Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from google import genai
|
2 |
+
from google.genai import types
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
client = genai.Client(api_key=GOOGLE_API_KEY)
|
6 |
+
MODEL_ID = "gemini-2.0-flash-thinking-exp"
|
7 |
+
from google import genai
|
8 |
+
client = genai.Client(api_key="AIzaSyCmUDbVAOGcRZcOKP4q6mmeZ7Gx1WgE3vE")
|
9 |
+
|
10 |
+
def llm_response(text):
|
11 |
+
response = client.models.generate_content(
|
12 |
+
model=MODEL_ID,
|
13 |
+
contents= text)
|
14 |
+
return response.text
|
15 |
+
|
16 |
+
def theorem_prover(theorem):
|
17 |
+
theorem_llm = llm_response(f'''You are an advanced mathematical reasoning model specializing in formal theorem proving. Your task is to analyze a given theorem,
|
18 |
+
determine the most appropriate proof strategy, and construct a rigorous proof using formal proof assistants such as Lean, Coq, or Isabelle. If a proof is not
|
19 |
+
possible, identify gaps, suggest refinements, or provide counterexamples.
|
20 |
+
|
21 |
+
User Prompt:
|
22 |
+
Input:
|
23 |
+
"Theorem Statement:
|
24 |
+
{theorem}
|
25 |
+
Task Breakdown:
|
26 |
+
1. Understand the Theorem
|
27 |
+
Identify the mathematical domain (e.g., Number Theory, Algebra, Topology).
|
28 |
+
Recognize any implicit assumptions, definitions, or missing details.
|
29 |
+
Determine whether the theorem is constructive, existential, or universally quantified.
|
30 |
+
2. Determine the Proof Strategy
|
31 |
+
The model will automatically select the best approach based on the theorem's structure:
|
32 |
+
|
33 |
+
Proof Strategy Selection Guidelines
|
34 |
+
To determine the best proof strategy for a given theorem, follow these principles:
|
35 |
+
|
36 |
+
Direct Proof β Use when the statement follows naturally from known axioms or definitions. Example: Proving that if
|
37 |
+
π
|
38 |
+
n is even, then
|
39 |
+
π
|
40 |
+
2
|
41 |
+
n
|
42 |
+
2
|
43 |
+
is even.
|
44 |
+
Proof by Contradiction β Assume the negation of the statement and show it leads to a contradiction. This is useful for proving the infinitude of primes.
|
45 |
+
Proof by Induction β Apply when proving a property for an infinite sequence or recursively defined structures. Example: Proving the sum formula
|
46 |
+
β
|
47 |
+
π
|
48 |
+
=
|
49 |
+
1
|
50 |
+
π
|
51 |
+
π
|
52 |
+
=
|
53 |
+
π
|
54 |
+
(
|
55 |
+
π
|
56 |
+
+
|
57 |
+
1
|
58 |
+
)
|
59 |
+
2
|
60 |
+
β
|
61 |
+
i=1
|
62 |
+
n
|
63 |
+
β
|
64 |
+
i=
|
65 |
+
2
|
66 |
+
n(n+1)
|
67 |
+
β
|
68 |
+
.
|
69 |
+
Case Analysis β Use when different scenarios must be considered separately. Example: Proving that a quadratic equation has at most two real roots.
|
70 |
+
Constructive Proof β Show existence by explicitly constructing an example. Example: Proving that there exists an irrational number
|
71 |
+
π₯
|
72 |
+
x such that
|
73 |
+
π₯
|
74 |
+
π₯
|
75 |
+
x
|
76 |
+
x
|
77 |
+
is rational.
|
78 |
+
Non-constructive Proof β Prove existence without constructing an explicit example, often using logic or set theory. Example: Proving that there exists a prime number between
|
79 |
+
π
|
80 |
+
n and
|
81 |
+
2
|
82 |
+
π
|
83 |
+
2n.
|
84 |
+
Proof by Exhaustion β Use when a theorem holds for a small, finite set of cases that can be checked individually. Example: Verifying a property for small integers.
|
85 |
+
Proof using a Counterexample β Disprove a general claim by providing a specific case where it fails. Example: Showing that not all differentiable functions are continuous.
|
86 |
+
The model should analyze the structure of the theorem and automatically select the most suitable proof technique based on these guidelines.
|
87 |
+
|
88 |
+
3. Construct the Proof
|
89 |
+
Step-by-step logical explanation.
|
90 |
+
|
91 |
+
Verification and validation.
|
92 |
+
4. Handle Edge Cases
|
93 |
+
If proof fails:
|
94 |
+
|
95 |
+
Highlight missing assumptions.
|
96 |
+
Provide a minimal counterexample (if the statement is false).
|
97 |
+
Suggest a reformulation or alternative direction.
|
98 |
+
Expected Output:
|
99 |
+
β Proof Found:
|
100 |
+
|
101 |
+
Step-by-step reasoning.
|
102 |
+
Proof strategy justification.
|
103 |
+
|
104 |
+
β Proof Not Possible:
|
105 |
+
|
106 |
+
Identified logical gap or missing assumptions.
|
107 |
+
Suggested refinement or counterexample.
|
108 |
+
Example Usage:
|
109 |
+
Input:
|
110 |
+
"Every even integer greater than 2 can be expressed as the sum of two prime numbers."
|
111 |
+
|
112 |
+
Output:
|
113 |
+
β Proof Attempt:
|
114 |
+
|
115 |
+
Identified Proof Strategy:
|
116 |
+
|
117 |
+
This is an existential statement (β two primes p1, p2 such that p1 + p2 = n).
|
118 |
+
Since direct proof is difficult, contradiction and case analysis are common approaches.
|
119 |
+
Computational methods confirm the conjecture for large values of
|
120 |
+
π
|
121 |
+
n, but no general proof exists.
|
122 |
+
Proof Attempt:
|
123 |
+
|
124 |
+
|
125 |
+
theorem goldbach_conjecture (n : β) (h : even n β§ n > 2) :
|
126 |
+
β p1 p2, prime p1 β§ prime p2 β§ p1 + p2 = n :=
|
127 |
+
begin
|
128 |
+
-- Step 1: Assume n is an even integer greater than 2
|
129 |
+
-- Step 2: Search for prime pairs (p1, p2) such that p1 + p2 = n
|
130 |
+
-- Step 3: If no counterexamples exist up to a given range, assume general case
|
131 |
+
-- Theorem remains unproven but verified for large n using computational methods
|
132 |
+
end
|
133 |
+
β Proof Not Found:
|
134 |
+
|
135 |
+
No general proof within standard number theory axioms.
|
136 |
+
Computational verification up to
|
137 |
+
10
|
138 |
+
18
|
139 |
+
10
|
140 |
+
18
|
141 |
+
supports the conjecture.
|
142 |
+
Suggest refining the conjecture by imposing additional constraints.
|
143 |
+
|
144 |
+
You should intelligently selects the best proof strategy.
|
145 |
+
Provides clear justifications for strategy choice.
|
146 |
+
|
147 |
+
Output a rigorous proof or meaningful insight even when a full proof is impossible in markdown format.''')
|
148 |
+
return theorem_llm
|
149 |
+
|
150 |
+
iface = gr.Interface(
|
151 |
+
fn=verify_formula,
|
152 |
+
inputs=gr.Textbox(label="Enter Formula (e.g., x > 5 and y < 10)"),
|
153 |
+
outputs=gr.HTML(label="Result"), # Output as HTML
|
154 |
+
title="Theorem proving agent",
|
155 |
+
description="Enter a logical formula using Z3 syntax to check its satisfiability."
|
156 |
+
)
|
157 |
+
|
158 |
+
# Launch the app
|
159 |
+
iface.launch()
|