Zulip Chat Archive

Stream: Is there code for X?

Topic: How to replace `a : Int` with `-a`?


Kim Morrison (Apr 07 2024 at 06:45):

What is the most ergonomic way to replace a hypothesis a : Int with its negation?

One can jump through hoops with:

have h := Int.neg_neg a
generalize -a = b at h
subst h

but that feels pretty tedious, and ends up with a different name.

I guess we could write an appropriate XXX so we could write cases a using XXX, but it seems a lot of work to prepare such lemmas for all invertible operations.

Yaël Dillies (Apr 07 2024 at 06:48):

obtain ⟨a, rfl⟩ : ∃ b, -b = a := ⟨-a, a.neg_neg⟩?

Kim Morrison (Apr 07 2024 at 06:48):

(needs a .neg_neg.symm, but yes!)

Yaël Dillies (Apr 07 2024 at 06:56):

Edited to avoid the .symm!

Eric Wieser (Apr 07 2024 at 13:27):

revert a; rw [neg_involutive.surjective.forall]; intro a?

Mitchell Lee (Apr 07 2024 at 16:05):

Another option (in case you still want more options)

rewrite [ Int.neg_neg a] at *
set a := -a

Mitchell Lee (Apr 07 2024 at 16:11):

Eric Wieser said:

revert a; rw [neg_involutive.surjective.forall]; intro a?

This would also require re-introducing any other hypotheses that involve a.

Eric Wieser (Apr 07 2024 at 19:36):

That's perhaps an argument for "rewrite by a surjective function" being a tactic


Last updated: May 02 2025 at 03:31 UTC