Zulip Chat Archive

Stream: new members

Topic: proving algebraic facts


zera (Jan 06 2024 at 01:49):

Hi,
I'm new to Lean and I'm trying to find what's the best way to have something like the following step by step proof proven in a more natural written way.
For example, In English I would write:
a - b = 0
and next I can derive the following assume a,b \in \R
a + c = b + c

but right now I need to do
calc
a + c = a - (a - b) + c := by rw [h];ring
= b + c := by ring
which is a bit unnatural to me

I guess I'm asking if there is something similar to ring but proving on P \iff Q instead of equality using the ring property. Apology if the question may be unclear!

Kevin Buzzard (Jan 06 2024 at 01:51):

There will be lemmas in the library saying ab=0    a=ba-b=0\iff a=b and a=b    a+c=b+ca=b\iff a+c=b+c and you can rw those.

Kevin Buzzard (Jan 06 2024 at 01:52):

Alternatively if you have a hypothesis ab=0a-b=0 and want to prove a+c=b+ca+c=b+c you can use the polyrith tactic. I would encourage you to ask your question by posting code though, for example right now we don't even know the types of aa and bb (Lean has many 37s, the natural 37 and the integer 37 and the real 37 are all different objects in Lean and the difference matters).

zera (Jan 06 2024 at 02:16):

Thanks! Here is the code example

example (a b: ) (h: a-b=0) : a+c=b+c:= by{
  calc
  a+c = (a-b)+b+c := by ring
  _ = b+c := by rw [h]; ring
}

The reason I asked is that I feel this is kind of unnatural to me that I need to explicitly rewrite a with (a -b) +b myself in order to prove this with ring tactic. Wonder if there is tactic that can implicit infer this kind of things.

(Haven't looked at polyrith in detailed, but might be the thing I'm looking for)

Notification Bot (Jan 06 2024 at 04:57):

4 messages were moved here from #new members > basic question by Heather Macbeth.

Kevin Buzzard (Jan 06 2024 at 09:09):

I would look at polyrith. Your code doesn't compile by the way -- read #mwe to learn about the best way to ask questions.


Last updated: May 02 2025 at 03:31 UTC