Zulip Chat Archive

Stream: new members

Topic: The Mechanics Of Proof - induction


Michael Bucko (Nov 22 2024 at 10:16):

Paragraph 6 - induction. How can I make those proofs better?

2 proofs

Ilmārs Cīrulis (Nov 22 2024 at 12:07):

These theorems can be found in the Mathlib. But I assume you already know that. :sweat_smile:
The second looks good, the first I would write differently but your way is good too.

(I'm beginner too, just in case.)

import Mathlib
example (n : ) : Even n  Odd n := Nat.even_or_odd n
example {a b d : } (h : a  b [ZMOD d]) (n : ) : a ^ n  b ^ n [ZMOD d] := Int.ModEq.pow n h

Michael Bucko (Nov 22 2024 at 12:13):

Even if a proof from The Mechanics had already been done, it's okay. For me, it's more about learning by doing.

And since my proofs are still often quite ugly in Lean, many help me make them better.

Michael Bucko (Nov 22 2024 at 12:16):

Still, your point is a good one :thank_you: . Eventually, I'll try to reuse as much as possible from what had already been done.

Ilmārs Cīrulis (Nov 22 2024 at 12:17):

import Mathlib

example (n : ) : Even n  Odd n := by
  induction n with
  | zero => simp
  | succ n ih =>
    obtain w, hw | w, hw := ih <;> subst n
    . simp
    . have H: 2 * w + 1 + 1 = 2 * (w + 1) := by ring
      rw [H]
      simp

That's how I did it, but I used the fact that simp is quite powerful with all the Mathlib imported.

(Is it possible to merge lines have H: 2 * w + 1 + 1 = 2 * (w + 1) and rw [H] into one somehow?)

Ilmārs Cīrulis (Nov 22 2024 at 12:21):

(Smth like this - change 2 * w + 1 + 1 into 2 * ( w + 1) by ring. Something like this could be done in Coq, but I don't know about Lean...)

Michael Bucko (Nov 22 2024 at 12:23):

I need to experiment more with simp.

Yakov Pechersky (Nov 22 2024 at 12:27):

I think aiming to prove these lemmas in one go is counterproductive. It's often useful to prove other helpful side lemmas. I don't think Mechanics of Proof is against that

Yakov Pechersky (Nov 22 2024 at 12:31):

So in your Even n or Odd n, a more powerful statement is Even n => Odd (n + 1), then upgraded to an iff; and Even n => not Even (n + 1), then upgraded to an iff. Then linking Even n => not Odd n, then upgrading to an iff. Then using that with (em _).imp_right, which is shorthand for splitting on the cases using docs#Or.imp_right


Last updated: May 02 2025 at 03:31 UTC