Zulip Chat Archive
Stream: new members
Topic: Problem with add_pow
Andrew Wheen (Jun 22 2023 at 10:58):
I'm having trouble getting add_pow (binomial theorem) to run properly. For example:
import data.nat.basic
import data.real.basic
import data.nat.choose.sum -- Binomial Theorem
variables (x y : ℝ)
variables (z : ℕ)
def x : ℝ := 2.0
def y : ℝ := 3.0
def z : ℕ := 4
#eval add_pow x y z
produces the message "cannot evaluate function: 0 arguments given but expected 3". When I tried:
#eval add_pow 2.0 3.0 4
it returned an answer of #0 with "result type does not have an instance of type class 'has_repr', dumping internal representation". Any suggestions?
Reid Barton (Jun 22 2023 at 11:01):
add_pow
is a theorem that says that two real numbers (in this case) are equal.
What are you expecting to happen when you "run" it?
Reid Barton (Jun 22 2023 at 11:02):
Maybe #check add_pow 2.0 3.0 4
is more like what you want?
Eric Wieser (Jun 22 2023 at 11:02):
(Please also take a look at #backticks)
Ruben Van de Velde (Jun 22 2023 at 11:04):
I don't think #eval
is going to do much for you, especially with real numbers
Andrew Wheen (Jun 22 2023 at 11:18):
My expectation was that '''#eval 2 3 4''' would return a result of 625 (ie (2 + 3)^4). The definition of add_pow says that it is an implementation of the binomial theorem. I've tried making x and y into natural numbers but the result is the same.
Thanks for the guidance on backticks.
Reid Barton (Jun 22 2023 at 11:23):
#eval (2 + 3)^4
should print 625.
Andrew Wheen (Jun 22 2023 at 11:29):
Yes, '''#eval (2 + 3)^4''' does print 625, but for some reason '''#eval add_pow 2 3 4''' prints #0.
Reid Barton (Jun 22 2023 at 11:31):
Right, it doesn't really make sense to #eval
a theorem.
Kevin Buzzard (Jun 22 2023 at 11:33):
More precisely, add_pow 2 3 4
is the proof of a theorem.
Kevin Buzzard (Jun 22 2023 at 11:33):
(in this case it's a proof that 625=625)
Mauricio Collares (Jun 22 2023 at 11:37):
And all that lean stores about proofs at runtime is "Yep, that was a proof indeed" (which is printed as #0
)
Andrew Wheen (Jun 22 2023 at 11:44):
OK. So why does #eval nat.choose 5 3
return a result of 10 (as I expected)?
Kevin Buzzard (Jun 22 2023 at 11:45):
Because nat.choose
is a function, and nat.choose 5 3
is a number.
Matthew Ballard (Jun 22 2023 at 11:45):
It’s a def
.
Matthew Ballard (Jun 22 2023 at 11:46):
def
’s can store data that your computer can compute on.
Andrew Wheen (Jun 22 2023 at 11:47):
Is the binomial theorem available as a function?
Kevin Buzzard (Jun 22 2023 at 11:47):
What does that question even mean? The binomial theorem is a theorem statement or a theorem proof, depending on what precisely you mean. It is not a number or a function.
Kevin Buzzard (Jun 22 2023 at 11:48):
I guess strictly speaking add_pow
is a function which eats three numbers and then returns a proof, so it is a function in that sense.
Matthew Ballard (Jun 22 2023 at 11:48):
theorem
s carry no such data. As Mauricio, they are evidence to the Lean kernel that a theorem statement is ok
Kevin Buzzard (Jun 22 2023 at 11:48):
But nat.choose
is a function which eats two numbers and returns a number.
Reid Barton (Jun 22 2023 at 11:50):
Can you rephrase your question without the phrase "binomial theorem"?
Andrew Wheen (Jun 22 2023 at 11:57):
OK. Perhaps I've asked the wrong question. In simple terms, I want to prove that (a + b)^n > a^n + b^n
if n > 1
, and the simplest way to do this seemed to be to use a binomial expansion and show that the total is greater than the first and last terms. Is there a better way of doing this in Lean3 ?
Kevin Buzzard (Jun 22 2023 at 11:59):
Sure you can do that, that will work just fine (as long as a,b>0). But what does that have to do with #eval
?
Reid Barton (Jun 22 2023 at 12:09):
Try #check
as suggested above.
Andrew Wheen (Jun 22 2023 at 12:13):
I used #eval
because I hadn't spotted the distinction between add_pow
returning a proof while choose
returns a number . I therefore assumed that add_pow wasn't working properly when I started getting strange error messages, and my first response in these circumstances is typically to try #eval
and #check
.
Many thanks to everyone who replied. I think I can now see a way forward.
Last updated: Dec 20 2023 at 11:08 UTC