lean4-htt/tests/lean/termination_by.lean
Joachim Breitner b5122b6a7b feat: per-function termination hints
This change

 * moves `termination_by` and `decreasing_by` next to the function they
   apply to
 * simplify the syntax of `termination_by`
 * apply the `decreasing_by` goal to all goals at once, for better
   interactive use.

See the section in `RELEASES.md` for more details and migration advise.

This is a hard breaking change, requiring developers to touch every
`termination_by` in their code base. We decided to still do it as a
hard-breaking change, because supporting both old and new syntax at the
same time would be non-trivial, and not save that much. Moreover, this
requires changes to some metaprograms that developers might have
written, and supporting both syntaxes at the same time would make
_their_ migration harder.
2024-01-10 17:27:35 +01:00

85 lines
1.8 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.

/-!
This module tests various mis-uses of termination_by and decreasing_by:
* use in non-recursive functions
* that all or none of a recursive group have termination_by.
-/
def nonRecursive1 (n : Nat) : Nat := n
termination_by n -- Error
def nonRecursive2 (n : Nat) : Nat := n
decreasing_by sorry -- Error
def nonRecursive3 (n : Nat) : Nat := n
termination_by n -- Error
decreasing_by sorry
partial def partial1 (n : Nat) : Nat := partial1 n
termination_by n -- Error
partial def partial2 (n : Nat) : Nat := partial2 n
decreasing_by sorry -- Error
partial def partial3 (n : Nat) : Nat := partial3 n
termination_by n -- Error
decreasing_by sorry
unsafe def unsafe1 (n : Nat) : Nat := unsafe1 n
termination_by n -- Error
unsafe def unsafe2 (n : Nat) : Nat := unsafe2 n
decreasing_by sorry -- Error
unsafe def unsafe3 (n : Nat) : Nat := unsafe3 n
termination_by x -- Error
decreasing_by sorry
unsafe def withWhere (n : Nat) : Nat := foo n
where foo (n : Nat) := n
termination_by n -- Error
unsafe def withLetRec (n : Nat) : Nat :=
let rec foo (n : Nat) := n
termination_by n -- Error
foo n
mutual
def rec : Nat → Nat
| 0 => 0
| n+1 => rec n + notrec n
termination_by x => x
def notrec (n : Nat) : Nat := n
termination_by n -- Error
end
mutual
def isEven : Nat → Bool
| 0 => true
| n+1 => isOdd n
termination_by x => x
def isOdd : Nat → Bool -- Error
| 0 => false
| n+1 => isEven n
end
namespace Test
mutual
def f : Nat → ααα
| 0, a, b => a
| n+1, a, b => g n a b |>.1
termination_by n _ _ => n
def g : Nat → αα → (α × α)
| 0, a, b => (a, b)
| n+1, a, b => (h n a b, a)
termination_by n _ _ => n
def h : Nat → ααα -- Error
| 0, a, b => b
| n+1, a, b => f n a b
end
end Test