Zulip Chat Archive

Stream: new members

Topic: Injectivity of subtraction in Nat?


Luiz Kazuo Takei (Oct 02 2025 at 18:22):

Is there a lemma in Nat that states the result below?

h1 : b \le a
h2 : c \le a
h3 : a - b = a - c

then

b = c

Aaron Liu (Oct 02 2025 at 18:34):

@loogle (?a - _ : Nat) = ?a - _

loogle (Oct 02 2025 at 18:34):

:search: Nat.sub_eq_sub_min, Array.extract_eq_extract_left, and 2 more

Aaron Liu (Oct 02 2025 at 18:35):

I thought there would be something

Aaron Liu (Oct 02 2025 at 18:36):

Maybe you can compose two lemmas

Aaron Liu (Oct 02 2025 at 18:37):

@loogle "sub_eq", "iff"

loogle (Oct 02 2025 at 18:37):

:search: Nat.sub_eq_iff_eq_add, Nat.sub_eq_iff_eq_add', and 57 more

Aaron Liu (Oct 02 2025 at 18:38):

@loogle Nat, _ - _ + _, _+ _ - _, LE.le

loogle (Oct 02 2025 at 18:38):

:search: Nat.sub_add_comm, Vector.insertIdx_eraseIdx_of_ge, and 3 more

Aaron Liu (Oct 02 2025 at 18:39):

Yes you can use docs#Nat.sub_eq_iff_eq_add with docs#Nat.sub_add_comm to get rid of the subtraction

Aaron Liu (Oct 02 2025 at 18:39):

or I guess you could cast to int

Damiano Testa (Oct 02 2025 at 18:40):

Would docs#tsub_inj_left work?

Aaron Liu (Oct 02 2025 at 18:44):

we want the other side inj

Aaron Liu (Oct 02 2025 at 18:45):

the right inj

Matt Diamond (Oct 02 2025 at 18:49):

what about... docs#tsub_inj_right

Matt Diamond (Oct 02 2025 at 18:50):

I think that's it

Damiano Testa (Oct 02 2025 at 18:52):

Ah, yes, the variable that's not repeated is the one that gets reflected in the name!

Luiz Kazuo Takei (Oct 02 2025 at 18:52):

Yes! docs#tsub_inj_right is the good one.

Thanks a lot!

Jireh Loreaux (Oct 02 2025 at 18:54):

It's not a lemma, but just noting that grind solves this.

Luiz Kazuo Takei (Oct 02 2025 at 19:10):

I noticed that omega also works:

example (a b c : ) (h1 : a  c) (h2 : b  c) (h3 : c - a = c - b) : a = b := by omega

Jireh Loreaux (Oct 02 2025 at 19:52):

probably grind should be preferred over omega. If you ever find an instance where the latter succeeds, but the former doesn't, I'm sure Kim Morrison will want to know.


Last updated: Dec 20 2025 at 21:32 UTC