Zulip Chat Archive
Stream: lean4
Topic: Using noConfusion in apply
Leni Aniva (May 05 2024 at 17:59):
Consider
example : ∀ (n: Nat), 0 = n + 1 → False := λ _ h => Nat.noConfusion h
if I were to write this in tactic form
example : ∀ (n: Nat), 0 = n + 1 → False := by
intro n h
apply Nat.noConfusion
The apply
tactic fails since noConfusionType
cannot be unified with False
. Is there a way to invoke the Nat.noConfusion
theorem without explicitly writing down Nat.noConfusion h
like apply Nat.noConfusion h
?
Kyle Miller (May 05 2024 at 18:02):
I doubt it. refine Nat.noConfusion ?_
doesn't work either.
The noConfusion
mechanism really needs h
to see if it's type correct.
Kyle Miller (May 05 2024 at 18:06):
If you want to play around with this, here's a simplified version of Nat.noConfusion:
def Nat.noConfusionType'.{u} (P : Sort u) (a b : Nat) : Sort u :=
Nat.casesOn a
(zero := Nat.casesOn b (P → P) (fun _ => P))
(succ := fun _ => Nat.casesOn b P (fun _ => P → P))
def Nat.noConfusion'.{u} {P : Sort u} {a b : Nat} (h : a = b) : Nat.noConfusionType' P a b :=
Eq.recOn h (Nat.casesOn a (zero := id) (succ := fun _ => id))
example : ∀ (n : Nat), 0 = n + 1 → False := by
intro n h
exact Nat.noConfusion' h
Tom Kranz (May 05 2024 at 18:13):
If you really want to avoid passing the witness for 0 = n + 1
in the tactic application, you can just leave it in the goal and it'll fall into place:
example : ∀ (n: Nat), 0 = n + 1 → False := by
intro n
exact Nat.noConfusion
Although this is of course not exactly what you wrote in term form, it is just an η-reduction away from the original:
example : ∀ (n: Nat), 0 = n + 1 → False := λ _ => Nat.noConfusion
François G. Dorais (May 05 2024 at 20:00):
The contradiction
tactic will do it:
example : ∀ (n: Nat), 0 = n + 1 → False := by
intros; contradiction
Last updated: May 02 2025 at 03:31 UTC