Zulip Chat Archive

Stream: new members

Topic: More elegant way?


Walter Moreira (Jun 04 2020 at 15:47):

What could be a more elegant way to solve this? It looks like too many steps:

import data.real.basic

example : 1 = ((1 + real.sqrt 5) / 2 - (1 - real.sqrt 5) / 2) / real.sqrt 5 :=
begin
ring,
refine (inv_mul_cancel _).symm,
intro,
linarith [(real.sqrt_eq_zero (by linarith)).mp a],
end

Jalex Stark (Jun 04 2020 at 15:49):

you're missing import tactic to make this a #mwe

Jalex Stark (Jun 04 2020 at 15:50):

import data.real.basic
import tactic

example : 1 = ((1 + real.sqrt 5) / 2 - (1 - real.sqrt 5) / 2) / real.sqrt 5 :=
begin
  ring,
  refine (inv_mul_cancel _).symm, norm_num,
end

Jalex Stark (Jun 04 2020 at 15:50):

norm_num is the first thing i hit up when i want to prove something is not 0

Walter Moreira (Jun 04 2020 at 15:50):

Oh so sorry! How does it work for me?

Jalex Stark (Jun 04 2020 at 15:51):

uh, I assume you're running this codeblock inside of a file that already imported tactic?

Jalex Stark (Jun 04 2020 at 15:51):

oh, nevermind, I just had one of those "lean spits out a temporary error before it finishes compiling". I guess data.real.basic imports tactic?

Johan Commelin (Jun 04 2020 at 15:52):

Yup, certainly

Walter Moreira (Jun 04 2020 at 15:52):

No, it's just it's own file [Screen-Shot-2020-06-04-at-10.51.51-AM.png]
(https://leanprover.zulipchat.com/user_uploads/3121/gsrQOXPpBtrhTLj9BVx3OMdt/Screen-Shot-2020-06-04-at-10.51.51-AM.png)

Walter Moreira (Jun 04 2020 at 15:53):

@Jalex Stark Ah cool. Thanks for the norm_num hint.

Jalex Stark (Jun 04 2020 at 15:53):

it's working for me now, too. the problem was on my end.

Jalex Stark (Jun 04 2020 at 15:54):

you can just use rw instead of refine

import data.real.basic

example : 1 = ((1 + real.sqrt 5) / 2 - (1 - real.sqrt 5) / 2) / real.sqrt 5 :=
begin
  ring, rw inv_mul_cancel, norm_num,
end

Jalex Stark (Jun 04 2020 at 15:54):

rw is usually how iff statements are meant to be used

Walter Moreira (Jun 04 2020 at 15:55):

Very nice!

Patrick Massot (Jun 04 2020 at 15:56):

I see norm_num still has a lot to improve...

Jalex Stark (Jun 04 2020 at 15:58):

? do you want norm_num to be able to do everything ring can?

Patrick Massot (Jun 04 2020 at 16:00):

norm_num should close this goal without any help.

Johan Commelin (Jun 04 2020 at 16:51):

We can improve norm_num be writing the right simp lemmas

Johan Commelin (Jun 04 2020 at 16:52):

This might be related to Yury's recent question of making the field_simp simpset a subset of the normal simpset.

Jalex Stark (Jun 04 2020 at 16:52):

at some point it needs to know that it's supposed to prove a denominator is not equal to 0

Jalex Stark (Jun 04 2020 at 16:53):

field_simp doesn't do any denominator-clearing unless you pass it a proof that something is not 0

Jalex Stark (Jun 04 2020 at 16:54):

I think simp only [inv_mul_cancel]doesn't do anything here

Johan Commelin (Jun 04 2020 at 16:54):

That's true. Still... since there are no variables here, I think that in principle norm_num ought to be able to tackle this alone.

Patrick Massot (Jun 04 2020 at 16:54):

Yes, my point is that there is no variable.

Jalex Stark (Jun 04 2020 at 16:56):

I guess the first target is

example : (1:) = 2/2 := by norm_num

Jalex Stark (Jun 04 2020 at 16:58):

oh, norm_num does handle that, I should have tried it first...

Jalex Stark (Jun 04 2020 at 16:59):

but not

example : (1:) = (real.sqrt 5)/(real.sqrt 5):= sorry

Jalex Stark (Jun 04 2020 at 17:00):

should I raise an issue?

Patrick Massot (Jun 04 2020 at 17:06):

We can ask @Mario Carneiro first.

Mario Carneiro (Jun 04 2020 at 19:33):

What do you think norm_num is? It can't just evaluate arbitrary real number expressions. (That's undecidable, remember?)

Johan Commelin (Jun 04 2020 at 19:33):

But this one isn't arbitrary!

Johan Commelin (Jun 04 2020 at 19:34):

More seriously... can we add some special tags or lemmas that will teach norm_num to evaluate this

Mario Carneiro (Jun 04 2020 at 19:34):

Even though norm_num nominally works on real number expressions, that's only if they in fact describe rationals

Alex J. Best (Jun 04 2020 at 19:34):

Algebraic numbers are decidable right? (I actually don't know but they feel decidable!)

Johan Commelin (Jun 04 2020 at 19:34):

Galois theory says yes

Mario Carneiro (Jun 04 2020 at 19:34):

Algebraic numbers are decidable, yes. The algorithm is very complicated and I've never done it although I've looked at the proof

Johan Commelin (Jun 04 2020 at 19:34):

I guess you don't actually need galois theory for that

Mario Carneiro (Jun 04 2020 at 19:34):

something to do with permanents

Alex J. Best (Jun 04 2020 at 19:35):

You probably need some float approximation too?

Mario Carneiro (Jun 04 2020 at 19:35):

no

Johan Commelin (Jun 04 2020 at 19:35):

That might give a speed up, maybe?

Alex J. Best (Jun 04 2020 at 19:36):

Hmm interesting, I figured the operations would all be with the minimal polynomials, but then you need some approximation to distinguish roots occasionally

Mario Carneiro (Jun 04 2020 at 19:36):

Evaluating algebraic numbers is a component in CAD

Alex J. Best (Jun 04 2020 at 19:36):

http://fredrikj.net/calcium/index.html

Mario Carneiro (Jun 04 2020 at 19:36):

and that needs some approximation too

Mario Carneiro (Jun 04 2020 at 19:36):

You can express approximation problems as alg_1 < alg_2

Alex J. Best (Jun 04 2020 at 19:37):

His qqbar implementation uses some root finding, which is what put the idea in my head, its cool that its not needed!

Mario Carneiro (Jun 04 2020 at 19:39):

There are multiple ways to express algebraic numbers. A minimal polynomial is not enough because polynomials have several roots. You can number and order them but this still basically requires you to locate all the roots. One popular method is to put a box around the root you want that excludes all the others

Mario Carneiro (Jun 04 2020 at 19:40):

another trick (for real algebraics) is to use the sequence of signs of all the derivatives of the minimal polynomial at the target number. Perhaps surprisingly this determines which root uniquely

Johan Commelin (Jun 04 2020 at 19:41):

But square roots are easier, right

Johan Commelin (Jun 04 2020 at 19:41):

Human beings have no problem calculating with roots and powers

Mario Carneiro (Jun 04 2020 at 19:41):

They are acting more like simp though

Johan Commelin (Jun 04 2020 at 19:42):

So maybe quadratic_closure rat is tractible?

Mario Carneiro (Jun 04 2020 at 19:42):

I don't think this is an appropriate goal for norm_num

Johan Commelin (Jun 04 2020 at 19:42):

Yup... so we need some simp lemmas

Mario Carneiro (Jun 04 2020 at 19:44):

I know people love their kitchen sink tactics, but I really think I should take a stand and say that this is out of scope for norm_num. norm_num assumes that all evaluable expressions have a normal form that is a rational numeral. Here that is not the case

Mario Carneiro (Jun 04 2020 at 19:45):

It is really best if the tactic knows in advance what the normal form is. Currently we are using separate tactics for separate normal forms for separate decision procedures, e.g. ring vs abel vs norm_num

Johan Commelin (Jun 04 2020 at 19:49):

Ok, that's fine. Then we just need a new tactic.

Kevin Buzzard (Jun 04 2020 at 21:37):

How does field_simp fare?

Mario Carneiro (Jun 04 2020 at 21:39):

It should be possible to prove this with ring++

Mario Carneiro (Jun 04 2020 at 21:41):

field_simp should work if you pass it a sqrt positivity lemma and use norm_num as discharger

Walter Moreira (Jun 06 2020 at 21:09):

As a continuation of this question, I'm able to prove in one line that phi^2 - phi - 1 = 0, and deduce from there that phi^2 = phi + 1.

But when I try to prove directly that phi^2 = phi + 1 (last example) I cannot find a simple chain of rws to prove it. Am I missing some more powerful technique for this?

import data.real.basic

noncomputable theory

def phi :  := ((1 + real.sqrt 5) / 2)

lemma phi_sol : phi^2 - phi - 1 = 0 :=
begin
unfold phi, ring, rw real.sqr_sqrt; norm_num,
end

example : phi^2 = phi + 1 :=
begin
rw [sub_eq_zero, sub_add_eq_sub_sub, phi_sol],
end

example : phi^2 = phi + 1 :=
begin
unfold phi,
sorry
end

Patrick Massot (Jun 06 2020 at 21:18):

I think this is again a trivial case of the missing Grobner basis tactic.

Patrick Massot (Jun 06 2020 at 21:18):

Here you can apply eq_of_sub_eq_zero then rw and ring


Last updated: Dec 20 2023 at 11:08 UTC