Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


SSL Basic.lean   Sprache: Lean

 

/-
Copyright (c) 2025 Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir
-/

module

public import Mathlib.Algebra.Algebra.Rat  -- shake: keep (used in `example` only)
public import Mathlib.Algebra.Algebra.Subalgebra.Lattice
public import Mathlib.Algebra.QuadraticAlgebra.Defs
public import Mathlib.Algebra.Star.Unitary

import Mathlib.Tactic.FieldSimp

/-!
# Quadratic algebras: involution, norm, trace, change of generator, etc.

Let `R` be a commutative ring. We define:

* `QuadraticAlgebra.star`: the quadratic involution

* `QuadraticAlgebra.norm`: the norm

* `QuadraticAlgebra.trace`: the trace, as an `R`-linear map

* `QuadraticAlgebra.changeGenerator` and `QuadraticAlgebra.changeGeneratorEquiv`: the `R`-algebra
  map, respectively isomorphism (when `u` is a unit), induced by the change of generator
  `ω ↦ u • ω + k`

* `QuadraticAlgebra.mapRingHom`: the ring homomorphism induced by a ring homomorphism `R →+* S`

* `QuadraticAlgebra.baseChange`: the `R`-algebra homomorphism induced by a base change `R → S`

We prove:

* `QuadraticAlgebra.isUnit_iff_norm_isUnit`:
  `w : QuadraticAlgebra R a b` is a unit iff `w.norm` is a unit in `R`.

* `QuadraticAlgebra.norm_mem_nonZeroDivisors_iff`:
  `w : QuadraticAlgebra R a b` isn't a zero divisor iff
  `w.norm` isn't a zero divisor in `R`.

* If `K` is a field, and `∀ r, r ^ 2 ≠ a + b * r`, then `QuadraticAlgebra K a b` is a field.
-/


@[expose] public section

namespace QuadraticAlgebra

variable {K R : Type*} {a b : R}

section omega

section

variable [Zero R] [One R]

/-- The representative of the root in the quadratic algebra -/
def omega : QuadraticAlgebra R a b :=
  ⟨0, 1⟩

/-- the canonical element `⟨0, 1⟩` in a quadratic algebra `QuadraticAlgebra R a b`. -/
scoped notation "ω" => omega

@[simp]
theorem re_omega : (ω : QuadraticAlgebra R a b).re = 0 :=
  rfl

@[simp]
theorem im_omega : (ω : QuadraticAlgebra R a b).im = 1 :=
  rfl

@[deprecated (since := "2026-08-13")] alias omega_re := re_omega
@[deprecated (since := "2026-08-13")] alias omega_im := im_omega

end

variable [CommSemiring R]

theorem omega_mul_omega_eq_mk : (ω : QuadraticAlgebra R a b) * ω = ⟨a, b⟩ := by
  ext <;> simp

theorem omega_mul_omega_eq_add :
    (ω : QuadraticAlgebra R a b) * ω = a • 1 + b • ω := by
  ext <;> simp

theorem omega_pow_two_eq_add :
    ω ^ 2 = a • (1 : QuadraticAlgebra R a b) + b • ω := by
  rw [sq , omega_mul_omega_eq_add]

theorem omega_mul_omega_eq_algebraMap :
    (ω : QuadraticAlgebra R a b) * ω = algebraMap R _ a + algebraMap R _ b * ω := by
  simp [omega_mul_omega_eq_add, Algebra.algebraMap_eq_smul_one]

@[simp]
theorem basis_apply_one : basis a b 1 = ω := by
  ext <;> simp [basis]

@[simp]
theorem omega_mul_mk (x y : R) : (ω : QuadraticAlgebra R a b) * ⟨x, y⟩ = ⟨a * y, x + b * y⟩ := by
  ext <;> simp

@[simp]
theorem omega_mul_algebraMap_mul_mk (n x y : R) :
    (ω : QuadraticAlgebra R a b) * algebraMap _ _ n * ⟨x, y⟩ = ⟨a * n * y, n * x + n * b * y⟩ := by
  ext <;> simp; ring

theorem mk_eq_add_smul_omega (x y : R) :
    (⟨x, y⟩ : QuadraticAlgebra R a b) = algebraMap _ _ x + y • ω := by
  ext <;> simp

/-- Decomposition of an element of a quadratic algebra in the basis `(1, ω)`. -/
theorem re_smul_add_im_smul (x : QuadraticAlgebra R a b) : x.re • 1 + x.im • ω = x := by
  ext <;> simp

variable {A : Type*} [Ring A] [Algebra R A]

@[ext]
theorem algHom_ext {f g : QuadraticAlgebra R a b →ₐ[R] A}
    (h : f ω = g ω) : f = g := by
  refine AlgHom.ext fun z ↦ ?_
  rw [← re_smul_add_im_smul z]
  simp [h]

/-- The unique `AlgHom` from `QuadraticAlgebra R a b` to an `R`-algebra `A`,
constructed by replacing `ω` with the provided root.
Conversely, this associates to every algebra morphism `QuadraticAlgebra R a b →ₐ[R] A`
a value of `ω` in `A`. -/

@[simps]
def lift : { u : A // u * u = a • 1 + b • u } ≃ (QuadraticAlgebra R a b →ₐ[R] A) where
  toFun u :=
    { toFun z := z.re • 1 + z.im • u
      map_zero' := by simp
      map_add' z w := by
        simp only [re_add, im_add, add_smul, ← add_assoc]
        congr 1
        simp only [add_assoc]
        congr 1
        rw [add_comm]
      map_one' := by simp
      map_mul' z w := by
        symm
        calc
          (z.re • (1 : A) + z.im • ↑u) * (w.re • 1 + w.im • ↑u) =
            (z.re * w.re) • (1 : A) + (z.re * w.im) • u +
              (z.im * w.re) • u + (z.im * w.im) • (u * u) := by
              simp only [mul_add, mul_one, add_mul, one_mul, ← add_assoc, smul_mul_smul]
              apply add_add_add_comm'
          _ = (z.re * w.re) • (1 : A) + (z.re * w.im + z.im * w.re) • u +
                (z.im * w.im) • (u * u) := by
              congr 1
              simp only [add_assoc]
              rw [← add_smul]
          _ = (z.re * w.re) • 1 + (z.re * w.im + z.im * w.re) • u +
                (z.im * w.im) • (a • 1 + b • u) := by
              simp [u.prop]
          _ = (z.re * w.re + a * z.im * w.im) • 1 +
                (z.re * w.im + z.im * w.re + b * z.im * w.im) • u := by
              simp only [smul_add]
              module
            _ = (z * w).re • 1 + (z * w).im • u := by
              simp
      commutes' r := by
        simp [← Algebra.algebraMap_eq_smul_one] }
  invFun f := ⟨f (ω), by
    simp [← map_mul, omega_mul_omega_eq_add]
    ⟩
  left_inv r := by
    simp
  right_inv f := by
    ext
    simp

/-- A quadratic algebra is generated by `ω`. -/
theorem adjoin_omega_eq_top : Algebra.adjoin R {(ω : QuadraticAlgebra R a b)} = ⊤ :=
  Algebra.eq_top_iff.mpr fun z ↦
    re_smul_add_im_smul z ▸ add_mem (Subalgebra.smul_mem _ (one_mem _) _)
      (Subalgebra.smul_mem _ (Algebra.self_mem_adjoin_singleton R ω) _)

/-- The range of `lift ⟨u, h⟩` is the subalgebra of `A` generated by `u`. -/
theorem range_lift {u : A} (h : u * u = a • 1 + b • u) :
    (lift ⟨u, h⟩).range = Algebra.adjoin R {u} := by
  rw [← Algebra.map_top, ← adjoin_omega_eq_top, AlgHom.map_adjoin_singleton]
  simp

/-- `lift ⟨u, h⟩` is surjective iff `u` generates `A` as an `R`-algebra. -/
theorem lift_surjective_iff {u : A} (h : u * u = a • 1 + b • u) :
    Function.Surjective (lift ⟨u, h⟩) ↔ Algebra.adjoin R {u} = ⊤ := by
  rw [← AlgHom.range_eq_top, range_lift]

end omega

section lift

variable [CommRing R] {A : Type*} [Ring A] [Algebra R A]

/-- `lift ⟨u, h⟩` is injective iff `1` and `u` are `R`-linearly independent. -/
theorem lift_injective_iff {u : A} (h : u * u = a • 1 + b • u) :
    Function.Injective (lift ⟨u, h⟩) ↔ LinearIndependent R ![1, u] := by
  rw [LinearIndependent.pair_iff, injective_iff_map_eq_zero]
  refine ⟨fun hlift s t hst ↦ ?_, fun hlift z hz ↦ by ext <;> simp [hlift z.re z.im hz]⟩
  simpa using QuadraticAlgebra.ext_iff.mp (hlift ⟨s, t⟩ (by rwa [lift_apply_apply]))

end lift

section star

variable [CommRing R]

/-- Conjugation in `QuadraticAlgebra R a b`.
The conjugate of `x + y ω` is `x + y ω' = (x + b * y) - y ω`. -/

instance : Star (QuadraticAlgebra R a b) where
  star z := ⟨z.re + b * z.im, -z.im⟩

@[simp]
theorem star_mk (x y : R) :
    star (⟨x, y⟩ : QuadraticAlgebra R a b) = ⟨x + b * y, -y⟩ :=
  rfl

@[simp]
theorem re_star (z : QuadraticAlgebra R a b) :
    (star z).re = z.re + b * z.im :=
  rfl

@[simp]
theorem im_star (z : QuadraticAlgebra R a b) :
    (star z).im = -z.im :=
  rfl

theorem mul_star (x y : R) :
    (⟨x, y⟩ * star ⟨x, y⟩ : QuadraticAlgebra R a b) = (algebraMap _ _ x) * (algebraMap _ _ x) +
      (algebraMap _ _ b) * (algebraMap _ _ x) * (algebraMap _ _ y) - (algebraMap _ _ a) *
      (algebraMap _ _ y) * (algebraMap _ _ y) := by
  ext <;> simp <;> ring

instance : StarRing (QuadraticAlgebra R a b) where
  star_involutive _ := by
    refine QuadraticAlgebra.ext (by simp) (neg_neg _)
  star_mul a b := by ext <;>
    simp only [re_star, re_mul, im_mul, im_star, mul_neg, neg_mul, neg_neg] <;> ring
  star_add _ _ := QuadraticAlgebra.ext (by simp only [re_star, re_add, im_add]; ring) (neg_add _ _)

/-- `z - star z` is a multiple of the difference `ω - star ω`. -/
theorem sub_star (z : QuadraticAlgebra R a b) :
    z - star z = z.im • (ω - star ω) := by
  ext <;> simp <;> ring

/-- Conjugation as an `R`-algebra automorphism of `QuadraticAlgebra R a b`. -/
def starAlgEquiv : QuadraticAlgebra R a b ≃ₐ[R] QuadraticAlgebra R a b where
  __ := starRingAut
  commutes' _ := by ext <;> simp

@[simp]
theorem starAlgEquiv_apply (z : QuadraticAlgebra R a b) : starAlgEquiv z = star z := rfl

@[simp]
theorem starAlgEquiv_symm_apply (z : QuadraticAlgebra R a b) : starAlgEquiv.symm z = star z := rfl

end star

section norm

variable [CommRing R]

/-- the norm in a quadratic algebra, as a `MonoidHom`. -/
def norm : QuadraticAlgebra R a b →* R where
  toFun z := z.re * z.re + b * z.re * z.im - a * z.im * z.im
  map_mul' z w := by simp only [re_mul, im_mul]; ring
  map_one' := by simp

theorem norm_def (z : QuadraticAlgebra R a b) :
    z.norm = z.re * z.re + b * z.re * z.im - a * z.im * z.im :=
  rfl

@[simp]
theorem norm_zero : norm (0 : QuadraticAlgebra R a b) = 0 := by simp [norm]

@[simp]
theorem norm_one : norm (1 : QuadraticAlgebra R a b) = 1 := by simp [norm]

@[simp]
theorem norm_algebraMap (r : R) : norm (algebraMap R (QuadraticAlgebra R a b) r) = r ^ 2 := by
  simp [norm_def, pow_two]

@[simp]
theorem norm_smul {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R]
    (s : S) (z : QuadraticAlgebra R a b) :
    norm (s • z) = s ^ 2 • norm z := by
  simp [norm_def, mul_smul_comm, smul_sub, pow_two, mul_smul, smul_mul_assoc]

@[simp]
theorem norm_natCast (n : ℕ) : norm (n : QuadraticAlgebra R a b) = n ^ 2 := by
  simp [norm_def, pow_two]

@[simp]
theorem norm_intCast (n : ℤ) : norm (n : QuadraticAlgebra R a b) = n ^ 2 := by
  simp [norm_def, pow_two]

theorem algebraMap_norm_eq_mul_star (z : QuadraticAlgebra R a b) :
    (algebraMap R _ (norm z : R)) = z * star z := by
  ext <;> simp [norm, star, mul_comm] <;> ring

@[simp]
theorem norm_neg (x : QuadraticAlgebra R a b) : (-x).norm = x.norm := by
  simp [norm]

@[simp]
theorem norm_star (x : QuadraticAlgebra R a b) : (star x).norm = x.norm := by
  simp only [norm, MonoidHom.coe_mk, OneHom.coe_mk, re_star, im_star, mul_neg, neg_mul, neg_neg,
    sub_left_inj]
  ring

theorem isUnit_iff_norm_isUnit {x : QuadraticAlgebra R a b} :
    IsUnit x ↔ IsUnit (x.norm) := by
  constructor
  · exact IsUnit.map norm
  · simp only [isUnit_iff_exists]
    rintro ⟨r, hr, hr'⟩
    rw [← C_inj (R := R) (a := a) (b := b), C_mul, C_eq_algebraMap, algebraMap_norm_eq_mul_star,
      mul_assoc, map_one] at hr
    refine ⟨_, hr, ?_⟩
    rw [mul_comm, hr]

/-- An element of `QuadraticAlgebra R a b` has norm equal to `1`
if and only if it is contained in the submonoid of unitary elements. -/

theorem norm_eq_one_iff_mem_unitary {z : QuadraticAlgebra R a b} :
    z.norm = 1 ↔ z ∈ unitary (QuadraticAlgebra R a b) := by
  rw [Unitary.mem_iff_self_mul_star, ← algebraMap_norm_eq_mul_star]
  simp [← algebraMap_inj (R := R) (a := a) (b := b)]

alias ⟨mem_unitary, norm_eq_one⟩ := norm_eq_one_iff_mem_unitary

/-- The kernel of the norm map on `QuadraticAlgebra R a b` equals
the submonoid of unitary elements. -/

theorem mker_norm_eq_unitary :
    MonoidHom.mker (@norm R a b _) = unitary (QuadraticAlgebra R a b) :=
  Submonoid.ext fun _ => norm_eq_one_iff_mem_unitary

open nonZeroDivisors

theorem algebraMap_mem_nonZeroDivisors_iff {r : R} :
    algebraMap R (QuadraticAlgebra R a b) r ∈ (QuadraticAlgebra R a b)⁰ ↔ r ∈ R⁰ := by
  simp only [mem_nonZeroDivisors_iff_right]
  constructor
  · intro H x hxr
    rw [← algebraMap_inj, map_zero]
    apply H
    rw [← map_mul, hxr, map_zero]
  · intro h z hz
    rw [QuadraticAlgebra.ext_iff, re_zero, im_zero] at hz
    simp only [re_mul, algebraMap_re, algebraMap_im, mul_zero, add_zero, im_mul, zero_add] at hz
    simp [QuadraticAlgebra.ext_iff, re_zero, im_zero, h _ hz.left, h _ hz.right]

theorem star_mem_nonZeroDivisors {z : QuadraticAlgebra R a b}
    (hz : z ∈ (QuadraticAlgebra R a b)⁰) :
    star z ∈ (QuadraticAlgebra R a b)⁰ := by
  rw [mem_nonZeroDivisors_iff_right] at hz ⊢
  intro w hw
  apply star_involutive.injective
  rw [star_zero]
  apply hz
  rw [← star_involutive z, ← star_mul, mul_comm, hw, star_zero]

theorem star_mem_nonZeroDivisors_iff {z : QuadraticAlgebra R a b} :
    star z ∈ (QuadraticAlgebra R a b)⁰ ↔ z ∈ (QuadraticAlgebra R a b)⁰ := by
  refine ⟨fun h ↦ ?_, star_mem_nonZeroDivisors⟩
  rw [← star_involutive z]
  exact star_mem_nonZeroDivisors h

theorem norm_mem_nonZeroDivisors_iff {z : QuadraticAlgebra R a b} :
    z.norm ∈ R⁰ ↔ z ∈ (QuadraticAlgebra R a b)⁰ := by
  constructor
  · simp only [mem_nonZeroDivisors_iff_right]
    intro h w hw
    have : norm z • w = 0 := by
      rw [← C_mul_eq_smul, C_eq_algebraMap, algebraMap_norm_eq_mul_star, mul_comm, ← mul_assoc, hw,
        zero_mul]
    simp only [QuadraticAlgebra.ext_iff, re_smul, smul_eq_mul, mul_comm, re_zero, im_smul,
      im_zero] at this
    ext <;> simp [h _ this.left, h _ this.right]
  · intro hz
    rw [← algebraMap_mem_nonZeroDivisors_iff, algebraMap_norm_eq_mul_star]
    exact Submonoid.mul_mem _ hz (star_mem_nonZeroDivisors hz)

end norm

section trace

variable [CommRing R]

attribute [local grind =] re_add im_add im_star re_star re_smul im_smul RingHom.id_apply
  algebraMap_re algebraMap_im

/-- The trace in a quadratic algebra, as an `R`-linear map. -/
def trace : QuadraticAlgebra R a b →ₗ[R] R where
  toFun z := 2 * z.re + b * z.im
  map_add' := by grind
  map_smul' := by grind [smul_eq_mul]

variable (z : QuadraticAlgebra R a b)

theorem trace_def : trace z = 2 * z.re + b * z.im := rfl

@[simp]
theorem trace_algebraMap (r : R) :
    trace (algebraMap R (QuadraticAlgebra R a b) r) = 2 * r := by
  grind [trace_def]

@[simp]
theorem trace_natCast (n : ℕ) : trace (n : QuadraticAlgebra R a b) = 2 * n := by
  simp [trace_def, re_natCast, im_natCast]

@[simp]
theorem trace_intCast (n : ℤ) : trace (n : QuadraticAlgebra R a b) = 2 * n := by
  simp [trace_def, re_intCast, im_intCast]

@[simp]
theorem trace_omega : trace (ω : QuadraticAlgebra R a b) = b := by
  simp [trace_def]

@[simp]
theorem trace_one : trace (1 : QuadraticAlgebra R a b) = 2 := by
  simp [trace_def]

@[simp]
theorem trace_star : trace (star z) = trace z := by
  grind [trace_def]

/-- `z + star z` is the trace of `z`. -/
theorem algebraMap_trace_eq_add_star :
    algebraMap R (QuadraticAlgebra R a b) (trace z) = z + star z := by
  ext <;> grind [trace_def]

/-- The conjugate of `z` is `trace z - z`. -/
theorem star_eq :
    star z = algebraMap R (QuadraticAlgebra R a b) (trace z) - z := by
  rw [algebraMap_trace_eq_add_star, add_sub_cancel_left]

/-- Every element of a quadratic algebra satisfies its characteristic equation. -/
theorem sq_sub_trace_smul_add_norm_eq_zero :
    z ^ 2 - trace z • z + algebraMap R _ (norm z) = 0 := by
  rw [Algebra.smul_def, algebraMap_trace_eq_add_star, algebraMap_norm_eq_mul_star]; ring

theorem sq_eq_trace_smul_sub_norm :
    z ^ 2 = trace z • z - algebraMap R _ (norm z) := by
  rw [← sub_eq_zero, ← sub_add, sq_sub_trace_smul_add_norm_eq_zero]

end trace

section changeGenerator

variable [CommRing R]

-- The quadratic relation satisfied by the new generator `u • ω + k`; this is what makes
-- `changeGenerator` well defined. Stated with `x * x` rather than `x ^ 2` to match the shape of
-- the subtype condition of `lift` (`{ u // u * u = a • 1 + b • u }`), so it feeds
-- `changeGenerator` verbatim.
private theorem changeGenerator_relation (a b u k : R) :
    (u • ω + algebraMap R (QuadraticAlgebra R a b) k) *
        (u • ω + algebraMap R (QuadraticAlgebra R a b) k) =
      (u ^ 2 * a - u * b * k - k ^ 2) • 1 +
        (u * b + 2 * k) • (u • ω + algebraMap R (QuadraticAlgebra R a b) k) := by
  ext <;> simp <;> ring

/-- The `R`-algebra map induced by the change of generator `ω ↦ u • ω + k`, see
`changeGenerator_omega`. -/

@[simps!]
def changeGenerator (a b u k : R) {a' b' : R} (ha : a' = u ^ 2 * a - u * b * k - k ^ 2)
    (hb : b' = u * b + 2 * k) :
    QuadraticAlgebra R a' b' →ₐ[R] QuadraticAlgebra R a b :=
  lift ⟨u • ω + algebraMap R _ k, by rw [ha, hb]; exact changeGenerator_relation a b u k⟩

@[simp]
theorem changeGenerator_omega (a b u k : R) {a' b' : R} (ha : a' = u ^ 2 * a - u * b * k - k ^ 2)
    (hb : b' = u * b + 2 * k) :
    changeGenerator a b u k ha hb ω = u • ω + algebraMap R (QuadraticAlgebra R a b) k := by
  ext <;> simp

theorem changeGenerator_injective (a b u k : R) {a' b' : R}
    (ha : a' = u ^ 2 * a - u * b * k - k ^ 2)
    (hb : b' = u * b + 2 * k) (hu : IsRegular u) :
    Function.Injective (changeGenerator a b u k ha hb) := by
  intro z w h
  have hy : z.im = w.im := hu.right <| by simpa using congr(im $h)
  exact QuadraticAlgebra.ext (by simpa [hy] using congr(re $h)) hy

/-- `changeGenerator` along a unit `u`, as an isomorphism. -/
@[simps! apply symm_apply]
def changeGeneratorEquiv (a b : R) (u : Rˣ) (k : R) {a' b' : R}
    (ha : a' = (u : R) ^ 2 * a - (u : R) * b * k - k ^ 2)
    (hb : b' = (u : R) * b + 2 * k) :
    QuadraticAlgebra R a' b' ≃ₐ[R] QuadraticAlgebra R a b where
  __ := changeGenerator a b u k ha hb
  invFun := changeGenerator a' b' (u⁻¹ : Rˣ) (-(u⁻¹ : Rˣ) * k)
    (by grind [sq, mul_assoc, Units.inv_mul_cancel_left])
    (by grind [Units.inv_mul_cancel_left])
  left_inv _ := by ext <;> simp [mul_assoc]
  right_inv _ := by ext <;> simp [mul_assoc]

@[deprecated (since := "2026-08-14")] alias map := changeGenerator
@[deprecated (since := "2026-08-14")] alias map_omega := changeGenerator_omega
@[deprecated (since := "2026-08-14")] alias map_injective := changeGenerator_injective
@[deprecated (since := "2026-08-14")] alias mapEquiv := changeGeneratorEquiv

end changeGenerator

section mapRingHom

variable {R S T : Type*}

section CommSemiring

variable [CommSemiring R] [CommSemiring S] (f : R →+* S) (a b : R)

/-- The ring homomorphism between quadratic algebras induced by a ring homomorphism `f : R →+* S`,
sending `ω` to `ω`. -/

@[simps!]
def mapRingHom : QuadraticAlgebra R a b →+* QuadraticAlgebra S (f a) (f b) where
  toFun z := ⟨f z.re, f z.im⟩
  map_one' := by ext <;> simp
  map_mul' _ _ := by ext <;> simp
  map_zero' := by ext <;> simp
  map_add' _ _ := by ext <;> simp

@[simp]
theorem mapRingHom_omega : mapRingHom f a b ω = ω := by
  ext <;> simp

theorem mapRingHom_injective (hf : Function.Injective f) :
    Function.Injective (mapRingHom f a b) := fun _ _ h ↦ by
  ext
  · exact hf (congr_arg re h)
  · exact hf (congr_arg im h)

theorem mapRingHom_surjective (hf : Function.Surjective f) :
    Function.Surjective (mapRingHom f a b) := fun z ↦ by
  obtain ⟨x, hx⟩ := hf z.re
  obtain ⟨y, hy⟩ := hf z.im
  exact ⟨⟨x, y⟩, by ext <;> simp [hx, hy]⟩

@[simp]
theorem mapRingHom_id : mapRingHom (.id R) a b = .id (QuadraticAlgebra R a b) := rfl

theorem mapRingHom_comp [CommSemiring T] (g : S →+* T) :
    (mapRingHom g (f a) (f b)).comp (mapRingHom f a b) = mapRingHom (g.comp f) a b := rfl

end CommSemiring

section CommRing

variable [CommRing R] [CommRing S] (f : R →+* S) (a b : R) (x : QuadraticAlgebra R a b)

@[simp]
theorem norm_mapRingHom : norm (mapRingHom f a b x) = f (norm x) := by
  simp [norm_def]

@[simp]
theorem trace_mapRingHom : trace (mapRingHom f a b x) = f (trace x) := by
  simp [trace_def, map_ofNat]

@[simp]
theorem mapRingHom_star : mapRingHom f a b (star x) = star (mapRingHom f a b x) := by
  ext <;> simp

end CommRing

end mapRingHom

section baseChange

variable {R : Type*} (S : Type*) [CommSemiring R] [CommSemiring S] [Algebra R S] (a b : R)

/-- The `R`-algebra homomorphism between quadratic algebras induced by the base change `R → S`,
sending `ω` to `ω`. -/

def baseChange :
    QuadraticAlgebra R a b →ₐ[R] QuadraticAlgebra S (algebraMap R S a) (algebraMap R S b) :=
  { mapRingHom (algebraMap R S) a b with
    commutes' _ := by ext <;> simp [Algebra.algebraMap_eq_smul_one] }

@[simp]
theorem coe_baseChange :
    baseChange S a b = mapRingHom (algebraMap R S) a b := rfl

/-- The `QuadraticAlgebra R a b`-algebra structure on the base change of `QuadraticAlgebra R a b`
along `R → S`. This is not an instance, since for `R = S` it clashes with `Algebra.id`. -/

@[instance_reducible]
def algebra : Algebra (QuadraticAlgebra R a b)
    (QuadraticAlgebra S (algebraMap R S a) (algebraMap R S b)) :=
  (mapRingHom (algebraMap R S) a b).toAlgebra

theorem baseChange_injective [FaithfulSMul R S] :
    Function.Injective (baseChange S a b) :=
  mapRingHom_injective _ a b (FaithfulSMul.algebraMap_injective R S)

end baseChange

section field

variable [Field K] {a b : K} [Hab : Fact (∀ r, r ^ 2 ≠ a + b * r)]

lemma norm_eq_zero_iff_eq_zero {z : QuadraticAlgebra K a b} :
    norm z = 0 ↔ z = 0 := by
  constructor
  · intro hz
    rw [norm_def] at hz
    by_cases h : z.im = 0
    · simp [h] at hz
      aesop
    · exfalso
      rw [← pow_two, sub_eq_zero, ← eq_sub_iff_add_eq] at hz
      apply Hab.out (-z.re / z.im)
      grind
  · intro hz
    simp [hz]

@[simps -isSimp, simps!] instance : NNRatCast (QuadraticAlgebra K a b) where nnratCast q := .C q
@[simps -isSimp, simps!] instance : RatCast (QuadraticAlgebra K a b) where ratCast q := .C q

@[simps -isSimp, simps!] instance : Inv (QuadraticAlgebra K a b) where inv z := (norm z)⁻¹ • star z
@[simps -isSimp, simps!] instance : Div (QuadraticAlgebra K a b) where div w z := w * z⁻¹

/-- If `K` is a field and there is no `r : K` such that `r ^ 2 = a + b * r`,
then `QuadraticAlgebra K a b` is a field. -/

instance : Field (QuadraticAlgebra K a b) where
  inv_zero := by ext <;> simp
  mul_inv_cancel z hz := by
    rw [ne_eq, ← norm_eq_zero_iff_eq_zero] at hz
    simp only [inv_def, Algebra.mul_smul_comm]
    rw [← C_mul_eq_smul, C_eq_algebraMap, ← algebraMap_norm_eq_mul_star, ← map_mul,
      inv_mul_cancel₀ hz, map_one]
  nnratCast_def q := by ext <;> simp [sq]; field_simp; simp [NNRat.cast_def]
  ratCast_def q := by ext <;> simp [sq]; field_simp; simp [Rat.cast_def]
  nnqsmul := (· • ·)
  qsmul := (· • ·)
  nnqsmul_def q x := by ext <;> simp [NNRat.smul_def]
  qsmul_def q x := by ext <;> simp [Rat.smul_def]

/-- When `b = 0`, the `Field` instance is inferable from `¬ IsSquare a` alone: it provides the
no-root condition `∀ r, r ^ 2 ≠ a + 0 * r`. -/

instance {a : K} [Fact (¬ IsSquare a)] : Fact (∀ r : K, r ^ 2 ≠ a + 0 * r) :=
  ⟨fun r hr ↦ Fact.out (p := ¬ IsSquare a) ⟨r, by simpa [sq] using hr.symm⟩⟩

-- The `b = 0` bridge makes the `Field` instance inferable from `¬ IsSquare a` alone.
example {a : K} [Fact (¬ IsSquare a)] : Field (QuadraticAlgebra K a 0) := inferInstance

-- Over `ℚ`, the algebra structure of `QuadraticAlgebra.instAlgebra` and the one coming from the
-- `Field` structure through `DivisionRing.toRatAlgebra` are the same instance.
example {a b : ℚ} [Fact (∀ r : ℚ, r ^ 2 ≠ a + b * r)] :
    (DivisionRing.toRatAlgebra : Algebra ℚ (QuadraticAlgebra ℚ a b)) = instAlgebra := by
  with_implicit rfl

end field

end QuadraticAlgebra

Messung
CHZG
9310010097

¤ Dauer der Verarbeitung: 0.21 Sekunden  ¤

*© Formatika GbR, Deutschland







                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,088
#Domains=862,466