88public import Mathlib.Algebra.QuadraticAlgebra.Defs
99public import Mathlib.Algebra.Star.Unitary
1010
11- /-! # Quadratic algebras : involution and norm.
11+ import Mathlib.Tactic.FieldSimp
12+
13+ /-!
14+ # Quadratic algebras: involution and norm.
1215
1316Let `R` be a commutative ring. We define:
1417
15- * `QuadraticAlgebra.star` : the quadratic involution
18+ * `QuadraticAlgebra.star`: the quadratic involution
1619
17- * `QuadraticAlgebra.norm` : the norm
20+ * `QuadraticAlgebra.norm`: the norm
1821
19- We prove :
22+ We prove:
2023
2124* `QuadraticAlgebra.isUnit_iff_norm_isUnit`:
2225 `w : QuadraticAlgebra R a b` is a unit iff `w.norm` is a unit in `R`.
@@ -25,19 +28,14 @@ We prove :
2528 `w : QuadraticAlgebra R a b` isn't a zero divisor iff
2629 `w.norm` isn't a zero divisor in `R`.
2730
28- * If `R` is a field, and `∀ r, r ^ 2 ≠ a + b * r`, then `QuadraticAlgebra R a b` is a field.
29-
30- ## Warning
31- If you are working over `ℚ`, note the existence of the diamond explained in
32- `Mathlib.Algebra.QuadraticAlgebra.Defs`.
33-
31+ * If `K` is a field, and `∀ r, r ^ 2 ≠ a + b * r`, then `QuadraticAlgebra K a b` is a field.
3432 -/
3533
3634@[expose] public section
3735
3836namespace QuadraticAlgebra
3937
40- variable {R : Type *} {a b : R}
38+ variable {K R : Type *} {a b : R}
4139
4240section omega
4341
@@ -313,9 +311,9 @@ end norm
313311
314312section field
315313
316- variable [Field R] [Hab : Fact (∀ r, r ^ 2 ≠ a + b * r)]
314+ variable [Field K] {a b : K} [Hab : Fact (∀ r, r ^ 2 ≠ a + b * r)]
317315
318- lemma norm_eq_zero_iff_eq_zero {z : QuadraticAlgebra R a b} :
316+ lemma norm_eq_zero_iff_eq_zero {z : QuadraticAlgebra K a b} :
319317 norm z = 0 ↔ z = 0 := by
320318 constructor
321319 · intro hz
@@ -330,20 +328,27 @@ lemma norm_eq_zero_iff_eq_zero {z : QuadraticAlgebra R a b} :
330328 · intro hz
331329 simp [hz]
332330
333- /-- If `R` is a field and there is no `r : R` such that `r ^ 2 = a + b * r`,
334- then `QuadraticAlgebra R a b` is a field. -/
335- instance : Field (QuadraticAlgebra R a b) where
336- inv z := (norm z)⁻¹ • star z
331+ @[simps] instance : NNRatCast (QuadraticAlgebra K a b) where nnratCast q := ⟨q, 0 ⟩
332+ @[simps] instance : RatCast (QuadraticAlgebra K a b) where ratCast q := ⟨q, 0 ⟩
333+
334+ @ [simps -isSimp, simps!] instance : Inv (QuadraticAlgebra K a b) where inv z := (norm z)⁻¹ • star z
335+ @ [simps -isSimp, simps!] instance : Div (QuadraticAlgebra K a b) where div w z := w * z⁻¹
336+
337+ /-- If `K` is a field and there is no `r : K` such that `r ^ 2 = a + b * r`,
338+ then `QuadraticAlgebra K a b` is a field. -/
339+ instance : Field (QuadraticAlgebra K a b) where
340+ inv_zero := by ext <;> simp
337341 mul_inv_cancel z hz := by
338342 rw [ne_eq, ← norm_eq_zero_iff_eq_zero] at hz
339- simp only [Algebra.mul_smul_comm]
343+ simp only [inv_def, Algebra.mul_smul_comm]
340344 rw [← C_mul_eq_smul, C_eq_algebraMap, ← algebraMap_norm_eq_mul_star, ← map_mul,
341345 inv_mul_cancel₀ hz, map_one]
342- inv_zero := by simp
343- nnqsmul := _
344- nnqsmul_def := fun _ _ => rfl
345- qsmul := _
346- qsmul_def := fun _ _ => rfl
346+ nnratCast_def q := by ext <;> simp [sq]; field_simp; simp [NNRat.cast_def]
347+ ratCast_def q := by ext <;> simp [sq]; field_simp; simp [Rat.cast_def]
348+ nnqsmul := (· • ·)
349+ qsmul := (· • ·)
350+ nnqsmul_def q x := by ext <;> simp [NNRat.smul_def]
351+ qsmul_def q x := by ext <;> simp [Rat.smul_def]
347352
348353end field
349354
0 commit comments