lean4-htt/tests/lean/run/partial_fixpoint_prop.lean
Wojciech Rozowski 96fcc94acb
feat: add support for lattice-theoretic (co)inductive predicates (#8097)
This PR adds support for inductive and coinductive predicates defined
using lattice theoretic structures on `Prop`. These are syntactically
defined using `greatest_fixpoint` or `least_fixpoint` termination
clauses for recursive `Prop`-valued functions. The functionality relies
on `partial_fixpoint` machinery and requires function definitions to be
monotone. For non-mutually recursive predicates, an appropriate
(co)induction proof principle (given by Park induction) is generated.

Summary of changes:
- `Interal.Order.Basic` now contains `CompleteLattice` class, as well as
version of Knaster-Tarski fixpoint theorem (with an associated Park
induction principle) for the internal use for defining (co)inductive
predicates. `Prop` is shown to have two complete lattice structures (one
given by implication order for defining inductive predicates, and one
given by reverse implication for defining coinductive predicates).
Additionally, proofs that lattices are closed under products and
function spaces are included.
- Partial fixpoint's `EqnInfo` now additionally carries an information
whether something is defined as a lattice-theoretic fixpoint or via
CCPOs.
- When constructing a (co)inductive predicate,`PartialFixpoint/Main`
builds an appropriate lattice structure on the type of the predicate
using product lattice, function space lattice and an appropriate lattice
instance on `Prop`.
- `PartialFixpoint/Eqns` is modified to be able to perform rewrite under
lattice-theoretic fixpoint construction
- `PartialFixpoint/Induction`contains a case split for handling of the
(co)inductive predicates. In the case of lattice-theoretic fixpoints, it
appropriately desugars the Park induction principle.
2025-04-30 15:48:58 +00:00

25 lines
1.1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/--
Tests that `partial_fixpoint` is not picking up the partial order structure on Prop, that is exclusively used for defining (co)inductive predicates. Since `Prop` is inhabitted, `partial_fixpoint` will synthetise a `FlatOrder` instance, but in the provided example, it will not be able to prove that the recursive calls are monotone in their arguments.
-/
-- This works as `` is monotone in its arguments with respect to the (`ImplicationOrder`/`ReverseImplicationOrder` on `Prop`.
def f (x : Nat) : Prop :=
f (x + 1) f ( x + 2)
greatest_fixpoint
def f' (x : Nat) : Prop :=
f' (x + 1) f' ( x + 2)
least_fixpoint
/--
error: Could not prove 'f''' to be monotone in its recursive calls:
Cannot eliminate recursive call `f'' (x + 1)` enclosed in
f'' (x + 1) f'' (x + 2)
Tried to apply 'Lean.Order.implication_order_monotone_or' and 'Lean.Order.coind_monotone_or', but failed.
Possible cause: A missing `Lean.Order.MonoBind` instance.
Use `set_option trace.Elab.Tactic.monotonicity true` to debug.
-/
#guard_msgs in
def f'' (x : Nat) : Prop :=
f'' (x + 1) f'' ( x + 2)
partial_fixpoint