ESL ⚡ Ampcode ◆ Wolfram
1 / 19
Ampcode: Research Paper to Mathematica Notebook

Ampcode + Wolfram Mathematica

From Research Paper to Self-Consistent Proof & Interactive Notebook

Ampcode Workflow

The Ampcode Workflow

Extract → Implement → Validate → Self-Consistency → Novel Results

The Core Problem

Why GPT-5 Fundamentally Cannot Do This

This isn't about GPT-5 being "not smart enough." The failures are architectural — built into how Large Language Models work. No amount of prompting can fix them.

🧠 No Symbolic Algebra Engine

LLMs generate text that looks like math — they predict the next token. They don't have a Computer Algebra System (CAS). When GPT-5 writes "dα*/dP = ...", it's pattern-matching from training data, not computing a derivative.

🔄 No Execution Feedback Loop

GPT-5 cannot run FindRoot, NIntegrate, or Solve. It cannot plug values back in to check if the answer is correct. Each equation is generated once — with no way to verify it actually holds.

📝 Stateless Token Generation

Each token is predicted from context — there's no internal state that tracks "I assumed α is fixed here, but α depends on γ." The model cannot detect when its own assumptions contradict its conclusions.

🚫 No Self-Consistency Verification

The critical error: GPT-5 computed γ_crit ≈ 5.9 while holding α fixed. But α₀ depends on γ through the FOC. An LLM has no mechanism to detect this circular dependency — it requires solving an implicit equation, which requires a CAS.

The Failure Chain

How Each Architectural Gap → Specific Error

No CAS →

Incorrect implicit differentiation of the FOC. GPT-5 dropped terms, confused ∂/∂P with d/dP, and produced wrong Arrow-Pratt substitutions across multiple attempts.

No Execution →

Could never verify that its Eq.(17) actually satisfies the identity. No FindRoot to compute α*, no NIntegrate to check limit behavior at P→0 and P→1.

Stateless →

Held α fixed at 0.5 while computing γ_crit, unaware this contradicts the FOC which determines α₀(γ). Repeated the same error across 5+ attempts because it couldn't "remember" the dependency.

No Verification →

Concluded "Lemma 1(i) holds for CRRA when γ > 5.9." The correct answer: it almost NEVER holds — only for catastrophic harm (H/W > 88%). GPT-5 had no way to catch this.

💡 The bottom line: mathematical proof verification requires execution + feedback + self-consistency checking.
These are not features you can add to an LLM with better prompts — they require an infrastructure stack.

The Magic Moment

One Prompt. Complete Solution.

The entire task was accomplished with a single natural-language request:

User → Use Wolfram Mathematica CK skill. Attached is the research paper "Insurance_Demand_Insurance_demand". Start from Lemma 1 in the paper. I want to verify that the lemma and its proof (which is in the appendix) are correct, and then show that Lemma 1(i) can apply to consumers with CRRA utility. Result should be interactive Wolfram Mathematica .nb where user can insert inputs and use sliders, documented in detail for a scientific presentation to the lead author.

No manual equation entry. No debugging.

Under The Hood

The Complete Process

① AI Reads PDF

Extracts all equations, definitions, lemma statement, and appendix proof steps

② CandleKeep Reference

Queries Wolfram Language syntax from 60+ reference documents for correct Mathematica code

③ Skill Generates .nb

12 sections including 3 Manipulate panels with interactive sliders

④ 6-Point Syntax Validation

Brackets, invalid characters, BoxData, notebook structure, string escaping, cell grouping

⑤ Self-Consistency Verification

Catches the naive threshold error — α₀ depends on γ, so γ_crit(γ) must be solved implicitly

⑥ Plain-English Proof Appendix

Human-readable step-by-step proof added for presentation to the lead author

The Paper

Authors (2025)

Insurance Demand under Supra-Competitive Pricing

📋 Model Setup

  • W — Initial wealth
  • H — Harm (loss in bad state)
  • P — Accident probability
  • q ≥ 1 — Loading factor (supra-competitive price)
  • α ∈ [0,1] — Coverage chosen by consumer
  • Ra(A) = −U″(A)/U′(A) — Arrow-Pratt coefficient

📐 Lemma 1

  • (i) Single-peaked: If Ra decreases fast enough in wealth, ∃ P̄ that maximizes insurance demand
  • (ii) Monotone decreasing: If Ra is not too decreasing, demand falls monotonically with P
  • Proof via implicit differentiation of the FOC
  • Limit arguments at P→0 and P→1 determine sign of dα*/dP
Proof Step 1

The First-Order Condition

The consumer maximizes expected utility. The FOC equates marginal cost of insurance (premium in the good state) with marginal benefit (coverage in the bad state).

−(1−P)·q·U′(W₁) + (1−qP)·U′(W₂) = 0 where W₁ = W − αqPH (good state) W₂ = W − H(1−α) − αqPH (bad state)

CRRA Specialization: U′(A) = A−γ

(W₁ / W₂)^γ = (1−P)·q / (1−qP) At P = 0: W^(−γ) = q · (W − H(1−α))^(−γ)
Proof Step 2

Optimal Coverage at P → 0

At P→0, the FOC simplifies. Solving for α₀ reveals coverage depends on risk aversion γ.

FOC at P→0: W^(−γ) = q · (W − H(1−α))^(−γ) Solving for α₀: α₀(γ) = 1 − (W/H) · (1 − q^(−1/γ))

🔑 KEY INSIGHT

Coverage α₀ depends on γ — this creates the self-consistency issue later. You cannot compute γ_crit while holding α fixed, because α itself changes with γ.

Proof Step 3

How Coverage Changes with Risk

Implicit differentiation of the FOC yields Eq. (17) — the derivative dα*/dP:

dα*/dP = N / D N = (1−P)·α·q·H·[Ra(W₁) − Ra(W₂)] + (q−1)/(1−qP) D = −(1−P)·H·[qP·Ra(W₁) + (1−qP)·Ra(W₂)] ← always < 0

N < 0 → dα*/dP > 0

If N is strictly increasing in P (crosses zero once), demand is single-peaked → Lemma 1(i)

N > 0 → dα*/dP < 0

N stays positive for all P → demand falls monotonically → Lemma 1(ii)

Numerator at P→0

N₀ = α₀·q·H·γ·[1/W − 1/(W − H(1−α₀))] + (q−1)

⚠ Domain: P ∈ [0, 1/q), not [0, 1]. The constraint 1−qP > 0 requires P < 1/q. As P → 1/q, the term (q−1)/(1−qP) → +∞, making N > 0 and dα*/dP < 0 unambiguously.

Key Insight

The Self-Consistency Trap

❌ The Naive Approach (GPT-5's Error)

  • Hold α fixed at some value (e.g. α = 0.5)
  • Compute γ_crit ≈ 5.9
  • Claim Lemma 1(i) holds for γ > 5.9
⚠ WRONG: α itself changes with γ! As γ increases, α₀(γ) → 1 The "fixed α" assumption is invalid.

✅ The Self-Consistent Approach

  • α₀ depends on γ through the FOC
  • As γ ↑, α₀(γ) → 1 (full coverage)
  • Wealth gap W₁ − W₂ vanishes
  • γ_crit(γ) grows faster than γ
Must solve the implicit inequality: γ > γ_crit(γ) where γ_crit depends on α₀(γ).
Proof Step 5

The Asymptotic Argument

Taylor expansion of q−1/γ as γ → ∞ reveals the limiting behavior of the numerator N₀.

Taylor expansion: q^(−1/γ) ≈ 1 − ln(q)/γ as γ → ∞ Then: α₀ → 1 − (W/H)·(ln(q)/γ) The product γ·[1/W − 1/W₂] → −ln(q)/W Therefore: N₀ → (q−1) − q·H·ln(q)/W

Numerical Check: W=100, H=40, q=1.3

N₀ → (1.3 − 1) − 1.3 × 40 × ln(1.3) / 100 = 0.3 − 1.3 × 40 × 0.2624 / 100 = 0.3 − 0.136 = +0.164 > 0

N₀ is ALWAYS positive for typical parameters. Lemma 1(i) NEVER holds for CRRA when H/W = 0.4

Proof Step 6

When CAN Lemma 1(i) Hold?

For N₀ < 0 (single-peaked demand), we need the harm term to dominate:

H/W ≥ (q−1) / (q · ln q)
Loading qMinimum H/WInterpretation
q = 1.10.954Harm ≥ 95.4% of wealth
q = 1.30.880Harm ≥ 88.0% of wealth
q = 1.50.822Harm ≥ 82.2% of wealth

Only catastrophic harm (88%+ of wealth for q = 1.3) produces single-peaked demand with CRRA utility.

Economic Intuition

Why the Two Effects Cancel

✓ Effect 1: Risk Aversion Rises

γ ↑ → Risk aversion increases → Ra(W₁) − Ra(W₂) becomes more negative → pushes N₀ toward negative

✗ Effect 2: Coverage Closes the Gap

γ ↑ → Coverage α₀ → 1 → Wealth gap shrinks → Ra(W₁) ≈ Ra(W₂) → difference vanishes

≈ Net Effect: Forces Cancel

The two effects approximately cancel, leaving the (q−1) > 0 term dominant → N₀ > 0 → Lemma 1(ii)

Utility functions where Ra(A) decreases faster than 1/A (e.g., HARA with appropriate parameters, DRRA class) are needed for Lemma 1(i) to hold at typical harm levels.

📊 Individual → Aggregate

Single-peakedness of each consumer's α*(P) does not automatically imply single-peakedness of aggregate demand. A sufficient condition: if dα*/dP is strictly decreasing in P for all consumer types (regardless of how types are distributed), then the sum of derivatives is also decreasing — aggregate demand inherits single-peakedness.

Deliverable

Interactive Mathematica Notebook

📊 3 Manipulate Panels

  • Coverage α*(P) with peak detection
  • Arrow-Pratt decomposition of Eq.(17)
  • Aggregate demand with heterogeneous consumers

🔬 6 Validation Tests

  • FOC consistency check
  • Wealth ordering W₁ > W₂
  • Arrow-Pratt identity
  • Denominator sign < 0
  • P→1 limit behavior
  • Reproducibility (fixed seed)

🎛️ Interactive Sliders

  • Wealth W: 50–500
  • Harm H: 5–80
  • Loading q: 1.01–3.0
  • CRRA γ: 0.1–15.0
  • Consumer heterogeneity range
Universal Pattern

Self-Consistency Across Science

The "threshold depends on the equilibrium which depends on the threshold" trap appears everywhere.

FieldCritical ParameterEquilibrium VariableSelf-Consistency Eq.
Economicsγ_critα*(γ)First-Order Condition (FOC)
PhysicsT_cm(T)Mean-field equation
EngineeringP_critδ(P)Equilibrium equation
Biologyμ_cx*(μ)Selection-mutation balance
Financeσ_ch*(σ)Portfolio FOC
EpidemiologyR₀I*(R₀)SIR steady-state

The Wolfram-Mathematica skill now checks for this pattern in any field automatically.

Comparison

Ampcode + Wolfram vs. GPT-5

❌ GPT-5 (ChatGPT Plus)

  • Multiple attempts, repeated algebraic errors
  • Cannot execute or validate equations
  • No interactive visualizations
  • No numerical root-finding
  • Cannot produce runnable .nb files
  • No syntax validation pipeline
  • No self-consistency verification
  • Hours of manual correction needed

✅ Ampcode + Wolfram Skill

  • Single prompt → complete solution
  • Executable Mathematica notebook
  • 3 interactive Manipulate panels
  • Numerical solver with fallback methods
  • Production-ready .nb with 12 sections
  • Automated 6-point syntax validation
  • Self-consistency verification catches errors
  • Minutes, not hours
Why It Works

The Infrastructure Stack

🤖 Ampcode Agent

AI orchestrator that reads papers, plans the approach, writes code, and validates output end-to-end

📚 CandleKeep Library (60+ docs)

RAG-backed Wolfram Language reference — correct syntax for Manipulate, FindRoot, Plot, NIntegrate, and more

⚙️ Wolfram-Mathematica Skill

Phase 4B self-consistency verification + Phase 4C plain-English proof generation — custom skill with .nb format constraints

🔒 6-Point Syntax Validator

Invalid characters, BoxData check, bracket balance, notebook structure, string escaping, cell grouping — all automated

Ampcode: Research Paper to Mathematica Notebook

Ampcode + Wolfram Mathematica

From Research Paper to Self-Consistent Proof

One prompt. Self-consistent proof. Interactive notebook.

ESL  •  ⚡ Ampcode  •  ◆ Wolfram Mathematica