lean4-htt/src/Init
Joachim Breitner 7b813d4f5d
feat: partial_fixpoint: partial functions with equations (#6355)
This PR adds the ability to define possibly non-terminating functions
and still be able to reason about them equationally, as long as they are
tail-recursive or monadic.

Typical uses of this feature are
```lean4
def ack : (n m : Nat) → Option Nat
  | 0,   y   => some (y+1)
  | x+1, 0   => ack x 1
  | x+1, y+1 => do ack x (← ack (x+1) y)
partial_fixpiont

def whileSome (f : α → Option α) (x : α) : α :=
  match f x with
  | none => x
  | some x' => whileSome f x'
partial_fixpiont

def computeLfp {α : Type u} [DecidableEq α] (f : α → α) (x : α) : α :=
  let next := f x
  if x ≠ next then
    computeLfp f next
  else
    x
partial_fixpiont

noncomputable def geom : Distr Nat := do
  let head ← coin
  if head then
    return 0
  else
    let n ← geom
    return (n + 1)
partial_fixpiont
```

This PR contains

* The necessary fragment of domain theory, up to (a variant of)
Knaster–Tarski theorem (merged as
https://github.com/leanprover/lean4/pull/6477)
* A tactic to solve monotonicity goals compositionally (a bit like
mathlib’s `fun_prop`) (merged as
https://github.com/leanprover/lean4/pull/6506)
* An attribute to extend that tactic (merged as
https://github.com/leanprover/lean4/pull/6506)
* A “derecursifier” that uses that machinery to define recursive
function, including support for dependent functions and mutual
recursion.
* Fixed-point induction principles (technical, tedious to use)
* For `Option`-valued functions: Partial correctness induction theorems
that hide all the domain theory

This is heavily inspired by [Isabelle’s `partial_function`
command](https://isabelle.in.tum.de/doc/codegen.pdf).
2025-01-21 09:54:30 +00:00
..
Control chore: run Batteries linter on Lean (#6364) 2024-12-13 01:28:53 +00:00
Data feat: partial_fixpoint: partial functions with equations (#6355) 2025-01-21 09:54:30 +00:00
Grind feat: case splitting in grind (#6717) 2025-01-20 22:44:56 +00:00
Internal feat: partial_fixpoint: partial functions with equations (#6355) 2025-01-21 09:54:30 +00:00
Omega chore: cleanup of List/Array lemmas (#6249) 2024-11-29 06:12:38 +00:00
System refactor: move IO.Channel and IO.Mutex to Std.Sync (#6282) 2024-12-03 09:36:50 +00:00
BinderPredicates.lean chore: upstream set notation (#3339) 2024-02-15 02:08:45 +00:00
ByCases.lean chore: cleaning up redundant simp lemmas (#5381) 2024-09-18 10:06:29 +00:00
Classical.lean chore: move @[simp] from exists_prop' to exists_prop (#5529) 2024-10-01 05:38:18 +00:00
Coe.lean fix: make Lean.Internal.liftCoeM and Lean.Internal.coeM unfold (#3404) 2024-02-27 22:17:46 +00:00
Control.lean
Conv.lean feat: add simp? and dsimp? in conversion mode (#6593) 2025-01-10 01:42:17 +00:00
Core.lean chore: fix some docstrings (#6410) 2024-12-18 19:32:07 +00:00
Data.lean feat: add support for Float32 to the Lean runtime (#6348) 2024-12-09 21:33:43 +00:00
Dynamic.lean chore: snake-case attributes (part 2) 2022-10-19 09:28:08 -07:00
Ext.lean feat: add [ext] attribute to Array.ext (#4970) 2024-08-09 12:40:39 +00:00
GetElem.lean chore: run Batteries linter on Lean (#6364) 2024-12-13 01:28:53 +00:00
Grind.lean feat: improve grind failure message (#6633) 2025-01-14 01:10:47 +00:00
Guard.lean feat: upstream guard_expr (#3297) 2024-02-11 23:25:04 +00:00
Hints.lean
Internal.lean feat: partial_fixpoint: theory (#6477) 2025-01-02 09:39:18 +00:00
MacroTrace.lean chore: reorganising to reduce imports (#3790) 2024-03-27 11:15:01 +00:00
Meta.lean fix: allow ⱼ in identifiers (#6679) 2025-01-21 03:51:51 +00:00
MetaTypes.lean chore: add simp configuration to norm_cast syntax 2024-12-03 17:59:23 +11:00
Notation.lean feat: parity between structure instance notation and where notation (#6165) 2024-11-30 20:27:25 +00:00
NotationExtra.lean feat: labeled and unique sorries (#5757) 2024-12-11 23:53:02 +00:00
Omega.lean chore: update copyrights (#5449) 2024-09-24 05:27:53 +00:00
Prelude.lean feat: add lcAny constant to Prelude (#6665) 2025-01-17 01:33:35 +00:00
PropLemmas.lean feat: lemmas about lexicographic order on Array and Vector (#6399) 2024-12-19 10:36:50 +00:00
RCases.lean doc: typo in rcases docs (#3796) 2024-03-28 07:31:01 +00:00
ShareCommon.lean feat: USize.size inequalities (#6203) 2024-11-26 23:42:15 +00:00
SimpLemmas.lean chore: run Batteries linter on Lean (#6364) 2024-12-13 01:28:53 +00:00
Simproc.lean chore: fix simproc doc-string (#3800) 2024-03-28 17:54:52 +00:00
SizeOf.lean refactor: name the default SizeOf instance (#5981) 2024-11-07 09:21:32 +00:00
SizeOfLemmas.lean refactor: redefine unsigned fixed width integers in terms of BitVec (#5323) 2024-10-16 07:28:23 +00:00
Syntax.lean feat: rename Array.setD to setIfInBounds (#6195) 2024-11-24 08:54:19 +00:00
System.lean feat: Mutex, Condvar 2022-09-05 08:52:46 -07:00
Tactics.lean chore: remove [grind_norm] attribute (#6692) 2025-01-19 02:12:01 +00:00
TacticsExtra.lean feat: activate new tactic configuration syntax for most tactics (#5898) 2024-11-01 02:08:53 +00:00
Util.lean feat: generalize panic to Sort (#6333) 2024-12-15 21:36:45 +00:00
WF.lean chore: cleanup unused variables (#5579) 2024-10-02 01:51:22 +00:00
WFTactics.lean feat: update omega/solve_by_elim to use new tactic syntax, use new tactic syntax (#5932) 2024-11-03 16:23:37 +00:00
While.lean chore: make 'while' available earlier (#5784) 2024-10-21 05:56:37 +00:00