blob: cef10a9ff5dbac1dbdce888c78c07ff323eda363 [file]
structure Foo where num : Nat deriving DecidableEq
namespace Foo
instance : OfNat Foo n := ⟨⟨n⟩⟩
/-! # Example 1 -/
@[irreducible] def mul (a b : Foo) : Foo :=
let d := Nat.gcd a.num 1
⟨(a.num.div d) * (b.num.div d)⟩
-- should fail fast; exact heartbeat count at time of writing is 31
set_option maxHeartbeats 310
/--
error: Tactic `decide` failed to reduce
@decide (((mul 4 1).mul 1).mul 1 = 4) (instDecidableEqFoo (((mul 4 1).mul 1).mul 1) 4)
to `true` or `false`.
After unfolding the instances `instDecidableEqFoo`, `instDecidableEqNat`, `Nat.decEq`, and `instDecidableEqFoo.decEq`, reduction got stuck at
(((mul 4 1).mul 1).mul 1).num.beq 4
-/
#guard_msgs in
example : ((Foo.mul 4 1).mul 1).mul 1 = 4 := by decide
/-! # Example 2 -/
@[irreducible] def add (a b : Foo) : Foo := ⟨a.num * b.num⟩
-- should not succeed (and fail fast); exact heartbeat count at time of writing is 21
/--
error: Tactic `decide` failed to reduce
@decide (((add 4 1).add 1).add 1 = 4) (instDecidableEqFoo (((add 4 1).add 1).add 1) 4)
to `true` or `false`.
After unfolding the instances `instDecidableEqFoo`, `instDecidableEqNat`, `Nat.decEq`, and `instDecidableEqFoo.decEq`, reduction got stuck at
(((add 4 1).add 1).add 1).num.beq 4
-/
#guard_msgs in
example : ((Foo.add 4 1).add 1).add 1 = 4 := by decide