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 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: - **P**: Problems that can be solved in deterministic polynomial time. - **NP**: Problems for which a proposed solution can be verified in deterministic polynomial time. - **NP-complete**: Problems that are both in NP and as hard as any problem in NP, via polynomial-time reductions. - **NP-hard**: Problems that are at least as hard as NP-complete problems but may not be in NP. - **Beyond NP**: Problems that likely belong to more complex classes (e.g., PSPACE, EXPTIME) or are undecidable. - **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. **Problem Description:** {problem} **Guidelines:** 1. **Comprehensive Analysis**: - Determine whether the problem is primarily a decision problem, an optimization problem, or a function computation. - Identify key input and output characteristics and any explicit constraints. 2. **Complexity Characteristics**: - 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. - Assess whether there is potential for polynomial-time reductions from or to well-studied problems in the literature. 3. **Advanced and Recent Research Considerations**: - Incorporate insights from the latest research, including the implications of the Minimum Circuit Size Problem (MCSP) for NP-completeness. - Consider parameterized complexity aspects: does the problem admit fixed-parameter tractable (FPT) solutions under certain parameters? - Evaluate any connections to fine-grained complexity results, such as relationships to the Strong Exponential Time Hypothesis (SETH) or other conjectures. - If the problem has probabilistic or average-case aspects, mention how these might affect its classification. 4. **Explanation of Reasoning**: - 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. **Your Classification and Explanation:** ''') return classification 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()