Skip to content

Commit 4b7e5c1

Browse files
committed
refactor(Algebra/QuadraticAlgebra): crush -algebra diamond (#38818)
From FormalConjectures
1 parent e361dab commit 4b7e5c1

2 files changed

Lines changed: 28 additions & 37 deletions

File tree

Mathlib/Algebra/QuadraticAlgebra/Basic.lean

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ module
88
public import Mathlib.Algebra.QuadraticAlgebra.Defs
99
public 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
1316
Let `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

3836
namespace QuadraticAlgebra
3937

40-
variable {R : Type*} {a b : R}
38+
variable {K R : Type*} {a b : R}
4139

4240
section omega
4341

@@ -313,9 +311,9 @@ end norm
313311

314312
section 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

348353
end field
349354

Mathlib/Algebra/QuadraticAlgebra/Defs.lean

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ and define some algebraic structures on it.
2121
* `QuadraticAlgebra R a b`:
2222
[Bourbaki, *Algebra I*][bourbaki1989] with coefficients `a`, `b` in `R`.
2323
24-
## Warning
25-
If `R` is a ring, then `QuadraticAlgebra a b` is an `R`-algebra, and if `R` is of characteristic
26-
zero then the same holds for `QuadraticAlgebra a b`. In particular, in the very common case where
27-
`R` is `ℚ` and `a` and `b` are such that `QuadraticAlgebra a b` is a field, then
28-
`QuadraticAlgebra a b` is a `ℚ`-algebra in two ways, that are not definitionally equal. This is a
29-
known diamond for characteristic zero fields. If you are working in this setting you should start
30-
your file with
31-
```
32-
attribute [-instance] DivisionRing.toRatAlgebra
33-
```
34-
to keep the `CharZero` instance but to avoid having two `Algebra` instances. (Note that all the
35-
basic theorems about `QuadraticAlgebra` are stated using the general instance
36-
`Algebra R (QuadraticAlgebra a b)`, so you don't want to deactivate that one.)
37-
3824
## Tags
3925
4026
Quadratic algebra, quadratic extension

0 commit comments

Comments
 (0)