lean4-htt/src/Lean/Meta/Tactic
Joachim Breitner 1311e36a98
feat: structural mutual recursion (#4575)
This adds support for mutual structural recursive functions.

For now this is opt-in: The functions must have a `termination_by
structural …` annotation (new since #4542) for this to work:

```lean
mutual
inductive A
  | self : A → A
  | other : B → A
  | empty
inductive B
  | self : B → B
  | other : A → B
  | empty
end

mutual
def A.size : A → Nat
  | .self a => a.size + 1
  | .other b => b.size + 1
  | .empty => 0
termination_by structural x => x
def B.size : B → Nat
  | .self b => b.size + 1
  | .other a => a.size + 1
  | .empty => 0
termination_by structural x => x
end
```

The recursive functions don’t have to be in a one-to-one relation to a
set of mutually recursive inductive data types. It is possible to ignore
some of the types:

```lean
def A.self_size : A → Nat
  | .self a => a.self_size + 1
  | .other _ => 0
  | .empty => 0
termination_by structural x => x
```

or have more than one function per argument type:

```lean
  def isEven : Nat → Prop
    | 0 => True
    | n+1 => ¬ isOdd n
  termination_by structural x => x

  def isOdd : Nat → Prop
    | 0 => False
    | n+1 => ¬ isEven n
  termination_by structural x => x
```


This does not include

 * Support for nested inductive data types or nested recursion
* Inferring mutual structural recursion in the absence of
`termination_by`.
 * Functional induction principles for these.
* Mutually recursive functions that live in different universes. This
may be possible,
maybe after beefing up the `.below` and `.brecOn` functions; we can look
into this some
   other time, maybe when there are concrete use cases.

---------

Co-authored-by: Richard Kiss <him@richardkiss.com>
Co-authored-by: Tobias Grosser <tobias@grosser.es>
2024-07-08 14:39:50 +00:00
..
AC feat: add a linter for local vars that clash with their constructors (#4301) 2024-06-14 13:03:09 +00:00
Grind feat: add grind core module (#4249) 2024-05-22 03:50:36 +00:00
LinearArith perf: use with_reducible in special-purpose decreasing_trivial macros (#3991) 2024-04-29 15:12:27 +00:00
Simp feat: safe exponentiation (#4637) 2024-07-03 05:12:53 +00:00
AC.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Acyclic.lean fix: regression on match expressions with builtin literals (#3521) 2024-02-27 18:49:44 +00:00
Apply.lean fix: improve synthAppInstances (#4646) 2024-07-03 19:14:25 +00:00
Assert.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Assumption.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
AuxLemma.lean feat: propagate maxHeartbeats to kernel (#4113) 2024-05-09 17:44:19 +00:00
Backtrack.lean chore: upstream solve_by_elim (#3408) 2024-02-21 01:16:04 +00:00
Cases.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Cleanup.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Clear.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Congr.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Constructor.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Contradiction.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Delta.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
ElimInfo.lean feat: custom eliminators for induction and cases tactics, and beautiful eliminators for Nat (#3629) 2024-03-09 15:31:51 +00:00
FunInd.lean feat: structural mutual recursion (#4575) 2024-07-08 14:39:50 +00:00
FVarSubst.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Generalize.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Grind.lean feat: add grind core module (#4249) 2024-05-22 03:50:36 +00:00
IndependentOf.lean chore: upstream solve_by_elim (#3408) 2024-02-21 01:16:04 +00:00
Induction.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Injection.lean fix: regression on match expressions with builtin literals (#3521) 2024-02-27 18:49:44 +00:00
Intro.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
LibrarySearch.lean chore: Std -> Batteries renaming (#4108) 2024-05-08 05:04:25 +00:00
LinearArith.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
NormCast.lean feat: use attribute command to add and erase simprocs (#3511) 2024-02-26 23:41:49 +00:00
Refl.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Rename.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Repeat.lean refactor: termination arguments as Expr, not Syntax (#3658) 2024-03-14 23:51:53 +00:00
Replace.lean chore: add 'since' dates to deprecated (#4617) 2024-07-02 04:30:09 +00:00
Revert.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Rewrite.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00
Rewrites.lean fix: do not lift (<- ...) over pure if-then-else (#3820) 2024-04-01 21:33:59 +00:00
Rfl.lean feat: change apply_rfl tactic so that it does not operate on = (#3784) 2024-03-27 12:04:22 +00:00
Simp.lean feat: report diagnostic information for simp at exception 2024-05-01 03:19:39 +02:00
SolveByElim.lean fix: solveByElim would add symm hypotheses to local context and make impossible-to-elaborate terms (#3962) 2024-04-22 04:13:22 +00:00
Split.lean fix: improve split discriminant generalization strategy (#4401) 2024-06-07 21:35:09 +00:00
SplitIf.lean fix: split (for if-expressions) should work on non-propositional goals (#4349) 2024-06-05 04:43:46 +00:00
Subst.lean fix: substVars in functional inductions removed valuable information (#3695) 2024-03-16 14:55:31 +00:00
Symm.lean chore: upstream solve_by_elim (#3408) 2024-02-21 01:16:04 +00:00
TryThis.lean chore: remove @ from rw? suggestions, and enable hover on constants in #check (#3911) 2024-04-19 01:27:02 +00:00
Unfold.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
UnifyEq.lean fix: missing withIncRecDepth and unifyEqs? and add support for offsets at unifyEq? (#4224) 2024-05-20 13:42:36 +00:00
Util.lean chore: delete deprecations from 2022 (#4618) 2024-07-02 03:47:33 +00:00