Paper deep dive
Just Type It in Isabelle! AI Agents Drafting, Mechanizing, and Generalizing from Human Hints
Kevin Kappelmann, Maximilian Schäffeler, Lukas Stevens, Mohammad Abdulaziz, Andrei Popescu, Dmitriy Traytel
Intelligence
Status: succeeded | Model: Gemma-4-26B-A4B | Prompt: intel-v1 | Confidence: 90%
Last extracted: 7/18/2026, 4:10:10 PM
Summary
This paper addresses the problem of generating complete and minimal type annotations for rank-one polymorphic lambda-calculus terms in the Isabelle proof assistant. The authors provide a formal metatheoretical account of the Smolka-Blanchette algorithm, which ensures that printed terms can be reparsed and type-inferred to recover the original term (the 'round-trip' property). The study highlights a collaborative workflow where human experts and LLM-powered AI agents independently draft proofs, which are then autoformalized in Isabelle/HOL. The AI agents successfully mechanized the proofs, and human hints were used to generalize the algorithm, demonstrating the efficacy of AI in formalizing programming language metatheory.
Entities (10)
Relation Signals (7)
Isabelle/HOL → usedfor → Autoformalization
confidence 95% · formalize it in Isabelle/HOL
Claude Opus 4.6 → usedby → AI Agent
confidence 92% · As our LLM, we used Claude Opus 4.6
AI Agent → performs → Autoformalization
confidence 90% · AI agent autoformalizes both in Isabelle
Smolka-Blanchette algorithm → solves → Type annotations
confidence 90% · Smolka, Blanchette et al. ... devised a solution to the correct printing problem
Smolka-Blanchette algorithm → ensures → Round-trip property
confidence 88% · print it in a way so that reparsing it and using type inference afterwards yields the original term
Smolka-Blanchette algorithm → implementedin → Isabelle
confidence 85% · Their implementation is part of the Isabelle distribution
Damas-Hindley-Milner → underpins → Type inference
confidence 80% · classic Damas-Hindley-Milner type inference result
Cypher Suggestions (0)
No Cypher suggestions yet.
Abstract
Abstract:Type annotations are essential when printing terms in a way that preserves their meaning under reparsing and type inference. We study the problem of complete and minimal type annotations for rank-one polymorphic $\lambda$-calculus terms, as used in Isabelle. Building on prior work by Smolka, Blanchette et al., we give a metatheoretical account of the problem, with a full formal specification and proofs, and formalize it in Isabelle/HOL. Our development is a series of experiments featuring human-driven and AI-driven formalization workflows: a human and an LLM-powered AI agent independently produce pen-and-paper proofs, and the AI agent autoformalizes both in Isabelle, with further human-hinted AI interventions refining and generalizing the development.
Tags
Links
- Source: https://arxiv.org/abs/2604.15713v1
- Canonical: https://arxiv.org/abs/2604.15713v1
Trouble viewing inline? Open PDF directly →
Full Text
108,591 characters extracted from source content.
Expand or collapse full text
11institutetext: Department of Computer Science, University of Sheffield, United Kingdom22institutetext: Department of Informatics, King’s College London, United Kingdom 33institutetext: Department of Computer Science, University of Copenhagen, Denmark Just Type It in Isabelle! AI Agents Drafting, Mechanizing, and Generalizing from Human Hints Kevin Kappelmann Maximilian Schäffeler Lukas Stevens Mohammad Abdulaziz Andrei Popescu Dmitriy Traytel Abstract Type annotations are essential when printing terms in a way that preserves their meaning under reparsing and type inference. We study the problem of complete and minimal type annotations for rank-one polymorphic λ-calculus terms, as used in Isabelle. Building on prior work by Smolka, Blanchette et al., we give a metatheoretical account of the problem, with a full formal specification and proofs, and formalize it in Isabelle/HOL. Our development is a series of experiments featuring human-driven and AI-driven formalization workflows: a human and an LLM-powered AI agent independently produce pen-and-paper proofs, and the AI agent autoformalizes both in Isabelle, with further human-hinted AI interventions refining and generalizing the development. 1 Introduction Some 30 years ago, Larry Paulson taught the working ML111Hereby, we refer to the programming language Standard ML, and its spiritual successors, implementations, and variants such as OCaml, Poly/ML and Isabelle/ML. programmers how to pretty print [34]. His textbook algorithm is mainly concerned with the printing layout for improved legibility, and has inspired the pretty printers of types, terms, and theorems used in the Isabelle proof assistant to this day. When printing Isabelle’s terms, or more generally terms of the typed lambda calculus (§˜2), in addition to legibility, it is crucial to preserve the type information. Specifically, we are interested in the following round-trip property: starting from a fully typed term, we wish to print it in a way so that reparsing it and using type inference afterwards yields the original term. For example, printing the term (cα,dα)(c_α,d_α)222We prefer the compact tτt_τ over Isabelle’s t::τt::τ type annotation syntax. with polymorphic constants c and d as (c,d)(c,d) violates this property: invoking type inference yields the more general typing (cα,dβ)(c_α,d_β). Achieving the round-trip hence requires type annotations. Since legibility remains a desideratum, these annotations should be as sparse as possible while still constraining type inference to recover the original term. Smolka, Blanchette et al. [39, 38, 8] identified these requirements and formulated the type annotation problem in the context of Isar proof reconstruction for Sledgehammer [33]. They call the round-trip property completeness, and they are interested in a complete solution that is also minimal. We use completeness and minimality as the correct printing problem’s specification (§˜3). Smolka, Blanchette et al. [39, 38, 8] also devised a solution to the correct printing problem, indicating that full minimality (w.r.t. a function assigning costs to annotation positions) is NP-hard, they settle for a tractable greedy algorithm, producing a complete, locally minimal solution. Their implementation is part of the Isabelle distribution and has been reused beyond Isar proof reconstruction in different contexts in which terms are printed: sketch and explore [20], super_sketch [40], AutoCorres2 [9], types-to-sets [31], and Apply2Isar [7]. Despite widespread usage, the algorithm’s implementation contained a completeness-compromising issue in one optimization. In the Isabelle2025-2 release, (cα,dα)(c_α,d_α) is printed as (c,d)(c,d)—the type annotation is incorrectly dropped. In addition, it is difficult to convince Isabelle to actually print type annotations correctly when they are attached to constants and bound variables: [][]_ nat\; list gets printed as [][] and λx.xλ x.\,x_ nat as the garbled _type_constraint_. We resolved these issues by correcting the optimization, forbidding annotations on bound variables in favor of annotating binders, and adding a custom print translation that preserves all annotations inserted by the algorithm. We also set up a testing environment for the algorithm using Mirabelle [17]. These implementation problems, however, also exposed a deeper issue: without a precise formal account of what the algorithm is supposed to guarantee, it is difficult to explain exactly why an optimization is unsound, to justify the repairs, or to rule out similar regressions. Alas, this paper is not about our technical refinements of the implementation. Our main goal as working programming-language metatheorists is to understand the type annotation problem precisely, with formal statements and complete proofs. (Smolka, Blanchette, et al. [39, 38, 8] give only informal claims and no proofs.) At the same time, we also identify as working metatheory formalizers and thus want a proof assistant to validate our proofs. Being modern working metatheorists and formalizers, we would like to conduct both activities assisted by modern technology, particularly large language models (LLMs), thus corroborating numerous recent accounts of their usefulness in our field. To this end, we conduct the following experiments contrasting human-driven and AI-driven activities, starting from Smolka, Blanchette, et al.’s informal description, the Isabelle/ML implementation, and an example algorithm execution: 1. A human expert formalizes the type annotation problem’s metatheory on paper. We present this in §˜2, 3 and 4, an occasion to describe the problem in detail. 2. Independently, an LLM-powered AI agent formalizes the problem’s metatheory on paper. We discuss the experimental setup and how the result differs from the human pen-and-paper formalization (§˜5). Drafts were iteratively refined through human reviews. Some feedback also went in the other direction: AI’s work has informed the human formalizer to prove local minimality. 3. A second AI agent (disconnected from the first) formalizes both pen-and-paper proofs in Isabelle/HOL. Both resulting autoformalizations333Autoformalization can refer to translating natural language statements to a formal system. Here, we adopt the deeper reading coined by Urban [42], in which not only statements, but also proofs are translated to and checked by a proof assistant. use mostly the same setup; we discuss differences in the experience (§˜6). 4. A human expert intervenes with the AI’s pen-and-paper formalization, observing that a core part of the algorithm could be generalized by reducing it to a standard problem, for which a rich theory as well as off-the-shelf algorithms exist. The AI agent analyses the human hint, shows the reduction to be correct, and updates the Isabelle formalization to do the same (§˜7). To our own surprise, all experiments were successful. We have obtained three Isabelle formalizations of the desired results, without writing a single line of Isabelle ourselves. As our LLM, we used Claude Opus 4.6, a state-of-the-art general purpose model with strong reasoning capabilities—but, as far as we know, without a specific focus on interacting with proof assistants in general, nor Isabelle specifically. Claude proved a capable, although not logically infallible, companion: one that can substantially amplify the human experts’ work. In contrast to prior work in autoformalization (§˜8), which typically starts from pen-and-paper proofs and/or targets classic mathematics, we begin with an algorithm that lacks formal correctness specifications. Another contribution is autoformalization of programming language metatheory, which has been largely unexplored. Finally, we are the first to report on a comprehensive autoformalization to Isabelle with a simple, reusable setup and best practices for the community. The input and output data of our experiments is available on Zenodo [25]. 2 Syntactic Preliminaries Next we introduce the necessary background: the syntax of types and terms, and the typing relation for rank-one polymorphic λ-calculus. Our presentation will be tailored to the forthcoming discussion of the Smolka-Blanchette type annotation removal algorithm, in that our notion of terms will be more general than usual, allowing annotations at any position in the term’s abstract syntax tree. The material in §˜2, 3 and 4 was not used for the AI pen-and-paper proofs (§˜5). 2.1 Types For the entire paper, we fix an infinite set TVar of type variables (tyvars for short), ranged over by α,βα,β, and an infinite set Var of term variables (vars for short), ranged over by x,y,zx,y,z. We also fix a type structure, i.e., a pair (,)( K, arOf) where K, ranged over by κ, is the set of type constructors, and :→ℕ arOf: K , is a function associating arities to the type constructors. The types, ranged over by σ,τσ,τ, forming the set Type, are given by the grammar σ::=α∣σ⇒τ∣(σ1,...,σ(κ))κσ\;::=\;α\, \,σ τ\, \,( _1, . 3.0mu. 3.0mu., _ arOf(κ))\,κ. Thus, a type is a tyvar, or the function type constructor ⇒ applied to two types, or another type constructor κ postfix-applied to a number of types matching its arity. Finally, we fix a signature for the type structure (,)( K, arOf), i.e., a pair Σ=(,) =( C, ctpOf), where: C, ranged over by c, is a set of symbols called constants, and :→ ctpOf: C→ Type is a function associating a type to every constant. A (type) substitution is a function ρ:→ρ: TVar→ Type with finite support, in that ρ(α)≠αρ(α) =α for all but a finite set of tyvars. For a substitution ρ and a type σ, σ[ρ]σ[ρ] denotes the application of ρ to σ. For a type σ, (σ) TV(σ) denotes the set of its (occurring) tyvars. We say that σ is an instance of τ via a substitution ρ, written σ≤ρτσ _ρτ, when σ=τ[ρ]σ=τ[ρ]; and that σ is an instance of τ, or that τ is more general than σ, written σ≤τσ≤τ, when there exists ρ such that σ≤ρτσ _ρτ. For two substitutions ρ and ρ′ρ , their composition ρ∙ρ′ρ\, \,ρ is defined by (ρ∙ρ′)(α)=ρ′(α)[ρ](ρ\, \,ρ )(α)=ρ (α)[ρ]. We write σ/ασ/α for the substitution that takes α to σ and any other tyvar to itself. We write ρ[α←σ]ρ[α←σ] for the substitution obtained from updating ρ at α with σ, i.e., acting the same as ρ on all tyvars except for α, where it returns σ. We will work with elements of the set ⊥=∪⊥ Type_ = Type∪\ \ (where ⊥∉ ∉ Type), which we call maybe-types, and let ξ,ζξ,ζ range over them. The operators TV and _[_]\_[\_] are extended from Type to ⊥ Type_ by defining (⊥)=∅ TV( )= and ⊥[ρ]=⊥ [ρ]= . 2.2 Terms The partially typed terms (which we simply call terms), ranged over by s,ts,t, forming the set Term, are given by the grammar t::=xξ∣cξ∣(t1t2)ξ∣(λxξ.t)ζt\;::=\;x_ξ\, \,c_ξ\, \,(t_1\,t_2)_ξ\, \,(λ x_ξ.\,t)_ζ. We call xξx_ξ a (maybe-)typed variable and cξc_ξ a constant instance. Thus, a term is either (1) a typed variable, (2) a constant instance, (3) an application decorated with a maybe-type, or (4) a λ-abstraction of a typed variable, decorated with a maybe-type. Thus, our terms are “decorated” with maybe-types on any occurring variable or constant, as well as at any subterm. We think of an actual type decoration (i.e., when the maybe-type is a type) as a type annotation, and of a ⊥ decoration as the absence of a type annotation. Therefore, in examples we will sometimes omit some ⊥ decorations, thus writing, e.g., λxα.yβλ x_α.\;y_β instead of (λxα.yβ)⊥(λ x_α.\;y_β)_ . Our term decoration scheme captures the process of type inference—of which we think of as “completing” a term such as λxα⇒β⇒γ.xcλ x_α β γ.\;x\;c to a fully annotated term such as (λxα⇒β⇒γ.(xα⇒β⇒γcα)β⇒γ)(α⇒β⇒γ)⇒β⇒γ(λ x_α β γ.\,(x_ light-gray$α β γ$\,c_ light-gray$α$)_ light-gray$β γ$)_\, light-gray$(α β γ) β γ$, where the highlighted types are the ones that have been inferred, culminated with the overall type at the top, (α⇒β⇒γ)⇒β⇒γ(α β γ) β γ. Additionally, this scheme allows for a smooth presentation of the algorithm that we will study, which, starting from a fully annotated term, repeatedly removes redundant annotations. We let (t) TV(t) be the set of tyvars occurring in t, i.e., occurring in all the type annotations from t; and t[ρ]t[ρ] be the application of the substitution ρ to t, which is defined by applying ρ to (all the types occurring in) t. We let (t) FTV(t) be the set of free typed variables occurring in t; e.g., (λxσ.yσ⇒τxσ)=yσ⇒τ FTV(λ x_σ.\;y_σ τ\,x_σ)=\y_σ τ\. We extend the “instance of” relation from types to terms: t≤ρst _ρs is defined as t=s[ρ]t=s[ρ], and t≤st≤ s is defined as the existence of ρ such that t≤ρst _ρs; in this case, we say t is an instance of s, or that s is more general than t. A term will be called: • unambiguous, if its binding variable occurrences are non-repetitive, in that there exists no variable x and (possibly equal) maybe-types ξ and ζ such that λxξλ x_ξ and λxζλ x_ζ occur at two different positions in a term; • a fully typed term (F-term), when all its occurring maybe-types are types; • a Church-typed term (C-term), when (1) all maybe-types annotating its application and abstraction subterms are ⊥ , and (2) all maybe-types annotating its constants and variables, as well as its binding variables, are types. The above concepts have straightforward inductive definitions. We let FTerm, and CTerm denote the subsets of Term consisting of the F-terms and C-terms, respectively. We let u,vu,v range over F-terms. A position is a list of numbers in 1,2\1,2\, identifying the location of a subterm or a binding variable in a term via its unique path. (t) Poss(t) denotes the set of positions of term t. If p∈(t)p∈ Poss(t), we write (t,p) mtpOf(t,p) for the maybe-type decoration at that position. (Details in App. 0.A.) For example, if t is (λx.(f⊥x⊥))⊥(λ x_ nat.\;(f_ \,x_ )_ bool)_ , then (t)=[],[1],[2],[2,1],[2,2] Poss(t)=\[],[1],[2],[2,1],[2,2]\; (t,[])=⊥ mtpOf(t,[])= , (t,[1])= mtpOf(t,[1])= nat, (t,[2])= mtpOf(t,[2])= bool, and (t,[2,1])=(t,[2,2])=⊥ mtpOf(t,[2,1])= mtpOf(t,[2,2])= . We write (t) mtpOf(t) instead (t,[]) mtpOf(t,[]). For F-terms u we write (u,p) tpOf(u,p) and (u) tpOf(u) instead of (u,p) mtpOf(u,p) and (u) mtpOf(u) (since we know that this is a type). On ⊥ Type_ , we define the relation ⊑ by ξ⊑ζξ ζ iff ξ∈⊥,ζξ∈\ ,ζ\. This order is extended to Term, by defining the annotation subsumption relation t⊑st s to mean that s is obtained from t by adding zero or more type annotations: ξ⊑ζxξ⊑xζ‾ξ⊑ζcξ⊑cζ‾s⊑s′ t⊑t′ ξ⊑ξ′(st)ξ⊑(s′t′)ξ′‾ξ⊑ξ′ t⊑t′ ζ⊑ζ′(λxζ.t)ξ⊑(λxζ′.t′)ξ′‾ x_ξ x_ζξ ζ c_ξ c_ζξ ζ (s\;t)_ξ (s \;t )_ξ @proof@logical@and s s t t ξ ξ (λ x_ζ.\;t)_ξ (λ x_ζ .\;t )_ξ @proof@logical@andξ ξ t t ζ ζ For a term t and position p∈(t)p∈ Poss(t), let t[p:=⊥]t[p:= ] denote the term obtained from t by erasing the type annotation at p (i.e., turning its decoration into ⊥ ). For a term t, the (completely unannotated) term (t) erase(t) denotes the term obtained from t by erasing all its type annotations. Note that (t)⊑t[p:=⊥]⊑t erase(t) t[p:= ] t. The well-typedness predicate ⊢ is defined on FTerm by the following rules: ⊢xσ‾σ≤(c)⊢cσ‾ x_σ c_σ≤ ctpOf(c) ⊢u ⊢v (u)=(v)⇒σ⊢(uv)σ‾⊢u ∀xτ∈(u).τ=σ⊢(λxσ.u)σ⇒(u)‾ (u\,v)_σ @proof@logical@and u v tpOf(u)= tpOf(v) σ (λ x_σ.\,u)_σ tpOf(u) @proof@logical@and u∀ x_τ∈ FTV(u).\;τ=σ Note that the condition ∀xτ∈(u).τ=σ∀ x_τ∈ FTV(u).\;τ=σ guarantees that terms with type-incompatible bindings are ill-typed, such as λxα.xβλ x_α.\;x_β. Alternatively, this would also be achieved by the explicit consideration of typing contexts. An F-term u is said to be a well-typed completion of a term t, provided t⊑ut u and ⊢u u. We call a term t typable when it has a well-typed completion. Note that for F-terms, typability is equivalent to well-typedness. In our formalism, the process of type inference for a (partially annotated) term t means producing a most general well-typed completion for t. We will take for granted the classic Damas-Hindley-Milner type inference result [21, 32, 13, 12], which we only need in existential form: Thm 1 Assume that t is a typable unambiguous term. Then there exists a most general well-typed completion of t (i.e., a ≤-maximal F-term among the F-terms u such that t⊑ut u and ⊢u u). We let (t) mgen(t) denote a choice (unique up to tyvar renaming) of a most general well-typed completion of t. 3 The Problem of Correct Printing and the Smolka-Blanchette Algorithm The terms used internally by Isabelle are captured by our notion of unambiguous C-terms. A crucial property of these terms is that they contain enough information in order for their inferred type to be actually unique: Prop 2 Assume that t is a typable unambiguous C-term. Then there is only one well-typed completion of t (hence only one choice for (t) mgen(t)). We can now define a correct printing of an Isabelle term to be another term (not necessarily a C-term) that has the same type-free content and allows for the same unique most general typing as the original: Def 3 Given a typable unambiguous C-term t, a correct printing of t is a term s such that (t) mgen(t) is the unique most general well-typed completion of s. We are interested in a correct printing that is minimal w.r.t. the annotation subsumption relation, ⊑ . This is also the problem that Smolka and Blanchette have considered, leading to their implementation which is currently part of Isabelle. They have not formulated the definition of correct printing rigorously, but focused on more practical, operational matters. Namely, they described a criterion for deeming an annotation redundant, provided an implementation that starts with a fully annotated term and repeatedly removes positions deemed redundant for as long as possible following a reverse greedy pattern, and informally claimed minimality. Next, we discuss a simplified version of their algorithm and a detailed informal proof that it indeed achieves a minimal correct printing. The difference between what we will describe and what Smolka and Blanchette actually implemented is threefold: (1) we abstract away from the specific cost function that they employ when deciding the annotation at which of the eligible positions to remove, (2) we ignore a number of small optimizations, and (3) we ignore typing contexts altogether. Concerning (2), in future work we plan to extend our formal development (and our partnership with LLMs) to cover these optimizations as well, and possibly to even go beyond them together with a further sharpening of the implementation. Concerning (3), our motivation for avoiding contexts is that they are completely uninteresting for the correct printing problem—in that the tyvars (from (σi) TV( _i)) and variables (xix_i) from a typing context Γ=x1:σ1,...,xn:σn =x_1: _1, . 3.0mu. 3.0mu.,x_n: _n would be treated exactly as if they were part of the signature Σ , namely as nullary type constructors and constants; so the problem can be safely reduced to printing closed terms in the empty context. We express the Smolka-Blanchette algorithm (subject to the simplifications discussed above) by the function smobla which we define below, after defining the auxiliary functions coverage -0.44446ptTest and decrease. The ternary predicate coverage -0.44446ptTest acting on F-terms v∈v∈ FTerm, terms s∈s∈ Term and positions p∈1,2∗p∈\1,2\^*, is defined by (v,s,p)= coverage -0.44446ptTest(v,s,p)\;= p∈(s)∩(v)∧(s,p)≠⊥∧p∈ Poss(s)∩ Poss(v) mtpOf(s,p) = \; (∀α∈((v,p)).(∀α∈ TV( tpOf(v,p)).\; ∃q∈(s)∖p.α∈((v,q))∧(s,q)≠⊥)∃ q∈ Poss(s) \p\.\;α∈ TV( tpOf(v,q)) mtpOf(s,q) = ) As will be seen from the upcoming definitions, coverage -0.44446ptTest will be called with v being ((t)) mgen( erase(t)), the most general well-typed completion of the erasure of the original term t, and s being the current term obtained by repeated removal of position annotations from (t) mgen(t); so we will always have s⊑vs v, which (as we discuss in §4.2) will ensure (s)=(v) Poss(s)= Poss(v) and (s,q)⊑(v,q) mtpOf(s,q) tpOf(v,q). The predicate checks whether a position p on the one hand has an annotation within s, and on the other hand has all the tyvars occurring in v at that position covered by another annotation in s, in the sense that there is another position q that has an annotation within s and α occurs in v at q. We say that a function :×→1,2∗pickPos: FTerm× Term→\1,2\^* is coverage -0.44446ptTest-compatible when, for all v∈v∈ FTerm and s∈s∈ Term, if ∃p.(v,s,p)∃ p.\; coverage -0.44446ptTest(v,s,p) then (v,s,(v,s)) coverage -0.44446ptTest(v,s,pickPos(v,s)). Thus, compatibility means being a correct choice function for the position argument of coverage -0.44446ptTest. We let Compat denote the set of coverage -0.44446ptTest-compatible functions. Now, the function :×→ decrease: Compat× FTerm× Term→ Term is defined by (,v,s)= decrease(pickPos,v,s)\;= (,v,s[((v,s)):=⊥]), if ∃p.(v,s,p)s, otherwise \ array[]l decrease(pickPos,v,s[(pickPos(v,s)):= ]),&\\ 21.52771ptif $∃ p.\; coverage -0.44446ptTest(v,s,p)$&\\ s, otherwise array . Thus, decrease keeps removing annotations from s at positions chosen using pickPos provided they pass the coverage test. Finally, the function :×→ smobla: Compat× Term→ Term is defined by calling decrease on v=((t))v= mgen( erase(t)) (the fixed provider of tyvars that must stay covered) and s=(t)s= mgen(t) (the changing term from which annotations keep being removed, initially set to the fully annotated term (t) mgen(t)). (,t)=(,((t)),(t)) smobla(pickPos,t)= decrease(pickPos,\, mgen( erase(t)),\, mgen(t)) In the above algorithm, we can distinguish two components. First, there is the general-purpose reverse greedy component: The algorithm starts with a fully annotated term (t) mgen(t) and, via its decrease function, keeps removing annotations for positions p satisfying a given test, coverage -0.44446ptTest, for as long as such annotation carrying positions exist (and the choice of the exact position to remove is regulated by a coverage -0.44446ptTest-compatible parameter function pickPos). Then, there is the ad hoc component, given by the definition of coverage -0.44446ptTest, which is the heart of the algorithm. Intuitively, we are interested in removing annotations at positions for as long as we do not lose information about the (unique) typing of the term. The algorithm does not pursue this (clear yet non-effective) intuition directly, but in a roundabout manner: It first erases all type annotations from t and builds a most general well-typed completion for the erased term, v=((t))v= mgen( erase(t)). Then it proceeds based on the following crucial observation: The most general well-typed completion of the original term, s=(t)s= mgen(t), is less than or equally general as v, which means that the tyvars of v correspond position-wise to specific subterms of s. Then the protection against loss of typing information is offered through the test coverage -0.44446ptTest, which makes sure that any α∈(v)α∈ TV(v) is still “covered” by an annotation in s at a corresponding position, in that there is a position p such that (1) α appears in the type annotation at that position in v, and (2) p has a type annotation in s as well. Then the fact that the algorithm achieves (i) correct printing that is also (i) minimal (which is the subject of our proof development) essentially amounts to the fact that this test (i) guarantees the desired preservation of typing information and (i) nothing beyond that. For brevity, our presentation of the algorithm did not formally separate the generic from the ad hoc component. However, for the sake of conceptual cleanness and reusability, a mechanization should ideally do that. In §˜7 we report on how an AI agent has performed this separation based on a minimal prompt. 4 Human-Authored Paper Proof Development In this section we give a rigorous pen-and-paper description of our results about the type annotation problem, which we also call minimal correct printing problem, starting with the statements (§4.1) and then delving into the proofs (§4.2). We aim to provide enough detail for the reader to form an informed view of the statement and proof complexity involved in what we consider a fairly direct “no-nonsense” solution, and thereby to appreciate the extent of the creative effort an AI agent would require when starting from first principles. 4.1 The statements of the main results Our first goal will be to prove that the Smolka-Blanchette algorithm returns a correct printing of the original term (something that Smolka and Blanchette refer to as “completeness”): Thm 4 (Completeness) If t is a typable unambiguous C-term and ∈pickPos∈ Compat, then (,t) smobla(pickPos,t) is a correct printing for t. Then we will prove that what is being returned is a minimal such correct printing: Thm 5 (Minimality) If t is a typable unambiguous C-term and ∈pickPos ∈ Compat, then (,t) smobla(pickPos,t) is ⊑ -minimal among the correct printings for t. One may object to the notion of correct printing, hence to the statement of completeness, as being too weak. Indeed, s being a correct printing of t means that (t) mgen(t) is the unique most general well-typed completion of s—which makes sense because this is what the type inference algorithm produces. However, one may argue, we want (t) mgen(t) to be the unique well-typed completion of s (without the “most general” qualifier), because we do not want any alternative way to type the term sneaking in; let us call this (superficially) stronger notion a strong correct printing. We show that the two notions coincide, because the existence of two well-typed completions implies the existence of two most general ones. Prop 6 Assume s∈s∈ Term is unambiguous, and u,u′∈u,u ∈ FTerm are two distinct well-typed completions of s. Then there exist two distinct most general well-typed completions of s. This immediately gives: Corollary 7 Assume s∈s∈ Term is unambiguous. Then s is a correct printing of t if and only if s is a strongly correct printing of t. 4.2 Proof development Next we give an overview of our proof development leading the above results, namely Thm. 4, Thm. 5 and Prop. 6, as well as Prop. 2 which underlies the definition of correct printing. Appendix˜0.C gives full details. The development is supported by several types of background lemmas: (1) Constructor-aware inversion lemmas associated to inductively defined predicates such as ⊢ and ⊑ . These lemmas reconstitute “one inductive rule back” of history in situations where an inductive predicate holds with one of the arguments having a specific syntactic constructor at the top. For example, the λ-abstraction aware left inversion lemma for ⊑ states the following: If (λxζ.s)ξ⊑t(λ x_ζ.\;s)_ξ t then there exist s′s , ζ′ζ and ξ′ξ such that s⊑s′s s , ζ⊑ζ′ζ ζ , ξ⊑ξ′ξ ξ and t=(λxζ′.s′)ξ′t=(λx_ζ .\;s )_ξ . The (immediate) proofs of these lemmas combine the freeness (injectiveness) of the syntactic constructors with the standard inversion (elimination) rules stemming from inductive definitions. (Incidentally, Isabelle automates the process of inferring these lemmas via the inductive_cases command.) (2) Lemmas on syntax basics, describing properties of the occurring-variable and substitution application operators, TV and _[_]\_[\_]. These lemmas are mostly the typical ones proved when developing a theory of syntax, such as substitution compositionality, t[ρ∙ρ′]=t[ρ′][ρ]t[ρ\, \,ρ ]=t[ρ ][ρ], distributivity of TV along substitution, (t[ρ])=⋃α∈(t)(ρ(α)) TV(t[ρ])= _α∈ TV(t)\! TV(ρ(α)), and substitution extensionality (in the Isabelle ecosystem also known as substitution congruence), ∀α∈(t).ρ(α)=ρ′(α)∀α∈ TV(t).\,ρ(α)=ρ (α) implies t[ρ]=t[ρ′]t[ρ]=t[ρ ]. We will in fact need the converse of extensionality, which is slightly outside the usual repertoire in theories of syntax: t[ρ]=t[ρ′]t[ρ]=t[ρ ] implies ∀α∈(t).ρ(α)=ρ′(α)∀α∈ TV(t).\,ρ(α)=ρ (α). There are both type and term variants of these lemmas, and their proofs go by straightforward structural induction on types or terms (with the proofs of the latter using the former). (3) Annotation lemmas, by which we collectively mean simple lemmas about positions, type annotations at positions, and the annotation-removal operator and their interaction with substitution and occurring tyvars—stating, for example, that positions are not affected by substitutions, (t[ρ])=(t) Poss(t[ρ])= Poss(t), that substitution operates position-wise, (t[ρ],p)=(t,p)[ρ] mtpOf(t[ρ],p)= mtpOf(t,p)[ρ], and that deleting an annotation yields a decrease in the annotation ordering, t[p:=⊥]⊑t[p:= ] t. The proofs again proceed by straightforward structural inductions on terms. (4) The type preservation lemma, stating that substitution preserves typing, i.e., ⊢v v implies ⊢v[ρ] v[ρ], proved by induction on the definition of ⊢ . With these preparations, the proof justifying Prop. 2 is a low-hanging fruit. Proof(Prop. 2.) Let u and v be such that t⊑ut u, t⊑vt v, ⊢u u, ⊢v v. Then u=vu=v follows by induction on t, using the constructor-aware left inversion rules for ⊑ . The fact that t is a C-term is used in the variable, constant, and abstraction cases, ensuring that respective annotation is a type (not just a maybe-type). ∎ Moving towards the main results, we state lemmas about annotation subsumption and its interaction with the other operators. In particular, we need that ⊑ is a preorder on terms, does not affect the position sets, and interacts as expected with annotations at positions (in that s⊑ts t implies (s,p)⊑(s,p) mtpOf(s,p) mtpOf(s,p))—we will refer to these as the ⊑ -lemmas. Moreover, we need that less annotated terms yield more general completions, in that t⊑st s implies (s)≤(t) mgen(s)≤ mgen(t). This fact, henceforth called the (⊑,≤)( ,≤)-lemma, supports the main intuition behind the Smolka-Blanchette algorithm—which, as discussed in §3, decides on removing annotations taking advantage of the position synchronization offered by (t)≤((t)) mgen(t)≤ mgen( erase(t)), and this in turn follows from (t)⊑t erase(t) t. As a final preparation, we need some consequences of the (quasi-)generic reverse greedy component of the algorithm, namely that the result has fewer annotations than the original and that the coverage test no longer holds for the result. Now, the technical core of the correct printing theorem (Thm. 4) is expressed by the following “sandwich” property: If an F-term u on the one hand subsumes the annotations of a term s, and on the other hand is less general than a term v, i.e., is (⊑,≤)( ,≤)-sandwitched between s and v, such that all tyvars of v are covered by an annotation of s, then u is uniquely determined by s and v. Lemma 8 Assume s∈s∈ Term is unambiguous and u,v∈u,v∈ FTerm such that s⊑u≤vs u≤ v and ∀α∈(v).∃p∈(v).α∈((v,p))∧(s,p)≠⊥∀α∈ TV(v).\,∃ p∈ Poss(v).\,α∈ TV( tpOf(v,p)) mtpOf(s,p) = . Then u is the unique u′∈u ∈ FTerm such that s⊑u′≤vs u ≤ v. Proof From u≤vu≤ v, we obtain a substitution ρ such that u≤ρvu _ρv. Let u′∈u ∈ FTerm be such that s⊑u′≤vs u ≤ v, i.e., (1) s⊑u′≤ρ′vs u _ρ v for some ρ′ρ . We need to prove u′=u =u. By syntax basics, it suffices to fix α∈(v)α∈ TV(v) and to show that ρ(α)=ρ′(α)ρ(α)=ρ (α). From α∈(v)α∈ TV(v) and our assumption, we obtain p∈(v)p∈ Poss(v) such that (2) α∈((v,p))α∈ TV( tpOf(v,p)) and (s,p)≠⊥ mtpOf(s,p) = . With the ⊑ -lemmas and s⊑u,u′s u,u , this implies (3) (u,p)=(s,p)=(u′,p) tpOf(u,p)= mtpOf(s,p)= tpOf(u ,p). Moreover, by the annotation lemmas, we have (4) (u,p)=(v[ρ],p)=(v,p)[ρ] tpOf(u,p)= tpOf(v[ρ],p)= tpOf(v,p)[ρ], and similarly (5) (u′,p)=(v[ρ′],p)=(v,p)[ρ′] tpOf(u ,p)= tpOf(v[ρ ],p)= tpOf(v,p)[ρ ]. From (3), (4) and (5), we obtain (v,p)[ρ]=(v,p)[ρ′] tpOf(v,p)[ρ]= tpOf(v,p)[ρ ]. Applying syntax basics (specifically the converse of substitution extensionality) to this and (2) yields ρ(α)=ρ′(α)ρ(α)=ρ (α), as desired. ∎ Proof(Thm. 4) Let v=((t))v= mgen( erase(t)). By smobla’s definition, we have s=(,v,(t))s= decrease(pickPos,v, mgen(t)). We first prove φ(s′)⟶φ((,v,s′)) (s ) ( decrease(pickPos,v,s )) for terms s′s by induction on |≠⊥(s′)|| Poss_ = (s )|, where φ(s′)= (s )= (t)⊑s′⊑(t)∧ erase(t) s mgen(t) ∀α∈(v).∃p∈(v).α∈((v,p))∧(s′,p)≠⊥, ∀α∈ TV(v).\,∃ p∈ Poss(v).\;α∈ TV( tpOf(v,p)) mtpOf(s ,p) = , ≠⊥(s′)= Poss_ = (s )= p∈(s′)∣(s′,p)≠⊥. \p∈ Poss(s ) mtpOf(s ,p) = \. In the inductive proof, we distinguish two cases: (i) if ∃p.(v,s′,p)∃ p.\; coverage -0.44446ptTest(v,s ,p), then we apply the induction hypothesis together with ⊑ -lemmas, annotation lemmas, and some straightforward set-theoretic computation; (i) otherwise, we have (,v,s′)=s′ decrease(pickPos,v,s )=s , and the fact holds trivially. Now, since φ((t)) ( mgen(t)) holds, we obtain φ(s) (s). By the (⊑,≤)( ,≤)-lemma, we have (t)≤v mgen(t)≤ v. From this and φ(s) (s), by Lemma 8 we obtain that (t) mgen(t) is the unique F-term u such that s⊑u≤vs u≤ v. Since ⊢(t) mgen(t) and ∀u∈.s⊑u∧⊢u⟶u≤v∀ u∈ FTerm.\;s u\; \, u u≤ v (by the (⊑,≤)( ,≤)-lemma and the (t)⊑s erase(t) s fact), we obtain that (t) mgen(t) is the unique well-typed completion of s, i.e., the unique F-term u such that ⊢u u and s⊑us u. ∎ What we actually proved in Thm. 4 is the a priori stronger property that s is a strongly correct printing of t—as we did not assume u to be most general. It remains to prove Prop. 6 and the minimality theorem Thm. 5. These require further preparations. First, a trivial lemma about observable difference in annotations when descending on the annotation subsumption relation: Lemma 9 If s,s′s,s are terms such that s′⊏s s , then there exists p∈(s)=(s′)p∈ Poss(s)= Poss(s ) such that (s′,p)=⊥≠(s,p) mtpOf(s ,p)= = mtpOf(s,p). Then a crucial lemma allowing us to change an F-term’s instance (by changing the instantiating substitution) without affecting annotation subsumption: Lemma 10 Assume s is a term, v is an F-term and ρ,ρ′ρ,ρ are substitutions such that s⊑v[ρ]s v[ρ]. and ∀α,p.p∈(v)∧α∈(v,p)∧(s,p)≠⊥⟶ρ(α)=ρ′(α)∀α,p.\;p∈ Poss(v) α∈ TV(v,p) mtpOf(s,p) = ρ(α)=ρ (α). Then s⊑v[ρ′]s v[ρ ]. Finally, we need a lemma that allows us to construct a second well-typed most general completion from a given one with “loose” tyvars: Lemma 11 Assume s∈s∈ Term is unambiguous, and v is a most general well-typed completion of s such as (v)∖(s)≠∅ TV(v) TV(s) = . Then there exists a most general well-typed completion of s different from v. Proof(Prop. 6) Expanding the definitions, we have u≠u′u =u , s⊑us u, ⊢u u, s⊑u′s u and ⊢u′ u . Let v=(s)v= mgen(s). From the definition of mgen, we have ⊢v v and obtain the substitutions ρ,ρ′ρ,ρ such that u=v[ρ]u=v[ρ] and u′=v[ρ′]u =v[ρ ]. Since u≠u′u =u , by syntax basics we obtain α∈(v)α∈ TV(v) such that (a) ρ(α)≠ρ′(α)ρ(α) =ρ (α). We claim that α∉(s)α∉ TV(s). Assuming α∈(s)α∈ TV(s), the annotation lemmas yield p∈(v)=(u)=(u′)=(s)p∈ Poss(v)= Poss(u)= Poss(u )= Poss(s) such that (b) (s,p)≠⊥ mtpOf(s,p) = and (c) α∈((s,p))α∈ TV( mtpOf(s,p)). From these and s⊑vs v, we have (d) α∈((v,p))α∈ TV( tpOf(v,p)). From (b) and s⊑u,u′s u,u , we have (u,p)=(u′,p)=(s,p) tpOf(u,p)= tpOf(u ,p)= mtpOf(s,p). From this, by annotation lemmas we have (v,p)[ρ]=(v,p)[ρ′] tpOf(v,p)[ρ]= tpOf(v,p)[ρ ], which together with (a) and (d) yields a contradiction by syntax basics. Hence, α∈(v)∖(s)α∈ TV(v) TV(s). From this and v’s definition, by Lemma 11, we obtain v′v such that v′≠v =v and v′v is a most general well-typed completion of s. Thus, v and v′v are two distinct most general well-typed completions of s, as desired. ∎ Proof(Thm 5) Let s′s be an unambiguous term such that (a) s′⊏s s. Let v=((t))v= mgen( erase(t)). By Lemma 9, there exists p∈(s)=(s′)p∈ Poss(s)= Poss(s ) such that (b) (s′,p)=⊥≠(s,p) mtpOf(s ,p)= = mtpOf(s,p). Since by generic reverse greedy lemmas we have ¬(v,s,p) \; coverage -0.44446ptTest(v,s,p), we obtain α∈((v,p))α∈ TV( tpOf(v,p)) such that ∀q∈(s)∖p.α∈((v,q))⟶(s,q)=⊥∀ q∈ Poss(s) \p\.\;α∈ TV( tpOf(v,q)) mtpOf(s,q)= . With (a) and (b), this gives us (c) ∀q∈(s′).α∈((v,q))⟶(s′,q)=⊥∀ q∈ Poss(s ).\;α∈ TV( tpOf(v,q)) mtpOf(s ,q)= . Let ρ be such that (t)=v[ρ] mgen(t)=v[ρ]. From this, since (s)=(t) mgen(s)= mgen(t) by Thm. 4, we obtain (s)=v[ρ] mgen(s)=v[ρ], and therefore (1) s′⊑v[ρ]s v[ρ]. We choose a fresh type τ such that τ≠ρ(α)τ =ρ(α) (for example, a fresh tyvar), and let ρ′=ρ[α→τ]ρ =ρ[α→τ]. Using (c) and the definition of ρ′ρ , we obtain (2) ∀q∈≠⊥(s′),β∈(v,q).ρ(β)=ρ′(β)∀ q∈ Poss_ = (s ),β∈ TV(v,q).\;ρ(β)=ρ (β). For (1) and (2), applying Lemma 10, we obtain (3) s′⊑v[ρ′]s v[ρ ]. By the type substitution lemma, from ⊢v v we obtain (4) ⊢v[ρ′] v[ρ ]. Since α∈(v)α∈ TV(v) and ρ(α)≠ρ′(α)ρ(α) =ρ (α), by syntax basics (again the converse of the substitution extensionality lemma), we obtain (5) v[ρ]≠v[ρ′]v[ρ] =v[ρ ]. Thus, (1–5) tell us that v[ρ]v[ρ] and v[ρ′]v[ρ ] are two distinct well-typed completions of s. Finally, we apply Prop. 6 to obtain two distinct most general well-typed completions of s′s , as desired. ∎ Note that we used Prop. 6 (which forms the basis of the equivalence between correct printing and strong correct printing) in order to finalize our proof of minimality. This is natural, because in the proof it was easier to prove minimality in the extent of the (superficially) narrower concept of strong correct printing—which could then be lifted to minimality w.r.t. correct printing via Prop. 6. Summary of the human development. Unsurprisingly for a metatheory of syntax, a sizable number of simple lemmas were needed, having straightforward inductive proofs. In addition, some creativity was required to pin down the intuition of why the coverage test correctly models the typing information preservation goal (via results such as the sandwich ˜8 and the instance changing ˜10). Apart from the proof development per se, modeling the concepts required nontrivial design choices, such as working with terms decorated with maybe-types and introducing annotation subsumption ⊑ inductively. 5 AI-Authored Paper Proof Development In parallel to the human-authored development described in the previous section, we independently employed an AI agent to produce a pen-and-paper (LaTeX) specification and proofs for the Smolka-Blanchette algorithm. We first describe our technical setup (§5.1) and the paper generation process (§5.2), and then provide an analysis and a comparison with the human proof development (§5.3). 5.1 Technical setup Our setup is based on OpenCode [2], an open source AI coding environment. It provides AI agents with several tools, such as the ability to read and edit files, search the web, and usage of the command line and the Model Context Protocol (MCP). As our agent, we used Claude Opus 4.6-v1 [3], a state-of-the-art model optimized for coding and reasoning tasks. In each experiment, we provided the agent some background material (e.g., links to related work) and an experiment-specific AGENTS.md file as input. The AGENTS.md files contain the detailed instructions for the agent. The files were created by the agent itself from short hand-crafted prompts containing the problem statement and some guidelines (take notes, make backups, etc.). The experiments mimicked an academic peer-review process: The agent was instructed to create a complete artifact (a LaTeX document), which was then reviewed by human experts. The feedback was passed to the agent, and the process was repeated. 5.2 Generating the paper proofs Generating proofs for the Smolka-Blanchette algorithm poses challenges. First, their paper presentation of the concepts [39, 38, 8] is extremely informal. Not only that it does not include proofs, but the desirable properties are not rigorously defined. Concerning the notion of correct printing, they introduce it by saying: “types are inferred correctly when the generated HOL formulas are parsed again by Isabelle” [8]. As for minimality, they note that the greedy algorithm’s “goal is to compute a locally minimal set of sites that completely covers all type variables [in the substitution’s domain]” [8]. Thus, the notion of completeness (complete coverage) with respect to which they formulate minimality appears not to be the “declarative” notion of not losing typing information (which in §3 we captured by the definition of correct printing) but simply the “operational” notion employed by the algorithm—namely, that of passing the coverage test ( coverage -0.44446ptTest in our §3 notations). Completeness and minimality w.r.t. this operational notion follows directly from the nature of the reverse greedy algorithm. However, the algorithm is undoubtedly aimed at achieving the declarative versions (of the kind we formulated in §˜3), but that is not made explicit in their text. An additional smaller challenge comes from their implementation diverging from their paper presentation, by including several additional optimizations. Despite these challenges, the agent produced a specification, with some limitations on generality, and mostly correct proof sketches in its first attempt, as further elaborated below. Following the initial version, we ran three revision rounds in which the agent resolved the limitations while also adding proof details, resulting in a correct proof document amenable to autoformalization (cf. §˜6.2). We next describe the agent’s input followed by a summary of the generation process. All artifacts are available in the supplementary material. Input. We created a notes.md file, containing (1) links to previous works [39, 38, 8], (2) the corrected Isabelle/ML implementation, and (3) the execution trace of the algorithm on an example. In the AGENTS.md file, we instructed the agent to create results publishable at a peer-reviewed venue and to take notes in files while iteratively working on its tasks. The notes serve as reference for the agent, e.g., to recover its progress upon memory loss due to context compaction. In rounds 2–4, we moreover passed as input a review by a human expert and extra instructions to use an internal two-stage review process before finishing the paper: (1) Self-review: the agent creates a review for its paper and revises it. (2) Simulated peer-review: the agent performs simulated peer reviews for a scientific submission and finalizes the paper based on the feedback. We found that the agent identified several presentational and some logical issues using internal reviews, such as the wrong usage of an assumption, the need for extra lemmas, and missing definitions. However, some significant shortcomings were only identified by human review, as explicated below. Round 1. In the initial round, we prompted the agent to create a precise, formal exposition for the unoptimized algorithm including proofs. The agent successfully produced a paper with a specification and proof sketches. Here are some notable highlights, impressing a non-empty subset of the authors: (1) While the statement of completeness is informal—“reparsing [the output] recovers exactly the types of t [the input]”— the agent showed the correct formal statement (cf. Thm. 4 and Def. 3) in its proof. (2) The agent introduced an almost correct statement of minimality. (3) The agent discovered correct proof approaches for completeness and minimality and introduced several required lemmas, such as converse substitution extensionality (cf. §˜4.2). However, the human reviewer also identified several defects, most notably: (1) The completeness and minimality proofs were restricted to ground terms (for no good reason), and minimality also needed a small correction to exclude an existential quantifier instantiation that made the statement vacuously true. (2) There were some self-contradictory statements, e.g., “The output of the annotation algorithm is a constraint-free term augmented with type constraints”. (3) Definitions for key concepts (e.g., annotated terms, well-typedness, position enumeration), and statements of key lemmas (e.g., preservation of well-typedness under substitution) were missing. Some milder issues included the AI’s affinity for the Isabelle/ML implementation, resulting in a very technical presentation. For example, it used Isabelle jargon and notations, such as dummyT, inference in “pattern” mode, and a carbon copy of Isabelle’s term and type syntax (including a false claim: “for any type τ of sort s, the type ττ\; list also has sort s”). Moreover, it delved into implementation-specific performance optimizations that are irrelevant for the algorithm. Rounds 2–4. Each revision round was initiated by a short prompt: read the new input (notably, the human review), devise a plan, and revise. The human review summarized the shortcomings of the previous round. Admittedly, writing the reviews was not an overly pleasant task, but it seemed like a necessary one: while the agent was able to convince itself and its role-played scientific peers that the paper was worthy of publication fairly quickly, the human controller thought otherwise. The agent was able to correct, adapt and generalize its statements and proofs and to significantly improve its exposition in each revision round, but it required substantial human work to spot and review logical flaws, defects in generality, and deficiencies in rigor. After four rounds, we were convinced that the document is ready for autoformalization (though not for “publication”). 5.3 Discussion The most remarkable aspect of this experiment’s outcome was the agent’s ability to make its way towards the correct concepts and results, and to produce proof sketches that were plausible (and later validated by autoformalization). Specifically, the agent discovered the notion of strongly correct printing—although it did not introduce it as a separate notion, the agent’s statements of completeness and minimality are equivalent to variations of our Thms. 4 and 5 that have “strongly correct printing” instead of “correct printing”. Our Corollary 7 shows that the two concepts are equivalent, though this is not something that the agent has attempted (nor was it prompted) to establish. Another remarkable aspect is the informative nature of the agent’s output. The agent’s human controller learned the problems’s correct specification and the proof ideas by reading, and also by critically scrutinizing the generated document. Moreover, before being informed by the agent’s work, the human expert producing our pen-and-paper development from §˜3 had not realized the necessity to even state minimality (essentially due to confusing the operational and the declarative versions, hence wrongly assuming minimality to be trivial). A persistent weakness of the agent was its lack of precision, including: (1) missing definitions, (2) slightly wrong definitions, (3) missing lemmas, (4) slightly wrong lemmas, (5) wrong assumptions, and (6) a few logical errors. We employed simulated peer reviews by the agent to mitigate these issues, but many slipped through the review process, only being identified by the human expert. It is reported that LLMs perform worse detecting their own mistakes than those by other models [16], which we will consider for future work. All in all, the prevalence of such flaws urges the need for verification, which we will consider in §˜6. The agent’s document, while not publication-ready, served as an effective self-study material that human experts can scrutinize and improve. The human document undoubtedly trumps the agent’s in terms of clarity and conceptual cleanness. One qualitative difference stems from the agent staying close to the existing work and Isabelle/ML implementation, even when instructed to abstract from particularities; this complicates the reuse and invention of concepts (such as maybe-types and completion relations ⊑ from §˜4) that capture the problem’s essence more cleanly. On the other hand, the AI development clearly wins cost-wise and time-wise: The agent created an autoformalizable document with a cost of $70, two hours of computation time and one day of human review effort, while the human-authored document took approximately five days of human work. 6 Autoformalization in Isabelle/HOL Building on the results of the human and AI paper proofs, we conduct autoformalization experiments for both approaches in Isabelle/HOL. The generated Isabelle theories are available in the supplementary material, and Isabelle snippets with the final theorem statements can be found in App. 0.E. Our experiments are motivated by the following questions: (1) Can the correctness of algorithms in the domain of programming language theory be formalized automatically, with reasonable costs and resources? (2) What are the limits of state-of-the-art LLMs as Isabelle proof engineers? (3) How does the autoformalization effort differ between mechanizing human expert proofs versus AI-generated proofs? Relatedly, can autoformalization serve as an effective tool for validating AI-generated results? 6.1 Technical setup Our setup extends our AI paper proof setup from §˜5.1. We connect OpenCode to Isabelle via Isabelle/Q [5], an MCP server for Isabelle/jEdit. Isabelle/Q lets the agent use Isabelle interactively, with tool access, such as modifying theory files, fact search, Sledgehammer, and retrieval of proof states. Inspired by prior autoformalization efforts [43], we provide an Isabelle guidance file to the agent. This guide contains both style guidelines, e.g., to create idiomatic Isar proofs, and proof engineering patterns to facilitate efficient interaction with Isabelle/Q. 6.2 AI-authored proof autoformalization First, we tasked Claude Opus to formalize the AI-authored proof. The agent receives all input and generated artifacts from the AI paper experiment (§˜5), i.e., the proof document including source files, notes, and reviews. An AGENTS.md file instructs the agent to first produce a formalization plan to be implemented in Isabelle/HOL, producing a mechanization that is faithful to the underlying material. We provide no problem-specific strategies for formalization. From the initial prompt, we obtain a sorry-free proof in Isabelle/HOL that fills in details missing in the AI paper proof, while also improving its structure: (1) It uses an Isabelle locale [6] to introduce well-formedness assumptions on the inputs and to axiomatize the existence of most general types. (2) Another locale is used to abstract the proof of the main theorems, fixing a set of locally minimal set of annotations covering all inference variables. (3) To prove that each kept position is required for coverage, the agent identified a necessary, complex statement generalization, depicted in LABEL:fig:gen_statement. Fig. 1: AI-generalized statement for induction proof: The non-generalized statement expresses that each position kept by the reverse-greedy algorithm (rg_fold) must cover at least one type variable. Here, cands is a list of candidate annotations with their tyvars, cnt counts the occurrences of each tyvar in cands. The agent noticed that an induction proof requires generalizing the statement to also count for each tyvar in how many kept positions it occurs (via extra). figure]fig:gen_statement However, the first human review identified several instances where the theorem statements in Isabelle/HOL and the AI paper are not aligned: (1) Completeness and minimality are proved only within the abstraction locale, but are not instantiated to obtain statements about the algorithm’s actual output. However, all relevant facts required for instantiation are present in the formalization. (2) The formalization claims to abstract from the order in which annotations are processed, but actually fixes a concrete post-order enumeration. This discrepancy still remains in the final version, despite human reviews repeatedly pointing to the problem. (3) The AI paper uses the informal notion of consistency of a term with a set of annotations in the algorithm’s specifications. The formalization’s definition seems to not match the paper’s intended meaning, though the authors also argued whether the paper version is ambiguous and thus the true culprit. Based on the review, the agent correctly instantiates the abstraction locale. A second round of human reviews identified that the completeness statement refers to the set of annotations determined by the algorithm and not the output of the algorithm (as the paper version does). In a final run, the agent aligns the completeness statement with the paper. The agent also modifies the definition of consistency, which remains suboptimal but captures the right meaning in the statements of completeness and minimality. 6.3 Human-authored proof autoformalization As a second experiment, we instructed the agent to mechanize the human proof, which was explicitly created with autoformalization in mind. The agent received as input a draft of §˜4, including the LaTeX source files and the PDF document. Its initial prompt and the AGENTS.md file are analogous to the AI proof autoformalization experiment. The agent produced sorry-free proofs, which faithfully capture the underlying material, except for a small but severe issue discovered in the review process. As part of a locale definition, the agent introduces assumptions on coverage -0.44446ptTest before defining the constant. This allows the instantiation of these assumptions with arbitrary terms, that could have been exploited to derive a contradiction, but was not. Missing concrete instantiations of the minimality and completeness statements constitute further minor issues. In round two, the agent makes minor adjustments that address all issues raised in the review. After the second run, we happened to discover an improvement in the paper definition of well-typedness from §2.2, namely the condition on the free typed variables from the typing of abstraction. When informed about the change, the AI agent correctly updates the definition of well-typedness in the formalization and adapts the proof of the type preservation lemma from §˜4.2. 6.4 Discussion Both autoformalizations successfully produced results that faithfully capture a significant share of the underlying document, with minor problems identified in human reviews. Even though the AI-authored proof was not optimized for autoformalization and its mechanization required more human feedback identifying alignment errors, the results are of comparable size and incur similar cost in terms of compute resources: The human-authored proof mechanization spans 1938 lines at an LLM usage cost of $139, vs. 2071 lines and $140 for the AI-authored proof (using Claude Opus 4.6 at a cost of $5 per 1M input and $25 per 1M output tokens). Resource usage in terms of human work is more difficult to quantify, but the AI paper proof mechanization demanded more human feedback in the review process, as well as more rounds of review. As the proofs themselves are checked for correctness by the proof assistant, the reviews were focused on aligning theorem statements and definitions with the underlying paper, where the more formal style of the human expert development proved advantageous. Claude as a proof engineer. On a high level, the proof documents are idiomatic Isabelle developments: They use locales, inductive predicates, and recursive data types, as well as nested Isar proofs [46] of significant length and complexity. The proofs are generally of good quality and maintainable, yet at times overly verbose, e.g., several induction proofs with explicit case distinctions can easily be compressed into one-line proofs. Moreover, the agent showed a preference towards object-level quantifiers instead over structured Isar statements, making theorems harder to reuse and instantiate later on (see LABEL:fig:gen_statement for an example). The agent routinely ignored the prescribed gradual workflow, instead producing large Isar proofs at once, then fixing the resulting errors. Similarly, the agent did not make use of Sledgehammer, relying instead on pattern-based fact search and manual proof development. Human intervention into the proof engineering process was only required to remedy a misconception on non-terminating proof methods, where the agent misinterpreted Isabelle/Q’s responses. The resulting mechanizations may not meet the highest quality standards of expert proof engineers, but can serve as a good baseline for further improvements. Learning from our experience, we provide an improved Isabelle interaction guide for AI agents in the supplementary material. Future directions. Our experiments are a playground for autoformalization with minimal dependencies and a simple background theory. In future work, we plan to fully stress the AI agent’s capabilities, exploring navigability in large proof libraries, like the AFP [4], and complex proof developments in computer science, such as graph matching algorithms and programming language metatheory. A key challenge is reducing resource cost, both in terms of compute and human feedback. This might involve improving utilization of symbolic tools, such as Sledgehammer [33], the Isabelle linter [30], and the development of specialized proof engineering LLMs. The faithfulness of the formalization may also be improved by using a critique model for definitions and theorem statements [10]. 7 Autogeneralization based on Human Hints Our final experiment explores the AI agent’s ability to separate the generic from the ad hoc component of the algorithm (§3). To this end, we handed a hint to the AI agent to consider the following independence system (IS), which abstracts the type annotation problem: (S,F) where F=F∣F⊆S∧S∖F covers V(S,F) where F=\F F S S F covers V\ and S∖FS F corresponds to the to-be-annotated positions and V to the input term’s tyvars. We then prompted the agent to reprove the results from the AI-authored paper proof (§˜5) by taking advantage of the generic setting for the standard best-in-greedy algorithm for ISs [27, Chapter 13]. The AI agent succeeded in reproving the local minimality result—that was the part benefitting most from the general results on the best-in-greedy algorithm. The proof was 6.25 pages, computed at a price of $11 (while having full access to the original proof). Next, we prompted the agent to formalize this pen-and-paper proof in Isabelle/HOL, building on an existing Isabelle formalization of ISs [1]. The agent was able to autoformalize the arguments of its own pen-and-paper proofs but, instead of importing the existing formalization, which we asked it to use, proceeded by copying definitions and lemmas. The formalization (of both local minimality and completeness, which were re-proved from scratch) spans 1800 lines, in addition to 200 lines reused from the pre-existing formalization of ISs. The cost of the entire experiment was $93. This experiment was performed by an author with no prior familiarity with the correct printing problem who, when reviewing the AI and human proofs, wanted to understand the problem abstractly by formulating it in terms of ISs. The AI agent demonstrated that it can drastically accelerate the process of understanding the problem by pinning down all the details of the connection to ISs in less than three hours. This may hint to a potential role of LLMs as “propped up” automated proof methods or counter-example finders, benefiting the economics of formal theorem proving and even the practice of mathematics. We also hypothesise that hinting the LLM could make (formal) proving cheaper. 8 Related Work and Conclusion Type annotations are typically considered as part of type inference: the process of translating a partially typed term from an external language to a fully typed term in an internal language [35]. In this work, we consider the reverse direction: the translation of a fully typed term to a partially typed one. Since type inference for expressive languages, such as System F, is undecidable [45], type inference algorithms for these languages are only partially complete: for any well-typed t of type τ, there is t′t with t⊑t′t t such that running type inference on t′t yields τ. Completeness in this context is also called annotatability [18]. Note that annotatability does not tell us where type annotations are needed. Xue and Oliveira [51] hence call this weak annotatability, differentiating it from strong annotatability which also describes where annotations are needed. Existing work on strong annotatability [50, 51, 19, 11, 22, 28] covers the completeness part of the correct printing problem but, to our knowledge, does not address minimality. Unlike in our case, the languages used in many of these works do not admit most general well-typed completions. As a result, their annotation criteria are typically coupled to the respective type inference algorithm and offer little control to specify favorable annotation positions, whereas the approach studied here is independent of the inference algorithm and controllable via the pickPos function. A related concern is the construction of correct pretty printers [36, 14]. The focus there is to create infrastructure for correct-by-construction parser and printer combinators, whereas we are concerned with the correctness of a particular pretty printer that minimizes type annotations. For pen-and-paper mathematics, LLMs have shown significant and accelerating progress (see Ju and Dong’s survey [24]). Applications include problems ranging from finding conjectures in research mathematics [15], to solving mathematics olympiad problems [41], all the way to proving open problems in theoretical computer science [26]. Our work here demonstrates the AI’s abilities in a new domain of pen-and-paper mathematics: we show that off-the-shelf LLMs can produce new pen-and-paper theorem statements and proofs in programming language metatheory while based only on informal hints as input, e.g. an algorithm lacking formal correctness specifications (as in §5) or a pointer to a pen-and-paper description of a general concept (as in §7). Our use case showed that this can be done within reasonable time and financial boundaries, advocating for LLMs to be used in an interactive loop with human researchers, i.e., as a day-to-day proof automation tool, substantially accelerating the human’s progress. The area of autoformalization is rapidly growing. Several fine-tuned models [48, 47, 29] and sophisticated frameworks [44, 23] have been developed. We demonstrated that even a simple setup—using an off-the-shelf AI coding environment, LLM, and Isabelle MCP server—can be sufficient for non-trivial autoformalization tasks. Our setup was inspired by Urban’s remarkable experiment [42], who used an off-the-shelf LLM to autoformalize textbook results in topology without human intervention. Notable experiments in the area of programming languages are by Xi and Odersky [49] and Ilya Sergey [37]. Both present an iterative development where humans wrote the definitions while agents handled the proof development. This is unlike our work, which hands all steps to the LLM, only providing human review once a complete formalization is obtained. Conclusion We provide a formal account of the problem of sufficient and minimal type annotations for correct printing, in particular the Smolka-Blanchette algorithm, with mechanized statements and proofs of completeness and minimality. Our main focus was on using LLMs as research assistants in the context of programming language research. Our comparison of human and AI proof development reveals that state-of-the-art models and human insights can be complementary and therefore mutually beneficial. Our work suggests that LLMs can already be used for day-to-day proof assistance, in the same way as existing tools like Sledgehammer, Nitpick, and auto would be used in Isabelle, but with a substantially broader scope and power and with the added advantage of natural language interaction. Our work also points to a promising future in which a deep integration of AI agents and proof assistants could catalyze both AI’s and humans’ capabilities for proving theorems. credits Acknowledgements This research is conducted within the Copilots for Isabelle project under the AI for Math Fund, an initiative by Renaissance Philanthropy with funding support from XTX Markets. Our interest in adding type annotations during printing arose in the context of implementing a wrap-up proof copilot aiming to translate exploratory apply-style proofs to readable Isar proofs. References [1] M. Abdulaziz, T. Ammer, S. Meenakshisundaram, and A. Rimpapa (2025) A Formal Analysis of Algorithms for Matroids and Greedoids. In The 16th International Conference on Interactive Theorem Proving (ITP), External Links: Document Cited by: §7. [2] OpenCode Note: Open-source AI coding environment. GitHub repository; version 1.2.24 External Links: Link Cited by: §5.1. [3] Anthropic (2026-02-05)Introducing claude opus 4.6(Website) Note: Accessed Apr 03, 2026 External Links: Link Cited by: §5.1. [4] Archive of Formal Proofs (AFP)(Website) Note: proof library collection for Isabelle, accessed Apr 03, 2026 External Links: Link Cited by: §6.4. [5] Isabelle/Q Note: MCP server for Isabelle/jEdit. GitHub repository; commit 72160e2 External Links: Link Cited by: §6.1. [6] C. Ballarin (2004) Locales and locale expressions in isabelle/isar. In Types for Proofs and Programs, S. Berardi, M. Coppo, and F. Damiani (Eds.), Berlin, Heidelberg, p. 34–50. External Links: ISBN 978-3-540-24849-1 Cited by: item 1. [7] S. Binder, H. Lachnitt, and K. Kosaian (2026) Apply2Isar: automatically converting Isabelle/HOL apply-style proofs to structured Isar. External Links: 2603.07771, Link Cited by: §1. [8] J. C. Blanchette, S. Böhme, M. Fleury, S. J. Smolka, and A. Steckermeier (2016) Semi-intelligible Isar proofs from machine-generated proofs. Journal of Automated Reasoning 56 (2), p. 155–200. External Links: Document Cited by: §1, §1, §1, item 1, §5.2. [9] M. Brecknell, D. Greenaway, J. Hölzl, F. Immler, G. Klein, R. Kolanski, J. Lim, M. Norrish, N. Schirmer, S. Sickert, T. Sewell, H. Tuch, and S. Wimmer (2024) AutoCorres2. Arch. Formal Proofs 2024. External Links: Link Cited by: §1. [10] G. Chen, W. Jing, X. Chen, X. Zhao, R. Song, C. Li, K. Fan, D. Liu, and M. Liao (2026) ReForm: reflective autoformalization with prospective bounded sequence optimization. In The Fourteenth International Conference on Learning Representations, External Links: Link Cited by: §6.4. [11] L. Chen and H. Ko (2024) A formal treatment of bidirectional typing. In Programming Languages and Systems, p. 115–142. External Links: ISBN 9783031572623, Document, ISSN 1611-3349 Cited by: §8. [12] L. Damas and R. Milner (1982) Principal type-schemes for functional programs. In Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), p. 207–212. Cited by: §2.2. [13] L. Damas (1985) Type assignment in programming languages. Ph.D. Thesis, University of Edinburgh. Note: Technical Report CST-33-85 Cited by: §2.2. [14] N. A. Danielsson (2013-09) Correct-by-construction pretty-printing. In Proceedings of the 2013 ACM SIGPLAN workshop on Dependently-typed programming, ICFP’13, p. 1–12. External Links: Document Cited by: §8. [15] A. Davies, P. Veličković, L. Buesing, S. Blackwell, D. Zheng, N. Tomašev, R. Tanburn, P. Battaglia, C. Blundell, A. Juhász, M. Lackenby, G. Williamson, D. Hassabis, and P. Kohli (2021) Advancing mathematics by guiding human intuition with AI. Nature. External Links: Document Cited by: §8. [16] J. Dekoninck, I. Petrov, K. Minchev, M. Marinov, M. Drencheva, L. Konova, M. M. Shumanov, K. Tsvetkov, N. Drenchev, L. D. Todorov, K. Nikolova, N. Georgiev, V. Kalinkova, M. Ismoldayev, M. Balunovic, and M. Vechev (2026) The open proof corpus: a large-scale study of LLM-generated mathematical proofs. In The Fourteenth International Conference on Learning Representations, External Links: Link Cited by: §5.3. [17] M. Desharnais, P. Vukmirovic, J. Blanchette, and M. Wenzel (2022) Seventeen provers under the hammer. In ITP 2022, J. Andronick and L. de Moura (Eds.), LIPIcs, p. 8:1–8:18. External Links: Document Cited by: §1. [18] J. Dunfield and N. Krishnaswami (2021-05) Bidirectional typing. ACM Computing Surveys 54 (5), p. 1–38. External Links: ISSN 1557-7341, Document Cited by: §8. [19] J. Dunfield and N. R. Krishnaswami (2013) Complete and easy bidirectional typechecking for higher-rank polymorphism. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013, G. Morrisett and T. Uustalu (Eds.), p. 429–442. External Links: Link, Document Cited by: §8. [20] F. Haftmann (2019) Sketch and Explore. Note: accessed Mar 30, 2026 External Links: Link Cited by: §1. [21] J. R. Hindley (1969) The principal type-scheme of an object in combinatory logic. Transactions of the American Mathematical Society 146, p. 29–60. External Links: Document Cited by: §2.2. [22] C. Jenkins and A. Stump (2018) Spine-local type inference. In Proceedings of the 30th Symposium on Implementation and Application of Functional Languages, IFL ’18, New York, NY, USA, p. 37–48. External Links: ISBN 9781450371438, Document Cited by: §8. [23] A. Q. Jiang, S. Welleck, J. P. Zhou, T. Lacroix, J. Liu, W. Li, M. Jamnik, G. Lample, and Y. Wu (2023) Draft, sketch, and prove: guiding formal theorem provers with informal proofs. In The Eleventh International Conference on Learning Representations, External Links: Link Cited by: §8. [24] H. Ju and B. Dong (2026) AI for mathematics: progress, challenges, and prospects. External Links: 2601.13209, Document Cited by: §8. [25] Cited by: §1. [26] D. Knuth (2026) Claude’s cycles. External Links: Link Cited by: §8. [27] B. Korte and J. Vygen (2012) Combinatorial Optimization. Springer. External Links: Document Cited by: §7. [28] D. Le Botlan and D. Rémy (2003) MLF: raising ml to the power of system f. In Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming, ICFP ’03, New York, NY, USA, p. 27–38. External Links: ISBN 1581137567, Document Cited by: §8. [29] Y. Lin, S. Tang, B. Lyu, Z. Yang, J. Chung, H. Zhao, L. Jiang, Y. Geng, J. Ge, J. Sun, J. Wu, J. Gesi, X. Lu, D. Acuna, K. Yang, H. Lin, Y. Choi, D. Chen, S. Arora, and C. Jin (2026) Goedel-prover-v2: scaling formal theorem proving with scaffolded data synthesis and self-correction. In The Fourteenth International Conference on Learning Representations, External Links: Link Cited by: §8. [30] Y. Megdiche, F. Huch, and L. Stevens (2022) A linter for isabelle: implementation and evaluation. External Links: Document Cited by: §6.4. [31] M. Milehins (2022) An extension of the framework types-to-sets for Isabelle/HOL. In CPP 2022, A. Popescu and S. Zdancewic (Eds.), p. 180–196. External Links: Document Cited by: §1. [32] R. Milner (1978) A theory of type polymorphism in programming. Journal of Computer and System Sciences 17 (3), p. 348–375. External Links: Document Cited by: §2.2. [33] L. C. Paulson and J. C. Blanchette (2010) Three years of experience with sledgehammer, a practical link between automatic and interactive theorem provers. In IWIL@LPAR, EPiC Series in Computing, p. 1–11. Cited by: §1, §6.4. [34] L. C. Paulson (1996) ML for the working programmer (2. ed.). Cambridge University Press. External Links: ISBN 978-0-521-57050-3 Cited by: §1. [35] B. C. Pierce and D. N. Turner (2000-01) Local type inference. ACM Transactions on Programming Languages and Systems 22 (1), p. 1–44. External Links: ISSN 0164-0925, Document Cited by: §8. [36] T. Rendel and K. Ostermann (2010-09) Invertible syntax descriptions: unifying parsing and pretty printing. In Proceedings of the third ACM Haskell symposium on Haskell, ICFP ’10, p. 1–12. External Links: Document Cited by: §8. [37] I. Sergey (2026-03) Verifying Move borrow checker in Lean: an experiment in AI-assisted PL metatheory. Note: archive snapshot: https://web.archive.org/web/20260330164922/https://proofsandintuitions.net/2026/03/18/move-borrow-checker-lean/ External Links: Link Cited by: §8. [38] S. J. Smolka and J. C. Blanchette (2013) Robust, semi-intelligible Isabelle proofs from ATP proofs. In PxTP 2013. Third International Workshop on Proof Exchange for Theorem Proving, J. C. Blanchette and J. Urban (Eds.), EPiC Series in Computing, Vol. 14, p. 117–132. External Links: ISSN 2398-7340, Document Cited by: §1, §1, §1, item 1, §5.2. [39] S. J. Smolka (2013) Synthesis of robust, semi-intelligble Isar proofs from ATP proofs. Bachelor’s Thesis, Technical University of Munich. External Links: Link Cited by: §1, §1, §1, item 1, §5.2. [40] C. Tan, A. F. Donaldson, J. J. H. y Munive, and J. Wickerson (2025) The burden of proof: automated tooling for rapid iteration on large mechanised proofs. In FormaliSE 2025, p. 34–45. External Links: Document Cited by: §1. [41] T. H. Trinh, Y. Wu, Q. V. Le, H. He, and T. Luong (2024) Solving olympiad geometry without human demonstrations. Nature. External Links: Document Cited by: §8. [42] J. Urban (2026) 130k lines of formal topology in two weeks: simple and cheap autoformalization for everyone?. CoRR abs/2601.03298. External Links: Document, 2601.03298 Cited by: §8, footnote 3. [43] J. Urban (2026) Rules for working on the Isabelle/HOL formalization. Note: CLAUDE.md file. GitHub repository; commit a9fe8b5 External Links: Link Cited by: §6.1. [44] H. Wang, H. Xin, C. Zheng, Z. Liu, Q. Cao, Y. Huang, J. Xiong, H. Shi, E. Xie, J. Yin, Z. Li, and X. Liang (2024) LEGO-prover: neural theorem proving with growing libraries. In The Twelfth International Conference on Learning Representations, External Links: Link Cited by: §8. [45] J.B. Wells (1999) Typability and type checking in system f are equivalent and undecidable. Annals of Pure and Applied Logic 98 (1), p. 111–156. External Links: ISSN 0168-0072, Document Cited by: §8. [46] M. Wenzel (1999) Isar - A generic interpretative approach to readable formal proof documents. In TPHOLs, Lecture Notes in Computer Science, p. 167–184. Cited by: §6.4. [47] Y. Wu, D. Huang, R. Wan, Y. Peng, S. Shang, C. Cao, L. Qi, R. Zhang, X. Zhang, Z. Du, J. Yan, and X. Hu (2026-Mar.) StepFun-formalizer: unlocking the autoformalization potential of llms through knowledge-reasoning fusion. Proceedings of the AAAI Conference on Artificial Intelligence 40 (40), p. 33980–33988. External Links: Document Cited by: §8. [48] H. Xin, D. Guo, Z. Shao, Z.Z. Ren, Q. Zhu, B. Liu, C. Ruan, W. Li, and X. Liang (2024) Advancing theorem proving in LLMs through large-scale synthetic data. In The 4th Workshop on Mathematical Reasoning and AI at NeurIPS’24, External Links: Link Cited by: §8. [49] Y. Xu and M. Odersky (2026) Agentic proof automation: a case study. arXiv. External Links: Document Cited by: §8. [50] X. Xue, C. Cui, S. Jiang, and B. C. d. S. Oliveira (2026-01) Local contextual type inference. Proceedings of the ACM on Programming Languages 10 (POPL). External Links: Document Cited by: §8. [51] X. Xue and B. C. d. S. Oliveira (2024-08) Contextual typing. Proceedings of the ACM on Programming Languages 8 (ICFP). External Links: Document Cited by: §8. APPENDIX This appendix contains further details on the concepts and statements from the main paper. In case of acceptance, the appendix will be replaced by a technical report cited from the paper and made available online. Appendix 0.A More Details on Syntax The definition of substitution application _[ρ]\_[ρ] on types consists of the following recursive equations: • α[ρ]=ρ(α)α[ρ]=ρ(α); • (σ⇒τ)[ρ]=σ[ρ]⇒τ[ρ](σ τ)[ρ]=σ[ρ] τ[ρ]; • ((σ1,...,σn)κ)[ρ]=(σ1[ρ],...,σn[ρ])κ(( _1, . 3.0mu. 3.0mu., _n)\,κ)[ρ]=( _1[ρ], . 3.0mu. 3.0mu., _n[ρ])\,κ. And similarly for the one on terms: • xξ[ρ]=xξ[ρ]x_ξ[ρ]=x_ξ[ρ] • cξ[ρ]=cξ[ρ]c_ξ[ρ]=c_ξ[ρ] • (t1t2)ξ[ρ]=(t1[ρ]t2[ρ])ξ[ρ](t_1\,t_2)_ξ[ρ]=(t_1[ρ]\,t_2[ρ])_ξ[ρ] • (λxξ.t)ζ[ρ]=(λxξ[ρ].t[ρ])ζ[ρ](λ x_ξ.\,t)_ζ[ρ]=(λ x_ξ[ρ].\,t[ρ])_ζ[ρ] The definition of TV (the occurring tyvars operator) on types consists of the following recursive equations: • (α)=α TV(α)=α; • (σ⇒τ)=(σ)∪(ρ) TV(σ τ)= TV(σ)∪ TV(ρ); • ((σ1,...,σn)κ)=⋃i=1n(σi) TV(( _1, . 3.0mu. 3.0mu., _n)\,κ)= _i=1^n TV( _i). And similarly for the one on terms: • (xξ)=(ξ) TV(x_ξ)= TV(ξ) • (cξ)=(ξ) TV(c_ξ)= TV(ξ) • ((t1t2)ξ)=(t1)∪(t2)∪(ξ) TV((t_1\,t_2)_ξ)= TV(t_1)∪ TV(t_2)∪ TV(ξ) • ((λxξ.t)ζ)=(ξ)∪(t)∪(ζ) TV((λ x_ξ.\,t)_ζ)= TV(ξ)∪ TV(t)∪ TV(ζ) We write [n1,...,nk][n_1, . 3.0mu. 3.0mu.,n_k] for the list consisting of n1,...,nkn_1, . 3.0mu. 3.0mu.,n_k (in particular, [][] for the empty list) and n⋅ln· l for consing an element n to a list l. The set of positions of a term, (t) Poss(t), is defined by: (xξ)=(cξ)=[]((ts)ξ)=[],1⋅(t),2⋅(s) Poss(x_ξ)= Poss(c_ξ)=\[]\ Poss((t\,s)_ξ)=\[],1· Poss(t),2· Poss(s)\ ((λxξ.t)ζ)=[],[1],2⋅(t) Poss((λ x_ξ.\;t)_ζ)=\[],[1],2· Poss(t)\ Each position of a term uniquely identifies a location of a subterm or a binding variable. If p∈(t)p∈ Poss(t), the maybe-type of (the subterm at) position p in t, (t,p) mtpOf(t,p), is defined recursively: (xξ,p)=ξ mtpOf(x_ξ,p)=ξ ((t1t2)ξ,p)=(t1,p′),if p=1⋅p′(t2,p′),if p=2⋅p′ξ,otherwise mtpOf((t_1\,t_2)_ξ,p)= cases mtpOf(t_1,p ),&if p=1· p \\ mtpOf(t_2,p ),&if p=2· p \\ ξ,&otherwise cases (cξ,p)=ξ mtpOf(c_ξ,p)=ξ ((λxξ.t)ζ,p)=ξ,if p=[1](t,p′),if p=2⋅p′ζ,otherwise mtpOf((λ x_ξ.\,t)_ζ,p)= casesξ,&if p=[1]\\ mtpOf(t,p ),&if p=2· p \\ ζ,&otherwise cases The annotation deletion operator t[p:=⊥]t[p:= ] has the following recursive definition: xξ[p:=⊥]x_ξ[p:= ] == x⊥x_ cξ[p:=⊥]c_ξ[p:= ] == c⊥c_ (t1t2)ξ[p:=⊥](t_1\,t_2)_ξ[p:= ] == (t1[p′:=⊥]t2)ξ, if p has the form 1⋅p′(t1(t2[p′:=⊥]))ξ, if p has the form 2⋅p′(t1t2)⊥, otherwise \ array[]l(t_1[p := ]\,t_2)_ξ,& if $p$ has the form $1· p $\\ (t_1\,(t_2[p := ]))_ξ,& if $p$ has the form $2· p $\\ (t_1\,t_2)_ , otherwise array . (λxξ.t)ζ[p:=⊥](λ x_ξ.\,t)_ζ[p:= ] == (λx⊥.t)ζ, if p=1(λxξ.(t[p′:=⊥]))ζ, if p has the form 2⋅p′(λxξ.t)⊥, otherwise \ array[]l(λ x_ .\;t)_ζ,& if $p=1$\\ (λ x_ξ.\;(t[p := ]))_ζ,& if $p$ has the form $2· p $\\ (λ x_ξ.\,t)_ , otherwise array . Appendix 0.B More Details on the Smolka-Blanchette Algorithm The definition of decrease is correct (i.e., its recursion terminates) because, in the recursive call, the number of positions p in s such that (s,p)≠⊥ mtpOf(s,p) = , i.e., |≠⊥(s)|| Poss_ = (s)| where ≠⊥(s)=p∈(s)∣(s,p)≠⊥ Poss_ = (s)=\p∈ Poss(s) mtpOf(s,p) = \, decreases by 1. Appendix 0.C More Details on the Human-Authored Paper Proof Development 0.C.1 Constructor-aware inversion lemmas Lemma 12 (term-constructor-guided inversion rules for ⊢ ) The following hold: (1) If ⊢cσ c_σ then σ≤(c)σ≤ ctpOf(c) (2) If ⊢(t1t2)σ (t_1\,t_2)_σ then there exists τ such that ⊢t1 t_1, ⊢t2 t_2 and (t1)=(t2)⇒σ tpOf(t_1)= tpOf(t_2) σ. (3) If ⊢(λxσ.t)τ (λ x_σ.\,t)_τ then ⊢t t and τ=σ⇒(t)τ=σ tpOf(t). Proof Follows from the standard inversion rule associated to the inductive definition of ⊢ and the injectiveness and distinctness of the syntactic term constructors. ∎ Lemma 13 (term-constructor-guided left inversion rules for ⊑ ) The following hold: (1) If xξ⊑tx_ξ t then there exists ξ′ξ such that ξ⊑ξ′ξ ξ and t=xξ′t=x_ξ . (2) If cξ⊑tc_ξ t then there exists ξ′ξ such that ξ⊑ξ′ξ ξ and t=cξ′t=c_ξ . (3) If (s1s2)ξ⊑t(s_1\,s_2)_ξ t then there exist s1′s_1 , s2′s_2 and ξ′ξ such that s1⊑s1′s_1 s_1 , s2⊑s2′s_2 s_2 , ξ⊑ξ′ξ ξ and t=(s1′s2′)ξ′t=(s_1 \,s_2 )_ξ . (4) If (λxζ.s)ξ⊑t(λ x_ζ.\;s)_ξ t then there exist s′s , ζ′ζ and ξ′ξ such that s⊑s′s s , ζ⊑ζ′ζ ζ , ξ⊑ξ′ξ ξ and t=(λxζ′.s′)ξ′t=(λx_ζ .\;s )_ξ . Proof Follows from the standard inversion rule associated to the inductive definition of ⊑ and the injectiveness and distinctness of the syntactic term constructors. ∎ Lemma 14 (term-constructor-guided right inversion rules for ⊑ ) The following hold: (1) If t⊑xξt x_ξ then there exists ξ′ξ such that ξ′⊑ξ ξ and t=xξ′t=x_ξ . (2) If t⊑cξt c_ξ then there exists ξ′ξ such that ξ′⊑ξ ξ and t=cξ′t=c_ξ . (3) If t⊑(s1s2)ξt (s_1\,s_2)_ξ then there exist s1′s_1 , s2′s_2 and ξ′ξ such that s1′⊑s1s_1 s_1, s2′⊑s2s_2 s_2, ξ′⊑ξ ξ and t=(s1′s2′)ξ′t=(s_1 \,s_2 )_ξ . (4) If t⊑(λxζ.s)ξt (λ x_ζ.\;s)_ξ then there exist s′s , ζ′ζ and ξ′ξ such that s′⊑s s, ζ′⊑ζ ζ, ξ′⊑ξ ξ and t=(λxζ′.s′)ξ′t=(λx_ζ .\;s )_ξ . Proof Follows from the standard inversion rule associated to the inductive definition of ⊑ and the injectiveness and distinctness of the syntactic term constructors. ∎ 0.C.2 Lemmas on syntax basics Lemma 15 The following hold: (1) τ[ρ∙ρ′]=τ[ρ′][ρ]τ[ρ\, \,ρ ]=τ[ρ ][ρ]. (2) If β∉(τ)β∉ TV(τ), then τ[β/α][α/β]=τ[β/α][α/β]=τ. (3) τ[ρ]=τ[ρ′]τ[ρ]=τ[ρ ] iff ∀α∈(τ).ρ(α)=ρ′(α)∀α∈ TV(τ).\,ρ(α)=ρ (α). (4) (τ[ρ])=⋃α∈(τ)(ρ(α) TV(τ[ρ])= _α∈ TV(τ)\! TV(ρ(α). (5) (τ) TV(τ) is finite. (6) ≤ is a preorder on types. (7) Assume that ∀α∈(τ).ρ(α)≤ρ′(α)∀α∈ TV(τ).\;ρ(α)≤ρ (α). Then τ[ρ]≤τ[ρ′]τ[ρ]≤τ[ρ ]. Proof (1)–(5) and (7) follow by straightforward structural induction over τ, using the definitions of TV and _[_]\_[\_] on types. (3) also needs the injectiveness and distinctness properties of the syntactic constructors for types. (6) follows immediately from (1). ∎ Lemma 16 The following hold for all unambiguous terms t: (1) t[1]=t[1_ TVar]=t and t[ρ∙ρ′]=t[ρ′][ρ]t[ρ\, \,ρ ]=t[ρ ][ρ]. (2) If β∉(t)β∉ TV(t), then t[β/α][α/β]=t[β/α][α/β]=t. (3) t[ρ]=t[ρ′]t[ρ]=t[ρ ] iff ∀α∈(t).ρ(α)=ρ′(α)∀α∈ TV(t).\,ρ(α)=ρ (α).444This “iff” version covers both substitution extensionality and its converse. In particular, t[ρ]=t[ρ]=t iff ∀α∈(t).ρ(α)=α∀α∈ TV(t).\,ρ(α)=α. (4) (t[ρ])=⋃α∈(t)(ρ(α) TV(t[ρ])= _α∈ TV(t)\! TV(ρ(α). (5) (t) TV(t) is finite. (6) ≤ is a preorder. Proof (1)–(5) follow by straightforward structural induction over t, using the definitions of TV and _[_]\_[\_] on terms, and the corresponding fact for types (from Lemma 15). Again, (3) needs injectiveness and distinctness of the syntactic constructors for terms. The second part of (3) follows from the first part of (3) and the first part of point (1). (6) again follows easily from (1). ∎ 0.C.3 Annotation lemmas Lemma 17 Assume t∈t∈ Term and p∈(t)p∈ Poss(t). Then the following hold: (1) t[p:=⊥]⊑t[p:= ] t. (2) (t[p:=⊥],p)=⊥ mtpOf(t[p:= ],p)= . (3) For all q∈(t)∖pq∈ Poss(t) \p\, (t[p:=⊥],q)=(t,q) mtpOf(t[p:= ],q)= mtpOf(t,q). (4) If t is unambiguous, then t[p:=⊥]t[p:= ] is unambiguous. Proof By straightforward induction on t, using the definitions of _[_:=_]\_[\_:=\_] and mtpOf, and that of unambiguity. ∎ 0.C.4 The type preservation lemma Lemma 18 Assume v is an unambiguous F-term such that ⊢v v and ρ a substitution. Then ⊢v[ρ] v[ρ]. Proof By structural induction on v, using the definitions of TV and _[_]\_[\_]. ∎ 0.C.5 The⊑ - and (⊑,≤)( ,≤)-lemmas Lemma 19 The following hold: (1) ⊑ is a partial order (and therefore ⊏ is a strict partial order) on Term having the U-terms as the minimal elements and the F-terms as the maximal elements. (2) If t⊑st s, then (t)⊑(s) mtpOf(t) mtpOf(s). (3) (t)⊑t erase(t) t. (4) If t⊑st s then t is unambiguous iff s is unambiguous. Proof (1), (2) and (4): By induction on the definition of ⊑ . For transitivity, we also need the right-inversion rules for ⊑ (Lemma 14). (3): By structural induction on t, using the definition of erase. The next lemma essentially says that any two terms connected by ⊑ or ≤ have the “same shape” hence the same positions, and their “at position” type annotations are related correspondingly. Lemma 20 (1) If t⊑st s then (t)=(s) Poss(t)= Poss(s). (2) If t⊑st s and p∈(t)p∈ Poss(t) then (t,p)⊑(s,p) mtpOf(t,p) mtpOf(s,p). (3) If t≤st≤ s then (t)=(s) Poss(t)= Poss(s). (4) If t≤st≤ s and p∈(t)p∈ Poss(t) then (t,p)≤(s,p) mtpOf(t,p)≤ mtpOf(s,p). Proof (1) and (2): By induction on the inductive definition of ⊑ , using the definitions of Poss and (t,p) mtpOf(t,p). (3) and (4): We obtain ρ such that t=s[ρ]t=s[ρ]. Then the proof goes by structural induction on t. ∎ 0.C.6 The generic reverse greedy lemmas Strictly speaking, only Lemma 21 is entirely generic, whereas Lemma 22 also uses some specific properties of ⊑ , including transitivity. Lemma 21 Assume t is an unambiguous term and v is an F-term and ∈pickPos∈ Compat. Let s=(,v,t)s= decrease(pickPos,v,t). Then ¬∃p.(v,s,p) \,∃ p.\; coverage -0.44446ptTest(v,s,p). Proof Immediately by induction on |≠⊥(s)|| Poss_ = (s)| (alternatively, by the computation induction principle stemming from the definition of decrease). ∎ Lemma 22 Assume t is an unambiguous term and v is an F-term and ∈pickPos∈ Compat. Let s=(,v,t)s= decrease(pickPos,v,t). Then s⊑(t)s mgen(t), in particular s is unambiguous. Proof By induction on |≠⊥(s)|| Poss_ = (s)| (alternatively, by the computation induction principle stemming from the definition of decrease), using Lemma 19(1,4). ∎ 0.C.7 Some omitted proofs and proof sketches Proof of Lemma 9. By induction on the definition of ⊑ , using the definition of mtpOf. ∎ Proof of Lemma 10. By structural induction on v, using the definitions of ⊑ and _[_]\_[\_]. ∎ Proof of Lemma 11. From the definitions, we have s⊑vs v and ⊢v v, and we obtain α such that α∈(v)∖(s)α∈ TV(v) TV(s). From this and s⊑vs v, using the annotation lemmas and the ⊑ -lemmas, we have (a) ∀p∈(v)=(s).α∈(v,p)⟶(s,p)=⊥∀ p∈ Poss(v)= Poss(s).\;α∈ TV(v,p) mtpOf(s,p)= . We choose β such that (b) β∉(v)β∉ TV(v) (in particular, β≠αβ =α), and let v′=v[β/α]v =v[β/α]. By syntax basics and α∈(v)α∈ TV(v), we have v≠v′v =v . Moreover, again by syntaxc basics, from (b) we obtain (c) v=v[β/α][α/β]=v′[α/β]v=v[β/α][α/β]=v [α/β]. By the type preservation lemma from ⊢v v we obtain ⊢v′ v . Moreover, by Lemma 10 used with the identity and β/αβ/α as substitutions, from s⊑vs v and (a) we obtain s⊑v′s v . Thus, v′v is distinct from v, and is a well-typed completion of s. It remains to show that v′v is a most general well-typed completions of s. Let w be a well-typed completion of s. Since v is a most general completion, we obtain ρ such that w=v[ρ]w=v[ρ]. Moreover, by syntax basics, from (c) we obtain v[ρ]=v′[α/β][ρ]=v′[ρ∙(α/β)]v[ρ]=v [α/β][ρ]=v [ρ\, \,(α/β)]. So w≤v′w≤ v , as desired. ∎ Appendix 0.D More Details on the AI Paper Development The human and AI agent pen-and-paper developments have been developed mostly independently, with the only influence occurring from the AI agent to the human—who, as we report in the main paper, obtained the idea of stating and proving minimality from the AI agent. Unavoidably, independent developments lead to different design decisions, and this was the case here: (1) The human expert considered the problem starting from an arbitrary typable C-term t, (which corresponds to an Isabelle term, i.e., features the usual Church-style type annotations), then proved in Prop 2 that such a term has a unique well-typed completion, namely the F-term (t) mgen(t), and applied the algorithm starting with (t) mgen(t). By contrast, the AI ignored the original term t and worked directly with an F-term (corresponding to what the human called (t) mgen(t)).555Incidentally, since the AI did not prove a result analogous to Prop 2, it did not need syntactic-constructor-aware inversion rules or anything equivalent to that. In this respect, the result proved by the AI is less complete, but consistent because ((t)) erase( mgen(t)) is the same as (t) erase(t). (2) The human expert did not consider typing contexts, after making an argument that these are “not interesting” in that the problem can be reduced to an empty-context problem (by considering the typing context to be part of the signature). By contrast, the AI considered typing contexts, and formulated the results with the additional requirements for the proper treatment of tyvars from the context by the substitutions. In this respect, the result proved by the AI is more complete, as it avoids any informal (meta-)argument in order to cover the general case. (3) In the human account, the algorithm operates with an evolving (partially annotated) term of the same shape as the original term, which iteratively loses annotations. In the AI account, the algorithm, and the corresponding theorems, operate instead on sets of positions, and therefor use inclusions between sets of positions as opposed to the annotation subsumption relation ⊑ . This makes the AI account more direct, although arguably less intuitive.666Incidentally, the AI, following the implementation, represents positions differently from (but equivalently to) the human, namely as numbers rather than lists. (4) The AI fixed a lot of items and made several assumptions globally, which were shared by many lemmas and proposition statements, including the main results (in the style of Isabelle locales), whereas the human preferred to distribute the assumptions as needed in each statement. These two approaches trade succinctness on the one hand with readability and precision on the other hand.777Incidentally, the AI paper introduced some scoping issues, such as a definition inlined inside a theorem and referred to from another theorem, which were nevertheless sorted at autoformalization time. It also introduced some useless/tautological but harmless assumptions. Appendix 0.E More Details on the Autoformalization Experiments We show the complete statements of the formalization in §˜0.E.1 and §˜0.E.2, for the AI-authored and human-authored proofs respectively. 0.E.1 AI-authored proof The main results of the formalization are stated within the context of the locale annotation_problem (cf. Fig.˜4). It introduces • the fully annotated input term a, corresponding to t in the definition of smobla; • a most general completion a_star (of a stripped from type annotations), corresponding to ((t)) mgen( erase(t))); • a type substitution relating a and a_star; • a context Γ and a constant signature const_type; • well-typedness assumptions on a and a_star; • a freshness assumption on the type substitution, modeling that type inference uses fresh type variables. Both completeness (cf. Fig.˜4) and minimality (cf. Fig.˜4) are stated within the annotation_problem locale. A limitation inherited from the AI-authored paper is that both statements refer to the set of annotation positions, not only the output term t_out. Fig. 2: AI-based annotation problem locale: well-formedness assumptions on the input a as well as type inference in terms of a_star. Fig. 3: AI-based completeness statement: a is the unique term a’ that is consistent with a at the positions determined by the reverse_greedy algorithm. The locale context only assumes type inference properties for a, so this assumption is repeated here for a’. Fig. 4: AI-based minimality statement: removing any position the algorithm deems necessary allows us to obtain a well-typed term different from a that agrees with a on the remaining positions. 0.E.2 Human-authored proof The formalization defines the locale signature_with_mgen (cf. Fig.˜8), it fixes a type signature and also follows the paper and assumes Thm. 1. An oddity here is the introduction of the superfluous locale parameter dummy_t. The algorithm locale (cf. Fig.˜8) abstracts over specific pickPos functions, where the compat assumption corresponds to Compat. Both completeness (cf. Fig.˜8) and minimality (cf. Fig.˜8) are stated within this algorithm locale. Fig. 5: Human-based signature locale: corresponds to Thm. 1 Fig. 6: Human-based algorithm locale Fig. 7: Human-based completeness statement: corresponds to Thm. 4 Fig. 8: Human-based minimality statement: corresponds to Thm. 5