path
stringlengths
11
71
content
stringlengths
75
124k
Algebra\Polynomial\Degree\Lemmas.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Eval /-! # Theory of degrees of polynomials Some of the main results include - `natDegree_comp_le` : The degree of the composition is at most the product of degrees -/ noncomputable section open Polynomial open Finsupp Finset namespace Polynomial universe u v w variable {R : Type u} {S : Type v} {ι : Type w} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section Degree theorem natDegree_comp_le : natDegree (p.comp q) ≤ natDegree p * natDegree q := letI := Classical.decEq R if h0 : p.comp q = 0 then by rw [h0, natDegree_zero]; exact Nat.zero_le _ else WithBot.coe_le_coe.1 <| calc ↑(natDegree (p.comp q)) = degree (p.comp q) := (degree_eq_natDegree h0).symm _ = _ := congr_arg degree comp_eq_sum_left _ ≤ _ := degree_sum_le _ _ _ ≤ _ := Finset.sup_le fun n hn => calc degree (C (coeff p n) * q ^ n) ≤ degree (C (coeff p n)) + degree (q ^ n) := degree_mul_le _ _ _ ≤ natDegree (C (coeff p n)) + n • degree q := (add_le_add degree_le_natDegree (degree_pow_le _ _)) _ ≤ natDegree (C (coeff p n)) + n • ↑(natDegree q) := (add_le_add_left (nsmul_le_nsmul_right (@degree_le_natDegree _ _ q) n) _) _ = (n * natDegree q : ℕ) := by rw [natDegree_C, Nat.cast_zero, zero_add, nsmul_eq_mul] simp _ ≤ (natDegree p * natDegree q : ℕ) := WithBot.coe_le_coe.2 <| mul_le_mul_of_nonneg_right (le_natDegree_of_ne_zero (mem_support_iff.1 hn)) (Nat.zero_le _) theorem degree_pos_of_root {p : R[X]} (hp : p ≠ 0) (h : IsRoot p a) : 0 < degree p := lt_of_not_ge fun hlt => by have := eq_C_of_degree_le_zero hlt rw [IsRoot, this, eval_C] at h simp only [h, RingHom.map_zero] at this exact hp this theorem natDegree_le_iff_coeff_eq_zero : p.natDegree ≤ n ↔ ∀ N : ℕ, n < N → p.coeff N = 0 := by simp_rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero, Nat.cast_lt] theorem natDegree_add_le_iff_left {n : ℕ} (p q : R[X]) (qn : q.natDegree ≤ n) : (p + q).natDegree ≤ n ↔ p.natDegree ≤ n := by refine ⟨fun h => ?_, fun h => natDegree_add_le_of_degree_le h qn⟩ refine natDegree_le_iff_coeff_eq_zero.mpr fun m hm => ?_ convert natDegree_le_iff_coeff_eq_zero.mp h m hm using 1 rw [coeff_add, natDegree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero] theorem natDegree_add_le_iff_right {n : ℕ} (p q : R[X]) (pn : p.natDegree ≤ n) : (p + q).natDegree ≤ n ↔ q.natDegree ≤ n := by rw [add_comm] exact natDegree_add_le_iff_left _ _ pn theorem natDegree_C_mul_le (a : R) (f : R[X]) : (C a * f).natDegree ≤ f.natDegree := calc (C a * f).natDegree ≤ (C a).natDegree + f.natDegree := natDegree_mul_le _ = 0 + f.natDegree := by rw [natDegree_C a] _ = f.natDegree := zero_add _ theorem natDegree_mul_C_le (f : R[X]) (a : R) : (f * C a).natDegree ≤ f.natDegree := calc (f * C a).natDegree ≤ f.natDegree + (C a).natDegree := natDegree_mul_le _ = f.natDegree + 0 := by rw [natDegree_C a] _ = f.natDegree := add_zero _ theorem eq_natDegree_of_le_mem_support (pn : p.natDegree ≤ n) (ns : n ∈ p.support) : p.natDegree = n := le_antisymm pn (le_natDegree_of_mem_supp _ ns) theorem natDegree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) : (C a * p).natDegree = p.natDegree := le_antisymm (natDegree_C_mul_le a p) (calc p.natDegree = (1 * p).natDegree := by nth_rw 1 [← one_mul p] _ = (C ai * (C a * p)).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc] _ ≤ (C a * p).natDegree := natDegree_C_mul_le ai (C a * p)) theorem natDegree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) : (p * C a).natDegree = p.natDegree := le_antisymm (natDegree_mul_C_le p a) (calc p.natDegree = (p * 1).natDegree := by nth_rw 1 [← mul_one p] _ = (p * C a * C ai).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc] _ ≤ (p * C a).natDegree := natDegree_mul_C_le (p * C a) ai) /-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero` force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`. -/ theorem natDegree_mul_C_eq_of_mul_ne_zero (h : p.leadingCoeff * a ≠ 0) : (p * C a).natDegree = p.natDegree := by refine eq_natDegree_of_le_mem_support (natDegree_mul_C_le p a) ?_ refine mem_support_iff.mpr ?_ rwa [coeff_mul_C] /-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero` force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`. -/ theorem natDegree_C_mul_eq_of_mul_ne_zero (h : a * p.leadingCoeff ≠ 0) : (C a * p).natDegree = p.natDegree := by refine eq_natDegree_of_le_mem_support (natDegree_C_mul_le a p) ?_ refine mem_support_iff.mpr ?_ rwa [coeff_C_mul] theorem natDegree_add_coeff_mul (f g : R[X]) : (f * g).coeff (f.natDegree + g.natDegree) = f.coeff f.natDegree * g.coeff g.natDegree := by simp only [coeff_natDegree, coeff_mul_degree_add_degree] theorem natDegree_lt_coeff_mul (h : p.natDegree + q.natDegree < m + n) : (p * q).coeff (m + n) = 0 := coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt h) theorem coeff_mul_of_natDegree_le (pm : p.natDegree ≤ m) (qn : q.natDegree ≤ n) : (p * q).coeff (m + n) = p.coeff m * q.coeff n := by simp_rw [← Polynomial.toFinsupp_apply, toFinsupp_mul] refine AddMonoidAlgebra.apply_add_of_supDegree_le ?_ Function.injective_id ?_ ?_ · simp · rwa [supDegree_eq_natDegree, id_eq] · rwa [supDegree_eq_natDegree, id_eq] theorem coeff_pow_of_natDegree_le (pn : p.natDegree ≤ n) : (p ^ m).coeff (m * n) = p.coeff n ^ m := by induction' m with m hm · simp · rw [pow_succ, pow_succ, ← hm, Nat.succ_mul, coeff_mul_of_natDegree_le _ pn] refine natDegree_pow_le.trans (le_trans ?_ (le_refl _)) exact mul_le_mul_of_nonneg_left pn m.zero_le theorem coeff_pow_eq_ite_of_natDegree_le_of_le {o : ℕ} (pn : natDegree p ≤ n) (mno : m * n ≤ o) : coeff (p ^ m) o = if o = m * n then (coeff p n) ^ m else 0 := by rcases eq_or_ne o (m * n) with rfl | h · simpa only [ite_true] using coeff_pow_of_natDegree_le pn · simpa only [h, ite_false] using coeff_eq_zero_of_natDegree_lt <| lt_of_le_of_lt (natDegree_pow_le_of_le m pn) (lt_of_le_of_ne mno h.symm) theorem coeff_add_eq_left_of_lt (qn : q.natDegree < n) : (p + q).coeff n = p.coeff n := (coeff_add _ _ _).trans <| (congr_arg _ <| coeff_eq_zero_of_natDegree_lt <| qn).trans <| add_zero _ theorem coeff_add_eq_right_of_lt (pn : p.natDegree < n) : (p + q).coeff n = q.coeff n := by rw [add_comm] exact coeff_add_eq_left_of_lt pn theorem degree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S) (h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on degree ∘ f)) : degree (s.sum f) = s.sup fun i => degree (f i) := by classical induction' s using Finset.induction_on with x s hx IH · simp · simp only [hx, Finset.sum_insert, not_false_iff, Finset.sup_insert] specialize IH (h.mono fun _ => by simp (config := { contextual := true })) rcases lt_trichotomy (degree (f x)) (degree (s.sum f)) with (H | H | H) · rw [← IH, sup_eq_right.mpr H.le, degree_add_eq_right_of_degree_lt H] · rcases s.eq_empty_or_nonempty with (rfl | hs) · simp obtain ⟨y, hy, hy'⟩ := Finset.exists_mem_eq_sup s hs fun i => degree (f i) rw [IH, hy'] at H by_cases hx0 : f x = 0 · simp [hx0, IH] have hy0 : f y ≠ 0 := by contrapose! H simpa [H, degree_eq_bot] using hx0 refine absurd H (h ?_ ?_ fun H => hx ?_) · simp [hx0] · simp [hy, hy0] · exact H.symm ▸ hy · rw [← IH, sup_eq_left.mpr H.le, degree_add_eq_left_of_degree_lt H] theorem natDegree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S) (h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on natDegree ∘ f)) : natDegree (s.sum f) = s.sup fun i => natDegree (f i) := by by_cases H : ∃ x ∈ s, f x ≠ 0 · obtain ⟨x, hx, hx'⟩ := H have hs : s.Nonempty := ⟨x, hx⟩ refine natDegree_eq_of_degree_eq_some ?_ rw [degree_sum_eq_of_disjoint] · rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs, Nat.cast_withBot, Finset.coe_sup' hs, ← Finset.sup'_eq_sup hs] refine le_antisymm ?_ ?_ · rw [Finset.sup'_le_iff] intro b hb by_cases hb' : f b = 0 · simpa [hb'] using hs rw [degree_eq_natDegree hb', Nat.cast_withBot] exact Finset.le_sup' (fun i : S => (natDegree (f i) : WithBot ℕ)) hb · rw [Finset.sup'_le_iff] intro b hb simp only [Finset.le_sup'_iff, exists_prop, Function.comp_apply] by_cases hb' : f b = 0 · refine ⟨x, hx, ?_⟩ contrapose! hx' simpa [← Nat.cast_withBot, hb', degree_eq_bot] using hx' exact ⟨b, hb, (degree_eq_natDegree hb').ge⟩ · exact h.imp fun x y hxy hxy' => hxy (natDegree_eq_of_degree_eq hxy') · push_neg at H rw [Finset.sum_eq_zero H, natDegree_zero, eq_comm, show 0 = ⊥ from rfl, Finset.sup_eq_bot_iff] intro x hx simp [H x hx] variable [Semiring S] theorem natDegree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < natDegree p := lt_of_not_ge fun hlt => by have A : p = C (p.coeff 0) := eq_C_of_natDegree_le_zero hlt rw [A, eval₂_C] at hz simp only [inj (p.coeff 0) hz, RingHom.map_zero] at A exact hp A theorem degree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < degree p := natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_eval₂_root hp f hz inj) @[simp] theorem coe_lt_degree {p : R[X]} {n : ℕ} : (n : WithBot ℕ) < degree p ↔ n < natDegree p := by by_cases h : p = 0 · simp [h] simp [degree_eq_natDegree h, Nat.cast_lt] @[simp] theorem degree_map_eq_iff {f : R →+* S} {p : Polynomial R} : degree (map f p) = degree p ↔ f (leadingCoeff p) ≠ 0 ∨ p = 0 := by rcases eq_or_ne p 0 with h|h · simp [h] simp only [h, or_false] refine ⟨fun h2 ↦ ?_, degree_map_eq_of_leadingCoeff_ne_zero f⟩ have h3 : natDegree (map f p) = natDegree p := by simp_rw [natDegree, h2] have h4 : map f p ≠ 0 := by rwa [ne_eq, ← degree_eq_bot, h2, degree_eq_bot] rwa [← coeff_natDegree, ← coeff_map, ← h3, coeff_natDegree, ne_eq, leadingCoeff_eq_zero] @[simp] theorem natDegree_map_eq_iff {f : R →+* S} {p : Polynomial R} : natDegree (map f p) = natDegree p ↔ f (p.leadingCoeff) ≠ 0 ∨ natDegree p = 0 := by rcases eq_or_ne (natDegree p) 0 with h|h · simp_rw [h, ne_eq, or_true, iff_true, ← Nat.le_zero, ← h, natDegree_map_le f p] have h2 : p ≠ 0 := by rintro rfl; simp at h have h3 : degree p ≠ (0 : ℕ) := degree_ne_of_natDegree_ne h simp_rw [h, or_false, natDegree, WithBot.unbot'_eq_unbot'_iff, degree_map_eq_iff] simp [h, h2, h3] -- simp doesn't rewrite in the hypothesis for some reason tauto theorem natDegree_pos_of_nextCoeff_ne_zero (h : p.nextCoeff ≠ 0) : 0 < p.natDegree := by rw [nextCoeff] at h by_cases hpz : p.natDegree = 0 · simp_all only [ne_eq, zero_le, ite_true, not_true_eq_false] · apply Nat.zero_lt_of_ne_zero hpz end Degree end Semiring section Ring variable [Ring R] {p q : R[X]} theorem natDegree_sub : (p - q).natDegree = (q - p).natDegree := by rw [← natDegree_neg, neg_sub] theorem natDegree_sub_le_iff_left (qn : q.natDegree ≤ n) : (p - q).natDegree ≤ n ↔ p.natDegree ≤ n := by rw [← natDegree_neg] at qn rw [sub_eq_add_neg, natDegree_add_le_iff_left _ _ qn] theorem natDegree_sub_le_iff_right (pn : p.natDegree ≤ n) : (p - q).natDegree ≤ n ↔ q.natDegree ≤ n := by rwa [natDegree_sub, natDegree_sub_le_iff_left] theorem coeff_sub_eq_left_of_lt (dg : q.natDegree < n) : (p - q).coeff n = p.coeff n := by rw [← natDegree_neg] at dg rw [sub_eq_add_neg, coeff_add_eq_left_of_lt dg] theorem coeff_sub_eq_neg_right_of_lt (df : p.natDegree < n) : (p - q).coeff n = -q.coeff n := by rwa [sub_eq_add_neg, coeff_add_eq_right_of_lt, coeff_neg] end Ring section NoZeroDivisors variable [Semiring R] {p q : R[X]} {a : R} @[simp] lemma nextCoeff_C_mul_X_add_C (ha : a ≠ 0) (c : R) : nextCoeff (C a * X + C c) = c := by rw [nextCoeff_of_natDegree_pos] <;> simp [ha] lemma natDegree_eq_one : p.natDegree = 1 ↔ ∃ a ≠ 0, ∃ b, C a * X + C b = p := by refine ⟨fun hp ↦ ⟨p.coeff 1, fun h ↦ ?_, p.coeff 0, ?_⟩, ?_⟩ · rw [← hp, coeff_natDegree, leadingCoeff_eq_zero] at h aesop · ext n obtain _ | _ | n := n · simp · simp · simp only [coeff_add, coeff_mul_X, coeff_C_succ, add_zero] rw [coeff_eq_zero_of_natDegree_lt] simp [hp] · rintro ⟨a, ha, b, rfl⟩ simp [ha] variable [NoZeroDivisors R] theorem degree_mul_C (a0 : a ≠ 0) : (p * C a).degree = p.degree := by rw [degree_mul, degree_C a0, add_zero] theorem degree_C_mul (a0 : a ≠ 0) : (C a * p).degree = p.degree := by rw [degree_mul, degree_C a0, zero_add] theorem natDegree_mul_C (a0 : a ≠ 0) : (p * C a).natDegree = p.natDegree := by simp only [natDegree, degree_mul_C a0] theorem natDegree_C_mul (a0 : a ≠ 0) : (C a * p).natDegree = p.natDegree := by simp only [natDegree, degree_C_mul a0] theorem natDegree_comp : natDegree (p.comp q) = natDegree p * natDegree q := by by_cases q0 : q.natDegree = 0 · rw [degree_le_zero_iff.mp (natDegree_eq_zero_iff_degree_le_zero.mp q0), comp_C, natDegree_C, natDegree_C, mul_zero] · by_cases p0 : p = 0 · simp only [p0, zero_comp, natDegree_zero, zero_mul] refine le_antisymm natDegree_comp_le (le_natDegree_of_ne_zero ?_) simp only [coeff_comp_degree_mul_degree q0, p0, mul_eq_zero, leadingCoeff_eq_zero, or_self_iff, ne_zero_of_natDegree_gt (Nat.pos_of_ne_zero q0), pow_ne_zero, Ne, not_false_iff] @[simp] theorem natDegree_iterate_comp (k : ℕ) : (p.comp^[k] q).natDegree = p.natDegree ^ k * q.natDegree := by induction' k with k IH · simp · rw [Function.iterate_succ_apply', natDegree_comp, IH, pow_succ', mul_assoc] theorem leadingCoeff_comp (hq : natDegree q ≠ 0) : leadingCoeff (p.comp q) = leadingCoeff p * leadingCoeff q ^ natDegree p := by rw [← coeff_comp_degree_mul_degree hq, ← natDegree_comp, coeff_natDegree] end NoZeroDivisors section DivisionRing variable {K : Type*} [DivisionRing K] /-! Useful lemmas for the "monicization" of a nonzero polynomial `p`. -/ @[simp] theorem irreducible_mul_leadingCoeff_inv {p : K[X]} : Irreducible (p * C (leadingCoeff p)⁻¹) ↔ Irreducible p := by by_cases hp0 : p = 0 · simp [hp0] exact irreducible_mul_isUnit (isUnit_C.mpr (IsUnit.mk0 _ (inv_ne_zero (leadingCoeff_ne_zero.mpr hp0)))) @[simp] lemma dvd_mul_leadingCoeff_inv {p q : K[X]} (hp0 : p ≠ 0) : q ∣ p * C (leadingCoeff p)⁻¹ ↔ q ∣ p := IsUnit.dvd_mul_right <| isUnit_C.mpr <| IsUnit.mk0 _ <| inv_ne_zero <| leadingCoeff_ne_zero.mpr hp0 theorem monic_mul_leadingCoeff_inv {p : K[X]} (h : p ≠ 0) : Monic (p * C (leadingCoeff p)⁻¹) := by rw [Monic, leadingCoeff_mul, leadingCoeff_C, mul_inv_cancel (show leadingCoeff p ≠ 0 from mt leadingCoeff_eq_zero.1 h)] -- `simp` normal form of `degree_mul_leadingCoeff_inv` @[simp] lemma degree_leadingCoeff_inv {p : K[X]} (hp0 : p ≠ 0) : degree (C (leadingCoeff p)⁻¹) = 0 := degree_C (inv_ne_zero <| leadingCoeff_ne_zero.mpr hp0) theorem degree_mul_leadingCoeff_inv (p : K[X]) {q : K[X]} (h : q ≠ 0) : degree (p * C (leadingCoeff q)⁻¹) = degree p := by have h₁ : (leadingCoeff q)⁻¹ ≠ 0 := inv_ne_zero (mt leadingCoeff_eq_zero.1 h) rw [degree_mul_C h₁] theorem natDegree_mul_leadingCoeff_inv (p : K[X]) {q : K[X]} (h : q ≠ 0) : natDegree (p * C (leadingCoeff q)⁻¹) = natDegree p := natDegree_eq_of_degree_eq (degree_mul_leadingCoeff_inv _ h) theorem degree_mul_leadingCoeff_self_inv (p : K[X]) : degree (p * C (leadingCoeff p)⁻¹) = degree p := by by_cases hp : p = 0 · simp [hp] exact degree_mul_leadingCoeff_inv _ hp theorem natDegree_mul_leadingCoeff_self_inv (p : K[X]) : natDegree (p * C (leadingCoeff p)⁻¹) = natDegree p := natDegree_eq_of_degree_eq (degree_mul_leadingCoeff_self_inv _) -- `simp` normal form of `degree_mul_leadingCoeff_self_inv` @[simp] lemma degree_add_degree_leadingCoeff_inv (p : K[X]) : degree p + degree (C (leadingCoeff p)⁻¹) = degree p := by rw [← degree_mul, degree_mul_leadingCoeff_self_inv] end DivisionRing end Polynomial
Algebra\Polynomial\Degree\TrailingDegree.lean
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Data.ENat.Basic /-! # Trailing degree of univariate polynomials ## Main definitions * `trailingDegree p`: the multiplicity of `X` in the polynomial `p` * `natTrailingDegree`: a variant of `trailingDegree` that takes values in the natural numbers * `trailingCoeff`: the coefficient at index `natTrailingDegree p` Converts most results about `degree`, `natDegree` and `leadingCoeff` to results about the bottom end of a polynomial -/ noncomputable section open Function Polynomial Finsupp Finset open scoped Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `trailingDegree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest `X`-exponent in `p`. `trailingDegree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears in `p`, otherwise `trailingDegree 0 = ⊤`. -/ def trailingDegree (p : R[X]) : ℕ∞ := p.support.min theorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q := InvImage.wf trailingDegree wellFounded_lt /-- `natTrailingDegree p` forces `trailingDegree p` to `ℕ`, by defining `natTrailingDegree ⊤ = 0`. -/ def natTrailingDegree (p : R[X]) : ℕ := ENat.toNat (trailingDegree p) /-- `trailingCoeff p` gives the coefficient of the smallest power of `X` in `p`-/ def trailingCoeff (p : R[X]) : R := coeff p (natTrailingDegree p) /-- a polynomial is `monic_at` if its trailing coefficient is 1 -/ def TrailingMonic (p : R[X]) := trailingCoeff p = (1 : R) theorem TrailingMonic.def : TrailingMonic p ↔ trailingCoeff p = 1 := Iff.rfl instance TrailingMonic.decidable [DecidableEq R] : Decidable (TrailingMonic p) := inferInstanceAs <| Decidable (trailingCoeff p = (1 : R)) @[simp] theorem TrailingMonic.trailingCoeff {p : R[X]} (hp : p.TrailingMonic) : trailingCoeff p = 1 := hp @[simp] theorem trailingDegree_zero : trailingDegree (0 : R[X]) = ⊤ := rfl @[simp] theorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 := rfl @[simp] theorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 := rfl @[simp] theorem trailingDegree_eq_top : trailingDegree p = ⊤ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]⟩ theorem trailingDegree_eq_natTrailingDegree (hp : p ≠ 0) : trailingDegree p = (natTrailingDegree p : ℕ∞) := .symm <| ENat.coe_toNat <| mt trailingDegree_eq_top.1 hp theorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.trailingDegree = n ↔ p.natTrailingDegree = n := by rw [trailingDegree_eq_natTrailingDegree hp, Nat.cast_inj] theorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : n ≠ 0) : p.trailingDegree = n ↔ p.natTrailingDegree = n := by rw [natTrailingDegree, ENat.toNat_eq_iff hn] theorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : ℕ} (h : trailingDegree p = n) : natTrailingDegree p = n := by simp [natTrailingDegree, h] @[simp] theorem natTrailingDegree_le_trailingDegree : ↑(natTrailingDegree p) ≤ trailingDegree p := ENat.coe_toNat_le_self _ theorem natTrailingDegree_eq_of_trailingDegree_eq [Semiring S] {q : S[X]} (h : trailingDegree p = trailingDegree q) : natTrailingDegree p = natTrailingDegree q := by unfold natTrailingDegree rw [h] theorem trailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : trailingDegree p ≤ n := min_le (mem_support_iff.2 h) theorem natTrailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : natTrailingDegree p ≤ n := ENat.toNat_le_of_le_coe <| trailingDegree_le_of_ne_zero h @[simp] lemma coeff_natTrailingDegree_eq_zero : coeff p p.natTrailingDegree = 0 ↔ p = 0 := by constructor · rintro h by_contra hp obtain ⟨n, hpn, hn⟩ := by simpa using min_mem_image_coe $ support_nonempty.2 hp obtain rfl := (trailingDegree_eq_iff_natTrailingDegree_eq hp).1 hn.symm exact hpn h · rintro rfl simp lemma coeff_natTrailingDegree_ne_zero : coeff p p.natTrailingDegree ≠ 0 ↔ p ≠ 0 := coeff_natTrailingDegree_eq_zero.not @[simp] lemma trailingDegree_eq_zero : trailingDegree p = 0 ↔ coeff p 0 ≠ 0 := Finset.min_eq_bot.trans mem_support_iff @[simp] lemma natTrailingDegree_eq_zero : natTrailingDegree p = 0 ↔ p = 0 ∨ coeff p 0 ≠ 0 := by simp [natTrailingDegree, or_comm] lemma natTrailingDegree_ne_zero : natTrailingDegree p ≠ 0 ↔ p ≠ 0 ∧ coeff p 0 = 0 := natTrailingDegree_eq_zero.not.trans $ by rw [not_or, not_ne_iff] lemma trailingDegree_ne_zero : trailingDegree p ≠ 0 ↔ coeff p 0 = 0 := trailingDegree_eq_zero.not_left @[simp] theorem trailingDegree_le_trailingDegree (h : coeff q (natTrailingDegree p) ≠ 0) : trailingDegree q ≤ trailingDegree p := (trailingDegree_le_of_ne_zero h).trans natTrailingDegree_le_trailingDegree theorem trailingDegree_ne_of_natTrailingDegree_ne {n : ℕ} : p.natTrailingDegree ≠ n → trailingDegree p ≠ n := mt fun h => by rw [natTrailingDegree, h, ENat.toNat_coe] theorem natTrailingDegree_le_of_trailingDegree_le {n : ℕ} {hp : p ≠ 0} (H : (n : ℕ∞) ≤ trailingDegree p) : n ≤ natTrailingDegree p := by rwa [trailingDegree_eq_natTrailingDegree hp, Nat.cast_le] at H theorem natTrailingDegree_le_natTrailingDegree (hq : q ≠ 0) (hpq : p.trailingDegree ≤ q.trailingDegree) : p.natTrailingDegree ≤ q.natTrailingDegree := ENat.toNat_le_toNat hpq <| by simpa @[simp] theorem trailingDegree_monomial (ha : a ≠ 0) : trailingDegree (monomial n a) = n := by rw [trailingDegree, support_monomial n ha, min_singleton] rfl theorem natTrailingDegree_monomial (ha : a ≠ 0) : natTrailingDegree (monomial n a) = n := by rw [natTrailingDegree, trailingDegree_monomial ha] rfl theorem natTrailingDegree_monomial_le : natTrailingDegree (monomial n a) ≤ n := letI := Classical.decEq R if ha : a = 0 then by simp [ha] else (natTrailingDegree_monomial ha).le theorem le_trailingDegree_monomial : ↑n ≤ trailingDegree (monomial n a) := letI := Classical.decEq R if ha : a = 0 then by simp [ha] else (trailingDegree_monomial ha).ge @[simp] theorem trailingDegree_C (ha : a ≠ 0) : trailingDegree (C a) = (0 : ℕ∞) := trailingDegree_monomial ha theorem le_trailingDegree_C : (0 : ℕ∞) ≤ trailingDegree (C a) := le_trailingDegree_monomial theorem trailingDegree_one_le : (0 : ℕ∞) ≤ trailingDegree (1 : R[X]) := by rw [← C_1] exact le_trailingDegree_C @[simp] theorem natTrailingDegree_C (a : R) : natTrailingDegree (C a) = 0 := nonpos_iff_eq_zero.1 natTrailingDegree_monomial_le @[simp] theorem natTrailingDegree_one : natTrailingDegree (1 : R[X]) = 0 := natTrailingDegree_C 1 @[simp] theorem natTrailingDegree_natCast (n : ℕ) : natTrailingDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natTrailingDegree_C] @[deprecated (since := "2024-04-17")] alias natTrailingDegree_nat_cast := natTrailingDegree_natCast @[simp] theorem trailingDegree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : trailingDegree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, trailingDegree_monomial ha] theorem le_trailingDegree_C_mul_X_pow (n : ℕ) (a : R) : (n : ℕ∞) ≤ trailingDegree (C a * X ^ n) := by rw [C_mul_X_pow_eq_monomial] exact le_trailingDegree_monomial theorem coeff_eq_zero_of_lt_trailingDegree (h : (n : ℕ∞) < trailingDegree p) : coeff p n = 0 := Classical.not_not.1 (mt trailingDegree_le_of_ne_zero (not_le_of_gt h)) theorem coeff_eq_zero_of_lt_natTrailingDegree {p : R[X]} {n : ℕ} (h : n < p.natTrailingDegree) : p.coeff n = 0 := by apply coeff_eq_zero_of_lt_trailingDegree by_cases hp : p = 0 · rw [hp, trailingDegree_zero] exact WithTop.coe_lt_top n · rw [trailingDegree_eq_natTrailingDegree hp] exact WithTop.coe_lt_coe.2 h @[simp] theorem coeff_natTrailingDegree_pred_eq_zero {p : R[X]} {hp : (0 : ℕ∞) < natTrailingDegree p} : p.coeff (p.natTrailingDegree - 1) = 0 := coeff_eq_zero_of_lt_natTrailingDegree <| Nat.sub_lt ((WithTop.zero_lt_coe (natTrailingDegree p)).mp hp) Nat.one_pos theorem le_trailingDegree_X_pow (n : ℕ) : (n : ℕ∞) ≤ trailingDegree (X ^ n : R[X]) := by simpa only [C_1, one_mul] using le_trailingDegree_C_mul_X_pow n (1 : R) theorem le_trailingDegree_X : (1 : ℕ∞) ≤ trailingDegree (X : R[X]) := le_trailingDegree_monomial theorem natTrailingDegree_X_le : (X : R[X]).natTrailingDegree ≤ 1 := natTrailingDegree_monomial_le @[simp] theorem trailingCoeff_eq_zero : trailingCoeff p = 0 ↔ p = 0 := ⟨fun h => _root_.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_min (trailingDegree_eq_natTrailingDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ theorem trailingCoeff_nonzero_iff_nonzero : trailingCoeff p ≠ 0 ↔ p ≠ 0 := not_congr trailingCoeff_eq_zero theorem natTrailingDegree_mem_support_of_nonzero : p ≠ 0 → natTrailingDegree p ∈ p.support := mem_support_iff.mpr ∘ trailingCoeff_nonzero_iff_nonzero.mpr theorem natTrailingDegree_le_of_mem_supp (a : ℕ) : a ∈ p.support → natTrailingDegree p ≤ a := natTrailingDegree_le_of_ne_zero ∘ mem_support_iff.mp theorem natTrailingDegree_eq_support_min' (h : p ≠ 0) : natTrailingDegree p = p.support.min' (nonempty_support_iff.mpr h) := by rw [natTrailingDegree, trailingDegree, ← Finset.coe_min', ENat.some_eq_coe, ENat.toNat_coe] theorem le_natTrailingDegree (hp : p ≠ 0) (hn : ∀ m < n, p.coeff m = 0) : n ≤ p.natTrailingDegree := by rw [natTrailingDegree_eq_support_min' hp] exact Finset.le_min' _ _ _ fun m hm => not_lt.1 fun hmn => mem_support_iff.1 hm <| hn _ hmn theorem natTrailingDegree_le_natDegree (p : R[X]) : p.natTrailingDegree ≤ p.natDegree := by by_cases hp : p = 0 · rw [hp, natDegree_zero, natTrailingDegree_zero] · exact le_natDegree_of_ne_zero (mt trailingCoeff_eq_zero.mp hp) theorem natTrailingDegree_mul_X_pow {p : R[X]} (hp : p ≠ 0) (n : ℕ) : (p * X ^ n).natTrailingDegree = p.natTrailingDegree + n := by apply le_antisymm · refine natTrailingDegree_le_of_ne_zero fun h => mt trailingCoeff_eq_zero.mp hp ?_ rwa [trailingCoeff, ← coeff_mul_X_pow] · rw [natTrailingDegree_eq_support_min' fun h => hp (mul_X_pow_eq_zero h), Finset.le_min'_iff] intro y hy have key : n ≤ y := by rw [mem_support_iff, coeff_mul_X_pow'] at hy exact by_contra fun h => hy (if_neg h) rw [mem_support_iff, coeff_mul_X_pow', if_pos key] at hy exact (le_tsub_iff_right key).mp (natTrailingDegree_le_of_ne_zero hy) theorem le_trailingDegree_mul : p.trailingDegree + q.trailingDegree ≤ (p * q).trailingDegree := by refine Finset.le_min fun n hn => ?_ rw [mem_support_iff, coeff_mul] at hn obtain ⟨⟨i, j⟩, hij, hpq⟩ := exists_ne_zero_of_sum_ne_zero hn refine (add_le_add (min_le (mem_support_iff.mpr (left_ne_zero_of_mul hpq))) (min_le (mem_support_iff.mpr (right_ne_zero_of_mul hpq)))).trans (le_of_eq ?_) rwa [← WithTop.coe_add, WithTop.coe_eq_coe, ← mem_antidiagonal] theorem le_natTrailingDegree_mul (h : p * q ≠ 0) : p.natTrailingDegree + q.natTrailingDegree ≤ (p * q).natTrailingDegree := by have hp : p ≠ 0 := fun hp => h (by rw [hp, zero_mul]) have hq : q ≠ 0 := fun hq => h (by rw [hq, mul_zero]) -- Porting note: Needed to account for different coercion behaviour & add the lemma below have : ∀ (p : R[X]), WithTop.some (natTrailingDegree p) = Nat.cast (natTrailingDegree p) := fun p ↦ rfl rw [← WithTop.coe_le_coe, WithTop.coe_add, this p, this q, this (p * q), ← trailingDegree_eq_natTrailingDegree hp, ← trailingDegree_eq_natTrailingDegree hq, ← trailingDegree_eq_natTrailingDegree h] exact le_trailingDegree_mul theorem coeff_mul_natTrailingDegree_add_natTrailingDegree : (p * q).coeff (p.natTrailingDegree + q.natTrailingDegree) = p.trailingCoeff * q.trailingCoeff := by rw [coeff_mul] refine Finset.sum_eq_single (p.natTrailingDegree, q.natTrailingDegree) ?_ fun h => (h (mem_antidiagonal.mpr rfl)).elim rintro ⟨i, j⟩ h₁ h₂ rw [mem_antidiagonal] at h₁ by_cases hi : i < p.natTrailingDegree · rw [coeff_eq_zero_of_lt_natTrailingDegree hi, zero_mul] by_cases hj : j < q.natTrailingDegree · rw [coeff_eq_zero_of_lt_natTrailingDegree hj, mul_zero] rw [not_lt] at hi hj refine (h₂ (Prod.ext_iff.mpr ?_).symm).elim exact (add_eq_add_iff_eq_and_eq hi hj).mp h₁.symm theorem trailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) : (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul]) have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero]) refine le_antisymm ?_ le_trailingDegree_mul rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, ← ENat.coe_add] apply trailingDegree_le_of_ne_zero rwa [coeff_mul_natTrailingDegree_add_natTrailingDegree] theorem natTrailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) : (p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree := by have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul]) have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero]) -- Porting note: Needed to account for different coercion behaviour & add the lemmas below have aux1 : ∀ n, Nat.cast n = WithTop.some (n) := fun n ↦ rfl have aux2 : ∀ (p : R[X]), WithTop.some (natTrailingDegree p) = Nat.cast (natTrailingDegree p) := fun p ↦ rfl apply natTrailingDegree_eq_of_trailingDegree_eq_some rw [trailingDegree_mul' h, aux1 (natTrailingDegree p + natTrailingDegree q), WithTop.coe_add, aux2 p, aux2 q, ← trailingDegree_eq_natTrailingDegree hp, ← trailingDegree_eq_natTrailingDegree hq] theorem natTrailingDegree_mul [NoZeroDivisors R] (hp : p ≠ 0) (hq : q ≠ 0) : (p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree := natTrailingDegree_mul' (mul_ne_zero (mt trailingCoeff_eq_zero.mp hp) (mt trailingCoeff_eq_zero.mp hq)) end Semiring section NonzeroSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} @[simp] theorem trailingDegree_one : trailingDegree (1 : R[X]) = (0 : ℕ∞) := trailingDegree_C one_ne_zero @[simp] theorem trailingDegree_X : trailingDegree (X : R[X]) = 1 := trailingDegree_monomial one_ne_zero @[simp] theorem natTrailingDegree_X : (X : R[X]).natTrailingDegree = 1 := natTrailingDegree_monomial one_ne_zero @[simp] lemma trailingDegree_X_pow (n : ℕ) : (X ^ n : R[X]).trailingDegree = n := by rw [X_pow_eq_monomial, trailingDegree_monomial one_ne_zero] @[simp] lemma natTrailingDegree_X_pow (n : ℕ) : (X ^ n : R[X]).natTrailingDegree = n := by rw [X_pow_eq_monomial, natTrailingDegree_monomial one_ne_zero] end NonzeroSemiring section Ring variable [Ring R] @[simp] theorem trailingDegree_neg (p : R[X]) : trailingDegree (-p) = trailingDegree p := by unfold trailingDegree rw [support_neg] @[simp] theorem natTrailingDegree_neg (p : R[X]) : natTrailingDegree (-p) = natTrailingDegree p := by simp [natTrailingDegree] @[simp] theorem natTrailingDegree_intCast (n : ℤ) : natTrailingDegree (n : R[X]) = 0 := by simp only [← C_eq_intCast, natTrailingDegree_C] @[deprecated (since := "2024-04-17")] alias natTrailingDegree_int_cast := natTrailingDegree_intCast end Ring section Semiring variable [Semiring R] /-- The second-lowest coefficient, or 0 for constants -/ def nextCoeffUp (p : R[X]) : R := if p.natTrailingDegree = 0 then 0 else p.coeff (p.natTrailingDegree + 1) @[simp] lemma nextCoeffUp_zero : nextCoeffUp (0 : R[X]) = 0 := by simp [nextCoeffUp] @[simp] theorem nextCoeffUp_C_eq_zero (c : R) : nextCoeffUp (C c) = 0 := by rw [nextCoeffUp] simp theorem nextCoeffUp_of_constantCoeff_eq_zero (p : R[X]) (hp : coeff p 0 = 0) : nextCoeffUp p = p.coeff (p.natTrailingDegree + 1) := by obtain rfl | hp₀ := eq_or_ne p 0 · simp · rw [nextCoeffUp, if_neg (natTrailingDegree_ne_zero.2 ⟨hp₀, hp⟩)] end Semiring section Semiring variable [Semiring R] {p q : R[X]} theorem coeff_natTrailingDegree_eq_zero_of_trailingDegree_lt (h : trailingDegree p < trailingDegree q) : coeff q (natTrailingDegree p) = 0 := coeff_eq_zero_of_lt_trailingDegree <| natTrailingDegree_le_trailingDegree.trans_lt h theorem ne_zero_of_trailingDegree_lt {n : ℕ∞} (h : trailingDegree p < n) : p ≠ 0 := fun h₀ => h.not_le (by simp [h₀]) lemma natTrailingDegree_eq_zero_of_constantCoeff_ne_zero (h : constantCoeff p ≠ 0) : p.natTrailingDegree = 0 := le_antisymm (natTrailingDegree_le_of_ne_zero h) zero_le' namespace Monic lemma eq_X_pow_iff_natDegree_le_natTrailingDegree (h₁ : p.Monic) : p = X ^ p.natDegree ↔ p.natDegree ≤ p.natTrailingDegree := by refine ⟨fun h => ?_, fun h => ?_⟩ · nontriviality R rw [h, natTrailingDegree_X_pow, ← h] · ext n rw [coeff_X_pow] obtain hn | rfl | hn := lt_trichotomy n p.natDegree · rw [if_neg hn.ne, coeff_eq_zero_of_lt_natTrailingDegree (hn.trans_le h)] · simpa only [if_pos rfl] using h₁.leadingCoeff · rw [if_neg hn.ne', coeff_eq_zero_of_natDegree_lt hn] lemma eq_X_pow_iff_natTrailingDegree_eq_natDegree (h₁ : p.Monic) : p = X ^ p.natDegree ↔ p.natTrailingDegree = p.natDegree := h₁.eq_X_pow_iff_natDegree_le_natTrailingDegree.trans (natTrailingDegree_le_natDegree p).ge_iff_eq @[deprecated (since := "2024-04-26")] alias ⟨_, eq_X_pow_of_natTrailingDegree_eq_natDegree⟩ := eq_X_pow_iff_natTrailingDegree_eq_natDegree end Monic end Semiring end Polynomial
Algebra\Polynomial\Module\AEval.lean
/- Copyright (c) 2022 Richard M. Hill. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Richard M. Hill -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.RingTheory.Finiteness /-! # Action of the polynomial ring on module induced by an algebra element. Given an element `a` in an `R`-algebra `A` and an `A`-module `M` we define an `R[X]`-module `Module.AEval R M a`, which is a type synonym of `M` with the action of a polynomial `f` given by `f • m = Polynomial.aeval a f • m`. In particular `X • m = a • m`. In the special case that `A = M →ₗ[R] M` and `φ : M →ₗ[R] M`, the module `Module.AEval R M a` is abbreviated `Module.AEval' φ`. In this module we have `X • m = ↑φ m`. -/ open Set Function Polynomial namespace Module /-- Suppose `a` is an element of an `R`-algebra `A` and `M` is an `A`-module. Loosely speaking, `Module.AEval R M a` is the `R[X]`-module with elements `m : M`, where the action of a polynomial $f$ is given by $f • m = f(a) • m$. More precisely, `Module.AEval R M a` has elements `Module.AEval.of R M a m` for `m : M`, and the action of `f` is `f • (of R M a m) = of R M a ((aeval a f) • m)`. -/ @[nolint unusedArguments] def AEval (R M : Type*) {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] (_ : A) := M instance AEval.instAddCommGroup {R A M} [CommSemiring R] [Semiring A] (a : A) [Algebra R A] [AddCommGroup M] [Module A M] [Module R M] [IsScalarTower R A M] : AddCommGroup <| AEval R M a := inferInstanceAs (AddCommGroup M) variable {R A M} [CommSemiring R] [Semiring A] (a : A) [Algebra R A] [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] namespace AEval instance instAddCommMonoid : AddCommMonoid <| AEval R M a := inferInstanceAs (AddCommMonoid M) instance instModuleOrig : Module R <| AEval R M a := inferInstanceAs (Module R M) instance instFiniteOrig [Finite R M] : Finite R <| AEval R M a := inferInstanceAs (Finite R M) instance instModulePolynomial : Module R[X] <| AEval R M a := compHom M (aeval a).toRingHom variable (R M) /-- The canonical linear equivalence between `M` and `Module.AEval R M a` as an `R`-module. -/ def of : M ≃ₗ[R] AEval R M a := LinearEquiv.refl _ _ variable {R M} lemma of_aeval_smul (f : R[X]) (m : M) : of R M a (aeval a f • m) = f • of R M a m := rfl @[simp] lemma of_symm_smul (f : R[X]) (m : AEval R M a) : (of R M a).symm (f • m) = aeval a f • (of R M a).symm m := rfl @[simp] lemma C_smul (t : R) (m : AEval R M a) : C t • m = t • m := (of R M a).symm.injective <| by simp lemma X_smul_of (m : M) : (X : R[X]) • (of R M a m) = of R M a (a • m) := by rw [← of_aeval_smul, aeval_X] lemma of_symm_X_smul (m : AEval R M a) : (of R M a).symm ((X : R[X]) • m) = a • (of R M a).symm m := by rw [of_symm_smul, aeval_X] instance instIsScalarTowerOrigPolynomial : IsScalarTower R R[X] <| AEval R M a where smul_assoc r f m := by apply (of R M a).symm.injective rw [of_symm_smul, map_smul, smul_assoc, map_smul, of_symm_smul] instance instFinitePolynomial [Finite R M] : Finite R[X] <| AEval R M a := Finite.of_restrictScalars_finite R _ _ /-- Construct an `R[X]`-linear map out of `AEval R M a` from a `R`-linear map out of `M`. -/ def _root_.LinearMap.ofAEval {N} [AddCommMonoid N] [Module R N] [Module R[X] N] [IsScalarTower R R[X] N] (f : M →ₗ[R] N) (hf : ∀ m : M, f (a • m) = (X : R[X]) • f m) : AEval R M a →ₗ[R[X]] N where __ := f ∘ₗ (of R M a).symm map_smul' p := p.induction_on (fun k m ↦ by simp [C_eq_algebraMap]) (fun p q hp hq m ↦ by simp_all [add_smul]) fun n k h m ↦ by simp_rw [RingHom.id_apply, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearMap.comp_apply, LinearEquiv.coe_toLinearMap] at h ⊢ simp_rw [pow_succ, ← mul_assoc, mul_smul _ X, ← hf, ← of_symm_X_smul, ← h] lemma annihilator_eq_ker_aeval [FaithfulSMul A M] : annihilator R[X] (AEval R M a) = RingHom.ker (aeval a) := by ext p simp_rw [mem_annihilator, RingHom.mem_ker] change (∀ m : M, aeval a p • m = 0) ↔ _ exact ⟨fun h ↦ eq_of_smul_eq_smul (α := M) <| by simp [h], fun h ↦ by simp [h]⟩ @[simp] lemma annihilator_top_eq_ker_aeval [FaithfulSMul A M] : (⊤ : Submodule R[X] <| AEval R M a).annihilator = RingHom.ker (aeval a) := by ext p simp only [Submodule.mem_annihilator, Submodule.mem_top, forall_true_left, RingHom.mem_ker] change (∀ m : M, aeval a p • m = 0) ↔ _ exact ⟨fun h ↦ eq_of_smul_eq_smul (α := M) <| by simp [h], fun h ↦ by simp [h]⟩ section Submodule variable {p : Submodule R M} (hp : p ≤ p.comap (Algebra.lsmul R R M a)) {q : Submodule R[X] <| AEval R M a} variable (R M) in /-- We can turn an `R[X]`-submodule into an `R`-submodule by forgetting the action of `X`. -/ def comapSubmodule : CompleteLatticeHom (Submodule R[X] <| AEval R M a) (Submodule R M) := (Submodule.orderIsoMapComap (of R M a)).symm.toCompleteLatticeHom.comp <| Submodule.restrictScalarsLatticeHom R R[X] (AEval R M a) @[simp] lemma mem_comapSubmodule {x : M} : x ∈ comapSubmodule R M a q ↔ of R M a x ∈ q := Iff.rfl @[simp] lemma comapSubmodule_le_comap : comapSubmodule R M a q ≤ (comapSubmodule R M a q).comap (Algebra.lsmul R R M a) := by intro m hm simpa only [Submodule.mem_comap, Algebra.lsmul_coe, mem_comapSubmodule, ← X_smul_of] using q.smul_mem (X : R[X]) hm /-- An `R`-submodule which is stable under the action of `a` can be promoted to an `R[X]`-submodule. -/ def mapSubmodule : Submodule R[X] <| AEval R M a := { toAddSubmonoid := p.toAddSubmonoid.map (of R M a) smul_mem' := by rintro f - ⟨m : M, h : m ∈ p, rfl⟩ simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, AddSubmonoid.mem_map, Submodule.mem_toAddSubmonoid] exact ⟨aeval a f • m, aeval_apply_smul_mem_of_le_comap' h f a hp, of_aeval_smul a f m⟩ } @[simp] lemma mem_mapSubmodule {m : AEval R M a} : m ∈ mapSubmodule a hp ↔ (of R M a).symm m ∈ p := ⟨fun ⟨_, hm, hm'⟩ ↦ hm'.symm ▸ hm, fun hm ↦ ⟨(of R M a).symm m, hm, rfl⟩⟩ @[simp] lemma mapSubmodule_comapSubmodule (h := comapSubmodule_le_comap a) : mapSubmodule a (p := comapSubmodule R M a q) h = q := by ext; simp @[simp] lemma comapSubmodule_mapSubmodule : comapSubmodule R M a (mapSubmodule a hp) = p := by ext; simp variable (R M) lemma injective_comapSubmodule : Injective (comapSubmodule R M a) := by intro q₁ q₂ hq rw [← mapSubmodule_comapSubmodule (q := q₁), ← mapSubmodule_comapSubmodule (q := q₂)] simp_rw [hq] lemma range_comapSubmodule : range (comapSubmodule R M a) = {p | p ≤ p.comap (Algebra.lsmul R R M a)} := le_antisymm (fun _ ⟨_, hq⟩ ↦ hq ▸ comapSubmodule_le_comap a) (fun _ hp ↦ ⟨mapSubmodule a hp, comapSubmodule_mapSubmodule a hp⟩) end Submodule end AEval variable (φ : M →ₗ[R] M) /-- Given and `R`-module `M` and a linear map `φ : M →ₗ[R] M`, `Module.AEval' φ` is loosely speaking the `R[X]`-module with elements `m : M`, where the action of a polynomial $f$ is given by $f • m = f(a) • m$. More precisely, `Module.AEval' φ` has elements `Module.AEval'.of φ m` for `m : M`, and the action of `f` is `f • (of φ m) = of φ ((aeval φ f) • m)`. `Module.AEval'` is defined as a special case of `Module.AEval` in which the `R`-algebra is `M →ₗ[R] M`. Lemmas involving `Module.AEval` may be applied to `Module.AEval'`. -/ abbrev AEval' := AEval R M φ /-- The canonical linear equivalence between `M` and `Module.AEval' φ` as an `R`-module, where `φ : M →ₗ[R] M`. -/ abbrev AEval'.of : M ≃ₗ[R] AEval' φ := AEval.of R M φ lemma AEval'_def : AEval' φ = AEval R M φ := rfl lemma AEval'.X_smul_of (m : M) : (X : R[X]) • AEval'.of φ m = AEval'.of φ (φ m) := AEval.X_smul_of _ _ lemma AEval'.of_symm_X_smul (m : AEval' φ) : (AEval'.of φ).symm ((X : R[X]) • m) = φ ((AEval'.of φ).symm m) := AEval.of_symm_X_smul _ _ instance [Finite R M] : Finite R[X] <| AEval' φ := inferInstance end Module
Algebra\Polynomial\Module\Basic.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Polynomial.Module.AEval /-! # Polynomial module In this file, we define the polynomial module for an `R`-module `M`, i.e. the `R[X]`-module `M[X]`. This is defined as a type alias `PolynomialModule R M := ℕ →₀ M`, since there might be different module structures on `ℕ →₀ M` of interest. See the docstring of `PolynomialModule` for details. -/ universe u v open Polynomial BigOperators /-- The `R[X]`-module `M[X]` for an `R`-module `M`. This is isomorphic (as an `R`-module) to `M[X]` when `M` is a ring. We require all the module instances `Module S (PolynomialModule R M)` to factor through `R` except `Module R[X] (PolynomialModule R M)`. In this constraint, we have the following instances for example : - `R` acts on `PolynomialModule R R[X]` - `R[X]` acts on `PolynomialModule R R[X]` as `R[Y]` acting on `R[X][Y]` - `R` acts on `PolynomialModule R[X] R[X]` - `R[X]` acts on `PolynomialModule R[X] R[X]` as `R[X]` acting on `R[X][Y]` - `R[X][X]` acts on `PolynomialModule R[X] R[X]` as `R[X][Y]` acting on itself This is also the reason why `R` is included in the alias, or else there will be two different instances of `Module R[X] (PolynomialModule R[X])`. See https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2315065.20polynomial.20modules for the full discussion. -/ @[nolint unusedArguments] def PolynomialModule (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] := ℕ →₀ M variable (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R) -- Porting note: stated instead of deriving noncomputable instance : Inhabited (PolynomialModule R M) := Finsupp.instInhabited noncomputable instance : AddCommGroup (PolynomialModule R M) := Finsupp.instAddCommGroup variable {M} variable {S : Type*} [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] namespace PolynomialModule /-- This is required to have the `IsScalarTower S R M` instance to avoid diamonds. -/ @[nolint unusedArguments] noncomputable instance : Module S (PolynomialModule R M) := Finsupp.module ℕ M instance instFunLike : FunLike (PolynomialModule R M) ℕ M := Finsupp.instFunLike instance : CoeFun (PolynomialModule R M) fun _ => ℕ → M := Finsupp.instCoeFun theorem zero_apply (i : ℕ) : (0 : PolynomialModule R M) i = 0 := Finsupp.zero_apply theorem add_apply (g₁ g₂ : PolynomialModule R M) (a : ℕ) : (g₁ + g₂) a = g₁ a + g₂ a := Finsupp.add_apply g₁ g₂ a /-- The monomial `m * x ^ i`. This is defeq to `Finsupp.singleAddHom`, and is redefined here so that it has the desired type signature. -/ noncomputable def single (i : ℕ) : M →+ PolynomialModule R M := Finsupp.singleAddHom i theorem single_apply (i : ℕ) (m : M) (n : ℕ) : single R i m n = ite (i = n) m 0 := Finsupp.single_apply /-- `PolynomialModule.single` as a linear map. -/ noncomputable def lsingle (i : ℕ) : M →ₗ[R] PolynomialModule R M := Finsupp.lsingle i theorem lsingle_apply (i : ℕ) (m : M) (n : ℕ) : lsingle R i m n = ite (i = n) m 0 := Finsupp.single_apply theorem single_smul (i : ℕ) (r : R) (m : M) : single R i (r • m) = r • single R i m := (lsingle R i).map_smul r m variable {R} theorem induction_linear {P : PolynomialModule R M → Prop} (f : PolynomialModule R M) (h0 : P 0) (hadd : ∀ f g, P f → P g → P (f + g)) (hsingle : ∀ a b, P (single R a b)) : P f := Finsupp.induction_linear f h0 hadd hsingle noncomputable instance polynomialModule : Module R[X] (PolynomialModule R M) := inferInstanceAs (Module R[X] (Module.AEval' (Finsupp.lmapDomain M R Nat.succ))) lemma smul_def (f : R[X]) (m : PolynomialModule R M) : f • m = aeval (Finsupp.lmapDomain M R Nat.succ) f m := by rfl instance (M : Type u) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower S R M] : IsScalarTower S R (PolynomialModule R M) := Finsupp.isScalarTower _ _ instance isScalarTower' (M : Type u) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower S R M] : IsScalarTower S R[X] (PolynomialModule R M) := by haveI : IsScalarTower R R[X] (PolynomialModule R M) := inferInstanceAs <| IsScalarTower R R[X] <| Module.AEval' <| Finsupp.lmapDomain M R Nat.succ constructor intro x y z rw [← @IsScalarTower.algebraMap_smul S R, ← @IsScalarTower.algebraMap_smul S R, smul_assoc] @[simp] theorem monomial_smul_single (i : ℕ) (r : R) (j : ℕ) (m : M) : monomial i r • single R j m = single R (i + j) (r • m) := by simp only [LinearMap.mul_apply, Polynomial.aeval_monomial, LinearMap.pow_apply, Module.algebraMap_end_apply, smul_def] induction i generalizing r j m with | zero => rw [Function.iterate_zero, zero_add] exact Finsupp.smul_single r j m | succ n hn => rw [Function.iterate_succ, Function.comp_apply, add_assoc, ← hn] congr 2 rw [Nat.one_add] exact Finsupp.mapDomain_single @[simp] theorem monomial_smul_apply (i : ℕ) (r : R) (g : PolynomialModule R M) (n : ℕ) : (monomial i r • g) n = ite (i ≤ n) (r • g (n - i)) 0 := by induction' g using PolynomialModule.induction_linear with p q hp hq · simp only [smul_zero, zero_apply, ite_self] · simp only [smul_add, add_apply, hp, hq] split_ifs exacts [rfl, zero_add 0] · rw [monomial_smul_single, single_apply, single_apply, smul_ite, smul_zero, ← ite_and] congr rw [eq_iff_iff] constructor · rintro rfl simp · rintro ⟨e, rfl⟩ rw [add_comm, tsub_add_cancel_of_le e] @[simp] theorem smul_single_apply (i : ℕ) (f : R[X]) (m : M) (n : ℕ) : (f • single R i m) n = ite (i ≤ n) (f.coeff (n - i) • m) 0 := by induction' f using Polynomial.induction_on' with p q hp hq · rw [add_smul, Finsupp.add_apply, hp, hq, coeff_add, add_smul] split_ifs exacts [rfl, zero_add 0] · rw [monomial_smul_single, single_apply, coeff_monomial, ite_smul, zero_smul] by_cases h : i ≤ n · simp_rw [eq_tsub_iff_add_eq_of_le h, if_pos h] · rw [if_neg h, ite_eq_right_iff] intro e exfalso linarith theorem smul_apply (f : R[X]) (g : PolynomialModule R M) (n : ℕ) : (f • g) n = ∑ x ∈ Finset.antidiagonal n, f.coeff x.1 • g x.2 := by induction' f using Polynomial.induction_on' with p q hp hq f_n f_a · rw [add_smul, Finsupp.add_apply, hp, hq, ← Finset.sum_add_distrib] congr ext rw [coeff_add, add_smul] · rw [Finset.Nat.sum_antidiagonal_eq_sum_range_succ fun i j => (monomial f_n f_a).coeff i • g j, monomial_smul_apply] simp_rw [Polynomial.coeff_monomial, ← Finset.mem_range_succ_iff] rw [← Finset.sum_ite_eq (Finset.range (Nat.succ n)) f_n (fun x => f_a • g (n - x))] congr ext x split_ifs exacts [rfl, (zero_smul R _).symm] /-- `PolynomialModule R R` is isomorphic to `R[X]` as an `R[X]` module. -/ noncomputable def equivPolynomialSelf : PolynomialModule R R ≃ₗ[R[X]] R[X] := { (Polynomial.toFinsuppIso R).symm with map_smul' := fun r x => by dsimp rw [← RingEquiv.coe_toEquiv_symm, RingEquiv.coe_toEquiv] induction' x using induction_linear with _ _ hp hq n a · rw [smul_zero, map_zero, mul_zero] · rw [smul_add, map_add, map_add, mul_add, hp, hq] · ext i simp only [coeff_ofFinsupp, smul_single_apply, toFinsuppIso_symm_apply, coeff_ofFinsupp, single_apply, smul_eq_mul, Polynomial.coeff_mul, mul_ite, mul_zero] split_ifs with hn · rw [Finset.sum_eq_single (i - n, n)] · simp only [ite_true] · rintro ⟨p, q⟩ hpq1 hpq2 rw [Finset.mem_antidiagonal] at hpq1 split_ifs with H · dsimp at H exfalso apply hpq2 rw [← hpq1, H] simp only [add_le_iff_nonpos_left, nonpos_iff_eq_zero, add_tsub_cancel_right] · rfl · intro H exfalso apply H rw [Finset.mem_antidiagonal, tsub_add_cancel_of_le hn] · symm rw [Finset.sum_ite_of_false, Finset.sum_const_zero] simp_rw [Finset.mem_antidiagonal] intro x hx contrapose! hn rw [add_comm, ← hn] at hx exact Nat.le.intro hx } /-- `PolynomialModule R S` is isomorphic to `S[X]` as an `R` module. -/ noncomputable def equivPolynomial {S : Type*} [CommRing S] [Algebra R S] : PolynomialModule R S ≃ₗ[R] S[X] := { (Polynomial.toFinsuppIso S).symm with map_smul' := fun _ _ => rfl } @[simp] lemma equivPolynomialSelf_apply_eq (p : PolynomialModule R R) : equivPolynomialSelf p = equivPolynomial p := rfl @[simp] lemma equivPolynomial_single {S : Type*} [CommRing S] [Algebra R S] (n : ℕ) (x : S) : equivPolynomial (single R n x) = monomial n x := rfl variable (R' : Type*) {M' : Type*} [CommRing R'] [AddCommGroup M'] [Module R' M'] variable [Module R M'] /-- The image of a polynomial under a linear map. -/ noncomputable def map (f : M →ₗ[R] M') : PolynomialModule R M →ₗ[R] PolynomialModule R' M' := Finsupp.mapRange.linearMap f @[simp] theorem map_single (f : M →ₗ[R] M') (i : ℕ) (m : M) : map R' f (single R i m) = single R' i (f m) := Finsupp.mapRange_single (hf := f.map_zero) variable [Algebra R R'] [IsScalarTower R R' M'] theorem map_smul (f : M →ₗ[R] M') (p : R[X]) (q : PolynomialModule R M) : map R' f (p • q) = p.map (algebraMap R R') • map R' f q := by apply induction_linear q · rw [smul_zero, map_zero, smul_zero] · intro f g e₁ e₂ rw [smul_add, map_add, e₁, e₂, map_add, smul_add] intro i m induction' p using Polynomial.induction_on' with _ _ e₁ e₂ · rw [add_smul, map_add, e₁, e₂, Polynomial.map_add, add_smul] · rw [monomial_smul_single, map_single, Polynomial.map_monomial, map_single, monomial_smul_single, f.map_smul, algebraMap_smul] /-- Evaluate a polynomial `p : PolynomialModule R M` at `r : R`. -/ @[simps! (config := .lemmasOnly)] def eval (r : R) : PolynomialModule R M →ₗ[R] M where toFun p := p.sum fun i m => r ^ i • m map_add' x y := Finsupp.sum_add_index' (fun _ => smul_zero _) fun _ _ _ => smul_add _ _ _ map_smul' s m := by refine (Finsupp.sum_smul_index' ?_).trans ?_ · exact fun i => smul_zero _ · simp_rw [RingHom.id_apply, Finsupp.smul_sum] congr ext i c rw [smul_comm] @[simp] theorem eval_single (r : R) (i : ℕ) (m : M) : eval r (single R i m) = r ^ i • m := Finsupp.sum_single_index (smul_zero _) @[simp] theorem eval_lsingle (r : R) (i : ℕ) (m : M) : eval r (lsingle R i m) = r ^ i • m := eval_single r i m theorem eval_smul (p : R[X]) (q : PolynomialModule R M) (r : R) : eval r (p • q) = p.eval r • eval r q := by apply induction_linear q · rw [smul_zero, map_zero, smul_zero] · intro f g e₁ e₂ rw [smul_add, map_add, e₁, e₂, map_add, smul_add] intro i m induction' p using Polynomial.induction_on' with _ _ e₁ e₂ · rw [add_smul, map_add, Polynomial.eval_add, e₁, e₂, add_smul] · rw [monomial_smul_single, eval_single, Polynomial.eval_monomial, eval_single, smul_comm, ← smul_smul, pow_add, mul_smul] @[simp] theorem eval_map (f : M →ₗ[R] M') (q : PolynomialModule R M) (r : R) : eval (algebraMap R R' r) (map R' f q) = f (eval r q) := by apply induction_linear q · simp_rw [map_zero] · intro f g e₁ e₂ simp_rw [map_add, e₁, e₂] · intro i m rw [map_single, eval_single, eval_single, f.map_smul, ← map_pow, algebraMap_smul] @[simp] theorem eval_map' (f : M →ₗ[R] M) (q : PolynomialModule R M) (r : R) : eval r (map R f q) = f (eval r q) := eval_map R f q r @[simp] lemma aeval_equivPolynomial {S : Type*} [CommRing S] [Algebra S R] (f : PolynomialModule S S) (x : R) : aeval x (equivPolynomial f) = eval x (map R (Algebra.linearMap S R) f) := by apply induction_linear f · simp · intro f g e₁ e₂ simp_rw [map_add, e₁, e₂] · intro i m rw [equivPolynomial_single, aeval_monomial, mul_comm, map_single, Algebra.linearMap_apply, eval_single, smul_eq_mul] /-- `comp p q` is the composition of `p : R[X]` and `q : M[X]` as `q(p(x))`. -/ @[simps!] noncomputable def comp (p : R[X]) : PolynomialModule R M →ₗ[R] PolynomialModule R M := LinearMap.comp ((eval p).restrictScalars R) (map R[X] (lsingle R 0)) theorem comp_single (p : R[X]) (i : ℕ) (m : M) : comp p (single R i m) = p ^ i • single R 0 m := by rw [comp_apply] erw [map_single, eval_single] rfl theorem comp_eval (p : R[X]) (q : PolynomialModule R M) (r : R) : eval r (comp p q) = eval (p.eval r) q := by rw [← LinearMap.comp_apply] apply induction_linear q · simp_rw [map_zero] · intro _ _ e₁ e₂ simp_rw [map_add, e₁, e₂] · intro i m rw [LinearMap.comp_apply, comp_single, eval_single, eval_smul, eval_single, pow_zero, one_smul, Polynomial.eval_pow] theorem comp_smul (p p' : R[X]) (q : PolynomialModule R M) : comp p (p' • q) = p'.comp p • comp p q := by rw [comp_apply, map_smul, eval_smul, Polynomial.comp, Polynomial.eval_map, comp_apply] rfl end PolynomialModule
Algebra\Polynomial\Module\FiniteDimensional.lean
/- Copyright (c) 2024 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.FieldTheory.Minpoly.Field import Mathlib.Algebra.Polynomial.Module.AEval /-! # Polynomial modules in finite dimensions This file is a place to collect results about the `R[X]`-module structure induced on an `R`-module by an `R`-linear endomorphism, which require the concept of finite-dimensionality. ## Main results: * `Module.AEval.isTorsion_of_finiteDimensional`: if a vector space `M` with coefficients in a field `K` carries a natural `K`-linear endomorphism which belongs to a finite-dimensional algebra over `K`, then the induced `K[X]`-module structure on `M` is pure torsion. -/ open Polynomial variable {R K M A : Type*} {a : A} namespace Module.AEval theorem isTorsion_of_aeval_eq_zero [CommSemiring R] [NoZeroDivisors R] [Semiring A] [Algebra R A] [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] {p : R[X]} (h : aeval a p = 0) (h' : p ≠ 0) : IsTorsion R[X] (AEval R M a) := by have hp : p ∈ nonZeroDivisors R[X] := fun q hq ↦ Or.resolve_right (mul_eq_zero.mp hq) h' exact fun x ↦ ⟨⟨p, hp⟩, (of R M a).symm.injective <| by simp [h]⟩ variable (K M a) theorem isTorsion_of_finiteDimensional [Field K] [Ring A] [Algebra K A] [AddCommGroup M] [Module A M] [Module K M] [IsScalarTower K A M] [FiniteDimensional K A] : IsTorsion K[X] (AEval K M a) := isTorsion_of_aeval_eq_zero (minpoly.aeval K a) (minpoly.ne_zero_of_finite K a) end Module.AEval
Algebra\PUnitInstances\Algebra.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.GCDMonoid.Basic /-! # Instances on PUnit This file collects facts about algebraic structures on the one-element type, e.g. that it is a commutative ring. -/ namespace PUnit @[to_additive] instance commGroup : CommGroup PUnit where mul _ _ := unit one := unit inv _ := unit div _ _ := unit npow _ _ := unit zpow _ _ := unit mul_assoc := by intros; rfl one_mul := by intros; rfl mul_one := by intros; rfl mul_left_inv := by intros; rfl mul_comm := by intros; rfl -- shortcut instances @[to_additive] instance : One PUnit where one := () @[to_additive] instance : Mul PUnit where mul _ _ := () @[to_additive] instance : Div PUnit where div _ _ := () @[to_additive] instance : Inv PUnit where inv _ := () -- dsimp loops when applying this lemma to its LHS, -- probably https://github.com/leanprover/lean4/pull/2867 @[to_additive (attr := simp, nolint simpNF)] theorem one_eq : (1 : PUnit) = unit := rfl -- note simp can prove this when the Boolean ring structure is introduced @[to_additive] theorem mul_eq {x y : PUnit} : x * y = unit := rfl @[to_additive (attr := simp)] theorem div_eq {x y : PUnit} : x / y = unit := rfl @[to_additive (attr := simp)] theorem inv_eq {x : PUnit} : x⁻¹ = unit := rfl instance commRing : CommRing PUnit where __ := PUnit.commGroup __ := PUnit.addCommGroup left_distrib := by intros; rfl right_distrib := by intros; rfl zero_mul := by intros; rfl mul_zero := by intros; rfl natCast _ := unit instance cancelCommMonoidWithZero : CancelCommMonoidWithZero PUnit where -- This is too high-powered and should be split off also instance normalizedGCDMonoid : NormalizedGCDMonoid PUnit where gcd _ _ := unit lcm _ _ := unit normUnit _ := 1 normUnit_zero := rfl normUnit_mul := by intros; rfl normUnit_coe_units := by intros; rfl gcd_dvd_left _ _ := ⟨unit, by subsingleton⟩ gcd_dvd_right _ _ := ⟨unit, by subsingleton⟩ dvd_gcd {_ _} _ _ _ := ⟨unit, by subsingleton⟩ gcd_mul_lcm _ _ := ⟨1, by subsingleton⟩ lcm_zero_left := by intros; rfl lcm_zero_right := by intros; rfl normalize_gcd := by intros; rfl normalize_lcm := by intros; rfl -- Porting note (#10618): simpNF lint: simp can prove this @[simp] theorem gcd_eq {x y : PUnit} : gcd x y = unit := rfl -- Porting note (#10618): simpNF lint: simp can prove this @[simp] theorem lcm_eq {x y : PUnit} : lcm x y = unit := rfl @[simp] theorem norm_unit_eq {x : PUnit} : normUnit x = 1 := rfl end PUnit
Algebra\PUnitInstances\Module.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.PUnitInstances.Algebra import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Ring.Action.Basic /-! # Instances on PUnit This file collects facts about module structures on the one-element type -/ namespace PUnit variable {R S : Type*} @[to_additive] instance smul : SMul R PUnit := ⟨fun _ _ => unit⟩ @[to_additive (attr := simp)] theorem smul_eq {R : Type*} (y : PUnit) (r : R) : r • y = unit := rfl @[to_additive] instance : IsCentralScalar R PUnit := ⟨fun _ _ => rfl⟩ @[to_additive] instance : SMulCommClass R S PUnit := ⟨fun _ _ _ => rfl⟩ @[to_additive] instance instIsScalarTowerOfSMul [SMul R S] : IsScalarTower R S PUnit := ⟨fun _ _ _ => rfl⟩ instance smulWithZero [Zero R] : SMulWithZero R PUnit where __ := PUnit.smul smul_zero := by subsingleton zero_smul := by subsingleton instance mulAction [Monoid R] : MulAction R PUnit where __ := PUnit.smul one_smul := by subsingleton mul_smul := by subsingleton instance distribMulAction [Monoid R] : DistribMulAction R PUnit where __ := PUnit.mulAction smul_zero := by subsingleton smul_add := by subsingleton instance mulDistribMulAction [Monoid R] : MulDistribMulAction R PUnit where __ := PUnit.mulAction smul_mul := by subsingleton smul_one := by subsingleton instance mulSemiringAction [Semiring R] : MulSemiringAction R PUnit := { PUnit.distribMulAction, PUnit.mulDistribMulAction with } instance mulActionWithZero [MonoidWithZero R] : MulActionWithZero R PUnit := { PUnit.mulAction, PUnit.smulWithZero with } instance module [Semiring R] : Module R PUnit where __ := PUnit.distribMulAction add_smul := by subsingleton zero_smul := by subsingleton end PUnit
Algebra\PUnitInstances\Order.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.PUnitInstances.Algebra import Mathlib.Algebra.Order.AddGroupWithTop import Mathlib.Order.Heyting.Basic /-! # Instances on PUnit This file collects facts about ordered algebraic structures on the one-element type. -/ namespace PUnit instance canonicallyOrderedAddCommMonoid : CanonicallyOrderedAddCommMonoid PUnit where exists_add_of_le {_ _} _ := ⟨unit, by subsingleton⟩ add_le_add_left _ _ _ _ := trivial le_self_add _ _ := trivial instance linearOrderedCancelAddCommMonoid : LinearOrderedCancelAddCommMonoid PUnit where __ := PUnit.instLinearOrder le_of_add_le_add_left _ _ _ _ := trivial add_le_add_left := by intros; rfl instance : LinearOrderedAddCommMonoidWithTop PUnit where top_add' _ := rfl end PUnit
Algebra\Regular\Basic.lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Algebra.Group.Units import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.Basic import Mathlib.Tactic.NthRewrite /-! # Regular elements We introduce left-regular, right-regular and regular elements, along with their `to_additive` analogues add-left-regular, add-right-regular and add-regular elements. By definition, a regular element in a commutative ring is a non-zero divisor. Lemma `isRegular_of_ne_zero` implies that every non-zero element of an integral domain is regular. Since it assumes that the ring is a `CancelMonoidWithZero` it applies also, for instance, to `ℕ`. The lemmas in Section `MulZeroClass` show that the `0` element is (left/right-)regular if and only if the `MulZeroClass` is trivial. This is useful when figuring out stopping conditions for regular sequences: if `0` is ever an element of a regular sequence, then we can extend the sequence by adding one further `0`. The final goal is to develop part of the API to prove, eventually, results about non-zero-divisors. -/ variable {R : Type*} section Mul variable [Mul R] /-- A left-regular element is an element `c` such that multiplication on the left by `c` is injective. -/ @[to_additive "An add-left-regular element is an element `c` such that addition on the left by `c` is injective."] def IsLeftRegular (c : R) := (c * ·).Injective /-- A right-regular element is an element `c` such that multiplication on the right by `c` is injective. -/ @[to_additive "An add-right-regular element is an element `c` such that addition on the right by `c` is injective."] def IsRightRegular (c : R) := (· * c).Injective /-- An add-regular element is an element `c` such that addition by `c` both on the left and on the right is injective. -/ structure IsAddRegular {R : Type*} [Add R] (c : R) : Prop where /-- An add-regular element `c` is left-regular -/ left : IsAddLeftRegular c -- Porting note: It seems like to_additive is misbehaving /-- An add-regular element `c` is right-regular -/ right : IsAddRightRegular c /-- A regular element is an element `c` such that multiplication by `c` both on the left and on the right is injective. -/ structure IsRegular (c : R) : Prop where /-- A regular element `c` is left-regular -/ left : IsLeftRegular c /-- A regular element `c` is right-regular -/ right : IsRightRegular c attribute [simp] IsRegular.left IsRegular.right attribute [to_additive] IsRegular @[to_additive] theorem isRegular_iff {c : R} : IsRegular c ↔ IsLeftRegular c ∧ IsRightRegular c := ⟨fun ⟨h1, h2⟩ => ⟨h1, h2⟩, fun ⟨h1, h2⟩ => ⟨h1, h2⟩⟩ @[to_additive] protected theorem MulLECancellable.isLeftRegular [PartialOrder R] {a : R} (ha : MulLECancellable a) : IsLeftRegular a := ha.Injective theorem IsLeftRegular.right_of_commute {a : R} (ca : ∀ b, Commute a b) (h : IsLeftRegular a) : IsRightRegular a := fun x y xy => h <| (ca x).trans <| xy.trans <| (ca y).symm theorem IsRightRegular.left_of_commute {a : R} (ca : ∀ b, Commute a b) (h : IsRightRegular a) : IsLeftRegular a := by simp_rw [@Commute.symm_iff R _ a] at ca exact fun x y xy => h <| (ca x).trans <| xy.trans <| (ca y).symm theorem Commute.isRightRegular_iff {a : R} (ca : ∀ b, Commute a b) : IsRightRegular a ↔ IsLeftRegular a := ⟨IsRightRegular.left_of_commute ca, IsLeftRegular.right_of_commute ca⟩ theorem Commute.isRegular_iff {a : R} (ca : ∀ b, Commute a b) : IsRegular a ↔ IsLeftRegular a := ⟨fun h => h.left, fun h => ⟨h, h.right_of_commute ca⟩⟩ end Mul section Semigroup variable [Semigroup R] {a b : R} /-- In a semigroup, the product of left-regular elements is left-regular. -/ @[to_additive "In an additive semigroup, the sum of add-left-regular elements is add-left.regular."] theorem IsLeftRegular.mul (lra : IsLeftRegular a) (lrb : IsLeftRegular b) : IsLeftRegular (a * b) := show Function.Injective (((a * b) * ·)) from comp_mul_left a b ▸ lra.comp lrb /-- In a semigroup, the product of right-regular elements is right-regular. -/ @[to_additive "In an additive semigroup, the sum of add-right-regular elements is add-right-regular."] theorem IsRightRegular.mul (rra : IsRightRegular a) (rrb : IsRightRegular b) : IsRightRegular (a * b) := show Function.Injective (· * (a * b)) from comp_mul_right b a ▸ rrb.comp rra /-- In a semigroup, the product of regular elements is regular. -/ @[to_additive "In an additive semigroup, the sum of add-regular elements is add-regular."] theorem IsRegular.mul (rra : IsRegular a) (rrb : IsRegular b) : IsRegular (a * b) := ⟨rra.left.mul rrb.left, rra.right.mul rrb.right⟩ /-- If an element `b` becomes left-regular after multiplying it on the left by a left-regular element, then `b` is left-regular. -/ @[to_additive "If an element `b` becomes add-left-regular after adding to it on the left an add-left-regular element, then `b` is add-left-regular."] theorem IsLeftRegular.of_mul (ab : IsLeftRegular (a * b)) : IsLeftRegular b := Function.Injective.of_comp (f := (a * ·)) (by rwa [comp_mul_left a b]) /-- An element is left-regular if and only if multiplying it on the left by a left-regular element is left-regular. -/ @[to_additive (attr := simp) "An element is add-left-regular if and only if adding to it on the left an add-left-regular element is add-left-regular."] theorem mul_isLeftRegular_iff (b : R) (ha : IsLeftRegular a) : IsLeftRegular (a * b) ↔ IsLeftRegular b := ⟨fun ab => IsLeftRegular.of_mul ab, fun ab => IsLeftRegular.mul ha ab⟩ /-- If an element `b` becomes right-regular after multiplying it on the right by a right-regular element, then `b` is right-regular. -/ @[to_additive "If an element `b` becomes add-right-regular after adding to it on the right an add-right-regular element, then `b` is add-right-regular."] theorem IsRightRegular.of_mul (ab : IsRightRegular (b * a)) : IsRightRegular b := by refine fun x y xy => ab (?_ : x * (b * a) = y * (b * a)) rw [← mul_assoc, ← mul_assoc] exact congr_arg (· * a) xy /-- An element is right-regular if and only if multiplying it on the right with a right-regular element is right-regular. -/ @[to_additive (attr := simp) "An element is add-right-regular if and only if adding it on the right to an add-right-regular element is add-right-regular."] theorem mul_isRightRegular_iff (b : R) (ha : IsRightRegular a) : IsRightRegular (b * a) ↔ IsRightRegular b := ⟨fun ab => IsRightRegular.of_mul ab, fun ab => IsRightRegular.mul ab ha⟩ /-- Two elements `a` and `b` are regular if and only if both products `a * b` and `b * a` are regular. -/ @[to_additive "Two elements `a` and `b` are add-regular if and only if both sums `a + b` and `b + a` are add-regular."] theorem isRegular_mul_and_mul_iff : IsRegular (a * b) ∧ IsRegular (b * a) ↔ IsRegular a ∧ IsRegular b := by refine ⟨?_, ?_⟩ · rintro ⟨ab, ba⟩ exact ⟨⟨IsLeftRegular.of_mul ba.left, IsRightRegular.of_mul ab.right⟩, ⟨IsLeftRegular.of_mul ab.left, IsRightRegular.of_mul ba.right⟩⟩ · rintro ⟨ha, hb⟩ exact ⟨ha.mul hb, hb.mul ha⟩ /-- The "most used" implication of `mul_and_mul_iff`, with split hypotheses, instead of `∧`. -/ @[to_additive "The \"most used\" implication of `add_and_add_iff`, with split hypotheses, instead of `∧`."] theorem IsRegular.and_of_mul_of_mul (ab : IsRegular (a * b)) (ba : IsRegular (b * a)) : IsRegular a ∧ IsRegular b := isRegular_mul_and_mul_iff.mp ⟨ab, ba⟩ end Semigroup section MulZeroClass variable [MulZeroClass R] {a b : R} /-- The element `0` is left-regular if and only if `R` is trivial. -/ theorem IsLeftRegular.subsingleton (h : IsLeftRegular (0 : R)) : Subsingleton R := ⟨fun a b => h <| Eq.trans (zero_mul a) (zero_mul b).symm⟩ /-- The element `0` is right-regular if and only if `R` is trivial. -/ theorem IsRightRegular.subsingleton (h : IsRightRegular (0 : R)) : Subsingleton R := ⟨fun a b => h <| Eq.trans (mul_zero a) (mul_zero b).symm⟩ /-- The element `0` is regular if and only if `R` is trivial. -/ theorem IsRegular.subsingleton (h : IsRegular (0 : R)) : Subsingleton R := h.left.subsingleton /-- The element `0` is left-regular if and only if `R` is trivial. -/ theorem isLeftRegular_zero_iff_subsingleton : IsLeftRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩ /-- In a non-trivial `MulZeroClass`, the `0` element is not left-regular. -/ theorem not_isLeftRegular_zero_iff : ¬IsLeftRegular (0 : R) ↔ Nontrivial R := by rw [nontrivial_iff, not_iff_comm, isLeftRegular_zero_iff_subsingleton, subsingleton_iff] push_neg exact Iff.rfl /-- The element `0` is right-regular if and only if `R` is trivial. -/ theorem isRightRegular_zero_iff_subsingleton : IsRightRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩ /-- In a non-trivial `MulZeroClass`, the `0` element is not right-regular. -/ theorem not_isRightRegular_zero_iff : ¬IsRightRegular (0 : R) ↔ Nontrivial R := by rw [nontrivial_iff, not_iff_comm, isRightRegular_zero_iff_subsingleton, subsingleton_iff] push_neg exact Iff.rfl /-- The element `0` is regular if and only if `R` is trivial. -/ theorem isRegular_iff_subsingleton : IsRegular (0 : R) ↔ Subsingleton R := ⟨fun h => h.left.subsingleton, fun h => ⟨isLeftRegular_zero_iff_subsingleton.mpr h, isRightRegular_zero_iff_subsingleton.mpr h⟩⟩ /-- A left-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsLeftRegular.ne_zero [Nontrivial R] (la : IsLeftRegular a) : a ≠ 0 := by rintro rfl rcases exists_pair_ne R with ⟨x, y, xy⟩ refine xy (la (?_ : 0 * x = 0 * y)) -- Porting note: lean4 seems to need the type signature rw [zero_mul, zero_mul] /-- A right-regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsRightRegular.ne_zero [Nontrivial R] (ra : IsRightRegular a) : a ≠ 0 := by rintro rfl rcases exists_pair_ne R with ⟨x, y, xy⟩ refine xy (ra (?_ : x * 0 = y * 0)) rw [mul_zero, mul_zero] /-- A regular element of a `Nontrivial` `MulZeroClass` is non-zero. -/ theorem IsRegular.ne_zero [Nontrivial R] (la : IsRegular a) : a ≠ 0 := la.left.ne_zero /-- In a non-trivial ring, the element `0` is not left-regular -- with typeclasses. -/ theorem not_isLeftRegular_zero [nR : Nontrivial R] : ¬IsLeftRegular (0 : R) := not_isLeftRegular_zero_iff.mpr nR /-- In a non-trivial ring, the element `0` is not right-regular -- with typeclasses. -/ theorem not_isRightRegular_zero [nR : Nontrivial R] : ¬IsRightRegular (0 : R) := not_isRightRegular_zero_iff.mpr nR /-- In a non-trivial ring, the element `0` is not regular -- with typeclasses. -/ theorem not_isRegular_zero [Nontrivial R] : ¬IsRegular (0 : R) := fun h => IsRegular.ne_zero h rfl @[simp] lemma IsLeftRegular.mul_left_eq_zero_iff (hb : IsLeftRegular b) : b * a = 0 ↔ a = 0 := by nth_rw 1 [← mul_zero b] exact ⟨fun h ↦ hb h, fun ha ↦ by rw [ha]⟩ @[simp] lemma IsRightRegular.mul_right_eq_zero_iff (hb : IsRightRegular b) : a * b = 0 ↔ a = 0 := by nth_rw 1 [← zero_mul b] exact ⟨fun h ↦ hb h, fun ha ↦ by rw [ha]⟩ end MulZeroClass section MulOneClass variable [MulOneClass R] /-- If multiplying by `1` on either side is the identity, `1` is regular. -/ @[to_additive "If adding `0` on either side is the identity, `0` is regular."] theorem isRegular_one : IsRegular (1 : R) := ⟨fun a b ab => (one_mul a).symm.trans (Eq.trans ab (one_mul b)), fun a b ab => (mul_one a).symm.trans (Eq.trans ab (mul_one b))⟩ end MulOneClass section CommSemigroup variable [CommSemigroup R] {a b : R} /-- A product is regular if and only if the factors are. -/ @[to_additive "A sum is add-regular if and only if the summands are."] theorem isRegular_mul_iff : IsRegular (a * b) ↔ IsRegular a ∧ IsRegular b := by refine Iff.trans ?_ isRegular_mul_and_mul_iff exact ⟨fun ab => ⟨ab, by rwa [mul_comm]⟩, fun rab => rab.1⟩ end CommSemigroup section Monoid variable [Monoid R] {a b : R} /-- An element admitting a left inverse is left-regular. -/ @[to_additive "An element admitting a left additive opposite is add-left-regular."] theorem isLeftRegular_of_mul_eq_one (h : b * a = 1) : IsLeftRegular a := IsLeftRegular.of_mul (a := b) (by rw [h]; exact isRegular_one.left) /-- An element admitting a right inverse is right-regular. -/ @[to_additive "An element admitting a right additive opposite is add-right-regular."] theorem isRightRegular_of_mul_eq_one (h : a * b = 1) : IsRightRegular a := IsRightRegular.of_mul (a := b) (by rw [h]; exact isRegular_one.right) /-- If `R` is a monoid, an element in `Rˣ` is regular. -/ @[to_additive "If `R` is an additive monoid, an element in `add_units R` is add-regular."] theorem Units.isRegular (a : Rˣ) : IsRegular (a : R) := ⟨isLeftRegular_of_mul_eq_one a.inv_mul, isRightRegular_of_mul_eq_one a.mul_inv⟩ /-- A unit in a monoid is regular. -/ @[to_additive "An additive unit in an additive monoid is add-regular."] theorem IsUnit.isRegular (ua : IsUnit a) : IsRegular a := by rcases ua with ⟨a, rfl⟩ exact Units.isRegular a end Monoid /-- If all multiplications cancel on the left then every element is left-regular. -/ @[to_additive "If all additions cancel on the left then every element is add-left-regular."] theorem IsLeftRegular.all [Mul R] [IsLeftCancelMul R] (g : R) : IsLeftRegular g := mul_right_injective g /-- If all multiplications cancel on the right then every element is right-regular. -/ @[to_additive "If all additions cancel on the right then every element is add-right-regular."] theorem IsRightRegular.all [Mul R] [IsRightCancelMul R] (g : R) : IsRightRegular g := mul_left_injective g /-- If all multiplications cancel then every element is regular. -/ @[to_additive "If all additions cancel then every element is add-regular."] theorem IsRegular.all [Mul R] [IsCancelMul R] (g : R) : IsRegular g := ⟨mul_right_injective g, mul_left_injective g⟩ section CancelMonoidWithZero variable [MulZeroClass R] [IsCancelMulZero R] {a : R} /-- Non-zero elements of an integral domain are regular. -/ theorem isRegular_of_ne_zero (a0 : a ≠ 0) : IsRegular a := ⟨fun _ _ => mul_left_cancel₀ a0, fun _ _ => mul_right_cancel₀ a0⟩ /-- In a non-trivial integral domain, an element is regular iff it is non-zero. -/ theorem isRegular_iff_ne_zero [Nontrivial R] : IsRegular a ↔ a ≠ 0 := ⟨IsRegular.ne_zero, isRegular_of_ne_zero⟩ end CancelMonoidWithZero
Algebra\Regular\Pow.lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Algebra.Regular.Basic /-! # Regular elements ## Implementation details Group powers and other definitions import a lot of the algebra hierarchy. Lemmas about them are kept separate to be able to provide `IsRegular` early in the algebra hierarchy. -/ variable {R : Type*} {a b : R} section Monoid variable [Monoid R] /-- Any power of a left-regular element is left-regular. -/ theorem IsLeftRegular.pow (n : ℕ) (rla : IsLeftRegular a) : IsLeftRegular (a ^ n) := by simp only [IsLeftRegular, ← mul_left_iterate, rla.iterate n] /-- Any power of a right-regular element is right-regular. -/ theorem IsRightRegular.pow (n : ℕ) (rra : IsRightRegular a) : IsRightRegular (a ^ n) := by rw [IsRightRegular, ← mul_right_iterate] exact rra.iterate n /-- Any power of a regular element is regular. -/ theorem IsRegular.pow (n : ℕ) (ra : IsRegular a) : IsRegular (a ^ n) := ⟨IsLeftRegular.pow n ra.left, IsRightRegular.pow n ra.right⟩ /-- An element `a` is left-regular if and only if a positive power of `a` is left-regular. -/ theorem IsLeftRegular.pow_iff {n : ℕ} (n0 : 0 < n) : IsLeftRegular (a ^ n) ↔ IsLeftRegular a := by refine ⟨?_, IsLeftRegular.pow n⟩ rw [← Nat.succ_pred_eq_of_pos n0, pow_succ] exact IsLeftRegular.of_mul /-- An element `a` is right-regular if and only if a positive power of `a` is right-regular. -/ theorem IsRightRegular.pow_iff {n : ℕ} (n0 : 0 < n) : IsRightRegular (a ^ n) ↔ IsRightRegular a := by refine ⟨?_, IsRightRegular.pow n⟩ rw [← Nat.succ_pred_eq_of_pos n0, pow_succ'] exact IsRightRegular.of_mul /-- An element `a` is regular if and only if a positive power of `a` is regular. -/ theorem IsRegular.pow_iff {n : ℕ} (n0 : 0 < n) : IsRegular (a ^ n) ↔ IsRegular a := ⟨fun h => ⟨(IsLeftRegular.pow_iff n0).mp h.left, (IsRightRegular.pow_iff n0).mp h.right⟩, fun h => ⟨IsLeftRegular.pow n h.left, IsRightRegular.pow n h.right⟩⟩ end Monoid section CommMonoid variable {ι R : Type*} [CommMonoid R] {s : Finset ι} {f : ι → R} lemma IsLeftRegular.prod (h : ∀ i ∈ s, IsLeftRegular (f i)) : IsLeftRegular (∏ i ∈ s, f i) := s.prod_induction _ _ (@IsLeftRegular.mul R _) isRegular_one.left h lemma IsRightRegular.prod (h : ∀ i ∈ s, IsRightRegular (f i)) : IsRightRegular (∏ i ∈ s, f i) := s.prod_induction _ _ (@IsRightRegular.mul R _) isRegular_one.right h lemma IsRegular.prod (h : ∀ i ∈ s, IsRegular (f i)) : IsRegular (∏ i ∈ s, f i) := ⟨IsLeftRegular.prod fun a ha ↦ (h a ha).left, IsRightRegular.prod fun a ha ↦ (h a ha).right⟩ end CommMonoid
Algebra\Regular\SMul.lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Regular.Basic import Mathlib.GroupTheory.GroupAction.Hom /-! # Action of regular elements on a module We introduce `M`-regular elements, in the context of an `R`-module `M`. The corresponding predicate is called `IsSMulRegular`. There are very limited typeclass assumptions on `R` and `M`, but the "mathematical" case of interest is a commutative ring `R` acting on a module `M`. Since the properties are "multiplicative", there is no actual requirement of having an addition, but there is a zero in both `R` and `M`. SMultiplications involving `0` are, of course, all trivial. The defining property is that an element `a ∈ R` is `M`-regular if the smultiplication map `M → M`, defined by `m ↦ a • m`, is injective. This property is the direct generalization to modules of the property `IsLeftRegular` defined in `Algebra/Regular`. Lemma `isLeftRegular_iff` shows that indeed the two notions coincide. -/ variable {R S : Type*} (M : Type*) {a b : R} {s : S} /-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an injective map `M → M`. -/ def IsSMulRegular [SMul R M] (c : R) := Function.Injective ((c • ·) : M → M) theorem IsLeftRegular.isSMulRegular [Mul R] {c : R} (h : IsLeftRegular c) : IsSMulRegular R c := h /-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/ theorem isLeftRegular_iff [Mul R] {a : R} : IsLeftRegular a ↔ IsSMulRegular R a := Iff.rfl theorem IsRightRegular.isSMulRegular [Mul R] {c : R} (h : IsRightRegular c) : IsSMulRegular R (MulOpposite.op c) := h /-- Right-regular multiplication on `R` is equivalent to `Rᵐᵒᵖ`-regularity of `R` itself. -/ theorem isRightRegular_iff [Mul R] {a : R} : IsRightRegular a ↔ IsSMulRegular R (MulOpposite.op a) := Iff.rfl namespace IsSMulRegular variable {M} section SMul variable [SMul R M] [SMul R S] [SMul S M] [IsScalarTower R S M] /-- The product of `M`-regular elements is `M`-regular. -/ theorem smul (ra : IsSMulRegular M a) (rs : IsSMulRegular M s) : IsSMulRegular M (a • s) := fun _ _ ab => rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _)))) /-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular element, then `b` is `M`-regular. -/ theorem of_smul (a : R) (ab : IsSMulRegular M (a • s)) : IsSMulRegular M s := @Function.Injective.of_comp _ _ _ (fun m : M => a • m) _ fun c d cd => by dsimp only [Function.comp_def] at cd rw [← smul_assoc, ← smul_assoc] at cd exact ab cd /-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element is `M`-regular. -/ @[simp] theorem smul_iff (b : S) (ha : IsSMulRegular M a) : IsSMulRegular M (a • b) ↔ IsSMulRegular M b := ⟨of_smul _, ha.smul⟩ theorem isLeftRegular [Mul R] {a : R} (h : IsSMulRegular R a) : IsLeftRegular a := h theorem isRightRegular [Mul R] {a : R} (h : IsSMulRegular R (MulOpposite.op a)) : IsRightRegular a := h theorem mul [Mul R] [IsScalarTower R R M] (ra : IsSMulRegular M a) (rb : IsSMulRegular M b) : IsSMulRegular M (a * b) := ra.smul rb theorem of_mul [Mul R] [IsScalarTower R R M] (ab : IsSMulRegular M (a * b)) : IsSMulRegular M b := by rw [← smul_eq_mul] at ab exact ab.of_smul _ @[simp] theorem mul_iff_right [Mul R] [IsScalarTower R R M] (ha : IsSMulRegular M a) : IsSMulRegular M (a * b) ↔ IsSMulRegular M b := ⟨of_mul, ha.mul⟩ /-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a` are `M`-regular. -/ theorem mul_and_mul_iff [Mul R] [IsScalarTower R R M] : IsSMulRegular M (a * b) ∧ IsSMulRegular M (b * a) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by refine ⟨?_, ?_⟩ · rintro ⟨ab, ba⟩ exact ⟨ba.of_mul, ab.of_mul⟩ · rintro ⟨ha, hb⟩ exact ⟨ha.mul hb, hb.mul ha⟩ lemma of_injective {N F} [SMul R N] [FunLike F M N] [MulActionHomClass F R M N] (f : F) {r : R} (h1 : Function.Injective f) (h2 : IsSMulRegular N r) : IsSMulRegular M r := fun x y h3 => h1 <| h2 <| (map_smulₛₗ f r x).symm.trans ((congrArg f h3).trans (map_smulₛₗ f r y)) end SMul section Monoid variable [Monoid R] [MulAction R M] variable (M) /-- One is always `M`-regular. -/ @[simp] theorem one : IsSMulRegular M (1 : R) := fun a b ab => by dsimp only [Function.comp_def] at ab rw [one_smul, one_smul] at ab assumption variable {M} /-- An element of `R` admitting a left inverse is `M`-regular. -/ theorem of_mul_eq_one (h : a * b = 1) : IsSMulRegular M b := of_mul (a := a) (by rw [h]; exact one M) /-- Any power of an `M`-regular element is `M`-regular. -/ theorem pow (n : ℕ) (ra : IsSMulRegular M a) : IsSMulRegular M (a ^ n) := by induction' n with n hn · rw [pow_zero]; simp only [one] · rw [pow_succ'] exact (ra.smul_iff (a ^ n)).mpr hn /-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/ theorem pow_iff {n : ℕ} (n0 : 0 < n) : IsSMulRegular M (a ^ n) ↔ IsSMulRegular M a := by refine ⟨?_, pow n⟩ rw [← Nat.succ_pred_eq_of_pos n0, pow_succ, ← smul_eq_mul] exact of_smul _ end Monoid section MonoidSMul variable [Monoid S] [SMul R M] [SMul R S] [MulAction S M] [IsScalarTower R S M] /-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/ theorem of_smul_eq_one (h : a • s = 1) : IsSMulRegular M s := of_smul a (by rw [h] exact one M) end MonoidSMul section MonoidWithZero variable [MonoidWithZero R] [MonoidWithZero S] [Zero M] [MulActionWithZero R M] [MulActionWithZero R S] [MulActionWithZero S M] [IsScalarTower R S M] /-- The element `0` is `M`-regular if and only if `M` is trivial. -/ protected theorem subsingleton (h : IsSMulRegular M (0 : R)) : Subsingleton M := ⟨fun a b => h (by dsimp only [Function.comp_def]; repeat' rw [MulActionWithZero.zero_smul])⟩ /-- The element `0` is `M`-regular if and only if `M` is trivial. -/ theorem zero_iff_subsingleton : IsSMulRegular M (0 : R) ↔ Subsingleton M := ⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩ /-- The `0` element is not `M`-regular, on a non-trivial module. -/ theorem not_zero_iff : ¬IsSMulRegular M (0 : R) ↔ Nontrivial M := by rw [nontrivial_iff, not_iff_comm, zero_iff_subsingleton, subsingleton_iff] push_neg exact Iff.rfl /-- The element `0` is `M`-regular when `M` is trivial. -/ theorem zero [sM : Subsingleton M] : IsSMulRegular M (0 : R) := zero_iff_subsingleton.mpr sM /-- The `0` element is not `M`-regular, on a non-trivial module. -/ theorem not_zero [nM : Nontrivial M] : ¬IsSMulRegular M (0 : R) := not_zero_iff.mpr nM end MonoidWithZero section CommSemigroup variable [CommSemigroup R] [SMul R M] [IsScalarTower R R M] /-- A product is `M`-regular if and only if the factors are. -/ theorem mul_iff : IsSMulRegular M (a * b) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by rw [← mul_and_mul_iff] exact ⟨fun ab => ⟨ab, by rwa [mul_comm]⟩, fun rab => rab.1⟩ end CommSemigroup end IsSMulRegular section Group variable {G : Type*} [Group G] /-- An element of a group acting on a Type is regular. This relies on the availability of the inverse given by groups, since there is no `LeftCancelSMul` typeclass. -/ theorem isSMulRegular_of_group [MulAction G R] (g : G) : IsSMulRegular R g := by intro x y h convert congr_arg (g⁻¹ • ·) h using 1 <;> simp [← smul_assoc] end Group section Units variable [Monoid R] [MulAction R M] /-- Any element in `Rˣ` is `M`-regular. -/ theorem Units.isSMulRegular (a : Rˣ) : IsSMulRegular M (a : R) := IsSMulRegular.of_mul_eq_one a.inv_val /-- A unit is `M`-regular. -/ theorem IsUnit.isSMulRegular (ua : IsUnit a) : IsSMulRegular M a := by rcases ua with ⟨a, rfl⟩ exact a.isSMulRegular M end Units section SMulZeroClass variable {M} protected lemma IsSMulRegular.eq_zero_of_smul_eq_zero [Zero M] [SMulZeroClass R M] {r : R} {x : M} (h1 : IsSMulRegular M r) (h2 : r • x = 0) : x = 0 := h1 (h2.trans (smul_zero r).symm) end SMulZeroClass lemma Equiv.isSMulRegular_congr {R S M M'} [SMul R M] [SMul S M'] {e : M ≃ M'} {r : R} {s : S} (h : ∀ x, e (r • x) = s • e x) : IsSMulRegular M r ↔ IsSMulRegular M' s := (e.comp_injective _).symm.trans <| (iff_of_eq <| congrArg _ <| funext h).trans <| e.injective_comp _
Algebra\Ring\AddAut.lean
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.GroupTheory.GroupAction.Group import Mathlib.Algebra.Module.Defs /-! # Multiplication on the left/right as additive automorphisms In this file we define `AddAut.mulLeft` and `AddAut.mulRight`. See also `AddMonoidHom.mulLeft`, `AddMonoidHom.mulRight`, `AddMonoid.End.mulLeft`, and `AddMonoid.End.mulRight` for multiplication by `R` as an endomorphism instead of multiplication by `Rˣ` as an automorphism. -/ namespace AddAut variable {R : Type*} [Semiring R] /-- Left multiplication by a unit of a semiring as an additive automorphism. -/ @[simps! (config := { simpRhs := true })] def mulLeft : Rˣ →* AddAut R := DistribMulAction.toAddAut _ _ /-- Right multiplication by a unit of a semiring as an additive automorphism. -/ def mulRight (u : Rˣ) : AddAut R := DistribMulAction.toAddAut Rᵐᵒᵖˣ R (Units.opEquiv.symm <| MulOpposite.op u) @[simp] theorem mulRight_apply (u : Rˣ) (x : R) : mulRight u x = x * u := rfl @[simp] theorem mulRight_symm_apply (u : Rˣ) (x : R) : (mulRight u).symm x = x * u⁻¹ := rfl end AddAut
Algebra\Ring\Aut.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov -/ import Mathlib.Algebra.Group.Aut import Mathlib.Algebra.Ring.Action.Group import Mathlib.Algebra.Ring.Equiv /-! # Ring automorphisms This file defines the automorphism group structure on `RingAut R := RingEquiv R R`. ## Implementation notes The definition of multiplication in the automorphism group agrees with function composition, multiplication in `Equiv.Perm`, and multiplication in `CategoryTheory.End`, but not with `CategoryTheory.comp`. This file is kept separate from `Data/Equiv/Ring` so that `GroupTheory.Perm` is free to use equivalences (and other files that use them) before the group structure is defined. ## Tags RingAut -/ /-- The group of ring automorphisms. -/ abbrev RingAut (R : Type*) [Mul R] [Add R] := RingEquiv R R namespace RingAut section mul_add variable (R : Type*) [Mul R] [Add R] /-- The group operation on automorphisms of a ring is defined by `fun g h => RingEquiv.trans h g`. This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`. -/ instance : Group (RingAut R) where mul g h := RingEquiv.trans h g one := RingEquiv.refl R inv := RingEquiv.symm mul_assoc _ _ _ := rfl one_mul _ := rfl mul_one _ := rfl mul_left_inv := RingEquiv.self_trans_symm instance : Inhabited (RingAut R) := ⟨1⟩ /-- Monoid homomorphism from ring automorphisms to additive automorphisms. -/ def toAddAut : RingAut R →* AddAut R where toFun := RingEquiv.toAddEquiv map_one' := rfl map_mul' _ _ := rfl /-- Monoid homomorphism from ring automorphisms to multiplicative automorphisms. -/ def toMulAut : RingAut R →* MulAut R where toFun := RingEquiv.toMulEquiv map_one' := rfl map_mul' _ _ := rfl /-- Monoid homomorphism from ring automorphisms to permutations. -/ def toPerm : RingAut R →* Equiv.Perm R where toFun := RingEquiv.toEquiv map_one' := rfl map_mul' _ _ := rfl end mul_add section Semiring variable {G R : Type*} [Group G] [Semiring R] /-- The tautological action by the group of automorphism of a ring `R` on `R`. -/ instance applyMulSemiringAction : MulSemiringAction (RingAut R) R where smul := (· <| ·) smul_zero := RingEquiv.map_zero smul_add := RingEquiv.map_add smul_one := RingEquiv.map_one smul_mul := RingEquiv.map_mul one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] protected theorem smul_def (f : RingAut R) (r : R) : f • r = f r := rfl instance apply_faithfulSMul : FaithfulSMul (RingAut R) R := ⟨RingEquiv.ext⟩ variable (G R) /-- Each element of the group defines a ring automorphism. This is a stronger version of `DistribMulAction.toAddAut` and `MulDistribMulAction.toMulAut`. -/ @[simps] def _root_.MulSemiringAction.toRingAut [MulSemiringAction G R] : G →* RingAut R where toFun := MulSemiringAction.toRingEquiv G R map_mul' g h := RingEquiv.ext <| mul_smul g h map_one' := RingEquiv.ext <| one_smul _ end Semiring end RingAut
Algebra\Ring\Basic.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Algebra.GroupWithZero.NeZero import Mathlib.Algebra.Opposites import Mathlib.Algebra.Ring.Defs /-! # Semirings and rings This file gives lemmas about semirings, rings and domains. This is analogous to `Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. For the definitions of semirings and rings see `Algebra.Ring.Defs`. -/ variable {R : Type*} open Function namespace AddHom /-- Left multiplication by an element of a type with distributive multiplication is an `AddHom`. -/ @[simps (config := .asFn)] def mulLeft [Distrib R] (r : R) : AddHom R R where toFun := (r * ·) map_add' := mul_add r /-- Left multiplication by an element of a type with distributive multiplication is an `AddHom`. -/ @[simps (config := .asFn)] def mulRight [Distrib R] (r : R) : AddHom R R where toFun a := a * r map_add' _ _ := add_mul _ _ r end AddHom section AddHomClass variable {α β F : Type*} [NonAssocSemiring α] [NonAssocSemiring β] [FunLike F α β] [AddHomClass F α β] end AddHomClass namespace AddMonoidHom /-- Left multiplication by an element of a (semi)ring is an `AddMonoidHom` -/ def mulLeft [NonUnitalNonAssocSemiring R] (r : R) : R →+ R where toFun := (r * ·) map_zero' := mul_zero r map_add' := mul_add r @[simp] theorem coe_mulLeft [NonUnitalNonAssocSemiring R] (r : R) : (mulLeft r : R → R) = HMul.hMul r := rfl /-- Right multiplication by an element of a (semi)ring is an `AddMonoidHom` -/ def mulRight [NonUnitalNonAssocSemiring R] (r : R) : R →+ R where toFun a := a * r map_zero' := zero_mul r map_add' _ _ := add_mul _ _ r @[simp] theorem coe_mulRight [NonUnitalNonAssocSemiring R] (r : R) : (mulRight r) = (· * r) := rfl theorem mulRight_apply [NonUnitalNonAssocSemiring R] (a r : R) : mulRight r a = a * r := rfl end AddMonoidHom section HasDistribNeg section Mul variable {α : Type*} [Mul α] [HasDistribNeg α] open MulOpposite instance instHasDistribNeg : HasDistribNeg αᵐᵒᵖ where neg_mul _ _ := unop_injective <| mul_neg _ _ mul_neg _ _ := unop_injective <| neg_mul _ _ end Mul section Group variable {α : Type*} [Group α] [HasDistribNeg α] @[simp] theorem inv_neg' (a : α) : (-a)⁻¹ = -a⁻¹ := by rw [eq_comm, eq_inv_iff_mul_eq_one, neg_mul, mul_neg, neg_neg, mul_left_inv] end Group end HasDistribNeg section NonUnitalCommRing variable {α : Type*} [NonUnitalCommRing α] {a b c : α} attribute [local simp] add_assoc add_comm add_left_comm mul_comm /-- Vieta's formula for a quadratic equation, relating the coefficients of the polynomial with its roots. This particular version states that if we have a root `x` of a monic quadratic polynomial, then there is another root `y` such that `x + y` is negative the `a_1` coefficient and `x * y` is the `a_0` coefficient. -/ theorem vieta_formula_quadratic {b c x : α} (h : x * x - b * x + c = 0) : ∃ y : α, y * y - b * y + c = 0 ∧ x + y = b ∧ x * y = c := by have : c = x * (b - x) := (eq_neg_of_add_eq_zero_right h).trans (by simp [mul_sub, mul_comm]) refine ⟨b - x, ?_, by simp, by rw [this]⟩ rw [this, sub_add, ← sub_mul, sub_self] end NonUnitalCommRing theorem succ_ne_self {α : Type*} [NonAssocRing α] [Nontrivial α] (a : α) : a + 1 ≠ a := fun h => one_ne_zero ((add_right_inj a).mp (by simp [h])) theorem pred_ne_self {α : Type*} [NonAssocRing α] [Nontrivial α] (a : α) : a - 1 ≠ a := fun h ↦ one_ne_zero (neg_injective ((add_right_inj a).mp (by simp [← sub_eq_add_neg, h]))) section NoZeroDivisors variable (α) lemma IsLeftCancelMulZero.to_noZeroDivisors [NonUnitalNonAssocRing α] [IsLeftCancelMulZero α] : NoZeroDivisors α := { eq_zero_or_eq_zero_of_mul_eq_zero := fun {x y} h ↦ by by_cases hx : x = 0 { left exact hx } { right rw [← sub_zero (x * y), ← mul_zero x, ← mul_sub] at h have := (IsLeftCancelMulZero.mul_left_cancel_of_ne_zero) hx h rwa [sub_zero] at this } } lemma IsRightCancelMulZero.to_noZeroDivisors [NonUnitalNonAssocRing α] [IsRightCancelMulZero α] : NoZeroDivisors α := { eq_zero_or_eq_zero_of_mul_eq_zero := fun {x y} h ↦ by by_cases hy : y = 0 { right exact hy } { left rw [← sub_zero (x * y), ← zero_mul y, ← sub_mul] at h have := (IsRightCancelMulZero.mul_right_cancel_of_ne_zero) hy h rwa [sub_zero] at this } } instance (priority := 100) NoZeroDivisors.to_isCancelMulZero [NonUnitalNonAssocRing α] [NoZeroDivisors α] : IsCancelMulZero α := { mul_left_cancel_of_ne_zero := fun ha h ↦ by rw [← sub_eq_zero, ← mul_sub] at h exact sub_eq_zero.1 ((eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left ha) mul_right_cancel_of_ne_zero := fun hb h ↦ by rw [← sub_eq_zero, ← sub_mul] at h exact sub_eq_zero.1 ((eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hb) } /-- In a ring, `IsCancelMulZero` and `NoZeroDivisors` are equivalent. -/ lemma isCancelMulZero_iff_noZeroDivisors [NonUnitalNonAssocRing α] : IsCancelMulZero α ↔ NoZeroDivisors α := ⟨fun _ => IsRightCancelMulZero.to_noZeroDivisors _, fun _ => inferInstance⟩ lemma NoZeroDivisors.to_isDomain [Ring α] [h : Nontrivial α] [NoZeroDivisors α] : IsDomain α := { NoZeroDivisors.to_isCancelMulZero α, h with .. } instance (priority := 100) IsDomain.to_noZeroDivisors [Ring α] [IsDomain α] : NoZeroDivisors α := IsRightCancelMulZero.to_noZeroDivisors α instance Subsingleton.to_isCancelMulZero [Mul α] [Zero α] [Subsingleton α] : IsCancelMulZero α where mul_right_cancel_of_ne_zero hb := (hb <| Subsingleton.eq_zero _).elim mul_left_cancel_of_ne_zero hb := (hb <| Subsingleton.eq_zero _).elim instance Subsingleton.to_noZeroDivisors [Mul α] [Zero α] [Subsingleton α] : NoZeroDivisors α where eq_zero_or_eq_zero_of_mul_eq_zero _ := .inl (Subsingleton.eq_zero _) lemma isDomain_iff_cancelMulZero_and_nontrivial [Semiring α] : IsDomain α ↔ IsCancelMulZero α ∧ Nontrivial α := ⟨fun _ => ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ => {}⟩ lemma isCancelMulZero_iff_isDomain_or_subsingleton [Semiring α] : IsCancelMulZero α ↔ IsDomain α ∨ Subsingleton α := by refine ⟨fun t ↦ ?_, fun h ↦ h.elim (fun _ ↦ inferInstance) (fun _ ↦ inferInstance)⟩ rw [or_iff_not_imp_right, not_subsingleton_iff_nontrivial] exact fun _ ↦ {} lemma isDomain_iff_noZeroDivisors_and_nontrivial [Ring α] : IsDomain α ↔ NoZeroDivisors α ∧ Nontrivial α := by rw [← isCancelMulZero_iff_noZeroDivisors, isDomain_iff_cancelMulZero_and_nontrivial] lemma noZeroDivisors_iff_isDomain_or_subsingleton [Ring α] : NoZeroDivisors α ↔ IsDomain α ∨ Subsingleton α := by rw [← isCancelMulZero_iff_noZeroDivisors, isCancelMulZero_iff_isDomain_or_subsingleton] end NoZeroDivisors
Algebra\Ring\BooleanRing.lean
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bryan Gin-ge Chen, Yaël Dillies -/ import Mathlib.Algebra.PUnitInstances.Algebra import Mathlib.Tactic.Abel import Mathlib.Tactic.Ring import Mathlib.Order.Hom.Lattice import Mathlib.Algebra.Ring.Equiv /-! # Boolean rings A Boolean ring is a ring where multiplication is idempotent. They are equivalent to Boolean algebras. ## Main declarations * `BooleanRing`: a typeclass for rings where multiplication is idempotent. * `BooleanRing.toBooleanAlgebra`: Turn a Boolean ring into a Boolean algebra. * `BooleanAlgebra.toBooleanRing`: Turn a Boolean algebra into a Boolean ring. * `AsBoolAlg`: Type-synonym for the Boolean algebra associated to a Boolean ring. * `AsBoolRing`: Type-synonym for the Boolean ring associated to a Boolean algebra. ## Implementation notes We provide two ways of turning a Boolean algebra/ring into a Boolean ring/algebra: * Instances on the same type accessible in locales `BooleanAlgebraOfBooleanRing` and `BooleanRingOfBooleanAlgebra`. * Type-synonyms `AsBoolAlg` and `AsBoolRing`. At this point in time, it is not clear the first way is useful, but we keep it for educational purposes and because it is easier than dealing with `ofBoolAlg`/`toBoolAlg`/`ofBoolRing`/`toBoolRing` explicitly. ## Tags boolean ring, boolean algebra -/ open scoped symmDiff variable {α β γ : Type*} /-- A Boolean ring is a ring where multiplication is idempotent. -/ class BooleanRing (α) extends Ring α where /-- Multiplication in a boolean ring is idempotent. -/ mul_self : ∀ a : α, a * a = a section BooleanRing variable [BooleanRing α] (a b : α) instance : Std.IdempotentOp (α := α) (· * ·) := ⟨BooleanRing.mul_self⟩ @[simp] theorem mul_self : a * a = a := BooleanRing.mul_self _ @[simp] theorem add_self : a + a = 0 := by have : a + a = a + a + (a + a) := calc a + a = (a + a) * (a + a) := by rw [mul_self] _ = a * a + a * a + (a * a + a * a) := by rw [add_mul, mul_add] _ = a + a + (a + a) := by rw [mul_self] rwa [self_eq_add_left] at this @[simp] theorem neg_eq : -a = a := calc -a = -a + 0 := by rw [add_zero] _ = -a + -a + a := by rw [← neg_add_self, add_assoc] _ = a := by rw [add_self, zero_add] theorem add_eq_zero' : a + b = 0 ↔ a = b := calc a + b = 0 ↔ a = -b := add_eq_zero_iff_eq_neg _ ↔ a = b := by rw [neg_eq] @[simp] theorem mul_add_mul : a * b + b * a = 0 := by have : a + b = a + b + (a * b + b * a) := calc a + b = (a + b) * (a + b) := by rw [mul_self] _ = a * a + a * b + (b * a + b * b) := by rw [add_mul, mul_add, mul_add] _ = a + a * b + (b * a + b) := by simp only [mul_self] _ = a + b + (a * b + b * a) := by abel rwa [self_eq_add_right] at this @[simp] theorem sub_eq_add : a - b = a + b := by rw [sub_eq_add_neg, add_right_inj, neg_eq] @[simp] theorem mul_one_add_self : a * (1 + a) = 0 := by rw [mul_add, mul_one, mul_self, add_self] -- Note [lower instance priority] instance (priority := 100) BooleanRing.toCommRing : CommRing α := { (inferInstance : BooleanRing α) with mul_comm := fun a b => by rw [← add_eq_zero', mul_add_mul] } end BooleanRing instance : BooleanRing PUnit := ⟨fun _ => Subsingleton.elim _ _⟩ /-! ### Turning a Boolean ring into a Boolean algebra -/ section RingToAlgebra /-- Type synonym to view a Boolean ring as a Boolean algebra. -/ def AsBoolAlg (α : Type*) := α /-- The "identity" equivalence between `AsBoolAlg α` and `α`. -/ def toBoolAlg : α ≃ AsBoolAlg α := Equiv.refl _ /-- The "identity" equivalence between `α` and `AsBoolAlg α`. -/ def ofBoolAlg : AsBoolAlg α ≃ α := Equiv.refl _ @[simp] theorem toBoolAlg_symm_eq : (@toBoolAlg α).symm = ofBoolAlg := rfl @[simp] theorem ofBoolAlg_symm_eq : (@ofBoolAlg α).symm = toBoolAlg := rfl @[simp] theorem toBoolAlg_ofBoolAlg (a : AsBoolAlg α) : toBoolAlg (ofBoolAlg a) = a := rfl @[simp] theorem ofBoolAlg_toBoolAlg (a : α) : ofBoolAlg (toBoolAlg a) = a := rfl -- Porting note (#10618): simp can prove this -- @[simp] theorem toBoolAlg_inj {a b : α} : toBoolAlg a = toBoolAlg b ↔ a = b := Iff.rfl -- Porting note (#10618): simp can prove this -- @[simp] theorem ofBoolAlg_inj {a b : AsBoolAlg α} : ofBoolAlg a = ofBoolAlg b ↔ a = b := Iff.rfl instance [Inhabited α] : Inhabited (AsBoolAlg α) := ‹Inhabited α› variable [BooleanRing α] [BooleanRing β] [BooleanRing γ] namespace BooleanRing /-- The join operation in a Boolean ring is `x + y + x * y`. -/ def sup : Sup α := ⟨fun x y => x + y + x * y⟩ /-- The meet operation in a Boolean ring is `x * y`. -/ def inf : Inf α := ⟨(· * ·)⟩ -- Porting note (#11215): TODO: add priority 100. lower instance priority scoped [BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.sup scoped [BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.inf open BooleanAlgebraOfBooleanRing theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by dsimp only [(· ⊔ ·)] ring theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := by dsimp only [(· ⊓ ·)] ring theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := by dsimp only [(· ⊔ ·)] ring theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := by dsimp only [(· ⊓ ·)] ring theorem sup_inf_self (a b : α) : a ⊔ a ⊓ b = a := by dsimp only [(· ⊔ ·), (· ⊓ ·)] rw [← mul_assoc, mul_self, add_assoc, add_self, add_zero] theorem inf_sup_self (a b : α) : a ⊓ (a ⊔ b) = a := by dsimp only [(· ⊔ ·), (· ⊓ ·)] rw [mul_add, mul_add, mul_self, ← mul_assoc, mul_self, add_assoc, add_self, add_zero] theorem le_sup_inf_aux (a b c : α) : (a + b + a * b) * (a + c + a * c) = a + b * c + a * (b * c) := calc (a + b + a * b) * (a + c + a * c) = a * a + b * c + a * (b * c) + (a * b + a * a * b) + (a * c + a * a * c) + (a * b * c + a * a * b * c) := by ring _ = a + b * c + a * (b * c) := by simp only [mul_self, add_self, add_zero] theorem le_sup_inf (a b c : α) : (a ⊔ b) ⊓ (a ⊔ c) ⊔ (a ⊔ b ⊓ c) = a ⊔ b ⊓ c := by dsimp only [(· ⊔ ·), (· ⊓ ·)] rw [le_sup_inf_aux, add_self, mul_self, zero_add] /-- The Boolean algebra structure on a Boolean ring. The data is defined so that: * `a ⊔ b` unfolds to `a + b + a * b` * `a ⊓ b` unfolds to `a * b` * `a ≤ b` unfolds to `a + b + a * b = b` * `⊥` unfolds to `0` * `⊤` unfolds to `1` * `aᶜ` unfolds to `1 + a` * `a \ b` unfolds to `a * (1 + b)` -/ def toBooleanAlgebra : BooleanAlgebra α := { Lattice.mk' sup_comm sup_assoc inf_comm inf_assoc sup_inf_self inf_sup_self with le_sup_inf := le_sup_inf top := 1 le_top := fun a => show a + 1 + a * 1 = 1 by rw [mul_one, add_comm a 1, add_assoc, add_self, add_zero] bot := 0 bot_le := fun a => show 0 + a + 0 * a = a by rw [zero_mul, zero_add, add_zero] compl := fun a => 1 + a inf_compl_le_bot := fun a => show a * (1 + a) + 0 + a * (1 + a) * 0 = 0 by norm_num [mul_add, mul_self, add_self] top_le_sup_compl := fun a => by change 1 + (a + (1 + a) + a * (1 + a)) + 1 * (a + (1 + a) + a * (1 + a)) = a + (1 + a) + a * (1 + a) norm_num [mul_add, mul_self, add_self] rw [← add_assoc, add_self] } -- Porting note (#11215): TODO: add priority 100. lower instance priority scoped[BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.toBooleanAlgebra end BooleanRing instance : BooleanAlgebra (AsBoolAlg α) := @BooleanRing.toBooleanAlgebra α _ @[simp] theorem ofBoolAlg_top : ofBoolAlg (⊤ : AsBoolAlg α) = 1 := rfl @[simp] theorem ofBoolAlg_bot : ofBoolAlg (⊥ : AsBoolAlg α) = 0 := rfl @[simp] theorem ofBoolAlg_sup (a b : AsBoolAlg α) : ofBoolAlg (a ⊔ b) = ofBoolAlg a + ofBoolAlg b + ofBoolAlg a * ofBoolAlg b := rfl @[simp] theorem ofBoolAlg_inf (a b : AsBoolAlg α) : ofBoolAlg (a ⊓ b) = ofBoolAlg a * ofBoolAlg b := rfl @[simp] theorem ofBoolAlg_compl (a : AsBoolAlg α) : ofBoolAlg aᶜ = 1 + ofBoolAlg a := rfl @[simp] theorem ofBoolAlg_sdiff (a b : AsBoolAlg α) : ofBoolAlg (a \ b) = ofBoolAlg a * (1 + ofBoolAlg b) := rfl private theorem of_boolalg_symmDiff_aux (a b : α) : (a + b + a * b) * (1 + a * b) = a + b := calc (a + b + a * b) * (1 + a * b) _ = a + b + (a * b + a * b * (a * b)) + (a * (b * b) + a * a * b) := by ring _ = a + b := by simp only [mul_self, add_self, add_zero] @[simp] theorem ofBoolAlg_symmDiff (a b : AsBoolAlg α) : ofBoolAlg (a ∆ b) = ofBoolAlg a + ofBoolAlg b := by rw [symmDiff_eq_sup_sdiff_inf] exact of_boolalg_symmDiff_aux _ _ @[simp] theorem ofBoolAlg_mul_ofBoolAlg_eq_left_iff {a b : AsBoolAlg α} : ofBoolAlg a * ofBoolAlg b = ofBoolAlg a ↔ a ≤ b := @inf_eq_left (AsBoolAlg α) _ _ _ @[simp] theorem toBoolAlg_zero : toBoolAlg (0 : α) = ⊥ := rfl @[simp] theorem toBoolAlg_one : toBoolAlg (1 : α) = ⊤ := rfl @[simp] theorem toBoolAlg_mul (a b : α) : toBoolAlg (a * b) = toBoolAlg a ⊓ toBoolAlg b := rfl @[simp] theorem toBoolAlg_add_add_mul (a b : α) : toBoolAlg (a + b + a * b) = toBoolAlg a ⊔ toBoolAlg b := rfl @[simp] theorem toBoolAlg_add (a b : α) : toBoolAlg (a + b) = toBoolAlg a ∆ toBoolAlg b := (ofBoolAlg_symmDiff a b).symm /-- Turn a ring homomorphism from Boolean rings `α` to `β` into a bounded lattice homomorphism from `α` to `β` considered as Boolean algebras. -/ @[simps] protected def RingHom.asBoolAlg (f : α →+* β) : BoundedLatticeHom (AsBoolAlg α) (AsBoolAlg β) where toFun := toBoolAlg ∘ f ∘ ofBoolAlg map_sup' a b := by dsimp simp_rw [map_add f, map_mul f, toBoolAlg_add_add_mul] map_inf' := f.map_mul' map_top' := f.map_one' map_bot' := f.map_zero' @[simp] theorem RingHom.asBoolAlg_id : (RingHom.id α).asBoolAlg = BoundedLatticeHom.id _ := rfl @[simp] theorem RingHom.asBoolAlg_comp (g : β →+* γ) (f : α →+* β) : (g.comp f).asBoolAlg = g.asBoolAlg.comp f.asBoolAlg := rfl end RingToAlgebra /-! ### Turning a Boolean algebra into a Boolean ring -/ section AlgebraToRing /-- Type synonym to view a Boolean ring as a Boolean algebra. -/ def AsBoolRing (α : Type*) := α /-- The "identity" equivalence between `AsBoolRing α` and `α`. -/ def toBoolRing : α ≃ AsBoolRing α := Equiv.refl _ /-- The "identity" equivalence between `α` and `AsBoolRing α`. -/ def ofBoolRing : AsBoolRing α ≃ α := Equiv.refl _ @[simp] theorem toBoolRing_symm_eq : (@toBoolRing α).symm = ofBoolRing := rfl @[simp] theorem ofBoolRing_symm_eq : (@ofBoolRing α).symm = toBoolRing := rfl @[simp] theorem toBoolRing_ofBoolRing (a : AsBoolRing α) : toBoolRing (ofBoolRing a) = a := rfl @[simp] theorem ofBoolRing_toBoolRing (a : α) : ofBoolRing (toBoolRing a) = a := rfl -- Porting note (#10618): simp can prove this -- @[simp] theorem toBoolRing_inj {a b : α} : toBoolRing a = toBoolRing b ↔ a = b := Iff.rfl -- Porting note (#10618): simp can prove this -- @[simp] theorem ofBoolRing_inj {a b : AsBoolRing α} : ofBoolRing a = ofBoolRing b ↔ a = b := Iff.rfl instance [Inhabited α] : Inhabited (AsBoolRing α) := ‹Inhabited α› -- See note [reducible non-instances] /-- Every generalized Boolean algebra has the structure of a non unital commutative ring with the following data: * `a + b` unfolds to `a ∆ b` (symmetric difference) * `a * b` unfolds to `a ⊓ b` * `-a` unfolds to `a` * `0` unfolds to `⊥` -/ abbrev GeneralizedBooleanAlgebra.toNonUnitalCommRing [GeneralizedBooleanAlgebra α] : NonUnitalCommRing α where add := (· ∆ ·) add_assoc := symmDiff_assoc zero := ⊥ zero_add := bot_symmDiff add_zero := symmDiff_bot zero_mul := bot_inf_eq mul_zero := inf_bot_eq neg := id add_left_neg := symmDiff_self add_comm := symmDiff_comm mul := (· ⊓ ·) mul_assoc := inf_assoc mul_comm := inf_comm left_distrib := inf_symmDiff_distrib_left right_distrib := inf_symmDiff_distrib_right nsmul := letI : Zero α := ⟨⊥⟩; letI : Add α := ⟨(· ∆ ·)⟩; nsmulRec zsmul := letI : Zero α := ⟨⊥⟩; letI : Add α := ⟨(· ∆ ·)⟩; letI : Neg α := ⟨id⟩; zsmulRec instance [GeneralizedBooleanAlgebra α] : NonUnitalCommRing (AsBoolRing α) := @GeneralizedBooleanAlgebra.toNonUnitalCommRing α _ variable [BooleanAlgebra α] [BooleanAlgebra β] [BooleanAlgebra γ] -- See note [reducible non-instances] /-- Every Boolean algebra has the structure of a Boolean ring with the following data: * `a + b` unfolds to `a ∆ b` (symmetric difference) * `a * b` unfolds to `a ⊓ b` * `-a` unfolds to `a` * `0` unfolds to `⊥` * `1` unfolds to `⊤` -/ abbrev BooleanAlgebra.toBooleanRing : BooleanRing α where __ := GeneralizedBooleanAlgebra.toNonUnitalCommRing one := ⊤ one_mul := top_inf_eq mul_one := inf_top_eq mul_self := inf_idem scoped[BooleanRingOfBooleanAlgebra] attribute [instance] GeneralizedBooleanAlgebra.toNonUnitalCommRing BooleanAlgebra.toBooleanRing instance : BooleanRing (AsBoolRing α) := @BooleanAlgebra.toBooleanRing α _ @[simp] theorem ofBoolRing_zero : ofBoolRing (0 : AsBoolRing α) = ⊥ := rfl @[simp] theorem ofBoolRing_one : ofBoolRing (1 : AsBoolRing α) = ⊤ := rfl @[simp] theorem ofBoolRing_neg (a : AsBoolRing α) : ofBoolRing (-a) = ofBoolRing a := rfl @[simp] theorem ofBoolRing_add (a b : AsBoolRing α) : ofBoolRing (a + b) = ofBoolRing a ∆ ofBoolRing b := rfl @[simp] theorem ofBoolRing_sub (a b : AsBoolRing α) : ofBoolRing (a - b) = ofBoolRing a ∆ ofBoolRing b := rfl @[simp] theorem ofBoolRing_mul (a b : AsBoolRing α) : ofBoolRing (a * b) = ofBoolRing a ⊓ ofBoolRing b := rfl @[simp] theorem ofBoolRing_le_ofBoolRing_iff {a b : AsBoolRing α} : ofBoolRing a ≤ ofBoolRing b ↔ a * b = a := inf_eq_left.symm @[simp] theorem toBoolRing_bot : toBoolRing (⊥ : α) = 0 := rfl @[simp] theorem toBoolRing_top : toBoolRing (⊤ : α) = 1 := rfl @[simp] theorem toBoolRing_inf (a b : α) : toBoolRing (a ⊓ b) = toBoolRing a * toBoolRing b := rfl @[simp] theorem toBoolRing_symmDiff (a b : α) : toBoolRing (a ∆ b) = toBoolRing a + toBoolRing b := rfl /-- Turn a bounded lattice homomorphism from Boolean algebras `α` to `β` into a ring homomorphism from `α` to `β` considered as Boolean rings. -/ @[simps] protected def BoundedLatticeHom.asBoolRing (f : BoundedLatticeHom α β) : AsBoolRing α →+* AsBoolRing β where toFun := toBoolRing ∘ f ∘ ofBoolRing map_zero' := f.map_bot' map_one' := f.map_top' map_add' := map_symmDiff' f map_mul' := f.map_inf' @[simp] theorem BoundedLatticeHom.asBoolRing_id : (BoundedLatticeHom.id α).asBoolRing = RingHom.id _ := rfl @[simp] theorem BoundedLatticeHom.asBoolRing_comp (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) : (g.comp f).asBoolRing = g.asBoolRing.comp f.asBoolRing := rfl end AlgebraToRing /-! ### Equivalence between Boolean rings and Boolean algebras -/ /-- Order isomorphism between `α` considered as a Boolean ring considered as a Boolean algebra and `α`. -/ @[simps!] def OrderIso.asBoolAlgAsBoolRing (α : Type*) [BooleanAlgebra α] : AsBoolAlg (AsBoolRing α) ≃o α := ⟨ofBoolAlg.trans ofBoolRing, ofBoolRing_le_ofBoolRing_iff.trans ofBoolAlg_mul_ofBoolAlg_eq_left_iff⟩ /-- Ring isomorphism between `α` considered as a Boolean algebra considered as a Boolean ring and `α`. -/ @[simps!] def RingEquiv.asBoolRingAsBoolAlg (α : Type*) [BooleanRing α] : AsBoolRing (AsBoolAlg α) ≃+* α := { ofBoolRing.trans ofBoolAlg with map_mul' := fun _a _b => rfl map_add' := ofBoolAlg_symmDiff } open Bool instance : Zero Bool where zero := false instance : One Bool where one := true instance : Add Bool where add := xor instance : Neg Bool where neg := id instance : Sub Bool where sub := xor instance : Mul Bool where mul := and instance : BooleanRing Bool where add_assoc := xor_assoc zero_add := Bool.false_xor add_zero := Bool.xor_false sub_eq_add_neg _ _ := rfl add_left_neg := Bool.xor_self add_comm := xor_comm mul_assoc := and_assoc one_mul := Bool.true_and mul_one := Bool.and_true left_distrib := and_xor_distrib_left right_distrib := and_xor_distrib_right mul_self := Bool.and_self zero_mul a := rfl mul_zero a := by cases a <;> rfl nsmul := nsmulRec zsmul := zsmulRec
Algebra\Ring\Center.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Jireh Loreaux -/ import Mathlib.Algebra.Group.Center import Mathlib.Data.Int.Cast.Lemmas /-! # Centers of rings -/ variable {M : Type*} namespace Set variable (M) @[simp] theorem natCast_mem_center [NonAssocSemiring M] (n : ℕ) : (n : M) ∈ Set.center M where comm _ := by rw [Nat.commute_cast] left_assoc _ _ := by induction n with | zero => rw [Nat.cast_zero, zero_mul, zero_mul, zero_mul] | succ n ihn => rw [Nat.cast_succ, add_mul, one_mul, ihn, add_mul, add_mul, one_mul] mid_assoc _ _ := by induction n with | zero => rw [Nat.cast_zero, zero_mul, mul_zero, zero_mul] | succ n ihn => rw [Nat.cast_succ, add_mul, mul_add, add_mul, ihn, mul_add, one_mul, mul_one] right_assoc _ _ := by induction n with | zero => rw [Nat.cast_zero, mul_zero, mul_zero, mul_zero] | succ n ihn => rw [Nat.cast_succ, mul_add, ihn, mul_add, mul_add, mul_one, mul_one] -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_mem_center [NonAssocSemiring M] (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n)) ∈ Set.center M := natCast_mem_center M n @[simp] theorem intCast_mem_center [NonAssocRing M] (n : ℤ) : (n : M) ∈ Set.center M where comm _ := by rw [Int.commute_cast] left_assoc _ _ := match n with | (n : ℕ) => by rw [Int.cast_natCast, (natCast_mem_center _ n).left_assoc _ _] | Int.negSucc n => by rw [Int.cast_negSucc, Nat.cast_add, Nat.cast_one, neg_add_rev, add_mul, add_mul, add_mul, neg_mul, one_mul, neg_mul 1, one_mul, ← neg_mul, add_right_inj, neg_mul, (natCast_mem_center _ n).left_assoc _ _, neg_mul, neg_mul] mid_assoc _ _ := match n with | (n : ℕ) => by rw [Int.cast_natCast, (natCast_mem_center _ n).mid_assoc _ _] | Int.negSucc n => by simp only [Int.cast_negSucc, Nat.cast_add, Nat.cast_one, neg_add_rev] rw [add_mul, mul_add, add_mul, mul_add, neg_mul, one_mul] rw [neg_mul, mul_neg, mul_one, mul_neg, neg_mul, neg_mul] rw [(natCast_mem_center _ n).mid_assoc _ _] simp only [mul_neg] right_assoc _ _ := match n with | (n : ℕ) => by rw [Int.cast_natCast, (natCast_mem_center _ n).right_assoc _ _] | Int.negSucc n => by simp only [Int.cast_negSucc, Nat.cast_add, Nat.cast_one, neg_add_rev] rw [mul_add, mul_add, mul_add, mul_neg, mul_one, mul_neg, mul_neg, mul_one, mul_neg, add_right_inj, (natCast_mem_center _ n).right_assoc _ _, mul_neg, mul_neg] variable {M} @[simp] theorem add_mem_center [Distrib M] {a b : M} (ha : a ∈ Set.center M) (hb : b ∈ Set.center M) : a + b ∈ Set.center M where comm _ := by rw [add_mul, mul_add, ha.comm, hb.comm] left_assoc _ _ := by rw [add_mul, ha.left_assoc, hb.left_assoc, ← add_mul, ← add_mul] mid_assoc _ _ := by rw [mul_add, add_mul, ha.mid_assoc, hb.mid_assoc, ← mul_add, ← add_mul] right_assoc _ _ := by rw [mul_add, ha.right_assoc, hb.right_assoc, ← mul_add, ← mul_add] @[simp] theorem neg_mem_center [NonUnitalNonAssocRing M] {a : M} (ha : a ∈ Set.center M) : -a ∈ Set.center M where comm _ := by rw [← neg_mul_comm, ← ha.comm, neg_mul_comm] left_assoc _ _ := by rw [neg_mul, ha.left_assoc, neg_mul, neg_mul] mid_assoc _ _ := by rw [← neg_mul_comm, ha.mid_assoc, neg_mul_comm, neg_mul] right_assoc _ _ := by rw [mul_neg, ha.right_assoc, mul_neg, mul_neg] end Set -- Guard against import creep assert_not_exists Finset assert_not_exists Subsemigroup
Algebra\Ring\Centralizer.lean
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Jireh Loreaux -/ import Mathlib.Algebra.Group.Center import Mathlib.Algebra.Ring.Defs /-! # Centralizers of rings -/ variable {M : Type*} {S T : Set M} namespace Set variable {a b} @[simp] theorem add_mem_centralizer [Distrib M] (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) : a + b ∈ centralizer S := fun c hc => by rw [add_mul, mul_add, ha c hc, hb c hc] @[simp] theorem neg_mem_centralizer [Mul M] [HasDistribNeg M] (ha : a ∈ centralizer S) : -a ∈ centralizer S := fun c hc => by rw [mul_neg, ha c hc, neg_mul] end Set
Algebra\Ring\CentroidHom.lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Christopher Hoskin -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.Module.Hom import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.RingTheory.NonUnitalSubsemiring.Basic import Mathlib.Algebra.Ring.Subsemiring.Basic /-! # Centroid homomorphisms Let `A` be a (non unital, non associative) algebra. The centroid of `A` is the set of linear maps `T` on `A` such that `T` commutes with left and right multiplication, that is to say, for all `a` and `b` in `A`, $$ T(ab) = (Ta)b, T(ab) = a(Tb). $$ In mathlib we call elements of the centroid "centroid homomorphisms" (`CentroidHom`) in keeping with `AddMonoidHom` etc. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `CentroidHom`: Maps which preserve left and right multiplication. ## Typeclasses * `CentroidHomClass` ## References * [Jacobson, Structure of Rings][Jacobson1956] * [McCrimmon, A taste of Jordan algebras][mccrimmon2004] ## Tags centroid -/ assert_not_exists Field open Function variable {F M N R α : Type*} /-- The type of centroid homomorphisms from `α` to `α`. -/ structure CentroidHom (α : Type*) [NonUnitalNonAssocSemiring α] extends α →+ α where /-- Commutativity of centroid homomorphims with left multiplication. -/ map_mul_left' (a b : α) : toFun (a * b) = a * toFun b /-- Commutativity of centroid homomorphims with right multiplication. -/ map_mul_right' (a b : α) : toFun (a * b) = toFun a * b attribute [nolint docBlame] CentroidHom.toAddMonoidHom /-- `CentroidHomClass F α` states that `F` is a type of centroid homomorphisms. You should extend this class when you extend `CentroidHom`. -/ class CentroidHomClass (F α : Type*) [NonUnitalNonAssocSemiring α] [FunLike F α α] extends AddMonoidHomClass F α α : Prop where /-- Commutativity of centroid homomorphims with left multiplication. -/ map_mul_left (f : F) (a b : α) : f (a * b) = a * f b /-- Commutativity of centroid homomorphims with right multiplication. -/ map_mul_right (f : F) (a b : α) : f (a * b) = f a * b export CentroidHomClass (map_mul_left map_mul_right) instance [NonUnitalNonAssocSemiring α] [FunLike F α α] [CentroidHomClass F α] : CoeTC F (CentroidHom α) := ⟨fun f ↦ { (f : α →+ α) with toFun := f map_mul_left' := map_mul_left f map_mul_right' := map_mul_right f }⟩ /-! ### Centroid homomorphisms -/ namespace CentroidHom section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] instance : FunLike (CentroidHom α) α α where coe f := f.toFun coe_injective' f g h := by cases f cases g congr with x exact congrFun h x instance : CentroidHomClass (CentroidHom α) α where map_zero f := f.map_zero' map_add f := f.map_add' map_mul_left f := f.map_mul_left' map_mul_right f := f.map_mul_right' /-- Helper instance for when there's too many metavariables to apply `DFunLike.CoeFun` directly. -/ /- Porting note: Lean gave me `unknown constant 'DFunLike.CoeFun'` and says `CoeFun` is a type mismatch, so I used `library_search`. -/ instance : CoeFun (CentroidHom α) fun _ ↦ α → α := inferInstanceAs (CoeFun (CentroidHom α) fun _ ↦ α → α) -- Porting note: removed @[simp]; not in normal form. (`toAddMonoidHom_eq_coe` below ensures that -- the LHS simplifies to the RHS anyway.) theorem toFun_eq_coe {f : CentroidHom α} : f.toFun = f := rfl @[ext] theorem ext {f g : CentroidHom α} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h @[simp, norm_cast] theorem coe_toAddMonoidHom (f : CentroidHom α) : ⇑(f : α →+ α) = f := rfl @[simp] theorem toAddMonoidHom_eq_coe (f : CentroidHom α) : f.toAddMonoidHom = f := rfl theorem coe_toAddMonoidHom_injective : Injective ((↑) : CentroidHom α → α →+ α) := fun _f _g h => ext fun a ↦ haveI := DFunLike.congr_fun h a this /-- Turn a centroid homomorphism into an additive monoid endomorphism. -/ def toEnd (f : CentroidHom α) : AddMonoid.End α := (f : α →+ α) theorem toEnd_injective : Injective (CentroidHom.toEnd : CentroidHom α → AddMonoid.End α) := coe_toAddMonoidHom_injective /-- Copy of a `CentroidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : CentroidHom α) (f' : α → α) (h : f' = f) : CentroidHom α := { f.toAddMonoidHom.copy f' <| h with toFun := f' map_mul_left' := fun a b ↦ by simp_rw [h, map_mul_left] map_mul_right' := fun a b ↦ by simp_rw [h, map_mul_right] } @[simp] theorem coe_copy (f : CentroidHom α) (f' : α → α) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : CentroidHom α) (f' : α → α) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable (α) /-- `id` as a `CentroidHom`. -/ protected def id : CentroidHom α := { AddMonoidHom.id α with map_mul_left' := fun _ _ ↦ rfl map_mul_right' := fun _ _ ↦ rfl } instance : Inhabited (CentroidHom α) := ⟨CentroidHom.id α⟩ @[simp, norm_cast] theorem coe_id : ⇑(CentroidHom.id α) = id := rfl @[simp, norm_cast] theorem toAddMonoidHom_id : (CentroidHom.id α : α →+ α) = AddMonoidHom.id α := rfl variable {α} @[simp] theorem id_apply (a : α) : CentroidHom.id α a = a := rfl /-- Composition of `CentroidHom`s as a `CentroidHom`. -/ def comp (g f : CentroidHom α) : CentroidHom α := { g.toAddMonoidHom.comp f.toAddMonoidHom with map_mul_left' := fun _a _b ↦ (congr_arg g <| f.map_mul_left' _ _).trans <| g.map_mul_left' _ _ map_mul_right' := fun _a _b ↦ (congr_arg g <| f.map_mul_right' _ _).trans <| g.map_mul_right' _ _ } @[simp, norm_cast] theorem coe_comp (g f : CentroidHom α) : ⇑(g.comp f) = g ∘ f := rfl @[simp] theorem comp_apply (g f : CentroidHom α) (a : α) : g.comp f a = g (f a) := rfl @[simp, norm_cast] theorem coe_comp_addMonoidHom (g f : CentroidHom α) : (g.comp f : α →+ α) = (g : α →+ α).comp f := rfl @[simp] theorem comp_assoc (h g f : CentroidHom α) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem comp_id (f : CentroidHom α) : f.comp (CentroidHom.id α) = f := rfl @[simp] theorem id_comp (f : CentroidHom α) : (CentroidHom.id α).comp f = f := rfl @[simp] theorem cancel_right {g₁ g₂ f : CentroidHom α} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h ↦ ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun a ↦ congrFun (congrArg comp a) f⟩ @[simp] theorem cancel_left {g f₁ f₂ : CentroidHom α} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h ↦ ext fun a ↦ hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩ instance : Zero (CentroidHom α) := ⟨{ (0 : α →+ α) with map_mul_left' := fun _a _b ↦ (mul_zero _).symm map_mul_right' := fun _a _b ↦ (zero_mul _).symm }⟩ instance : One (CentroidHom α) := ⟨CentroidHom.id α⟩ instance : Add (CentroidHom α) := ⟨fun f g ↦ { (f + g : α →+ α) with map_mul_left' := fun a b ↦ by show f (a * b) + g (a * b) = a * (f b + g b) simp [map_mul_left, mul_add] map_mul_right' := fun a b ↦ by show f (a * b) + g (a * b) = (f a + g a) * b simp [map_mul_right, add_mul] }⟩ instance : Mul (CentroidHom α) := ⟨comp⟩ variable [Monoid M] [Monoid N] [Semiring R] variable [DistribMulAction M α] [SMulCommClass M α α] [IsScalarTower M α α] variable [DistribMulAction N α] [SMulCommClass N α α] [IsScalarTower N α α] variable [Module R α] [SMulCommClass R α α] [IsScalarTower R α α] instance instSMul : SMul M (CentroidHom α) where smul n f := { (n • f : α →+ α) with map_mul_left' := fun a b ↦ by change n • f (a * b) = a * n • f b rw [map_mul_left f, ← mul_smul_comm] map_mul_right' := fun a b ↦ by change n • f (a * b) = n • f a * b rw [map_mul_right f, ← smul_mul_assoc] } instance [SMul M N] [IsScalarTower M N α] : IsScalarTower M N (CentroidHom α) where smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _ instance [SMulCommClass M N α] : SMulCommClass M N (CentroidHom α) where smul_comm _ _ _ := ext fun _ => smul_comm _ _ _ instance [DistribMulAction Mᵐᵒᵖ α] [IsCentralScalar M α] : IsCentralScalar M (CentroidHom α) where op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _ instance isScalarTowerRight : IsScalarTower M (CentroidHom α) (CentroidHom α) where smul_assoc _ _ _ := rfl instance hasNPowNat : Pow (CentroidHom α) ℕ := ⟨fun f n ↦ { toAddMonoidHom := (f.toEnd ^ n : AddMonoid.End α) map_mul_left' := fun a b ↦ by induction' n with n ih · exact rfl · rw [pow_succ'] exact (congr_arg f.toEnd ih).trans (f.map_mul_left' _ _) map_mul_right' := fun a b ↦ by induction' n with n ih · exact rfl · rw [pow_succ'] exact (congr_arg f.toEnd ih).trans (f.map_mul_right' _ _) }⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : CentroidHom α) = 0 := rfl @[simp, norm_cast] theorem coe_one : ⇑(1 : CentroidHom α) = id := rfl @[simp, norm_cast] theorem coe_add (f g : CentroidHom α) : ⇑(f + g) = f + g := rfl @[simp, norm_cast] theorem coe_mul (f g : CentroidHom α) : ⇑(f * g) = f ∘ g := rfl @[simp, norm_cast] theorem coe_smul (n : M) (f : CentroidHom α) : ⇑(n • f) = n • ⇑f := rfl @[simp] theorem zero_apply (a : α) : (0 : CentroidHom α) a = 0 := rfl @[simp] theorem one_apply (a : α) : (1 : CentroidHom α) a = a := rfl @[simp] theorem add_apply (f g : CentroidHom α) (a : α) : (f + g) a = f a + g a := rfl @[simp] theorem mul_apply (f g : CentroidHom α) (a : α) : (f * g) a = f (g a) := rfl @[simp] theorem smul_apply (n : M) (f : CentroidHom α) (a : α) : (n • f) a = n • f a := rfl example : SMul ℕ (CentroidHom α) := instSMul @[simp] theorem toEnd_zero : (0 : CentroidHom α).toEnd = 0 := rfl @[simp] theorem toEnd_add (x y : CentroidHom α) : (x + y).toEnd = x.toEnd + y.toEnd := rfl theorem toEnd_smul (m : M) (x : CentroidHom α) : (m • x).toEnd = m • x.toEnd := rfl instance : AddCommMonoid (CentroidHom α) := coe_toAddMonoidHom_injective.addCommMonoid _ toEnd_zero toEnd_add (swap toEnd_smul) instance : NatCast (CentroidHom α) where natCast n := n • (1 : CentroidHom α) @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ⇑(n : CentroidHom α) = n • (CentroidHom.id α) := rfl @[deprecated (since := "2024-04-17")] alias coe_nat_cast := coe_natCast theorem natCast_apply (n : ℕ) (m : α) : (n : CentroidHom α) m = n • m := rfl @[deprecated (since := "2024-04-17")] alias nat_cast_apply := natCast_apply @[simp] theorem toEnd_one : (1 : CentroidHom α).toEnd = 1 := rfl @[simp] theorem toEnd_mul (x y : CentroidHom α) : (x * y).toEnd = x.toEnd * y.toEnd := rfl @[simp] theorem toEnd_pow (x : CentroidHom α) (n : ℕ) : (x ^ n).toEnd = x.toEnd ^ n := rfl @[simp, norm_cast] theorem toEnd_natCast (n : ℕ) : (n : CentroidHom α).toEnd = ↑n := rfl @[deprecated (since := "2024-04-17")] alias toEnd_nat_cast := toEnd_natCast -- cf `add_monoid.End.semiring` instance : Semiring (CentroidHom α) := toEnd_injective.semiring _ toEnd_zero toEnd_one toEnd_add toEnd_mul toEnd_smul toEnd_pow toEnd_natCast variable (α) in /-- `CentroidHom.toEnd` as a `RingHom`. -/ @[simps] def toEndRingHom : CentroidHom α →+* AddMonoid.End α where toFun := toEnd map_zero' := toEnd_zero map_one' := toEnd_one map_add' := toEnd_add map_mul' := toEnd_mul theorem comp_mul_comm (T S : CentroidHom α) (a b : α) : (T ∘ S) (a * b) = (S ∘ T) (a * b) := by simp only [Function.comp_apply] rw [map_mul_right, map_mul_left, ← map_mul_right, ← map_mul_left] instance : DistribMulAction M (CentroidHom α) := toEnd_injective.distribMulAction (toEndRingHom α).toAddMonoidHom toEnd_smul instance : Module R (CentroidHom α) := toEnd_injective.module R (toEndRingHom α).toAddMonoidHom toEnd_smul /-! The following instances show that `α` is a non-unital and non-associative algebra over `CentroidHom α`. -/ /-- The tautological action by `CentroidHom α` on `α`. This generalizes `Function.End.applyMulAction`. -/ instance applyModule : Module (CentroidHom α) α where smul T a := T a add_smul _ _ _ := rfl zero_smul _ := rfl one_smul _ := rfl mul_smul _ _ _ := rfl smul_zero := map_zero smul_add := map_add @[simp] lemma smul_def (T : CentroidHom α) (a : α) : T • a = T a := rfl instance : SMulCommClass (CentroidHom α) α α where smul_comm _ _ _ := map_mul_left _ _ _ instance : SMulCommClass α (CentroidHom α) α := SMulCommClass.symm _ _ _ instance : IsScalarTower (CentroidHom α) α α where smul_assoc _ _ _ := (map_mul_right _ _ _).symm /-! Let `α` be an algebra over `R`, such that the canonical ring homomorphism of `R` into `CentroidHom α` lies in the center of `CentroidHom α`. Then `CentroidHom α` is an algebra over `R` -/ variable {R : Type*} variable [CommSemiring R] variable [Module R α] [SMulCommClass R α α] [IsScalarTower R α α] /-- The natural ring homomorphism from `R` into `CentroidHom α`. This is a stronger version of `Module.toAddMonoidEnd`. -/ @[simps! apply_toFun] def _root_.Module.toCentroidHom : R →+* CentroidHom α := RingHom.smulOneHom open Module in /-- `CentroidHom α` as an algebra over `R`. -/ example (h : ∀ (r : R) (T : CentroidHom α), toCentroidHom r * T = T * toCentroidHom r) : Algebra R (CentroidHom α) := toCentroidHom.toAlgebra' h local notation "L" => AddMonoid.End.mulLeft local notation "R" => AddMonoid.End.mulRight lemma centroid_eq_centralizer_mulLeftRight : RingHom.rangeS (toEndRingHom α) = Subsemiring.centralizer (Set.range L ∪ Set.range R) := by ext T refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, rfl⟩ S (⟨a, rfl⟩ | ⟨b, rfl⟩) · exact AddMonoidHom.ext fun b ↦ (map_mul_left f a b).symm · exact AddMonoidHom.ext fun a ↦ (map_mul_right f a b).symm · rw [Subsemiring.mem_centralizer_iff] at h refine ⟨⟨T, fun a b ↦ ?_, fun a b ↦ ?_⟩, rfl⟩ · exact congr($(h (L a) (.inl ⟨a, rfl⟩)) b).symm · exact congr($(h (R b) (.inr ⟨b, rfl⟩)) a).symm /-- The canonical homomorphism from the center into the center of the centroid -/ def centerToCentroidCenter : NonUnitalSubsemiring.center α →ₙ+* Subsemiring.center (CentroidHom α) where toFun z := { L (z : α) with val := ⟨L z, z.prop.left_comm, z.prop.left_assoc ⟩ property := by rw [Subsemiring.mem_center_iff] intros g ext a exact map_mul_left g (↑z) a } map_zero' := by simp only [ZeroMemClass.coe_zero, map_zero] exact rfl map_add' := fun _ _ => by simp only [AddSubmonoid.coe_add, NonUnitalSubsemiring.coe_toAddSubmonoid, map_add] exact rfl map_mul' z₁ z₂ := by ext a; exact (z₁.prop.left_assoc z₂ a).symm instance : FunLike (Subsemiring.center (CentroidHom α)) α α where coe f := f.val.toFun coe_injective' f g h := by cases f cases g congr with x exact congrFun h x lemma centerToCentroidCenter_apply (z : NonUnitalSubsemiring.center α) (a : α) : (centerToCentroidCenter z) a = z * a := rfl /-- The canonical homomorphism from the center into the centroid -/ def centerToCentroid : NonUnitalSubsemiring.center α →ₙ+* CentroidHom α := NonUnitalRingHom.comp (SubsemiringClass.subtype (Subsemiring.center (CentroidHom α))).toNonUnitalRingHom centerToCentroidCenter lemma centerToCentroid_apply (z : NonUnitalSubsemiring.center α) (a : α) : (centerToCentroid z) a = z * a := rfl lemma _root_.NonUnitalNonAssocSemiring.mem_center_iff (a : α) : a ∈ NonUnitalSubsemiring.center α ↔ R a = L a ∧ (L a) ∈ RingHom.rangeS (toEndRingHom α) := by constructor · exact fun ha ↦ ⟨AddMonoidHom.ext <| fun _ => (IsMulCentral.comm ha _).symm, ⟨centerToCentroid ⟨a, ha⟩, rfl⟩⟩ · rintro ⟨hc, ⟨T, hT⟩⟩ have e1 (d : α) : T d = a * d := congr($hT d) have e2 (d : α) : T d = d * a := congr($(hT.trans hc.symm) d) constructor case comm => exact (congr($hc.symm ·)) case left_assoc => simpa [e1] using (map_mul_right T · ·) case mid_assoc => exact fun b c ↦ by simpa [e1 c, e2 b] using (map_mul_right T b c).symm.trans <| map_mul_left T b c case right_assoc => simpa [e2] using (map_mul_left T · ·) end NonUnitalNonAssocSemiring section NonUnitalNonAssocCommSemiring variable [NonUnitalNonAssocCommSemiring α] /- Left and right multiplication coincide as α is commutative -/ local notation "L" => AddMonoid.End.mulLeft lemma _root_.NonUnitalNonAssocCommSemiring.mem_center_iff (a : α) : a ∈ NonUnitalSubsemiring.center α ↔ ∀ b : α, Commute (L b) (L a) := by rw [NonUnitalNonAssocSemiring.mem_center_iff, CentroidHom.centroid_eq_centralizer_mulLeftRight, Subsemiring.mem_centralizer_iff, AddMonoid.End.mulRight_eq_mulLeft, Set.union_self] aesop end NonUnitalNonAssocCommSemiring section NonAssocSemiring variable [NonAssocSemiring α] /-- The canonical isomorphism from the center of a (non-associative) semiring onto its centroid. -/ def centerIsoCentroid : Subsemiring.center α ≃+* CentroidHom α := { centerToCentroid with invFun := fun T ↦ ⟨T 1, by refine ⟨?_, ?_, ?_, ?_⟩; all_goals simp [← map_mul_left, ← map_mul_right]⟩ left_inv := fun z ↦ Subtype.ext <| by simp only [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom, centerToCentroid_apply, mul_one] right_inv := fun T ↦ CentroidHom.ext <| fun _ => by rw [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom, centerToCentroid_apply, ← map_mul_right, one_mul] } end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] /-- Negation of `CentroidHom`s as a `CentroidHom`. -/ instance : Neg (CentroidHom α) := ⟨fun f ↦ { (-f : α →+ α) with map_mul_left' := fun a b ↦ by change -f (a * b) = a * (-f b) simp [map_mul_left] map_mul_right' := fun a b ↦ by change -f (a * b) = (-f a) * b simp [map_mul_right] }⟩ instance : Sub (CentroidHom α) := ⟨fun f g ↦ { (f - g : α →+ α) with map_mul_left' := fun a b ↦ by change (⇑f - ⇑g) (a * b) = a * (⇑f - ⇑g) b simp [map_mul_left, mul_sub] map_mul_right' := fun a b ↦ by change (⇑f - ⇑g) (a * b) = ((⇑f - ⇑g) a) * b simp [map_mul_right, sub_mul] }⟩ instance : IntCast (CentroidHom α) where intCast z := z • (1 : CentroidHom α) @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ⇑(z : CentroidHom α) = z • (CentroidHom.id α) := rfl @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast theorem intCast_apply (z : ℤ) (m : α) : (z : CentroidHom α) m = z • m := rfl @[deprecated (since := "2024-04-17")] alias int_cast_apply := intCast_apply @[simp] theorem toEnd_neg (x : CentroidHom α) : (-x).toEnd = -x.toEnd := rfl @[simp] theorem toEnd_sub (x y : CentroidHom α) : (x - y).toEnd = x.toEnd - y.toEnd := rfl instance : AddCommGroup (CentroidHom α) := toEnd_injective.addCommGroup _ toEnd_zero toEnd_add toEnd_neg toEnd_sub (swap toEnd_smul) (swap toEnd_smul) @[simp, norm_cast] theorem coe_neg (f : CentroidHom α) : ⇑(-f) = -f := rfl @[simp, norm_cast] theorem coe_sub (f g : CentroidHom α) : ⇑(f - g) = f - g := rfl @[simp] theorem neg_apply (f : CentroidHom α) (a : α) : (-f) a = -f a := rfl @[simp] theorem sub_apply (f g : CentroidHom α) (a : α) : (f - g) a = f a - g a := rfl @[simp, norm_cast] theorem toEnd_intCast (z : ℤ) : (z : CentroidHom α).toEnd = ↑z := rfl @[deprecated (since := "2024-04-17")] alias toEnd_int_cast := toEnd_intCast instance instRing : Ring (CentroidHom α) := toEnd_injective.ring _ toEnd_zero toEnd_one toEnd_add toEnd_mul toEnd_neg toEnd_sub toEnd_smul toEnd_smul toEnd_pow toEnd_natCast toEnd_intCast end NonUnitalNonAssocRing section NonUnitalRing variable [NonUnitalRing α] -- Porting note: Not sure why Lean didn't like `CentroidHom.Ring` -- See note [reducible non instances] /-- A prime associative ring has commutative centroid. -/ abbrev commRing (h : ∀ a b : α, (∀ r : α, a * r * b = 0) → a = 0 ∨ b = 0) : CommRing (CentroidHom α) := { CentroidHom.instRing with mul_comm := fun f g ↦ by ext refine sub_eq_zero.1 (or_self_iff.1 <| (h _ _) fun r ↦ ?_) rw [mul_assoc, sub_mul, sub_eq_zero, ← map_mul_right, ← map_mul_right, coe_mul, coe_mul, comp_mul_comm] } end NonUnitalRing end CentroidHom
Algebra\Ring\Commute.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Ring.Semiconj import Mathlib.Algebra.Ring.Units import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Data.Bracket /-! # Semirings and rings This file gives lemmas about semirings, rings and domains. This is analogous to `Mathlib.Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. For the definitions of semirings and rings see `Mathlib.Algebra.Ring.Defs`. -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {R : Type x} open Function namespace Commute @[simp] theorem add_right [Distrib R] {a b c : R} : Commute a b → Commute a c → Commute a (b + c) := SemiconjBy.add_right -- for some reason mathport expected `Semiring` instead of `Distrib`? @[simp] theorem add_left [Distrib R] {a b c : R} : Commute a c → Commute b c → Commute (a + b) c := SemiconjBy.add_left -- for some reason mathport expected `Semiring` instead of `Distrib`? /-- Representation of a difference of two squares of commuting elements as a product. -/ theorem mul_self_sub_mul_self_eq [NonUnitalNonAssocRing R] {a b : R} (h : Commute a b) : a * a - b * b = (a + b) * (a - b) := by rw [add_mul, mul_sub, mul_sub, h.eq, sub_add_sub_cancel] theorem mul_self_sub_mul_self_eq' [NonUnitalNonAssocRing R] {a b : R} (h : Commute a b) : a * a - b * b = (a - b) * (a + b) := by rw [mul_add, sub_mul, sub_mul, h.eq, sub_add_sub_cancel] theorem mul_self_eq_mul_self_iff [NonUnitalNonAssocRing R] [NoZeroDivisors R] {a b : R} (h : Commute a b) : a * a = b * b ↔ a = b ∨ a = -b := by rw [← sub_eq_zero, h.mul_self_sub_mul_self_eq, mul_eq_zero, or_comm, sub_eq_zero, add_eq_zero_iff_eq_neg] section variable [Mul R] [HasDistribNeg R] {a b : R} theorem neg_right : Commute a b → Commute a (-b) := SemiconjBy.neg_right @[simp] theorem neg_right_iff : Commute a (-b) ↔ Commute a b := SemiconjBy.neg_right_iff theorem neg_left : Commute a b → Commute (-a) b := SemiconjBy.neg_left @[simp] theorem neg_left_iff : Commute (-a) b ↔ Commute a b := SemiconjBy.neg_left_iff end section variable [MulOneClass R] [HasDistribNeg R] {a : R} -- Porting note (#10618): no longer needs to be `@[simp]` since `simp` can prove it. -- @[simp] theorem neg_one_right (a : R) : Commute a (-1) := SemiconjBy.neg_one_right a -- Porting note (#10618): no longer needs to be `@[simp]` since `simp` can prove it. -- @[simp] theorem neg_one_left (a : R) : Commute (-1) a := SemiconjBy.neg_one_left a end section variable [NonUnitalNonAssocRing R] {a b c : R} @[simp] theorem sub_right : Commute a b → Commute a c → Commute a (b - c) := SemiconjBy.sub_right @[simp] theorem sub_left : Commute a c → Commute b c → Commute (a - b) c := SemiconjBy.sub_left end section Ring variable [Ring R] {a b : R} protected lemma sq_sub_sq (h : Commute a b) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by rw [sq, sq, h.mul_self_sub_mul_self_eq] variable [NoZeroDivisors R] protected lemma sq_eq_sq_iff_eq_or_eq_neg (h : Commute a b) : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := by rw [← sub_eq_zero, h.sq_sub_sq, mul_eq_zero, add_eq_zero_iff_eq_neg, sub_eq_zero, or_comm] end Ring end Commute section HasDistribNeg variable (R) variable [Monoid R] [HasDistribNeg R] lemma neg_one_pow_eq_or : ∀ n : ℕ, (-1 : R) ^ n = 1 ∨ (-1 : R) ^ n = -1 | 0 => Or.inl (pow_zero _) | n + 1 => (neg_one_pow_eq_or n).symm.imp (fun h ↦ by rw [pow_succ, h, neg_one_mul, neg_neg]) (fun h ↦ by rw [pow_succ, h, one_mul]) variable {R} lemma neg_pow (a : R) (n : ℕ) : (-a) ^ n = (-1) ^ n * a ^ n := neg_one_mul a ▸ (Commute.neg_one_left a).mul_pow n lemma neg_pow' (a : R) (n : ℕ) : (-a) ^ n = a ^ n * (-1) ^ n := mul_neg_one a ▸ (Commute.neg_one_right a).mul_pow n lemma neg_sq (a : R) : (-a) ^ 2 = a ^ 2 := by simp [sq] -- Porting note: removed the simp attribute to please the simpNF linter lemma neg_one_sq : (-1 : R) ^ 2 = 1 := by simp [neg_sq, one_pow] alias neg_pow_two := neg_sq alias neg_one_pow_two := neg_one_sq end HasDistribNeg section Ring variable [Ring R] {a b : R} {n : ℕ} @[simp] lemma neg_one_pow_mul_eq_zero_iff : (-1) ^ n * a = 0 ↔ a = 0 := by rcases neg_one_pow_eq_or R n with h | h <;> simp [h] @[simp] lemma mul_neg_one_pow_eq_zero_iff : a * (-1) ^ n = 0 ↔ a = 0 := by obtain h | h := neg_one_pow_eq_or R n <;> simp [h] lemma neg_one_pow_eq_pow_mod_two (n : ℕ) : (-1 : R) ^ n = (-1) ^ (n % 2) := by rw [← Nat.mod_add_div n 2, pow_add, pow_mul]; simp [sq] variable [NoZeroDivisors R] @[simp] lemma sq_eq_one_iff : a ^ 2 = 1 ↔ a = 1 ∨ a = -1 := by rw [← (Commute.one_right a).sq_eq_sq_iff_eq_or_eq_neg, one_pow] lemma sq_ne_one_iff : a ^ 2 ≠ 1 ↔ a ≠ 1 ∧ a ≠ -1 := sq_eq_one_iff.not.trans not_or end Ring /-- Representation of a difference of two squares in a commutative ring as a product. -/ theorem mul_self_sub_mul_self [CommRing R] (a b : R) : a * a - b * b = (a + b) * (a - b) := (Commute.all a b).mul_self_sub_mul_self_eq theorem mul_self_sub_one [NonAssocRing R] (a : R) : a * a - 1 = (a + 1) * (a - 1) := by rw [← (Commute.one_right a).mul_self_sub_mul_self_eq, mul_one] theorem mul_self_eq_mul_self_iff [CommRing R] [NoZeroDivisors R] {a b : R} : a * a = b * b ↔ a = b ∨ a = -b := (Commute.all a b).mul_self_eq_mul_self_iff theorem mul_self_eq_one_iff [NonAssocRing R] [NoZeroDivisors R] {a : R} : a * a = 1 ↔ a = 1 ∨ a = -1 := by rw [← (Commute.one_right a).mul_self_eq_mul_self_iff, mul_one] section CommRing variable [CommRing R] lemma sq_sub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := (Commute.all a b).sq_sub_sq alias pow_two_sub_pow_two := sq_sub_sq lemma sub_sq (a b : R) : (a - b) ^ 2 = a ^ 2 - 2 * a * b + b ^ 2 := by rw [sub_eq_add_neg, add_sq, neg_sq, mul_neg, ← sub_eq_add_neg] alias sub_pow_two := sub_sq lemma sub_sq' (a b : R) : (a - b) ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b := by rw [sub_eq_add_neg, add_sq', neg_sq, mul_neg, ← sub_eq_add_neg] variable [NoZeroDivisors R] {a b : R} lemma sq_eq_sq_iff_eq_or_eq_neg : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := (Commute.all a b).sq_eq_sq_iff_eq_or_eq_neg lemma eq_or_eq_neg_of_sq_eq_sq (a b : R) : a ^ 2 = b ^ 2 → a = b ∨ a = -b := sq_eq_sq_iff_eq_or_eq_neg.1 -- Copies of the above CommRing lemmas for `Units R`. namespace Units protected lemma sq_eq_sq_iff_eq_or_eq_neg {a b : Rˣ} : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := by simp_rw [Units.ext_iff, val_pow_eq_pow_val, sq_eq_sq_iff_eq_or_eq_neg, Units.val_neg] protected lemma eq_or_eq_neg_of_sq_eq_sq (a b : Rˣ) (h : a ^ 2 = b ^ 2) : a = b ∨ a = -b := Units.sq_eq_sq_iff_eq_or_eq_neg.1 h end Units end CommRing namespace Units /-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or one's additive inverse. -/ theorem inv_eq_self_iff [Ring R] [NoZeroDivisors R] (u : Rˣ) : u⁻¹ = u ↔ u = 1 ∨ u = -1 := by rw [inv_eq_iff_mul_eq_one] simp only [Units.ext_iff] push_cast exact mul_self_eq_one_iff end Units section Bracket variable [NonUnitalNonAssocRing R] namespace Ring instance (priority := 100) instBracket : Bracket R R := ⟨fun x y => x * y - y * x⟩ theorem lie_def (x y : R) : ⁅x, y⁆ = x * y - y * x := rfl end Ring theorem commute_iff_lie_eq {x y : R} : Commute x y ↔ ⁅x, y⁆ = 0 := sub_eq_zero.symm theorem Commute.lie_eq {x y : R} (h : Commute x y) : ⁅x, y⁆ = 0 := sub_eq_zero_of_eq h end Bracket
Algebra\Ring\CompTypeclasses.lean
/- Copyright (c) 2021 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Ring.Equiv /-! # Propositional typeclasses on several ring homs This file contains three typeclasses used in the definition of (semi)linear maps: * `RingHomId σ`, which expresses the fact that `σ₂₃ = id` * `RingHomCompTriple σ₁₂ σ₂₃ σ₁₃`, which expresses the fact that `σ₂₃.comp σ₁₂ = σ₁₃` * `RingHomInvPair σ₁₂ σ₂₁`, which states that `σ₁₂` and `σ₂₁` are inverses of each other * `RingHomSurjective σ`, which states that `σ` is surjective These typeclasses ensure that objects such as `σ₂₃.comp σ₁₂` never end up in the type of a semilinear map; instead, the typeclass system directly finds the appropriate `RingHom` to use. A typical use-case is conjugate-linear maps, i.e. when `σ = Complex.conj`; this system ensures that composing two conjugate-linear maps is a linear map, and not a `conj.comp conj`-linear map. Instances of these typeclasses mostly involving `RingHom.id` are also provided: * `RingHomInvPair (RingHom.id R) (RingHom.id R)` * `[RingHomInvPair σ₁₂ σ₂₁] : RingHomCompTriple σ₁₂ σ₂₁ (RingHom.id R₁)` * `RingHomCompTriple (RingHom.id R₁) σ₁₂ σ₁₂` * `RingHomCompTriple σ₁₂ (RingHom.id R₂) σ₁₂` * `RingHomSurjective (RingHom.id R)` * `[RingHomInvPair σ₁ σ₂] : RingHomSurjective σ₁` ## Implementation notes * For the typeclass `RingHomInvPair σ₁₂ σ₂₁`, `σ₂₁` is marked as an `outParam`, as it must typically be found via the typeclass inference system. * Likewise, for `RingHomCompTriple σ₁₂ σ₂₃ σ₁₃`, `σ₁₃` is marked as an `outParam`, for the same reason. ## Tags `RingHomCompTriple`, `RingHomInvPair`, `RingHomSurjective` -/ variable {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} variable [Semiring R₁] [Semiring R₂] [Semiring R₃] /-- Class that expresses that a ring homomorphism is in fact the identity. -/ -- This at first seems not very useful. However we need this when considering -- modules over some diagram in the category of rings, -- e.g. when defining presheaves over a presheaf of rings. -- See `Mathlib.Algebra.Category.ModuleCat.Presheaf`. class RingHomId {R : Type*} [Semiring R] (σ : R →+* R) : Prop where eq_id : σ = RingHom.id R instance {R : Type*} [Semiring R] : RingHomId (RingHom.id R) where eq_id := rfl /-- Class that expresses the fact that three ring homomorphisms form a composition triple. This is used to handle composition of semilinear maps. -/ class RingHomCompTriple (σ₁₂ : R₁ →+* R₂) (σ₂₃ : R₂ →+* R₃) (σ₁₃ : outParam (R₁ →+* R₃)) : Prop where /-- The morphisms form a commutative triangle -/ comp_eq : σ₂₃.comp σ₁₂ = σ₁₃ attribute [simp] RingHomCompTriple.comp_eq variable {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} namespace RingHomCompTriple @[simp] theorem comp_apply [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] {x : R₁} : σ₂₃ (σ₁₂ x) = σ₁₃ x := RingHom.congr_fun comp_eq x end RingHomCompTriple /-- Class that expresses the fact that two ring homomorphisms are inverses of each other. This is used to handle `symm` for semilinear equivalences. -/ class RingHomInvPair (σ : R₁ →+* R₂) (σ' : outParam (R₂ →+* R₁)) : Prop where /-- `σ'` is a left inverse of `σ` -/ comp_eq : σ'.comp σ = RingHom.id R₁ /-- `σ'` is a left inverse of `σ'` -/ comp_eq₂ : σ.comp σ' = RingHom.id R₂ -- attribute [simp] RingHomInvPair.comp_eq Porting note (#10618): `simp` can prove it -- attribute [simp] RingHomInvPair.comp_eq₂ Porting note (#10618): `simp` can prove it variable {σ : R₁ →+* R₂} {σ' : R₂ →+* R₁} namespace RingHomInvPair variable [RingHomInvPair σ σ'] -- @[simp] Porting note (#10618): `simp` can prove it theorem comp_apply_eq {x : R₁} : σ' (σ x) = x := by rw [← RingHom.comp_apply, comp_eq] simp -- @[simp] Porting note (#10618): `simp` can prove it theorem comp_apply_eq₂ {x : R₂} : σ (σ' x) = x := by rw [← RingHom.comp_apply, comp_eq₂] simp instance ids : RingHomInvPair (RingHom.id R₁) (RingHom.id R₁) := ⟨rfl, rfl⟩ instance triples {σ₂₁ : R₂ →+* R₁} [RingHomInvPair σ₁₂ σ₂₁] : RingHomCompTriple σ₁₂ σ₂₁ (RingHom.id R₁) := ⟨by simp only [comp_eq]⟩ instance triples₂ {σ₂₁ : R₂ →+* R₁} [RingHomInvPair σ₁₂ σ₂₁] : RingHomCompTriple σ₂₁ σ₁₂ (RingHom.id R₂) := ⟨by simp only [comp_eq₂]⟩ /-- Construct a `RingHomInvPair` from both directions of a ring equiv. This is not an instance, as for equivalences that are involutions, a better instance would be `RingHomInvPair e e`. Indeed, this declaration is not currently used in mathlib. -/ theorem of_ringEquiv (e : R₁ ≃+* R₂) : RingHomInvPair (↑e : R₁ →+* R₂) ↑e.symm := ⟨e.symm_toRingHom_comp_toRingHom, e.symm.symm_toRingHom_comp_toRingHom⟩ /-- Swap the direction of a `RingHomInvPair`. This is not an instance as it would loop, and better instances are often available and may often be preferrable to using this one. Indeed, this declaration is not currently used in mathlib. -/ theorem symm (σ₁₂ : R₁ →+* R₂) (σ₂₁ : R₂ →+* R₁) [RingHomInvPair σ₁₂ σ₂₁] : RingHomInvPair σ₂₁ σ₁₂ := ⟨RingHomInvPair.comp_eq₂, RingHomInvPair.comp_eq⟩ end RingHomInvPair namespace RingHomCompTriple instance ids : RingHomCompTriple (RingHom.id R₁) σ₁₂ σ₁₂ := ⟨by ext simp⟩ instance right_ids : RingHomCompTriple σ₁₂ (RingHom.id R₂) σ₁₂ := ⟨by ext simp⟩ end RingHomCompTriple /-- Class expressing the fact that a `RingHom` is surjective. This is needed in the context of semilinear maps, where some lemmas require this. -/ class RingHomSurjective (σ : R₁ →+* R₂) : Prop where /-- The ring homomorphism is surjective -/ is_surjective : Function.Surjective σ theorem RingHom.surjective (σ : R₁ →+* R₂) [t : RingHomSurjective σ] : Function.Surjective σ := t.is_surjective namespace RingHomSurjective -- The linter gives a false positive, since `σ₂` is an out_param -- Porting note(#12094): removed nolint; dangerous_instance linter not ported yet -- @[nolint dangerous_instance] instance (priority := 100) invPair {σ₁ : R₁ →+* R₂} {σ₂ : R₂ →+* R₁} [RingHomInvPair σ₁ σ₂] : RingHomSurjective σ₁ := ⟨fun x => ⟨σ₂ x, RingHomInvPair.comp_apply_eq₂⟩⟩ instance ids : RingHomSurjective (RingHom.id R₁) := ⟨is_surjective⟩ /-- This cannot be an instance as there is no way to infer `σ₁₂` and `σ₂₃`. -/ theorem comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomSurjective σ₁₂] [RingHomSurjective σ₂₃] : RingHomSurjective σ₁₃ := { is_surjective := by have := σ₂₃.surjective.comp σ₁₂.surjective rwa [← RingHom.coe_comp, RingHomCompTriple.comp_eq] at this } instance (σ : R₁ ≃+* R₂) : RingHomSurjective (σ : R₁ →+* R₂) := ⟨σ.surjective⟩ end RingHomSurjective
Algebra\Ring\Defs.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Group.Defs import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Data.Int.Cast.Defs import Mathlib.Tactic.Spread import Mathlib.Util.AssertExists /-! # Semirings and rings This file defines semirings, rings and domains. This is analogous to `Algebra.Group.Defs` and `Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. ## Main definitions * `Distrib`: Typeclass for distributivity of multiplication over addition. * `HasDistribNeg`: Typeclass for commutativity of negation and multiplication. This is useful when dealing with multiplicative submonoids which are closed under negation without being closed under addition, for example `Units`. * `(NonUnital)(NonAssoc)(Semi)Ring`: Typeclasses for possibly non-unital or non-associative rings and semirings. Some combinations are not defined yet because they haven't found use. ## Tags `Semiring`, `CommSemiring`, `Ring`, `CommRing`, domain, `IsDomain`, nonzero, units -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {R : Type x} open Function /-! ### `Distrib` class -/ /-- A typeclass stating that multiplication is left and right distributive over addition. -/ class Distrib (R : Type*) extends Mul R, Add R where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c /-- A typeclass stating that multiplication is left distributive over addition. -/ class LeftDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c /-- A typeclass stating that multiplication is right distributive over addition. -/ class RightDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c -- see Note [lower instance priority] instance (priority := 100) Distrib.leftDistribClass (R : Type*) [Distrib R] : LeftDistribClass R := ⟨Distrib.left_distrib⟩ -- see Note [lower instance priority] instance (priority := 100) Distrib.rightDistribClass (R : Type*) [Distrib R] : RightDistribClass R := ⟨Distrib.right_distrib⟩ theorem left_distrib [Mul R] [Add R] [LeftDistribClass R] (a b c : R) : a * (b + c) = a * b + a * c := LeftDistribClass.left_distrib a b c alias mul_add := left_distrib theorem right_distrib [Mul R] [Add R] [RightDistribClass R] (a b c : R) : (a + b) * c = a * c + b * c := RightDistribClass.right_distrib a b c alias add_mul := right_distrib theorem distrib_three_right [Mul R] [Add R] [RightDistribClass R] (a b c d : R) : (a + b + c) * d = a * d + b * d + c * d := by simp [right_distrib] /-! ### Classes of semirings and rings We make sure that the canonical path from `NonAssocSemiring` to `Ring` passes through `Semiring`, as this is a path which is followed all the time in linear algebra where the defining semilinear map `σ : R →+* S` depends on the `NonAssocSemiring` structure of `R` and `S` while the module definition depends on the `Semiring` structure. It is not currently possible to adjust priorities by hand (see lean4#2115). Instead, the last declared instance is used, so we make sure that `Semiring` is declared after `NonAssocRing`, so that `Semiring -> NonAssocSemiring` is tried before `NonAssocRing -> NonAssocSemiring`. TODO: clean this once lean4#2115 is fixed -/ /-- A not-necessarily-unital, not-necessarily-associative semiring. -/ class NonUnitalNonAssocSemiring (α : Type u) extends AddCommMonoid α, Distrib α, MulZeroClass α /-- An associative but not-necessarily unital semiring. -/ class NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, SemigroupWithZero α /-- A unital but not-necessarily-associative semiring. -/ class NonAssocSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, MulZeroOneClass α, AddCommMonoidWithOne α /-- A not-necessarily-unital, not-necessarily-associative ring. -/ class NonUnitalNonAssocRing (α : Type u) extends AddCommGroup α, NonUnitalNonAssocSemiring α /-- An associative but not-necessarily unital ring. -/ class NonUnitalRing (α : Type*) extends NonUnitalNonAssocRing α, NonUnitalSemiring α /-- A unital but not-necessarily-associative ring. -/ class NonAssocRing (α : Type*) extends NonUnitalNonAssocRing α, NonAssocSemiring α, AddCommGroupWithOne α /-- A `Semiring` is a type with addition, multiplication, a `0` and a `1` where addition is commutative and associative, multiplication is associative and left and right distributive over addition, and `0` and `1` are additive and multiplicative identities. -/ class Semiring (α : Type u) extends NonUnitalSemiring α, NonAssocSemiring α, MonoidWithZero α /-- A `Ring` is a `Semiring` with negation making it an additive group. -/ class Ring (R : Type u) extends Semiring R, AddCommGroup R, AddGroupWithOne R /-! ### Semirings -/ section DistribMulOneClass variable [Add α] [MulOneClass α] theorem add_one_mul [RightDistribClass α] (a b : α) : (a + 1) * b = a * b + b := by rw [add_mul, one_mul] theorem mul_add_one [LeftDistribClass α] (a b : α) : a * (b + 1) = a * b + a := by rw [mul_add, mul_one] theorem one_add_mul [RightDistribClass α] (a b : α) : (1 + a) * b = b + a * b := by rw [add_mul, one_mul] theorem mul_one_add [LeftDistribClass α] (a b : α) : a * (1 + b) = a + a * b := by rw [mul_add, mul_one] end DistribMulOneClass section NonAssocSemiring variable [NonAssocSemiring α] -- Porting note: was [has_add α] [mul_one_class α] [right_distrib_class α] theorem two_mul (n : α) : 2 * n = n + n := (congrArg₂ _ one_add_one_eq_two.symm rfl).trans <| (right_distrib 1 1 n).trans (by rw [one_mul]) -- Porting note: was [has_add α] [mul_one_class α] [left_distrib_class α] theorem mul_two (n : α) : n * 2 = n + n := (congrArg₂ _ rfl one_add_one_eq_two.symm).trans <| (left_distrib n 1 1).trans (by rw [mul_one]) end NonAssocSemiring @[to_additive] theorem mul_ite {α} [Mul α] (P : Prop) [Decidable P] (a b c : α) : (a * if P then b else c) = if P then a * b else a * c := by split_ifs <;> rfl @[to_additive] theorem ite_mul {α} [Mul α] (P : Prop) [Decidable P] (a b c : α) : (if P then a else b) * c = if P then a * c else b * c := by split_ifs <;> rfl -- We make `mul_ite` and `ite_mul` simp lemmas, -- but not `add_ite` or `ite_add`. -- The problem we're trying to avoid is dealing with -- summations of the form `∑ x ∈ s, (f x + ite P 1 0)`, -- in which `add_ite` followed by `sum_ite` would needlessly slice up -- the `f x` terms according to whether `P` holds at `x`. -- There doesn't appear to be a corresponding difficulty so far with -- `mul_ite` and `ite_mul`. attribute [simp] mul_ite ite_mul theorem ite_sub_ite {α} [Sub α] (P : Prop) [Decidable P] (a b c d : α) : ((if P then a else b) - if P then c else d) = if P then a - c else b - d := by split repeat rfl theorem ite_add_ite {α} [Add α] (P : Prop) [Decidable P] (a b c d : α) : ((if P then a else b) + if P then c else d) = if P then a + c else b + d := by split repeat rfl section MulZeroClass variable [MulZeroClass α] (P Q : Prop) [Decidable P] [Decidable Q] (a b : α) lemma ite_zero_mul : ite P a 0 * b = ite P (a * b) 0 := by simp lemma mul_ite_zero : a * ite P b 0 = ite P (a * b) 0 := by simp lemma ite_zero_mul_ite_zero : ite P a 0 * ite Q b 0 = ite (P ∧ Q) (a * b) 0 := by simp only [← ite_and, ite_mul, mul_ite, mul_zero, zero_mul, and_comm] end MulZeroClass -- Porting note: no @[simp] because simp proves it theorem mul_boole {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) : (a * if P then 1 else 0) = if P then a else 0 := by simp -- Porting note: no @[simp] because simp proves it theorem boole_mul {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) : (if P then 1 else 0) * a = if P then a else 0 := by simp /-- A not-necessarily-unital, not-necessarily-associative, but commutative semiring. -/ class NonUnitalNonAssocCommSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, CommMagma α /-- A non-unital commutative semiring is a `NonUnitalSemiring` with commutative multiplication. In other words, it is a type with the following structures: additive commutative monoid (`AddCommMonoid`), commutative semigroup (`CommSemigroup`), distributive laws (`Distrib`), and multiplication by zero law (`MulZeroClass`). -/ class NonUnitalCommSemiring (α : Type u) extends NonUnitalSemiring α, CommSemigroup α /-- A commutative semiring is a semiring with commutative multiplication. -/ class CommSemiring (R : Type u) extends Semiring R, CommMonoid R -- see Note [lower instance priority] instance (priority := 100) CommSemiring.toNonUnitalCommSemiring [CommSemiring α] : NonUnitalCommSemiring α := { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with } -- see Note [lower instance priority] instance (priority := 100) CommSemiring.toCommMonoidWithZero [CommSemiring α] : CommMonoidWithZero α := { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with } section CommSemiring variable [CommSemiring α] {a b c : α} theorem add_mul_self_eq (a b : α) : (a + b) * (a + b) = a * a + 2 * a * b + b * b := by simp only [two_mul, add_mul, mul_add, add_assoc, mul_comm b] lemma add_sq (a b : α) : (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2 := by simp only [sq, add_mul_self_eq] lemma add_sq' (a b : α) : (a + b) ^ 2 = a ^ 2 + b ^ 2 + 2 * a * b := by rw [add_sq, add_assoc, add_comm _ (b ^ 2), add_assoc] alias add_pow_two := add_sq end CommSemiring section HasDistribNeg /-- Typeclass for a negation operator that distributes across multiplication. This is useful for dealing with submonoids of a ring that contain `-1` without having to duplicate lemmas. -/ class HasDistribNeg (α : Type*) [Mul α] extends InvolutiveNeg α where /-- Negation is left distributive over multiplication -/ neg_mul : ∀ x y : α, -x * y = -(x * y) /-- Negation is right distributive over multiplication -/ mul_neg : ∀ x y : α, x * -y = -(x * y) section Mul variable [Mul α] [HasDistribNeg α] @[simp] theorem neg_mul (a b : α) : -a * b = -(a * b) := HasDistribNeg.neg_mul _ _ @[simp] theorem mul_neg (a b : α) : a * -b = -(a * b) := HasDistribNeg.mul_neg _ _ theorem neg_mul_neg (a b : α) : -a * -b = a * b := by simp theorem neg_mul_eq_neg_mul (a b : α) : -(a * b) = -a * b := (neg_mul _ _).symm theorem neg_mul_eq_mul_neg (a b : α) : -(a * b) = a * -b := (mul_neg _ _).symm theorem neg_mul_comm (a b : α) : -a * b = a * -b := by simp end Mul section MulOneClass variable [MulOneClass α] [HasDistribNeg α] theorem neg_eq_neg_one_mul (a : α) : -a = -1 * a := by simp /-- An element of a ring multiplied by the additive inverse of one is the element's additive inverse. -/ theorem mul_neg_one (a : α) : a * -1 = -a := by simp /-- The additive inverse of one multiplied by an element of a ring is the element's additive inverse. -/ theorem neg_one_mul (a : α) : -1 * a = -a := by simp end MulOneClass section MulZeroClass variable [MulZeroClass α] [HasDistribNeg α] instance (priority := 100) MulZeroClass.negZeroClass : NegZeroClass α where __ := inferInstanceAs (Zero α); __ := inferInstanceAs (InvolutiveNeg α) neg_zero := by rw [← zero_mul (0 : α), ← neg_mul, mul_zero, mul_zero] end MulZeroClass end HasDistribNeg /-! ### Rings -/ section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] instance (priority := 100) NonUnitalNonAssocRing.toHasDistribNeg : HasDistribNeg α where neg := Neg.neg neg_neg := neg_neg neg_mul a b := eq_neg_of_add_eq_zero_left <| by rw [← right_distrib, add_left_neg, zero_mul] mul_neg a b := eq_neg_of_add_eq_zero_left <| by rw [← left_distrib, add_left_neg, mul_zero] theorem mul_sub_left_distrib (a b c : α) : a * (b - c) = a * b - a * c := by simpa only [sub_eq_add_neg, neg_mul_eq_mul_neg] using mul_add a b (-c) alias mul_sub := mul_sub_left_distrib theorem mul_sub_right_distrib (a b c : α) : (a - b) * c = a * c - b * c := by simpa only [sub_eq_add_neg, neg_mul_eq_neg_mul] using add_mul a (-b) c alias sub_mul := mul_sub_right_distrib end NonUnitalNonAssocRing section NonAssocRing variable [NonAssocRing α] theorem sub_one_mul (a b : α) : (a - 1) * b = a * b - b := by rw [sub_mul, one_mul] theorem mul_sub_one (a b : α) : a * (b - 1) = a * b - a := by rw [mul_sub, mul_one] theorem one_sub_mul (a b : α) : (1 - a) * b = b - a * b := by rw [sub_mul, one_mul] theorem mul_one_sub (a b : α) : a * (1 - b) = a - a * b := by rw [mul_sub, mul_one] end NonAssocRing section Ring variable [Ring α] {a b c d e : α} -- A (unital, associative) ring is a not-necessarily-unital ring -- see Note [lower instance priority] instance (priority := 100) Ring.toNonUnitalRing : NonUnitalRing α := { ‹Ring α› with } -- A (unital, associative) ring is a not-necessarily-associative ring -- see Note [lower instance priority] instance (priority := 100) Ring.toNonAssocRing : NonAssocRing α := { ‹Ring α› with } /-- The instance from `Ring` to `Semiring` happens often in linear algebra, for which all the basic definitions are given in terms of semirings, but many applications use rings or fields. We increase a little bit its priority above 100 to try it quickly, but remaining below the default 1000 so that more specific instances are tried first. -/ instance (priority := 200) : Semiring α := { ‹Ring α› with } end Ring /-- A non-unital non-associative commutative ring is a `NonUnitalNonAssocRing` with commutative multiplication. -/ class NonUnitalNonAssocCommRing (α : Type u) extends NonUnitalNonAssocRing α, NonUnitalNonAssocCommSemiring α /-- A non-unital commutative ring is a `NonUnitalRing` with commutative multiplication. -/ class NonUnitalCommRing (α : Type u) extends NonUnitalRing α, NonUnitalNonAssocCommRing α -- see Note [lower instance priority] instance (priority := 100) NonUnitalCommRing.toNonUnitalCommSemiring [s : NonUnitalCommRing α] : NonUnitalCommSemiring α := { s with } /-- A commutative ring is a ring with commutative multiplication. -/ class CommRing (α : Type u) extends Ring α, CommMonoid α instance (priority := 100) CommRing.toCommSemiring [s : CommRing α] : CommSemiring α := { s with } -- see Note [lower instance priority] instance (priority := 100) CommRing.toNonUnitalCommRing [s : CommRing α] : NonUnitalCommRing α := { s with } -- see Note [lower instance priority] instance (priority := 100) CommRing.toAddCommGroupWithOne [s : CommRing α] : AddCommGroupWithOne α := { s with } /-- A domain is a nontrivial semiring such that multiplication by a non zero element is cancellative on both sides. In other words, a nontrivial semiring `R` satisfying `∀ {a b c : R}, a ≠ 0 → a * b = a * c → b = c` and `∀ {a b c : R}, b ≠ 0 → a * b = c * b → a = c`. This is implemented as a mixin for `Semiring α`. To obtain an integral domain use `[CommRing α] [IsDomain α]`. -/ class IsDomain (α : Type u) [Semiring α] extends IsCancelMulZero α, Nontrivial α : Prop /-! Previously an import dependency on `Mathlib.Algebra.Group.Basic` had crept in. In general, the `.Defs` files in the basic algebraic hierarchy should only depend on earlier `.Defs` files, without importing `.Basic` theory development. These `assert_not_exists` statements guard against this returning. -/ assert_not_exists DivisionMonoid.toDivInvOneMonoid assert_not_exists mul_rotate
Algebra\Ring\Equiv.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.Group.Units.Equiv import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Logic.Equiv.Set import Mathlib.Util.AssertExists /-! # (Semi)ring equivs In this file we define an extension of `Equiv` called `RingEquiv`, which is a datatype representing an isomorphism of `Semiring`s, `Ring`s, `DivisionRing`s, or `Field`s. ## Notations * ``infixl ` ≃+* `:25 := RingEquiv`` The extended equiv have coercions to functions, and the coercion is the canonical notation when treating the isomorphism as maps. ## Implementation notes The fields for `RingEquiv` now avoid the unbundled `isMulHom` and `isAddHom`, as these are deprecated. Definition of multiplication in the groups of automorphisms agrees with function composition, multiplication in `Equiv.Perm`, and multiplication in `CategoryTheory.End`, not with `CategoryTheory.CategoryStruct.comp`. ## Tags Equiv, MulEquiv, AddEquiv, RingEquiv, MulAut, AddAut, RingAut -/ variable {F α β R S S' : Type*} /-- makes a `NonUnitalRingHom` from the bijective inverse of a `NonUnitalRingHom` -/ @[simps] def NonUnitalRingHom.inverse [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R →ₙ+* S) (g : S → R) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : S →ₙ+* R := { (f : R →+ S).inverse g h₁ h₂, (f : R →ₙ* S).inverse g h₁ h₂ with toFun := g } /-- makes a `RingHom` from the bijective inverse of a `RingHom` -/ @[simps] def RingHom.inverse [NonAssocSemiring R] [NonAssocSemiring S] (f : RingHom R S) (g : S → R) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : S →+* R := { (f : OneHom R S).inverse g h₁, (f : MulHom R S).inverse g h₁ h₂, (f : R →+ S).inverse g h₁ h₂ with toFun := g } /-- An equivalence between two (non-unital non-associative semi)rings that preserves the algebraic structure. -/ structure RingEquiv (R S : Type*) [Mul R] [Mul S] [Add R] [Add S] extends R ≃ S, R ≃* S, R ≃+ S /-- Notation for `RingEquiv`. -/ infixl:25 " ≃+* " => RingEquiv /-- The "plain" equivalence of types underlying an equivalence of (semi)rings. -/ add_decl_doc RingEquiv.toEquiv /-- The equivalence of additive monoids underlying an equivalence of (semi)rings. -/ add_decl_doc RingEquiv.toAddEquiv /-- The equivalence of multiplicative monoids underlying an equivalence of (semi)rings. -/ add_decl_doc RingEquiv.toMulEquiv /-- `RingEquivClass F R S` states that `F` is a type of ring structure preserving equivalences. You should extend this class when you extend `RingEquiv`. -/ class RingEquivClass (F R S : Type*) [Mul R] [Add R] [Mul S] [Add S] [EquivLike F R S] extends MulEquivClass F R S : Prop where /-- By definition, a ring isomorphism preserves the additive structure. -/ map_add : ∀ (f : F) (a b), f (a + b) = f a + f b namespace RingEquivClass variable [EquivLike F R S] -- See note [lower instance priority] instance (priority := 100) toAddEquivClass [Mul R] [Add R] [Mul S] [Add S] [h : RingEquivClass F R S] : AddEquivClass F R S := { h with } -- See note [lower instance priority] instance (priority := 100) toRingHomClass [NonAssocSemiring R] [NonAssocSemiring S] [h : RingEquivClass F R S] : RingHomClass F R S := { h with map_zero := map_zero map_one := map_one } -- See note [lower instance priority] instance (priority := 100) toNonUnitalRingHomClass [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [h : RingEquivClass F R S] : NonUnitalRingHomClass F R S := { h with map_zero := map_zero } /-- Turn an element of a type `F` satisfying `RingEquivClass F α β` into an actual `RingEquiv`. This is declared as the default coercion from `F` to `α ≃+* β`. -/ @[coe] def toRingEquiv [Mul α] [Add α] [Mul β] [Add β] [EquivLike F α β] [RingEquivClass F α β] (f : F) : α ≃+* β := { (f : α ≃* β), (f : α ≃+ β) with } end RingEquivClass /-- Any type satisfying `RingEquivClass` can be cast into `RingEquiv` via `RingEquivClass.toRingEquiv`. -/ instance [Mul α] [Add α] [Mul β] [Add β] [EquivLike F α β] [RingEquivClass F α β] : CoeTC F (α ≃+* β) := ⟨RingEquivClass.toRingEquiv⟩ namespace RingEquiv section Basic variable [Mul R] [Mul S] [Add R] [Add S] [Mul S'] [Add S'] instance : EquivLike (R ≃+* S) R S where coe f := f.toFun inv f := f.invFun coe_injective' e f h₁ h₂ := by cases e cases f congr apply Equiv.coe_fn_injective h₁ left_inv f := f.left_inv right_inv f := f.right_inv instance : RingEquivClass (R ≃+* S) R S where map_add f := f.map_add' map_mul f := f.map_mul' @[simp] theorem toEquiv_eq_coe (f : R ≃+* S) : f.toEquiv = f := rfl -- Porting note: `toFun_eq_coe` no longer needed in Lean4 @[simp] theorem coe_toEquiv (f : R ≃+* S) : ⇑(f : R ≃ S) = f := rfl /-- A ring isomorphism preserves multiplication. -/ protected theorem map_mul (e : R ≃+* S) (x y : R) : e (x * y) = e x * e y := map_mul e x y /-- A ring isomorphism preserves addition. -/ protected theorem map_add (e : R ≃+* S) (x y : R) : e (x + y) = e x + e y := map_add e x y /-- Two ring isomorphisms agree if they are defined by the same underlying function. -/ @[ext] theorem ext {f g : R ≃+* S} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[simp] theorem coe_mk (e h₃ h₄) : ⇑(⟨e, h₃, h₄⟩ : R ≃+* S) = e := rfl -- Porting note: `toEquiv_mk` no longer needed in Lean4 @[simp] theorem mk_coe (e : R ≃+* S) (e' h₁ h₂ h₃ h₄) : (⟨⟨e, e', h₁, h₂⟩, h₃, h₄⟩ : R ≃+* S) = e := ext fun _ => rfl protected theorem congr_arg {f : R ≃+* S} {x x' : R} : x = x' → f x = f x' := DFunLike.congr_arg f protected theorem congr_fun {f g : R ≃+* S} (h : f = g) (x : R) : f x = g x := DFunLike.congr_fun h x @[simp] theorem toAddEquiv_eq_coe (f : R ≃+* S) : f.toAddEquiv = ↑f := rfl @[simp] theorem toMulEquiv_eq_coe (f : R ≃+* S) : f.toMulEquiv = ↑f := rfl @[simp, norm_cast] theorem coe_toMulEquiv (f : R ≃+* S) : ⇑(f : R ≃* S) = f := rfl @[simp] theorem coe_toAddEquiv (f : R ≃+* S) : ⇑(f : R ≃+ S) = f := rfl /-- The `RingEquiv` between two semirings with a unique element. -/ def ringEquivOfUnique {M N} [Unique M] [Unique N] [Add M] [Mul M] [Add N] [Mul N] : M ≃+* N := { AddEquiv.addEquivOfUnique, MulEquiv.mulEquivOfUnique with } instance {M N} [Unique M] [Unique N] [Add M] [Mul M] [Add N] [Mul N] : Unique (M ≃+* N) where default := ringEquivOfUnique uniq _ := ext fun _ => Subsingleton.elim _ _ variable (R) /-- The identity map is a ring isomorphism. -/ @[refl] def refl : R ≃+* R := { MulEquiv.refl R, AddEquiv.refl R with } @[simp] theorem refl_apply (x : R) : RingEquiv.refl R x = x := rfl @[simp] theorem coe_addEquiv_refl : (RingEquiv.refl R : R ≃+ R) = AddEquiv.refl R := rfl @[simp] theorem coe_mulEquiv_refl : (RingEquiv.refl R : R ≃* R) = MulEquiv.refl R := rfl instance : Inhabited (R ≃+* R) := ⟨RingEquiv.refl R⟩ variable {R} /-- The inverse of a ring isomorphism is a ring isomorphism. -/ @[symm] protected def symm (e : R ≃+* S) : S ≃+* R := { e.toMulEquiv.symm, e.toAddEquiv.symm with } /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : R ≃+* S) : S → R := e.symm initialize_simps_projections RingEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem invFun_eq_symm (f : R ≃+* S) : EquivLike.inv f = f.symm := rfl @[simp] theorem symm_symm (e : R ≃+* S) : e.symm.symm = e := ext fun _ => rfl @[simp] theorem symm_refl : (RingEquiv.refl R).symm = RingEquiv.refl R := rfl @[simp] theorem coe_toEquiv_symm (e : R ≃+* S) : (e.symm : S ≃ R) = (e : R ≃ S).symm := rfl theorem symm_bijective : Function.Bijective (RingEquiv.symm : (R ≃+* S) → S ≃+* R) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem mk_coe' (e : R ≃+* S) (f h₁ h₂ h₃ h₄) : (⟨⟨f, ⇑e, h₁, h₂⟩, h₃, h₄⟩ : S ≃+* R) = e.symm := symm_bijective.injective <| ext fun _ => rfl /-- Auxilliary definition to avoid looping in `dsimp` with `RingEquiv.symm_mk`. -/ protected def symm_mk.aux (f : R → S) (g h₁ h₂ h₃ h₄) := (mk ⟨f, g, h₁, h₂⟩ h₃ h₄).symm @[simp] theorem symm_mk (f : R → S) (g h₁ h₂ h₃ h₄) : (mk ⟨f, g, h₁, h₂⟩ h₃ h₄).symm = { symm_mk.aux f g h₁ h₂ h₃ h₄ with toFun := g invFun := f } := rfl /-- Transitivity of `RingEquiv`. -/ @[trans] protected def trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : R ≃+* S' := { e₁.toMulEquiv.trans e₂.toMulEquiv, e₁.toAddEquiv.trans e₂.toAddEquiv with } theorem trans_apply (e₁ : R ≃+* S) (e₂ : S ≃+* S') (a : R) : e₁.trans e₂ a = e₂ (e₁ a) := rfl @[simp] theorem coe_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R → S') = e₂ ∘ e₁ := rfl @[simp] theorem symm_trans_apply (e₁ : R ≃+* S) (e₂ : S ≃+* S') (a : S') : (e₁.trans e₂).symm a = e₁.symm (e₂.symm a) := rfl theorem symm_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl protected theorem bijective (e : R ≃+* S) : Function.Bijective e := EquivLike.bijective e protected theorem injective (e : R ≃+* S) : Function.Injective e := EquivLike.injective e protected theorem surjective (e : R ≃+* S) : Function.Surjective e := EquivLike.surjective e @[simp] theorem apply_symm_apply (e : R ≃+* S) : ∀ x, e (e.symm x) = x := e.toEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : R ≃+* S) : ∀ x, e.symm (e x) = x := e.toEquiv.symm_apply_apply theorem image_eq_preimage (e : R ≃+* S) (s : Set R) : e '' s = e.symm ⁻¹' s := e.toEquiv.image_eq_preimage s @[simp] theorem coe_mulEquiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R ≃* S') = (e₁ : R ≃* S).trans ↑e₂ := rfl @[simp] theorem coe_addEquiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R ≃+ S') = (e₁ : R ≃+ S).trans ↑e₂ := rfl end Basic section Opposite open MulOpposite /-- A ring iso `α ≃+* β` can equivalently be viewed as a ring iso `αᵐᵒᵖ ≃+* βᵐᵒᵖ`. -/ @[simps! symm_apply_apply symm_apply_symm_apply apply_apply apply_symm_apply] protected def op {α β} [Add α] [Mul α] [Add β] [Mul β] : α ≃+* β ≃ (αᵐᵒᵖ ≃+* βᵐᵒᵖ) where toFun f := { AddEquiv.mulOp f.toAddEquiv, MulEquiv.op f.toMulEquiv with } invFun f := { AddEquiv.mulOp.symm f.toAddEquiv, MulEquiv.op.symm f.toMulEquiv with } left_inv f := by ext rfl right_inv f := by ext rfl /-- The 'unopposite' of a ring iso `αᵐᵒᵖ ≃+* βᵐᵒᵖ`. Inverse to `RingEquiv.op`. -/ @[simp] protected def unop {α β} [Add α] [Mul α] [Add β] [Mul β] : αᵐᵒᵖ ≃+* βᵐᵒᵖ ≃ (α ≃+* β) := RingEquiv.op.symm /-- A ring is isomorphic to the opposite of its opposite. -/ @[simps!] def opOp (R : Type*) [Add R] [Mul R] : R ≃+* Rᵐᵒᵖᵐᵒᵖ where __ := MulEquiv.opOp R map_add' _ _ := rfl section NonUnitalCommSemiring variable (R) [NonUnitalCommSemiring R] /-- A non-unital commutative ring is isomorphic to its opposite. -/ def toOpposite : R ≃+* Rᵐᵒᵖ := { MulOpposite.opEquiv with map_add' := fun _ _ => rfl map_mul' := fun x y => mul_comm (op y) (op x) } @[simp] theorem toOpposite_apply (r : R) : toOpposite R r = op r := rfl @[simp] theorem toOpposite_symm_apply (r : Rᵐᵒᵖ) : (toOpposite R).symm r = unop r := rfl end NonUnitalCommSemiring end Opposite section NonUnitalSemiring variable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R ≃+* S) (x y : R) /-- A ring isomorphism sends zero to zero. -/ protected theorem map_zero : f 0 = 0 := map_zero f variable {x} protected theorem map_eq_zero_iff : f x = 0 ↔ x = 0 := AddEquivClass.map_eq_zero_iff f theorem map_ne_zero_iff : f x ≠ 0 ↔ x ≠ 0 := AddEquivClass.map_ne_zero_iff f variable [FunLike F R S] /-- Produce a ring isomorphism from a bijective ring homomorphism. -/ noncomputable def ofBijective [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Bijective f) : R ≃+* S := { Equiv.ofBijective f hf with map_mul' := map_mul f map_add' := map_add f } @[simp] theorem coe_ofBijective [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Bijective f) : (ofBijective f hf : R → S) = f := rfl theorem ofBijective_apply [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Bijective f) (x : R) : ofBijective f hf x = f x := rfl /-- A family of ring isomorphisms `∀ j, (R j ≃+* S j)` generates a ring isomorphisms between `∀ j, R j` and `∀ j, S j`. This is the `RingEquiv` version of `Equiv.piCongrRight`, and the dependent version of `RingEquiv.arrowCongr`. -/ @[simps apply] def piCongrRight {ι : Type*} {R S : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] [∀ i, NonUnitalNonAssocSemiring (S i)] (e : ∀ i, R i ≃+* S i) : (∀ i, R i) ≃+* ∀ i, S i := { @MulEquiv.piCongrRight ι R S _ _ fun i => (e i).toMulEquiv, @AddEquiv.piCongrRight ι R S _ _ fun i => (e i).toAddEquiv with toFun := fun x j => e j (x j) invFun := fun x j => (e j).symm (x j) } @[simp] theorem piCongrRight_refl {ι : Type*} {R : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] : (piCongrRight fun i => RingEquiv.refl (R i)) = RingEquiv.refl _ := rfl @[simp] theorem piCongrRight_symm {ι : Type*} {R S : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] [∀ i, NonUnitalNonAssocSemiring (S i)] (e : ∀ i, R i ≃+* S i) : (piCongrRight e).symm = piCongrRight fun i => (e i).symm := rfl @[simp] theorem piCongrRight_trans {ι : Type*} {R S T : ι → Type*} [∀ i, NonUnitalNonAssocSemiring (R i)] [∀ i, NonUnitalNonAssocSemiring (S i)] [∀ i, NonUnitalNonAssocSemiring (T i)] (e : ∀ i, R i ≃+* S i) (f : ∀ i, S i ≃+* T i) : (piCongrRight e).trans (piCongrRight f) = piCongrRight fun i => (e i).trans (f i) := rfl end NonUnitalSemiring section Semiring variable [NonAssocSemiring R] [NonAssocSemiring S] (f : R ≃+* S) (x y : R) /-- A ring isomorphism sends one to one. -/ protected theorem map_one : f 1 = 1 := map_one f variable {x} protected theorem map_eq_one_iff : f x = 1 ↔ x = 1 := MulEquivClass.map_eq_one_iff f theorem map_ne_one_iff : f x ≠ 1 ↔ x ≠ 1 := MulEquivClass.map_ne_one_iff f theorem coe_monoidHom_refl : (RingEquiv.refl R : R →* R) = MonoidHom.id R := rfl @[simp] theorem coe_addMonoidHom_refl : (RingEquiv.refl R : R →+ R) = AddMonoidHom.id R := rfl /-! `RingEquiv.coe_mulEquiv_refl` and `RingEquiv.coe_addEquiv_refl` are proved above in higher generality -/ @[simp] theorem coe_ringHom_refl : (RingEquiv.refl R : R →+* R) = RingHom.id R := rfl @[simp] theorem coe_monoidHom_trans [NonAssocSemiring S'] (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R →* S') = (e₂ : S →* S').comp ↑e₁ := rfl @[simp] theorem coe_addMonoidHom_trans [NonAssocSemiring S'] (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R →+ S') = (e₂ : S →+ S').comp ↑e₁ := rfl /-! `RingEquiv.coe_mulEquiv_trans` and `RingEquiv.coe_addEquiv_trans` are proved above in higher generality -/ @[simp] theorem coe_ringHom_trans [NonAssocSemiring S'] (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂ : R →+* S') = (e₂ : S →+* S').comp ↑e₁ := rfl @[simp] theorem comp_symm (e : R ≃+* S) : (e : R →+* S).comp (e.symm : S →+* R) = RingHom.id S := RingHom.ext e.apply_symm_apply @[simp] theorem symm_comp (e : R ≃+* S) : (e.symm : S →+* R).comp (e : R →+* S) = RingHom.id R := RingHom.ext e.symm_apply_apply end Semiring section NonUnitalRing variable [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] (f : R ≃+* S) (x y : R) protected theorem map_neg : f (-x) = -f x := map_neg f x protected theorem map_sub : f (x - y) = f x - f y := map_sub f x y end NonUnitalRing section Ring variable [NonAssocRing R] [NonAssocRing S] (f : R ≃+* S) (x y : R) -- Porting note (#10618): `simp` can now prove that, so we remove the `@[simp]` tag theorem map_neg_one : f (-1) = -1 := f.map_one ▸ f.map_neg 1 theorem map_eq_neg_one_iff {x : R} : f x = -1 ↔ x = -1 := by rw [← neg_eq_iff_eq_neg, ← neg_eq_iff_eq_neg, ← map_neg, RingEquiv.map_eq_one_iff] end Ring section NonUnitalSemiringHom variable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring S'] /-- Reinterpret a ring equivalence as a non-unital ring homomorphism. -/ def toNonUnitalRingHom (e : R ≃+* S) : R →ₙ+* S := { e.toMulEquiv.toMulHom, e.toAddEquiv.toAddMonoidHom with } theorem toNonUnitalRingHom_injective : Function.Injective (toNonUnitalRingHom : R ≃+* S → R →ₙ+* S) := fun _ _ h => RingEquiv.ext (NonUnitalRingHom.ext_iff.1 h) theorem toNonUnitalRingHom_eq_coe (f : R ≃+* S) : f.toNonUnitalRingHom = ↑f := rfl @[simp, norm_cast] theorem coe_toNonUnitalRingHom (f : R ≃+* S) : ⇑(f : R →ₙ+* S) = f := rfl theorem coe_nonUnitalRingHom_inj_iff {R S : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f g : R ≃+* S) : f = g ↔ (f : R →ₙ+* S) = g := ⟨fun h => by rw [h], fun h => ext <| NonUnitalRingHom.ext_iff.mp h⟩ @[simp] theorem toNonUnitalRingHom_refl : (RingEquiv.refl R).toNonUnitalRingHom = NonUnitalRingHom.id R := rfl @[simp] theorem toNonUnitalRingHom_apply_symm_toNonUnitalRingHom_apply (e : R ≃+* S) : ∀ y : S, e.toNonUnitalRingHom (e.symm.toNonUnitalRingHom y) = y := e.toEquiv.apply_symm_apply @[simp] theorem symm_toNonUnitalRingHom_apply_toNonUnitalRingHom_apply (e : R ≃+* S) : ∀ x : R, e.symm.toNonUnitalRingHom (e.toNonUnitalRingHom x) = x := Equiv.symm_apply_apply e.toEquiv @[simp] theorem toNonUnitalRingHom_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).toNonUnitalRingHom = e₂.toNonUnitalRingHom.comp e₁.toNonUnitalRingHom := rfl @[simp] theorem toNonUnitalRingHomm_comp_symm_toNonUnitalRingHom (e : R ≃+* S) : e.toNonUnitalRingHom.comp e.symm.toNonUnitalRingHom = NonUnitalRingHom.id _ := by ext simp @[simp] theorem symm_toNonUnitalRingHom_comp_toNonUnitalRingHom (e : R ≃+* S) : e.symm.toNonUnitalRingHom.comp e.toNonUnitalRingHom = NonUnitalRingHom.id _ := by ext simp end NonUnitalSemiringHom section SemiringHom variable [NonAssocSemiring R] [NonAssocSemiring S] [NonAssocSemiring S'] /-- Reinterpret a ring equivalence as a ring homomorphism. -/ def toRingHom (e : R ≃+* S) : R →+* S := { e.toMulEquiv.toMonoidHom, e.toAddEquiv.toAddMonoidHom with } theorem toRingHom_injective : Function.Injective (toRingHom : R ≃+* S → R →+* S) := fun _ _ h => RingEquiv.ext (RingHom.ext_iff.1 h) @[simp] theorem toRingHom_eq_coe (f : R ≃+* S) : f.toRingHom = ↑f := rfl @[simp, norm_cast] theorem coe_toRingHom (f : R ≃+* S) : ⇑(f : R →+* S) = f := rfl theorem coe_ringHom_inj_iff {R S : Type*} [NonAssocSemiring R] [NonAssocSemiring S] (f g : R ≃+* S) : f = g ↔ (f : R →+* S) = g := ⟨fun h => by rw [h], fun h => ext <| RingHom.ext_iff.mp h⟩ /-- The two paths coercion can take to a `NonUnitalRingEquiv` are equivalent -/ @[simp, norm_cast] theorem toNonUnitalRingHom_commutes (f : R ≃+* S) : ((f : R →+* S) : R →ₙ+* S) = (f : R →ₙ+* S) := rfl /-- Reinterpret a ring equivalence as a monoid homomorphism. -/ abbrev toMonoidHom (e : R ≃+* S) : R →* S := e.toRingHom.toMonoidHom /-- Reinterpret a ring equivalence as an `AddMonoid` homomorphism. -/ abbrev toAddMonoidHom (e : R ≃+* S) : R →+ S := e.toRingHom.toAddMonoidHom /-- The two paths coercion can take to an `AddMonoidHom` are equivalent -/ theorem toAddMonoidMom_commutes (f : R ≃+* S) : (f : R →+* S).toAddMonoidHom = (f : R ≃+ S).toAddMonoidHom := rfl /-- The two paths coercion can take to a `MonoidHom` are equivalent -/ theorem toMonoidHom_commutes (f : R ≃+* S) : (f : R →+* S).toMonoidHom = (f : R ≃* S).toMonoidHom := rfl /-- The two paths coercion can take to an `Equiv` are equivalent -/ theorem toEquiv_commutes (f : R ≃+* S) : (f : R ≃+ S).toEquiv = (f : R ≃* S).toEquiv := rfl @[simp] theorem toRingHom_refl : (RingEquiv.refl R).toRingHom = RingHom.id R := rfl @[simp] theorem toMonoidHom_refl : (RingEquiv.refl R).toMonoidHom = MonoidHom.id R := rfl @[simp] theorem toAddMonoidHom_refl : (RingEquiv.refl R).toAddMonoidHom = AddMonoidHom.id R := rfl -- Porting note (#10618): Now other `simp` can do this, so removed `simp` attribute theorem toRingHom_apply_symm_toRingHom_apply (e : R ≃+* S) : ∀ y : S, e.toRingHom (e.symm.toRingHom y) = y := e.toEquiv.apply_symm_apply -- Porting note (#10618): Now other `simp` can do this, so removed `simp` attribute theorem symm_toRingHom_apply_toRingHom_apply (e : R ≃+* S) : ∀ x : R, e.symm.toRingHom (e.toRingHom x) = x := Equiv.symm_apply_apply e.toEquiv @[simp] theorem toRingHom_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).toRingHom = e₂.toRingHom.comp e₁.toRingHom := rfl -- Porting note (#10618): Now other `simp` can do this, so removed `simp` attribute theorem toRingHom_comp_symm_toRingHom (e : R ≃+* S) : e.toRingHom.comp e.symm.toRingHom = RingHom.id _ := by ext simp -- Porting note (#10618): Now other `simp` can do this, so removed `simp` attribute theorem symm_toRingHom_comp_toRingHom (e : R ≃+* S) : e.symm.toRingHom.comp e.toRingHom = RingHom.id _ := by ext simp /-- Construct an equivalence of rings from homomorphisms in both directions, which are inverses. -/ @[simps] def ofHomInv' {R S F G : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [FunLike F R S] [FunLike G S R] [NonUnitalRingHomClass F R S] [NonUnitalRingHomClass G S R] (hom : F) (inv : G) (hom_inv_id : (inv : S →ₙ+* R).comp (hom : R →ₙ+* S) = NonUnitalRingHom.id R) (inv_hom_id : (hom : R →ₙ+* S).comp (inv : S →ₙ+* R) = NonUnitalRingHom.id S) : R ≃+* S where toFun := hom invFun := inv left_inv := DFunLike.congr_fun hom_inv_id right_inv := DFunLike.congr_fun inv_hom_id map_mul' := map_mul hom map_add' := map_add hom /-- Construct an equivalence of rings from unital homomorphisms in both directions, which are inverses. -/ @[simps] def ofHomInv {R S F G : Type*} [NonAssocSemiring R] [NonAssocSemiring S] [FunLike F R S] [FunLike G S R] [RingHomClass F R S] [RingHomClass G S R] (hom : F) (inv : G) (hom_inv_id : (inv : S →+* R).comp (hom : R →+* S) = RingHom.id R) (inv_hom_id : (hom : R →+* S).comp (inv : S →+* R) = RingHom.id S) : R ≃+* S where toFun := hom invFun := inv left_inv := DFunLike.congr_fun hom_inv_id right_inv := DFunLike.congr_fun inv_hom_id map_mul' := map_mul hom map_add' := map_add hom end SemiringHom variable [Semiring R] [Semiring S] section GroupPower protected theorem map_pow (f : R ≃+* S) (a) : ∀ n : ℕ, f (a ^ n) = f a ^ n := map_pow f a end GroupPower protected theorem isUnit_iff (f : R ≃+* S) {a} : IsUnit (f a) ↔ IsUnit a := MulEquiv.map_isUnit_iff f end RingEquiv namespace MulEquiv /-- Gives a `RingEquiv` from an element of a `MulEquivClass` preserving addition. -/ def toRingEquiv {R S F : Type*} [Add R] [Add S] [Mul R] [Mul S] [EquivLike F R S] [MulEquivClass F R S] (f : F) (H : ∀ x y : R, f (x + y) = f x + f y) : R ≃+* S := { (f : R ≃* S).toEquiv, (f : R ≃* S), AddEquiv.mk' (f : R ≃* S).toEquiv H with } end MulEquiv namespace AddEquiv /-- Gives a `RingEquiv` from an element of an `AddEquivClass` preserving addition. -/ def toRingEquiv {R S F : Type*} [Add R] [Add S] [Mul R] [Mul S] [EquivLike F R S] [AddEquivClass F R S] (f : F) (H : ∀ x y : R, f (x * y) = f x * f y) : R ≃+* S := { (f : R ≃+ S).toEquiv, (f : R ≃+ S), MulEquiv.mk' (f : R ≃+ S).toEquiv H with } end AddEquiv namespace RingEquiv variable [Add R] [Add S] [Mul R] [Mul S] @[simp] theorem self_trans_symm (e : R ≃+* S) : e.trans e.symm = RingEquiv.refl R := ext e.left_inv @[simp] theorem symm_trans_self (e : R ≃+* S) : e.symm.trans e = RingEquiv.refl S := ext e.right_inv end RingEquiv namespace MulEquiv /-- If two rings are isomorphic, and the second doesn't have zero divisors, then so does the first. -/ protected theorem noZeroDivisors {A : Type*} (B : Type*) [MulZeroClass A] [MulZeroClass B] [NoZeroDivisors B] (e : A ≃* B) : NoZeroDivisors A := e.injective.noZeroDivisors e (map_zero e) (map_mul e) /-- If two rings are isomorphic, and the second is a domain, then so is the first. -/ protected theorem isDomain {A : Type*} (B : Type*) [Semiring A] [Semiring B] [IsDomain B] (e : A ≃* B) : IsDomain A := { e.injective.isLeftCancelMulZero e (map_zero e) (map_mul e), e.injective.isRightCancelMulZero e (map_zero e) (map_mul e) with exists_pair_ne := ⟨e.symm 0, e.symm 1, e.symm.injective.ne zero_ne_one⟩ } end MulEquiv -- guard against import creep assert_not_exists Field assert_not_exists Fintype
Algebra\Ring\Ext.lean
/- Copyright (c) 2024 Raghuram Sundararajan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Raghuram Sundararajan -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Ext /-! # Extensionality lemmas for rings and similar structures In this file we prove extensionality lemmas for the ring-like structures defined in `Mathlib/Algebra/Ring/Defs.lean`, ranging from `NonUnitalNonAssocSemiring` to `CommRing`. These extensionality lemmas take the form of asserting that two algebraic structures on a type are equal whenever the addition and multiplication defined by them are both the same. ## Implementation details We follow `Mathlib/Algebra/Group/Ext.lean` in using the term `(letI := i; HMul.hMul : R → R → R)` to refer to the multiplication specified by a typeclass instance `i` on a type `R` (and similarly for addition). We abbreviate these using some local notations. Since `Mathlib/Algebra/Group/Ext.lean` proved several injectivity lemmas, we do so as well — even if sometimes we don't need them to prove extensionality. ## Tags semiring, ring, extensionality -/ local macro:max "local_hAdd[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HAdd.hAdd : $type → $type → $type)) local macro:max "local_hMul[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HMul.hMul : $type → $type → $type)) universe u variable {R : Type u} /-! ### Distrib -/ namespace Distrib @[ext] theorem ext ⦃inst₁ inst₂ : Distrib R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `add` and `mul` functions and properties. rcases inst₁ with @⟨⟨⟩, ⟨⟩⟩ rcases inst₂ with @⟨⟨⟩, ⟨⟩⟩ -- Prove equality of parts using function extensionality. congr end Distrib /-! ### NonUnitalNonAssocSemiring -/ namespace NonUnitalNonAssocSemiring @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddMonoid` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩ rcases inst₂ with @⟨_, ⟨⟩⟩ -- Prove equality of parts using already-proved extensionality lemmas. congr; ext : 1; assumption theorem toDistrib_injective : Function.Injective (@toDistrib R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocSemiring /-! ### NonUnitalSemiring -/ namespace NonUnitalSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul end NonUnitalSemiring /-! ### NonAssocSemiring and its ancestors This section also includes results for `AddMonoidWithOne`, `AddCommMonoidWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ /- TODO consider relocating these lemmas. -/ @[ext] theorem AddMonoidWithOne.ext ⦃inst₁ inst₂ : AddMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := by have h_monoid : inst₁.toAddMonoid = inst₂.toAddMonoid := by ext : 1; exact h_add have h_zero' : inst₁.toZero = inst₂.toZero := congrArg (·.toZero) h_monoid have h_one' : inst₁.toOne = inst₂.toOne := congrArg One.mk h_one have h_natCast : inst₁.toNatCast.natCast = inst₂.toNatCast.natCast := by funext n; induction n with | zero => rewrite [inst₁.natCast_zero, inst₂.natCast_zero] exact congrArg (@Zero.zero R) h_zero' | succ n h => rw [inst₁.natCast_succ, inst₂.natCast_succ, h_add] exact congrArg₂ _ h h_one rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr theorem AddCommMonoidWithOne.toAddMonoidWithOne_injective : Function.Injective (@AddCommMonoidWithOne.toAddMonoidWithOne R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem AddCommMonoidWithOne.ext ⦃inst₁ inst₂ : AddCommMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := AddCommMonoidWithOne.toAddMonoidWithOne_injective <| AddMonoidWithOne.ext h_add h_one namespace NonAssocSemiring /- The best place to prove that the `NatCast` is determined by the other operations is probably in an extensionality lemma for `AddMonoidWithOne`, in which case we may as well do the typeclasses defined in `Mathlib/Algebra/GroupWithZero/Defs.lean` as well. -/ @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h : inst₁.toNonUnitalNonAssocSemiring = inst₂.toNonUnitalNonAssocSemiring := by ext : 1 <;> assumption have h_zero : (inst₁.toMulZeroClass).toZero.zero = (inst₂.toMulZeroClass).toZero.zero := congrArg (fun inst => (inst.toMulZeroClass).toZero.zero) h have h_one' : (inst₁.toMulZeroOneClass).toMulOneClass.toOne = (inst₂.toMulZeroOneClass).toMulOneClass.toOne := congrArg (@MulOneClass.toOne R) <| by ext : 1; exact h_mul have h_one : (inst₁.toMulZeroOneClass).toMulOneClass.toOne.one = (inst₂.toMulZeroOneClass).toMulOneClass.toOne.one := congrArg (@One.one R) h_one' have : inst₁.toAddCommMonoidWithOne = inst₂.toAddCommMonoidWithOne := by ext : 1 <;> assumption have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this -- Split into `NonUnitalNonAssocSemiring`, `One` and `natCast` instances. cases inst₁; cases inst₂ congr theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ _ ext <;> congr end NonAssocSemiring /-! ### NonUnitalNonAssocRing -/ namespace NonUnitalNonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddCommGroup` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩; rcases inst₂ with @⟨_, ⟨⟩⟩ congr; (ext : 1; assumption) theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ h -- Use above extensionality lemma to prove injectivity by showing that `h_add` and `h_mul` hold. ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocRing /-! ### NonUnitalRing -/ namespace NonUnitalRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr end NonUnitalRing /-! ### NonAssocRing and its ancestors This section also includes results for `AddGroupWithOne`, `AddCommGroupWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ @[ext] theorem AddGroupWithOne.ext ⦃inst₁ inst₂ : AddGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddMonoidWithOne = inst₂.toAddMonoidWithOne := AddMonoidWithOne.ext h_add h_one have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this have h_group : inst₁.toAddGroup = inst₂.toAddGroup := by ext : 1; exact h_add -- Extract equality of necessary substructures from h_group injection h_group with h_group; injection h_group have : inst₁.toIntCast.intCast = inst₂.toIntCast.intCast := by funext n; cases n with | ofNat n => rewrite [Int.ofNat_eq_coe, inst₁.intCast_ofNat, inst₂.intCast_ofNat]; congr | negSucc n => rewrite [inst₁.intCast_negSucc, inst₂.intCast_negSucc]; congr rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr @[ext] theorem AddCommGroupWithOne.ext ⦃inst₁ inst₂ : AddCommGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddCommGroup = inst₂.toAddCommGroup := AddCommGroup.ext h_add have : inst₁.toAddGroupWithOne = inst₂.toAddGroupWithOne := AddGroupWithOne.ext h_add h_one injection this with _ h_addMonoidWithOne; injection h_addMonoidWithOne cases inst₁; cases inst₂ congr namespace NonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h₁ : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by ext : 1 <;> assumption -- Mathematically non-trivial fact: `intCast` is determined by the rest. have h₃ : inst₁.toAddCommGroupWithOne = inst₂.toAddCommGroupWithOne := AddCommGroupWithOne.ext h_add (congrArg (·.toOne.one) h₂) cases inst₁; cases inst₂ congr <;> solve| injection h₁ | injection h₂ | injection h₃ theorem toNonAssocSemiring_injective : Function.Injective (@toNonAssocSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr end NonAssocRing /-! ### Semiring -/ namespace Semiring @[ext] theorem ext ⦃inst₁ inst₂ : Semiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Show that enough substructures are equal. have h₁ : inst₁.toNonUnitalSemiring = inst₂.toNonUnitalSemiring := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by ext : 1 <;> assumption have h₃ : (inst₁.toMonoidWithZero).toMonoid = (inst₂.toMonoidWithZero).toMonoid := by ext : 1; exact h_mul -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr <;> solve| injection h₁ | injection h₂ | injection h₃ theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonAssocSemiring_injective : Function.Injective (@toNonAssocSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end Semiring /-! ### Ring -/ namespace Ring @[ext] theorem ext ⦃inst₁ inst₂ : Ring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Show that enough substructures are equal. have h₁ : inst₁.toSemiring = inst₂.toSemiring := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocRing = inst₂.toNonAssocRing := by ext : 1 <;> assumption /- We prove that the `SubNegMonoid`s are equal because they are one field away from `Sub` and `Neg`, enabling use of `injection`. -/ have h₃ : (inst₁.toAddCommGroup).toAddGroup.toSubNegMonoid = (inst₂.toAddCommGroup).toAddGroup.toSubNegMonoid := congrArg (@AddGroup.toSubNegMonoid R) <| by ext : 1; exact h_add -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr <;> solve | injection h₂ | injection h₃ theorem toNonUnitalRing_injective : Function.Injective (@toNonUnitalRing R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonAssocRing_injective : Function.Injective (@toNonAssocRing R) := by intro _ _ _ ext <;> congr theorem toSemiring_injective : Function.Injective (@toSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end Ring /-! ### NonUnitalNonAssocCommSemiring -/ namespace NonUnitalNonAssocCommSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocCommSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul end NonUnitalNonAssocCommSemiring /-! ### NonUnitalCommSemiring -/ namespace NonUnitalCommSemiring theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalCommSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalSemiring_injective <| NonUnitalSemiring.ext h_add h_mul end NonUnitalCommSemiring -- At present, there is no `NonAssocCommSemiring` in Mathlib. /-! ### NonUnitalNonAssocCommRing -/ namespace NonUnitalNonAssocCommRing theorem toNonUnitalNonAssocRing_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocCommRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocRing_injective <| NonUnitalNonAssocRing.ext h_add h_mul end NonUnitalNonAssocCommRing /-! ### NonUnitalCommRing -/ namespace NonUnitalCommRing theorem toNonUnitalRing_injective : Function.Injective (@toNonUnitalRing R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalCommRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalRing_injective <| NonUnitalRing.ext h_add h_mul end NonUnitalCommRing -- At present, there is no `NonAssocCommRing` in Mathlib. /-! ### CommSemiring -/ namespace CommSemiring theorem toSemiring_injective : Function.Injective (@toSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : CommSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toSemiring_injective <| Semiring.ext h_add h_mul end CommSemiring /-! ### CommRing -/ namespace CommRing theorem toRing_injective : Function.Injective (@toRing R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : CommRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toRing_injective <| Ring.ext h_add h_mul end CommRing
Algebra\Ring\Fin.lean
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.Ring.Equiv import Mathlib.Logic.Equiv.Fin /-! # Rings and `Fin` This file collects some basic results involving rings and the `Fin` type ## Main results * `RingEquiv.piFinTwo`: The product over `Fin 2` of some rings is the cartesian product -/ /-- The product over `Fin 2` of some rings is just the cartesian product of these rings. -/ @[simps] def RingEquiv.piFinTwo (R : Fin 2 → Type*) [∀ i, Semiring (R i)] : (∀ i : Fin 2, R i) ≃+* R 0 × R 1 := { piFinTwoEquiv R with toFun := piFinTwoEquiv R map_add' := fun _ _ => rfl map_mul' := fun _ _ => rfl }
Algebra\Ring\Idempotents.lean
/- Copyright (c) 2022 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Subtype import Mathlib.Order.Notation /-! # Idempotents This file defines idempotents for an arbitrary multiplication and proves some basic results, including: * `IsIdempotentElem.mul_of_commute`: In a semigroup, the product of two commuting idempotents is an idempotent; * `IsIdempotentElem.one_sub_iff`: In a (non-associative) ring, `p` is an idempotent if and only if `1-p` is an idempotent. * `IsIdempotentElem.pow_succ_eq`: In a monoid `p ^ (n+1) = p` for `p` an idempotent and `n` a natural number. ## Tags projection, idempotent -/ variable {M N S M₀ M₁ R G G₀ : Type*} variable [Mul M] [Monoid N] [Semigroup S] [MulZeroClass M₀] [MulOneClass M₁] [NonAssocRing R] [Group G] [CancelMonoidWithZero G₀] /-- An element `p` is said to be idempotent if `p * p = p` -/ def IsIdempotentElem (p : M) : Prop := p * p = p namespace IsIdempotentElem theorem of_isIdempotent [Std.IdempotentOp (α := M) (· * ·)] (a : M) : IsIdempotentElem a := Std.IdempotentOp.idempotent a theorem eq {p : M} (h : IsIdempotentElem p) : p * p = p := h theorem mul_of_commute {p q : S} (h : Commute p q) (h₁ : IsIdempotentElem p) (h₂ : IsIdempotentElem q) : IsIdempotentElem (p * q) := by rw [IsIdempotentElem, mul_assoc, ← mul_assoc q, ← h.eq, mul_assoc p, h₂.eq, ← mul_assoc, h₁.eq] theorem zero : IsIdempotentElem (0 : M₀) := mul_zero _ theorem one : IsIdempotentElem (1 : M₁) := mul_one _ theorem one_sub {p : R} (h : IsIdempotentElem p) : IsIdempotentElem (1 - p) := by rw [IsIdempotentElem, mul_sub, mul_one, sub_mul, one_mul, h.eq, sub_self, sub_zero] @[simp] theorem one_sub_iff {p : R} : IsIdempotentElem (1 - p) ↔ IsIdempotentElem p := ⟨fun h => sub_sub_cancel 1 p ▸ h.one_sub, IsIdempotentElem.one_sub⟩ theorem pow {p : N} (n : ℕ) (h : IsIdempotentElem p) : IsIdempotentElem (p ^ n) := Nat.recOn n ((pow_zero p).symm ▸ one) fun n _ => show p ^ n.succ * p ^ n.succ = p ^ n.succ by conv_rhs => rw [← h.eq] -- Porting note: was `nth_rw 3 [← h.eq]` rw [← sq, ← sq, ← pow_mul, ← pow_mul'] theorem pow_succ_eq {p : N} (n : ℕ) (h : IsIdempotentElem p) : p ^ (n + 1) = p := Nat.recOn n ((Nat.zero_add 1).symm ▸ pow_one p) fun n ih => by rw [pow_succ, ih, h.eq] @[simp] theorem iff_eq_one {p : G} : IsIdempotentElem p ↔ p = 1 := Iff.intro (fun h => mul_left_cancel ((mul_one p).symm ▸ h.eq : p * p = p * 1)) fun h => h.symm ▸ one @[simp] theorem iff_eq_zero_or_one {p : G₀} : IsIdempotentElem p ↔ p = 0 ∨ p = 1 := by refine Iff.intro (fun h => or_iff_not_imp_left.mpr fun hp => ?_) fun h => h.elim (fun hp => hp.symm ▸ zero) fun hp => hp.symm ▸ one exact mul_left_cancel₀ hp (h.trans (mul_one p).symm) /-! ### Instances on `Subtype IsIdempotentElem` -/ section Instances instance : Zero { p : M₀ // IsIdempotentElem p } where zero := ⟨0, zero⟩ @[simp] theorem coe_zero : ↑(0 : { p : M₀ // IsIdempotentElem p }) = (0 : M₀) := rfl instance : One { p : M₁ // IsIdempotentElem p } where one := ⟨1, one⟩ @[simp] theorem coe_one : ↑(1 : { p : M₁ // IsIdempotentElem p }) = (1 : M₁) := rfl instance : HasCompl { p : R // IsIdempotentElem p } := ⟨fun p => ⟨1 - p, p.prop.one_sub⟩⟩ @[simp] theorem coe_compl (p : { p : R // IsIdempotentElem p }) : ↑pᶜ = (1 : R) - ↑p := rfl @[simp] theorem compl_compl (p : { p : R // IsIdempotentElem p }) : pᶜᶜ = p := Subtype.ext <| sub_sub_cancel _ _ @[simp] theorem zero_compl : (0 : { p : R // IsIdempotentElem p })ᶜ = 1 := Subtype.ext <| sub_zero _ @[simp] theorem one_compl : (1 : { p : R // IsIdempotentElem p })ᶜ = 0 := Subtype.ext <| sub_self _ end Instances end IsIdempotentElem
Algebra\Ring\Identities.lean
/- Copyright (c) 2020 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bryan Gin-ge Chen, Kevin Lacker -/ import Mathlib.Tactic.Ring /-! # Identities This file contains some "named" commutative ring identities. -/ variable {R : Type*} [CommRing R] {a b x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ y₁ y₂ y₃ y₄ y₅ y₆ y₇ y₈ n : R} /-- Brahmagupta-Fibonacci identity or Diophantus identity, see <https://en.wikipedia.org/wiki/Brahmagupta%E2%80%93Fibonacci_identity>. This sign choice here corresponds to the signs obtained by multiplying two complex numbers. -/ theorem sq_add_sq_mul_sq_add_sq : (x₁ ^ 2 + x₂ ^ 2) * (y₁ ^ 2 + y₂ ^ 2) = (x₁ * y₁ - x₂ * y₂) ^ 2 + (x₁ * y₂ + x₂ * y₁) ^ 2 := by ring /-- Brahmagupta's identity, see <https://en.wikipedia.org/wiki/Brahmagupta%27s_identity> -/ theorem sq_add_mul_sq_mul_sq_add_mul_sq : (x₁ ^ 2 + n * x₂ ^ 2) * (y₁ ^ 2 + n * y₂ ^ 2) = (x₁ * y₁ - n * x₂ * y₂) ^ 2 + n * (x₁ * y₂ + x₂ * y₁) ^ 2 := by ring /-- Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>. -/ theorem pow_four_add_four_mul_pow_four : a ^ 4 + 4 * b ^ 4 = ((a - b) ^ 2 + b ^ 2) * ((a + b) ^ 2 + b ^ 2) := by ring /-- Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>. -/ theorem pow_four_add_four_mul_pow_four' : a ^ 4 + 4 * b ^ 4 = (a ^ 2 - 2 * a * b + 2 * b ^ 2) * (a ^ 2 + 2 * a * b + 2 * b ^ 2) := by ring /-- Euler's four-square identity, see <https://en.wikipedia.org/wiki/Euler%27s_four-square_identity>. This sign choice here corresponds to the signs obtained by multiplying two quaternions. -/ theorem sum_four_sq_mul_sum_four_sq : (x₁ ^ 2 + x₂ ^ 2 + x₃ ^ 2 + x₄ ^ 2) * (y₁ ^ 2 + y₂ ^ 2 + y₃ ^ 2 + y₄ ^ 2) = (x₁ * y₁ - x₂ * y₂ - x₃ * y₃ - x₄ * y₄) ^ 2 + (x₁ * y₂ + x₂ * y₁ + x₃ * y₄ - x₄ * y₃) ^ 2 + (x₁ * y₃ - x₂ * y₄ + x₃ * y₁ + x₄ * y₂) ^ 2 + (x₁ * y₄ + x₂ * y₃ - x₃ * y₂ + x₄ * y₁) ^ 2 := by ring /-- Degen's eight squares identity, see <https://en.wikipedia.org/wiki/Degen%27s_eight-square_identity>. This sign choice here corresponds to the signs obtained by multiplying two octonions. -/ theorem sum_eight_sq_mul_sum_eight_sq : (x₁ ^ 2 + x₂ ^ 2 + x₃ ^ 2 + x₄ ^ 2 + x₅ ^ 2 + x₆ ^ 2 + x₇ ^ 2 + x₈ ^ 2) * (y₁ ^ 2 + y₂ ^ 2 + y₃ ^ 2 + y₄ ^ 2 + y₅ ^ 2 + y₆ ^ 2 + y₇ ^ 2 + y₈ ^ 2) = (x₁ * y₁ - x₂ * y₂ - x₃ * y₃ - x₄ * y₄ - x₅ * y₅ - x₆ * y₆ - x₇ * y₇ - x₈ * y₈) ^ 2 + (x₁ * y₂ + x₂ * y₁ + x₃ * y₄ - x₄ * y₃ + x₅ * y₆ - x₆ * y₅ - x₇ * y₈ + x₈ * y₇) ^ 2 + (x₁ * y₃ - x₂ * y₄ + x₃ * y₁ + x₄ * y₂ + x₅ * y₇ + x₆ * y₈ - x₇ * y₅ - x₈ * y₆) ^ 2 + (x₁ * y₄ + x₂ * y₃ - x₃ * y₂ + x₄ * y₁ + x₅ * y₈ - x₆ * y₇ + x₇ * y₆ - x₈ * y₅) ^ 2 + (x₁ * y₅ - x₂ * y₆ - x₃ * y₇ - x₄ * y₈ + x₅ * y₁ + x₆ * y₂ + x₇ * y₃ + x₈ * y₄) ^ 2 + (x₁ * y₆ + x₂ * y₅ - x₃ * y₈ + x₄ * y₇ - x₅ * y₂ + x₆ * y₁ - x₇ * y₄ + x₈ * y₃) ^ 2 + (x₁ * y₇ + x₂ * y₈ + x₃ * y₅ - x₄ * y₆ - x₅ * y₃ + x₆ * y₄ + x₇ * y₁ - x₈ * y₂) ^ 2 + (x₁ * y₈ - x₂ * y₇ + x₃ * y₆ + x₄ * y₅ - x₅ * y₄ - x₆ * y₃ + x₇ * y₂ + x₈ * y₁) ^ 2 := by ring
Algebra\Ring\InjSurj.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Opposites import Mathlib.Algebra.GroupWithZero.InjSurj /-! # Pulling back rings along injective maps, and pushing them forward along surjective maps -/ variable {α β : Type*} namespace Function.Injective variable (f : β → α) (hf : Injective f) variable [Add β] [Mul β] /-- Pullback a `LeftDistribClass` instance along an injective function. -/ theorem leftDistribClass [Mul α] [Add α] [LeftDistribClass α] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : LeftDistribClass β where left_distrib x y z := hf <| by simp only [*, left_distrib] /-- Pullback a `RightDistribClass` instance along an injective function. -/ theorem rightDistribClass [Mul α] [Add α] [RightDistribClass α] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : RightDistribClass β where right_distrib x y z := hf <| by simp only [*, right_distrib] variable [Zero β] [One β] [Neg β] [Sub β] [SMul ℕ β] [SMul ℤ β] [Pow β ℕ] [NatCast β] [IntCast β] /-- Pullback a `Distrib` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev distrib [Distrib α] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : Distrib β where __ := hf.leftDistribClass f add mul __ := hf.rightDistribClass f add mul /-- A type endowed with `-` and `*` has distributive negation, if it admits an injective map that preserves `-` and `*` to a type which has distributive negation. -/ -- -- See note [reducible non-instances] protected abbrev hasDistribNeg (f : β → α) (hf : Injective f) [Mul α] [HasDistribNeg α] (neg : ∀ a, f (-a) = -f a) (mul : ∀ a b, f (a * b) = f a * f b) : HasDistribNeg β := { hf.involutiveNeg _ neg, ‹Mul β› with neg_mul := fun x y => hf <| by erw [neg, mul, neg, neg_mul, mul], mul_neg := fun x y => hf <| by erw [neg, mul, neg, mul_neg, mul] } /-- Pullback a `NonUnitalNonAssocSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocSemiring β where toAddCommMonoid := hf.addCommMonoid f zero add (swap nsmul) __ := hf.distrib f add mul __ := hf.mulZeroClass f zero mul /-- Pullback a `NonUnitalSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalSemiring [NonUnitalSemiring α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalSemiring β where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.semigroupWithZero f zero mul /-- Pullback a `NonAssocSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocSemiring [NonAssocSemiring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : NonAssocSemiring β where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.mulZeroOneClass f zero one mul __ := hf.addMonoidWithOne f zero one add nsmul natCast /-- Pullback a `Semiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev semiring [Semiring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : Semiring β where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.monoidWithZero f zero one mul npow /-- Pullback a `NonUnitalNonAssocRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocRing [NonUnitalNonAssocRing α] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocRing β where toAddCommGroup := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) __ := hf.nonUnitalNonAssocSemiring f zero add mul nsmul /-- Pullback a `NonUnitalRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalRing [NonUnitalRing α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalRing β where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalSemiring f zero add mul nsmul /-- Pullback a `NonAssocRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocRing [NonAssocRing α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : NonAssocRing β where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.addCommGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast /-- Pullback a `Ring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev ring [Ring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : Ring β where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.addGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast __ := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) /-- Pullback a `NonUnitalNonAssocCommSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommSemiring [NonUnitalNonAssocCommSemiring α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommSemiring β where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.commMagma f mul /-- Pullback a `NonUnitalCommSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalCommSemiring [NonUnitalCommSemiring α] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalCommSemiring β where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.commSemigroup f mul -- `NonAssocCommSemiring` currently doesn't exist /-- Pullback a `CommSemiring` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev commSemiring [CommSemiring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : CommSemiring β where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.commSemigroup f mul /-- Pullback a `NonUnitalNonAssocCommRing` instance along an injective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommRing [NonUnitalNonAssocCommRing α] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommRing β where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommSemiring f zero add mul nsmul /-- Pullback a `NonUnitalCommRing` instance along an injective function. -/ -- -- See note [reducible non-instances] protected abbrev nonUnitalCommRing [NonUnitalCommRing α] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalCommRing β where toNonUnitalRing := hf.nonUnitalRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommRing f zero add mul neg sub nsmul zsmul /-- Pullback a `CommRing` instance along an injective function. -/ -- -- See note [reducible non-instances] protected abbrev commRing [CommRing α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : CommRing β where toRing := hf.ring f zero one add mul neg sub nsmul zsmul npow natCast intCast __ := hf.commMonoid f one mul npow end Function.Injective namespace Function.Surjective variable (f : α → β) (hf : Surjective f) variable [Add β] [Mul β] /-- Pushforward a `LeftDistribClass` instance along a surjective function. -/ theorem leftDistribClass [Mul α] [Add α] [LeftDistribClass α] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : LeftDistribClass β where left_distrib := hf.forall₃.2 fun x y z => by simp only [← add, ← mul, left_distrib] /-- Pushforward a `RightDistribClass` instance along a surjective function. -/ theorem rightDistribClass [Mul α] [Add α] [RightDistribClass α] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : RightDistribClass β where right_distrib := hf.forall₃.2 fun x y z => by simp only [← add, ← mul, right_distrib] /-- Pushforward a `Distrib` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev distrib [Distrib α] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : Distrib β where __ := hf.leftDistribClass f add mul __ := hf.rightDistribClass f add mul variable [Zero β] [One β] [Neg β] [Sub β] [SMul ℕ β] [SMul ℤ β] [Pow β ℕ] [NatCast β] [IntCast β] /-- A type endowed with `-` and `*` has distributive negation, if it admits a surjective map that preserves `-` and `*` from a type which has distributive negation. -/ -- See note [reducible non-instances] protected abbrev hasDistribNeg [Mul α] [HasDistribNeg α] (neg : ∀ a, f (-a) = -f a) (mul : ∀ a b, f (a * b) = f a * f b) : HasDistribNeg β := { hf.involutiveNeg _ neg, ‹Mul β› with neg_mul := hf.forall₂.2 fun x y => by erw [← neg, ← mul, neg_mul, neg, mul] mul_neg := hf.forall₂.2 fun x y => by erw [← neg, ← mul, mul_neg, neg, mul] } /-- Pushforward a `NonUnitalNonAssocSemiring` instance along a surjective function. See note [reducible non-instances]. -/ protected abbrev nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocSemiring β where toAddCommMonoid := hf.addCommMonoid f zero add (swap nsmul) __ := hf.distrib f add mul __ := hf.mulZeroClass f zero mul /-- Pushforward a `NonUnitalSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalSemiring [NonUnitalSemiring α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalSemiring β where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.semigroupWithZero f zero mul /-- Pushforward a `NonAssocSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocSemiring [NonAssocSemiring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) : NonAssocSemiring β where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.mulZeroOneClass f zero one mul __ := hf.addMonoidWithOne f zero one add nsmul natCast /-- Pushforward a `Semiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev semiring [Semiring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : Semiring β where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.monoidWithZero f zero one mul npow /-- Pushforward a `NonUnitalNonAssocRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocRing [NonUnitalNonAssocRing α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocRing β where toAddCommGroup := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) __ := hf.nonUnitalNonAssocSemiring f zero add mul nsmul /-- Pushforward a `NonUnitalRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalRing [NonUnitalRing α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalRing β where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalSemiring f zero add mul nsmul /-- Pushforward a `NonAssocRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonAssocRing [NonAssocRing α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : NonAssocRing β where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonAssocSemiring f zero one add mul nsmul natCast __ := hf.addCommGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast /-- Pushforward a `Ring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev ring [Ring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : Ring β where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.addGroupWithOne f zero one add neg sub nsmul zsmul natCast intCast __ := hf.addCommGroup f zero add neg sub (swap nsmul) (swap zsmul) /-- Pushforward a `NonUnitalNonAssocCommSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommSemiring [NonUnitalNonAssocCommSemiring α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommSemiring β where toNonUnitalNonAssocSemiring := hf.nonUnitalNonAssocSemiring f zero add mul nsmul __ := hf.commMagma f mul /-- Pushforward a `NonUnitalCommSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalCommSemiring [NonUnitalCommSemiring α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) : NonUnitalCommSemiring β where toNonUnitalSemiring := hf.nonUnitalSemiring f zero add mul nsmul __ := hf.commSemigroup f mul /-- Pushforward a `CommSemiring` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev commSemiring [CommSemiring α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) : CommSemiring β where toSemiring := hf.semiring f zero one add mul nsmul npow natCast __ := hf.commSemigroup f mul /-- Pushforward a `NonUnitalNonAssocCommRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalNonAssocCommRing [NonUnitalNonAssocCommRing α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalNonAssocCommRing β where toNonUnitalNonAssocRing := hf.nonUnitalNonAssocRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommSemiring f zero add mul nsmul /-- Pushforward a `NonUnitalCommRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev nonUnitalCommRing [NonUnitalCommRing α] (zero : f 0 = 0) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) : NonUnitalCommRing β where toNonUnitalRing := hf.nonUnitalRing f zero add mul neg sub nsmul zsmul __ := hf.nonUnitalNonAssocCommRing f zero add mul neg sub nsmul zsmul /-- Pushforward a `CommRing` instance along a surjective function. -/ -- See note [reducible non-instances] protected abbrev commRing [CommRing α] (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) : CommRing β where toRing := hf.ring f zero one add mul neg sub nsmul zsmul npow natCast intCast __ := hf.commMonoid f one mul npow end Function.Surjective variable [Mul α] [HasDistribNeg α] instance AddOpposite.instHasDistribNeg : HasDistribNeg αᵃᵒᵖ := unop_injective.hasDistribNeg _ unop_neg unop_mul
Algebra\Ring\Int.lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.Group.Int import Mathlib.Algebra.Ring.Parity /-! # The integers are a ring This file contains the commutative ring instance on `ℤ`. See note [foundational algebra order theory]. ## Note If this file needs to be split, please create an `Algebra.Ring.Int` folder and make the first file be `Algebra.Ring.Int.Basic`. -/ assert_not_exists DenselyOrdered assert_not_exists Set.Subsingleton namespace Int instance instCommRing : CommRing ℤ where __ := instAddCommGroup __ := instCommSemigroup zero_mul := Int.zero_mul mul_zero := Int.mul_zero left_distrib := Int.mul_add right_distrib := Int.add_mul mul_one := Int.mul_one one_mul := Int.one_mul npow n x := x ^ n npow_zero _ := rfl npow_succ _ _ := rfl natCast := (·) natCast_zero := rfl natCast_succ _ := rfl intCast := (·) intCast_ofNat _ := rfl intCast_negSucc _ := rfl instance instCancelCommMonoidWithZero : CancelCommMonoidWithZero ℤ where mul_left_cancel_of_ne_zero {_a _b _c} ha := (mul_eq_mul_left_iff ha).1 instance instCharZero : CharZero ℤ where cast_injective _ _ := ofNat.inj instance instMulDivCancelClass : MulDivCancelClass ℤ where mul_div_cancel _ _ := mul_ediv_cancel _ @[simp, norm_cast] lemma cast_mul {α : Type*} [NonAssocRing α] : ∀ m n, ((m * n : ℤ) : α) = m * n := fun m => by obtain ⟨m, rfl | rfl⟩ := Int.eq_nat_or_neg m · induction m with | zero => simp | succ m ih => simp_all [add_mul] · induction m with | zero => simp | succ m ih => simp_all [add_mul] @[simp, norm_cast] lemma cast_pow {R : Type*} [Ring R] (n : ℤ) (m : ℕ) : ↑(n ^ m) = (n ^ m : R) := by induction' m with m ih <;> simp [_root_.pow_succ, *] /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances like `Int.normedCommRing` being used to construct these instances non-computably. -/ instance instCommSemiring : CommSemiring ℤ := inferInstance instance instSemiring : Semiring ℤ := inferInstance instance instRing : Ring ℤ := inferInstance instance instDistrib : Distrib ℤ := inferInstance /-! ### Miscellaneous lemmas -/ /-! #### Units -/ lemma units_eq_one_or (u : ℤˣ) : u = 1 ∨ u = -1 := by simpa only [Units.ext_iff] using isUnit_eq_one_or u.isUnit lemma units_ne_iff_eq_neg {u v : ℤˣ} : u ≠ v ↔ u = -v := by simpa only [Ne, Units.ext_iff] using isUnit_ne_iff_eq_neg u.isUnit v.isUnit /-! #### Parity -/ variable {m n : ℤ} lemma odd_iff : Odd n ↔ n % 2 = 1 where mp := fun ⟨m, hm⟩ ↦ by simp [hm, add_emod] mpr h := ⟨n / 2, by rw [← h, add_comm, emod_add_ediv n 2]⟩ lemma not_odd_iff : ¬Odd n ↔ n % 2 = 0 := by rw [odd_iff, emod_two_ne_one] lemma even_iff_not_odd : Even n ↔ ¬Odd n := by rw [not_odd_iff, even_iff] @[simp] lemma odd_iff_not_even : Odd n ↔ ¬Even n := by rw [not_even_iff, odd_iff] lemma even_or_odd (n : ℤ) : Even n ∨ Odd n := Or.imp_right odd_iff_not_even.2 <| em <| Even n lemma even_or_odd' (n : ℤ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 := by simpa only [two_mul, exists_or, Odd, Even] using even_or_odd n lemma even_xor'_odd (n : ℤ) : Xor' (Even n) (Odd n) := by cases even_or_odd n with | inl h => exact Or.inl ⟨h, even_iff_not_odd.mp h⟩ | inr h => exact Or.inr ⟨h, odd_iff_not_even.mp h⟩ lemma even_xor'_odd' (n : ℤ) : ∃ k, Xor' (n = 2 * k) (n = 2 * k + 1) := by rcases even_or_odd n with (⟨k, rfl⟩ | ⟨k, rfl⟩) <;> use k · simpa only [← two_mul, Xor', true_and_iff, eq_self_iff_true, not_true, or_false_iff, and_false_iff] using (succ_ne_self (2 * k)).symm · simp only [Xor', add_right_eq_self, false_or_iff, eq_self_iff_true, not_true, not_false_iff, one_ne_zero, and_self_iff] instance : DecidablePred (Odd : ℤ → Prop) := fun _ => decidable_of_iff _ odd_iff_not_even.symm lemma even_add' : Even (m + n) ↔ (Odd m ↔ Odd n) := by rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not] set_option linter.deprecated false in @[simp, deprecated (since := "2023-01-26")] lemma not_even_bit1 (n : ℤ) : ¬Even (2 * n + 1) := by simp [parity_simps] lemma not_even_two_mul_add_one (n : ℤ) : ¬ Even (2 * n + 1) := odd_iff_not_even.1 <| odd_two_mul_add_one n lemma even_sub' : Even (m - n) ↔ (Odd m ↔ Odd n) := by rw [even_sub, even_iff_not_odd, even_iff_not_odd, not_iff_not] lemma odd_mul : Odd (m * n) ↔ Odd m ∧ Odd n := by simp [not_or, parity_simps] lemma Odd.of_mul_left (h : Odd (m * n)) : Odd m := (odd_mul.mp h).1 lemma Odd.of_mul_right (h : Odd (m * n)) : Odd n := (odd_mul.mp h).2 @[parity_simps] lemma odd_pow {n : ℕ} : Odd (m ^ n) ↔ Odd m ∨ n = 0 := by rw [← not_iff_not, ← even_iff_not_odd, not_or, ← even_iff_not_odd, even_pow] lemma odd_pow' {n : ℕ} (h : n ≠ 0) : Odd (m ^ n) ↔ Odd m := odd_pow.trans <| or_iff_left h @[parity_simps] lemma odd_add : Odd (m + n) ↔ (Odd m ↔ Even n) := by rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even] lemma odd_add' : Odd (m + n) ↔ (Odd n ↔ Even m) := by rw [add_comm, odd_add] lemma ne_of_odd_add (h : Odd (m + n)) : m ≠ n := fun hnot ↦ by simp [hnot, parity_simps] at h @[parity_simps] lemma odd_sub : Odd (m - n) ↔ (Odd m ↔ Even n) := by rw [odd_iff_not_even, even_sub, not_iff, odd_iff_not_even] lemma odd_sub' : Odd (m - n) ↔ (Odd n ↔ Even m) := by rw [odd_iff_not_even, even_sub, not_iff, not_iff_comm, odd_iff_not_even] lemma even_mul_succ_self (n : ℤ) : Even (n * (n + 1)) := by simpa [even_mul, parity_simps] using n.even_or_odd lemma even_mul_pred_self (n : ℤ) : Even (n * (n - 1)) := by simpa [even_mul, parity_simps] using n.even_or_odd -- Porting note (#10618): was simp. simp can prove this. @[norm_cast] lemma odd_coe_nat (n : ℕ) : Odd (n : ℤ) ↔ Odd n := by rw [odd_iff_not_even, Nat.odd_iff_not_even, even_coe_nat] @[simp] lemma natAbs_even : Even n.natAbs ↔ Even n := by simp [even_iff_two_dvd, dvd_natAbs, natCast_dvd.symm] -- Porting note (#10618): was simp. simp can prove this. --@[simp] lemma natAbs_odd : Odd n.natAbs ↔ Odd n := by rw [odd_iff_not_even, Nat.odd_iff_not_even, natAbs_even] alias ⟨_, _root_.Even.natAbs⟩ := natAbs_even alias ⟨_, _root_.Odd.natAbs⟩ := natAbs_odd -- Porting note: "protected"-attribute not implemented yet. -- mathlib3 had: -- `attribute [protected] Even.natAbs Odd.natAbs` lemma four_dvd_add_or_sub_of_odd {a b : ℤ} (ha : Odd a) (hb : Odd b) : 4 ∣ a + b ∨ 4 ∣ a - b := by obtain ⟨m, rfl⟩ := ha obtain ⟨n, rfl⟩ := hb obtain h | h := Int.even_or_odd (m + n) · right rw [Int.even_add, ← Int.even_sub] at h obtain ⟨k, hk⟩ := h convert dvd_mul_right 4 k using 1 rw [eq_add_of_sub_eq hk, mul_add, add_assoc, add_sub_cancel_right, ← two_mul, ← mul_assoc] rfl · left obtain ⟨k, hk⟩ := h convert dvd_mul_right 4 (k + 1) using 1 rw [eq_sub_of_add_eq hk, add_right_comm, ← add_sub, mul_add, mul_sub, add_assoc, add_assoc, sub_add, add_assoc, ← sub_sub (2 * n), sub_self, zero_sub, sub_neg_eq_add, ← mul_assoc, mul_add] rfl lemma two_mul_ediv_two_add_one_of_odd : Odd n → 2 * (n / 2) + 1 = n := by rintro ⟨c, rfl⟩ rw [mul_comm] convert Int.ediv_add_emod' (2 * c + 1) 2 simp [Int.add_emod] lemma ediv_two_mul_two_add_one_of_odd : Odd n → n / 2 * 2 + 1 = n := by rintro ⟨c, rfl⟩ convert Int.ediv_add_emod' (2 * c + 1) 2 simp [Int.add_emod] lemma add_one_ediv_two_mul_two_of_odd : Odd n → 1 + n / 2 * 2 = n := by rintro ⟨c, rfl⟩ rw [add_comm] convert Int.ediv_add_emod' (2 * c + 1) 2 simp [Int.add_emod] lemma two_mul_ediv_two_of_odd (h : Odd n) : 2 * (n / 2) = n - 1 := eq_sub_of_add_eq (two_mul_ediv_two_add_one_of_odd h) @[norm_cast, simp] theorem isSquare_natCast_iff {n : ℕ} : IsSquare (n : ℤ) ↔ IsSquare n := by constructor <;> rintro ⟨x, h⟩ · exact ⟨x.natAbs, (natAbs_mul_natAbs_eq h.symm).symm⟩ · exact ⟨x, mod_cast h⟩ -- See note [no_index around OfNat.ofNat] @[simp] theorem isSquare_ofNat_iff {n : ℕ} : IsSquare (no_index (OfNat.ofNat n) : ℤ) ↔ IsSquare (OfNat.ofNat n : ℕ) := isSquare_natCast_iff end Int
Algebra\Ring\Invertible.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.GroupWithZero.Invertible import Mathlib.Algebra.Ring.Defs /-! # Theorems about invertible elements in rings -/ universe u variable {α : Type u} /-- `-⅟a` is the inverse of `-a` -/ def invertibleNeg [Mul α] [One α] [HasDistribNeg α] (a : α) [Invertible a] : Invertible (-a) := ⟨-⅟ a, by simp, by simp⟩ @[simp] theorem invOf_neg [Monoid α] [HasDistribNeg α] (a : α) [Invertible a] [Invertible (-a)] : ⅟ (-a) = -⅟ a := invOf_eq_right_inv (by simp) @[simp] theorem one_sub_invOf_two [Ring α] [Invertible (2 : α)] : 1 - (⅟ 2 : α) = ⅟ 2 := (isUnit_of_invertible (2 : α)).mul_right_inj.1 <| by rw [mul_sub, mul_invOf_self, mul_one, ← one_add_one_eq_two, add_sub_cancel_right] @[simp] theorem invOf_two_add_invOf_two [NonAssocSemiring α] [Invertible (2 : α)] : (⅟ 2 : α) + (⅟ 2 : α) = 1 := by rw [← two_mul, mul_invOf_self] theorem pos_of_invertible_cast [Semiring α] [Nontrivial α] (n : ℕ) [Invertible (n : α)] : 0 < n := Nat.zero_lt_of_ne_zero fun h => nonzero_of_invertible (n : α) (h ▸ Nat.cast_zero) theorem invOf_add_invOf [Semiring α] (a b : α) [Invertible a] [Invertible b] : ⅟a + ⅟b = ⅟a * (a + b) * ⅟b := by rw [mul_add, invOf_mul_self, add_mul, one_mul, mul_assoc, mul_invOf_self, mul_one, add_comm] /-- A version of `inv_sub_inv'` for `invOf`. -/ theorem invOf_sub_invOf [Ring α] (a b : α) [Invertible a] [Invertible b] : ⅟a - ⅟b = ⅟a * (b - a) * ⅟b := by rw [mul_sub, invOf_mul_self, sub_mul, one_mul, mul_assoc, mul_invOf_self, mul_one] /-- A version of `inv_add_inv'` for `Ring.inverse`. -/ theorem Ring.inverse_add_inverse [Semiring α] {a b : α} (h : IsUnit a ↔ IsUnit b) : Ring.inverse a + Ring.inverse b = Ring.inverse a * (a + b) * Ring.inverse b := by by_cases ha : IsUnit a · have hb := h.mp ha obtain ⟨ia⟩ := ha.nonempty_invertible obtain ⟨ib⟩ := hb.nonempty_invertible simp_rw [inverse_invertible, invOf_add_invOf] · have hb := h.not.mp ha simp [inverse_non_unit, ha, hb] /-- A version of `inv_sub_inv'` for `Ring.inverse`. -/ theorem Ring.inverse_sub_inverse [Ring α] {a b : α} (h : IsUnit a ↔ IsUnit b) : Ring.inverse a - Ring.inverse b = Ring.inverse a * (b - a) * Ring.inverse b := by by_cases ha : IsUnit a · have hb := h.mp ha obtain ⟨ia⟩ := ha.nonempty_invertible obtain ⟨ib⟩ := hb.nonempty_invertible simp_rw [inverse_invertible, invOf_sub_invOf] · have hb := h.not.mp ha simp [inverse_non_unit, ha, hb]
Algebra\Ring\MinimalAxioms.lean
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.MinimalAxioms /-! # Minimal Axioms for a Ring This file defines constructors to define a `Ring` or `CommRing` structure on a Type, while proving a minimum number of equalities. ## Main Definitions * `Ring.ofMinimalAxioms`: Define a `Ring` structure on a Type by proving a minimized set of axioms * `CommRing.ofMinimalAxioms`: Define a `CommRing` structure on a Type by proving a minimized set of axioms -/ universe u /-- Define a `Ring` structure on a Type by proving a minimized set of axioms. Note that this uses the default definitions for `npow`, `nsmul`, `zsmul` and `sub` See note [reducible non-instances]. -/ abbrev Ring.ofMinimalAxioms {R : Type u} [Add R] [Mul R] [Neg R] [Zero R] [One R] (add_assoc : ∀ a b c : R, a + b + c = a + (b + c)) (zero_add : ∀ a : R, 0 + a = a) (add_left_neg : ∀ a : R, -a + a = 0) (mul_assoc : ∀ a b c : R, a * b * c = a * (b * c)) (one_mul : ∀ a : R, 1 * a = a) (mul_one : ∀ a : R, a * 1 = a) (left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c) (right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c) : Ring R := letI := AddGroup.ofLeftAxioms add_assoc zero_add add_left_neg haveI add_comm : ∀ a b, a + b = b + a := by intro a b have h₁ : (1 + 1 : R) * (a + b) = a + (a + b) + b := by rw [left_distrib] simp only [right_distrib, one_mul, add_assoc] have h₂ : (1 + 1 : R) * (a + b) = a + (b + a) + b := by rw [right_distrib] simp only [left_distrib, one_mul, add_assoc] have := h₁.symm.trans h₂ rwa [add_left_inj, add_right_inj] at this haveI zero_mul : ∀ a, (0 : R) * a = 0 := fun a => by have : 0 * a = 0 * a + 0 * a := calc 0 * a = (0 + 0) * a := by rw [zero_add] _ = 0 * a + 0 * a := by rw [right_distrib] rwa [self_eq_add_right] at this haveI mul_zero : ∀ a, a * (0 : R) = 0 := fun a => by have : a * 0 = a * 0 + a * 0 := calc a * 0 = a * (0 + 0) := by rw [zero_add] _ = a * 0 + a * 0 := by rw [left_distrib] rwa [self_eq_add_right] at this { add_comm := add_comm left_distrib := left_distrib right_distrib := right_distrib zero_mul := zero_mul mul_zero := mul_zero mul_assoc := mul_assoc one_mul := one_mul mul_one := mul_one add_left_neg := add_left_neg zsmul := (· • ·) } /-- Define a `CommRing` structure on a Type by proving a minimized set of axioms. Note that this uses the default definitions for `npow`, `nsmul`, `zsmul` and `sub` See note [reducible non-instances]. -/ abbrev CommRing.ofMinimalAxioms {R : Type u} [Add R] [Mul R] [Neg R] [Zero R] [One R] (add_assoc : ∀ a b c : R, a + b + c = a + (b + c)) (zero_add : ∀ a : R, 0 + a = a) (add_left_neg : ∀ a : R, -a + a = 0) (mul_assoc : ∀ a b c : R, a * b * c = a * (b * c)) (mul_comm : ∀ a b : R, a * b = b * a) (one_mul : ∀ a : R, 1 * a = a) (left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c) : CommRing R := haveI mul_one : ∀ a : R, a * 1 = a := fun a => by rw [mul_comm, one_mul] haveI right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c := fun a b c => by rw [mul_comm, left_distrib, mul_comm, mul_comm b c] letI := Ring.ofMinimalAxioms add_assoc zero_add add_left_neg mul_assoc one_mul mul_one left_distrib right_distrib { mul_comm := mul_comm }
Algebra\Ring\Nat.lean
/- Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.Group.Nat import Mathlib.Algebra.Ring.Defs /-! # The natural numbers form a semiring This file contains the commutative semiring instance on the natural numbers. See note [foundational algebra order theory]. -/ open Multiplicative namespace Nat /-! ### Instances -/ instance instCommSemiring : CommSemiring ℕ where __ := instCommMonoid left_distrib := Nat.left_distrib right_distrib := Nat.right_distrib zero_mul := Nat.zero_mul mul_zero := Nat.mul_zero npow m n := n ^ m npow_zero := Nat.pow_zero npow_succ _ _ := rfl natCast n := n natCast_zero := rfl natCast_succ _ := rfl instance instCancelCommMonoidWithZero : CancelCommMonoidWithZero ℕ where __ : CommMonoidWithZero ℕ := by infer_instance mul_left_cancel_of_ne_zero h := Nat.eq_of_mul_eq_mul_left (Nat.pos_of_ne_zero h) instance instMulDivCancelClass : MulDivCancelClass ℕ where mul_div_cancel _ _b hb := Nat.mul_div_cancel _ (Nat.pos_iff_ne_zero.2 hb) instance instCharZero : CharZero ℕ where cast_injective := Function.injective_id /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances being used to construct these instances non-computably. -/ instance instAddCommMonoidWithOne : AddCommMonoidWithOne ℕ := by infer_instance instance instDistrib : Distrib ℕ := by infer_instance instance instSemiring : Semiring ℕ := by infer_instance end Nat
Algebra\Ring\NegOnePow.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Johan Commelin -/ import Mathlib.Algebra.Ring.Int import Mathlib.Data.ZMod.IntUnitsPower /-! # Integer powers of (-1) This file defines the map `negOnePow : ℤ → ℤˣ` which sends `n` to `(-1 : ℤˣ) ^ n`. The definition of `negOnePow` and some lemmas first appeared in contributions by Johan Commelin to the Liquid Tensor Experiment. -/ namespace Int /-- The map `ℤ → ℤˣ` which sends `n` to `(-1 : ℤˣ) ^ n`. -/ def negOnePow (n : ℤ) : ℤˣ := (-1 : ℤˣ) ^ n lemma negOnePow_def (n : ℤ) : n.negOnePow = (-1 : ℤˣ) ^ n := rfl lemma negOnePow_add (n₁ n₂ : ℤ) : (n₁ + n₂).negOnePow = n₁.negOnePow * n₂.negOnePow := zpow_add _ _ _ @[simp] lemma negOnePow_zero : negOnePow 0 = 1 := rfl @[simp] lemma negOnePow_one : negOnePow 1 = -1 := rfl lemma negOnePow_succ (n : ℤ) : (n + 1).negOnePow = - n.negOnePow := by rw [negOnePow_add, negOnePow_one, mul_neg, mul_one] lemma negOnePow_even (n : ℤ) (hn : Even n) : n.negOnePow = 1 := by obtain ⟨k, rfl⟩ := hn rw [negOnePow_add, units_mul_self] @[simp] lemma negOnePow_two_mul (n : ℤ) : (2 * n).negOnePow = 1 := negOnePow_even _ ⟨n, two_mul n⟩ lemma negOnePow_odd (n : ℤ) (hn : Odd n) : n.negOnePow = -1 := by obtain ⟨k, rfl⟩ := hn simp only [negOnePow_add, negOnePow_two_mul, negOnePow_one, mul_neg, mul_one] @[simp] lemma negOnePow_two_mul_add_one (n : ℤ) : (2 * n + 1).negOnePow = -1 := negOnePow_odd _ ⟨n, rfl⟩ lemma negOnePow_eq_one_iff (n : ℤ) : n.negOnePow = 1 ↔ Even n := by constructor · intro h rw [Int.even_iff_not_odd] intro h' simp only [negOnePow_odd _ h'] at h contradiction · exact negOnePow_even n lemma negOnePow_eq_neg_one_iff (n : ℤ) : n.negOnePow = -1 ↔ Odd n := by constructor · intro h rw [Int.odd_iff_not_even] intro h' rw [negOnePow_even _ h'] at h contradiction · exact negOnePow_odd n @[simp] theorem abs_negOnePow (n : ℤ) : |(n.negOnePow : ℤ)| = 1 := by rw [abs_eq_natAbs, Int.units_natAbs, Nat.cast_one] @[simp] lemma negOnePow_neg (n : ℤ) : (-n).negOnePow = n.negOnePow := by dsimp [negOnePow] simp only [zpow_neg, ← inv_zpow, inv_neg, inv_one] @[simp] lemma negOnePow_abs (n : ℤ) : |n|.negOnePow = n.negOnePow := by obtain h|h := abs_choice n <;> simp only [h, negOnePow_neg] lemma negOnePow_sub (n₁ n₂ : ℤ) : (n₁ - n₂).negOnePow = n₁.negOnePow * n₂.negOnePow := by simp only [sub_eq_add_neg, negOnePow_add, negOnePow_neg] lemma negOnePow_eq_iff (n₁ n₂ : ℤ) : n₁.negOnePow = n₂.negOnePow ↔ Even (n₁ - n₂) := by by_cases h₂ : Even n₂ · rw [negOnePow_even _ h₂, Int.even_sub, negOnePow_eq_one_iff] tauto · rw [← Int.odd_iff_not_even] at h₂ rw [negOnePow_odd _ h₂, Int.even_sub, negOnePow_eq_neg_one_iff, Int.even_iff_not_odd, Int.even_iff_not_odd] tauto @[simp] lemma negOnePow_mul_self (n : ℤ) : (n * n).negOnePow = n.negOnePow := by simpa [mul_sub, negOnePow_eq_iff] using n.even_mul_pred_self lemma coe_negOnePow (K : Type*) (n : ℤ) [Field K] : n.negOnePow = (-1 : K) ^ n := by rcases even_or_odd' n with ⟨k, rfl | rfl⟩ · rw [zpow_mul, zpow_ofNat] simp · rw [zpow_add_one₀ (by norm_num), zpow_mul, zpow_ofNat] simp end Int
Algebra\Ring\Opposite.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.GroupWithZero.Opposite import Mathlib.Algebra.Ring.Hom.Defs /-! # Ring structures on the multiplicative opposite -/ variable {α : Type*} namespace MulOpposite instance instDistrib [Distrib α] : Distrib αᵐᵒᵖ where left_distrib _ _ _ := unop_injective <| add_mul _ _ _ right_distrib _ _ _ := unop_injective <| mul_add _ _ _ instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring α] : NonUnitalNonAssocSemiring αᵐᵒᵖ where __ := instAddCommMonoid __ := instDistrib __ := instMulZeroClass instance instNonUnitalSemiring [NonUnitalSemiring α] : NonUnitalSemiring αᵐᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instSemigroupWithZero instance instNonAssocSemiring [NonAssocSemiring α] : NonAssocSemiring αᵐᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instMulZeroOneClass __ := instAddCommMonoidWithOne instance instSemiring [Semiring α] : Semiring αᵐᵒᵖ where __ := instNonUnitalSemiring __ := instNonAssocSemiring __ := instMonoidWithZero instance instNonUnitalCommSemiring [NonUnitalCommSemiring α] : NonUnitalCommSemiring αᵐᵒᵖ where __ := instNonUnitalSemiring __ := instCommSemigroup instance instCommSemiring [CommSemiring α] : CommSemiring αᵐᵒᵖ where __ := instSemiring __ := instCommMonoid instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing α] : NonUnitalNonAssocRing αᵐᵒᵖ where __ := instAddCommGroup __ := instNonUnitalNonAssocSemiring instance instNonUnitalRing [NonUnitalRing α] : NonUnitalRing αᵐᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonUnitalSemiring instance instNonAssocRing [NonAssocRing α] : NonAssocRing αᵐᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonAssocSemiring __ := instAddCommGroupWithOne instance instRing [Ring α] : Ring αᵐᵒᵖ where __ := instSemiring __ := instAddCommGroupWithOne instance instNonUnitalCommRing [NonUnitalCommRing α] : NonUnitalCommRing αᵐᵒᵖ where __ := instNonUnitalRing __ := instNonUnitalCommSemiring instance instCommRing [CommRing α] : CommRing αᵐᵒᵖ where __ := instRing __ := instCommMonoid instance instIsDomain [Ring α] [IsDomain α] : IsDomain αᵐᵒᵖ := NoZeroDivisors.to_isDomain _ instance instGroupWithZero [GroupWithZero α] : GroupWithZero αᵐᵒᵖ where __ := instMonoidWithZero __ := instNontrivial __ := instDivInvMonoid mul_inv_cancel _ hx := unop_injective <| inv_mul_cancel <| unop_injective.ne hx inv_zero := unop_injective inv_zero end MulOpposite namespace AddOpposite instance instDistrib [Distrib α] : Distrib αᵃᵒᵖ where left_distrib _ _ _ := unop_injective <| mul_add _ _ _ right_distrib _ _ _ := unop_injective <| add_mul _ _ _ instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring α] : NonUnitalNonAssocSemiring αᵃᵒᵖ where __ := instAddCommMonoid __ := instDistrib __ := instMulZeroClass instance instNonUnitalSemiring [NonUnitalSemiring α] : NonUnitalSemiring αᵃᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instSemigroupWithZero instance instNonAssocSemiring [NonAssocSemiring α] : NonAssocSemiring αᵃᵒᵖ where __ := instNonUnitalNonAssocSemiring __ := instMulZeroOneClass __ := instAddCommMonoidWithOne instance instSemiring [Semiring α] : Semiring αᵃᵒᵖ where __ := instNonUnitalSemiring __ := instNonAssocSemiring __ := instMonoidWithZero instance instNonUnitalCommSemiring [NonUnitalCommSemiring α] : NonUnitalCommSemiring αᵃᵒᵖ where __ := instNonUnitalSemiring __ := instCommSemigroup instance instCommSemiring [CommSemiring α] : CommSemiring αᵃᵒᵖ where __ := instSemiring __ := instCommMonoid instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing α] : NonUnitalNonAssocRing αᵃᵒᵖ where __ := instAddCommGroup __ := instNonUnitalNonAssocSemiring instance instNonUnitalRing [NonUnitalRing α] : NonUnitalRing αᵃᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonUnitalSemiring instance instNonAssocRing [NonAssocRing α] : NonAssocRing αᵃᵒᵖ where __ := instNonUnitalNonAssocRing __ := instNonAssocSemiring __ := instAddCommGroupWithOne instance instRing [Ring α] : Ring αᵃᵒᵖ where __ := instSemiring __ := instAddCommGroupWithOne instance instNonUnitalCommRing [NonUnitalCommRing α] : NonUnitalCommRing αᵃᵒᵖ where __ := instNonUnitalRing __ := instNonUnitalCommSemiring instance instCommRing [CommRing α] : CommRing αᵃᵒᵖ where __ := instRing __ := instCommMonoid instance instIsDomain [Ring α] [IsDomain α] : IsDomain αᵃᵒᵖ := NoZeroDivisors.to_isDomain _ end AddOpposite open MulOpposite /-- A non-unital ring homomorphism `f : R →ₙ+* S` such that `f x` commutes with `f y` for all `x, y` defines a non-unital ring homomorphism to `Sᵐᵒᵖ`. -/ @[simps (config := .asFn)] def NonUnitalRingHom.toOpposite {R S : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R →ₙ+* S) (hf : ∀ x y, Commute (f x) (f y)) : R →ₙ+* Sᵐᵒᵖ := { ((opAddEquiv : S ≃+ Sᵐᵒᵖ).toAddMonoidHom.comp ↑f : R →+ Sᵐᵒᵖ), f.toMulHom.toOpposite hf with toFun := MulOpposite.op ∘ f } /-- A non-unital ring homomorphism `f : R →ₙ* S` such that `f x` commutes with `f y` for all `x, y` defines a non-unital ring homomorphism from `Rᵐᵒᵖ`. -/ @[simps (config := .asFn)] def NonUnitalRingHom.fromOpposite {R S : Type*} [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R →ₙ+* S) (hf : ∀ x y, Commute (f x) (f y)) : Rᵐᵒᵖ →ₙ+* S := { (f.toAddMonoidHom.comp (opAddEquiv : R ≃+ Rᵐᵒᵖ).symm.toAddMonoidHom : Rᵐᵒᵖ →+ S), f.toMulHom.fromOpposite hf with toFun := f ∘ MulOpposite.unop } /-- A non-unital ring hom `α →ₙ+* β` can equivalently be viewed as a non-unital ring hom `αᵐᵒᵖ →+* βᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/ @[simps] def NonUnitalRingHom.op {α β} [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] : (α →ₙ+* β) ≃ (αᵐᵒᵖ →ₙ+* βᵐᵒᵖ) where toFun f := { AddMonoidHom.mulOp f.toAddMonoidHom, MulHom.op f.toMulHom with } invFun f := { AddMonoidHom.mulUnop f.toAddMonoidHom, MulHom.unop f.toMulHom with } left_inv _ := rfl right_inv _ := rfl /-- The 'unopposite' of a non-unital ring hom `αᵐᵒᵖ →ₙ+* βᵐᵒᵖ`. Inverse to `NonUnitalRingHom.op`. -/ @[simp] def NonUnitalRingHom.unop {α β} [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] : (αᵐᵒᵖ →ₙ+* βᵐᵒᵖ) ≃ (α →ₙ+* β) := NonUnitalRingHom.op.symm /-- A ring homomorphism `f : R →+* S` such that `f x` commutes with `f y` for all `x, y` defines a ring homomorphism to `Sᵐᵒᵖ`. -/ @[simps (config := .asFn)] def RingHom.toOpposite {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) (hf : ∀ x y, Commute (f x) (f y)) : R →+* Sᵐᵒᵖ := { ((opAddEquiv : S ≃+ Sᵐᵒᵖ).toAddMonoidHom.comp ↑f : R →+ Sᵐᵒᵖ), f.toMonoidHom.toOpposite hf with toFun := MulOpposite.op ∘ f } /-- A ring homomorphism `f : R →+* S` such that `f x` commutes with `f y` for all `x, y` defines a ring homomorphism from `Rᵐᵒᵖ`. -/ @[simps (config := .asFn)] def RingHom.fromOpposite {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) (hf : ∀ x y, Commute (f x) (f y)) : Rᵐᵒᵖ →+* S := { (f.toAddMonoidHom.comp (opAddEquiv : R ≃+ Rᵐᵒᵖ).symm.toAddMonoidHom : Rᵐᵒᵖ →+ S), f.toMonoidHom.fromOpposite hf with toFun := f ∘ MulOpposite.unop } /-- A ring hom `α →+* β` can equivalently be viewed as a ring hom `αᵐᵒᵖ →+* βᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/ @[simps!] def RingHom.op {α β} [NonAssocSemiring α] [NonAssocSemiring β] : (α →+* β) ≃ (αᵐᵒᵖ →+* βᵐᵒᵖ) where toFun f := { AddMonoidHom.mulOp f.toAddMonoidHom, MonoidHom.op f.toMonoidHom with } invFun f := { AddMonoidHom.mulUnop f.toAddMonoidHom, MonoidHom.unop f.toMonoidHom with } left_inv _ := rfl right_inv _ := rfl /-- The 'unopposite' of a ring hom `αᵐᵒᵖ →+* βᵐᵒᵖ`. Inverse to `RingHom.op`. -/ @[simp] def RingHom.unop {α β} [NonAssocSemiring α] [NonAssocSemiring β] : (αᵐᵒᵖ →+* βᵐᵒᵖ) ≃ (α →+* β) := RingHom.op.symm
Algebra\Ring\Parity.lean
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Data.Nat.Cast.Basic import Mathlib.Data.Nat.Cast.Commute import Mathlib.Data.Set.Defs import Mathlib.Logic.Function.Iterate /-! # Even and odd elements in rings This file defines odd elements and proves some general facts about even and odd elements of rings. As opposed to `Even`, `Odd` does not have a multiplicative counterpart. ## TODO Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring` assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved to `Algebra.Group.Even`. ## See also `Algebra.Group.Even` for the definition of even elements. -/ assert_not_exists DenselyOrdered assert_not_exists OrderedRing open MulOpposite variable {F α β R : Type*} section Monoid variable [Monoid α] [HasDistribNeg α] {n : ℕ} {a : α} @[simp] lemma Even.neg_pow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a simp_rw [← two_mul, pow_mul, neg_sq] lemma Even.neg_one_pow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow] end Monoid section DivisionMonoid variable [DivisionMonoid α] [HasDistribNeg α] {a : α} {n : ℤ} lemma Even.neg_zpow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [← Int.two_mul, zpow_mul, zpow_two, neg_mul_neg] lemma Even.neg_one_zpow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow] end DivisionMonoid @[simp] lemma isSquare_zero [MulZeroClass α] : IsSquare (0 : α) := ⟨0, (mul_zero _).symm⟩ section Semiring variable [Semiring α] [Semiring β] {a b : α} {m n : ℕ} lemma even_iff_exists_two_mul : Even a ↔ ∃ b, a = 2 * b := by simp [even_iff_exists_two_nsmul] lemma even_iff_two_dvd : Even a ↔ 2 ∣ a := by simp [Even, Dvd.dvd, two_mul] alias ⟨Even.two_dvd, _⟩ := even_iff_two_dvd lemma Even.trans_dvd (ha : Even a) (hab : a ∣ b) : Even b := even_iff_two_dvd.2 <| ha.two_dvd.trans hab lemma Dvd.dvd.even (hab : a ∣ b) (ha : Even a) : Even b := ha.trans_dvd hab @[simp] lemma range_two_mul (α) [Semiring α] : Set.range (fun x : α ↦ 2 * x) = {a | Even a} := by ext x simp [eq_comm, two_mul, Even] @[simp] lemma even_two : Even (2 : α) := ⟨1, by rw [one_add_one_eq_two]⟩ @[simp] lemma Even.mul_left (ha : Even a) (b) : Even (b * a) := ha.map (AddMonoidHom.mulLeft _) @[simp] lemma Even.mul_right (ha : Even a) (b) : Even (a * b) := ha.map (AddMonoidHom.mulRight _) lemma even_two_mul (a : α) : Even (2 * a) := ⟨a, two_mul _⟩ lemma Even.pow_of_ne_zero (ha : Even a) : ∀ {n : ℕ}, n ≠ 0 → Even (a ^ n) | n + 1, _ => by rw [pow_succ]; exact ha.mul_left _ /-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/ def Odd (a : α) : Prop := ∃ k, a = 2 * k + 1 set_option linter.deprecated false in lemma odd_iff_exists_bit1 : Odd a ↔ ∃ b, a = 2 * b + 1 := exists_congr fun b ↦ by rw [two_mul] alias ⟨Odd.exists_bit1, _⟩ := odd_iff_exists_bit1 @[simp] lemma range_two_mul_add_one (α : Type*) [Semiring α] : Set.range (fun x : α ↦ 2 * x + 1) = {a | Odd a} := by ext x; simp [Odd, eq_comm] lemma Even.add_odd : Even a → Odd b → Odd (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a + b, by rw [mul_add, ← two_mul, add_assoc]⟩ lemma Even.odd_add (ha : Even a) (hb : Odd b) : Odd (b + a) := add_comm a b ▸ ha.add_odd hb lemma Odd.add_even (ha : Odd a) (hb : Even b) : Odd (a + b) := add_comm a b ▸ hb.add_odd ha lemma Odd.add_odd : Odd a → Odd b → Even (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨a + b + 1, ?_⟩ rw [two_mul, two_mul] ac_rfl @[simp] lemma odd_one : Odd (1 : α) := ⟨0, (zero_add _).symm.trans (congr_arg (· + (1 : α)) (mul_zero _).symm)⟩ @[simp] lemma Even.add_one (h : Even a) : Odd (a + 1) := h.add_odd odd_one @[simp] lemma Even.one_add (h : Even a) : Odd (1 + a) := h.odd_add odd_one lemma odd_two_mul_add_one (a : α) : Odd (2 * a + 1) := ⟨_, rfl⟩ @[simp] lemma odd_add_self_one' : Odd (a + (a + 1)) := by simp [← add_assoc] @[simp] lemma odd_add_one_self : Odd (a + 1 + a) := by simp [add_comm _ a] @[simp] lemma odd_add_one_self' : Odd (a + (1 + a)) := by simp [add_comm 1 a] lemma Odd.map [FunLike F α β] [RingHomClass F α β] (f : F) : Odd a → Odd (f a) := by rintro ⟨a, rfl⟩; exact ⟨f a, by simp [two_mul]⟩ lemma Odd.natCast {R : Type*} [Semiring R] {n : ℕ} (hn : Odd n) : Odd (n : R) := hn.map <| Nat.castRingHom R @[simp] lemma Odd.mul : Odd a → Odd b → Odd (a * b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨2 * a * b + b + a, ?_⟩ rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc, ← Nat.cast_two, ← Nat.cast_comm] lemma Odd.pow (ha : Odd a) : ∀ {n : ℕ}, Odd (a ^ n) | 0 => by rw [pow_zero] exact odd_one | n + 1 => by rw [pow_succ]; exact ha.pow.mul ha lemma Odd.pow_add_pow_eq_zero [IsCancelAdd α] (hn : Odd n) (hab : a + b = 0) : a ^ n + b ^ n = 0 := by obtain ⟨k, rfl⟩ := hn induction' k with k ih · simpa have : a ^ 2 = b ^ 2 := add_right_cancel $ calc a ^ 2 + a * b = 0 := by rw [sq, ← mul_add, hab, mul_zero] _ = b ^ 2 + a * b := by rw [sq, ← add_mul, add_comm, hab, zero_mul] refine add_right_cancel (b := b ^ (2 * k + 1) * a ^ 2) ?_ calc _ = (a ^ (2 * k + 1) + b ^ (2 * k + 1)) * a ^ 2 + b ^ (2 * k + 3) := by rw [add_mul, ← pow_add, add_right_comm]; rfl _ = _ := by rw [ih, zero_mul, zero_add, zero_add, this, ← pow_add] end Semiring section Monoid variable [Monoid α] [HasDistribNeg α] {a : α} {n : ℕ} lemma Odd.neg_pow : Odd n → ∀ a : α, (-a) ^ n = -a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg] @[simp] lemma Odd.neg_one_pow (h : Odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow] end Monoid section Ring variable [Ring α] {a b : α} {n : ℕ} /- Porting note (#10618): attribute `simp` removed based on linter report simp can prove this: by simp only [even_neg, even_two] -/ -- @[simp] lemma even_neg_two : Even (-2 : α) := by simp only [even_neg, even_two] lemma Odd.neg (hp : Odd a) : Odd (-a) := by obtain ⟨k, hk⟩ := hp use -(k + 1) rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add, neg_add_cancel_right, ← neg_add, hk] @[simp] lemma odd_neg : Odd (-a) ↔ Odd a := ⟨fun h ↦ neg_neg a ▸ h.neg, Odd.neg⟩ /- Porting note (#10618): attribute `simp` removed based on linter report simp can prove this: by simp only [odd_neg, odd_one] -/ -- @[simp] lemma odd_neg_one : Odd (-1 : α) := by simp lemma Odd.sub_even (ha : Odd a) (hb : Even b) : Odd (a - b) := by rw [sub_eq_add_neg]; exact ha.add_even hb.neg lemma Even.sub_odd (ha : Even a) (hb : Odd b) : Odd (a - b) := by rw [sub_eq_add_neg]; exact ha.add_odd hb.neg lemma Odd.sub_odd (ha : Odd a) (hb : Odd b) : Even (a - b) := by rw [sub_eq_add_neg]; exact ha.add_odd hb.neg end Ring namespace Nat variable {m n : ℕ} lemma odd_iff : Odd n ↔ n % 2 = 1 := ⟨fun ⟨m, hm⟩ ↦ by omega, fun h ↦ ⟨n / 2, (mod_add_div n 2).symm.trans (by rw [h, add_comm])⟩⟩ instance : DecidablePred (Odd : ℕ → Prop) := fun _ ↦ decidable_of_iff _ odd_iff.symm lemma not_odd_iff : ¬Odd n ↔ n % 2 = 0 := by rw [odd_iff, mod_two_ne_one] lemma even_iff_not_odd : Even n ↔ ¬Odd n := by rw [not_odd_iff, even_iff] @[simp] lemma odd_iff_not_even : Odd n ↔ ¬Even n := by rw [not_even_iff, odd_iff] lemma _root_.Odd.not_two_dvd_nat (h : Odd n) : ¬(2 ∣ n) := by rwa [← even_iff_two_dvd, ← odd_iff_not_even] lemma even_xor_odd (n : ℕ) : Xor' (Even n) (Odd n) := by simp [Xor', odd_iff_not_even, Decidable.em (Even n)] lemma even_or_odd (n : ℕ) : Even n ∨ Odd n := (even_xor_odd n).or lemma even_or_odd' (n : ℕ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 := by simpa only [← two_mul, exists_or, Odd, Even] using even_or_odd n lemma even_xor_odd' (n : ℕ) : ∃ k, Xor' (n = 2 * k) (n = 2 * k + 1) := by obtain ⟨k, rfl⟩ | ⟨k, rfl⟩ := even_or_odd n <;> use k · simpa only [← two_mul, eq_self_iff_true, xor_true] using (succ_ne_self (2 * k)).symm · simpa only [xor_true, xor_comm] using (succ_ne_self _) lemma mod_two_add_add_odd_mod_two (m : ℕ) {n : ℕ} (hn : Odd n) : m % 2 + (m + n) % 2 = 1 := ((even_or_odd m).elim fun hm ↦ by rw [even_iff.1 hm, odd_iff.1 (hm.add_odd hn)]) fun hm ↦ by rw [odd_iff.1 hm, even_iff.1 (hm.add_odd hn)] @[simp] lemma mod_two_add_succ_mod_two (m : ℕ) : m % 2 + (m + 1) % 2 = 1 := mod_two_add_add_odd_mod_two m odd_one @[simp] lemma succ_mod_two_add_mod_two (m : ℕ) : (m + 1) % 2 + m % 2 = 1 := by rw [add_comm, mod_two_add_succ_mod_two] lemma even_add' : Even (m + n) ↔ (Odd m ↔ Odd n) := by rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not] set_option linter.deprecated false in @[simp] lemma not_even_bit1 (n : ℕ) : ¬Even (2 * n + 1) := by simp [parity_simps] lemma not_even_two_mul_add_one (n : ℕ) : ¬ Even (2 * n + 1) := odd_iff_not_even.1 <| odd_two_mul_add_one n lemma even_sub' (h : n ≤ m) : Even (m - n) ↔ (Odd m ↔ Odd n) := by rw [even_sub h, even_iff_not_odd, even_iff_not_odd, not_iff_not] lemma Odd.sub_odd (hm : Odd m) (hn : Odd n) : Even (m - n) := (le_total n m).elim (fun h ↦ by simp only [even_sub' h, *]) fun h ↦ by simp only [Nat.sub_eq_zero_iff_le.2 h, even_zero] alias _root_.Odd.tsub_odd := Nat.Odd.sub_odd lemma odd_mul : Odd (m * n) ↔ Odd m ∧ Odd n := by simp [not_or, even_mul] lemma Odd.of_mul_left (h : Odd (m * n)) : Odd m := (odd_mul.mp h).1 lemma Odd.of_mul_right (h : Odd (m * n)) : Odd n := (odd_mul.mp h).2 lemma even_div : Even (m / n) ↔ m % (2 * n) / n = 0 := by rw [even_iff_two_dvd, dvd_iff_mod_eq_zero, ← Nat.mod_mul_right_div_self, mul_comm] @[parity_simps] lemma odd_add : Odd (m + n) ↔ (Odd m ↔ Even n) := by rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even] lemma odd_add' : Odd (m + n) ↔ (Odd n ↔ Even m) := by rw [add_comm, odd_add] lemma ne_of_odd_add (h : Odd (m + n)) : m ≠ n := fun hnot ↦ by simp [hnot] at h @[parity_simps] lemma odd_sub (h : n ≤ m) : Odd (m - n) ↔ (Odd m ↔ Even n) := by rw [odd_iff_not_even, even_sub h, not_iff, odd_iff_not_even] lemma Odd.sub_even (h : n ≤ m) (hm : Odd m) (hn : Even n) : Odd (m - n) := (odd_sub h).mpr <| iff_of_true hm hn lemma odd_sub' (h : n ≤ m) : Odd (m - n) ↔ (Odd n ↔ Even m) := by rw [odd_iff_not_even, even_sub h, not_iff, not_iff_comm, odd_iff_not_even] lemma Even.sub_odd (h : n ≤ m) (hm : Even m) (hn : Odd n) : Odd (m - n) := (odd_sub' h).mpr <| iff_of_true hn hm lemma two_mul_div_two_add_one_of_odd (h : Odd n) : 2 * (n / 2) + 1 = n := by rw [← odd_iff.mp h, div_add_mod] lemma div_two_mul_two_add_one_of_odd (h : Odd n) : n / 2 * 2 + 1 = n := by rw [← odd_iff.mp h, div_add_mod'] lemma one_add_div_two_mul_two_of_odd (h : Odd n) : 1 + n / 2 * 2 = n := by rw [← odd_iff.mp h, mod_add_div'] section end -- Here are examples of how `parity_simps` can be used with `Nat`. example (m n : ℕ) (h : Even m) : ¬Even (n + 3) ↔ Even (m ^ 2 + m + n) := by simp [*, two_ne_zero, parity_simps] /- Porting note: the `simp` lemmas about `bit*` no longer apply. -/ example : ¬Even 25394535 := by decide end Nat open Nat namespace Function namespace Involutive variable {α : Type*} {f : α → α} {n : ℕ} set_option linter.deprecated false in section lemma iterate_bit0 (hf : Involutive f) (n : ℕ) : f^[2 * n] = id := by rw [iterate_mul, involutive_iff_iter_2_eq_id.1 hf, iterate_id] lemma iterate_bit1 (hf : Involutive f) (n : ℕ) : f^[2 * n + 1] = f := by rw [← succ_eq_add_one, iterate_succ, hf.iterate_bit0, id_comp] end lemma iterate_two_mul (hf : Involutive f) (n : ℕ) : f^[2 * n] = id := by rw [iterate_mul, involutive_iff_iter_2_eq_id.1 hf, iterate_id] lemma iterate_even (hf : Involutive f) (hn : Even n) : f^[n] = id := by obtain ⟨m, rfl⟩ := hn rw [← two_mul, hf.iterate_two_mul] lemma iterate_odd (hf : Involutive f) (hn : Odd n) : f^[n] = f := by obtain ⟨m, rfl⟩ := hn rw [iterate_add, hf.iterate_two_mul, id_comp, iterate_one] lemma iterate_eq_self (hf : Involutive f) (hne : f ≠ id) : f^[n] = f ↔ Odd n := ⟨fun H ↦ odd_iff_not_even.2 fun hn ↦ hne <| by rwa [hf.iterate_even hn, eq_comm] at H, hf.iterate_odd⟩ lemma iterate_eq_id (hf : Involutive f) (hne : f ≠ id) : f^[n] = id ↔ Even n := ⟨fun H ↦ even_iff_not_odd.2 fun hn ↦ hne <| by rwa [hf.iterate_odd hn] at H, hf.iterate_even⟩ end Involutive end Function lemma neg_one_pow_eq_one_iff_even {R : Type*} [Monoid R] [HasDistribNeg R] {n : ℕ} (h : (-1 : R) ≠ 1) : (-1 : R) ^ n = 1 ↔ Even n where mp h' := of_not_not fun hn ↦ h <| (Odd.neg_one_pow <| odd_iff_not_even.mpr hn).symm.trans h' mpr := Even.neg_one_pow
Algebra\Ring\Pi.lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Patrick Massot -/ import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.GroupWithZero.Pi import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Ring.Hom.Defs /-! # Pi instances for ring This file defines instances for ring, semiring and related structures on Pi Types -/ -- Porting note: used to import `tactic.pi_instances` namespace Pi universe u v w variable {I : Type u} -- The indexing type variable {f : I → Type v} -- The family of types already equipped with instances variable (x y : ∀ i, f i) (i : I) instance distrib [∀ i, Distrib <| f i] : Distrib (∀ i : I, f i) := { add := (· + ·) mul := (· * ·) left_distrib := by intros; ext; exact mul_add _ _ _ right_distrib := by intros; ext; exact add_mul _ _ _} instance hasDistribNeg [∀ i, Mul (f i)] [∀ i, HasDistribNeg (f i)] : HasDistribNeg (∀ i, f i) where neg_mul _ _ := funext fun _ ↦ neg_mul _ _ mul_neg _ _ := funext fun _ ↦ mul_neg _ _ instance addMonoidWithOne [∀ i, AddMonoidWithOne (f i)] : AddMonoidWithOne (∀ i, f i) where natCast n _ := n natCast_zero := funext fun _ ↦ AddMonoidWithOne.natCast_zero natCast_succ n := funext fun _ ↦ AddMonoidWithOne.natCast_succ n instance addGroupWithOne [∀ i, AddGroupWithOne (f i)] : AddGroupWithOne (∀ i, f i) where __ := addGroup __ := addMonoidWithOne intCast n _ := n intCast_ofNat n := funext fun _ ↦ AddGroupWithOne.intCast_ofNat n intCast_negSucc n := funext fun _ ↦ AddGroupWithOne.intCast_negSucc n instance nonUnitalNonAssocSemiring [∀ i, NonUnitalNonAssocSemiring <| f i] : NonUnitalNonAssocSemiring (∀ i : I, f i) := { Pi.distrib, Pi.addCommMonoid, Pi.mulZeroClass with } instance nonUnitalSemiring [∀ i, NonUnitalSemiring <| f i] : NonUnitalSemiring (∀ i : I, f i) := { Pi.nonUnitalNonAssocSemiring, Pi.semigroupWithZero with } instance nonAssocSemiring [∀ i, NonAssocSemiring <| f i] : NonAssocSemiring (∀ i : I, f i) := { Pi.nonUnitalNonAssocSemiring, Pi.mulZeroOneClass, Pi.addMonoidWithOne with } instance semiring [∀ i, Semiring <| f i] : Semiring (∀ i : I, f i) := { Pi.nonUnitalSemiring, Pi.nonAssocSemiring, Pi.monoidWithZero with } instance nonUnitalCommSemiring [∀ i, NonUnitalCommSemiring <| f i] : NonUnitalCommSemiring (∀ i : I, f i) := { Pi.nonUnitalSemiring, Pi.commSemigroup with } instance commSemiring [∀ i, CommSemiring <| f i] : CommSemiring (∀ i : I, f i) := { Pi.semiring, Pi.commMonoid with } instance nonUnitalNonAssocRing [∀ i, NonUnitalNonAssocRing <| f i] : NonUnitalNonAssocRing (∀ i : I, f i) := { Pi.addCommGroup, Pi.nonUnitalNonAssocSemiring with } instance nonUnitalRing [∀ i, NonUnitalRing <| f i] : NonUnitalRing (∀ i : I, f i) := { Pi.nonUnitalNonAssocRing, Pi.nonUnitalSemiring with } instance nonAssocRing [∀ i, NonAssocRing <| f i] : NonAssocRing (∀ i : I, f i) := { Pi.nonUnitalNonAssocRing, Pi.nonAssocSemiring, Pi.addGroupWithOne with } instance ring [∀ i, Ring <| f i] : Ring (∀ i : I, f i) := { Pi.semiring, Pi.addCommGroup, Pi.addGroupWithOne with } instance nonUnitalCommRing [∀ i, NonUnitalCommRing <| f i] : NonUnitalCommRing (∀ i : I, f i) := { Pi.nonUnitalRing, Pi.commSemigroup with } instance commRing [∀ i, CommRing <| f i] : CommRing (∀ i : I, f i) := { Pi.ring, Pi.commSemiring with } /-- A family of non-unital ring homomorphisms `f a : γ →ₙ+* β a` defines a non-unital ring homomorphism `Pi.nonUnitalRingHom f : γ →+* Π a, β a` given by `Pi.nonUnitalRingHom f x b = f b x`. -/ @[simps] protected def nonUnitalRingHom {γ : Type w} [∀ i, NonUnitalNonAssocSemiring (f i)] [NonUnitalNonAssocSemiring γ] (g : ∀ i, γ →ₙ+* f i) : γ →ₙ+* ∀ i, f i := { Pi.mulHom fun i => (g i).toMulHom, Pi.addMonoidHom fun i => (g i).toAddMonoidHom with toFun := fun x b => g b x } theorem nonUnitalRingHom_injective {γ : Type w} [Nonempty I] [∀ i, NonUnitalNonAssocSemiring (f i)] [NonUnitalNonAssocSemiring γ] (g : ∀ i, γ →ₙ+* f i) (hg : ∀ i, Function.Injective (g i)) : Function.Injective (Pi.nonUnitalRingHom g) := mulHom_injective (fun i => (g i).toMulHom) hg /-- A family of ring homomorphisms `f a : γ →+* β a` defines a ring homomorphism `Pi.ringHom f : γ →+* Π a, β a` given by `Pi.ringHom f x b = f b x`. -/ @[simps] protected def ringHom {γ : Type w} [∀ i, NonAssocSemiring (f i)] [NonAssocSemiring γ] (g : ∀ i, γ →+* f i) : γ →+* ∀ i, f i := { Pi.monoidHom fun i => (g i).toMonoidHom, Pi.addMonoidHom fun i => (g i).toAddMonoidHom with toFun := fun x b => g b x } theorem ringHom_injective {γ : Type w} [Nonempty I] [∀ i, NonAssocSemiring (f i)] [NonAssocSemiring γ] (g : ∀ i, γ →+* f i) (hg : ∀ i, Function.Injective (g i)) : Function.Injective (Pi.ringHom g) := monoidHom_injective (fun i => (g i).toMonoidHom) hg end Pi section NonUnitalRingHom universe u v variable {I : Type u} /-- Evaluation of functions into an indexed collection of non-unital rings at a point is a non-unital ring homomorphism. This is `Function.eval` as a `NonUnitalRingHom`. -/ @[simps!] def Pi.evalNonUnitalRingHom (f : I → Type v) [∀ i, NonUnitalNonAssocSemiring (f i)] (i : I) : (∀ i, f i) →ₙ+* f i := { Pi.evalMulHom f i, Pi.evalAddMonoidHom f i with } /-- `Function.const` as a `NonUnitalRingHom`. -/ @[simps] def Pi.constNonUnitalRingHom (α β : Type*) [NonUnitalNonAssocSemiring β] : β →ₙ+* α → β := { Pi.nonUnitalRingHom fun _ => NonUnitalRingHom.id β with toFun := Function.const _ } /-- Non-unital ring homomorphism between the function spaces `I → α` and `I → β`, induced by a non-unital ring homomorphism `f` between `α` and `β`. -/ @[simps] protected def NonUnitalRingHom.compLeft {α β : Type*} [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] (f : α →ₙ+* β) (I : Type*) : (I → α) →ₙ+* I → β := { f.toMulHom.compLeft I, f.toAddMonoidHom.compLeft I with toFun := fun h => f ∘ h } end NonUnitalRingHom section RingHom universe u v variable {I : Type u} /-- Evaluation of functions into an indexed collection of rings at a point is a ring homomorphism. This is `Function.eval` as a `RingHom`. -/ @[simps!] def Pi.evalRingHom (f : I → Type v) [∀ i, NonAssocSemiring (f i)] (i : I) : (∀ i, f i) →+* f i := { Pi.evalMonoidHom f i, Pi.evalAddMonoidHom f i with } instance (f : I → Type*) [∀ i, Semiring (f i)] (i) : RingHomSurjective (Pi.evalRingHom f i) where is_surjective x := ⟨by classical exact (if h : · = i then h ▸ x else 0), by simp⟩ /-- `Function.const` as a `RingHom`. -/ @[simps] def Pi.constRingHom (α β : Type*) [NonAssocSemiring β] : β →+* α → β := { Pi.ringHom fun _ => RingHom.id β with toFun := Function.const _ } /-- Ring homomorphism between the function spaces `I → α` and `I → β`, induced by a ring homomorphism `f` between `α` and `β`. -/ @[simps] protected def RingHom.compLeft {α β : Type*} [NonAssocSemiring α] [NonAssocSemiring β] (f : α →+* β) (I : Type*) : (I → α) →+* I → β := { f.toMonoidHom.compLeft I, f.toAddMonoidHom.compLeft I with toFun := fun h => f ∘ h } end RingHom
Algebra\Ring\Prod.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Chris Hughes, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Data.Int.Cast.Prod import Mathlib.Algebra.GroupWithZero.Prod import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Ring.Equiv /-! # Semiring, ring etc structures on `R × S` In this file we define two-binop (`Semiring`, `Ring` etc) structures on `R × S`. We also prove trivial `simp` lemmas, and define the following operations on `RingHom`s and similarly for `NonUnitalRingHom`s: * `fst R S : R × S →+* R`, `snd R S : R × S →+* S`: projections `Prod.fst` and `Prod.snd` as `RingHom`s; * `f.prod g : R →+* S × T`: sends `x` to `(f x, g x)`; * `f.prod_map g : R × S → R' × S'`: `Prod.map f g` as a `RingHom`, sends `(x, y)` to `(f x, g y)`. -/ variable {α β R R' S S' T T' : Type*} namespace Prod /-- Product of two distributive types is distributive. -/ instance instDistrib [Distrib R] [Distrib S] : Distrib (R × S) := { left_distrib := fun _ _ _ => mk.inj_iff.mpr ⟨left_distrib _ _ _, left_distrib _ _ _⟩ right_distrib := fun _ _ _ => mk.inj_iff.mpr ⟨right_distrib _ _ _, right_distrib _ _ _⟩ } /-- Product of two `NonUnitalNonAssocSemiring`s is a `NonUnitalNonAssocSemiring`. -/ instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] : NonUnitalNonAssocSemiring (R × S) := { inferInstanceAs (AddCommMonoid (R × S)), inferInstanceAs (Distrib (R × S)), inferInstanceAs (MulZeroClass (R × S)) with } /-- Product of two `NonUnitalSemiring`s is a `NonUnitalSemiring`. -/ instance instNonUnitalSemiring [NonUnitalSemiring R] [NonUnitalSemiring S] : NonUnitalSemiring (R × S) := { inferInstanceAs (NonUnitalNonAssocSemiring (R × S)), inferInstanceAs (SemigroupWithZero (R × S)) with } /-- Product of two `NonAssocSemiring`s is a `NonAssocSemiring`. -/ instance instNonAssocSemiring [NonAssocSemiring R] [NonAssocSemiring S] : NonAssocSemiring (R × S) := { inferInstanceAs (NonUnitalNonAssocSemiring (R × S)), inferInstanceAs (MulZeroOneClass (R × S)), inferInstanceAs (AddMonoidWithOne (R × S)) with } /-- Product of two semirings is a semiring. -/ instance instSemiring [Semiring R] [Semiring S] : Semiring (R × S) := { inferInstanceAs (NonUnitalSemiring (R × S)), inferInstanceAs (NonAssocSemiring (R × S)), inferInstanceAs (MonoidWithZero (R × S)) with } /-- Product of two `NonUnitalCommSemiring`s is a `NonUnitalCommSemiring`. -/ instance instNonUnitalCommSemiring [NonUnitalCommSemiring R] [NonUnitalCommSemiring S] : NonUnitalCommSemiring (R × S) := { inferInstanceAs (NonUnitalSemiring (R × S)), inferInstanceAs (CommSemigroup (R × S)) with } /-- Product of two commutative semirings is a commutative semiring. -/ instance instCommSemiring [CommSemiring R] [CommSemiring S] : CommSemiring (R × S) := { inferInstanceAs (Semiring (R × S)), inferInstanceAs (CommMonoid (R × S)) with } instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] : NonUnitalNonAssocRing (R × S) := { inferInstanceAs (AddCommGroup (R × S)), inferInstanceAs (NonUnitalNonAssocSemiring (R × S)) with } instance instNonUnitalRing [NonUnitalRing R] [NonUnitalRing S] : NonUnitalRing (R × S) := { inferInstanceAs (NonUnitalNonAssocRing (R × S)), inferInstanceAs (NonUnitalSemiring (R × S)) with } instance instNonAssocRing [NonAssocRing R] [NonAssocRing S] : NonAssocRing (R × S) := { inferInstanceAs (NonUnitalNonAssocRing (R × S)), inferInstanceAs (NonAssocSemiring (R × S)), inferInstanceAs (AddGroupWithOne (R × S)) with } /-- Product of two rings is a ring. -/ instance instRing [Ring R] [Ring S] : Ring (R × S) := { inferInstanceAs (Semiring (R × S)), inferInstanceAs (AddCommGroup (R × S)), inferInstanceAs (AddGroupWithOne (R × S)) with } /-- Product of two `NonUnitalCommRing`s is a `NonUnitalCommRing`. -/ instance instNonUnitalCommRing [NonUnitalCommRing R] [NonUnitalCommRing S] : NonUnitalCommRing (R × S) := { inferInstanceAs (NonUnitalRing (R × S)), inferInstanceAs (CommSemigroup (R × S)) with } /-- Product of two commutative rings is a commutative ring. -/ instance instCommRing [CommRing R] [CommRing S] : CommRing (R × S) := { inferInstanceAs (Ring (R × S)), inferInstanceAs (CommMonoid (R × S)) with } end Prod namespace NonUnitalRingHom variable (R S) [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] /-- Given non-unital semirings `R`, `S`, the natural projection homomorphism from `R × S` to `R`. -/ def fst : R × S →ₙ+* R := { MulHom.fst R S, AddMonoidHom.fst R S with toFun := Prod.fst } /-- Given non-unital semirings `R`, `S`, the natural projection homomorphism from `R × S` to `S`. -/ def snd : R × S →ₙ+* S := { MulHom.snd R S, AddMonoidHom.snd R S with toFun := Prod.snd } variable {R S} @[simp] theorem coe_fst : ⇑(fst R S) = Prod.fst := rfl @[simp] theorem coe_snd : ⇑(snd R S) = Prod.snd := rfl section Prod variable [NonUnitalNonAssocSemiring T] (f : R →ₙ+* S) (g : R →ₙ+* T) /-- Combine two non-unital ring homomorphisms `f : R →ₙ+* S`, `g : R →ₙ+* T` into `f.prod g : R →ₙ+* S × T` given by `(f.prod g) x = (f x, g x)` -/ protected def prod (f : R →ₙ+* S) (g : R →ₙ+* T) : R →ₙ+* S × T := { MulHom.prod (f : MulHom R S) (g : MulHom R T), AddMonoidHom.prod (f : R →+ S) (g : R →+ T) with toFun := fun x => (f x, g x) } @[simp] theorem prod_apply (x) : f.prod g x = (f x, g x) := rfl @[simp] theorem fst_comp_prod : (fst S T).comp (f.prod g) = f := ext fun _ => rfl @[simp] theorem snd_comp_prod : (snd S T).comp (f.prod g) = g := ext fun _ => rfl theorem prod_unique (f : R →ₙ+* S × T) : ((fst S T).comp f).prod ((snd S T).comp f) = f := ext fun x => by simp only [prod_apply, coe_fst, coe_snd, comp_apply] end Prod section prodMap variable [NonUnitalNonAssocSemiring R'] [NonUnitalNonAssocSemiring S'] [NonUnitalNonAssocSemiring T] variable (f : R →ₙ+* R') (g : S →ₙ+* S') /-- `Prod.map` as a `NonUnitalRingHom`. -/ def prodMap : R × S →ₙ+* R' × S' := (f.comp (fst R S)).prod (g.comp (snd R S)) theorem prodMap_def : prodMap f g = (f.comp (fst R S)).prod (g.comp (snd R S)) := rfl @[simp] theorem coe_prodMap : ⇑(prodMap f g) = Prod.map f g := rfl theorem prod_comp_prodMap (f : T →ₙ+* R) (g : T →ₙ+* S) (f' : R →ₙ+* R') (g' : S →ₙ+* S') : (f'.prodMap g').comp (f.prod g) = (f'.comp f).prod (g'.comp g) := rfl end prodMap end NonUnitalRingHom namespace RingHom variable (R S) [NonAssocSemiring R] [NonAssocSemiring S] /-- Given semirings `R`, `S`, the natural projection homomorphism from `R × S` to `R`. -/ def fst : R × S →+* R := { MonoidHom.fst R S, AddMonoidHom.fst R S with toFun := Prod.fst } /-- Given semirings `R`, `S`, the natural projection homomorphism from `R × S` to `S`. -/ def snd : R × S →+* S := { MonoidHom.snd R S, AddMonoidHom.snd R S with toFun := Prod.snd } instance (R S) [Semiring R] [Semiring S] : RingHomSurjective (fst R S) := ⟨(⟨⟨·, 0⟩, rfl⟩)⟩ instance (R S) [Semiring R] [Semiring S] : RingHomSurjective (snd R S) := ⟨(⟨⟨0, ·⟩, rfl⟩)⟩ variable {R S} @[simp] theorem coe_fst : ⇑(fst R S) = Prod.fst := rfl @[simp] theorem coe_snd : ⇑(snd R S) = Prod.snd := rfl section Prod variable [NonAssocSemiring T] (f : R →+* S) (g : R →+* T) /-- Combine two ring homomorphisms `f : R →+* S`, `g : R →+* T` into `f.prod g : R →+* S × T` given by `(f.prod g) x = (f x, g x)` -/ protected def prod (f : R →+* S) (g : R →+* T) : R →+* S × T := { MonoidHom.prod (f : R →* S) (g : R →* T), AddMonoidHom.prod (f : R →+ S) (g : R →+ T) with toFun := fun x => (f x, g x) } @[simp] theorem prod_apply (x) : f.prod g x = (f x, g x) := rfl @[simp] theorem fst_comp_prod : (fst S T).comp (f.prod g) = f := ext fun _ => rfl @[simp] theorem snd_comp_prod : (snd S T).comp (f.prod g) = g := ext fun _ => rfl theorem prod_unique (f : R →+* S × T) : ((fst S T).comp f).prod ((snd S T).comp f) = f := ext fun x => by simp only [prod_apply, coe_fst, coe_snd, comp_apply] end Prod section prodMap variable [NonAssocSemiring R'] [NonAssocSemiring S'] [NonAssocSemiring T] variable (f : R →+* R') (g : S →+* S') /-- `Prod.map` as a `RingHom`. -/ def prodMap : R × S →+* R' × S' := (f.comp (fst R S)).prod (g.comp (snd R S)) theorem prodMap_def : prodMap f g = (f.comp (fst R S)).prod (g.comp (snd R S)) := rfl @[simp] theorem coe_prodMap : ⇑(prodMap f g) = Prod.map f g := rfl theorem prod_comp_prodMap (f : T →+* R) (g : T →+* S) (f' : R →+* R') (g' : S →+* S') : (f'.prodMap g').comp (f.prod g) = (f'.comp f).prod (g'.comp g) := rfl end prodMap end RingHom namespace RingEquiv variable [NonAssocSemiring R] [NonAssocSemiring S] [NonAssocSemiring R'] [NonAssocSemiring S'] /-- Swapping components as an equivalence of (semi)rings. -/ def prodComm : R × S ≃+* S × R := { AddEquiv.prodComm, MulEquiv.prodComm with } @[simp] theorem coe_prodComm : ⇑(prodComm : R × S ≃+* S × R) = Prod.swap := rfl @[simp] theorem coe_prodComm_symm : ⇑(prodComm : R × S ≃+* S × R).symm = Prod.swap := rfl @[simp] theorem fst_comp_coe_prodComm : (RingHom.fst S R).comp ↑(prodComm : R × S ≃+* S × R) = RingHom.snd R S := RingHom.ext fun _ => rfl @[simp] theorem snd_comp_coe_prodComm : (RingHom.snd S R).comp ↑(prodComm : R × S ≃+* S × R) = RingHom.fst R S := RingHom.ext fun _ => rfl section variable (R R' S S') /-- Four-way commutativity of `Prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm : (R × R') × S × S' ≃+* (R × S) × R' × S' := { AddEquiv.prodProdProdComm R R' S S', MulEquiv.prodProdProdComm R R' S S' with toFun := fun rrss => ((rrss.1.1, rrss.2.1), (rrss.1.2, rrss.2.2)) invFun := fun rsrs => ((rsrs.1.1, rsrs.2.1), (rsrs.1.2, rsrs.2.2)) } @[simp] theorem prodProdProdComm_symm : (prodProdProdComm R R' S S').symm = prodProdProdComm R S R' S' := rfl @[simp] theorem prodProdProdComm_toAddEquiv : (prodProdProdComm R R' S S' : _ ≃+ _) = AddEquiv.prodProdProdComm R R' S S' := rfl @[simp] theorem prodProdProdComm_toMulEquiv : (prodProdProdComm R R' S S' : _ ≃* _) = MulEquiv.prodProdProdComm R R' S S' := rfl @[simp] theorem prodProdProdComm_toEquiv : (prodProdProdComm R R' S S' : _ ≃ _) = Equiv.prodProdProdComm R R' S S' := rfl end variable (R S) [Subsingleton S] /-- A ring `R` is isomorphic to `R × S` when `S` is the zero ring -/ @[simps] def prodZeroRing : R ≃+* R × S where toFun x := (x, 0) invFun := Prod.fst map_add' := by simp map_mul' := by simp left_inv x := rfl right_inv x := by cases x; simp [eq_iff_true_of_subsingleton] /-- A ring `R` is isomorphic to `S × R` when `S` is the zero ring -/ @[simps] def zeroRingProd : R ≃+* S × R where toFun x := (0, x) invFun := Prod.snd map_add' := by simp map_mul' := by simp left_inv x := rfl right_inv x := by cases x; simp [eq_iff_true_of_subsingleton] end RingEquiv /-- The product of two nontrivial rings is not a domain -/ theorem false_of_nontrivial_of_product_domain (R S : Type*) [Ring R] [Ring S] [IsDomain (R × S)] [Nontrivial R] [Nontrivial S] : False := by have := NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero (show ((0 : R), (1 : S)) * (1, 0) = 0 by simp) rw [Prod.mk_eq_zero, Prod.mk_eq_zero] at this rcases this with (⟨_, h⟩ | ⟨h, _⟩) · exact zero_ne_one h.symm · exact zero_ne_one h.symm
Algebra\Ring\Rat.lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Ring.Int import Mathlib.Data.Rat.Defs /-! # The rational numbers are a commutative ring This file contains the commutative ring instance on the rational numbers. See note [foundational algebra order theory]. -/ assert_not_exists OrderedCommMonoid assert_not_exists Field assert_not_exists PNat assert_not_exists Nat.dvd_mul assert_not_exists IsDomain.toCancelMonoidWithZero namespace Rat /-! ### Instances -/ instance commRing : CommRing ℚ where __ := addCommGroup __ := commMonoid zero_mul := Rat.zero_mul mul_zero := Rat.mul_zero left_distrib := Rat.mul_add right_distrib := Rat.add_mul intCast := fun n => n natCast n := Int.cast n natCast_zero := rfl natCast_succ n := by simp only [intCast_eq_divInt, divInt_add_divInt _ _ Int.one_ne_zero Int.one_ne_zero, ← divInt_one_one, Int.natCast_add, Int.natCast_one, mul_one] instance commGroupWithZero : CommGroupWithZero ℚ := { exists_pair_ne := ⟨0, 1, Rat.zero_ne_one⟩ inv_zero := by change Rat.inv 0 = 0 rw [Rat.inv_def] rfl mul_inv_cancel := Rat.mul_inv_cancel mul_zero := mul_zero zero_mul := zero_mul } instance isDomain : IsDomain ℚ := NoZeroDivisors.to_isDomain _ instance instCharZero : CharZero ℚ where cast_injective a b hab := by simpa using congr_arg num hab /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances being used to construct these instances non-computably. -/ instance commSemiring : CommSemiring ℚ := by infer_instance instance semiring : Semiring ℚ := by infer_instance /-! ### Miscellaneous lemmas -/ lemma mkRat_eq_div (n : ℤ) (d : ℕ) : mkRat n d = n / d := by simp only [mkRat_eq_divInt, divInt_eq_div, Int.cast_natCast] lemma divInt_div_divInt_cancel_left {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x / (d /. x) = n /. d := by rw [div_eq_mul_inv, inv_divInt', divInt_mul_divInt_cancel hx] lemma divInt_div_divInt_cancel_right {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : x /. n / (x /. d) = d /. n := by rw [div_eq_mul_inv, inv_divInt', mul_comm, divInt_mul_divInt_cancel hx] lemma num_div_den (r : ℚ) : (r.num : ℚ) / (r.den : ℚ) = r := by rw [← Int.cast_natCast, ← divInt_eq_div, num_divInt_den] @[simp] lemma divInt_pow (num : ℕ) (den : ℤ) (n : ℕ) : (num /. den) ^ n = num ^ n /. den ^ n := by simp [divInt_eq_div, div_pow, Int.natCast_pow] @[simp] lemma mkRat_pow (num den : ℕ) (n : ℕ) : mkRat num den ^ n = mkRat (num ^ n) (den ^ n) := by rw [mkRat_eq_divInt, mkRat_eq_divInt, divInt_pow, Int.natCast_pow] lemma natCast_eq_divInt (n : ℕ) : ↑n = n /. 1 := by rw [← Int.cast_natCast, intCast_eq_divInt] @[simp] lemma mul_den_eq_num (q : ℚ) : q * q.den = q.num := by suffices (q.num /. ↑q.den) * (↑q.den /. 1) = q.num /. 1 by conv => pattern (occs := 1) q; (rw [← num_divInt_den q]) simp only [intCast_eq_divInt, natCast_eq_divInt, num_divInt_den] at this ⊢; assumption have : (q.den : ℤ) ≠ 0 := mod_cast q.den_ne_zero rw [divInt_mul_divInt _ _ this Int.one_ne_zero, mul_comm (q.den : ℤ) 1, divInt_mul_right this] @[simp] lemma den_mul_eq_num (q : ℚ) : q.den * q = q.num := by rw [mul_comm, mul_den_eq_num] @[deprecated (since := "2024-04-07")] alias coe_nat_eq_divInt := natCast_eq_divInt end Rat
Algebra\Ring\Regular.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Regular.Basic import Mathlib.Algebra.Ring.Defs /-! # Lemmas about regular elements in rings. -/ variable {α : Type*} /-- Left `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor. The typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/ theorem isLeftRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α) (h : ∀ x : α, k * x = 0 → x = 0) : IsLeftRegular k := by refine fun x y (h' : k * x = k * y) => sub_eq_zero.mp (h _ ?_) rw [mul_sub, sub_eq_zero, h'] /-- Right `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor. The typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/ theorem isRightRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α) (h : ∀ x : α, x * k = 0 → x = 0) : IsRightRegular k := by refine fun x y (h' : x * k = y * k) => sub_eq_zero.mp (h _ ?_) rw [sub_mul, sub_eq_zero, h'] theorem isRegular_of_ne_zero' [NonUnitalNonAssocRing α] [NoZeroDivisors α] {k : α} (hk : k ≠ 0) : IsRegular k := ⟨isLeftRegular_of_non_zero_divisor k fun _ h => (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left hk, isRightRegular_of_non_zero_divisor k fun _ h => (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hk⟩ theorem isRegular_iff_ne_zero' [Nontrivial α] [NonUnitalNonAssocRing α] [NoZeroDivisors α] {k : α} : IsRegular k ↔ k ≠ 0 := ⟨fun h => by rintro rfl exact not_not.mpr h.left not_isLeftRegular_zero, isRegular_of_ne_zero'⟩ /-- A ring with no zero divisors is a `CancelMonoidWithZero`. Note this is not an instance as it forms a typeclass loop. -/ abbrev NoZeroDivisors.toCancelMonoidWithZero [Ring α] [NoZeroDivisors α] : CancelMonoidWithZero α := { (by infer_instance : MonoidWithZero α) with mul_left_cancel_of_ne_zero := fun ha => @IsRegular.left _ _ _ (isRegular_of_ne_zero' ha) _ _, mul_right_cancel_of_ne_zero := fun hb => @IsRegular.right _ _ _ (isRegular_of_ne_zero' hb) _ _ } /-- A commutative ring with no zero divisors is a `CancelCommMonoidWithZero`. Note this is not an instance as it forms a typeclass loop. -/ abbrev NoZeroDivisors.toCancelCommMonoidWithZero [CommRing α] [NoZeroDivisors α] : CancelCommMonoidWithZero α := { NoZeroDivisors.toCancelMonoidWithZero, ‹CommRing α› with } section IsDomain -- see Note [lower instance priority] instance (priority := 100) IsDomain.toCancelMonoidWithZero [Semiring α] [IsDomain α] : CancelMonoidWithZero α := { } variable [CommSemiring α] [IsDomain α] -- see Note [lower instance priority] instance (priority := 100) IsDomain.toCancelCommMonoidWithZero : CancelCommMonoidWithZero α := { mul_left_cancel_of_ne_zero := IsLeftCancelMulZero.mul_left_cancel_of_ne_zero } end IsDomain
Algebra\Ring\Semiconj.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Group.Semiconj.Defs import Mathlib.Algebra.Ring.Defs /-! # Semirings and rings This file gives lemmas about semirings, rings and domains. This is analogous to `Mathlib.Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. For the definitions of semirings and rings see `Mathlib.Algebra.Ring.Defs`. -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {R : Type x} open Function namespace SemiconjBy @[simp] theorem add_right [Distrib R] {a x y x' y' : R} (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x + x') (y + y') := by simp only [SemiconjBy, left_distrib, right_distrib, h.eq, h'.eq] @[simp] theorem add_left [Distrib R] {a b x y : R} (ha : SemiconjBy a x y) (hb : SemiconjBy b x y) : SemiconjBy (a + b) x y := by simp only [SemiconjBy, left_distrib, right_distrib, ha.eq, hb.eq] section variable [Mul R] [HasDistribNeg R] {a x y : R} theorem neg_right (h : SemiconjBy a x y) : SemiconjBy a (-x) (-y) := by simp only [SemiconjBy, h.eq, neg_mul, mul_neg] @[simp] theorem neg_right_iff : SemiconjBy a (-x) (-y) ↔ SemiconjBy a x y := ⟨fun h => neg_neg x ▸ neg_neg y ▸ h.neg_right, SemiconjBy.neg_right⟩ theorem neg_left (h : SemiconjBy a x y) : SemiconjBy (-a) x y := by simp only [SemiconjBy, h.eq, neg_mul, mul_neg] @[simp] theorem neg_left_iff : SemiconjBy (-a) x y ↔ SemiconjBy a x y := ⟨fun h => neg_neg a ▸ h.neg_left, SemiconjBy.neg_left⟩ end section variable [MulOneClass R] [HasDistribNeg R] {a x y : R} -- Porting note: `simpNF` told me to remove `simp` attribute theorem neg_one_right (a : R) : SemiconjBy a (-1) (-1) := (one_right a).neg_right -- Porting note: `simpNF` told me to remove `simp` attribute theorem neg_one_left (x : R) : SemiconjBy (-1) x x := (SemiconjBy.one_left x).neg_left end section variable [NonUnitalNonAssocRing R] {a b x y x' y' : R} @[simp] theorem sub_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x - x') (y - y') := by simpa only [sub_eq_add_neg] using h.add_right h'.neg_right @[simp] theorem sub_left (ha : SemiconjBy a x y) (hb : SemiconjBy b x y) : SemiconjBy (a - b) x y := by simpa only [sub_eq_add_neg] using ha.add_left hb.neg_left end end SemiconjBy
Algebra\Ring\SumsOfSquares.lean
/- Copyright (c) 2024 Florent Schaffhauser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Florent Schaffhauser -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Group.Even import Mathlib.Algebra.Order.Ring.Defs /-! # Sums of squares We introduce sums of squares in a type `R` endowed with an `[Add R]`, `[Zero R]` and `[Mul R]` instances. Sums of squares in `R` are defined by an inductive predicate `isSumSq : R → Prop`: `0 : R` is a sum of squares and if `S` is a sum of squares, then for all `a : R`, `a * a + S` is a sum of squares in `R`. ## Main declaration - The predicate `isSumSq : R → Prop`, defining the property of being a sum of squares in `R`. ## Auxiliary declarations - The type `SumSqIn R` : in an additive monoid with multiplication `R`, we introduce the type `SumSqIn R` as the submonoid of `R` whose carrier is the subset `{S : R | isSumSq S}`. ## Theorems - `isSumSq.add`: if `S1` and `S2` are sums of squares in `R`, then so is `S1 + S2`. - `SumSq.nonneg`: in a linearly ordered semiring `R` with an `[ExistsAddOfLE R]` instance, sums of squares are non-negative. - `SquaresInSumSq`: a square is a sum of squares. - `SquaresAddClosure`: the submonoid of `R` generated by the squares in `R` is the set of sums of squares in `R`. -/ variable {R : Type*} [Mul R] /-- In a type `R` with an addition, a zero element and a multiplication, the property of being a sum of squares is defined by an inductive predicate: `0 : R` is a sum of squares and if `S` is a sum of squares, then for all `a : R`, `a * a + S` is a sum of squares in `R`. -/ @[mk_iff] inductive isSumSq [Add R] [Zero R] : R → Prop | zero : isSumSq 0 | sq_add (a S : R) (pS : isSumSq S) : isSumSq (a * a + S) /-- If `S1` and `S2` are sums of squares in a semiring `R`, then `S1 + S2` is a sum of squares in `R`. -/ theorem isSumSq.add [AddMonoid R] {S1 S2 : R} (p1 : isSumSq S1) (p2 : isSumSq S2) : isSumSq (S1 + S2) := by induction p1 with | zero => rw [zero_add]; exact p2 | sq_add a S pS ih => rw [add_assoc]; exact isSumSq.sq_add a (S + S2) ih variable (R) in /-- In an additive monoid with multiplication `R`, the type `SumSqIn R` is the submonoid of sums of squares in `R`. -/ def SumSqIn [AddMonoid R] : AddSubmonoid R where carrier := {S : R | isSumSq S} zero_mem' := isSumSq.zero add_mem' := isSumSq.add /-- In an additive monoid with multiplication, every square is a sum of squares. By definition, a square in `R` is a term `x : R` such that `x = y * y` for some `y : R` and in Mathlib this is known as `IsSquare R` (see Mathlib.Algebra.Group.Even). -/ theorem SquaresInSumSq [AddMonoid R] {x : R} (px : IsSquare x) : x ∈ SumSqIn R := by rcases px with ⟨y, py⟩ rw [py, ← AddMonoid.add_zero (y * y)] exact isSumSq.sq_add _ _ isSumSq.zero open AddSubmonoid in /-- In an additive monoid with multiplication `R`, the submonoid generated by the squares is the set of sums of squares. -/ theorem SquaresAddClosure [AddMonoid R] : closure IsSquare = SumSqIn R := by refine le_antisymm (closure_le.2 (fun x hx ↦ SquaresInSumSq hx)) (fun x hx ↦ ?_) induction hx with | zero => exact zero_mem _ | sq_add a S _ ih => exact AddSubmonoid.add_mem _ (subset_closure ⟨a, rfl⟩) ih /-- Let `R` be a linearly ordered semiring in which the property `a ≤ b → ∃ c, a + c = b` holds (e.g. `R = ℕ`). If `S : R` is a sum of squares in `R`, then `0 ≤ S`. This is used in `Mathlib.Algebra.Ring.Semireal.Defs` to show that linearly ordered fields are semireal. -/ theorem isSumSq.nonneg {R : Type*} [LinearOrderedSemiring R] [ExistsAddOfLE R] {S : R} (pS : isSumSq S) : 0 ≤ S := by induction pS with | zero => simp only [le_refl] | sq_add x S _ ih => apply add_nonneg ?_ ih; simp only [← pow_two x, sq_nonneg]
Algebra\Ring\ULift.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.ULift import Mathlib.Algebra.Ring.Equiv /-! # `ULift` instances for ring This file defines instances for ring, semiring and related structures on `ULift` types. (Recall `ULift α` is just a "copy" of a type `α` in a higher universe.) We also provide `ULift.ringEquiv : ULift R ≃+* R`. -/ universe u v variable {α : Type u} namespace ULift instance mulZeroClass [MulZeroClass α] : MulZeroClass (ULift α) := { zero := (0 : ULift α), mul := (· * ·), zero_mul := fun _ => (Equiv.ulift).injective (by simp), mul_zero := fun _ => (Equiv.ulift).injective (by simp) } instance distrib [Distrib α] : Distrib (ULift α) := { add := (· + ·), mul := (· * ·), left_distrib := fun _ _ _ => (Equiv.ulift).injective (by simp [left_distrib]), right_distrib := fun _ _ _ => (Equiv.ulift).injective (by simp [right_distrib]) } instance nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring α] : NonUnitalNonAssocSemiring (ULift α) := { zero := (0 : ULift α), add := (· + ·), mul := (· * ·), nsmul := AddMonoid.nsmul, zero_add, add_zero, zero_mul, mul_zero, left_distrib, right_distrib, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, add_assoc, add_comm } instance nonAssocSemiring [NonAssocSemiring α] : NonAssocSemiring (ULift α) := { ULift.addMonoidWithOne with nsmul := AddMonoid.nsmul, natCast := fun n => ULift.up n, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, one_mul, mul_one } instance nonUnitalSemiring [NonUnitalSemiring α] : NonUnitalSemiring (ULift α) := { zero := (0 : ULift α), add := (· + ·), mul := (· * ·), nsmul := AddMonoid.nsmul, add_assoc, zero_add, add_zero, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _ } instance semiring [Semiring α] : Semiring (ULift α) := { ULift.addMonoidWithOne with nsmul := AddMonoid.nsmul, npow := Monoid.npow, natCast := fun n => ULift.up n, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, one_mul, mul_one, npow_zero := fun _ => Monoid.npow_zero _, npow_succ := fun _ _ => Monoid.npow_succ _ _ } /-- The ring equivalence between `ULift α` and `α`. -/ def ringEquiv [NonUnitalNonAssocSemiring α] : ULift α ≃+* α where toFun := ULift.down invFun := ULift.up map_mul' _ _ := rfl map_add' _ _ := rfl left_inv := fun _ => rfl right_inv := fun _ => rfl instance nonUnitalCommSemiring [NonUnitalCommSemiring α] : NonUnitalCommSemiring (ULift α) := { zero := (0 : ULift α), add := (· + ·), mul := (· * ·), nsmul := AddMonoid.nsmul, add_assoc, zero_add, add_zero, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, mul_comm, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _ } instance commSemiring [CommSemiring α] : CommSemiring (ULift α) := { ULift.semiring with nsmul := AddMonoid.nsmul, natCast := fun n => ULift.up n, npow := Monoid.npow, mul_comm } instance nonUnitalNonAssocRing [NonUnitalNonAssocRing α] : NonUnitalNonAssocRing (ULift α) := { zero := (0 : ULift α), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, zsmul := SubNegMonoid.zsmul, add_assoc, zero_add, add_zero, add_left_neg, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, sub_eq_add_neg, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg' } instance nonUnitalRing [NonUnitalRing α] : NonUnitalRing (ULift α) := { zero := (0 : ULift α), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, zsmul := SubNegMonoid.zsmul, add_assoc, zero_add, add_zero, add_comm, add_left_neg, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, sub_eq_add_neg nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg' } instance nonAssocRing [NonAssocRing α] : NonAssocRing (ULift α) := { zero := (0 : ULift α), one := (1 : ULift α), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, natCast := fun n => ULift.up n, intCast := fun n => ULift.up n, zsmul := SubNegMonoid.zsmul, intCast_ofNat := addGroupWithOne.intCast_ofNat, add_assoc, zero_add, add_zero, add_left_neg, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, one_mul, mul_one, sub_eq_add_neg, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg', natCast_zero := AddMonoidWithOne.natCast_zero, natCast_succ := AddMonoidWithOne.natCast_succ, intCast_negSucc := AddGroupWithOne.intCast_negSucc } instance ring [Ring α] : Ring (ULift α) := { zero := (0 : ULift α), one := (1 : ULift α), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, npow := Monoid.npow, zsmul := SubNegMonoid.zsmul, intCast_ofNat := addGroupWithOne.intCast_ofNat, add_assoc, zero_add, add_zero, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, one_mul, mul_one, sub_eq_add_neg, add_left_neg, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, natCast := fun n => ULift.up n, intCast := fun n => ULift.up n, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, natCast_zero := AddMonoidWithOne.natCast_zero, natCast_succ := AddMonoidWithOne.natCast_succ, npow_zero := fun _ => Monoid.npow_zero _, npow_succ := fun _ _ => Monoid.npow_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg', intCast_negSucc := AddGroupWithOne.intCast_negSucc } instance nonUnitalCommRing [NonUnitalCommRing α] : NonUnitalCommRing (ULift α) := { zero := (0 : ULift α), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, zsmul := SubNegMonoid.zsmul, zero_mul, add_assoc, zero_add, add_zero, mul_zero, left_distrib, right_distrib, add_comm, mul_assoc, mul_comm, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, add_left_neg, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, sub_eq_add_neg, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg'.. } instance commRing [CommRing α] : CommRing (ULift α) := { ULift.ring with mul_comm } end ULift
Algebra\Ring\Units.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Ring.InjSurj import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Ring.Hom.Defs /-! # Units in semirings and rings -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {R : Type x} open Function namespace Units section HasDistribNeg variable [Monoid α] [HasDistribNeg α] {a b : α} /-- Each element of the group of units of a ring has an additive inverse. -/ instance : Neg αˣ := ⟨fun u => ⟨-↑u, -↑u⁻¹, by simp, by simp⟩⟩ /-- Representing an element of a ring's unit group as an element of the ring commutes with mapping this element to its additive inverse. -/ @[simp, norm_cast] protected theorem val_neg (u : αˣ) : (↑(-u) : α) = -u := rfl @[simp, norm_cast] protected theorem coe_neg_one : ((-1 : αˣ) : α) = -1 := rfl instance : HasDistribNeg αˣ := Units.ext.hasDistribNeg _ Units.val_neg Units.val_mul @[field_simps] theorem neg_divp (a : α) (u : αˣ) : -(a /ₚ u) = -a /ₚ u := by simp only [divp, neg_mul] end HasDistribNeg section Ring variable [Ring α] {a b : α} -- Needs to have higher simp priority than divp_add_divp. 1000 is the default priority. @[field_simps 1010] theorem divp_add_divp_same (a b : α) (u : αˣ) : a /ₚ u + b /ₚ u = (a + b) /ₚ u := by simp only [divp, add_mul] -- Needs to have higher simp priority than divp_sub_divp. 1000 is the default priority. @[field_simps 1010] theorem divp_sub_divp_same (a b : α) (u : αˣ) : a /ₚ u - b /ₚ u = (a - b) /ₚ u := by rw [sub_eq_add_neg, sub_eq_add_neg, neg_divp, divp_add_divp_same] @[field_simps] theorem add_divp (a b : α) (u : αˣ) : a + b /ₚ u = (a * u + b) /ₚ u := by simp only [divp, add_mul, Units.mul_inv_cancel_right] @[field_simps] theorem sub_divp (a b : α) (u : αˣ) : a - b /ₚ u = (a * u - b) /ₚ u := by simp only [divp, sub_mul, Units.mul_inv_cancel_right] @[field_simps] theorem divp_add (a b : α) (u : αˣ) : a /ₚ u + b = (a + b * u) /ₚ u := by simp only [divp, add_mul, Units.mul_inv_cancel_right] @[field_simps] theorem divp_sub (a b : α) (u : αˣ) : a /ₚ u - b = (a - b * u) /ₚ u := by simp only [divp, sub_mul, sub_right_inj] rw [mul_assoc, Units.mul_inv, mul_one] @[simp] protected theorem map_neg {F : Type*} [Ring β] [FunLike F α β] [RingHomClass F α β] (f : F) (u : αˣ) : map (f : α →* β) (-u) = -map (f : α →* β) u := ext (by simp only [coe_map, Units.val_neg, MonoidHom.coe_coe, map_neg]) protected theorem map_neg_one {F : Type*} [Ring β] [FunLike F α β] [RingHomClass F α β] (f : F) : map (f : α →* β) (-1) = -1 := by simp only [Units.map_neg, map_one] end Ring end Units theorem IsUnit.neg [Monoid α] [HasDistribNeg α] {a : α} : IsUnit a → IsUnit (-a) | ⟨x, hx⟩ => hx ▸ (-x).isUnit @[simp] theorem IsUnit.neg_iff [Monoid α] [HasDistribNeg α] (a : α) : IsUnit (-a) ↔ IsUnit a := ⟨fun h => neg_neg a ▸ h.neg, IsUnit.neg⟩ theorem isUnit_neg_one [Monoid α] [HasDistribNeg α] : IsUnit (-1 : α) := isUnit_one.neg theorem IsUnit.sub_iff [Ring α] {x y : α} : IsUnit (x - y) ↔ IsUnit (y - x) := (IsUnit.neg_iff _).symm.trans <| neg_sub x y ▸ Iff.rfl namespace Units @[field_simps] theorem divp_add_divp [CommRing α] (a b : α) (u₁ u₂ : αˣ) : a /ₚ u₁ + b /ₚ u₂ = (a * u₂ + u₁ * b) /ₚ (u₁ * u₂) := by simp only [divp, add_mul, mul_inv_rev, val_mul] rw [mul_comm (↑u₁ * b), mul_comm b] rw [← mul_assoc, ← mul_assoc, mul_assoc a, mul_assoc (↑u₂⁻¹ : α), mul_inv, inv_mul, mul_one, mul_one] -- Porting note: `assoc_rw` not ported: `assoc_rw [mul_inv, mul_inv, mul_one, mul_one]` @[field_simps] theorem divp_sub_divp [CommRing α] (a b : α) (u₁ u₂ : αˣ) : a /ₚ u₁ - b /ₚ u₂ = (a * u₂ - u₁ * b) /ₚ (u₁ * u₂) := by simp only [sub_eq_add_neg, neg_divp, divp_add_divp, mul_neg] theorem add_eq_mul_one_add_div [Semiring R] {a : Rˣ} {b : R} : ↑a + b = a * (1 + ↑a⁻¹ * b) := by rw [mul_add, mul_one, ← mul_assoc, Units.mul_inv, one_mul] end Units
Algebra\Ring\WithZero.lean
/- Copyright (c) 2020 Mario Carneiro, Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johan Commelin -/ import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.Algebra.Ring.Defs /-! # Adjoining a zero to a semiring -/ namespace WithZero variable {α : Type*} instance instLeftDistribClass [Mul α] [Add α] [LeftDistribClass α] : LeftDistribClass (WithZero α) where left_distrib a b c := by cases' a with a; · rfl cases' b with b <;> cases' c with c <;> try rfl exact congr_arg some (left_distrib _ _ _) instance instRightDistribClass [Mul α] [Add α] [RightDistribClass α] : RightDistribClass (WithZero α) where right_distrib a b c := by cases' c with c · change (a + b) * 0 = a * 0 + b * 0 simp cases' a with a <;> cases' b with b <;> try rfl exact congr_arg some (right_distrib _ _ _) instance instDistrib [Distrib α] : Distrib (WithZero α) where left_distrib := left_distrib right_distrib := right_distrib instance instSemiring [Semiring α] : Semiring (WithZero α) := { addMonoidWithOne, addCommMonoid, mulZeroClass, monoidWithZero, instDistrib with } end WithZero
Algebra\Ring\Action\Basic.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.Ring.Hom.Defs /-! # Group action on rings This file defines the typeclass of monoid acting on semirings `MulSemiringAction M R`, and the corresponding typeclass of invariant subrings. Note that `Algebra` does not satisfy the axioms of `MulSemiringAction`. ## Implementation notes There is no separate typeclass for group acting on rings, group acting on fields, etc. They are all grouped under `MulSemiringAction`. ## Tags group action, invariant subring -/ assert_not_exists Equiv.Perm.equivUnitsEnd assert_not_exists Prod.fst_mul universe u v /-- Typeclass for multiplicative actions by monoids on semirings. This combines `DistribMulAction` with `MulDistribMulAction`. -/ class MulSemiringAction (M : Type u) (R : Type v) [Monoid M] [Semiring R] extends DistribMulAction M R where /-- Multipliying `1` by a scalar gives `1` -/ smul_one : ∀ g : M, (g • (1 : R) : R) = 1 /-- Scalar multiplication distributes across multiplication -/ smul_mul : ∀ (g : M) (x y : R), g • (x * y) = g • x * g • y section Semiring variable (M N G : Type*) [Monoid M] [Monoid N] [Group G] variable (A R S F : Type v) [AddMonoid A] [Semiring R] [CommSemiring S] -- note we could not use `extends` since these typeclasses are made with `old_structure_cmd` instance (priority := 100) MulSemiringAction.toMulDistribMulAction [h : MulSemiringAction M R] : MulDistribMulAction M R := { h with } /-- Each element of the monoid defines a semiring homomorphism. -/ @[simps!] def MulSemiringAction.toRingHom [MulSemiringAction M R] (x : M) : R →+* R := { MulDistribMulAction.toMonoidHom R x, DistribMulAction.toAddMonoidHom R x with } theorem toRingHom_injective [MulSemiringAction M R] [FaithfulSMul M R] : Function.Injective (MulSemiringAction.toRingHom M R) := fun _ _ h => eq_of_smul_eq_smul fun r => RingHom.ext_iff.1 h r /-- The tautological action by `R →+* R` on `R`. This generalizes `Function.End.applyMulAction`. -/ instance RingHom.applyMulSemiringAction : MulSemiringAction (R →+* R) R where smul := (· <| ·) smul_one := map_one smul_mul := map_mul smul_zero := RingHom.map_zero smul_add := RingHom.map_add one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] protected theorem RingHom.smul_def (f : R →+* R) (a : R) : f • a = f a := rfl /-- `RingHom.applyMulSemiringAction` is faithful. -/ instance RingHom.applyFaithfulSMul : FaithfulSMul (R →+* R) R := ⟨fun {_ _} h => RingHom.ext h⟩ section variable {M N} /-- Compose a `MulSemiringAction` with a `MonoidHom`, with action `f r' • m`. See note [reducible non-instances]. -/ abbrev MulSemiringAction.compHom (f : N →* M) [MulSemiringAction M R] : MulSemiringAction N R := { DistribMulAction.compHom R f, MulDistribMulAction.compHom R f with } end section SimpLemmas variable {M G A R F} attribute [simp] smul_one smul_mul' smul_zero smul_add end SimpLemmas end Semiring
Algebra\Ring\Action\Field.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Ring.Action.Basic import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.GroupWithZero.Units.Lemmas /-! # Group action on fields -/ variable {M} [Monoid M] {F} [DivisionRing F] /-- Note that `smul_inv'` refers to the group case, and `smul_inv` has an additional inverse on `x`. -/ @[simp] theorem smul_inv'' [MulSemiringAction M F] (x : M) (m : F) : x • m⁻¹ = (x • m)⁻¹ := map_inv₀ (MulSemiringAction.toRingHom M F x) _
Algebra\Ring\Action\Group.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Ring.Action.Basic import Mathlib.GroupTheory.GroupAction.Group import Mathlib.Algebra.Ring.Equiv /-! # If a group acts multiplicatively on a semiring, each group element acts by a ring automorphism. This result is split out from `Mathlib.Algebra.Ring.Action.Basic` to avoid needing the import of `Mathlib.GroupTheory.GroupAction.Group`. -/ section Semiring variable (G : Type*) [Group G] variable (R : Type*) [Semiring R] /-- Each element of the group defines a semiring isomorphism. -/ @[simps!] def MulSemiringAction.toRingEquiv [MulSemiringAction G R] (x : G) : R ≃+* R := { DistribMulAction.toAddEquiv R x, MulSemiringAction.toRingHom G R x with } end Semiring
Algebra\Ring\Action\Invariant.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.GroupTheory.GroupAction.Hom import Mathlib.Algebra.Ring.Subring.Basic /-! # Subrings invariant under an action -/ section Ring variable (M R : Type*) [Monoid M] [Ring R] [MulSemiringAction M R] variable (S : Subring R) open MulAction variable {R} /-- A typeclass for subrings invariant under a `MulSemiringAction`. -/ class IsInvariantSubring : Prop where smul_mem : ∀ (m : M) {x : R}, x ∈ S → m • x ∈ S instance IsInvariantSubring.toMulSemiringAction [IsInvariantSubring M S] : MulSemiringAction M S where smul m x := ⟨m • ↑x, IsInvariantSubring.smul_mem m x.2⟩ one_smul s := Subtype.eq <| one_smul M (s : R) mul_smul m₁ m₂ s := Subtype.eq <| mul_smul m₁ m₂ (s : R) smul_add m s₁ s₂ := Subtype.eq <| smul_add m (s₁ : R) (s₂ : R) smul_zero m := Subtype.eq <| smul_zero m smul_one m := Subtype.eq <| smul_one m smul_mul m s₁ s₂ := Subtype.eq <| smul_mul' m (s₁ : R) (s₂ : R) end Ring section variable (M : Type*) [Monoid M] variable {R' : Type*} [Ring R'] [MulSemiringAction M R'] variable (U : Subring R') [IsInvariantSubring M U] /-- The canonical inclusion from an invariant subring. -/ def IsInvariantSubring.subtypeHom : U →+*[M] R' := { U.subtype with map_smul' := fun _ _ ↦ rfl } -- Porting note: changed `coe` to `Subtype.val` @[simp] theorem IsInvariantSubring.coe_subtypeHom : (IsInvariantSubring.subtypeHom M U : U → R') = Subtype.val := rfl -- Porting note: added `toRingHom` @[simp] theorem IsInvariantSubring.coe_subtypeHom' : ((IsInvariantSubring.subtypeHom M U).toRingHom : U →+* R') = U.subtype := rfl end
Algebra\Ring\Action\Subobjects.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Group.Submonoid.DistribMulAction import Mathlib.Algebra.Ring.Action.Basic /-! # Instances of `MulSemiringAction` for subobjects These are defined in this file as `Semiring`s are not available yet where `Submonoid` and `Subgroup` are defined. Instances for `Subsemiring` and `Subring` are provided next to the other scalar actions instances for those subobjects. -/ variable {M G R : Type*} variable [Monoid M] [Group G] [Semiring R] /-- A stronger version of `Submonoid.distribMulAction`. -/ instance Submonoid.mulSemiringAction [MulSemiringAction M R] (H : Submonoid M) : MulSemiringAction H R := { inferInstanceAs (DistribMulAction H R), inferInstanceAs (MulDistribMulAction H R) with } /-- A stronger version of `Subgroup.distribMulAction`. -/ instance Subgroup.mulSemiringAction [MulSemiringAction G R] (H : Subgroup G) : MulSemiringAction H R := H.toSubmonoid.mulSemiringAction
Algebra\Ring\Divisibility\Basic.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Ring.Defs /-! # Lemmas about divisibility in rings Note that this file is imported by basic tactics like `linarith` and so must have only minimal imports. Further results about divisibility in rings may be found in `Mathlib.Algebra.Ring.Divisibility.Lemmas` which is not subject to this import constraint. -/ variable {α β : Type*} section Semigroup variable [Semigroup α] [Semigroup β] {F : Type*} [EquivLike F α β] [MulEquivClass F α β] (f : F) theorem map_dvd_iff {a b} : f a ∣ f b ↔ a ∣ b := let f := MulEquivClass.toMulEquiv f ⟨fun h ↦ by rw [← f.left_inv a, ← f.left_inv b]; exact map_dvd f.symm h, map_dvd f⟩ theorem MulEquiv.decompositionMonoid [DecompositionMonoid β] : DecompositionMonoid α where primal a b c h := by rw [← map_dvd_iff f, map_mul] at h obtain ⟨a₁, a₂, h⟩ := DecompositionMonoid.primal _ h refine ⟨symm f a₁, symm f a₂, ?_⟩ simp_rw [← map_dvd_iff f, ← map_mul, eq_symm_apply] iterate 2 erw [(f : α ≃* β).apply_symm_apply] exact h end Semigroup section DistribSemigroup variable [Add α] [Semigroup α] theorem dvd_add [LeftDistribClass α] {a b c : α} (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b + c := Dvd.elim h₁ fun d hd => Dvd.elim h₂ fun e he => Dvd.intro (d + e) (by simp [left_distrib, hd, he]) alias Dvd.dvd.add := dvd_add end DistribSemigroup section Semiring variable [Semiring α] {a b c : α} {m n : ℕ} lemma min_pow_dvd_add (ha : c ^ m ∣ a) (hb : c ^ n ∣ b) : c ^ min m n ∣ a + b := ((pow_dvd_pow c (m.min_le_left n)).trans ha).add ((pow_dvd_pow c (m.min_le_right n)).trans hb) end Semiring section NonUnitalCommSemiring variable [NonUnitalCommSemiring α] [NonUnitalCommSemiring β] {a b c : α} theorem Dvd.dvd.linear_comb {d x y : α} (hdx : d ∣ x) (hdy : d ∣ y) (a b : α) : d ∣ a * x + b * y := dvd_add (hdx.mul_left a) (hdy.mul_left b) end NonUnitalCommSemiring section Semigroup variable [Semigroup α] [HasDistribNeg α] {a b c : α} /-- An element `a` of a semigroup with a distributive negation divides the negation of an element `b` iff `a` divides `b`. -/ @[simp] theorem dvd_neg : a ∣ -b ↔ a ∣ b := (Equiv.neg _).exists_congr_left.trans <| by simp only [Equiv.neg_symm, Equiv.neg_apply, mul_neg, neg_inj, Dvd.dvd] /-- The negation of an element `a` of a semigroup with a distributive negation divides another element `b` iff `a` divides `b`. -/ @[simp] theorem neg_dvd : -a ∣ b ↔ a ∣ b := (Equiv.neg _).exists_congr_left.trans <| by simp only [Equiv.neg_symm, Equiv.neg_apply, mul_neg, neg_mul, neg_neg, Dvd.dvd] alias ⟨Dvd.dvd.of_neg_left, Dvd.dvd.neg_left⟩ := neg_dvd alias ⟨Dvd.dvd.of_neg_right, Dvd.dvd.neg_right⟩ := dvd_neg end Semigroup section NonUnitalRing variable [NonUnitalRing α] {a b c : α} theorem dvd_sub (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b - c := by simpa only [← sub_eq_add_neg] using h₁.add h₂.neg_right alias Dvd.dvd.sub := dvd_sub /-- If an element `a` divides another element `c` in a ring, `a` divides the sum of another element `b` with `c` iff `a` divides `b`. -/ theorem dvd_add_left (h : a ∣ c) : a ∣ b + c ↔ a ∣ b := ⟨fun H => by simpa only [add_sub_cancel_right] using dvd_sub H h, fun h₂ => dvd_add h₂ h⟩ /-- If an element `a` divides another element `b` in a ring, `a` divides the sum of `b` and another element `c` iff `a` divides `c`. -/ theorem dvd_add_right (h : a ∣ b) : a ∣ b + c ↔ a ∣ c := by rw [add_comm]; exact dvd_add_left h /-- If an element `a` divides another element `c` in a ring, `a` divides the difference of another element `b` with `c` iff `a` divides `b`. -/ theorem dvd_sub_left (h : a ∣ c) : a ∣ b - c ↔ a ∣ b := by -- Porting note: Needed to give `α` explicitly simpa only [← sub_eq_add_neg] using dvd_add_left ((dvd_neg (α := α)).2 h) /-- If an element `a` divides another element `b` in a ring, `a` divides the difference of `b` and another element `c` iff `a` divides `c`. -/ theorem dvd_sub_right (h : a ∣ b) : a ∣ b - c ↔ a ∣ c := by -- Porting note: Needed to give `α` explicitly rw [sub_eq_add_neg, dvd_add_right h, dvd_neg (α := α)] theorem dvd_iff_dvd_of_dvd_sub (h : a ∣ b - c) : a ∣ b ↔ a ∣ c := by rw [← sub_add_cancel b c, dvd_add_right h] -- Porting note: Needed to give `α` explicitly theorem dvd_sub_comm : a ∣ b - c ↔ a ∣ c - b := by rw [← dvd_neg (α := α), neg_sub] end NonUnitalRing section Ring variable [Ring α] {a b c : α} /-- An element a divides the sum a + b if and only if a divides b. -/ @[simp] theorem dvd_add_self_left {a b : α} : a ∣ a + b ↔ a ∣ b := dvd_add_right (dvd_refl a) /-- An element a divides the sum b + a if and only if a divides b. -/ @[simp] theorem dvd_add_self_right {a b : α} : a ∣ b + a ↔ a ∣ b := dvd_add_left (dvd_refl a) /-- An element `a` divides the difference `a - b` if and only if `a` divides `b`. -/ @[simp] theorem dvd_sub_self_left : a ∣ a - b ↔ a ∣ b := dvd_sub_right dvd_rfl /-- An element `a` divides the difference `b - a` if and only if `a` divides `b`. -/ @[simp] theorem dvd_sub_self_right : a ∣ b - a ↔ a ∣ b := dvd_sub_left dvd_rfl end Ring section NonUnitalCommRing variable [NonUnitalCommRing α] {a b c : α} theorem dvd_mul_sub_mul {k a b x y : α} (hab : k ∣ a - b) (hxy : k ∣ x - y) : k ∣ a * x - b * y := by convert dvd_add (hxy.mul_left a) (hab.mul_right y) using 1 rw [mul_sub_left_distrib, mul_sub_right_distrib] simp only [sub_eq_add_neg, add_assoc, neg_add_cancel_left] end NonUnitalCommRing
Algebra\Ring\Divisibility\Lemmas.lean
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Data.Nat.Choose.Sum import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Algebra.GCDMonoid.Basic /-! # Lemmas about divisibility in rings ## Main results: * `dvd_smul_of_dvd`: stating that `x ∣ y → x ∣ m • y` for any scalar `m`. * `Commute.pow_dvd_add_pow_of_pow_eq_zero_right`: stating that if `y` is nilpotent then `x ^ m ∣ (x + y) ^ p` for sufficiently large `p` (together with many variations for convenience). -/ variable {R : Type*} lemma dvd_smul_of_dvd {M : Type*} [SMul M R] [Semigroup R] [SMulCommClass M R R] {x y : R} (m : M) (h : x ∣ y) : x ∣ m • y := let ⟨k, hk⟩ := h; ⟨m • k, by rw [mul_smul_comm, ← hk]⟩ lemma dvd_nsmul_of_dvd [NonUnitalSemiring R] {x y : R} (n : ℕ) (h : x ∣ y) : x ∣ n • y := dvd_smul_of_dvd n h lemma dvd_zsmul_of_dvd [NonUnitalRing R] {x y : R} (z : ℤ) (h : x ∣ y) : x ∣ z • y := dvd_smul_of_dvd z h namespace Commute variable {x y : R} {n m p : ℕ} section Semiring variable [Semiring R] lemma pow_dvd_add_pow_of_pow_eq_zero_right (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hy : y ^ n = 0) : x ^ m ∣ (x + y) ^ p := by rw [h_comm.add_pow'] refine Finset.dvd_sum fun ⟨i, j⟩ hij ↦ ?_ replace hij : i + j = p := by simpa using hij apply dvd_nsmul_of_dvd rcases le_or_lt m i with (hi : m ≤ i) | (hi : i + 1 ≤ m) · exact dvd_mul_of_dvd_left (pow_dvd_pow x hi) _ · simp [pow_eq_zero_of_le (by omega : n ≤ j) hy] lemma pow_dvd_add_pow_of_pow_eq_zero_left (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hx : x ^ n = 0) : y ^ m ∣ (x + y) ^ p := add_comm x y ▸ h_comm.symm.pow_dvd_add_pow_of_pow_eq_zero_right hp hx end Semiring section Ring variable [Ring R] lemma pow_dvd_pow_of_sub_pow_eq_zero (hp : n + m ≤ p + 1) (h_comm : Commute x y) (h : (x - y) ^ n = 0) : x ^ m ∣ y ^ p := by rw [← sub_add_cancel y x] apply (h_comm.symm.sub_left rfl).pow_dvd_add_pow_of_pow_eq_zero_left hp _ rw [← neg_sub x y, neg_pow, h, mul_zero] lemma pow_dvd_pow_of_add_pow_eq_zero (hp : n + m ≤ p + 1) (h_comm : Commute x y) (h : (x + y) ^ n = 0) : x ^ m ∣ y ^ p := by rw [← neg_neg y, neg_pow'] apply dvd_mul_of_dvd_left apply h_comm.neg_right.pow_dvd_pow_of_sub_pow_eq_zero hp simpa lemma pow_dvd_sub_pow_of_pow_eq_zero_right (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hy : y ^ n = 0) : x ^ m ∣ (x - y) ^ p := (sub_right rfl h_comm).pow_dvd_pow_of_sub_pow_eq_zero hp (by simpa) lemma pow_dvd_sub_pow_of_pow_eq_zero_left (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hx : x ^ n = 0) : y ^ m ∣ (x - y) ^ p := by rw [← neg_sub y x, neg_pow'] apply dvd_mul_of_dvd_left exact h_comm.symm.pow_dvd_sub_pow_of_pow_eq_zero_right hp hx lemma add_pow_dvd_pow_of_pow_eq_zero_right (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hx : x ^ n = 0) : (x + y) ^ m ∣ y ^ p := (h_comm.add_left rfl).pow_dvd_pow_of_sub_pow_eq_zero hp (by simpa) lemma add_pow_dvd_pow_of_pow_eq_zero_left (hp : n + m ≤ p + 1) (h_comm : Commute x y) (hy : y ^ n = 0) : (x + y) ^ m ∣ x ^ p := add_comm x y ▸ h_comm.symm.add_pow_dvd_pow_of_pow_eq_zero_right hp hy end Ring end Commute section CommRing variable [CommRing R] lemma dvd_mul_sub_mul_mul_left_of_dvd {p a b c d x y : R} (h1 : p ∣ a * x + b * y) (h2 : p ∣ c * x + d * y) : p ∣ (a * d - b * c) * x := by obtain ⟨k1, hk1⟩ := h1 obtain ⟨k2, hk2⟩ := h2 refine ⟨d * k1 - b * k2, ?_⟩ rw [show (a * d - b * c) * x = a * x * d - c * x * b by ring, eq_sub_of_add_eq hk1, eq_sub_of_add_eq hk2] ring lemma dvd_mul_sub_mul_mul_right_of_dvd {p a b c d x y : R} (h1 : p ∣ a * x + b * y) (h2 : p ∣ c * x + d * y) : p ∣ (a * d - b * c) * y := (mul_comm a _ ▸ mul_comm c _ ▸ dvd_mul_sub_mul_mul_left_of_dvd (add_comm (c * x) _ ▸ h2) (add_comm (a * x) _ ▸ h1)) lemma dvd_mul_sub_mul_mul_gcd_of_dvd {p a b c d x y : R} [IsDomain R] [GCDMonoid R] (h1 : p ∣ a * x + b * y) (h2 : p ∣ c * x + d * y) : p ∣ (a * d - b * c) * gcd x y := by rw [← (gcd_mul_left' (a*d - b*c) x y).dvd_iff_dvd_right] exact (dvd_gcd_iff _ _ _).2 ⟨dvd_mul_sub_mul_mul_left_of_dvd h1 h2, dvd_mul_sub_mul_mul_right_of_dvd h1 h2⟩ end CommRing
Algebra\Ring\Hom\Basic.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Jireh Loreaux -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Data.Set.Basic /-! # Additional lemmas about homomorphisms of semirings and rings These lemmas have been banished here to avoid unnecessary imports in `Mathlib.Algebra.Hom.Ring.Defs`. They could be moved to more natural homes. -/ open Function variable {F α β γ : Type*} namespace RingHom section variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} (f : α →+* β) {x y : α} /-- `f : α →+* β` has a trivial codomain iff its range is `{0}`. -/ theorem codomain_trivial_iff_range_eq_singleton_zero : (0 : β) = 1 ↔ Set.range f = {0} := f.codomain_trivial_iff_range_trivial.trans ⟨fun h => Set.ext fun y => ⟨fun ⟨x, hx⟩ => by simp [← hx, h x], fun hy => ⟨0, by simpa using hy.symm⟩⟩, fun h x => Set.mem_singleton_iff.mp (h ▸ Set.mem_range_self x)⟩ end section Semiring variable [Semiring α] [Semiring β] theorem isUnit_map (f : α →+* β) {a : α} : IsUnit a → IsUnit (f a) := IsUnit.map f protected theorem map_dvd (f : α →+* β) {a b : α} : a ∣ b → f a ∣ f b := map_dvd f end Semiring end RingHom /-- Pullback `IsDomain` instance along an injective function. -/ protected theorem Function.Injective.isDomain [Ring α] [IsDomain α] [Ring β] (f : β →+* α) (hf : Injective f) : IsDomain β := by haveI := pullback_nonzero f f.map_zero f.map_one haveI := IsRightCancelMulZero.to_noZeroDivisors α haveI := hf.noZeroDivisors f f.map_zero f.map_mul exact NoZeroDivisors.to_isDomain β
Algebra\Ring\Hom\Defs.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Jireh Loreaux -/ import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Ring.Basic /-! # Homomorphisms of semirings and rings This file defines bundled homomorphisms of (non-unital) semirings and rings. As with monoid and groups, we use the same structure `RingHom a β`, a.k.a. `α →+* β`, for both types of homomorphisms. ## Main definitions * `NonUnitalRingHom`: Non-unital (semi)ring homomorphisms. Additive monoid homomorphism which preserve multiplication. * `RingHom`: (Semi)ring homomorphisms. Monoid homomorphisms which are also additive monoid homomorphism. ## Notations * `→ₙ+*`: Non-unital (semi)ring homs * `→+*`: (Semi)ring homs ## Implementation notes * There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. * There is no `SemiringHom` -- the idea is that `RingHom` is used. The constructor for a `RingHom` between semirings needs a proof of `map_zero`, `map_one` and `map_add` as well as `map_mul`; a separate constructor `RingHom.mk'` will construct ring homs between rings from monoid homs given only a proof that addition is preserved. ## Tags `RingHom`, `SemiringHom` -/ open Function variable {F α β γ : Type*} /-- Bundled non-unital semiring homomorphisms `α →ₙ+* β`; use this for bundled non-unital ring homomorphisms too. When possible, instead of parametrizing results over `(f : α →ₙ+* β)`, you should parametrize over `(F : Type*) [NonUnitalRingHomClass F α β] (f : F)`. When you extend this structure, make sure to extend `NonUnitalRingHomClass`. -/ structure NonUnitalRingHom (α β : Type*) [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] extends α →ₙ* β, α →+ β /-- `α →ₙ+* β` denotes the type of non-unital ring homomorphisms from `α` to `β`. -/ infixr:25 " →ₙ+* " => NonUnitalRingHom /-- Reinterpret a non-unital ring homomorphism `f : α →ₙ+* β` as a semigroup homomorphism `α →ₙ* β`. The `simp`-normal form is `(f : α →ₙ* β)`. -/ add_decl_doc NonUnitalRingHom.toMulHom /-- Reinterpret a non-unital ring homomorphism `f : α →ₙ+* β` as an additive monoid homomorphism `α →+ β`. The `simp`-normal form is `(f : α →+ β)`. -/ add_decl_doc NonUnitalRingHom.toAddMonoidHom section NonUnitalRingHomClass /-- `NonUnitalRingHomClass F α β` states that `F` is a type of non-unital (semi)ring homomorphisms. You should extend this class when you extend `NonUnitalRingHom`. -/ class NonUnitalRingHomClass (F : Type*) (α β : outParam Type*) [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] [FunLike F α β] extends MulHomClass F α β, AddMonoidHomClass F α β : Prop variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] [FunLike F α β] variable [NonUnitalRingHomClass F α β] /-- Turn an element of a type `F` satisfying `NonUnitalRingHomClass F α β` into an actual `NonUnitalRingHom`. This is declared as the default coercion from `F` to `α →ₙ+* β`. -/ @[coe] def NonUnitalRingHomClass.toNonUnitalRingHom (f : F) : α →ₙ+* β := { (f : α →ₙ* β), (f : α →+ β) with } /-- Any type satisfying `NonUnitalRingHomClass` can be cast into `NonUnitalRingHom` via `NonUnitalRingHomClass.toNonUnitalRingHom`. -/ instance : CoeTC F (α →ₙ+* β) := ⟨NonUnitalRingHomClass.toNonUnitalRingHom⟩ end NonUnitalRingHomClass namespace NonUnitalRingHom section coe variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] instance : FunLike (α →ₙ+* β) α β where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h instance : NonUnitalRingHomClass (α →ₙ+* β) α β where map_add := NonUnitalRingHom.map_add' map_zero := NonUnitalRingHom.map_zero' map_mul f := f.map_mul' -- Porting note: removed due to new `coe` in Lean4 initialize_simps_projections NonUnitalRingHom (toFun → apply) @[simp] theorem coe_toMulHom (f : α →ₙ+* β) : ⇑f.toMulHom = f := rfl @[simp] theorem coe_mulHom_mk (f : α → β) (h₁ h₂ h₃) : ((⟨⟨f, h₁⟩, h₂, h₃⟩ : α →ₙ+* β) : α →ₙ* β) = ⟨f, h₁⟩ := rfl theorem coe_toAddMonoidHom (f : α →ₙ+* β) : ⇑f.toAddMonoidHom = f := rfl @[simp] theorem coe_addMonoidHom_mk (f : α → β) (h₁ h₂ h₃) : ((⟨⟨f, h₁⟩, h₂, h₃⟩ : α →ₙ+* β) : α →+ β) = ⟨⟨f, h₂⟩, h₃⟩ := rfl /-- Copy of a `RingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : α →ₙ+* β := { f.toMulHom.copy f' h, f.toAddMonoidHom.copy f' h with } @[simp] theorem coe_copy (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : α →ₙ+* β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h end coe section variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] variable (f : α →ₙ+* β) {x y : α} @[ext] theorem ext ⦃f g : α →ₙ+* β⦄ : (∀ x, f x = g x) → f = g := DFunLike.ext _ _ @[simp] theorem mk_coe (f : α →ₙ+* β) (h₁ h₂ h₃) : NonUnitalRingHom.mk (MulHom.mk f h₁) h₂ h₃ = f := ext fun _ => rfl theorem coe_addMonoidHom_injective : Injective fun f : α →ₙ+* β => (f : α →+ β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective theorem coe_mulHom_injective : Injective fun f : α →ₙ+* β => (f : α →ₙ* β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective end variable [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] /-- The identity non-unital ring homomorphism from a non-unital semiring to itself. -/ protected def id (α : Type*) [NonUnitalNonAssocSemiring α] : α →ₙ+* α where toFun := id map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl instance : Zero (α →ₙ+* β) := ⟨{ toFun := 0, map_mul' := fun _ _ => (mul_zero (0 : β)).symm, map_zero' := rfl, map_add' := fun _ _ => (add_zero (0 : β)).symm }⟩ instance : Inhabited (α →ₙ+* β) := ⟨0⟩ @[simp] theorem coe_zero : ⇑(0 : α →ₙ+* β) = 0 := rfl @[simp] theorem zero_apply (x : α) : (0 : α →ₙ+* β) x = 0 := rfl @[simp] theorem id_apply (x : α) : NonUnitalRingHom.id α x = x := rfl @[simp] theorem coe_addMonoidHom_id : (NonUnitalRingHom.id α : α →+ α) = AddMonoidHom.id α := rfl @[simp] theorem coe_mulHom_id : (NonUnitalRingHom.id α : α →ₙ* α) = MulHom.id α := rfl variable [NonUnitalNonAssocSemiring γ] /-- Composition of non-unital ring homomorphisms is a non-unital ring homomorphism. -/ def comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : α →ₙ+* γ := { g.toMulHom.comp f.toMulHom, g.toAddMonoidHom.comp f.toAddMonoidHom with } /-- Composition of non-unital ring homomorphisms is associative. -/ theorem comp_assoc {δ} {_ : NonUnitalNonAssocSemiring δ} (f : α →ₙ+* β) (g : β →ₙ+* γ) (h : γ →ₙ+* δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem coe_comp (g : β →ₙ+* γ) (f : α →ₙ+* β) : ⇑(g.comp f) = g ∘ f := rfl @[simp] theorem comp_apply (g : β →ₙ+* γ) (f : α →ₙ+* β) (x : α) : g.comp f x = g (f x) := rfl variable (g : β →ₙ+* γ) (f : α →ₙ+* β) @[simp] theorem coe_comp_addMonoidHom (g : β →ₙ+* γ) (f : α →ₙ+* β) : AddMonoidHom.mk ⟨g ∘ f, (g.comp f).map_zero'⟩ (g.comp f).map_add' = (g : β →+ γ).comp f := rfl @[simp] theorem coe_comp_mulHom (g : β →ₙ+* γ) (f : α →ₙ+* β) : MulHom.mk (g ∘ f) (g.comp f).map_mul' = (g : β →ₙ* γ).comp f := rfl @[simp] theorem comp_zero (g : β →ₙ+* γ) : g.comp (0 : α →ₙ+* β) = 0 := by ext simp @[simp] theorem zero_comp (f : α →ₙ+* β) : (0 : β →ₙ+* γ).comp f = 0 := by ext rfl @[simp] theorem comp_id (f : α →ₙ+* β) : f.comp (NonUnitalRingHom.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : α →ₙ+* β) : (NonUnitalRingHom.id β).comp f = f := ext fun _ => rfl instance : MonoidWithZero (α →ₙ+* α) where one := NonUnitalRingHom.id α mul := comp mul_one := comp_id one_mul := id_comp mul_assoc f g h := comp_assoc _ _ _ zero := 0 mul_zero := comp_zero zero_mul := zero_comp theorem one_def : (1 : α →ₙ+* α) = NonUnitalRingHom.id α := rfl @[simp] theorem coe_one : ⇑(1 : α →ₙ+* α) = id := rfl theorem mul_def (f g : α →ₙ+* α) : f * g = f.comp g := rfl @[simp] theorem coe_mul (f g : α →ₙ+* α) : ⇑(f * g) = f ∘ g := rfl @[simp] theorem cancel_right {g₁ g₂ : β →ₙ+* γ} {f : α →ₙ+* β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => ext <| hf.forall.2 (NonUnitalRingHom.ext_iff.1 h), fun h => h ▸ rfl⟩ @[simp] theorem cancel_left {g : β →ₙ+* γ} {f₁ f₂ : α →ₙ+* β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => ext fun x => hg <| by rw [← comp_apply, h, comp_apply], fun h => h ▸ rfl⟩ end NonUnitalRingHom /-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too. This extends from both `MonoidHom` and `MonoidWithZeroHom` in order to put the fields in a sensible order, even though `MonoidWithZeroHom` already extends `MonoidHom`. -/ structure RingHom (α : Type*) (β : Type*) [NonAssocSemiring α] [NonAssocSemiring β] extends α →* β, α →+ β, α →ₙ+* β, α →*₀ β /-- `α →+* β` denotes the type of ring homomorphisms from `α` to `β`. -/ infixr:25 " →+* " => RingHom /-- Reinterpret a ring homomorphism `f : α →+* β` as a monoid with zero homomorphism `α →*₀ β`. The `simp`-normal form is `(f : α →*₀ β)`. -/ add_decl_doc RingHom.toMonoidWithZeroHom /-- Reinterpret a ring homomorphism `f : α →+* β` as a monoid homomorphism `α →* β`. The `simp`-normal form is `(f : α →* β)`. -/ add_decl_doc RingHom.toMonoidHom /-- Reinterpret a ring homomorphism `f : α →+* β` as an additive monoid homomorphism `α →+ β`. The `simp`-normal form is `(f : α →+ β)`. -/ add_decl_doc RingHom.toAddMonoidHom /-- Reinterpret a ring homomorphism `f : α →+* β` as a non-unital ring homomorphism `α →ₙ+* β`. The `simp`-normal form is `(f : α →ₙ+* β)`. -/ add_decl_doc RingHom.toNonUnitalRingHom section RingHomClass /-- `RingHomClass F α β` states that `F` is a type of (semi)ring homomorphisms. You should extend this class when you extend `RingHom`. This extends from both `MonoidHomClass` and `MonoidWithZeroHomClass` in order to put the fields in a sensible order, even though `MonoidWithZeroHomClass` already extends `MonoidHomClass`. -/ class RingHomClass (F : Type*) (α β : outParam Type*) [NonAssocSemiring α] [NonAssocSemiring β] [FunLike F α β] extends MonoidHomClass F α β, AddMonoidHomClass F α β, MonoidWithZeroHomClass F α β : Prop variable [FunLike F α β] -- Porting note: marked `{}` rather than `[]` to prevent dangerous instances variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} [RingHomClass F α β] /-- Turn an element of a type `F` satisfying `RingHomClass F α β` into an actual `RingHom`. This is declared as the default coercion from `F` to `α →+* β`. -/ @[coe] def RingHomClass.toRingHom (f : F) : α →+* β := { (f : α →* β), (f : α →+ β) with } /-- Any type satisfying `RingHomClass` can be cast into `RingHom` via `RingHomClass.toRingHom`. -/ instance : CoeTC F (α →+* β) := ⟨RingHomClass.toRingHom⟩ instance (priority := 100) RingHomClass.toNonUnitalRingHomClass : NonUnitalRingHomClass F α β := { ‹RingHomClass F α β› with } end RingHomClass namespace RingHom section coe /-! Throughout this section, some `Semiring` arguments are specified with `{}` instead of `[]`. See note [implicit instance arguments]. -/ variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} instance instFunLike : FunLike (α →+* β) α β where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h instance instRingHomClass : RingHomClass (α →+* β) α β where map_add := RingHom.map_add' map_zero := RingHom.map_zero' map_mul f := f.map_mul' map_one f := f.map_one' initialize_simps_projections RingHom (toFun → apply) -- Porting note: is this lemma still needed in Lean4? -- Porting note: because `f.toFun` really means `f.toMonoidHom.toOneHom.toFun` and -- `toMonoidHom_eq_coe` wants to simplify `f.toMonoidHom` to `(↑f : M →* N)`, this can't -- be a simp lemma anymore -- @[simp] theorem toFun_eq_coe (f : α →+* β) : f.toFun = f := rfl @[simp] theorem coe_mk (f : α →* β) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : α →+* β) : α → β) = f := rfl @[simp] theorem coe_coe {F : Type*} [FunLike F α β] [RingHomClass F α β] (f : F) : ((f : α →+* β) : α → β) = f := rfl attribute [coe] RingHom.toMonoidHom instance coeToMonoidHom : Coe (α →+* β) (α →* β) := ⟨RingHom.toMonoidHom⟩ -- Porting note: `dsimp only` can prove this @[simp] theorem toMonoidHom_eq_coe (f : α →+* β) : f.toMonoidHom = f := rfl -- Porting note: this can't be a simp lemma anymore -- @[simp] theorem toMonoidWithZeroHom_eq_coe (f : α →+* β) : (f.toMonoidWithZeroHom : α → β) = f := by rfl @[simp] theorem coe_monoidHom_mk (f : α →* β) (h₁ h₂) : ((⟨f, h₁, h₂⟩ : α →+* β) : α →* β) = f := rfl -- Porting note: `dsimp only` can prove this @[simp] theorem toAddMonoidHom_eq_coe (f : α →+* β) : f.toAddMonoidHom = f := rfl @[simp] theorem coe_addMonoidHom_mk (f : α → β) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩ : α →+* β) : α →+ β) = ⟨⟨f, h₃⟩, h₄⟩ := rfl /-- Copy of a `RingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ def copy (f : α →+* β) (f' : α → β) (h : f' = f) : α →+* β := { f.toMonoidWithZeroHom.copy f' h, f.toAddMonoidHom.copy f' h with } @[simp] theorem coe_copy (f : α →+* β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : α →+* β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h end coe section variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} (f : α →+* β) {x y : α} protected theorem congr_fun {f g : α →+* β} (h : f = g) (x : α) : f x = g x := DFunLike.congr_fun h x protected theorem congr_arg (f : α →+* β) {x y : α} (h : x = y) : f x = f y := DFunLike.congr_arg f h theorem coe_inj ⦃f g : α →+* β⦄ (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h @[ext] theorem ext ⦃f g : α →+* β⦄ : (∀ x, f x = g x) → f = g := DFunLike.ext _ _ @[simp] theorem mk_coe (f : α →+* β) (h₁ h₂ h₃ h₄) : RingHom.mk ⟨⟨f, h₁⟩, h₂⟩ h₃ h₄ = f := ext fun _ => rfl theorem coe_addMonoidHom_injective : Injective (fun f : α →+* β => (f : α →+ β)) := fun _ _ h => ext <| DFunLike.congr_fun (F := α →+ β) h theorem coe_monoidHom_injective : Injective (fun f : α →+* β => (f : α →* β)) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective /-- Ring homomorphisms map zero to zero. -/ protected theorem map_zero (f : α →+* β) : f 0 = 0 := map_zero f /-- Ring homomorphisms map one to one. -/ protected theorem map_one (f : α →+* β) : f 1 = 1 := map_one f /-- Ring homomorphisms preserve addition. -/ protected theorem map_add (f : α →+* β) : ∀ a b, f (a + b) = f a + f b := map_add f /-- Ring homomorphisms preserve multiplication. -/ protected theorem map_mul (f : α →+* β) : ∀ a b, f (a * b) = f a * f b := map_mul f @[simp] theorem map_ite_zero_one {F : Type*} [FunLike F α β] [RingHomClass F α β] (f : F) (p : Prop) [Decidable p] : f (ite p 0 1) = ite p 0 1 := by split_ifs with h <;> simp [h] @[simp] theorem map_ite_one_zero {F : Type*} [FunLike F α β] [RingHomClass F α β] (f : F) (p : Prop) [Decidable p] : f (ite p 1 0) = ite p 1 0 := by split_ifs with h <;> simp [h] /-- `f : α →+* β` has a trivial codomain iff `f 1 = 0`. -/ theorem codomain_trivial_iff_map_one_eq_zero : (0 : β) = 1 ↔ f 1 = 0 := by rw [map_one, eq_comm] /-- `f : α →+* β` has a trivial codomain iff it has a trivial range. -/ theorem codomain_trivial_iff_range_trivial : (0 : β) = 1 ↔ ∀ x, f x = 0 := f.codomain_trivial_iff_map_one_eq_zero.trans ⟨fun h x => by rw [← mul_one x, map_mul, h, mul_zero], fun h => h 1⟩ /-- `f : α →+* β` doesn't map `1` to `0` if `β` is nontrivial -/ theorem map_one_ne_zero [Nontrivial β] : f 1 ≠ 0 := mt f.codomain_trivial_iff_map_one_eq_zero.mpr zero_ne_one /-- If there is a homomorphism `f : α →+* β` and `β` is nontrivial, then `α` is nontrivial. -/ theorem domain_nontrivial [Nontrivial β] : Nontrivial α := ⟨⟨1, 0, mt (fun h => show f 1 = 0 by rw [h, map_zero]) f.map_one_ne_zero⟩⟩ theorem codomain_trivial (f : α →+* β) [h : Subsingleton α] : Subsingleton β := (subsingleton_or_nontrivial β).resolve_right fun _ => not_nontrivial_iff_subsingleton.mpr h f.domain_nontrivial end /-- Ring homomorphisms preserve additive inverse. -/ protected theorem map_neg [NonAssocRing α] [NonAssocRing β] (f : α →+* β) (x : α) : f (-x) = -f x := map_neg f x /-- Ring homomorphisms preserve subtraction. -/ protected theorem map_sub [NonAssocRing α] [NonAssocRing β] (f : α →+* β) (x y : α) : f (x - y) = f x - f y := map_sub f x y /-- Makes a ring homomorphism from a monoid homomorphism of rings which preserves addition. -/ def mk' [NonAssocSemiring α] [NonAssocRing β] (f : α →* β) (map_add : ∀ a b, f (a + b) = f a + f b) : α →+* β := { AddMonoidHom.mk' f map_add, f with } variable {_ : NonAssocSemiring α} {_ : NonAssocSemiring β} /-- The identity ring homomorphism from a semiring to itself. -/ def id (α : Type*) [NonAssocSemiring α] : α →+* α where toFun := _root_.id map_zero' := rfl map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl instance : Inhabited (α →+* α) := ⟨id α⟩ @[simp] theorem id_apply (x : α) : RingHom.id α x = x := rfl @[simp] theorem coe_addMonoidHom_id : (id α : α →+ α) = AddMonoidHom.id α := rfl @[simp] theorem coe_monoidHom_id : (id α : α →* α) = MonoidHom.id α := rfl variable {_ : NonAssocSemiring γ} /-- Composition of ring homomorphisms is a ring homomorphism. -/ def comp (g : β →+* γ) (f : α →+* β) : α →+* γ := { g.toNonUnitalRingHom.comp f.toNonUnitalRingHom with toFun := g ∘ f, map_one' := by simp } /-- Composition of semiring homomorphisms is associative. -/ theorem comp_assoc {δ} {_ : NonAssocSemiring δ} (f : α →+* β) (g : β →+* γ) (h : γ →+* δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem coe_comp (hnp : β →+* γ) (hmn : α →+* β) : (hnp.comp hmn : α → γ) = hnp ∘ hmn := rfl theorem comp_apply (hnp : β →+* γ) (hmn : α →+* β) (x : α) : (hnp.comp hmn : α → γ) x = hnp (hmn x) := rfl @[simp] theorem comp_id (f : α →+* β) : f.comp (id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : α →+* β) : (id β).comp f = f := ext fun _ => rfl instance instOne : One (α →+* α) where one := id _ instance instMul : Mul (α →+* α) where mul := comp lemma one_def : (1 : α →+* α) = id α := rfl lemma mul_def (f g : α →+* α) : f * g = f.comp g := rfl @[simp, norm_cast] lemma coe_one : ⇑(1 : α →+* α) = _root_.id := rfl @[simp, norm_cast] lemma coe_mul (f g : α →+* α) : ⇑(f * g) = f ∘ g := rfl instance instMonoid : Monoid (α →+* α) where mul_one := comp_id one_mul := id_comp mul_assoc f g h := comp_assoc _ _ _ npow n f := (npowRec n f).copy f^[n] $ by induction' n <;> simp [npowRec, *] npow_succ n f := DFunLike.coe_injective $ Function.iterate_succ _ _ @[simp, norm_cast] lemma coe_pow (f : α →+* α) (n : ℕ) : ⇑(f ^ n) = f^[n] := rfl @[simp] theorem cancel_right {g₁ g₂ : β →+* γ} {f : α →+* β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => RingHom.ext <| hf.forall.2 (RingHom.ext_iff.1 h), fun h => h ▸ rfl⟩ @[simp] theorem cancel_left {g : β →+* γ} {f₁ f₂ : α →+* β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => RingHom.ext fun x => hg <| by rw [← comp_apply, h, comp_apply], fun h => h ▸ rfl⟩ end RingHom section Semiring variable [Semiring α] [Semiring β] protected lemma RingHom.map_pow (f : α →+* β) (a) : ∀ n : ℕ, f (a ^ n) = f a ^ n := map_pow f a end Semiring namespace AddMonoidHom variable [CommRing α] [IsDomain α] [CommRing β] (f : β →+ α) -- Porting note: there's some disagreement over the naming scheme here. -- This could perhaps be `mkRingHom_of_mul_self_of_two_ne_zero`. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/naming.20conventions/near/315558410 /-- Make a ring homomorphism from an additive group homomorphism from a commutative ring to an integral domain that commutes with self multiplication, assumes that two is nonzero and `1` is sent to `1`. -/ def mkRingHomOfMulSelfOfTwoNeZero (h : ∀ x, f (x * x) = f x * f x) (h_two : (2 : α) ≠ 0) (h_one : f 1 = 1) : β →+* α := { f with map_one' := h_one, map_mul' := fun x y => by have hxy := h (x + y) rw [mul_add, add_mul, add_mul, f.map_add, f.map_add, f.map_add, f.map_add, h x, h y, add_mul, mul_add, mul_add, ← sub_eq_zero, add_comm (f x * f x + f (y * x)), ← sub_sub, ← sub_sub, ← sub_sub, mul_comm y x, mul_comm (f y) (f x)] at hxy simp only [add_assoc, add_sub_assoc, add_sub_cancel] at hxy rw [sub_sub, ← two_mul, ← add_sub_assoc, ← two_mul, ← mul_sub, mul_eq_zero (M₀ := α), sub_eq_zero, or_iff_not_imp_left] at hxy exact hxy h_two } @[simp] theorem coe_fn_mkRingHomOfMulSelfOfTwoNeZero (h h_two h_one) : (f.mkRingHomOfMulSelfOfTwoNeZero h h_two h_one : β → α) = f := rfl -- Porting note (#10618): `simp` can prove this -- @[simp] theorem coe_addMonoidHom_mkRingHomOfMulSelfOfTwoNeZero (h h_two h_one) : (f.mkRingHomOfMulSelfOfTwoNeZero h h_two h_one : β →+ α) = f := by ext rfl end AddMonoidHom assert_not_exists Function.Injective.mulZeroClass assert_not_exists semigroupDvd assert_not_exists Units.map assert_not_exists Set.range
Algebra\Ring\Semireal\Defs.lean
/- Copyright (c) 2024 Florent Schaffhauser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Florent Schaffhauser -/ import Mathlib.Algebra.Ring.SumsOfSquares import Mathlib.Algebra.Order.Field.Defs /-! # Semireal rings A semireal ring is a non-trivial commutative ring (with unit) in which `-1` is *not* a sum of squares. Note that `-1` does not make sense in a semiring. For instance, linearly ordered fields are semireal, because sums of squares are positive and `-1` is not. More generally, linearly ordered semirings in which `a ≤ b → ∃ c, a + c = b` holds, are semireal. ## Main declaration - `isSemireal`: the predicate asserting that a commutative ring `R` is semireal. ## References - *An introduction to real algebra*, by T.Y. Lam. Rocky Mountain J. Math. 14(4): 767-814 (1984). [lam_1984](https://doi.org/10.1216/RMJ-1984-14-4-767) -/ variable (R : Type*) /-- A semireal ring is a non-trivial commutative ring (with unit) in which `-1` is *not* a sum of squares. Note that `-1` does not make sense in a semiring. Below we define the class `isSemiReal R` for all additive monoid `R` equipped with a multiplication, a multiplicative unit and a negation. -/ @[mk_iff] class isSemireal [AddMonoid R] [Mul R] [One R] [Neg R] : Prop where non_trivial : (0 : R) ≠ 1 neg_one_not_SumSq : ¬isSumSq (-1 : R) instance [LinearOrderedField R] : isSemireal R where non_trivial := zero_ne_one neg_one_not_SumSq := fun h ↦ (not_le (α := R)).2 neg_one_lt_zero h.nonneg
Algebra\Ring\Subring\Basic.lean
/- Copyright (c) 2020 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan -/ import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Ring.Subsemiring.Basic /-! # Subrings Let `R` be a ring. This file defines the "bundled" subring type `Subring R`, a type whose terms correspond to subrings of `R`. This is the preferred way to talk about subrings in mathlib. Unbundled subrings (`s : Set R` and `IsSubring s`) are not in this file, and they will ultimately be deprecated. We prove that subrings are a complete lattice, and that you can `map` (pushforward) and `comap` (pull back) them along ring homomorphisms. We define the `closure` construction from `Set R` to `Subring R`, sending a subset of `R` to the subring it generates, and prove that it is a Galois insertion. ## Main definitions Notation used here: `(R : Type u) [Ring R] (S : Type u) [Ring S] (f g : R →+* S)` `(A : Subring R) (B : Subring S) (s : Set R)` * `Subring R` : the type of subrings of a ring `R`. * `instance : CompleteLattice (Subring R)` : the complete lattice structure on the subrings. * `Subring.center` : the center of a ring `R`. * `Subring.closure` : subring closure of a set, i.e., the smallest subring that includes the set. * `Subring.gi` : `closure : Set M → Subring M` and coercion `(↑) : Subring M → et M` form a `GaloisInsertion`. * `comap f B : Subring A` : the preimage of a subring `B` along the ring homomorphism `f` * `map f A : Subring B` : the image of a subring `A` along the ring homomorphism `f`. * `prod A B : Subring (R × S)` : the product of subrings * `f.range : Subring B` : the range of the ring homomorphism `f`. * `eqLocus f g : Subring R` : given ring homomorphisms `f g : R →+* S`, the subring of `R` where `f x = g x` ## Implementation notes A subring is implemented as a subsemiring which is also an additive subgroup. The initial PR was as a submonoid which is also an additive subgroup. Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although `∈` is defined as membership of a subring's underlying set. ## Tags subring, subrings -/ assert_not_exists OrderedRing universe u v w variable {R : Type u} {S : Type v} {T : Type w} [Ring R] section SubringClass /-- `SubringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both a multiplicative submonoid and an additive subgroup. -/ class SubringClass (S : Type*) (R : Type u) [Ring R] [SetLike S R] extends SubsemiringClass S R, NegMemClass S R : Prop -- See note [lower instance priority] instance (priority := 100) SubringClass.addSubgroupClass (S : Type*) (R : Type u) [SetLike S R] [Ring R] [h : SubringClass S R] : AddSubgroupClass S R := { h with } variable [SetLike S R] [hSR : SubringClass S R] (s : S) @[aesop safe apply (rule_sets := [SetLike])] theorem intCast_mem (n : ℤ) : (n : R) ∈ s := by simp only [← zsmul_one, zsmul_mem, one_mem] @[deprecated _root_.intCast_mem (since := "2024-04-05")] alias coe_int_mem := intCast_mem namespace SubringClass instance (priority := 75) toHasIntCast : IntCast s := ⟨fun n => ⟨n, intCast_mem s n⟩⟩ -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a ring inherits a ring structure -/ instance (priority := 75) toRing : Ring s := Subtype.coe_injective.ring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a `CommRing` is a `CommRing`. -/ instance (priority := 75) toCommRing {R} [CommRing R] [SetLike S R] [SubringClass S R] : CommRing s := Subtype.coe_injective.commRing (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a domain is a domain. -/ instance (priority := 75) {R} [Ring R] [IsDomain R] [SetLike S R] [SubringClass S R] : IsDomain s := NoZeroDivisors.to_isDomain _ /-- The natural ring hom from a subring of ring `R` to `R`. -/ def subtype (s : S) : s →+* R := { SubmonoidClass.subtype s, AddSubgroupClass.subtype s with toFun := (↑) } @[simp] theorem coeSubtype : (subtype s : s → R) = ((↑) : s → R) := rfl @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : s) : R) = n := map_natCast (subtype s) n @[simp, norm_cast] theorem coe_intCast (n : ℤ) : ((n : s) : R) = n := map_intCast (subtype s) n end SubringClass end SubringClass variable [Ring S] [Ring T] /-- `Subring R` is the type of subrings of `R`. A subring of `R` is a subset `s` that is a multiplicative submonoid and an additive subgroup. Note in particular that it shares the same 0 and 1 as R. -/ structure Subring (R : Type u) [Ring R] extends Subsemiring R, AddSubgroup R /-- Reinterpret a `Subring` as a `Subsemiring`. -/ add_decl_doc Subring.toSubsemiring /-- Reinterpret a `Subring` as an `AddSubgroup`. -/ add_decl_doc Subring.toAddSubgroup namespace Subring -- Porting note: there is no `Subring.toSubmonoid` but we can't define it because there is a -- projection `s.toSubmonoid` instance : SetLike (Subring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h instance : SubringClass (Subring R) R where zero_mem s := s.zero_mem' add_mem {s} := s.add_mem' one_mem s := s.one_mem' mul_mem {s} := s.mul_mem' neg_mem {s} := s.neg_mem' @[simp] theorem mem_toSubsemiring {s : Subring R} {x : R} : x ∈ s.toSubsemiring ↔ x ∈ s := Iff.rfl theorem mem_carrier {s : Subring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[simp] theorem mem_mk {S : Subsemiring R} {x : R} (h) : x ∈ (⟨S, h⟩ : Subring R) ↔ x ∈ S := Iff.rfl @[simp] theorem coe_set_mk (S : Subsemiring R) (h) : ((⟨S, h⟩ : Subring R) : Set R) = S := rfl @[simp] theorem mk_le_mk {S S' : Subsemiring R} (h₁ h₂) : (⟨S, h₁⟩ : Subring R) ≤ (⟨S', h₂⟩ : Subring R) ↔ S ≤ S' := Iff.rfl /-- Two subrings are equal if they have the same elements. -/ @[ext] theorem ext {S T : Subring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy of a subring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : Subring R) (s : Set R) (hs : s = ↑S) : Subring R := { S.toSubsemiring.copy s hs with carrier := s neg_mem' := hs.symm ▸ S.neg_mem' } @[simp] theorem coe_copy (S : Subring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : Subring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs theorem toSubsemiring_injective : Function.Injective (toSubsemiring : Subring R → Subsemiring R) | _, _, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toSubsemiring_strictMono : StrictMono (toSubsemiring : Subring R → Subsemiring R) := fun _ _ => id @[mono] theorem toSubsemiring_mono : Monotone (toSubsemiring : Subring R → Subsemiring R) := toSubsemiring_strictMono.monotone theorem toAddSubgroup_injective : Function.Injective (toAddSubgroup : Subring R → AddSubgroup R) | _, _, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : Subring R → AddSubgroup R) := fun _ _ => id @[mono] theorem toAddSubgroup_mono : Monotone (toAddSubgroup : Subring R → AddSubgroup R) := toAddSubgroup_strictMono.monotone theorem toSubmonoid_injective : Function.Injective (fun s : Subring R => s.toSubmonoid) | _, _, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toSubmonoid_strictMono : StrictMono (fun s : Subring R => s.toSubmonoid) := fun _ _ => id @[mono] theorem toSubmonoid_mono : Monotone (fun s : Subring R => s.toSubmonoid) := toSubmonoid_strictMono.monotone /-- Construct a `Subring R` from a set `s`, a submonoid `sm`, and an additive subgroup `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sm : Submonoid R) (sa : AddSubgroup R) (hm : ↑sm = s) (ha : ↑sa = s) : Subring R := { sm.copy s hm.symm, sa.copy s ha.symm with } @[simp] theorem coe_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (Subring.mk' s sm sa hm ha : Set R) = s := rfl @[simp] theorem mem_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) {x : R} : x ∈ Subring.mk' s sm sa hm ha ↔ x ∈ s := Iff.rfl @[simp] theorem mk'_toSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (Subring.mk' s sm sa hm ha).toSubmonoid = sm := SetLike.coe_injective hm.symm @[simp] theorem mk'_toAddSubgroup {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (Subring.mk' s sm sa hm ha).toAddSubgroup = sa := SetLike.coe_injective ha.symm end Subring /-- A `Subsemiring` containing -1 is a `Subring`. -/ def Subsemiring.toSubring (s : Subsemiring R) (hneg : (-1 : R) ∈ s) : Subring R where toSubsemiring := s neg_mem' h := by rw [← neg_one_mul] exact mul_mem hneg h namespace Subring variable (s : Subring R) /-- A subring contains the ring's 1. -/ protected theorem one_mem : (1 : R) ∈ s := one_mem _ /-- A subring contains the ring's 0. -/ protected theorem zero_mem : (0 : R) ∈ s := zero_mem _ /-- A subring is closed under multiplication. -/ protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem /-- A subring is closed under addition. -/ protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s := add_mem /-- A subring is closed under negation. -/ protected theorem neg_mem {x : R} : x ∈ s → -x ∈ s := neg_mem /-- A subring is closed under subtraction -/ protected theorem sub_mem {x y : R} (hx : x ∈ s) (hy : y ∈ s) : x - y ∈ s := sub_mem hx hy /-- Product of a list of elements in a subring is in the subring. -/ protected theorem list_prod_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s := list_prod_mem /-- Sum of a list of elements in a subring is in the subring. -/ protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem /-- Product of a multiset of elements in a subring of a `CommRing` is in the subring. -/ protected theorem multiset_prod_mem {R} [CommRing R] (s : Subring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.prod ∈ s := multiset_prod_mem _ /-- Sum of a multiset of elements in a `Subring` of a `Ring` is in the `Subring`. -/ protected theorem multiset_sum_mem {R} [Ring R] (s : Subring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem _ /-- Product of elements of a subring of a `CommRing` indexed by a `Finset` is in the subring. -/ protected theorem prod_mem {R : Type*} [CommRing R] (s : Subring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∏ i ∈ t, f i) ∈ s := prod_mem h /-- Sum of elements in a `Subring` of a `Ring` indexed by a `Finset` is in the `Subring`. -/ protected theorem sum_mem {R : Type*} [Ring R] (s : Subring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h /-- A subring of a ring inherits a ring structure -/ instance toRing : Ring s := SubringClass.toRing s protected theorem zsmul_mem {x : R} (hx : x ∈ s) (n : ℤ) : n • x ∈ s := zsmul_mem hx n protected theorem pow_mem {x : R} (hx : x ∈ s) (n : ℕ) : x ^ n ∈ s := pow_mem hx n @[simp, norm_cast] theorem coe_add (x y : s) : (↑(x + y) : R) = ↑x + ↑y := rfl @[simp, norm_cast] theorem coe_neg (x : s) : (↑(-x) : R) = -↑x := rfl @[simp, norm_cast] theorem coe_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y := rfl @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = 0 := rfl @[simp, norm_cast] theorem coe_one : ((1 : s) : R) = 1 := rfl @[simp, norm_cast] theorem coe_pow (x : s) (n : ℕ) : ↑(x ^ n) = (x : R) ^ n := SubmonoidClass.coe_pow x n -- TODO: can be generalized to `AddSubmonoidClass` -- @[simp] -- Porting note (#10618): simp can prove this theorem coe_eq_zero_iff {x : s} : (x : R) = 0 ↔ x = 0 := ⟨fun h => Subtype.ext (Trans.trans h s.coe_zero.symm), fun h => h.symm ▸ s.coe_zero⟩ /-- A subring of a `CommRing` is a `CommRing`. -/ instance toCommRing {R} [CommRing R] (s : Subring R) : CommRing s := SubringClass.toCommRing s /-- A subring of a non-trivial ring is non-trivial. -/ instance {R} [Ring R] [Nontrivial R] (s : Subring R) : Nontrivial s := s.toSubsemiring.nontrivial /-- A subring of a ring with no zero divisors has no zero divisors. -/ instance {R} [Ring R] [NoZeroDivisors R] (s : Subring R) : NoZeroDivisors s := s.toSubsemiring.noZeroDivisors /-- A subring of a domain is a domain. -/ instance {R} [Ring R] [IsDomain R] (s : Subring R) : IsDomain s := NoZeroDivisors.to_isDomain _ /-- The natural ring hom from a subring of ring `R` to `R`. -/ def subtype (s : Subring R) : s →+* R := { s.toSubmonoid.subtype, s.toAddSubgroup.subtype with toFun := (↑) } @[simp] theorem coeSubtype : ⇑s.subtype = ((↑) : s → R) := rfl @[norm_cast] -- Porting note (#10618): simp can prove this (removed `@[simp]`) theorem coe_natCast : ∀ n : ℕ, ((n : s) : R) = n := map_natCast s.subtype @[norm_cast] -- Porting note (#10618): simp can prove this (removed `@[simp]`) theorem coe_intCast : ∀ n : ℤ, ((n : s) : R) = n := map_intCast s.subtype /-! ## Partial order -/ @[simp] theorem coe_toSubsemiring (s : Subring R) : (s.toSubsemiring : Set R) = s := rfl @[simp, nolint simpNF] -- Porting note (#10675): dsimp can not prove this theorem mem_toSubmonoid {s : Subring R} {x : R} : x ∈ s.toSubmonoid ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toSubmonoid (s : Subring R) : (s.toSubmonoid : Set R) = s := rfl @[simp, nolint simpNF] -- Porting note (#10675): dsimp can not prove this theorem mem_toAddSubgroup {s : Subring R} {x : R} : x ∈ s.toAddSubgroup ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toAddSubgroup (s : Subring R) : (s.toAddSubgroup : Set R) = s := rfl /-! ## top -/ /-- The subring `R` of the ring `R`. -/ instance : Top (Subring R) := ⟨{ (⊤ : Submonoid R), (⊤ : AddSubgroup R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : Subring R) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : Subring R) : Set R) = Set.univ := rfl /-- The ring equiv between the top element of `Subring R` and `R`. -/ @[simps!] def topEquiv : (⊤ : Subring R) ≃+* R := Subsemiring.topEquiv theorem card_top (R) [Ring R] [Fintype R] : Fintype.card (⊤ : Subring R) = Fintype.card R := Fintype.card_congr topEquiv.toEquiv /-! ## comap -/ /-- The preimage of a subring along a ring homomorphism is a subring. -/ def comap {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring S) : Subring R := { s.toSubmonoid.comap (f : R →* S), s.toAddSubgroup.comap (f : R →+ S) with carrier := f ⁻¹' s.carrier } @[simp] theorem coe_comap (s : Subring S) (f : R →+* S) : (s.comap f : Set R) = f ⁻¹' s := rfl @[simp] theorem mem_comap {s : Subring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl theorem comap_comap (s : Subring T) (g : S →+* T) (f : R →+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl /-! ## map -/ /-- The image of a subring along a ring homomorphism is a subring. -/ def map {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring R) : Subring S := { s.toSubmonoid.map (f : R →* S), s.toAddSubgroup.map (f : R →+ S) with carrier := f '' s.carrier } @[simp] theorem coe_map (f : R →+* S) (s : Subring R) : (s.map f : Set S) = f '' s := rfl @[simp] theorem mem_map {f : R →+* S} {s : Subring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl @[simp] theorem map_id : s.map (RingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ theorem map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ theorem map_le_iff_le_comap {f : R →+* S} {s : Subring R} {t : Subring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff theorem gc_map_comap (f : R →+* S) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap /-- A subring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : R →+* S) (hf : Function.Injective f) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) map_add' := fun _ _ => Subtype.ext (f.map_add _ _) } @[simp] theorem coe_equivMapOfInjective_apply (f : R →+* S) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl end Subring namespace RingHom variable (g : S →+* T) (f : R →+* S) /-! ## range -/ /-- The range of a ring homomorphism, as a subring of the target. See Note [range copy pattern]. -/ def range {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) : Subring S := ((⊤ : Subring R).map f).copy (Set.range f) Set.image_univ.symm @[simp] theorem coe_range : (f.range : Set S) = Set.range f := rfl @[simp] theorem mem_range {f : R →+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y := Iff.rfl theorem range_eq_map (f : R →+* S) : f.range = Subring.map f ⊤ := by ext simp theorem mem_range_self (f : R →+* S) (x : R) : f x ∈ f.range := mem_range.mpr ⟨x, rfl⟩ theorem map_range : f.range.map g = (g.comp f).range := by simpa only [range_eq_map] using (⊤ : Subring R).map_map g f /-- The range of a ring homomorphism is a fintype, if the domain is a fintype. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype S`. -/ instance fintypeRange [Fintype R] [DecidableEq S] (f : R →+* S) : Fintype (range f) := Set.fintypeRange f end RingHom namespace Subring /-! ## bot -/ instance : Bot (Subring R) := ⟨(Int.castRingHom R).range⟩ instance : Inhabited (Subring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : Subring R) : Set R) = Set.range ((↑) : ℤ → R) := RingHom.coe_range (Int.castRingHom R) theorem mem_bot {x : R} : x ∈ (⊥ : Subring R) ↔ ∃ n : ℤ, ↑n = x := RingHom.mem_range /-! ## inf -/ /-- The inf of two subrings is their intersection. -/ instance : Inf (Subring R) := ⟨fun s t => { s.toSubmonoid ⊓ t.toSubmonoid, s.toAddSubgroup ⊓ t.toAddSubgroup with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : Subring R) : ((p ⊓ p' : Subring R) : Set R) = (p : Set R) ∩ p' := rfl @[simp] theorem mem_inf {p p' : Subring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance : InfSet (Subring R) := ⟨fun s => Subring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, t.toSubmonoid) (⨅ t ∈ s, Subring.toAddSubgroup t) (by simp) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (Subring R)) : ((sInf S : Subring R) : Set R) = ⋂ s ∈ S, ↑s := rfl theorem mem_sInf {S : Set (Subring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → Subring R} : (↑(⨅ i, S i) : Set R) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] theorem mem_iInf {ι : Sort*} {S : ι → Subring R} {x : R} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp] theorem sInf_toSubmonoid (s : Set (Subring R)) : (sInf s).toSubmonoid = ⨅ t ∈ s, t.toSubmonoid := mk'_toSubmonoid _ _ @[simp] theorem sInf_toAddSubgroup (s : Set (Subring R)) : (sInf s).toAddSubgroup = ⨅ t ∈ s, Subring.toAddSubgroup t := mk'_toAddSubgroup _ _ /-- Subrings of a ring form a complete lattice. -/ instance : CompleteLattice (Subring R) := { completeLatticeOfInf (Subring R) fun _ => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with bot := ⊥ bot_le := fun s _x hx => let ⟨n, hn⟩ := mem_bot.1 hx hn ▸ intCast_mem s n top := ⊤ le_top := fun _s _x _hx => trivial inf := (· ⊓ ·) inf_le_left := fun _s _t _x => And.left inf_le_right := fun _s _t _x => And.right le_inf := fun _s _t₁ _t₂ h₁ h₂ _x hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : Subring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ /-! ## Center of a ring -/ section variable (R) /-- The center of a ring `R` is the set of elements that commute with everything in `R` -/ def center : Subring R := { Subsemiring.center R with carrier := Set.center R neg_mem' := Set.neg_mem_center } theorem coe_center : ↑(center R) = Set.center R := rfl @[simp] theorem center_toSubsemiring : (center R).toSubsemiring = Subsemiring.center R := rfl variable {R} theorem mem_center_iff {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := Subsemigroup.mem_center_iff instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff @[simp] theorem center_eq_top (R) [CommRing R] : center R = ⊤ := SetLike.coe_injective (Set.center_eq_univ R) /-- The center is commutative. -/ instance : CommRing (center R) := { inferInstanceAs (CommSemiring (Subsemiring.center R)), (center R).toRing with } end section DivisionRing variable {K : Type u} [DivisionRing K] instance instField : Field (center K) where inv a := ⟨a⁻¹, Set.inv_mem_center a.prop⟩ mul_inv_cancel a ha := Subtype.ext <| mul_inv_cancel <| Subtype.coe_injective.ne ha div a b := ⟨a / b, Set.div_mem_center a.prop b.prop⟩ div_eq_mul_inv a b := Subtype.ext <| div_eq_mul_inv _ _ inv_zero := Subtype.ext inv_zero -- TODO: use a nicer defeq nnqsmul := _ nnqsmul_def := fun q a => rfl qsmul := _ qsmul_def := fun q x => rfl @[simp] theorem center.coe_inv (a : center K) : ((a⁻¹ : center K) : K) = (a : K)⁻¹ := rfl @[simp] theorem center.coe_div (a b : center K) : ((a / b : center K) : K) = (a : K) / (b : K) := rfl end DivisionRing section Centralizer /-- The centralizer of a set inside a ring as a `Subring`. -/ def centralizer (s : Set R) : Subring R := { Subsemiring.centralizer s with neg_mem' := Set.neg_mem_centralizer } @[simp, norm_cast] theorem coe_centralizer (s : Set R) : (centralizer s : Set R) = s.centralizer := rfl theorem centralizer_toSubmonoid (s : Set R) : (centralizer s).toSubmonoid = Submonoid.centralizer s := rfl theorem centralizer_toSubsemiring (s : Set R) : (centralizer s).toSubsemiring = Subsemiring.centralizer s := rfl theorem mem_centralizer_iff {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl theorem center_le_centralizer (s) : center R ≤ centralizer s := s.center_subset_centralizer theorem centralizer_le (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s := Set.centralizer_subset h @[simp] theorem centralizer_eq_top_iff_subset {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset @[simp] theorem centralizer_univ : centralizer Set.univ = center R := SetLike.ext' (Set.centralizer_univ R) end Centralizer /-! ## subring closure of a subset -/ /-- The `Subring` generated by a set. -/ def closure (s : Set R) : Subring R := sInf { S | s ⊆ S } theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : Subring R, s ⊆ S → x ∈ S := mem_sInf /-- The subring generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) /-- A subring `t` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : Subring R} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ /-- Subring closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure theorem closure_eq_of_le {s : Set R} {t : Subring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ /-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set R} {p : R → Prop} {x} (h : x ∈ closure s) (Hs : ∀ x ∈ s, p x) (zero : p 0) (one : p 1) (add : ∀ x y, p x → p y → p (x + y)) (neg : ∀ x : R, p x → p (-x)) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨⟨⟨⟨p, @mul⟩, one⟩, @add, zero⟩, @neg⟩).2 Hs h @[elab_as_elim] theorem closure_induction' {s : Set R} {p : ∀ x, x ∈ closure s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_closure h)) (zero : p 0 (zero_mem _)) (one : p 1 (one_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (neg : ∀ x hx, p x hx → p (-x) (neg_mem hx)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {a : R} (ha : a ∈ closure s) : p a ha := by refine Exists.elim ?_ fun (ha : a ∈ closure s) (hc : p a ha) => hc refine closure_induction ha (fun m hm => ⟨subset_closure hm, mem m hm⟩) ⟨zero_mem _, zero⟩ ⟨one_mem _, one⟩ ?_ (fun x hx => hx.elim fun hx' hx => ⟨neg_mem hx', neg _ _ hx⟩) ?_ · exact (fun x y hx hy => hx.elim fun hx' hx => hy.elim fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) · exact (fun x y hx hy => hx.elim fun hx' hx => hy.elim fun hy' hy => ⟨mul_mem hx' hy', mul _ _ _ _ hx hy⟩) /-- An induction principle for closure membership, for predicates with two arguments. -/ @[elab_as_elim] theorem closure_induction₂ {s : Set R} {p : R → R → Prop} {a b : R} (ha : a ∈ closure s) (hb : b ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ x, p 0 x) (H0_right : ∀ x, p x 0) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hneg_left : ∀ x y, p x y → p (-x) y) (Hneg_right : ∀ x y, p x y → p x (-y)) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p a b := by refine closure_induction hb ?_ (H0_right _) (H1_right _) (Hadd_right a) (Hneg_right a) (Hmul_right a) refine closure_induction ha Hs (fun x _ => H0_left x) (fun x _ => H1_left x) ?_ ?_ ?_ · exact fun x y H₁ H₂ z zs => Hadd_left x y z (H₁ z zs) (H₂ z zs) · exact fun x hx z zs => Hneg_left x z (hx z zs) · exact fun x y H₁ H₂ z zs => Hmul_left x y z (H₁ z zs) (H₂ z zs) theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubgroup.closure (Submonoid.closure s : Set R) := ⟨fun h => closure_induction h (fun x hx => AddSubgroup.subset_closure <| Submonoid.subset_closure hx) (AddSubgroup.zero_mem _) (AddSubgroup.subset_closure (Submonoid.one_mem (Submonoid.closure s))) (fun x y hx hy => AddSubgroup.add_mem _ hx hy) (fun x hx => AddSubgroup.neg_mem _ hx) fun x y hx hy => AddSubgroup.closure_induction hy (fun q hq => AddSubgroup.closure_induction hx (fun p hp => AddSubgroup.subset_closure ((Submonoid.closure s).mul_mem hp hq)) (by rw [zero_mul q]; apply AddSubgroup.zero_mem _) (fun p₁ p₂ ihp₁ ihp₂ => by rw [add_mul p₁ p₂ q]; apply AddSubgroup.add_mem _ ihp₁ ihp₂) fun x hx => by have f : -x * q = -(x * q) := by simp rw [f]; apply AddSubgroup.neg_mem _ hx) (by rw [mul_zero x]; apply AddSubgroup.zero_mem _) (fun q₁ q₂ ihq₁ ihq₂ => by rw [mul_add x q₁ q₂]; apply AddSubgroup.add_mem _ ihq₁ ihq₂) fun z hz => by have f : x * -z = -(x * z) := by simp rw [f]; apply AddSubgroup.neg_mem _ hz, fun h => AddSubgroup.closure_induction (p := (· ∈ closure s)) h (fun x hx => Submonoid.closure_induction hx (fun x hx => subset_closure hx) (one_mem _) fun x y hx hy => mul_mem hx hy) (zero_mem _) (fun x y hx hy => add_mem hx hy) fun x hx => neg_mem hx⟩ /-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/ def closureCommRingOfComm {s : Set R} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : CommRing (closure s) := { (closure s).toRing with mul_comm := fun x y => by ext simp only [Subring.coe_mul] refine closure_induction₂ x.prop y.prop hcomm (fun x => by simp only [mul_zero, zero_mul]) (fun x => by simp only [mul_zero, zero_mul]) (fun x => by simp only [mul_one, one_mul]) (fun x => by simp only [mul_one, one_mul]) (fun x y hxy => by simp only [mul_neg, neg_mul, hxy]) (fun x y hxy => by simp only [mul_neg, neg_mul, hxy]) (fun x₁ x₂ y h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun x₁ x₂ y h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun x₁ x₂ y h₁ h₂ => by rw [← mul_assoc, ← h₁, mul_assoc x₁ y x₂, ← h₂, mul_assoc]) fun x₁ x₂ y h₁ h₂ => by rw [← mul_assoc, h₁, mul_assoc, h₂, ← mul_assoc] } theorem exists_list_of_mem_closure {s : Set R} {x : R} (h : x ∈ closure s) : ∃ L : List (List R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s ∨ y = (-1 : R)) ∧ (L.map List.prod).sum = x := AddSubgroup.closure_induction (G := R) (p := (∃ L : List (List R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s ∨ y = -1) ∧ (L.map List.prod).sum = ·)) (mem_closure_iff.1 h) (fun x hx => let ⟨l, hl, h⟩ := Submonoid.exists_list_of_mem_closure hx ⟨[l], by simp [h]; clear_aux_decl; tauto⟩) ⟨[], by simp⟩ (fun x y ⟨l, hl1, hl2⟩ ⟨m, hm1, hm2⟩ => ⟨l ++ m, fun t ht => (List.mem_append.1 ht).elim (hl1 t) (hm1 t), by simp [hl2, hm2]⟩) fun x ⟨L, hL⟩ => ⟨L.map (List.cons (-1)), List.forall_mem_map.2 fun j hj => List.forall_mem_cons.2 ⟨Or.inr rfl, hL.1 j hj⟩, hL.2 ▸ List.recOn L (by simp) (by simp (config := { contextual := true }) [List.map_cons, add_comm])⟩ variable (R) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure R _) (↑) where choice s _ := closure s gc _s _t := closure_le le_l_u _s := subset_closure choice_eq _s _h := rfl variable {R} /-- Closure of a subring `S` equals `S`. -/ theorem closure_eq (s : Subring R) : closure (s : Set R) = s := (Subring.gi R).l_u_eq s @[simp] theorem closure_empty : closure (∅ : Set R) = ⊥ := (Subring.gi R).gc.l_bot @[simp] theorem closure_univ : closure (Set.univ : Set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤ theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t := (Subring.gi R).gc.l_sup theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subring.gi R).gc.l_iSup theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (Subring.gi R).gc.l_sSup theorem map_sup (s t : Subring R) (f : R →+* S) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : R →+* S) (s : ι → Subring R) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem comap_inf (s t : Subring S) (f : R →+* S) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f := (gc_map_comap f).u_inf theorem comap_iInf {ι : Sort*} (f : R →+* S) (s : ι → Subring S) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf @[simp] theorem map_bot (f : R →+* S) : (⊥ : Subring R).map f = ⊥ := (gc_map_comap f).l_bot @[simp] theorem comap_top (f : R →+* S) : (⊤ : Subring S).comap f = ⊤ := (gc_map_comap f).u_top /-- Given `Subring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s ×̂ t` as a subring of `R × S`. -/ def prod (s : Subring R) (t : Subring S) : Subring (R × S) := { s.toSubmonoid.prod t.toSubmonoid, s.toAddSubgroup.prod t.toAddSubgroup with carrier := s ×ˢ t } @[norm_cast] theorem coe_prod (s : Subring R) (t : Subring S) : (s.prod t : Set (R × S)) = (s : Set R) ×ˢ (t : Set S) := rfl theorem mem_prod {s : Subring R} {t : Subring S} {p : R × S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl @[mono] theorem prod_mono ⦃s₁ s₂ : Subring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : Subring S⦄ (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht theorem prod_mono_right (s : Subring R) : Monotone fun t : Subring S => s.prod t := prod_mono (le_refl s) theorem prod_mono_left (t : Subring S) : Monotone fun s : Subring R => s.prod t := fun _ _ hs => prod_mono hs (le_refl t) theorem prod_top (s : Subring R) : s.prod (⊤ : Subring S) = s.comap (RingHom.fst R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] theorem top_prod (s : Subring S) : (⊤ : Subring R).prod s = s.comap (RingHom.snd R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[simp] theorem top_prod_top : (⊤ : Subring R).prod (⊤ : Subring S) = ⊤ := (top_prod _).trans <| comap_top _ /-- Product of subrings is isomorphic to their product as rings. -/ def prodEquiv (s : Subring R) (t : Subring S) : s.prod t ≃+* s × t := { Equiv.Set.prod (s : Set R) (t : Set S) with map_mul' := fun _x _y => rfl map_add' := fun _x _y => rfl } /-- The underlying set of a non-empty directed sSup of subrings is just a union of the subrings. Note that this fails without the directedness assumption (the union of two subrings is typically not a subring) -/ theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subring R} (hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ let U : Subring R := Subring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubmonoid) (⨆ i, (S i).toAddSubgroup) (Submonoid.coe_iSup_of_directed hS) (AddSubgroup.coe_iSup_of_directed hS) suffices ⨆ i, S i ≤ U by simpa [U] using @this x exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩ theorem coe_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subring R} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Subring R) : Set R) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] theorem mem_sSup_of_directedOn {S : Set (Subring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) {x : R} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] theorem coe_sSup_of_directedOn {S : Set (Subring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] theorem mem_map_equiv {f : R ≃+* S} {K : Subring R} {x : S} : x ∈ K.map (f : R →+* S) ↔ f.symm x ∈ K := @Set.mem_image_equiv _ _ (K : Set R) f.toEquiv x theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : Subring R) : K.map (f : R →+* S) = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : Subring S) : K.comap (f : R →+* S) = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm end Subring namespace RingHom variable {s : Subring R} open Subring /-- Restriction of a ring homomorphism to its range interpreted as a subsemiring. This is the bundled version of `Set.rangeFactorization`. -/ def rangeRestrict (f : R →+* S) : R →+* f.range := f.codRestrict f.range fun x => ⟨x, rfl⟩ @[simp] theorem coe_rangeRestrict (f : R →+* S) (x : R) : (f.rangeRestrict x : S) = f x := rfl theorem rangeRestrict_surjective (f : R →+* S) : Function.Surjective f.rangeRestrict := fun ⟨_y, hy⟩ => let ⟨x, hx⟩ := mem_range.mp hy ⟨x, Subtype.ext hx⟩ theorem range_top_iff_surjective {f : R →+* S} : f.range = (⊤ : Subring S) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_iff_surjective /-- The range of a surjective ring homomorphism is the whole of the codomain. -/ @[simp] theorem range_top_of_surjective (f : R →+* S) (hf : Function.Surjective f) : f.range = (⊤ : Subring S) := range_top_iff_surjective.2 hf section eqLocus variable {S : Type v} [Semiring S] /-- The subring of elements `x : R` such that `f x = g x`, i.e., the equalizer of f and g as a subring of R -/ def eqLocus (f g : R →+* S) : Subring R := { (f : R →* S).eqLocusM g, (f : R →+ S).eqLocus g with carrier := { x | f x = g x } } @[simp] theorem eqLocus_same (f : R →+* S) : f.eqLocus f = ⊤ := SetLike.ext fun _ => eq_self_iff_true _ /-- If two ring homomorphisms are equal on a set, then they are equal on its subring closure. -/ theorem eqOn_set_closure {f g : R →+* S} {s : Set R} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) := show closure s ≤ f.eqLocus g from closure_le.2 h theorem eq_of_eqOn_set_top {f g : R →+* S} (h : Set.EqOn f g (⊤ : Subring R)) : f = g := ext fun _x => h trivial theorem eq_of_eqOn_set_dense {s : Set R} (hs : closure s = ⊤) {f g : R →+* S} (h : s.EqOn f g) : f = g := eq_of_eqOn_set_top <| hs ▸ eqOn_set_closure h end eqLocus theorem closure_preimage_le (f : R →+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a ring homomorphism of the subring generated by a set equals the subring generated by the image of the set. -/ theorem map_closure (f : R →+* S) (s : Set R) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 <| le_trans (closure_mono <| Set.subset_preimage_image _ _) (closure_preimage_le _ _)) (closure_le.2 <| Set.image_subset _ subset_closure) end RingHom namespace Subring open RingHom /-- The ring homomorphism associated to an inclusion of subrings. -/ def inclusion {S T : Subring R} (h : S ≤ T) : S →+* T := S.subtype.codRestrict _ fun x => h x.2 @[simp] theorem range_subtype (s : Subring R) : s.subtype.range = s := SetLike.coe_injective <| (coe_rangeS _).trans Subtype.range_coe -- @[simp] -- Porting note (#10618): simp can prove this theorem range_fst : (fst R S).rangeS = ⊤ := (fst R S).rangeS_top_of_surjective <| Prod.fst_surjective -- @[simp] -- Porting note (#10618): simp can prove this theorem range_snd : (snd R S).rangeS = ⊤ := (snd R S).rangeS_top_of_surjective <| Prod.snd_surjective @[simp] theorem prod_bot_sup_bot_prod (s : Subring R) (t : Subring S) : s.prod ⊥ ⊔ prod ⊥ t = s.prod t := le_antisymm (sup_le (prod_mono_right s bot_le) (prod_mono_left t bot_le)) fun p hp => Prod.fst_mul_snd p ▸ mul_mem ((le_sup_left : s.prod ⊥ ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨hp.1, SetLike.mem_coe.2 <| one_mem ⊥⟩) ((le_sup_right : prod ⊥ t ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨SetLike.mem_coe.2 <| one_mem ⊥, hp.2⟩) end Subring namespace RingEquiv variable {s t : Subring R} /-- Makes the identity isomorphism from a proof two subrings of a multiplicative monoid are equal. -/ def subringCongr (h : s = t) : s ≃+* t := { Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } /-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its `RingHom.range`. -/ def ofLeftInverse {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) : R ≃+* f.range := { f.rangeRestrict with toFun := fun x => f.rangeRestrict x invFun := fun x => (g ∘ f.range.subtype) x left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := RingHom.mem_range.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse_apply {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) (x : R) : ↑(ofLeftInverse h x) = f x := rfl @[simp] theorem ofLeftInverse_symm_apply {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) (x : f.range) : (ofLeftInverse h).symm x = g x := rfl /-- Given an equivalence `e : R ≃+* S` of rings and a subring `s` of `R`, `subringMap e s` is the induced equivalence between `s` and `s.map e` -/ @[simps!] def subringMap (e : R ≃+* S) : s ≃+* s.map e.toRingHom := e.subsemiringMap s.toSubsemiring -- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing attribute [nolint simpNF] RingEquiv.subringMap_symm_apply_coe RingEquiv.subringMap_apply_coe end RingEquiv namespace Subring variable {s : Set R} -- attribute [local reducible] closure -- Porting note: not available in Lean4 @[elab_as_elim] protected theorem InClosure.recOn {C : R → Prop} {x : R} (hx : x ∈ closure s) (h1 : C 1) (hneg1 : C (-1)) (hs : ∀ z ∈ s, ∀ n, C n → C (z * n)) (ha : ∀ {x y}, C x → C y → C (x + y)) : C x := by have h0 : C 0 := add_neg_self (1 : R) ▸ ha h1 hneg1 rcases exists_list_of_mem_closure hx with ⟨L, HL, rfl⟩ clear hx induction' L with hd tl ih · exact h0 rw [List.forall_mem_cons] at HL suffices C (List.prod hd) by rw [List.map_cons, List.sum_cons] exact ha this (ih HL.2) replace HL := HL.1 clear ih tl rsuffices ⟨L, HL', HP | HP⟩ : ∃ L : List R, (∀ x ∈ L, x ∈ s) ∧ (List.prod hd = List.prod L ∨ List.prod hd = -List.prod L) · rw [HP] clear HP HL hd induction' L with hd tl ih · exact h1 rw [List.forall_mem_cons] at HL' rw [List.prod_cons] exact hs _ HL'.1 _ (ih HL'.2) · rw [HP] clear HP HL hd induction' L with hd tl ih · exact hneg1 rw [List.prod_cons, neg_mul_eq_mul_neg] rw [List.forall_mem_cons] at HL' exact hs _ HL'.1 _ (ih HL'.2) induction' hd with hd tl ih · exact ⟨[], List.forall_mem_nil _, Or.inl rfl⟩ rw [List.forall_mem_cons] at HL rcases ih HL.2 with ⟨L, HL', HP | HP⟩ <;> cases' HL.1 with hhd hhd · exact ⟨hd::L, List.forall_mem_cons.2 ⟨hhd, HL'⟩, Or.inl <| by rw [List.prod_cons, List.prod_cons, HP]⟩ · exact ⟨L, HL', Or.inr <| by rw [List.prod_cons, hhd, neg_one_mul, HP]⟩ · exact ⟨hd::L, List.forall_mem_cons.2 ⟨hhd, HL'⟩, Or.inr <| by rw [List.prod_cons, List.prod_cons, HP, neg_mul_eq_mul_neg]⟩ · exact ⟨L, HL', Or.inl <| by rw [List.prod_cons, hhd, HP, neg_one_mul, neg_neg]⟩ theorem closure_preimage_le (f : R →+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx end Subring theorem AddSubgroup.int_mul_mem {G : AddSubgroup R} (k : ℤ) {g : R} (h : g ∈ G) : (k : R) * g ∈ G := by convert AddSubgroup.zsmul_mem G h k using 1 simp /-! ## Actions by `Subring`s These are just copies of the definitions about `Subsemiring` starting from `Subsemiring.MulAction`. When `R` is commutative, `Algebra.ofSubring` provides a stronger result than those found in this file, which uses the same scalar action. -/ section Actions namespace Subring variable {α β : Type*} -- Porting note: Lean can find this instance already /-- The action by a subring is the action by the underlying ring. -/ instance [SMul R α] (S : Subring R) : SMul S α := inferInstanceAs (SMul S.toSubsemiring α) theorem smul_def [SMul R α] {S : Subring R} (g : S) (m : α) : g • m = (g : R) • m := rfl -- Porting note: Lean can find this instance already instance smulCommClass_left [SMul R β] [SMul α β] [SMulCommClass R α β] (S : Subring R) : SMulCommClass S α β := inferInstanceAs (SMulCommClass S.toSubsemiring α β) -- Porting note: Lean can find this instance already instance smulCommClass_right [SMul α β] [SMul R β] [SMulCommClass α R β] (S : Subring R) : SMulCommClass α S β := inferInstanceAs (SMulCommClass α S.toSubsemiring β) -- Porting note: Lean can find this instance already /-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/ instance [SMul α β] [SMul R α] [SMul R β] [IsScalarTower R α β] (S : Subring R) : IsScalarTower S α β := inferInstanceAs (IsScalarTower S.toSubsemiring α β) -- Porting note: Lean can find this instance already instance [SMul R α] [FaithfulSMul R α] (S : Subring R) : FaithfulSMul S α := inferInstanceAs (FaithfulSMul S.toSubsemiring α) -- Porting note: Lean can find this instance already /-- The action by a subring is the action by the underlying ring. -/ instance [MulAction R α] (S : Subring R) : MulAction S α := inferInstanceAs (MulAction S.toSubsemiring α) -- Porting note: Lean can find this instance already /-- The action by a subring is the action by the underlying ring. -/ instance [AddMonoid α] [DistribMulAction R α] (S : Subring R) : DistribMulAction S α := inferInstanceAs (DistribMulAction S.toSubsemiring α) -- Porting note: Lean can find this instance already /-- The action by a subring is the action by the underlying ring. -/ instance [Monoid α] [MulDistribMulAction R α] (S : Subring R) : MulDistribMulAction S α := inferInstanceAs (MulDistribMulAction S.toSubsemiring α) -- Porting note: Lean can find this instance already /-- The action by a subring is the action by the underlying ring. -/ instance [Zero α] [SMulWithZero R α] (S : Subring R) : SMulWithZero S α := inferInstanceAs (SMulWithZero S.toSubsemiring α) /-- The action by a subring is the action by the underlying ring. -/ instance [Zero α] [MulActionWithZero R α] (S : Subring R) : MulActionWithZero S α := -- inferInstanceAs (MulActionWithZero S.toSubsemiring α) -- Porting note: does not work Subsemiring.mulActionWithZero S.toSubsemiring /-- The action by a subring is the action by the underlying ring. -/ instance [AddCommMonoid α] [Module R α] (S : Subring R) : Module S α := -- inferInstanceAs (Module S.toSubsemiring α) -- Porting note: does not work Subsemiring.module S.toSubsemiring -- Porting note: Lean can find this instance already /-- The action by a subsemiring is the action by the underlying ring. -/ instance [Semiring α] [MulSemiringAction R α] (S : Subring R) : MulSemiringAction S α := inferInstanceAs (MulSemiringAction S.toSubmonoid α) /-- The center of a semiring acts commutatively on that semiring. -/ instance center.smulCommClass_left : SMulCommClass (center R) R R := Subsemiring.center.smulCommClass_left /-- The center of a semiring acts commutatively on that semiring. -/ instance center.smulCommClass_right : SMulCommClass R (center R) R := Subsemiring.center.smulCommClass_right end Subring end Actions namespace Subring theorem map_comap_eq (f : R →+* S) (t : Subring S) : (t.comap f).map f = t ⊓ f.range := SetLike.coe_injective Set.image_preimage_eq_inter_range theorem map_comap_eq_self {f : R →+* S} {t : Subring S} (h : t ≤ f.range) : (t.comap f).map f = t := by simpa only [inf_of_le_left h] using Subring.map_comap_eq f t theorem map_comap_eq_self_of_surjective {f : R →+* S} (hf : Function.Surjective f) (t : Subring S) : (t.comap f).map f = t := map_comap_eq_self <| by simp [hf] theorem comap_map_eq (f : R →+* S) (s : Subring R) : (s.map f).comap f = s ⊔ closure (f ⁻¹' {0}) := by apply le_antisymm · intro x hx rw [mem_comap, mem_map] at hx obtain ⟨y, hy, hxy⟩ := hx replace hxy : x - y ∈ f ⁻¹' {0} := by simp [hxy] rw [← closure_eq s, ← closure_union, ← add_sub_cancel y x] exact Subring.add_mem _ (subset_closure <| Or.inl hy) (subset_closure <| Or.inr hxy) · rw [← map_le_iff_le_comap, map_sup, f.map_closure] apply le_of_eq rw [sup_eq_left, closure_le] exact (Set.image_preimage_subset f {0}).trans (Set.singleton_subset_iff.2 (s.map f).zero_mem) theorem comap_map_eq_self {f : R →+* S} {s : Subring R} (h : f ⁻¹' {0} ⊆ s) : (s.map f).comap f = s := by convert comap_map_eq f s rwa [left_eq_sup, closure_le] theorem comap_map_eq_self_of_injective {f : R →+* S} (hf : Function.Injective f) (s : Subring R) : (s.map f).comap f = s := SetLike.coe_injective (Set.preimage_image_eq _ hf) end Subring
Algebra\Ring\Subring\MulOpposite.lean
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.Algebra.Ring.Subsemiring.MulOpposite import Mathlib.Algebra.Ring.Subring.Basic /-! # Subring of opposite rings For every ring `R`, we construct an equivalence between subrings of `R` and that of `Rᵐᵒᵖ`. -/ namespace Subring variable {ι : Sort*} {R : Type*} [Ring R] /-- Pull a subring back to an opposite subring along `MulOpposite.unop` -/ @[simps toSubsemiring] protected def op (S : Subring R) : Subring Rᵐᵒᵖ where toSubsemiring := S.toSubsemiring.op neg_mem' {x} hx := neg_mem (show x.unop ∈ S from hx) @[simp, norm_cast] theorem op_coe (S : Subring R) : S.op = MulOpposite.unop ⁻¹' (S : Set R) := rfl @[simp] theorem mem_op {x : Rᵐᵒᵖ} {S : Subring R} : x ∈ S.op ↔ x.unop ∈ S := Iff.rfl /-- Pull an opposite subring back to a subring along `MulOpposite.op` -/ @[simps toSubsemiring] protected def unop (S : Subring Rᵐᵒᵖ) : Subring R where toSubsemiring := S.toSubsemiring.unop neg_mem' {x} hx := neg_mem (show MulOpposite.op x ∈ S from hx) @[simp, norm_cast] theorem unop_coe (S : Subring Rᵐᵒᵖ) : S.unop = MulOpposite.op ⁻¹' (S : Set Rᵐᵒᵖ) := rfl @[simp] theorem mem_unop {x : R} {S : Subring Rᵐᵒᵖ} : x ∈ S.unop ↔ MulOpposite.op x ∈ S := Iff.rfl @[simp] theorem unop_op (S : Subring R) : S.op.unop = S := rfl @[simp] theorem op_unop (S : Subring Rᵐᵒᵖ) : S.unop.op = S := rfl /-! ### Lattice results -/ theorem op_le_iff {S₁ : Subring R} {S₂ : Subring Rᵐᵒᵖ} : S₁.op ≤ S₂ ↔ S₁ ≤ S₂.unop := MulOpposite.op_surjective.forall theorem le_op_iff {S₁ : Subring Rᵐᵒᵖ} {S₂ : Subring R} : S₁ ≤ S₂.op ↔ S₁.unop ≤ S₂ := MulOpposite.op_surjective.forall @[simp] theorem op_le_op_iff {S₁ S₂ : Subring R} : S₁.op ≤ S₂.op ↔ S₁ ≤ S₂ := MulOpposite.op_surjective.forall @[simp] theorem unop_le_unop_iff {S₁ S₂ : Subring Rᵐᵒᵖ} : S₁.unop ≤ S₂.unop ↔ S₁ ≤ S₂ := MulOpposite.unop_surjective.forall /-- A subring `S` of `R` determines a subring `S.op` of the opposite ring `Rᵐᵒᵖ`. -/ @[simps] def opEquiv : Subring R ≃o Subring Rᵐᵒᵖ where toFun := Subring.op invFun := Subring.unop left_inv := unop_op right_inv := op_unop map_rel_iff' := op_le_op_iff @[simp] theorem op_bot : (⊥ : Subring R).op = ⊥ := opEquiv.map_bot @[simp] theorem unop_bot : (⊥ : Subring Rᵐᵒᵖ).unop = ⊥ := opEquiv.symm.map_bot @[simp] theorem op_top : (⊤ : Subring R).op = ⊤ := opEquiv.map_top @[simp] theorem unop_top : (⊤ : Subring Rᵐᵒᵖ).unop = ⊤ := opEquiv.symm.map_top theorem op_sup (S₁ S₂ : Subring R) : (S₁ ⊔ S₂).op = S₁.op ⊔ S₂.op := opEquiv.map_sup _ _ theorem unop_sup (S₁ S₂ : Subring Rᵐᵒᵖ) : (S₁ ⊔ S₂).unop = S₁.unop ⊔ S₂.unop := opEquiv.symm.map_sup _ _ theorem op_inf (S₁ S₂ : Subring R) : (S₁ ⊓ S₂).op = S₁.op ⊓ S₂.op := opEquiv.map_inf _ _ theorem unop_inf (S₁ S₂ : Subring Rᵐᵒᵖ) : (S₁ ⊓ S₂).unop = S₁.unop ⊓ S₂.unop := opEquiv.symm.map_inf _ _ theorem op_sSup (S : Set (Subring R)) : (sSup S).op = sSup (.unop ⁻¹' S) := opEquiv.map_sSup_eq_sSup_symm_preimage _ theorem unop_sSup (S : Set (Subring Rᵐᵒᵖ)) : (sSup S).unop = sSup (.op ⁻¹' S) := opEquiv.symm.map_sSup_eq_sSup_symm_preimage _ theorem op_sInf (S : Set (Subring R)) : (sInf S).op = sInf (.unop ⁻¹' S) := opEquiv.map_sInf_eq_sInf_symm_preimage _ theorem unop_sInf (S : Set (Subring Rᵐᵒᵖ)) : (sInf S).unop = sInf (.op ⁻¹' S) := opEquiv.symm.map_sInf_eq_sInf_symm_preimage _ theorem op_iSup (S : ι → Subring R) : (iSup S).op = ⨆ i, (S i).op := opEquiv.map_iSup _ theorem unop_iSup (S : ι → Subring Rᵐᵒᵖ) : (iSup S).unop = ⨆ i, (S i).unop := opEquiv.symm.map_iSup _ theorem op_iInf (S : ι → Subring R) : (iInf S).op = ⨅ i, (S i).op := opEquiv.map_iInf _ theorem unop_iInf (S : ι → Subring Rᵐᵒᵖ) : (iInf S).unop = ⨅ i, (S i).unop := opEquiv.symm.map_iInf _ theorem op_closure (s : Set R) : (closure s).op = closure (MulOpposite.unop ⁻¹' s) := by simp_rw [closure, op_sInf, Set.preimage_setOf_eq, unop_coe] congr with a exact MulOpposite.unop_surjective.forall theorem unop_closure (s : Set Rᵐᵒᵖ) : (closure s).unop = closure (MulOpposite.op ⁻¹' s) := by simp_rw [closure, unop_sInf, Set.preimage_setOf_eq, op_coe] congr with a exact MulOpposite.op_surjective.forall /-- Bijection between a subring `S` and its opposite. -/ @[simps!] def addEquivOp (S : Subring R) : S ≃+ S.op := S.toSubsemiring.addEquivOp /-- Bijection between a subring `S` and `MulOpposite` of its opposite. -/ @[simps!] def ringEquivOpMop (S : Subring R) : S ≃+* (S.op)ᵐᵒᵖ := S.toSubsemiring.ringEquivOpMop /-- Bijection between `MulOpposite` of a subring `S` and its opposite. -/ @[simps!] def mopRingEquivOp (S : Subring R) : Sᵐᵒᵖ ≃+* S.op := S.toSubsemiring.mopRingEquivOp end Subring
Algebra\Ring\Subring\Order.lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.Algebra.Order.Hom.Ring import Mathlib.Algebra.Order.Ring.InjSurj /-! # Subrings of ordered rings We study subrings of ordered rings and prove their basic properties. ## Main definitions and results * `Subring.orderedSubtype`: the inclusion `S → R` of a subring as an ordered ring homomorphism * various ordered instances: a subring of an `OrderedRing`, `OrderedCommRing`, `LinearOrderedRing`, `toLinearOrderedCommRing` is again an ordering ring -/ namespace SubringClass variable {R S : Type*} [SetLike S R] (s : S) -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of an `OrderedRing` is an `OrderedRing`. -/ instance (priority := 75) toOrderedRing [OrderedRing R] [SubringClass S R] : OrderedRing s := Subtype.coe_injective.orderedRing (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of an `OrderedCommRing` is an `OrderedCommRing`. -/ instance (priority := 75) toOrderedCommRing [OrderedCommRing R] [SubringClass S R] : OrderedCommRing s := Subtype.coe_injective.orderedCommRing (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a `LinearOrderedRing` is a `LinearOrderedRing`. -/ instance (priority := 75) toLinearOrderedRing [LinearOrderedRing R] [SubringClass S R] : LinearOrderedRing s := Subtype.coe_injective.linearOrderedRing (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) (fun _ _ => rfl) fun _ _ => rfl -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a `LinearOrderedCommRing` is a `LinearOrderedCommRing`. -/ instance (priority := 75) toLinearOrderedCommRing [LinearOrderedCommRing R] [SubringClass S R] : LinearOrderedCommRing s := Subtype.coe_injective.linearOrderedCommRing (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) (fun _ _ => rfl) fun _ _ => rfl end SubringClass namespace Subring variable {R : Type*} /-- A subring of an `OrderedRing` is an `OrderedRing`. -/ instance toOrderedRing [OrderedRing R] (s : Subring R) : OrderedRing s := SubringClass.toOrderedRing s /-- A subring of an `OrderedCommRing` is an `OrderedCommRing`. -/ instance toOrderedCommRing [OrderedCommRing R] (s : Subring R) : OrderedCommRing s := SubringClass.toOrderedCommRing s /-- A subring of a `LinearOrderedRing` is a `LinearOrderedRing`. -/ instance toLinearOrderedRing [LinearOrderedRing R] (s : Subring R) : LinearOrderedRing s := SubringClass.toLinearOrderedRing s /-- A subring of a `LinearOrderedCommRing` is a `LinearOrderedCommRing`. -/ instance toLinearOrderedCommRing [LinearOrderedCommRing R] (s : Subring R) : LinearOrderedCommRing s := SubringClass.toLinearOrderedCommRing s /-- The inclusion `S → R` of a subring, as an ordered ring homomorphism. -/ def orderedSubtype {R : Type*} [OrderedRing R] (s : Subring R) : s →+*o R where __ := s.subtype monotone' := fun _ _ h ↦ h variable {R : Type*} [OrderedRing R] lemma orderedSubtype_coe (s : Subring R) : Subring.orderedSubtype s = Subring.subtype s := rfl end Subring
Algebra\Ring\Subring\Pointwise.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.Algebra.Ring.Subsemiring.Pointwise import Mathlib.Data.Set.Pointwise.Basic /-! # Pointwise instances on `Subring`s This file provides the action `Subring.pointwiseMulAction` which matches the action of `mulActionSet`. This actions is available in the `Pointwise` locale. ## Implementation notes This file is almost identical to the file `Mathlib.Algebra.Ring.Subsemiring.Pointwise`. Where possible, try to keep them in sync. -/ open Set variable {M R : Type*} namespace Subring section Monoid variable [Monoid M] [Ring R] [MulSemiringAction M R] /-- The action on a subring corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction M (Subring R) where smul a S := S.map (MulSemiringAction.toRingHom _ _ a) one_smul S := (congr_arg (fun f => S.map f) (RingHom.ext <| one_smul M)).trans S.map_id mul_smul _ _ S := (congr_arg (fun f => S.map f) (RingHom.ext <| mul_smul _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] Subring.pointwiseMulAction open Pointwise theorem pointwise_smul_def {a : M} (S : Subring R) : a • S = S.map (MulSemiringAction.toRingHom _ _ a) := rfl @[simp] theorem coe_pointwise_smul (m : M) (S : Subring R) : ↑(m • S) = m • (S : Set R) := rfl @[simp] theorem pointwise_smul_toAddSubgroup (m : M) (S : Subring R) : (m • S).toAddSubgroup = m • S.toAddSubgroup := rfl @[simp] theorem pointwise_smul_toSubsemiring (m : M) (S : Subring R) : (m • S).toSubsemiring = m • S.toSubsemiring := rfl theorem smul_mem_pointwise_smul (m : M) (r : R) (S : Subring R) : r ∈ S → m • r ∈ m • S := (Set.smul_mem_smul_set : _ → _ ∈ m • (S : Set R)) instance : CovariantClass M (Subring R) HSMul.hSMul LE.le := ⟨fun _ _ => image_subset _⟩ theorem mem_smul_pointwise_iff_exists (m : M) (r : R) (S : Subring R) : r ∈ m • S ↔ ∃ s : R, s ∈ S ∧ m • s = r := (Set.mem_smul_set : r ∈ m • (S : Set R) ↔ _) @[simp] theorem smul_bot (a : M) : a • (⊥ : Subring R) = ⊥ := map_bot _ theorem smul_sup (a : M) (S T : Subring R) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ theorem smul_closure (a : M) (s : Set R) : a • closure s = closure (a • s) := RingHom.map_closure _ _ instance pointwise_central_scalar [MulSemiringAction Mᵐᵒᵖ R] [IsCentralScalar M R] : IsCentralScalar M (Subring R) := ⟨fun _ S => (congr_arg fun f => S.map f) <| RingHom.ext <| op_smul_eq_smul _⟩ end Monoid section Group variable [Group M] [Ring R] [MulSemiringAction M R] open Pointwise @[simp] theorem smul_mem_pointwise_smul_iff {a : M} {S : Subring R} {x : R} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : M} {S : Subring R} {x : R} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : M} {S : Subring R} {x : R} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : M} {S T : Subring R} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff theorem pointwise_smul_subset_iff {a : M} {S T : Subring R} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff theorem subset_pointwise_smul_iff {a : M} {S T : Subring R} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff /-! TODO: add `equivSMul` like we have for subgroup. -/ end Group section GroupWithZero variable [GroupWithZero M] [Ring R] [MulSemiringAction M R] open Pointwise @[simp] theorem smul_mem_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) (S : Subring R) (x : R) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set R) x theorem mem_pointwise_smul_iff_inv_smul_mem₀ {a : M} (ha : a ≠ 0) (S : Subring R) (x : R) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set R) x theorem mem_inv_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) (S : Subring R) (x : R) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set R) x @[simp] theorem pointwise_smul_le_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) {S T : Subring R} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha theorem pointwise_smul_le_iff₀ {a : M} (ha : a ≠ 0) {S T : Subring R} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha theorem le_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) {S T : Subring R} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end GroupWithZero end Subring
Algebra\Ring\Subring\Units.lean
/- Copyright (c) 2021 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Order.Monoid.Submonoid import Mathlib.Algebra.Order.Ring.Defs /-! # Unit subgroups of a ring -/ /-- The subgroup of positive units of a linear ordered semiring. -/ def Units.posSubgroup (R : Type*) [LinearOrderedSemiring R] : Subgroup Rˣ := { (Submonoid.pos R).comap (Units.coeHom R) with carrier := { x | (0 : R) < x } inv_mem' := Units.inv_pos.mpr } @[simp] theorem Units.mem_posSubgroup {R : Type*} [LinearOrderedSemiring R] (u : Rˣ) : u ∈ Units.posSubgroup R ↔ (0 : R) < u := Iff.rfl
Algebra\Ring\Subsemiring\Basic.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Ring.Action.Subobjects import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Prod import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.Submonoid.Centralizer import Mathlib.RingTheory.NonUnitalSubsemiring.Basic /-! # Bundled subsemirings We define bundled subsemirings and some standard constructions: `CompleteLattice` structure, `Subtype` and `inclusion` ring homomorphisms, subsemiring `map`, `comap` and range (`rangeS`) of a `RingHom` etc. -/ universe u v w section AddSubmonoidWithOneClass /-- `AddSubmonoidWithOneClass S R` says `S` is a type of subsets `s ≤ R` that contain `0`, `1`, and are closed under `(+)` -/ class AddSubmonoidWithOneClass (S R : Type*) [AddMonoidWithOne R] [SetLike S R] extends AddSubmonoidClass S R, OneMemClass S R : Prop variable {S R : Type*} [AddMonoidWithOne R] [SetLike S R] (s : S) @[aesop safe apply (rule_sets := [SetLike])] theorem natCast_mem [AddSubmonoidWithOneClass S R] (n : ℕ) : (n : R) ∈ s := by induction n <;> simp [zero_mem, add_mem, one_mem, *] @[deprecated (since := "2024-04-05")] alias coe_nat_mem := natCast_mem @[aesop safe apply (rule_sets := [SetLike])] lemma ofNat_mem [AddSubmonoidWithOneClass S R] (s : S) (n : ℕ) [n.AtLeastTwo] : no_index (OfNat.ofNat n) ∈ s := by rw [← Nat.cast_eq_ofNat]; exact natCast_mem s n instance (priority := 74) AddSubmonoidWithOneClass.toAddMonoidWithOne [AddSubmonoidWithOneClass S R] : AddMonoidWithOne s := { AddSubmonoidClass.toAddMonoid s with one := ⟨_, one_mem s⟩ natCast := fun n => ⟨n, natCast_mem s n⟩ natCast_zero := Subtype.ext Nat.cast_zero natCast_succ := fun _ => Subtype.ext (Nat.cast_succ _) } end AddSubmonoidWithOneClass variable {R : Type u} {S : Type v} {T : Type w} [NonAssocSemiring R] (M : Submonoid R) section SubsemiringClass /-- `SubsemiringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both a multiplicative and an additive submonoid. -/ class SubsemiringClass (S : Type*) (R : Type u) [NonAssocSemiring R] [SetLike S R] extends SubmonoidClass S R, AddSubmonoidClass S R : Prop -- See note [lower instance priority] instance (priority := 100) SubsemiringClass.addSubmonoidWithOneClass (S : Type*) (R : Type u) [NonAssocSemiring R] [SetLike S R] [h : SubsemiringClass S R] : AddSubmonoidWithOneClass S R := { h with } variable [SetLike S R] [hSR : SubsemiringClass S R] (s : S) namespace SubsemiringClass -- Prefer subclasses of `NonAssocSemiring` over subclasses of `SubsemiringClass`. /-- A subsemiring of a `NonAssocSemiring` inherits a `NonAssocSemiring` structure -/ instance (priority := 75) toNonAssocSemiring : NonAssocSemiring s := Subtype.coe_injective.nonAssocSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance nontrivial [Nontrivial R] : Nontrivial s := nontrivial_of_ne 0 1 fun H => zero_ne_one (congr_arg Subtype.val H) instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s := Subtype.coe_injective.noZeroDivisors _ rfl fun _ _ => rfl /-- The natural ring hom from a subsemiring of semiring `R` to `R`. -/ def subtype : s →+* R := { SubmonoidClass.subtype s, AddSubmonoidClass.subtype s with toFun := (↑) } @[simp] theorem coe_subtype : (subtype s : s → R) = ((↑) : s → R) := rfl -- Prefer subclasses of `Semiring` over subclasses of `SubsemiringClass`. /-- A subsemiring of a `Semiring` is a `Semiring`. -/ instance (priority := 75) toSemiring {R} [Semiring R] [SetLike S R] [SubsemiringClass S R] : Semiring s := Subtype.coe_injective.semiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl @[simp, norm_cast] theorem coe_pow {R} [Semiring R] [SetLike S R] [SubsemiringClass S R] (x : s) (n : ℕ) : ((x ^ n : s) : R) = (x : R) ^ n := by induction' n with n ih · simp · simp [pow_succ, ih] /-- A subsemiring of a `CommSemiring` is a `CommSemiring`. -/ instance toCommSemiring {R} [CommSemiring R] [SetLike S R] [SubsemiringClass S R] : CommSemiring s := Subtype.coe_injective.commSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl instance instCharZero [CharZero R] : CharZero s := ⟨Function.Injective.of_comp (f := Subtype.val) (g := Nat.cast (R := s)) Nat.cast_injective⟩ end SubsemiringClass end SubsemiringClass variable [NonAssocSemiring S] [NonAssocSemiring T] /-- A subsemiring of a semiring `R` is a subset `s` that is both a multiplicative and an additive submonoid. -/ structure Subsemiring (R : Type u) [NonAssocSemiring R] extends Submonoid R, AddSubmonoid R /-- Reinterpret a `Subsemiring` as a `Submonoid`. -/ add_decl_doc Subsemiring.toSubmonoid /-- Reinterpret a `Subsemiring` as an `AddSubmonoid`. -/ add_decl_doc Subsemiring.toAddSubmonoid namespace Subsemiring instance : SetLike (Subsemiring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h instance : SubsemiringClass (Subsemiring R) R where zero_mem := zero_mem' add_mem {s} := AddSubsemigroup.add_mem' s.toAddSubmonoid.toAddSubsemigroup one_mem {s} := Submonoid.one_mem' s.toSubmonoid mul_mem {s} := Subsemigroup.mul_mem' s.toSubmonoid.toSubsemigroup @[simp] theorem mem_toSubmonoid {s : Subsemiring R} {x : R} : x ∈ s.toSubmonoid ↔ x ∈ s := Iff.rfl -- `@[simp]` -- Porting note (#10618): simp can prove thisrove this theorem mem_carrier {s : Subsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl /-- Two subsemirings are equal if they have the same elements. -/ @[ext] theorem ext {S T : Subsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy of a subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : Subsemiring R := { S.toAddSubmonoid.copy s hs, S.toSubmonoid.copy s hs with carrier := s } @[simp] theorem coe_copy (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subsemiring R → Submonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subsemiring R → Submonoid R) := fun _ _ => id @[mono] theorem toSubmonoid_mono : Monotone (toSubmonoid : Subsemiring R → Submonoid R) := toSubmonoid_strictMono.monotone theorem toAddSubmonoid_injective : Function.Injective (toAddSubmonoid : Subsemiring R → AddSubmonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : Subsemiring R → AddSubmonoid R) := fun _ _ => id @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : Subsemiring R → AddSubmonoid R) := toAddSubmonoid_strictMono.monotone /-- Construct a `Subsemiring R` from a set `s`, a submonoid `sm`, and an additive submonoid `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sm : Submonoid R) (hm : ↑sm = s) (sa : AddSubmonoid R) (ha : ↑sa = s) : Subsemiring R where carrier := s zero_mem' := by exact ha ▸ sa.zero_mem one_mem' := by exact hm ▸ sm.one_mem add_mem' {x y} := by simpa only [← ha] using sa.add_mem mul_mem' {x y} := by simpa only [← hm] using sm.mul_mem @[simp] theorem coe_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha : Set R) = s := rfl @[simp] theorem mem_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) {x : R} : x ∈ Subsemiring.mk' s sm hm sa ha ↔ x ∈ s := Iff.rfl @[simp] theorem mk'_toSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha).toSubmonoid = sm := SetLike.coe_injective hm.symm @[simp] theorem mk'_toAddSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha).toAddSubmonoid = sa := SetLike.coe_injective ha.symm end Subsemiring namespace Subsemiring variable (s : Subsemiring R) /-- A subsemiring contains the semiring's 1. -/ protected theorem one_mem : (1 : R) ∈ s := one_mem s /-- A subsemiring contains the semiring's 0. -/ protected theorem zero_mem : (0 : R) ∈ s := zero_mem s /-- A subsemiring is closed under multiplication. -/ protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem /-- A subsemiring is closed under addition. -/ protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s := add_mem /-- Product of a list of elements in a `Subsemiring` is in the `Subsemiring`. -/ nonrec theorem list_prod_mem {R : Type*} [Semiring R] (s : Subsemiring R) {l : List R} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s := list_prod_mem /-- Sum of a list of elements in a `Subsemiring` is in the `Subsemiring`. -/ protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem /-- Product of a multiset of elements in a `Subsemiring` of a `CommSemiring` is in the `Subsemiring`. -/ protected theorem multiset_prod_mem {R} [CommSemiring R] (s : Subsemiring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.prod ∈ s := multiset_prod_mem m /-- Sum of a multiset of elements in a `Subsemiring` of a `Semiring` is in the `add_subsemiring`. -/ protected theorem multiset_sum_mem (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem m /-- Product of elements of a subsemiring of a `CommSemiring` indexed by a `Finset` is in the subsemiring. -/ protected theorem prod_mem {R : Type*} [CommSemiring R] (s : Subsemiring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∏ i ∈ t, f i) ∈ s := prod_mem h /-- Sum of elements in a `Subsemiring` of a `Semiring` indexed by a `Finset` is in the `add_subsemiring`. -/ protected theorem sum_mem (s : Subsemiring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h /-- A subsemiring of a `NonAssocSemiring` inherits a `NonAssocSemiring` structure -/ instance toNonAssocSemiring : NonAssocSemiring s := -- Porting note: this used to be a specialized instance which needed to be expensively unified. SubsemiringClass.toNonAssocSemiring _ @[simp, norm_cast] theorem coe_one : ((1 : s) : R) = (1 : R) := rfl @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = (0 : R) := rfl @[simp, norm_cast] theorem coe_add (x y : s) : ((x + y : s) : R) = (x + y : R) := rfl @[simp, norm_cast] theorem coe_mul (x y : s) : ((x * y : s) : R) = (x * y : R) := rfl instance nontrivial [Nontrivial R] : Nontrivial s := nontrivial_of_ne 0 1 fun H => zero_ne_one (congr_arg Subtype.val H) protected theorem pow_mem {R : Type*} [Semiring R] (s : Subsemiring R) {x : R} (hx : x ∈ s) (n : ℕ) : x ^ n ∈ s := pow_mem hx n instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s where eq_zero_or_eq_zero_of_mul_eq_zero {_ _} h := (eq_zero_or_eq_zero_of_mul_eq_zero <| Subtype.ext_iff.mp h).imp Subtype.eq Subtype.eq /-- A subsemiring of a `Semiring` is a `Semiring`. -/ instance toSemiring {R} [Semiring R] (s : Subsemiring R) : Semiring s := { s.toNonAssocSemiring, s.toSubmonoid.toMonoid with } @[simp, norm_cast] theorem coe_pow {R} [Semiring R] (s : Subsemiring R) (x : s) (n : ℕ) : ((x ^ n : s) : R) = (x : R) ^ n := by induction' n with n ih · simp · simp [pow_succ, ih] /-- A subsemiring of a `CommSemiring` is a `CommSemiring`. -/ instance toCommSemiring {R} [CommSemiring R] (s : Subsemiring R) : CommSemiring s := { s.toSemiring with mul_comm := fun _ _ => Subtype.eq <| mul_comm _ _ } /-- The natural ring hom from a subsemiring of semiring `R` to `R`. -/ def subtype : s →+* R := { s.toSubmonoid.subtype, s.toAddSubmonoid.subtype with toFun := (↑) } @[simp] theorem coe_subtype : ⇑s.subtype = ((↑) : s → R) := rfl protected theorem nsmul_mem {x : R} (hx : x ∈ s) (n : ℕ) : n • x ∈ s := nsmul_mem hx n @[simp] theorem coe_toSubmonoid (s : Subsemiring R) : (s.toSubmonoid : Set R) = s := rfl -- Porting note: adding this as `simp`-normal form for `coe_toAddSubmonoid` @[simp] theorem coe_carrier_toSubmonoid (s : Subsemiring R) : (s.toSubmonoid.carrier : Set R) = s := rfl -- Porting note: can be proven using `SetLike` so removing `@[simp]` theorem mem_toAddSubmonoid {s : Subsemiring R} {x : R} : x ∈ s.toAddSubmonoid ↔ x ∈ s := Iff.rfl -- Porting note: new normal form is `coe_carrier_toSubmonoid` so removing `@[simp]` theorem coe_toAddSubmonoid (s : Subsemiring R) : (s.toAddSubmonoid : Set R) = s := rfl /-- The subsemiring `R` of the semiring `R`. -/ instance : Top (Subsemiring R) := ⟨{ (⊤ : Submonoid R), (⊤ : AddSubmonoid R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : Subsemiring R) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : Subsemiring R) : Set R) = Set.univ := rfl /-- The ring equiv between the top element of `Subsemiring R` and `R`. -/ @[simps] def topEquiv : (⊤ : Subsemiring R) ≃+* R where toFun r := r invFun r := ⟨r, Subsemiring.mem_top r⟩ left_inv _ := rfl right_inv _ := rfl map_mul' := (⊤ : Subsemiring R).coe_mul map_add' := (⊤ : Subsemiring R).coe_add /-- The preimage of a subsemiring along a ring homomorphism is a subsemiring. -/ def comap (f : R →+* S) (s : Subsemiring S) : Subsemiring R := { s.toSubmonoid.comap (f : R →* S), s.toAddSubmonoid.comap (f : R →+ S) with carrier := f ⁻¹' s } @[simp] theorem coe_comap (s : Subsemiring S) (f : R →+* S) : (s.comap f : Set R) = f ⁻¹' s := rfl @[simp] theorem mem_comap {s : Subsemiring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl theorem comap_comap (s : Subsemiring T) (g : S →+* T) (f : R →+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl /-- The image of a subsemiring along a ring homomorphism is a subsemiring. -/ def map (f : R →+* S) (s : Subsemiring R) : Subsemiring S := { s.toSubmonoid.map (f : R →* S), s.toAddSubmonoid.map (f : R →+ S) with carrier := f '' s } @[simp] theorem coe_map (f : R →+* S) (s : Subsemiring R) : (s.map f : Set S) = f '' s := rfl @[simp] lemma mem_map {f : R →+* S} {s : Subsemiring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl @[simp] theorem map_id : s.map (RingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ theorem map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ theorem map_le_iff_le_comap {f : R →+* S} {s : Subsemiring R} {t : Subsemiring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff theorem gc_map_comap (f : R →+* S) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap /-- A subsemiring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : R →+* S) (hf : Function.Injective f) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) map_add' := fun _ _ => Subtype.ext (f.map_add _ _) } @[simp] theorem coe_equivMapOfInjective_apply (f : R →+* S) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl end Subsemiring namespace RingHom variable (g : S →+* T) (f : R →+* S) /-- The range of a ring homomorphism is a subsemiring. See Note [range copy pattern]. -/ def rangeS : Subsemiring S := ((⊤ : Subsemiring R).map f).copy (Set.range f) Set.image_univ.symm @[simp] theorem coe_rangeS : (f.rangeS : Set S) = Set.range f := rfl @[simp] theorem mem_rangeS {f : R →+* S} {y : S} : y ∈ f.rangeS ↔ ∃ x, f x = y := Iff.rfl theorem rangeS_eq_map (f : R →+* S) : f.rangeS = (⊤ : Subsemiring R).map f := by ext simp theorem mem_rangeS_self (f : R →+* S) (x : R) : f x ∈ f.rangeS := mem_rangeS.mpr ⟨x, rfl⟩ theorem map_rangeS : f.rangeS.map g = (g.comp f).rangeS := by simpa only [rangeS_eq_map] using (⊤ : Subsemiring R).map_map g f /-- The range of a morphism of semirings is a fintype, if the domain is a fintype. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype S`. -/ instance fintypeRangeS [Fintype R] [DecidableEq S] (f : R →+* S) : Fintype (rangeS f) := Set.fintypeRange f end RingHom namespace Subsemiring instance : Bot (Subsemiring R) := ⟨(Nat.castRingHom R).rangeS⟩ instance : Inhabited (Subsemiring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : Subsemiring R) : Set R) = Set.range ((↑) : ℕ → R) := (Nat.castRingHom R).coe_rangeS theorem mem_bot {x : R} : x ∈ (⊥ : Subsemiring R) ↔ ∃ n : ℕ, ↑n = x := RingHom.mem_rangeS /-- The inf of two subsemirings is their intersection. -/ instance : Inf (Subsemiring R) := ⟨fun s t => { s.toSubmonoid ⊓ t.toSubmonoid, s.toAddSubmonoid ⊓ t.toAddSubmonoid with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : Subsemiring R) : ((p ⊓ p' : Subsemiring R) : Set R) = (p : Set R) ∩ p' := rfl @[simp] theorem mem_inf {p p' : Subsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance : InfSet (Subsemiring R) := ⟨fun s => Subsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, Subsemiring.toSubmonoid t) (by simp) (⨅ t ∈ s, Subsemiring.toAddSubmonoid t) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (Subsemiring R)) : ((sInf S : Subsemiring R) : Set R) = ⋂ s ∈ S, ↑s := rfl theorem mem_sInf {S : Set (Subsemiring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ @[simp] theorem sInf_toSubmonoid (s : Set (Subsemiring R)) : (sInf s).toSubmonoid = ⨅ t ∈ s, Subsemiring.toSubmonoid t := mk'_toSubmonoid _ _ @[simp] theorem sInf_toAddSubmonoid (s : Set (Subsemiring R)) : (sInf s).toAddSubmonoid = ⨅ t ∈ s, Subsemiring.toAddSubmonoid t := mk'_toAddSubmonoid _ _ /-- Subsemirings of a semiring form a complete lattice. -/ instance : CompleteLattice (Subsemiring R) := { completeLatticeOfInf (Subsemiring R) fun _ => IsGLB.of_image (fun {s t : Subsemiring R} => show (s : Set R) ⊆ t ↔ s ≤ t from SetLike.coe_subset_coe) isGLB_biInf with bot := ⊥ bot_le := fun s _ hx => let ⟨n, hn⟩ := mem_bot.1 hx hn ▸ natCast_mem s n top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _ _ _ h₁ h₂ _ hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : Subsemiring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ section NonAssocSemiring variable (R) /-- The center of a non-associative semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center : Subsemiring R := { NonUnitalSubsemiring.center R with one_mem' := Set.one_mem_center } theorem coe_center : ↑(center R) = Set.center R := rfl @[simp] theorem center_toSubmonoid : (center R).toSubmonoid = Submonoid.center R := rfl /-- The center is commutative and associative. This is not an instance as it forms a non-defeq diamond with `NonUnitalSubringClass.tNonUnitalring ` in the `npow` field. -/ abbrev center.commSemiring' : CommSemiring (center R) := { Submonoid.center.commMonoid', (center R).toNonAssocSemiring with } end NonAssocSemiring section Semiring /-- The center is commutative. -/ instance center.commSemiring {R} [Semiring R] : CommSemiring (center R) := { Submonoid.center.commMonoid, (center R).toSemiring with } -- no instance diamond, unlike the primed version example {R} [Semiring R] : center.commSemiring.toSemiring = Subsemiring.toSemiring (center R) := by with_reducible_and_instances rfl theorem mem_center_iff {R} [Semiring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := Subsemigroup.mem_center_iff instance decidableMemCenter {R} [Semiring R] [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff @[simp] theorem center_eq_top (R) [CommSemiring R] : center R = ⊤ := SetLike.coe_injective (Set.center_eq_univ R) end Semiring section Centralizer /-- The centralizer of a set as subsemiring. -/ def centralizer {R} [Semiring R] (s : Set R) : Subsemiring R := { Submonoid.centralizer s with carrier := s.centralizer zero_mem' := Set.zero_mem_centralizer add_mem' := Set.add_mem_centralizer } @[simp, norm_cast] theorem coe_centralizer {R} [Semiring R] (s : Set R) : (centralizer s : Set R) = s.centralizer := rfl theorem centralizer_toSubmonoid {R} [Semiring R] (s : Set R) : (centralizer s).toSubmonoid = Submonoid.centralizer s := rfl theorem mem_centralizer_iff {R} [Semiring R] {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl theorem center_le_centralizer {R} [Semiring R] (s) : center R ≤ centralizer s := s.center_subset_centralizer theorem centralizer_le {R} [Semiring R] (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s := Set.centralizer_subset h @[simp] theorem centralizer_eq_top_iff_subset {R} [Semiring R] {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset @[simp] theorem centralizer_univ {R} [Semiring R] : centralizer Set.univ = center R := SetLike.ext' (Set.centralizer_univ R) lemma le_centralizer_centralizer {R} [Semiring R] {s : Subsemiring R} : s ≤ centralizer (centralizer (s : Set R)) := Set.subset_centralizer_centralizer @[simp] lemma centralizer_centralizer_centralizer {R} [Semiring R] {s : Set R} : centralizer s.centralizer.centralizer = centralizer s := by apply SetLike.coe_injective simp only [coe_centralizer, Set.centralizer_centralizer_centralizer] end Centralizer /-- The `Subsemiring` generated by a set. -/ def closure (s : Set R) : Subsemiring R := sInf { S | s ⊆ S } theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : Subsemiring R, s ⊆ S → x ∈ S := mem_sInf /-- The subsemiring generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) /-- A subsemiring `S` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : Subsemiring R} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ /-- Subsemiring closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure theorem closure_eq_of_le {s : Set R} {t : Subsemiring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ theorem mem_map_equiv {f : R ≃+* S} {K : Subsemiring R} {x : S} : x ∈ K.map (f : R →+* S) ↔ f.symm x ∈ K := by convert @Set.mem_image_equiv _ _ (↑K) f.toEquiv x using 1 theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : Subsemiring R) : K.map (f : R →+* S) = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : Subsemiring S) : K.comap (f : R →+* S) = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm end Subsemiring namespace Submonoid /-- The additive closure of a submonoid is a subsemiring. -/ def subsemiringClosure (M : Submonoid R) : Subsemiring R := { AddSubmonoid.closure (M : Set R) with one_mem' := AddSubmonoid.mem_closure.mpr fun _ hy => hy M.one_mem mul_mem' := MulMemClass.mul_mem_add_closure } theorem subsemiringClosure_coe : (M.subsemiringClosure : Set R) = AddSubmonoid.closure (M : Set R) := rfl theorem subsemiringClosure_toAddSubmonoid : M.subsemiringClosure.toAddSubmonoid = AddSubmonoid.closure (M : Set R) := rfl /-- The `Subsemiring` generated by a multiplicative submonoid coincides with the `Subsemiring.closure` of the submonoid itself . -/ theorem subsemiringClosure_eq_closure : M.subsemiringClosure = Subsemiring.closure (M : Set R) := by ext refine ⟨fun hx => ?_, fun hx => (Subsemiring.mem_closure.mp hx) M.subsemiringClosure fun s sM => ?_⟩ <;> rintro - ⟨H1, rfl⟩ <;> rintro - ⟨H2, rfl⟩ · exact AddSubmonoid.mem_closure.mp hx H1.toAddSubmonoid H2 · exact H2 sM end Submonoid namespace Subsemiring @[simp] theorem closure_submonoid_closure (s : Set R) : closure ↑(Submonoid.closure s) = closure s := le_antisymm (closure_le.mpr fun _ hy => (Submonoid.mem_closure.mp hy) (closure s).toSubmonoid subset_closure) (closure_mono Submonoid.subset_closure) /-- The elements of the subsemiring closure of `M` are exactly the elements of the additive closure of a multiplicative submonoid `M`. -/ theorem coe_closure_eq (s : Set R) : (closure s : Set R) = AddSubmonoid.closure (Submonoid.closure s : Set R) := by simp [← Submonoid.subsemiringClosure_toAddSubmonoid, Submonoid.subsemiringClosure_eq_closure] theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubmonoid.closure (Submonoid.closure s : Set R) := Set.ext_iff.mp (coe_closure_eq s) x @[simp] theorem closure_addSubmonoid_closure {s : Set R} : closure ↑(AddSubmonoid.closure s) = closure s := by ext x refine ⟨fun hx => ?_, fun hx => closure_mono AddSubmonoid.subset_closure hx⟩ rintro - ⟨H, rfl⟩ rintro - ⟨J, rfl⟩ refine (AddSubmonoid.mem_closure.mp (mem_closure_iff.mp hx)) H.toAddSubmonoid fun y hy => ?_ refine (Submonoid.mem_closure.mp hy) H.toSubmonoid fun z hz => ?_ exact (AddSubmonoid.mem_closure.mp hz) H.toAddSubmonoid fun w hw => J hw /-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements of `s`, and is preserved under addition and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set R} {p : R → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x) (zero : p 0) (one : p 1) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨⟨⟨p, @mul⟩, one⟩, @add, zero⟩).2 mem h @[elab_as_elim] theorem closure_induction' {s : Set R} {p : ∀ x, x ∈ closure s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_closure h)) (zero : p 0 (zero_mem _)) (one : p 1 (one_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {a : R} (ha : a ∈ closure s) : p a ha := by refine Exists.elim ?_ fun (ha : a ∈ closure s) (hc : p a ha) => hc refine closure_induction ha (fun m hm => ⟨subset_closure hm, mem m hm⟩) ⟨zero_mem _, zero⟩ ⟨one_mem _, one⟩ ?_ ?_ · exact (fun x y hx hy => hx.elim fun hx' hx => hy.elim fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) · exact (fun x y hx hy => hx.elim fun hx' hx => hy.elim fun hy' hy => ⟨mul_mem hx' hy', mul _ _ _ _ hx hy⟩) /-- An induction principle for closure membership for predicates with two arguments. -/ @[elab_as_elim] theorem closure_induction₂ {s : Set R} {p : R → R → Prop} {x} {y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ x, p 0 x) (H0_right : ∀ x, p x 0) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p x y := closure_induction hx (fun x₁ x₁s => closure_induction hy (Hs x₁ x₁s) (H0_right x₁) (H1_right x₁) (Hadd_right x₁) (Hmul_right x₁)) (H0_left y) (H1_left y) (fun z z' => Hadd_left z z' y) fun z z' => Hmul_left z z' y theorem mem_closure_iff_exists_list {R} [Semiring R] {s : Set R} {x} : x ∈ closure s ↔ ∃ L : List (List R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s) ∧ (L.map List.prod).sum = x := by constructor · intro hx -- Porting note: needed explicit `p` let p : R → Prop := fun x => ∃ (L : List (List R)), (∀ (t : List R), t ∈ L → ∀ (y : R), y ∈ t → y ∈ s) ∧ (List.map List.prod L).sum = x exact AddSubmonoid.closure_induction (p := p) (mem_closure_iff.1 hx) (fun x hx => suffices ∃ t : List R, (∀ y ∈ t, y ∈ s) ∧ t.prod = x from let ⟨t, ht1, ht2⟩ := this ⟨[t], List.forall_mem_singleton.2 ht1, by rw [List.map_singleton, List.sum_singleton, ht2]⟩ Submonoid.closure_induction hx (fun x hx => ⟨[x], List.forall_mem_singleton.2 hx, one_mul x⟩) ⟨[], List.forall_mem_nil _, rfl⟩ fun x y ⟨t, ht1, ht2⟩ ⟨u, hu1, hu2⟩ => ⟨t ++ u, List.forall_mem_append.2 ⟨ht1, hu1⟩, by rw [List.prod_append, ht2, hu2]⟩) ⟨[], List.forall_mem_nil _, rfl⟩ fun x y ⟨L, HL1, HL2⟩ ⟨M, HM1, HM2⟩ => ⟨L ++ M, List.forall_mem_append.2 ⟨HL1, HM1⟩, by rw [List.map_append, List.sum_append, HL2, HM2]⟩ · rintro ⟨L, HL1, HL2⟩ exact HL2 ▸ list_sum_mem fun r hr => let ⟨t, ht1, ht2⟩ := List.mem_map.1 hr ht2 ▸ list_prod_mem _ fun y hy => subset_closure <| HL1 t ht1 y hy variable (R) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure R _) (↑) where choice s _ := closure s gc _ _ := closure_le le_l_u _ := subset_closure choice_eq _ _ := rfl variable {R} /-- Closure of a subsemiring `S` equals `S`. -/ theorem closure_eq (s : Subsemiring R) : closure (s : Set R) = s := (Subsemiring.gi R).l_u_eq s @[simp] theorem closure_empty : closure (∅ : Set R) = ⊥ := (Subsemiring.gi R).gc.l_bot @[simp] theorem closure_univ : closure (Set.univ : Set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤ theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t := (Subsemiring.gi R).gc.l_sup theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subsemiring.gi R).gc.l_iSup theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (Subsemiring.gi R).gc.l_sSup theorem map_sup (s t : Subsemiring R) (f : R →+* S) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : R →+* S) (s : ι → Subsemiring R) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem comap_inf (s t : Subsemiring S) (f : R →+* S) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f := (gc_map_comap f).u_inf theorem comap_iInf {ι : Sort*} (f : R →+* S) (s : ι → Subsemiring S) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf @[simp] theorem map_bot (f : R →+* S) : (⊥ : Subsemiring R).map f = ⊥ := (gc_map_comap f).l_bot @[simp] theorem comap_top (f : R →+* S) : (⊤ : Subsemiring S).comap f = ⊤ := (gc_map_comap f).u_top /-- Given `Subsemiring`s `s`, `t` of semirings `R`, `S` respectively, `s.prod t` is `s × t` as a subsemiring of `R × S`. -/ def prod (s : Subsemiring R) (t : Subsemiring S) : Subsemiring (R × S) := { s.toSubmonoid.prod t.toSubmonoid, s.toAddSubmonoid.prod t.toAddSubmonoid with carrier := s ×ˢ t } @[norm_cast] theorem coe_prod (s : Subsemiring R) (t : Subsemiring S) : (s.prod t : Set (R × S)) = (s : Set R) ×ˢ (t : Set S) := rfl theorem mem_prod {s : Subsemiring R} {t : Subsemiring S} {p : R × S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl @[mono] theorem prod_mono ⦃s₁ s₂ : Subsemiring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : Subsemiring S⦄ (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht theorem prod_mono_right (s : Subsemiring R) : Monotone fun t : Subsemiring S => s.prod t := prod_mono (le_refl s) theorem prod_mono_left (t : Subsemiring S) : Monotone fun s : Subsemiring R => s.prod t := fun _ _ hs => prod_mono hs (le_refl t) theorem prod_top (s : Subsemiring R) : s.prod (⊤ : Subsemiring S) = s.comap (RingHom.fst R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] theorem top_prod (s : Subsemiring S) : (⊤ : Subsemiring R).prod s = s.comap (RingHom.snd R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[simp] theorem top_prod_top : (⊤ : Subsemiring R).prod (⊤ : Subsemiring S) = ⊤ := (top_prod _).trans <| comap_top _ /-- Product of subsemirings is isomorphic to their product as monoids. -/ def prodEquiv (s : Subsemiring R) (t : Subsemiring S) : s.prod t ≃+* s × t := { Equiv.Set.prod (s : Set R) (t : Set S) with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subsemiring R} (hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ let U : Subsemiring R := Subsemiring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubmonoid) (Submonoid.coe_iSup_of_directed hS) (⨆ i, (S i).toAddSubmonoid) (AddSubmonoid.coe_iSup_of_directed hS) -- Porting note: gave the hypothesis an explicit name because `@this` doesn't work suffices h : ⨆ i, S i ≤ U by simpa [U] using @h x exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩ theorem coe_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subsemiring R} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Subsemiring R) : Set R) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] theorem mem_sSup_of_directedOn {S : Set (Subsemiring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) {x : R} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] theorem coe_sSup_of_directedOn {S : Set (Subsemiring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] end Subsemiring namespace RingHom variable [NonAssocSemiring T] {s : Subsemiring R} variable {σR σS : Type*} variable [SetLike σR R] [SetLike σS S] [SubsemiringClass σR R] [SubsemiringClass σS S] open Subsemiring /-- Restriction of a ring homomorphism to a subsemiring of the domain. -/ def domRestrict (f : R →+* S) (s : σR) : s →+* S := f.comp <| SubsemiringClass.subtype s @[simp] theorem restrict_apply (f : R →+* S) {s : σR} (x : s) : f.domRestrict s x = f x := rfl /-- Restriction of a ring homomorphism to a subsemiring of the codomain. -/ def codRestrict (f : R →+* S) (s : σS) (h : ∀ x, f x ∈ s) : R →+* s := { (f : R →* S).codRestrict s h, (f : R →+ S).codRestrict s h with toFun := fun n => ⟨f n, h n⟩ } /-- The ring homomorphism from the preimage of `s` to `s`. -/ def restrict (f : R →+* S) (s' : σR) (s : σS) (h : ∀ x ∈ s', f x ∈ s) : s' →+* s := (f.domRestrict s').codRestrict s fun x => h x x.2 @[simp] theorem coe_restrict_apply (f : R →+* S) (s' : σR) (s : σS) (h : ∀ x ∈ s', f x ∈ s) (x : s') : (f.restrict s' s h x : S) = f x := rfl @[simp] theorem comp_restrict (f : R →+* S) (s' : σR) (s : σS) (h : ∀ x ∈ s', f x ∈ s) : (SubsemiringClass.subtype s).comp (f.restrict s' s h) = f.comp (SubsemiringClass.subtype s') := rfl /-- Restriction of a ring homomorphism to its range interpreted as a subsemiring. This is the bundled version of `Set.rangeFactorization`. -/ def rangeSRestrict (f : R →+* S) : R →+* f.rangeS := f.codRestrict (R := R) (S := S) (σS := Subsemiring S) f.rangeS f.mem_rangeS_self @[simp] theorem coe_rangeSRestrict (f : R →+* S) (x : R) : (f.rangeSRestrict x : S) = f x := rfl theorem rangeSRestrict_surjective (f : R →+* S) : Function.Surjective f.rangeSRestrict := fun ⟨_, hy⟩ => let ⟨x, hx⟩ := mem_rangeS.mp hy ⟨x, Subtype.ext hx⟩ theorem rangeS_top_iff_surjective {f : R →+* S} : f.rangeS = (⊤ : Subsemiring S) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_rangeS, coe_top]) Set.range_iff_surjective /-- The range of a surjective ring homomorphism is the whole of the codomain. -/ @[simp] theorem rangeS_top_of_surjective (f : R →+* S) (hf : Function.Surjective f) : f.rangeS = (⊤ : Subsemiring S) := rangeS_top_iff_surjective.2 hf /-- The subsemiring of elements `x : R` such that `f x = g x` -/ def eqLocusS (f g : R →+* S) : Subsemiring R := { (f : R →* S).eqLocusM g, (f : R →+ S).eqLocusM g with carrier := { x | f x = g x } } @[simp] theorem eqLocusS_same (f : R →+* S) : f.eqLocusS f = ⊤ := SetLike.ext fun _ => eq_self_iff_true _ /-- If two ring homomorphisms are equal on a set, then they are equal on its subsemiring closure. -/ theorem eqOn_sclosure {f g : R →+* S} {s : Set R} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) := show closure s ≤ f.eqLocusS g from closure_le.2 h theorem eq_of_eqOn_stop {f g : R →+* S} (h : Set.EqOn f g (⊤ : Subsemiring R)) : f = g := ext fun _ => h trivial theorem eq_of_eqOn_sdense {s : Set R} (hs : closure s = ⊤) {f g : R →+* S} (h : s.EqOn f g) : f = g := eq_of_eqOn_stop <| hs ▸ eqOn_sclosure h theorem sclosure_preimage_le (f : R →+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a ring homomorphism of the subsemiring generated by a set equals the subsemiring generated by the image of the set. -/ theorem map_closureS (f : R →+* S) (s : Set R) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 <| le_trans (closure_mono <| Set.subset_preimage_image _ _) (sclosure_preimage_le _ _)) (closure_le.2 <| Set.image_subset _ subset_closure) end RingHom namespace Subsemiring open RingHom /-- The ring homomorphism associated to an inclusion of subsemirings. -/ def inclusion {S T : Subsemiring R} (h : S ≤ T) : S →+* T := S.subtype.codRestrict _ fun x => h x.2 @[simp] theorem rangeS_subtype (s : Subsemiring R) : s.subtype.rangeS = s := SetLike.coe_injective <| (coe_rangeS _).trans Subtype.range_coe @[simp] theorem range_fst : (fst R S).rangeS = ⊤ := (fst R S).rangeS_top_of_surjective <| Prod.fst_surjective @[simp] theorem range_snd : (snd R S).rangeS = ⊤ := (snd R S).rangeS_top_of_surjective <| Prod.snd_surjective @[simp] theorem prod_bot_sup_bot_prod (s : Subsemiring R) (t : Subsemiring S) : s.prod ⊥ ⊔ prod ⊥ t = s.prod t := le_antisymm (sup_le (prod_mono_right s bot_le) (prod_mono_left t bot_le)) fun p hp => Prod.fst_mul_snd p ▸ mul_mem ((le_sup_left : s.prod ⊥ ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨hp.1, SetLike.mem_coe.2 <| one_mem ⊥⟩) ((le_sup_right : prod ⊥ t ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨SetLike.mem_coe.2 <| one_mem ⊥, hp.2⟩) end Subsemiring namespace RingEquiv variable {s t : Subsemiring R} /-- Makes the identity isomorphism from a proof two subsemirings of a multiplicative monoid are equal. -/ def subsemiringCongr (h : s = t) : s ≃+* t := { Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } /-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its `RingHom.rangeS`. -/ def ofLeftInverseS {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) : R ≃+* f.rangeS := { f.rangeSRestrict with toFun := fun x => f.rangeSRestrict x invFun := fun x => (g ∘ f.rangeS.subtype) x left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := RingHom.mem_rangeS.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverseS_apply {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) (x : R) : ↑(ofLeftInverseS h x) = f x := rfl @[simp] theorem ofLeftInverseS_symm_apply {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) (x : f.rangeS) : (ofLeftInverseS h).symm x = g x := rfl /-- Given an equivalence `e : R ≃+* S` of semirings and a subsemiring `s` of `R`, `subsemiring_map e s` is the induced equivalence between `s` and `s.map e` -/ @[simps!] def subsemiringMap (e : R ≃+* S) (s : Subsemiring R) : s ≃+* s.map e.toRingHom := { e.toAddEquiv.addSubmonoidMap s.toAddSubmonoid, e.toMulEquiv.submonoidMap s.toSubmonoid with } -- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing attribute [nolint simpNF] RingEquiv.subsemiringMap_symm_apply_coe RingEquiv.subsemiringMap_apply_coe end RingEquiv /-! ### Actions by `Subsemiring`s These are just copies of the definitions about `Submonoid` starting from `submonoid.mul_action`. The only new result is `subsemiring.module`. When `R` is commutative, `Algebra.ofSubsemiring` provides a stronger result than those found in this file, which uses the same scalar action. -/ section Actions namespace Subsemiring variable {R' α β : Type*} section NonAssocSemiring variable [NonAssocSemiring R'] /-- The action by a subsemiring is the action by the underlying semiring. -/ instance smul [SMul R' α] (S : Subsemiring R') : SMul S α := S.toSubmonoid.smul theorem smul_def [SMul R' α] {S : Subsemiring R'} (g : S) (m : α) : g • m = (g : R') • m := rfl instance smulCommClass_left [SMul R' β] [SMul α β] [SMulCommClass R' α β] (S : Subsemiring R') : SMulCommClass S α β := S.toSubmonoid.smulCommClass_left instance smulCommClass_right [SMul α β] [SMul R' β] [SMulCommClass α R' β] (S : Subsemiring R') : SMulCommClass α S β := S.toSubmonoid.smulCommClass_right /-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/ instance isScalarTower [SMul α β] [SMul R' α] [SMul R' β] [IsScalarTower R' α β] (S : Subsemiring R') : IsScalarTower S α β := S.toSubmonoid.isScalarTower instance faithfulSMul [SMul R' α] [FaithfulSMul R' α] (S : Subsemiring R') : FaithfulSMul S α := S.toSubmonoid.faithfulSMul /-- The action by a subsemiring is the action by the underlying semiring. -/ instance [Zero α] [SMulWithZero R' α] (S : Subsemiring R') : SMulWithZero S α := SMulWithZero.compHom _ S.subtype.toMonoidWithZeroHom.toZeroHom end NonAssocSemiring variable [Semiring R'] /-- The action by a subsemiring is the action by the underlying semiring. -/ instance mulAction [MulAction R' α] (S : Subsemiring R') : MulAction S α := S.toSubmonoid.mulAction /-- The action by a subsemiring is the action by the underlying semiring. -/ instance distribMulAction [AddMonoid α] [DistribMulAction R' α] (S : Subsemiring R') : DistribMulAction S α := S.toSubmonoid.distribMulAction /-- The action by a subsemiring is the action by the underlying semiring. -/ instance mulDistribMulAction [Monoid α] [MulDistribMulAction R' α] (S : Subsemiring R') : MulDistribMulAction S α := S.toSubmonoid.mulDistribMulAction /-- The action by a subsemiring is the action by the underlying semiring. -/ instance mulActionWithZero [Zero α] [MulActionWithZero R' α] (S : Subsemiring R') : MulActionWithZero S α := MulActionWithZero.compHom _ S.subtype.toMonoidWithZeroHom -- Porting note: instance named explicitly for use in `RingTheory/Subring/Basic` /-- The action by a subsemiring is the action by the underlying semiring. -/ instance module [AddCommMonoid α] [Module R' α] (S : Subsemiring R') : Module S α := -- Porting note: copying over the `smul` field causes a timeout -- { Module.compHom _ S.subtype with smul := (· • ·) } Module.compHom _ S.subtype /-- The action by a subsemiring is the action by the underlying semiring. -/ instance [Semiring α] [MulSemiringAction R' α] (S : Subsemiring R') : MulSemiringAction S α := S.toSubmonoid.mulSemiringAction /-- The center of a semiring acts commutatively on that semiring. -/ instance center.smulCommClass_left : SMulCommClass (center R') R' R' := Submonoid.center.smulCommClass_left /-- The center of a semiring acts commutatively on that semiring. -/ instance center.smulCommClass_right : SMulCommClass R' (center R') R' := Submonoid.center.smulCommClass_right /-- If all the elements of a set `s` commute, then `closure s` is a commutative monoid. -/ def closureCommSemiringOfComm {s : Set R'} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : CommSemiring (closure s) := { (closure s).toSemiring with mul_comm := fun x y => by ext simp only [Subsemiring.coe_mul] refine closure_induction₂ x.prop y.prop hcomm (fun x => by simp only [zero_mul, mul_zero]) (fun x => by simp only [zero_mul, mul_zero]) (fun x => by simp only [one_mul, mul_one]) (fun x => by simp only [one_mul, mul_one]) (fun x y z h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun x y z h₁ h₂ => by simp only [add_mul, mul_add, h₁, h₂]) (fun x y z h₁ h₂ => by rw [mul_assoc, h₂, ← mul_assoc, h₁, mul_assoc]) fun x y z h₁ h₂ => by rw [← mul_assoc, h₁, mul_assoc, h₂, ← mul_assoc] } end Subsemiring end Actions namespace Subsemiring theorem map_comap_eq (f : R →+* S) (t : Subsemiring S) : (t.comap f).map f = t ⊓ f.rangeS := SetLike.coe_injective Set.image_preimage_eq_inter_range theorem map_comap_eq_self {f : R →+* S} {t : Subsemiring S} (h : t ≤ f.rangeS) : (t.comap f).map f = t := by simpa only [inf_of_le_left h] using map_comap_eq f t theorem map_comap_eq_self_of_surjective {f : R →+* S} (hf : Function.Surjective f) (t : Subsemiring S) : (t.comap f).map f = t := map_comap_eq_self <| by simp [hf] theorem comap_map_eq_self_of_injective {f : R →+* S} (hf : Function.Injective f) (s : Subsemiring R) : (s.map f).comap f = s := SetLike.coe_injective (Set.preimage_image_eq _ hf) end Subsemiring
Algebra\Ring\Subsemiring\MulOpposite.lean
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.Algebra.Group.Submonoid.MulOpposite import Mathlib.Algebra.Ring.Subsemiring.Basic /-! # Subsemiring of opposite semirings For every semiring `R`, we construct an equivalence between subsemirings of `R` and that of `Rᵐᵒᵖ`. -/ namespace Subsemiring variable {ι : Sort*} {R : Type*} [NonAssocSemiring R] /-- Pull a subsemiring back to an opposite subsemiring along `MulOpposite.unop` -/ @[simps toSubmonoid] protected def op (S : Subsemiring R) : Subsemiring Rᵐᵒᵖ where toSubmonoid := S.toSubmonoid.op add_mem' {x} {y} hx hy := add_mem (show x.unop ∈ S from hx) (show y.unop ∈ S from hy) zero_mem' := zero_mem S @[simp, norm_cast] theorem op_coe (S : Subsemiring R) : S.op = MulOpposite.unop ⁻¹' (S : Set R) := rfl @[simp] theorem mem_op {x : Rᵐᵒᵖ} {S : Subsemiring R} : x ∈ S.op ↔ x.unop ∈ S := Iff.rfl /-- Pull an opposite subsemiring back to a subsemiring along `MulOpposite.op` -/ @[simps toSubmonoid] protected def unop (S : Subsemiring Rᵐᵒᵖ) : Subsemiring R where toSubmonoid := S.toSubmonoid.unop add_mem' {x} {y} hx hy := add_mem (show MulOpposite.op x ∈ S from hx) (show MulOpposite.op y ∈ S from hy) zero_mem' := zero_mem S @[simp, norm_cast] theorem unop_coe (S : Subsemiring Rᵐᵒᵖ) : S.unop = MulOpposite.op ⁻¹' (S : Set Rᵐᵒᵖ) := rfl @[simp] theorem mem_unop {x : R} {S : Subsemiring Rᵐᵒᵖ} : x ∈ S.unop ↔ MulOpposite.op x ∈ S := Iff.rfl @[simp] theorem unop_op (S : Subsemiring R) : S.op.unop = S := rfl @[simp] theorem op_unop (S : Subsemiring Rᵐᵒᵖ) : S.unop.op = S := rfl /-! ### Lattice results -/ theorem op_le_iff {S₁ : Subsemiring R} {S₂ : Subsemiring Rᵐᵒᵖ} : S₁.op ≤ S₂ ↔ S₁ ≤ S₂.unop := MulOpposite.op_surjective.forall theorem le_op_iff {S₁ : Subsemiring Rᵐᵒᵖ} {S₂ : Subsemiring R} : S₁ ≤ S₂.op ↔ S₁.unop ≤ S₂ := MulOpposite.op_surjective.forall @[simp] theorem op_le_op_iff {S₁ S₂ : Subsemiring R} : S₁.op ≤ S₂.op ↔ S₁ ≤ S₂ := MulOpposite.op_surjective.forall @[simp] theorem unop_le_unop_iff {S₁ S₂ : Subsemiring Rᵐᵒᵖ} : S₁.unop ≤ S₂.unop ↔ S₁ ≤ S₂ := MulOpposite.unop_surjective.forall /-- A subsemiring `S` of `R` determines a subsemiring `S.op` of the opposite ring `Rᵐᵒᵖ`. -/ @[simps] def opEquiv : Subsemiring R ≃o Subsemiring Rᵐᵒᵖ where toFun := Subsemiring.op invFun := Subsemiring.unop left_inv := unop_op right_inv := op_unop map_rel_iff' := op_le_op_iff @[simp] theorem op_bot : (⊥ : Subsemiring R).op = ⊥ := opEquiv.map_bot @[simp] theorem unop_bot : (⊥ : Subsemiring Rᵐᵒᵖ).unop = ⊥ := opEquiv.symm.map_bot @[simp] theorem op_top : (⊤ : Subsemiring R).op = ⊤ := opEquiv.map_top @[simp] theorem unop_top : (⊤ : Subsemiring Rᵐᵒᵖ).unop = ⊤ := opEquiv.symm.map_top theorem op_sup (S₁ S₂ : Subsemiring R) : (S₁ ⊔ S₂).op = S₁.op ⊔ S₂.op := opEquiv.map_sup _ _ theorem unop_sup (S₁ S₂ : Subsemiring Rᵐᵒᵖ) : (S₁ ⊔ S₂).unop = S₁.unop ⊔ S₂.unop := opEquiv.symm.map_sup _ _ theorem op_inf (S₁ S₂ : Subsemiring R) : (S₁ ⊓ S₂).op = S₁.op ⊓ S₂.op := opEquiv.map_inf _ _ theorem unop_inf (S₁ S₂ : Subsemiring Rᵐᵒᵖ) : (S₁ ⊓ S₂).unop = S₁.unop ⊓ S₂.unop := opEquiv.symm.map_inf _ _ theorem op_sSup (S : Set (Subsemiring R)) : (sSup S).op = sSup (.unop ⁻¹' S) := opEquiv.map_sSup_eq_sSup_symm_preimage _ theorem unop_sSup (S : Set (Subsemiring Rᵐᵒᵖ)) : (sSup S).unop = sSup (.op ⁻¹' S) := opEquiv.symm.map_sSup_eq_sSup_symm_preimage _ theorem op_sInf (S : Set (Subsemiring R)) : (sInf S).op = sInf (.unop ⁻¹' S) := opEquiv.map_sInf_eq_sInf_symm_preimage _ theorem unop_sInf (S : Set (Subsemiring Rᵐᵒᵖ)) : (sInf S).unop = sInf (.op ⁻¹' S) := opEquiv.symm.map_sInf_eq_sInf_symm_preimage _ theorem op_iSup (S : ι → Subsemiring R) : (iSup S).op = ⨆ i, (S i).op := opEquiv.map_iSup _ theorem unop_iSup (S : ι → Subsemiring Rᵐᵒᵖ) : (iSup S).unop = ⨆ i, (S i).unop := opEquiv.symm.map_iSup _ theorem op_iInf (S : ι → Subsemiring R) : (iInf S).op = ⨅ i, (S i).op := opEquiv.map_iInf _ theorem unop_iInf (S : ι → Subsemiring Rᵐᵒᵖ) : (iInf S).unop = ⨅ i, (S i).unop := opEquiv.symm.map_iInf _ theorem op_closure (s : Set R) : (closure s).op = closure (MulOpposite.unop ⁻¹' s) := by simp_rw [closure, op_sInf, Set.preimage_setOf_eq, unop_coe] congr with a exact MulOpposite.unop_surjective.forall theorem unop_closure (s : Set Rᵐᵒᵖ) : (closure s).unop = closure (MulOpposite.op ⁻¹' s) := by simp_rw [closure, unop_sInf, Set.preimage_setOf_eq, op_coe] congr with a exact MulOpposite.op_surjective.forall /-- Bijection between a subsemiring `S` and its opposite. -/ @[simps!] def addEquivOp (S : Subsemiring R) : S ≃+ S.op where toEquiv := S.toSubmonoid.equivOp map_add' _ _ := rfl -- TODO: Add this for `[Add]Submonoid` and `[Add]Subgroup` /-- Bijection between a subsemiring `S` and `MulOpposite` of its opposite. -/ @[simps!] def ringEquivOpMop (S : Subsemiring R) : S ≃+* (S.op)ᵐᵒᵖ where __ := S.addEquivOp.trans MulOpposite.opAddEquiv map_mul' _ _ := rfl -- TODO: Add this for `[Add]Submonoid` and `[Add]Subgroup` /-- Bijection between `MulOpposite` of a subsemiring `S` and its opposite. -/ @[simps!] def mopRingEquivOp (S : Subsemiring R) : Sᵐᵒᵖ ≃+* S.op where __ := MulOpposite.opAddEquiv.symm.trans S.addEquivOp map_mul' _ _ := rfl end Subsemiring
Algebra\Ring\Subsemiring\Order.lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Order.Ring.InjSurj import Mathlib.Algebra.Ring.Subsemiring.Basic /-! # `Order`ed instances for `SubsemiringClass` and `Subsemiring`. -/ namespace SubsemiringClass variable {R S : Type*} [SetLike S R] (s : S) /-- A subsemiring of an `OrderedSemiring` is an `OrderedSemiring`. -/ instance toOrderedSemiring [OrderedSemiring R] [SubsemiringClass S R] : OrderedSemiring s := Subtype.coe_injective.orderedSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of a `StrictOrderedSemiring` is a `StrictOrderedSemiring`. -/ instance toStrictOrderedSemiring [StrictOrderedSemiring R] [SubsemiringClass S R] : StrictOrderedSemiring s := Subtype.coe_injective.strictOrderedSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of an `OrderedCommSemiring` is an `OrderedCommSemiring`. -/ instance toOrderedCommSemiring [OrderedCommSemiring R] [SubsemiringClass S R] : OrderedCommSemiring s := Subtype.coe_injective.orderedCommSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of a `StrictOrderedCommSemiring` is a `StrictOrderedCommSemiring`. -/ instance toStrictOrderedCommSemiring [StrictOrderedCommSemiring R] [SubsemiringClass S R] : StrictOrderedCommSemiring s := Subtype.coe_injective.strictOrderedCommSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of a `LinearOrderedSemiring` is a `LinearOrderedSemiring`. -/ instance toLinearOrderedSemiring [LinearOrderedSemiring R] [SubsemiringClass S R] : LinearOrderedSemiring s := Subtype.coe_injective.linearOrderedSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-- A subsemiring of a `LinearOrderedCommSemiring` is a `LinearOrderedCommSemiring`. -/ instance toLinearOrderedCommSemiring [LinearOrderedCommSemiring R] [SubsemiringClass S R] : LinearOrderedCommSemiring s := Subtype.coe_injective.linearOrderedCommSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) fun _ _ => rfl end SubsemiringClass namespace Subsemiring variable {R : Type*} /-- A subsemiring of an `OrderedSemiring` is an `OrderedSemiring`. -/ instance toOrderedSemiring [OrderedSemiring R] (s : Subsemiring R) : OrderedSemiring s := Subtype.coe_injective.orderedSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of a `StrictOrderedSemiring` is a `StrictOrderedSemiring`. -/ instance toStrictOrderedSemiring [StrictOrderedSemiring R] (s : Subsemiring R) : StrictOrderedSemiring s := Subtype.coe_injective.strictOrderedSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of an `OrderedCommSemiring` is an `OrderedCommSemiring`. -/ instance toOrderedCommSemiring [OrderedCommSemiring R] (s : Subsemiring R) : OrderedCommSemiring s := Subtype.coe_injective.orderedCommSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of a `StrictOrderedCommSemiring` is a `StrictOrderedCommSemiring`. -/ instance toStrictOrderedCommSemiring [StrictOrderedCommSemiring R] (s : Subsemiring R) : StrictOrderedCommSemiring s := Subtype.coe_injective.strictOrderedCommSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subsemiring of a `LinearOrderedSemiring` is a `LinearOrderedSemiring`. -/ instance toLinearOrderedSemiring [LinearOrderedSemiring R] (s : Subsemiring R) : LinearOrderedSemiring s := Subtype.coe_injective.linearOrderedSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-- A subsemiring of a `LinearOrderedCommSemiring` is a `LinearOrderedCommSemiring`. -/ instance toLinearOrderedCommSemiring [LinearOrderedCommSemiring R] (s : Subsemiring R) : LinearOrderedCommSemiring s := Subtype.coe_injective.linearOrderedCommSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-- The set of nonnegative elements in an ordered semiring, as a subsemiring. -/ @[simps] def nonneg (R : Type*) [OrderedSemiring R] : Subsemiring R where carrier := Set.Ici 0 mul_mem' := mul_nonneg one_mem' := zero_le_one add_mem' := add_nonneg zero_mem' := le_rfl end Subsemiring
Algebra\Ring\Subsemiring\Pointwise.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Submonoid.Pointwise import Mathlib.Algebra.Ring.Action.Basic import Mathlib.Algebra.Ring.Subsemiring.Basic import Mathlib.Data.Set.Pointwise.Basic /-! # Pointwise instances on `Subsemiring`s This file provides the action `Subsemiring.PointwiseMulAction` which matches the action of `MulActionSet`. This actions is available in the `Pointwise` locale. ## Implementation notes This file is almost identical to the file `Mathlib.Algebra.Group.Submonoid.Pointwise`. Where possible, try to keep them in sync. -/ open Set variable {M R : Type*} namespace Subsemiring section Monoid variable [Monoid M] [Semiring R] [MulSemiringAction M R] /-- The action on a subsemiring corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction M (Subsemiring R) where smul a S := S.map (MulSemiringAction.toRingHom _ _ a) one_smul S := (congr_arg (fun f => S.map f) (RingHom.ext <| one_smul M)).trans S.map_id mul_smul _a₁ _a₂ S := (congr_arg (fun f => S.map f) (RingHom.ext <| mul_smul _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] Subsemiring.pointwiseMulAction open Pointwise theorem pointwise_smul_def {a : M} (S : Subsemiring R) : a • S = S.map (MulSemiringAction.toRingHom _ _ a) := rfl @[simp] theorem coe_pointwise_smul (m : M) (S : Subsemiring R) : ↑(m • S) = m • (S : Set R) := rfl @[simp] theorem pointwise_smul_toAddSubmonoid (m : M) (S : Subsemiring R) : (m • S).toAddSubmonoid = m • S.toAddSubmonoid := rfl theorem smul_mem_pointwise_smul (m : M) (r : R) (S : Subsemiring R) : r ∈ S → m • r ∈ m • S := (Set.smul_mem_smul_set : _ → _ ∈ m • (S : Set R)) instance : CovariantClass M (Subsemiring R) HSMul.hSMul LE.le := ⟨fun _ _ => image_subset _⟩ theorem mem_smul_pointwise_iff_exists (m : M) (r : R) (S : Subsemiring R) : r ∈ m • S ↔ ∃ s : R, s ∈ S ∧ m • s = r := (Set.mem_smul_set : r ∈ m • (S : Set R) ↔ _) @[simp] theorem smul_bot (a : M) : a • (⊥ : Subsemiring R) = ⊥ := map_bot _ theorem smul_sup (a : M) (S T : Subsemiring R) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ theorem smul_closure (a : M) (s : Set R) : a • closure s = closure (a • s) := RingHom.map_closureS _ _ instance pointwise_central_scalar [MulSemiringAction Mᵐᵒᵖ R] [IsCentralScalar M R] : IsCentralScalar M (Subsemiring R) := ⟨fun _a S => (congr_arg fun f => S.map f) <| RingHom.ext <| op_smul_eq_smul _⟩ end Monoid section Group variable [Group M] [Semiring R] [MulSemiringAction M R] open Pointwise @[simp] theorem smul_mem_pointwise_smul_iff {a : M} {S : Subsemiring R} {x : R} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : M} {S : Subsemiring R} {x : R} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : M} {S : Subsemiring R} {x : R} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : M} {S T : Subsemiring R} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff theorem pointwise_smul_subset_iff {a : M} {S T : Subsemiring R} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff theorem subset_pointwise_smul_iff {a : M} {S T : Subsemiring R} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff /-! TODO: add `equiv_smul` like we have for subgroup. -/ end Group section GroupWithZero variable [GroupWithZero M] [Semiring R] [MulSemiringAction M R] open Pointwise @[simp] theorem smul_mem_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) (S : Subsemiring R) (x : R) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set R) x theorem mem_pointwise_smul_iff_inv_smul_mem₀ {a : M} (ha : a ≠ 0) (S : Subsemiring R) (x : R) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set R) x theorem mem_inv_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) (S : Subsemiring R) (x : R) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set R) x @[simp] theorem pointwise_smul_le_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) {S T : Subsemiring R} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha theorem pointwise_smul_le_iff₀ {a : M} (ha : a ≠ 0) {S T : Subsemiring R} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha theorem le_pointwise_smul_iff₀ {a : M} (ha : a ≠ 0) {S T : Subsemiring R} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end GroupWithZero end Subsemiring
Algebra\Squarefree\Basic.lean
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.RingTheory.Nilpotent.Basic import Mathlib.RingTheory.UniqueFactorizationDomain /-! # Squarefree elements of monoids An element of a monoid is squarefree when it is not divisible by any squares except the squares of units. Results about squarefree natural numbers are proved in `Data.Nat.Squarefree`. ## Main Definitions - `Squarefree r` indicates that `r` is only divisible by `x * x` if `x` is a unit. ## Main Results - `multiplicity.squarefree_iff_multiplicity_le_one`: `x` is `Squarefree` iff for every `y`, either `multiplicity y x ≤ 1` or `IsUnit y`. - `UniqueFactorizationMonoid.squarefree_iff_nodup_factors`: A nonzero element `x` of a unique factorization monoid is squarefree iff `factors x` has no duplicate factors. ## Tags squarefree, multiplicity -/ variable {R : Type*} /-- An element of a monoid is squarefree if the only squares that divide it are the squares of units. -/ def Squarefree [Monoid R] (r : R) : Prop := ∀ x : R, x * x ∣ r → IsUnit x theorem IsRelPrime.of_squarefree_mul [CommMonoid R] {m n : R} (h : Squarefree (m * n)) : IsRelPrime m n := fun c hca hcb ↦ h c (mul_dvd_mul hca hcb) @[simp] theorem IsUnit.squarefree [CommMonoid R] {x : R} (h : IsUnit x) : Squarefree x := fun _ hdvd => isUnit_of_mul_isUnit_left (isUnit_of_dvd_unit hdvd h) -- @[simp] -- Porting note (#10618): simp can prove this theorem squarefree_one [CommMonoid R] : Squarefree (1 : R) := isUnit_one.squarefree @[simp] theorem not_squarefree_zero [MonoidWithZero R] [Nontrivial R] : ¬Squarefree (0 : R) := by erw [not_forall] exact ⟨0, by simp⟩ theorem Squarefree.ne_zero [MonoidWithZero R] [Nontrivial R] {m : R} (hm : Squarefree (m : R)) : m ≠ 0 := by rintro rfl exact not_squarefree_zero hm @[simp] theorem Irreducible.squarefree [CommMonoid R] {x : R} (h : Irreducible x) : Squarefree x := by rintro y ⟨z, hz⟩ rw [mul_assoc] at hz rcases h.isUnit_or_isUnit hz with (hu | hu) · exact hu · apply isUnit_of_mul_isUnit_left hu @[simp] theorem Prime.squarefree [CancelCommMonoidWithZero R] {x : R} (h : Prime x) : Squarefree x := h.irreducible.squarefree theorem Squarefree.of_mul_left [CommMonoid R] {m n : R} (hmn : Squarefree (m * n)) : Squarefree m := fun p hp => hmn p (dvd_mul_of_dvd_left hp n) theorem Squarefree.of_mul_right [CommMonoid R] {m n : R} (hmn : Squarefree (m * n)) : Squarefree n := fun p hp => hmn p (dvd_mul_of_dvd_right hp m) theorem Squarefree.squarefree_of_dvd [CommMonoid R] {x y : R} (hdvd : x ∣ y) (hsq : Squarefree y) : Squarefree x := fun _ h => hsq _ (h.trans hdvd) theorem Squarefree.eq_zero_or_one_of_pow_of_not_isUnit [CommMonoid R] {x : R} {n : ℕ} (h : Squarefree (x ^ n)) (h' : ¬ IsUnit x) : n = 0 ∨ n = 1 := by contrapose! h' replace h' : 2 ≤ n := by omega have : x * x ∣ x ^ n := by rw [← sq]; exact pow_dvd_pow x h' exact h.squarefree_of_dvd this x (refl _) section SquarefreeGcdOfSquarefree variable {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] theorem Squarefree.gcd_right (a : α) {b : α} (hb : Squarefree b) : Squarefree (gcd a b) := hb.squarefree_of_dvd (gcd_dvd_right _ _) theorem Squarefree.gcd_left {a : α} (b : α) (ha : Squarefree a) : Squarefree (gcd a b) := ha.squarefree_of_dvd (gcd_dvd_left _ _) end SquarefreeGcdOfSquarefree namespace multiplicity section CommMonoid variable [CommMonoid R] [DecidableRel (Dvd.dvd : R → R → Prop)] theorem squarefree_iff_multiplicity_le_one (r : R) : Squarefree r ↔ ∀ x : R, multiplicity x r ≤ 1 ∨ IsUnit x := by refine forall_congr' fun a => ?_ rw [← sq, pow_dvd_iff_le_multiplicity, or_iff_not_imp_left, not_le, imp_congr _ Iff.rfl] norm_cast rw [← one_add_one_eq_two] simpa using PartENat.add_one_le_iff_lt (PartENat.natCast_ne_top 1) end CommMonoid section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero R] [WfDvdMonoid R] theorem finite_prime_left {a b : R} (ha : Prime a) (hb : b ≠ 0) : multiplicity.Finite a b := finite_of_not_isUnit ha.not_unit hb end CancelCommMonoidWithZero end multiplicity section Irreducible variable [CommMonoidWithZero R] [WfDvdMonoid R] theorem squarefree_iff_no_irreducibles {x : R} (hx₀ : x ≠ 0) : Squarefree x ↔ ∀ p, Irreducible p → ¬ (p * p ∣ x) := by refine ⟨fun h p hp hp' ↦ hp.not_unit (h p hp'), fun h d hd ↦ by_contra fun hdu ↦ ?_⟩ have hd₀ : d ≠ 0 := ne_zero_of_dvd_ne_zero (ne_zero_of_dvd_ne_zero hx₀ hd) (dvd_mul_left d d) obtain ⟨p, irr, dvd⟩ := WfDvdMonoid.exists_irreducible_factor hdu hd₀ exact h p irr ((mul_dvd_mul dvd dvd).trans hd) theorem irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree (r : R) : (∀ x : R, Irreducible x → ¬x * x ∣ r) ↔ (r = 0 ∧ ∀ x : R, ¬Irreducible x) ∨ Squarefree r := by refine ⟨fun h ↦ ?_, ?_⟩ · rcases eq_or_ne r 0 with (rfl | hr) · exact .inl (by simpa using h) · exact .inr ((squarefree_iff_no_irreducibles hr).mpr h) · rintro (⟨rfl, h⟩ | h) · simpa using h intro x hx t exact hx.not_unit (h x t) theorem squarefree_iff_irreducible_sq_not_dvd_of_ne_zero {r : R} (hr : r ≠ 0) : Squarefree r ↔ ∀ x : R, Irreducible x → ¬x * x ∣ r := by simpa [hr] using (irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree r).symm theorem squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible {r : R} (hr : ∃ x : R, Irreducible x) : Squarefree r ↔ ∀ x : R, Irreducible x → ¬x * x ∣ r := by rw [irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree, ← not_exists] simp only [hr, not_true, false_or_iff, and_false_iff] end Irreducible section IsRadical section variable [CommMonoidWithZero R] [DecompositionMonoid R] theorem Squarefree.isRadical {x : R} (hx : Squarefree x) : IsRadical x := (isRadical_iff_pow_one_lt 2 one_lt_two).2 fun y hy ↦ by obtain ⟨a, b, ha, hb, rfl⟩ := exists_dvd_and_dvd_of_dvd_mul (sq y ▸ hy) exact (IsRelPrime.of_squarefree_mul hx).mul_dvd ha hb theorem Squarefree.dvd_pow_iff_dvd {x y : R} {n : ℕ} (hsq : Squarefree x) (h0 : n ≠ 0) : x ∣ y ^ n ↔ x ∣ y := ⟨hsq.isRadical n y, (·.pow h0)⟩ @[deprecated (since := "2024-02-12")] alias UniqueFactorizationMonoid.dvd_pow_iff_dvd_of_squarefree := Squarefree.dvd_pow_iff_dvd end variable [CancelCommMonoidWithZero R] {x y p d : R} theorem IsRadical.squarefree (h0 : x ≠ 0) (h : IsRadical x) : Squarefree x := by rintro z ⟨w, rfl⟩ specialize h 2 (z * w) ⟨w, by simp_rw [pow_two, mul_left_comm, ← mul_assoc]⟩ rwa [← one_mul (z * w), mul_assoc, mul_dvd_mul_iff_right, ← isUnit_iff_dvd_one] at h rw [mul_assoc, mul_ne_zero_iff] at h0; exact h0.2 namespace Squarefree theorem pow_dvd_of_squarefree_of_pow_succ_dvd_mul_right {k : ℕ} (hx : Squarefree x) (hp : Prime p) (h : p ^ (k + 1) ∣ x * y) : p ^ k ∣ y := by by_cases hxp : p ∣ x · obtain ⟨x', rfl⟩ := hxp have hx' : ¬ p ∣ x' := fun contra ↦ hp.not_unit <| hx p (mul_dvd_mul_left p contra) replace h : p ^ k ∣ x' * y := by rw [pow_succ', mul_assoc] at h exact (mul_dvd_mul_iff_left hp.ne_zero).mp h exact hp.pow_dvd_of_dvd_mul_left _ hx' h · exact (pow_dvd_pow _ k.le_succ).trans (hp.pow_dvd_of_dvd_mul_left _ hxp h) theorem pow_dvd_of_squarefree_of_pow_succ_dvd_mul_left {k : ℕ} (hy : Squarefree y) (hp : Prime p) (h : p ^ (k + 1) ∣ x * y) : p ^ k ∣ x := by rw [mul_comm] at h exact pow_dvd_of_squarefree_of_pow_succ_dvd_mul_right hy hp h variable [DecompositionMonoid R] theorem dvd_of_squarefree_of_mul_dvd_mul_right (hx : Squarefree x) (h : d * d ∣ x * y) : d ∣ y := by nontriviality R obtain ⟨a, b, ha, hb, eq⟩ := exists_dvd_and_dvd_of_dvd_mul h replace ha : Squarefree a := hx.squarefree_of_dvd ha obtain ⟨c, hc⟩ : a ∣ d := ha.isRadical 2 d ⟨b, by rw [sq, eq]⟩ rw [hc, mul_assoc, (mul_right_injective₀ ha.ne_zero).eq_iff] at eq exact dvd_trans ⟨c, by rw [hc, ← eq, mul_comm]⟩ hb theorem dvd_of_squarefree_of_mul_dvd_mul_left (hy : Squarefree y) (h : d * d ∣ x * y) : d ∣ x := dvd_of_squarefree_of_mul_dvd_mul_right hy (mul_comm x y ▸ h) end Squarefree variable [DecompositionMonoid R] /-- `x * y` is square-free iff `x` and `y` have no common factors and are themselves square-free. -/ theorem squarefree_mul_iff : Squarefree (x * y) ↔ IsRelPrime x y ∧ Squarefree x ∧ Squarefree y := ⟨fun h ↦ ⟨IsRelPrime.of_squarefree_mul h, h.of_mul_left, h.of_mul_right⟩, fun ⟨hp, sqx, sqy⟩ _ dvd ↦ hp (sqy.dvd_of_squarefree_of_mul_dvd_mul_left dvd) (sqx.dvd_of_squarefree_of_mul_dvd_mul_right dvd)⟩ theorem isRadical_iff_squarefree_or_zero : IsRadical x ↔ Squarefree x ∨ x = 0 := ⟨fun hx ↦ (em <| x = 0).elim .inr fun h ↦ .inl <| hx.squarefree h, Or.rec Squarefree.isRadical <| by rintro rfl rw [zero_isRadical_iff] infer_instance⟩ theorem isRadical_iff_squarefree_of_ne_zero (h : x ≠ 0) : IsRadical x ↔ Squarefree x := ⟨IsRadical.squarefree h, Squarefree.isRadical⟩ end IsRadical namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R] lemma _root_.exists_squarefree_dvd_pow_of_ne_zero {x : R} (hx : x ≠ 0) : ∃ (y : R) (n : ℕ), Squarefree y ∧ y ∣ x ∧ x ∣ y ^ n := by induction' x using WfDvdMonoid.induction_on_irreducible with u hu z p hz hp ih · contradiction · exact ⟨1, 0, squarefree_one, one_dvd u, hu.dvd⟩ · obtain ⟨y, n, hy, hyx, hy'⟩ := ih hz rcases n.eq_zero_or_pos with rfl | hn · exact ⟨p, 1, hp.squarefree, dvd_mul_right p z, by simp [isUnit_of_dvd_one (pow_zero y ▸ hy')]⟩ by_cases hp' : p ∣ y · exact ⟨y, n + 1, hy, dvd_mul_of_dvd_right hyx _, mul_comm p z ▸ pow_succ y n ▸ mul_dvd_mul hy' hp'⟩ · suffices Squarefree (p * y) from ⟨p * y, n, this, mul_dvd_mul_left p hyx, mul_pow p y n ▸ mul_dvd_mul (dvd_pow_self p hn.ne') hy'⟩ exact squarefree_mul_iff.mpr ⟨hp.isRelPrime_iff_not_dvd.mpr hp', hp.squarefree, hy⟩ theorem squarefree_iff_nodup_normalizedFactors [NormalizationMonoid R] {x : R} (x0 : x ≠ 0) : Squarefree x ↔ Multiset.Nodup (normalizedFactors x) := by classical rw [multiplicity.squarefree_iff_multiplicity_le_one, Multiset.nodup_iff_count_le_one] haveI := nontrivial_of_ne x 0 x0 constructor <;> intro h a · by_cases hmem : a ∈ normalizedFactors x · have ha := irreducible_of_normalized_factor _ hmem rcases h a with (h | h) · rw [← normalize_normalized_factor _ hmem] rw [multiplicity_eq_count_normalizedFactors ha x0] at h assumption_mod_cast · have := ha.1 contradiction · simp [Multiset.count_eq_zero_of_not_mem hmem] · rw [or_iff_not_imp_right] intro hu rcases eq_or_ne a 0 with rfl | h0 · simp [x0] rcases WfDvdMonoid.exists_irreducible_factor hu h0 with ⟨b, hib, hdvd⟩ apply le_trans (multiplicity.multiplicity_le_multiplicity_of_dvd_left hdvd) rw [multiplicity_eq_count_normalizedFactors hib x0] exact_mod_cast h (normalize b) end UniqueFactorizationMonoid namespace Int @[simp] theorem squarefree_natAbs {n : ℤ} : Squarefree n.natAbs ↔ Squarefree n := by simp_rw [Squarefree, natAbs_surjective.forall, ← natAbs_mul, natAbs_dvd_natAbs, isUnit_iff_natAbs_eq, Nat.isUnit_iff] @[simp] theorem squarefree_natCast {n : ℕ} : Squarefree (n : ℤ) ↔ Squarefree n := by rw [← squarefree_natAbs, natAbs_ofNat] @[deprecated (since := "2024-04-05")] alias squarefree_coe_nat := squarefree_natCast end Int
Algebra\Star\Basic.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Group.Invertible.Defs import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Regular.Basic import Mathlib.Algebra.Ring.Aut import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Ring.Opposite import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.SetLike.Basic /-! # Star monoids, rings, and modules We introduce the basic algebraic notions of star monoids, star rings, and star modules. A star algebra is simply a star ring that is also a star module. These are implemented as "mixin" typeclasses, so to summon a star ring (for example) one needs to write `(R : Type*) [Ring R] [StarRing R]`. This avoids difficulties with diamond inheritance. For now we simply do not introduce notations, as different users are expected to feel strongly about the relative merits of `r^*`, `r†`, `rᘁ`, and so on. Our star rings are actually star non-unital, non-associative, semirings, but of course we can prove `star_neg : star (-r) = - star r` when the underlying semiring is a ring. -/ assert_not_exists Finset assert_not_exists Subgroup assert_not_exists Rat.instField universe u v w open MulOpposite open scoped NNRat /-- Notation typeclass (with no default notation!) for an algebraic structure with a star operation. -/ class Star (R : Type u) where star : R → R -- https://github.com/leanprover/lean4/issues/2096 compile_def% Star.star variable {R : Type u} export Star (star) /-- A star operation (e.g. complex conjugate). -/ add_decl_doc star /-- `StarMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under star. -/ class StarMemClass (S R : Type*) [Star R] [SetLike S R] : Prop where /-- Closure under star. -/ star_mem : ∀ {s : S} {r : R}, r ∈ s → star r ∈ s export StarMemClass (star_mem) attribute [aesop safe apply (rule_sets := [SetLike])] star_mem namespace StarMemClass variable {S : Type w} [Star R] [SetLike S R] [hS : StarMemClass S R] (s : S) instance instStar : Star s where star r := ⟨star (r : R), star_mem r.prop⟩ @[simp] lemma coe_star (x : s) : star x = star (x : R) := rfl end StarMemClass /-- Typeclass for a star operation with is involutive. -/ class InvolutiveStar (R : Type u) extends Star R where /-- Involutive condition. -/ star_involutive : Function.Involutive star export InvolutiveStar (star_involutive) @[simp] theorem star_star [InvolutiveStar R] (r : R) : star (star r) = r := star_involutive _ theorem star_injective [InvolutiveStar R] : Function.Injective (star : R → R) := Function.Involutive.injective star_involutive @[simp] theorem star_inj [InvolutiveStar R] {x y : R} : star x = star y ↔ x = y := star_injective.eq_iff /-- `star` as an equivalence when it is involutive. -/ protected def Equiv.star [InvolutiveStar R] : Equiv.Perm R := star_involutive.toPerm _ theorem eq_star_of_eq_star [InvolutiveStar R] {r s : R} (h : r = star s) : s = star r := by simp [h] theorem eq_star_iff_eq_star [InvolutiveStar R] {r s : R} : r = star s ↔ s = star r := ⟨eq_star_of_eq_star, eq_star_of_eq_star⟩ theorem star_eq_iff_star_eq [InvolutiveStar R] {r s : R} : star r = s ↔ star s = r := eq_comm.trans <| eq_star_iff_eq_star.trans eq_comm /-- Typeclass for a trivial star operation. This is mostly meant for `ℝ`. -/ class TrivialStar (R : Type u) [Star R] : Prop where /-- Condition that star is trivial-/ star_trivial : ∀ r : R, star r = r export TrivialStar (star_trivial) attribute [simp] star_trivial /-- A `*`-magma is a magma `R` with an involutive operation `star` such that `star (r * s) = star s * star r`. -/ class StarMul (R : Type u) [Mul R] extends InvolutiveStar R where /-- `star` skew-distributes over multiplication. -/ star_mul : ∀ r s : R, star (r * s) = star s * star r export StarMul (star_mul) attribute [simp 900] star_mul section StarMul variable [Mul R] [StarMul R] theorem star_star_mul (x y : R) : star (star x * y) = star y * x := by rw [star_mul, star_star] theorem star_mul_star (x y : R) : star (x * star y) = y * star x := by rw [star_mul, star_star] @[simp] theorem semiconjBy_star_star_star {x y z : R} : SemiconjBy (star x) (star z) (star y) ↔ SemiconjBy x y z := by simp_rw [SemiconjBy, ← star_mul, star_inj, eq_comm] alias ⟨_, SemiconjBy.star_star_star⟩ := semiconjBy_star_star_star @[simp] theorem commute_star_star {x y : R} : Commute (star x) (star y) ↔ Commute x y := semiconjBy_star_star_star alias ⟨_, Commute.star_star⟩ := commute_star_star theorem commute_star_comm {x y : R} : Commute (star x) y ↔ Commute x (star y) := by rw [← commute_star_star, star_star] end StarMul /-- In a commutative ring, make `simp` prefer leaving the order unchanged. -/ @[simp] theorem star_mul' [CommSemigroup R] [StarMul R] (x y : R) : star (x * y) = star x * star y := (star_mul x y).trans (mul_comm _ _) /-- `star` as a `MulEquiv` from `R` to `Rᵐᵒᵖ` -/ @[simps apply] def starMulEquiv [Mul R] [StarMul R] : R ≃* Rᵐᵒᵖ := { (InvolutiveStar.star_involutive.toPerm star).trans opEquiv with toFun := fun x => MulOpposite.op (star x) map_mul' := fun x y => by simp only [star_mul, op_mul] } /-- `star` as a `MulAut` for commutative `R`. -/ @[simps apply] def starMulAut [CommSemigroup R] [StarMul R] : MulAut R := { InvolutiveStar.star_involutive.toPerm star with toFun := star map_mul' := star_mul' } variable (R) @[simp] theorem star_one [MulOneClass R] [StarMul R] : star (1 : R) = 1 := op_injective <| (starMulEquiv : R ≃* Rᵐᵒᵖ).map_one.trans op_one.symm variable {R} @[simp] theorem star_pow [Monoid R] [StarMul R] (x : R) (n : ℕ) : star (x ^ n) = star x ^ n := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_pow x n).trans (op_pow (star x) n).symm @[simp] theorem star_inv [Group R] [StarMul R] (x : R) : star x⁻¹ = (star x)⁻¹ := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_inv x).trans (op_inv (star x)).symm @[simp] theorem star_zpow [Group R] [StarMul R] (x : R) (z : ℤ) : star (x ^ z) = star x ^ z := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_zpow x z).trans (op_zpow (star x) z).symm /-- When multiplication is commutative, `star` preserves division. -/ @[simp] theorem star_div [CommGroup R] [StarMul R] (x y : R) : star (x / y) = star x / star y := map_div (starMulAut : R ≃* R) _ _ /-- Any commutative monoid admits the trivial `*`-structure. See note [reducible non-instances]. -/ abbrev starMulOfComm {R : Type*} [CommMonoid R] : StarMul R where star := id star_involutive _ := rfl star_mul := mul_comm section attribute [local instance] starMulOfComm /-- Note that since `starMulOfComm` is reducible, `simp` can already prove this. -/ theorem star_id_of_comm {R : Type*} [CommSemiring R] {x : R} : star x = x := rfl end /-- A `*`-additive monoid `R` is an additive monoid with an involutive `star` operation which preserves addition. -/ class StarAddMonoid (R : Type u) [AddMonoid R] extends InvolutiveStar R where /-- `star` commutes with addition -/ star_add : ∀ r s : R, star (r + s) = star r + star s export StarAddMonoid (star_add) attribute [simp] star_add /-- `star` as an `AddEquiv` -/ @[simps apply] def starAddEquiv [AddMonoid R] [StarAddMonoid R] : R ≃+ R := { InvolutiveStar.star_involutive.toPerm star with toFun := star map_add' := star_add } variable (R) @[simp] theorem star_zero [AddMonoid R] [StarAddMonoid R] : star (0 : R) = 0 := (starAddEquiv : R ≃+ R).map_zero variable {R} @[simp] theorem star_eq_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x = 0 ↔ x = 0 := starAddEquiv.map_eq_zero_iff (M := R) theorem star_ne_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x ≠ 0 ↔ x ≠ 0 := by simp only [ne_eq, star_eq_zero] @[simp] theorem star_neg [AddGroup R] [StarAddMonoid R] (r : R) : star (-r) = -star r := (starAddEquiv : R ≃+ R).map_neg _ @[simp] theorem star_sub [AddGroup R] [StarAddMonoid R] (r s : R) : star (r - s) = star r - star s := (starAddEquiv : R ≃+ R).map_sub _ _ @[simp] theorem star_nsmul [AddMonoid R] [StarAddMonoid R] (x : R) (n : ℕ) : star (n • x) = n • star x := (starAddEquiv : R ≃+ R).toAddMonoidHom.map_nsmul _ _ @[simp] theorem star_zsmul [AddGroup R] [StarAddMonoid R] (x : R) (n : ℤ) : star (n • x) = n • star x := (starAddEquiv : R ≃+ R).toAddMonoidHom.map_zsmul _ _ /-- A `*`-ring `R` is a non-unital, non-associative (semi)ring with an involutive `star` operation which is additive which makes `R` with its multiplicative structure into a `*`-multiplication (i.e. `star (r * s) = star s * star r`). -/ class StarRing (R : Type u) [NonUnitalNonAssocSemiring R] extends StarMul R where /-- `star` commutes with addition -/ star_add : ∀ r s : R, star (r + s) = star r + star s instance (priority := 100) StarRing.toStarAddMonoid [NonUnitalNonAssocSemiring R] [StarRing R] : StarAddMonoid R where star_add := StarRing.star_add /-- `star` as a `RingEquiv` from `R` to `Rᵐᵒᵖ` -/ @[simps apply] def starRingEquiv [NonUnitalNonAssocSemiring R] [StarRing R] : R ≃+* Rᵐᵒᵖ := { starAddEquiv.trans (MulOpposite.opAddEquiv : R ≃+ Rᵐᵒᵖ), starMulEquiv with toFun := fun x => MulOpposite.op (star x) } @[simp, norm_cast] theorem star_natCast [NonAssocSemiring R] [StarRing R] (n : ℕ) : star (n : R) = n := (congr_arg unop (map_natCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) n)).trans (unop_natCast _) @[simp] theorem star_ofNat [NonAssocSemiring R] [StarRing R] (n : ℕ) [n.AtLeastTwo] : star (no_index (OfNat.ofNat n) : R) = OfNat.ofNat n := star_natCast _ section @[simp, norm_cast] theorem star_intCast [Ring R] [StarRing R] (z : ℤ) : star (z : R) = z := (congr_arg unop <| map_intCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) z).trans (unop_intCast _) end section CommSemiring variable [CommSemiring R] [StarRing R] /-- `star` as a ring automorphism, for commutative `R`. -/ @[simps apply] def starRingAut : RingAut R := { starAddEquiv, starMulAut (R := R) with toFun := star } variable (R) /-- `star` as a ring endomorphism, for commutative `R`. This is used to denote complex conjugation, and is available under the notation `conj` in the locale `ComplexConjugate`. Note that this is the preferred form (over `starRingAut`, available under the same hypotheses) because the notation `E →ₗ⋆[R] F` for an `R`-conjugate-linear map (short for `E →ₛₗ[starRingEnd R] F`) does not pretty-print if there is a coercion involved, as would be the case for `(↑starRingAut : R →* R)`. -/ def starRingEnd : R →+* R := @starRingAut R _ _ variable {R} @[inherit_doc] scoped[ComplexConjugate] notation "conj" => starRingEnd _ /-- This is not a simp lemma, since we usually want simp to keep `starRingEnd` bundled. For example, for complex conjugation, we don't want simp to turn `conj x` into the bare function `star x` automatically since most lemmas are about `conj x`. -/ theorem starRingEnd_apply (x : R) : starRingEnd R x = star x := rfl /- Porting note (#11119): removed `simp` attribute due to report by linter: simp can prove this: by simp only [RingHomCompTriple.comp_apply, RingHom.id_apply] One of the lemmas above could be a duplicate. If that's not the case try reordering lemmas or adding @[priority]. -/ -- @[simp] theorem starRingEnd_self_apply (x : R) : starRingEnd R (starRingEnd R x) = x := star_star x instance RingHom.involutiveStar {S : Type*} [NonAssocSemiring S] : InvolutiveStar (S →+* R) where toStar := { star := fun f => RingHom.comp (starRingEnd R) f } star_involutive := by intro ext simp only [RingHom.coe_comp, Function.comp_apply, starRingEnd_self_apply] theorem RingHom.star_def {S : Type*} [NonAssocSemiring S] (f : S →+* R) : Star.star f = RingHom.comp (starRingEnd R) f := rfl theorem RingHom.star_apply {S : Type*} [NonAssocSemiring S] (f : S →+* R) (s : S) : star f s = star (f s) := rfl -- A more convenient name for complex conjugation alias Complex.conj_conj := starRingEnd_self_apply alias RCLike.conj_conj := starRingEnd_self_apply open scoped ComplexConjugate @[simp] lemma conj_trivial [TrivialStar R] (a : R) : conj a = a := star_trivial _ end CommSemiring @[simp] theorem star_inv' [DivisionSemiring R] [StarRing R] (x : R) : star x⁻¹ = (star x)⁻¹ := op_injective <| (map_inv₀ (starRingEquiv : R ≃+* Rᵐᵒᵖ) x).trans (op_inv (star x)).symm @[simp] theorem star_zpow₀ [DivisionSemiring R] [StarRing R] (x : R) (z : ℤ) : star (x ^ z) = star x ^ z := op_injective <| (map_zpow₀ (starRingEquiv : R ≃+* Rᵐᵒᵖ) x z).trans (op_zpow (star x) z).symm /-- When multiplication is commutative, `star` preserves division. -/ @[simp] theorem star_div' [Semifield R] [StarRing R] (x y : R) : star (x / y) = star x / star y := by apply op_injective rw [division_def, op_div, mul_comm, star_mul, star_inv', op_mul, op_inv] /-- Any commutative semiring admits the trivial `*`-structure. See note [reducible non-instances]. -/ abbrev starRingOfComm {R : Type*} [CommSemiring R] : StarRing R := { starMulOfComm with star_add := fun _ _ => rfl } instance Nat.instStarRing : StarRing ℕ := starRingOfComm instance Int.instStarRing : StarRing ℤ := starRingOfComm instance Nat.instTrivialStar : TrivialStar ℕ := ⟨fun _ ↦ rfl⟩ instance Int.instTrivialStar : TrivialStar ℤ := ⟨fun _ ↦ rfl⟩ /-- A star module `A` over a star ring `R` is a module which is a star add monoid, and the two star structures are compatible in the sense `star (r • a) = star r • star a`. Note that it is up to the user of this typeclass to enforce `[Semiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A]`, and that the statement only requires `[Star R] [Star A] [SMul R A]`. If used as `[CommRing R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A]`, this represents a star algebra. -/ class StarModule (R : Type u) (A : Type v) [Star R] [Star A] [SMul R A] : Prop where /-- `star` commutes with scalar multiplication -/ star_smul : ∀ (r : R) (a : A), star (r • a) = star r • star a export StarModule (star_smul) attribute [simp] star_smul /-- A commutative star monoid is a star module over itself via `Monoid.toMulAction`. -/ instance StarMul.toStarModule [CommMonoid R] [StarMul R] : StarModule R R := ⟨star_mul'⟩ instance StarAddMonoid.toStarModuleNat {α} [AddCommMonoid α] [StarAddMonoid α] : StarModule ℕ α := ⟨fun n a ↦ by rw [star_nsmul, star_trivial n]⟩ namespace RingHomInvPair /-- Instance needed to define star-linear maps over a commutative star ring (ex: conjugate-linear maps when R = ℂ). -/ instance [CommSemiring R] [StarRing R] : RingHomInvPair (starRingEnd R) (starRingEnd R) := ⟨RingHom.ext star_star, RingHom.ext star_star⟩ end RingHomInvPair section /-- `StarHomClass F R S` states that `F` is a type of `star`-preserving maps from `R` to `S`. -/ class StarHomClass (F : Type*) (R S : outParam Type*) [Star R] [Star S] [FunLike F R S] : Prop where /-- the maps preserve star -/ map_star : ∀ (f : F) (r : R), f (star r) = star (f r) export StarHomClass (map_star) end /-! ### Instances -/ namespace Units variable [Monoid R] [StarMul R] instance : StarMul Rˣ where star u := { val := star u inv := star ↑u⁻¹ val_inv := (star_mul _ _).symm.trans <| (congr_arg star u.inv_val).trans <| star_one _ inv_val := (star_mul _ _).symm.trans <| (congr_arg star u.val_inv).trans <| star_one _ } star_involutive _ := Units.ext (star_involutive _) star_mul _ _ := Units.ext (star_mul _ _) @[simp] theorem coe_star (u : Rˣ) : ↑(star u) = (star ↑u : R) := rfl @[simp] theorem coe_star_inv (u : Rˣ) : ↑(star u)⁻¹ = (star ↑u⁻¹ : R) := rfl instance {A : Type*} [Star A] [SMul R A] [StarModule R A] : StarModule Rˣ A := ⟨fun u a => star_smul (u : R) a⟩ end Units protected theorem IsUnit.star [Monoid R] [StarMul R] {a : R} : IsUnit a → IsUnit (star a) | ⟨u, hu⟩ => ⟨Star.star u, hu ▸ rfl⟩ @[simp] theorem isUnit_star [Monoid R] [StarMul R] {a : R} : IsUnit (star a) ↔ IsUnit a := ⟨fun h => star_star a ▸ h.star, IsUnit.star⟩ theorem Ring.inverse_star [Semiring R] [StarRing R] (a : R) : Ring.inverse (star a) = star (Ring.inverse a) := by by_cases ha : IsUnit a · obtain ⟨u, rfl⟩ := ha rw [Ring.inverse_unit, ← Units.coe_star, Ring.inverse_unit, ← Units.coe_star_inv] rw [Ring.inverse_non_unit _ ha, Ring.inverse_non_unit _ (mt isUnit_star.mp ha), star_zero] protected instance Invertible.star {R : Type*} [MulOneClass R] [StarMul R] (r : R) [Invertible r] : Invertible (star r) where invOf := Star.star (⅟ r) invOf_mul_self := by rw [← star_mul, mul_invOf_self, star_one] mul_invOf_self := by rw [← star_mul, invOf_mul_self, star_one] theorem star_invOf {R : Type*} [Monoid R] [StarMul R] (r : R) [Invertible r] [Invertible (star r)] : star (⅟ r) = ⅟ (star r) := by have : star (⅟ r) = star (⅟ r) * ((star r) * ⅟ (star r)) := by simp only [mul_invOf_self, mul_one] rw [this, ← mul_assoc] have : (star (⅟ r)) * (star r) = star 1 := by rw [← star_mul, mul_invOf_self] rw [this, star_one, one_mul] section Regular protected theorem IsLeftRegular.star [Mul R] [StarMul R] {x : R} (hx : IsLeftRegular x) : IsRightRegular (star x) := fun a b h => star_injective <| hx <| by simpa using congr_arg Star.star h protected theorem IsRightRegular.star [Mul R] [StarMul R] {x : R} (hx : IsRightRegular x) : IsLeftRegular (star x) := fun a b h => star_injective <| hx <| by simpa using congr_arg Star.star h protected theorem IsRegular.star [Mul R] [StarMul R] {x : R} (hx : IsRegular x) : IsRegular (star x) := ⟨hx.right.star, hx.left.star⟩ @[simp] theorem isRightRegular_star_iff [Mul R] [StarMul R] {x : R} : IsRightRegular (star x) ↔ IsLeftRegular x := ⟨fun h => star_star x ▸ h.star, (·.star)⟩ @[simp] theorem isLeftRegular_star_iff [Mul R] [StarMul R] {x : R} : IsLeftRegular (star x) ↔ IsRightRegular x := ⟨fun h => star_star x ▸ h.star, (·.star)⟩ @[simp] theorem isRegular_star_iff [Mul R] [StarMul R] {x : R} : IsRegular (star x) ↔ IsRegular x := by rw [isRegular_iff, isRegular_iff, isRightRegular_star_iff, isLeftRegular_star_iff, and_comm] end Regular namespace MulOpposite /-- The opposite type carries the same star operation. -/ instance [Star R] : Star Rᵐᵒᵖ where star r := op (star r.unop) @[simp] theorem unop_star [Star R] (r : Rᵐᵒᵖ) : unop (star r) = star (unop r) := rfl @[simp] theorem op_star [Star R] (r : R) : op (star r) = star (op r) := rfl instance [InvolutiveStar R] : InvolutiveStar Rᵐᵒᵖ where star_involutive r := unop_injective (star_star r.unop) instance [Mul R] [StarMul R] : StarMul Rᵐᵒᵖ where star_mul x y := unop_injective (star_mul y.unop x.unop) instance [AddMonoid R] [StarAddMonoid R] : StarAddMonoid Rᵐᵒᵖ where star_add x y := unop_injective (star_add x.unop y.unop) instance [Semiring R] [StarRing R] : StarRing Rᵐᵒᵖ where star_add x y := unop_injective (star_add x.unop y.unop) end MulOpposite /-- A commutative star monoid is a star module over its opposite via `Monoid.toOppositeMulAction`. -/ instance StarSemigroup.toOpposite_starModule [CommMonoid R] [StarMul R] : StarModule Rᵐᵒᵖ R := ⟨fun r s => star_mul' s r.unop⟩
Algebra\Star\BigOperators.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Star.Basic /-! # Big-operators lemmas about `star` algebraic operations These results are kept separate from `Algebra.Star.Basic` to avoid it needing to import `Finset`. -/ variable {R : Type*} @[simp] theorem star_prod [CommMonoid R] [StarMul R] {α : Type*} (s : Finset α) (f : α → R) : star (∏ x ∈ s, f x) = ∏ x ∈ s, star (f x) := map_prod (starMulAut : R ≃* R) _ _ @[simp] theorem star_sum [AddCommMonoid R] [StarAddMonoid R] {α : Type*} (s : Finset α) (f : α → R) : star (∑ x ∈ s, f x) = ∑ x ∈ s, star (f x) := map_sum (starAddEquiv : R ≃+ R) _ _
Algebra\Star\Center.lean
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.Star.Pointwise import Mathlib.Algebra.Group.Center /-! # `Set.center`, `Set.centralizer` and the `star` operation -/ variable {R : Type*} [Mul R] [StarMul R] {a : R} {s : Set R} theorem Set.star_mem_center (ha : a ∈ Set.center R) : star a ∈ Set.center R where comm := by simpa only [star_mul, star_star] using fun g => congr_arg star ((mem_center_iff.1 ha).comm <| star g).symm left_assoc b c := calc star a * (b * c) = star a * (star (star b) * star (star c)) := by rw [star_star, star_star] _ = star a * star (star c * star b) := by rw [star_mul] _ = star ((star c * star b) * a) := by rw [← star_mul] _ = star (star c * (star b * a)) := by rw [ha.right_assoc] _ = star (star b * a) * c := by rw [star_mul, star_star] _ = (star a * b) * c := by rw [star_mul, star_star] mid_assoc b c := calc b * star a * c = star (star c * star (b * star a)) := by rw [← star_mul, star_star] _ = star (star c * (a * star b)) := by rw [star_mul b, star_star] _ = star ((star c * a) * star b) := by rw [ha.mid_assoc] _ = b * (star a * c) := by rw [star_mul, star_star, star_mul (star c), star_star] right_assoc b c := calc b * c * star a = star (a * star (b * c)) := by rw [star_mul, star_star] _ = star (a * (star c * star b)) := by rw [star_mul b] _ = star ((a * star c) * star b) := by rw [ha.left_assoc] _ = b * star (a * star c) := by rw [star_mul, star_star] _ = b * (c * star a) := by rw [star_mul, star_star] theorem Set.star_mem_centralizer' (h : ∀ a : R, a ∈ s → star a ∈ s) (ha : a ∈ Set.centralizer s) : star a ∈ Set.centralizer s := fun y hy => by simpa using congr_arg star (ha _ (h _ hy)).symm open scoped Pointwise theorem Set.star_mem_centralizer (ha : a ∈ Set.centralizer (s ∪ star s)) : star a ∈ Set.centralizer (s ∪ star s) := Set.star_mem_centralizer' (fun _x hx => hx.elim (fun hx => Or.inr <| Set.star_mem_star.mpr hx) Or.inl) ha
Algebra\Star\CentroidHom.lean
/- Copyright (c) 2024 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Algebra.Ring.CentroidHom import Mathlib.Algebra.Star.StarRingHom import Mathlib.Algebra.Star.Subsemiring import Mathlib.Algebra.Star.Basic /-! # Centroid homomorphisms on Star Rings When a (non unital, non-associative) semi-ring is equipped with an involutive automorphism the center of the centroid becomes a star ring in a natural way and the natural mapping of the centre of the semi-ring into the centre of the centroid becomes a *-homomorphism. ## Tags centroid -/ variable {α : Type*} namespace CentroidHom section NonUnitalNonAssocStarSemiring variable [NonUnitalNonAssocSemiring α] [StarRing α] instance : Star (CentroidHom α) where star f := { toFun := fun a => star (f (star a)) map_zero' := by simp only [star_zero, map_zero] map_add' := fun a b => by simp only [star_add, map_add] map_mul_left' := fun a b => by simp only [star_mul, map_mul_right, star_star] map_mul_right' := fun a b => by simp only [star_mul, map_mul_left, star_star] } @[simp] lemma star_apply (f : CentroidHom α) (a : α) : (star f) a = star (f (star a)) := rfl instance instStarAddMonoid : StarAddMonoid (CentroidHom α) where star_involutive f := ext (fun _ => by rw [star_apply, star_apply, star_star, star_star]) star_add f g := ext fun _ => star_add _ _ instance : Star (Subsemiring.center (CentroidHom α)) where star f := ⟨star (f : CentroidHom α), Subsemiring.mem_center_iff.mpr (fun g => ext (fun a => calc g (star (f (star a))) = star (star g (f (star a))) := by rw [star_apply, star_star] _ = star ((star g * f) (star a)) := rfl _ = star ((f * star g) (star a)) := by rw [f.property.comm] _ = star (f (star g (star a))) := rfl _ = star (f (star (g a))) := by rw [star_apply, star_star]))⟩ instance instStarAddMonoidCenter : StarAddMonoid (Subsemiring.center (CentroidHom α)) where star_involutive f := SetCoe.ext (star_involutive f.val) star_add f g := SetCoe.ext (star_add f.val g.val) instance : StarRing (Subsemiring.center (CentroidHom α)) where __ := instStarAddMonoidCenter star_mul f g := by ext a calc star (f * g) a = star (g * f) a := by rw [CommMonoid.mul_comm f g] _ = star (g (f (star a))) := rfl _ = star (g (star (star (f (star a))))) := by simp only [star_star] _ = (star g * star f) a := rfl /-- The canonical *-homomorphism embedding the center of `CentroidHom α` into `CentroidHom α`. -/ def centerStarEmbedding : Subsemiring.center (CentroidHom α) →⋆ₙ+* CentroidHom α where toNonUnitalRingHom := (SubsemiringClass.subtype (Subsemiring.center (CentroidHom α))).toNonUnitalRingHom map_star' f := by simp only [RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, MonoidHom.coe_coe, SubsemiringClass.coe_subtype] exact rfl theorem star_centerToCentroidCenter (z : NonUnitalStarSubsemiring.center α) : star (centerToCentroidCenter z) = (centerToCentroidCenter (star z : NonUnitalStarSubsemiring.center α)) := by ext a calc (star (centerToCentroidCenter z)) a = star (z * star a) := rfl _ = star (star a) * star z := by simp only [star_mul, star_star, StarMemClass.coe_star] _ = a * star z := by rw [star_star] _ = (star z) * a := by rw [(star z).property.comm] _ = (centerToCentroidCenter ((star z) : NonUnitalStarSubsemiring.center α)) a := rfl /-- The canonical *-homomorphism from the center of a non-unital, non-associative *-semiring into the center of its centroid. -/ def starCenterToCentroidCenter : NonUnitalStarSubsemiring.center α →⋆ₙ+* Subsemiring.center (CentroidHom α) where toNonUnitalRingHom := centerToCentroidCenter map_star' _ := by simp only [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom] exact (star_centerToCentroidCenter _).symm /-- The canonical homomorphism from the center into the centroid -/ def starCenterToCentroid : NonUnitalStarSubsemiring.center α →⋆ₙ+* CentroidHom α := NonUnitalStarRingHom.comp (centerStarEmbedding) (starCenterToCentroidCenter) lemma starCenterToCentroid_apply (z : NonUnitalStarSubsemiring.center α) (a : α) : (starCenterToCentroid z) a = z * a := rfl /-- Let `α` be a star ring with commutative centroid. Then the centroid is a star ring. -/ @[reducible] def starRingOfCommCentroidHom (mul_comm : Std.Commutative (α := CentroidHom α) (· * ·)) : StarRing (CentroidHom α) where __ := instStarAddMonoid star_mul _ _ := ext (fun _ => by rw [mul_comm.comm, star_apply, mul_apply, mul_apply, star_apply, star_apply, star_star]) end NonUnitalNonAssocStarSemiring section NonAssocStarSemiring variable [NonAssocSemiring α] [StarRing α] /-- The canonical isomorphism from the center of a (non-associative) semiring onto its centroid. -/ def starCenterIsoCentroid : StarSubsemiring.center α ≃⋆+* CentroidHom α where __ := starCenterToCentroid invFun T := ⟨T 1, by refine ⟨?_, ?_, ?_, ?_⟩; all_goals simp [← map_mul_left, ← map_mul_right]⟩ left_inv z := Subtype.ext <| by simp only [MulHom.toFun_eq_coe, NonUnitalRingHom.coe_toMulHom, NonUnitalStarRingHom.coe_toNonUnitalRingHom, starCenterToCentroid_apply, mul_one] right_inv T := CentroidHom.ext <| fun _ => by simp [starCenterToCentroid_apply, ← map_mul_right] @[simp] lemma starCenterIsoCentroid_apply (a : ↥(NonUnitalStarSubsemiring.center α)) : CentroidHom.starCenterIsoCentroid a = CentroidHom.starCenterToCentroid a := rfl @[simp] lemma starCenterIsoCentroid_symm_apply_coe (T : CentroidHom α) : ↑(CentroidHom.starCenterIsoCentroid.symm T) = T 1 := rfl end NonAssocStarSemiring end CentroidHom
Algebra\Star\CHSH.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Star.Order import Mathlib.Data.Real.Sqrt import Mathlib.Tactic.Polyrith /-! # The Clauser-Horne-Shimony-Holt inequality and Tsirelson's inequality. We establish a version of the Clauser-Horne-Shimony-Holt (CHSH) inequality (which is a generalization of Bell's inequality). This is a foundational result which implies that quantum mechanics is not a local hidden variable theory. As usually stated the CHSH inequality requires substantial language from physics and probability, but it is possible to give a statement that is purely about ordered `*`-algebras. We do that here, to avoid as many practical and logical dependencies as possible. Since the algebra of observables of any quantum system is an ordered `*`-algebra (in particular a von Neumann algebra) this is a strict generalization of the usual statement. Let `R` be a `*`-ring. A CHSH tuple in `R` consists of * four elements `A₀ A₁ B₀ B₁ : R`, such that * each `Aᵢ` and `Bⱼ` is a self-adjoint involution, and * the `Aᵢ` commute with the `Bⱼ`. The physical interpretation is that the four elements are observables (hence self-adjoint) that take values ±1 (hence involutions), and that the `Aᵢ` are spacelike separated from the `Bⱼ` (and hence commute). The CHSH inequality says that when `R` is an ordered `*`-ring (that is, a `*`-ring which is ordered, and for every `r : R`, `0 ≤ star r * r`), which is moreover *commutative*, we have `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2` On the other hand, Tsirelson's inequality says that for any ordered `*`-ring we have `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2√2` (A caveat: in the commutative case we need 2⁻¹ in the ring, and in the noncommutative case we need √2 and √2⁻¹. To keep things simple we just assume our rings are ℝ-algebras.) The proofs I've seen in the literature either assume a significant framework for quantum mechanics, or assume the ring is a `C^*`-algebra. In the `C^*`-algebra case, the order structure is completely determined by the `*`-algebra structure: `0 ≤ A` iff there exists some `B` so `A = star B * B`. There's a nice proof of both bounds in this setting at https://en.wikipedia.org/wiki/Tsirelson%27s_bound The proof given here is purely algebraic. ## Future work One can show that Tsirelson's inequality is tight. In the `*`-ring of n-by-n complex matrices, if `A ≤ λ I` for some `λ : ℝ`, then every eigenvalue has absolute value at most `λ`. There is a CHSH tuple in 4-by-4 matrices such that `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁` has `2√2` as an eigenvalue. ## References * [Clauser, Horne, Shimony, Holt, *Proposed experiment to test local hidden-variable theories*][zbMATH06785026] * [Bell, *On the Einstein Podolsky Rosen Paradox*][MR3790629] * [Tsirelson, *Quantum generalizations of Bell's inequality*][MR577178] -/ universe u /-- A CHSH tuple in a *-monoid consists of 4 self-adjoint involutions `A₀ A₁ B₀ B₁` such that the `Aᵢ` commute with the `Bⱼ`. The physical interpretation is that `A₀` and `A₁` are a pair of boolean observables which are spacelike separated from another pair `B₀` and `B₁` of boolean observables. -/ --@[nolint has_nonempty_instance] Porting note(#5171): linter not ported yet structure IsCHSHTuple {R} [Monoid R] [StarMul R] (A₀ A₁ B₀ B₁ : R) : Prop where A₀_inv : A₀ ^ 2 = 1 A₁_inv : A₁ ^ 2 = 1 B₀_inv : B₀ ^ 2 = 1 B₁_inv : B₁ ^ 2 = 1 A₀_sa : star A₀ = A₀ A₁_sa : star A₁ = A₁ B₀_sa : star B₀ = B₀ B₁_sa : star B₁ = B₁ A₀B₀_commutes : A₀ * B₀ = B₀ * A₀ A₀B₁_commutes : A₀ * B₁ = B₁ * A₀ A₁B₀_commutes : A₁ * B₀ = B₀ * A₁ A₁B₁_commutes : A₁ * B₁ = B₁ * A₁ variable {R : Type u} theorem CHSH_id [CommRing R] {A₀ A₁ B₀ B₁ : R} (A₀_inv : A₀ ^ 2 = 1) (A₁_inv : A₁ ^ 2 = 1) (B₀_inv : B₀ ^ 2 = 1) (B₁_inv : B₁ ^ 2 = 1) : (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) = 4 * (2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁) := by -- polyrith suggests: linear_combination (2 * B₀ * B₁ + 2) * A₀_inv + (B₀ ^ 2 - 2 * B₀ * B₁ + B₁ ^ 2) * A₁_inv + (A₀ ^ 2 + 2 * A₀ * A₁ + 1) * B₀_inv + (A₀ ^ 2 - 2 * A₀ * A₁ + 1) * B₁_inv /-- Given a CHSH tuple (A₀, A₁, B₀, B₁) in a *commutative* ordered `*`-algebra over ℝ, `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2`. (We could work over ℤ[⅟2] if we wanted to!) -/ theorem CHSH_inequality_of_comm [OrderedCommRing R] [StarRing R] [StarOrderedRing R] [Algebra ℝ R] [OrderedSMul ℝ R] (A₀ A₁ B₀ B₁ : R) (T : IsCHSHTuple A₀ A₁ B₀ B₁) : A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2 := by let P := 2 - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ have i₁ : 0 ≤ P := by have idem : P * P = 4 * P := CHSH_id T.A₀_inv T.A₁_inv T.B₀_inv T.B₁_inv have idem' : P = (1 / 4 : ℝ) • (P * P) := by have h : 4 * P = (4 : ℝ) • P := by simp [Algebra.smul_def] rw [idem, h, ← mul_smul] norm_num have sa : star P = P := by dsimp [P] simp only [star_add, star_sub, star_mul, star_ofNat, star_one, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa, mul_comm B₀, mul_comm B₁] simpa only [← idem', sa] using smul_nonneg (by norm_num : (0 : ℝ) ≤ 1 / 4) (star_mul_self_nonneg P) apply le_of_sub_nonneg simpa only [sub_add_eq_sub_sub, ← sub_add] using i₁ /-! We now prove some rather specialized lemmas in preparation for the Tsirelson inequality, which we hide in a namespace as they are unlikely to be useful elsewhere. -/ namespace TsirelsonInequality /-! Before proving Tsirelson's bound, we prepare some easy lemmas about √2. -/ -- This calculation, which we need for Tsirelson's bound, -- defeated me. Thanks for the rescue from Shing Tak Lam! theorem tsirelson_inequality_aux : √2 * √2 ^ 3 = √2 * (2 * (√2)⁻¹ + 4 * ((√2)⁻¹ * 2⁻¹)) := by ring_nf rw [mul_inv_cancel (ne_of_gt (Real.sqrt_pos.2 (show (2 : ℝ) > 0 by norm_num)))] convert congr_arg (· ^ 2) (@Real.sq_sqrt 2 (by norm_num)) using 1 <;> (try simp only [← pow_mul]) <;> norm_num theorem sqrt_two_inv_mul_self : (√2)⁻¹ * (√2)⁻¹ = (2⁻¹ : ℝ) := by rw [← mul_inv] norm_num end TsirelsonInequality open TsirelsonInequality /-- In a noncommutative ordered `*`-algebra over ℝ, Tsirelson's bound for a CHSH tuple (A₀, A₁, B₀, B₁) is `A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ 2^(3/2) • 1`. We prove this by providing an explicit sum-of-squares decomposition of the difference. (We could work over `ℤ[2^(1/2), 2^(-1/2)]` if we really wanted to!) -/ theorem tsirelson_inequality [OrderedRing R] [StarRing R] [StarOrderedRing R] [Algebra ℝ R] [OrderedSMul ℝ R] [StarModule ℝ R] (A₀ A₁ B₀ B₁ : R) (T : IsCHSHTuple A₀ A₁ B₀ B₁) : A₀ * B₀ + A₀ * B₁ + A₁ * B₀ - A₁ * B₁ ≤ √2 ^ 3 • (1 : R) := by -- abel will create `ℤ` multiplication. We will `simp` them away to `ℝ` multiplication. have M : ∀ (m : ℤ) (a : ℝ) (x : R), m • a • x = ((m : ℝ) * a) • x := fun m a x => by rw [← Int.cast_smul_eq_zsmul ℝ, ← mul_smul] let P := (√2)⁻¹ • (A₁ + A₀) - B₀ let Q := (√2)⁻¹ • (A₁ - A₀) + B₁ have w : √2 ^ 3 • (1 : R) - A₀ * B₀ - A₀ * B₁ - A₁ * B₀ + A₁ * B₁ = (√2)⁻¹ • (P ^ 2 + Q ^ 2) := by dsimp [P, Q] -- distribute out all the powers and products appearing on the RHS simp only [sq, sub_mul, mul_sub, add_mul, mul_add, smul_add, smul_sub] -- pull all coefficients out to the front, and combine `√2`s where possible simp only [Algebra.mul_smul_comm, Algebra.smul_mul_assoc, ← mul_smul, sqrt_two_inv_mul_self] -- replace Aᵢ * Aᵢ = 1 and Bᵢ * Bᵢ = 1 simp only [← sq, T.A₀_inv, T.A₁_inv, T.B₀_inv, T.B₁_inv] -- move Aᵢ to the left of Bᵢ simp only [← T.A₀B₀_commutes, ← T.A₀B₁_commutes, ← T.A₁B₀_commutes, ← T.A₁B₁_commutes] -- collect terms, simplify coefficients, and collect terms again: abel_nf -- all terms coincide, but the last one. Simplify all other terms simp only [M] simp only [neg_mul, one_mul, mul_inv_cancel_of_invertible, Int.cast_one, add_assoc, add_comm, add_left_comm, one_smul, Int.cast_neg, neg_smul, Int.cast_ofNat] simp only [← add_assoc, ← add_smul] -- just look at the coefficients now: congr exact mul_left_cancel₀ (by norm_num) tsirelson_inequality_aux have pos : 0 ≤ (√2)⁻¹ • (P ^ 2 + Q ^ 2) := by have P_sa : star P = P := by simp only [P, star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] have Q_sa : star Q = Q := by simp only [Q, star_smul, star_add, star_sub, star_id_of_comm, T.A₀_sa, T.A₁_sa, T.B₀_sa, T.B₁_sa] have P2_nonneg : 0 ≤ P ^ 2 := by simpa only [P_sa, sq] using star_mul_self_nonneg P have Q2_nonneg : 0 ≤ Q ^ 2 := by simpa only [Q_sa, sq] using star_mul_self_nonneg Q exact smul_nonneg (by positivity) (add_nonneg P2_nonneg Q2_nonneg) apply le_of_sub_nonneg simpa only [sub_add_eq_sub_sub, ← sub_add, w, Nat.cast_zero] using pos
Algebra\Star\Free.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.FreeAlgebra /-! # A *-algebra structure on the free algebra. Reversing words gives a *-structure on the free monoid or on the free algebra on a type. ## Implementation note We have this in a separate file, rather than in `Algebra.FreeMonoid` and `Algebra.FreeAlgebra`, to avoid importing `Algebra.Star.Basic` into the entire hierarchy. -/ namespace FreeMonoid variable {α : Type*} instance : StarMul (FreeMonoid α) where star := List.reverse star_involutive := List.reverse_reverse star_mul := List.reverse_append @[simp] theorem star_of (x : α) : star (of x) = of x := rfl /-- Note that `star_one` is already a global simp lemma, but this one works with dsimp too -/ @[simp] theorem star_one : star (1 : FreeMonoid α) = 1 := rfl end FreeMonoid namespace FreeAlgebra variable {R : Type*} [CommSemiring R] {X : Type*} /-- The star ring formed by reversing the elements of products -/ instance : StarRing (FreeAlgebra R X) where star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R) star_involutive x := by unfold Star.star simp only [Function.comp_apply] let y := lift R (X := X) (MulOpposite.op ∘ ι R) apply induction (C := fun x ↦ (y (y x).unop).unop = x) _ _ _ _ x · intros simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op] · intros simp only [y, lift_ι_apply, Function.comp_apply, MulOpposite.unop_op] · intros simp only [*, map_mul, MulOpposite.unop_mul] · intros simp only [*, map_add, MulOpposite.unop_add] star_mul a b := by simp only [Function.comp_apply, map_mul, MulOpposite.unop_mul] star_add a b := by simp only [Function.comp_apply, map_add, MulOpposite.unop_add] @[simp] theorem star_ι (x : X) : star (ι R x) = ι R x := by simp [star, Star.star] @[simp] theorem star_algebraMap (r : R) : star (algebraMap R (FreeAlgebra R X) r) = algebraMap R _ r := by simp [star, Star.star] /-- `star` as an `AlgEquiv` -/ def starHom : FreeAlgebra R X ≃ₐ[R] (FreeAlgebra R X)ᵐᵒᵖ := { starRingEquiv with commutes' := fun r => by simp [star_algebraMap] } end FreeAlgebra
Algebra\Star\Module.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Frédéric Dupuis -/ import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Module.Basic import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.LinearMap.Star import Mathlib.Algebra.Module.Rat import Mathlib.LinearAlgebra.Prod /-! # The star operation, bundled as a star-linear equiv We define `starLinearEquiv`, which is the star operation bundled as a star-linear map. It is defined on a star algebra `A` over the base ring `R`. This file also provides some lemmas that need `Algebra.Module.Basic` imported to prove. ## TODO - Define `starLinearEquiv` for noncommutative `R`. We only the commutative case for now since, in the noncommutative case, the ring hom needs to reverse the order of multiplication. This requires a ring hom of type `R →+* Rᵐᵒᵖ`, which is very undesirable in the commutative case. One way out would be to define a new typeclass `IsOp R S` and have an instance `IsOp R R` for commutative `R`. - Also note that such a definition involving `Rᵐᵒᵖ` or `is_op R S` would require adding the appropriate `RingHomInvPair` instances to be able to define the semilinear equivalence. -/ section SMulLemmas variable {R M : Type*} @[simp] theorem star_natCast_smul [Semiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_natCast_smul (starAddEquiv : M ≃+ M) R R n x @[deprecated (since := "2024-04-17")] alias star_nat_cast_smul := star_natCast_smul @[simp] theorem star_intCast_smul [Ring R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℤ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_intCast_smul (starAddEquiv : M ≃+ M) R R n x @[deprecated (since := "2024-04-17")] alias star_int_cast_smul := star_intCast_smul @[simp] theorem star_inv_natCast_smul [DivisionSemiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x := map_inv_natCast_smul (starAddEquiv : M ≃+ M) R R n x @[deprecated (since := "2024-04-17")] alias star_inv_nat_cast_smul := star_inv_natCast_smul @[simp] theorem star_inv_intCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℤ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x := map_inv_intCast_smul (starAddEquiv : M ≃+ M) R R n x @[deprecated (since := "2024-04-17")] alias star_inv_int_cast_smul := star_inv_intCast_smul @[simp] theorem star_ratCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℚ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_ratCast_smul (starAddEquiv : M ≃+ M) _ _ _ x @[deprecated (since := "2024-04-17")] alias star_rat_cast_smul := star_ratCast_smul @[simp] theorem star_rat_smul {R : Type*} [AddCommGroup R] [StarAddMonoid R] [Module ℚ R] (x : R) (n : ℚ) : star (n • x) = n • star x := map_rat_smul (starAddEquiv : R ≃+ R) _ _ end SMulLemmas /-- If `A` is a module over a commutative `R` with compatible actions, then `star` is a semilinear equivalence. -/ @[simps] def starLinearEquiv (R : Type*) {A : Type*} [CommSemiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A] [StarModule R A] : A ≃ₗ⋆[R] A := { starAddEquiv with toFun := star map_smul' := star_smul } section SelfSkewAdjoint variable (R : Type*) (A : Type*) [Semiring R] [StarMul R] [TrivialStar R] [AddCommGroup A] [Module R A] [StarAddMonoid A] [StarModule R A] /-- The self-adjoint elements of a star module, as a submodule. -/ def selfAdjoint.submodule : Submodule R A := { selfAdjoint A with smul_mem' := fun _ _ => (IsSelfAdjoint.all _).smul } /-- The skew-adjoint elements of a star module, as a submodule. -/ def skewAdjoint.submodule : Submodule R A := { skewAdjoint A with smul_mem' := skewAdjoint.smul_mem } variable {A} [Invertible (2 : R)] /-- The self-adjoint part of an element of a star module, as a linear map. -/ @[simps] def selfAdjointPart : A →ₗ[R] selfAdjoint A where toFun x := ⟨(⅟ 2 : R) • (x + star x), by rw [selfAdjoint.mem_iff, star_smul, star_trivial, star_add, star_star, add_comm]⟩ map_add' x y := by ext simp [add_add_add_comm] map_smul' r x := by ext simp [← mul_smul, show ⅟ 2 * r = r * ⅟ 2 from Commute.invOf_left <| (2 : ℕ).cast_commute r] /-- The skew-adjoint part of an element of a star module, as a linear map. -/ @[simps] def skewAdjointPart : A →ₗ[R] skewAdjoint A where toFun x := ⟨(⅟ 2 : R) • (x - star x), by simp only [skewAdjoint.mem_iff, star_smul, star_sub, star_star, star_trivial, ← smul_neg, neg_sub]⟩ map_add' x y := by ext simp only [sub_add, ← smul_add, sub_sub_eq_add_sub, star_add, AddSubgroup.coe_mk, AddSubgroup.coe_add] map_smul' r x := by ext simp [← mul_smul, ← smul_sub, show r * ⅟ 2 = ⅟ 2 * r from Commute.invOf_right <| (2 : ℕ).commute_cast r] theorem StarModule.selfAdjointPart_add_skewAdjointPart (x : A) : (selfAdjointPart R x : A) + skewAdjointPart R x = x := by simp only [smul_sub, selfAdjointPart_apply_coe, smul_add, skewAdjointPart_apply_coe, add_add_sub_cancel, invOf_two_smul_add_invOf_two_smul] theorem IsSelfAdjoint.coe_selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : (selfAdjointPart R x : A) = x := by rw [selfAdjointPart_apply_coe, hx.star_eq, smul_add, invOf_two_smul_add_invOf_two_smul] theorem IsSelfAdjoint.selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : selfAdjointPart R x = ⟨x, hx⟩ := Subtype.eq (hx.coe_selfAdjointPart_apply R) -- Porting note (#11215): TODO: make it a `simp` theorem selfAdjointPart_comp_subtype_selfAdjoint : (selfAdjointPart R).comp (selfAdjoint.submodule R A).subtype = .id := LinearMap.ext fun x ↦ x.2.selfAdjointPart_apply R theorem IsSelfAdjoint.skewAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : skewAdjointPart R x = 0 := Subtype.eq <| by rw [skewAdjointPart_apply_coe, hx.star_eq, sub_self, smul_zero, ZeroMemClass.coe_zero] -- Porting note (#11215): TODO: make it a `simp` theorem skewAdjointPart_comp_subtype_selfAdjoint : (skewAdjointPart R).comp (selfAdjoint.submodule R A).subtype = 0 := LinearMap.ext fun x ↦ x.2.skewAdjointPart_apply R -- Porting note (#11215): TODO: make it a `simp` theorem selfAdjointPart_comp_subtype_skewAdjoint : (selfAdjointPart R).comp (skewAdjoint.submodule R A).subtype = 0 := LinearMap.ext fun ⟨x, (hx : _ = _)⟩ ↦ Subtype.eq <| by simp [hx] -- Porting note (#11215): TODO: make it a `simp` theorem skewAdjointPart_comp_subtype_skewAdjoint : (skewAdjointPart R).comp (skewAdjoint.submodule R A).subtype = .id := LinearMap.ext fun ⟨x, (hx : _ = _)⟩ ↦ Subtype.eq <| by simp only [LinearMap.comp_apply, Submodule.subtype_apply, skewAdjointPart_apply_coe, hx, sub_neg_eq_add, smul_add, invOf_two_smul_add_invOf_two_smul]; rfl variable (A) /-- The decomposition of elements of a star module into their self- and skew-adjoint parts, as a linear equivalence. -/ -- Porting note: This attribute causes a `timeout at 'whnf'`. @[simps!] def StarModule.decomposeProdAdjoint : A ≃ₗ[R] selfAdjoint A × skewAdjoint A := by refine LinearEquiv.ofLinear ((selfAdjointPart R).prod (skewAdjointPart R)) (LinearMap.coprod ((selfAdjoint.submodule R A).subtype) (skewAdjoint.submodule R A).subtype) ?_ (LinearMap.ext <| StarModule.selfAdjointPart_add_skewAdjointPart R) -- Note: with #6965 `Submodule.coeSubtype` doesn't fire in `dsimp` or `simp` ext x <;> dsimp <;> erw [Submodule.coeSubtype, Submodule.coeSubtype] <;> simp end SelfSkewAdjoint section algebraMap variable {R A : Type*} [CommSemiring R] [StarRing R] [Semiring A] variable [StarMul A] [Algebra R A] [StarModule R A] @[simp] theorem algebraMap_star_comm (r : R) : algebraMap R A (star r) = star (algebraMap R A r) := by simp only [Algebra.algebraMap_eq_smul_one, star_smul, star_one] variable (A) in protected lemma IsSelfAdjoint.algebraMap {r : R} (hr : IsSelfAdjoint r) : IsSelfAdjoint (algebraMap R A r) := by simpa using congr(algebraMap R A $(hr.star_eq)) lemma isSelfAdjoint_algebraMap_iff {r : R} (h : Function.Injective (algebraMap R A)) : IsSelfAdjoint (algebraMap R A r) ↔ IsSelfAdjoint r := ⟨fun hr ↦ h <| algebraMap_star_comm r (A := A) ▸ hr.star_eq, IsSelfAdjoint.algebraMap A⟩ end algebraMap
Algebra\Star\NonUnitalSubalgebra.lean
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.NonUnitalSubalgebra import Mathlib.Algebra.Star.StarAlgHom import Mathlib.Algebra.Star.Center /-! # Non-unital Star Subalgebras In this file we define `NonUnitalStarSubalgebra`s and the usual operations on them (`map`, `comap`). ## TODO * once we have scalar actions by semigroups (as opposed to monoids), implement the action of a non-unital subalgebra on the larger algebra. -/ namespace StarMemClass /-- If a type carries an involutive star, then any star-closed subset does too. -/ instance instInvolutiveStar {S R : Type*} [InvolutiveStar R] [SetLike S R] [StarMemClass S R] (s : S) : InvolutiveStar s where star_involutive r := Subtype.ext <| star_star (r : R) /-- In a star magma (i.e., a multiplication with an antimultiplicative involutive star operation), any star-closed subset which is also closed under multiplication is itself a star magma. -/ instance instStarMul {S R : Type*} [Mul R] [StarMul R] [SetLike S R] [MulMemClass S R] [StarMemClass S R] (s : S) : StarMul s where star_mul _ _ := Subtype.ext <| star_mul _ _ /-- In a `StarAddMonoid` (i.e., an additive monoid with an additive involutive star operation), any star-closed subset which is also closed under addition and contains zero is itself a `StarAddMonoid`. -/ instance instStarAddMonoid {S R : Type*} [AddMonoid R] [StarAddMonoid R] [SetLike S R] [AddSubmonoidClass S R] [StarMemClass S R] (s : S) : StarAddMonoid s where star_add _ _ := Subtype.ext <| star_add _ _ /-- In a star ring (i.e., a non-unital, non-associative, semiring with an additive, antimultiplicative, involutive star operation), a star-closed non-unital subsemiring is itself a star ring. -/ instance instStarRing {S R : Type*} [NonUnitalNonAssocSemiring R] [StarRing R] [SetLike S R] [NonUnitalSubsemiringClass S R] [StarMemClass S R] (s : S) : StarRing s := { StarMemClass.instStarMul s, StarMemClass.instStarAddMonoid s with } /-- In a star `R`-module (i.e., `star (r • m) = (star r) • m`) any star-closed subset which is also closed under the scalar action by `R` is itself a star `R`-module. -/ instance instStarModule {S : Type*} (R : Type*) {M : Type*} [Star R] [Star M] [SMul R M] [StarModule R M] [SetLike S M] [SMulMemClass S R M] [StarMemClass S M] (s : S) : StarModule R s where star_smul _ _ := Subtype.ext <| star_smul _ _ end StarMemClass universe u u' v v' w w' w'' variable {F : Type v'} {R' : Type u'} {R : Type u} variable {A : Type v} {B : Type w} {C : Type w'} namespace NonUnitalStarSubalgebraClass variable [CommSemiring R] [NonUnitalNonAssocSemiring A] variable [Star A] [Module R A] variable {S : Type w''} [SetLike S A] [NonUnitalSubsemiringClass S A] variable [hSR : SMulMemClass S R A] [StarMemClass S A] (s : S) /-- Embedding of a non-unital star subalgebra into the non-unital star algebra. -/ def subtype (s : S) : s →⋆ₙₐ[R] A := { NonUnitalSubalgebraClass.subtype s with toFun := Subtype.val map_star' := fun _ => rfl } @[simp] theorem coeSubtype : (subtype s : s → A) = Subtype.val := rfl end NonUnitalStarSubalgebraClass /-- A non-unital star subalgebra is a non-unital subalgebra which is closed under the `star` operation. -/ structure NonUnitalStarSubalgebra (R : Type u) (A : Type v) [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] [Star A] extends NonUnitalSubalgebra R A : Type v where /-- The `carrier` of a `NonUnitalStarSubalgebra` is closed under the `star` operation. -/ star_mem' : ∀ {a : A} (_ha : a ∈ carrier), star a ∈ carrier /-- Reinterpret a `NonUnitalStarSubalgebra` as a `NonUnitalSubalgebra`. -/ add_decl_doc NonUnitalStarSubalgebra.toNonUnitalSubalgebra namespace NonUnitalStarSubalgebra variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A] variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B] variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B] instance instSetLike : SetLike (NonUnitalStarSubalgebra R A) A where coe {s} := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h instance instNonUnitalSubsemiringClass : NonUnitalSubsemiringClass (NonUnitalStarSubalgebra R A) A where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' zero_mem {s} := s.zero_mem' instance instSMulMemClass : SMulMemClass (NonUnitalStarSubalgebra R A) R A where smul_mem {s} := s.smul_mem' instance instStarMemClass : StarMemClass (NonUnitalStarSubalgebra R A) A where star_mem {s} := s.star_mem' instance instNonUnitalSubringClass {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [Star A] : NonUnitalSubringClass (NonUnitalStarSubalgebra R A) A := { NonUnitalStarSubalgebra.instNonUnitalSubsemiringClass with neg_mem := fun _S {x} hx => neg_one_smul R x ▸ SMulMemClass.smul_mem _ hx } theorem mem_carrier {s : NonUnitalStarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : NonUnitalStarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] theorem mem_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {x} : x ∈ S.toNonUnitalSubalgebra ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toNonUnitalSubalgebra (S : NonUnitalStarSubalgebra R A) : (↑S.toNonUnitalSubalgebra : Set A) = S := rfl theorem toNonUnitalSubalgebra_injective : Function.Injective (toNonUnitalSubalgebra : NonUnitalStarSubalgebra R A → NonUnitalSubalgebra R A) := fun S T h => ext fun x => by rw [← mem_toNonUnitalSubalgebra, ← mem_toNonUnitalSubalgebra, h] theorem toNonUnitalSubalgebra_inj {S U : NonUnitalStarSubalgebra R A} : S.toNonUnitalSubalgebra = U.toNonUnitalSubalgebra ↔ S = U := toNonUnitalSubalgebra_injective.eq_iff theorem toNonUnitalSubalgebra_le_iff {S₁ S₂ : NonUnitalStarSubalgebra R A} : S₁.toNonUnitalSubalgebra ≤ S₂.toNonUnitalSubalgebra ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a non-unital star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : NonUnitalStarSubalgebra R A := { S.toNonUnitalSubalgebra.copy s hs with star_mem' := @fun x (hx : x ∈ s) => by show star x ∈ s rw [hs] at hx ⊢ exact S.star_mem' hx } @[simp] theorem coe_copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s := rfl theorem copy_eq (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : NonUnitalStarSubalgebra R A) /-- A non-unital star subalgebra over a ring is also a `Subring`. -/ def toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSubring A where toNonUnitalSubsemiring := S.toNonUnitalSubsemiring neg_mem' := neg_mem (s := S) @[simp] theorem mem_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} {x} : x ∈ S.toNonUnitalSubring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : (↑S.toNonUnitalSubring : Set A) = S := rfl theorem toNonUnitalSubring_injective {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] : Function.Injective (toNonUnitalSubring : NonUnitalStarSubalgebra R A → NonUnitalSubring A) := fun S T h => ext fun x => by rw [← mem_toNonUnitalSubring, ← mem_toNonUnitalSubring, h] theorem toNonUnitalSubring_inj {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] {S U : NonUnitalStarSubalgebra R A} : S.toNonUnitalSubring = U.toNonUnitalSubring ↔ S = U := toNonUnitalSubring_injective.eq_iff instance instInhabited : Inhabited S := ⟨(0 : S.toNonUnitalSubalgebra)⟩ section /-! `NonUnitalStarSubalgebra`s inherit structure from their `NonUnitalSubsemiringClass` and `NonUnitalSubringClass` instances. -/ instance toNonUnitalSemiring {R A} [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSemiring S := inferInstance instance toNonUnitalCommSemiring {R A} [CommSemiring R] [NonUnitalCommSemiring A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalCommSemiring S := inferInstance instance toNonUnitalRing {R A} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalRing S := inferInstance instance toNonUnitalCommRing {R A} [CommRing R] [NonUnitalCommRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalCommRing S := inferInstance end /-- The forgetful map from `NonUnitalStarSubalgebra` to `NonUnitalSubalgebra` as an `OrderEmbedding` -/ def toNonUnitalSubalgebra' : NonUnitalStarSubalgebra R A ↪o NonUnitalSubalgebra R A where toEmbedding := { toFun := fun S => S.toNonUnitalSubalgebra inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h } map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe section /-! `NonUnitalStarSubalgebra`s inherit structure from their `Submodule` coercions. -/ instance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S := SMulMemClass.toModule' _ R' R A S instance instModule : Module R S := S.module' instance instIsScalarTower' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S := S.toNonUnitalSubalgebra.instIsScalarTower' instance instIsScalarTower [IsScalarTower R A A] : IsScalarTower R S S where smul_assoc r x y := Subtype.ext <| smul_assoc r (x : A) (y : A) instance instSMulCommClass' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] [SMulCommClass R' R A] : SMulCommClass R' R S where smul_comm r' r s := Subtype.ext <| smul_comm r' r (s : A) instance instSMulCommClass [SMulCommClass R A A] : SMulCommClass R S S where smul_comm r x y := Subtype.ext <| smul_comm r (x : A) (y : A) end instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S := ⟨fun {c x} h => have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg ((↑) : S → A) h) this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩ protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl protected theorem coe_zero : ((0 : S) : A) = 0 := rfl protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl @[simp, norm_cast] theorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) : ↑(r • x) = r • (x : A) := rfl protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 := ZeroMemClass.coe_eq_zero @[simp] theorem toNonUnitalSubalgebra_subtype : NonUnitalSubalgebraClass.subtype S = NonUnitalStarSubalgebraClass.subtype S := rfl @[simp] theorem toSubring_subtype {R A : Type*} [CommRing R] [NonUnitalRing A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSubringClass.subtype S = NonUnitalStarSubalgebraClass.subtype S := rfl /-- Transport a non-unital star subalgebra via a non-unital star algebra homomorphism. -/ def map (f : F) (S : NonUnitalStarSubalgebra R A) : NonUnitalStarSubalgebra R B where toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.map (f : A →ₙₐ[R] B) star_mem' := by rintro _ ⟨a, ha, rfl⟩; exact ⟨star a, star_mem (s := S) ha, map_star f a⟩ theorem map_mono {S₁ S₂ : NonUnitalStarSubalgebra R A} {f : F} : S₁ ≤ S₂ → (map f S₁ : NonUnitalStarSubalgebra R B) ≤ map f S₂ := Set.image_subset f theorem map_injective {f : F} (hf : Function.Injective f) : Function.Injective (map f : NonUnitalStarSubalgebra R A → NonUnitalStarSubalgebra R B) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : NonUnitalStarSubalgebra R A) : map (NonUnitalStarAlgHom.id R A) S = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : NonUnitalStarSubalgebra R A) (g : B →⋆ₙₐ[R] C) (f : A →⋆ₙₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : NonUnitalStarSubalgebra R A} {f : F} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := NonUnitalSubalgebra.mem_map theorem map_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {f : F} : (map f S : NonUnitalStarSubalgebra R B).toNonUnitalSubalgebra = NonUnitalSubalgebra.map f S.toNonUnitalSubalgebra := SetLike.coe_injective rfl @[simp] theorem coe_map (S : NonUnitalStarSubalgebra R A) (f : F) : map f S = f '' S := rfl /-- Preimage of a non-unital star subalgebra under a non-unital star algebra homomorphism. -/ def comap (f : F) (S : NonUnitalStarSubalgebra R B) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.comap f star_mem' := @fun a (ha : f a ∈ S) => show f (star a) ∈ S from (map_star f a).symm ▸ star_mem (s := S) ha theorem map_le {S : NonUnitalStarSubalgebra R A} {f : F} {U : NonUnitalStarSubalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) := fun _S _U => map_le @[simp] theorem mem_comap (S : NonUnitalStarSubalgebra R B) (f : F) (x : A) : x ∈ comap f S ↔ f x ∈ S := Iff.rfl @[simp, norm_cast] theorem coe_comap (S : NonUnitalStarSubalgebra R B) (f : F) : comap f S = f ⁻¹' (S : Set B) := rfl instance instNoZeroDivisors {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [NoZeroDivisors A] [Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NoZeroDivisors S := NonUnitalSubsemiringClass.noZeroDivisors S end NonUnitalStarSubalgebra namespace NonUnitalSubalgebra variable [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A] variable (s : NonUnitalSubalgebra R A) /-- A non-unital subalgebra closed under `star` is a non-unital star subalgebra. -/ def toNonUnitalStarSubalgebra (h_star : ∀ x, x ∈ s → star x ∈ s) : NonUnitalStarSubalgebra R A := { s with star_mem' := @h_star } @[simp] theorem mem_toNonUnitalStarSubalgebra {s : NonUnitalSubalgebra R A} {h_star} {x} : x ∈ s.toNonUnitalStarSubalgebra h_star ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toNonUnitalStarSubalgebra (s : NonUnitalSubalgebra R A) (h_star) : (s.toNonUnitalStarSubalgebra h_star : Set A) = s := rfl @[simp] theorem toNonUnitalStarSubalgebra_toNonUnitalSubalgebra (s : NonUnitalSubalgebra R A) (h_star) : (s.toNonUnitalStarSubalgebra h_star).toNonUnitalSubalgebra = s := SetLike.coe_injective rfl @[simp] theorem _root_.NonUnitalStarSubalgebra.toNonUnitalSubalgebra_toNonUnitalStarSubalgebra (S : NonUnitalStarSubalgebra R A) : (S.toNonUnitalSubalgebra.toNonUnitalStarSubalgebra fun _ => star_mem (s := S)) = S := SetLike.coe_injective rfl end NonUnitalSubalgebra namespace NonUnitalStarAlgHom variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A] variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B] variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B] /-- Range of an `NonUnitalAlgHom` as a `NonUnitalStarSubalgebra`. -/ protected def range (φ : F) : NonUnitalStarSubalgebra R B where toNonUnitalSubalgebra := NonUnitalAlgHom.range (φ : A →ₙₐ[R] B) star_mem' := by rintro _ ⟨a, rfl⟩; exact ⟨star a, map_star φ a⟩ @[simp] theorem mem_range (φ : F) {y : B} : y ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) ↔ ∃ x : A, φ x = y := NonUnitalRingHom.mem_srange theorem mem_range_self (φ : F) (x : A) : φ x ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) := (NonUnitalAlgHom.mem_range φ).2 ⟨x, rfl⟩ @[simp] theorem coe_range (φ : F) : ((NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) : Set B) = Set.range (φ : A → B) := by ext; rw [SetLike.mem_coe, mem_range]; rfl theorem range_comp (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) : NonUnitalStarAlgHom.range (g.comp f) = (NonUnitalStarAlgHom.range f).map g := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) : NonUnitalStarAlgHom.range (g.comp f) ≤ NonUnitalStarAlgHom.range g := SetLike.coe_mono (Set.range_comp_subset_range f g) /-- Restrict the codomain of a non-unital star algebra homomorphism. -/ def codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →⋆ₙₐ[R] S where toNonUnitalAlgHom := NonUnitalAlgHom.codRestrict f S.toNonUnitalSubalgebra hf map_star' := fun a => Subtype.ext <| map_star f a @[simp] theorem subtype_comp_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : (NonUnitalStarSubalgebraClass.subtype S).comp (NonUnitalStarAlgHom.codRestrict f S hf) = f := NonUnitalStarAlgHom.ext fun _ => rfl @[simp] theorem coe_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) : ↑(NonUnitalStarAlgHom.codRestrict f S hf x) = f x := rfl theorem injective_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : Function.Injective (NonUnitalStarAlgHom.codRestrict f S hf) ↔ Function.Injective f := ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩ /-- Restrict the codomain of a non-unital star algebra homomorphism `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict (f : F) : A →⋆ₙₐ[R] (NonUnitalStarAlgHom.range f : NonUnitalStarSubalgebra R B) := NonUnitalStarAlgHom.codRestrict f (NonUnitalStarAlgHom.range f) (NonUnitalStarAlgHom.mem_range_self f) /-- The equalizer of two non-unital star `R`-algebra homomorphisms -/ def equalizer (ϕ ψ : F) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := NonUnitalAlgHom.equalizer ϕ ψ star_mem' := @fun x (hx : ϕ x = ψ x) => by simp [map_star, hx] @[simp] theorem mem_equalizer (φ ψ : F) (x : A) : x ∈ NonUnitalStarAlgHom.equalizer φ ψ ↔ φ x = ψ x := Iff.rfl end NonUnitalStarAlgHom namespace StarAlgEquiv variable [CommSemiring R] variable [NonUnitalSemiring A] [Module R A] [Star A] variable [NonUnitalSemiring B] [Module R B] [Star B] variable [NonUnitalSemiring C] [Module R C] [Star C] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B] /-- Restrict a non-unital star algebra homomorphism with a left inverse to an algebra isomorphism to its range. This is a computable alternative to `StarAlgEquiv.ofInjective`. -/ def ofLeftInverse' {g : B → A} {f : F} (h : Function.LeftInverse g f) : A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f := { NonUnitalStarAlgHom.rangeRestrict f with toFun := NonUnitalStarAlgHom.rangeRestrict f invFun := g ∘ (NonUnitalStarSubalgebraClass.subtype <| NonUnitalStarAlgHom.range f) left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := (NonUnitalStarAlgHom.mem_range f).mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse'_apply {g : B → A} {f : F} (h : Function.LeftInverse g f) (x : A) : ofLeftInverse' h x = f x := rfl @[simp] theorem ofLeftInverse'_symm_apply {g : B → A} {f : F} (h : Function.LeftInverse g f) (x : NonUnitalStarAlgHom.range f) : (ofLeftInverse' h).symm x = g x := rfl /-- Restrict an injective non-unital star algebra homomorphism to a star algebra isomorphism -/ noncomputable def ofInjective' (f : F) (hf : Function.Injective f) : A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f := ofLeftInverse' (Classical.choose_spec hf.hasLeftInverse) @[simp] theorem ofInjective'_apply (f : F) (hf : Function.Injective f) (x : A) : ofInjective' f hf x = f x := rfl end StarAlgEquiv /-! ### The star closure of a subalgebra -/ namespace NonUnitalSubalgebra open scoped Pointwise variable [CommSemiring R] [StarRing R] variable [NonUnitalSemiring A] [StarRing A] [Module R A] variable [StarModule R A] /-- The pointwise `star` of a non-unital subalgebra is a non-unital subalgebra. -/ instance instInvolutiveStar : InvolutiveStar (NonUnitalSubalgebra R A) where star S := { carrier := star S.carrier mul_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier] using (star_mul x y).symm ▸ mul_mem hy hx add_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier] using (star_add x y).symm ▸ add_mem hx hy zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S) smul_mem' := fun r x hx => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier] using (star_smul r x).symm ▸ SMulMemClass.smul_mem (star r) hx } star_involutive S := NonUnitalSubalgebra.ext fun x => ⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩ @[simp] theorem mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S := Iff.rfl theorem star_mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by simp @[simp] theorem coe_star (S : NonUnitalSubalgebra R A) : star S = star (S : Set A) := rfl theorem star_mono : Monotone (star : NonUnitalSubalgebra R A → NonUnitalSubalgebra R A) := fun _ _ h _ hx => h hx variable (R) variable [IsScalarTower R A A] [SMulCommClass R A A] /-- The star operation on `NonUnitalSubalgebra` commutes with `NonUnitalAlgebra.adjoin`. -/ theorem star_adjoin_comm (s : Set A) : star (NonUnitalAlgebra.adjoin R s) = NonUnitalAlgebra.adjoin R (star s) := have this : ∀ t : Set A, NonUnitalAlgebra.adjoin R (star t) ≤ star (NonUnitalAlgebra.adjoin R t) := fun t => NonUnitalAlgebra.adjoin_le fun x hx => NonUnitalAlgebra.subset_adjoin R hx le_antisymm (by simpa only [star_star] using NonUnitalSubalgebra.star_mono (this (star s))) (this s) variable {R} /-- The `NonUnitalStarSubalgebra` obtained from `S : NonUnitalSubalgebra R A` by taking the smallest non-unital subalgebra containing both `S` and `star S`. -/ @[simps!] def starClosure (S : NonUnitalSubalgebra R A) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := S ⊔ star S star_mem' := @fun a (ha : a ∈ S ⊔ star S) => show star a ∈ S ⊔ star S by simp only [← mem_star_iff _ a, ← (@NonUnitalAlgebra.gi R A _ _ _ _ _).l_sup_u _ _] at * convert ha using 2 simp only [Set.sup_eq_union, star_adjoin_comm, Set.union_star, coe_star, star_star, Set.union_comm] theorem starClosure_le {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A} (h : S₁ ≤ S₂.toNonUnitalSubalgebra) : S₁.starClosure ≤ S₂ := NonUnitalStarSubalgebra.toNonUnitalSubalgebra_le_iff.1 <| sup_le h fun x hx => (star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂) theorem starClosure_le_iff {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A} : S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toNonUnitalSubalgebra := ⟨fun h => le_sup_left.trans h, starClosure_le⟩ @[simp] theorem starClosure_toNonunitalSubalgebra {S : NonUnitalSubalgebra R A} : S.starClosure.toNonUnitalSubalgebra = S ⊔ star S := rfl @[mono] theorem starClosure_mono : Monotone (starClosure (R := R) (A := A)) := fun _ _ h => starClosure_le <| h.trans le_sup_left end NonUnitalSubalgebra namespace NonUnitalStarAlgebra variable [CommSemiring R] [StarRing R] variable [NonUnitalSemiring A] [StarRing A] variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] variable [NonUnitalSemiring B] [StarRing B] variable [Module R B] [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B] open scoped Pointwise open NonUnitalStarSubalgebra variable (R) /-- The minimal non-unital subalgebra that includes `s`. -/ def adjoin (s : Set A) : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := NonUnitalAlgebra.adjoin R (s ∪ star s) star_mem' _ := by rwa [NonUnitalSubalgebra.mem_carrier, ← NonUnitalSubalgebra.mem_star_iff, NonUnitalSubalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm] theorem adjoin_eq_starClosure_adjoin (s : Set A) : adjoin R s = (NonUnitalAlgebra.adjoin R s).starClosure := toNonUnitalSubalgebra_injective <| show NonUnitalAlgebra.adjoin R (s ∪ star s) = NonUnitalAlgebra.adjoin R s ⊔ star (NonUnitalAlgebra.adjoin R s) from (NonUnitalSubalgebra.star_adjoin_comm R s).symm ▸ NonUnitalAlgebra.adjoin_union s (star s) theorem adjoin_toNonUnitalSubalgebra (s : Set A) : (adjoin R s).toNonUnitalSubalgebra = NonUnitalAlgebra.adjoin R (s ∪ star s) := rfl @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s := Set.subset_union_left.trans <| NonUnitalAlgebra.subset_adjoin R theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s := Set.subset_union_right.trans <| NonUnitalAlgebra.subset_adjoin R theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := NonUnitalAlgebra.subset_adjoin R <| Set.mem_union_left _ (Set.mem_singleton x) theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) := star_mem <| self_mem_adjoin_singleton R x @[elab_as_elim] lemma adjoin_induction' {s : Set A} {p : ∀ x, x ∈ adjoin R s → Prop} {a : A} (ha : a ∈ adjoin R s) (mem : ∀ (x : A) (hx : x ∈ s), p x (subset_adjoin R s hx)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (zero : p 0 (zero_mem _)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (smul : ∀ (r : R) x hx, p x hx → p (r • x) (SMulMemClass.smul_mem r hx)) (star : ∀ x hx, p x hx → p (star x) (star_mem hx)) : p a ha := by refine NonUnitalAlgebra.adjoin_induction' (fun x hx ↦ ?_) add zero mul smul ha simp only [Set.mem_union, Set.mem_star] at hx obtain (hx | hx) := hx · exact mem x hx · simpa using star _ (NonUnitalAlgebra.subset_adjoin R (by simpa using Or.inl hx)) (mem _ hx) variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) := by intro s S rw [← toNonUnitalSubalgebra_le_iff, adjoin_toNonUnitalSubalgebra, NonUnitalAlgebra.adjoin_le_iff, coe_toNonUnitalSubalgebra] exact ⟨fun h => Set.subset_union_left.trans h, fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩ /-- Galois insertion between `adjoin` and `Subtype.val`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (NonUnitalStarAlgebra.gc.le_u_l s) hs gc := NonUnitalStarAlgebra.gc le_l_u S := (NonUnitalStarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := NonUnitalStarSubalgebra.copy_eq _ _ _ theorem adjoin_le {S : NonUnitalStarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S := NonUnitalStarAlgebra.gc.l_le hs theorem adjoin_le_iff {S : NonUnitalStarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S := NonUnitalStarAlgebra.gc _ _ lemma adjoin_eq (s : NonUnitalStarSubalgebra R A) : adjoin R (s : Set A) = s := le_antisymm (adjoin_le le_rfl) (subset_adjoin R (s : Set A)) lemma adjoin_eq_span (s : Set A) : (adjoin R s).toSubmodule = Submodule.span R (Subsemigroup.closure (s ∪ star s)) := by rw [adjoin_toNonUnitalSubalgebra, NonUnitalAlgebra.adjoin_eq_span] @[simp] lemma span_eq_toSubmodule {R} [CommSemiring R] [Module R A] (s : NonUnitalStarSubalgebra R A) : Submodule.span R (s : Set A) = s.toSubmodule := by simp [SetLike.ext'_iff, Submodule.coe_span_eq_self] theorem _root_.NonUnitalSubalgebra.starClosure_eq_adjoin (S : NonUnitalSubalgebra R A) : S.starClosure = adjoin R (S : Set A) := le_antisymm (NonUnitalSubalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A)) (adjoin_le (le_sup_left : S ≤ S ⊔ star S)) instance : CompleteLattice (NonUnitalStarSubalgebra R A) := GaloisInsertion.liftCompleteLattice NonUnitalStarAlgebra.gi @[simp] theorem coe_top : ((⊤ : NonUnitalStarSubalgebra R A) : Set A) = Set.univ := rfl @[simp] theorem mem_top {x : A} : x ∈ (⊤ : NonUnitalStarSubalgebra R A) := Set.mem_univ x @[simp] theorem top_toNonUnitalSubalgebra : (⊤ : NonUnitalStarSubalgebra R A).toNonUnitalSubalgebra = ⊤ := by ext; simp @[simp] theorem toNonUnitalSubalgebra_eq_top {S : NonUnitalStarSubalgebra R A} : S.toNonUnitalSubalgebra = ⊤ ↔ S = ⊤ := NonUnitalStarSubalgebra.toNonUnitalSubalgebra_injective.eq_iff' top_toNonUnitalSubalgebra theorem mem_sup_left {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_left theorem mem_sup_right {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_right theorem mul_mem_sup {S T : NonUnitalStarSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := mul_mem (mem_sup_left hx) (mem_sup_right hy) theorem map_sup (f : F) (S T : NonUnitalStarSubalgebra R A) : ((S ⊔ T).map f : NonUnitalStarSubalgebra R B) = S.map f ⊔ T.map f := (NonUnitalStarSubalgebra.gc_map_comap f).l_sup @[simp, norm_cast] theorem coe_inf (S T : NonUnitalStarSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T := rfl @[simp] theorem mem_inf {S T : NonUnitalStarSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl @[simp] theorem inf_toNonUnitalSubalgebra (S T : NonUnitalStarSubalgebra R A) : (S ⊓ T).toNonUnitalSubalgebra = S.toNonUnitalSubalgebra ⊓ T.toNonUnitalSubalgebra := SetLike.coe_injective <| coe_inf _ _ -- it's a bit surprising `rfl` fails here. @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalStarSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s := sInf_image theorem mem_sInf {S : Set (NonUnitalStarSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂] @[simp] theorem sInf_toNonUnitalSubalgebra (S : Set (NonUnitalStarSubalgebra R A)) : (sInf S).toNonUnitalSubalgebra = sInf (NonUnitalStarSubalgebra.toNonUnitalSubalgebra '' S) := SetLike.coe_injective <| by simp @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalStarSubalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by simp [iInf] theorem mem_iInf {ι : Sort*} {S : ι → NonUnitalStarSubalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp] theorem iInf_toNonUnitalSubalgebra {ι : Sort*} (S : ι → NonUnitalStarSubalgebra R A) : (⨅ i, S i).toNonUnitalSubalgebra = ⨅ i, (S i).toNonUnitalSubalgebra := SetLike.coe_injective <| by simp instance : Inhabited (NonUnitalStarSubalgebra R A) := ⟨⊥⟩ theorem mem_bot {x : A} : x ∈ (⊥ : NonUnitalStarSubalgebra R A) ↔ x = 0 := show x ∈ NonUnitalAlgebra.adjoin R (∅ ∪ star ∅ : Set A) ↔ x = 0 by rw [Set.star_empty, Set.union_empty, NonUnitalAlgebra.adjoin_empty, NonUnitalAlgebra.mem_bot] theorem toNonUnitalSubalgebra_bot : (⊥ : NonUnitalStarSubalgebra R A).toNonUnitalSubalgebra = ⊥ := by ext x simp only [mem_bot, NonUnitalStarSubalgebra.mem_toNonUnitalSubalgebra, NonUnitalAlgebra.mem_bot] @[simp] theorem coe_bot : ((⊥ : NonUnitalStarSubalgebra R A) : Set A) = {0} := by simp only [Set.ext_iff, NonUnitalStarAlgebra.mem_bot, SetLike.mem_coe, Set.mem_singleton_iff, iff_self_iff, forall_const] theorem eq_top_iff {S : NonUnitalStarSubalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S := ⟨fun h x => by rw [h]; exact mem_top, fun h => by ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩ theorem range_top_iff_surjective (f : F) : NonUnitalStarAlgHom.range f = (⊤ : NonUnitalStarSubalgebra R B) ↔ Function.Surjective f := NonUnitalStarAlgebra.eq_top_iff @[simp] theorem range_id : NonUnitalStarAlgHom.range (NonUnitalStarAlgHom.id R A) = ⊤ := SetLike.coe_injective Set.range_id @[simp] theorem map_top (f : F) : (⊤ : NonUnitalStarSubalgebra R A).map f = NonUnitalStarAlgHom.range f := SetLike.coe_injective Set.image_univ @[simp] theorem map_bot (f : F) : (⊥ : NonUnitalStarSubalgebra R A).map f = ⊥ := SetLike.coe_injective <| by simp [NonUnitalAlgebra.coe_bot, NonUnitalStarSubalgebra.coe_map] @[simp] theorem comap_top (f : F) : (⊤ : NonUnitalStarSubalgebra R B).comap f = ⊤ := eq_top_iff.2 fun _x => mem_top /-- `NonUnitalStarAlgHom` to `⊤ : NonUnitalStarSubalgebra R A`. -/ def toTop : A →⋆ₙₐ[R] (⊤ : NonUnitalStarSubalgebra R A) := NonUnitalStarAlgHom.codRestrict (NonUnitalStarAlgHom.id R A) ⊤ fun _ => mem_top end NonUnitalStarAlgebra namespace NonUnitalStarSubalgebra open NonUnitalStarAlgebra variable [CommSemiring R] [StarRing R] variable [NonUnitalSemiring A] [StarRing A] variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] variable [NonUnitalSemiring B] [StarRing B] variable [Module R B] [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B] variable (S : NonUnitalStarSubalgebra R A) lemma _root_.NonUnitalStarAlgHom.map_adjoin (f : F) (s : Set A) : map f (adjoin R s) = adjoin R (f '' s) := Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) NonUnitalStarAlgebra.gi.gc NonUnitalStarAlgebra.gi.gc fun _t => rfl @[simp] lemma _root_.NonUnitalStarAlgHom.map_adjoin_singleton (f : F) (x : A) : map f (adjoin R {x}) = adjoin R {f x} := by simp [NonUnitalStarAlgHom.map_adjoin] instance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (NonUnitalStarSubalgebra R A) := ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩ instance _root_.NonUnitalStarAlgHom.subsingleton [Subsingleton (NonUnitalStarSubalgebra R A)] : Subsingleton (A →⋆ₙₐ[R] B) := ⟨fun f g => NonUnitalStarAlgHom.ext fun a => have : a ∈ (⊥ : NonUnitalStarSubalgebra R A) := Subsingleton.elim (⊤ : NonUnitalStarSubalgebra R A) ⊥ ▸ mem_top (mem_bot.mp this).symm ▸ (map_zero f).trans (map_zero g).symm⟩ theorem range_val : NonUnitalStarAlgHom.range (NonUnitalStarSubalgebraClass.subtype S) = S := ext <| Set.ext_iff.1 <| (NonUnitalStarSubalgebraClass.subtype S).coe_range.trans Subtype.range_val /-- The map `S → T` when `S` is a non-unital star subalgebra contained in the non-unital star algebra `T`. This is the non-unital star subalgebra version of `Submodule.inclusion`, or `NonUnitalSubalgebra.inclusion` -/ def inclusion {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) : S →⋆ₙₐ[R] T where toNonUnitalAlgHom := NonUnitalSubalgebra.inclusion h map_star' _ := rfl theorem inclusion_injective {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) := fun _ _ => Subtype.ext ∘ Subtype.mk.inj @[simp] theorem inclusion_self {S : NonUnitalStarSubalgebra R A} : inclusion (le_refl S) = NonUnitalAlgHom.id R S := NonUnitalAlgHom.ext fun _x => Subtype.ext rfl @[simp] theorem inclusion_mk {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl theorem inclusion_right {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) : inclusion h ⟨x, m⟩ = x := Subtype.ext rfl @[simp] theorem inclusion_inclusion {S T U : NonUnitalStarSubalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) : inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x := Subtype.ext rfl @[simp] theorem val_inclusion {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s := rfl section Prod variable (S₁ : NonUnitalStarSubalgebra R B) /-- The product of two non-unital star subalgebras is a non-unital star subalgebra. -/ def prod : NonUnitalStarSubalgebra R (A × B) := { S.toNonUnitalSubalgebra.prod S₁.toNonUnitalSubalgebra with carrier := S ×ˢ S₁ star_mem' := fun hx => ⟨star_mem hx.1, star_mem hx.2⟩ } @[simp] theorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ S₁ := rfl theorem prod_toNonUnitalSubalgebra : (S.prod S₁).toNonUnitalSubalgebra = S.toNonUnitalSubalgebra.prod S₁.toNonUnitalSubalgebra := rfl @[simp] theorem mem_prod {S : NonUnitalStarSubalgebra R A} {S₁ : NonUnitalStarSubalgebra R B} {x : A × B} : x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod @[simp] theorem prod_top : (prod ⊤ ⊤ : NonUnitalStarSubalgebra R (A × B)) = ⊤ := by ext; simp theorem prod_mono {S T : NonUnitalStarSubalgebra R A} {S₁ T₁ : NonUnitalStarSubalgebra R B} : S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ := Set.prod_mono @[simp] theorem prod_inf_prod {S T : NonUnitalStarSubalgebra R A} {S₁ T₁ : NonUnitalStarSubalgebra R B} : S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) := SetLike.coe_injective Set.prod_inter_prod end Prod section iSupLift variable {ι : Type*} theorem coe_iSup_of_directed [Nonempty ι] {S : ι → NonUnitalStarSubalgebra R A} (dir : Directed (· ≤ ·) S) : ↑(iSup S) = ⋃ i, (S i : Set A) := let K : NonUnitalStarSubalgebra R A := { __ := NonUnitalSubalgebra.copy _ _ (NonUnitalSubalgebra.coe_iSup_of_directed dir).symm star_mem' := fun hx ↦ let ⟨i, hi⟩ := Set.mem_iUnion.1 hx Set.mem_iUnion.2 ⟨i, star_mem (s := S i) hi⟩ } have : iSup S = K := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup S _) this.symm ▸ rfl /-- Define a non-unital star algebra homomorphism on a directed supremum of non-unital star subalgebras by defining it on each non-unital star subalgebra, and proving that it agrees on the intersection of non-unital star subalgebras. -/ noncomputable def iSupLift [Nonempty ι] (K : ι → NonUnitalStarSubalgebra R A) (dir : Directed (· ≤ ·) K) (f : ∀ i, K i →⋆ₙₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)) (T : NonUnitalStarSubalgebra R A) (hT : T = iSup K) : ↥T →⋆ₙₐ[R] B := by subst hT exact { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x) (fun i j x hxi hxj => by let ⟨k, hik, hjk⟩ := dir i j simp only rw [hf i k hik, hf j k hjk] rfl) (↑(iSup K)) (by rw [coe_iSup_of_directed dir]) map_zero' := by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast] exact Set.iUnionLift_const _ (fun i : ι => (0 : K i)) (fun _ => rfl) _ (by simp) map_mul' := by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast, ZeroMemClass.coe_zero, AddSubmonoid.mk_add_mk, Set.inclusion_mk] apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·)) all_goals simp map_add' := by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast] apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·)) all_goals simp map_smul' := fun r => by dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast] apply Set.iUnionLift_unary (coe_iSup_of_directed dir) _ (fun _ x => r • x) (fun _ _ => rfl) all_goals simp map_star' := by dsimp only [SetLike.coe_sort_coe, NonUnitalStarAlgHom.comp_apply, inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast, ZeroMemClass.coe_zero, AddSubmonoid.mk_add_mk, Set.inclusion_mk, MulMemClass.mk_mul_mk, NonUnitalAlgHom.toDistribMulActionHom_eq_coe, DistribMulActionHom.toFun_eq_coe, NonUnitalAlgHom.coe_to_distribMulActionHom, NonUnitalAlgHom.coe_mk] apply Set.iUnionLift_unary (coe_iSup_of_directed dir) _ (fun _ x => star x) (fun _ _ => rfl) all_goals simp [map_star] } variable [Nonempty ι] {K : ι → NonUnitalStarSubalgebra R A} {dir : Directed (· ≤ ·) K} {f : ∀ i, K i →⋆ₙₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)} {T : NonUnitalStarSubalgebra R A} {hT : T = iSup K} @[simp] theorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) : iSupLift K dir f hf T hT (inclusion h x) = f i x := by subst T dsimp [iSupLift] apply Set.iUnionLift_inclusion exact h @[simp] theorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) : (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp @[simp] theorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) : iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by subst hT dsimp [iSupLift] apply Set.iUnionLift_mk theorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) : iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by subst hT dsimp [iSupLift] apply Set.iUnionLift_of_mem end iSupLift section Center variable (R A) /-- The center of a non-unital star algebra is the set of elements which commute with every element. They form a non-unital star subalgebra. -/ def center : NonUnitalStarSubalgebra R A where toNonUnitalSubalgebra := NonUnitalSubalgebra.center R A star_mem' := Set.star_mem_center theorem coe_center : (center R A : Set A) = Set.center A := rfl @[simp] theorem center_toNonUnitalSubalgebra : (center R A).toNonUnitalSubalgebra = NonUnitalSubalgebra.center R A := rfl @[simp] theorem center_eq_top (A : Type*) [NonUnitalCommSemiring A] [StarRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] : center R A = ⊤ := SetLike.coe_injective (Set.center_eq_univ A) variable {R A} instance instNonUnitalCommSemiring : NonUnitalCommSemiring (center R A) := NonUnitalSubalgebra.center.instNonUnitalCommSemiring instance instNonUnitalCommRing {A : Type*} [NonUnitalRing A] [StarRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : NonUnitalCommRing (center R A) := NonUnitalSubalgebra.center.instNonUnitalCommRing theorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b := Subsemigroup.mem_center_iff end Center section Centralizer variable (R) /-- The centralizer of the star-closure of a set as a non-unital star subalgebra. -/ def centralizer (s : Set A) : NonUnitalStarSubalgebra R A := { NonUnitalSubalgebra.centralizer R (s ∪ star s) with star_mem' := Set.star_mem_centralizer } @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = (s ∪ star s).centralizer := rfl theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g := by show (∀ g ∈ s ∪ star s, g * z = z * g) ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g simp only [Set.mem_union, or_imp, forall_and, and_congr_right_iff] exact fun _ => ⟨fun hz a ha => hz _ (Set.star_mem_star.mpr ha), fun hz a ha => star_star a ▸ hz _ ha⟩ theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset (Set.union_subset_union h <| Set.preimage_mono h) @[simp] theorem centralizer_univ : centralizer R Set.univ = center R A := SetLike.ext' <| by rw [coe_centralizer, Set.univ_union, coe_center, Set.centralizer_univ] end Centralizer end NonUnitalStarSubalgebra
Algebra\Star\NonUnitalSubsemiring.lean
/- Copyright (c) 2024 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Subsemigroup.Basic import Mathlib.RingTheory.NonUnitalSubsemiring.Basic import Mathlib.Algebra.Star.Center /-! # Non-unital Star Subsemirings In this file we define `NonUnitalStarSubsemiring`s and the usual operations on them. ## Implementation This file is heavily inspired by `Mathlib.Algebra.Star.NonUnitalSubalgebra`. -/ universe v w w' variable {A : Type v} {B : Type w} {C : Type w'} /-- A sub star semigroup is a subset of a magma which is closed under the `star`-/ structure SubStarSemigroup (M : Type v) [Mul M] [Star M] extends Subsemigroup M : Type v where /-- The `carrier` of a `StarSubset` is closed under the `star` operation. -/ star_mem' : ∀ {a : M} (_ha : a ∈ carrier), star a ∈ carrier /-- Reinterpret a `SubStarSemigroup` as a `Subsemigroup`. -/ add_decl_doc SubStarSemigroup.toSubsemigroup /-- A non-unital star subsemiring is a non-unital subsemiring which also is closed under the `star` operation. -/ structure NonUnitalStarSubsemiring (R : Type v) [NonUnitalNonAssocSemiring R] [Star R] extends NonUnitalSubsemiring R : Type v where /-- The `carrier` of a `NonUnitalStarSubsemiring` is closed under the `star` operation. -/ star_mem' : ∀ {a : R} (_ha : a ∈ carrier), star a ∈ carrier /-- Reinterpret a `NonUnitalStarSubsemiring` as a `NonUnitalSubsemiring`. -/ add_decl_doc NonUnitalStarSubsemiring.toNonUnitalSubsemiring section NonUnitalStarSubsemiring namespace NonUnitalStarSubsemiring variable {R : Type v} [NonUnitalNonAssocSemiring R] [StarRing R] instance instSetLike : SetLike (NonUnitalStarSubsemiring R) R where coe {s} := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h instance instNonUnitalSubsemiringClass : NonUnitalSubsemiringClass (NonUnitalStarSubsemiring R) R where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' zero_mem {s} := s.zero_mem' instance instStarMemClass : StarMemClass (NonUnitalStarSubsemiring R) R where star_mem {s} := s.star_mem' theorem mem_carrier {s : NonUnitalStarSubsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl /-- Copy of a non-unital star subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalStarSubsemiring R) (s : Set R) (hs : s = ↑S) : NonUnitalStarSubsemiring R := { S.toNonUnitalSubsemiring.copy s hs with star_mem' := fun {x} (hx : x ∈ s) => by show star x ∈ s rw [hs] at hx ⊢ exact S.star_mem' hx } @[simp] theorem coe_copy (S : NonUnitalStarSubsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : NonUnitalStarSubsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs section Center variable (R) /-- The center of a non-unital non-associative semiring `R` is the set of elements that commute and associate with everything in `R`, here realized as non-unital star subsemiring. -/ def center (R) [NonUnitalNonAssocSemiring R] [StarRing R] : NonUnitalStarSubsemiring R where toNonUnitalSubsemiring := NonUnitalSubsemiring.center R star_mem' := Set.star_mem_center end Center end NonUnitalStarSubsemiring end NonUnitalStarSubsemiring
Algebra\Star\Order.lean
/- Copyright (c) 2023 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Star.StarRingHom import Mathlib.Algebra.Regular.Basic /-! # Star ordered rings We define the class `StarOrderedRing R`, which says that the order on `R` respects the star operation, i.e. an element `r` is nonnegative iff it is in the `AddSubmonoid` generated by elements of the form `star s * s`. In many cases, including all C⋆-algebras, this can be reduced to `0 ≤ r ↔ ∃ s, r = star s * s`. However, this generality is slightly more convenient (e.g., it allows us to register a `StarOrderedRing` instance for `ℚ`), and more closely resembles the literature (see the seminal paper [*The positive cone in Banach algebras*][kelleyVaught1953]) In order to accommodate `NonUnitalSemiring R`, we actually don't characterize nonnegativity, but rather the entire `≤` relation with `StarOrderedRing.le_iff`. However, notice that when `R` is a `NonUnitalRing`, these are equivalent (see `StarOrderedRing.nonneg_iff` and `StarOrderedRing.of_nonneg_iff`). It is important to note that while a `StarOrderedRing` is an `OrderedAddCommMonoid` it is often *not* an `OrderedSemiring`. ## TODO * In a Banach star algebra without a well-defined square root, the natural ordering is given by the positive cone which is the _closure_ of the sums of elements `star r * r`. A weaker version of `StarOrderedRing` could be defined for this case (again, see [*The positive cone in Banach algebras*][kelleyVaught1953]). Note that the current definition has the advantage of not requiring a topology. -/ open Set open scoped NNRat universe u variable {R : Type u} /-- An ordered `*`-ring is a `*`ring with a partial order such that the nonnegative elements constitute precisely the `AddSubmonoid` generated by elements of the form `star s * s`. If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, it may be more convenient to declare instances using `StarOrderedRing.of_nonneg_iff`. Porting note: dropped an unneeded assumption `add_le_add_left : ∀ {x y}, x ≤ y → ∀ z, z + x ≤ z + y` -/ class StarOrderedRing (R : Type u) [NonUnitalSemiring R] [PartialOrder R] [StarRing R] : Prop where /-- characterization of the order in terms of the `StarRing` structure. -/ le_iff : ∀ x y : R, x ≤ y ↔ ∃ p, p ∈ AddSubmonoid.closure (Set.range fun s => star s * s) ∧ y = x + p namespace StarOrderedRing -- see note [lower instance priority] instance (priority := 100) toOrderedAddCommMonoid [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] : OrderedAddCommMonoid R where add_le_add_left := fun x y hle z ↦ by rw [StarOrderedRing.le_iff] at hle ⊢ refine hle.imp fun s hs ↦ ?_ rw [hs.2, add_assoc] exact ⟨hs.1, rfl⟩ -- see note [lower instance priority] instance (priority := 100) toExistsAddOfLE [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] : ExistsAddOfLE R where exists_add_of_le h := match (le_iff _ _).mp h with | ⟨p, _, hp⟩ => ⟨p, hp⟩ -- see note [lower instance priority] instance (priority := 100) toOrderedAddCommGroup [NonUnitalRing R] [PartialOrder R] [StarRing R] [StarOrderedRing R] : OrderedAddCommGroup R where add_le_add_left := @add_le_add_left _ _ _ _ /-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if `y = x + star s * s` for some `s : R`. This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`) and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances. If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see `StarOrderedRing.of_nonneg_iff` for a more convenient version. -/ lemma of_le_iff [NonUnitalSemiring R] [PartialOrder R] [StarRing R] (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where le_iff x y := by refine ⟨fun h => ?_, ?_⟩ · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩ · rintro ⟨p, hp, hpxy⟩ revert x y hpxy refine AddSubmonoid.closure_induction hp ?_ (fun x y h => add_zero x ▸ h.ge) ?_ · rintro _ ⟨s, rfl⟩ x y rfl exact (h_le_iff _ _).mpr ⟨s, rfl⟩ · rintro a b ha hb x y rfl rw [← add_assoc] exact (ha _ _ rfl).trans (hb _ _ rfl) /-- When `R` is a non-unital ring, to construct a `StarOrderedRing` instance it suffices to show that the nonnegative elements are precisely those elements in the `AddSubmonoid` generated by `star s * s` for `s : R`. -/ lemma of_nonneg_iff [NonUnitalRing R] [PartialOrder R] [StarRing R] (h_add : ∀ {x y : R}, x ≤ y → ∀ z, z + x ≤ z + y) (h_nonneg_iff : ∀ x : R, 0 ≤ x ↔ x ∈ AddSubmonoid.closure (Set.range fun s : R => star s * s)) : StarOrderedRing R where le_iff x y := by haveI : CovariantClass R R (· + ·) (· ≤ ·) := ⟨fun _ _ _ h => h_add h _⟩ simpa only [← sub_eq_iff_eq_add', sub_nonneg, exists_eq_right'] using h_nonneg_iff (y - x) /-- When `R` is a non-unital ring, to construct a `StarOrderedRing` instance it suffices to show that the nonnegative elements are precisely those elements of the form `star s * s` for `s : R`. This is provided for convenience because it holds in many common scenarios (e.g.,`ℝ`, `ℂ`, or any C⋆-algebra), and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances. -/ lemma of_nonneg_iff' [NonUnitalRing R] [PartialOrder R] [StarRing R] (h_add : ∀ {x y : R}, x ≤ y → ∀ z, z + x ≤ z + y) (h_nonneg_iff : ∀ x : R, 0 ≤ x ↔ ∃ s, x = star s * s) : StarOrderedRing R := of_le_iff <| by haveI : CovariantClass R R (· + ·) (· ≤ ·) := ⟨fun _ _ _ h => h_add h _⟩ simpa [sub_eq_iff_eq_add', sub_nonneg] using fun x y => h_nonneg_iff (y - x) theorem nonneg_iff [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] {x : R} : 0 ≤ x ↔ x ∈ AddSubmonoid.closure (Set.range fun s : R => star s * s) := by simp only [le_iff, zero_add, exists_eq_right'] end StarOrderedRing section NonUnitalSemiring variable [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] theorem star_mul_self_nonneg (r : R) : 0 ≤ star r * r := StarOrderedRing.nonneg_iff.mpr <| AddSubmonoid.subset_closure ⟨r, rfl⟩ theorem mul_star_self_nonneg (r : R) : 0 ≤ r * star r := by simpa only [star_star] using star_mul_self_nonneg (star r) theorem conjugate_nonneg {a : R} (ha : 0 ≤ a) (c : R) : 0 ≤ star c * a * c := by rw [StarOrderedRing.nonneg_iff] at ha refine AddSubmonoid.closure_induction ha (fun x hx => ?_) (by rw [mul_zero, zero_mul]) fun x y hx hy => ?_ · obtain ⟨x, rfl⟩ := hx convert star_mul_self_nonneg (x * c) using 1 rw [star_mul, ← mul_assoc, mul_assoc _ _ c] · calc 0 ≤ star c * x * c + 0 := by rw [add_zero]; exact hx _ ≤ star c * x * c + star c * y * c := add_le_add_left hy _ _ ≤ _ := by rw [mul_add, add_mul] theorem conjugate_nonneg' {a : R} (ha : 0 ≤ a) (c : R) : 0 ≤ c * a * star c := by simpa only [star_star] using conjugate_nonneg ha (star c) theorem conjugate_le_conjugate {a b : R} (hab : a ≤ b) (c : R) : star c * a * c ≤ star c * b * c := by rw [StarOrderedRing.le_iff] at hab ⊢ obtain ⟨p, hp, rfl⟩ := hab simp_rw [← StarOrderedRing.nonneg_iff] at hp ⊢ exact ⟨star c * p * c, conjugate_nonneg hp c, by simp only [add_mul, mul_add]⟩ theorem conjugate_le_conjugate' {a b : R} (hab : a ≤ b) (c : R) : c * a * star c ≤ c * b * star c := by simpa only [star_star] using conjugate_le_conjugate hab (star c) @[simp] lemma star_le_star_iff {x y : R} : star x ≤ star y ↔ x ≤ y := by suffices ∀ x y, x ≤ y → star x ≤ star y from ⟨by simpa only [star_star] using this (star x) (star y), this x y⟩ intro x y h rw [StarOrderedRing.le_iff] at h ⊢ obtain ⟨d, hd, rfl⟩ := h refine ⟨starAddEquiv d, ?_, star_add _ _⟩ refine AddMonoidHom.mclosure_preimage_le _ _ <| AddSubmonoid.closure_mono ?_ hd rintro - ⟨s, rfl⟩ exact ⟨s, by simp⟩ @[simp] lemma star_lt_star_iff {x y : R} : star x < star y ↔ x < y := by by_cases h : x = y · simp [h] · simpa [le_iff_lt_or_eq, h] using star_le_star_iff (x := x) (y := y) lemma star_le_iff {x y : R} : star x ≤ y ↔ x ≤ star y := by rw [← star_le_star_iff, star_star] lemma star_lt_iff {x y : R} : star x < y ↔ x < star y := by rw [← star_lt_star_iff, star_star] @[simp] lemma star_nonneg_iff {x : R} : 0 ≤ star x ↔ 0 ≤ x := by simpa using star_le_star_iff (x := 0) (y := x) @[simp] lemma star_nonpos_iff {x : R} : star x ≤ 0 ↔ x ≤ 0 := by simpa using star_le_star_iff (x := x) (y := 0) @[simp] lemma star_pos_iff {x : R} : 0 < star x ↔ 0 < x := by simpa using star_lt_star_iff (x := 0) (y := x) @[simp] lemma star_neg_iff {x : R} : star x < 0 ↔ x < 0 := by simpa using star_lt_star_iff (x := x) (y := 0) lemma IsSelfAdjoint.mono {x y : R} (h : x ≤ y) (hx : IsSelfAdjoint x) : IsSelfAdjoint y := by rw [StarOrderedRing.le_iff] at h obtain ⟨d, hd, rfl⟩ := h rw [IsSelfAdjoint, star_add, hx.star_eq] congr refine AddMonoidHom.eqOn_closureM (f := starAddEquiv (R := R)) (g := .id R) ?_ hd rintro - ⟨s, rfl⟩ simp @[aesop 10% apply] lemma IsSelfAdjoint.of_nonneg {x : R} (hx : 0 ≤ x) : IsSelfAdjoint x := .mono hx <| .zero R theorem conjugate_lt_conjugate {a b : R} (hab : a < b) {c : R} (hc : IsRegular c) : star c * a * c < star c * b * c := by rw [(conjugate_le_conjugate hab.le _).lt_iff_ne, hc.right.ne_iff, hc.star.left.ne_iff] exact hab.ne theorem conjugate_lt_conjugate' {a b : R} (hab : a < b) {c : R} (hc : IsRegular c) : c * a * star c < c * b * star c := by simpa only [star_star] using conjugate_lt_conjugate hab hc.star theorem conjugate_pos {a : R} (ha : 0 < a) {c : R} (hc : IsRegular c) : 0 < star c * a * c := by simpa only [mul_zero, zero_mul] using conjugate_lt_conjugate ha hc theorem conjugate_pos' {a : R} (ha : 0 < a) {c : R} (hc : IsRegular c) : 0 < c * a * star c := by simpa only [star_star] using conjugate_pos ha hc.star theorem star_mul_self_pos [Nontrivial R] {x : R} (hx : IsRegular x) : 0 < star x * x := by rw [(star_mul_self_nonneg _).lt_iff_ne, ← mul_zero (star x), hx.star.left.ne_iff] exact hx.ne_zero.symm theorem mul_star_self_pos [Nontrivial R] {x : R} (hx : IsRegular x) : 0 < x * star x := by simpa using star_mul_self_pos hx.star end NonUnitalSemiring section Semiring variable [Semiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] instance : ZeroLEOneClass R where zero_le_one := by simpa using star_mul_self_nonneg (1 : R) @[simp] lemma one_le_star_iff {x : R} : 1 ≤ star x ↔ 1 ≤ x := by simpa using star_le_star_iff (x := 1) (y := x) @[simp] lemma star_le_one_iff {x : R} : star x ≤ 1 ↔ x ≤ 1 := by simpa using star_le_star_iff (x := x) (y := 1) @[simp] lemma one_lt_star_iff {x : R} : 1 < star x ↔ 1 < x := by simpa using star_lt_star_iff (x := 1) (y := x) @[simp] lemma star_lt_one_iff {x : R} : star x < 1 ↔ x < 1 := by simpa using star_lt_star_iff (x := x) (y := 1) end Semiring section StarModule variable {A : Type*} [Semiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] [NonUnitalRing A] [StarRing A] [PartialOrder A] [StarOrderedRing A] [Module R A] [StarModule R A] [NoZeroSMulDivisors R A] [IsScalarTower R A A] [SMulCommClass R A A] lemma StarModule.smul_lt_smul_of_pos {a b : A} {c : R} (hab : a < b) (hc : 0 < c) : c • a < c • b := by rw [← sub_pos] at hab ⊢ rw [← smul_sub] refine lt_of_le_of_ne ?le ?ne case le => have hab := le_of_lt hab rw [StarOrderedRing.nonneg_iff] at hab ⊢ refine AddSubmonoid.closure_induction hab ?mem ?zero ?add case mem => intro x hx have hc := le_of_lt hc rw [StarOrderedRing.nonneg_iff] at hc refine AddSubmonoid.closure_induction hc ?memc ?zeroc ?addc case memc => intro c' hc' obtain ⟨z, hz⟩ := hc' obtain ⟨y, hy⟩ := hx apply AddSubmonoid.subset_closure refine ⟨z • y, ?_⟩ simp only [star_smul, smul_mul_smul, hz, hy] case zeroc => simpa only [zero_smul] using zero_mem _ case addc => exact fun c' d ↦ by simpa only [add_smul] using add_mem case zero => simpa only [smul_zero] using zero_mem _ case add => exact fun x y ↦ by simpa only [smul_add] using add_mem case ne => refine (smul_ne_zero ?_ ?_).symm · exact (ne_of_lt hc).symm · exact (ne_of_lt hab).symm end StarModule section OrderClass variable {F R S : Type*} [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] variable [NonUnitalSemiring S] [PartialOrder S] [StarRing S] [StarOrderedRing S] -- we prove this auxiliary lemma in order to avoid duplicating the proof twice below. lemma NonUnitalStarRingHom.map_le_map_of_map_star (f : R →⋆ₙ+* S) {x y : R} (hxy : x ≤ y) : f x ≤ f y := by rw [StarOrderedRing.le_iff] at hxy ⊢ obtain ⟨p, hp, rfl⟩ := hxy refine ⟨f p, ?_, map_add f _ _⟩ have hf : ∀ r, f (star r) = star (f r) := map_star _ induction hp using AddSubmonoid.closure_induction' all_goals aesop instance (priority := 100) StarRingHomClass.instOrderHomClass [FunLike F R S] [NonUnitalSemiring R] [StarRing R] [StarOrderedRing R] [NonUnitalSemiring S] [StarRing S] [StarOrderedRing S] [NonUnitalRingHomClass F R S] [NonUnitalStarRingHomClass F R S] : OrderHomClass F R S where map_rel f := (f : R →⋆ₙ+* S).map_le_map_of_map_star instance (priority := 100) StarRingEquivClass.instOrderIsoClass [EquivLike F R S] [StarRingEquivClass F R S] : OrderIsoClass F R S where map_le_map_iff f x y := by refine ⟨fun h ↦ ?_, map_rel f⟩ let f_inv : S →⋆ₙ+* R := (f : R ≃⋆+* S).symm have f_inv_f (r : R) : f_inv (f r) = r := EquivLike.inv_apply_apply f r rw [← f_inv_f x, ← f_inv_f y] exact NonUnitalStarRingHom.map_le_map_of_map_star f_inv h end OrderClass instance Nat.instStarOrderedRing : StarOrderedRing ℕ where le_iff a b := by have : AddSubmonoid.closure (range fun x : ℕ ↦ x * x) = ⊤ := eq_top_mono (AddSubmonoid.closure_mono <| singleton_subset_iff.2 <| mem_range.2 ⟨1, one_mul _⟩) Nat.addSubmonoid_closure_one simp [this, le_iff_exists_add]
Algebra\Star\Pi.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.Ring.Pi /-! # `star` on pi types We put a `Star` structure on pi types that operates elementwise, such that it describes the complex conjugation of vectors. -/ universe u v w variable {I : Type u} -- The indexing type variable {f : I → Type v} -- The family of types already equipped with instances namespace Pi instance [∀ i, Star (f i)] : Star (∀ i, f i) where star x i := star (x i) @[simp] theorem star_apply [∀ i, Star (f i)] (x : ∀ i, f i) (i : I) : star x i = star (x i) := rfl theorem star_def [∀ i, Star (f i)] (x : ∀ i, f i) : star x = fun i => star (x i) := rfl instance [∀ i, Star (f i)] [∀ i, TrivialStar (f i)] : TrivialStar (∀ i, f i) where star_trivial _ := funext fun _ => star_trivial _ instance [∀ i, InvolutiveStar (f i)] : InvolutiveStar (∀ i, f i) where star_involutive _ := funext fun _ => star_star _ instance [∀ i, Mul (f i)] [∀ i, StarMul (f i)] : StarMul (∀ i, f i) where star_mul _ _ := funext fun _ => star_mul _ _ instance [∀ i, AddMonoid (f i)] [∀ i, StarAddMonoid (f i)] : StarAddMonoid (∀ i, f i) where star_add _ _ := funext fun _ => star_add _ _ instance [∀ i, NonUnitalSemiring (f i)] [∀ i, StarRing (f i)] : StarRing (∀ i, f i) where star_add _ _ := funext fun _ => star_add _ _ instance {R : Type w} [∀ i, SMul R (f i)] [Star R] [∀ i, Star (f i)] [∀ i, StarModule R (f i)] : StarModule R (∀ i, f i) where star_smul r x := funext fun i => star_smul r (x i) theorem single_star [∀ i, AddMonoid (f i)] [∀ i, StarAddMonoid (f i)] [DecidableEq I] (i : I) (a : f i) : Pi.single i (star a) = star (Pi.single i a) := single_op (fun i => @star (f i) _) (fun _ => star_zero _) i a open scoped ComplexConjugate @[simp] lemma conj_apply {ι : Type*} {α : ι → Type*} [∀ i, CommSemiring (α i)] [∀ i, StarRing (α i)] (f : ∀ i, α i) (i : ι) : conj f i = conj (f i) := rfl end Pi namespace Function theorem update_star [∀ i, Star (f i)] [DecidableEq I] (h : ∀ i : I, f i) (i : I) (a : f i) : Function.update (star h) i (star a) = star (Function.update h i a) := funext fun j => (apply_update (fun _ => star) h i a j).symm theorem star_sum_elim {I J α : Type*} (x : I → α) (y : J → α) [Star α] : star (Sum.elim x y) = Sum.elim (star x) (star y) := by ext x; cases x <;> simp only [Pi.star_apply, Sum.elim_inl, Sum.elim_inr] end Function
Algebra\Star\Pointwise.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Star.Basic import Mathlib.Data.Set.Finite import Mathlib.Data.Set.Pointwise.Basic /-! # Pointwise star operation on sets This file defines the star operation pointwise on sets and provides the basic API. Besides basic facts about how the star operation acts on sets (e.g., `(s ∩ t)⋆ = s⋆ ∩ t⋆`), if `s t : Set α`, then under suitable assumption on `α`, it is shown * `(s + t)⋆ = s⋆ + t⋆` * `(s * t)⋆ = t⋆ + s⋆` * `(s⁻¹)⋆ = (s⋆)⁻¹` -/ namespace Set open Pointwise local postfix:max "⋆" => star variable {α : Type*} {s t : Set α} {a : α} /-- The set `(star s : Set α)` is defined as `{x | star x ∈ s}` in the locale `Pointwise`. In the usual case where `star` is involutive, it is equal to `{star s | x ∈ s}`, see `Set.image_star`. -/ protected def star [Star α] : Star (Set α) := ⟨preimage Star.star⟩ scoped[Pointwise] attribute [instance] Set.star @[simp] theorem star_empty [Star α] : (∅ : Set α)⋆ = ∅ := rfl @[simp] theorem star_univ [Star α] : (univ : Set α)⋆ = univ := rfl @[simp] theorem nonempty_star [InvolutiveStar α] {s : Set α} : s⋆.Nonempty ↔ s.Nonempty := star_involutive.surjective.nonempty_preimage theorem Nonempty.star [InvolutiveStar α] {s : Set α} (h : s.Nonempty) : s⋆.Nonempty := nonempty_star.2 h @[simp] theorem mem_star [Star α] : a ∈ s⋆ ↔ a⋆ ∈ s := Iff.rfl theorem star_mem_star [InvolutiveStar α] : a⋆ ∈ s⋆ ↔ a ∈ s := by simp only [mem_star, star_star] @[simp] theorem star_preimage [Star α] : Star.star ⁻¹' s = s⋆ := rfl @[simp] theorem image_star [InvolutiveStar α] : Star.star '' s = s⋆ := by simp only [← star_preimage] rw [image_eq_preimage_of_inverse] <;> intro <;> simp only [star_star] @[simp] theorem inter_star [Star α] : (s ∩ t)⋆ = s⋆ ∩ t⋆ := preimage_inter @[simp] theorem union_star [Star α] : (s ∪ t)⋆ = s⋆ ∪ t⋆ := preimage_union @[simp] theorem iInter_star {ι : Sort*} [Star α] (s : ι → Set α) : (⋂ i, s i)⋆ = ⋂ i, (s i)⋆ := preimage_iInter @[simp] theorem iUnion_star {ι : Sort*} [Star α] (s : ι → Set α) : (⋃ i, s i)⋆ = ⋃ i, (s i)⋆ := preimage_iUnion @[simp] theorem compl_star [Star α] : sᶜ⋆ = s⋆ᶜ := preimage_compl @[simp] instance [InvolutiveStar α] : InvolutiveStar (Set α) where star := Star.star star_involutive s := by simp only [← star_preimage, preimage_preimage, star_star, preimage_id'] @[simp] theorem star_subset_star [InvolutiveStar α] {s t : Set α} : s⋆ ⊆ t⋆ ↔ s ⊆ t := Equiv.star.surjective.preimage_subset_preimage_iff theorem star_subset [InvolutiveStar α] {s t : Set α} : s⋆ ⊆ t ↔ s ⊆ t⋆ := by rw [← star_subset_star, star_star] theorem Finite.star [InvolutiveStar α] {s : Set α} (hs : s.Finite) : s⋆.Finite := hs.preimage star_injective.injOn theorem star_singleton {β : Type*} [InvolutiveStar β] (x : β) : ({x} : Set β)⋆ = {x⋆} := by ext1 y rw [mem_star, mem_singleton_iff, mem_singleton_iff, star_eq_iff_star_eq, eq_comm] protected theorem star_mul [Mul α] [StarMul α] (s t : Set α) : (s * t)⋆ = t⋆ * s⋆ := by simp_rw [← image_star, ← image2_mul, image_image2, image2_image_left, image2_image_right, star_mul, image2_swap _ s t] protected theorem star_add [AddMonoid α] [StarAddMonoid α] (s t : Set α) : (s + t)⋆ = s⋆ + t⋆ := by simp_rw [← image_star, ← image2_add, image_image2, image2_image_left, image2_image_right, star_add] @[simp] instance [Star α] [TrivialStar α] : TrivialStar (Set α) where star_trivial s := by rw [← star_preimage] ext1 simp [star_trivial] protected theorem star_inv [Group α] [StarMul α] (s : Set α) : s⁻¹⋆ = s⋆⁻¹ := by ext simp only [mem_star, mem_inv, star_inv] protected theorem star_inv' [DivisionSemiring α] [StarRing α] (s : Set α) : s⁻¹⋆ = s⋆⁻¹ := by ext simp only [mem_star, mem_inv, star_inv'] end Set @[simp] lemma StarMemClass.star_coe_eq {S α : Type*} [InvolutiveStar α] [SetLike S α] [StarMemClass S α] (s : S) : star (s : Set α) = s := by ext x simp only [Set.mem_star, SetLike.mem_coe] exact ⟨by simpa only [star_star] using star_mem (s := s) (r := star x), star_mem⟩
Algebra\Star\Prod.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Prod import Mathlib.Algebra.Ring.Prod import Mathlib.Algebra.Star.Basic /-! # `Star` on product types We put a `Star` structure on product types that operates elementwise. -/ universe u v w variable {R : Type u} {S : Type v} namespace Prod instance [Star R] [Star S] : Star (R × S) where star x := (star x.1, star x.2) @[simp] theorem fst_star [Star R] [Star S] (x : R × S) : (star x).1 = star x.1 := rfl @[simp] theorem snd_star [Star R] [Star S] (x : R × S) : (star x).2 = star x.2 := rfl theorem star_def [Star R] [Star S] (x : R × S) : star x = (star x.1, star x.2) := rfl instance [Star R] [Star S] [TrivialStar R] [TrivialStar S] : TrivialStar (R × S) where star_trivial _ := Prod.ext (star_trivial _) (star_trivial _) instance [InvolutiveStar R] [InvolutiveStar S] : InvolutiveStar (R × S) where star_involutive _ := Prod.ext (star_star _) (star_star _) instance [Mul R] [Mul S] [StarMul R] [StarMul S] : StarMul (R × S) where star_mul _ _ := Prod.ext (star_mul _ _) (star_mul _ _) instance [AddMonoid R] [AddMonoid S] [StarAddMonoid R] [StarAddMonoid S] : StarAddMonoid (R × S) where star_add _ _ := Prod.ext (star_add _ _) (star_add _ _) instance [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] [StarRing R] [StarRing S] : StarRing (R × S) := { inferInstanceAs (StarAddMonoid (R × S)), inferInstanceAs (StarMul (R × S)) with } instance {α : Type w} [SMul α R] [SMul α S] [Star α] [Star R] [Star S] [StarModule α R] [StarModule α S] : StarModule α (R × S) where star_smul _ _ := Prod.ext (star_smul _ _) (star_smul _ _) end Prod -- Porting note: removing @[simp], `simp` simplifies LHS theorem Units.embed_product_star [Monoid R] [StarMul R] (u : Rˣ) : Units.embedProduct R (star u) = star (Units.embedProduct R u) := rfl
Algebra\Star\Rat.lean
/- Copyright (c) 2024 Yael Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yael Dillies -/ import Mathlib.Algebra.Field.Opposite import Mathlib.Algebra.Star.Basic import Mathlib.Data.NNRat.Defs import Mathlib.Data.Rat.Cast.Defs /-! # *-ring structure on ℚ and ℚ≥0. -/ instance Rat.instStarRing : StarRing ℚ := starRingOfComm instance NNRat.instStarRing : StarRing ℚ≥0 := starRingOfComm instance Rat.instTrivialStar : TrivialStar ℚ := ⟨fun _ ↦ rfl⟩ instance NNRat.instTrivialStar : TrivialStar ℚ≥0 := ⟨fun _ ↦ rfl⟩ variable {R : Type*} open MulOpposite @[simp, norm_cast] lemma star_nnratCast [DivisionSemiring R] [StarRing R] (q : ℚ≥0) : star (q : R) = q := (congr_arg unop <| map_nnratCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) q).trans (unop_nnratCast _) @[simp, norm_cast] theorem star_ratCast [DivisionRing R] [StarRing R] (r : ℚ) : star (r : R) = r := (congr_arg unop <| map_ratCast (starRingEquiv : R ≃+* Rᵐᵒᵖ) r).trans (unop_ratCast _)
Algebra\Star\RingQuot.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.RingQuot import Mathlib.Algebra.Star.Basic /-! # The *-ring structure on suitable quotients of a *-ring. -/ namespace RingQuot universe u variable {R : Type u} [Semiring R] (r : R → R → Prop) section StarRing variable [StarRing R] theorem Rel.star (hr : ∀ a b, r a b → r (star a) (star b)) ⦃a b : R⦄ (h : Rel r a b) : Rel r (star a) (star b) := by induction h with | of h => exact Rel.of (hr _ _ h) | add_left _ h => rw [star_add, star_add] exact Rel.add_left h | mul_left _ h => rw [star_mul, star_mul] exact Rel.mul_right h | mul_right _ h => rw [star_mul, star_mul] exact Rel.mul_left h private irreducible_def star' (hr : ∀ a b, r a b → r (star a) (star b)) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (star : R → R) (Rel.star r hr) a⟩ theorem star'_quot (hr : ∀ a b, r a b → r (star a) (star b)) {a} : (star' r hr ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (star a)⟩ := star'_def _ _ _ /-- Transfer a star_ring instance through a quotient, if the quotient is invariant to `star` -/ def starRing {R : Type u} [Semiring R] [StarRing R] (r : R → R → Prop) (hr : ∀ a b, r a b → r (star a) (star b)) : StarRing (RingQuot r) where star := star' r hr star_involutive := by rintro ⟨⟨⟩⟩ simp [star'_quot] star_mul := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [star'_quot, mul_quot, star_mul] star_add := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [star'_quot, add_quot, star_add] end StarRing end RingQuot
Algebra\Star\SelfAdjoint.lean
/- Copyright (c) 2021 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Star.Pi import Mathlib.Algebra.Star.Rat /-! # Self-adjoint, skew-adjoint and normal elements of a star additive group This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group, as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`). This includes, for instance, (skew-)Hermitian operators on Hilbert spaces. We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies `star x * x = x * star x`. ## Implementation notes * When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural `Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)` and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass `[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then add a `[Module R₃ (selfAdjoint R)]` instance whenever we have `[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define `[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but this typeclass would have the disadvantage of taking two type arguments.) ## TODO * Define `IsSkewAdjoint` to match `IsSelfAdjoint`. * Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R` (similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is invariant under it. -/ open Function variable {R A : Type*} /-- An element is self-adjoint if it is equal to its star. -/ def IsSelfAdjoint [Star R] (x : R) : Prop := star x = x /-- An element of a star monoid is normal if it commutes with its adjoint. -/ @[mk_iff] class IsStarNormal [Mul R] [Star R] (x : R) : Prop where /-- A normal element of a star monoid commutes with its adjoint. -/ star_comm_self : Commute (star x) x export IsStarNormal (star_comm_self) theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x := IsStarNormal.star_comm_self namespace IsSelfAdjoint -- named to match `Commute.allₓ` /-- All elements are self-adjoint when `star` is trivial. -/ theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r := star_trivial _ theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x := hx theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x := Iff.rfl @[simp] theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by simpa only [IsSelfAdjoint, star_star] using eq_comm @[simp] theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by simp only [IsSelfAdjoint, star_mul, star_star] @[simp] theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by simpa only [star_star] using star_mul_self (star x) /-- Self-adjoint elements commute if and only if their product is self-adjoint. -/ lemma commute_iff {R : Type*} [Mul R] [StarMul R] {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : Commute x y ↔ IsSelfAdjoint (x * y) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [isSelfAdjoint_iff, star_mul, hx.star_eq, hy.star_eq, h.eq] · simpa only [star_mul, hx.star_eq, hy.star_eq] using h.symm /-- Functions in a `StarHomClass` preserve self-adjoint elements. -/ theorem starHom_apply {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] {x : R} (hx : IsSelfAdjoint x) (f : F) : IsSelfAdjoint (f x) := show star (f x) = f x from map_star f x ▸ congr_arg f hx /- note: this lemma is *not* marked as `simp` so that Lean doesn't look for a `[TrivialStar R]` instance every time it sees `⊢ IsSelfAdjoint (f x)`, which will likely occur relatively often. -/ theorem _root_.isSelfAdjoint_starHom_apply {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] [TrivialStar R] (f : F) (x : R) : IsSelfAdjoint (f x) := (IsSelfAdjoint.all x).starHom_apply f section AddMonoid variable [AddMonoid R] [StarAddMonoid R] variable (R) @[simp] protected theorem zero : IsSelfAdjoint (0 : R) := star_zero R variable {R} @[aesop 90% apply] theorem add {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x + y) := by simp only [isSelfAdjoint_iff, star_add, hx.star_eq, hy.star_eq] end AddMonoid section AddGroup variable [AddGroup R] [StarAddMonoid R] @[aesop safe apply] theorem neg {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint (-x) := by simp only [isSelfAdjoint_iff, star_neg, hx.star_eq] @[aesop 90% apply] theorem sub {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x - y) := by simp only [isSelfAdjoint_iff, star_sub, hx.star_eq, hy.star_eq] end AddGroup section AddCommMonoid variable [AddCommMonoid R] [StarAddMonoid R] @[simp] theorem add_star_self (x : R) : IsSelfAdjoint (x + star x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] @[simp] theorem star_add_self (x : R) : IsSelfAdjoint (star x + x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] end AddCommMonoid section Semigroup variable [Semigroup R] [StarMul R] @[aesop safe apply] theorem conjugate {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (z * x * star z) := by simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq] @[aesop safe apply] theorem conjugate' {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (star z * x * z) := by simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq] @[aesop 10% apply] theorem isStarNormal {x : R} (hx : IsSelfAdjoint x) : IsStarNormal x := ⟨by simp only [Commute, SemiconjBy, hx.star_eq]⟩ end Semigroup section MulOneClass variable [MulOneClass R] [StarMul R] variable (R) @[simp] protected theorem one : IsSelfAdjoint (1 : R) := star_one R end MulOneClass section Monoid variable [Monoid R] [StarMul R] @[aesop safe apply] theorem pow {x : R} (hx : IsSelfAdjoint x) (n : ℕ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_pow, hx.star_eq] end Monoid section Semiring variable [Semiring R] [StarRing R] @[simp] protected theorem natCast (n : ℕ) : IsSelfAdjoint (n : R) := star_natCast _ -- See note [no_index around OfNat.ofNat] @[simp] protected theorem ofNat (n : ℕ) [n.AtLeastTwo] : IsSelfAdjoint (no_index (OfNat.ofNat n : R)) := .natCast n end Semiring section CommSemigroup variable [CommSemigroup R] [StarMul R] theorem mul {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x * y) := by simp only [isSelfAdjoint_iff, star_mul', hx.star_eq, hy.star_eq] end CommSemigroup section CommSemiring variable {α : Type*} [CommSemiring α] [StarRing α] {a : α} open scoped ComplexConjugate lemma conj_eq (ha : IsSelfAdjoint a) : conj a = a := ha.star_eq end CommSemiring section Ring variable [Ring R] [StarRing R] @[simp] protected theorem intCast (z : ℤ) : IsSelfAdjoint (z : R) := star_intCast _ end Ring section DivisionSemiring variable [DivisionSemiring R] [StarRing R] @[aesop safe apply] theorem inv {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint x⁻¹ := by simp only [isSelfAdjoint_iff, star_inv', hx.star_eq] @[aesop safe apply] theorem zpow {x : R} (hx : IsSelfAdjoint x) (n : ℤ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_zpow₀, hx.star_eq] @[simp] protected lemma nnratCast (q : ℚ≥0) : IsSelfAdjoint (q : R) := star_nnratCast _ end DivisionSemiring section DivisionRing variable [DivisionRing R] [StarRing R] @[simp] protected theorem ratCast (x : ℚ) : IsSelfAdjoint (x : R) := star_ratCast _ end DivisionRing section Semifield variable [Semifield R] [StarRing R] theorem div {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x / y) := by simp only [isSelfAdjoint_iff, star_div', hx.star_eq, hy.star_eq] end Semifield section SMul variable [Star R] [AddMonoid A] [StarAddMonoid A] [SMul R A] [StarModule R A] @[aesop safe apply] theorem smul {r : R} (hr : IsSelfAdjoint r) {x : A} (hx : IsSelfAdjoint x) : IsSelfAdjoint (r • x) := by simp only [isSelfAdjoint_iff, star_smul, hr.star_eq, hx.star_eq] end SMul end IsSelfAdjoint variable (R) /-- The self-adjoint elements of a star additive group, as an additive subgroup. -/ def selfAdjoint [AddGroup R] [StarAddMonoid R] : AddSubgroup R where carrier := { x | IsSelfAdjoint x } zero_mem' := star_zero R add_mem' hx := hx.add neg_mem' hx := hx.neg /-- The skew-adjoint elements of a star additive group, as an additive subgroup. -/ def skewAdjoint [AddCommGroup R] [StarAddMonoid R] : AddSubgroup R where carrier := { x | star x = -x } zero_mem' := show star (0 : R) = -0 by simp only [star_zero, neg_zero] add_mem' := @fun x y (hx : star x = -x) (hy : star y = -y) => show star (x + y) = -(x + y) by rw [star_add x y, hx, hy, neg_add] neg_mem' := @fun x (hx : star x = -x) => show star (-x) = - -x by simp only [hx, star_neg] variable {R} namespace selfAdjoint section AddGroup variable [AddGroup R] [StarAddMonoid R] theorem mem_iff {x : R} : x ∈ selfAdjoint R ↔ star x = x := by rw [← AddSubgroup.mem_carrier] exact Iff.rfl @[simp, norm_cast] theorem star_val_eq {x : selfAdjoint R} : star (x : R) = x := x.prop instance : Inhabited (selfAdjoint R) := ⟨0⟩ end AddGroup instance isStarNormal [NonUnitalRing R] [StarRing R] (x : selfAdjoint R) : IsStarNormal (x : R) := x.prop.isStarNormal section Ring variable [Ring R] [StarRing R] instance : One (selfAdjoint R) := ⟨⟨1, .one R⟩⟩ @[simp, norm_cast] theorem val_one : ↑(1 : selfAdjoint R) = (1 : R) := rfl instance [Nontrivial R] : Nontrivial (selfAdjoint R) := ⟨⟨0, 1, ne_of_apply_ne Subtype.val zero_ne_one⟩⟩ instance : NatCast (selfAdjoint R) where natCast n := ⟨n, .natCast _⟩ instance : IntCast (selfAdjoint R) where intCast n := ⟨n, .intCast _⟩ instance : Pow (selfAdjoint R) ℕ where pow x n := ⟨(x : R) ^ n, x.prop.pow n⟩ @[simp, norm_cast] theorem val_pow (x : selfAdjoint R) (n : ℕ) : ↑(x ^ n) = (x : R) ^ n := rfl end Ring section NonUnitalCommRing variable [NonUnitalCommRing R] [StarRing R] instance : Mul (selfAdjoint R) where mul x y := ⟨(x : R) * y, x.prop.mul y.prop⟩ @[simp, norm_cast] theorem val_mul (x y : selfAdjoint R) : ↑(x * y) = (x : R) * y := rfl end NonUnitalCommRing section CommRing variable [CommRing R] [StarRing R] instance : CommRing (selfAdjoint R) := Function.Injective.commRing _ Subtype.coe_injective (selfAdjoint R).coe_zero val_one (selfAdjoint R).coe_add val_mul (selfAdjoint R).coe_neg (selfAdjoint R).coe_sub (by intros; rfl) (by intros; rfl) val_pow (fun _ => rfl) fun _ => rfl end CommRing section Field variable [Field R] [StarRing R] instance : Inv (selfAdjoint R) where inv x := ⟨x.val⁻¹, x.prop.inv⟩ @[simp, norm_cast] theorem val_inv (x : selfAdjoint R) : ↑x⁻¹ = (x : R)⁻¹ := rfl instance : Div (selfAdjoint R) where div x y := ⟨x / y, x.prop.div y.prop⟩ @[simp, norm_cast] theorem val_div (x y : selfAdjoint R) : ↑(x / y) = (x / y : R) := rfl instance : Pow (selfAdjoint R) ℤ where pow x z := ⟨(x : R) ^ z, x.prop.zpow z⟩ @[simp, norm_cast] theorem val_zpow (x : selfAdjoint R) (z : ℤ) : ↑(x ^ z) = (x : R) ^ z := rfl instance instNNRatCast : NNRatCast (selfAdjoint R) where nnratCast q := ⟨q, .nnratCast q⟩ instance instRatCast : RatCast (selfAdjoint R) where ratCast q := ⟨q, .ratCast q⟩ @[simp, norm_cast] lemma val_nnratCast (q : ℚ≥0) : (q : selfAdjoint R) = (q : R) := rfl @[simp, norm_cast] lemma val_ratCast (q : ℚ) : (q : selfAdjoint R) = (q : R) := rfl instance instSMulNNRat : SMul ℚ≥0 (selfAdjoint R) where smul a x := ⟨a • (x : R), by rw [NNRat.smul_def]; exact .mul (.nnratCast a) x.prop⟩ instance instSMulRat : SMul ℚ (selfAdjoint R) where smul a x := ⟨a • (x : R), by rw [Rat.smul_def]; exact .mul (.ratCast a) x.prop⟩ @[simp, norm_cast] lemma val_nnqsmul (q : ℚ≥0) (x : selfAdjoint R) : ↑(q • x) = q • (x : R) := rfl @[simp, norm_cast] lemma val_qsmul (q : ℚ) (x : selfAdjoint R) : ↑(q • x) = q • (x : R) := rfl instance instField : Field (selfAdjoint R) := Subtype.coe_injective.field _ (selfAdjoint R).coe_zero val_one (selfAdjoint R).coe_add val_mul (selfAdjoint R).coe_neg (selfAdjoint R).coe_sub val_inv val_div (swap (selfAdjoint R).coe_nsmul) (by intros; rfl) val_nnqsmul val_qsmul val_pow val_zpow (fun _ => rfl) (fun _ => rfl) val_nnratCast val_ratCast end Field section SMul variable [Star R] [TrivialStar R] [AddGroup A] [StarAddMonoid A] instance [SMul R A] [StarModule R A] : SMul R (selfAdjoint A) where smul r x := ⟨r • (x : A), (IsSelfAdjoint.all _).smul x.prop⟩ @[simp, norm_cast] theorem val_smul [SMul R A] [StarModule R A] (r : R) (x : selfAdjoint A) : ↑(r • x) = r • (x : A) := rfl instance [Monoid R] [MulAction R A] [StarModule R A] : MulAction R (selfAdjoint A) := Function.Injective.mulAction (↑) Subtype.coe_injective val_smul instance [Monoid R] [DistribMulAction R A] [StarModule R A] : DistribMulAction R (selfAdjoint A) := Function.Injective.distribMulAction (selfAdjoint A).subtype Subtype.coe_injective val_smul end SMul section Module variable [Star R] [TrivialStar R] [AddCommGroup A] [StarAddMonoid A] instance [Semiring R] [Module R A] [StarModule R A] : Module R (selfAdjoint A) := Function.Injective.module R (selfAdjoint A).subtype Subtype.coe_injective val_smul end Module end selfAdjoint namespace skewAdjoint section AddGroup variable [AddCommGroup R] [StarAddMonoid R] theorem mem_iff {x : R} : x ∈ skewAdjoint R ↔ star x = -x := by rw [← AddSubgroup.mem_carrier] exact Iff.rfl @[simp, norm_cast] theorem star_val_eq {x : skewAdjoint R} : star (x : R) = -x := x.prop instance : Inhabited (skewAdjoint R) := ⟨0⟩ end AddGroup section Ring variable [Ring R] [StarRing R] theorem conjugate {x : R} (hx : x ∈ skewAdjoint R) (z : R) : z * x * star z ∈ skewAdjoint R := by simp only [mem_iff, star_mul, star_star, mem_iff.mp hx, neg_mul, mul_neg, mul_assoc] theorem conjugate' {x : R} (hx : x ∈ skewAdjoint R) (z : R) : star z * x * z ∈ skewAdjoint R := by simp only [mem_iff, star_mul, star_star, mem_iff.mp hx, neg_mul, mul_neg, mul_assoc] theorem isStarNormal_of_mem {x : R} (hx : x ∈ skewAdjoint R) : IsStarNormal x := ⟨by simp only [mem_iff] at hx simp only [hx, Commute.neg_left, Commute.refl]⟩ instance (x : skewAdjoint R) : IsStarNormal (x : R) := isStarNormal_of_mem (SetLike.coe_mem _) end Ring section SMul variable [Star R] [TrivialStar R] [AddCommGroup A] [StarAddMonoid A] @[aesop safe apply (rule_sets := [SetLike])] theorem smul_mem [Monoid R] [DistribMulAction R A] [StarModule R A] (r : R) {x : A} (h : x ∈ skewAdjoint A) : r • x ∈ skewAdjoint A := by rw [mem_iff, star_smul, star_trivial, mem_iff.mp h, smul_neg r] instance [Monoid R] [DistribMulAction R A] [StarModule R A] : SMul R (skewAdjoint A) where smul r x := ⟨r • (x : A), smul_mem r x.prop⟩ @[simp, norm_cast] theorem val_smul [Monoid R] [DistribMulAction R A] [StarModule R A] (r : R) (x : skewAdjoint A) : ↑(r • x) = r • (x : A) := rfl instance [Monoid R] [DistribMulAction R A] [StarModule R A] : DistribMulAction R (skewAdjoint A) := Function.Injective.distribMulAction (skewAdjoint A).subtype Subtype.coe_injective val_smul instance [Semiring R] [Module R A] [StarModule R A] : Module R (skewAdjoint A) := Function.Injective.module R (skewAdjoint A).subtype Subtype.coe_injective val_smul end SMul end skewAdjoint /-- Scalar multiplication of a self-adjoint element by a skew-adjoint element produces a skew-adjoint element. -/ theorem IsSelfAdjoint.smul_mem_skewAdjoint [Ring R] [AddCommGroup A] [Module R A] [StarAddMonoid R] [StarAddMonoid A] [StarModule R A] {r : R} (hr : r ∈ skewAdjoint R) {a : A} (ha : IsSelfAdjoint a) : r • a ∈ skewAdjoint A := (star_smul _ _).trans <| (congr_arg₂ _ hr ha).trans <| neg_smul _ _ /-- Scalar multiplication of a skew-adjoint element by a skew-adjoint element produces a self-adjoint element. -/ theorem isSelfAdjoint_smul_of_mem_skewAdjoint [Ring R] [AddCommGroup A] [Module R A] [StarAddMonoid R] [StarAddMonoid A] [StarModule R A] {r : R} (hr : r ∈ skewAdjoint R) {a : A} (ha : a ∈ skewAdjoint A) : IsSelfAdjoint (r • a) := (star_smul _ _).trans <| (congr_arg₂ _ hr ha).trans <| neg_smul_neg _ _ instance isStarNormal_zero [Semiring R] [StarRing R] : IsStarNormal (0 : R) := ⟨by simp only [Commute.refl, star_comm_self, star_zero]⟩ instance isStarNormal_one [MulOneClass R] [StarMul R] : IsStarNormal (1 : R) := ⟨by simp only [Commute.refl, star_comm_self, star_one]⟩ protected instance IsStarNormal.star [Mul R] [StarMul R] {x : R} [IsStarNormal x] : IsStarNormal (star x) := ⟨show star (star x) * star x = star x * star (star x) by rw [star_star, star_comm_self']⟩ protected instance IsStarNormal.neg [Ring R] [StarAddMonoid R] {x : R} [IsStarNormal x] : IsStarNormal (-x) := ⟨show star (-x) * -x = -x * star (-x) by simp_rw [star_neg, neg_mul_neg, star_comm_self']⟩ protected instance IsStarNormal.map {F R S : Type*} [Mul R] [Star R] [Mul S] [Star S] [FunLike F R S] [MulHomClass F R S] [StarHomClass F R S] (f : F) (r : R) [hr : IsStarNormal r] : IsStarNormal (f r) where star_comm_self := by simpa [map_star] using congr(f $(hr.star_comm_self)) -- see Note [lower instance priority] instance (priority := 100) TrivialStar.isStarNormal [Mul R] [StarMul R] [TrivialStar R] {x : R} : IsStarNormal x := ⟨by rw [star_trivial]⟩ -- see Note [lower instance priority] instance (priority := 100) CommMonoid.isStarNormal [CommMonoid R] [StarMul R] {x : R} : IsStarNormal x := ⟨mul_comm _ _⟩ namespace Pi variable {ι : Type*} {α : ι → Type*} [∀ i, Star (α i)] {f : ∀ i, α i} protected lemma isSelfAdjoint : IsSelfAdjoint f ↔ ∀ i, IsSelfAdjoint (f i) := funext_iff alias ⟨_root_.IsSelfAdjoint.apply, _⟩ := Pi.isSelfAdjoint end Pi
Algebra\Star\StarAlgHom.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Star.Prod import Mathlib.Algebra.Star.StarRingHom /-! # Morphisms of star algebras This file defines morphisms between `R`-algebras (unital or non-unital) `A` and `B` where both `A` and `B` are equipped with a `star` operation. These morphisms, namely `StarAlgHom` and `NonUnitalStarAlgHom` are direct extensions of their non-`star`red counterparts with a field `map_star` which guarantees they preserve the star operation. We keep the type classes as generic as possible, in keeping with the definition of `NonUnitalAlgHom` in the non-unital case. In this file, we only assume `Star` unless we want to talk about the zero map as a `NonUnitalStarAlgHom`, in which case we need `StarAddMonoid`. Note that the scalar ring `R` is not required to have a star operation, nor do we need `StarRing` or `StarModule` structures on `A` and `B`. As with `NonUnitalAlgHom`, in the non-unital case the multiplications are not assumed to be associative or unital, or even to be compatible with the scalar actions. In a typical application, the operations will satisfy compatibility conditions making them into algebras (albeit possibly non-associative and/or non-unital) but such conditions are not required here for the definitions. The primary impetus for defining these types is that they constitute the morphisms in the categories of unital C⋆-algebras (with `StarAlgHom`s) and of C⋆-algebras (with `NonUnitalStarAlgHom`s). ## Main definitions * `NonUnitalStarAlgHom` * `StarAlgHom` ## Tags non-unital, algebra, morphism, star -/ open EquivLike /-! ### Non-unital star algebra homomorphisms -/ /-- A *non-unital ⋆-algebra homomorphism* is a non-unital algebra homomorphism between non-unital `R`-algebras `A` and `B` equipped with a `star` operation, and this homomorphism is also `star`-preserving. -/ structure NonUnitalStarAlgHom (R A B : Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] extends A →ₙₐ[R] B where /-- By definition, a non-unital ⋆-algebra homomorphism preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) @[inherit_doc NonUnitalStarAlgHom] infixr:25 " →⋆ₙₐ " => NonUnitalStarAlgHom _ @[inherit_doc] notation:25 A " →⋆ₙₐ[" R "] " B => NonUnitalStarAlgHom R A B /-- Reinterpret a non-unital star algebra homomorphism as a non-unital algebra homomorphism by forgetting the interaction with the star operation. -/ add_decl_doc NonUnitalStarAlgHom.toNonUnitalAlgHom /-- `NonUnitalStarAlgHomClass F R A B` asserts `F` is a type of bundled non-unital ⋆-algebra homomorphisms from `A` to `B`. -/ class NonUnitalStarAlgHomClass (F : Type*) (R A B : outParam Type*) [Monoid R] [Star A] [Star B] [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [DistribMulAction R A] [DistribMulAction R B] [FunLike F A B] [NonUnitalAlgHomClass F R A B] extends StarHomClass F A B : Prop namespace NonUnitalStarAlgHomClass variable {F R A B : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] /-- Turn an element of a type `F` satisfying `NonUnitalStarAlgHomClass F R A B` into an actual `NonUnitalStarAlgHom`. This is declared as the default coercion from `F` to `A →⋆ₙₐ[R] B`. -/ @[coe] def toNonUnitalStarAlgHom [NonUnitalStarAlgHomClass F R A B] (f : F) : A →⋆ₙₐ[R] B := { (f : A →ₙₐ[R] B) with map_star' := map_star f } instance [NonUnitalStarAlgHomClass F R A B] : CoeTC F (A →⋆ₙₐ[R] B) := ⟨toNonUnitalStarAlgHom⟩ instance [NonUnitalStarAlgHomClass F R A B] : NonUnitalStarRingHomClass F A B := NonUnitalStarRingHomClass.mk end NonUnitalStarAlgHomClass namespace NonUnitalStarAlgHom section Basic variable {R A B C D : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] variable [NonUnitalNonAssocSemiring C] [DistribMulAction R C] [Star C] variable [NonUnitalNonAssocSemiring D] [DistribMulAction R D] [Star D] instance : FunLike (A →⋆ₙₐ[R] B) A B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨⟨f, _⟩, _⟩, _⟩, _⟩ ⟨⟨⟨⟨g, _⟩, _⟩, _⟩, _⟩ h; congr instance : NonUnitalAlgHomClass (A →⋆ₙₐ[R] B) R A B where map_smulₛₗ f := f.map_smul' map_add f := f.map_add' map_zero f := f.map_zero' map_mul f := f.map_mul' instance : NonUnitalStarAlgHomClass (A →⋆ₙₐ[R] B) R A B where map_star f := f.map_star' -- Porting note: in mathlib3 we didn't need the `Simps.apply` hint. /-- See Note [custom simps projection] -/ def Simps.apply (f : A →⋆ₙₐ[R] B) : A → B := f initialize_simps_projections NonUnitalStarAlgHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B] (f : F) : ⇑(f : A →⋆ₙₐ[R] B) = f := rfl @[simp] theorem coe_toNonUnitalAlgHom {f : A →⋆ₙₐ[R] B} : (f.toNonUnitalAlgHom : A → B) = f := rfl @[ext] theorem ext {f g : A →⋆ₙₐ[R] B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Copy of a `NonUnitalStarAlgHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →⋆ₙₐ[R] B) (f' : A → B) (h : f' = f) : A →⋆ₙₐ[R] B where toFun := f' map_smul' := h.symm ▸ map_smul f map_zero' := h.symm ▸ map_zero f map_add' := h.symm ▸ map_add f map_mul' := h.symm ▸ map_mul f map_star' := h.symm ▸ map_star f @[simp] theorem coe_copy (f : A →⋆ₙₐ[R] B) (f' : A → B) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →⋆ₙₐ[R] B) (f' : A → B) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_mk (f : A → B) (h₁ h₂ h₃ h₄ h₅) : ((⟨⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩, h₅⟩ : A →⋆ₙₐ[R] B) : A → B) = f := rfl -- this is probably the more useful lemma for Lean 4 and should likely replace `coe_mk` above @[simp] theorem coe_mk' (f : A →ₙₐ[R] B) (h) : ((⟨f, h⟩ : A →⋆ₙₐ[R] B) : A → B) = f := rfl @[simp] theorem mk_coe (f : A →⋆ₙₐ[R] B) (h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩, h₅⟩ : A →⋆ₙₐ[R] B) = f := by ext rfl section variable (R A) /-- The identity as a non-unital ⋆-algebra homomorphism. -/ protected def id : A →⋆ₙₐ[R] A := { (1 : A →ₙₐ[R] A) with map_star' := fun _ => rfl } @[simp] theorem coe_id : ⇑(NonUnitalStarAlgHom.id R A) = id := rfl end /-- The composition of non-unital ⋆-algebra homomorphisms, as a non-unital ⋆-algebra homomorphism. -/ def comp (f : B →⋆ₙₐ[R] C) (g : A →⋆ₙₐ[R] B) : A →⋆ₙₐ[R] C := { f.toNonUnitalAlgHom.comp g.toNonUnitalAlgHom with map_star' := by simp only [map_star, NonUnitalAlgHom.toFun_eq_coe, eq_self_iff_true, NonUnitalAlgHom.coe_comp, coe_toNonUnitalAlgHom, Function.comp_apply, forall_const] } @[simp] theorem coe_comp (f : B →⋆ₙₐ[R] C) (g : A →⋆ₙₐ[R] B) : ⇑(comp f g) = f ∘ g := rfl @[simp] theorem comp_apply (f : B →⋆ₙₐ[R] C) (g : A →⋆ₙₐ[R] B) (a : A) : comp f g a = f (g a) := rfl @[simp] theorem comp_assoc (f : C →⋆ₙₐ[R] D) (g : B →⋆ₙₐ[R] C) (h : A →⋆ₙₐ[R] B) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem id_comp (f : A →⋆ₙₐ[R] B) : (NonUnitalStarAlgHom.id _ _).comp f = f := ext fun _ => rfl @[simp] theorem comp_id (f : A →⋆ₙₐ[R] B) : f.comp (NonUnitalStarAlgHom.id _ _) = f := ext fun _ => rfl instance : Monoid (A →⋆ₙₐ[R] A) where mul := comp mul_assoc := comp_assoc one := NonUnitalStarAlgHom.id R A one_mul := id_comp mul_one := comp_id @[simp] theorem coe_one : ((1 : A →⋆ₙₐ[R] A) : A → A) = id := rfl theorem one_apply (a : A) : (1 : A →⋆ₙₐ[R] A) a = a := rfl end Basic section Zero -- the `zero` requires extra type class assumptions because we need `star_zero` variable {R A B C D : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [StarAddMonoid A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [StarAddMonoid B] instance : Zero (A →⋆ₙₐ[R] B) := ⟨{ (0 : NonUnitalAlgHom (MonoidHom.id R) A B) with map_star' := by simp }⟩ instance : Inhabited (A →⋆ₙₐ[R] B) := ⟨0⟩ instance : MonoidWithZero (A →⋆ₙₐ[R] A) := { inferInstanceAs (Monoid (A →⋆ₙₐ[R] A)), inferInstanceAs (Zero (A →⋆ₙₐ[R] A)) with zero_mul := fun _ => ext fun _ => rfl mul_zero := fun f => ext fun _ => map_zero f } @[simp] theorem coe_zero : ((0 : A →⋆ₙₐ[R] B) : A → B) = 0 := rfl theorem zero_apply (a : A) : (0 : A →⋆ₙₐ[R] B) a = 0 := rfl end Zero section RestrictScalars variable (R : Type*) {S A B : Type*} [Monoid R] [Monoid S] [Star A] [Star B] [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [MulAction R S] [DistribMulAction S A] [DistribMulAction S B] [DistribMulAction R A] [DistribMulAction R B] [IsScalarTower R S A] [IsScalarTower R S B] /-- If a monoid `R` acts on another monoid `S`, then a non-unital star algebra homomorphism over `S` can be viewed as a non-unital star algebra homomorphism over `R`. -/ def restrictScalars (f : A →⋆ₙₐ[S] B) : A →⋆ₙₐ[R] B := { (f : A →ₙₐ[S] B).restrictScalars R with map_star' := map_star f } @[simp] lemma restrictScalars_apply (f : A →⋆ₙₐ[S] B) (x : A) : f.restrictScalars R x = f x := rfl lemma coe_restrictScalars (f : A →⋆ₙₐ[S] B) : (f.restrictScalars R : A →ₙ+* B) = f := rfl lemma coe_restrictScalars' (f : A →⋆ₙₐ[S] B) : (f.restrictScalars R : A → B) = f := rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : (A →⋆ₙₐ[S] B) → A →⋆ₙₐ[R] B) := fun _ _ h ↦ ext (DFunLike.congr_fun h : _) end RestrictScalars end NonUnitalStarAlgHom /-! ### Unital star algebra homomorphisms -/ section Unital /-- A *⋆-algebra homomorphism* is an algebra homomorphism between `R`-algebras `A` and `B` equipped with a `star` operation, and this homomorphism is also `star`-preserving. -/ structure StarAlgHom (R A B : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] extends AlgHom R A B where /-- By definition, a ⋆-algebra homomorphism preserves the `star` operation. -/ map_star' : ∀ x : A, toFun (star x) = star (toFun x) @[inherit_doc StarAlgHom] infixr:25 " →⋆ₐ " => StarAlgHom _ @[inherit_doc] notation:25 A " →⋆ₐ[" R "] " B => StarAlgHom R A B /-- Reinterpret a unital star algebra homomorphism as a unital algebra homomorphism by forgetting the interaction with the star operation. -/ add_decl_doc StarAlgHom.toAlgHom /-- `StarAlgHomClass F R A B` states that `F` is a type of ⋆-algebra homomorphisms. You should also extend this typeclass when you extend `StarAlgHom`. -/ class StarAlgHomClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] [FunLike F A B] [AlgHomClass F R A B] extends StarHomClass F A B : Prop -- Porting note: no longer needed ---- `R` becomes a metavariable but that's fine because it's an `outParam` --attribute [nolint dangerousInstance] StarAlgHomClass.toStarHomClass namespace StarAlgHomClass variable (F R A B : Type*) -- See note [lower instance priority] instance (priority := 100) toNonUnitalStarAlgHomClass [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] [FunLike F A B] [AlgHomClass F R A B] [StarAlgHomClass F R A B] : NonUnitalStarAlgHomClass F R A B := { } variable [CommSemiring R] [Semiring A] [Algebra R A] [Star A] variable [Semiring B] [Algebra R B] [Star B] [FunLike F A B] [AlgHomClass F R A B] variable [StarAlgHomClass F R A B] variable {F R A B} in /-- Turn an element of a type `F` satisfying `StarAlgHomClass F R A B` into an actual `StarAlgHom`. This is declared as the default coercion from `F` to `A →⋆ₐ[R] B`. -/ @[coe] def toStarAlgHom (f : F) : A →⋆ₐ[R] B := { (f : A →ₐ[R] B) with map_star' := map_star f } instance : CoeTC F (A →⋆ₐ[R] B) := ⟨toStarAlgHom⟩ end StarAlgHomClass namespace StarAlgHom variable {F R A B C D : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] [Semiring C] [Algebra R C] [Star C] [Semiring D] [Algebra R D] [Star D] instance : FunLike (A →⋆ₐ[R] B) A B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨⟨⟨f, _⟩, _⟩, _⟩, _⟩, _⟩ ⟨⟨⟨⟨⟨g, _⟩, _⟩, _⟩, _⟩, _⟩ h; congr instance : AlgHomClass (A →⋆ₐ[R] B) R A B where map_mul f := f.map_mul' map_one f := f.map_one' map_add f := f.map_add' map_zero f := f.map_zero' commutes f := f.commutes' instance : StarAlgHomClass (A →⋆ₐ[R] B) R A B where map_star f := f.map_star' @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [AlgHomClass F R A B] [StarAlgHomClass F R A B] (f : F) : ⇑(f : A →⋆ₐ[R] B) = f := rfl -- Porting note: in mathlib3 we didn't need the `Simps.apply` hint. /-- See Note [custom simps projection] -/ def Simps.apply (f : A →⋆ₐ[R] B) : A → B := f initialize_simps_projections StarAlgHom (toFun → apply) @[simp] theorem coe_toAlgHom {f : A →⋆ₐ[R] B} : (f.toAlgHom : A → B) = f := rfl @[ext] theorem ext {f g : A →⋆ₐ[R] B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Copy of a `StarAlgHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →⋆ₐ[R] B) (f' : A → B) (h : f' = f) : A →⋆ₐ[R] B where toFun := f' map_one' := h.symm ▸ map_one f map_mul' := h.symm ▸ map_mul f map_zero' := h.symm ▸ map_zero f map_add' := h.symm ▸ map_add f commutes' := h.symm ▸ AlgHomClass.commutes f map_star' := h.symm ▸ map_star f @[simp] theorem coe_copy (f : A →⋆ₐ[R] B) (f' : A → B) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →⋆ₐ[R] B) (f' : A → B) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_mk (f : A → B) (h₁ h₂ h₃ h₄ h₅ h₆) : ((⟨⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩, h₆⟩ : A →⋆ₐ[R] B) : A → B) = f := rfl -- this is probably the more useful lemma for Lean 4 and should likely replace `coe_mk` above @[simp] theorem coe_mk' (f : A →ₐ[R] B) (h) : ((⟨f, h⟩ : A →⋆ₐ[R] B) : A → B) = f := rfl @[simp] theorem mk_coe (f : A →⋆ₐ[R] B) (h₁ h₂ h₃ h₄ h₅ h₆) : (⟨⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩, h₆⟩ : A →⋆ₐ[R] B) = f := by ext rfl section variable (R A) /-- The identity as a `StarAlgHom`. -/ protected def id : A →⋆ₐ[R] A := { AlgHom.id _ _ with map_star' := fun _ => rfl } @[simp] theorem coe_id : ⇑(StarAlgHom.id R A) = id := rfl /-- `algebraMap R A` as a `StarAlgHom` when `A` is a star algebra over `R`. -/ @[simps] def ofId (R A : Type*) [CommSemiring R] [StarRing R] [Semiring A] [StarMul A] [Algebra R A] [StarModule R A] : R →⋆ₐ[R] A := { Algebra.ofId R A with toFun := algebraMap R A map_star' := by simp [Algebra.algebraMap_eq_smul_one] } end instance : Inhabited (A →⋆ₐ[R] A) := ⟨StarAlgHom.id R A⟩ /-- The composition of ⋆-algebra homomorphisms, as a ⋆-algebra homomorphism. -/ def comp (f : B →⋆ₐ[R] C) (g : A →⋆ₐ[R] B) : A →⋆ₐ[R] C := { f.toAlgHom.comp g.toAlgHom with map_star' := by simp only [map_star, AlgHom.toFun_eq_coe, AlgHom.coe_comp, coe_toAlgHom, Function.comp_apply, eq_self_iff_true, forall_const] } @[simp] theorem coe_comp (f : B →⋆ₐ[R] C) (g : A →⋆ₐ[R] B) : ⇑(comp f g) = f ∘ g := rfl @[simp] theorem comp_apply (f : B →⋆ₐ[R] C) (g : A →⋆ₐ[R] B) (a : A) : comp f g a = f (g a) := rfl @[simp] theorem comp_assoc (f : C →⋆ₐ[R] D) (g : B →⋆ₐ[R] C) (h : A →⋆ₐ[R] B) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem id_comp (f : A →⋆ₐ[R] B) : (StarAlgHom.id _ _).comp f = f := ext fun _ => rfl @[simp] theorem comp_id (f : A →⋆ₐ[R] B) : f.comp (StarAlgHom.id _ _) = f := ext fun _ => rfl instance : Monoid (A →⋆ₐ[R] A) where mul := comp mul_assoc := comp_assoc one := StarAlgHom.id R A one_mul := id_comp mul_one := comp_id /-- A unital morphism of ⋆-algebras is a `NonUnitalStarAlgHom`. -/ def toNonUnitalStarAlgHom (f : A →⋆ₐ[R] B) : A →⋆ₙₐ[R] B := { f with map_smul' := map_smul f } @[simp] theorem coe_toNonUnitalStarAlgHom (f : A →⋆ₐ[R] B) : (f.toNonUnitalStarAlgHom : A → B) = f := rfl end StarAlgHom end Unital /-! ### Operations on the product type Note that this is copied from [`Algebra.Hom.NonUnitalAlg`](../Hom/NonUnitalAlg). -/ namespace NonUnitalStarAlgHom section Prod variable (R A B C : Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] [NonUnitalNonAssocSemiring C] [DistribMulAction R C] [Star C] /-- The first projection of a product is a non-unital ⋆-algebra homomorphism. -/ @[simps!] def fst : A × B →⋆ₙₐ[R] A := { NonUnitalAlgHom.fst R A B with map_star' := fun _ => rfl } /-- The second projection of a product is a non-unital ⋆-algebra homomorphism. -/ @[simps!] def snd : A × B →⋆ₙₐ[R] B := { NonUnitalAlgHom.snd R A B with map_star' := fun _ => rfl } variable {R A B C} /-- The `Pi.prod` of two morphisms is a morphism. -/ @[simps!] def prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : A →⋆ₙₐ[R] B × C := { f.toNonUnitalAlgHom.prod g.toNonUnitalAlgHom with map_star' := fun x => by simp [map_star, Prod.star_def] } theorem coe_prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : (fst R B C).comp (prod f g) = f := by ext; rfl @[simp] theorem snd_prod (f : A →⋆ₙₐ[R] B) (g : A →⋆ₙₐ[R] C) : (snd R B C).comp (prod f g) = g := by ext; rfl @[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = 1 := DFunLike.coe_injective Pi.prod_fst_snd /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. -/ @[simps] def prodEquiv : (A →⋆ₙₐ[R] B) × (A →⋆ₙₐ[R] C) ≃ (A →⋆ₙₐ[R] B × C) where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) left_inv f := by ext <;> rfl right_inv f := by ext <;> rfl end Prod section InlInr variable (R A B C : Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [StarAddMonoid A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [StarAddMonoid B] [NonUnitalNonAssocSemiring C] [DistribMulAction R C] [StarAddMonoid C] /-- The left injection into a product is a non-unital algebra homomorphism. -/ def inl : A →⋆ₙₐ[R] A × B := prod 1 0 /-- The right injection into a product is a non-unital algebra homomorphism. -/ def inr : B →⋆ₙₐ[R] A × B := prod 0 1 variable {R A B} @[simp] theorem coe_inl : (inl R A B : A → A × B) = fun x => (x, 0) := rfl theorem inl_apply (x : A) : inl R A B x = (x, 0) := rfl @[simp] theorem coe_inr : (inr R A B : B → A × B) = Prod.mk 0 := rfl theorem inr_apply (x : B) : inr R A B x = (0, x) := rfl end InlInr end NonUnitalStarAlgHom namespace StarAlgHom variable (R A B C : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] [Semiring C] [Algebra R C] [Star C] /-- The first projection of a product is a ⋆-algebra homomorphism. -/ @[simps!] def fst : A × B →⋆ₐ[R] A := { AlgHom.fst R A B with map_star' := fun _ => rfl } /-- The second projection of a product is a ⋆-algebra homomorphism. -/ @[simps!] def snd : A × B →⋆ₐ[R] B := { AlgHom.snd R A B with map_star' := fun _ => rfl } variable {R A B C} /-- The `Pi.prod` of two morphisms is a morphism. -/ @[simps!] def prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : A →⋆ₐ[R] B × C := { f.toAlgHom.prod g.toAlgHom with map_star' := fun x => by simp [Prod.star_def, map_star] } theorem coe_prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : (fst R B C).comp (prod f g) = f := by ext; rfl @[simp] theorem snd_prod (f : A →⋆ₐ[R] B) (g : A →⋆ₐ[R] C) : (snd R B C).comp (prod f g) = g := by ext; rfl @[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = 1 := DFunLike.coe_injective Pi.prod_fst_snd /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. -/ @[simps] def prodEquiv : (A →⋆ₐ[R] B) × (A →⋆ₐ[R] C) ≃ (A →⋆ₐ[R] B × C) where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) left_inv f := by ext <;> rfl right_inv f := by ext <;> rfl end StarAlgHom /-! ### Star algebra equivalences -/ -- Porting note: changed order of arguments to work around -- [https://github.com/leanprover-community/mathlib4/issues/2505] /-- A *⋆-algebra* equivalence is an equivalence preserving addition, multiplication, scalar multiplication and the star operation, which allows for considering both unital and non-unital equivalences with a single structure. Currently, `AlgEquiv` requires unital algebras, which is why this structure does not extend it. -/ structure StarAlgEquiv (R A B : Type*) [Add A] [Add B] [Mul A] [Mul B] [SMul R A] [SMul R B] [Star A] [Star B] extends A ≃+* B where /-- By definition, a ⋆-algebra equivalence preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) /-- By definition, a ⋆-algebra equivalence commutes with the action of scalars. -/ map_smul' : ∀ (r : R) (a : A), toFun (r • a) = r • toFun a @[inherit_doc StarAlgEquiv] infixr:25 " ≃⋆ₐ " => StarAlgEquiv _ @[inherit_doc] notation:25 A " ≃⋆ₐ[" R "] " B => StarAlgEquiv R A B /-- Reinterpret a star algebra equivalence as a `RingEquiv` by forgetting the interaction with the star operation and scalar multiplication. -/ add_decl_doc StarAlgEquiv.toRingEquiv /-- The class that directly extends `RingEquivClass` and `SMulHomClass`. Mostly an implementation detail for `StarAlgEquivClass`. -/ class NonUnitalAlgEquivClass (F : Type*) (R A B : outParam Type*) [Add A] [Mul A] [SMul R A] [Add B] [Mul B] [SMul R B] [EquivLike F A B] extends RingEquivClass F A B, MulActionSemiHomClass F (@id R) A B : Prop where /-- `StarAlgEquivClass F R A B` asserts `F` is a type of bundled ⋆-algebra equivalences between `A` and `B`. You should also extend this typeclass when you extend `StarAlgEquiv`. -/ class StarAlgEquivClass (F : Type*) (R A B : outParam Type*) [Add A] [Mul A] [SMul R A] [Star A] [Add B] [Mul B] [SMul R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] : Prop where /-- By definition, a ⋆-algebra equivalence preserves the `star` operation. -/ map_star : ∀ (f : F) (a : A), f (star a) = star (f a) -- Porting note: no longer needed ---- `R` becomes a metavariable but that's fine because it's an `outParam` -- attribute [nolint dangerousInstance] StarAlgEquivClass.toRingEquivClass namespace StarAlgEquivClass -- See note [lower instance priority] instance (priority := 50) {F R A B : Type*} [Add A] [Mul A] [SMul R A] [Star A] [Add B] [Mul B] [SMul R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] [hF : StarAlgEquivClass F R A B] : StarHomClass F A B := { hF with } -- See note [lower instance priority] instance (priority := 100) {F R A B : Type*} [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] : NonUnitalAlgHomClass F R A B := { } -- See note [lower instance priority] instance (priority := 100) {F R A B : Type*} [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] [StarAlgEquivClass F R A B] : NonUnitalStarAlgHomClass F R A B := { } -- See note [lower instance priority] instance (priority := 100) instAlgHomClass (F R A B : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] : AlgEquivClass F R A B := { commutes := fun f r => by simp only [Algebra.algebraMap_eq_smul_one, map_smul, map_one] } -- See note [lower instance priority] instance (priority := 100) instStarAlgHomClass (F R A B : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [Star A] [Semiring B] [Algebra R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] [StarAlgEquivClass F R A B] : StarAlgHomClass F R A B := { } /-- Turn an element of a type `F` satisfying `StarAlgEquivClass F R A B` into an actual `StarAlgEquiv`. This is declared as the default coercion from `F` to `A ≃⋆ₐ[R] B`. -/ @[coe] def toStarAlgEquiv {F R A B : Type*} [Add A] [Mul A] [SMul R A] [Star A] [Add B] [Mul B] [SMul R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] [StarAlgEquivClass F R A B] (f : F) : A ≃⋆ₐ[R] B := { (f : A ≃+* B) with map_star' := map_star f map_smul' := map_smul f} /-- Any type satisfying `StarAlgEquivClass` can be cast into `StarAlgEquiv` via `StarAlgEquivClass.toStarAlgEquiv`. -/ instance instCoeHead {F R A B : Type*} [Add A] [Mul A] [SMul R A] [Star A] [Add B] [Mul B] [SMul R B] [Star B] [EquivLike F A B] [NonUnitalAlgEquivClass F R A B] [StarAlgEquivClass F R A B] : CoeHead F (A ≃⋆ₐ[R] B) := ⟨toStarAlgEquiv⟩ end StarAlgEquivClass namespace StarAlgEquiv section Basic variable {F R A B C : Type*} [Add A] [Add B] [Mul A] [Mul B] [SMul R A] [SMul R B] [Star A] [Star B] [Add C] [Mul C] [SMul R C] [Star C] instance : EquivLike (A ≃⋆ₐ[R] B) A B where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by rcases f with ⟨⟨⟨_, _, _⟩, _⟩, _⟩ rcases g with ⟨⟨⟨_, _, _⟩, _⟩, _⟩ congr instance : NonUnitalAlgEquivClass (A ≃⋆ₐ[R] B) R A B where map_mul f := f.map_mul' map_add f := f.map_add' map_smulₛₗ := map_smul' instance : StarAlgEquivClass (A ≃⋆ₐ[R] B) R A B where map_star := map_star' /-- Helper instance for cases where the inference via `EquivLike` is too hard. -/ instance : FunLike (A ≃⋆ₐ[R] B) A B where coe f := f.toFun coe_injective' := DFunLike.coe_injective @[simp] theorem toRingEquiv_eq_coe (e : A ≃⋆ₐ[R] B) : e.toRingEquiv = e := rfl @[ext] theorem ext {f g : A ≃⋆ₐ[R] B} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- The identity map is a star algebra isomorphism. -/ @[refl] def refl : A ≃⋆ₐ[R] A := { RingEquiv.refl A with map_smul' := fun _ _ => rfl map_star' := fun _ => rfl } instance : Inhabited (A ≃⋆ₐ[R] A) := ⟨refl⟩ @[simp] theorem coe_refl : ⇑(refl : A ≃⋆ₐ[R] A) = id := rfl -- Porting note: changed proof a bit by using `EquivLike` to avoid lots of coercions /-- The inverse of a star algebra isomorphism is a star algebra isomorphism. -/ @[symm] nonrec def symm (e : A ≃⋆ₐ[R] B) : B ≃⋆ₐ[R] A := { e.symm with map_star' := fun b => by simpa only [apply_inv_apply, inv_apply_apply] using congr_arg (inv e) (map_star e (inv e b)).symm map_smul' := fun r b => by simpa only [apply_inv_apply, inv_apply_apply] using congr_arg (inv e) (map_smul e r (inv e b)).symm } -- Porting note: in mathlib3 we didn't need the `Simps.apply` hint. /-- See Note [custom simps projection] -/ def Simps.apply (e : A ≃⋆ₐ[R] B) : A → B := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : A ≃⋆ₐ[R] B) : B → A := e.symm initialize_simps_projections StarAlgEquiv (toFun → apply, invFun → symm_apply) -- Porting note: use `EquivLike.inv` instead of `invFun` @[simp] theorem invFun_eq_symm {e : A ≃⋆ₐ[R] B} : EquivLike.inv e = e.symm := rfl @[simp] theorem symm_symm (e : A ≃⋆ₐ[R] B) : e.symm.symm = e := by ext rfl theorem symm_bijective : Function.Bijective (symm : (A ≃⋆ₐ[R] B) → B ≃⋆ₐ[R] A) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem coe_mk (e h₁ h₂) : ⇑(⟨e, h₁, h₂⟩ : A ≃⋆ₐ[R] B) = e := rfl @[simp] theorem mk_coe (e : A ≃⋆ₐ[R] B) (e' h₁ h₂ h₃ h₄ h₅ h₆) : (⟨⟨⟨e, e', h₁, h₂⟩, h₃, h₄⟩, h₅, h₆⟩ : A ≃⋆ₐ[R] B) = e := ext fun _ => rfl /-- Auxilliary definition to avoid looping in `dsimp` with `StarAlgEquiv.symm_mk`. -/ protected def symm_mk.aux (f f') (h₁ h₂ h₃ h₄ h₅ h₆) := (⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅, h₆⟩ : A ≃⋆ₐ[R] B).symm @[simp] theorem symm_mk (f f') (h₁ h₂ h₃ h₄ h₅ h₆) : (⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅, h₆⟩ : A ≃⋆ₐ[R] B).symm = { symm_mk.aux f f' h₁ h₂ h₃ h₄ h₅ h₆ with toFun := f' invFun := f } := rfl @[simp] theorem refl_symm : (StarAlgEquiv.refl : A ≃⋆ₐ[R] A).symm = StarAlgEquiv.refl := rfl -- should be a `simp` lemma, but causes a linter timeout theorem to_ringEquiv_symm (f : A ≃⋆ₐ[R] B) : (f : A ≃+* B).symm = f.symm := rfl @[simp] theorem symm_to_ringEquiv (e : A ≃⋆ₐ[R] B) : (e.symm : B ≃+* A) = (e : A ≃+* B).symm := rfl /-- Transitivity of `StarAlgEquiv`. -/ @[trans] def trans (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) : A ≃⋆ₐ[R] C := { e₁.toRingEquiv.trans e₂.toRingEquiv with map_smul' := fun r a => show e₂.toFun (e₁.toFun (r • a)) = r • e₂.toFun (e₁.toFun a) by rw [e₁.map_smul', e₂.map_smul'] map_star' := fun a => show e₂.toFun (e₁.toFun (star a)) = star (e₂.toFun (e₁.toFun a)) by rw [e₁.map_star', e₂.map_star'] } @[simp] theorem apply_symm_apply (e : A ≃⋆ₐ[R] B) : ∀ x, e (e.symm x) = x := e.toRingEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : A ≃⋆ₐ[R] B) : ∀ x, e.symm (e x) = x := e.toRingEquiv.symm_apply_apply @[simp] theorem symm_trans_apply (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) (x : C) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl @[simp] theorem coe_trans (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] theorem trans_apply (e₁ : A ≃⋆ₐ[R] B) (e₂ : B ≃⋆ₐ[R] C) (x : A) : (e₁.trans e₂) x = e₂ (e₁ x) := rfl theorem leftInverse_symm (e : A ≃⋆ₐ[R] B) : Function.LeftInverse e.symm e := e.left_inv theorem rightInverse_symm (e : A ≃⋆ₐ[R] B) : Function.RightInverse e.symm e := e.right_inv end Basic section Bijective variable {F G R A B : Type*} [Monoid R] variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [Star A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [Star B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B] variable [FunLike G B A] [NonUnitalAlgHomClass G R B A] [NonUnitalStarAlgHomClass G R B A] /-- If a (unital or non-unital) star algebra morphism has an inverse, it is an isomorphism of star algebras. -/ @[simps] def ofStarAlgHom (f : F) (g : G) (h₁ : ∀ x, g (f x) = x) (h₂ : ∀ x, f (g x) = x) : A ≃⋆ₐ[R] B where toFun := f invFun := g left_inv := h₁ right_inv := h₂ map_add' := map_add f map_mul' := map_mul f map_smul' := map_smul f map_star' := map_star f /-- Promote a bijective star algebra homomorphism to a star algebra equivalence. -/ noncomputable def ofBijective (f : F) (hf : Function.Bijective f) : A ≃⋆ₐ[R] B := { RingEquiv.ofBijective f (hf : Function.Bijective (f : A → B)) with toFun := f map_star' := map_star f map_smul' := map_smul f } @[simp] theorem coe_ofBijective {f : F} (hf : Function.Bijective f) : (StarAlgEquiv.ofBijective f hf : A → B) = f := rfl theorem ofBijective_apply {f : F} (hf : Function.Bijective f) (a : A) : (StarAlgEquiv.ofBijective f hf) a = f a := rfl end Bijective end StarAlgEquiv
Algebra\Star\StarRingHom.lean
/- Copyright (c) 2024 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Star.Basic /-! # Morphisms of star rings This file defines a new type of morphism between (non-unital) rings `A` and `B` where both `A` and `B` are equipped with a `star` operation. This morphism, namely `NonUnitalStarRingHom`, is a direct extension of its non-`star`red counterpart with a field `map_star` which guarantees it preserves the star operation. As with `NonUnitalRingHom`, the multiplications are not assumed to be associative or unital. ## Main definitions * `NonUnitalStarRingHom` ## Implementation This file is heavily inspired by `Mathlib.Algebra.Star.StarAlgHom`. ## Tags non-unital, ring, morphism, star -/ open EquivLike /-! ### Non-unital star ring homomorphisms -/ /-- A *non-unital ⋆-ring homomorphism* is a non-unital ring homomorphism between non-unital non-associative semirings `A` and `B` equipped with a `star` operation, and this homomorphism is also `star`-preserving. -/ structure NonUnitalStarRingHom (A B : Type*) [NonUnitalNonAssocSemiring A] [Star A] [NonUnitalNonAssocSemiring B] [Star B] extends A →ₙ+* B where /-- By definition, a non-unital ⋆-ring homomorphism preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) /-- `α →⋆ₙ+* β` denotes the type of non-unital ring homomorphisms from `α` to `β`. -/ infixr:25 " →⋆ₙ+* " => NonUnitalStarRingHom /-- Reinterpret a non-unital star ring homomorphism as a non-unital ring homomorphism by forgetting the interaction with the star operation. Users should not make use of this, but instead utilize the coercion obtained through the `NonUnitalRingHomClass` instance. -/ add_decl_doc NonUnitalStarRingHom.toNonUnitalRingHom /-- `NonUnitalStarRingHomClass F A B` states that `F` is a type of non-unital ⋆-ring homomorphisms. You should also extend this typeclass when you extend `NonUnitalStarRingHom`. -/ class NonUnitalStarRingHomClass (F : Type*) (A B : outParam Type*) [NonUnitalNonAssocSemiring A] [Star A] [NonUnitalNonAssocSemiring B] [Star B] [FunLike F A B] [NonUnitalRingHomClass F A B] extends StarHomClass F A B : Prop namespace NonUnitalStarRingHomClass variable {F A B : Type*} variable [NonUnitalNonAssocSemiring A] [Star A] variable [NonUnitalNonAssocSemiring B] [Star B] variable [FunLike F A B] [NonUnitalRingHomClass F A B] /-- Turn an element of a type `F` satisfying `NonUnitalStarRingHomClass F A B` into an actual `NonUnitalStarRingHom`. This is declared as the default coercion from `F` to `A →⋆ₙ+ B`. -/ @[coe] def toNonUnitalStarRingHom [NonUnitalStarRingHomClass F A B] (f : F) : A →⋆ₙ+* B := { (f : A →ₙ+* B) with map_star' := map_star f } instance [NonUnitalStarRingHomClass F A B] : CoeHead F (A →⋆ₙ+* B) := ⟨toNonUnitalStarRingHom⟩ end NonUnitalStarRingHomClass namespace NonUnitalStarRingHom section Basic variable {A B C D : Type*} variable [NonUnitalNonAssocSemiring A] [Star A] variable [NonUnitalNonAssocSemiring B] [Star B] variable [NonUnitalNonAssocSemiring C] [Star C] variable [NonUnitalNonAssocSemiring D] [Star D] instance : FunLike (A →⋆ₙ+* B) A B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h; congr instance : NonUnitalRingHomClass (A →⋆ₙ+* B) A B where map_mul f := f.map_mul' map_add f := f.map_add' map_zero f := f.map_zero' instance : NonUnitalStarRingHomClass (A →⋆ₙ+* B) A B where map_star f := f.map_star' /-- See Note [custom simps projection] -/ def Simps.apply (f : A →⋆ₙ+* B) : A → B := f initialize_simps_projections NonUnitalStarRingHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [NonUnitalRingHomClass F A B] [NonUnitalStarRingHomClass F A B] (f : F) : ⇑(f : A →⋆ₙ+* B) = f := rfl @[simp] theorem coe_toNonUnitalRingHom (f : A →⋆ₙ+* B) : ⇑f.toNonUnitalRingHom = f := rfl @[ext] theorem ext {f g : A →⋆ₙ+* B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Copy of a `NonUnitalStarRingHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : A →⋆ₙ+* B) (f' : A → B) (h : f' = f) : A →⋆ₙ+* B where toFun := f' map_zero' := h.symm ▸ map_zero f map_add' := h.symm ▸ map_add f map_mul' := h.symm ▸ map_mul f map_star' := h.symm ▸ map_star f @[simp] theorem coe_copy (f : A →⋆ₙ+* B) (f' : A → B) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : A →⋆ₙ+* B) (f' : A → B) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_mk (f : A →ₙ+* B) (h) : ((⟨f, h⟩ : A →⋆ₙ+* B) : A → B) = f := rfl @[simp] theorem mk_coe (f : A →⋆ₙ+* B) (h₁ h₂ h₃ h₄) : (⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →⋆ₙ+* B) = f := by ext rfl section variable (A) /-- The identity as a non-unital ⋆-ring homomorphism. -/ protected def id : A →⋆ₙ+* A := { (1 : A →ₙ+* A) with map_star' := fun _ => rfl } @[simp] theorem coe_id : ⇑(NonUnitalStarRingHom.id A) = id := rfl end /-- The composition of non-unital ⋆-ring homomorphisms, as a non-unital ⋆-ring homomorphism. -/ def comp (f : B →⋆ₙ+* C) (g : A →⋆ₙ+* B) : A →⋆ₙ+* C := { f.toNonUnitalRingHom.comp g.toNonUnitalRingHom with map_star' := fun a => by simp [Function.comp_def, map_star, map_star] } @[simp] theorem coe_comp (f : B →⋆ₙ+* C) (g : A →⋆ₙ+* B) : ⇑(comp f g) = f ∘ g := rfl @[simp] theorem comp_apply (f : B →⋆ₙ+* C) (g : A →⋆ₙ+* B) (a : A) : comp f g a = f (g a) := rfl @[simp] theorem comp_assoc (f : C →⋆ₙ+* D) (g : B →⋆ₙ+* C) (h : A →⋆ₙ+* B) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem id_comp (f : A →⋆ₙ+* B) : (NonUnitalStarRingHom.id _).comp f = f := ext fun _ => rfl @[simp] theorem comp_id (f : A →⋆ₙ+* B) : f.comp (NonUnitalStarRingHom.id _) = f := ext fun _ => rfl instance : Monoid (A →⋆ₙ+* A) where mul := comp mul_assoc := comp_assoc one := NonUnitalStarRingHom.id A one_mul := id_comp mul_one := comp_id @[simp] theorem coe_one : ((1 : A →⋆ₙ+* A) : A → A) = id := rfl theorem one_apply (a : A) : (1 : A →⋆ₙ+* A) a = a := rfl end Basic section Zero -- the `zero` requires extra type class assumptions because we need `star_zero` variable {A B C D : Type*} variable [NonUnitalNonAssocSemiring A] [StarAddMonoid A] variable [NonUnitalNonAssocSemiring B] [StarAddMonoid B] instance : Zero (A →⋆ₙ+* B) := ⟨{ (0 : NonUnitalRingHom A B) with map_star' := by simp }⟩ instance : Inhabited (A →⋆ₙ+* B) := ⟨0⟩ instance : MonoidWithZero (A →⋆ₙ+* A) where zero_mul := fun _ => ext fun _ => rfl mul_zero := fun f => ext fun _ => map_zero f @[simp] theorem coe_zero : ((0 : A →⋆ₙ+* B) : A → B) = 0 := rfl theorem zero_apply (a : A) : (0 : A →⋆ₙ+* B) a = 0 := rfl end Zero end NonUnitalStarRingHom /-! ### Star ring equivalences -/ /-- A *⋆-ring* equivalence is an equivalence preserving addition, multiplication, and the star operation, which allows for considering both unital and non-unital equivalences with a single structure. -/ structure StarRingEquiv (A B : Type*) [Add A] [Add B] [Mul A] [Mul B] [Star A] [Star B] extends A ≃+* B where /-- By definition, a ⋆-ring equivalence preserves the `star` operation. -/ map_star' : ∀ a : A, toFun (star a) = star (toFun a) @[inherit_doc] notation:25 A " ≃⋆+* " B => StarRingEquiv A B /-- Reinterpret a star ring equivalence as a `RingEquiv` by forgetting the interaction with the star operation. -/ add_decl_doc StarRingEquiv.toRingEquiv /-- `StarRingEquivClass F A B` asserts `F` is a type of bundled ⋆-ring equivalences between `A` and `B`. You should also extend this typeclass when you extend `StarRingEquiv`. -/ class StarRingEquivClass (F : Type*) (A B : outParam Type*) [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] extends RingEquivClass F A B : Prop where /-- By definition, a ⋆-ring equivalence preserves the `star` operation. -/ map_star : ∀ (f : F) (a : A), f (star a) = star (f a) namespace StarRingEquivClass -- See note [lower instance priority] instance (priority := 50) {F A B : Type*} [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] [hF : StarRingEquivClass F A B] : StarHomClass F A B := { hF with } -- See note [lower instance priority] instance (priority := 100) {F A B : Type*} [NonUnitalNonAssocSemiring A] [Star A] [NonUnitalNonAssocSemiring B] [Star B] [EquivLike F A B] [RingEquivClass F A B] [StarRingEquivClass F A B] : NonUnitalStarRingHomClass F A B := { } /-- Turn an element of a type `F` satisfying `StarRingEquivClass F A B` into an actual `StarRingEquiv`. This is declared as the default coercion from `F` to `A ≃⋆+* B`. -/ @[coe] def toStarRingEquiv {F A B : Type*} [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] [RingEquivClass F A B] [StarRingEquivClass F A B] (f : F) : A ≃⋆+* B := { (f : A ≃+* B) with map_star' := map_star f} /-- Any type satisfying `StarRingEquivClass` can be cast into `StarRingEquiv` via `StarRingEquivClass.toStarRingEquiv`. -/ instance instCoeHead {F A B : Type*} [Add A] [Mul A] [Star A] [Add B] [Mul B] [Star B] [EquivLike F A B] [RingEquivClass F A B] [StarRingEquivClass F A B] : CoeHead F (A ≃⋆+* B) := ⟨toStarRingEquiv⟩ end StarRingEquivClass namespace StarRingEquiv section Basic variable {A B C : Type*} [Add A] [Add B] [Mul A] [Mul B] [Star A] [Star B] [Add C] [Mul C] [Star C] instance : EquivLike (A ≃⋆+* B) A B where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by rcases f with ⟨⟨⟨_, _, _⟩, _⟩, _⟩ rcases g with ⟨⟨⟨_, _, _⟩, _⟩, _⟩ congr instance : RingEquivClass (A ≃⋆+* B) A B where map_mul f := f.map_mul' map_add f := f.map_add' instance : StarRingEquivClass (A ≃⋆+* B) A B where map_star := map_star' /-- Helper instance for cases where the inference via `EquivLike` is too hard. -/ instance : FunLike (A ≃⋆+* B) A B where coe f := f.toFun coe_injective' := DFunLike.coe_injective @[simp] theorem toRingEquiv_eq_coe (e : A ≃⋆+* B) : e.toRingEquiv = e := rfl @[ext] theorem ext {f g : A ≃⋆+* B} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- The identity map as a star ring isomorphism. -/ @[refl] def refl : A ≃⋆+* A := { RingEquiv.refl A with map_star' := fun _ => rfl } instance : Inhabited (A ≃⋆+* A) := ⟨refl⟩ @[simp] theorem coe_refl : ⇑(refl : A ≃⋆+* A) = id := rfl /-- The inverse of a star ring isomorphism is a star ring isomorphism. -/ @[symm] nonrec def symm (e : A ≃⋆+* B) : B ≃⋆+* A := { e.symm with map_star' := fun b => by simpa only [apply_inv_apply, inv_apply_apply] using congr_arg (inv e) (map_star e (inv e b)).symm } /-- See Note [custom simps projection] -/ def Simps.apply (e : A ≃⋆+* B) : A → B := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : A ≃⋆+* B) : B → A := e.symm initialize_simps_projections StarRingEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem invFun_eq_symm {e : A ≃⋆+* B} : EquivLike.inv e = e.symm := rfl @[simp] theorem symm_symm (e : A ≃⋆+* B) : e.symm.symm = e := by ext rfl theorem symm_bijective : Function.Bijective (symm : (A ≃⋆+* B) → B ≃⋆+* A) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem coe_mk (e h₁) : ⇑(⟨e, h₁⟩ : A ≃⋆+* B) = e := rfl @[simp] theorem mk_coe (e : A ≃⋆+* B) (e' h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨e, e', h₁, h₂⟩, h₃, h₄⟩, h₅⟩ : A ≃⋆+* B) = e := ext fun _ => rfl /-- Auxilliary definition to avoid looping in `dsimp` with `StarRingEquiv.symm_mk`. -/ protected def symm_mk.aux (f f') (h₁ h₂ h₃ h₄ h₅) := (⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅⟩ : A ≃⋆+* B).symm @[simp] theorem symm_mk (f f') (h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨f, f', h₁, h₂⟩, h₃, h₄⟩, h₅⟩ : A ≃⋆+* B).symm = { symm_mk.aux f f' h₁ h₂ h₃ h₄ h₅ with toFun := f' invFun := f } := rfl @[simp] theorem refl_symm : (StarRingEquiv.refl : A ≃⋆+* A).symm = StarRingEquiv.refl := rfl /-- Transitivity of `StarRingEquiv`. -/ @[trans] def trans (e₁ : A≃⋆+* B) (e₂ : B ≃⋆+* C) : A ≃⋆+* C := { e₁.toRingEquiv.trans e₂.toRingEquiv with map_star' := fun a => show e₂.toFun (e₁.toFun (star a)) = star (e₂.toFun (e₁.toFun a)) by rw [e₁.map_star', e₂.map_star'] } @[simp] theorem apply_symm_apply (e : A ≃⋆+* B) : ∀ x, e (e.symm x) = x := e.toRingEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : A ≃⋆+* B) : ∀ x, e.symm (e x) = x := e.toRingEquiv.symm_apply_apply @[simp] theorem symm_trans_apply (e₁ : A ≃⋆+* B) (e₂ : B≃⋆+* C) (x : C) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl @[simp] theorem coe_trans (e₁ : A ≃⋆+* B) (e₂ : B ≃⋆+* C) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] theorem trans_apply (e₁ : A ≃⋆+* B) (e₂ : B ≃⋆+* C) (x : A) : (e₁.trans e₂) x = e₂ (e₁ x) := rfl theorem leftInverse_symm (e : A ≃⋆+* B) : Function.LeftInverse e.symm e := e.left_inv theorem rightInverse_symm (e : A ≃⋆+* B) : Function.RightInverse e.symm e := e.right_inv end Basic section Bijective variable {F G A B : Type*} variable [NonUnitalNonAssocSemiring A] [Star A] variable [NonUnitalNonAssocSemiring B] [Star B] variable [FunLike F A B] [NonUnitalRingHomClass F A B] [NonUnitalStarRingHomClass F A B] variable [FunLike G B A] [NonUnitalRingHomClass G B A] [NonUnitalStarRingHomClass G B A] /-- If a (unital or non-unital) star ring morphism has an inverse, it is an isomorphism of star rings. -/ @[simps] def ofStarRingHom (f : F) (g : G) (h₁ : ∀ x, g (f x) = x) (h₂ : ∀ x, f (g x) = x) : A ≃⋆+* B where toFun := f invFun := g left_inv := h₁ right_inv := h₂ map_add' := map_add f map_mul' := map_mul f map_star' := map_star f /-- Promote a bijective star ring homomorphism to a star ring equivalence. -/ noncomputable def ofBijective (f : F) (hf : Function.Bijective f) : A ≃⋆+* B := { RingEquiv.ofBijective f (hf : Function.Bijective (f : A → B)) with toFun := f map_star' := map_star f } @[simp] theorem coe_ofBijective {f : F} (hf : Function.Bijective f) : (StarRingEquiv.ofBijective f hf : A → B) = f := rfl theorem ofBijective_apply {f : F} (hf : Function.Bijective f) (a : A) : (StarRingEquiv.ofBijective f hf) a = f a := rfl end Bijective end StarRingEquiv
Algebra\Star\Subalgebra.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Jireh Loreaux -/ import Mathlib.Algebra.Star.Center import Mathlib.Algebra.Star.StarAlgHom import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.Star.Pointwise import Mathlib.Algebra.Star.Module import Mathlib.RingTheory.Adjoin.Basic /-! # Star subalgebras A *-subalgebra is a subalgebra of a *-algebra which is closed under *. The centralizer of a *-closed set is a *-subalgebra. -/ universe u v /-- A *-subalgebra is a subalgebra of a *-algebra which is closed under *. -/ structure StarSubalgebra (R : Type u) (A : Type v) [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] extends Subalgebra R A : Type v where /-- The `carrier` is closed under the `star` operation. -/ star_mem' {a} : a ∈ carrier → star a ∈ carrier namespace StarSubalgebra /-- Forgetting that a *-subalgebra is closed under *. -/ add_decl_doc StarSubalgebra.toSubalgebra variable {F R A B C : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] variable [Semiring B] [StarRing B] [Algebra R B] [StarModule R B] variable [Semiring C] [StarRing C] [Algebra R C] [StarModule R C] instance setLike : SetLike (StarSubalgebra R A) A where coe S := S.carrier coe_injective' p q h := by obtain ⟨⟨⟨⟨⟨_, _⟩, _⟩, _⟩, _⟩, _⟩ := p; cases q; congr instance starMemClass : StarMemClass (StarSubalgebra R A) A where star_mem {s} := s.star_mem' instance subsemiringClass : SubsemiringClass (StarSubalgebra R A) A where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' one_mem {s} := s.one_mem' zero_mem {s} := s.zero_mem' instance smulMemClass : SMulMemClass (StarSubalgebra R A) R A where smul_mem {s} r a (ha : a ∈ s.toSubalgebra) := (SMulMemClass.smul_mem r ha : r • a ∈ s.toSubalgebra) instance subringClass {R A} [CommRing R] [StarRing R] [Ring A] [StarRing A] [Algebra R A] [StarModule R A] : SubringClass (StarSubalgebra R A) A where neg_mem {s a} ha := show -a ∈ s.toSubalgebra from neg_mem ha -- this uses the `Star` instance `s` inherits from `StarMemClass (StarSubalgebra R A) A` instance starRing (s : StarSubalgebra R A) : StarRing s := { StarMemClass.instStar s with star_involutive := fun r => Subtype.ext (star_star (r : A)) star_mul := fun r₁ r₂ => Subtype.ext (star_mul (r₁ : A) (r₂ : A)) star_add := fun r₁ r₂ => Subtype.ext (star_add (r₁ : A) (r₂ : A)) } instance algebra (s : StarSubalgebra R A) : Algebra R s := s.toSubalgebra.algebra' instance starModule (s : StarSubalgebra R A) : StarModule R s where star_smul r a := Subtype.ext (star_smul r (a : A)) @[simp, nolint simpNF] -- porting note (#10618): `simpNF` says `simp` can prove this, but it can't theorem mem_carrier {s : StarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : StarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] lemma coe_mk (S : Subalgebra R A) (h) : ((⟨S, h⟩ : StarSubalgebra R A) : Set A) = S := rfl @[simp] theorem mem_toSubalgebra {S : StarSubalgebra R A} {x} : x ∈ S.toSubalgebra ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubalgebra (S : StarSubalgebra R A) : (S.toSubalgebra : Set A) = S := rfl theorem toSubalgebra_injective : Function.Injective (toSubalgebra : StarSubalgebra R A → Subalgebra R A) := fun S T h => ext fun x => by rw [← mem_toSubalgebra, ← mem_toSubalgebra, h] theorem toSubalgebra_inj {S U : StarSubalgebra R A} : S.toSubalgebra = U.toSubalgebra ↔ S = U := toSubalgebra_injective.eq_iff theorem toSubalgebra_le_iff {S₁ S₂ : StarSubalgebra R A} : S₁.toSubalgebra ≤ S₂.toSubalgebra ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : StarSubalgebra R A where toSubalgebra := Subalgebra.copy S.toSubalgebra s hs star_mem' := @fun a ha => hs ▸ (S.star_mem' (by simpa [hs] using ha) : star a ∈ (S : Set A)) -- Porting note: the old proof kept crashing Lean @[simp] theorem coe_copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s := rfl theorem copy_eq (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : StarSubalgebra R A) theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S := S.algebraMap_mem' r theorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubalgebra.toSubsemiring := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_le : Set.range (algebraMap R A) ≤ S := S.range_subset protected theorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem r) hx /-- Embedding of a subalgebra into the algebra. -/ def subtype : S →⋆ₐ[R] A where toFun := ((↑) : S → A) map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl @[simp] theorem coe_subtype : (S.subtype : S → A) = Subtype.val := rfl theorem subtype_apply (x : S) : S.subtype x = (x : A) := rfl @[simp] theorem toSubalgebra_subtype : S.toSubalgebra.val = S.subtype.toAlgHom := rfl /-- The inclusion map between `StarSubalgebra`s given by `Subtype.map id` as a `StarAlgHom`. -/ @[simps] def inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₁ →⋆ₐ[R] S₂ where toFun := Subtype.map id h map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl theorem inclusion_injective {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : Function.Injective <| inclusion h := Set.inclusion_injective h @[simp] theorem subtype_comp_inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₂.subtype.comp (inclusion h) = S₁.subtype := rfl section Map /-- Transport a star subalgebra via a star algebra homomorphism. -/ def map (f : A →⋆ₐ[R] B) (S : StarSubalgebra R A) : StarSubalgebra R B := { S.toSubalgebra.map f.toAlgHom with star_mem' := by rintro _ ⟨a, ha, rfl⟩ exact map_star f a ▸ Set.mem_image_of_mem _ (S.star_mem' ha) } theorem map_mono {S₁ S₂ : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f := Set.image_subset f theorem map_injective {f : A →⋆ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : StarSubalgebra R A) : S.map (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : StarSubalgebra R A) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := Subsemiring.mem_map theorem map_toSubalgebra {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : (S.map f).toSubalgebra = S.toSubalgebra.map f.toAlgHom := SetLike.coe_injective rfl @[simp] theorem coe_map (S : StarSubalgebra R A) (f : A →⋆ₐ[R] B) : (S.map f : Set B) = f '' S := rfl /-- Preimage of a star subalgebra under a star algebra homomorphism. -/ def comap (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) : StarSubalgebra R A := { S.toSubalgebra.comap f.toAlgHom with star_mem' := @fun a ha => show f (star a) ∈ S from (map_star f a).symm ▸ star_mem ha } theorem map_le_iff_le_comap {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {U : StarSubalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : A →⋆ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le_iff_le_comap theorem comap_mono {S₁ S₂ : StarSubalgebra R B} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.comap f ≤ S₂.comap f := Set.preimage_mono theorem comap_injective {f : A →⋆ₐ[R] B} (hf : Function.Surjective f) : Function.Injective (comap f) := fun _S₁ _S₂ h => ext fun b => let ⟨x, hx⟩ := hf b let this := SetLike.ext_iff.1 h x hx ▸ this @[simp] theorem comap_id (S : StarSubalgebra R A) : S.comap (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.preimage_id theorem comap_comap (S : StarSubalgebra R C) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.comap g).comap f = S.comap (g.comp f) := SetLike.coe_injective <| by exact Set.preimage_preimage -- Porting note: the `by exact` trick still works sometimes @[simp] theorem mem_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl @[simp, norm_cast] theorem coe_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) := rfl end Map section Centralizer variable (R) /-- The centralizer, or commutant, of the star-closure of a set as a star subalgebra. -/ def centralizer (s : Set A) : StarSubalgebra R A where toSubalgebra := Subalgebra.centralizer R (s ∪ star s) star_mem' := Set.star_mem_centralizer @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = (s ∪ star s).centralizer := rfl theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g := by show (∀ g ∈ s ∪ star s, g * z = z * g) ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g simp only [Set.mem_union, or_imp, forall_and, and_congr_right_iff] exact fun _ => ⟨fun hz a ha => hz _ (Set.star_mem_star.mpr ha), fun hz a ha => star_star a ▸ hz _ ha⟩ theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset (Set.union_subset_union h <| Set.preimage_mono h) end Centralizer end StarSubalgebra /-! ### The star closure of a subalgebra -/ namespace Subalgebra open Pointwise variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] /-- The pointwise `star` of a subalgebra is a subalgebra. -/ instance involutiveStar : InvolutiveStar (Subalgebra R A) where star S := { carrier := star S.carrier mul_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_mul x y).symm ▸ mul_mem hy hx one_mem' := Set.mem_star.mp ((star_one A).symm ▸ one_mem S : star (1 : A) ∈ S) add_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_add x y).symm ▸ add_mem hx hy zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S) algebraMap_mem' := fun r => by simpa only [Set.mem_star, Subalgebra.mem_carrier, ← algebraMap_star_comm] using S.algebraMap_mem (star r) } star_involutive S := Subalgebra.ext fun x => ⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩ @[simp] theorem mem_star_iff (S : Subalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S := Iff.rfl -- Porting note: removed `@[simp]` tag because `simp` can prove this theorem star_mem_star_iff (S : Subalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by simp only [mem_star_iff, star_star] @[simp] theorem coe_star (S : Subalgebra R A) : ((star S : Subalgebra R A) : Set A) = star (S : Set A) := rfl theorem star_mono : Monotone (star : Subalgebra R A → Subalgebra R A) := fun _ _ h _ hx => h hx variable (R) /-- The star operation on `Subalgebra` commutes with `Algebra.adjoin`. -/ theorem star_adjoin_comm (s : Set A) : star (Algebra.adjoin R s) = Algebra.adjoin R (star s) := have this : ∀ t : Set A, Algebra.adjoin R (star t) ≤ star (Algebra.adjoin R t) := fun t => Algebra.adjoin_le fun x hx => Algebra.subset_adjoin hx le_antisymm (by simpa only [star_star] using Subalgebra.star_mono (this (star s))) (this s) variable {R} /-- The `StarSubalgebra` obtained from `S : Subalgebra R A` by taking the smallest subalgebra containing both `S` and `star S`. -/ @[simps!] def starClosure (S : Subalgebra R A) : StarSubalgebra R A where toSubalgebra := S ⊔ star S star_mem' := fun {a} ha => by simp only [Subalgebra.mem_carrier, ← (@Algebra.gi R A _ _ _).l_sup_u _ _] at * rw [← mem_star_iff _ a, star_adjoin_comm, sup_comm] simpa using ha theorem starClosure_toSubalgebra (S : Subalgebra R A) : S.starClosure.toSubalgebra = S ⊔ star S := rfl theorem starClosure_le {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂.toSubalgebra) : S₁.starClosure ≤ S₂ := StarSubalgebra.toSubalgebra_le_iff.1 <| sup_le h fun x hx => (star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂) theorem starClosure_le_iff {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} : S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toSubalgebra := ⟨fun h => le_sup_left.trans h, starClosure_le⟩ end Subalgebra /-! ### The star subalgebra generated by a set -/ namespace StarAlgebra open StarSubalgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] variable (R) /-- The minimal star subalgebra that contains `s`. -/ @[simps!] def adjoin (s : Set A) : StarSubalgebra R A := { Algebra.adjoin R (s ∪ star s) with star_mem' := fun hx => by rwa [Subalgebra.mem_carrier, ← Subalgebra.mem_star_iff, Subalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm] } theorem adjoin_eq_starClosure_adjoin (s : Set A) : adjoin R s = (Algebra.adjoin R s).starClosure := toSubalgebra_injective <| show Algebra.adjoin R (s ∪ star s) = Algebra.adjoin R s ⊔ star (Algebra.adjoin R s) from (Subalgebra.star_adjoin_comm R s).symm ▸ Algebra.adjoin_union s (star s) theorem adjoin_toSubalgebra (s : Set A) : (adjoin R s).toSubalgebra = Algebra.adjoin R (s ∪ star s) := rfl @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s := Set.subset_union_left.trans Algebra.subset_adjoin theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s := Set.subset_union_right.trans Algebra.subset_adjoin theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := Algebra.subset_adjoin <| Set.mem_union_left _ (Set.mem_singleton x) theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) := star_mem <| self_mem_adjoin_singleton R x variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → StarSubalgebra R A) (↑) := by intro s S rw [← toSubalgebra_le_iff, adjoin_toSubalgebra, Algebra.adjoin_le_iff, coe_toSubalgebra] exact ⟨fun h => Set.subset_union_left.trans h, fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩ /-- Galois insertion between `adjoin` and `coe`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → StarSubalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (StarAlgebra.gc.le_u_l s) hs gc := StarAlgebra.gc le_l_u S := (StarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := StarSubalgebra.copy_eq _ _ _ theorem adjoin_le {S : StarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S := StarAlgebra.gc.l_le hs theorem adjoin_le_iff {S : StarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S := StarAlgebra.gc _ _ lemma adjoin_eq (S : StarSubalgebra R A) : adjoin R (S : Set A) = S := le_antisymm (adjoin_le le_rfl) (subset_adjoin R (S : Set A)) open Submodule in lemma adjoin_eq_span (s : Set A) : Subalgebra.toSubmodule (adjoin R s).toSubalgebra = span R (Submonoid.closure (s ∪ star s)) := by rw [adjoin_toSubalgebra, Algebra.adjoin_eq_span] theorem _root_.Subalgebra.starClosure_eq_adjoin (S : Subalgebra R A) : S.starClosure = adjoin R (S : Set A) := le_antisymm (Subalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A)) (adjoin_le (le_sup_left : S ≤ S ⊔ star S)) /-- If some predicate holds for all `x ∈ (s : Set A)` and this predicate is closed under the `algebraMap`, addition, multiplication and star operations, then it holds for `a ∈ adjoin R s`. -/ @[elab_as_elim] theorem adjoin_induction {s : Set A} {p : A → Prop} {a : A} (h : a ∈ adjoin R s) (mem : ∀ x : A, x ∈ s → p x) (algebraMap : ∀ r : R, p (algebraMap R A r)) (add : ∀ x y : A, p x → p y → p (x + y)) (mul : ∀ x y : A, p x → p y → p (x * y)) (star : ∀ x : A, p x → p (star x)) : p a := Algebra.adjoin_induction h (fun x hx => hx.elim (fun hx => mem x hx) fun hx => star_star x ▸ star _ (mem _ hx)) algebraMap add mul @[elab_as_elim] theorem adjoin_induction₂ {s : Set A} {p : A → A → Prop} {a b : A} (ha : a ∈ adjoin R s) (hb : b ∈ adjoin R s) (Hs : ∀ x : A, x ∈ s → ∀ y : A, y ∈ s → p x y) (Halg : ∀ r₁ r₂ : R, p (algebraMap R A r₁) (algebraMap R A r₂)) (Halg_left : ∀ (r : R) (x : A), x ∈ s → p (algebraMap R A r) x) (Halg_right : ∀ (r : R) (x : A), x ∈ s → p x (algebraMap R A r)) (Hadd_left : ∀ x₁ x₂ y : A, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂ : A, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y : A, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂ : A, p x y₁ → p x y₂ → p x (y₁ * y₂)) (Hstar : ∀ x y : A, p x y → p (star x) (star y)) (Hstar_left : ∀ x y : A, p x y → p (star x) y) (Hstar_right : ∀ x y : A, p x y → p x (star y)) : p a b := by refine Algebra.adjoin_induction₂ ha hb (fun x hx y hy => ?_) Halg (fun r x hx => ?_) (fun r x hx => ?_) Hadd_left Hadd_right Hmul_left Hmul_right · cases' hx with hx hx <;> cases' hy with hy hy · exact Hs x hx y hy · exact star_star y ▸ Hstar_right _ _ (Hs _ hx _ hy) · exact star_star x ▸ Hstar_left _ _ (Hs _ hx _ hy) · exact star_star x ▸ star_star y ▸ Hstar _ _ (Hs _ hx _ hy) · cases' hx with hx hx · exact Halg_left _ _ hx · exact star_star x ▸ Hstar_right _ _ (Halg_left r _ hx) · cases' hx with hx hx · exact Halg_right _ _ hx · exact star_star x ▸ Hstar_left _ _ (Halg_right r _ hx) /-- The difference with `StarSubalgebra.adjoin_induction` is that this acts on the subtype. -/ @[elab_as_elim] theorem adjoin_induction' {s : Set A} {p : adjoin R s → Prop} (a : adjoin R s) (mem : ∀ (x) (h : x ∈ s), p ⟨x, subset_adjoin R s h⟩) (algebraMap : ∀ r, p (algebraMap R _ r)) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) (star : ∀ x, p x → p (star x)) : p a := Subtype.recOn a fun b hb => by refine Exists.elim ?_ fun (hb : b ∈ adjoin R s) (hc : p ⟨b, hb⟩) => hc refine adjoin_induction hb ?_ ?_ ?_ ?_ ?_ exacts [fun x hx => ⟨subset_adjoin R s hx, mem x hx⟩, fun r => ⟨StarSubalgebra.algebraMap_mem _ r, algebraMap r⟩, fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ hx hy⟩, fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨mul_mem hx' hy', mul _ _ hx hy⟩, fun x hx => Exists.elim hx fun hx' hx => ⟨star_mem hx', star _ hx⟩] variable (R) /-- If all elements of `s : Set A` commute pairwise and also commute pairwise with elements of `star s`, then `StarSubalgebra.adjoin R s` is commutative. See note [reducible non-instances]. -/ abbrev adjoinCommSemiringOfComm {s : Set A} (hcomm : ∀ a : A, a ∈ s → ∀ b : A, b ∈ s → a * b = b * a) (hcomm_star : ∀ a : A, a ∈ s → ∀ b : A, b ∈ s → a * star b = star b * a) : CommSemiring (adjoin R s) := { (adjoin R s).toSubalgebra.toSemiring with mul_comm := by rintro ⟨x, hx⟩ ⟨y, hy⟩ ext simp only [MulMemClass.mk_mul_mk] rw [← mem_toSubalgebra, adjoin_toSubalgebra] at hx hy letI : CommSemiring (Algebra.adjoin R (s ∪ star s)) := Algebra.adjoinCommSemiringOfComm R (by intro a ha b hb cases' ha with ha ha <;> cases' hb with hb hb · exact hcomm _ ha _ hb · exact star_star b ▸ hcomm_star _ ha _ hb · exact star_star a ▸ (hcomm_star _ hb _ ha).symm · simpa only [star_mul, star_star] using congr_arg star (hcomm _ hb _ ha)) exact congr_arg Subtype.val (mul_comm (⟨x, hx⟩ : Algebra.adjoin R (s ∪ star s)) ⟨y, hy⟩) } /-- If all elements of `s : Set A` commute pairwise and also commute pairwise with elements of `star s`, then `StarSubalgebra.adjoin R s` is commutative. See note [reducible non-instances]. -/ abbrev adjoinCommRingOfComm (R : Type u) {A : Type v} [CommRing R] [StarRing R] [Ring A] [Algebra R A] [StarRing A] [StarModule R A] {s : Set A} (hcomm : ∀ a : A, a ∈ s → ∀ b : A, b ∈ s → a * b = b * a) (hcomm_star : ∀ a : A, a ∈ s → ∀ b : A, b ∈ s → a * star b = star b * a) : CommRing (adjoin R s) := { StarAlgebra.adjoinCommSemiringOfComm R hcomm hcomm_star, (adjoin R s).toSubalgebra.toRing with } /-- The star subalgebra `StarSubalgebra.adjoin R {x}` generated by a single `x : A` is commutative if `x` is normal. -/ instance adjoinCommSemiringOfIsStarNormal (x : A) [IsStarNormal x] : CommSemiring (adjoin R ({x} : Set A)) := adjoinCommSemiringOfComm R (fun a ha b hb => by rw [Set.mem_singleton_iff] at ha hb rw [ha, hb]) fun a ha b hb => by rw [Set.mem_singleton_iff] at ha hb simpa only [ha, hb] using (star_comm_self' x).symm /-- The star subalgebra `StarSubalgebra.adjoin R {x}` generated by a single `x : A` is commutative if `x` is normal. -/ instance adjoinCommRingOfIsStarNormal (R : Type u) {A : Type v} [CommRing R] [StarRing R] [Ring A] [Algebra R A] [StarRing A] [StarModule R A] (x : A) [IsStarNormal x] : CommRing (adjoin R ({x} : Set A)) := { (adjoin R ({x} : Set A)).toSubalgebra.toRing with mul_comm := mul_comm } /-! ### Complete lattice structure -/ end StarAlgebra namespace StarSubalgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] instance completeLattice : CompleteLattice (StarSubalgebra R A) where __ := GaloisInsertion.liftCompleteLattice StarAlgebra.gi bot := { toSubalgebra := ⊥, star_mem' := fun ⟨r, hr⟩ => ⟨star r, hr ▸ algebraMap_star_comm _⟩ } bot_le S := (bot_le : ⊥ ≤ S.toSubalgebra) instance inhabited : Inhabited (StarSubalgebra R A) := ⟨⊤⟩ @[simp] theorem coe_top : (↑(⊤ : StarSubalgebra R A) : Set A) = Set.univ := rfl @[simp] theorem mem_top {x : A} : x ∈ (⊤ : StarSubalgebra R A) := Set.mem_univ x @[simp] theorem top_toSubalgebra : (⊤ : StarSubalgebra R A).toSubalgebra = ⊤ := by ext; simp -- Porting note: Lean can no longer prove this by `rfl`, it times out @[simp] theorem toSubalgebra_eq_top {S : StarSubalgebra R A} : S.toSubalgebra = ⊤ ↔ S = ⊤ := StarSubalgebra.toSubalgebra_injective.eq_iff' top_toSubalgebra theorem mem_sup_left {S T : StarSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := have : S ≤ S ⊔ T := le_sup_left; (this ·) -- Porting note: need `have` instead of `show` theorem mem_sup_right {S T : StarSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := have : T ≤ S ⊔ T := le_sup_right; (this ·) -- Porting note: need `have` instead of `show` theorem mul_mem_sup {S T : StarSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := mul_mem (mem_sup_left hx) (mem_sup_right hy) theorem map_sup (f : A →⋆ₐ[R] B) (S T : StarSubalgebra R A) : map f (S ⊔ T) = map f S ⊔ map f T := (StarSubalgebra.gc_map_comap f).l_sup @[simp, norm_cast] theorem coe_inf (S T : StarSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T := rfl @[simp] theorem mem_inf {S T : StarSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl @[simp] theorem inf_toSubalgebra (S T : StarSubalgebra R A) : (S ⊓ T).toSubalgebra = S.toSubalgebra ⊓ T.toSubalgebra := by ext; simp -- Porting note: Lean can no longer prove this by `rfl`, it times out @[simp, norm_cast] theorem coe_sInf (S : Set (StarSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s := sInf_image theorem mem_sInf {S : Set (StarSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂] @[simp] theorem sInf_toSubalgebra (S : Set (StarSubalgebra R A)) : (sInf S).toSubalgebra = sInf (StarSubalgebra.toSubalgebra '' S) := SetLike.coe_injective <| by simp @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → StarSubalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by simp [iInf] theorem mem_iInf {ι : Sort*} {S : ι → StarSubalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp] theorem iInf_toSubalgebra {ι : Sort*} (S : ι → StarSubalgebra R A) : (⨅ i, S i).toSubalgebra = ⨅ i, (S i).toSubalgebra := SetLike.coe_injective <| by simp theorem bot_toSubalgebra : (⊥ : StarSubalgebra R A).toSubalgebra = ⊥ := rfl theorem mem_bot {x : A} : x ∈ (⊥ : StarSubalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl @[simp] theorem coe_bot : ((⊥ : StarSubalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl theorem eq_top_iff {S : StarSubalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S := ⟨fun h x => by rw [h]; exact mem_top, fun h => by ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩ end StarSubalgebra namespace StarAlgHom open StarSubalgebra StarAlgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] variable [Semiring B] [Algebra R B] [StarRing B] section variable [StarModule R A] theorem ext_adjoin {s : Set A} [FunLike F (adjoin R s) B] [AlgHomClass F R (adjoin R s) B] [StarAlgHomClass F R (adjoin R s) B] {f g : F} (h : ∀ x : adjoin R s, (x : A) ∈ s → f x = g x) : f = g := by refine DFunLike.ext f g fun a => adjoin_induction' (p := fun y => f y = g y) a (fun x hx => ?_) (fun r => ?_) (fun x y hx hy => ?_) (fun x y hx hy => ?_) fun x hx => ?_ · exact h ⟨x, subset_adjoin R s hx⟩ hx · simp only [AlgHomClass.commutes] · simp only [map_add, map_add, hx, hy] · simp only [map_mul, map_mul, hx, hy] · simp only [map_star, hx] theorem ext_adjoin_singleton {a : A} [FunLike F (adjoin R ({a} : Set A)) B] [AlgHomClass F R (adjoin R ({a} : Set A)) B] [StarAlgHomClass F R (adjoin R ({a} : Set A)) B] {f g : F} (h : f ⟨a, self_mem_adjoin_singleton R a⟩ = g ⟨a, self_mem_adjoin_singleton R a⟩) : f = g := ext_adjoin fun x hx => (show x = ⟨a, self_mem_adjoin_singleton R a⟩ from Subtype.ext <| Set.mem_singleton_iff.mp hx).symm ▸ h variable [FunLike F A B] [AlgHomClass F R A B] [StarAlgHomClass F R A B] (f g : F) /-- The equalizer of two star `R`-algebra homomorphisms. -/ def equalizer : StarSubalgebra R A := { toSubalgebra := AlgHom.equalizer (f : A →ₐ[R] B) g star_mem' := @fun a (ha : f a = g a) => by simpa only [← map_star] using congrArg star ha } -- Porting note: much like `StarSubalgebra.copy` the old proof was broken and hard to fix @[simp] theorem mem_equalizer (x : A) : x ∈ StarAlgHom.equalizer f g ↔ f x = g x := Iff.rfl theorem adjoin_le_equalizer {s : Set A} (h : s.EqOn f g) : adjoin R s ≤ StarAlgHom.equalizer f g := adjoin_le h theorem ext_of_adjoin_eq_top {s : Set A} (h : adjoin R s = ⊤) ⦃f g : F⦄ (hs : s.EqOn f g) : f = g := DFunLike.ext f g fun _x => StarAlgHom.adjoin_le_equalizer f g hs <| h.symm ▸ trivial variable [StarModule R B] theorem map_adjoin (f : A →⋆ₐ[R] B) (s : Set A) : map f (adjoin R s) = adjoin R (f '' s) := GaloisConnection.l_comm_of_u_comm Set.image_preimage (gc_map_comap f) StarAlgebra.gc StarAlgebra.gc fun _ => rfl /-- Range of a `StarAlgHom` as a star subalgebra. -/ protected def range (φ : A →⋆ₐ[R] B) : StarSubalgebra R B where toSubalgebra := φ.toAlgHom.range star_mem' := by rintro _ ⟨b, rfl⟩; exact ⟨star b, map_star φ b⟩ theorem range_eq_map_top (φ : A →⋆ₐ[R] B) : φ.range = (⊤ : StarSubalgebra R A).map φ := StarSubalgebra.ext fun x => ⟨by rintro ⟨a, ha⟩; exact ⟨a, by simp, ha⟩, by rintro ⟨a, -, ha⟩; exact ⟨a, ha⟩⟩ end variable [StarModule R B] /-- Restriction of the codomain of a `StarAlgHom` to a star subalgebra containing the range. -/ protected def codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →⋆ₐ[R] S where toAlgHom := AlgHom.codRestrict f.toAlgHom S.toSubalgebra hf map_star' := fun x => Subtype.ext (map_star f x) @[simp] theorem coe_codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) : ↑(f.codRestrict S hf x) = f x := rfl @[simp] theorem subtype_comp_codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : S.subtype.comp (f.codRestrict S hf) = f := StarAlgHom.ext <| coe_codRestrict _ S hf theorem injective_codRestrict (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : Function.Injective (StarAlgHom.codRestrict f S hf) ↔ Function.Injective f := ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩ /-- Restriction of the codomain of a `StarAlgHom` to its range. -/ def rangeRestrict (f : A →⋆ₐ[R] B) : A →⋆ₐ[R] f.range := StarAlgHom.codRestrict f _ fun x => ⟨x, rfl⟩ /-- The `StarAlgEquiv` onto the range corresponding to an injective `StarAlgHom`. -/ @[simps] noncomputable def _root_.StarAlgEquiv.ofInjective (f : A →⋆ₐ[R] B) (hf : Function.Injective f) : A ≃⋆ₐ[R] f.range := { AlgEquiv.ofInjective (f : A →ₐ[R] B) hf with toFun := f.rangeRestrict map_star' := fun a => Subtype.ext (map_star f a) map_smul' := fun r a => Subtype.ext (map_smul f r a) } end StarAlgHom section RestrictScalars variable (R : Type*) {S A B : Type*} [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] [Algebra R S] [Algebra S A] [Algebra S B] [Algebra R A] [Algebra R B] [IsScalarTower R S A] [IsScalarTower R S B] [Star A] [Star B] @[simps!] def StarAlgHom.restrictScalars (f : A →⋆ₐ[S] B) : A →⋆ₐ[R] B where toAlgHom := f.toAlgHom.restrictScalars R map_star' := map_star f theorem StarAlgHom.restrictScalars_injective : Function.Injective (StarAlgHom.restrictScalars R : (A →⋆ₐ[S] B) → A →⋆ₐ[R] B) := fun f g h => StarAlgHom.ext fun x => show f.restrictScalars R x = g.restrictScalars R x from DFunLike.congr_fun h x @[simps] def StarAlgEquiv.restrictScalars (f : A ≃⋆ₐ[S] B) : A ≃⋆ₐ[R] B := { (f : A →⋆ₐ[S] B).restrictScalars R, f with toFun := f map_smul' := map_smul ((f : A →⋆ₐ[S] B).restrictScalars R) } theorem StarAlgEquiv.restrictScalars_injective : Function.Injective (StarAlgEquiv.restrictScalars R : (A ≃⋆ₐ[S] B) → A ≃⋆ₐ[R] B) := fun f g h => StarAlgEquiv.ext fun x => show f.restrictScalars R x = g.restrictScalars R x from DFunLike.congr_fun h x end RestrictScalars
Algebra\Star\Subsemiring.lean
/- Copyright (c) 2024 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Algebra.Star.NonUnitalSubsemiring import Mathlib.Algebra.Ring.Subsemiring.Basic /-! # Star subrings A *-subring is a subring of a *-ring which is closed under *. -/ universe v /-- A (unital) star subsemiring is a non-associative ring which is closed under the `star` operation. -/ structure StarSubsemiring (R : Type v) [NonAssocSemiring R] [Star R] extends Subsemiring R : Type v where /-- The `carrier` of a `StarSubsemiring` is closed under the `star` operation. -/ star_mem' {a} : a ∈ carrier → star a ∈ carrier section StarSubsemiring namespace StarSubsemiring /-- Reinterpret a `StarSubsemiring` as a `Subsemiring`. -/ add_decl_doc StarSubsemiring.toSubsemiring variable {R : Type v} [NonAssocSemiring R] [StarRing R] instance setLike : SetLike (StarSubsemiring R) R where coe {s} := s.carrier coe_injective' p q h := by obtain ⟨⟨⟨⟨_, _⟩, _⟩, _⟩, _⟩ := p; cases q; congr instance starMemClass : StarMemClass (StarSubsemiring R) R where star_mem {s} := s.star_mem' instance subsemiringClass : SubsemiringClass (StarSubsemiring R) R where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' zero_mem {s} := s.zero_mem' one_mem {s} := s.one_mem' -- this uses the `Star` instance `s` inherits from `StarMemClass (StarSubsemiring R A) A` instance starRing (s : StarSubsemiring R) : StarRing s := { StarMemClass.instStar s with star_involutive := fun r => Subtype.ext (star_star (r : R)) star_mul := fun r₁ r₂ => Subtype.ext (star_mul (r₁ : R) (r₂ : R)) star_add := fun r₁ r₂ => Subtype.ext (star_add (r₁ : R) (r₂ : R)) } instance semiring (s : StarSubsemiring R) : NonAssocSemiring s := s.toSubsemiring.toNonAssocSemiring @[simp, nolint simpNF] theorem mem_carrier {s : StarSubsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : StarSubsemiring R} (h : ∀ x : R, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] lemma coe_mk (S : Subsemiring R) (h) : ((⟨S, h⟩ : StarSubsemiring R) : Set R) = S := rfl @[simp] theorem mem_toSubsemiring {S : StarSubsemiring R} {x} : x ∈ S.toSubsemiring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubsemiring (S : StarSubsemiring R) : (S.toSubsemiring : Set R) = S := rfl theorem toSubsemiring_injective : Function.Injective (toSubsemiring : StarSubsemiring R → Subsemiring R) := fun S T h => ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h] theorem toSubsemiring_inj {S U : StarSubsemiring R} : S.toSubsemiring = U.toSubsemiring ↔ S = U := toSubsemiring_injective.eq_iff theorem toSubsemiring_le_iff {S₁ S₂ : StarSubsemiring R} : S₁.toSubsemiring ≤ S₂.toSubsemiring ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a non-unital star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : StarSubsemiring R) (s : Set R) (hs : s = ↑S) : StarSubsemiring R where toSubsemiring := Subsemiring.copy S.toSubsemiring s hs star_mem' := @fun a ha => hs ▸ (S.star_mem' (by simpa [hs] using ha) : star a ∈ (S : Set R)) @[simp] theorem coe_copy (S : StarSubsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : StarSubsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs section Center variable (R) /-- The center of a semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center (R) [NonAssocSemiring R][StarRing R] : StarSubsemiring R where toSubsemiring := Subsemiring.center R star_mem' := Set.star_mem_center end Center end StarSubsemiring end StarSubsemiring section SubStarSemigroup variable (A) [Mul A] [StarMul A] namespace SubStarSemigroup /-- The center of magma `A` is the set of elements that commute and associate with everything in `A`, here realized as a `SubStarSemigroup`. -/ def center : SubStarSemigroup A := { Subsemigroup.center A with star_mem' := Set.star_mem_center } end SubStarSemigroup end SubStarSemigroup
Algebra\Star\Unitary.lean
/- Copyright (c) 2022 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shing Tak Lam, Frédéric Dupuis -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Algebra.Spectrum /-! # Unitary elements of a star monoid This file defines `unitary R`, where `R` is a star monoid, as the submonoid made of the elements that satisfy `star U * U = 1` and `U * star U = 1`, and these form a group. This includes, for instance, unitary operators on Hilbert spaces. See also `Matrix.UnitaryGroup` for specializations to `unitary (Matrix n n R)`. ## Tags unitary -/ /-- In a *-monoid, `unitary R` is the submonoid consisting of all the elements `U` of `R` such that `star U * U = 1` and `U * star U = 1`. -/ def unitary (R : Type*) [Monoid R] [StarMul R] : Submonoid R where carrier := { U | star U * U = 1 ∧ U * star U = 1 } one_mem' := by simp only [mul_one, and_self_iff, Set.mem_setOf_eq, star_one] mul_mem' := @fun U B ⟨hA₁, hA₂⟩ ⟨hB₁, hB₂⟩ => by refine ⟨?_, ?_⟩ · calc star (U * B) * (U * B) = star B * star U * U * B := by simp only [mul_assoc, star_mul] _ = star B * (star U * U) * B := by rw [← mul_assoc] _ = 1 := by rw [hA₁, mul_one, hB₁] · calc U * B * star (U * B) = U * B * (star B * star U) := by rw [star_mul] _ = U * (B * star B) * star U := by simp_rw [← mul_assoc] _ = 1 := by rw [hB₂, mul_one, hA₂] variable {R : Type*} namespace unitary section Monoid variable [Monoid R] [StarMul R] theorem mem_iff {U : R} : U ∈ unitary R ↔ star U * U = 1 ∧ U * star U = 1 := Iff.rfl @[simp] theorem star_mul_self_of_mem {U : R} (hU : U ∈ unitary R) : star U * U = 1 := hU.1 @[simp] theorem mul_star_self_of_mem {U : R} (hU : U ∈ unitary R) : U * star U = 1 := hU.2 theorem star_mem {U : R} (hU : U ∈ unitary R) : star U ∈ unitary R := ⟨by rw [star_star, mul_star_self_of_mem hU], by rw [star_star, star_mul_self_of_mem hU]⟩ @[simp] theorem star_mem_iff {U : R} : star U ∈ unitary R ↔ U ∈ unitary R := ⟨fun h => star_star U ▸ star_mem h, star_mem⟩ instance : Star (unitary R) := ⟨fun U => ⟨star U, star_mem U.prop⟩⟩ @[simp, norm_cast] theorem coe_star {U : unitary R} : ↑(star U) = (star U : R) := rfl theorem coe_star_mul_self (U : unitary R) : (star U : R) * U = 1 := star_mul_self_of_mem U.prop theorem coe_mul_star_self (U : unitary R) : (U : R) * star U = 1 := mul_star_self_of_mem U.prop @[simp] theorem star_mul_self (U : unitary R) : star U * U = 1 := Subtype.ext <| coe_star_mul_self U @[simp] theorem mul_star_self (U : unitary R) : U * star U = 1 := Subtype.ext <| coe_mul_star_self U instance : Group (unitary R) := { Submonoid.toMonoid _ with inv := star mul_left_inv := star_mul_self } instance : InvolutiveStar (unitary R) := ⟨by intro x ext rw [coe_star, coe_star, star_star]⟩ instance : StarMul (unitary R) := ⟨by intro x y ext rw [coe_star, Submonoid.coe_mul, Submonoid.coe_mul, coe_star, coe_star, star_mul]⟩ instance : Inhabited (unitary R) := ⟨1⟩ theorem star_eq_inv (U : unitary R) : star U = U⁻¹ := rfl theorem star_eq_inv' : (star : unitary R → unitary R) = Inv.inv := rfl /-- The unitary elements embed into the units. -/ @[simps] def toUnits : unitary R →* Rˣ where toFun x := ⟨x, ↑x⁻¹, coe_mul_star_self x, coe_star_mul_self x⟩ map_one' := Units.ext rfl map_mul' _ _ := Units.ext rfl theorem toUnits_injective : Function.Injective (toUnits : unitary R → Rˣ) := fun _ _ h => Subtype.ext <| Units.ext_iff.mp h theorem _root_.IsUnit.mem_unitary_of_star_mul_self {u : R} (hu : IsUnit u) (h_mul : star u * u = 1) : u ∈ unitary R := by refine unitary.mem_iff.mpr ⟨h_mul, ?_⟩ lift u to Rˣ using hu exact left_inv_eq_right_inv h_mul u.mul_inv ▸ u.mul_inv theorem _root_.IsUnit.mem_unitary_of_mul_star_self {u : R} (hu : IsUnit u) (h_mul : u * star u = 1) : u ∈ unitary R := star_star u ▸ (hu.star.mem_unitary_of_star_mul_self ((star_star u).symm ▸ h_mul) |> unitary.star_mem) instance instIsStarNormal (u : unitary R) : IsStarNormal u where star_comm_self := star_mul_self u |>.trans <| (mul_star_self u).symm instance coe_isStarNormal (u : unitary R) : IsStarNormal (u : R) where star_comm_self := congr(Subtype.val $(star_comm_self' u)) lemma _root_.isStarNormal_of_mem_unitary {u : R} (hu : u ∈ unitary R) : IsStarNormal u := coe_isStarNormal ⟨u, hu⟩ end Monoid section Map variable {F R S : Type*} [Monoid R] [StarMul R] [Monoid S] [StarMul S] variable [FunLike F R S] [StarHomClass F R S] [MonoidHomClass F R S] (f : F) lemma map_mem {r : R} (hr : r ∈ unitary R) : f r ∈ unitary S := by rw [unitary.mem_iff] at hr simpa [map_star, map_mul] using And.intro congr(f $(hr.1)) congr(f $(hr.2)) /-- The group homomorphism between unitary subgroups of star monoids induced by a star homomorphism -/ @[simps] def map : unitary R →* unitary S where toFun := Subtype.map f (fun _ ↦ map_mem f) map_one' := Subtype.ext <| map_one f map_mul' _ _ := Subtype.ext <| map_mul f _ _ lemma toUnits_comp_map : toUnits.comp (map f) = (Units.map f).comp toUnits := by ext; rfl end Map section CommMonoid variable [CommMonoid R] [StarMul R] instance : CommGroup (unitary R) := { inferInstanceAs (Group (unitary R)), Submonoid.toCommMonoid _ with } theorem mem_iff_star_mul_self {U : R} : U ∈ unitary R ↔ star U * U = 1 := mem_iff.trans <| and_iff_left_of_imp fun h => mul_comm (star U) U ▸ h theorem mem_iff_self_mul_star {U : R} : U ∈ unitary R ↔ U * star U = 1 := mem_iff.trans <| and_iff_right_of_imp fun h => mul_comm U (star U) ▸ h end CommMonoid section GroupWithZero variable [GroupWithZero R] [StarMul R] @[norm_cast] theorem coe_inv (U : unitary R) : ↑U⁻¹ = (U⁻¹ : R) := eq_inv_of_mul_eq_one_right <| coe_mul_star_self _ @[norm_cast] theorem coe_div (U₁ U₂ : unitary R) : ↑(U₁ / U₂) = (U₁ / U₂ : R) := by simp only [div_eq_mul_inv, coe_inv, Submonoid.coe_mul] @[norm_cast] theorem coe_zpow (U : unitary R) (z : ℤ) : ↑(U ^ z) = (U : R) ^ z := by induction z · simp [SubmonoidClass.coe_pow] · simp [coe_inv] end GroupWithZero section Ring variable [Ring R] [StarRing R] instance : Neg (unitary R) where neg U := ⟨-U, by simp [mem_iff, star_neg, neg_mul_neg]⟩ @[norm_cast] theorem coe_neg (U : unitary R) : ↑(-U) = (-U : R) := rfl instance : HasDistribNeg (unitary R) := Subtype.coe_injective.hasDistribNeg _ coe_neg (unitary R).coe_mul end Ring section UnitaryConjugate universe u variable {R A : Type*} [CommSemiring R] [Ring A] [Algebra R A] [StarMul A] /-- Unitary conjugation preserves the spectrum, star on left. -/ @[simp] lemma spectrum.unitary_conjugate {a : A} {u : unitary A} : spectrum R (u * a * (star u : A)) = spectrum R a := spectrum.units_conjugate (u := unitary.toUnits u) /-- Unitary conjugation preserves the spectrum, star on right. -/ @[simp] lemma spectrum.unitary_conjugate' {a : A} {u : unitary A} : spectrum R ((star u : A) * a * u) = spectrum R a := by simpa using spectrum.unitary_conjugate (u := star u) end UnitaryConjugate end unitary
Algebra\Tropical\Basic.lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Algebra.SMulWithZero import Mathlib.Order.Hom.Basic import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop /-! # Tropical algebraic structures This file defines algebraic structures of the (min-)tropical numbers, up to the tropical semiring. Some basic lemmas about conversion from the base type `R` to `Tropical R` are provided, as well as the expected implementations of tropical addition and tropical multiplication. ## Main declarations * `Tropical R`: The type synonym of the tropical interpretation of `R`. If `[LinearOrder R]`, then addition on `R` is via `min`. * `Semiring (Tropical R)`: A `LinearOrderedAddCommMonoidWithTop R` induces a `Semiring (Tropical R)`. If one solely has `[LinearOrderedAddCommMonoid R]`, then the "tropicalization of `R`" would be `Tropical (WithTop R)`. ## Implementation notes The tropical structure relies on `Top` and `min`. For the max-tropical numbers, use `OrderDual R`. Inspiration was drawn from the implementation of `Additive`/`Multiplicative`/`Opposite`, where a type synonym is created with some barebones API, and quickly made irreducible. Algebraic structures are provided with as few typeclass assumptions as possible, even though most references rely on `Semiring (Tropical R)` for building up the whole theory. ## References followed * https://arxiv.org/pdf/math/0408099.pdf * https://www.mathenjeans.fr/sites/default/files/sujets/tropical_geometry_-_casagrande.pdf -/ universe u v variable (R : Type u) /-- The tropicalization of a type `R`. -/ def Tropical : Type u := R variable {R} namespace Tropical /-- Reinterpret `x : R` as an element of `Tropical R`. See `Tropical.tropEquiv` for the equivalence. -/ def trop : R → Tropical R := id /-- Reinterpret `x : Tropical R` as an element of `R`. See `Tropical.tropEquiv` for the equivalence. -/ @[pp_nodot] def untrop : Tropical R → R := id theorem trop_injective : Function.Injective (trop : R → Tropical R) := fun _ _ => id theorem untrop_injective : Function.Injective (untrop : Tropical R → R) := fun _ _ => id @[simp] theorem trop_inj_iff (x y : R) : trop x = trop y ↔ x = y := Iff.rfl @[simp] theorem untrop_inj_iff (x y : Tropical R) : untrop x = untrop y ↔ x = y := Iff.rfl @[simp] theorem trop_untrop (x : Tropical R) : trop (untrop x) = x := rfl @[simp] theorem untrop_trop (x : R) : untrop (trop x) = x := rfl -- Porting note: New attribute seems to fix things attribute [irreducible] Tropical theorem leftInverse_trop : Function.LeftInverse (trop : R → Tropical R) untrop := trop_untrop theorem rightInverse_trop : Function.RightInverse (trop : R → Tropical R) untrop := untrop_trop /-- Reinterpret `x : R` as an element of `Tropical R`. See `Tropical.tropOrderIso` for the order-preserving equivalence. -/ def tropEquiv : R ≃ Tropical R where toFun := trop invFun := untrop left_inv := untrop_trop right_inv := trop_untrop @[simp] theorem tropEquiv_coe_fn : (tropEquiv : R → Tropical R) = trop := rfl @[simp] theorem tropEquiv_symm_coe_fn : (tropEquiv.symm : Tropical R → R) = untrop := rfl theorem trop_eq_iff_eq_untrop {x : R} {y} : trop x = y ↔ x = untrop y := tropEquiv.apply_eq_iff_eq_symm_apply theorem untrop_eq_iff_eq_trop {x} {y : R} : untrop x = y ↔ x = trop y := tropEquiv.symm.apply_eq_iff_eq_symm_apply theorem injective_trop : Function.Injective (trop : R → Tropical R) := tropEquiv.injective theorem injective_untrop : Function.Injective (untrop : Tropical R → R) := tropEquiv.symm.injective theorem surjective_trop : Function.Surjective (trop : R → Tropical R) := tropEquiv.surjective theorem surjective_untrop : Function.Surjective (untrop : Tropical R → R) := tropEquiv.symm.surjective instance [Inhabited R] : Inhabited (Tropical R) := ⟨trop default⟩ /-- Recursing on an `x' : Tropical R` is the same as recursing on an `x : R` reinterpreted as a term of `Tropical R` via `trop x`. -/ @[simp] def tropRec {F : Tropical R → Sort v} (h : ∀ X, F (trop X)) : ∀ X, F X := fun X => h (untrop X) instance [DecidableEq R] : DecidableEq (Tropical R) := fun _ _ => decidable_of_iff _ injective_untrop.eq_iff section Order instance instLETropical [LE R] : LE (Tropical R) where le x y := untrop x ≤ untrop y @[simp] theorem untrop_le_iff [LE R] {x y : Tropical R} : untrop x ≤ untrop y ↔ x ≤ y := Iff.rfl instance decidableLE [LE R] [DecidableRel ((· ≤ ·) : R → R → Prop)] : DecidableRel ((· ≤ ·) : Tropical R → Tropical R → Prop) := fun x y => ‹DecidableRel (· ≤ ·)› (untrop x) (untrop y) instance instLTTropical [LT R] : LT (Tropical R) where lt x y := untrop x < untrop y @[simp] theorem untrop_lt_iff [LT R] {x y : Tropical R} : untrop x < untrop y ↔ x < y := Iff.rfl instance decidableLT [LT R] [DecidableRel ((· < ·) : R → R → Prop)] : DecidableRel ((· < ·) : Tropical R → Tropical R → Prop) := fun x y => ‹DecidableRel (· < ·)› (untrop x) (untrop y) instance instPreorderTropical [Preorder R] : Preorder (Tropical R) := { instLETropical, instLTTropical with le_refl := fun x => le_refl (untrop x) le_trans := fun _ _ _ h h' => le_trans (α := R) h h' lt_iff_le_not_le := fun _ _ => lt_iff_le_not_le (α := R) } /-- Reinterpret `x : R` as an element of `Tropical R`, preserving the order. -/ def tropOrderIso [Preorder R] : R ≃o Tropical R := { tropEquiv with map_rel_iff' := untrop_le_iff } @[simp] theorem tropOrderIso_coe_fn [Preorder R] : (tropOrderIso : R → Tropical R) = trop := rfl @[simp] theorem tropOrderIso_symm_coe_fn [Preorder R] : (tropOrderIso.symm : Tropical R → R) = untrop := rfl theorem trop_monotone [Preorder R] : Monotone (trop : R → Tropical R) := fun _ _ => id theorem untrop_monotone [Preorder R] : Monotone (untrop : Tropical R → R) := fun _ _ => id instance instPartialOrderTropical [PartialOrder R] : PartialOrder (Tropical R) := { instPreorderTropical with le_antisymm := fun _ _ h h' => untrop_injective (le_antisymm h h') } instance instZeroTropical [Top R] : Zero (Tropical R) := ⟨trop ⊤⟩ instance instTopTropical [Top R] : Top (Tropical R) := ⟨0⟩ @[simp] theorem untrop_zero [Top R] : untrop (0 : Tropical R) = ⊤ := rfl @[simp] theorem trop_top [Top R] : trop (⊤ : R) = 0 := rfl @[simp] theorem trop_coe_ne_zero (x : R) : trop (x : WithTop R) ≠ 0 := nofun @[simp] theorem zero_ne_trop_coe (x : R) : (0 : Tropical (WithTop R)) ≠ trop x := nofun @[simp] theorem le_zero [LE R] [OrderTop R] (x : Tropical R) : x ≤ 0 := le_top (α := R) instance [LE R] [OrderTop R] : OrderTop (Tropical R) := { instTopTropical with le_top := fun _ => le_top (α := R) } variable [LinearOrder R] /-- Tropical addition is the minimum of two underlying elements of `R`. -/ instance : Add (Tropical R) := ⟨fun x y => trop (min (untrop x) (untrop y))⟩ instance instAddCommSemigroupTropical : AddCommSemigroup (Tropical R) where add := (· + ·) add_assoc _ _ _ := untrop_injective (min_assoc _ _ _) add_comm _ _ := untrop_injective (min_comm _ _) @[simp] theorem untrop_add (x y : Tropical R) : untrop (x + y) = min (untrop x) (untrop y) := rfl @[simp] theorem trop_min (x y : R) : trop (min x y) = trop x + trop y := rfl @[simp] theorem trop_inf (x y : R) : trop (x ⊓ y) = trop x + trop y := rfl theorem trop_add_def (x y : Tropical R) : x + y = trop (min (untrop x) (untrop y)) := rfl instance instLinearOrderTropical : LinearOrder (Tropical R) := { instPartialOrderTropical with le_total := fun a b => le_total (untrop a) (untrop b) decidableLE := Tropical.decidableLE max := fun a b => trop (max (untrop a) (untrop b)) max_def := fun a b => untrop_injective (by simp only [max_def, untrop_le_iff, untrop_trop]; split_ifs <;> simp) min := (· + ·) min_def := fun a b => untrop_injective (by simp only [untrop_add, min_def, untrop_le_iff]; split_ifs <;> simp) } @[simp] theorem untrop_sup (x y : Tropical R) : untrop (x ⊔ y) = untrop x ⊔ untrop y := rfl @[simp] theorem untrop_max (x y : Tropical R) : untrop (max x y) = max (untrop x) (untrop y) := rfl @[simp] theorem min_eq_add : (min : Tropical R → Tropical R → Tropical R) = (· + ·) := rfl @[simp] theorem inf_eq_add : ((· ⊓ ·) : Tropical R → Tropical R → Tropical R) = (· + ·) := rfl theorem trop_max_def (x y : Tropical R) : max x y = trop (max (untrop x) (untrop y)) := rfl theorem trop_sup_def (x y : Tropical R) : x ⊔ y = trop (untrop x ⊔ untrop y) := rfl @[simp] theorem add_eq_left ⦃x y : Tropical R⦄ (h : x ≤ y) : x + y = x := untrop_injective (by simpa using h) @[simp] theorem add_eq_right ⦃x y : Tropical R⦄ (h : y ≤ x) : x + y = y := untrop_injective (by simpa using h) theorem add_eq_left_iff {x y : Tropical R} : x + y = x ↔ x ≤ y := by rw [trop_add_def, trop_eq_iff_eq_untrop, ← untrop_le_iff, min_eq_left_iff] theorem add_eq_right_iff {x y : Tropical R} : x + y = y ↔ y ≤ x := by rw [trop_add_def, trop_eq_iff_eq_untrop, ← untrop_le_iff, min_eq_right_iff] -- Porting note (#10618): removing `simp`. `simp` can prove it theorem add_self (x : Tropical R) : x + x = x := untrop_injective (min_eq_right le_rfl) theorem add_eq_iff {x y z : Tropical R} : x + y = z ↔ x = z ∧ x ≤ y ∨ y = z ∧ y ≤ x := by rw [trop_add_def, trop_eq_iff_eq_untrop] simp [min_eq_iff] @[simp] theorem add_eq_zero_iff {a b : Tropical (WithTop R)} : a + b = 0 ↔ a = 0 ∧ b = 0 := by rw [add_eq_iff] constructor · rintro (⟨rfl, h⟩ | ⟨rfl, h⟩) · exact ⟨rfl, le_antisymm (le_zero _) h⟩ · exact ⟨le_antisymm (le_zero _) h, rfl⟩ · rintro ⟨rfl, rfl⟩ simp instance instAddCommMonoidTropical [OrderTop R] : AddCommMonoid (Tropical R) := { instZeroTropical, instAddCommSemigroupTropical with zero_add := fun _ => untrop_injective (min_top_left _) add_zero := fun _ => untrop_injective (min_top_right _) nsmul := nsmulRec } end Order section Monoid /-- Tropical multiplication is the addition in the underlying `R`. -/ instance [Add R] : Mul (Tropical R) := ⟨fun x y => trop (untrop x + untrop y)⟩ @[simp] theorem trop_add [Add R] (x y : R) : trop (x + y) = trop x * trop y := rfl @[simp] theorem untrop_mul [Add R] (x y : Tropical R) : untrop (x * y) = untrop x + untrop y := rfl theorem trop_mul_def [Add R] (x y : Tropical R) : x * y = trop (untrop x + untrop y) := rfl instance instOneTropical [Zero R] : One (Tropical R) := ⟨trop 0⟩ @[simp] theorem trop_zero [Zero R] : trop (0 : R) = 1 := rfl @[simp] theorem untrop_one [Zero R] : untrop (1 : Tropical R) = 0 := rfl instance instAddMonoidWithOneTropical [LinearOrder R] [OrderTop R] [Zero R] : AddMonoidWithOne (Tropical R) := { instOneTropical, instAddCommMonoidTropical with natCast := fun n => if n = 0 then 0 else 1 natCast_zero := rfl natCast_succ := fun n => (untrop_inj_iff _ _).1 (by cases n <;> simp [Nat.cast]) } instance [Zero R] : Nontrivial (Tropical (WithTop R)) := ⟨⟨0, 1, trop_injective.ne WithTop.top_ne_coe⟩⟩ instance [Neg R] : Inv (Tropical R) := ⟨fun x => trop (-untrop x)⟩ @[simp] theorem untrop_inv [Neg R] (x : Tropical R) : untrop x⁻¹ = -untrop x := rfl instance [Sub R] : Div (Tropical R) := ⟨fun x y => trop (untrop x - untrop y)⟩ @[simp] theorem untrop_div [Sub R] (x y : Tropical R) : untrop (x / y) = untrop x - untrop y := rfl instance instSemigroupTropical [AddSemigroup R] : Semigroup (Tropical R) where mul := (· * ·) mul_assoc _ _ _ := untrop_injective (add_assoc _ _ _) instance instCommSemigroupTropical [AddCommSemigroup R] : CommSemigroup (Tropical R) := { instSemigroupTropical with mul_comm := fun _ _ => untrop_injective (add_comm _ _) } instance {α : Type*} [SMul α R] : Pow (Tropical R) α where pow x n := trop <| n • untrop x @[simp] theorem untrop_pow {α : Type*} [SMul α R] (x : Tropical R) (n : α) : untrop (x ^ n) = n • untrop x := rfl @[simp] theorem trop_smul {α : Type*} [SMul α R] (x : R) (n : α) : trop (n • x) = trop x ^ n := rfl instance instMulOneClassTropical [AddZeroClass R] : MulOneClass (Tropical R) where one := 1 mul := (· * ·) one_mul _ := untrop_injective <| zero_add _ mul_one _ := untrop_injective <| add_zero _ instance instMonoidTropical [AddMonoid R] : Monoid (Tropical R) := { instMulOneClassTropical, instSemigroupTropical with npow := fun n x => x ^ n npow_zero := fun _ => untrop_injective <| by simp npow_succ := fun _ _ => untrop_injective <| succ_nsmul _ _ } @[simp] theorem trop_nsmul [AddMonoid R] (x : R) (n : ℕ) : trop (n • x) = trop x ^ n := rfl instance instCommMonoidTropical [AddCommMonoid R] : CommMonoid (Tropical R) := { instMonoidTropical, instCommSemigroupTropical with } instance instGroupTropical [AddGroup R] : Group (Tropical R) := { instMonoidTropical with inv := Inv.inv div_eq_mul_inv := fun _ _ => untrop_injective <| by simp [sub_eq_add_neg] mul_left_inv := fun _ => untrop_injective <| add_left_neg _ zpow := fun n x => trop <| n • untrop x zpow_zero' := fun _ => untrop_injective <| zero_zsmul _ zpow_succ' := fun _ _ => untrop_injective <| SubNegMonoid.zsmul_succ' _ _ zpow_neg' := fun _ _ => untrop_injective <| SubNegMonoid.zsmul_neg' _ _ } instance [AddCommGroup R] : CommGroup (Tropical R) := { instGroupTropical with mul_comm := fun _ _ => untrop_injective (add_comm _ _) } @[simp] theorem untrop_zpow [AddGroup R] (x : Tropical R) (n : ℤ) : untrop (x ^ n) = n • untrop x := rfl @[simp] theorem trop_zsmul [AddGroup R] (x : R) (n : ℤ) : trop (n • x) = trop x ^ n := rfl end Monoid section Distrib instance covariant_mul [LE R] [Add R] [CovariantClass R R (· + ·) (· ≤ ·)] : CovariantClass (Tropical R) (Tropical R) (· * ·) (· ≤ ·) := ⟨fun _ y z h => add_le_add_left (show untrop y ≤ untrop z from h) _⟩ instance covariant_swap_mul [LE R] [Add R] [CovariantClass R R (Function.swap (· + ·)) (· ≤ ·)] : CovariantClass (Tropical R) (Tropical R) (Function.swap (· * ·)) (· ≤ ·) := ⟨fun _ y z h => add_le_add_right (show untrop y ≤ untrop z from h) _⟩ instance covariant_add [LinearOrder R] : CovariantClass (Tropical R) (Tropical R) (· + ·) (· ≤ ·) := ⟨fun x y z h => by rcases le_total x y with hx | hy · rw [add_eq_left hx, add_eq_left (hx.trans h)] · rw [add_eq_right hy] rcases le_total x z with hx | hx · rwa [add_eq_left hx] · rwa [add_eq_right hx]⟩ instance covariant_mul_lt [LT R] [Add R] [CovariantClass R R (· + ·) (· < ·)] : CovariantClass (Tropical R) (Tropical R) (· * ·) (· < ·) := ⟨fun _ _ _ h => add_lt_add_left (untrop_lt_iff.2 h) _⟩ instance covariant_swap_mul_lt [Preorder R] [Add R] [CovariantClass R R (Function.swap (· + ·)) (· < ·)] : CovariantClass (Tropical R) (Tropical R) (Function.swap (· * ·)) (· < ·) := ⟨fun _ y z h => add_lt_add_right (show untrop y < untrop z from h) _⟩ instance instDistribTropical [LinearOrder R] [Add R] [CovariantClass R R (· + ·) (· ≤ ·)] [CovariantClass R R (Function.swap (· + ·)) (· ≤ ·)] : Distrib (Tropical R) where mul := (· * ·) add := (· + ·) left_distrib _ _ _ := untrop_injective (min_add_add_left _ _ _).symm right_distrib _ _ _ := untrop_injective (min_add_add_right _ _ _).symm @[simp] theorem add_pow [LinearOrder R] [AddMonoid R] [CovariantClass R R (· + ·) (· ≤ ·)] [CovariantClass R R (Function.swap (· + ·)) (· ≤ ·)] (x y : Tropical R) (n : ℕ) : (x + y) ^ n = x ^ n + y ^ n := by rcases le_total x y with h | h · rw [add_eq_left h, add_eq_left (pow_le_pow_left' h _)] · rw [add_eq_right h, add_eq_right (pow_le_pow_left' h _)] end Distrib section Semiring variable [LinearOrderedAddCommMonoidWithTop R] instance : CommSemiring (Tropical R) := { instAddMonoidWithOneTropical, instDistribTropical, instAddCommMonoidTropical, instCommMonoidTropical with zero_mul := fun _ => untrop_injective (by simp [top_add]) mul_zero := fun _ => untrop_injective (by simp [add_top]) } @[simp] theorem succ_nsmul {R} [LinearOrder R] [OrderTop R] (x : Tropical R) (n : ℕ) : (n + 1) • x = x := by induction' n with n IH · simp · rw [add_nsmul, IH, one_nsmul, add_self] -- TODO: find/create the right classes to make this hold (for enat, ennreal, etc) -- Requires `zero_eq_bot` to be true -- lemma add_eq_zero_iff {a b : tropical R} : -- a + b = 1 ↔ a = 1 ∨ b = 1 := sorry -- Porting note (#10618): removing @[simp], `simp` can prove it theorem mul_eq_zero_iff {R : Type*} [LinearOrderedAddCommMonoid R] {a b : Tropical (WithTop R)} : a * b = 0 ↔ a = 0 ∨ b = 0 := by simp [← untrop_inj_iff, WithTop.add_eq_top] instance {R : Type*} [LinearOrderedAddCommMonoid R] : NoZeroDivisors (Tropical (WithTop R)) := ⟨mul_eq_zero_iff.mp⟩ end Semiring end Tropical
Algebra\Tropical\BigOperators.lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Data.List.MinMax import Mathlib.Algebra.Tropical.Basic import Mathlib.Order.ConditionallyCompleteLattice.Finset /-! # Tropicalization of finitary operations This file provides the "big-op" or notation-based finitary operations on tropicalized types. This allows easy conversion between sums to Infs and prods to sums. Results here are important for expressing that evaluation of tropical polynomials are the minimum over a finite piecewise collection of linear functions. ## Main declarations * `untrop_sum` ## Implementation notes No concrete (semi)ring is used here, only ones with inferrable order/lattice structure, to support `Real`, `Rat`, `EReal`, and others (`ERat` is not yet defined). Minima over `List α` are defined as producing a value in `WithTop α` so proofs about lists do not directly transfer to minima over multisets or finsets. -/ variable {R S : Type*} open Tropical Finset theorem List.trop_sum [AddMonoid R] (l : List R) : trop l.sum = List.prod (l.map trop) := by induction' l with hd tl IH · simp · simp [← IH] theorem Multiset.trop_sum [AddCommMonoid R] (s : Multiset R) : trop s.sum = Multiset.prod (s.map trop) := Quotient.inductionOn s (by simpa using List.trop_sum) theorem trop_sum [AddCommMonoid R] (s : Finset S) (f : S → R) : trop (∑ i ∈ s, f i) = ∏ i ∈ s, trop (f i) := by convert Multiset.trop_sum (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem List.untrop_prod [AddMonoid R] (l : List (Tropical R)) : untrop l.prod = List.sum (l.map untrop) := by induction' l with hd tl IH · simp · simp [← IH] theorem Multiset.untrop_prod [AddCommMonoid R] (s : Multiset (Tropical R)) : untrop s.prod = Multiset.sum (s.map untrop) := Quotient.inductionOn s (by simpa using List.untrop_prod) theorem untrop_prod [AddCommMonoid R] (s : Finset S) (f : S → Tropical R) : untrop (∏ i ∈ s, f i) = ∑ i ∈ s, untrop (f i) := by convert Multiset.untrop_prod (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl -- Porting note: replaced `coe` with `WithTop.some` in statement theorem List.trop_minimum [LinearOrder R] (l : List R) : trop l.minimum = List.sum (l.map (trop ∘ WithTop.some)) := by induction' l with hd tl IH · simp · simp [List.minimum_cons, ← IH] theorem Multiset.trop_inf [LinearOrder R] [OrderTop R] (s : Multiset R) : trop s.inf = Multiset.sum (s.map trop) := by induction' s using Multiset.induction with s x IH · simp · simp [← IH] theorem Finset.trop_inf [LinearOrder R] [OrderTop R] (s : Finset S) (f : S → R) : trop (s.inf f) = ∑ i ∈ s, trop (f i) := by convert Multiset.trop_inf (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem trop_sInf_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → WithTop R) : trop (sInf (f '' s)) = ∑ i ∈ s, trop (f i) := by rcases s.eq_empty_or_nonempty with (rfl | h) · simp only [Set.image_empty, coe_empty, sum_empty, WithTop.sInf_empty, trop_top] rw [← inf'_eq_csInf_image _ h, inf'_eq_inf, s.trop_inf] theorem trop_iInf [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S → WithTop R) : trop (⨅ i : S, f i) = ∑ i : S, trop (f i) := by rw [iInf, ← Set.image_univ, ← coe_univ, trop_sInf_image] theorem Multiset.untrop_sum [LinearOrder R] [OrderTop R] (s : Multiset (Tropical R)) : untrop s.sum = Multiset.inf (s.map untrop) := by induction' s using Multiset.induction with s x IH · simp · simp only [sum_cons, untrop_add, untrop_le_iff, map_cons, inf_cons, ← IH, inf_eq_min] theorem Finset.untrop_sum' [LinearOrder R] [OrderTop R] (s : Finset S) (f : S → Tropical R) : untrop (∑ i ∈ s, f i) = s.inf (untrop ∘ f) := by convert Multiset.untrop_sum (s.val.map f) simp only [Multiset.map_map, Function.comp_apply, inf_def] theorem untrop_sum_eq_sInf_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → Tropical (WithTop R)) : untrop (∑ i ∈ s, f i) = sInf (untrop ∘ f '' s) := by rcases s.eq_empty_or_nonempty with (rfl | h) · simp only [Set.image_empty, coe_empty, sum_empty, WithTop.sInf_empty, untrop_zero] · rw [← inf'_eq_csInf_image _ h, inf'_eq_inf, Finset.untrop_sum'] theorem untrop_sum [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S → Tropical (WithTop R)) : untrop (∑ i : S, f i) = ⨅ i : S, untrop (f i) := by rw [iInf, ← Set.image_univ, ← coe_univ, untrop_sum_eq_sInf_image, Function.comp_def] /-- Note we cannot use `i ∈ s` instead of `i : s` here as it is simply not true on conditionally complete lattices! -/ theorem Finset.untrop_sum [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → Tropical (WithTop R)) : untrop (∑ i ∈ s, f i) = ⨅ i : s, untrop (f i) := by simpa [← _root_.untrop_sum] using (sum_attach _ _).symm
Algebra\Tropical\Lattice.lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.Tropical.Basic import Mathlib.Order.ConditionallyCompleteLattice.Basic /-! # Order on tropical algebraic structure This file defines the orders induced on tropical algebraic structures by the underlying type. ## Main declarations * `ConditionallyCompleteLattice (Tropical R)` * `ConditionallyCompleteLinearOrder (Tropical R)` ## Implementation notes The order induced is the definitionally equal underlying order, which makes the proofs and constructions quicker to implement. -/ variable {R S : Type*} open Tropical instance instSupTropical [Sup R] : Sup (Tropical R) where sup x y := trop (untrop x ⊔ untrop y) instance instInfTropical [Inf R] : Inf (Tropical R) where inf x y := trop (untrop x ⊓ untrop y) instance instSemilatticeInfTropical [SemilatticeInf R] : SemilatticeInf (Tropical R) := { instInfTropical, Tropical.instPartialOrderTropical with le_inf := fun _ _ _ ↦ @SemilatticeInf.le_inf R _ _ _ _ inf_le_left := fun _ _ ↦ inf_le_left inf_le_right := fun _ _ ↦ inf_le_right } instance instSemilatticeSupTropical [SemilatticeSup R] : SemilatticeSup (Tropical R) := { instSupTropical, Tropical.instPartialOrderTropical with sup_le := fun _ _ _ ↦ @SemilatticeSup.sup_le R _ _ _ _ le_sup_left := fun _ _ ↦ le_sup_left le_sup_right := fun _ _ ↦ le_sup_right } instance instLatticeTropical [Lattice R] : Lattice (Tropical R) := { instSemilatticeInfTropical, instSemilatticeSupTropical with } instance [SupSet R] : SupSet (Tropical R) where sSup s := trop (sSup (untrop '' s)) instance [InfSet R] : InfSet (Tropical R) where sInf s := trop (sInf (untrop '' s)) instance instConditionallyCompleteLatticeTropical [ConditionallyCompleteLattice R] : ConditionallyCompleteLattice (Tropical R) := { @instInfTropical R _, @instSupTropical R _, instLatticeTropical with le_csSup := fun _s _x hs hx ↦ le_csSup (untrop_monotone.map_bddAbove hs) (Set.mem_image_of_mem untrop hx) csSup_le := fun _s _x hs hx ↦ csSup_le (hs.image untrop) (untrop_monotone.mem_upperBounds_image hx) le_csInf := fun _s _x hs hx ↦ le_csInf (hs.image untrop) (untrop_monotone.mem_lowerBounds_image hx) csInf_le := fun _s _x hs hx ↦ csInf_le (untrop_monotone.map_bddBelow hs) (Set.mem_image_of_mem untrop hx) } instance [ConditionallyCompleteLinearOrder R] : ConditionallyCompleteLinearOrder (Tropical R) := { instConditionallyCompleteLatticeTropical, Tropical.instLinearOrderTropical with csSup_of_not_bddAbove := by intro s hs have : Set.range untrop = (Set.univ : Set R) := Equiv.range_eq_univ tropEquiv.symm simp only [sSup, Set.image_empty, trop_inj_iff] apply csSup_of_not_bddAbove contrapose! hs change BddAbove (tropOrderIso.symm '' s) at hs exact tropOrderIso.symm.bddAbove_image.1 hs csInf_of_not_bddBelow := by intro s hs have : Set.range untrop = (Set.univ : Set R) := Equiv.range_eq_univ tropEquiv.symm simp only [sInf, Set.image_empty, trop_inj_iff] apply csInf_of_not_bddBelow contrapose! hs change BddBelow (tropOrderIso.symm '' s) at hs exact tropOrderIso.symm.bddBelow_image.1 hs }
Algebra\Vertex\HVertexOperator.lean
/- Copyright (c) 2024 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.RingTheory.HahnSeries.Multiplication /-! # Vertex operators In this file we introduce heterogeneous vertex operators using Hahn series. When `R = ℂ`, `V = W`, and `Γ = ℤ`, then this is the usual notion of "meromorphic left-moving 2D field". The notion we use here allows us to consider composites and scalar-multiply by multivariable Laurent series. ## Definitions * `HVertexOperator` : An `R`-linear map from an `R`-module `V` to `HahnModule Γ W`. * The coefficient function as an `R`-linear map. * Composition of heterogeneous vertex operators - values are Hahn series on lex order product. ## Main results * Ext ## TODO * `HahnSeries Γ R`-module structure on `HVertexOperator Γ R V W` (needs PR#10846). This means we can consider products of the form `(X-Y)^n A(X)B(Y)` for all integers `n`, where `(X-Y)^n` is expanded as `X^n(1-Y/X)^n` in `R((X))((Y))`. * curry for tensor product inputs * more API to make ext comparisons easier. * formal variable API, e.g., like the `T` function for Laurent polynomials. ## References * [R. Borcherds, *Vertex Algebras, Kac-Moody Algebras, and the Monster*][borcherds1986vertex] -/ noncomputable section variable {Γ : Type*} [PartialOrder Γ] {R : Type*} {V W : Type*} [CommRing R] [AddCommGroup V] [Module R V] [AddCommGroup W] [Module R W] /-- A heterogeneous `Γ`-vertex operator over a commutator ring `R` is an `R`-linear map from an `R`-module `V` to `Γ`-Hahn series with coefficients in an `R`-module `W`. -/ abbrev HVertexOperator (Γ : Type*) [PartialOrder Γ] (R : Type*) [CommRing R] (V : Type*) (W : Type*) [AddCommGroup V] [Module R V] [AddCommGroup W] [Module R W] := V →ₗ[R] (HahnModule Γ R W) namespace HVertexOperator section Coeff open HahnModule @[ext] theorem ext (A B : HVertexOperator Γ R V W) (h : ∀ v : V, A v = B v) : A = B := LinearMap.ext h @[deprecated (since := "2024-06-18")] alias _root_.VertexAlg.HetVertexOperator.ext := ext /-- The coefficient of a heterogeneous vertex operator, viewed as a formal power series with coefficients in linear maps. -/ @[simps] def coeff (A : HVertexOperator Γ R V W) (n : Γ) : V →ₗ[R] W where toFun v := ((of R).symm (A v)).coeff n map_add' _ _ := by simp map_smul' _ _ := by simp only [map_smul, RingHom.id_apply, of_symm_smul, HahnSeries.smul_coeff] @[deprecated (since := "2024-06-18")] alias _root_.VertexAlg.coeff := coeff theorem coeff_isPWOsupport (A : HVertexOperator Γ R V W) (v : V) : ((of R).symm (A v)).coeff.support.IsPWO := ((of R).symm (A v)).isPWO_support' @[deprecated (since := "2024-06-18")] alias _root_.VertexAlg.coeff_isPWOsupport := coeff_isPWOsupport @[ext] theorem coeff_inj : Function.Injective (coeff : HVertexOperator Γ R V W → Γ → (V →ₗ[R] W)) := by intro _ _ h ext v n exact congrFun (congrArg DFunLike.coe (congrFun h n)) v @[deprecated (since := "2024-06-18")] alias _root_.VertexAlg.coeff_inj := coeff_inj /-- Given a coefficient function valued in linear maps satisfying a partially well-ordered support condition, we produce a heterogeneous vertex operator. -/ @[simps] def of_coeff (f : Γ → V →ₗ[R] W) (hf : ∀(x : V), (Function.support (f · x)).IsPWO) : HVertexOperator Γ R V W where toFun x := (of R) { coeff := fun g => f g x, isPWO_support' := hf x } map_add' _ _ := by ext; simp map_smul' _ _ := by ext; simp @[deprecated (since := "2024-06-18")] alias _root_.VertexAlg.HetVertexOperator.of_coeff := of_coeff end Coeff section Products variable {Γ Γ' : Type*} [OrderedCancelAddCommMonoid Γ] [OrderedCancelAddCommMonoid Γ'] {R : Type*} [CommRing R] {U V W : Type*} [AddCommGroup U] [Module R U][AddCommGroup V] [Module R V] [AddCommGroup W] [Module R W] (A : HVertexOperator Γ R V W) (B : HVertexOperator Γ' R U V) open HahnModule /-- The composite of two heterogeneous vertex operators acting on a vector, as an iterated Hahn series. -/ @[simps] def compHahnSeries (u : U) : HahnSeries Γ' (HahnSeries Γ W) where coeff g' := A (coeff B g' u) isPWO_support' := by refine Set.IsPWO.mono (((of R).symm (B u)).isPWO_support') ?_ simp_all only [coeff_apply, Function.support_subset_iff, ne_eq, Function.mem_support] intro g' hg' hAB apply hg' simp_rw [hAB] simp_all only [map_zero, HahnSeries.zero_coeff, not_true_eq_false] @[simp] theorem compHahnSeries_add (u v : U) : compHahnSeries A B (u + v) = compHahnSeries A B u + compHahnSeries A B v := by ext simp only [compHahnSeries_coeff, map_add, coeff_apply, HahnSeries.add_coeff', Pi.add_apply] rw [← HahnSeries.add_coeff] @[simp] theorem compHahnSeries_smul (r : R) (u : U) : compHahnSeries A B (r • u) = r • compHahnSeries A B u := by ext simp only [compHahnSeries_coeff, LinearMapClass.map_smul, coeff_apply, HahnSeries.smul_coeff] rw [← HahnSeries.smul_coeff] /-- The composite of two heterogeneous vertex operators, as a heterogeneous vertex operator. -/ @[simps] def comp : HVertexOperator (Γ' ×ₗ Γ) R U W where toFun u := HahnModule.of R (HahnSeries.ofIterate (compHahnSeries A B u)) map_add' := by intro u v ext g simp only [HahnSeries.ofIterate, compHahnSeries_add, Equiv.symm_apply_apply, HahnModule.of_symm_add, HahnSeries.add_coeff', Pi.add_apply] map_smul' := by intro r x ext g simp only [HahnSeries.ofIterate, compHahnSeries_smul, HahnSeries.smul_coeff, compHahnSeries_coeff, coeff_apply, Equiv.symm_apply_apply, RingHom.id_apply, of_symm_smul] @[simp] theorem comp_coeff (g : Γ' ×ₗ Γ) : (comp A B).coeff g = A.coeff (ofLex g).2 ∘ₗ B.coeff (ofLex g).1 := by rfl end Products end HVertexOperator
AlgebraicGeometry\AffineScheme.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.GammaSpecAdjunction import Mathlib.AlgebraicGeometry.Restrict import Mathlib.AlgebraicGeometry.Cover.Open import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.RingTheory.Localization.InvSubmonoid /-! # Affine schemes We define the category of `AffineScheme`s as the essential image of `Spec`. We also define predicates about affine schemes and affine open sets. ## Main definitions * `AlgebraicGeometry.AffineScheme`: The category of affine schemes. * `AlgebraicGeometry.IsAffine`: A scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. * `AlgebraicGeometry.Scheme.isoSpec`: The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. * `AlgebraicGeometry.AffineScheme.equivCommRingCat`: The equivalence of categories `AffineScheme ≌ CommRingᵒᵖ` given by `AffineScheme.Spec : CommRingᵒᵖ ⥤ AffineScheme` and `AffineScheme.Γ : AffineSchemeᵒᵖ ⥤ CommRingCat`. * `AlgebraicGeometry.IsAffineOpen`: An open subset of a scheme is affine if the open subscheme is affine. * `AlgebraicGeometry.IsAffineOpen.fromSpec`: The immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`. -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 noncomputable section open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace universe u namespace AlgebraicGeometry open Spec (structureSheaf) /-- The category of affine schemes -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] def AffineScheme := Scheme.Spec.EssImageSubcategory deriving Category /-- A Scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. -/ class IsAffine (X : Scheme) : Prop where affine : IsIso (ΓSpec.adjunction.unit.app X) attribute [instance] IsAffine.affine /-- The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. -/ @[simps! (config := .lemmasOnly) hom] def Scheme.isoSpec (X : Scheme) [IsAffine X] : X ≅ Spec Γ(X, ⊤) := asIso (ΓSpec.adjunction.unit.app X) @[reassoc] theorem Scheme.isoSpec_hom_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : X.isoSpec.hom ≫ Spec.map (f.app ⊤) = f ≫ Y.isoSpec.hom := by simp only [isoSpec, asIso_hom, ΓSpec.adjunction_unit_naturality] @[reassoc] theorem Scheme.isoSpec_inv_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : Spec.map (f.app ⊤) ≫ Y.isoSpec.inv = X.isoSpec.inv ≫ f := by rw [Iso.eq_inv_comp, isoSpec, asIso_hom, ← ΓSpec.adjunction_unit_naturality_assoc, isoSpec, asIso_inv, IsIso.hom_inv_id, Category.comp_id] /-- Construct an affine scheme from a scheme and the information that it is affine. Also see `AffineScheme.of` for a typeclass version. -/ @[simps] def AffineScheme.mk (X : Scheme) (_ : IsAffine X) : AffineScheme := ⟨X, ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩ /-- Construct an affine scheme from a scheme. Also see `AffineScheme.mk` for a non-typeclass version. -/ def AffineScheme.of (X : Scheme) [h : IsAffine X] : AffineScheme := AffineScheme.mk X h /-- Type check a morphism of schemes as a morphism in `AffineScheme`. -/ def AffineScheme.ofHom {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : AffineScheme.of X ⟶ AffineScheme.of Y := f theorem mem_Spec_essImage (X : Scheme) : X ∈ Scheme.Spec.essImage ↔ IsAffine X := ⟨fun h => ⟨Functor.essImage.unit_isIso h⟩, fun _ => ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩ instance isAffine_affineScheme (X : AffineScheme.{u}) : IsAffine X.obj := ⟨Functor.essImage.unit_isIso X.property⟩ instance (R : CommRingCatᵒᵖ) : IsAffine (Scheme.Spec.obj R) := AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage R⟩ instance isAffine_Spec (R : CommRingCat) : IsAffine (Spec R) := AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage (op R)⟩ theorem isAffine_of_isIso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] [h : IsAffine Y] : IsAffine X := by rw [← mem_Spec_essImage] at h ⊢; exact Functor.essImage.ofIso (asIso f).symm h /-- If `f : X ⟶ Y` is a morphism between affine schemes, the corresponding arrow is isomorphic to the arrow of the morphism on prime spectra induced by the map on global sections. -/ noncomputable def arrowIsoSpecΓOfIsAffine {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : Arrow.mk f ≅ Arrow.mk (Spec.map (Scheme.Γ.map f.op)) := Arrow.isoMk X.isoSpec Y.isoSpec (ΓSpec.adjunction.unit_naturality _) namespace AffineScheme /-- The `Spec` functor into the category of affine schemes. -/ def Spec : CommRingCatᵒᵖ ⥤ AffineScheme := Scheme.Spec.toEssImage -- Porting note (#11081): cannot automatically derive instance Spec_full : Spec.Full := Functor.Full.toEssImage _ -- Porting note (#11081): cannot automatically derive instance Spec_faithful : Spec.Faithful := Functor.Faithful.toEssImage _ -- Porting note (#11081): cannot automatically derive instance Spec_essSurj : Spec.EssSurj := Functor.EssSurj.toEssImage (F := _) /-- The forgetful functor `AffineScheme ⥤ Scheme`. -/ @[simps!] def forgetToScheme : AffineScheme ⥤ Scheme := Scheme.Spec.essImageInclusion -- Porting note (#11081): cannot automatically derive instance forgetToScheme_full : forgetToScheme.Full := show (Scheme.Spec.essImageInclusion).Full from inferInstance -- Porting note (#11081): cannot automatically derive instance forgetToScheme_faithful : forgetToScheme.Faithful := show (Scheme.Spec.essImageInclusion).Faithful from inferInstance /-- The global section functor of an affine scheme. -/ def Γ : AffineSchemeᵒᵖ ⥤ CommRingCat := forgetToScheme.op ⋙ Scheme.Γ /-- The category of affine schemes is equivalent to the category of commutative rings. -/ def equivCommRingCat : AffineScheme ≌ CommRingCatᵒᵖ := equivEssImageOfReflective.symm instance : Γ.{u}.rightOp.IsEquivalence := equivCommRingCat.isEquivalence_functor instance : Γ.{u}.rightOp.op.IsEquivalence := equivCommRingCat.op.isEquivalence_functor instance ΓIsEquiv : Γ.{u}.IsEquivalence := inferInstanceAs (Γ.{u}.rightOp.op ⋙ (opOpEquivalence _).functor).IsEquivalence instance hasColimits : HasColimits AffineScheme.{u} := haveI := Adjunction.has_limits_of_equivalence.{u} Γ.{u} Adjunction.has_colimits_of_equivalence.{u} (opOpEquivalence AffineScheme.{u}).inverse instance hasLimits : HasLimits AffineScheme.{u} := by haveI := Adjunction.has_colimits_of_equivalence Γ.{u} haveI : HasLimits AffineScheme.{u}ᵒᵖᵒᵖ := Limits.hasLimits_op_of_hasColimits exact Adjunction.has_limits_of_equivalence (opOpEquivalence AffineScheme.{u}).inverse noncomputable instance Γ_preservesLimits : PreservesLimits Γ.{u}.rightOp := inferInstance noncomputable instance forgetToScheme_preservesLimits : PreservesLimits forgetToScheme := by apply (config := { allowSynthFailures := true }) @preservesLimitsOfNatIso _ _ _ _ _ _ (isoWhiskerRight equivCommRingCat.unitIso forgetToScheme).symm change PreservesLimits (equivCommRingCat.functor ⋙ Scheme.Spec) infer_instance end AffineScheme /-- An open subset of a scheme is affine if the open subscheme is affine. -/ def IsAffineOpen {X : Scheme} (U : X.Opens) : Prop := IsAffine U /-- The set of affine opens as a subset of `opens X`. -/ def Scheme.affineOpens (X : Scheme) : Set X.Opens := {U : X.Opens | IsAffineOpen U} instance {Y : Scheme.{u}} (U : Y.affineOpens) : IsAffine U := U.property theorem isAffineOpen_opensRange {X Y : Scheme} [IsAffine X] (f : X ⟶ Y) [H : IsOpenImmersion f] : IsAffineOpen (Scheme.Hom.opensRange f) := by refine isAffine_of_isIso (IsOpenImmersion.isoOfRangeEq f (Y.ofRestrict _) ?_).inv exact Subtype.range_val.symm theorem isAffineOpen_top (X : Scheme) [IsAffine X] : IsAffineOpen (⊤ : X.Opens) := by convert isAffineOpen_opensRange (𝟙 X) ext1 exact Set.range_id.symm instance Scheme.isAffine_affineCover (X : Scheme) (i : X.affineCover.J) : IsAffine (X.affineCover.obj i) := isAffine_Spec _ instance Scheme.isAffine_affineBasisCover (X : Scheme) (i : X.affineBasisCover.J) : IsAffine (X.affineBasisCover.obj i) := isAffine_Spec _ instance Scheme.isAffine_affineOpenCover (X : Scheme) (𝒰 : X.AffineOpenCover) (i : 𝒰.J) : IsAffine (𝒰.openCover.obj i) := inferInstanceAs (IsAffine (Spec (𝒰.obj i))) instance {X} [IsAffine X] (i) : IsAffine ((Scheme.openCoverOfIsIso (𝟙 X)).obj i) := by dsimp; infer_instance theorem isBasis_affine_open (X : Scheme) : Opens.IsBasis X.affineOpens := by rw [Opens.isBasis_iff_nbhd] rintro U x (hU : x ∈ (U : Set X)) obtain ⟨S, hS, hxS, hSU⟩ := X.affineBasisCover_is_basis.exists_subset_of_mem_open hU U.isOpen refine ⟨⟨S, X.affineBasisCover_is_basis.isOpen hS⟩, ?_, hxS, hSU⟩ rcases hS with ⟨i, rfl⟩ exact isAffineOpen_opensRange _ theorem iSup_affineOpens_eq_top (X : Scheme) : ⨆ i : X.affineOpens, (i : X.Opens) = ⊤ := by apply Opens.ext rw [Opens.coe_iSup] apply IsTopologicalBasis.sUnion_eq rw [← Set.image_eq_range] exact isBasis_affine_open X theorem Scheme.map_PrimeSpectrum_basicOpen_of_affine (X : Scheme) [IsAffine X] (f : Scheme.Γ.obj (op X)) : X.isoSpec.hom ⁻¹ᵁ PrimeSpectrum.basicOpen f = X.basicOpen f := ΓSpec.adjunction_unit_map_basicOpen _ _ theorem isBasis_basicOpen (X : Scheme) [IsAffine X] : Opens.IsBasis (Set.range (X.basicOpen : Γ(X, ⊤) → X.Opens)) := by delta Opens.IsBasis convert PrimeSpectrum.isBasis_basic_opens.inducing (TopCat.homeoOfIso (Scheme.forgetToTop.mapIso X.isoSpec)).inducing using 1 ext simp only [Set.mem_image, exists_exists_eq_and] constructor · rintro ⟨_, ⟨x, rfl⟩, rfl⟩ refine ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, ?_⟩ exact congr_arg Opens.carrier (ΓSpec.adjunction_unit_map_basicOpen _ _) · rintro ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, rfl⟩ refine ⟨_, ⟨x, rfl⟩, ?_⟩ exact congr_arg Opens.carrier (ΓSpec.adjunction_unit_map_basicOpen _ _).symm namespace IsAffineOpen variable {X Y : Scheme.{u}} {U : X.Opens} (hU : IsAffineOpen U) (f : Γ(X, U)) /-- The open immersion `Spec Γ(X, U) ⟶ X` for an affine `U`. -/ def fromSpec : Spec Γ(X, U) ⟶ X := haveI : IsAffine U := hU Spec.map (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op) ≫ U.toScheme.isoSpec.inv ≫ U.ι instance isOpenImmersion_fromSpec : IsOpenImmersion hU.fromSpec := by delta fromSpec infer_instance @[simp] theorem range_fromSpec : Set.range hU.fromSpec.1.base = (U : Set X) := by delta IsAffineOpen.fromSpec; dsimp rw [Function.comp.assoc, Set.range_comp, Set.range_iff_surjective.mpr, Set.image_univ] · exact Subtype.range_coe erw [← coe_comp, ← TopCat.epi_iff_surjective] -- now `erw` after #13170 infer_instance @[simp] theorem opensRange_fromSpec : Scheme.Hom.opensRange hU.fromSpec = U := Opens.ext (range_fromSpec hU) @[reassoc (attr := simp)] theorem map_fromSpec {V : X.Opens} (hV : IsAffineOpen V) (f : op U ⟶ op V) : Spec.map (X.presheaf.map f) ≫ hU.fromSpec = hV.fromSpec := by have : IsAffine (X.restrictFunctor.obj U).left := hU haveI : IsAffine _ := hV conv_rhs => rw [fromSpec, ← X.restrictFunctor_map_ofRestrict f.unop, ← Scheme.isoSpec_inv_naturality_assoc, ← Spec.map_comp_assoc, Scheme.restrictFunctor_map_app, ← Functor.map_comp] rw [fromSpec, ← Spec.map_comp_assoc, ← Functor.map_comp] rfl protected theorem isCompact : IsCompact (U : Set X) := by convert @IsCompact.image _ _ _ _ Set.univ hU.fromSpec.1.base PrimeSpectrum.compactSpace.1 (by fun_prop) convert hU.range_fromSpec.symm exact Set.image_univ theorem image_of_isOpenImmersion (f : X ⟶ Y) [H : IsOpenImmersion f] : IsAffineOpen (f ''ᵁ U) := by have : IsAffine _ := hU convert isAffineOpen_opensRange (U.ι ≫ f) ext1 exact Set.image_eq_range _ _ theorem preimage_of_isIso {U : Y.Opens} (hU : IsAffineOpen U) (f : X ⟶ Y) [IsIso f] : IsAffineOpen (f ⁻¹ᵁ U) := haveI : IsAffine _ := hU isAffine_of_isIso (f ∣_ U) theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : X.Opens} : IsAffineOpen (f ''ᵁ U) ↔ IsAffineOpen U := by refine ⟨fun hU => @isAffine_of_isIso _ _ (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) ?_).hom ?_ hU, fun hU => hU.image_of_isOpenImmersion f⟩ · erw [Scheme.comp_val_base, coe_comp, Set.range_comp] -- now `erw` after #13170 dsimp [Opens.coe_inclusion, Scheme.restrict] erw [Subtype.range_coe, Subtype.range_coe] -- now `erw` after #13170 rfl · infer_instance /-- The affine open sets of an open subscheme corresponds to the affine open sets containing in the image. -/ @[simps] def _root_.AlgebraicGeometry.IsOpenImmersion.affineOpensEquiv (f : X ⟶ Y) [H : IsOpenImmersion f] : X.affineOpens ≃ { U : Y.affineOpens // U ≤ f.opensRange } where toFun U := ⟨⟨f ''ᵁ U, U.2.image_of_isOpenImmersion f⟩, Set.image_subset_range _ _⟩ invFun U := ⟨f ⁻¹ᵁ U, f.isAffineOpen_iff_of_isOpenImmersion.mp (by rw [show f ''ᵁ f ⁻¹ᵁ U = U from Opens.ext (Set.image_preimage_eq_of_subset U.2)]; exact U.1.2)⟩ left_inv _ := Subtype.ext (Opens.ext (Set.preimage_image_eq _ H.base_open.inj)) right_inv U := Subtype.ext (Subtype.ext (Opens.ext (Set.image_preimage_eq_of_subset U.2))) /-- The affine open sets of an open subscheme corresponds to the affine open sets containing in the subset. -/ @[simps! apply_coe_coe] def _root_.AlgebraicGeometry.affineOpensRestrict {X : Scheme.{u}} (U : X.Opens) : U.toScheme.affineOpens ≃ { V : X.affineOpens // V ≤ U } := (IsOpenImmersion.affineOpensEquiv U.ι).trans (Equiv.subtypeEquivProp (by simp)) @[simp] lemma _root_.AlgebraicGeometry.affineOpensRestrict_symm_apply_coe {X : Scheme.{u}} (U : X.Opens) (V) : ((affineOpensRestrict U).symm V).1 = U.ι ⁻¹ᵁ V := rfl instance (priority := 100) _root_.AlgebraicGeometry.Scheme.compactSpace_of_isAffine (X : Scheme) [IsAffine X] : CompactSpace X := ⟨(isAffineOpen_top X).isCompact⟩ @[simp] theorem fromSpec_preimage_self : hU.fromSpec ⁻¹ᵁ U = ⊤ := by ext1 rw [Opens.map_coe, Opens.coe_top, ← hU.range_fromSpec, ← Set.image_univ] exact Set.preimage_image_eq _ PresheafedSpace.IsOpenImmersion.base_open.inj theorem SpecΓIdentity_hom_app_fromSpec : (Scheme.ΓSpecIso Γ(X, U)).hom ≫ hU.fromSpec.app U = (Spec Γ(X, U)).presheaf.map (eqToHom hU.fromSpec_preimage_self).op := by simp only [fromSpec, Scheme.isoSpec, asIso_inv, Scheme.comp_coeBase, Opens.map_comp_obj, ΓSpecIso_obj_hom, Scheme.Opens.topIso_inv, Opens.map_top, Functor.id_obj, Functor.comp_obj, Functor.rightOp_obj, Scheme.Γ_obj, unop_op, Scheme.Spec_obj, Scheme.Opens.topIso_hom, Scheme.comp_app, Scheme.Opens.ι_app_self, Category.assoc, ← Functor.map_comp_assoc, ← op_comp, eqToHom_trans, Scheme.Opens.eq_presheaf_map_eqToHom, Scheme.Hom.naturality_assoc, Scheme.inv_app_top, IsIso.hom_inv_id_assoc] simp only [eqToHom_op, eqToHom_map, Spec.map_eqToHom, eqToHom_unop, Scheme.Spec_map_presheaf_map_eqToHom, eqToHom_trans] @[elementwise] theorem fromSpec_app_self : hU.fromSpec.app U = (Scheme.ΓSpecIso Γ(X, U)).inv ≫ (Spec Γ(X, U)).presheaf.map (eqToHom hU.fromSpec_preimage_self).op := by rw [← hU.SpecΓIdentity_hom_app_fromSpec, Iso.inv_hom_id_assoc] theorem fromSpec_preimage_basicOpen' : hU.fromSpec ⁻¹ᵁ X.basicOpen f = (Spec Γ(X, U)).basicOpen ((Scheme.ΓSpecIso Γ(X, U)).inv f) := by rw [Scheme.preimage_basicOpen, hU.fromSpec_app_self] exact Scheme.basicOpen_res_eq _ _ (eqToHom hU.fromSpec_preimage_self).op theorem fromSpec_preimage_basicOpen : hU.fromSpec ⁻¹ᵁ X.basicOpen f = PrimeSpectrum.basicOpen f := by rw [fromSpec_preimage_basicOpen', ← basicOpen_eq_of_affine] theorem fromSpec_image_basicOpen : hU.fromSpec ''ᵁ (PrimeSpectrum.basicOpen f) = X.basicOpen f := by rw [← hU.fromSpec_preimage_basicOpen] ext1 change hU.fromSpec.val.base '' (hU.fromSpec.val.base ⁻¹' (X.basicOpen f : Set X)) = _ rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left, hU.range_fromSpec] exact Scheme.basicOpen_le _ _ @[simp] theorem basicOpen_fromSpec_app : (Spec Γ(X, U)).basicOpen (hU.fromSpec.app U f) = PrimeSpectrum.basicOpen f := by rw [← hU.fromSpec_preimage_basicOpen, Scheme.preimage_basicOpen] theorem basicOpen : IsAffineOpen (X.basicOpen f) := by rw [← hU.fromSpec_image_basicOpen, Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion] convert isAffineOpen_opensRange (Spec.map (CommRingCat.ofHom <| algebraMap Γ(X, U) (Localization.Away f))) exact Opens.ext (PrimeSpectrum.localization_away_comap_range (Localization.Away f) f).symm instance [IsAffine X] (r : Γ(X, ⊤)) : IsAffine (X.basicOpen r) := (isAffineOpen_top X).basicOpen _ theorem ι_basicOpen_preimage (r : Γ(X, ⊤)) : IsAffineOpen ((X.basicOpen r).ι ⁻¹ᵁ U) := by apply (X.basicOpen r).ι.isAffineOpen_iff_of_isOpenImmersion.mp dsimp [Scheme.Hom.opensFunctor, LocallyRingedSpace.IsOpenImmersion.opensFunctor] rw [Opens.functor_obj_map_obj, Opens.openEmbedding_obj_top, inf_comm, ← Scheme.basicOpen_res _ _ (homOfLE le_top).op] exact hU.basicOpen _ theorem exists_basicOpen_le {V : X.Opens} (x : V) (h : ↑x ∈ U) : ∃ f : Γ(X, U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by have : IsAffine _ := hU obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ := (isBasis_basicOpen U).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _) ((Opens.map U.inclusion).obj V).isOpen have : U.ι ''ᵁ (U.toScheme.basicOpen r) = X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by refine (Scheme.image_basicOpen U.ι r).trans ?_ rw [Scheme.basicOpen_res_eq] simp only [Scheme.Opens.toScheme_presheaf_obj, Scheme.Opens.ι_appIso, Iso.refl_inv, CommRingCat.id_apply] use X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r rw [← this] exact ⟨Set.image_subset_iff.mpr h₂, ⟨_, h⟩, h₁, rfl⟩ /-- Given an affine open U and some `f : U`, this is the canonical map `Γ(𝒪ₓ, D(f)) ⟶ Γ(Spec 𝒪ₓ(U), D(f))` This is an isomorphism, as witnessed by an `IsIso` instance. -/ def basicOpenSectionsToAffine : Γ(X, X.basicOpen f) ⟶ Γ(Spec Γ(X, U), PrimeSpectrum.basicOpen f) := hU.fromSpec.1.c.app (op <| X.basicOpen f) ≫ (Spec Γ(X, U)).presheaf.map (eqToHom <| (hU.fromSpec_preimage_basicOpen f).symm).op instance basicOpenSectionsToAffine_isIso : IsIso (basicOpenSectionsToAffine hU f) := by delta basicOpenSectionsToAffine apply (config := { allowSynthFailures := true }) IsIso.comp_isIso apply PresheafedSpace.IsOpenImmersion.isIso_of_subset rw [hU.range_fromSpec] exact RingedSpace.basicOpen_le _ _ theorem isLocalization_basicOpen : IsLocalization.Away f Γ(X, X.basicOpen f) := by apply (IsLocalization.isLocalization_iff_of_ringEquiv (Submonoid.powers f) (asIso <| basicOpenSectionsToAffine hU f).commRingCatIsoToRingEquiv).mpr convert StructureSheaf.IsLocalization.to_basicOpen _ f using 1 -- Porting note: more hand holding is required here, the next 4 lines were not necessary delta StructureSheaf.openAlgebra congr 1 rw [CommRingCat.ringHom_comp_eq_comp, Iso.commRingIsoToRingEquiv_toRingHom, asIso_hom] dsimp [CommRingCat.ofHom, RingHom.algebraMap_toAlgebra] change X.presheaf.map _ ≫ basicOpenSectionsToAffine hU f = _ delta basicOpenSectionsToAffine rw [hU.fromSpec.naturality_assoc, hU.fromSpec_app_self] simp only [Category.assoc, ← Functor.map_comp, ← op_comp] apply StructureSheaf.toOpen_res instance _root_.AlgebraicGeometry.isLocalization_away_of_isAffine [IsAffine X] (r : Γ(X, ⊤)) : IsLocalization.Away r Γ(X, X.basicOpen r) := isLocalization_basicOpen (isAffineOpen_top X) r lemma appLE_eq_away_map {X Y : Scheme.{u}} (f : X ⟶ Y) {U : Y.Opens} (hU : IsAffineOpen U) {V : X.Opens} (hV : IsAffineOpen V) (e) (r : Γ(Y, U)) : letI := hU.isLocalization_basicOpen r letI := hV.isLocalization_basicOpen (f.appLE U V e r) f.appLE (Y.basicOpen r) (X.basicOpen (f.appLE U V e r)) (by simp [Scheme.Hom.appLE]) = IsLocalization.Away.map _ _ (f.appLE U V e) r := by letI := hU.isLocalization_basicOpen r letI := hV.isLocalization_basicOpen (f.appLE U V e r) apply IsLocalization.ringHom_ext (.powers r) rw [← CommRingCat.comp_eq_ring_hom_comp, IsLocalization.Away.map, IsLocalization.map_comp, RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra, ← CommRingCat.comp_eq_ring_hom_comp, Scheme.Hom.appLE_map, Scheme.Hom.map_appLE] theorem isLocalization_of_eq_basicOpen {V : X.Opens} (i : V ⟶ U) (e : V = X.basicOpen f) : @IsLocalization.Away _ _ f Γ(X, V) _ (X.presheaf.map i.op).toAlgebra := by subst e; convert isLocalization_basicOpen hU f using 3 instance _root_.AlgebraicGeometry.Γ_restrict_isLocalization (X : Scheme.{u}) [IsAffine X] (r : Γ(X, ⊤)) : IsLocalization.Away r Γ(X.basicOpen r, ⊤) := (isAffineOpen_top X).isLocalization_of_eq_basicOpen r _ (Opens.openEmbedding_obj_top _) theorem basicOpen_basicOpen_is_basicOpen (g : Γ(X, X.basicOpen f)) : ∃ f' : Γ(X, U), X.basicOpen f' = X.basicOpen g := by have := isLocalization_basicOpen hU f obtain ⟨x, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.surj'' (Submonoid.powers f) g use f * x rw [Algebra.smul_def, Scheme.basicOpen_mul, Scheme.basicOpen_mul, RingHom.algebraMap_toAlgebra] rw [Scheme.basicOpen_res] refine (inf_eq_left.mpr ?_).symm -- Porting note: a little help is needed here convert inf_le_left (α := X.Opens) using 1 apply Scheme.basicOpen_of_isUnit apply Submonoid.leftInv_le_isUnit _ (IsLocalization.toInvSubmonoid (Submonoid.powers f) (Γ(X, X.basicOpen f)) _).prop theorem _root_.AlgebraicGeometry.exists_basicOpen_le_affine_inter {V : X.Opens} (hV : IsAffineOpen V) (x : X) (hx : x ∈ U ⊓ V) : ∃ (f : Γ(X, U)) (g : Γ(X, V)), X.basicOpen f = X.basicOpen g ∧ x ∈ X.basicOpen f := by obtain ⟨f, hf₁, hf₂⟩ := hU.exists_basicOpen_le ⟨x, hx.2⟩ hx.1 obtain ⟨g, hg₁, hg₂⟩ := hV.exists_basicOpen_le ⟨x, hf₂⟩ hx.2 obtain ⟨f', hf'⟩ := basicOpen_basicOpen_is_basicOpen hU f (X.presheaf.map (homOfLE hf₁ : _ ⟶ V).op g) replace hf' := (hf'.trans (RingedSpace.basicOpen_res _ _ _)).trans (inf_eq_right.mpr hg₁) exact ⟨f', g, hf', hf'.symm ▸ hg₂⟩ /-- The prime ideal of `𝒪ₓ(U)` corresponding to a point `x : U`. -/ noncomputable def primeIdealOf (x : U) : PrimeSpectrum Γ(X, U) := ((@Scheme.isoSpec U hU).hom ≫ Spec.map (X.presheaf.map (eqToHom U.openEmbedding_obj_top).op)).1.base x theorem fromSpec_primeIdealOf (x : U) : hU.fromSpec.val.base (hU.primeIdealOf x) = x.1 := by dsimp only [IsAffineOpen.fromSpec, Subtype.coe_mk, IsAffineOpen.primeIdealOf] -- Porting note: in the porting note of `Scheme.comp_val_base`, it says that `elementwise` is -- unnecessary, indeed, the linter did not like it, so I just use `elementwise_of%` instead of -- adding the corresponding lemma in `Scheme.lean` file erw [← elementwise_of% Scheme.comp_val_base] -- now `erw` after #13170 simp only [Scheme.Opens.toScheme_presheaf_obj, Category.assoc, ← Spec.map_comp_assoc, ← Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl, op_id, CategoryTheory.Functor.map_id, Spec.map_id, Category.id_comp, Iso.hom_inv_id_assoc] rfl -- `rfl` was not needed before #13170 theorem isLocalization_stalk' (y : PrimeSpectrum Γ(X, U)) (hy : hU.fromSpec.1.base y ∈ U) : @IsLocalization.AtPrime (R := Γ(X, U)) (S := X.presheaf.stalk <| hU.fromSpec.1.base y) _ _ ((TopCat.Presheaf.algebra_section_stalk X.presheaf _)) y.asIdeal _ := by apply (@IsLocalization.isLocalization_iff_of_ringEquiv (R := Γ(X, U)) (S := X.presheaf.stalk (hU.fromSpec.1.base y)) _ y.asIdeal.primeCompl _ (TopCat.Presheaf.algebra_section_stalk X.presheaf ⟨hU.fromSpec.1.base y, hy⟩) _ _ (asIso <| hU.fromSpec.stalkMap y).commRingCatIsoToRingEquiv).mpr -- Porting note: need to know what the ring is and after convert, instead of equality -- we get an `iff`. convert StructureSheaf.IsLocalization.to_stalk Γ(X, U) y using 1 delta IsLocalization.AtPrime StructureSheaf.stalkAlgebra rw [iff_iff_eq] congr 2 rw [RingHom.algebraMap_toAlgebra] refine (PresheafedSpace.stalkMap_germ hU.fromSpec.1 _ ⟨_, hy⟩).trans ?_ rw [← Scheme.Hom.app, IsAffineOpen.fromSpec_app_self, Category.assoc, TopCat.Presheaf.germ_res] rfl -- Porting note: I have split this into two lemmas theorem isLocalization_stalk (x : U) : IsLocalization.AtPrime (X.presheaf.stalk x) (hU.primeIdealOf x).asIdeal := by rcases x with ⟨x, hx⟩ set y := hU.primeIdealOf ⟨x, hx⟩ with hy have : hU.fromSpec.val.base y = x := hy ▸ hU.fromSpec_primeIdealOf ⟨x, hx⟩ clear_value y subst this exact hU.isLocalization_stalk' y hx /-- The basic open set of a section `f` on an affine open as an `X.affineOpens`. -/ @[simps] def _root_.AlgebraicGeometry.Scheme.affineBasicOpen (X : Scheme) {U : X.affineOpens} (f : Γ(X, U)) : X.affineOpens := ⟨X.basicOpen f, U.prop.basicOpen f⟩ /-- In an affine open set `U`, a family of basic open covers `U` iff the sections span `Γ(X, U)`. See `iSup_basicOpen_of_span_eq_top` for the inverse direction without the affine-ness assuption. -/ theorem basicOpen_union_eq_self_iff (s : Set Γ(X, U)) : ⨆ f : s, X.basicOpen (f : Γ(X, U)) = U ↔ Ideal.span s = ⊤ := by trans ⋃ i : s, (PrimeSpectrum.basicOpen i.1).1 = Set.univ · trans hU.fromSpec.1.base ⁻¹' (⨆ f : s, X.basicOpen (f : Γ(X, U))).1 = hU.fromSpec.1.base ⁻¹' U.1 · refine ⟨fun h => by rw [h], ?_⟩ intro h apply_fun Set.image hU.fromSpec.1.base at h rw [Set.image_preimage_eq_inter_range, Set.image_preimage_eq_inter_range, hU.range_fromSpec] at h simp only [Set.inter_self, Opens.carrier_eq_coe, Set.inter_eq_right] at h ext1 refine Set.Subset.antisymm ?_ h simp only [Set.iUnion_subset_iff, SetCoe.forall, Opens.coe_iSup] intro x _ exact X.basicOpen_le x · simp only [Opens.iSup_def, Subtype.coe_mk, Set.preimage_iUnion] congr! 1 · refine congr_arg (Set.iUnion ·) ?_ ext1 x exact congr_arg Opens.carrier (hU.fromSpec_preimage_basicOpen _) · exact congr_arg Opens.carrier hU.fromSpec_preimage_self · simp only [Opens.carrier_eq_coe, PrimeSpectrum.basicOpen_eq_zeroLocus_compl] rw [← Set.compl_iInter, Set.compl_univ_iff, ← PrimeSpectrum.zeroLocus_iUnion, ← PrimeSpectrum.zeroLocus_empty_iff_eq_top, PrimeSpectrum.zeroLocus_span] simp only [Set.iUnion_singleton_eq_range, Subtype.range_val_subtype, Set.setOf_mem_eq] theorem self_le_basicOpen_union_iff (s : Set Γ(X, U)) : (U ≤ ⨆ f : s, X.basicOpen f.1) ↔ Ideal.span s = ⊤ := by rw [← hU.basicOpen_union_eq_self_iff, @comm _ Eq] refine ⟨fun h => le_antisymm h ?_, le_of_eq⟩ simp only [iSup_le_iff, SetCoe.forall] intro x _ exact X.basicOpen_le x end IsAffineOpen /-- Given a spanning set of `Γ(X, U)`, the corresponding basic open sets cover `U`. See `IsAffineOpen.basicOpen_union_eq_self_iff` for the inverse direction for affine open sets. -/ lemma iSup_basicOpen_of_span_eq_top {X : Scheme} (U) (s : Set Γ(X, U)) (hs : Ideal.span s = ⊤) : (⨆ i ∈ s, X.basicOpen i) = U := by apply le_antisymm · rw [iSup₂_le_iff] exact fun i _ ↦ X.basicOpen_le i · intro x hx obtain ⟨_, ⟨V, hV, rfl⟩, hxV, hVU⟩ := (isBasis_affine_open X).exists_subset_of_mem_open hx U.2 refine SetLike.mem_of_subset ?_ hxV rw [← (hV.basicOpen_union_eq_self_iff (X.presheaf.map (homOfLE hVU).op '' s)).mpr (by rw [← Ideal.map_span, hs, Ideal.map_top])] simp only [Opens.iSup_mk, Opens.carrier_eq_coe, Set.iUnion_coe_set, Set.mem_image, Set.iUnion_exists, Set.biUnion_and', Set.iUnion_iUnion_eq_right, Scheme.basicOpen_res, Opens.coe_inf, Opens.coe_mk, Set.iUnion_subset_iff] exact fun i hi ↦ (Set.inter_subset_right.trans (Set.subset_iUnion₂ (s := fun x _ ↦ (X.basicOpen x : Set X)) i hi)) /-- Let `P` be a predicate on the affine open sets of `X` satisfying 1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`. 2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`. 3. There exists an affine open cover of `X` each satisfying `P`. Then `P` holds for every affine open of `X`. This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/ @[elab_as_elim] theorem of_affine_open_cover {X : Scheme} {P : X.affineOpens → Prop} {ι} (U : ι → X.affineOpens) (iSup_U : (⨆ i, U i : X.Opens) = ⊤) (V : X.affineOpens) (basicOpen : ∀ (U : X.affineOpens) (f : Γ(X, U)), P U → P (X.affineBasicOpen f)) (openCover : ∀ (U : X.affineOpens) (s : Finset (Γ(X, U))) (_ : Ideal.span (s : Set (Γ(X, U))) = ⊤), (∀ f : s, P (X.affineBasicOpen f.1)) → P U) (hU : ∀ i, P (U i)) : P V := by classical have : ∀ (x : V.1), ∃ f : Γ(X, V), ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by intro x obtain ⟨i, hi⟩ := Opens.mem_iSup.mp (show x.1 ∈ (⨆ i, U i : X.Opens) from iSup_U ▸ trivial) obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop (U i).prop x ⟨x.prop, hi⟩ refine ⟨f, hf, ?_⟩ convert basicOpen _ g (hU i) using 1 ext1 exact e choose f hf₁ hf₂ using this suffices Ideal.span (Set.range f) = ⊤ by obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this apply openCover V t ht₂ rintro ⟨i, hi⟩ obtain ⟨x, rfl⟩ := ht₁ hi exact hf₂ x rw [← V.prop.self_le_basicOpen_union_iff] intro x hx rw [iSup_range', SetLike.mem_coe, Opens.mem_iSup] exact ⟨_, hf₁ ⟨x, hx⟩⟩ section ZeroLocus /-- On a locally ringed space `X`, the preimage of the zero locus of the prime spectrum of `Γ(X, ⊤)` under `toΓSpecFun` agrees with the associated zero locus on `X`. -/ lemma Scheme.toΓSpec_preimage_zeroLocus_eq {X : Scheme.{u}} (s : Set Γ(X, ⊤)) : (ΓSpec.adjunction.unit.app X).val.base ⁻¹' PrimeSpectrum.zeroLocus s = X.zeroLocus s := LocallyRingedSpace.toΓSpec_preimage_zeroLocus_eq s open ConcreteCategory /-- If `X` is affine, the image of the zero locus of global sections of `X` under `toΓSpecFun` is the zero locus in terms of the prime spectrum of `Γ(X, ⊤)`. -/ lemma Scheme.toΓSpec_image_zeroLocus_eq_of_isAffine {X : Scheme.{u}} [IsAffine X] (s : Set Γ(X, ⊤)) : X.isoSpec.hom.val.base '' X.zeroLocus s = PrimeSpectrum.zeroLocus s := by erw [← X.toΓSpec_preimage_zeroLocus_eq, Set.image_preimage_eq] exact (bijective_of_isIso X.isoSpec.hom.val.base).surjective /-- If `X` is an affine scheme, every closed set of `X` is the zero locus of a set of global sections. -/ lemma Scheme.eq_zeroLocus_of_isClosed_of_isAffine (X : Scheme.{u}) [IsAffine X] (s : Set X) : IsClosed s ↔ ∃ I : Ideal (Γ(X, ⊤)), s = X.zeroLocus (I : Set Γ(X, ⊤)) := by refine ⟨fun hs ↦ ?_, ?_⟩ · let Z : Set (Spec <| Γ(X, ⊤)) := X.toΓSpecFun '' s have hZ : IsClosed Z := (X.isoSpec.hom.homeomorph).isClosedMap _ hs obtain ⟨I, (hI : Z = _)⟩ := (PrimeSpectrum.isClosed_iff_zeroLocus_ideal _).mp hZ use I simp only [← Scheme.toΓSpec_preimage_zeroLocus_eq, ← hI, Z] erw [Set.preimage_image_eq _ (bijective_of_isIso X.isoSpec.hom.val.base).injective] · rintro ⟨I, rfl⟩ exact zeroLocus_isClosed X I.carrier end ZeroLocus section Stalks /-- Variant of `AlgebraicGeometry.localRingHom_comp_stalkIso` for `Spec.map`. -/ @[elementwise] lemma Scheme.localRingHom_comp_stalkIso {R S : CommRingCat.{u}} (f : R ⟶ S) (p : PrimeSpectrum S) : (StructureSheaf.stalkIso R (PrimeSpectrum.comap f p)).hom ≫ (CommRingCat.ofHom <| Localization.localRingHom (PrimeSpectrum.comap f p).asIdeal p.asIdeal f rfl) ≫ (StructureSheaf.stalkIso S p).inv = (Spec.map f).stalkMap p := AlgebraicGeometry.localRingHom_comp_stalkIso f p /-- Given a morphism of rings `f : R ⟶ S`, the stalk map of `Spec S ⟶ Spec R` at a prime of `S` is isomorphic to the localized ring homomorphism. -/ def Scheme.arrowStalkMapSpecIso {R S : CommRingCat.{u}} (f : R ⟶ S) (p : PrimeSpectrum S) : Arrow.mk ((Spec.map f).stalkMap p) ≅ Arrow.mk (CommRingCat.ofHom <| Localization.localRingHom (PrimeSpectrum.comap f p).asIdeal p.asIdeal f rfl) := Arrow.isoMk (StructureSheaf.stalkIso R (PrimeSpectrum.comap f p)) (StructureSheaf.stalkIso S p) <| by rw [← Scheme.localRingHom_comp_stalkIso] simp end Stalks @[deprecated (since := "2024-06-21"), nolint defLemma] alias isAffineAffineScheme := isAffine_affineScheme @[deprecated (since := "2024-06-21"), nolint defLemma] alias SpecIsAffine := isAffine_Spec @[deprecated (since := "2024-06-21")] alias isAffineOfIso := isAffine_of_isIso @[deprecated (since := "2024-06-21")] alias rangeIsAffineOpenOfOpenImmersion := isAffineOpen_opensRange @[deprecated (since := "2024-06-21")] alias topIsAffineOpen := isAffineOpen_top @[deprecated (since := "2024-06-21"), nolint defLemma] alias Scheme.affineCoverIsAffine := Scheme.isAffine_affineCover @[deprecated (since := "2024-06-21"), nolint defLemma] alias Scheme.affineBasisCoverIsAffine := Scheme.isAffine_affineBasisCover @[deprecated (since := "2024-06-21")] alias IsAffineOpen.fromSpec_range := IsAffineOpen.range_fromSpec @[deprecated (since := "2024-06-21")] alias IsAffineOpen.imageIsOpenImmersion := IsAffineOpen.image_of_isOpenImmersion @[deprecated (since := "2024-06-21"), nolint defLemma] alias Scheme.quasi_compact_of_affine := Scheme.compactSpace_of_isAffine @[deprecated (since := "2024-06-21")] alias IsAffineOpen.fromSpec_base_preimage := IsAffineOpen.fromSpec_preimage_self @[deprecated (since := "2024-06-21")] alias IsAffineOpen.fromSpec_map_basicOpen' := IsAffineOpen.fromSpec_preimage_basicOpen' @[deprecated (since := "2024-06-21")] alias IsAffineOpen.fromSpec_map_basicOpen := IsAffineOpen.fromSpec_preimage_basicOpen @[deprecated (since := "2024-06-21")] alias IsAffineOpen.opensFunctor_map_basicOpen := IsAffineOpen.fromSpec_image_basicOpen @[deprecated (since := "2024-06-21")] alias IsAffineOpen.basicOpenIsAffine := IsAffineOpen.basicOpen @[deprecated (since := "2024-06-21")] alias IsAffineOpen.mapRestrictBasicOpen := IsAffineOpen.ι_basicOpen_preimage end AlgebraicGeometry
AlgebraicGeometry\FunctionField.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Properties /-! # Function field of integral schemes We define the function field of an irreducible scheme as the stalk of the generic point. This is a field when the scheme is integral. ## Main definition * `AlgebraicGeometry.Scheme.functionField`: The function field of an integral scheme. * `AlgebraicGeometry.Scheme.germToFunctionField`: The canonical map from a component into the function field. This map is injective. -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 universe u v open TopologicalSpace Opposite CategoryTheory CategoryTheory.Limits TopCat namespace AlgebraicGeometry variable (X : Scheme) /-- The function field of an irreducible scheme is the local ring at its generic point. Despite the name, this is a field only when the scheme is integral. -/ noncomputable abbrev Scheme.functionField [IrreducibleSpace X] : CommRingCat := X.presheaf.stalk (genericPoint X) /-- The restriction map from a component to the function field. -/ noncomputable abbrev Scheme.germToFunctionField [IrreducibleSpace X] (U : X.Opens) [h : Nonempty U] : Γ(X, U) ⟶ X.functionField := X.presheaf.germ ⟨genericPoint X, ((genericPoint_spec X).mem_open_set_iff U.isOpen).mpr (by simpa using h)⟩ noncomputable instance [IrreducibleSpace X] (U : X.Opens) [Nonempty U] : Algebra Γ(X, U) X.functionField := (X.germToFunctionField U).toAlgebra noncomputable instance [IsIntegral X] : Field X.functionField := by refine .ofIsUnitOrEqZero fun a ↦ ?_ obtain ⟨U, m, s, rfl⟩ := TopCat.Presheaf.germ_exist _ _ a rw [or_iff_not_imp_right, ← (X.presheaf.germ ⟨_, m⟩).map_zero] intro ha replace ha := ne_of_apply_ne _ ha have hs : genericPoint X ∈ RingedSpace.basicOpen _ s := by rw [← SetLike.mem_coe, (genericPoint_spec X).mem_open_set_iff, Set.top_eq_univ, Set.univ_inter, Set.nonempty_iff_ne_empty, Ne, ← Opens.coe_bot, ← SetLike.ext'_iff] · erw [basicOpen_eq_bot_iff] exact ha · exact (RingedSpace.basicOpen _ _).isOpen have := (X.presheaf.germ ⟨_, hs⟩).isUnit_map (RingedSpace.isUnit_res_basicOpen _ s) rwa [TopCat.Presheaf.germ_res_apply] at this theorem germ_injective_of_isIntegral [IsIntegral X] {U : X.Opens} (x : U) : Function.Injective (X.presheaf.germ x) := by rw [injective_iff_map_eq_zero] intro y hy rw [← (X.presheaf.germ x).map_zero] at hy obtain ⟨W, hW, iU, iV, e⟩ := X.presheaf.germ_eq _ x.prop x.prop _ _ hy cases Subsingleton.elim iU iV haveI : Nonempty W := ⟨⟨_, hW⟩⟩ exact map_injective_of_isIntegral X iU e theorem Scheme.germToFunctionField_injective [IsIntegral X] (U : X.Opens) [Nonempty U] : Function.Injective (X.germToFunctionField U) := germ_injective_of_isIntegral _ _ theorem genericPoint_eq_of_isOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f] [hX : IrreducibleSpace X] [IrreducibleSpace Y] : f.1.base (genericPoint X) = genericPoint Y := by apply ((genericPoint_spec Y).eq _).symm convert (genericPoint_spec X).image (show Continuous f.1.base by fun_prop) symm rw [eq_top_iff, Set.top_eq_univ, Set.top_eq_univ] convert subset_closure_inter_of_isPreirreducible_of_isOpen _ H.base_open.isOpen_range _ · rw [Set.univ_inter, Set.image_univ] · apply PreirreducibleSpace.isPreirreducible_univ (X := Y) · exact ⟨_, trivial, Set.mem_range_self hX.2.some⟩ noncomputable instance stalkFunctionFieldAlgebra [IrreducibleSpace X] (x : X) : Algebra (X.presheaf.stalk x) X.functionField := by apply RingHom.toAlgebra exact X.presheaf.stalkSpecializes ((genericPoint_spec X).specializes trivial) instance functionField_isScalarTower [IrreducibleSpace X] (U : X.Opens) (x : U) [Nonempty U] : IsScalarTower Γ(X, U) (X.presheaf.stalk x) X.functionField := by apply IsScalarTower.of_algebraMap_eq' simp_rw [RingHom.algebraMap_toAlgebra] change _ = X.presheaf.germ x ≫ _ rw [X.presheaf.germ_stalkSpecializes] noncomputable instance (R : CommRingCat.{u}) [IsDomain R] : Algebra R (Spec R).functionField := RingHom.toAlgebra <| by change CommRingCat.of R ⟶ _; apply StructureSheaf.toStalk @[simp] theorem genericPoint_eq_bot_of_affine (R : CommRingCat) [IsDomain R] : genericPoint (Spec R) = (⊥ : PrimeSpectrum R) := by apply (genericPoint_spec (Spec R)).eq rw [isGenericPoint_def] rw [← PrimeSpectrum.zeroLocus_vanishingIdeal_eq_closure, PrimeSpectrum.vanishingIdeal_singleton] rw [Set.top_eq_univ, ← PrimeSpectrum.zeroLocus_singleton_zero] rfl instance functionField_isFractionRing_of_affine (R : CommRingCat.{u}) [IsDomain R] : IsFractionRing R (Spec R).functionField := by convert StructureSheaf.IsLocalization.to_stalk R (genericPoint (Spec R)) delta IsFractionRing IsLocalization.AtPrime -- Porting note: `congr` does not work for `Iff` apply Eq.to_iff congr 1 rw [genericPoint_eq_bot_of_affine] ext exact mem_nonZeroDivisors_iff_ne_zero instance {X : Scheme} [IsIntegral X] {U : X.Opens} [Nonempty U] : IsIntegral U := isIntegral_of_isOpenImmersion U.ι theorem IsAffineOpen.primeIdealOf_genericPoint {X : Scheme} [IsIntegral X] {U : X.Opens} (hU : IsAffineOpen U) [h : Nonempty U] : hU.primeIdealOf ⟨genericPoint X, ((genericPoint_spec X).mem_open_set_iff U.isOpen).mpr (by simpa using h)⟩ = genericPoint (Spec Γ(X, U)) := by haveI : IsAffine _ := hU delta IsAffineOpen.primeIdealOf convert genericPoint_eq_of_isOpenImmersion (U.toScheme.isoSpec.hom ≫ Spec.map (X.presheaf.map (eqToHom U.openEmbedding_obj_top).op)) -- Porting note: this was `ext1` apply Subtype.ext exact (genericPoint_eq_of_isOpenImmersion U.ι).symm theorem functionField_isFractionRing_of_isAffineOpen [IsIntegral X] (U : X.Opens) (hU : IsAffineOpen U) [Nonempty U] : IsFractionRing Γ(X, U) X.functionField := by haveI : IsAffine _ := hU haveI : IsIntegral U := @isIntegral_of_isAffine_of_isDomain _ _ _ (by rw [Scheme.Opens.toScheme_presheaf_obj, Opens.openEmbedding_obj_top]; infer_instance) delta IsFractionRing Scheme.functionField convert hU.isLocalization_stalk ⟨genericPoint X, _⟩ using 1 rw [hU.primeIdealOf_genericPoint, genericPoint_eq_bot_of_affine] ext; exact mem_nonZeroDivisors_iff_ne_zero instance (x : X) : IsAffine (X.affineCover.obj x) := AlgebraicGeometry.isAffine_Spec _ instance [IsIntegral X] (x : X) : IsFractionRing (X.presheaf.stalk x) X.functionField := let U : X.Opens := (X.affineCover.map x).opensRange have hU : IsAffineOpen U := isAffineOpen_opensRange (X.affineCover.map x) let x : U := ⟨x, X.affineCover.covers x⟩ have : Nonempty U := ⟨x⟩ let M := (hU.primeIdealOf x).asIdeal.primeCompl have := hU.isLocalization_stalk x have := functionField_isFractionRing_of_isAffineOpen X U hU -- Porting note: the following two lines were not needed. let _hA := Presheaf.algebra_section_stalk X.presheaf x have := functionField_isScalarTower X U x .isFractionRing_of_isDomain_of_isLocalization M ↑(Presheaf.stalk X.presheaf x) (Scheme.functionField X) end AlgebraicGeometry
AlgebraicGeometry\GammaSpecAdjunction.lean
/- Copyright (c) 2021 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.AlgebraicGeometry.Restrict import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Adjunction.Reflective /-! # Adjunction between `Γ` and `Spec` We define the adjunction `ΓSpec.adjunction : Γ ⊣ Spec` by defining the unit (`toΓSpec`, in multiple steps in this file) and counit (done in `Spec.lean`) and checking that they satisfy the left and right triangle identities. The constructions and proofs make use of maps and lemmas defined and proved in structure_sheaf.lean extensively. Notice that since the adjunction is between contravariant functors, you get to choose one of the two categories to have arrows reversed, and it is equally valid to present the adjunction as `Spec ⊣ Γ` (`Spec.to_LocallyRingedSpace.right_op ⊣ Γ`), in which case the unit and the counit would switch to each other. ## Main definition * `AlgebraicGeometry.identityToΓSpec` : The natural transformation `𝟭 _ ⟶ Γ ⋙ Spec`. * `AlgebraicGeometry.ΓSpec.locallyRingedSpaceAdjunction` : The adjunction `Γ ⊣ Spec` from `CommRingᵒᵖ` to `LocallyRingedSpace`. * `AlgebraicGeometry.ΓSpec.adjunction` : The adjunction `Γ ⊣ Spec` from `CommRingᵒᵖ` to `Scheme`. -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 noncomputable section universe u open PrimeSpectrum namespace AlgebraicGeometry open Opposite open CategoryTheory open StructureSheaf open Spec (structureSheaf) open TopologicalSpace open AlgebraicGeometry.LocallyRingedSpace open TopCat.Presheaf open TopCat.Presheaf.SheafCondition namespace LocallyRingedSpace variable (X : LocallyRingedSpace.{u}) /-- The canonical map from the underlying set to the prime spectrum of `Γ(X)`. -/ def toΓSpecFun : X → PrimeSpectrum (Γ.obj (op X)) := fun x => comap (X.presheaf.Γgerm x) (LocalRing.closedPoint (X.presheaf.stalk x)) theorem not_mem_prime_iff_unit_in_stalk (r : Γ.obj (op X)) (x : X) : r ∉ (X.toΓSpecFun x).asIdeal ↔ IsUnit (X.presheaf.Γgerm x r) := by erw [LocalRing.mem_maximalIdeal, Classical.not_not] /-- The preimage of a basic open in `Spec Γ(X)` under the unit is the basic open in `X` defined by the same element (they are equal as sets). -/ theorem toΓSpec_preimage_basicOpen_eq (r : Γ.obj (op X)) : X.toΓSpecFun ⁻¹' (basicOpen r).1 = (X.toRingedSpace.basicOpen r).1 := by ext erw [X.toRingedSpace.mem_top_basicOpen]; apply not_mem_prime_iff_unit_in_stalk /-- `toΓSpecFun` is continuous. -/ theorem toΓSpec_continuous : Continuous X.toΓSpecFun := by rw [isTopologicalBasis_basic_opens.continuous_iff] rintro _ ⟨r, rfl⟩ erw [X.toΓSpec_preimage_basicOpen_eq r] exact (X.toRingedSpace.basicOpen r).2 /-- The canonical (bundled) continuous map from the underlying topological space of `X` to the prime spectrum of its global sections. -/ @[simps] def toΓSpecBase : X.toTopCat ⟶ Spec.topObj (Γ.obj (op X)) where toFun := X.toΓSpecFun continuous_toFun := X.toΓSpec_continuous -- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing attribute [nolint simpNF] AlgebraicGeometry.LocallyRingedSpace.toΓSpecBase_apply variable (r : Γ.obj (op X)) /-- The preimage in `X` of a basic open in `Spec Γ(X)` (as an open set). -/ abbrev toΓSpecMapBasicOpen : Opens X := (Opens.map X.toΓSpecBase).obj (basicOpen r) /-- The preimage is the basic open in `X` defined by the same element `r`. -/ theorem toΓSpecMapBasicOpen_eq : X.toΓSpecMapBasicOpen r = X.toRingedSpace.basicOpen r := Opens.ext (X.toΓSpec_preimage_basicOpen_eq r) /-- The map from the global sections `Γ(X)` to the sections on the (preimage of) a basic open. -/ abbrev toToΓSpecMapBasicOpen : X.presheaf.obj (op ⊤) ⟶ X.presheaf.obj (op <| X.toΓSpecMapBasicOpen r) := X.presheaf.map (X.toΓSpecMapBasicOpen r).leTop.op /-- `r` is a unit as a section on the basic open defined by `r`. -/ theorem isUnit_res_toΓSpecMapBasicOpen : IsUnit (X.toToΓSpecMapBasicOpen r r) := by convert (X.presheaf.map <| (eqToHom <| X.toΓSpecMapBasicOpen_eq r).op).isUnit_map (X.toRingedSpace.isUnit_res_basicOpen r) -- Porting note: `rw [comp_apply]` to `erw [comp_apply]` erw [← comp_apply, ← Functor.map_comp] congr /-- Define the sheaf hom on individual basic opens for the unit. -/ def toΓSpecCApp : (structureSheaf <| Γ.obj <| op X).val.obj (op <| basicOpen r) ⟶ X.presheaf.obj (op <| X.toΓSpecMapBasicOpen r) := IsLocalization.Away.lift r (isUnit_res_toΓSpecMapBasicOpen _ r) /-- Characterization of the sheaf hom on basic opens, direction ← (next lemma) is used at various places, but → is not used in this file. -/ theorem toΓSpecCApp_iff (f : (structureSheaf <| Γ.obj <| op X).val.obj (op <| basicOpen r) ⟶ X.presheaf.obj (op <| X.toΓSpecMapBasicOpen r)) : toOpen _ (basicOpen r) ≫ f = X.toToΓSpecMapBasicOpen r ↔ f = X.toΓSpecCApp r := by -- Porting Note: Type class problem got stuck in `IsLocalization.Away.AwayMap.lift_comp` -- created instance manually. This replaces the `pick_goal` tactics have loc_inst := IsLocalization.to_basicOpen (Γ.obj (op X)) r rw [← @IsLocalization.Away.AwayMap.lift_comp _ _ _ _ _ _ _ r loc_inst _ (X.isUnit_res_toΓSpecMapBasicOpen r)] --pick_goal 5; exact is_localization.to_basic_open _ r constructor · intro h exact IsLocalization.ringHom_ext (Submonoid.powers r) h apply congr_arg theorem toΓSpecCApp_spec : toOpen _ (basicOpen r) ≫ X.toΓSpecCApp r = X.toToΓSpecMapBasicOpen r := (X.toΓSpecCApp_iff r _).2 rfl /-- The sheaf hom on all basic opens, commuting with restrictions. -/ @[simps app] def toΓSpecCBasicOpens : (inducedFunctor basicOpen).op ⋙ (structureSheaf (Γ.obj (op X))).1 ⟶ (inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward _ X.toΓSpecBase).obj X.𝒪).1 where app r := X.toΓSpecCApp r.unop naturality r s f := by apply (StructureSheaf.to_basicOpen_epi (Γ.obj (op X)) r.unop).1 simp only [← Category.assoc] erw [X.toΓSpecCApp_spec r.unop] convert X.toΓSpecCApp_spec s.unop symm apply X.presheaf.map_comp /-- The canonical morphism of sheafed spaces from `X` to the spectrum of its global sections. -/ @[simps] def toΓSpecSheafedSpace : X.toSheafedSpace ⟶ Spec.toSheafedSpace.obj (op (Γ.obj (op X))) where base := X.toΓSpecBase c := TopCat.Sheaf.restrictHomEquivHom (structureSheaf (Γ.obj (op X))).1 _ isBasis_basic_opens X.toΓSpecCBasicOpens theorem toΓSpecSheafedSpace_app_eq : X.toΓSpecSheafedSpace.c.app (op (basicOpen r)) = X.toΓSpecCApp r := by apply TopCat.Sheaf.extend_hom_app _ _ _ -- Porting note: need a helper lemma `toΓSpecSheafedSpace_app_spec_assoc` to help compile -- `toStalk_stalkMap_to_Γ_Spec` @[reassoc] theorem toΓSpecSheafedSpace_app_spec (r : Γ.obj (op X)) : toOpen (Γ.obj (op X)) (basicOpen r) ≫ X.toΓSpecSheafedSpace.c.app (op (basicOpen r)) = X.toToΓSpecMapBasicOpen r := (X.toΓSpecSheafedSpace_app_eq r).symm ▸ X.toΓSpecCApp_spec r /-- The map on stalks induced by the unit commutes with maps from `Γ(X)` to stalks (in `Spec Γ(X)` and in `X`). -/ theorem toStalk_stalkMap_toΓSpec (x : X) : toStalk _ _ ≫ X.toΓSpecSheafedSpace.stalkMap x = X.presheaf.Γgerm x := by rw [PresheafedSpace.Hom.stalkMap] erw [← toOpen_germ _ (basicOpen (1 : Γ.obj (op X))) ⟨X.toΓSpecFun x, by rw [basicOpen_one]; trivial⟩] rw [← Category.assoc, Category.assoc (toOpen _ _)] erw [stalkFunctor_map_germ] rw [← Category.assoc, toΓSpecSheafedSpace_app_spec, Γgerm] rw [← stalkPushforward_germ _ X.toΓSpecBase X.presheaf ⊤] congr 1 change (X.toΓSpecBase _* X.presheaf).map le_top.hom.op ≫ _ = _ apply germ_res /-- The canonical morphism from `X` to the spectrum of its global sections. -/ @[simps! val_base] def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where val := X.toΓSpecSheafedSpace prop := by intro x let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x constructor -- show stalk map is local hom ↓ let S := (structureSheaf _).presheaf.stalk p rintro (t : S) ht obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t dsimp at he set t' := _ change t * t' = _ at he apply isUnit_of_mul_isUnit_left (y := t') rw [he] refine IsLocalization.map_units S (⟨r, ?_⟩ : p.asIdeal.primeCompl) apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr rw [← toStalk_stalkMap_toΓSpec] erw [comp_apply, ← he] rw [RingHom.map_mul] exact ht.mul <| (IsLocalization.map_units (R := Γ.obj (op X)) S s).map _ /-- On a locally ringed space `X`, the preimage of the zero locus of the prime spectrum of `Γ(X, ⊤)` under `toΓSpec` agrees with the associated zero locus on `X`. -/ lemma toΓSpec_preimage_zeroLocus_eq {X : LocallyRingedSpace.{u}} (s : Set (X.presheaf.obj (op ⊤))) : X.toΓSpec.val.base ⁻¹' PrimeSpectrum.zeroLocus s = X.toRingedSpace.zeroLocus s := by simp only [RingedSpace.zeroLocus] have (i : LocallyRingedSpace.Γ.obj (op X)) (_ : i ∈ s) : ((X.toRingedSpace.basicOpen i).carrier)ᶜ = X.toΓSpec.val.base ⁻¹' (PrimeSpectrum.basicOpen i).carrierᶜ := by symm erw [Set.preimage_compl, X.toΓSpec_preimage_basicOpen_eq i] erw [Set.iInter₂_congr this] simp_rw [← Set.preimage_iInter₂, Opens.carrier_eq_coe, PrimeSpectrum.basicOpen_eq_zeroLocus_compl, compl_compl] rw [← PrimeSpectrum.zeroLocus_iUnion₂] simp theorem comp_ring_hom_ext {X : LocallyRingedSpace.{u}} {R : CommRingCat.{u}} {f : R ⟶ Γ.obj (op X)} {β : X ⟶ Spec.locallyRingedSpaceObj R} (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base) (h : ∀ r : R, f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op = toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) : X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by ext1 -- Porting note: was `apply Spec.basicOpen_hom_ext` refine Spec.basicOpen_hom_ext w ?_ intro r U rw [LocallyRingedSpace.comp_val_c_app] erw [toOpen_comp_comap_assoc] rw [Category.assoc] erw [toΓSpecSheafedSpace_app_spec, ← X.presheaf.map_comp] exact h r /-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/ theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by unfold toSpecΓ rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)] erw [Category.assoc] rw [NatTrans.naturality, ← Category.assoc] erw [X.toΓSpecSheafedSpace_app_spec 1, ← Functor.map_comp] convert eqToHom_map X.presheaf _; rfl end LocallyRingedSpace /-- The unit as a natural transformation. -/ def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where app := LocallyRingedSpace.toΓSpec naturality X Y f := by symm apply LocallyRingedSpace.comp_ring_hom_ext · ext1 x dsimp only [Spec.topMap, LocallyRingedSpace.toΓSpecFun] -- Porting note: Had to add the next four lines rw [comp_apply] dsimp [toΓSpecBase] -- The next six lines were `rw [ContinuousMap.coe_mk, ContinuousMap.coe_mk]` before -- leanprover/lean4#2644 have : (ContinuousMap.mk (toΓSpecFun Y) (toΓSpec_continuous _)) (f.val.base x) = toΓSpecFun Y (f.val.base x) := by rw [ContinuousMap.coe_mk] erw [this] have : (ContinuousMap.mk (toΓSpecFun X) (toΓSpec_continuous _)) x = toΓSpecFun X x := by rw [ContinuousMap.coe_mk] erw [this] dsimp [toΓSpecFun] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← LocalRing.comap_closedPoint (f.stalkMap x), ← PrimeSpectrum.comap_comp_apply, ← PrimeSpectrum.comap_comp_apply] congr 2 exact (PresheafedSpace.stalkMap_germ f.1 ⊤ ⟨x, trivial⟩).symm · intro r rw [LocallyRingedSpace.comp_val_c_app, ← Category.assoc] erw [Y.toΓSpecSheafedSpace_app_spec, f.1.c.naturality] rfl namespace ΓSpec theorem left_triangle (X : LocallyRingedSpace) : SpecΓIdentity.inv.app (Γ.obj (op X)) ≫ (identityToΓSpec.app X).val.c.app (op ⊤) = 𝟙 _ := X.Γ_Spec_left_triangle /-- `SpecΓIdentity` is iso so these are mutually two-sided inverses. -/ theorem right_triangle (R : CommRingCat) : identityToΓSpec.app (Spec.toLocallyRingedSpace.obj <| op R) ≫ Spec.toLocallyRingedSpace.map (SpecΓIdentity.inv.app R).op = 𝟙 _ := by apply LocallyRingedSpace.comp_ring_hom_ext · ext (p : PrimeSpectrum R) dsimp ext x erw [← IsLocalization.AtPrime.to_map_mem_maximal_iff ((structureSheaf R).presheaf.stalk p) p.asIdeal x] rfl · intro r; apply toOpen_res /-- The adjunction `Γ ⊣ Spec` from `CommRingᵒᵖ` to `LocallyRingedSpace`. -/ -- Porting note: `simps` cause a time out, so `Unit` and `counit` will be added manually def locallyRingedSpaceAdjunction : Γ.rightOp ⊣ Spec.toLocallyRingedSpace.{u} := Adjunction.mkOfUnitCounit { unit := identityToΓSpec counit := (NatIso.op SpecΓIdentity).inv left_triangle := by ext X; erw [Category.id_comp] exact congr_arg Quiver.Hom.op (left_triangle X) right_triangle := by ext R : 2 -- Porting note: a little bit hand holding change identityToΓSpec.app _ ≫ 𝟙 _ ≫ Spec.toLocallyRingedSpace.map _ = 𝟙 _ simp_rw [Category.id_comp, show (NatIso.op SpecΓIdentity).inv.app R = (SpecΓIdentity.inv.app R.unop).op from rfl] exact right_triangle R.unop } lemma locallyRingedSpaceAdjunction_unit : locallyRingedSpaceAdjunction.unit = identityToΓSpec := rfl lemma locallyRingedSpaceAdjunction_counit : locallyRingedSpaceAdjunction.counit = (NatIso.op SpecΓIdentity.{u}).inv := rfl @[simp] lemma locallyRingedSpaceAdjunction_counit_app (R : CommRingCatᵒᵖ) : locallyRingedSpaceAdjunction.counit.app R = (toOpen R.unop ⊤).op := rfl @[simp] lemma locallyRingedSpaceAdjunction_counit_app' (R : Type u) [CommRing R] : locallyRingedSpaceAdjunction.counit.app (op <| CommRingCat.of R) = (toOpen R ⊤).op := rfl lemma locallyRingedSpaceAdjunction_homEquiv_apply {X : LocallyRingedSpace} {R : CommRingCatᵒᵖ} (f : Γ.rightOp.obj X ⟶ R) : locallyRingedSpaceAdjunction.homEquiv X R f = identityToΓSpec.app X ≫ Spec.locallyRingedSpaceMap f.unop := rfl lemma locallyRingedSpaceAdjunction_homEquiv_apply' {X : LocallyRingedSpace} {R : Type u} [CommRing R] (f : CommRingCat.of R ⟶ Γ.obj <| op X) : locallyRingedSpaceAdjunction.homEquiv X (op <| CommRingCat.of R) (op f) = identityToΓSpec.app X ≫ Spec.locallyRingedSpaceMap f := rfl lemma toOpen_comp_locallyRingedSpaceAdjunction_homEquiv_app {X : LocallyRingedSpace} {R : Type u} [CommRing R] (f : Γ.rightOp.obj X ⟶ op (CommRingCat.of R)) (U) : StructureSheaf.toOpen R U.unop ≫ (locallyRingedSpaceAdjunction.homEquiv X (op <| CommRingCat.of R) f).1.c.app U = f.unop ≫ X.presheaf.map (homOfLE le_top).op := by rw [← StructureSheaf.toOpen_res _ _ _ (homOfLE le_top), Category.assoc, NatTrans.naturality _ (homOfLE (le_top (a := U.unop))).op, show (toOpen R ⊤) = (toOpen R ⊤).op.unop from rfl, ← locallyRingedSpaceAdjunction_counit_app'] simp_rw [← Γ_map_op] rw [← Γ.rightOp_map_unop, ← Category.assoc, ← unop_comp, ← Adjunction.homEquiv_counit, Equiv.symm_apply_apply] rfl /-- The adjunction `Γ ⊣ Spec` from `CommRingᵒᵖ` to `Scheme`. -/ def adjunction : Scheme.Γ.rightOp ⊣ Scheme.Spec.{u} where homEquiv X Y := locallyRingedSpaceAdjunction.{u}.homEquiv X.toLocallyRingedSpace Y unit := { app := fun X ↦ locallyRingedSpaceAdjunction.{u}.unit.app X.toLocallyRingedSpace naturality := fun _ _ f ↦ locallyRingedSpaceAdjunction.{u}.unit.naturality f } counit := (NatIso.op Scheme.SpecΓIdentity.{u}).inv homEquiv_unit := rfl homEquiv_counit := rfl theorem adjunction_homEquiv_apply {X : Scheme} {R : CommRingCatᵒᵖ} (f : (op <| Scheme.Γ.obj <| op X) ⟶ R) : ΓSpec.adjunction.homEquiv X R f = locallyRingedSpaceAdjunction.homEquiv X.1 R f := rfl theorem adjunction_homEquiv (X : Scheme) (R : CommRingCatᵒᵖ) : ΓSpec.adjunction.homEquiv X R = locallyRingedSpaceAdjunction.homEquiv X.1 R := rfl theorem adjunction_homEquiv_symm_apply {X : Scheme} {R : CommRingCatᵒᵖ} (f : X ⟶ Scheme.Spec.obj R) : (ΓSpec.adjunction.homEquiv X R).symm f = (locallyRingedSpaceAdjunction.homEquiv X.1 R).symm f := rfl theorem adjunction_counit_app' {R : CommRingCatᵒᵖ} : ΓSpec.adjunction.counit.app R = locallyRingedSpaceAdjunction.counit.app R := rfl @[simp] theorem adjunction_counit_app {R : CommRingCatᵒᵖ} : ΓSpec.adjunction.counit.app R = (Scheme.ΓSpecIso (unop R)).inv.op := rfl -- This is not a simp lemma to respect the abstraction theorem adjunction_unit_app {X : Scheme} : ΓSpec.adjunction.unit.app X = locallyRingedSpaceAdjunction.unit.app X.1 := rfl @[reassoc (attr := simp)] theorem adjunction_unit_naturality {X Y : Scheme.{u}} (f : X ⟶ Y) : f ≫ ΓSpec.adjunction.unit.app Y = ΓSpec.adjunction.unit.app X ≫ Spec.map (f.app ⊤) := ΓSpec.adjunction.unit.naturality f instance isIso_locallyRingedSpaceAdjunction_counit : IsIso.{u + 1, u + 1} locallyRingedSpaceAdjunction.counit := (NatIso.op SpecΓIdentity).isIso_inv instance isIso_adjunction_counit : IsIso ΓSpec.adjunction.counit := by apply (config := { allowSynthFailures := true }) NatIso.isIso_of_isIso_app intro R rw [adjunction_counit_app] infer_instance @[simp] theorem adjunction_unit_app_app_top (X : Scheme.{u}) : (ΓSpec.adjunction.unit.app X).app ⊤ = (Scheme.ΓSpecIso Γ(X, ⊤)).hom := by have := ΓSpec.adjunction.left_triangle_components X dsimp at this rw [← IsIso.eq_comp_inv] at this simp only [adjunction_counit_app, Functor.id_obj, Functor.comp_obj, Functor.rightOp_obj, Scheme.Γ_obj, Category.id_comp] at this rw [← Quiver.Hom.op_inj.eq_iff, this, ← op_inv, IsIso.Iso.inv_inv] @[simp] theorem SpecMap_ΓSpecIso_hom (R : CommRingCat.{u}) : Spec.map ((Scheme.ΓSpecIso R).hom) = adjunction.unit.app (Spec R) := by have := ΓSpec.adjunction.right_triangle_components (op R) dsimp at this rwa [← IsIso.eq_comp_inv, Category.id_comp, ← Spec.map_inv, IsIso.Iso.inv_inv, eq_comm] at this lemma adjunction_unit_map_basicOpen (X : Scheme.{u}) (r : Γ(X, ⊤)) : (ΓSpec.adjunction.unit.app X ⁻¹ᵁ (PrimeSpectrum.basicOpen r)) = X.basicOpen r := by rw [← basicOpen_eq_of_affine] erw [Scheme.preimage_basicOpen] congr rw [ΓSpec.adjunction_unit_app_app_top] exact Iso.inv_hom_id_apply _ _ theorem toOpen_unit_app_val_c_app {X : Scheme.{u}} (U) : StructureSheaf.toOpen _ _ ≫ (ΓSpec.adjunction.unit.app X).val.c.app U = X.presheaf.map (homOfLE (by exact le_top)).op := by rw [← StructureSheaf.toOpen_res _ _ _ (homOfLE le_top), Category.assoc, NatTrans.naturality _ (homOfLE (le_top (a := U.unop))).op] show (ΓSpec.adjunction.counit.app (Scheme.Γ.rightOp.obj X)).unop ≫ (Scheme.Γ.rightOp.map (ΓSpec.adjunction.unit.app X)).unop ≫ _ = _ rw [← Category.assoc, ← unop_comp, ΓSpec.adjunction.left_triangle_components] dsimp exact Category.id_comp _ -- Warning: this LHS of this lemma breaks the structure-sheaf abstraction. @[reassoc (attr := simp)] theorem toOpen_unit_app_val_c_app' {X : Scheme.{u}} (U : Opens (PrimeSpectrum Γ(X, ⊤))) : toOpen Γ(X, ⊤) U ≫ (adjunction.unit.app X).app U = X.presheaf.map (homOfLE (by exact le_top)).op := ΓSpec.toOpen_unit_app_val_c_app (op U) end ΓSpec theorem ΓSpecIso_obj_hom {X : Scheme.{u}} (U : X.Opens) : (Scheme.ΓSpecIso Γ(X, U)).hom = (Spec.map U.topIso.inv).app ⊤ ≫ (ΓSpec.adjunction.unit.app U).app ⊤ ≫ U.topIso.hom := by rw [ΓSpec.adjunction_unit_app_app_top] -- why can't simp find this simp /-! Immediate consequences of the adjunction. -/ /-- Spec preserves limits. -/ instance : Limits.PreservesLimits Spec.toLocallyRingedSpace := ΓSpec.locallyRingedSpaceAdjunction.rightAdjointPreservesLimits instance Spec.preservesLimits : Limits.PreservesLimits Scheme.Spec := ΓSpec.adjunction.rightAdjointPreservesLimits /-- The functor `Spec.toLocallyRingedSpace : CommRingCatᵒᵖ ⥤ LocallyRingedSpace` is fully faithful.-/ def Spec.fullyFaithfulToLocallyRingedSpace : Spec.toLocallyRingedSpace.FullyFaithful := ΓSpec.locallyRingedSpaceAdjunction.fullyFaithfulROfIsIsoCounit /-- Spec is a full functor. -/ instance : Spec.toLocallyRingedSpace.Full := Spec.fullyFaithfulToLocallyRingedSpace.full /-- Spec is a faithful functor. -/ instance : Spec.toLocallyRingedSpace.Faithful := Spec.fullyFaithfulToLocallyRingedSpace.faithful /-- The functor `Spec : CommRingCatᵒᵖ ⥤ Scheme` is fully faithful.-/ def Spec.fullyFaithful : Scheme.Spec.FullyFaithful := ΓSpec.adjunction.fullyFaithfulROfIsIsoCounit /-- Spec is a full functor. -/ instance Spec.full : Scheme.Spec.Full := Spec.fullyFaithful.full /-- Spec is a faithful functor. -/ instance Spec.faithful : Scheme.Spec.Faithful := Spec.fullyFaithful.faithful section variable {R S : CommRingCat.{u}} {φ ψ : R ⟶ S} (f : Spec S ⟶ Spec R) lemma Spec.map_inj : Spec.map φ = Spec.map ψ ↔ φ = ψ := by rw [iff_comm, ← Quiver.Hom.op_inj.eq_iff, ← Scheme.Spec.map_injective.eq_iff] rfl lemma Spec.map_injective {R S : CommRingCat} : Function.Injective (Spec.map : (R ⟶ S) → _) := fun _ _ ↦ Spec.map_inj.mp /-- The preimage under Spec. -/ def Spec.preimage : R ⟶ S := (Scheme.Spec.preimage f).unop @[simp] lemma Spec.map_preimage : Spec.map (Spec.preimage f) = f := Scheme.Spec.map_preimage f variable (φ) in @[simp] lemma Spec.preimage_map : Spec.preimage (Spec.map φ) = φ := Spec.map_injective (Spec.map_preimage (Spec.map φ)) /-- Spec is fully faithful -/ @[simps] def Spec.homEquiv {R S : CommRingCat} : (Spec S ⟶ Spec R) ≃ (R ⟶ S) where toFun := Spec.preimage invFun := Spec.map left_inv := Spec.map_preimage right_inv := Spec.preimage_map end instance : Spec.toLocallyRingedSpace.IsRightAdjoint := (ΓSpec.locallyRingedSpaceAdjunction).isRightAdjoint instance : Scheme.Spec.IsRightAdjoint := (ΓSpec.adjunction).isRightAdjoint instance : Reflective Spec.toLocallyRingedSpace where adj := ΓSpec.locallyRingedSpaceAdjunction instance Spec.reflective : Reflective Scheme.Spec where adj := ΓSpec.adjunction @[deprecated (since := "2024-07-02")] alias LocallyRingedSpace.toΓSpec_preim_basicOpen_eq := LocallyRingedSpace.toΓSpec_preimage_basicOpen_eq end AlgebraicGeometry
AlgebraicGeometry\Gluing.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Geometry.RingedSpace.PresheafedSpace.Gluing import Mathlib.AlgebraicGeometry.Cover.Open /-! # Gluing Schemes Given a family of gluing data of schemes, we may glue them together. ## Main definitions * `AlgebraicGeometry.Scheme.GlueData`: A structure containing the family of gluing data. * `AlgebraicGeometry.Scheme.GlueData.glued`: The glued scheme. This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API can be used. * `AlgebraicGeometry.Scheme.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : J`. * `AlgebraicGeometry.Scheme.GlueData.isoCarrier`: The isomorphism between the underlying space of the glued scheme and the gluing of the underlying topological spaces. * `AlgebraicGeometry.Scheme.OpenCover.gluedCover`: The glue data associated with an open cover. * `AlgebraicGeometry.Scheme.OpenCover.fromGlued`: The canonical morphism `𝒰.gluedCover.glued ⟶ X`. This has an `is_iso` instance. * `AlgebraicGeometry.Scheme.OpenCover.glueMorphisms`: We may glue a family of compatible morphisms defined on an open cover of a scheme. ## Main results * `AlgebraicGeometry.Scheme.GlueData.ι_isOpenImmersion`: The map `ι i : U i ⟶ glued` is an open immersion for each `i : J`. * `AlgebraicGeometry.Scheme.GlueData.ι_jointly_surjective` : The underlying maps of `ι i : U i ⟶ glued` are jointly surjective. * `AlgebraicGeometry.Scheme.GlueData.vPullbackConeIsLimit` : `V i j` is the pullback (intersection) of `U i` and `U j` over the glued space. * `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff` : `ι i x = ι j y` if and only if they coincide when restricted to `V i i`. * `AlgebraicGeometry.Scheme.GlueData.isOpen_iff` : A subset of the glued scheme is open iff all its preimages in `U i` are open. ## Implementation details All the hard work is done in `AlgebraicGeometry/PresheafedSpace/Gluing.lean` where we glue presheafed spaces, sheafed spaces, and locally ringed spaces. -/ noncomputable section universe u open TopologicalSpace CategoryTheory Opposite open CategoryTheory.Limits AlgebraicGeometry.PresheafedSpace open CategoryTheory.GlueData namespace AlgebraicGeometry namespace Scheme /-- A family of gluing data consists of 1. An index type `J` 2. A scheme `U i` for each `i : J`. 3. A scheme `V i j` for each `i j : J`. (Note that this is `J × J → Scheme` rather than `J → J → Scheme` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the schemes `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subschemes of the glued space. -/ -- Porting note(#5171): @[nolint has_nonempty_instance]; linter not ported yet structure GlueData extends CategoryTheory.GlueData Scheme where f_open : ∀ i j, IsOpenImmersion (f i j) attribute [instance] GlueData.f_open namespace GlueData variable (D : GlueData.{u}) local notation "𝖣" => D.toGlueData /-- The glue data of locally ringed spaces associated to a family of glue data of schemes. -/ abbrev toLocallyRingedSpaceGlueData : LocallyRingedSpace.GlueData := { f_open := D.f_open toGlueData := 𝖣.mapGlueData forgetToLocallyRingedSpace } instance (i j : 𝖣.J) : LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.f i j) := by apply GlueData.f_open instance (i j : 𝖣.J) : SheafedSpace.IsOpenImmersion (D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toGlueData.f i j) := by apply GlueData.f_open instance (i j : 𝖣.J) : PresheafedSpace.IsOpenImmersion (D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toGlueData.f i j) := by apply GlueData.f_open -- Porting note: this was not needed. instance (i : 𝖣.J) : LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.ι i) := by apply LocallyRingedSpace.GlueData.ι_isOpenImmersion /-- (Implementation). The glued scheme of a glue data. This should not be used outside this file. Use `AlgebraicGeometry.Scheme.GlueData.glued` instead. -/ def gluedScheme : Scheme := by apply LocallyRingedSpace.IsOpenImmersion.scheme D.toLocallyRingedSpaceGlueData.toGlueData.glued intro x obtain ⟨i, y, rfl⟩ := D.toLocallyRingedSpaceGlueData.ι_jointly_surjective x refine ⟨?_, ?_ ≫ D.toLocallyRingedSpaceGlueData.toGlueData.ι i, ?_⟩ swap · exact (D.U i).affineCover.map y constructor · erw [TopCat.coe_comp, Set.range_comp] -- now `erw` after #13170 refine Set.mem_image_of_mem _ ?_ exact (D.U i).affineCover.covers y · infer_instance instance : CreatesColimit 𝖣.diagram.multispan forgetToLocallyRingedSpace := createsColimitOfFullyFaithfulOfIso D.gluedScheme (HasColimit.isoOfNatIso (𝖣.diagramIso forgetToLocallyRingedSpace).symm) instance : PreservesColimit (𝖣.diagram.multispan) forgetToTop := inferInstanceAs (PreservesColimit (𝖣.diagram).multispan (forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget CommRingCat)) instance : HasMulticoequalizer 𝖣.diagram := hasColimit_of_created _ forgetToLocallyRingedSpace /-- The glued scheme of a glued space. -/ abbrev glued : Scheme := 𝖣.glued /-- The immersion from `D.U i` into the glued space. -/ abbrev ι (i : D.J) : D.U i ⟶ D.glued := 𝖣.ι i /-- The gluing as sheafed spaces is isomorphic to the gluing as presheafed spaces. -/ abbrev isoLocallyRingedSpace : D.glued.toLocallyRingedSpace ≅ D.toLocallyRingedSpaceGlueData.toGlueData.glued := 𝖣.gluedIso forgetToLocallyRingedSpace theorem ι_isoLocallyRingedSpace_inv (i : D.J) : D.toLocallyRingedSpaceGlueData.toGlueData.ι i ≫ D.isoLocallyRingedSpace.inv = 𝖣.ι i := 𝖣.ι_gluedIso_inv forgetToLocallyRingedSpace i instance ι_isOpenImmersion (i : D.J) : IsOpenImmersion (𝖣.ι i) := by rw [← D.ι_isoLocallyRingedSpace_inv]; infer_instance theorem ι_jointly_surjective (x : 𝖣.glued.carrier) : ∃ (i : D.J) (y : (D.U i).carrier), (D.ι i).1.base y = x := 𝖣.ι_jointly_surjective (forgetToTop ⋙ forget TopCat) x -- Porting note: promote to higher priority to short circuit simplifier @[simp (high), reassoc] theorem glue_condition (i j : D.J) : D.t i j ≫ D.f j i ≫ D.ι j = D.f i j ≫ D.ι i := 𝖣.glue_condition i j /-- The pullback cone spanned by `V i j ⟶ U i` and `V i j ⟶ U j`. This is a pullback diagram (`vPullbackConeIsLimit`). -/ def vPullbackCone (i j : D.J) : PullbackCone (D.ι i) (D.ι j) := PullbackCone.mk (D.f i j) (D.t i j ≫ D.f j i) (by simp) /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X -/ def vPullbackConeIsLimit (i j : D.J) : IsLimit (D.vPullbackCone i j) := 𝖣.vPullbackConeIsLimitOfMap forgetToLocallyRingedSpace i j (D.toLocallyRingedSpaceGlueData.vPullbackConeIsLimit _ _) -- Porting note: new notation local notation "D_" => TopCat.GlueData.toGlueData <| D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData /-- The underlying topological space of the glued scheme is isomorphic to the gluing of the underlying spaces -/ def isoCarrier : D.glued.carrier ≅ (D_).glued := by refine (PresheafedSpace.forget _).mapIso ?_ ≪≫ GlueData.gluedIso _ (PresheafedSpace.forget.{_, _, u} _) refine SheafedSpace.forgetToPresheafedSpace.mapIso ?_ ≪≫ SheafedSpace.GlueData.isoPresheafedSpace _ refine LocallyRingedSpace.forgetToSheafedSpace.mapIso ?_ ≪≫ LocallyRingedSpace.GlueData.isoSheafedSpace _ exact Scheme.GlueData.isoLocallyRingedSpace _ @[simp] theorem ι_isoCarrier_inv (i : D.J) : (D_).ι i ≫ D.isoCarrier.inv = (D.ι i).1.base := by delta isoCarrier rw [Iso.trans_inv, GlueData.ι_gluedIso_inv_assoc, Functor.mapIso_inv, Iso.trans_inv, Functor.mapIso_inv, Iso.trans_inv, SheafedSpace.forgetToPresheafedSpace_map, forget_map, forget_map, ← comp_base, ← Category.assoc, D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.ι_isoPresheafedSpace_inv i] erw [← Category.assoc, D.toLocallyRingedSpaceGlueData.ι_isoSheafedSpace_inv i] change (_ ≫ D.isoLocallyRingedSpace.inv).1.base = _ rw [D.ι_isoLocallyRingedSpace_inv i] /-- An equivalence relation on `Σ i, D.U i` that holds iff `𝖣 .ι i x = 𝖣 .ι j y`. See `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff`. -/ def Rel (a b : Σ i, ((D.U i).carrier : Type _)) : Prop := a = b ∨ ∃ x : (D.V (a.1, b.1)).carrier, (D.f _ _).1.base x = a.2 ∧ (D.t _ _ ≫ D.f _ _).1.base x = b.2 theorem ι_eq_iff (i j : D.J) (x : (D.U i).carrier) (y : (D.U j).carrier) : (𝖣.ι i).1.base x = (𝖣.ι j).1.base y ↔ D.Rel ⟨i, x⟩ ⟨j, y⟩ := by refine Iff.trans ?_ (TopCat.GlueData.ι_eq_iff_rel D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData i j x y) rw [← ((TopCat.mono_iff_injective D.isoCarrier.inv).mp _).eq_iff] · erw [← comp_apply] -- now `erw` after #13170 simp_rw [← D.ι_isoCarrier_inv] rfl -- `rfl` was not needed before #13170 · infer_instance theorem isOpen_iff (U : Set D.glued.carrier) : IsOpen U ↔ ∀ i, IsOpen ((D.ι i).1.base ⁻¹' U) := by rw [← (TopCat.homeoOfIso D.isoCarrier.symm).isOpen_preimage] rw [TopCat.GlueData.isOpen_iff] apply forall_congr' intro i erw [← Set.preimage_comp, ← ι_isoCarrier_inv] rfl /-- The open cover of the glued space given by the glue data. -/ @[simps (config := .lemmasOnly)] def openCover (D : Scheme.GlueData) : OpenCover D.glued where J := D.J obj := D.U map := D.ι f x := (D.ι_jointly_surjective x).choose covers x := ⟨_, (D.ι_jointly_surjective x).choose_spec.choose_spec⟩ end GlueData namespace OpenCover variable {X : Scheme.{u}} (𝒰 : OpenCover.{u} X) /-- (Implementation) the transition maps in the glue data associated with an open cover. -/ def gluedCoverT' (x y z : 𝒰.J) : pullback (pullback.fst (𝒰.map x) (𝒰.map y)) (pullback.fst (𝒰.map x) (𝒰.map z)) ⟶ pullback (pullback.fst (𝒰.map y) (𝒰.map z)) (pullback.fst (𝒰.map y) (𝒰.map x)) := by refine (pullbackRightPullbackFstIso _ _ _).hom ≫ ?_ refine ?_ ≫ (pullbackSymmetry _ _).hom refine ?_ ≫ (pullbackRightPullbackFstIso _ _ _).inv refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ · simp [pullback.condition] · simp @[simp, reassoc] theorem gluedCoverT'_fst_fst (x y z : 𝒰.J) : 𝒰.gluedCoverT' x y z ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta gluedCoverT'; simp @[simp, reassoc] theorem gluedCoverT'_fst_snd (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta gluedCoverT'; simp @[simp, reassoc] theorem gluedCoverT'_snd_fst (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta gluedCoverT'; simp @[simp, reassoc] theorem gluedCoverT'_snd_snd (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by delta gluedCoverT'; simp theorem glued_cover_cocycle_fst (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.fst _ _ = pullback.fst _ _ := by apply pullback.hom_ext <;> simp theorem glued_cover_cocycle_snd (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.snd _ _ = pullback.snd _ _ := by apply pullback.hom_ext <;> simp [pullback.condition] theorem glued_cover_cocycle (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y = 𝟙 _ := by apply pullback.hom_ext <;> simp_rw [Category.id_comp, Category.assoc] · apply glued_cover_cocycle_fst · apply glued_cover_cocycle_snd /-- The glue data associated with an open cover. The canonical isomorphism `𝒰.gluedCover.glued ⟶ X` is provided by `𝒰.fromGlued`. -/ @[simps] def gluedCover : Scheme.GlueData.{u} where J := 𝒰.J U := 𝒰.obj V := fun ⟨x, y⟩ => pullback (𝒰.map x) (𝒰.map y) f x y := pullback.fst _ _ f_id x := inferInstance t x y := (pullbackSymmetry _ _).hom t_id x := by simp t' x y z := gluedCoverT' 𝒰 x y z t_fac x y z := by apply pullback.hom_ext <;> simp -- The `cocycle` field could have been `by tidy` but lean timeouts. cocycle x y z := glued_cover_cocycle 𝒰 x y z f_open x := inferInstance /-- The canonical morphism from the gluing of an open cover of `X` into `X`. This is an isomorphism, as witnessed by an `IsIso` instance. -/ def fromGlued : 𝒰.gluedCover.glued ⟶ X := by fapply Multicoequalizer.desc · exact fun x => 𝒰.map x rintro ⟨x, y⟩ change pullback.fst _ _ ≫ _ = ((pullbackSymmetry _ _).hom ≫ pullback.fst _ _) ≫ _ simpa using pullback.condition @[simp, reassoc] theorem ι_fromGlued (x : 𝒰.J) : 𝒰.gluedCover.ι x ≫ 𝒰.fromGlued = 𝒰.map x := Multicoequalizer.π_desc _ _ _ _ _ theorem fromGlued_injective : Function.Injective 𝒰.fromGlued.1.base := by intro x y h obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x obtain ⟨j, y, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective y erw [← comp_apply, ← comp_apply] at h -- now `erw` after #13170 simp_rw [← SheafedSpace.comp_base, ← LocallyRingedSpace.comp_val] at h erw [ι_fromGlued, ι_fromGlued] at h let e := (TopCat.pullbackConeIsLimit _ _).conePointUniqueUpToIso (isLimitOfHasPullbackOfPreservesLimit Scheme.forgetToTop (𝒰.map i) (𝒰.map j)) rw [𝒰.gluedCover.ι_eq_iff] right use e.hom ⟨⟨x, y⟩, h⟩ constructor · erw [← comp_apply e.hom, IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left]; rfl · erw [← comp_apply e.hom, pullbackSymmetry_hom_comp_fst, IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right] rfl instance fromGlued_stalk_iso (x : 𝒰.gluedCover.glued.carrier) : IsIso (𝒰.fromGlued.stalkMap x) := by obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x have := stalkMap_congr_hom _ _ (𝒰.ι_fromGlued i) x rw [stalkMap_comp, ← IsIso.eq_comp_inv] at this rw [this] infer_instance theorem fromGlued_open_map : IsOpenMap 𝒰.fromGlued.1.base := by intro U hU rw [isOpen_iff_forall_mem_open] intro x hx rw [𝒰.gluedCover.isOpen_iff] at hU use 𝒰.fromGlued.val.base '' U ∩ Set.range (𝒰.map (𝒰.f x)).1.base use Set.inter_subset_left constructor · rw [← Set.image_preimage_eq_inter_range] apply (show IsOpenImmersion (𝒰.map (𝒰.f x)) from inferInstance).base_open.isOpenMap convert hU (𝒰.f x) using 1 rw [← ι_fromGlued]; erw [coe_comp]; rw [Set.preimage_comp] congr! 1 exact Set.preimage_image_eq _ 𝒰.fromGlued_injective · exact ⟨hx, 𝒰.covers x⟩ theorem fromGlued_openEmbedding : OpenEmbedding 𝒰.fromGlued.1.base := openEmbedding_of_continuous_injective_open (by fun_prop) 𝒰.fromGlued_injective 𝒰.fromGlued_open_map instance : Epi 𝒰.fromGlued.val.base := by rw [TopCat.epi_iff_surjective] intro x obtain ⟨y, h⟩ := 𝒰.covers x use (𝒰.gluedCover.ι (𝒰.f x)).1.base y erw [← comp_apply] -- now `erw` after #13170 rw [← 𝒰.ι_fromGlued (𝒰.f x)] at h exact h instance fromGlued_open_immersion : IsOpenImmersion 𝒰.fromGlued := IsOpenImmersion.of_stalk_iso _ 𝒰.fromGlued_openEmbedding instance : IsIso 𝒰.fromGlued := let F := Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace have : IsIso (F.map (fromGlued 𝒰)) := by change @IsIso (PresheafedSpace _) _ _ _ 𝒰.fromGlued.val apply PresheafedSpace.IsOpenImmersion.to_iso isIso_of_reflects_iso _ F /-- Given an open cover of `X`, and a morphism `𝒰.obj x ⟶ Y` for each open subscheme in the cover, such that these morphisms are compatible in the intersection (pullback), we may glue the morphisms together into a morphism `X ⟶ Y`. Note: If `X` is exactly (defeq to) the gluing of `U i`, then using `Multicoequalizer.desc` suffices. -/ def glueMorphisms {Y : Scheme} (f : ∀ x, 𝒰.obj x ⟶ Y) (hf : ∀ x y, pullback.fst (𝒰.map x) (𝒰.map y) ≫ f x = pullback.snd _ _ ≫ f y) : X ⟶ Y := by refine inv 𝒰.fromGlued ≫ ?_ fapply Multicoequalizer.desc · exact f rintro ⟨i, j⟩ change pullback.fst _ _ ≫ f i = (_ ≫ _) ≫ f j erw [pullbackSymmetry_hom_comp_fst] exact hf i j @[simp, reassoc] theorem ι_glueMorphisms {Y : Scheme} (f : ∀ x, 𝒰.obj x ⟶ Y) (hf : ∀ x y, pullback.fst (𝒰.map x) (𝒰.map y) ≫ f x = pullback.snd _ _ ≫ f y) (x : 𝒰.J) : 𝒰.map x ≫ 𝒰.glueMorphisms f hf = f x := by rw [← ι_fromGlued, Category.assoc] erw [IsIso.hom_inv_id_assoc, Multicoequalizer.π_desc] theorem hom_ext {Y : Scheme} (f₁ f₂ : X ⟶ Y) (h : ∀ x, 𝒰.map x ≫ f₁ = 𝒰.map x ≫ f₂) : f₁ = f₂ := by rw [← cancel_epi 𝒰.fromGlued] apply Multicoequalizer.hom_ext intro x erw [Multicoequalizer.π_desc_assoc] erw [Multicoequalizer.π_desc_assoc] exact h x end OpenCover end Scheme end AlgebraicGeometry
AlgebraicGeometry\GluingOneHypercover.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne, Joël Riou, Ravi Vakil -/ import Mathlib.AlgebraicGeometry.Gluing import Mathlib.AlgebraicGeometry.Sites.BigZariski import Mathlib.CategoryTheory.Sites.OneHypercover /-! # The 1-hypercover of a glue data In this file, given `D : Scheme.GlueData`, we construct a 1-hypercover `D.openHypercover` of the scheme `D.glued` in the big Zariski site. We use this 1-hypercover in order to define a constructor `D.sheafValGluedMk` for sections over `D.glued` of a sheaf of types over the big Zariski site. ## Notes This contribution was created as part of the AIM workshop "Formalizing algebraic geometry" in June 2024. -/ universe v u open CategoryTheory Opposite Limits namespace AlgebraicGeometry.Scheme.GlueData variable (D : Scheme.GlueData.{u}) /-- The 1-hypercover of `D.glued` in the big Zariski site that is given by the open cover `D.U` from the glue data `D`. The "covering of the intersection of two such open subsets" is the trivial covering given by `D.V`. -/ @[simps] noncomputable def oneHypercover : Scheme.zariskiTopology.OneHypercover D.glued where I₀ := D.J X := D.U f := D.ι I₁ _ _ := PUnit Y i₁ i₂ _ := D.V (i₁, i₂) p₁ i₁ i₂ _ := D.f i₁ i₂ p₂ i₁ i₂ j := D.t i₁ i₂ ≫ D.f i₂ i₁ w i₁ i₂ _ := by simp only [Category.assoc, Scheme.GlueData.glue_condition] mem₀ := by refine zariskiTopology.superset_covering ?_ (zariskiTopology_openCover D.openCover) rw [Sieve.generate_le_iff] rintro W _ ⟨i⟩ exact ⟨_, 𝟙 _, _, ⟨i⟩, by simp; rfl⟩ mem₁ i₁ i₂ W p₁ p₂ fac := by refine zariskiTopology.superset_covering (fun T g _ ↦ ?_) (zariskiTopology.top_mem _) have ⟨φ, h₁, h₂⟩ := PullbackCone.IsLimit.lift' (D.vPullbackConeIsLimit i₁ i₂) (g ≫ p₁) (g ≫ p₂) (by simpa using g ≫= fac) exact ⟨⟨⟩, φ, h₁.symm, h₂.symm⟩ section variable {F : Sheaf Scheme.zariskiTopology (Type v)} (s : ∀ (j : D.J), F.val.obj (op (D.U j))) (h : ∀ (i j : D.J), F.val.map (D.f i j).op (s i) = F.val.map ((D.f j i).op ≫ (D.t i j).op) (s j)) /-- Constructor for sections over `D.glued` of a sheaf of types on the big Zariski site. -/ noncomputable def sheafValGluedMk : F.val.obj (op D.glued) := Multifork.IsLimit.sectionsEquiv (D.oneHypercover.isLimitMultifork F) { val := s property := fun _ ↦ h _ _ } @[simp] lemma sheafValGluedMk_val (j : D.J) : F.val.map (D.ι j).op (D.sheafValGluedMk s h) = s j := Multifork.IsLimit.sectionsEquiv_apply_val (D.oneHypercover.isLimitMultifork F) _ _ end end AlgebraicGeometry.Scheme.GlueData
AlgebraicGeometry\Limits.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Pullbacks import Mathlib.AlgebraicGeometry.AffineScheme /-! # (Co)Limits of Schemes We construct various limits and colimits in the category of schemes. * The existence of fibred products was shown in `Mathlib/AlgebraicGeometry/Pullbacks.lean`. * `Spec ℤ` is the terminal object. * The preceding two results imply that `Scheme` has all finite limits. * The empty scheme is the (strict) initial object. * The disjoint union is the coproduct of a family of schemes, and the forgetful functor to `LocallyRingedSpace` and `TopCat` preserves them. ## TODO * Spec preserves finite coproducts. -/ suppress_compilation universe u open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace namespace AlgebraicGeometry /-- `Spec ℤ` is the terminal object in the category of schemes. -/ noncomputable def specZIsTerminal : IsTerminal (Spec (CommRingCat.of ℤ)) := @IsTerminal.isTerminalObj _ _ _ _ Scheme.Spec _ inferInstance (terminalOpOfInitial CommRingCat.zIsInitial) instance : HasTerminal Scheme := hasTerminal_of_hasTerminal_of_preservesLimit Scheme.Spec instance : IsAffine (⊤_ Scheme.{u}) := isAffine_of_isIso (PreservesTerminal.iso Scheme.Spec).inv instance : HasFiniteLimits Scheme := hasFiniteLimits_of_hasTerminal_and_pullbacks section Initial /-- The map from the empty scheme. -/ @[simps] def Scheme.emptyTo (X : Scheme.{u}) : ∅ ⟶ X := ⟨{ base := ⟨fun x => PEmpty.elim x, by fun_prop⟩ c := { app := fun U => CommRingCat.punitIsTerminal.from _ } }, fun x => PEmpty.elim x⟩ @[ext] theorem Scheme.empty_ext {X : Scheme.{u}} (f g : ∅ ⟶ X) : f = g := -- Porting note (#11041): `ext` regression LocallyRingedSpace.Hom.ext <| PresheafedSpace.ext _ _ (by ext a; exact PEmpty.elim a) <| NatTrans.ext <| funext fun a => by aesop_cat theorem Scheme.eq_emptyTo {X : Scheme.{u}} (f : ∅ ⟶ X) : f = Scheme.emptyTo X := Scheme.empty_ext f (Scheme.emptyTo X) instance Scheme.hom_unique_of_empty_source (X : Scheme.{u}) : Unique (∅ ⟶ X) := ⟨⟨Scheme.emptyTo _⟩, fun _ => Scheme.empty_ext _ _⟩ /-- The empty scheme is the initial object in the category of schemes. -/ def emptyIsInitial : IsInitial (∅ : Scheme.{u}) := IsInitial.ofUnique _ @[simp] theorem emptyIsInitial_to : emptyIsInitial.to = Scheme.emptyTo := rfl instance : IsEmpty (∅ : Scheme.{u}) := show IsEmpty PEmpty by infer_instance instance spec_punit_isEmpty : IsEmpty (Spec (CommRingCat.of PUnit.{u+1})) := inferInstanceAs <| IsEmpty (PrimeSpectrum PUnit) instance (priority := 100) isOpenImmersion_of_isEmpty {X Y : Scheme} (f : X ⟶ Y) [IsEmpty X] : IsOpenImmersion f := by apply (config := { allowSynthFailures := true }) IsOpenImmersion.of_stalk_iso · exact .of_isEmpty (X := X) _ · intro (i : X); exact isEmptyElim i instance (priority := 100) isIso_of_isEmpty {X Y : Scheme} (f : X ⟶ Y) [IsEmpty Y] : IsIso f := by haveI : IsEmpty X := f.1.base.1.isEmpty have : Epi f.1.base := by rw [TopCat.epi_iff_surjective]; rintro (x : Y) exact isEmptyElim x apply IsOpenImmersion.to_iso /-- A scheme is initial if its underlying space is empty . -/ noncomputable def isInitialOfIsEmpty {X : Scheme} [IsEmpty X] : IsInitial X := emptyIsInitial.ofIso (asIso <| emptyIsInitial.to _) /-- `Spec 0` is the initial object in the category of schemes. -/ noncomputable def specPunitIsInitial : IsInitial (Spec (.of PUnit.{u+1})) := emptyIsInitial.ofIso (asIso <| emptyIsInitial.to _) instance (priority := 100) isAffine_of_isEmpty {X : Scheme} [IsEmpty X] : IsAffine X := isAffine_of_isIso (inv (emptyIsInitial.to X) ≫ emptyIsInitial.to (Spec (.of PUnit))) instance : HasInitial Scheme.{u} := hasInitial_of_unique ∅ instance initial_isEmpty : IsEmpty (⊥_ Scheme) := ⟨fun x => ((initial.to Scheme.empty : _).1.base x).elim⟩ theorem isAffineOpen_bot (X : Scheme) : IsAffineOpen (⊥ : X.Opens) := @isAffine_of_isEmpty _ (inferInstanceAs (IsEmpty (∅ : Set X))) instance : HasStrictInitialObjects Scheme := hasStrictInitialObjects_of_initial_is_strict fun A f => by infer_instance end Initial section Coproduct variable {ι : Type u} (f : ι → Scheme.{u}) /-- (Implementation Detail) The glue data associated to a disjoint union. -/ @[simps] noncomputable def disjointGlueData' : GlueData' Scheme where J := ι U := f V _ _ _ := ∅ f _ _ _ := Scheme.emptyTo _ t _ _ _ := 𝟙 _ t' _ _ _ _ _ _ := Limits.pullback.fst _ _ ≫ Scheme.emptyTo _ t_fac _ _ _ _ _ _ := emptyIsInitial.strict_hom_ext _ _ t_inv _ _ _ := Category.comp_id _ cocycle _ _ _ _ _ _ := (emptyIsInitial.ofStrict (pullback.fst _ _)).hom_ext _ _ f_mono _ _ := by dsimp only; infer_instance /-- (Implementation Detail) The glue data associated to a disjoint union. -/ @[simps! J V U f t] noncomputable def disjointGlueData : Scheme.GlueData where __ := GlueData.ofGlueData' (disjointGlueData' f) f_open i j := by dsimp only [GlueData.ofGlueData', GlueData'.f', disjointGlueData'] split <;> infer_instance /-- (Implementation Detail) The cofan in `LocallyRingedSpace` associated to a disjoint union. -/ noncomputable def toLocallyRingedSpaceCoproductCofan : Cofan (Scheme.toLocallyRingedSpace ∘ f) := Cofan.mk (disjointGlueData f).toLocallyRingedSpaceGlueData.glued (disjointGlueData f).toLocallyRingedSpaceGlueData.ι /-- (Implementation Detail) The cofan in `LocallyRingedSpace` associated to a disjoint union is a colimit. -/ noncomputable def toLocallyRingedSpaceCoproductCofanIsColimit : IsColimit (toLocallyRingedSpaceCoproductCofan f) := by fapply mkCofanColimit · refine fun t ↦ Multicoequalizer.desc _ _ t.inj ?_ rintro ⟨i, j⟩ simp only [GlueData.diagram, disjointGlueData_J, disjointGlueData_V, disjointGlueData_U, disjointGlueData_f, disjointGlueData_t, Category.comp_id, Category.assoc, GlueData.mapGlueData_J, disjointGlueData_J, GlueData.mapGlueData_V, disjointGlueData_V, Scheme.forgetToLocallyRingedSpace_obj, GlueData.mapGlueData_U, disjointGlueData_U, GlueData.mapGlueData_f, disjointGlueData_f, Category.comp_id, Scheme.forgetToLocallyRingedSpace_map, GlueData.mapGlueData_t, disjointGlueData_t] split_ifs with h · subst h simp only [eqToHom_refl, ↓reduceDIte, ← Category.assoc, GlueData'.f'] congr · apply Limits.IsInitial.hom_ext rw [if_neg h] exact LocallyRingedSpace.emptyIsInitial · exact fun _ _ ↦ Multicoequalizer.π_desc _ _ _ _ _ · intro i m h apply Multicoequalizer.hom_ext _ _ _ fun j ↦ ?_ rw [Multicoequalizer.π_desc] exact h j noncomputable instance : CreatesColimit (Discrete.functor f) Scheme.forgetToLocallyRingedSpace := createsColimitOfFullyFaithfulOfIso (disjointGlueData f).gluedScheme <| let F : Discrete.functor f ⋙ Scheme.forgetToLocallyRingedSpace ≅ Discrete.functor (Scheme.toLocallyRingedSpace ∘ f) := Discrete.natIsoFunctor have := (IsColimit.precomposeHomEquiv F _).symm (toLocallyRingedSpaceCoproductCofanIsColimit f) (colimit.isoColimitCocone ⟨_, this⟩).symm noncomputable instance : CreatesColimitsOfShape (Discrete ι) Scheme.forgetToLocallyRingedSpace := by constructor intro K exact createsColimitOfIsoDiagram _ (Discrete.natIsoFunctor (F := K)).symm noncomputable instance : PreservesColimitsOfShape (Discrete ι) Scheme.forgetToTop := inferInstanceAs (PreservesColimitsOfShape (Discrete ι) (Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget CommRingCat)) instance : HasCoproducts.{u} Scheme.{u} := fun _ ↦ ⟨fun _ ↦ hasColimit_of_created _ Scheme.forgetToLocallyRingedSpace⟩ instance : HasCoproducts.{0} Scheme.{u} := has_smallest_coproducts_of_hasCoproducts noncomputable instance {ι : Type} : PreservesColimitsOfShape (Discrete ι) Scheme.forgetToTop := preservesColimitsOfShapeOfEquiv (Discrete.equivalence Equiv.ulift : Discrete (ULift.{u} ι) ≌ _) _ noncomputable instance {ι : Type} : PreservesColimitsOfShape (Discrete ι) Scheme.forgetToLocallyRingedSpace := preservesColimitsOfShapeOfEquiv (Discrete.equivalence Equiv.ulift : Discrete (ULift.{u} ι) ≌ _) _ /-- (Implementation Detail) Coproduct of schemes is isomorphic to the disjoint union. -/ noncomputable def sigmaIsoGlued : ∐ f ≅ (disjointGlueData f).glued := Scheme.fullyFaithfulForgetToLocallyRingedSpace.preimageIso (PreservesCoproduct.iso _ _ ≪≫ colimit.isoColimitCocone ⟨_, toLocallyRingedSpaceCoproductCofanIsColimit f⟩ ≪≫ (disjointGlueData f).isoLocallyRingedSpace.symm) @[reassoc (attr := simp)] lemma ι_sigmaIsoGlued_inv (i) : (disjointGlueData f).ι i ≫ (sigmaIsoGlued f).inv = Sigma.ι f i := by apply Scheme.forgetToLocallyRingedSpace.map_injective dsimp [sigmaIsoGlued] simp only [Category.assoc] refine ((disjointGlueData f).ι_gluedIso_hom_assoc Scheme.forgetToLocallyRingedSpace i _).trans ?_ refine (colimit.isoColimitCocone_ι_inv_assoc ⟨_, toLocallyRingedSpaceCoproductCofanIsColimit f⟩ ⟨i⟩ _).trans ?_ exact ι_comp_sigmaComparison Scheme.forgetToLocallyRingedSpace _ _ @[reassoc (attr := simp)] lemma ι_sigmaIsoGlued_hom (i) : Sigma.ι f i ≫ (sigmaIsoGlued f).hom = (disjointGlueData f).ι i := by rw [← ι_sigmaIsoGlued_inv, Category.assoc, Iso.inv_hom_id, Category.comp_id] instance (i) : IsOpenImmersion (Sigma.ι f i) := by rw [← ι_sigmaIsoGlued_inv] infer_instance lemma sigmaι_eq_iff (i j : ι) (x y) : (Sigma.ι f i).1.base x = (Sigma.ι f j).1.base y ↔ (Sigma.mk i x : Σ i, f i) = Sigma.mk j y := by constructor · intro H rw [← ι_sigmaIsoGlued_inv, ← ι_sigmaIsoGlued_inv] at H erw [(TopCat.homeoOfIso (Scheme.forgetToTop.mapIso (sigmaIsoGlued f))).symm.injective.eq_iff] at H by_cases h : i = j · subst h simp only [Sigma.mk.inj_iff, heq_eq_eq, true_and] exact ((disjointGlueData f).ι i).openEmbedding.inj H · obtain (e | ⟨z, _⟩) := (Scheme.GlueData.ι_eq_iff _ _ _ _ _).mp H · exact (h (Sigma.mk.inj_iff.mp e).1).elim · simp only [disjointGlueData_J, disjointGlueData_V, h, ↓reduceIte] at z cases z · rintro ⟨rfl⟩ rfl /-- The images of each component in the coproduct is disjoint. -/ lemma disjoint_opensRange_sigmaι (i j : ι) (h : i ≠ j) : Disjoint (Sigma.ι f i).opensRange (Sigma.ι f j).opensRange := by intro U hU hU' x hx obtain ⟨x, rfl⟩ := hU hx obtain ⟨y, hy⟩ := hU' hx obtain ⟨rfl⟩ := (sigmaι_eq_iff _ _ _ _ _).mp hy cases h rfl lemma exists_sigmaι_eq (x : (∐ f : _)) : ∃ i y, (Sigma.ι f i).1.base y = x := by obtain ⟨i, y, e⟩ := (disjointGlueData f).ι_jointly_surjective ((sigmaIsoGlued f).hom.1.base x) refine ⟨i, y, (sigmaIsoGlued f).hom.openEmbedding.inj ?_⟩ rwa [← Scheme.comp_val_base_apply, ι_sigmaIsoGlued_hom] lemma iSup_opensRange_sigmaι : ⨆ i, (Sigma.ι f i).opensRange = ⊤ := eq_top_iff.mpr fun x ↦ by simpa using exists_sigmaι_eq f x /-- The open cover of the coproduct. -/ @[simps obj map] noncomputable def sigmaOpenCover : (∐ f).OpenCover where J := ι obj := f map := Sigma.ι f f x := (exists_sigmaι_eq f x).choose covers x := (exists_sigmaι_eq f x).choose_spec /-- The underlying topological space of the coproduct is homeomorphic to the disjoint union. -/ noncomputable def sigmaMk : (Σ i, f i) ≃ₜ (∐ f : _) := TopCat.homeoOfIso ((colimit.isoColimitCocone ⟨_, TopCat.sigmaCofanIsColimit _⟩).symm ≪≫ (PreservesCoproduct.iso Scheme.forgetToTop f).symm) @[simp] lemma sigmaMk_mk (i) (x : f i) : sigmaMk f (.mk i x) = (Sigma.ι f i).1.base x := by show ((TopCat.sigmaCofan (fun x ↦ (f x).toTopCat)).inj i ≫ (colimit.isoColimitCocone ⟨_, TopCat.sigmaCofanIsColimit _⟩).inv ≫ _) x = Scheme.forgetToTop.map (Sigma.ι f i) x congr 1 refine (colimit.isoColimitCocone_ι_inv_assoc ⟨_, TopCat.sigmaCofanIsColimit _⟩ _ _).trans ?_ exact ι_comp_sigmaComparison Scheme.forgetToTop _ _ variable (X Y : Scheme.{u}) /-- (Implementation Detail) The coproduct of the two schemes is given by indexed coproducts over `WalkingPair`. -/ noncomputable def coprodIsoSigma : X ⨿ Y ≅ ∐ fun i : ULift.{u} WalkingPair ↦ i.1.casesOn X Y := Sigma.whiskerEquiv Equiv.ulift.symm (fun _ ↦ by exact Iso.refl _) lemma ι_left_coprodIsoSigma_inv : Sigma.ι _ ⟨.left⟩ ≫ (coprodIsoSigma X Y).inv = coprod.inl := Sigma.ι_comp_map' _ _ _ lemma ι_right_coprodIsoSigma_inv : Sigma.ι _ ⟨.right⟩ ≫ (coprodIsoSigma X Y).inv = coprod.inr := Sigma.ι_comp_map' _ _ _ instance : IsOpenImmersion (coprod.inl : X ⟶ X ⨿ Y) := by rw [← ι_left_coprodIsoSigma_inv]; infer_instance instance : IsOpenImmersion (coprod.inr : Y ⟶ X ⨿ Y) := by rw [← ι_right_coprodIsoSigma_inv]; infer_instance lemma isCompl_range_inl_inr : IsCompl (Set.range (coprod.inl : X ⟶ X ⨿ Y).1.base) (Set.range (coprod.inr : Y ⟶ X ⨿ Y).1.base) := ((TopCat.binaryCofan_isColimit_iff _).mp ⟨mapIsColimitOfPreservesOfIsColimit Scheme.forgetToTop _ _ (coprodIsCoprod X Y)⟩).2.2 lemma isCompl_opensRange_inl_inr : IsCompl (coprod.inl : X ⟶ X ⨿ Y).opensRange (coprod.inr : Y ⟶ X ⨿ Y).opensRange := by convert isCompl_range_inl_inr X Y simp only [isCompl_iff, disjoint_iff, codisjoint_iff, ← TopologicalSpace.Opens.coe_inj] rfl /-- The underlying topological space of the coproduct is homeomorphic to the disjoint union -/ noncomputable def coprodMk : X ⊕ Y ≃ₜ (X ⨿ Y : Scheme.{u}) := TopCat.homeoOfIso ((colimit.isoColimitCocone ⟨_, TopCat.binaryCofanIsColimit _ _⟩).symm ≪≫ PreservesColimitPair.iso Scheme.forgetToTop X Y) @[simp] lemma coprodMk_inl (x : X) : coprodMk X Y (.inl x) = (coprod.inl : X ⟶ X ⨿ Y).1.base x := by show ((TopCat.binaryCofan X Y).inl ≫ (colimit.isoColimitCocone ⟨_, TopCat.binaryCofanIsColimit _ _⟩).inv ≫ _) x = Scheme.forgetToTop.map coprod.inl x congr 1 refine (colimit.isoColimitCocone_ι_inv_assoc ⟨_, TopCat.binaryCofanIsColimit _ _⟩ _ _).trans ?_ exact coprodComparison_inl Scheme.forgetToTop @[simp] lemma coprodMk_inr (x : Y) : coprodMk X Y (.inr x) = (coprod.inr : Y ⟶ X ⨿ Y).1.base x := by show ((TopCat.binaryCofan X Y).inr ≫ (colimit.isoColimitCocone ⟨_, TopCat.binaryCofanIsColimit _ _⟩).inv ≫ _) x = Scheme.forgetToTop.map coprod.inr x congr 1 refine (colimit.isoColimitCocone_ι_inv_assoc ⟨_, TopCat.binaryCofanIsColimit _ _⟩ _ _).trans ?_ exact coprodComparison_inr Scheme.forgetToTop /-- The open cover of the coproduct of two schemes. -/ noncomputable def coprodOpenCover.{w} : (X ⨿ Y).OpenCover where J := PUnit.{w + 1} ⊕ PUnit.{w + 1} obj x := x.elim (fun _ ↦ X) (fun _ ↦ Y) map x := x.rec (fun _ ↦ coprod.inl) (fun _ ↦ coprod.inr) f x := ((coprodMk X Y).symm x).elim (fun _ ↦ Sum.inl .unit) (fun _ ↦ Sum.inr .unit) covers x := by obtain ⟨x, rfl⟩ := (coprodMk X Y).surjective x simp only [Sum.elim_inl, Sum.elim_inr, Set.mem_range] rw [Homeomorph.symm_apply_apply] obtain (x | x) := x · simp only [Sum.elim_inl, coprodMk_inl, exists_apply_eq_apply] · simp only [Sum.elim_inr, coprodMk_inr, exists_apply_eq_apply] IsOpen x := x.rec (fun _ ↦ inferInstance) (fun _ ↦ inferInstance) variable (R S : Type u) [CommRing R] [CommRing S] /-- The map `Spec R ⨿ Spec S ⟶ Spec (R × S)`. This is an isomorphism as witnessed by an `IsIso` instance provided below. -/ noncomputable def coprodSpec : Spec (.of R) ⨿ Spec (.of S) ⟶ Spec (.of (R × S)) := coprod.desc (Spec.map (CommRingCat.ofHom <| RingHom.fst _ _)) (Spec.map (CommRingCat.ofHom <| RingHom.snd _ _)) @[simp, reassoc] lemma coprodSpec_inl : coprod.inl ≫ coprodSpec R S = Spec.map (CommRingCat.ofHom <| RingHom.fst R S) := coprod.inl_desc _ _ @[simp, reassoc] lemma coprodSpec_inr : coprod.inr ≫ coprodSpec R S = Spec.map (CommRingCat.ofHom <| RingHom.snd R S) := coprod.inr_desc _ _ lemma coprodSpec_coprodMk (x) : (coprodSpec R S).1.base (coprodMk _ _ x) = (PrimeSpectrum.primeSpectrumProd R S).symm x := by apply PrimeSpectrum.ext obtain (x | x) := x <;> simp only [coprodMk_inl, coprodMk_inr, ← Scheme.comp_val_base_apply, coprodSpec, coprod.inl_desc, coprod.inr_desc] · show Ideal.comap _ _ = x.asIdeal.prod ⊤ ext; simp [Ideal.prod, CommRingCat.ofHom] · show Ideal.comap _ _ = Ideal.prod ⊤ x.asIdeal ext; simp [Ideal.prod, CommRingCat.ofHom] lemma coprodSpec_apply (x) : (coprodSpec R S).1.base x = (PrimeSpectrum.primeSpectrumProd R S).symm ((coprodMk (Spec (.of R)) (Spec (.of S))).symm x) := by rw [← coprodSpec_coprodMk, Homeomorph.apply_symm_apply] lemma isIso_stalkMap_coprodSpec (x) : IsIso ((coprodSpec R S).stalkMap x) := by obtain ⟨x | x, rfl⟩ := (coprodMk _ _).surjective x · have := Scheme.stalkMap_comp coprod.inl (coprodSpec R S) x rw [← IsIso.comp_inv_eq, Scheme.stalkMap_congr_hom _ (Spec.map _) (coprodSpec_inl R S)] at this rw [coprodMk_inl, ← this] letI := (RingHom.fst R S).toAlgebra have := IsLocalization.away_fst (R := R) (S := S) have : IsOpenImmersion (Spec.map (CommRingCat.ofHom (RingHom.fst R S))) := IsOpenImmersion.of_isLocalization (1, 0) infer_instance · have := Scheme.stalkMap_comp coprod.inr (coprodSpec R S) x rw [← IsIso.comp_inv_eq, Scheme.stalkMap_congr_hom _ (Spec.map _) (coprodSpec_inr R S)] at this rw [coprodMk_inr, ← this] letI := (RingHom.snd R S).toAlgebra have := IsLocalization.away_snd (R := R) (S := S) have : IsOpenImmersion (Spec.map (CommRingCat.ofHom (RingHom.snd R S))) := IsOpenImmersion.of_isLocalization (0, 1) infer_instance instance : IsIso (coprodSpec R S) := by rw [isIso_iff_stalk_iso] refine ⟨?_, isIso_stalkMap_coprodSpec R S⟩ convert_to IsIso (TopCat.isoOfHomeo (X := Spec (.of (R × S))) <| PrimeSpectrum.primeSpectrumProdHomeo.trans (coprodMk (Spec (.of R)) (Spec (.of S)))).inv · ext x; exact coprodSpec_apply R S x · infer_instance instance (R S : CommRingCatᵒᵖ) : IsIso (coprodComparison Scheme.Spec R S) := by obtain ⟨R⟩ := R; obtain ⟨S⟩ := S have : coprodComparison Scheme.Spec (.op R) (.op S) ≫ (Spec.map ((limit.isoLimitCone ⟨_, CommRingCat.prodFanIsLimit R S⟩).inv ≫ (opProdIsoCoprod R S).unop.inv)) = coprodSpec R S := by ext1 · rw [coprodComparison_inl_assoc, coprodSpec, coprod.inl_desc, Scheme.Spec_map, ← Spec.map_comp, Category.assoc, Iso.unop_inv, opProdIsoCoprod_inv_inl, limit.isoLimitCone_inv_π] rfl · rw [coprodComparison_inr_assoc, coprodSpec, coprod.inr_desc, Scheme.Spec_map, ← Spec.map_comp, Category.assoc, Iso.unop_inv, opProdIsoCoprod_inv_inr, limit.isoLimitCone_inv_π] rfl rw [(IsIso.eq_comp_inv _).mpr this] infer_instance noncomputable instance : PreservesColimitsOfShape (Discrete WalkingPair) Scheme.Spec := ⟨fun {_} ↦ have (X Y : CommRingCatᵒᵖ) := PreservesColimitPair.ofIsoCoprodComparison Scheme.Spec X Y preservesColimitOfIsoDiagram _ (diagramIsoPair _).symm⟩ noncomputable instance : PreservesColimitsOfShape (Discrete PEmpty.{1}) Scheme.Spec := by have : IsEmpty (Scheme.Spec.obj (⊥_ CommRingCatᵒᵖ)) := @Function.isEmpty _ _ spec_punit_isEmpty (Scheme.Spec.mapIso (initialIsoIsInitial (initialOpOfTerminal CommRingCat.punitIsTerminal))).hom.1.base have := preservesInitialOfIso Scheme.Spec (asIso (initial.to _)) exact preservesColimitsOfShapePemptyOfPreservesInitial _ noncomputable instance {J} [Fintype J] : PreservesColimitsOfShape (Discrete J) Scheme.Spec := preservesFiniteCoproductsOfPreservesBinaryAndInitial _ _ noncomputable instance {J : Type*} [Finite J] : PreservesColimitsOfShape (Discrete J) Scheme.Spec := letI := (nonempty_fintype J).some preservesColimitsOfShapeOfEquiv (Discrete.equivalence (Fintype.equivFin _).symm) _ /-- The canonical map `∐ Spec Rᵢ ⟶ Spec (Π Rᵢ)`. This is an isomorphism when the product is finite. -/ noncomputable def sigmaSpec (R : ι → CommRingCat) : (∐ fun i ↦ Spec (R i)) ⟶ Spec (.of (Π i, R i)) := Sigma.desc (fun i ↦ Spec.map (CommRingCat.ofHom (Pi.evalRingHom _ i))) @[simp, reassoc] lemma ι_sigmaSpec (R : ι → CommRingCat) (i) : Sigma.ι _ i ≫ sigmaSpec R = Spec.map (CommRingCat.ofHom (Pi.evalRingHom _ i)) := Sigma.ι_desc _ _ instance [Finite ι] (R : ι → CommRingCat) : IsIso (sigmaSpec R) := by have : sigmaSpec R = (colimit.isoColimitCocone ⟨_, (IsColimit.precomposeHomEquiv Discrete.natIsoFunctor.symm _).symm (isColimitOfPreserves Scheme.Spec (Fan.IsLimit.op (CommRingCat.piFanIsLimit R)))⟩).hom := by ext1; simp; rfl rw [this] infer_instance instance [Finite ι] [∀ i, IsAffine (f i)] : IsAffine (∐ f) := isAffine_of_isIso ((Sigma.mapIso (fun i ↦ (f i).isoSpec)).hom ≫ sigmaSpec _) instance [IsAffine X] [IsAffine Y] : IsAffine (X ⨿ Y) := isAffine_of_isIso ((coprod.mapIso X.isoSpec Y.isoSpec).hom ≫ coprodSpec _ _) end Coproduct end AlgebraicGeometry
AlgebraicGeometry\Noetherian.lean
/- Copyright (c) 2024 Geno Racklin Asher. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Geno Racklin Asher -/ import Mathlib.AlgebraicGeometry.Morphisms.QuasiSeparated import Mathlib.AlgebraicGeometry.PrimeSpectrum.Noetherian import Mathlib.RingTheory.Localization.Submodule /-! # Noetherian and Locally Noetherian Schemes We introduce the concept of (locally) Noetherian schemes, giving definitions, equivalent conditions, and basic properties. ## Main definitions * `AlgebraicGeometry.IsLocallyNoetherian`: A scheme is locally Noetherian if the components of the structure sheaf at each affine open are Noetherian rings. * `AlgebraicGeometry.IsNoetherian`: A scheme is Noetherian if it is locally Noetherian and quasi-compact as a topological space. ## Main results * `AlgebraicGeometry.isLocallyNoetherian_iff_of_affine_openCover`: A scheme is locally Noetherian if and only if it is covered by affine opens whose sections are Noetherian rings. * `AlgebraicGeometry.IsLocallyNoetherian.quasiSeparatedSpace`: A locally Noetherian scheme is quasi-separated. * `AlgebraicGeometry.isNoetherian_iff_of_finite_affine_openCover`: A scheme is Noetherian if and only if it is covered by finitely many affine opens whose sections are Noetherian rings. * `AlgebraicGeometry.IsNoetherian.noetherianSpace`: A Noetherian scheme is topologically a Noetherian space. ## References * [Stacks: Noetherian Schemes](https://stacks.math.columbia.edu/tag/01OU) * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ universe u v open Opposite AlgebraicGeometry Localization IsLocalization TopologicalSpace namespace AlgebraicGeometry /-- A scheme `X` is locally Noetherian if `𝒪ₓ(U)` is Noetherian for all affine `U`. -/ class IsLocallyNoetherian (X : Scheme) : Prop where component_noetherian : ∀ (U : X.affineOpens), IsNoetherianRing Γ(X, U) := by infer_instance section localizationProps variable {R : Type u} [CommRing R] (S : Finset R) (hS : Ideal.span (α := R) S = ⊤) (hN : ∀ s : S, IsNoetherianRing (Away (M := R) s)) /-- Let `R` be a ring, and `f i` a finite collection of elements of `R` generating the unit ideal. If the localization of `R` at each `f i` is noetherian, so is `R`. We follow the proof given in [Har77], Proposition II.3.2 -/ theorem isNoetherianRing_of_away : IsNoetherianRing R := by apply monotone_stabilizes_iff_noetherian.mp intro I let floc s := algebraMap R (Away (M := R) s) let suitableN s := { n : ℕ | ∀ m : ℕ, n ≤ m → (Ideal.map (floc s) (I n)) = (Ideal.map (floc s) (I m)) } let minN s := sInf (suitableN s) have hSuit : ∀ s : S, minN s ∈ suitableN s := by intro s apply Nat.sInf_mem let f : ℕ →o Ideal (Away (M := R) s) := ⟨fun n ↦ Ideal.map (floc s) (I n), fun _ _ h ↦ Ideal.map_mono (I.monotone h)⟩ exact monotone_stabilizes_iff_noetherian.mpr (hN s) f let N := Finset.sup S minN use N have hN : ∀ s : S, minN s ≤ N := fun s => Finset.le_sup s.prop intro n hn rw [IsLocalization.ideal_eq_iInf_comap_map_away hS (I N), IsLocalization.ideal_eq_iInf_comap_map_away hS (I n), iInf_subtype', iInf_subtype'] apply iInf_congr intro s congr 1 rw [← hSuit s N (hN s)] exact hSuit s n <| Nat.le_trans (hN s) hn end localizationProps variable {X : Scheme} /-- If a scheme `X` has a cover by affine opens whose sections are Noetherian rings, then `X` is locally Noetherian. -/ theorem isLocallyNoetherian_of_affine_cover {ι} {S : ι → X.affineOpens} (hS : (⨆ i, S i : X.Opens) = ⊤) (hS' : ∀ i, IsNoetherianRing Γ(X, S i)) : IsLocallyNoetherian X := by refine ⟨fun U => ?_⟩ induction U using of_affine_open_cover S hS with | basicOpen U f hN => have := U.prop.isLocalization_basicOpen f exact IsLocalization.isNoetherianRing (.powers f) Γ(X, X.basicOpen f) hN | openCover U s _ hN => apply isNoetherianRing_of_away s ‹_› intro ⟨f, hf⟩ have : IsNoetherianRing Γ(X, X.basicOpen f) := hN ⟨f, hf⟩ have := U.prop.isLocalization_basicOpen f have hEq := IsLocalization.algEquiv (.powers f) (Localization.Away f) Γ(X, X.basicOpen f) exact isNoetherianRing_of_ringEquiv Γ(X, X.basicOpen f) hEq.symm.toRingEquiv | hU => exact hS' _ /-- A scheme is locally Noetherian if and only if it is covered by affine opens whose sections are noetherian rings. See [Har77], Proposition II.3.2. -/ theorem isLocallyNoetherian_iff_of_iSup_eq_top {ι} {S : ι → X.affineOpens} (hS : (⨆ i, S i : X.Opens) = ⊤) : IsLocallyNoetherian X ↔ ∀ i, IsNoetherianRing Γ(X, S i) := ⟨fun _ i => IsLocallyNoetherian.component_noetherian (S i), isLocallyNoetherian_of_affine_cover hS⟩ open CategoryTheory in /-- A version of `isLocallyNoetherian_iff_of_iSup_eq_top` using `Scheme.OpenCover`. -/ theorem isLocallyNoetherian_iff_of_affine_openCover (𝒰 : Scheme.OpenCover.{v, u} X) [∀ i, IsAffine (𝒰.obj i)] : IsLocallyNoetherian X ↔ ∀ (i : 𝒰.J), IsNoetherianRing Γ(𝒰.obj i, ⊤) := by constructor · intro h i let U := Scheme.Hom.opensRange (𝒰.map i) have := h.component_noetherian ⟨U, isAffineOpen_opensRange _⟩ apply isNoetherianRing_of_ringEquiv (R := Γ(X, U)) apply CategoryTheory.Iso.commRingCatIsoToRingEquiv exact (IsOpenImmersion.ΓIsoTop (𝒰.map i)).symm · intro hCNoeth let fS i : X.affineOpens := ⟨Scheme.Hom.opensRange (𝒰.map i), isAffineOpen_opensRange _⟩ apply isLocallyNoetherian_of_affine_cover (S := fS) · rw [← Scheme.OpenCover.iSup_opensRange 𝒰] intro i apply isNoetherianRing_of_ringEquiv (R := Γ(𝒰.obj i, ⊤)) apply CategoryTheory.Iso.commRingCatIsoToRingEquiv exact IsOpenImmersion.ΓIsoTop (𝒰.map i) lemma isLocallyNoetherian_of_isOpenImmersion {Y : Scheme} (f : X ⟶ Y) [IsOpenImmersion f] [IsLocallyNoetherian Y] : IsLocallyNoetherian X := by refine ⟨fun U => ?_⟩ let V : Y.affineOpens := ⟨f ''ᵁ U, IsAffineOpen.image_of_isOpenImmersion U.prop _⟩ suffices Γ(X, U) ≅ Γ(Y, V) by convert isNoetherianRing_of_ringEquiv (R := Γ(Y, V)) _ · apply CategoryTheory.Iso.commRingCatIsoToRingEquiv exact this.symm · exact IsLocallyNoetherian.component_noetherian V rw [← Scheme.Hom.preimage_image_eq f U] trans · apply IsOpenImmersion.ΓIso · suffices Scheme.Hom.opensRange f ⊓ V = V by rw [this] rw [← Opens.coe_inj] rw [Opens.coe_inf, Scheme.Hom.opensRange_coe, IsOpenMap.functor_obj_coe, Set.inter_eq_right, Set.image_subset_iff, Set.preimage_range] exact Set.subset_univ _ /-- If `𝒰` is an open cover of a scheme `X`, then `X` is locally noetherian if and only if `𝒰.obj i` are all locally noetherian. -/ theorem isLocallyNoetherian_iff_openCover (𝒰 : Scheme.OpenCover X) : IsLocallyNoetherian X ↔ ∀ (i : 𝒰.J), IsLocallyNoetherian (𝒰.obj i) := by constructor · intro h i exact isLocallyNoetherian_of_isOpenImmersion (𝒰.map i) · rw [isLocallyNoetherian_iff_of_affine_openCover (𝒰 := 𝒰.affineRefinement.openCover)] intro h i exact @isNoetherianRing_of_ringEquiv _ _ _ _ (IsOpenImmersion.ΓIsoTop (Scheme.OpenCover.map _ i.2)).symm.commRingCatIsoToRingEquiv (IsLocallyNoetherian.component_noetherian ⟨_, isAffineOpen_opensRange _⟩) /-- If `R` is a noetherian ring, `Spec R` is a noetherian topological space. -/ instance {R : CommRingCat} [IsNoetherianRing R] : NoetherianSpace (Spec R) := by convert PrimeSpectrum.instNoetherianSpace (R := R) lemma noetherianSpace_of_isAffine [IsAffine X] [IsNoetherianRing Γ(X, ⊤)] : NoetherianSpace X := (noetherianSpace_iff_of_homeomorph X.isoSpec.inv.homeomorph).mp inferInstance lemma noetherianSpace_of_isAffineOpen (U : X.Opens) (hU : IsAffineOpen U) [IsNoetherianRing Γ(X, U)] : NoetherianSpace U := by have : IsNoetherianRing Γ(U, ⊤) := isNoetherianRing_of_ringEquiv _ (Scheme.restrictFunctorΓ.app (op U)).symm.commRingCatIsoToRingEquiv exact @noetherianSpace_of_isAffine _ hU _ /-- Any open immersion `Z ⟶ X` with `X` locally Noetherian is quasi-compact. [Stacks: Lemma 01OX](https://stacks.math.columbia.edu/tag/01OX) -/ instance (priority := 100) {Z : Scheme} [IsLocallyNoetherian X] {f : Z ⟶ X} [IsOpenImmersion f] : QuasiCompact f := by apply (quasiCompact_iff_forall_affine f).mpr intro U hU rw [Opens.map_coe, ← Set.preimage_inter_range] apply f.openEmbedding.toInducing.isCompact_preimage' · apply (noetherianSpace_set_iff _).mp · convert noetherianSpace_of_isAffineOpen U hU apply IsLocallyNoetherian.component_noetherian ⟨U, hU⟩ · exact Set.inter_subset_left · exact Set.inter_subset_right /-- A locally Noetherian scheme is quasi-separated. [Stacks: Lemma 01OY](https://stacks.math.columbia.edu/tag/01OY) -/ instance (priority := 100) IsLocallyNoetherian.quasiSeparatedSpace [IsLocallyNoetherian X] : QuasiSeparatedSpace X := by apply (quasiSeparatedSpace_iff_affine X).mpr intro U V have hInd := U.2.fromSpec.openEmbedding.toInducing apply (hInd.isCompact_preimage_iff ?_).mp · rw [← Set.preimage_inter_range, IsAffineOpen.range_fromSpec, Set.inter_comm] apply hInd.isCompact_preimage' · apply (noetherianSpace_set_iff _).mp · convert noetherianSpace_of_isAffineOpen U.1 U.2 apply IsLocallyNoetherian.component_noetherian · exact Set.inter_subset_left · rw [IsAffineOpen.range_fromSpec] exact Set.inter_subset_left · rw [IsAffineOpen.range_fromSpec] exact Set.inter_subset_left /-- A scheme `X` is Noetherian if it is locally Noetherian and compact. -/ @[mk_iff] class IsNoetherian (X : Scheme) extends IsLocallyNoetherian X, CompactSpace X : Prop /-- A scheme is Noetherian if and only if it is covered by finitely many affine opens whose sections are noetherian rings. -/ theorem isNoetherian_iff_of_finite_iSup_eq_top {ι} [Finite ι] {S : ι → X.affineOpens} (hS : (⨆ i, S i : X.Opens) = ⊤) : IsNoetherian X ↔ ∀ i, IsNoetherianRing Γ(X, S i) := by constructor · intro h i apply (isLocallyNoetherian_iff_of_iSup_eq_top hS).mp exact h.toIsLocallyNoetherian · intro h convert IsNoetherian.mk · exact isLocallyNoetherian_of_affine_cover hS h · constructor rw [← Opens.coe_top, ← hS, Opens.iSup_mk] apply isCompact_iUnion intro i apply isCompact_iff_isCompact_univ.mpr convert CompactSpace.isCompact_univ have : NoetherianSpace (S i) := by apply noetherianSpace_of_isAffineOpen (S i).1 (S i).2 apply NoetherianSpace.compactSpace (S i) /-- A version of `isNoetherian_iff_of_finite_iSup_eq_top` using `Scheme.OpenCover`. -/ theorem isNoetherian_iff_of_finite_affine_openCover {𝒰 : Scheme.OpenCover.{v, u} X} [Finite 𝒰.J] [∀ i, IsAffine (𝒰.obj i)] : IsNoetherian X ↔ ∀ (i : 𝒰.J), IsNoetherianRing Γ(𝒰.obj i, ⊤) := by constructor · intro h i apply (isLocallyNoetherian_iff_of_affine_openCover _).mp exact h.toIsLocallyNoetherian · intro hNoeth convert IsNoetherian.mk · exact (isLocallyNoetherian_iff_of_affine_openCover _).mpr hNoeth · exact Scheme.OpenCover.compactSpace 𝒰 open CategoryTheory in /-- A Noetherian scheme has a Noetherian underlying topological space. [Stacks, Lemma 01OZ](https://stacks.math.columbia.edu/tag/01OZ) -/ instance (priority := 100) IsNoetherian.noetherianSpace [IsNoetherian X] : NoetherianSpace X := by apply TopologicalSpace.noetherian_univ_iff.mp let 𝒰 := X.affineCover.finiteSubcover rw [← 𝒰.iUnion_range] suffices ∀ i : 𝒰.J, NoetherianSpace (Set.range <| (𝒰.map i).val.base) by apply NoetherianSpace.iUnion intro i have : IsAffine (𝒰.obj i) := by rw [X.affineCover.finiteSubcover_obj] apply Scheme.isAffine_affineCover let U : X.affineOpens := ⟨Scheme.Hom.opensRange (𝒰.map i), isAffineOpen_opensRange _⟩ convert noetherianSpace_of_isAffineOpen U.1 U.2 apply IsLocallyNoetherian.component_noetherian /-- Any morphism of schemes `f : X ⟶ Y` with `X` Noetherian is quasi-compact. [Stacks, Lemma 01P0](https://stacks.math.columbia.edu/tag/01P0) -/ instance (priority := 100) quasiCompact_of_noetherianSpace_source {X Y : Scheme} [NoetherianSpace X] (f : X ⟶ Y) : QuasiCompact f := ⟨fun _ _ _ => NoetherianSpace.isCompact _⟩ /-- If `R` is a Noetherian ring, `Spec R` is a locally Noetherian scheme. -/ instance {R : CommRingCat} [IsNoetherianRing R] : IsLocallyNoetherian (Spec R) := by apply isLocallyNoetherian_of_affine_cover (ι := Fin 1) (S := fun _ => ⟨⊤, isAffineOpen_top (Spec R)⟩) · exact iSup_const · intro apply isNoetherianRing_of_ringEquiv R apply CategoryTheory.Iso.commRingCatIsoToRingEquiv exact (Scheme.ΓSpecIso R).symm instance (priority := 100) {R : CommRingCat} [IsLocallyNoetherian (Spec R)] : IsNoetherianRing R := by have := IsLocallyNoetherian.component_noetherian ⟨⊤, AlgebraicGeometry.isAffineOpen_top (Spec R)⟩ apply isNoetherianRing_of_ringEquiv Γ(Spec R, ⊤) apply CategoryTheory.Iso.commRingCatIsoToRingEquiv exact Scheme.ΓSpecIso R /-- If `R` is a Noetherian ring, `Spec R` is a Noetherian scheme. -/ instance {R : CommRingCat} [IsNoetherianRing R] : IsNoetherian (Spec R) where instance {R} [CommRing R] [IsNoetherianRing R] : IsNoetherian (Spec (.of R)) := by suffices IsNoetherianRing (CommRingCat.of R) by infer_instance simp only [CommRingCat.coe_of] assumption /-- `R` is a Noetherian ring if and only if `Spec R` is a Noetherian scheme. -/ theorem isNoetherian_Spec {R : CommRingCat} : IsNoetherian (Spec R) ↔ IsNoetherianRing R := ⟨fun _ => inferInstance, fun _ => inferInstance⟩ /-- A Noetherian scheme has a finite number of irreducible components. [Stacks, Lemma 0BA8](https://stacks.math.columbia.edu/tag/0BA8) -/ theorem finite_irreducibleComponents_of_isNoetherian [IsNoetherian X] : (irreducibleComponents X).Finite := NoetherianSpace.finite_irreducibleComponents end AlgebraicGeometry
AlgebraicGeometry\OpenImmersion.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Geometry.RingedSpace.OpenImmersion import Mathlib.AlgebraicGeometry.Scheme import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Open immersions of schemes -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 noncomputable section open TopologicalSpace CategoryTheory Opposite open CategoryTheory.Limits namespace AlgebraicGeometry universe v v₁ v₂ u variable {C : Type u} [Category.{v} C] /-- A morphism of Schemes is an open immersion if it is an open immersion as a morphism of LocallyRingedSpaces -/ abbrev IsOpenImmersion {X Y : Scheme.{u}} (f : X ⟶ Y) : Prop := LocallyRingedSpace.IsOpenImmersion f instance IsOpenImmersion.comp {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) [IsOpenImmersion f] [IsOpenImmersion g] : IsOpenImmersion (f ≫ g) := LocallyRingedSpace.IsOpenImmersion.comp f g namespace LocallyRingedSpace.IsOpenImmersion /-- To show that a locally ringed space is a scheme, it suffices to show that it has a jointly surjective family of open immersions from affine schemes. -/ protected def scheme (X : LocallyRingedSpace.{u}) (h : ∀ x : X, ∃ (R : CommRingCat) (f : Spec.toLocallyRingedSpace.obj (op R) ⟶ X), (x ∈ Set.range f.1.base : _) ∧ LocallyRingedSpace.IsOpenImmersion f) : Scheme where toLocallyRingedSpace := X local_affine := by intro x obtain ⟨R, f, h₁, h₂⟩ := h x refine ⟨⟨⟨_, h₂.base_open.isOpen_range⟩, h₁⟩, R, ⟨?_⟩⟩ apply LocallyRingedSpace.isoOfSheafedSpaceIso refine SheafedSpace.forgetToPresheafedSpace.preimageIso ?_ apply PresheafedSpace.IsOpenImmersion.isoOfRangeEq (PresheafedSpace.ofRestrict _ _) f.1 · exact Subtype.range_coe_subtype · exact Opens.openEmbedding _ -- Porting note (#11187): was `infer_instance` end LocallyRingedSpace.IsOpenImmersion theorem IsOpenImmersion.isOpen_range {X Y : Scheme.{u}} (f : X ⟶ Y) [H : IsOpenImmersion f] : IsOpen (Set.range f.1.base) := H.base_open.isOpen_range @[deprecated (since := "2024-03-17")] alias IsOpenImmersion.open_range := IsOpenImmersion.isOpen_range namespace Scheme.Hom variable {X Y : Scheme.{u}} (f : Scheme.Hom X Y) [H : IsOpenImmersion f] theorem openEmbedding : OpenEmbedding f.1.base := H.base_open /-- The image of an open immersion as an open set. -/ @[simps] def opensRange : Y.Opens := ⟨_, f.openEmbedding.isOpen_range⟩ /-- The functor `opens X ⥤ opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor : X.Opens ⥤ Y.Opens := LocallyRingedSpace.IsOpenImmersion.opensFunctor f /-- `f ''ᵁ U` is notation for the image (as an open set) of `U` under an open immersion `f`. -/ scoped[AlgebraicGeometry] notation3:90 f:91 " ''ᵁ " U:90 => (Scheme.Hom.opensFunctor f).obj U lemma image_le_image_of_le {U V : X.Opens} (e : U ≤ V) : f ''ᵁ U ≤ f ''ᵁ V := by rintro a ⟨u, hu, rfl⟩ exact Set.mem_image_of_mem (⇑f.val.base) (e hu) @[simp] lemma opensFunctor_map_homOfLE {U V : X.Opens} (e : U ≤ V) : (Scheme.Hom.opensFunctor f).map (homOfLE e) = homOfLE (f.image_le_image_of_le e) := rfl @[simp] lemma image_top_eq_opensRange : f ''ᵁ ⊤ = f.opensRange := by apply Opens.ext simp @[simp] lemma preimage_image_eq (U : X.Opens) : f ⁻¹ᵁ f ''ᵁ U = U := by apply Opens.ext simp [Set.preimage_image_eq _ f.openEmbedding.inj] lemma image_preimage_eq_opensRange_inter (U : Y.Opens) : f ''ᵁ f ⁻¹ᵁ U = f.opensRange ⊓ U := by apply Opens.ext simp [Set.image_preimage_eq_range_inter] /-- The isomorphism `Γ(Y, f(U)) ≅ Γ(X, U)` induced by an open immersion `f : X ⟶ Y`. -/ def appIso (U) : Γ(Y, f ''ᵁ U) ≅ Γ(X, U) := (asIso <| LocallyRingedSpace.IsOpenImmersion.invApp f U).symm @[reassoc (attr := simp)] theorem appIso_inv_naturality {U V : X.Opens} (i : op U ⟶ op V) : X.presheaf.map i ≫ (f.appIso V).inv = (f.appIso U).inv ≫ Y.presheaf.map (f.opensFunctor.op.map i) := PresheafedSpace.IsOpenImmersion.inv_naturality _ _ theorem appIso_hom (U) : (f.appIso U).hom = f.app (f ''ᵁ U) ≫ X.presheaf.map (eqToHom (preimage_image_eq f U).symm).op := (PresheafedSpace.IsOpenImmersion.inv_invApp f.1 U).trans (by rw [eqToHom_op]) theorem appIso_hom' (U) : (f.appIso U).hom = f.appLE (f ''ᵁ U) U (preimage_image_eq f U).ge := f.appIso_hom U @[reassoc (attr := simp)] theorem app_appIso_inv (U) : f.app U ≫ (f.appIso (f ⁻¹ᵁ U)).inv = Y.presheaf.map (homOfLE (Set.image_preimage_subset f.1.base U.1)).op := PresheafedSpace.IsOpenImmersion.app_invApp _ _ /-- A variant of `app_invApp` that gives an `eqToHom` instead of `homOfLE`. -/ @[reassoc] theorem app_invApp' (U) (hU : U ≤ f.opensRange) : f.app U ≫ (f.appIso (f ⁻¹ᵁ U)).inv = Y.presheaf.map (eqToHom (Opens.ext <| by simpa [Set.image_preimage_eq_inter_range])).op := PresheafedSpace.IsOpenImmersion.app_invApp _ _ @[reassoc (attr := simp), elementwise (attr := simp)] theorem appIso_inv_app (U) : (f.appIso U).inv ≫ f.app (f ''ᵁ U) = X.presheaf.map (eqToHom (preimage_image_eq f U)).op := (PresheafedSpace.IsOpenImmersion.invApp_app _ _).trans (by rw [eqToHom_op]) @[reassoc (attr := simp), elementwise] lemma appLE_appIso_inv {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] {U : Y.Opens} {V : X.Opens} (e : V ≤ f ⁻¹ᵁ U) : f.appLE U V e ≫ (f.appIso V).inv = Y.presheaf.map (homOfLE <| (f.image_le_image_of_le e).trans (f.image_preimage_eq_opensRange_inter U ▸ inf_le_right)).op := by simp only [appLE, Category.assoc, appIso_inv_naturality, Functor.op_obj, Functor.op_map, Quiver.Hom.unop_op, opensFunctor_map_homOfLE, app_appIso_inv_assoc, Opens.carrier_eq_coe] rw [← Functor.map_comp] rfl @[reassoc (attr := simp)] lemma appIso_inv_appLE {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] {U V : X.Opens} (e : V ≤ f ⁻¹ᵁ f ''ᵁ U) : (f.appIso U).inv ≫ f.appLE (f ''ᵁ U) V e = X.presheaf.map (homOfLE (by rwa [preimage_image_eq] at e)).op := by simp only [appLE, appIso_inv_app_assoc, eqToHom_op] rw [← Functor.map_comp] rfl end Scheme.Hom /-- The open sets of an open subscheme corresponds to the open sets containing in the image. -/ @[simps] def IsOpenImmersion.opensEquiv {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] : X.Opens ≃ { U : Y.Opens // U ≤ f.opensRange } where toFun U := ⟨f ''ᵁ U, Set.image_subset_range _ _⟩ invFun U := f ⁻¹ᵁ U left_inv _ := Opens.ext (Set.preimage_image_eq _ f.openEmbedding.inj) right_inv U := Subtype.ext (Opens.ext (Set.image_preimage_eq_of_subset U.2)) namespace Scheme instance basic_open_isOpenImmersion {R : CommRingCat.{u}} (f : R) : IsOpenImmersion (Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away f)))) := by apply SheafedSpace.IsOpenImmersion.of_stalk_iso (H := ?_) · exact (PrimeSpectrum.localization_away_openEmbedding (Localization.Away f) f : _) · intro x exact Spec_map_localization_isIso R (Submonoid.powers f) x instance {R} [CommRing R] (f : R) : IsOpenImmersion (Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away f)))) := basic_open_isOpenImmersion (R := .of R) f lemma _root_.AlgebraicGeometry.IsOpenImmersion.of_isLocalization {R S} [CommRing R] [CommRing S] [Algebra R S] (f : R) [IsLocalization.Away f S] : IsOpenImmersion (Spec.map (CommRingCat.ofHom (algebraMap R S))) := by have e := (IsLocalization.algEquiv (.powers f) S (Localization.Away f)).symm.toAlgHom.comp_algebraMap rw [← e, CommRingCat.ringHom_comp_eq_comp] erw [Spec.map_comp] have H : IsIso (CommRingCat.ofHom (IsLocalization.algEquiv (Submonoid.powers f) S (Localization.Away f)).symm.toAlgHom.toRingHom) := by exact inferInstanceAs (IsIso <| (IsLocalization.algEquiv (Submonoid.powers f) S (Localization.Away f)).toRingEquiv.toCommRingCatIso.inv) simp only [AlgEquiv.toAlgHom_eq_coe, AlgHom.toRingHom_eq_coe, AlgEquiv.toAlgHom_toRingHom] at H ⊢ infer_instance theorem exists_affine_mem_range_and_range_subset {X : Scheme.{u}} {x : X} {U : X.Opens} (hxU : x ∈ U) : ∃ (R : CommRingCat) (f : Spec R ⟶ X), IsOpenImmersion f ∧ x ∈ Set.range f.1.base ∧ Set.range f.1.base ⊆ U := by obtain ⟨⟨V, hxV⟩, R, ⟨e⟩⟩ := X.2 x have : e.hom.1.base ⟨x, hxV⟩ ∈ (Opens.map (e.inv.1.base ≫ V.inclusion)).obj U := show ((e.hom ≫ e.inv).1.base ⟨x, hxV⟩).1 ∈ U from e.hom_inv_id ▸ hxU obtain ⟨_, ⟨_, ⟨r : R, rfl⟩, rfl⟩, hr, hr'⟩ := PrimeSpectrum.isBasis_basic_opens.exists_subset_of_mem_open this (Opens.is_open' _) let f : Spec (CommRingCat.of (Localization.Away r)) ⟶ X := Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away r))) ≫ (e.inv ≫ X.ofRestrict _ : _) refine ⟨.of (Localization.Away r), f, inferInstance, ?_⟩ rw [Scheme.comp_val_base, LocallyRingedSpace.comp_val, SheafedSpace.comp_base, TopCat.coe_comp, Set.range_comp] erw [PrimeSpectrum.localization_away_comap_range (Localization.Away r) r] exact ⟨⟨_, hr, congr(($(e.hom_inv_id).1.base ⟨x, hxV⟩).1)⟩, Set.image_subset_iff.mpr hr'⟩ end Scheme namespace PresheafedSpace.IsOpenImmersion section ToScheme variable {X : PresheafedSpace CommRingCat.{u}} (Y : Scheme.{u}) variable (f : X ⟶ Y.toPresheafedSpace) [H : PresheafedSpace.IsOpenImmersion f] /-- If `X ⟶ Y` is an open immersion, and `Y` is a scheme, then so is `X`. -/ def toScheme : Scheme := by apply LocallyRingedSpace.IsOpenImmersion.scheme (toLocallyRingedSpace _ f) intro x obtain ⟨R, i, _, h₁, h₂⟩ := Scheme.exists_affine_mem_range_and_range_subset (U := ⟨_, H.base_open.isOpen_range⟩) ⟨x, rfl⟩ refine ⟨R, LocallyRingedSpace.IsOpenImmersion.lift (toLocallyRingedSpaceHom _ f) _ h₂, ?_, ?_⟩ · rw [LocallyRingedSpace.IsOpenImmersion.lift_range]; exact h₁ · delta LocallyRingedSpace.IsOpenImmersion.lift; infer_instance @[simp] theorem toScheme_toLocallyRingedSpace : (toScheme Y f).toLocallyRingedSpace = toLocallyRingedSpace Y.1 f := rfl /-- If `X ⟶ Y` is an open immersion of PresheafedSpaces, and `Y` is a Scheme, we can upgrade it into a morphism of Schemes. -/ def toSchemeHom : toScheme Y f ⟶ Y := toLocallyRingedSpaceHom _ f @[simp] theorem toSchemeHom_val : (toSchemeHom Y f).val = f := rfl instance toSchemeHom_isOpenImmersion : AlgebraicGeometry.IsOpenImmersion (toSchemeHom Y f) := H theorem scheme_eq_of_locallyRingedSpace_eq {X Y : Scheme.{u}} (H : X.toLocallyRingedSpace = Y.toLocallyRingedSpace) : X = Y := by cases X; cases Y; congr theorem scheme_toScheme {X Y : Scheme.{u}} (f : X ⟶ Y) [AlgebraicGeometry.IsOpenImmersion f] : toScheme Y f.1 = X := by apply scheme_eq_of_locallyRingedSpace_eq exact locallyRingedSpace_toLocallyRingedSpace f end ToScheme end PresheafedSpace.IsOpenImmersion section Restrict variable {U : TopCat.{u}} (X : Scheme.{u}) {f : U ⟶ TopCat.of X} (h : OpenEmbedding f) /-- The restriction of a Scheme along an open embedding. -/ @[simps! (config := .lemmasOnly) carrier, simps! presheaf_obj] def Scheme.restrict : Scheme := { PresheafedSpace.IsOpenImmersion.toScheme X (X.toPresheafedSpace.ofRestrict h) with toPresheafedSpace := X.toPresheafedSpace.restrict h } lemma Scheme.restrict_toPresheafedSpace : (X.restrict h).toPresheafedSpace = X.toPresheafedSpace.restrict h := rfl /-- The canonical map from the restriction to the subspace. -/ @[simps! val_base, simps! (config := .lemmasOnly) val_c_app] def Scheme.ofRestrict : X.restrict h ⟶ X := X.toLocallyRingedSpace.ofRestrict h @[simp] lemma Scheme.ofRestrict_app (V) : (X.ofRestrict h).app V = X.presheaf.map (h.isOpenMap.adjunction.counit.app V).op := Scheme.ofRestrict_val_c_app X h (op V) instance IsOpenImmersion.ofRestrict : IsOpenImmersion (X.ofRestrict h) := show PresheafedSpace.IsOpenImmersion (X.toPresheafedSpace.ofRestrict h) by infer_instance @[simp] lemma Scheme.ofRestrict_appLE (V W e) : (X.ofRestrict h).appLE V W e = X.presheaf.map (homOfLE (show X.ofRestrict h ''ᵁ _ ≤ _ by exact Set.image_subset_iff.mpr e)).op := by dsimp [Hom.appLE] exact (X.presheaf.map_comp _ _).symm @[simp] lemma Scheme.ofRestrict_appIso (U) : (X.ofRestrict h).appIso U = Iso.refl _ := by ext1 simp only [restrict_presheaf_obj, Hom.appIso_hom', ofRestrict_appLE, homOfLE_refl, op_id, CategoryTheory.Functor.map_id, Iso.refl_hom] @[simp] lemma Scheme.restrict_presheaf_map (V W) (i : V ⟶ W) : (X.restrict h).presheaf.map i = X.presheaf.map (homOfLE (show X.ofRestrict h ''ᵁ W.unop ≤ X.ofRestrict h ''ᵁ V.unop from Set.image_subset _ i.unop.le)).op := rfl end Restrict namespace IsOpenImmersion variable {X Y Z : Scheme.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) variable [H : IsOpenImmersion f] instance (priority := 100) of_isIso [IsIso g] : IsOpenImmersion g := @LocallyRingedSpace.IsOpenImmersion.of_isIso _ _ _ (show IsIso ((inducedFunctor _).map g) by infer_instance) theorem to_iso {X Y : Scheme.{u}} (f : X ⟶ Y) [h : IsOpenImmersion f] [Epi f.1.base] : IsIso f := @isIso_of_reflects_iso _ _ _ _ _ _ f (Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace) (@PresheafedSpace.IsOpenImmersion.to_iso _ _ _ _ f.1 h _) _ theorem of_stalk_iso {X Y : Scheme.{u}} (f : X ⟶ Y) (hf : OpenEmbedding f.1.base) [∀ x, IsIso (f.stalkMap x)] : IsOpenImmersion f := haveI (x : X) : IsIso (f.val.stalkMap x) := inferInstanceAs <| IsIso (f.stalkMap x) SheafedSpace.IsOpenImmersion.of_stalk_iso f.1 hf instance stalk_iso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] (x : X) : IsIso (f.stalkMap x) := inferInstanceAs <| IsIso (f.val.stalkMap x) theorem iff_stalk_iso {X Y : Scheme.{u}} (f : X ⟶ Y) : IsOpenImmersion f ↔ OpenEmbedding f.1.base ∧ ∀ x, IsIso (f.stalkMap x) := ⟨fun H => ⟨H.1, fun x ↦ inferInstanceAs <| IsIso (f.val.stalkMap x)⟩, fun ⟨h₁, h₂⟩ => @IsOpenImmersion.of_stalk_iso _ _ f h₁ h₂⟩ theorem _root_.AlgebraicGeometry.isIso_iff_isOpenImmersion {X Y : Scheme.{u}} (f : X ⟶ Y) : IsIso f ↔ IsOpenImmersion f ∧ Epi f.1.base := ⟨fun _ => ⟨inferInstance, inferInstance⟩, fun ⟨h₁, h₂⟩ => @IsOpenImmersion.to_iso _ _ f h₁ h₂⟩ theorem _root_.AlgebraicGeometry.isIso_iff_stalk_iso {X Y : Scheme.{u}} (f : X ⟶ Y) : IsIso f ↔ IsIso f.1.base ∧ ∀ x, IsIso (f.stalkMap x) := by rw [isIso_iff_isOpenImmersion, IsOpenImmersion.iff_stalk_iso, and_comm, ← and_assoc] refine and_congr ⟨?_, ?_⟩ Iff.rfl · rintro ⟨h₁, h₂⟩ convert_to IsIso (TopCat.isoOfHomeo (Homeomorph.homeomorphOfContinuousOpen (Equiv.ofBijective _ ⟨h₂.inj, (TopCat.epi_iff_surjective _).mp h₁⟩) h₂.continuous h₂.isOpenMap)).hom infer_instance · intro H; exact ⟨inferInstance, (TopCat.homeoOfIso (asIso f.1.base)).openEmbedding⟩ /-- An open immersion induces an isomorphism from the domain onto the image -/ def isoRestrict : X ≅ (Z.restrict H.base_open : _) where __ := (LocallyRingedSpace.IsOpenImmersion.isoRestrict f) local notation "forget" => Scheme.forgetToLocallyRingedSpace instance mono : Mono f := (inducedFunctor _).mono_of_mono_map (show @Mono LocallyRingedSpace _ _ _ f by infer_instance) instance forget_map_isOpenImmersion : LocallyRingedSpace.IsOpenImmersion ((forget).map f) := ⟨H.base_open, H.c_iso⟩ instance hasLimit_cospan_forget_of_left : HasLimit (cospan f g ⋙ Scheme.forgetToLocallyRingedSpace) := by apply @hasLimitOfIso _ _ _ _ _ _ ?_ (diagramIsoCospan.{u} _).symm change HasLimit (cospan ((forget).map f) ((forget).map g)) infer_instance open CategoryTheory.Limits.WalkingCospan instance hasLimit_cospan_forget_of_left' : HasLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map f) ((forget).map g)) from inferInstance instance hasLimit_cospan_forget_of_right : HasLimit (cospan g f ⋙ forget) := by apply @hasLimitOfIso _ _ _ _ _ _ ?_ (diagramIsoCospan.{u} _).symm change HasLimit (cospan ((forget).map g) ((forget).map f)) infer_instance instance hasLimit_cospan_forget_of_right' : HasLimit (cospan ((cospan g f ⋙ forget).map Hom.inl) ((cospan g f ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map g) ((forget).map f)) from inferInstance instance forgetCreatesPullbackOfLeft : CreatesLimit (cospan f g) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toScheme Y (@pullback.snd LocallyRingedSpace _ _ _ _ f g _).1) (eqToIso (by simp) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) instance forgetCreatesPullbackOfRight : CreatesLimit (cospan g f) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toScheme Y (@pullback.fst LocallyRingedSpace _ _ _ _ g f _).1) (eqToIso (by simp) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) instance forgetPreservesOfLeft : PreservesLimit (cospan f g) forget := CategoryTheory.preservesLimitOfCreatesLimitAndHasLimit _ _ instance forgetPreservesOfRight : PreservesLimit (cospan g f) forget := preservesPullbackSymmetry _ _ _ instance hasPullback_of_left : HasPullback f g := hasLimit_of_created (cospan f g) forget instance hasPullback_of_right : HasPullback g f := hasLimit_of_created (cospan g f) forget instance pullback_snd_of_left : IsOpenImmersion (pullback.snd f g) := by have := PreservesPullback.iso_hom_snd forget f g dsimp only [Scheme.forgetToLocallyRingedSpace, inducedFunctor_map] at this rw [← this] change LocallyRingedSpace.IsOpenImmersion _ infer_instance instance pullback_fst_of_right : IsOpenImmersion (pullback.fst g f) := by rw [← pullbackSymmetry_hom_comp_snd] -- Porting note: was just `infer_instance`, it is a bit weird that no explicit class instance is -- provided but still class inference fail to find this exact LocallyRingedSpace.IsOpenImmersion.comp (H := inferInstance) _ instance pullback_to_base [IsOpenImmersion g] : IsOpenImmersion (limit.π (cospan f g) WalkingCospan.one) := by rw [← limit.w (cospan f g) WalkingCospan.Hom.inl] change IsOpenImmersion (_ ≫ f) -- Porting note: was just `infer_instance`, it is a bit weird that no explicit class instance is -- provided but still class inference fail to find this exact LocallyRingedSpace.IsOpenImmersion.comp (H := inferInstance) _ instance forgetToTopPreservesOfLeft : PreservesLimit (cospan f g) Scheme.forgetToTop := by delta Scheme.forgetToTop apply @Limits.compPreservesLimit (K := cospan f g) (F := forget) (G := LocallyRingedSpace.forgetToTop) ?_ ?_ · infer_instance apply @preservesLimitOfIsoDiagram (F := _) _ _ _ _ _ _ (diagramIsoCospan.{u} _).symm ?_ dsimp [LocallyRingedSpace.forgetToTop] infer_instance instance forgetToTopPreservesOfRight : PreservesLimit (cospan g f) Scheme.forgetToTop := preservesPullbackSymmetry _ _ _ theorem range_pullback_snd_of_left : Set.range (pullback.snd f g).1.base = (g ⁻¹ᵁ f.opensRange).1 := by rw [← show _ = (pullback.snd f g).1.base from PreservesPullback.iso_hom_snd Scheme.forgetToTop f g, TopCat.coe_comp, Set.range_comp, Set.range_iff_surjective.mpr, ← @Set.preimage_univ _ _ (pullback.fst f.1.base g.1.base)] -- Porting note (#10691): was `rw` · erw [TopCat.pullback_snd_image_fst_preimage] rw [Set.image_univ] rfl rw [← TopCat.epi_iff_surjective] infer_instance theorem opensRange_pullback_snd_of_left : (pullback.snd f g).opensRange = g ⁻¹ᵁ f.opensRange := Opens.ext (range_pullback_snd_of_left f g) theorem range_pullback_fst_of_right : Set.range (pullback.fst g f).1.base = ((Opens.map g.1.base).obj ⟨Set.range f.1.base, H.base_open.isOpen_range⟩).1 := by rw [← show _ = (pullback.fst g f).1.base from PreservesPullback.iso_hom_fst Scheme.forgetToTop g f, TopCat.coe_comp, Set.range_comp, Set.range_iff_surjective.mpr, ← @Set.preimage_univ _ _ (pullback.snd g.1.base f.1.base)] -- Porting note (#10691): was `rw` · erw [TopCat.pullback_fst_image_snd_preimage] rw [Set.image_univ] rfl rw [← TopCat.epi_iff_surjective] infer_instance theorem opensRange_pullback_fst_of_right : (pullback.fst g f).opensRange = g ⁻¹ᵁ f.opensRange := Opens.ext (range_pullback_fst_of_right f g) theorem range_pullback_to_base_of_left : Set.range (pullback.fst f g ≫ f).1.base = Set.range f.1.base ∩ Set.range g.1.base := by rw [pullback.condition, Scheme.comp_val_base, TopCat.coe_comp, Set.range_comp, range_pullback_snd_of_left, Opens.carrier_eq_coe, Opens.map_obj, Opens.coe_mk, Set.image_preimage_eq_inter_range, Opens.carrier_eq_coe, Scheme.Hom.opensRange_coe] theorem range_pullback_to_base_of_right : Set.range (pullback.fst g f ≫ g).1.base = Set.range g.1.base ∩ Set.range f.1.base := by rw [Scheme.comp_val_base, TopCat.coe_comp, Set.range_comp, range_pullback_fst_of_right, Opens.map_obj, Opens.carrier_eq_coe, Opens.coe_mk, Set.image_preimage_eq_inter_range, Set.inter_comm] /-- The universal property of open immersions: For an open immersion `f : X ⟶ Z`, given any morphism of schemes `g : Y ⟶ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟶ X` that commutes with these maps. -/ def lift (H' : Set.range g.1.base ⊆ Set.range f.1.base) : Y ⟶ X := LocallyRingedSpace.IsOpenImmersion.lift f g H' @[simp, reassoc] theorem lift_fac (H' : Set.range g.1.base ⊆ Set.range f.1.base) : lift f g H' ≫ f = g := LocallyRingedSpace.IsOpenImmersion.lift_fac f g H' theorem lift_uniq (H' : Set.range g.1.base ⊆ Set.range f.1.base) (l : Y ⟶ X) (hl : l ≫ f = g) : l = lift f g H' := LocallyRingedSpace.IsOpenImmersion.lift_uniq f g H' l hl /-- Two open immersions with equal range are isomorphic. -/ def isoOfRangeEq [IsOpenImmersion g] (e : Set.range f.1.base = Set.range g.1.base) : X ≅ Y where hom := lift g f (le_of_eq e) inv := lift f g (le_of_eq e.symm) hom_inv_id := by rw [← cancel_mono f]; simp inv_hom_id := by rw [← cancel_mono g]; simp @[simp, reassoc] lemma isoOfRangeEq_hom_fac {X Y Z : Scheme.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) [IsOpenImmersion f] [IsOpenImmersion g] (e : Set.range f.1.base = Set.range g.1.base) : (isoOfRangeEq f g e).hom ≫ g = f := lift_fac _ _ (le_of_eq e) @[simp, reassoc] lemma isoOfRangeEq_inv_fac {X Y Z : Scheme.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) [IsOpenImmersion f] [IsOpenImmersion g] (e : Set.range f.1.base = Set.range g.1.base) : (isoOfRangeEq f g e).inv ≫ f = g := lift_fac _ _ (le_of_eq e.symm) theorem app_eq_invApp_app_of_comp_eq_aux {X Y U : Scheme.{u}} (f : Y ⟶ U) (g : U ⟶ X) (fg : Y ⟶ X) (H : fg = f ≫ g) [h : IsOpenImmersion g] (V : U.Opens) : f ⁻¹ᵁ V = fg ⁻¹ᵁ (g ''ᵁ V) := by subst H rw [Scheme.comp_val_base, Opens.map_comp_obj] congr 1 ext1 exact (Set.preimage_image_eq _ h.base_open.inj).symm /-- The `fg` argument is to avoid nasty stuff about dependent types. -/ theorem app_eq_appIso_inv_app_of_comp_eq {X Y U : Scheme.{u}} (f : Y ⟶ U) (g : U ⟶ X) (fg : Y ⟶ X) (H : fg = f ≫ g) [h : IsOpenImmersion g] (V : U.Opens) : f.app V = (g.appIso V).inv ≫ fg.app (g ''ᵁ V) ≫ Y.presheaf.map (eqToHom <| IsOpenImmersion.app_eq_invApp_app_of_comp_eq_aux f g fg H V).op := by subst H rw [Scheme.comp_app, Category.assoc, Scheme.Hom.appIso_inv_app_assoc, f.naturality_assoc, ← Functor.map_comp, ← op_comp, Quiver.Hom.unop_op, eqToHom_map, eqToHom_trans, eqToHom_op, eqToHom_refl, CategoryTheory.Functor.map_id, Category.comp_id] theorem lift_app {X Y U : Scheme.{u}} (f : U ⟶ Y) (g : X ⟶ Y) [IsOpenImmersion f] (H) (V : U.Opens) : (IsOpenImmersion.lift f g H).app V = (f.appIso V).inv ≫ g.app (f ''ᵁ V) ≫ X.presheaf.map (eqToHom <| IsOpenImmersion.app_eq_invApp_app_of_comp_eq_aux _ _ _ (IsOpenImmersion.lift_fac f g H).symm V).op := IsOpenImmersion.app_eq_appIso_inv_app_of_comp_eq _ _ _ (lift_fac _ _ _).symm _ /-- If `f` is an open immersion `X ⟶ Y`, the global sections of `X` are naturally isomorphic to the sections of `Y` over the image of `f`. -/ noncomputable def ΓIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] (U : Y.Opens) : Γ(X, f⁻¹ᵁ U) ≅ Γ(Y, f.opensRange ⊓ U) := (f.appIso (f⁻¹ᵁ U)).symm ≪≫ Y.presheaf.mapIso (eqToIso <| (f.image_preimage_eq_opensRange_inter U).symm).op @[simp] lemma ΓIso_inv {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] (U : Y.Opens) : (ΓIso f U).inv = f.appLE (f.opensRange ⊓ U) (f⁻¹ᵁ U) (by rw [← f.image_preimage_eq_opensRange_inter, f.preimage_image_eq]) := by simp only [ΓIso, Iso.trans_inv, Functor.mapIso_inv, Iso.op_inv, eqToIso.inv, eqToHom_op, asIso_inv, IsIso.comp_inv_eq, Iso.symm_inv, Scheme.Hom.appIso_hom', Scheme.Hom.map_appLE] @[reassoc, elementwise] lemma map_ΓIso_inv {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] (U : Y.Opens) : Y.presheaf.map (homOfLE inf_le_right).op ≫ (ΓIso f U).inv = f.app U := by simp [Scheme.Hom.appLE_eq_app] @[reassoc, elementwise] lemma ΓIso_hom_map {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] (U : Y.Opens) : f.app U ≫ (ΓIso f U).hom = Y.presheaf.map (homOfLE inf_le_right).op := by rw [← map_ΓIso_inv] simp [-ΓIso_inv] /-- Given an open immersion `f : U ⟶ X`, the isomorphism between global sections of `U` and the sections of `X` at the image of `f`. -/ noncomputable def ΓIsoTop {X Y : Scheme.{u}} (f : X ⟶ Y) [IsOpenImmersion f] : Γ(X, ⊤) ≅ Γ(Y, f.opensRange) := (f.appIso ⊤).symm ≪≫ Y.presheaf.mapIso (eqToIso f.image_top_eq_opensRange.symm).op end IsOpenImmersion namespace Scheme theorem image_basicOpen {X Y : Scheme.{u}} (f : X ⟶ Y) [H : IsOpenImmersion f] {U : X.Opens} (r : Γ(X, U)) : f ''ᵁ X.basicOpen r = Y.basicOpen ((f.appIso U).inv r) := by have e := Scheme.preimage_basicOpen f ((f.appIso U).inv r) rw [Scheme.Hom.appIso_inv_app_apply, Scheme.basicOpen_res, inf_eq_right.mpr _] at e · rw [← e, f.image_preimage_eq_opensRange_inter, inf_eq_right] refine Set.Subset.trans (Scheme.basicOpen_le _ _) (Set.image_subset_range _ _) · exact (X.basicOpen_le r).trans (f.preimage_image_eq _).ge end Scheme end AlgebraicGeometry
AlgebraicGeometry\Properties.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.AffineScheme import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Topology.Sheaves.SheafCondition.Sites import Mathlib.Algebra.Category.Ring.Constructions import Mathlib.RingTheory.LocalProperties /-! # Basic properties of schemes We provide some basic properties of schemes ## Main definition * `AlgebraicGeometry.IsIntegral`: A scheme is integral if it is nontrivial and all nontrivial components of the structure sheaf are integral domains. * `AlgebraicGeometry.IsReduced`: A scheme is reduced if all the components of the structure sheaf are reduced. -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 universe u open TopologicalSpace Opposite CategoryTheory CategoryTheory.Limits TopCat namespace AlgebraicGeometry variable (X : Scheme) instance : T0Space X := by refine T0Space.of_open_cover fun x => ?_ obtain ⟨U, R, ⟨e⟩⟩ := X.local_affine x let e' : U.1 ≃ₜ PrimeSpectrum R := homeoOfIso ((LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget _).mapIso e) exact ⟨U.1.1, U.2, U.1.2, e'.embedding.t0Space⟩ instance : QuasiSober X := by apply (config := { allowSynthFailures := true }) quasiSober_of_open_cover (Set.range fun x => Set.range <| (X.affineCover.map x).1.base) · rintro ⟨_, i, rfl⟩; exact (X.affineCover.IsOpen i).base_open.isOpen_range · rintro ⟨_, i, rfl⟩ exact @OpenEmbedding.quasiSober _ _ _ _ _ (Homeomorph.ofEmbedding _ (X.affineCover.IsOpen i).base_open.toEmbedding).symm.openEmbedding PrimeSpectrum.quasiSober · rw [Set.top_eq_univ, Set.sUnion_range, Set.eq_univ_iff_forall] intro x; exact ⟨_, ⟨_, rfl⟩, X.affineCover.covers x⟩ /-- A scheme `X` is reduced if all `𝒪ₓ(U)` are reduced. -/ class IsReduced : Prop where component_reduced : ∀ U, IsReduced Γ(X, U) := by infer_instance attribute [instance] IsReduced.component_reduced theorem isReduced_of_isReduced_stalk [∀ x : X, _root_.IsReduced (X.presheaf.stalk x)] : IsReduced X := by refine ⟨fun U => ⟨fun s hs => ?_⟩⟩ apply Presheaf.section_ext X.sheaf U s 0 intro x rw [RingHom.map_zero] change X.presheaf.germ x s = 0 exact (hs.map _).eq_zero instance isReduced_stalk_of_isReduced [IsReduced X] (x : X) : _root_.IsReduced (X.presheaf.stalk x) := by constructor rintro g ⟨n, e⟩ obtain ⟨U, hxU, s, rfl⟩ := X.presheaf.germ_exist x g rw [← map_pow, ← map_zero (X.presheaf.germ ⟨x, hxU⟩)] at e obtain ⟨V, hxV, iU, iV, e'⟩ := X.presheaf.germ_eq x hxU hxU _ 0 e rw [map_pow, map_zero] at e' replace e' := (IsNilpotent.mk _ _ e').eq_zero (R := Γ(X, V)) erw [← ConcreteCategory.congr_hom (X.presheaf.germ_res iU ⟨x, hxV⟩) s] rw [comp_apply, e', map_zero] theorem isReduced_of_isOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f] [IsReduced Y] : IsReduced X := by constructor intro U have : U = f ⁻¹ᵁ f ''ᵁ U := by ext1; exact (Set.preimage_image_eq _ H.base_open.inj).symm rw [this] exact isReduced_of_injective (inv <| f.app (f ''ᵁ U)) (asIso <| f.app (f ''ᵁ U) : Γ(Y, f ''ᵁ U) ≅ _).symm.commRingCatIsoToRingEquiv.injective instance {R : CommRingCat.{u}} [H : _root_.IsReduced R] : IsReduced (Spec R) := by apply (config := { allowSynthFailures := true }) isReduced_of_isReduced_stalk intro x; dsimp have : _root_.IsReduced (CommRingCat.of <| Localization.AtPrime (PrimeSpectrum.asIdeal x)) := by dsimp; infer_instance exact isReduced_of_injective (StructureSheaf.stalkIso R x).hom (StructureSheaf.stalkIso R x).commRingCatIsoToRingEquiv.injective theorem affine_isReduced_iff (R : CommRingCat) : IsReduced (Spec R) ↔ _root_.IsReduced R := by refine ⟨?_, fun h => inferInstance⟩ intro h exact isReduced_of_injective (Scheme.ΓSpecIso R).inv (Scheme.ΓSpecIso R).symm.commRingCatIsoToRingEquiv.injective theorem isReduced_of_isAffine_isReduced [IsAffine X] [_root_.IsReduced Γ(X, ⊤)] : IsReduced X := isReduced_of_isOpenImmersion X.isoSpec.hom /-- To show that a statement `P` holds for all open subsets of all schemes, it suffices to show that 1. In any scheme `X`, if `P` holds for an open cover of `U`, then `P` holds for `U`. 2. For an open immerison `f : X ⟶ Y`, if `P` holds for the entire space of `X`, then `P` holds for the image of `f`. 3. `P` holds for the entire space of an affine scheme. -/ @[elab_as_elim] theorem reduce_to_affine_global (P : ∀ {X : Scheme} (_ : X.Opens), Prop) {X : Scheme} (U : X.Opens) (h₁ : ∀ (X : Scheme) (U : X.Opens), (∀ x : U, ∃ (V : _) (_ : x.1 ∈ V) (_ : V ⟶ U), P V) → P U) (h₂ : ∀ (X Y) (f : X ⟶ Y) [hf : IsOpenImmersion f], ∃ (U : Set X) (V : Set Y) (hU : U = ⊤) (hV : V = Set.range f.1.base), P ⟨U, hU.symm ▸ isOpen_univ⟩ → P ⟨V, hV.symm ▸ hf.base_open.isOpen_range⟩) (h₃ : ∀ R : CommRingCat, P (X := Spec R) ⊤) : P U := by apply h₁ intro x obtain ⟨_, ⟨j, rfl⟩, hx, i⟩ := X.affineBasisCover_is_basis.exists_subset_of_mem_open (SetLike.mem_coe.2 x.prop) U.isOpen let U' : Opens _ := ⟨_, (X.affineBasisCover.IsOpen j).base_open.isOpen_range⟩ let i' : U' ⟶ U := homOfLE i refine ⟨U', hx, i', ?_⟩ obtain ⟨_, _, rfl, rfl, h₂'⟩ := h₂ _ _ (X.affineBasisCover.map j) apply h₂' apply h₃ theorem reduce_to_affine_nbhd (P : ∀ (X : Scheme) (_ : X), Prop) (h₁ : ∀ R x, P (Spec R) x) (h₂ : ∀ {X Y} (f : X ⟶ Y) [IsOpenImmersion f] (x : X), P X x → P Y (f.1.base x)) : ∀ (X : Scheme) (x : X), P X x := by intro X x obtain ⟨y, e⟩ := X.affineCover.covers x convert h₂ (X.affineCover.map (X.affineCover.f x)) y _ · rw [e] apply h₁ theorem eq_zero_of_basicOpen_eq_bot {X : Scheme} [hX : IsReduced X] {U : X.Opens} (s : Γ(X, U)) (hs : X.basicOpen s = ⊥) : s = 0 := by apply TopCat.Presheaf.section_ext X.sheaf U intro x rw [RingHom.map_zero] induction U using reduce_to_affine_global generalizing hX with | h₁ X U hx => obtain ⟨V, hx, i, H⟩ := hx x specialize H (X.presheaf.map i.op s) erw [Scheme.basicOpen_res] at H rw [hs] at H specialize H (inf_bot_eq _) ⟨x, hx⟩ erw [TopCat.Presheaf.germ_res_apply] at H exact H | h₂ X Y f => have e : f.val.base ⁻¹' Set.range ↑f.val.base = Set.univ := by rw [← Set.image_univ, Set.preimage_image_eq _ ‹IsOpenImmersion f›.base_open.inj] refine ⟨_, _, e, rfl, ?_⟩ rintro H hX s hs ⟨_, x, rfl⟩ haveI := isReduced_of_isOpenImmersion f specialize H (f.app _ s) _ ⟨x, by rw [Opens.mem_mk, e]; trivial⟩ · rw [← Scheme.preimage_basicOpen, hs]; ext1; simp [Opens.map] · erw [← PresheafedSpace.stalkMap_germ_apply f.1 ⟨_, _⟩ ⟨x, _⟩] at H apply_fun inv <| f.stalkMap x at H erw [CategoryTheory.IsIso.hom_inv_id_apply, map_zero] at H exact H | h₃ R => rw [basicOpen_eq_of_affine', PrimeSpectrum.basicOpen_eq_bot_iff] at hs replace hs := (hs.map (Scheme.ΓSpecIso R).inv).eq_zero rw [Iso.hom_inv_id_apply] at hs rw [hs, map_zero] @[simp] theorem basicOpen_eq_bot_iff {X : Scheme} [IsReduced X] {U : X.Opens} (s : Γ(X, U)) : X.basicOpen s = ⊥ ↔ s = 0 := by refine ⟨eq_zero_of_basicOpen_eq_bot s, ?_⟩ rintro rfl simp /-- A scheme `X` is integral if its is nonempty, and `𝒪ₓ(U)` is an integral domain for each `U ≠ ∅`. -/ class IsIntegral : Prop where nonempty : Nonempty X := by infer_instance component_integral : ∀ (U : X.Opens) [Nonempty U], IsDomain Γ(X, U) := by infer_instance attribute [instance] IsIntegral.component_integral IsIntegral.nonempty instance [IsIntegral X] : IsDomain Γ(X, ⊤) := @IsIntegral.component_integral _ _ _ ⟨Nonempty.some inferInstance, trivial⟩ instance (priority := 900) isReduced_of_isIntegral [IsIntegral X] : IsReduced X := by constructor intro U rcases U.1.eq_empty_or_nonempty with h | h · have : U = ⊥ := SetLike.ext' h haveI : Subsingleton Γ(X, U) := CommRingCat.subsingleton_of_isTerminal (X.sheaf.isTerminalOfEqEmpty this) infer_instance · haveI : Nonempty U := by simpa infer_instance instance Scheme.component_nontrivial (X : Scheme.{u}) (U : X.Opens) [Nonempty U] : Nontrivial Γ(X, U) := LocallyRingedSpace.component_nontrivial (hU := ‹_›) instance irreducibleSpace_of_isIntegral [IsIntegral X] : IrreducibleSpace X := by by_contra H replace H : ¬IsPreirreducible (⊤ : Set X) := fun h => H { toPreirreducibleSpace := ⟨h⟩ toNonempty := inferInstance } simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩ erw [not_forall] at h₂ h₃ simp_rw [not_forall] at h₂ h₃ haveI : Nonempty (⟨Sᶜ, hS.1⟩ : X.Opens) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩ haveI : Nonempty (⟨Tᶜ, hT.1⟩ : X.Opens) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩ haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : X.Opens) := ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩ let e : Γ(X, _) ≅ CommRingCat.of _ := (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso (CommRingCat.prodFanIsLimit _ _) · have : IsDomain (Γ(X, ⟨Sᶜ, hS.1⟩) × Γ(X, ⟨Tᶜ, hT.1⟩)) := e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _ exact false_of_nontrivial_of_product_domain Γ(X, ⟨Sᶜ, hS.1⟩) Γ(X, ⟨Tᶜ, hT.1⟩) · ext x constructor · rintro ⟨hS, hT⟩ cases' h₁ (show x ∈ ⊤ by trivial) with h h exacts [hS h, hT h] · simp theorem isIntegral_of_irreducibleSpace_of_isReduced [IsReduced X] [H : IrreducibleSpace X] : IsIntegral X := by constructor; · infer_instance intro U hU haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1 have : NoZeroDivisors (X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by refine ⟨fun {a b} e => ?_⟩ simp_rw [← basicOpen_eq_bot_iff, ← Opens.not_nonempty_iff_eq_bot] by_contra! h obtain ⟨_, ⟨x, hx₁, rfl⟩, ⟨x, hx₂, e'⟩⟩ := nonempty_preirreducible_inter (X.basicOpen a).2 (X.basicOpen b).2 h.1 h.2 replace e' := Subtype.eq e' subst e' replace e := congr_arg (X.presheaf.germ x) e rw [RingHom.map_mul, RingHom.map_zero] at e refine zero_ne_one' (X.presheaf.stalk x.1) (isUnit_zero_iff.1 ?_) convert hx₁.mul hx₂ exact e.symm exact NoZeroDivisors.to_isDomain _ theorem isIntegral_iff_irreducibleSpace_and_isReduced : IsIntegral X ↔ IrreducibleSpace X ∧ IsReduced X := ⟨fun _ => ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ => isIntegral_of_irreducibleSpace_of_isReduced X⟩ theorem isIntegral_of_isOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f] [IsIntegral Y] [Nonempty X] : IsIntegral X := by constructor; · infer_instance intro U hU have : U = f ⁻¹ᵁ f ''ᵁ U := by ext1; exact (Set.preimage_image_eq _ H.base_open.inj).symm rw [this] have : IsDomain Γ(Y, f ''ᵁ U) := by apply (config := { allowSynthFailures := true }) IsIntegral.component_integral exact ⟨⟨_, _, hU.some.prop, rfl⟩⟩ exact (asIso <| f.app (f ''ᵁ U) : Γ(Y, f ''ᵁ U) ≅ _).symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _ instance {R : CommRingCat} [IsDomain R] : IrreducibleSpace (Spec R) := by convert PrimeSpectrum.irreducibleSpace (R := R) instance {R : CommRingCat} [IsDomain R] : IsIntegral (Spec R) := isIntegral_of_irreducibleSpace_of_isReduced _ theorem affine_isIntegral_iff (R : CommRingCat) : IsIntegral (Spec R) ↔ IsDomain R := ⟨fun _ => MulEquiv.isDomain Γ(Spec R, ⊤) (Scheme.ΓSpecIso R).symm.commRingCatIsoToRingEquiv.toMulEquiv, fun _ => inferInstance⟩ theorem isIntegral_of_isAffine_of_isDomain [IsAffine X] [Nonempty X] [IsDomain Γ(X, ⊤)] : IsIntegral X := isIntegral_of_isOpenImmersion X.isoSpec.hom theorem map_injective_of_isIntegral [IsIntegral X] {U V : X.Opens} (i : U ⟶ V) [H : Nonempty U] : Function.Injective (X.presheaf.map i.op) := by rw [injective_iff_map_eq_zero] intro x hx rw [← basicOpen_eq_bot_iff] at hx ⊢ rw [Scheme.basicOpen_res] at hx revert hx contrapose! simp_rw [Ne, ← Opens.not_nonempty_iff_eq_bot, Classical.not_not] apply nonempty_preirreducible_inter U.isOpen (RingedSpace.basicOpen _ _).isOpen simpa using H end AlgebraicGeometry
AlgebraicGeometry\Pullbacks.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Gluing import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.AlgebraicGeometry.AffineScheme import Mathlib.CategoryTheory.Limits.Shapes.Diagonal /-! # Fibred products of schemes In this file we construct the fibred product of schemes via gluing. We roughly follow [har77] Theorem 3.3. In particular, the main construction is to show that for an open cover `{ Uᵢ }` of `X`, if there exist fibred products `Uᵢ ×[Z] Y` for each `i`, then there exists a fibred product `X ×[Z] Y`. Then, for constructing the fibred product for arbitrary schemes `X, Y, Z`, we can use the construction to reduce to the case where `X, Y, Z` are all affine, where fibred products are constructed via tensor products. -/ universe v u noncomputable section open CategoryTheory CategoryTheory.Limits AlgebraicGeometry namespace AlgebraicGeometry.Scheme namespace Pullback variable {C : Type u} [Category.{v} C] variable {X Y Z : Scheme.{u}} (𝒰 : OpenCover.{u} X) (f : X ⟶ Z) (g : Y ⟶ Z) variable [∀ i, HasPullback (𝒰.map i ≫ f) g] /-- The intersection of `Uᵢ ×[Z] Y` and `Uⱼ ×[Z] Y` is given by (Uᵢ ×[Z] Y) ×[X] Uⱼ -/ def v (i j : 𝒰.J) : Scheme := pullback ((pullback.fst (𝒰.map i ≫ f) g) ≫ 𝒰.map i) (𝒰.map j) /-- The canonical transition map `(Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ (Uⱼ ×[Z] Y) ×[X] Uᵢ` given by the fact that pullbacks are associative and symmetric. -/ def t (i j : 𝒰.J) : v 𝒰 f g i j ⟶ v 𝒰 f g j i := by have : HasPullback (pullback.snd _ _ ≫ 𝒰.map i ≫ f) g := hasPullback_assoc_symm (𝒰.map j) (𝒰.map i) (𝒰.map i ≫ f) g have : HasPullback (pullback.snd _ _ ≫ 𝒰.map j ≫ f) g := hasPullback_assoc_symm (𝒰.map i) (𝒰.map j) (𝒰.map j ≫ f) g refine (pullbackSymmetry ..).hom ≫ (pullbackAssoc ..).inv ≫ ?_ refine ?_ ≫ (pullbackAssoc ..).hom ≫ (pullbackSymmetry ..).hom refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ · rw [pullbackSymmetry_hom_comp_snd_assoc, pullback.condition_assoc, Category.comp_id] · rw [Category.comp_id, Category.id_comp] @[simp, reassoc] theorem t_fst_fst (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.snd _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_inv_fst_fst, pullbackSymmetry_hom_comp_fst] @[simp, reassoc] theorem t_fst_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_snd, pullback.lift_snd, Category.comp_id, pullbackAssoc_inv_snd, pullbackSymmetry_hom_comp_snd_assoc] @[simp, reassoc] theorem t_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_hom_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_fst, pullbackAssoc_inv_fst_snd, pullbackSymmetry_hom_comp_snd_assoc] theorem t_id (i : 𝒰.J) : t 𝒰 f g i i = 𝟙 _ := by apply pullback.hom_ext <;> rw [Category.id_comp] · apply pullback.hom_ext · rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, Category.assoc, t_fst_fst] · simp only [Category.assoc, t_fst_snd] · rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, t_snd, Category.assoc] /-- The inclusion map of `V i j = (Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ Uᵢ ×[Z] Y`-/ abbrev fV (i j : 𝒰.J) : v 𝒰 f g i j ⟶ pullback (𝒰.map i ≫ f) g := pullback.fst _ _ /-- The map `((Xᵢ ×[Z] Y) ×[X] Xⱼ) ×[Xᵢ ×[Z] Y] ((Xᵢ ×[Z] Y) ×[X] Xₖ)` ⟶ `((Xⱼ ×[Z] Y) ×[X] Xₖ) ×[Xⱼ ×[Z] Y] ((Xⱼ ×[Z] Y) ×[X] Xᵢ)` needed for gluing -/ def t' (i j k : 𝒰.J) : pullback (fV 𝒰 f g i j) (fV 𝒰 f g i k) ⟶ pullback (fV 𝒰 f g j k) (fV 𝒰 f g j i) := by refine (pullbackRightPullbackFstIso ..).hom ≫ ?_ refine ?_ ≫ (pullbackSymmetry _ _).hom refine ?_ ≫ (pullbackRightPullbackFstIso ..).inv refine pullback.map _ _ _ _ (t 𝒰 f g i j) (𝟙 _) (𝟙 _) ?_ ?_ · simp_rw [Category.comp_id, t_fst_fst_assoc, ← pullback.condition] · rw [Category.comp_id, Category.id_comp] @[simp, reassoc] theorem t'_fst_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_fst, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_fst_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_snd, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_snd, pullback.lift_snd, Category.comp_id, pullbackRightPullbackFstIso_hom_snd] @[simp, reassoc] theorem t'_snd_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_fst, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_snd_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_snd, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_snd_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_snd, pullbackRightPullbackFstIso_hom_fst_assoc] theorem cocycle_fst_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ := by simp only [t'_fst_fst_fst, t'_fst_snd, t'_snd_snd] theorem cocycle_fst_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t'_fst_fst_snd] theorem cocycle_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t'_fst_snd, t'_snd_snd, t'_fst_fst_fst] theorem cocycle_snd_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ := by rw [← cancel_mono (𝒰.map i)] simp only [pullback.condition_assoc, t'_snd_fst_fst, t'_fst_snd, t'_snd_snd] theorem cocycle_snd_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [pullback.condition_assoc, t'_snd_fst_snd] theorem cocycle_snd_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by simp only [t'_snd_snd, t'_fst_fst_fst, t'_fst_snd] -- `by tidy` should solve it, but it times out. theorem cocycle (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j = 𝟙 _ := by apply pullback.hom_ext <;> rw [Category.id_comp] · apply pullback.hom_ext · apply pullback.hom_ext · simp_rw [Category.assoc, cocycle_fst_fst_fst 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_fst_fst_snd 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_fst_snd 𝒰 f g i j k] · apply pullback.hom_ext · apply pullback.hom_ext · simp_rw [Category.assoc, cocycle_snd_fst_fst 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_snd_fst_snd 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_snd_snd 𝒰 f g i j k] /-- Given `Uᵢ ×[Z] Y`, this is the glued fibered product `X ×[Z] Y`. -/ @[simps U V f t t', simps (config := .lemmasOnly) J] def gluing : Scheme.GlueData.{u} where J := 𝒰.J U i := pullback (𝒰.map i ≫ f) g V := fun ⟨i, j⟩ => v 𝒰 f g i j -- `p⁻¹(Uᵢ ∩ Uⱼ)` where `p : Uᵢ ×[Z] Y ⟶ Uᵢ ⟶ X`. f i j := pullback.fst _ _ f_id i := inferInstance f_open := inferInstance t i j := t 𝒰 f g i j t_id i := t_id 𝒰 f g i t' i j k := t' 𝒰 f g i j k t_fac i j k := by apply pullback.hom_ext on_goal 1 => apply pullback.hom_ext all_goals simp only [t'_snd_fst_fst, t'_snd_fst_snd, t'_snd_snd, t_fst_fst, t_fst_snd, t_snd, Category.assoc] cocycle i j k := cocycle 𝒰 f g i j k @[simp] lemma gluing_ι (j : 𝒰.J) : (gluing 𝒰 f g).ι j = Multicoequalizer.π (gluing 𝒰 f g).diagram j := rfl /-- The first projection from the glued scheme into `X`. -/ def p1 : (gluing 𝒰 f g).glued ⟶ X := by apply Multicoequalizer.desc (gluing 𝒰 f g).diagram _ fun i ↦ pullback.fst _ _ ≫ 𝒰.map i simp [t_fst_fst_assoc, ← pullback.condition] /-- The second projection from the glued scheme into `Y`. -/ def p2 : (gluing 𝒰 f g).glued ⟶ Y := by apply Multicoequalizer.desc _ _ fun i ↦ pullback.snd _ _ simp [t_fst_snd] theorem p_comm : p1 𝒰 f g ≫ f = p2 𝒰 f g ≫ g := by apply Multicoequalizer.hom_ext simp [p1, p2, pullback.condition] variable (s : PullbackCone f g) /-- (Implementation) The canonical map `(s.X ×[X] Uᵢ) ×[s.X] (s.X ×[X] Uⱼ) ⟶ (Uᵢ ×[Z] Y) ×[X] Uⱼ` This is used in `gluedLift`. -/ def gluedLiftPullbackMap (i j : 𝒰.J) : pullback ((𝒰.pullbackCover s.fst).map i) ((𝒰.pullbackCover s.fst).map j) ⟶ (gluing 𝒰 f g).V ⟨i, j⟩ := by refine (pullbackRightPullbackFstIso _ _ _).hom ≫ ?_ refine pullback.map _ _ _ _ ?_ (𝟙 _) (𝟙 _) ?_ ?_ · exact (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition · simpa using pullback.condition · simp only [Category.comp_id, Category.id_comp] @[reassoc] theorem gluedLiftPullbackMap_fst (i j : 𝒰.J) : gluedLiftPullbackMap 𝒰 f g s i j ≫ pullback.fst _ _ = pullback.fst _ _ ≫ (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition := by simp [gluedLiftPullbackMap] @[reassoc] theorem gluedLiftPullbackMap_snd (i j : 𝒰.J) : gluedLiftPullbackMap 𝒰 f g s i j ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by simp [gluedLiftPullbackMap] /-- The lifted map `s.X ⟶ (gluing 𝒰 f g).glued` in order to show that `(gluing 𝒰 f g).glued` is indeed the pullback. Given a pullback cone `s`, we have the maps `s.fst ⁻¹' Uᵢ ⟶ Uᵢ` and `s.fst ⁻¹' Uᵢ ⟶ s.X ⟶ Y` that we may lift to a map `s.fst ⁻¹' Uᵢ ⟶ Uᵢ ×[Z] Y`. to glue these into a map `s.X ⟶ Uᵢ ×[Z] Y`, we need to show that the maps agree on `(s.fst ⁻¹' Uᵢ) ×[s.X] (s.fst ⁻¹' Uⱼ) ⟶ Uᵢ ×[Z] Y`. This is achieved by showing that both of these maps factors through `gluedLiftPullbackMap`. -/ def gluedLift : s.pt ⟶ (gluing 𝒰 f g).glued := by fapply (𝒰.pullbackCover s.fst).glueMorphisms · exact fun i ↦ (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition ≫ (gluing 𝒰 f g).ι i intro i j rw [← gluedLiftPullbackMap_fst_assoc, ← gluing_f, ← (gluing 𝒰 f g).glue_condition i j, gluing_t, gluing_f] simp_rw [← Category.assoc] congr 1 apply pullback.hom_ext <;> simp_rw [Category.assoc] · rw [t_fst_fst, gluedLiftPullbackMap_snd] congr 1 rw [← Iso.inv_comp_eq, pullbackSymmetry_inv_comp_snd, pullback.lift_fst, Category.comp_id] · rw [t_fst_snd, gluedLiftPullbackMap_fst_assoc, pullback.lift_snd, pullback.lift_snd] simp_rw [pullbackSymmetry_hom_comp_snd_assoc] exact pullback.condition_assoc _ theorem gluedLift_p1 : gluedLift 𝒰 f g s ≫ p1 𝒰 f g = s.fst := by rw [← cancel_epi (𝒰.pullbackCover s.fst).fromGlued] apply Multicoequalizer.hom_ext intro b simp_rw [OpenCover.fromGlued, Multicoequalizer.π_desc_assoc, gluedLift, ← Category.assoc] simp_rw [(𝒰.pullbackCover s.fst).ι_glueMorphisms] simp [p1, pullback.condition] theorem gluedLift_p2 : gluedLift 𝒰 f g s ≫ p2 𝒰 f g = s.snd := by rw [← cancel_epi (𝒰.pullbackCover s.fst).fromGlued] apply Multicoequalizer.hom_ext intro b simp_rw [OpenCover.fromGlued, Multicoequalizer.π_desc_assoc, gluedLift, ← Category.assoc] simp_rw [(𝒰.pullbackCover s.fst).ι_glueMorphisms] simp [p2, pullback.condition] /-- (Implementation) The canonical map `(W ×[X] Uᵢ) ×[W] (Uⱼ ×[Z] Y) ⟶ (Uⱼ ×[Z] Y) ×[X] Uᵢ = V j i` where `W` is the glued fibred product. This is used in `lift_comp_ι`. -/ def pullbackFstιToV (i j : 𝒰.J) : pullback (pullback.fst (p1 𝒰 f g) (𝒰.map i)) ((gluing 𝒰 f g).ι j) ⟶ v 𝒰 f g j i := (pullbackSymmetry _ _ ≪≫ pullbackRightPullbackFstIso (p1 𝒰 f g) (𝒰.map i) _).hom ≫ (pullback.congrHom (Multicoequalizer.π_desc ..) rfl).hom @[simp, reassoc] theorem pullbackFstιToV_fst (i j : 𝒰.J) : pullbackFstιToV 𝒰 f g i j ≫ pullback.fst _ _ = pullback.snd _ _ := by simp [pullbackFstιToV, p1] @[simp, reassoc] theorem pullbackFstιToV_snd (i j : 𝒰.J) : pullbackFstιToV 𝒰 f g i j ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp [pullbackFstιToV, p1] /-- We show that the map `W ×[X] Uᵢ ⟶ Uᵢ ×[Z] Y ⟶ W` is the first projection, where the first map is given by the lift of `W ×[X] Uᵢ ⟶ Uᵢ` and `W ×[X] Uᵢ ⟶ W ⟶ Y`. It suffices to show that the two map agrees when restricted onto `Uⱼ ×[Z] Y`. In this case, both maps factor through `V j i` via `pullback_fst_ι_to_V` -/ theorem lift_comp_ι (i : 𝒰.J) : pullback.lift (pullback.snd _ _) (pullback.fst _ _ ≫ p2 𝒰 f g) (by rw [← pullback.condition_assoc, Category.assoc, p_comm]) ≫ (gluing 𝒰 f g).ι i = (pullback.fst _ _ : pullback (p1 𝒰 f g) (𝒰.map i) ⟶ _) := by apply ((gluing 𝒰 f g).openCover.pullbackCover (pullback.fst _ _)).hom_ext intro j dsimp only [OpenCover.pullbackCover] trans pullbackFstιToV 𝒰 f g i j ≫ fV 𝒰 f g j i ≫ (gluing 𝒰 f g).ι _ · rw [← show _ = fV 𝒰 f g j i ≫ _ from (gluing 𝒰 f g).glue_condition j i] simp_rw [← Category.assoc] congr 1 rw [gluing_f, gluing_t] apply pullback.hom_ext <;> simp_rw [Category.assoc] · simp_rw [t_fst_fst, pullback.lift_fst, pullbackFstιToV_snd, GlueData.openCover_map] · simp_rw [t_fst_snd, pullback.lift_snd, pullbackFstιToV_fst_assoc, pullback.condition_assoc, GlueData.openCover_map, p2] simp · rw [pullback.condition, ← Category.assoc] simp_rw [pullbackFstιToV_fst, GlueData.openCover_map] /-- The canonical isomorphism between `W ×[X] Uᵢ` and `Uᵢ ×[X] Y`. That is, the preimage of `Uᵢ` in `W` along `p1` is indeed `Uᵢ ×[X] Y`. -/ def pullbackP1Iso (i : 𝒰.J) : pullback (p1 𝒰 f g) (𝒰.map i) ≅ pullback (𝒰.map i ≫ f) g := by fconstructor · exact pullback.lift (pullback.snd _ _) (pullback.fst _ _ ≫ p2 𝒰 f g) (by rw [← pullback.condition_assoc, Category.assoc, p_comm]) · apply pullback.lift ((gluing 𝒰 f g).ι i) (pullback.fst _ _) rw [gluing_ι, p1, Multicoequalizer.π_desc] · apply pullback.hom_ext · simpa using lift_comp_ι 𝒰 f g i · simp_rw [Category.assoc, pullback.lift_snd, pullback.lift_fst, Category.id_comp] · apply pullback.hom_ext · simp_rw [Category.assoc, pullback.lift_fst, pullback.lift_snd, Category.id_comp] · simp [p2] @[simp, reassoc] theorem pullbackP1Iso_hom_fst (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).hom ≫ pullback.fst _ _ = pullback.snd _ _ := by simp_rw [pullbackP1Iso, pullback.lift_fst] @[simp, reassoc] theorem pullbackP1Iso_hom_snd (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).hom ≫ pullback.snd _ _ = pullback.fst _ _ ≫ p2 𝒰 f g := by simp_rw [pullbackP1Iso, pullback.lift_snd] @[simp, reassoc] theorem pullbackP1Iso_inv_fst (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).inv ≫ pullback.fst _ _ = (gluing 𝒰 f g).ι i := by simp_rw [pullbackP1Iso, pullback.lift_fst] @[simp, reassoc] theorem pullbackP1Iso_inv_snd (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).inv ≫ pullback.snd _ _ = pullback.fst _ _ := by simp_rw [pullbackP1Iso, pullback.lift_snd] @[simp, reassoc] theorem pullbackP1Iso_hom_ι (i : 𝒰.J) : (pullbackP1Iso 𝒰 f g i).hom ≫ Multicoequalizer.π (gluing 𝒰 f g).diagram i = pullback.fst _ _ := by rw [← gluing_ι, ← pullbackP1Iso_inv_fst, Iso.hom_inv_id_assoc] /-- The glued scheme (`(gluing 𝒰 f g).glued`) is indeed the pullback of `f` and `g`. -/ def gluedIsLimit : IsLimit (PullbackCone.mk _ _ (p_comm 𝒰 f g)) := by apply PullbackCone.isLimitAux' intro s refine ⟨gluedLift 𝒰 f g s, gluedLift_p1 𝒰 f g s, gluedLift_p2 𝒰 f g s, ?_⟩ intro m h₁ h₂ simp_rw [PullbackCone.mk_pt, PullbackCone.mk_π_app] at h₁ h₂ apply (𝒰.pullbackCover s.fst).hom_ext intro i rw [gluedLift, (𝒰.pullbackCover s.fst).ι_glueMorphisms, 𝒰.pullbackCover_map] rw [← cancel_epi (pullbackRightPullbackFstIso (p1 𝒰 f g) (𝒰.map i) m ≪≫ pullback.congrHom h₁ rfl).hom, Iso.trans_hom, Category.assoc, pullback.congrHom_hom, pullback.lift_fst_assoc, Category.comp_id, pullbackRightPullbackFstIso_hom_fst_assoc, pullback.condition] conv_lhs => rhs; rw [← pullbackP1Iso_hom_ι] simp_rw [← Category.assoc] congr 1 apply pullback.hom_ext · simp_rw [Category.assoc, pullbackP1Iso_hom_fst, pullback.lift_fst, Category.comp_id, pullbackSymmetry_hom_comp_fst, pullback.lift_snd, Category.comp_id, pullbackRightPullbackFstIso_hom_snd] · simp_rw [Category.assoc, pullbackP1Iso_hom_snd, pullback.lift_snd, pullbackSymmetry_hom_comp_snd_assoc, pullback.lift_fst_assoc, Category.comp_id, pullbackRightPullbackFstIso_hom_fst_assoc, ← pullback.condition_assoc, h₂] theorem hasPullback_of_cover : HasPullback f g := ⟨⟨⟨_, gluedIsLimit 𝒰 f g⟩⟩⟩ instance affine_hasPullback {A B C : CommRingCat} (f : Spec A ⟶ Spec C) (g : Spec B ⟶ Spec C) : HasPullback f g := by rw [← Scheme.Spec.map_preimage f, ← Scheme.Spec.map_preimage g] exact ⟨⟨⟨_, isLimitOfHasPullbackOfPreservesLimit Scheme.Spec (Scheme.Spec.preimage f) (Scheme.Spec.preimage g)⟩⟩⟩ theorem affine_affine_hasPullback {B C : CommRingCat} {X : Scheme} (f : X ⟶ Spec C) (g : Spec B ⟶ Spec C) : HasPullback f g := hasPullback_of_cover X.affineCover f g instance base_affine_hasPullback {C : CommRingCat} {X Y : Scheme} (f : X ⟶ Spec C) (g : Y ⟶ Spec C) : HasPullback f g := @hasPullback_symmetry _ _ _ _ _ _ _ (@hasPullback_of_cover _ _ _ Y.affineCover g f fun _ => @hasPullback_symmetry _ _ _ _ _ _ _ <| affine_affine_hasPullback _ _) instance left_affine_comp_pullback_hasPullback {X Y Z : Scheme} (f : X ⟶ Z) (g : Y ⟶ Z) (i : Z.affineCover.J) : HasPullback ((Z.affineCover.pullbackCover f).map i ≫ f) g := by simp only [OpenCover.pullbackCover_obj, OpenCover.pullbackCover_map, pullback.condition] exact hasPullback_assoc_symm f (Z.affineCover.map i) (Z.affineCover.map i) g instance {X Y Z : Scheme} (f : X ⟶ Z) (g : Y ⟶ Z) : HasPullback f g := hasPullback_of_cover (Z.affineCover.pullbackCover f) f g instance : HasPullbacks Scheme := hasPullbacks_of_hasLimit_cospan _ instance isAffine_of_isAffine_isAffine_isAffine {X Y Z : Scheme} (f : X ⟶ Z) (g : Y ⟶ Z) [IsAffine X] [IsAffine Y] [IsAffine Z] : IsAffine (pullback f g) := isAffine_of_isIso (pullback.map f g (Spec.map (Γ.map f.op)) (Spec.map (Γ.map g.op)) (ΓSpec.adjunction.unit.app X) (ΓSpec.adjunction.unit.app Y) (ΓSpec.adjunction.unit.app Z) (ΓSpec.adjunction.unit.naturality f) (ΓSpec.adjunction.unit.naturality g) ≫ (PreservesPullback.iso Scheme.Spec _ _).inv) /-- Given an open cover `{ Xᵢ }` of `X`, then `X ×[Z] Y` is covered by `Xᵢ ×[Z] Y`. -/ @[simps! J obj map] def openCoverOfLeft (𝒰 : OpenCover X) (f : X ⟶ Z) (g : Y ⟶ Z) : OpenCover (pullback f g) := by fapply ((gluing 𝒰 f g).openCover.pushforwardIso (limit.isoLimitCone ⟨_, gluedIsLimit 𝒰 f g⟩).inv).copy 𝒰.J (fun i => pullback (𝒰.map i ≫ f) g) (fun i => pullback.map _ _ _ _ (𝒰.map i) (𝟙 _) (𝟙 _) (Category.comp_id _) (by simp)) (Equiv.refl 𝒰.J) fun _ => Iso.refl _ rintro (i : 𝒰.J) simp_rw [OpenCover.pushforwardIso_J, OpenCover.pushforwardIso_map, GlueData.openCover_map, GlueData.openCover_J, gluing_J] exact pullback.hom_ext (by simp [p1]) (by simp [p2]) /-- Given an open cover `{ Yᵢ }` of `Y`, then `X ×[Z] Y` is covered by `X ×[Z] Yᵢ`. -/ @[simps! J obj map] def openCoverOfRight (𝒰 : OpenCover Y) (f : X ⟶ Z) (g : Y ⟶ Z) : OpenCover (pullback f g) := by fapply ((openCoverOfLeft 𝒰 g f).pushforwardIso (pullbackSymmetry _ _).hom).copy 𝒰.J (fun i => pullback f (𝒰.map i ≫ g)) (fun i => pullback.map _ _ _ _ (𝟙 _) (𝒰.map i) (𝟙 _) (by simp) (Category.comp_id _)) (Equiv.refl _) fun i => pullbackSymmetry _ _ intro i dsimp [OpenCover.bind] apply pullback.hom_ext <;> simp /-- Given an open cover `{ Xᵢ }` of `X` and an open cover `{ Yⱼ }` of `Y`, then `X ×[Z] Y` is covered by `Xᵢ ×[Z] Yⱼ`. -/ @[simps! J obj map] def openCoverOfLeftRight (𝒰X : X.OpenCover) (𝒰Y : Y.OpenCover) (f : X ⟶ Z) (g : Y ⟶ Z) : (pullback f g).OpenCover := by fapply ((openCoverOfLeft 𝒰X f g).bind fun x => openCoverOfRight 𝒰Y (𝒰X.map x ≫ f) g).copy (𝒰X.J × 𝒰Y.J) (fun ij => pullback (𝒰X.map ij.1 ≫ f) (𝒰Y.map ij.2 ≫ g)) (fun ij => pullback.map _ _ _ _ (𝒰X.map ij.1) (𝒰Y.map ij.2) (𝟙 _) (Category.comp_id _) (Category.comp_id _)) (Equiv.sigmaEquivProd _ _).symm fun _ => Iso.refl _ rintro ⟨i, j⟩ apply pullback.hom_ext <;> simp /-- (Implementation). Use `openCoverOfBase` instead. -/ @[simps! map] def openCoverOfBase' (𝒰 : OpenCover Z) (f : X ⟶ Z) (g : Y ⟶ Z) : OpenCover (pullback f g) := by apply (openCoverOfLeft (𝒰.pullbackCover f) f g).bind intro i have := PullbackCone.flipIsLimit <| pasteVertIsPullback rfl (pullbackIsPullback g (𝒰.map i)) (pullbackIsPullback (pullback.snd g (𝒰.map i)) (pullback.snd f (𝒰.map i))) refine @openCoverOfIsIso (f := (pullbackSymmetry _ _).hom ≫ (limit.isoLimitCone ⟨_, this⟩).inv ≫ pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) ?_ ?_) inferInstance · simp [← pullback.condition] · simp only [Category.comp_id, Category.id_comp] /-- Given an open cover `{ Zᵢ }` of `Z`, then `X ×[Z] Y` is covered by `Xᵢ ×[Zᵢ] Yᵢ`, where `Xᵢ = X ×[Z] Zᵢ` and `Yᵢ = Y ×[Z] Zᵢ` is the preimage of `Zᵢ` in `X` and `Y`. -/ @[simps! J obj map] def openCoverOfBase (𝒰 : OpenCover Z) (f : X ⟶ Z) (g : Y ⟶ Z) : OpenCover (pullback f g) := by apply (openCoverOfBase'.{u, u} 𝒰 f g).copy 𝒰.J (fun i => pullback (pullback.snd _ _ : pullback f (𝒰.map i) ⟶ _) (pullback.snd _ _ : pullback g (𝒰.map i) ⟶ _)) (fun i => pullback.map _ _ _ _ (pullback.fst _ _) (pullback.fst _ _) (𝒰.map i) pullback.condition.symm pullback.condition.symm) ((Equiv.prodPUnit 𝒰.J).symm.trans (Equiv.sigmaEquivProd 𝒰.J PUnit).symm) fun _ => Iso.refl _ intro i rw [Iso.refl_hom, Category.id_comp, openCoverOfBase'_map] apply pullback.hom_ext <;> dsimp <;> · simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Category.assoc, limit.lift_π_assoc, cospan_left, Category.comp_id, limit.isoLimitCone_inv_π, limit.isoLimitCone_inv_π_assoc, PullbackCone.flip_pt, PullbackCone.π_app_left, PullbackCone.π_app_right, PullbackCone.flip_fst, PullbackCone.flip_snd, pullbackSymmetry_hom_comp_snd_assoc, pullbackSymmetry_hom_comp_fst_assoc] rfl end Pullback end AlgebraicGeometry.Scheme namespace AlgebraicGeometry instance Scheme.pullback_map_isOpenImmersion {X Y S X' Y' S' : Scheme} (f : X ⟶ S) (g : Y ⟶ S) (f' : X' ⟶ S') (g' : Y' ⟶ S') (i₁ : X ⟶ X') (i₂ : Y ⟶ Y') (i₃ : S ⟶ S') (e₁ : f ≫ i₃ = i₁ ≫ f') (e₂ : g ≫ i₃ = i₂ ≫ g') [IsOpenImmersion i₁] [IsOpenImmersion i₂] [Mono i₃] : IsOpenImmersion (pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂) := by rw [pullback_map_eq_pullbackFstFstIso_inv] infer_instance section Spec variable (R S T : Type u) [CommRing R] [CommRing S] [CommRing T] [Algebra R S] [Algebra R T] open TensorProduct Algebra.TensorProduct CommRingCat RingHomClass /-- The isomorphism between the fiber product of two schemes `Spec S` and `Spec T` over a scheme `Spec R` and the `Spec` of the tensor product `S ⊗[R] T`.-/ noncomputable def pullbackSpecIso : pullback (Spec.map (CommRingCat.ofHom (algebraMap R S))) (Spec.map (CommRingCat.ofHom (algebraMap R T))) ≅ Spec (.of <| S ⊗[R] T) := letI H := IsLimit.equivIsoLimit (PullbackCone.eta _) (PushoutCocone.isColimitEquivIsLimitOp _ (CommRingCat.pushoutCoconeIsColimit R S T)) limit.isoLimitCone ⟨_, isLimitPullbackConeMapOfIsLimit Scheme.Spec _ H⟩ /-- The composition of the inverse of the isomorphism `pullbackSepcIso R S T` (from the pullback of `Spec S ⟶ Spec R` and `Spec T ⟶ Spec R` to `Spec (S ⊗[R] T)`) with the first projection is the morphism `Spec (S ⊗[R] T) ⟶ Spec S` obtained by applying `Spec.map` to the ring morphism `s ↦ s ⊗ₜ[R] 1`. -/ @[reassoc (attr := simp)] lemma pullbackSpecIso_inv_fst : (pullbackSpecIso R S T).inv ≫ pullback.fst _ _ = Spec.map (ofHom includeLeftRingHom) := limit.isoLimitCone_inv_π _ _ /-- The composition of the inverse of the isomorphism `pullbackSepcIso R S T` (from the pullback of `Spec S ⟶ Spec R` and `Spec T ⟶ Spec R` to `Spec (S ⊗[R] T)`) with the second projection is the morphism `Spec (S ⊗[R] T) ⟶ Spec T` obtained by applying `Spec.map` to the ring morphism `t ↦ 1 ⊗ₜ[R] t`. -/ @[reassoc (attr := simp)] lemma pullbackSpecIso_inv_snd : (pullbackSpecIso R S T).inv ≫ pullback.snd _ _ = Spec.map (ofHom (toRingHom includeRight)) := limit.isoLimitCone_inv_π _ _ /-- The composition of the isomorphism `pullbackSepcIso R S T` (from the pullback of `Spec S ⟶ Spec R` and `Spec T ⟶ Spec R` to `Spec (S ⊗[R] T)`) with the morphism `Spec (S ⊗[R] T) ⟶ Spec S` obtained by applying `Spec.map` to the ring morphism `s ↦ s ⊗ₜ[R] 1` is the first projection. -/ @[reassoc (attr := simp)] lemma pullbackSpecIso_hom_fst : (pullbackSpecIso R S T).hom ≫ Spec.map (ofHom includeLeftRingHom) = pullback.fst _ _ := by rw [← pullbackSpecIso_inv_fst, Iso.hom_inv_id_assoc] /-- The composition of the isomorphism `pullbackSepcIso R S T` (from the pullback of `Spec S ⟶ Spec R` and `Spec T ⟶ Spec R` to `Spec (S ⊗[R] T)`) with the morphism `Spec (S ⊗[R] T) ⟶ Spec T` obtained by applying `Spec.map` to the ring morphism `t ↦ 1 ⊗ₜ[R] t` is the second projection. -/ @[reassoc (attr := simp)] lemma pullbackSpecIso_hom_snd : (pullbackSpecIso R S T).hom ≫ Spec.map (ofHom (toRingHom includeRight)) = pullback.snd _ _ := by rw [← pullbackSpecIso_inv_snd, Iso.hom_inv_id_assoc] end Spec end AlgebraicGeometry
AlgebraicGeometry\Restrict.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Cover.Open /-! # Restriction of Schemes and Morphisms ## Main definition - `AlgebraicGeometry.Scheme.restrict`: The restriction of a scheme along an open embedding. The map `X.restrict f ⟶ X` is `AlgebraicGeometry.Scheme.ofRestrict`. `U : X.Opens` has a coercion to `Scheme` and `U.ι` is a shorthand for `X.restrict U.open_embedding : U ⟶ X`. - `AlgebraicGeometry.morphism_restrict`: The restriction of `X ⟶ Y` to `X ∣_ᵤ f ⁻¹ᵁ U ⟶ Y ∣_ᵤ U`. -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 noncomputable section open TopologicalSpace CategoryTheory Opposite open CategoryTheory.Limits namespace AlgebraicGeometry universe v v₁ v₂ u u₁ variable {C : Type u₁} [Category.{v} C] section variable {X : Scheme.{u}} (U : X.Opens) namespace Scheme.Opens /-- Open subset of a scheme as a scheme. -/ @[coe] def toScheme {X : Scheme.{u}} (U : X.Opens) : Scheme.{u} := X.restrict U.openEmbedding instance : CoeOut X.Opens Scheme := ⟨toScheme⟩ /-- The restriction of a scheme to an open subset. -/ @[simps! val_base_apply] def ι : ↑U ⟶ X := X.ofRestrict _ instance : IsOpenImmersion U.ι := inferInstanceAs (IsOpenImmersion (X.ofRestrict _)) lemma toScheme_carrier : (U : Type u) = (U : Set X) := rfl lemma toScheme_presheaf_obj (V) : Γ(U, V) = Γ(X, U.ι ''ᵁ V) := rfl @[simp] lemma toScheme_presheaf_map {V W} (i : V ⟶ W) : U.toScheme.presheaf.map i = X.presheaf.map (U.ι.opensFunctor.map i.unop).op := rfl @[simp] lemma ι_app (V) : U.ι.app V = X.presheaf.map (homOfLE (x := U.ι ''ᵁ U.ι ⁻¹ᵁ V) (Set.image_preimage_subset _ _)).op := rfl @[simp] lemma ι_appLE (V W e) : U.ι.appLE V W e = X.presheaf.map (homOfLE (x := U.ι ''ᵁ W) (Set.image_subset_iff.mpr ‹_›)).op := by simp only [Hom.appLE, ι_app, Functor.op_obj, Opens.carrier_eq_coe, toScheme_presheaf_map, Quiver.Hom.unop_op, Hom.opensFunctor_map_homOfLE, Opens.coe_inclusion, ← Functor.map_comp] rfl @[simp] lemma ι_appIso (V) : U.ι.appIso V = Iso.refl _ := X.ofRestrict_appIso _ _ @[simp] lemma opensRange_ι : U.ι.opensRange = U := Opens.ext Subtype.range_val @[simp] lemma range_ι : Set.range U.ι.val.base = U := Subtype.range_val lemma ι_image_top : U.ι ''ᵁ ⊤ = U := U.openEmbedding_obj_top @[simp] lemma ι_preimage_self : U.ι ⁻¹ᵁ U = ⊤ := Opens.inclusion_map_eq_top _ instance ι_appLE_isIso : IsIso (U.ι.appLE U ⊤ U.ι_preimage_self.ge) := by simp only [ι, ofRestrict_appLE] show IsIso (X.presheaf.map (eqToIso U.ι_image_top).hom.op) infer_instance lemma ι_app_self : U.ι.app U = X.presheaf.map (eqToHom (X := U.ι ''ᵁ _) (by simp)).op := rfl lemma eq_presheaf_map_eqToHom {V W : Opens U} (e : U.ι ''ᵁ V = U.ι ''ᵁ W) : X.presheaf.map (eqToHom e).op = U.toScheme.presheaf.map (eqToHom <| U.openEmbedding.functor_obj_injective e).op := rfl @[simp] lemma nonempty_iff : Nonempty U.toScheme ↔ (U : Set X).Nonempty := by simp only [toScheme_carrier, SetLike.coe_sort_coe, nonempty_subtype] rfl attribute [-simp] eqToHom_op in /-- The global sections of the restriction is isomorphic to the sections on the open set. -/ @[simps!] def topIso : Γ(U, ⊤) ≅ Γ(X, U) := X.presheaf.mapIso (eqToIso U.ι_image_top.symm).op /-- The stalks of an open subscheme are isomorphic to the stalks of the original scheme. -/ def stalkIso {X : Scheme.{u}} (U : X.Opens) (x : U) : U.toScheme.presheaf.stalk x ≅ X.presheaf.stalk x.1 := X.restrictStalkIso (Opens.openEmbedding _) _ @[reassoc (attr := simp)] lemma germ_stalkIso_hom {X : Scheme.{u}} (U : X.Opens) {V : U.toScheme.Opens} (x : V) : U.toScheme.presheaf.germ x ≫ (U.stalkIso x.1).hom = X.presheaf.germ ⟨x.1.1, show x.1.1 ∈ U.ι ''ᵁ V from ⟨x.1, x.2, rfl⟩⟩ := PresheafedSpace.restrictStalkIso_hom_eq_germ _ U.openEmbedding _ _ _ @[reassoc (attr := simp)] lemma germ_stalkIso_hom' {X : Scheme.{u}} (U : X.Opens) {V : TopologicalSpace.Opens U} (x : U) (hx : x ∈ V) : U.toScheme.presheaf.germ ⟨x, hx⟩ ≫ (U.stalkIso x).hom = X.presheaf.germ ⟨x.1, show x.1 ∈ U.ι ''ᵁ V from ⟨x, hx, rfl⟩⟩ := PresheafedSpace.restrictStalkIso_hom_eq_germ _ U.openEmbedding _ _ _ @[simp, reassoc] lemma germ_stalkIso_inv {X : Scheme.{u}} (U : X.Opens) (V : U.toScheme.Opens) (x : U) (hx : x ∈ V) : X.presheaf.germ ⟨x.val, show x.val ∈ U.ι ''ᵁ V from ⟨x, hx, rfl⟩⟩ ≫ (U.stalkIso x).inv = U.toScheme.presheaf.germ ⟨x, hx⟩ := PresheafedSpace.restrictStalkIso_inv_eq_germ X.toPresheafedSpace U.openEmbedding V x hx end Scheme.Opens /-- If `U` is a family of open sets that covers `X`, then `X.restrict U` forms an `X.open_cover`. -/ @[simps! J obj map] def Scheme.openCoverOfISupEqTop {s : Type*} (X : Scheme.{u}) (U : s → X.Opens) (hU : ⨆ i, U i = ⊤) : X.OpenCover where J := s obj i := U i map i := (U i).ι f x := haveI : x ∈ ⨆ i, U i := hU.symm ▸ show x ∈ (⊤ : X.Opens) by trivial (Opens.mem_iSup.mp this).choose covers x := by erw [Subtype.range_coe] have : x ∈ ⨆ i, U i := hU.symm ▸ show x ∈ (⊤ : X.Opens) by trivial exact (Opens.mem_iSup.mp this).choose_spec @[deprecated (since := "2024-07-24")] noncomputable alias Scheme.openCoverOfSuprEqTop := Scheme.openCoverOfISupEqTop /-- The open sets of an open subscheme corresponds to the open sets containing in the subset. -/ @[simps!] def opensRestrict : Scheme.Opens U ≃ { V : X.Opens // V ≤ U } := (IsOpenImmersion.opensEquiv (U.ι)).trans (Equiv.subtypeEquivProp (by simp)) instance ΓRestrictAlgebra {X : Scheme.{u}} (U : X.Opens) : Algebra (Γ(X, ⊤)) Γ(U, ⊤) := (U.ι.app ⊤).toAlgebra lemma Scheme.map_basicOpen' (r : Γ(U, ⊤)) : U.ι ''ᵁ (U.toScheme.basicOpen r) = X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by refine (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans ?_ erw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op] rw [← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl, op_id, CategoryTheory.Functor.map_id] congr exact PresheafedSpace.IsOpenImmersion.ofRestrict_invApp _ _ _ lemma Scheme.Opens.ι_image_basicOpen (r : Γ(U, ⊤)) : U.ι ''ᵁ (U.toScheme.basicOpen r) = X.basicOpen r := by rw [Scheme.map_basicOpen', Scheme.basicOpen_res_eq] lemma Scheme.map_basicOpen_map (r : Γ(X, U)) : U.ι ''ᵁ (U.toScheme.basicOpen <| U.topIso.inv r) = X.basicOpen r := by simp only [Scheme.Opens.toScheme_presheaf_obj] rw [Scheme.map_basicOpen', Scheme.basicOpen_res_eq, Scheme.Opens.topIso_inv, Scheme.basicOpen_res_eq X] -- Porting note: `simps` can't synthesize `obj_left, obj_hom, mapLeft` variable (X) in /-- The functor taking open subsets of `X` to open subschemes of `X`. -/ -- @[simps obj_left obj_hom mapLeft] def Scheme.restrictFunctor : X.Opens ⥤ Over X where obj U := Over.mk U.ι map {U V} i := Over.homMk (IsOpenImmersion.lift V.ι U.ι <| by simpa using i.le) (IsOpenImmersion.lift_fac _ _ _) map_id U := by ext1 dsimp only [Over.homMk_left, Over.id_left] rw [← cancel_mono U.ι, Category.id_comp, IsOpenImmersion.lift_fac] map_comp {U V W} i j := by ext1 dsimp only [Over.homMk_left, Over.comp_left] rw [← cancel_mono W.ι, Category.assoc] iterate 3 rw [IsOpenImmersion.lift_fac] @[simp] lemma Scheme.restrictFunctor_obj_left (U : X.Opens) : (X.restrictFunctor.obj U).left = U := rfl @[simp] lemma Scheme.restrictFunctor_obj_hom (U : X.Opens) : (X.restrictFunctor.obj U).hom = U.ι := rfl @[simp] lemma Scheme.restrictFunctor_map_left {U V : X.Opens} (i : U ⟶ V) : (X.restrictFunctor.map i).left = IsOpenImmersion.lift (V.ι) U.ι (by simpa using i.le) := rfl -- Porting note: the `by ...` used to be automatically done by unification magic @[reassoc] theorem Scheme.restrictFunctor_map_ofRestrict {U V : X.Opens} (i : U ⟶ V) : (X.restrictFunctor.map i).1 ≫ V.ι = U.ι := IsOpenImmersion.lift_fac _ _ (by simpa using i.le) theorem Scheme.restrictFunctor_map_base {U V : X.Opens} (i : U ⟶ V) : (X.restrictFunctor.map i).1.val.base = (Opens.toTopCat _).map i := by ext a; refine Subtype.ext ?_ -- Porting note: `ext` did not pick up `Subtype.ext` exact (congr_arg (fun f : X.restrict U.openEmbedding ⟶ X => f.val.base a) (X.restrictFunctor_map_ofRestrict i)) theorem Scheme.restrictFunctor_map_app_aux {U V : X.Opens} (i : U ⟶ V) (W : Opens V) : U.ι ''ᵁ ((X.restrictFunctor.map i).1 ⁻¹ᵁ W) ≤ V.ι ''ᵁ W := by simp only [← SetLike.coe_subset_coe, IsOpenMap.functor_obj_coe, Set.image_subset_iff, Scheme.restrictFunctor_map_base, Opens.map_coe, Opens.inclusion_apply] rintro _ h exact ⟨_, h, rfl⟩ theorem Scheme.restrictFunctor_map_app {U V : X.Opens} (i : U ⟶ V) (W : Opens V) : (X.restrictFunctor.map i).1.app W = X.presheaf.map (homOfLE <| X.restrictFunctor_map_app_aux i W).op := by have e₁ := Scheme.congr_app (X.restrictFunctor_map_ofRestrict i) (V.ι ''ᵁ W) have : V.ι ⁻¹ᵁ V.ι ''ᵁ W = W := W.map_functor_eq (U := V) have e₂ := (X.restrictFunctor.map i).1.naturality (eqToIso this).hom.op have e₃ := e₂.symm.trans e₁ dsimp at e₃ ⊢ rw [← IsIso.eq_comp_inv, ← Functor.map_inv, ← Functor.map_comp] at e₃ rw [e₃, ← Functor.map_comp] congr 1 /-- The functor that restricts to open subschemes and then takes global section is isomorphic to the structure sheaf. -/ @[simps!] def Scheme.restrictFunctorΓ : X.restrictFunctor.op ⋙ (Over.forget X).op ⋙ Scheme.Γ ≅ X.presheaf := NatIso.ofComponents (fun U => X.presheaf.mapIso ((eqToIso (unop U).openEmbedding_obj_top).symm.op : _)) (by intro U V i dsimp [-Scheme.restrictFunctor_map_left] rw [X.restrictFunctor_map_app, ← Functor.map_comp, ← Functor.map_comp] congr 1) /-- `X ∣_ U ∣_ V` is isomorphic to `X ∣_ V ∣_ U` -/ noncomputable def Scheme.restrictRestrictComm (X : Scheme.{u}) (U V : X.Opens) : (U.ι ⁻¹ᵁ V).toScheme ≅ V.ι ⁻¹ᵁ U := IsOpenImmersion.isoOfRangeEq (Opens.ι _ ≫ U.ι) (Opens.ι _ ≫ V.ι) <| by simp [Set.image_preimage_eq_inter_range, Set.inter_comm (U : Set X), Set.range_comp] /-- If `V` is an open subset of `U`, then `X ∣_ U ∣_ V` is isomorphic to `X ∣_ V`. -/ noncomputable def Scheme.restrictRestrict (X : Scheme.{u}) (U : X.Opens) (V : U.toScheme.Opens) : V.toScheme ≅ U.ι ''ᵁ V := IsOpenImmersion.isoOfRangeEq (Opens.ι _ ≫ U.ι) (Opens.ι _) (by simp [Set.range_comp]) @[simp, reassoc] lemma Scheme.restrictRestrict_hom_restrict (X : Scheme.{u}) (U : X.Opens) (V : U.toScheme.Opens) : (X.restrictRestrict U V).hom ≫ Opens.ι _ = V.ι ≫ U.ι := IsOpenImmersion.isoOfRangeEq_hom_fac _ _ _ @[simp, reassoc] lemma Scheme.restrictRestrict_inv_restrict_restrict (X : Scheme.{u}) (U : X.Opens) (V : U.toScheme.Opens) : (X.restrictRestrict U V).inv ≫ V.ι ≫ U.ι = Opens.ι _ := IsOpenImmersion.isoOfRangeEq_inv_fac _ _ _ /-- If `U = V`, then `X ∣_ U` is isomorphic to `X ∣_ V`. -/ noncomputable def Scheme.restrictIsoOfEq (X : Scheme.{u}) {U V : X.Opens} (e : U = V) : (U : Scheme.{u}) ≅ V := IsOpenImmersion.isoOfRangeEq U.ι (V.ι) (by rw [e]) end /-- The restriction of an isomorphism onto an open set. -/ noncomputable abbrev Scheme.restrictMapIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] (U : Y.Opens) : (f ⁻¹ᵁ U).toScheme ≅ U := by apply IsOpenImmersion.isoOfRangeEq (f := (f ⁻¹ᵁ U).ι ≫ f) U.ι _ dsimp rw [Set.range_comp, Opens.range_ι, Opens.range_ι] refine @Set.image_preimage_eq _ _ f.val.base U.1 f.homeomorph.surjective section MorphismRestrict /-- Given a morphism `f : X ⟶ Y` and an open set `U ⊆ Y`, we have `X ×[Y] U ≅ X |_{f ⁻¹ U}` -/ def pullbackRestrictIsoRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : pullback f (U.ι) ≅ f ⁻¹ᵁ U := by refine IsOpenImmersion.isoOfRangeEq (pullback.fst f _) (Scheme.Opens.ι _) ?_ simp [IsOpenImmersion.range_pullback_fst_of_right] @[simp, reassoc] theorem pullbackRestrictIsoRestrict_inv_fst {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : (pullbackRestrictIsoRestrict f U).inv ≫ pullback.fst f _ = (f ⁻¹ᵁ U).ι := by delta pullbackRestrictIsoRestrict; simp @[simp, reassoc] theorem pullbackRestrictIsoRestrict_hom_restrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : (pullbackRestrictIsoRestrict f U).hom ≫ (f ⁻¹ᵁ U).ι = pullback.fst f _ := by delta pullbackRestrictIsoRestrict; simp /-- The restriction of a morphism `X ⟶ Y` onto `X |_{f ⁻¹ U} ⟶ Y |_ U`. -/ def morphismRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : (f ⁻¹ᵁ U).toScheme ⟶ U := (pullbackRestrictIsoRestrict f U).inv ≫ pullback.snd _ _ /-- the notation for restricting a morphism of scheme to an open subset of the target scheme -/ infixl:85 " ∣_ " => morphismRestrict @[simp, reassoc] theorem pullbackRestrictIsoRestrict_hom_morphismRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : (pullbackRestrictIsoRestrict f U).hom ≫ f ∣_ U = pullback.snd _ _ := Iso.hom_inv_id_assoc _ _ @[simp, reassoc] theorem morphismRestrict_ι {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : (f ∣_ U) ≫ U.ι = (f ⁻¹ᵁ U).ι ≫ f := by delta morphismRestrict rw [Category.assoc, pullback.condition.symm, pullbackRestrictIsoRestrict_inv_fst_assoc] theorem isPullback_morphismRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : IsPullback (f ∣_ U) (f ⁻¹ᵁ U).ι U.ι f := by delta morphismRestrict rw [← Category.id_comp f] refine (IsPullback.of_horiz_isIso ⟨?_⟩).paste_horiz (IsPullback.of_hasPullback f (Y.ofRestrict U.openEmbedding)).flip -- Porting note: changed `rw` to `erw` erw [pullbackRestrictIsoRestrict_inv_fst]; rw [Category.comp_id] @[simp] lemma morphismRestrict_id {X : Scheme.{u}} (U : X.Opens) : 𝟙 X ∣_ U = 𝟙 _ := by rw [← cancel_mono U.ι, morphismRestrict_ι, Category.comp_id, Category.id_comp] rfl theorem morphismRestrict_comp {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) (U : Opens Z) : (f ≫ g) ∣_ U = f ∣_ g ⁻¹ᵁ U ≫ g ∣_ U := by delta morphismRestrict rw [← pullbackRightPullbackFstIso_inv_snd_snd] simp_rw [← Category.assoc] congr 1 rw [← cancel_mono (pullback.fst _ _)] simp_rw [Category.assoc] rw [pullbackRestrictIsoRestrict_inv_fst, pullbackRightPullbackFstIso_inv_snd_fst, ← pullback.condition, pullbackRestrictIsoRestrict_inv_fst_assoc, pullbackRestrictIsoRestrict_inv_fst_assoc] rfl instance {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] (U : Y.Opens) : IsIso (f ∣_ U) := by delta morphismRestrict; infer_instance theorem morphismRestrict_base_coe {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (x) : @Coe.coe U Y (⟨fun x => x.1⟩) ((f ∣_ U).val.base x) = f.val.base x.1 := congr_arg (fun f => PresheafedSpace.Hom.base (LocallyRingedSpace.Hom.val f) x) (morphismRestrict_ι f U) theorem morphismRestrict_val_base {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : ⇑(f ∣_ U).val.base = U.1.restrictPreimage f.val.base := funext fun x => Subtype.ext (morphismRestrict_base_coe f U x) theorem image_morphismRestrict_preimage {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (V : Opens U) : (f ⁻¹ᵁ U).ι ''ᵁ ((f ∣_ U) ⁻¹ᵁ V) = f ⁻¹ᵁ (U.ι ''ᵁ V) := by ext1 ext x constructor · rintro ⟨⟨x, hx⟩, hx' : (f ∣_ U).val.base _ ∈ V, rfl⟩ refine ⟨⟨_, hx⟩, ?_, rfl⟩ -- Porting note: this rewrite was not necessary rw [SetLike.mem_coe] convert hx' -- Porting note: `ext1` is not compiling refine Subtype.ext ?_ exact (morphismRestrict_base_coe f U ⟨x, hx⟩).symm · rintro ⟨⟨x, hx⟩, hx' : _ ∈ V.1, rfl : x = _⟩ refine ⟨⟨_, hx⟩, (?_ : (f ∣_ U).val.base ⟨x, hx⟩ ∈ V.1), rfl⟩ convert hx' -- Porting note: `ext1` is compiling refine Subtype.ext ?_ exact morphismRestrict_base_coe f U ⟨x, hx⟩ lemma eqToHom_eq_homOfLE {C} [Preorder C] {X Y : C} (e : X = Y) : eqToHom e = homOfLE e.le := rfl open Scheme in theorem morphismRestrict_app {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (V : U.toScheme.Opens) : (f ∣_ U).app V = f.app (U.ι ''ᵁ V) ≫ X.presheaf.map (eqToHom (image_morphismRestrict_preimage f U V)).op := by have := Scheme.congr_app (morphismRestrict_ι f U) (U.ι ''ᵁ V) simp only [Scheme.preimage_comp, Opens.toScheme_presheaf_obj, Hom.app_eq_appLE, comp_appLE, Opens.ι_appLE, eqToHom_op, Opens.toScheme_presheaf_map, eqToHom_unop] at this have e : U.ι ⁻¹ᵁ (U.ι ''ᵁ V) = V := Opens.ext (Set.preimage_image_eq _ Subtype.coe_injective) have e' : (f ∣_ U) ⁻¹ᵁ V = (f ∣_ U) ⁻¹ᵁ U.ι ⁻¹ᵁ U.ι ''ᵁ V := by rw [e] simp only [Opens.toScheme_presheaf_obj, Hom.app_eq_appLE, eqToHom_op, Hom.appLE_map] rw [← (f ∣_ U).appLE_map' _ e', ← (f ∣_ U).map_appLE' _ e] simp only [Opens.toScheme_presheaf_obj, eqToHom_eq_homOfLE, Opens.toScheme_presheaf_map, Quiver.Hom.unop_op, Hom.opensFunctor_map_homOfLE] rw [this, Hom.appLE_map, Hom.appLE_map, Hom.appLE_map] @[simp] theorem morphismRestrict_app' {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (V : Opens U) : (f ∣_ U).app V = f.appLE _ _ (image_morphismRestrict_preimage f U V).le := morphismRestrict_app f U V @[simp] theorem morphismRestrict_appLE {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (V W e) : (f ∣_ U).appLE V W e = f.appLE (U.ι ''ᵁ V) ((f ⁻¹ᵁ U).ι ''ᵁ W) ((Set.image_subset _ e).trans (image_morphismRestrict_preimage f U V).le) := by rw [Scheme.Hom.appLE, morphismRestrict_app', Scheme.Opens.toScheme_presheaf_map, Scheme.Hom.appLE_map] theorem Γ_map_morphismRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) : Scheme.Γ.map (f ∣_ U).op = Y.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op ≫ f.app U ≫ X.presheaf.map (eqToHom (f ⁻¹ᵁ U).openEmbedding_obj_top).op := by rw [Scheme.Γ_map_op, morphismRestrict_app f U ⊤, f.naturality_assoc, ← X.presheaf.map_comp] rfl /-- Restricting a morphism onto the image of an open immersion is isomorphic to the base change along the immersion. -/ def morphismRestrictOpensRange {X Y U : Scheme.{u}} (f : X ⟶ Y) (g : U ⟶ Y) [hg : IsOpenImmersion g] : Arrow.mk (f ∣_ g.opensRange) ≅ Arrow.mk (pullback.snd f g) := by let V : Y.Opens := g.opensRange let e := IsOpenImmersion.isoOfRangeEq g V.ι Subtype.range_coe.symm let t : pullback f g ⟶ pullback f V.ι := pullback.map _ _ _ _ (𝟙 _) e.hom (𝟙 _) (by rw [Category.comp_id, Category.id_comp]) (by rw [Category.comp_id, IsOpenImmersion.isoOfRangeEq_hom_fac]) symm refine Arrow.isoMk (asIso t ≪≫ pullbackRestrictIsoRestrict f V) e ?_ rw [Iso.trans_hom, asIso_hom, ← Iso.comp_inv_eq, ← cancel_mono g, Arrow.mk_hom, Arrow.mk_hom, Category.assoc, Category.assoc, Category.assoc, IsOpenImmersion.isoOfRangeEq_inv_fac, ← pullback.condition, morphismRestrict_ι, pullbackRestrictIsoRestrict_hom_restrict_assoc, pullback.lift_fst_assoc, Category.comp_id] /-- The restrictions onto two equal open sets are isomorphic. This currently has bad defeqs when unfolded, but it should not matter for now. Replace this definition if better defeqs are needed. -/ def morphismRestrictEq {X Y : Scheme.{u}} (f : X ⟶ Y) {U V : Y.Opens} (e : U = V) : Arrow.mk (f ∣_ U) ≅ Arrow.mk (f ∣_ V) := eqToIso (by subst e; rfl) /-- Restricting a morphism twice is isomorphic to one restriction. -/ def morphismRestrictRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (V : U.toScheme.Opens) : Arrow.mk (f ∣_ U ∣_ V) ≅ Arrow.mk (f ∣_ U.ι ''ᵁ V) := by refine Arrow.isoMk' _ _ (Scheme.restrictRestrict _ _ _ ≪≫ Scheme.restrictIsoOfEq _ ?_) (Scheme.restrictRestrict _ _ _) ?_ · ext x simp only [IsOpenMap.functor_obj_coe, Opens.coe_inclusion, Opens.map_coe, Set.mem_image, Set.mem_preimage, SetLike.mem_coe, morphismRestrict_val_base] constructor · rintro ⟨⟨a, h₁⟩, h₂, rfl⟩ exact ⟨_, h₂, rfl⟩ · rintro ⟨⟨a, h₁⟩, h₂, rfl : a = _⟩ exact ⟨⟨x, h₁⟩, h₂, rfl⟩ · rw [← cancel_mono (Scheme.Opens.ι _), Iso.trans_hom, Category.assoc, Category.assoc, Category.assoc, morphismRestrict_ι, Scheme.restrictIsoOfEq, IsOpenImmersion.isoOfRangeEq_hom_fac_assoc, Scheme.restrictRestrict_hom_restrict_assoc, Scheme.restrictRestrict_hom_restrict, morphismRestrict_ι_assoc, morphismRestrict_ι] /-- Restricting a morphism twice onto a basic open set is isomorphic to one restriction. -/ def morphismRestrictRestrictBasicOpen {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (r : Γ(Y, U)) : Arrow.mk (f ∣_ U ∣_ U.toScheme.basicOpen (Y.presheaf.map (eqToHom U.openEmbedding_obj_top).op r)) ≅ Arrow.mk (f ∣_ Y.basicOpen r) := by refine morphismRestrictRestrict _ _ _ ≪≫ morphismRestrictEq _ ?_ have e := Scheme.preimage_basicOpen U.ι r rw [Scheme.Opens.ι_app] at e rw [← U.toScheme.basicOpen_res_eq _ (eqToHom U.inclusion_map_eq_top).op] erw [← comp_apply] erw [← Y.presheaf.map_comp] rw [eqToHom_op, eqToHom_op, eqToHom_map, eqToHom_trans] erw [← e] ext1 dsimp [Opens.map_coe] rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left, Scheme.Opens.range_ι] exact Y.basicOpen_le r /-- The stalk map of a restriction of a morphism is isomorphic to the stalk map of the original map. -/ def morphismRestrictStalkMap {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (x) : Arrow.mk ((f ∣_ U).stalkMap x) ≅ Arrow.mk (f.stalkMap x.1) := Arrow.isoMk' _ _ (U.stalkIso ((f ∣_ U).1.base x) ≪≫ (TopCat.Presheaf.stalkCongr _ <| Inseparable.of_eq <| morphismRestrict_base_coe f U x)) ((f ⁻¹ᵁ U).stalkIso x) <| by apply TopCat.Presheaf.stalk_hom_ext intro V hxV change ↑(f ⁻¹ᵁ U) at x simp [Scheme.stalkMap_germ'_assoc, Scheme.Hom.appLE] instance {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) [IsOpenImmersion f] : IsOpenImmersion (f ∣_ U) := by delta morphismRestrict exact PresheafedSpace.IsOpenImmersion.comp _ _ end MorphismRestrict /-- The restriction of an open cover to an open subset. -/ @[simps! J obj map] noncomputable def Scheme.OpenCover.restrict {X : Scheme.{u}} (𝒰 : X.OpenCover) (U : Opens X) : U.toScheme.OpenCover := by refine copy (𝒰.pullbackCover U.ι) 𝒰.J _ (𝒰.map · ∣_ U) (Equiv.refl _) (fun i ↦ IsOpenImmersion.isoOfRangeEq (Opens.ι _) (pullback.snd _ _) ?_) ?_ · erw [IsOpenImmersion.range_pullback_snd_of_left U.ι (𝒰.map i)] rw [Opens.opensRange_ι] exact Subtype.range_val · intro i rw [← cancel_mono U.ι] simp only [morphismRestrict_ι, pullbackCover_J, Equiv.refl_apply, pullbackCover_obj, pullbackCover_map, Category.assoc, pullback.condition] erw [IsOpenImmersion.isoOfRangeEq_hom_fac_assoc] end AlgebraicGeometry
AlgebraicGeometry\Scheme.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.AlgebraicGeometry.Spec import Mathlib.Algebra.Category.Ring.Constructions import Mathlib.CategoryTheory.Elementwise /-! # The category of schemes A scheme is a locally ringed space such that every point is contained in some open set where there is an isomorphism of presheaves between the restriction to that open set, and the structure sheaf of `Spec R`, for some commutative ring `R`. A morphism of schemes is just a morphism of the underlying locally ringed spaces. -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 universe u noncomputable section open TopologicalSpace open CategoryTheory open TopCat open Opposite namespace AlgebraicGeometry /-- We define `Scheme` as an `X : LocallyRingedSpace`, along with a proof that every point has an open neighbourhood `U` so that the restriction of `X` to `U` is isomorphic, as a locally ringed space, to `Spec.toLocallyRingedSpace.obj (op R)` for some `R : CommRingCat`. -/ structure Scheme extends LocallyRingedSpace where local_affine : ∀ x : toLocallyRingedSpace, ∃ (U : OpenNhds x) (R : CommRingCat), Nonempty (toLocallyRingedSpace.restrict U.openEmbedding ≅ Spec.toLocallyRingedSpace.obj (op R)) namespace Scheme instance : CoeSort Scheme Type* where coe X := X.carrier /-- The type of open sets of a scheme. -/ abbrev Opens (X : Scheme) : Type* := TopologicalSpace.Opens X /-- A morphism between schemes is a morphism between the underlying locally ringed spaces. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): linter not ported yet def Hom (X Y : Scheme) : Type* := X.toLocallyRingedSpace ⟶ Y.toLocallyRingedSpace /-- Schemes are a full subcategory of locally ringed spaces. -/ instance : Category Scheme := { InducedCategory.category Scheme.toLocallyRingedSpace with Hom := Hom } /-- `f ⁻¹ᵁ U` is notation for `(Opens.map f.1.base).obj U`, the preimage of an open set `U` under `f`. -/ scoped[AlgebraicGeometry] notation3:90 f:91 " ⁻¹ᵁ " U:90 => @Prefunctor.obj (Scheme.Opens _) _ (Scheme.Opens _) _ (Opens.map (f : LocallyRingedSpace.Hom _ _).val.base).toPrefunctor U /-- `Γ(X, U)` is notation for `X.presheaf.obj (op U)`. -/ scoped[AlgebraicGeometry] notation3 "Γ(" X ", " U ")" => (PresheafedSpace.presheaf (SheafedSpace.toPresheafedSpace (LocallyRingedSpace.toSheafedSpace (Scheme.toLocallyRingedSpace X)))).obj (op (α := Scheme.Opens _) U) instance {X : Scheme.{u}} : Subsingleton Γ(X, ⊥) := CommRingCat.subsingleton_of_isTerminal X.sheaf.isTerminalOfEmpty @[continuity, fun_prop] lemma Hom.continuous {X Y : Scheme} (f : X ⟶ Y) : Continuous f.1.base := f.1.base.2 /-- The structure sheaf of a scheme. -/ protected abbrev sheaf (X : Scheme) := X.toSheafedSpace.sheaf namespace Hom variable {X Y : Scheme.{u}} (f : Hom X Y) {U U' : Y.Opens} {V V' : X.Opens} /-- Given a morphism of schemes `f : X ⟶ Y`, and open `U ⊆ Y`, this is the induced map `Γ(Y, U) ⟶ Γ(X, f ⁻¹ᵁ U)`. -/ abbrev app (U : Y.Opens) : Γ(Y, U) ⟶ Γ(X, f ⁻¹ᵁ U) := f.1.c.app (op U) @[reassoc] lemma naturality (i : op U' ⟶ op U) : Y.presheaf.map i ≫ f.app U = f.app U' ≫ X.presheaf.map ((Opens.map f.1.base).map i.unop).op := f.1.c.naturality i /-- Given a morphism of schemes `f : X ⟶ Y`, and open sets `U ⊆ Y`, `V ⊆ f ⁻¹' U`, this is the induced map `Γ(Y, U) ⟶ Γ(X, V)`. -/ def appLE (U : Y.Opens) (V : X.Opens) (e : V ≤ f ⁻¹ᵁ U) : Γ(Y, U) ⟶ Γ(X, V) := f.app U ≫ X.presheaf.map (homOfLE e).op @[reassoc (attr := simp)] lemma appLE_map (e : V ≤ f ⁻¹ᵁ U) (i : op V ⟶ op V') : f.appLE U V e ≫ X.presheaf.map i = f.appLE U V' (i.unop.le.trans e) := by rw [Hom.appLE, Category.assoc, ← Functor.map_comp] rfl @[reassoc] lemma appLE_map' (e : V ≤ f ⁻¹ᵁ U) (i : V = V') : f.appLE U V' (i ▸ e) ≫ X.presheaf.map (eqToHom i).op = f.appLE U V e := appLE_map _ _ _ @[reassoc (attr := simp)] lemma map_appLE (e : V ≤ f ⁻¹ᵁ U) (i : op U' ⟶ op U) : Y.presheaf.map i ≫ f.appLE U V e = f.appLE U' V (e.trans ((Opens.map f.1.base).map i.unop).le) := by rw [Hom.appLE, f.naturality_assoc, ← Functor.map_comp] rfl @[reassoc] lemma map_appLE' (e : V ≤ f ⁻¹ᵁ U) (i : U' = U) : Y.presheaf.map (eqToHom i).op ≫ f.appLE U' V (i ▸ e) = f.appLE U V e := map_appLE _ _ _ lemma app_eq_appLE {U : Y.Opens} : f.app U = f.appLE U _ le_rfl := by simp [Hom.appLE] lemma appLE_eq_app {U : Y.Opens} : f.appLE U (f ⁻¹ᵁ U) le_rfl = f.app U := (app_eq_appLE f).symm lemma appLE_congr (e : V ≤ f ⁻¹ᵁ U) (e₁ : U = U') (e₂ : V = V') (P : ∀ {R S : Type u} [CommRing R] [CommRing S] (_ : R →+* S), Prop) : P (f.appLE U V e) ↔ P (f.appLE U' V' (e₁ ▸ e₂ ▸ e)) := by subst e₁; subst e₂; rfl /-- An isomorphism of schemes induces a homeomorphism of the underlying topological spaces. -/ noncomputable def homeomorph [IsIso f] : X ≃ₜ Y := TopCat.homeoOfIso (asIso <| f.val.base) /-- A morphism of schemes `f : X ⟶ Y` induces a local ring homomorphis from `Y.presheaf.stalk (f x)` to `X.presheaf.stalk x` for any `x : X`. -/ def stalkMap (x : X) : Y.presheaf.stalk (f.val.base x) ⟶ X.presheaf.stalk x := f.val.stalkMap x @[ext (iff := false)] protected lemma ext {f g : X ⟶ Y} (h_base : f.1.base = g.1.base) (h_app : ∀ U, f.app U ≫ X.presheaf.map (eqToHom congr((Opens.map $h_base.symm).obj U)).op = g.app U) : f = g := LocallyRingedSpace.Hom.ext <| SheafedSpace.ext _ _ h_base (TopCat.Presheaf.ext fun U ↦ by simpa using h_app U) lemma preimage_iSup {ι} (U : ι → Opens Y) : f ⁻¹ᵁ iSup U = ⨆ i, f ⁻¹ᵁ U i := Opens.ext (by simp) lemma preimage_iSup_eq_top {ι} {U : ι → Opens Y} (hU : iSup U = ⊤) : ⨆ i, f ⁻¹ᵁ U i = ⊤ := f.preimage_iSup U ▸ hU ▸ rfl end Hom @[simp] lemma preimage_comp {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) (U) : (f ≫ g) ⁻¹ᵁ U = f ⁻¹ᵁ g ⁻¹ᵁ U := rfl /-- The forgetful functor from `Scheme` to `LocallyRingedSpace`. -/ @[simps!] def forgetToLocallyRingedSpace : Scheme ⥤ LocallyRingedSpace := inducedFunctor _ -- deriving Full, Faithful -- Porting note: no delta derive handler, see https://github.com/leanprover-community/mathlib4/issues/5020 /-- The forget functor `Scheme ⥤ LocallyRingedSpace` is fully faithful. -/ @[simps!] def fullyFaithfulForgetToLocallyRingedSpace : forgetToLocallyRingedSpace.FullyFaithful := fullyFaithfulInducedFunctor _ instance : forgetToLocallyRingedSpace.Full := InducedCategory.full _ instance : forgetToLocallyRingedSpace.Faithful := InducedCategory.faithful _ /-- The forgetful functor from `Scheme` to `TopCat`. -/ @[simps!] def forgetToTop : Scheme ⥤ TopCat := Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToTop -- Porting note: Lean seems not able to find this coercion any more instance hasCoeToTopCat : CoeOut Scheme TopCat where coe X := X.carrier -- Porting note: added this unification hint just in case /-- forgetful functor to `TopCat` is the same as coercion -/ unif_hint forgetToTop_obj_eq_coe (X : Scheme) where ⊢ forgetToTop.obj X ≟ (X : TopCat) @[simp] theorem id_val_base (X : Scheme) : (𝟙 X : _).1.base = 𝟙 _ := rfl @[simp] theorem id_app {X : Scheme} (U : X.Opens) : (𝟙 X : _).app U = 𝟙 _ := rfl @[reassoc] theorem comp_val {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).val = f.val ≫ g.val := rfl @[simp, reassoc] -- reassoc lemma does not need `simp` theorem comp_coeBase {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).val.base = f.val.base ≫ g.val.base := rfl -- Porting note: removed elementwise attribute, as generated lemmas were trivial. @[reassoc] theorem comp_val_base {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).val.base = f.val.base ≫ g.val.base := rfl theorem comp_val_base_apply {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g).val.base x = g.val.base (f.val.base x) := by simp @[simp, reassoc] -- reassoc lemma does not need `simp` theorem comp_app {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) (U) : (f ≫ g).app U = g.app U ≫ f.app _ := rfl @[deprecated (since := "2024-06-23")] alias comp_val_c_app := comp_app @[deprecated (since := "2024-06-23")] alias comp_val_c_app_assoc := comp_app_assoc theorem appLE_comp_appLE {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) (U V W e₁ e₂) : g.appLE U V e₁ ≫ f.appLE V W e₂ = (f ≫ g).appLE U W (e₂.trans ((Opens.map f.1.base).map (homOfLE e₁)).le) := by dsimp [Hom.appLE] rw [Category.assoc, f.naturality_assoc, ← Functor.map_comp] rfl @[simp, reassoc] -- reassoc lemma does not need `simp` theorem comp_appLE {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) (U V e) : (f ≫ g).appLE U V e = g.app U ≫ f.appLE _ V e := by rw [g.app_eq_appLE, appLE_comp_appLE] theorem congr_app {X Y : Scheme} {f g : X ⟶ Y} (e : f = g) (U) : f.app U = g.app U ≫ X.presheaf.map (eqToHom (by subst e; rfl)).op := by subst e; dsimp; simp theorem app_eq {X Y : Scheme} (f : X ⟶ Y) {U V : Y.Opens} (e : U = V) : f.app U = Y.presheaf.map (eqToHom e.symm).op ≫ f.app V ≫ X.presheaf.map (eqToHom (congr_arg (Opens.map f.val.base).obj e)).op := by rw [← IsIso.inv_comp_eq, ← Functor.map_inv, f.val.c.naturality] cases e rfl theorem eqToHom_c_app {X Y : Scheme} (e : X = Y) (U) : (eqToHom e).app U = eqToHom (by subst e; rfl) := by subst e; rfl -- Porting note: in `AffineScheme.lean` file, `eqToHom_op` can't be used in `(e)rw` or `simp(_rw)` -- when terms get very complicated. See `AlgebraicGeometry.IsAffineOpen.isLocalization_stalk_aux`. lemma presheaf_map_eqToHom_op (X : Scheme) (U V : X.Opens) (i : U = V) : X.presheaf.map (eqToHom i).op = eqToHom (i ▸ rfl) := by rw [eqToHom_op, eqToHom_map] instance is_locallyRingedSpace_iso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] : @IsIso LocallyRingedSpace _ _ _ f := forgetToLocallyRingedSpace.map_isIso f instance val_base_isIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : IsIso f.1.base := Scheme.forgetToTop.map_isIso f -- Porting note: need an extra instance here. instance {X Y : Scheme} (f : X ⟶ Y) [IsIso f] (U) : IsIso (f.val.c.app U) := haveI := PresheafedSpace.c_isIso_of_iso f.val NatIso.isIso_app_of_isIso _ _ instance {X Y : Scheme} (f : X ⟶ Y) [IsIso f] (U) : IsIso (f.app U) := haveI := PresheafedSpace.c_isIso_of_iso f.val NatIso.isIso_app_of_isIso _ _ @[simp] theorem inv_app {X Y : Scheme} (f : X ⟶ Y) [IsIso f] (U : X.Opens) : (inv f).app U = X.presheaf.map (eqToHom (show (f ≫ inv f) ⁻¹ᵁ U = U by rw [IsIso.hom_inv_id]; rfl)).op ≫ inv (f.app ((inv f) ⁻¹ᵁ U)) := by rw [IsIso.eq_comp_inv, ← Scheme.comp_app, Scheme.congr_app (IsIso.hom_inv_id f), Scheme.id_app, Category.id_comp] theorem inv_app_top {X Y : Scheme} (f : X ⟶ Y) [IsIso f] : (inv f).app ⊤ = inv (f.app ⊤) := by simp end Scheme /-- The spectrum of a commutative ring, as a scheme. -/ def Spec (R : CommRingCat) : Scheme where local_affine _ := ⟨⟨⊤, trivial⟩, R, ⟨(Spec.toLocallyRingedSpace.obj (op R)).restrictTopIso⟩⟩ toLocallyRingedSpace := Spec.locallyRingedSpaceObj R theorem Spec_toLocallyRingedSpace (R : CommRingCat) : (Spec R).toLocallyRingedSpace = Spec.locallyRingedSpaceObj R := rfl /-- The induced map of a ring homomorphism on the ring spectra, as a morphism of schemes. -/ def Spec.map {R S : CommRingCat} (f : R ⟶ S) : Spec S ⟶ Spec R := (Spec.locallyRingedSpaceMap f : Spec.locallyRingedSpaceObj S ⟶ Spec.locallyRingedSpaceObj R) @[simp] theorem Spec.map_id (R : CommRingCat) : Spec.map (𝟙 R) = 𝟙 (Spec R) := Spec.locallyRingedSpaceMap_id R @[reassoc, simp] theorem Spec.map_comp {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) : Spec.map (f ≫ g) = Spec.map g ≫ Spec.map f := Spec.locallyRingedSpaceMap_comp f g /-- The spectrum, as a contravariant functor from commutative rings to schemes. -/ @[simps] protected def Scheme.Spec : CommRingCatᵒᵖ ⥤ Scheme where obj R := Spec (unop R) map f := Spec.map f.unop map_id R := by simp map_comp f g := by simp lemma Spec.map_eqToHom {R S : CommRingCat} (e : R = S) : Spec.map (eqToHom e) = eqToHom (e ▸ rfl) := by subst e; exact Spec.map_id _ instance {R S : CommRingCat} (f : R ⟶ S) [IsIso f] : IsIso (Spec.map f) := inferInstanceAs (IsIso <| Scheme.Spec.map f.op) @[simp] lemma Spec.map_inv {R S : CommRingCat} (f : R ⟶ S) [IsIso f] : Spec.map (inv f) = inv (Spec.map f) := by show Scheme.Spec.map (inv f).op = inv (Scheme.Spec.map f.op) rw [op_inv, ← Scheme.Spec.map_inv] section variable {R S : CommRingCat.{u}} (f : R ⟶ S) -- The lemmas below are not tagged simp to respect the abstraction. lemma Spec_carrier (R : CommRingCat.{u}) : (Spec R).carrier = PrimeSpectrum R := rfl lemma Spec_sheaf (R : CommRingCat.{u}) : (Spec R).sheaf = Spec.structureSheaf R := rfl lemma Spec_presheaf (R : CommRingCat.{u}) : (Spec R).presheaf = (Spec.structureSheaf R).1 := rfl lemma Spec.map_base : (Spec.map f).1.base = PrimeSpectrum.comap f := rfl lemma Spec.map_app (U) : (Spec.map f).app U = StructureSheaf.comap f U (Spec.map f ⁻¹ᵁ U) le_rfl := rfl lemma Spec.map_appLE {U V} (e : U ≤ Spec.map f ⁻¹ᵁ V) : (Spec.map f).appLE V U e = StructureSheaf.comap f V U e := rfl end namespace Scheme /-- The empty scheme. -/ @[simps] def empty : Scheme where carrier := TopCat.of PEmpty presheaf := (CategoryTheory.Functor.const _).obj (CommRingCat.of PUnit) IsSheaf := Presheaf.isSheaf_of_isTerminal _ CommRingCat.punitIsTerminal localRing x := PEmpty.elim x local_affine x := PEmpty.elim x instance : EmptyCollection Scheme := ⟨empty⟩ instance : Inhabited Scheme := ⟨∅⟩ /-- The global sections, notated Gamma. -/ def Γ : Schemeᵒᵖ ⥤ CommRingCat := (inducedFunctor Scheme.toLocallyRingedSpace).op ⋙ LocallyRingedSpace.Γ theorem Γ_def : Γ = (inducedFunctor Scheme.toLocallyRingedSpace).op ⋙ LocallyRingedSpace.Γ := rfl @[simp] theorem Γ_obj (X : Schemeᵒᵖ) : Γ.obj X = Γ(unop X, ⊤) := rfl theorem Γ_obj_op (X : Scheme) : Γ.obj (op X) = Γ(X, ⊤) := rfl @[simp] theorem Γ_map {X Y : Schemeᵒᵖ} (f : X ⟶ Y) : Γ.map f = f.unop.app ⊤ := rfl theorem Γ_map_op {X Y : Scheme} (f : X ⟶ Y) : Γ.map f.op = f.app ⊤ := rfl /-- The counit (`SpecΓIdentity.inv.op`) of the adjunction `Γ ⊣ Spec` as an isomorphism. This is almost never needed in practical use cases. Use `ΓSpecIso` instead. -/ def SpecΓIdentity : Scheme.Spec.rightOp ⋙ Scheme.Γ ≅ 𝟭 _ := Iso.symm <| NatIso.ofComponents.{u,u,u+1,u+1} (fun R => asIso (StructureSheaf.toOpen R ⊤)) (fun {X Y} f => by convert Spec_Γ_naturality (R := X) (S := Y) f) variable (R : CommRingCat.{u}) /-- The global sections of `Spec R` is isomorphic to `R`. -/ def ΓSpecIso : Γ(Spec R, ⊤) ≅ R := SpecΓIdentity.app R @[simp] lemma SpecΓIdentity_app : SpecΓIdentity.app R = ΓSpecIso R := rfl @[simp] lemma SpecΓIdentity_hom_app : SpecΓIdentity.hom.app R = (ΓSpecIso R).hom := rfl @[simp] lemma SpecΓIdentity_inv_app : SpecΓIdentity.inv.app R = (ΓSpecIso R).inv := rfl @[reassoc (attr := simp)] lemma ΓSpecIso_naturality {R S : CommRingCat.{u}} (f : R ⟶ S) : (Spec.map f).app ⊤ ≫ (ΓSpecIso S).hom = (ΓSpecIso R).hom ≫ f := SpecΓIdentity.hom.naturality f -- The RHS is not necessarily simpler than the LHS, but this direction coincides with the simp -- direction of `NatTrans.naturality`. @[reassoc (attr := simp)] lemma ΓSpecIso_inv_naturality {R S : CommRingCat.{u}} (f : R ⟶ S) : f ≫ (ΓSpecIso S).inv = (ΓSpecIso R).inv ≫ (Spec.map f).app ⊤ := SpecΓIdentity.inv.naturality f -- This is not marked simp to respect the abstraction lemma ΓSpecIso_inv : (ΓSpecIso R).inv = StructureSheaf.toOpen R ⊤ := rfl lemma toOpen_eq (U) : (by exact StructureSheaf.toOpen R U) = (ΓSpecIso R).inv ≫ (Spec R).presheaf.map (homOfLE le_top).op := rfl section BasicOpen variable (X : Scheme) {V U : X.Opens} (f g : Γ(X, U)) /-- The subset of the underlying space where the given section does not vanish. -/ def basicOpen : X.Opens := X.toLocallyRingedSpace.toRingedSpace.basicOpen f @[simp] theorem mem_basicOpen (x : U) : ↑x ∈ X.basicOpen f ↔ IsUnit (X.presheaf.germ x f) := RingedSpace.mem_basicOpen _ _ _ theorem mem_basicOpen_top' {U : X.Opens} (f : Γ(X, U)) (x : X) : x ∈ X.basicOpen f ↔ ∃ (m : x ∈ U), IsUnit (X.presheaf.germ (⟨x, m⟩ : U) f) := by fconstructor · rintro ⟨y, hy1, rfl⟩ exact ⟨y.2, hy1⟩ · rintro ⟨m, hm⟩ exact ⟨⟨x, m⟩, hm, rfl⟩ @[simp] theorem mem_basicOpen_top (f : Γ(X, ⊤)) (x : X) : x ∈ X.basicOpen f ↔ IsUnit (X.presheaf.germ (⟨x, trivial⟩ : (⊤ : Opens _)) f) := RingedSpace.mem_basicOpen _ f ⟨x, trivial⟩ @[simp] theorem basicOpen_res (i : op U ⟶ op V) : X.basicOpen (X.presheaf.map i f) = V ⊓ X.basicOpen f := RingedSpace.basicOpen_res _ i f -- This should fire before `basicOpen_res`. @[simp 1100] theorem basicOpen_res_eq (i : op U ⟶ op V) [IsIso i] : X.basicOpen (X.presheaf.map i f) = X.basicOpen f := RingedSpace.basicOpen_res_eq _ i f @[sheaf_restrict] theorem basicOpen_le : X.basicOpen f ≤ U := RingedSpace.basicOpen_le _ _ @[sheaf_restrict] lemma basicOpen_restrict (i : V ⟶ U) (f : Γ(X, U)) : X.basicOpen (f |_ₕ i) ≤ X.basicOpen f := (Scheme.basicOpen_res _ _ _).trans_le inf_le_right @[simp] theorem preimage_basicOpen {X Y : Scheme.{u}} (f : X ⟶ Y) {U : Y.Opens} (r : Γ(Y, U)) : f ⁻¹ᵁ (Y.basicOpen r) = X.basicOpen (f.app U r) := LocallyRingedSpace.preimage_basicOpen f r lemma basicOpen_appLE {X Y : Scheme.{u}} (f : X ⟶ Y) (U : X.Opens) (V : Y.Opens) (e : U ≤ f ⁻¹ᵁ V) (s : Γ(Y, V)) : X.basicOpen (f.appLE V U e s) = U ⊓ f ⁻¹ᵁ (Y.basicOpen s) := by simp only [preimage_basicOpen, Hom.appLE, CommRingCat.coe_comp_of, RingHom.coe_comp, Function.comp_apply] rw [basicOpen_res] @[simp] theorem basicOpen_zero (U : X.Opens) : X.basicOpen (0 : Γ(X, U)) = ⊥ := LocallyRingedSpace.basicOpen_zero _ U @[simp] theorem basicOpen_mul : X.basicOpen (f * g) = X.basicOpen f ⊓ X.basicOpen g := RingedSpace.basicOpen_mul _ _ _ lemma basicOpen_pow {n : ℕ} (h : 0 < n) : X.basicOpen (f ^ n) = X.basicOpen f := RingedSpace.basicOpen_pow _ _ _ h theorem basicOpen_of_isUnit {f : Γ(X, U)} (hf : IsUnit f) : X.basicOpen f = U := RingedSpace.basicOpen_of_isUnit _ hf instance algebra_section_section_basicOpen {X : Scheme} {U : X.Opens} (f : Γ(X, U)) : Algebra Γ(X, U) Γ(X, X.basicOpen f) := (X.presheaf.map (homOfLE <| X.basicOpen_le f : _ ⟶ U).op).toAlgebra end BasicOpen section ZeroLocus variable (X : Scheme.{u}) /-- The zero locus of a set of sections `s` over an open set `U` is the closed set consisting of the complement of `U` and of all points of `U`, where all elements of `f` vanish. -/ def zeroLocus {U : X.Opens} (s : Set Γ(X, U)) : Set X := X.toRingedSpace.zeroLocus s lemma zeroLocus_def {U : X.Opens} (s : Set Γ(X, U)) : X.zeroLocus s = ⋂ f ∈ s, (X.basicOpen f).carrierᶜ := rfl lemma zeroLocus_isClosed {U : X.Opens} (s : Set Γ(X, U)) : IsClosed (X.zeroLocus s) := X.toRingedSpace.zeroLocus_isClosed s lemma zeroLocus_singleton {U : X.Opens} (f : Γ(X, U)) : X.zeroLocus {f} = (X.basicOpen f).carrierᶜ := X.toRingedSpace.zeroLocus_singleton f @[simp] lemma zeroLocus_empty_eq_univ {U : X.Opens} : X.zeroLocus (∅ : Set Γ(X, U)) = Set.univ := X.toRingedSpace.zeroLocus_empty_eq_univ @[simp] lemma mem_zeroLocus_iff {U : X.Opens} (s : Set Γ(X, U)) (x : X) : x ∈ X.zeroLocus s ↔ ∀ f ∈ s, x ∉ X.basicOpen f := X.toRingedSpace.mem_zeroLocus_iff s x end ZeroLocus end Scheme theorem basicOpen_eq_of_affine {R : CommRingCat} (f : R) : (Spec R).basicOpen ((Scheme.ΓSpecIso R).inv f) = PrimeSpectrum.basicOpen f := by ext x simp only [SetLike.mem_coe, Scheme.mem_basicOpen_top, Opens.coe_top] suffices IsUnit (StructureSheaf.toStalk R x f) ↔ f ∉ PrimeSpectrum.asIdeal x by exact this erw [← isUnit_map_iff (StructureSheaf.stalkToFiberRingHom R x), StructureSheaf.stalkToFiberRingHom_toStalk] exact (IsLocalization.AtPrime.isUnit_to_map_iff (Localization.AtPrime (PrimeSpectrum.asIdeal x)) (PrimeSpectrum.asIdeal x) f : _) @[simp] theorem basicOpen_eq_of_affine' {R : CommRingCat} (f : Γ(Spec R, ⊤)) : (Spec R).basicOpen f = PrimeSpectrum.basicOpen ((Scheme.ΓSpecIso R).hom f) := by convert basicOpen_eq_of_affine ((Scheme.ΓSpecIso R).hom f) exact (Iso.hom_inv_id_apply (Scheme.ΓSpecIso R) f).symm theorem Scheme.Spec_map_presheaf_map_eqToHom {X : Scheme} {U V : X.Opens} (h : U = V) (W) : (Spec.map (X.presheaf.map (eqToHom h).op)).app W = eqToHom (by cases h; dsimp; simp) := by have : Scheme.Spec.map (X.presheaf.map (𝟙 (op U))).op = 𝟙 _ := by rw [X.presheaf.map_id, op_id, Scheme.Spec.map_id] cases h refine (Scheme.congr_app this _).trans ?_ simp [eqToHom_map] @[reassoc (attr := simp)] lemma Scheme.iso_hom_val_base_inv_val_base {X Y : Scheme.{u}} (e : X ≅ Y) : e.hom.val.base ≫ e.inv.val.base = 𝟙 _ := LocallyRingedSpace.iso_hom_val_base_inv_val_base (Scheme.forgetToLocallyRingedSpace.mapIso e) @[simp] lemma Scheme.iso_hom_val_base_inv_val_base_apply {X Y : Scheme.{u}} (e : X ≅ Y) (x : X) : (e.inv.val.base (e.hom.val.base x)) = x := by show (e.hom.val.base ≫ e.inv.val.base) x = 𝟙 X.toPresheafedSpace x simp @[reassoc (attr := simp)] lemma Scheme.iso_inv_val_base_hom_val_base {X Y : Scheme.{u}} (e : X ≅ Y) : e.inv.val.base ≫ e.hom.val.base = 𝟙 _ := LocallyRingedSpace.iso_inv_val_base_hom_val_base (Scheme.forgetToLocallyRingedSpace.mapIso e) @[simp] lemma Scheme.iso_inv_val_base_hom_val_base_apply {X Y : Scheme.{u}} (e : X ≅ Y) (y : Y) : (e.hom.val.base (e.inv.val.base y)) = y := by show (e.inv.val.base ≫ e.hom.val.base) y = 𝟙 Y.toPresheafedSpace y simp section Stalks namespace Scheme variable {X Y : Scheme.{u}} (f : X ⟶ Y) @[simp] lemma stalkMap_id (X : Scheme.{u}) (x : X) : (𝟙 X : X ⟶ X).stalkMap x = 𝟙 (X.presheaf.stalk x) := PresheafedSpace.stalkMap.id _ x lemma stalkMap_comp {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g : X ⟶ Z).stalkMap x = g.stalkMap (f.val.base x) ≫ f.stalkMap x := PresheafedSpace.stalkMap.comp f.val g.val x @[reassoc] lemma stalkSpecializes_stalkMap (x x' : X) (h : x ⤳ x') : Y.presheaf.stalkSpecializes (f.val.base.map_specializes h) ≫ f.stalkMap x = f.stalkMap x' ≫ X.presheaf.stalkSpecializes h := PresheafedSpace.stalkMap.stalkSpecializes_stalkMap f.val h lemma stalkSpecializes_stalkMap_apply (x x' : X) (h : x ⤳ x') (y) : f.stalkMap x (Y.presheaf.stalkSpecializes (f.val.base.map_specializes h) y) = (X.presheaf.stalkSpecializes h (f.stalkMap x' y)) := DFunLike.congr_fun (stalkSpecializes_stalkMap f x x' h) y @[reassoc] lemma stalkMap_congr (f g : X ⟶ Y) (hfg : f = g) (x x' : X) (hxx' : x = x') : f.stalkMap x ≫ (X.presheaf.stalkCongr (.of_eq hxx')).hom = (Y.presheaf.stalkCongr (.of_eq <| hfg ▸ hxx' ▸ rfl)).hom ≫ g.stalkMap x' := LocallyRingedSpace.stalkMap_congr f g hfg x x' hxx' @[reassoc] lemma stalkMap_congr_hom (f g : X ⟶ Y) (hfg : f = g) (x : X) : f.stalkMap x = (Y.presheaf.stalkCongr (.of_eq <| hfg ▸ rfl)).hom ≫ g.stalkMap x := LocallyRingedSpace.stalkMap_congr_hom f g hfg x @[reassoc] lemma stalkMap_congr_point (x x' : X) (hxx' : x = x') : f.stalkMap x ≫ (X.presheaf.stalkCongr (.of_eq hxx')).hom = (Y.presheaf.stalkCongr (.of_eq <| hxx' ▸ rfl)).hom ≫ f.stalkMap x' := LocallyRingedSpace.stalkMap_congr_point f x x' hxx' @[reassoc (attr := simp)] lemma stalkMap_hom_inv (e : X ≅ Y) (y : Y) : e.hom.stalkMap (e.inv.val.base y) ≫ e.inv.stalkMap y = (Y.presheaf.stalkCongr (.of_eq (by simp))).hom := LocallyRingedSpace.stalkMap_hom_inv (forgetToLocallyRingedSpace.mapIso e) y @[simp] lemma stalkMap_hom_inv_apply (e : X ≅ Y) (y : Y) (z) : e.inv.stalkMap y (e.hom.stalkMap (e.inv.val.base y) z) = (Y.presheaf.stalkCongr (.of_eq (by simp))).hom z := DFunLike.congr_fun (stalkMap_hom_inv e y) z @[reassoc (attr := simp)] lemma stalkMap_inv_hom (e : X ≅ Y) (x : X) : e.inv.stalkMap (e.hom.val.base x) ≫ e.hom.stalkMap x = (X.presheaf.stalkCongr (.of_eq (by simp))).hom := LocallyRingedSpace.stalkMap_inv_hom (forgetToLocallyRingedSpace.mapIso e) x @[simp] lemma stalkMap_inv_hom_apply (e : X ≅ Y) (x : X) (y) : e.hom.stalkMap x (e.inv.stalkMap (e.hom.val.base x) y) = (X.presheaf.stalkCongr (.of_eq (by simp))).hom y := DFunLike.congr_fun (stalkMap_inv_hom e x) y @[reassoc] lemma stalkMap_germ (U : Y.Opens) (x : f ⁻¹ᵁ U) : Y.presheaf.germ ⟨f.val.base x.val, x.property⟩ ≫ f.stalkMap x = f.app U ≫ X.presheaf.germ x := PresheafedSpace.stalkMap_germ f.val U x lemma stalkMap_germ_apply (U : Y.Opens) (x : f ⁻¹ᵁ U) (y) : f.stalkMap x.val (Y.presheaf.germ ⟨f.val.base x.val, x.property⟩ y) = X.presheaf.germ x (f.val.c.app (op U) y) := PresheafedSpace.stalkMap_germ_apply f.val U x y @[reassoc (attr := simp)] lemma stalkMap_germ' (U : Y.Opens) (x : X) (hx : f.val.base x ∈ U) : Y.presheaf.germ ⟨f.val.base x, hx⟩ ≫ f.stalkMap x = f.app U ≫ X.presheaf.germ (U := f⁻¹ᵁ U) ⟨x, hx⟩ := PresheafedSpace.stalkMap_germ' f.val U x hx @[simp] lemma stalkMap_germ'_apply (U : Y.Opens) (x : X) (hx : f.val.base x ∈ U) (y) : f.stalkMap x (Y.presheaf.germ ⟨f.val.base x, hx⟩ y) = X.presheaf.germ (U := (Opens.map f.val.base).obj U) ⟨x, hx⟩ (f.val.c.app (op U) y) := PresheafedSpace.stalkMap_germ_apply f.val U ⟨x, hx⟩ y end Scheme end Stalks end AlgebraicGeometry