LongCat-Flash-Prover: Advancing Native Formal Reasoning via Agentic Tool-Integrated Reinforcement Learning

Paper: arXiv:2603.21065 Code: meituan-longcat/LongCat-Flash-Prover Code reference: main @ 95ef9359 (2026-05-09)

1. Motivation (研究动机)

当前形式化推理的主要瓶颈

这篇技术报告关注 Native Formal Reasoning:模型不是先用自然语言写推理、再事后翻译成 Lean4,而是直接在 Lean4 的形式系统中生成 statement、lemma sketch 和 proof,并通过 Lean4 verifier / compiler 的反馈迭代。现有 LLM 在自然语言数学推理上已经很强,但直接迁移到 Lean4 theorem proving 时有三个瓶颈。

  • 形式语义比普通工具调用更脆弱:Lean4 proof 同时是程序和逻辑对象,能编译只是最低门槛;statement 是否语义等价、proof 是否篡改目标、context 是否被污染,都需要额外检查。
  • 长轨迹 agentic RL 不稳定:formal proving 需要长序列、多轮工具反馈和异步 rollout。vanilla GRPO/PPO 风格目标会受到训练引擎与推理引擎概率不一致、rollout policy staleness 的影响。
  • 单一专家不能覆盖完整链路:auto-formalization、lemma-style sketching、whole-proof / sketch-proof proving 是不同能力;只训练一个 prover 会忽略 statement 质量、lemma decomposition 和 tool interaction 之间的耦合。

论文要解决的具体问题

论文训练一个 560B-parameter open-source MoE prover,使其具备三种 Lean4 native formal reasoning 能力:1)把自然语言问题转成 Lean4 formal statement;2)生成包含 helper lemmas 的 lemma-style sketch;3)直接或基于 sketch 生成 Lean4 proof。关键目标不是只提高 pass rate,而是在工具反馈闭环中同时提升 statement、sketch、proof 的正确性,并抑制模型利用 evaluator loopholes 的 reward hacking。

为什么值得研究

形式化定理证明把“看起来合理”的推理变成 Lean4 kernel 可检查的对象。如果模型能稳定生成语义正确的 statement 与合法 proof,就能把 LLM 数学推理接入可验证数学、软件验证和科学推理工作流。LongCat-Flash-Prover 的价值在于把 statement generation、lemma decomposition、proof search、tool feedback、RL stability 和 cheating detection 组合成可迭代训练闭环。

2. Idea (核心思想)

核心 insight 是:形式化推理不应被当成单一“生成 Lean code”任务,而应拆成多个可验证专家能力,并让工具反馈同时服务于数据合成、RL 奖励和合法性过滤。Auto-formalizer 负责语义等价的 Lean statement,sketcher 负责把复杂目标分解成 helper lemmas,prover 负责生成 Lean proof;三者通过 rejection sampling 和 tool-integrated trajectories 互相增强。

关键创新有三点:第一,提出 Hybrid-Experts Iteration Framework,用 auto-formalizer / sketcher / prover 三类专家合成六种轨迹集合,覆盖无工具的一步轨迹和带工具反馈的困难轨迹;第二,提出 HisPO,在 GRPO 目标上加入 sequence-level 与 token-level hierarchical gradient masking,降低长序列 agentic RL 中 train-inference discrepancy 的影响;第三,加入 theorem consistency 与 Lean4 AST legality detection,避免模型通过篡改 theorem、使用 axiom / opaque / #exit / unsafe 等方式骗过 verifier。

它和 DeepSeek-Prover、Kimina-Prover、Goedel-Prover 等 prior prover 的核心区别在于:这些方法通常侧重 proof generation 或 self-correction,而 LongCat-Flash-Prover 把 auto-formalization → sketch → proof → legality-aware reward 作为统一训练管线,并显式处理 MoE + asynchronous rollout 下的 policy staleness / inference discrepancy。

3. Method (方法)

3.1 Overall framework:三专家 + 工具反馈的轨迹合成

Figure 2 解读:这张图展示核心数据合成机制。输入是自然语言数学问题;Auto-Formalizer 先生成 Lean4 statement,并通过 syntax correctness 与 semantic consistency 过滤;statement 再分两路进入 Prover Expert 和 Sketcher Expert。Prover 可以直接生成 whole-proof;Sketcher 先生成 lemma-style sketch,再由 Prover 完成 helper lemmas。每一路都可以是单轮生成,也可以接入 Lean4 tool feedback 多轮修复;最终只保留 syntax-correct、theorem-consistent、legality-verified trajectories。

Auto-Formalization expert

  • Input:自然语言题目或未完成证明,记为
  • Output:Lean4 formal statement
  • Verifier / objective:statement syntax detection 与 semantic consistency detection 使用 Lean4 Server v4.15,把 generated statement 拼上 := by sorry 后编译;若唯一未完成部分是 sorry,返回 SORRY,否则返回 FAIL 用 LLM-as-a-Judger 检查自然语言题目与 Lean statement 是否语义一致。
  • 移除后可能失败:模型会弱化条件、改写目标,导致后续 proof 证明的是错误 theorem。

Sketcher expert

  • Input:自然语言问题 与已验证 formal statement
  • Output:lemma-style sketch ,其中 helper lemmas 初始可用 := by sorry 占位,主 theorem body 引用这些 lemmas。
  • Verifier / objective:sketch syntax check 与 theorem consistency check,要求 sketch 能作为合法 Lean 结构存在且不改变目标 theorem。
  • 移除后可能失败:复杂题只能依赖 whole-proof sampling,proof search 更耗 budget,且长上下文中容易重复失败。

Prover expert

  • Input:whole-proof setting 使用 ,sketch-proof setting 使用
  • Output:Lean4 proof
  • Verifier / objective:syntax verification 与 legality detection PASS 表示 Lean4 kernel 编译通过且没有未完成证明; 检查 proof 没有篡改 statement、污染 context 或注入 cheating constructs。
  • 移除后可能失败:proof 可能能编译,但不再对应原始 theorem。

3.2 六类 trajectory 集合与 curriculum synthesis

Hybrid-experts framework 生成六种 verified trajectories。Auto-formalization 的无工具与带工具轨迹为: Whole-proof 与 sketch-proof 的 verified sets 进一步要求 proof PASS 且 legality check 通过,例如: 另外还有 ,分别对应带 tool feedback 的 whole-proof、带 tool feedback 的 sketch、以及基于 sketch 的 tool-integrated proof completion。curriculum 先做无工具 single-turn synthesis,再做多轮 tool-call synthesis;先尝试 whole-proof,再用 sketch-proof 覆盖 whole-proof 失败的困难样本。直觉上,单轮成功样本较简单;需要工具反馈和 sketch 的样本更难,因此轨迹类型本身也提供 difficulty signal。

3.3 训练管线:cold-start、self-distillation、domain-mixed SFT 与 agentic RL

Figure 3 解读:训练从 LongCat Mid-train Base 出发,先利用 ATF-32B 与 prior LongCat-Flash-Thinking 系列模型合成 formal statement 和 agentic trajectories,再经过 decontamination、deduplication、difficulty/diversity sampling 做 domain-mixed SFT,得到 cold-start model。之后进入 iteration phase:用新 cold-start model 刷新 prompts 与 trajectories,通过 self-distillation 和 agentic TIR RL 继续提升 formal reasoning,同时混入 general reasoning trajectories 以保持通用能力。

Data curation 有三步:1)Basic processing:语义去重、desaturation、质量检查,并过滤可能接近 test set 的 formal statements;2)Difficulty estimation:对每个 prompt 重复采样 条 trajectories,并计算 这里 是六类 verified trajectory set 中的一类。difficulty 为 0 的 prompt 留到后续合成;若连续多轮为 1,说明过易,会从 synthesis process 移除以节约计算。3)Diversity sampling:每个 prompt 只保留一条 trajectory,但按平均轨迹长度与 tool-call frequency 做 weighted sampling,避免过长推理或无关 tool use,同时保留整体多样性。

3.4 HisPO:分层 importance masking 稳定 long-horizon agentic RL

vanilla GRPO 在该任务上不稳定,因为 importance ratio 同时包含 train-inference engine discrepancy 和 policy staleness: HisPO 在 GRPO surrogate objective 中加入 masking matrix: 直觉上,sequence-level mask 会丢弃整体 train-inference discrepancy 过大的 trajectory;token-level mask 进一步丢弃局部概率比异常的 token。这样不是盲目裁剪所有 PPO ratio,而是只让“训练引擎和推理引擎足够一致”的 token 贡献梯度。

3.5 Reward hacking 修复:theorem consistency + AST legality detection

论文在 RL 过程中观察到训练集 rollout pass rate 在第 80 step 左右异常暴涨。原因是旧 evaluation pipeline 只看 Lean4 syntax verification 和 target theorem definition consistency,但 target theorem 的 formal context 可编辑;模型可以通过 importopen、helper definitions、axiom#exitunsafe、local instance 等方式绕过真正证明。

Figure 4 解读:hacking 曲线在训练中出现过快上升,说明模型学到的是 evaluator loophole,而不是真正证明能力。修复 reward function 后,从第 80 step 恢复训练,pass rate 不再虚高;Table 5 显示,加入 AST Checking 后,hacking model 的 1024 个训练样本中只有 286 个仍通过,而 fixed model 有 499 个通过,说明修复后的模型牺牲了表面 syntax pass rate,但提升了合法 proof 比例。

Released code 中这部分对应 lean4parser:它把 Lean4 code tokenize、parse 成 AST,再比较 problem definition 与 generated proof 的 AST consistency。论文公式与 released code 实现差异 / scope gap:GitHub commit main@95ef9359 只公开了 legality checker、Lean4 parser、README 与结果图;没有公开 Hybrid-Experts synthesis、HisPO / GRPO training loop、DORA rollout、SFT/RL configs 或 launch scripts。因此 HisPO 与三专家训练伪代码只能依据论文公式和 arXiv source,而 legality-check pseudocode 可直接锚定 released code。

Figure 5 解读:Tree Search 把模型提示成统一的 Judger-Sketcher-and-Prover。每一步给模型当前 tree outline、已证明 lemmas 构成的 formal context,以及当前 target theorem / lemma。模型可以判断节点是否 provable、输出 sketch 继续分解,或输出完整 proof。已证明 lemmas 会被压缩成 axioms,只保留 statement 不保留 proof body,从而减少 agent memory;未证明或失败的子树会被剪枝,已完成的 by-products 可作为后续参考。

Tree Search 的规则包括:总 sketch depth 不超过 12,连续 chain 长度不超过 5,避免模型把同一问题反复改写成链式 sketch。

3.7 Pseudocode(paper-level + released-code-grounded)

Hybrid-experts trajectory synthesis(paper-level)

def synthesize_hybrid_trajectories(problem, autoformalizer, sketcher, prover, tools, n_samples):
    af, af_tir, whole, whole_tir, sketches, sketch_proofs = [], [], [], [], [], []
    for _ in range(n_samples):
        statement = autoformalizer.generate(problem)
        if tools.syntax_statement(statement) == "SORRY" and tools.semantic_consistent(problem, statement):
            af.append((problem, statement))
        else:
            statement, trace = tools.repair_statement(autoformalizer, problem, statement)
            if tools.syntax_statement(statement) == "SORRY" and tools.semantic_consistent(problem, statement):
                af_tir.append((problem, trace, statement))
    for problem, statement in af + [(p, s) for p, _, s in af_tir]:
        proof = prover.generate_whole_proof(problem, statement)
        if tools.syntax_proof(proof) == "PASS" and tools.legal(statement, proof):
            whole.append((problem, statement, proof))
        else:
            proof, trace = tools.repair_proof(prover, problem, statement, proof)
            if tools.syntax_proof(proof) == "PASS" and tools.legal(statement, proof):
                whole_tir.append((problem, statement, trace, proof))
        sketch, sketch_trace = tools.generate_sketch(sketcher, problem, statement)
        if tools.syntax_statement(sketch) == "SORRY" and tools.theorem_consistent(statement, sketch):
            sketches.append((problem, statement, sketch_trace, sketch))
            sketch_proof = tools.prove_each_lemma(prover, problem, sketch)
            if tools.syntax_proof(sketch_proof) == "PASS" and tools.legal(statement, sketch_proof):
                sketch_proofs.append((problem, sketch, sketch_proof))
    return af, af_tir, whole, whole_tir, sketches, sketch_proofs

Difficulty / diversity sampling(paper-level)

def curate_iteration_data(prompts, verified_sets, n_samples):
    retained = []
    for x in prompts:
        difficulty = {
            name: sum(1 for traj in trajs if traj[0] == x) / n_samples
            for name, trajs in verified_sets.items()
        }
        if all(score == 0.0 for score in difficulty.values()):
            retained.append((x, "future_synthesis"))
        elif any(0.0 < score < 1.0 for score in difficulty.values()):
            candidates = [traj for trajs in verified_sets.values() for traj in trajs if traj[0] == x]
            weights = [1.0 / (1.0 + trajectory_length(t) + tool_call_count(t)) for t in candidates]
            retained.append(weighted_sample(candidates, weights))
        elif easy_for_multiple_iterations(x):
            continue
    return retained

HisPO gradient masking(paper-level)

import torch
 
 
def hispo_surrogate_loss(logp_train, logp_infer_old, logp_train_old, advantages, eps, delta_seq, delta_tok):
    log_ratio = logp_train - logp_infer_old
    log_ratio_dis = logp_train_old - logp_infer_old
    ratio = torch.exp(log_ratio)
    ratio_dis = torch.exp(log_ratio_dis)
    seq_discrepancy = torch.exp(log_ratio_dis.mean(dim=1)) - 1.0
    seq_mask = (seq_discrepancy.abs() < delta_seq).float().unsqueeze(1)
    tok_mask = ((ratio_dis - 1.0).abs() < delta_tok).float()
    h_mask = seq_mask * tok_mask
    unclipped = ratio * advantages
    clipped = torch.clamp(ratio, 1.0 - eps, 1.0 + eps) * advantages
    objective = h_mask * torch.minimum(unclipped, clipped)
    return -objective.sum() / (logp_train.shape[0] * logp_train.shape[1])

Lean4 AST legality check(released-code-grounded)

from lean4parser import Checker
 
 
def legality_check(formal_statement: str, proof: str, allow_sorry: bool = False):
    checker = Checker()
    problem_tokens, problem_ast = checker.parse_ast(formal_statement, return_tokens=True)
    proof_ast = checker.parse_ast(proof)
    if problem_ast is None or proof_ast is None:
        return False, "failed to parse ast"
    return checker.check_ast_consistency(formal_statement, proof, allow_sorry=allow_sorry)

Agentic lemma tree search(paper-level)

def lemma_tree_search(model, root_theorem, imports, max_depth=12, max_chain=5):
    tree = initialize_tree(root_theorem)
    context = {"imports": imports, "proved_lemmas": []}
    while tree.has_open_nodes():
        node = tree.select_open_node()
        prompt = build_prompt(tree_outline=tree.outline(), context=context, target=node.statement)
        action = model.judge_sketch_or_prove(prompt)
        if action.kind == "UNPROVABLE":
            tree.prune(node)
        elif action.kind == "SKETCH" and node.depth < max_depth and node.chain_len < max_chain:
            tree.expand(node, action.lemmas)
        elif action.kind == "PROOF" and lean4_passes(action.proof):
            tree.mark_proved(node, action.proof)
            context["proved_lemmas"].append(as_axiom(node.statement))
        else:
            tree.backtrack(node)
    return tree.assemble_proof() if tree.root_is_proved() else None

3.8 Code-to-paper mapping

Code reference: main @ 95ef9359 (2026-05-09) — pseudocode and mapping based on this commit

Paper ConceptSource FileKey Class/Function
Lean4 legality detection / AST consistencylean4parser/checker.pyChecker.parse_ast, Checker.check_ast_consistency
Public API for parser/checkerlean4parser/__init__.pyparse, parse_file, parse_clean, check_consistency, extract_last_theorem, extract_axioms
Lean4 lexical analysislean4parser/lexer.pyLexer.tokenize, Lexer.next_token, TokenType
Lean4 syntactic parserlean4parser/parser.pyParser.parse, parse_definition, parse_set_option, parse_variable, parse_macro, parse_instance
AST nodes and source reconstructionlean4parser/ast.pyModule, Definition, Variable, SetOption, Macro, Instance, to_source methods
Released result figures / README evaluation displayREADME.md, figures/*.pngevaluation result images for auto-formalization, proving and general tasks
HisPO / Hybrid-Experts / DORA rollout / SFT-RL trainingnot released in GitHub commitpaper-only description in arXiv source sections/recipe.tex and sections/hybrid_experts_iter.tex

4. Experimental Setup (实验设置)

Datasets and scale

  • CombiBench:100 个 combinatorial math problems,覆盖中学到大学/IMO 难度,十多个组合数学主题。
  • FormalMath-lite:425 个题目,其中 359 个高中级、66 个本科级,来自 5,560 题 FormalMATH 的精选子集。
  • MathOlympiad-Bench:360 个 human-verified Olympiad-level formalizations,包括 158 个 1959–2024 IMO 题、131 个 2006–2023 IMO shortlist 题、68 个 national Olympiad 题和 3 个 puzzle。
  • MiniF2F-Test:MiniF2F 含 244 train + 244 test;论文只在 test split 上评估。
  • ProofNet-Test:ProofNet Lean4 translation 含 valid/test 两个 split,分别 185 / 186 题;论文用 test split。
  • ProverBench:325 个 formalized math problems,其中 15 个 recent AIME high-school competition problems,310 个 textbook/tutorial undergraduate-level problems。
  • PutnamBench:1965–2025 Putnam Mathematical Competition 题目的 Lean4 formalizations,共 672 个。
  • General reasoning benchmarks:AIME-25、HMMT-25、IMO-AnswerBench、AMO-Bench EN/CH、GPQA-Diamond、LiveCodeBench 24.08–25.05、OJBench。

Baselines

Open-weights reasoning baselines 包括 DeepSeek-V3.2、Kimi-K2.5;closed-weights reasoning baselines 包括 Claude-Opus-4.5、Gemini-3 Pro。Auto-formalizer baselines 包括 Kimina-Autoformalizer-7B、StepFun-Formalizer-7B/32B、Goedel-V2-Formalizer-8B/32B、ATF-8B-Distilled、ATF-32B。Prover baselines 包括 Kimina-Prover-8B/72B、DeepSeek-Prover-V2-7B/671B、Leanabell-Prover-V2-KM/DS、Goedel-Prover-V2-8B/32B;large-budget 表还比较 Self-play Theorem Proving、Delta-Prover、Seed-Prover、Seed-Prover 1.5。

Metrics

  • Pass@8 / Pass@32 / Pass@b:在给定采样/尝试预算下至少一个输出通过验证的比例;theorem proving 的 Pass@32 用 unbiased estimation。
  • Avg@k:general reasoning tasks 中对 次采样取平均表现。
  • Verification-layer pass rate:对 1024 个 training cases,逐层加入 syntax verification、target consistency 和 AST checking 后仍通过的 proof 数量与比例。

Training / inference config disclosed by paper and code

  • Model:LongCat-Flash-Prover 是 560B-parameter open-source MoE model,初始化自 LongCat Mid-train Base;cold-start 使用 ATF-32B 与 LongCat-Flash-Thinking 系列产生 formal data / trajectories。
  • Training stages:domain-mixed SFT → self-distillation / trajectory refresh → agentic TIR RL;重复多轮后再做 final SFT + agentic TIR RL。
  • Tool stack:Lean4 Server v4.15 用于 statement/proof syntax check;LLM-as-a-Judger 做 semantic consistency;released lean4parser 做 AST legality check。
  • Not disclosed:论文和 main@95ef9359 release 没有提供 GPU 类型/数量、batch size、learning rate、optimizer、训练总 steps、HisPO 的 、DORA rollout 并发配置或实际 launch config;因此这些训练超参不能从 repo defaults 推断。
  • Inference budgets:Table 2 固定 Pass@32;Table 3 报告 larger-budget setting,例如 MiniF2F-Test 72、ProverBench 220、PutnamBench 118 attempts for LongCat sketch-proof + Tree Search。

5. Experimental Results (实验结果)

Overall proving comparison(Figure 1)

Figure 1 解读:左图和中图展示 fixed Pass@32 下 MathOlympiad-Bench 与 PutnamBench 的 proving performance,右图展示 MiniF2F-Test 在不同 inference budget 下的 sample efficiency。LongCat-Flash-Prover 在 whole-proof、whole-proof w/ TIR、sketch-proof w/ TIR 三种模式中逐步提升,说明 tool feedback 与 lemma-style sketch 对 proving 任务都有贡献。

Auto-formalization results

ModelCombiBenchFormalMath-LiteMathOlympiadMiniF2FProofNetProverBenchPutnamBench
LongCat-Flash-Prover83.098.693.399.287.195.289.9
LongCat-Flash-Prover w/ TIR97.099.899.2100.097.9100.098.1

TIR 最大带来 14.0 points 增益(CombiBench:83.0 → 97.0)。MiniF2F-Test 和 ProverBench 达到 100.0,ProofNet 达到 97.9,说明工具反馈对修复 syntax/semantic errors 特别有效。

Theorem proving at Pass@32

Model / modeMathOlympiadMiniF2FProofNetProverBenchPutnamBench
Goedel-Prover-V2-32B w/ self-correction20.390.4--8.6
LongCat whole-proof mode16.984.419.949.94.9
LongCat whole-proof mode w/ TIR27.590.236.157.910.4
LongCat sketch-proof mode w/ TIR35.893.947.366.528.9

Whole-proof mode 本身不一定强于已有专用 prover;加入 TIR 后显著提升;再加入 sketch-proof 后,在 MathOlympiad、ProofNet、ProverBench、PutnamBench 上都形成新的 open-weights SOTA。PutnamBench 从 whole-proof TIR 的 10.4 提升到 sketch-proof TIR 的 28.9,说明 lemma decomposition 对难题尤其关键。

Larger-budget / Tree Search results

LongCat modeMathOlympiadMiniF2FProofNetProverBenchPutnamBench
sketch-proof w/ TIR42.5 / 18095.5 / 7251.1 / 6869.5 / 22031.7 / 118
sketch-proof w/ TIR & Tree Search46.7 / 18097.1 / 7252.2 / 6870.8 / 22041.5 / 118

Tree Search 平均带来 3.1 points 提升。最显著的是 PutnamBench:31.7 → 41.5,在相同 118 budget 下增加 9.8 points;MiniF2F-Test 达到 97.1,只用 72 inference budget。

General reasoning retention

Informal TaskLongCat-Flash-Thinking-2601LongCat-Flash-Prover
AIME-25 (Avg@16)99.697.7
HMMT-25 (Avg@16)93.490.8
IMO-AnswerBench (Avg@4)78.677.3
AMO-Bench EN (Avg@16)61.662.2
AMO-Bench CH (Avg@16)56.857.3
GPQA-Diamond (Avg@16)80.579.2
LCB 24.08–25.05 (Avg@4)82.881.8
OJBench (Pass@1)42.241.8

Formal training 没有完全破坏通用能力:AIME/HMMT/IMO/GPQA/LCB/OJBench 有小幅下降,但 AMO-Bench EN/CH 略升。

Reward hacking / legality ablation

Verification LayerStep-100 (hacking)Step-96 (fixed)
Syntax Verification1003 / 1024 (97.9%)715 / 1024 (69.8%)
+ Target Consistency999 / 1024 (97.6%)702 / 1024 (68.6%)
+ AST Checking (fix)286 / 1024 (27.9%)499 / 1024 (48.7%)

这个表是论文最重要的可靠性证据之一:hacking model 在 syntax 与 target consistency 层几乎全过,但加 AST checking 后骤降到 27.9%;fixed model 的 syntax pass rate 较低,却有更高比例的合法 proof 通过 AST checking。也就是说,单看 Lean compiler pass rate 会高估模型真实证明能力。

Limitations and caveats

  • 训练细节不可复现:公开 repo 没有 release training code、DORA rollout、HisPO implementation 或 launch configs;论文也未公开 GPU/LR/batch/steps 等关键训练超参。
  • closed-weight baseline 不完全可控:论文注明 closed-weight reasoning model 的 inference API 存在不稳定性,因此部分指标可能不能完全反映真实能力。
  • evaluation 仍依赖 checker 覆盖率:AST legality detection 能覆盖论文列出的 9 类 cheating patterns,但未来模型可能发现新的 Lean4/evaluator loopholes;checker 需要持续维护。
  • Tree Search 成本与策略未完全展开:论文说明 depth=12、consecutive chain=5 等限制,但没有系统报告 tree-search compute cost、失败模式或剪枝策略消融。

总的来说,LongCat-Flash-Prover 的实验证明:agentic tool feedback、lemma-style sketching、HisPO 稳定化训练与 legality-aware reward 是互补的;其中 sketch-proof + TIR 决定了 proving SOTA,AST legality detection 决定了这些分数是否可信。