- add : R → R → R
- add_assoc : ∀ (a b c_1 : R), a + b + c_1 = a + (b + c_1)
- zero : R
- zero_add : ∀ (a : R), 0 + a = a
- add_zero : ∀ (a : R), a + 0 = a
- neg : R → R
- add_left_neg : ∀ (a : R), -a + a = 0
- add_comm : ∀ (a b : R), a + b = b + a
- mul : R → R → R
- mul_assoc : ∀ (a b c_1 : R), a * b * c_1 = a * (b * c_1)
- one : R
- one_mul : ∀ (a : R), 1 * a = a
- mul_one : ∀ (a : R), a * 1 = a
- left_distrib : ∀ (a b c_1 : R), a * (b + c_1) = a * b + a * c_1
- right_distrib : ∀ (a b c_1 : R), (a + b) * c_1 = a * c_1 + b * c_1
- mul_comm : ∀ (a b : R), a * b = b * a
- exists_pair_ne : ∃ (x y : R), x ≠ y
- quotient : R → R → R
- quotient_zero : ∀ (a : R), euclidean_domain.quotient a 0 = 0
- remainder : R → R → R
- quotient_mul_add_remainder_eq : ∀ (a b : R), b * euclidean_domain.quotient a b + euclidean_domain.remainder a b = a
- r : R → R → Prop
- r_well_founded : well_founded euclidean_domain.r
- remainder_lt : ∀ (a : R) {b : R}, b ≠ 0 → euclidean_domain.r (euclidean_domain.remainder a b) b
- mul_left_not_lt : ∀ (a : R) {b : R}, b ≠ 0 → ¬euclidean_domain.r (a * b) a
A euclidean_domain
is an integral_domain
with a division and a remainder, satisfying
b * (a / b) + a % b = a
. The definition of a euclidean domain usually includes a valuation
function R → ℕ
. This definition is slightly generalised to include a well founded relation
r
with the property that r (a % b) b
, instead of a valuation.
Equations
- euclidean_domain.has_div = {div := euclidean_domain.quotient _inst_1}
Equations
- euclidean_domain.has_mod = {mod := euclidean_domain.remainder _inst_1}
gcd a b
is a (non-unique) element such that gcd a b ∣ a
gcd a b ∣ b
, and for
any element c
such that c ∣ a
and c ∣ b
, then c ∣ gcd a b
Equations
- euclidean_domain.gcd a = λ (b : R), ite (a = 0) b (euclidean_domain.gcd (b % a) a)
An implementation of the extended GCD algorithm.
At each step we are computing a triple (r, s, t)
, where r
is the next value of the GCD
algorithm, to compute the greatest common divisor of the input (say x
and y
), and s
and t
are the coefficients in front of x
and y
to obtain r
(i.e. r = s * x + t * y
).
The function xgcd_aux
takes in two triples, and from these recursively computes the next triple:
xgcd_aux (r, s, t) (r', s', t') = xgcd_aux (r' % r, s' - (r' / r) * s, t' - (r' / r) * t) (r, s, t)
Use the extended GCD algorithm to generate the a
and b
values
satisfying gcd x y = x * a + y * b
.
Equations
- euclidean_domain.xgcd x y = (euclidean_domain.xgcd_aux x 1 0 y 0 1).snd
The extended GCD a
value in the equation gcd x y = x * a + y * b
.
Equations
- euclidean_domain.gcd_a x y = (euclidean_domain.xgcd x y).fst
The extended GCD b
value in the equation gcd x y = x * a + y * b
.
Equations
- euclidean_domain.gcd_b x y = (euclidean_domain.xgcd x y).snd
Equations
- euclidean_domain.integral_domain R = {add := has_add.add (distrib.to_has_add R), add_assoc := _, zero := 0, zero_add := _, add_zero := _, neg := euclidean_domain.neg e, add_left_neg := _, add_comm := _, mul := has_mul.mul (distrib.to_has_mul R), mul_assoc := _, one := euclidean_domain.one e, one_mul := _, mul_one := _, left_distrib := _, right_distrib := _, mul_comm := _, exists_pair_ne := _, eq_zero_or_eq_zero_of_mul_eq_zero := _}
lcm a b
is a (non-unique) element such that a ∣ lcm a b
b ∣ lcm a b
, and for
any element c
such that a ∣ c
and b ∣ c
, then lcm a b ∣ c
Equations
- euclidean_domain.lcm x y = x * y / euclidean_domain.gcd x y
Equations
- int.euclidean_domain = {add := has_add.add int.has_add, add_assoc := _, zero := 0, zero_add := _, add_zero := _, neg := has_neg.neg int.has_neg, add_left_neg := _, add_comm := _, mul := has_mul.mul int.has_mul, mul_assoc := _, one := 1, one_mul := _, mul_one := _, left_distrib := _, right_distrib := _, mul_comm := _, exists_pair_ne := _, quotient := has_div.div int.has_div, quotient_zero := int.div_zero, remainder := has_mod.mod int.has_mod, quotient_mul_add_remainder_eq := int.euclidean_domain._proof_1, r := λ (a b : ℤ), a.nat_abs < b.nat_abs, r_well_founded := int.euclidean_domain._proof_2, remainder_lt := int.euclidean_domain._proof_3, mul_left_not_lt := int.euclidean_domain._proof_4}
Equations
- field.to_euclidean_domain = {add := has_add.add (distrib.to_has_add K), add_assoc := _, zero := 0, zero_add := _, add_zero := _, neg := has_neg.neg (add_group.to_has_neg K), add_left_neg := _, add_comm := _, mul := has_mul.mul (distrib.to_has_mul K), mul_assoc := _, one := 1, one_mul := _, mul_one := _, left_distrib := _, right_distrib := _, mul_comm := _, exists_pair_ne := _, quotient := has_div.div division_ring_has_div, quotient_zero := _, remainder := λ (a b : K), a - a * b / b, quotient_mul_add_remainder_eq := _, r := λ (a b : K), a = 0 ∧ b ≠ 0, r_well_founded := _, remainder_lt := _, mul_left_not_lt := _}