Skip to content

feat: partial_fixpoint: theory #6477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2025
Merged

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Dec 30, 2024

This PR adds the necessary domain theory that backs the
partial_fixpoint feature.

Part of #6355.

This PR adds the necessary domain theory that backs the
`partial_fixpoint` feature.

Part of #6355.
@nomeata nomeata added will-merge-soon …unless someone speaks up changelog-library Library labels Dec 30, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 30, 2024 11:03 Inactive
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 30, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 30, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 30, 2024
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Dec 30, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 30, 2024

Mathlib CI status (docs):

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 30, 2024 12:07 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 30, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 30, 2024
@nomeata nomeata added this pull request to the merge queue Jan 2, 2025
Merged via the queue into master with commit 7d0c0d4 Jan 2, 2025
19 checks passed
@nomeata nomeata deleted the joachim/partial_fixpoint_theory branch January 2, 2025 11:08
luisacicolini pushed a commit to opencompl/lean4 that referenced this pull request Jan 21, 2025
This PR adds the necessary domain theory that backs the
`partial_fixpoint` feature.

Part of leanprover#6355.
github-merge-queue bot pushed a commit that referenced this pull request Jan 21, 2025
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
#6477)
* A tactic to solve monotonicity goals compositionally (a bit like
mathlib’s `fun_prop`) (merged as
#6506)
* An attribute to extend that tactic (merged as
#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).
JovanGerb pushed a commit to JovanGerb/lean4 that referenced this pull request Jan 21, 2025
This PR adds the necessary domain theory that backs the
`partial_fixpoint` feature.

Part of leanprover#6355.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR changelog-library Library toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN will-merge-soon …unless someone speaks up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants