lean4-htt/tests/lean/run/conv1.lean
Kim Morrison 3a457e6ad6
chore: use #guard_msgs in run tests (#4175)
Many of our tests in `tests/lean/run/` produce output from `#eval` (or
`#check`) statements, that is then ignored.

This PR tries to capture all the useful output using `#guard_msgs`. I've
only done a cursory check that the output is still sane --- there is a
chance that some "unchecked" tests have already accumulated regressions
and this just cements them!

In the other direction, I did identify two rotten tests:
* a minor one in `setStructInstNotation.lean`, where a comment says `Set
Nat`, but `#check` actually prints `?_`. Weird?
* `CompilerProbe.lean` is generating empty output, apparently indicating
that something is broken, but I don't know the signficance of this file.

In any case, I'll ask about these elsewhere.

(This started by noticing that a recent `grind` test file had an
untested `trace_state`, and then got carried away.)
2024-05-16 00:38:31 +00:00

161 lines
2.9 KiB
Text

set_option pp.analyze false
def p (x y : Nat) := x = y
/--
info: x y : Nat
⊢ x + y = y.add x
-/
#guard_msgs in
example (x y : Nat) : p (x + y) (y + x + 0) := by
conv =>
whnf
congr
. rfl
. whnf; rfl
trace_state
rw [Nat.add_comm]
rfl
/--
info: x y : Nat
⊢ x + y = y.add x
-/
#guard_msgs in
example (x y : Nat) : p (x + y) (y + x + 0) := by
conv =>
whnf
rhs
whnf
trace_state
rw [Nat.add_comm]
rfl
/--
info: x y : Nat
⊢ x.add y = y.add x
-/
#guard_msgs in
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
/--
info: x y : Nat
| x + y
-/
#guard_msgs in
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₁
/--
info: x y : Nat
f : Nat → Nat → Nat
g : Nat → Nat
h₁ : ∀ (z : Nat), f z z = z
h₂ : ∀ (x y : Nat), f (g x) (g y) = y
⊢ f (g (0 + y)) (f (g x) (g x)) = x
---
info: x y : Nat
f : Nat → Nat → Nat
g : Nat → Nat
h₁ : ∀ (z : Nat), f z z = z
h₂ : ∀ (x y : Nat), f (g x) (g y) = y
⊢ f (g y) (f (g x) (g x)) = x
-/
#guard_msgs in
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₂]
set_option linter.unusedVariables false
/--
info: x y : Nat
f : Nat → Nat → Nat
g : Nat → Nat
h₁ : ∀ (z : Nat), f z z = z
h₂ : ∀ (x y : Nat), f (g x) (g y) = y
h₃ : f (g x) (g x) = 0
⊢ g x = 0
---
info: x y : Nat
f : Nat → Nat → Nat
g : Nat → Nat
h₁ : ∀ (z : Nat), f z z = z
h₂ : ∀ (x y : Nat), f (g x) (g y) = y
h₃ : g x = 0
⊢ g x = 0
-/
#guard_msgs in
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