blob: f32d0e1bb42165c90c9e1ee03b8a4fce82d1e6a5 [file]
/-!
Tests that definitions by well-founded recursion (not on Nat) are irreducible.
-/
set_option pp.mvars false
def foo : Nat → Nat → Nat
| 0, m => m
| n+1, m => foo n (m + n)
termination_by n m => (n, m)
/--
error: Type mismatch
rfl
has type
?_ = ?_
but is expected to have type
foo 0 m = m
-/
#guard_msgs in
example : foo 0 m = m := rfl
/--
error: Type mismatch
rfl
has type
?_ = ?_
but is expected to have type
foo (n + 1) m = foo n (m + n)
-/
#guard_msgs in
example : foo (n+1) m = foo n (m + n) := rfl
-- also for closed terms
/--
error: Tactic `rfl` failed: The left-hand side
foo 0 0
is not definitionally equal to the right-hand side
0
⊢ foo 0 0 = 0
-/
#guard_msgs in
example : foo 0 0 = 0 := by rfl
section Unsealed
unseal foo
-- unsealing works, but does not have the desired effect
/--
error: Type mismatch
rfl
has type
?_ = ?_
but is expected to have type
foo 0 0 = 0
-/
#guard_msgs in
example : foo 0 0 = 0 := rfl
/--
error: Type mismatch
rfl
has type
?_ = ?_
but is expected to have type
foo (n + 1) m = foo n (n + m)
-/
#guard_msgs in
example : foo (n+1) m = foo n (n +m ):= rfl
end Unsealed
--should be sealed again here
/--
error: Type mismatch
rfl
has type
?_ = ?_
but is expected to have type
foo 0 m = m
-/
#guard_msgs in
example : foo 0 m = m := rfl
def bar : Nat → Nat → Nat
| 0, m => m
| n+1, m => bar n (m + n)
termination_by n m => (n, m)
-- Once unsealed, the full internals are visible. This allows one to prove, for example
-- an equality like the following
/--
error: Type mismatch
rfl
has type
?_ = ?_
but is expected to have type
foo = bar
-/
#guard_msgs in
example : foo = bar := rfl
unseal foo bar in
example : foo = bar := rfl
/-!
Tests that reducibility attributes set by the user are preserved for WF-recursive functions.
In particular, both `@[instance_reducible]` and `@[implicit_reducible]` should not be
overridden by the default `@[irreducible]` that WF recursion sets. See issue #7082.
-/
@[instance_reducible] def baz : Nat → Nat → Nat
| 0, m => m
| n+1, m => baz n (m + n)
termination_by n m => (n, m)
/-- info: @[instance_reducible] def baz : Nat → Nat → Nat -/
#guard_msgs in
#print sig baz
@[instance_reducible] def qux : Nat → Nat → Nat
| 0, m => m
| n+1, m => qux n (m + n)
termination_by n m => (n, m)
/-- info: @[instance_reducible] def qux : Nat → Nat → Nat -/
#guard_msgs in
#print sig qux