LeanEconomics: Building Economic Theory in Lean

I’ve started playing around with using Lean for Macroeconomics. You should join in :wink:

I built Lean proofs of the existence of stationary general eqm in both the Aiyagari and Huggett models. I build proof of uniqueness of the stationary general eqm in the Aiyagari model with CES utility parameter mu=1 (log utility) [proof applies to mu<=1].

I set up the ‘frontier’ on how close/far-away from a proof of uniqueness of stationary general eqm in the Aiyagari model with mu=3,5 (Aiyagari 1994 paper’s other parameterizations), and how close/far-away from a proof of uniqueness of stationary general eqm in the Huggett model.

There are also various comparative statics results, and lots of other things for these models.

None of these findings are new, they just provide Lean formalization of known results.

I put it all on a new “LeanEconomics” organization on Github.

Here is the repo: github.com/LeanEconomics/LeanEconomics

If anyone finds this interesting and wants to join in, just use github to ask to join the organization, or set up a pull request. The more the merrier :slight_smile: You can do anything vaguely economics here, happy to accept micro as well as macro contributions.

Claude built all the lean, and the pdf explanation of what has been proved. My job is prompting next task and suggesting ideas and papers that will help build things out. I do know the area as I wrote a related paper.

PS. Claude wrote the pdf and plays up the originality and contribution. While it is novel in a narrow sense I don’t feel like this is yet really anything beyond what was already understood even if nobody quite so cleanly dotted the i’s and crossed the t’s.

PPS. Claude Fable does not like the odds of trying to prove uniqueness of stationary general eqm in Aiyagari model with mu=3,5. This is hard stuff, not like that wussy Navier-Stokes eqn :winking_face_with_tongue: :rofl: :upside_down_face:

PPPS. One motive for me was this chat. They discuss how Lean can be used to prove that things about algorithms, like that two compression algorithms are equally lossy (and we know from running them that one compresses to smaller size). This can allow designing better algorithms.

3 Likes

If anyone out there want to join in and is looking for something to start with you can: (i) tell AI to install lean, then tell it to pull the LeanEconomics repo, (ii) formalize lots of results about Solow-Swan economic growth model, and then about Ramsey-Cass-Koopmans, or any other model you want to try for, (iii) join the github org, or just tell your AI to set up a pull request.

1 Like

Very interesting, Robert! Besides the video, can you please point me to another Lean reference/tutorial? Thank you!

I am not aware of a specific Lean reference/tutorial (of course they are out there somewhere). But you don’t really need nor even want to be able to read/write Lean. Your AI will read/write Lean, not you. The point of Lean is that it allows you to trust AI output, and trust is normally the achilles heel of AI output.

One key point is that you neither need, nor want, to read/write Lean yourself. The point of Lean is to allow your AI to do math without you needing to check the lines of code. Lean was built so that the lean code only runs if the maths is correct. So you can ask AI to write Lean to prove X, and if it runs (no “sorry” as Lean calls it), then you know the AI really did prove X. This removes the main difficulty of using AI, which is being able to trust anything AI does. If AI says it proved X using Lean, know you for a fact that X has been proved, and you only need to trust the AI when it tells you what X is. Since asking AI what X is just depends on translating the result from one format (Lean) to another format (e.g., pdf) this is an exercise where AI is highly trustworthy.

You can see this in the recent announcement by OpenAI that they solved the Navier-Stokes with a counterexample to the existence and smoothness problem. Nobody wondered if their proof was correct or not because they announced that it was proved in Lean, but equally noone actually read the proof. Because it is in Lean we all know that it is correct, and we only have to trust that the proof is about what they say it is. Contrast this with the proof back in 1989 of the Four Colour Theorem. “At first, The New York Times refused, as a matter of policy, to report on the Appel–Haken proof, fearing that the proof would be shown false like the ones before it. Some alleged proofs, like Kempe’s and Tait’s mentioned above, stood under public scrutiny for over a decade before they were refuted.” [Wikipedia] With Lean there is no waiting months or years while other people read and confirm, if the Lean code runs it is correct.

This is why Lean, which has existed for over a decade, recently moved from an esoteric thing a few mathematicians used to being widespread. Because it is no longer a programming language you use, instead it is a programming language that allows you to trust AI.

So how do I use Lean? I just chat with Claude. My work in the LeanEconomics repo began with me saying [all the following paraphrases my Claude Code session, R=robert, C=claude]:
R: I want to do a project in folder X, we are going to prove existence of equilibrium in Bewley-Imrohoroglu-Huggett-Aiyagari models using Lean. Install Lean and get a copy of Mathlib, read the three papers I uploaded (two of which contain proofs of existence). Give me a proposal starting with a proof that the value and policy fn have a unique solution.
C: I installed Lean. I would like to use git so we can track progress. We need to do X, Y and Z to prove that the value and policy fn have a unique solution. The first thing that we need which is not in mathlib is Berges maximum theorem.
R: Do Berges maximum theorem, we will use the repo https://github.com/LeanEconomics/LeanEconomics
C: done Berges maximum theorem, next is X, Y and Z
R: do X and Y, then report back
C: done, next is Z
R: do Z
C: done Z
R: give me a progress report, what is done and suggest next steps
etc.

This is how things went. I just chat with Claude about Math. Sometimes Claude just does things (especially if you give it a copy of the theorem and proof that already exist). I chose the existence and uniqueness of BIHA stationary eqm because it is a topic I have worked on before, so occasionally there were chats like,
C: next I will use the Feller property to prove uniqueness of the stationary agent distribution
R: should we do both Feller and Mixing conditions?
C: good idea, now doing both

Or another chat
C: I cannot apply Lasry-Lions to Aiyagari as it requires a shared distribution agent across interest rates
R [a few hours later I had an idea and returned to this]: We know that if you start from an arbitrary initial guess, then you converge to the unique stationary agent distribution, can we apply Lasry-Lions using the same arbitrary initial guess for both interest rates
C: yes, we now have Lasry-Lions applied to Aiyagari. But the Lasry–Lions conclusion needs the pairing to be monotone in the distribution, and for a coupling through a price it is not, which is Graber and Matter’s point.

Eventually once I felt we had proved enough,
R: write a pdf explaining our results
C: here it is, in filepath X

I glanced briefly at the contents of a few lean files once we were done, but I certainly cannot read nor write Lean. That is however the point. Lean is not for me, lean is for Claude. So that when Claude tells me we proved X, I know that we actually did prove X. What I did read was the pdf, and I checked this contained the statements what I expected. I just trust that the pdf really is what the Lean is proving.

The whole process is quite fun, although also rather quite disconcerting. You focus on the main math concepts, and Claude+Lean does all the actual lines of proof. Fun as you only think about the math concepts. Disconcerting as you can feel the ground shifting underneath your feet (probably less disconcerting if you are younger).

Long story short. Tell Claude (or whatever AI you use) to install Lean (the programming language) and Mathlib (a collection of mathematical objects/results you will build on). Then just start playing, pick a mathematical result you already understand for your first run, as this way you will understand everything Claude tells you about what it is doing.

PS. As mentioned, while you know for a fact the AI did prove X because the Lean code runs (no “sorry”) you are still dependent on the AI to ‘translate’ X into, e.g., pdf so that you can read what X actually states. Personally, I find that one of the few tasks I can 100% trust AI on is translating documents from one format to another. Actually the resulting freedom from formats is one of my favourite things about AI. Instead of writing equations in latex, I write them by hand, take a photo, and ask Claude to write up the eqns in photo as latex. Or I print a paper, write on it in red pen, scan, ask Claude to turn my red pen into a referee report. This freedom to work in whatever format is easiest/most enjoyable for me, and not have to care about what the final format needs to be because Claude will just convert it, is possibly my favourite thing about AI. So far across hundreds of ‘translations’ between formats I am yet to have Claude fail to nail it, so when I ask for the pdf of the Lean results, I trust that the pdf of the theorem is correct, and we already know the proof of the theorem is correct because Lean is sorry-free.

2 Likes

Thank you for the detailed answer :slight_smile: I will follow your advice and try it with Codex, I don´t use Claude :stuck_out_tongue:

Cheers

2 Likes

I’m sure it will be fine, but fingers crossed you don’t accidentally hack Hugging Face as part of trying to prove a result in Economics :upside_down_face:

PS. For implementing already-existing results Opus (the second best Claude model) was plenty, and you can probably even get away with something lower powered (I did not try). I only turned on Fable (the best Claude model) when we finished formalizing things that have already been done and started taking shots at previously unproven results. Point is that for most things you don’t need a top model to prove, which will help conserve tokens.

1 Like