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

@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 2, 2025 13:14 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 3, 2025 16:22 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 3, 2025 17:37 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 6, 2025 21:02 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 7, 2025 10:35 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 10, 2025 15:41 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 13, 2025 12:06 Inactive
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 13, 2025 19:38 Inactive
Julian added a commit to Julian/lean.nvim that referenced this pull request Jan 14, 2025
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc January 14, 2025 19:32 Inactive
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