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 111 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.

This is heavily inspired by Isabelle’s partial_function command.

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 16, 2024 11:16 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 16, 2024 11:29 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 16, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 16, 2024
@leanprover-community-bot leanprover-community-bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Dec 16, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 17, 2024 11:33 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 17, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 17, 2024 11:54 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 17, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc December 17, 2024 15:24 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 18, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 18, 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