Skip to content
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

feat: partial_fixpoint: partial functions with equations #6355

Draft
wants to merge 134 commits into
base: master
Choose a base branch
from

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Dec 10, 2024

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.

This is still WIP. In particular, syntax and naming is not finalized yet, and currently inconsistent and all-over the place.

Typical uses of this feature are

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
  • A tactic to solve monotonicity goals compositionally (a bit like mathlib’s fun_prop)
  • An attribute to extend that tactic
  • A “derecursifyer” that uses that machinery to define recursive function, including support for dependent functions and mutual recursion.
  • Fixed-point induction principles (technical, tediuos 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.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 20, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 26, 2024 08:48 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 26, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 26, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 28, 2024 22:29 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 28, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 28, 2024
This PR adds the necessary domain theory that backs the
`partial_fixpoint` feature.

Part of #6355.
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 30, 2024 11: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
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 30, 2024 12:30 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
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 30, 2024 16:35 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
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 toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants