Built with
doc-gen4 , running Lean4.
Bubbles (
) indicate interactive fragments: hover for details, tap to reveal contents.
Use
Ctrl+↑ Ctrl+↓ to navigate,
Ctrl+🖱️ to focus.
On Mac, use
Cmd instead of
Ctrl .
/-
Copyright (c) 2018 Louis Carlin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Louis Carlin, Mario Carneiro
! This file was ported from Lean 3 source module algebra.euclidean_domain.instances
! leanprover-community/mathlib commit e1bccd6e40ae78370f01659715d3c948716e3b7e
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Algebra.EuclideanDomain.Defs
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Lemmas
import Mathlib.Init.Data.Int.Order
import Mathlib.Data.Int.Basic
import Mathlib.Data.Nat.Order.Basic
import Mathlib.Data.Int.Order.Basic
/-!
# Instances for Euclidean domains
* `Int.euclideanDomain`: shows that `ℤ` is a Euclidean domain.
* `Field.toEuclideanDomain`: shows that any field is a Euclidean domain.
-/
instance Int.euclideanDomain : EuclideanDomain ℤ :=
{ inferInstanceAs : (α : Sort ?u.6) → [i : α ] → α inferInstanceAs ( CommRing Int ), inferInstanceAs : ∀ (α : Sort ?u.18) [i : α ], α inferInstanceAs ( Nontrivial Int ) with
add := (· + ·) , mul := (· * ·) , one := 1 , zero := 0 ,
neg := Neg.neg : {α : Type ?u.495} → [self : Neg α ] → α → α Neg.neg,
quotient := (· / ·) , quotient_zero := Int.ediv_zero : ∀ (a : ℤ ), a / 0 = 0 Int.ediv_zero, remainder := (· % ·) ,
quotient_mul_add_remainder_eq := Int.ediv_add_emod : ∀ (a b : ℤ ), b * (a / b ) + a % b = a Int.ediv_add_emod,
r := fun a b => a . natAbs < b . natAbs ,
r_wellFounded := ( measure natAbs ). wf
remainder_lt := fun a b b0 => Int.ofNat_lt : ∀ {n m : ℕ }, ↑n < ↑m ↔ n < m Int.ofNat_lt. 1 : ∀ {a b : Prop }, (a ↔ b ) → a → b 1 <| by
rw [ Int.natAbs_of_nonneg : ∀ {a : ℤ }, 0 ≤ a → ↑(natAbs a ) = a Int.natAbs_of_nonneg ( Int.emod_nonneg : ∀ (a : ℤ ) {b : ℤ }, b ≠ 0 → 0 ≤ a % b Int.emod_nonneg _ b0 ), ← Int.abs_eq_natAbs ]
exact Int.emod_lt : ∀ (a : ℤ ) {b : ℤ }, b ≠ 0 → a % b < abs b Int.emod_lt _ b0
mul_left_not_lt := fun a b b0 =>
not_lt_of_ge <| by
rw [ ← mul_one a . natAbs , Int.natAbs_mul ]
rw [ ← Int.natAbs_pos ] at b0
exact Nat.mul_le_mul_of_nonneg_left : ∀ {a b c : ℕ }, a ≤ b → c * a ≤ c * b Nat.mul_le_mul_of_nonneg_left b0 }
-- Porting note: this seems very slow.
-- see Note [lower instance priority]
instance ( priority := 100) Field.toEuclideanDomain { K : Type _ } [ Field K ] : EuclideanDomain : Type ?u.2454 → Type ?u.2454 EuclideanDomain K :=
{ ‹Field K› with
add := (· + ·) , mul := (· * ·) , one := 1 , zero := 0 , neg := Neg.neg : {α : Type ?u.3336} → [self : Neg α ] → α → α Neg.neg,
quotient := (· / ·) , remainder := fun a b => a - a * b / b , quotient_zero := div_zero ,
quotient_mul_add_remainder_eq := fun a b => by
-- Porting note: was `by_cases h : b = 0 <;> simp [h, mul_div_cancel']`
b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a by_cases h : b = 0 pos b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a neg b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a <;> pos b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a neg b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a dsimp only
b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a · dsimp only
rw [ h , zero_mul , mul_zero , zero_div , zero_add , sub_zero ]
b * (fun x x_1 => x / x_1 ) a b + (fun a b => a - a * b / b ) a b = a · dsimp only
rw [ mul_div_cancel' _ h ]
simp only [ ne_eq : ∀ {α : Sort ?u.5547} (a b : α ), (a ≠ b ) = ¬ a = b ne_eq, h , not_false_iff , mul_div_cancel , sub_self , add_zero ]
r := fun a b => a = 0 ∧ b ≠ 0 ,
r_wellFounded :=
WellFounded.intro fun a =>
( Acc.intro : ∀ {α : Sort ?u.3924} {r : α → α → Prop } (x : α ), (∀ (y : α ), r y x → Acc r y ) → Acc r x Acc.intro _ ) fun b ⟨ hb , _⟩ => ( Acc.intro : ∀ {α : Sort ?u.3972} {r : α → α → Prop } (x : α ), (∀ (y : α ), r y x → Acc r y ) → Acc r x Acc.intro _ ) fun c ⟨_, hnb ⟩ => False.elim <| hnb hb ,
remainder_lt := fun a b hnb => by (fun a b => a = 0 ∧ b ≠ 0 ) ((fun a b => a - a * b / b ) a b ) b simp [ hnb ] ,
mul_left_not_lt := fun a b hnb ⟨ hab , hna ⟩ => Or.casesOn : ∀ {a b : Prop } {motive : a ∨ b → Prop } (t : a ∨ b ),
(∀ (h : a ), motive (_ : a ∨ b ) ) → (∀ (h : b ), motive (_ : a ∨ b ) ) → motive t Or.casesOn ( mul_eq_zero . 1 : ∀ {a b : Prop }, (a ↔ b ) → a → b 1 hab ) hna hnb }
#align field.to_euclidean_domain Field.toEuclideanDomain