Zulip Chat Archive

Stream: new members

Topic: sqrt{25} = 5 ?


RedPig (Oct 17 2024 at 20:39):

Trying some simple example on LEAN but somehow struggle to generalize the proof, in the below examples, the first example works but the second fails. The main reason is that norm_num is able to do 1=1\sqrt{1} = 1 but can not do 25=5\sqrt{25} = 5. How shall we do it then, I guess we need to prove 25=5\sqrt{25} = 5. Or do I miss something simple here?

import Mathlib

theorem evaluate_f1 (f :   ) (h₀ :  x, f x =  3 * Real.sqrt (2 * x - 7) - 8) : f 4 = -5 := by
 simp [h₀]
 norm_num
import Mathlib

theorem evaluate_f2 (f :   ) (h₀ :  x, f x =  3 * Real.sqrt (2 * x - 7) - 8) : f 16 = 7:= by
 simp [h₀]
 norm_num

Jireh Loreaux (Oct 17 2024 at 20:44):

I'm not saying it's ideal, but you can do this:

import Mathlib

theorem evaluate_f2 (f :   ) (h₀ :  x, f x =  3 * Real.sqrt (2 * x - 7) - 8) : f 16 = 7:= by
  simp [h₀]
  rw [show (2 : ) * 16 - 7 = 5 ^ 2 by norm_num, Real.sqrt_sq (by norm_num)]
  norm_num

Bjørn Kjos-Hanssen (Oct 17 2024 at 20:46):

Or this

import Mathlib

theorem evaluate_f2 (f :   ) (h₀ :  x, f x =  3 * Real.sqrt (2 * x - 7) - 8) : f 16 = 7:= by
 simp [h₀]
 norm_num
 have : (25)=5 := by
  refine Real.sqrt_eq_cases.mpr ?_
  norm_num
 rw [this]
 ring_nf

Ruben Van de Velde (Oct 17 2024 at 20:51):

Sounds like someone should write a norm_num extension

Jireh Loreaux (Oct 17 2024 at 20:53):

What should it do on √12? Nothing? Or should it return 2 * √3? (I don't see a way to make the latter efficient)

Jireh Loreaux (Oct 17 2024 at 20:54):

And what about OfScientific?

RedPig (Oct 17 2024 at 20:57):

Jireh Loreaux said:

What should it do on √12? Nothing? Or should it return 2 * √3?

will it be useful to leverage sympy to do it? sp.simplify can do it in python as 232\sqrt{3}

Ruben Van de Velde (Oct 17 2024 at 20:57):

Approximate to 3.46

Jireh Loreaux (Oct 17 2024 at 20:58):

?? But then it can't return a proof?

Ruben Van de Velde (Oct 17 2024 at 20:58):

More seriously, an extension that only covers perfect squares would be a useful first step

Jireh Loreaux (Oct 17 2024 at 20:59):

It should be relatively easy to adapt the existing extension for Nat.sqrt.

RedPig (Oct 17 2024 at 21:00):

Jireh Loreaux said:

?? But then it can't return a proof?

or use sympy to suggest the form and use LEAN to prove it? I don't think this is the way to go but just saying out my thought.

Jireh Loreaux (Oct 17 2024 at 21:01):

My comment was directed at Ruben's suggestion, not yours, sorry for the confusion.

Ruben Van de Velde (Oct 17 2024 at 21:01):

I think the overhead of calling out to sympy is probably not worth it, either in time or complexity

Ruben Van de Velde (Oct 17 2024 at 21:02):

Though it's an interesting idea

RedPig (Oct 17 2024 at 21:11):

another question: currently the proofs stuck at
3258=73 * √25 - 8 = 7
from a human perspective, we should be able to reformat it as
325=7+83 * √25 = 7 + 8
and then
325=153 * √25 = 15
and then
25=5√25 = 5

Is there function in LEAN can auto-transform in this way or it is all need to be manual?

Jireh Loreaux (Oct 17 2024 at 21:12):

How would Lean know that this is the form you want? (i.e., how would it know you wouldn't want 3 = 15 / √25, or any other variation?)

Kyle Miller (Oct 17 2024 at 21:27):

Somewhere in Zulip there is a simproc that can reduce squares to k * sqrt s with s square-free. It's not appropriate for normnum (other than for perfect squares) since normnum is for calculating a normal form that's integral or rational.

Kyle Miller (Oct 17 2024 at 21:27):

(I believe the simproc is just for Nat.sqrt)

Kyle Miller (Oct 17 2024 at 21:30):

Found it, and it was for Real.sqrt: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Should.20these.20surds.20be.20simplified.20with.20norm_num.3F/near/444362938

Kevin Buzzard (Oct 17 2024 at 22:54):

RedPig said:

another question: currently the proofs stuck at
3258=73 * √25 - 8 = 7
from a human perspective, we should be able to reformat it as
325=7+83 * √25 = 7 + 8
and then
325=153 * √25 = 15
and then
25=5√25 = 5

Is there function in LEAN can auto-transform in this way or it is all need to be manual?

import Mathlib.Tactic

example : 3 * 25 - 8 = 7 := by
  suffices 25 = 5 by polyrith
  rw [Real.sqrt_eq_cases]; norm_num

i.e. if you tell it the form you want, it's plain sailing.

Eric Wieser (Oct 17 2024 at 23:35):

(deleted)

Bjørn Kjos-Hanssen (Oct 18 2024 at 01:32):

polyrith doesn't seem to work in the Lean 4 playground, but linarith does the job too.

Kevin Buzzard (Oct 18 2024 at 07:39):

Huh, I thought it worked for me locally. Maybe polyrith doesn't work at all in the playground?

Kevin Buzzard (Oct 18 2024 at 08:35):

import Mathlib.Tactic

example : 3 * 25 - 8 = 7 := by
  suffices 25 = 5 by linear_combination 3 * this
  rw [Real.sqrt_eq_cases]; norm_num

works in the playground (i.e. replace polyrith with its output).

Eric Wieser (Oct 18 2024 at 08:46):

I don't think the playground is allowed network access


Last updated: May 02 2025 at 03:31 UTC