Zulip Chat Archive

Stream: new members

Topic: bezout


Brian Jiang (Apr 27 2020 at 02:31):

one of the theorems I am trying to prove uses this version of bezouts defined over the integers

'''
theorem relatively_prime_sum_to_one (a b : ℤ) (h : relatively_prime a b) :
∃ m n: ℤ, m* a + n * b = 1 := sorry
'''
Does lean already have a way to show the existence of m and n? Could I end up exacting something to get rid of the sorry?

Bryan Gin-ge Chen (Apr 27 2020 at 02:46):

You can probably use nat.gcd_eq_gcd_ab from data.int.gcd. If you paste more of your code (esp. the definition of relatively_prime) we can give more details.

By the way, to get proper syntax highlighting, use three backticks: ```, not single quotes.

Brian Jiang (Apr 28 2020 at 01:15):

here is the definition of relatively_prime:

def relatively_prime(a b:) := l:, ¬(divides l a)  ¬(divides l b)

Mario Carneiro (Apr 28 2020 at 01:16):

That's false

Mario Carneiro (Apr 28 2020 at 01:17):

1 always divides both a and b

Mario Carneiro (Apr 28 2020 at 01:17):

Maybe use nat.coprime instead?

Mario Carneiro (Apr 28 2020 at 01:18):

I'm not sure if there is an int.coprime but you could use nat.coprime (int.nat_abs a) (int.nat_abs b)

Brian Jiang (Apr 28 2020 at 01:18):

ah right, thanks

Brian Jiang (Apr 28 2020 at 01:18):

any suggestions on how to fill in the first theorem?

Mario Carneiro (Apr 28 2020 at 01:19):

Bryan already gave the suggestion

Brian Jiang (Apr 28 2020 at 01:20):

exact nat.gcd_eq_gcd_ab ?

Brian Jiang (Apr 28 2020 at 01:20):

apologies my grasp of the syntax isn't too good

Mario Carneiro (Apr 28 2020 at 01:20):

You will probably have to do some modifications depending on the exact statement of the theorem

Mario Carneiro (Apr 28 2020 at 01:23):

There is another version, euclidean_domain.gcd_eq_gcd_ab, that works over any euclidean domain. Since int is a euclidean domain this should give you something closer to what you want

Mario Carneiro (Apr 28 2020 at 01:23):

you have to import algebra.euclidean_domain

Brian Jiang (Apr 28 2020 at 01:25):

so when I define relatively_prime as def relatively_prime(a b:ℤ) := nat.coprime (int.nat_abs a) (int.nat_abs b)
and my theorem as theorem relatively_prime_sum_to_one (a b : ℤ) (h : relatively_prime a b) : ∃ m n: ℤ, m* a + n * b = 1 :=

Brian Jiang (Apr 28 2020 at 01:26):

how should I use euclidean_domain.gcd_eq_gcd_ab?

Brian Jiang (Apr 28 2020 at 01:27):

I tried exact euclidean_domain.gcd_eq_gcd_ab but that did not work

Mario Carneiro (Apr 28 2020 at 01:31):

Here's the start:

import algebra.euclidean_domain

def relatively_prime(a b:) :=  nat.coprime (int.nat_abs a) (int.nat_abs b)
open euclidean_domain
theorem relatively_prime_sum_to_one (a b : ) (h : relatively_prime a b) :
   m n : , m * a + n * b = 1 :=
begin
  existsi [gcd_a a b, gcd_b a b],
  rw [mul_comm _ a, mul_comm _ b,  gcd_eq_gcd_ab],

end

but I see now that there is a hole in the library: euclidean_domain.gcd on int is not proven equal to int.gcd

Mario Carneiro (Apr 28 2020 at 01:47):

What's more, it seems that euclidean_domain.gcd is not easily relatable to int.gcd because of a +- 1 difference. It seems that the proof using the nat version is easiest

import data.int.gcd

def relatively_prime(a b:) :=  nat.coprime (int.nat_abs a) (int.nat_abs b)
theorem relatively_prime_sum_to_one (a b : ) (h : relatively_prime a b) :
   m n : , m * a + n * b = 1 :=
begin
  existsi [int.sign a * nat.gcd_a (int.nat_abs a) (int.nat_abs b),
           int.sign b * nat.gcd_b (int.nat_abs a) (int.nat_abs b)],
  rw [mul_right_comm, mul_comm _ a, int.mul_sign,
      mul_right_comm, mul_comm _ b, int.mul_sign,
       nat.gcd_eq_gcd_ab,
      show nat.gcd (int.nat_abs a) (int.nat_abs b) = 1, from h,
      int.coe_nat_one],
end

Mario Carneiro (Apr 28 2020 at 01:49):

@Brian Jiang Sorry for this, but it seems you might have picked an example that is not appropriate for your level. You should try working through theorem proving in lean to get the hang of the syntax

Reid Barton (Apr 28 2020 at 01:51):

If this isn't easy, it's definitely a hole in the library

Bryan Gin-ge Chen (Apr 28 2020 at 01:52):

What's the +-1 issue?

Mario Carneiro (Apr 28 2020 at 01:52):

This theorem itself is also a hole in the library, indeed

Mario Carneiro (Apr 28 2020 at 01:53):

It's easy enough to define gcd_a, gcd_b and gcd_eq_gcd_ab for integers using the parts of this proof

Mario Carneiro (Apr 28 2020 at 01:54):

It is true that int.nat_abs (gcd a b) = int.gcd a b but not gcd a b = \u (int.gcd a b)

Mario Carneiro (Apr 28 2020 at 01:54):

because gcd 0 b = b and int.gcd 0 b = int.nat_abs b

Mario Carneiro (Apr 28 2020 at 01:56):

I think we need a variation on gcd_eq_gcd_ab for euclidean domains where the lhs is any multiple of the gcd

Mario Carneiro (Apr 28 2020 at 01:57):

(in particular 1)

Brian Jiang (Apr 28 2020 at 02:04):

alright, thanks!

Patrick Massot (Apr 28 2020 at 08:13):

Mario Carneiro said:

but I see now that there is a hole in the library: euclidean_domain.gcd on int is not proven equal to int.gcd

This is a very well known hole. And each time we discuss it we end up noticing that sign issue, and the discussion stops.

Mario Carneiro (Apr 28 2020 at 08:28):

int.nat_abs (gcd a b) = int.gcd a b should be there regardless

Mario Carneiro (Apr 28 2020 at 08:30):

Isn't there something about normalization domains that should ensure that gcd a b is always the "canonical" element of the unit class, which in this case would mean that it's always nonnegative?

Mario Carneiro (Apr 28 2020 at 08:30):

Otherwise this function looks pretty scatterbrained


Last updated: Dec 20 2023 at 11:08 UTC