"""Verbatim prompts recovered from the original GAP/Putnam source. Do not edit prompt literals in this file. ``tests/test_prompts.py`` pins their SHA-256 digests against the recovered source files. """ from __future__ import annotations import json from .models import CanonicalItem, KernelCandidate, KernelPlan, ProofPlanDAG # Source: PutnamVariants@c3bed737370df2dbf73afd66bf6e86d4ece82d68 # scripts/o3_kernel_variant.py KERNEL_PLAN_SYSTEM = "You are an IMO medalist & pedagogue." KERNEL_PLAN_PROMPT = """ You are a competition-math expert. (1) Read the Putnam problem and its official solution below. (2) List the MINIMAL chain of lemmas / techniques essential to the solution. (3) Identify every numerical or structural element that could be changed *without* altering that chain of reasoning. Denote them as MUTABLE_SLOTS. Return **one JSON object only**: {{ "core_steps": ["..."], // 1–5 concise phrases "mutable_slots": {{ "slot1": {{"description": "...", "original": "..."}}, "slot2": {{"description": "...", "original": "..."}} }} }} PROBLEM: <<<{question}>>> SOLUTION: <<<{solution}>>> """ KERNEL_GENERATE_SYSTEM = "You are a creative yet rigorous math professor." KERNEL_GENERATE_PROMPT = """ We previously extracted: CORE_STEPS = {core} MUTABLE_SLOTS = {slots} Here is the ORIGINAL problem for reference: <<<{orig_q}>>> And its OFFICIAL solution: <<<{orig_s}>>> Create ONE *new* Putnam-level problem that • still requires exactly the chain CORE_STEPS to solve, • alters *every* MUTABLE_SLOT in a significant way. Return JSON only: {{ "question": "...", // full statement (LaTeX-friendly) "solution": "..." // complete proof with new data }} """ # Source: paper Appendix F.3, Listing 4. JUDGE_SYSTEM_PROMPT = """You are a verification judge for a kernel-variant generation pipeline. You must decide whether a CANDIDATE variant problem and its CANDIDATE proof are mathematically equivalent to the ORIGINAL problem under the given METHOD-LABEL sequence (the abstract proof plan). Your job is verification, not solving. You receive: - the ORIGINAL problem statement and reference solution, - the abstract METHOD-LABEL sequence (a list of content-free steps), - the SLOT replacement that was applied, - the CANDIDATE variant statement and the CANDIDATE regenerated proof. You must check, step by step, that: 1. Every CANDIDATE step instantiates the corresponding METHOD label with the new operands. 2. The CANDIDATE proof is mathematically valid: each step follows from the previous one, with no unjustified leap. 3. The CANDIDATE problem statement is well-posed and has a unique terminal answer matching the regenerated proof. 4. The CANDIDATE variant is genuinely different from the ORIGINAL (the slot replacement actually changed the instance) but uses the same plan. Output a single JSON object with exactly these fields.""" JUDGE_USER_TEMPLATE = """ORIGINAL PROBLEM: {original_problem} ORIGINAL REFERENCE SOLUTION: {original_solution} METHOD-LABEL SEQUENCE (abstract plan): {method_labels} SLOT REPLACEMENT: {slot_replacement} CANDIDATE VARIANT PROBLEM: {candidate_problem} CANDIDATE REGENERATED PROOF: {candidate_proof} Return: {{"verdict": "accept" or "reject", "step_by_step_check": "for each METHOD label, state whether the CANDIDATE step instantiates it correctly", "blocking_issues": "list any logical gap, computation error, ill-posed statement, or plan deviation", "patch_suggestion": "if reject, propose a minimal patch (a corrected proof step or a corrected slot value); leave empty if accept"}}""" FIX_SYSTEM_PROMPT = """You are a mathematical expert tasked with fixing kernel variant problems. Based on the review feedback, correct the identified issues while maintaining the problem's essence. Guidelines: - Fix mathematical errors while preserving the problem's structure - Ensure the corrected version is well-posed and solvable - Keep solutions detailed and pedagogically clear - Maintain similar difficulty level to the original problem Provide COMPLETE corrected versions, not just patches.""" FIX_USER_TEMPLATE = """Based on the review feedback, please fix this kernel variant: CURRENT PROBLEM: {kv_question} CURRENT SOLUTION: {kv_solution} REVIEW FEEDBACK: Problem Issues: {problem_issues} Solution Issues: {solution_issues} ORIGINAL PROBLEM (for reference): {orig_question} ORIGINAL SOLUTION (for reference): {orig_solution} Please provide corrected versions. Return JSON with: {{"corrected_question": "complete corrected problem statement", "corrected_solution": "complete corrected solution",\x20 "changes_made": "summary of key changes made"}}""" # Source: PutnamVariants@c3bed737370df2dbf73afd66bf6e86d4ece82d68 # scripts/o3_rename_vars.py SURFACE_SYSTEM_BASE = "You are a meticulous LaTeX editor." SURFACE_TASK_COMMON = """ Given: • A Putnam problem statement and its official solution (LaTeX-like); • Two symbol lists: vars (unknowns) and params (given constants). Rename every symbol in *vars* and *params* with a unique English identifier: – all-lowercase letters, ≥8 chars, no underscore/space; – same original symbol → same new name everywhere; – different symbols → different new names; – NEVER touch sci_consts (\\pi,e,i,…) or numeric constants; – do NOT alter any other text or LaTeX markup. """ SURFACE_TASK_DESCRIPTIVE = """ Each new identifier **should describe the symbol's mathematical role**. """ SURFACE_TASK_CONFUSING = """ Each new identifier **should *not* match the symbol's role**; choose plausible but misleading nouns so the name sounds related but not matching the true meaning, such as replace Area with Radius. """ SURFACE_TASK_MISLEADING = """ Each new identifier **should describe the *opposite* concept**. Pick names that directly contradict the symbol's actual meaning, e.g. rename a parallel vector to orthogonalvector. """ SURFACE_TASK_GARBLED = """ Each new identifier **should look like random gibberish**: at least eight lowercase letters with no apparent meaning such as qzxwvtnp or hjgrksla. """ SURFACE_RETURN_SPEC = """ Return exactly **one JSON object** and nothing else: {"map":{"old":"new",...},"question":"...","solution":"..."} """ SURFACE_USER_TEMPLATE = """Problem: <<< {question} >>> Solution: <<< {solution} >>> vars = {vars} params = {params} """ SURFACE_TASKS = { "descriptive_long": SURFACE_TASK_DESCRIPTIVE, "descriptive_long_confusing": SURFACE_TASK_CONFUSING, "descriptive_long_misleading": SURFACE_TASK_MISLEADING, "garbled_string": SURFACE_TASK_GARBLED, } def kernel_plan_user(item: CanonicalItem) -> str: return KERNEL_PLAN_PROMPT.format( question=item.problem, solution=item.solution, ) def kernel_generate_user(item: CanonicalItem, plan: KernelPlan) -> str: return KERNEL_GENERATE_PROMPT.format( core=json.dumps(plan.core_steps, ensure_ascii=False), slots=json.dumps( { key: value.model_dump(mode="json") for key, value in plan.mutable_slots.items() }, ensure_ascii=False, ), orig_q=item.problem, orig_s=item.solution, ) def judge_user( item: CanonicalItem, plan: KernelPlan, dag: ProofPlanDAG, candidate: KernelCandidate, ) -> str: return JUDGE_USER_TEMPLATE.format( original_problem=item.problem, original_solution=item.solution, method_labels=json.dumps(dag.method_labels_payload(), ensure_ascii=False), slot_replacement=json.dumps( { key: value.model_dump(mode="json") for key, value in plan.mutable_slots.items() }, ensure_ascii=False, ), candidate_problem=candidate.question, candidate_proof=candidate.solution, ) def fix_user( item: CanonicalItem, candidate: KernelCandidate, *, problem_issues: str, solution_issues: str, ) -> str: return FIX_USER_TEMPLATE.format( kv_question=candidate.question, kv_solution=candidate.solution, problem_issues=problem_issues, solution_issues=solution_issues, orig_question=item.problem, orig_solution=item.solution, ) def surface_system(family: str) -> str: return ( SURFACE_SYSTEM_BASE + SURFACE_TASK_COMMON + SURFACE_TASKS[family] + SURFACE_RETURN_SPEC ) def surface_user(item: CanonicalItem) -> str: return SURFACE_USER_TEMPLATE.format( question=item.problem, solution=item.solution, vars=item.variables, params=item.parameters, )