AI-Quotient commited on
Commit
d4ffe9c
Β·
verified Β·
1 Parent(s): 4fdc471

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -136
app.py CHANGED
@@ -15,147 +15,53 @@ def llm_response(text):
15
  contents= text)
16
  return response.text
17
 
18
- def theorem_prover(theorem):
19
- 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,
20
- determine the most appropriate proof strategy, and construct a rigorous proof. If a proof is not possible, identify gaps, suggest refinements, or provide counterexamples.
21
-
22
- User Prompt:
23
- Input:
24
- "Theorem Statement:
25
- {theorem}
26
- Task Breakdown:
27
- 1. Understand the Theorem
28
- Identify the mathematical domain (e.g., Number Theory, Algebra, Topology).
29
- Recognize any implicit assumptions, definitions, or missing details.
30
- Determine whether the theorem is constructive, existential, or universally quantified.
31
- 2. Determine the Proof Strategy
32
- The model will automatically select the best approach based on the theorem's structure:
33
-
34
- Proof Strategy Selection Guidelines
35
- To determine the best proof strategy for a given theorem, follow these principles:
36
-
37
- Direct Proof β†’ Use when the statement follows naturally from known axioms or definitions. Example: Proving that if
38
- 𝑛
39
- n is even, then
40
- 𝑛
41
- 2
42
- n
43
- 2
44
- is even.
45
- 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.
46
- Proof by Induction β†’ Apply when proving a property for an infinite sequence or recursively defined structures. Example: Proving the sum formula
47
- βˆ‘
48
- 𝑖
49
- =
50
- 1
51
- 𝑛
52
- 𝑖
53
- =
54
- 𝑛
55
- (
56
- 𝑛
57
- +
58
- 1
59
- )
60
- 2
61
- βˆ‘
62
- i=1
63
- n
64
- ​
65
- i=
66
- 2
67
- n(n+1)
68
- ​
69
- .
70
- Case Analysis β†’ Use when different scenarios must be considered separately. Example: Proving that a quadratic equation has at most two real roots.
71
- Constructive Proof β†’ Show existence by explicitly constructing an example. Example: Proving that there exists an irrational number
72
- π‘₯
73
- x such that
74
- π‘₯
75
- π‘₯
76
- x
77
- x
78
- is rational.
79
- 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
80
- 𝑛
81
- n and
82
- 2
83
- 𝑛
84
- 2n.
85
- 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.
86
- 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.
87
- The model should analyze the structure of the theorem and automatically select the most suitable proof technique based on these guidelines.
88
-
89
- 3. Construct the Proof
90
- Step-by-step logical explanation.
91
-
92
- Verification and validation.
93
- 4. Handle Edge Cases
94
- If proof fails:
95
-
96
- Highlight missing assumptions.
97
- Provide a minimal counterexample (if the statement is false).
98
- Suggest a reformulation or alternative direction.
99
- Expected Output:
100
- βœ” Proof Found:
101
-
102
- Step-by-step reasoning.
103
- Proof strategy justification.
104
-
105
- ❌ Proof Not Possible:
106
-
107
- Identified logical gap or missing assumptions.
108
- Suggested refinement or counterexample.
109
- Example Usage:
110
- Input:
111
- "Every even integer greater than 2 can be expressed as the sum of two prime numbers."
112
-
113
- Output:
114
- βœ” Proof Attempt:
115
-
116
- Identified Proof Strategy:
117
-
118
- This is an existential statement (βˆƒ two primes p1, p2 such that p1 + p2 = n).
119
- Since direct proof is difficult, contradiction and case analysis are common approaches.
120
- Computational methods confirm the conjecture for large values of
121
- 𝑛
122
- n, but no general proof exists.
123
- Proof Attempt:
124
-
125
-
126
- theorem goldbach_conjecture (n : β„•) (h : even n ∧ n > 2) :
127
- βˆƒ p1 p2, prime p1 ∧ prime p2 ∧ p1 + p2 = n :=
128
- begin
129
- -- Step 1: Assume n is an even integer greater than 2
130
- -- Step 2: Search for prime pairs (p1, p2) such that p1 + p2 = n
131
- -- Step 3: If no counterexamples exist up to a given range, assume general case
132
- -- Theorem remains unproven but verified for large n using computational methods
133
- end
134
- ❌ Proof Not Found:
135
-
136
- No general proof within standard number theory axioms.
137
- Computational verification up to
138
- 10
139
- 18
140
- 10
141
- 18
142
- supports the conjecture.
143
- Suggest refining the conjecture by imposing additional constraints.
144
-
145
- You should intelligently selects the best proof strategy.
146
- Provides clear justifications for strategy choice.
147
-
148
- Output a rigorous proof or meaningful insight even when a full proof is impossible in markdown format.''')
149
- return theorem_llm
150
 
151
  iface = gr.Interface(
152
- fn=theorem_prover,
153
- inputs=gr.Textbox(label="Enter the theorem you want to prove or disprove"),
154
  outputs=gr.Markdown(label="Agent's response"), # Output as HTML
155
  title="PolyProb",
156
- description="PolyProb is an advanced AI agent that guides users through the intricate maze of computational complexity. This agent scrutinizes problem descriptions with sophisticated LLM prompts and symbolic reasoning. It classifies problems into categories such as P, NP, NP-complete, NP-hard, or beyond (e.g., PSPACE, EXPTIME), while providing clear, concise explanations of its reasoning. As part of AI Quotient’s Millennium Math Challenge, it is the first step towards solving the P vs NP problem",
157
  theme = gr.themes.Ocean(),
158
- examples = ["Every prime number greater than 2 is odd.", "The sum of two rational numbers is always rational.", "The power set of any set has strictly greater cardinality than the set itself."]
159
  )
160
 
161
  # Launch the app
 
15
  contents= text)
16
  return response.text
17
 
18
+ def pvsnp(problem):
19
+ classification = llm_response(f'''
20
+
21
+ You are an expert in computational complexity theory with deep knowledge of both classical complexity classes (P, NP, NP-complete, NP-hard) and modern developments such as parameterized complexity, fine-grained complexity, and recent findings like the Minimum Circuit Size Problem (MCSP). Your task is to analyze a given problem description and classify it into one of the following categories:
22
+
23
+ - **P**: Problems that can be solved in deterministic polynomial time.
24
+ - **NP**: Problems for which a proposed solution can be verified in deterministic polynomial time.
25
+ - **NP-complete**: Problems that are both in NP and as hard as any problem in NP, via polynomial-time reductions.
26
+ - **NP-hard**: Problems that are at least as hard as NP-complete problems but may not be in NP.
27
+ - **Beyond NP**: Problems that likely belong to more complex classes (e.g., PSPACE, EXPTIME) or are undecidable.
28
+ - **Other**: If the problem fits into an alternative complexity class (e.g., BPP, co-NP) or does not clearly align with the categories above, note that explicitly.
29
+
30
+ **Problem Description:**
31
+ {problem}
32
+
33
+ **Guidelines:**
34
+
35
+ 1. **Comprehensive Analysis**:
36
+ - Determine whether the problem is primarily a decision problem, an optimization problem, or a function computation.
37
+ - Identify key input and output characteristics and any explicit constraints.
38
+
39
+ 2. **Complexity Characteristics**:
40
+ - Examine if the problem exhibits features common to polynomial-time algorithms (e.g., dynamic programming, greedy strategies) or if it has structural similarities to known NP-complete problems.
41
+ - Assess whether there is potential for polynomial-time reductions from or to well-studied problems in the literature.
42
+
43
+ 3. **Advanced and Recent Research Considerations**:
44
+ - Incorporate insights from the latest research, including the implications of the Minimum Circuit Size Problem (MCSP) for NP-completeness.
45
+ - Consider parameterized complexity aspects: does the problem admit fixed-parameter tractable (FPT) solutions under certain parameters?
46
+ - Evaluate any connections to fine-grained complexity results, such as relationships to the Strong Exponential Time Hypothesis (SETH) or other conjectures.
47
+ - If the problem has probabilistic or average-case aspects, mention how these might affect its classification.
48
+
49
+ 4. **Explanation of Reasoning**:
50
+ - Provide a brief, clear explanation for your classification. Justify your decision by referencing specific features of the problem and connecting them to established theory and recent research insights.
51
+
52
+ **Your Classification and Explanation:**
53
+
54
+ ''')
55
+ return classification
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  iface = gr.Interface(
58
+ fn=pvsnp,
59
+ inputs=gr.Textbox(label="What problem would you like to classify as P or NP?"),
60
  outputs=gr.Markdown(label="Agent's response"), # Output as HTML
61
  title="PolyProb",
62
+ description="PolyProb is an advanced AI agent that guides users through the intricate maze of computational complexity. This agent scrutinizes problem descriptions with sophisticated LLM prompts and symbolic reasoning. It classifies problems into categories such as P, NP, NP-complete, NP-hard, or beyond (e.g., PSPACE, EXPTIME), while providing clear, concise explanations of its reasoning. As part of AI Quotient’s Millennium Math Challenge, it is the first step towards solving the P vs NP problem.",
63
  theme = gr.themes.Ocean(),
64
+ examples = ["Can you find a path that visits each node exactly once in a given graph?", "How efficiently can two nXn matrices be multiplied?", "Is there a subset of given numbers that sums to a target value?"]
65
  )
66
 
67
  # Launch the app