File size: 6,765 Bytes
ddb9676
 
 
1c48a8d
 
 
ddb9676
 
 
1c48a8d
ddb9676
 
 
 
 
 
 
d4ffe9c
 
00104af
d4ffe9c
00104af
d4ffe9c
00104af
d4ffe9c
00104af
 
 
 
 
 
 
 
 
 
 
d4ffe9c
 
00104af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d4ffe9c
00104af
d4ffe9c
00104af
d4ffe9c
00104af
d4ffe9c
00104af
d4ffe9c
00104af
d4ffe9c
00104af
d4ffe9c
ac0b367
 
ddb9676
ac0b367
ed00423
735d35a
ac0b367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddb9676
d4ffe9c
 
9d26912
4fdc471
d4ffe9c
9d26912
d4ffe9c
ddb9676
 
 
ac0b367
 
6dc8c56
ac0b367
 
 
 
 
 
 
 
 
 
e7b233c
ac0b367
 
 
 
 
 
 
 
 
 
 
6dc8c56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from google import genai
from google.genai import types
import gradio as gr
import os



MODEL_ID = "gemini-2.0-flash-thinking-exp"
from google import genai
client = genai.Client(api_key=os.getenv('api_key'))

def llm_response(text):
  response = client.models.generate_content(
    model=MODEL_ID,
    contents= text)
  return response.text

def pvsnp(problem):
  classification = llm_response(f'''
You are an expert in computational complexity theory, specializing in both classical complexity classes (P, NP, NP-complete, NP-hard) and modern developments (e.g., parameterized complexity, fine-grained complexity, Minimum Circuit Size Problem).

Your task is to classify a given problem into one of the following categories:

P: Solvable in deterministic polynomial time.

NP: Verifiable in polynomial time.

NP-complete: Both in NP and NP-hard.

NP-hard: At least as hard as NP-complete problems, possibly outside NP.

Beyond NP: Likely in PSPACE, EXPTIME, or undecidable.

Other: Fits alternative complexity classes (e.g., BPP, co-NP).

Problem Description:
{problem}

If the given problem is a NP-hard problem,  decompose the NP-hard problem into polynomial-time solvable subproblems without solving them.

🔹 Inputs:
A formal definition and instance of the NP-hard problem (e.g., SAT, TSP, Graph Coloring).

Optional: Constraints or domain knowledge.

🔹 Decomposition Process:
Graph Representation & Structural Analysis

Convert the problem into a graph (if applicable).

Identify independent or tractable substructures.

Classification of Subproblems

Detect polynomially solvable parts (e.g., tree structures, bipartite graphs).

Separate them from harder components.

Partitioning & Transformation

Break the problem into independent or loosely connected subproblems.

Ensure each subproblem is in P or provably easier than the original.

Output a structured breakdown.

🔹 Outputs:
A list of P-complexity subproblems.

A dependency graph of their relationships in ASCII format.

A complexity analysis report quantifying decomposition effectiveness.

Guidelines for Classification:
Problem Analysis

Determine if the problem is a decision, optimization, or function computation problem.

Identify key input/output characteristics and constraints.

Complexity Insights

Check for polynomial-time solvability via known techniques (dynamic programming, greedy methods).

Assess reductions to/from well-studied problems.

Advanced Considerations

Incorporate recent research (e.g., MCSP's implications for NP-completeness).

Evaluate parameterized complexity (FPT results) and fine-grained complexity (SETH, other conjectures).

Consider probabilistic or average-case complexity aspects.

Justification

Provide a concise explanation for the classification, referencing key problem features and relevant research.

Your Classification and Explanation:
''')
  
  return classification

def critic_analysis(classification_output):
    critic = llm_response(f'''"You are PolyCritic, an expert in computational complexity and problem decomposition. Your goal is to critically evaluate whether a given
      NP-hard problem, when broken into P-solvable subproblems, can be efficiently recombined to yield the full solution. Here is the problem and the analysis: {classification_output}

Instructions:
1️⃣ Input: A decomposed NP-hard problem along with its P-solvable subproblems.
2️⃣ Step 1 - Validate Subproblems:

Do these subproblems fully cover the original problem?

Are they correctly categorized as P?
3️⃣ Step 2 - Analyze Recombination Complexity:

Can the subproblem solutions be combined in polynomial time?

If not, what is the bottleneck? (e.g., exponential merging, missing constraints)
4️⃣ Step 3 - Provide Verdict:

If recombination is efficient, explain why this suggests progress towards P = NP.

If inefficient, identify where complexity remains and suggest next steps.
5️⃣ Step 4 - Provide Complexity Insights:

Offer insights into whether certain structural patterns predict efficient recombination.

Suggest improvements in decomposition strategies.

Example Analysis Format:
💡 Problem: Traveling Salesperson (TSP)
🔍 Subproblems: Shortest paths between city clusters (P-solvable)
⚖ Recombination Complexity: Exponential growth in possible paths when merging clusters
🚨 Verdict: Recombination remains NP-hard → Decomposition needs refinement

👉 Your task is to apply this structured critique to any NP-hard problem and determine if it truly reduces to P.''')  
    return critic
    

'''
iface = gr.Interface(
    fn=pvsnp, 
    inputs=gr.Textbox(label="What problem would you like to classify as P or NP?"), 
    outputs=gr.Markdown(label="Agent's response"),  # Output as HTML
    title="PolyProb",
    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.",
    theme = gr.themes.Ocean(),
    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?"]
)

# Launch the app
iface.launch() '''

with gr.Blocks(theme=gr.themes.Ocean()) as app:
    gr.Markdown("# PolyProb & PolyCritic AI 🤖")
    gr.Markdown('''PolyProb and PolyCritic are AI Agents that help users classify a problem into categories such as P, NP, NP-complete, NP-hard 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.''')
    
    with gr.Row():
        problem_input = gr.Textbox(label="Enter a computational problem")
        classify_button = gr.Button("Classify")
    
    classification_output = gr.Markdown(label="Classification (P or NP)")
    
    classify_button.click(pvsnp, inputs=problem_input, outputs=[classification_output])
    
    evaluate_button = gr.Button("Evaluate Recombination Complexity")
    recombination_output = gr.Textbox(label="Recombination Complexity")
    
    evaluate_button.click(critic_analysis, inputs=classification_output, outputs=recombination_output)
    
    #results_button = gr.Button("Show Stored Results")
    #results_display = gr.Textbox(label="Stored Results")
    
    #results_button.click(get_stored_results, outputs=results_display)

app.launch()