[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"PxkrJcGtjh":3},"# Formalization of bounded arithmetic\nIn this project, I explore a way to formalize the results from the field of bounded arithmetic, most notably from the book [Logical Foundations of Proof Complexity](https://www2.karlin.mff.cuni.cz/~krajicek/cook-nguyen.pdf) from 2010 by Stephen Cook and Phuong Nguyen.\n\nThe design and motivation behind this project was presented at [AITP 2025](https://github.com/ruplet/presentation-aitp2025) in Aussois, France.\n\nIf successful, it could contribute towards:\n- providing a sensible way to certify computational complexity bounds of computer programs\n- providing a new way of extracting computer programs from mathematical theorems\n- perhaps getting a few logicians interested in formal verification\n\nPlease see [the $I\\Delta_0$ file](BoundedArithmetic/IDelta0.lean) for a demonstration.\n\n## Current todo list\n- we could probably do without modifying the mathlib.ModelTheory library (which now, modified, is in BoundedArithmetic/BoundedModelTheory)\n- it seems in reach to formalize that $I\\Delta_0$ $\\Delta_0$-defines the $\\text{Exp}(x, y)$ relation.\n- the design has to be slightly altered, as now when proving theorems in $I\\Delta_0$, we can't use already proved lemmas for $I\\text{OPEN}$. Typeclasses should be utilized to enable this behaviour\n- a huge milestone for this project is to formalize that $V\\text{TC}^0$ defines sorting\n- demonstrate how code can be extracted from constructive proofs of definability of functions\n- explore potential for proof automatization coming from finite axiomatizability of $V^0$\n\n## Problems in this project\n### Single-sorted logic only\nThe design of mathlib.ModelTheory is fundamentally single-sorted. When I started working on $V^0$, I re-wrote parts of the library to supports two sorts. It is feasible, but it is much easier to use explicit typing rules to encode two-sorted theory as a single-sorted one.\nThis is demonstrated in [file V0.lean](BoundedArithmetic/V0.lean)\n\n### Too classical\nModelTheory sets $\\exists \\phi := \\neg \\forall \\neg \\phi$ internally. This is not ideal, as in our setting we need to check if a formula is $\\Delta_0$, $\\Sigma_1$\\, $\\Pi_1$ etc. and defining the existential quantifier like this completely breaks this. It also breaks the computational content of the proofs. For these reasons, I rewrote parts of ModelTheory to **not** do this substitution. I applied `sorry` where it was necessary for the library to work; these should be very safe, as the change is not important for the semantics.\n\nNow it seems likely that we could do without modifying ModelTheory by just not caring about it. It is a task of a lower priority so I have left dealing with that for now.\n\n### Many lemmas missing\nWorking on this project at this stage requires proving many lemmas about ModelTheory.BoundedFormula definitions for our types. This is good and perhaps will contribute to making this library even better.\n\n### Very slow `simp`\nThis is something I have not dealt with yet, and it is a problem - simplifying the formulas resulting from creating the\ninduction axioms is very slow. It makes my VSCode laggy, my computer heat and, most annoyingly, the `apply?` and `rw?` tactics timeout. This definitely has to be addressed so that the simplifications are fast and simple.\n\n## Existing works\n### Foundation project\nMost notably, there is an active project on formalizing logic in Lean 4, [`Foundations`](https://github.com/FormalizedFormalLogic/Foundation).\nTheir design, however, doesn't enable to solve the crux problem I want to solve - to extract useful computation from the proofs. They focus on mathematical theories, whereas my desired focus are two-sorted theories capturing complexity classes. `Foundations`' design doesn't align well with  Mathlib.ModelTheory`, and also doesn't foster convenient extraction of code from proofs. Initially I thought that some of their proofs are conducted in the Lean model only (due to using lemmas from Mathlib inside of the object-theory proofs), this is not the case however. That was addressed in [my discussion with the developers](https://github.com/orgs/FormalizedFormalLogic/discussions/358).\n\n### Flypitch project\nIn a brekathrough effort, contributors of the [Flypitch project](https://github.com/flypitch/flypitch) managed to formalize the proof of\nindependence of continuum hypothesis from ZFC. They obviously considered the notion of provability. \n\n### Developments in Rocq\nThe environment of Rocq seemed to better foster this project, as the community of Lean is entirely nonconstructive and is\nless likely to be interested in results about reverse mathematics. Importantly, these projects exist:\n- [Rocq library to work with FOL](https://github.com/uds-psl/coq-library-fol.git)\n- [Notable work on FOL in Rocq](https://ps.uni-saarland.de/~bailitis/bachelor.php)\n\n### Just a shallow embedding\nThe obvious approach for this project is to embed our weak logic shallowly inside of Rocq / Lean / Isabelle.\nIt works well for the single axioms. There is a catch though - all these systems have a single `Prop` type (or equivalent)\nand have completely no way of expressing `$\\Delta_0-Prop$` or `$\\Sigma_1-Prop$`. Without a deep embedding of at least the\nsyntax of logic, it doesn't seem possible to proceed in any of the existing systems. And a deep embedding of the logic obviously doesn't foster any way of proving these deeply embedded formulas without implementing the whole model theory\nand proving in generalized model.\n\n### Shallow embedding + nice syntactical macros to ease proving in object theory\nInitially I had thought that the only feasible (i.e. not taking years of work) way to approach this is to\ndo everything in Lean, as a shallow embedding, but using syntactical macros provide frontend enabling\nproving in the object theory and making cheating harder / easily visible to the reader.\n\nI found some pointers on how could it looks like:\n- [Presentation by Simon Hudon](https://lean-forward.github.io/lean-together/2019/slides/hudon.pdf)\n- [Iris Proof mode for Lean](https://github.com/leanprover-community/iris-lean/blob/master/src/Iris/ProofMode/Display.lean)\n\nObviously, our current approach is good enough and doesn't need improving the frontend for now.\n\n## Contact\nPlease contact me at ruplet+bounded at ruplet dot com.\n\n## History of the project\nThis project is a part of my Master's thesis at the University of Warsaw.\nMy Master's project was to answer how to design programming languages to capture precisely a particular complexity class.\nThe works are in a [separate repository](https://github.com/ruplet/oracles).\n\nThis project, as my whole Master's program, has been supported by the [ZSM IDUB program](https://inicjatywadoskonalosci.uw.edu.pl/dzialania/iii-2-2/ios/).\n",1780846768620]