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

Ampcode + Wolfram

From Research Paper to Working Mathematica Notebook

Ampcode Workflow

The Ampcode Workflow

Extract → Implement → Execute → Novel Results

The Challenge

What GPT-5 Couldn't Do

Professor Gilo's paper on insurance collusion contains Lemma 1 — a nuanced mathematical proof involving implicit differentiation, Arrow-Pratt risk aversion, and limit arguments. GPT-5 kept making algebraic errors when trying to verify it and apply it to CRRA utility.

❌ GPT-5 Failures

  • Incorrect implicit differentiation of FOC
  • Wrong Arrow-Pratt substitution steps
  • Missed limit behavior at P→0 and P→1
  • Could not produce executable code
  • Repeated mistakes across multiple attempts

✅ What Was Needed

  • Verify every equation (14–19) step by step
  • Compute optimal α* numerically via FOC
  • Apply Lemma 1(i) to CRRA utility U=A^(1-γ)/(1-γ)
  • Find critical γ threshold analytically
  • Interactive notebook for Professor Gilo
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 "Avraham_and_Gilo_Insurance_collusion". 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 Professor Gilo.

That's it. No manual equation entry. No debugging. No iteration.

Under The Hood

What Happens Automatically

📄 Step 1

AI reads the full PDF and extracts every equation

📚 Step 2

CandleKeep library provides Wolfram Language syntax reference

⚙️ Step 3

Skill generates validated .nb with 12 sections

✅ Step 4

Syntax validation: brackets, characters, structure

🔧 Infrastructure Stack

  • Ampcode Agent — orchestrates the entire pipeline
  • Wolfram-Mathematica Skill — paper-to-notebook generation rules
  • CandleKeep Library — 60+ Wolfram Language reference docs
  • PDF Extraction — equations, definitions, proof steps
  • 6-Point Syntax Validator — ensures error-free .nb files
The Paper

Avraham & Gilo (2025)

Insurance Collusion and Imperfect Competition when Insurers Increase Risk

📋 Model Setup

  • Wealth W, Harm H, probability P
  • Loading factor q ≥ 1 (supra-competitive)
  • Risk-averse consumers: U''(A) < 0
  • Arrow-Pratt: Ra(A) = −U''(A)/U'(A)
  • Coverage α* ∈ [0,1] maximizes EU

📐 Lemma 1

  • (i) Single-peaked: If Ra decreases fast enough, ∃ P̄ maximizing demand
  • (ii) Monotone: If Ra is not too decreasing, demand falls with P
  • Proof: Implicit differentiation → Eq.(17)
  • Limit arguments at P→0 and P→1
Mathematics

Key Equations Verified

FOC (Eq. 1)

−(1−P)·q·U'(W₁) + (1−qP)·U'(W₂) = 0

Derivative (Eq. 17)

dα*/dP = [(1−P)αqH(Ra₁−Ra₂) + (q−1)/(1−qP)] / [−(1−P)H(qP·Ra₁ + (1−qP)·Ra₂)]

CRRA Specialization

U(A) = A^(1−γ) / (1−γ) Ra(A) = γ / A (DARA)

Critical γ Threshold

γ_crit = (q−1)·W·(W−H(1−α)) / (α·q·H²·(1−α))

All 6 equations (14–19) from the Appendix verified computationally in the notebook.

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
  • 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
Results

Key Findings

FindingDetail
✅ Lemma 1 Proof CorrectAll algebraic steps (Eq. 14→19) verified computationally
✅ CRRA Satisfies 1(i)For γ > γ_crit, insurance demand is single-peaked in P
📊 Critical γ ≈ 1–3For typical parameters (W=100, H=40, q=1.3)
🎯 Empirically RelevantStandard CRRA estimates γ=2–5 consistently satisfy Lemma 1(i)
📈 Phase DiagramComplete (γ, q) map showing Lemma 1(i) vs 1(ii) regions
✅ P→1 Limitdα*/dP proven negative — concavity argument confirmed
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
  • 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
  • Minutes, not hours
Why It Works

The Infrastructure Stack

🤖 Ampcode Agent

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

📚 CandleKeep Library (60+ docs)

RAG-backed Wolfram Language reference — correct syntax for Manipulate, FindRoot, Plot, etc.

⚙️ Wolfram-Mathematica Skill

Custom skill with notebook generation rules, .nb format constraints, and validation checklist

🔒 6-Point Syntax Validator

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

Ampcode: Research Paper to Mathematica Notebook

Ampcode + Wolfram

From Research Paper to Working Mathematica Notebook

One prompt. Verified proof. Interactive notebook.

ESL  •  ⚡ Ampcode  •  ◆ Wolfram Mathematica