Zulip Chat Archive
Stream: new members
Topic: Learning the basics of Lean
Riley Riles (Feb 20 2025 at 01:46):
Hi! I'm new to Lean and am trying to learn the basics. I'm currently trying to prove that 2*n^2 = m^2 where n, m are integers is a contradiction. As an informal proof I would use induction, but I don't see a way to use the induction tactic here. Any suggestions for how to approach this?
Yakov Pechersky (Feb 20 2025 at 01:54):
First thing would be to try to even write the statement of the problem. Do you have an example of how you'd formalize the statement?
Aaron Liu (Feb 20 2025 at 02:00):
First you have to get an idea of what you mean by induction. There are two indices, so there are lots of ways to do induction. You can do strong, two-step, or cauchy induction on the first, second, or both indices at once. What kind of induction do you want?
Julian Berman (Feb 20 2025 at 02:14):
First you have to choose which of the two first things you want to do first!
Riley Riles (Feb 20 2025 at 03:40):
\forall n m : Int, \not (2*n^2 = m^2)
``` is how I formalized it. The issue is that just doing induction on n or m would induct on the successor function, which is not particularly helpful here. What I want to do is induct on the degree of powers of two that divide n or m, but I can't figure out a way to do this without having an inductive constructor that depends on prime factorization, which would be a nightmare to implement.
Notification Bot (Feb 20 2025 at 03:42):
This topic was moved here from #maths > Learning the basics of Lean by Frédéric Dupuis.
Chris Wong (Feb 20 2025 at 04:26):
docs#Nat.binaryRec might be helpful.
Chris Wong (Feb 20 2025 at 04:31):
That induction principle works by repeatedly halving the argument.
Bolton Bailey (Feb 20 2025 at 04:32):
\forall n m : Int, \not (2*n^2 = m^2)
You might have some trouble trying to formalize this version: What happens if both m and n are zero?
Yakov Pechersky (Feb 20 2025 at 04:33):
Okay but it's not true as stated. n = 0, m = 0 is a solution. So you could reduce your (corrected) statement to one over the positive naturals. Then using your assumption, you could show that m > n, then express m as n + k + 1, removing one free variable.
That being said, we also have docs#Nat.recOnPrimePow or you can use the binaryRec, or argue from a parity point of view
suhr (Feb 20 2025 at 08:01):
Here's a generalized statement of your exercise with some lemmas that could be used to prove it:
import Mathlib
#check padicValNat
#check padicValNat.mul
#check padicValNat.prime_pow
#check Nat.prime_def
theorem sq_ne_prime_sq {n k p: Nat}[pp: Fact p.Prime](pn: 0 < n)(pk: 0 < k)
(h: n*n = p*(k*k)): False :=
sorry
You don't need induction to prove this.
Kevin Buzzard (Feb 20 2025 at 08:07):
You don't need induction if you use p-adic valuations but in some sense they're defined using induction. In some sense you can't prove anything about the naturals beyond statements like 2+2=4 without induction
suhr (Feb 20 2025 at 08:12):
True, but that particular proof does not require explicit induction. It is also a rather nice proof, p-adic valuation makes things more elegant.
Kevin Buzzard (Feb 20 2025 at 09:01):
I agree that p-adic valuations make the proof look very elegant. All I'm saying is that they are hiding a huge amount of stuff behind the API. For example (necessary for the even/odd part of the argument in the contradiction) is assuming uniqueness of prime factorization which is far deeper than irrationality of sqrt(2).
suhr (Feb 20 2025 at 09:32):
I think one could prove this using just the Euclid's lemma, which in turn only requires the Bezout's identity. So it does not have to be this big under the API. I agree that it's a boring corollary of much cooler results though.
Kevin Buzzard (Feb 20 2025 at 10:28):
Yes, it only requires all the key ingredients for uniqueness of prime factorization.
Riley Riles (Feb 20 2025 at 19:23):
Wow, I didn't know p-adic valuations were in Lean! Thanks so much, I'll use this :)
Last updated: May 02 2025 at 03:31 UTC