lean4-htt/src/Lean/Elab
Wojciech Rozowski 2d52d44710
feat: fixpoint_induct and partial_correctness lemmas for mutual blocks come in conjunction and projected variants (#9651)
This PR modifies the generation of induction and partial correctness
lemmas for `mutual` blocks defined via `partial_fixpoint`. Additionally,
the generation of lattice-theoretic induction principles of functions
via `mutual` blocks is modified for consistency with `partial_fixpoint`.

The lemmas now come in two variants:
1. A conjunction variant that combines conclusions for all elements of
the mutual block. This is generated only for the first function inside
of the mutual block.
2. Projected variants for each function separately

## Example 1
```lean4
axiom A : Type
axiom B : Type

axiom A.toB : A → B
axiom B.toA : B → A

mutual
noncomputable def f : A := g.toA
partial_fixpoint
noncomputable def g : B := f.toB
partial_fixpoint
end
```

Generated `fixpoint_induct` lemmas:
```lean4
f.fixpoint_induct (motive_1 : A → Prop) (motive_2 : B → Prop) (adm_1 : admissible motive_1)
  (adm_2 : admissible motive_2) (h_1 : ∀ (g : B), motive_2 g → motive_1 g.toA)
  (h_2 : ∀ (f : A), motive_1 f → motive_2 f.toB) : motive_1 f

g.fixpoint_induct (motive_1 : A → Prop) (motive_2 : B → Prop) (adm_1 : admissible motive_1)
  (adm_2 : admissible motive_2) (h_1 : ∀ (g : B), motive_2 g → motive_1 g.toA)
  (h_2 : ∀ (f : A), motive_1 f → motive_2 f.toB) : motive_2 g
```

Mutual (conjunction) variant:
```lean4
f.mutual_fixpoint_induct (motive_1 : A → Prop) (motive_2 : B → Prop) (adm_1 : admissible motive_1) (adm_2 : admissible motive_2)
  (h_1 : ∀ (g : B), motive_2 g → motive_1 g.toA) (h_2 : ∀ (f : A), motive_1 f → motive_2 f.toB) :
  motive_1 f ∧ motive_2 g
```

## Example 2 
```lean4
mutual
  def f (n : Nat) : Option Nat :=
    g (n + 1)
  partial_fixpoint

  def g (n : Nat) : Option Nat :=
    if n = 0 then .none else f (n + 1)
  partial_fixpoint
end
```
Generated `partial_correctness` lemmas (in a projected variant):
```lean4
f.partial_correctness (motive_1 motive_2 : Nat → Nat → Prop)
  (h_1 :
    ∀ (g : Nat → Option Nat),
      (∀ (n r : Nat), g n = some r → motive_2 n r) → ∀ (n r : Nat), g (n + 1) = some r → motive_1 n r)
  (h_2 :
    ∀ (f : Nat → Option Nat),
      (∀ (n r : Nat), f n = some r → motive_1 n r) →
        ∀ (n r : Nat), (if n = 0 then none else f (n + 1)) = some r → motive_2 n r)
  (n r✝ : Nat) : f n = some r✝ → motive_1 n r✝

g.partial_correctness (motive_1 motive_2 : Nat → Nat → Prop)
  (h_1 :
    ∀ (g : Nat → Option Nat),
      (∀ (n r : Nat), g n = some r → motive_2 n r) → ∀ (n r : Nat), g (n + 1) = some r → motive_1 n r)
  (h_2 :
    ∀ (f : Nat → Option Nat),
      (∀ (n r : Nat), f n = some r → motive_1 n r) →
        ∀ (n r : Nat), (if n = 0 then none else f (n + 1)) = some r → motive_2 n r)
  (n r✝ : Nat) : g n = some r✝ → motive_2 n r✝
```

Mutual (conjunction) variant:
```
f.mutual_partial_correctness (motive_1 motive_2 : Nat → Nat → Prop)
  (h_1 :
    ∀ (g : Nat → Option Nat),
      (∀ (n r : Nat), g n = some r → motive_2 n r) → ∀ (n r : Nat), g (n + 1) = some r → motive_1 n r)
  (h_2 :
    ∀ (f : Nat → Option Nat),
      (∀ (n r : Nat), f n = some r → motive_1 n r) →
        ∀ (n r : Nat), (if n = 0 then none else f (n + 1)) = some r → motive_2 n r) :
  (∀ (n r : Nat), f n = some r → motive_1 n r) ∧ ∀ (n r : Nat), g n = some r → motive_2 n r
```
2025-08-18 15:26:30 +00:00
..
Deriving chore: warn on [expose] on private definition (#9917) 2025-08-15 11:31:33 +00:00
InfoTree refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
PreDefinition feat: fixpoint_induct and partial_correctness lemmas for mutual blocks come in conjunction and projected variants (#9651) 2025-08-18 15:26:30 +00:00
Quotation refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Tactic feat: tactic info per intro hypothesis, rfl pattern (#9942) 2025-08-18 13:55:06 +00:00
App.lean feat: use name resolution for dot identifier notation (#9634) 2025-08-01 02:27:40 +00:00
Arg.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Attributes.lean refactor: update and consolidate attribute-related error messages (#9495) 2025-07-26 02:03:18 +00:00
AutoBound.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
AuxDef.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
BinderPredicates.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Binders.lean feat: clean up type annotations when elaborating declaration bodies (#9674) 2025-08-18 04:43:20 +00:00
BindersUtil.lean fix: mark __x patterns as impl details in match and intro (#9702) 2025-08-04 22:54:39 +00:00
BuiltinCommand.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
BuiltinEvalCommand.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
BuiltinNotation.lean fix: have unsafe term produce an opaqueDecl (#9819) 2025-08-10 09:30:55 +00:00
BuiltinTerm.lean fix: function field notation errors when head is an fvar (#9595) 2025-07-28 23:07:02 +00:00
Calc.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
CheckTactic.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Command.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
ComputedFields.lean feat: Add List.zipWithM and Array.zipWithM (#9528) 2025-07-28 08:39:52 +00:00
Config.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Declaration.lean fix: macros unfolding to multiple commands inside mutual (#9649) 2025-07-31 21:00:53 +00:00
DeclarationRange.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
DeclModifiers.lean feat: allow combining private/public and protected 2025-08-09 12:35:07 +02:00
DeclNameGen.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
DeclUtil.lean fix: more deriving handlers under the module system (#9647) 2025-07-31 15:00:58 +00:00
DefView.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Deriving.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Do.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
ElabRules.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
ErrorExplanation.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Eval.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Exception.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Extra.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Frontend.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
GenInjective.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
GuardMsgs.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Import.lean refactor: move import validation to parser & Lake (#9716) 2025-08-05 22:36:54 +00:00
Inductive.lean feat: allow combining private/public and protected 2025-08-09 12:35:07 +02:00
InfoTree.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
InfoTrees.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
InheritDoc.lean refactor: update and consolidate attribute-related error messages (#9495) 2025-07-26 02:03:18 +00:00
LetRec.lean feat: default let rec and where decls to private under the module system (#9759) 2025-08-06 15:53:51 +00:00
Level.lean chore: break up universe level error message (#9637) 2025-07-30 23:52:53 +00:00
Macro.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
MacroArgUtil.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
MacroRules.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Match.lean fix: mark __x patterns as impl details in match and intro (#9702) 2025-08-04 22:54:39 +00:00
MatchAltView.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
MatchExpr.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Mixfix.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
MutualDef.lean feat: clean up type annotations when elaborating declaration bodies (#9674) 2025-08-18 04:43:20 +00:00
MutualInductive.lean fix: do not allow access to private primitives in public scope (#9890) 2025-08-14 15:34:54 +00:00
Notation.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Open.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
ParseImportsFast.lean refactor: move import validation to parser & Lake (#9716) 2025-08-05 22:36:54 +00:00
PatternVar.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
PreDefinition.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Print.lean chore: show @[expose] attribute in #print (#9722) 2025-08-05 15:59:49 +00:00
Quotation.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
RecAppSyntax.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
RecommendedSpelling.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
SetOption.lean feat: improve set_option error messages (#9496) 2025-07-26 02:04:45 +00:00
StructInst.lean fix: do not allow access to private primitives in public scope (#9890) 2025-08-14 15:34:54 +00:00
StructInstHint.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Structure.lean feat: allow combining private/public and protected 2025-08-09 12:35:07 +02:00
Syntax.lean feat: Add List.zipWithM and Array.zipWithM (#9528) 2025-07-28 08:39:52 +00:00
SyntheticMVars.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Tactic.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Term.lean chore: avoid turning accesses to private decs from public signatures into auto implicits (#9961) 2025-08-18 08:01:12 +00:00
Time.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00
Util.lean perf: shorten rebuild critical path by 19% (#9626) 2025-08-01 11:18:21 +00:00
WhereFinally.lean refactor: module-ize Lean (#9330) 2025-07-25 12:02:51 +00:00