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 #253

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
3 changes: 3 additions & 0 deletions .vale/styles/config/ignore/terms.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
APIs
Abelian
Ackermann
Kleisli
Packrat
antiquotation
Expand Down Expand Up @@ -49,6 +50,8 @@ enum
equational
extensional
extensionality
fixpoint
fixpoints
functor
functor's
functors
Expand Down
16 changes: 14 additions & 2 deletions Manual/Language/RecursiveDefs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import VersoManual
import Manual.Meta

import Manual.Language.RecursiveDefs.Structural
import Manual.Language.RecursiveDefs.PartialFixpoint

open Verso.Genre Manual
open Lean.Elab.Tactic.GuardMsgs.WhitespaceMode
Expand All @@ -29,7 +30,7 @@ Furthermore, most useful recursive functions do not threaten soundness, and infi
Instead of banning recursive functions, Lean requires that each recursive function is defined safely.
While elaborating recursive definitions, the Lean elaborator also produces a justification that the function being defined is safe.{margin}[The section on {ref "elaboration-results"}[the elaborator's output] in the overview of elaboration contextualizes the elaboration of recursive definitions in the overall context of the elaborator.]

There are four main kinds of recursive functions that can be defined:
There are five main kinds of recursive functions that can be defined:

: Structurally recursive functions

Expand All @@ -47,6 +48,15 @@ There are four main kinds of recursive functions that can be defined:
Applications of functions defined via well-founded recursion are not necessarily definitionally equal to their return values, but this equality can be proved as a proposition.
Even when definitional equalities exist, these functions are frequently slow to compute with because they require reducing proof terms that are often very large.

: Recursive functions as fixpoints

Taking the function definition as an equation that specifies the behavior of the function, in certain cases the existence of a function satisfying this specification can be proven.
This strategy can apply even when the function definition is not necessarily terminating on all inputs; hence the term {tech}_partial fixpoint_.

In particular monadic functions in certain monads (e.g. {name}`Option`) are amenable for this strategy, and additional theorems are generated by lean (partial correctness).

As with well-founded recursion, applications of functions defined via partial fixpoint are not definitionally equal to their return values.

: Partial functions with nonempty ranges

For many applications, it's not important to reason about the implementation of certain functions.
Expand Down Expand Up @@ -77,7 +87,7 @@ As described in the {ref "elaboration-results"}[overview of the elaborator's out
If there is no such clause, then the elaborator performs a search, testing each parameter to the function as a candidate for structural recursion, and attempting to find a measure with a well-founded relation that decreases at each recursive call.

This section describes the rules that govern recursive functions.
After a description of mutual recursion, each of the four kinds of recursive definitions is specified, along with the tradeoffs between reasoning power and flexibility that go along with each.
After a description of mutual recursion, each of the five kinds of recursive definitions is specified, along with the tradeoffs between reasoning power and flexibility that go along with each.

# Mutual Recursion
%%%
Expand Down Expand Up @@ -162,6 +172,8 @@ tag := "well-founded-recursion"
This section will describe the translation of {deftech}[well-founded recursion].
:::

{include 0 Manual.Language.RecursiveDefs.PartialFixpoint}

# Partial and Unsafe Recursive Definitions
%%%
tag := "partial-unsafe"
Expand Down
Loading
Loading