Skip to content

term_cases: close constructor disjointness and injectivity goals #280

Closed

Description

@afflom

Problem

term_cases cannot close a goal that needs constructor disjointness or injectivity. SPEC.md lines 2678 to 2700 (SM-35) lower it to:

cases llCase : <term> <;> simp (config := {decide := true}) only [<definitions>, llCase, ite_true, ite_false]

decide := true decides only closed propositions. After the split, a case that equates two different constructors over a variable is left open, for example Verdict.good = Verdict.bad p or none = some p. So is a case that equates the same constructor over different fields, Verdict.bad x = Verdict.bad p.

The everyday statement "if the check returns bad p, the report names p" therefore cannot be proved. The workaround is to restate theorems over Nat class flags, so every case is closed (UOR-Foundation/mcp#20, JsonGate).

Reproduced at release/v0.4 9796067, Lean 4.32.1:

\begin{lexlean}{Main}
\useglossary{lexlean.std.nat@1.2.0}
\title{Natural number addition}
\begin{semanticmodule}
inductive{name: Verdict, type_parameters: [], parameters: [], constructors: [{name: good, fields: []}, {name: bad, fields: [Nat]}]}

definition{
  name: check,
  parameters: [n : Nat],
  result: Verdict,
  body: (if (n =? 0) then (ctor Verdict.good) else (ctor Verdict.bad n))
}

definition{
  name: report,
  parameters: [n : Nat],
  result: (Option Nat),
  body: (match (check n)
    | Verdict.good => (ctor Option.none [Nat])
    | Verdict.bad at => (ctor Option.some [Nat] at))
}

theorem{
  name: report_names_the_bad_value,
  parameters: [n : Nat, p : Nat],
  statement: (((check n) = (ctor Verdict.bad p)) -> ((report n) = (ctor Option.some [Nat] p))),
  proof: term_cases{scrutinee: (check n), definitions: [report]},
  axioms: [propext]
}
\end{semanticmodule}
\end{lexlean}
error[LLV7002]: Lean rejected `Repro.Main` (error): unsolved goals
case good
n p : Nat
llCase : check n = Verdict.good
⊢ Verdict.good = Verdict.bad p → none = some p
case bad
n p x✝ : Nat
llCase : check n = Verdict.bad x✝
⊢ Verdict.bad x✝ = Verdict.bad p → some x✝ = some p

Item

term_cases (or a sibling proof form with its own row) closes constructor disjointness and injectivity, for the inductives of the module and for Option, Result and List. For example, it could add the generated <Ctor>.injEq lemmas and reduceCtorEq to the fixed simp set. The set stays fixed, so the proof form stays closed.

Accepted when

  • The theorem above verifies with an exact axiom policy.
  • A false variant is still rejected.
  • SM-35, or a new row, states the extended simp set.

Found while building UOR-Foundation/mcp#18.


Generated by Claude Code

Activity

  1. humuhumu33 commented on Oct 22, 2026

    @humuhumu33
    Contributor

    Claiming this. Plan: reproduce, then extend the fixed simp set of SM-35 (constructor injectivity and no-confusion lemmas, nothing from simp's default set), register first (row or SM-35 amendment, scenario, failing cases: the module above, an Option case, an injectivity case, and a false variant that must stay open), then the lowering change. term_cases and SM-35 are on release/v0.4 only (release/v0.5 has SM-01..SM-34 and no forward merge yet), so the branch is cut from release/v0.4; say if you want it on another line.

  2. humuhumu33 commented on Oct 23, 2026

    @humuhumu33
    Contributor

    Draft PR #299 against release/v0.4. It amends SM-35 with no new row: the fixed simp set gains reduceCtorEq, false_implies, imp_self, and_true, true_and, the Option/Except/List injectivity lemmas, and <T>.<c>.injEq for each constructor with a field of the module's inductives. The module above verifies with [propext], and the false variant is still rejected. No compiler-semantics identity moves.

  3. added a commit that references this issue on Oct 27, 2026
  4. afflom commented on Oct 31, 2026

    @afflom
    MemberAuthor

    Fixed by #299 (SM-35), merged into release/v0.5 on 2026-10-27. Closing.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions