lean4-htt/tests/lean/run/conv1.lean
Joachim Breitner b181fd83ef
feat: in conv tactic, use try with_reducibe rfl (#3763)
The `conv` tactic tries to close “trivial” goals after itself. As of
now, it uses
`try rfl`, which means it can close goals that are only trivial after
reducing with
default transparency. This is suboptimal

* this can require a fair amount of unfolding, and possibly slow down
the proof
   a lot. And the user cannot even prevent it.
* it does not match what `rw` does, and a user might expect the two to
behave the
   same.

So this PR changes it to `with_reducible rfl`, matching `rw`’s behavior.

I considered `with_reducible eq_refl` to only solve trivial goals that
involve equality,
but not other relations (e.g. `Perm xs xs`), but a discussion on mathlib
pointed out
that it’s expected and desirable to solve more general reflexive goals:


https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Closing.20after.20.60rw.60.2C.20.60conv.60.3A.20.60eq_refl.60.20instead.20of.20.60rfl.60/near/429851605
2024-03-29 11:59:45 +00:00

106 lines
2 KiB
Text

set_option pp.analyze false
def p (x y : Nat) := x = y
example (x y : Nat) : p (x + y) (y + x + 0) := by
conv =>
whnf
congr
. rfl
. whnf; rfl
trace_state
rw [Nat.add_comm]
rfl
example (x y : Nat) : p (x + y) (y + x + 0) := by
conv =>
whnf
rhs
whnf
trace_state
rw [Nat.add_comm]
rfl
example (x y : Nat) : p (x + y) (y + x + 0) := by
conv =>
whnf
lhs
whnf
conv =>
rhs
whnf
trace_state
apply Nat.add_comm x y
example (x y : Nat) : p (x + y) (0 + y + x) := by
conv =>
whnf
rhs
rw [Nat.zero_add, Nat.add_comm]
trace_state
rfl
done
axiom div_self (x : Nat) : x ≠ 0 → x / x = 1
example (h : x ≠ 0) : x / x + x = x.succ := by
conv =>
lhs
arg 1
rw [div_self]
rfl
tactic => assumption
done
show 1 + x = x.succ
rw [Nat.succ_add, Nat.zero_add]
example (h1 : x ≠ 0) (h2 : y = x / x) : y = 1 := by
conv at h2 =>
rhs
rw [div_self]
rfl
tactic => assumption
assumption
example : id (fun x => 0 + x) = id := by
conv =>
lhs
arg 1
ext y
rw [Nat.zero_add]
rfl
def f (x : Nat) :=
if x > 0 then
x + 1
else
x + 2
example (g : Nat → Nat) (h₁ : g x = x + 1) (h₂ : x > 0) : g x = f x := by
conv =>
rhs
simp [f, h₂]
exact h₁
example (h₁ : f x = x + 1) (h₂ : x > 0) : f x = f x := by
conv =>
rhs
simp [f, h₂]
exact h₁
example (x y : Nat) (f : Nat → Nat → Nat) (g : Nat → Nat) (h₁ : ∀ z, f z z = z) (h₂ : ∀ x y, f (g x) (g y) = y) : f (g (0 + y)) (f (g x) (g (x + 0))) = x := by
conv in _ + 0 => apply Nat.add_zero
trace_state
conv in 0 + _ => apply Nat.zero_add
trace_state
simp [h₁, h₂]
example (x y : Nat) (f : Nat → Nat → Nat) (g : Nat → Nat)
(h₁ : ∀ z, f z z = z) (h₂ : ∀ x y, f (g x) (g y) = y)
(h₃ : f (g (0 + x)) (g x) = 0)
: g x = 0 := by
conv at h₃ in 0 + x => apply Nat.zero_add
trace_state
conv at h₃ => lhs; apply h₁
trace_state
assumption