Papers
Topics
Authors
Recent
Search
2000 character limit reached

FormalML: Formal Methods in Machine Learning

Updated 13 July 2026
  • FormalML is a research paradigm that integrates formal mathematical representations with machine learning to enable transparent, verifiable, and sample-efficient systems.
  • It encompasses mixed formal learning architectures, autoformalization systems, theorem-proving benchmarks, and domain-specific pipelines in software, hardware, and control engineering.
  • The approach leverages explicit domain models to facilitate low-shot learning, improve premise retrieval, and promote the reuse of verified abstractions across diverse applications.

FormalML is used in this literature as an umbrella label for research that combines machine learning with formal mathematical representations, formal methods, or mechanically checked reasoning. In the works considered here, it spans architectures that place a formal domain model inside a learning pipeline, Lean 4 benchmarks for theorem proving and subgoal completion, autoformalization systems that translate natural language into formal statements, datasets for premise selection and contract inference, and domain-specific formalization pipelines for software, hardware, control engineering, and temporal logic (Carrico, 2019, Yang et al., 26 Sep 2025, Chakraborty et al., 21 Feb 2025, Bauer et al., 2023, Fiedler et al., 4 Nov 2025, Xiong et al., 8 May 2026). The term therefore denotes a family of methods and infrastructures rather than a single model class.

1. Scope and conceptual foundations

A recurrent theme across this body of work is that “formal” does not mean merely symbolic surface structure. It refers to explicit mathematical or logical structure that can constrain learning, expose semantically meaningful latent variables, support verification, or serve as the target of machine-checked translation. In one line of work, formal structure is inserted directly into an ML architecture; in another, machine learning is used to generate, retrieve, or validate formal artifacts such as Lean theorems, C++ contracts, or knowledge-graph assertions (Carrico, 2019, Lu et al., 9 Aug 2025, Huang et al., 26 Aug 2025).

This literature also treats FormalML as adjacent to several neighboring areas. Mixed Formal Learning is situated near “scientific ML,” “model-based ML,” and parts of “neuro-symbolic” and “hybrid AI,” but emphasizes formal mathematical representations as the source of latent structure rather than symbolic logic alone (Carrico, 2019). Autoformalization and theorem-proving systems instead center on the translation of informal mathematics into Lean 4, premise retrieval over formal libraries, and machine-checked proof search (Lu et al., 2024, Yu et al., 5 May 2025). A further theoretical strand gives a formal account of LLMs themselves, insisting that a LLM is a distribution over finite strings rather than merely a next-token predictor, and introducing tightness as the condition that rules out probability mass leaking to infinite sequences (Cotterell et al., 2023).

Taken together, these works suggest that FormalML is best understood as a research program in which formal structure is not only an object of verification after learning, but also a representational substrate, a training signal, a retrieval target, or a persistent memory.

2. Mixed Formal Learning and formal structure inside ML systems

The clearest architectural statement of this idea is “Mixed Formal Learning,” which defines a two-stage pattern: a first component based on a formal mathematical model of the domain that exposes latent variables, followed by a second component that learns a task-specific skill using those variables (Carrico, 2019). The paper contrasts this with opaque end-to-end mappings xyx \mapsto y, and instead describes a factorization of the form xzyx \mapsto z \mapsto y, where zz denotes semantically meaningful latent variables derived from a formal representation.

The central claims are transparency and sample efficiency. Because the latent variables are tied to a tightly constructed mathematical representation tailored to the domain, they are meant to be legible both to humans and to downstream learners. The paper states that this “facilitates transparency” and enables “Low Shot and Zero Shot training of machine learning without sacrificing accuracy or recall” (Carrico, 2019). In the GLYNT document-understanding example, the reported result is “better than 95% F1 score with 7 or fewer training examples,” with “F1 score performance at 95% and above, obtained with fewer than 10 documents in the training set,” and “the gain in performance levels off at about 7 documents” (Carrico, 2019). It also reports that “Most of the improvement in performance derives from improvements in recall, as accuracy remains fairly uniform.”

The formalism in this paper is intentionally broad rather than algorithmically fixed. The first-stage model may be based on geometry, Newtonian physics, fluid flow, material separation, or supply-chain optimization, provided it yields exposed latent variables with semantic meaning. This suggests a general design principle rather than a single implementation recipe. The same source is explicit, however, that “Getting this representation right is key to enabling Low Shot Learning,” so the approach depends strongly on domains that admit a useful and tractable mathematical formalization (Carrico, 2019).

3. Autoformalization and machine-checked proof generation

A second major meaning of FormalML is the use of LLMs and related models to translate informal mathematics into formal systems such as Lean 4, and to verify the resulting artifacts mechanically. Early evidence came from Lean-based mathematical formalization with Codex: with careful input-dependent prompt selection and postprocessing, Codex was reported to formalize short mathematical statements at undergrad level with nearly 75% accuracy for 120 theorem statements, and to produce proof drafts where at least one out of twelve completions was easy to repair into a complete proof in a 13-theorem case study (Agrawal et al., 2022).

Later work turned this into benchmark infrastructure. “Process-Driven Autoformalization in Lean 4” introduced FormL4, a Lean 4 benchmark for complete autoformalization from natural-language question and answer to theorem statement and proof, with 14,510 training examples, a 970-example random test set, a 981-example basic test set, and a 1,000-example real test set (Lu et al., 2024). Its Process-Supervised Verifier uses Lean 4 compiler feedback to label intermediate proof steps, rather than only final success or failure, and the paper reports that “RFT + Verifier” reaches 46.28 on Basic, 39.38 on Random, and 27.90 on Real (Lu et al., 2024). The same paper also shows that step-level compiler supervision is more effective than pure outcome supervision in verifier training.

FormalMATH scales the evaluation problem further. It contributes a Lean4 benchmark of 5,560 formally verified problems spanning high-school Olympiad to undergraduate mathematics and reports that even the strongest models remain weak under practical budgets: “Kimina-Prover” reaches only 16.46% on FormalMATH-Full at Pass@32 (Yu et al., 5 May 2025). The benchmark-construction pipeline is itself a FormalML contribution, combining specialized statement autoformalization, multi-LLM semantic verification, negation-based disproof filtering, and expert review, with a reported preservation rate of 72.09% before manual verification (Yu et al., 5 May 2025).

Several systems focus specifically on improving statement-level autoformalization. CRAMF constructs a concept-definition knowledge base from Mathlib4, indexing over 26,000 formal definitions and 1,000+ core mathematical concepts, then uses contextual query augmentation plus dual-channel retrieval and reranking to ground Lean 4 generation (Lu et al., 9 Aug 2025). The paper reports consistent gains on miniF2F, ProofNet, and AdvancedMath, with up to 62.1% and an average of 29.9% relative improvement. FormaRL addresses the data-scarcity problem differently: it trains an autoformalizer with reinforcement learning using only 859 unlabeled statements, combining Lean syntax checking with LLM-based consistency checking as reward, and reports improvements from 4.04% to 26.15% pass@1 on ProofNet and from 2.4% to 9.6% on uproof for Qwen2.5-Coder-7B-Instruct (Huang et al., 26 Aug 2025).

A common implication across these papers is that formalization quality depends on more than surface translation. The main recurring bottlenecks are semantic fidelity, library compatibility, premise retrieval, and the need to align informal concepts with prover-specific abstractions.

4. Subgoal completion, premise retrieval, and reusable lemma libraries

FormalML also names a specific benchmark for Lean 4 subgoal completion in machine learning theory. This benchmark contains 4,937 extracted problems from Optlib and FoML, with 2,907 in optimization and 2,030 in probability (Yang et al., 26 Sep 2025). Its task is not full theorem proving from scratch, but local proof-obligation discharge inside a larger human-written proof. The paper emphasizes that it is “the first subgoal completion benchmark to combine premise retrieval and complex research-level contexts,” and reports that 2,049 theorems require explicit premise retrieval (Yang et al., 26 Sep 2025). Empirically, the benchmark remains difficult: the best Pass@32 on all problems is 63.21 for STP, while the best Pass@1 is only 26.96% (Yang et al., 26 Sep 2025). It also reports that long chain-of-thought provers underperform concise systems on this task, and that retrieval helps some models substantially while slightly hurting others.

DreamProver addresses a different but related problem: how to accumulate reusable formal abstractions across many proofs rather than solving each theorem independently (Zhang et al., 29 Apr 2026). Its wake-sleep cycle alternates between proving training theorems or extracting subgoals in the wake stage, and abstracting, clustering, validating, deduplicating, and compressing candidate lemmas in the sleep stage. The resulting library is intentionally compact—fewer than 100 lemmas—and is evaluated by transfer to unseen theorems. The paper reports that 58% of generated lemmas are reused on test sets and that learned lemmas contribute to proofs for 71% of successfully proved theorems (Zhang et al., 29 Apr 2026).

This library-learning view is especially consequential for machine learning theory. On FormalML-Hard, DreamProver with a GPT-5.3-Codex backbone solves 95/122 = 77.9%, compared with a GPT-5.3-Codex baseline at 59/122 = 48.4% (Zhang et al., 29 Apr 2026). Appendix examples such as quadratic_form_difference_identity, gradient_step_algebraic_identity, and subgradient_bound_on_f_diff indicate that the learned artifacts are neither raw premises from a fixed library nor theorem-specific one-offs, but reusable domain abstractions.

5. Datasets and knowledge infrastructures

A large part of FormalML is infrastructural. MLFMF provides a collection of datasets for recommendation and premise-selection over formal mathematical libraries extracted from Lean 4 Mathlib, the Agda standard library, Agda-unimath, and TypeTopology (Bauer et al., 2023). Each library is represented both as a heterogeneous dependency multigraph and as s-expressions encoding elaborated syntax trees or computational graphs. The collection contains more than 250000250\,000 entries in total, and the paper reports that node2vec-based link prediction decisively outperforms content-only baselines, with 0.96/0.96/0.98/0.95 accuracy on the Agda stdlib, Agda-unimath, TypeTopology, and Lean Mathlib4 datasets respectively (Bauer et al., 2023). The paper’s main lesson is that graph structure is highly informative for recommendation in formal libraries.

FormalSpecCpp addresses a comparable gap in software verification. It contributes 105 C++ files with preconditions and postconditions, derived from verified Dafny sources and translated with GPT-4-turbo, using the macro-based schema #define REQUIRE(cond) assert(cond) and #define ENSURE(cond) assert(cond) (Chakraborty et al., 21 Feb 2025). The first-pass validation found that 62 passed all tests and 43 failed, and the authors emphasize that test translation noise and semantic drift required manual review (Chakraborty et al., 21 Feb 2025). The value of the dataset is not a new verifier, but a standardized benchmark for C++ contract inference and validation, where such infrastructure had been missing.

A related infrastructure effort appears in control engineering knowledge representation. Using PyIRK and a semi-formal intermediate language called Formal Natural Language, one paper describes an LLM-supported pipeline that transforms LaTeX source and natural-language descriptions into a formal knowledge graph, then augments the original document with an “interactive semantic layer” (Fiedler et al., 4 Nov 2025). The authors report that roughly 10% to 20% of FNL statements require manual intervention and that the first two sections of a control-engineering monograph—eight pages—were converted into an HTML document with approximately 700 tooltip elements (Fiedler et al., 4 Nov 2025). This suggests a broader FormalML pattern in which formalization is valuable not only for back-end verification but also for front-end navigation, traceability, and reuse.

6. Broader applications, adjacent usages, and recurrent limitations

Beyond theorem proving and dataset construction, FormalML includes domain-specific formalization pipelines and foundational semantic work. In hardware generation, CktFormalizer redirects natural-language-to-hardware generation through a dependently typed HDL embedded in Lean 4, using Lean as type checker, correctness firewall, and proof assistant (Xiong et al., 8 May 2026). On VerilogEval, RTLLM, and ResBench, it achieves simulation pass rates competitive with direct Verilog generation while delivering substantially higher backend realizability: 95–100% of compiled designs complete the full synthesis, place-and-route, DRC, and LVS flow (Xiong et al., 8 May 2026). Its closed-loop optimization stage reports up to 35.2% area reduction and 30.3% post-route power reduction on validated variants.

In temporal logic, “Formalizing MLTL Formula Progression in Isabelle/HOL” supplies a machine-checked reference development for Mission-time Linear Temporal Logic, including syntax, finite-trace semantics, custom induction rules, computation length, and a verified progression algorithm (Kosaian et al., 2024). The paper explicitly states that it “identify and fix several errors and gaps in the source material,” illustrating a recurrent FormalML theme: mechanization often sharpens or corrects informal theory. “A Monadic Formalization of ML5” plays a similar role for programming-language semantics, explaining ML5 by translating it into intuitionistic S5S5 with a lax modality interpreted as a monad, and embedding the target logic as a universe within Agda (Licata et al., 2010). “Formal Aspects of Language Modeling” provides another foundational clarification by defining a LLM as a distribution over Σ\Sigma^*, introducing tightness, and distinguishing sequence models from genuine LLMs that assign zero mass to infinite strings (Cotterell et al., 2023).

The term “formal” is not uniform across all papers that align themselves with a FormalML agenda. One multilingual generation study treats formality as a sociolinguistic property rather than a formal specification artifact, comparing XGLM and BLOOM across Arabic, Bengali, English, French, and Spanish, and releasing 6,000 manually annotated samples labeled formal, informal, or incohesive (Ersoy et al., 2023). This is a distinct use of “formal,” concerning linguistic register rather than theorem proving or contract verification, and it underscores a terminological ambiguity in the broader label.

Across the literature, several limitations recur. Mixed Formal Learning depends strongly on identifying an appropriate formal representation in the first place (Carrico, 2019). Autoformalization systems still struggle with semantic fidelity, library-specific naming, and the mismatch between natural-language reasoning and formal proof obligations (Lu et al., 2024, Yu et al., 5 May 2025, Lu et al., 9 Aug 2025). Dataset-construction papers repeatedly require human curation because automatically generated formal artifacts can be syntactically plausible but semantically wrong (Chakraborty et al., 21 Feb 2025, Fiedler et al., 4 Nov 2025). Requirement-verification work further shows that failure to prove equivalence may reflect non-equivalence, poor formalization, or incomplete grounding, rather than contradiction in a strict logical sense (Gupte et al., 14 Nov 2025). A plausible implication is that FormalML’s central challenge is no longer only how to generate formal artifacts, but how to ground, validate, reuse, and maintain them across domains with different notions of correctness and different forms of formal structure.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (17)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to FormalML.