filename
stringlengths
5
42
content
stringlengths
15
319k
Ineq.lean
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Tactic.NormNum.Eq import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Invertible import Mathlib.Algebra.Order.Monoid.WithTop import Mathlib.Algebra.Order.Ring.Cast /-! # `norm_num` extensions for inequalities. -/ open Lean Meta Qq namespace Mathlib.Meta.NormNum variable {u : Level} /-- Helper function to synthesize typed `Semiring α` `PartialOrder α` `IsOrderedSemiring α` expressions. -/ def inferOrderedSemiring (α : Q(Type u)) : MetaM <| (_ : Q(Semiring $α)) × (_ : Q(PartialOrder $α)) × Q(IsOrderedRing $α) := let go := do let semiring ← synthInstanceQ q(Semiring $α) let partialOrder ← synthInstanceQ q(PartialOrder $α) let isOrderedRing ← synthInstanceQ q(IsOrderedRing $α) return ⟨semiring, partialOrder, isOrderedRing⟩ go <|> throwError "not an ordered semiring" /-- Helper function to synthesize typed `Ring α` `PartialOrder α` `IsOrderedSemiring α` expressions. -/ def inferOrderedRing (α : Q(Type u)) : MetaM <| (_ : Q(Ring $α)) × (_ : Q(PartialOrder $α)) × Q(IsOrderedRing $α) := let go := do let ring ← synthInstanceQ q(Ring $α) let partialOrder ← synthInstanceQ q(PartialOrder $α) let isOrderedRing ← synthInstanceQ q(IsOrderedRing $α) return ⟨ring, partialOrder, isOrderedRing⟩ go <|> throwError "not an ordered ring" /-- Helper function to synthesize typed `Semifield α` `LinearOrder α` `IsStrictOrderedRing α` expressions. -/ def inferLinearOrderedSemifield (α : Q(Type u)) : MetaM <| (_ : Q(Semifield $α)) × (_ : Q(LinearOrder $α)) × Q(IsStrictOrderedRing $α) := let go := do let semifield ← synthInstanceQ q(Semifield $α) let linearOrder ← synthInstanceQ q(LinearOrder $α) let isStrictOrderedRing ← synthInstanceQ q(IsStrictOrderedRing $α) return ⟨semifield, linearOrder, isStrictOrderedRing⟩ go <|> throwError "not a linear ordered semifield" /-- Helper function to synthesize typed `Field α` `LinearOrder α` `IsStrictOrderedRing α` expressions. -/ def inferLinearOrderedField (α : Q(Type u)) : MetaM <| (_ : Q(Field $α)) × (_ : Q(LinearOrder $α)) × Q(IsStrictOrderedRing $α) := let go := do let field ← synthInstanceQ q(Field $α) let linearOrder ← synthInstanceQ q(LinearOrder $α) let isStrictOrderedRing ← synthInstanceQ q(IsStrictOrderedRing $α) return ⟨field, linearOrder, isStrictOrderedRing⟩ go <|> throwError "not a linear ordered field" variable {α : Type*} theorem isNat_le_true [Semiring α] [PartialOrder α] [IsOrderedRing α] : {a b : α} → {a' b' : ℕ} → IsNat a a' → IsNat b b' → Nat.ble a' b' = true → a ≤ b | _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Nat.mono_cast (Nat.le_of_ble_eq_true h) theorem isNat_lt_false [Semiring α] [PartialOrder α] [IsOrderedRing α] {a b : α} {a' b' : ℕ} (ha : IsNat a a') (hb : IsNat b b') (h : Nat.ble b' a' = true) : ¬a < b := not_lt_of_ge (isNat_le_true hb ha h) theorem isNNRat_le_true [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] : {a b : α} → {na nb : ℕ} → {da db : ℕ} → IsNNRat a na da → IsNNRat b nb db → decide (Nat.mul na (db) ≤ Nat.mul nb (da)) → a ≤ b | _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by have h := (Nat.cast_le (α := α)).mpr <| of_decide_eq_true h have ha : 0 ≤ ⅟(da : α) := invOf_nonneg.mpr <| Nat.cast_nonneg da have hb : 0 ≤ ⅟(db : α) := invOf_nonneg.mpr <| Nat.cast_nonneg db have h := (mul_le_mul_of_nonneg_left · hb) <| mul_le_mul_of_nonneg_right h ha rw [← mul_assoc, Nat.commute_cast] at h simp at h; rwa [Nat.commute_cast] at h theorem isNNRat_lt_true [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α] : {a b : α} → {na nb : ℕ} → {da db : ℕ} → IsNNRat a na da → IsNNRat b nb db → decide (na * db < nb * da) → a < b | _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by have h := (Nat.cast_lt (α := α)).mpr <| of_decide_eq_true h have ha : 0 < ⅟(da : α) := pos_invOf_of_invertible_cast da have hb : 0 < ⅟(db : α) := pos_invOf_of_invertible_cast db have h := (mul_lt_mul_of_pos_left · hb) <| mul_lt_mul_of_pos_right h ha rw [← mul_assoc, Nat.commute_cast] at h simp? at h says simp only [Nat.cast_mul, mul_invOf_cancel_right'] at h rwa [Nat.commute_cast] at h theorem isNNRat_le_false [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α] {a b : α} {na nb : ℕ} {da db : ℕ} (ha : IsNNRat a na da) (hb : IsNNRat b nb db) (h : decide (nb * da < na * db)) : ¬a ≤ b := not_le_of_gt (isNNRat_lt_true hb ha h) theorem isNNRat_lt_false [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α} {na nb : ℕ} {da db : ℕ} (ha : IsNNRat a na da) (hb : IsNNRat b nb db) (h : decide (nb * da ≤ na * db)) : ¬a < b := not_lt_of_ge (isNNRat_le_true hb ha h) theorem isRat_le_true [Ring α] [LinearOrder α] [IsStrictOrderedRing α] : {a b : α} → {na nb : ℤ} → {da db : ℕ} → IsRat a na da → IsRat b nb db → decide (Int.mul na (.ofNat db) ≤ Int.mul nb (.ofNat da)) → a ≤ b | _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by have h := Int.cast_mono (R := α) <| of_decide_eq_true h have ha : 0 ≤ ⅟(da : α) := invOf_nonneg.mpr <| Nat.cast_nonneg da have hb : 0 ≤ ⅟(db : α) := invOf_nonneg.mpr <| Nat.cast_nonneg db have h := (mul_le_mul_of_nonneg_left · hb) <| mul_le_mul_of_nonneg_right h ha rw [← mul_assoc, Int.commute_cast] at h simp at h; rwa [Int.commute_cast] at h theorem isRat_lt_true [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α] : {a b : α} → {na nb : ℤ} → {da db : ℕ} → IsRat a na da → IsRat b nb db → decide (na * db < nb * da) → a < b | _, _, _, _, da, db, ⟨_, rfl⟩, ⟨_, rfl⟩, h => by have h := Int.cast_strictMono (R := α) <| of_decide_eq_true h have ha : 0 < ⅟(da : α) := pos_invOf_of_invertible_cast da have hb : 0 < ⅟(db : α) := pos_invOf_of_invertible_cast db have h := (mul_lt_mul_of_pos_left · hb) <| mul_lt_mul_of_pos_right h ha rw [← mul_assoc, Int.commute_cast] at h simp? at h says simp only [Int.cast_mul, Int.cast_natCast, mul_invOf_cancel_right'] at h rwa [Int.commute_cast] at h theorem isRat_le_false [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Nontrivial α] {a b : α} {na nb : ℤ} {da db : ℕ} (ha : IsRat a na da) (hb : IsRat b nb db) (h : decide (nb * da < na * db)) : ¬a ≤ b := not_le_of_gt (isRat_lt_true hb ha h) theorem isRat_lt_false [Ring α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α} {na nb : ℤ} {da db : ℕ} (ha : IsRat a na da) (hb : IsRat b nb db) (h : decide (nb * da ≤ na * db)) : ¬a < b := not_lt_of_ge (isRat_le_true hb ha h) /-! # (In)equalities -/ theorem isNat_lt_true [Semiring α] [PartialOrder α] [IsOrderedRing α] [CharZero α] : {a b : α} → {a' b' : ℕ} → IsNat a a' → IsNat b b' → Nat.ble b' a' = false → a < b | _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Nat.cast_lt.2 <| ble_eq_false.1 h theorem isNat_le_false [Semiring α] [PartialOrder α] [IsOrderedRing α] [CharZero α] {a b : α} {a' b' : ℕ} (ha : IsNat a a') (hb : IsNat b b') (h : Nat.ble a' b' = false) : ¬a ≤ b := not_le_of_gt (isNat_lt_true hb ha h) theorem isInt_le_true [Ring α] [PartialOrder α] [IsOrderedRing α] : {a b : α} → {a' b' : ℤ} → IsInt a a' → IsInt b b' → decide (a' ≤ b') → a ≤ b | _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Int.cast_mono <| of_decide_eq_true h theorem isInt_lt_true [Ring α] [PartialOrder α] [IsOrderedRing α] [Nontrivial α] : {a b : α} → {a' b' : ℤ} → IsInt a a' → IsInt b b' → decide (a' < b') → a < b | _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, h => Int.cast_lt.2 <| of_decide_eq_true h theorem isInt_le_false [Ring α] [PartialOrder α] [IsOrderedRing α] [Nontrivial α] {a b : α} {a' b' : ℤ} (ha : IsInt a a') (hb : IsInt b b') (h : decide (b' < a')) : ¬a ≤ b := not_le_of_gt (isInt_lt_true hb ha h) theorem isInt_lt_false [Ring α] [PartialOrder α] [IsOrderedRing α] {a b : α} {a' b' : ℤ} (ha : IsInt a a') (hb : IsInt b b') (h : decide (b' ≤ a')) : ¬a < b := not_lt_of_ge (isInt_le_true hb ha h) attribute [local instance] monadLiftOptionMetaM in /-- The `norm_num` extension which identifies expressions of the form `a ≤ b`, such that `norm_num` successfully recognises both `a` and `b`. -/ @[norm_num _ ≤ _] def evalLE : NormNumExt where eval {v β} e := do haveI' : v =QL 0 := ⟨⟩; haveI' : $β =Q Prop := ⟨⟩ let .app (.app f a) b ← whnfR e | failure let ⟨u, α, a⟩ ← inferTypeQ' a have b : Q($α) := b let ra ← derive a; let rb ← derive b let lα ← synthInstanceQ q(LE $α) guard <|← withNewMCtxDepth <| isDefEq f q(LE.le (α := $α)) core lα ra rb where /-- Identify (as `true` or `false`) expressions of the form `a ≤ b`, where `a` and `b` are numeric expressions whose evaluations to `NormNum.Result` have already been computed. -/ core {u : Level} {α : Q(Type u)} (lα : Q(LE $α)) {a b : Q($α)} (ra : NormNum.Result a) (rb : NormNum.Result b) : MetaM (NormNum.Result q($a ≤ $b)) := do let e := q($a ≤ $b) let rec intArm : MetaM (Result e) := do let ⟨_ir, _, _i⟩ ← inferOrderedRing α haveI' : $e =Q ($a ≤ $b) := ⟨⟩ let ⟨za, na, pa⟩ ← ra.toInt q($_ir) let ⟨zb, nb, pb⟩ ← rb.toInt q($_ir) assumeInstancesCommute if decide (za ≤ zb) then let r : Q(decide ($na ≤ $nb) = true) := (q(Eq.refl true) : Expr) return .isTrue q(isInt_le_true $pa $pb $r) else if let .some _i ← trySynthInstanceQ q(Nontrivial $α) then let r : Q(decide ($nb < $na) = true) := (q(Eq.refl true) : Expr) return .isFalse q(isInt_le_false $pa $pb $r) else failure let rec ratArm : MetaM (Result e) := do let ⟨_if, _, _i⟩ ← inferLinearOrderedField α haveI' : $e =Q ($a ≤ $b) := ⟨⟩ let ⟨qa, na, da, pa⟩ ← ra.toRat' q(Field.toDivisionRing) let ⟨qb, nb, db, pb⟩ ← rb.toRat' q(Field.toDivisionRing) assumeInstancesCommute if decide (qa ≤ qb) then let r : Q(decide ($na * $db ≤ $nb * $da) = true) := (q(Eq.refl true) : Expr) return (.isTrue q(isRat_le_true $pa $pb $r)) else let _i : Q(Nontrivial $α) := q(IsStrictOrderedRing.toNontrivial) let r : Q(decide ($nb * $da < $na * $db) = true) := (q(Eq.refl true) : Expr) return .isFalse q(isRat_le_false $pa $pb $r) match ra, rb with | .isBool .., _ | _, .isBool .. => failure | .isNNRat _ .., _ | _, .isNNRat _ .. => ratArm | .isNegNNRat _ .., _ | _, .isNegNNRat _ .. => ratArm | .isNegNat _ .., _ | _, .isNegNat _ .. => intArm | .isNat ra na pa, .isNat rb nb pb => let ⟨_, _, _i⟩ ← inferOrderedSemiring α haveI' : $ra =Q by clear! $ra $rb; infer_instance := ⟨⟩ haveI' : $rb =Q by clear! $ra $rb; infer_instance := ⟨⟩ haveI' : $e =Q ($a ≤ $b) := ⟨⟩ assumeInstancesCommute if na.natLit! ≤ nb.natLit! then let r : Q(Nat.ble $na $nb = true) := (q(Eq.refl true) : Expr) return .isTrue q(isNat_le_true $pa $pb $r) else if let .some _i ← trySynthInstanceQ q(CharZero $α) then let r : Q(Nat.ble $na $nb = false) := (q(Eq.refl false) : Expr) return .isFalse q(isNat_le_false $pa $pb $r) else -- Nats can appear in an `OrderedRing` without `CharZero`. intArm attribute [local instance] monadLiftOptionMetaM in /-- The `norm_num` extension which identifies expressions of the form `a < b`, such that `norm_num` successfully recognises both `a` and `b`. -/ @[norm_num _ < _] def evalLT : NormNumExt where eval {v β} e := do haveI' : v =QL 0 := ⟨⟩; haveI' : $β =Q Prop := ⟨⟩ let .app (.app f a) b ← whnfR e | failure let ⟨u, α, a⟩ ← inferTypeQ' a have b : Q($α) := b let ra ← derive a; let rb ← derive b let lα ← synthInstanceQ q(LT $α) guard <|← withNewMCtxDepth <| isDefEq f q(LT.lt (α := $α)) core lα ra rb where /-- Identify (as `true` or `false`) expressions of the form `a < b`, where `a` and `b` are numeric expressions whose evaluations to `NormNum.Result` have already been computed. -/ core {u : Level} {α : Q(Type u)} (lα : Q(LT $α)) {a b : Q($α)} (ra : NormNum.Result a) (rb : NormNum.Result b) : MetaM (NormNum.Result q($a < $b)) := do let e := q($a < $b) let rec intArm : MetaM (Result e) := do let ⟨_ir, _, _i⟩ ← inferOrderedRing α haveI' : $e =Q ($a < $b) := ⟨⟩ let ⟨za, na, pa⟩ ← ra.toInt q($_ir) let ⟨zb, nb, pb⟩ ← rb.toInt q($_ir) assumeInstancesCommute if za < zb then if let .some _i ← trySynthInstanceQ q(Nontrivial $α) then let r : Q(decide ($na < $nb) = true) := (q(Eq.refl true) : Expr) return .isTrue q(isInt_lt_true $pa $pb $r) else failure else let r : Q(decide ($nb ≤ $na) = true) := (q(Eq.refl true) : Expr) return .isFalse q(isInt_lt_false $pa $pb $r) let rec nnratArm : MetaM (Result e) := do -- We need a division ring with an order, and `LinearOrderedField` is the closest mathlib has. /- NOTE: after the ordered algebra refactor, this is not true anymore, so there may be a better typeclass -/ let ⟨_, _, _⟩ ← inferLinearOrderedSemifield α assumeInstancesCommute haveI' : $e =Q ($a < $b) := ⟨⟩ let ⟨qa, na, da, pa⟩ ← ra.toNNRat' q(Semifield.toDivisionSemiring) let ⟨qb, nb, db, pb⟩ ← rb.toNNRat' q(Semifield.toDivisionSemiring) if qa < qb then let r : Q(decide ($na * $db < $nb * $da) = true) := (q(Eq.refl true) : Expr) return .isTrue q(isNNRat_lt_true $pa $pb $r) else let r : Q(decide ($nb * $da ≤ $na * $db) = true) := (q(Eq.refl true) : Expr) return .isFalse q(isNNRat_lt_false $pa $pb $r) let rec ratArm : MetaM (Result e) := do -- We need a division ring with an order, and `LinearOrderedField` is the closest mathlib has. /- NOTE: after the ordered algebra refactor, this is not true anymore, so there may be a better typeclass -/ let ⟨_, _, _i⟩ ← inferLinearOrderedField α assumeInstancesCommute haveI' : $e =Q ($a < $b) := ⟨⟩ let ⟨qa, na, da, pa⟩ ← ra.toRat' q(Field.toDivisionRing) let ⟨qb, nb, db, pb⟩ ← rb.toRat' q(Field.toDivisionRing) if qa < qb then let r : Q(decide ($na * $db < $nb * $da) = true) := (q(Eq.refl true) : Expr) return .isTrue q(isRat_lt_true $pa $pb $r) else let r : Q(decide ($nb * $da ≤ $na * $db) = true) := (q(Eq.refl true) : Expr) return .isFalse q(isRat_lt_false $pa $pb $r) match ra, rb with | .isBool .., _ | _, .isBool .. => failure | .isNegNNRat _ .., _ | _, .isNegNNRat _ .. => ratArm -- mixing positive rationals and negative naturals means we need to use the full rat handler | .isNNRat _ .., .isNegNat _ .. | .isNegNat _ .., .isNNRat _ .. => ratArm | .isNNRat _ .., _ | _, .isNNRat _ .. => nnratArm | .isNegNat _ .., _ | _, .isNegNat _ .. => intArm | .isNat ra na pa, .isNat rb nb pb => let ⟨_, _, _i⟩ ← inferOrderedSemiring α haveI' : $ra =Q by clear! $ra $rb; infer_instance := ⟨⟩ haveI' : $rb =Q by clear! $ra $rb; infer_instance := ⟨⟩ haveI' : $e =Q ($a < $b) := ⟨⟩ assumeInstancesCommute if na.natLit! < nb.natLit! then if let .some _i ← trySynthInstanceQ q(CharZero $α) then let r : Q(Nat.ble $nb $na = false) := (q(Eq.refl false) : Expr) return .isTrue q(isNat_lt_true $pa $pb $r) else -- Nats can appear in an `OrderedRing` without `CharZero`. intArm else let r : Q(Nat.ble $nb $na = true) := (q(Eq.refl true) : Expr) return .isFalse q(isNat_lt_false $pa $pb $r) end Mathlib.Meta.NormNum
Ring.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.GradedMonoid import Mathlib.Algebra.DirectSum.Basic import Mathlib.Algebra.Ring.Associator /-! # Additively-graded multiplicative structures on `⨁ i, A i` This module provides a set of heterogeneous typeclasses for defining a multiplicative structure over `⨁ i, A i` such that `(*) : A i → A j → A (i + j)`; that is to say, `A` forms an additively-graded ring. The typeclasses are: * `DirectSum.GNonUnitalNonAssocSemiring A` * `DirectSum.GSemiring A` * `DirectSum.GRing A` * `DirectSum.GCommSemiring A` * `DirectSum.GCommRing A` Respectively, these imbue the external direct sum `⨁ i, A i` with: * `DirectSum.nonUnitalNonAssocSemiring`, `DirectSum.nonUnitalNonAssocRing` * `DirectSum.semiring` * `DirectSum.ring` * `DirectSum.commSemiring` * `DirectSum.commRing` the base ring `A 0` with: * `DirectSum.GradeZero.nonUnitalNonAssocSemiring`, `DirectSum.GradeZero.nonUnitalNonAssocRing` * `DirectSum.GradeZero.semiring` * `DirectSum.GradeZero.ring` * `DirectSum.GradeZero.commSemiring` * `DirectSum.GradeZero.commRing` and the `i`th grade `A i` with `A 0`-actions (`•`) defined as left-multiplication: * `DirectSum.GradeZero.smul (A 0)`, `DirectSum.GradeZero.smulWithZero (A 0)` * `DirectSum.GradeZero.module (A 0)` * (nothing) * (nothing) * (nothing) Note that in the presence of these instances, `⨁ i, A i` itself inherits an `A 0`-action. `DirectSum.ofZeroRingHom : A 0 →+* ⨁ i, A i` provides `DirectSum.of A 0` as a ring homomorphism. `DirectSum.toSemiring` extends `DirectSum.toAddMonoid` to produce a `RingHom`. ## Direct sums of subobjects Additionally, this module provides helper functions to construct `GSemiring` and `GCommSemiring` instances for: * `A : ι → Submonoid S`: `DirectSum.GSemiring.ofAddSubmonoids`, `DirectSum.GCommSemiring.ofAddSubmonoids`. * `A : ι → Subgroup S`: `DirectSum.GSemiring.ofAddSubgroups`, `DirectSum.GCommSemiring.ofAddSubgroups`. * `A : ι → Submodule S`: `DirectSum.GSemiring.ofSubmodules`, `DirectSum.GCommSemiring.ofSubmodules`. If `sSupIndep A`, these provide a gradation of `⨆ i, A i`, and the mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as `DirectSum.toMonoid (fun i ↦ AddSubmonoid.inclusion <| le_iSup A i)`. ## Tags graded ring, filtered ring, direct sum, add_submonoid -/ variable {ι : Type*} [DecidableEq ι] namespace DirectSum open DirectSum /-! ### Typeclasses -/ section Defs variable (A : ι → Type*) /-- A graded version of `NonUnitalNonAssocSemiring`. -/ class GNonUnitalNonAssocSemiring [Add ι] [∀ i, AddCommMonoid (A i)] extends GradedMonoid.GMul A where /-- Multiplication from the right with any graded component's zero vanishes. -/ mul_zero : ∀ {i j} (a : A i), mul a (0 : A j) = 0 /-- Multiplication from the left with any graded component's zero vanishes. -/ zero_mul : ∀ {i j} (b : A j), mul (0 : A i) b = 0 /-- Multiplication from the right between graded components distributes with respect to addition. -/ mul_add : ∀ {i j} (a : A i) (b c : A j), mul a (b + c) = mul a b + mul a c /-- Multiplication from the left between graded components distributes with respect to addition. -/ add_mul : ∀ {i j} (a b : A i) (c : A j), mul (a + b) c = mul a c + mul b c end Defs section Defs variable (A : ι → Type*) /-- A graded version of `Semiring`. -/ class GSemiring [AddMonoid ι] [∀ i, AddCommMonoid (A i)] extends GNonUnitalNonAssocSemiring A, GradedMonoid.GMonoid A where /-- The canonical map from ℕ to the zeroth component of a graded semiring. -/ natCast : ℕ → A 0 /-- The canonical map from ℕ to a graded semiring respects zero. -/ natCast_zero : natCast 0 = 0 /-- The canonical map from ℕ to a graded semiring respects successors. -/ natCast_succ : ∀ n : ℕ, natCast (n + 1) = natCast n + GradedMonoid.GOne.one /-- A graded version of `CommSemiring`. -/ class GCommSemiring [AddCommMonoid ι] [∀ i, AddCommMonoid (A i)] extends GSemiring A, GradedMonoid.GCommMonoid A /-- A graded version of `Ring`. -/ class GRing [AddMonoid ι] [∀ i, AddCommGroup (A i)] extends GSemiring A where /-- The canonical map from ℤ to the zeroth component of a graded ring. -/ intCast : ℤ → A 0 /-- The canonical map from ℤ to a graded ring extends the canonical map from ℕ to the underlying graded semiring. -/ intCast_ofNat : ∀ n : ℕ, intCast n = natCast n /-- On negative integers, the canonical map from ℤ to a graded ring is the negative extension of the canonical map from ℕ to the underlying graded semiring. -/ -- Porting note: -(n + 1) -> Int.negSucc intCast_negSucc_ofNat : ∀ n : ℕ, intCast (Int.negSucc n) = -natCast (n + 1 : ℕ) /-- A graded version of `CommRing`. -/ class GCommRing [AddCommMonoid ι] [∀ i, AddCommGroup (A i)] extends GRing A, GCommSemiring A end Defs theorem of_eq_of_gradedMonoid_eq {A : ι → Type*} [∀ i : ι, AddCommMonoid (A i)] {i j : ι} {a : A i} {b : A j} (h : GradedMonoid.mk i a = GradedMonoid.mk j b) : DirectSum.of A i a = DirectSum.of A j b := DFinsupp.single_eq_of_sigma_eq h variable (A : ι → Type*) /-! ### Instances for `⨁ i, A i` -/ section One variable [Zero ι] [GradedMonoid.GOne A] [∀ i, AddCommMonoid (A i)] instance : One (⨁ i, A i) where one := DirectSum.of A 0 GradedMonoid.GOne.one theorem one_def : 1 = DirectSum.of A 0 GradedMonoid.GOne.one := rfl end One section Mul variable [Add ι] [∀ i, AddCommMonoid (A i)] [GNonUnitalNonAssocSemiring A] open AddMonoidHom (flip_apply coe_comp compHom) /-- The piecewise multiplication from the `Mul` instance, as a bundled homomorphism. -/ @[simps] def gMulHom {i j} : A i →+ A j →+ A (i + j) where toFun a := { toFun := fun b => GradedMonoid.GMul.mul a b map_zero' := GNonUnitalNonAssocSemiring.mul_zero _ map_add' := GNonUnitalNonAssocSemiring.mul_add _ } map_zero' := AddMonoidHom.ext fun a => GNonUnitalNonAssocSemiring.zero_mul a map_add' _ _ := AddMonoidHom.ext fun _ => GNonUnitalNonAssocSemiring.add_mul _ _ _ /-- The multiplication from the `Mul` instance, as a bundled homomorphism. -/ -- See note [non-reducible instance] @[reducible] def mulHom : (⨁ i, A i) →+ (⨁ i, A i) →+ ⨁ i, A i := DirectSum.toAddMonoid fun _ => AddMonoidHom.flip <| DirectSum.toAddMonoid fun _ => AddMonoidHom.flip <| (DirectSum.of A _).compHom.comp <| gMulHom A instance instMul : Mul (⨁ i, A i) where mul := fun a b => mulHom A a b instance : NonUnitalNonAssocSemiring (⨁ i, A i) := { (inferInstance : AddCommMonoid _) with zero_mul := fun _ => by simp only [Mul.mul, HMul.hMul, map_zero, AddMonoidHom.zero_apply] mul_zero := fun _ => by simp only [Mul.mul, HMul.hMul, AddMonoidHom.map_zero] left_distrib := fun _ _ _ => by simp only [Mul.mul, HMul.hMul, AddMonoidHom.map_add] right_distrib := fun _ _ _ => by simp only [Mul.mul, HMul.hMul, AddMonoidHom.map_add, AddMonoidHom.add_apply] } variable {A} theorem mulHom_apply (a b : ⨁ i, A i) : mulHom A a b = a * b := rfl theorem mulHom_of_of {i j} (a : A i) (b : A j) : mulHom A (of A i a) (of A j b) = of A (i + j) (GradedMonoid.GMul.mul a b) := by simp theorem of_mul_of {i j} (a : A i) (b : A j) : of A i a * of A j b = of _ (i + j) (GradedMonoid.GMul.mul a b) := mulHom_of_of a b end Mul section Semiring variable [∀ i, AddCommMonoid (A i)] [AddMonoid ι] [GSemiring A] open AddMonoidHom (flipHom coe_comp compHom flip_apply) private nonrec theorem one_mul (x : ⨁ i, A i) : 1 * x = x := by suffices mulHom A One.one = AddMonoidHom.id (⨁ i, A i) from DFunLike.congr_fun this x apply addHom_ext; intro i xi simp only [One.one] rw [mulHom_of_of] exact of_eq_of_gradedMonoid_eq (one_mul <| GradedMonoid.mk i xi) private nonrec theorem mul_one (x : ⨁ i, A i) : x * 1 = x := by suffices (mulHom A).flip One.one = AddMonoidHom.id (⨁ i, A i) from DFunLike.congr_fun this x apply addHom_ext; intro i xi simp only [One.one] rw [flip_apply, mulHom_of_of] exact of_eq_of_gradedMonoid_eq (mul_one <| GradedMonoid.mk i xi) private theorem mul_assoc (a b c : ⨁ i, A i) : a * b * c = a * (b * c) := by -- (`fun a b c => a * b * c` as a bundled hom) = (`fun a b c => a * (b * c)` as a bundled hom) suffices AddMonoidHom.mulLeft₃ = AddMonoidHom.mulRight₃ by simpa only [AddMonoidHom.mulLeft₃_apply, AddMonoidHom.mulRight₃_apply] using DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this a) b) c ext ai ax bi bx ci cx : 6 dsimp only [coe_comp, Function.comp_apply, AddMonoidHom.mulLeft₃_apply, AddMonoidHom.mulRight₃_apply] simp_rw [of_mul_of] exact of_eq_of_gradedMonoid_eq (_root_.mul_assoc (GradedMonoid.mk ai ax) ⟨bi, bx⟩ ⟨ci, cx⟩) instance instNatCast : NatCast (⨁ i, A i) where natCast := fun n => of _ _ (GSemiring.natCast n) /-- The `Semiring` structure derived from `GSemiring A`. -/ instance semiring : Semiring (⨁ i, A i) := { (inferInstance : NonUnitalNonAssocSemiring _) with one_mul := one_mul A mul_one := mul_one A mul_assoc := mul_assoc A toNatCast := instNatCast _ natCast_zero := by simp only [NatCast.natCast, GSemiring.natCast_zero, map_zero] natCast_succ := fun n => by simp_rw [NatCast.natCast, GSemiring.natCast_succ] rw [map_add] rfl } theorem ofPow {i} (a : A i) (n : ℕ) : of _ i a ^ n = of _ (n • i) (GradedMonoid.GMonoid.gnpow _ a) := by induction n with | zero => exact of_eq_of_gradedMonoid_eq (pow_zero <| GradedMonoid.mk _ a).symm | succ n n_ih => rw [pow_succ, n_ih, of_mul_of] exact of_eq_of_gradedMonoid_eq (pow_succ (GradedMonoid.mk _ a) n).symm theorem ofList_dProd {α} (l : List α) (fι : α → ι) (fA : ∀ a, A (fι a)) : of A _ (l.dProd fι fA) = (l.map fun a => of A (fι a) (fA a)).prod := by induction l with | nil => simp only [List.map_nil, List.prod_nil, List.dProd_nil]; rfl | cons head tail => rename_i ih simp only [List.map_cons, List.prod_cons, List.dProd_cons, ← ih] rw [DirectSum.of_mul_of (fA head)] rfl theorem list_prod_ofFn_of_eq_dProd (n : ℕ) (fι : Fin n → ι) (fA : ∀ a, A (fι a)) : (List.ofFn fun a => of A (fι a) (fA a)).prod = of A _ ((List.finRange n).dProd fι fA) := by rw [List.ofFn_eq_map, ofList_dProd] theorem mul_eq_dfinsuppSum [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (a a' : ⨁ i, A i) : a * a' = a.sum fun _ ai => a'.sum fun _ aj => DirectSum.of _ _ <| GradedMonoid.GMul.mul ai aj := by change mulHom _ a a' = _ -- Porting note: I have no idea how the proof from ml3 worked it used to be -- simpa only [mul_hom, to_add_monoid, dfinsupp.lift_add_hom_apply, dfinsupp.sum_add_hom_apply, -- add_monoid_hom.dfinsupp_sum_apply, flip_apply, add_monoid_hom.dfinsupp_sum_add_hom_apply], rw [mulHom, toAddMonoid, DFinsupp.liftAddHom_apply] dsimp only [DirectSum] rw [DFinsupp.sumAddHom_apply, AddMonoidHom.dfinsuppSum_apply] apply congrArg _ simp_rw [flip_apply] funext x -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [DFinsupp.sumAddHom_apply] simp only [gMulHom, AddMonoidHom.dfinsuppSum_apply, flip_apply, coe_comp, AddMonoidHom.coe_mk, ZeroHom.coe_mk, Function.comp_apply, AddMonoidHom.compHom_apply_apply] @[deprecated (since := "2025-04-06")] alias mul_eq_dfinsupp_sum := mul_eq_dfinsuppSum /-- A heavily unfolded version of the definition of multiplication -/ theorem mul_eq_sum_support_ghas_mul [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (a a' : ⨁ i, A i) : a * a' = ∑ ij ∈ DFinsupp.support a ×ˢ DFinsupp.support a', DirectSum.of _ _ (GradedMonoid.GMul.mul (a ij.fst) (a' ij.snd)) := by simp only [mul_eq_dfinsuppSum, DFinsupp.sum, Finset.sum_product] end Semiring section CommSemiring variable [∀ i, AddCommMonoid (A i)] [AddCommMonoid ι] [GCommSemiring A] private theorem mul_comm (a b : ⨁ i, A i) : a * b = b * a := by suffices mulHom A = (mulHom A).flip by rw [← mulHom_apply, this, AddMonoidHom.flip_apply, mulHom_apply] apply addHom_ext; intro ai ax; apply addHom_ext; intro bi bx rw [AddMonoidHom.flip_apply, mulHom_of_of, mulHom_of_of] exact of_eq_of_gradedMonoid_eq (GCommSemiring.mul_comm ⟨ai, ax⟩ ⟨bi, bx⟩) /-- The `CommSemiring` structure derived from `GCommSemiring A`. -/ instance commSemiring : CommSemiring (⨁ i, A i) := { DirectSum.semiring A with mul_comm := mul_comm A } end CommSemiring section NonUnitalNonAssocRing variable [∀ i, AddCommGroup (A i)] [Add ι] [GNonUnitalNonAssocSemiring A] /-- The `Ring` derived from `GSemiring A`. -/ instance nonAssocRing : NonUnitalNonAssocRing (⨁ i, A i) := { (inferInstance : NonUnitalNonAssocSemiring (⨁ i, A i)), (inferInstance : AddCommGroup (⨁ i, A i)) with } end NonUnitalNonAssocRing section Ring variable [∀ i, AddCommGroup (A i)] [AddMonoid ι] [GRing A] -- Porting note: overspecified fields in ml4 /-- The `Ring` derived from `GSemiring A`. -/ instance ring : Ring (⨁ i, A i) := { DirectSum.semiring A, (inferInstance : AddCommGroup (⨁ i, A i)) with toIntCast.intCast := fun z => of A 0 <| (GRing.intCast z) intCast_ofNat := fun _ => congrArg (of A 0) <| GRing.intCast_ofNat _ intCast_negSucc := fun _ => (congrArg (of A 0) <| GRing.intCast_negSucc_ofNat _).trans <| map_neg _ _} end Ring section CommRing variable [∀ i, AddCommGroup (A i)] [AddCommMonoid ι] [GCommRing A] /-- The `CommRing` derived from `GCommSemiring A`. -/ instance commRing : CommRing (⨁ i, A i) := { DirectSum.ring A, DirectSum.commSemiring A with } end CommRing /-! ### Instances for `A 0` The various `G*` instances are enough to promote the `AddCommMonoid (A 0)` structure to various types of multiplicative structure. -/ section GradeZero section One variable [Zero ι] [GradedMonoid.GOne A] [∀ i, AddCommMonoid (A i)] @[simp] theorem of_zero_one : of _ 0 (1 : A 0) = 1 := rfl end One section Mul variable [AddZeroClass ι] [∀ i, AddCommMonoid (A i)] [GNonUnitalNonAssocSemiring A] @[simp] theorem of_zero_smul {i} (a : A 0) (b : A i) : of _ _ (a • b) = of _ _ a * of _ _ b := (of_eq_of_gradedMonoid_eq (GradedMonoid.mk_zero_smul a b)).trans (of_mul_of _ _).symm @[simp] theorem of_zero_mul (a b : A 0) : of _ 0 (a * b) = of _ 0 a * of _ 0 b := of_zero_smul A a b instance GradeZero.nonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (A 0) := Function.Injective.nonUnitalNonAssocSemiring (of A 0) DFinsupp.single_injective (of A 0).map_zero (of A 0).map_add (of_zero_mul A) (map_nsmul _) instance GradeZero.smulWithZero (i : ι) : SMulWithZero (A 0) (A i) := by letI := SMulWithZero.compHom (⨁ i, A i) (of A 0).toZeroHom exact Function.Injective.smulWithZero (of A i).toZeroHom DFinsupp.single_injective (of_zero_smul A) end Mul section Semiring variable [∀ i, AddCommMonoid (A i)] [AddMonoid ι] [GSemiring A] @[simp] theorem of_zero_pow (a : A 0) : ∀ n : ℕ, of A 0 (a ^ n) = of A 0 a ^ n | 0 => by rw [pow_zero, pow_zero, DirectSum.of_zero_one] -- Porting note: Lean doesn't think this terminates if we only use `of_zero_pow` alone | n + 1 => by rw [pow_succ, pow_succ, of_zero_mul, of_zero_pow _ n] instance : NatCast (A 0) := ⟨GSemiring.natCast⟩ -- TODO: These could be replaced by the general lemmas for `AddMonoidHomClass` (`map_natCast'` and -- `map_ofNat'`) if those were marked `@[simp low]`. @[simp] theorem of_natCast (n : ℕ) : of A 0 n = n := rfl @[simp] theorem of_zero_ofNat (n : ℕ) [n.AtLeastTwo] : of A 0 ofNat(n) = ofNat(n) := of_natCast A n /-- The `Semiring` structure derived from `GSemiring A`. -/ instance GradeZero.semiring : Semiring (A 0) := Function.Injective.semiring (of A 0) DFinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) (fun _ _ ↦ (of A 0).map_nsmul _ _) (fun _ _ => of_zero_pow _ _ _) (of_natCast A) /-- `of A 0` is a `RingHom`, using the `DirectSum.GradeZero.semiring` structure. -/ def ofZeroRingHom : A 0 →+* ⨁ i, A i := { of _ 0 with map_one' := of_zero_one A map_mul' := of_zero_mul A } /-- Each grade `A i` derives an `A 0`-module structure from `GSemiring A`. Note that this results in an overall `Module (A 0) (⨁ i, A i)` structure via `DirectSum.module`. -/ instance GradeZero.module {i} : Module (A 0) (A i) := letI := Module.compHom (⨁ i, A i) (ofZeroRingHom A) DFinsupp.single_injective.module (A 0) (of A i) fun a => of_zero_smul A a end Semiring section CommSemiring variable [∀ i, AddCommMonoid (A i)] [AddCommMonoid ι] [GCommSemiring A] /-- The `CommSemiring` structure derived from `GCommSemiring A`. -/ instance GradeZero.commSemiring : CommSemiring (A 0) := Function.Injective.commSemiring (of A 0) DFinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) (fun _ _ ↦ map_nsmul _ _ _) (fun _ _ => of_zero_pow _ _ _) (of_natCast A) end CommSemiring section Ring variable [∀ i, AddCommGroup (A i)] [AddZeroClass ι] [GNonUnitalNonAssocSemiring A] /-- The `NonUnitalNonAssocRing` derived from `GNonUnitalNonAssocSemiring A`. -/ instance GradeZero.nonUnitalNonAssocRing : NonUnitalNonAssocRing (A 0) := Function.Injective.nonUnitalNonAssocRing (of A 0) DFinsupp.single_injective (of A 0).map_zero (of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub (fun _ _ ↦ map_nsmul _ _ _) (fun _ _ ↦ map_zsmul _ _ _) end Ring section Ring variable [∀ i, AddCommGroup (A i)] [AddMonoid ι] [GRing A] instance : IntCast (A 0) := ⟨GRing.intCast⟩ @[simp] theorem of_intCast (n : ℤ) : of A 0 n = n := by rfl /-- The `Ring` derived from `GSemiring A`. -/ instance GradeZero.ring : Ring (A 0) := Function.Injective.ring (of A 0) DFinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub (fun _ _ ↦ map_nsmul _ _ _) (fun _ _ ↦ map_zsmul _ _ _) (fun _ _ => of_zero_pow _ _ _) (of_natCast A) (of_intCast A) end Ring section CommRing variable [∀ i, AddCommGroup (A i)] [AddCommMonoid ι] [GCommRing A] /-- The `CommRing` derived from `GCommSemiring A`. -/ instance GradeZero.commRing : CommRing (A 0) := Function.Injective.commRing (of A 0) DFinsupp.single_injective (of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A) (of A 0).map_neg (of A 0).map_sub (fun _ _ ↦ map_nsmul _ _ _) (fun _ _ ↦ map_zsmul _ _ _) (fun _ _ => of_zero_pow _ _ _) (of_natCast A) (of_intCast A) end CommRing end GradeZero section ToSemiring variable {R : Type*} [∀ i, AddCommMonoid (A i)] [AddMonoid ι] [GSemiring A] [Semiring R] variable {A} /-- If two ring homomorphisms from `⨁ i, A i` are equal on each `of A i y`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext] theorem ringHom_ext' ⦃F G : (⨁ i, A i) →+* R⦄ (h : ∀ i, (↑F : _ →+ R).comp (of A i) = (↑G : _ →+ R).comp (of A i)) : F = G := RingHom.coe_addMonoidHom_injective <| DirectSum.addHom_ext' h /-- Two `RingHom`s out of a direct sum are equal if they agree on the generators. -/ theorem ringHom_ext ⦃f g : (⨁ i, A i) →+* R⦄ (h : ∀ i x, f (of A i x) = g (of A i x)) : f = g := ringHom_ext' fun i => AddMonoidHom.ext <| h i /-- A family of `AddMonoidHom`s preserving `DirectSum.One.one` and `DirectSum.Mul.mul` describes a `RingHom`s on `⨁ i, A i`. This is a stronger version of `DirectSum.toMonoid`. Of particular interest is the case when `A i` are bundled subobjects, `f` is the family of coercions such as `AddSubmonoid.subtype (A i)`, and the `[GSemiring A]` structure originates from `DirectSum.gsemiring.ofAddSubmonoids`, in which case the proofs about `GOne` and `GMul` can be discharged by `rfl`. -/ @[simps] def toSemiring (f : ∀ i, A i →+ R) (hone : f _ GradedMonoid.GOne.one = 1) (hmul : ∀ {i j} (ai : A i) (aj : A j), f _ (GradedMonoid.GMul.mul ai aj) = f _ ai * f _ aj) : (⨁ i, A i) →+* R := { toAddMonoid f with toFun := toAddMonoid f map_one' := by change (toAddMonoid f) (of _ 0 _) = 1 rw [toAddMonoid_of] exact hone map_mul' := by rw [(toAddMonoid f).map_mul_iff] refine DirectSum.addHom_ext' (fun xi ↦ AddMonoidHom.ext (fun xv ↦ ?_)) refine DirectSum.addHom_ext' (fun yi ↦ AddMonoidHom.ext (fun yv ↦ ?_)) change toAddMonoid f (of A xi xv * of A yi yv) = toAddMonoid f (of A xi xv) * toAddMonoid f (of A yi yv) simp_rw [of_mul_of, toAddMonoid_of] exact hmul _ _ } theorem toSemiring_of (f : ∀ i, A i →+ R) (hone hmul) (i : ι) (x : A i) : toSemiring f hone hmul (of _ i x) = f _ x := toAddMonoid_of f i x @[simp] theorem toSemiring_coe_addMonoidHom (f : ∀ i, A i →+ R) (hone hmul) : (toSemiring f hone hmul : (⨁ i, A i) →+ R) = toAddMonoid f := rfl /-- Families of `AddMonoidHom`s preserving `DirectSum.One.one` and `DirectSum.Mul.mul` are isomorphic to `RingHom`s on `⨁ i, A i`. This is a stronger version of `DFinsupp.liftAddHom`. -/ @[simps] def liftRingHom : { f : ∀ {i}, A i →+ R // f GradedMonoid.GOne.one = 1 ∧ ∀ {i j} (ai : A i) (aj : A j), f (GradedMonoid.GMul.mul ai aj) = f ai * f aj } ≃ ((⨁ i, A i) →+* R) where toFun f := toSemiring (fun _ => f.1) f.2.1 f.2.2 invFun F := ⟨by intro i; exact (F : (⨁ i, A i) →+ R).comp (of _ i), by simp only [AddMonoidHom.comp_apply] rw [← F.map_one] rfl, by intros i j ai aj simp only [AddMonoidHom.comp_apply, AddMonoidHom.coe_coe] rw [← F.map_mul (of A i ai), of_mul_of ai]⟩ left_inv f := by ext xi xv exact toAddMonoid_of (fun _ => f.1) xi xv right_inv F := by apply RingHom.coe_addMonoidHom_injective refine DirectSum.addHom_ext' (fun xi ↦ AddMonoidHom.ext (fun xv ↦ ?_)) simp only [DirectSum.toAddMonoid_of, AddMonoidHom.comp_apply, toSemiring_coe_addMonoidHom] end ToSemiring end DirectSum /-! ### Concrete instances -/ section Uniform variable (ι) /-- A direct sum of copies of a `NonUnitalNonAssocSemiring` inherits the multiplication structure. -/ instance NonUnitalNonAssocSemiring.directSumGNonUnitalNonAssocSemiring {R : Type*} [AddMonoid ι] [NonUnitalNonAssocSemiring R] : DirectSum.GNonUnitalNonAssocSemiring fun _ : ι => R := { -- Porting note: removed Mul.gMul ι with and we seem ok mul_zero := mul_zero zero_mul := zero_mul mul_add := mul_add add_mul := add_mul } /-- A direct sum of copies of a `Semiring` inherits the multiplication structure. -/ instance Semiring.directSumGSemiring {R : Type*} [AddMonoid ι] [Semiring R] : DirectSum.GSemiring fun _ : ι => R where __ := NonUnitalNonAssocSemiring.directSumGNonUnitalNonAssocSemiring ι __ := Monoid.gMonoid ι natCast n := n natCast_zero := Nat.cast_zero natCast_succ := Nat.cast_succ /-- A direct sum of copies of a `Ring` inherits the multiplication structure. -/ instance Ring.directSumGRing {R : Type*} [AddMonoid ι] [Ring R] : DirectSum.GRing fun _ : ι => R where __ := Semiring.directSumGSemiring ι intCast z := z intCast_ofNat := Int.cast_natCast intCast_negSucc_ofNat := Int.cast_negSucc open DirectSum -- To check `Mul.gmul_mul` matches example {R : Type*} [AddMonoid ι] [Semiring R] (i j : ι) (a b : R) : (DirectSum.of _ i a * DirectSum.of _ j b : ⨁ _, R) = DirectSum.of _ (i + j) (a * b) := by rw [DirectSum.of_mul_of, Mul.gMul_mul] /-- A direct sum of copies of a `CommSemiring` inherits the commutative multiplication structure. -/ instance CommSemiring.directSumGCommSemiring {R : Type*} [AddCommMonoid ι] [CommSemiring R] : DirectSum.GCommSemiring fun _ : ι => R where __ := Semiring.directSumGSemiring ι __ := CommMonoid.gCommMonoid ι /-- A direct sum of copies of a `CommRing` inherits the commutative multiplication structure. -/ instance CommRing.directSumGCommRing {R : Type*} [AddCommMonoid ι] [CommRing R] : DirectSum.GCommRing fun _ : ι => R where __ := Ring.directSumGRing ι __ := CommMonoid.gCommMonoid ι end Uniform
prime.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import choice fintype div bigop. (******************************************************************************) (* This file contains the definitions of: *) (* prime p <=> p is a prime. *) (* primes m == the sorted list of prime divisors of m > 1, else [::]. *) (* pfactor p e == the value p ^ e of a prime factor (p, e). *) (* NumFactor f == print version of a prime factor, converting the prime *) (* component to a Num (which can print large values). *) (* prime_decomp m == the list of prime factors of m > 1, sorted by primes. *) (* logn p m == the e such that (p ^ e) \in prime_decomp n, else 0. *) (* trunc_log p m == the largest e such that p ^ e <= m, or 0 if p <= 1 or *) (* m is 0. *) (* up_log p m == the smallest e such that m <= p ^ e, or 0 if p <= 1 *) (* pdiv n == the smallest prime divisor of n > 1, else 1. *) (* max_pdiv n == the largest prime divisor of n > 1, else 1. *) (* divisors m == the sorted list of divisors of m > 0, else [::]. *) (* totient n == the Euler totient (#|{i < n | i and n coprime}|). *) (* nat_pred == the type of explicit collective nat predicates. *) (* := simpl_pred nat. *) (* -> We allow the coercion nat >-> nat_pred, interpreting p as pred1 p. *) (* -> We define a predType for nat_pred, enabling the notation p \in pi. *) (* -> We don't have nat_pred >-> pred, which would imply nat >-> Funclass. *) (* pi^' == the complement of pi : nat_pred, i.e., the nat_pred such *) (* that (p \in pi^') = (p \notin pi). *) (* \pi(n) == the set of prime divisors of n, i.e., the nat_pred such *) (* that (p \in \pi(n)) = (p \in primes n). *) (* \pi(A) == the set of primes of #|A|, with A a collective predicate *) (* over a finite Type. *) (* -> The notation \pi(A) is implemented with a collapsible Coercion. The *) (* type of A must coerce to finpred_sort (e.g., by coercing to {set T}) *) (* and not merely implement the predType interface (as seq T does). *) (* -> The expression #|A| will only appear in \pi(A) after simplification *) (* collapses the coercion, so it is advisable to do so early on. *) (* pi.-nat n <=> n > 0 and all prime divisors of n are in pi. *) (* n`_pi == the pi-part of n -- the largest pi.-nat divisor of n. *) (* := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. *) (* -> The nat >-> nat_pred coercion lets us write p.-nat n and n`_p. *) (* In addition to the lemmas relevant to these definitions, this file also *) (* contains the dvdn_sum lemma, so that bigop.v doesn't depend on div.v. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "pi ^'" (format "pi ^'"). Reserved Notation "pi .-nat" (format "pi .-nat"). (* The complexity of any arithmetic operation with the Peano representation *) (* is pretty dreadful, so using algorithms for "harder" problems such as *) (* factoring, that are geared for efficient arithmetic leads to dismal *) (* performance -- it takes a significant time, for instance, to compute the *) (* divisors of just a two-digit number. On the other hand, for Peano *) (* integers, prime factoring (and testing) is linear-time with a small *) (* constant factor -- indeed, the same as converting in and out of a binary *) (* representation. This is implemented by the code below, which is then *) (* used to give the "standard" definitions of prime, primes, and divisors, *) (* which can then be used casually in proofs with moderately-sized numeric *) (* values (indeed, the code here performs well for up to 6-digit numbers). *) Module Import PrimeDecompAux. (* We start with faster mod-2 and 2-valuation functions. *) Fixpoint edivn2 q r := if r is r'.+2 then edivn2 q.+1 r' else (q, r). Lemma edivn2P n : edivn_spec n 2 (edivn2 0 n). Proof. rewrite -[n]odd_double_half addnC -{1}[n./2]addn0 -{1}mul2n mulnC. elim: n./2 {1 4}0 => [|r IHr] q; first by case (odd n) => /=. by rewrite addSnnS; apply: IHr. Qed. Fixpoint elogn2 e q r {struct q} := match q, r with | 0, _ | _, 0 => (e, q) | q'.+1, 1 => elogn2 e.+1 q' q' | q'.+1, r'.+2 => elogn2 e q' r' end. Arguments elogn2 : simpl nomatch. Variant elogn2_spec n : nat * nat -> Type := Elogn2Spec e m of n = 2 ^ e * m.*2.+1 : elogn2_spec n (e, m). Lemma elogn2P n : elogn2_spec n.+1 (elogn2 0 n n). Proof. rewrite -[n.+1]mul1n -[1]/(2 ^ 0) -[n in _ * n.+1](addKn n n) addnn. elim: n {1 4 6}n {2 3}0 (leqnn n) => [|q IHq] [|[|r]] e //=; last first. by move/ltnW; apply: IHq. rewrite subn1 prednK // -mul2n mulnA -expnSr. by rewrite -[q in _ * q.+1](addKn q q) addnn => _; apply: IHq. Qed. Definition ifnz T n (x y : T) := if n is 0 then y else x. Variant ifnz_spec T n (x y : T) : T -> Type := | IfnzPos of n > 0 : ifnz_spec n x y x | IfnzZero of n = 0 : ifnz_spec n x y y. Lemma ifnzP T n (x y : T) : ifnz_spec n x y (ifnz n x y). Proof. by case: n => [|n]; [right | left]. Qed. (* The list of divisors and the Euler function are computed directly from *) (* the decomposition, using a merge_sort variant sort of the divisor list. *) Definition add_divisors f divs := let: (p, e) := f in let add1 divs' := merge leq (map (NatTrec.mul p) divs') divs in iter e add1 divs. Import NatTrec. Definition add_totient_factor f m := let: (p, e) := f in p.-1 * p ^ e.-1 * m. Definition cons_pfactor (p e : nat) pd := ifnz e ((p, e) :: pd) pd. Notation "p ^? e :: pd" := (cons_pfactor p e pd) (at level 30, e at level 30, pd at level 60) : nat_scope. End PrimeDecompAux. (* For pretty-printing. *) Definition NumFactor (f : nat * nat) := ([Num of f.1], f.2). Definition pfactor p e := p ^ e. Section prime_decomp. Import NatTrec. Local Fixpoint prime_decomp_rec m k a b c e := let p := k.*2.+1 in if a is a'.+1 then if b - (ifnz e 1 k - c) is b'.+1 then [rec m, k, a', b', ifnz c c.-1 (ifnz e p.-2 1), e] else if (b == 0) && (c == 0) then let b' := k + a' in [rec b'.*2.+3, k, a', b', k.-1, e.+1] else let bc' := ifnz e (ifnz b (k, 0) (edivn2 0 c)) (b, c) in p ^? e :: ifnz a' [rec m, k.+1, a'.-1, bc'.1 + a', bc'.2, 0] [:: (m, 1)] else if (b == 0) && (c == 0) then [:: (p, e.+2)] else p ^? e :: [:: (m, 1)] where "[ 'rec' m , k , a , b , c , e ]" := (prime_decomp_rec m k a b c e). Definition prime_decomp n := let: (e2, m2) := elogn2 0 n.-1 n.-1 in if m2 < 2 then 2 ^? e2 :: 3 ^? m2 :: [::] else let: (a, bc) := edivn m2.-2 3 in let: (b, c) := edivn (2 - bc) 2 in 2 ^? e2 :: [rec m2.*2.+1, 1, a, b, c, 0]. End prime_decomp. Definition primes n := unzip1 (prime_decomp n). Definition prime p := if prime_decomp p is [:: (_ , 1)] then true else false. Definition nat_pred := simpl_pred nat. Definition pi_arg := nat. Coercion pi_arg_of_nat (n : nat) : pi_arg := n. Coercion pi_arg_of_fin_pred T pT (A : @fin_pred_sort T pT) : pi_arg := #|A|. Arguments pi_arg_of_nat n /. Arguments pi_arg_of_fin_pred {T pT} A /. Definition pi_of (n : pi_arg) : nat_pred := [pred p in primes n]. Notation "\pi ( n )" := (pi_of n) (format "\pi ( n )") : nat_scope. Notation "\p 'i' ( A )" := \pi(#|A|) (format "\p 'i' ( A )") : nat_scope. Definition pdiv n := head 1 (primes n). Definition max_pdiv n := last 1 (primes n). Definition divisors n := foldr add_divisors [:: 1] (prime_decomp n). Definition totient n := foldr add_totient_factor (n > 0) (prime_decomp n). (* Correctness of the decomposition algorithm. *) Lemma prime_decomp_correct : let pd_val pd := \prod_(f <- pd) pfactor f.1 f.2 in let lb_dvd q m := ~~ has [pred d | d %| m] (index_iota 2 q) in let pf_ok f := lb_dvd f.1 f.1 && (0 < f.2) in let pd_ord q pd := path ltn q (unzip1 pd) in let pd_ok q n pd := [/\ n = pd_val pd, all pf_ok pd & pd_ord q pd] in forall n, n > 0 -> pd_ok 1 n (prime_decomp n). Proof. rewrite unlock => pd_val lb_dvd pf_ok pd_ord pd_ok. have leq_pd_ok m p q pd: q <= p -> pd_ok p m pd -> pd_ok q m pd. rewrite /pd_ok /pd_ord; case: pd => [|[r _] pd] //= leqp [<- ->]. by case/andP=> /(leq_trans _)->. have apd_ok m e q p pd: lb_dvd p p || (e == 0) -> q < p -> pd_ok p m pd -> pd_ok q (p ^ e * m) (p ^? e :: pd). - case: e => [|e]; rewrite orbC /= => pr_p ltqp. by rewrite mul1n; apply: leq_pd_ok; apply: ltnW. by rewrite /pd_ok /pd_ord /pf_ok /= pr_p ltqp => [[<- -> ->]]. case=> // n _; rewrite /prime_decomp. case: elogn2P => e2 m2 -> {n}; case: m2 => [|[|abc]]; try exact: apd_ok. rewrite [_.-2]/= !ltnS ltn0 natTrecE; case: edivnP => a bc ->{abc}. case: edivnP => b c def_bc /= ltc2 ltbc3; apply: (apd_ok) => //. move def_m: _.*2.+1 => m; set k := {2}1; rewrite -[2]/k.*2; set e := 0. pose p := k.*2.+1; rewrite -{1}[m]mul1n -[1]/(p ^ e)%N. have{def_m bc def_bc ltc2 ltbc3}: let kb := (ifnz e k 1).*2 in [&& k > 0, p < m, lb_dvd p m, c < kb & lb_dvd p p || (e == 0)] /\ m + (b * kb + c).*2 = p ^ 2 + (a * p).*2. - rewrite -def_m [in lb_dvd _ _]def_m; split=> //=; last first. by rewrite -def_bc addSn -doubleD 2!addSn -addnA subnKC // addnC. rewrite ltc2 /lb_dvd /index_iota /= dvdn2 -def_m. by rewrite [_.+2]lock /= odd_double. have [n] := ubnP a. elim: n => // n IHn in a (k) p m b c (e) * => /ltnSE-le_a_n []. set kb := _.*2; set d := _ + c => /and5P[lt0k ltpm leppm ltc pr_p def_m]. have def_k1: k.-1.+1 = k := ltn_predK lt0k. have def_kb1: kb.-1.+1 = kb by rewrite /kb -def_k1; case e. have eq_bc_0: (b == 0) && (c == 0) = (d == 0). by rewrite addn_eq0 muln_eq0 orbC -def_kb1. have lt1p: 1 < p by rewrite ltnS double_gt0. have co_p_2: coprime p 2 by rewrite /coprime gcdnC gcdnE modn2 /= odd_double. have if_d0: d = 0 -> [/\ m = (p + a.*2) * p, lb_dvd p p & lb_dvd p (p + a.*2)]. move=> d0; have{d0} def_m: m = (p + a.*2) * p. by rewrite d0 addn0 -!mul2n mulnA -mulnDl in def_m *. split=> //; apply/hasPn=> r /(hasPn leppm); apply: contra => /= dv_r. by rewrite def_m dvdn_mull. by rewrite def_m dvdn_mulr. case def_a: a => [|a'] /= in le_a_n *; rewrite !natTrecE -/p {}eq_bc_0. case: d if_d0 def_m => [[//| def_m {}pr_p pr_m'] _ | d _ def_m] /=. rewrite def_m def_a addn0 mulnA -2!expnSr. by split; rewrite /pd_ord /pf_ok /= ?muln1 ?pr_p ?leqnn. apply: apd_ok; rewrite // /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm. rewrite /pf_ok !andbT /=; split=> //; apply: contra leppm. case/hasP=> r /=; rewrite mem_index_iota => /andP[lt1r ltrm] dvrm; apply/hasP. have [ltrp | lepr] := ltnP r p. by exists r; rewrite // mem_index_iota lt1r. case/dvdnP: dvrm => q def_q; exists q; last by rewrite def_q /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1r)) -def_q mul1n ltrm. move: def_m; rewrite def_a addn0 -(@ltn_pmul2r p) // mulnn => <-. apply: (@leq_ltn_trans m); first by rewrite def_q leq_mul. by rewrite -addn1 leq_add2l. have def_k2: k.*2 = ifnz e 1 k * kb. by rewrite /kb; case: (e) => [|e']; rewrite (mul1n, muln2). case def_b': (b - _) => [|b']; last first. have ->: ifnz e k.*2.-1 1 = kb.-1 by rewrite /kb; case e. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split=> //. rewrite lt0k ltpm leppm pr_p andbT /=. by case: ifnzP; [move/ltn_predK->; apply: ltnW | rewrite def_kb1]. apply: (@addIn p.*2). rewrite -2!addnA -!doubleD -addnA -mulSnr -def_a -def_m /d. have ->: b * kb = b' * kb + (k.*2 - c * kb + kb). rewrite addnCA addnC -mulSnr -def_b' def_k2 -mulnBl -mulnDl subnK //. by rewrite ltnW // -subn_gt0 def_b'. rewrite -addnA; congr (_ + (_ + _).*2). case: (c) ltc; first by rewrite -addSnnS def_kb1 subn0 addn0 addnC. rewrite /kb; case e => [[] // _ | e' c' _] /=; last first. by rewrite subnDA subnn addnC addSnnS. by rewrite mul1n -doubleB -doubleD subn1 !addn1 def_k1. have ltdp: d < p. move/eqP: def_b'; rewrite subn_eq0 -(@leq_pmul2r kb); last first. by rewrite -def_kb1. rewrite mulnBl -def_k2 ltnS -(leq_add2r c); move/leq_trans; apply. have{} ltc: c < k.*2. by apply: (leq_trans ltc); rewrite leq_double /kb; case e. rewrite -{2}(subnK (ltnW ltc)) leq_add2r leq_sub2l //. by rewrite -def_kb1 mulnS leq_addr. case def_d: d if_d0 => [|d'] => [[//|{ltdp pr_p}def_m pr_p pr_m'] | _]. rewrite eqxx -doubleS -addnS -def_a doubleD -addSn -/p def_m. rewrite mulnCA mulnC -expnSr. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split. rewrite lt0k -addn1 leq_add2l {1}def_a pr_m' pr_p /= def_k1 -addnn. by rewrite leq_addr. rewrite -addnA -doubleD addnCA def_a addSnnS def_k1 -(addnC k) -mulnSr. by rewrite -[_.*2.+1]/p mulnDl doubleD addnA -mul2n mulnA mul2n -mulSn. have next_pm: lb_dvd p.+2 m. rewrite /lb_dvd /index_iota (addKn 2) -(subnK lt1p) iotaD has_cat. apply/norP; split; rewrite //= orbF subnKC // orbC. apply/norP; split; apply/dvdnP=> [[q def_q]]. case/hasP: leppm; exists 2; first by rewrite /p -(subnKC lt0k). by rewrite /= def_q dvdn_mull // dvdn2 /= odd_double. move/(congr1 (dvdn p)): def_m; rewrite -!mul2n mulnA -mulnDl. rewrite dvdn_mull // dvdn_addr; last by rewrite def_q dvdn_mull. case/dvdnP=> r; rewrite mul2n => def_r; move: ltdp (congr1 odd def_r). rewrite odd_double -ltn_double def_r -mul2n ltn_pmul2r //. by case: r def_r => [|[|[]]] //; rewrite def_d // mul1n /= odd_double. apply: apd_ok => //; case: a' def_a le_a_n => [|a'] def_a => [_ | lta] /=. rewrite /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm /pf_ok !andbT /=. split=> //; apply: contra next_pm. case/hasP=> q; rewrite mem_index_iota => /andP[lt1q ltqm] dvqm; apply/hasP. have [ltqp | lepq] := ltnP q p.+2. by exists q; rewrite // mem_index_iota lt1q. case/dvdnP: dvqm => r def_r; exists r; last by rewrite def_r /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1q)) -def_r mul1n ltqm /=. rewrite -(@ltn_pmul2l p.+2) //; apply: (@leq_ltn_trans m). by rewrite def_r mulnC leq_mul. rewrite -addn2 mulnn sqrnD mul2n muln2 -addnn addnACA. by rewrite def_a mul1n in def_m; rewrite -def_m addnS /= ltnS -addnA leq_addr. set bc := ifnz _ _ _; apply: leq_pd_ok (leqnSn _) _. rewrite -doubleS -{1}[m]mul1n -[1]/(k.+1.*2.+1 ^ 0)%N. apply: IHn; first exact: ltnW. rewrite doubleS -/p [ifnz 0 _ _]/=; do 2?split => //. rewrite orbT next_pm /= -(leq_add2r d.*2) def_m 2!addSnnS -doubleS leq_add. - move: ltc; rewrite /kb {}/bc andbT; case e => //= e' _; case: ifnzP => //. by case: edivn2P. - by rewrite -[ltnLHS]muln1 ltn_pmul2l. by rewrite leq_double def_a mulSn (leq_trans ltdp) ?leq_addr. rewrite mulnDl !muln2 -addnA addnCA doubleD addnCA. rewrite (_ : _ + bc.2 = d); last first. rewrite /d {}/bc /kb -muln2. case: (e) (b) def_b' => //= _ []; first by case: edivn2P. by case c; do 2?case; rewrite // mul1n /= muln2. rewrite def_m 3!doubleS addnC -(addn2 p) sqrnD mul2n muln2 -3!addnA. congr (_ + _); rewrite 4!addnS -!doubleD; congr _.*2.+2.+2. by rewrite def_a -add2n mulnDl -addnA -muln2 -mulnDr mul2n. Qed. Lemma primePn n : reflect (n < 2 \/ exists2 d, 1 < d < n & d %| n) (~~ prime n). Proof. rewrite /prime; case: n => [|[|p2]]; try by do 2!left. case: (@prime_decomp_correct p2.+2) => //; rewrite unlock. case: prime_decomp => [|[q [|[|e]]] pd] //=; last first; last by rewrite andbF. rewrite {1}/pfactor 2!expnS -!mulnA /=. case: (_ ^ _ * _) => [|u -> _ /andP[lt1q _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. have lt0q := ltnW lt1q; rewrite lt1q -[ltnLHS]muln1 ltn_pmul2l //. by rewrite -[2]muln1 leq_mul. rewrite {1}/pfactor expn1; case: pd => [|[r e] pd] /=; last first. case: e => [|e] /=; first by rewrite !andbF. rewrite {1}/pfactor expnS -mulnA. case: (_ ^ _ * _) => [|u -> _ /and3P[lt1q ltqr _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. by rewrite lt1q -[ltnLHS]mul1n ltn_mul // -[q.+1]muln1 leq_mul. rewrite muln1 !andbT => def_q pr_q lt1q; right=> [[]] // [d]. by rewrite def_q -mem_index_iota => in_d_2q dv_d_q; case/hasP: pr_q; exists d. Qed. Lemma primeNsig n : ~~ prime n -> 2 <= n -> { d : nat | 1 < d < n & d %| n }. Proof. by move=> /primePn; case: ltnP => // lt1n nP _; apply/sig2W; case: nP. Qed. Lemma primeP p : reflect (p > 1 /\ forall d, d %| p -> xpred2 1 p d) (prime p). Proof. rewrite -[prime p]negbK; have [npr_p | pr_p] := primePn p. right=> [[lt1p pr_p]]; case: npr_p => [|[d n1pd]]. by rewrite ltnNge lt1p. by move/pr_p=> /orP[] /eqP def_d; rewrite def_d ltnn ?andbF in n1pd. have [lep1 | lt1p] := leqP; first by case: pr_p; left. left; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]; case: pr_p; right. exists d; rewrite // andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_nt_dvdP d p : prime p -> d != 1 -> reflect (d = p) (d %| p). Proof. case/primeP=> _ min_p d_neq1; apply: (iffP idP) => [/min_p|-> //]. by rewrite (negPf d_neq1) /= => /eqP. Qed. Arguments primeP {p}. Arguments primePn {n}. Lemma prime_gt1 p : prime p -> 1 < p. Proof. by case/primeP. Qed. Lemma prime_gt0 p : prime p -> 0 < p. Proof. by move/prime_gt1; apply: ltnW. Qed. #[global] Hint Resolve prime_gt1 prime_gt0 : core. Lemma prod_prime_decomp n : n > 0 -> n = \prod_(f <- prime_decomp n) f.1 ^ f.2. Proof. by case/prime_decomp_correct. Qed. Lemma even_prime p : prime p -> p = 2 \/ odd p. Proof. move=> pr_p; case odd_p: (odd p); [by right | left]. have: 2 %| p by rewrite dvdn2 odd_p. by case/primeP: pr_p => _ dv_p /dv_p/(2 =P p). Qed. Lemma prime_oddPn p : prime p -> reflect (p = 2) (~~ odd p). Proof. by move=> p_pr; apply: (iffP idP) => [|-> //]; case/even_prime: p_pr => ->. Qed. Lemma odd_prime_gt2 p : odd p -> prime p -> p > 2. Proof. by move=> odd_p /prime_gt1; apply: odd_gt2. Qed. Lemma mem_prime_decomp n p e : (p, e) \in prime_decomp n -> [/\ prime p, e > 0 & p ^ e %| n]. Proof. case: (posnP n) => [-> //| /prime_decomp_correct[def_n mem_pd ord_pd pd_pe]]. have /andP[pr_p ->] := allP mem_pd _ pd_pe; split=> //; last first. case/splitPr: pd_pe def_n => pd1 pd2 ->. by rewrite big_cat big_cons /= mulnCA dvdn_mulr. have lt1p: 1 < p. apply: (allP (order_path_min ltn_trans ord_pd)). by apply/mapP; exists (p, e). apply/primeP; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]. case/hasP: pr_p; exists d => //. rewrite mem_index_iota andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_coprime p m : prime p -> coprime p m = ~~ (p %| m). Proof. case/primeP=> p_gt1 p_pr; apply/eqP/negP=> [d1 | ndv_pm]. case/dvdnP=> k def_m; rewrite -(addn0 m) def_m gcdnMDl gcdn0 in d1. by rewrite d1 in p_gt1. by apply: gcdn_def => // d /p_pr /orP[] /eqP->. Qed. Lemma dvdn_prime2 p q : prime p -> prime q -> (p %| q) = (p == q). Proof. move=> pr_p pr_q; apply: negb_inj. by rewrite eqn_dvd negb_and -!prime_coprime // coprime_sym orbb. Qed. Lemma Euclid_dvd1 p : prime p -> (p %| 1) = false. Proof. by rewrite dvdn1; case: eqP => // ->. Qed. Lemma Euclid_dvdM m n p : prime p -> (p %| m * n) = (p %| m) || (p %| n). Proof. move=> pr_p; case dv_pm: (p %| m); first exact: dvdn_mulr. by rewrite Gauss_dvdr // prime_coprime // dv_pm. Qed. Lemma Euclid_dvd_prod (I : Type) (r : seq I) (P : pred I) (f : I -> nat) p : prime p -> p %| \prod_(i <- r | P i) f i = \big[orb/false]_(i <- r | P i) (p %| f i). Proof. move=> pP; apply: big_morph=> [x y|]; [exact: Euclid_dvdM | exact: Euclid_dvd1]. Qed. Lemma Euclid_dvdX m n p : prime p -> (p %| m ^ n) = (p %| m) && (n > 0). Proof. case: n => [|n] pr_p; first by rewrite andbF Euclid_dvd1. by apply: (inv_inj negbK); rewrite !andbT -!prime_coprime // coprime_pexpr. Qed. Lemma mem_primes p n : (p \in primes n) = [&& prime p, n > 0 & p %| n]. Proof. rewrite andbCA; have [-> // | /= n_gt0] := posnP. apply/mapP/andP=> [[[q e]]|[pr_p]] /=. case/mem_prime_decomp=> pr_q e_gt0 /dvdnP [u ->] -> {p}. by rewrite -(prednK e_gt0) expnS mulnCA dvdn_mulr. rewrite [n in _ %| n]prod_prime_decomp // big_seq. apply big_ind => [| u v IHu IHv | [q e] /= mem_qe dv_p_qe]. - by rewrite Euclid_dvd1. - by rewrite Euclid_dvdM // => /orP[]. exists (q, e) => //=; case/mem_prime_decomp: mem_qe => pr_q _ _. by rewrite Euclid_dvdX // dvdn_prime2 // in dv_p_qe; case: eqP dv_p_qe. Qed. Lemma sorted_primes n : sorted ltn (primes n). Proof. by case: (posnP n) => [-> // | /prime_decomp_correct[_ _]]; apply: path_sorted. Qed. Lemma all_prime_primes n : all prime (primes n). Proof. by apply/allP => p; rewrite mem_primes => /and3P[]. Qed. Lemma eq_primes m n : (primes m =i primes n) <-> (primes m = primes n). Proof. split=> [eqpr| -> //]. by apply: (irr_sorted_eq ltn_trans ltnn); rewrite ?sorted_primes. Qed. Lemma primes_uniq n : uniq (primes n). Proof. exact: (sorted_uniq ltn_trans ltnn (sorted_primes n)). Qed. (* The smallest prime divisor *) Lemma pi_pdiv n : (pdiv n \in \pi(n)) = (n > 1). Proof. case: n => [|[|n]] //; rewrite /pdiv !inE /primes. have:= prod_prime_decomp (ltn0Sn n.+1); rewrite unlock. by case: prime_decomp => //= pf pd _; rewrite mem_head. Qed. Lemma pdiv_prime n : 1 < n -> prime (pdiv n). Proof. by rewrite -pi_pdiv mem_primes; case/and3P. Qed. Lemma pdiv_dvd n : pdiv n %| n. Proof. by case: n (pi_pdiv n) => [|[|n]] //; rewrite mem_primes=> /and3P[]. Qed. Lemma pi_max_pdiv n : (max_pdiv n \in \pi(n)) = (n > 1). Proof. rewrite !inE -pi_pdiv /max_pdiv /pdiv !inE. by case: (primes n) => //= p ps; rewrite mem_head mem_last. Qed. Lemma max_pdiv_prime n : n > 1 -> prime (max_pdiv n). Proof. by rewrite -pi_max_pdiv mem_primes => /andP[]. Qed. Lemma max_pdiv_dvd n : max_pdiv n %| n. Proof. by case: n (pi_max_pdiv n) => [|[|n]] //; rewrite mem_primes => /andP[]. Qed. Lemma pdiv_leq n : 0 < n -> pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // pdiv_dvd. Qed. Lemma max_pdiv_leq n : 0 < n -> max_pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // max_pdiv_dvd. Qed. Lemma pdiv_gt0 n : 0 < pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?pdiv_prime. Qed. Lemma max_pdiv_gt0 n : 0 < max_pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?max_pdiv_prime. Qed. #[global] Hint Resolve pdiv_gt0 max_pdiv_gt0 : core. Lemma pdiv_min_dvd m d : 1 < d -> d %| m -> pdiv m <= d. Proof. case: (posnP m) => [->|mpos] lt1d dv_d_m; first exact: ltnW. rewrite /pdiv; apply: leq_trans (pdiv_leq (ltnW lt1d)). have: pdiv d \in primes m. by rewrite mem_primes mpos pdiv_prime // (dvdn_trans (pdiv_dvd d)). case: (primes m) (sorted_primes m) => //= p pm ord_pm; rewrite inE. by case/predU1P => [-> | /(allP (order_path_min ltn_trans ord_pm)) /ltnW]. Qed. Lemma max_pdiv_max n p : p \in \pi(n) -> p <= max_pdiv n. Proof. rewrite /max_pdiv !inE => n_p. case/splitPr: n_p (sorted_primes n) => p1 p2; rewrite last_cat -cat_rcons /=. rewrite headI /= cat_path -(last_cons 0) -headI last_rcons; case/andP=> _. move/(order_path_min ltn_trans); case/lastP: p2 => //= p2 q. by rewrite all_rcons last_rcons ltn_neqAle -andbA => /and3P[]. Qed. Lemma ltn_pdiv2_prime n : 0 < n -> n < pdiv n ^ 2 -> prime n. Proof. case def_n: n => [|[|n']] // _; rewrite -def_n => lt_n_p2. suffices ->: n = pdiv n by rewrite pdiv_prime ?def_n. apply/eqP; rewrite eqn_leq leqNgt andbC pdiv_leq; last by rewrite def_n. apply/contraL: lt_n_p2 => lt_pm_m; case/dvdnP: (pdiv_dvd n) => q def_q. rewrite -leqNgt [leqRHS]def_q leq_pmul2r // pdiv_min_dvd //. by rewrite -[pdiv n]mul1n [ltnRHS]def_q ltn_pmul2r in lt_pm_m. by rewrite def_q dvdn_mulr. Qed. Lemma primePns n : reflect (n < 2 \/ exists p, [/\ prime p, p ^ 2 <= n & p %| n]) (~~ prime n). Proof. apply: (iffP idP) => [npr_p|]; last first. case=> [|[p [pr_p le_p2_n dv_p_n]]]; first by case: n => [|[]]. apply/negP=> pr_n; move: dv_p_n le_p2_n; rewrite dvdn_prime2 //; move/eqP->. by rewrite leqNgt -[ltnLHS]muln1 ltn_pmul2l ?prime_gt1 ?prime_gt0. have [lt1p|] := leqP; [right | by left]. exists (pdiv n); rewrite pdiv_dvd pdiv_prime //; split=> //. by case: leqP npr_p => // /ltn_pdiv2_prime -> //; exact: ltnW. Qed. Arguments primePns {n}. Lemma pdivP n : n > 1 -> {p | prime p & p %| n}. Proof. by move=> lt1n; exists (pdiv n); rewrite ?pdiv_dvd ?pdiv_prime. Qed. Lemma primes_eq0 n : (primes n == [::]) = (n < 2). Proof. case: n => [|[|n']]//=; have [//|p pp pn] := @pdivP (n'.+2). suff: p \in primes n'.+2 by case: primes. by rewrite mem_primes pp pn. Qed. Lemma primesM m n p : m > 0 -> n > 0 -> (p \in primes (m * n)) = (p \in primes m) || (p \in primes n). Proof. move=> m_gt0 n_gt0; rewrite !mem_primes muln_gt0 m_gt0 n_gt0. by case pr_p: (prime p); rewrite // Euclid_dvdM. Qed. Lemma primesX m n : n > 0 -> primes (m ^ n) = primes m. Proof. case: n => // n _; rewrite expnS; have [-> // | m_gt0] := posnP m. apply/eq_primes => /= p; elim: n => [|n IHn]; first by rewrite muln1. by rewrite primesM ?(expn_gt0, expnS, IHn, orbb, m_gt0). Qed. Lemma primes_prime p : prime p -> primes p = [:: p]. Proof. move=> pr_p; apply: (irr_sorted_eq ltn_trans ltnn) => // [|q]. exact: sorted_primes. rewrite mem_seq1 mem_primes prime_gt0 //=. by apply/andP/idP=> [[pr_q q_p] | /eqP-> //]; rewrite -dvdn_prime2. Qed. Lemma coprime_has_primes m n : 0 < m -> 0 < n -> coprime m n = ~~ has [in primes m] (primes n). Proof. move=> m_gt0 n_gt0; apply/eqP/hasPn=> [mn1 p | no_p_mn]. rewrite /= !mem_primes m_gt0 n_gt0 /= => /andP[pr_p p_n]. have:= prime_gt1 pr_p; rewrite pr_p ltnNge -mn1 /=; apply: contra => p_m. by rewrite dvdn_leq ?gcdn_gt0 ?m_gt0 // dvdn_gcd ?p_m. apply/eqP; rewrite eqn_leq gcdn_gt0 m_gt0 andbT leqNgt; apply/negP. move/pdiv_prime; set p := pdiv _ => pr_p. move/implyP: (no_p_mn p); rewrite /= !mem_primes m_gt0 n_gt0 pr_p /=. by rewrite !(dvdn_trans (pdiv_dvd _)) // (dvdn_gcdl, dvdn_gcdr). Qed. Lemma pdiv_id p : prime p -> pdiv p = p. Proof. by move=> p_pr; rewrite /pdiv primes_prime. Qed. Lemma pdiv_pfactor p k : prime p -> pdiv (p ^ k.+1) = p. Proof. by move=> p_pr; rewrite /pdiv primesX ?primes_prime. Qed. (* Primes are unbounded. *) Lemma prime_above m : {p | m < p & prime p}. Proof. have /pdivP[p pr_p p_dv_m1]: 1 < m`! + 1 by rewrite addn1 ltnS fact_gt0. exists p => //; rewrite ltnNge; apply: contraL p_dv_m1 => p_le_m. by rewrite dvdn_addr ?dvdn_fact ?prime_gt0 // gtnNdvd ?prime_gt1. Qed. (* "prime" logarithms and p-parts. *) Fixpoint logn_rec d m r := match r, edivn m d with | r'.+1, (_.+1 as m', 0) => (logn_rec d m' r').+1 | _, _ => 0 end. Definition logn p m := if prime p then logn_rec p m m else 0. Lemma lognE p m : logn p m = if [&& prime p, 0 < m & p %| m] then (logn p (m %/ p)).+1 else 0. Proof. rewrite /logn /dvdn; case p_pr: (prime p) => //. case def_m: m => // [m']; rewrite !andTb [LHS]/= -def_m /divn modn_def. case: edivnP def_m => [[|q] [|r] -> _] // def_m; congr _.+1; rewrite [_.1]/=. have{m def_m}: q < m'. by rewrite -ltnS -def_m addn0 mulnC -{1}[q.+1]mul1n ltn_pmul2r // prime_gt1. elim/ltn_ind: m' {q}q.+1 (ltn0Sn q) => -[_ []|r IHr m] //= m_gt0 le_mr. rewrite -[m in logn_rec _ _ m]prednK //=. case: edivnP => [[|q] [|_] def_q _] //; rewrite addn0 in def_q. have{def_q} lt_qm1: q < m.-1. by rewrite -[q.+1]muln1 -ltnS prednK // def_q ltn_pmul2l // prime_gt1. have{le_mr} le_m1r: m.-1 <= r by rewrite -ltnS prednK. by rewrite (IHr r) ?(IHr m.-1) // (leq_trans lt_qm1). Qed. Lemma logn_gt0 p n : (0 < logn p n) = (p \in primes n). Proof. by rewrite lognE -mem_primes; case: {+}(p \in _). Qed. Lemma ltn_log0 p n : n < p -> logn p n = 0. Proof. by case: n => [|n] ltnp; rewrite lognE ?andbF // gtnNdvd ?andbF. Qed. Lemma logn0 p : logn p 0 = 0. Proof. by rewrite /logn if_same. Qed. Lemma logn1 p : logn p 1 = 0. Proof. by rewrite lognE dvdn1 /= andbC; case: eqP => // ->. Qed. Lemma pfactor_gt0 p n : 0 < p ^ logn p n. Proof. by rewrite expn_gt0 lognE; case: (posnP p) => // ->. Qed. #[global] Hint Resolve pfactor_gt0 : core. Lemma pfactor_dvdn p n m : prime p -> m > 0 -> (p ^ n %| m) = (n <= logn p m). Proof. move=> p_pr; elim: n m => [|n IHn] m m_gt0; first exact: dvd1n. rewrite lognE p_pr m_gt0 /=; case dv_pm: (p %| m); last first. apply/dvdnP=> [] [/= q def_m]. by rewrite def_m expnS mulnCA dvdn_mulr in dv_pm. case/dvdnP: dv_pm m_gt0 => q ->{m}; rewrite muln_gt0 => /andP[p_gt0 q_gt0]. by rewrite expnSr dvdn_pmul2r // mulnK // IHn. Qed. Lemma pfactor_dvdnn p n : p ^ logn p n %| n. Proof. case: n => // n; case pr_p: (prime p); first by rewrite pfactor_dvdn. by rewrite lognE pr_p dvd1n. Qed. Lemma logn_prime p q : prime q -> logn p q = (p == q). Proof. move=> pr_q; have q_gt0 := prime_gt0 pr_q; rewrite lognE q_gt0 /=. case pr_p: (prime p); last by case: eqP pr_p pr_q => // -> ->. by rewrite dvdn_prime2 //; case: eqP => // ->; rewrite divnn q_gt0 logn1. Qed. Lemma pfactor_coprime p n : prime p -> n > 0 -> {m | coprime p m & n = m * p ^ logn p n}. Proof. move=> p_pr n_gt0; set k := logn p n. have dv_pk_n: p ^ k %| n by rewrite pfactor_dvdn. exists (n %/ p ^ k); last by rewrite divnK. rewrite prime_coprime // -(@dvdn_pmul2r (p ^ k)) ?expn_gt0 ?prime_gt0 //. by rewrite -expnS divnK // pfactor_dvdn // ltnn. Qed. Lemma pfactorK p n : prime p -> logn p (p ^ n) = n. Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply/eqP; rewrite eqn_leq -pfactor_dvdn // dvdnn andbT. by rewrite -(leq_exp2l _ _ (prime_gt1 p_pr)) dvdn_leq // pfactor_dvdn. Qed. Lemma pfactorKpdiv p n : prime p -> logn (pdiv (p ^ n)) (p ^ n) = n. Proof. by case: n => // n p_pr; rewrite pdiv_pfactor ?pfactorK. Qed. Lemma dvdn_leq_log p m n : 0 < n -> m %| n -> logn p m <= logn p n. Proof. move=> n_gt0 dv_m_n; have m_gt0 := dvdn_gt0 n_gt0 dv_m_n. case p_pr: (prime p); last by do 2!rewrite lognE p_pr /=. by rewrite -pfactor_dvdn //; apply: dvdn_trans dv_m_n; rewrite pfactor_dvdn. Qed. Lemma ltn_logl p n : 0 < n -> logn p n < n. Proof. move=> n_gt0; have [p_gt1 | p_le1] := boolP (1 < p). by rewrite (leq_trans (ltn_expl _ p_gt1)) // dvdn_leq ?pfactor_dvdnn. by rewrite lognE (contraNF (@prime_gt1 _)). Qed. Lemma logn_Gauss p m n : coprime p m -> logn p (m * n) = logn p n. Proof. move=> co_pm; case p_pr: (prime p); last by rewrite /logn p_pr. have [-> | n_gt0] := posnP n; first by rewrite muln0. have [m0 | m_gt0] := posnP m; first by rewrite m0 prime_coprime ?dvdn0 in co_pm. have mn_gt0: m * n > 0 by rewrite muln_gt0 m_gt0. apply/eqP; rewrite eqn_leq andbC dvdn_leq_log ?dvdn_mull //. set k := logn p _; have: p ^ k %| m * n by rewrite pfactor_dvdn. by rewrite Gauss_dvdr ?coprimeXl // -pfactor_dvdn. Qed. Lemma logn_coprime p m : coprime p m -> logn p m = 0. Proof. by move=> coprime_pm; rewrite -[m]muln1 logn_Gauss// logn1. Qed. Lemma lognM p m n : 0 < m -> 0 < n -> logn p (m * n) = logn p m + logn p n. Proof. case p_pr: (prime p); last by rewrite /logn p_pr. have xlp := pfactor_coprime p_pr. case/xlp=> m' co_m' def_m /xlp[n' co_n' def_n] {xlp}. rewrite [in LHS]def_m [in LHS]def_n mulnCA -mulnA -expnD !logn_Gauss //. exact: pfactorK. Qed. Lemma lognX p m n : logn p (m ^ n) = n * logn p m. Proof. case p_pr: (prime p); last by rewrite /logn p_pr muln0. elim: n => [|n IHn]; first by rewrite logn1. have [->|m_gt0] := posnP m; first by rewrite exp0n // lognE andbF muln0. by rewrite expnS lognM ?IHn // expn_gt0 m_gt0. Qed. Lemma logn_div p m n : m %| n -> logn p (n %/ m) = logn p n - logn p m. Proof. rewrite dvdn_eq => /eqP def_n. case: (posnP n) => [-> |]; first by rewrite div0n logn0. by rewrite -{1 3}def_n muln_gt0 => /andP[q_gt0 m_gt0]; rewrite lognM ?addnK. Qed. Lemma dvdn_pfactor p d n : prime p -> reflect (exists2 m, m <= n & d = p ^ m) (d %| p ^ n). Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply: (iffP idP) => [dv_d_pn|[m le_m_n ->]]; last first. by rewrite -(subnK le_m_n) expnD dvdn_mull. exists (logn p d); first by rewrite -(pfactorK n p_pr) dvdn_leq_log. have d_gt0: d > 0 by apply: dvdn_gt0 dv_d_pn. case: (pfactor_coprime p_pr d_gt0) => q co_p_q def_d. rewrite [LHS]def_d ((q =P 1) _) ?mul1n // -dvdn1. suff: q %| p ^ n * 1 by rewrite Gauss_dvdr // coprime_sym coprimeXl. by rewrite muln1 (dvdn_trans _ dv_d_pn) // def_d dvdn_mulr. Qed. Lemma prime_decompE n : prime_decomp n = [seq (p, logn p n) | p <- primes n]. Proof. case: n => // n; pose f0 := (0, 0); rewrite -map_comp. apply: (@eq_from_nth _ f0) => [|i lt_i_n]; first by rewrite size_map. rewrite (nth_map f0) //; case def_f: (nth _ _ i) => [p e] /=. congr (_, _); rewrite [n.+1]prod_prime_decomp //. have: (p, e) \in prime_decomp n.+1 by rewrite -def_f mem_nth. case/mem_prime_decomp=> pr_p _ _. rewrite (big_nth f0) big_mkord (bigD1 (Ordinal lt_i_n)) //=. rewrite def_f mulnC logn_Gauss ?pfactorK //. apply big_ind => [|m1 m2 com1 com2| [j ltj] /=]; first exact: coprimen1. by rewrite coprimeMr com1. rewrite -val_eqE /= => nji; case def_j: (nth _ _ j) => [q e1] /=. have: (q, e1) \in prime_decomp n.+1 by rewrite -def_j mem_nth. case/mem_prime_decomp=> pr_q e1_gt0 _; rewrite coprime_pexpr //. rewrite prime_coprime // dvdn_prime2 //; apply: contra nji => eq_pq. rewrite -(nth_uniq 0 _ _ (primes_uniq n.+1)) ?size_map //=. by rewrite !(nth_map f0) // def_f def_j /= eq_sym. Qed. (* Some combinatorial formulae. *) Lemma divn_count_dvd d n : n %/ d = \sum_(1 <= i < n.+1) (d %| i). Proof. have [-> | d_gt0] := posnP d; first by rewrite big_add1 divn0 big1. apply: (@addnI (d %| 0)); rewrite -(@big_ltn _ 0 _ 0 _ (dvdn d)) // big_mkord. rewrite (partition_big (fun i : 'I_n.+1 => inord (i %/ d)) 'I_(n %/ d).+1) //=. rewrite dvdn0 add1n -[_.+1 in LHS]card_ord -sum1_card. apply: eq_bigr => [[q ?] _]. rewrite (bigD1 (inord (q * d))) /eq_op /= !inordK ?ltnS -?leq_divRL ?mulnK //. rewrite dvdn_mull ?big1 // => [[i /= ?] /andP[/eqP <- /negPf]]. by rewrite eq_sym dvdn_eq inordK ?ltnS ?leq_div2r // => ->. Qed. Lemma logn_count_dvd p n : prime p -> logn p n = \sum_(1 <= k < n) (p ^ k %| n). Proof. rewrite big_add1 => p_prime; case: n => [|n]; first by rewrite logn0 big_geq. rewrite big_mkord -big_mkcond (eq_bigl _ _ (fun _ => pfactor_dvdn _ _ _)) //=. by rewrite big_ord_narrow ?sum1_card ?card_ord // -ltnS ltn_logl. Qed. (* Truncated real log. *) Definition trunc_log p n := let fix loop n k := if k is k'.+1 then if p <= n then (loop (n %/ p) k').+1 else 0 else 0 in if p <= 1 then 0 else loop n n. Lemma trunc_log0 p : trunc_log p 0 = 0. Proof. by case: p => [] // []. Qed. Lemma trunc_log1 p : trunc_log p 1 = 0. Proof. by case: p => [|[]]. Qed. Lemma trunc_log_bounds p n : 1 < p -> 0 < n -> let k := trunc_log p n in p ^ k <= n < p ^ k.+1. Proof. rewrite {+}/trunc_log => p_gt1; have p_gt0 := ltnW p_gt1. rewrite [p <= 1]leqNgt p_gt1 /=. set loop := (loop in loop n n); set m := n; rewrite [in n in loop m n]/m. have: m <= n by []; elim: n m => [|n IHn] [|m] //= /ltnSE-le_m_n _. have [le_p_n | // ] := leqP p _; rewrite 2!expnSr -leq_divRL -?ltn_divLR //. by apply: IHn; rewrite ?divn_gt0 // -ltnS (leq_trans (ltn_Pdiv _ _)). Qed. Lemma trunc_logP p n : 1 < p -> 0 < n -> p ^ trunc_log p n <= n. Proof. by move=> p_gt1 /(trunc_log_bounds p_gt1)/andP[]. Qed. Lemma trunc_log_ltn p n : 1 < p -> n < p ^ (trunc_log p n).+1. Proof. have [-> | n_gt0] := posnP n; first by rewrite trunc_log0 => /ltnW. by case/trunc_log_bounds/(_ n_gt0)/andP. Qed. Lemma trunc_log_max p k j : 1 < p -> p ^ j <= k -> j <= trunc_log p k. Proof. move=> p_gt1 le_pj_k; rewrite -ltnS -(@ltn_exp2l p) //. exact: leq_ltn_trans (trunc_log_ltn _ _). Qed. Lemma trunc_log_eq0 p n : (trunc_log p n == 0) = (p <= 1) || (n <= p.-1). Proof. case: p => [|[|p]]; case: n => // n; rewrite /= ltnS. have /= /andP[] := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+1). case: trunc_log => [//|k] b1 b2. apply/idP/idP => [/eqP sk0 | nlep]; first by move: b2; rewrite sk0. symmetry; rewrite -[_ == _]/false /is_true -b1; apply/negbTE; rewrite -ltnNge. move: nlep; rewrite -ltnS => nlep; apply: (leq_ltn_trans nlep). by rewrite -[leqLHS]expn1; apply: leq_pexp2l. Qed. Lemma trunc_log_gt0 p n : (0 < trunc_log p n) = (1 < p) && (p.-1 < n). Proof. by rewrite ltnNge leqn0 trunc_log_eq0 negb_or -!ltnNge. Qed. Lemma trunc_log0n n : trunc_log 0 n = 0. Proof. by []. Qed. Lemma trunc_log1n n : trunc_log 1 n = 0. Proof. by []. Qed. Lemma leq_trunc_log p m n : m <= n -> trunc_log p m <= trunc_log p n. Proof. move=> mlen; case: p => [|[|p]]; rewrite ?trunc_log0n ?trunc_log1n //. case: m mlen => [|m] mlen; first by rewrite trunc_log0. apply/trunc_log_max => //; apply: leq_trans mlen; exact: trunc_logP. Qed. Lemma trunc_log_eq p n k : 1 < p -> p ^ n <= k < p ^ n.+1 -> trunc_log p k = n. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/anti_leq. rewrite trunc_log_max// andbT -ltnS -(ltn_exp2l _ _ p_gt1). apply: leq_ltn_trans kLpn; apply: trunc_logP => //. by apply: leq_trans npLk; rewrite expn_gt0 ltnW. Qed. Lemma trunc_lognn p : 1 < p -> trunc_log p p = 1. Proof. by case: p => [|[|p]] // _; rewrite /trunc_log ltnSn divnn. Qed. Lemma trunc_expnK p n : 1 < p -> trunc_log p (p ^ n) = n. Proof. by move=> ?; apply: trunc_log_eq; rewrite // leqnn ltn_exp2l /=. Qed. Lemma trunc_logMp p n : 1 < p -> 0 < n -> trunc_log p (p * n) = (trunc_log p n).+1. Proof. case: p => [//|p] => p_gt0 n_gt0; apply: trunc_log_eq => //. rewrite expnS leq_pmul2l// trunc_logP//=. by rewrite expnS ltn_pmul2l// trunc_log_ltn. Qed. Lemma trunc_log2_double n : 0 < n -> trunc_log 2 n.*2 = (trunc_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n trunc_logMp. Qed. Lemma trunc_log2S n : 1 < n -> trunc_log 2 n = (trunc_log 2 n./2).+1. Proof. move=> n_gt1. rewrite -trunc_log2_double ?half_gt0//. rewrite -[n in LHS]odd_double_half. case: odd => //; rewrite add1n. apply: trunc_log_eq => //. rewrite leqW ?trunc_logP //= ?double_gt0 ?half_gt0//. rewrite trunc_log2_double ?half_gt0// expnS. by rewrite -doubleS mul2n leq_double trunc_log_ltn. Qed. (* Truncated up real logarithm *) Definition up_log p n := if (p <= 1) then 0 else let v := trunc_log p n in if n <= p ^ v then v else v.+1. Lemma up_log0 p : up_log p 0 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log1 p : up_log p 1 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log_eq0 p n : (up_log p n == 0) = (p <= 1) || (n <= 1). Proof. case: p => // [] [] // p. case: n => [|[|n]]; rewrite /up_log //=. have /= := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+2). by case: (leqP _ n.+1); case: trunc_log. Qed. Lemma up_log_gt0 p n : (0 < up_log p n) = (1 < p) && (1 < n). Proof. by rewrite ltnNge leqn0 up_log_eq0 negb_or -!ltnNge. Qed. Lemma up_log_bounds p n : 1 < p -> 1 < n -> let k := up_log p n in p ^ k.-1 < n <= p ^ k. Proof. move=> p_gt1 n_gt1. have n_gt0 : 0 < n by apply: leq_trans n_gt1. rewrite /up_log (leqNgt p 1) p_gt1 /=. have /= /andP[tpLn nLtpS] := trunc_log_bounds p_gt1 n_gt0. have [nLnp|npLn] := leqP n (p ^ trunc_log p n); last by rewrite npLn ltnW. rewrite nLnp (leq_trans _ tpLn) // ltn_exp2l // prednK ?leqnn //. by case: trunc_log (leq_trans n_gt1 nLnp). Qed. Lemma up_logP p n : 1 < p -> n <= p ^ up_log p n. Proof. case: n => [|[|n]] // p_gt1; first by rewrite up_log1. by have /andP[] := up_log_bounds p_gt1 (isT: 1 < n.+2). Qed. Lemma up_log_gtn p n : 1 < p -> 1 < n -> p ^ (up_log p n).-1 < n. Proof. by case: n => [|[|n]] p_gt1 n_gt1 //; have /andP[] := up_log_bounds p_gt1 n_gt1. Qed. Lemma up_log_min p k j : 1 < p -> k <= p ^ j -> up_log p k <= j. Proof. case: k => [|[|k]] // p_gt1 kLj; rewrite ?(up_log0, up_log1) //. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt1 // -(@ltn_exp2l p) //. by apply: leq_trans (up_log_gtn p_gt1 (isT : 1 < k.+2)) _. Qed. Lemma leq_up_log p m n : m <= n -> up_log p m <= up_log p n. Proof. move=> mLn; case: p => [|[|p]] //. by apply/up_log_min => //; apply: leq_trans mLn (up_logP _ _). Qed. Lemma up_log_eq p n k : 1 < p -> p ^ n < k <= p ^ n.+1 -> up_log p k = n.+1. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/eqP; rewrite eqn_leq. apply/andP; split; first by apply: up_log_min. rewrite -(ltn_exp2l _ _ p_gt1) //. by apply: leq_trans npLk (up_logP _ _). Qed. Lemma up_lognn p : 1 < p -> up_log p p = 1. Proof. by move=> p_gt1; apply: up_log_eq; rewrite p_gt1 /=. Qed. Lemma up_expnK p n : 1 < p -> up_log p (p ^ n) = n. Proof. case: n => [|n] p_gt1 /=; first by rewrite up_log1. by apply: up_log_eq; rewrite // leqnn andbT ltn_exp2l. Qed. Lemma up_logMp p n : 1 < p -> 0 < n -> up_log p (p * n) = (up_log p n).+1. Proof. case: p => [//|p] p_gt0. case: n => [//|[|n]] _; first by rewrite muln1 up_lognn// up_log1. apply: up_log_eq => //. rewrite expnS leq_pmul2l// up_logP// andbT. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt0 //. by rewrite expnS ltn_pmul2l// up_log_gtn. Qed. Lemma up_log2_double n : 0 < n -> up_log 2 n.*2 = (up_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n up_logMp. Qed. Lemma up_log2S n : 0 < n -> up_log 2 n.+1 = (up_log 2 (n./2.+1)).+1. Proof. case: n=> // [] [|n] // _. apply: up_log_eq => //; apply/andP; split. apply: leq_trans (_ : n./2.+1.*2 < n.+3); last first. by rewrite doubleS !ltnS -[leqRHS]odd_double_half leq_addl. have /= /andP[H1n _] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). by rewrite ltnS -leq_double -mul2n -expnS prednK ?up_log_gt0 // in H1n. rewrite -[_./2.+1]/(n./2.+2). have /= /andP[_ H2n] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). rewrite -leq_double -!mul2n -expnS in H2n. apply: leq_trans H2n. rewrite mul2n !doubleS !ltnS. by rewrite -[leqLHS]odd_double_half -add1n leq_add2r; case: odd. Qed. Lemma up_log_trunc_log p n : 1 < p -> 1 < n -> up_log p n = (trunc_log p n.-1).+1. Proof. move=> p_gt1 n_gt1; apply: up_log_eq => //. rewrite -[n]prednK ?ltnS -?pred_Sn ?[0 < n]ltnW//. by rewrite trunc_logP ?ltn_predRL// trunc_log_ltn. Qed. Lemma trunc_log_up_log p n : 1 < p -> 0 < n -> trunc_log p n = (up_log p n.+1).-1. Proof. by move=> ? ?; rewrite up_log_trunc_log. Qed. (* pi- parts *) (* Testing for membership in set of prime factors. *) Canonical nat_pred_pred := Eval hnf in [predType of nat_pred]. Coercion nat_pred_of_nat (p : nat) : nat_pred := pred1 p. Section NatPreds. Variables (n : nat) (pi : nat_pred). Definition negn : nat_pred := [predC pi]. Definition pnat : pred nat := fun m => (m > 0) && all [in pi] (primes m). Definition partn := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. End NatPreds. Notation "pi ^'" := (negn pi) : nat_scope. Notation "pi .-nat" := (pnat pi) : nat_scope. Notation "n `_ pi" := (partn n pi) : nat_scope. Section PnatTheory. Implicit Types (n p : nat) (pi rho : nat_pred). Lemma negnK pi : pi^'^' =i pi. Proof. by move=> p; apply: negbK. Qed. Lemma eq_negn pi1 pi2 : pi1 =i pi2 -> pi1^' =i pi2^'. Proof. by move=> eq_pi n; rewrite inE eq_pi. Qed. Lemma eq_piP m n : \pi(m) =i \pi(n) <-> \pi(m) = \pi(n). Proof. rewrite /pi_of; have eqs := irr_sorted_eq ltn_trans ltnn. by split=> [|-> //] /(eqs _ _ (sorted_primes m) (sorted_primes n)) ->. Qed. Lemma part_gt0 pi n : 0 < n`_pi. Proof. exact: prodn_gt0. Qed. Hint Resolve part_gt0 : core. Lemma sub_in_partn pi1 pi2 n : {in \pi(n), {subset pi1 <= pi2}} -> n`_pi1 %| n`_pi2. Proof. move=> pi12; rewrite ![n`__]big_mkcond /=. apply (big_ind2 (fun m1 m2 => m1 %| m2)) => // [*|p _]; first exact: dvdn_mul. rewrite lognE -mem_primes; case: ifP => pi1p; last exact: dvd1n. by case: ifP => pr_p; [rewrite pi12 | rewrite if_same]. Qed. Lemma eq_in_partn pi1 pi2 n : {in \pi(n), pi1 =i pi2} -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply/eqP; rewrite eqn_dvd ?sub_in_partn // => p /pi12->. Qed. Lemma eq_partn pi1 pi2 n : pi1 =i pi2 -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply: eq_in_partn => p _. Qed. Lemma partnNK pi n : n`_pi^'^' = n`_pi. Proof. by apply: eq_partn; apply: negnK. Qed. Lemma widen_partn m pi n : n <= m -> n`_pi = \prod_(0 <= p < m.+1 | p \in pi) p ^ logn p n. Proof. move=> le_n_m; rewrite big_mkcond /=. rewrite [n`_pi](big_nat_widen _ _ m.+1) // big_mkcond /=. apply: eq_bigr => p _; rewrite ltnS lognE. by case: and3P => [[_ n_gt0 p_dv_n]|]; rewrite ?if_same // andbC dvdn_leq. Qed. Lemma eq_partn_from_log m n (pi : nat_pred) : 0 < m -> 0 < n -> {in pi, logn^~ m =1 logn^~ n} -> m`_pi = n`_pi. Proof. move=> m0 n0 eq_log; rewrite !(@widen_partn (maxn m n)) ?leq_maxl ?leq_maxr//. by apply: eq_bigr => p /eq_log ->. Qed. Lemma partn0 pi : 0`_pi = 1. Proof. by apply: big1_seq => [] [|n]; rewrite andbC. Qed. Lemma partn1 pi : 1`_pi = 1. Proof. by apply: big1_seq => [] [|[|n]]; rewrite andbC. Qed. Lemma partnM pi m n : m > 0 -> n > 0 -> (m * n)`_pi = m`_pi * n`_pi. Proof. have le_pmul m' n': m' > 0 -> n' <= m' * n' by move/prednK <-; apply: leq_addr. move=> mpos npos; rewrite !(@widen_partn (n * m)) 3?(le_pmul, mulnC) //. rewrite !big_mkord -big_split; apply: eq_bigr => p _ /=. by rewrite lognM // expnD. Qed. Lemma partnX pi m n : (m ^ n)`_pi = m`_pi ^ n. Proof. elim: n => [|n IHn]; first exact: partn1. rewrite expnS; have [->|m_gt0] := posnP m; first by rewrite partn0 exp1n. by rewrite expnS partnM ?IHn // expn_gt0 m_gt0. Qed. Lemma partn_dvd pi m n : n > 0 -> m %| n -> m`_pi %| n`_pi. Proof. move=> n_gt0 dvmn; case/dvdnP: dvmn n_gt0 => q ->{n}. by rewrite muln_gt0 => /andP[q_gt0 m_gt0]; rewrite partnM ?dvdn_mull. Qed. Lemma p_part p n : n`_p = p ^ logn p n. Proof. case (posnP (logn p n)) => [log0 |]. by rewrite log0 [n`_p]big1_seq // => q /andP [/eqP ->]; rewrite log0. rewrite logn_gt0 mem_primes; case/and3P=> _ n_gt0 dv_p_n. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. by rewrite [n`_p]big_mkord (big_pred1 (Ordinal le_p_n)). Qed. Lemma p_part_eq1 p n : (n`_p == 1) = (p \notin \pi(n)). Proof. rewrite mem_primes p_part lognE; case: and3P => // [[p_pr _ _]]. by rewrite -dvdn1 pfactor_dvdn // logn1. Qed. Lemma p_part_gt1 p n : (n`_p > 1) = (p \in \pi(n)). Proof. by rewrite ltn_neqAle part_gt0 andbT eq_sym p_part_eq1 negbK. Qed. Lemma primes_part pi n : primes n`_pi = filter [in pi] (primes n). Proof. have ltnT := ltn_trans; have [->|n_gt0] := posnP n; first by rewrite partn0. apply: (irr_sorted_eq ltnT ltnn); rewrite ?(sorted_primes, sorted_filter) //. move=> p; rewrite mem_filter /= !mem_primes n_gt0 part_gt0 /=. apply/andP/and3P=> [[p_pr] | [pi_p p_pr dv_p_n]]. rewrite /partn; apply big_ind => [|n1 n2 IHn1 IHn2|q pi_q]. - by rewrite dvdn1; case: eqP p_pr => // ->. - by rewrite Euclid_dvdM //; case/orP. rewrite -{1}(expn1 p) pfactor_dvdn // lognX muln_gt0. rewrite logn_gt0 mem_primes n_gt0 - andbA /=; case/and3P=> pr_q dv_q_n. by rewrite logn_prime //; case: eqP => // ->. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. rewrite [n`_pi]big_mkord (bigD1 (Ordinal le_p_n)) //= dvdn_mulr //. by rewrite lognE p_pr n_gt0 dv_p_n expnS dvdn_mulr. Qed. Lemma filter_pi_of n m : n < m -> filter \pi(n) (index_iota 0 m) = primes n. Proof. move=> lt_n_m; have ltnT := ltn_trans; apply: (irr_sorted_eq ltnT ltnn). - by rewrite sorted_filter // iota_ltn_sorted. - exact: sorted_primes. move=> p; rewrite mem_filter mem_index_iota /= mem_primes; case: and3P => //. by case=> _ n_gt0 dv_p_n; apply: leq_ltn_trans lt_n_m; apply: dvdn_leq. Qed. Lemma partn_pi n : n > 0 -> n`_\pi(n) = n. Proof. move=> n_gt0; rewrite [RHS]prod_prime_decomp // prime_decompE big_map. by rewrite -[n`__]big_filter filter_pi_of. Qed. Lemma partnT n : n > 0 -> n`_predT = n. Proof. move=> n_gt0; rewrite -[RHS]partn_pi // [RHS]/partn big_mkcond /=. by apply: eq_bigr => p _; rewrite -logn_gt0; case: (logn p _). Qed. Lemma eqn_from_log m n : 0 < m -> 0 < n -> logn^~ m =1 logn^~ n -> m = n. Proof. by move=> ? ? /(@in1W _ predT)/eq_partn_from_log; rewrite !partnT// => ->. Qed. Lemma partnC pi n : n > 0 -> n`_pi * n`_pi^' = n. Proof. move=> n_gt0; rewrite -[RHS]partnT /partn //. do 2!rewrite mulnC big_mkcond /=; rewrite -big_split; apply: eq_bigr => p _ /=. by rewrite mulnC inE /=; case: (p \in pi); rewrite /= (muln1, mul1n). Qed. Lemma dvdn_part pi n : n`_pi %| n. Proof. by case: n => // n; rewrite -{2}[n.+1](@partnC pi) // dvdn_mulr. Qed. Lemma logn_part p m : logn p m`_p = logn p m. Proof. case p_pr: (prime p); first by rewrite p_part pfactorK. by rewrite lognE (lognE p m) p_pr. Qed. Lemma partn_lcm pi m n : m > 0 -> n > 0 -> (lcmn m n)`_pi = lcmn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: lcmn m n > 0 by rewrite lcmn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_lcm !partn_dvd ?dvdn_lcml ?dvdn_lcmr //. rewrite -(dvdn_pmul2r (part_gt0 pi^' (lcmn m n))) partnC // dvdn_lcm !andbT. rewrite -[m in m %| _](partnC pi m_gt0) andbC -[n in n %| _](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_lcml ?dvdn_lcmr. Qed. Lemma partn_gcd pi m n : m > 0 -> n > 0 -> (gcdn m n)`_pi = gcdn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: gcdn m n > 0 by rewrite gcdn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_gcd !partn_dvd ?dvdn_gcdl ?dvdn_gcdr //=. rewrite -(dvdn_pmul2r (part_gt0 pi^' (gcdn m n))) partnC // dvdn_gcd. rewrite -[m in _ %| m](partnC pi m_gt0) andbC -[n in _%| n](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_gcdl ?dvdn_gcdr. Qed. Lemma partn_biglcm (I : finType) (P : pred I) F pi : (forall i, P i -> F i > 0) -> (\big[lcmn/1%N]_(i | P i) F i)`_pi = \big[lcmn/1%N]_(i | P i) (F i)`_pi. Proof. move=> F_gt0; set m := \big[lcmn/1%N]_(i | P i) F i. have m_gt0: 0 < m by elim/big_ind: m => // p q p_gt0; rewrite lcmn_gt0 p_gt0. apply/eqP; rewrite eqn_dvd andbC; apply/andP; split. by apply/dvdn_biglcmP=> i Pi; rewrite partn_dvd // (@biglcmn_sup _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' m)) partnC //. apply/dvdn_biglcmP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biglcmn_sup _ i). by rewrite partn_dvd // (@biglcmn_sup _ i). Qed. Lemma partn_biggcd (I : finType) (P : pred I) F pi : #|SimplPred P| > 0 -> (forall i, P i -> F i > 0) -> (\big[gcdn/0]_(i | P i) F i)`_pi = \big[gcdn/0]_(i | P i) (F i)`_pi. Proof. move=> ntP F_gt0; set d := \big[gcdn/0]_(i | P i) F i. have d_gt0: 0 < d. case/card_gt0P: ntP => i /= Pi; have:= F_gt0 i Pi. rewrite !lt0n -!dvd0n; apply: contra => dv0d. by rewrite (dvdn_trans dv0d) // (@biggcdn_inf _ i). apply/eqP; rewrite eqn_dvd; apply/andP; split. by apply/dvdn_biggcdP=> i Pi; rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' d)) partnC //. apply/dvdn_biggcdP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biggcdn_inf _ i). by rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). Qed. Lemma logn_gcd p m n : 0 < m -> 0 < n -> logn p (gcdn m n) = minn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; case p_pr: (prime p); last by rewrite /logn p_pr. by apply: (@expnI p); rewrite ?prime_gt1// expn_min -!p_part partn_gcd. Qed. Lemma logn_lcm p m n : 0 < m -> 0 < n -> logn p (lcmn m n) = maxn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; rewrite /lcmn logn_div ?dvdn_mull ?dvdn_gcdr//. by rewrite lognM// logn_gcd// -addn_min_max addnC addnK. Qed. Lemma sub_in_pnat pi rho n : {in \pi(n), {subset pi <= rho}} -> pi.-nat n -> rho.-nat n. Proof. rewrite /pnat => subpi /andP[-> pi_n]. by apply/allP=> p pr_p; apply: subpi => //; apply: (allP pi_n). Qed. Lemma eq_in_pnat pi rho n : {in \pi(n), pi =i rho} -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply/idP/idP; apply: sub_in_pnat => p /eqpi->. Qed. Lemma eq_pnat pi rho n : pi =i rho -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply: eq_in_pnat => p _. Qed. Lemma pnatNK pi n : pi^'^'.-nat n = pi.-nat n. Proof. exact: eq_pnat (negnK pi). Qed. Lemma pnatI pi rho n : [predI pi & rho].-nat n = pi.-nat n && rho.-nat n. Proof. by rewrite /pnat andbCA all_predI !andbA andbb. Qed. Lemma pnatM pi m n : pi.-nat (m * n) = pi.-nat m && pi.-nat n. Proof. rewrite /pnat muln_gt0 andbCA -andbA andbCA. case: posnP => // n_gt0; case: posnP => //= m_gt0. apply/allP/andP=> [pi_mn | [pi_m pi_n] p]. by split; apply/allP=> p m_p; apply: pi_mn; rewrite primesM // m_p ?orbT. by rewrite primesM // => /orP[]; [apply: (allP pi_m) | apply: (allP pi_n)]. Qed. Lemma pnatX pi m n : pi.-nat (m ^ n) = pi.-nat m || (n == 0). Proof. by case: n => [|n]; rewrite orbC // /pnat expn_gt0 orbC primesX. Qed. Lemma part_pnat pi n : pi.-nat n`_pi. Proof. rewrite /pnat primes_part part_gt0. by apply/allP=> p; rewrite mem_filter => /andP[]. Qed. Lemma pnatE pi p : prime p -> pi.-nat p = (p \in pi). Proof. by move=> pr_p; rewrite /pnat prime_gt0 ?primes_prime //= andbT. Qed. Lemma pnat_id p : prime p -> p.-nat p. Proof. by move=> pr_p; rewrite pnatE ?inE /=. Qed. Lemma coprime_pi' m n : m > 0 -> n > 0 -> coprime m n = \pi(m)^'.-nat n. Proof. by move=> m_gt0 n_gt0; rewrite /pnat n_gt0 all_predC coprime_has_primes. Qed. Lemma pnat_pi n : n > 0 -> \pi(n).-nat n. Proof. by rewrite /pnat => ->; apply/allP. Qed. Lemma pi_of_dvd m n : m %| n -> n > 0 -> {subset \pi(m) <= \pi(n)}. Proof. move=> m_dv_n n_gt0 p; rewrite !mem_primes n_gt0 => /and3P[-> _ p_dv_m]. exact: dvdn_trans p_dv_m m_dv_n. Qed. Lemma pi_ofM m n : m > 0 -> n > 0 -> \pi(m * n) =i [predU \pi(m) & \pi(n)]. Proof. by move=> m_gt0 n_gt0 p; apply: primesM. Qed. Lemma pi_of_part pi n : n > 0 -> \pi(n`_pi) =i [predI \pi(n) & pi]. Proof. by move=> n_gt0 p; rewrite /pi_of primes_part mem_filter andbC. Qed. Lemma pi_of_exp p n : n > 0 -> \pi(p ^ n) = \pi(p). Proof. by move=> n_gt0; rewrite /pi_of primesX. Qed. Lemma pi_of_prime p : prime p -> \pi(p) =i (p : nat_pred). Proof. by move=> pr_p q; rewrite /pi_of primes_prime // mem_seq1. Qed. Lemma p'natEpi p n : n > 0 -> p^'.-nat n = (p \notin \pi(n)). Proof. by case: n => // n _; rewrite /pnat all_predC has_pred1. Qed. Lemma p'natE p n : prime p -> p^'.-nat n = ~~ (p %| n). Proof. case: n => [|n] p_pr; first by case: p p_pr. by rewrite p'natEpi // mem_primes p_pr. Qed. Lemma pnatPpi pi n p : pi.-nat n -> p \in \pi(n) -> p \in pi. Proof. by case/andP=> _ /allP; apply. Qed. Lemma pnat_dvd m n pi : m %| n -> pi.-nat n -> pi.-nat m. Proof. by case/dvdnP=> q ->; rewrite pnatM; case/andP. Qed. Lemma pnat_div m n pi : m %| n -> pi.-nat n -> pi.-nat (n %/ m). Proof. case/dvdnP=> q ->; rewrite pnatM andbC => /andP[]. by case: m => // m _; rewrite mulnK. Qed. Lemma pnat_coprime pi m n : pi.-nat m -> pi^'.-nat n -> coprime m n. Proof. case/andP=> m_gt0 pi_m /andP[n_gt0 pi'_n]; rewrite coprime_has_primes //. by apply/hasPn=> p /(allP pi'_n); apply/contra/allP. Qed. Lemma p'nat_coprime pi m n : pi^'.-nat m -> pi.-nat n -> coprime m n. Proof. by move=> pi'm pi_n; rewrite (pnat_coprime pi'm) ?pnatNK. Qed. Lemma sub_pnat_coprime pi rho m n : {subset rho <= pi^'} -> pi.-nat m -> rho.-nat n -> coprime m n. Proof. by move=> pi'rho pi_m /(sub_in_pnat (in1W pi'rho)); apply: pnat_coprime. Qed. Lemma coprime_partC pi m n : coprime m`_pi n`_pi^'. Proof. by apply: (@pnat_coprime pi); apply: part_pnat. Qed. Lemma pnat_1 pi n : pi.-nat n -> pi^'.-nat n -> n = 1. Proof. by move=> pi_n pi'_n; rewrite -(eqnP (pnat_coprime pi_n pi'_n)) gcdnn. Qed. Lemma part_pnat_id pi n : pi.-nat n -> n`_pi = n. Proof. case/andP=> n_gt0 pi_n; rewrite -[RHS]partnT // /partn big_mkcond /=. apply: eq_bigr=> p _; have [->|] := posnP (logn p n); first by rewrite if_same. by rewrite logn_gt0 => /(allP pi_n)/= ->. Qed. Lemma part_p'nat pi n : pi^'.-nat n -> n`_pi = 1. Proof. case/andP=> n_gt0 pi'_n; apply: big1_seq => p /andP[pi_p _]. by have [-> //|] := posnP (logn p n); rewrite logn_gt0; case/(allP pi'_n)/negP. Qed. Lemma partn_eq1 pi n : n > 0 -> (n`_pi == 1) = pi^'.-nat n. Proof. move=> n_gt0; apply/eqP/idP=> [pi_n_1|]; last exact: part_p'nat. by rewrite -(partnC pi n_gt0) pi_n_1 mul1n part_pnat. Qed. Lemma pnatP pi n : n > 0 -> reflect (forall p, prime p -> p %| n -> p \in pi) (pi.-nat n). Proof. move=> n_gt0; rewrite /pnat n_gt0. apply: (iffP allP) => /= pi_n p => [pr_p p_n|]. by rewrite pi_n // mem_primes pr_p n_gt0. by rewrite mem_primes n_gt0 /=; case/andP; move: p. Qed. Lemma pi_pnat pi p n : p.-nat n -> p \in pi -> pi.-nat n. Proof. move=> p_n pi_p; have [n_gt0 _] := andP p_n. by apply/pnatP=> // q q_pr /(pnatP _ n_gt0 p_n _ q_pr)/eqnP->. Qed. Lemma p_natP p n : p.-nat n -> {k | n = p ^ k}. Proof. by move=> p_n; exists (logn p n); rewrite -p_part part_pnat_id. Qed. Lemma pi'_p'nat pi p n : pi^'.-nat n -> p \in pi -> p^'.-nat n. Proof. by move=> pi'n pi_p; apply: sub_in_pnat pi'n => q _; apply: contraNneq => ->. Qed. Lemma pi_p'nat p pi n : pi.-nat n -> p \in pi^' -> p^'.-nat n. Proof. by move=> pi_n; apply: pi'_p'nat; rewrite pnatNK. Qed. Lemma partn_part pi rho n : {subset pi <= rho} -> n`_rho`_pi = n`_pi. Proof. move=> pi_sub_rho; have [->|n_gt0] := posnP n; first by rewrite !partn0 partn1. rewrite -[in RHS](partnC rho n_gt0) partnM //. suffices: pi^'.-nat n`_rho^' by move/part_p'nat->; rewrite muln1. by apply: sub_in_pnat (part_pnat _ _) => q _; apply/contra/pi_sub_rho. Qed. Lemma partnI pi rho n : n`_[predI pi & rho] = n`_pi`_rho. Proof. rewrite -(@partnC [predI pi & rho] _`_rho) //. symmetry; rewrite 2?partn_part; try by move=> p /andP []. rewrite mulnC part_p'nat ?mul1n // pnatNK pnatI part_pnat andbT. exact: pnat_dvd (dvdn_part _ _) (part_pnat _ _). Qed. Lemma odd_2'nat n : odd n = 2^'.-nat n. Proof. by case: n => // n; rewrite p'natE // dvdn2 negbK. Qed. End PnatTheory. #[global] Hint Resolve part_gt0 : core. (************************************) (* Properties of the divisors list. *) (************************************) Lemma divisors_correct n : n > 0 -> [/\ uniq (divisors n), sorted leq (divisors n) & forall d, (d \in divisors n) = (d %| n)]. Proof. move/prod_prime_decomp=> def_n; rewrite {4}def_n {def_n}. have: all prime (primes n) by apply/allP=> p; rewrite mem_primes; case/andP. have:= primes_uniq n; rewrite /primes /divisors; move/prime_decomp: n. elim=> [|[p e] pd] /=; first by split=> // d; rewrite big_nil dvdn1 mem_seq1. rewrite big_cons /=; move: (foldr _ _ pd) => divs. move=> IHpd /andP[npd_p Upd] /andP[pr_p pr_pd]. have lt0p: 0 < p by apply: prime_gt0. have {IHpd Upd}[Udivs Odivs mem_divs] := IHpd Upd pr_pd. have ndivs_p m: p * m \notin divs. suffices: p \notin divs; rewrite !mem_divs. by apply: contra => /dvdnP[n ->]; rewrite mulnCA dvdn_mulr. have ndv_p_1: ~~(p %| 1) by rewrite dvdn1 neq_ltn orbC prime_gt1. rewrite big_seq; elim/big_ind: _ => [//|u v npu npv|[q f] /= pd_qf]. by rewrite Euclid_dvdM //; apply/norP. elim: (f) => // f'; rewrite expnS Euclid_dvdM // orbC negb_or => -> {f'}/=. have pd_q: q \in unzip1 pd by apply/mapP; exists (q, f). by apply: contra npd_p; rewrite dvdn_prime2 // ?(allP pr_pd) // => /eqP->. elim: e => [|e] /=; first by split=> // d; rewrite mul1n. have Tmulp_inj: injective (NatTrec.mul p). by move=> u v /eqP; rewrite !natTrecE eqn_pmul2l // => /eqP. move: (iter e _ _) => divs' [Udivs' Odivs' mem_divs']; split=> [||d]. - rewrite merge_uniq cat_uniq map_inj_uniq // Udivs Udivs' andbT /=. apply/hasP=> [[d dv_d /mapP[d' _ def_d]]]. by case/idPn: dv_d; rewrite def_d natTrecE. - rewrite (merge_sorted leq_total) //; case: (divs') Odivs' => //= d ds. rewrite (@map_path _ _ _ _ leq xpred0) ?has_pred0 // => u v _. by rewrite !natTrecE leq_pmul2l. rewrite mem_merge mem_cat; case dv_d_p: (p %| d). case/dvdnP: dv_d_p => d' ->{d}; rewrite mulnC (negbTE (ndivs_p d')) orbF. rewrite expnS -mulnA dvdn_pmul2l // -mem_divs'. by rewrite -(mem_map Tmulp_inj divs') natTrecE. case pdiv_d: (_ \in _). by case/mapP: pdiv_d dv_d_p => d' _ ->; rewrite natTrecE dvdn_mulr. rewrite mem_divs Gauss_dvdr // coprime_sym. by rewrite coprimeXl ?prime_coprime ?dv_d_p. Qed. Lemma sorted_divisors n : sorted leq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma divisors_uniq n : uniq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma sorted_divisors_ltn n : sorted ltn (divisors n). Proof. by rewrite ltn_sorted_uniq_leq divisors_uniq sorted_divisors. Qed. Lemma dvdn_divisors d m : 0 < m -> (d %| m) = (d \in divisors m). Proof. by case/divisors_correct. Qed. Lemma divisor1 n : 1 \in divisors n. Proof. by case: n => // n; rewrite -dvdn_divisors // dvd1n. Qed. Lemma divisors_id n : 0 < n -> n \in divisors n. Proof. by move/dvdn_divisors <-. Qed. (* Big sum / product lemmas*) Lemma dvdn_sum d I r (K : pred I) F : (forall i, K i -> d %| F i) -> d %| \sum_(i <- r | K i) F i. Proof. by move=> dF; elim/big_ind: _ => //; apply: dvdn_add. Qed. Lemma dvdn_partP n m : 0 < n -> reflect (forall p, p \in \pi(n) -> n`_p %| m) (n %| m). Proof. move=> n_gt0; apply: (iffP idP) => n_dvd_m => [p _|]. by apply: dvdn_trans n_dvd_m; apply: dvdn_part. have [-> // | m_gt0] := posnP m. rewrite -(partnT n_gt0) -(partnT m_gt0). rewrite !(@widen_partn (m + n)) ?leq_addl ?leq_addr // /in_mem /=. elim/big_ind2: _ => // [* | q _]; first exact: dvdn_mul. have [-> // | ] := posnP (logn q n); rewrite logn_gt0 => q_n. have pr_q: prime q by move: q_n; rewrite mem_primes; case/andP. by have:= n_dvd_m q q_n; rewrite p_part !pfactor_dvdn // pfactorK. Qed. Lemma modn_partP n a b : 0 < n -> reflect (forall p : nat, p \in \pi(n) -> a = b %[mod n`_p]) (a == b %[mod n]). Proof. move=> n_gt0; wlog le_b_a: a b / b <= a. move=> IH; case: (leqP b a) => [|/ltnW] /IH {IH}// IH. by rewrite eq_sym; apply: (iffP IH) => eqab p /eqab. rewrite eqn_mod_dvd //; apply: (iffP (dvdn_partP _ n_gt0)) => eqab p /eqab; by rewrite -eqn_mod_dvd // => /eqP. Qed. (* The Euler totient function *) Lemma totientE n : n > 0 -> totient n = \prod_(p <- primes n) (p.-1 * p ^ (logn p n).-1). Proof. move=> n_gt0; rewrite /totient n_gt0 prime_decompE unlock. by elim: (primes n) => //= [p pr ->]; rewrite !natTrecE. Qed. Lemma totient_gt0 n : (0 < totient n) = (0 < n). Proof. case: n => // n; rewrite totientE // big_seq_cond prodn_cond_gt0 // => p. by rewrite mem_primes muln_gt0 expn_gt0; case: p => [|[|]]. Qed. Lemma totient_pfactor p e : prime p -> e > 0 -> totient (p ^ e) = p.-1 * p ^ e.-1. Proof. move=> p_pr e_gt0; rewrite totientE ?expn_gt0 ?prime_gt0 //. by rewrite primesX // primes_prime // unlock /= muln1 pfactorK. Qed. Lemma totient_prime p : prime p -> totient p = p.-1. Proof. by move=> p_prime; rewrite -{1}[p]expn1 totient_pfactor // muln1. Qed. Lemma totient_coprime m n : coprime m n -> totient (m * n) = totient m * totient n. Proof. move=> co_mn; have [-> //| m_gt0] := posnP m. have [->|n_gt0] := posnP n; first by rewrite !muln0. rewrite !totientE ?muln_gt0 ?m_gt0 //. have /(perm_big _)->: perm_eq (primes (m * n)) (primes m ++ primes n). apply: uniq_perm => [||p]; first exact: primes_uniq. by rewrite cat_uniq !primes_uniq -coprime_has_primes // co_mn. by rewrite mem_cat primesM. rewrite big_cat /= !big_seq. congr (_ * _); apply: eq_bigr => p; rewrite mem_primes => /and3P[_ _ dvp]. rewrite (mulnC m) logn_Gauss //; move: co_mn. by rewrite -(divnK dvp) coprimeMl => /andP[]. rewrite logn_Gauss //; move: co_mn. by rewrite coprime_sym -(divnK dvp) coprimeMl => /andP[]. Qed. Lemma totient_count_coprime n : totient n = \sum_(0 <= d < n) coprime n d. Proof. elim/ltn_ind: n => // n IHn. case: (leqP n 1) => [|lt1n]; first by rewrite unlock; case: (n) => [|[]]. pose p := pdiv n; have p_pr: prime p by apply: pdiv_prime. have p1 := prime_gt1 p_pr; have p0 := ltnW p1. pose np := n`_p; pose np' := n`_p^'. have co_npp': coprime np np' by rewrite coprime_partC. have [n0 np0 np'0]: [/\ n > 0, np > 0 & np' > 0] by rewrite ltnW ?part_gt0. have def_n: n = np * np' by rewrite partnC. have lnp0: 0 < logn p n by rewrite lognE p_pr n0 pdiv_dvd. pose in_mod k (k0 : k > 0) d := Ordinal (ltn_pmod d k0). rewrite {1}def_n totient_coprime // {IHn}(IHn np') ?big_mkord; last first. by rewrite def_n ltn_Pmull // /np p_part -(expn0 p) ltn_exp2l. have ->: totient np = #|[pred d : 'I_np | coprime np d]|. rewrite [np in LHS]p_part totient_pfactor //=; set q := p ^ _. apply: (@addnI (1 * q)); rewrite -mulnDl [1 + _]prednK // mul1n. have def_np: np = p * q by rewrite -expnS prednK // -p_part. pose mulp := [fun d : 'I_q => in_mod _ np0 (p * d)]. rewrite -def_np -{1}[np]card_ord -(cardC [in codom mulp]). rewrite card_in_image => [|[d1 ltd1] [d2 ltd2] /= _ _ []]; last first. move/eqP; rewrite def_np -!muln_modr ?modn_small //. by rewrite eqn_pmul2l // => eq_op12; apply/eqP. rewrite card_ord; congr (q + _); apply: eq_card => d /=. rewrite !inE [np in coprime np _]p_part coprime_pexpl ?prime_coprime //. congr (~~ _); apply/codomP/idP=> [[d' -> /=] | /dvdnP[r def_d]]. by rewrite def_np -muln_modr // dvdn_mulr. do [rewrite mulnC; case: d => d ltd /=] in def_d *. have ltr: r < q by rewrite -(ltn_pmul2l p0) -def_np -def_d. by exists (Ordinal ltr); apply: val_inj; rewrite /= -def_d modn_small. pose h (d : 'I_n) := (in_mod _ np0 d, in_mod _ np'0 d). pose h' (d : 'I_np * 'I_np') := in_mod _ n0 (chinese np np' d.1 d.2). rewrite -!big_mkcond -sum_nat_const pair_big (reindex_onto h h') => [|[d d'] _]. apply: eq_bigl => [[d ltd] /=]; rewrite !inE -val_eqE /= andbC !coprime_modr. by rewrite def_n -chinese_mod // -coprimeMl -def_n modn_small ?eqxx. apply/eqP; rewrite /eq_op /= /eq_op /= !modn_dvdm ?dvdn_part //. by rewrite chinese_modl // chinese_modr // !modn_small ?eqxx ?ltn_ord. Qed. Lemma totient_gt1 n : (totient n > 1) = (n > 2). Proof. case: n => [|[|[|[|n']]]]//=; set n := n'.+4; rewrite [RHS]isT. wlog [q] : / exists k, k.+3 \in primes n; last first. rewrite mem_primes => /and3P[qp ngt0 qn]. have [[|k]// cqk ->] := pfactor_coprime qp ngt0. rewrite totient_coprime 1?coprime_sym ?coprimeXl//. rewrite totient_pfactor// -?pfactor_dvdn// mulnCA/= (@leq_trans q.+2)//. by rewrite leq_pmulr// muln_gt0 totient_gt0 expn_gt0. have := @prod_prime_decomp n isT; rewrite prime_decompE big_map/=. case: (primes n) (all_prime_primes n) (sorted_primes n) => [|[|[|p']]// [|[|[|[|q']]] r]]//=; first by rewrite big_nil. case: p' => [_ _|p' _ _ _]; last by apply; exists p'; rewrite ?mem_head. rewrite big_seq1; case: logn => [|[|k]]//= ->. by rewrite totient_pfactor//= mul1n (@leq_pexp2l 2 1)//. by move=> _ _ _; apply; exists q'=> //; rewrite !in_cons eqxx orbT. Qed.
Factors.lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Nat.GCD.Basic import Mathlib.Data.Nat.Prime.Basic import Mathlib.Data.List.Prime import Mathlib.Data.List.Sort import Mathlib.Data.List.Perm.Subperm /-! # Prime numbers This file deals with the factors of natural numbers. ## Important declarations - `Nat.primeFactorsList n`: the prime factorization of `n` - `Nat.primeFactorsList_unique`: uniqueness of the prime factorisation -/ assert_not_exists Multiset open Bool Subtype open Nat namespace Nat /-- `primeFactorsList n` is the prime factorization of `n`, listed in increasing order. -/ def primeFactorsList : ℕ → List ℕ | 0 => [] | 1 => [] | k + 2 => let m := minFac (k + 2) m :: primeFactorsList ((k + 2) / m) decreasing_by exact factors_lemma @[simp] theorem primeFactorsList_zero : primeFactorsList 0 = [] := by rw [primeFactorsList] @[simp] theorem primeFactorsList_one : primeFactorsList 1 = [] := by rw [primeFactorsList] @[simp] theorem primeFactorsList_two : primeFactorsList 2 = [2] := by simp [primeFactorsList] theorem prime_of_mem_primeFactorsList {n : ℕ} : ∀ {p : ℕ}, p ∈ primeFactorsList n → Prime p := by match n with | 0 => simp | 1 => simp | k + 2 => intro p h let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma have h₁ : p = m ∨ p ∈ primeFactorsList ((k + 2) / m) := List.mem_cons.1 (by rwa [primeFactorsList] at h) exact Or.casesOn h₁ (fun h₂ => h₂.symm ▸ minFac_prime (by simp)) prime_of_mem_primeFactorsList theorem pos_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ primeFactorsList n) : 0 < p := Prime.pos (prime_of_mem_primeFactorsList h) theorem prod_primeFactorsList : ∀ {n}, n ≠ 0 → List.prod (primeFactorsList n) = n | 0 => by simp | 1 => by simp | k + 2 => fun _ => let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma show (primeFactorsList (k + 2)).prod = (k + 2) by have h₁ : (k + 2) / m ≠ 0 := fun h => by have : (k + 2) = 0 * m := (Nat.div_eq_iff_eq_mul_left (minFac_pos _) (minFac_dvd _)).1 h rw [zero_mul] at this; exact (show k + 2 ≠ 0 by simp) this rw [primeFactorsList, List.prod_cons, prod_primeFactorsList h₁, Nat.mul_div_cancel' (minFac_dvd _)] theorem primeFactorsList_prime {p : ℕ} (hp : Nat.Prime p) : p.primeFactorsList = [p] := by have : p = p - 2 + 2 := Nat.eq_add_of_sub_eq hp.two_le rfl rw [this, primeFactorsList] simp only [Eq.symm this] have : Nat.minFac p = p := (Nat.prime_def_minFac.mp hp).2 simp only [this, primeFactorsList, Nat.div_self (Nat.Prime.pos hp)] theorem primeFactorsList_chain {n : ℕ} : ∀ {a}, (∀ p, Prime p → p ∣ n → a ≤ p) → List.Chain (· ≤ ·) a (primeFactorsList n) := by match n with | 0 => simp | 1 => simp | k + 2 => intro a h let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma rw [primeFactorsList] refine List.Chain.cons ((le_minFac.2 h).resolve_left (by simp)) (primeFactorsList_chain ?_) exact fun p pp d => minFac_le_of_dvd pp.two_le (d.trans <| div_dvd_of_dvd <| minFac_dvd _) theorem primeFactorsList_chain_2 (n) : List.Chain (· ≤ ·) 2 (primeFactorsList n) := primeFactorsList_chain fun _ pp _ => pp.two_le theorem primeFactorsList_chain' (n) : List.Chain' (· ≤ ·) (primeFactorsList n) := @List.Chain'.tail _ _ (_ :: _) (primeFactorsList_chain_2 _) theorem primeFactorsList_sorted (n : ℕ) : List.Sorted (· ≤ ·) (primeFactorsList n) := List.chain'_iff_pairwise.1 (primeFactorsList_chain' _) /-- `primeFactorsList` can be constructed inductively by extracting `minFac`, for sufficiently large `n`. -/ theorem primeFactorsList_add_two (n : ℕ) : primeFactorsList (n + 2) = minFac (n + 2) :: primeFactorsList ((n + 2) / minFac (n + 2)) := by rw [primeFactorsList] @[simp] theorem primeFactorsList_eq_nil (n : ℕ) : n.primeFactorsList = [] ↔ n = 0 ∨ n = 1 := by constructor <;> intro h · rcases n with (_ | _ | n) · exact Or.inl rfl · exact Or.inr rfl · rw [primeFactorsList] at h injection h · rcases h with (rfl | rfl) · exact primeFactorsList_zero · exact primeFactorsList_one open scoped List in theorem eq_of_perm_primeFactorsList {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : a.primeFactorsList ~ b.primeFactorsList) : a = b := by simpa [prod_primeFactorsList ha, prod_primeFactorsList hb] using List.Perm.prod_eq h section open List theorem mem_primeFactorsList_iff_dvd {n p : ℕ} (hn : n ≠ 0) (hp : Prime p) : p ∈ primeFactorsList n ↔ p ∣ n where mp h := prod_primeFactorsList hn ▸ List.dvd_prod h mpr h := mem_list_primes_of_dvd_prod (prime_iff.mp hp) (fun _ h ↦ prime_iff.mp (prime_of_mem_primeFactorsList h)) ((prod_primeFactorsList hn).symm ▸ h) theorem dvd_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ∣ n := by rcases n.eq_zero_or_pos with (rfl | hn) · exact dvd_zero p · rwa [← mem_primeFactorsList_iff_dvd hn.ne' (prime_of_mem_primeFactorsList h)] theorem mem_primeFactorsList {n p} (hn : n ≠ 0) : p ∈ primeFactorsList n ↔ Prime p ∧ p ∣ n := ⟨fun h => ⟨prime_of_mem_primeFactorsList h, dvd_of_mem_primeFactorsList h⟩, fun ⟨hprime, hdvd⟩ => (mem_primeFactorsList_iff_dvd hn hprime).mpr hdvd⟩ @[simp] lemma mem_primeFactorsList' {n p} : p ∈ n.primeFactorsList ↔ p.Prime ∧ p ∣ n ∧ n ≠ 0 := by cases n <;> simp [mem_primeFactorsList, *] theorem le_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ≤ n := by rcases n.eq_zero_or_pos with (rfl | hn) · rw [primeFactorsList_zero] at h cases h · exact le_of_dvd hn (dvd_of_mem_primeFactorsList h) /-- **Fundamental theorem of arithmetic** -/ theorem primeFactorsList_unique {n : ℕ} {l : List ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, Prime p) : l ~ primeFactorsList n := by refine perm_of_prod_eq_prod ?_ ?_ ?_ · rw [h₁] refine (prod_primeFactorsList ?_).symm rintro rfl rw [prod_eq_zero_iff] at h₁ exact Prime.ne_zero (h₂ 0 h₁) rfl · simp_rw [← prime_iff] exact h₂ · simp_rw [← prime_iff] exact fun p => prime_of_mem_primeFactorsList theorem Prime.primeFactorsList_pow {p : ℕ} (hp : p.Prime) (n : ℕ) : (p ^ n).primeFactorsList = List.replicate n p := by symm rw [← List.replicate_perm] apply Nat.primeFactorsList_unique (List.prod_replicate n p) intro q hq rwa [eq_of_mem_replicate hq] theorem eq_prime_pow_of_unique_prime_dvd {n p : ℕ} (hpos : n ≠ 0) (h : ∀ {d}, Nat.Prime d → d ∣ n → d = p) : n = p ^ n.primeFactorsList.length := by set k := n.primeFactorsList.length rw [← prod_primeFactorsList hpos, ← prod_replicate k p, eq_replicate_of_mem fun d hd => h (prime_of_mem_primeFactorsList hd) (dvd_of_mem_primeFactorsList hd)] /-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/ theorem perm_primeFactorsList_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) : (a * b).primeFactorsList ~ a.primeFactorsList ++ b.primeFactorsList := by refine (primeFactorsList_unique ?_ ?_).symm · rw [List.prod_append, prod_primeFactorsList ha, prod_primeFactorsList hb] · intro p hp rw [List.mem_append] at hp rcases hp with hp' | hp' <;> exact prime_of_mem_primeFactorsList hp' /-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/ theorem perm_primeFactorsList_mul_of_coprime {a b : ℕ} (hab : Coprime a b) : (a * b).primeFactorsList ~ a.primeFactorsList ++ b.primeFactorsList := by rcases a.eq_zero_or_pos with (rfl | ha) · simp [(coprime_zero_left _).mp hab] rcases b.eq_zero_or_pos with (rfl | hb) · simp [(coprime_zero_right _).mp hab] exact perm_primeFactorsList_mul ha.ne' hb.ne' theorem primeFactorsList_sublist_right {n k : ℕ} (h : k ≠ 0) : n.primeFactorsList <+ (n * k).primeFactorsList := by rcases n with - | hn · simp [zero_mul] apply sublist_of_subperm_of_sorted _ (primeFactorsList_sorted _) (primeFactorsList_sorted _) simp only [(perm_primeFactorsList_mul (Nat.succ_ne_zero _) h).subperm_left] exact (sublist_append_left _ _).subperm theorem primeFactorsList_sublist_of_dvd {n k : ℕ} (h : n ∣ k) (h' : k ≠ 0) : n.primeFactorsList <+ k.primeFactorsList := by obtain ⟨a, rfl⟩ := h exact primeFactorsList_sublist_right (right_ne_zero_of_mul h') theorem primeFactorsList_subset_right {n k : ℕ} (h : k ≠ 0) : n.primeFactorsList ⊆ (n * k).primeFactorsList := (primeFactorsList_sublist_right h).subset theorem primeFactorsList_subset_of_dvd {n k : ℕ} (h : n ∣ k) (h' : k ≠ 0) : n.primeFactorsList ⊆ k.primeFactorsList := (primeFactorsList_sublist_of_dvd h h').subset theorem dvd_of_primeFactorsList_subperm {a b : ℕ} (ha : a ≠ 0) (h : a.primeFactorsList <+~ b.primeFactorsList) : a ∣ b := by rcases b.eq_zero_or_pos with (rfl | hb) · exact dvd_zero _ rcases a with (_ | _ | a) · exact (ha rfl).elim · exact one_dvd _ use (b.primeFactorsList.diff a.succ.succ.primeFactorsList).prod nth_rw 1 [← Nat.prod_primeFactorsList ha] rw [← List.prod_append, List.Perm.prod_eq <| List.subperm_append_diff_self_of_count_le <| List.subperm_ext_iff.mp h, Nat.prod_primeFactorsList hb.ne'] theorem replicate_subperm_primeFactorsList_iff {a b n : ℕ} (ha : Prime a) (hb : b ≠ 0) : replicate n a <+~ primeFactorsList b ↔ a ^ n ∣ b := by induction n generalizing b with | zero => simp | succ n ih => constructor · rw [List.subperm_iff] rintro ⟨u, hu1, hu2⟩ rw [← Nat.prod_primeFactorsList hb, ← hu1.prod_eq, ← prod_replicate] exact hu2.prod_dvd_prod · rintro ⟨c, rfl⟩ rw [Ne, pow_succ', mul_assoc, mul_eq_zero, _root_.not_or] at hb rw [pow_succ', mul_assoc, replicate_succ, (Nat.perm_primeFactorsList_mul hb.1 hb.2).subperm_left, primeFactorsList_prime ha, singleton_append, subperm_cons, ih hb.2] exact dvd_mul_right _ _ end theorem mem_primeFactorsList_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) {p : ℕ} : p ∈ (a * b).primeFactorsList ↔ p ∈ a.primeFactorsList ∨ p ∈ b.primeFactorsList := by rw [mem_primeFactorsList (mul_ne_zero ha hb), mem_primeFactorsList ha, mem_primeFactorsList hb, ← and_or_left] simpa only [and_congr_right_iff] using Prime.dvd_mul /-- The sets of factors of coprime `a` and `b` are disjoint -/ theorem coprime_primeFactorsList_disjoint {a b : ℕ} (hab : a.Coprime b) : List.Disjoint a.primeFactorsList b.primeFactorsList := by intro q hqa hqb apply not_prime_one rw [← eq_one_of_dvd_coprimes hab (dvd_of_mem_primeFactorsList hqa) (dvd_of_mem_primeFactorsList hqb)] exact prime_of_mem_primeFactorsList hqa theorem mem_primeFactorsList_mul_of_coprime {a b : ℕ} (hab : Coprime a b) (p : ℕ) : p ∈ (a * b).primeFactorsList ↔ p ∈ a.primeFactorsList ∪ b.primeFactorsList := by rcases a.eq_zero_or_pos with (rfl | ha) · simp [(coprime_zero_left _).mp hab] rcases b.eq_zero_or_pos with (rfl | hb) · simp [(coprime_zero_right _).mp hab] rw [mem_primeFactorsList_mul ha.ne' hb.ne', List.mem_union_iff] open List /-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/ theorem mem_primeFactorsList_mul_left {p a b : ℕ} (hpa : p ∈ a.primeFactorsList) (hb : b ≠ 0) : p ∈ (a * b).primeFactorsList := by rcases eq_or_ne a 0 with (rfl | ha) · simp at hpa apply (mem_primeFactorsList_mul ha hb).2 (Or.inl hpa) /-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/ theorem mem_primeFactorsList_mul_right {p a b : ℕ} (hpb : p ∈ b.primeFactorsList) (ha : a ≠ 0) : p ∈ (a * b).primeFactorsList := by rw [mul_comm] exact mem_primeFactorsList_mul_left hpb ha theorem eq_two_pow_or_exists_odd_prime_and_dvd (n : ℕ) : (∃ k : ℕ, n = 2 ^ k) ∨ ∃ p, Nat.Prime p ∧ p ∣ n ∧ Odd p := (eq_or_ne n 0).elim (fun hn => Or.inr ⟨3, prime_three, hn.symm ▸ dvd_zero 3, ⟨1, rfl⟩⟩) fun hn => or_iff_not_imp_right.mpr fun H => ⟨n.primeFactorsList.length, eq_prime_pow_of_unique_prime_dvd hn fun {_} hprime hdvd => hprime.eq_two_or_odd'.resolve_right fun hodd => H ⟨_, hprime, hdvd, hodd⟩⟩ theorem four_dvd_or_exists_odd_prime_and_dvd_of_two_lt {n : ℕ} (n2 : 2 < n) : 4 ∣ n ∨ ∃ p, Prime p ∧ p ∣ n ∧ Odd p := by obtain ⟨_ | _ | k, rfl⟩ | ⟨p, hp, hdvd, hodd⟩ := n.eq_two_pow_or_exists_odd_prime_and_dvd · contradiction · contradiction · simp [Nat.pow_succ, mul_assoc] · exact Or.inr ⟨p, hp, hdvd, hodd⟩ end Nat
character.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype choice ssrnat seq. From mathcomp Require Import path div fintype tuple finfun bigop prime order. From mathcomp Require Import ssralg poly finset gproduct fingroup morphism. From mathcomp Require Import perm automorphism quotient finalg action zmodp. From mathcomp Require Import commutator cyclic center pgroup nilpotent sylow. From mathcomp Require Import abelian matrix mxalgebra mxpoly mxrepresentation. From mathcomp Require Import vector ssrnum algC classfun archimedean. (******************************************************************************) (* This file contains the basic notions of character theory, based on Isaacs. *) (* irr G == tuple of the elements of 'CF(G) that are irreducible *) (* characters of G. *) (* Nirr G == number of irreducible characters of G. *) (* Iirr G == index type for the irreducible characters of G. *) (* := 'I_(Nirr G). *) (* 'chi_i == the i-th element of irr G, for i : Iirr G. *) (* 'chi[G]_i Note that 'chi_0 = 1, the principal character of G. *) (* 'Chi_i == an irreducible representation that affords 'chi_i. *) (* socle_of_Iirr i == the Wedderburn component of the regular representation *) (* of G, corresponding to 'Chi_i. *) (* Iirr_of_socle == the inverse of socle_of_Iirr (which is one-to-one). *) (* phi.[A]%CF == the image of A \in group_ring G under phi : 'CF(G). *) (* cfRepr rG == the character afforded by the representation rG of G. *) (* cfReg G == the regular character, afforded by the regular *) (* representation of G. *) (* detRepr rG == the linear character afforded by the determinant of rG. *) (* cfDet phi == the linear character afforded by the determinant of a *) (* representation affording phi. *) (* 'o(phi) == the "determinential order" of phi (the multiplicative *) (* order of cfDet phi. *) (* phi \is a character <=> phi : 'CF(G) is a character of G or 0. *) (* i \in irr_constt phi <=> 'chi_i is an irreducible constituent of phi: phi *) (* has a non-zero coordinate on 'chi_i over the basis irr G. *) (* xi \is a linear_char xi <=> xi : 'CF(G) is a linear character of G. *) (* 'Z(chi)%CF == the center of chi when chi is a character of G, i.e., *) (* rcenter rG where rG is a representation that affords phi. *) (* If phi is not a character then 'Z(chi)%CF = cfker phi. *) (* aut_Iirr u i == the index of cfAut u 'chi_i in irr G. *) (* conjC_Iirr i == the index of 'chi_i^*%CF in irr G. *) (* morph_Iirr i == the index of cfMorph 'chi[f @* G]_i in irr G. *) (* isom_Iirr isoG i == the index of cfIsom isoG 'chi[G]_i in irr R. *) (* mod_Iirr i == the index of ('chi[G / H]_i %% H)%CF in irr G. *) (* quo_Iirr i == the index of ('chi[G]_i / H)%CF in irr (G / H). *) (* Ind_Iirr G i == the index of 'Ind[G, H] 'chi_i, provided it is an *) (* irreducible character (such as when if H is the inertia *) (* group of 'chi_i). *) (* Res_Iirr H i == the index of 'Res[H, G] 'chi_i, provided it is an *) (* irreducible character (such as when 'chi_i is linear). *) (* sdprod_Iirr defG i == the index of cfSdprod defG 'chi_i in irr G, given *) (* defG : K ><| H = G. *) (* And, for KxK : K \x H = G. *) (* dprodl_Iirr KxH i == the index of cfDprodl KxH 'chi[K]_i in irr G. *) (* dprodr_Iirr KxH j == the index of cfDprodr KxH 'chi[H]_j in irr G. *) (* dprod_Iirr KxH (i, j) == the index of cfDprod KxH 'chi[K]_i 'chi[H]_j. *) (* inv_dprod_Iirr KxH == the inverse of dprod_Iirr KxH. *) (* The following are used to define and exploit the character table: *) (* character_table G == the character table of G, whose i-th row lists the *) (* values taken by 'chi_i on the conjugacy classes *) (* of G; this is a square Nirr G x NirrG matrix. *) (* irr_class i == the conjugacy class of G with index i : Iirr G. *) (* class_Iirr xG == the index of xG \in classes G, in Iirr G. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. Section AlgC. Variable (gT : finGroupType). Lemma groupC : group_closure_field algC gT. Proof. exact: group_closure_closed_field. Qed. End AlgC. Section Tensor. Variable (F : fieldType). Fixpoint trow (n1 : nat) : forall (A : 'rV[F]_n1) m2 n2 (B : 'M[F]_(m2,n2)), 'M[F]_(m2,n1 * n2) := if n1 is n'1.+1 then fun (A : 'M[F]_(1,(1 + n'1))) m2 n2 (B : 'M[F]_(m2,n2)) => (row_mx (lsubmx A 0 0 *: B) (trow (rsubmx A) B)) else (fun _ _ _ _ => 0). Lemma trow0 n1 m2 n2 B : @trow n1 0 m2 n2 B = 0. Proof. elim: n1=> //= n1 IH. rewrite !mxE scale0r linear0. rewrite IH //; apply/matrixP=> i j; rewrite !mxE. by case: split=> *; rewrite mxE. Qed. Definition trowb n1 m2 n2 B A := @trow n1 A m2 n2 B. Lemma trowbE n1 m2 n2 A B : trowb B A = @trow n1 A m2 n2 B. Proof. by []. Qed. Lemma trowb_is_linear n1 m2 n2 (B : 'M_(m2,n2)) : linear (@trowb n1 m2 n2 B). Proof. elim: n1=> [|n1 IH] //= k A1 A2 /=; first by rewrite scaler0 add0r. rewrite !linearD /= !linearZ /= IH 2!mxE. by rewrite scalerDl -scalerA -add_row_mx -scale_row_mx. Qed. HB.instance Definition _ n1 m2 n2 B := GRing.isSemilinear.Build _ _ _ _ (trowb B) (GRing.semilinear_linear (@trowb_is_linear n1 m2 n2 B)). Lemma trow_is_linear n1 m2 n2 (A : 'rV_n1) : linear (@trow n1 A m2 n2). Proof. elim: n1 A => [|n1 IH] //= A k A1 A2 /=; first by rewrite scaler0 add0r. rewrite linearP /=; apply/matrixP=> i j; rewrite !mxE. by case: split=> a; rewrite ?IH !mxE. Qed. HB.instance Definition _ n1 m2 n2 A := GRing.isSemilinear.Build _ _ _ _ (@trow n1 A m2 n2) (GRing.semilinear_linear (@trow_is_linear n1 m2 n2 A)). Fixpoint tprod (m1 : nat) : forall n1 (A : 'M[F]_(m1,n1)) m2 n2 (B : 'M[F]_(m2,n2)), 'M[F]_(m1 * m2,n1 * n2) := if m1 is m'1.+1 return forall n1 (A : 'M[F]_(m1,n1)) m2 n2 (B : 'M[F]_(m2,n2)), 'M[F]_(m1 * m2,n1 * n2) then fun n1 (A : 'M[F]_(1 + m'1,n1)) m2 n2 B => (col_mx (trow (usubmx A) B) (tprod (dsubmx A) B)) else (fun _ _ _ _ _ => 0). Lemma dsumx_mul m1 m2 n p A B : dsubmx ((A *m B) : 'M[F]_(m1 + m2, n)) = dsubmx (A : 'M_(m1 + m2, p)) *m B. Proof. apply/matrixP=> i j /[!mxE]; apply: eq_bigr=> k _. by rewrite !mxE. Qed. Lemma usumx_mul m1 m2 n p A B : usubmx ((A *m B) : 'M[F]_(m1 + m2, n)) = usubmx (A : 'M_(m1 + m2, p)) *m B. Proof. by apply/matrixP=> i j /[!mxE]; apply: eq_bigr=> k _ /[!mxE]. Qed. Let trow_mul (m1 m2 n2 p2 : nat) (A : 'rV_m1) (B1: 'M[F]_(m2,n2)) (B2 :'M[F]_(n2,p2)) : trow A (B1 *m B2) = B1 *m trow A B2. Proof. elim: m1 A => [|m1 IH] A /=; first by rewrite mulmx0. by rewrite IH mul_mx_row -scalemxAr. Qed. Lemma tprodE m1 n1 p1 (A1 :'M[F]_(m1,n1)) (A2 :'M[F]_(n1,p1)) m2 n2 p2 (B1 :'M[F]_(m2,n2)) (B2 :'M[F]_(n2,p2)) : tprod (A1 *m A2) (B1 *m B2) = (tprod A1 B1) *m (tprod A2 B2). Proof. elim: m1 n1 p1 A1 A2 m2 n2 p2 B1 B2 => /= [|m1 IH]. by move=> *; rewrite mul0mx. move=> n1 p1 A1 A2 m2 n2 p2 B1 B2. rewrite mul_col_mx -IH. congr col_mx; last by rewrite dsumx_mul. rewrite usumx_mul. elim: n1 {A1}(usubmx (A1: 'M_(1 + m1, n1))) p1 A2=> //= [u p1 A2|]. by rewrite [A2](flatmx0) !mulmx0 -trowbE linear0. move=> n1 IH1 A p1 A2 //=. set Al := lsubmx _; set Ar := rsubmx _. set Su := usubmx _; set Sd := dsubmx _. rewrite mul_row_col -IH1. rewrite -{1}(@hsubmxK F 1 1 n1 A). rewrite -{1}(@vsubmxK F 1 n1 p1 A2). rewrite (@mul_row_col F 1 1 n1 p1). rewrite -trowbE linearD /= trowbE -/Al. congr (_ + _). rewrite {1}[Al]mx11_scalar mul_scalar_mx. by rewrite -trowbE linearZ /= trowbE -/Su trow_mul scalemxAl. Qed. Let tprod_tr m1 n1 (A :'M[F]_(m1, 1 + n1)) m2 n2 (B :'M[F]_(m2, n2)) : tprod A B = row_mx (trow (lsubmx A)^T B^T)^T (tprod (rsubmx A) B). Proof. elim: m1 n1 A m2 n2 B=> [|m1 IH] n1 A m2 n2 B //=. by rewrite trmx0 row_mx0. rewrite !IH. pose A1 := A : 'M_(1 + m1, 1 + n1). have F1: dsubmx (rsubmx A1) = rsubmx (dsubmx A1). by apply/matrixP=> i j; rewrite !mxE. have F2: rsubmx (usubmx A1) = usubmx (rsubmx A1). by apply/matrixP=> i j; rewrite !mxE. have F3: lsubmx (dsubmx A1) = dsubmx (lsubmx A1). by apply/matrixP=> i j; rewrite !mxE. rewrite tr_row_mx -block_mxEv -block_mxEh !(F1,F2,F3); congr block_mx. - by rewrite !mxE linearZ /= trmxK. by rewrite -trmx_dsub. Qed. Lemma tprod1 m n : tprod (1%:M : 'M[F]_(m,m)) (1%:M : 'M[F]_(n,n)) = 1%:M. Proof. elim: m n => [|m IH] n //=; first by rewrite [1%:M]flatmx0. rewrite tprod_tr. set u := rsubmx _; have->: u = 0. apply/matrixP=> i j; rewrite !mxE. by case: i; case: j=> /= j Hj; case. set v := lsubmx (dsubmx _); have->: v = 0. apply/matrixP=> i j; rewrite !mxE. by case: i; case: j; case. set w := rsubmx _; have->: w = 1%:M. apply/matrixP=> i j; rewrite !mxE. by case: i; case: j; case. rewrite IH -!trowbE !linear0. rewrite -block_mxEv. set z := (lsubmx _) 0 0; have->: z = 1. by rewrite /z !mxE eqxx. by rewrite scale1r scalar_mx_block. Qed. Lemma mxtrace_prod m n (A :'M[F]_(m)) (B :'M[F]_(n)) : \tr (tprod A B) = \tr A * \tr B. Proof. elim: m n A B => [|m IH] n A B //=. by rewrite [A]flatmx0 mxtrace0 mul0r. rewrite tprod_tr -block_mxEv mxtrace_block IH. rewrite linearZ/= -mulrDl -trace_mx11; congr (_ * _). pose A1 := A : 'M_(1 + m). rewrite -[A in RHS](@submxK _ 1 m 1 m A1). by rewrite (@mxtrace_block _ _ _ (ulsubmx A1)). Qed. End Tensor. (* Representation sigma type and standard representations. *) Section StandardRepresentation. Variables (R : fieldType) (gT : finGroupType) (G : {group gT}). Local Notation reprG := (mx_representation R G). Record representation := Representation {rdegree; mx_repr_of_repr :> reprG rdegree}. Lemma mx_repr0 : mx_repr G (fun _ : gT => 1%:M : 'M[R]_0). Proof. by split=> // g h Hg Hx; rewrite mulmx1. Qed. Definition grepr0 := Representation (MxRepresentation mx_repr0). Lemma add_mx_repr (rG1 rG2 : representation) : mx_repr G (fun g => block_mx (rG1 g) 0 0 (rG2 g)). Proof. split=> [|x y Hx Hy]; first by rewrite !repr_mx1 -scalar_mx_block. by rewrite mulmx_block !(mulmx0, mul0mx, addr0, add0r, repr_mxM). Qed. Definition dadd_grepr rG1 rG2 := Representation (MxRepresentation (add_mx_repr rG1 rG2)). Section DsumRepr. Variables (n : nat) (rG : reprG n). Lemma mx_rsim_dadd (U V W : 'M_n) (rU rV : representation) (modU : mxmodule rG U) (modV : mxmodule rG V) (modW : mxmodule rG W) : (U + V :=: W)%MS -> mxdirect (U + V) -> mx_rsim (submod_repr modU) rU -> mx_rsim (submod_repr modV) rV -> mx_rsim (submod_repr modW) (dadd_grepr rU rV). Proof. case: rU; case: rV=> nV rV nU rU defW dxUV /=. have tiUV := mxdirect_addsP dxUV. move=> [fU def_nU]; rewrite -{nU}def_nU in rU fU * => inv_fU hom_fU. move=> [fV def_nV]; rewrite -{nV}def_nV in rV fV * => inv_fV hom_fV. pose pU := in_submod U (proj_mx U V) *m fU. pose pV := in_submod V (proj_mx V U) *m fV. exists (val_submod 1%:M *m row_mx pU pV) => [||g Gg]. - by rewrite -defW (mxdirectP dxUV). - apply/row_freeP. pose pU' := invmx fU *m val_submod 1%:M. pose pV' := invmx fV *m val_submod 1%:M. exists (in_submod _ (col_mx pU' pV')). rewrite in_submodE mulmxA -in_submodE -mulmxA mul_row_col mulmxDr. rewrite -[pU *m _]mulmxA -[pV *m _]mulmxA !mulKVmx -?row_free_unit //. rewrite addrC (in_submodE V) 2![val_submod 1%:M *m _]mulmxA -in_submodE. rewrite addrC (in_submodE U) 2![val_submod 1%:M *m _ in X in X + _]mulmxA. rewrite -in_submodE -!val_submodE !in_submodK ?proj_mx_sub //. by rewrite add_proj_mx ?val_submodK // val_submod1 defW. rewrite mulmxA -val_submodE -[submod_repr _ g]mul1mx val_submodJ //. rewrite -(mulmxA _ (rG g)) mul_mx_row -[in RHS]mulmxA mul_row_block. rewrite !mulmx0 addr0 add0r !mul_mx_row. set W' := val_submod 1%:M; congr (row_mx _ _). rewrite 3!mulmxA in_submodE mulmxA. have hom_pU: (W' <= dom_hom_mx rG (proj_mx U V))%MS. by rewrite val_submod1 -defW proj_mx_hom. rewrite (hom_mxP hom_pU) // -in_submodE (in_submodJ modU) ?proj_mx_sub //. rewrite -(mulmxA _ _ fU) hom_fU // in_submodE -2!(mulmxA W') -in_submodE. by rewrite -mulmxA (mulmxA _ fU). rewrite 3!mulmxA in_submodE mulmxA. have hom_pV: (W' <= dom_hom_mx rG (proj_mx V U))%MS. by rewrite val_submod1 -defW addsmxC proj_mx_hom // capmxC. rewrite (hom_mxP hom_pV) // -in_submodE (in_submodJ modV) ?proj_mx_sub //. rewrite -(mulmxA _ _ fV) hom_fV // in_submodE -2!(mulmxA W') -in_submodE. by rewrite -mulmxA (mulmxA _ fV). Qed. Lemma mx_rsim_dsum (I : finType) (P : pred I) U rU (W : 'M_n) (modU : forall i, mxmodule rG (U i)) (modW : mxmodule rG W) : let S := (\sum_(i | P i) U i)%MS in (S :=: W)%MS -> mxdirect S -> (forall i, mx_rsim (submod_repr (modU i)) (rU i : representation)) -> mx_rsim (submod_repr modW) (\big[dadd_grepr/grepr0]_(i | P i) rU i). Proof. move=> /= defW dxW rsimU. rewrite mxdirectE /= -!(big_filter _ P) in dxW defW *. elim: {P}(filter P _) => [|i e IHe] in W modW dxW defW *. rewrite !big_nil /= in defW *. by exists 0 => [||? _]; rewrite ?mul0mx ?mulmx0 // /row_free -defW !mxrank0. rewrite !big_cons /= in dxW defW *. rewrite 2!(big_nth i) !big_mkord /= in IHe dxW defW. set Wi := (\sum_i _)%MS in defW dxW IHe. rewrite -mxdirectE mxdirect_addsE !mxdirectE eqxx /= -/Wi in dxW. have modWi: mxmodule rG Wi by apply: sumsmx_module. case/andP: dxW; move/(IHe Wi modWi) {IHe}; move/(_ (eqmx_refl _))=> rsimWi. by move/eqP; move/mxdirect_addsP=> dxUiWi; apply: mx_rsim_dadd (rsimU i) rsimWi. Qed. Definition muln_grepr rW k := \big[dadd_grepr/grepr0]_(i < k) rW. Lemma mx_rsim_socle (sG : socleType rG) (W : sG) (rW : representation) : let modW : mxmodule rG W := component_mx_module rG (socle_base W) in mx_rsim (socle_repr W) rW -> mx_rsim (submod_repr modW) (muln_grepr rW (socle_mult W)). Proof. set M := socle_base W => modW rsimM. have simM: mxsimple rG M := socle_simple W. have rankM_gt0: (\rank M > 0)%N by rewrite lt0n mxrank_eq0; case: simM. have [I /= U_I simU]: mxsemisimple rG W by apply: component_mx_semisimple. pose U (i : 'I_#|I|) := U_I (enum_val i). have reindexI := reindex _ (onW_bij I (enum_val_bij I)). rewrite mxdirectE /= !reindexI -mxdirectE /= => defW dxW. have isoU: forall i, mx_iso rG M (U i). move=> i; have sUiW: (U i <= W)%MS by rewrite -defW (sumsmx_sup i). exact: component_mx_iso (simU _) sUiW. have ->: socle_mult W = #|I|. rewrite -(mulnK #|I| rankM_gt0); congr (_ %/ _)%N. rewrite -defW (mxdirectP dxW) /= -sum_nat_const reindexI /=. by apply: eq_bigr => i _; rewrite -(mxrank_iso (isoU i)). have modU: mxmodule rG (U _) := mxsimple_module (simU _). suff: mx_rsim (submod_repr (modU _)) rW by apply: mx_rsim_dsum defW dxW. by move=> i; apply: mx_rsim_trans (mx_rsim_sym _) rsimM; apply/mx_rsim_iso. Qed. End DsumRepr. Section ProdRepr. Variables (n1 n2 : nat) (rG1 : reprG n1) (rG2 : reprG n2). Lemma prod_mx_repr : mx_repr G (fun g => tprod (rG1 g) (rG2 g)). Proof. split=>[|i j InG JnG]; first by rewrite !repr_mx1 tprod1. by rewrite !repr_mxM // tprodE. Qed. Definition prod_repr := MxRepresentation prod_mx_repr. End ProdRepr. Lemma prod_repr_lin n2 (rG1 : reprG 1) (rG2 : reprG n2) : {in G, forall x, let cast_n2 := esym (mul1n n2) in prod_repr rG1 rG2 x = castmx (cast_n2, cast_n2) (rG1 x 0 0 *: rG2 x)}. Proof. move=> x Gx /=; set cast_n2 := esym _; rewrite /prod_repr /= !mxE !lshift0. apply/matrixP=> i j; rewrite castmxE /=. do 2![rewrite mxE; case: splitP => [? ? | []//]]. by congr ((_ *: rG2 x) _ _); apply: val_inj. Qed. End StandardRepresentation. Arguments grepr0 {R gT G}. Prenex Implicits dadd_grepr. Section Char. Variables (gT : finGroupType) (G : {group gT}). Fact cfRepr_subproof n (rG : mx_representation algC G n) : is_class_fun <<G>> [ffun x => \tr (rG x) *+ (x \in G)]. Proof. rewrite genGid; apply: intro_class_fun => [x y Gx Gy | _ /negbTE-> //]. by rewrite groupJr // !repr_mxM ?groupM ?groupV // mxtrace_mulC repr_mxK. Qed. Definition cfRepr n rG := Cfun 0 (@cfRepr_subproof n rG). Lemma cfRepr1 n rG : @cfRepr n rG 1%g = n%:R. Proof. by rewrite cfunE group1 repr_mx1 mxtrace1. Qed. Lemma cfRepr_sim n1 n2 rG1 rG2 : mx_rsim rG1 rG2 -> @cfRepr n1 rG1 = @cfRepr n2 rG2. Proof. case/mx_rsim_def=> f12 [f21] fK def_rG1; apply/cfun_inP=> x Gx. by rewrite !cfunE def_rG1 // mxtrace_mulC mulmxA fK mul1mx. Qed. Lemma cfRepr0 : cfRepr grepr0 = 0. Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx mxtrace1. Qed. Lemma cfRepr_dadd rG1 rG2 : cfRepr (dadd_grepr rG1 rG2) = cfRepr rG1 + cfRepr rG2. Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx mxtrace_block. Qed. Lemma cfRepr_dsum I r (P : pred I) rG : cfRepr (\big[dadd_grepr/grepr0]_(i <- r | P i) rG i) = \sum_(i <- r | P i) cfRepr (rG i). Proof. exact: (big_morph _ cfRepr_dadd cfRepr0). Qed. Lemma cfRepr_muln rG k : cfRepr (muln_grepr rG k) = cfRepr rG *+ k. Proof. by rewrite cfRepr_dsum /= sumr_const card_ord. Qed. Section StandardRepr. Variables (n : nat) (rG : mx_representation algC G n). Let sG := DecSocleType rG. Let iG : irrType algC G := DecSocleType _. Definition standard_irr (W : sG) := irr_comp iG (socle_repr W). Definition standard_socle i := pick [pred W | standard_irr W == i]. Local Notation soc := standard_socle. Definition standard_irr_coef i := oapp (fun W => socle_mult W) 0 (soc i). Definition standard_grepr := \big[dadd_grepr/grepr0]_i muln_grepr (Representation (socle_repr i)) (standard_irr_coef i). Lemma mx_rsim_standard : mx_rsim rG standard_grepr. Proof. pose W i := oapp val 0 (soc i); pose S := (\sum_i W i)%MS. have C'G: [pchar algC]^'.-group G := algC'G_pchar G. have [defS dxS]: (S :=: 1%:M)%MS /\ mxdirect S. rewrite /S mxdirectE /= !(bigID soc xpredT) /=. rewrite addsmxC big1 => [|i]; last by rewrite /W; case (soc i). rewrite adds0mx_id addnC (@big1 nat) ?add0n => [|i]; last first. by rewrite /W; case: (soc i); rewrite ?mxrank0. have <-: Socle sG = 1%:M := reducible_Socle1 sG (mx_Maschke_pchar rG C'G). have [W0 _ | noW] := pickP sG; last first. suff no_i: (soc : pred iG) =1 xpred0 by rewrite /Socle !big_pred0 ?mxrank0. by move=> i; rewrite /soc; case: pickP => // W0; have:= noW W0. have irrK Wi: soc (standard_irr Wi) = Some Wi. rewrite /soc; case: pickP => [W' | /(_ Wi)] /= /eqP // eqWi. apply/eqP/socle_rsimP. apply: mx_rsim_trans (rsim_irr_comp_pchar iG C'G (socle_irr _)) (mx_rsim_sym _). by rewrite [irr_comp _ _]eqWi; apply: rsim_irr_comp_pchar (socle_irr _). have bij_irr: {on [pred i | soc i], bijective standard_irr}. exists (odflt W0 \o soc) => [Wi _ | i]; first by rewrite /= irrK. by rewrite inE /soc /=; case: pickP => //= Wi; move/eqP. rewrite !(reindex standard_irr) {bij_irr}//=. have all_soc Wi: soc (standard_irr Wi) by rewrite irrK. rewrite (eq_bigr val) => [|Wi _]; last by rewrite /W irrK. rewrite !(eq_bigl _ _ all_soc); split=> //. rewrite (eq_bigr (mxrank \o val)) => [|Wi _]; last by rewrite /W irrK. by rewrite -mxdirectE /= Socle_direct. pose modW i : mxmodule rG (W i) := if soc i is Some Wi as oWi return mxmodule rG (oapp val 0 oWi) then component_mx_module rG (socle_base Wi) else mxmodule0 rG n. apply: mx_rsim_trans (mx_rsim_sym (rsim_submod1 (mxmodule1 rG) _)) _ => //. apply: mx_rsim_dsum (modW) _ defS dxS _ => i. rewrite /W /standard_irr_coef /modW /soc; case: pickP => [Wi|_] /=; last first. rewrite /muln_grepr big_ord0. by exists 0 => [||x _]; rewrite /row_free ?mxrank0 ?mulmx0 ?mul0mx. move/eqP=> <-; apply: mx_rsim_socle. exact: rsim_irr_comp_pchar (socle_irr Wi). Qed. End StandardRepr. Definition cfReg (B : {set gT}) : 'CF(B) := #|B|%:R *: '1_[1]. Lemma cfRegE x : @cfReg G x = #|G|%:R *+ (x == 1%g). Proof. by rewrite cfunE cfuniE ?normal1 // inE mulr_natr. Qed. (* This is Isaacs, Lemma (2.10). *) Lemma cfReprReg : cfRepr (regular_repr algC G) = cfReg G. Proof. apply/cfun_inP=> x Gx; rewrite cfRegE. have [-> | ntx] := eqVneq x 1%g; first by rewrite cfRepr1. rewrite cfunE Gx [\tr _]big1 // => i _; rewrite 2!mxE /=. rewrite -(inj_eq enum_val_inj) gring_indexK ?groupM ?enum_valP //. by rewrite eq_mulVg1 mulKg (negbTE ntx). Qed. Definition xcfun (chi : 'CF(G)) A := (gring_row A *m (\col_(i < #|G|) chi (enum_val i))) 0 0. Lemma xcfun_is_zmod_morphism phi : zmod_morphism (xcfun phi). Proof. by move=> A B; rewrite /xcfun [gring_row _]linearB mulmxBl !mxE. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `xcfun_is_zmod_morphism` instead")] Definition xcfun_is_additive := xcfun_is_zmod_morphism. HB.instance Definition _ phi := GRing.isZmodMorphism.Build 'M_(gcard G) _ (xcfun phi) (xcfun_is_zmod_morphism phi). Lemma xcfunZr a phi A : xcfun phi (a *: A) = a * xcfun phi A. Proof. by rewrite /xcfun linearZ -scalemxAl mxE. Qed. (* In order to add a second canonical structure on xcfun *) Definition xcfun_r A phi := xcfun phi A. Arguments xcfun_r A phi /. Lemma xcfun_rE A chi : xcfun_r A chi = xcfun chi A. Proof. by []. Qed. Fact xcfun_r_is_zmod_morphism A : zmod_morphism (xcfun_r A). Proof. move=> phi psi; rewrite /= /xcfun !mxE -sumrB; apply: eq_bigr => i _. by rewrite !mxE !cfunE mulrBr. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `xcfun_r_is_zmod_morphism` instead")] Definition xcfun_r_is_additive := xcfun_r_is_zmod_morphism. HB.instance Definition _ A := GRing.isZmodMorphism.Build _ _ (xcfun_r A) (xcfun_r_is_zmod_morphism A). Lemma xcfunZl a phi A : xcfun (a *: phi) A = a * xcfun phi A. Proof. rewrite /xcfun !mxE big_distrr; apply: eq_bigr => i _ /=. by rewrite !mxE cfunE mulrCA. Qed. Lemma xcfun_repr n rG A : xcfun (@cfRepr n rG) A = \tr (gring_op rG A). Proof. rewrite gring_opE [gring_row A]row_sum_delta !linear_sum /xcfun !mxE. apply: eq_bigr => i _; rewrite !mxE /= !linearZ cfunE enum_valP /=. by congr (_ * \tr _); rewrite {A}/gring_mx /= -rowE rowK mxvecK. Qed. End Char. Arguments xcfun_r {_ _} A phi /. Notation "phi .[ A ]" := (xcfun phi A) : cfun_scope. Definition pred_Nirr gT B := #|@classes gT B|.-1. Arguments pred_Nirr {gT} B%_g. Notation Nirr G := (pred_Nirr G).+1. Notation Iirr G := 'I_(Nirr G). Section IrrClassDef. Variables (gT : finGroupType) (G : {group gT}). Let sG := DecSocleType (regular_repr algC G). Lemma NirrE : Nirr G = #|classes G|. Proof. by rewrite /pred_Nirr (cardD1 [1]) classes1. Qed. Fact Iirr_cast : Nirr G = #|sG|. Proof. by rewrite NirrE ?card_irr_pchar ?algC'G_pchar //; apply: groupC. Qed. Let offset := cast_ord (esym Iirr_cast) (enum_rank [1 sG]%irr). Definition socle_of_Iirr (i : Iirr G) : sG := enum_val (cast_ord Iirr_cast (i + offset)). Definition irr_of_socle (Wi : sG) : Iirr G := cast_ord (esym Iirr_cast) (enum_rank Wi) - offset. Local Notation W := socle_of_Iirr. Lemma socle_Iirr0 : W 0 = [1 sG]%irr. Proof. by rewrite /W add0r cast_ordKV enum_rankK. Qed. Lemma socle_of_IirrK : cancel W irr_of_socle. Proof. by move=> i; rewrite /irr_of_socle enum_valK cast_ordK addrK. Qed. Lemma irr_of_socleK : cancel irr_of_socle W. Proof. by move=> Wi; rewrite /W subrK cast_ordKV enum_rankK. Qed. Hint Resolve socle_of_IirrK irr_of_socleK : core. Lemma irr_of_socle_bij (A : {pred (Iirr G)}) : {on A, bijective irr_of_socle}. Proof. by apply: onW_bij; exists W. Qed. Lemma socle_of_Iirr_bij (A : {pred sG}) : {on A, bijective W}. Proof. by apply: onW_bij; exists irr_of_socle. Qed. End IrrClassDef. Prenex Implicits socle_of_IirrK irr_of_socleK. Arguments socle_of_Iirr {gT G%_G} i%_R. Notation "''Chi_' i" := (irr_repr (socle_of_Iirr i)) (at level 8, i at level 2, format "''Chi_' i"). HB.lock Definition irr gT B : (Nirr B).-tuple 'CF(B) := let irr_of i := 'Res[B, <<B>>] (@cfRepr gT _ _ 'Chi_(inord i)) in [tuple of mkseq irr_of (Nirr B)]. Arguments irr {gT} B%_g. Notation "''chi_' i" := (tnth (irr _) i%R) (at level 8, i at level 2, format "''chi_' i") : ring_scope. Notation "''chi[' G ]_ i" := (tnth (irr G) i%R) (at level 8, i at level 2, only parsing) : ring_scope. Section IrrClass. Variable (gT : finGroupType) (G : {group gT}). Implicit Types (i : Iirr G) (B : {set gT}). Open Scope group_ring_scope. Lemma congr_irr i1 i2 : i1 = i2 -> 'chi_i1 = 'chi_i2. Proof. by move->. Qed. Lemma Iirr1_neq0 : G :!=: 1%g -> inord 1 != 0 :> Iirr G. Proof. by rewrite -classes_gt1 -NirrE -val_eqE /= => /inordK->. Qed. Lemma has_nonprincipal_irr : G :!=: 1%g -> {i : Iirr G | i != 0}. Proof. by move/Iirr1_neq0; exists (inord 1). Qed. Lemma irrRepr i : cfRepr 'Chi_i = 'chi_i. Proof. rewrite irr.unlock (tnth_nth 0) nth_mkseq // -[<<G>>]/(gval _) genGidG. by rewrite cfRes_id inord_val. Qed. Lemma irr0 : 'chi[G]_0 = 1. Proof. apply/cfun_inP=> x Gx; rewrite -irrRepr cfun1E cfunE Gx. by rewrite socle_Iirr0 irr1_repr // mxtrace1 degree_irr1. Qed. Lemma cfun1_irr : 1 \in irr G. Proof. by rewrite -irr0 mem_tnth. Qed. Lemma mem_irr i : 'chi_i \in irr G. Proof. exact: mem_tnth. Qed. Lemma irrP xi : reflect (exists i, xi = 'chi_i) (xi \in irr G). Proof. apply: (iffP idP) => [/(nthP 0)[i] | [i ->]]; last exact: mem_irr. rewrite size_tuple => lt_i_G <-. by exists (Ordinal lt_i_G); rewrite (tnth_nth 0). Qed. Let sG := DecSocleType (regular_repr algC G). Let C'G := algC'G_pchar G. Let closG := @groupC _ G. Local Notation W i := (@socle_of_Iirr _ G i). Local Notation "''n_' i" := 'n_(W i). Local Notation "''R_' i" := 'R_(W i). Local Notation "''e_' i" := 'e_(W i). Lemma irr1_degree i : 'chi_i 1%g = ('n_i)%:R. Proof. by rewrite -irrRepr cfRepr1. Qed. Lemma Cnat_irr1 i : 'chi_i 1%g \in Num.nat. Proof. by rewrite irr1_degree rpred_nat. Qed. Lemma irr1_gt0 i : 0 < 'chi_i 1%g. Proof. by rewrite irr1_degree ltr0n irr_degree_gt0. Qed. Lemma irr1_neq0 i : 'chi_i 1%g != 0. Proof. by rewrite eq_le lt_geF ?irr1_gt0. Qed. Lemma irr_neq0 i : 'chi_i != 0. Proof. by apply: contraNneq (irr1_neq0 i) => ->; rewrite cfunE. Qed. Local Remark cfIirr_key : unit. Proof. by []. Qed. Definition cfIirr : forall B, 'CF(B) -> Iirr B := locked_with cfIirr_key (fun B chi => inord (index chi (irr B))). Lemma cfIirrE chi : chi \in irr G -> 'chi_(cfIirr chi) = chi. Proof. move=> chi_irr; rewrite (tnth_nth 0) [cfIirr]unlock inordK ?nth_index //. by rewrite -index_mem size_tuple in chi_irr. Qed. Lemma cfIirrPE J (f : J -> 'CF(G)) (P : pred J) : (forall j, P j -> f j \in irr G) -> forall j, P j -> 'chi_(cfIirr (f j)) = f j. Proof. by move=> irr_f j /irr_f; apply: cfIirrE. Qed. (* This is Isaacs, Corollary (2.7). *) Corollary irr_sum_square : \sum_i ('chi[G]_i 1%g) ^+ 2 = #|G|%:R. Proof. rewrite -(sum_irr_degree_pchar sG) // natr_sum. rewrite (reindex _ (socle_of_Iirr_bij _)) /=. by apply: eq_bigr => i _; rewrite irr1_degree natrX. Qed. (* This is Isaacs, Lemma (2.11). *) Lemma cfReg_sum : cfReg G = \sum_i 'chi_i 1%g *: 'chi_i. Proof. apply/cfun_inP=> x Gx. rewrite -cfReprReg cfunE Gx (mxtrace_regular_pchar sG) //=. rewrite sum_cfunE (reindex _ (socle_of_Iirr_bij _)); apply: eq_bigr => i _. by rewrite -irrRepr cfRepr1 !cfunE Gx mulr_natl. Qed. Let aG := regular_repr algC G. Let R_G := group_ring algC G. Lemma xcfun_annihilate i j A : i != j -> (A \in 'R_j)%MS -> ('chi_i).[A]%CF = 0. Proof. move=> neq_ij RjA; rewrite -irrRepr xcfun_repr. rewrite (irr_repr'_op0_pchar _ _ RjA) ?raddf0 //. by rewrite eq_sym (can_eq socle_of_IirrK). Qed. Lemma xcfunG phi x : x \in G -> phi.[aG x]%CF = phi x. Proof. by move=> Gx; rewrite /xcfun /gring_row rowK -rowE !mxE !(gring_indexK, mul1g). Qed. Lemma xcfun_mul_id i A : (A \in R_G)%MS -> ('chi_i).['e_i *m A]%CF = ('chi_i).[A]%CF. Proof. move=> RG_A; rewrite -irrRepr !xcfun_repr gring_opM //. by rewrite op_Wedderburn_id_pchar ?mul1mx. Qed. Lemma xcfun_id i j : ('chi_i).['e_j]%CF = 'chi_i 1%g *+ (i == j). Proof. have [<-{j} | /xcfun_annihilate->//] := eqVneq; last exact: Wedderburn_id_mem. by rewrite -xcfunG // repr_mx1 -(xcfun_mul_id _ (envelop_mx1 _)) mulmx1. Qed. Lemma irr_free : free (irr G). Proof. apply/freeP=> s s0 i; apply: (mulIf (irr1_neq0 i)). rewrite mul0r -(raddf0 (xcfun_r 'e_i)) -{}s0 raddf_sum /=. rewrite (bigD1 i)//= -tnth_nth xcfunZl xcfun_id eqxx big1 ?addr0 // => j ne_ji. by rewrite -tnth_nth xcfunZl xcfun_id (negbTE ne_ji) mulr0. Qed. Lemma irr_inj : injective (tnth (irr G)). Proof. by apply/injectiveP/free_uniq; rewrite map_tnth_enum irr_free. Qed. Lemma irrK : cancel (tnth (irr G)) (@cfIirr G). Proof. by move=> i; apply: irr_inj; rewrite cfIirrE ?mem_irr. Qed. Lemma irr_eq1 i : ('chi_i == 1) = (i == 0). Proof. by rewrite -irr0 (inj_eq irr_inj). Qed. Lemma cforder_irr_eq1 i : (#['chi_i]%CF == 1) = (i == 0). Proof. by rewrite -dvdn1 dvdn_cforder irr_eq1. Qed. Lemma irr_basis : basis_of 'CF(G)%VS (irr G). Proof. rewrite /basis_of irr_free andbT -dimv_leqif_eq ?subvf //. by rewrite dim_cfun (eqnP irr_free) size_tuple NirrE. Qed. Lemma eq_sum_nth_irr a : \sum_i a i *: 'chi[G]_i = \sum_i a i *: (irr G)`_i. Proof. by apply: eq_bigr => i; rewrite -tnth_nth. Qed. (* This is Isaacs, Theorem (2.8). *) Theorem cfun_irr_sum phi : {a | phi = \sum_i a i *: 'chi[G]_i}. Proof. rewrite (coord_basis irr_basis (memvf phi)) -eq_sum_nth_irr. by exists ((coord (irr G))^~ phi). Qed. Lemma cfRepr_standard n (rG : mx_representation algC G n) : cfRepr (standard_grepr rG) = \sum_i (standard_irr_coef rG (W i))%:R *: 'chi_i. Proof. rewrite cfRepr_dsum (reindex _ (socle_of_Iirr_bij _)). by apply: eq_bigr => i _; rewrite scaler_nat cfRepr_muln irrRepr. Qed. Lemma cfRepr_inj n1 n2 rG1 rG2 : @cfRepr _ G n1 rG1 = @cfRepr _ G n2 rG2 -> mx_rsim rG1 rG2. Proof. move=> eq_repr12; pose c i : algC := (standard_irr_coef _ (W i))%:R. have [rsim1 rsim2] := (mx_rsim_standard rG1, mx_rsim_standard rG2). apply: mx_rsim_trans (rsim1) (mx_rsim_sym _). suffices ->: standard_grepr rG1 = standard_grepr rG2 by []. apply: eq_bigr => Wi _; congr (muln_grepr _ _); apply/eqP; rewrite -eqC_nat. rewrite -[Wi]irr_of_socleK -!/(c _ _ _) -!(coord_sum_free (c _ _) _ irr_free). rewrite -!eq_sum_nth_irr -!cfRepr_standard. by rewrite -(cfRepr_sim rsim1) -(cfRepr_sim rsim2) eq_repr12. Qed. Lemma cfRepr_rsimP n1 n2 rG1 rG2 : reflect (mx_rsim rG1 rG2) (@cfRepr _ G n1 rG1 == @cfRepr _ G n2 rG2). Proof. by apply: (iffP eqP) => [/cfRepr_inj | /cfRepr_sim]. Qed. Lemma irr_reprP xi : reflect (exists2 rG : representation _ G, mx_irreducible rG & xi = cfRepr rG) (xi \in irr G). Proof. apply: (iffP (irrP xi)) => [[i ->] | [[n rG] irr_rG ->]]. by exists (Representation 'Chi_i); [apply: socle_irr | rewrite irrRepr]. exists (irr_of_socle (irr_comp sG rG)); rewrite -irrRepr irr_of_socleK /=. exact/cfRepr_sim/rsim_irr_comp_pchar. Qed. (* This is Isaacs, Theorem (2.12). *) Lemma Wedderburn_id_expansion i : 'e_i = #|G|%:R^-1 *: (\sum_(x in G) 'chi_i 1%g * 'chi_i x^-1%g *: aG x). Proof. have Rei: ('e_i \in 'R_i)%MS by apply: Wedderburn_id_mem. have /envelop_mxP[a def_e]: ('e_i \in R_G)%MS; last rewrite -/aG in def_e. by move: Rei; rewrite genmxE mem_sub_gring => /andP[]. apply: canRL (scalerK (neq0CG _)) _; rewrite def_e linear_sum /=. apply: eq_bigr => x Gx; have Gx' := groupVr Gx; rewrite scalerA; congr (_ *: _). transitivity (cfReg G).['e_i *m aG x^-1%g]%CF. rewrite def_e mulmx_suml raddf_sum (bigD1 x) //= -scalemxAl xcfunZr. rewrite -repr_mxM // mulgV xcfunG // cfRegE eqxx mulrC big1 ?addr0 //. move=> y /andP[Gy /negbTE neq_xy]; rewrite -scalemxAl xcfunZr -repr_mxM //. by rewrite xcfunG ?groupM // cfRegE -eq_mulgV1 neq_xy mulr0. rewrite cfReg_sum -xcfun_rE raddf_sum /= (bigD1 i) //= xcfunZl. rewrite xcfun_mul_id ?envelop_mx_id ?xcfunG ?groupV ?big1 ?addr0 // => j ne_ji. rewrite xcfunZl (xcfun_annihilate ne_ji) ?mulr0 //. have /andP[_ /(submx_trans _)-> //] := Wedderburn_ideal (W i). by rewrite mem_mulsmx // envelop_mx_id ?groupV. Qed. End IrrClass. Arguments cfReg {gT} B%_g. Prenex Implicits cfIirr irrK. Arguments irrP {gT G xi}. Arguments irr_reprP {gT G xi}. Arguments irr_inj {gT G} [x1 x2]. Section IsChar. Variable gT : finGroupType. Definition character_pred {G : {set gT}} := fun phi : 'CF(G) => [forall i, coord (irr G) i phi \in Num.nat]. Arguments character_pred _ _ /. Definition character {G : {set gT}} := [qualify a phi | @character_pred G phi]. Variable G : {group gT}. Implicit Types (phi chi xi : 'CF(G)) (i : Iirr G). Lemma irr_char i : 'chi_i \is a character. Proof. by apply/forallP=> j; rewrite (tnth_nth 0) coord_free ?irr_free. Qed. Lemma cfun1_char : (1 : 'CF(G)) \is a character. Proof. by rewrite -irr0 irr_char. Qed. Lemma cfun0_char : (0 : 'CF(G)) \is a character. Proof. by apply/forallP=> i; rewrite linear0 rpred0. Qed. Fact add_char : addr_closed (@character G). Proof. split=> [|chi xi /forallP-Nchi /forallP-Nxi]; first exact: cfun0_char. by apply/forallP=> i; rewrite linearD rpredD /=. Qed. HB.instance Definition _ := GRing.isAddClosed.Build (classfun G) character_pred add_char. Lemma char_sum_irrP {phi} : reflect (exists n, phi = \sum_i (n i)%:R *: 'chi_i) (phi \is a character). Proof. apply: (iffP idP)=> [/forallP-Nphi | [n ->]]; last first. by apply: rpred_sum => i _; rewrite scaler_nat rpredMn // irr_char. do [have [a ->] := cfun_irr_sum phi] in Nphi *; exists (Num.truncn \o a). apply: eq_bigr => i _; congr (_ *: _); have:= eqP (Nphi i). by rewrite eq_sum_nth_irr coord_sum_free ?irr_free. Qed. Lemma char_sum_irr chi : chi \is a character -> {r | chi = \sum_(i <- r) 'chi_i}. Proof. move=> Nchi; apply: sig_eqW; case/char_sum_irrP: Nchi => n {chi}->. elim/big_rec: _ => [|i _ _ [r ->]]; first by exists nil; rewrite big_nil. exists (ncons (n i) i r); rewrite scaler_nat. by elim: {n}(n i) => [|n IHn]; rewrite ?add0r //= big_cons mulrS -addrA IHn. Qed. Lemma Cnat_char1 chi : chi \is a character -> chi 1%g \in Num.nat. Proof. case/char_sum_irr=> r ->{chi}. by elim/big_rec: _ => [|i chi _ Nchi1]; rewrite cfunE ?rpredD // Cnat_irr1. Qed. Lemma char1_ge0 chi : chi \is a character -> 0 <= chi 1%g. Proof. by move/Cnat_char1/natr_ge0. Qed. Lemma char1_eq0 chi : chi \is a character -> (chi 1%g == 0) = (chi == 0). Proof. case/char_sum_irr=> r ->; apply/idP/idP=> [|/eqP->]; last by rewrite cfunE. case: r => [|i r]; rewrite ?big_nil // sum_cfunE big_cons. rewrite paddr_eq0 ?sumr_ge0 => // [||j _]; rewrite 1?ltW ?irr1_gt0 //. by rewrite (negbTE (irr1_neq0 i)). Qed. Lemma char1_gt0 chi : chi \is a character -> (0 < chi 1%g) = (chi != 0). Proof. by move=> Nchi; rewrite -char1_eq0 // natr_gt0 ?Cnat_char1. Qed. Lemma char_reprP phi : reflect (exists rG : representation algC G, phi = cfRepr rG) (phi \is a character). Proof. apply: (iffP char_sum_irrP) => [[n ->] | [[n rG] ->]]; last first. exists (fun i => standard_irr_coef rG (socle_of_Iirr i)). by rewrite -cfRepr_standard (cfRepr_sim (mx_rsim_standard rG)). exists (\big[dadd_grepr/grepr0]_i muln_grepr (Representation 'Chi_i) (n i)). rewrite cfRepr_dsum; apply: eq_bigr => i _. by rewrite cfRepr_muln irrRepr scaler_nat. Qed. Local Notation reprG := (mx_representation algC G). Lemma cfRepr_char n (rG : reprG n) : cfRepr rG \is a character. Proof. by apply/char_reprP; exists (Representation rG). Qed. Lemma cfReg_char : cfReg G \is a character. Proof. by rewrite -cfReprReg cfRepr_char. Qed. Lemma cfRepr_prod n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : cfRepr rG1 * cfRepr rG2 = cfRepr (prod_repr rG1 rG2). Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE /= Gx mxtrace_prod. Qed. Lemma mul_char : mulr_closed (@character G). Proof. split=> [|_ _ /char_reprP[rG1 ->] /char_reprP[rG2 ->]]; first exact: cfun1_char. apply/char_reprP; exists (Representation (prod_repr rG1 rG2)). by rewrite cfRepr_prod. Qed. HB.instance Definition _ := GRing.isMulClosed.Build (classfun G) character_pred mul_char. End IsChar. Prenex Implicits character. Arguments character_pred _ _ _ /. Arguments char_reprP {gT G phi}. Section AutChar. Variables (gT : finGroupType) (G : {group gT}). Implicit Type u : {rmorphism algC -> algC}. Implicit Type chi : 'CF(G). Lemma cfRepr_map u n (rG : mx_representation algC G n) : cfRepr (map_repr u rG) = cfAut u (cfRepr rG). Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx map_reprE trace_map_mx. Qed. Lemma cfAut_char u chi : (cfAut u chi \is a character) = (chi \is a character). Proof. without loss /char_reprP[rG ->]: u chi / chi \is a character. by move=> IHu; apply/idP/idP=> ?; first rewrite -(cfAutK u chi); rewrite IHu. rewrite cfRepr_char; apply/char_reprP. by exists (Representation (map_repr u rG)); rewrite cfRepr_map. Qed. Lemma cfConjC_char chi : (chi^*%CF \is a character) = (chi \is a character). Proof. exact: cfAut_char. Qed. Lemma cfAut_char1 u (chi : 'CF(G)) : chi \is a character -> cfAut u chi 1%g = chi 1%g. Proof. by move/Cnat_char1=> Nchi1; rewrite cfunE /= aut_natr. Qed. Lemma cfAut_irr1 u i : (cfAut u 'chi[G]_i) 1%g = 'chi_i 1%g. Proof. exact: cfAut_char1 (irr_char i). Qed. Lemma cfConjC_char1 (chi : 'CF(G)) : chi \is a character -> chi^*%CF 1%g = chi 1%g. Proof. exact: cfAut_char1. Qed. Lemma cfConjC_irr1 u i : ('chi[G]_i)^*%CF 1%g = 'chi_i 1%g. Proof. exact: cfAut_irr1. Qed. End AutChar. Section Linear. Variables (gT : finGroupType) (G : {group gT}). Definition linear_char_pred {B : {set gT}} := fun phi : 'CF(B) => (phi \is a character) && (phi 1%g == 1). Arguments linear_char_pred _ _ /. Definition linear_char {B : {set gT}} := [qualify a phi | @linear_char_pred B phi]. Section OneChar. Variable xi : 'CF(G). Hypothesis CFxi : xi \is a linear_char. Lemma lin_char1: xi 1%g = 1. Proof. by case/andP: CFxi => _ /eqP. Qed. Lemma lin_charW : xi \is a character. Proof. by case/andP: CFxi. Qed. Lemma cfun1_lin_char : (1 : 'CF(G)) \is a linear_char. Proof. by rewrite qualifE/= cfun1_char /= cfun11. Qed. Lemma lin_charM : {in G &, {morph xi : x y / (x * y)%g >-> x * y}}. Proof. move=> x y Gx Gy; case/andP: CFxi => /char_reprP[[n rG] -> /=]. rewrite cfRepr1 pnatr_eq1 => /eqP n1; rewrite {n}n1 in rG *. rewrite !cfunE Gx Gy groupM //= !mulr1n repr_mxM //. by rewrite [rG x]mx11_scalar [rG y]mx11_scalar -scalar_mxM !mxtrace_scalar. Qed. Lemma lin_char_prod I r (P : pred I) (x : I -> gT) : (forall i, P i -> x i \in G) -> xi (\prod_(i <- r | P i) x i)%g = \prod_(i <- r | P i) xi (x i). Proof. move=> Gx; elim/(big_load (fun y => y \in G)): _. elim/big_rec2: _ => [|i a y Pi [Gy <-]]; first by rewrite lin_char1. by rewrite groupM ?lin_charM ?Gx. Qed. Let xiMV x : x \in G -> xi x * xi (x^-1)%g = 1. Proof. by move=> Gx; rewrite -lin_charM ?groupV // mulgV lin_char1. Qed. Lemma lin_char_neq0 x : x \in G -> xi x != 0. Proof. by move/xiMV/(congr1 (predC1 0)); rewrite /= oner_eq0 mulf_eq0 => /norP[]. Qed. Lemma lin_charV x : x \in G -> xi x^-1%g = (xi x)^-1. Proof. by move=> Gx; rewrite -[_^-1]mulr1 -(xiMV Gx) mulKf ?lin_char_neq0. Qed. Lemma lin_charX x n : x \in G -> xi (x ^+ n)%g = xi x ^+ n. Proof. move=> Gx; elim: n => [|n IHn]; first exact: lin_char1. by rewrite expgS exprS lin_charM ?groupX ?IHn. Qed. Lemma lin_char_unity_root x : x \in G -> xi x ^+ #[x] = 1. Proof. by move=> Gx; rewrite -lin_charX // expg_order lin_char1. Qed. Lemma normC_lin_char x : x \in G -> `|xi x| = 1. Proof. move=> Gx; apply/eqP; rewrite -(@pexpr_eq1 _ _ #[x]) //. by rewrite -normrX // lin_char_unity_root ?normr1. Qed. Lemma lin_charV_conj x : x \in G -> xi x^-1%g = (xi x)^*. Proof. move=> Gx; rewrite lin_charV // invC_norm mulrC normC_lin_char //. by rewrite expr1n divr1. Qed. Lemma lin_char_irr : xi \in irr G. Proof. case/andP: CFxi => /char_reprP[rG ->]; rewrite cfRepr1 pnatr_eq1 => /eqP n1. by apply/irr_reprP; exists rG => //; apply/mx_abs_irrW/linear_mx_abs_irr. Qed. Lemma mul_conjC_lin_char : xi * xi^*%CF = 1. Proof. apply/cfun_inP=> x Gx. by rewrite !cfunE cfun1E Gx -normCK normC_lin_char ?expr1n. Qed. Lemma lin_char_unitr : xi \in GRing.unit. Proof. by apply/unitrPr; exists xi^*%CF; apply: mul_conjC_lin_char. Qed. Lemma invr_lin_char : xi^-1 = xi^*%CF. Proof. by rewrite -[_^-1]mulr1 -mul_conjC_lin_char mulKr ?lin_char_unitr. Qed. Lemma fful_lin_char_inj : cfaithful xi -> {in G &, injective xi}. Proof. move=> fful_phi x y Gx Gy xi_xy; apply/eqP; rewrite eq_mulgV1 -in_set1. rewrite (subsetP fful_phi) // inE groupM ?groupV //=; apply/forallP=> z. have [Gz | G'z] := boolP (z \in G); last by rewrite !cfun0 ?groupMl ?groupV. by rewrite -mulgA lin_charM ?xi_xy -?lin_charM ?groupM ?groupV // mulKVg. Qed. End OneChar. Lemma cfAut_lin_char u (xi : 'CF(G)) : (cfAut u xi \is a linear_char) = (xi \is a linear_char). Proof. by rewrite qualifE/= cfAut_char; apply/andb_id2l=> /cfAut_char1->. Qed. Lemma cfConjC_lin_char (xi : 'CF(G)) : (xi^*%CF \is a linear_char) = (xi \is a linear_char). Proof. exact: cfAut_lin_char. Qed. Lemma card_Iirr_abelian : abelian G -> #|Iirr G| = #|G|. Proof. by rewrite card_ord NirrE card_classes_abelian => /eqP. Qed. Lemma card_Iirr_cyclic : cyclic G -> #|Iirr G| = #|G|. Proof. by move/cyclic_abelian/card_Iirr_abelian. Qed. Lemma char_abelianP : reflect (forall i : Iirr G, 'chi_i \is a linear_char) (abelian G). Proof. apply: (iffP idP) => [cGG i | CF_G]. rewrite qualifE/= irr_char /= irr1_degree. by rewrite irr_degree_abelian //; last apply: groupC. rewrite card_classes_abelian -NirrE -eqC_nat -irr_sum_square //. rewrite -{1}[Nirr G]card_ord -sumr_const; apply/eqP/eq_bigr=> i _. by rewrite lin_char1 ?expr1n ?CF_G. Qed. Lemma irr_repr_lin_char (i : Iirr G) x : x \in G -> 'chi_i \is a linear_char -> irr_repr (socle_of_Iirr i) x = ('chi_i x)%:M. Proof. move=> Gx CFi; rewrite -irrRepr cfunE Gx. move: (_ x); rewrite -[irr_degree _](@natrK algC) -irr1_degree lin_char1 //. by rewrite (natrK 1) => A; rewrite trace_mx11 -mx11_scalar. Qed. Fact linear_char_divr : divr_closed (@linear_char G). Proof. split=> [|chi xi Lchi Lxi]; first exact: cfun1_lin_char. rewrite invr_lin_char // qualifE/= cfunE. by rewrite rpredM ?lin_char1 ?mulr1 ?lin_charW //= cfConjC_lin_char. Qed. HB.instance Definition _ := GRing.isDivClosed.Build (classfun G) linear_char_pred linear_char_divr. Lemma irr_cyclic_lin i : cyclic G -> 'chi[G]_i \is a linear_char. Proof. by move/cyclic_abelian/char_abelianP. Qed. Lemma irr_prime_lin i : prime #|G| -> 'chi[G]_i \is a linear_char. Proof. by move/prime_cyclic/irr_cyclic_lin. Qed. End Linear. Prenex Implicits linear_char. Arguments linear_char_pred _ _ _ /. Section OrthogonalityRelations. Variables aT gT : finGroupType. (* This is Isaacs, Lemma (2.15) *) Lemma repr_rsim_diag (G : {group gT}) f (rG : mx_representation algC G f) x : x \in G -> let chi := cfRepr rG in exists e, [/\ (*a*) exists2 B, B \in unitmx & rG x = invmx B *m diag_mx e *m B, (*b*) (forall i, e 0 i ^+ #[x] = 1) /\ (forall i, `|e 0 i| = 1), (*c*) chi x = \sum_i e 0 i /\ `|chi x| <= chi 1%g & (*d*) chi x^-1%g = (chi x)^*]. Proof. move=> Gx; without loss cGG: G rG Gx / abelian G. have sXG: <[x]> \subset G by rewrite cycle_subG. move/(_ _ (subg_repr rG sXG) (cycle_id x) (cycle_abelian x)). by rewrite /= !cfunE !groupV Gx (cycle_id x) !group1. have [I U W simU W1 dxW]: mxsemisimple rG 1%:M. rewrite -(reducible_Socle1 (DecSocleType rG) (mx_Maschke_pchar _ (algC'G_pchar G))). exact: Socle_semisimple. have linU i: \rank (U i) = 1. by apply: mxsimple_abelian_linear cGG (simU i); apply: groupC. have castI: f = #|I|. by rewrite -(mxrank1 algC f) -W1 (eqnP dxW) /= -sum1_card; apply/eq_bigr. pose B := \matrix_j nz_row (U (enum_val (cast_ord castI j))). have rowU i: (nz_row (U i) :=: U i)%MS. apply/eqmxP; rewrite -(geq_leqif (mxrank_leqif_eq (nz_row_sub _))) linU. by rewrite lt0n mxrank_eq0 (nz_row_mxsimple (simU i)). have unitB: B \in unitmx. rewrite -row_full_unit -sub1mx -W1; apply/sumsmx_subP=> i _. pose j := cast_ord (esym castI) (enum_rank i). by rewrite (submx_trans _ (row_sub j B)) // rowK cast_ordKV enum_rankK rowU. pose e := \row_j row j (B *m rG x *m invmx B) 0 j. have rGx: rG x = invmx B *m diag_mx e *m B. rewrite -mulmxA; apply: canRL (mulKmx unitB) _. apply/row_matrixP=> j; rewrite 2!row_mul; set u := row j B. have /sub_rVP[a def_ux]: (u *m rG x <= u)%MS. rewrite /u rowK rowU (eqmxMr _ (rowU _)). exact: (mxmoduleP (mxsimple_module (simU _))). rewrite def_ux [u]rowE scalemxAl; congr (_ *m _). apply/rowP=> k; rewrite 5!mxE !row_mul def_ux [u]rowE scalemxAl mulmxK //. by rewrite !mxE !eqxx !mulr_natr eq_sym. have exp_e j: e 0 j ^+ #[x] = 1. suffices: (diag_mx e j j) ^+ #[x] = (B *m rG (x ^+ #[x])%g *m invmx B) j j. by rewrite expg_order repr_mx1 mulmx1 mulmxV // [e]lock !mxE eqxx. elim: #[x] => [|n IHn]; first by rewrite repr_mx1 mulmx1 mulmxV // !mxE eqxx. rewrite expgS repr_mxM ?groupX // {1}rGx -!mulmxA mulKVmx //. by rewrite mul_diag_mx mulmxA [M in _ = M]mxE -IHn exprS {1}mxE eqxx. have norm1_e j: `|e 0 j| = 1. by apply/eqP; rewrite -(@pexpr_eq1 _ _ #[x]) // -normrX exp_e normr1. exists e; split=> //; first by exists B. rewrite cfRepr1 !cfunE Gx rGx mxtrace_mulC mulKVmx // mxtrace_diag. split=> //=; apply: (le_trans (ler_norm_sum _ _ _)). by rewrite (eq_bigr _ (in1W norm1_e)) sumr_const card_ord lexx. rewrite !cfunE groupV !mulrb Gx rGx mxtrace_mulC mulKVmx //. rewrite -trace_map_mx map_diag_mx; set d' := diag_mx _. rewrite -[d'](mulKVmx unitB) mxtrace_mulC -[_ *m _](repr_mxK rG Gx) rGx. rewrite -!mulmxA mulKVmx // (mulmxA d'). suffices->: d' *m diag_mx e = 1%:M by rewrite mul1mx mulKmx. rewrite mulmx_diag -diag_const_mx; congr diag_mx; apply/rowP=> j. by rewrite [e]lock !mxE mulrC -normCK -lock norm1_e expr1n. Qed. Variables (A : {group aT}) (G : {group gT}). (* This is Isaacs, Lemma (2.15) (d). *) Lemma char_inv (chi : 'CF(G)) x : chi \is a character -> chi x^-1%g = (chi x)^*. Proof. case Gx: (x \in G); last by rewrite !cfun0 ?rmorph0 ?groupV ?Gx. by case/char_reprP=> rG ->; have [e [_ _ _]] := repr_rsim_diag rG Gx. Qed. Lemma irr_inv i x : 'chi[G]_i x^-1%g = ('chi_i x)^*. Proof. exact/char_inv/irr_char. Qed. (* This is Isaacs, Theorem (2.13). *) Theorem generalized_orthogonality_relation y (i j : Iirr G) : #|G|%:R^-1 * (\sum_(x in G) 'chi_i (x * y)%g * 'chi_j x^-1%g) = (i == j)%:R * ('chi_i y / 'chi_i 1%g). Proof. pose W := @socle_of_Iirr _ G; pose e k := Wedderburn_id (W k). pose aG := regular_repr algC G. have [Gy | notGy] := boolP (y \in G); last first. rewrite cfun0 // mul0r big1 ?mulr0 // => x Gx. by rewrite cfun0 ?groupMl ?mul0r. transitivity (('chi_i).[e j *m aG y]%CF / 'chi_j 1%g). rewrite [e j]Wedderburn_id_expansion -scalemxAl xcfunZr -mulrA; congr (_ * _). rewrite mulmx_suml raddf_sum big_distrl; apply: eq_bigr => x Gx /=. rewrite -scalemxAl xcfunZr -repr_mxM // xcfunG ?groupM // mulrAC mulrC. by congr (_ * _); rewrite mulrC mulKf ?irr1_neq0. rewrite mulr_natl mulrb; have [<-{j} | neq_ij] := eqVneq. by congr (_ / _); rewrite xcfun_mul_id ?envelop_mx_id ?xcfunG. rewrite (xcfun_annihilate neq_ij) ?mul0r //. case/andP: (Wedderburn_ideal (W j)) => _; apply: submx_trans. by rewrite mem_mulsmx ?Wedderburn_id_mem ?envelop_mx_id. Qed. (* This is Isaacs, Corollary (2.14). *) Corollary first_orthogonality_relation (i j : Iirr G) : #|G|%:R^-1 * (\sum_(x in G) 'chi_i x * 'chi_j x^-1%g) = (i == j)%:R. Proof. have:= generalized_orthogonality_relation 1 i j. rewrite mulrA mulfK ?irr1_neq0 // => <-; congr (_ * _). by apply: eq_bigr => x; rewrite mulg1. Qed. (* The character table. *) Definition irr_class i := enum_val (cast_ord (NirrE G) i). Definition class_Iirr xG := cast_ord (esym (NirrE G)) (enum_rank_in (classes1 G) xG). Local Notation c := irr_class. Local Notation g i := (repr (c i)). Local Notation iC := class_Iirr. Definition character_table := \matrix_(i, j) 'chi[G]_i (g j). Local Notation X := character_table. Lemma irr_classP i : c i \in classes G. Proof. exact: enum_valP. Qed. Lemma repr_irr_classK i : g i ^: G = c i. Proof. by case/repr_classesP: (irr_classP i). Qed. Lemma irr_classK : cancel c iC. Proof. by move=> i; rewrite /iC enum_valK_in cast_ordK. Qed. Lemma class_IirrK : {in classes G, cancel iC c}. Proof. by move=> xG GxG; rewrite /c cast_ordKV enum_rankK_in. Qed. Lemma reindex_irr_class R idx (op : @Monoid.com_law R idx) F : \big[op/idx]_(xG in classes G) F xG = \big[op/idx]_i F (c i). Proof. rewrite (reindex c); first by apply: eq_bigl => i; apply: enum_valP. by exists iC; [apply: in1W; apply: irr_classK | apply: class_IirrK]. Qed. (* The explicit value of the inverse is needed for the proof of the second *) (* orthogonality relation. *) Let X' := \matrix_(i, j) (#|'C_G[g i]|%:R^-1 * ('chi[G]_j (g i))^*). Let XX'_1: X *m X' = 1%:M. Proof. apply/matrixP=> i j; rewrite !mxE -first_orthogonality_relation mulr_sumr. rewrite sum_by_classes => [|u v Gu Gv]; last by rewrite -conjVg !cfunJ. rewrite reindex_irr_class /=; apply/esym/eq_bigr=> k _. rewrite !mxE irr_inv // -/(g k) -divg_index -indexgI /=. rewrite (pchar0_natf_div Cpchar) ?dvdn_indexg // index_cent1 invfM invrK. by rewrite repr_irr_classK mulrCA mulrA mulrCA. Qed. Lemma character_table_unit : X \in unitmx. Proof. by case/mulmx1_unit: XX'_1. Qed. Let uX := character_table_unit. (* This is Isaacs, Theorem (2.18). *) Theorem second_orthogonality_relation x y : y \in G -> \sum_i 'chi[G]_i x * ('chi_i y)^* = #|'C_G[x]|%:R *+ (x \in y ^: G). Proof. move=> Gy; pose i_x := iC (x ^: G); pose i_y := iC (y ^: G). have [Gx | notGx] := boolP (x \in G); last first. rewrite (contraNF (subsetP _ x) notGx) ?class_subG ?big1 // => i _. by rewrite cfun0 ?mul0r. transitivity ((#|'C_G[repr (y ^: G)]|%:R *: (X' *m X)) i_y i_x). rewrite scalemxAl !mxE; apply: eq_bigr => k _; rewrite !mxE mulrC -!mulrA. by rewrite !class_IirrK ?mem_classes // !cfun_repr mulVKf ?neq0CG. rewrite mulmx1C // !mxE -!divg_index; do 2!rewrite -indexgI index_cent1. rewrite (class_eqP (mem_repr y _)) ?class_refl // mulr_natr. rewrite (can_in_eq class_IirrK) ?mem_classes //. have [-> | not_yGx] := eqVneq; first by rewrite class_refl. by rewrite [x \in _](contraNF _ not_yGx) // => /class_eqP->. Qed. Lemma eq_irr_mem_classP x y : y \in G -> reflect (forall i, 'chi[G]_i x = 'chi_i y) (x \in y ^: G). Proof. move=> Gy; apply: (iffP idP) => [/imsetP[z Gz ->] i | xGy]; first exact: cfunJ. have Gx: x \in G. congr is_true: Gy; apply/eqP; rewrite -(can_eq oddb) -eqC_nat -!cfun1E. by rewrite -irr0 xGy. congr is_true: (class_refl G x); apply/eqP; rewrite -(can_eq oddb). rewrite -(eqn_pmul2l (cardG_gt0 'C_G[x])) -eqC_nat !mulrnA; apply/eqP. by rewrite -!second_orthogonality_relation //; apply/eq_bigr=> i _; rewrite xGy. Qed. (* This is Isaacs, Theorem (6.32) (due to Brauer). *) Lemma card_afix_irr_classes (ito : action A (Iirr G)) (cto : action A _) a : a \in A -> [acts A, on classes G | cto] -> (forall i x y, x \in G -> y \in cto (x ^: G) a -> 'chi_i x = 'chi_(ito i a) y) -> #|'Fix_ito[a]| = #|'Fix_(classes G | cto)[a]|. Proof. move=> Aa actsAG stabAchi; apply/eqP; rewrite -eqC_nat; apply/eqP. have [[cP cK] iCK] := (irr_classP, irr_classK, class_IirrK). pose icto b i := iC (cto (c i) b). have Gca i: cto (c i) a \in classes G by rewrite (acts_act actsAG). have inj_qa: injective (icto a). by apply: can_inj (icto a^-1%g) _ => i; rewrite /icto iCK ?actKin ?cK. pose Pa : 'M[algC]_(Nirr G) := perm_mx (actperm ito a). pose qa := perm inj_qa; pose Qa : 'M[algC]_(Nirr G) := perm_mx qa^-1^-1%g. transitivity (\tr Pa). rewrite -sumr_const big_mkcond; apply: eq_bigr => i _. by rewrite !mxE permE inE sub1set inE; case: ifP. symmetry; transitivity (\tr Qa). rewrite cardsE -sumr_const -big_filter_cond big_mkcond big_filter /=. rewrite reindex_irr_class; apply: eq_bigr => i _; rewrite !mxE invgK permE. by rewrite inE sub1set inE -(can_eq cK) iCK //; case: ifP. rewrite -[Pa](mulmxK uX) -[Qa](mulKmx uX) mxtrace_mulC; congr (\tr(_ *m _)). rewrite -row_permE -col_permE; apply/matrixP=> i j; rewrite !mxE. rewrite -{2}[j](permKV qa); move: {j}(_ j) => j; rewrite !permE iCK //. apply: stabAchi; first by case/repr_classesP: (cP j). by rewrite repr_irr_classK (mem_repr_classes (Gca _)). Qed. End OrthogonalityRelations. Prenex Implicits irr_class class_Iirr irr_classK. Arguments class_IirrK {gT G%_G} [xG%_g] GxG : rename. Arguments character_table {gT} G%_g. Section InnerProduct. Variable (gT : finGroupType) (G : {group gT}). Lemma cfdot_irr i j : '['chi_i, 'chi_j]_G = (i == j)%:R. Proof. rewrite -first_orthogonality_relation; congr (_ * _). by apply: eq_bigr => x Gx; rewrite irr_inv. Qed. Lemma cfnorm_irr i : '['chi[G]_i] = 1. Proof. by rewrite cfdot_irr eqxx. Qed. Lemma irr_orthonormal : orthonormal (irr G). Proof. apply/orthonormalP; split; first exact: free_uniq (irr_free G). move=> _ _ /irrP[i ->] /irrP[j ->]. by rewrite cfdot_irr (inj_eq irr_inj). Qed. Lemma coord_cfdot phi i : coord (irr G) i phi = '[phi, 'chi_i]. Proof. rewrite {2}(coord_basis (irr_basis G) (memvf phi)). rewrite cfdot_suml (bigD1 i) // cfdotZl /= -tnth_nth cfdot_irr eqxx mulr1. rewrite big1 ?addr0 // => j neq_ji; rewrite cfdotZl /= -tnth_nth cfdot_irr. by rewrite (negbTE neq_ji) mulr0. Qed. Lemma cfun_sum_cfdot phi : phi = \sum_i '[phi, 'chi_i]_G *: 'chi_i. Proof. rewrite {1}(coord_basis (irr_basis G) (memvf phi)). by apply: eq_bigr => i _; rewrite coord_cfdot -tnth_nth. Qed. Lemma cfdot_sum_irr phi psi : '[phi, psi]_G = \sum_i '[phi, 'chi_i] * '[psi, 'chi_i]^*. Proof. rewrite {1}[phi]cfun_sum_cfdot cfdot_suml; apply: eq_bigr => i _. by rewrite cfdotZl -cfdotC. Qed. Lemma Cnat_cfdot_char_irr i phi : phi \is a character -> '[phi, 'chi_i]_G \in Num.nat. Proof. by move/forallP/(_ i); rewrite coord_cfdot. Qed. Lemma cfdot_char_r phi chi : chi \is a character -> '[phi, chi]_G = \sum_i '[phi, 'chi_i] * '[chi, 'chi_i]. Proof. move=> Nchi; rewrite cfdot_sum_irr; apply: eq_bigr => i _; congr (_ * _). by rewrite conj_natr ?Cnat_cfdot_char_irr. Qed. Lemma Cnat_cfdot_char chi xi : chi \is a character -> xi \is a character -> '[chi, xi]_G \in Num.nat. Proof. move=> Nchi Nxi; rewrite cfdot_char_r ?rpred_sum // => i _. by rewrite rpredM ?Cnat_cfdot_char_irr. Qed. Lemma cfdotC_char chi xi : chi \is a character-> xi \is a character -> '[chi, xi]_G = '[xi, chi]. Proof. by move=> Nchi Nxi; rewrite cfdotC conj_natr ?Cnat_cfdot_char. Qed. Lemma irrEchar chi : (chi \in irr G) = (chi \is a character) && ('[chi] == 1). Proof. apply/irrP/andP=> [[i ->] | [Nchi]]; first by rewrite irr_char cfnorm_irr. rewrite cfdot_sum_irr => /eqP/natr_sum_eq1[i _| i [_ ci1 cj0]]. by rewrite rpredM // ?conj_natr ?Cnat_cfdot_char_irr. exists i; rewrite [chi]cfun_sum_cfdot (bigD1 i) //=. rewrite -(normr_idP (natr_ge0 (Cnat_cfdot_char_irr i Nchi))). rewrite normC_def {}ci1 sqrtC1 scale1r big1 ?addr0 // => j neq_ji. by rewrite (('[_] =P 0) _) ?scale0r // -normr_eq0 normC_def cj0 ?sqrtC0. Qed. Lemma irrWchar chi : chi \in irr G -> chi \is a character. Proof. by rewrite irrEchar => /andP[]. Qed. Lemma irrWnorm chi : chi \in irr G -> '[chi] = 1. Proof. by rewrite irrEchar => /andP[_ /eqP]. Qed. Lemma mul_lin_irr xi chi : xi \is a linear_char -> chi \in irr G -> xi * chi \in irr G. Proof. move=> Lxi; rewrite !irrEchar => /andP[Nphi /eqP <-]. rewrite rpredM // ?lin_charW //=; apply/eqP; congr (_ * _). apply: eq_bigr=> x Gx; rewrite !cfunE rmorphM/= mulrACA -(lin_charV_conj Lxi)//. by rewrite -lin_charM ?groupV // mulgV lin_char1 ?mul1r. Qed. Lemma eq_scaled_irr a b i j : (a *: 'chi[G]_i == b *: 'chi_j) = (a == b) && ((a == 0) || (i == j)). Proof. apply/eqP/andP=> [|[/eqP-> /pred2P[]-> //]]; last by rewrite !scale0r. move/(congr1 (cfdotr 'chi__)) => /= eq_ai_bj. move: {eq_ai_bj}(eq_ai_bj i) (esym (eq_ai_bj j)); rewrite !cfdotZl !cfdot_irr. by rewrite !mulr_natr !mulrb !eqxx eq_sym orbC; case: ifP => _ -> //= ->. Qed. Lemma eq_signed_irr (s t : bool) i j : ((-1) ^+ s *: 'chi[G]_i == (-1) ^+ t *: 'chi_j) = (s == t) && (i == j). Proof. by rewrite eq_scaled_irr signr_eq0 (inj_eq signr_inj). Qed. Lemma eq_scale_irr a (i j : Iirr G) : (a *: 'chi_i == a *: 'chi_j) = (a == 0) || (i == j). Proof. by rewrite eq_scaled_irr eqxx. Qed. Lemma eq_addZ_irr a b (i j r t : Iirr G) : (a *: 'chi_i + b *: 'chi_j == a *: 'chi_r + b *: 'chi_t) = [|| [&& (a == 0) || (i == r) & (b == 0) || (j == t)], [&& i == t, j == r & a == b] | [&& i == j, r == t & a == - b]]. Proof. rewrite -!eq_scale_irr; apply/eqP/idP; last first. case/orP; first by case/andP=> /eqP-> /eqP->. case/orP=> /and3P[/eqP-> /eqP-> /eqP->]; first by rewrite addrC. by rewrite !scaleNr !addNr. have [-> /addrI/eqP-> // | /=] := eqVneq. rewrite eq_scale_irr => /norP[/negP nz_a /negPf neq_ir]. move/(congr1 (cfdotr 'chi__))/esym/eqP => /= eq_cfdot. move: {eq_cfdot}(eq_cfdot i) (eq_cfdot r); rewrite eq_sym !cfdotDl !cfdotZl. rewrite !cfdot_irr !mulr_natr !mulrb !eqxx -!(eq_sym i) neq_ir !add0r. have [<- _ | _] := i =P t; first by rewrite neq_ir addr0; case: ifP => // _ ->. rewrite 2!fun_if if_arg addr0 addr_eq0; case: eqP => //= <- ->. by rewrite neq_ir 2!fun_if if_arg eq_sym addr0; case: ifP. Qed. Lemma eq_subZnat_irr (a b : nat) (i j r t : Iirr G) : (a%:R *: 'chi_i - b%:R *: 'chi_j == a%:R *: 'chi_r - b%:R *: 'chi_t) = [|| a == 0 | i == r] && [|| b == 0 | j == t] || [&& i == j, r == t & a == b]. Proof. rewrite -!scaleNr eq_addZ_irr oppr_eq0 opprK -addr_eq0 -natrD eqr_nat. by rewrite !pnatr_eq0 addn_eq0; case: a b => [|a] [|b]; rewrite ?andbF. Qed. End InnerProduct. Section IrrConstt. Variable (gT : finGroupType) (G H : {group gT}). Lemma char1_ge_norm (chi : 'CF(G)) x : chi \is a character -> `|chi x| <= chi 1%g. Proof. case/char_reprP=> rG ->; case Gx: (x \in G); last first. by rewrite cfunE cfRepr1 Gx normr0 ler0n. by have [e [_ _ []]] := repr_rsim_diag rG Gx. Qed. Lemma max_cfRepr_norm_scalar n (rG : mx_representation algC G n) x : x \in G -> `|cfRepr rG x| = cfRepr rG 1%g -> exists2 c, `|c| = 1 & rG x = c%:M. Proof. move=> Gx; have [e [[B uB def_x] [_ e1] [-> _] _]] := repr_rsim_diag rG Gx. rewrite cfRepr1 -[n in n%:R]card_ord -sumr_const -(eq_bigr _ (in1W e1)). case/normC_sum_eq1=> [i _ | c /eqP norm_c_1 def_e]; first by rewrite e1. have{} def_e: e = const_mx c by apply/rowP=> i; rewrite mxE def_e ?andbT. by exists c => //; rewrite def_x def_e diag_const_mx scalar_mxC mulmxKV. Qed. Lemma max_cfRepr_mx1 n (rG : mx_representation algC G n) x : x \in G -> cfRepr rG x = cfRepr rG 1%g -> rG x = 1%:M. Proof. move=> Gx kerGx; have [|c _ def_x] := @max_cfRepr_norm_scalar n rG x Gx. by rewrite kerGx cfRepr1 normr_nat. move/eqP: kerGx; rewrite cfRepr1 cfunE Gx {rG}def_x mxtrace_scalar. case: n => [_|n]; first by rewrite ![_%:M]flatmx0. rewrite mulrb -subr_eq0 -mulrnBl -mulr_natl mulf_eq0 pnatr_eq0 /=. by rewrite subr_eq0 => /eqP->. Qed. Definition irr_constt (B : {set gT}) phi := [pred i | '[phi, 'chi_i]_B != 0]. Lemma irr_consttE i phi : (i \in irr_constt phi) = ('[phi, 'chi_i]_G != 0). Proof. by []. Qed. Lemma constt_charP (i : Iirr G) chi : chi \is a character -> reflect (exists2 chi', chi' \is a character & chi = 'chi_i + chi') (i \in irr_constt chi). Proof. move=> Nchi; apply: (iffP idP) => [i_in_chi| [chi' Nchi' ->]]; last first. rewrite inE /= cfdotDl cfdot_irr eqxx -(eqP (Cnat_cfdot_char_irr i Nchi')). by rewrite -natrD pnatr_eq0. exists (chi - 'chi_i); last by rewrite addrC subrK. apply/forallP=> j; rewrite coord_cfdot cfdotBl cfdot_irr. have [<- | _] := eqP; last by rewrite subr0 Cnat_cfdot_char_irr. move: i_in_chi; rewrite inE; case/natrP: (Cnat_cfdot_char_irr i Nchi) => n ->. by rewrite pnatr_eq0 -lt0n => /natrB <-; apply: rpred_nat. Qed. Lemma cfun_sum_constt (phi : 'CF(G)) : phi = \sum_(i in irr_constt phi) '[phi, 'chi_i] *: 'chi_i. Proof. rewrite {1}[phi]cfun_sum_cfdot (bigID [pred i | '[phi, 'chi_i] == 0]) /=. by rewrite big1 ?add0r // => i /eqP->; rewrite scale0r. Qed. Lemma neq0_has_constt (phi : 'CF(G)) : phi != 0 -> exists i, i \in irr_constt phi. Proof. move=> nz_phi; apply/existsP; apply: contra nz_phi => /pred0P phi0. by rewrite [phi]cfun_sum_constt big_pred0. Qed. Lemma constt_irr i : irr_constt 'chi[G]_i =i pred1 i. Proof. by move=> j; rewrite !inE cfdot_irr pnatr_eq0 (eq_sym j); case: (i == j). Qed. Lemma char1_ge_constt (i : Iirr G) chi : chi \is a character -> i \in irr_constt chi -> 'chi_i 1%g <= chi 1%g. Proof. move=> {chi} _ /constt_charP[// | chi Nchi ->]. by rewrite cfunE addrC -subr_ge0 addrK char1_ge0. Qed. Lemma constt_ortho_char (phi psi : 'CF(G)) i j : phi \is a character -> psi \is a character -> i \in irr_constt phi -> j \in irr_constt psi -> '[phi, psi] = 0 -> '['chi_i, 'chi_j] = 0. Proof. move=> _ _ /constt_charP[//|phi1 Nphi1 ->] /constt_charP[//|psi1 Npsi1 ->]. rewrite cfdot_irr; case: eqP => // -> /eqP/idPn[]. rewrite cfdotDl !cfdotDr cfnorm_irr -addrA gt_eqF ?ltr_wpDr ?ltr01 //. by rewrite natr_ge0 ?rpredD ?Cnat_cfdot_char ?irr_char. Qed. End IrrConstt. Arguments irr_constt {gT B%_g} phi%_CF. Section Kernel. Variable (gT : finGroupType) (G : {group gT}). Implicit Types (phi chi xi : 'CF(G)) (H : {group gT}). Lemma cfker_repr n (rG : mx_representation algC G n) : cfker (cfRepr rG) = rker rG. Proof. apply/esym/setP=> x; rewrite inE mul1mx /=. case Gx: (x \in G); last by rewrite inE Gx. apply/eqP/idP=> Kx; last by rewrite max_cfRepr_mx1 // cfker1. rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !mulrb groupMl //. by case: ifP => // Gy; rewrite repr_mxM // Kx mul1mx. Qed. Lemma cfkerEchar chi : chi \is a character -> cfker chi = [set x in G | chi x == chi 1%g]. Proof. move=> Nchi; apply/setP=> x; apply/idP/setIdP=> [Kx | [Gx /eqP chi_x]]. by rewrite (subsetP (cfker_sub chi)) // cfker1. case/char_reprP: Nchi => rG -> in chi_x *; rewrite inE Gx; apply/forallP=> y. rewrite !cfunE groupMl // !mulrb; case: ifP => // Gy. by rewrite repr_mxM // max_cfRepr_mx1 ?mul1mx. Qed. Lemma cfker_nzcharE chi : chi \is a character -> chi != 0 -> cfker chi = [set x | chi x == chi 1%g]. Proof. move=> Nchi nzchi; apply/setP=> x; rewrite cfkerEchar // !inE andb_idl //. by apply: contraLR => /cfun0-> //; rewrite eq_sym char1_eq0. Qed. Lemma cfkerEirr i : cfker 'chi[G]_i = [set x | 'chi_i x == 'chi_i 1%g]. Proof. by rewrite cfker_nzcharE ?irr_char ?irr_neq0. Qed. Lemma cfker_irr0 : cfker 'chi[G]_0 = G. Proof. by rewrite irr0 cfker_cfun1. Qed. Lemma cfaithful_reg : cfaithful (cfReg G). Proof. apply/subsetP=> x; rewrite cfkerEchar ?cfReg_char // !inE !cfRegE eqxx. by case/andP=> _; apply: contraLR => /negbTE->; rewrite eq_sym neq0CG. Qed. Lemma cfkerE chi : chi \is a character -> cfker chi = G :&: \bigcap_(i in irr_constt chi) cfker 'chi_i. Proof. move=> Nchi; rewrite cfkerEchar //; apply/setP=> x; rewrite !inE. apply: andb_id2l => Gx; rewrite {1 2}[chi]cfun_sum_constt !sum_cfunE. apply/eqP/bigcapP=> [Kx i Ci | Kx]; last first. by apply: eq_bigr => i /Kx Kx_i; rewrite !cfunE cfker1. rewrite cfkerEirr inE /= -(inj_eq (mulfI Ci)). have:= (normC_sum_upper _ Kx) i; rewrite !cfunE => -> // {Ci}i _. have chi_i_ge0: 0 <= '[chi, 'chi_i]. by rewrite natr_ge0 ?Cnat_cfdot_char_irr. by rewrite !cfunE normrM (normr_idP _) ?ler_wpM2l ?char1_ge_norm ?irr_char. Qed. Lemma TI_cfker_irr : \bigcap_i cfker 'chi[G]_i = [1]. Proof. apply/trivgP; apply: subset_trans cfaithful_reg; rewrite cfkerE ?cfReg_char //. rewrite subsetI (bigcap_min 0) //=; last by rewrite cfker_irr0. by apply/bigcapsP=> i _; rewrite bigcap_inf. Qed. Lemma cfker_constt i chi : chi \is a character -> i \in irr_constt chi -> cfker chi \subset cfker 'chi[G]_i. Proof. by move=> Nchi Ci; rewrite cfkerE ?subIset ?(bigcap_min i) ?orbT. Qed. Section KerLin. Variable xi : 'CF(G). Hypothesis lin_xi : xi \is a linear_char. Let Nxi: xi \is a character. Proof. by have [] := andP lin_xi. Qed. Lemma lin_char_der1 : G^`(1)%g \subset cfker xi. Proof. rewrite gen_subG /=; apply/subsetP=> _ /imset2P[x y Gx Gy ->]. rewrite cfkerEchar // inE groupR //= !lin_charM ?lin_charV ?in_group //. by rewrite mulrCA mulKf ?mulVf ?lin_char_neq0 // lin_char1. Qed. Lemma cforder_lin_char : #[xi]%CF = exponent (G / cfker xi)%g. Proof. apply/eqP; rewrite eqn_dvd; apply/andP; split. apply/dvdn_cforderP=> x Gx; rewrite -lin_charX // -cfQuoEker ?groupX //. rewrite morphX ?(subsetP (cfker_norm xi)) //= expg_exponent ?mem_quotient //. by rewrite cfQuo1 ?cfker_normal ?lin_char1. have abGbar: abelian (G / cfker xi) := sub_der1_abelian lin_char_der1. have [_ /morphimP[x Nx Gx ->] ->] := exponent_witness (abelian_nil abGbar). rewrite order_dvdn -morphX //= coset_id cfkerEchar // !inE groupX //=. by rewrite lin_charX ?lin_char1 // (dvdn_cforderP _ _ _). Qed. Lemma cforder_lin_char_dvdG : #[xi]%CF %| #|G|. Proof. by rewrite cforder_lin_char (dvdn_trans (exponent_dvdn _)) ?dvdn_morphim. Qed. Lemma cforder_lin_char_gt0 : (0 < #[xi]%CF)%N. Proof. by rewrite cforder_lin_char exponent_gt0. Qed. End KerLin. End Kernel. Section Restrict. Variable (gT : finGroupType) (G H : {group gT}). Lemma cfRepr_sub n (rG : mx_representation algC G n) (sHG : H \subset G) : cfRepr (subg_repr rG sHG) = 'Res[H] (cfRepr rG). Proof. by apply/cfun_inP => x Hx; rewrite cfResE // !cfunE Hx (subsetP sHG). Qed. Lemma cfRes_char chi : chi \is a character -> 'Res[H, G] chi \is a character. Proof. have [sHG | not_sHG] := boolP (H \subset G). by case/char_reprP=> rG ->; rewrite -(cfRepr_sub rG sHG) cfRepr_char. by move/Cnat_char1=> Nchi1; rewrite cfResEout // rpredZ_nat ?rpred1. Qed. Lemma cfRes_eq0 phi : phi \is a character -> ('Res[H, G] phi == 0) = (phi == 0). Proof. by move=> Nchi; rewrite -!char1_eq0 ?cfRes_char // cfRes1. Qed. Lemma cfRes_lin_char chi : chi \is a linear_char -> 'Res[H, G] chi \is a linear_char. Proof. by case/andP=> Nchi; rewrite qualifE/= cfRes_char ?cfRes1. Qed. Lemma Res_irr_neq0 i : 'Res[H, G] 'chi_i != 0. Proof. by rewrite cfRes_eq0 ?irr_neq0 ?irr_char. Qed. Lemma cfRes_lin_lin (chi : 'CF(G)) : chi \is a character -> 'Res[H] chi \is a linear_char -> chi \is a linear_char. Proof. by rewrite !qualifE/= !qualifE/= cfRes1 => -> /andP[]. Qed. Lemma cfRes_irr_irr chi : chi \is a character -> 'Res[H] chi \in irr H -> chi \in irr G. Proof. have [sHG /char_reprP[rG ->] | not_sHG Nchi] := boolP (H \subset G). rewrite -(cfRepr_sub _ sHG) => /irr_reprP[rH irrH def_rH]; apply/irr_reprP. suffices /subg_mx_irr: mx_irreducible (subg_repr rG sHG) by exists rG. by apply: mx_rsim_irr irrH; apply/cfRepr_rsimP/eqP. rewrite cfResEout // => /irrP[j Dchi_j]; apply/lin_char_irr/cfRes_lin_lin=> //. suffices j0: j = 0 by rewrite cfResEout // Dchi_j j0 irr0 rpred1. apply: contraNeq (irr1_neq0 j) => nz_j. have:= xcfun_id j 0; rewrite -Dchi_j cfunE xcfunZl -irr0 xcfun_id eqxx => ->. by rewrite (negPf nz_j). Qed. Definition Res_Iirr (A B : {set gT}) i := cfIirr ('Res[B, A] 'chi_i). Lemma Res_Iirr0 : Res_Iirr H (0 : Iirr G) = 0. Proof. by rewrite /Res_Iirr irr0 rmorph1 -irr0 irrK. Qed. Lemma lin_Res_IirrE i : 'chi[G]_i 1%g = 1 -> 'chi_(Res_Iirr H i) = 'Res 'chi_i. Proof. move=> chi1; rewrite cfIirrE ?lin_char_irr ?cfRes_lin_char //. by rewrite qualifE/= irr_char /= chi1. Qed. End Restrict. Arguments Res_Iirr {gT A%_g} B%_g i%_R. Section MoreConstt. Variables (gT : finGroupType) (G H : {group gT}). Lemma constt_Ind_Res i j : i \in irr_constt ('Ind[G] 'chi_j) = (j \in irr_constt ('Res[H] 'chi_i)). Proof. by rewrite !irr_consttE cfdotC conjC_eq0 -cfdot_Res_l. Qed. Lemma cfdot_Res_ge_constt i j psi : psi \is a character -> j \in irr_constt psi -> '['Res[H, G] 'chi_j, 'chi_i] <= '['Res[H] psi, 'chi_i]. Proof. move=> {psi} _ /constt_charP[// | psi Npsi ->]. rewrite linearD cfdotDl addrC -subr_ge0 addrK natr_ge0 //=. by rewrite Cnat_cfdot_char_irr // cfRes_char. Qed. Lemma constt_Res_trans j psi : psi \is a character -> j \in irr_constt psi -> {subset irr_constt ('Res[H, G] 'chi_j) <= irr_constt ('Res[H] psi)}. Proof. move=> Npsi Cj i; apply: contraNneq; rewrite eq_le => {1}<-. rewrite cfdot_Res_ge_constt ?natr_ge0 ?Cnat_cfdot_char_irr //. by rewrite cfRes_char ?irr_char. Qed. End MoreConstt. Section Morphim. Variables (aT rT : finGroupType) (G D : {group aT}) (f : {morphism D >-> rT}). Implicit Type chi : 'CF(f @* G). Lemma cfRepr_morphim n (rfG : mx_representation algC (f @* G) n) sGD : cfRepr (morphim_repr rfG sGD) = cfMorph (cfRepr rfG). Proof. apply/cfun_inP=> x Gx; have Dx: x \in D := subsetP sGD x Gx. by rewrite cfMorphE // !cfunE ?mem_morphim ?Gx. Qed. Lemma cfMorph_char chi : chi \is a character -> cfMorph chi \is a character. Proof. have [sGD /char_reprP[rfG ->] | outGD Nchi] := boolP (G \subset D); last first. by rewrite cfMorphEout // rpredZ_nat ?rpred1 ?Cnat_char1. apply/char_reprP; exists (Representation (morphim_repr rfG sGD)). by rewrite cfRepr_morphim. Qed. Lemma cfMorph_lin_char chi : chi \is a linear_char -> cfMorph chi \is a linear_char. Proof. by case/andP=> Nchi; rewrite qualifE/= cfMorph1 cfMorph_char. Qed. Lemma cfMorph_charE chi : G \subset D -> (cfMorph chi \is a character) = (chi \is a character). Proof. move=> sGD; apply/idP/idP=> [/char_reprP[[n rG] /=Dfchi] | /cfMorph_char//]. pose H := 'ker_G f; have kerH: H \subset rker rG. by rewrite -cfker_repr -Dfchi cfker_morph // setIS // ker_sub_pre. have nHG: G \subset 'N(H) by rewrite normsI // (subset_trans sGD) ?ker_norm. have [h injh im_h] := first_isom_loc f sGD; rewrite -/H in h injh im_h. have DfG: invm injh @*^-1 (G / H) == (f @* G)%g by rewrite morphpre_invm im_h. pose rfG := eqg_repr (morphpre_repr _ (quo_repr kerH nHG)) DfG. apply/char_reprP; exists (Representation rfG). apply/cfun_inP=> _ /morphimP[x Dx Gx ->]; rewrite -cfMorphE // Dfchi !cfunE Gx. pose xH := coset H x; have GxH: xH \in (G / H)%g by apply: mem_quotient. suffices Dfx: f x = h xH by rewrite mem_morphim //= Dfx invmE ?quo_repr_coset. by apply/set1_inj; rewrite -?morphim_set1 ?im_h ?(subsetP nHG) ?sub1set. Qed. Lemma cfMorph_lin_charE chi : G \subset D -> (cfMorph chi \is a linear_char) = (chi \is a linear_char). Proof. by rewrite qualifE/= cfMorph1 => /cfMorph_charE->. Qed. Lemma cfMorph_irr chi : G \subset D -> (cfMorph chi \in irr G) = (chi \in irr (f @* G)). Proof. by move=> sGD; rewrite !irrEchar cfMorph_charE // cfMorph_iso. Qed. Definition morph_Iirr i := cfIirr (cfMorph 'chi[f @* G]_i). Lemma morph_Iirr0 : morph_Iirr 0 = 0. Proof. by rewrite /morph_Iirr irr0 rmorph1 -irr0 irrK. Qed. Hypothesis sGD : G \subset D. Lemma morph_IirrE i : 'chi_(morph_Iirr i) = cfMorph 'chi_i. Proof. by rewrite cfIirrE ?cfMorph_irr ?mem_irr. Qed. Lemma morph_Iirr_inj : injective morph_Iirr. Proof. by move=> i j eq_ij; apply/irr_inj/cfMorph_inj; rewrite // -!morph_IirrE eq_ij. Qed. Lemma morph_Iirr_eq0 i : (morph_Iirr i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 morph_IirrE cfMorph_eq1. Qed. End Morphim. Section Isom. Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}). Variables (R : {group rT}) (isoGR : isom G R f). Implicit Type chi : 'CF(G). Lemma cfIsom_char chi : (cfIsom isoGR chi \is a character) = (chi \is a character). Proof. rewrite [cfIsom _]locked_withE cfMorph_charE //. by rewrite (isom_im (isom_sym _)) cfRes_id. Qed. Lemma cfIsom_lin_char chi : (cfIsom isoGR chi \is a linear_char) = (chi \is a linear_char). Proof. by rewrite qualifE/= cfIsom_char cfIsom1. Qed. Lemma cfIsom_irr chi : (cfIsom isoGR chi \in irr R) = (chi \in irr G). Proof. by rewrite !irrEchar cfIsom_char cfIsom_iso. Qed. Definition isom_Iirr i := cfIirr (cfIsom isoGR 'chi_i). Lemma isom_IirrE i : 'chi_(isom_Iirr i) = cfIsom isoGR 'chi_i. Proof. by rewrite cfIirrE ?cfIsom_irr ?mem_irr. Qed. Lemma isom_Iirr_inj : injective isom_Iirr. Proof. by move=> i j eqij; apply/irr_inj/(cfIsom_inj isoGR); rewrite -!isom_IirrE eqij. Qed. Lemma isom_Iirr_eq0 i : (isom_Iirr i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 isom_IirrE cfIsom_eq1. Qed. Lemma isom_Iirr0 : isom_Iirr 0 = 0. Proof. by apply/eqP; rewrite isom_Iirr_eq0. Qed. End Isom. Arguments isom_Iirr_inj {aT rT G f R} isoGR [i1 i2] : rename. Section IsomInv. Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}). Variables (R : {group rT}) (isoGR : isom G R f). Lemma isom_IirrK : cancel (isom_Iirr isoGR) (isom_Iirr (isom_sym isoGR)). Proof. by move=> i; apply: irr_inj; rewrite !isom_IirrE cfIsomK. Qed. Lemma isom_IirrKV : cancel (isom_Iirr (isom_sym isoGR)) (isom_Iirr isoGR). Proof. by move=> i; apply: irr_inj; rewrite !isom_IirrE cfIsomKV. Qed. End IsomInv. Section Sdprod. Variables (gT : finGroupType) (K H G : {group gT}). Hypothesis defG : K ><| H = G. Let nKG: G \subset 'N(K). Proof. by have [/andP[]] := sdprod_context defG. Qed. Lemma cfSdprod_char chi : (cfSdprod defG chi \is a character) = (chi \is a character). Proof. by rewrite unlock cfMorph_charE // cfIsom_char. Qed. Lemma cfSdprod_lin_char chi : (cfSdprod defG chi \is a linear_char) = (chi \is a linear_char). Proof. by rewrite qualifE/= cfSdprod_char cfSdprod1. Qed. Lemma cfSdprod_irr chi : (cfSdprod defG chi \in irr G) = (chi \in irr H). Proof. by rewrite !irrEchar cfSdprod_char cfSdprod_iso. Qed. Definition sdprod_Iirr j := cfIirr (cfSdprod defG 'chi_j). Lemma sdprod_IirrE j : 'chi_(sdprod_Iirr j) = cfSdprod defG 'chi_j. Proof. by rewrite cfIirrE ?cfSdprod_irr ?mem_irr. Qed. Lemma sdprod_IirrK : cancel sdprod_Iirr (Res_Iirr H). Proof. by move=> j; rewrite /Res_Iirr sdprod_IirrE cfSdprodK irrK. Qed. Lemma sdprod_Iirr_inj : injective sdprod_Iirr. Proof. exact: can_inj sdprod_IirrK. Qed. Lemma sdprod_Iirr_eq0 i : (sdprod_Iirr i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 sdprod_IirrE cfSdprod_eq1. Qed. Lemma sdprod_Iirr0 : sdprod_Iirr 0 = 0. Proof. by apply/eqP; rewrite sdprod_Iirr_eq0. Qed. Lemma Res_sdprod_irr phi : K \subset cfker phi -> phi \in irr G -> 'Res phi \in irr H. Proof. move=> kerK /irrP[i Dphi]; rewrite irrEchar -(cfSdprod_iso defG). by rewrite cfRes_sdprodK // Dphi cfnorm_irr cfRes_char ?irr_char /=. Qed. Lemma sdprod_Res_IirrE i : K \subset cfker 'chi[G]_i -> 'chi_(Res_Iirr H i) = 'Res 'chi_i. Proof. by move=> kerK; rewrite cfIirrE ?Res_sdprod_irr ?mem_irr. Qed. Lemma sdprod_Res_IirrK i : K \subset cfker 'chi_i -> sdprod_Iirr (Res_Iirr H i) = i. Proof. by move=> kerK; rewrite /sdprod_Iirr sdprod_Res_IirrE ?cfRes_sdprodK ?irrK. Qed. End Sdprod. Arguments sdprod_Iirr_inj {gT K H G} defG [i1 i2] : rename. Section DProd. Variables (gT : finGroupType) (G K H : {group gT}). Hypothesis KxH : K \x H = G. Lemma cfDprodKl_abelian j : abelian H -> cancel ((cfDprod KxH)^~ 'chi_j) 'Res. Proof. by move=> cHH; apply: cfDprodKl; apply/lin_char1/char_abelianP. Qed. Lemma cfDprodKr_abelian i : abelian K -> cancel (cfDprod KxH 'chi_i) 'Res. Proof. by move=> cKK; apply: cfDprodKr; apply/lin_char1/char_abelianP. Qed. Lemma cfDprodl_char phi : (cfDprodl KxH phi \is a character) = (phi \is a character). Proof. exact: cfSdprod_char. Qed. Lemma cfDprodr_char psi : (cfDprodr KxH psi \is a character) = (psi \is a character). Proof. exact: cfSdprod_char. Qed. Lemma cfDprod_char phi psi : phi \is a character -> psi \is a character -> cfDprod KxH phi psi \is a character. Proof. by move=> Nphi Npsi; rewrite rpredM ?cfDprodl_char ?cfDprodr_char. Qed. Lemma cfDprod_eq1 phi psi : phi \is a character -> psi \is a character -> (cfDprod KxH phi psi == 1) = (phi == 1) && (psi == 1). Proof. move=> /Cnat_char1 Nphi /Cnat_char1 Npsi. apply/eqP/andP=> [phi_psi_1 | [/eqP-> /eqP->]]; last by rewrite cfDprod_cfun1. have /andP[/eqP phi1 /eqP psi1]: (phi 1%g == 1) && (psi 1%g == 1). by rewrite -natr_mul_eq1 // -(cfDprod1 KxH) phi_psi_1 cfun11. rewrite -[phi](cfDprodKl KxH psi1) -{2}[psi](cfDprodKr KxH phi1) phi_psi_1. by rewrite !rmorph1. Qed. Lemma cfDprodl_lin_char phi : (cfDprodl KxH phi \is a linear_char) = (phi \is a linear_char). Proof. exact: cfSdprod_lin_char. Qed. Lemma cfDprodr_lin_char psi : (cfDprodr KxH psi \is a linear_char) = (psi \is a linear_char). Proof. exact: cfSdprod_lin_char. Qed. Lemma cfDprod_lin_char phi psi : phi \is a linear_char -> psi \is a linear_char -> cfDprod KxH phi psi \is a linear_char. Proof. by move=> Nphi Npsi; rewrite rpredM ?cfSdprod_lin_char. Qed. Lemma cfDprodl_irr chi : (cfDprodl KxH chi \in irr G) = (chi \in irr K). Proof. exact: cfSdprod_irr. Qed. Lemma cfDprodr_irr chi : (cfDprodr KxH chi \in irr G) = (chi \in irr H). Proof. exact: cfSdprod_irr. Qed. Definition dprodl_Iirr i := cfIirr (cfDprodl KxH 'chi_i). Lemma dprodl_IirrE i : 'chi_(dprodl_Iirr i) = cfDprodl KxH 'chi_i. Proof. exact: sdprod_IirrE. Qed. Lemma dprodl_IirrK : cancel dprodl_Iirr (Res_Iirr K). Proof. exact: sdprod_IirrK. Qed. Lemma dprodl_Iirr_eq0 i : (dprodl_Iirr i == 0) = (i == 0). Proof. exact: sdprod_Iirr_eq0. Qed. Lemma dprodl_Iirr0 : dprodl_Iirr 0 = 0. Proof. exact: sdprod_Iirr0. Qed. Definition dprodr_Iirr j := cfIirr (cfDprodr KxH 'chi_j). Lemma dprodr_IirrE j : 'chi_(dprodr_Iirr j) = cfDprodr KxH 'chi_j. Proof. exact: sdprod_IirrE. Qed. Lemma dprodr_IirrK : cancel dprodr_Iirr (Res_Iirr H). Proof. exact: sdprod_IirrK. Qed. Lemma dprodr_Iirr_eq0 j : (dprodr_Iirr j == 0) = (j == 0). Proof. exact: sdprod_Iirr_eq0. Qed. Lemma dprodr_Iirr0 : dprodr_Iirr 0 = 0. Proof. exact: sdprod_Iirr0. Qed. Lemma cfDprod_irr i j : cfDprod KxH 'chi_i 'chi_j \in irr G. Proof. rewrite irrEchar cfDprod_char ?irr_char //=. by rewrite cfdot_dprod !cfdot_irr !eqxx mul1r. Qed. Definition dprod_Iirr ij := cfIirr (cfDprod KxH 'chi_ij.1 'chi_ij.2). Lemma dprod_IirrE i j : 'chi_(dprod_Iirr (i, j)) = cfDprod KxH 'chi_i 'chi_j. Proof. by rewrite cfIirrE ?cfDprod_irr. Qed. Lemma dprod_IirrEl i : 'chi_(dprod_Iirr (i, 0)) = cfDprodl KxH 'chi_i. Proof. by rewrite dprod_IirrE /cfDprod irr0 rmorph1 mulr1. Qed. Lemma dprod_IirrEr j : 'chi_(dprod_Iirr (0, j)) = cfDprodr KxH 'chi_j. Proof. by rewrite dprod_IirrE /cfDprod irr0 rmorph1 mul1r. Qed. Lemma dprod_Iirr_inj : injective dprod_Iirr. Proof. move=> [i1 j1] [i2 j2] /eqP; rewrite -[_ == _]oddb -(@natrK algC (_ == _)). rewrite -cfdot_irr !dprod_IirrE cfdot_dprod !cfdot_irr -natrM mulnb. by rewrite natrK oddb -xpair_eqE => /eqP. Qed. Lemma dprod_Iirr0 : dprod_Iirr (0, 0) = 0. Proof. by apply/irr_inj; rewrite dprod_IirrE !irr0 cfDprod_cfun1. Qed. Lemma dprod_Iirr0l j : dprod_Iirr (0, j) = dprodr_Iirr j. Proof. by apply/irr_inj; rewrite dprod_IirrE irr0 dprodr_IirrE cfDprod_cfun1l. Qed. Lemma dprod_Iirr0r i : dprod_Iirr (i, 0) = dprodl_Iirr i. Proof. by apply/irr_inj; rewrite dprod_IirrE irr0 dprodl_IirrE cfDprod_cfun1r. Qed. Lemma dprod_Iirr_eq0 i j : (dprod_Iirr (i, j) == 0) = (i == 0) && (j == 0). Proof. by rewrite -xpair_eqE -(inj_eq dprod_Iirr_inj) dprod_Iirr0. Qed. Lemma cfdot_dprod_irr i1 i2 j1 j2 : '['chi_(dprod_Iirr (i1, j1)), 'chi_(dprod_Iirr (i2, j2))] = ((i1 == i2) && (j1 == j2))%:R. Proof. by rewrite cfdot_irr (inj_eq dprod_Iirr_inj). Qed. Lemma dprod_Iirr_onto k : k \in codom dprod_Iirr. Proof. set D := codom _; have Df: dprod_Iirr _ \in D := codom_f dprod_Iirr _. have: 'chi_k 1%g ^+ 2 != 0 by rewrite mulf_neq0 ?irr1_neq0. apply: contraR => notDk; move/eqP: (irr_sum_square G). rewrite (bigID [in D]) (reindex _ (bij_on_codom dprod_Iirr_inj (0, 0))) /=. have ->: #|G|%:R = \sum_i \sum_j 'chi_(dprod_Iirr (i, j)) 1%g ^+ 2. rewrite -(dprod_card KxH) natrM. do 2![rewrite -irr_sum_square (mulr_suml, mulr_sumr); apply: eq_bigr => ? _]. by rewrite dprod_IirrE -exprMn -{3}(mulg1 1%g) cfDprodE. rewrite (eq_bigl _ _ Df) pair_bigA addrC -subr_eq0 addrK. by move/eqP/psumr_eq0P=> -> //= i _; rewrite irr1_degree -natrX ler0n. Qed. Definition inv_dprod_Iirr i := iinv (dprod_Iirr_onto i). Lemma dprod_IirrK : cancel dprod_Iirr inv_dprod_Iirr. Proof. by move=> p; apply: (iinv_f dprod_Iirr_inj). Qed. Lemma inv_dprod_IirrK : cancel inv_dprod_Iirr dprod_Iirr. Proof. by move=> i; apply: f_iinv. Qed. Lemma inv_dprod_Iirr0 : inv_dprod_Iirr 0 = (0, 0). Proof. by apply/(canLR dprod_IirrK); rewrite dprod_Iirr0. Qed. End DProd. Arguments dprod_Iirr_inj {gT G K H} KxH [i1 i2] : rename. Lemma dprod_IirrC (gT : finGroupType) (G K H : {group gT}) (KxH : K \x H = G) (HxK : H \x K = G) i j : dprod_Iirr KxH (i, j) = dprod_Iirr HxK (j, i). Proof. by apply: irr_inj; rewrite !dprod_IirrE; apply: cfDprodC. Qed. Section BigDprod. Variables (gT : finGroupType) (I : finType) (P : pred I). Variables (A : I -> {group gT}) (G : {group gT}). Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G. Let sAG i : P i -> A i \subset G. Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed. Lemma cfBigdprodi_char i (phi : 'CF(A i)) : phi \is a character -> cfBigdprodi defG phi \is a character. Proof. by move=> Nphi; rewrite cfDprodl_char cfRes_char. Qed. Lemma cfBigdprodi_charE i (phi : 'CF(A i)) : P i -> (cfBigdprodi defG phi \is a character) = (phi \is a character). Proof. by move=> Pi; rewrite cfDprodl_char Pi cfRes_id. Qed. Lemma cfBigdprod_char phi : (forall i, P i -> phi i \is a character) -> cfBigdprod defG phi \is a character. Proof. by move=> Nphi; apply: rpred_prod => i /Nphi; apply: cfBigdprodi_char. Qed. Lemma cfBigdprodi_lin_char i (phi : 'CF(A i)) : phi \is a linear_char -> cfBigdprodi defG phi \is a linear_char. Proof. by move=> Lphi; rewrite cfDprodl_lin_char ?cfRes_lin_char. Qed. Lemma cfBigdprodi_lin_charE i (phi : 'CF(A i)) : P i -> (cfBigdprodi defG phi \is a linear_char) = (phi \is a linear_char). Proof. by move=> Pi; rewrite qualifE/= cfBigdprodi_charE // cfBigdprodi1. Qed. Lemma cfBigdprod_lin_char phi : (forall i, P i -> phi i \is a linear_char) -> cfBigdprod defG phi \is a linear_char. Proof. by move=> Lphi; apply/rpred_prod=> i /Lphi; apply: cfBigdprodi_lin_char. Qed. Lemma cfBigdprodi_irr i chi : P i -> (cfBigdprodi defG chi \in irr G) = (chi \in irr (A i)). Proof. by move=> Pi; rewrite !irrEchar cfBigdprodi_charE ?cfBigdprodi_iso. Qed. Lemma cfBigdprod_irr chi : (forall i, P i -> chi i \in irr (A i)) -> cfBigdprod defG chi \in irr G. Proof. move=> Nchi; rewrite irrEchar cfBigdprod_char => [|i /Nchi/irrWchar] //=. by rewrite cfdot_bigdprod big1 // => i /Nchi/irrWnorm. Qed. Lemma cfBigdprod_eq1 phi : (forall i, P i -> phi i \is a character) -> (cfBigdprod defG phi == 1) = [forall (i | P i), phi i == 1]. Proof. move=> Nphi; set Phi := cfBigdprod defG phi. apply/eqP/eqfun_inP=> [Phi1 i Pi | phi1]; last first. by apply: big1 => i /phi1->; rewrite rmorph1. have Phi1_1: Phi 1%g = 1 by rewrite Phi1 cfun1E group1. have nz_Phi1: Phi 1%g != 0 by rewrite Phi1_1 oner_eq0. have [_ <-] := cfBigdprodK nz_Phi1 Pi. rewrite Phi1_1 divr1 -/Phi Phi1 rmorph1. rewrite prod_cfunE // in Phi1_1; have := natr_prod_eq1 _ Phi1_1 Pi. rewrite -(cfRes1 (A i)) cfBigdprodiK // => ->; first by rewrite scale1r. by move=> {i Pi} j /Nphi Nphi_j; rewrite Cnat_char1 ?cfBigdprodi_char. Qed. Lemma cfBigdprod_Res_lin chi : chi \is a linear_char -> cfBigdprod defG (fun i => 'Res[A i] chi) = chi. Proof. move=> Lchi; apply/cfun_inP=> _ /(mem_bigdprod defG)[x [Ax -> _]]. rewrite (lin_char_prod Lchi) ?cfBigdprodE // => [|i Pi]; last first. by rewrite (subsetP (sAG Pi)) ?Ax. by apply/eq_bigr=> i Pi; rewrite cfResE ?sAG ?Ax. Qed. Lemma cfBigdprodKlin phi : (forall i, P i -> phi i \is a linear_char) -> forall i, P i -> 'Res (cfBigdprod defG phi) = phi i. Proof. move=> Lphi i Pi; have Lpsi := cfBigdprod_lin_char Lphi. have [_ <-] := cfBigdprodK (lin_char_neq0 Lpsi (group1 G)) Pi. by rewrite !lin_char1 ?Lphi // divr1 scale1r. Qed. Lemma cfBigdprodKabelian Iphi (phi := fun i => 'chi_(Iphi i)) : abelian G -> forall i, P i -> 'Res (cfBigdprod defG phi) = 'chi_(Iphi i). Proof. move=> /(abelianS _) cGG. by apply: cfBigdprodKlin => i /sAG/cGG/char_abelianP->. Qed. End BigDprod. Section Aut. Variables (gT : finGroupType) (G : {group gT}). Implicit Type u : {rmorphism algC -> algC}. Lemma conjC_charAut u (chi : 'CF(G)) x : chi \is a character -> (u (chi x))^* = u (chi x)^*. Proof. have [Gx | /cfun0->] := boolP (x \in G); last by rewrite !rmorph0. case/char_reprP=> rG ->; have [e [_ [en1 _] [-> _] _]] := repr_rsim_diag rG Gx. by rewrite !rmorph_sum; apply: eq_bigr => i _; apply: aut_unity_rootC (en1 i). Qed. Lemma conjC_irrAut u i x : (u ('chi[G]_i x))^* = u ('chi_i x)^*. Proof. exact: conjC_charAut (irr_char i). Qed. Lemma cfdot_aut_char u (phi chi : 'CF(G)) : chi \is a character -> '[cfAut u phi, cfAut u chi] = u '[phi, chi]. Proof. by move/conjC_charAut=> Nchi; apply: cfdot_cfAut => _ /mapP[x _ ->]. Qed. Lemma cfdot_aut_irr u phi i : '[cfAut u phi, cfAut u 'chi[G]_i] = u '[phi, 'chi_i]. Proof. exact: cfdot_aut_char (irr_char i). Qed. Lemma cfAut_irr u chi : (cfAut u chi \in irr G) = (chi \in irr G). Proof. rewrite !irrEchar cfAut_char; apply/andb_id2l=> /cfdot_aut_char->. exact: fmorph_eq1. Qed. Lemma cfConjC_irr i : (('chi_i)^*)%CF \in irr G. Proof. by rewrite cfAut_irr mem_irr. Qed. Lemma irr_aut_closed u : cfAut_closed u (irr G). Proof. by move=> chi; rewrite /= cfAut_irr. Qed. Definition aut_Iirr u i := cfIirr (cfAut u 'chi[G]_i). Lemma aut_IirrE u i : 'chi_(aut_Iirr u i) = cfAut u 'chi_i. Proof. by rewrite cfIirrE ?cfAut_irr ?mem_irr. Qed. Definition conjC_Iirr := aut_Iirr conjC. Lemma conjC_IirrE i : 'chi[G]_(conjC_Iirr i) = ('chi_i)^*%CF. Proof. exact: aut_IirrE. Qed. Lemma conjC_IirrK : involutive conjC_Iirr. Proof. by move=> i; apply: irr_inj; rewrite !conjC_IirrE cfConjCK. Qed. Lemma aut_Iirr0 u : aut_Iirr u 0 = 0 :> Iirr G. Proof. by apply/irr_inj; rewrite aut_IirrE irr0 cfAut_cfun1. Qed. Lemma conjC_Iirr0 : conjC_Iirr 0 = 0 :> Iirr G. Proof. exact: aut_Iirr0. Qed. Lemma aut_Iirr_eq0 u i : (aut_Iirr u i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 aut_IirrE cfAut_eq1. Qed. Lemma conjC_Iirr_eq0 i : (conjC_Iirr i == 0 :> Iirr G) = (i == 0). Proof. exact: aut_Iirr_eq0. Qed. Lemma aut_Iirr_inj u : injective (aut_Iirr u). Proof. by move=> i j eq_ij; apply/irr_inj/(cfAut_inj u); rewrite -!aut_IirrE eq_ij. Qed. End Aut. Arguments aut_Iirr_inj {gT G} u [i1 i2] : rename. Arguments conjC_IirrK {gT G} i : rename. Section Coset. Variable (gT : finGroupType). Implicit Types G H : {group gT}. Lemma cfQuo_char G H (chi : 'CF(G)) : chi \is a character -> (chi / H)%CF \is a character. Proof. move=> Nchi; without loss kerH: / H \subset cfker chi. move/contraNF=> IHchi; apply/wlog_neg=> N'chiH. suffices ->: (chi / H)%CF = (chi 1%g)%:A. by rewrite rpredZ_nat ?Cnat_char1 ?rpred1. by apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr cfunElock IHchi. without loss nsHG: G chi Nchi kerH / H <| G. move=> IHchi; have nsHN := normalSG (subset_trans kerH (cfker_sub chi)). rewrite cfQuoInorm//; apply/cfRes_char/IHchi => //; first exact: cfRes_char. by apply: sub_cfker_Res => //; apply: normal_sub. have [rG Dchi] := char_reprP Nchi; rewrite Dchi cfker_repr in kerH. apply/char_reprP; exists (Representation (quo_repr kerH (normal_norm nsHG))). apply/cfun_inP=> _ /morphimP[x nHx Gx ->]; rewrite Dchi cfQuoE ?cfker_repr //=. by rewrite !cfunE Gx quo_repr_coset ?mem_quotient. Qed. Lemma cfQuo_lin_char G H (chi : 'CF(G)) : chi \is a linear_char -> (chi / H)%CF \is a linear_char. Proof. by case/andP=> Nchi; rewrite qualifE/= cfQuo_char ?cfQuo1. Qed. Lemma cfMod_char G H (chi : 'CF(G / H)) : chi \is a character -> (chi %% H)%CF \is a character. Proof. exact: cfMorph_char. Qed. Lemma cfMod_lin_char G H (chi : 'CF(G / H)) : chi \is a linear_char -> (chi %% H)%CF \is a linear_char. Proof. exact: cfMorph_lin_char. Qed. Lemma cfMod_charE G H (chi : 'CF(G / H)) : H <| G -> (chi %% H \is a character)%CF = (chi \is a character). Proof. by case/andP=> _; apply: cfMorph_charE. Qed. Lemma cfMod_lin_charE G H (chi : 'CF(G / H)) : H <| G -> (chi %% H \is a linear_char)%CF = (chi \is a linear_char). Proof. by case/andP=> _; apply: cfMorph_lin_charE. Qed. Lemma cfQuo_charE G H (chi : 'CF(G)) : H <| G -> H \subset cfker chi -> (chi / H \is a character)%CF = (chi \is a character). Proof. by move=> nsHG kerH; rewrite -cfMod_charE ?cfQuoK. Qed. Lemma cfQuo_lin_charE G H (chi : 'CF(G)) : H <| G -> H \subset cfker chi -> (chi / H \is a linear_char)%CF = (chi \is a linear_char). Proof. by move=> nsHG kerH; rewrite -cfMod_lin_charE ?cfQuoK. Qed. Lemma cfMod_irr G H chi : H <| G -> (chi %% H \in irr G)%CF = (chi \in irr (G / H)). Proof. by case/andP=> _; apply: cfMorph_irr. Qed. Definition mod_Iirr G H i := cfIirr ('chi[G / H]_i %% H)%CF. Lemma mod_Iirr0 G H : mod_Iirr (0 : Iirr (G / H)) = 0. Proof. exact: morph_Iirr0. Qed. Lemma mod_IirrE G H i : H <| G -> 'chi_(mod_Iirr i) = ('chi[G / H]_i %% H)%CF. Proof. by move=> nsHG; rewrite cfIirrE ?cfMod_irr ?mem_irr. Qed. Lemma mod_Iirr_eq0 G H i : H <| G -> (mod_Iirr i == 0) = (i == 0 :> Iirr (G / H)). Proof. by case/andP=> _ /morph_Iirr_eq0->. Qed. Lemma cfQuo_irr G H chi : H <| G -> H \subset cfker chi -> ((chi / H)%CF \in irr (G / H)) = (chi \in irr G). Proof. by move=> nsHG kerH; rewrite -cfMod_irr ?cfQuoK. Qed. Definition quo_Iirr G H i := cfIirr ('chi[G]_i / H)%CF. Lemma quo_Iirr0 G H : quo_Iirr H (0 : Iirr G) = 0. Proof. by rewrite /quo_Iirr irr0 cfQuo_cfun1 -irr0 irrK. Qed. Lemma quo_IirrE G H i : H <| G -> H \subset cfker 'chi[G]_i -> 'chi_(quo_Iirr H i) = ('chi_i / H)%CF. Proof. by move=> nsHG kerH; rewrite cfIirrE ?cfQuo_irr ?mem_irr. Qed. Lemma quo_Iirr_eq0 G H i : H <| G -> H \subset cfker 'chi[G]_i -> (quo_Iirr H i == 0) = (i == 0). Proof. by move=> nsHG kerH; rewrite -!irr_eq1 quo_IirrE ?cfQuo_eq1. Qed. Lemma mod_IirrK G H : H <| G -> cancel (@mod_Iirr G H) (@quo_Iirr G H). Proof. move=> nsHG i; apply: irr_inj. by rewrite quo_IirrE ?mod_IirrE ?cfker_mod // cfModK. Qed. Lemma quo_IirrK G H i : H <| G -> H \subset cfker 'chi[G]_i -> mod_Iirr (quo_Iirr H i) = i. Proof. by move=> nsHG kerH; apply: irr_inj; rewrite mod_IirrE ?quo_IirrE ?cfQuoK. Qed. Lemma quo_IirrKeq G H : H <| G -> forall i, (mod_Iirr (quo_Iirr H i) == i) = (H \subset cfker 'chi[G]_i). Proof. move=> nsHG i; apply/eqP/idP=> [<- | ]; last exact: quo_IirrK. by rewrite mod_IirrE ?cfker_mod. Qed. Lemma mod_Iirr_bij H G : H <| G -> {on [pred i | H \subset cfker 'chi_i], bijective (@mod_Iirr G H)}. Proof. by exists (quo_Iirr H) => [i _ | i]; [apply: mod_IirrK | apply: quo_IirrK]. Qed. Lemma sum_norm_irr_quo H G x : x \in G -> H <| G -> \sum_i `|'chi[G / H]_i (coset H x)| ^+ 2 = \sum_(i | H \subset cfker 'chi_i) `|'chi[G]_i x| ^+ 2. Proof. move=> Gx nsHG; rewrite (reindex _ (mod_Iirr_bij nsHG)) /=. by apply/esym/eq_big=> [i | i _]; rewrite mod_IirrE ?cfker_mod ?cfModE. Qed. Lemma cap_cfker_normal G H : H <| G -> \bigcap_(i | H \subset cfker 'chi[G]_i) (cfker 'chi_i) = H. Proof. move=> nsHG; have [sHG nHG] := andP nsHG; set lhs := \bigcap_(i | _) _. have nHlhs: lhs \subset 'N(H) by rewrite (bigcap_min 0) ?cfker_irr0. apply/esym/eqP; rewrite eqEsubset (introT bigcapsP) //= -quotient_sub1 //. rewrite -(TI_cfker_irr (G / H)); apply/bigcapsP=> i _. rewrite sub_quotient_pre // (bigcap_min (mod_Iirr i)) ?mod_IirrE ?cfker_mod //. by rewrite cfker_morph ?subsetIr. Qed. Lemma cfker_reg_quo G H : H <| G -> cfker (cfReg (G / H)%g %% H) = H. Proof. move=> nsHG; have [sHG nHG] := andP nsHG. apply/setP=> x; rewrite cfkerEchar ?cfMod_char ?cfReg_char //. rewrite -[in RHS in _ = RHS](setIidPr sHG) !inE; apply: andb_id2l => Gx. rewrite !cfModE // !cfRegE // morph1 eqxx. rewrite (sameP eqP (kerP _ (subsetP nHG x Gx))) ker_coset. by rewrite -!mulrnA eqr_nat eqn_pmul2l ?cardG_gt0 // (can_eq oddb) eqb_id. Qed. End Coset. Section DerivedGroup. Variable gT : finGroupType. Implicit Types G H : {group gT}. Lemma lin_irr_der1 G i : ('chi_i \is a linear_char) = (G^`(1)%g \subset cfker 'chi[G]_i). Proof. apply/idP/idP=> [|sG'K]; first exact: lin_char_der1. have nsG'G: G^`(1) <| G := der_normal 1 G. rewrite qualifE/= irr_char -[i](quo_IirrK nsG'G) // mod_IirrE //=. by rewrite cfModE // morph1 lin_char1 //; apply/char_abelianP/der_abelian. Qed. Lemma subGcfker G i : (G \subset cfker 'chi[G]_i) = (i == 0). Proof. rewrite -irr_eq1; apply/idP/eqP=> [chiG1 | ->]; last by rewrite cfker_cfun1. apply/cfun_inP=> x Gx; rewrite cfun1E Gx cfker1 ?(subsetP chiG1) ?lin_char1 //. by rewrite lin_irr_der1 (subset_trans (der_sub 1 G)). Qed. Lemma irr_prime_injP G i : prime #|G| -> reflect {in G &, injective 'chi[G]_i} (i != 0). Proof. move=> pr_G; apply: (iffP idP) => [nz_i | inj_chi]. apply: fful_lin_char_inj (irr_prime_lin i pr_G) _. by rewrite cfaithfulE -(setIidPr (cfker_sub _)) prime_TIg // subGcfker. have /trivgPn[x Gx ntx]: G :!=: 1%g by rewrite -cardG_gt1 prime_gt1. apply: contraNneq ntx => i0; apply/eqP/inj_chi=> //. by rewrite i0 irr0 !cfun1E Gx group1. Qed. (* This is Isaacs (2.23)(a). *) Lemma cap_cfker_lin_irr G : \bigcap_(i | 'chi[G]_i \is a linear_char) (cfker 'chi_i) = G^`(1)%g. Proof. rewrite -(cap_cfker_normal (der_normal 1 G)). by apply: eq_bigl => i; rewrite lin_irr_der1. Qed. (* This is Isaacs (2.23)(b) *) Lemma card_lin_irr G : #|[pred i | 'chi[G]_i \is a linear_char]| = #|G : G^`(1)%g|. Proof. have nsG'G := der_normal 1 G; rewrite (eq_card (@lin_irr_der1 G)). rewrite -(on_card_preimset (mod_Iirr_bij nsG'G)). rewrite -card_quotient ?normal_norm //. move: (der_abelian 0 G); rewrite card_classes_abelian; move/eqP<-. rewrite -NirrE -[RHS]card_ord. by apply: eq_card => i; rewrite !inE mod_IirrE ?cfker_mod. (* Alternative: use the equivalent result in modular representation theory transitivity #|@socle_of_Iirr _ G @^-1: linear_irr _|; last first. rewrite (on_card_preimset (socle_of_Iirr_bij _)). by rewrite card_linear_irr ?algC'G; last apply: groupC. by apply: eq_card => i; rewrite !inE /lin_char irr_char irr1_degree -eqC_nat. *) Qed. (* A non-trivial solvable group has a nonprincipal linear character. *) Lemma solvable_has_lin_char G : G :!=: 1%g -> solvable G -> exists2 i, 'chi[G]_i \is a linear_char & 'chi_i != 1. Proof. move=> ntG solG. suff /subsetPn[i]: ~~ ([pred i | 'chi[G]_i \is a linear_char] \subset pred1 0). by rewrite !inE -(inj_eq irr_inj) irr0; exists i. rewrite (contra (@subset_leq_card _ _ _)) // -ltnNge card1 card_lin_irr. by rewrite indexg_gt1 proper_subn // (sol_der1_proper solG). Qed. (* A combinatorial group isommorphic to the linear characters. *) Lemma lin_char_group G : {linG : finGroupType & {cF : linG -> 'CF(G) | [/\ injective cF, #|linG| = #|G : G^`(1)|, forall u, cF u \is a linear_char & forall phi, phi \is a linear_char -> exists u, phi = cF u] & [/\ cF 1%g = 1%R, {morph cF : u v / (u * v)%g >-> (u * v)%R}, forall k, {morph cF : u / (u^+ k)%g >-> u ^+ k}, {morph cF: u / u^-1%g >-> u^-1%CF} & {mono cF: u / #[u]%g >-> #[u]%CF} ]}}. Proof. pose linT := {i : Iirr G | 'chi_i \is a linear_char}. pose cF (u : linT) := 'chi_(sval u). have cFlin u: cF u \is a linear_char := svalP u. have cFinj: injective cF := inj_comp irr_inj val_inj. have inT xi : xi \is a linear_char -> {u | cF u = xi}. move=> lin_xi; have /irrP/sig_eqW[i Dxi] := lin_char_irr lin_xi. by apply: (exist _ (Sub i _)) => //; rewrite -Dxi. have [one cFone] := inT 1 (rpred1 _). pose inv u := sval (inT _ (rpredVr (cFlin u))). pose mul u v := sval (inT _ (rpredM (cFlin u) (cFlin v))). have cFmul u v: cF (mul u v) = cF u * cF v := svalP (inT _ _). have cFinv u: cF (inv u) = (cF u)^-1 := svalP (inT _ _). have mulA: associative mul by move=> u v w; apply: cFinj; rewrite !cFmul mulrA. have mul1: left_id one mul by move=> u; apply: cFinj; rewrite cFmul cFone mul1r. have mulV: left_inverse one inv mul. by move=> u; apply: cFinj; rewrite cFmul cFinv cFone mulVr ?lin_char_unitr. pose imA := isMulGroup.Build linT mulA mul1 mulV. pose linG : finGroupType := HB.pack linT imA. have cFexp k: {morph cF : u / ((u : linG) ^+ k)%g >-> u ^+ k}. by move=> u; elim: k => // k IHk; rewrite expgS exprS cFmul IHk. do [exists linG, cF; split=> //] => [|xi /inT[u <-]|u]; first 2 [by exists u]. have inj_cFI: injective (cfIirr \o cF). apply: can_inj (insubd one) _ => u; apply: val_inj. by rewrite insubdK /= ?irrK //; apply: cFlin. rewrite -(card_image inj_cFI) -card_lin_irr. apply/eq_card=> i /[1!inE]; apply/codomP/idP=> [[u ->] | /inT[u Du]]. by rewrite /= irrK; apply: cFlin. by exists u; apply: irr_inj; rewrite /= irrK. apply/eqP; rewrite eqn_dvd; apply/andP; split. by rewrite dvdn_cforder; rewrite -cFexp expg_order cFone. by rewrite order_dvdn -(inj_eq cFinj) cFone cFexp exp_cforder. Qed. Lemma cfExp_prime_transitive G (i j : Iirr G) : prime #|G| -> i != 0 -> j != 0 -> exists2 k, coprime k #['chi_i]%CF & 'chi_j = 'chi_i ^+ k. Proof. set p := #|G| => pr_p nz_i nz_j; have cycG := prime_cyclic pr_p. have [L [h [injh oL Lh h_ontoL]] [h1 hM hX _ o_h]] := lin_char_group G. rewrite (derG1P (cyclic_abelian cycG)) indexg1 -/p in oL. have /fin_all_exists[h' h'K] := h_ontoL _ (irr_cyclic_lin _ cycG). have o_h' k: k != 0 -> #[h' k] = p. rewrite -cforder_irr_eq1 h'K -o_h => nt_h'k. by apply/prime_nt_dvdP=> //; rewrite cforder_lin_char_dvdG. have{oL} genL k: k != 0 -> generator [set: L] (h' k). move=> /o_h' o_h'k; rewrite /generator eq_sym eqEcard subsetT /=. by rewrite cardsT oL -o_h'k. have [/(_ =P <[_]>)-> gen_j] := (genL i nz_i, genL j nz_j). have /cycleP[k Dj] := cycle_generator gen_j. by rewrite !h'K Dj o_h hX generator_coprime coprime_sym in gen_j *; exists k. Qed. (* This is Isaacs (2.24). *) Lemma card_subcent1_coset G H x : x \in G -> H <| G -> (#|'C_(G / H)[coset H x]| <= #|'C_G[x]|)%N. Proof. move=> Gx nsHG; rewrite -leC_nat. move: (second_orthogonality_relation x Gx); rewrite mulrb class_refl => <-. have GHx: coset H x \in (G / H)%g by apply: mem_quotient. move: (second_orthogonality_relation (coset H x) GHx). rewrite mulrb class_refl => <-. rewrite -2!(eq_bigr _ (fun _ _ => normCK _)) sum_norm_irr_quo // -subr_ge0. rewrite (bigID (fun i => H \subset cfker 'chi[G]_i)) //= [X in X + _]addrC addrK. by apply: sumr_ge0 => i _; rewrite normCK mul_conjC_ge0. Qed. End DerivedGroup. Arguments irr_prime_injP {gT G i}. (* Determinant characters and determinential order. *) Section DetRepr. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation algC G n). Definition det_repr_mx x : 'M_1 := (\det (rG x))%:M. Fact det_is_repr : mx_repr G det_repr_mx. Proof. split=> [|g h Gg Gh]; first by rewrite /det_repr_mx repr_mx1 det1. by rewrite /det_repr_mx repr_mxM // det_mulmx !mulmxE scalar_mxM. Qed. Canonical det_repr := MxRepresentation det_is_repr. Definition detRepr := cfRepr det_repr. Lemma detRepr_lin_char : detRepr \is a linear_char. Proof. by rewrite qualifE/= cfRepr_char cfunE group1 repr_mx1 mxtrace1 mulr1n /=. Qed. End DetRepr. HB.lock Definition cfDet (gT : finGroupType) (G : {group gT}) phi := \prod_i detRepr 'Chi_i ^+ Num.truncn '[phi, 'chi[G]_i]. Canonical cfDet_unlockable := Unlockable cfDet.unlock. Section DetOrder. Variables (gT : finGroupType) (G : {group gT}). Local Notation cfDet := (@cfDet gT G). Lemma cfDet_lin_char phi : cfDet phi \is a linear_char. Proof. rewrite unlock; apply: rpred_prod => i _; apply: rpredX. exact: detRepr_lin_char. Qed. Lemma cfDetD : {in character &, {morph cfDet : phi psi / phi + psi >-> phi * psi}}. Proof. move=> phi psi Nphi Npsi; rewrite unlock /= -big_split; apply: eq_bigr => i _ /=. by rewrite -exprD cfdotDl truncnD ?nnegrE ?natr_ge0 // Cnat_cfdot_char_irr. Qed. Lemma cfDet0 : cfDet 0 = 1. Proof. by rewrite unlock big1 // => i _; rewrite cfdot0l truncn0. Qed. Lemma cfDetMn k : {in character, {morph cfDet : phi / phi *+ k >-> phi ^+ k}}. Proof. move=> phi Nphi; elim: k => [|k IHk]; rewrite ?cfDet0 // mulrS exprS -{}IHk. by rewrite cfDetD ?rpredMn. Qed. Lemma cfDetRepr n rG : cfDet (cfRepr rG) = @detRepr _ _ n rG. Proof. transitivity (\prod_W detRepr (socle_repr W) ^+ standard_irr_coef rG W). rewrite (reindex _ (socle_of_Iirr_bij _)) unlock /=. apply: eq_bigr => i _; congr (_ ^+ _). rewrite (cfRepr_sim (mx_rsim_standard rG)) cfRepr_standard. rewrite cfdot_suml (bigD1 i) ?big1 //= => [|j i'j]; last first. by rewrite cfdotZl cfdot_irr (negPf i'j) mulr0. by rewrite cfdotZl cfnorm_irr mulr1 addr0 natrK. apply/cfun_inP=> x Gx; rewrite prod_cfunE //. transitivity (detRepr (standard_grepr rG) x); last first. rewrite !cfunE Gx !trace_mx11 !mxE eqxx !mulrb. case: (standard_grepr rG) (mx_rsim_standard rG) => /= n1 rG1 [B Dn1]. rewrite -{n1}Dn1 in rG1 B *; rewrite row_free_unit => uB rG_B. by rewrite -[rG x](mulmxK uB) rG_B // !det_mulmx mulrC -!det_mulmx mulKmx. rewrite /standard_grepr; elim/big_rec2: _ => [|W y _ _ ->]. by rewrite cfunE trace_mx11 mxE Gx det1. rewrite !cfunE Gx /= !{1}trace_mx11 !{1}mxE det_ublock; congr (_ * _). rewrite exp_cfunE //; elim: (standard_irr_coef rG W) => /= [|k IHk]. by rewrite /muln_grepr big_ord0 det1. rewrite exprS /muln_grepr big_ord_recl det_ublock -IHk; congr (_ * _). by rewrite cfunE trace_mx11 mxE Gx. Qed. Lemma cfDet_id xi : xi \is a linear_char -> cfDet xi = xi. Proof. move=> lin_xi; have /irrP[i Dxi] := lin_char_irr lin_xi. apply/cfun_inP=> x Gx; rewrite Dxi -irrRepr cfDetRepr !cfunE trace_mx11 mxE. move: lin_xi (_ x) => /andP[_]; rewrite Dxi irr1_degree pnatr_eq1 => /eqP-> X. by rewrite {1}[X]mx11_scalar det_scalar1 trace_mx11. Qed. Definition cfDet_order phi := #[cfDet phi]%CF. Definition cfDet_order_lin xi : xi \is a linear_char -> cfDet_order xi = #[xi]%CF. Proof. by rewrite /cfDet_order => /cfDet_id->. Qed. Definition cfDet_order_dvdG phi : cfDet_order phi %| #|G|. Proof. by rewrite cforder_lin_char_dvdG ?cfDet_lin_char. Qed. End DetOrder. Notation "''o' ( phi )" := (cfDet_order phi) (format "''o' ( phi )") : cfun_scope. Section CfDetOps. Implicit Types gT aT rT : finGroupType. Lemma cfDetRes gT (G H : {group gT}) phi : phi \is a character -> cfDet ('Res[H, G] phi) = 'Res (cfDet phi). Proof. move=> Nphi; have [sGH | not_sHG] := boolP (H \subset G); last first. have /natrP[n Dphi1] := Cnat_char1 Nphi. rewrite !cfResEout // Dphi1 lin_char1 ?cfDet_lin_char // scale1r. by rewrite scaler_nat cfDetMn ?cfDet_id ?rpred1 // expr1n. have [rG ->] := char_reprP Nphi; rewrite !(=^~ cfRepr_sub, cfDetRepr) //. apply: cfRepr_sim; exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => x Hx. by rewrite mulmx1 mul1mx. Qed. Lemma cfDetMorph aT rT (D G : {group aT}) (f : {morphism D >-> rT}) (phi : 'CF(f @* G)) : phi \is a character -> cfDet (cfMorph phi) = cfMorph (cfDet phi). Proof. move=> Nphi; have [sGD | not_sGD] := boolP (G \subset D); last first. have /natrP[n Dphi1] := Cnat_char1 Nphi. rewrite !cfMorphEout // Dphi1 lin_char1 ?cfDet_lin_char // scale1r. by rewrite scaler_nat cfDetMn ?cfDet_id ?rpred1 // expr1n. have [rG ->] := char_reprP Nphi; rewrite !(=^~ cfRepr_morphim, cfDetRepr) //. apply: cfRepr_sim; exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => x Hx. by rewrite mulmx1 mul1mx. Qed. Lemma cfDetIsom aT rT (G : {group aT}) (R : {group rT}) (f : {morphism G >-> rT}) (isoGR : isom G R f) phi : cfDet (cfIsom isoGR phi) = cfIsom isoGR (cfDet phi). Proof. rewrite unlock rmorph_prod (reindex (isom_Iirr isoGR)); last first. by exists (isom_Iirr (isom_sym isoGR)) => i; rewrite ?isom_IirrK ?isom_IirrKV. apply: eq_bigr=> i; rewrite -!cfDetRepr !irrRepr isom_IirrE rmorphXn cfIsom_iso. by rewrite /= ![in cfIsom _]unlock cfDetMorph ?cfRes_char ?cfDetRes ?irr_char. Qed. Lemma cfDet_mul_lin gT (G : {group gT}) (lambda phi : 'CF(G)) : lambda \is a linear_char -> phi \is a character -> cfDet (lambda * phi) = lambda ^+ Num.truncn (phi 1%g) * cfDet phi. Proof. case/andP=> /char_reprP[[n1 rG1] ->] /= n1_1 /char_reprP[[n2 rG2] ->] /=. do [rewrite !cfRepr1 pnatr_eq1 natrK; move/eqP] in n1_1 *. rewrite {n1}n1_1 in rG1 *; rewrite cfRepr_prod cfDetRepr. apply/cfun_inP=> x Gx; rewrite !cfunE cfDetRepr cfunE Gx !mulrb !trace_mx11. rewrite !mxE prod_repr_lin ?mulrb //=; case: _ / (esym _); rewrite detZ. congr (_ * _); case: {rG2}n2 => [|n2]; first by rewrite cfun1E Gx. by rewrite expS_cfunE //= cfunE Gx trace_mx11. Qed. End CfDetOps. Definition cfcenter (gT : finGroupType) (G : {set gT}) (phi : 'CF(G)) := if phi \is a character then [set g in G | `|phi g| == phi 1%g] else cfker phi. Notation "''Z' ( phi )" := (cfcenter phi) : cfun_scope. Section Center. Variable (gT : finGroupType) (G : {group gT}). Implicit Types (phi chi : 'CF(G)) (H : {group gT}). (* This is Isaacs (2.27)(a). *) Lemma cfcenter_repr n (rG : mx_representation algC G n) : 'Z(cfRepr rG)%CF = rcenter rG. Proof. rewrite /cfcenter /rcenter cfRepr_char /=. apply/setP=> x /[!inE]; apply/andb_id2l=> Gx. apply/eqP/is_scalar_mxP=> [|[c rG_c]]. by case/max_cfRepr_norm_scalar=> // c; exists c. rewrite -(sqrCK (char1_ge0 (cfRepr_char rG))) normC_def; congr (sqrtC _). rewrite expr2 -{2}(mulgV x) -char_inv ?cfRepr_char ?cfunE ?groupM ?groupV //. rewrite Gx group1 repr_mx1 repr_mxM ?repr_mxV ?groupV // !mulrb rG_c. by rewrite invmx_scalar -scalar_mxM !mxtrace_scalar mulrnAr mulrnAl mulr_natl. Qed. (* This is part of Isaacs (2.27)(b). *) Fact cfcenter_group_set phi : group_set ('Z(phi))%CF. Proof. have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ G phi). by rewrite cfcenter_repr groupP. by rewrite /cfcenter notNphi groupP. Qed. Canonical cfcenter_group f := Group (cfcenter_group_set f). Lemma char_cfcenterE chi x : chi \is a character -> x \in G -> (x \in ('Z(chi))%CF) = (`|chi x| == chi 1%g). Proof. by move=> Nchi Gx; rewrite /cfcenter Nchi inE Gx. Qed. Lemma irr_cfcenterE i x : x \in G -> (x \in 'Z('chi[G]_i)%CF) = (`|'chi_i x| == 'chi_i 1%g). Proof. by move/char_cfcenterE->; rewrite ?irr_char. Qed. (* This is also Isaacs (2.27)(b). *) Lemma cfcenter_sub phi : ('Z(phi))%CF \subset G. Proof. by rewrite /cfcenter /cfker !setIdE -fun_if subsetIl. Qed. Lemma cfker_center_normal phi : cfker phi <| 'Z(phi)%CF. Proof. apply: normalS (cfcenter_sub phi) (cfker_normal phi). rewrite /= /cfcenter; case: ifP => // Hphi; rewrite cfkerEchar //. apply/subsetP=> x /[!inE] /andP[-> /eqP->] /=. by rewrite ger0_norm ?char1_ge0. Qed. Lemma cfcenter_normal phi : 'Z(phi)%CF <| G. Proof. have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ _ phi). by rewrite cfcenter_repr rcenter_normal. by rewrite /cfcenter notNphi cfker_normal. Qed. (* This is Isaacs (2.27)(c). *) Lemma cfcenter_Res chi : exists2 chi1, chi1 \is a linear_char & 'Res['Z(chi)%CF] chi = chi 1%g *: chi1. Proof. have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ _ chi); last first. exists 1; first exact: cfun1_lin_char. rewrite /cfcenter notNphi; apply/cfun_inP=> x Kx. by rewrite cfunE cfun1E Kx mulr1 cfResE ?cfker_sub // cfker1. rewrite cfcenter_repr -(cfRepr_sub _ (normal_sub (rcenter_normal _))). case: rG => [[|n] rG] /=; rewrite cfRepr1. exists 1; first exact: cfun1_lin_char. by apply/cfun_inP=> x Zx; rewrite scale0r !cfunE flatmx0 raddf0 Zx. pose rZmx x := ((rG x 0 0)%:M : 'M_(1,1)). have rZmxP: mx_repr [group of rcenter rG] rZmx. split=> [|x y]; first by rewrite /rZmx repr_mx1 mxE eqxx. move=> /setIdP[Gx /is_scalar_mxP[a rGx]] /setIdP[Gy /is_scalar_mxP[b rGy]]. by rewrite /rZmx repr_mxM // rGx rGy -!scalar_mxM !mxE. exists (cfRepr (MxRepresentation rZmxP)). by rewrite qualifE/= cfRepr_char cfRepr1 eqxx. apply/cfun_inP=> x Zx; rewrite !cfunE Zx /= /rZmx mulr_natl. by case/setIdP: Zx => Gx /is_scalar_mxP[a ->]; rewrite mxE !mxtrace_scalar. Qed. (* This is Isaacs (2.27)(d). *) Lemma cfcenter_cyclic chi : cyclic ('Z(chi)%CF / cfker chi)%g. Proof. case Nchi: (chi \is a character); last first. by rewrite /cfcenter Nchi trivg_quotient cyclic1. have [-> | nz_chi] := eqVneq chi 0. rewrite quotientS1 ?cyclic1 //= /cfcenter cfkerEchar ?cfun0_char //. by apply/subsetP=> x /setIdP[Gx _]; rewrite inE Gx /= !cfunE. have [xi Lxi def_chi] := cfcenter_Res chi. set Z := ('Z(_))%CF in xi Lxi def_chi *. have sZG: Z \subset G by apply: cfcenter_sub. have ->: cfker chi = cfker xi. rewrite -(setIidPr (normal_sub (cfker_center_normal _))) -/Z. rewrite !cfkerEchar // ?lin_charW //= -/Z. apply/setP=> x /[!inE]; apply: andb_id2l => Zx. rewrite (subsetP sZG) //= -!(cfResE chi sZG) ?group1 // def_chi !cfunE. by rewrite (inj_eq (mulfI _)) ?char1_eq0. have: abelian (Z / cfker xi) by rewrite sub_der1_abelian ?lin_char_der1. have /irr_reprP[rG irrG ->] := lin_char_irr Lxi; rewrite cfker_repr. apply: mx_faithful_irr_abelian_cyclic (kquo_mx_faithful rG) _. exact/quo_mx_irr. Qed. (* This is Isaacs (2.27)(e). *) Lemma cfcenter_subset_center chi : ('Z(chi)%CF / cfker chi)%g \subset 'Z(G / cfker chi)%g. Proof. case Nchi: (chi \is a character); last first. by rewrite /cfcenter Nchi trivg_quotient sub1G. rewrite subsetI quotientS ?cfcenter_sub // quotient_cents2r //=. case/char_reprP: Nchi => rG ->{chi}; rewrite cfker_repr cfcenter_repr gen_subG. apply/subsetP=> _ /imset2P[x y /setIdP[Gx /is_scalar_mxP[c rGx]] Gy ->]. rewrite inE groupR //= !repr_mxM ?groupM ?groupV // rGx -(scalar_mxC c) -rGx. by rewrite !mulmxA !repr_mxKV. Qed. (* This is Isaacs (2.27)(f). *) Lemma cfcenter_eq_center (i : Iirr G) : ('Z('chi_i)%CF / cfker 'chi_i)%g = 'Z(G / cfker 'chi_i)%g. Proof. apply/eqP; rewrite eqEsubset; rewrite cfcenter_subset_center ?irr_char //. apply/subsetP=> _ /setIP[/morphimP[x /= _ Gx ->] cGx]; rewrite mem_quotient //=. rewrite -irrRepr cfker_repr cfcenter_repr inE Gx in cGx *. apply: mx_abs_irr_cent_scalar 'Chi_i _ _ _; first exact/groupC/socle_irr. have nKG: G \subset 'N(rker 'Chi_i) by apply: rker_norm. (* GG -- locking here is critical to prevent Coq kernel divergence. *) apply/centgmxP=> y Gy; rewrite [eq]lock -2?(quo_repr_coset (subxx _) nKG) //. move: (quo_repr _ _) => rG; rewrite -2?repr_mxM ?mem_quotient // -lock. by rewrite (centP cGx) // mem_quotient. Qed. (* This is Isaacs (2.28). *) Lemma cap_cfcenter_irr : \bigcap_i 'Z('chi[G]_i)%CF = 'Z(G). Proof. apply/esym/eqP; rewrite eqEsubset (introT bigcapsP) /= => [|i _]; last first. rewrite -(quotientSGK _ (normal_sub (cfker_center_normal _))). by rewrite cfcenter_eq_center morphim_center. by rewrite subIset // normal_norm // cfker_normal. set Z := \bigcap_i _. have sZG: Z \subset G by rewrite (bigcap_min 0) ?cfcenter_sub. rewrite subsetI sZG (sameP commG1P trivgP) -(TI_cfker_irr G). apply/bigcapsP=> i _; have nKiG := normal_norm (cfker_normal 'chi_i). rewrite -quotient_cents2 ?(subset_trans sZG) //. rewrite (subset_trans (quotientS _ (bigcap_inf i _))) //. by rewrite cfcenter_eq_center subsetIr. Qed. (* This is Isaacs (2.29). *) Lemma cfnorm_Res_leif H phi : H \subset G -> '['Res[H] phi] <= #|G : H|%:R * '[phi] ?= iff (phi \in 'CF(G, H)). Proof. move=> sHG; rewrite cfun_onE mulrCA natf_indexg // -mulrA mulKf ?neq0CG //. rewrite (big_setID H) (setIidPr sHG) /= addrC. rewrite (mono_leif (ler_pM2l _)) ?invr_gt0 ?gt0CG // -leifBLR -sumrB. rewrite big1 => [|x Hx]; last by rewrite !cfResE ?subrr. have ->: (support phi \subset H) = (G :\: H \subset [set x | phi x == 0]). rewrite subDset setUC -subDset; apply: eq_subset => x. by rewrite !inE (andb_idr (contraR _)) // => /cfun0->. rewrite (sameP subsetP forall_inP); apply: leif_0_sum => x _. by rewrite !inE /<?=%R mul_conjC_ge0 eq_sym mul_conjC_eq0. Qed. (* This is Isaacs (2.30). *) Lemma irr1_bound (i : Iirr G) : ('chi_i 1%g) ^+ 2 <= #|G : 'Z('chi_i)%CF|%:R ?= iff ('chi_i \in 'CF(G, 'Z('chi_i)%CF)). Proof. congr (_ <= _ ?= iff _): (cfnorm_Res_leif 'chi_i (cfcenter_sub 'chi_i)). have [xi Lxi ->] := cfcenter_Res 'chi_i. have /irrP[j ->] := lin_char_irr Lxi; rewrite cfdotZl cfdotZr cfdot_irr eqxx. by rewrite mulr1 irr1_degree conjC_nat. by rewrite cfdot_irr eqxx mulr1. Qed. (* This is Isaacs (2.31). *) Lemma irr1_abelian_bound (i : Iirr G) : abelian (G / 'Z('chi_i)%CF) -> ('chi_i 1%g) ^+ 2 = #|G : 'Z('chi_i)%CF|%:R. Proof. move=> AbGc; apply/eqP; rewrite irr1_bound cfun_onE; apply/subsetP=> x nz_chi_x. have Gx: x \in G by apply: contraR nz_chi_x => /cfun0->. have nKx := subsetP (normal_norm (cfker_normal 'chi_i)) _ Gx. rewrite -(quotientGK (cfker_center_normal _)) inE nKx inE /=. rewrite cfcenter_eq_center inE mem_quotient //=. apply/centP=> _ /morphimP[y nKy Gy ->]; apply/commgP; rewrite -morphR //=. set z := [~ x, y]; rewrite coset_id //. have: z \in 'Z('chi_i)%CF. apply: subsetP (mem_commg Gx Gy). by rewrite der1_min // normal_norm ?cfcenter_normal. rewrite -irrRepr cfker_repr cfcenter_repr !inE in nz_chi_x *. case/andP=> Gz /is_scalar_mxP[c Chi_z]; rewrite Gz Chi_z mul1mx /=. apply/eqP; congr _%:M; apply: (mulIf nz_chi_x); rewrite mul1r. rewrite -{2}(cfunJ _ x Gy) conjg_mulR -/z !cfunE Gx groupM // !{1}mulrb. by rewrite repr_mxM // Chi_z mul_mx_scalar mxtraceZ. Qed. (* This is Isaacs (2.32)(a). *) Lemma irr_faithful_center i : cfaithful 'chi[G]_i -> cyclic 'Z(G). Proof. rewrite (isog_cyclic (isog_center (quotient1_isog G))) /=. by move/trivgP <-; rewrite -cfcenter_eq_center cfcenter_cyclic. Qed. Lemma cfcenter_fful_irr i : cfaithful 'chi[G]_i -> 'Z('chi_i)%CF = 'Z(G). Proof. move/trivgP=> Ki1; have:= cfcenter_eq_center i; rewrite {}Ki1. have inj1: 'injm (@coset gT 1%g) by rewrite ker_coset. by rewrite -injm_center; first apply: injm_morphim_inj; rewrite ?norms1. Qed. (* This is Isaacs (2.32)(b). *) Lemma pgroup_cyclic_faithful (p : nat) : p.-group G -> cyclic 'Z(G) -> exists i, cfaithful 'chi[G]_i. Proof. pose Z := 'Ohm_1('Z(G)) => pG cycZG; have nilG := pgroup_nil pG. have [-> | ntG] := eqsVneq G [1]; first by exists 0; apply: cfker_sub. have{pG} [[p_pr _ _] pZ] := (pgroup_pdiv pG ntG, pgroupS (center_sub G) pG). have ntZ: 'Z(G) != [1] by rewrite center_nil_eq1. have{pZ} oZ: #|Z| = p by apply: Ohm1_cyclic_pgroup_prime. apply/existsP; apply: contraR ntZ => /existsPn-not_ffulG. rewrite -Ohm1_eq1 -subG1 /= -/Z -(TI_cfker_irr G); apply/bigcapsP=> i _. rewrite prime_meetG ?oZ // setIC meet_Ohm1 // meet_center_nil ?cfker_normal //. by rewrite -subG1 not_ffulG. Qed. End Center. Section Induced. Variables (gT : finGroupType) (G H : {group gT}). Implicit Types (phi : 'CF(G)) (chi : 'CF(H)). Lemma cfInd_char chi : chi \is a character -> 'Ind[G] chi \is a character. Proof. move=> Nchi; apply/forallP=> i; rewrite coord_cfdot -Frobenius_reciprocity //. by rewrite Cnat_cfdot_char ?cfRes_char ?irr_char. Qed. Lemma cfInd_eq0 chi : H \subset G -> chi \is a character -> ('Ind[G] chi == 0) = (chi == 0). Proof. move=> sHG Nchi; rewrite -!(char1_eq0) ?cfInd_char // cfInd1 //. by rewrite (mulrI_eq0 _ (mulfI _)) ?neq0CiG. Qed. Lemma Ind_irr_neq0 i : H \subset G -> 'Ind[G, H] 'chi_i != 0. Proof. by move/cfInd_eq0->; rewrite ?irr_neq0 ?irr_char. Qed. Definition Ind_Iirr (A B : {set gT}) i := cfIirr ('Ind[B, A] 'chi_i). Lemma constt_cfRes_irr i : {j | j \in irr_constt ('Res[H, G] 'chi_i)}. Proof. apply/sigW/neq0_has_constt/Res_irr_neq0. Qed. Lemma constt_cfInd_irr i : H \subset G -> {j | j \in irr_constt ('Ind[G, H] 'chi_i)}. Proof. by move=> sHG; apply/sigW/neq0_has_constt/Ind_irr_neq0. Qed. Lemma cfker_Res phi : H \subset G -> phi \is a character -> cfker ('Res[H] phi) = H :&: cfker phi. Proof. move=> sHG Nphi; apply/setP=> x; rewrite !cfkerEchar ?cfRes_char // !inE. by apply/andb_id2l=> Hx; rewrite (subsetP sHG) ?cfResE. Qed. (* This is Isaacs Lemma (5.11). *) Lemma cfker_Ind chi : H \subset G -> chi \is a character -> chi != 0 -> cfker ('Ind[G, H] chi) = gcore (cfker chi) G. Proof. move=> sHG Nchi nzchi; rewrite !cfker_nzcharE ?cfInd_char ?cfInd_eq0 //. apply/setP=> x; rewrite inE cfIndE // (can2_eq (mulVKf _) (mulKf _)) ?neq0CG //. rewrite cfInd1 // mulrA -natrM Lagrange // mulr_natl -sumr_const. apply/eqP/bigcapP=> [/normC_sum_upper ker_chiG_x y Gy | ker_chiG_x]. by rewrite mem_conjg inE ker_chiG_x ?groupV // => z _; apply: char1_ge_norm. by apply: eq_bigr => y /groupVr/ker_chiG_x; rewrite mem_conjgV inE => /eqP. Qed. Lemma cfker_Ind_irr i : H \subset G -> cfker ('Ind[G, H] 'chi_i) = gcore (cfker 'chi_i) G. Proof. by move/cfker_Ind->; rewrite ?irr_neq0 ?irr_char. Qed. End Induced. Arguments Ind_Iirr {gT A%_g} B%_g i%_R.
Functor.lean
/- Copyright (c) 2016 Leonardo de Moura. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Control.Basic import Mathlib.Data.Set.Defs import Mathlib.Data.Set.Lattice.Image import Mathlib.Data.Set.Notation /-! # Functoriality of `Set` This file defines the functor structure of `Set`. -/ universe u open Function Set.Notation namespace Set variable {α β : Type u} {s : Set α} {f : α → Set β} /-- The `Set` functor is a monad. This is not a global instance because it does not have computational content, so it does not make much sense using `do` notation in general. Plus, this would cause monad-related coercions and monad lifting logic to become activated. Either use `attribute [local instance] Set.monad` to make it be a local instance or use `SetM.run do ...` when `do` notation is wanted. -/ protected def monad : Monad.{u} Set where pure a := {a} bind s f := ⋃ i ∈ s, f i seq s t := Set.seq s (t ()) map := Set.image section with_instance attribute [local instance] Set.monad @[simp] theorem bind_def : s >>= f = ⋃ i ∈ s, f i := rfl @[simp] theorem fmap_eq_image (f : α → β) : f <$> s = f '' s := rfl @[simp] theorem seq_eq_set_seq (s : Set (α → β)) (t : Set α) : s <*> t = s.seq t := rfl @[simp] theorem pure_def (a : α) : (pure a : Set α) = {a} := rfl /-- `Set.image2` in terms of monadic operations. Note that this can't be taken as the definition because of the lack of universe polymorphism. -/ theorem image2_def {α β γ : Type u} (f : α → β → γ) (s : Set α) (t : Set β) : image2 f s t = f <$> s <*> t := by ext simp instance : LawfulMonad Set := LawfulMonad.mk' (id_map := image_id) (pure_bind := biUnion_singleton) (bind_assoc := fun _ _ _ => by simp only [bind_def, biUnion_iUnion]) (bind_pure_comp := fun _ _ => (image_eq_iUnion _ _).symm) (bind_map := fun _ _ => seq_def.symm) instance : CommApplicative (Set : Type u → Type u) := ⟨fun s t => prod_image_seq_comm s t⟩ instance : Alternative Set := { Set.monad with orElse := fun s t => s ∪ (t ()) failure := ∅ } /-! ### Monadic coercion lemmas -/ variable {β : Set α} {γ : Set β} theorem mem_coe_of_mem {a : α} (ha : a ∈ β) (ha' : ⟨a, ha⟩ ∈ γ) : a ∈ (γ : Set α) := ⟨_, ⟨⟨_, rfl⟩, _, ⟨ha', rfl⟩, rfl⟩⟩ theorem coe_subset : (γ : Set α) ⊆ β := by intro _ ⟨_, ⟨⟨⟨_, ha⟩, rfl⟩, _, ⟨_, rfl⟩, _⟩⟩; convert ha theorem mem_of_mem_coe {a : α} (ha : a ∈ (γ : Set α)) : ⟨a, coe_subset ha⟩ ∈ γ := by rcases ha with ⟨_, ⟨_, rfl⟩, _, ⟨ha, rfl⟩, _⟩; convert ha theorem eq_univ_of_coe_eq (hγ : (γ : Set α) = β) : γ = univ := eq_univ_of_forall fun ⟨_, ha⟩ => mem_of_mem_coe <| hγ.symm ▸ ha theorem image_coe_eq_restrict_image {δ : Type*} {f : α → δ} : f '' γ = β.restrict f '' γ := ext fun _ => ⟨fun ⟨_, h, ha⟩ => ⟨_, mem_of_mem_coe h, ha⟩, fun ⟨_, h, ha⟩ => ⟨_, mem_coe_of_mem _ h, ha⟩⟩ end with_instance /-! ### Coercion applying functoriality for `Subtype.val` The `Monad` instance gives a coercion using the internal function `Lean.Internal.coeM`. In practice this is only used for applying the `Set` functor to `Subtype.val`, as was defined in `Data.Set.Notation`. -/ /-- The coercion from `Set.monad` as an instance is equal to the coercion in `Data.Set.Notation`. -/ theorem coe_eq_image_val (t : Set s) : @Lean.Internal.coeM Set s α _ Set.monad t = (t : Set α) := by change ⋃ (x ∈ t), {x.1} = _ ext simp variable {β : Set α} {γ : Set β} {a : α} theorem mem_image_val_of_mem (ha : a ∈ β) (ha' : ⟨a, ha⟩ ∈ γ) : a ∈ (γ : Set α) := ⟨_, ha', rfl⟩ theorem image_val_subset : (γ : Set α) ⊆ β := by rintro _ ⟨⟨_, ha⟩, _, rfl⟩; exact ha theorem mem_of_mem_image_val (ha : a ∈ (γ : Set α)) : ⟨a, image_val_subset ha⟩ ∈ γ := by rcases ha with ⟨_, ha, rfl⟩; exact ha theorem eq_univ_of_image_val_eq (hγ : (γ : Set α) = β) : γ = univ := eq_univ_of_forall fun ⟨_, ha⟩ => mem_of_mem_image_val <| hγ.symm ▸ ha theorem image_image_val_eq_restrict_image {δ : Type*} {f : α → δ} : f '' γ = β.restrict f '' γ := by ext; simp end Set /-! ### Wrapper to enable the `Set` monad -/ /-- This is `Set` but with a `Monad` instance. -/ def SetM (α : Type u) := Set α instance : Monad SetM := Set.monad /-- Evaluates the `SetM` monad, yielding a `Set`. Implementation note: this is the identity function. -/ protected def SetM.run {α : Type*} (s : SetM α) : Set α := s
ssreflect.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From Corelib Require Export ssreflect. Global Set SsrOldRewriteGoalsOrder. Global Set Asymmetric Patterns. Global Set Bullet Behavior "None". #[deprecated(since="mathcomp 2.3.0", note="Use `Arguments def : simpl never` instead (should work fine since Coq 8.18).")] Notation nosimpl t := (nosimpl t). (** Additions to be ported to Corelib ssreflect: hide t == t, but hide t displays as <hidden> hideT t == t, but both hideT t and its inferred type display as <hidden> New ltac views: => /#[#hide#]# := insert hide in the type of the top assumption (and its body if it is a 'let'), so it displays as <hidden>. => /#[#let#]# := if the type (or body) of the top assumption is a 'let', make that 'let' the top assumption, e.g., turn (let n := 1 in m < half n) -> G into let n := 1 in m < half n -> G => /#[#fix#]# := names a 'fix' expression f in the goal G(f), by replacing the goal with let fx := hide f in G(fx), where fx is a fresh variable, and hide f displays as <hidden>. => /#[#cofix#]# := similarly, names a 'cofix' expression in the goal. **) Definition hide {T} t : T := t. Notation hideT := (@hide (hide _)) (only parsing). Notation "<hidden >" := (hide _) (at level 0, format "<hidden >", only printing) : ssr_scope. Notation "'[' 'hide' ']'" := (ltac:( move; lazymatch goal with | |- forall x : ?A, ?G => change (forall x : hide A, G) | |- let x : ?A := ?a in ?G => change (let x : hide A := @hide A a in G) | _ => fail "[hide] : no top assumption" end)) (at level 0, only parsing) : ssripat_scope. Notation "'[' 'let' ']'" := (ltac:( move; lazymatch goal with | |- forall (H : let x : ?A := ?a in ?T), ?G => change (let x : A := a in forall H : T, G) | |- let H : (let x : ?A := ?a in ?T) := ?t in ?G => change (let x : A := a in let H : T := t in G) | |- let H : ?T := (let x : ?A := ?a in ?t) in ?G => change (let x : A := a in let H : T := t in G) | _ => fail "[let]: top assumption type or body is not a 'let'" end)) (at level 0, only parsing) : ssripat_scope. Notation "'[' 'fix' ']'" := (ltac:( match goal with | |- context [?t] => is_fix t; let f := fresh "fix" in set f := t; move: @f => /[hide] | _ => fail 1 "[fix]: no visible 'fix' in goal" end)) (at level 0, only parsing) : ssripat_scope. Notation "'[' 'cofix' ']'" := (ltac:( match goal with | |- context [?t] => is_cofix t; let z := fresh "cofix" in set z := t; move: @z => /[hide] | _ => fail 1 "[cofix]: no visible 'cofix' in goal" end)) (at level 0, only parsing) : ssripat_scope.
ssrmatching.v
From Corelib Require Export ssrmatching.
KAbstractPositions.lean
/- Copyright (c) 2023 Jovan Gerbscheid. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jovan Gerbscheid -/ import Mathlib.Init import Lean.HeadIndex import Lean.Meta.ExprLens import Lean.Meta.Check /-! # Find the positions of a pattern in an expression This file defines some tools for dealing with sub expressions and occurrence numbers. This is used for creating a `rw` tactic call that rewrites a selected expression. `viewKAbstractSubExpr` takes an expression and a position in the expression, and returns the sub-expression together with an optional occurrence number that would be required to find the sub-expression using `kabstract` (which is what `rw` uses to find the position of the rewrite) `rw` can fail if the motive is not type correct. `kabstractIsTypeCorrect` checks whether this is the case. -/ namespace Lean.Meta /-- Return the positions that `kabstract` would abstract for pattern `p` in expression `e`. i.e. the positions that unify with `p`. -/ def kabstractPositions (p e : Expr) : MetaM (Array SubExpr.Pos) := do let e ← instantiateMVars e let mctx ← getMCtx let pHeadIdx := p.toHeadIndex let pNumArgs := p.headNumArgs let rec /-- The main loop that loops through all subexpressions -/ visit (e : Expr) (pos : SubExpr.Pos) (positions : Array SubExpr.Pos) : MetaM (Array SubExpr.Pos) := do let visitChildren : Array SubExpr.Pos → MetaM (Array SubExpr.Pos) := match e with | .app fn arg => visit fn pos.pushAppFn >=> visit arg pos.pushAppArg | .mdata _ expr => visit expr pos | .proj _ _ struct => visit struct pos.pushProj | .letE _ type value body _ => visit type pos.pushLetVarType >=> visit value pos.pushLetValue >=> visit body pos.pushLetBody | .lam _ binderType body _ => visit binderType pos.pushBindingDomain >=> visit body pos.pushBindingBody | .forallE _ binderType body _ => visit binderType pos.pushBindingDomain >=> visit body pos.pushBindingBody | _ => pure if e.hasLooseBVars then visitChildren positions else if e.toHeadIndex != pHeadIdx || e.headNumArgs != pNumArgs then visitChildren positions else if ← isDefEq e p then setMCtx mctx -- reset the `MetavarContext` because `isDefEq` can modify it if it succeeds visitChildren (positions.push pos) else visitChildren positions visit e .root #[] /-- Return the subexpression at position `pos` in `e` together with an occurrence number that allows the expression to be found by `kabstract`. Return `none` when the subexpression contains loose bound variables. -/ def viewKAbstractSubExpr (e : Expr) (pos : SubExpr.Pos) : MetaM (Option (Expr × Option Nat)) := do let subExpr ← Core.viewSubexpr pos e if subExpr.hasLooseBVars then return none let positions ← kabstractPositions subExpr e let some n := positions.idxOf? pos | unreachable! return some (subExpr, if positions.size == 1 then none else some (n + 1)) /-- Determine whether the result of abstracting `subExpr` from `e` at position `pos` results in a well typed expression. This is important if you want to rewrite at this position. Here is an example of what goes wrong with an ill-typed kabstract result: ``` example (h : [5] ≠ []) : List.getLast [5] h = 5 := by rw [show [5] = [5] from rfl] -- tactic 'rewrite' failed, motive is not type correct ``` -/ def kabstractIsTypeCorrect (e subExpr : Expr) (pos : SubExpr.Pos) : MetaM Bool := do withLocalDeclD `_a (← inferType subExpr) fun fvar => do isTypeCorrect (← replaceSubexpr (fun _ => pure fvar) pos e) end Lean.Meta
IntegralRestrict.lean
/- Copyright (c) 2023 Andrew Yang, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.DedekindDomain.IntegralClosure import Mathlib.RingTheory.RingHom.Finite import Mathlib.RingTheory.Localization.LocalizationLocalization import Mathlib.RingTheory.Localization.NormTrace /-! # Restriction of various maps between fields to integrally closed subrings. In this file, we assume `A` is an integrally closed domain; `K` is the fraction ring of `A`; `L` is a finite (separable) extension of `K`; `B` is the integral closure of `A` in `L`. We call this the AKLB setup. ## Main definition - `galRestrict`: The restriction `Aut(L/K) → Aut(B/A)` as an `MulEquiv` in an AKLB setup. - `Algebra.intTrace`: The trace map of a finite extension of integrally closed domains `B/A` is defined to be the restriction of the trace map of `Frac(B)/Frac(A)`. - `Algebra.intNorm`: The norm map of a finite extension of integrally closed domains `B/A` is defined to be the restriction of the norm map of `Frac(B)/Frac(A)`. -/ open nonZeroDivisors variable (A K L B : Type*) [CommRing A] [CommRing B] [Algebra A B] [Field K] [Field L] [Algebra A K] [IsFractionRing A K] [Algebra B L] [Algebra K L] [Algebra A L] [IsScalarTower A B L] [IsScalarTower A K L] [IsIntegralClosure B A L] section galois variable [Algebra.IsAlgebraic K L] /-- The lift `End(B/A) → End(L/K)` in an ALKB setup. This is inverse to the restriction. See `galRestrictHom`. -/ noncomputable def galLift (σ : B →ₐ[A] B) : L →ₐ[K] L := haveI := (IsFractionRing.injective A K).isDomain haveI := NoZeroSMulDivisors.trans_faithfulSMul A K L haveI := IsIntegralClosure.isLocalization A K L B haveI H : ∀ (y : Algebra.algebraMapSubmonoid B A⁰), IsUnit (((algebraMap B L).comp σ) (y : B)) := by rintro ⟨_, x, hx, rfl⟩ simpa only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, AlgHom.commutes, isUnit_iff_ne_zero, ne_eq, map_eq_zero_iff _ (FaithfulSMul.algebraMap_injective _ _), ← IsScalarTower.algebraMap_apply] using nonZeroDivisors.ne_zero hx haveI H_eq : (IsLocalization.lift (S := L) H).comp (algebraMap K L) = (algebraMap K L) := by apply IsLocalization.ringHom_ext A⁰ ext simp only [RingHom.coe_comp, Function.comp_apply, ← IsScalarTower.algebraMap_apply A K L, IsScalarTower.algebraMap_apply A B L, IsLocalization.lift_eq, RingHom.coe_coe, AlgHom.commutes] { IsLocalization.lift (S := L) H with commutes' := DFunLike.congr_fun H_eq } /-- The restriction `End(L/K) → End(B/A)` in an AKLB setup. Also see `galRestrict` for the `AlgEquiv` version. -/ noncomputable def galRestrictHom : (L →ₐ[K] L) ≃* (B →ₐ[A] B) where toFun := fun f ↦ (IsIntegralClosure.equiv A (integralClosure A L) L B).toAlgHom.comp (((f.restrictScalars A).comp (IsScalarTower.toAlgHom A B L)).codRestrict (integralClosure A L) (fun x ↦ IsIntegral.map _ (IsIntegralClosure.isIntegral A L x))) map_mul' := by intros σ₁ σ₂ ext x apply (IsIntegralClosure.equiv A (integralClosure A L) L B).symm.injective ext dsimp simp only [AlgEquiv.symm_apply_apply, AlgHom.coe_codRestrict, AlgHom.coe_restrictScalars', AlgHom.coe_comp, IsScalarTower.coe_toAlgHom', Function.comp_apply, AlgHom.mul_apply, IsIntegralClosure.algebraMap_equiv, Subalgebra.algebraMap_eq] rfl invFun := galLift A K L B left_inv σ := have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext (Algebra.algebraMapSubmonoid B A⁰) <| RingHom.ext fun x ↦ by simp [Subalgebra.algebraMap_eq, galLift] right_inv σ := have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B AlgHom.ext fun x ↦ IsIntegralClosure.algebraMap_injective B A L (by simp [Subalgebra.algebraMap_eq, galLift]) @[simp] lemma algebraMap_galRestrictHom_apply (σ : L →ₐ[K] L) (x : B) : algebraMap B L (galRestrictHom A K L B σ x) = σ (algebraMap B L x) := by simp [galRestrictHom, Subalgebra.algebraMap_eq] @[simp, nolint unusedHavesSuffices] -- false positive from unfolding galRestrictHom lemma galRestrictHom_symm_algebraMap_apply (σ : B →ₐ[A] B) (x : B) : (galRestrictHom A K L B).symm σ (algebraMap B L x) = algebraMap B L (σ x) := by have := (IsFractionRing.injective A K).isDomain have := IsIntegralClosure.isLocalization A K L B simp [galRestrictHom, galLift] /-- The restriction `Aut(L/K) → Aut(B/A)` in an AKLB setup. -/ noncomputable def galRestrict : (L ≃ₐ[K] L) ≃* (B ≃ₐ[A] B) := (AlgEquiv.algHomUnitsEquiv K L).symm.trans ((Units.mapEquiv <| galRestrictHom A K L B).trans (AlgEquiv.algHomUnitsEquiv A B)) variable {K L} lemma coe_galRestrict_apply (σ : L ≃ₐ[K] L) : (galRestrict A K L B σ : B →ₐ[A] B) = galRestrictHom A K L B σ := rfl variable {B} lemma galRestrict_apply (σ : L ≃ₐ[K] L) (x : B) : galRestrict A K L B σ x = galRestrictHom A K L B σ x := rfl lemma algebraMap_galRestrict_apply (σ : L ≃ₐ[K] L) (x : B) : algebraMap B L (galRestrict A K L B σ x) = σ (algebraMap B L x) := algebraMap_galRestrictHom_apply A K L B σ.toAlgHom x end galois variable [FiniteDimensional K L] lemma prod_galRestrict_eq_norm [IsGalois K L] [IsIntegrallyClosed A] (x : B) : (∏ σ : L ≃ₐ[K] L, galRestrict A K L B σ x) = algebraMap A B (IsIntegralClosure.mk' (R := A) A (Algebra.norm K <| algebraMap B L x) (Algebra.isIntegral_norm K (IsIntegralClosure.isIntegral A L x).algebraMap)) := by apply IsIntegralClosure.algebraMap_injective B A L rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_eq A K L] simp only [map_prod, algebraMap_galRestrict_apply, IsIntegralClosure.algebraMap_mk', Algebra.norm_eq_prod_automorphisms, RingHom.coe_comp, Function.comp_apply] attribute [local instance] FractionRing.liftAlgebra FractionRing.isScalarTower_liftAlgebra noncomputable instance (priority := 900) [IsDomain A] [IsDomain B] [IsIntegrallyClosed B] [Module.Finite A B] [NoZeroSMulDivisors A B] : Fintype (B ≃ₐ[A] B) := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ Fintype.ofEquiv _ (galRestrict A (FractionRing A) (FractionRing B) B).toEquiv variable {Aₘ Bₘ} [CommRing Aₘ] [CommRing Bₘ] [Algebra Aₘ Bₘ] [Algebra A Aₘ] [Algebra B Bₘ] variable [Algebra A Bₘ] [IsScalarTower A Aₘ Bₘ] [IsScalarTower A B Bₘ] variable (M : Submonoid A) [IsLocalization M Aₘ] variable [IsLocalization (Algebra.algebraMapSubmonoid B M) Bₘ] section trace /-- The restriction of the trace on `L/K` restricted onto `B/A` in an AKLB setup. See `Algebra.intTrace` instead. -/ noncomputable def Algebra.intTraceAux [IsIntegrallyClosed A] : B →ₗ[A] A := (IsIntegralClosure.equiv A (integralClosure A K) K A).toLinearMap.comp ((((Algebra.trace K L).restrictScalars A).comp (IsScalarTower.toAlgHom A B L).toLinearMap).codRestrict (Subalgebra.toSubmodule <| integralClosure A K) (fun x ↦ isIntegral_trace (IsIntegral.algebraMap (IsIntegralClosure.isIntegral A L x)))) variable {A K L B} lemma Algebra.map_intTraceAux [IsIntegrallyClosed A] (x : B) : algebraMap A K (Algebra.intTraceAux A K L B x) = Algebra.trace K L (algebraMap B L x) := IsIntegralClosure.algebraMap_equiv A (integralClosure A K) K A _ variable (A B) variable [IsDomain A] [IsIntegrallyClosed A] [IsDomain B] [IsIntegrallyClosed B] variable [Module.Finite A B] [NoZeroSMulDivisors A B] /-- The trace of a finite extension of integrally closed domains `B/A` is the restriction of the trace on `Frac(B)/Frac(A)` onto `B/A`. See `Algebra.algebraMap_intTrace`. -/ noncomputable def Algebra.intTrace : B →ₗ[A] A := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ Algebra.intTraceAux A (FractionRing A) (FractionRing B) B variable {A B} lemma Algebra.algebraMap_intTrace (x : B) : algebraMap A K (Algebra.intTrace A B x) = Algebra.trace K L (algebraMap B L x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ haveI := IsIntegralClosure.isFractionRing_of_finite_extension A K L B apply (FractionRing.algEquiv A K).symm.injective rw [AlgEquiv.commutes, Algebra.intTrace, Algebra.map_intTraceAux, ← AlgEquiv.commutes (FractionRing.algEquiv B L)] apply Algebra.trace_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv apply IsLocalization.ringHom_ext A⁰ simp only [AlgEquiv.toRingEquiv_eq_coe, ← AlgEquiv.coe_ringHom_commutes, RingHom.comp_assoc, AlgHom.comp_algebraMap_of_tower, ← IsScalarTower.algebraMap_eq, RingHom.comp_assoc] lemma Algebra.algebraMap_intTrace_fractionRing (x : B) : algebraMap A (FractionRing A) (Algebra.intTrace A B x) = Algebra.trace (FractionRing A) (FractionRing B) (algebraMap B _ x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ exact Algebra.map_intTraceAux x variable (A B) lemma Algebra.intTrace_eq_trace [Module.Free A B] : Algebra.intTrace A B = Algebra.trace A B := by ext x haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ apply IsFractionRing.injective A (FractionRing A) rw [Algebra.algebraMap_intTrace_fractionRing, Algebra.trace_localization A A⁰] open nonZeroDivisors variable [IsDomain Aₘ] [IsIntegrallyClosed Aₘ] [IsDomain Bₘ] [IsIntegrallyClosed Bₘ] variable [NoZeroSMulDivisors Aₘ Bₘ] [Module.Finite Aₘ Bₘ] include M in lemma Algebra.intTrace_eq_of_isLocalization (x : B) : algebraMap A Aₘ (Algebra.intTrace A B x) = Algebra.intTrace Aₘ Bₘ (algebraMap B Bₘ x) := by by_cases hM : 0 ∈ M · subsingleton [IsLocalization.uniqueOfZeroMem (S := Aₘ) hM] replace hM : M ≤ A⁰ := fun x hx ↦ mem_nonZeroDivisors_iff_ne_zero.mpr (fun e ↦ hM (e ▸ hx)) let K := FractionRing A let L := FractionRing B have : IsIntegralClosure B A L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ have : IsLocalization (algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ let f : Aₘ →+* K := IsLocalization.map _ (T := A⁰) (RingHom.id A) hM letI := f.toAlgebra have : IsScalarTower A Aₘ K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M Aₘ K let g : Bₘ →+* L := IsLocalization.map _ (M := algebraMapSubmonoid B M) (T := algebraMapSubmonoid B A⁰) (RingHom.id B) (Submonoid.monotone_map hM) letI := g.toAlgebra have : IsScalarTower B Bₘ L := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := ((algebraMap K L).comp f).toAlgebra have : IsScalarTower Aₘ K L := IsScalarTower.of_algebraMap_eq' rfl have : IsScalarTower Aₘ Bₘ L := by apply IsScalarTower.of_algebraMap_eq' apply IsLocalization.ringHom_ext M rw [RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra (R := Bₘ), RingHom.comp_assoc, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq A B Bₘ, IsLocalization.map_comp, RingHom.comp_id, ← RingHom.comp_assoc, IsLocalization.map_comp, RingHom.comp_id, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization (algebraMapSubmonoid B M) Bₘ L have : FiniteDimensional K L := .of_isLocalization A B A⁰ have : IsIntegralClosure Bₘ Aₘ L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ apply IsFractionRing.injective Aₘ K rw [← IsScalarTower.algebraMap_apply, Algebra.algebraMap_intTrace_fractionRing, Algebra.algebraMap_intTrace (L := L), ← IsScalarTower.algebraMap_apply] end trace section norm variable [IsIntegrallyClosed A] /-- The restriction of the norm on `L/K` restricted onto `B/A` in an AKLB setup. See `Algebra.intNorm` instead. -/ noncomputable def Algebra.intNormAux [Algebra.IsSeparable K L] : B →* A where toFun := fun s ↦ IsIntegralClosure.mk' (R := A) A (Algebra.norm K (algebraMap B L s)) (isIntegral_norm K <| IsIntegral.map (IsScalarTower.toAlgHom A B L) (IsIntegralClosure.isIntegral A L s)) map_one' := by simp map_mul' := fun x y ↦ by simpa using IsIntegralClosure.mk'_mul _ _ _ _ _ variable {A K L B} lemma Algebra.map_intNormAux [Algebra.IsSeparable K L] (x : B) : algebraMap A K (Algebra.intNormAux A K L B x) = Algebra.norm K (algebraMap B L x) := by dsimp [Algebra.intNormAux] exact IsIntegralClosure.algebraMap_mk' _ _ _ variable (A B) variable [IsDomain A] [IsDomain B] [IsIntegrallyClosed B] variable [Module.Finite A B] [NoZeroSMulDivisors A B] variable [Algebra.IsSeparable (FractionRing A) (FractionRing B)] -- TODO: remove this /-- The norm of a finite extension of integrally closed domains `B/A` is the restriction of the norm on `Frac(B)/Frac(A)` onto `B/A`. See `Algebra.algebraMap_intNorm`. -/ noncomputable def Algebra.intNorm : B →* A := haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ Algebra.intNormAux A (FractionRing A) (FractionRing B) B variable {A B} lemma Algebra.algebraMap_intNorm (x : B) : algebraMap A K (Algebra.intNorm A B x) = Algebra.norm K (algebraMap B L x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ haveI := IsIntegralClosure.isFractionRing_of_finite_extension A K L B apply (FractionRing.algEquiv A K).symm.injective rw [AlgEquiv.commutes, Algebra.intNorm, Algebra.map_intNormAux, ← AlgEquiv.commutes (FractionRing.algEquiv B L)] apply Algebra.norm_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv apply IsLocalization.ringHom_ext A⁰ simp only [AlgEquiv.toRingEquiv_eq_coe, ← AlgEquiv.coe_ringHom_commutes, RingHom.comp_assoc, AlgHom.comp_algebraMap_of_tower, ← IsScalarTower.algebraMap_eq, RingHom.comp_assoc] @[simp] lemma Algebra.algebraMap_intNorm_fractionRing (x : B) : algebraMap A (FractionRing A) (Algebra.intNorm A B x) = Algebra.norm (FractionRing A) (algebraMap B (FractionRing B) x) := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ exact Algebra.map_intNormAux x variable (A B) lemma Algebra.intNorm_eq_norm [Module.Free A B] : Algebra.intNorm A B = Algebra.norm A := by ext x haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ apply IsFractionRing.injective A (FractionRing A) rw [Algebra.algebraMap_intNorm_fractionRing, Algebra.norm_localization A A⁰] @[simp] lemma Algebra.intNorm_zero : Algebra.intNorm A B 0 = 0 := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ apply IsFractionRing.injective A (FractionRing A) simp variable {A B} @[simp] lemma Algebra.intNorm_eq_zero {x : B} : Algebra.intNorm A B x = 0 ↔ x = 0 := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ rw [← (IsFractionRing.injective A (FractionRing A)).eq_iff, ← (IsFractionRing.injective B (FractionRing B)).eq_iff] simp only [algebraMap_intNorm_fractionRing, map_zero, norm_eq_zero_iff] lemma Algebra.intNorm_ne_zero {x : B} : Algebra.intNorm A B x ≠ 0 ↔ x ≠ 0 := by simp variable [IsDomain Aₘ] [IsIntegrallyClosed Aₘ] [IsDomain Bₘ] [IsIntegrallyClosed Bₘ] variable [NoZeroSMulDivisors Aₘ Bₘ] [Module.Finite Aₘ Bₘ] variable [Algebra.IsSeparable (FractionRing Aₘ) (FractionRing Bₘ)] include M in lemma Algebra.intNorm_eq_of_isLocalization (x : B) : algebraMap A Aₘ (Algebra.intNorm A B x) = Algebra.intNorm Aₘ Bₘ (algebraMap B Bₘ x) := by by_cases hM : 0 ∈ M · subsingleton [IsLocalization.uniqueOfZeroMem (S := Aₘ) hM] replace hM : M ≤ A⁰ := fun x hx ↦ mem_nonZeroDivisors_iff_ne_zero.mpr (fun e ↦ hM (e ▸ hx)) let K := FractionRing A let L := FractionRing B have : IsIntegralClosure B A L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ have : IsLocalization (algebraMapSubmonoid B A⁰) L := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ let f : Aₘ →+* K := IsLocalization.map _ (T := A⁰) (RingHom.id A) hM letI := f.toAlgebra have : IsScalarTower A Aₘ K := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M Aₘ K let g : Bₘ →+* L := IsLocalization.map _ (M := algebraMapSubmonoid B M) (T := algebraMapSubmonoid B A⁰) (RingHom.id B) (Submonoid.monotone_map hM) letI := g.toAlgebra have : IsScalarTower B Bₘ L := IsScalarTower.of_algebraMap_eq' (by rw [RingHom.algebraMap_toAlgebra, IsLocalization.map_comp, RingHomCompTriple.comp_eq]) letI := ((algebraMap K L).comp f).toAlgebra have : IsScalarTower Aₘ K L := IsScalarTower.of_algebraMap_eq' rfl have : IsScalarTower Aₘ Bₘ L := by apply IsScalarTower.of_algebraMap_eq' apply IsLocalization.ringHom_ext M rw [RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra (R := Bₘ), RingHom.comp_assoc, RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, IsScalarTower.algebraMap_eq A B Bₘ, IsLocalization.map_comp, RingHom.comp_id, ← RingHom.comp_assoc, IsLocalization.map_comp, RingHom.comp_id, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] letI := IsFractionRing.isFractionRing_of_isDomain_of_isLocalization (algebraMapSubmonoid B M) Bₘ L have : FiniteDimensional K L := .of_isLocalization A B A⁰ have : IsIntegralClosure Bₘ Aₘ L := IsIntegralClosure.of_isIntegrallyClosed _ _ _ apply IsFractionRing.injective Aₘ K rw [← IsScalarTower.algebraMap_apply, Algebra.algebraMap_intNorm_fractionRing, Algebra.algebraMap_intNorm (L := L), ← IsScalarTower.algebraMap_apply] end norm variable [IsDomain A] [IsIntegrallyClosed A] [IsDomain B] [IsIntegrallyClosed B] [Module.Finite A B] [NoZeroSMulDivisors A B] lemma Algebra.algebraMap_intNorm_of_isGalois [IsGalois (FractionRing A) (FractionRing B)] {x : B} : algebraMap A B (Algebra.intNorm A B x) = ∏ σ : B ≃ₐ[A] B, σ x := by haveI : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ haveI : IsLocalization (Algebra.algebraMapSubmonoid B A⁰) (FractionRing B) := IsIntegralClosure.isLocalization _ (FractionRing A) _ _ haveI : FiniteDimensional (FractionRing A) (FractionRing B) := .of_isLocalization A B A⁰ rw [← (galRestrict A (FractionRing A) (FractionRing B) B).toEquiv.prod_comp] simp only [MulEquiv.toEquiv_eq_coe, EquivLike.coe_coe] convert (prod_galRestrict_eq_norm A (FractionRing A) (FractionRing B) B x).symm theorem Algebra.dvd_algebraMap_intNorm_self [Algebra.IsSeparable (FractionRing A) (FractionRing B)] (x : B) : x ∣ algebraMap A B (intNorm A B x) := by classical by_cases hx : x = 0 · exact ⟨1, by simp [hx]⟩ let K := FractionRing A let L := FractionRing B let E := AlgebraicClosure L suffices IsIntegral A ((algebraMap B L x)⁻¹ * (algebraMap A L (intNorm A B x))) by obtain ⟨y, hy⟩ := IsIntegrallyClosed.isIntegral_iff.mp <| _root_.IsIntegral.tower_top (A := B) this refine ⟨y, ?_⟩ apply FaithfulSMul.algebraMap_injective B L rw [← IsScalarTower.algebraMap_apply, map_mul, hy, mul_inv_cancel_left₀] exact (map_ne_zero_iff _ (FaithfulSMul.algebraMap_injective B L)).mpr hx rw [← isIntegral_algHom_iff (IsScalarTower.toAlgHom A L E) (FaithfulSMul.algebraMap_injective L E), IsScalarTower.coe_toAlgHom', map_mul, map_inv₀, IsScalarTower.algebraMap_apply A K L, algebraMap_intNorm (L := L), ← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, norm_eq_prod_embeddings, ← Finset.univ.mul_prod_erase _ (Finset.mem_univ (IsScalarTower.toAlgHom K L E)), IsScalarTower.coe_toAlgHom', ← IsScalarTower.algebraMap_apply, inv_mul_cancel_left₀] · refine _root_.IsIntegral.prod _ fun σ _ ↦ ?_ change IsIntegral A ((σ.restrictScalars A) (IsScalarTower.toAlgHom A B L x)) rw [isIntegral_algHom_iff _ (RingHom.injective _), isIntegral_algHom_iff _ (FaithfulSMul.algebraMap_injective B L)] exact IsIntegral.isIntegral x · have := NoZeroSMulDivisors.trans_faithfulSMul B L E exact (map_ne_zero_iff _ (FaithfulSMul.algebraMap_injective B E)).mpr hx
Basic.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.Equiv.Defs import Mathlib.Algebra.Group.Hom.Basic import Mathlib.Logic.Equiv.Basic import Mathlib.Tactic.Spread /-! # Multiplicative and additive equivs This file contains basic results on `MulEquiv` and `AddEquiv`. ## Tags Equiv, MulEquiv, AddEquiv -/ assert_not_exists Fintype open Function variable {F α β M M₁ M₂ M₃ N N₁ N₂ N₃ P Q G H : Type*} namespace EmbeddingLike variable [One M] [One N] [FunLike F M N] [EmbeddingLike F M N] [OneHomClass F M N] end EmbeddingLike variable [EquivLike F α β] @[to_additive] theorem MulEquivClass.toMulEquiv_injective [Mul α] [Mul β] [MulEquivClass F α β] : Function.Injective ((↑) : F → α ≃* β) := fun _ _ e ↦ DFunLike.ext _ _ fun a ↦ congr_arg (fun e : α ≃* β ↦ e.toFun a) e namespace MulEquiv section Mul variable [Mul M] [Mul N] [Mul P] section unique /-- The `MulEquiv` between two monoids with a unique element. -/ @[to_additive /-- The `AddEquiv` between two `AddMonoid`s with a unique element. -/] def ofUnique {M N} [Unique M] [Unique N] [Mul M] [Mul N] : M ≃* N := { Equiv.ofUnique M N with map_mul' := fun _ _ => Subsingleton.elim _ _ } /-- There is a unique monoid homomorphism between two monoids with a unique element. -/ @[to_additive /-- There is a unique additive monoid homomorphism between two additive monoids with a unique element. -/] instance {M N} [Unique M] [Unique N] [Mul M] [Mul N] : Unique (M ≃* N) where default := ofUnique uniq _ := ext fun _ => Subsingleton.elim _ _ end unique end Mul /-! ## Monoids -/ /-- A multiplicative analogue of `Equiv.arrowCongr`, where the equivalence between the targets is multiplicative. -/ @[to_additive (attr := simps apply) /-- An additive analogue of `Equiv.arrowCongr`, where the equivalence between the targets is additive. -/] def arrowCongr {M N P Q : Type*} [Mul P] [Mul Q] (f : M ≃ N) (g : P ≃* Q) : (M → P) ≃* (N → Q) where toFun h n := g (h (f.symm n)) invFun k m := g.symm (k (f m)) left_inv h := by ext; simp right_inv k := by ext; simp map_mul' h k := by ext; simp section monoidHomCongrEquiv variable [MulOneClass M] [MulOneClass M₁] [MulOneClass M₂] [MulOneClass M₃] [Monoid N] [Monoid N₁] [Monoid N₂] [Monoid N₃] /-- The equivalence `(M₁ →* N) ≃ (M₂ →* N)` obtained by postcomposition with a multiplicative equivalence `e : M₁ ≃* M₂`. -/ @[to_additive (attr := simps) /-- The equivalence `(M₁ →+ N) ≃ (M₂ →+ N)` obtained by postcomposition with an additive equivalence `e : M₁ ≃+ M₂`. -/] def monoidHomCongrLeftEquiv (e : M₁ ≃* M₂) : (M₁ →* N) ≃ (M₂ →* N) where toFun f := f.comp e.symm.toMonoidHom invFun f := f.comp e.toMonoidHom left_inv f := by ext; simp right_inv f := by ext; simp /-- The equivalence `(M →* N₁) ≃ (M →* N₂)` obtained by postcomposition with a multiplicative equivalence `e : N₁ ≃* N₂`. -/ @[to_additive (attr := simps) /-- The equivalence `(M →+ N₁) ≃ (M →+ N₂)` obtained by postcomposition with an additive equivalence `e : N₁ ≃+ N₂`. -/] def monoidHomCongrRightEquiv (e : N₁ ≃* N₂) : (M →* N₁) ≃ (M →* N₂) where toFun := e.toMonoidHom.comp invFun := e.symm.toMonoidHom.comp left_inv f := by ext; simp right_inv f := by ext; simp @[to_additive (attr := simp)] lemma monoidHomCongrLeftEquiv_refl : monoidHomCongrLeftEquiv (.refl M) = .refl (M →* N) := rfl @[to_additive (attr := simp)] lemma monoidHomCongrRightEquiv_refl : monoidHomCongrRightEquiv (.refl N) = .refl (M →* N) := rfl @[to_additive (attr := simp)] lemma symm_monoidHomCongrLeftEquiv (e : M₁ ≃* M₂) : (monoidHomCongrLeftEquiv e).symm = monoidHomCongrLeftEquiv (N := N) e.symm := rfl @[to_additive (attr := simp)] lemma symm_monoidHomCongrRightEquiv (e : N₁ ≃* N₂) : (monoidHomCongrRightEquiv e).symm = monoidHomCongrRightEquiv (M := M) e.symm := rfl @[to_additive (attr := simp)] lemma monoidHomCongrLeftEquiv_trans (e₁₂ : M₁ ≃* M₂) (e₂₃ : M₂ ≃* M₃) : monoidHomCongrLeftEquiv (N := N) (e₁₂.trans e₂₃) = (monoidHomCongrLeftEquiv e₁₂).trans (monoidHomCongrLeftEquiv e₂₃) := rfl @[to_additive (attr := simp)] lemma monoidHomCongrRightEquiv_trans (e₁₂ : N₁ ≃* N₂) (e₂₃ : N₂ ≃* N₃) : monoidHomCongrRightEquiv (M := M) (e₁₂.trans e₂₃) = (monoidHomCongrRightEquiv e₁₂).trans (monoidHomCongrRightEquiv e₂₃) := rfl end monoidHomCongrEquiv section monoidHomCongr variable [MulOneClass M] [MulOneClass M₁] [MulOneClass M₂] [MulOneClass M₃] [CommMonoid N] [CommMonoid N₁] [CommMonoid N₂] [CommMonoid N₃] /-- The isomorphism `(M₁ →* N) ≃* (M₂ →* N)` obtained by postcomposition with a multiplicative equivalence `e : M₁ ≃* M₂`. -/ @[to_additive (attr := simps! apply) /-- The isomorphism `(M₁ →+ N) ≃+ (M₂ →+ N)` obtained by postcomposition with an additive equivalence `e : M₁ ≃+ M₂`. -/] def monoidHomCongrLeft (e : M₁ ≃* M₂) : (M₁ →* N) ≃* (M₂ →* N) where __ := e.monoidHomCongrLeftEquiv map_mul' f g := by ext; simp /-- The isomorphism `(M →* N₁) ≃* (M →* N₂)` obtained by postcomposition with a multiplicative equivalence `e : N₁ ≃* N₂`. -/ @[to_additive (attr := simps! apply) /-- The isomorphism `(M →+ N₁) ≃+ (M →+ N₂)` obtained by postcomposition with an additive equivalence `e : N₁ ≃+ N₂`. -/] def monoidHomCongrRight (e : N₁ ≃* N₂) : (M →* N₁) ≃* (M →* N₂) where __ := e.monoidHomCongrRightEquiv map_mul' f g := by ext; simp @[to_additive (attr := simp)] lemma monoidHomCongrLeft_refl : monoidHomCongrLeft (.refl M) = .refl (M →* N) := rfl @[to_additive (attr := simp)] lemma monoidHomCongrRight_refl : monoidHomCongrRight (.refl N) = .refl (M →* N) := rfl @[to_additive (attr := simp)] lemma symm_monoidHomCongrLeft (e : M₁ ≃* M₂) : (monoidHomCongrLeft e).symm = monoidHomCongrLeft (N := N) e.symm := rfl @[to_additive (attr := simp)] lemma symm_monoidHomCongrRight (e : N₁ ≃* N₂) : (monoidHomCongrRight e).symm = monoidHomCongrRight (M := M) e.symm := rfl @[to_additive (attr := simp)] lemma monoidHomCongrLeft_trans (e₁₂ : M₁ ≃* M₂) (e₂₃ : M₂ ≃* M₃) : monoidHomCongrLeft (N := N) (e₁₂.trans e₂₃) = (monoidHomCongrLeft e₁₂).trans (monoidHomCongrLeft e₂₃) := rfl @[to_additive (attr := simp)] lemma monoidHomCongrRight_trans (e₁₂ : N₁ ≃* N₂) (e₂₃ : N₂ ≃* N₃) : monoidHomCongrRight (M := M) (e₁₂.trans e₂₃) = (monoidHomCongrRight e₁₂).trans (monoidHomCongrRight e₂₃) := rfl end monoidHomCongr /-- A multiplicative analogue of `Equiv.arrowCongr`, for multiplicative maps from a monoid to a commutative monoid. -/ @[to_additive (attr := deprecated MulEquiv.monoidHomCongrLeft (since := "2025-08-12")) /-- An additive analogue of `Equiv.arrowCongr`, for additive maps from an additive monoid to a commutative additive monoid. -/] def monoidHomCongr {M N P Q} [MulOneClass M] [MulOneClass N] [CommMonoid P] [CommMonoid Q] (f : M ≃* N) (g : P ≃* Q) : (M →* P) ≃* (N →* Q) := f.monoidHomCongrLeft.trans g.monoidHomCongrRight /-- A family of multiplicative equivalences `Π j, (Ms j ≃* Ns j)` generates a multiplicative equivalence between `Π j, Ms j` and `Π j, Ns j`. This is the `MulEquiv` version of `Equiv.piCongrRight`, and the dependent version of `MulEquiv.arrowCongr`. -/ @[to_additive (attr := simps apply) /-- A family of additive equivalences `Π j, (Ms j ≃+ Ns j)` generates an additive equivalence between `Π j, Ms j` and `Π j, Ns j`. This is the `AddEquiv` version of `Equiv.piCongrRight`, and the dependent version of `AddEquiv.arrowCongr`. -/] def piCongrRight {η : Type*} {Ms Ns : η → Type*} [∀ j, Mul (Ms j)] [∀ j, Mul (Ns j)] (es : ∀ j, Ms j ≃* Ns j) : (∀ j, Ms j) ≃* ∀ j, Ns j := { Equiv.piCongrRight fun j => (es j).toEquiv with toFun := fun x j => es j (x j), invFun := fun x j => (es j).symm (x j), map_mul' := fun x y => funext fun j => map_mul (es j) (x j) (y j) } @[to_additive (attr := simp)] theorem piCongrRight_refl {η : Type*} {Ms : η → Type*} [∀ j, Mul (Ms j)] : (piCongrRight fun j => MulEquiv.refl (Ms j)) = MulEquiv.refl _ := rfl @[to_additive (attr := simp)] theorem piCongrRight_symm {η : Type*} {Ms Ns : η → Type*} [∀ j, Mul (Ms j)] [∀ j, Mul (Ns j)] (es : ∀ j, Ms j ≃* Ns j) : (piCongrRight es).symm = piCongrRight fun i => (es i).symm := rfl @[to_additive (attr := simp)] theorem piCongrRight_trans {η : Type*} {Ms Ns Ps : η → Type*} [∀ j, Mul (Ms j)] [∀ j, Mul (Ns j)] [∀ j, Mul (Ps j)] (es : ∀ j, Ms j ≃* Ns j) (fs : ∀ j, Ns j ≃* Ps j) : (piCongrRight es).trans (piCongrRight fs) = piCongrRight fun i => (es i).trans (fs i) := rfl /-- A family indexed by a type with a unique element is `MulEquiv` to the element at the single index. -/ @[to_additive (attr := simps!) /-- A family indexed by a type with a unique element is `AddEquiv` to the element at the single index. -/] def piUnique {ι : Type*} (M : ι → Type*) [∀ j, Mul (M j)] [Unique ι] : (∀ j, M j) ≃* M default := { Equiv.piUnique M with map_mul' := fun _ _ => Pi.mul_apply _ _ _ } end MulEquiv namespace MonoidHom variable {M N₁ N₂ : Type*} [Monoid M] [CommMonoid N₁] [CommMonoid N₂] /-- The equivalence `(β →* γ) ≃ (α →* γ)` obtained by precomposition with a multiplicative equivalence `e : α ≃* β`. -/ @[to_additive (attr := simps -isSimp, deprecated MulEquiv.monoidHomCongrLeftEquiv (since := "2025-08-12")) /-- The equivalence `(β →+ γ) ≃ (α →+ γ)` obtained by precomposition with an additive equivalence `e : α ≃+ β`. -/] def precompEquiv {α β : Type*} [Monoid α] [Monoid β] (e : α ≃* β) (γ : Type*) [Monoid γ] : (β →* γ) ≃ (α →* γ) where toFun f := f.comp e invFun g := g.comp e.symm left_inv _ := by ext; simp right_inv _ := by ext; simp /-- The equivalence `(γ →* α) ≃ (γ →* β)` obtained by postcomposition with a multiplicative equivalence `e : α ≃* β`. -/ @[to_additive (attr := simps -isSimp, deprecated MulEquiv.monoidHomCongrRightEquiv (since := "2025-08-12")) /-- The equivalence `(γ →+ α) ≃ (γ →+ β)` obtained by postcomposition with an additive equivalence `e : α ≃+ β`. -/] def postcompEquiv {α β : Type*} [Monoid α] [Monoid β] (e : α ≃* β) (γ : Type*) [Monoid γ] : (γ →* α) ≃ (γ →* β) where toFun f := e.toMonoidHom.comp f invFun g := e.symm.toMonoidHom.comp g left_inv _ := by ext; simp right_inv _ := by ext; simp end MonoidHom namespace Equiv section InvolutiveInv variable (G) [InvolutiveInv G] /-- Inversion on a `Group` or `GroupWithZero` is a permutation of the underlying type. -/ @[to_additive (attr := simps! -fullyApplied apply) /-- Negation on an `AddGroup` is a permutation of the underlying type. -/] protected def inv : Perm G := inv_involutive.toPerm _ variable {G} @[to_additive (attr := simp)] theorem inv_symm : (Equiv.inv G).symm = Equiv.inv G := rfl end InvolutiveInv end Equiv
Defs.lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Fabian Glöckle, Kyle Miller -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.Span.Defs /-! # Dual vector spaces The dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \to R$. ## Main definitions * Duals and transposes: * `Module.Dual R M` defines the dual space of the `R`-module `M`, as `M →ₗ[R] R`. * `Module.dualPairing R M` is the canonical pairing between `Dual R M` and `M`. * `Module.Dual.eval R M : M →ₗ[R] Dual R (Dual R)` is the canonical map to the double dual. * `Module.Dual.transpose` is the linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. * `LinearMap.dualMap` is `Module.Dual.transpose` of a given linear map, for dot notation. * `LinearEquiv.dualMap` is for the dual of an equivalence. * Submodules: * `Submodule.dualRestrict W` is the transpose `Dual R M →ₗ[R] Dual R W` of the inclusion map. * `Submodule.dualAnnihilator W` is the kernel of `W.dualRestrict`. That is, it is the submodule of `dual R M` whose elements all annihilate `W`. * `Submodule.dualPairing W` is the canonical pairing between `Dual R M ⧸ W.dualAnnihilator` and `W`. It is nondegenerate for vector spaces (`Subspace.dualPairing_nondegenerate`). ## Main results * Annihilators: * `Module.dualAnnihilator_gc R M` is the antitone Galois correspondence between `Submodule.dualAnnihilator` and `Submodule.dualConnihilator`. * Finite-dimensional vector spaces: * `Module.evalEquiv` is the equivalence `V ≃ₗ[K] Dual K (Dual K V)` * `Module.mapEvalEquiv` is the order isomorphism between subspaces of `V` and subspaces of `Dual K (Dual K V)`. -/ open Module Submodule noncomputable section namespace Module variable (R A M : Type*) variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- The dual space of an R-module M is the R-module of linear maps `M → R`. -/ abbrev Dual := M →ₗ[R] R /-- The canonical pairing of a vector space and its algebraic dual. -/ def dualPairing (R M) [CommSemiring R] [AddCommMonoid M] [Module R M] : Module.Dual R M →ₗ[R] M →ₗ[R] R := LinearMap.id @[simp] theorem dualPairing_apply (v x) : dualPairing R M v x = v x := rfl namespace Dual instance : Inhabited (Dual R M) := ⟨0⟩ /-- Maps a module M to the dual of the dual of M. See `Module.erange_coe` and `Module.evalEquiv`. -/ def eval : M →ₗ[R] Dual R (Dual R M) := LinearMap.flip LinearMap.id @[simp] theorem eval_apply (v : M) (a : Dual R M) : eval R M v a = a v := rfl variable {R M} {M' : Type*} variable [AddCommMonoid M'] [Module R M'] /-- The transposition of linear maps, as a linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. -/ def transpose : (M →ₗ[R] M') →ₗ[R] Dual R M' →ₗ[R] Dual R M := (LinearMap.llcomp R M M' R).flip theorem transpose_apply (u : M →ₗ[R] M') (l : Dual R M') : transpose u l = l.comp u := rfl variable {M'' : Type*} [AddCommMonoid M''] [Module R M''] theorem transpose_comp (u : M' →ₗ[R] M'') (v : M →ₗ[R] M') : transpose (u.comp v) = (transpose v).comp (transpose u) := rfl end Dual end Module section DualMap open Module variable {R M₁ M₂ : Type*} [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] /-- Given a linear map `f : M₁ →ₗ[R] M₂`, `f.dualMap` is the linear map between the dual of `M₂` and `M₁` such that it maps the functional `φ` to `φ ∘ f`. -/ def LinearMap.dualMap (f : M₁ →ₗ[R] M₂) : Dual R M₂ →ₗ[R] Dual R M₁ := Module.Dual.transpose f lemma LinearMap.dualMap_eq_lcomp (f : M₁ →ₗ[R] M₂) : f.dualMap = f.lcomp R R := rfl theorem LinearMap.dualMap_def (f : M₁ →ₗ[R] M₂) : f.dualMap = Module.Dual.transpose f := rfl theorem LinearMap.dualMap_apply' (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) : f.dualMap g = g.comp f := rfl @[simp] theorem LinearMap.dualMap_apply (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl @[simp] theorem LinearMap.dualMap_id : (LinearMap.id : M₁ →ₗ[R] M₁).dualMap = LinearMap.id := by ext rfl theorem LinearMap.dualMap_comp_dualMap {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (f : M₁ →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : f.dualMap.comp g.dualMap = (g.comp f).dualMap := rfl /-- If a linear map is surjective, then its dual is injective. -/ theorem LinearMap.dualMap_injective_of_surjective {f : M₁ →ₗ[R] M₂} (hf : Function.Surjective f) : Function.Injective f.dualMap := by intro φ ψ h ext x obtain ⟨y, rfl⟩ := hf x exact congr_arg (fun g : Module.Dual R M₁ => g y) h /-- The `Linear_equiv` version of `LinearMap.dualMap`. -/ def LinearEquiv.dualMap (f : M₁ ≃ₗ[R] M₂) : Dual R M₂ ≃ₗ[R] Dual R M₁ where __ := f.toLinearMap.dualMap invFun := f.symm.toLinearMap.dualMap left_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.right_inv x) right_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.left_inv x) @[simp] theorem LinearEquiv.dualMap_apply (f : M₁ ≃ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl @[simp] theorem LinearEquiv.dualMap_refl : (LinearEquiv.refl R M₁).dualMap = LinearEquiv.refl R (Dual R M₁) := by ext rfl @[simp] theorem LinearEquiv.dualMap_symm {f : M₁ ≃ₗ[R] M₂} : (LinearEquiv.dualMap f).symm = LinearEquiv.dualMap f.symm := rfl theorem LinearEquiv.dualMap_trans {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (f : M₁ ≃ₗ[R] M₂) (g : M₂ ≃ₗ[R] M₃) : g.dualMap.trans f.dualMap = (f.trans g).dualMap := rfl theorem Module.Dual.eval_naturality (f : M₁ →ₗ[R] M₂) : f.dualMap.dualMap ∘ₗ eval R M₁ = eval R M₂ ∘ₗ f := by rfl @[simp] lemma Dual.apply_one_mul_eq (f : Dual R R) (r : R) : f 1 * r = f r := by conv_rhs => rw [← mul_one r, ← smul_eq_mul] rw [map_smul, smul_eq_mul, mul_comm] @[simp] lemma LinearMap.range_dualMap_dual_eq_span_singleton (f : Dual R M₁) : range f.dualMap = R ∙ f := by ext m rw [Submodule.mem_span_singleton] refine ⟨fun ⟨r, hr⟩ ↦ ⟨r 1, ?_⟩, fun ⟨r, hr⟩ ↦ ⟨r • LinearMap.id, ?_⟩⟩ · ext; simp [dualMap_apply', ← hr] · ext; simp [dualMap_apply', ← hr] end DualMap namespace Module variable {K V : Type*} variable [CommSemiring K] [AddCommMonoid V] [Module K V] open Module Module.Dual Submodule LinearMap Module section IsReflexive open Function variable (R M N : Type*) variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] /-- A reflexive module is one for which the natural map to its double dual is a bijection. Any finitely-generated projective module (and thus any finite-dimensional vector space) is reflexive. See `Module.instIsReflexiveOfFiniteOfProjective`. -/ class IsReflexive : Prop where /-- A reflexive module is one for which the natural map to its double dual is a bijection. -/ bijective_dual_eval' : Bijective (Dual.eval R M) lemma bijective_dual_eval [IsReflexive R M] : Bijective (Dual.eval R M) := IsReflexive.bijective_dual_eval' variable [IsReflexive R M] theorem erange_coe : LinearMap.range (eval R M) = ⊤ := range_eq_top.mpr (bijective_dual_eval _ _).2 /-- The bijection between a reflexive module and its double dual, bundled as a `LinearEquiv`. -/ def evalEquiv : M ≃ₗ[R] Dual R (Dual R M) := LinearEquiv.ofBijective _ (bijective_dual_eval R M) @[simp] lemma evalEquiv_toLinearMap : evalEquiv R M = Dual.eval R M := rfl @[simp] lemma evalEquiv_apply (m : M) : evalEquiv R M m = Dual.eval R M m := rfl @[simp] lemma apply_evalEquiv_symm_apply (f : Dual R M) (g : Dual R (Dual R M)) : f ((evalEquiv R M).symm g) = g f := by set m := (evalEquiv R M).symm g rw [← (evalEquiv R M).apply_symm_apply g, evalEquiv_apply, Dual.eval_apply] @[simp] lemma symm_dualMap_evalEquiv : (evalEquiv R M).symm.dualMap = Dual.eval R (Dual R M) := by ext; simp @[simp] lemma Dual.eval_comp_comp_evalEquiv_eq {M' : Type*} [AddCommMonoid M'] [Module R M'] {f : M →ₗ[R] M'} : Dual.eval R M' ∘ₗ f ∘ₗ (evalEquiv R M).symm = f.dualMap.dualMap := by rw [← LinearMap.comp_assoc, LinearEquiv.comp_toLinearMap_symm_eq, evalEquiv_toLinearMap, eval_naturality] lemma dualMap_dualMap_eq_iff_of_injective {M' : Type*} [AddCommMonoid M'] [Module R M'] {f g : M →ₗ[R] M'} (h : Injective (Dual.eval R M')) : f.dualMap.dualMap = g.dualMap.dualMap ↔ f = g := by simp only [← Dual.eval_comp_comp_evalEquiv_eq] refine ⟨fun hfg => ?_, fun a ↦ congrArg (Dual.eval R M').comp (congrFun (congrArg LinearMap.comp a) (evalEquiv R M).symm.toLinearMap)⟩ rw [propext (cancel_left h), LinearEquiv.eq_comp_toLinearMap_iff] at hfg exact hfg @[simp] lemma dualMap_dualMap_eq_iff {M' : Type*} [AddCommMonoid M'] [Module R M'] [IsReflexive R M'] {f g : M →ₗ[R] M'} : f.dualMap.dualMap = g.dualMap.dualMap ↔ f = g := dualMap_dualMap_eq_iff_of_injective _ _ (bijective_dual_eval R M').injective /-- The dual of a reflexive module is reflexive. -/ instance Dual.instIsReflecive : IsReflexive R (Dual R M) := ⟨by simpa only [← symm_dualMap_evalEquiv] using (evalEquiv R M).dualMap.symm.bijective⟩ variable {R M N} in /-- A direct summand of a reflexive module is reflexive. -/ lemma IsReflexive.of_split (i : N →ₗ[R] M) (s : M →ₗ[R] N) (H : s ∘ₗ i = .id) : IsReflexive R N where bijective_dual_eval' := ⟨.of_comp (f := i.dualMap.dualMap) <| (bijective_dual_eval R M).1.comp (injective_of_comp_eq_id i _ H), .of_comp (g := s) <| (surjective_of_comp_eq_id i.dualMap.dualMap s.dualMap.dualMap <| congr_arg (dualMap ∘ dualMap) H).comp (bijective_dual_eval R M).2⟩ /-- The isomorphism `Module.evalEquiv` induces an order isomorphism on subspaces. -/ def mapEvalEquiv : Submodule R M ≃o Submodule R (Dual R (Dual R M)) := Submodule.orderIsoMapComap (evalEquiv R M) @[simp] theorem mapEvalEquiv_apply (W : Submodule R M) : mapEvalEquiv R M W = W.map (Dual.eval R M) := rfl @[simp] theorem mapEvalEquiv_symm_apply (W'' : Submodule R (Dual R (Dual R M))) : (mapEvalEquiv R M).symm W'' = W''.comap (Dual.eval R M) := rfl variable {R M N} in lemma equiv (e : M ≃ₗ[R] N) : IsReflexive R N where bijective_dual_eval' := by let ed : Dual R (Dual R N) ≃ₗ[R] Dual R (Dual R M) := e.symm.dualMap.dualMap have : Dual.eval R N = ed.symm.comp ((Dual.eval R M).comp e.symm.toLinearMap) := by ext m f exact DFunLike.congr_arg f (e.apply_symm_apply m).symm simp only [this, coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective] exact Bijective.comp (bijective_dual_eval R M) (LinearEquiv.bijective _) instance _root_.MulOpposite.instModuleIsReflexive : IsReflexive R (MulOpposite M) := equiv <| MulOpposite.opLinearEquiv _ -- see Note [lower instance priority] instance (priority := 100) [IsDomain R] : NoZeroSMulDivisors R M := by refine (noZeroSMulDivisors_iff R M).mpr ?_ intro r m hrm rw [or_iff_not_imp_left] intro hr suffices Dual.eval R M m = Dual.eval R M 0 from (bijective_dual_eval R M).injective this ext n simp only [Dual.eval_apply, map_zero, LinearMap.zero_apply] suffices r • n m = 0 from eq_zero_of_ne_zero_of_mul_left_eq_zero hr this rw [← LinearMap.map_smul_of_tower, hrm, LinearMap.map_zero] end IsReflexive end Module namespace Submodule variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {W : Submodule R M} /-- The `dualRestrict` of a submodule `W` of `M` is the linear map from the dual of `M` to the dual of `W` such that the domain of each linear map is restricted to `W`. -/ def dualRestrict (W : Submodule R M) : Module.Dual R M →ₗ[R] Module.Dual R W := LinearMap.domRestrict' W theorem dualRestrict_def (W : Submodule R M) : W.dualRestrict = W.subtype.dualMap := rfl @[simp] theorem dualRestrict_apply (W : Submodule R M) (φ : Module.Dual R M) (x : W) : W.dualRestrict φ x = φ (x : M) := rfl /-- The `dualAnnihilator` of a submodule `W` is the set of linear maps `φ` such that `φ w = 0` for all `w ∈ W`. -/ def dualAnnihilator {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] (W : Submodule R M) : Submodule R <| Module.Dual R M := LinearMap.ker W.dualRestrict @[simp] theorem mem_dualAnnihilator (φ : Module.Dual R M) : φ ∈ W.dualAnnihilator ↔ ∀ w ∈ W, φ w = 0 := by refine LinearMap.mem_ker.trans ?_ simp_rw [LinearMap.ext_iff, dualRestrict_apply] exact ⟨fun h w hw => h ⟨w, hw⟩, fun h w => h w.1 w.2⟩ /-- That $\operatorname{ker}(\iota^* : V^* \to W^*) = \operatorname{ann}(W)$. This is the definition of the dual annihilator of the submodule $W$. -/ theorem dualRestrict_ker_eq_dualAnnihilator (W : Submodule R M) : LinearMap.ker W.dualRestrict = W.dualAnnihilator := rfl /-- The `dualAnnihilator` of a submodule of the dual space pulled back along the evaluation map `Module.Dual.eval`. -/ def dualCoannihilator (Φ : Submodule R (Module.Dual R M)) : Submodule R M := Φ.dualAnnihilator.comap (Module.Dual.eval R M) @[simp] theorem mem_dualCoannihilator {Φ : Submodule R (Module.Dual R M)} (x : M) : x ∈ Φ.dualCoannihilator ↔ ∀ φ ∈ Φ, (φ x : R) = 0 := by simp_rw [dualCoannihilator, mem_comap, mem_dualAnnihilator, Module.Dual.eval_apply] lemma dualAnnihilator_map_dualMap_le {N : Type*} [AddCommMonoid N] [Module R N] (W : Submodule R M) (f : N →ₗ[R] M) : W.dualAnnihilator.map f.dualMap ≤ (W.comap f).dualAnnihilator := by intro; aesop theorem comap_dualAnnihilator (Φ : Submodule R (Module.Dual R M)) : Φ.dualAnnihilator.comap (Module.Dual.eval R M) = Φ.dualCoannihilator := rfl theorem map_dualCoannihilator_le (Φ : Submodule R (Module.Dual R M)) : Φ.dualCoannihilator.map (Module.Dual.eval R M) ≤ Φ.dualAnnihilator := map_le_iff_le_comap.mpr (comap_dualAnnihilator Φ).le variable (R M) in theorem dualAnnihilator_gc : GaloisConnection (OrderDual.toDual ∘ (dualAnnihilator : Submodule R M → Submodule R (Module.Dual R M))) (dualCoannihilator ∘ OrderDual.ofDual) := by intro a b induction b using OrderDual.rec simp only [Function.comp_apply, OrderDual.toDual_le_toDual, OrderDual.ofDual_toDual] constructor <;> · intro h x hx simp only [mem_dualAnnihilator, mem_dualCoannihilator] intro y hy have := h hy simp only [mem_dualAnnihilator, mem_dualCoannihilator] at this exact this x hx theorem le_dualAnnihilator_iff_le_dualCoannihilator {U : Submodule R (Module.Dual R M)} {V : Submodule R M} : U ≤ V.dualAnnihilator ↔ V ≤ U.dualCoannihilator := (dualAnnihilator_gc R M).le_iff_le @[simp] theorem dualAnnihilator_bot : (⊥ : Submodule R M).dualAnnihilator = ⊤ := (dualAnnihilator_gc R M).l_bot @[simp] theorem dualAnnihilator_top : (⊤ : Submodule R M).dualAnnihilator = ⊥ := by rw [eq_bot_iff] intro v simp_rw [mem_dualAnnihilator, mem_bot, mem_top, forall_true_left] exact fun h => LinearMap.ext h @[simp] theorem dualCoannihilator_bot : (⊥ : Submodule R (Module.Dual R M)).dualCoannihilator = ⊤ := (dualAnnihilator_gc R M).u_top @[mono] theorem dualAnnihilator_anti {U V : Submodule R M} (hUV : U ≤ V) : V.dualAnnihilator ≤ U.dualAnnihilator := (dualAnnihilator_gc R M).monotone_l hUV @[mono] theorem dualCoannihilator_anti {U V : Submodule R (Module.Dual R M)} (hUV : U ≤ V) : V.dualCoannihilator ≤ U.dualCoannihilator := (dualAnnihilator_gc R M).monotone_u hUV theorem le_dualAnnihilator_dualCoannihilator (U : Submodule R M) : U ≤ U.dualAnnihilator.dualCoannihilator := (dualAnnihilator_gc R M).le_u_l U theorem le_dualCoannihilator_dualAnnihilator (U : Submodule R (Module.Dual R M)) : U ≤ U.dualCoannihilator.dualAnnihilator := (dualAnnihilator_gc R M).l_u_le U theorem dualAnnihilator_dualCoannihilator_dualAnnihilator (U : Submodule R M) : U.dualAnnihilator.dualCoannihilator.dualAnnihilator = U.dualAnnihilator := (dualAnnihilator_gc R M).l_u_l_eq_l U theorem dualCoannihilator_dualAnnihilator_dualCoannihilator (U : Submodule R (Module.Dual R M)) : U.dualCoannihilator.dualAnnihilator.dualCoannihilator = U.dualCoannihilator := (dualAnnihilator_gc R M).u_l_u_eq_u U theorem dualAnnihilator_sup_eq (U V : Submodule R M) : (U ⊔ V).dualAnnihilator = U.dualAnnihilator ⊓ V.dualAnnihilator := (dualAnnihilator_gc R M).l_sup theorem dualCoannihilator_sup_eq (U V : Submodule R (Module.Dual R M)) : (U ⊔ V).dualCoannihilator = U.dualCoannihilator ⊓ V.dualCoannihilator := (dualAnnihilator_gc R M).u_inf theorem dualAnnihilator_iSup_eq {ι : Sort*} (U : ι → Submodule R M) : (⨆ i : ι, U i).dualAnnihilator = ⨅ i : ι, (U i).dualAnnihilator := (dualAnnihilator_gc R M).l_iSup theorem dualCoannihilator_iSup_eq {ι : Sort*} (U : ι → Submodule R (Module.Dual R M)) : (⨆ i : ι, U i).dualCoannihilator = ⨅ i : ι, (U i).dualCoannihilator := (dualAnnihilator_gc R M).u_iInf /-- See also `Subspace.dualAnnihilator_inf_eq` for vector subspaces. -/ theorem sup_dualAnnihilator_le_inf (U V : Submodule R M) : U.dualAnnihilator ⊔ V.dualAnnihilator ≤ (U ⊓ V).dualAnnihilator := by rw [le_dualAnnihilator_iff_le_dualCoannihilator, dualCoannihilator_sup_eq] apply inf_le_inf <;> exact le_dualAnnihilator_dualCoannihilator _ /-- See also `Subspace.dualAnnihilator_iInf_eq` for vector subspaces when `ι` is finite. -/ theorem iSup_dualAnnihilator_le_iInf {ι : Sort*} (U : ι → Submodule R M) : ⨆ i : ι, (U i).dualAnnihilator ≤ (⨅ i : ι, U i).dualAnnihilator := by rw [le_dualAnnihilator_iff_le_dualCoannihilator, dualCoannihilator_iSup_eq] apply iInf_mono exact fun i : ι => le_dualAnnihilator_dualCoannihilator (U i) @[simp] lemma coe_dualAnnihilator_span (s : Set M) : ((span R s).dualAnnihilator : Set (Module.Dual R M)) = {f | s ⊆ LinearMap.ker f} := by ext f simp only [SetLike.mem_coe, mem_dualAnnihilator, Set.mem_setOf_eq, ← LinearMap.mem_ker] exact span_le @[simp] lemma coe_dualCoannihilator_span (s : Set (Module.Dual R M)) : ((span R s).dualCoannihilator : Set M) = {x | ∀ f ∈ s, f x = 0} := by ext x have (φ : _) : x ∈ LinearMap.ker φ ↔ φ ∈ LinearMap.ker (Module.Dual.eval R M x) := by simp simp only [SetLike.mem_coe, mem_dualCoannihilator, Set.mem_setOf_eq, ← LinearMap.mem_ker, this] exact span_le end Submodule open Module namespace LinearMap variable {R M₁ M₂ : Type*} [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] variable (f : M₁ →ₗ[R] M₂) theorem ker_dualMap_eq_dualAnnihilator_range : LinearMap.ker f.dualMap = (range f).dualAnnihilator := by ext simp_rw [mem_ker, LinearMap.ext_iff, Submodule.mem_dualAnnihilator, ← SetLike.mem_coe, range_coe, Set.forall_mem_range] rfl theorem range_dualMap_le_dualAnnihilator_ker : LinearMap.range f.dualMap ≤ (ker f).dualAnnihilator := by rintro _ ⟨ψ, rfl⟩ simp_rw [Submodule.mem_dualAnnihilator, mem_ker] rintro x hx rw [dualMap_apply, hx, map_zero] end LinearMap section CommSemiring variable {R M M' : Type*} variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] namespace LinearMap open Submodule theorem ker_dualMap_eq_dualCoannihilator_range (f : M →ₗ[R] M') : LinearMap.ker f.dualMap = (range (Dual.eval R M' ∘ₗ f)).dualCoannihilator := by ext x; simp [LinearMap.ext_iff (f := dualMap f x)] @[simp] lemma dualCoannihilator_range_eq_ker_flip (B : M →ₗ[R] M' →ₗ[R] R) : (range B).dualCoannihilator = LinearMap.ker B.flip := by ext x; simp [LinearMap.ext_iff (f := B.flip x)] end LinearMap end CommSemiring
Projective.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, David Swinarski -/ import Mathlib.Algebra.Module.FinitePresentation import Mathlib.Algebra.Module.Projective import Mathlib.LinearAlgebra.Dimension.Constructions import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.RingTheory.LocalProperties.Submodule /-! # Being projective is a local property ## Main results - `LinearMap.split_surjective_of_localization_maximal` If `N` is finitely presented, then `f : M →ₗ[R] N` being split injective can be checked on stalks (of maximal ideals). - `Module.projective_of_localization_maximal` If `M` is finitely presented, then `M` being projective can be checked on stalks (of maximal ideals). ## TODO - Show that being projective is Zariski-local (very hard) -/ universe uM variable {R N N' : Type*} {M : Type uM} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] variable [Module R N] [AddCommGroup N'] [Module R N'] (S : Submonoid R) theorem Module.free_of_isLocalizedModule {Rₛ Mₛ} [AddCommGroup Mₛ] [Module R Mₛ] [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ Mₛ] [IsScalarTower R Rₛ Mₛ] (S) (f : M →ₗ[R] Mₛ) [IsLocalization S Rₛ] [IsLocalizedModule S f] [Module.Free R M] : Module.Free Rₛ Mₛ := Free.of_equiv (IsLocalizedModule.isBaseChange S Rₛ f).equiv universe uR' uM' in /-- Also see `IsLocalizedModule.lift_rank_eq` for a version for non-free modules, but requires `S` to not contain any zero-divisors. -/ theorem Module.lift_rank_of_isLocalizedModule_of_free (Rₛ : Type uR') {Mₛ : Type uM'} [AddCommGroup Mₛ] [Module R Mₛ] [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ Mₛ] [IsScalarTower R Rₛ Mₛ] (S : Submonoid R) (f : M →ₗ[R] Mₛ) [IsLocalization S Rₛ] [IsLocalizedModule S f] [Module.Free R M] [Nontrivial Rₛ] : Cardinal.lift.{uM} (Module.rank Rₛ Mₛ) = Cardinal.lift.{uM'} (Module.rank R M) := by apply Cardinal.lift_injective.{max uM' uR'} have := (algebraMap R Rₛ).domain_nontrivial have := (IsLocalizedModule.isBaseChange S Rₛ f).equiv.lift_rank_eq.symm simp only [rank_tensorProduct, rank_self, Cardinal.lift_one, one_mul, Cardinal.lift_lift] at this ⊢ convert this exact Cardinal.lift_umax theorem Module.finrank_of_isLocalizedModule_of_free (Rₛ : Type*) {Mₛ : Type*} [AddCommGroup Mₛ] [Module R Mₛ] [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ Mₛ] [IsScalarTower R Rₛ Mₛ] (S : Submonoid R) (f : M →ₗ[R] Mₛ) [IsLocalization S Rₛ] [IsLocalizedModule S f] [Module.Free R M] [Nontrivial Rₛ] : Module.finrank Rₛ Mₛ = Module.finrank R M := by simpa using congr(Cardinal.toNat $(Module.lift_rank_of_isLocalizedModule_of_free Rₛ S f)) theorem Module.projective_of_isLocalizedModule {Rₛ Mₛ} [AddCommGroup Mₛ] [Module R Mₛ] [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ Mₛ] [IsScalarTower R Rₛ Mₛ] (S) (f : M →ₗ[R] Mₛ) [IsLocalization S Rₛ] [IsLocalizedModule S f] [Module.Projective R M] : Module.Projective Rₛ Mₛ := Projective.of_equiv (IsLocalizedModule.isBaseChange S Rₛ f).equiv theorem LinearMap.split_surjective_of_localization_maximal (f : M →ₗ[R] N) [Module.FinitePresentation R N] (H : ∀ (I : Ideal R) (_ : I.IsMaximal), ∃ (g : _ →ₗ[Localization.AtPrime I] _), (LocalizedModule.map I.primeCompl f).comp g = LinearMap.id) : ∃ (g : N →ₗ[R] M), f.comp g = LinearMap.id := by change LinearMap.id ∈ LinearMap.range (LinearMap.llcomp R N M N f) refine Submodule.mem_of_localization_maximal _ (fun P _ ↦ LocalizedModule.map P.primeCompl) _ _ fun I hI ↦ ?_ rw [LocalizedModule.map_id] have : LinearMap.id ∈ LinearMap.range (LinearMap.llcomp _ (LocalizedModule I.primeCompl N) _ _ (LocalizedModule.map I.primeCompl f)) := H I hI convert this · ext f constructor · intro hf obtain ⟨a, ha, c, rfl⟩ := hf obtain ⟨g, rfl⟩ := ha use IsLocalizedModule.mk' (LocalizedModule.map I.primeCompl) g c apply ((Module.End.isUnit_iff _).mp <| IsLocalizedModule.map_units (LocalizedModule.map I.primeCompl) c).injective dsimp conv_rhs => rw [← Submonoid.smul_def] conv_lhs => rw [← LinearMap.map_smul_of_tower] rw [← Submonoid.smul_def, IsLocalizedModule.mk'_cancel', IsLocalizedModule.mk'_cancel'] apply LinearMap.restrictScalars_injective R apply IsLocalizedModule.ext I.primeCompl (LocalizedModule.mkLinearMap I.primeCompl N) · exact IsLocalizedModule.map_units (LocalizedModule.mkLinearMap I.primeCompl N) ext simp only [LocalizedModule.map_mk, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Function.comp_apply, LocalizedModule.mkLinearMap_apply, LinearMap.llcomp_apply, LocalizedModule.map_mk] · rintro ⟨g, rfl⟩ obtain ⟨⟨g, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective I.primeCompl (LocalizedModule.map I.primeCompl) g simp only [Function.uncurry_apply_pair] refine ⟨f.comp g, ⟨g, rfl⟩, s, ?_⟩ apply ((Module.End.isUnit_iff _).mp <| IsLocalizedModule.map_units (LocalizedModule.map I.primeCompl) s).injective simp only [Module.algebraMap_end_apply, ← Submonoid.smul_def, IsLocalizedModule.mk'_cancel', ← LinearMap.map_smul_of_tower] apply LinearMap.restrictScalars_injective R apply IsLocalizedModule.ext I.primeCompl (LocalizedModule.mkLinearMap I.primeCompl N) · exact IsLocalizedModule.map_units (LocalizedModule.mkLinearMap I.primeCompl N) ext simp only [coe_comp, coe_restrictScalars, Function.comp_apply, LocalizedModule.mkLinearMap_apply, LocalizedModule.map_mk, llcomp_apply] theorem Module.projective_of_localization_maximal (H : ∀ (I : Ideal R) (_ : I.IsMaximal), Module.Projective (Localization.AtPrime I) (LocalizedModule I.primeCompl M)) [Module.FinitePresentation R M] : Module.Projective R M := by have : Module.Finite R M := by infer_instance have : (⊤ : Submodule R M).FG := this.fg_top have : ∃ (s : Finset M), _ := this obtain ⟨s, hs⟩ := this let N := s →₀ R let f : N →ₗ[R] M := Finsupp.linearCombination R (Subtype.val : s → M) have hf : Function.Surjective f := by rw [← LinearMap.range_eq_top, Finsupp.range_linearCombination, Subtype.range_val] convert hs have (I : Ideal R) (hI : I.IsMaximal) := letI := H I hI Module.projective_lifting_property (LocalizedModule.map I.primeCompl f) LinearMap.id (LocalizedModule.map_surjective _ _ hf) obtain ⟨g, hg⟩ := LinearMap.split_surjective_of_localization_maximal _ this exact Module.Projective.of_split _ _ hg variable (Rₚ : ∀ (P : Ideal R) [P.IsMaximal], Type*) [∀ (P : Ideal R) [P.IsMaximal], CommRing (Rₚ P)] [∀ (P : Ideal R) [P.IsMaximal], Algebra R (Rₚ P)] [∀ (P : Ideal R) [P.IsMaximal], IsLocalization.AtPrime (Rₚ P) P] (Mₚ : ∀ (P : Ideal R) [P.IsMaximal], Type*) [∀ (P : Ideal R) [P.IsMaximal], AddCommGroup (Mₚ P)] [∀ (P : Ideal R) [P.IsMaximal], Module R (Mₚ P)] [∀ (P : Ideal R) [P.IsMaximal], Module (Rₚ P) (Mₚ P)] [∀ (P : Ideal R) [P.IsMaximal], IsScalarTower R (Rₚ P) (Mₚ P)] (f : ∀ (P : Ideal R) [P.IsMaximal], M →ₗ[R] Mₚ P) [inst : ∀ (P : Ideal R) [P.IsMaximal], IsLocalizedModule P.primeCompl (f P)] attribute [local instance] RingHomInvPair.of_ringEquiv in include f in /-- A variant of `Module.projective_of_localization_maximal` that accepts `IsLocalizedModule`. -/ theorem Module.projective_of_localization_maximal' (H : ∀ (I : Ideal R) (_ : I.IsMaximal), Module.Projective (Rₚ I) (Mₚ I)) [Module.FinitePresentation R M] : Module.Projective R M := by apply Module.projective_of_localization_maximal intros P hP refine Module.Projective.of_ringEquiv (M := Mₚ P) (IsLocalization.algEquiv P.primeCompl (Rₚ P) (Localization.AtPrime P)).toRingEquiv { __ := IsLocalizedModule.linearEquiv P.primeCompl (f P) (LocalizedModule.mkLinearMap P.primeCompl M) map_smul' := ?_ } · intros r m obtain ⟨r, s, rfl⟩ := IsLocalization.mk'_surjective P.primeCompl r apply ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units (LocalizedModule.mkLinearMap P.primeCompl M) s)).1 dsimp simp only [← map_smul, ← smul_assoc, IsLocalization.smul_mk'_self, algebraMap_smul, IsLocalization.map_id_mk']
PNatToNat.lean
/- Copyright (c) 2025 Vasilii Nesterov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vasilii Nesterov -/ import Mathlib.Data.PNat.Basic /-! # `pnat_to_nat` This file implements the `pnat_to_nat` tactic that shifts `PNat`s in the context to `Nat`. ## Implementation details The implementation follows these steps: 1. For each `x : PNat` in the context, add the hypothesis `0 < (↑x : ℕ)`. 2. Translate arithmetic on `PNat` to `Nat` using the `pnat_to_nat_coe` simp set. -/ namespace Mathlib.Tactic.PNatToNat open private getElimNameInfo generalizeTargets generalizeVars from Lean.Elab.Tactic.Induction open Lean Meta Elab Tactic Qq /-- For each `x : PNat` in the context, add the hypothesis `0 < (↑x : ℕ)`. -/ elab "pnat_positivity" : tactic => withMainContext do let result ← (← getLCtx).foldlM (init := ← getMainGoal) fun g decl => do let ⟨1, declType, declExpr⟩ ← inferTypeQ decl.toExpr | return g let ~q(PNat) := declType | return g let pf := q(PNat.pos $declExpr) let ctx ← getLCtx let alreadyDeclared := Option.isSome <| ← ctx.findDeclM? fun ldecl => do if ← isDefEq ldecl.type q(0 < PNat.val $declExpr) then pure <| .some () else pure .none if alreadyDeclared then return g let (_, mvarIdNew) ← (← g.assert .anonymous q(0 < PNat.val $declExpr) pf).intro1P return mvarIdNew setGoals [result] @[pnat_to_nat_coe] lemma coe_inj (m n : PNat) : m = n ↔ (m : ℕ) = (n : ℕ) := by simp @[pnat_to_nat_coe] lemma coe_le_coe (m n : PNat) : m ≤ n ↔ (m : ℕ) ≤ (n : ℕ) := by simp @[pnat_to_nat_coe] lemma coe_lt_coe (m n : PNat) : m < n ↔ (m : ℕ) < (n : ℕ) := by simp attribute [pnat_to_nat_coe] PNat.add_coe PNat.mul_coe PNat.val_ofNat @[pnat_to_nat_coe] lemma sub_coe (a b : PNat) : ((a - b : PNat) : Nat) = a.val - 1 - b.val + 1 := by cases a cases b simp only [PNat.mk_coe, _root_.PNat.sub_coe, ← _root_.PNat.coe_lt_coe] split_ifs <;> omega /-- `pnat_to_nat` shifts all `PNat`s in the context to `Nat`, rewriting propositions about them. A typical use case is `pnat_to_nat; omega`. -/ macro "pnat_to_nat" : tactic => `(tactic| focus ( pnat_positivity; simp only [pnat_to_nat_coe] at *) ) end Mathlib.Tactic.PNatToNat
BifunctorHomotopy.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Bifunctor import Mathlib.Algebra.Homology.Homotopy /-! # The action of a bifunctor on homological complexes factors through homotopies Given a `TotalComplexShape c₁ c₂ c`, a functor `F : C₁ ⥤ C₂ ⥤ D`, we shall show in this file that up to homotopy the morphism `mapBifunctorMap f₁ f₂ F c` only depends on the homotopy classes of the morphism `f₁` in `HomologicalComplex C c₁` and of the morphism `f₂` in `HomologicalComplex C c₂` (TODO). -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits variable {C₁ C₂ D I₁ I₂ J : Type*} [Category C₁] [Category C₂] [Category D] [Preadditive C₁] [Preadditive C₂] [Preadditive D] {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} namespace HomologicalComplex variable {K₁ L₁ : HomologicalComplex C₁ c₁} {f₁ f₁' : K₁ ⟶ L₁} (h₁ : Homotopy f₁ f₁') {K₂ L₂ : HomologicalComplex C₂ c₂} (f₂ : K₂ ⟶ L₂) (F : C₁ ⥤ C₂ ⥤ D) [F.Additive] [∀ X₁, (F.obj X₁).Additive] (c : ComplexShape J) [DecidableEq J] [TotalComplexShape c₁ c₂ c] [HasMapBifunctor K₁ K₂ F c] [HasMapBifunctor L₁ L₂ F c] namespace mapBifunctorMapHomotopy /-- Auxiliary definition for `mapBifunctorMapHomotopy₁`. -/ noncomputable def hom₁ (j j' : J) : (mapBifunctor K₁ K₂ F c).X j ⟶ (mapBifunctor L₁ L₂ F c).X j' := HomologicalComplex₂.totalDesc _ (fun i₁ i₂ _ => ComplexShape.ε₁ c₁ c₂ c (c₁.prev i₁, i₂) • (F.map (h₁.hom i₁ (c₁.prev i₁))).app (K₂.X i₂) ≫ (F.obj (L₁.X (c₁.prev i₁))).map (f₂.f i₂) ≫ ιMapBifunctorOrZero L₁ L₂ F c _ _ j') @[reassoc] lemma ιMapBifunctor_hom₁ (i₁ i₁' : I₁) (i₂ : I₂) (j j' : J) (h : ComplexShape.π c₁ c₂ c (i₁', i₂) = j) (h' : c₁.prev i₁' = i₁) : ιMapBifunctor K₁ K₂ F c i₁' i₂ j h ≫ hom₁ h₁ f₂ F c j j' = ComplexShape.ε₁ c₁ c₂ c (i₁, i₂) • (F.map (h₁.hom i₁' i₁)).app (K₂.X i₂) ≫ (F.obj (L₁.X i₁)).map (f₂.f i₂) ≫ ιMapBifunctorOrZero L₁ L₂ F c _ _ j' := by subst h' simp [hom₁] lemma zero₁ (j j' : J) (h : ¬ c.Rel j' j) : hom₁ h₁ f₂ F c j j' = 0 := by ext i₁ i₂ h' dsimp [hom₁] rw [comp_zero, HomologicalComplex₂.ι_totalDesc] by_cases h₃ : c₁.Rel (c₁.prev i₁) i₁ · rw [ιMapBifunctorOrZero_eq_zero, comp_zero, comp_zero, smul_zero] intro h₄ apply h rw [← h', ← h₄] exact ComplexShape.rel_π₁ c₂ c h₃ i₂ · dsimp rw [h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, smul_zero] lemma comm₁_aux {i₁ i₁' : I₁} (hi₁ : c₁.Rel i₁ i₁') {i₂ i₂' : I₂} (hi₂ : c₂.Rel i₂ i₂') (j : J) (hj : ComplexShape.π c₁ c₂ c (i₁', i₂) = j) : ComplexShape.ε₁ c₁ c₂ c (i₁, i₂) • (F.map (h₁.hom i₁' i₁)).app (K₂.X i₂) ≫ (F.obj (L₁.X i₁)).map (f₂.f i₂) ≫ (((F.mapBifunctorHomologicalComplex c₁ c₂).obj L₁).obj L₂).d₂ c i₁ i₂ j = -(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).d₂ c i₁' i₂ (c.next j) ≫ hom₁ h₁ f₂ F c (c.next j) j := by have hj' : ComplexShape.π c₁ c₂ c ⟨i₁, i₂'⟩ = j := by rw [← hj, ← ComplexShape.next_π₂ c₁ c i₁ hi₂, ComplexShape.next_π₁ c₂ c hi₁ i₂] rw [HomologicalComplex₂.d₂_eq _ _ _ hi₂ _ hj', HomologicalComplex₂.d₂_eq _ _ _ hi₂ _ (by rw [← c.next_eq' (ComplexShape.rel_π₂ c₁ c i₁' hi₂), hj]), Linear.comp_units_smul, Linear.comp_units_smul, Linear.units_smul_comp, assoc, ιMapBifunctor_hom₁ _ _ _ _ _ _ _ _ _ _ (c₁.prev_eq' hi₁), ιMapBifunctorOrZero_eq _ _ _ _ _ _ _ hj', Linear.comp_units_smul, smul_smul, smul_smul, Functor.mapBifunctorHomologicalComplex_obj_obj_X_d, Functor.mapBifunctorHomologicalComplex_obj_obj_X_d, NatTrans.naturality_assoc, ComplexShape.ε₁_ε₂ c hi₁ hi₂, neg_mul, Units.neg_smul, neg_inj, smul_left_cancel_iff, ← Functor.map_comp_assoc, ← Functor.map_comp_assoc, f₂.comm] lemma comm₁ (j : J) : (mapBifunctorMap f₁ f₂ F c).f j = (mapBifunctor K₁ K₂ F c).d j (c.next j) ≫ mapBifunctorMapHomotopy.hom₁ h₁ f₂ F c (c.next j) j + mapBifunctorMapHomotopy.hom₁ h₁ f₂ F c j (c.prev j) ≫ (mapBifunctor L₁ L₂ F c).d (c.prev j) j + (mapBifunctorMap f₁' f₂ F c).f j := by ext i₁ i₂ h simp? [HomologicalComplex₂.total_d, h₁.comm i₁, dFrom, fromNext, toPrev, dTo] says simp only [ι_mapBifunctorMap, h₁.comm i₁, dNext_eq_dFrom_fromNext, dFrom, fromNext, AddMonoidHom.mk'_apply, prevD_eq_toPrev_dTo, toPrev, dTo, Functor.map_add, Functor.map_comp, NatTrans.app_add, NatTrans.comp_app, Preadditive.add_comp, assoc, HomologicalComplex₂.total_d, Functor.mapBifunctorHomologicalComplex_obj_obj_toGradedObject, Preadditive.comp_add, HomologicalComplex₂.ι_D₁_assoc, Functor.mapBifunctorHomologicalComplex_obj_obj_X_X, HomologicalComplex₂.ι_D₂_assoc, add_left_inj] have : ∀ {X Y : D} (a b c d e f : X ⟶ Y), a = c → b = e → f = -d → a + b = c + d + (e + f) := by rintro X Y a b _ d _ _ rfl rfl rfl; abel apply this · by_cases h₃ : c₁.Rel i₁ (c₁.next i₁) · rw [HomologicalComplex₂.d₁_eq _ _ h₃ _ _ (by rw [← h, ComplexShape.next_π₁ c₂ c h₃]), Functor.mapBifunctorHomologicalComplex_obj_obj_d_f, Linear.units_smul_comp, assoc, ιMapBifunctor_hom₁ _ _ _ _ i₁ _ _ _ _ _ (c₁.prev_eq' h₃), Linear.comp_units_smul, smul_smul, Int.units_mul_self, one_smul, ιMapBifunctorOrZero_eq] · rw [K₁.shape _ _ h₃, Functor.map_zero, zero_app, zero_comp, HomologicalComplex₂.d₁_eq_zero _ _ _ _ _ h₃, zero_comp] · rw [ιMapBifunctor_hom₁_assoc _ _ _ _ _ _ _ _ _ _ rfl] by_cases h₃ : c₁.Rel (c₁.prev i₁) i₁ · rw [ιMapBifunctorOrZero_eq _ _ _ _ _ _ _ (by rw [← ComplexShape.prev_π₁ c₂ c h₃, h]), Linear.units_smul_comp, assoc, assoc, HomologicalComplex₂.ι_D₁, HomologicalComplex₂.d₁_eq _ _ h₃ _ _ h, Linear.comp_units_smul, Linear.comp_units_smul, smul_smul, Int.units_mul_self, one_smul, Functor.mapBifunctorHomologicalComplex_obj_obj_d_f, NatTrans.naturality_assoc] · rw [h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, zero_comp, smul_zero, zero_comp] · rw [ιMapBifunctor_hom₁_assoc _ _ _ _ _ _ _ _ _ _ rfl] by_cases h₃ : c₁.Rel (c₁.prev i₁) i₁ · dsimp rw [Linear.units_smul_comp, assoc, assoc, ιMapBifunctorOrZero_eq _ _ _ _ _ _ _ (by rw [← ComplexShape.prev_π₁ c₂ c h₃, h]), HomologicalComplex₂.ι_D₂] by_cases h₄ : c₂.Rel i₂ (c₂.next i₂) · exact comm₁_aux h₁ f₂ F c h₃ h₄ j h · rw [HomologicalComplex₂.d₂_eq_zero _ _ _ _ _ h₄, comp_zero, comp_zero, smul_zero, HomologicalComplex₂.d₂_eq_zero _ _ _ _ _ h₄, zero_comp, neg_zero] · rw [h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, smul_zero, zero_comp, zero_eq_neg] by_cases h₄ : c₂.Rel i₂ (c₂.next i₂) · by_cases h₅ : c.Rel j (c.next j) · rw [HomologicalComplex₂.d₂_eq _ _ _ h₄ _ (by rw [← ComplexShape.next_π₂ c₁ c i₁ h₄, h]), Linear.units_smul_comp, assoc, Functor.mapBifunctorHomologicalComplex_obj_obj_X_d, ιMapBifunctor_hom₁ _ _ _ _ _ _ _ _ _ _ rfl, h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, smul_zero, comp_zero, smul_zero] · rw [zero₁ _ _ _ _ _ _ h₅, comp_zero] · rw [HomologicalComplex₂.d₂_eq_zero _ _ _ _ _ h₄, zero_comp] end mapBifunctorMapHomotopy open mapBifunctorMapHomotopy in /-- The homotopy between `mapBifunctorMap f₁ f₂ F c` and `mapBifunctorMap f₁' f₂ F c` that is induced by an homotopy between `f₁` and `f₁'`. -/ noncomputable def mapBifunctorMapHomotopy₁ : Homotopy (mapBifunctorMap f₁ f₂ F c) (mapBifunctorMap f₁' f₂ F c) where hom := hom₁ h₁ f₂ F c zero := zero₁ h₁ f₂ F c comm := comm₁ h₁ f₂ F c end HomologicalComplex
TensorProduct.lean
/- Copyright (c) 2025 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Yunzhou Xie -/ import Mathlib.Algebra.Central.Basic import Mathlib.RingTheory.Flat.Basic import Mathlib.LinearAlgebra.Basis.VectorSpace /-! # Lemmas about tensor products of central algebras In this file we prove for algebras `B` and `C` over a field `K` that if `B ⊗[K] C` is a central algebra and `B, C` nontrivial, then both `B` and `C` are central algebras. ## Main Results - `Algebra.IsCentral.left_of_tensor_of_field`: If `B` `C` are `K`-algebras where `K` is a field, `C` is nontrivial and `B ⊗[K] C` is a central algebra over `K`, then `B` is a central algebra over `K`. - `Algebra.IsCentral.right_of_tensor_of_field`: If `B` `C` are `K`-algebras where `K` is a field, `B` is nontrivial and `B ⊗[K] C` is a central algebra over `K`, then `C` is a central algebra over `K`. ## Tags Central Algebras, Central Simple Algebras, Noncommutative Algebra -/ universe u v open TensorProduct variable (K B C : Type*) [CommSemiring K] [Semiring B] [Semiring C] [Algebra K B] [Algebra K C] lemma Algebra.TensorProduct.includeLeft_map_center_le : (Subalgebra.center K B).map includeLeft ≤ Subalgebra.center K (B ⊗[K] C) := by intro x hx simp only [Subalgebra.mem_map, Subalgebra.mem_center_iff] at hx ⊢ obtain ⟨b, hb0, rfl⟩ := hx intro bc induction bc using TensorProduct.induction_on with | zero => simp | tmul b' c => simp [hb0] | add _ _ _ _ => simp_all [add_mul, mul_add] lemma Algebra.TensorProduct.includeRight_map_center_le : (Subalgebra.center K C).map includeRight ≤ Subalgebra.center K (B ⊗[K] C) := fun x hx ↦ by simp only [Subalgebra.mem_map, Subalgebra.mem_center_iff] at hx ⊢ obtain ⟨c, hc0, rfl⟩ := hx intro bc induction bc using TensorProduct.induction_on with | zero => simp | tmul b c' => simp [hc0] | add _ _ _ _ => simp_all [add_mul, mul_add] namespace Algebra.IsCentral open Algebra.TensorProduct in lemma left_of_tensor (inj : Function.Injective (algebraMap K C)) [Module.Flat K B] [hbc : Algebra.IsCentral K (B ⊗[K] C)] : IsCentral K B where out := (Subalgebra.map_le.mp ((includeLeft_map_center_le K B C).trans hbc.1)).trans fun _ ⟨k, hk⟩ ↦ ⟨k, includeLeft_injective (S := K) inj hk⟩ lemma right_of_tensor (inj : Function.Injective (algebraMap K B)) [Module.Flat K C] [Algebra.IsCentral K (B ⊗[K] C)] : IsCentral K C := have : IsCentral K (C ⊗[K] B) := IsCentral.of_algEquiv K _ _ <| Algebra.TensorProduct.comm _ _ _ left_of_tensor K C B inj /-- Let `B` and `C` be two algebras over a field `K`, if `B ⊗[K] C` is central and `C` is non-trivial, then `B` is central. -/ lemma left_of_tensor_of_field (K B C : Type*) [Field K] [Ring B] [Ring C] [Nontrivial C] [Algebra K B] [Algebra K C] [IsCentral K (B ⊗[K] C)] : IsCentral K B := left_of_tensor K B C <| FaithfulSMul.algebraMap_injective K C /-- Let `B` and `C` be two algebras over a field `K`, if `B ⊗[K] C` is central and `B` is non-trivial, then `C` is central. -/ lemma right_of_tensor_of_field (K B C : Type*) [Field K] [Ring B] [Ring C] [Nontrivial B] [Algebra K B] [Algebra K C] [IsCentral K (B ⊗[K] C)] : IsCentral K C := right_of_tensor K B C <| FaithfulSMul.algebraMap_injective K B end Algebra.IsCentral
LocallyUniformConvergence.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.UniformSpace.UniformConvergence /-! # Locally uniform convergence We define a sequence of functions `Fₙ` to *converge locally uniformly* to a limiting function `f` with respect to a filter `p`, spelled `TendstoLocallyUniformly F f p`, if for any `x ∈ s` and any entourage of the diagonal `u`, there is a neighbourhood `v` of `x` such that `p`-eventually we have `(f y, Fₙ y) ∈ u` for all `y ∈ v`. It is important to note that this definition is somewhat non-standard; it is **not** in general equivalent to "every point has a neighborhood on which the convergence is uniform", which is the definition more commonly encountered in the literature. The reason is that in our definition the neighborhood `v` of `x` can depend on the entourage `u`; so our condition is *a priori* weaker than the usual one, although the two conditions are equivalent if the domain is locally compact. See `tendstoLocallyUniformlyOn_of_forall_exists_nhds` for the one-way implication; the equivalence assuming local compactness is part of `tendstoLocallyUniformlyOn_TFAE`. We adopt this weaker condition because it is more general but appears to be sufficient for the standard applications of locally-uniform convergence (in particular, for proving that a locally-uniform limit of continuous functions is continuous). We also define variants for locally uniform convergence on a subset, called `TendstoLocallyUniformlyOn F f p s`. ## Tags Uniform limit, uniform convergence, tends uniformly to -/ noncomputable section open Topology Uniformity Filter Set Uniform variable {α β γ ι : Type*} [TopologicalSpace α] [UniformSpace β] variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} /-- A sequence of functions `Fₙ` converges locally uniformly on a set `s` to a limiting function `f` with respect to a filter `p` if, for any entourage of the diagonal `u`, for any `x ∈ s`, one has `p`-eventually `(f y, Fₙ y) ∈ u` for all `y` in a neighborhood of `x` in `s`. -/ def TendstoLocallyUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) := ∀ u ∈ 𝓤 β, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u /-- A sequence of functions `Fₙ` converges locally uniformly to a limiting function `f` with respect to a filter `p` if, for any entourage of the diagonal `u`, for any `x`, one has `p`-eventually `(f y, Fₙ y) ∈ u` for all `y` in a neighborhood of `x`. -/ def TendstoLocallyUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) := ∀ u ∈ 𝓤 β, ∀ x : α, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u theorem tendstoLocallyUniformlyOn_univ : TendstoLocallyUniformlyOn F f p univ ↔ TendstoLocallyUniformly F f p := by simp [TendstoLocallyUniformlyOn, TendstoLocallyUniformly, nhdsWithin_univ] theorem tendstoLocallyUniformlyOn_iff_forall_tendsto : TendstoLocallyUniformlyOn F f p s ↔ ∀ x ∈ s, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝[s] x) (𝓤 β) := forall₂_swap.trans <| forall₄_congr fun _ _ _ _ => by simp_rw [mem_map, mem_prod_iff_right, mem_preimage] nonrec theorem IsOpen.tendstoLocallyUniformlyOn_iff_forall_tendsto (hs : IsOpen s) : TendstoLocallyUniformlyOn F f p s ↔ ∀ x ∈ s, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝 x) (𝓤 β) := tendstoLocallyUniformlyOn_iff_forall_tendsto.trans <| forall₂_congr fun x hx => by rw [hs.nhdsWithin_eq hx] theorem tendstoLocallyUniformly_iff_forall_tendsto : TendstoLocallyUniformly F f p ↔ ∀ x, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝 x) (𝓤 β) := by simp [← tendstoLocallyUniformlyOn_univ, isOpen_univ.tendstoLocallyUniformlyOn_iff_forall_tendsto] theorem tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe : TendstoLocallyUniformlyOn F f p s ↔ TendstoLocallyUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p := by simp only [tendstoLocallyUniformly_iff_forall_tendsto, Subtype.forall', tendsto_map'_iff, tendstoLocallyUniformlyOn_iff_forall_tendsto, ← map_nhds_subtype_val, prod_map_right]; rfl protected theorem TendstoUniformlyOn.tendstoLocallyUniformlyOn (h : TendstoUniformlyOn F f p s) : TendstoLocallyUniformlyOn F f p s := fun u hu _ _ => ⟨s, self_mem_nhdsWithin, by simpa using h u hu⟩ protected theorem TendstoUniformly.tendstoLocallyUniformly (h : TendstoUniformly F f p) : TendstoLocallyUniformly F f p := fun u hu _ => ⟨univ, univ_mem, by simpa using h u hu⟩ theorem TendstoLocallyUniformlyOn.mono (h : TendstoLocallyUniformlyOn F f p s) (h' : s' ⊆ s) : TendstoLocallyUniformlyOn F f p s' := by intro u hu x hx rcases h u hu x (h' hx) with ⟨t, ht, H⟩ exact ⟨t, nhdsWithin_mono x h' ht, H.mono fun n => id⟩ theorem tendstoLocallyUniformlyOn_iUnion {ι' : Sort*} {S : ι' → Set α} (hS : ∀ i, IsOpen (S i)) (h : ∀ i, TendstoLocallyUniformlyOn F f p (S i)) : TendstoLocallyUniformlyOn F f p (⋃ i, S i) := (isOpen_iUnion hS).tendstoLocallyUniformlyOn_iff_forall_tendsto.2 fun _x hx => let ⟨i, hi⟩ := mem_iUnion.1 hx (hS i).tendstoLocallyUniformlyOn_iff_forall_tendsto.1 (h i) _ hi theorem tendstoLocallyUniformlyOn_biUnion {s : Set γ} {S : γ → Set α} (hS : ∀ i ∈ s, IsOpen (S i)) (h : ∀ i ∈ s, TendstoLocallyUniformlyOn F f p (S i)) : TendstoLocallyUniformlyOn F f p (⋃ i ∈ s, S i) := tendstoLocallyUniformlyOn_iUnion (fun i => isOpen_iUnion (hS i)) fun i ↦ tendstoLocallyUniformlyOn_iUnion (hS i) (h i) theorem tendstoLocallyUniformlyOn_sUnion (S : Set (Set α)) (hS : ∀ s ∈ S, IsOpen s) (h : ∀ s ∈ S, TendstoLocallyUniformlyOn F f p s) : TendstoLocallyUniformlyOn F f p (⋃₀ S) := by rw [sUnion_eq_biUnion] exact tendstoLocallyUniformlyOn_biUnion hS h theorem TendstoLocallyUniformlyOn.union (hs₁ : IsOpen s) (hs₂ : IsOpen s') (h₁ : TendstoLocallyUniformlyOn F f p s) (h₂ : TendstoLocallyUniformlyOn F f p s') : TendstoLocallyUniformlyOn F f p (s ∪ s') := by rw [← sUnion_pair] refine tendstoLocallyUniformlyOn_sUnion _ ?_ ?_ <;> simp [*] protected theorem TendstoLocallyUniformly.tendstoLocallyUniformlyOn (h : TendstoLocallyUniformly F f p) : TendstoLocallyUniformlyOn F f p s := (tendstoLocallyUniformlyOn_univ.mpr h).mono (subset_univ _) /-- On a compact space, locally uniform convergence is just uniform convergence. -/ theorem tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace [CompactSpace α] : TendstoLocallyUniformly F f p ↔ TendstoUniformly F f p := by refine ⟨fun h V hV => ?_, TendstoUniformly.tendstoLocallyUniformly⟩ choose U hU using h V hV obtain ⟨t, ht⟩ := isCompact_univ.elim_nhds_subcover' (fun k _ => U k) fun k _ => (hU k).1 replace hU := fun x : t => (hU x).2 rw [← eventually_all] at hU refine hU.mono fun i hi x => ?_ specialize ht (mem_univ x) simp only [exists_prop, mem_iUnion, SetCoe.exists, exists_and_right] at ht obtain ⟨y, ⟨hy₁, hy₂⟩, hy₃⟩ := ht exact hi ⟨⟨y, hy₁⟩, hy₂⟩ x hy₃ /-- For a compact set `s`, locally uniform convergence on `s` is just uniform convergence on `s`. -/ theorem tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact (hs : IsCompact s) : TendstoLocallyUniformlyOn F f p s ↔ TendstoUniformlyOn F f p s := by haveI : CompactSpace s := isCompact_iff_compactSpace.mp hs refine ⟨fun h => ?_, TendstoUniformlyOn.tendstoLocallyUniformlyOn⟩ rwa [tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe, tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace, ← tendstoUniformlyOn_iff_tendstoUniformly_comp_coe] at h theorem TendstoLocallyUniformlyOn.comp [TopologicalSpace γ] {t : Set γ} (h : TendstoLocallyUniformlyOn F f p s) (g : γ → α) (hg : MapsTo g t s) (cg : ContinuousOn g t) : TendstoLocallyUniformlyOn (fun n => F n ∘ g) (f ∘ g) p t := by intro u hu x hx rcases h u hu (g x) (hg hx) with ⟨a, ha, H⟩ have : g ⁻¹' a ∈ 𝓝[t] x := (cg x hx).preimage_mem_nhdsWithin' (nhdsWithin_mono (g x) hg.image_subset ha) exact ⟨g ⁻¹' a, this, H.mono fun n hn y hy => hn _ hy⟩ theorem TendstoLocallyUniformly.comp [TopologicalSpace γ] (h : TendstoLocallyUniformly F f p) (g : γ → α) (cg : Continuous g) : TendstoLocallyUniformly (fun n => F n ∘ g) (f ∘ g) p := by rw [← tendstoLocallyUniformlyOn_univ] at h ⊢ rw [← continuousOn_univ] at cg exact h.comp _ (mapsTo_univ _ _) cg /-- If every `x ∈ s` has a neighbourhood within `s` on which `F i` tends uniformly to `f`, then `F i` tends locally uniformly on `s` to `f`. Note this is **not** a tautology, since our definition of `TendstoLocallyUniformlyOn` is slightly more general (although the conditions are equivalent if `β` is locally compact and `s` is open, see `tendstoLocallyUniformlyOn_TFAE`). -/ lemma tendstoLocallyUniformlyOn_of_forall_exists_nhds (h : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, TendstoUniformlyOn F f p t) : TendstoLocallyUniformlyOn F f p s := by refine tendstoLocallyUniformlyOn_iff_forall_tendsto.mpr fun x hx ↦ ?_ obtain ⟨t, ht, htr⟩ := h x hx rw [tendstoUniformlyOn_iff_tendsto] at htr exact htr.mono_left <| prod_mono_right _ <| le_principal_iff.mpr ht @[deprecated (since := "2025-05-22")] alias tendstoLocallyUniformlyOn_of_forall_exists_nhd := tendstoLocallyUniformlyOn_of_forall_exists_nhds /-- If every `x` has a neighbourhood on which `F i` tends uniformly to `f`, then `F i` tends locally uniformly to `f`. (Special case of `tendstoLocallyUniformlyOn_of_forall_exists_nhds` where `s = univ`.) -/ lemma tendstoLocallyUniformly_of_forall_exists_nhds (h : ∀ x, ∃ t ∈ 𝓝 x, TendstoUniformlyOn F f p t) : TendstoLocallyUniformly F f p := tendstoLocallyUniformlyOn_univ.mp <| tendstoLocallyUniformlyOn_of_forall_exists_nhds (by simpa using h) @[deprecated (since := "2025-05-22")] alias tendstoLocallyUniformly_of_forall_exists_nhd := tendstoLocallyUniformly_of_forall_exists_nhds theorem tendstoLocallyUniformlyOn_TFAE [LocallyCompactSpace α] (G : ι → α → β) (g : α → β) (p : Filter ι) (hs : IsOpen s) : List.TFAE [ TendstoLocallyUniformlyOn G g p s, ∀ K, K ⊆ s → IsCompact K → TendstoUniformlyOn G g p K, ∀ x ∈ s, ∃ v ∈ 𝓝[s] x, TendstoUniformlyOn G g p v] := by tfae_have 1 → 2 | h, K, hK1, hK2 => (tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK2).mp (h.mono hK1) tfae_have 2 → 3 | h, x, hx => by obtain ⟨K, ⟨hK1, hK2⟩, hK3⟩ := (compact_basis_nhds x).mem_iff.mp (hs.mem_nhds hx) exact ⟨K, nhdsWithin_le_nhds hK1, h K hK3 hK2⟩ tfae_have 3 → 1 | h, u, hu, x, hx => by obtain ⟨v, hv1, hv2⟩ := h x hx exact ⟨v, hv1, hv2 u hu⟩ tfae_finish theorem tendstoLocallyUniformlyOn_iff_forall_isCompact [LocallyCompactSpace α] (hs : IsOpen s) : TendstoLocallyUniformlyOn F f p s ↔ ∀ K, K ⊆ s → IsCompact K → TendstoUniformlyOn F f p K := (tendstoLocallyUniformlyOn_TFAE F f p hs).out 0 1 lemma tendstoLocallyUniformly_iff_forall_isCompact [LocallyCompactSpace α] : TendstoLocallyUniformly F f p ↔ ∀ K : Set α, IsCompact K → TendstoUniformlyOn F f p K := by simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff_forall_isCompact isOpen_univ, Set.subset_univ, forall_true_left] theorem tendstoLocallyUniformlyOn_iff_filter : TendstoLocallyUniformlyOn F f p s ↔ ∀ x ∈ s, TendstoUniformlyOnFilter F f p (𝓝[s] x) := by simp only [TendstoUniformlyOnFilter, eventually_prod_iff] constructor · rintro h x hx u hu obtain ⟨s, hs1, hs2⟩ := h u hu x hx exact ⟨_, hs2, _, eventually_of_mem hs1 fun x => id, fun hi y hy => hi y hy⟩ · rintro h u hu x hx obtain ⟨pa, hpa, pb, hpb, h⟩ := h x hx u hu exact ⟨pb, hpb, eventually_of_mem hpa fun i hi y hy => h hi hy⟩ theorem tendstoLocallyUniformly_iff_filter : TendstoLocallyUniformly F f p ↔ ∀ x, TendstoUniformlyOnFilter F f p (𝓝 x) := by simpa [← tendstoLocallyUniformlyOn_univ, ← nhdsWithin_univ] using @tendstoLocallyUniformlyOn_iff_filter _ _ _ _ _ F f univ p theorem TendstoLocallyUniformlyOn.tendsto_at (hf : TendstoLocallyUniformlyOn F f p s) {a : α} (ha : a ∈ s) : Tendsto (fun i => F i a) p (𝓝 (f a)) := by refine ((tendstoLocallyUniformlyOn_iff_filter.mp hf) a ha).tendsto_at ?_ simpa only [Filter.principal_singleton] using pure_le_nhdsWithin ha theorem TendstoLocallyUniformlyOn.unique [p.NeBot] [T2Space β] {g : α → β} (hf : TendstoLocallyUniformlyOn F f p s) (hg : TendstoLocallyUniformlyOn F g p s) : s.EqOn f g := fun _a ha => tendsto_nhds_unique (hf.tendsto_at ha) (hg.tendsto_at ha) theorem TendstoLocallyUniformlyOn.congr {G : ι → α → β} (hf : TendstoLocallyUniformlyOn F f p s) (hg : ∀ n, s.EqOn (F n) (G n)) : TendstoLocallyUniformlyOn G f p s := by rintro u hu x hx obtain ⟨t, ht, h⟩ := hf u hu x hx refine ⟨s ∩ t, inter_mem self_mem_nhdsWithin ht, ?_⟩ filter_upwards [h] with i hi y hy using hg i hy.1 ▸ hi y hy.2 theorem TendstoLocallyUniformlyOn.congr_right {g : α → β} (hf : TendstoLocallyUniformlyOn F f p s) (hg : s.EqOn f g) : TendstoLocallyUniformlyOn F g p s := by rintro u hu x hx obtain ⟨t, ht, h⟩ := hf u hu x hx refine ⟨s ∩ t, inter_mem self_mem_nhdsWithin ht, ?_⟩ filter_upwards [h] with i hi y hy using hg hy.1 ▸ hi y hy.2
integral_char.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime order. From mathcomp Require Import ssralg poly finset fingroup morphism perm. From mathcomp Require Import automorphism quotient action countalg finalg zmodp. From mathcomp Require Import commutator cyclic center pgroup sylow gseries. From mathcomp Require Import nilpotent abelian ssrnum ssrint archimedean. From mathcomp Require Import polydiv rat matrix mxalgebra intdiv mxpoly vector. From mathcomp Require Import falgebra fieldext separable galois algC cyclotomic. From mathcomp Require Import algnum mxrepresentation classfun character. (******************************************************************************) (* This file provides some standard results based on integrality properties *) (* of characters, such as theorem asserting that the degree of an irreducible *) (* character of G divides the order of G (Isaacs 3.11), or the famous p^a.q^b *) (* solvability theorem of Burnside. *) (* Defined here: *) (* 'K_k == the kth class sum in gring F G, where k : 'I_#|classes G|, and *) (* F is inferred from the context. *) (* := gset_mx F G (enum_val k) (see mxrepresentation.v). *) (* --> The 'K_k form a basis of 'Z(group_ring F G)%MS. *) (* gring_classM_coef i j k == the coordinate of 'K_i *m 'K_j on 'K_k; this *) (* is usually abbreviated as a i j k. *) (* gring_classM_coef_set A B z == the set of all (x, y) in setX A B such *) (* that x * y = z; if A and B are respectively the ith and jth *) (* conjugacy class of G, and z is in the kth conjugacy class, then *) (* gring_classM_coef i j k is exactly the cardinal of this set. *) (* 'omega_i[A] == the mode of 'chi[G]_i on (A \in 'Z(group_ring algC G))%MS, *) (* i.e., the z such that gring_op 'Chi_i A = z%:M. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. Lemma group_num_field_exists (gT : finGroupType) (G : {group gT}) : {Qn : splittingFieldType rat & galois 1 {:Qn} & {QnC : {rmorphism Qn -> algC} & forall nuQn : argumentType [in 'Gal({:Qn} / 1)], {nu : {rmorphism algC -> algC} | {morph QnC: a / nuQn a >-> nu a}} & {w : Qn & #|G|.-primitive_root w /\ <<1; w>>%VS = fullv & forall (hT : finGroupType) (H : {group hT}) (phi : 'CF(H)), phi \is a character -> forall x, (#[x] %| #|G|)%N -> {a | QnC a = phi x}}}}. Proof. have [z prim_z] := C_prim_root_exists (cardG_gt0 G); set n := #|G| in prim_z *. have [Qn [QnC [[|w []] // [Dz] genQn]]] := num_field_exists [:: z]. have prim_w: n.-primitive_root w by rewrite -Dz fmorph_primitive_root in prim_z. have Q_Xn1: ('X^n - 1 : {poly Qn}) \is a polyOver 1%AS. by rewrite rpredB ?rpred1 ?rpredX //= polyOverX. have splitXn1: splittingFieldFor 1 ('X^n - 1) {:Qn}. pose r := codom (fun i : 'I_n => w ^+ i). have Dr: 'X^n - 1 = \prod_(y <- r) ('X - y%:P). by rewrite -(factor_Xn_sub_1 prim_w) big_mkord big_image. exists r; first by rewrite -Dr eqpxx. apply/eqP; rewrite eqEsubv subvf -genQn adjoin_seqSr //; apply/allP=> /=. by rewrite andbT -root_prod_XsubC -Dr; apply/unity_rootP/prim_expr_order. have Qn_ax : FieldExt_isSplittingField _ Qn by constructor; exists ('X^n - 1). exists (HB.pack_for (splittingFieldType rat) Qn Qn_ax). apply/splitting_galoisField. exists ('X^n - 1); split => //. apply: separable_Xn_sub_1; rewrite -(fmorph_eq0 QnC) rmorph_nat. by rewrite pnatr_eq0 -lt0n cardG_gt0. exists QnC => [// nuQn|]; first exact: (extend_algC_subfield_aut QnC nuQn). rewrite span_seq1 in genQn. exists w => // hT H phi Nphi x x_dv_n. apply: sig_eqW; have [rH ->] := char_reprP Nphi. have [Hx | /cfun0->] := boolP (x \in H); last by exists 0; rewrite rmorph0. have [e [_ [enx1 _] [-> _] _]] := repr_rsim_diag rH Hx. have /fin_all_exists[k Dk] i: exists k, e 0 i = z ^+ k. have [|k ->] := (prim_rootP prim_z) (e 0 i); last by exists k. by have /dvdnP[q ->] := x_dv_n; rewrite mulnC exprM enx1 expr1n. exists (\sum_i w ^+ k i); rewrite rmorph_sum; apply/eq_bigr => i _. by rewrite rmorphXn /= Dz Dk. Qed. Section GenericClassSums. (* This is Isaacs, Theorem (2.4), generalized to an arbitrary field, and with *) (* the combinatorial definition of the coefficients exposed. *) (* This part could move to mxrepresentation.*) Variable (gT : finGroupType) (G : {group gT}) (F : fieldType). Definition gring_classM_coef_set (Ki Kj : {set gT}) g := [set xy in [predX Ki & Kj] | let: (x, y) := xy in x * y == g]%g. Definition gring_classM_coef (i j k : 'I_#|classes G|) := #|gring_classM_coef_set (enum_val i) (enum_val j) (repr (enum_val k))|. Definition gring_class_sum (i : 'I_#|classes G|) := gset_mx F G (enum_val i). Local Notation "''K_' i" := (gring_class_sum i) (at level 8, i at level 2, format "''K_' i") : ring_scope. Local Notation a := gring_classM_coef. Lemma gring_class_sum_central i : ('K_i \in 'Z(group_ring F G))%MS. Proof. by rewrite -classg_base_center (eq_row_sub i) // rowK. Qed. Lemma set_gring_classM_coef (i j k : 'I_#|classes G|) g : g \in enum_val k -> a i j k = #|gring_classM_coef_set (enum_val i) (enum_val j) g|. Proof. rewrite /a; have /repr_classesP[] := enum_valP k; move: (repr _) => g1 Gg1 ->. have [/imsetP[zi Gzi ->] /imsetP[zj Gzj ->]] := (enum_valP i, enum_valP j). move=> g1Gg; have Gg := subsetP (class_subG Gg1 (subxx _)) _ g1Gg. set Aij := gring_classM_coef_set _ _. without loss suffices IH: g g1 Gg Gg1 g1Gg / (#|Aij g1| <= #|Aij g|)%N. by apply/eqP; rewrite eqn_leq !IH // class_sym. have [w Gw Dg] := imsetP g1Gg; pose J2 (v : gT) xy := (xy.1 ^ v, xy.2 ^ v)%g. have J2inj: injective (J2 w). by apply: can_inj (J2 w^-1)%g _ => [[x y]]; rewrite /J2 /= !conjgK. rewrite -(card_imset _ J2inj) subset_leq_card //; apply/subsetP. move=> _ /imsetP[[x y] /setIdP[/andP[/= x1Gx y1Gy] Dxy1] ->] /[!inE]/=. rewrite !(class_sym _ (_ ^ _)) !classGidl // class_sym x1Gx class_sym y1Gy. by rewrite -conjMg (eqP Dxy1) /= -Dg. Qed. Theorem gring_classM_expansion i j : 'K_i *m 'K_j = \sum_k (a i j k)%:R *: 'K_k. Proof. have [/imsetP[zi Gzi dKi] /imsetP[zj Gzj dKj]] := (enum_valP i, enum_valP j). pose aG := regular_repr F G; have sKG := subsetP (class_subG _ (subxx G)). transitivity (\sum_(x in zi ^: G) \sum_(y in zj ^: G) aG (x * y)%g). rewrite mulmx_suml -/aG dKi; apply: eq_bigr => x /sKG Gx. rewrite mulmx_sumr -/aG dKj; apply: eq_bigr => y /sKG Gy. by rewrite repr_mxM ?Gx ?Gy. pose h2 xy : gT := (xy.1 * xy.2)%g. pose h1 xy := enum_rank_in (classes1 G) (h2 xy ^: G). rewrite pair_big (partition_big h1 xpredT) //=; apply: eq_bigr => k _. rewrite (partition_big h2 [in enum_val k]) /= => [|[x y]]; last first. case/andP=> /andP[/= /sKG Gx /sKG Gy] /eqP <-. by rewrite enum_rankK_in ?class_refl ?mem_classes ?groupM ?Gx ?Gy. rewrite scaler_sumr; apply: eq_bigr => g Kk_g; rewrite scaler_nat. rewrite (set_gring_classM_coef _ _ Kk_g) -sumr_const; apply: eq_big => [] [x y]. rewrite !inE /= dKi dKj /h1 /h2 /=; apply: andb_id2r => /eqP ->. have /imsetP[zk Gzk dKk] := enum_valP k; rewrite dKk in Kk_g. by rewrite (class_eqP Kk_g) -dKk enum_valK_in eqxx andbT. by rewrite /h2 /= => /andP[_ /eqP->]. Qed. End GenericClassSums. HB.lock Definition gring_irr_mode (gT : finGroupType) (G : {group gT}) (i : Iirr G) := ('chi_i 1%g)^-1 *: 'chi_i. Canonical gring_irr_mode_unlockable := Unlockable gring_irr_mode.unlock. Arguments gring_irr_mode {gT G%_G} i%_R _%_g : extra scopes. Notation "''K_' i" := (gring_class_sum _ i) (at level 8, i at level 2, format "''K_' i") : ring_scope. Notation "''omega_' i [ A ]" := (xcfun (gring_irr_mode i) A) (i at level 2, format "''omega_' i [ A ]") : ring_scope. Section IntegralChar. Variables (gT : finGroupType) (G : {group gT}). (* This is Isaacs, Corollary (3.6). *) Lemma Aint_char (chi : 'CF(G)) x : chi \is a character -> chi x \in Aint. Proof. have [Gx /char_reprP[rG ->] {chi} | /cfun0->//] := boolP (x \in G). have [e [_ [unit_e _] [-> _] _]] := repr_rsim_diag rG Gx. rewrite rpred_sum // => i _; apply: (@Aint_unity_root #[x]) => //. exact/unity_rootP. Qed. Lemma Aint_irr i x : 'chi[G]_i x \in Aint. Proof. exact/Aint_char/irr_char. Qed. Local Notation R_G := (group_ring algCfield G). Local Notation a := gring_classM_coef. (* This is Isaacs (2.25). *) Lemma mx_irr_gring_op_center_scalar n (rG : mx_representation algCfield G n) A : mx_irreducible rG -> (A \in 'Z(R_G))%MS -> is_scalar_mx (gring_op rG A). Proof. move/groupC=> irrG /center_mxP[R_A cGA]. apply: mx_abs_irr_cent_scalar irrG _ _; apply/centgmxP => x Gx. by rewrite -(gring_opG rG Gx) -!gring_opM ?cGA // envelop_mx_id. Qed. Section GringIrrMode. Variable i : Iirr G. Let n := irr_degree (socle_of_Iirr i). Let mxZn_inj: injective (@scalar_mx algCfield n). Proof. by rewrite -[n]prednK ?irr_degree_gt0 //; apply: fmorph_inj. Qed. Lemma cfRepr_gring_center n1 (rG : mx_representation algCfield G n1) A : cfRepr rG = 'chi_i -> (A \in 'Z(R_G))%MS -> gring_op rG A = 'omega_i[A]%:M. Proof. move=> def_rG Z_A; rewrite unlock xcfunZl -{2}def_rG xcfun_repr. have irr_rG: mx_irreducible rG. have sim_rG: mx_rsim 'Chi_i rG by apply: cfRepr_inj; rewrite irrRepr. exact: mx_rsim_irr sim_rG (socle_irr _). have /is_scalar_mxP[e ->] := mx_irr_gring_op_center_scalar irr_rG Z_A. congr _%:M; apply: (canRL (mulKf (irr1_neq0 i))). by rewrite mulrC -def_rG cfunE repr_mx1 group1 -mxtraceZ scalemx1. Qed. Lemma irr_gring_center A : (A \in 'Z(R_G))%MS -> gring_op 'Chi_i A = 'omega_i[A]%:M. Proof. exact: cfRepr_gring_center (irrRepr i). Qed. Lemma gring_irr_modeM A B : (A \in 'Z(R_G))%MS -> (B \in 'Z(R_G))%MS -> 'omega_i[A *m B] = 'omega_i[A] * 'omega_i[B]. Proof. move=> Z_A Z_B; have [[R_A cRA] [R_B cRB]] := (center_mxP Z_A, center_mxP Z_B). apply: mxZn_inj; rewrite scalar_mxM -!irr_gring_center ?gring_opM //. apply/center_mxP; split=> [|C R_C]; first exact: envelop_mxM. by rewrite mulmxA cRA // -!mulmxA cRB. Qed. Lemma gring_mode_class_sum_eq (k : 'I_#|classes G|) g : g \in enum_val k -> 'omega_i['K_k] = #|g ^: G|%:R * 'chi_i g / 'chi_i 1%g. Proof. have /imsetP[x Gx DxG] := enum_valP k; rewrite DxG => /imsetP[u Gu ->{g}]. rewrite unlock classGidl ?cfunJ {u Gu}// mulrC mulr_natl. rewrite xcfunZl raddf_sum DxG -sumr_const /=; congr (_ * _). by apply: eq_bigr => _ /imsetP[u Gu ->]; rewrite xcfunG ?groupJ ?cfunJ. Qed. (* This is Isaacs, Theorem (3.7). *) Lemma Aint_gring_mode_class_sum k : 'omega_i['K_k] \in Aint. Proof. move: k; pose X := [tuple 'omega_i['K_k] | k < #|classes G| ]. have memX k: 'omega_i['K_k] \in X by apply: image_f. have S_P := Cint_spanP X; set S := Cint_span X in S_P. have S_X: {subset X <= S} by apply: mem_Cint_span. have S_1: 1 \in S. apply: S_X; apply/codomP; exists (enum_rank_in (classes1 G) 1%g). rewrite (@gring_mode_class_sum_eq _ 1%g) ?enum_rankK_in ?classes1 //. by rewrite mulfK ?irr1_neq0 // class1G cards1. suffices Smul: mulr_closed S. by move=> k; apply: fin_Csubring_Aint S_P _ _; rewrite ?S_X. split=> // _ _ /S_P[x ->] /S_P[y ->]. rewrite mulr_sumr rpred_sum // => j _. rewrite mulrzAr mulr_suml rpredMz ?rpred_sum // => k _. rewrite mulrzAl rpredMz {x y}// !nth_mktuple. rewrite -gring_irr_modeM ?gring_class_sum_central //. rewrite gring_classM_expansion raddf_sum rpred_sum // => jk _. by rewrite scaler_nat raddfMn rpredMn ?S_X ?memX. Qed. (* A more usable reformulation that does not involve the class sums. *) Corollary Aint_class_div_irr1 x : x \in G -> #|x ^: G|%:R * 'chi_i x / 'chi_i 1%g \in Aint. Proof. move=> Gx; have clGxG := mem_classes Gx; pose k := enum_rank_in clGxG (x ^: G). have k_x: x \in enum_val k by rewrite enum_rankK_in // class_refl. by rewrite -(gring_mode_class_sum_eq k_x) Aint_gring_mode_class_sum. Qed. (* This is Isaacs, Theorem (3.8). *) Theorem coprime_degree_support_cfcenter g : coprime (Num.truncn ('chi_i 1%g)) #|g ^: G| -> g \notin ('Z('chi_i))%CF -> 'chi_i g = 0. Proof. set m := Num.truncn _ => co_m_gG notZg. have [Gg | /cfun0-> //] := boolP (g \in G). have Dm: 'chi_i 1%g = m%:R by rewrite truncnK ?Cnat_irr1. have m_gt0: (0 < m)%N by rewrite -ltC_nat -Dm irr1_gt0. have nz_m: m%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n. pose alpha := 'chi_i g / m%:R. have a_lt1: `|alpha| < 1. rewrite normrM normfV normr_nat -{2}(divff nz_m). rewrite lt_def (can_eq (mulfVK nz_m)) eq_sym -{1}Dm -irr_cfcenterE // notZg. by rewrite ler_pM2r ?invr_gt0 ?ltr0n // -Dm char1_ge_norm ?irr_char. have Za: alpha \in Aint. have [u _ /dvdnP[v eq_uv]] := Bezoutl #|g ^: G| m_gt0. suffices ->: alpha = v%:R * 'chi_i g - u%:R * (alpha * #|g ^: G|%:R). rewrite rpredB // rpredM ?rpred_nat ?Aint_irr //. by rewrite mulrC mulrA -Dm Aint_class_div_irr1. rewrite -mulrCA -[v%:R](mulfK nz_m) -!natrM -eq_uv (eqnP co_m_gG). by rewrite mulrAC -mulrA -/alpha mulr_natl mulr_natr mulrS addrK. have [Qn galQn [QnC gQnC [_ _ Qn_g]]] := group_num_field_exists <[g]>. have{Qn_g} [a Da]: exists a, QnC a = alpha. rewrite /alpha; have [a <-] := Qn_g _ G _ (irr_char i) g (dvdnn _). by exists (a / m%:R); rewrite fmorph_div rmorph_nat. have Za_nu nu: sval (gQnC nu) alpha \in Aint by rewrite Aint_aut. have norm_a_nu nu: `|sval (gQnC nu) alpha| <= 1. move: {nu}(sval _) => nu; rewrite fmorph_div rmorph_nat normrM normfV. rewrite normr_nat -Dm -(ler_pM2r (irr1_gt0 (aut_Iirr nu i))) mul1r. congr (_ <= _): (char1_ge_norm g (irr_char (aut_Iirr nu i))). by rewrite !aut_IirrE !cfunE Dm rmorph_nat divfK. pose beta := QnC (galNorm 1 {:Qn} a). have Dbeta: beta = \prod_(nu in 'Gal({:Qn} / 1)) sval (gQnC nu) alpha. rewrite /beta rmorph_prod. apply: eq_bigr => nu _. by case: (gQnC nu) => f /= ->; rewrite Da. have Zbeta: beta \in Num.int. apply: Cint_rat_Aint; last by rewrite Dbeta rpred_prod. rewrite /beta; have /vlineP[/= c ->] := mem_galNorm galQn (memvf a). by rewrite alg_num_field fmorph_rat rpred_rat. have [|nz_a] := boolP (alpha == 0). by rewrite (can2_eq (divfK _) (mulfK _)) // mul0r => /eqP. have: beta != 0 by rewrite Dbeta; apply/prodf_neq0 => nu _; rewrite fmorph_eq0. move/(norm_intr_ge1 Zbeta); rewrite lt_geF //; apply: le_lt_trans a_lt1. rewrite -[`|alpha|]mulr1 Dbeta (bigD1 1%g) ?group1 //= -Da. case: (gQnC _) => /= _ <-. rewrite gal_id normrM -subr_ge0 -mulrBr mulr_ge0 // Da subr_ge0. elim/big_rec: _ => [|nu c _]; first by rewrite normr1 lexx. apply: le_trans; rewrite -subr_ge0 -{1}[`|c|]mul1r normrM -mulrBl. by rewrite mulr_ge0 // subr_ge0 norm_a_nu. Qed. End GringIrrMode. (* This is Isaacs, Theorem (3.9). *) Theorem primes_class_simple_gt1 C : simple G -> ~~ abelian G -> C \in (classes G)^# -> (size (primes #|C|) > 1)%N. Proof. move=> simpleG not_cGG /setD1P[ntC /imsetP[g Gg defC]]. have{ntC} nt_g: g != 1%g by rewrite defC classG_eq1 in ntC. rewrite ltnNge {C}defC; set m := #|_|; apply/negP=> p_natC. have{p_natC} [p p_pr [a Dm]]: {p : nat & prime p & {a | m = p ^ a}%N}. have /prod_prime_decomp->: (0 < m)%N by rewrite /m -index_cent1. rewrite prime_decompE; case Dpr: (primes _) p_natC => [|p []] // _. by exists 2%N => //; rewrite big_nil; exists 0. rewrite big_seq1; exists p; last by exists (logn p m). by have:= mem_primes p m; rewrite Dpr mem_head => /esym/and3P[]. have{simpleG} [ntG minG] := simpleP _ simpleG. pose p_dv1 i := (p %| 'chi[G]_i 1%g)%C. have p_dvd_supp_g i: ~~ p_dv1 i && (i != 0) -> 'chi_i g = 0. rewrite /p_dv1 irr1_degree dvdC_nat -prime_coprime // => /andP[co_p_i1 nz_i]. have fful_i: cfker 'chi_i = [1]. have /minG[//|/eqP] := cfker_normal 'chi_i. by rewrite eqEsubset subGcfker (negPf nz_i) andbF. have trivZ: 'Z(G) = [1] by have /minG[|/center_idP/idPn] := center_normal G. have trivZi: ('Z('chi_i))%CF = [1]. apply/trivgP; rewrite -quotient_sub1 ?norms1 //= -fful_i cfcenter_eq_center. rewrite fful_i subG1 -(isog_eq1 (isog_center (quotient1_isog G))) /=. by rewrite trivZ. rewrite coprime_degree_support_cfcenter ?trivZi ?inE //. by rewrite -/m Dm irr1_degree natrK coprime_sym coprimeXl. pose alpha := \sum_(i | p_dv1 i && (i != 0)) 'chi_i 1%g / p%:R * 'chi_i g. have nz_p: p%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n prime_gt0. have Dalpha: alpha = - 1 / p%:R. apply/(canRL (mulfK nz_p))/eqP; rewrite -addr_eq0 addrC; apply/eqP/esym. transitivity (cfReg G g); first by rewrite cfRegE (negPf nt_g). rewrite cfReg_sum sum_cfunE (bigD1 0) //= irr0 !cfunE cfun11 cfun1E Gg. rewrite mulr1; congr (1 + _); rewrite (bigID p_dv1) /= addrC big_andbC. rewrite big1 => [|i /p_dvd_supp_g chig0]; last by rewrite cfunE chig0 mulr0. rewrite add0r big_andbC mulr_suml; apply: eq_bigr => i _. by rewrite mulrAC divfK // cfunE. suffices: (p %| 1)%C by rewrite (dvdC_nat p 1) dvdn1 -(subnKC (prime_gt1 p_pr)). rewrite unfold_in (negPf nz_p). rewrite Cint_rat_Aint ?rpred_div ?rpred1 ?rpred_nat //. rewrite -rpredN // -mulNr -Dalpha rpred_sum // => i /andP[/dvdCP[c Zc ->] _]. by rewrite mulfK // rpredM ?Aint_irr ?Aint_Cint. Qed. End IntegralChar. Section MoreIntegralChar. Implicit Type gT : finGroupType. (* This is Burnside's famous p^a.q^b theorem (Isaacs, Theorem (3.10)). *) Theorem Burnside_p_a_q_b gT (G : {group gT}) : (size (primes #|G|) <= 2)%N -> solvable G. Proof. move: {2}_.+1 (ltnSn #|G|) => n; elim: n => // n IHn in gT G *. rewrite ltnS => leGn piGle2; have [simpleG | ] := boolP (simple G); last first. rewrite negb_forall_in => /exists_inP[N sNG]; rewrite eq_sym. have [->|] := eqVneq N G. rewrite groupP /= genGid normG andbT eqb_id negbK => /eqP->. exact: solvable1. rewrite [N == G]eqEproper sNG eqbF_neg !negbK => ltNG /and3P[grN]. case/isgroupP: grN => {}N -> in sNG ltNG *; rewrite /= genGid => ntN nNG. have nsNG: N <| G by apply/andP. have dv_le_pi m: (m %| #|G| -> size (primes m) <= 2)%N. move=> m_dv_G; apply: leq_trans piGle2. by rewrite uniq_leq_size ?primes_uniq //; apply: pi_of_dvd. rewrite (series_sol nsNG) !IHn ?dv_le_pi ?cardSg ?dvdn_quotient //. by apply: leq_trans leGn; apply: ltn_quotient. by apply: leq_trans leGn; apply: proper_card. have [->|[p p_pr p_dv_G]] := trivgVpdiv G; first exact: solvable1. have piGp: p \in \pi(G) by rewrite mem_primes p_pr cardG_gt0. have [P sylP] := Sylow_exists p G; have [sPG pP p'GP] := and3P sylP. have ntP: P :!=: 1%g by rewrite -rank_gt0 (rank_Sylow sylP) p_rank_gt0. have /trivgPn[g /setIP[Pg cPg] nt_g]: 'Z(P) != 1%g. by rewrite center_nil_eq1 // (pgroup_nil pP). apply: abelian_sol; have: (size (primes #|g ^: G|) <= 1)%N. rewrite -ltnS -[_.+1]/(size (p :: _)) (leq_trans _ piGle2) //. rewrite -index_cent1 uniq_leq_size // => [/= | q]. rewrite primes_uniq -p'natEpi ?(pnat_dvd _ p'GP) ?indexgS //. by rewrite subsetI sPG sub_cent1. by rewrite inE => /predU1P[-> // |]; apply: pi_of_dvd; rewrite ?dvdn_indexg. rewrite leqNgt; apply: contraR => /primes_class_simple_gt1-> //. by rewrite !inE classG_eq1 nt_g mem_classes // (subsetP sPG). Qed. (* This is Isaacs, Theorem (3.11). *) Theorem dvd_irr1_cardG gT (G : {group gT}) i : ('chi[G]_i 1%g %| #|G|)%C. Proof. rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //=. by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1. rewrite -[n in n / _]/(_ *+ true) -(eqxx i) -mulr_natr. rewrite -first_orthogonality_relation mulVKf ?neq0CG //. rewrite sum_by_classes => [|x y Gx Gy]; rewrite -?conjVg ?cfunJ //. rewrite mulr_suml rpred_sum // => K /repr_classesP[Gx {1}->]. by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1. Qed. (* This is Isaacs, Theorem (3.12). *) Theorem dvd_irr1_index_center gT (G : {group gT}) i : ('chi[G]_i 1%g %| #|G : 'Z('chi_i)%CF|)%C. Proof. without loss fful: gT G i / cfaithful 'chi_i. rewrite -{2}[i](quo_IirrK _ (subxx _)) 1?mod_IirrE ?cfModE ?cfker_normal //. rewrite morph1; set i1 := quo_Iirr _ i => /(_ _ _ i1) IH. have fful_i1: cfaithful 'chi_i1. by rewrite quo_IirrE ?cfker_normal ?cfaithful_quo. have:= IH fful_i1; rewrite cfcenter_fful_irr // -cfcenter_eq_center. rewrite index_quotient_eq ?cfcenter_sub ?cfker_norm //. by rewrite setIC subIset // normal_sub ?cfker_center_normal. have [lambda lin_lambda Dlambda] := cfcenter_Res 'chi_i. have DchiZ: {in G & 'Z(G), forall x y, 'chi_i (x * y)%g = 'chi_i x * lambda y}. rewrite -(cfcenter_fful_irr fful) => x y Gx Zy. apply: (mulfI (irr1_neq0 i)); rewrite mulrCA. transitivity ('chi_i x * ('chi_i 1%g *: lambda) y); last by rewrite !cfunE. rewrite -Dlambda cfResE ?cfcenter_sub //. rewrite -irrRepr cfcenter_repr !cfunE in Zy *. case/setIdP: Zy => Gy /is_scalar_mxP[e De]. rewrite repr_mx1 group1 (groupM Gx Gy) (repr_mxM _ Gx Gy) Gx Gy De. by rewrite mul_mx_scalar mxtraceZ mulrCA mulrA mulrC -mxtraceZ scalemx1. have inj_lambda: {in 'Z(G) &, injective lambda}. rewrite -(cfcenter_fful_irr fful) => x y Zx Zy eq_xy. apply/eqP; rewrite eq_mulVg1 -in_set1 (subsetP fful) // cfkerEirr inE. apply/eqP; transitivity ('Res['Z('chi_i)%CF] 'chi_i (x^-1 * y)%g). by rewrite cfResE ?cfcenter_sub // groupM ?groupV. rewrite Dlambda !cfunE lin_charM ?groupV // -eq_xy -lin_charM ?groupV //. by rewrite mulrC mulVg lin_char1 ?mul1r. rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //. by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1. rewrite (cfcenter_fful_irr fful) nCdivE natf_indexg ?center_sub //=. have ->: #|G|%:R = \sum_(x in G) 'chi_i x * 'chi_i (x^-1)%g. rewrite -[_%:R]mulr1; apply: canLR (mulVKf (neq0CG G)) _. by rewrite first_orthogonality_relation eqxx. rewrite (big_setID [set x | 'chi_i x == 0]) /= -setIdE. rewrite big1 ?add0r => [| x /setIdP[_ /eqP->]]; last by rewrite mul0r. pose h x := (x ^: G * 'Z(G))%g; rewrite (partition_big_imset h). rewrite !mulr_suml rpred_sum //= => _ /imsetP[x /setDP[Gx nz_chi_x] ->]. have: #|x ^: G|%:R * ('chi_i x * 'chi_i x^-1%g) / 'chi_i 1%g \in Aint. by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1. congr 2 (_ * _ \in Aint); apply: canRL (mulfK (neq0CG _)) _. rewrite inE in nz_chi_x. transitivity ('chi_i x * 'chi_i (x^-1)%g *+ #|h x|); last first. rewrite -sumr_const. apply: eq_big => [y | _ /mulsgP[_ z /imsetP[u Gu ->] Zz] ->]. rewrite !inE -andbA; apply/idP/and3P=> [|[_ _ /eqP <-]]; last first. by rewrite -{1}[y]mulg1 mem_mulg ?class_refl. case/mulsgP=> _ z /imsetP[u Gu ->] Zz ->; have /centerP[Gz cGz] := Zz. rewrite groupM 1?DchiZ ?groupJ ?cfunJ //; split=> //. by rewrite mulf_neq0 // lin_char_neq0 /= ?cfcenter_fful_irr. rewrite -[z](mulKg u) -cGz // -conjMg /h classGidl {u Gu}//. apply/eqP/setP=> w; apply/mulsgP/mulsgP=> [][_ z1 /imsetP[v Gv ->] Zz1 ->]. exists (x ^ v)%g (z * z1)%g; rewrite ?imset_f ?groupM //. by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg. exists ((x * z) ^ v)%g (z^-1 * z1)%g; rewrite ?imset_f ?groupM ?groupV //. by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg mulKVg. rewrite !irr_inv DchiZ ?groupJ ?cfunJ // rmorphM mulrACA -!normCK -exprMn. by rewrite (normC_lin_char lin_lambda) ?mulr1 //= cfcenter_fful_irr. rewrite mulrAC -natrM mulr_natl; congr (_ *+ _). symmetry; rewrite /h /mulg /= /set_mulg [in _ @2: (_, _)]unlock cardsE. rewrite -cardX card_in_image // => [] [y1 z1] [y2 z2] /=. move=> /andP[/=/imsetP[u1 Gu1 ->] Zz1] /andP[/=/imsetP[u2 Gu2 ->] Zz2] {y1 y2}. move=> eq12; have /eqP := congr1 'chi_i eq12. rewrite !(cfunJ, DchiZ) ?groupJ // (can_eq (mulKf nz_chi_x)). rewrite (inj_in_eq inj_lambda) // => /eqP eq_z12; rewrite eq_z12 in eq12 *. by rewrite (mulIg _ _ _ eq12). Qed. (* This is Isaacs, Problem (3.7). *) Lemma gring_classM_coef_sum_eq gT (G : {group gT}) j1 j2 k g1 g2 g : let a := @gring_classM_coef gT G j1 j2 in let a_k := a k in g1 \in enum_val j1 -> g2 \in enum_val j2 -> g \in enum_val k -> let sum12g := \sum_i 'chi[G]_i g1 * 'chi_i g2 * ('chi_i g)^* / 'chi_i 1%g in a_k%:R = (#|enum_val j1| * #|enum_val j2|)%:R / #|G|%:R * sum12g. Proof. move=> a /= Kg1 Kg2 Kg; rewrite mulrAC; apply: canRL (mulfK (neq0CG G)) _. transitivity (\sum_j (#|G| * a j)%:R *+ (j == k) : algC). by rewrite (bigD1 k) //= eqxx -natrM mulnC big1 ?addr0 // => j /negPf->. have defK (j : 'I_#|classes G|) x: x \in enum_val j -> enum_val j = x ^: G. by have /imsetP[y Gy ->] := enum_valP j => /class_eqP. have Gg: g \in G. by case/imsetP: (enum_valP k) Kg => x Gx -> /imsetP[y Gy ->]; apply: groupJ. transitivity (\sum_j \sum_i 'omega_i['K_j] * 'chi_i 1%g * ('chi_i g)^* *+ a j). apply: eq_bigr => j _; have /imsetP[z Gz Dj] := enum_valP j. have Kz: z \in enum_val j by rewrite Dj class_refl. rewrite -(Lagrange (subsetIl G 'C[z])) index_cent1 -mulnA natrM -mulrnAl. have ->: (j == k) = (z \in enum_val k). by rewrite -(inj_eq enum_val_inj); apply/eqP/idP=> [<-|/defK->]. rewrite (defK _ g) // -second_orthogonality_relation // mulr_suml. apply: eq_bigr=> i _; rewrite natrM mulrA mulr_natr mulrC mulrA. by rewrite (gring_mode_class_sum_eq i Kz) divfK ?irr1_neq0. rewrite exchange_big /= mulr_sumr; apply: eq_bigr => i _. transitivity ('omega_i['K_j1 *m 'K_j2] * 'chi_i 1%g * ('chi_i g)^*). rewrite gring_classM_expansion -/a raddf_sum !mulr_suml /=. by apply: eq_bigr => j _; rewrite xcfunZr -!mulrA mulr_natl. rewrite !mulrA 2![_ / _]mulrAC (defK _ _ Kg1) (defK _ _ Kg2); congr (_ * _). rewrite gring_irr_modeM ?gring_class_sum_central // mulnC natrM. rewrite (gring_mode_class_sum_eq i Kg2) !mulrA divfK ?irr1_neq0 //. by congr (_ * _); rewrite [_ * _]mulrC (gring_mode_class_sum_eq i Kg1) !mulrA. Qed. (* This is Isaacs, Problem (2.16). *) Lemma index_support_dvd_degree gT (G H : {group gT}) chi : H \subset G -> chi \is a character -> chi \in 'CF(G, H) -> (H :==: 1%g) || abelian G -> (#|G : H| %| chi 1%g)%C. Proof. move=> sHG Nchi Hchi ZHG. suffices: (#|G : H| %| 'Res[H] chi 1%g)%C by rewrite cfResE ?group1. rewrite ['Res _]cfun_sum_cfdot sum_cfunE rpred_sum // => i _. rewrite cfunE dvdC_mulr ?intr_nat ?Cnat_irr1 //. have [j ->]: exists j, 'chi_i = 'Res 'chi[G]_j. case/predU1P: ZHG => [-> | cGG] in i *. suffices ->: i = 0 by exists 0; rewrite !irr0 cfRes_cfun1 ?sub1G. apply/val_inj; case: i => [[|i] //=]; rewrite ltnNge NirrE. by rewrite (@leq_trans 1) // leqNgt classes_gt1 eqxx. have linG := char_abelianP G cGG; have linG1 j := eqP (proj2 (andP (linG j))). have /fin_all_exists[rH DrH] j: exists k, 'Res[H, G] 'chi_j = 'chi_k. apply/irrP/lin_char_irr/andP. by rewrite cfRes_char ?irr_char // cfRes1 ?linG1. suffices{i} all_rH: codom rH =i Iirr H. by exists (iinv (all_rH i)); rewrite DrH f_iinv. apply/subset_cardP; last exact/subsetP; apply/esym/eqP. rewrite card_Iirr_abelian ?(abelianS sHG) //. rewrite -(eqn_pmul2r (indexg_gt0 G H)) Lagrange //; apply/eqP. rewrite -sum_nat_const -card_Iirr_abelian // -sum1_card. rewrite (partition_big rH [in codom rH]) /=; last exact: image_f. have nsHG: H <| G by rewrite -sub_abelian_normal. apply: eq_bigr => _ /codomP[i ->]; rewrite -card_quotient ?normal_norm //. rewrite -card_Iirr_abelian ?quotient_abelian //. have Mlin j1 j2: exists k, 'chi_j1 * 'chi_j2 = 'chi[G]_k. exact/irrP/lin_char_irr/rpredM. have /fin_all_exists[rQ DrQ] (j : Iirr (G / H)) := Mlin i (mod_Iirr j). have mulJi: ('chi[G]_i)^*%CF * 'chi_i = 1. apply/cfun_inP=> x Gx; rewrite !cfunE /= -lin_charV_conj ?linG // cfun1E Gx. by rewrite lin_charV ?mulVf ?lin_char_neq0 ?linG. have inj_rQ: injective rQ. move=> j1 j2 /(congr1 (fun k => (('chi_i)^*%CF * 'chi_k) / H)%CF). by rewrite -!DrQ !mulrA mulJi !mul1r !mod_IirrE ?cfModK // => /irr_inj. rewrite -(card_imset _ inj_rQ) -sum1_card; apply: eq_bigl => j. rewrite -(inj_eq irr_inj) -!DrH; apply/eqP/imsetP=> [eq_ij | [k _ ->]]. have [k Dk] := Mlin (conjC_Iirr i) j; exists (quo_Iirr H k) => //. apply/irr_inj; rewrite -DrQ quo_IirrK //. by rewrite -Dk conjC_IirrE mulrCA mulrA mulJi mul1r. apply/subsetP=> x Hx; have Gx := subsetP sHG x Hx. rewrite cfkerEirr inE linG1 -Dk conjC_IirrE; apply/eqP. transitivity ((1 : 'CF(G)) x); last by rewrite cfun1E Gx. by rewrite -mulJi !cfunE -!(cfResE _ sHG Hx) eq_ij. rewrite -DrQ; apply/cfun_inP=> x Hx; rewrite !cfResE // cfunE mulrC. by rewrite cfker1 ?linG1 ?mul1r ?(subsetP _ x Hx) // mod_IirrE ?cfker_mod. have: (#|G : H| %| #|G : H|%:R * '[chi, 'chi_j])%C. by rewrite dvdC_mulr ?intr_nat ?Cnat_cfdot_char_irr. congr (_ %| _)%C; rewrite (cfdotEl _ Hchi) -(Lagrange sHG) mulnC natrM. rewrite invfM -mulrA mulVKf ?neq0CiG //; congr (_ * _). by apply: eq_bigr => x Hx; rewrite !cfResE. Qed. (* This is Isaacs, Theorem (3.13). *) Theorem faithful_degree_p_part gT (p : nat) (G P : {group gT}) i : cfaithful 'chi[G]_i -> p.-nat (Num.truncn ('chi_i 1%g)) -> p.-Sylow(G) P -> abelian P -> 'chi_i 1%g = (#|G : 'Z(G)|`_p)%:R. Proof. have [p_pr | pr'p] := boolP (prime p); last first. have p'n n: (n > 0)%N -> p^'.-nat n. by move/p'natEpi->; rewrite mem_primes (negPf pr'p). rewrite irr1_degree natrK => _ /pnat_1-> => [_ _|]. by rewrite part_p'nat ?p'n. by rewrite p'n ?irr_degree_gt0. move=> fful_i /p_natP[a Dchi1] sylP cPP. have Dchi1C: 'chi_i 1%g = (p ^ a)%:R by rewrite -Dchi1 irr1_degree natrK. have pa_dv_ZiG: (p ^ a %| #|G : 'Z(G)|)%N. rewrite -dvdC_nat -[pa in (pa %| _)%C]Dchi1C -(cfcenter_fful_irr fful_i). exact: dvd_irr1_index_center. have [sPG pP p'PiG] := and3P sylP. have ZchiP: 'Res[P] 'chi_i \in 'CF(P, P :&: 'Z(G)). apply/cfun_onP=> x /[1!inE]; have [Px | /cfun0->//] := boolP (x \in P). rewrite /= -(cfcenter_fful_irr fful_i) cfResE //. apply: coprime_degree_support_cfcenter. rewrite Dchi1 coprimeXl // prime_coprime // -p'natE //. apply: pnat_dvd p'PiG; rewrite -index_cent1 indexgS // subsetI sPG. by rewrite sub_cent1 (subsetP cPP). have /andP[_ nZG] := center_normal G; have nZP := subset_trans sPG nZG. apply/eqP; rewrite Dchi1C eqr_nat eqn_dvd -{1}(pfactorK a p_pr) -p_part. rewrite partn_dvd //= -dvdC_nat -[pa in (_ %| pa)%C]Dchi1C -card_quotient //=. rewrite -(card_Hall (quotient_pHall nZP sylP)) card_quotient // -indexgI. rewrite -(cfResE _ sPG) // index_support_dvd_degree ?subsetIl ?cPP ?orbT //. by rewrite cfRes_char ?irr_char. Qed. (* This is Isaacs, Lemma (3.14). *) (* Note that the assumption that G be cyclic is unnecessary, as S will be *) (* empty if this is not the case. *) Lemma sum_norm2_char_generators gT (G : {group gT}) (chi : 'CF(G)) : let S := [pred s | generator G s] in chi \is a character -> {in S, forall s, chi s != 0} -> \sum_(s in S) `|chi s| ^+ 2 >= #|S|%:R. Proof. move=> S Nchi nz_chi_S; pose n := #|G|. have [g Sg | S_0] := pickP (generator G); last first. by rewrite eq_card0 // big_pred0 ?lerr. have defG: <[g]> = G by apply/esym/eqP. have [cycG Gg]: cyclic G /\ g \in G by rewrite -defG cycle_cyclic cycle_id. pose I := {k : 'I_n | coprime n k}; pose ItoS (k : I) := (g ^+ sval k)%g. have imItoS: codom ItoS =i S. move=> s; rewrite inE /= /ItoS /I /n /S -defG -orderE. apply/codomP/idP=> [[[i cogi] ->] | Ss]; first by rewrite generator_coprime. have [m ltmg Ds] := cyclePmin (cycle_generator Ss). by rewrite Ds generator_coprime in Ss; apply: ex_intro (Sub (Sub m _) _) _. have /injectiveP injItoS: injective ItoS. move=> k1 k2 /eqP; apply: contraTeq. by rewrite eq_expg_mod_order orderE defG -/n !modn_small. have [Qn galQn [QnC gQnC [eps [pr_eps defQn] QnG]]] := group_num_field_exists G. have{QnG} QnGg := QnG _ G _ _ g (order_dvdG Gg). pose calG := 'Gal({:Qn} / 1). have /fin_all_exists2[ItoQ inItoQ defItoQ] (k : I): exists2 nu, nu \in calG & nu eps = eps ^+ val k. - case: k => [[m _] /=]; rewrite coprime_sym => /Qn_aut_exists[nuC DnuC]. have [nuQ DnuQ] := restrict_aut_to_normal_num_field QnC nuC. have hom_nu: kHom 1 {:Qn} (linfun nuQ). rewrite k1HomE; apply/ahom_inP. by split=> [u v | ]; rewrite !lfunE ?rmorphM ?rmorph1. have [|nu cGnu Dnu] := kHom_to_gal _ (normalFieldf 1) hom_nu. by rewrite !subvf. exists nu => //; apply: (fmorph_inj QnC). rewrite -Dnu ?memvf // lfunE DnuQ rmorphXn DnuC //. by rewrite prim_expr_order // fmorph_primitive_root. have{defQn} imItoQ: calG = ItoQ @: {:I}. apply/setP=> nu; apply/idP/imsetP=> [cGnu | [k _ ->] //]. have pr_nu_e: n.-primitive_root (nu eps) by rewrite fmorph_primitive_root. have [i Dnue] := prim_rootP pr_eps (prim_expr_order pr_nu_e). rewrite Dnue prim_root_exp_coprime // coprime_sym in pr_nu_e. apply: ex_intro2 (Sub i _) _ _ => //; apply/eqP. rewrite /calG /= -defQn in ItoQ inItoQ defItoQ nu cGnu Dnue *. by rewrite gal_adjoin_eq // defItoQ -Dnue. have injItoQ: {in {:I} &, injective ItoQ}. move=> k1 k2 _ _ /(congr1 (fun nu : gal_of _ => nu eps))/eqP. by apply: contraTeq; rewrite !defItoQ (eq_prim_root_expr pr_eps) !modn_small. pose pi1 := \prod_(s in S) chi s; pose pi2 := \prod_(s in S) `|chi s| ^+ 2. have Qpi1: pi1 \in Crat. have [a Da] := QnGg _ Nchi; suffices ->: pi1 = QnC (galNorm 1 {:Qn} a). have /vlineP[q ->] := mem_galNorm galQn (memvf a). by rewrite rmorphZ_num rmorph1 mulr1 Crat_rat. rewrite /galNorm rmorph_prod -/calG imItoQ big_imset //=. rewrite /pi1 -(eq_bigl _ _ imItoS) -big_uniq // big_image /=. apply: eq_bigr => k _; have [nuC DnuC] := gQnC (ItoQ k); rewrite DnuC Da. have [r ->] := char_sum_irr Nchi; rewrite !sum_cfunE rmorph_sum. apply: eq_bigr => i _; have /QnGg[b Db] := irr_char i. have Lchi_i: 'chi_i \is a linear_char by rewrite irr_cyclic_lin. have /(prim_rootP pr_eps)[m Dem]: b ^+ n = 1. apply/eqP; rewrite -(fmorph_eq1 QnC) rmorphXn /= Db -lin_charX //. by rewrite -expg_mod_order orderE defG modnn lin_char1. rewrite -Db /= -DnuC Dem rmorphXn /= defItoQ exprAC -{m}Dem rmorphXn /= {b}Db. by rewrite lin_charX. clear I ItoS imItoS injItoS ItoQ inItoQ defItoQ imItoQ injItoQ. clear Qn galQn QnC gQnC eps pr_eps QnGg calG. have{Qpi1} Zpi1: pi1 \in Num.int. by rewrite Cint_rat_Aint // rpred_prod // => s _; apply: Aint_char. have{pi1 Zpi1} pi2_ge1: 1 <= pi2. have ->: pi2 = `|pi1| ^+ 2. by rewrite (big_morph Num.norm (@normrM _) (@normr1 _)) -prodrXl. by rewrite intr_normK // sqr_intr_ge1 //; apply/prodf_neq0. have Sgt0: (#|S| > 0)%N by rewrite (cardD1 g) [g \in S]Sg. rewrite -mulr_natr -ler_pdivlMr ?ltr0n //. have n2chi_ge0 s: s \in S -> 0 <= `|chi s| ^+ 2 by rewrite exprn_ge0. rewrite -(expr_ge1 Sgt0); last by rewrite divr_ge0 ?ler0n ?sumr_ge0. by rewrite (le_trans pi2_ge1) // leif_AGM. Qed. (* This is Burnside's vanishing theorem (Isaacs, Theorem (3.15)). *) Theorem nonlinear_irr_vanish gT (G : {group gT}) i : 'chi[G]_i 1%g > 1 -> exists2 x, x \in G & 'chi_i x = 0. Proof. move=> chi1gt1; apply/exists_eq_inP; apply: contraFT (lt_geF chi1gt1). move=> /exists_inPn-nz_chi. rewrite -(norm_natr (Cnat_irr1 i)) -(@expr_le1 _ 2)//. rewrite -(lerD2r (#|G|%:R * '['chi_i])) {1}cfnorm_irr mulr1. rewrite (cfnormE (cfun_onG _)) mulVKf ?neq0CG // (big_setD1 1%g) //=. rewrite addrCA lerD2l (cardsD1 1%g) group1 mulrS lerD2l. rewrite -sumr_const !(partition_big_imset (fun s => <[s]>)) /=. apply: ler_sum => _ /imsetP[g /setD1P[ntg Gg] ->]. have sgG: <[g]> \subset G by rewrite cycle_subG. pose S := [pred s | generator <[g]> s]; pose chi := 'Res[<[g]>] 'chi_i. have defS: [pred s in G^# | <[s]> == <[g]>] =i S. move=> s; rewrite inE /= eq_sym andb_idl // !inE -cycle_eq1 -cycle_subG. by move/eqP <-; rewrite cycle_eq1 ntg. have resS: {in S, 'chi_i =1 chi}. by move=> s /cycle_generator=> g_s; rewrite cfResE ?cycle_subG. rewrite !(eq_bigl _ _ defS) sumr_const. rewrite (eq_bigr (fun s => `|chi s| ^+ 2)) => [|s /resS-> //]. apply: sum_norm2_char_generators => [|s Ss]. by rewrite cfRes_char ?irr_char. by rewrite -resS // nz_chi ?(subsetP sgG) ?cycle_generator. Qed. End MoreIntegralChar.
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.Group.Commute.Defs import Mathlib.Algebra.Group.InjSurj import Mathlib.Algebra.Opposites import Mathlib.Tactic.Spread /-! # Group structures on the multiplicative and additive opposites -/ assert_not_exists MonoidWithZero DenselyOrdered Units variable {α : Type*} namespace MulOpposite /-! ### Additive structures on `αᵐᵒᵖ` -/ instance instAddSemigroup [AddSemigroup α] : AddSemigroup αᵐᵒᵖ := unop_injective.addSemigroup _ fun _ _ => rfl instance instAddLeftCancelSemigroup [AddLeftCancelSemigroup α] : AddLeftCancelSemigroup αᵐᵒᵖ := unop_injective.addLeftCancelSemigroup _ fun _ _ => rfl instance instAddRightCancelSemigroup [AddRightCancelSemigroup α] : AddRightCancelSemigroup αᵐᵒᵖ := unop_injective.addRightCancelSemigroup _ fun _ _ => rfl instance instAddCommMagma [AddCommMagma α] : AddCommMagma αᵐᵒᵖ := unop_injective.addCommMagma _ fun _ _ => rfl instance instAddCommSemigroup [AddCommSemigroup α] : AddCommSemigroup αᵐᵒᵖ := unop_injective.addCommSemigroup _ fun _ _ => rfl instance instAddZeroClass [AddZeroClass α] : AddZeroClass αᵐᵒᵖ := unop_injective.addZeroClass _ (by exact rfl) fun _ _ => rfl instance instAddMonoid [AddMonoid α] : AddMonoid αᵐᵒᵖ := unop_injective.addMonoid _ (by exact rfl) (fun _ _ => rfl) fun _ _ => rfl instance instAddCommMonoid [AddCommMonoid α] : AddCommMonoid αᵐᵒᵖ := unop_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl instance instSubNegMonoid [SubNegMonoid α] : SubNegMonoid αᵐᵒᵖ := unop_injective.subNegMonoid _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance instAddGroup [AddGroup α] : AddGroup αᵐᵒᵖ := unop_injective.addGroup _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance instAddCommGroup [AddCommGroup α] : AddCommGroup αᵐᵒᵖ := unop_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-! ### Multiplicative structures on `αᵐᵒᵖ` We also generate additive structures on `αᵃᵒᵖ` using `to_additive` -/ @[to_additive] instance instIsRightCancelMul [Mul α] [IsLeftCancelMul α] : IsRightCancelMul αᵐᵒᵖ where mul_right_cancel _ _ _ h := unop_injective <| mul_left_cancel <| op_injective h @[to_additive] instance instIsLeftCancelMul [Mul α] [IsRightCancelMul α] : IsLeftCancelMul αᵐᵒᵖ where mul_left_cancel _ _ _ h := unop_injective <| mul_right_cancel <| op_injective h @[to_additive] instance instSemigroup [Semigroup α] : Semigroup αᵐᵒᵖ where mul_assoc x y z := unop_injective <| Eq.symm <| mul_assoc (unop z) (unop y) (unop x) @[to_additive] instance instLeftCancelSemigroup [RightCancelSemigroup α] : LeftCancelSemigroup αᵐᵒᵖ where mul_left_cancel _ _ _ := mul_left_cancel @[to_additive] instance instRightCancelSemigroup [LeftCancelSemigroup α] : RightCancelSemigroup αᵐᵒᵖ where mul_right_cancel _ _ _ := mul_right_cancel @[to_additive] instance instCommSemigroup [CommSemigroup α] : CommSemigroup αᵐᵒᵖ where mul_comm x y := unop_injective <| mul_comm (unop y) (unop x) @[to_additive] instance instMulOneClass [MulOneClass α] : MulOneClass αᵐᵒᵖ where toMul := instMul toOne := instOne one_mul _ := unop_injective <| mul_one _ mul_one _ := unop_injective <| one_mul _ @[to_additive] instance instMonoid [Monoid α] : Monoid αᵐᵒᵖ where toSemigroup := instSemigroup __ := instMulOneClass npow n a := op <| a.unop ^ n npow_zero _ := unop_injective <| pow_zero _ npow_succ _ _ := unop_injective <| pow_succ' _ _ @[to_additive] instance instLeftCancelMonoid [RightCancelMonoid α] : LeftCancelMonoid αᵐᵒᵖ where toMonoid := instMonoid __ := instLeftCancelSemigroup @[to_additive] instance instRightCancelMonoid [LeftCancelMonoid α] : RightCancelMonoid αᵐᵒᵖ where toMonoid := instMonoid __ := instRightCancelSemigroup @[to_additive] instance instCancelMonoid [CancelMonoid α] : CancelMonoid αᵐᵒᵖ where toLeftCancelMonoid := instLeftCancelMonoid __ := instRightCancelMonoid @[to_additive] instance instCommMonoid [CommMonoid α] : CommMonoid αᵐᵒᵖ where toMonoid := instMonoid __ := instCommSemigroup @[to_additive] instance instCancelCommMonoid [CancelCommMonoid α] : CancelCommMonoid αᵐᵒᵖ where toCommMonoid := instCommMonoid __ := instLeftCancelMonoid @[to_additive AddOpposite.instSubNegMonoid] instance instDivInvMonoid [DivInvMonoid α] : DivInvMonoid αᵐᵒᵖ where toMonoid := instMonoid toInv := instInv zpow n a := op <| a.unop ^ n zpow_zero' _ := unop_injective <| zpow_zero _ zpow_succ' _ _ := unop_injective <| by rw [unop_op, zpow_natCast, pow_succ', unop_mul, unop_op, zpow_natCast] zpow_neg' _ _ := unop_injective <| DivInvMonoid.zpow_neg' _ _ @[to_additive] instance instDivisionMonoid [DivisionMonoid α] : DivisionMonoid αᵐᵒᵖ where toDivInvMonoid := instDivInvMonoid __ := instInvolutiveInv mul_inv_rev _ _ := unop_injective <| mul_inv_rev _ _ inv_eq_of_mul _ _ h := unop_injective <| inv_eq_of_mul_eq_one_left <| congr_arg unop h @[to_additive AddOpposite.instSubtractionCommMonoid] instance instDivisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid αᵐᵒᵖ where toDivisionMonoid := instDivisionMonoid __ := instCommSemigroup @[to_additive] instance instGroup [Group α] : Group αᵐᵒᵖ where toDivInvMonoid := instDivInvMonoid inv_mul_cancel _ := unop_injective <| mul_inv_cancel _ @[to_additive] instance instCommGroup [CommGroup α] : CommGroup αᵐᵒᵖ where toGroup := instGroup __ := instCommSemigroup section Monoid variable [Monoid α] @[simp] lemma op_pow (x : α) (n : ℕ) : op (x ^ n) = op x ^ n := rfl @[simp] lemma unop_pow (x : αᵐᵒᵖ) (n : ℕ) : unop (x ^ n) = unop x ^ n := rfl end Monoid section DivInvMonoid variable [DivInvMonoid α] @[simp] lemma op_zpow (x : α) (z : ℤ) : op (x ^ z) = op x ^ z := rfl @[simp] lemma unop_zpow (x : αᵐᵒᵖ) (z : ℤ) : unop (x ^ z) = unop x ^ z := rfl end DivInvMonoid @[to_additive (attr := simp)] theorem unop_div [DivInvMonoid α] (x y : αᵐᵒᵖ) : unop (x / y) = (unop y)⁻¹ * unop x := rfl @[to_additive (attr := simp)] theorem op_div [DivInvMonoid α] (x y : α) : op (x / y) = (op y)⁻¹ * op x := by simp [div_eq_mul_inv] @[to_additive (attr := simp)] theorem semiconjBy_op [Mul α] {a x y : α} : SemiconjBy (op a) (op y) (op x) ↔ SemiconjBy a x y := by simp only [SemiconjBy, ← op_mul, op_inj, eq_comm] @[to_additive (attr := simp, nolint simpComm)] theorem semiconjBy_unop [Mul α] {a x y : αᵐᵒᵖ} : SemiconjBy (unop a) (unop y) (unop x) ↔ SemiconjBy a x y := by conv_rhs => rw [← op_unop a, ← op_unop x, ← op_unop y, semiconjBy_op] attribute [nolint simpComm] AddOpposite.addSemiconjBy_unop @[to_additive] theorem _root_.SemiconjBy.op [Mul α] {a x y : α} (h : SemiconjBy a x y) : SemiconjBy (op a) (op y) (op x) := semiconjBy_op.2 h @[to_additive] theorem _root_.SemiconjBy.unop [Mul α] {a x y : αᵐᵒᵖ} (h : SemiconjBy a x y) : SemiconjBy (unop a) (unop y) (unop x) := semiconjBy_unop.2 h @[to_additive] theorem _root_.Commute.op [Mul α] {x y : α} (h : Commute x y) : Commute (op x) (op y) := SemiconjBy.op h @[to_additive] nonrec theorem _root_.Commute.unop [Mul α] {x y : αᵐᵒᵖ} (h : Commute x y) : Commute (unop x) (unop y) := h.unop @[to_additive (attr := simp)] theorem commute_op [Mul α] {x y : α} : Commute (op x) (op y) ↔ Commute x y := semiconjBy_op @[to_additive (attr := simp, nolint simpComm)] theorem commute_unop [Mul α] {x y : αᵐᵒᵖ} : Commute (unop x) (unop y) ↔ Commute x y := semiconjBy_unop attribute [nolint simpComm] AddOpposite.addCommute_unop end MulOpposite /-! ### Multiplicative structures on `αᵃᵒᵖ` -/ namespace AddOpposite instance instSemigroup [Semigroup α] : Semigroup αᵃᵒᵖ := unop_injective.semigroup _ fun _ _ ↦ rfl instance instLeftCancelSemigroup [LeftCancelSemigroup α] : LeftCancelSemigroup αᵃᵒᵖ := unop_injective.leftCancelSemigroup _ fun _ _ => rfl instance instRightCancelSemigroup [RightCancelSemigroup α] : RightCancelSemigroup αᵃᵒᵖ := unop_injective.rightCancelSemigroup _ fun _ _ => rfl instance instCommSemigroup [CommSemigroup α] : CommSemigroup αᵃᵒᵖ := unop_injective.commSemigroup _ fun _ _ => rfl instance instMulOneClass [MulOneClass α] : MulOneClass αᵃᵒᵖ := unop_injective.mulOneClass _ (by exact rfl) fun _ _ => rfl instance pow {β} [Pow α β] : Pow αᵃᵒᵖ β where pow a b := op (unop a ^ b) @[simp] theorem op_pow {β} [Pow α β] (a : α) (b : β) : op (a ^ b) = op a ^ b := rfl @[simp] theorem unop_pow {β} [Pow α β] (a : αᵃᵒᵖ) (b : β) : unop (a ^ b) = unop a ^ b := rfl instance instMonoid [Monoid α] : Monoid αᵃᵒᵖ := unop_injective.monoid _ (by exact rfl) (fun _ _ => rfl) fun _ _ => rfl instance instCommMonoid [CommMonoid α] : CommMonoid αᵃᵒᵖ := unop_injective.commMonoid _ (by exact rfl) (fun _ _ => rfl) fun _ _ => rfl instance instDivInvMonoid [DivInvMonoid α] : DivInvMonoid αᵃᵒᵖ := unop_injective.divInvMonoid _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance instGroup [Group α] : Group αᵃᵒᵖ := unop_injective.group _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance instCommGroup [CommGroup α] : CommGroup αᵃᵒᵖ := unop_injective.commGroup _ (by exact rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl end AddOpposite
Associated.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, Jens Wagemaker, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.GroupWithZero.Associated /-! # Products of associated, prime, and irreducible elements. This file contains some theorems relating definitions in `Algebra.Associated` and products of multisets, finsets, and finsupps. -/ assert_not_exists Field variable {ι M M₀ : Type*} -- the same local notation used in `Algebra.Associated` local infixl:50 " ~ᵤ " => Associated namespace Prime variable [CommMonoidWithZero M₀] {p : M₀} theorem exists_mem_multiset_dvd (hp : Prime p) {s : Multiset M₀} : p ∣ s.prod → ∃ a ∈ s, p ∣ a := Multiset.induction_on s (fun h => (hp.not_dvd_one h).elim) fun a s ih h => have : p ∣ a * s.prod := by simpa using h match hp.dvd_or_dvd this with | Or.inl h => ⟨a, Multiset.mem_cons_self a s, h⟩ | Or.inr h => let ⟨a, has, h⟩ := ih h ⟨a, Multiset.mem_cons_of_mem has, h⟩ theorem exists_mem_multiset_map_dvd (hp : Prime p) {s : Multiset ι} {f : ι → M₀} : p ∣ (s.map f).prod → ∃ a ∈ s, p ∣ f a := fun h => by simpa only [exists_prop, Multiset.mem_map, exists_exists_and_eq_and] using hp.exists_mem_multiset_dvd h theorem exists_mem_finset_dvd (hp : Prime p) {s : Finset ι} {f : ι → M₀} : p ∣ s.prod f → ∃ i ∈ s, p ∣ f i := hp.exists_mem_multiset_map_dvd end Prime theorem Prod.associated_iff {M N : Type*} [Monoid M] [Monoid N] {x z : M × N} : x ~ᵤ z ↔ x.1 ~ᵤ z.1 ∧ x.2 ~ᵤ z.2 := ⟨fun ⟨u, hu⟩ => ⟨⟨(MulEquiv.prodUnits.toFun u).1, (Prod.eq_iff_fst_eq_snd_eq.1 hu).1⟩, ⟨(MulEquiv.prodUnits.toFun u).2, (Prod.eq_iff_fst_eq_snd_eq.1 hu).2⟩⟩, fun ⟨⟨u₁, h₁⟩, ⟨u₂, h₂⟩⟩ => ⟨MulEquiv.prodUnits.invFun (u₁, u₂), Prod.eq_iff_fst_eq_snd_eq.2 ⟨h₁, h₂⟩⟩⟩ theorem Associated.prod {M : Type*} [CommMonoid M] {ι : Type*} (s : Finset ι) (f : ι → M) (g : ι → M) (h : ∀ i, i ∈ s → (f i) ~ᵤ (g i)) : (∏ i ∈ s, f i) ~ᵤ (∏ i ∈ s, g i) := by induction s using Finset.induction with | empty => simp only [Finset.prod_empty] rfl | insert j s hjs IH => classical convert_to (∏ i ∈ insert j s, f i) ~ᵤ (∏ i ∈ insert j s, g i) rw [Finset.prod_insert hjs, Finset.prod_insert hjs] grind [Associated.mul_mul] theorem exists_associated_mem_of_dvd_prod [CancelCommMonoidWithZero M₀] {p : M₀} (hp : Prime p) {s : Multiset M₀} : (∀ r ∈ s, Prime r) → p ∣ s.prod → ∃ q ∈ s, p ~ᵤ q := Multiset.induction_on s (by simp [mt isUnit_iff_dvd_one.2 hp.not_unit]) fun a s ih hs hps => by rw [Multiset.prod_cons] at hps rcases hp.dvd_or_dvd hps with h | h · have hap := hs a (Multiset.mem_cons.2 (Or.inl rfl)) exact ⟨a, Multiset.mem_cons_self a _, hp.associated_of_dvd hap h⟩ · rcases ih (fun r hr => hs _ (Multiset.mem_cons.2 (Or.inr hr))) h with ⟨q, hq₁, hq₂⟩ exact ⟨q, Multiset.mem_cons.2 (Or.inr hq₁), hq₂⟩ open Submonoid in /-- Let x, y ∈ M₀. If x * y can be written as a product of units and prime elements, then x can be written as a product of units and prime elements. -/ theorem divisor_closure_eq_closure [CancelCommMonoidWithZero M₀] (x y : M₀) (hxy : x * y ∈ closure { r : M₀ | IsUnit r ∨ Prime r}) : x ∈ closure { r : M₀ | IsUnit r ∨ Prime r} := by obtain ⟨m, hm, hprod⟩ := exists_multiset_of_mem_closure hxy induction m using Multiset.induction generalizing x y with | empty => apply subset_closure simp only [Set.mem_setOf] simp only [Multiset.prod_zero] at hprod left; exact isUnit_of_mul_eq_one _ _ hprod.symm | cons c s hind => simp only [Multiset.mem_cons, forall_eq_or_imp, Set.mem_setOf] at hm simp only [Multiset.prod_cons] at hprod simp only [Set.mem_setOf_eq] at hind obtain ⟨ha₁ | ha₂, hs⟩ := hm · rcases ha₁.exists_right_inv with ⟨k, hk⟩ refine hind x (y*k) ?_ hs ?_ · simp only [← mul_assoc, ← hprod, ← Multiset.prod_cons, mul_comm] refine multiset_prod_mem _ _ (Multiset.forall_mem_cons.2 ⟨subset_closure ?_, Multiset.forall_mem_cons.2 ⟨subset_closure ?_, fun t ht => subset_closure (hs t ht)⟩⟩) · left; exact isUnit_of_mul_eq_one_right _ _ hk · left; exact ha₁ · rw [← mul_one s.prod, ← hk, ← mul_assoc, ← mul_assoc, mul_eq_mul_right_iff, mul_comm] left; exact hprod · rcases ha₂.dvd_mul.1 (Dvd.intro _ hprod) with ⟨c, hc⟩ | ⟨c, hc⟩ · rw [hc]; rw [hc, mul_assoc] at hprod refine Submonoid.mul_mem _ (subset_closure ?_) (hind _ _ ?_ hs (mul_left_cancel₀ ha₂.ne_zero hprod)) · right; exact ha₂ rw [← mul_left_cancel₀ ha₂.ne_zero hprod] exact multiset_prod_mem _ _ (fun t ht => subset_closure (hs t ht)) rw [hc, mul_comm x _, mul_assoc, mul_comm c _] at hprod refine hind x c ?_ hs (mul_left_cancel₀ ha₂.ne_zero hprod) rw [← mul_left_cancel₀ ha₂.ne_zero hprod] exact multiset_prod_mem _ _ (fun t ht => subset_closure (hs t ht)) theorem Multiset.prod_primes_dvd [CancelCommMonoidWithZero M₀] [∀ a : M₀, DecidablePred (Associated a)] {s : Multiset M₀} (n : M₀) (h : ∀ a ∈ s, Prime a) (div : ∀ a ∈ s, a ∣ n) (uniq : ∀ a, s.countP (Associated a) ≤ 1) : s.prod ∣ n := by induction s using Multiset.induction_on generalizing n with | empty => simp only [Multiset.prod_zero, one_dvd] | cons a s induct => rw [Multiset.prod_cons] obtain ⟨k, rfl⟩ : a ∣ n := div a (Multiset.mem_cons_self a s) gcongr refine induct _ (fun a ha => h a (Multiset.mem_cons_of_mem ha)) (fun b b_in_s => ?_) fun a => (Multiset.countP_le_of_le _ (Multiset.le_cons_self _ _)).trans (uniq a) have b_div_n := div b (Multiset.mem_cons_of_mem b_in_s) have a_prime := h a (Multiset.mem_cons_self a s) have b_prime := h b (Multiset.mem_cons_of_mem b_in_s) refine (b_prime.dvd_or_dvd b_div_n).resolve_left fun b_div_a => ?_ have assoc := b_prime.associated_of_dvd a_prime b_div_a have := uniq a rw [Multiset.countP_cons_of_pos _ (Associated.refl _), Nat.succ_le_succ_iff, ← not_lt, Multiset.countP_pos] at this exact this ⟨b, b_in_s, assoc.symm⟩ theorem Finset.prod_primes_dvd [CancelCommMonoidWithZero M₀] [Subsingleton M₀ˣ] {s : Finset M₀} (n : M₀) (h : ∀ a ∈ s, Prime a) (div : ∀ a ∈ s, a ∣ n) : ∏ p ∈ s, p ∣ n := by classical exact Multiset.prod_primes_dvd n (by simpa only [Multiset.map_id', Finset.mem_def] using h) (by simpa only [Multiset.map_id', Finset.mem_def] using div) (by simp only [Multiset.map_id', associated_eq_eq, Multiset.countP_eq_card_filter, ← s.val.count_eq_card_filter_eq, ← Multiset.nodup_iff_count_le_one, s.nodup]) namespace Associates section CommMonoid variable [CommMonoid M] theorem prod_mk {p : Multiset M} : (p.map Associates.mk).prod = Associates.mk p.prod := Multiset.induction_on p (by simp) fun a s ih => by simp [ih, Associates.mk_mul_mk] theorem finset_prod_mk {p : Finset ι} {f : ι → M} : (∏ i ∈ p, Associates.mk (f i)) = Associates.mk (∏ i ∈ p, f i) := by rw [Finset.prod_eq_multiset_prod, ← Function.comp_def, ← Multiset.map_map, prod_mk, ← Finset.prod_eq_multiset_prod] theorem rel_associated_iff_map_eq_map {p q : Multiset M} : Multiset.Rel Associated p q ↔ p.map Associates.mk = q.map Associates.mk := by rw [← Multiset.rel_eq, Multiset.rel_map] simp only [mk_eq_mk_iff_associated] theorem prod_eq_one_iff {p : Multiset (Associates M)} : p.prod = 1 ↔ ∀ a ∈ p, (a : Associates M) = 1 := Multiset.induction_on p (by simp) (by simp +contextual [mul_eq_one, or_imp, forall_and]) theorem prod_le_prod {p q : Multiset (Associates M)} (h : p ≤ q) : p.prod ≤ q.prod := by haveI := Classical.decEq (Associates M) haveI := Classical.decEq M suffices p.prod ≤ (p + (q - p)).prod by rwa [add_tsub_cancel_of_le h] at this suffices p.prod * 1 ≤ p.prod * (q - p).prod by simpa exact mul_mono (le_refl p.prod) one_le end CommMonoid section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero M₀] theorem exists_mem_multiset_le_of_prime {s : Multiset (Associates M₀)} {p : Associates M₀} (hp : Prime p) : p ≤ s.prod → ∃ a ∈ s, p ≤ a := Multiset.induction_on s (fun ⟨_, eq⟩ => (hp.ne_one (mul_eq_one.1 eq.symm).1).elim) fun a s ih h => have : p ≤ a * s.prod := by simpa using h match Prime.le_or_le hp this with | Or.inl h => ⟨a, Multiset.mem_cons_self a s, h⟩ | Or.inr h => let ⟨a, has, h⟩ := ih h ⟨a, Multiset.mem_cons_of_mem has, h⟩ end CancelCommMonoidWithZero end Associates namespace Multiset theorem prod_ne_zero_of_prime [CancelCommMonoidWithZero M₀] [Nontrivial M₀] (s : Multiset M₀) (h : ∀ x ∈ s, Prime x) : s.prod ≠ 0 := Multiset.prod_ne_zero fun h0 => Prime.ne_zero (h 0 h0) rfl end Multiset open Finset Finsupp section CommMonoidWithZero variable {M : Type*} [CommMonoidWithZero M] theorem Prime.dvd_finset_prod_iff {S : Finset M₀} {p : M} (pp : Prime p) (g : M₀ → M) : p ∣ S.prod g ↔ ∃ a ∈ S, p ∣ g a := ⟨pp.exists_mem_finset_dvd, fun ⟨_, ha1, ha2⟩ => dvd_trans ha2 (dvd_prod_of_mem g ha1)⟩ theorem Prime.not_dvd_finset_prod {S : Finset M₀} {p : M} (pp : Prime p) {g : M₀ → M} (hS : ∀ a ∈ S, ¬p ∣ g a) : ¬p ∣ S.prod g := by exact mt (Prime.dvd_finset_prod_iff pp _).1 <| not_exists.2 fun a => not_and.2 (hS a) theorem Prime.dvd_finsuppProd_iff {f : M₀ →₀ M} {g : M₀ → M → ℕ} {p : ℕ} (pp : Prime p) : p ∣ f.prod g ↔ ∃ a ∈ f.support, p ∣ g a (f a) := Prime.dvd_finset_prod_iff pp _ @[deprecated (since := "2025-04-06")] alias Prime.dvd_finsupp_prod_iff := Prime.dvd_finsuppProd_iff theorem Prime.not_dvd_finsuppProd {f : M₀ →₀ M} {g : M₀ → M → ℕ} {p : ℕ} (pp : Prime p) (hS : ∀ a ∈ f.support, ¬p ∣ g a (f a)) : ¬p ∣ f.prod g := Prime.not_dvd_finset_prod pp hS @[deprecated (since := "2025-04-06")] alias Prime.not_dvd_finsupp_prod := Prime.not_dvd_finsuppProd end CommMonoidWithZero
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.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Order.BigOperators.Group.List import Mathlib.Order.WellFoundedSet /-! # Pointwise instances on `Submonoid`s and `AddSubmonoid`s This file provides: * `Submonoid.inv` * `AddSubmonoid.neg` and the actions * `Submonoid.pointwiseMulAction` * `AddSubmonoid.pointwiseAddAction` which matches the action of `Set.mulActionSet`. ## Implementation notes Most of the lemmas in this file are direct copies of lemmas from `Mathlib/Algebra/Group/Pointwise/Set/Basic.lean` and `Mathlib/Algebra/Group/Action/Pointwise/Set/Basic.lean`. While the statements of these lemmas are defeq, we repeat them here due to them not being syntactically equal. Before adding new lemmas here, consider if they would also apply to the action on `Set`s. -/ assert_not_exists GroupWithZero open Set Pointwise variable {α G M R A S : Type*} variable [Monoid M] [AddMonoid A] @[to_additive (attr := simp, norm_cast)] lemma coe_mul_coe [SetLike S M] [SubmonoidClass S M] (H : S) : H * H = (H : Set M) := by aesop (add simp mem_mul) @[to_additive (attr := simp)] lemma coe_set_pow [SetLike S M] [SubmonoidClass S M] : ∀ {n} (_ : n ≠ 0) (H : S), (H ^ n : Set M) = H | 1, _, H => by simp | n + 2, _, H => by rw [pow_succ, coe_set_pow n.succ_ne_zero, coe_mul_coe] /-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in `GroupTheory.Submonoid.Basic`, but currently we cannot because that file is imported by this. -/ namespace Submonoid variable {s t u : Set M} @[to_additive] theorem mul_subset {S : Submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S := mul_subset_iff.2 fun _x hx _y hy ↦ mul_mem (hs hx) (ht hy) @[to_additive] theorem mul_subset_closure (hs : s ⊆ u) (ht : t ⊆ u) : s * t ⊆ Submonoid.closure u := mul_subset (Subset.trans hs Submonoid.subset_closure) (Subset.trans ht Submonoid.subset_closure) @[to_additive] theorem coe_mul_self_eq (s : Submonoid M) : (s : Set M) * s = s := by simp @[to_additive] theorem closure_mul_le (S T : Set M) : closure (S * T) ≤ closure S ⊔ closure T := sInf_le fun _x ⟨_s, hs, _t, ht, hx⟩ => hx ▸ (closure S ⊔ closure T).mul_mem (SetLike.le_def.mp le_sup_left <| subset_closure hs) (SetLike.le_def.mp le_sup_right <| subset_closure ht) @[to_additive] lemma closure_pow_le : ∀ {n}, n ≠ 0 → closure (s ^ n) ≤ closure s | 1, _ => by simp | n + 2, _ => calc closure (s ^ (n + 2)) _ = closure (s ^ (n + 1) * s) := by rw [pow_succ] _ ≤ closure (s ^ (n + 1)) ⊔ closure s := closure_mul_le .. _ ≤ closure s ⊔ closure s := by gcongr ?_ ⊔ _; exact closure_pow_le n.succ_ne_zero _ = closure s := sup_idem _ @[to_additive] lemma closure_pow {n : ℕ} (hs : 1 ∈ s) (hn : n ≠ 0) : closure (s ^ n) = closure s := (closure_pow_le hn).antisymm <| by gcongr; exact subset_pow hs hn @[to_additive] theorem sup_eq_closure_mul (H K : Submonoid M) : H ⊔ K = closure ((H : Set M) * (K : Set M)) := le_antisymm (sup_le (fun h hh => subset_closure ⟨h, hh, 1, K.one_mem, mul_one h⟩) fun k hk => subset_closure ⟨1, H.one_mem, k, hk, one_mul k⟩) ((closure_mul_le _ _).trans <| by rw [closure_eq, closure_eq]) @[to_additive] theorem coe_sup {N : Type*} [CommMonoid N] (H K : Submonoid N) : ↑(H ⊔ K) = (H * K : Set N) := by ext x simp [mem_sup, Set.mem_mul] @[to_additive] theorem pow_smul_mem_closure_smul {N : Type*} [CommMonoid N] [MulAction M N] [IsScalarTower M N N] (r : M) (s : Set N) {x : N} (hx : x ∈ closure s) : ∃ n : ℕ, r ^ n • x ∈ closure (r • s) := by induction hx using closure_induction with | mem x hx => exact ⟨1, subset_closure ⟨_, hx, by rw [pow_one]⟩⟩ | one => exact ⟨0, by simp⟩ | mul x y _ _ hx hy => obtain ⟨⟨nx, hx⟩, ⟨ny, hy⟩⟩ := And.intro hx hy use ny + nx rw [pow_add, mul_smul, ← smul_mul_assoc, mul_comm, ← smul_mul_assoc] exact mul_mem hy hx variable [Group G] /-- The submonoid with every element inverted. -/ @[to_additive /-- The additive submonoid with every element negated. -/] protected def inv : Inv (Submonoid G) where inv S := { carrier := (S : Set G)⁻¹ mul_mem' := fun ha hb => by rw [mem_inv, mul_inv_rev]; exact mul_mem hb ha one_mem' := mem_inv.2 <| by rw [inv_one]; exact S.one_mem' } scoped[Pointwise] attribute [instance] Submonoid.inv AddSubmonoid.neg @[to_additive (attr := simp)] theorem coe_inv (S : Submonoid G) : ↑S⁻¹ = (S : Set G)⁻¹ := rfl @[to_additive (attr := simp)] theorem mem_inv {g : G} {S : Submonoid G} : g ∈ S⁻¹ ↔ g⁻¹ ∈ S := Iff.rfl /-- Inversion is involutive on submonoids. -/ @[to_additive /-- Inversion is involutive on additive submonoids. -/] def involutiveInv : InvolutiveInv (Submonoid G) := SetLike.coe_injective.involutiveInv _ fun _ => rfl scoped[Pointwise] attribute [instance] Submonoid.involutiveInv AddSubmonoid.involutiveNeg @[to_additive (attr := simp)] theorem inv_le_inv (S T : Submonoid G) : S⁻¹ ≤ T⁻¹ ↔ S ≤ T := SetLike.coe_subset_coe.symm.trans Set.inv_subset_inv @[to_additive] theorem inv_le (S T : Submonoid G) : S⁻¹ ≤ T ↔ S ≤ T⁻¹ := SetLike.coe_subset_coe.symm.trans Set.inv_subset /-- Pointwise inversion of submonoids as an order isomorphism. -/ @[to_additive (attr := simps!) /-- Pointwise negation of additive submonoids as an order isomorphism -/] def invOrderIso : Submonoid G ≃o Submonoid G where toEquiv := Equiv.inv _ map_rel_iff' := inv_le_inv _ _ @[to_additive] theorem closure_inv (s : Set G) : closure s⁻¹ = (closure s)⁻¹ := by apply le_antisymm · rw [closure_le, coe_inv, ← Set.inv_subset, inv_inv] exact subset_closure · rw [inv_le, closure_le, coe_inv, ← Set.inv_subset] exact subset_closure @[to_additive] lemma mem_closure_inv (s : Set G) (x : G) : x ∈ closure s⁻¹ ↔ x⁻¹ ∈ closure s := by rw [closure_inv, mem_inv] @[to_additive (attr := simp)] theorem inv_inf (S T : Submonoid G) : (S ⊓ T)⁻¹ = S⁻¹ ⊓ T⁻¹ := SetLike.coe_injective Set.inter_inv @[to_additive (attr := simp)] theorem inv_sup (S T : Submonoid G) : (S ⊔ T)⁻¹ = S⁻¹ ⊔ T⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_sup S T @[to_additive (attr := simp)] theorem inv_bot : (⊥ : Submonoid G)⁻¹ = ⊥ := SetLike.coe_injective <| (Set.inv_singleton 1).trans <| congr_arg _ inv_one @[to_additive (attr := simp)] theorem inv_top : (⊤ : Submonoid G)⁻¹ = ⊤ := SetLike.coe_injective <| Set.inv_univ @[to_additive (attr := simp)] theorem inv_iInf {ι : Sort*} (S : ι → Submonoid G) : (⨅ i, S i)⁻¹ = ⨅ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iInf _ @[to_additive (attr := simp)] theorem inv_iSup {ι : Sort*} (S : ι → Submonoid G) : (⨆ i, S i)⁻¹ = ⨆ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iSup _ end Submonoid namespace Submonoid section Monoid variable [Monoid α] [MulDistribMulAction α M] -- todo: add `to_additive`? /-- The action on a submonoid corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction α (Submonoid M) where smul a S := S.map (MulDistribMulAction.toMonoidEnd _ M a) one_smul S := by change S.map _ = S simpa only [map_one] using S.map_id mul_smul _ _ S := (congr_arg (fun f : Monoid.End M => S.map f) (MonoidHom.map_mul _ _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] Submonoid.pointwiseMulAction @[simp] theorem coe_pointwise_smul (a : α) (S : Submonoid M) : ↑(a • S) = a • (S : Set M) := rfl theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submonoid M) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M)) instance : CovariantClass α (Submonoid M) HSMul.hSMul LE.le := ⟨fun _ _ => image_mono⟩ theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submonoid M) : m ∈ a • S ↔ ∃ s : M, s ∈ S ∧ a • s = m := (Set.mem_smul_set : m ∈ a • (S : Set M) ↔ _) @[simp] theorem smul_bot (a : α) : a • (⊥ : Submonoid M) = ⊥ := map_bot _ theorem smul_sup (a : α) (S T : Submonoid M) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ theorem smul_closure (a : α) (s : Set M) : a • closure s = closure (a • s) := MonoidHom.map_mclosure _ _ lemma pointwise_isCentralScalar [MulDistribMulAction αᵐᵒᵖ M] [IsCentralScalar α M] : IsCentralScalar α (Submonoid M) := ⟨fun _ S => (congr_arg fun f : Monoid.End M => S.map f) <| MonoidHom.ext <| op_smul_eq_smul _⟩ scoped[Pointwise] attribute [instance] Submonoid.pointwise_isCentralScalar end Monoid section Group variable [Group α] [MulDistribMulAction α M] @[simp] theorem smul_mem_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : Submonoid M} {x : M} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : Submonoid M} : a • S ≤ a • T ↔ S ≤ T := smul_set_subset_smul_set_iff theorem pointwise_smul_subset_iff {a : α} {S T : Submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := smul_set_subset_iff_subset_inv_smul_set theorem subset_pointwise_smul_iff {a : α} {S T : Submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_smul_set_iff end Group end Submonoid namespace Set.IsPWO variable [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] {s : Set α} @[to_additive] theorem submonoid_closure (hpos : ∀ x : α, x ∈ s → 1 ≤ x) (h : s.IsPWO) : IsPWO (Submonoid.closure s : Set α) := by rw [Submonoid.closure_eq_image_prod] refine (h.partiallyWellOrderedOn_sublistForall₂ (· ≤ ·)).image_of_monotone_on ?_ exact fun l1 _ l2 hl2 h12 => h12.prod_le_prod' fun x hx => hpos x <| hl2 x hx end Set.IsPWO
Degree.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.Algebra.Group.Subsemigroup.Operations import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Order.Filter.Extr /-! # Lemmas about the `sup` and `inf` of the support of `AddMonoidAlgebra` ## TODO The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a "generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`. Next, the general lemmas get specialized for some yet-to-be-defined `degree`s. -/ variable {R R' A T B ι : Type*} namespace AddMonoidAlgebra /-! # sup-degree and inf-degree of an `AddMonoidAlgebra` Let `R` be a semiring and let `A` be a `SemilatticeSup`. For an element `f : R[A]`, this file defines * `AddMonoidAlgebra.supDegree`: the sup-degree taking values in `WithBot A`, * `AddMonoidAlgebra.infDegree`: the inf-degree taking values in `WithTop A`. If the grading type `A` is a linearly ordered additive monoid, then these two notions of degree coincide with the standard one: * the sup-degree is the maximum of the exponents of the monomials that appear with non-zero coefficient in `f`, or `⊥`, if `f = 0`; * the inf-degree is the minimum of the exponents of the monomials that appear with non-zero coefficient in `f`, or `⊤`, if `f = 0`. The main results are * `AddMonoidAlgebra.supDegree_mul_le`: the sup-degree of a product is at most the sum of the sup-degrees, * `AddMonoidAlgebra.le_infDegree_mul`: the inf-degree of a product is at least the sum of the inf-degrees, * `AddMonoidAlgebra.supDegree_add_le`: the sup-degree of a sum is at most the sup of the sup-degrees, * `AddMonoidAlgebra.le_infDegree_add`: the inf-degree of a sum is at least the inf of the inf-degrees. ## Implementation notes The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a "generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`. Next, the general lemmas get specialized twice: * once for `supDegree` (essentially a simple application) and * once for `infDegree` (a simple application, via `OrderDual`). These final lemmas are the ones that likely get used the most. The generic lemmas about `Finset.support.sup` may not be used directly much outside of this file. To see this in action, you can look at the triple `(sup_support_mul_le, maxDegree_mul_le, le_minDegree_mul)`. -/ section GeneralResultsAssumingSemilatticeSup variable [SemilatticeSup B] [OrderBot B] [SemilatticeInf T] [OrderTop T] section Semiring variable [Semiring R] section ExplicitDegrees /-! In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in a type with *b*ot or *t*op respectively. -/ variable (degb : A → B) (degt : A → T) (f g : R[A]) theorem sup_support_add_le : (f + g).support.sup degb ≤ f.support.sup degb ⊔ g.support.sup degb := by classical exact (Finset.sup_mono Finsupp.support_add).trans_eq Finset.sup_union theorem le_inf_support_add : f.support.inf degt ⊓ g.support.inf degt ≤ (f + g).support.inf degt := sup_support_add_le (fun a : A => OrderDual.toDual (degt a)) f g end ExplicitDegrees section AddOnly variable [Add A] [Add B] [Add T] [AddLeftMono B] [AddRightMono B] [AddLeftMono T] [AddRightMono T] theorem sup_support_mul_le {degb : A → B} (degbm : ∀ {a b}, degb (a + b) ≤ degb a + degb b) (f g : R[A]) : (f * g).support.sup degb ≤ f.support.sup degb + g.support.sup degb := by classical exact (Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds ↦ degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds) theorem le_inf_support_mul {degt : A → T} (degtm : ∀ {a b}, degt a + degt b ≤ degt (a + b)) (f g : R[A]) : f.support.inf degt + g.support.inf degt ≤ (f * g).support.inf degt := sup_support_mul_le (B := Tᵒᵈ) degtm f g end AddOnly section AddMonoids variable [AddMonoid A] [AddMonoid B] [AddLeftMono B] [AddRightMono B] [AddMonoid T] [AddLeftMono T] [AddRightMono T] {degb : A → B} {degt : A → T} theorem sup_support_list_prod_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) : ∀ l : List R[A], l.prod.support.sup degb ≤ (l.map fun f : R[A] => f.support.sup degb).sum | [] => by rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil] exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)] | f::fs => by rw [List.prod_cons, List.map_cons, List.sum_cons] exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans (add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _) theorem le_inf_support_list_prod (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (l : List R[A]) : (l.map fun f : R[A] => f.support.inf degt).sum ≤ l.prod.support.inf degt := by refine OrderDual.ofDual_le_ofDual.mpr ?_ refine sup_support_list_prod_le ?_ ?_ l · refine (OrderDual.ofDual_le_ofDual.mp ?_) exact degt0 · refine (fun a b => OrderDual.ofDual_le_ofDual.mp ?_) exact degtm a b theorem sup_support_pow_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (n : ℕ) (f : R[A]) : (f ^ n).support.sup degb ≤ n • f.support.sup degb := by rw [← List.prod_replicate, ← List.sum_replicate] refine (sup_support_list_prod_le degb0 degbm _).trans_eq ?_ rw [List.map_replicate] theorem le_inf_support_pow (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (n : ℕ) (f : R[A]) : n • f.support.inf degt ≤ (f ^ n).support.inf degt := by refine OrderDual.ofDual_le_ofDual.mpr <| sup_support_pow_le (OrderDual.ofDual_le_ofDual.mp ?_) (fun a b => OrderDual.ofDual_le_ofDual.mp ?_) n f · exact degt0 · exact degtm _ _ end AddMonoids end Semiring section CommutativeLemmas variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [AddLeftMono B] [AddRightMono B] [AddCommMonoid T] [AddLeftMono T] [AddRightMono T] {degb : A → B} {degt : A → T} theorem sup_support_multiset_prod_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (m : Multiset R[A]) : m.prod.support.sup degb ≤ (m.map fun f : R[A] => f.support.sup degb).sum := by induction m using Quot.inductionOn rw [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.sum_coe, Multiset.prod_coe] exact sup_support_list_prod_le degb0 degbm _ theorem le_inf_support_multiset_prod (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (m : Multiset R[A]) : (m.map fun f : R[A] => f.support.inf degt).sum ≤ m.prod.support.inf degt := by refine OrderDual.ofDual_le_ofDual.mpr <| sup_support_multiset_prod_le (OrderDual.ofDual_le_ofDual.mp ?_) (fun a b => OrderDual.ofDual_le_ofDual.mp ?_) m · exact degt0 · exact degtm _ _ theorem sup_support_finset_prod_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (s : Finset ι) (f : ι → R[A]) : (∏ i ∈ s, f i).support.sup degb ≤ ∑ i ∈ s, (f i).support.sup degb := (sup_support_multiset_prod_le degb0 degbm _).trans_eq <| congr_arg _ <| Multiset.map_map _ _ _ theorem le_inf_support_finset_prod (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (s : Finset ι) (f : ι → R[A]) : (∑ i ∈ s, (f i).support.inf degt) ≤ (∏ i ∈ s, f i).support.inf degt := le_of_eq_of_le (by rw [Multiset.map_map]; rfl) (le_inf_support_multiset_prod degt0 degtm _) end CommutativeLemmas end GeneralResultsAssumingSemilatticeSup /-! ### Shorthands for special cases Note that these definitions are reducible, in order to make it easier to apply the more generic lemmas above. -/ section Degrees variable [Semiring R] [Ring R'] section SupDegree variable [SemilatticeSup B] [OrderBot B] (D : A → B) /-- Let `R` be a semiring, let `A` be an `AddZeroClass`, let `B` be an `OrderBot`, and let `D : A → B` be a "degree" function. For an element `f : R[A]`, the element `supDegree f : B` is the supremum of all the elements in the support of `f`, or `⊥` if `f` is zero. Often, the Type `B` is `WithBot A`, If, further, `A` has a linear order, then this notion coincides with the usual one, using the maximum of the exponents. If `A := σ →₀ ℕ` then `R[A] = MvPolynomial σ R`, and if we equip `σ` with a linear order then the induced linear order on `Lex A` equips `MvPolynomial` ring with a [monomial order](https://en.wikipedia.org/wiki/Monomial_order) (i.e. a linear order on `A`, the type of (monic) monomials in `R[A]`, that respects addition). We make use of this monomial order by taking `D := toLex`, and different monomial orders could be accessed via different type synonyms once they are added. -/ abbrev supDegree (f : R[A]) : B := f.support.sup D variable {D} theorem supDegree_add_le {f g : R[A]} : (f + g).supDegree D ≤ (f.supDegree D) ⊔ (g.supDegree D) := sup_support_add_le D f g @[simp] theorem supDegree_neg {f : R'[A]} : (-f).supDegree D = f.supDegree D := by rw [supDegree, supDegree, Finsupp.support_neg] theorem supDegree_sub_le {f g : R'[A]} : (f - g).supDegree D ≤ f.supDegree D ⊔ g.supDegree D := by rw [sub_eq_add_neg, ← supDegree_neg (f := g)]; apply supDegree_add_le theorem supDegree_sum_le {ι} {s : Finset ι} {f : ι → R[A]} : (∑ i ∈ s, f i).supDegree D ≤ s.sup (fun i => (f i).supDegree D) := by classical exact (Finset.sup_mono Finsupp.support_finset_sum).trans_eq (Finset.sup_biUnion _ _) theorem supDegree_single_ne_zero (a : A) {r : R} (hr : r ≠ 0) : (single a r).supDegree D = D a := by rw [supDegree, Finsupp.support_single_ne_zero a hr, Finset.sup_singleton] open Classical in theorem supDegree_single (a : A) (r : R) : (single a r).supDegree D = if r = 0 then ⊥ else D a := by split_ifs with hr <;> simp [supDegree_single_ne_zero, hr] theorem apply_eq_zero_of_not_le_supDegree {p : R[A]} {a : A} (hlt : ¬ D a ≤ p.supDegree D) : p a = 0 := by contrapose! hlt exact Finset.le_sup (Finsupp.mem_support_iff.2 hlt) theorem supDegree_withBot_some_comp {s : AddMonoidAlgebra R A} (hs : s.support.Nonempty) : supDegree (WithBot.some ∘ D) s = supDegree D s := by unfold AddMonoidAlgebra.supDegree rw [← Finset.coe_sup' hs, Finset.sup'_eq_sup] theorem supDegree_eq_of_isMaxOn {p : R[A]} {a : A} (hmem : a ∈ p.support) (hmax : IsMaxOn D p.support a) : p.supDegree D = D a := sup_eq_of_isMaxOn hmem hmax variable [AddZeroClass A] {p q : R[A]} @[simp] theorem supDegree_zero : (0 : R[A]).supDegree D = ⊥ := by simp [supDegree] theorem ne_zero_of_supDegree_ne_bot : p.supDegree D ≠ ⊥ → p ≠ 0 := mt (fun h => h ▸ supDegree_zero) theorem ne_zero_of_not_supDegree_le {b : B} (h : ¬ p.supDegree D ≤ b) : p ≠ 0 := ne_zero_of_supDegree_ne_bot (fun he => h <| he ▸ bot_le) theorem supDegree_eq_of_max {b : B} (hb : b ∈ Set.range D) (hmem : D.invFun b ∈ p.support) (hmax : ∀ a ∈ p.support, D a ≤ b) : p.supDegree D = b := sup_eq_of_max hb hmem hmax variable [Add B] theorem supDegree_mul_le (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) [AddLeftMono B] [AddRightMono B] : (p * q).supDegree D ≤ p.supDegree D + q.supDegree D := sup_support_mul_le (fun {_ _} => (hadd _ _).le) p q theorem supDegree_prod_le {R A B : Type*} [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [SemilatticeSup B] [OrderBot B] [AddLeftMono B] [AddRightMono B] {D : A → B} (hzero : D 0 = 0) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) {ι} {s : Finset ι} {f : ι → R[A]} : (∏ i ∈ s, f i).supDegree D ≤ ∑ i ∈ s, (f i).supDegree D := by classical refine s.induction ?_ ?_ · rw [Finset.prod_empty, Finset.sum_empty, one_def, supDegree_single] split_ifs; exacts [bot_le, hzero.le] · intro i s his ih rw [Finset.prod_insert his, Finset.sum_insert his] exact (supDegree_mul_le hadd).trans (by gcongr) theorem apply_add_of_supDegree_le (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) [AddLeftStrictMono B] [AddRightStrictMono B] (hD : D.Injective) {ap aq : A} (hp : p.supDegree D ≤ D ap) (hq : q.supDegree D ≤ D aq) : (p * q) (ap + aq) = p ap * q aq := by classical simp_rw [mul_apply, Finsupp.sum] rw [Finset.sum_eq_single ap, Finset.sum_eq_single aq, if_pos rfl] · refine fun a ha hne => if_neg (fun he => ?_) apply_fun D at he; simp_rw [hadd] at he exact (add_lt_add_left (((Finset.le_sup ha).trans hq).lt_of_ne <| hD.ne_iff.2 hne) _).ne he · intro h; rw [if_pos rfl, Finsupp.notMem_support_iff.1 h, mul_zero] · refine fun a ha hne => Finset.sum_eq_zero (fun a' ha' => if_neg <| fun he => ?_) apply_fun D at he simp_rw [hadd] at he have := addLeftMono_of_addLeftStrictMono B exact (add_lt_add_of_lt_of_le (((Finset.le_sup ha).trans hp).lt_of_ne <| hD.ne_iff.2 hne) <| (Finset.le_sup ha').trans hq).ne he · refine fun h => Finset.sum_eq_zero (fun a _ => ite_eq_right_iff.mpr <| fun _ => ?_) rw [Finsupp.notMem_support_iff.mp h, zero_mul] end SupDegree section LinearOrder variable [LinearOrder B] [OrderBot B] {p q : R[A]} (D : A → B) /-- If `D` is an injection into a linear order `B`, the leading coefficient of `f : R[A]` is the nonzero coefficient of highest degree according to `D`, or 0 if `f = 0`. In general, it is defined to be the coefficient at an inverse image of `supDegree f` (if such exists). -/ noncomputable def leadingCoeff [Nonempty A] (f : R[A]) : R := f (D.invFun <| f.supDegree D) /-- An element `f : R[A]` is monic if its leading coefficient is one. -/ @[reducible] def Monic [Nonempty A] (f : R[A]) : Prop := f.leadingCoeff D = 1 variable {D} @[simp] theorem leadingCoeff_single [Nonempty A] (hD : D.Injective) (a : A) (r : R) : (single a r).leadingCoeff D = r := by classical rw [leadingCoeff, supDegree_single] split_ifs with hr · simp [hr] · rw [Function.leftInverse_invFun hD, single_apply, if_pos rfl] @[simp] theorem leadingCoeff_zero [Nonempty A] : (0 : R[A]).leadingCoeff D = 0 := rfl lemma Monic.ne_zero [Nonempty A] [Nontrivial R] (hp : p.Monic D) : p ≠ 0 := fun h => by simp_rw [Monic, h, leadingCoeff_zero, zero_ne_one] at hp @[simp] theorem monic_one [AddZeroClass A] (hD : D.Injective) : (1 : R[A]).Monic D := by rw [Monic, one_def, leadingCoeff_single hD] variable (D) in lemma exists_supDegree_mem_support (hp : p ≠ 0) : ∃ a ∈ p.support, p.supDegree D = D a := Finset.exists_mem_eq_sup _ (Finsupp.support_nonempty_iff.mpr hp) D variable (D) in lemma supDegree_mem_range (hp : p ≠ 0) : p.supDegree D ∈ Set.range D := by obtain ⟨a, -, he⟩ := exists_supDegree_mem_support D hp; exact ⟨a, he.symm⟩ variable {ι : Type*} {s : Finset ι} {i : ι} (hi : i ∈ s) {f : ι → R[A]} lemma supDegree_sum_lt (hs : s.Nonempty) {b : B} (h : ∀ i ∈ s, (f i).supDegree D < b) : (∑ i ∈ s, f i).supDegree D < b := by refine supDegree_sum_le.trans_lt ((Finset.sup_lt_iff ?_).mpr h) obtain ⟨i, hi⟩ := hs; exact bot_le.trans_lt (h i hi) variable [AddZeroClass A] open Finsupp in lemma supDegree_add_eq_left (h : q.supDegree D < p.supDegree D) : (p + q).supDegree D = p.supDegree D := by apply (supDegree_add_le.trans <| sup_le le_rfl h.le).antisymm obtain ⟨a, ha, he⟩ := exists_supDegree_mem_support D (ne_zero_of_not_supDegree_le h.not_ge) rw [he] at h ⊢ apply Finset.le_sup rw [mem_support_iff, add_apply, apply_eq_zero_of_not_le_supDegree h.not_ge, add_zero] exact mem_support_iff.mp ha lemma supDegree_add_eq_right (h : p.supDegree D < q.supDegree D) : (p + q).supDegree D = q.supDegree D := by rw [add_comm, supDegree_add_eq_left h] lemma leadingCoeff_add_eq_left (h : q.supDegree D < p.supDegree D) : (p + q).leadingCoeff D = p.leadingCoeff D := by obtain ⟨a, he⟩ := supDegree_mem_range D (ne_zero_of_not_supDegree_le h.not_ge) rw [leadingCoeff, supDegree_add_eq_left h, Finsupp.add_apply, ← leadingCoeff, apply_eq_zero_of_not_le_supDegree (D := D), add_zero] rw [← he, Function.apply_invFun_apply (f := D), he]; exact h.not_ge lemma leadingCoeff_add_eq_right (h : p.supDegree D < q.supDegree D) : (p + q).leadingCoeff D = q.leadingCoeff D := by rw [add_comm, leadingCoeff_add_eq_left h] lemma supDegree_mem_support (hD : D.Injective) (hp : p ≠ 0) : D.invFun (p.supDegree D) ∈ p.support := by obtain ⟨a, ha, he⟩ := exists_supDegree_mem_support D hp rwa [he, Function.leftInverse_invFun hD] @[simp] lemma leadingCoeff_eq_zero (hD : D.Injective) : p.leadingCoeff D = 0 ↔ p = 0 := by refine ⟨(fun h => ?_).mtr, fun h => h ▸ leadingCoeff_zero⟩ rw [leadingCoeff, ← Ne, ← Finsupp.mem_support_iff] exact supDegree_mem_support hD h lemma leadingCoeff_ne_zero (hD : D.Injective) : p.leadingCoeff D ≠ 0 ↔ p ≠ 0 := (leadingCoeff_eq_zero hD).ne lemma supDegree_sub_lt_of_leadingCoeff_eq (hD : D.Injective) {R} [Ring R] {p q : R[A]} (hd : p.supDegree D = q.supDegree D) (hc : p.leadingCoeff D = q.leadingCoeff D) : (p - q).supDegree D < p.supDegree D ∨ p = q := by rw [or_iff_not_imp_right] refine fun he => (supDegree_sub_le.trans ?_).lt_of_ne ?_ · rw [hd, sup_idem] · rw [← sub_eq_zero, ← leadingCoeff_eq_zero hD, leadingCoeff] at he refine fun h => he ?_ rwa [h, Finsupp.sub_apply, ← leadingCoeff, hd, ← leadingCoeff, sub_eq_zero] lemma supDegree_leadingCoeff_sum_eq (hi : i ∈ s) (hmax : ∀ j ∈ s, j ≠ i → (f j).supDegree D < (f i).supDegree D) : (∑ j ∈ s, f j).supDegree D = (f i).supDegree D ∧ (∑ j ∈ s, f j).leadingCoeff D = (f i).leadingCoeff D := by classical rw [← s.add_sum_erase _ hi] by_cases hs : s.erase i = ∅ · rw [hs, Finset.sum_empty, add_zero]; exact ⟨rfl, rfl⟩ suffices _ from ⟨supDegree_add_eq_left this, leadingCoeff_add_eq_left this⟩ refine supDegree_sum_lt ?_ (fun j hj => ?_) · rw [Finset.nonempty_iff_ne_empty]; exact hs · rw [Finset.mem_erase] at hj; exact hmax j hj.2 hj.1 open Finset in lemma sum_ne_zero_of_injOn_supDegree' (hs : ∃ i ∈ s, f i ≠ 0) (hd : (s : Set ι).InjOn (supDegree D ∘ f)) : ∑ i ∈ s, f i ≠ 0 := by obtain ⟨j, hj, hne⟩ := hs obtain ⟨i, hi, he⟩ := exists_mem_eq_sup _ ⟨j, hj⟩ (supDegree D ∘ f) by_cases h : ∀ k ∈ s, k = i · refine (sum_eq_single_of_mem j hj (fun k hk hne => ?_)).trans_ne hne rw [h k hk, h j hj] at hne; exact hne.irrefl.elim push_neg at h; obtain ⟨j, hj, hne⟩ := h apply ne_zero_of_supDegree_ne_bot (D := D) have (k) (hk : k ∈ s) (hne : k ≠ i) : supDegree D (f k) < supDegree D (f i) := ((le_sup hk).trans_eq he).lt_of_ne (hd.ne hk hi hne) rw [(supDegree_leadingCoeff_sum_eq hi this).1] exact (this j hj hne).ne_bot lemma sum_ne_zero_of_injOn_supDegree (hs : s ≠ ∅) (hf : ∀ i ∈ s, f i ≠ 0) (hd : (s : Set ι).InjOn (supDegree D ∘ f)) : ∑ i ∈ s, f i ≠ 0 := let ⟨i, hi⟩ := Finset.nonempty_iff_ne_empty.2 hs sum_ne_zero_of_injOn_supDegree' ⟨i, hi, hf i hi⟩ hd variable [Add B] variable [AddLeftStrictMono B] [AddRightStrictMono B] lemma apply_supDegree_add_supDegree (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) : (p * q) (D.invFun (p.supDegree D + q.supDegree D)) = p.leadingCoeff D * q.leadingCoeff D := by obtain rfl | hp := eq_or_ne p 0 · simp_rw [leadingCoeff_zero, zero_mul, Finsupp.coe_zero, Pi.zero_apply] obtain rfl | hq := eq_or_ne q 0 · simp_rw [leadingCoeff_zero, mul_zero, Finsupp.coe_zero, Pi.zero_apply] obtain ⟨ap, -, hp⟩ := exists_supDegree_mem_support D hp obtain ⟨aq, -, hq⟩ := exists_supDegree_mem_support D hq simp_rw [leadingCoeff, hp, hq, ← hadd, Function.leftInverse_invFun hD _] exact apply_add_of_supDegree_le hadd hD hp.le hq.le lemma supDegree_mul (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hpq : leadingCoeff D p * leadingCoeff D q ≠ 0) (hp : p ≠ 0) (hq : q ≠ 0) : (p * q).supDegree D = p.supDegree D + q.supDegree D := by cases subsingleton_or_nontrivial R; · exact (hp (Subsingleton.elim _ _)).elim apply supDegree_eq_of_max · rw [← AddSubsemigroup.coe_set_mk (Set.range D), ← AddHom.srange_mk _ hadd, SetLike.mem_coe] exact add_mem (supDegree_mem_range D hp) (supDegree_mem_range D hq) · simp_rw [Finsupp.mem_support_iff, apply_supDegree_add_supDegree hD hadd] exact hpq · have := addLeftMono_of_addLeftStrictMono B have := addRightMono_of_addRightStrictMono B exact fun a ha => (Finset.le_sup ha).trans (supDegree_mul_le hadd) lemma Monic.supDegree_mul_of_ne_zero_left (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hq : q.Monic D) (hp : p ≠ 0) : (p * q).supDegree D = p.supDegree D + q.supDegree D := by cases subsingleton_or_nontrivial R; · exact (hp (Subsingleton.elim _ _)).elim apply supDegree_mul hD hadd ?_ hp hq.ne_zero simp_rw [hq, mul_one, Ne, leadingCoeff_eq_zero hD, hp, not_false_eq_true] lemma Monic.supDegree_mul_of_ne_zero_right (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hp : p.Monic D) (hq : q ≠ 0) : (p * q).supDegree D = p.supDegree D + q.supDegree D := by cases subsingleton_or_nontrivial R; · exact (hq (Subsingleton.elim _ _)).elim apply supDegree_mul hD hadd ?_ hp.ne_zero hq simp_rw [hp, one_mul, Ne, leadingCoeff_eq_zero hD, hq, not_false_eq_true] lemma Monic.supDegree_mul (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hbot : (⊥ : B) + ⊥ = ⊥) (hp : p.Monic D) (hq : q.Monic D) : (p * q).supDegree D = p.supDegree D + q.supDegree D := by cases subsingleton_or_nontrivial R · simp_rw [Subsingleton.eq_zero p, Subsingleton.eq_zero q, mul_zero, supDegree_zero, hbot] exact hq.supDegree_mul_of_ne_zero_left hD hadd hp.ne_zero lemma leadingCoeff_mul [NoZeroDivisors R] (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) : (p * q).leadingCoeff D = p.leadingCoeff D * q.leadingCoeff D := by obtain rfl | hp := eq_or_ne p 0 · simp_rw [leadingCoeff_zero, zero_mul, leadingCoeff_zero] obtain rfl | hq := eq_or_ne q 0 · simp_rw [leadingCoeff_zero, mul_zero, leadingCoeff_zero] rw [← apply_supDegree_add_supDegree hD hadd, ← supDegree_mul hD hadd ?_ hp hq, leadingCoeff] apply mul_ne_zero <;> rwa [Ne, leadingCoeff_eq_zero hD] lemma Monic.leadingCoeff_mul_eq_left (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hq : q.Monic D) : (p * q).leadingCoeff D = p.leadingCoeff D := by obtain rfl | hp := eq_or_ne p 0 · rw [zero_mul] rw [leadingCoeff, hq.supDegree_mul_of_ne_zero_left hD hadd hp, apply_supDegree_add_supDegree hD hadd, hq, mul_one] lemma Monic.leadingCoeff_mul_eq_right (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hp : p.Monic D) : (p * q).leadingCoeff D = q.leadingCoeff D := by obtain rfl | hq := eq_or_ne q 0 · rw [mul_zero] rw [leadingCoeff, hp.supDegree_mul_of_ne_zero_right hD hadd hq, apply_supDegree_add_supDegree hD hadd, hp, one_mul] lemma Monic.mul (hD : D.Injective) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hp : p.Monic D) (hq : q.Monic D) : (p * q).Monic D := by rw [Monic, hq.leadingCoeff_mul_eq_left hD hadd]; exact hp section AddMonoid variable {A B : Type*} [AddMonoid A] [AddMonoid B] [LinearOrder B] [OrderBot B] [AddLeftStrictMono B] [AddRightStrictMono B] {D : A → B} {p : R[A]} {n : ℕ} lemma Monic.pow (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hD : D.Injective) (hp : p.Monic D) : (p ^ n).Monic D := by induction n with | zero => rw [pow_zero]; exact monic_one hD | succ n ih => rw [pow_succ']; exact hp.mul hD hadd ih lemma Monic.supDegree_pow (hzero : D 0 = 0) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2) (hD : D.Injective) [Nontrivial R] (hp : p.Monic D) : (p ^ n).supDegree D = n • p.supDegree D := by induction n with | zero => rw [pow_zero, zero_nsmul, one_def, supDegree_single 0 1, if_neg one_ne_zero, hzero] | succ n ih => rw [pow_succ', (hp.pow hadd hD).supDegree_mul_of_ne_zero_left hD hadd hp.ne_zero, ih, succ_nsmul'] end AddMonoid end LinearOrder section InfDegree variable [SemilatticeInf T] [OrderTop T] (D : A → T) /-- Let `R` be a semiring, let `A` be an `AddZeroClass`, let `T` be an `OrderTop`, and let `D : A → T` be a "degree" function. For an element `f : R[A]`, the element `infDegree f : T` is the infimum of all the elements in the support of `f`, or `⊤` if `f` is zero. Often, the Type `T` is `WithTop A`, If, further, `A` has a linear order, then this notion coincides with the usual one, using the minimum of the exponents. -/ abbrev infDegree (f : R[A]) : T := f.support.inf D theorem le_infDegree_add (f g : R[A]) : (f.infDegree D) ⊓ (g.infDegree D) ≤ (f + g).infDegree D := le_inf_support_add D f g variable {D} in theorem infDegree_withTop_some_comp {s : AddMonoidAlgebra R A} (hs : s.support.Nonempty) : infDegree (WithTop.some ∘ D) s = infDegree D s := by unfold AddMonoidAlgebra.infDegree rw [← Finset.coe_inf' hs, Finset.inf'_eq_inf] theorem le_infDegree_mul [AddZeroClass A] [Add T] [AddLeftMono T] [AddRightMono T] (D : AddHom A T) (f g : R[A]) : f.infDegree D + g.infDegree D ≤ (f * g).infDegree D := le_inf_support_mul (fun {a b : A} => (map_add D a b).ge) _ _ end InfDegree end Degrees end AddMonoidAlgebra
Enrichment.lean
/- Copyright (c) 2024 Daniel Carranza. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Daniel Carranza, Joël Riou -/ import Mathlib.CategoryTheory.Enriched.Ordinary.Basic import Mathlib.CategoryTheory.Closed.Monoidal /-! # A closed monoidal category is enriched in itself From the data of a closed monoidal category `C`, we define a `C`-category structure for `C`. where the hom-object is given by the internal hom (coming from the closed structure). We use `scoped instance` to avoid potential issues where `C` may also have a `C`-category structure coming from another source (e.g. the type of simplicial sets `SSet.{v}` has an instance of `EnrichedCategory SSet.{v}` as a category of simplicial objects; see `Mathlib/AlgebraicTopology/SimplicialCategory/SimplicialObject.lean`). All structure field values are defined in `Mathlib/CategoryTheory/Closed/Monoidal.lean`. -/ universe u v namespace CategoryTheory open Category MonoidalCategory namespace MonoidalClosed variable (C : Type u) [Category.{v} C] [MonoidalCategory C] [MonoidalClosed C] /-- For `C` closed monoidal, build an instance of `C` as a `C`-category -/ scoped instance enrichedCategorySelf : EnrichedCategory C C where Hom x := (ihom x).obj id _ := id _ comp _ _ _ := comp _ _ _ assoc _ _ _ _ := assoc _ _ _ _ section variable {C} lemma enrichedCategorySelf_hom (X Y : C) : EnrichedCategory.Hom X Y = (ihom X).obj Y := rfl lemma enrichedCategorySelf_id (X : C) : eId C X = id X := rfl lemma enrichedCategorySelf_comp (X Y Z : C) : eComp C X Y Z = comp X Y Z := rfl end /-- A monoidal closed category is an enriched ordinary category over itself. -/ scoped instance enrichedOrdinaryCategorySelf : EnrichedOrdinaryCategory C C where homEquiv := curryHomEquiv' homEquiv_id X := curry'_id X homEquiv_comp := curry'_comp lemma enrichedOrdinaryCategorySelf_eHomWhiskerLeft (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) : eHomWhiskerLeft C X g = (ihom X).map g := by change (ρ_ _).inv ≫ _ ◁ curry' g ≫ comp X Y₁ Y₂ = _ rw [whiskerLeft_curry'_comp, Iso.inv_hom_id_assoc] lemma enrichedOrdinaryCategorySelf_eHomWhiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : eHomWhiskerRight C f Y = (pre f).app Y := by change (λ_ _).inv ≫ curry' f ▷ _ ≫ comp X₁ X₂ Y = _ rw [curry'_whiskerRight_comp, Iso.inv_hom_id_assoc] lemma enrichedOrdinaryCategorySelf_homEquiv {X Y : C} (f : X ⟶ Y) : eHomEquiv C f = curry' f := rfl lemma enrichedOrdinaryCategorySelf_homEquiv_symm {X Y : C} (g : 𝟙_ C ⟶ (ihom X).obj Y) : (eHomEquiv C).symm g = uncurry' g := rfl end MonoidalClosed end CategoryTheory
mxalgebra.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice. From mathcomp Require Import fintype finfun bigop finset fingroup perm order. From mathcomp Require Import div prime binomial ssralg finalg zmodp matrix. (*****************************************************************************) (* In this file we develop the rank and row space theory of matrices, based *) (* on an extended Gaussian elimination procedure similar to LUP *) (* decomposition. This provides us with a concrete but generic model of *) (* finite dimensional vector spaces and F-algebras, in which vectors, linear *) (* functions, families, bases, subspaces, ideals and subrings are all *) (* represented using matrices. This model can be used as a foundation for *) (* the usual theory of abstract linear algebra, but it can also be used to *) (* develop directly substantial theories, such as the theory of finite group *) (* linear representation. *) (* Here we define the following concepts and notations: *) (* Gaussian_elimination A == a permuted triangular decomposition (L, U, r) *) (* of A, with L a column permutation of a lower triangular *) (* invertible matrix, U a row permutation of an upper *) (* triangular invertible matrix, and r the rank of A, all *) (* satisfying the identity L *m pid_mx r *m U = A. *) (* \rank A == the rank of A. *) (* row_free A <=> the rows of A are linearly free (i.e., the rank and *) (* height of A are equal). *) (* row_full A <=> the row-space of A spans all row-vectors (i.e., the *) (* rank and width of A are equal). *) (* col_ebase A == the extended column basis of A (the first matrix L *) (* returned by Gaussian_elimination A). *) (* row_ebase A == the extended row base of A (the second matrix U *) (* returned by Gaussian_elimination A). *) (* col_base A == a basis for the columns of A: a row-full matrix *) (* consisting of the first \rank A columns of col_ebase A. *) (* row_base A == a basis for the rows of A: a row-free matrix consisting *) (* of the first \rank A rows of row_ebase A. *) (* pinvmx A == a partial inverse for A in its row space (or on its *) (* column space, equivalently). In particular, if u is a *) (* row vector in the row_space of A, then u *m pinvmx A is *) (* the row vector of the coefficients of a decomposition *) (* of u as a sub of rows of A. *) (* kermx A == the row kernel of A : a square matrix whose row space *) (* consists of all u such that u *m A = 0 (it consists of *) (* the inverse of col_ebase A, with the top \rank A rows *) (* zeroed out). Also, kermx A is a partial right inverse *) (* to col_ebase A, in the row space annihilated by A. *) (* cokermx A == the cokernel of A : a square matrix whose column space *) (* consists of all v such that A *m v = 0 (it consists of *) (* the inverse of row_ebase A, with the leftmost \rank A *) (* columns zeroed out). *) (* maxrankfun A == injective function f so that rowsub f A is a submatrix *) (* of A with the same rank as A. *) (* fullrankfun fA == injective function f so that rowsub f A is row full, *) (* where fA is a proof of row_full A *) (* eigenvalue g a <=> a is an eigenvalue of the square matrix g. *) (* eigenspace g a == a square matrix whose row space is the eigenspace of *) (* the eigenvalue a of g (or 0 if a is not an eigenvalue). *) (* We use a different scope %MS for matrix row-space set-like operations; to *) (* avoid confusion, this scope should not be opened globally. Note that the *) (* the arguments of \rank _ and the operations below have default scope %MS. *) (* (A <= B)%MS <=> the row-space of A is included in the row-space of B. *) (* We test for this by testing if cokermx B annihilates A. *) (* (A < B)%MS <=> the row-space of A is properly included in the *) (* row-space of B. *) (* (A <= B <= C)%MS == (A <= B)%MS && (B <= C)%MS, and similarly for *) (* (A < B <= C)%MS, (A < B <= C)%MS and (A < B < C)%MS. *) (* (A == B)%MS == (A <= B <= A)%MS (A and B have the same row-space). *) (* (A :=: B)%MS == A and B behave identically wrt. \rank and <=. This *) (* triple rewrite rule is the Prop version of (A == B)%MS. *) (* Note that :=: cannot be treated as a setoid-style *) (* Equivalence because its arguments can have different *) (* types: A and B need not have the same number of rows, *) (* and often don't (e.g., in row_base A :=: A). *) (* <<A>>%MS == a square matrix with the same row-space as A; <<A>>%MS *) (* is a canonical representation of the subspace generated *) (* by A, viewed as a list of row-vectors: if (A == B)%MS, *) (* then <<A>>%MS = <<B>>%MS. *) (* (A + B)%MS == a square matrix whose row-space is the sum of the *) (* row-spaces of A and B; thus (A + B == col_mx A B)%MS. *) (* (\sum_i <expr i>)%MS == the "big" version of (_ + _)%MS; as the latter *) (* has a canonical abelian monoid structure, most generic *) (* bigop lemmas apply (the other bigop indexing notations *) (* are also defined). *) (* (A :&: B)%MS == a square matrix whose row-space is the intersection of *) (* the row-spaces of A and B. *) (* (\bigcap_i <expr i>)%MS == the "big" version of (_ :&: _)%MS, which also *) (* has a canonical abelian monoid structure. *) (* A^C%MS == a square matrix whose row-space is a complement to the *) (* the row-space of A (it consists of row_ebase A with the *) (* top \rank A rows zeroed out). *) (* (A :\: B)%MS == a square matrix whose row-space is a complement of the *) (* the row-space of (A :&: B)%MS in the row-space of A. *) (* We have (A :\: B := A :&: (capmx_gen A B)^C)%MS, where *) (* capmx_gen A B is a rectangular matrix equivalent to *) (* (A :&: B)%MS, i.e., (capmx_gen A B == A :&: B)%MS. *) (* proj_mx A B == a square matrix that projects (A + B)%MS onto A *) (* parallel to B, when (A :&: B)%MS = 0 (A and B must also *) (* be square). *) (* mxdirect S == the sum expression S is a direct sum. This is a NON *) (* EXTENSIONAL notation: the exact boolean expression is *) (* inferred from the syntactic form of S (expanding *) (* definitions, however); both (\sum_(i | _) _)%MS and *) (* (_ + _)%MS sums are recognized. This construct uses a *) (* variant of the reflexive ("quote") canonical structure, *) (* mxsum_expr. The structure also recognizes sums of *) (* matrix ranks, so that lemmas concerning the rank of *) (* direct sums can be used bidirectionally. *) (* stablemx V f <=> the matrix f represents an endomorphism that preserves V *) (* := (V *m f <= V)%MS *) (* The next set of definitions let us represent F-algebras using matrices: *) (* 'A[F]_(m, n) == the type of matrices encoding (sub)algebras of square *) (* n x n matrices, via mxvec; as in the matrix type *) (* notation, m and F can be omitted (m defaults to n ^ 2). *) (* := 'M[F]_(m, n ^ 2). *) (* (A \in R)%MS <=> the square matrix A belongs to the linear set of *) (* matrices (most often, a sub-algebra) encoded by the *) (* row space of R. This is simply notation, so all the *) (* lemmas and rewrite rules for (_ <= _)%MS can apply. *) (* := (mxvec A <= R)%MS. *) (* (R * S)%MS == a square n^2 x n^2 matrix whose row-space encodes the *) (* linear set of n x n matrices generated by the pointwise *) (* product of the sets of matrices encoded by R and S. *) (* 'C(R)%MS == a square matrix encoding the centraliser of the set of *) (* square matrices encoded by R. *) (* 'C_S(R)%MS := (S :&: 'C(R))%MS (the centraliser of R in S). *) (* 'Z(R)%MS == the center of R (i.e., 'C_R(R)%MS). *) (* left_mx_ideal R S <=> S is a left ideal for R (R * S <= S)%MS. *) (* right_mx_ideal R S <=> S is a right ideal for R (S * R <= S)%MS. *) (* mx_ideal R S <=> S is a bilateral ideal for R. *) (* mxring_id R e <-> e is an identity element for R (Prop predicate). *) (* has_mxring_id R <=> R has a nonzero identity element (bool predicate). *) (* mxring R <=> R encodes a nontrivial subring. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope matrix_set_scope. Import GroupScope. Import GRing.Theory. Local Open Scope ring_scope. Reserved Notation "\rank A" (at level 10, A at level 8, format "\rank A"). Reserved Notation "A ^C" (format "A ^C"). Notation "''A_' ( m , n )" := 'M_(m, n ^ 2) (format "''A_' ( m , n )") : type_scope. Notation "''A_' ( n )" := 'A_(n ^ 2, n) (only parsing) : type_scope. Notation "''A_' n" := 'A_(n) (n at next level, format "''A_' n") : type_scope. Notation "''A' [ F ]_ ( m , n )" := 'M[F]_(m, n ^ 2) (only parsing) : type_scope. Notation "''A' [ F ]_ ( n )" := 'A[F]_(n ^ 2, n) (only parsing) : type_scope. Notation "''A' [ F ]_ n" := 'A[F]_(n) (n at level 2, only parsing) : type_scope. Delimit Scope matrix_set_scope with MS. Local Notation simp := (Monoid.Theory.simpm, oppr0). (*****************************************************************************) (******************** Rank and row-space theory ******************************) (*****************************************************************************) (* Decomposition with double pivoting; computes the rank, row and column *) (* images, kernels, and complements of a matrix. *) Fixpoint Gaussian_elimination_ {F : fieldType} {m n} : 'M[F]_(m, n) -> 'M_m * 'M_n * nat := match m, n with | _.+1, _.+1 => fun A : 'M_(1 + _, 1 + _) => if [pick ij | A ij.1 ij.2 != 0] is Some (i, j) then let a := A i j in let A1 := xrow i 0 (xcol j 0 A) in let u := ursubmx A1 in let v := a^-1 *: dlsubmx A1 in let: (L, U, r) := Gaussian_elimination_ (drsubmx A1 - v *m u) in (xrow i 0 (block_mx 1 0 v L), xcol j 0 (block_mx a%:M u 0 U), r.+1) else (1%:M, 1%:M, 0) | _, _ => fun _ => (1%:M, 1%:M, 0) end. HB.lock Definition Gaussian_elimination := @Gaussian_elimination_. Canonical Gaussian_elimination_unlockable := Unlockable Gaussian_elimination.unlock. HB.lock Definition mxrank (F : fieldType) m n (A : 'M_(m, n)) := if [|| m == 0 | n == 0]%N then 0 else (@Gaussian_elimination F m n A).2. Canonical mxrank_unlockable := Unlockable mxrank.unlock. Section RowSpaceTheoryDefs. Variable F : fieldType. Implicit Types m n p r : nat. Local Notation "''M_' ( m , n )" := 'M[F]_(m, n) : type_scope. Local Notation "''M_' n" := 'M[F]_(n, n) : type_scope. Variables (m n : nat) (A : 'M_(m, n)). Local Notation mxrank := (@mxrank F m n A). Let LUr := @Gaussian_elimination F m n A. Definition col_ebase := LUr.1.1. Definition row_ebase := LUr.1.2. Definition row_free := mxrank == m. Definition row_full := mxrank == n. Definition row_base : 'M_(mxrank, n) := pid_mx mxrank *m row_ebase. Definition col_base : 'M_(m, mxrank) := col_ebase *m pid_mx mxrank. Definition complmx : 'M_n := copid_mx mxrank *m row_ebase. Definition kermx : 'M_m := copid_mx mxrank *m invmx col_ebase. Definition cokermx : 'M_n := invmx row_ebase *m copid_mx mxrank. Definition pinvmx : 'M_(n, m) := invmx row_ebase *m pid_mx mxrank *m invmx col_ebase. End RowSpaceTheoryDefs. Implicit Types F : fieldType. HB.lock Definition submx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := A *m cokermx B == 0. Canonical submx_unlockable := Unlockable submx.unlock. Arguments mxrank {F} {m%_N n%_N} A%_MS. Arguments complmx {F} {m%_N n%_N} A%_MS. Arguments submx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "\rank A" := (mxrank A) : nat_scope. Local Notation "A ^C" := (complmx A) : matrix_set_scope. Local Notation "A <= B" := (submx A B) : matrix_set_scope. Local Notation "A <= B <= C" := ((A <= B) && (B <= C))%MS : matrix_set_scope. Local Notation "A == B" := (A <= B <= A)%MS : matrix_set_scope. Definition ltmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := (A <= B)%MS && ~~ (B <= A)%MS. Arguments ltmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS. Local Notation "A < B" := (ltmx A B) : matrix_set_scope. Definition eqmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := prod (\rank A = \rank B) (forall m3 (C : 'M_(m3, n)), ((A <= C) = (B <= C)) * ((C <= A) = (C <= B)))%MS. Arguments eqmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS. Local Notation "A :=: B" := (eqmx A%MS B%MS) : matrix_set_scope. Notation stablemx V f := (V%MS *m f%R <= V%MS)%MS. Section LtmxIdentities. Variable F : fieldType. Implicit Types m n p r : nat. Local Notation "''M_' ( m , n )" := 'M[F]_(m, n) : type_scope. Local Notation "''M_' n" := 'M[F]_(n, n) : type_scope. Variables (m1 m2 n : nat) (A : 'M_(m1, n)) (B : 'M_(m2, n)). Lemma ltmxE : (A < B)%MS = ((A <= B)%MS && ~~ (B <= A)%MS). Proof. by []. Qed. Lemma ltmxW : (A < B)%MS -> (A <= B)%MS. Proof. by case/andP. Qed. Lemma ltmxEneq : (A < B)%MS = (A <= B)%MS && ~~ (A == B)%MS. Proof. by apply: andb_id2l => ->. Qed. Lemma submxElt : (A <= B)%MS = (A == B)%MS || (A < B)%MS. Proof. by rewrite -andb_orr orbN andbT. Qed. End LtmxIdentities. (* The definition of the row-space operator is rigged to return the identity *) (* matrix for full matrices. To allow for further tweaks that will make the *) (* row-space intersection operator strictly commutative and monoidal, we *) (* slightly generalize some auxiliary definitions: we parametrize the *) (* "equivalent subspace and identity" choice predicate equivmx by a boolean *) (* determining whether the matrix should be the identity (so for genmx A its *) (* value is row_full A), and introduce a "quasi-identity" predicate qidmx *) (* that selects non-square full matrices along with the identity matrix 1%:M *) (* (this does not affect genmx, which chooses a square matrix). *) (* The choice witness for genmx A is either 1%:M for a row-full A, or else *) (* row_base A padded with null rows. *) Local Definition qidmx F m n (A : 'M[F]_(m, n)) := if m == n then A == pid_mx n else row_full A. Local Definition equivmx F m n (A : 'M[F]_(m, n)) idA (B : 'M_n) := (B == A)%MS && (qidmx B == idA). Local Definition equivmx_spec F m n (A : 'M[F]_(m, n)) idA (B : 'M_n) := prod (B :=: A)%MS (qidmx B = idA). Local Definition genmx_witness F m n (A : 'M[F]_(m, n)) : 'M_n := if row_full A then 1%:M else pid_mx (\rank A) *m row_ebase A. HB.lock Definition genmx F m n (A : 'M[F]_(m, n)) : 'M_n := choose (equivmx A (row_full A)) (genmx_witness A). Canonical genmx_unlockable := Unlockable genmx.unlock. Arguments genmx {F} {n m}%_N A%_MS : rename. Local Notation "<< A >>" := (genmx A%MS) : matrix_set_scope. (* The setwise sum is tweaked so that 0 is a strict identity element for *) (* square matrices, because this lets us use the bigop component. As a result *) (* setwise sum is not quite strictly extensional. *) Local Definition addsmx_nop F m n (A : 'M[F]_(m, n)) := conform_mx <<A>>%MS A. HB.lock Definition addsmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) : 'M_n := if A == 0 then addsmx_nop B else if B == 0 then addsmx_nop A else <<col_mx A B>>%MS. Canonical addsmx_unlockable := Unlockable addsmx.unlock. Arguments addsmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "A + B" := (addsmx A B) : matrix_set_scope. Local Notation "\sum_ ( i | P ) B" := (\big[addsmx/0]_(i | P) B%MS) : matrix_set_scope. Local Notation "\sum_ ( i <- r | P ) B" := (\big[addsmx/0]_(i <- r | P) B%MS) : matrix_set_scope. (* The set intersection is similarly biased so that the identity matrix is a *) (* strict identity. This is somewhat more delicate than for the sum, because *) (* the test for the identity is non-extensional. This forces us to actually *) (* bias the choice operator so that it does not accidentally map an *) (* intersection of non-identity matrices to 1%:M; this would spoil *) (* associativity: if B :&: C = 1%:M but B and C are not identity, then for a *) (* square matrix A we have A :&: (B :&: C) = A != (A :&: B) :&: C in general. *) (* To complicate matters there may not be a square non-singular matrix *) (* different than 1%:M, since we could be dealing with 'M['F_2]_1. We *) (* sidestep the issue by making all non-square row-full matrices identities, *) (* and choosing a normal representative that preserves the qidmx property. *) (* Thus A :&: B = 1%:M iff A and B are both identities, and this suffices for *) (* showing that associativity is strict. *) Local Definition capmx_witness F m n (A : 'M[F]_(m, n)) := if row_full A then conform_mx 1%:M A else <<A>>%MS. Local Definition capmx_norm F m n (A : 'M[F]_(m, n)) := choose (equivmx A (qidmx A)) (capmx_witness A). Local Definition capmx_nop F m n (A : 'M[F]_(m, n)) := conform_mx (capmx_norm A) A. Definition capmx_gen F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := lsubmx (kermx (col_mx A B)) *m A. HB.lock Definition capmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) : 'M_n := if qidmx A then capmx_nop B else if qidmx B then capmx_nop A else if row_full B then capmx_norm A else capmx_norm (capmx_gen A B). Canonical capmx_unlockable := Unlockable capmx.unlock. Arguments capmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "A :&: B" := (capmx A B) : matrix_set_scope. Local Notation "\bigcap_ ( i | P ) B" := (\big[capmx/1%:M]_(i | P) B) : matrix_set_scope. HB.lock Definition diffmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) : 'M_n := <<capmx_gen A (capmx_gen A B)^C>>%MS. Canonical diffmx_unlockable := Unlockable diffmx.unlock. Arguments diffmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "A :\: B" := (diffmx A B) : matrix_set_scope. Section RowSpaceTheory. Variable F : fieldType. Implicit Types m n p r : nat. Local Notation "''M_' ( m , n )" := 'M[F]_(m, n) : type_scope. Local Notation "''M_' n" := 'M[F]_(n, n) : type_scope. Definition proj_mx n (U V : 'M_n) : 'M_n := pinvmx (col_mx U V) *m col_mx U 0. Local Notation GaussE := Gaussian_elimination_. Fact mxrankE m n (A : 'M_(m, n)) : \rank A = (GaussE A).2. Proof. by rewrite mxrank.unlock unlock /=; case: m n A => [|m] [|n]. Qed. Lemma rank_leq_row m n (A : 'M_(m, n)) : \rank A <= m. Proof. rewrite mxrankE. elim: m n A => [|m IHm] [|n] //= A; case: pickP => [[i j] _|] //=. by move: (_ - _) => B; case: GaussE (IHm _ B) => [[L U] r] /=. Qed. Lemma row_leq_rank m n (A : 'M_(m, n)) : (m <= \rank A) = row_free A. Proof. by rewrite /row_free eqn_leq rank_leq_row. Qed. Lemma rank_leq_col m n (A : 'M_(m, n)) : \rank A <= n. Proof. rewrite mxrankE. elim: m n A => [|m IHm] [|n] //= A; case: pickP => [[i j] _|] //=. by move: (_ - _) => B; case: GaussE (IHm _ B) => [[L U] r] /=. Qed. Lemma col_leq_rank m n (A : 'M_(m, n)) : (n <= \rank A) = row_full A. Proof. by rewrite /row_full eqn_leq rank_leq_col. Qed. Lemma eq_row_full m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> row_full A = row_full B. Proof. by rewrite /row_full => ->. Qed. Let unitmx1F := @unitmx1 F. Lemma row_ebase_unit m n (A : 'M_(m, n)) : row_ebase A \in unitmx. Proof. rewrite /row_ebase unlock; elim: m n A => [|m IHm] [|n] //= A. case: pickP => [[i j] /= nzAij | //=]; move: (_ - _) => B. case: GaussE (IHm _ B) => [[L U] r] /= uU. rewrite unitmxE xcolE det_mulmx (@det_ublock _ 1) det_scalar1 !unitrM. by rewrite unitfE nzAij -!unitmxE uU unitmx_perm. Qed. Lemma col_ebase_unit m n (A : 'M_(m, n)) : col_ebase A \in unitmx. Proof. rewrite /col_ebase unlock; elim: m n A => [|m IHm] [|n] //= A. case: pickP => [[i j] _|] //=; move: (_ - _) => B. case: GaussE (IHm _ B) => [[L U] r] /= uL. rewrite unitmxE xrowE det_mulmx (@det_lblock _ 1) det1 mul1r unitrM. by rewrite -unitmxE unitmx_perm. Qed. Hint Resolve rank_leq_row rank_leq_col row_ebase_unit col_ebase_unit : core. Lemma mulmx_ebase m n (A : 'M_(m, n)) : col_ebase A *m pid_mx (\rank A) *m row_ebase A = A. Proof. rewrite mxrankE /col_ebase /row_ebase unlock. elim: m n A => [n A | m IHm]; first by rewrite [A]flatmx0 [_ *m _]flatmx0. case=> [A | n]; first by rewrite [_ *m _]thinmx0 [A]thinmx0. rewrite -(add1n m) -?(add1n n) => A /=. case: pickP => [[i0 j0] | A0] /=; last first. apply/matrixP=> i j; rewrite pid_mx_0 mulmx0 mul0mx mxE. by move/eqP: (A0 (i, j)). set a := A i0 j0 => nz_a; set A1 := xrow _ _ _. set u := ursubmx _; set v := _ *: _; set B : 'M_(m, n) := _ - _. move: (rank_leq_col B) (rank_leq_row B) {IHm}(IHm n B); rewrite mxrankE. case: (GaussE B) => [[L U] r] /= r_m r_n defB. have ->: pid_mx (1 + r) = block_mx 1 0 0 (pid_mx r) :> 'M[F]_(1 + m, 1 + n). rewrite -(subnKC r_m) -(subnKC r_n) pid_mx_block -col_mx0 -row_mx0. by rewrite block_mxA castmx_id col_mx0 row_mx0 -scalar_mx_block -pid_mx_block. rewrite xcolE xrowE mulmxA -xcolE -!mulmxA. rewrite !(addr0, add0r, mulmx0, mul0mx, mulmx_block, mul1mx) mulmxA defB. rewrite addrC subrK mul_mx_scalar scalerA divff // scale1r. have ->: a%:M = ulsubmx A1 by rewrite [_ A1]mx11_scalar !mxE !lshift0 !tpermR. rewrite submxK /A1 xrowE !xcolE -!mulmxA mulmxA -!perm_mxM !tperm2 !perm_mx1. by rewrite mulmx1 mul1mx. Qed. Lemma mulmx_base m n (A : 'M_(m, n)) : col_base A *m row_base A = A. Proof. by rewrite mulmxA -[col_base A *m _]mulmxA pid_mx_id ?mulmx_ebase. Qed. Lemma mulmx1_min_rank r m n (A : 'M_(m, n)) M N : M *m A *m N = 1%:M :> 'M_r -> r <= \rank A. Proof. by rewrite -{1}(mulmx_base A) mulmxA -mulmxA; move/mulmx1_min. Qed. Arguments mulmx1_min_rank [r m n A]. Lemma mulmx_max_rank r m n (M : 'M_(m, r)) (N : 'M_(r, n)) : \rank (M *m N) <= r. Proof. set MN := M *m N; set rMN := \rank _. pose L : 'M_(rMN, m) := pid_mx rMN *m invmx (col_ebase MN). pose U : 'M_(n, rMN) := invmx (row_ebase MN) *m pid_mx rMN. suffices: L *m M *m (N *m U) = 1%:M by apply: mulmx1_min. rewrite mulmxA -(mulmxA L) -[M *m N]mulmx_ebase -/MN. by rewrite !mulmxA mulmxKV // mulmxK // !pid_mx_id /rMN ?pid_mx_1. Qed. Arguments mulmx_max_rank [r m n]. Lemma mxrank_tr m n (A : 'M_(m, n)) : \rank A^T = \rank A. Proof. apply/eqP; rewrite eqn_leq -{3}[A]trmxK -{1}(mulmx_base A) -{1}(mulmx_base A^T). by rewrite !trmx_mul !mulmx_max_rank. Qed. Lemma mxrank_add m n (A B : 'M_(m, n)) : \rank (A + B)%R <= \rank A + \rank B. Proof. by rewrite -{1}(mulmx_base A) -{1}(mulmx_base B) -mul_row_col mulmx_max_rank. Qed. Lemma mxrankM_maxl m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : \rank (A *m B) <= \rank A. Proof. by rewrite -{1}(mulmx_base A) -mulmxA mulmx_max_rank. Qed. Lemma mxrankM_maxr m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : \rank (A *m B) <= \rank B. Proof. by rewrite -mxrank_tr -(mxrank_tr B) trmx_mul mxrankM_maxl. Qed. Lemma mxrank_scale m n a (A : 'M_(m, n)) : \rank (a *: A) <= \rank A. Proof. by rewrite -mul_scalar_mx mxrankM_maxr. Qed. Lemma mxrank_scale_nz m n a (A : 'M_(m, n)) : a != 0 -> \rank (a *: A) = \rank A. Proof. move=> nza; apply/eqP; rewrite eqn_leq -{3}[A]scale1r -(mulVf nza). by rewrite -scalerA !mxrank_scale. Qed. Lemma mxrank_opp m n (A : 'M_(m, n)) : \rank (- A) = \rank A. Proof. by rewrite -scaleN1r mxrank_scale_nz // oppr_eq0 oner_eq0. Qed. Lemma mxrank0 m n : \rank (0 : 'M_(m, n)) = 0%N. Proof. by apply/eqP; rewrite -leqn0 -(@mulmx0 _ m 0 n 0) mulmx_max_rank. Qed. Lemma mxrank_eq0 m n (A : 'M_(m, n)) : (\rank A == 0) = (A == 0). Proof. apply/eqP/eqP=> [rA0 | ->{A}]; last exact: mxrank0. move: (col_base A) (row_base A) (mulmx_base A); rewrite rA0 => Ac Ar <-. by rewrite [Ac]thinmx0 mul0mx. Qed. Lemma mulmx_coker m n (A : 'M_(m, n)) : A *m cokermx A = 0. Proof. by rewrite -{1}[A]mulmx_ebase -!mulmxA mulKVmx // mul_pid_mx_copid ?mulmx0. Qed. Lemma submxE m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS = (A *m cokermx B == 0). Proof. by rewrite unlock. Qed. Lemma mulmxKpV m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> A *m pinvmx B *m B = A. Proof. rewrite submxE !mulmxA mulmxBr mulmx1 subr_eq0 => /eqP defA. rewrite -{4}[B]mulmx_ebase -!mulmxA mulKmx //. by rewrite (mulmxA (pid_mx _)) pid_mx_id // !mulmxA -{}defA mulmxKV. Qed. Lemma mulmxVp m n (A : 'M[F]_(m, n)) : row_free A -> A *m pinvmx A = 1%:M. Proof. move=> fA; rewrite -[X in X *m _]mulmx_ebase !mulmxA mulmxK ?row_ebase_unit//. rewrite -[X in X *m _]mulmxA mul_pid_mx !minnn (minn_idPr _) ?rank_leq_col//. by rewrite (eqP fA) pid_mx_1 mulmx1 mulmxV ?col_ebase_unit. Qed. Lemma mulmxKp p m n (B : 'M[F]_(m, n)) : row_free B -> cancel ((@mulmx _ p _ _)^~ B) (mulmx^~ (pinvmx B)). Proof. by move=> ? A; rewrite -mulmxA mulmxVp ?mulmx1. Qed. Lemma submxP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (exists D, A = D *m B) (A <= B)%MS. Proof. apply: (iffP idP) => [/mulmxKpV | [D ->]]; first by exists (A *m pinvmx B). by rewrite submxE -mulmxA mulmx_coker mulmx0. Qed. Arguments submxP {m1 m2 n A B}. Lemma submx_refl m n (A : 'M_(m, n)) : (A <= A)%MS. Proof. by rewrite submxE mulmx_coker. Qed. Hint Resolve submx_refl : core. Lemma submxMl m n p (D : 'M_(m, n)) (A : 'M_(n, p)) : (D *m A <= A)%MS. Proof. by rewrite submxE -mulmxA mulmx_coker mulmx0. Qed. Lemma submxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : (A <= B)%MS -> (A *m C <= B *m C)%MS. Proof. by case/submxP=> D ->; rewrite -mulmxA submxMl. Qed. Lemma mulmx_sub m n1 n2 p (C : 'M_(m, n1)) A (B : 'M_(n2, p)) : (A <= B -> C *m A <= B)%MS. Proof. by case/submxP=> D ->; rewrite mulmxA submxMl. Qed. Lemma submx_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= B -> B <= C -> A <= C)%MS. Proof. by case/submxP=> D ->{A}; apply: mulmx_sub. Qed. Lemma ltmx_sub_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A < B)%MS -> (B <= C)%MS -> (A < C)%MS. Proof. case/andP=> sAB ltAB sBC; rewrite ltmxE (submx_trans sAB) //. by apply: contra ltAB; apply: submx_trans. Qed. Lemma sub_ltmx_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= B)%MS -> (B < C)%MS -> (A < C)%MS. Proof. move=> sAB /andP[sBC ltBC]; rewrite ltmxE (submx_trans sAB) //. by apply: contra ltBC => sCA; apply: submx_trans sAB. Qed. Lemma ltmx_trans m n : transitive (@ltmx F m m n). Proof. by move=> A B C; move/ltmxW; apply: sub_ltmx_trans. Qed. Lemma ltmx_irrefl m n : irreflexive (@ltmx F m m n). Proof. by move=> A; rewrite /ltmx submx_refl andbF. Qed. Lemma sub0mx m1 m2 n (A : 'M_(m2, n)) : ((0 : 'M_(m1, n)) <= A)%MS. Proof. by rewrite submxE mul0mx. Qed. Lemma submx0null m1 m2 n (A : 'M[F]_(m1, n)) : (A <= (0 : 'M_(m2, n)))%MS -> A = 0. Proof. by case/submxP=> D; rewrite mulmx0. Qed. Lemma submx0 m n (A : 'M_(m, n)) : (A <= (0 : 'M_n))%MS = (A == 0). Proof. by apply/idP/eqP=> [|->]; [apply: submx0null | apply: sub0mx]. Qed. Lemma lt0mx m n (A : 'M_(m, n)) : ((0 : 'M_n) < A)%MS = (A != 0). Proof. by rewrite /ltmx sub0mx submx0. Qed. Lemma ltmx0 m n (A : 'M[F]_(m, n)) : (A < (0 : 'M_n))%MS = false. Proof. by rewrite /ltmx sub0mx andbF. Qed. Lemma eqmx0P m n (A : 'M_(m, n)) : reflect (A = 0) (A == (0 : 'M_n))%MS. Proof. by rewrite submx0 sub0mx andbT; apply: eqP. Qed. Lemma eqmx_eq0 m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> (A == 0) = (B == 0). Proof. by move=> eqAB; rewrite -!submx0 eqAB. Qed. Lemma addmx_sub m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m1, n)) (C : 'M_(m2, n)) : (A <= C)%MS -> (B <= C)%MS -> ((A + B)%R <= C)%MS. Proof. by case/submxP=> A' ->; case/submxP=> B' ->; rewrite -mulmxDl submxMl. Qed. Lemma rowsub_sub m1 m2 n (f : 'I_m2 -> 'I_m1) (A : 'M_(m1, n)) : (rowsub f A <= A)%MS. Proof. by rewrite rowsubE mulmx_sub. Qed. Lemma summx_sub m1 m2 n (B : 'M_(m2, n)) I (r : seq I) (P : pred I) (A_ : I -> 'M_(m1, n)) : (forall i, P i -> A_ i <= B)%MS -> ((\sum_(i <- r | P i) A_ i)%R <= B)%MS. Proof. by move=> leAB; elim/big_ind: _ => // [|C D]; [apply/sub0mx | apply/addmx_sub]. Qed. Lemma scalemx_sub m1 m2 n a (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> (a *: A <= B)%MS. Proof. by case/submxP=> A' ->; rewrite scalemxAl submxMl. Qed. Lemma row_sub m n i (A : 'M_(m, n)) : (row i A <= A)%MS. Proof. exact: rowsub_sub. Qed. Lemma eq_row_sub m n v (A : 'M_(m, n)) i : row i A = v -> (v <= A)%MS. Proof. by move <-; rewrite row_sub. Qed. Arguments eq_row_sub [m n v A]. Lemma nz_row_sub m n (A : 'M_(m, n)) : (nz_row A <= A)%MS. Proof. by rewrite /nz_row; case: pickP => [i|] _; rewrite ?row_sub ?sub0mx. Qed. Lemma row_subP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (forall i, row i A <= B)%MS (A <= B)%MS. Proof. apply: (iffP idP) => [sAB i|sAB]. by apply: submx_trans sAB; apply: row_sub. rewrite submxE; apply/eqP/row_matrixP=> i; apply/eqP. by rewrite row_mul row0 -submxE. Qed. Arguments row_subP {m1 m2 n A B}. Lemma rV_subP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (forall v : 'rV_n, v <= A -> v <= B)%MS (A <= B)%MS. Proof. apply: (iffP idP) => [sAB v Av | sAB]; first exact: submx_trans sAB. by apply/row_subP=> i; rewrite sAB ?row_sub. Qed. Arguments rV_subP {m1 m2 n A B}. Lemma row_subPn m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (exists i, ~~ (row i A <= B)%MS) (~~ (A <= B)%MS). Proof. by rewrite (sameP row_subP forallP); apply: forallPn. Qed. Lemma sub_rVP n (u v : 'rV[F]_n) : reflect (exists a, u = a *: v) (u <= v)%MS. Proof. apply: (iffP submxP) => [[w ->] | [a ->]]. by exists (w 0 0); rewrite -mul_scalar_mx -mx11_scalar. by exists a%:M; rewrite mul_scalar_mx. Qed. Lemma rank_rV n (v : 'rV[F]_n) : \rank v = (v != 0). Proof. case: eqP => [-> | nz_v]; first by rewrite mxrank0. by apply/eqP; rewrite eqn_leq rank_leq_row lt0n mxrank_eq0; apply/eqP. Qed. Lemma rowV0Pn m n (A : 'M_(m, n)) : reflect (exists2 v : 'rV_n, v <= A & v != 0)%MS (A != 0). Proof. rewrite -submx0; apply: (iffP idP) => [| [v svA]]; last first. by rewrite -submx0; apply: contra (submx_trans _). by case/row_subPn=> i; rewrite submx0; exists (row i A); rewrite ?row_sub. Qed. Lemma rowV0P m n (A : 'M_(m, n)) : reflect (forall v : 'rV_n, v <= A -> v = 0)%MS (A == 0). Proof. rewrite -[A == 0]negbK; case: rowV0Pn => IH. by right; case: IH => v svA nzv IH; case/eqP: nzv; apply: IH. by left=> v svA; apply/eqP/idPn=> nzv; case: IH; exists v. Qed. Lemma submx_full m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : row_full B -> (A <= B)%MS. Proof. by rewrite submxE /cokermx => /eqnP->; rewrite /copid_mx pid_mx_1 subrr !mulmx0. Qed. Lemma row_fullP m n (A : 'M_(m, n)) : reflect (exists B, B *m A = 1%:M) (row_full A). Proof. apply: (iffP idP) => [Afull | [B kA]]. by exists (1%:M *m pinvmx A); apply: mulmxKpV (submx_full _ Afull). by rewrite [_ A]eqn_leq rank_leq_col (mulmx1_min_rank B 1%:M) ?mulmx1. Qed. Arguments row_fullP {m n A}. Lemma row_full_inj m n p A : row_full A -> injective (@mulmx F m n p A). Proof. case/row_fullP=> A' A'K; apply: can_inj (mulmx A') _ => B. by rewrite mulmxA A'K mul1mx. Qed. Lemma row_freeP m n (A : 'M_(m, n)) : reflect (exists B, A *m B = 1%:M) (row_free A). Proof. rewrite /row_free -mxrank_tr. apply: (iffP row_fullP) => [] [B kA]; by exists B^T; rewrite -trmx1 -kA trmx_mul ?trmxK. Qed. Lemma row_free_inj m n p A : row_free A -> injective ((@mulmx F m n p)^~ A). Proof. case/row_freeP=> A' AK; apply: can_inj (mulmx^~ A') _ => B. by rewrite -mulmxA AK mulmx1. Qed. (* A variant of row_free_inj that exposes mulmxr, an alias for mulmx^~ *) (* but which is canonically additive *) Definition row_free_injr m n p A : row_free A -> injective (mulmxr A) := @row_free_inj m n p A. Lemma row_free_unit n (A : 'M_n) : row_free A = (A \in unitmx). Proof. apply/row_fullP/idP=> [[A'] | uA]; first by case/mulmx1_unit. by exists (invmx A); rewrite mulVmx. Qed. Lemma row_full_unit n (A : 'M_n) : row_full A = (A \in unitmx). Proof. exact: row_free_unit. Qed. Lemma mxrank_unit n (A : 'M_n) : A \in unitmx -> \rank A = n. Proof. by rewrite -row_full_unit => /eqnP. Qed. Lemma mxrank1 n : \rank (1%:M : 'M_n) = n. Proof. exact: mxrank_unit. Qed. Lemma mxrank_delta m n i j : \rank (delta_mx i j : 'M_(m, n)) = 1. Proof. apply/eqP; rewrite eqn_leq lt0n mxrank_eq0. rewrite -{1}(mul_delta_mx (0 : 'I_1)) mulmx_max_rank. by apply/eqP; move/matrixP; move/(_ i j); move/eqP; rewrite !mxE !eqxx oner_eq0. Qed. Lemma mxrankS m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> \rank A <= \rank B. Proof. by case/submxP=> D ->; rewrite mxrankM_maxr. Qed. Lemma submx1 m n (A : 'M_(m, n)) : (A <= 1%:M)%MS. Proof. by rewrite submx_full // row_full_unit unitmx1. Qed. Lemma sub1mx m n (A : 'M_(m, n)) : (1%:M <= A)%MS = row_full A. Proof. apply/idP/idP; last exact: submx_full. by move/mxrankS; rewrite mxrank1 col_leq_rank. Qed. Lemma ltmx1 m n (A : 'M_(m, n)) : (A < 1%:M)%MS = ~~ row_full A. Proof. by rewrite /ltmx sub1mx submx1. Qed. Lemma lt1mx m n (A : 'M_(m, n)) : (1%:M < A)%MS = false. Proof. by rewrite /ltmx submx1 andbF. Qed. Lemma pinvmxE n (A : 'M[F]_n) : A \in unitmx -> pinvmx A = invmx A. Proof. move=> A_unit; apply: (@row_free_inj _ _ _ A); rewrite ?row_free_unit//. by rewrite -[pinvmx _]mul1mx mulmxKpV ?sub1mx ?row_full_unit// mulVmx. Qed. Lemma mulVpmx m n (A : 'M[F]_(m, n)) : row_full A -> pinvmx A *m A = 1%:M. Proof. by move=> fA; rewrite -[pinvmx _]mul1mx mulmxKpV// sub1mx. Qed. Lemma pinvmx_free m n (A : 'M[F]_(m, n)) : row_full A -> row_free (pinvmx A). Proof. by move=> /mulVpmx pAA1; apply/row_freeP; exists A. Qed. Lemma pinvmx_full m n (A : 'M[F]_(m, n)) : row_free A -> row_full (pinvmx A). Proof. by move=> /mulmxVp ApA1; apply/row_fullP; exists A. Qed. Lemma eqmxP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :=: B)%MS (A == B)%MS. Proof. apply: (iffP andP) => [[sAB sBA] | eqAB]; last by rewrite !eqAB. split=> [|m3 C]; first by apply/eqP; rewrite eqn_leq !mxrankS. split; first by apply/idP/idP; apply: submx_trans. by apply/idP/idP=> sC; apply: submx_trans sC _. Qed. Arguments eqmxP {m1 m2 n A B}. Lemma rV_eqP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (forall u : 'rV_n, (u <= A) = (u <= B))%MS (A == B)%MS. Proof. apply: (iffP idP) => [eqAB u | eqAB]; first by rewrite (eqmxP eqAB). by apply/andP; split; apply/rV_subP=> u; rewrite eqAB. Qed. Lemma mulmxP (m n : nat) (A B : 'M[F]_(m, n)) : reflect (forall u : 'rV_m, u *m A = u *m B) (A == B). Proof. apply: (iffP eqP) => [-> //|eqAB]. apply: (@row_full_inj _ _ _ 1%:M); first by rewrite row_full_unit unitmx1. by apply/row_matrixP => i; rewrite !row_mul eqAB. Qed. Lemma eqmx_refl m1 n (A : 'M_(m1, n)) : (A :=: A)%MS. Proof. by []. Qed. Lemma eqmx_sym m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> (B :=: A)%MS. Proof. by move=> eqAB; split=> [|m3 C]; rewrite !eqAB. Qed. Lemma eqmx_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A :=: B)%MS -> (B :=: C)%MS -> (A :=: C)%MS. Proof. by move=> eqAB eqBC; split=> [|m4 D]; rewrite !eqAB !eqBC. Qed. Lemma eqmx_rank m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A == B)%MS -> \rank A = \rank B. Proof. by move/eqmxP->. Qed. Lemma lt_eqmx m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> forall C : 'M_(m3, n), (((A < C) = (B < C))%MS * ((C < A) = (C < B))%MS)%type. Proof. by move=> eqAB C; rewrite /ltmx !eqAB. Qed. Lemma eqmxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : (A :=: B)%MS -> (A *m C :=: B *m C)%MS. Proof. by move=> eqAB; apply/eqmxP; rewrite !submxMr ?eqAB. Qed. Lemma eqmxMfull m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : row_full A -> (A *m B :=: B)%MS. Proof. case/row_fullP=> A' A'A; apply/eqmxP; rewrite submxMl /=. by apply/submxP; exists A'; rewrite mulmxA A'A mul1mx. Qed. Lemma eqmx0 m n : ((0 : 'M[F]_(m, n)) :=: (0 : 'M_n))%MS. Proof. by apply/eqmxP; rewrite !sub0mx. Qed. Lemma eqmx_scale m n a (A : 'M_(m, n)) : a != 0 -> (a *: A :=: A)%MS. Proof. move=> nz_a; apply/eqmxP; rewrite scalemx_sub //. by rewrite -{1}[A]scale1r -(mulVf nz_a) -scalerA scalemx_sub. Qed. Lemma eqmx_opp m n (A : 'M_(m, n)) : (- A :=: A)%MS. Proof. by rewrite -scaleN1r; apply: eqmx_scale => //; rewrite oppr_eq0 oner_eq0. Qed. Lemma submxMfree m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : row_free C -> (A *m C <= B *m C)%MS = (A <= B)%MS. Proof. case/row_freeP=> C' C_C'_1; apply/idP/idP=> sAB; last exact: submxMr. by rewrite -[A]mulmx1 -[B]mulmx1 -C_C'_1 !mulmxA submxMr. Qed. Lemma eqmxMfree m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : row_free C -> (A *m C :=: B *m C)%MS -> (A :=: B)%MS. Proof. by move=> Cfree eqAB; apply/eqmxP; move/eqmxP: eqAB; rewrite !submxMfree. Qed. Lemma mxrankMfree m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : row_free B -> \rank (A *m B) = \rank A. Proof. by move=> Bfree; rewrite -mxrank_tr trmx_mul eqmxMfull /row_full mxrank_tr. Qed. Lemma eq_row_base m n (A : 'M_(m, n)) : (row_base A :=: A)%MS. Proof. apply/eqmxP/andP; split; apply/submxP. exists (pid_mx (\rank A) *m invmx (col_ebase A)). by rewrite -{8}[A]mulmx_ebase !mulmxA mulmxKV // pid_mx_id. exists (col_ebase A *m pid_mx (\rank A)). by rewrite mulmxA -(mulmxA _ _ (pid_mx _)) pid_mx_id // mulmx_ebase. Qed. Lemma row_base0 (m n : nat) : row_base (0 : 'M[F]_(m, n)) = 0. Proof. by apply/eqmx0P; rewrite !eq_row_base !sub0mx. Qed. Let qidmx_eq1 n (A : 'M_n) : qidmx A = (A == 1%:M). Proof. by rewrite /qidmx eqxx pid_mx_1. Qed. Let genmx_witnessP m n (A : 'M_(m, n)) : equivmx A (row_full A) (genmx_witness A). Proof. rewrite /equivmx qidmx_eq1 /genmx_witness. case fullA: (row_full A); first by rewrite eqxx sub1mx submx1 fullA. set B := _ *m _; have defB : (B == A)%MS. apply/andP; split; apply/submxP. exists (pid_mx (\rank A) *m invmx (col_ebase A)). by rewrite -{3}[A]mulmx_ebase !mulmxA mulmxKV // pid_mx_id. exists (col_ebase A *m pid_mx (\rank A)). by rewrite mulmxA -(mulmxA _ _ (pid_mx _)) pid_mx_id // mulmx_ebase. rewrite defB -negb_add addbF; case: eqP defB => // ->. by rewrite sub1mx fullA. Qed. Lemma genmxE m n (A : 'M_(m, n)) : (<<A>> :=: A)%MS. Proof. by rewrite unlock; apply/eqmxP; case/andP: (chooseP (genmx_witnessP A)). Qed. Lemma eq_genmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B -> <<A>> = <<B>>)%MS. Proof. move=> eqAB; rewrite unlock. have{} eqAB: equivmx A (row_full A) =1 equivmx B (row_full B). by move=> C; rewrite /row_full /equivmx !eqAB. rewrite (eq_choose eqAB) (choose_id _ (genmx_witnessP B)) //. by rewrite -eqAB genmx_witnessP. Qed. Lemma genmxP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (<<A>> = <<B>>)%MS (A == B)%MS. Proof. apply: (iffP idP) => eqAB; first exact: eq_genmx (eqmxP _). by rewrite -!(genmxE A) eqAB !genmxE andbb. Qed. Arguments genmxP {m1 m2 n A B}. Lemma genmx0 m n : <<0 : 'M_(m, n)>>%MS = 0. Proof. by apply/eqP; rewrite -submx0 genmxE sub0mx. Qed. Lemma genmx1 n : <<1%:M : 'M_n>>%MS = 1%:M. Proof. rewrite unlock; case/andP: (chooseP (@genmx_witnessP n n 1%:M)) => _ /eqP. by rewrite qidmx_eq1 row_full_unit unitmx1 => /eqP. Qed. Lemma genmx_id m n (A : 'M_(m, n)) : (<<<<A>>>> = <<A>>)%MS. Proof. exact/eq_genmx/genmxE. Qed. Lemma row_base_free m n (A : 'M_(m, n)) : row_free (row_base A). Proof. by apply/eqnP; rewrite eq_row_base. Qed. Lemma mxrank_gen m n (A : 'M_(m, n)) : \rank <<A>>%MS = \rank A. Proof. by rewrite genmxE. Qed. Lemma col_base_full m n (A : 'M_(m, n)) : row_full (col_base A). Proof. apply/row_fullP; exists (pid_mx (\rank A) *m invmx (col_ebase A)). by rewrite !mulmxA mulmxKV // pid_mx_id // pid_mx_1. Qed. Hint Resolve row_base_free col_base_full : core. Lemma mxrank_leqif_sup m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> \rank A <= \rank B ?= iff (B <= A)%MS. Proof. move=> sAB; split; first by rewrite mxrankS. apply/idP/idP=> [| sBA]; last by rewrite eqn_leq !mxrankS. case/submxP: sAB => D ->; set r := \rank B; rewrite -(mulmx_base B) mulmxA. rewrite mxrankMfree // => /row_fullP[E kE]. by rewrite -[rB in _ *m rB]mul1mx -kE -(mulmxA E) (mulmxA _ E) submxMl. Qed. Lemma mxrank_leqif_eq m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> \rank A <= \rank B ?= iff (A == B)%MS. Proof. by move=> sAB; rewrite sAB; apply: mxrank_leqif_sup. Qed. Lemma ltmxErank m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A < B)%MS = (A <= B)%MS && (\rank A < \rank B). Proof. by apply: andb_id2l => sAB; rewrite (ltn_leqif (mxrank_leqif_sup sAB)). Qed. Lemma rank_ltmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A < B)%MS -> \rank A < \rank B. Proof. by rewrite ltmxErank => /andP[]. Qed. Lemma eqmx_cast m1 m2 n (A : 'M_(m1, n)) e : ((castmx e A : 'M_(m2, n)) :=: A)%MS. Proof. by case: e A; case: m2 / => A e; rewrite castmx_id. Qed. Lemma row_full_castmx m1 m2 n (A : 'M_(m1, n)) e : row_full (castmx e A : 'M_(m2, n)) = row_full A. Proof. exact/eq_row_full/eqmx_cast. Qed. Lemma row_free_castmx m1 m2 n (A : 'M_(m1, n)) e : row_free (castmx e A : 'M_(m2, n)) = row_free A. Proof. by rewrite /row_free eqmx_cast; congr (_ == _); rewrite e.1. Qed. Lemma eqmx_conform m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (conform_mx A B :=: A \/ conform_mx A B :=: B)%MS. Proof. case: (eqVneq m2 m1) => [-> | neqm12] in B *. by right; rewrite conform_mx_id. by left; rewrite nonconform_mx ?neqm12. Qed. Let eqmx_sum_nop m n (A : 'M_(m, n)) : (addsmx_nop A :=: A)%MS. Proof. case: (eqmx_conform <<A>>%MS A) => // eq_id_gen. exact: eqmx_trans (genmxE A). Qed. Lemma rowsub_comp_sub (m n p q : nat) f (g : 'I_n -> 'I_p) (A : 'M_(m, q)) : (rowsub (f \o g) A <= rowsub f A)%MS. Proof. by rewrite rowsub_comp rowsubE mulmx_sub. Qed. Lemma submx_rowsub (m n p q : nat) (h : 'I_n -> 'I_p) f g (A : 'M_(m, q)) : f =1 g \o h -> (rowsub f A <= rowsub g A)%MS. Proof. by move=> /eq_rowsub->; rewrite rowsub_comp_sub. Qed. Arguments submx_rowsub [m1 m2 m3 n] h [f g A] _ : rename. Lemma eqmx_rowsub_comp_perm (m1 m2 n : nat) (s : 'S_m2) f (A : 'M_(m1, n)) : (rowsub (f \o s) A :=: rowsub f A)%MS. Proof. rewrite rowsub_comp rowsubE; apply: eqmxMfull. by rewrite -perm_mxEsub row_full_unit unitmx_perm. Qed. Lemma eqmx_rowsub_comp (m n p q : nat) f (g : 'I_n -> 'I_p) (A : 'M_(m, q)) : p <= n -> injective g -> (rowsub (f \o g) A :=: rowsub f A)%MS. Proof. move=> leq_pn g_inj; have eq_np : n == p by rewrite eqn_leq leq_pn (inj_leq g). rewrite (eqP eq_np) in g g_inj *. rewrite (eq_rowsub (f \o (perm g_inj))); last by move=> i; rewrite /= permE. exact: eqmx_rowsub_comp_perm. Qed. Lemma eqmx_rowsub (m n p q : nat) (h : 'I_n -> 'I_p) f g (A : 'M_(m, q)) : injective h -> p <= n -> f =1 g \o h -> (rowsub f A :=: rowsub g A)%MS. Proof. by move=> leq_pn h_inj /eq_rowsub->; apply: eqmx_rowsub_comp. Qed. Arguments eqmx_rowsub [m1 m2 m3 n] h [f g A] _ : rename. Section AddsmxSub. Variable (m1 m2 n : nat) (A : 'M[F]_(m1, n)) (B : 'M[F]_(m2, n)). Lemma col_mx_sub m3 (C : 'M_(m3, n)) : (col_mx A B <= C)%MS = (A <= C)%MS && (B <= C)%MS. Proof. rewrite !submxE mul_col_mx -col_mx0. by apply/eqP/andP; [case/eq_col_mx=> -> -> | case; do 2!move/eqP->]. Qed. Lemma addsmxE : (A + B :=: col_mx A B)%MS. Proof. have:= submx_refl (col_mx A B); rewrite col_mx_sub; case/andP=> sAS sBS. rewrite unlock; do 2?case: eqP => [AB0 | _]; last exact: genmxE. by apply/eqmxP; rewrite !eqmx_sum_nop sBS col_mx_sub AB0 sub0mx /=. by apply/eqmxP; rewrite !eqmx_sum_nop sAS col_mx_sub AB0 sub0mx andbT /=. Qed. Lemma addsmx_sub m3 (C : 'M_(m3, n)) : (A + B <= C)%MS = (A <= C)%MS && (B <= C)%MS. Proof. by rewrite addsmxE col_mx_sub. Qed. Lemma addsmxSl : (A <= A + B)%MS. Proof. by have:= submx_refl (A + B)%MS; rewrite addsmx_sub; case/andP. Qed. Lemma addsmxSr : (B <= A + B)%MS. Proof. by have:= submx_refl (A + B)%MS; rewrite addsmx_sub; case/andP. Qed. Lemma addsmx_idPr : reflect (A + B :=: B)%MS (A <= B)%MS. Proof. have:= @eqmxP _ _ _ (A + B)%MS B. by rewrite addsmxSr addsmx_sub submx_refl !andbT. Qed. Lemma addsmx_idPl : reflect (A + B :=: A)%MS (B <= A)%MS. Proof. have:= @eqmxP _ _ _ (A + B)%MS A. by rewrite addsmxSl addsmx_sub submx_refl !andbT. Qed. End AddsmxSub. Lemma adds0mx m1 m2 n (B : 'M_(m2, n)) : ((0 : 'M_(m1, n)) + B :=: B)%MS. Proof. by apply/eqmxP; rewrite addsmx_sub sub0mx addsmxSr /= andbT. Qed. Lemma addsmx0 m1 m2 n (A : 'M_(m1, n)) : (A + (0 : 'M_(m2, n)) :=: A)%MS. Proof. by apply/eqmxP; rewrite addsmx_sub sub0mx addsmxSl /= !andbT. Qed. Let addsmx_nop_eq0 m n (A : 'M_(m, n)) : (addsmx_nop A == 0) = (A == 0). Proof. by rewrite -!submx0 eqmx_sum_nop. Qed. Let addsmx_nop0 m n : addsmx_nop (0 : 'M_(m, n)) = 0. Proof. by apply/eqP; rewrite addsmx_nop_eq0. Qed. Let addsmx_nop_id n (A : 'M_n) : addsmx_nop A = A. Proof. exact: conform_mx_id. Qed. Lemma addsmxC m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A + B = B + A)%MS. Proof. have: (A + B == B + A)%MS. by apply/andP; rewrite !addsmx_sub andbC -addsmx_sub andbC -addsmx_sub. move/genmxP; rewrite [@addsmx]unlock -!submx0 !submx0. by do 2!case: eqP => [// -> | _]; rewrite ?genmx_id ?addsmx_nop0. Qed. Lemma adds0mx_id m1 n (B : 'M_n) : ((0 : 'M_(m1, n)) + B)%MS = B. Proof. by rewrite unlock eqxx addsmx_nop_id. Qed. Lemma addsmx0_id m2 n (A : 'M_n) : (A + (0 : 'M_(m2, n)))%MS = A. Proof. by rewrite addsmxC adds0mx_id. Qed. Lemma addsmxA m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A + (B + C) = A + B + C)%MS. Proof. have: (A + (B + C) :=: A + B + C)%MS. by apply/eqmxP/andP; rewrite !addsmx_sub -andbA andbA -!addsmx_sub. rewrite {1 3}[in @addsmx _ m1]unlock [in @addsmx _ n]unlock !addsmx_nop_id -!submx0. rewrite !addsmx_sub ![@addsmx]unlock -!submx0; move/eq_genmx. by do 3!case: (_ <= 0)%MS; rewrite //= !genmx_id. Qed. HB.instance Definition _ n := Monoid.isComLaw.Build (matrix F n n) 0%MS addsmx.body (@addsmxA n n n n) (@addsmxC n n n) (@adds0mx_id n n). Lemma addsmxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : ((A + B)%MS *m C :=: A *m C + B *m C)%MS. Proof. by apply/eqmxP; rewrite !addsmxE -!mul_col_mx !submxMr ?addsmxE. Qed. Lemma addsmxS m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A <= C -> B <= D -> A + B <= C + D)%MS. Proof. move=> sAC sBD. by rewrite addsmx_sub {1}addsmxC !(submx_trans _ (addsmxSr _ _)). Qed. Lemma addmx_sub_adds m m1 m2 n (A : 'M_(m, n)) (B : 'M_(m, n)) (C : 'M_(m1, n)) (D : 'M_(m2, n)) : (A <= C -> B <= D -> (A + B)%R <= C + D)%MS. Proof. move=> sAC; move/(addsmxS sAC); apply: submx_trans. by rewrite addmx_sub ?addsmxSl ?addsmxSr. Qed. Lemma addsmx_addKl n m1 m2 (A : 'M_(m1, n)) (B C : 'M_(m2, n)) : (B <= A)%MS -> (A + (B + C)%R :=: A + C)%MS. Proof. move=> sBA; apply/eqmxP; rewrite !addsmx_sub !addsmxSl. by rewrite -{3}[C](addKr B) !addmx_sub_adds ?eqmx_opp. Qed. Lemma addsmx_addKr n m1 m2 (A B : 'M_(m1, n)) (C : 'M_(m2, n)) : (B <= C)%MS -> ((A + B)%R + C :=: A + C)%MS. Proof. by rewrite -!(addsmxC C) addrC; apply: addsmx_addKl. Qed. Lemma adds_eqmx m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A :=: C -> B :=: D -> A + B :=: C + D)%MS. Proof. by move=> eqAC eqBD; apply/eqmxP; rewrite !addsmxS ?eqAC ?eqBD. Qed. Lemma genmx_adds m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (<<(A + B)%MS>> = <<A>> + <<B>>)%MS. Proof. rewrite -(eq_genmx (adds_eqmx (genmxE A) (genmxE B))). by rewrite [@addsmx]unlock !addsmx_nop_id !(fun_if (@genmx _ _ _)) !genmx_id. Qed. Lemma sub_addsmxP m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : reflect (exists u, A = u.1 *m B + u.2 *m C) (A <= B + C)%MS. Proof. apply: (iffP idP) => [|[u ->]]; last by rewrite addmx_sub_adds ?submxMl. rewrite addsmxE; case/submxP=> u ->; exists (lsubmx u, rsubmx u). by rewrite -mul_row_col hsubmxK. Qed. Arguments sub_addsmxP {m1 m2 m3 n A B C}. Variable I : finType. Implicit Type P : pred I. Lemma genmx_sums P n (B_ : I -> 'M_n) : <<(\sum_(i | P i) B_ i)%MS>>%MS = (\sum_(i | P i) <<B_ i>>)%MS. Proof. exact: (big_morph _ (@genmx_adds n n n) (@genmx0 n n)). Qed. Lemma sumsmx_sup i0 P m n (A : 'M_(m, n)) (B_ : I -> 'M_n) : P i0 -> (A <= B_ i0)%MS -> (A <= \sum_(i | P i) B_ i)%MS. Proof. by move=> Pi0 sAB; apply: submx_trans sAB _; rewrite (bigD1 i0) // addsmxSl. Qed. Arguments sumsmx_sup i0 [P m n A B_]. Lemma sumsmx_subP P m n (A_ : I -> 'M_n) (B : 'M_(m, n)) : reflect (forall i, P i -> A_ i <= B)%MS (\sum_(i | P i) A_ i <= B)%MS. Proof. apply: (iffP idP) => [sAB i Pi | sAB]. by apply: submx_trans sAB; apply: sumsmx_sup Pi _. by elim/big_rec: _ => [|i Ai Pi sAiB]; rewrite ?sub0mx // addsmx_sub sAB. Qed. Lemma summx_sub_sums P m n (A : I -> 'M[F]_(m, n)) B : (forall i, P i -> A i <= B i)%MS -> ((\sum_(i | P i) A i)%R <= \sum_(i | P i) B i)%MS. Proof. by move=> sAB; apply: summx_sub => i Pi; rewrite (sumsmx_sup i) ?sAB. Qed. Lemma sumsmxS P n (A B : I -> 'M[F]_n) : (forall i, P i -> A i <= B i)%MS -> (\sum_(i | P i) A i <= \sum_(i | P i) B i)%MS. Proof. by move=> sAB; apply/sumsmx_subP=> i Pi; rewrite (sumsmx_sup i) ?sAB. Qed. Lemma eqmx_sums P n (A B : I -> 'M[F]_n) : (forall i, P i -> A i :=: B i)%MS -> (\sum_(i | P i) A i :=: \sum_(i | P i) B i)%MS. Proof. by move=> eqAB; apply/eqmxP; rewrite !sumsmxS // => i; move/eqAB->. Qed. Lemma sub_sums_genmxP P m n p (A : 'M_(m, p)) (B_ : I -> 'M_(n, p)) : reflect (exists u_ : I -> 'M_(m, n), A = \sum_(i | P i) u_ i *m B_ i) (A <= \sum_(i | P i) <<B_ i>>)%MS. Proof. apply: (iffP idP) => [| [u_ ->]]; last first. by apply: summx_sub_sums => i _; rewrite genmxE; apply: submxMl. have [b] := ubnP #|P|; elim: b => // b IHb in P A *. case: (pickP P) => [i Pi | P0 _]; last first. rewrite big_pred0 //; move/submx0null->. by exists (fun _ => 0); rewrite big_pred0. rewrite (cardD1x Pi) (bigD1 i) //= => /IHb{b IHb} /= IHi. rewrite (adds_eqmx (genmxE _) (eqmx_refl _)) => /sub_addsmxP[u ->]. have [u_ ->] := IHi _ (submxMl u.2 _). exists [eta u_ with i |-> u.1]; rewrite (bigD1 i Pi)/= eqxx; congr (_ + _). by apply: eq_bigr => j /andP[_ /negPf->]. Qed. Lemma sub_sumsmxP P m n (A : 'M_(m, n)) (B_ : I -> 'M_n) : reflect (exists u_, A = \sum_(i | P i) u_ i *m B_ i) (A <= \sum_(i | P i) B_ i)%MS. Proof. by rewrite -(eqmx_sums (fun _ _ => genmxE _)); apply/sub_sums_genmxP. Qed. Lemma sumsmxMr_gen P m n A (B : 'M[F]_(m, n)) : ((\sum_(i | P i) A i)%MS *m B :=: \sum_(i | P i) <<A i *m B>>)%MS. Proof. apply/eqmxP/andP; split; last first. by apply/sumsmx_subP=> i Pi; rewrite genmxE submxMr ?(sumsmx_sup i). have [u ->] := sub_sumsmxP _ _ _ (submx_refl (\sum_(i | P i) A i)%MS). by rewrite mulmx_suml summx_sub_sums // => i _; rewrite genmxE -mulmxA submxMl. Qed. Lemma sumsmxMr P n (A_ : I -> 'M[F]_n) (B : 'M_n) : ((\sum_(i | P i) A_ i)%MS *m B :=: \sum_(i | P i) (A_ i *m B))%MS. Proof. by apply: eqmx_trans (sumsmxMr_gen _ _ _) (eqmx_sums _) => i _; apply: genmxE. Qed. Lemma rank_pid_mx m n r : r <= m -> r <= n -> \rank (pid_mx r : 'M_(m, n)) = r. Proof. do 2!move/subnKC <-; rewrite pid_mx_block block_mxEv row_mx0 -addsmxE addsmx0. by rewrite -mxrank_tr tr_row_mx trmx0 trmx1 -addsmxE addsmx0 mxrank1. Qed. Lemma rank_copid_mx n r : r <= n -> \rank (copid_mx r : 'M_n) = (n - r)%N. Proof. move/subnKC <-; rewrite /copid_mx pid_mx_block scalar_mx_block. rewrite opp_block_mx !oppr0 add_block_mx !addr0 subrr block_mxEv row_mx0. rewrite -addsmxE adds0mx -mxrank_tr tr_row_mx trmx0 trmx1. by rewrite -addsmxE adds0mx mxrank1 addKn. Qed. Lemma mxrank_compl m n (A : 'M_(m, n)) : \rank A^C = (n - \rank A)%N. Proof. by rewrite mxrankMfree ?row_free_unit ?rank_copid_mx. Qed. Lemma mxrank_ker m n (A : 'M_(m, n)) : \rank (kermx A) = (m - \rank A)%N. Proof. by rewrite mxrankMfree ?row_free_unit ?unitmx_inv ?rank_copid_mx. Qed. Lemma kermx_eq0 n m (A : 'M_(m, n)) : (kermx A == 0) = row_free A. Proof. by rewrite -mxrank_eq0 mxrank_ker subn_eq0 row_leq_rank. Qed. Lemma mxrank_coker m n (A : 'M_(m, n)) : \rank (cokermx A) = (n - \rank A)%N. Proof. by rewrite eqmxMfull ?row_full_unit ?unitmx_inv ?rank_copid_mx. Qed. Lemma cokermx_eq0 n m (A : 'M_(m, n)) : (cokermx A == 0) = row_full A. Proof. by rewrite -mxrank_eq0 mxrank_coker subn_eq0 col_leq_rank. Qed. Lemma mulmx_ker m n (A : 'M_(m, n)) : kermx A *m A = 0. Proof. by rewrite -{2}[A]mulmx_ebase !mulmxA mulmxKV // mul_copid_mx_pid ?mul0mx. Qed. Lemma mulmxKV_ker m n p (A : 'M_(n, p)) (B : 'M_(m, n)) : B *m A = 0 -> B *m col_ebase A *m kermx A = B. Proof. rewrite mulmxA mulmxBr mulmx1 mulmxBl mulmxK //. rewrite -{1}[A]mulmx_ebase !mulmxA => /(canRL (mulmxK (row_ebase_unit A))). rewrite mul0mx // => BA0; apply: (canLR (addrK _)). by rewrite -(pid_mx_id _ _ n (rank_leq_col A)) mulmxA BA0 !mul0mx addr0. Qed. Lemma sub_kermxP p m n (A : 'M_(m, n)) (B : 'M_(p, m)) : reflect (B *m A = 0) (B <= kermx A)%MS. Proof. apply: (iffP submxP) => [[D ->]|]; first by rewrite -mulmxA mulmx_ker mulmx0. by move/mulmxKV_ker; exists (B *m col_ebase A). Qed. Lemma sub_kermx p m n (A : 'M_(m, n)) (B : 'M_(p, m)) : (B <= kermx A)%MS = (B *m A == 0). Proof. exact/sub_kermxP/eqP. Qed. Lemma kermx0 m n : (kermx (0 : 'M_(m, n)) :=: 1%:M)%MS. Proof. by apply/eqmxP; rewrite submx1/= sub_kermx mulmx0. Qed. Lemma mulmx_free_eq0 m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : row_free B -> (A *m B == 0) = (A == 0). Proof. by rewrite -sub_kermx -kermx_eq0 => /eqP->; rewrite submx0. Qed. Lemma inj_row_free m n (A : 'M_(m, n)) : (forall v : 'rV_m, v *m A = 0 -> v = 0) -> row_free A. Proof. move=> Ainj; rewrite -kermx_eq0; apply/eqP/row_matrixP => i. by rewrite row0; apply/Ainj; rewrite -row_mul mulmx_ker row0. Qed. Lemma row_freePn m n (M : 'M[F]_(m, n)) : reflect (exists i, (row i M <= row' i M)%MS) (~~ row_free M). Proof. rewrite -kermx_eq0; apply: (iffP (rowV0Pn _)) => [|[i0 /submxP[D rM]]]. move=> [v /sub_kermxP vM_eq0 /rV0Pn[i0 vi0_neq0]]; exists i0. have := vM_eq0; rewrite mulmx_sum_row (bigD1_ord i0)//=. move=> /(canRL (addrK _))/(canRL (scalerK _))->//. rewrite sub0r scalerN -scaleNr scalemx_sub// summx_sub// => l _. by rewrite scalemx_sub// -row_rowsub row_sub. exists (\row_j oapp (D 0) (- 1) (unlift i0 j)); last first. by apply/rV0Pn; exists i0; rewrite !mxE unlift_none/= oppr_eq0 oner_eq0. apply/sub_kermxP; rewrite mulmx_sum_row (bigD1_ord i0)//= !mxE. rewrite unlift_none scaleN1r rM mulmx_sum_row addrC -sumrB big1 // => l _. by rewrite !mxE liftK row_rowsub subrr. Qed. Lemma negb_row_free m n (M : 'M[F]_(m, n)) : ~~ row_free M = [exists i, (row i M <= row' i M)%MS]. Proof. exact/row_freePn/existsP. Qed. Lemma mulmx0_rank_max m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : A *m B = 0 -> \rank A + \rank B <= n. Proof. move=> AB0; rewrite -{3}(subnK (rank_leq_row B)) leq_add2r. by rewrite -mxrank_ker mxrankS // sub_kermx AB0. Qed. Lemma mxrank_Frobenius m n p q (A : 'M_(m, n)) B (C : 'M_(p, q)) : \rank (A *m B) + \rank (B *m C) <= \rank B + \rank (A *m B *m C). Proof. rewrite -{2}(mulmx_base (A *m B)) -mulmxA (eqmxMfull _ (col_base_full _)). set C2 := row_base _ *m C. rewrite -{1}(subnK (rank_leq_row C2)) -(mxrank_ker C2) addnAC leq_add2r. rewrite addnC -{1}(mulmx_base B) -mulmxA eqmxMfull //. set C1 := _ *m C; rewrite -{2}(subnKC (rank_leq_row C1)) leq_add2l -mxrank_ker. rewrite -(mxrankMfree _ (row_base_free (A *m B))). have: (row_base (A *m B) <= row_base B)%MS by rewrite !eq_row_base submxMl. case/submxP=> D defD; rewrite defD mulmxA mxrankMfree ?mxrankS //. by rewrite sub_kermx -mulmxA (mulmxA D) -defD -/C2 mulmx_ker. Qed. Lemma mxrank_mul_min m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : \rank A + \rank B - n <= \rank (A *m B). Proof. by have:= mxrank_Frobenius A 1%:M B; rewrite mulmx1 mul1mx mxrank1 leq_subLR. Qed. Lemma addsmx_compl_full m n (A : 'M_(m, n)) : row_full (A + A^C)%MS. Proof. rewrite /row_full addsmxE; apply/row_fullP. exists (row_mx (pinvmx A) (cokermx A)); rewrite mul_row_col. rewrite -{2}[A]mulmx_ebase -!mulmxA mulKmx // -mulmxDr !mulmxA. by rewrite pid_mx_id ?copid_mx_id // -mulmxDl addrC subrK mul1mx mulVmx. Qed. Lemma sub_capmx_gen m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= capmx_gen B C)%MS = (A <= B)%MS && (A <= C)%MS. Proof. apply/idP/andP=> [sAI | [/submxP[B' ->{A}] /submxP[C' eqBC']]]. rewrite !(submx_trans sAI) ?submxMl // /capmx_gen. have:= mulmx_ker (col_mx B C); set K := kermx _. rewrite -{1}[K]hsubmxK mul_row_col; move/(canRL (addrK _))->. by rewrite add0r -mulNmx submxMl. have: (row_mx B' (- C') <= kermx (col_mx B C))%MS. by rewrite sub_kermx mul_row_col eqBC' mulNmx subrr. case/submxP=> D; rewrite -[kermx _]hsubmxK mul_mx_row. by case/eq_row_mx=> -> _; rewrite -mulmxA submxMl. Qed. Let capmx_witnessP m n (A : 'M_(m, n)) : equivmx A (qidmx A) (capmx_witness A). Proof. rewrite /equivmx qidmx_eq1 /qidmx /capmx_witness. rewrite -sub1mx; case s1A: (1%:M <= A)%MS => /=; last first. rewrite !genmxE submx_refl /= -negb_add; apply: contra {s1A}(negbT s1A). have [<- | _] := eqP; first by rewrite genmxE. by case: eqP A => //= -> A /eqP ->; rewrite pid_mx_1. case: (m =P n) => [-> | ne_mn] in A s1A *. by rewrite conform_mx_id submx_refl pid_mx_1 eqxx. by rewrite nonconform_mx ?submx1 ?s1A ?eqxx //; case: eqP. Qed. Let capmx_normP m n (A : 'M_(m, n)) : equivmx_spec A (qidmx A) (capmx_norm A). Proof. by case/andP: (chooseP (capmx_witnessP A)) => /eqmxP defN /eqP. Qed. Let capmx_norm_eq m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx A = qidmx B -> (A == B)%MS -> capmx_norm A = capmx_norm B. Proof. move=> eqABid /eqmxP eqAB. have{eqABid} eqAB: equivmx A (qidmx A) =1 equivmx B (qidmx B). by move=> C; rewrite /equivmx eqABid !eqAB. rewrite {1}/capmx_norm (eq_choose eqAB). by apply: choose_id; first rewrite -eqAB; apply: capmx_witnessP. Qed. Let capmx_nopP m n (A : 'M_(m, n)) : equivmx_spec A (qidmx A) (capmx_nop A). Proof. rewrite /capmx_nop; case: (eqVneq m n) => [-> | ne_mn] in A *. by rewrite conform_mx_id. by rewrite nonconform_mx ?ne_mn //; apply: capmx_normP. Qed. Let sub_qidmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx B -> (A <= B)%MS. Proof. rewrite /qidmx => idB; apply: {A}submx_trans (submx1 A) _. by case: eqP B idB => [-> _ /eqP-> | _ B]; rewrite (=^~ sub1mx, pid_mx_1). Qed. Let qidmx_cap m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx (A :&: B)%MS = qidmx A && qidmx B. Proof. rewrite unlock -sub1mx. case idA: (qidmx A); case idB: (qidmx B); try by rewrite capmx_nopP. case s1B: (_ <= B)%MS; first by rewrite capmx_normP. apply/idP=> /(sub_qidmx 1%:M). by rewrite capmx_normP sub_capmx_gen s1B andbF. Qed. Let capmx_eq_norm m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx A = qidmx B -> (A :&: B)%MS = capmx_norm (A :&: B)%MS. Proof. move=> eqABid; rewrite unlock -sub1mx {}eqABid. have norm_id m (C : 'M_(m, n)) (N := capmx_norm C) : capmx_norm N = N. by apply: capmx_norm_eq; rewrite ?capmx_normP ?andbb. case idB: (qidmx B); last by case: ifP; rewrite norm_id. rewrite /capmx_nop; case: (eqVneq m2 n) => [-> | neqm2n] in B idB *. have idN := idB; rewrite -{1}capmx_normP !qidmx_eq1 in idN idB. by rewrite conform_mx_id (eqP idN) (eqP idB). by rewrite nonconform_mx ?neqm2n ?norm_id. Qed. Lemma capmxE m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B :=: capmx_gen A B)%MS. Proof. rewrite unlock -sub1mx; apply/eqmxP. have:= submx_refl (capmx_gen A B); rewrite !sub_capmx_gen => /andP[sIA sIB]. case idA: (qidmx A); first by rewrite !capmx_nopP submx_refl sub_qidmx. case idB: (qidmx B); first by rewrite !capmx_nopP submx_refl sub_qidmx. case s1B: (1%:M <= B)%MS; rewrite !capmx_normP ?sub_capmx_gen sIA ?sIB //=. by rewrite submx_refl (submx_trans (submx1 _)). Qed. Lemma capmxSl m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B <= A)%MS. Proof. by rewrite capmxE submxMl. Qed. Lemma sub_capmx m m1 m2 n (A : 'M_(m, n)) (B : 'M_(m1, n)) (C : 'M_(m2, n)) : (A <= B :&: C)%MS = (A <= B)%MS && (A <= C)%MS. Proof. by rewrite capmxE sub_capmx_gen. Qed. Lemma capmxC m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B = B :&: A)%MS. Proof. have [eqAB|] := eqVneq (qidmx A) (qidmx B). rewrite (capmx_eq_norm eqAB) (capmx_eq_norm (esym eqAB)). apply: capmx_norm_eq; first by rewrite !qidmx_cap andbC. by apply/andP; split; rewrite !sub_capmx andbC -sub_capmx. by rewrite negb_eqb !unlock => /addbP <-; case: (qidmx A). Qed. Lemma capmxSr m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B <= B)%MS. Proof. by rewrite capmxC capmxSl. Qed. Lemma capmx_idPr n m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :&: B :=: B)%MS (B <= A)%MS. Proof. have:= @eqmxP _ _ _ (A :&: B)%MS B. by rewrite capmxSr sub_capmx submx_refl !andbT. Qed. Lemma capmx_idPl n m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :&: B :=: A)%MS (A <= B)%MS. Proof. by rewrite capmxC; apply: capmx_idPr. Qed. Lemma capmxS m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A <= C -> B <= D -> A :&: B <= C :&: D)%MS. Proof. by move=> sAC sBD; rewrite sub_capmx {1}capmxC !(submx_trans (capmxSr _ _)). Qed. Lemma cap_eqmx m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A :=: C -> B :=: D -> A :&: B :=: C :&: D)%MS. Proof. by move=> eqAC eqBD; apply/eqmxP; rewrite !capmxS ?eqAC ?eqBD. Qed. Lemma capmxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : ((A :&: B) *m C <= A *m C :&: B *m C)%MS. Proof. by rewrite sub_capmx !submxMr ?capmxSl ?capmxSr. Qed. Lemma cap0mx m1 m2 n (A : 'M_(m2, n)) : ((0 : 'M_(m1, n)) :&: A)%MS = 0. Proof. exact: submx0null (capmxSl _ _). Qed. Lemma capmx0 m1 m2 n (A : 'M_(m1, n)) : (A :&: (0 : 'M_(m2, n)))%MS = 0. Proof. exact: submx0null (capmxSr _ _). Qed. Lemma capmxT m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : row_full B -> (A :&: B :=: A)%MS. Proof. rewrite -sub1mx => s1B; apply/eqmxP. by rewrite capmxSl sub_capmx submx_refl (submx_trans (submx1 A)). Qed. Lemma capTmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : row_full A -> (A :&: B :=: B)%MS. Proof. by move=> Afull; apply/eqmxP; rewrite capmxC !capmxT ?andbb. Qed. Let capmx_nop_id n (A : 'M_n) : capmx_nop A = A. Proof. by rewrite /capmx_nop conform_mx_id. Qed. Lemma cap1mx n (A : 'M_n) : (1%:M :&: A = A)%MS. Proof. by rewrite unlock qidmx_eq1 eqxx capmx_nop_id. Qed. Lemma capmx1 n (A : 'M_n) : (A :&: 1%:M = A)%MS. Proof. by rewrite capmxC cap1mx. Qed. Lemma genmx_cap m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : <<A :&: B>>%MS = (<<A>> :&: <<B>>)%MS. Proof. rewrite -(eq_genmx (cap_eqmx (genmxE A) (genmxE B))). case idAB: (qidmx <<A>> || qidmx <<B>>)%MS. rewrite [@capmx]unlock !capmx_nop_id !(fun_if (@genmx _ _ _)) !genmx_id. by case: (qidmx _) idAB => //= ->. case idA: (qidmx _) idAB => //= idB; rewrite {2}capmx_eq_norm ?idA //. set C := (_ :&: _)%MS; have eq_idC: row_full C = qidmx C. rewrite qidmx_cap idA -sub1mx sub_capmx genmxE; apply/andP=> [[s1A]]. by case/idP: idA; rewrite qidmx_eq1 -genmx1 (sameP eqP genmxP) submx1. rewrite unlock /capmx_norm eq_idC. by apply: choose_id (capmx_witnessP _); rewrite -eq_idC genmx_witnessP. Qed. Lemma capmxA m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A :&: (B :&: C) = A :&: B :&: C)%MS. Proof. rewrite (capmxC A B) capmxC; wlog idA: m1 m3 A C / qidmx A. move=> IH; case idA: (qidmx A); first exact: IH. case idC: (qidmx C); first by rewrite -IH. rewrite (@capmx_eq_norm n m3) ?qidmx_cap ?idA ?idC ?andbF //. rewrite capmx_eq_norm ?qidmx_cap ?idA ?idC ?andbF //. apply: capmx_norm_eq; first by rewrite !qidmx_cap andbAC. by apply/andP; split; rewrite !sub_capmx andbAC -!sub_capmx. rewrite -!(capmxC A) [in @capmx _ m1]unlock idA capmx_nop_id. have [eqBC|] := eqVneq (qidmx B) (qidmx C). rewrite (@capmx_eq_norm n) ?capmx_nopP // capmx_eq_norm //. by apply: capmx_norm_eq; rewrite ?qidmx_cap ?capmxS ?capmx_nopP. by rewrite !unlock capmx_nopP capmx_nop_id; do 2?case: (qidmx _) => //. Qed. HB.instance Definition _ n := Monoid.isComLaw.Build (matrix F n n) 1%:M capmx.body (@capmxA n n n n) (@capmxC n n n) (@cap1mx n). Lemma bigcapmx_inf i0 P m n (A_ : I -> 'M_n) (B : 'M_(m, n)) : P i0 -> (A_ i0 <= B -> \bigcap_(i | P i) A_ i <= B)%MS. Proof. by move=> Pi0; apply: submx_trans; rewrite (bigD1 i0) // capmxSl. Qed. Lemma sub_bigcapmxP P m n (A : 'M_(m, n)) (B_ : I -> 'M_n) : reflect (forall i, P i -> A <= B_ i)%MS (A <= \bigcap_(i | P i) B_ i)%MS. Proof. apply: (iffP idP) => [sAB i Pi | sAB]. by apply: (submx_trans sAB); rewrite (bigcapmx_inf Pi). by elim/big_rec: _ => [|i Pi C sAC]; rewrite ?submx1 // sub_capmx sAB. Qed. Lemma genmx_bigcap P n (A_ : I -> 'M_n) : (<<\bigcap_(i | P i) A_ i>> = \bigcap_(i | P i) <<A_ i>>)%MS. Proof. exact: (big_morph _ (@genmx_cap n n n) (@genmx1 n)). Qed. Lemma matrix_modl m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= C -> A + (B :&: C) :=: (A + B) :&: C)%MS. Proof. move=> sAC; set D := ((A + B) :&: C)%MS; apply/eqmxP. rewrite sub_capmx addsmxS ?capmxSl // addsmx_sub sAC capmxSr /=. have: (D <= B + A)%MS by rewrite addsmxC capmxSl. case/sub_addsmxP=> u defD; rewrite defD addrC addmx_sub_adds ?submxMl //. rewrite sub_capmx submxMl -[_ *m B](addrK (u.2 *m A)) -defD. by rewrite addmx_sub ?capmxSr // eqmx_opp mulmx_sub. Qed. Lemma matrix_modr m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (C <= A -> (A :&: B) + C :=: A :&: (B + C))%MS. Proof. by rewrite !(capmxC A) -!(addsmxC C); apply: matrix_modl. Qed. Lemma capmx_compl m n (A : 'M_(m, n)) : (A :&: A^C)%MS = 0. Proof. set D := (A :&: A^C)%MS; have: (D <= D)%MS by []. rewrite sub_capmx andbC => /andP[/submxP[B defB]]. rewrite submxE => /eqP; rewrite defB -!mulmxA mulKVmx ?copid_mx_id //. by rewrite mulmxA => ->; rewrite mul0mx. Qed. Lemma mxrank_mul_ker m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : (\rank (A *m B) + \rank (A :&: kermx B))%N = \rank A. Proof. apply/eqP; set K := kermx B; set C := (A :&: K)%MS. rewrite -(eqmxMr B (eq_row_base A)); set K' := _ *m B. rewrite -{2}(subnKC (rank_leq_row K')) -mxrank_ker eqn_add2l. rewrite -(mxrankMfree _ (row_base_free A)) mxrank_leqif_sup. by rewrite sub_capmx -(eq_row_base A) submxMl sub_kermx -mulmxA mulmx_ker/=. have /submxP[C' defC]: (C <= row_base A)%MS by rewrite eq_row_base capmxSl. by rewrite defC submxMr // sub_kermx mulmxA -defC -sub_kermx capmxSr. Qed. Lemma mxrank_injP m n p (A : 'M_(m, n)) (f : 'M_(n, p)) : reflect (\rank (A *m f) = \rank A) ((A :&: kermx f)%MS == 0). Proof. rewrite -mxrank_eq0 -(eqn_add2l (\rank (A *m f))). by rewrite mxrank_mul_ker addn0 eq_sym; apply: eqP. Qed. Lemma mxrank_disjoint_sum m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B)%MS = 0 -> \rank (A + B)%MS = (\rank A + \rank B)%N. Proof. move=> AB0; pose Ar := row_base A; pose Br := row_base B. have [Afree Bfree]: row_free Ar /\ row_free Br by rewrite !row_base_free. have: (Ar :&: Br <= A :&: B)%MS by rewrite capmxS ?eq_row_base. rewrite {}AB0 submx0 -mxrank_eq0 capmxE mxrankMfree //. set Cr := col_mx Ar Br; set Crl := lsubmx _; rewrite mxrank_eq0 => /eqP Crl0. rewrite -(adds_eqmx (eq_row_base _) (eq_row_base _)) addsmxE -/Cr. suffices K0: kermx Cr = 0. by apply/eqP; rewrite eqn_leq rank_leq_row -subn_eq0 -mxrank_ker K0 mxrank0. move/eqP: (mulmx_ker Cr); rewrite -[kermx Cr]hsubmxK mul_row_col -/Crl Crl0. rewrite mul0mx add0r -mxrank_eq0 mxrankMfree // mxrank_eq0 => /eqP->. exact: row_mx0. Qed. Lemma diffmxE m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :\: B :=: A :&: (capmx_gen A B)^C)%MS. Proof. by rewrite unlock; apply/eqmxP; rewrite !genmxE !capmxE andbb. Qed. Lemma genmx_diff m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (<<A :\: B>> = A :\: B)%MS. Proof. by rewrite [@diffmx]unlock genmx_id. Qed. Lemma diffmxSl m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :\: B <= A)%MS. Proof. by rewrite diffmxE capmxSl. Qed. Lemma capmx_diff m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : ((A :\: B) :&: B)%MS = 0. Proof. apply/eqP; pose C := capmx_gen A B; rewrite -submx0 -(capmx_compl C). by rewrite sub_capmx -capmxE sub_capmx andbAC -sub_capmx -diffmxE -sub_capmx. Qed. Lemma addsmx_diff_cap_eq m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :\: B + A :&: B :=: A)%MS. Proof. apply/eqmxP; rewrite addsmx_sub capmxSl diffmxSl /=. set C := (A :\: B)%MS; set D := capmx_gen A B. suffices sACD: (A <= C + D)%MS. by rewrite (submx_trans sACD) ?addsmxS ?capmxE. have:= addsmx_compl_full D; rewrite /row_full addsmxE. case/row_fullP=> U /(congr1 (mulmx A)); rewrite mulmx1. rewrite -[U]hsubmxK mul_row_col mulmxDr addrC 2!mulmxA. set V := _ *m _ => defA; rewrite -defA; move/(canRL (addrK _)): defA => defV. suffices /submxP[W ->]: (V <= C)%MS by rewrite -mul_row_col addsmxE submxMl. rewrite diffmxE sub_capmx {1}defV -mulNmx addmx_sub 1?mulmx_sub //. by rewrite -capmxE capmxSl. Qed. Lemma mxrank_cap_compl m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (\rank (A :&: B) + \rank (A :\: B))%N = \rank A. Proof. rewrite addnC -mxrank_disjoint_sum ?addsmx_diff_cap_eq //. by rewrite (capmxC A) capmxA capmx_diff cap0mx. Qed. Lemma mxrank_sum_cap m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (\rank (A + B) + \rank (A :&: B) = \rank A + \rank B)%N. Proof. set C := (A :&: B)%MS; set D := (A :\: B)%MS. have rDB: \rank (A + B)%MS = \rank (D + B)%MS. apply/eqP; rewrite mxrank_leqif_sup; first by rewrite addsmxS ?diffmxSl. by rewrite addsmx_sub addsmxSr -(addsmx_diff_cap_eq A B) addsmxS ?capmxSr. rewrite {1}rDB mxrank_disjoint_sum ?capmx_diff //. by rewrite addnC addnA mxrank_cap_compl. Qed. Lemma mxrank_adds_leqif m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : \rank (A + B) <= \rank A + \rank B ?= iff (A :&: B <= (0 : 'M_n))%MS. Proof. rewrite -mxrank_sum_cap; split; first exact: leq_addr. by rewrite addnC (@eqn_add2r _ 0) eq_sym mxrank_eq0 -submx0. Qed. (* rank of block matrices with 0s inside *) Lemma rank_col_mx0 m n p (A : 'M_(m, n)) : \rank (col_mx A (0 : 'M_(p, n))) = \rank A. Proof. by rewrite -addsmxE addsmx0. Qed. Lemma rank_col_0mx m n p (A : 'M_(m, n)) : \rank (col_mx (0 : 'M_(p, n)) A) = \rank A. Proof. by rewrite -addsmxE adds0mx. Qed. Lemma rank_row_mx0 m n p (A : 'M_(m, n)) : \rank (row_mx A (0 : 'M_(m, p))) = \rank A. Proof. by rewrite -mxrank_tr -[RHS]mxrank_tr tr_row_mx trmx0 rank_col_mx0. Qed. Lemma rank_row_0mx m n p (A : 'M_(m, n)) : \rank (row_mx (0 : 'M_(m, p)) A) = \rank A. Proof. by rewrite -mxrank_tr -[RHS]mxrank_tr tr_row_mx trmx0 rank_col_0mx. Qed. Lemma rank_diag_block_mx m n p q (A : 'M_(m, n)) (B : 'M_(p, q)) : \rank (block_mx A 0 0 B) = (\rank A + \rank B)%N. Proof. rewrite block_mxEv -addsmxE mxrank_disjoint_sum ?rank_row_mx0 ?rank_row_0mx//. apply/eqP/rowV0P => v; rewrite sub_capmx => /andP[/submxP[x ->]]. rewrite mul_mx_row mulmx0 => /submxP[y]; rewrite mul_mx_row mulmx0. by move=> /eq_row_mx[-> _]; rewrite row_mx0. Qed. (* Subspace projection matrix *) Lemma proj_mx_sub m n U V (W : 'M_(m, n)) : (W *m proj_mx U V <= U)%MS. Proof. by rewrite !mulmx_sub // -addsmxE addsmx0. Qed. Lemma proj_mx_compl_sub m n U V (W : 'M_(m, n)) : (W <= U + V -> W - W *m proj_mx U V <= V)%MS. Proof. rewrite addsmxE => sWUV; rewrite mulmxA -{1}(mulmxKpV sWUV) -mulmxBr. by rewrite mulmx_sub // opp_col_mx add_col_mx subrr subr0 -addsmxE adds0mx. Qed. Lemma proj_mx_id m n U V (W : 'M_(m, n)) : (U :&: V = 0)%MS -> (W <= U)%MS -> W *m proj_mx U V = W. Proof. move=> dxUV sWU; apply/eqP; rewrite -subr_eq0 -submx0 -dxUV. rewrite sub_capmx addmx_sub ?eqmx_opp ?proj_mx_sub //= -eqmx_opp opprB. by rewrite proj_mx_compl_sub // (submx_trans sWU) ?addsmxSl. Qed. Lemma proj_mx_0 m n U V (W : 'M_(m, n)) : (U :&: V = 0)%MS -> (W <= V)%MS -> W *m proj_mx U V = 0. Proof. move=> dxUV sWV; apply/eqP; rewrite -submx0 -dxUV. rewrite sub_capmx proj_mx_sub /= -[_ *m _](subrK W) addmx_sub // -eqmx_opp. by rewrite opprB proj_mx_compl_sub // (submx_trans sWV) ?addsmxSr. Qed. Lemma add_proj_mx m n U V (W : 'M_(m, n)) : (U :&: V = 0)%MS -> (W <= U + V)%MS -> W *m proj_mx U V + W *m proj_mx V U = W. Proof. move=> dxUV sWUV; apply/eqP; rewrite -subr_eq0 -submx0 -dxUV. rewrite -addrA sub_capmx {2}addrCA -!(opprB W). by rewrite !{1}addmx_sub ?proj_mx_sub ?eqmx_opp ?proj_mx_compl_sub // addsmxC. Qed. Lemma proj_mx_proj n (U V : 'M_n) : let P := proj_mx U V in (U :&: V = 0)%MS -> P *m P = P. Proof. by move=> P dxUV; rewrite -[P in P *m _]mul1mx proj_mx_id ?proj_mx_sub ?mul1mx. Qed. (* Completing a partially injective matrix to get a unit matrix. *) Lemma complete_unitmx m n (U : 'M_(m, n)) (f : 'M_n) : \rank (U *m f) = \rank U -> {g : 'M_n | g \in unitmx & U *m f = U *m g}. Proof. move=> injfU; pose V := <<U>>%MS; pose W := V *m f. pose g := proj_mx V (V^C)%MS *m f + cokermx V *m row_ebase W. have defW: V *m g = W. rewrite mulmxDr mulmxA proj_mx_id ?genmxE ?capmx_compl //. by rewrite mulmxA mulmx_coker mul0mx addr0. exists g; last first. have /submxP[u ->]: (U <= V)%MS by rewrite genmxE. by rewrite -!mulmxA defW. rewrite -row_full_unit -sub1mx; apply/submxP. have: (invmx (col_ebase W) *m W <= V *m g)%MS by rewrite defW submxMl. case/submxP=> v def_v; exists (invmx (row_ebase W) *m (v *m V + (V^C)%MS)). rewrite -mulmxA mulmxDl -mulmxA -def_v -{3}[W]mulmx_ebase -mulmxA. rewrite mulKmx ?col_ebase_unit // [_ *m g]mulmxDr mulmxA. rewrite (proj_mx_0 (capmx_compl _)) // mul0mx add0r 2!mulmxA. rewrite mulmxK ?row_ebase_unit // copid_mx_id ?rank_leq_row //. rewrite (eqmxMr _ (genmxE U)) injfU genmxE addrC -mulmxDl subrK. by rewrite mul1mx mulVmx ?row_ebase_unit. Qed. (* Two matrices with the same shape represent the same subspace *) (* iff they differ only by a change of basis. *) Lemma eqmxMunitP m n (U V : 'M_(m, n)) : reflect (exists2 P, P \in unitmx & U = P *m V) (U == V)%MS. Proof. apply: (iffP eqmxP) => [eqUV | [P Punit ->]]; last first. by apply/eqmxMfull; rewrite row_full_unit. have [D defU]: exists D, U = D *m V by apply/submxP; rewrite eqUV. have{eqUV} [Pt Pt_unit defUt]: {Pt | Pt \in unitmx & V^T *m D^T = V^T *m Pt}. by apply/complete_unitmx; rewrite -trmx_mul -defU !mxrank_tr eqUV. by exists Pt^T; last apply/trmx_inj; rewrite ?unitmx_tr // defU !trmx_mul trmxK. Qed. (* Mapping between two subspaces with the same dimension. *) Lemma eq_rank_unitmx m1 m2 n (U : 'M_(m1, n)) (V : 'M_(m2, n)) : \rank U = \rank V -> {f : 'M_n | f \in unitmx & V :=: U *m f}%MS. Proof. move=> eqrUV; pose f := invmx (row_ebase <<U>>%MS) *m row_ebase <<V>>%MS. have defUf: (<<U>> *m f :=: <<V>>)%MS. rewrite -[<<U>>%MS]mulmx_ebase mulmxA mulmxK ?row_ebase_unit // -mulmxA. rewrite genmxE eqrUV -genmxE -{3}[<<V>>%MS]mulmx_ebase -mulmxA. move: (pid_mx _ *m _) => W; apply/eqmxP. by rewrite !eqmxMfull ?andbb // row_full_unit col_ebase_unit. have{defUf} defV: (V :=: U *m f)%MS. by apply/eqmxP; rewrite -!(eqmxMr f (genmxE U)) !defUf !genmxE andbb. have injfU: \rank (U *m f) = \rank U by rewrite -defV eqrUV. by have [g injg defUg] := complete_unitmx injfU; exists g; rewrite -?defUg. Qed. (* maximal rank and full rank submatrices *) Section MaxRankSubMatrix. Variables (m n : nat) (A : 'M_(m, n)). Definition maxrankfun : 'I_m ^ \rank A := [arg max_(f > finfun (widen_ord (rank_leq_row A))) \rank (rowsub f A)]. Local Notation mxf := maxrankfun. Lemma maxrowsub_free : row_free (rowsub mxf A). Proof. rewrite /mxf; case: arg_maxnP => //= f _ fM; apply/negP => /negP rfA. have [i NriA] : exists i, ~~ (row i A <= rowsub f A)%MS. by apply/row_subPn; apply: contraNN rfA => /mxrankS; rewrite row_leq_rank. have [j rjfA] : exists j, (row (f j) A <= rowsub (f \o lift j) A)%MS. case/row_freePn: rfA => j. by rewrite row_rowsub row'Esub -mxsub_comp; exists j. pose g : 'I_m ^ \rank A := finfun [eta f with j |-> i]. suff: (rowsub f A < rowsub g A)%MS by rewrite ltmxErank andbC ltnNge fM. rewrite ltmxE; apply/andP; split; last first. apply: contra NriA; apply: submx_trans. by rewrite (eq_row_sub j)// row_rowsub ffunE/= eqxx. apply/row_subP => k; rewrite !row_rowsub. have [->|/negPf eq_kjF] := eqVneq k j; last first. by rewrite (eq_row_sub k)// row_rowsub ffunE/= eq_kjF. rewrite (submx_trans rjfA)// (submx_rowsub (lift j))// => l /=. by rewrite ffunE/= eq_sym (negPf (neq_lift _ _)). Qed. Lemma eq_maxrowsub : (rowsub mxf A :=: A)%MS. Proof. apply/eqmxP; rewrite -(eq_leqif (mxrank_leqif_eq _))//. exact: maxrowsub_free. apply/row_subP => i; apply/submxP; exists (delta_mx 0 (mxf i)). by rewrite -rowE; apply/rowP => j; rewrite !mxE. Qed. Lemma maxrankfun_inj : injective mxf. Proof. move=> i j eqAij; have /row_free_inj := maxrowsub_free. move=> /(_ 1) /(_ (delta_mx 0 i) (delta_mx 0 j)). rewrite -!rowE !row_rowsub eqAij => /(_ erefl) /matrixP /(_ 0 i) /eqP. by rewrite !mxE !eqxx/=; case: (i =P j); rewrite // oner_eq0. Qed. Variable (rkA : row_full A). Lemma maxrowsub_full : row_full (rowsub mxf A). Proof. by rewrite /row_full eq_maxrowsub. Qed. Hint Resolve maxrowsub_full : core. Definition fullrankfun : 'I_m ^ n := finfun (mxf \o cast_ord (esym (eqP rkA))). Local Notation frf := fullrankfun. Lemma fullrowsub_full : row_full (rowsub frf A). Proof. by rewrite mxsub_ffunl rowsub_comp rowsub_cast esymK row_full_castmx. Qed. Lemma fullrowsub_unit : rowsub frf A \in unitmx. Proof. by rewrite -row_full_unit fullrowsub_full. Qed. Lemma fullrowsub_free : row_free (rowsub frf A). Proof. by rewrite row_free_unit fullrowsub_unit. Qed. Lemma mxrank_fullrowsub : \rank (rowsub frf A) = n. Proof. exact/eqP/fullrowsub_full. Qed. Lemma eq_fullrowsub : (rowsub frf A :=: A)%MS. Proof. rewrite mxsub_ffunl rowsub_comp rowsub_cast esymK. exact: (eqmx_trans (eqmx_cast _ _) eq_maxrowsub). Qed. Lemma fullrankfun_inj : injective frf. Proof. by move=> i j; rewrite !ffunE => /maxrankfun_inj /(congr1 val)/= /val_inj. Qed. End MaxRankSubMatrix. Section SumExpr. (* This is the infrastructure to support the mxdirect predicate. We use a *) (* bespoke canonical structure to decompose a matrix expression into binary *) (* and n-ary products, using some of the "quote" technology. This lets us *) (* characterize direct sums as set sums whose rank is equal to the sum of the *) (* ranks of the individual terms. The mxsum_expr/proper_mxsum_expr structures *) (* below supply both the decomposition and the calculation of the rank sum. *) (* The mxsum_spec dependent predicate family expresses the consistency of *) (* these two decompositions. *) (* The main technical difficulty we need to overcome is the fact that *) (* the "catch-all" case of canonical structures has a priority lower than *) (* constant expansion. However, it is undesirable that local abbreviations *) (* be opaque for the direct-sum predicate, e.g., not be able to handle *) (* let S := (\sum_(i | P i) LargeExpression i)%MS in mxdirect S -> ...). *) (* As in "quote", we use the interleaving of constant expansion and *) (* canonical projection matching to achieve our goal: we use a "wrapper" type *) (* (indeed, the wrapped T type defined in ssrfun.v) with a self-inserting *) (* non-primitive constructor to gain finer control over the type and *) (* structure inference process. The innermost, primitive, constructor flags *) (* trivial sums; it is initially hidden by an eta-expansion, which has been *) (* made into a (default) canonical structure -- this lets type inference *) (* automatically insert this outer tag. *) (* In detail, we define three types *) (* mxsum_spec S r <-> There exists a finite list of matrices A1, ..., Ak *) (* such that S is the set sum of the Ai, and r is the sum *) (* of the ranks of the Ai, i.e., S = (A1 + ... + Ak)%MS *) (* and r = \rank A1 + ... + \rank Ak. Note that *) (* mxsum_spec is a recursive dependent predicate family *) (* whose elimination rewrites simultaneaously S, r and *) (* the height of S. *) (* proper_mxsum_expr n == The interface for proper sum expressions; this is *) (* a double-entry interface, keyed on both the matrix sum *) (* value and the rank sum. The matrix value is restricted *) (* to square matrices, as the "+"%MS operator always *) (* returns a square matrix. This interface has two *) (* canonical instances, for binary and n-ary sums. *) (* mxsum_expr m n == The interface for general sum expressions, comprising *) (* both proper sums and trivial sums consisting of a *) (* single matrix. The key values are WRAPPED as this lets *) (* us give priority to the "proper sum" interpretation *) (* (see below). To allow for trivial sums, the matrix key *) (* can have any dimension. The mxsum_expr interface has *) (* two canonical instances, for trivial and proper sums, *) (* keyed to the Wrap and wrap constructors, respectively. *) (* The projections for the two interfaces above are *) (* proper_mxsum_val, mxsum_val : these are respectively coercions to 'M_n *) (* and wrapped 'M_(m, n); thus, the matrix sum for an *) (* S : mxsum_expr m n can be written unwrap S. *) (* proper_mxsum_rank, mxsum_rank : projections to the nat and wrapped nat, *) (* respectively; the rank sum for S : mxsum_expr m n is *) (* thus written unwrap (mxsum_rank S). *) (* The mxdirect A predicate actually gets A in a phantom argument, which is *) (* used to infer an (implicit) S : mxsum_expr such that unwrap S = A; the *) (* actual definition is \rank (unwrap S) == unwrap (mxsum_rank S). *) (* Note that the inference of S is inherently ambiguous: ANY matrix can be *) (* viewed as a trivial sum, including one whose description is manifestly a *) (* proper sum. We use the wrapped type and the interaction between delta *) (* reduction and canonical structure inference to resolve this ambiguity in *) (* favor of proper sums, as follows: *) (* - The phantom type sets up a unification problem of the form *) (* unwrap (mxsum_val ?S) = A *) (* with unknown evar ?S : mxsum_expr m n. *) (* - As the constructor wrap is also a default Canonical instance for the *) (* wrapped type, so A is immediately replaced with unwrap (wrap A) and *) (* we get the residual unification problem *) (* mxsum_val ?S = wrap A *) (* - Now Coq tries to apply the proper sum Canonical instance, which has *) (* key projection wrap (proper_mxsum_val ?PS) where ?PS is a fresh evar *) (* (of type proper_mxsum_expr n). This can only succeed if m = n, and if *) (* a solution can be found to the recursive unification problem *) (* proper_mxsum_val ?PS = A *) (* This causes Coq to look for one of the two canonical constants for *) (* proper_mxsum_val (addsmx or bigop) at the head of A, delta-expanding *) (* A as needed, and then inferring recursively mxsum_expr structures for *) (* the last argument(s) of that constant. *) (* - If the above step fails then the wrap constant is expanded, revealing *) (* the primitive Wrap constructor; the unification problem now becomes *) (* mxsum_val ?S = Wrap A *) (* which fits perfectly the trivial sum canonical structure, whose key *) (* projection is Wrap ?B where ?B is a fresh evar. Thus the inference *) (* succeeds, and returns the trivial sum. *) (* Note that the rank projections also register canonical values, so that the *) (* same process can be used to infer a sum structure from the rank sum. In *) (* that case, however, there is no ambiguity and the inference can fail, *) (* because the rank sum for a trivial sum is not an arbitrary integer -- it *) (* must be of the form \rank ?B. It is nevertheless necessary to use the *) (* wrapped nat type for the rank sums, because in the non-trivial case the *) (* head constant of the nat expression is determined by the proper_mxsum_expr *) (* canonical structure, so the mxsum_expr structure must use a generic *) (* constant, namely wrap. *) Inductive mxsum_spec n : forall m, 'M[F]_(m, n) -> nat -> Prop := | TrivialMxsum m A : @mxsum_spec n m A (\rank A) | ProperMxsum m1 m2 T1 T2 r1 r2 of @mxsum_spec n m1 T1 r1 & @mxsum_spec n m2 T2 r2 : mxsum_spec (T1 + T2)%MS (r1 + r2)%N. Arguments mxsum_spec {n%_N m%_N} T%_MS r%_N. Structure mxsum_expr m n := Mxsum { mxsum_val :> wrapped 'M_(m, n); mxsum_rank : wrapped nat; _ : mxsum_spec (unwrap mxsum_val) (unwrap mxsum_rank) }. Canonical trivial_mxsum m n A := @Mxsum m n (Wrap A) (Wrap (\rank A)) (TrivialMxsum A). Structure proper_mxsum_expr n := ProperMxsumExpr { proper_mxsum_val :> 'M_n; proper_mxsum_rank : nat; _ : mxsum_spec proper_mxsum_val proper_mxsum_rank }. Definition proper_mxsumP n (S : proper_mxsum_expr n) := let: ProperMxsumExpr _ _ termS := S return mxsum_spec S (proper_mxsum_rank S) in termS. Canonical sum_mxsum n (S : proper_mxsum_expr n) := @Mxsum n n (wrap (S : 'M_n)) (wrap (proper_mxsum_rank S)) (proper_mxsumP S). Section Binary. Variable (m1 m2 n : nat) (S1 : mxsum_expr m1 n) (S2 : mxsum_expr m2 n). Fact binary_mxsum_proof : mxsum_spec (unwrap S1 + unwrap S2) (unwrap (mxsum_rank S1) + unwrap (mxsum_rank S2)). Proof. by case: S1 S2 => [A1 r1 A1P] [A2 r2 A2P]; right. Qed. Canonical binary_mxsum_expr := ProperMxsumExpr binary_mxsum_proof. End Binary. Section Nary. Context J (r : seq J) (P : pred J) n (S_ : J -> mxsum_expr n n). Fact nary_mxsum_proof : mxsum_spec (\sum_(j <- r | P j) unwrap (S_ j)) (\sum_(j <- r | P j) unwrap (mxsum_rank (S_ j))). Proof. elim/big_rec2: _ => [|j]; first by rewrite -(mxrank0 n n); left. by case: (S_ j); right. Qed. Canonical nary_mxsum_expr := ProperMxsumExpr nary_mxsum_proof. End Nary. Definition mxdirect_def m n T of phantom 'M_(m, n) (unwrap (mxsum_val T)) := \rank (unwrap T) == unwrap (mxsum_rank T). End SumExpr. Notation mxdirect A := (mxdirect_def (Phantom 'M_(_,_) A%MS)). Lemma mxdirectP n (S : proper_mxsum_expr n) : reflect (\rank S = proper_mxsum_rank S) (mxdirect S). Proof. exact: eqnP. Qed. Arguments mxdirectP {n S}. Lemma mxdirect_trivial m n A : mxdirect (unwrap (@trivial_mxsum m n A)). Proof. exact: eqxx. Qed. Lemma mxrank_sum_leqif m n (S : mxsum_expr m n) : \rank (unwrap S) <= unwrap (mxsum_rank S) ?= iff mxdirect (unwrap S). Proof. rewrite /mxdirect_def; case: S => [[A] [r] /= defAr]; split=> //=. elim: m A r / defAr => // m1 m2 A1 A2 r1 r2 _ leAr1 _ leAr2. by apply: leq_trans (leq_add leAr1 leAr2); rewrite mxrank_adds_leqif. Qed. Lemma mxdirectE m n (S : mxsum_expr m n) : mxdirect (unwrap S) = (\rank (unwrap S) == unwrap (mxsum_rank S)). Proof. by []. Qed. Lemma mxdirectEgeq m n (S : mxsum_expr m n) : mxdirect (unwrap S) = (\rank (unwrap S) >= unwrap (mxsum_rank S)). Proof. by rewrite (geq_leqif (mxrank_sum_leqif S)). Qed. Section BinaryDirect. Variables m1 m2 n : nat. Lemma mxdirect_addsE (S1 : mxsum_expr m1 n) (S2 : mxsum_expr m2 n) : mxdirect (unwrap S1 + unwrap S2) = [&& mxdirect (unwrap S1), mxdirect (unwrap S2) & unwrap S1 :&: unwrap S2 == 0]%MS. Proof. rewrite (@mxdirectE n) /=. have:= leqif_add (mxrank_sum_leqif S1) (mxrank_sum_leqif S2). move/(leqif_trans (mxrank_adds_leqif (unwrap S1) (unwrap S2)))=> ->. by rewrite andbC -andbA submx0. Qed. Lemma mxdirect_addsP (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :&: B = 0)%MS (mxdirect (A + B)). Proof. by rewrite mxdirect_addsE !mxdirect_trivial; apply: eqP. Qed. End BinaryDirect. Section NaryDirect. Variables (P : pred I) (n : nat). Let TIsum A_ i := (A_ i :&: (\sum_(j | P j && (j != i)) A_ j) = 0 :> 'M_n)%MS. Let mxdirect_sums_recP (S_ : I -> mxsum_expr n n) : reflect (forall i, P i -> mxdirect (unwrap (S_ i)) /\ TIsum (unwrap \o S_) i) (mxdirect (\sum_(i | P i) (unwrap (S_ i)))). Proof. rewrite /TIsum; apply: (iffP eqnP) => /= [dxS i Pi | dxS]. set Si' := (\sum_(j | _) unwrap (S_ j))%MS. have: mxdirect (unwrap (S_ i) + Si') by apply/eqnP; rewrite /= -!(bigD1 i). by rewrite mxdirect_addsE => /and3P[-> _ /eqP]. set Q := P; have [m] := ubnP #|Q|; have: Q \subset P by []. elim: m Q => // m IHm Q /subsetP-sQP. case: (pickP Q) => [i Qi | Q0]; last by rewrite !big_pred0 ?mxrank0. rewrite (cardD1x Qi) !((bigD1 i) Q) //=. move/IHm=> <- {IHm}/=; last by apply/subsetP=> j /andP[/sQP]. case: (dxS i (sQP i Qi)) => /eqnP=> <- TiQ_0; rewrite mxrank_disjoint_sum //. apply/eqP; rewrite -submx0 -{2}TiQ_0 capmxS //=. by apply/sumsmx_subP=> j /= /andP[Qj i'j]; rewrite (sumsmx_sup j) ?[P j]sQP. Qed. Lemma mxdirect_sumsP (A_ : I -> 'M_n) : reflect (forall i, P i -> A_ i :&: (\sum_(j | P j && (j != i)) A_ j) = 0)%MS (mxdirect (\sum_(i | P i) A_ i)). Proof. apply: (iffP (mxdirect_sums_recP _)) => dxA i /dxA; first by case. by rewrite mxdirect_trivial. Qed. Lemma mxdirect_sumsE (S_ : I -> mxsum_expr n n) (xunwrap := unwrap) : reflect (and (forall i, P i -> mxdirect (unwrap (S_ i))) (mxdirect (\sum_(i | P i) (xunwrap (S_ i))))) (mxdirect (\sum_(i | P i) (unwrap (S_ i)))). Proof. apply: (iffP (mxdirect_sums_recP _)) => [dxS | [dxS_ dxS] i Pi]. by do [split; last apply/mxdirect_sumsP] => i; case/dxS. by split; [apply: dxS_ | apply: mxdirect_sumsP Pi]. Qed. End NaryDirect. Section SubDaddsmx. Variables m m1 m2 n : nat. Variables (A : 'M[F]_(m, n)) (B1 : 'M[F]_(m1, n)) (B2 : 'M[F]_(m2, n)). Variant sub_daddsmx_spec : Prop := SubDaddsmxSpec A1 A2 of (A1 <= B1)%MS & (A2 <= B2)%MS & A = A1 + A2 & forall C1 C2, (C1 <= B1)%MS -> (C2 <= B2)%MS -> A = C1 + C2 -> C1 = A1 /\ C2 = A2. Lemma sub_daddsmx : (B1 :&: B2 = 0)%MS -> (A <= B1 + B2)%MS -> sub_daddsmx_spec. Proof. move=> dxB /sub_addsmxP[u defA]. exists (u.1 *m B1) (u.2 *m B2); rewrite ?submxMl // => C1 C2 sCB1 sCB2. move/(canLR (addrK _)) => defC1. suffices: (C2 - u.2 *m B2 <= B1 :&: B2)%MS. by rewrite dxB submx0 subr_eq0 -defC1 defA; move/eqP->; rewrite addrK. rewrite sub_capmx -opprB -{1}(canLR (addKr _) defA) -addrA defC1. by rewrite !(eqmx_opp, addmx_sub) ?submxMl. Qed. End SubDaddsmx. Section SubDsumsmx. Variables (P : pred I) (m n : nat) (A : 'M[F]_(m, n)) (B : I -> 'M[F]_n). Variant sub_dsumsmx_spec : Prop := SubDsumsmxSpec A_ of forall i, P i -> (A_ i <= B i)%MS & A = \sum_(i | P i) A_ i & forall C, (forall i, P i -> C i <= B i)%MS -> A = \sum_(i | P i) C i -> {in SimplPred P, C =1 A_}. Lemma sub_dsumsmx : mxdirect (\sum_(i | P i) B i) -> (A <= \sum_(i | P i) B i)%MS -> sub_dsumsmx_spec. Proof. move/mxdirect_sumsP=> dxB /sub_sumsmxP[u defA]. pose A_ i := u i *m B i. exists A_ => //= [i _ | C sCB defAC i Pi]; first exact: submxMl. apply/eqP; rewrite -subr_eq0 -submx0 -{dxB}(dxB i Pi) /=. rewrite sub_capmx addmx_sub ?eqmx_opp ?submxMl ?sCB //=. rewrite -(subrK A (C i)) -addrA -opprB addmx_sub ?eqmx_opp //. rewrite addrC defAC (bigD1 i) // addKr /= summx_sub // => j Pi'j. by rewrite (sumsmx_sup j) ?sCB //; case/andP: Pi'j. rewrite addrC defA (bigD1 i) // addKr /= summx_sub // => j Pi'j. by rewrite (sumsmx_sup j) ?submxMl. Qed. End SubDsumsmx. Section Eigenspace. Variables (n : nat) (g : 'M_n). Definition eigenspace a := kermx (g - a%:M). Definition eigenvalue : pred F := fun a => eigenspace a != 0. Lemma eigenspaceP a m (W : 'M_(m, n)) : reflect (W *m g = a *: W) (W <= eigenspace a)%MS. Proof. by rewrite sub_kermx mulmxBr subr_eq0 mul_mx_scalar; apply/eqP. Qed. Lemma eigenvalueP a : reflect (exists2 v : 'rV_n, v *m g = a *: v & v != 0) (eigenvalue a). Proof. by apply: (iffP (rowV0Pn _)) => [] [v]; move/eigenspaceP; exists v. Qed. Notation stablemx V f := (V%MS *m f%R <= V%MS)%MS. Lemma eigenvectorP {v : 'rV_n} : reflect (exists a, (v <= eigenspace a)%MS) (stablemx v g). Proof. by apply: (iffP (sub_rVP _ _)) => -[a] /eigenspaceP; exists a. Qed. Lemma mxdirect_sum_eigenspace (P : pred I) a_ : {in P &, injective a_} -> mxdirect (\sum_(i | P i) eigenspace (a_ i)). Proof. have [m] := ubnP #|P|; elim: m P => // m IHm P lePm inj_a. apply/mxdirect_sumsP=> i Pi; apply/eqP/rowV0P => v. rewrite sub_capmx => /andP[/eigenspaceP def_vg]. set Vi' := (\sum_(i | _) _)%MS => Vi'v. have dxVi': mxdirect Vi'. rewrite (cardD1x Pi) in lePm; apply: IHm => //. by apply: sub_in2 inj_a => j /andP[]. case/sub_dsumsmx: Vi'v => // u Vi'u def_v _. rewrite def_v big1 // => j Pi'j; apply/eqP. have nz_aij: a_ i - a_ j != 0. by case/andP: Pi'j => Pj ne_ji; rewrite subr_eq0 eq_sym (inj_in_eq inj_a). case: (sub_dsumsmx dxVi' (sub0mx 1 _)) => C _ _ uniqC. rewrite -(eqmx_eq0 (eqmx_scale _ nz_aij)). rewrite (uniqC (fun k => (a_ i - a_ k) *: u k)) => // [|k Pi'k|]. - by rewrite -(uniqC (fun _ => 0)) ?big1 // => k Pi'k; apply: sub0mx. - by rewrite scalemx_sub ?Vi'u. rewrite -{1}(subrr (v *m g)) {1}def_vg def_v scaler_sumr mulmx_suml -sumrB. by apply: eq_bigr => k /Vi'u/eigenspaceP->; rewrite scalerBl. Qed. End Eigenspace. End RowSpaceTheory. #[global] Hint Resolve submx_refl : core. Arguments submxP {F m1 m2 n A B}. Arguments eq_row_sub [F m n v A]. Arguments row_subP {F m1 m2 n A B}. Arguments rV_subP {F m1 m2 n A B}. Arguments row_subPn {F m1 m2 n A B}. Arguments sub_rVP {F n u v}. Arguments rV_eqP {F m1 m2 n A B}. Arguments rowV0Pn {F m n A}. Arguments rowV0P {F m n A}. Arguments eqmx0P {F m n A}. Arguments row_fullP {F m n A}. Arguments row_freeP {F m n A}. Arguments eqmxP {F m1 m2 n A B}. Arguments genmxP {F m1 m2 n A B}. Arguments addsmx_idPr {F m1 m2 n A B}. Arguments addsmx_idPl {F m1 m2 n A B}. Arguments sub_addsmxP {F m1 m2 m3 n A B C}. Arguments sumsmx_sup [F I] i0 [P m n A B_]. Arguments sumsmx_subP {F I P m n A_ B}. Arguments sub_sumsmxP {F I P m n A B_}. Arguments sub_kermxP {F p m n A B}. Arguments capmx_idPr {F n m1 m2 A B}. Arguments capmx_idPl {F n m1 m2 A B}. Arguments bigcapmx_inf [F I] i0 [P m n A_ B]. Arguments sub_bigcapmxP {F I P m n A B_}. Arguments mxrank_injP {F m n} p {A f}. Arguments mxdirectP {F n S}. Arguments mxdirect_addsP {F m1 m2 n A B}. Arguments mxdirect_sumsP {F I P n A_}. Arguments mxdirect_sumsE {F I P n S_}. Arguments eigenspaceP {F n g a m W}. Arguments eigenvalueP {F n g a}. Arguments submx_rowsub [F m1 m2 m3 n] h [f g A] _ : rename. Arguments eqmx_rowsub [F m1 m2 m3 n] h [f g A] _ : rename. Arguments mxrank {F m%_N n%_N} A%_MS. Arguments complmx {F m%_N n%_N} A%_MS. Arguments row_full {F m%_N n%_N} A%_MS. Arguments submx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments ltmx {F m1%_N m2%_N n%_N} A%_MS B%_MS. Arguments eqmx {F m1%_N m2%_N n%_N} A%_MS B%_MS. Arguments addsmx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments capmx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments diffmx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments genmx {F m%_N n%_N} A%_R : rename. Notation "\rank A" := (mxrank A) : nat_scope. Notation "<< A >>" := (genmx A) : matrix_set_scope. Notation "A ^C" := (complmx A) : matrix_set_scope. Notation "A <= B" := (submx A B) : matrix_set_scope. Notation "A < B" := (ltmx A B) : matrix_set_scope. Notation "A <= B <= C" := ((submx A B) && (submx B C)) : matrix_set_scope. Notation "A < B <= C" := (ltmx A B && submx B C) : matrix_set_scope. Notation "A <= B < C" := (submx A B && ltmx B C) : matrix_set_scope. Notation "A < B < C" := (ltmx A B && ltmx B C) : matrix_set_scope. Notation "A == B" := ((submx A B) && (submx B A)) : matrix_set_scope. Notation "A :=: B" := (eqmx A B) : matrix_set_scope. Notation "A + B" := (addsmx A B) : matrix_set_scope. Notation "A :&: B" := (capmx A B) : matrix_set_scope. Notation "A :\: B" := (diffmx A B) : matrix_set_scope. Notation mxdirect S := (mxdirect_def (Phantom 'M_(_,_) S%MS)). Notation "\sum_ ( i <- r | P ) B" := (\big[addsmx/0%R]_(i <- r | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( i <- r ) B" := (\big[addsmx/0%R]_(i <- r) B%MS) : matrix_set_scope. Notation "\sum_ ( m <= i < n | P ) B" := (\big[addsmx/0%R]_(m <= i < n | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( m <= i < n ) B" := (\big[addsmx/0%R]_(m <= i < n) B%MS) : matrix_set_scope. Notation "\sum_ ( i | P ) B" := (\big[addsmx/0%R]_(i | P%B) B%MS) : matrix_set_scope. Notation "\sum_ i B" := (\big[addsmx/0%R]_i B%MS) : matrix_set_scope. Notation "\sum_ ( i : t | P ) B" := (\big[addsmx/0%R]_(i : t | P%B) B%MS) (only parsing) : matrix_set_scope. Notation "\sum_ ( i : t ) B" := (\big[addsmx/0%R]_(i : t) B%MS) (only parsing) : matrix_set_scope. Notation "\sum_ ( i < n | P ) B" := (\big[addsmx/0%R]_(i < n | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( i < n ) B" := (\big[addsmx/0%R]_(i < n) B%MS) : matrix_set_scope. Notation "\sum_ ( i 'in' A | P ) B" := (\big[addsmx/0%R]_(i in A | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( i 'in' A ) B" := (\big[addsmx/0%R]_(i in A) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i <- r | P ) B" := (\big[capmx/1%:M]_(i <- r | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i <- r ) B" := (\big[capmx/1%:M]_(i <- r) B%MS) : matrix_set_scope. Notation "\bigcap_ ( m <= i < n | P ) B" := (\big[capmx/1%:M]_(m <= i < n | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( m <= i < n ) B" := (\big[capmx/1%:M]_(m <= i < n) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i | P ) B" := (\big[capmx/1%:M]_(i | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ i B" := (\big[capmx/1%:M]_i B%MS) : matrix_set_scope. Notation "\bigcap_ ( i : t | P ) B" := (\big[capmx/1%:M]_(i : t | P%B) B%MS) (only parsing) : matrix_set_scope. Notation "\bigcap_ ( i : t ) B" := (\big[capmx/1%:M]_(i : t) B%MS) (only parsing) : matrix_set_scope. Notation "\bigcap_ ( i < n | P ) B" := (\big[capmx/1%:M]_(i < n | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i < n ) B" := (\big[capmx/1%:M]_(i < n) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i 'in' A | P ) B" := (\big[capmx/1%:M]_(i in A | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i 'in' A ) B" := (\big[capmx/1%:M]_(i in A) B%MS) : matrix_set_scope. Section Stability. Variable (F : fieldType). Lemma eqmx_stable m m' n (V : 'M[F]_(m, n)) (V' : 'M[F]_(m', n)) (f : 'M[F]_n) : (V :=: V')%MS -> stablemx V f = stablemx V' f. Proof. by move=> eqVV'; rewrite (eqmxMr _ eqVV') eqVV'. Qed. Section FixedDim. Variables (m n : nat) (V W : 'M[F]_(m, n)) (f g : 'M[F]_n). Lemma stablemx_row_base : (stablemx (row_base V) f) = (stablemx V f). Proof. by apply: eqmx_stable; apply: eq_row_base. Qed. Lemma stablemx_full : row_full V -> stablemx V f. Proof. exact: submx_full. Qed. Lemma stablemxM : stablemx V f -> stablemx V g -> stablemx V (f *m g). Proof. by move=> f_stab /(submx_trans _)->//; rewrite mulmxA submxMr. Qed. Lemma stablemxD : stablemx V f -> stablemx V g -> stablemx V (f + g). Proof. by move=> f_stab g_stab; rewrite mulmxDr addmx_sub. Qed. Lemma stablemxN : stablemx V (- f) = stablemx V f. Proof. by rewrite mulmxN eqmx_opp. Qed. Lemma stablemxC x : stablemx V x%:M. Proof. by rewrite mul_mx_scalar scalemx_sub. Qed. Lemma stablemx0 : stablemx V 0. Proof. by rewrite mulmx0 sub0mx. Qed. Lemma stableDmx : stablemx V f -> stablemx W f -> stablemx (V + W)%MS f. Proof. by move=> fV fW; rewrite addsmxMr addsmxS. Qed. Lemma stableNmx : stablemx (- V) f = stablemx V f. Proof. by rewrite mulNmx !eqmx_opp. Qed. Lemma stable0mx : stablemx (0 : 'M_(m, n)) f. Proof. by rewrite mul0mx. Qed. End FixedDim. Lemma stableCmx (m n : nat) x (f : 'M[F]_(m, n)) : stablemx x%:M f. Proof. have [->|x_neq0] := eqVneq x 0; first by rewrite mul_scalar_mx scale0r sub0mx. by rewrite -![x%:M]scalemx1 eqmx_scale// submx_full// -sub1mx. Qed. Lemma stablemx_sums (n : nat) (I : finType) (V_ : I -> 'M[F]_n) (f : 'M_n) : (forall i, stablemx (V_ i) f) -> stablemx (\sum_i V_ i)%MS f. Proof. by move=> fV; rewrite sumsmxMr; apply/sumsmx_subP => i; rewrite (sumsmx_sup i). Qed. Lemma stablemx_unit (n : nat) (V f : 'M[F]_n) : V \in unitmx -> stablemx V f. Proof. by move=> Vunit; rewrite submx_full ?row_full_unit. Qed. Section Commutation. Variable (n : nat). Implicit Types (f g : 'M[F]_n). Lemma comm_mx_stable (f g : 'M[F]_n) : comm_mx f g -> stablemx f g. Proof. by move=> comm_fg; rewrite [_ *m _]comm_fg mulmx_sub. Qed. Lemma comm_mx_stable_ker (f g : 'M[F]_n) : comm_mx f g -> stablemx (kermx f) g. Proof. move=> comm_fg; apply/sub_kermxP. by rewrite -mulmxA -[g *m _]comm_fg mulmxA mulmx_ker mul0mx. Qed. Lemma comm_mx_stable_eigenspace (f g : 'M[F]_n) a : comm_mx f g -> stablemx (eigenspace f a) g. Proof. move=> cfg; rewrite comm_mx_stable_ker//. by apply/comm_mx_sym/comm_mxB => //; apply:comm_mx_scalar. Qed. End Commutation. End Stability. Section DirectSums. Variables (F : fieldType) (I : finType) (P : pred I). Lemma mxdirect_delta n f : {in P &, injective f} -> mxdirect (\sum_(i | P i) <<delta_mx 0 (f i) : 'rV[F]_n>>). Proof. pose fP := image f P => Uf; have UfP: uniq fP by apply/dinjectiveP. suffices /mxdirectP : mxdirect (\sum_i <<delta_mx 0 i : 'rV[F]_n>>). rewrite /= !(bigID [in fP] predT) -!big_uniq //= !big_map !big_enum. by move/mxdirectP; rewrite mxdirect_addsE => /andP[]. apply/mxdirectP=> /=; transitivity (mxrank (1%:M : 'M[F]_n)). apply/eqmx_rank; rewrite submx1 mx1_sum_delta summx_sub_sums // => i _. by rewrite -(mul_delta_mx (0 : 'I_1)) genmxE submxMl. rewrite mxrank1 -[LHS]card_ord -sum1_card. by apply/eq_bigr=> i _; rewrite /= mxrank_gen mxrank_delta. Qed. End DirectSums. Section CardGL. Variable F : finFieldType. Lemma card_GL n : n > 0 -> #|'GL_n[F]| = (#|F| ^ 'C(n, 2) * \prod_(1 <= i < n.+1) (#|F| ^ i - 1))%N. Proof. case: n => // n' _; set n := n'.+1; set p := #|F|. rewrite big_nat_rev big_add1 -bin2_sum expn_sum -big_split /=. pose fr m := [pred A : 'M[F]_(m, n) | \rank A == m]. set m := n; rewrite [in m.+1]/m; transitivity #|fr m|. by rewrite cardsT /= card_sub; apply: eq_card => A; rewrite -row_free_unit. have: m <= n by []; elim: m => [_ | m IHm /ltnW-le_mn]. rewrite (@eq_card1 _ (0 : 'M_(0, n))) ?big_geq //= => A. by rewrite flatmx0 !inE mxrank.unlock !eqxx. rewrite big_nat_recr // -{}IHm //= !subSS mulnBr muln1 -expnD subnKC //. rewrite -sum_nat_const /= -sum1_card -add1n. rewrite (partition_big dsubmx (fr m)) /= => [|A]; last first. rewrite !inE -{1}(vsubmxK A); move: {A}(_ A) (_ A) => Ad Au Afull. rewrite eqn_leq rank_leq_row -(leq_add2l (\rank Au)) -mxrank_sum_cap. rewrite {1 3}[@mxrank]lock addsmxE (eqnP Afull) -lock -addnA. by rewrite leq_add ?rank_leq_row ?leq_addr. apply: eq_bigr => A rAm; rewrite (reindex (col_mx^~ A)) /=; last first. exists usubmx => [v _ | vA]; first by rewrite col_mxKu. by case/andP=> _ /eqP <-; rewrite vsubmxK. transitivity #|~: [set v *m A | v in 'rV_m]|; last first. rewrite cardsCs setCK card_imset ?card_mx ?card_ord ?mul1n //. have [B AB1] := row_freeP rAm; apply: can_inj (mulmx^~ B) _ => v. by rewrite -mulmxA AB1 mulmx1. rewrite -sum1_card; apply: eq_bigl => v; rewrite !inE col_mxKd eqxx. rewrite andbT eqn_leq rank_leq_row /= -(leq_add2r (\rank (v :&: A)%MS)). rewrite -addsmxE mxrank_sum_cap (eqnP rAm) addnAC leq_add2r. rewrite (ltn_leqif (mxrank_leqif_sup _)) ?capmxSl // sub_capmx submx_refl. by congr (~~ _); apply/submxP/imsetP=> [] [u]; exists u. Qed. (* An alternate, somewhat more elementary proof, that does not rely on the *) (* row-space theory, but directly performs the LUP decomposition. *) Lemma LUP_card_GL n : n > 0 -> #|'GL_n[F]| = (#|F| ^ 'C(n, 2) * \prod_(1 <= i < n.+1) (#|F| ^ i - 1))%N. Proof. case: n => // n' _; set n := n'.+1; set p := #|F|. rewrite cardsT /= card_sub /GRing.unit /= big_add1 /= -bin2_sum -/n /=. elim: {n'}n => [|n IHn]. rewrite !big_geq // mul1n (@eq_card _ _ predT) ?card_mx //= => M. by rewrite {1}[M]flatmx0 -(flatmx0 1%:M) unitmx1. rewrite !big_nat_recr //= expnD mulnAC mulnA -{}IHn -mulnA mulnC. set LHS := #|_|; rewrite -[n.+1]muln1 -{2}[n]mul1n {}/LHS. rewrite -!card_mx subn1 -(cardC1 0) -mulnA; set nzC := predC1 _. rewrite -sum1_card (partition_big lsubmx nzC) => [|A]; last first. rewrite unitmxE unitfE; apply: contra; move/eqP=> v0. rewrite -[A]hsubmxK v0 -[n.+1]/(1 + n)%N -col_mx0. rewrite -[rsubmx _]vsubmxK -det_tr tr_row_mx !tr_col_mx !trmx0. by rewrite det_lblock [0]mx11_scalar det_scalar1 mxE mul0r. rewrite -sum_nat_const; apply: eq_bigr => /= v /cV0Pn[k nza]. have xrkK: involutive (@xrow F _ _ 0 k). by move=> m A /=; rewrite /xrow -row_permM tperm2 row_perm1. rewrite (reindex_inj (inv_inj (xrkK (1 + n)%N))) /= -[n.+1]/(1 + n)%N. rewrite (partition_big ursubmx xpredT) //= -sum_nat_const. apply: eq_bigr => u _; set a : F := v _ _ in nza. set v1 : 'cV_(1 + n) := xrow 0 k v. have def_a: usubmx v1 = a%:M. by rewrite [_ v1]mx11_scalar mxE lshift0 mxE tpermL. pose Schur := dsubmx v1 *m (a^-1 *: u). pose L : 'M_(1 + n) := block_mx a%:M 0 (dsubmx v1) 1%:M. pose U B : 'M_(1 + n) := block_mx 1 (a^-1 *: u) 0 B. rewrite (reindex (fun B => L *m U B)); last first. exists (fun A1 => drsubmx A1 - Schur) => [B _ | A1]. by rewrite mulmx_block block_mxKdr mul1mx addrC addKr. rewrite !inE mulmx_block !mulmx0 mul0mx !mulmx1 !addr0 mul1mx addrC subrK. rewrite mul_scalar_mx scalerA divff // scale1r andbC; case/and3P => /eqP <- _. rewrite -{1}(hsubmxK A1) xrowE mul_mx_row row_mxKl -xrowE => /eqP def_v. rewrite -def_a block_mxEh vsubmxK /v1 -def_v xrkK. apply: trmx_inj; rewrite tr_row_mx tr_col_mx trmx_ursub trmx_drsub trmx_lsub. by rewrite hsubmxK vsubmxK. rewrite -sum1_card; apply: eq_bigl => B; rewrite xrowE unitmxE. rewrite !det_mulmx unitrM -unitmxE unitmx_perm det_lblock det_ublock. rewrite !det_scalar1 det1 mulr1 mul1r unitrM unitfE nza -unitmxE. rewrite mulmx_block !mulmx0 mul0mx !addr0 !mulmx1 mul1mx block_mxKur. rewrite mul_scalar_mx scalerA divff // scale1r eqxx andbT. by rewrite block_mxEh mul_mx_row row_mxKl -def_a vsubmxK -xrowE xrkK eqxx andbT. Qed. Lemma card_GL_1 : #|'GL_1[F]| = #|F|.-1. Proof. by rewrite card_GL // mul1n big_nat1 expn1 subn1. Qed. Lemma card_GL_2 : #|'GL_2[F]| = (#|F| * #|F|.-1 ^ 2 * #|F|.+1)%N. Proof. rewrite card_GL // big_ltn // big_nat1 expn1 -(addn1 #|F|) -subn1 -!mulnA. by rewrite -subn_sqr. Qed. End CardGL. Lemma logn_card_GL_p n p : prime p -> logn p #|'GL_n(p)| = 'C(n, 2). Proof. move=> p_pr; have p_gt1 := prime_gt1 p_pr. have p_i_gt0: p ^ _ > 0 by move=> i; rewrite expn_gt0 ltnW. have <- : #|'GL_n.-1.+1(p)| = #|'GL_n(p)| by []. rewrite (card_GL _ (ltn0Sn n.-1)) card_ord Fp_cast // big_add1 /=. pose p'gt0 m := m > 0 /\ logn p m = 0. suffices [Pgt0 p'P]: p'gt0 (\prod_(0 <= i < n.-1.+1) (p ^ i.+1 - 1))%N. by rewrite lognM // p'P pfactorK // addn0; case n. apply: big_ind => [|m1 m2 [m10 p'm1] [m20]|i _]; rewrite {}/p'gt0 ?logn1 //. by rewrite muln_gt0 m10 lognM ?p'm1. rewrite lognE -if_neg subn_gt0 p_pr /= -{1 2}(exp1n i.+1) ltn_exp2r // p_gt1. by rewrite dvdn_subr ?dvdn_exp // gtnNdvd. Qed. Section MatrixAlgebra. Variables F : fieldType. Local Notation "A \in R" := (@submx F _ _ _ (mxvec A) R). Lemma mem0mx m n (R : 'A_(m, n)) : 0 \in R. Proof. by rewrite linear0 sub0mx. Qed. Lemma memmx0 n A : (A \in (0 : 'A_n)) -> A = 0. Proof. by rewrite submx0 mxvec_eq0; move/eqP. Qed. Lemma memmx1 n (A : 'M_n) : (A \in mxvec 1%:M) = is_scalar_mx A. Proof. apply/sub_rVP/is_scalar_mxP=> [[a] | [a ->]]. by rewrite -linearZ scale_scalar_mx mulr1 => /(can_inj mxvecK); exists a. by exists a; rewrite -linearZ scale_scalar_mx mulr1. Qed. Lemma memmx_subP m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (forall A, A \in R1 -> A \in R2) (R1 <= R2)%MS. Proof. apply: (iffP idP) => [sR12 A R1_A | sR12]; first exact: submx_trans sR12. by apply/rV_subP=> vA; rewrite -(vec_mxK vA); apply: sR12. Qed. Arguments memmx_subP {m1 m2 n R1 R2}. Lemma memmx_eqP m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (forall A, (A \in R1) = (A \in R2)) (R1 == R2)%MS. Proof. apply: (iffP eqmxP) => [eqR12 A | eqR12]; first by rewrite eqR12. by apply/eqmxP/rV_eqP=> vA; rewrite -(vec_mxK vA) eqR12. Qed. Arguments memmx_eqP {m1 m2 n R1 R2}. Lemma memmx_addsP m1 m2 n A (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (exists D, [/\ D.1 \in R1, D.2 \in R2 & A = D.1 + D.2]) (A \in R1 + R2)%MS. Proof. apply: (iffP sub_addsmxP) => [[u /(canRL mxvecK)->] | [D []]]. exists (vec_mx (u.1 *m R1), vec_mx (u.2 *m R2)). by rewrite /= linearD !vec_mxK !submxMl. case/submxP=> u1 defD1 /submxP[u2 defD2] ->. by exists (u1, u2); rewrite linearD /= defD1 defD2. Qed. Arguments memmx_addsP {m1 m2 n A R1 R2}. Lemma memmx_sumsP (I : finType) (P : pred I) n (A : 'M_n) R_ : reflect (exists2 A_, A = \sum_(i | P i) A_ i & forall i, A_ i \in R_ i) (A \in \sum_(i | P i) R_ i)%MS. Proof. apply: (iffP sub_sumsmxP) => [[C defA] | [A_ -> R_A] {A}]. exists (fun i => vec_mx (C i *m R_ i)) => [|i]. by rewrite -linear_sum -defA /= mxvecK. by rewrite vec_mxK submxMl. exists (fun i => mxvec (A_ i) *m pinvmx (R_ i)). by rewrite linear_sum; apply: eq_bigr => i _; rewrite mulmxKpV. Qed. Arguments memmx_sumsP {I P n A R_}. Lemma has_non_scalar_mxP m n (R : 'A_(m, n)) : (1%:M \in R)%MS -> reflect (exists2 A, A \in R & ~~ is_scalar_mx A)%MS (1 < \rank R). Proof. case: (posnP n) => [-> | n_gt0] in R *; set S := mxvec _ => sSR. by rewrite [R]thinmx0 mxrank0; right; case; rewrite /is_scalar_mx ?insubF. have rankS: \rank S = 1%N. apply/eqP; rewrite eqn_leq rank_leq_row lt0n mxrank_eq0 mxvec_eq0. by rewrite -mxrank_eq0 mxrank1 -lt0n. rewrite -{2}rankS (ltn_leqif (mxrank_leqif_sup sSR)). apply: (iffP idP) => [/row_subPn[i] | [A sAR]]. rewrite -[row i R]vec_mxK memmx1; set A := vec_mx _ => nsA. by exists A; rewrite // vec_mxK row_sub. by rewrite -memmx1; apply/contra/submx_trans. Qed. Definition mulsmx m1 m2 n (R1 : 'A[F]_(m1, n)) (R2 : 'A_(m2, n)) := (\sum_i <<R1 *m lin_mx (mulmxr (vec_mx (row i R2)))>>)%MS. Arguments mulsmx {m1%_N m2%_N n%_N} R1%_MS R2%_MS. Local Notation "R1 * R2" := (mulsmx R1 R2) : matrix_set_scope. Lemma genmx_muls m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : <<(R1 * R2)%MS>>%MS = (R1 * R2)%MS. Proof. by rewrite genmx_sums; apply: eq_bigr => i; rewrite genmx_id. Qed. Lemma mem_mulsmx m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) A1 A2 : (A1 \in R1 -> A2 \in R2 -> A1 *m A2 \in R1 * R2)%MS. Proof. move=> R_A1 R_A2; rewrite -[A2]mxvecK; case/submxP: R_A2 => a ->{A2}. rewrite mulmx_sum_row !linear_sum summx_sub // => i _. rewrite 3!linearZ scalemx_sub {a}//= (sumsmx_sup i) // genmxE. rewrite -[A1]mxvecK; case/submxP: R_A1 => a ->{A1}. by apply/submxP; exists a; rewrite mulmxA mul_rV_lin. Qed. Lemma mulsmx_subP m1 m2 m n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R : 'A_(m, n)) : reflect (forall A1 A2, A1 \in R1 -> A2 \in R2 -> A1 *m A2 \in R) (R1 * R2 <= R)%MS. Proof. apply: (iffP memmx_subP) => [sR12R A1 A2 R_A1 R_A2 | sR12R A]. by rewrite sR12R ?mem_mulsmx. case/memmx_sumsP=> A_ -> R_A; rewrite linear_sum summx_sub //= => j _. rewrite (submx_trans (R_A _)) // genmxE; apply/row_subP=> i. by rewrite row_mul mul_rV_lin sR12R ?vec_mxK ?row_sub. Qed. Arguments mulsmx_subP {m1 m2 m n R1 R2 R}. Lemma mulsmxS m1 m2 m3 m4 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) (R4 : 'A_(m4, n)) : (R1 <= R3 -> R2 <= R4 -> R1 * R2 <= R3 * R4)%MS. Proof. move=> sR13 sR24; apply/mulsmx_subP=> A1 A2 R_A1 R_A2. by apply: mem_mulsmx; [apply: submx_trans sR13 | apply: submx_trans sR24]. Qed. Lemma muls_eqmx m1 m2 m3 m4 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) (R4 : 'A_(m4, n)) : (R1 :=: R3 -> R2 :=: R4 -> R1 * R2 = R3 * R4)%MS. Proof. move=> eqR13 eqR24; rewrite -(genmx_muls R1 R2) -(genmx_muls R3 R4). by apply/genmxP; rewrite !mulsmxS ?eqR13 ?eqR24. Qed. Lemma mulsmxP m1 m2 n A (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (exists2 A1, forall i, A1 i \in R1 & exists2 A2, forall i, A2 i \in R2 & A = \sum_(i < n ^ 2) A1 i *m A2 i) (A \in R1 * R2)%MS. Proof. apply: (iffP idP) => [R_A|[A1 R_A1 [A2 R_A2 ->{A}]]]; last first. by rewrite linear_sum summx_sub // => i _; rewrite mem_mulsmx. have{R_A}: (A \in R1 * <<R2>>)%MS. by apply: memmx_subP R_A; rewrite mulsmxS ?genmxE. case/memmx_sumsP=> A_ -> R_A; pose A2_ i := vec_mx (row i <<R2>>%MS). pose A1_ i := mxvec (A_ i) *m pinvmx (R1 *m lin_mx (mulmxr (A2_ i))) *m R1. exists (vec_mx \o A1_) => [i|]; first by rewrite vec_mxK submxMl. exists A2_ => [i|]; first by rewrite vec_mxK -(genmxE R2) row_sub. apply: eq_bigr => i _; rewrite -[_ *m _](mx_rV_lin (mulmxr (A2_ i))). by rewrite -mulmxA mulmxKpV ?mxvecK // -(genmxE (_ *m _)) R_A. Qed. Arguments mulsmxP {m1 m2 n A R1 R2}. Lemma mulsmxA m1 m2 m3 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) : (R1 * (R2 * R3) = R1 * R2 * R3)%MS. Proof. rewrite -(genmx_muls (_ * _)%MS) -genmx_muls; apply/genmxP/andP; split. apply/mulsmx_subP=> A1 A23 R_A1; case/mulsmxP=> A2 R_A2 [A3 R_A3 ->{A23}]. by rewrite !linear_sum summx_sub //= => i _; rewrite mulmxA !mem_mulsmx. apply/mulsmx_subP=> _ A3 /mulsmxP[A1 R_A1 [A2 R_A2 ->]] R_A3. rewrite mulmx_suml linear_sum summx_sub //= => i _. by rewrite -mulmxA !mem_mulsmx. Qed. Lemma mulsmxDl m1 m2 m3 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) : ((R1 + R2) * R3 = R1 * R3 + R2 * R3)%MS. Proof. rewrite -(genmx_muls R2 R3) -(genmx_muls R1 R3) -genmx_muls -genmx_adds. apply/genmxP; rewrite andbC addsmx_sub !mulsmxS ?addsmxSl ?addsmxSr //=. apply/mulsmx_subP=> _ A3 /memmx_addsP[A [R_A1 R_A2 ->]] R_A3. by rewrite mulmxDl linearD addmx_sub_adds ?mem_mulsmx. Qed. Lemma mulsmxDr m1 m2 m3 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) : (R1 * (R2 + R3) = R1 * R2 + R1 * R3)%MS. Proof. rewrite -(genmx_muls R1 R3) -(genmx_muls R1 R2) -genmx_muls -genmx_adds. apply/genmxP; rewrite andbC addsmx_sub !mulsmxS ?addsmxSl ?addsmxSr //=. apply/mulsmx_subP=> A1 _ R_A1 /memmx_addsP[A [R_A2 R_A3 ->]]. by rewrite mulmxDr linearD addmx_sub_adds ?mem_mulsmx. Qed. Lemma mulsmx0 m1 m2 n (R1 : 'A_(m1, n)) : (R1 * (0 : 'A_(m2, n)) = 0)%MS. Proof. apply/eqP; rewrite -submx0; apply/mulsmx_subP=> A1 A0 _. by rewrite [A0 \in 0]eqmx0 => /memmx0->; rewrite mulmx0 mem0mx. Qed. Lemma muls0mx m1 m2 n (R2 : 'A_(m2, n)) : ((0 : 'A_(m1, n)) * R2 = 0)%MS. Proof. apply/eqP; rewrite -submx0; apply/mulsmx_subP=> A0 A2. by rewrite [A0 \in 0]eqmx0 => /memmx0->; rewrite mul0mx mem0mx. Qed. Definition left_mx_ideal m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) := (R1 * R2 <= R2)%MS. Definition right_mx_ideal m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) := (R2 * R1 <= R2)%MS. Definition mx_ideal m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) := left_mx_ideal R1 R2 && right_mx_ideal R1 R2. Definition mxring_id m n (R : 'A_(m, n)) e := [/\ e != 0, e \in R, forall A, A \in R -> e *m A = A & forall A, A \in R -> A *m e = A]%MS. Definition has_mxring_id m n (R : 'A[F]_(m , n)) := (R != 0) && (row_mx 0 (row_mx (mxvec R) (mxvec R)) <= row_mx (cokermx R) (row_mx (lin_mx (mulmx R \o lin_mulmx)) (lin_mx (mulmx R \o lin_mulmxr))))%MS. Definition mxring m n (R : 'A_(m, n)) := left_mx_ideal R R && has_mxring_id R. Lemma mxring_idP m n (R : 'A_(m, n)) : reflect (exists e, mxring_id R e) (has_mxring_id R). Proof. apply: (iffP andP) => [[nzR] | [e [nz_e Re ideR idRe]]]. case/submxP=> v; rewrite -[v]vec_mxK; move/vec_mx: v => e. rewrite !mul_mx_row; case/eq_row_mx => /eqP. rewrite eq_sym -submxE => Re. case/eq_row_mx; rewrite !{1}mul_rV_lin1 /= mxvecK. set u := (_ *m _) => /(can_inj mxvecK) idRe /(can_inj mxvecK) ideR. exists e; split=> // [ | A /submxP[a defA] | A /submxP[a defA]]. - by apply: contra nzR; rewrite ideR => /eqP->; rewrite !linear0. - by rewrite -{2}[A]mxvecK defA idRe mulmxA mx_rV_lin -defA /= mxvecK. by rewrite -{2}[A]mxvecK defA ideR mulmxA mx_rV_lin -defA /= mxvecK. split. by apply: contraNneq nz_e => R0; rewrite R0 eqmx0 in Re; rewrite (memmx0 Re). apply/submxP; exists (mxvec e); rewrite !mul_mx_row !{1}mul_rV_lin1. rewrite submxE in Re; rewrite {Re}(eqP Re). congr (row_mx 0 (row_mx (mxvec _) (mxvec _))); apply/row_matrixP=> i. by rewrite !row_mul !mul_rV_lin1 /= mxvecK ideR vec_mxK ?row_sub. by rewrite !row_mul !mul_rV_lin1 /= mxvecK idRe vec_mxK ?row_sub. Qed. Arguments mxring_idP {m n R}. Section CentMxDef. Variables (m n : nat) (R : 'A[F]_(m, n)). Definition cent_mx_fun (B : 'M[F]_n) := R *m lin_mx (mulmxr B \- mulmx B). Lemma cent_mx_fun_is_linear : linear cent_mx_fun. Proof. move=> a A B; apply/row_matrixP=> i; rewrite linearP row_mul mul_rV_lin. rewrite /= [row i _ as v in a *: v]row_mul mul_rV_lin row_mul mul_rV_lin. by rewrite -linearP -(linearP (mulmx (vec_mx (row i R)) \- mulmxr _)). Qed. HB.instance Definition _ := GRing.isSemilinear.Build F 'M[F]_n 'M[F]_(m, n * n) _ cent_mx_fun (GRing.semilinear_linear cent_mx_fun_is_linear). Definition cent_mx := kermx (lin_mx cent_mx_fun). Definition center_mx := (R :&: cent_mx)%MS. End CentMxDef. Local Notation "''C' ( R )" := (cent_mx R) : matrix_set_scope. Local Notation "''Z' ( R )" := (center_mx R) : matrix_set_scope. Lemma cent_rowP m n B (R : 'A_(m, n)) : reflect (forall i (A := vec_mx (row i R)), A *m B = B *m A) (B \in 'C(R))%MS. Proof. apply: (iffP sub_kermxP); rewrite mul_vec_lin => cBE. move/(canRL mxvecK): cBE => cBE i A /=; move/(congr1 (row i)): cBE. rewrite row_mul mul_rV_lin -/A; move/(canRL mxvecK). by move/(canRL (subrK _)); rewrite !linear0 add0r. apply: (canLR vec_mxK); apply/row_matrixP=> i. by rewrite row_mul mul_rV_lin /= cBE subrr !linear0. Qed. Arguments cent_rowP {m n B R}. Lemma cent_mxP m n B (R : 'A_(m, n)) : reflect (forall A, A \in R -> A *m B = B *m A) (B \in 'C(R))%MS. Proof. apply: (iffP cent_rowP) => cEB => [A sAE | i A]. rewrite -[A]mxvecK -(mulmxKpV sAE); move: (mxvec A *m _) => u. rewrite !mulmx_sum_row !linear_sum mulmx_suml; apply: eq_bigr => i _ /=. by rewrite 2!linearZ -scalemxAl /= cEB. by rewrite cEB // vec_mxK row_sub. Qed. Arguments cent_mxP {m n B R}. Lemma scalar_mx_cent m n a (R : 'A_(m, n)) : (a%:M \in 'C(R))%MS. Proof. by apply/cent_mxP=> A _; apply: scalar_mxC. Qed. Lemma center_mx_sub m n (R : 'A_(m, n)) : ('Z(R) <= R)%MS. Proof. exact: capmxSl. Qed. Lemma center_mxP m n A (R : 'A_(m, n)) : reflect (A \in R /\ forall B, B \in R -> B *m A = A *m B) (A \in 'Z(R))%MS. Proof. rewrite sub_capmx; case R_A: (A \in R); last by right; case. by apply: (iffP cent_mxP) => [cAR | [_ cAR]]. Qed. Arguments center_mxP {m n A R}. Lemma mxring_id_uniq m n (R : 'A_(m, n)) e1 e2 : mxring_id R e1 -> mxring_id R e2 -> e1 = e2. Proof. by case=> [_ Re1 idRe1 _] [_ Re2 _ ide2R]; rewrite -(idRe1 _ Re2) ide2R. Qed. Lemma cent_mx_ideal m n (R : 'A_(m, n)) : left_mx_ideal 'C(R)%MS 'C(R)%MS. Proof. apply/mulsmx_subP=> A1 A2 C_A1 C_A2; apply/cent_mxP=> B R_B. by rewrite mulmxA (cent_mxP C_A1) // -!mulmxA (cent_mxP C_A2). Qed. Lemma cent_mx_ring m n (R : 'A_(m, n)) : n > 0 -> mxring 'C(R)%MS. Proof. move=> n_gt0; rewrite /mxring cent_mx_ideal; apply/mxring_idP. exists 1%:M; split=> [||A _|A _]; rewrite ?mulmx1 ?mul1mx ?scalar_mx_cent //. by rewrite -mxrank_eq0 mxrank1 -lt0n. Qed. Lemma mxdirect_adds_center m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : mx_ideal (R1 + R2)%MS R1 -> mx_ideal (R1 + R2)%MS R2 -> mxdirect (R1 + R2) -> ('Z((R1 + R2)%MS) :=: 'Z(R1) + 'Z(R2))%MS. Proof. case/andP=> idlR1 idrR1 /andP[idlR2 idrR2] /mxdirect_addsP dxR12. apply/eqmxP/andP; split. apply/memmx_subP=> z0; rewrite sub_capmx => /andP[]. case/memmx_addsP=> z [R1z1 R2z2 ->{z0}] Cz. rewrite linearD addmx_sub_adds //= ?sub_capmx ?R1z1 ?R2z2 /=. apply/cent_mxP=> A R1_A; have R_A := submx_trans R1_A (addsmxSl R1 R2). have Rz2 := submx_trans R2z2 (addsmxSr R1 R2). rewrite -{1}[z.1](addrK z.2) mulmxBr (cent_mxP Cz) // mulmxDl. rewrite [A *m z.2]memmx0 1?[z.2 *m A]memmx0 ?addrK //. by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). apply/cent_mxP=> A R2_A; have R_A := submx_trans R2_A (addsmxSr R1 R2). have Rz1 := submx_trans R1z1 (addsmxSl R1 R2). rewrite -{1}[z.2](addKr z.1) mulmxDr (cent_mxP Cz) // mulmxDl. rewrite mulmxN [A *m z.1]memmx0 1?[z.1 *m A]memmx0 ?addKr //. by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). rewrite addsmx_sub; apply/andP; split. apply/memmx_subP=> z; rewrite sub_capmx => /andP[R1z cR1z]. have Rz := submx_trans R1z (addsmxSl R1 R2). rewrite sub_capmx Rz; apply/cent_mxP=> A0. case/memmx_addsP=> A [R1_A1 R2_A2] ->{A0}. have R_A2 := submx_trans R2_A2 (addsmxSr R1 R2). rewrite mulmxDl mulmxDr (cent_mxP cR1z) //; congr (_ + _). rewrite [A.2 *m z]memmx0 1?[z *m A.2]memmx0 //. by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). apply/memmx_subP=> z; rewrite !sub_capmx => /andP[R2z cR2z]. have Rz := submx_trans R2z (addsmxSr R1 R2); rewrite Rz. apply/cent_mxP=> _ /memmx_addsP[A [R1_A1 R2_A2 ->]]. rewrite mulmxDl mulmxDr (cent_mxP cR2z _ R2_A2) //; congr (_ + _). have R_A1 := submx_trans R1_A1 (addsmxSl R1 R2). rewrite [A.1 *m z]memmx0 1?[z *m A.1]memmx0 //. by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). Qed. Lemma mxdirect_sums_center (I : finType) m n (R : 'A_(m, n)) R_ : (\sum_i R_ i :=: R)%MS -> mxdirect (\sum_i R_ i) -> (forall i : I, mx_ideal R (R_ i)) -> ('Z(R) :=: \sum_i 'Z(R_ i))%MS. Proof. move=> defR dxR idealR. have sR_R: (R_ _ <= R)%MS by move=> i; rewrite -defR (sumsmx_sup i). have anhR i j A B : i != j -> A \in R_ i -> B \in R_ j -> A *m B = 0. move=> ne_ij RiA RjB; apply: memmx0. have [[_ idRiR] [idRRj _]] := (andP (idealR i), andP (idealR j)). rewrite -(mxdirect_sumsP dxR j) // sub_capmx (sumsmx_sup i) //. by rewrite (mulsmx_subP idRRj) // (memmx_subP (sR_R i)). by rewrite (mulsmx_subP idRiR) // (memmx_subP (sR_R j)). apply/eqmxP/andP; split. apply/memmx_subP=> Z; rewrite sub_capmx => /andP[]. rewrite -{1}defR => /memmx_sumsP[z ->{Z} Rz cRz]. apply/memmx_sumsP; exists z => // i; rewrite sub_capmx Rz. apply/cent_mxP=> A RiA; have:= cent_mxP cRz A (memmx_subP (sR_R i) A RiA). rewrite (bigD1 i) //= mulmxDl mulmxDr mulmx_suml mulmx_sumr. by rewrite !big1 ?addr0 // => j; last rewrite eq_sym; move/anhR->. apply/sumsmx_subP => i _; apply/memmx_subP=> z; rewrite sub_capmx. case/andP=> Riz cRiz; rewrite sub_capmx (memmx_subP (sR_R i)) //=. apply/cent_mxP=> A; rewrite -{1}defR; case/memmx_sumsP=> a -> R_a. rewrite (bigD1 i) // mulmxDl mulmxDr mulmx_suml mulmx_sumr. rewrite !big1 => [|j|j]; first by rewrite !addr0 (cent_mxP cRiz). by rewrite eq_sym => /anhR->. by move/anhR->. Qed. End MatrixAlgebra. Arguments mulsmx {F m1%_N m2%_N n%_N} R1%_MS R2%_MS. Arguments left_mx_ideal {F m1%_N m2%_N n%_N} R%_MS S%_MS : rename. Arguments right_mx_ideal {F m1%_N m2%_N n%_N} R%_MS S%_MS : rename. Arguments mx_ideal {F m1%_N m2%_N n%_N} R%_MS S%_MS : rename. Arguments mxring_id {F m%_N n%_N} R%_MS e%_R. Arguments has_mxring_id {F m%_N n%_N} R%_MS. Arguments mxring {F m%_N n%_N} R%_MS. Arguments cent_mx {F m%_N n%_N} R%_MS. Arguments center_mx {F m%_N n%_N} R%_MS. Notation "A \in R" := (submx (mxvec A) R) : matrix_set_scope. Notation "R * S" := (mulsmx R S) : matrix_set_scope. Notation "''C' ( R )" := (cent_mx R) : matrix_set_scope. Notation "''C_' R ( S )" := (R :&: 'C(S))%MS : matrix_set_scope. Notation "''C_' ( R ) ( S )" := ('C_R(S))%MS (only parsing) : matrix_set_scope. Notation "''Z' ( R )" := (center_mx R) : matrix_set_scope. Arguments memmx_subP {F m1 m2 n R1 R2}. Arguments memmx_eqP {F m1 m2 n R1 R2}. Arguments memmx_addsP {F m1 m2 n} A {R1 R2}. Arguments memmx_sumsP {F I P n A R_}. Arguments mulsmx_subP {F m1 m2 m n R1 R2 R}. Arguments mulsmxP {F m1 m2 n A R1 R2}. Arguments mxring_idP F {m n R}. Arguments cent_rowP {F m n B R}. Arguments cent_mxP {F m n B R}. Arguments center_mxP {F m n A R}. (* Parametricity for the row-space/F-algebra theory. *) Section MapMatrixSpaces. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Lemma Gaussian_elimination_map m n (A : 'M_(m, n)) : Gaussian_elimination_ A^f = ((col_ebase A)^f, (row_ebase A)^f, \rank A). Proof. rewrite mxrankE /row_ebase /col_ebase unlock. elim: m n A => [|m IHm] [|n] A /=; rewrite ?map_mx1 //. set pAnz := [pred k | A k.1 k.2 != 0]. rewrite (@eq_pick _ _ pAnz) => [|k]; last by rewrite /= mxE fmorph_eq0. case: {+}(pick _) => [[i j]|]; last by rewrite !map_mx1. rewrite mxE -fmorphV -map_xcol -map_xrow -map_dlsubmx -map_drsubmx. rewrite -map_ursubmx -map_mxZ -map_mxM -map_mxB {}IHm /=. case: {+}(Gaussian_elimination_ _) => [[L U] r] /=; rewrite map_xrow map_xcol. by rewrite !(@map_block_mx _ _ f 1 _ 1) !map_mx0 ?map_mx1 ?map_scalar_mx. Qed. Lemma mxrank_map m n (A : 'M_(m, n)) : \rank A^f = \rank A. Proof. by rewrite mxrankE Gaussian_elimination_map. Qed. Lemma row_free_map m n (A : 'M_(m, n)) : row_free A^f = row_free A. Proof. by rewrite /row_free mxrank_map. Qed. Lemma row_full_map m n (A : 'M_(m, n)) : row_full A^f = row_full A. Proof. by rewrite /row_full mxrank_map. Qed. Lemma map_row_ebase m n (A : 'M_(m, n)) : (row_ebase A)^f = row_ebase A^f. Proof. by rewrite {2}/row_ebase unlock Gaussian_elimination_map. Qed. Lemma map_col_ebase m n (A : 'M_(m, n)) : (col_ebase A)^f = col_ebase A^f. Proof. by rewrite {2}/col_ebase unlock Gaussian_elimination_map. Qed. Lemma map_row_base m n (A : 'M_(m, n)) : (row_base A)^f = castmx (mxrank_map A, erefl n) (row_base A^f). Proof. move: (mxrank_map A); rewrite {2}/row_base mxrank_map => eqrr. by rewrite castmx_id map_mxM map_pid_mx map_row_ebase. Qed. Lemma map_col_base m n (A : 'M_(m, n)) : (col_base A)^f = castmx (erefl m, mxrank_map A) (col_base A^f). Proof. move: (mxrank_map A); rewrite {2}/col_base mxrank_map => eqrr. by rewrite castmx_id map_mxM map_pid_mx map_col_ebase. Qed. Lemma map_pinvmx m n (A : 'M_(m, n)) : (pinvmx A)^f = pinvmx A^f. Proof. rewrite !map_mxM !map_invmx map_row_ebase map_col_ebase. by rewrite map_pid_mx -mxrank_map. Qed. Lemma map_kermx m n (A : 'M_(m, n)) : (kermx A)^f = kermx A^f. Proof. by rewrite !map_mxM map_invmx map_col_ebase -mxrank_map map_copid_mx. Qed. Lemma map_cokermx m n (A : 'M_(m, n)) : (cokermx A)^f = cokermx A^f. Proof. by rewrite !map_mxM map_invmx map_row_ebase -mxrank_map map_copid_mx. Qed. Lemma map_submx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A^f <= B^f)%MS = (A <= B)%MS. Proof. by rewrite !submxE -map_cokermx -map_mxM map_mx_eq0. Qed. Lemma map_ltmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A^f < B^f)%MS = (A < B)%MS. Proof. by rewrite /ltmx !map_submx. Qed. Lemma map_eqmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A^f :=: B^f)%MS <-> (A :=: B)%MS. Proof. split=> [/eqmxP|eqAB]; first by rewrite !map_submx => /eqmxP. by apply/eqmxP; rewrite !map_submx !eqAB !submx_refl. Qed. Lemma map_genmx m n (A : 'M_(m, n)) : (<<A>>^f :=: <<A^f>>)%MS. Proof. by apply/eqmxP; rewrite !(genmxE, map_submx) andbb. Qed. Lemma map_addsmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (((A + B)%MS)^f :=: A^f + B^f)%MS. Proof. by apply/eqmxP; rewrite !addsmxE -map_col_mx !map_submx !addsmxE andbb. Qed. Lemma map_capmx_gen m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (capmx_gen A B)^f = capmx_gen A^f B^f. Proof. by rewrite map_mxM map_lsubmx map_kermx map_col_mx. Qed. Lemma map_capmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : ((A :&: B)^f :=: A^f :&: B^f)%MS. Proof. by apply/eqmxP; rewrite !capmxE -map_capmx_gen !map_submx -!capmxE andbb. Qed. Lemma map_complmx m n (A : 'M_(m, n)) : (A^C^f = A^f^C)%MS. Proof. by rewrite map_mxM map_row_ebase -mxrank_map map_copid_mx. Qed. Lemma map_diffmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : ((A :\: B)^f :=: A^f :\: B^f)%MS. Proof. apply/eqmxP; rewrite !diffmxE -map_capmx_gen -map_complmx. by rewrite -!map_capmx !map_submx -!diffmxE andbb. Qed. Lemma map_eigenspace n (g : 'M_n) a : (eigenspace g a)^f = eigenspace g^f (f a). Proof. by rewrite map_kermx map_mxB ?map_scalar_mx. Qed. Lemma eigenvalue_map n (g : 'M_n) a : eigenvalue g^f (f a) = eigenvalue g a. Proof. by rewrite /eigenvalue -map_eigenspace map_mx_eq0. Qed. Lemma memmx_map m n A (E : 'A_(m, n)) : (A^f \in E^f)%MS = (A \in E)%MS. Proof. by rewrite -map_mxvec map_submx. Qed. Lemma map_mulsmx m1 m2 n (E1 : 'A_(m1, n)) (E2 : 'A_(m2, n)) : ((E1 * E2)%MS^f :=: E1^f * E2^f)%MS. Proof. rewrite /mulsmx; elim/big_rec2: _ => [|i A Af _ eqA]; first by rewrite map_mx0. apply: (eqmx_trans (map_addsmx _ _)); apply: adds_eqmx {A Af}eqA. apply/eqmxP; rewrite !map_genmx !genmxE map_mxM. apply/rV_eqP=> u; congr (u <= _ *m _)%MS. by apply: map_lin_mx => //= A; rewrite map_mxM // map_vec_mx map_row. Qed. Lemma map_cent_mx m n (E : 'A_(m, n)) : ('C(E)%MS)^f = 'C(E^f)%MS. Proof. rewrite map_kermx; congr kermx; apply: map_lin_mx => A; rewrite map_mxM. by congr (_ *m _); apply: map_lin_mx => B; rewrite map_mxB ?map_mxM. Qed. Lemma map_center_mx m n (E : 'A_(m, n)) : (('Z(E))^f :=: 'Z(E^f))%MS. Proof. by rewrite /center_mx -map_cent_mx; apply: map_capmx. Qed. End MapMatrixSpaces. Section RowColDiagBlockMatrix. Import tagnat. Context {F : fieldType} {n : nat} {p_ : 'I_n -> nat}. Lemma eqmx_col {m} (V_ : forall i, 'M[F]_(p_ i, m)) : (\mxcol_i V_ i :=: \sum_i <<V_ i>>)%MS. Proof. apply/eqmxP/andP; split. apply/row_subP => i; rewrite row_mxcol. by rewrite (sumsmx_sup (sig1 i))// genmxE row_sub. apply/sumsmx_subP => i0 _; rewrite genmxE; apply/row_subP => j. apply: (eq_row_sub (Rank _ j)); apply/rowP => k. by rewrite !mxE Rank2K; case: _ / esym; rewrite cast_ord_id. Qed. Lemma rank_mxdiag (V_ : forall i, 'M[F]_(p_ i)) : (\rank (\mxdiag_i V_ i) = \sum_i \rank (V_ i))%N. Proof. elim: {+}n {+}p_ V_ => [|m IHm] q_ V_. by move: (\mxdiag__ _); rewrite !big_ord0 => M; rewrite flatmx0 mxrank0. rewrite mxdiag_recl [RHS]big_ord_recl/= -IHm. by case: _ / mxsize_recl; rewrite ?castmx_id rank_diag_block_mx. Qed. End RowColDiagBlockMatrix.
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.Subring.Defs import Mathlib.Algebra.Ring.Subsemiring.Basic import Mathlib.RingTheory.NonUnitalSubring.Defs import Mathlib.Data.Set.Finite.Basic /-! # Subrings 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)` * `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] variable [Ring S] [Ring T] namespace Subring variable {s t : Subring R} -- Porting note: there is no `Subring.toSubmonoid` but we can't define it because there is a -- projection `s.toSubmonoid` @[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 @[gcongr] lemma toSubsemiring_lt_toSubsemiring (hst : s < t) : s.toSubsemiring < t.toSubsemiring := hst @[gcongr] lemma toSubsemiring_le_toSubsemiring (hst : s ≤ t) : s.toSubsemiring ≤ t.toSubsemiring := hst @[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 @[gcongr] lemma toAddSubgroup_lt_toAddSubgroup (hst : s < t) : s.toAddSubgroup < t.toAddSubgroup := hst @[gcongr] lemma toAddSubgroup_le_toAddSubgroup (hst : s ≤ t) : s.toAddSubgroup ≤ t.toAddSubgroup := hst @[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 end Subring namespace Subring variable (s : Subring R) /-- 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 /-! ## 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 instance {R : Type*} [Ring R] [Fintype R] : Fintype (⊤ : Subring R) := inferInstanceAs (Fintype (⊤ : Set R)) 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 : Min (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 } /-- The center of isomorphic (not necessarily associative) rings are isomorphic. -/ @[simps!] def centerCongr (e : R ≃+* S) : center R ≃+* center S := NonUnitalSubsemiring.centerCongr e /-- The center of a (not necessarily associative) ring is isomorphic to the center of its opposite. -/ @[simps!] def centerToMulOpposite : center R ≃+* center Rᵐᵒᵖ := NonUnitalSubsemiring.centerToMulOpposite 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 _ 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 _ _ := Subtype.ext <| div_eq_mul_inv _ _ inv_zero := Subtype.ext inv_zero -- TODO: use a nicer defeq nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => 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 (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx @[aesop 80% (rule_sets := [SetLike])] theorem mem_closure_of_mem {s : Set R} {x : R} (hx : x ∈ s) : x ∈ closure s := subset_closure hx theorem notMem_of_notMem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) @[deprecated (since := "2025-05-23")] alias not_mem_of_not_mem_closure := notMem_of_notMem_closure /-- 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`. -/ @[gcongr] 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 : (x : R) → x ∈ closure s → Prop} (mem : ∀ (x) (hx : x ∈ s), p x (subset_closure hx)) (zero : p 0 (zero_mem _)) (one : p 1 (one_mem _)) (add : ∀ x y hx 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 y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {x} (hx : x ∈ closure s) : p x hx := let K : Subring R := { carrier := { x | ∃ hx, p x hx } mul_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, mul _ _ _ _ hpx hpy⟩ add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩ neg_mem' := fun ⟨_, hpx⟩ ↦ ⟨_, neg _ _ hpx⟩ zero_mem' := ⟨_, zero⟩ one_mem' := ⟨_, one⟩ } closure_le (t := K) |>.mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id /-- An induction principle for closure membership, for predicates with two arguments. -/ @[elab_as_elim] theorem closure_induction₂ {s : Set R} {p : (x y : R) → x ∈ closure s → y ∈ closure s → Prop} (mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_closure hx) (subset_closure hy)) (zero_left : ∀ x hx, p 0 x (zero_mem _) hx) (zero_right : ∀ x hx, p x 0 hx (zero_mem _)) (one_left : ∀ x hx, p 1 x (one_mem _) hx) (one_right : ∀ x hx, p x 1 hx (one_mem _)) (neg_left : ∀ x y hx hy, p x y hx hy → p (-x) y (neg_mem hx) hy) (neg_right : ∀ x y hx hy, p x y hx hy → p x (-y) hx (neg_mem hy)) (add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz) (add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz)) (mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz) (mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz)) {x y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) : p x y hx hy := by induction hy using closure_induction with | mem z hz => induction hx using closure_induction with | mem _ h => exact mem_mem _ _ h hz | zero => exact zero_left _ _ | one => exact one_left _ _ | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | neg _ _ h => exact neg_left _ _ _ _ h | zero => exact zero_right x hx | one => exact one_right x hx | mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂ | neg _ _ h => exact neg_right _ _ _ _ h theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubgroup.closure (Submonoid.closure s : Set R) := ⟨fun h => by induction h using closure_induction with | mem _ hx => exact AddSubgroup.subset_closure (Submonoid.subset_closure hx) | zero => exact zero_mem _ | one => exact AddSubgroup.subset_closure (one_mem _) | add _ _ _ _ hx hy => exact add_mem hx hy | neg _ _ hx => exact neg_mem hx | mul _ _ _hx _hy hx hy => clear _hx _hy induction hx, hy using AddSubgroup.closure_induction₂ with | mem _ _ hx hy => exact AddSubgroup.subset_closure (mul_mem hx hy) | one_left => simp | one_right => simp | mul_left _ _ _ _ _ _ h₁ h₂ => simpa [add_mul] using add_mem h₁ h₂ | mul_right _ _ _ _ _ _ h₁ h₂ => simpa [mul_add] using add_mem h₁ h₂ | inv_left _ _ _ _ h => simpa [neg_mul] using neg_mem h | inv_right _ _ _ _ h => simpa [mul_neg] using neg_mem h, fun h => by induction h using AddSubgroup.closure_induction with | mem x hx => induction hx using Submonoid.closure_induction with | mem _ h => exact subset_closure h | one => exact one_mem _ | mul _ _ _ _ h₁ h₂ => exact mul_mem h₁ h₂ | one => exact zero_mem _ | mul _ _ _ _ h₁ h₂ => exact add_mem h₁ h₂ | inv _ _ h => exact neg_mem h⟩ lemma closure_le_centralizer_centralizer (s : Set R) : closure s ≤ centralizer (centralizer s) := closure_le.mpr Set.subset_centralizer_centralizer /-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/ abbrev closureCommRingOfComm {s : Set R} (hcomm : ∀ x ∈ s, ∀ y ∈ s, x * y = y * x) : CommRing (closure s) := { (closure s).toRing with mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦ have := closure_le_centralizer_centralizer s Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ (this h₁) _ (this h₂) } theorem exists_list_of_mem_closure {s : Set R} {x : R} (hx : x ∈ closure s) : ∃ L : List (List R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s ∨ y = (-1 : R)) ∧ (L.map List.prod).sum = x := by rw [mem_closure_iff] at hx induction hx using AddSubgroup.closure_induction with | mem _ hx => obtain ⟨l, hl, h⟩ := Submonoid.exists_list_of_mem_closure hx exact ⟨[l], by simp [h]; clear_aux_decl; tauto⟩ | one => exact ⟨[], List.forall_mem_nil _, rfl⟩ | mul _ _ _ _ hL hM => obtain ⟨⟨L, HL1, HL2⟩, ⟨M, HM1, HM2⟩⟩ := And.intro hL hM exact ⟨L ++ M, List.forall_mem_append.2 ⟨HL1, HM1⟩, by rw [List.map_append, List.sum_append, HL2, HM2]⟩ | inv _ _ hL => obtain ⟨L, hL⟩ := hL exact ⟨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 +contextual [List.map_cons, add_comm])⟩ variable (R) in /-- `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 /-- Closure of a subring `S` equals `S`. -/ @[simp] 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 @[simp] theorem closure_singleton_intCast (n : ℤ) : closure {(n : R)} = ⊥ := bot_unique <| closure_le.2 <| Set.singleton_subset_iff.mpr <| intCast_mem _ _ @[simp] theorem closure_singleton_natCast (n : ℕ) : closure {(n : R)} = ⊥ := mod_cast closure_singleton_intCast n @[simp] theorem closure_singleton_zero : closure {(0 : R)} = ⊥ := mod_cast closure_singleton_natCast 0 @[simp] theorem closure_singleton_one : closure {(1 : R)} = ⊥ := mod_cast closure_singleton_natCast 1 @[simp] theorem closure_insert_intCast (n : ℤ) (s : Set R) : closure (insert (n : R) s) = closure s := by rw [Set.insert_eq, closure_union] simp @[simp] theorem closure_insert_natCast (n : ℕ) (s : Set R) : closure (insert (n : R) s) = closure s := mod_cast closure_insert_intCast n s @[simp] theorem closure_insert_zero (s : Set R) : closure (insert 0 s) = closure s := mod_cast closure_insert_natCast 0 s @[simp] theorem closure_insert_one (s : Set R) : closure (insert 1 s) = closure s := mod_cast closure_insert_natCast 1 s 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 map_inf (s t : Subring R) (f : R →+* S) (hf : Function.Injective f) : (s ⊓ t).map f = s.map f ⊓ t.map f := SetLike.coe_injective (Set.image_inter hf) theorem map_iInf {ι : Sort*} [Nonempty ι] (f : R →+* S) (hf : Function.Injective f) (s : ι → Subring R) : (iInf s).map f = ⨅ i, (s i).map f := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s) 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 @[gcongr, 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] theorem top_prod (s : Subring S) : (⊤ : Subring R).prod s = s.comap (RingHom.snd R S) := ext fun x => by simp [mem_prod] @[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, 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_eq_top {f : R →+* S} : f.range = (⊤ : Subring S) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_eq_univ /-- The range of a surjective ring homomorphism is the whole of the codomain. -/ @[simp] theorem range_eq_top_of_surjective (f : R →+* S) (hf : Function.Surjective f) : f.range = (⊤ : Subring S) := range_eq_top.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) := Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Subring.gi S).gc (Subring.gi R).gc fun _ ↦ rfl end RingHom namespace Subring open RingHom theorem mem_closure_image_of (f : R →+* S) {s : Set R} {x : R} (hx : x ∈ Subring.closure s) : f x ∈ Subring.closure (f '' s) := by rw [← f.map_closure, Subring.mem_map] exact ⟨x, hx, rfl⟩ /-- 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 theorem range_fst : (fst R S).rangeS = ⊤ := (fst R S).rangeS_top_of_surjective <| Prod.fst_surjective 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` -/ def subringMap (e : R ≃+* S) : s ≃+* s.map e.toRingHom := e.subsemiringMap s.toSubsemiring 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_cancel (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⟩ <;> rcases 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 /-! ## 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 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 rw [zsmul_eq_mul]
Multiset.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.List.Chain import Mathlib.Data.Multiset.Sort import Mathlib.Logic.Equiv.List /-! # `Encodable` and `Denumerable` instances for `Multiset` -/ variable {α : Type*} open Encodable section Finset variable [Encodable α] private def enle : α → α → Prop := encode ⁻¹'o (· ≤ ·) private theorem enle.isLinearOrder : IsLinearOrder α enle := (RelEmbedding.preimage ⟨encode, encode_injective⟩ (· ≤ ·)).isLinearOrder private def decidable_enle (a b : α) : Decidable (enle a b) := by unfold enle Order.Preimage infer_instance attribute [local instance] enle.isLinearOrder decidable_enle /-- Explicit encoding function for `Multiset α` -/ def encodeMultiset (s : Multiset α) : ℕ := encode (s.sort enle) /-- Explicit decoding function for `Multiset α` -/ def decodeMultiset (n : ℕ) : Option (Multiset α) := ((↑) : List α → Multiset α) <$> decode (α := List α) n /-- If `α` is encodable, then so is `Multiset α`. -/ instance _root_.Multiset.encodable : Encodable (Multiset α) := ⟨encodeMultiset, decodeMultiset, fun s => by simp [encodeMultiset, decodeMultiset, encodek]⟩ end Finset namespace Denumerable variable [Denumerable α] section Multiset /-- Outputs the list of differences of the input list, that is `lower [a₁, a₂, ...] n = [a₁ - n, a₂ - a₁, ...]` -/ def lower : List ℕ → ℕ → List ℕ | [], _ => [] | m :: l, n => (m - n) :: lower l m /-- Outputs the list of partial sums of the input list, that is `raise [a₁, a₂, ...] n = [n + a₁, n + a₁ + a₂, ...]` -/ def raise : List ℕ → ℕ → List ℕ | [], _ => [] | m :: l, n => (m + n) :: raise l (m + n) theorem lower_raise : ∀ l n, lower (raise l n) n = l | [], _ => rfl | m :: l, n => by rw [raise, lower, Nat.add_sub_cancel_right, lower_raise l] theorem raise_lower : ∀ {l n}, List.Sorted (· ≤ ·) (n :: l) → raise (lower l n) n = l | [], _, _ => rfl | m :: l, n, h => by have : n ≤ m := List.rel_of_sorted_cons h _ List.mem_cons_self simp [raise, lower, Nat.sub_add_cancel this, raise_lower h.of_cons] theorem raise_chain : ∀ l n, List.Chain (· ≤ ·) n (raise l n) | [], _ => List.Chain.nil | _ :: _, _ => List.Chain.cons (Nat.le_add_left _ _) (raise_chain _ _) /-- `raise l n` is a non-decreasing sequence. -/ theorem raise_sorted : ∀ l n, List.Sorted (· ≤ ·) (raise l n) | [], _ => List.sorted_nil | _ :: _, _ => List.chain_iff_pairwise.1 (raise_chain _ _) /-- If `α` is denumerable, then so is `Multiset α`. Warning: this is *not* the same encoding as used in `Multiset.encodable`. -/ instance multiset : Denumerable (Multiset α) := mk' ⟨fun s : Multiset α => encode <| lower ((s.map encode).sort (· ≤ ·)) 0, fun n => Multiset.map (ofNat α) (raise (ofNat (List ℕ) n) 0), fun s => by have := raise_lower (List.sorted_cons.2 ⟨fun n _ => Nat.zero_le n, (s.map encode).sort_sorted _⟩) simp [-Multiset.map_coe, this], fun n => by simp [-Multiset.map_coe, List.mergeSort_eq_self _ (raise_sorted _ _), lower_raise]⟩ end Multiset end Denumerable
Multiset.lean
/- Copyright (c) 2021 Ruben Van de Velde. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ruben Van de Velde, Daniel Weber -/ import Mathlib.Algebra.BigOperators.Group.Multiset.Defs import Mathlib.Algebra.Order.BigOperators.GroupWithZero.List /-! # Big operators on a multiset in ordered groups with zeros This file contains the results concerning the interaction of multiset big operators with ordered groups with zeros. -/ namespace Multiset variable {R : Type*} [CommMonoidWithZero R] [PartialOrder R] [ZeroLEOneClass R] [PosMulMono R] lemma prod_nonneg {s : Multiset R} (h : ∀ a ∈ s, 0 ≤ a) : 0 ≤ s.prod := by cases s using Quotient.ind simp only [quot_mk_to_coe, mem_coe, prod_coe] at * apply List.prod_nonneg h lemma one_le_prod {s : Multiset R} (h : ∀ a ∈ s, 1 ≤ a) : 1 ≤ s.prod := by cases s using Quotient.ind simp only [quot_mk_to_coe, mem_coe, prod_coe] at * apply List.one_le_prod h theorem prod_map_le_prod_map₀ {ι : Type*} {s : Multiset ι} (f : ι → R) (g : ι → R) (h0 : ∀ i ∈ s, 0 ≤ f i) (h : ∀ i ∈ s, f i ≤ g i) : (map f s).prod ≤ (map g s).prod := by cases s using Quotient.ind simp only [quot_mk_to_coe, mem_coe, map_coe, prod_coe] at * apply List.prod_map_le_prod_map₀ f g h0 h theorem prod_map_le_pow_card {F L : Type*} [FunLike F L R] {f : F} {r : R} {t : Multiset L} (hf0 : ∀ x ∈ t, 0 ≤ f x) (hf : ∀ x ∈ t, f x ≤ r) : (map f t).prod ≤ r ^ card t := by induction t using Quotient.inductionOn simp_all [List.prod_map_le_pow_length₀] omit [PosMulMono R] variable [PosMulStrictMono R] [NeZero (1 : R)] lemma prod_pos {s : Multiset R} (h : ∀ a ∈ s, 0 < a) : 0 < s.prod := by cases s using Quotient.ind simp only [quot_mk_to_coe, mem_coe, prod_coe] at * apply List.prod_pos h theorem prod_map_lt_prod_map {ι : Type*} {s : Multiset ι} (hs : s ≠ 0) (f : ι → R) (g : ι → R) (h0 : ∀ i ∈ s, 0 < f i) (h : ∀ i ∈ s, f i < g i) : (map f s).prod < (map g s).prod := by cases s using Quotient.ind simp only [quot_mk_to_coe, mem_coe, map_coe, prod_coe, ne_eq, coe_eq_zero] at * apply List.prod_map_lt_prod_map hs f g h0 h end Multiset
ModuleTopology.lean
/- Copyright (c) 2024 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Will Sawin -/ import Mathlib.Topology.Algebra.Module.Equiv import Mathlib.RingTheory.Finiteness.Cardinality import Mathlib.Algebra.Algebra.Bilinear /-! # A "module topology" for modules over a topological ring If `R` is a topological ring acting on an additive abelian group `A`, we define the *module topology* to be the finest topology on `A` making both the maps `• : R × A → A` and `+ : A × A → A` continuous (with all the products having the product topology). Note that `- : A → A` is also automatically continuous as it is `a ↦ (-1) • a`. This topology was suggested by Will Sawin [here](https://mathoverflow.net/a/477763/1384). ## Mathematical details I (buzzard) don't know of any reference for this other than Sawin's mathoverflow answer, so I expand some of the details here. First note that the definition makes sense in far more generality (for example `R` just needs to be a topological space acting on an additive monoid). Next note that there *is* a finest topology with this property! Indeed, topologies on a fixed type form a complete lattice (infinite infs and sups exist). So if `τ` is the Inf of all the topologies on `A` which make `+` and `•` continuous, then the claim is that `+` and `•` are still continuous for `τ` (note that topologies are ordered so that finer topologies are smaller). To show `+ : A × A → A` is continuous we equivalently need to show that the pushforward of the product topology `τ × τ` along `+` is `≤ τ`, and because `τ` is the greatest lower bound of the topologies making `•` and `+` continuous, it suffices to show that it's `≤ σ` for any topology `σ` on `A` which makes `+` and `•` continuous. However pushforward and products are monotone, so `τ × τ ≤ σ × σ`, and the pushforward of `σ × σ` is `≤ σ` because that's precisely the statement that `+` is continuous for `σ`. The proof for `•` follows mutatis mutandis. A *topological module* for a topological ring `R` is an `R`-module `A` with a topology making `+` and `•` continuous. The discussion so far has shown that the module topology makes an `R`-module `A` into a topological module, and moreover is the finest topology with this property. A crucial observation is that if `M` is a topological `R`-module, if `A` is an `R`-module with no topology, and if `φ : A → M` is linear, then the pullback of `M`'s topology to `A` is a topology making `A` into a topological module. Let's for example check that `•` is continuous. If `U ⊆ A` is open then by definition of the pullback topology, `U = φ⁻¹(V)` for some open `V ⊆ M`, and now the pullback of `U` under `•` is just the pullback along the continuous map `id × φ : R × A → R × M` of the preimage of `V` under the continuous map `• : R × M → M`, so it's open. The proof for `+` is similar. As a consequence of this, we see that if `φ : A → M` is a linear map between topological `R`-modules modules and if `A` has the module topology, then `φ` is automatically continuous. Indeed the argument above shows that if `A → M` is linear then the module topology on `A` is `≤` the pullback of the module topology on `M` (because it's the inf of a set containing this topology) which is the definition of continuity. We also deduce that the module topology is a functor from the category of `R`-modules (`R` a topological ring) to the category of topological `R`-modules, and it is perhaps unsurprising that this is an adjoint to the forgetful functor. Indeed, if `A` is an `R`-module and `M` is a topological `R`-module, then the previous paragraph shows that the linear maps `A → M` are precisely the continuous linear maps from (`A` with its module topology) to `M`, so the module topology is a left adjoint to the forgetful functor. This file develops the theory of the module topology. ## Main theorems * `IsTopologicalSemiring.toIsModuleTopology : IsModuleTopology R R`. The module topology on `R` is `R`'s topology. * `IsModuleTopology.iso [IsModuleTopology R A] (e : A ≃L[R] B) : IsModuleTopology R B`. If `A` and `B` are `R`-modules with topologies, if `e` is a topological isomorphism between them, and if `A` has the module topology, then `B` has the module topology. * `IsModuleTopology.instProd` : If `M` and `N` are `R`-modules each equipped with the module topology, then the product topology on `M × N` is the module topology. * `IsModuleTopology.instPi` : Given a finite collection of `R`-modules each of which has the module topology, the product topology on the product module is the module topology. * `IsModuleTopology.isTopologicalRing` : If `D` is an `R`-algebra equipped with the module topology, and `D` is finite as an `R`-module, then `D` is a topological ring (that is, addition, negation and multiplication are continuous). Now say `φ : A →ₗ[R] B` is an `R`-linear map between `R`-modules equipped with the module topology. * `IsModuleTopology.continuous_of_linearMap φ` is the proof that `φ` is automatically continuous. * `IsModuleTopology.isQuotientMap_of_surjective (hφ : Function.Surjective φ)` is the proof that if furthermore `φ` is surjective then it is a quotient map, that is, the module topology on `B` is the pushforward of the module topology on `A`. Now say `ψ : A →ₗ[R] B →ₗ[R] C` is an `R`-bilinear map between `R`-modules equipped with the module topology. * `IsModuleTopology.continuous_bilinear_of_finite_left` : If `A` is finite then `A × B → C` is continuous. * `IsModuleTopology.continuous_bilinear_of_finite_right` : If `B` is finite then `A × B → C` is continuous. ## TODO * The module topology is a functor from the category of `R`-modules to the category of topological `R`-modules, and it's an adjoint to the forgetful functor. -/ section basics /- This section is just boilerplate, defining the module topology and making some infrastructure. Note that we don't even need that `R` is a ring in the main definitions, just that it acts on `A`. -/ variable (R : Type*) [TopologicalSpace R] (A : Type*) [Add A] [SMul R A] /-- The module topology, for a module `A` over a topological ring `R`. It's the finest topology making addition and the `R`-action continuous, or equivalently the finest topology making `A` into a topological `R`-module. More precisely it's the Inf of the set of topologies with these properties; theorems `continuousSMul` and `continuousAdd` show that the module topology also has these properties. -/ abbrev moduleTopology : TopologicalSpace A := sInf {t | @ContinuousSMul R A _ _ t ∧ @ContinuousAdd A t _} /-- A class asserting that the topology on a module over a topological ring `R` is the module topology. See `moduleTopology` for more discussion of the module topology. -/ class IsModuleTopology [τA : TopologicalSpace A] : Prop where /-- Note that this should not be used directly, and `eq_moduleTopology`, which takes `R` and `A` explicitly, should be used instead. -/ eq_moduleTopology' : τA = moduleTopology R A theorem eq_moduleTopology [τA : TopologicalSpace A] [IsModuleTopology R A] : τA = moduleTopology R A := IsModuleTopology.eq_moduleTopology' (R := R) (A := A) /-- Note that the topology isn't part of the discrimination key so this gets tried on every `IsModuleTopology` goal and hence the low priority. -/ instance (priority := low) {R : Type*} [TopologicalSpace R] {A : Type*} [Add A] [SMul R A] : letI := moduleTopology R A; IsModuleTopology R A := letI := moduleTopology R A; ⟨rfl⟩ /-- Scalar multiplication `• : R × A → A` is continuous if `R` is a topological ring, and `A` is an `R` module with the module topology. -/ theorem ModuleTopology.continuousSMul : @ContinuousSMul R A _ _ (moduleTopology R A) := /- Proof: We need to prove that the product topology is finer than the pullback of the module topology. But the module topology is an Inf and thus a limit, and pullback is a right adjoint, so it preserves limits. We must thus show that the product topology is finer than an Inf, so it suffices to show it's a lower bound, which is not hard. All this is wrapped into `continuousSMul_sInf`. -/ continuousSMul_sInf fun _ h ↦ h.1 /-- Addition `+ : A × A → A` is continuous if `R` is a topological ring, and `A` is an `R` module with the module topology. -/ theorem ModuleTopology.continuousAdd : @ContinuousAdd A (moduleTopology R A) _ := continuousAdd_sInf fun _ h ↦ h.2 instance IsModuleTopology.toContinuousSMul [TopologicalSpace A] [IsModuleTopology R A] : ContinuousSMul R A := eq_moduleTopology R A ▸ ModuleTopology.continuousSMul R A -- this can't be an instance because typeclass inference can't be expected to find `R`. theorem IsModuleTopology.toContinuousAdd [TopologicalSpace A] [IsModuleTopology R A] : ContinuousAdd A := eq_moduleTopology R A ▸ ModuleTopology.continuousAdd R A /-- The module topology is `≤` any topology making `A` into a topological module. -/ theorem moduleTopology_le [τA : TopologicalSpace A] [ContinuousSMul R A] [ContinuousAdd A] : moduleTopology R A ≤ τA := sInf_le ⟨inferInstance, inferInstance⟩ end basics namespace IsModuleTopology section basics variable {R : Type*} [TopologicalSpace R] {A : Type*} [Add A] [SMul R A] [τA : TopologicalSpace A] /-- If `A` is a topological `R`-module and the identity map from (`A` with its given topology) to (`A` with the module topology) is continuous, then the topology on `A` is the module topology. -/ theorem of_continuous_id [ContinuousAdd A] [ContinuousSMul R A] (h : @Continuous A A τA (moduleTopology R A) id) : IsModuleTopology R A where -- The topologies are equal because each is finer than the other. One inclusion -- follows from the continuity hypothesis; the other is because the module topology -- is the inf of all the topologies making `A` a topological module. eq_moduleTopology' := le_antisymm (continuous_id_iff_le.1 h) (moduleTopology_le _ _) /-- The zero module has the module topology. -/ instance instSubsingleton [Subsingleton A] : IsModuleTopology R A where eq_moduleTopology' := Subsingleton.elim _ _ end basics section iso variable {R : Type*} [τR : TopologicalSpace R] [Semiring R] variable {A : Type*} [AddCommMonoid A] [Module R A] [τA : TopologicalSpace A] [IsModuleTopology R A] variable {B : Type*} [AddCommMonoid B] [Module R B] [τB : TopologicalSpace B] /-- If `A` and `B` are `R`-modules, homeomorphic via an `R`-linear homeomorphism, and if `A` has the module topology, then so does `B`. -/ theorem iso (e : A ≃L[R] B) : IsModuleTopology R B where eq_moduleTopology' := by -- get these in before I start putting new topologies on A and B and have to use `@` let g : A →ₗ[R] B := e let g' : B →ₗ[R] A := e.symm let h : A →+ B := e let h' : B →+ A := e.symm simp_rw [e.toHomeomorph.symm.isInducing.1, eq_moduleTopology R A, moduleTopology, induced_sInf] apply congr_arg ext τ -- from this point on the definitions of `g`, `g'` etc above don't work without `@`. rw [Set.mem_image] constructor · rintro ⟨σ, ⟨hσ1, hσ2⟩, rfl⟩ exact ⟨continuousSMul_induced g'.toMulActionHom, continuousAdd_induced h'⟩ · rintro ⟨h1, h2⟩ use τ.induced e rw [induced_compose] refine ⟨⟨continuousSMul_induced g.toMulActionHom, continuousAdd_induced h⟩, ?_⟩ nth_rw 2 [← induced_id (t := τ)] simp end iso section self variable (R : Type*) [Semiring R] [τR : TopologicalSpace R] [IsTopologicalSemiring R] /-! We now fix once and for all a topological semiring `R`. We first prove that the module topology on `R` considered as a module over itself, is `R`'s topology. -/ /-- The topology on a topological semiring `R` agrees with the module topology when considering `R` as an `R`-module in the obvious way (i.e., via `Semiring.toModule`). -/ instance _root_.IsTopologicalSemiring.toIsModuleTopology : IsModuleTopology R R := by /- By a previous lemma it suffices to show that the identity from (R,usual) to (R, module topology) is continuous. -/ apply of_continuous_id /- The idea needed here is to rewrite the identity function as the composite of `r ↦ (r,1)` from `R` to `R × R`, and multiplication `R × R → R`. -/ rw [show (id : R → R) = (fun rs ↦ rs.1 • rs.2) ∘ (fun r ↦ (r, 1)) by ext; simp] /- It thus suffices to show that each of these maps are continuous. For this claim to even make sense, we need to topologise `R × R`. The trick is to do this by giving the first `R` the usual topology `τR` and the second `R` the module topology. To do this we have to "fight mathlib" a bit with `@`, because there is more than one topology on `R` here. -/ apply @Continuous.comp R (R × R) R τR (@instTopologicalSpaceProd R R τR (moduleTopology R R)) (moduleTopology R R) · /- The map R × R → R is `•`, so by a fundamental property of the module topology, this is continuous. -/ exact @continuous_smul _ _ _ _ (moduleTopology R R) <| ModuleTopology.continuousSMul .. · /- The map `R → R × R` sending `r` to `(r,1)` is a map into a product, so it suffices to show that each of the two factors is continuous. But the first is the identity function on `(R, usual topology)` and the second is a constant function. -/ exact @Continuous.prodMk _ _ _ _ (moduleTopology R R) _ _ _ continuous_id <| @continuous_const _ _ _ (moduleTopology R R) _ end self section MulOpposite variable (R : Type*) [Semiring R] [τR : TopologicalSpace R] [IsTopologicalSemiring R] /-- The module topology coming from the action of the topological ring `Rᵐᵒᵖ` on `R` (via `Semiring.toOppositeModule`, i.e. via `(op r) • m = m * r`) is `R`'s topology. -/ instance _root_.IsTopologicalSemiring.toOppositeIsModuleTopology : IsModuleTopology Rᵐᵒᵖ R := .iso (MulOpposite.opContinuousLinearEquiv Rᵐᵒᵖ).symm end MulOpposite section function variable {R : Type*} [τR : TopologicalSpace R] [Semiring R] variable {A : Type*} [AddCommMonoid A] [Module R A] [aA : TopologicalSpace A] [IsModuleTopology R A] variable {B : Type*} [AddCommMonoid B] [Module R B] [aB : TopologicalSpace B] [ContinuousAdd B] [ContinuousSMul R B] /-- Every `R`-linear map between two topological `R`-modules, where the source has the module topology, is continuous. -/ @[fun_prop, continuity] theorem continuous_of_distribMulActionHom (φ : A →+[R] B) : Continuous φ := by -- the proof: We know that `+ : B × B → B` and `• : R × B → B` are continuous for the module -- topology on `B`, and two earlier theorems (`continuousSMul_induced` and -- `continuousAdd_induced`) say that hence `+` and `•` on `A` are continuous if `A` -- is given the topology induced from `φ`. Hence the module topology is finer than -- the induced topology, and so the function is continuous. rw [eq_moduleTopology R A, continuous_iff_le_induced] exact sInf_le <| ⟨continuousSMul_induced (φ.toMulActionHom), continuousAdd_induced φ.toAddMonoidHom⟩ @[fun_prop, continuity] theorem continuous_of_linearMap (φ : A →ₗ[R] B) : Continuous φ := continuous_of_distribMulActionHom φ.toDistribMulActionHom variable (R) in theorem continuous_neg (C : Type*) [AddCommGroup C] [Module R C] [TopologicalSpace C] [IsModuleTopology R C] : Continuous (fun a ↦ -a : C → C) := haveI : ContinuousAdd C := IsModuleTopology.toContinuousAdd R C continuous_of_linearMap (LinearEquiv.neg R).toLinearMap variable (R) in theorem continuousNeg (C : Type*) [AddCommGroup C] [Module R C] [TopologicalSpace C] [IsModuleTopology R C] : ContinuousNeg C where continuous_neg := continuous_neg R C variable (R) in theorem topologicalAddGroup (C : Type*) [AddCommGroup C] [Module R C] [TopologicalSpace C] [IsModuleTopology R C] : IsTopologicalAddGroup C where continuous_add := (IsModuleTopology.toContinuousAdd R C).1 continuous_neg := continuous_neg R C @[fun_prop, continuity] theorem continuous_of_ringHom {R A B} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [TopologicalSpace R] [TopologicalSpace A] [IsModuleTopology R A] [TopologicalSpace B] [IsTopologicalSemiring B] (φ : A →+* B) (hφ : Continuous (φ.comp (algebraMap R A))) : Continuous φ := by let inst := Module.compHom B (φ.comp (algebraMap R A)) let φ' : A →ₗ[R] B := ⟨φ, fun r m ↦ by simp [Algebra.smul_def]; rfl⟩ have : ContinuousSMul R B := ⟨(hφ.comp continuous_fst).mul continuous_snd⟩ exact continuous_of_linearMap φ' end function section surjection variable {R : Type*} [τR : TopologicalSpace R] [Ring R] variable {A : Type*} [AddCommGroup A] [Module R A] [TopologicalSpace A] [IsModuleTopology R A] variable {B : Type*} [AddCommGroup B] [Module R B] open Topology in /-- A linear surjection between modules with the module topology is a quotient map. Equivalently, the pushforward of the module topology along a surjective linear map is again the module topology. -/ theorem isQuotientMap_of_surjective [τB : TopologicalSpace B] [IsModuleTopology R B] {φ : A →ₗ[R] B} (hφ : Function.Surjective φ) : IsQuotientMap φ where surjective := hφ eq_coinduced := by -- We need to prove that the topology on B is coinduced from that on A. -- First tell the typeclass inference system that A and B are topological groups. haveI := topologicalAddGroup R A haveI := topologicalAddGroup R B -- Because φ is linear, it's continuous for the module topologies (by a previous result). have this : Continuous φ := continuous_of_linearMap φ -- So the coinduced topology is finer than the module topology on B. rw [continuous_iff_coinduced_le] at this -- So STP the module topology on B is ≤ the topology coinduced from A refine le_antisymm ?_ this rw [eq_moduleTopology R B] -- Now let's remove B's topology from the typeclass system clear! τB -- and replace it with the coinduced topology (which will be the same, but that's what we're -- trying to prove). This means we don't have to fight with the typeclass system. letI : TopologicalSpace B := .coinduced φ inferInstance -- With this new topology on `B`, φ is a quotient map by definition, -- and hence an open quotient map by a result in the library. have hφo : IsOpenQuotientMap φ := AddMonoidHom.isOpenQuotientMap_of_isQuotientMap ⟨hφ, rfl⟩ -- We're trying to prove the module topology on B is ≤ the coinduced topology. -- But recall that the module topology is the Inf of the topologies on B making addition -- and scalar multiplication continuous, so it suffices to prove -- that the coinduced topology on B has these properties. refine sInf_le ⟨?_, ?_⟩ · -- In this branch, we prove that `• : R × B → B` is continuous for the coinduced topology. apply ContinuousSMul.mk -- We know that `• : R × A → A` is continuous, by assumption. obtain ⟨hA⟩ : ContinuousSMul R A := inferInstance /- By linearity of φ, this diagram commutes: R × A --(•)--> A | | |id × φ |φ | | \/ \/ R × B --(•)--> B -/ have hφ2 : (fun p ↦ p.1 • p.2 : R × B → B) ∘ (Prod.map id φ) = φ ∘ (fun p ↦ p.1 • p.2 : R × A → A) := by ext; simp -- Furthermore, the identity from R to R is an open quotient map as is `φ`, -- so the product `id × φ` is an open quotient map, by a result in the library. have hoq : IsOpenQuotientMap (_ : R × A → R × B) := IsOpenQuotientMap.prodMap .id hφo -- This is the left map in the diagram. So by a standard fact about open quotient maps, -- to prove that the bottom map is continuous, it suffices to prove -- that the diagonal map is continuous. rw [← hoq.continuous_comp_iff] -- but the diagonal is the composite of the continuous maps `φ` and `• : R × A → A` rw [hφ2] -- so we're done exact Continuous.comp hφo.continuous hA · /- In this branch we show that addition is continuous for the coinduced topology on `B`. The argument is basically the same, this time using commutativity of A × A --(+)--> A | | |φ × φ |φ | | \/ \/ B × B --(+)--> B -/ apply ContinuousAdd.mk obtain ⟨hA⟩ := IsModuleTopology.toContinuousAdd R A have hφ2 : (fun p ↦ p.1 + p.2 : B × B → B) ∘ (Prod.map φ φ) = φ ∘ (fun p ↦ p.1 + p.2 : A × A → A) := by ext; simp rw [← (IsOpenQuotientMap.prodMap hφo hφo).continuous_comp_iff, hφ2] exact Continuous.comp hφo.continuous hA lemma _root_.ModuleTopology.eq_coinduced_of_surjective {φ : A →ₗ[R] B} (hφ : Function.Surjective φ) : moduleTopology R B = TopologicalSpace.coinduced φ inferInstance := by letI : TopologicalSpace B := moduleTopology R B haveI : IsModuleTopology R B := ⟨rfl⟩ exact (isQuotientMap_of_surjective hφ).eq_coinduced end surjection section Prod variable {R : Type*} [TopologicalSpace R] [Semiring R] variable {M : Type*} [AddCommMonoid M] [Module R M] [TopologicalSpace M] [IsModuleTopology R M] variable {N : Type*} [AddCommMonoid N] [Module R N] [TopologicalSpace N] [IsModuleTopology R N] /-- The product of the module topologies for two modules over a topological ring is the module topology. -/ instance instProd : IsModuleTopology R (M × N) := by constructor have : ContinuousAdd M := toContinuousAdd R M have : ContinuousAdd N := toContinuousAdd R N -- In this proof, `M × N` always denotes the product with its *product* topology. -- Addition `(M × N)² → M × N` and scalar multiplication `R × (M × N) → M × N` -- are continuous for the product topology (by results in the library), so the module topology -- on `M × N` is finer than the product topology (as it's the Inf of such topologies). -- It thus remains to show that the product topology is finer than the module topology. refine le_antisymm ?_ <| sInf_le ⟨Prod.continuousSMul, Prod.continuousAdd⟩ -- Or equivalently, if `P` denotes `M × N` with the module topology, let P := M × N let τP : TopologicalSpace P := moduleTopology R P have : IsModuleTopology R P := ⟨rfl⟩ have : ContinuousAdd P := ModuleTopology.continuousAdd R P -- and if `i` denotes the identity map from `M × N` to `P` let i : M × N → P := id -- then we need to show that `i` is continuous. rw [← continuous_id_iff_le] change @Continuous (M × N) P instTopologicalSpaceProd τP i -- But `i` can be written as (m, n) ↦ (m, 0) + (0, n) -- or equivalently as i₁ ∘ pr₁ + i₂ ∘ pr₂, where prᵢ are the projections, -- the iⱼ's are linear inclusions M → P and N → P, and the addition is P × P → P. let i₁ : M →ₗ[R] P := LinearMap.inl R M N let i₂ : N →ₗ[R] P := LinearMap.inr R M N rw [show (i : M × N → P) = (fun abcd ↦ abcd.1 + abcd.2 : P × P → P) ∘ (fun ab ↦ (i₁ ab.1, i₂ ab.2)) by ext ⟨a, b⟩ <;> aesop] -- and these maps are all continuous, hence `i` is too fun_prop end Prod section Pi variable {R : Type*} [TopologicalSpace R] [Semiring R] variable {ι : Type*} [Finite ι] {A : ι → Type*} [∀ i, AddCommMonoid (A i)] [∀ i, Module R (A i)] [∀ i, TopologicalSpace (A i)] [∀ i, IsModuleTopology R (A i)] /-- The product of the module topologies for a finite family of modules over a topological ring is the module topology. -/ instance instPi : IsModuleTopology R (∀ i, A i) := by -- This is an easy induction on the size of the finite type, given the result -- for binary products above. We use a "decategorified" induction principle for finite types. induction ι using Finite.induction_empty_option · -- invariance under equivalence of the finite type we're taking the product over case of_equiv X Y e _ _ _ _ _ => exact iso (ContinuousLinearEquiv.piCongrLeft R A e) · -- empty case infer_instance · -- "inductive step" is to check for product over `Option ι` case when known for product over `ι` case h_option ι _ hind _ _ _ _ => -- `Option ι` is a `Sum` of `ι` and `Unit` let e : Option ι ≃ ι ⊕ Unit := Equiv.optionEquivSumPUnit ι -- so suffices to check for a product of modules over `ι ⊕ Unit` suffices IsModuleTopology R ((i' : ι ⊕ Unit) → A (e.symm i')) from iso (.piCongrLeft R A e.symm) -- but such a product is isomorphic to a binary product -- of (product over `ι`) and (product over `Unit`) suffices IsModuleTopology R (((s : ι) → A (e.symm (Sum.inl s))) × ((t : Unit) → A (e.symm (Sum.inr t)))) from iso (ContinuousLinearEquiv.sumPiEquivProdPi R ι Unit _).symm -- The product over `ι` has the module topology by the inductive hypothesis, -- and the product over `Unit` is just a module which is assumed to have the module topology have := iso (ContinuousLinearEquiv.piUnique R (fun t ↦ A (e.symm (Sum.inr t)))).symm -- so the result follows from the previous lemma (binary products). infer_instance end Pi section bilinear section semiring variable {R : Type*} [TopologicalSpace R] [CommSemiring R] variable {B : Type*} [AddCommMonoid B] [Module R B] [TopologicalSpace B] [IsModuleTopology R B] variable {C : Type*} [AddCommMonoid C] [Module R C] [TopologicalSpace C] [IsModuleTopology R C] /-- If `n` is finite and `B`,`C` are `R`-modules with the module topology, then any bilinear map `Rⁿ × B → C` is automatically continuous. Note that whilst this result works for semirings, for rings this result is superseded by `IsModuleTopology.continuous_bilinear_of_finite_left`. -/ theorem continuous_bilinear_of_pi_fintype (ι : Type*) [Finite ι] (bil : (ι → R) →ₗ[R] B →ₗ[R] C) : Continuous (fun ab ↦ bil ab.1 ab.2 : ((ι → R) × B → C)) := by classical cases nonempty_fintype ι -- The map in question, `(f, b) ↦ bil f b`, is easily checked to be equal to -- `(f, b) ↦ ∑ᵢ f i • bil (single i 1) b` where `single i 1 : ι → R` sends `i` to `1` and -- everything else to `0`. have h : (fun fb ↦ bil fb.1 fb.2 : ((ι → R) × B → C)) = (fun fb ↦ ∑ i, ((fb.1 i) • (bil (Finsupp.single i 1) fb.2) : C)) := by ext ⟨f, b⟩ nth_rw 1 [← Finset.univ_sum_single f] simp_rw [← Finsupp.single_eq_pi_single, map_sum, LinearMap.coeFn_sum, Finset.sum_apply] refine Finset.sum_congr rfl (fun x _ ↦ ?_) rw [← Finsupp.smul_single_one] push_cast simp rw [h] -- But this map is obviously continuous, because for a fixed `i`, `bil (single i 1)` is -- linear and thus continuous, and scalar multiplication and finite sums are continuous haveI : ContinuousAdd C := toContinuousAdd R C fun_prop end semiring section ring variable {R : Type*} [TopologicalSpace R] [CommRing R] [IsTopologicalRing R] variable {A : Type*} [AddCommGroup A] [Module R A] [aA : TopologicalSpace A] [IsModuleTopology R A] variable {B : Type*} [AddCommGroup B] [Module R B] [aB : TopologicalSpace B] [IsModuleTopology R B] variable {C : Type*} [AddCommGroup C] [Module R C] [aC : TopologicalSpace C] [IsModuleTopology R C] /-- If `A`, `B` and `C` have the module topology, and if furthermore `A` is a finite `R`-module, then any bilinear map `A × B → C` is automatically continuous -/ @[continuity, fun_prop] theorem continuous_bilinear_of_finite_left [Module.Finite R A] (bil : A →ₗ[R] B →ₗ[R] C) : Continuous (fun ab ↦ bil ab.1 ab.2 : (A × B → C)) := by -- `A` is finite and hence admits a surjection from `Rⁿ` for some finite `n`. obtain ⟨m, f, hf⟩ := Module.Finite.exists_fin' R A -- The induced linear map `φ : Rⁿ × B → A × B` is surjective let bil' : (Fin m → R) →ₗ[R] B →ₗ[R] C := bil.comp f let φ := f.prodMap (LinearMap.id : B →ₗ[R] B) have hφ : Function.Surjective φ := Function.Surjective.prodMap hf fun b ↦ ⟨b, rfl⟩ -- ... and thus a quotient map, so it suffices to prove that the composite `Rⁿ × B → C` is -- continuous. rw [Topology.IsQuotientMap.continuous_iff (isQuotientMap_of_surjective hφ)] -- But this follows from an earlier result. exact continuous_bilinear_of_pi_fintype (Fin m) bil' /-- If `A`, `B` and `C` have the module topology, and if furthermore `B` is a finite `R`-module, then any bilinear map `A × B → C` is automatically continuous -/ @[continuity, fun_prop] theorem continuous_bilinear_of_finite_right [Module.Finite R B] (bil : A →ₗ[R] B →ₗ[R] C) : Continuous (fun ab ↦ bil ab.1 ab.2 : (A × B → C)) := by -- We already proved this when `A` is finite instead of `B`, so it's obvious by symmetry rw [show (fun ab ↦ bil ab.1 ab.2 : (A × B → C)) = ((fun ba ↦ bil.flip ba.1 ba.2 : (B × A → C)) ∘ (Prod.swap : A × B → B × A)) by ext; simp] fun_prop end ring end bilinear section algebra variable (R : Type*) [CommRing R] [TopologicalSpace R] [IsTopologicalRing R] (D : Type*) [Ring D] [Algebra R D] [Module.Finite R D] [TopologicalSpace D] [IsModuleTopology R D] include R in /-- If `D` is an `R`-algebra, finite as an `R`-module, and if `D` has the module topology, then multiplication on `D` is automatically continuous. -/ @[continuity, fun_prop] theorem continuous_mul_of_finite : Continuous (fun ab ↦ ab.1 * ab.2 : D × D → D) := -- Proof: multiplication is bilinear so this follows from previous results. continuous_bilinear_of_finite_left (LinearMap.mul R D) include R in /-- If `R` is a topological ring and `D` is an `R`-algebra, finite as an `R`-module, and if `D` is given the module topology, then `D` is a topological ring. -/ theorem isTopologicalRing : IsTopologicalRing D where -- Proof: we have already checked all the axioms above. continuous_add := (toContinuousAdd R D).1 continuous_mul := continuous_mul_of_finite R D continuous_neg := continuous_neg R D end algebra end IsModuleTopology
Basic.lean
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.LinearAlgebra.Countable import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.MeasureTheory.Group.FundamentalDomain import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.RingTheory.Localization.Module /-! # ℤ-lattices Let `E` be a finite dimensional vector space over a `NormedLinearOrderedField` `K` with a solid norm that is also a `FloorRing`, e.g. `ℝ`. A (full) `ℤ`-lattice `L` of `E` is a discrete subgroup of `E` such that `L` spans `E` over `K`. A `ℤ`-lattice `L` can be defined in two ways: * For `b` a basis of `E`, then `L = Submodule.span ℤ (Set.range b)` is a ℤ-lattice of `E` * As a `ℤ-submodule` of `E` with the additional properties: * `DiscreteTopology L`, that is `L` is discrete * `Submodule.span ℝ (L : Set E) = ⊤`, that is `L` spans `E` over `K`. Results about the first point of view are in the `ZSpan` namespace and results about the second point of view are in the `ZLattice` namespace. ## Main results and definitions * `ZSpan.isAddFundamentalDomain`: for a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that the set defined by `ZSpan.fundamentalDomain` is a fundamental domain. * `ZLattice.module_free`: a `ℤ`-submodule of `E` that is discrete and spans `E` over `K` is a free `ℤ`-module * `ZLattice.rank`: a `ℤ`-submodule of `E` that is discrete and spans `E` over `K` is free of `ℤ`-rank equal to the `K`-rank of `E` * `ZLattice.comap`: for `e : E → F` a linear map and `L : Submodule ℤ E`, define the pullback of `L` by `e`. If `L` is a `IsZLattice` and `e` is a continuous linear equiv, then it is also a `IsZLattice`, see `instIsZLatticeComap`. ## Note There is also `Submodule.IsLattice` which has slightly different applications. There no topology is needed and the discrete condition is replaced by finitely generated. ## Implementation Notes A `ZLattice` could be defined either as a `AddSubgroup E` or a `Submodule ℤ E`. However, the module aspect appears to be the more useful one (especially in computations involving basis) and is also consistent with the `ZSpan` construction of `ℤ`-lattices. -/ noncomputable section namespace ZSpan open MeasureTheory MeasurableSet Module Submodule Bornology variable {E ι : Type*} section NormedLatticeField variable {K : Type*} [NormedField K] variable [NormedAddCommGroup E] [NormedSpace K E] variable (b : Basis ι K E) theorem span_top : span K (span ℤ (Set.range b) : Set E) = ⊤ := by simp [span_span_of_tower] theorem map {F : Type*} [AddCommGroup F] [Module K F] (f : E ≃ₗ[K] F) : Submodule.map (f.restrictScalars ℤ) (span ℤ (Set.range b)) = span ℤ (Set.range (b.map f)) := by simp_rw [Submodule.map_span, LinearEquiv.restrictScalars_apply, Basis.coe_map, Set.range_comp] open scoped Pointwise in theorem smul {c : K} (hc : c ≠ 0) : c • span ℤ (Set.range b) = span ℤ (Set.range (b.isUnitSMul (fun _ ↦ hc.isUnit))) := by rw [smul_span, Set.smul_set_range] congr! rw [Basis.isUnitSMul_apply] variable [LinearOrder K] /-- The fundamental domain of the ℤ-lattice spanned by `b`. See `ZSpan.isAddFundamentalDomain` for the proof that it is a fundamental domain. -/ def fundamentalDomain : Set E := {m | ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1} @[simp] theorem mem_fundamentalDomain {m : E} : m ∈ fundamentalDomain b ↔ ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1 := Iff.rfl theorem map_fundamentalDomain {F : Type*} [NormedAddCommGroup F] [NormedSpace K F] (f : E ≃ₗ[K] F) : f '' (fundamentalDomain b) = fundamentalDomain (b.map f) := by ext x rw [mem_fundamentalDomain, Basis.map_repr, LinearEquiv.trans_apply, ← mem_fundamentalDomain, show f.symm x = f.toEquiv.symm x by rfl, ← Set.mem_image_equiv] rfl @[simp] theorem fundamentalDomain_reindex {ι' : Type*} (e : ι ≃ ι') : fundamentalDomain (b.reindex e) = fundamentalDomain b := by ext simp_rw [mem_fundamentalDomain, Basis.repr_reindex_apply] rw [Equiv.forall_congr' e] simp_rw [implies_true] variable [IsStrictOrderedRing K] lemma fundamentalDomain_pi_basisFun [Fintype ι] : fundamentalDomain (Pi.basisFun ℝ ι) = Set.pi Set.univ fun _ : ι ↦ Set.Ico (0 : ℝ) 1 := by ext; simp variable [FloorRing K] section Fintype variable [Fintype ι] /-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained by rounding down its coordinates on the basis `b`. -/ def floor (m : E) : span ℤ (Set.range b) := ∑ i, ⌊b.repr m i⌋ • b.restrictScalars ℤ i /-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained by rounding up its coordinates on the basis `b`. -/ def ceil (m : E) : span ℤ (Set.range b) := ∑ i, ⌈b.repr m i⌉ • b.restrictScalars ℤ i @[simp] theorem repr_floor_apply (m : E) (i : ι) : b.repr (floor b m) i = ⌊b.repr m i⌋ := by classical simp only [floor, ← Int.cast_smul_eq_zsmul K, b.repr.map_smul, Finsupp.single_apply, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum, Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum] @[simp] theorem repr_ceil_apply (m : E) (i : ι) : b.repr (ceil b m) i = ⌈b.repr m i⌉ := by classical simp only [ceil, ← Int.cast_smul_eq_zsmul K, b.repr.map_smul, Finsupp.single_apply, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum, Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum] @[simp] theorem floor_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (floor b m : E) = m := by apply b.ext_elem simp_rw [repr_floor_apply b] intro i obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i rw [← hz] exact congr_arg (Int.cast : ℤ → K) (Int.floor_intCast z) @[simp] theorem ceil_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (ceil b m : E) = m := by apply b.ext_elem simp_rw [repr_ceil_apply b] intro i obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i rw [← hz] exact congr_arg (Int.cast : ℤ → K) (Int.ceil_intCast z) /-- The map that sends a vector `E` to the `fundamentalDomain` of the lattice, see `ZSpan.fract_mem_fundamentalDomain`, and `fractRestrict` for the map with the codomain restricted to `fundamentalDomain`. -/ def fract (m : E) : E := m - floor b m theorem fract_apply (m : E) : fract b m = m - floor b m := rfl @[simp] theorem repr_fract_apply (m : E) (i : ι) : b.repr (fract b m) i = Int.fract (b.repr m i) := by rw [fract, map_sub, Finsupp.coe_sub, Pi.sub_apply, repr_floor_apply, Int.fract] @[simp] theorem fract_fract (m : E) : fract b (fract b m) = fract b m := Basis.ext_elem b fun _ => by classical simp only [repr_fract_apply, Int.fract_fract] @[simp] theorem fract_zSpan_add (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) : fract b (v + m) = fract b m := by classical refine (Basis.ext_elem_iff b).mpr fun i => ?_ simp_rw [repr_fract_apply, Int.fract_eq_fract] use (b.restrictScalars ℤ).repr ⟨v, h⟩ i rw [map_add, Finsupp.coe_add, Pi.add_apply, add_tsub_cancel_right, ← eq_intCast (algebraMap ℤ K) _, Basis.restrictScalars_repr_apply, coe_mk] @[simp] theorem fract_add_ZSpan (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) : fract b (m + v) = fract b m := by rw [add_comm, fract_zSpan_add b m h] variable {b} in theorem fract_eq_self {x : E} : fract b x = x ↔ x ∈ fundamentalDomain b := by classical simp only [Basis.ext_elem_iff b, repr_fract_apply, Int.fract_eq_self, mem_fundamentalDomain, Set.mem_Ico] theorem fract_mem_fundamentalDomain (x : E) : fract b x ∈ fundamentalDomain b := fract_eq_self.mp (fract_fract b _) /-- The map `fract` with codomain restricted to `fundamentalDomain`. -/ def fractRestrict (x : E) : fundamentalDomain b := ⟨fract b x, fract_mem_fundamentalDomain b x⟩ theorem fractRestrict_surjective : Function.Surjective (fractRestrict b) := fun x => ⟨↑x, Subtype.eq (fract_eq_self.mpr (Subtype.mem x))⟩ @[simp] theorem fractRestrict_apply (x : E) : (fractRestrict b x : E) = fract b x := rfl theorem fract_eq_fract (m n : E) : fract b m = fract b n ↔ -m + n ∈ span ℤ (Set.range b) := by classical rw [eq_comm, Basis.ext_elem_iff b] simp_rw [repr_fract_apply, Int.fract_eq_fract, eq_comm, Basis.mem_span_iff_repr_mem, sub_eq_neg_add, map_add, map_neg, Finsupp.coe_add, Finsupp.coe_neg, Pi.add_apply, Pi.neg_apply, ← eq_intCast (algebraMap ℤ K) _, Set.mem_range] theorem norm_fract_le [HasSolidNorm K] (m : E) : ‖fract b m‖ ≤ ∑ i, ‖b i‖ := by classical calc ‖fract b m‖ = ‖∑ i, b.repr (fract b m) i • b i‖ := by rw [b.sum_repr] _ = ‖∑ i, Int.fract (b.repr m i) • b i‖ := by simp_rw [repr_fract_apply] _ ≤ ∑ i, ‖Int.fract (b.repr m i) • b i‖ := norm_sum_le _ _ _ = ∑ i, ‖Int.fract (b.repr m i)‖ * ‖b i‖ := by simp_rw [norm_smul] _ ≤ ∑ i, ‖b i‖ := Finset.sum_le_sum fun i _ => ?_ suffices ‖Int.fract ((b.repr m) i)‖ ≤ 1 by convert mul_le_mul_of_nonneg_right this (norm_nonneg _ : 0 ≤ ‖b i‖) exact (one_mul _).symm rw [(norm_one.symm : 1 = ‖(1 : K)‖)] apply norm_le_norm_of_abs_le_abs rw [abs_one, Int.abs_fract] exact le_of_lt (Int.fract_lt_one _) section Unique variable [Unique ι] @[simp] theorem coe_floor_self (k : K) : (floor (Basis.singleton ι K) k : K) = ⌊k⌋ := Basis.ext_elem (Basis.singleton ι K) fun _ => by rw [repr_floor_apply, Basis.singleton_repr, Basis.singleton_repr] @[simp] theorem coe_fract_self (k : K) : (fract (Basis.singleton ι K) k : K) = Int.fract k := Basis.ext_elem (Basis.singleton ι K) fun _ => by rw [repr_fract_apply, Basis.singleton_repr, Basis.singleton_repr] end Unique end Fintype theorem fundamentalDomain_isBounded [Finite ι] [HasSolidNorm K] : IsBounded (fundamentalDomain b) := by cases nonempty_fintype ι refine isBounded_iff_forall_norm_le.2 ⟨∑ j, ‖b j‖, fun x hx ↦ ?_⟩ rw [← fract_eq_self.mpr hx] apply norm_fract_le theorem vadd_mem_fundamentalDomain [Fintype ι] (y : span ℤ (Set.range b)) (x : E) : y +ᵥ x ∈ fundamentalDomain b ↔ y = -floor b x := by rw [Subtype.ext_iff, ← add_right_inj x, NegMemClass.coe_neg, ← sub_eq_add_neg, ← fract_apply, ← fract_zSpan_add b _ (Subtype.mem y), add_comm, ← vadd_eq_add, ← vadd_def, eq_comm, ← fract_eq_self] theorem exist_unique_vadd_mem_fundamentalDomain [Finite ι] (x : E) : ∃! v : span ℤ (Set.range b), v +ᵥ x ∈ fundamentalDomain b := by cases nonempty_fintype ι refine ⟨-floor b x, ?_, fun y h => ?_⟩ · exact (vadd_mem_fundamentalDomain b (-floor b x) x).mpr rfl · exact (vadd_mem_fundamentalDomain b y x).mp h /-- The map `ZSpan.fractRestrict` defines an equiv map between `E ⧸ span ℤ (Set.range b)` and `ZSpan.fundamentalDomain b`. -/ def quotientEquiv [Fintype ι] : E ⧸ span ℤ (Set.range b) ≃ (fundamentalDomain b) := by refine Equiv.ofBijective ?_ ⟨fun x y => ?_, fun x => ?_⟩ · refine fun q => Quotient.liftOn q (fractRestrict b) (fun _ _ h => ?_) rw [Subtype.mk.injEq, fractRestrict_apply, fractRestrict_apply, fract_eq_fract] exact QuotientAddGroup.leftRel_apply.mp h · refine Quotient.inductionOn₂ x y (fun _ _ hxy => ?_) rw [Quotient.liftOn_mk (s := quotientRel (span ℤ (Set.range b))), fractRestrict, Quotient.liftOn_mk (s := quotientRel (span ℤ (Set.range b))), fractRestrict, Subtype.mk.injEq] at hxy apply Quotient.sound' rwa [QuotientAddGroup.leftRel_apply, mem_toAddSubgroup, ← fract_eq_fract] · obtain ⟨a, rfl⟩ := fractRestrict_surjective b x exact ⟨Quotient.mk'' a, rfl⟩ @[simp] theorem quotientEquiv_apply_mk [Fintype ι] (x : E) : quotientEquiv b (Submodule.Quotient.mk x) = fractRestrict b x := rfl @[simp] theorem quotientEquiv.symm_apply [Fintype ι] (x : fundamentalDomain b) : (quotientEquiv b).symm x = Submodule.Quotient.mk ↑x := by rw [Equiv.symm_apply_eq, quotientEquiv_apply_mk b ↑x, Subtype.ext_iff, fractRestrict_apply] exact (fract_eq_self.mpr x.prop).symm end NormedLatticeField section Real theorem discreteTopology_pi_basisFun [Finite ι] : DiscreteTopology (span ℤ (Set.range (Pi.basisFun ℝ ι))) := by cases nonempty_fintype ι refine discreteTopology_iff_isOpen_singleton_zero.mpr ⟨Metric.ball 0 1, Metric.isOpen_ball, ?_⟩ ext x rw [Set.mem_preimage, mem_ball_zero_iff, pi_norm_lt_iff zero_lt_one, Set.mem_singleton_iff] simp_rw [← coe_eq_zero, funext_iff, Pi.zero_apply, Real.norm_eq_abs] refine forall_congr' (fun i => ?_) rsuffices ⟨y, hy⟩ : ∃ (y : ℤ), (y : ℝ) = (x : ι → ℝ) i · rw [← hy, ← Int.cast_abs, ← Int.cast_one, Int.cast_lt, Int.abs_lt_one_iff, Int.cast_eq_zero] exact ((Pi.basisFun ℝ ι).mem_span_iff_repr_mem ℤ x).mp (SetLike.coe_mem x) i variable [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ι ℝ E) theorem fundamentalDomain_subset_parallelepiped [Fintype ι] : fundamentalDomain b ⊆ parallelepiped b := by rw [fundamentalDomain, parallelepiped_basis_eq, Set.setOf_subset_setOf] exact fun _ h i ↦ Set.Ico_subset_Icc_self (h i) instance [Finite ι] : DiscreteTopology (span ℤ (Set.range b)) := by have h : Set.MapsTo b.equivFun (span ℤ (Set.range b)) (span ℤ (Set.range (Pi.basisFun ℝ ι))) := by intro _ hx rwa [SetLike.mem_coe, Basis.mem_span_iff_repr_mem] at hx ⊢ convert DiscreteTopology.of_continuous_injective ((continuous_equivFun_basis b).restrict h) ?_ · exact discreteTopology_pi_basisFun · refine Subtype.map_injective _ (Basis.equivFun b).injective instance [Finite ι] : DiscreteTopology (span ℤ (Set.range b)).toAddSubgroup := inferInstanceAs <| DiscreteTopology (span ℤ (Set.range b)) theorem setFinite_inter [ProperSpace E] [Finite ι] {s : Set E} (hs : Bornology.IsBounded s) : Set.Finite (s ∩ span ℤ (Set.range b)) := by have : DiscreteTopology (span ℤ (Set.range b)) := inferInstance refine Metric.finite_isBounded_inter_isClosed hs ?_ rw [← coe_toAddSubgroup] exact AddSubgroup.isClosed_of_discrete @[measurability] theorem fundamentalDomain_measurableSet [MeasurableSpace E] [OpensMeasurableSpace E] [Finite ι] : MeasurableSet (fundamentalDomain b) := by cases nonempty_fintype ι haveI : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b let D : Set (ι → ℝ) := Set.pi Set.univ fun _ : ι => Set.Ico (0 : ℝ) 1 rw [(_ : fundamentalDomain b = b.equivFun.toLinearMap ⁻¹' D)] · refine measurableSet_preimage (LinearMap.continuous_of_finiteDimensional _).measurable ?_ exact MeasurableSet.pi Set.countable_univ fun _ _ => measurableSet_Ico · ext simp only [D, fundamentalDomain, Set.mem_Ico, Set.mem_setOf_eq, LinearEquiv.coe_coe, Set.mem_preimage, Basis.equivFun_apply, Set.mem_pi, Set.mem_univ, forall_true_left] /-- For a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that the set defined by `ZSpan.fundamentalDomain` is a fundamental domain. -/ protected theorem isAddFundamentalDomain [Finite ι] [MeasurableSpace E] [OpensMeasurableSpace E] (μ : Measure E) : IsAddFundamentalDomain (span ℤ (Set.range b)) (fundamentalDomain b) μ := by cases nonempty_fintype ι exact IsAddFundamentalDomain.mk' (nullMeasurableSet (fundamentalDomain_measurableSet b)) fun x => exist_unique_vadd_mem_fundamentalDomain b x /-- A version of `ZSpan.isAddFundamentalDomain` for `AddSubgroup`. -/ protected theorem isAddFundamentalDomain' [Finite ι] [MeasurableSpace E] [OpensMeasurableSpace E] (μ : Measure E) : IsAddFundamentalDomain (span ℤ (Set.range b)).toAddSubgroup (fundamentalDomain b) μ := ZSpan.isAddFundamentalDomain b μ theorem measure_fundamentalDomain_ne_zero [Finite ι] [MeasurableSpace E] [BorelSpace E] {μ : Measure E} [Measure.IsAddHaarMeasure μ] : μ (fundamentalDomain b) ≠ 0 := by convert (ZSpan.isAddFundamentalDomain b μ).measure_ne_zero (NeZero.ne μ) exact inferInstanceAs <| VAddInvariantMeasure (span ℤ (Set.range b)).toAddSubgroup E μ theorem measure_fundamentalDomain [Fintype ι] [DecidableEq ι] [MeasurableSpace E] (μ : Measure E) [BorelSpace E] [Measure.IsAddHaarMeasure μ] (b₀ : Basis ι ℝ E) : μ (fundamentalDomain b) = ENNReal.ofReal |b₀.det b| * μ (fundamentalDomain b₀) := by have : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b convert μ.addHaar_preimage_linearEquiv (b.equiv b₀ (Equiv.refl ι)) (fundamentalDomain b₀) · rw [Set.eq_preimage_iff_image_eq (LinearEquiv.bijective _), map_fundamentalDomain, Basis.map_equiv, Equiv.refl_symm, Basis.reindex_refl] · simp theorem measureReal_fundamentalDomain [Fintype ι] [DecidableEq ι] [MeasurableSpace E] (μ : Measure E) [BorelSpace E] [Measure.IsAddHaarMeasure μ] (b₀ : Basis ι ℝ E) : μ.real (fundamentalDomain b) = |b₀.det b| * μ.real (fundamentalDomain b₀) := by simp [measureReal_def, measure_fundamentalDomain b μ b₀] @[simp] theorem volume_fundamentalDomain [Fintype ι] [DecidableEq ι] (b : Basis ι ℝ (ι → ℝ)) : volume (fundamentalDomain b) = ENNReal.ofReal |(Matrix.of b).det| := by rw [measure_fundamentalDomain b volume (b₀ := Pi.basisFun ℝ ι), fundamentalDomain_pi_basisFun, volume_pi, Measure.pi_pi, Real.volume_Ico, sub_zero, ENNReal.ofReal_one, Finset.prod_const_one, mul_one, ← Matrix.det_transpose] rfl @[simp] theorem volume_real_fundamentalDomain [Fintype ι] [DecidableEq ι] (b : Basis ι ℝ (ι → ℝ)) : volume.real (fundamentalDomain b) = |(Matrix.of b).det| := by simp [measureReal_def] theorem fundamentalDomain_ae_parallelepiped [Fintype ι] [MeasurableSpace E] (μ : Measure E) [BorelSpace E] [Measure.IsAddHaarMeasure μ] : fundamentalDomain b =ᵐ[μ] parallelepiped b := by classical have : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b rw [← measure_symmDiff_eq_zero_iff, symmDiff_of_le (fundamentalDomain_subset_parallelepiped b)] suffices (parallelepiped b \ fundamentalDomain b) ⊆ ⋃ i, AffineSubspace.mk' (b i) (span ℝ (b '' (Set.univ \ {i}))) by refine measure_mono_null this (measure_iUnion_null_iff.mpr fun i ↦ Measure.addHaar_affineSubspace μ _ ?_) refine (ne_of_mem_of_not_mem' (AffineSubspace.mem_top _ _ 0) (AffineSubspace.mem_mk'_iff_vsub_mem.not.mpr ?_)).symm simp_rw [vsub_eq_sub, zero_sub, neg_mem_iff] exact linearIndependent_iff_notMem_span.mp b.linearIndependent i intro x hx simp_rw [parallelepiped_basis_eq, Set.mem_Icc, Set.mem_diff, Set.mem_setOf_eq, mem_fundamentalDomain, Set.mem_Ico, not_forall, not_and, not_lt] at hx obtain ⟨i, hi⟩ := hx.2 have : b.repr x i = 1 := le_antisymm (hx.1 i).2 (hi (hx.1 i).1) rw [← b.sum_repr x, ← Finset.sum_erase_add _ _ (Finset.mem_univ i), this, one_smul, ← vadd_eq_add] refine Set.mem_iUnion.mpr ⟨i, AffineSubspace.vadd_mem_mk' _ (sum_smul_mem _ _ (fun i hi ↦ Submodule.subset_span ?_))⟩ exact ⟨i, Set.mem_diff_singleton.mpr ⟨trivial, Finset.ne_of_mem_erase hi⟩, rfl⟩ end Real end ZSpan section ZLattice open Submodule Module ZSpan -- TODO: generalize this class to other rings than `ℤ` /-- `L : Submodule ℤ E` where `E` is a vector space over a normed field `K` is a `ℤ`-lattice if it is discrete and spans `E` over `K`. -/ class IsZLattice (K : Type*) [NormedField K] {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] (L : Submodule ℤ E) [DiscreteTopology L] : Prop where /-- `L` spans the full space `E` over `K`. -/ span_top : span K (L : Set E) = ⊤ instance instIsZLatticeRealSpan {E ι : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [Finite ι] (b : Basis ι ℝ E) : IsZLattice ℝ (span ℤ (Set.range b)) where span_top := ZSpan.span_top b @[deprecated (since := "2025-05-08")] alias ZSpan.isZLattice := instIsZLatticeRealSpan section NormedLinearOrderedField variable (K : Type*) [NormedField K] [LinearOrder K] [IsStrictOrderedRing K] [HasSolidNorm K] [FloorRing K] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] [FiniteDimensional K E] variable [ProperSpace E] (L : Submodule ℤ E) [DiscreteTopology L] theorem ZLattice.FG [hs : IsZLattice K L] : L.FG := by obtain ⟨s, ⟨h_incl, ⟨h_span, h_lind⟩⟩⟩ := exists_linearIndependent K (L : Set E) -- Let `s` be a maximal `K`-linear independent family of elements of `L`. We show that -- `L` is finitely generated (as a ℤ-module) because it fits in the exact sequence -- `0 → span ℤ s → L → L ⧸ span ℤ s → 0` with `span ℤ s` and `L ⧸ span ℤ s` finitely generated. refine fg_of_fg_map_of_fg_inf_ker (span ℤ s).mkQ ?_ ?_ · -- Let `b` be the `K`-basis of `E` formed by the vectors in `s`. The elements of -- `L ⧸ span ℤ s = L ⧸ span ℤ b` are in bijection with elements of `L ∩ fundamentalDomain b` -- so there are finitely many since `fundamentalDomain b` is bounded. refine fg_def.mpr ⟨map (span ℤ s).mkQ L, ?_, span_eq _⟩ let b := Basis.mk h_lind (by rw [← hs.span_top, ← h_span] exact span_mono (by simp only [Subtype.range_coe_subtype, Set.setOf_mem_eq, subset_rfl])) rw [show span ℤ s = span ℤ (Set.range b) by simp [b, Basis.coe_mk, Subtype.range_coe_subtype]] have : Fintype s := h_lind.setFinite.fintype refine Set.Finite.of_finite_image (f := ((↑) : _ → E) ∘ quotientEquiv b) ?_ (Function.Injective.injOn (Subtype.coe_injective.comp (quotientEquiv b).injective)) have : ((fundamentalDomain b) ∩ L).Finite := by change ((fundamentalDomain b) ∩ L.toAddSubgroup).Finite have : DiscreteTopology L.toAddSubgroup := (inferInstance : DiscreteTopology L) exact Metric.finite_isBounded_inter_isClosed (fundamentalDomain_isBounded b) inferInstance refine Set.Finite.subset this ?_ rintro _ ⟨_, ⟨⟨x, ⟨h_mem, rfl⟩⟩, rfl⟩⟩ rw [Function.comp_apply, mkQ_apply, quotientEquiv_apply_mk, fractRestrict_apply] refine ⟨?_, ?_⟩ · exact fract_mem_fundamentalDomain b x · rw [fract, SetLike.mem_coe, sub_eq_add_neg] refine Submodule.add_mem _ h_mem (neg_mem (Set.mem_of_subset_of_mem ?_ (Subtype.mem (floor b x)))) rw [SetLike.coe_subset_coe, Basis.coe_mk, Subtype.range_coe_subtype, Set.setOf_mem_eq] exact span_le.mpr h_incl · -- `span ℤ s` is finitely generated because `s` is finite rw [ker_mkQ, inf_of_le_right (span_le.mpr h_incl)] exact fg_span (LinearIndependent.setFinite h_lind) @[deprecated (since := "2025-08-11")] alias Zlattice.FG := ZLattice.FG theorem ZLattice.module_finite [IsZLattice K L] : Module.Finite ℤ L := Module.Finite.iff_fg.mpr (ZLattice.FG K L) instance instModuleFinite_of_discrete_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : Submodule ℤ E) [DiscreteTopology L] : Module.Finite ℤ L := by let f := (span ℝ (L : Set E)).subtype let L₀ := L.comap (f.restrictScalars ℤ) have h_img : f '' L₀ = L := by rw [← LinearMap.coe_restrictScalars ℤ f, ← Submodule.map_coe (f.restrictScalars ℤ), Submodule.map_comap_eq_self] exact fun x hx ↦ LinearMap.mem_range.mpr ⟨⟨x, Submodule.subset_span hx⟩, rfl⟩ suffices Module.Finite ℤ L₀ by have : L₀.map (f.restrictScalars ℤ) = L := SetLike.ext'_iff.mpr h_img convert this ▸ Module.Finite.map L₀ (f.restrictScalars ℤ) have : DiscreteTopology L₀ := by refine DiscreteTopology.preimage_of_continuous_injective (L : Set E) ?_ (injective_subtype _) exact LinearMap.continuous_of_finiteDimensional f have : IsZLattice ℝ L₀ := ⟨by rw [← (Submodule.map_injective_of_injective (injective_subtype _)).eq_iff, Submodule.map_span, Submodule.map_top, range_subtype, h_img]⟩ exact ZLattice.module_finite ℝ L₀ theorem ZLattice.module_free [IsZLattice K L] : Module.Free ℤ L := by have : Module.Finite ℤ L := module_finite K L have : Module ℚ E := Module.compHom E (algebraMap ℚ K) infer_instance instance instModuleFree_of_discrete_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : Submodule ℤ E) [DiscreteTopology L] : Module.Free ℤ L := by have : Module ℚ E := Module.compHom E (algebraMap ℚ ℝ) infer_instance theorem ZLattice.rank [hs : IsZLattice K L] : finrank ℤ L = finrank K E := by classical have : Module.Finite ℤ L := module_finite K L have : Module.Free ℤ L := module_free K L have : Module ℚ E := Module.compHom E (algebraMap ℚ K) let b₀ := Module.Free.chooseBasis ℤ L -- Let `b` be a `ℤ`-basis of `L` formed of vectors of `E` let b := Subtype.val ∘ b₀ have : LinearIndependent ℤ b := LinearIndependent.map' b₀.linearIndependent (L.subtype) (ker_subtype _) -- We prove some assertions that will be useful later on have h_spanL : span ℤ (Set.range b) = L := by convert congrArg (map (Submodule.subtype L)) b₀.span_eq · rw [map_span, Set.range_comp] rfl · exact (map_subtype_top _).symm have h_spanE : span K (Set.range b) = ⊤ := by rw [← span_span_of_tower (R := ℤ), h_spanL] exact hs.span_top have h_card : Fintype.card (Module.Free.ChooseBasisIndex ℤ L) = (Set.range b).toFinset.card := by rw [Set.toFinset_range, Finset.univ.card_image_of_injective] · rfl · exact Subtype.coe_injective.comp (Basis.injective _) rw [finrank_eq_card_chooseBasisIndex] -- We prove that `finrank ℤ L ≤ finrank K E` and `finrank K E ≤ finrank ℤ L` refine le_antisymm ?_ ?_ · -- To prove that `finrank ℤ L ≤ finrank K E`, we proceed by contradiction and prove that, in -- this case, there is a ℤ-relation between the vectors of `b` obtain ⟨t, ⟨ht_inc, ⟨ht_span, ht_lin⟩⟩⟩ := exists_linearIndependent K (Set.range b) -- `e` is a `K`-basis of `E` formed of vectors of `b` let e : Basis t K E := Basis.mk ht_lin (by simp [ht_span, h_spanE]) have : Fintype t := Set.Finite.fintype ((Set.range b).toFinite.subset ht_inc) have h : LinearIndepOn ℤ id (Set.range b) := by rwa [linearIndepOn_id_range_iff (Subtype.coe_injective.comp b₀.injective)] contrapose! h -- Since `finrank ℤ L > finrank K E`, there exists a vector `v ∈ b` with `v ∉ e` obtain ⟨v, hv⟩ : (Set.range b \ Set.range e).Nonempty := by rw [Basis.coe_mk, Subtype.range_coe_subtype, Set.setOf_mem_eq, ← Set.toFinset_nonempty] contrapose h rw [Finset.not_nonempty_iff_eq_empty, Set.toFinset_diff, Finset.sdiff_eq_empty_iff_subset] at h replace h := Finset.card_le_card h rwa [not_lt, h_card, ← topEquiv.finrank_eq, ← h_spanE, ← ht_span, finrank_span_set_eq_card ht_lin] -- Assume that `e ∪ {v}` is not `ℤ`-linear independent then we get the contradiction suffices ¬ LinearIndepOn ℤ id (insert v (Set.range e)) by contrapose! this refine this.mono ?_ exact Set.insert_subset (Set.mem_of_mem_diff hv) (by simp [e, ht_inc]) -- We prove finally that `e ∪ {v}` is not ℤ-linear independent or, equivalently, -- not ℚ-linear independent by showing that `v ∈ span ℚ e`. rw [LinearIndepOn, LinearIndependent.iff_fractionRing ℤ ℚ, ← LinearIndepOn, linearIndepOn_id_insert (Set.notMem_of_mem_diff hv), not_and, not_not] intro _ -- But that follows from the fact that there exist `n, m : ℕ`, `n ≠ m` -- such that `(n - m) • v ∈ span ℤ e` which is true since `n ↦ ZSpan.fract e (n • v)` -- takes value into the finite set `fundamentalDomain e ∩ L` have h_mapsto : Set.MapsTo (fun n : ℤ => fract e (n • v)) Set.univ (Metric.closedBall 0 (∑ i, ‖e i‖) ∩ (L : Set E)) := by rw [Set.mapsTo_inter, Set.mapsTo_univ_iff, Set.mapsTo_univ_iff] refine ⟨fun _ ↦ mem_closedBall_zero_iff.mpr (norm_fract_le e _), fun _ => ?_⟩ · rw [← h_spanL] refine sub_mem ?_ ?_ · exact zsmul_mem (subset_span (Set.diff_subset hv)) _ · exact span_mono (by simp [e, ht_inc]) (coe_mem _) have h_finite : Set.Finite (Metric.closedBall 0 (∑ i, ‖e i‖) ∩ (L : Set E)) := by change ((_ : Set E) ∩ L.toAddSubgroup).Finite have : DiscreteTopology L.toAddSubgroup := (inferInstance : DiscreteTopology L) exact Metric.finite_isBounded_inter_isClosed Metric.isBounded_closedBall inferInstance obtain ⟨n, -, m, -, h_neq, h_eq⟩ := Set.Infinite.exists_ne_map_eq_of_mapsTo Set.infinite_univ h_mapsto h_finite have h_nz : (-n + m : ℚ) ≠ 0 := by rwa [Ne, add_eq_zero_iff_eq_neg.not, neg_inj, Rat.coe_int_inj, ← Ne] apply (smul_mem_iff _ h_nz).mp refine span_subset_span ℤ ℚ _ ?_ rwa [add_smul, neg_smul, SetLike.mem_coe, ← fract_eq_fract, Int.cast_smul_eq_zsmul ℚ, Int.cast_smul_eq_zsmul ℚ] · -- To prove that `finrank K E ≤ finrank ℤ L`, we use the fact `b` generates `E` over `K` -- and thus `finrank K E ≤ card b = finrank ℤ L` rw [← topEquiv.finrank_eq, ← h_spanE] convert finrank_span_le_card (R := K) (Set.range b) variable {ι : Type*} [hs : IsZLattice K L] (b : Basis ι ℤ L) namespace Module.Basis /-- Any `ℤ`-basis of `L` is also a `K`-basis of `E`. -/ def ofZLatticeBasis : Basis ι K E := by have : Module.Finite ℤ L := ZLattice.module_finite K L have : Free ℤ L := ZLattice.module_free K L let e := (Free.chooseBasis ℤ L).indexEquiv b have : Fintype ι := Fintype.ofEquiv _ e refine basisOfTopLeSpanOfCardEqFinrank (L.subtype ∘ b) ?_ ?_ · rw [← span_span_of_tower ℤ, Set.range_comp, ← map_span, Basis.span_eq, Submodule.map_top, range_subtype, top_le_iff, hs.span_top] · rw [← Fintype.card_congr e, ← finrank_eq_card_chooseBasisIndex, ZLattice.rank K L] @[simp] theorem ofZLatticeBasis_apply (i : ι) : b.ofZLatticeBasis K L i = b i := by simp [Basis.ofZLatticeBasis] @[simp] theorem ofZLatticeBasis_repr_apply (x : L) (i : ι) : (b.ofZLatticeBasis K L).repr x i = b.repr x i := by suffices ((b.ofZLatticeBasis K L).repr.toLinearMap.restrictScalars ℤ) ∘ₗ L.subtype = Finsupp.mapRange.linearMap (Algebra.linearMap ℤ K) ∘ₗ b.repr.toLinearMap by exact DFunLike.congr_fun (LinearMap.congr_fun this x) i refine Basis.ext b fun i ↦ ?_ simp_rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.coe_restrictScalars, LinearEquiv.coe_coe, coe_subtype, ← b.ofZLatticeBasis_apply K, repr_self, Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single, Algebra.linearMap_apply, map_one] theorem ofZLatticeBasis_span : span ℤ (Set.range (b.ofZLatticeBasis K)) = L := by calc span ℤ (Set.range (b.ofZLatticeBasis K)) _ = span ℤ (L.subtype '' Set.range b) := by congr; ext; simp _ = map L.subtype (span ℤ (Set.range b)) := by rw [Submodule.map_span] _ = L := by simp [b.span_eq] end Module.Basis open MeasureTheory in theorem ZLattice.isAddFundamentalDomain {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {L : Submodule ℤ E} [DiscreteTopology L] [IsZLattice ℝ L] [Finite ι] (b : Basis ι ℤ L) [MeasurableSpace E] [OpensMeasurableSpace E] (μ : Measure E) : IsAddFundamentalDomain L (fundamentalDomain (b.ofZLatticeBasis ℝ)) μ := by convert ZSpan.isAddFundamentalDomain (b.ofZLatticeBasis ℝ) μ all_goals exact (b.ofZLatticeBasis_span ℝ).symm instance instCountable_of_discrete_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L] : Countable L := by simp_rw [← (Module.Free.chooseBasis ℤ L).ofZLatticeBasis_span ℝ] infer_instance /-- Assume that the set `s` spans over `ℤ` a discrete set. Then its `ℝ`-rank is equal to its `ℤ`-rank. -/ theorem Real.finrank_eq_int_finrank_of_discrete {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {s : Set E} (hs : DiscreteTopology (span ℤ s)) : Set.finrank ℝ s = Set.finrank ℤ s := by let F := span ℝ s let L : Submodule ℤ (span ℝ s) := comap (F.restrictScalars ℤ).subtype (span ℤ s) let f := Submodule.comapSubtypeEquivOfLe (span_le_restrictScalars ℤ ℝ s) have : DiscreteTopology L := by let e : span ℤ s ≃L[ℤ] L := ⟨f.symm, continuous_of_discreteTopology, Isometry.continuous fun _ ↦ congrFun rfl⟩ exact e.toHomeomorph.discreteTopology have : IsZLattice ℝ L := ⟨eq_top_iff.mpr <| span_span_coe_preimage.symm.le.trans (span_mono (Set.preimage_mono subset_span))⟩ rw [Set.finrank, Set.finrank, ← f.finrank_eq] exact (ZLattice.rank ℝ L).symm end NormedLinearOrderedField section Basis variable {ι : Type*} [Fintype ι] (L : Submodule ℤ (ι → ℝ)) [DiscreteTopology L] [IsZLattice ℝ L] /-- Return an arbitrary `ℤ`-basis of a lattice `L` of `ι → ℝ` indexed by `ι`. -/ def IsZLattice.basis : Basis ι ℤ L := (Free.chooseBasis ℤ L).reindex (Fintype.equivOfCardEq (by rw [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ, finrank_fintype_fun_eq_card])) end Basis section comap variable (K : Type*) [NormedField K] {E F : Type*} [NormedAddCommGroup E] [NormedSpace K E] [NormedAddCommGroup F] [NormedSpace K F] (L : Submodule ℤ E) /-- Let `e : E → F` a linear map, the map that sends a `L : Submodule ℤ E` to the `Submodule ℤ F` that is the pullback of `L` by `e`. If `IsZLattice L` and `e` is a continuous linear equiv, then it is a `IsZLattice` of `E`, see `instIsZLatticeComap`. -/ protected def ZLattice.comap (e : F →ₗ[K] E) := L.comap (e.restrictScalars ℤ) @[simp] theorem ZLattice.coe_comap (e : F →ₗ[K] E) : (ZLattice.comap K L e : Set F) = e⁻¹' L := rfl theorem ZLattice.comap_refl : ZLattice.comap K L (1 : E →ₗ[K] E)= L := Submodule.comap_id L theorem ZLattice.comap_discreteTopology [hL : DiscreteTopology L] {e : F →ₗ[K] E} (he₁ : Continuous e) (he₂ : Function.Injective e) : DiscreteTopology (ZLattice.comap K L e) := by exact DiscreteTopology.preimage_of_continuous_injective L he₁ he₂ instance [DiscreteTopology L] (e : F ≃L[K] E) : DiscreteTopology (ZLattice.comap K L e.toLinearMap) := ZLattice.comap_discreteTopology K L e.continuous e.injective theorem ZLattice.comap_span_top (hL : span K (L : Set E) = ⊤) {e : F →ₗ[K] E} (he : (L : Set E) ⊆ LinearMap.range e) : span K (ZLattice.comap K L e : Set F) = ⊤ := by rw [ZLattice.coe_comap, Submodule.span_preimage_eq (Submodule.nonempty L) he, hL, comap_top] instance instIsZLatticeComap [DiscreteTopology L] [IsZLattice K L] (e : F ≃L[K] E) : IsZLattice K (ZLattice.comap K L e.toLinearMap) where span_top := by rw [ZLattice.coe_comap, LinearEquiv.coe_coe, e.coe_toLinearEquiv, ← e.image_symm_eq_preimage, ← Submodule.map_span, IsZLattice.span_top, Submodule.map_top, LinearEquivClass.range] @[simp] theorem ZLattice.comap_toAddSubgroup (e : F →ₗ[K] E) : (ZLattice.comap K L e).toAddSubgroup = L.toAddSubgroup.comap e.toAddMonoidHom := rfl theorem ZLattice.comap_comp {G : Type*} [NormedAddCommGroup G] [NormedSpace K G] (e : F →ₗ[K] E) (e' : G →ₗ[K] F) : (ZLattice.comap K (ZLattice.comap K L e) e') = ZLattice.comap K L (e ∘ₗ e') := (Submodule.comap_comp _ _ L).symm /-- If `e` is a linear equivalence, it induces a `ℤ`-linear equivalence between `L` and `ZLattice.comap K L e`. -/ def ZLattice.comap_equiv (e : F ≃ₗ[K] E) : L ≃ₗ[ℤ] (ZLattice.comap K L e.toLinearMap) := LinearEquiv.ofBijective ((e.symm.toLinearMap.restrictScalars ℤ).restrict (fun _ h ↦ by simpa [← SetLike.mem_coe] using h)) ⟨fun _ _ h ↦ Subtype.ext_iff_val.mpr (e.symm.injective (congr_arg Subtype.val h)), fun ⟨x, hx⟩ ↦ ⟨⟨e x, by rwa [← SetLike.mem_coe, ZLattice.coe_comap] at hx⟩, by simp [Subtype.ext_iff_val]⟩⟩ @[simp] theorem ZLattice.comap_equiv_apply (e : F ≃ₗ[K] E) (x : L) : ZLattice.comap_equiv K L e x = e.symm x := rfl namespace Module.Basis /-- The basis of `ZLattice.comap K L e` given by the image of a basis `b` of `L` by `e.symm`. -/ def ofZLatticeComap (e : F ≃ₗ[K] E) {ι : Type*} (b : Basis ι ℤ L) : Basis ι ℤ (ZLattice.comap K L e.toLinearMap) := b.map (ZLattice.comap_equiv K L e) @[simp] theorem ofZLatticeComap_apply (e : F ≃ₗ[K] E) {ι : Type*} (b : Basis ι ℤ L) (i : ι) : b.ofZLatticeComap K L e i = e.symm (b i) := by simp [Basis.ofZLatticeComap] @[simp] theorem ofZLatticeComap_repr_apply (e : F ≃ₗ[K] E) {ι : Type*} (b : Basis ι ℤ L) (x : L) (i : ι) : (b.ofZLatticeComap K L e).repr (ZLattice.comap_equiv K L e x) i = b.repr x i := by simp [Basis.ofZLatticeComap] end Module.Basis end comap section NormedLinearOrderedField_comap variable (K : Type*) [NormedField K] [LinearOrder K] [IsStrictOrderedRing K] [HasSolidNorm K] [FloorRing K] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace K E] [FiniteDimensional K E] [ProperSpace E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace K F] [FiniteDimensional K F] [ProperSpace F] variable (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice K L] theorem Module.Basis.ofZLatticeBasis_comap (e : F ≃L[K] E) {ι : Type*} (b : Basis ι ℤ L) : (b.ofZLatticeComap K L e.toLinearEquiv).ofZLatticeBasis K (ZLattice.comap K L e.toLinearMap) = (b.ofZLatticeBasis K L).map e.symm.toLinearEquiv := by ext simp end NormedLinearOrderedField_comap end ZLattice
Shrink.lean
/- Copyright (c) 2025 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Order.SuccPred.Basic import Mathlib.Logic.Small.Defs /-! # Order instances on Shrink If `α : Type v` is `u`-small, we transport various order related instances on `α` to `Shrink.{u} α`. -/ universe u v variable (α : Type v) [Small.{u} α] instance [Preorder α] : Preorder (Shrink.{u} α) where le a b := (equivShrink α).symm a ≤ (equivShrink _).symm b le_refl a := le_refl _ le_trans _ _ _ h₁ h₂ := h₁.trans h₂ /-- The order isomorphism `α ≃o Shrink.{u} α`. -/ noncomputable def orderIsoShrink [Preorder α] : α ≃o Shrink.{u} α where toEquiv := equivShrink α map_rel_iff' {a b} := by obtain ⟨a, rfl⟩ := (equivShrink.{u} α).symm.surjective a obtain ⟨b, rfl⟩ := (equivShrink.{u} α).symm.surjective b simp only [Equiv.apply_symm_apply] rfl variable {α} @[simp] lemma orderIsoShrink_apply [Preorder α] (a : α) : orderIsoShrink α a = equivShrink α a := rfl @[simp] lemma orderIsoShrink_symm_apply [Preorder α] (a : Shrink.{u} α) : (orderIsoShrink α).symm a = (equivShrink α).symm a := rfl instance [PartialOrder α] : PartialOrder (Shrink.{u} α) where le_antisymm _ _ h₁ h₂ := (equivShrink _).symm.injective (le_antisymm h₁ h₂) noncomputable instance [LinearOrder α] : LinearOrder (Shrink.{u} α) where le_total _ _ := le_total _ _ toDecidableLE _ _ := LinearOrder.toDecidableLE _ _ noncomputable instance [Bot α] : Bot (Shrink.{u} α) where bot := equivShrink _ ⊥ @[simp] lemma equivShrink_bot [Bot α] : equivShrink.{u} α ⊥ = ⊥ := rfl @[simp] lemma equivShrink_symm_bot [Bot α] : (equivShrink.{u} α).symm ⊥ = ⊥ := (equivShrink.{u} α).injective (by simp) noncomputable instance [Top α] : Top (Shrink.{u} α) where top := equivShrink _ ⊤ @[simp] lemma equivShrink_top [Top α] : equivShrink.{u} α ⊤ = ⊤ := rfl @[simp] lemma equivShrink_symm_top [Top α] : (equivShrink.{u} α).symm ⊤ = ⊤ := (equivShrink.{u} α).injective (by simp) section Preorder variable [Preorder α] noncomputable instance [OrderBot α] : OrderBot (Shrink.{u} α) where bot_le a := by simp only [← (orderIsoShrink.{u} α).symm.le_iff_le, orderIsoShrink_symm_apply, equivShrink_symm_bot, bot_le] noncomputable instance [OrderTop α] : OrderTop (Shrink.{u} α) where le_top a := by simp only [← (orderIsoShrink.{u} α).symm.le_iff_le, orderIsoShrink_symm_apply, equivShrink_symm_top, le_top] noncomputable instance [SuccOrder α] : SuccOrder (Shrink.{u} α) := SuccOrder.ofOrderIso (orderIsoShrink.{u} α) noncomputable instance [PredOrder α] : PredOrder (Shrink.{u} α) := PredOrder.ofOrderIso (orderIsoShrink.{u} α) instance [WellFoundedLT α] : WellFoundedLT (Shrink.{u} α) where wf := (orderIsoShrink.{u} α).symm.toRelIsoLT.toRelEmbedding.isWellFounded.wf end Preorder
Recurse.lean
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Heather Macbeth -/ import Mathlib.Util.AtomM /-! # Running `AtomM` metaprograms recursively Tactics such as `ring` and `abel` are implemented using the `AtomM` monad, which tracks "atoms" -- expressions which cannot be further parsed according to the arithmetic operations they handle -- to allow for consistent normalization relative to these atoms. This file provides methods to allow for such normalization to run recursively: the atoms themselves will have the normalization run on any of their subterms for which this makes sense. For example, given an implementation of ring-normalization, the methods in this file implement the bottom-to-top recursive ring-normalization in which `sin (x + y) + sin (y + x)` is normalized first to `sin (x + y) + sin (x + y)` and then to `2 * sin (x + y)`. ## Main declarations * `Mathlib.Tactic.AtomM.RecurseM.run`: run a metaprogram (in `AtomM` or its slight extension `AtomM.RecurseM`), with atoms normalized according to a provided normalization operation (in `AtomM`), run recursively. * `Mathlib.Tactic.AtomM.recurse`: run a normalization operation (in `AtomM`) recursively on an expression. -/ namespace Mathlib.Tactic.AtomM open Lean Meta /-- Configuration for `AtomM.Recurse`. -/ structure Recurse.Config where /-- the reducibility setting to use when comparing atoms for defeq -/ red := TransparencyMode.reducible /-- if true, local let variables can be unfolded -/ zetaDelta := false deriving Inhabited, BEq, Repr /-- The read-only state of the `AtomM.Recurse` monad. -/ structure Recurse.Context where /-- A basically empty simp context, passed to the `simp` traversal in `AtomM.onSubexpressions`. -/ ctx : Simp.Context /-- A cleanup routine, which simplifies evaluation results to a more human-friendly format. -/ simp : Simp.Result → MetaM Simp.Result /-- The monad for `AtomM.Recurse` contains, in addition to the `AtomM` state, a simp context for the main traversal and a cleanup function to simplify evaluation results. -/ abbrev RecurseM := ReaderT Recurse.Context AtomM /-- A tactic in the `AtomM.RecurseM` monad which will simplify expression `parent` to a normal form, by running a core operation `eval` (in the `AtomM` monad) on the maximal subexpression(s) on which `eval` does not fail. There is also a subsequent clean-up operation, governed by the context from the `AtomM.RecurseM` monad. * `root`: true if this is a direct call to the function. `AtomM.RecurseM.run` sets this to `false` in recursive mode. -/ def onSubexpressions (eval : Expr → AtomM Simp.Result) (parent : Expr) (root := true) : RecurseM Simp.Result := fun nctx rctx s ↦ do let pre : Simp.Simproc := fun e => try guard <| root || parent != e -- recursion guard let r' ← eval e rctx s let r ← nctx.simp r' if ← withReducible <| isDefEq r.expr e then return .done { expr := r.expr } pure (.done r) catch _ => pure <| .continue let post := Simp.postDefault #[] (·.1) <$> Simp.main parent nctx.ctx (methods := { pre, post }) /-- Runs a tactic in the `AtomM.RecurseM` monad, given initial data: * `s`: a reference to the mutable `AtomM` state, for persisting across calls. This ensures that atom ordering is used consistently. * `cfg`: the configuration options * `eval`: a normalization operation which will be run recursively, potentially dependent on a known atom ordering * `simp`: a cleanup operation which will be used to post-process expressions * `x`: the tactic to run -/ partial def RecurseM.run {α : Type} (s : IO.Ref State) (cfg : Recurse.Config) (eval : Expr → AtomM Simp.Result) (simp : Simp.Result → MetaM Simp.Result) (x : RecurseM α) : MetaM α := do let ctx ← Simp.mkContext { zetaDelta := cfg.zetaDelta, singlePass := true } (simpTheorems := #[← Elab.Tactic.simpOnlyBuiltins.foldlM (·.addConst ·) {}]) (congrTheorems := ← getSimpCongrTheorems) let nctx := { ctx, simp } let rec /-- The recursive context. -/ rctx := { red := cfg.red, evalAtom }, /-- The atom evaluator calls `AtomM.onSubexpressions` recursively. -/ evalAtom e := onSubexpressions eval e false nctx rctx s withConfig ({ · with zetaDelta := cfg.zetaDelta }) <| x nctx rctx s /-- Normalizes an expression, given initial data: * `s`: a reference to the mutable `AtomM` state, for persisting across calls. This ensures that atom ordering is used consistently. * `cfg`: the configuration options * `eval`: a normalization operation which will be run recursively, potentially dependent on a known atom ordering * `simp`: a cleanup operation which will be used to post-process expressions * `tgt`: the expression to normalize -/ def recurse (s : IO.Ref State) (cfg : Recurse.Config) (eval : Expr → AtomM Simp.Result) (simp : Simp.Result → MetaM Simp.Result) (tgt : Expr) : MetaM Simp.Result := do RecurseM.run s cfg eval simp <| onSubexpressions eval tgt end Mathlib.Tactic.AtomM
Frobenius.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Algebra.ZMod import Mathlib.Data.Nat.Multiplicity import Mathlib.FieldTheory.Perfect import Mathlib.RingTheory.WittVector.Basic import Mathlib.RingTheory.WittVector.IsPoly /-! ## The Frobenius operator If `R` has characteristic `p`, then there is a ring endomorphism `frobenius R p` that raises `r : R` to the power `p`. By applying `WittVector.map` to `frobenius R p`, we obtain a ring endomorphism `𝕎 R →+* 𝕎 R`. It turns out that this endomorphism can be described by polynomials over `ℤ` that do not depend on `R` or the fact that it has characteristic `p`. In this way, we obtain a Frobenius endomorphism `WittVector.frobeniusFun : 𝕎 R → 𝕎 R` for every commutative ring `R`. Unfortunately, the aforementioned polynomials can not be obtained using the machinery of `wittStructureInt` that was developed in `StructurePolynomial.lean`. We therefore have to define the polynomials by hand, and check that they have the required property. In case `R` has characteristic `p`, we show in `frobenius_eq_map_frobenius` that `WittVector.frobeniusFun` is equal to `WittVector.map (frobenius R p)`. ### Main definitions and results * `frobeniusPoly`: the polynomials that describe the coefficients of `frobeniusFun`; * `frobeniusFun`: the Frobenius endomorphism on Witt vectors; * `frobeniusFun_isPoly`: the tautological assertion that Frobenius is a polynomial function; * `frobenius_eq_map_frobenius`: the fact that in characteristic `p`, Frobenius is equal to `WittVector.map (frobenius R p)`. TODO: Show that `WittVector.frobeniusFun` is a ring homomorphism, and bundle it into `WittVector.frobenius`. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ namespace WittVector variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R] local notation "𝕎" => WittVector p -- type as `\bbW` noncomputable section open MvPolynomial Finset variable (p) /-- The rational polynomials that give the coefficients of `frobenius x`, in terms of the coefficients of `x`. These polynomials actually have integral coefficients, see `frobeniusPoly` and `map_frobeniusPoly`. -/ def frobeniusPolyRat (n : ℕ) : MvPolynomial ℕ ℚ := bind₁ (wittPolynomial p ℚ ∘ fun n => n + 1) (xInTermsOfW p ℚ n) theorem bind₁_frobeniusPolyRat_wittPolynomial (n : ℕ) : bind₁ (frobeniusPolyRat p) (wittPolynomial p ℚ n) = wittPolynomial p ℚ (n + 1) := by delta frobeniusPolyRat rw [← bind₁_bind₁, bind₁_xInTermsOfW_wittPolynomial, bind₁_X_right, Function.comp_apply] local notation "v" => multiplicity /-- An auxiliary polynomial over the integers, that satisfies `p * (frobeniusPolyAux p n) + X n ^ p = frobeniusPoly p n`. This makes it easy to show that `frobeniusPoly p n` is congruent to `X n ^ p` modulo `p`. -/ noncomputable def frobeniusPolyAux : ℕ → MvPolynomial ℕ ℤ | n => X (n + 1) - ∑ i : Fin n, have _ := i.is_lt ∑ j ∈ range (p ^ (n - i)), (((X (i : ℕ) ^ p) ^ (p ^ (n - (i : ℕ)) - (j + 1)) : MvPolynomial ℕ ℤ) * (frobeniusPolyAux i) ^ (j + 1)) * C (((p ^ (n - i)).choose (j + 1) / (p ^ (n - i - v p (j + 1))) * ↑p ^ (j - v p (j + 1)) : ℕ) : ℤ) omit hp in theorem frobeniusPolyAux_eq (n : ℕ) : frobeniusPolyAux p n = X (n + 1) - ∑ i ∈ range n, ∑ j ∈ range (p ^ (n - i)), (X i ^ p) ^ (p ^ (n - i) - (j + 1)) * frobeniusPolyAux p i ^ (j + 1) * C ↑((p ^ (n - i)).choose (j + 1) / p ^ (n - i - v p (j + 1)) * ↑p ^ (j - v p (j + 1)) : ℕ) := by rw [frobeniusPolyAux, ← Fin.sum_univ_eq_sum_range] /-- The polynomials that give the coefficients of `frobenius x`, in terms of the coefficients of `x`. -/ def frobeniusPoly (n : ℕ) : MvPolynomial ℕ ℤ := X n ^ p + C (p : ℤ) * frobeniusPolyAux p n /- Our next goal is to prove ``` lemma map_frobeniusPoly (n : ℕ) : MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n ``` This lemma has a rather long proof, but it mostly boils down to applying induction, and then using the following two key facts at the right point. -/ /-- A key divisibility fact for the proof of `WittVector.map_frobeniusPoly`. -/ theorem map_frobeniusPoly.key₁ (n j : ℕ) (hj : j < p ^ n) : p ^ (n - v p (j + 1)) ∣ (p ^ n).choose (j + 1) := by apply pow_dvd_of_le_emultiplicity rw [hp.out.emultiplicity_choose_prime_pow hj j.succ_ne_zero] /-- A key numerical identity needed for the proof of `WittVector.map_frobeniusPoly`. -/ theorem map_frobeniusPoly.key₂ {n i j : ℕ} (hi : i ≤ n) (hj : j < p ^ (n - i)) : j - v p (j + 1) + n = i + j + (n - i - v p (j + 1)) := by generalize h : v p (j + 1) = m rsuffices ⟨h₁, h₂⟩ : m ≤ n - i ∧ m ≤ j · rw [tsub_add_eq_add_tsub h₂, add_comm i j, add_tsub_assoc_of_le (h₁.trans (Nat.sub_le n i)), add_assoc, tsub_right_comm, add_comm i, tsub_add_cancel_of_le (le_tsub_of_add_le_right ((le_tsub_iff_left hi).mp h₁))] have hle : p ^ m ≤ j + 1 := h ▸ Nat.le_of_dvd j.succ_pos (pow_multiplicity_dvd _ _) exact ⟨(Nat.pow_le_pow_iff_right hp.1.one_lt).1 (hle.trans hj), Nat.le_of_lt_succ ((m.lt_pow_self hp.1.one_lt).trans_le hle)⟩ theorem map_frobeniusPoly (n : ℕ) : MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n := by rw [frobeniusPoly, RingHom.map_add, RingHom.map_mul, RingHom.map_pow, map_C, map_X, eq_intCast, Int.cast_natCast, frobeniusPolyRat] refine Nat.strong_induction_on n ?_; clear n intro n IH rw [xInTermsOfW_eq] simp only [map_sum, map_sub, map_mul, map_pow (bind₁ _), bind₁_C_right] have h1 : (p : ℚ) ^ n * ⅟(p : ℚ) ^ n = 1 := by rw [← mul_pow, mul_invOf_self, one_pow] rw [bind₁_X_right, Function.comp_apply, wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ, sum_range_succ, tsub_self, add_tsub_cancel_left, pow_zero, pow_one, pow_one, sub_mul, add_mul, add_mul, mul_right_comm, mul_right_comm (C ((p : ℚ) ^ (n + 1))), ← C_mul, ← C_mul, pow_succ', mul_assoc (p : ℚ) ((p : ℚ) ^ n), h1, mul_one, C_1, one_mul, add_comm _ (X n ^ p), add_assoc, ← add_sub, add_right_inj, frobeniusPolyAux_eq, RingHom.map_sub, map_X, mul_sub, sub_eq_add_neg, add_comm _ (C (p : ℚ) * X (n + 1)), ← add_sub, add_right_inj, neg_eq_iff_eq_neg, neg_sub, eq_comm] simp only [map_sum, mul_sum, sum_mul, ← sum_sub_distrib] apply sum_congr rfl intro i hi rw [mem_range] at hi rw [← IH i hi] clear IH rw [add_comm (X i ^ p), add_pow, sum_range_succ', pow_zero, tsub_zero, Nat.choose_zero_right, one_mul, Nat.cast_one, mul_one, mul_add, add_mul, Nat.succ_sub (le_of_lt hi), Nat.succ_eq_add_one (n - i), pow_succ', pow_mul, add_sub_cancel_right, mul_sum, sum_mul] apply sum_congr rfl intro j hj rw [mem_range] at hj rw [RingHom.map_mul, RingHom.map_mul, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow, map_C, map_X, mul_pow] rw [mul_comm (C (p : ℚ) ^ i), mul_comm _ ((X i ^ p) ^ _), mul_comm (C (p : ℚ) ^ (j + 1)), mul_comm (C (p : ℚ))] simp only [mul_assoc] apply congr_arg apply congr_arg rw [← C_eq_coe_nat] simp only [← RingHom.map_pow, ← C_mul] rw [C_inj] simp only [invOf_eq_inv, eq_intCast, inv_pow, Int.cast_natCast, Nat.cast_mul, Int.cast_mul] rw [Rat.natCast_div _ _ (map_frobeniusPoly.key₁ p (n - i) j hj)] simp only [Nat.cast_pow, pow_add, pow_one] suffices (((p ^ (n - i)).choose (j + 1) : ℚ) * (p : ℚ) ^ (j - v p (j + 1)) * p * (p ^ n : ℚ)) = (p : ℚ) ^ j * p * ↑((p ^ (n - i)).choose (j + 1) * p ^ i) * (p : ℚ) ^ (n - i - v p (j + 1)) by have aux : ∀ k : ℕ, (p : ℚ) ^ k ≠ 0 := by intro; apply pow_ne_zero; exact mod_cast hp.1.ne_zero simpa [aux, -one_div, -pow_eq_zero_iff', field_simps] using this.symm rw [mul_comm _ (p : ℚ), mul_assoc, mul_assoc, ← pow_add, map_frobeniusPoly.key₂ p hi.le hj, Nat.cast_mul, Nat.cast_pow] ring theorem frobeniusPoly_zmod (n : ℕ) : MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n) = X n ^ p := by rw [frobeniusPoly, RingHom.map_add, RingHom.map_pow, RingHom.map_mul, map_X, map_C] simp only [Int.cast_natCast, add_zero, eq_intCast, ZMod.natCast_self, zero_mul, C_0] @[simp] theorem bind₁_frobeniusPoly_wittPolynomial (n : ℕ) : bind₁ (frobeniusPoly p) (wittPolynomial p ℤ n) = wittPolynomial p ℤ (n + 1) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [map_bind₁, map_frobeniusPoly, bind₁_frobeniusPolyRat_wittPolynomial, map_wittPolynomial] variable {p} /-- `frobeniusFun` is the function underlying the ring endomorphism `frobenius : 𝕎 R →+* frobenius 𝕎 R`. -/ def frobeniusFun (x : 𝕎 R) : 𝕎 R := mk p fun n => MvPolynomial.aeval x.coeff (frobeniusPoly p n) omit hp in theorem coeff_frobeniusFun (x : 𝕎 R) (n : ℕ) : coeff (frobeniusFun x) n = MvPolynomial.aeval x.coeff (frobeniusPoly p n) := by rw [frobeniusFun, coeff_mk] variable (p) in /-- `frobeniusFun` is tautologically a polynomial function. See also `frobenius_isPoly`. -/ instance frobeniusFun_isPoly : IsPoly p fun R _ Rcr => @frobeniusFun p R _ Rcr := ⟨⟨frobeniusPoly p, by intros; funext n; apply coeff_frobeniusFun⟩⟩ @[ghost_simps] theorem ghostComponent_frobeniusFun (n : ℕ) (x : 𝕎 R) : ghostComponent n (frobeniusFun x) = ghostComponent (n + 1) x := by simp only [ghostComponent_apply, frobeniusFun, coeff_mk, ← bind₁_frobeniusPoly_wittPolynomial, aeval_bind₁] /-- If `R` has characteristic `p`, then there is a ring endomorphism that raises `r : R` to the power `p`. By applying `WittVector.map` to this endomorphism, we obtain a ring endomorphism `frobenius R p : 𝕎 R →+* 𝕎 R`. The underlying function of this morphism is `WittVector.frobeniusFun`. -/ def frobenius : 𝕎 R →+* 𝕎 R where toFun := frobeniusFun map_zero' := by -- Porting note: removing the placeholders give an error refine IsPoly.ext (@IsPoly.comp p _ _ (frobeniusFun_isPoly p) WittVector.zeroIsPoly) (@IsPoly.comp p _ _ WittVector.zeroIsPoly (frobeniusFun_isPoly p)) ?_ _ 0 simp only [Function.comp_apply, map_zero, forall_const] ghost_simp map_one' := by refine -- Porting note: removing the placeholders give an error IsPoly.ext (@IsPoly.comp p _ _ (frobeniusFun_isPoly p) WittVector.oneIsPoly) (@IsPoly.comp p _ _ WittVector.oneIsPoly (frobeniusFun_isPoly p)) ?_ _ 0 simp only [Function.comp_apply, map_one, forall_const] ghost_simp map_add' := by ghost_calc _ _; ghost_simp map_mul' := by ghost_calc _ _; ghost_simp theorem coeff_frobenius (x : 𝕎 R) (n : ℕ) : coeff (frobenius x) n = MvPolynomial.aeval x.coeff (frobeniusPoly p n) := coeff_frobeniusFun _ _ @[ghost_simps] theorem ghostComponent_frobenius (n : ℕ) (x : 𝕎 R) : ghostComponent n (frobenius x) = ghostComponent (n + 1) x := ghostComponent_frobeniusFun _ _ variable (p) /-- `frobenius` is tautologically a polynomial function. -/ instance frobenius_isPoly : IsPoly p fun R _Rcr => @frobenius p R _ _Rcr := frobeniusFun_isPoly _ section CharP variable [CharP R p] @[simp] theorem coeff_frobenius_charP (x : 𝕎 R) (n : ℕ) : coeff (frobenius x) n = x.coeff n ^ p := by rw [coeff_frobenius] letI : Algebra (ZMod p) R := ZMod.algebra _ _ -- outline of the calculation, proofs follow below calc aeval (fun k => x.coeff k) (frobeniusPoly p n) = aeval (fun k => x.coeff k) (MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n)) := ?_ _ = aeval (fun k => x.coeff k) (X n ^ p : MvPolynomial ℕ (ZMod p)) := ?_ _ = x.coeff n ^ p := ?_ · conv_rhs => rw [aeval_eq_eval₂Hom, eval₂Hom_map_hom] apply eval₂Hom_congr (RingHom.ext_int _ _) rfl rfl · rw [frobeniusPoly_zmod] · rw [map_pow, aeval_X] theorem frobenius_eq_map_frobenius : @frobenius p R _ _ = map (_root_.frobenius R p) := by ext (x n) simp only [coeff_frobenius_charP, map_coeff, frobenius_def] @[simp] theorem frobenius_zmodp (x : 𝕎 (ZMod p)) : frobenius x = x := by simp only [WittVector.ext_iff, coeff_frobenius_charP, ZMod.pow_card, forall_const] variable (R) /-- `WittVector.frobenius` as an equiv. -/ @[simps -fullyApplied] def frobeniusEquiv [PerfectRing R p] : WittVector p R ≃+* WittVector p R := { (WittVector.frobenius : WittVector p R →+* WittVector p R) with toFun := WittVector.frobenius invFun := map (_root_.frobeniusEquiv R p).symm left_inv := fun f => ext fun n => by rw [frobenius_eq_map_frobenius] exact frobeniusEquiv_symm_apply_frobenius R p _ right_inv := fun f => ext fun n => by rw [frobenius_eq_map_frobenius] exact frobenius_apply_frobeniusEquiv_symm R p _ } theorem frobenius_bijective [PerfectRing R p] : Function.Bijective (@WittVector.frobenius p R _ _) := (frobeniusEquiv p R).bijective end CharP end end WittVector
ssrAC.v
From HB Require Import structures. From Corelib Require Import PosDef. (* use #[warning="-hiding-delimiting-key"] attribute once we require Coq 8.18 *) (* (the warning was completely removed in 9.0) *) Set Warnings "-hiding-delimiting-key". From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype seq bigop. Set Warnings "hiding-delimiting-key". Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (************************************************************************) (* Small Scale Rewriting using Associativity and Commutativity *) (* *) (* Rewriting with AC (not modulo AC), using a small scale command. *) (* Replaces opA, opC, opAC, opCA, ... and any combinations of them *) (* *) (* Usage : *) (* rewrite [pattern](AC patternshape reordering) *) (* rewrite [pattern](ACl reordering) *) (* rewrite [pattern](ACof reordering reordering) *) (* rewrite [pattern]op.[AC patternshape reordering] *) (* rewrite [pattern]op.[ACl reordering] *) (* rewrite [pattern]op.[ACof reordering reordering] *) (* *) (* - if op is specified, the rule is specialized to op *) (* otherwise, the head symbol is a generic comm_law *) (* and the rewrite might be less efficient *) (* NOTE because of a bug in Coq's notations coq/coq#8190 *) (* op must not contain any hole. *) (* *%R.[AC p s] currently does not work because of that *) (* (@GRing.mul R).[AC p s] must be used instead *) (* *) (* - pattern is optional, as usual, but must be used to select the *) (* appropriate operator in case of ambiguity such an operator must *) (* have a canonical Monoid.com_law structure *) (* (additions, multiplications, conjunction and disjunction do) *) (* *) (* - patternshape is expressed using the syntax *) (* p := n | p * p' *) (* where "*" is purely formal *) (* and n > 0 is the number of left associated symbols *) (* examples of pattern shapes: *) (* + 4 represents (n * m * p * q) *) (* + (1*2) represents (n * (m * p)) *) (* *) (* - reordering is expressed using the syntax *) (* s := n | s * s' *) (* where "*" is purely formal and n > 0 is the position in the LHS *) (* positions start at 1 ! *) (* *) (* If the ACl variant is used, the patternshape defaults to the *) (* pattern fully associated to the left i.e. n i.e (x * y * ...) *) (* *) (* Examples of reorderings: *) (* - ACl ((1*2)*3) is the identity (and will fail with error message) *) (* - opAC == op.[ACl (1*3)*2] == op.[AC 3 ((1*3)*2)] *) (* - opCA == op.[AC (2*1) (1*2*3)] *) (* - opACA == op.[AC (2*2) ((1*3)*(2*4))] *) (* - rewrite opAC -opA == rewrite op.[ACl 1*(3*2)] *) (* ... *) (************************************************************************) Declare Scope AC_scope. Delimit Scope AC_scope with AC. Reserved Notation "op .[ 'ACof' p s ]" (p at level 1, left associativity). Reserved Notation "op .[ 'AC' p s ]" (p at level 1, left associativity). Reserved Notation "op .[ 'ACl' s ]" (left associativity). Definition change_type ty ty' (x : ty) (strategy : ty = ty') : ty' := ecast ty ty strategy x. Notation simplrefl := (ltac: (simpl; reflexivity)) (only parsing). Notation cbvrefl := (ltac: (cbv; reflexivity)) (only parsing). Notation vmrefl := (ltac: (vm_compute; reflexivity)) (only parsing). (* From stdlib *) Module Pos. Import Pos. (** ** Conversion with a decimal representation for printing/parsing *) Local Notation ten := (xO (xI (xO xH))). Fixpoint of_uint_acc (d:Decimal.uint) (acc:positive) := match d with | Decimal.Nil => acc | Decimal.D0 l => of_uint_acc l (mul ten acc) | Decimal.D1 l => of_uint_acc l (add 1 (mul ten acc)) | Decimal.D2 l => of_uint_acc l (add 1~0 (mul ten acc)) | Decimal.D3 l => of_uint_acc l (add 1~1 (mul ten acc)) | Decimal.D4 l => of_uint_acc l (add 1~0~0 (mul ten acc)) | Decimal.D5 l => of_uint_acc l (add 1~0~1 (mul ten acc)) | Decimal.D6 l => of_uint_acc l (add 1~1~0 (mul ten acc)) | Decimal.D7 l => of_uint_acc l (add 1~1~1 (mul ten acc)) | Decimal.D8 l => of_uint_acc l (add 1~0~0~0 (mul ten acc)) | Decimal.D9 l => of_uint_acc l (add 1~0~0~1 (mul ten acc)) end. Fixpoint of_uint (d:Decimal.uint) : N := match d with | Decimal.Nil => N0 | Decimal.D0 l => of_uint l | Decimal.D1 l => Npos (of_uint_acc l 1) | Decimal.D2 l => Npos (of_uint_acc l 1~0) | Decimal.D3 l => Npos (of_uint_acc l 1~1) | Decimal.D4 l => Npos (of_uint_acc l 1~0~0) | Decimal.D5 l => Npos (of_uint_acc l 1~0~1) | Decimal.D6 l => Npos (of_uint_acc l 1~1~0) | Decimal.D7 l => Npos (of_uint_acc l 1~1~1) | Decimal.D8 l => Npos (of_uint_acc l 1~0~0~0) | Decimal.D9 l => Npos (of_uint_acc l 1~0~0~1) end. Local Notation sixteen := (xO (xO (xO (xO xH)))). Fixpoint of_hex_uint_acc (d:Hexadecimal.uint) (acc:positive) := match d with | Hexadecimal.Nil => acc | Hexadecimal.D0 l => of_hex_uint_acc l (mul sixteen acc) | Hexadecimal.D1 l => of_hex_uint_acc l (add 1 (mul sixteen acc)) | Hexadecimal.D2 l => of_hex_uint_acc l (add 1~0 (mul sixteen acc)) | Hexadecimal.D3 l => of_hex_uint_acc l (add 1~1 (mul sixteen acc)) | Hexadecimal.D4 l => of_hex_uint_acc l (add 1~0~0 (mul sixteen acc)) | Hexadecimal.D5 l => of_hex_uint_acc l (add 1~0~1 (mul sixteen acc)) | Hexadecimal.D6 l => of_hex_uint_acc l (add 1~1~0 (mul sixteen acc)) | Hexadecimal.D7 l => of_hex_uint_acc l (add 1~1~1 (mul sixteen acc)) | Hexadecimal.D8 l => of_hex_uint_acc l (add 1~0~0~0 (mul sixteen acc)) | Hexadecimal.D9 l => of_hex_uint_acc l (add 1~0~0~1 (mul sixteen acc)) | Hexadecimal.Da l => of_hex_uint_acc l (add 1~0~1~0 (mul sixteen acc)) | Hexadecimal.Db l => of_hex_uint_acc l (add 1~0~1~1 (mul sixteen acc)) | Hexadecimal.Dc l => of_hex_uint_acc l (add 1~1~0~0 (mul sixteen acc)) | Hexadecimal.Dd l => of_hex_uint_acc l (add 1~1~0~1 (mul sixteen acc)) | Hexadecimal.De l => of_hex_uint_acc l (add 1~1~1~0 (mul sixteen acc)) | Hexadecimal.Df l => of_hex_uint_acc l (add 1~1~1~1 (mul sixteen acc)) end. Fixpoint of_hex_uint (d:Hexadecimal.uint) : N := match d with | Hexadecimal.Nil => N0 | Hexadecimal.D0 l => of_hex_uint l | Hexadecimal.D1 l => Npos (of_hex_uint_acc l 1) | Hexadecimal.D2 l => Npos (of_hex_uint_acc l 1~0) | Hexadecimal.D3 l => Npos (of_hex_uint_acc l 1~1) | Hexadecimal.D4 l => Npos (of_hex_uint_acc l 1~0~0) | Hexadecimal.D5 l => Npos (of_hex_uint_acc l 1~0~1) | Hexadecimal.D6 l => Npos (of_hex_uint_acc l 1~1~0) | Hexadecimal.D7 l => Npos (of_hex_uint_acc l 1~1~1) | Hexadecimal.D8 l => Npos (of_hex_uint_acc l 1~0~0~0) | Hexadecimal.D9 l => Npos (of_hex_uint_acc l 1~0~0~1) | Hexadecimal.Da l => Npos (of_hex_uint_acc l 1~0~1~0) | Hexadecimal.Db l => Npos (of_hex_uint_acc l 1~0~1~1) | Hexadecimal.Dc l => Npos (of_hex_uint_acc l 1~1~0~0) | Hexadecimal.Dd l => Npos (of_hex_uint_acc l 1~1~0~1) | Hexadecimal.De l => Npos (of_hex_uint_acc l 1~1~1~0) | Hexadecimal.Df l => Npos (of_hex_uint_acc l 1~1~1~1) end. Definition of_int (d:Decimal.int) : option positive := match d with | Decimal.Pos d => match of_uint d with | N0 => None | Npos p => Some p end | Decimal.Neg _ => None end. Definition of_hex_int (d:Hexadecimal.int) : option positive := match d with | Hexadecimal.Pos d => match of_hex_uint d with | N0 => None | Npos p => Some p end | Hexadecimal.Neg _ => None end. Definition of_num_int (d:Number.int) : option positive := match d with | Number.IntDecimal d => of_int d | Number.IntHexadecimal d => of_hex_int d end. Fixpoint to_little_uint p := match p with | xH => Decimal.D1 Decimal.Nil | xI p => Decimal.Little.succ_double (to_little_uint p) | xO p => Decimal.Little.double (to_little_uint p) end. Definition to_uint p := Decimal.rev (to_little_uint p). Definition to_num_uint p := Number.UIntDecimal (to_uint p). (** ** Successor *) Definition Nsucc n := match n with | N0 => Npos xH | Npos p => Npos (Pos.succ p) end. Lemma nat_of_succ_bin b : nat_of_bin (Nsucc b) = 1 + nat_of_bin b :> nat. Proof. by case: b => [//|p /=]; rewrite nat_of_succ_pos. Qed. Theorem eqb_eq p q : Pos.eqb p q = true <-> p=q. Proof. by elim: p q => [p IHp|p IHp|] [q|q|] //=; split=> [/IHp->//|]; case=> /IHp. Qed. End Pos. Module AC. HB.instance Definition _ := hasDecEq.Build positive (fun _ _ => equivP idP (Pos.eqb_eq _ _)). Inductive syntax := Leaf of positive | Op of syntax & syntax. Coercion serial := (fix loop (acc : seq positive) (s : syntax) := match s with | Leaf n => n :: acc | Op s s' => (loop^~ s (loop^~ s' acc)) end) [::]. Lemma serial_Op s1 s2 : Op s1 s2 = s1 ++ s2 :> seq _. Proof. rewrite /serial; set loop := (X in X [::]); rewrite -/loop. elim: s1 (loop [::] s2) => [n|s11 IHs1 s12 IHs2] //= l. by rewrite IHs1 [in RHS]IHs1 IHs2 catA. Qed. Definition Leaf_of_nat n := Leaf (Pos.sub (pos_of_nat n n) xH). Module Import Syntax. Bind Scope AC_scope with syntax. Number Notation positive Pos.of_num_int Pos.to_num_uint : AC_scope. Coercion Leaf : positive >-> syntax. Coercion Leaf_of_nat : nat >-> syntax. Notation "x * y" := (Op x%AC y%AC) : AC_scope. End Syntax. Definition pattern (s : syntax) := ((fix loop n s := match s with | Leaf 1%positive => (Leaf n, Pos.succ n) | Leaf m => Pos.iter (fun oi => (Op oi.1 (Leaf oi.2), Pos.succ oi.2)) (Leaf n, Pos.succ n) (Pos.sub m xH) | Op s s' => let: (p, n') := loop n s in let: (p', n'') := loop n' s' in (Op p p', n'') end) 1%positive s).1. Section eval. Variables (T : Type) (idx : T) (op : T -> T -> T). Inductive env := Empty | ENode of T & env & env. Definition pos := fix loop (e : env) p {struct e} := match e, p with | ENode t _ _, 1%positive => t | ENode t e _, (p~0)%positive => loop e p | ENode t _ e, (p~1)%positive => loop e p | _, _ => idx end. Definition set_pos (f : T -> T) := fix loop e p {struct p} := match e, p with | ENode t e e', 1%positive => ENode (f t) e e' | ENode t e e', (p~0)%positive => ENode t (loop e p) e' | ENode t e e', (p~1)%positive => ENode t e (loop e' p) | Empty, 1%positive => ENode (f idx) Empty Empty | Empty, (p~0)%positive => ENode idx (loop Empty p) Empty | Empty, (p~1)%positive => ENode idx Empty (loop Empty p) end. Lemma pos_set_pos (f : T -> T) e (p p' : positive) : pos (set_pos f e p) p' = if p == p' then f (pos e p) else pos e p'. Proof. by elim: p e p' => [p IHp|p IHp|] [|???] [?|?|]//=; rewrite IHp. Qed. Fixpoint unzip z (e : env) : env := match z with | [::] => e | (x, inl e') :: z' => unzip z' (ENode x e' e) | (x, inr e') :: z' => unzip z' (ENode x e e') end. Definition set_pos_trec (f : T -> T) := fix loop z e p {struct p} := match e, p with | ENode t e e', 1%positive => unzip z (ENode (f t) e e') | ENode t e e', (p~0)%positive => loop ((t, inr e') :: z) e p | ENode t e e', (p~1)%positive => loop ((t, inl e) :: z) e' p | Empty, 1%positive => unzip z (ENode (f idx) Empty Empty) | Empty, (p~0)%positive => loop ((idx, (inr Empty)) :: z) Empty p | Empty, (p~1)%positive => loop ((idx, (inl Empty)) :: z) Empty p end. Lemma set_pos_trecE f z e p : set_pos_trec f z e p = unzip z (set_pos f e p). Proof. by elim: p e z => [p IHp|p IHp|] [|???] [|[??]?] //=; rewrite ?IHp. Qed. Definition eval (e : env) := fix loop (s : syntax) := match s with | Leaf n => pos e n | Op s s' => op (loop s) (loop s') end. End eval. Arguments Empty {T}. Definition content := (fix loop (acc : env N) s := match s with | Leaf n => set_pos_trec N0 Pos.Nsucc [::] acc n | Op s s' => loop (loop acc s') s end) Empty. Lemma count_memE x (t : syntax) : count_mem x t = nat_of_bin (pos N0 (content t) x). Proof. rewrite /content; set loop := (X in X Empty); rewrite -/loop. rewrite -[LHS]addn0. have <- : nat_of_bin (pos N0 Empty x) = 0 :> nat by elim: x. elim: t Empty => [n|s IHs s' IHs'] e //=; last first. by rewrite serial_Op count_cat -addnA IHs' IHs. rewrite ?addn0 set_pos_trecE pos_set_pos; case: (altP eqP) => [->|] //=. by rewrite Pos.nat_of_succ_bin. Qed. Definition cforall N T : env N -> (env T -> Type) -> Type := env_rect (@^~ Empty) (fun _ e IHe e' IHe' R => forall x, IHe (fun xe => IHe' (R \o ENode x xe))). Lemma cforallP N T R : (forall e : env T, R e) -> forall (e : env N), cforall e R. Proof. move=> Re e; elim: e R Re => [|? e /= IHe e' IHe' ?? x] //=. by apply: IHe => ?; apply: IHe' => /=. Qed. Section eq_eval. Variables (T : Type) (idx : T) (op : Monoid.com_law idx). Lemma proof (p s : syntax) : content p = content s -> forall env, eval idx op env p = eval idx op env s. Proof. suff evalE env t : eval idx op env t = \big[op/idx]_(i <- t) (pos idx env i). move=> cps e; rewrite !evalE; apply: perm_big. by apply/allP => x _ /=; rewrite !count_memE cps. elim: t => //= [n|t -> t' ->]; last by rewrite serial_Op big_cat. by rewrite big_cons big_nil Monoid.mulm1. Qed. Definition direct p s ps := cforallP (@proof p s ps) (content p). End eq_eval. Module Exports. Export AC.Syntax. End Exports. End AC. Export AC.Exports. Notation AC_check_pattern := (ltac: (match goal with |- AC.content ?pat = AC.content ?ord => let pat' := fresh "pat" in let pat' := eval compute in pat in tryif unify pat' ord then fail 1 "AC: equality between" pat "and" ord "is trivial, cannot progress" else tryif vm_compute; reflexivity then idtac else fail 2 "AC: mismatch between shape" pat "=" pat' "and reordering" ord | |- ?G => fail 3 "AC: no pattern to check" G end)) (only parsing). Notation opACof law p s := ((fun T idx op assoc lid rid comm => (change_type (@AC.direct T idx (Monoid.ComLaw.Pack (* FIXME: find a way to make this robust to hierarchy evolutions *) (Monoid.ComLaw.Class (SemiGroup.isLaw.Axioms_ op assoc) (Monoid.isMonoidLaw.Axioms_ idx op lid rid) (SemiGroup.isCommutativeLaw.Axioms_ op comm))) p%AC s%AC AC_check_pattern) cbvrefl)) _ _ law (Monoid.mulmA _) (Monoid.mul1m _) (Monoid.mulm1 _) (Monoid.mulmC _)) (only parsing). Notation opAC op p s := (opACof op (AC.pattern p%AC) s%AC) (only parsing). Notation opACl op s := (opAC op (AC.Leaf_of_nat (size (AC.serial s%AC))) s%AC) (only parsing). Notation "op .[ 'ACof' p s ]" := (opACof op p%AC s%AC) (only parsing). Notation "op .[ 'AC' p s ]" := (opAC op p%AC s%AC) (only parsing). Notation "op .[ 'ACl' s ]" := (opACl op s%AC) (only parsing). Notation AC_strategy := (ltac: (cbv -[Monoid.ComLaw.sort Monoid.Law.sort]; reflexivity)) (only parsing). Notation ACof p s := (change_type (@AC.direct _ _ _ p%AC s%AC AC_check_pattern) AC_strategy) (only parsing). Notation AC p s := (ACof (AC.pattern p%AC) s%AC) (only parsing). Notation ACl s := (AC (AC.Leaf_of_nat (size (AC.serial s%AC))) s%AC) (only parsing).
all_field.v
From mathcomp Require Export algC. From mathcomp Require Export algebraics_fundamentals. From mathcomp Require Export algnum. From mathcomp Require Export closed_field. From mathcomp Require Export cyclotomic. From mathcomp Require Export falgebra. From mathcomp Require Export fieldext. From mathcomp Require Export finfield. From mathcomp Require Export galois. From mathcomp Require Export separable. From mathcomp Require Export qfpoly.
Basic.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.ContMDiff.Defs /-! ## Basic properties of `C^n` functions between manifolds In this file, we show that standard operations on `C^n` maps between manifolds are `C^n` : * `ContMDiffOn.comp` gives the invariance of the `Cⁿ` property under composition * `contMDiff_id` gives the smoothness of the identity * `contMDiff_const` gives the smoothness of constant functions * `contMDiff_inclusion` shows that the inclusion between open sets of a topological space is `C^n` * `contMDiff_isOpenEmbedding` shows that if `M` has a `ChartedSpace` structure induced by an open embedding `e : M → H`, then `e` is `C^n`. ## Tags chain rule, manifolds, higher derivative -/ open Filter Function Set Topology open scoped Manifold ContDiff variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare the prerequisites for a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] -- declare the prerequisites for a charted space `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] -- declare the prerequisites for a charted space `M''` over the pair `(E'', H'')`. {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] section ChartedSpace variable [ChartedSpace H M] [ChartedSpace H' M'] [ChartedSpace H'' M''] -- declare functions, sets, points and smoothness indices {f : M → M'} {s : Set M} {x : M} {n : WithTop ℕ∞} /-! ### Regularity of the composition of `C^n` functions between manifolds -/ section Composition /-- The composition of `C^n` functions within domains at points is `C^n`. -/ theorem ContMDiffWithinAt.comp {t : Set M'} {g : M' → M''} (x : M) (hg : ContMDiffWithinAt I' I'' n g t (f x)) (hf : ContMDiffWithinAt I I' n f s x) (st : MapsTo f s t) : ContMDiffWithinAt I I'' n (g ∘ f) s x := by rw [contMDiffWithinAt_iff] at hg hf ⊢ refine ⟨hg.1.comp hf.1 st, ?_⟩ set e := extChartAt I x set e' := extChartAt I' (f x) have : e' (f x) = (writtenInExtChartAt I I' x f) (e x) := by simp only [e, e', mfld_simps] rw [this] at hg have A : ∀ᶠ y in 𝓝[e.symm ⁻¹' s ∩ range I] e x, f (e.symm y) ∈ t ∧ f (e.symm y) ∈ e'.source := by simp only [e, ← map_extChartAt_nhdsWithin, eventually_map] filter_upwards [hf.1.tendsto (extChartAt_source_mem_nhds (I := I') (f x)), inter_mem_nhdsWithin s (extChartAt_source_mem_nhds (I := I) x)] rintro x' (hfx' : f x' ∈ e'.source) ⟨hx's, hx'⟩ simp only [e, true_and, e.left_inv hx', st hx's, *] refine ((hg.2.comp _ (hf.2.mono inter_subset_right) ((mapsTo_preimage _ _).mono_left inter_subset_left)).mono_of_mem_nhdsWithin (inter_mem ?_ self_mem_nhdsWithin)).congr_of_eventuallyEq ?_ ?_ · filter_upwards [A] rintro x' ⟨ht, hfx'⟩ simp only [*, e, e',mem_preimage, writtenInExtChartAt, (· ∘ ·), mem_inter_iff, e'.left_inv, true_and] exact mem_range_self _ · filter_upwards [A] rintro x' ⟨-, hfx'⟩ simp only [*, e, e', (· ∘ ·), writtenInExtChartAt, e'.left_inv] · simp only [e, e', writtenInExtChartAt, (· ∘ ·), mem_extChartAt_source, e.left_inv, e'.left_inv] /-- See note [comp_of_eq lemmas] -/ theorem ContMDiffWithinAt.comp_of_eq {t : Set M'} {g : M' → M''} {x : M} {y : M'} (hg : ContMDiffWithinAt I' I'' n g t y) (hf : ContMDiffWithinAt I I' n f s x) (st : MapsTo f s t) (hx : f x = y) : ContMDiffWithinAt I I'' n (g ∘ f) s x := by subst hx; exact hg.comp x hf st /-- The composition of `C^n` functions on domains is `C^n`. -/ theorem ContMDiffOn.comp {t : Set M'} {g : M' → M''} (hg : ContMDiffOn I' I'' n g t) (hf : ContMDiffOn I I' n f s) (st : s ⊆ f ⁻¹' t) : ContMDiffOn I I'' n (g ∘ f) s := fun x hx => (hg _ (st hx)).comp x (hf x hx) st /-- The composition of `C^n` functions on domains is `C^n`. -/ theorem ContMDiffOn.comp' {t : Set M'} {g : M' → M''} (hg : ContMDiffOn I' I'' n g t) (hf : ContMDiffOn I I' n f s) : ContMDiffOn I I'' n (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right /-- The composition of `C^n` functions is `C^n`. -/ theorem ContMDiff.comp {g : M' → M''} (hg : ContMDiff I' I'' n g) (hf : ContMDiff I I' n f) : ContMDiff I I'' n (g ∘ f) := by rw [← contMDiffOn_univ] at hf hg ⊢ exact hg.comp hf subset_preimage_univ /-- The composition of `C^n` functions within domains at points is `C^n`. -/ theorem ContMDiffWithinAt.comp' {t : Set M'} {g : M' → M''} (x : M) (hg : ContMDiffWithinAt I' I'' n g t (f x)) (hf : ContMDiffWithinAt I I' n f s x) : ContMDiffWithinAt I I'' n (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp x (hf.mono inter_subset_left) inter_subset_right /-- `g ∘ f` is `C^n` within `s` at `x` if `g` is `C^n` at `f x` and `f` is `C^n` within `s` at `x`. -/ theorem ContMDiffAt.comp_contMDiffWithinAt {g : M' → M''} (x : M) (hg : ContMDiffAt I' I'' n g (f x)) (hf : ContMDiffWithinAt I I' n f s x) : ContMDiffWithinAt I I'' n (g ∘ f) s x := hg.comp x hf (mapsTo_univ _ _) /-- `g ∘ f` is `C^n` within `s` at `x` if `g` is `C^n` at `f x` and `f` is `C^n` within `s` at `x`. -/ theorem ContMDiffAt.comp_contMDiffWithinAt_of_eq {g : M' → M''} {x : M} {y : M'} (hg : ContMDiffAt I' I'' n g y) (hf : ContMDiffWithinAt I I' n f s x) (hx : f x = y) : ContMDiffWithinAt I I'' n (g ∘ f) s x := by subst hx; exact hg.comp_contMDiffWithinAt x hf /-- The composition of `C^n` functions at points is `C^n`. -/ nonrec theorem ContMDiffAt.comp {g : M' → M''} (x : M) (hg : ContMDiffAt I' I'' n g (f x)) (hf : ContMDiffAt I I' n f x) : ContMDiffAt I I'' n (g ∘ f) x := hg.comp x hf (mapsTo_univ _ _) /-- See note [comp_of_eq lemmas] -/ theorem ContMDiffAt.comp_of_eq {g : M' → M''} {x : M} {y : M'} (hg : ContMDiffAt I' I'' n g y) (hf : ContMDiffAt I I' n f x) (hx : f x = y) : ContMDiffAt I I'' n (g ∘ f) x := by subst hx; exact hg.comp x hf theorem ContMDiff.comp_contMDiffOn {f : M → M'} {g : M' → M''} {s : Set M} (hg : ContMDiff I' I'' n g) (hf : ContMDiffOn I I' n f s) : ContMDiffOn I I'' n (g ∘ f) s := hg.contMDiffOn.comp hf Set.subset_preimage_univ theorem ContMDiffOn.comp_contMDiff {t : Set M'} {g : M' → M''} (hg : ContMDiffOn I' I'' n g t) (hf : ContMDiff I I' n f) (ht : ∀ x, f x ∈ t) : ContMDiff I I'' n (g ∘ f) := contMDiffOn_univ.mp <| hg.comp hf.contMDiffOn fun x _ => ht x end Composition /-! ### The identity is `C^n` -/ section id theorem contMDiff_id : ContMDiff I I n (id : M → M) := ContMDiff.of_le ((contDiffWithinAt_localInvariantProp ⊤).liftProp_id contDiffWithinAtProp_id) le_top theorem contMDiffOn_id : ContMDiffOn I I n (id : M → M) s := contMDiff_id.contMDiffOn theorem contMDiffAt_id : ContMDiffAt I I n (id : M → M) x := contMDiff_id.contMDiffAt theorem contMDiffWithinAt_id : ContMDiffWithinAt I I n (id : M → M) s x := contMDiffAt_id.contMDiffWithinAt end id /-! ### Constants are `C^n` -/ section const variable {c : M'} theorem contMDiff_const : ContMDiff I I' n fun _ : M => c := by intro x refine ⟨continuousWithinAt_const, ?_⟩ simp only [ContDiffWithinAtProp, Function.comp_def] exact contDiffWithinAt_const @[to_additive] theorem contMDiff_one [One M'] : ContMDiff I I' n (1 : M → M') := by simp only [Pi.one_def, contMDiff_const] theorem contMDiffOn_const : ContMDiffOn I I' n (fun _ : M => c) s := contMDiff_const.contMDiffOn @[to_additive] theorem contMDiffOn_one [One M'] : ContMDiffOn I I' n (1 : M → M') s := contMDiff_one.contMDiffOn theorem contMDiffAt_const : ContMDiffAt I I' n (fun _ : M => c) x := contMDiff_const.contMDiffAt @[to_additive] theorem contMDiffAt_one [One M'] : ContMDiffAt I I' n (1 : M → M') x := contMDiff_one.contMDiffAt theorem contMDiffWithinAt_const : ContMDiffWithinAt I I' n (fun _ : M => c) s x := contMDiffAt_const.contMDiffWithinAt @[to_additive] theorem contMDiffWithinAt_one [One M'] : ContMDiffWithinAt I I' n (1 : M → M') s x := contMDiffAt_const.contMDiffWithinAt @[nontriviality] theorem contMDiff_of_subsingleton [Subsingleton M'] : ContMDiff I I' n f := by intro x rw [Subsingleton.elim f fun _ => (f x)] exact contMDiffAt_const @[nontriviality] theorem contMDiffAt_of_subsingleton [Subsingleton M'] : ContMDiffAt I I' n f x := contMDiff_of_subsingleton.contMDiffAt @[nontriviality] theorem contMDiffWithinAt_of_subsingleton [Subsingleton M'] : ContMDiffWithinAt I I' n f s x := contMDiffAt_of_subsingleton.contMDiffWithinAt @[nontriviality] theorem contMDiffOn_of_subsingleton [Subsingleton M'] : ContMDiffOn I I' n f s := contMDiff_of_subsingleton.contMDiffOn lemma contMDiff_of_discreteTopology [DiscreteTopology M] : ContMDiff I I' n f := by intro x -- f is locally constant, and constant functions are smooth. apply contMDiff_const (c := f x).contMDiffAt.congr_of_eventuallyEq simp [EventuallyEq] end const /-- `f` is continuously differentiable if it is cont. differentiable at each `x ∈ mulTSupport f`. -/ @[to_additive /-- `f` is continuously differentiable if it is continuously differentiable at each `x ∈ tsupport f`. See also `contMDiff_section_of_tsupport` for a similar result for sections of vector bundles. -/] theorem contMDiff_of_mulTSupport [One M'] {f : M → M'} (hf : ∀ x ∈ mulTSupport f, ContMDiffAt I I' n f x) : ContMDiff I I' n f := by intro x by_cases hx : x ∈ mulTSupport f · exact hf x hx · exact ContMDiffAt.congr_of_eventuallyEq contMDiffAt_const (notMem_mulTSupport_iff_eventuallyEq.1 hx) @[to_additive contMDiffWithinAt_of_notMem] theorem contMDiffWithinAt_of_notMem_mulTSupport {f : M → M'} [One M'] {x : M} (hx : x ∉ mulTSupport f) (n : WithTop ℕ∞) (s : Set M) : ContMDiffWithinAt I I' n f s x := by apply contMDiffWithinAt_const.congr_of_eventuallyEq (eventually_nhdsWithin_of_eventually_nhds <| notMem_mulTSupport_iff_eventuallyEq.mp hx) (image_eq_one_of_notMem_mulTSupport hx) @[deprecated (since := "2025-05-23")] alias contMDiffWithinAt_of_not_mem := contMDiffWithinAt_of_notMem @[to_additive existing contMDiffWithinAt_of_not_mem, deprecated (since := "2025-05-23")] alias contMDiffWithinAt_of_not_mem_mulTSupport := contMDiffWithinAt_of_notMem_mulTSupport /-- `f` is continuously differentiable at each point outside of its `mulTSupport`. -/ @[to_additive contMDiffAt_of_notMem] theorem contMDiffAt_of_notMem_mulTSupport {f : M → M'} [One M'] {x : M} (hx : x ∉ mulTSupport f) (n : WithTop ℕ∞) : ContMDiffAt I I' n f x := contMDiffWithinAt_of_notMem_mulTSupport hx n univ @[deprecated (since := "2025-05-23")] alias contMDiffAt_of_not_mem := contMDiffAt_of_notMem @[to_additive existing contMDiffAt_of_not_mem, deprecated (since := "2025-05-23")] alias contMDiffAt_of_not_mem_mulTSupport := contMDiffAt_of_notMem_mulTSupport /-- Given two `C^n` functions `f` and `g` which coincide locally around the frontier of a set `s`, then the piecewise function defined using `f` on `s` and `g` elsewhere is `C^n`. -/ lemma ContMDiff.piecewise {f g : M → M'} {s : Set M} [DecidablePred (· ∈ s)] (hf : ContMDiff I I' n f) (hg : ContMDiff I I' n g) (hfg : ∀ x ∈ frontier s, f =ᶠ[𝓝 x] g) : ContMDiff I I' n (piecewise s f g) := by intro x by_cases hx : x ∈ interior s · apply (hf x).congr_of_eventuallyEq filter_upwards [isOpen_interior.mem_nhds hx] with y hy rw [piecewise_eq_of_mem] apply interior_subset hy by_cases h'x : x ∈ closure s · have : x ∈ frontier s := ⟨h'x, hx⟩ apply (hf x).congr_of_eventuallyEq filter_upwards [hfg x this] with y hy simp [Set.piecewise, hy] · apply (hg x).congr_of_eventuallyEq filter_upwards [isClosed_closure.isOpen_compl.mem_nhds h'x] with y hy rw [piecewise_eq_of_notMem] contrapose! hy simpa using subset_closure hy /-- Given two `C^n` functions `f` and `g` from `ℝ` to a real manifold which coincide locally around a point `s`, then the piecewise function using `f` before `t` and `g` after is `C^n`. -/ lemma ContMDiff.piecewise_Iic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {f g : ℝ → M} {s : ℝ} (hf : ContMDiff 𝓘(ℝ) I n f) (hg : ContMDiff 𝓘(ℝ) I n g) (hfg : f =ᶠ[𝓝 s] g) : ContMDiff 𝓘(ℝ) I n (Set.piecewise (Iic s) f g) := hf.piecewise hg (by simpa using hfg) /-! ### Being `C^k` on a union of open sets can be tested on each set -/ section contMDiff_union variable {s t : Set M} /-- If a function is `C^k` on two open sets, it is also `C^n` on their union. -/ lemma ContMDiffOn.union_of_isOpen (hf : ContMDiffOn I I' n f s) (hf' : ContMDiffOn I I' n f t) (hs : IsOpen s) (ht : IsOpen t) : ContMDiffOn I I' n f (s ∪ t) := by intro x hx obtain (hx | hx) := hx · exact (hf x hx).contMDiffAt (hs.mem_nhds hx) |>.contMDiffWithinAt · exact (hf' x hx).contMDiffAt (ht.mem_nhds hx) |>.contMDiffWithinAt /-- A function is `C^k` on two open sets iff it is `C^k` on their union. -/ lemma contMDiffOn_union_iff_of_isOpen (hs : IsOpen s) (ht : IsOpen t) : ContMDiffOn I I' n f (s ∪ t) ↔ ContMDiffOn I I' n f s ∧ ContMDiffOn I I' n f t := ⟨fun h ↦ ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun ⟨hfs, hft⟩ ↦ ContMDiffOn.union_of_isOpen hfs hft hs ht⟩ lemma contMDiff_of_contMDiffOn_union_of_isOpen (hf : ContMDiffOn I I' n f s) (hf' : ContMDiffOn I I' n f t) (hst : s ∪ t = univ) (hs : IsOpen s) (ht : IsOpen t) : ContMDiff I I' n f := by rw [← contMDiffOn_univ, ← hst] exact hf.union_of_isOpen hf' hs ht /-- If a function is `C^k` on open sets `s i`, it is `C^k` on their union -/ lemma ContMDiffOn.iUnion_of_isOpen {ι : Type*} {s : ι → Set M} (hf : ∀ i : ι, ContMDiffOn I I' n f (s i)) (hs : ∀ i, IsOpen (s i)) : ContMDiffOn I I' n f (⋃ i, s i) := by rintro x ⟨si, ⟨i, rfl⟩, hxsi⟩ exact (hf i).contMDiffAt ((hs i).mem_nhds hxsi) |>.contMDiffWithinAt /-- A function is `C^k` on a union of open sets `s i` iff it is `C^k` on each `s i`. -/ lemma contMDiffOn_iUnion_iff_of_isOpen {ι : Type*} {s : ι → Set M} (hs : ∀ i, IsOpen (s i)) : ContMDiffOn I I' n f (⋃ i, s i) ↔ ∀ i : ι, ContMDiffOn I I' n f (s i) := ⟨fun h i ↦ h.mono <| subset_iUnion_of_subset i fun _ a ↦ a, fun h ↦ ContMDiffOn.iUnion_of_isOpen h hs⟩ lemma contMDiff_of_contMDiffOn_iUnion_of_isOpen {ι : Type*} {s : ι → Set M} (hf : ∀ i : ι, ContMDiffOn I I' n f (s i)) (hs : ∀ i, IsOpen (s i)) (hs' : ⋃ i, s i = univ) : ContMDiff I I' n f := by rw [← contMDiffOn_univ, ← hs'] exact ContMDiffOn.iUnion_of_isOpen hf hs end contMDiff_union /-! ### The inclusion map from one open set to another is `C^n` -/ section Inclusion open TopologicalSpace theorem contMDiffAt_subtype_iff {n : WithTop ℕ∞} {U : Opens M} {f : M → M'} {x : U} : ContMDiffAt I I' n (fun x : U ↦ f x) x ↔ ContMDiffAt I I' n f x := ((contDiffWithinAt_localInvariantProp n).liftPropAt_iff_comp_subtype_val _ _).symm theorem contMDiff_subtype_val {n : WithTop ℕ∞} {U : Opens M} : ContMDiff I I n (Subtype.val : U → M) := fun _ ↦ contMDiffAt_subtype_iff.mpr contMDiffAt_id @[to_additive] theorem ContMDiff.extend_one [T2Space M] [One M'] {n : WithTop ℕ∞} {U : Opens M} {f : U → M'} (supp : HasCompactMulSupport f) (diff : ContMDiff I I' n f) : ContMDiff I I' n (Subtype.val.extend f 1) := fun x ↦ by refine contMDiff_of_mulTSupport (fun x h ↦ ?_) _ lift x to U using Subtype.coe_image_subset _ _ (supp.mulTSupport_extend_one_subset continuous_subtype_val h) rw [← contMDiffAt_subtype_iff] simp_rw [← comp_def] rw [extend_comp Subtype.val_injective] exact diff.contMDiffAt theorem contMDiff_inclusion {n : WithTop ℕ∞} {U V : Opens M} (h : U ≤ V) : ContMDiff I I n (Opens.inclusion h : U → V) := by rintro ⟨x, hx : x ∈ U⟩ apply (contDiffWithinAt_localInvariantProp n).liftProp_inclusion intro y dsimp only [ContDiffWithinAtProp, id_comp, preimage_univ] rw [Set.univ_inter] exact contDiffWithinAt_id.congr I.rightInvOn (congr_arg I (I.left_inv y)) end Inclusion end ChartedSpace /-! ### Open embeddings and their inverses are `C^n` -/ section variable {e : M → H} (h : IsOpenEmbedding e) {n : WithTop ℕ∞} /-- If the `ChartedSpace` structure on a manifold `M` is given by an open embedding `e : M → H`, then `e` is `C^n`. -/ lemma contMDiff_isOpenEmbedding [Nonempty M] : haveI := h.singletonChartedSpace; ContMDiff I I n e := by haveI := h.isManifold_singleton (I := I) (n := ω) rw [@contMDiff_iff _ _ _ _ _ _ _ _ _ _ h.singletonChartedSpace] use h.continuous intros x y -- show the function is actually the identity on the range of I ∘ e apply contDiffOn_id.congr intros z hz -- factorise into the chart `e` and the model `id` simp only [mfld_simps] rw [h.toPartialHomeomorph_right_inv] · rw [I.right_inv] apply mem_of_subset_of_mem _ hz.1 exact letI := h.singletonChartedSpace; extChartAt_target_subset_range (I := I) x · -- `hz` implies that `z ∈ range (I ∘ e)` have := hz.1 rw [@extChartAt_target _ _ _ _ _ _ _ _ _ _ h.singletonChartedSpace] at this have := this.1 rw [mem_preimage, PartialHomeomorph.singletonChartedSpace_chartAt_eq, h.toPartialHomeomorph_target] at this exact this /-- If the `ChartedSpace` structure on a manifold `M` is given by an open embedding `e : M → H`, then the inverse of `e` is `C^n`. -/ lemma contMDiffOn_isOpenEmbedding_symm [Nonempty M] : haveI := h.singletonChartedSpace; ContMDiffOn I I n (IsOpenEmbedding.toPartialHomeomorph e h).symm (range e) := by haveI := h.isManifold_singleton (I := I) (n := ω) rw [@contMDiffOn_iff] constructor · rw [← h.toPartialHomeomorph_target] exact (h.toPartialHomeomorph e).continuousOn_symm · intros z hz -- show the function is actually the identity on the range of I ∘ e apply contDiffOn_id.congr intros z hz -- factorise into the chart `e` and the model `id` simp only [mfld_simps] have : I.symm z ∈ range e := by rw [ModelWithCorners.symm, ← mem_preimage] exact hz.2.1 rw [h.toPartialHomeomorph_right_inv e this] apply I.right_inv exact mem_of_subset_of_mem (extChartAt_target_subset_range _) hz.1 variable [ChartedSpace H M] variable [Nonempty M'] {e' : M' → H'} (h' : IsOpenEmbedding e') /-- Let `M'` be a manifold whose chart structure is given by an open embedding `e'` into its model space `H'`. If `e' ∘ f : M → H'` is `C^n`, then `f` is `C^n`. This is useful, for example, when `e' ∘ f = g ∘ e` for smooth maps `e : M → X` and `g : X → H'`. -/ lemma ContMDiff.of_comp_isOpenEmbedding {f : M → M'} (hf : ContMDiff I I' n (e' ∘ f)) : haveI := h'.singletonChartedSpace; ContMDiff I I' n f := by have : f = (h'.toPartialHomeomorph e').symm ∘ e' ∘ f := by ext rw [Function.comp_apply, Function.comp_apply, IsOpenEmbedding.toPartialHomeomorph_left_inv] rw [this] apply @ContMDiffOn.comp_contMDiff _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ h'.singletonChartedSpace _ _ (range e') _ (contMDiffOn_isOpenEmbedding_symm h') hf simp end
Orthogonality.lean
/- Copyright (c) 2023 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.BigOperators.Expect import Mathlib.Algebra.Group.AddChar import Mathlib.Analysis.RCLike.Inner /-! # Orthogonality of characters of a finite abelian group This file proves that characters of a finite abelian group are orthogonal, and in particular that there are at most as many characters as there are elements of the group. -/ open Finset hiding card open Fintype (card) open Function RCLike open scoped BigOperators ComplexConjugate DirectSum variable {G H R : Type*} namespace AddChar section AddGroup variable [AddGroup G] section Semifield variable [Fintype G] [Semifield R] [IsDomain R] [CharZero R] {ψ : AddChar G R} lemma expect_eq_ite (ψ : AddChar G R) : 𝔼 a, ψ a = if ψ = 0 then 1 else 0 := by simp [Fintype.expect_eq_sum_div_card, sum_eq_ite, ite_div] lemma expect_eq_zero_iff_ne_zero : 𝔼 x, ψ x = 0 ↔ ψ ≠ 0 := by rw [expect_eq_ite, one_ne_zero.ite_eq_right_iff] lemma expect_ne_zero_iff_eq_zero : 𝔼 x, ψ x ≠ 0 ↔ ψ = 0 := expect_eq_zero_iff_ne_zero.not_left end Semifield section RCLike variable [RCLike R] [Fintype G] lemma wInner_cWeight_self (ψ : AddChar G R) : ⟪(ψ : G → R), ψ⟫ₙ_[R] = 1 := by simp [wInner_cWeight_eq_expect, ψ.norm_apply, RCLike.mul_conj] end RCLike end AddGroup section AddCommGroup variable [AddCommGroup G] section RCLike variable [RCLike R] {ψ₁ ψ₂ : AddChar G R} lemma wInner_cWeight_eq_boole [Fintype G] (ψ₁ ψ₂ : AddChar G R) : ⟪(ψ₁ : G → R), ψ₂⟫ₙ_[R] = if ψ₁ = ψ₂ then 1 else 0 := by split_ifs with h · rw [h, wInner_cWeight_self] have : ψ₂ * ψ₁⁻¹ ≠ 1 := by rwa [Ne, mul_inv_eq_one, eq_comm] simp_rw [wInner_cWeight_eq_expect, RCLike.inner_apply, ← inv_apply_eq_conj] simpa [map_neg_eq_inv] using expect_eq_zero_iff_ne_zero.2 this lemma wInner_cWeight_eq_zero_iff_ne [Fintype G] : ⟪(ψ₁ : G → R), ψ₂⟫ₙ_[R] = 0 ↔ ψ₁ ≠ ψ₂ := by rw [wInner_cWeight_eq_boole, one_ne_zero.ite_eq_right_iff] lemma wInner_cWeight_eq_one_iff_eq [Fintype G] : ⟪(ψ₁ : G → R), ψ₂⟫ₙ_[R] = 1 ↔ ψ₁ = ψ₂ := by rw [wInner_cWeight_eq_boole, one_ne_zero.ite_eq_left_iff] variable (G R) protected lemma linearIndependent [Finite G] : LinearIndependent R ((⇑) : AddChar G R → G → R) := by cases nonempty_fintype G exact linearIndependent_of_ne_zero_of_wInner_cWeight_eq_zero coe_ne_zero fun ψ₁ ψ₂ ↦ wInner_cWeight_eq_zero_iff_ne.2 noncomputable instance instFintype [Finite G] : Fintype (AddChar G R) := @Fintype.ofFinite _ (AddChar.linearIndependent G R).finite @[simp] lemma card_addChar_le [Fintype G] : card (AddChar G R) ≤ card G := by simpa only [Module.finrank_fintype_fun_eq_card] using (AddChar.linearIndependent G R).fintype_card_le_finrank end RCLike end AddCommGroup end AddChar
Compact.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Topology.Algebra.Group.Pointwise import Mathlib.Topology.Sets.Compacts /-! # Additional results on topological groups A result on topological groups that has been separated out as it requires more substantial imports developing positive compacts. -/ universe u variable {G : Type u} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] /-- Every topological group in which there exists a compact set with nonempty interior is locally compact. -/ @[to_additive /-- Every topological additive group in which there exists a compact set with nonempty interior is locally compact. -/] theorem TopologicalSpace.PositiveCompacts.locallyCompactSpace_of_group (K : PositiveCompacts G) : LocallyCompactSpace G := let ⟨_x, hx⟩ := K.interior_nonempty K.isCompact.locallyCompactSpace_of_mem_nhds_of_group (mem_interior_iff_mem_nhds.1 hx)
Grp_.lean
/- Copyright (c) 2025 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Category.Grp.Limits import Mathlib.CategoryTheory.Monoidal.Grp_ /-! # Yoneda embedding of `Grp_ C` We show that group objects are exactly those whose yoneda presheaf is a presheaf of groups, by constructing the yoneda embedding `Grp_ C ⥤ Cᵒᵖ ⥤ Grp.{v}` and showing that it is fully faithful and its (essential) image is the representable functors. -/ assert_not_exists Field open CategoryTheory MonoidalCategory Limits Opposite CartesianMonoidalCategory Mon_Class universe w v u variable {C : Type u} [Category.{v} C] [CartesianMonoidalCategory C] {M G H X Y : C} [Mon_Class M] [Grp_Class G] [Grp_Class H] /-- Construct a morphism `G ⟶ H` of `Grp_ C` C from a map `f : G ⟶ H` and a `IsMon_Hom f` instance. -/ @[simps] def Grp_.homMk (f : G ⟶ H) [IsMon_Hom f] : .mk G ⟶ Grp_.mk H := ⟨f⟩ variable (X) in /-- If `X` represents a presheaf of monoids, then `X` is a monoid object. -/ def Grp_Class.ofRepresentableBy (F : Cᵒᵖ ⥤ Grp.{w}) (α : (F ⋙ forget _).RepresentableBy X) : Grp_Class X where __ := Mon_Class.ofRepresentableBy X (F ⋙ forget₂ Grp MonCat) α inv := α.homEquiv.symm (α.homEquiv (𝟙 _))⁻¹ left_inv := by change lift (α.homEquiv.symm (α.homEquiv (𝟙 X))⁻¹) (𝟙 X) ≫ α.homEquiv.symm (α.homEquiv (fst X X) * α.homEquiv (snd X X)) = toUnit X ≫ α.homEquiv.symm 1 apply α.homEquiv.injective simp only [α.homEquiv_comp, Equiv.apply_symm_apply] simp only [Functor.comp_map, ConcreteCategory.forget_map_eq_coe, map_one, map_mul] simp only [← ConcreteCategory.forget_map_eq_coe, ← Functor.comp_map, ← α.homEquiv_comp] simp [- Functor.comp_obj] right_inv := by change lift (𝟙 X) (α.homEquiv.symm (α.homEquiv (𝟙 X))⁻¹) ≫ α.homEquiv.symm (α.homEquiv (fst X X) * α.homEquiv (snd X X)) = toUnit X ≫ α.homEquiv.symm 1 apply α.homEquiv.injective simp only [α.homEquiv_comp, Equiv.apply_symm_apply] simp only [Functor.comp_map, ConcreteCategory.forget_map_eq_coe, map_one, map_mul] simp only [← ConcreteCategory.forget_map_eq_coe, ← Functor.comp_map, ← α.homEquiv_comp] simp [- Functor.comp_obj] /-- If `G` is a group object, then `Hom(X, G)` has a group structure. -/ abbrev Hom.group : Group (X ⟶ G) where inv f := f ≫ ι inv_mul_cancel f := calc lift (f ≫ ι) f ≫ μ _ = (f ≫ lift ι (𝟙 G)) ≫ μ := by simp _ = toUnit X ≫ η := by rw [Category.assoc]; simp scoped[Mon_Class] attribute [instance] Hom.group lemma Hom.inv_def (f : X ⟶ G) : f⁻¹ = f ≫ ι := rfl variable (G) in /-- If `G` is a group object, then `Hom(-, G)` is a presheaf of groups. -/ @[simps] def yonedaGrpObj : Cᵒᵖ ⥤ Grp.{v} where obj X := Grp.of (unop X ⟶ G) map φ := Grp.ofHom ((yonedaMonObj G).map φ).hom variable (G) in /-- If `G` is a monoid object, then `Hom(-, G)` as a presheaf of monoids is represented by `G`. -/ def yonedaGrpObjRepresentableBy : (yonedaGrpObj G ⋙ forget _).RepresentableBy G := Functor.representableByEquiv.symm (.refl _) variable (G) in lemma Grp_Class.ofRepresentableBy_yonedaGrpObjRepresentableBy : ofRepresentableBy G _ (yonedaGrpObjRepresentableBy G) = ‹Grp_Class G› := by ext; change lift (fst G G) (snd G G) ≫ μ = μ; rw [lift_fst_snd, Category.id_comp] variable (X) in /-- If `X` represents a presheaf of groups `F`, then `Hom(-, X)` is isomorphic to `F` as a presheaf of groups. -/ @[simps! hom inv] def yonedaGrpObjIsoOfRepresentableBy (F : Cᵒᵖ ⥤ Grp.{v}) (α : (F ⋙ forget _).RepresentableBy X) : letI := Grp_Class.ofRepresentableBy X F α yonedaGrpObj X ≅ F := letI := Grp_Class.ofRepresentableBy X F α NatIso.ofComponents (fun Y ↦ MulEquiv.toGrpIso { toEquiv := α.homEquiv map_mul' := ((yonedaMonObjIsoOfRepresentableBy X (F ⋙ forget₂ Grp MonCat) α).hom.app Y).hom.map_mul}) fun φ ↦ Grp.hom_ext <| MonoidHom.ext <| α.homEquiv_comp φ.unop /-- The yoneda embedding of `Grp_C` into presheaves of groups. -/ @[simps] def yonedaGrp : Grp_ C ⥤ Cᵒᵖ ⥤ Grp.{v} where obj G := yonedaGrpObj G.X map {G H} ψ := { app Y := Grp.ofHom ((yonedaMon.map ψ).app Y).hom } @[reassoc] lemma yonedaGrp_naturality (α : yonedaGrpObj G ⟶ yonedaGrpObj H) (f : X ⟶ Y) (g : Y ⟶ G) : α.app _ (f ≫ g) = f ≫ α.app _ g := congr($(α.naturality f.op) g) /-- The yoneda embedding for `Grp_C` is fully faithful. -/ def yonedaGrpFullyFaithful : yonedaGrp (C := C).FullyFaithful where preimage {G H} α := yonedaMonFullyFaithful.preimage (Functor.whiskerRight α (forget₂ Grp MonCat)) map_preimage {G H} α := by ext X : 3 exact congr(($(yonedaMonFullyFaithful.map_preimage (X := G.toMon_) (Y := H.toMon_) (Functor.whiskerRight α (forget₂ Grp MonCat))).app X).hom) preimage_map := yonedaMonFullyFaithful.preimage_map instance : yonedaGrp (C := C).Full := yonedaGrpFullyFaithful.full instance : yonedaGrp (C := C).Faithful := yonedaGrpFullyFaithful.faithful lemma essImage_yonedaGrp : yonedaGrp (C := C).essImage = (· ⋙ forget _) ⁻¹' setOf Functor.IsRepresentable := by ext F constructor · rintro ⟨G, ⟨α⟩⟩ exact ⟨G.X, ⟨Functor.representableByEquiv.symm (Functor.isoWhiskerRight α (forget _))⟩⟩ · rintro ⟨X, ⟨e⟩⟩ letI := Grp_Class.ofRepresentableBy X F e exact ⟨⟨X⟩, ⟨yonedaGrpObjIsoOfRepresentableBy X F e⟩⟩ @[reassoc] lemma Grp_Class.inv_comp (f : X ⟶ G) (g : G ⟶ H) [IsMon_Hom g] : f⁻¹ ≫ g = (f ≫ g)⁻¹ := by simp [Hom.inv_def] @[reassoc] lemma Grp_Class.div_comp (f g : X ⟶ G) (h : G ⟶ H) [IsMon_Hom h] : (f / g) ≫ h = (f ≫ h) / (g ≫ h) := ((yonedaGrp.map <| Grp_.homMk h).app <| op X).hom.map_div f g @[reassoc] lemma Grp_Class.zpow_comp (f : X ⟶ G) (n : ℤ) (g : G ⟶ H) [IsMon_Hom g] : (f ^ n) ≫ g = (f ≫ g) ^ n := ((yonedaGrp.map <| Grp_.homMk g).app <| op X).hom.map_zpow f n @[reassoc] lemma Grp_Class.comp_inv (f : X ⟶ Y) (g : Y ⟶ G) : f ≫ g⁻¹ = (f ≫ g)⁻¹ := ((yonedaGrp.obj ⟨G⟩).map f.op).hom.map_inv g @[reassoc] lemma Grp_Class.comp_div (f : X ⟶ Y) (g h : Y ⟶ G) : f ≫ (g / h) = f ≫ g / f ≫ h := ((yonedaGrp.obj ⟨G⟩).map f.op).hom.map_div g h @[reassoc] lemma Grp_Class.comp_zpow (f : X ⟶ Y) (g : Y ⟶ G) : ∀ n : ℤ, f ≫ g ^ n = (f ≫ g) ^ n | (n : ℕ) => by simp [comp_pow] | .negSucc n => by simp [comp_pow, comp_inv] lemma Grp_Class.inv_eq_inv : ι = (𝟙 G)⁻¹ := by simp [Hom.inv_def] instance [BraidedCategory C] [IsCommMon G] : IsMon_Hom ι[G] where one_hom := by simp [one_eq_one, ← Hom.inv_def] mul_hom := by simp [Grp_Class.mul_inv_rev] attribute [local simp] Hom.inv_def in instance [BraidedCategory C] [IsCommMon G] {f : M ⟶ G} [IsMon_Hom f] : IsMon_Hom f⁻¹ where /-- If `G` is a commutative group object, then `Hom(X, G)` has a commutative group structure. -/ abbrev Hom.commGroup [BraidedCategory C] [IsCommMon G] : CommGroup (X ⟶ G) where scoped[Mon_Class] attribute [instance] Hom.commGroup
Defs.lean
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Yury Kudryashov -/ import Mathlib.Tactic.Continuity import Mathlib.Tactic.Lift import Mathlib.Topology.Defs.Basic /-! # Continuous bundled maps In this file we define the type `ContinuousMap` of continuous bundled maps. 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. -/ open Function open scoped Topology /-- The type of continuous maps from `X` to `Y`. When possible, instead of parametrizing results over `(f : C(X, Y))`, you should parametrize over `{F : Type*} [ContinuousMapClass F X Y] (f : F)`. When you extend this structure, make sure to extend `ContinuousMapClass`. -/ structure ContinuousMap (X Y : Type*) [TopologicalSpace X] [TopologicalSpace Y] where /-- The function `X → Y` -/ protected toFun : X → Y /-- Proposition that `toFun` is continuous -/ protected continuous_toFun : Continuous toFun := by continuity /-- `C(X, Y)` is the type of continuous maps from `X` to `Y`. -/ notation "C(" X ", " Y ")" => ContinuousMap X Y section /-- `ContinuousMapClass F X Y` states that `F` is a type of continuous maps. You should extend this class when you extend `ContinuousMap`. -/ class ContinuousMapClass (F : Type*) (X Y : outParam Type*) [TopologicalSpace X] [TopologicalSpace Y] [FunLike F X Y] : Prop where /-- Continuity -/ map_continuous (f : F) : Continuous f end export ContinuousMapClass (map_continuous) attribute [continuity, fun_prop] map_continuous section ContinuousMapClass variable {F X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [FunLike F X Y] variable [ContinuousMapClass F X Y] /-- Coerce a bundled morphism with a `ContinuousMapClass` instance to a `ContinuousMap`. -/ @[coe] def toContinuousMap (f : F) : C(X, Y) := ⟨f, map_continuous f⟩ instance : CoeTC F C(X, Y) := ⟨toContinuousMap⟩ end ContinuousMapClass /-! ### Continuous maps -/ namespace ContinuousMap variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] instance instFunLike : FunLike C(X, Y) X Y where coe := ContinuousMap.toFun coe_injective' f g h := by cases f; cases g; congr instance instContinuousMapClass : ContinuousMapClass C(X, Y) X Y where map_continuous := ContinuousMap.continuous_toFun @[simp] theorem toFun_eq_coe {f : C(X, Y)} : f.toFun = (f : X → Y) := rfl instance : CanLift (X → Y) C(X, Y) DFunLike.coe Continuous := ⟨fun f hf ↦ ⟨⟨f, hf⟩, rfl⟩⟩ /-- See note [custom simps projection]. -/ def Simps.apply (f : C(X, Y)) : X → Y := f -- this must come after the coe_to_fun definition initialize_simps_projections ContinuousMap (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F X Y] [ContinuousMapClass F X Y] (f : F) : ⇑(f : C(X, Y)) = f := rfl protected theorem coe_apply {F : Type*} [FunLike F X Y] [ContinuousMapClass F X Y] (f : F) (x : X) : (f : C(X, Y)) x = f x := rfl @[ext] theorem ext {f g : C(X, Y)} (h : ∀ a, f a = g a) : f = g := DFunLike.ext _ _ h /-- Copy of a `ContinuousMap` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : C(X, Y)) (f' : X → Y) (h : f' = f) : C(X, Y) where toFun := f' continuous_toFun := h.symm ▸ f.continuous_toFun @[simp] theorem coe_copy (f : C(X, Y)) (f' : X → Y) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : C(X, Y)) (f' : X → Y) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h /-- Deprecated. Use `map_continuous` instead. -/ protected theorem continuous (f : C(X, Y)) : Continuous f := f.continuous_toFun /-- Deprecated. Use `DFunLike.congr_fun` instead. -/ protected theorem congr_fun {f g : C(X, Y)} (H : f = g) (x : X) : f x = g x := H ▸ rfl /-- Deprecated. Use `DFunLike.congr_arg` instead. -/ protected theorem congr_arg (f : C(X, Y)) {x y : X} (h : x = y) : f x = f y := h ▸ rfl theorem coe_injective : Function.Injective (DFunLike.coe : C(X, Y) → (X → Y)) := DFunLike.coe_injective @[simp] theorem coe_mk (f : X → Y) (h : Continuous f) : ⇑(⟨f, h⟩ : C(X, Y)) = f := rfl instance [Subsingleton Y] : Subsingleton C(X, Y) := DFunLike.subsingleton_cod instance [IsEmpty X] : Subsingleton C(X, Y) := DFunLike.subsingleton_dom end ContinuousMap
ssralg.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div seq. From mathcomp Require Import choice fintype finfun bigop prime binomial. From mathcomp Require Export nmodule. (******************************************************************************) (* Ring-like structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* Reference: Francois Garillot, Georges Gonthier, Assia Mahboubi, Laurence *) (* Rideau, Packaging mathematical structures, TPHOLs 2009 *) (* *) (* This file defines the following algebraic structures: *) (* *) (* semiPzRingType == non-commutative semi rings *) (* (NModule with a multiplication) *) (* The HB class is called PzSemiRing. *) (* nzSemiRingType == non-commutative non-trivial semi rings *) (* (NModule with a multiplication) *) (* The HB class is called NzSemiRing. *) (* comPzSemiRingType == commutative semi rings *) (* The HB class is called ComPzSemiRing. *) (* comNzSemiRingType == commutative non-trivial semi rings *) (* The HB class is called ComNzSemiRing. *) (* pzRingType == non-commutative rings *) (* (semi rings with an opposite) *) (* The HB class is called PzRing. *) (* nzRingType == non-commutative non-trivial rings *) (* (semi rings with an opposite) *) (* The HB class is called NzRing. *) (* comPzRingType == commutative rings *) (* The HB class is called ComPzRing. *) (* comNzRingType == commutative non-trivial rings *) (* The HB class is called ComNzRing. *) (* lSemiModType R == semimodule with left multiplication by external scalars *) (* in the semiring R *) (* The HB class is called LSemiModule. *) (* lmodType R == module with left multiplication by external scalars *) (* in the pzRing R *) (* The HB class is called Lmodule. *) (* lSemiAlgType R == left semialgebra, semiring with scaling that associates *) (* on the left *) (* The HB class is called LSemiAlgebra. *) (* lalgType R == left algebra, ring with scaling that associates on the *) (* left *) (* The HB class is called Lalgebra. *) (* semiAlgType R == semialgebra, semiring with scaling that associates both *) (* left and right *) (* The HB class is called SemiAlgebra. *) (* algType R == algebra, ring with scaling that associates both left *) (* and right *) (* The HB class is called Algebra. *) (*comSemiAlgType R == commutative semiAlgType *) (* The HB class is called ComSemiAlgebra. *) (* comAlgType R == commutative algType *) (* The HB class is called ComAlgebra. *) (* unitRingType == Rings whose units have computable inverses *) (* The HB class is called UnitRing. *) (* comUnitRingType == commutative UnitRing *) (* The HB class is called ComUnitRing. *) (* unitAlgType R == algebra with computable inverses *) (* The HB class is called UnitAlgebra. *) (*comUnitAlgType R == commutative UnitAlgebra *) (* The HB class is called ComUnitAlgebra. *) (* idomainType == integral, commutative, ring with partial inverses *) (* The HB class is called IntegralDomain. *) (* fieldType == commutative fields *) (* The HB class is called Field. *) (* decFieldType == fields with a decidable first order theory *) (* The HB class is called DecidableField. *) (* closedFieldType == algebraically closed fields *) (* The HB class is called ClosedField. *) (* *) (* and their joins with subType: *) (* *) (* subPzSemiRingType R P == join of pzSemiRingType and *) (* subType (P : pred R) such that val is a *) (* semiring morphism *) (* The HB class is called SubPzSemiRing. *) (* subNzSemiRingType R P == join of nzSemiRingType and *) (* subType (P : pred R) such that val is a *) (* semiring morphism *) (* The HB class is called SubNzSemiRing. *) (*subComPzSemiRingType R P == join of comPzSemiRingType and *) (* subType (P : pred R) such that val is a morphism*) (* The HB class is called SubComPzSemiRing. *) (*subComNzSemiRingType R P == join of comNzSemiRingType and *) (* subType (P : pred R) such that val is a morphism*) (* The HB class is called SubComNzSemiRing. *) (* subPzRingType R P == join of pzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubPzRing. *) (* subComPzRingType R P == join of comPzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubComPzRing. *) (* subNzRingType R P == join of nzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubNzRing. *) (* subComNzRingType R P == join of comNzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubComNzRing. *) (* subLSemiModType R V P == join of lSemiModType and subType (P : pred V) *) (* such that val is scalable *) (* The HB class is called SubLSemiModule. *) (* subLmodType R V P == join of lmodType and subType (P : pred V) *) (* such that val is scalable *) (* The HB class is called SubLmodule. *) (* subLSemiAlgType R V P == join of lSemiAlgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubLSemiAlgebra. *) (* subLalgType R V P == join of lalgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubLalgebra. *) (* subSemiAlgType R V P == join of semiAlgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubSemiAlgebra. *) (* subAlgType R V P == join of algType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubAlgebra. *) (* subUnitRingType R P == join of unitRingType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubUnitRing. *) (* subComUnitRingType R P == join of comUnitRingType and subType (P : pred R)*) (* such that val is a ring morphism *) (* The HB class is called SubComUnitRing. *) (* subIdomainType R P == join of idomainType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubIntegralDomain. *) (* subField R P == join of fieldType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubField. *) (* *) (* Morphisms between the above structures (see below for details): *) (* *) (* {rmorphism R -> S} == semi ring (resp. ring) morphism between *) (* semiPzRingType (resp. pzRingType) instances *) (* R and S. *) (* The HB class is called RMorphism. *) (* {linear U -> V | s} == semilinear (resp. linear) functions of type *) (* U -> V, where U is a left semimodule (resp. *) (* left module) over semiring (resp. ring) R, V is *) (* an N-module (resp. Z-module), and s is a scaling*) (* operator (detailed below) of type R -> V -> V. *) (* The HB class is called Linear. *) (* {lrmorphism A -> B | s} == semialgebra (resp. algebra) morphisms of type *) (* A -> B, where A is a left semialgebra *) (* (resp. left algebra) over semiring (resp. ring) *) (* R, B is an semiring (resp. ring), and s is a *) (* scaling operator (detailed below) of type *) (* R -> B -> B. *) (* The HB class is called LRMorphism. *) (* *) (* -> The scaling operator s above should be one of *:%R, *%R, or a *) (* combination nu \; *:%R or nu \; *%R with a semiring morphism nu; *) (* otherwise some of the theory (e.g., the linearZ rule) will not apply. *) (* To enable the overloading of the scaling operator, we use the following *) (* structures: *) (* *) (* GRing.Scale.preLaw R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.PreLaw. *) (* GRing.Scale.semiLaw R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.SemiLaw. *) (* GRing.Scale.law R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.Law. *) (* *) (* Closedness predicates for the algebraic structures: *) (* *) (* addrClosed V == predicate closed under addition on V : nmodType *) (* The HB class is called AddClosed. *) (* opprClosed V == predicate closed under opposite on V : zmodType *) (* The HB class is called OppClosed. *) (* zmodClosed V == predicate closed under opposite and addition on V *) (* The HB class is called ZmodClosed. *) (* mulr2Closed R == predicate closed under multiplication on *) (* R : semiPzRingType *) (* The HB class is called Mul2Closed. *) (* mulrClosed R == predicate closed under multiplication and for 1 *) (* The HB class is called MulClosed. *) (* semiring2Closed R == predicate closed under addition and multiplication *) (* The HB class is called Semiring2Closed. *) (* semiringClosed R == predicate closed under semiring operations *) (* The HB class is called SemiringClosed. *) (* smulClosed R == predicate closed under multiplication and for -1 *) (* The HB class is called SmulClosed. *) (* subringClosed R == predicate closed under ring operations *) (* The HB class is called SubringClosed. *) (* divClosed R == predicate closed under division *) (* The HB class is called DivClosed. *) (* sdivClosed R == predicate closed under division and opposite *) (* The HB class is called SdivClosed. *) (* submodClosed R == predicate closed under lSemiModType operations *) (* The HB class is called SubmodClosed. *) (* subalgClosed R == predicate closed under lSemiAlgType operations *) (* The HB class is called SubalgClosed. *) (* divringClosed R == predicate closed under unitRing operations *) (* The HB class is called DivringClosed. *) (* divalgClosed R S == predicate closed under (S : unitAlg R) operations *) (* The HB class is called DivalgClosed. *) (* *) (* The rpred* lemmas ensure that the set S remains stable under the specified *) (* operations, provided the corresponding closedness predicate is satisfied. *) (* This stability is crucial for constructing and reasoning about *) (* substructures within algebraic hierarchies. For example: *) (* *) (* - rpred0: Concludes 0 \in S if S is addrClosed. *) (* - rpredD: Concludes x + y \in S if x \in S and y \in S and S is addrClosed.*) (* - rpredN: Concludes -x \in S if x \in S and S is opprClosed. *) (* - rpredZ: Concludes a *: v \in S if v \in S and S is scalerClosed. *) (* *) (* Canonical properties of the algebraic structures: *) (* * Nmodule (additive abelian monoids): *) (* 0 == the zero (additive identity) of a Nmodule *) (* x + y == the sum of x and y (in a Nmodule) *) (* x *+ n == n times x, with n in nat (non-negative), i.e., *) (* x + (x + .. (x + x)..) (n terms); x *+ 1 is thus *) (* convertible to x, and x *+ 2 to x + x *) (* \sum_<range> e == iterated sum for a Nmodule (cf bigop.v) *) (* e`_i == nth 0 e i, when e : seq M and M has a nmodType *) (* structure *) (* support f == 0.-support f, i.e., [pred x | f x != 0] *) (* addr_closed S <-> collective predicate S is closed under finite *) (* sums (0 and x + y in S, for x, y in S) *) (* [SubChoice_isSubNmodule of U by <:] == nmodType mixin for a subType whose *) (* base type is a nmodType and whose predicate's is *) (* an addrClosed *) (* *) (* * Zmodule (additive abelian groups): *) (* - x == the opposite (additive inverse) of x *) (* x - y == the difference of x and y; this is only notation *) (* for x + (- y) *) (* x *- n == notation for - (x *+ n), the opposite of x *+ n *) (* oppr_closed S <-> collective predicate S is closed under opposite *) (* zmod_closed S <-> collective predicate S is closed under zmodType *) (* operations (0 and x - y in S, for x, y in S) *) (* This property coerces to oppr_pred and addr_pred. *) (* [SubChoice_isSubZmodule of U by <:] == zmodType mixin for a subType whose *) (* base type is a zmodType and whose predicate's *) (* is a zmodClosed *) (* *) (* * PzSemiRing (non-commutative semirings): *) (* R^c == the converse (semi)ring for R: R^c is convertible*) (* to R but when R has a canonical (semi)ring *) (* structure R^c has the converse one: *) (* if x y : R^c, then x * y = (y : R) * (x : R) *) (* 1 == the multiplicative identity element of a semiring*) (* n%:R == the semiring image of an n in nat; this is just *) (* notation for 1 *+ n, so 1%:R is convertible to 1 *) (* and 2%:R to 1 + 1 *) (* <number> == <number>%:R with <number> a sequence of digits *) (* x * y == the semiring product of x and y *) (* \prod_<range> e == iterated product for a semiring (cf bigop.v) *) (* x ^+ n == x to the nth power with n in nat (non-negative), *) (* i.e., x * (x * .. (x * x)..) (n factors); x ^+ 1 *) (* is thus convertible to x, and x ^+ 2 to x * x *) (* GRing.comm x y <-> x and y commute, i.e., x * y = y * x *) (* GRing.lreg x <-> x if left-regular, i.e., *%R x is injective *) (* GRing.rreg x <-> x if right-regular, i.e., *%R^~ x is injective *) (* [pchar R] == the characteristic of R, defined as the set of *) (* prime numbers p such that p%:R = 0 in R *) (* The set [pchar R] has at most one element, and is*) (* implemented as a pred_nat collective predicate *) (* (see prime.v); thus the statement p \in [pchar R]*) (* can be read as `R has characteristic p', while *) (* [pchar R] =i pred0 means `R has characteristic 0'*) (* when R is a field. *) (* pFrobenius_aut chRp == the Frobenius automorphism mapping x in R to *) (* x ^+ p, where chRp : p \in [pchar R] is a proof *) (* that R has (non-zero) characteristic p *) (* mulr_closed S <-> collective predicate S is closed under finite *) (* products (1 and x * y in S for x, y in S) *) (* semiring_closed S <-> collective predicate S is closed under semiring *) (* operations (0, 1, x + y and x * y in S) *) (* [SubNmodule_isSubPzSemiRing of R by <:] == *) (* [SubChoice_isSubPzSemiRing of R by <:] == semiPzRingType mixin for a *) (* subType whose base type is a pzSemiRingType and *) (* whose predicate's is a semiringClosed *) (* *) (* * NzSemiRing (non-commutative non-trivial semirings): *) (* [SubNmodule_isSubNzSemiRing of R by <:] == *) (* [SubChoice_isSubNzSemiRing of R by <:] == semiNzRingType mixin for a *) (* subType whose base type is a nzSemiRingType and *) (* whose predicate's is a semiringClosed *) (* *) (* * PzRing (non-commutative rings): *) (* GRing.sign R b := (-1) ^+ b in R : pzRingType, with b : bool *) (* This is a parsing-only helper notation, to be *) (* used for defining more specific instances. *) (* smulr_closed S <-> collective predicate S is closed under products *) (* and opposite (-1 and x * y in S for x, y in S) *) (* subring_closed S <-> collective predicate S is closed under ring *) (* operations (1, x - y and x * y in S) *) (* [SubZmodule_isSubPzRing of R by <:] == *) (* [SubChoice_isSubPzRing of R by <:] == pzRingType mixin for a subType whose *) (* base *) (* type is a pzRingType and whose predicate's is a *) (* subringClosed *) (* *) (* * NzRing (non-commutative non-trivial rings): *) (* [SubZmodule_isSubNzRing of R by <:] == *) (* [SubChoice_isSubNzRing of R by <:] == nzRingType mixin for a subType whose *) (* base *) (* type is a nzRingType and whose predicate's is a *) (* subringClosed *) (* *) (* * ComPzSemiRing (commutative PzSemiRings): *) (* [SubNmodule_isSubComPzSemiRing of R by <:] == *) (* [SubChoice_isSubComPzSemiRing of R by <:] == comPzSemiRingType mixin for a *) (* subType whose base type is a comPzSemiRingType *) (* and whose predicate's is a semiringClosed *) (* *) (* * ComNzSemiRing (commutative NzSemiRings): *) (* [SubNmodule_isSubComNzSemiRing of R by <:] == *) (* [SubChoice_isSubComNzSemiRing of R by <:] == comNzSemiRingType mixin for a *) (* subType whose base type is a comNzSemiRingType *) (* and whose predicate's is a semiringClosed *) (* *) (* * ComPzRing (commutative PzRings): *) (* [SubZmodule_isSubComPzRing of R by <:] == *) (* [SubChoice_isSubComPzRing of R by <:] == comPzRingType mixin for a *) (* subType whose base type is a comPzRingType and *) (* whose predicate's is a subringClosed *) (* *) (* * ComNzRing (commutative NzRings): *) (* [SubZmodule_isSubComNzRing of R by <:] == *) (* [SubChoice_isSubComNzRing of R by <:] == comNzRingType mixin for a *) (* subType whose base type is a comNzRingType and *) (* whose predicate's is a subringClosed *) (* *) (* * UnitRing (NzRings whose units have computable inverses): *) (* x \is a GRing.unit <=> x is a unit (i.e., has an inverse) *) (* x^-1 == the ring inverse of x, if x is a unit, else x *) (* x / y == x divided by y (notation for x * y^-1) *) (* x ^- n := notation for (x ^+ n)^-1, the inverse of x ^+ n *) (* invr_closed S <-> collective predicate S is closed under inverse *) (* divr_closed S <-> collective predicate S is closed under division *) (* (1 and x / y in S) *) (* sdivr_closed S <-> collective predicate S is closed under division *) (* and opposite (-1 and x / y in S, for x, y in S) *) (* divring_closed S <-> collective predicate S is closed under unitRing *) (* operations (1, x - y and x / y in S) *) (* [SubNzRing_isSubUnitRing of R by <:] == *) (* [SubChoice_isSubUnitRing of R by <:] == unitRingType mixin for a subType *) (* whose base type is a unitRingType and whose *) (* predicate's is a divringClosed and whose ring *) (* structure is compatible with the base type's *) (* *) (* * ComUnitRing (commutative rings with computable inverses): *) (* [SubChoice_isSubComUnitRing of R by <:] == comUnitRingType mixin for a *) (* subType whose base type is a comUnitRingType and *) (* whose predicate's is a divringClosed and whose *) (* ring structure is compatible with the base *) (* type's *) (* *) (* * IntegralDomain (integral, commutative, ring with partial inverses): *) (* [SubComUnitRing_isSubIntegralDomain R by <:] == *) (* [SubChoice_isSubIntegralDomain R by <:] == mixin axiom for a idomain *) (* subType *) (* *) (* * Field (commutative fields): *) (* GRing.Field.axiom inv == field axiom: x != 0 -> inv x * x = 1 for all x *) (* This is equivalent to the property above, but *) (* does not require a unitRingType as inv is an *) (* explicit argument. *) (* [SubIntegralDomain_isSubField of R by <:] == mixin axiom for a field *) (* subType *) (* *) (* * DecidableField (fields with a decidable first order theory): *) (* GRing.term R == the type of formal expressions in a unit ring R *) (* with formal variables 'X_k, k : nat, and *) (* manifest constants x%:T, x : R *) (* The notation of all the ring operations is *) (* redefined for terms, in scope %T. *) (* GRing.formula R == the type of first order formulas over R; the %T *) (* scope binds the logical connectives /\, \/, ~, *) (* ==>, ==, and != to formulae; GRing.True/False *) (* and GRing.Bool b denote constant formulae, and *) (* quantifiers are written 'forall/'exists 'X_k, f *) (* GRing.Unit x tests for ring units *) (* GRing.If p_f t_f e_f emulates if-then-else *) (* GRing.Pick p_f t_f e_f emulates fintype.pick *) (* foldr GRing.Exists/Forall q_f xs can be used *) (* to write iterated quantifiers *) (* GRing.eval e t == the value of term t with valuation e : seq R *) (* (e maps 'X_i to e`_i) *) (* GRing.same_env e1 e2 <-> environments e1 and e2 are extensionally equal *) (* GRing.qf_form f == f is quantifier-free *) (* GRing.holds e f == the intuitionistic CiC interpretation of the *) (* formula f holds with valuation e *) (* GRing.qf_eval e f == the value (in bool) of a quantifier-free f *) (* GRing.sat e f == valuation e satisfies f (only in a decField) *) (* GRing.sol n f == a sequence e of size n such that e satisfies f, *) (* if one exists, or [::] if there is no such e *) (* 'exists 'X_i, u1 == 0 /\ ... /\ u_m == 0 /\ v1 != 0 ... /\ v_n != 0 *) (* *) (* * LSemiModule (semimodule with left multiplication by external scalars). *) (* a *: v == v scaled by a, when v is in an LSemiModule V and *) (* a is in the scalar semiring of V *) (* scaler_closed S <-> collective predicate S is closed under scaling *) (* subsemimod_closed S <-> collective predicate S is closed under *) (* lSemiModType operations (0, +%R, and *:%R) *) (* [SubNmodule_isSubLSemiModule of V by <:] == *) (* [SubChoice_isSubLSemiModule of V by <:] == mixin axiom for a subType of an *) (* lSemiModType *) (* *) (* * Lmodule (module with left multiplication by external scalars). *) (* linear_closed S <-> collective predicate S is closed under linear *) (* combinations (a *: u + v in S when u, v in S) *) (* submod_closed S <-> collective predicate S is closed under lmodType *) (* operations (0 and a *: u + v in S) *) (* [SubZmodule_isSubLmodule of V by <:] == *) (* [SubChoice_isSubLmodule of V by <:] == mixin axiom for a subType of an *) (* lmodType *) (* *) (* * LSemiAlgebra *) (* (left semialgebra, semiring with scaling that associates on the left): *) (* R^o == the regular (semi)algebra of R: R^o is *) (* convertible to R, but when R has a *) (* nz(Semi)RingType structure then R^o extends it *) (* to an l(Semi)AlgType structure by letting R act *) (* on itself: if x : R and y : R^o then *) (* x *: y = x * (y : R) *) (* k%:A == the image of the scalar k in a left semialgebra; *) (* this is simply notation for k *: 1 *) (* [SubSemiRing_SubLSemiModule_isSubLSemiAlgebra of V by <:] *) (* == mixin axiom for a subType of an lSemiAlgType *) (* *) (* * Lalgebra (left algebra, ring with scaling that associates on the left): *) (* subalg_closed S <-> collective predicate S is closed under lalgType *) (* operations (1, a *: u + v and u * v in S) *) (* [SubNzRing_SubLmodule_isSubLalgebra of V by <:] == *) (* [SubChoice_isSubLalgebra of V by <:] == mixin axiom for a subType of an *) (* lalgType *) (* *) (* * SemiAlgebra (semiring with scaling that associates both left and right):*) (* [SubLSemiAlgebra_isSubSemiAlgebra of V by <:] == *) (* == mixin axiom for a subType of an semiAlgType *) (* *) (* * Algebra (ring with scaling that associates both left and right): *) (* [SubLalgebra_isSubAlgebra of V by <:] == *) (* [SubChoice_isSubAlgebra of V by <:] == mixin axiom for a subType of an *) (* algType *) (* *) (* * UnitAlgebra (algebra with computable inverses): *) (* divalg_closed S <-> collective predicate S is closed under all *) (* unitAlgType operations (1, a *: u + v and u / v *) (* are in S fo u, v in S) *) (* *) (* In addition to this structure hierarchy, we also develop a separate, *) (* parallel hierarchy for morphisms linking these structures: *) (* *) (* * RMorphism (semiring or ring morphisms): *) (* monoid_morphism f <-> f of type R -> S is a multiplicative monoid *) (* morphism, i.e., f maps 1 and * in R to 1 and * *) (* in S, respectively. R and S must have canonical *) (* pzSemiRingType instances. *) (* {rmorphism R -> S} == the interface type for semiring morphisms; both *) (* R and S must have pzSemiRingType instances *) (* When both R and S have pzRingType instances, it *) (* is a ring morphism. *) (* := GRing.RMorphism.type R S *) (* *) (* -> If R and S are UnitRings the f also maps units to units and inverses *) (* of units to inverses; if R is a field then f is a field isomorphism *) (* between R and its image. *) (* -> Additive properties (raddf_suffix, see below) are duplicated and *) (* specialised for RMorphism (as rmorph_suffix). This allows more *) (* precise rewriting and cleaner chaining: although raddf lemmas will *) (* recognize RMorphism functions, the converse will not hold (we cannot *) (* add reverse inheritance rules because of incomplete backtracking in *) (* the Canonical Projection unification), so one would have to insert a *) (* /= every time one switched from additive to multiplicative rules. *) (* *) (* * Linear (semilinear or linear functions): *) (* scalable_for s f <-> f of type U -> V is scalable for the scaling *) (* operator s of type R -> V -> V, i.e., *) (* f morphs a *: _ to s a _; R, U, and V must be a *) (* pzSemiRingType, an lSemiModType R, and an *) (* nmodType, respectively. *) (* := forall a, {morph f : u / a *: u >-> s a u} *) (* scalable f <-> f of type U -> V is scalable, i.e., f morphs *) (* scaling on U to scaling on V, a *: _ to a *: _; *) (* U and V must be lSemiModType R for the same *) (* pzSemiRingType R. *) (* := scalable_for *:%R f *) (* semilinear_for s f <-> f of type U -> V is semilinear for s of type *) (* R -> V -> V , i.e., f morphs a *: _ and addition *) (* on U to s a _ and addition on V, respectively; *) (* R, U, and V must be a pzSemiRingType, an *) (* lSemiModType R and an nmodType, respectively. *) (* := scalable_for s f * {morph f : x y / x + y} *) (* semilinear f <-> f of type U -> V is semilinear, i.e., f morphs *) (* scaling and addition on U to scaling and *) (* addition on V, respectively; U and V must be *) (* lSemiModType R for the same pzSemiRingType R. *) (* := semilinear_for *:% f *) (* semiscalar f <-> f of type U -> R is a semiscalar function, *) (* i.e., f morphs scaling and addition on U to *) (* multiplication and addition on R; R and U must *) (* be a pzSemiRingType and an lSemiModType R, *) (* respectively. *) (* := semilinear_for *%R f *) (* linear_for s f <-> f of type U -> V is linear for s of type *) (* R -> V -> V, i.e., *) (* f (a *: u + v) = s a (f u) + f v; *) (* R, U, and V must be a pzRingType, an lmodType R, *) (* and a zmodType, respectively. *) (* linear f <-> f of type U -> V is linear, i.e., *) (* f (f *: u + v) = a *: f u + f v; *) (* U and V must be lmodType R for the same *) (* pzRingType R. *) (* := linear_for *:%R f *) (* scalar f <-> f of type U -> R is a scalar function, i.e., *) (* f (a *: u + v) = a * f u + f v; *) (* R and U must be a pzRingType and an lmodType R, *) (* respectively. *) (* := linear_for *%R f *) (* {linear U -> V | s} == the interface type for functions (semi)linear *) (* for the scaling operator s of type R -> V -> V, *) (* i.e., a structure that encapsulates two *) (* properties semi_additive f and scalable_for s f *) (* for functions f : U -> V; R, U, and V must be a *) (* pzSemiRingType, an lSemiModType R, and an *) (* nmodType, respectively. *) (* {linear U -> V} == the interface type for (semi)linear functions, *) (* of type U -> V where both U and V must be *) (* lSemiModType R for the same pzSemiRingType R *) (* := {linear U -> V | *:%R} *) (* {scalar U} == the interface type for (semi)scalar functions, *) (* of type U -> R where U must be an lSemiModType R *) (* := {linear U -> R | *%R} *) (* (a *: u)%Rlin == transient forms that simplify to a *: u, a * u, *) (* (a * u)%Rlin nu a *: u, and nu a * u, respectively, and are *) (* (a *:^nu u)%Rlin created by rewriting with the linearZ lemma *) (* (a *^nu u)%Rlin The forms allows the RHS of linearZ to be matched*) (* reliably, using the GRing.Scale.law structure. *) (* -> Similarly to semiring morphisms, semiadditive properties are *) (* specialized for semilinear functions. *) (* -> Although {scalar U} is convertible to {linear U -> R^o}, it does not *) (* actually use R^o, so that rewriting preserves the canonical structure *) (* of the range of scalar functions. *) (* -> The generic linearZ lemma uses a set of bespoke interface structures to *) (* ensure that both left-to-right and right-to-left rewriting work even in *) (* the presence of scaling functions that simplify non-trivially (e.g., *) (* idfun \; *%R). Because most of the canonical instances and projections *) (* are coercions the machinery will be mostly invisible (with only the *) (* {linear ...} structure and %Rlin notations showing), but users should *) (* beware that in (a *: f u)%Rlin, a actually occurs in the f u subterm. *) (* -> The simpler linear_LR, or more specialized linearZZ and scalarZ rules *) (* should be used instead of linearZ if there are complexity issues, as *) (* well as for explicit forward and backward application, as the main *) (* parameter of linearZ is a proper sub-interface of {linear U -> V | s}. *) (* *) (* * LRMorphism (semialgebra or algebra morphisms): *) (* {lrmorphism A -> B | s} == the interface type for semiring (resp. ring) *) (* morphisms semilinear (resp. linear) for the *) (* scaling operator s of type R -> B -> B, i.e., *) (* the join of semiring (resp. ring) morphisms *) (* {rmorphism A -> B} and semilinear (resp. linear) *) (* functions {linear A -> B | s}; R, A, and B must *) (* be a pzSemiRingType (resp. pzRingType), an *) (* lSemiAlgType R (resp. lalgType R), and a *) (* pzSemiRingType (resp. pzRingType), respectively *) (* {lrmorphism A -> B} == the interface type for semialgebra (resp. *) (* algebra) morphisms, where A and B must be *) (* lSemiAlgType R (resp. lalgType R) for the same *) (* pzSemiRingType (resp. pzRingType) R *) (* := {lrmorphism A -> B | *:%R} *) (* -> Linear and rmorphism properties do not need to be specialized for *) (* as we supply inheritance join instances in both directions. *) (* Finally we supply some helper notation for morphisms: *) (* x^f == the image of x under some morphism *) (* This notation is only reserved (not defined) *) (* here; it is bound locally in sections where some *) (* morphism is used heavily (e.g., the container *) (* morphism in the parametricity sections of poly *) (* and matrix, or the Frobenius section here) *) (* \0 == the constant null function, which has a *) (* canonical linear structure, and simplifies on *) (* application (see ssrfun.v) *) (* f \+ g == the additive composition of f and g, i.e., the *) (* function x |-> f x + g x; f \+ g is canonically *) (* linear when f and g are, and simplifies on *) (* application (see ssrfun.v) *) (* f \- g == the function x |-> f x - g x, canonically *) (* linear when f and g are, and simplifies on *) (* application *) (* \- g == the function x |-> - f x, canonically linear *) (* when f is, and simplifies on application *) (* k \*: f == the function x |-> k *: f x, which is *) (* canonically linear when f is and simplifies on *) (* application (this is a shorter alternative to *) (* *:%R k \o f) *) (* GRing.in_alg A == the ring morphism that injects R into A, where A *) (* has an lalgType R structure; GRing.in_alg A k *) (* simplifies to k%:A *) (* a \*o f == the function x |-> a * f x, canonically linear *) (* when f is and its codomain is an algType *) (* and which simplifies on application *) (* a \o* f == the function x |-> f x * a, canonically linear *) (* when f is and its codomain is an lalgType *) (* and which simplifies on application *) (* f \* g == the function x |-> f x * g x; f \* g *) (* simplifies on application *) (* The Lemmas about these structures are contained in both the GRing module *) (* and in the submodule GRing.Theory, which can be imported when unqualified *) (* access to the theory is needed (GRing.Theory also allows the unqualified *) (* use of additive, linear, Linear, etc). The main GRing module should NOT be *) (* imported. *) (* Notations are defined in scope ring_scope (delimiter %R), except term *) (* and formula notations, which are in term_scope (delimiter %T). *) (* This library also extends the conventional suffixes described in library *) (* ssrbool.v with the following: *) (* 0 -- ring 0, as in addr0 : x + 0 = x *) (* 1 -- ring 1, as in mulr1 : x * 1 = x *) (* D -- ring addition, as in linearD : f (u + v) = f u + f v *) (* B -- ring subtraction, as in opprB : - (x - y) = y - x *) (* M -- ring multiplication, as in invfM : (x * y)^-1 = x^-1 * y^-1 *) (* Mn -- ring by nat multiplication, as in raddfMn : f (x *+ n) = f x *+ n *) (* N -- ring opposite, as in mulNr : (- x) * y = - (x * y) *) (* V -- ring inverse, as in mulVr : x^-1 * x = 1 *) (* X -- ring exponentiation, as in rmorphXn : f (x ^+ n) = f x ^+ n *) (* Z -- (left) module scaling, as in linearZ : f (a *: v) = s *: f v *) (* The operator suffixes D, B, M and X are also used for the corresponding *) (* operations on nat, as in natrX : (m ^ n)%:R = m%:R ^+ n. For the binary *) (* power operator, a trailing "n" suffix is used to indicate the operator *) (* suffix applies to the left-hand ring argument, as in *) (* expr1n : 1 ^+ n = 1 vs. expr1 : x ^+ 1 = x. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope ring_scope. Declare Scope term_scope. Declare Scope linear_ring_scope. Reserved Notation "+%R". Reserved Notation "-%R". Reserved Notation "*%R" (format " *%R"). Reserved Notation "*:%R" (format " *:%R"). Reserved Notation "n %:R" (left associativity, format "n %:R"). Reserved Notation "k %:A" (left associativity, format "k %:A"). Reserved Notation "[ 'pchar' F ]" (format "[ 'pchar' F ]"). Reserved Notation "[ 'char' F ]" (format "[ 'char' F ]"). Reserved Notation "x %:T" (left associativity, format "x %:T"). Reserved Notation "''X_' i" (at level 8, i at level 2, format "''X_' i"). (* Patch for recurring Coq parser bug: Coq seg faults when a level 200 *) (* notation is used as a pattern. *) Reserved Notation "''exists' ''X_' i , f" (at level 199, i at level 2, right associativity, format "'[hv' ''exists' ''X_' i , '/ ' f ']'"). Reserved Notation "''forall' ''X_' i , f" (at level 199, i at level 2, right associativity, format "'[hv' ''forall' ''X_' i , '/ ' f ']'"). Reserved Notation "x ^f" (left associativity, format "x ^f"). Reserved Notation "\0". Reserved Notation "f \+ g" (at level 50, left associativity). Reserved Notation "f \- g" (at level 50, left associativity). Reserved Notation "\- f" (at level 35, f at level 35). Reserved Notation "a \*o f" (at level 40). Reserved Notation "a \o* f" (at level 40). Reserved Notation "a \*: f" (at level 40). Reserved Notation "f \* g" (at level 40, left associativity). Reserved Notation "'{' 'additive' U '->' V '}'" (U at level 98, V at level 99, format "{ 'additive' U -> V }"). Reserved Notation "'{' 'rmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'rmorphism' U -> V }"). Reserved Notation "'{' 'lrmorphism' U '->' V '|' s '}'" (U at level 98, V at level 99, format "{ 'lrmorphism' U -> V | s }"). Reserved Notation "'{' 'lrmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'lrmorphism' U -> V }"). Reserved Notation "'{' 'linear' U '->' V '|' s '}'" (U at level 98, V at level 99, format "{ 'linear' U -> V | s }"). Reserved Notation "'{' 'linear' U '->' V '}'" (U at level 98, V at level 99, format "{ 'linear' U -> V }"). Reserved Notation "'{' 'scalar' U '}'" (format "{ 'scalar' U }"). Reserved Notation "R ^c" (format "R ^c"). Reserved Notation "R ^o" (format "R ^o"). Declare Scope ring_scope. Delimit Scope ring_scope with R. Declare Scope term_scope. Delimit Scope term_scope with T. Local Open Scope ring_scope. Module Export Dummy. Module GRing := Algebra. End Dummy. Module Import GRing. Export Algebra. Import Monoid.Theory. Local Notation "0" := (@zero _) : ring_scope. Local Notation "+%R" := (@add _) : function_scope. Local Notation "x + y" := (add x y) : ring_scope. Local Notation "x *+ n" := (natmul x n) : ring_scope. Local Notation "\sum_ ( i <- r | P ) F" := (\big[+%R/0]_(i <- r | P) F). Local Notation "\sum_ ( m <= i < n ) F" := (\big[+%R/0]_(m <= i < n) F). Local Notation "\sum_ ( i < n ) F" := (\big[+%R/0]_(i < n) F). Local Notation "\sum_ ( i 'in' A ) F" := (\big[+%R/0]_(i in A) F). Local Notation "s `_ i" := (nth 0 s i) : ring_scope. Section NmoduleTheory. Variable V : nmodType. Implicit Types x y : V. Lemma addrA : associative (@add V). Proof. exact: addrA. Qed. Lemma addrC : commutative (@add V). Proof. exact: addrC. Qed. Lemma add0r : left_id (@zero V) add. Proof. exact: add0r. Qed. Lemma addr0 : right_id (@zero V) add. Proof. exact: addr0. Qed. Lemma addrCA : @left_commutative V V +%R. Proof. exact: addrCA. Qed. Lemma addrAC : @right_commutative V V +%R. Proof. exact: addrAC. Qed. Lemma addrACA : @interchange V +%R +%R. Proof. exact: addrACA. Qed. Lemma mulr0n x : x *+ 0 = 0. Proof. exact: mulr0n. Qed. Lemma mulr1n x : x *+ 1 = x. Proof. exact: mulr1n. Qed. Lemma mulr2n x : x *+ 2 = x + x. Proof. exact: mulr2n. Qed. Lemma mulrS x n : x *+ n.+1 = x + (x *+ n). Proof. exact: mulrS. Qed. Lemma mulrSr x n : x *+ n.+1 = x *+ n + x. Proof. exact: mulrSr. Qed. Lemma mulrb x (b : bool) : x *+ b = (if b then x else 0). Proof. exact: mulrb. Qed. Lemma mul0rn n : 0 *+ n = 0 :> V. Proof. exact: mul0rn. Qed. Lemma mulrnDl n : {morph (fun x => x *+ n) : x y / x + y}. Proof. exact: mulrnDl. Qed. Lemma mulrnDr x m n : x *+ (m + n) = x *+ m + x *+ n. Proof. exact: mulrnDr. Qed. Lemma mulrnA x m n : x *+ (m * n) = x *+ m *+ n. Proof. exact: mulrnA. Qed. Lemma mulrnAC x m n : x *+ m *+ n = x *+ n *+ m. Proof. exact: mulrnAC. Qed. Lemma iter_addr n x y : iter n (+%R x) y = x *+ n + y. Proof. exact: iter_addr. Qed. Lemma iter_addr_0 n x : iter n (+%R x) 0 = x *+ n. Proof. exact: iter_addr_0. Qed. Lemma sumrMnl I r P (F : I -> V) n : \sum_(i <- r | P i) F i *+ n = (\sum_(i <- r | P i) F i) *+ n. Proof. exact: sumrMnl. Qed. Lemma sumrMnr x I r P (F : I -> nat) : \sum_(i <- r | P i) x *+ F i = x *+ (\sum_(i <- r | P i) F i). Proof. exact: sumrMnr. Qed. Lemma sumr_const (I : finType) (A : pred I) x : \sum_(i in A) x = x *+ #|A|. Proof. exact: sumr_const. Qed. Lemma sumr_const_nat m n x : \sum_(n <= i < m) x = x *+ (m - n). Proof. exact: sumr_const_nat. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use Algebra.nmod_closed instead.")] Definition addr_closed := nmod_closed. End NmoduleTheory. Local Notation "-%R" := (@opp _) : ring_scope. Local Notation "- x" := (opp x) : ring_scope. Local Notation "x - y" := (x + - y) : ring_scope. Local Notation "x *- n" := (- (x *+ n)) : ring_scope. Section ZmoduleTheory. Variable V : zmodType. Implicit Types x y : V. Lemma addNr : @left_inverse V V V 0 -%R +%R. Proof. exact: addNr. Qed. Lemma addrN : @right_inverse V V V 0 -%R +%R. Proof. exact: addrN. Qed. Definition subrr := addrN. Lemma addKr : @left_loop V V -%R +%R. Proof. exact: addKr. Qed. Lemma addNKr : @rev_left_loop V V -%R +%R. Proof. exact: addNKr. Qed. Lemma addrK : @right_loop V V -%R +%R. Proof. exact: addrK. Qed. Lemma addrNK : @rev_right_loop V V -%R +%R. Proof. exact: addrNK. Qed. Definition subrK := addrNK. Lemma subrKC x y : x + (y - x) = y. Proof. by rewrite addrC subrK. Qed. Lemma subKr x : involutive (fun y => x - y). Proof. exact: subKr. Qed. Lemma addrI : @right_injective V V V +%R. Proof. exact: addrI. Qed. Lemma addIr : @left_injective V V V +%R. Proof. exact: addIr. Qed. Lemma subrI : right_injective (fun x y => x - y). Proof. exact: subrI. Qed. Lemma subIr : left_injective (fun x y => x - y). Proof. exact: subIr. Qed. Lemma opprK : @involutive V -%R. Proof. exact: opprK. Qed. Lemma oppr_inj : @injective V V -%R. Proof. exact: oppr_inj. Qed. Lemma oppr0 : -0 = 0 :> V. Proof. exact: oppr0. Qed. Lemma oppr_eq0 x : (- x == 0) = (x == 0). Proof. exact: oppr_eq0. Qed. Lemma subr0 x : x - 0 = x. Proof. exact: subr0. Qed. Lemma sub0r x : 0 - x = - x. Proof. exact: sub0r. Qed. Lemma opprB x y : - (x - y) = y - x. Proof. exact: opprB. Qed. Lemma opprD : {morph -%R: x y / x + y : V}. Proof. exact: opprD. Qed. Lemma addrKA z x y : (x + z) - (z + y) = x - y. Proof. exact: addrKA. Qed. Lemma subrKA z x y : (x - z) + (z + y) = x + y. Proof. exact: subrKA. Qed. Lemma addr0_eq x y : x + y = 0 -> - x = y. Proof. exact: addr0_eq. Qed. Lemma subr0_eq x y : x - y = 0 -> x = y. Proof. exact: subr0_eq. Qed. Lemma subr_eq x y z : (x - z == y) = (x == y + z). Proof. exact: subr_eq. Qed. Lemma subr_eq0 x y : (x - y == 0) = (x == y). Proof. exact: subr_eq0. Qed. Lemma addr_eq0 x y : (x + y == 0) = (x == - y). Proof. exact: addr_eq0. Qed. Lemma eqr_opp x y : (- x == - y) = (x == y). Proof. exact: eqr_opp. Qed. Lemma eqr_oppLR x y : (- x == y) = (x == - y). Proof. exact: eqr_oppLR. Qed. Lemma mulNrn x n : (- x) *+ n = x *- n. Proof. exact: mulNrn. Qed. Lemma mulrnBl n : {morph (fun x => x *+ n) : x y / x - y}. Proof. exact: mulrnBl. Qed. Lemma mulrnBr x m n : n <= m -> x *+ (m - n) = x *+ m - x *+ n. Proof. exact: mulrnBr. Qed. Lemma sumrN I r P (F : I -> V) : (\sum_(i <- r | P i) - F i = - (\sum_(i <- r | P i) F i)). Proof. exact: sumrN. Qed. Lemma sumrB I r (P : pred I) (F1 F2 : I -> V) : \sum_(i <- r | P i) (F1 i - F2 i) = \sum_(i <- r | P i) F1 i - \sum_(i <- r | P i) F2 i. Proof. exact: sumrB. Qed. Lemma telescope_sumr n m (f : nat -> V) : n <= m -> \sum_(n <= k < m) (f k.+1 - f k) = f m - f n. Proof. exact: telescope_sumr. Qed. Lemma telescope_sumr_eq n m (f u : nat -> V) : n <= m -> (forall k, (n <= k < m)%N -> u k = f k.+1 - f k) -> \sum_(n <= k < m) u k = f m - f n. Proof. exact: telescope_sumr_eq. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition oppr_closed := oppr_closed S. Definition subr_2closed := subr_closed S. Definition zmod_closed := zmod_closed S. Lemma zmod_closedN : zmod_closed -> oppr_closed. Proof. exact: zmod_closedN. Qed. Lemma zmod_closedD : zmod_closed -> nmod_closed S. Proof. by move=> z; split; [case: z|apply/zmod_closedD]. Qed. End ClosedPredicates. End ZmoduleTheory. Arguments addrI {V} y [x1 x2]. Arguments addIr {V} x [x1 x2]. Arguments opprK {V}. Arguments oppr_inj {V} [x1 x2]. Arguments telescope_sumr_eq {V n m} f u. HB.mixin Record Nmodule_isPzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; }. #[short(type="pzSemiRingType")] HB.structure Definition PzSemiRing := { R of Nmodule_isPzSemiRing R & Nmodule R }. HB.factory Record isPzSemiRing R of Choice R := { zero : R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; }. HB.builders Context R of isPzSemiRing R. HB.instance Definition _ := @isNmodule.Build R zero add addrA addrC add0r. HB.instance Definition _ := @Nmodule_isPzSemiRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.end. Module PzSemiRingExports. Bind Scope ring_scope with PzSemiRing.sort. End PzSemiRingExports. HB.export PzSemiRingExports. HB.mixin Record PzSemiRing_isNonZero R of PzSemiRing R := { oner_neq0 : @one R != 0 }. #[short(type="nzSemiRingType")] HB.structure Definition NzSemiRing := { R of PzSemiRing_isNonZero R & PzSemiRing R }. #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing instead.")] Notation SemiRing R := (NzSemiRing R) (only parsing). Module SemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.sort instead.")] Notation sort := (NzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.on instead.")] Notation on R := (NzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.copy instead.")] Notation copy T U := (NzSemiRing.copy T U) (only parsing). End SemiRing. HB.factory Record Nmodule_isNzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; oner_neq0 : one != 0 }. HB.builders Context R of Nmodule_isNzSemiRing R. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0. HB.end. Module Nmodule_isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isNzSemiRing.Build instead.")] Notation Build R := (Nmodule_isNzSemiRing.Build R) (only parsing). End Nmodule_isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isNzSemiRing instead.")] Notation Nmodule_isSemiRing R := (Nmodule_isNzSemiRing R) (only parsing). HB.factory Record isNzSemiRing R of Choice R := { zero : R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; oner_neq0 : one != zero }. Module isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzSemiRing.Build instead.")] Notation Build R := (isNzSemiRing.Build R) (only parsing). End isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzSemiRing instead.")] Notation isSemiRing R := (isNzSemiRing R) (only parsing). HB.builders Context R of isNzSemiRing R. HB.instance Definition _ := @isNmodule.Build R zero add addrA addrC add0r. HB.instance Definition _ := @Nmodule_isNzSemiRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0. HB.end. Module NzSemiRingExports. Bind Scope ring_scope with NzSemiRing.sort. End NzSemiRingExports. HB.export NzSemiRingExports. Definition exp R x n := iterop n (@mul R) x (@one R). Arguments exp : simpl never. Definition comm R x y := @mul R x y = mul y x. Definition lreg R x := injective (@mul R x). Definition rreg R x := injective ((@mul R)^~ x). Local Notation "1" := (@one _) : ring_scope. Local Notation "n %:R" := (1 *+ n) : ring_scope. Local Notation "*%R" := (@mul _) : function_scope. Local Notation "x * y" := (mul x y) : ring_scope. Local Notation "x ^+ n" := (exp x n) : ring_scope. Local Notation "\prod_ ( i <- r | P ) F" := (\big[*%R/1]_(i <- r | P) F). Local Notation "\prod_ ( i | P ) F" := (\big[*%R/1]_(i | P) F). Local Notation "\prod_ ( i 'in' A ) F" := (\big[*%R/1]_(i in A) F). Local Notation "\prod_ ( m <= i < n ) F" := (\big[*%R/1%R]_(m <= i < n) F%R). (* The ``field'' characteristic; the definition, and many of the theorems, *) (* has to apply to rings as well; indeed, we need the Frobenius automorphism *) (* results for a non commutative ring in the proof of Gorenstein 2.6.3. *) Definition pchar (R : nzSemiRingType) : nat_pred := [pred p | prime p & p%:R == 0 :> R]. #[deprecated(since="mathcomp 2.4.0", note="Use pchar instead.")] Notation char := pchar (only parsing). Local Notation has_pchar0 L := (pchar L =i pred0). #[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")] Notation has_char0 L := (has_pchar0 L) (only parsing). (* Converse ring tag. *) Definition converse R : Type := R. Local Notation "R ^c" := (converse R) : type_scope. Section PzSemiRingTheory. Variable R : pzSemiRingType. Implicit Types x y : R. #[export] HB.instance Definition _ := Monoid.isLaw.Build R 1 *%R mulrA mul1r mulr1. #[export] HB.instance Definition _ := Monoid.isMulLaw.Build R 0 *%R mul0r mulr0. #[export] HB.instance Definition _ := Monoid.isAddLaw.Build R *%R +%R mulrDl mulrDr. Lemma mulr_suml I r P (F : I -> R) x : (\sum_(i <- r | P i) F i) * x = \sum_(i <- r | P i) F i * x. Proof. exact: big_distrl. Qed. Lemma mulr_sumr I r P (F : I -> R) x : x * (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) x * F i. Proof. exact: big_distrr. Qed. Lemma mulrnAl x y n : (x *+ n) * y = (x * y) *+ n. Proof. by elim: n => [|n IHn]; rewrite ?mul0r // !mulrS mulrDl IHn. Qed. Lemma mulrnAr x y n : x * (y *+ n) = (x * y) *+ n. Proof. by elim: n => [|n IHn]; rewrite ?mulr0 // !mulrS mulrDr IHn. Qed. Lemma mulr_natl x n : n%:R * x = x *+ n. Proof. by rewrite mulrnAl mul1r. Qed. Lemma mulr_natr x n : x * n%:R = x *+ n. Proof. by rewrite mulrnAr mulr1. Qed. Lemma natrD m n : (m + n)%:R = m%:R + n%:R :> R. Proof. exact: mulrnDr. Qed. Lemma natr1 n : n%:R + 1 = n.+1%:R :> R. Proof. by rewrite mulrSr. Qed. Lemma nat1r n : 1 + n%:R = n.+1%:R :> R. Proof. by rewrite mulrS. Qed. Definition natr_sum := big_morph (natmul 1) natrD (mulr0n 1). Lemma natrM m n : (m * n)%:R = m%:R * n%:R :> R. Proof. by rewrite mulrnA mulr_natr. Qed. Lemma expr0 x : x ^+ 0 = 1. Proof. by []. Qed. Lemma expr1 x : x ^+ 1 = x. Proof. by []. Qed. Lemma expr2 x : x ^+ 2 = x * x. Proof. by []. Qed. Lemma exprS x n : x ^+ n.+1 = x * x ^+ n. Proof. by case: n => //; rewrite mulr1. Qed. Lemma expr0n n : 0 ^+ n = (n == 0%N)%:R :> R. Proof. by case: n => // n; rewrite exprS mul0r. Qed. Lemma expr1n n : 1 ^+ n = 1 :> R. Proof. by elim: n => // n IHn; rewrite exprS mul1r. Qed. Lemma exprD x m n : x ^+ (m + n) = x ^+ m * x ^+ n. Proof. by elim: m => [|m IHm]; rewrite ?mul1r // !exprS -mulrA -IHm. Qed. Lemma exprSr x n : x ^+ n.+1 = x ^+ n * x. Proof. by rewrite -addn1 exprD expr1. Qed. Lemma expr_sum x (I : Type) (s : seq I) (P : pred I) F : x ^+ (\sum_(i <- s | P i) F i) = \prod_(i <- s | P i) x ^+ F i :> R. Proof. exact: (big_morph _ (exprD _)). Qed. Lemma commr_sym x y : comm x y -> comm y x. Proof. by []. Qed. Lemma commr_refl x : comm x x. Proof. by []. Qed. Lemma commr0 x : comm x 0. Proof. by rewrite /comm mulr0 mul0r. Qed. Lemma commr1 x : comm x 1. Proof. by rewrite /comm mulr1 mul1r. Qed. Lemma commrD x y z : comm x y -> comm x z -> comm x (y + z). Proof. by rewrite /comm mulrDl mulrDr => -> ->. Qed. Lemma commr_sum (I : Type) (s : seq I) (P : pred I) (F : I -> R) x : (forall i, P i -> comm x (F i)) -> comm x (\sum_(i <- s | P i) F i). Proof. move=> comm_x_F; rewrite /comm mulr_suml mulr_sumr. by apply: eq_bigr => i /comm_x_F. Qed. Lemma commrMn x y n : comm x y -> comm x (y *+ n). Proof. rewrite /comm => com_xy. by elim: n => [|n IHn]; rewrite ?commr0 // mulrS commrD. Qed. Lemma commrM x y z : comm x y -> comm x z -> comm x (y * z). Proof. by move=> com_xy; rewrite /comm mulrA com_xy -!mulrA => ->. Qed. Lemma commr_prod (I : Type) (s : seq I) (P : pred I) (F : I -> R) x : (forall i, P i -> comm x (F i)) -> comm x (\prod_(i <- s | P i) F i). Proof. exact: (big_ind _ (commr1 x) (@commrM x)). Qed. Lemma commr_nat x n : comm x n%:R. Proof. exact/commrMn/commr1. Qed. Lemma commrX x y n : comm x y -> comm x (y ^+ n). Proof. rewrite /comm => com_xy. by elim: n => [|n IHn]; rewrite ?commr1 // exprS commrM. Qed. Lemma exprMn_comm x y n : comm x y -> (x * y) ^+ n = x ^+ n * y ^+ n. Proof. move=> com_xy; elim: n => /= [|n IHn]; first by rewrite mulr1. by rewrite !exprS IHn !mulrA; congr (_ * _); rewrite -!mulrA -commrX. Qed. Lemma exprMn_n x m n : (x *+ m) ^+ n = x ^+ n *+ (m ^ n) :> R. Proof. elim: n => [|n IHn]; first by rewrite mulr1n. by rewrite exprS IHn mulrnAl mulrnAr -mulrnA exprS -expnSr. Qed. Lemma exprM x m n : x ^+ (m * n) = x ^+ m ^+ n. Proof. elim: m => [|m IHm]; first by rewrite expr1n. by rewrite mulSn exprD IHm exprS exprMn_comm //; apply: commrX. Qed. Lemma exprAC x m n : (x ^+ m) ^+ n = (x ^+ n) ^+ m. Proof. by rewrite -!exprM mulnC. Qed. Lemma expr_mod n x i : x ^+ n = 1 -> x ^+ (i %% n) = x ^+ i. Proof. move=> xn1; rewrite {2}(divn_eq i n) exprD mulnC exprM xn1. by rewrite expr1n mul1r. Qed. Lemma expr_dvd n x i : x ^+ n = 1 -> n %| i -> x ^+ i = 1. Proof. by move=> xn1 dvd_n_i; rewrite -(expr_mod i xn1) (eqnP dvd_n_i). Qed. Lemma natrX n k : (n ^ k)%:R = n%:R ^+ k :> R. Proof. by rewrite exprMn_n expr1n. Qed. Lemma mulrI_eq0 x y : lreg x -> (x * y == 0) = (y == 0). Proof. by move=> reg_x; rewrite -{1}(mulr0 x) (inj_eq reg_x). Qed. Lemma lreg1 : lreg (1 : R). Proof. by move=> x y; rewrite !mul1r. Qed. Lemma lregM x y : lreg x -> lreg y -> lreg (x * y). Proof. by move=> reg_x reg_y z t; rewrite -!mulrA => /reg_x/reg_y. Qed. Lemma lregMl (a b: R) : lreg (a * b) -> lreg b. Proof. by move=> rab c c' eq_bc; apply/rab; rewrite -!mulrA eq_bc. Qed. Lemma rregMr (a b: R) : rreg (a * b) -> rreg a. Proof. by move=> rab c c' eq_ca; apply/rab; rewrite !mulrA eq_ca. Qed. Lemma lregX x n : lreg x -> lreg (x ^+ n). Proof. by move=> reg_x; elim: n => [|n]; [apply: lreg1 | rewrite exprS; apply: lregM]. Qed. Lemma iter_mulr n x y : iter n ( *%R x) y = x ^+ n * y. Proof. by elim: n => [|n ih]; rewrite ?expr0 ?mul1r //= ih exprS -mulrA. Qed. Lemma iter_mulr_1 n x : iter n ( *%R x) 1 = x ^+ n. Proof. by rewrite iter_mulr mulr1. Qed. Lemma prodr_const (I : finType) (A : pred I) x : \prod_(i in A) x = x ^+ #|A|. Proof. by rewrite big_const -iteropE. Qed. Lemma prodr_const_nat n m x : \prod_(n <= i < m) x = x ^+ (m - n). Proof. by rewrite big_const_nat -iteropE. Qed. Lemma prodrXr x I r P (F : I -> nat) : \prod_(i <- r | P i) x ^+ F i = x ^+ (\sum_(i <- r | P i) F i). Proof. by rewrite (big_morph _ (exprD _) (erefl _)). Qed. Lemma prodrM_comm {I : eqType} r (P : pred I) (F G : I -> R) : (forall i j, P i -> P j -> comm (F i) (G j)) -> \prod_(i <- r | P i) (F i * G i) = \prod_(i <- r | P i) F i * \prod_(i <- r | P i) G i. Proof. move=> FG; elim: r => [|i r IHr]; rewrite !(big_nil, big_cons) ?mulr1//. case: ifPn => // Pi; rewrite IHr !mulrA; congr (_ * _); rewrite -!mulrA. by rewrite commr_prod // => j Pj; apply/commr_sym/FG. Qed. Lemma prodrMl_comm {I : finType} (A : pred I) (x : R) F : (forall i, A i -> comm x (F i)) -> \prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i. Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j _ /xF. Qed. Lemma prodrMr_comm {I : finType} (A : pred I) (x : R) F : (forall i, A i -> comm x (F i)) -> \prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|. Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j /xF. Qed. Lemma prodrMn (I : Type) (s : seq I) (P : pred I) (F : I -> R) (g : I -> nat) : \prod_(i <- s | P i) (F i *+ g i) = \prod_(i <- s | P i) (F i) *+ \prod_(i <- s | P i) g i. Proof. by elim/big_rec3: _ => // i y1 y2 y3 _ ->; rewrite mulrnAr mulrnAl -mulrnA. Qed. Lemma prodrMn_const n (I : finType) (A : pred I) (F : I -> R) : \prod_(i in A) (F i *+ n) = \prod_(i in A) F i *+ n ^ #|A|. Proof. by rewrite prodrMn prod_nat_const. Qed. Lemma natr_prod I r P (F : I -> nat) : (\prod_(i <- r | P i) F i)%:R = \prod_(i <- r | P i) (F i)%:R :> R. Proof. exact: (big_morph _ natrM). Qed. Lemma exprDn_comm x y n (cxy : comm x y) : (x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. elim: n => [|n IHn]; rewrite big_ord_recl mulr1 ?big_ord0 ?addr0 //=. rewrite exprS {}IHn /= mulrDl !big_distrr /= big_ord_recl mulr1 subn0. rewrite !big_ord_recr /= !binn !subnn !mul1r !subn0 bin0 !exprS -addrA. congr (_ + _); rewrite addrA -big_split /=; congr (_ + _). apply: eq_bigr => i _; rewrite !mulrnAr !mulrA -exprS -subSn ?(valP i) //. by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS -mulrnDr. Qed. Lemma exprD1n x n : (x + 1) ^+ n = \sum_(i < n.+1) x ^+ i *+ 'C(n, i). Proof. rewrite addrC (exprDn_comm n (commr_sym (commr1 x))). by apply: eq_bigr => i _; rewrite expr1n mul1r. Qed. Lemma sqrrD1 x : (x + 1) ^+ 2 = x ^+ 2 + x *+ 2 + 1. Proof. rewrite exprD1n !big_ord_recr big_ord0 /= add0r. by rewrite addrC addrA addrAC. Qed. Section ClosedPredicates. Variable S : {pred R}. Definition mulr_2closed := {in S &, forall u v, u * v \in S}. Definition mulr_closed := 1 \in S /\ mulr_2closed. Definition semiring_closed := nmod_closed S /\ mulr_closed. Lemma semiring_closedD : semiring_closed -> nmod_closed S. Proof. by case. Qed. Lemma semiring_closedM : semiring_closed -> mulr_closed. Proof. by case. Qed. End ClosedPredicates. End PzSemiRingTheory. Section NzSemiRingTheory. Variable R : nzSemiRingType. Implicit Types x y : R. Lemma oner_eq0 : (1 == 0 :> R) = false. Proof. exact: negbTE oner_neq0. Qed. Lemma lastr_eq0 (s : seq R) x : x != 0 -> (last x s == 0) = (last 1 s == 0). Proof. by case: s => [|y s] /negPf // ->; rewrite oner_eq0. Qed. Lemma lreg_neq0 x : lreg x -> x != 0. Proof. by move=> reg_x; rewrite -[x]mulr1 mulrI_eq0 ?oner_eq0. Qed. Definition pFrobenius_aut p of p \in pchar R := fun x => x ^+ p. (* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible definition. *) Section FrobeniusAutomorphism. Variable p : nat. Hypothesis pcharFp : p \in pchar R. Lemma pcharf0 : p%:R = 0 :> R. Proof. by apply/eqP; case/andP: pcharFp. Qed. Lemma pcharf_prime : prime p. Proof. by case/andP: pcharFp. Qed. Hint Resolve pcharf_prime : core. Lemma mulrn_pchar x : x *+ p = 0. Proof. by rewrite -mulr_natl pcharf0 mul0r. Qed. Lemma natr_mod_pchar n : (n %% p)%:R = n%:R :> R. Proof. by rewrite {2}(divn_eq n p) natrD mulrnA mulrn_pchar add0r. Qed. Lemma dvdn_pcharf n : (p %| n)%N = (n%:R == 0 :> R). Proof. apply/idP/eqP=> [/dvdnP[n' ->]|n0]; first by rewrite natrM pcharf0 mulr0. apply/idPn; rewrite -prime_coprime // => /eqnP pn1. have [a _ /dvdnP[b]] := Bezoutl n (prime_gt0 pcharf_prime). move/(congr1 (fun m => m%:R : R))/eqP. by rewrite natrD !natrM pcharf0 n0 !mulr0 pn1 addr0 oner_eq0. Qed. Lemma pcharf_eq : pchar R =i (p : nat_pred). Proof. move=> q; apply/andP/eqP=> [[q_pr q0] | ->]; last by rewrite pcharf0. by apply/eqP; rewrite eq_sym -dvdn_prime2 // dvdn_pcharf. Qed. Lemma bin_lt_pcharf_0 k : 0 < k < p -> 'C(p, k)%:R = 0 :> R. Proof. by move=> lt0kp; apply/eqP; rewrite -dvdn_pcharf prime_dvd_bin. Qed. Local Notation "x ^f" := (pFrobenius_aut pcharFp x). Lemma pFrobenius_autE x : x^f = x ^+ p. Proof. by []. Qed. Local Notation f'E := pFrobenius_autE. Lemma pFrobenius_aut0 : 0^f = 0. Proof. by rewrite f'E -(prednK (prime_gt0 pcharf_prime)) exprS mul0r. Qed. Lemma pFrobenius_aut1 : 1^f = 1. Proof. by rewrite f'E expr1n. Qed. Lemma pFrobenius_autD_comm x y (cxy : comm x y) : (x + y)^f = x^f + y^f. Proof. have defp := prednK (prime_gt0 pcharf_prime). rewrite !f'E exprDn_comm // big_ord_recr subnn -defp big_ord_recl /= defp. rewrite subn0 mulr1 mul1r bin0 binn big1 ?addr0 // => i _. by rewrite -mulr_natl bin_lt_pcharf_0 ?mul0r //= -{2}defp ltnS (valP i). Qed. Lemma pFrobenius_autMn x n : (x *+ n)^f = x^f *+ n. Proof. elim: n => [|n IHn]; first exact: pFrobenius_aut0. by rewrite !mulrS pFrobenius_autD_comm ?IHn //; apply: commrMn. Qed. Lemma pFrobenius_aut_nat n : (n%:R)^f = n%:R. Proof. by rewrite pFrobenius_autMn pFrobenius_aut1. Qed. Lemma pFrobenius_autM_comm x y : comm x y -> (x * y)^f = x^f * y^f. Proof. exact: exprMn_comm. Qed. Lemma pFrobenius_autX x n : (x ^+ n)^f = x^f ^+ n. Proof. by rewrite !f'E -!exprM mulnC. Qed. End FrobeniusAutomorphism. Section Char2. Hypothesis pcharR2 : 2 \in pchar R. Lemma addrr_pchar2 x : x + x = 0. Proof. by rewrite -mulr2n mulrn_pchar. Qed. End Char2. End NzSemiRingTheory. #[short(type="pzRingType")] HB.structure Definition PzRing := { R of PzSemiRing R & Zmodule R }. HB.factory Record Zmodule_isPzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; }. HB.builders Context R of Zmodule_isPzRing R. Local Notation "1" := one. Local Notation "x * y" := (mul x y). Lemma mul0r : @left_zero R R 0 mul. Proof. by move=> x; apply: (addIr (1 * x)); rewrite -mulrDl !add0r mul1r. Qed. Lemma mulr0 : @right_zero R R 0 mul. Proof. by move=> x; apply: (addIr (x * 1)); rewrite -mulrDr !add0r mulr1. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.end. HB.factory Record isPzRing R of Choice R := { zero : R; opp : R -> R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; addNr : left_inverse zero opp add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; }. HB.builders Context R of isPzRing R. HB.instance Definition _ := @isZmodule.Build R zero opp add addrA addrC add0r addNr. HB.instance Definition _ := @Zmodule_isPzRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr. HB.end. Module PzRingExports. Bind Scope ring_scope with PzRing.sort. End PzRingExports. HB.export PzRingExports. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")] Notation Frobenius_aut := pFrobenius_aut (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")] Notation charf0 := pcharf0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")] Notation charf_prime := pcharf_prime (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")] Notation mulrn_char := mulrn_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use natr_mod_pchar instead.")] Notation natr_mod_char := natr_mod_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")] Notation dvdn_charf := dvdn_pcharf (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")] Notation charf_eq := pcharf_eq (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")] Notation bin_lt_charf_0 := bin_lt_pcharf_0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")] Notation Frobenius_autE := pFrobenius_autE (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")] Notation Frobenius_aut0 := pFrobenius_aut0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")] Notation Frobenius_aut1 := pFrobenius_aut1 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")] Notation Frobenius_autD_comm := pFrobenius_autD_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")] Notation Frobenius_autMn := pFrobenius_autMn (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")] Notation Frobenius_aut_nat := pFrobenius_aut_nat (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")] Notation Frobenius_autM_comm := pFrobenius_autM_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")] Notation Frobenius_autX := pFrobenius_autX (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")] Notation addrr_char2 := addrr_pchar2 (only parsing). #[short(type="nzRingType")] HB.structure Definition NzRing := { R of NzSemiRing R & Zmodule R }. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing instead.")] Notation Ring R := (NzRing R) (only parsing). Module Ring. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.sort instead.")] Notation sort := (NzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.on instead.")] Notation on R := (NzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.copy instead.")] Notation copy T U := (NzRing.copy T U) (only parsing). End Ring. HB.factory Record Zmodule_isNzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; oner_neq0 : one != 0 }. Module Zmodule_isRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isNzRing.Build instead.")] Notation Build R := (Zmodule_isNzRing.Build R) (only parsing). End Zmodule_isRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isNzRing instead.")] Notation Zmodule_isRing R := (Zmodule_isNzRing R) (only parsing). HB.builders Context R of Zmodule_isNzRing R. HB.instance Definition _ := Zmodule_isPzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr. HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0. HB.end. HB.factory Record isNzRing R of Choice R := { zero : R; opp : R -> R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; addNr : left_inverse zero opp add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; oner_neq0 : one != zero }. Module isRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzRing.Build instead.")] Notation Build R := (isNzRing.Build R) (only parsing). End isRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzRing instead.")] Notation isRing R := (isNzRing R) (only parsing). HB.builders Context R of isNzRing R. HB.instance Definition _ := @isZmodule.Build R zero opp add addrA addrC add0r addNr. HB.instance Definition _ := @Zmodule_isNzRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr oner_neq0. HB.end. Module NzRingExports. Bind Scope ring_scope with NzRing.sort. End NzRingExports. HB.export NzRingExports. Notation sign R b := (exp (- @one R) (nat_of_bool b)) (only parsing). Local Notation "- 1" := (- (1)) : ring_scope. Section PzRingTheory. Variable R : pzRingType. Implicit Types x y : R. Lemma mulrN x y : x * (- y) = - (x * y). Proof. by apply: (addrI (x * y)); rewrite -mulrDr !subrr mulr0. Qed. Lemma mulNr x y : (- x) * y = - (x * y). Proof. by apply: (addrI (x * y)); rewrite -mulrDl !subrr mul0r. Qed. Lemma mulrNN x y : (- x) * (- y) = x * y. Proof. by rewrite mulrN mulNr opprK. Qed. Lemma mulN1r x : -1 * x = - x. Proof. by rewrite mulNr mul1r. Qed. Lemma mulrN1 x : x * -1 = - x. Proof. by rewrite mulrN mulr1. Qed. Lemma mulrBl x y z : (y - z) * x = y * x - z * x. Proof. by rewrite mulrDl mulNr. Qed. Lemma mulrBr x y z : x * (y - z) = x * y - x * z. Proof. by rewrite mulrDr mulrN. Qed. Lemma natrB m n : n <= m -> (m - n)%:R = m%:R - n%:R :> R. Proof. exact: mulrnBr. Qed. Lemma commrN x y : comm x y -> comm x (- y). Proof. by move=> com_xy; rewrite /comm mulrN com_xy mulNr. Qed. Lemma commrN1 x : comm x (-1). Proof. exact/commrN/commr1. Qed. Lemma commrB x y z : comm x y -> comm x z -> comm x (y - z). Proof. by move=> com_xy com_xz; apply: commrD => //; apply: commrN. Qed. Lemma commr_sign x n : comm x ((-1) ^+ n). Proof. exact: (commrX n (commrN1 x)). Qed. Lemma signr_odd n : (-1) ^+ (odd n) = (-1) ^+ n :> R. Proof. elim: n => //= n IHn; rewrite exprS -{}IHn. by case/odd: n; rewrite !mulN1r ?opprK. Qed. Lemma mulr_sign (b : bool) x : (-1) ^+ b * x = (if b then - x else x). Proof. by case: b; rewrite ?mulNr mul1r. Qed. Lemma signr_addb b1 b2 : (-1) ^+ (b1 (+) b2) = (-1) ^+ b1 * (-1) ^+ b2 :> R. Proof. by rewrite mulr_sign; case: b1 b2 => [] []; rewrite ?opprK. Qed. Lemma signrE (b : bool) : (-1) ^+ b = 1 - b.*2%:R :> R. Proof. by case: b; rewrite ?subr0 // opprD addNKr. Qed. Lemma signrN b : (-1) ^+ (~~ b) = - (-1) ^+ b :> R. Proof. by case: b; rewrite ?opprK. Qed. Lemma mulr_signM (b1 b2 : bool) x1 x2 : ((-1) ^+ b1 * x1) * ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 * x2). Proof. by rewrite signr_addb -!mulrA; congr (_ * _); rewrite !mulrA commr_sign. Qed. Lemma exprNn x n : (- x) ^+ n = (-1) ^+ n * x ^+ n :> R. Proof. by rewrite -mulN1r exprMn_comm // /comm mulN1r mulrN mulr1. Qed. Lemma sqrrN x : (- x) ^+ 2 = x ^+ 2. Proof. exact: mulrNN. Qed. Lemma sqrr_sign n : ((-1) ^+ n) ^+ 2 = 1 :> R. Proof. by rewrite exprAC sqrrN !expr1n. Qed. Lemma signrMK n : @involutive R ( *%R ((-1) ^+ n)). Proof. by move=> x; rewrite mulrA -expr2 sqrr_sign mul1r. Qed. Lemma mulrI0_lreg x : (forall y, x * y = 0 -> y = 0) -> lreg x. Proof. move=> reg_x y z eq_xy_xz; apply/eqP; rewrite -subr_eq0 [y - z]reg_x //. by rewrite mulrBr eq_xy_xz subrr. Qed. Lemma lregN x : lreg x -> lreg (- x). Proof. by move=> reg_x y z; rewrite !mulNr => /oppr_inj/reg_x. Qed. Lemma lreg_sign n : lreg ((-1) ^+ n : R). Proof. exact/lregX/lregN/lreg1. Qed. Lemma prodrN (I : finType) (A : pred I) (F : I -> R) : \prod_(i in A) - F i = (- 1) ^+ #|A| * \prod_(i in A) F i. Proof. rewrite -sum1_card; elim/big_rec3: _ => [|i x n _ _ ->]; first by rewrite mulr1. by rewrite exprS !mulrA mulN1r !mulNr commrX //; apply: commrN1. Qed. Lemma exprBn_comm x y n (cxy : comm x y) : (x - y) ^+ n = \sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. rewrite exprDn_comm; last exact: commrN. by apply: eq_bigr => i _; congr (_ *+ _); rewrite -commr_sign -mulrA -exprNn. Qed. Lemma subrXX_comm x y n (cxy : comm x y) : x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i). Proof. case: n => [|n]; first by rewrite big_ord0 mulr0 subrr. rewrite mulrBl !big_distrr big_ord_recl big_ord_recr /= subnn mulr1 mul1r. rewrite subn0 -!exprS opprD -!addrA; congr (_ + _); rewrite addrA -sumrB. rewrite big1 ?add0r // => i _; rewrite !mulrA -exprS -subSn ?(valP i) //. by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS subrr. Qed. Lemma subrX1 x n : x ^+ n - 1 = (x - 1) * (\sum_(i < n) x ^+ i). Proof. rewrite -!(opprB 1) mulNr -{1}(expr1n _ n). rewrite (subrXX_comm _ (commr_sym (commr1 x))); congr (- (_ * _)). by apply: eq_bigr => i _; rewrite expr1n mul1r. Qed. Lemma sqrrB1 x : (x - 1) ^+ 2 = x ^+ 2 - x *+ 2 + 1. Proof. by rewrite -sqrrN opprB addrC sqrrD1 sqrrN mulNrn. Qed. Lemma subr_sqr_1 x : x ^+ 2 - 1 = (x - 1) * (x + 1). Proof. by rewrite subrX1 !big_ord_recr big_ord0 /= addrAC add0r. Qed. Section ClosedPredicates. Variable S : {pred R}. Definition smulr_closed := -1 \in S /\ mulr_2closed S. Definition subring_closed := [/\ 1 \in S, subr_2closed S & mulr_2closed S]. Lemma smulr_closedM : smulr_closed -> mulr_closed S. Proof. by case=> SN1 SM; split=> //; rewrite -[1]mulr1 -mulrNN SM. Qed. Lemma smulr_closedN : smulr_closed -> oppr_closed S. Proof. by case=> SN1 SM x Sx; rewrite -mulN1r SM. Qed. Lemma subring_closedB : subring_closed -> zmod_closed S. Proof. by case=> S1 SB _; split; rewrite // -(subrr 1) SB. Qed. Lemma subring_closedM : subring_closed -> smulr_closed. Proof. by case=> S1 SB SM; split; rewrite ?(zmod_closedN (subring_closedB _)). Qed. Lemma subring_closed_semi : subring_closed -> semiring_closed S. Proof. by move=> ringS; split; [apply/zmod_closedD/subring_closedB | case: ringS]. Qed. End ClosedPredicates. End PzRingTheory. Section NzRingTheory. Variable R : nzRingType. Implicit Types x y : R. Lemma signr_eq0 n : ((-1) ^+ n == 0 :> R) = false. Proof. by rewrite -signr_odd; case: odd; rewrite ?oppr_eq0 oner_eq0. Qed. (* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible definition. *) Section FrobeniusAutomorphism. Variable p : nat. Hypothesis pcharFp : p \in pchar R. Hint Resolve pcharf_prime : core. Local Notation "x ^f" := (pFrobenius_aut pcharFp x). Lemma pFrobenius_autN x : (- x)^f = - x^f. Proof. apply/eqP; rewrite -subr_eq0 opprK addrC. by rewrite -(pFrobenius_autD_comm _ (commrN _)) // subrr pFrobenius_aut0. Qed. Lemma pFrobenius_autB_comm x y : comm x y -> (x - y)^f = x^f - y^f. Proof. by move/commrN/pFrobenius_autD_comm->; rewrite pFrobenius_autN. Qed. End FrobeniusAutomorphism. Lemma exprNn_pchar x n : (pchar R).-nat n -> (- x) ^+ n = - (x ^+ n). Proof. pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]]. have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) // pi_pdiv. have /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)). elim: e => // e IHe; rewrite expnSr !exprM {}IHe. by rewrite -pFrobenius_autE pFrobenius_autN. Qed. Section Char2. Hypothesis pcharR2 : 2 \in pchar R. Lemma oppr_pchar2 x : - x = x. Proof. by apply/esym/eqP; rewrite -addr_eq0 addrr_pchar2. Qed. Lemma subr_pchar2 x y : x - y = x + y. Proof. by rewrite oppr_pchar2. Qed. Lemma addrK_pchar2 x : involutive (+%R^~ x). Proof. by move=> y; rewrite /= -subr_pchar2 addrK. Qed. Lemma addKr_pchar2 x : involutive (+%R x). Proof. by move=> y; rewrite -{1}[x]oppr_pchar2 addKr. Qed. End Char2. End NzRingTheory. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")] Notation Frobenius_autN := pFrobenius_autN (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")] Notation Frobenius_autB_comm := pFrobenius_autB_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")] Notation exprNn_char := exprNn_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")] Notation oppr_char2 := oppr_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use subr_pchar2 instead.")] Notation subr_char2 := subr_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")] Notation addrK_char2 := addrK_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")] Notation addKr_char2 := addKr_pchar2 (only parsing). Section ConverseRing. #[export] HB.instance Definition _ (T : eqType) := Equality.on T^c. #[export] HB.instance Definition _ (T : choiceType) := Choice.on T^c. #[export] HB.instance Definition _ (U : nmodType) := Nmodule.on U^c. #[export] HB.instance Definition _ (U : zmodType) := Zmodule.on U^c. #[export] HB.instance Definition _ (R : pzSemiRingType) := let mul' (x y : R) := y * x in let mulrA' x y z := esym (mulrA z y x) in let mulrDl' x y z := mulrDr z x y in let mulrDr' x y z := mulrDl y z x in Nmodule_isPzSemiRing.Build R^c mulrA' mulr1 mul1r mulrDl' mulrDr' mulr0 mul0r. #[export] HB.instance Definition _ (R : pzRingType) := PzSemiRing.on R^c. #[export] HB.instance Definition _ (R : nzSemiRingType) := PzSemiRing_isNonZero.Build R^c oner_neq0. #[export] HB.instance Definition _ (R : nzRingType) := NzSemiRing.on R^c. End ConverseRing. Lemma rev_prodr (R : pzSemiRingType) (I : Type) (r : seq I) (P : pred I) (E : I -> R) : \prod_(i <- r | P i) (E i : R^c) = \prod_(i <- rev r | P i) E i. Proof. by rewrite rev_big_rev. Qed. Section SemiRightRegular. Variable R : pzSemiRingType. Implicit Types x y : R. Lemma mulIr_eq0 x y : rreg x -> (y * x == 0) = (y == 0). Proof. exact: (@mulrI_eq0 R^c). Qed. Lemma rreg1 : rreg (1 : R). Proof. exact: (@lreg1 R^c). Qed. Lemma rregM x y : rreg x -> rreg y -> rreg (x * y). Proof. by move=> reg_x reg_y; apply: (@lregM R^c). Qed. Lemma revrX x n : (x : R^c) ^+ n = (x : R) ^+ n. Proof. by elim: n => // n IHn; rewrite exprS exprSr IHn. Qed. Lemma rregX x n : rreg x -> rreg (x ^+ n). Proof. by move/(@lregX R^c x n); rewrite revrX. Qed. End SemiRightRegular. Lemma rreg_neq0 (R : nzSemiRingType) (x : R) : rreg x -> x != 0. Proof. exact: (@lreg_neq0 R^c). Qed. Section RightRegular. Variable R : pzRingType. Implicit Types x y : R. Lemma mulIr0_rreg x : (forall y, y * x = 0 -> y = 0) -> rreg x. Proof. exact: (@mulrI0_lreg R^c). Qed. Lemma rregN x : rreg x -> rreg (- x). Proof. exact: (@lregN R^c). Qed. End RightRegular. HB.mixin Record Nmodule_isLSemiModule (R : pzSemiRingType) V of Nmodule V := { scale : R -> V -> V; scalerA : forall a b v, scale a (scale b v) = scale (a * b) v; scale0r : forall v, scale 0 v = 0; scale1r : left_id 1 scale; scalerDr : right_distributive scale +%R; scalerDl : forall v, {morph scale^~ v: a b / a + b} }. #[short(type="lSemiModType")] HB.structure Definition LSemiModule (R : pzSemiRingType) := {M of Nmodule M & Nmodule_isLSemiModule R M}. Module LSemiModExports. Bind Scope ring_scope with LSemiModule.sort. End LSemiModExports. HB.export LSemiModExports. Local Notation "*:%R" := (@scale _ _) : function_scope. Local Notation "a *: v" := (scale a v) : ring_scope. #[short(type="lmodType")] HB.structure Definition Lmodule (R : pzRingType) := {M of Zmodule M & Nmodule_isLSemiModule R M}. (* FIXME: see #1126 and #1127 *) Arguments scalerA [R s] (a b)%_ring_scope v. Module LmodExports. Bind Scope ring_scope with Lmodule.sort. End LmodExports. HB.export LmodExports. HB.factory Record Zmodule_isLmodule (R : pzRingType) V of Zmodule V := { scale : R -> V -> V; scalerA : forall a b v, scale a (scale b v) = scale (a * b) v; scale1r : left_id 1 scale; scalerDr : right_distributive scale +%R; scalerDl : forall v, {morph scale^~ v: a b / a + b} }. HB.builders Context R V of Zmodule_isLmodule R V. Lemma scale0r v : scale 0 v = 0. Proof. by apply: (addIr (scale 1 v)); rewrite -scalerDl !add0r. Qed. HB.instance Definition _ := Nmodule_isLSemiModule.Build R V scalerA scale0r scale1r scalerDr scalerDl. HB.end. HB.factory Record LSemiModule_isLmodule (R : pzRingType) V of LSemiModule R V := {}. HB.builders Context R V of LSemiModule_isLmodule R V. Definition opp : V -> V := scale (- 1). Lemma addNr : left_inverse 0 opp +%R. Proof. move=> v; suff : scale (-1 + 1) v = 0 by rewrite scalerDl scale1r. by rewrite addNr scale0r. Qed. HB.instance Definition _ := Nmodule_isZmodule.Build V addNr. HB.end. Section LSemiModuleTheory. Variables (R : pzSemiRingType) (V : lSemiModType R). Implicit Types (a b c : R) (u v : V). Lemma scaler0 a : a *: 0 = 0 :> V. Proof. by rewrite -[0 in LHS](scale0r 0) scalerA mulr0 scale0r. Qed. Lemma scaler_nat n v : n%:R *: v = v *+ n. Proof. elim: n => /= [|n]; first by rewrite scale0r. by rewrite !mulrS scalerDl ?scale1r => ->. Qed. Lemma scalerMnl a v n : a *: v *+ n = (a *+ n) *: v. Proof. elim: n => [|n IHn]; first by rewrite !mulr0n scale0r. by rewrite !mulrSr IHn scalerDl. Qed. Lemma scalerMnr a v n : a *: v *+ n = a *: (v *+ n). Proof. elim: n => [|n IHn]; first by rewrite !mulr0n scaler0. by rewrite !mulrSr IHn scalerDr. Qed. Lemma scaler_suml v I r (P : pred I) F : (\sum_(i <- r | P i) F i) *: v = \sum_(i <- r | P i) F i *: v. Proof. exact: (big_morph _ (scalerDl v) (scale0r v)). Qed. Lemma scaler_sumr a I r (P : pred I) (F : I -> V) : a *: (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) a *: F i. Proof. exact: big_endo (scalerDr a) (scaler0 a) I r P F. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition scaler_closed := forall a, {in S, forall v, a *: v \in S}. Definition subsemimod_closed := nmod_closed S /\ scaler_closed. Lemma subsemimod_closedD : subsemimod_closed -> nmod_closed S. Proof. by case. Qed. Lemma subsemimod_closedZ : subsemimod_closed -> scaler_closed. Proof. by case. Qed. End ClosedPredicates. End LSemiModuleTheory. Section LmoduleTheory. Variables (R : pzRingType) (V : lmodType R). Implicit Types (a b c : R) (u v : V). Lemma scaleNr a v : - a *: v = - (a *: v). Proof. by apply: (addIr (a *: v)); rewrite -scalerDl !addNr scale0r. Qed. Lemma scaleN1r v : - 1 *: v = - v. Proof. by rewrite scaleNr scale1r. Qed. Lemma scalerN a v : a *: - v = - (a *: v). Proof. by apply: (addIr (a *: v)); rewrite -scalerDr !addNr scaler0. Qed. Lemma scalerBl a b v : (a - b) *: v = a *: v - b *: v. Proof. by rewrite scalerDl scaleNr. Qed. Lemma scalerBr a u v : a *: (u - v) = a *: u - a *: v. Proof. by rewrite scalerDr scalerN. Qed. Lemma scaler_sign (b : bool) v : (-1) ^+ b *: v = (if b then - v else v). Proof. by case: b; rewrite ?scaleNr scale1r. Qed. Lemma signrZK n : @involutive V ( *:%R ((-1) ^+ n)). Proof. by move=> u; rewrite scalerA -expr2 sqrr_sign scale1r. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition linear_closed := forall a, {in S &, forall u v, a *: u + v \in S}. Definition submod_closed := 0 \in S /\ linear_closed. Lemma linear_closedB : linear_closed -> subr_2closed S. Proof. by move=> Slin u v Su Sv; rewrite addrC -scaleN1r Slin. Qed. Lemma submod_closedB : submod_closed -> zmod_closed S. Proof. by case=> S0 /linear_closedB. Qed. Lemma submod_closed_semi : submod_closed -> subsemimod_closed S. Proof. move=> /[dup] /submod_closedB /zmod_closedD SD [S0 Slin]; split => // a v Sv. by rewrite -[a *: v]addr0 Slin. Qed. End ClosedPredicates. End LmoduleTheory. (* TOTHINK: Can I change `NzSemiRing` to `PzSemiRing`? *) HB.mixin Record LSemiModule_isLSemiAlgebra R V of NzSemiRing V & LSemiModule R V := { scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v }. #[short(type="lSemiAlgType")] HB.structure Definition LSemiAlgebra R := {A of LSemiModule R A & NzSemiRing A & LSemiModule_isLSemiAlgebra R A}. Module LSemiAlgExports. Bind Scope ring_scope with LSemiAlgebra.sort. End LSemiAlgExports. HB.export LSemiAlgExports. (* Scalar injection (see the definition of in_alg A below). *) Local Notation "k %:A" := (k *: 1) : ring_scope. #[short(type="lalgType")] HB.structure Definition Lalgebra R := {A of Lmodule R A & NzRing A & LSemiModule_isLSemiAlgebra R A}. Module LalgExports. Bind Scope ring_scope with Lalgebra.sort. End LalgExports. HB.export LalgExports. HB.factory Record Lmodule_isLalgebra R V of NzRing V & Lmodule R V := { scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v }. HB.builders Context R V of Lmodule_isLalgebra R V. HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R V scalerAl. HB.end. (* Regular ring algebra tag. *) Definition regular R : Type := R. Local Notation "R ^o" := (regular R) : type_scope. Section RegularAlgebra. #[export] HB.instance Definition _ (V : nmodType) := Nmodule.on V^o. #[export] HB.instance Definition _ (V : zmodType) := Zmodule.on V^o. #[export] HB.instance Definition _ (R : pzSemiRingType) := PzSemiRing.on R^o. #[export] HB.instance Definition _ (R : nzSemiRingType) := NzSemiRing.on R^o. #[export] HB.instance Definition _ (R : pzSemiRingType) := @Nmodule_isLSemiModule.Build R R^o mul mulrA mul0r mul1r mulrDr (fun v a b => mulrDl a b v). #[export] HB.instance Definition _ (R : nzSemiRingType) := LSemiModule_isLSemiAlgebra.Build R R^o mulrA. #[export] HB.instance Definition _ (R : pzRingType) := PzRing.on R^o. #[export] HB.instance Definition _ (R : nzRingType) := NzRing.on R^o. End RegularAlgebra. Section LSemiAlgebraTheory. Variables (R : pzSemiRingType) (A : lSemiAlgType R). Lemma mulr_algl (a : R) (x : A) : (a *: 1) * x = a *: x. Proof. by rewrite -scalerAl mul1r. Qed. End LSemiAlgebraTheory. Section LalgebraTheory. Variables (R : pzRingType) (A : lalgType R). Section ClosedPredicates. Variable S : {pred A}. Definition subalg_closed := [/\ 1 \in S, linear_closed S & mulr_2closed S]. Lemma subalg_closedZ : subalg_closed -> submod_closed S. Proof. by case=> S1 Slin _; split; rewrite // -(subrr 1) linear_closedB. Qed. Lemma subalg_closedBM : subalg_closed -> subring_closed S. Proof. by case=> S1 Slin SM; split=> //; apply: linear_closedB. Qed. End ClosedPredicates. End LalgebraTheory. (* Morphism hierarchy. *) (* Lifted multiplication. *) Section LiftedSemiRing. Variables (R : pzSemiRingType) (T : Type). Implicit Type f : T -> R. Definition mull_fun a f x := a * f x. Definition mulr_fun a f x := f x * a. Definition mul_fun f g x := f x * g x. End LiftedSemiRing. (* Lifted linear operations. *) Section LiftedScale. Variables (R : pzSemiRingType) (U : Type). Variables (V : lSemiModType R) (A : lSemiAlgType R). Definition scale_fun a (f : U -> V) x := a *: f x. Definition in_alg k : A := k%:A. End LiftedScale. Local Notation "\0" := (null_fun _) : function_scope. Local Notation "f \+ g" := (add_fun f g) : function_scope. Local Notation "f \- g" := (sub_fun f g) : function_scope. Local Notation "\- f" := (opp_fun f) : function_scope. Local Notation "a \*: f" := (scale_fun a f) : function_scope. Local Notation "x \*o f" := (mull_fun x f) : function_scope. Local Notation "x \o* f" := (mulr_fun x f) : function_scope. Local Notation "f \* g" := (mul_fun f g) : function_scope. Arguments in_alg {_} A _ /. Arguments mull_fun {_ _} a f _ /. Arguments mulr_fun {_ _} a f _ /. Arguments scale_fun {_ _ _} a f _ /. Arguments mul_fun {_ _} f g _ /. Section AdditiveTheory. Section SemiRingProperties. Variables (R S : pzSemiRingType) (f : {additive R -> S}). Lemma raddfMnat n x : f (n%:R * x) = n%:R * f x. Proof. by rewrite !mulr_natl raddfMn. Qed. Variables (U : lSemiModType R) (V : lSemiModType S) (h : {additive U -> V}). Lemma raddfZnat n u : h (n%:R *: u) = n%:R *: h u. Proof. by rewrite !scaler_nat raddfMn. Qed. End SemiRingProperties. Section MulFun. Variables (R : pzSemiRingType) (U : nmodType) (a : R) (f : {additive U -> R}). Fact mull_fun_is_nmod_morphism : nmod_morphism (a \*o f). Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mulr0// raddfD mulrDr. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build U R (a \*o f) mull_fun_is_nmod_morphism. Fact mulr_fun_is_nmod_morphism : nmod_morphism (a \o* f). Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mul0r// raddfD mulrDl. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build U R (a \o* f) mulr_fun_is_nmod_morphism. End MulFun. Section Properties. Variables (U V : zmodType) (f : {additive U -> V}). Lemma raddfN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma raddfB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed. Lemma raddf_inj : (forall x, f x = 0 -> x = 0) -> injective f. Proof. exact: raddf_inj. Qed. Lemma raddfMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. End Properties. Section RingProperties. Variables (R S : pzRingType) (f : {additive R -> S}). Lemma raddfMsign n x : f ((-1) ^+ n * x) = (-1) ^+ n * f x. Proof. by rewrite !(mulr_sign, =^~ signr_odd) (fun_if f) raddfN. Qed. Variables (U : lmodType R) (V : lmodType S) (h : {additive U -> V}). Lemma raddfZsign n u : h ((-1) ^+ n *: u) = (-1) ^+ n *: h u. Proof. by rewrite !(scaler_sign, =^~ signr_odd) (fun_if h) raddfN. Qed. End RingProperties. Section ScaleFun. Variables (R : pzSemiRingType) (U : nmodType) (V : lSemiModType R). Variables (a : R) (f : {additive U -> V}). #[export] HB.instance Definition _ := isNmodMorphism.Build V V ( *:%R a) (conj (scaler0 _ a) (scalerDr a)). #[export] HB.instance Definition _ := Additive.copy (a \*: f) (f \; *:%R a). End ScaleFun. End AdditiveTheory. #[deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")] Definition multiplicative (R S : pzSemiRingType) (f : R -> S) : Prop := {morph f : x y / x * y}%R * (f 1 = 1). (* FIXME: remove once PzSemiRing extends Monoid. *) Definition monoid_morphism (R S : pzSemiRingType) (f : R -> S) : Prop := (f 1 = 1) * {morph f : x y / x * y}%R. HB.mixin Record isMonoidMorphism (R S : pzSemiRingType) (f : R -> S) := { monoid_morphism_subproof : monoid_morphism f }. HB.structure Definition RMorphism (R S : pzSemiRingType) := {f of @isNmodMorphism R S f & isMonoidMorphism R S f}. (* FIXME: remove the @ once https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *) #[warning="-deprecated-since-mathcomp-2.5.0"] HB.factory Record isMultiplicative (R S : pzSemiRingType) (f : R -> S) := { rmorphism_subproof : multiplicative f }. HB.builders Context R S f of isMultiplicative R S f. #[warning="-HB.no-new-instance"] HB.instance Definition _ := isMonoidMorphism.Build R S f (rmorphism_subproof.2, rmorphism_subproof.1). HB.end. Module RMorphismExports. Notation "{ 'rmorphism' U -> V }" := (RMorphism.type U%type V%type) : type_scope. End RMorphismExports. HB.export RMorphismExports. Section RmorphismTheory. Section Properties. Variables (R S : pzSemiRingType) (f : {rmorphism R -> S}). Lemma rmorph0 : f 0 = 0. Proof. exact: raddf0. Qed. Lemma rmorphD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed. Lemma rmorphMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma rmorph_sum I r (P : pred I) E : f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i). Proof. exact: raddf_sum. Qed. Lemma rmorphism_monoidP : monoid_morphism f. Proof. exact: monoid_morphism_subproof. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `rmorphism_monoidP` instead")] Definition rmorphismMP : multiplicative f := (fun p => (p.2, p.1)) rmorphism_monoidP. Lemma rmorph1 : f 1 = 1. Proof. by case: rmorphism_monoidP. Qed. Lemma rmorphM : {morph f: x y / x * y}. Proof. by case: rmorphism_monoidP. Qed. Lemma rmorph_prod I r (P : pred I) E : f (\prod_(i <- r | P i) E i) = \prod_(i <- r | P i) f (E i). Proof. exact: (big_morph f rmorphM rmorph1). Qed. Lemma rmorphXn n : {morph f : x / x ^+ n}. Proof. by elim: n => [|n IHn] x; rewrite ?rmorph1 // !exprS rmorphM IHn. Qed. Lemma rmorph_nat n : f n%:R = n%:R. Proof. by rewrite rmorphMn rmorph1. Qed. Lemma rmorph_eq_nat x n : injective f -> (f x == n%:R) = (x == n%:R). Proof. by move/inj_eq <-; rewrite rmorph_nat. Qed. Lemma rmorph_eq1 x : injective f -> (f x == 1) = (x == 1). Proof. exact: rmorph_eq_nat 1%N. Qed. Lemma can2_monoid_morphism f' : cancel f f' -> cancel f' f -> monoid_morphism f'. Proof. move=> fK f'K. by split=> [|x y]; apply: (canLR fK); rewrite /= (rmorph1, rmorphM) ?f'K. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `can2_monoid_morphism` instead")] Definition can2_rmorphism f' (cff' : cancel f f') := (fun p => (p.2, p.1)) \o (can2_monoid_morphism cff'). End Properties. Lemma rmorph_pchar (R S : nzSemiRingType) (f : {rmorphism R -> S}) p : p \in pchar R -> p \in pchar S. Proof. by rewrite !inE -(rmorph_nat f) => /andP[-> /= /eqP->]; rewrite rmorph0. Qed. Section Projections. Variables (R S T : pzSemiRingType). Variables (f : {rmorphism S -> T}) (g : {rmorphism R -> S}). Fact idfun_is_monoid_morphism : monoid_morphism (@idfun R). Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R R idfun idfun_is_monoid_morphism. Fact comp_is_monoid_morphism : monoid_morphism (f \o g). Proof. by split=> [|x y] /=; rewrite ?rmorph1 ?rmorphM. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R T (f \o g) comp_is_monoid_morphism. End Projections. Section Properties. Variables (R S : pzRingType) (f : {rmorphism R -> S}). Lemma rmorphN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma rmorphB : {morph f: x y / x - y}. Proof. exact: raddfB. Qed. Lemma rmorphMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. Lemma rmorphMsign n : {morph f : x / (- 1) ^+ n * x}. Proof. exact: raddfMsign. Qed. Lemma rmorphN1 : f (- 1) = (- 1). Proof. by rewrite rmorphN rmorph1. Qed. Lemma rmorph_sign n : f ((- 1) ^+ n) = (- 1) ^+ n. Proof. by rewrite rmorphXn /= rmorphN1. Qed. End Properties. Section InSemiAlgebra. Variables (R : pzSemiRingType) (A : lSemiAlgType R). Fact in_alg_is_nmod_morphism : nmod_morphism (in_alg A). Proof. by split; [exact: scale0r | exact: scalerDl]. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build R A (in_alg A) in_alg_is_nmod_morphism. Fact in_alg_is_monoid_morphism : monoid_morphism (in_alg A). Proof. by split=> [|x y]; rewrite /= ?scale1r // mulr_algl scalerA. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R A (in_alg A) in_alg_is_monoid_morphism. Lemma in_algE a : in_alg A a = a%:A. Proof. by []. Qed. End InSemiAlgebra. End RmorphismTheory. #[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")] Notation rmorph_char := rmorph_pchar (only parsing). Module Scale. HB.mixin Record isPreLaw (R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := { op_nmod_morphism : forall a, nmod_morphism (op a); }. #[export] HB.structure Definition PreLaw R V := {op of isPreLaw R V op}. Definition preLaw := PreLaw.type. HB.mixin Record isSemiLaw (R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := { op0v : forall v, op 0 v = 0; op1v : op 1 =1 id; opA : forall a b v, op a (op b v) = op (a * b) v; }. #[export] HB.structure Definition SemiLaw R V := {op of isPreLaw R V op & isSemiLaw R V op}. Definition semiLaw := SemiLaw.type. HB.mixin Record isLaw (R : pzRingType) (V : zmodType) (op : R -> V -> V) := { N1op : op (-1) =1 -%R }. #[export] HB.structure Definition Law (R : pzRingType) (V : zmodType) := {op of isPreLaw R V op & isLaw R V op}. Definition law := Law.type. Section CompSemiLaw. Context (R : pzSemiRingType) (V : nmodType) (s : semiLaw R V). Context (aR : pzSemiRingType) (nu : {rmorphism aR -> R}). Fact comp_op0v v : (nu \; s) 0 v = 0. Proof. by rewrite /= rmorph0 op0v. Qed. Fact comp_op1v : (nu \; s) 1 =1 id. Proof. by move=> v; rewrite /= rmorph1 op1v. Qed. Fact comp_opA a b v : (nu \; s) a ((nu \; s) b v) = (nu \; s) (a * b) v. Proof. by rewrite /= opA rmorphM. Qed. End CompSemiLaw. Fact compN1op (R : pzRingType) (V : zmodType) (s : law R V) (aR : pzRingType) (nu : {rmorphism aR -> R}) : (nu \; s) (-1) =1 -%R. Proof. by move=> v; rewrite /= rmorphN1 N1op. Qed. Module Exports. HB.reexport. End Exports. End Scale. Export Scale.Exports. #[export] HB.instance Definition _ (R : pzSemiRingType) := Scale.isPreLaw.Build R R *%R (fun => mull_fun_is_nmod_morphism _ idfun). #[export] HB.instance Definition _ (R : pzSemiRingType) := Scale.isSemiLaw.Build R R *%R mul0r mul1r mulrA. #[export] HB.instance Definition _ (R : pzRingType) := Scale.isLaw.Build R R *%R (@mulN1r R). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) := Scale.isPreLaw.Build R V *:%R (fun => (scaler0 _ _, scalerDr _)). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) := Scale.isSemiLaw.Build R V *:%R scale0r scale1r (@scalerA _ _). #[export] HB.instance Definition _ (R : pzRingType) (U : lmodType R) := Scale.isLaw.Build R U *:%R (@scaleN1r R U). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V) (aR : pzSemiRingType) (nu : {rmorphism aR -> R}) := Scale.isPreLaw.Build aR V (nu \; s) (fun => Scale.op_nmod_morphism _). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.semiLaw R V) (aR : pzSemiRingType) (nu : {rmorphism aR -> R}) := Scale.isSemiLaw.Build aR V (nu \; s) (Scale.comp_op0v s nu) (Scale.comp_op1v s nu) (Scale.comp_opA s nu). #[export] HB.instance Definition _ (R : pzRingType) (V : zmodType) (s : Scale.law R V) (aR : pzRingType) (nu : {rmorphism aR -> R}) := Scale.isLaw.Build aR V (nu \; s) (Scale.compN1op s nu). #[export, non_forgetful_inheritance] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V) a := isNmodMorphism.Build V V (s a) (Scale.op_nmod_morphism a). Definition scalable_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := forall a, {morph f : u / a *: u >-> s a u}. HB.mixin Record isScalable (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := { semi_linear_subproof : scalable_for s f; }. HB.structure Definition Linear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) := {f of @isNmodMorphism U V f & isScalable R U V s f}. Definition semilinear_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) : Type := scalable_for s f * {morph f : x y / x + y}. Lemma nmod_morphism_semilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) : semilinear_for s f -> nmod_morphism f. Proof. by case=> sf Df; split => //; rewrite -[0 in LHS](scale0r 0) sf Scale.op0v. Qed. Definition additive_semilinear := nmod_morphism_semilinear. Lemma scalable_semilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.preLaw R V) (f : U -> V) : semilinear_for s f -> scalable_for s f. Proof. by case. Qed. HB.factory Record isSemilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) := { linear_subproof : semilinear_for s f; }. HB.builders Context R U V s f of isSemilinear R U V s f. HB.instance Definition _ := isNmodMorphism.Build U V f (additive_semilinear linear_subproof). HB.instance Definition _ := isScalable.Build R U V s f (scalable_semilinear linear_subproof). HB.end. Definition linear_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := forall a, {morph f : u v / a *: u + v >-> s a u + v}. Lemma zmod_morphism_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> zmod_morphism f. Proof. by move=> Lsf x y; rewrite -scaleN1r addrC Lsf Scale.N1op addrC. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism_linear` instead")] Definition additive_linear := zmod_morphism_linear. Lemma scalable_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> scalable_for s f. Proof. by move=> Lsf a v; rewrite -[a *:v](addrK v) (zmod_morphism_linear Lsf) Lsf addrK. Qed. Lemma semilinear_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> semilinear_for s f. Proof. move=> Lsf; split=> [a x|x y]; first exact: (scalable_linear Lsf). have f0: f 0 = 0 by rewrite -[0 in LHS]subr0 (zmod_morphism_linear Lsf) subrr. by rewrite -[y in LHS]opprK -[- y]add0r !(zmod_morphism_linear Lsf) f0 sub0r opprK. Qed. HB.factory Record isLinear (R : pzRingType) (U : lmodType R) (V : zmodType) (s : Scale.law R V) (f : U -> V) := { linear_subproof : linear_for s f; }. HB.builders Context R U V s f of isLinear R U V s f. HB.instance Definition _ := isZmodMorphism.Build U V f (zmod_morphism_linear linear_subproof). HB.instance Definition _ := isScalable.Build R U V s f (scalable_linear linear_subproof). HB.end. Module LinearExports. Notation scalable f := (scalable_for *:%R f). Notation semilinear f := (semilinear_for *:%R f). Notation semiscalar f := (semilinear_for *%R f). Notation linear f := (linear_for *:%R f). Notation scalar f := (linear_for *%R f). Module Linear. Section Linear. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V). (* Support for right-to-left rewriting with the generic linearZ rule. *) Local Notation mapUV := (@Linear.type R U V s). Definition map_class := mapUV. Definition map_at (a : R) := mapUV. Structure map_for a s_a := MapFor {map_for_map : mapUV; _ : s a = s_a}. Definition unify_map_at a (g : map_at a) := MapFor g (erefl (s a)). Structure wrapped := Wrap {unwrap : mapUV}. Definition wrap (f : map_class) := Wrap f. End Linear. End Linear. Notation "{ 'linear' U -> V | s }" := (@Linear.type _ U V s) : type_scope. Notation "{ 'linear' U -> V }" := {linear U -> V | *:%R} : type_scope. Notation "{ 'scalar' U }" := {linear U -> _ | *%R} (format "{ 'scalar' U }") : type_scope. (* Support for right-to-left rewriting with the generic linearZ rule. *) Coercion Linear.map_for_map : Linear.map_for >-> Linear.type. Coercion Linear.unify_map_at : Linear.map_at >-> Linear.map_for. Canonical Linear.unify_map_at. Coercion Linear.unwrap : Linear.wrapped >-> Linear.type. Coercion Linear.wrap : Linear.map_class >-> Linear.wrapped. Canonical Linear.wrap. End LinearExports. HB.export LinearExports. Section LinearTheory. Section GenericProperties. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V) (f : {linear U -> V | s}). Lemma linear0 : f 0 = 0. Proof. exact: raddf0. Qed. Lemma linearD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed. Lemma linearMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma linear_sum I r (P : pred I) E : f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i). Proof. exact: raddf_sum. Qed. Lemma linearZ_LR : scalable_for s f. Proof. exact: semi_linear_subproof. Qed. Lemma semilinearP : semilinear_for s f. Proof. split; [exact: linearZ_LR | exact: linearD]. Qed. Lemma linearP : linear_for s f. Proof. by move=> a u v /=; rewrite !semilinearP. Qed. End GenericProperties. Section GenericProperties. Variables (R : pzRingType) (U : lmodType R) (V : zmodType) (s : R -> V -> V). Variables (f : {linear U -> V | s}). Lemma linearN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma linearB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed. Lemma linearMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. End GenericProperties. Section BidirectionalLinearZ. (* The general form of the linearZ lemma uses some bespoke interfaces to *) (* allow right-to-left rewriting when a composite scaling operation such as *) (* conjC \; *%R has been expanded, say in a^* * f u. This redex is matched *) (* by using the Scale.law interface to recognize a "head" scaling operation *) (* h (here *%R), stow away its "scalar" c, then reconcile h c and s a, once *) (* s is known, that is, once the Linear.map structure for f has been found. *) (* In general, s and a need not be equal to h and c; indeed they need not *) (* have the same type! The unification is performed by the unify_map_at *) (* default instance for the Linear.map_for U s a h_c sub-interface of *) (* Linear.map; the h_c pattern uses the Scale.law structure to insure it is *) (* inferred when rewriting right-to-left. *) (* The wrap on the rhs allows rewriting f (a *: b *: u) into a *: b *: f u *) (* with rewrite !linearZ /= instead of rewrite linearZ /= linearZ /=. *) (* Without it, the first rewrite linearZ would produce *) (* (a *: apply (map_for_map (@check_map_at .. a f)) (b *: u)%R)%Rlin *) (* and matching the second rewrite LHS would bypass the unify_map_at default *) (* instance for b, reuse the one for a, and subsequently fail to match the *) (* b *: u argument. The extra wrap / unwrap ensures that this can't happen. *) (* In the RL direction, the wrap / unwrap will be inserted on the redex side *) (* as needed, without causing unnecessary delta-expansion: using an explicit *) (* identity function would have Coq normalize the redex to head normal, then *) (* reduce the identity to expose the map_for_map projection, and the *) (* expanded Linear.map structure would then be exposed in the result. *) (* Most of this machinery will be invisible to a casual user, because all *) (* the projections and default instances involved are declared as coercions. *) Lemma linearZ (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (S : pzSemiRingType) (h : Scale.preLaw S V) (c : S) (a : R) (h_c := h c) (f : Linear.map_for U s a h_c) (u : U) : f (a *: u) = h_c (Linear.wrap f u). Proof. by rewrite linearZ_LR; case: f => f /= ->. Qed. End BidirectionalLinearZ. Section LmodProperties. Variables (R : pzSemiRingType) (U V : lSemiModType R) (f : {linear U -> V}). Lemma linearZZ : scalable f. Proof. exact: linearZ_LR. Qed. Lemma semilinearPZ : semilinear f. Proof. exact: semilinearP. Qed. Lemma linearPZ : linear f. Proof. exact: linearP. Qed. Lemma can2_scalable f' : cancel f f' -> cancel f' f -> scalable f'. Proof. by move=> fK f'K a x; apply: (canLR fK); rewrite linearZZ f'K. Qed. Lemma can2_semilinear f' : cancel f f' -> cancel f' f -> semilinear f'. Proof. by move=> fK f'K; split=> ? ?; apply: (canLR fK); rewrite semilinearPZ !f'K. Qed. Lemma can2_linear f' : cancel f f' -> cancel f' f -> linear f'. Proof. by move=> fK f'K a x y /=; apply: (canLR fK); rewrite linearP !f'K. Qed. End LmodProperties. Section ScalarProperties. Variable (R : pzSemiRingType) (U : lSemiModType R) (f : {scalar U}). Lemma scalarZ : scalable_for *%R f. Proof. exact: linearZ_LR. Qed. Lemma semiscalarP : semiscalar f. Proof. exact: semilinearP. Qed. Lemma scalarP : scalar f. Proof. exact: linearP. Qed. End ScalarProperties. Section LinearLSemiMod. Section Idfun. Variables (R : pzSemiRingType) (U : lSemiModType R). Lemma idfun_is_scalable : scalable (@idfun U). Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R U U *:%R idfun idfun_is_scalable. End Idfun. Section Plain. Variables (R : pzSemiRingType) (W U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V) (f : {linear U -> V | s}) (g : {linear W -> U}). Lemma comp_is_scalable : scalable_for s (f \o g). Proof. by move=> a v /=; rewrite !linearZ_LR. Qed. #[export] HB.instance Definition _ := isScalable.Build R W V s (f \o g) comp_is_scalable. End Plain. Section SemiScale. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}). Lemma null_fun_is_scalable : scalable_for s (\0 : U -> V). Proof. by move=> a v /=; rewrite raddf0. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s \0 null_fun_is_scalable. Lemma add_fun_is_scalable : scalable_for s (add_fun f g). Proof. by move=> a u; rewrite /= !linearZ_LR raddfD. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (f \+ g) add_fun_is_scalable. End SemiScale. End LinearLSemiMod. Section LinearLmod. Variables (R : pzRingType) (U : lmodType R). Lemma opp_is_scalable : scalable (-%R : U -> U). Proof. by move=> a v /=; rewrite scalerN. Qed. #[export] HB.instance Definition _ := isScalable.Build R U U *:%R -%R opp_is_scalable. End LinearLmod. Section Scale. Variables (R : pzRingType) (U : lmodType R) (V : zmodType). Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}). Lemma sub_fun_is_scalable : scalable_for s (f \- g). Proof. by move=> a u; rewrite /= !linearZ_LR raddfB. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (f \- g) sub_fun_is_scalable. Lemma opp_fun_is_scalable : scalable_for s (\- f). Proof. by move=> a u; rewrite /= linearZ_LR raddfN. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (\- f) opp_fun_is_scalable. End Scale. Section LinearLSemiAlg. Variables (R : pzSemiRingType) (A : lSemiAlgType R) (U : lSemiModType R). Variables (a : A) (f : {linear U -> A}). Fact mulr_fun_is_scalable : scalable (a \o* f). Proof. by move=> k x /=; rewrite linearZ scalerAl. Qed. #[export] HB.instance Definition _ := isScalable.Build R U A *:%R (a \o* f) mulr_fun_is_scalable. End LinearLSemiAlg. End LinearTheory. HB.structure Definition LRMorphism (R : pzSemiRingType) (A : lSemiAlgType R) (B : pzSemiRingType) (s : R -> B -> B) := {f of @RMorphism A B f & isScalable R A B s f}. (* FIXME: remove the @ once https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *) Module LRMorphismExports. Notation "{ 'lrmorphism' A -> B | s }" := (@LRMorphism.type _ A%type B%type s) : type_scope. Notation "{ 'lrmorphism' A -> B }" := {lrmorphism A%type -> B%type | *:%R} : type_scope. End LRMorphismExports. HB.export LRMorphismExports. Section LRMorphismTheory. Variables (R : pzSemiRingType) (A B : lSemiAlgType R) (C : pzSemiRingType). Variables (s : R -> C -> C). Variables (f : {lrmorphism A -> B}) (g : {lrmorphism B -> C | s}). #[export] HB.instance Definition _ := RMorphism.on (@idfun A). #[export] HB.instance Definition _ := RMorphism.on (g \o f). Lemma rmorph_alg a : f a%:A = a%:A. Proof. by rewrite linearZ /= rmorph1. Qed. End LRMorphismTheory. HB.mixin Record PzSemiRing_hasCommutativeMul R of PzSemiRing R := { mulrC : commutative (@mul R) }. Module SemiRing_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzSemiRing_hasCommutativeMul.Build instead.")] Notation Build R := (PzSemiRing_hasCommutativeMul.Build R) (only parsing). End SemiRing_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzSemiRing_hasCommutativeMul instead.")] Notation SemiRing_hasCommutativeMul R := (PzSemiRing_hasCommutativeMul R) (only parsing). #[short(type="comPzSemiRingType")] HB.structure Definition ComPzSemiRing := {R of PzSemiRing R & PzSemiRing_hasCommutativeMul R}. Module ComPzSemiRingExports. Bind Scope ring_scope with ComPzSemiRing.sort. End ComPzSemiRingExports. HB.export ComPzSemiRingExports. HB.factory Record Nmodule_isComPzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; mul0r : left_zero zero mul; }. HB.builders Context R of Nmodule_isComPzSemiRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. Lemma mulr0 : right_zero zero mul. Proof. by move=> x; rewrite mulrC mul0r. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. #[short(type="comNzSemiRingType")] HB.structure Definition ComNzSemiRing := {R of NzSemiRing R & PzSemiRing_hasCommutativeMul R}. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing instead.")] Notation ComSemiRing R := (ComNzSemiRing R) (only parsing). Module ComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.sort instead.")] Notation sort := (ComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.on instead.")] Notation on R := (ComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.copy instead.")] Notation copy T U := (ComNzSemiRing.copy T U) (only parsing). End ComSemiRing. Module ComNzSemiRingExports. Bind Scope ring_scope with ComNzSemiRing.sort. End ComNzSemiRingExports. HB.export ComNzSemiRingExports. HB.factory Record Nmodule_isComNzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; mul0r : left_zero zero mul; oner_neq0 : one != zero }. Module Nmodule_isComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isComNzSemiRing.Build instead.")] Notation Build R := (Nmodule_isComNzSemiRing.Build R) (only parsing). End Nmodule_isComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isComNzSemiRing instead.")] Notation Nmodule_isComSemiRing R := (Nmodule_isComNzSemiRing R) (only parsing). HB.builders Context R of Nmodule_isComNzSemiRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. Lemma mulr0 : right_zero zero mul. Proof. by move=> x; rewrite mulrC mul0r. Qed. HB.instance Definition _ := Nmodule_isNzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. Section ComSemiRingTheory. Variable R : comPzSemiRingType. Implicit Types x y : R. #[export] HB.instance Definition _ := SemiGroup.isCommutativeLaw.Build R *%R mulrC. Lemma mulrCA : @left_commutative R R *%R. Proof. exact: mulmCA. Qed. Lemma mulrAC : @right_commutative R R *%R. Proof. exact: mulmAC. Qed. Lemma mulrACA : @interchange R *%R *%R. Proof. exact: mulmACA. Qed. Lemma exprMn n : {morph (fun x => x ^+ n) : x y / x * y}. Proof. by move=> x y; exact/exprMn_comm/mulrC. Qed. Lemma prodrXl n I r (P : pred I) (F : I -> R) : \prod_(i <- r | P i) F i ^+ n = (\prod_(i <- r | P i) F i) ^+ n. Proof. by rewrite (big_morph _ (exprMn n) (expr1n _ n)). Qed. Lemma prodr_undup_exp_count (I : eqType) r (P : pred I) (F : I -> R) : \prod_(i <- undup r | P i) F i ^+ count_mem i r = \prod_(i <- r | P i) F i. Proof. exact: big_undup_iterop_count. Qed. Lemma prodrMl {I : finType} (A : pred I) (x : R) F : \prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i. Proof. by rewrite big_split ?prodr_const. Qed. Lemma prodrMr {I : finType} (A : pred I) (x : R) F : \prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|. Proof. by rewrite big_split ?prodr_const. Qed. Lemma exprDn x y n : (x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. by rewrite exprDn_comm //; apply: mulrC. Qed. Lemma sqrrD x y : (x + y) ^+ 2 = x ^+ 2 + x * y *+ 2 + y ^+ 2. Proof. by rewrite exprDn !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed. End ComSemiRingTheory. (* FIXME: Generalize to `comPzSemiRingType` ? *) Section ComNzSemiRingTheory. Variable R : comNzSemiRingType. Implicit Types x y : R. Section FrobeniusAutomorphism. Variables (p : nat) (pcharRp : p \in pchar R). Lemma pFrobenius_aut_is_nmod_morphism : nmod_morphism (pFrobenius_aut pcharRp). Proof. by split=> [|x y]; [exact: pFrobenius_aut0 | exact/pFrobenius_autD_comm/mulrC]. Qed. Lemma pFrobenius_aut_is_monoid_morphism : monoid_morphism (pFrobenius_aut pcharRp). Proof. by split=> [|x y]; [exact: pFrobenius_aut1 | exact/pFrobenius_autM_comm/mulrC]. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build R R (pFrobenius_aut pcharRp) pFrobenius_aut_is_nmod_morphism. #[export] HB.instance Definition _ := isMonoidMorphism.Build R R (pFrobenius_aut pcharRp) pFrobenius_aut_is_monoid_morphism. End FrobeniusAutomorphism. Lemma exprDn_pchar x y n : (pchar R).-nat n -> (x + y) ^+ n = x ^+ n + y ^+ n. Proof. pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]]. have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) ?pi_pdiv. have{pcharRn} /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)). by elim: e => // e IHe; rewrite !expnSr !exprM IHe -pFrobenius_autE rmorphD. Qed. (* FIXME: Generalize to `comPzSemiRingType` ? *) Lemma rmorph_comm (S : nzSemiRingType) (f : {rmorphism R -> S}) x y : comm (f x) (f y). Proof. by red; rewrite -!rmorphM mulrC. Qed. Section ScaleLinear. Variables (U V : lSemiModType R) (b : R) (f : {linear U -> V}). Lemma scale_is_scalable : scalable ( *:%R b : V -> V). Proof. by move=> a v /=; rewrite !scalerA mulrC. Qed. #[export] HB.instance Definition _ := isScalable.Build R V V *:%R ( *:%R b) scale_is_scalable. Lemma scale_fun_is_scalable : scalable (b \*: f). Proof. by move=> a v /=; rewrite !linearZ. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V *:%R (b \*: f) scale_fun_is_scalable. End ScaleLinear. End ComNzSemiRingTheory. #[short(type="comPzRingType")] HB.structure Definition ComPzRing := {R of PzRing R & ComPzSemiRing R}. HB.factory Record PzRing_hasCommutativeMul R of PzRing R := { mulrC : commutative (@mul R) }. Module Ring_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzRing_hasCommutativeMul.Build instead.")] Notation Build R := (PzRing_hasCommutativeMul.Build R) (only parsing). End Ring_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzRing_hasCommutativeMul instead.")] Notation Ring_hasCommutativeMul R := (PzRing_hasCommutativeMul R) (only parsing). HB.builders Context R of PzRing_hasCommutativeMul R. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. HB.factory Record Zmodule_isComPzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; }. HB.builders Context R of Zmodule_isComPzRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. HB.instance Definition _ := Zmodule_isPzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr. HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC. HB.end. Module ComPzRingExports. Bind Scope ring_scope with ComPzRing.sort. End ComPzRingExports. HB.export ComPzRingExports. #[deprecated(since="mathcomp 2.5.0", note="Use pFrobenius_aut_is_monoid_morphism instead.")] Notation pFrobenius_aut_is_multiplicative := (fun p => (p.2, p.1) \o pFrobenius_aut_is_monoid_morphism) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")] Notation exprDn_char := exprDn_pchar (only parsing). #[short(type="comNzRingType")] HB.structure Definition ComNzRing := {R of NzRing R & ComNzSemiRing R}. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing instead.")] Notation ComRing R := (ComNzRing R) (only parsing). Module ComRing. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.sort instead.")] Notation sort := (ComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.on instead.")] Notation on R := (ComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.copy instead.")] Notation copy T U := (ComNzRing.copy T U) (only parsing). End ComRing. HB.factory Record Zmodule_isComNzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; oner_neq0 : one != zero }. Module Zmodule_isComRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isComNzRing.Build instead.")] Notation Build R := (Zmodule_isComNzRing.Build R) (only parsing). End Zmodule_isComRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isComNzRing instead.")] Notation Zmodule_isComRing R := (Zmodule_isComNzRing R) (only parsing). HB.builders Context R of Zmodule_isComNzRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. HB.instance Definition _ := Zmodule_isNzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr oner_neq0. HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC. HB.end. Module ComNzRingExports. Bind Scope ring_scope with ComNzRing.sort. End ComNzRingExports. HB.export ComNzRingExports. Section ComPzRingTheory. Variable R : comPzRingType. Implicit Types x y : R. Lemma exprBn x y n : (x - y) ^+ n = \sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. by rewrite exprBn_comm //; apply: mulrC. Qed. Lemma subrXX x y n : x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i). Proof. by rewrite -subrXX_comm //; apply: mulrC. Qed. Lemma sqrrB x y : (x - y) ^+ 2 = x ^+ 2 - x * y *+ 2 + y ^+ 2. Proof. by rewrite sqrrD mulrN mulNrn sqrrN. Qed. Lemma subr_sqr x y : x ^+ 2 - y ^+ 2 = (x - y) * (x + y). Proof. by rewrite subrXX !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed. Lemma subr_sqrDB x y : (x + y) ^+ 2 - (x - y) ^+ 2 = x * y *+ 4. Proof. rewrite sqrrD sqrrB -!(addrAC _ (y ^+ 2)) opprB. by rewrite [LHS]addrC addrA subrK -mulrnDr. Qed. End ComPzRingTheory. HB.mixin Record LSemiAlgebra_isSemiAlgebra R V of LSemiAlgebra R V := { scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y); }. #[short(type="semiAlgType")] HB.structure Definition SemiAlgebra (R : pzSemiRingType) := {A of LSemiAlgebra_isSemiAlgebra R A & LSemiAlgebra R A}. Module SemiAlgExports. Bind Scope ring_scope with SemiAlgebra.sort. End SemiAlgExports. HB.factory Record LSemiAlgebra_isComSemiAlgebra R V of ComPzSemiRing V & LSemiAlgebra R V := {}. HB.builders Context (R : pzSemiRingType) V of LSemiAlgebra_isComSemiAlgebra R V. Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y). Proof. by rewrite mulrC scalerAl mulrC. Qed. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalarAr. HB.end. #[short(type="algType")] HB.structure Definition Algebra (R : pzRingType) := {A of LSemiAlgebra_isSemiAlgebra R A & Lalgebra R A}. Module AlgExports. Bind Scope ring_scope with Algebra.sort. End AlgExports. HB.export AlgExports. HB.factory Record Lalgebra_isAlgebra (R : pzRingType) V of Lalgebra R V := { scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y); }. HB.builders Context (R : pzRingType) V of Lalgebra_isAlgebra R V. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalerAr. HB.end. HB.factory Record Lalgebra_isComAlgebra R V of ComPzRing V & Lalgebra R V := {}. HB.builders Context (R : pzRingType) V of Lalgebra_isComAlgebra R V. Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y). Proof. by rewrite mulrC scalerAl mulrC. Qed. HB.instance Definition lalgebra_is_algebra : Lalgebra_isAlgebra R V := Lalgebra_isAlgebra.Build R V scalarAr. HB.end. #[short(type="comSemiAlgType")] HB.structure Definition ComSemiAlgebra R := {V of ComNzSemiRing V & SemiAlgebra R V}. Module ComSemiAlgExports. Bind Scope ring_scope with ComSemiAlgebra.sort. End ComSemiAlgExports. HB.export ComSemiAlgExports. Section SemiAlgebraTheory. #[export] HB.instance Definition _ (R : comPzSemiRingType) := PzSemiRing_hasCommutativeMul.Build R^c (fun _ _ => mulrC _ _). #[export] HB.instance Definition _ (R : comPzSemiRingType) := ComPzSemiRing.on R^o. #[export] HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^c. #[export] HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^o. #[export] HB.instance Definition _ (R : comNzSemiRingType) := LSemiAlgebra_isComSemiAlgebra.Build R R^o. End SemiAlgebraTheory. #[short(type="comAlgType")] HB.structure Definition ComAlgebra R := {V of ComNzRing V & Algebra R V}. Module ComAlgExports. Bind Scope ring_scope with ComAlgebra.sort. End ComAlgExports. HB.export ComAlgExports. Section AlgebraTheory. #[export] HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^c. #[export] HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^o. #[export] HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^c. #[export] HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^o. End AlgebraTheory. Section SemiAlgebraTheory. Variables (R : pzSemiRingType) (A : semiAlgType R). Implicit Types (k : R) (x y : A). Lemma scalerCA k x y : k *: x * y = x * (k *: y). Proof. by rewrite -scalerAl scalerAr. Qed. Lemma mulr_algr a x : x * a%:A = a *: x. Proof. by rewrite -scalerAr mulr1. Qed. Lemma comm_alg a x : comm a%:A x. Proof. by rewrite /comm mulr_algr mulr_algl. Qed. Lemma exprZn k x n : (k *: x) ^+ n = k ^+ n *: x ^+ n. Proof. elim: n => [|n IHn]; first by rewrite !expr0 scale1r. by rewrite !exprS IHn -scalerA scalerAr scalerAl. Qed. Lemma scaler_prod I r (P : pred I) (F : I -> R) (G : I -> A) : \prod_(i <- r | P i) (F i *: G i) = \prod_(i <- r | P i) F i *: \prod_(i <- r | P i) G i. Proof. elim/big_rec3: _ => [|i x a _ _ ->]; first by rewrite scale1r. by rewrite -scalerAl -scalerAr scalerA. Qed. Lemma scaler_prodl (I : finType) (S : pred I) (F : I -> A) k : \prod_(i in S) (k *: F i) = k ^+ #|S| *: \prod_(i in S) F i. Proof. by rewrite scaler_prod prodr_const. Qed. Lemma scaler_prodr (I : finType) (S : pred I) (F : I -> R) x : \prod_(i in S) (F i *: x) = \prod_(i in S) F i *: x ^+ #|S|. Proof. by rewrite scaler_prod prodr_const. Qed. End SemiAlgebraTheory. Section AlgebraTheory. Variables (R : pzSemiRingType) (A : semiAlgType R). Variables (U : lSemiModType R) (a : A) (f : {linear U -> A}). Lemma mull_fun_is_scalable : scalable (a \*o f). Proof. by move=> k x /=; rewrite linearZ scalerAr. Qed. #[export] HB.instance Definition _ := isScalable.Build R U A *:%R (a \*o f) mull_fun_is_scalable. End AlgebraTheory. HB.mixin Record NzRing_hasMulInverse R of NzRing R := { unit_subdef : pred R; inv : R -> R; mulVr_subproof : {in unit_subdef, left_inverse 1 inv *%R}; divrr_subproof : {in unit_subdef, right_inverse 1 inv *%R}; unitrP_subproof : forall x y, y * x = 1 /\ x * y = 1 -> unit_subdef x; invr_out_subproof : {in [predC unit_subdef], inv =1 id} }. Module Ring_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing_hasMulInverse.Build instead.")] Notation Build R := (NzRing_hasMulInverse.Build R) (only parsing). End Ring_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing_hasMulInverse instead.")] Notation Ring_hasMulInverse R := (NzRing_hasMulInverse R) (only parsing). #[short(type="unitRingType")] HB.structure Definition UnitRing := {R of NzRing_hasMulInverse R & NzRing R}. Module UnitRingExports. Bind Scope ring_scope with UnitRing.sort. End UnitRingExports. HB.export UnitRingExports. Definition unit_pred {R : unitRingType} := Eval cbv [ unit_subdef NzRing_hasMulInverse.unit_subdef ] in (fun u : R => unit_subdef u). Arguments unit_pred _ _ /. Definition unit {R : unitRingType} := [qualify a u : R | unit_pred u]. Local Notation "x ^-1" := (inv x). Local Notation "x / y" := (x * y^-1). Local Notation "x ^- n" := ((x ^+ n)^-1). Section UnitRingTheory. Variable R : unitRingType. Implicit Types x y : R. Lemma divrr : {in unit, right_inverse 1 (@inv R) *%R}. Proof. exact: divrr_subproof. Qed. Definition mulrV := divrr. Lemma mulVr : {in unit, left_inverse 1 (@inv R) *%R}. Proof. exact: mulVr_subproof. Qed. Lemma invr_out x : x \isn't a unit -> x^-1 = x. Proof. exact: invr_out_subproof. Qed. Lemma unitrP x : reflect (exists y, y * x = 1 /\ x * y = 1) (x \is a unit). Proof. apply: (iffP idP) => [Ux | []]; last exact: unitrP_subproof. by exists x^-1; rewrite divrr ?mulVr. Qed. Lemma mulKr : {in unit, left_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite mulrA mulVr ?mul1r. Qed. Lemma mulVKr : {in unit, rev_left_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite mulrA mulrV ?mul1r. Qed. Lemma mulrK : {in unit, right_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite -mulrA divrr ?mulr1. Qed. Lemma mulrVK : {in unit, rev_right_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite -mulrA mulVr ?mulr1. Qed. Definition divrK := mulrVK. Lemma mulrI : {in @unit R, right_injective *%R}. Proof. by move=> x Ux; apply: can_inj (mulKr Ux). Qed. Lemma mulIr : {in @unit R, left_injective *%R}. Proof. by move=> x Ux; apply: can_inj (mulrK Ux). Qed. (* Due to noncommutativity, fractions are inverted. *) Lemma telescope_prodr n m (f : nat -> R) : (forall k, n < k < m -> f k \is a unit) -> n < m -> \prod_(n <= k < m) (f k / f k.+1) = f n / f m. Proof. move=> Uf ltnm; rewrite (telescope_big (fun i j => f i / f j)) ?ltnm//. by move=> k ltnkm /=; rewrite mulrA divrK// Uf. Qed. Lemma telescope_prodr_eq n m (f u : nat -> R) : n < m -> (forall k, n < k < m -> f k \is a unit) -> (forall k, (n <= k < m)%N -> u k = f k / f k.+1) -> \prod_(n <= k < m) u k = f n / f m. Proof. by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodr. Qed. Lemma commrV x y : comm x y -> comm x y^-1. Proof. have [Uy cxy | /invr_out-> //] := boolP (y \in unit). by apply: (canLR (mulrK Uy)); rewrite -mulrA cxy mulKr. Qed. Lemma unitrE x : (x \is a unit) = (x / x == 1). Proof. apply/idP/eqP=> [Ux | xx1]; first exact: divrr. by apply/unitrP; exists x^-1; rewrite -commrV. Qed. Lemma invrK : involutive (@inv R). Proof. move=> x; case Ux: (x \in unit); last by rewrite !invr_out ?Ux. rewrite -(mulrK Ux _^-1) -mulrA commrV ?mulKr //. by apply/unitrP; exists x; rewrite divrr ?mulVr. Qed. Lemma invr_inj : injective (@inv R). Proof. exact: inv_inj invrK. Qed. Lemma unitrV x : (x^-1 \in unit) = (x \in unit). Proof. by rewrite !unitrE invrK commrV. Qed. Lemma unitr1 : 1 \in @unit R. Proof. by apply/unitrP; exists 1; rewrite mulr1. Qed. Lemma invr1 : 1^-1 = 1 :> R. Proof. by rewrite -{2}(mulVr unitr1) mulr1. Qed. Lemma div1r x : 1 / x = x^-1. Proof. by rewrite mul1r. Qed. Lemma divr1 x : x / 1 = x. Proof. by rewrite invr1 mulr1. Qed. Lemma natr_div m d : d %| m -> d%:R \is a @unit R -> (m %/ d)%:R = m%:R / d%:R :> R. Proof. by rewrite dvdn_eq => /eqP def_m unit_d; rewrite -{2}def_m natrM mulrK. Qed. Lemma divrI : {in unit, right_injective (fun x y => x / y)}. Proof. by move=> x /mulrI/inj_comp; apply; apply: invr_inj. Qed. Lemma divIr : {in unit, left_injective (fun x y => x / y)}. Proof. by move=> x; rewrite -unitrV => /mulIr. Qed. Lemma unitr0 : (0 \is a @unit R) = false. Proof. by apply/unitrP=> [[x [_ /esym/eqP]]]; rewrite mul0r oner_eq0. Qed. Lemma invr0 : 0^-1 = 0 :> R. Proof. by rewrite invr_out ?unitr0. Qed. Lemma unitrN1 : -1 \is a @unit R. Proof. by apply/unitrP; exists (-1); rewrite mulrNN mulr1. Qed. Lemma invrN1 : (-1)^-1 = -1 :> R. Proof. by rewrite -{2}(divrr unitrN1) mulN1r opprK. Qed. Lemma invr_sign n : ((-1) ^- n) = (-1) ^+ n :> R. Proof. by rewrite -signr_odd; case: (odd n); rewrite (invr1, invrN1). Qed. Lemma unitrMl x y : y \is a unit -> (x * y \is a unit) = (x \is a unit). Proof. move=> Uy; wlog Ux: x y Uy / x \is a unit => [WHxy|]. by apply/idP/idP=> Ux; first rewrite -(mulrK Uy x); rewrite WHxy ?unitrV. rewrite Ux; apply/unitrP; exists (y^-1 * x^-1). by rewrite -!mulrA mulKr ?mulrA ?mulrK ?divrr ?mulVr. Qed. Lemma unitrMr x y : x \is a unit -> (x * y \is a unit) = (y \is a unit). Proof. move=> Ux; apply/idP/idP=> [Uxy | Uy]; last by rewrite unitrMl. by rewrite -(mulKr Ux y) unitrMl ?unitrV. Qed. Lemma unitr_prod {I : Type} (P : pred I) (E : I -> R) (r : seq I) : (forall i, P i -> E i \is a GRing.unit) -> (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. by move=> Eunit; elim/big_rec: _ => [/[!unitr1] |i x /Eunit/unitrMr->]. Qed. Lemma unitr_prod_in {I : eqType} (P : pred I) (E : I -> R) (r : seq I) : {in r, forall i, P i -> E i \is a GRing.unit} -> (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. by rewrite big_seq_cond => H; apply: unitr_prod => i /andP[]; exact: H. Qed. Lemma invrM : {in unit &, forall x y, (x * y)^-1 = y^-1 * x^-1}. Proof. move=> x y Ux Uy; have Uxy: (x * y \in unit) by rewrite unitrMl. by apply: (mulrI Uxy); rewrite divrr ?mulrA ?mulrK ?divrr. Qed. Lemma unitrM_comm x y : comm x y -> (x * y \is a unit) = (x \is a unit) && (y \is a unit). Proof. move=> cxy; apply/idP/andP=> [Uxy | [Ux Uy]]; last by rewrite unitrMl. suffices Ux: x \in unit by rewrite unitrMr in Uxy. apply/unitrP; case/unitrP: Uxy => z [zxy xyz]; exists (y * z). rewrite mulrA xyz -{1}[y]mul1r -{1}zxy cxy -!mulrA (mulrA x) (mulrA _ z) xyz. by rewrite mul1r -cxy. Qed. Lemma unitrX x n : x \is a unit -> x ^+ n \is a unit. Proof. by move=> Ux; elim: n => [|n IHn]; rewrite ?unitr1 // exprS unitrMl. Qed. Lemma unitrX_pos x n : n > 0 -> (x ^+ n \in unit) = (x \in unit). Proof. case: n => // n _; rewrite exprS unitrM_comm; last exact: commrX. by case Ux: (x \is a unit); rewrite // unitrX. Qed. Lemma exprVn x n : x^-1 ^+ n = x ^- n. Proof. elim: n => [|n IHn]; first by rewrite !expr0 ?invr1. case Ux: (x \is a unit); first by rewrite exprSr exprS IHn -invrM // unitrX. by rewrite !invr_out ?unitrX_pos ?Ux. Qed. Lemma exprB m n x : n <= m -> x \is a unit -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. by move/subnK=> {2}<- Ux; rewrite exprD mulrK ?unitrX. Qed. Lemma invr_neq0 x : x != 0 -> x^-1 != 0. Proof. move=> nx0; case Ux: (x \is a unit); last by rewrite invr_out ?Ux. by apply/eqP=> x'0; rewrite -unitrV x'0 unitr0 in Ux. Qed. Lemma invr_eq0 x : (x^-1 == 0) = (x == 0). Proof. by apply: negb_inj; apply/idP/idP; move/invr_neq0; rewrite ?invrK. Qed. Lemma invr_eq1 x : (x^-1 == 1) = (x == 1). Proof. by rewrite (inv_eq invrK) invr1. Qed. Lemma rev_unitrP (x y : R^c) : y * x = 1 /\ x * y = 1 -> x \is a unit. Proof. by case=> [yx1 xy1]; apply/unitrP; exists y. Qed. #[export] HB.instance Definition _ := NzRing_hasMulInverse.Build R^c mulrV mulVr rev_unitrP invr_out. #[export] HB.instance Definition _ := UnitRing.on R^o. End UnitRingTheory. Arguments invrK {R}. Arguments invr_inj {R} [x1 x2]. Arguments telescope_prodr_eq {R n m} f u. Lemma rev_prodrV (R : unitRingType) (I : Type) (r : seq I) (P : pred I) (E : I -> R) : (forall i, P i -> E i \is a GRing.unit) -> \prod_(i <- r | P i) (E i)^-1 = ((\prod_(i <- r | P i) (E i : R^c))^-1). Proof. move=> Eunit; symmetry. apply: (big_morph_in GRing.unit _ _ (unitr1 R^c) (@invrM _) (invr1 _)) Eunit. by move=> x y xunit; rewrite unitrMr. Qed. Section UnitRingClosedPredicates. Variables (R : unitRingType) (S : {pred R}). Definition invr_closed := {in S, forall x, x^-1 \in S}. Definition divr_2closed := {in S &, forall x y, x / y \in S}. Definition divr_closed := 1 \in S /\ divr_2closed. Definition sdivr_closed := -1 \in S /\ divr_2closed. Definition divring_closed := [/\ 1 \in S, subr_2closed S & divr_2closed]. Lemma divr_closedV : divr_closed -> invr_closed. Proof. by case=> S1 Sdiv x Sx; rewrite -[x^-1]mul1r Sdiv. Qed. Lemma divr_closedM : divr_closed -> mulr_closed S. Proof. by case=> S1 Sdiv; split=> // x y Sx Sy; rewrite -[y]invrK -[y^-1]mul1r !Sdiv. Qed. Lemma sdivr_closed_div : sdivr_closed -> divr_closed. Proof. by case=> SN1 Sdiv; split; rewrite // -(divrr (@unitrN1 _)) Sdiv. Qed. Lemma sdivr_closedM : sdivr_closed -> smulr_closed S. Proof. by move=> Sdiv; have [_ SM] := divr_closedM (sdivr_closed_div Sdiv); case: Sdiv. Qed. Lemma divring_closedBM : divring_closed -> subring_closed S. Proof. by case=> S1 SB Sdiv; split=> //; case: divr_closedM. Qed. Lemma divring_closed_div : divring_closed -> sdivr_closed. Proof. case=> S1 SB Sdiv; split; rewrite ?zmod_closedN //. exact/subring_closedB/divring_closedBM. Qed. End UnitRingClosedPredicates. Section UnitRingMorphism. Variables (R S : unitRingType) (f : {rmorphism R -> S}). Lemma rmorph_unit x : x \in unit -> f x \in unit. Proof. case/unitrP=> y [yx1 xy1]; apply/unitrP. by exists (f y); rewrite -!rmorphM // yx1 xy1 rmorph1. Qed. Lemma rmorphV : {in unit, {morph f: x / x^-1}}. Proof. move=> x Ux; rewrite /= -[(f x)^-1]mul1r. by apply: (canRL (mulrK (rmorph_unit Ux))); rewrite -rmorphM mulVr ?rmorph1. Qed. Lemma rmorph_div x y : y \in unit -> f (x / y) = f x / f y. Proof. by move=> Uy; rewrite rmorphM /= rmorphV. Qed. End UnitRingMorphism. #[short(type="comUnitRingType")] HB.structure Definition ComUnitRing := {R of ComNzRing R & UnitRing R}. Module ComUnitRingExports. Bind Scope ring_scope with ComUnitRing.sort. End ComUnitRingExports. HB.export ComUnitRingExports. (* TODO_HB: fix the name (was ComUnitRingMixin) *) HB.factory Record ComNzRing_hasMulInverse R of ComNzRing R := { unit : {pred R}; inv : R -> R; mulVx : {in unit, left_inverse 1 inv *%R}; unitPl : forall x y, y * x = 1 -> unit x; invr_out : {in [predC unit], inv =1 id} }. Module ComRing_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_hasMulInverse.Build instead.")] Notation Build R := (ComNzRing_hasMulInverse.Build R) (only parsing). End ComRing_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_hasMulInverse instead.")] Notation ComRing_hasMulInverse R := (ComNzRing_hasMulInverse R) (only parsing). HB.builders Context R of ComNzRing_hasMulInverse R. Fact mulC_mulrV : {in unit, right_inverse 1 inv *%R}. Proof. by move=> x Ux /=; rewrite mulrC mulVx. Qed. Fact mulC_unitP x y : y * x = 1 /\ x * y = 1 -> unit x. Proof. by case=> yx _; apply: unitPl yx. Qed. HB.instance Definition _ := NzRing_hasMulInverse.Build R mulVx mulC_mulrV mulC_unitP invr_out. HB.end. #[short(type="unitAlgType")] HB.structure Definition UnitAlgebra R := {V of Algebra R V & UnitRing V}. Module UnitAlgebraExports. Bind Scope ring_scope with UnitAlgebra.sort. End UnitAlgebraExports. HB.export UnitAlgebraExports. #[short(type="comUnitAlgType")] HB.structure Definition ComUnitAlgebra R := {V of ComAlgebra R V & UnitRing V}. Module ComUnitAlgebraExports. Bind Scope ring_scope with UnitAlgebra.sort. End ComUnitAlgebraExports. HB.export ComUnitAlgebraExports. Section ComUnitRingTheory. Variable R : comUnitRingType. Implicit Types x y : R. Lemma unitrM x y : (x * y \in unit) = (x \in unit) && (y \in unit). Proof. exact/unitrM_comm/mulrC. Qed. Lemma unitrPr x : reflect (exists y, x * y = 1) (x \in unit). Proof. by apply: (iffP (unitrP x)) => [[y []] | [y]]; exists y; rewrite // mulrC. Qed. Lemma mulr1_eq x y : x * y = 1 -> x^-1 = y. Proof. by move=> xy_eq1; rewrite -[LHS]mulr1 -xy_eq1; apply/mulKr/unitrPr; exists y. Qed. Lemma divr1_eq x y : x / y = 1 -> x = y. Proof. by move/mulr1_eq/invr_inj. Qed. Lemma divKr x : x \is a unit -> {in unit, involutive (fun y => x / y)}. Proof. by move=> Ux y Uy; rewrite /= invrM ?unitrV // invrK mulrC divrK. Qed. Lemma expr_div_n x y n : (x / y) ^+ n = x ^+ n / y ^+ n. Proof. by rewrite exprMn exprVn. Qed. Lemma unitr_prodP (I : eqType) (r : seq I) (P : pred I) (E : I -> R) : reflect {in r, forall i, P i -> E i \is a GRing.unit} (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. rewrite (big_morph [in unit] unitrM (@unitr1 _) ) big_all_cond. exact: 'all_implyP. Qed. Lemma prodrV (I : eqType) (r : seq I) (P : pred I) (E : I -> R) : (forall i, P i -> E i \is a GRing.unit) -> \prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1. Proof. by move=> /rev_prodrV->; rewrite rev_prodr (perm_big r)// perm_rev. Qed. (* TODO: HB.saturate *) #[export] HB.instance Definition _ := ComUnitRing.on R^c. #[export] HB.instance Definition _ := ComUnitRing.on R^o. (* /TODO *) End ComUnitRingTheory. Section UnitAlgebraTheory. Variable (R : comUnitRingType) (A : unitAlgType R). Implicit Types (k : R) (x y : A). Lemma scaler_injl : {in unit, @right_injective R A A *:%R}. Proof. move=> k Uk x1 x2 Hx1x2. by rewrite -[x1]scale1r -(mulVr Uk) -scalerA Hx1x2 scalerA mulVr // scale1r. Qed. Lemma scaler_unit k x : k \in unit -> (k *: x \in unit) = (x \in unit). Proof. move=> Uk; apply/idP/idP=> [Ukx | Ux]; apply/unitrP; last first. exists (k^-1 *: x^-1). by rewrite -!scalerAl -!scalerAr !scalerA !mulVr // !mulrV // scale1r. exists (k *: (k *: x)^-1); split. apply: (mulrI Ukx). by rewrite mulr1 mulrA -scalerAr mulrV // -scalerAl mul1r. apply: (mulIr Ukx). by rewrite mul1r -mulrA -scalerAl mulVr // -scalerAr mulr1. Qed. Lemma invrZ k x : k \in unit -> x \in unit -> (k *: x)^-1 = k^-1 *: x^-1. Proof. move=> Uk Ux; have Ukx: (k *: x \in unit) by rewrite scaler_unit. apply: (mulIr Ukx). by rewrite mulVr // -scalerAl -scalerAr scalerA !mulVr // scale1r. Qed. Section ClosedPredicates. Variables S : {pred A}. Definition divalg_closed := [/\ 1 \in S, linear_closed S & divr_2closed S]. Lemma divalg_closedBdiv : divalg_closed -> divring_closed S. Proof. by case=> S1 /linear_closedB. Qed. Lemma divalg_closedZ : divalg_closed -> subalg_closed S. Proof. by case=> S1 Slin Sdiv; split=> //; have [] := @divr_closedM A S. Qed. End ClosedPredicates. End UnitAlgebraTheory. Module ClosedExports. Notation addr_closed := nmod_closed. Notation oppr_closed := oppr_closed. Notation zmod_closed := zmod_closed. Notation mulr_closed := mulr_closed. Notation semiring_closed := semiring_closed. Notation smulr_closed := smulr_closed. Notation subring_closed := subring_closed. Notation scaler_closed := scaler_closed. Notation subsemimod_closed := subsemimod_closed. Notation linear_closed := linear_closed. Notation submod_closed := submod_closed. Notation subalg_closed := subalg_closed. Notation invr_closed := invr_closed. Notation divr_2closed := divr_2closed. Notation divr_closed := divr_closed. Notation sdivr_closed := sdivr_closed. Notation divring_closed := divring_closed. Notation divalg_closed := divalg_closed. Coercion zmod_closedD : zmod_closed >-> nmod_closed. Coercion zmod_closedN : zmod_closed >-> oppr_closed. Coercion semiring_closedD : semiring_closed >-> addr_closed. Coercion semiring_closedM : semiring_closed >-> mulr_closed. Coercion smulr_closedM : smulr_closed >-> mulr_closed. Coercion smulr_closedN : smulr_closed >-> oppr_closed. Coercion subring_closedB : subring_closed >-> zmod_closed. Coercion subring_closedM : subring_closed >-> smulr_closed. Coercion subring_closed_semi : subring_closed >-> semiring_closed. Coercion subsemimod_closedD : subsemimod_closed >-> addr_closed. Coercion subsemimod_closedZ : subsemimod_closed >-> scaler_closed. Coercion linear_closedB : linear_closed >-> subr_2closed. Coercion submod_closedB : submod_closed >-> zmod_closed. Coercion submod_closed_semi : submod_closed >-> subsemimod_closed. Coercion subalg_closedZ : subalg_closed >-> submod_closed. Coercion subalg_closedBM : subalg_closed >-> subring_closed. Coercion divr_closedV : divr_closed >-> invr_closed. Coercion divr_closedM : divr_closed >-> mulr_closed. Coercion sdivr_closed_div : sdivr_closed >-> divr_closed. Coercion sdivr_closedM : sdivr_closed >-> smulr_closed. Coercion divring_closedBM : divring_closed >-> subring_closed. Coercion divring_closed_div : divring_closed >-> sdivr_closed. Coercion divalg_closedBdiv : divalg_closed >-> divring_closed. Coercion divalg_closedZ : divalg_closed >-> subalg_closed. End ClosedExports. (* Reification of the theory of rings with units, in named style *) Section TermDef. Variable R : Type. Inductive term : Type := | Var of nat | Const of R | NatConst of nat | Add of term & term | Opp of term | NatMul of term & nat | Mul of term & term | Inv of term | Exp of term & nat. Inductive formula : Type := | Bool of bool | Equal of term & term | Unit of term | And of formula & formula | Or of formula & formula | Implies of formula & formula | Not of formula | Exists of nat & formula | Forall of nat & formula. End TermDef. Bind Scope term_scope with term. Bind Scope term_scope with formula. Arguments Add {R} t1%_T t2%_T. Arguments Opp {R} t1%_T. Arguments NatMul {R} t1%_T n%_N. Arguments Mul {R} t1%_T t2%_T. Arguments Inv {R} t1%_T. Arguments Exp {R} t1%_T n%_N. Arguments Equal {R} t1%_T t2%_T. Arguments Unit {R} t1%_T. Arguments And {R} f1%_T f2%_T. Arguments Or {R} f1%_T f2%_T. Arguments Implies {R} f1%_T f2%_T. Arguments Not {R} f1%_T. Arguments Exists {R} i%_N f1%_T. Arguments Forall {R} i%_N f1%_T. Arguments Bool {R} b. Arguments Const {R} x. Notation True := (Bool true). Notation False := (Bool false). Local Notation "''X_' i" := (Var _ i) : term_scope. Local Notation "n %:R" := (NatConst _ n) : term_scope. Local Notation "x %:T" := (Const x) : term_scope. Local Notation "0" := 0%:R%T : term_scope. Local Notation "1" := 1%:R%T : term_scope. Local Infix "+" := Add : term_scope. Local Notation "- t" := (Opp t) : term_scope. Local Notation "t - u" := (Add t (- u)) : term_scope. Local Infix "*" := Mul : term_scope. Local Infix "*+" := NatMul : term_scope. Local Notation "t ^-1" := (Inv t) : term_scope. Local Notation "t / u" := (Mul t u^-1) : term_scope. Local Infix "^+" := Exp : term_scope. Local Infix "==" := Equal : term_scope. Local Infix "/\" := And : term_scope. Local Infix "\/" := Or : term_scope. Local Infix "==>" := Implies : term_scope. Local Notation "~ f" := (Not f) : term_scope. Local Notation "x != y" := (Not (x == y)) : term_scope. Local Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope. Local Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope. Section Substitution. Variable R : Type. Fixpoint tsubst (t : term R) (s : nat * term R) := match t with | 'X_i => if i == s.1 then s.2 else t | _%:T | _%:R => t | t1 + t2 => tsubst t1 s + tsubst t2 s | - t1 => - tsubst t1 s | t1 *+ n => tsubst t1 s *+ n | t1 * t2 => tsubst t1 s * tsubst t2 s | t1^-1 => (tsubst t1 s)^-1 | t1 ^+ n => tsubst t1 s ^+ n end%T. Fixpoint fsubst (f : formula R) (s : nat * term R) := match f with | Bool _ => f | t1 == t2 => tsubst t1 s == tsubst t2 s | Unit t1 => Unit (tsubst t1 s) | f1 /\ f2 => fsubst f1 s /\ fsubst f2 s | f1 \/ f2 => fsubst f1 s \/ fsubst f2 s | f1 ==> f2 => fsubst f1 s ==> fsubst f2 s | ~ f1 => ~ fsubst f1 s | ('exists 'X_i, f1) => 'exists 'X_i, if i == s.1 then f1 else fsubst f1 s | ('forall 'X_i, f1) => 'forall 'X_i, if i == s.1 then f1 else fsubst f1 s end%T. End Substitution. Section EvalTerm. Variable R : unitRingType. (* Evaluation of a reified term into R a ring with units *) Fixpoint eval (e : seq R) (t : term R) {struct t} : R := match t with | ('X_i)%T => e`_i | (x%:T)%T => x | (n%:R)%T => n%:R | (t1 + t2)%T => eval e t1 + eval e t2 | (- t1)%T => - eval e t1 | (t1 *+ n)%T => eval e t1 *+ n | (t1 * t2)%T => eval e t1 * eval e t2 | t1^-1%T => (eval e t1)^-1 | (t1 ^+ n)%T => eval e t1 ^+ n end. Definition same_env (e e' : seq R) := nth 0 e =1 nth 0 e'. Lemma eq_eval e e' t : same_env e e' -> eval e t = eval e' t. Proof. by move=> eq_e; elim: t => //= t1 -> // t2 ->. Qed. Lemma eval_tsubst e t s : eval e (tsubst t s) = eval (set_nth 0 e s.1 (eval e s.2)) t. Proof. case: s => i u; elim: t => //=; do 2?[move=> ? -> //] => j. by rewrite nth_set_nth /=; case: (_ == _). Qed. (* Evaluation of a reified formula *) Fixpoint holds (e : seq R) (f : formula R) {struct f} : Prop := match f with | Bool b => b | (t1 == t2)%T => eval e t1 = eval e t2 | Unit t1 => eval e t1 \in unit | (f1 /\ f2)%T => holds e f1 /\ holds e f2 | (f1 \/ f2)%T => holds e f1 \/ holds e f2 | (f1 ==> f2)%T => holds e f1 -> holds e f2 | (~ f1)%T => ~ holds e f1 | ('exists 'X_i, f1)%T => exists x, holds (set_nth 0 e i x) f1 | ('forall 'X_i, f1)%T => forall x, holds (set_nth 0 e i x) f1 end. Lemma same_env_sym e e' : same_env e e' -> same_env e' e. Proof. exact: fsym. Qed. (* Extensionality of formula evaluation *) Lemma eq_holds e e' f : same_env e e' -> holds e f -> holds e' f. Proof. pose sv := set_nth (0 : R). have eq_i i v e1 e2: same_env e1 e2 -> same_env (sv e1 i v) (sv e2 i v). by move=> eq_e j; rewrite !nth_set_nth /= eq_e. elim: f e e' => //=. - by move=> t1 t2 e e' eq_e; rewrite !(eq_eval _ eq_e). - by move=> t e e' eq_e; rewrite (eq_eval _ eq_e). - by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto. - by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto. - by move=> f1 IH1 f2 IH2 e e' eq_e f12; move/IH1: (same_env_sym eq_e); eauto. - by move=> f1 IH1 e e'; move/same_env_sym; move/IH1; tauto. - by move=> i f1 IH1 e e'; move/(eq_i i)=> eq_e [x f_ex]; exists x; eauto. by move=> i f1 IH1 e e'; move/(eq_i i); eauto. Qed. (* Evaluation and substitution by a constant *) Lemma holds_fsubst e f i v : holds e (fsubst f (i, v%:T)%T) <-> holds (set_nth 0 e i v) f. Proof. elim: f e => //=; do [ by move=> *; rewrite !eval_tsubst | move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto | move=> f IHf e; move: (IHf e); tauto | move=> j f IHf e]. - case eq_ji: (j == i); first rewrite (eqP eq_ji). by split=> [] [x f_x]; exists x; rewrite set_set_nth eqxx in f_x *. split=> [] [x f_x]; exists x; move: f_x; rewrite set_set_nth eq_sym eq_ji; have:= IHf (set_nth 0 e j x); tauto. case eq_ji: (j == i); first rewrite (eqP eq_ji). by split=> [] f_ x; move: (f_ x); rewrite set_set_nth eqxx. split=> [] f_ x; move: (IHf (set_nth 0 e j x)) (f_ x); by rewrite set_set_nth 1?[i == j]eq_sym eq_ji; tauto. Qed. (* Boolean test selecting terms in the language of rings *) Fixpoint rterm (t : term R) := match t with | _^-1 => false | t1 + t2 | t1 * t2 => rterm t1 && rterm t2 | - t1 | t1 *+ _ | t1 ^+ _ => rterm t1 | _ => true end%T. (* Boolean test selecting formulas in the theory of rings *) Fixpoint rformula (f : formula R) := match f with | Bool _ => true | t1 == t2 => rterm t1 && rterm t2 | Unit t1 => false | f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => rformula f1 && rformula f2 | ~ f1 | ('exists 'X__, f1) | ('forall 'X__, f1) => rformula f1 end%T. (* Upper bound of the names used in a term *) Fixpoint ub_var (t : term R) := match t with | 'X_i => i.+1 | t1 + t2 | t1 * t2 => maxn (ub_var t1) (ub_var t2) | - t1 | t1 *+ _ | t1 ^+ _ | t1^-1 => ub_var t1 | _ => 0%N end%T. (* Replaces inverses in the term t by fresh variables, accumulating the *) (* substitution. *) Fixpoint to_rterm (t : term R) (r : seq (term R)) (n : nat) {struct t} := match t with | t1^-1 => let: (t1', r1) := to_rterm t1 r n in ('X_(n + size r1), rcons r1 t1') | t1 + t2 => let: (t1', r1) := to_rterm t1 r n in let: (t2', r2) := to_rterm t2 r1 n in (t1' + t2', r2) | - t1 => let: (t1', r1) := to_rterm t1 r n in (- t1', r1) | t1 *+ m => let: (t1', r1) := to_rterm t1 r n in (t1' *+ m, r1) | t1 * t2 => let: (t1', r1) := to_rterm t1 r n in let: (t2', r2) := to_rterm t2 r1 n in (Mul t1' t2', r2) | t1 ^+ m => let: (t1', r1) := to_rterm t1 r n in (t1' ^+ m, r1) | _ => (t, r) end%T. Lemma to_rterm_id t r n : rterm t -> to_rterm t r n = (t, r). Proof. elim: t r n => //. - by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2. - by move=> t IHt r n /= rt; rewrite {}IHt. - by move=> t IHt r n m /= rt; rewrite {}IHt. - by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2. - by move=> t IHt r n m /= rt; rewrite {}IHt. Qed. (* A ring formula stating that t1 is equal to 0 in the ring theory. *) (* Also applies to non commutative rings. *) Definition eq0_rform t1 := let m := ub_var t1 in let: (t1', r1) := to_rterm t1 [::] m in let fix loop r i := match r with | [::] => t1' == 0 | t :: r' => let f := 'X_i * t == 1 /\ t * 'X_i == 1 in 'forall 'X_i, (f \/ 'X_i == t /\ ~ ('exists 'X_i, f)) ==> loop r' i.+1 end%T in loop r1 m. (* Transformation of a formula in the theory of rings with units into an *) (* equivalent formula in the sub-theory of rings. *) Fixpoint to_rform f := match f with | Bool b => f | t1 == t2 => eq0_rform (t1 - t2) | Unit t1 => eq0_rform (t1 * t1^-1 - 1) | f1 /\ f2 => to_rform f1 /\ to_rform f2 | f1 \/ f2 => to_rform f1 \/ to_rform f2 | f1 ==> f2 => to_rform f1 ==> to_rform f2 | ~ f1 => ~ to_rform f1 | ('exists 'X_i, f1) => 'exists 'X_i, to_rform f1 | ('forall 'X_i, f1) => 'forall 'X_i, to_rform f1 end%T. (* The transformation gives a ring formula. *) Lemma to_rform_rformula f : rformula (to_rform f). Proof. suffices eq0_ring t1: rformula (eq0_rform t1) by elim: f => //= => f1 ->. rewrite /eq0_rform; move: (ub_var t1) => m; set tr := _ m. suffices: all rterm (tr.1 :: tr.2). case: tr => {}t1 r /= /andP[t1_r]. by elim: r m => [|t r IHr] m; rewrite /= ?andbT // => /andP[->]; apply: IHr. have: all rterm [::] by []. rewrite {}/tr; elim: t1 [::] => //=. - move=> t1 IHt1 t2 IHt2 r. move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r]. move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r]. by rewrite t1_r t2_r. - by move=> t1 IHt1 r /IHt1; case: to_rterm. - by move=> t1 IHt1 n r /IHt1; case: to_rterm. - move=> t1 IHt1 t2 IHt2 r. move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r]. move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r]. by rewrite t1_r t2_r. - move=> t1 IHt1 r. by move/IHt1; case: to_rterm => {r IHt1}t1 r /=; rewrite all_rcons. - by move=> t1 IHt1 n r /IHt1; case: to_rterm. Qed. (* Correctness of the transformation. *) Lemma to_rformP e f : holds e (to_rform f) <-> holds e f. Proof. suffices{e f} equal0_equiv e t1 t2: holds e (eq0_rform (t1 - t2)) <-> (eval e t1 == eval e t2). - elim: f e => /=; try tauto. + move=> t1 t2 e. by split; [move/equal0_equiv/eqP | move/eqP/equal0_equiv]. + by move=> t1 e; rewrite unitrE; apply: equal0_equiv. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 e; move: (IHf1 e); tauto. + by move=> n f1 IHf1 e; split=> [] [x] /IHf1; exists x. + by move=> n f1 IHf1 e; split=> Hx x; apply/IHf1. rewrite -(add0r (eval e t2)) -(can2_eq (subrK _) (addrK _)). rewrite -/(eval e (t1 - t2)); move: (t1 - t2)%T => {t1 t2} t. have sub_var_tsubst s t0: s.1 >= ub_var t0 -> tsubst t0 s = t0. elim: t0 {t} => //=. - by move=> n; case: ltngtP. - by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->]. - by move=> t1 IHt1 /IHt1->. - by move=> t1 IHt1 n /IHt1->. - by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->]. - by move=> t1 IHt1 /IHt1->. - by move=> t1 IHt1 n /IHt1->. pose fix rsub t' m r : term R := if r is u :: r' then tsubst (rsub t' m.+1 r') (m, u^-1)%T else t'. pose fix ub_sub m r : Prop := if r is u :: r' then ub_var u <= m /\ ub_sub m.+1 r' else true. suffices{t} rsub_to_r t r0 m: m >= ub_var t -> ub_sub m r0 -> let: (t', r) := to_rterm t r0 m in [/\ take (size r0) r = r0, ub_var t' <= m + size r, ub_sub m r & rsub t' m r = t]. - have:= rsub_to_r t [::] _ (leqnn _); rewrite /eq0_rform. case: (to_rterm _ _ _) => [t1' r1] [//|_ _ ub_r1 def_t]. rewrite -{2}def_t {def_t}. elim: r1 (ub_var t) e ub_r1 => [|u r1 IHr1] m e /= => [_|[ub_u ub_r1]]. by split=> /eqP. rewrite eval_tsubst /=; set y := eval e u; split=> t_eq0. apply/IHr1=> //; apply: t_eq0. rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)). rewrite sub_var_tsubst //= -/y. case Uy: (y \in unit); [left | right]; first by rewrite mulVr ?divrr. split=> [|[z]]; first by rewrite invr_out ?Uy. rewrite nth_set_nth /= eqxx. rewrite -!(eval_tsubst _ _ (m, Const _)) !sub_var_tsubst // -/y => yz1. by case/unitrP: Uy; exists z. move=> x def_x; apply/IHr1=> //; suff ->: x = y^-1 by []; move: def_x. rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)). rewrite sub_var_tsubst //= -/y; case=> [[xy1 yx1] | [xy nUy]]. by rewrite -[y^-1]mul1r -[1]xy1 mulrK //; apply/unitrP; exists x. rewrite invr_out //; apply/unitrP=> [[z yz1]]; case: nUy; exists z. rewrite nth_set_nth /= eqxx -!(eval_tsubst _ _ (m, _%:T)%T). by rewrite !sub_var_tsubst. have rsub_id r t0 n: ub_var t0 <= n -> rsub t0 n r = t0. by elim: r n => //= t1 r IHr n let0n; rewrite IHr ?sub_var_tsubst ?leqW. have rsub_acc r s t1 m1: ub_var t1 <= m1 + size r -> rsub t1 m1 (r ++ s) = rsub t1 m1 r. elim: r t1 m1 => [|t1 r IHr] t2 m1 /=; first by rewrite addn0; apply: rsub_id. by move=> letmr; rewrite IHr ?addSnnS. elim: t r0 m => /=; try do [ by move=> n r m hlt hub; rewrite take_size (ltn_addr _ hlt) rsub_id | by move=> n r m hlt hub; rewrite leq0n take_size rsub_id | move=> t1 IHt1 t2 IHt2 r m; rewrite geq_max; case/andP=> hub1 hub2 hmr; case: to_rterm {hub1 hmr}(IHt1 r m hub1 hmr) => t1' r1; case=> htake1 hub1' hsub1 <-; case: to_rterm {IHt2 hub2 hsub1}(IHt2 r1 m hub2 hsub1) => t2' r2 /=; rewrite geq_max; case=> htake2 -> hsub2 /= <-; rewrite -{1 2}(cat_take_drop (size r1) r2) htake2; set r3 := drop _ _; rewrite size_cat addnA (leq_trans _ (leq_addr _ _)) //; split=> {hsub2}//; first by [rewrite takel_cat // -htake1 size_take geq_min leqnn orbT]; rewrite -(rsub_acc r1 r3 t1') {hub1'}// -{htake1}htake2 {r3}cat_take_drop; by elim: r2 m => //= u r2 IHr2 m; rewrite IHr2 | do [ move=> t1 IHt1 r m; do 2!move=> /IHt1{}IHt1 | move=> t1 IHt1 n r m; do 2!move=> /IHt1{}IHt1]; case: to_rterm IHt1 => t1' r1 [-> -> hsub1 <-]; split=> {hsub1}//; by elim: r1 m => //= u r1 IHr1 m; rewrite IHr1]. move=> t1 IH r m letm /IH {IH} /(_ letm) {letm}. case: to_rterm => t1' r1 /= [def_r ub_t1' ub_r1 <-]. rewrite size_rcons addnS leqnn -{1}cats1 takel_cat ?def_r; last first. by rewrite -def_r size_take geq_min leqnn orbT. elim: r1 m ub_r1 ub_t1' {def_r} => /= [|u r1 IHr1] m => [_|[->]]. by rewrite addn0 eqxx. by rewrite -addSnnS => /IHr1 IH /IH[_ _ ub_r1 ->]. Qed. (* Boolean test selecting formulas which describe a constructible set, *) (* i.e. formulas without quantifiers. *) (* The quantifier elimination check. *) Fixpoint qf_form (f : formula R) := match f with | Bool _ | _ == _ | Unit _ => true | f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => qf_form f1 && qf_form f2 | ~ f1 => qf_form f1 | _ => false end%T. (* Boolean holds predicate for quantifier free formulas *) Definition qf_eval e := fix loop (f : formula R) : bool := match f with | Bool b => b | t1 == t2 => (eval e t1 == eval e t2)%bool | Unit t1 => eval e t1 \in unit | f1 /\ f2 => loop f1 && loop f2 | f1 \/ f2 => loop f1 || loop f2 | f1 ==> f2 => (loop f1 ==> loop f2)%bool | ~ f1 => ~~ loop f1 |_ => false end%T. (* qf_eval is equivalent to holds *) Lemma qf_evalP e f : qf_form f -> reflect (holds e f) (qf_eval e f). Proof. elim: f => //=; try by move=> *; apply: idP. - by move=> t1 t2 _; apply: eqP. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by right; case. by case/IHf2; [left | right; case]. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1F]; first by do 2 left. by case/IHf2; [left; right | right; case]. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by left. by case/IHf2; [left | right; move/(_ f1T)]. by move=> f1 IHf1 /IHf1[]; [right | left]. Qed. Implicit Type bc : seq (term R) * seq (term R). (* Quantifier-free formula are normalized into DNF. A DNF is *) (* represented by the type seq (seq (term R) * seq (term R)), where we *) (* separate positive and negative literals *) (* DNF preserving conjunction *) Definition and_dnf bcs1 bcs2 := \big[cat/nil]_(bc1 <- bcs1) map (fun bc2 => (bc1.1 ++ bc2.1, bc1.2 ++ bc2.2)) bcs2. (* Computes a DNF from a qf ring formula *) Fixpoint qf_to_dnf (f : formula R) (neg : bool) {struct f} := match f with | Bool b => if b (+) neg then [:: ([::], [::])] else [::] | t1 == t2 => [:: if neg then ([::], [:: t1 - t2]) else ([:: t1 - t2], [::])] | f1 /\ f2 => (if neg then cat else and_dnf) [rec f1, neg] [rec f2, neg] | f1 \/ f2 => (if neg then and_dnf else cat) [rec f1, neg] [rec f2, neg] | f1 ==> f2 => (if neg then and_dnf else cat) [rec f1, ~~ neg] [rec f2, neg] | ~ f1 => [rec f1, ~~ neg] | _ => if neg then [:: ([::], [::])] else [::] end%T where "[ 'rec' f , neg ]" := (qf_to_dnf f neg). (* Conversely, transforms a DNF into a formula *) Definition dnf_to_form := let pos_lit t := And (t == 0) in let neg_lit t := And (t != 0) in let cls bc := Or (foldr pos_lit True bc.1 /\ foldr neg_lit True bc.2) in foldr cls False. (* Catenation of dnf is the Or of formulas *) Lemma cat_dnfP e bcs1 bcs2 : qf_eval e (dnf_to_form (bcs1 ++ bcs2)) = qf_eval e (dnf_to_form bcs1 \/ dnf_to_form bcs2). Proof. by elim: bcs1 => //= bc1 bcs1 IH1; rewrite -orbA; congr orb; rewrite IH1. Qed. (* and_dnf is the And of formulas *) Lemma and_dnfP e bcs1 bcs2 : qf_eval e (dnf_to_form (and_dnf bcs1 bcs2)) = qf_eval e (dnf_to_form bcs1 /\ dnf_to_form bcs2). Proof. elim: bcs1 => [|bc1 bcs1 IH1] /=; first by rewrite /and_dnf big_nil. rewrite /and_dnf big_cons -/(and_dnf bcs1 bcs2) cat_dnfP /=. rewrite {}IH1 /= andb_orl; congr orb. elim: bcs2 bc1 {bcs1} => [|bc2 bcs2 IH] bc1 /=; first by rewrite andbF. rewrite {}IH /= andb_orr; congr orb => {bcs2}. suffices aux (l1 l2 : seq (term R)) g : let redg := foldr (And \o g) True in qf_eval e (redg (l1 ++ l2)) = qf_eval e (redg l1 /\ redg l2)%T. + by rewrite 2!aux /= 2!andbA -andbA -andbCA andbA andbCA andbA. by elim: l1 => [| t1 l1 IHl1] //=; rewrite -andbA IHl1. Qed. Lemma qf_to_dnfP e : let qev f b := qf_eval e (dnf_to_form (qf_to_dnf f b)) in forall f, qf_form f && rformula f -> qev f false = qf_eval e f. Proof. move=> qev; have qevT f: qev f true = ~~ qev f false. rewrite {}/qev; elim: f => //=; do [by case | move=> f1 IH1 f2 IH2 | ]. - by move=> t1 t2; rewrite !andbT !orbF. - by rewrite and_dnfP cat_dnfP negb_and -IH1 -IH2. - by rewrite and_dnfP cat_dnfP negb_or -IH1 -IH2. - by rewrite and_dnfP cat_dnfP /= negb_or IH1 -IH2 negbK. by move=> t1 ->; rewrite negbK. rewrite /qev; elim=> //=; first by case. - by move=> t1 t2 _; rewrite subr_eq0 !andbT orbF. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite and_dnfP /= => /IH1-> /IH2->. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite cat_dnfP /= => /IH1-> => /IH2->. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite cat_dnfP /= [qf_eval _ _]qevT -implybE => /IH1 <- /IH2->. by move=> f1 IH1 /IH1 <-; rewrite -qevT. Qed. Lemma dnf_to_form_qf bcs : qf_form (dnf_to_form bcs). Proof. by elim: bcs => //= [[clT clF] _ ->] /=; elim: clT => //=; elim: clF. Qed. Definition dnf_rterm cl := all rterm cl.1 && all rterm cl.2. Lemma qf_to_dnf_rterm f b : rformula f -> all dnf_rterm (qf_to_dnf f b). Proof. set ok := all dnf_rterm. have cat_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (bcs1 ++ bcs2). by move=> ok1 ok2; rewrite [ok _]all_cat; apply/andP. have and_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (and_dnf bcs1 bcs2). rewrite /and_dnf unlock; elim: bcs1 => //= cl1 bcs1 IH1; rewrite -andbA. case/and3P=> ok11 ok12 ok1 ok2; rewrite cat_ok ?{}IH1 {bcs1 ok1}//. elim: bcs2 ok2 => //= cl2 bcs2 IH2 /andP[ok2 /IH2->]. by rewrite /dnf_rterm !all_cat ok11 ok12 /= !andbT. elim: f b => //=; [ by do 2!case | | | | | by auto | | ]; try by repeat case/andP || intro; case: ifP; auto. by rewrite /dnf_rterm => ?? [] /= ->. Qed. Lemma dnf_to_rform bcs : rformula (dnf_to_form bcs) = all dnf_rterm bcs. Proof. elim: bcs => //= [[cl1 cl2] bcs ->]; rewrite {2}/dnf_rterm /=; congr (_ && _). by (congr andb; [elim: cl1 | elim: cl2]) => //= t cl ->; rewrite andbT. Qed. Section If. Variables (pred_f then_f else_f : formula R). Definition If := (pred_f /\ then_f \/ ~ pred_f /\ else_f)%T. Lemma If_form_qf : qf_form pred_f -> qf_form then_f -> qf_form else_f -> qf_form If. Proof. by move=> /= -> -> ->. Qed. Lemma If_form_rf : rformula pred_f -> rformula then_f -> rformula else_f -> rformula If. Proof. by move=> /= -> -> ->. Qed. Lemma eval_If e : let ev := qf_eval e in ev If = (if ev pred_f then ev then_f else ev else_f). Proof. by rewrite /=; case: ifP => _; rewrite ?orbF. Qed. End If. Section Pick. Variables (I : finType) (pred_f then_f : I -> formula R) (else_f : formula R). Definition Pick := \big[Or/False]_(p : {ffun pred I}) ((\big[And/True]_i (if p i then pred_f i else ~ pred_f i)) /\ (if pick p is Some i then then_f i else else_f))%T. Lemma Pick_form_qf : (forall i, qf_form (pred_f i)) -> (forall i, qf_form (then_f i)) -> qf_form else_f -> qf_form Pick. Proof. move=> qfp qft qfe; have mA := (big_morph qf_form) true andb. rewrite mA // big1 //= => p _. rewrite mA // big1 => [|i _]; first by case: pick. by rewrite fun_if if_same /= qfp. Qed. Lemma eval_Pick e (qev := qf_eval e) : let P i := qev (pred_f i) in qev Pick = (if pick P is Some i then qev (then_f i) else qev else_f). Proof. move=> P; rewrite ((big_morph qev) false orb) //= big_orE /=. apply/existsP/idP=> [[p] | true_at_P]. rewrite ((big_morph qev) true andb) //= big_andE /=. case/andP=> /forallP-eq_p_P. rewrite (@eq_pick _ _ P) => [|i]; first by case: pick. by move/(_ i): eq_p_P => /=; case: (p i) => //= /negPf. exists [ffun i => P i] => /=; apply/andP; split. rewrite ((big_morph qev) true andb) //= big_andE /=. by apply/forallP=> i; rewrite /= ffunE; case Pi: (P i) => //=; apply: negbT. rewrite (@eq_pick _ _ P) => [|i]; first by case: pick true_at_P. by rewrite ffunE. Qed. End Pick. Section MultiQuant. Variable f : formula R. Implicit Types (I : seq nat) (e : seq R). Lemma foldExistsP I e : (exists2 e', {in [predC I], same_env e e'} & holds e' f) <-> holds e (foldr Exists f I). Proof. elim: I e => /= [|i I IHi] e. by split=> [[e' eq_e] |]; [apply: eq_holds => i; rewrite eq_e | exists e]. split=> [[e' eq_e f_e'] | [x]]; last set e_x := set_nth 0 e i x. exists e'`_i; apply/IHi; exists e' => // j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->. case/IHi=> e' eq_e f_e'; exists e' => // j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP. Qed. Lemma foldForallP I e : (forall e', {in [predC I], same_env e e'} -> holds e' f) <-> holds e (foldr Forall f I). Proof. elim: I e => /= [|i I IHi] e. by split=> [|f_e e' eq_e]; [apply | apply: eq_holds f_e => i; rewrite eq_e]. split=> [f_e' x | f_e e' eq_e]; first set e_x := set_nth 0 e i x. apply/IHi=> e' eq_e; apply: f_e' => j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP. move/IHi: (f_e e'`_i); apply=> j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->. Qed. End MultiQuant. End EvalTerm. Prenex Implicits dnf_rterm. Definition integral_domain_axiom (R : pzRingType) := forall x y : R, x * y = 0 -> (x == 0) || (y == 0). HB.mixin Record ComUnitRing_isIntegral R of ComUnitRing R := { mulf_eq0_subproof : integral_domain_axiom R; }. #[mathcomp(axiom="integral_domain_axiom"), short(type="idomainType")] HB.structure Definition IntegralDomain := {R of ComUnitRing_isIntegral R & ComUnitRing R}. Module IntegralDomainExports. Bind Scope ring_scope with IntegralDomain.sort. End IntegralDomainExports. HB.export IntegralDomainExports. Section IntegralDomainTheory. Variable R : idomainType. Implicit Types x y : R. Lemma mulf_eq0 x y : (x * y == 0) = (x == 0) || (y == 0). Proof. apply/eqP/idP; first exact: mulf_eq0_subproof. by case/pred2P=> ->; rewrite (mulr0, mul0r). Qed. Lemma prodf_eq0 (I : finType) (P : pred I) (F : I -> R) : reflect (exists2 i, P i & (F i == 0)) (\prod_(i | P i) F i == 0). Proof. apply: (iffP idP) => [|[i Pi /eqP Fi0]]; last first. by rewrite (bigD1 i) //= Fi0 mul0r. elim: (index_enum _) => [|i r IHr]; first by rewrite big_nil oner_eq0. rewrite big_cons /=; have [Pi | _] := ifP; last exact: IHr. by rewrite mulf_eq0; case/orP=> // Fi0; exists i. Qed. Lemma prodf_seq_eq0 I r (P : pred I) (F : I -> R) : (\prod_(i <- r | P i) F i == 0) = has (fun i => P i && (F i == 0)) r. Proof. by rewrite (big_morph _ mulf_eq0 (oner_eq0 _)) big_has_cond. Qed. Lemma mulf_neq0 x y : x != 0 -> y != 0 -> x * y != 0. Proof. by move=> x0 y0; rewrite mulf_eq0; apply/norP. Qed. Lemma prodf_neq0 (I : finType) (P : pred I) (F : I -> R) : reflect (forall i, P i -> (F i != 0)) (\prod_(i | P i) F i != 0). Proof. by rewrite (sameP (prodf_eq0 _ _) exists_inP); apply: exists_inPn. Qed. Lemma prodf_seq_neq0 I r (P : pred I) (F : I -> R) : (\prod_(i <- r | P i) F i != 0) = all (fun i => P i ==> (F i != 0)) r. Proof. rewrite prodf_seq_eq0 -all_predC; apply: eq_all => i /=. by rewrite implybE negb_and. Qed. Lemma expf_eq0 x n : (x ^+ n == 0) = (n > 0) && (x == 0). Proof. elim: n => [|n IHn]; first by rewrite oner_eq0. by rewrite exprS mulf_eq0 IHn andKb. Qed. Lemma sqrf_eq0 x : (x ^+ 2 == 0) = (x == 0). Proof. exact: expf_eq0. Qed. Lemma expf_neq0 x m : x != 0 -> x ^+ m != 0. Proof. by move=> x_nz; rewrite expf_eq0; apply/nandP; right. Qed. Lemma natf_neq0_pchar n : (n%:R != 0 :> R) = (pchar R)^'.-nat n. Proof. have [-> | /prod_prime_decomp->] := posnP n; first by rewrite eqxx. rewrite !big_seq; elim/big_rec: _ => [|[p e] s /=]; first by rewrite oner_eq0. case/mem_prime_decomp=> p_pr _ _; rewrite pnatM pnatX eqn0Ngt orbC => <-. by rewrite natrM natrX mulf_eq0 expf_eq0 negb_or negb_and pnatE ?inE p_pr. Qed. Lemma natf0_pchar n : n > 0 -> n%:R == 0 :> R -> exists p, p \in pchar R. Proof. move=> n_gt0 nR_0; exists (pdiv n`_(pchar R)). apply: pnatP (pdiv_dvd _); rewrite ?part_pnat // ?pdiv_prime //. by rewrite ltn_neqAle eq_sym partn_eq1 // -natf_neq0_pchar nR_0 /=. Qed. Lemma pcharf'_nat n : (pchar R)^'.-nat n = (n%:R != 0 :> R). Proof. have [-> | n_gt0] := posnP n; first by rewrite eqxx. apply/idP/idP => [|nz_n]; last first. by apply/pnatP=> // p p_pr p_dvd_n; apply: contra nz_n => /dvdn_pcharf <-. apply: contraL => n0; have [// | p pcharRp] := natf0_pchar _ n0. have [p_pr _] := andP pcharRp; rewrite (eq_pnat _ (eq_negn (pcharf_eq pcharRp))). by rewrite p'natE // (dvdn_pcharf pcharRp) n0. Qed. Lemma pcharf0P : pchar R =i pred0 <-> (forall n, (n%:R == 0 :> R) = (n == 0)%N). Proof. split=> pcharF0 n; last by rewrite !inE pcharF0 andbC; case: eqP => // ->. have [-> | n_gt0] := posnP; first exact: eqxx. by apply/negP; case/natf0_pchar=> // p; rewrite pcharF0. Qed. Lemma eqf_sqr x y : (x ^+ 2 == y ^+ 2) = (x == y) || (x == - y). Proof. by rewrite -subr_eq0 subr_sqr mulf_eq0 subr_eq0 addr_eq0. Qed. Lemma mulfI x : x != 0 -> injective ( *%R x). Proof. move=> nz_x y z; apply: contra_eq => neq_yz. by rewrite -subr_eq0 -mulrBr mulf_neq0 ?subr_eq0. Qed. Lemma mulIf x : x != 0 -> injective ( *%R^~ x). Proof. by move=> nz_x y z; rewrite -!(mulrC x); apply: mulfI. Qed. Lemma divfI x : x != 0 -> injective (fun y => x / y). Proof. by move/mulfI/inj_comp; apply; apply: invr_inj. Qed. Lemma divIf y : y != 0 -> injective (fun x => x / y). Proof. by rewrite -invr_eq0; apply: mulIf. Qed. Lemma sqrf_eq1 x : (x ^+ 2 == 1) = (x == 1) || (x == -1). Proof. by rewrite -subr_eq0 subr_sqr_1 mulf_eq0 subr_eq0 addr_eq0. Qed. Lemma expfS_eq1 x n : (x ^+ n.+1 == 1) = (x == 1) || (\sum_(i < n.+1) x ^+ i == 0). Proof. by rewrite -![_ == 1]subr_eq0 subrX1 mulf_eq0. Qed. Lemma lregP x : reflect (lreg x) (x != 0). Proof. by apply: (iffP idP) => [/mulfI | /lreg_neq0]. Qed. Lemma rregP x : reflect (rreg x) (x != 0). Proof. by apply: (iffP idP) => [/mulIf | /rreg_neq0]. Qed. #[export] HB.instance Definition _ := IntegralDomain.on R^o. End IntegralDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")] Notation natf_neq0 := natf_neq0_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")] Notation natf0_char := natf0_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")] Notation charf'_nat := pcharf'_nat (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")] Notation charf0P := pcharf0P (only parsing). Arguments lregP {R x}. Arguments rregP {R x}. Definition field_axiom (R : unitRingType) := forall x : R, x != 0 -> x \in unit. HB.mixin Record UnitRing_isField R of UnitRing R := { fieldP : field_axiom R; }. #[mathcomp(axiom="field_axiom"), short(type="fieldType")] HB.structure Definition Field := { R of IntegralDomain R & UnitRing_isField R }. Module FieldExports. Bind Scope ring_scope with Field.sort. End FieldExports. HB.export FieldExports. #[export] HB.instance Definition regular_field (F : fieldType) := Field.on F^o. Lemma IdomainMixin (R : unitRingType): Field.axiom R -> IntegralDomain.axiom R. Proof. move=> m x y xy0; apply/norP=> [[]] /m Ux /m. by rewrite -(unitrMr _ Ux) xy0 unitr0. Qed. HB.factory Record ComUnitRing_isField R of ComUnitRing R := { fieldP : field_axiom R; }. HB.builders Context R of ComUnitRing_isField R. HB.instance Definition _ := ComUnitRing_isIntegral.Build R (IdomainMixin fieldP). HB.instance Definition _ := UnitRing_isField.Build R fieldP. HB.end. HB.factory Record ComNzRing_isField R of ComNzRing R := { inv : R -> R; mulVf : forall x, x != 0 -> inv x * x = 1; invr0 : inv 0 = 0; }. Module ComRing_isField. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_isField.Build instead.")] Notation Build R := (ComNzRing_isField.Build R) (only parsing). End ComRing_isField. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_isField instead.")] Notation ComRing_isField R := (ComNzRing_isField R) (only parsing). HB.builders Context R of ComNzRing_isField R. Fact intro_unit (x y : R) : y * x = 1 -> x != 0. Proof. move=> yx1; apply: contraNneq (@oner_neq0 R) => x0. by rewrite -yx1 x0 mulr0. Qed. Fact inv_out : {in predC (predC1 0), inv =1 id}. Proof. by move=> x /negbNE/eqP->; exact: invr0. Qed. HB.instance Definition _ : ComNzRing_hasMulInverse R := ComNzRing_hasMulInverse.Build R mulVf intro_unit inv_out. HB.instance Definition _ : ComUnitRing_isField R := ComUnitRing_isField.Build R (fun x x_neq_0 => x_neq_0). HB.end. Section FieldTheory. Variable F : fieldType. Implicit Types x y : F. Lemma unitfE x : (x \in unit) = (x != 0). Proof. by apply/idP/idP=> [/(memPn _)-> | /fieldP]; rewrite ?unitr0. Qed. Lemma mulVf x : x != 0 -> x^-1 * x = 1. Proof. by rewrite -unitfE; apply: mulVr. Qed. Lemma divff x : x != 0 -> x / x = 1. Proof. by rewrite -unitfE; apply: divrr. Qed. Definition mulfV := divff. Lemma mulKf x : x != 0 -> cancel ( *%R x) ( *%R x^-1). Proof. by rewrite -unitfE; apply: mulKr. Qed. Lemma mulVKf x : x != 0 -> cancel ( *%R x^-1) ( *%R x). Proof. by rewrite -unitfE; apply: mulVKr. Qed. Lemma mulfK x : x != 0 -> cancel ( *%R^~ x) ( *%R^~ x^-1). Proof. by rewrite -unitfE; apply: mulrK. Qed. Lemma mulfVK x : x != 0 -> cancel ( *%R^~ x^-1) ( *%R^~ x). Proof. by rewrite -unitfE; apply: divrK. Qed. Definition divfK := mulfVK. Lemma invfM : {morph @inv F : x y / x * y}. Proof. move=> x y; have [->|nzx] := eqVneq x 0; first by rewrite !(mul0r, invr0). have [->|nzy] := eqVneq y 0; first by rewrite !(mulr0, invr0). by rewrite mulrC invrM ?unitfE. Qed. Lemma invf_div x y : (x / y)^-1 = y / x. Proof. by rewrite invfM invrK mulrC. Qed. Lemma divKf x : x != 0 -> involutive (fun y => x / y). Proof. by move=> nz_x y; rewrite invf_div mulrC divfK. Qed. Lemma expfB_cond m n x : (x == 0) + n <= m -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. move/subnK=> <-; rewrite addnA addnK !exprD. have [-> | nz_x] := eqVneq; first by rewrite !mulr0 !mul0r. by rewrite mulfK ?expf_neq0. Qed. Lemma expfB m n x : n < m -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. by move=> lt_n_m; apply: expfB_cond; case: eqP => // _; apply: ltnW. Qed. Lemma prodfV I r (P : pred I) (E : I -> F) : \prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1. Proof. by rewrite (big_morph _ invfM (invr1 F)). Qed. Lemma prodf_div I r (P : pred I) (E D : I -> F) : \prod_(i <- r | P i) (E i / D i) = \prod_(i <- r | P i) E i / \prod_(i <- r | P i) D i. Proof. by rewrite big_split prodfV. Qed. Lemma telescope_prodf n m (f : nat -> F) : (forall k, n < k < m -> f k != 0) -> n < m -> \prod_(n <= k < m) (f k.+1 / f k) = f m / f n. Proof. move=> nz_f ltnm; apply: invr_inj; rewrite prodf_div !invf_div -prodf_div. by apply: telescope_prodr => // k /nz_f; rewrite unitfE. Qed. Lemma telescope_prodf_eq n m (f u : nat -> F) : (forall k, n < k < m -> f k != 0) -> n < m -> (forall k, n <= k < m -> u k = f k.+1 / f k) -> \prod_(n <= k < m) u k = f m / f n. Proof. by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodf. Qed. Lemma addf_div x1 y1 x2 y2 : y1 != 0 -> y2 != 0 -> x1 / y1 + x2 / y2 = (x1 * y2 + x2 * y1) / (y1 * y2). Proof. by move=> nzy1 nzy2; rewrite invfM mulrDl !mulrA mulrAC !mulfK. Qed. Lemma mulf_div x1 y1 x2 y2 : (x1 / y1) * (x2 / y2) = (x1 * x2) / (y1 * y2). Proof. by rewrite mulrACA -invfM. Qed. Lemma eqr_div x y z t : y != 0 -> t != 0 -> (x / y == z / t) = (x * t == z * y). Proof. move=> yD0 tD0; rewrite -[x in RHS](divfK yD0) -[z in RHS](divfK tD0) mulrAC. by apply/eqP/eqP => [->|/(mulIf yD0)/(mulIf tD0)]. Qed. Lemma eqr_sum_div I r P (f : I -> F) c a : c != 0 -> \big[+%R/0]_(x <- r | P x) (f x / c) == a = (\big[+%R/0]_(x <- r | P x) f x == a * c). Proof. by move=> ?; rewrite -mulr_suml -(divr1 a) eqr_div ?oner_eq0// mulr1 divr1. Qed. Lemma pchar0_natf_div : pchar F =i pred0 -> forall m d, d %| m -> (m %/ d)%:R = m%:R / d%:R :> F. Proof. move/pcharf0P=> pchar0F m [|d] d_dv_m; first by rewrite divn0 invr0 mulr0. by rewrite natr_div // unitfE pchar0F. Qed. Section FieldMorphismInj. Variables (R : nzRingType) (f : {rmorphism F -> R}). Lemma fmorph_eq0 x : (f x == 0) = (x == 0). Proof. have [-> | nz_x] := eqVneq x; first by rewrite rmorph0 eqxx. apply/eqP; move/(congr1 ( *%R (f x^-1)))/eqP. by rewrite -rmorphM mulVf // mulr0 rmorph1 ?oner_eq0. Qed. Lemma fmorph_inj : injective f. Proof. by apply/raddf_inj => x /eqP; rewrite fmorph_eq0 => /eqP. Qed. Lemma fmorph_eq : {mono f : x y / x == y}. Proof. exact: inj_eq fmorph_inj. Qed. Lemma fmorph_eq1 x : (f x == 1) = (x == 1). Proof. by rewrite -(inj_eq fmorph_inj) rmorph1. Qed. Lemma fmorph_pchar : pchar R =i pchar F. Proof. by move=> p; rewrite !inE -fmorph_eq0 rmorph_nat. Qed. End FieldMorphismInj. Section FieldMorphismInv. Variables (R : unitRingType) (f : {rmorphism F -> R}). Lemma fmorph_unit x : (f x \in unit) = (x != 0). Proof. have [-> |] := eqVneq x; first by rewrite rmorph0 unitr0. by rewrite -unitfE; apply: rmorph_unit. Qed. Lemma fmorphV : {morph f: x / x^-1}. Proof. move=> x; have [-> | nz_x] := eqVneq x 0; first by rewrite !(invr0, rmorph0). by rewrite rmorphV ?unitfE. Qed. Lemma fmorph_div : {morph f : x y / x / y}. Proof. by move=> x y; rewrite rmorphM /= fmorphV. Qed. End FieldMorphismInv. Section ModuleTheory. Variable V : lmodType F. Implicit Types (a : F) (v : V). Lemma scalerK a : a != 0 -> cancel ( *:%R a : V -> V) ( *:%R a^-1). Proof. by move=> nz_a v; rewrite scalerA mulVf // scale1r. Qed. Lemma scalerKV a : a != 0 -> cancel ( *:%R a^-1 : V -> V) ( *:%R a). Proof. by rewrite -invr_eq0 -{3}[a]invrK; apply: scalerK. Qed. Lemma scalerI a : a != 0 -> injective ( *:%R a : V -> V). Proof. by move=> nz_a; apply: can_inj (scalerK nz_a). Qed. Lemma scaler_eq0 a v : (a *: v == 0) = (a == 0) || (v == 0). Proof. have [-> | nz_a] := eqVneq a; first by rewrite scale0r eqxx. by rewrite (can2_eq (scalerK nz_a) (scalerKV nz_a)) scaler0. Qed. End ModuleTheory. Lemma pchar_lalg (A : lalgType F) : pchar A =i pchar F. Proof. by move=> p; rewrite inE -scaler_nat scaler_eq0 oner_eq0 orbF. Qed. End FieldTheory. #[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")] Notation char0_natf_div := pchar0_natf_div (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")] Notation fmorph_char := fmorph_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")] Notation char_lalg := pchar_lalg (only parsing). Arguments fmorph_inj {F R} f [x1 x2]. Arguments telescope_prodf_eq {F n m} f u. Definition decidable_field_axiom (R : unitRingType) (s : seq R -> pred (formula R)) := forall e f, reflect (holds e f) (s e f). HB.mixin Record Field_isDecField R of UnitRing R := { sat : seq R -> pred (formula R); satP : decidable_field_axiom sat; }. #[mathcomp(axiom="decidable_field_axiom"), short(type="decFieldType")] HB.structure Definition DecidableField := { F of Field F & Field_isDecField F }. Module DecFieldExports. Bind Scope ring_scope with DecidableField.sort. End DecFieldExports. HB.export DecFieldExports. #[export] HB.instance Definition _ (F : decFieldType) := DecidableField.on F^o. Section DecidableFieldTheory. Variable F : decFieldType. Implicit Type f : formula F. Fact sol_subproof n f : reflect (exists s, (size s == n) && sat s f) (sat [::] (foldr Exists f (iota 0 n))). Proof. apply: (iffP (satP _ _)) => [|[s]]; last first. case/andP=> /eqP sz_s /satP f_s; apply/foldExistsP. exists s => // i; rewrite !inE mem_iota -leqNgt add0n => le_n_i. by rewrite !nth_default ?sz_s. case/foldExistsP=> e e0 f_e; set s := take n (set_nth 0 e n 0). have sz_s: size s = n by rewrite size_take size_set_nth leq_max leqnn. exists s; rewrite sz_s eqxx; apply/satP; apply: eq_holds f_e => i. case: (leqP n i) => [le_n_i | lt_i_n]. by rewrite -e0 ?nth_default ?sz_s // !inE mem_iota -leqNgt. by rewrite nth_take // nth_set_nth /= eq_sym eqn_leq leqNgt lt_i_n. Qed. Definition sol n f := if sol_subproof n f is ReflectT sP then xchoose sP else nseq n 0. Lemma size_sol n f : size (sol n f) = n. Proof. rewrite /sol; case: sol_subproof => [sP | _]; last exact: size_nseq. by case/andP: (xchooseP sP) => /eqP. Qed. Lemma solP n f : reflect (exists2 s, size s = n & holds s f) (sat (sol n f) f). Proof. rewrite /sol; case: sol_subproof => [sP | sPn]. case/andP: (xchooseP sP) => _ ->; left. by case: sP => s; case/andP; move/eqP=> <-; move/satP; exists s. apply: (iffP (satP _ _)); first by exists (nseq n 0); rewrite ?size_nseq. by case=> s sz_s; move/satP=> f_s; case: sPn; exists s; rewrite sz_s eqxx. Qed. Lemma eq_sat f1 f2 : (forall e, holds e f1 <-> holds e f2) -> sat^~ f1 =1 sat^~ f2. Proof. by move=> eqf12 e; apply/satP/satP; case: (eqf12 e). Qed. Lemma eq_sol f1 f2 : (forall e, holds e f1 <-> holds e f2) -> sol^~ f1 =1 sol^~ f2. Proof. rewrite /sol => /eq_sat eqf12 n. do 2![case: sol_subproof] => //= [f1s f2s | ns1 [s f2s] | [s f1s] []]. - by apply: eq_xchoose => s; rewrite eqf12. - by case: ns1; exists s; rewrite -eqf12. by exists s; rewrite eqf12. Qed. End DecidableFieldTheory. Arguments satP {F e f} : rename. Arguments solP {F n f} : rename. Section QE_Mixin. Variable F : Field.type. Implicit Type f : formula F. Variable proj : nat -> seq (term F) * seq (term F) -> formula F. (* proj is the elimination of a single existential quantifier *) (* The elimination projector is well_formed. *) Definition wf_QE_proj := forall i bc (bc_i := proj i bc), dnf_rterm bc -> qf_form bc_i && rformula bc_i. (* The elimination projector is valid *) Definition valid_QE_proj := forall i bc (ex_i_bc := ('exists 'X_i, dnf_to_form [:: bc])%T) e, dnf_rterm bc -> reflect (holds e ex_i_bc) (qf_eval e (proj i bc)). Hypotheses (wf_proj : wf_QE_proj) (ok_proj : valid_QE_proj). Let elim_aux f n := foldr Or False (map (proj n) (qf_to_dnf f false)). Fixpoint quantifier_elim f := match f with | f1 /\ f2 => (quantifier_elim f1) /\ (quantifier_elim f2) | f1 \/ f2 => (quantifier_elim f1) \/ (quantifier_elim f2) | f1 ==> f2 => (~ quantifier_elim f1) \/ (quantifier_elim f2) | ~ f => ~ quantifier_elim f | ('exists 'X_n, f) => elim_aux (quantifier_elim f) n | ('forall 'X_n, f) => ~ elim_aux (~ quantifier_elim f) n | _ => f end%T. Lemma quantifier_elim_wf f : let qf := quantifier_elim f in rformula f -> qf_form qf && rformula qf. Proof. suffices aux_wf f0 n : let qf := elim_aux f0 n in rformula f0 -> qf_form qf && rformula qf. - by elim: f => //=; do ?[ move=> f1 IH1 f2 IH2; case/andP=> rf1 rf2; case/andP:(IH1 rf1)=> -> ->; case/andP:(IH2 rf2)=> -> -> // | move=> n f1 IH rf1; case/andP: (IH rf1)=> qff rf; rewrite aux_wf ]. rewrite /elim_aux => rf. suffices or_wf fs : let ofs := foldr Or False fs in all (@qf_form F) fs && all (@rformula F) fs -> qf_form ofs && rformula ofs. - apply: or_wf. suffices map_proj_wf bcs: let mbcs := map (proj n) bcs in all dnf_rterm bcs -> all (@qf_form _) mbcs && all (@rformula _) mbcs. by apply/map_proj_wf/qf_to_dnf_rterm. elim: bcs => [|bc bcs ihb] bcsr //= /andP[rbc rbcs]. by rewrite andbAC andbA wf_proj //= andbC ihb. elim: fs => //= g gs ihg; rewrite -andbA => /and4P[-> qgs -> rgs] /=. by apply: ihg; rewrite qgs rgs. Qed. Lemma quantifier_elim_rformP e f : rformula f -> reflect (holds e f) (qf_eval e (quantifier_elim f)). Proof. pose rc e n f := exists x, qf_eval (set_nth 0 e n x) f. have auxP f0 e0 n0: qf_form f0 && rformula f0 -> reflect (rc e0 n0 f0) (qf_eval e0 (elim_aux f0 n0)). + rewrite /elim_aux => cf; set bcs := qf_to_dnf f0 false. apply: (@iffP (rc e0 n0 (dnf_to_form bcs))); last first. - by case=> x; rewrite -qf_to_dnfP //; exists x. - by case=> x; rewrite qf_to_dnfP //; exists x. have: all dnf_rterm bcs by case/andP: cf => _; apply: qf_to_dnf_rterm. elim: {f0 cf}bcs => [|bc bcs IHbcs] /=; first by right; case. case/andP=> r_bc /IHbcs {IHbcs}bcsP. have f_qf := dnf_to_form_qf [:: bc]. case: ok_proj => //= [ex_x|no_x]. left; case: ex_x => x /(qf_evalP _ f_qf); rewrite /= orbF => bc_x. by exists x; rewrite /= bc_x. apply: (iffP bcsP) => [[x bcs_x] | [x]] /=. by exists x; rewrite /= bcs_x orbT. case/orP => [bc_x|]; last by exists x. by case: no_x; exists x; apply/(qf_evalP _ f_qf); rewrite /= bc_x. elim: f e => //. - by move=> b e _; apply: idP. - by move=> t1 t2 e _; apply: eqP. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by right; case. by case/IH2; [left | right; case]. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; first by do 2!left. by case/IH2; [left; right | right; case]. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by left. by case/IH2; [left | right; move/(_ f1e)]. - by move=> f IHf e /= /IHf[]; [right | left]. - move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf. by apply: (iffP (auxP _ _ _ rqf)) => [] [x]; exists x; apply/IHf. move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf. case: auxP => // [f_x|no_x]; first by right=> no_x; case: f_x => x /IHf[]. by left=> x; apply/IHf=> //; apply/idPn=> f_x; case: no_x; exists x. Qed. Definition proj_sat e f := qf_eval e (quantifier_elim (to_rform f)). Lemma proj_satP : DecidableField.axiom proj_sat. Proof. move=> e f; have fP := quantifier_elim_rformP e (to_rform_rformula f). by apply: (iffP fP); move/to_rformP. Qed. End QE_Mixin. HB.factory Record Field_QE_isDecField F of Field F := { proj : nat -> seq (term F) * seq (term F) -> formula F; wf_proj : wf_QE_proj proj; ok_proj : valid_QE_proj proj; }. HB.builders Context F of Field_QE_isDecField F. HB.instance Definition qe_is_def_field : Field_isDecField F := Field_isDecField.Build F (proj_satP wf_proj ok_proj). HB.end. (* Axiom == all non-constant monic polynomials have a root *) Definition closed_field_axiom (R : pzRingType) := forall n (P : nat -> R), n > 0 -> exists x : R, x ^+ n = \sum_(i < n) P i * (x ^+ i). HB.mixin Record DecField_isAlgClosed F of DecidableField F := { solve_monicpoly : closed_field_axiom F; }. #[mathcomp(axiom="closed_field_axiom"), short(type="closedFieldType")] HB.structure Definition ClosedField := { F of DecidableField F & DecField_isAlgClosed F }. Module ClosedFieldExports. Bind Scope ring_scope with ClosedField.sort. End ClosedFieldExports. HB.export ClosedFieldExports. #[export] HB.instance Definition _ (F : closedFieldType) := ClosedField.on F^o. Section ClosedFieldTheory. Variable F : closedFieldType. Lemma imaginary_exists : {i : F | i ^+ 2 = -1}. Proof. have /sig_eqW[i Di2] := @solve_monicpoly F 2 (nth 0 [:: -1]) isT. by exists i; rewrite Di2 !big_ord_recl big_ord0 mul0r mulr1 !addr0. Qed. End ClosedFieldTheory. Lemma lalgMixin (R : pzRingType) (A : lalgType R) (B : lmodType R) (f : B -> A) : phant B -> injective f -> scalable f -> forall mulB, {morph f : x y / mulB x y >-> x * y} -> forall a u v, a *: (mulB u v) = mulB (a *: u) v. Proof. by move=> _ injf fZ mulB fM a x y; apply: injf; rewrite !(fZ, fM) scalerAl. Qed. Lemma comRingMixin (R : comPzRingType) (T : pzRingType) (f : T -> R) : phant T -> injective f -> {morph f : x y / x * y} -> commutative (@mul T). Proof. by move=> _ inj_f fM x y; apply: inj_f; rewrite !fM mulrC. Qed. Lemma algMixin (R : pzRingType) (A : algType R) (B : lalgType R) (f : B -> A) : phant B -> injective f -> {morph f : x y / x * y} -> scalable f -> forall k (x y : B), k *: (x * y) = x * (k *: y). Proof. by move=> _ inj_f fM fZ a x y; apply: inj_f; rewrite !(fM, fZ) scalerAr. Qed. (* Mixins for stability properties *) HB.mixin Record isMul2Closed (R : pzSemiRingType) (S : {pred R}) := { rpredM : mulr_2closed S }. HB.mixin Record isMul1Closed (R : pzSemiRingType) (S : {pred R}) := { rpred1 : 1 \in S }. HB.mixin Record isInvClosed (R : unitRingType) (S : {pred R}) := { rpredVr : invr_closed S }. HB.mixin Record isScaleClosed (R : pzSemiRingType) (V : lSemiModType R) (S : {pred V}) := { rpredZ : scaler_closed S }. (* Structures for stability properties *) Local Notation addrClosed := addrClosed. Local Notation opprClosed := opprClosed. #[short(type="mulr2Closed")] HB.structure Definition Mul2Closed (R : pzSemiRingType) := {S of isMul2Closed R S}. #[short(type="mulrClosed")] HB.structure Definition MulClosed (R : pzSemiRingType) := {S of Mul2Closed R S & isMul1Closed R S}. #[short(type="semiring2Closed")] HB.structure Definition Semiring2Closed (R : pzSemiRingType) := {S of AddClosed R S & Mul2Closed R S}. #[short(type="semiringClosed")] HB.structure Definition SemiringClosed (R : pzSemiRingType) := {S of AddClosed R S & MulClosed R S}. #[short(type="smulClosed")] HB.structure Definition SmulClosed (R : pzRingType) := {S of OppClosed R S & MulClosed R S}. #[short(type="subringClosed")] HB.structure Definition SubringClosed (R : pzRingType) := {S of ZmodClosed R S & MulClosed R S}. #[short(type="divClosed")] HB.structure Definition DivClosed (R : unitRingType) := {S of MulClosed R S & isInvClosed R S}. #[short(type="sdivClosed")] HB.structure Definition SdivClosed (R : unitRingType) := {S of SmulClosed R S & isInvClosed R S}. #[short(type="submodClosed")] HB.structure Definition SubmodClosed (R : pzSemiRingType) (V : lSemiModType R) := {S of AddClosed V S & isScaleClosed R V S}. #[short(type="subalgClosed")] HB.structure Definition SubalgClosed (R : pzSemiRingType) (A : lSemiAlgType R) := {S of SemiringClosed A S & isScaleClosed R A S}. #[short(type="divringClosed")] HB.structure Definition DivringClosed (R : unitRingType) := {S of SubringClosed R S & isInvClosed R S}. #[short(type="divalgClosed")] HB.structure Definition DivalgClosed (R : pzRingType) (A : unitAlgType R) := {S of DivringClosed A S & isScaleClosed R A S}. (* Factories for stability properties *) HB.factory Record isMulClosed (R : pzSemiRingType) (S : {pred R}) := { rpred1M : mulr_closed S }. HB.builders Context R S of isMulClosed R S. HB.instance Definition _ := isMul2Closed.Build R S (proj2 rpred1M). HB.instance Definition _ := isMul1Closed.Build R S (proj1 rpred1M). HB.end. HB.factory Record isSmulClosed (R : pzRingType) (S : R -> bool) := { smulr_closed_subproof : smulr_closed S }. HB.builders Context R S of isSmulClosed R S. HB.instance Definition _ := isMulClosed.Build R S (smulr_closedM smulr_closed_subproof). HB.instance Definition _ := isOppClosed.Build R S (smulr_closedN smulr_closed_subproof). HB.end. HB.factory Record isSemiringClosed (R : pzSemiRingType) (S : R -> bool) := { semiring_closed_subproof : semiring_closed S }. HB.builders Context R S of isSemiringClosed R S. HB.instance Definition _ := isAddClosed.Build R S (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := isMulClosed.Build R S (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record isSubringClosed (R : pzRingType) (S : R -> bool) := { subring_closed_subproof : subring_closed S }. HB.builders Context R S of isSubringClosed R S. HB.instance Definition _ := isZmodClosed.Build R S (subring_closedB subring_closed_subproof). HB.instance Definition _ := isSmulClosed.Build R S (subring_closedM subring_closed_subproof). HB.end. HB.factory Record isDivClosed (R : unitRingType) (S : R -> bool) := { divr_closed_subproof : divr_closed S }. HB.builders Context R S of isDivClosed R S. HB.instance Definition _ := isMulClosed.Build R S (divr_closedM divr_closed_subproof). HB.instance Definition _ := isInvClosed.Build R S (divr_closedV divr_closed_subproof). HB.end. HB.factory Record isSdivClosed (R : unitRingType) (S : R -> bool) := { sdivr_closed_subproof : sdivr_closed S }. HB.builders Context R S of isSdivClosed R S. HB.instance Definition _ := isDivClosed.Build R S (sdivr_closed_div sdivr_closed_subproof). HB.instance Definition _ := isSmulClosed.Build R S (sdivr_closedM sdivr_closed_subproof). HB.end. HB.factory Record isSubSemiModClosed (R : pzSemiRingType) (V : lSemiModType R) (S : V -> bool) := { subsemimod_closed_subproof : subsemimod_closed S }. HB.builders Context R V S of isSubSemiModClosed R V S. HB.instance Definition _ := isAddClosed.Build V S (subsemimod_closedD subsemimod_closed_subproof). HB.instance Definition _ := isScaleClosed.Build R V S (subsemimod_closedZ subsemimod_closed_subproof). HB.end. HB.factory Record isSubmodClosed (R : pzRingType) (V : lmodType R) (S : V -> bool) := { submod_closed_subproof : submod_closed S }. HB.builders Context R V S of isSubmodClosed R V S. HB.instance Definition _ := isZmodClosed.Build V S (submod_closedB submod_closed_subproof). HB.instance Definition _ := isScaleClosed.Build R V S (subsemimod_closedZ (submod_closed_semi submod_closed_subproof)). HB.end. HB.factory Record isSubalgClosed (R : pzRingType) (A : lalgType R) (S : A -> bool) := { subalg_closed_subproof : subalg_closed S }. HB.builders Context R A S of isSubalgClosed R A S. HB.instance Definition _ := isSubmodClosed.Build R A S (subalg_closedZ subalg_closed_subproof). HB.instance Definition _ := isSubringClosed.Build A S (subalg_closedBM subalg_closed_subproof). HB.end. HB.factory Record isDivringClosed (R : unitRingType) (S : R -> bool) := { divring_closed_subproof : divring_closed S }. HB.builders Context R S of isDivringClosed R S. HB.instance Definition _ := isSubringClosed.Build R S (divring_closedBM divring_closed_subproof). HB.instance Definition _ := isSdivClosed.Build R S (divring_closed_div divring_closed_subproof). HB.end. HB.factory Record isDivalgClosed (R : comUnitRingType) (A : unitAlgType R) (S : A -> bool) := { divalg_closed_subproof : divalg_closed S }. HB.builders Context R A S of isDivalgClosed R A S. HB.instance Definition _ := isDivringClosed.Build A S (divalg_closedBdiv divalg_closed_subproof). HB.instance Definition _ := isSubalgClosed.Build R A S (divalg_closedZ divalg_closed_subproof). HB.end. Section NmodulePred. Variables (V : nmodType). Section Add. Variable S : addrClosed V. Lemma rpred0D : nmod_closed S. Proof. exact: nmod_closed_subproof. Qed. End Add. End NmodulePred. Section ZmodulePred. Variables (V : zmodType). Section Opp. Variable S : opprClosed V. End Opp. Section Sub. Variable S : zmodClosed V. Lemma zmodClosedP : zmod_closed S. Proof. split; [ exact: (@rpred0D V S).1 | exact: rpredB ]. Qed. End Sub. End ZmodulePred. Section SemiRingPred. Variables (R : pzSemiRingType). Section Mul. Variable S : mulrClosed R. Lemma rpred1M : mulr_closed S. Proof. exact: (conj rpred1 rpredM). Qed. Lemma rpred_prod I r (P : pred I) F : (forall i, P i -> F i \in S) -> \prod_(i <- r | P i) F i \in S. Proof. by move=> IH; elim/big_ind: _; [apply: rpred1 | apply: rpredM |]. Qed. Lemma rpredX n : {in S, forall u, u ^+ n \in S}. Proof. by move=> u Su; rewrite -(card_ord n) -prodr_const rpred_prod. Qed. End Mul. Lemma rpred_nat (S : semiringClosed R) n : n%:R \in S. Proof. by rewrite rpredMn ?rpred1. Qed. Lemma semiringClosedP (rngS : semiringClosed R) : semiring_closed rngS. Proof. split; [ exact: rpred0D | exact: rpred1M ]. Qed. End SemiRingPred. Section RingPred. Variables (R : pzRingType). Lemma rpredMsign (S : opprClosed R) n x : ((-1) ^+ n * x \in S) = (x \in S). Proof. by rewrite -signr_odd mulr_sign; case: ifP => // _; rewrite rpredN. Qed. Lemma rpredN1 (S : smulClosed R) : -1 \in S. Proof. by rewrite rpredN rpred1. Qed. Lemma rpred_sign (S : smulClosed R) n : (-1) ^+ n \in S. Proof. by rewrite rpredX ?rpredN1. Qed. Lemma subringClosedP (rngS : subringClosed R) : subring_closed rngS. Proof. split; [ exact: rpred1 | exact: (zmodClosedP rngS).2 | exact: rpredM ]. Qed. End RingPred. Section LmodPred. Variables (R : pzSemiRingType) (V : lSemiModType R). Lemma rpredZnat (S : addrClosed V) n : {in S, forall u, n%:R *: u \in S}. Proof. by move=> u Su; rewrite /= scaler_nat rpredMn. Qed. Lemma subsemimodClosedP (modS : submodClosed V) : subsemimod_closed modS. Proof. by split; [exact: rpred0D | exact: rpredZ]. Qed. End LmodPred. Section LmodPred. Variables (R : pzRingType) (V : lmodType R). Lemma rpredZsign (S : opprClosed V) n u : ((-1) ^+ n *: u \in S) = (u \in S). Proof. by rewrite -signr_odd scaler_sign fun_if if_arg rpredN if_same. Qed. Lemma submodClosedP (modS : submodClosed V) : submod_closed modS. Proof. split; first exact (@rpred0D V modS).1. by move=> a u v uS vS; apply: rpredD; first exact: rpredZ. Qed. End LmodPred. Section LalgPred. Variables (R : pzRingType) (A : lalgType R). Lemma subalgClosedP (algS : subalgClosed A) : subalg_closed algS. Proof. split; [ exact: rpred1 | | exact: rpredM ]. by move=> a u v uS vS; apply: rpredD; first exact: rpredZ. Qed. End LalgPred. Section UnitRingPred. Variable R : unitRingType. Section Div. Variable S : divClosed R. Lemma rpredV x : (x^-1 \in S) = (x \in S). Proof. by apply/idP/idP=> /rpredVr; rewrite ?invrK. Qed. Lemma rpred_div : {in S &, forall x y, x / y \in S}. Proof. by move=> x y Sx Sy; rewrite /= rpredM ?rpredV. Qed. Lemma rpredXN n : {in S, forall x, x ^- n \in S}. Proof. by move=> x Sx; rewrite /= rpredV rpredX. Qed. Lemma rpredMl x y : x \in S -> x \is a unit-> (x * y \in S) = (y \in S). Proof. move=> Sx Ux; apply/idP/idP=> [Sxy | /(rpredM _ _ Sx)-> //]. by rewrite -(mulKr Ux y); rewrite rpredM ?rpredV. Qed. Lemma rpredMr x y : x \in S -> x \is a unit -> (y * x \in S) = (y \in S). Proof. move=> Sx Ux; apply/idP/idP=> [Sxy | /rpredM-> //]. by rewrite -(mulrK Ux y); rewrite rpred_div. Qed. Lemma rpred_divr x y : x \in S -> x \is a unit -> (y / x \in S) = (y \in S). Proof. by rewrite -rpredV -unitrV; apply: rpredMr. Qed. Lemma rpred_divl x y : x \in S -> x \is a unit -> (x / y \in S) = (y \in S). Proof. by rewrite -(rpredV y); apply: rpredMl. Qed. End Div. Lemma divringClosedP (divS : divringClosed R) : divring_closed divS. Proof. split; [ exact: rpred1 | exact: rpredB | exact: rpred_div ]. Qed. Fact unitr_sdivr_closed : @sdivr_closed R unit. Proof. by split=> [|x y Ux Uy]; rewrite ?unitrN1 // unitrMl ?unitrV. Qed. #[export] HB.instance Definition _ := isSdivClosed.Build R unit_pred unitr_sdivr_closed. Implicit Type x : R. Lemma unitrN x : (- x \is a unit) = (x \is a unit). Proof. exact: rpredN. Qed. Lemma invrN x : (- x)^-1 = - x^-1. Proof. have [Ux | U'x] := boolP (x \is a unit); last by rewrite !invr_out ?unitrN. by rewrite -mulN1r invrM ?unitrN1 // invrN1 mulrN1. Qed. Lemma divrNN x y : (- x) / (- y) = x / y. Proof. by rewrite invrN mulrNN. Qed. Lemma divrN x y : x / (- y) = - (x / y). Proof. by rewrite invrN mulrN. Qed. Lemma invr_signM n x : ((-1) ^+ n * x)^-1 = (-1) ^+ n * x^-1. Proof. by rewrite -signr_odd !mulr_sign; case: ifP => // _; rewrite invrN. Qed. Lemma divr_signM (b1 b2 : bool) x1 x2: ((-1) ^+ b1 * x1) / ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 / x2). Proof. by rewrite invr_signM mulr_signM. Qed. End UnitRingPred. Section FieldPred. Variable F : fieldType. Implicit Types x y : F. Section ModuleTheory. Variable V : lmodType F. Implicit Types (a : F) (v : V). Lemma rpredZeq (S : submodClosed V) a v : (a *: v \in S) = (a == 0) || (v \in S). Proof. have [-> | nz_a] := eqVneq; first by rewrite scale0r rpred0. by apply/idP/idP; first rewrite -{2}(scalerK nz_a v); apply: rpredZ. Qed. End ModuleTheory. Section Predicates. Context (S : divClosed F). Lemma fpredMl x y : x \in S -> x != 0 -> (x * y \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpredMl. Qed. Lemma fpredMr x y : x \in S -> x != 0 -> (y * x \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpredMr. Qed. Lemma fpred_divl x y : x \in S -> x != 0 -> (x / y \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpred_divl. Qed. Lemma fpred_divr x y : x \in S -> x != 0 -> (y / x \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpred_divr. Qed. End Predicates. End FieldPred. HB.mixin Record isSubPzSemiRing (R : pzSemiRingType) (S : pred R) U of SubNmodule R S U & PzSemiRing U := { valM_subproof : monoid_morphism (val : U -> R); }. Module isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isSubPzSemiRing.Build instead.")] Notation Build R S U := (isSubPzSemiRing.Build R S U) (only parsing). End isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isSubPzSemiRing instead.")] Notation isSubSemiRing R S U := (isSubPzSemiRing R S U) (only parsing). #[short(type="subPzSemiRingType")] HB.structure Definition SubPzSemiRing (R : pzSemiRingType) (S : pred R) := { U of SubNmodule R S U & PzSemiRing U & isSubPzSemiRing R S U }. #[short(type="subNzSemiRingType")] HB.structure Definition SubNzSemiRing (R : nzSemiRingType) (S : pred R) := { U of SubNmodule R S U & NzSemiRing U & isSubPzSemiRing R S U }. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing instead.")] Notation SubSemiRing R := (SubNzSemiRing R) (only parsing). Module SubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.sort instead.")] Notation sort := (SubNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.on instead.")] Notation on R := (SubNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.copy instead.")] Notation copy T U := (SubNzSemiRing.copy T U) (only parsing). End SubSemiRing. Section multiplicative. Context (R : pzSemiRingType) (S : pred R) (U : SubPzSemiRing.type S). Notation val := (val : U -> R). #[export] HB.instance Definition _ := isMonoidMorphism.Build U R val valM_subproof. Lemma val1 : val 1 = 1. Proof. exact: rmorph1. Qed. Lemma valM : {morph val : x y / x * y}. Proof. exact: rmorphM. Qed. Lemma valM1 : monoid_morphism val. Proof. exact: valM_subproof. Qed. End multiplicative. HB.factory Record SubNmodule_isSubPzSemiRing (R : pzSemiRingType) S U of SubNmodule R S U := { mulr_closed_subproof : mulr_closed S }. HB.builders Context R S U of SubNmodule_isSubPzSemiRing R S U. HB.instance Definition _ := isMulClosed.Build R S mulr_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). Lemma mulrA : associative mulU. Proof. by move=> x y z; apply: val_inj; rewrite !SubK mulrA. Qed. Lemma mul1r : left_id oneU mulU. Proof. by move=> x; apply: val_inj; rewrite !SubK mul1r. Qed. Lemma mulr1 : right_id oneU mulU. Proof. by move=> x; apply: val_inj; rewrite !SubK mulr1. Qed. Lemma mulrDl : left_distributive mulU +%R. Proof. by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDl. Qed. Lemma mulrDr : right_distributive mulU +%R. Proof. by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDr. Qed. Lemma mul0r : left_zero 0%R mulU. Proof. by move=> x; apply: val_inj; rewrite SubK val0 mul0r. Qed. Lemma mulr0 : right_zero 0%R mulU. Proof. by move=> x; apply: val_inj; rewrite SubK val0 mulr0. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build U mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. Lemma valM : monoid_morphism (val : U -> R). Proof. by split=> [|x y] /=; rewrite !SubK. Qed. HB.instance Definition _ := isSubPzSemiRing.Build R S U valM. HB.end. HB.factory Record SubNmodule_isSubNzSemiRing (R : nzSemiRingType) S U of SubNmodule R S U := { mulr_closed_subproof : mulr_closed S }. Module SubNmodule_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNmodule_isSubNzSemiRing.Build instead.")] Notation Build R S U := (SubNmodule_isSubNzSemiRing.Build R S U) (only parsing). End SubNmodule_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNmodule_isSubNzSemiRing instead.")] Notation SubNmodule_isSubSemiRing R S U := (SubNmodule_isSubNzSemiRing R S U) (only parsing). HB.builders Context R S U of SubNmodule_isSubNzSemiRing R S U. HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U mulr_closed_subproof. Lemma oner_neq0 : (1 : U) != 0. Proof. by rewrite -(inj_eq val_inj) SubK raddf0 oner_neq0. Qed. HB.instance Definition _ := PzSemiRing_isNonZero.Build U oner_neq0. HB.end. #[short(type="subComPzSemiRingType")] HB.structure Definition SubComPzSemiRing (R : pzSemiRingType) S := {U of SubPzSemiRing R S U & ComPzSemiRing U}. HB.factory Record SubPzSemiRing_isSubComPzSemiRing (R : comPzSemiRingType) S U of SubPzSemiRing R S U := {}. HB.builders Context R S U of SubPzSemiRing_isSubComPzSemiRing R S U. Lemma mulrC : @commutative U U *%R. Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build U mulrC. HB.end. #[short(type="subComNzSemiRingType")] HB.structure Definition SubComNzSemiRing (R : nzSemiRingType) S := {U of SubNzSemiRing R S U & ComNzSemiRing U}. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing instead.")] Notation SubComSemiRing R := (SubComNzSemiRing R) (only parsing). Module SubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.sort instead.")] Notation sort := (SubComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.on instead.")] Notation on R := (SubComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.copy instead.")] Notation copy T U := (SubComNzSemiRing.copy T U) (only parsing). End SubComSemiRing. HB.factory Record SubNzSemiRing_isSubComNzSemiRing (R : comNzSemiRingType) S U of SubNzSemiRing R S U := {}. Module SubSemiRing_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing_isSubComNzSemiRing.Build instead.")] Notation Build R S U := (SubNzSemiRing_isSubComNzSemiRing.Build R S U) (only parsing). End SubSemiRing_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing_isSubComNzSemiRing instead.")] Notation SubSemiRing_isSubComSemiRing R S U := (SubNzSemiRing_isSubComNzSemiRing R S U) (only parsing). HB.builders Context R S U of SubNzSemiRing_isSubComNzSemiRing R S U. HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U. HB.end. #[short(type="subPzRingType")] HB.structure Definition SubPzRing (R : pzRingType) (S : pred R) := { U of SubPzSemiRing R S U & PzRing U & isSubZmodule R S U }. HB.factory Record SubZmodule_isSubPzRing (R : pzRingType) S U of SubZmodule R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context R S U of SubZmodule_isSubPzRing R S U. HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U (smulr_closedM (subring_closedM subring_closed_subproof)). HB.end. #[short(type="subNzRingType")] HB.structure Definition SubNzRing (R : nzRingType) (S : pred R) := { U of SubNzSemiRing R S U & NzRing U & isSubBaseAddUMagma R S U }. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing instead.")] Notation SubRing R := (SubNzRing R) (only parsing). Module SubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.sort instead.")] Notation sort := (SubNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.on instead.")] Notation on R := (SubNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.copy instead.")] Notation copy T U := (SubNzRing.copy T U) (only parsing). End SubRing. HB.factory Record SubZmodule_isSubNzRing (R : nzRingType) S U of SubZmodule R S U := { subring_closed_subproof : subring_closed S }. Module SubZmodule_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubZmodule_isSubNzRing.Build instead.")] Notation Build R S U := (SubZmodule_isSubNzRing.Build R S U) (only parsing). End SubZmodule_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubZmodule_isSubNzRing instead.")] Notation SubZmodule_isSubRing R S U := (SubZmodule_isSubNzRing R S U) (only parsing). HB.builders Context R S U of SubZmodule_isSubNzRing R S U. HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U (smulr_closedM (subring_closedM subring_closed_subproof)). HB.end. #[short(type="subComPzRingType")] HB.structure Definition SubComPzRing (R : pzRingType) S := {U of SubPzRing R S U & ComPzRing U}. HB.factory Record SubPzRing_isSubComPzRing (R : comPzRingType) S U of SubPzRing R S U := {}. HB.builders Context R S U of SubPzRing_isSubComPzRing R S U. Lemma mulrC : @commutative U U *%R. Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed. HB.instance Definition _ := PzRing_hasCommutativeMul.Build U mulrC. HB.end. #[short(type="subComNzRingType")] HB.structure Definition SubComNzRing (R : nzRingType) S := {U of SubNzRing R S U & ComNzRing U}. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing instead.")] Notation SubComRing R := (SubComNzRing R) (only parsing). Module SubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.sort instead.")] Notation sort := (SubComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.on instead.")] Notation on R := (SubComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.copy instead.")] Notation copy T U := (SubComNzRing.copy T U) (only parsing). End SubComRing. HB.factory Record SubNzRing_isSubComNzRing (R : comNzRingType) S U of SubNzRing R S U := {}. Module SubRing_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_isSubComNzRing.Build instead.")] Notation Build R S U := (SubNzRing_isSubComNzRing.Build R S U) (only parsing). End SubRing_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_isSubComNzRing instead.")] Notation SubRing_isSubComRing R S U := (SubNzRing_isSubComNzRing R S U) (only parsing). HB.builders Context R S U of SubNzRing_isSubComNzRing R S U. HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U. HB.end. HB.mixin Record isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) (S : pred V) W of SubNmodule V S W & LSemiModule R W := { valZ : scalable (val : W -> V); }. #[short(type="subLSemiModType")] HB.structure Definition SubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) (S : pred V) := { W of SubNmodule V S W & Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}. #[short(type="subLmodType")] HB.structure Definition SubLmodule (R : pzRingType) (V : lmodType R) (S : pred V) := { W of SubZmodule V S W & Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}. Section linear. Context (R : pzSemiRingType) (V : lSemiModType R). Context (S : pred V) (W : subLSemiModType S). Notation val := (val : W -> V). #[export] HB.instance Definition _ := isScalable.Build R W V *:%R val valZ. End linear. HB.factory Record isSubLmodule (R : pzRingType) (V : lmodType R) (S : pred V) W of SubZmodule V S W & Lmodule R W := { valZ : scalable (val : W -> V); }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of isSubLmodule R V S W. HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ. HB.end. HB.factory Record SubNmodule_isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) S W of SubNmodule V S W := { submod_closed_subproof : subsemimod_closed S }. HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W of SubNmodule_isSubLSemiModule R V S W. HB.instance Definition _ := isSubSemiModClosed.Build R V S submod_closed_subproof. Let inW v Sv : W := Sub v Sv. Let scaleW a (w : W) := inW (rpredZ a _ (valP w)). Lemma scalerA' a b v : scaleW a (scaleW b v) = scaleW (a * b) v. Proof. by apply: val_inj; rewrite !SubK scalerA. Qed. Lemma scale0r v : scaleW 0 v = 0. Proof. by apply: val_inj; rewrite SubK scale0r raddf0. Qed. Lemma scale1r : left_id 1 scaleW. Proof. by move=> x; apply: val_inj; rewrite SubK scale1r. Qed. Lemma scalerDr : right_distributive scaleW +%R. Proof. by move=> a u v; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK. Qed. Lemma scalerDl v : {morph scaleW^~ v : a b / a + b}. Proof. by move=> a b; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK scalerDl. Qed. HB.instance Definition _ := Nmodule_isLSemiModule.Build R W scalerA' scale0r scale1r scalerDr scalerDl. Fact valZ : scalable (val : W -> _). Proof. by move=> k w; rewrite SubK. Qed. HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ. HB.end. HB.factory Record SubZmodule_isSubLmodule (R : pzRingType) (V : lmodType R) S W of SubZmodule V S W := { submod_closed_subproof : submod_closed S }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of SubZmodule_isSubLmodule R V S W. HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W (submod_closed_semi submod_closed_subproof). HB.end. #[short(type="subLSemiAlgType")] HB.structure Definition SubLSemiAlgebra (R : pzSemiRingType) (V : lSemiAlgType R) S := {W of SubNzSemiRing V S W & @SubLSemiModule R V S W & LSemiAlgebra R W}. #[short(type="subLalgType")] HB.structure Definition SubLalgebra (R : pzRingType) (V : lalgType R) S := {W of SubNzRing V S W & @SubLmodule R V S W & Lalgebra R W}. HB.factory Record SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra (R : pzSemiRingType) (V : lSemiAlgType R) S W of SubNzSemiRing V S W & @SubLSemiModule R V S W := {}. HB.builders Context (R : pzSemiRingType) (V : lSemiAlgType R) S W of SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra R V S W. Lemma scalerAl (a : R) (u v : W) : a *: (u * v) = a *: u * v. Proof. by apply: val_inj; rewrite !(linearZ, rmorphM) /= linearZ scalerAl. Qed. HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R W scalerAl. HB.end. HB.factory Record SubNzRing_SubLmodule_isSubLalgebra (R : pzRingType) (V : lalgType R) S W of SubNzRing V S W & @SubLmodule R V S W := {}. Module SubRing_SubLmodule_isSubLalgebra. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_SubLmodule_isSubLalgebra.Build instead.")] Notation Build R V S U := (SubNzRing_SubLmodule_isSubLalgebra.Build R V S U) (only parsing). End SubRing_SubLmodule_isSubLalgebra. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_SubLmodule_isSubLalgebra instead.")] Notation SubRing_SubLmodule_isSubLalgebra R V S U := (SubNzRing_SubLmodule_isSubLalgebra R V S U) (only parsing). HB.builders Context (R : pzRingType) (V : lalgType R) S W of SubNzRing_SubLmodule_isSubLalgebra R V S W. HB.instance Definition _ := SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build R V S W. HB.end. #[short(type="subSemiAlgType")] HB.structure Definition SubSemiAlgebra (R : pzSemiRingType) (V : semiAlgType R) S := {W of @SubLSemiAlgebra R V S W & SemiAlgebra R W}. #[short(type="subAlgType")] HB.structure Definition SubAlgebra (R : pzRingType) (V : algType R) S := {W of @SubLalgebra R V S W & Algebra R W}. HB.factory Record SubLSemiAlgebra_isSubSemiAlgebra (R : pzSemiRingType) (V : semiAlgType R) S W of @SubLSemiAlgebra R V S W := {}. HB.builders Context (R : pzSemiRingType) (V : semiAlgType R) S W of SubLSemiAlgebra_isSubSemiAlgebra R V S W. Lemma scalerAr (k : R) (x y : W) : k *: (x * y) = x * (k *: y). Proof. by apply: val_inj; rewrite !(linearZ, rmorphM)/= linearZ scalerAr. Qed. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R W scalerAr. HB.end. HB.factory Record SubLalgebra_isSubAlgebra (R : pzRingType) (V : algType R) S W of @SubLalgebra R V S W := {}. HB.builders Context (R : pzRingType) (V : algType R) S W of SubLalgebra_isSubAlgebra R V S W. HB.instance Definition _ := SubLSemiAlgebra_isSubSemiAlgebra.Build R V S W. HB.end. #[short(type="subUnitRingType")] HB.structure Definition SubUnitRing (R : nzRingType) (S : pred R) := {U of SubNzRing R S U & UnitRing U}. HB.factory Record SubNzRing_isSubUnitRing (R : unitRingType) S U of SubNzRing R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : unitRingType) S U of SubNzRing_isSubUnitRing R S U. HB.instance Definition _ := isDivringClosed.Build R S divring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let invU (u : U) := inU (rpredVr _ (valP u)). Lemma mulVr : {in [pred x | val x \is a unit], left_inverse 1 invU *%R}. Proof. by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulVr. Qed. Lemma divrr : {in [pred x | val x \is a unit], right_inverse 1 invU *%R}. by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulrV. Qed. Lemma unitrP (x y : U) : y * x = 1 /\ x * y = 1 -> val x \is a unit. Proof. move=> -[/(congr1 val) yx1 /(congr1 val) xy1]. by apply: rev_unitrP (val y) _; rewrite !rmorphM rmorph1 /= in yx1 xy1. Qed. Lemma invr_out : {in [pred x | val x \isn't a unit], invU =1 id}. Proof. by move=> x /[!inE] xNU; apply: val_inj; rewrite SubK invr_out. Qed. HB.instance Definition _ := NzRing_hasMulInverse.Build U mulVr divrr unitrP invr_out. HB.end. #[short(type="subComUnitRingType")] HB.structure Definition SubComUnitRing (R : comUnitRingType) (S : pred R) := {U of SubComNzRing R S U & SubUnitRing R S U}. #[short(type="subIdomainType")] HB.structure Definition SubIntegralDomain (R : idomainType) (S : pred R) := {U of SubComNzRing R S U & IntegralDomain U}. HB.factory Record SubComUnitRing_isSubIntegralDomain (R : idomainType) S U of SubComUnitRing R S U := {}. HB.builders Context (R : idomainType) S U of SubComUnitRing_isSubIntegralDomain R S U. Lemma id : IntegralDomain.axiom U. Proof. move=> x y /(congr1 val)/eqP; rewrite rmorphM /=. by rewrite -!(inj_eq val_inj) rmorph0 -mulf_eq0. Qed. HB.instance Definition _ := ComUnitRing_isIntegral.Build U id. HB.end. #[short(type="subFieldType")] HB.structure Definition SubField (F : fieldType) (S : pred F) := {U of SubIntegralDomain F S U & Field U}. HB.factory Record SubIntegralDomain_isSubField (F : fieldType) S U of SubIntegralDomain F S U := { subfield_subproof : {mono (val : U -> F) : u / u \in unit} }. HB.builders Context (F : fieldType) S U of SubIntegralDomain_isSubField F S U. Lemma fieldP : Field.axiom U. Proof. by move=> u; rewrite -(inj_eq val_inj) rmorph0 -unitfE subfield_subproof. Qed. HB.instance Definition _ := UnitRing_isField.Build U fieldP. HB.end. HB.factory Record SubChoice_isSubPzSemiRing (R : pzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. HB.builders Context (R : pzSemiRingType) S U of SubChoice_isSubPzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record SubChoice_isSubNzSemiRing (R : nzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. Module SubChoice_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzSemiRing.Build instead.")] Notation Build R S U := (SubChoice_isSubNzSemiRing.Build R S U) (only parsing). End SubChoice_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzSemiRing instead.")] Notation SubChoice_isSubSemiRing R S U := (SubChoice_isSubNzSemiRing R S U) (only parsing). HB.builders Context (R : nzSemiRingType) S U of SubChoice_isSubNzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record SubChoice_isSubComPzSemiRing (R : comPzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. HB.builders Context (R : comPzSemiRingType) S U of SubChoice_isSubComPzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubPzSemiRing.Build R S U semiring_closed_subproof. HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubComNzSemiRing (R : comNzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. Module SubChoice_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzSemiRing.Build instead.")] Notation Build R S U := (SubChoice_isSubComNzSemiRing.Build R S U) (only parsing). End SubChoice_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzSemiRing instead.")] Notation SubChoice_isSubComSemiRing R S U := (SubChoice_isSubComNzSemiRing R S U) (only parsing). HB.builders Context (R : comNzSemiRingType) S U of SubChoice_isSubComNzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNzSemiRing.Build R S U semiring_closed_subproof. HB.instance Definition _ := SubNzSemiRing_isSubComNzSemiRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubPzRing (R : pzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context (R : pzRingType) S U of SubChoice_isSubPzRing R S U. HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U (subring_closedB subring_closed_subproof). HB.instance Definition _ := SubZmodule_isSubPzRing.Build R S U subring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubNzRing (R : nzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. Module SubChoice_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzRing.Build instead.")] Notation Build R S U := (SubChoice_isSubNzRing.Build R S U) (only parsing). End SubChoice_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzRing instead.")] Notation SubChoice_isSubRing R S U := (SubChoice_isSubNzRing R S U) (only parsing). HB.builders Context (R : nzRingType) S U of SubChoice_isSubNzRing R S U. HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U (subring_closedB subring_closed_subproof). HB.instance Definition _ := SubZmodule_isSubNzRing.Build R S U subring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubComPzRing (R : comPzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context (R : comPzRingType) S U of SubChoice_isSubComPzRing R S U. HB.instance Definition _ := SubChoice_isSubPzRing.Build R S U subring_closed_subproof. HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubComNzRing (R : comNzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. Module SubChoice_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzRing.Build instead.")] Notation Build R S U := (SubChoice_isSubComNzRing.Build R S U) (only parsing). End SubChoice_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzRing instead.")] Notation SubChoice_isSubComRing R S U := (SubChoice_isSubComNzRing R S U) (only parsing). HB.builders Context (R : comNzRingType) S U of SubChoice_isSubComNzRing R S U. HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U subring_closed_subproof. HB.instance Definition _ := SubNzRing_isSubComNzRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) S W of SubChoice V S W := { subsemimod_closed_subproof : subsemimod_closed S }. HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W of SubChoice_isSubLSemiModule R V S W. HB.instance Definition _ := SubChoice_isSubNmodule.Build V S W (subsemimod_closedD subsemimod_closed_subproof). HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W subsemimod_closed_subproof. HB.end. HB.factory Record SubChoice_isSubLmodule (R : pzRingType) (V : lmodType R) S W of SubChoice V S W := { submod_closed_subproof : submod_closed S }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of SubChoice_isSubLmodule R V S W. HB.instance Definition _ := SubChoice_isSubZmodule.Build V S W (submod_closedB submod_closed_subproof). HB.instance Definition _ := SubZmodule_isSubLmodule.Build R V S W submod_closed_subproof. HB.end. (* TODO: SubChoice_isSubLSemiAlgebra? *) HB.factory Record SubChoice_isSubLalgebra (R : pzRingType) (A : lalgType R) S W of SubChoice A S W := { subalg_closed_subproof : subalg_closed S }. HB.builders Context (R : pzRingType) (A : lalgType R) S W of SubChoice_isSubLalgebra R A S W. HB.instance Definition _ := SubChoice_isSubNzRing.Build A S W (subalg_closedBM subalg_closed_subproof). HB.instance Definition _ := SubZmodule_isSubLmodule.Build R A S W (subalg_closedZ subalg_closed_subproof). HB.instance Definition _ := SubNzRing_SubLmodule_isSubLalgebra.Build R A S W. HB.end. (* TODO: SubChoice_isSubSemiAlgebra? *) HB.factory Record SubChoice_isSubAlgebra (R : pzRingType) (A : algType R) S W of SubChoice A S W := { subalg_closed_subproof : subalg_closed S }. HB.builders Context (R : pzRingType) (A : algType R) S W of SubChoice_isSubAlgebra R A S W. HB.instance Definition _ := SubChoice_isSubLalgebra.Build R A S W subalg_closed_subproof. HB.instance Definition _ := SubLalgebra_isSubAlgebra.Build R A S W. HB.end. HB.factory Record SubChoice_isSubUnitRing (R : unitRingType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : unitRingType) S U of SubChoice_isSubUnitRing R S U. HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U (divring_closedBM divring_closed_subproof). HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U divring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubComUnitRing (R : comUnitRingType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : comUnitRingType) S U of SubChoice_isSubComUnitRing R S U. HB.instance Definition _ := SubChoice_isSubComNzRing.Build R S U (divring_closedBM divring_closed_subproof). HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U divring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubIntegralDomain (R : idomainType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : idomainType) S U of SubChoice_isSubIntegralDomain R S U. HB.instance Definition _ := SubChoice_isSubComUnitRing.Build R S U divring_closed_subproof. HB.instance Definition _ := SubComUnitRing_isSubIntegralDomain.Build R S U. HB.end. Module SubExports. Notation "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]" := (SubChoice_isSubNmodule.Build _ _ U rpred0D) (format "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]" := (SubChoice_isSubZmodule.Build _ _ U (zmodClosedP _)) (format "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]" := (SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _)) (format "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ SubNmodule_isSubNzSemiRing of U by <: ] instead.")] Notation "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]" := (SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _)) (format "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]" := (SubNzSemiRing_isSubComNzSemiRing.Build _ _ U) (format "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzSemiRing_isSubComNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]" := (SubNzSemiRing_isSubComNzSemiRing.Build _ _ U) (format "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubComNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]" := (SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubZmodule_isSubNzRing' of U by <: ] instead.")] Notation "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]" := (SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubNzRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]" := (SubNzRing_isSubComNzRing.Build _ _ U) (format "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_isSubComNzRing' of U by <: ] instead.")] Notation "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]" := (SubNzRing_isSubComNzRing.Build _ _ U) (format "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubComNzRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]" := (SubNmodule_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _)) (format "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]" := (SubChoice_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _)) (format "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]" := (SubZmodule_isSubLmodule.Build _ _ _ U (submodClosedP _)) (format "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]" := (SubChoice_isSubLmodule.Build _ _ _ U (submodClosedP _)) (format "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]" := (SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build _ _ _ U) (format "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]") : form_scope. (* TODO: SubChoice_isSubLSemiAlgebra? *) Notation "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" := (SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U) (format "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_SubLmodule_isSubLalgebra' of U by <: ] instead.")] Notation "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" := (SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U) (format "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]" := (SubChoice_isSubLalgebra.Build _ _ _ U (subalgClosedP _)) (format "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]" := (SubLSemiAlgebra_isSubSemiAlgebra.Build _ _ _ U) (format "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]") : form_scope. (* TODO: SubChoice_isSubSemiAlgebra? *) Notation "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]" := (SubLalgebra_isSubAlgebra.Build _ _ _ U) (format "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]" := (SubChoice_isSubAlgebra.Build _ _ _ U (subalgClosedP _)) (format "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]" := (SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_isSubUnitRing' of U by <: ] instead.")] Notation "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]" := (SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]" := (SubChoice_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]" := (SubChoice_isSubComUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]" := (SubComUnitRing_isSubIntegralDomain.Build _ _ U) (format "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]" := (SubChoice_isSubIntegralDomain.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]" := (SubIntegralDomain_isSubField.Build _ _ U (frefl _)) (format "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]") : form_scope. End SubExports. HB.export SubExports. Module Theory. Definition addrA := @addrA. Definition addrC := @addrC. Definition add0r := @add0r. Definition addNr := @addNr. Definition addr0 := addr0. Definition addrN := addrN. Definition subrr := subrr. Definition addrCA := addrCA. Definition addrAC := addrAC. Definition addrACA := addrACA. Definition addKr := addKr. Definition addNKr := addNKr. Definition addrK := addrK. Definition addrNK := addrNK. Definition subrK := subrK. Definition subKr := subKr. Definition addrI := @addrI. Definition addIr := @addIr. Definition subrI := @subrI. Definition subIr := @subIr. Arguments addrI {V} y [x1 x2]. Arguments addIr {V} x [x1 x2]. Arguments subrI {V} y [x1 x2]. Arguments subIr {V} x [x1 x2]. Definition opprK := @opprK. Arguments opprK {V}. Definition oppr_inj := @oppr_inj. Arguments oppr_inj {V} [x1 x2]. Definition oppr0 := oppr0. Definition oppr_eq0 := oppr_eq0. Definition opprD := opprD. Definition opprB := opprB. Definition addrKA := addrKA. Definition subrKA := subrKA. Definition subr0 := subr0. Definition sub0r := sub0r. Definition subr_eq := subr_eq. Definition addr0_eq := addr0_eq. Definition subr0_eq := subr0_eq. Definition subr_eq0 := subr_eq0. Definition addr_eq0 := addr_eq0. Definition eqr_opp := eqr_opp. Definition eqr_oppLR := eqr_oppLR. Definition sumrN := sumrN. Definition sumrB := sumrB. Definition sumrMnl := sumrMnl. Definition sumrMnr := sumrMnr. Definition sumr_const := sumr_const. Definition sumr_const_nat := sumr_const_nat. Definition telescope_sumr := telescope_sumr. Definition telescope_sumr_eq := @telescope_sumr_eq. Arguments telescope_sumr_eq {V n m} f u. Definition mulr0n := mulr0n. Definition mulr1n := mulr1n. Definition mulr2n := mulr2n. Definition mulrS := mulrS. Definition mulrSr := mulrSr. Definition mulrb := mulrb. Definition mul0rn := mul0rn. Definition mulNrn := mulNrn. Definition mulrnDl := mulrnDl. Definition mulrnDr := mulrnDr. Definition mulrnBl := mulrnBl. Definition mulrnBr := mulrnBr. Definition mulrnA := mulrnA. Definition mulrnAC := mulrnAC. Definition iter_addr := iter_addr. Definition iter_addr_0 := iter_addr_0. Definition mulrA := @mulrA. Definition mul1r := @mul1r. Definition mulr1 := @mulr1. Definition mulrDl := @mulrDl. Definition mulrDr := @mulrDr. Definition oner_neq0 := @oner_neq0. Definition oner_eq0 := oner_eq0. Definition mul0r := @mul0r. Definition mulr0 := @mulr0. Definition mulrN := mulrN. Definition mulNr := mulNr. Definition mulrNN := mulrNN. Definition mulN1r := mulN1r. Definition mulrN1 := mulrN1. Definition mulr_suml := mulr_suml. Definition mulr_sumr := mulr_sumr. Definition mulrBl := mulrBl. Definition mulrBr := mulrBr. Definition mulrnAl := mulrnAl. Definition mulrnAr := mulrnAr. Definition mulr_natl := mulr_natl. Definition mulr_natr := mulr_natr. Definition natrD := natrD. Definition nat1r := nat1r. Definition natr1 := natr1. Arguments natr1 {R} n. Arguments nat1r {R} n. Definition natrB := natrB. Definition natr_sum := natr_sum. Definition natrM := natrM. Definition natrX := natrX. Definition expr0 := expr0. Definition exprS := exprS. Definition expr1 := expr1. Definition expr2 := expr2. Definition expr0n := expr0n. Definition expr1n := expr1n. Definition exprD := exprD. Definition exprSr := exprSr. Definition expr_sum := expr_sum. Definition commr_sym := commr_sym. Definition commr_refl := commr_refl. Definition commr0 := commr0. Definition commr1 := commr1. Definition commrN := commrN. Definition commrN1 := commrN1. Definition commrD := commrD. Definition commrB := commrB. Definition commr_sum := commr_sum. Definition commr_prod := commr_prod. Definition commrMn := commrMn. Definition commrM := commrM. Definition commr_nat := commr_nat. Definition commrX := commrX. Definition exprMn_comm := exprMn_comm. Definition commr_sign := commr_sign. Definition exprMn_n := exprMn_n. Definition exprM := exprM. Definition exprAC := exprAC. Definition expr_mod := expr_mod. Definition expr_dvd := expr_dvd. Definition signr_odd := signr_odd. Definition signr_eq0 := signr_eq0. Definition mulr_sign := mulr_sign. Definition signr_addb := signr_addb. Definition signrN := signrN. Definition signrE := signrE. Definition mulr_signM := mulr_signM. Definition exprNn := exprNn. Definition sqrrN := sqrrN. Definition sqrr_sign := sqrr_sign. Definition signrMK := signrMK. Definition mulrI_eq0 := mulrI_eq0. Definition lreg_neq0 := lreg_neq0. Definition mulrI0_lreg := mulrI0_lreg. Definition lregN := lregN. Definition lreg1 := lreg1. Definition lregM := lregM. Definition lregX := lregX. Definition lreg_sign := lreg_sign. Definition lregP {R x} := @lregP R x. Definition mulIr_eq0 := mulIr_eq0. Definition mulIr0_rreg := mulIr0_rreg. Definition rreg_neq0 := rreg_neq0. Definition rregN := rregN. Definition rreg1 := rreg1. Definition rregM := rregM. Definition revrX := revrX. Definition rregX := rregX. Definition rregP {R x} := @rregP R x. Definition exprDn_comm := exprDn_comm. Definition exprBn_comm := exprBn_comm. Definition subrXX_comm := subrXX_comm. Definition exprD1n := exprD1n. Definition subrX1 := subrX1. Definition sqrrD1 := sqrrD1. Definition sqrrB1 := sqrrB1. Definition subr_sqr_1 := subr_sqr_1. Definition pcharf0 := pcharf0. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")] Definition charf0 := pcharf0. Definition pcharf_prime := pcharf_prime. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")] Definition charf_prime := pcharf_prime. Definition mulrn_pchar := mulrn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")] Definition mulrn_char := mulrn_pchar. Definition dvdn_pcharf := dvdn_pcharf. #[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")] Definition dvdn_charf := dvdn_pcharf. Definition pcharf_eq := pcharf_eq. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")] Definition charf_eq := pcharf_eq. Definition bin_lt_pcharf_0 := bin_lt_pcharf_0. #[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")] Definition bin_lt_charf_0 := bin_lt_pcharf_0. Definition pFrobenius_autE := pFrobenius_autE. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")] Definition Frobenius_autE := pFrobenius_autE. Definition pFrobenius_aut0 := pFrobenius_aut0. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")] Definition Frobenius_aut0 := pFrobenius_aut0. Definition pFrobenius_aut1 := pFrobenius_aut1. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")] Definition Frobenius_aut1 := pFrobenius_aut1. Definition pFrobenius_autD_comm := pFrobenius_autD_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")] Definition Frobenius_autD_comm := pFrobenius_autD_comm. Definition pFrobenius_autMn := pFrobenius_autMn. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")] Definition Frobenius_autMn := pFrobenius_autMn. Definition pFrobenius_aut_nat := pFrobenius_aut_nat. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")] Definition Frobenius_aut_nat := pFrobenius_aut_nat. Definition pFrobenius_autM_comm := pFrobenius_autM_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")] Definition Frobenius_autM_comm := pFrobenius_autM_comm. Definition pFrobenius_autX := pFrobenius_autX. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")] Definition Frobenius_autX := pFrobenius_autX. Definition pFrobenius_autN := pFrobenius_autN. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")] Definition Frobenius_autN := pFrobenius_autN. Definition pFrobenius_autB_comm := pFrobenius_autB_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")] Definition Frobenius_autB_comm := pFrobenius_autB_comm. Definition exprNn_pchar := exprNn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")] Definition exprNn_char := exprNn_pchar. Definition addrr_pchar2 := addrr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")] Definition addrr_char2 := addrr_pchar2. Definition oppr_pchar2 := oppr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")] Definition oppr_char2 := oppr_pchar2. Definition addrK_pchar2 := addrK_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")] Definition addrK_char2 := addrK_pchar2. Definition addKr_pchar2 := addKr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")] Definition addKr_char2 := addKr_pchar2. Definition iter_mulr := iter_mulr. Definition iter_mulr_1 := iter_mulr_1. Definition prodr_const := prodr_const. Definition prodr_const_nat := prodr_const_nat. Definition mulrC := @mulrC. Definition mulrCA := mulrCA. Definition mulrAC := mulrAC. Definition mulrACA := mulrACA. Definition exprMn := exprMn. Definition prodrXl := prodrXl. Definition prodrXr := prodrXr. Definition prodrN := prodrN. Definition prodrMn_const := prodrMn_const. Definition prodrM_comm := prodrM_comm. Definition prodrMl_comm := prodrMl_comm. Definition prodrMr_comm := prodrMr_comm. Definition prodrMl := prodrMl. Definition prodrMr := prodrMr. Definition prodrMn := prodrMn. Definition rev_prodr := rev_prodr. Definition natr_prod := natr_prod. Definition prodr_undup_exp_count := prodr_undup_exp_count. Definition exprDn := exprDn. Definition exprBn := exprBn. Definition subrXX := subrXX. Definition sqrrD := sqrrD. Definition sqrrB := sqrrB. Definition subr_sqr := subr_sqr. Definition subr_sqrDB := subr_sqrDB. Definition exprDn_pchar := exprDn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")] Definition exprDn_char := exprDn_pchar. Definition mulrV := mulrV. Definition divrr := divrr. Definition mulVr := mulVr. Definition invr_out := invr_out. Definition unitrP {R x} := @unitrP R x. Definition mulKr := mulKr. Definition mulVKr := mulVKr. Definition mulrK := mulrK. Definition mulrVK := mulrVK. Definition divrK := divrK. Definition mulrI := mulrI. Definition mulIr := mulIr. Definition divrI := divrI. Definition divIr := divIr. Definition telescope_prodr := telescope_prodr. Definition telescope_prodr_eq := @telescope_prodr_eq. Arguments telescope_prodr_eq {R n m} f u. Definition commrV := commrV. Definition unitrE := unitrE. Definition invrK := @invrK. Arguments invrK {R}. Definition invr_inj := @invr_inj. Arguments invr_inj {R} [x1 x2]. Definition unitrV := unitrV. Definition unitr1 := unitr1. Definition invr1 := invr1. Definition divr1 := divr1. Definition div1r := div1r. Definition natr_div := natr_div. Definition unitr0 := unitr0. Definition invr0 := invr0. Definition unitrN1 := unitrN1. Definition unitrN := unitrN. Definition invrN1 := invrN1. Definition invrN := invrN. Definition divrNN := divrNN. Definition divrN := divrN. Definition invr_sign := invr_sign. Definition unitrMl := unitrMl. Definition unitrMr := unitrMr. Definition invrM := invrM. Definition unitr_prod := unitr_prod. Definition unitr_prod_in := unitr_prod_in. Definition invr_eq0 := invr_eq0. Definition invr_eq1 := invr_eq1. Definition invr_neq0 := invr_neq0. Definition rev_unitrP := rev_unitrP. Definition rev_prodrV := rev_prodrV. Definition unitrM_comm := unitrM_comm. Definition unitrX := unitrX. Definition unitrX_pos := unitrX_pos. Definition exprVn := exprVn. Definition exprB := exprB. Definition invr_signM := invr_signM. Definition divr_signM := divr_signM. Definition rpred0D := @rpred0D. Definition rpred0 := rpred0. Definition rpredD := rpredD. Definition rpredNr := @rpredNr. Definition rpred_sum := rpred_sum. Definition rpredMn := rpredMn. Definition rpredN := rpredN. Definition rpredB := rpredB. Definition rpredBC := rpredBC. Definition rpredMNn := rpredMNn. Definition rpredDr := rpredDr. Definition rpredDl := rpredDl. Definition rpredBr := rpredBr. Definition rpredBl := rpredBl. Definition zmodClosedP := zmodClosedP. Definition rpredMsign := rpredMsign. Definition rpred1M := @rpred1M. Definition rpred1 := @rpred1. Definition rpredM := @rpredM. Definition rpred_prod := rpred_prod. Definition rpredX := rpredX. Definition rpred_nat := rpred_nat. Definition rpredN1 := rpredN1. Definition rpred_sign := rpred_sign. Definition semiringClosedP := semiringClosedP. Definition subringClosedP := subringClosedP. Definition rpredZsign := rpredZsign. Definition rpredZnat := rpredZnat. Definition submodClosedP := submodClosedP. Definition subalgClosedP := subalgClosedP. Definition rpredZ := @rpredZ. Definition rpredVr := @rpredVr. Definition rpredV := rpredV. Definition rpred_div := rpred_div. Definition rpredXN := rpredXN. Definition rpredZeq := rpredZeq. Definition pchar_lalg := pchar_lalg. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")] Definition char_lalg := pchar_lalg. Definition rpredMr := rpredMr. Definition rpredMl := rpredMl. Definition rpred_divr := rpred_divr. Definition rpred_divl := rpred_divl. Definition divringClosedP := divringClosedP. Definition eq_eval := eq_eval. Definition eval_tsubst := eval_tsubst. Definition eq_holds := eq_holds. Definition holds_fsubst := holds_fsubst. Definition unitrM := unitrM. Definition unitr_prodP := unitr_prodP. Definition prodrV := prodrV. Definition unitrPr {R x} := @unitrPr R x. Definition expr_div_n := expr_div_n. Definition mulr1_eq := mulr1_eq. Definition divr1_eq := divr1_eq. Definition divKr := divKr. Definition mulf_eq0 := mulf_eq0. Definition prodf_eq0 := prodf_eq0. Definition prodf_seq_eq0 := prodf_seq_eq0. Definition mulf_neq0 := mulf_neq0. Definition prodf_neq0 := prodf_neq0. Definition prodf_seq_neq0 := prodf_seq_neq0. Definition expf_eq0 := expf_eq0. Definition sqrf_eq0 := sqrf_eq0. Definition expf_neq0 := expf_neq0. Definition natf_neq0_pchar := natf_neq0_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")] Definition natf_neq0 := natf_neq0_pchar. Definition natf0_pchar := natf0_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")] Definition natf0_char := natf0_pchar. Definition pcharf'_nat := pcharf'_nat. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")] Definition charf'_nat := pcharf'_nat. Definition pcharf0P := pcharf0P. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")] Definition charf0P := pcharf0P. Definition eqf_sqr := eqf_sqr. Definition mulfI := mulfI. Definition mulIf := mulIf. Definition divfI := divfI. Definition divIf := divIf. Definition sqrf_eq1 := sqrf_eq1. Definition expfS_eq1 := expfS_eq1. Definition fieldP := @fieldP. Definition unitfE := unitfE. Definition mulVf := mulVf. Definition mulfV := mulfV. Definition divff := divff. Definition mulKf := mulKf. Definition mulVKf := mulVKf. Definition mulfK := mulfK. Definition mulfVK := mulfVK. Definition divfK := divfK. Definition divKf := divKf. Definition invfM := invfM. Definition invf_div := invf_div. Definition expfB_cond := expfB_cond. Definition expfB := expfB. Definition prodfV := prodfV. Definition prodf_div := prodf_div. Definition telescope_prodf := telescope_prodf. Definition telescope_prodf_eq := @telescope_prodf_eq. Arguments telescope_prodf_eq {F n m} f u. Definition addf_div := addf_div. Definition mulf_div := mulf_div. Definition eqr_div := eqr_div. Definition eqr_sum_div := eqr_sum_div. Definition pchar0_natf_div := pchar0_natf_div. #[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")] Definition char0_natf_div := pchar0_natf_div. Definition fpredMr := fpredMr. Definition fpredMl := fpredMl. Definition fpred_divr := fpred_divr. Definition fpred_divl := fpred_divl. Definition satP {F e f} := @satP F e f. Definition eq_sat := eq_sat. Definition solP {F n f} := @solP F n f. Definition eq_sol := eq_sol. Definition size_sol := size_sol. Definition solve_monicpoly := @solve_monicpoly. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `nmod_morphism` instead")] Definition semi_additive := semi_additive. Definition nmod_morphism := nmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism` instead")] Definition additive := additive. Definition zmod_morphism := zmod_morphism. Definition raddf0 := raddf0. Definition raddf_eq0 := raddf_eq0. Definition raddf_inj := raddf_inj. Definition raddfN := raddfN. Definition raddfD := raddfD. Definition raddfB := raddfB. Definition raddf_sum := raddf_sum. Definition raddfMn := raddfMn. Definition raddfMNn := raddfMNn. Definition raddfMnat := raddfMnat. Definition raddfMsign := raddfMsign. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_nmod_morphism` instead")] Definition can2_semi_additive := can2_semi_additive. Definition can2_nmod_morphism := can2_nmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_zmod_morphism` instead")] Definition can2_additive := can2_additive. Definition can2_zmod_morphism := can2_zmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")] Definition multiplicative := multiplicative. Definition monoid_morphism := monoid_morphism. Definition rmorph0 := rmorph0. Definition rmorphN := rmorphN. Definition rmorphD := rmorphD. Definition rmorphB := rmorphB. Definition rmorph_sum := rmorph_sum. Definition rmorphMn := rmorphMn. Definition rmorphMNn := rmorphMNn. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `rmorphism_monoidP` instead")] Definition rmorphismMP := rmorphismMP. Definition rmorphism_monoidP := rmorphism_monoidP. Definition rmorph1 := rmorph1. Definition rmorph_eq1 := rmorph_eq1. Definition rmorphM := rmorphM. Definition rmorphMsign := rmorphMsign. Definition rmorph_nat := rmorph_nat. Definition rmorph_eq_nat := rmorph_eq_nat. Definition rmorph_prod := rmorph_prod. Definition rmorphXn := rmorphXn. Definition rmorphN1 := rmorphN1. Definition rmorph_sign := rmorph_sign. Definition rmorph_pchar := rmorph_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")] Definition rmorph_char := rmorph_pchar. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_monoid_morphism` instead")] Definition can2_rmorphism := can2_rmorphism. Definition can2_monoid_morphism := can2_monoid_morphism. Definition rmorph_comm := rmorph_comm. Definition rmorph_unit := rmorph_unit. Definition rmorphV := rmorphV. Definition rmorph_div := rmorph_div. Definition fmorph_eq0 := fmorph_eq0. Definition fmorph_inj := @fmorph_inj. Arguments fmorph_inj {F R} f [x1 x2]. Definition fmorph_eq := fmorph_eq. Definition fmorph_eq1 := fmorph_eq1. Definition fmorph_pchar := fmorph_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")] Definition fmorph_char := fmorph_pchar. Definition fmorph_unit := fmorph_unit. Definition fmorphV := fmorphV. Definition fmorph_div := fmorph_div. Definition scalerA := scalerA. Definition scale1r := @scale1r. Definition scalerDr := @scalerDr. Definition scalerDl := @scalerDl. Definition scaler0 := scaler0. Definition scale0r := @scale0r. Definition scaleNr := scaleNr. Definition scaleN1r := scaleN1r. Definition scalerN := scalerN. Definition scalerBl := scalerBl. Definition scalerBr := scalerBr. Definition scaler_nat := scaler_nat. Definition scalerMnl := scalerMnl. Definition scalerMnr := scalerMnr. Definition scaler_suml := scaler_suml. Definition scaler_sumr := scaler_sumr. Definition scaler_eq0 := scaler_eq0. Definition scalerK := scalerK. Definition scalerKV := scalerKV. Definition scalerI := scalerI. Definition scalerAl := @scalerAl. Definition mulr_algl := mulr_algl. Definition scaler_sign := scaler_sign. Definition signrZK := signrZK. Definition scalerCA := scalerCA. Definition scalerAr := @scalerAr. Definition mulr_algr := mulr_algr. Definition comm_alg := comm_alg. Definition exprZn := exprZn. Definition scaler_prodl := scaler_prodl. Definition scaler_prodr := scaler_prodr. Definition scaler_prod := scaler_prod. Definition scaler_injl := scaler_injl. Definition scaler_unit := scaler_unit. Definition invrZ := invrZ. Definition raddfZnat := raddfZnat. Definition raddfZsign := raddfZsign. Definition in_algE := in_algE. Definition scalable_for := scalable_for. Definition semilinear_for := semilinear_for. Definition linear_for := linear_for. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `nmod_morphism_semilinear` instead")] Definition additive_semilinear := additive_semilinear. Definition nmod_morphism_semilinear := nmod_morphism_semilinear. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism_linear` instead")] Definition additive_linear := additive_linear. Definition zmod_morphism_linear := zmod_morphism_linear. Definition scalable_semilinear := scalable_semilinear. Definition scalable_linear := scalable_linear. Definition linear0 := linear0. Definition linearN := linearN. Definition linearD := linearD. Definition linearB := linearB. Definition linear_sum := linear_sum. Definition linearMn := linearMn. Definition linearMNn := linearMNn. Definition semilinearP := semilinearP. Definition linearP := linearP. Definition linearZ_LR := linearZ_LR. Definition linearZ := linearZ. Definition semilinearPZ := semilinearPZ. Definition linearPZ := linearPZ. Definition linearZZ := linearZZ. Definition semiscalarP := semiscalarP. Definition scalarP := scalarP. Definition scalarZ := scalarZ. Definition can2_scalable := can2_scalable. Definition can2_linear := can2_linear. Definition can2_semilinear := can2_semilinear. Definition rmorph_alg := rmorph_alg. Definition imaginary_exists := imaginary_exists. Definition raddf := (raddf0, raddfN, raddfD, raddfMn). Definition rmorphE := (rmorphD, rmorph0, rmorphB, rmorphN, rmorphMNn, rmorphMn, rmorph1, rmorphXn). Definition linearE := (linearD, linear0, linearB, linearMNn, linearMn, linearZ). Notation null_fun V := (null_fun V) (only parsing). Notation in_alg A := (in_alg A) (only parsing). End Theory. Module AllExports. HB.reexport. End AllExports. End GRing. Export AllExports. Export Scale.Exports. Export ClosedExports. #[deprecated(since="mathcomp 2.4.0", note="Try pzSemiRingType (the potentially-zero counterpart) first, or use nzSemiRingType instead.")] Notation semiRingType := (nzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try pzRingType (the potentially-zero counterpart) first, or use nzRingType instead.")] Notation ringType := (nzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try comPzSemiRingType (the potentially-zero counterpart) first, or use comNzSemiRingType instead.")] Notation comSemiRingType := (comNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try comPzRingType (the potentially-zero counterpart) first, or use comNzRingType instead.")] Notation comRingType := (comNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subPzSemiRingType (the potentially-zero counterpart) first, or use subNzSemiRingType instead.")] Notation subSemiRingType := (subNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subComPzSemiRingType (the potentially-zero counterpart) first, or use subComNzSemiRingType instead.")] Notation subComSemiRingType := (subComNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subPzRingType (the potentially-zero counterpart) first, or use subNzRingType instead.")] Notation subRingType := (subNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subComPzRingType (the potentially-zero counterpart) first, or use subComNzRingType instead.")] Notation subComNzRingType := (subComNzRingType) (only parsing). Notation addrClosed := addrClosed. Notation opprClosed := opprClosed. Variant Ione := IOne : Ione. Inductive Inatmul := | INatmul : Ione -> nat -> Inatmul | IOpp : Inatmul -> Inatmul. Variant Idummy_placeholder :=. Definition parse (x : Number.int) : Inatmul := match x with | Number.IntDecimal (Decimal.Pos u) => INatmul IOne (Nat.of_uint u) | Number.IntDecimal (Decimal.Neg u) => IOpp (INatmul IOne (Nat.of_uint u)) | Number.IntHexadecimal (Hexadecimal.Pos u) => INatmul IOne (Nat.of_hex_uint u) | Number.IntHexadecimal (Hexadecimal.Neg u) => IOpp (INatmul IOne (Nat.of_hex_uint u)) end. Definition print (x : Inatmul) : option Number.int := match x with | INatmul IOne n => Some (Number.IntDecimal (Decimal.Pos (Nat.to_uint n))) | IOpp (INatmul IOne n) => Some (Number.IntDecimal (Decimal.Neg (Nat.to_uint n))) | _ => None end. Arguments GRing.one {_}. Set Warnings "-via-type-remapping,-via-type-mismatch". Number Notation Idummy_placeholder parse print (via Inatmul mapping [[natmul] => INatmul, [opp] => IOpp, [one] => IOne]) : ring_scope. Set Warnings "via-type-remapping,via-type-mismatch". Arguments GRing.one : clear implicits. Notation "0" := (@zero _) : ring_scope. Notation "-%R" := (@opp _) : ring_scope. Notation "- x" := (opp x) : ring_scope. Notation "+%R" := (@add _) : function_scope. Notation "x + y" := (add x y) : ring_scope. Notation "x - y" := (add x (- y)) : ring_scope. Arguments natmul : simpl never. Notation "x *+ n" := (natmul x n) : ring_scope. Notation "x *- n" := (opp (x *+ n)) : ring_scope. Notation "s `_ i" := (seq.nth 0%R s%R i) : ring_scope. Notation support := 0.-support. Notation "1" := (@one _) : ring_scope. Notation "- 1" := (opp 1) : ring_scope. Notation "n %:R" := (natmul 1 n) : ring_scope. Arguments GRing.pchar R%_type. Notation "[ 'pchar' R ]" := (GRing.pchar R) : ring_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [pchar R] instead.")] Notation "[ 'char' R ]" := (GRing.pchar R) : ring_scope. Notation has_pchar0 R := (GRing.pchar R =i pred0). #[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")] Notation has_char0 R := (GRing.pchar R =i pred0). Notation pFrobenius_aut chRp := (pFrobenius_aut chRp). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")] Notation Frobenius_aut chRp := (pFrobenius_aut chRp). Notation "*%R" := (@mul _) : function_scope. Notation "x * y" := (mul x y) : ring_scope. Arguments exp : simpl never. Notation "x ^+ n" := (exp x n) : ring_scope. Notation "x ^-1" := (inv x) : ring_scope. Notation "x ^- n" := (inv (x ^+ n)) : ring_scope. Notation "x / y" := (mul x y^-1) : ring_scope. Notation "*:%R" := (@scale _ _) : function_scope. Notation "a *: m" := (scale a m) : ring_scope. Notation "k %:A" := (scale k 1) : ring_scope. Notation "\0" := (null_fun _) : ring_scope. Notation "f \+ g" := (add_fun f g) : ring_scope. Notation "f \- g" := (sub_fun f g) : ring_scope. Notation "\- f" := (opp_fun f) : ring_scope. Notation "a \*: f" := (scale_fun a f) : ring_scope. Notation "x \*o f" := (mull_fun x f) : ring_scope. Notation "x \o* f" := (mulr_fun x f) : ring_scope. Notation "f \* g" := (mul_fun f g) : ring_scope. Arguments mull_fun {_ _} a f _ /. Arguments mulr_fun {_ _} a f _ /. Arguments scale_fun {_ _ _} a f _ /. Arguments mul_fun {_ _} f g _ /. Notation "\sum_ ( i <- r | P ) F" := (\big[+%R/0%R]_(i <- r | P%B) F%R) : ring_scope. Notation "\sum_ ( i <- r ) F" := (\big[+%R/0%R]_(i <- r) F%R) : ring_scope. Notation "\sum_ ( m <= i < n | P ) F" := (\big[+%R/0%R]_(m <= i < n | P%B) F%R) : ring_scope. Notation "\sum_ ( m <= i < n ) F" := (\big[+%R/0%R]_(m <= i < n) F%R) : ring_scope. Notation "\sum_ ( i | P ) F" := (\big[+%R/0%R]_(i | P%B) F%R) : ring_scope. Notation "\sum_ i F" := (\big[+%R/0%R]_i F%R) : ring_scope. Notation "\sum_ ( i : t | P ) F" := (\big[+%R/0%R]_(i : t | P%B) F%R) (only parsing) : ring_scope. Notation "\sum_ ( i : t ) F" := (\big[+%R/0%R]_(i : t) F%R) (only parsing) : ring_scope. Notation "\sum_ ( i < n | P ) F" := (\big[+%R/0%R]_(i < n | P%B) F%R) : ring_scope. Notation "\sum_ ( i < n ) F" := (\big[+%R/0%R]_(i < n) F%R) : ring_scope. Notation "\sum_ ( i 'in' A | P ) F" := (\big[+%R/0%R]_(i in A | P%B) F%R) : ring_scope. Notation "\sum_ ( i 'in' A ) F" := (\big[+%R/0%R]_(i in A) F%R) : ring_scope. Notation "\prod_ ( i <- r | P ) F" := (\big[*%R/1%R]_(i <- r | P%B) F%R) : ring_scope. Notation "\prod_ ( i <- r ) F" := (\big[*%R/1%R]_(i <- r) F%R) : ring_scope. Notation "\prod_ ( m <= i < n | P ) F" := (\big[*%R/1%R]_(m <= i < n | P%B) F%R) : ring_scope. Notation "\prod_ ( m <= i < n ) F" := (\big[*%R/1%R]_(m <= i < n) F%R) : ring_scope. Notation "\prod_ ( i | P ) F" := (\big[*%R/1%R]_(i | P%B) F%R) : ring_scope. Notation "\prod_ i F" := (\big[*%R/1%R]_i F%R) : ring_scope. Notation "\prod_ ( i : t | P ) F" := (\big[*%R/1%R]_(i : t | P%B) F%R) (only parsing) : ring_scope. Notation "\prod_ ( i : t ) F" := (\big[*%R/1%R]_(i : t) F%R) (only parsing) : ring_scope. Notation "\prod_ ( i < n | P ) F" := (\big[*%R/1%R]_(i < n | P%B) F%R) : ring_scope. Notation "\prod_ ( i < n ) F" := (\big[*%R/1%R]_(i < n) F%R) : ring_scope. Notation "\prod_ ( i 'in' A | P ) F" := (\big[*%R/1%R]_(i in A | P%B) F%R) : ring_scope. Notation "\prod_ ( i 'in' A ) F" := (\big[*%R/1%R]_(i in A) F%R) : ring_scope. Notation "R ^c" := (converse R) : type_scope. Notation "R ^o" := (regular R) : type_scope. Bind Scope term_scope with term. Bind Scope term_scope with formula. Notation "''X_' i" := (Var _ i) : term_scope. Notation "n %:R" := (NatConst _ n) : term_scope. Notation "0" := 0%:R%T : term_scope. Notation "1" := 1%:R%T : term_scope. Notation "x %:T" := (Const x) : term_scope. Infix "+" := Add : term_scope. Notation "- t" := (Opp t) : term_scope. Notation "t - u" := (Add t (- u)) : term_scope. Infix "*" := Mul : term_scope. Infix "*+" := NatMul : term_scope. Notation "t ^-1" := (Inv t) : term_scope. Notation "t / u" := (Mul t u^-1) : term_scope. Infix "^+" := Exp : term_scope. Infix "==" := Equal : term_scope. Notation "x != y" := (GRing.Not (x == y)) : term_scope. Infix "/\" := And : term_scope. Infix "\/" := Or : term_scope. Infix "==>" := Implies : term_scope. Notation "~ f" := (Not f) : term_scope. Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope. Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope. (* Lifting Structure from the codomain of finfuns. *) Section Sum. Variables (aT : finType) (rT : nmodType). Variables (I : Type) (r : seq I) (P : pred I) (F : I -> {ffun aT -> rT}). Lemma sum_ffunE x : (\sum_(i <- r | P i) F i) x = \sum_(i <- r | P i) F i x. Proof. by elim/big_rec2: _ => // [|i _ y _ <-]; rewrite !ffunE. Qed. Lemma sum_ffun : \sum_(i <- r | P i) F i = [ffun x => \sum_(i <- r | P i) F i x]. Proof. by apply/ffunP=> i; rewrite sum_ffunE ffunE. Qed. End Sum. Section FinFunSemiRing. (* As rings require 1 != 0 in order to lift a ring structure over finfuns *) (* we need evidence that the domain is non-empty. *) Variable (aT : finType) (R : pzSemiRingType). Definition ffun_one : {ffun aT -> R} := [ffun => 1]. Definition ffun_mul (f g : {ffun aT -> R}) := [ffun x => f x * g x]. Fact ffun_mulA : associative ffun_mul. Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrA. Qed. Fact ffun_mul_1l : left_id ffun_one ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul1r. Qed. Fact ffun_mul_1r : right_id ffun_one ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr1. Qed. Fact ffun_mul_addl : left_distributive ffun_mul (@ffun_add _ _). Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDl. Qed. Fact ffun_mul_addr : right_distributive ffun_mul (@ffun_add _ _). Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDr. Qed. Fact ffun_mul_0l : left_zero (@ffun_zero _ _) ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul0r. Qed. Fact ffun_mul_0r : right_zero (@ffun_zero _ _) ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr0. Qed. #[export] HB.instance Definition _ := Nmodule_isPzSemiRing.Build {ffun aT -> R} ffun_mulA ffun_mul_1l ffun_mul_1r ffun_mul_addl ffun_mul_addr ffun_mul_0l ffun_mul_0r. Definition ffun_semiring : pzSemiRingType := {ffun aT -> R}. End FinFunSemiRing. Section FinFunSemiRing. Variable (aT : finType) (R : nzSemiRingType) (a : aT). Fact ffun1_nonzero : ffun_one aT R != 0. Proof. by apply/eqP => /ffunP/(_ a)/eqP; rewrite !ffunE oner_eq0. Qed. (* TODO_HB uncomment once ffun_ring below is fixed #[export] HB.instance Definition _ := PzSemiRing_isNonZero.Build {ffun aT -> R} ffun1_nonzero. *) End FinFunSemiRing. HB.instance Definition _ (aT : finType) (R : pzRingType) := Zmodule_isPzRing.Build {ffun aT -> R} (@ffun_mulA _ _) (@ffun_mul_1l _ _) (@ffun_mul_1r _ _) (@ffun_mul_addl _ _) (@ffun_mul_addr _ _). (* As nzRings require 1 != 0 in order to lift a ring structure over finfuns *) (* we need evidence that the domain is non-empty. *) Section FinFunRing. Variable (aT : finType) (R : nzRingType) (a : aT). (* TODO_HB: doesn't work in combination with ffun_semiring above *) HB.instance Definition _ := PzSemiRing_isNonZero.Build {ffun aT -> R} (@ffun1_nonzero _ _ a). Definition ffun_ring : nzRingType := {ffun aT -> R}. End FinFunRing. (* TODO_HB do FinFunComSemiRing once above is fixed *) Section FinFunComRing. Variable (aT : finType) (R : comPzRingType) (a : aT). Fact ffun_mulC : commutative (@ffun_mul aT R). Proof. by move=> f1 f2; apply/ffunP=> i; rewrite !ffunE mulrC. Qed. (* TODO_HB #[export] HB.instance Definition _ := Ring_hasCommutativeMul.Build (ffun_ring _ a) ffun_mulC. *) End FinFunComRing. Section FinFunLSemiMod. Variable (R : pzSemiRingType) (aT : finType) (rT : lSemiModType R). Implicit Types f g : {ffun aT -> rT}. Definition ffun_scale k f := [ffun a => k *: f a]. Fact ffun_scaleA k1 k2 f : ffun_scale k1 (ffun_scale k2 f) = ffun_scale (k1 * k2) f. Proof. by apply/ffunP=> a; rewrite !ffunE scalerA. Qed. Fact ffun_scale0r f : ffun_scale 0 f = 0. Proof. by apply/ffunP=> a; rewrite !ffunE scale0r. Qed. Fact ffun_scale1 : left_id 1 ffun_scale. Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE scale1r. Qed. Fact ffun_scale_addr k : {morph (ffun_scale k) : x y / x + y}. Proof. by move=> f g; apply/ffunP=> a; rewrite !ffunE scalerDr. Qed. Fact ffun_scale_addl u : {morph (ffun_scale)^~ u : k1 k2 / k1 + k2}. Proof. by move=> k1 k2; apply/ffunP=> a; rewrite !ffunE scalerDl. Qed. #[export] HB.instance Definition _ := Nmodule_isLSemiModule.Build R {ffun aT -> rT} ffun_scaleA ffun_scale0r ffun_scale1 ffun_scale_addr ffun_scale_addl. End FinFunLSemiMod. #[export] HB.instance Definition _ (R : pzRingType) (aT : finType) (rT : lmodType R) := LSemiModule.on {ffun aT -> rT}. (* External direct product. *) Section PairSemiRing. Variables R1 R2 : pzSemiRingType. Definition mul_pair (x y : R1 * R2) := (x.1 * y.1, x.2 * y.2). Fact pair_mulA : associative mul_pair. Proof. by move=> x y z; congr (_, _); apply: mulrA. Qed. Fact pair_mul1l : left_id (1, 1) mul_pair. Proof. by case=> x1 x2; congr (_, _); apply: mul1r. Qed. Fact pair_mul1r : right_id (1, 1) mul_pair. Proof. by case=> x1 x2; congr (_, _); apply: mulr1. Qed. Fact pair_mulDl : left_distributive mul_pair +%R. Proof. by move=> x y z; congr (_, _); apply: mulrDl. Qed. Fact pair_mulDr : right_distributive mul_pair +%R. Proof. by move=> x y z; congr (_, _); apply: mulrDr. Qed. Fact pair_mul0r : left_zero 0 mul_pair. Proof. by move=> x; congr (_, _); apply: mul0r. Qed. Fact pair_mulr0 : right_zero 0 mul_pair. Proof. by move=> x; congr (_, _); apply: mulr0. Qed. #[export] HB.instance Definition _ := Nmodule_isPzSemiRing.Build (R1 * R2)%type pair_mulA pair_mul1l pair_mul1r pair_mulDl pair_mulDr pair_mul0r pair_mulr0. Fact fst_is_monoid_morphism : monoid_morphism fst. Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R1 fst fst_is_monoid_morphism. Fact snd_is_monoid_morphism : monoid_morphism snd. Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R2 snd snd_is_monoid_morphism. End PairSemiRing. Section PairSemiRing. Variables R1 R2 : nzSemiRingType. Fact pair_one_neq0 : 1 != 0 :> R1 * R2. Proof. by rewrite xpair_eqE oner_eq0. Qed. #[export] HB.instance Definition _ := PzSemiRing_isNonZero.Build (R1 * R2)%type pair_one_neq0. End PairSemiRing. Section PairComSemiRing. Variables R1 R2 : comPzSemiRingType. Fact pair_mulC : commutative (@mul_pair R1 R2). Proof. by move=> x y; congr (_, _); apply: mulrC. Qed. #[export] HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build (R1 * R2)%type pair_mulC. End PairComSemiRing. (* TODO: HB.saturate *) #[export] HB.instance Definition _ (R1 R2 : comNzSemiRingType) := NzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : pzRingType) := PzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : nzRingType) := NzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : comPzRingType) := PzRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : comNzRingType) := NzRing.on (R1 * R2)%type. (* /TODO *) Section PairLSemiMod. Variables (R : pzSemiRingType) (V1 V2 : lSemiModType R). Definition scale_pair a (v : V1 * V2) : V1 * V2 := (a *: v.1, a *: v.2). Fact pair_scaleA a b u : scale_pair a (scale_pair b u) = scale_pair (a * b) u. Proof. by congr (_, _); apply: scalerA. Qed. Fact pair_scale0 u : scale_pair 0 u = 0. Proof. by case: u => u1 u2; congr (_, _); apply: scale0r. Qed. Fact pair_scale1 u : scale_pair 1 u = u. Proof. by case: u => u1 u2; congr (_, _); apply: scale1r. Qed. Fact pair_scaleDr : right_distributive scale_pair +%R. Proof. by move=> a u v; congr (_, _); apply: scalerDr. Qed. Fact pair_scaleDl u : {morph scale_pair^~ u: a b / a + b}. Proof. by move=> a b; congr (_, _); apply: scalerDl. Qed. #[export] HB.instance Definition _ := Nmodule_isLSemiModule.Build R (V1 * V2)%type pair_scaleA pair_scale0 pair_scale1 pair_scaleDr pair_scaleDl. Fact fst_is_scalable : scalable fst. Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R (V1 * V2)%type V1 *:%R fst fst_is_scalable. Fact snd_is_scalable : scalable snd. Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R (V1 * V2)%type V2 *:%R snd snd_is_scalable. End PairLSemiMod. Section PairLSemiAlg. Variables (R : pzSemiRingType) (A1 A2 : lSemiAlgType R). Fact pair_scaleAl a (u v : A1 * A2) : a *: (u * v) = (a *: u) * v. Proof. by congr (_, _); apply: scalerAl. Qed. #[export] HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R (A1 * A2)%type pair_scaleAl. (* TODO: HB.saturate *) #[export] HB.instance Definition _ := RMorphism.on (@fst A1 A2). #[export] HB.instance Definition _ := RMorphism.on (@snd A1 A2). (* /TODO *) End PairLSemiAlg. Section PairSemiAlg. Variables (R : pzSemiRingType) (A1 A2 : semiAlgType R). Fact pair_scaleAr a (u v : A1 * A2) : a *: (u * v) = u * (a *: v). Proof. by congr (_, _); apply: scalerAr. Qed. #[export] HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R (A1 * A2)%type pair_scaleAr. End PairSemiAlg. Section PairUnitRing. Variables R1 R2 : unitRingType. Definition pair_unitr := [qualify a x : R1 * R2 | (x.1 \is a GRing.unit) && (x.2 \is a GRing.unit)]. Definition pair_invr x := if x \is a pair_unitr then (x.1^-1, x.2^-1) else x. Lemma pair_mulVl : {in pair_unitr, left_inverse 1 pair_invr *%R}. Proof. rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _. by congr (_, _); apply: mulVr. Qed. Lemma pair_mulVr : {in pair_unitr, right_inverse 1 pair_invr *%R}. Proof. rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _. by congr (_, _); apply: mulrV. Qed. Lemma pair_unitP x y : y * x = 1 /\ x * y = 1 -> x \is a pair_unitr. Proof. case=> [[y1x y2x] [x1y x2y]]; apply/andP. by split; apply/unitrP; [exists y.1 | exists y.2]. Qed. Lemma pair_invr_out : {in [predC pair_unitr], pair_invr =1 id}. Proof. by rewrite /pair_invr => x /negPf/= ->. Qed. #[export] HB.instance Definition _ := NzRing_hasMulInverse.Build (R1 * R2)%type pair_mulVl pair_mulVr pair_unitP pair_invr_out. End PairUnitRing. (* TODO: HB.saturate *) #[export] HB.instance Definition _ (R1 R2 : comUnitRingType) := UnitRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R : pzSemiRingType) (A1 A2 : comSemiAlgType R) := SemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (V1 V2 : lmodType R) := LSemiModule.on (V1 * V2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : lalgType R) := LSemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : algType R) := SemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : comAlgType R) := Algebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : unitAlgType R) := Algebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : comUnitAlgType R) := Algebra.on (A1 * A2)%type. (* /TODO *) Lemma pairMnE (M1 M2 : zmodType) (x : M1 * M2) n : x *+ n = (x.1 *+ n, x.2 *+ n). Proof. by case: x => x y; elim: n => //= n; rewrite !mulrS => ->. Qed. (* begin hide *) (* Testing subtype hierarchy Section Test0. Variables (T : choiceType) (S : {pred T}). Inductive B := mkB x & x \in S. Definition vB u := let: mkB x _ := u in x. HB.instance Definition _ := [isSub for vB]. HB.instance Definition _ := [Choice of B by <:]. End Test0. Section Test1. Variables (R : unitRingType) (S : divringClosed R). HB.instance Definition _ := [SubChoice_isSubUnitRing of B S by <:]. End Test1. Section Test2. Variables (R : comUnitRingType) (A : unitAlgType R) (S : divalgClosed A). HB.instance Definition _ := [SubZmodule_isSubLmodule of B S by <:]. HB.instance Definition _ := [SubNzRing_SubLmodule_isSubLalgebra of B S by <:]. HB.instance Definition _ := [SubLalgebra_isSubAlgebra of B S by <:]. End Test2. Section Test3. Variables (F : fieldType) (S : divringClosed F). HB.instance Definition _ := [SubRing_isSubComNzRing of B S by <:]. HB.instance Definition _ := [SubComUnitRing_isSubIntegralDomain of B S by <:]. HB.instance Definition _ := [SubIntegralDomain_isSubField of B S by <:]. End Test3. *) (* end hide *) (* Algebraic structure of bool *) HB.instance Definition _ := Zmodule_isComNzRing.Build bool andbA andbC andTb andb_addl isT. Fact mulVb (b : bool) : b != 0 -> b * b = 1. Proof. by case: b. Qed. Fact invb_out (x y : bool) : y * x = 1 -> x != 0. Proof. by case: x; case: y. Qed. HB.instance Definition _ := ComNzRing_hasMulInverse.Build bool mulVb invb_out (fun x => fun => erefl x). Lemma bool_fieldP : Field.axiom bool. Proof. by []. Qed. HB.instance Definition _ := ComUnitRing_isField.Build bool bool_fieldP. (* Algebraic structure of nat *) HB.instance Definition _ := Nmodule_isComNzSemiRing.Build nat mulnA mulnC mul1n mulnDl mul0n erefl. HB.instance Definition _ (R : pzSemiRingType) := isMonoidMorphism.Build nat R (natmul 1) (mulr1n 1, natrM R). Lemma natr0E : 0 = 0%N. Proof. by []. Qed. Lemma natr1E : 1 = 1%N. Proof. by []. Qed. Lemma natn n : n%:R = n. Proof. by elim: n => [//|n IHn]; rewrite -nat1r IHn. Qed. Lemma natrDE n m : n + m = (n + m)%N. Proof. by []. Qed. Lemma natrME n m : n * m = (n * m)%N. Proof. by []. Qed. Lemma natrXE n m : n ^+ m = (n ^ m)%N. Proof. by []. Qed. Definition natrE := (natr0E, natr1E, natn, natrDE, natrME, natrXE).
Basic.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.RingTheory.Norm.Defs import Mathlib.FieldTheory.PrimitiveElement import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Galois.Basic /-! # Norm for (finite) ring extensions Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`, the determinant of the linear map given by multiplying by `s` gives information about the roots of the minimal polynomial of `s` over `R`. ## Implementation notes Typically, the norm is defined specifically for finite field extensions. The current definition is as general as possible and the assumption that we have fields or that the extension is finite is added to the lemmas as needed. We only define the norm for left multiplication (`Algebra.leftMulMatrix`, i.e. `LinearMap.mulLeft`). For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway. See also `Algebra.trace`, which is defined similarly as the trace of `Algebra.leftMulMatrix`. ## References * https://en.wikipedia.org/wiki/Field_norm -/ universe u v w variable {R S T : Type*} [CommRing R] [Ring S] variable [Algebra R S] variable {K L F : Type*} [Field K] [Field L] [Field F] variable [Algebra K L] [Algebra K F] variable {ι : Type w} open Module open LinearMap open Matrix Polynomial open scoped Matrix namespace Algebra section EqProdRoots /-- Given `pb : PowerBasis K S`, then the norm of `pb.gen` is `(-1) ^ pb.dim * coeff (minpoly K pb.gen) 0`. -/ theorem PowerBasis.norm_gen_eq_coeff_zero_minpoly (pb : PowerBasis R S) : norm R pb.gen = (-1) ^ pb.dim * coeff (minpoly R pb.gen) 0 := by rw [norm_eq_matrix_det pb.basis, det_eq_sign_charpoly_coeff, charpoly_leftMulMatrix, Fintype.card_fin] /-- Given `pb : PowerBasis R S`, then the norm of `pb.gen` is `((minpoly R pb.gen).aroots F).prod`. -/ theorem PowerBasis.norm_gen_eq_prod_roots [Algebra R F] (pb : PowerBasis R S) (hf : (minpoly R pb.gen).Splits (algebraMap R F)) : algebraMap R F (norm R pb.gen) = ((minpoly R pb.gen).aroots F).prod := by haveI := Module.nontrivial R F have := minpoly.monic pb.isIntegral_gen rw [PowerBasis.norm_gen_eq_coeff_zero_minpoly, ← pb.natDegree_minpoly, RingHom.map_mul, ← coeff_map, prod_roots_eq_coeff_zero_of_monic_of_splits (this.map _) ((splits_id_iff_splits _).2 hf), this.natDegree_map, map_pow, ← mul_assoc, ← mul_pow] simp only [map_neg, map_one, neg_mul, neg_neg, one_pow, one_mul] end EqProdRoots section EqZeroIff variable [Finite ι] @[simp] theorem norm_zero [Nontrivial S] [Module.Free R S] [Module.Finite R S] : norm R (0 : S) = 0 := by nontriviality rw [norm_apply, coe_lmul_eq_mul, map_zero, LinearMap.det_zero' (Module.Free.chooseBasis R S)] @[simp] theorem norm_eq_zero_iff [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] {x : S} : norm R x = 0 ↔ x = 0 := by constructor swap · rintro rfl; exact norm_zero · let b := Module.Free.chooseBasis R S let decEq := Classical.decEq (Module.Free.ChooseBasisIndex R S) rw [norm_eq_matrix_det b, ← Matrix.exists_mulVec_eq_zero_iff] rintro ⟨v, v_ne, hv⟩ rw [← b.equivFun.apply_symm_apply v, b.equivFun_symm_apply, b.equivFun_apply, leftMulMatrix_mulVec_repr] at hv refine (mul_eq_zero.mp (b.ext_elem fun i => ?_)).resolve_right (show ∑ i, v i • b i ≠ 0 from ?_) · simpa only [LinearEquiv.map_zero, Pi.zero_apply] using congr_fun hv i · contrapose! v_ne with sum_eq apply b.equivFun.symm.injective rw [b.equivFun_symm_apply, sum_eq, LinearEquiv.map_zero] theorem norm_ne_zero_iff [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] {x : S} : norm R x ≠ 0 ↔ x ≠ 0 := not_iff_not.mpr norm_eq_zero_iff /-- This is `Algebra.norm_eq_zero_iff` composed with `Algebra.norm_apply`. -/ @[simp] theorem norm_eq_zero_iff' [IsDomain R] [IsDomain S] [Module.Free R S] [Module.Finite R S] {x : S} : LinearMap.det (LinearMap.mul R S x) = 0 ↔ x = 0 := norm_eq_zero_iff theorem norm_eq_zero_iff_of_basis [IsDomain R] [IsDomain S] (b : Basis ι R S) {x : S} : Algebra.norm R x = 0 ↔ x = 0 := by haveI : Module.Free R S := Module.Free.of_basis b haveI : Module.Finite R S := Module.Finite.of_basis b exact norm_eq_zero_iff theorem norm_ne_zero_iff_of_basis [IsDomain R] [IsDomain S] (b : Basis ι R S) {x : S} : Algebra.norm R x ≠ 0 ↔ x ≠ 0 := not_iff_not.mpr (norm_eq_zero_iff_of_basis b) end EqZeroIff open IntermediateField variable (K) in theorem norm_eq_norm_adjoin [FiniteDimensional K L] [Algebra.IsSeparable K L] (x : L) : norm K x = norm K (AdjoinSimple.gen K x) ^ finrank K⟮x⟯ L := by letI := Algebra.isSeparable_tower_top_of_isSeparable K K⟮x⟯ L let pbL := Field.powerBasisOfFiniteOfSeparable K⟮x⟯ L let pbx := IntermediateField.adjoin.powerBasis (Algebra.IsSeparable.isIntegral K x) rw [← AdjoinSimple.algebraMap_gen K x, norm_eq_matrix_det (pbx.basis.smulTower pbL.basis) _, smulTower_leftMulMatrix_algebraMap, det_blockDiagonal, AdjoinSimple.algebraMap_gen, norm_eq_matrix_det pbx.basis] simp only [Finset.card_fin, Finset.prod_const] congr rw [← PowerBasis.finrank] section IntermediateField theorem _root_.IntermediateField.AdjoinSimple.norm_gen_eq_one {x : L} (hx : ¬IsIntegral K x) : norm K (AdjoinSimple.gen K x) = 1 := by rw [norm_eq_one_of_not_exists_basis] contrapose! hx obtain ⟨s, ⟨b⟩⟩ := hx refine .of_mem_of_fg K⟮x⟯.toSubalgebra ?_ x ?_ · exact (Submodule.fg_iff_finiteDimensional _).mpr (.of_fintype_basis b) · exact IntermediateField.subset_adjoin K _ (Set.mem_singleton x) theorem _root_.IntermediateField.AdjoinSimple.norm_gen_eq_prod_roots (x : L) (hf : (minpoly K x).Splits (algebraMap K F)) : (algebraMap K F) (norm K (AdjoinSimple.gen K x)) = ((minpoly K x).aroots F).prod := by have injKxL := (algebraMap K⟮x⟯ L).injective by_cases hx : IsIntegral K x; swap · simp [minpoly.eq_zero hx, IntermediateField.AdjoinSimple.norm_gen_eq_one hx, aroots_def] rw [← adjoin.powerBasis_gen hx, PowerBasis.norm_gen_eq_prod_roots] <;> rw [adjoin.powerBasis_gen hx, ← minpoly.algebraMap_eq injKxL] <;> simp only [AdjoinSimple.algebraMap_gen _ _, hf] end IntermediateField section EqProdEmbeddings open IntermediateField IntermediateField.AdjoinSimple Polynomial variable (F) (E : Type*) [Field E] [Algebra K E] theorem norm_eq_prod_embeddings_gen [Algebra R F] (pb : PowerBasis R S) (hE : (minpoly R pb.gen).Splits (algebraMap R F)) (hfx : IsSeparable R pb.gen) : algebraMap R F (norm R pb.gen) = (@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).prod fun σ => σ pb.gen := by letI := Classical.decEq F rw [PowerBasis.norm_gen_eq_prod_roots pb hE] rw [@Fintype.prod_equiv (S →ₐ[R] F) _ _ (PowerBasis.AlgHom.fintype pb) _ _ pb.liftEquiv' (fun σ => σ pb.gen) (fun x => x) ?_] · rw [Finset.prod_mem_multiset, Finset.prod_eq_multiset_prod, Multiset.toFinset_val, Multiset.dedup_eq_self.mpr, Multiset.map_id] · exact nodup_roots (.map hfx) · intro x; rfl · intro σ; simp only [PowerBasis.liftEquiv'_apply_coe] theorem norm_eq_prod_roots [Algebra.IsSeparable K L] [FiniteDimensional K L] {x : L} (hF : (minpoly K x).Splits (algebraMap K F)) : algebraMap K F (norm K x) = ((minpoly K x).aroots F).prod ^ finrank K⟮x⟯ L := by rw [norm_eq_norm_adjoin K x, map_pow, IntermediateField.AdjoinSimple.norm_gen_eq_prod_roots _ hF] theorem prod_embeddings_eq_finrank_pow [Algebra L F] [IsScalarTower K L F] [IsAlgClosed E] [Algebra.IsSeparable K F] [FiniteDimensional K F] (pb : PowerBasis K L) : ∏ σ : F →ₐ[K] E, σ (algebraMap L F pb.gen) = ((@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).prod fun σ : L →ₐ[K] E => σ pb.gen) ^ finrank L F := by haveI : FiniteDimensional L F := FiniteDimensional.right K L F haveI : Algebra.IsSeparable L F := Algebra.isSeparable_tower_top_of_isSeparable K L F letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb rw [Fintype.prod_equiv algHomEquivSigma (fun σ : F →ₐ[K] E => _) fun σ => σ.1 pb.gen, ← Finset.univ_sigma_univ, Finset.prod_sigma, ← Finset.prod_pow] · refine Finset.prod_congr rfl fun σ _ => ?_ letI : Algebra L E := σ.toRingHom.toAlgebra simp_rw [Finset.prod_const] congr exact AlgHom.card L F E · intro σ simp only [algHomEquivSigma, Equiv.coe_fn_mk, AlgHom.restrictDomain, AlgHom.comp_apply, IsScalarTower.coe_toAlgHom'] variable (K) /-- For `L/K` a finite separable extension of fields and `E` an algebraically closed extension of `K`, the norm (down to `K`) of an element `x` of `L` is equal to the product of the images of `x` over all the `K`-embeddings `σ` of `L` into `E`. -/ theorem norm_eq_prod_embeddings [FiniteDimensional K L] [Algebra.IsSeparable K L] [IsAlgClosed E] (x : L) : algebraMap K E (norm K x) = ∏ σ : L →ₐ[K] E, σ x := by have hx := Algebra.IsSeparable.isIntegral K x rw [norm_eq_norm_adjoin K x, RingHom.map_pow, ← adjoin.powerBasis_gen hx, norm_eq_prod_embeddings_gen E (adjoin.powerBasis hx) (IsAlgClosed.splits_codomain _)] · exact (prod_embeddings_eq_finrank_pow L (L := K⟮x⟯) E (adjoin.powerBasis hx)).symm · haveI := Algebra.isSeparable_tower_bot_of_isSeparable K K⟮x⟯ L exact Algebra.IsSeparable.isSeparable K _ theorem norm_eq_prod_automorphisms [FiniteDimensional K L] [IsGalois K L] (x : L) : algebraMap K L (norm K x) = ∏ σ : L ≃ₐ[K] L, σ x := by apply FaithfulSMul.algebraMap_injective L (AlgebraicClosure L) rw [map_prod (algebraMap L (AlgebraicClosure L))] rw [← Fintype.prod_equiv (Normal.algHomEquivAut K (AlgebraicClosure L) L)] · rw [← norm_eq_prod_embeddings _ _ x, ← IsScalarTower.algebraMap_apply] · intro σ simp only [Normal.algHomEquivAut, AlgHom.restrictNormal', Equiv.coe_fn_mk, AlgEquiv.coe_ofBijective, AlgHom.restrictNormal_commutes, algebraMap_self, RingHom.id_apply] theorem isIntegral_norm [Algebra R L] [Algebra R K] [IsScalarTower R K L] [Algebra.IsSeparable K L] [FiniteDimensional K L] {x : L} (hx : IsIntegral R x) : IsIntegral R (norm K x) := by have hx' : IsIntegral K x := hx.tower_top rw [← isIntegral_algebraMap_iff (algebraMap K (AlgebraicClosure L)).injective, norm_eq_prod_roots] · refine (IsIntegral.multiset_prod fun y hy => ?_).pow _ rw [mem_roots_map (minpoly.ne_zero hx')] at hy use minpoly R x, minpoly.monic hx rw [← aeval_def] at hy ⊢ exact minpoly.aeval_of_isScalarTower R x y hy · apply IsAlgClosed.splits_codomain lemma norm_eq_of_algEquiv [Ring T] [Algebra R T] (e : S ≃ₐ[R] T) (x) : Algebra.norm R (e x) = Algebra.norm R x := by simp_rw [Algebra.norm_apply, ← LinearMap.det_conj _ e.toLinearEquiv]; congr; ext; simp lemma norm_eq_of_ringEquiv {A B C : Type*} [CommRing A] [CommRing B] [Ring C] [Algebra A C] [Algebra B C] (e : A ≃+* B) (he : (algebraMap B C).comp e = algebraMap A C) (x : C) : e (Algebra.norm A x) = Algebra.norm B x := by classical by_cases h : ∃ s : Finset C, Nonempty (Basis s B C) · obtain ⟨s, ⟨b⟩⟩ := h letI : Algebra A B := RingHom.toAlgebra e letI : IsScalarTower A B C := IsScalarTower.of_algebraMap_eq' he.symm rw [Algebra.norm_eq_matrix_det b, Algebra.norm_eq_matrix_det (b.mapCoeffs e.symm (by simp [Algebra.smul_def, ← he])), e.map_det] congr ext i j simp [leftMulMatrix_apply, LinearMap.toMatrix_apply] rw [norm_eq_one_of_not_exists_basis _ h, norm_eq_one_of_not_exists_basis, map_one] intro ⟨s, ⟨b⟩⟩ exact h ⟨s, ⟨b.mapCoeffs e (by simp [Algebra.smul_def, ← he])⟩⟩ lemma norm_eq_of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommRing A₁] [Ring B₁] [CommRing A₂] [Ring B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂) (e₂ : B₁ ≃+* B₂) (he : RingHom.comp (algebraMap A₂ B₂) ↑e₁ = RingHom.comp ↑e₂ (algebraMap A₁ B₁)) (x) : Algebra.norm A₁ x = e₁.symm (Algebra.norm A₂ (e₂ x)) := by letI := (RingHom.comp (e₂ : B₁ →+* B₂) (algebraMap A₁ B₁)).toAlgebra' ?_ · let e' : B₁ ≃ₐ[A₁] B₂ := { e₂ with commutes' := fun _ ↦ rfl } rw [← Algebra.norm_eq_of_ringEquiv e₁ he, ← Algebra.norm_eq_of_algEquiv e'] simp [e'] intros c x apply e₂.symm.injective simp only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, map_mul, RingEquiv.symm_apply_apply, commutes] end EqProdEmbeddings end Algebra
Extreme.lean
/- Copyright (c) 2025 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Convex.Extreme import Mathlib.Dynamics.Ergodic.Function import Mathlib.Dynamics.Ergodic.RadonNikodym import Mathlib.Probability.ConditionalProbability /-! # Ergodic measures as extreme points In this file we prove that a finite measure `μ` is an ergodic measure for a self-map `f` iff it is an extreme point of the set of invariant measures of `f` with the same total volume. We also specialize this result to probability measures. -/ open Filter Set Function MeasureTheory Measure ProbabilityTheory open scoped NNReal ENNReal Topology variable {X : Type*} {m : MeasurableSpace X} {μ ν : Measure X} {f : X → X} namespace Ergodic /-- Given a constant `c ≠ ∞`, an extreme point of the set of measures that are invariant under `f` and have total mass `c` is an ergodic measure. -/ theorem of_mem_extremePoints_measure_univ_eq {c : ℝ≥0∞} (hc : c ≠ ∞) (h : μ ∈ extremePoints ℝ≥0∞ {ν | MeasurePreserving f ν ν ∧ ν univ = c}) : Ergodic f μ := by have hf : MeasurePreserving f μ μ := h.1.1 rcases eq_or_ne c 0 with rfl | hc₀ · convert zero_measure hf.measurable rw [← measure_univ_eq_zero, h.1.2] · refine ⟨hf, ⟨?_⟩⟩ have : IsFiniteMeasure μ := by constructor rwa [h.1.2, lt_top_iff_ne_top] set S := {ν | MeasurePreserving f ν ν ∧ ν univ = c} have {s : Set X} (hsm : MeasurableSet s) (hfs : f ⁻¹' s = s) (hμs : μ s ≠ 0) : c • μ[|s] ∈ S := by refine ⟨.smul_measure (.smul_measure ?_ _) c, ?_⟩ · convert hf.restrict_preimage hsm exact hfs.symm · rw [Measure.smul_apply, (cond_isProbabilityMeasure hμs).1, smul_eq_mul, mul_one] intro s hsm hfs by_contra H obtain ⟨hs, hs'⟩ : μ s ≠ 0 ∧ μ sᶜ ≠ 0 := by simpa [eventuallyConst_set, ae_iff, and_comm] using H obtain ⟨hcond, -⟩ : c • μ[|s] = μ ∧ c • μ[|sᶜ] = μ := by apply h.2 (this hsm hfs hs) (this hsm.compl (by rw [preimage_compl, hfs]) hs') refine ⟨μ s / c, μ sᶜ / c, ENNReal.div_pos hs hc, ENNReal.div_pos hs' hc, ?_, ?_⟩ · rw [← ENNReal.add_div, measure_add_measure_compl hsm, h.1.2, ENNReal.div_self hc₀ hc] · simp [ProbabilityTheory.cond, smul_smul, ← mul_assoc, ENNReal.div_mul_cancel, ENNReal.mul_inv_cancel, *] rw [← hcond] at hs' simp [ProbabilityTheory.cond_apply, hsm] at hs' /-- An extreme point of the set of invariant probability measures is an ergodic measure. -/ theorem of_mem_extremePoints (h : μ ∈ extremePoints ℝ≥0∞ {ν | MeasurePreserving f ν ν ∧ IsProbabilityMeasure ν}) : Ergodic f μ := .of_mem_extremePoints_measure_univ_eq ENNReal.one_ne_top <| by simpa only [isProbabilityMeasure_iff] using h -- TODO: do we need `IsFiniteMeasure ν` here? theorem eq_smul_of_absolutelyContinuous [IsFiniteMeasure μ] [IsFiniteMeasure ν] (hμ : Ergodic f μ) (hfν : MeasurePreserving f ν ν) (hνμ : ν ≪ μ) : ∃ c : ℝ≥0∞, ν = c • μ := by have := hfν.rnDeriv_comp_aeEq hμ.toMeasurePreserving obtain ⟨c, hc⟩ := hμ.ae_eq_const_of_ae_eq_comp₀ (measurable_rnDeriv _ _).nullMeasurable this use c ext s hs calc ν s = ∫⁻ a in s, ν.rnDeriv μ a ∂μ := .symm <| setLIntegral_rnDeriv hνμ _ _ = ∫⁻ _ in s, c ∂μ := lintegral_congr_ae <| hc.filter_mono <| ae_mono restrict_le_self _ = (c • μ) s := by simp theorem eq_of_absolutelyContinuous_measure_univ_eq [IsFiniteMeasure μ] [IsFiniteMeasure ν] (hμ : Ergodic f μ) (hfν : MeasurePreserving f ν ν) (hνμ : ν ≪ μ) (huniv : ν univ = μ univ) : ν = μ := by rcases hμ.eq_smul_of_absolutelyContinuous hfν hνμ with ⟨c, rfl⟩ rcases eq_or_ne μ 0 with rfl | hμ₀ · simp · simp_all [ENNReal.mul_eq_right] theorem eq_of_absolutelyContinuous [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (hμ : Ergodic f μ) (hfν : MeasurePreserving f ν ν) (hνμ : ν ≪ μ) : ν = μ := eq_of_absolutelyContinuous_measure_univ_eq hμ hfν hνμ <| by simp theorem mem_extremePoints_measure_univ_eq [IsFiniteMeasure μ] (hμ : Ergodic f μ) : μ ∈ extremePoints ℝ≥0∞ {ν | MeasurePreserving f ν ν ∧ ν univ = μ univ} := by rw [mem_extremePoints_iff_left] refine ⟨⟨hμ.toMeasurePreserving, rfl⟩, ?_⟩ rintro ν₁ ⟨hfν₁, hν₁μ⟩ ν₂ ⟨hfν₂, hν₂μ⟩ ⟨a, b, ha, hb, hab, rfl⟩ have : IsFiniteMeasure ν₁ := ⟨by rw [hν₁μ]; apply measure_lt_top⟩ apply hμ.eq_of_absolutelyContinuous_measure_univ_eq hfν₁ (.add_right _ _) hν₁μ apply absolutelyContinuous_smul ha.ne' theorem mem_extremePoints [IsProbabilityMeasure μ] (hμ : Ergodic f μ) : μ ∈ extremePoints ℝ≥0∞ {ν | MeasurePreserving f ν ν ∧ IsProbabilityMeasure ν} := by simpa only [isProbabilityMeasure_iff, measure_univ] using hμ.mem_extremePoints_measure_univ_eq theorem iff_mem_extremePoints_measure_univ_eq [IsFiniteMeasure μ] : Ergodic f μ ↔ μ ∈ extremePoints ℝ≥0∞ {ν | MeasurePreserving f ν ν ∧ ν univ = μ univ} := ⟨mem_extremePoints_measure_univ_eq, of_mem_extremePoints_measure_univ_eq (measure_ne_top _ _)⟩ theorem iff_mem_extremePoints [IsProbabilityMeasure μ] : Ergodic f μ ↔ μ ∈ extremePoints ℝ≥0∞ {ν | MeasurePreserving f ν ν ∧ IsProbabilityMeasure ν} := ⟨mem_extremePoints, of_mem_extremePoints⟩ end Ergodic
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.lean`. -/ 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] : Type v extends Subsemigroup M 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] : Type v extends NonUnitalSubsemiring R 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 instance instSetLike {R : Type v} [NonUnitalNonAssocSemiring R] [Star R] : 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 initialize_simps_projections NonUnitalStarSubsemiring (carrier → coe, as_prefix coe) variable {R : Type v} [NonUnitalNonAssocSemiring R] [StarRing R] /-- The actual `NonUnitalStarSubsemiring` obtained from an element of a type satisfying `NonUnitalSubsemiringClass` and `StarMemClass`. -/ @[simps] def ofClass {S R : Type*} [NonUnitalNonAssocSemiring R] [StarRing R] [SetLike S R] [NonUnitalSubsemiringClass S R] [StarMemClass S R] (s : S) : NonUnitalStarSubsemiring R where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem star_mem' := star_mem instance (priority := 100) : CanLift (Set R) (NonUnitalStarSubsemiring R) (↑) (fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ {x}, x ∈ s → star x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := h.1 add_mem' := h.2.1 mul_mem' := h.2.2.1 star_mem' := h.2.2.2 }, rfl ⟩ 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 change 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
Imo2019Q2.lean
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Angle.Sphere import Mathlib.Geometry.Euclidean.Sphere.SecondInter /-! # IMO 2019 Q2 In triangle `ABC`, point `A₁` lies on side `BC` and point `B₁` lies on side `AC`. Let `P` and `Q` be points on segments `AA₁` and `BB₁`, respectively, such that `PQ` is parallel to `AB`. Let `P₁` be a point on line `PB₁`, such that `B₁` lies strictly between `P` and `P₁`, and `∠PP₁C = ∠BAC`. Similarly, let `Q₁` be a point on line `QA₁`, such that `A₁` lies strictly between `Q` and `Q₁`, and `∠CQ₁Q = ∠CBA`. Prove that points `P`, `Q`, `P₁`, and `Q₁` are concyclic. We follow Solution 1 from the [official solutions](https://www.imo2019.uk/wp-content/uploads/2018/07/solutions-r856.pdf). Letting the rays `AA₁` and `BB₁` intersect the circumcircle of `ABC` at `A₂` and `B₂` respectively, we show with an angle chase that `P`, `Q`, `A₂`, `B₂` are concyclic and let `ω` be the circle through those points. We then show that `C`, `Q₁`, `A₂`, `A₁` are concyclic, and then that `Q₁` lies on `ω`, and similarly that `P₁` lies on `ω`, so the required four points are concyclic. Note that most of the formal proof is actually proving nondegeneracy conditions needed for that angle chase / concyclicity argument, where an informal solution doesn't discuss those conditions at all. Also note that (as described in `Geometry.Euclidean.Angle.Oriented.Basic`) the oriented angles used are modulo `2 * π`, so parts of the angle chase that are only valid for angles modulo `π` (as used in the informal solution) are represented as equalities of twice angles, which we write as `(2 : ℤ) • ∡ _ _ _ = (2 : ℤ) • ∡ _ _ _`. -/ library_note "IMO geometry formalization conventions"/-- We apply the following conventions for formalizing IMO geometry problems. A problem is assumed to take place in the plane unless that is clearly not intended, so it is not required to prove that the points are coplanar (whether or not that in fact follows from the other conditions). Angles in problem statements are taken to be unoriented. A reference to an angle `∠XYZ` is taken to imply that `X` and `Z` are not equal to `Y`, since choices of junk values play no role in informal mathematics, and those implications are included as hypotheses for the problem whether or not they follow from the other hypotheses. Similar, a reference to `XY` as a line is taken to imply that `X` does not equal `Y` and that is included as a hypothesis, and a reference to `XY` being parallel to something is considered a reference to it as a line. However, such an implicit hypothesis about two points being different is included only once for any given two points (even if it follows from more than one reference to a line or an angle), if `X ≠ Y` is included then `Y ≠ X` is not included separately, and such hypotheses are not included in the case where there is also a reference in the problem to a triangle including those two points, or to strict betweenness of three points including those two. If betweenness is stated, it is taken to be strict betweenness. However, segments and sides are taken to include their endpoints (unless this makes a problem false), although those degenerate cases might not necessarily have been considered when the problem was formulated and contestants might not have been expected to deal with them. A reference to a point being on a side or a segment is expressed directly with `Wbtw` rather than more literally with `affineSegment`. -/ open Affine Affine.Simplex EuclideanGeometry Module open scoped Affine EuclideanGeometry Real attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two variable (V : Type*) (Pt : Type*) variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace Pt] variable [NormedAddTorsor V Pt] namespace Imo2019Q2 noncomputable section /-- A configuration satisfying the conditions of the problem. We define this structure to avoid passing many hypotheses around as we build up information about the configuration; the final result for a statement of the problem not using this structure is then deduced from one in terms of this structure. -/ structure Imo2019q2Cfg where (A B C A₁ B₁ P Q P₁ Q₁ : Pt) affineIndependent_ABC : AffineIndependent ℝ ![A, B, C] wbtw_B_A₁_C : Wbtw ℝ B A₁ C wbtw_A_B₁_C : Wbtw ℝ A B₁ C wbtw_A_P_A₁ : Wbtw ℝ A P A₁ wbtw_B_Q_B₁ : Wbtw ℝ B Q B₁ PQ_parallel_AB : line[ℝ, P, Q] ∥ line[ℝ, A, B] -- A hypothesis implicit in the named line. P_ne_Q : P ≠ Q sbtw_P_B₁_P₁ : Sbtw ℝ P B₁ P₁ angle_PP₁C_eq_angle_BAC : ∠ P P₁ C = ∠ B A C -- A hypothesis implicit in the first named angle. C_ne_P₁ : C ≠ P₁ sbtw_Q_A₁_Q₁ : Sbtw ℝ Q A₁ Q₁ angle_CQ₁Q_eq_angle_CBA : ∠ C Q₁ Q = ∠ C B A -- A hypothesis implicit in the first named angle. C_ne_Q₁ : C ≠ Q₁ /-- A default choice of orientation, for lemmas that need to pick one. -/ def someOrientation [hd2 : Fact (finrank ℝ V = 2)] : Module.Oriented ℝ V (Fin 2) := ⟨Basis.orientation (finBasisOfFinrankEq _ _ hd2.out)⟩ variable {V Pt} namespace Imo2019q2Cfg variable (cfg : Imo2019q2Cfg V Pt) /-- The configuration has symmetry, allowing results proved for one point to be applied for another (where the informal solution says "similarly"). -/ def symm : Imo2019q2Cfg V Pt where A := cfg.B B := cfg.A C := cfg.C A₁ := cfg.B₁ B₁ := cfg.A₁ P := cfg.Q Q := cfg.P P₁ := cfg.Q₁ Q₁ := cfg.P₁ affineIndependent_ABC := by rw [← affineIndependent_equiv (Equiv.swap (0 : Fin 3) 1)] convert cfg.affineIndependent_ABC using 1 ext x fin_cases x <;> rfl wbtw_B_A₁_C := cfg.wbtw_A_B₁_C wbtw_A_B₁_C := cfg.wbtw_B_A₁_C wbtw_A_P_A₁ := cfg.wbtw_B_Q_B₁ wbtw_B_Q_B₁ := cfg.wbtw_A_P_A₁ PQ_parallel_AB := Set.pair_comm cfg.P cfg.Q ▸ Set.pair_comm cfg.A cfg.B ▸ cfg.PQ_parallel_AB P_ne_Q := cfg.P_ne_Q.symm sbtw_P_B₁_P₁ := cfg.sbtw_Q_A₁_Q₁ angle_PP₁C_eq_angle_BAC := angle_comm cfg.C cfg.Q₁ cfg.Q ▸ angle_comm cfg.C cfg.B cfg.A ▸ cfg.angle_CQ₁Q_eq_angle_CBA C_ne_P₁ := cfg.C_ne_Q₁ sbtw_Q_A₁_Q₁ := cfg.sbtw_P_B₁_P₁ angle_CQ₁Q_eq_angle_CBA := angle_comm cfg.P cfg.P₁ cfg.C ▸ angle_comm cfg.B cfg.A cfg.C ▸ cfg.angle_PP₁C_eq_angle_BAC C_ne_Q₁ := cfg.C_ne_P₁ /-! ### Configuration properties that are obvious from the diagram, and construction of the points `A₂` and `B₂` -/ theorem A_ne_B : cfg.A ≠ cfg.B := cfg.affineIndependent_ABC.injective.ne (by decide : (0 : Fin 3) ≠ 1) theorem A_ne_C : cfg.A ≠ cfg.C := cfg.affineIndependent_ABC.injective.ne (by decide : (0 : Fin 3) ≠ 2) theorem B_ne_C : cfg.B ≠ cfg.C := cfg.affineIndependent_ABC.injective.ne (by decide : (1 : Fin 3) ≠ 2) theorem not_collinear_ABC : ¬Collinear ℝ ({cfg.A, cfg.B, cfg.C} : Set Pt) := affineIndependent_iff_not_collinear_set.1 cfg.affineIndependent_ABC /-- `ABC` as a `Triangle`. -/ def triangleABC : Triangle ℝ Pt := ⟨_, cfg.affineIndependent_ABC⟩ theorem A_mem_circumsphere : cfg.A ∈ cfg.triangleABC.circumsphere := cfg.triangleABC.mem_circumsphere 0 theorem B_mem_circumsphere : cfg.B ∈ cfg.triangleABC.circumsphere := cfg.triangleABC.mem_circumsphere 1 theorem C_mem_circumsphere : cfg.C ∈ cfg.triangleABC.circumsphere := cfg.triangleABC.mem_circumsphere 2 theorem symm_triangleABC : cfg.symm.triangleABC = cfg.triangleABC.reindex (Equiv.swap 0 1) := by ext i; fin_cases i <;> rfl theorem symm_triangleABC_circumsphere : cfg.symm.triangleABC.circumsphere = cfg.triangleABC.circumsphere := by rw [symm_triangleABC, Affine.Simplex.circumsphere_reindex] /-- `A₂` is the second point of intersection of the ray `AA₁` with the circumcircle of `ABC`. -/ def A₂ : Pt := cfg.triangleABC.circumsphere.secondInter cfg.A (cfg.A₁ -ᵥ cfg.A) /-- `B₂` is the second point of intersection of the ray `BB₁` with the circumcircle of `ABC`. -/ def B₂ : Pt := cfg.triangleABC.circumsphere.secondInter cfg.B (cfg.B₁ -ᵥ cfg.B) theorem A₂_mem_circumsphere : cfg.A₂ ∈ cfg.triangleABC.circumsphere := (Sphere.secondInter_mem _).2 cfg.A_mem_circumsphere theorem B₂_mem_circumsphere : cfg.B₂ ∈ cfg.triangleABC.circumsphere := (Sphere.secondInter_mem _).2 cfg.B_mem_circumsphere theorem symm_A₂ : cfg.symm.A₂ = cfg.B₂ := by simp_rw [A₂, B₂, symm_triangleABC_circumsphere]; rfl theorem QP_parallel_BA : line[ℝ, cfg.Q, cfg.P] ∥ line[ℝ, cfg.B, cfg.A] := by rw [Set.pair_comm cfg.Q, Set.pair_comm cfg.B]; exact cfg.PQ_parallel_AB theorem A_ne_A₁ : cfg.A ≠ cfg.A₁ := by intro h have h' := cfg.not_collinear_ABC rw [h, Set.insert_comm] at h' exact h' cfg.wbtw_B_A₁_C.collinear theorem collinear_PAA₁A₂ : Collinear ℝ ({cfg.P, cfg.A, cfg.A₁, cfg.A₂} : Set Pt) := by rw [A₂, (cfg.triangleABC.circumsphere.secondInter_collinear cfg.A cfg.A₁).collinear_insert_iff_of_ne (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) cfg.A_ne_A₁, Set.insert_comm] exact cfg.wbtw_A_P_A₁.collinear theorem A₁_ne_C : cfg.A₁ ≠ cfg.C := by intro h have hsbtw := cfg.sbtw_Q_A₁_Q₁ rw [h] at hsbtw have ha := hsbtw.angle₂₃₁_eq_zero rw [angle_CQ₁Q_eq_angle_CBA, angle_comm] at ha exact (angle_ne_zero_of_not_collinear cfg.not_collinear_ABC) ha theorem B₁_ne_C : cfg.B₁ ≠ cfg.C := cfg.symm.A₁_ne_C theorem Q_notMem_CB : cfg.Q ∉ line[ℝ, cfg.C, cfg.B] := by intro hQ have hQA₁ : line[ℝ, cfg.Q, cfg.A₁] ≤ line[ℝ, cfg.C, cfg.B] := affineSpan_pair_le_of_mem_of_mem hQ cfg.wbtw_B_A₁_C.symm.mem_affineSpan have hQ₁ : cfg.Q₁ ∈ line[ℝ, cfg.C, cfg.B] := by rw [AffineSubspace.le_def'] at hQA₁ exact hQA₁ _ cfg.sbtw_Q_A₁_Q₁.right_mem_affineSpan have hc : Collinear ℝ ({cfg.C, cfg.Q₁, cfg.Q} : Set Pt) := haveI hc' : Collinear ℝ ({cfg.B, cfg.C, cfg.Q₁, cfg.Q} : Set Pt) := by rw [Set.insert_comm cfg.B, Set.insert_comm cfg.B, Set.pair_comm, Set.insert_comm cfg.C, Set.insert_comm cfg.C] exact collinear_insert_insert_of_mem_affineSpan_pair hQ₁ hQ hc'.subset (Set.subset_insert _ _) rw [collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi, cfg.angle_CQ₁Q_eq_angle_CBA, or_iff_right cfg.C_ne_Q₁, or_iff_right cfg.sbtw_Q_A₁_Q₁.left_ne_right, angle_comm] at hc exact cfg.not_collinear_ABC (hc.elim collinear_of_angle_eq_zero collinear_of_angle_eq_pi) @[deprecated (since := "2025-05-23")] alias Q_not_mem_CB := Q_notMem_CB theorem Q_ne_B : cfg.Q ≠ cfg.B := by intro h have h' := cfg.Q_notMem_CB rw [h] at h' exact h' (right_mem_affineSpan_pair _ _ _) theorem sOppSide_CB_Q_Q₁ : line[ℝ, cfg.C, cfg.B].SOppSide cfg.Q cfg.Q₁ := cfg.sbtw_Q_A₁_Q₁.sOppSide_of_notMem_of_mem cfg.Q_notMem_CB cfg.wbtw_B_A₁_C.symm.mem_affineSpan /-! ### Relate the orientations of different angles in the configuration -/ section Oriented variable [Module.Oriented ℝ V (Fin 2)] theorem oangle_CQ₁Q_sign_eq_oangle_CBA_sign [Fact (finrank ℝ V = 2)] : (∡ cfg.C cfg.Q₁ cfg.Q).sign = (∡ cfg.C cfg.B cfg.A).sign := by rw [← cfg.sbtw_Q_A₁_Q₁.symm.oangle_eq_right, cfg.sOppSide_CB_Q_Q₁.oangle_sign_eq_neg (left_mem_affineSpan_pair ℝ cfg.C cfg.B) cfg.wbtw_B_A₁_C.symm.mem_affineSpan, ← Real.Angle.sign_neg, ← oangle_rev, cfg.wbtw_B_A₁_C.oangle_sign_eq_of_ne_right cfg.Q cfg.A₁_ne_C, oangle_rotate_sign, cfg.wbtw_B_Q_B₁.oangle_eq_right cfg.Q_ne_B, cfg.wbtw_A_B₁_C.symm.oangle_sign_eq_of_ne_left cfg.B cfg.B₁_ne_C.symm] theorem oangle_CQ₁Q_eq_oangle_CBA [Fact (finrank ℝ V = 2)] : ∡ cfg.C cfg.Q₁ cfg.Q = ∡ cfg.C cfg.B cfg.A := oangle_eq_of_angle_eq_of_sign_eq cfg.angle_CQ₁Q_eq_angle_CBA cfg.oangle_CQ₁Q_sign_eq_oangle_CBA_sign end Oriented /-! ### More obvious configuration properties -/ section variable [hd2 : Fact (finrank ℝ V = 2)] theorem A₁_ne_B : cfg.A₁ ≠ cfg.B := by intro h have hwbtw := cfg.wbtw_A_P_A₁ rw [h] at hwbtw have hPQ : line[ℝ, cfg.P, cfg.Q] = line[ℝ, cfg.A, cfg.B] := by rw [AffineSubspace.eq_iff_direction_eq_of_mem (left_mem_affineSpan_pair _ _ _) hwbtw.mem_affineSpan] exact cfg.PQ_parallel_AB.direction_eq haveI := someOrientation V have haQ : (2 : ℤ) • ∡ cfg.C cfg.B cfg.Q = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A := by rw [Collinear.two_zsmul_oangle_eq_right _ cfg.A_ne_B cfg.Q_ne_B] rw [Set.pair_comm, Set.insert_comm] refine collinear_insert_of_mem_affineSpan_pair ?_ rw [← hPQ] exact right_mem_affineSpan_pair _ _ _ have ha : (2 : ℤ) • ∡ cfg.C cfg.B cfg.Q = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.Q := by rw [oangle_CQ₁Q_eq_oangle_CBA, haQ] have hn : ¬Collinear ℝ ({cfg.C, cfg.B, cfg.Q} : Set Pt) := by rw [collinear_iff_of_two_zsmul_oangle_eq haQ, Set.pair_comm, Set.insert_comm, Set.pair_comm] exact cfg.not_collinear_ABC have hc := cospherical_of_two_zsmul_oangle_eq_of_not_collinear ha hn have hBQ₁ : cfg.B ≠ cfg.Q₁ := by rw [← h]; exact cfg.sbtw_Q_A₁_Q₁.ne_right have hQQ₁ : cfg.Q ≠ cfg.Q₁ := cfg.sbtw_Q_A₁_Q₁.left_ne_right have hBQ₁Q : AffineIndependent ℝ ![cfg.B, cfg.Q₁, cfg.Q] := hc.affineIndependent_of_mem_of_ne (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert _ _))) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)))) hBQ₁ cfg.Q_ne_B.symm hQQ₁.symm rw [affineIndependent_iff_not_collinear_set] at hBQ₁Q refine hBQ₁Q ?_ rw [← h, Set.pair_comm, Set.insert_comm] exact cfg.sbtw_Q_A₁_Q₁.wbtw.collinear theorem sbtw_B_A₁_C : Sbtw ℝ cfg.B cfg.A₁ cfg.C := ⟨cfg.wbtw_B_A₁_C, cfg.A₁_ne_B, cfg.A₁_ne_C⟩ theorem sbtw_A_B₁_C : Sbtw ℝ cfg.A cfg.B₁ cfg.C := cfg.symm.sbtw_B_A₁_C theorem sbtw_A_A₁_A₂ : Sbtw ℝ cfg.A cfg.A₁ cfg.A₂ := by refine Sphere.sbtw_secondInter cfg.A_mem_circumsphere ?_ convert cfg.sbtw_B_A₁_C.dist_lt_max_dist _ change _ = max (dist (cfg.triangleABC.points 1) _) (dist (cfg.triangleABC.points 2) _) simp_rw [circumsphere_center, circumsphere_radius, dist_circumcenter_eq_circumradius, max_self] theorem sbtw_B_B₁_B₂ : Sbtw ℝ cfg.B cfg.B₁ cfg.B₂ := by rw [← cfg.symm_A₂]; exact cfg.symm.sbtw_A_A₁_A₂ theorem A₂_ne_A : cfg.A₂ ≠ cfg.A := cfg.sbtw_A_A₁_A₂.left_ne_right.symm theorem A₂_ne_P : cfg.A₂ ≠ cfg.P := (cfg.sbtw_A_A₁_A₂.trans_wbtw_left_ne cfg.wbtw_A_P_A₁).symm theorem A₂_ne_B : cfg.A₂ ≠ cfg.B := by intro h have h₁ := cfg.sbtw_A_A₁_A₂ rw [h] at h₁ refine cfg.not_collinear_ABC ?_ have hc : Collinear ℝ ({cfg.A, cfg.C, cfg.B, cfg.A₁} : Set Pt) := collinear_insert_insert_of_mem_affineSpan_pair h₁.left_mem_affineSpan cfg.sbtw_B_A₁_C.right_mem_affineSpan refine hc.subset ?_ rw [Set.pair_comm _ cfg.A₁, Set.insert_comm _ cfg.A₁, Set.insert_comm _ cfg.A₁, Set.pair_comm] exact Set.subset_insert _ _ theorem A₂_ne_C : cfg.A₂ ≠ cfg.C := by intro h have h₁ := cfg.sbtw_A_A₁_A₂ rw [h] at h₁ refine cfg.not_collinear_ABC ?_ have hc : Collinear ℝ ({cfg.A, cfg.B, cfg.C, cfg.A₁} : Set Pt) := collinear_insert_insert_of_mem_affineSpan_pair h₁.left_mem_affineSpan cfg.sbtw_B_A₁_C.left_mem_affineSpan refine hc.subset ?_ gcongr rw [Set.singleton_subset_iff] exact Set.mem_insert _ _ theorem B₂_ne_B : cfg.B₂ ≠ cfg.B := by rw [← symm_A₂]; exact cfg.symm.A₂_ne_A theorem B₂_ne_Q : cfg.B₂ ≠ cfg.Q := by rw [← symm_A₂]; exact cfg.symm.A₂_ne_P theorem B₂_ne_A₂ : cfg.B₂ ≠ cfg.A₂ := by intro h have hA : Sbtw ℝ (cfg.triangleABC.points 1) cfg.A₁ (cfg.triangleABC.points 2) := cfg.sbtw_B_A₁_C have hB : Sbtw ℝ (cfg.triangleABC.points 0) cfg.B₁ (cfg.triangleABC.points 2) := cfg.sbtw_A_B₁_C have hA' : cfg.A₂ ∈ line[ℝ, cfg.triangleABC.points 0, cfg.A₁] := Sphere.secondInter_vsub_mem_affineSpan _ _ _ have hB' : cfg.A₂ ∈ line[ℝ, cfg.triangleABC.points 1, cfg.B₁] := by rw [← h]; exact Sphere.secondInter_vsub_mem_affineSpan _ _ _ exact (sbtw_of_sbtw_of_sbtw_of_mem_affineSpan_pair (by decide) hA hB hA' hB').symm.not_rotate cfg.sbtw_A_A₁_A₂.wbtw theorem wbtw_B_Q_B₂ : Wbtw ℝ cfg.B cfg.Q cfg.B₂ := cfg.sbtw_B_B₁_B₂.wbtw.trans_left cfg.wbtw_B_Q_B₁ /-! ### The first equality in the first angle chase in the solution -/ section Oriented variable [Module.Oriented ℝ V (Fin 2)] theorem two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂ : (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ = (2 : ℤ) • ∡ cfg.B cfg.A cfg.A₂ := by refine two_zsmul_oangle_of_parallel cfg.QP_parallel_BA ?_ convert AffineSubspace.Parallel.refl (k := ℝ) (P := Pt) _ using 1 rw [cfg.collinear_PAA₁A₂.affineSpan_eq_of_ne (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)))) (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) cfg.A₂_ne_A, cfg.collinear_PAA₁A₂.affineSpan_eq_of_ne (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)))) (Set.mem_insert _ _) cfg.A₂_ne_P] end Oriented /-! ### More obvious configuration properties -/ theorem not_collinear_QPA₂ : ¬Collinear ℝ ({cfg.Q, cfg.P, cfg.A₂} : Set Pt) := by haveI := someOrientation V rw [collinear_iff_of_two_zsmul_oangle_eq cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂, ← affineIndependent_iff_not_collinear_set] have h : Cospherical ({cfg.B, cfg.A, cfg.A₂} : Set Pt) := by refine cfg.triangleABC.circumsphere.cospherical.subset ?_ simp only [Set.insert_subset_iff, cfg.A_mem_circumsphere, cfg.B_mem_circumsphere, cfg.A₂_mem_circumsphere, Sphere.mem_coe, Set.singleton_subset_iff, and_true] exact h.affineIndependent_of_ne cfg.A_ne_B.symm cfg.A₂_ne_B.symm cfg.A₂_ne_A.symm theorem Q₁_ne_A₂ : cfg.Q₁ ≠ cfg.A₂ := by intro h have h₁ := cfg.sbtw_Q_A₁_Q₁ rw [h] at h₁ refine cfg.not_collinear_QPA₂ ?_ have hA₂ := cfg.sbtw_A_A₁_A₂.right_mem_affineSpan have hA₂A₁ : line[ℝ, cfg.A₂, cfg.A₁] ≤ line[ℝ, cfg.A, cfg.A₁] := affineSpan_pair_le_of_left_mem hA₂ have hQ : cfg.Q ∈ line[ℝ, cfg.A, cfg.A₁] := by rw [AffineSubspace.le_def'] at hA₂A₁ exact hA₂A₁ _ h₁.left_mem_affineSpan exact collinear_triple_of_mem_affineSpan_pair hQ cfg.wbtw_A_P_A₁.mem_affineSpan hA₂ theorem affineIndependent_QPA₂ : AffineIndependent ℝ ![cfg.Q, cfg.P, cfg.A₂] := affineIndependent_iff_not_collinear_set.2 cfg.not_collinear_QPA₂ theorem affineIndependent_PQB₂ : AffineIndependent ℝ ![cfg.P, cfg.Q, cfg.B₂] := by rw [← symm_A₂]; exact cfg.symm.affineIndependent_QPA₂ /-- `QPA₂` as a `Triangle`. -/ def triangleQPA₂ : Triangle ℝ Pt := ⟨_, cfg.affineIndependent_QPA₂⟩ /-- `PQB₂` as a `Triangle`. -/ def trianglePQB₂ : Triangle ℝ Pt := ⟨_, cfg.affineIndependent_PQB₂⟩ theorem symm_triangleQPA₂ : cfg.symm.triangleQPA₂ = cfg.trianglePQB₂ := by simp_rw [trianglePQB₂, ← symm_A₂]; ext i; fin_cases i <;> rfl /-- `ω` is the circle containing `Q`, `P` and `A₂`, which will be shown also to contain `B₂`, `P₁` and `Q₁`. -/ def ω : Sphere Pt := cfg.triangleQPA₂.circumsphere theorem P_mem_ω : cfg.P ∈ cfg.ω := cfg.triangleQPA₂.mem_circumsphere 1 theorem Q_mem_ω : cfg.Q ∈ cfg.ω := cfg.triangleQPA₂.mem_circumsphere 0 /-! ### The rest of the first angle chase in the solution -/ section Oriented variable [Module.Oriented ℝ V (Fin 2)] theorem two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_QB₂A₂ : (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ = (2 : ℤ) • ∡ cfg.Q cfg.B₂ cfg.A₂ := calc (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ = (2 : ℤ) • ∡ cfg.B cfg.A cfg.A₂ := cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂ _ = (2 : ℤ) • ∡ cfg.B cfg.B₂ cfg.A₂ := (Sphere.two_zsmul_oangle_eq cfg.B_mem_circumsphere cfg.A_mem_circumsphere cfg.B₂_mem_circumsphere cfg.A₂_mem_circumsphere cfg.A_ne_B cfg.A₂_ne_A.symm cfg.B₂_ne_B cfg.B₂_ne_A₂) _ = (2 : ℤ) • ∡ cfg.Q cfg.B₂ cfg.A₂ := by rw [cfg.wbtw_B_Q_B₂.symm.oangle_eq_left cfg.B₂_ne_Q.symm] end Oriented /-! ### Conclusions from that first angle chase -/ theorem cospherical_QPB₂A₂ : Cospherical ({cfg.Q, cfg.P, cfg.B₂, cfg.A₂} : Set Pt) := haveI := someOrientation V cospherical_of_two_zsmul_oangle_eq_of_not_collinear cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_QB₂A₂ cfg.not_collinear_QPA₂ theorem symm_ω_eq_trianglePQB₂_circumsphere : cfg.symm.ω = cfg.trianglePQB₂.circumsphere := by rw [ω, symm_triangleQPA₂] theorem symm_ω : cfg.symm.ω = cfg.ω := by rw [symm_ω_eq_trianglePQB₂_circumsphere, ω] refine circumsphere_eq_of_cospherical hd2.out cfg.cospherical_QPB₂A₂ ?_ ?_ · simp only [trianglePQB₂, Matrix.range_cons, Matrix.range_empty, Set.singleton_union, insert_empty_eq] rw [Set.insert_comm] gcongr simp · simp only [triangleQPA₂, Matrix.range_cons, Matrix.range_empty, Set.singleton_union, insert_empty_eq] gcongr simp /-! ### The second angle chase in the solution -/ section Oriented variable [Module.Oriented ℝ V (Fin 2)] theorem two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CBA : (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A := calc (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A := by rw [cfg.sbtw_A_A₁_A₂.symm.oangle_eq_right] _ = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A := Sphere.two_zsmul_oangle_eq cfg.C_mem_circumsphere cfg.A₂_mem_circumsphere cfg.B_mem_circumsphere cfg.A_mem_circumsphere cfg.A₂_ne_C cfg.A₂_ne_A cfg.B_ne_C cfg.A_ne_B.symm theorem two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CQ₁A₁ : (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.A₁ := calc (2 : ℤ) • ∡ cfg.C cfg.A₂ cfg.A₁ = (2 : ℤ) • ∡ cfg.C cfg.B cfg.A := cfg.two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CBA _ = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.Q := by rw [oangle_CQ₁Q_eq_oangle_CBA] _ = (2 : ℤ) • ∡ cfg.C cfg.Q₁ cfg.A₁ := by rw [cfg.sbtw_Q_A₁_Q₁.symm.oangle_eq_right] end Oriented /-! ### Conclusions from that second angle chase -/ theorem not_collinear_CA₂A₁ : ¬Collinear ℝ ({cfg.C, cfg.A₂, cfg.A₁} : Set Pt) := by haveI := someOrientation V rw [collinear_iff_of_two_zsmul_oangle_eq cfg.two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CBA, Set.pair_comm, Set.insert_comm, Set.pair_comm] exact cfg.not_collinear_ABC theorem cospherical_A₁Q₁CA₂ : Cospherical ({cfg.A₁, cfg.Q₁, cfg.C, cfg.A₂} : Set Pt) := by haveI := someOrientation V rw [Set.insert_comm cfg.Q₁, Set.insert_comm cfg.A₁, Set.pair_comm, Set.insert_comm cfg.A₁, Set.pair_comm] exact cospherical_of_two_zsmul_oangle_eq_of_not_collinear cfg.two_zsmul_oangle_CA₂A₁_eq_two_zsmul_oangle_CQ₁A₁ cfg.not_collinear_CA₂A₁ /-! ### The third angle chase in the solution -/ section Oriented variable [Module.Oriented ℝ V (Fin 2)] theorem two_zsmul_oangle_QQ₁A₂_eq_two_zsmul_oangle_QPA₂ : (2 : ℤ) • ∡ cfg.Q cfg.Q₁ cfg.A₂ = (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ := calc (2 : ℤ) • ∡ cfg.Q cfg.Q₁ cfg.A₂ = (2 : ℤ) • ∡ cfg.A₁ cfg.Q₁ cfg.A₂ := by rw [cfg.sbtw_Q_A₁_Q₁.symm.oangle_eq_left] _ = (2 : ℤ) • ∡ cfg.A₁ cfg.C cfg.A₂ := (cfg.cospherical_A₁Q₁CA₂.two_zsmul_oangle_eq cfg.sbtw_Q_A₁_Q₁.right_ne cfg.Q₁_ne_A₂ cfg.A₁_ne_C.symm cfg.A₂_ne_C.symm) _ = (2 : ℤ) • ∡ cfg.B cfg.C cfg.A₂ := by rw [cfg.sbtw_B_A₁_C.symm.oangle_eq_left] _ = (2 : ℤ) • ∡ cfg.B cfg.A cfg.A₂ := (Sphere.two_zsmul_oangle_eq cfg.B_mem_circumsphere cfg.C_mem_circumsphere cfg.A_mem_circumsphere cfg.A₂_mem_circumsphere cfg.B_ne_C.symm cfg.A₂_ne_C.symm cfg.A_ne_B cfg.A₂_ne_A.symm) _ = (2 : ℤ) • ∡ cfg.Q cfg.P cfg.A₂ := cfg.two_zsmul_oangle_QPA₂_eq_two_zsmul_oangle_BAA₂.symm end Oriented /-! ### Conclusions from that third angle chase -/ theorem Q₁_mem_ω : cfg.Q₁ ∈ cfg.ω := haveI := someOrientation V Affine.Triangle.mem_circumsphere_of_two_zsmul_oangle_eq (by decide : (0 : Fin 3) ≠ 1) (by decide : (0 : Fin 3) ≠ 2) (by decide) cfg.two_zsmul_oangle_QQ₁A₂_eq_two_zsmul_oangle_QPA₂ theorem P₁_mem_ω : cfg.P₁ ∈ cfg.ω := by rw [← symm_ω]; exact cfg.symm.Q₁_mem_ω theorem result : Concyclic ({cfg.P, cfg.Q, cfg.P₁, cfg.Q₁} : Set Pt) := by refine ⟨?_, coplanar_of_fact_finrank_eq_two _⟩ rw [cospherical_iff_exists_sphere] refine ⟨cfg.ω, ?_⟩ simp only [Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨cfg.P_mem_ω, cfg.Q_mem_ω, cfg.P₁_mem_ω, cfg.Q₁_mem_ω⟩ end end Imo2019q2Cfg end end Imo2019Q2 open Imo2019Q2 theorem imo2019_q2 [Fact (finrank ℝ V = 2)] (A B C A₁ B₁ P Q P₁ Q₁ : Pt) (affine_independent_ABC : AffineIndependent ℝ ![A, B, C]) (wbtw_B_A₁_C : Wbtw ℝ B A₁ C) (wbtw_A_B₁_C : Wbtw ℝ A B₁ C) (wbtw_A_P_A₁ : Wbtw ℝ A P A₁) (wbtw_B_Q_B₁ : Wbtw ℝ B Q B₁) (PQ_parallel_AB : line[ℝ, P, Q] ∥ line[ℝ, A, B]) (P_ne_Q : P ≠ Q) (sbtw_P_B₁_P₁ : Sbtw ℝ P B₁ P₁) (angle_PP₁C_eq_angle_BAC : ∠ P P₁ C = ∠ B A C) (C_ne_P₁ : C ≠ P₁) (sbtw_Q_A₁_Q₁ : Sbtw ℝ Q A₁ Q₁) (angle_CQ₁Q_eq_angle_CBA : ∠ C Q₁ Q = ∠ C B A) (C_ne_Q₁ : C ≠ Q₁) : Concyclic ({P, Q, P₁, Q₁} : Set Pt) := (⟨A, B, C, A₁, B₁, P, Q, P₁, Q₁, affine_independent_ABC, wbtw_B_A₁_C, wbtw_A_B₁_C, wbtw_A_P_A₁, wbtw_B_Q_B₁, PQ_parallel_AB, P_ne_Q, sbtw_P_B₁_P₁, angle_PP₁C_eq_angle_BAC, C_ne_P₁, sbtw_Q_A₁_Q₁, angle_CQ₁Q_eq_angle_CBA, C_ne_Q₁⟩ : Imo2019q2Cfg V Pt).result
Rel.lean
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.Set.BooleanAlgebra /-! # Relations as sets of pairs This file provides API to regard relations between `α` and `β` as sets of pairs `Set (α × β)`. This is in particular useful in the study of uniform spaces, which are topological spaces equipped with a *uniformity*, namely a filter of pairs `α × α` whose elements can be viewed as "proximity" relations. ## Main declarations * `SetRel α β`: Type of relations between `α` and `β`. * `SetRel.inv`: Turn `R : SetRel α β` into `R.inv : SetRel β α` by swapping the arguments. * `SetRel.dom`: Domain of a relation. `a ∈ R.dom` iff there exists `b` such that `a ~[R] b`. * `SetRel.cod`: Codomain of a relation. `b ∈ R.cod` iff there exists `a` such that `a ~[R] b`. * `SetRel.id`: The identity relation `SetRel α α`. * `SetRel.comp`: SetRelation composition. Note that the arguments order follows the category theory convention, namely `(R ○ S) a c ↔ ∃ b, a ~[R] b ∧ b ~[S] z`. * `SetRel.image`: Image of a set under a relation. `b ∈ image R s` iff there exists `a ∈ s` such that `a ~[R] b`. If `R` is the graph of `f` (`a ~[R] b ↔ f a = b`), then `R.image = Set.image f`. * `SetRel.preimage`: Preimage of a set under a relation. `a ∈ preimage R t` iff there exists `b ∈ t` such that `a ~[R] b`. If `R` is the graph of `f` (`a ~[R] b ↔ f a = b`), then `R.preimage = Set.preimage f`. * `SetRel.core`: Core of a set. For `t : Set β`, `a ∈ R.core t` iff all `b` related to `a` are in `t`. * `SetRel.restrictDomain`: Domain-restriction of a relation to a subtype. * `Function.graph`: Graph of a function as a relation. ## Implementation notes There is tension throughout the library between considering relations between `α` and `β` simply as `α → β → Prop`, or as a bundled object `SetRel α β` with dedicated operations and API. The former approach is used almost everywhere as it is very lightweight and has arguably native support from core Lean features, but it cracks at the seams whenever one starts talking about operations on relations. For example: * composition of relations `R : α → β → Prop`, `S : β → γ → Prop` is `SetRelation.Comp R S := fun a c ↦ ∃ b, R a b ∧ S b c` * map of a relation `R : α → β → Prop` under `f : α → γ`, `g : β → δ` is `SetRelation.map R f g := fun c d ↦ ∃ a b, r a b ∧ f a = c ∧ g b = d`. The latter approach is embodied by `SetRel α β`, with dedicated notation like `○` for composition. Previously, `SetRel` suffered from the leakage of its definition as ``` def SetRel (α β : Type*) := α → β → Prop ``` The fact that `SetRel` wasn't an `abbrev` confuses automation. But simply making it an `abbrev` would have killed the point of having a separate less see-through type to perform relation operations on, so we instead redefined ``` def SetRel (α β : Type*) := Set (α × β) → Prop ``` This extra level of indirection guides automation correctly and prevents (some kinds of) leakage. Simultaneously, uniform spaces need a theory of relations on a type `α` as elements of `Set (α × α)`, and the new definition of `SetRel` fulfills this role quite well. -/ variable {α β γ δ : Type*} /-- A relation on `α` and `β`, aka a set-valued function, aka a partial multifunction. We represent them as sets due to how relations are used in the context of uniform spaces. -/ abbrev SetRel (α β : Type*) := Set (α × β) namespace SetRel variable {R r₁ r₂ : SetRel α β} {S : SetRel β γ} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {u : Set γ} {a a₁ a₂ : α} {b : β} {c : γ} /-- Notation for apply a relation `R : SetRel α β` to `a : α`, `b : β`, scoped to the `SetRel` namespace. Since `SetRel α β := Set (α × β)`, `a ~[R] b` is simply notation for `(a, b) ∈ R`, but this should be considered an implementation detail. -/ scoped notation:50 a:50 " ~[" R "] " b:50 => (a, b) ∈ R variable (R) in /-- The inverse relation : `R.inv x y ↔ R y x`. Note that this is *not* a groupoid inverse. -/ def inv (R : SetRel α β) : SetRel β α := Prod.swap ⁻¹' R @[simp] lemma mem_inv : b ~[R.inv] a ↔ a ~[R] b := .rfl @[deprecated (since := "2025-07-06")] alias inv_def := mem_inv @[simp] lemma inv_inv : R.inv.inv = R := rfl @[gcongr] lemma inv_mono (h : r₁ ⊆ r₂) : r₁.inv ⊆ r₂.inv := fun (_a, _b) hab ↦ h hab @[simp] lemma inv_empty : (∅ : SetRel α β).inv = ∅ := rfl @[simp] lemma inv_univ : inv (.univ : SetRel α β) = .univ := rfl @[deprecated (since := "2025-07-06")] alias inv_bot := inv_empty variable (R) in /-- Domain of a relation. -/ def dom : Set α := {a | ∃ b, a ~[R] b} variable (R) in /-- Codomain of a relation, aka range. -/ def cod : Set β := {b | ∃ a, a ~[R] b} @[deprecated (since := "2025-07-06")] alias codom := cod @[simp] lemma mem_dom : a ∈ R.dom ↔ ∃ b, a ~[R] b := .rfl @[simp] lemma mem_cod : b ∈ R.cod ↔ ∃ a, a ~[R] b := .rfl @[gcongr] lemma dom_mono (h : r₁ ≤ r₂) : r₁.dom ⊆ r₂.dom := fun _a ⟨b, hab⟩ ↦ ⟨b, h hab⟩ @[gcongr] lemma cod_mono (h : r₁ ≤ r₂) : r₁.cod ⊆ r₂.cod := fun _b ⟨a, hab⟩ ↦ ⟨a, h hab⟩ @[simp] lemma dom_empty : (∅ : SetRel α β).dom = ∅ := by aesop @[simp] lemma cod_empty : (∅ : SetRel α β).cod = ∅ := by aesop @[simp] lemma dom_univ [Nonempty β] : dom (.univ : SetRel α β) = .univ := by aesop @[simp] lemma cod_univ [Nonempty α] : cod (.univ : SetRel α β) = .univ := by aesop @[simp] lemma cod_inv : R.inv.cod = R.dom := rfl @[simp] lemma dom_inv : R.inv.dom = R.cod := rfl @[deprecated (since := "2025-07-06")] alias codom_inv := cod_inv /-- The identity relation. -/ protected def id : SetRel α α := {(a₁, a₂) | a₁ = a₂} @[simp] lemma mem_id : a₁ ~[SetRel.id] a₂ ↔ a₁ = a₂ := .rfl @[simp] lemma inv_id : (.id : SetRel α α).inv = .id := by aesop /-- Composition of relation. Note that this follows the `CategoryTheory` order of arguments. -/ def comp (R : SetRel α β) (S : SetRel β γ) : SetRel α γ := {(a, c) | ∃ b, a ~[R] b ∧ b ~[S] c} @[inherit_doc] scoped infixl:62 " ○ " => comp @[simp] lemma mem_comp : a ~[R ○ S] c ↔ ∃ b, a ~[R] b ∧ b ~[S] c := .rfl lemma comp_assoc (R : SetRel α β) (S : SetRel β γ) (t : SetRel γ δ) : (R ○ S) ○ t = R ○ (S ○ t) := by aesop @[simp] lemma comp_id (R : SetRel α β) : R ○ .id = R := by aesop @[simp] lemma id_comp (R : SetRel α β) : .id ○ R = R := by aesop @[simp] lemma inv_comp (R : SetRel α β) (S : SetRel β γ) : (R ○ S).inv = S.inv ○ R.inv := by aesop @[simp] lemma comp_empty (R : SetRel α β) : R ○ (∅ : SetRel β γ) = ∅ := by aesop @[simp] lemma empty_comp (S : SetRel β γ) : (∅ : SetRel α β) ○ S = ∅ := by aesop @[simp] lemma comp_univ (R : SetRel α β) : R ○ (.univ : SetRel β γ) = {(a, _c) : α × γ | a ∈ R.dom} := by aesop @[simp] lemma univ_comp (S : SetRel β γ) : (.univ : SetRel α β) ○ S = {(_b, c) : α × γ | c ∈ S.cod} := by aesop @[deprecated (since := "2025-07-06")] alias comp_right_top := comp_univ @[deprecated (since := "2025-07-06")] alias comp_left_top := univ_comp variable (R s) in /-- Image of a set under a relation. -/ def image : Set β := {b | ∃ a ∈ s, a ~[R] b} variable (R t) in /-- Preimage of a set `t` under a relation `R`. Same as the image of `t` under `R.inv`. -/ def preimage : Set α := {a | ∃ b ∈ t, a ~[R] b} @[simp] lemma mem_image : b ∈ image R s ↔ ∃ a ∈ s, a ~[R] b := .rfl @[simp] lemma mem_preimage : a ∈ preimage R t ↔ ∃ b ∈ t, a ~[R] b := .rfl @[gcongr] lemma image_subset_image (hs : s₁ ⊆ s₂) : image R s₁ ⊆ image R s₂ := fun _ ⟨a, ha, hab⟩ ↦ ⟨a, hs ha, hab⟩ @[gcongr] lemma preimage_subset_preimage (ht : t₁ ⊆ t₂) : preimage R t₁ ⊆ preimage R t₂ := fun _ ⟨a, ha, hab⟩ ↦ ⟨a, ht ha, hab⟩ variable (R t) in @[simp] lemma image_inv : R.inv.image t = preimage R t := rfl variable (R s) in @[simp] lemma preimage_inv : R.inv.preimage s = image R s := rfl lemma image_mono : Monotone R.image := fun _ _ ↦ image_subset_image lemma preimage_mono : Monotone R.preimage := fun _ _ ↦ preimage_subset_preimage @[simp] lemma image_empty_right : image R ∅ = ∅ := by aesop @[simp] lemma preimage_empty_right : preimage R ∅ = ∅ := by aesop @[simp] lemma image_univ_right : image R .univ = R.cod := by aesop @[simp] lemma preimage_univ_right : preimage R .univ = R.dom := by aesop variable (R) in lemma image_inter_subset : image R (s₁ ∩ s₂) ⊆ image R s₁ ∩ image R s₂ := image_mono.map_inf_le .. @[deprecated (since := "2025-07-06")] alias preimage_top := image_inter_subset variable (R) in lemma preimage_inter_subset : preimage R (t₁ ∩ t₂) ⊆ preimage R t₁ ∩ preimage R t₂ := preimage_mono.map_inf_le .. @[deprecated (since := "2025-07-06")] alias image_eq_dom_of_codomain_subset := preimage_inter_subset variable (R s₁ s₂) in lemma image_union : image R (s₁ ∪ s₂) = image R s₁ ∪ image R s₂ := by aesop @[deprecated (since := "2025-07-06")] alias preimage_eq_codom_of_domain_subset := image_union variable (R t₁ t₂) in lemma preimage_union : preimage R (t₁ ∪ t₂) = preimage R t₁ ∪ preimage R t₂ := by aesop variable (s) in @[simp] lemma image_id : image .id s = s := by aesop variable (s) in @[simp] lemma preimage_id : preimage .id s = s := by aesop variable (R S s) in lemma image_comp : image (R ○ S) s = image S (image R s) := by aesop variable (R S u) in lemma preimage_comp : preimage (R ○ S) u = preimage R (preimage S u) := by aesop variable (s) in @[simp] lemma image_empty_left : image (∅ : SetRel α β) s = ∅ := by aesop variable (t) in @[simp] lemma preimage_empty_left : preimage (∅ : SetRel α β) t = ∅ := by aesop @[deprecated (since := "2025-07-06")] alias preimage_bot := preimage_empty_left @[simp] lemma image_univ_left (hs : s.Nonempty) : image (.univ : SetRel α β) s = .univ := by aesop @[simp] lemma preimage_univ_left (ht : t.Nonempty) : preimage (.univ : SetRel α β) t = .univ := by aesop lemma image_eq_cod_of_dom_subset (h : R.cod ⊆ t) : R.preimage t = R.dom := by aesop lemma preimage_eq_dom_of_cod_subset (h : R.cod ⊆ t) : R.preimage t = R.dom := by aesop variable (R s) in @[simp] lemma image_inter_dom : image R (s ∩ R.dom) = image R s := by aesop variable (R t) in @[simp] lemma preimage_inter_cod : preimage R (t ∩ R.cod) = preimage R t := by aesop @[deprecated (since := "2025-07-06")] alias preimage_inter_codom_eq := preimage_inter_cod lemma inter_dom_subset_preimage_image : s ∩ R.dom ⊆ R.preimage (image R s) := by aesop (add simp [Set.subset_def]) lemma inter_cod_subset_image_preimage : t ∩ R.cod ⊆ image R (R.preimage t) := by aesop (add simp [Set.subset_def]) @[deprecated (since := "2025-07-06")] alias image_preimage_subset_inter_codom := inter_cod_subset_image_preimage variable (R t) in /-- Core of a set `S : Set β` w.R.t `R : SetRel α β` is the set of `x : α` that are related *only* to elements of `S`. Other generalization of `Function.preimage`. -/ def core : Set α := {a | ∀ ⦃b⦄, a ~[R] b → b ∈ t} @[simp] lemma mem_core : a ∈ R.core t ↔ ∀ ⦃b⦄, a ~[R] b → b ∈ t := .rfl @[gcongr] lemma core_subset_core (ht : t₁ ⊆ t₂) : R.core t₁ ⊆ R.core t₂ := fun _a ha _b hab ↦ ht <| ha hab lemma core_mono : Monotone R.core := fun _ _ ↦ core_subset_core variable (R t₁ t₂) in lemma core_inter : R.core (t₁ ∩ t₂) = R.core t₁ ∩ R.core t₂ := by aesop lemma core_union_subset : R.core t₁ ∪ R.core t₂ ⊆ R.core (t₁ ∪ t₂) := core_mono.le_map_sup .. @[simp] lemma core_univ : R.core Set.univ = Set.univ := by aesop variable (t) in @[simp] lemma core_id : core .id t = t := by aesop variable (R S u) in lemma core_comp : core (R ○ S) u = core R (core S u) := by aesop lemma image_subset_iff : image R s ⊆ t ↔ s ⊆ core R t := by aesop (add simp [Set.subset_def]) lemma image_core_gc : GaloisConnection R.image R.core := fun _ _ ↦ image_subset_iff variable (R s) in /-- Restrict the domain of a relation to a subtype. -/ def restrictDomain : SetRel s β := {(a, b) | ↑a ~[R] b} variable {R : SetRel α α} {S : SetRel β β} {a b c : α} variable (R) in /-- A relation `R` is transitive if `a ~[R] b` and `b ~[R] c` together imply `a ~[R] c`. -/ protected abbrev IsTrans : Prop := IsTrans α (· ~[R] ·) variable (R) in protected lemma trans [R.IsTrans] (hab : a ~[R] b) (hbc : b ~[R] c) : a ~[R] c := trans_of (· ~[R] ·) hab hbc instance {R : α → α → Prop} [IsTrans α R] : SetRel.IsTrans {(a, b) | R a b} := ‹_› variable (R) in /-- A relation `R` is irreflexive if `¬ a ~[R] a`. -/ protected abbrev IsIrrefl : Prop := IsIrrefl α (· ~[R] ·) variable (R a) in protected lemma irrefl [R.IsIrrefl] : ¬ a ~[R] a := irrefl_of (· ~[R] ·) _ instance {R : α → α → Prop} [IsIrrefl α R] : SetRel.IsIrrefl {(a, b) | R a b} := ‹_› variable (R) in /-- A relation `R` on a type `α` is well-founded if all elements of `α` are accessible within `R`. -/ abbrev IsWellFounded : Prop := WellFounded (· ~[R] ·) variable (R S) in /-- A relation homomorphism with respect to a given pair of relations `R` and `S` s is a function `f : α → β` such that `a ~[R] b → f a ~[s] f b`. -/ abbrev Hom := (· ~[R] ·) →r (· ~[S] ·) end SetRel open Set open scoped SetRel namespace Function variable {f : α → β} {a : α} {b : β} /-- The graph of a function as a relation. -/ def graph (f : α → β) : SetRel α β := {(a, b) | f a = b} @[simp] lemma mem_graph : a ~[f.graph] b ↔ f a = b := .rfl @[deprecated (since := "2025-07-06")] alias graph_def := mem_graph theorem graph_injective : Injective (graph : (α → β) → SetRel α β) := by aesop (add simp [Injective, Set.ext_iff]) @[simp] lemma graph_inj {f g : α → β} : f.graph = g.graph ↔ f = g := graph_injective.eq_iff @[simp] lemma graph_id : graph (id : α → α) = .id := by aesop theorem graph_comp (f : β → γ) (g : α → β) : graph (f ∘ g) = graph g ○ graph f := by aesop end Function theorem Equiv.graph_inv (f : α ≃ β) : (f.symm : β → α).graph = SetRel.inv (f : α → β).graph := by aesop lemma SetRel.exists_graph_eq_iff (R : SetRel α β) : (∃! f, Function.graph f = R) ↔ ∀ a, ∃! b, a ~[R] b := by constructor · rintro ⟨f, rfl, _⟩ x simp intro h choose f hf using fun x ↦ (h x).exists refine ⟨f, ?_, by aesop⟩ ext ⟨a, b⟩ constructor · aesop · exact (h _).unique (hf _) @[deprecated (since := "2025-07-06")] alias SetRelation.is_graph_iff := SetRel.exists_graph_eq_iff namespace Set theorem image_eq (f : α → β) (s : Set α) : f '' s = (Function.graph f).image s := by rfl theorem preimage_eq (f : α → β) (s : Set β) : f ⁻¹' s = (Function.graph f).preimage s := by simp [Set.preimage, SetRel.preimage] theorem preimage_eq_core (f : α → β) (s : Set β) : f ⁻¹' s = (Function.graph f).core s := by simp [Set.preimage, SetRel.core] end Set /-- A shorthand for `α → β → Prop`. Consider using `SetRel` instead if you want extra API for relations. -/ abbrev Rel (α β : Type*) : Type _ := α → β → Prop
Limits.lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Johan Commelin -/ import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Limits.Creates /-! # Adjunctions and limits A left adjoint preserves colimits (`CategoryTheory.Adjunction.leftAdjoint_preservesColimits`), and a right adjoint preserves limits (`CategoryTheory.Adjunction.rightAdjoint_preservesLimits`). Equivalences create and reflect (co)limits. (`CategoryTheory.Functor.createsLimitsOfIsEquivalence`, `CategoryTheory.Functor.createsColimitsOfIsEquivalence`, `CategoryTheory.Functor.reflectsLimits_of_isEquivalence`, `CategoryTheory.Functor.reflectsColimits_of_isEquivalence`.) In `CategoryTheory.Adjunction.coconesIso` we show that when `F ⊣ G`, the functor associating to each `Y` the cocones over `K ⋙ F` with cone point `Y` is naturally isomorphic to the functor associating to each `Y` the cocones over `K` with cone point `G.obj Y`. -/ open Opposite namespace CategoryTheory open Functor Limits universe v u v₁ v₂ v₀ u₁ u₂ namespace Adjunction section ArbitraryUniverse variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) section PreservationColimits variable {J : Type u} [Category.{v} J] (K : J ⥤ C) /-- The right adjoint of `Cocones.functoriality K F : Cocone K ⥤ Cocone (K ⋙ F)`. Auxiliary definition for `functorialityIsLeftAdjoint`. -/ def functorialityRightAdjoint : Cocone (K ⋙ F) ⥤ Cocone K := Cocones.functoriality _ G ⋙ Cocones.precompose (K.rightUnitor.inv ≫ whiskerLeft K adj.unit ≫ (associator _ _ _).inv) attribute [local simp] functorialityRightAdjoint /-- The unit for the adjunction for `Cocones.functoriality K F : Cocone K ⥤ Cocone (K ⋙ F)`. Auxiliary definition for `functorialityIsLeftAdjoint`. -/ @[simps] def functorialityUnit : 𝟭 (Cocone K) ⟶ Cocones.functoriality _ F ⋙ functorialityRightAdjoint adj K where app c := { hom := adj.unit.app c.pt } /-- The counit for the adjunction for `Cocones.functoriality K F : Cocone K ⥤ Cocone (K ⋙ F)`. Auxiliary definition for `functorialityIsLeftAdjoint`. -/ @[simps] def functorialityCounit : functorialityRightAdjoint adj K ⋙ Cocones.functoriality _ F ⟶ 𝟭 (Cocone (K ⋙ F)) where app c := { hom := adj.counit.app c.pt } /-- The functor `Cocones.functoriality K F : Cocone K ⥤ Cocone (K ⋙ F)` is a left adjoint. -/ def functorialityAdjunction : Cocones.functoriality K F ⊣ functorialityRightAdjoint adj K where unit := functorialityUnit adj K counit := functorialityCounit adj K include adj in /-- A left adjoint preserves colimits. -/ @[stacks 0038] lemma leftAdjoint_preservesColimits : PreservesColimitsOfSize.{v, u} F where preservesColimitsOfShape := { preservesColimit := { preserves := fun hc => ⟨IsColimit.isoUniqueCoconeMorphism.inv fun _ => @Equiv.unique _ _ (IsColimit.isoUniqueCoconeMorphism.hom hc _) ((adj.functorialityAdjunction _).homEquiv _ _)⟩ } } noncomputable instance colim_preservesColimits [HasColimitsOfShape J C] : PreservesColimits (colim (J := J) (C := C)) := colimConstAdj.leftAdjoint_preservesColimits -- see Note [lower instance priority] noncomputable instance (priority := 100) isEquivalence_preservesColimits (E : C ⥤ D) [E.IsEquivalence] : PreservesColimitsOfSize.{v, u} E := leftAdjoint_preservesColimits E.adjunction -- see Note [lower instance priority] noncomputable instance (priority := 100) _root_.CategoryTheory.Functor.reflectsColimits_of_isEquivalence (E : D ⥤ C) [E.IsEquivalence] : ReflectsColimitsOfSize.{v, u} E where reflectsColimitsOfShape := { reflectsColimit := { reflects := fun t => ⟨(isColimitOfPreserves E.inv t).mapCoconeEquiv E.asEquivalence.unitIso.symm⟩ } } -- see Note [lower instance priority] noncomputable instance (priority := 100) _root_.CategoryTheory.Functor.createsColimitsOfIsEquivalence (H : D ⥤ C) [H.IsEquivalence] : CreatesColimitsOfSize.{v, u} H where CreatesColimitsOfShape := { CreatesColimit := { lifts := fun c _ => { liftedCocone := mapCoconeInv H c validLift := mapCoconeMapCoconeInv H c } } } -- verify the preserve_colimits instance works as expected: noncomputable example (E : C ⥤ D) [E.IsEquivalence] (c : Cocone K) (h : IsColimit c) : IsColimit (E.mapCocone c) := isColimitOfPreserves E h theorem hasColimit_comp_equivalence (E : C ⥤ D) [E.IsEquivalence] [HasColimit K] : HasColimit (K ⋙ E) := HasColimit.mk { cocone := E.mapCocone (colimit.cocone K) isColimit := isColimitOfPreserves _ (colimit.isColimit K) } theorem hasColimit_of_comp_equivalence (E : C ⥤ D) [E.IsEquivalence] [HasColimit (K ⋙ E)] : HasColimit K := by rw [hasColimit_iff_of_iso ((Functor.rightUnitor _).symm ≪≫ isoWhiskerLeft K E.asEquivalence.unitIso)] exact hasColimit_comp_equivalence (K ⋙ E) E.inv /-- Transport a `HasColimitsOfShape` instance across an equivalence. -/ theorem hasColimitsOfShape_of_equivalence (E : C ⥤ D) [E.IsEquivalence] [HasColimitsOfShape J D] : HasColimitsOfShape J C := ⟨fun F => hasColimit_of_comp_equivalence F E⟩ /-- Transport a `HasColimitsOfSize` instance across an equivalence. -/ theorem has_colimits_of_equivalence (E : C ⥤ D) [E.IsEquivalence] [HasColimitsOfSize.{v, u} D] : HasColimitsOfSize.{v, u} C := ⟨fun _ _ => hasColimitsOfShape_of_equivalence E⟩ end PreservationColimits section PreservationLimits variable {J : Type u} [Category.{v} J] (K : J ⥤ D) /-- The left adjoint of `Cones.functoriality K G : Cone K ⥤ Cone (K ⋙ G)`. Auxiliary definition for `functorialityIsRightAdjoint`. -/ def functorialityLeftAdjoint : Cone (K ⋙ G) ⥤ Cone K := Cones.functoriality _ F ⋙ Cones.postcompose ((associator _ _ _).hom ≫ whiskerLeft K adj.counit ≫ K.rightUnitor.hom) attribute [local simp] functorialityLeftAdjoint /-- The unit for the adjunction for `Cones.functoriality K G : Cone K ⥤ Cone (K ⋙ G)`. Auxiliary definition for `functorialityIsRightAdjoint`. -/ @[simps] def functorialityUnit' : 𝟭 (Cone (K ⋙ G)) ⟶ functorialityLeftAdjoint adj K ⋙ Cones.functoriality _ G where app c := { hom := adj.unit.app c.pt } /-- The counit for the adjunction for `Cones.functoriality K G : Cone K ⥤ Cone (K ⋙ G)`. Auxiliary definition for `functorialityIsRightAdjoint`. -/ @[simps] def functorialityCounit' : Cones.functoriality _ G ⋙ functorialityLeftAdjoint adj K ⟶ 𝟭 (Cone K) where app c := { hom := adj.counit.app c.pt } /-- The functor `Cones.functoriality K G : Cone K ⥤ Cone (K ⋙ G)` is a right adjoint. -/ def functorialityAdjunction' : functorialityLeftAdjoint adj K ⊣ Cones.functoriality K G where unit := functorialityUnit' adj K counit := functorialityCounit' adj K include adj in /-- A right adjoint preserves limits. -/ @[stacks 0038] lemma rightAdjoint_preservesLimits : PreservesLimitsOfSize.{v, u} G where preservesLimitsOfShape := { preservesLimit := { preserves := fun hc => ⟨IsLimit.isoUniqueConeMorphism.inv fun _ => @Equiv.unique _ _ (IsLimit.isoUniqueConeMorphism.hom hc _) ((adj.functorialityAdjunction' _).homEquiv _ _).symm⟩ } } instance lim_preservesLimits [HasLimitsOfShape J C] : PreservesLimits (lim (J := J) (C := C)) := constLimAdj.rightAdjoint_preservesLimits -- see Note [lower instance priority] instance (priority := 100) isEquivalencePreservesLimits (E : D ⥤ C) [E.IsEquivalence] : PreservesLimitsOfSize.{v, u} E := rightAdjoint_preservesLimits E.asEquivalence.symm.toAdjunction -- see Note [lower instance priority] noncomputable instance (priority := 100) _root_.CategoryTheory.Functor.reflectsLimits_of_isEquivalence (E : D ⥤ C) [E.IsEquivalence] : ReflectsLimitsOfSize.{v, u} E where reflectsLimitsOfShape := { reflectsLimit := { reflects := fun t => ⟨(isLimitOfPreserves E.inv t).mapConeEquiv E.asEquivalence.unitIso.symm⟩ } } -- see Note [lower instance priority] noncomputable instance (priority := 100) _root_.CategoryTheory.Functor.createsLimitsOfIsEquivalence (H : D ⥤ C) [H.IsEquivalence] : CreatesLimitsOfSize.{v, u} H where CreatesLimitsOfShape := { CreatesLimit := { lifts := fun c _ => { liftedCone := mapConeInv H c validLift := mapConeMapConeInv H c } } } -- verify the preserve_limits instance works as expected: noncomputable example (E : D ⥤ C) [E.IsEquivalence] (c : Cone K) (h : IsLimit c) : IsLimit (E.mapCone c) := isLimitOfPreserves E h theorem hasLimit_comp_equivalence (E : D ⥤ C) [E.IsEquivalence] [HasLimit K] : HasLimit (K ⋙ E) := HasLimit.mk { cone := E.mapCone (limit.cone K) isLimit := isLimitOfPreserves _ (limit.isLimit K) } theorem hasLimit_of_comp_equivalence (E : D ⥤ C) [E.IsEquivalence] [HasLimit (K ⋙ E)] : HasLimit K := by rw [← hasLimit_iff_of_iso (isoWhiskerLeft K E.asEquivalence.unitIso.symm ≪≫ Functor.rightUnitor _)] exact hasLimit_comp_equivalence (K ⋙ E) E.inv /-- Transport a `HasLimitsOfShape` instance across an equivalence. -/ theorem hasLimitsOfShape_of_equivalence (E : D ⥤ C) [E.IsEquivalence] [HasLimitsOfShape J C] : HasLimitsOfShape J D := ⟨fun F => hasLimit_of_comp_equivalence F E⟩ /-- Transport a `HasLimitsOfSize` instance across an equivalence. -/ theorem has_limits_of_equivalence (E : D ⥤ C) [E.IsEquivalence] [HasLimitsOfSize.{v, u} C] : HasLimitsOfSize.{v, u} D := ⟨fun _ _ => hasLimitsOfShape_of_equivalence E⟩ end PreservationLimits /-- auxiliary construction for `coconesIso` -/ @[simp] def coconesIsoComponentHom {J : Type u} [Category.{v} J] {K : J ⥤ C} (Y : D) (t : ((cocones J D).obj (op (K ⋙ F))).obj Y) : (G ⋙ (cocones J C).obj (op K)).obj Y where app j := (adj.homEquiv (K.obj j) Y) (t.app j) naturality j j' f := by rw [← adj.homEquiv_naturality_left, ← Functor.comp_map, t.naturality] simp /-- auxiliary construction for `coconesIso` -/ @[simp] def coconesIsoComponentInv {J : Type u} [Category.{v} J] {K : J ⥤ C} (Y : D) (t : (G ⋙ (cocones J C).obj (op K)).obj Y) : ((cocones J D).obj (op (K ⋙ F))).obj Y where app j := (adj.homEquiv (K.obj j) Y).symm (t.app j) naturality j j' f := by erw [← adj.homEquiv_naturality_left_symm, ← adj.homEquiv_naturality_right_symm, t.naturality] simp /-- auxiliary construction for `conesIso` -/ @[simp] def conesIsoComponentHom {J : Type u} [Category.{v} J] {K : J ⥤ D} (X : Cᵒᵖ) (t : (Functor.op F ⋙ (cones J D).obj K).obj X) : ((cones J C).obj (K ⋙ G)).obj X where app j := (adj.homEquiv (unop X) (K.obj j)) (t.app j) naturality j j' f := by erw [← adj.homEquiv_naturality_right, ← t.naturality, Category.id_comp, Category.id_comp] rfl /-- auxiliary construction for `conesIso` -/ @[simp] def conesIsoComponentInv {J : Type u} [Category.{v} J] {K : J ⥤ D} (X : Cᵒᵖ) (t : ((cones J C).obj (K ⋙ G)).obj X) : (Functor.op F ⋙ (cones J D).obj K).obj X where app j := (adj.homEquiv (unop X) (K.obj j)).symm (t.app j) naturality j j' f := by erw [← adj.homEquiv_naturality_right_symm, ← t.naturality, Category.id_comp, Category.id_comp] end ArbitraryUniverse variable {C : Type u₁} [Category.{v₀} C] {D : Type u₂} [Category.{v₀} D] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) attribute [local simp] homEquiv_unit homEquiv_counit -- Note: this is natural in K, but we do not yet have the tools to formulate that. /-- When `F ⊣ G`, the functor associating to each `Y` the cocones over `K ⋙ F` with cone point `Y` is naturally isomorphic to the functor associating to each `Y` the cocones over `K` with cone point `G.obj Y`. -/ def coconesIso {J : Type u} [Category.{v} J] {K : J ⥤ C} : (cocones J D).obj (op (K ⋙ F)) ≅ G ⋙ (cocones J C).obj (op K) := NatIso.ofComponents fun Y => { hom := coconesIsoComponentHom adj Y inv := coconesIsoComponentInv adj Y } -- Note: this is natural in K, but we do not yet have the tools to formulate that. /-- When `F ⊣ G`, the functor associating to each `X` the cones over `K` with cone point `F.op.obj X` is naturally isomorphic to the functor associating to each `X` the cones over `K ⋙ G` with cone point `X`. -/ def conesIso {J : Type u} [Category.{v} J] {K : J ⥤ D} : F.op ⋙ (cones J D).obj K ≅ (cones J C).obj (K ⋙ G) := NatIso.ofComponents fun X => { hom := conesIsoComponentHom adj X inv := conesIsoComponentInv adj X } end Adjunction namespace Functor variable {J C D : Type*} [Category J] [Category C] [Category D] (F : C ⥤ D) noncomputable instance [IsLeftAdjoint F] : PreservesColimitsOfShape J F := (Adjunction.ofIsLeftAdjoint F).leftAdjoint_preservesColimits.preservesColimitsOfShape noncomputable instance [IsLeftAdjoint F] : PreservesColimitsOfSize.{v, u} F where noncomputable instance [IsRightAdjoint F] : PreservesLimitsOfShape J F := (Adjunction.ofIsRightAdjoint F).rightAdjoint_preservesLimits.preservesLimitsOfShape noncomputable instance [IsRightAdjoint F] : PreservesLimitsOfSize.{v, u} F where end Functor end CategoryTheory
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.lean`. ## 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] : Prop extends StarHomClass F A B 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, norm_cast] 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 [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 : 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] : Prop extends RingEquivClass F A B 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 := 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 /-- Auxiliary 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] /-- 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
Basic.lean
/- Copyright (c) 2016 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.Data.Set.Defs import Mathlib.Logic.Basic import Mathlib.Logic.ExistsUnique import Mathlib.Logic.Nonempty import Mathlib.Logic.Nontrivial.Defs import Batteries.Tactic.Init import Mathlib.Order.Defs.Unbundled /-! # Miscellaneous function constructions and lemmas -/ open Function universe u v w x namespace Function section variable {α β γ : Sort*} {f : α → β} /-- Evaluate a function at an argument. Useful if you want to talk about the partially applied `Function.eval x : (∀ x, β x) → β x`. -/ @[reducible, simp] def eval {β : α → Sort*} (x : α) (f : ∀ x, β x) : β x := f x theorem eval_apply {β : α → Sort*} (x : α) (f : ∀ x, β x) : eval x f = f x := rfl theorem const_def {y : β} : (fun _ : α ↦ y) = const α y := rfl theorem const_injective [Nonempty α] : Injective (const α : β → α → β) := fun _ _ h ↦ let ⟨x⟩ := ‹Nonempty α› congr_fun h x @[simp] theorem const_inj [Nonempty α] {y₁ y₂ : β} : const α y₁ = const α y₂ ↔ y₁ = y₂ := ⟨fun h ↦ const_injective h, fun h ↦ h ▸ rfl⟩ theorem onFun_apply (f : β → β → γ) (g : α → β) (a b : α) : onFun f g a b = f (g a) (g b) := rfl lemma hfunext {α α' : Sort u} {β : α → Sort v} {β' : α' → Sort v} {f : ∀ a, β a} {f' : ∀ a, β' a} (hα : α = α') (h : ∀ a a', a ≍ a' → f a ≍ f' a') : f ≍ f' := by subst hα have : ∀ a, f a ≍ f' a := fun a ↦ h a a (HEq.refl a) have : β = β' := by funext a; exact type_eq_of_heq (this a) subst this apply heq_of_eq funext a exact eq_of_heq (this a) theorem ne_iff {β : α → Sort*} {f₁ f₂ : ∀ a, β a} : f₁ ≠ f₂ ↔ ∃ a, f₁ a ≠ f₂ a := funext_iff.not.trans not_forall lemma funext_iff_of_subsingleton [Subsingleton α] {g : α → β} (x y : α) : f x = g y ↔ f = g := by refine ⟨fun h ↦ funext fun z ↦ ?_, fun h ↦ ?_⟩ · rwa [Subsingleton.elim x z, Subsingleton.elim y z] at h · rw [h, Subsingleton.elim x y] theorem swap_lt {α} [LT α] : swap (· < · : α → α → _) = (· > ·) := rfl theorem swap_le {α} [LE α] : swap (· ≤ · : α → α → _) = (· ≥ ·) := rfl theorem swap_gt {α} [LT α] : swap (· > · : α → α → _) = (· < ·) := rfl theorem swap_ge {α} [LE α] : swap (· ≥ · : α → α → _) = (· ≤ ·) := rfl protected theorem Bijective.injective {f : α → β} (hf : Bijective f) : Injective f := hf.1 protected theorem Bijective.surjective {f : α → β} (hf : Bijective f) : Surjective f := hf.2 theorem not_injective_iff : ¬ Injective f ↔ ∃ a b, f a = f b ∧ a ≠ b := by simp only [Injective, not_forall, exists_prop] /-- If the co-domain `β` of an injective function `f : α → β` has decidable equality, then the domain `α` also has decidable equality. -/ protected def Injective.decidableEq [DecidableEq β] (I : Injective f) : DecidableEq α := fun _ _ ↦ decidable_of_iff _ I.eq_iff theorem Injective.of_comp {g : γ → α} (I : Injective (f ∘ g)) : Injective g := fun _ _ h ↦ I <| congr_arg f h @[simp] theorem Injective.of_comp_iff (hf : Injective f) (g : γ → α) : Injective (f ∘ g) ↔ Injective g := ⟨Injective.of_comp, hf.comp⟩ theorem Injective.of_comp_right {g : γ → α} (I : Injective (f ∘ g)) (hg : Surjective g) : Injective f := fun x y h ↦ by obtain ⟨x, rfl⟩ := hg x obtain ⟨y, rfl⟩ := hg y exact congr_arg g (I h) theorem Surjective.bijective₂_of_injective {g : γ → α} (hf : Surjective f) (hg : Surjective g) (I : Injective (f ∘ g)) : Bijective f ∧ Bijective g := ⟨⟨I.of_comp_right hg, hf⟩, I.of_comp, hg⟩ @[simp] theorem Injective.of_comp_iff' (f : α → β) {g : γ → α} (hg : Bijective g) : Injective (f ∘ g) ↔ Injective f := ⟨fun I ↦ I.of_comp_right hg.2, fun h ↦ h.comp hg.injective⟩ theorem Injective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i} (hf : ∀ i, Injective (f i)) : Injective (Pi.map f) := fun _ _ h ↦ funext fun i ↦ hf i <| congrFun h _ /-- Composition by an injective function on the left is itself injective. -/ theorem Injective.comp_left {g : β → γ} (hg : Injective g) : Injective (g ∘ · : (α → β) → α → γ) := .piMap fun _ ↦ hg theorem injective_comp_left_iff [Nonempty α] {g : β → γ} : Injective (g ∘ · : (α → β) → α → γ) ↔ Injective g := ⟨fun h b₁ b₂ eq ↦ Nonempty.elim ‹_› (congr_fun <| h (a₁ := fun _ ↦ b₁) (a₂ := fun _ ↦ b₂) <| funext fun _ ↦ eq), (·.comp_left)⟩ @[nontriviality] theorem injective_of_subsingleton [Subsingleton α] (f : α → β) : Injective f := fun _ _ _ ↦ Subsingleton.elim _ _ @[nontriviality] theorem bijective_of_subsingleton [Subsingleton α] (f : α → α) : Bijective f := ⟨injective_of_subsingleton f, fun a ↦ ⟨a, Subsingleton.elim ..⟩⟩ lemma Injective.dite (p : α → Prop) [DecidablePred p] {f : {a : α // p a} → β} {f' : {a : α // ¬ p a} → β} (hf : Injective f) (hf' : Injective f') (im_disj : ∀ {x x' : α} {hx : p x} {hx' : ¬ p x'}, f ⟨x, hx⟩ ≠ f' ⟨x', hx'⟩) : Function.Injective (fun x ↦ if h : p x then f ⟨x, h⟩ else f' ⟨x, h⟩) := fun x₁ x₂ h => by dsimp only at h by_cases h₁ : p x₁ <;> by_cases h₂ : p x₂ · rw [dif_pos h₁, dif_pos h₂] at h; injection (hf h) · rw [dif_pos h₁, dif_neg h₂] at h; exact (im_disj h).elim · rw [dif_neg h₁, dif_pos h₂] at h; exact (im_disj h.symm).elim · rw [dif_neg h₁, dif_neg h₂] at h; injection (hf' h) theorem Surjective.of_comp {g : γ → α} (S : Surjective (f ∘ g)) : Surjective f := fun y ↦ let ⟨x, h⟩ := S y ⟨g x, h⟩ @[simp] theorem Surjective.of_comp_iff (f : α → β) {g : γ → α} (hg : Surjective g) : Surjective (f ∘ g) ↔ Surjective f := ⟨Surjective.of_comp, fun h ↦ h.comp hg⟩ theorem Surjective.of_comp_left {g : γ → α} (S : Surjective (f ∘ g)) (hf : Injective f) : Surjective g := fun a ↦ let ⟨c, hc⟩ := S (f a); ⟨c, hf hc⟩ theorem Injective.bijective₂_of_surjective {g : γ → α} (hf : Injective f) (hg : Injective g) (S : Surjective (f ∘ g)) : Bijective f ∧ Bijective g := ⟨⟨hf, S.of_comp⟩, hg, S.of_comp_left hf⟩ @[simp] theorem Surjective.of_comp_iff' (hf : Bijective f) (g : γ → α) : Surjective (f ∘ g) ↔ Surjective g := ⟨fun S ↦ S.of_comp_left hf.1, hf.surjective.comp⟩ instance decidableEqPFun (p : Prop) [Decidable p] (α : p → Type*) [∀ hp, DecidableEq (α hp)] : DecidableEq (∀ hp, α hp) | f, g => decidable_of_iff (∀ hp, f hp = g hp) funext_iff.symm protected theorem Surjective.forall (hf : Surjective f) {p : β → Prop} : (∀ y, p y) ↔ ∀ x, p (f x) := ⟨fun h x ↦ h (f x), fun h y ↦ let ⟨x, hx⟩ := hf y hx ▸ h x⟩ protected theorem Surjective.forall₂ (hf : Surjective f) {p : β → β → Prop} : (∀ y₁ y₂, p y₁ y₂) ↔ ∀ x₁ x₂, p (f x₁) (f x₂) := hf.forall.trans <| forall_congr' fun _ ↦ hf.forall protected theorem Surjective.forall₃ (hf : Surjective f) {p : β → β → β → Prop} : (∀ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∀ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) := hf.forall.trans <| forall_congr' fun _ ↦ hf.forall₂ protected theorem Surjective.exists (hf : Surjective f) {p : β → Prop} : (∃ y, p y) ↔ ∃ x, p (f x) := ⟨fun ⟨y, hy⟩ ↦ let ⟨x, hx⟩ := hf y ⟨x, hx.symm ▸ hy⟩, fun ⟨x, hx⟩ ↦ ⟨f x, hx⟩⟩ protected theorem Surjective.exists₂ (hf : Surjective f) {p : β → β → Prop} : (∃ y₁ y₂, p y₁ y₂) ↔ ∃ x₁ x₂, p (f x₁) (f x₂) := hf.exists.trans <| exists_congr fun _ ↦ hf.exists protected theorem Surjective.exists₃ (hf : Surjective f) {p : β → β → β → Prop} : (∃ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∃ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) := hf.exists.trans <| exists_congr fun _ ↦ hf.exists₂ theorem Surjective.injective_comp_right (hf : Surjective f) : Injective fun g : β → γ ↦ g ∘ f := fun _ _ h ↦ funext <| hf.forall.2 <| congr_fun h theorem injective_comp_right_iff_surjective {γ : Type*} [Nontrivial γ] : Injective (fun g : β → γ ↦ g ∘ f) ↔ Surjective f := by refine ⟨not_imp_not.mp fun not_surj inj ↦ not_subsingleton γ ⟨fun c c' ↦ ?_⟩, (·.injective_comp_right)⟩ have ⟨b₀, hb⟩ := not_forall.mp not_surj classical have := inj (a₁ := fun _ ↦ c) (a₂ := (if · = b₀ then c' else c)) ?_ · simpa using congr_fun this b₀ ext a; simp only [comp_apply, if_neg fun h ↦ hb ⟨a, h⟩] protected theorem Surjective.right_cancellable (hf : Surjective f) {g₁ g₂ : β → γ} : g₁ ∘ f = g₂ ∘ f ↔ g₁ = g₂ := hf.injective_comp_right.eq_iff theorem surjective_of_right_cancellable_Prop (h : ∀ g₁ g₂ : β → Prop, g₁ ∘ f = g₂ ∘ f → g₁ = g₂) : Surjective f := injective_comp_right_iff_surjective.mp h theorem bijective_iff_existsUnique (f : α → β) : Bijective f ↔ ∀ b : β, ∃! a : α, f a = b := ⟨fun hf b ↦ let ⟨a, ha⟩ := hf.surjective b ⟨a, ha, fun _ ha' ↦ hf.injective (ha'.trans ha.symm)⟩, fun he ↦ ⟨fun {_a a'} h ↦ (he (f a')).unique h rfl, fun b ↦ (he b).exists⟩⟩ /-- Shorthand for using projection notation with `Function.bijective_iff_existsUnique`. -/ protected theorem Bijective.existsUnique {f : α → β} (hf : Bijective f) (b : β) : ∃! a : α, f a = b := (bijective_iff_existsUnique f).mp hf b theorem Bijective.existsUnique_iff {f : α → β} (hf : Bijective f) {p : β → Prop} : (∃! y, p y) ↔ ∃! x, p (f x) := ⟨fun ⟨y, hpy, hy⟩ ↦ let ⟨x, hx⟩ := hf.surjective y ⟨x, by simpa [hx], fun z (hz : p (f z)) ↦ hf.injective <| hx.symm ▸ hy _ hz⟩, fun ⟨x, hpx, hx⟩ ↦ ⟨f x, hpx, fun y hy ↦ let ⟨z, hz⟩ := hf.surjective y hz ▸ congr_arg f (hx _ (by simpa [hz]))⟩⟩ theorem Bijective.of_comp_iff (f : α → β) {g : γ → α} (hg : Bijective g) : Bijective (f ∘ g) ↔ Bijective f := and_congr (Injective.of_comp_iff' _ hg) (Surjective.of_comp_iff _ hg.surjective) theorem Bijective.of_comp_iff' {f : α → β} (hf : Bijective f) (g : γ → α) : Function.Bijective (f ∘ g) ↔ Function.Bijective g := and_congr (Injective.of_comp_iff hf.injective _) (Surjective.of_comp_iff' hf _) /-- **Cantor's diagonal argument** implies that there are no surjective functions from `α` to `Set α`. -/ theorem cantor_surjective {α} (f : α → Set α) : ¬Surjective f | h => let ⟨D, e⟩ := h {a | ¬ f a a} @iff_not_self (D ∈ f D) <| iff_of_eq <| congr_arg (D ∈ ·) e /-- **Cantor's diagonal argument** implies that there are no injective functions from `Set α` to `α`. -/ theorem cantor_injective {α : Type*} (f : Set α → α) : ¬Injective f | i => cantor_surjective (fun a ↦ {b | ∀ U, a = f U → U b}) <| RightInverse.surjective (fun U ↦ Set.ext fun _ ↦ ⟨fun h ↦ h U rfl, fun h _ e ↦ i e ▸ h⟩) /-- There is no surjection from `α : Type u` into `Type (max u v)`. This theorem demonstrates why `Type : Type` would be inconsistent in Lean. -/ theorem not_surjective_Type {α : Type u} (f : α → Type max u v) : ¬Surjective f := by intro hf let T : Type max u v := Sigma f cases hf (Set T) with | intro U hU => let g : Set T → T := fun s ↦ ⟨U, cast hU.symm s⟩ have hg : Injective g := by intro s t h suffices cast hU (g s).2 = cast hU (g t).2 by simp only [g, cast_cast, cast_eq] at this assumption · congr exact cantor_injective g hg /-- `g` is a partial inverse to `f` (an injective but not necessarily surjective function) if `g y = some x` implies `f x = y`, and `g y = none` implies that `y` is not in the range of `f`. -/ def IsPartialInv {α β} (f : α → β) (g : β → Option α) : Prop := ∀ x y, g y = some x ↔ f x = y theorem isPartialInv_left {α β} {f : α → β} {g} (H : IsPartialInv f g) (x) : g (f x) = some x := (H _ _).2 rfl theorem injective_of_isPartialInv {α β} {f : α → β} {g} (H : IsPartialInv f g) : Injective f := fun _ _ h ↦ Option.some.inj <| ((H _ _).2 h).symm.trans ((H _ _).2 rfl) theorem injective_of_isPartialInv_right {α β} {f : α → β} {g} (H : IsPartialInv f g) (x y b) (h₁ : b ∈ g x) (h₂ : b ∈ g y) : x = y := ((H _ _).1 h₁).symm.trans ((H _ _).1 h₂) theorem LeftInverse.comp_eq_id {f : α → β} {g : β → α} (h : LeftInverse f g) : f ∘ g = id := funext h theorem leftInverse_iff_comp {f : α → β} {g : β → α} : LeftInverse f g ↔ f ∘ g = id := ⟨LeftInverse.comp_eq_id, congr_fun⟩ theorem RightInverse.comp_eq_id {f : α → β} {g : β → α} (h : RightInverse f g) : g ∘ f = id := funext h theorem rightInverse_iff_comp {f : α → β} {g : β → α} : RightInverse f g ↔ g ∘ f = id := ⟨RightInverse.comp_eq_id, congr_fun⟩ theorem LeftInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : LeftInverse f g) (hh : LeftInverse h i) : LeftInverse (h ∘ f) (g ∘ i) := fun a ↦ show h (f (g (i a))) = a by rw [hf (i a), hh a] theorem RightInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : RightInverse f g) (hh : RightInverse h i) : RightInverse (h ∘ f) (g ∘ i) := LeftInverse.comp hh hf theorem LeftInverse.rightInverse {f : α → β} {g : β → α} (h : LeftInverse g f) : RightInverse f g := h theorem RightInverse.leftInverse {f : α → β} {g : β → α} (h : RightInverse g f) : LeftInverse f g := h theorem LeftInverse.surjective {f : α → β} {g : β → α} (h : LeftInverse f g) : Surjective f := h.rightInverse.surjective theorem RightInverse.injective {f : α → β} {g : β → α} (h : RightInverse f g) : Injective f := h.leftInverse.injective theorem LeftInverse.rightInverse_of_injective {f : α → β} {g : β → α} (h : LeftInverse f g) (hf : Injective f) : RightInverse f g := fun x ↦ hf <| h (f x) theorem LeftInverse.rightInverse_of_surjective {f : α → β} {g : β → α} (h : LeftInverse f g) (hg : Surjective g) : RightInverse f g := fun x ↦ let ⟨y, hy⟩ := hg x; hy ▸ congr_arg g (h y) theorem RightInverse.leftInverse_of_surjective {f : α → β} {g : β → α} : RightInverse f g → Surjective f → LeftInverse f g := LeftInverse.rightInverse_of_surjective theorem RightInverse.leftInverse_of_injective {f : α → β} {g : β → α} : RightInverse f g → Injective g → LeftInverse f g := LeftInverse.rightInverse_of_injective theorem LeftInverse.eq_rightInverse {f : α → β} {g₁ g₂ : β → α} (h₁ : LeftInverse g₁ f) (h₂ : RightInverse g₂ f) : g₁ = g₂ := calc g₁ = g₁ ∘ f ∘ g₂ := by rw [h₂.comp_eq_id, comp_id] _ = g₂ := by rw [← comp_assoc, h₁.comp_eq_id, id_comp] /-- We can use choice to construct explicitly a partial inverse for a given injective function `f`. -/ noncomputable def partialInv {α β} (f : α → β) (b : β) : Option α := open scoped Classical in if h : ∃ a, f a = b then some (Classical.choose h) else none theorem partialInv_of_injective {α β} {f : α → β} (I : Injective f) : IsPartialInv f (partialInv f) | a, b => ⟨fun h => open scoped Classical in have hpi : partialInv f b = if h : ∃ a, f a = b then some (Classical.choose h) else none := rfl if h' : ∃ a, f a = b then by rw [hpi, dif_pos h'] at h injection h with h subst h apply Classical.choose_spec h' else by rw [hpi, dif_neg h'] at h; contradiction, fun e => e ▸ have h : ∃ a', f a' = f a := ⟨_, rfl⟩ (dif_pos h).trans (congr_arg _ (I <| Classical.choose_spec h))⟩ theorem partialInv_left {α β} {f : α → β} (I : Injective f) : ∀ x, partialInv f (f x) = some x := isPartialInv_left (partialInv_of_injective I) end section InvFun variable {α β : Sort*} [Nonempty α] {f : α → β} {b : β} /-- The inverse of a function (which is a left inverse if `f` is injective and a right inverse if `f` is surjective). -/ -- Explicit Sort so that `α` isn't inferred to be Prop via `exists_prop_decidable` noncomputable def invFun {α : Sort u} {β} [Nonempty α] (f : α → β) : β → α := open scoped Classical in fun y ↦ if h : (∃ x, f x = y) then h.choose else Classical.arbitrary α theorem invFun_eq (h : ∃ a, f a = b) : f (invFun f b) = b := by simp only [invFun, dif_pos h, h.choose_spec] theorem apply_invFun_apply {α β : Type*} {f : α → β} {a : α} : f (@invFun _ _ ⟨a⟩ f (f a)) = f a := @invFun_eq _ _ ⟨a⟩ _ _ ⟨_, rfl⟩ theorem invFun_neg (h : ¬∃ a, f a = b) : invFun f b = Classical.choice ‹_› := dif_neg h theorem invFun_eq_of_injective_of_rightInverse {g : β → α} (hf : Injective f) (hg : RightInverse g f) : invFun f = g := funext fun b ↦ hf (by rw [hg b] exact invFun_eq ⟨g b, hg b⟩) theorem rightInverse_invFun (hf : Surjective f) : RightInverse (invFun f) f := fun b ↦ invFun_eq <| hf b theorem leftInverse_invFun (hf : Injective f) : LeftInverse (invFun f) f := fun b ↦ hf <| invFun_eq ⟨b, rfl⟩ theorem invFun_surjective (hf : Injective f) : Surjective (invFun f) := (leftInverse_invFun hf).surjective theorem invFun_comp (hf : Injective f) : invFun f ∘ f = id := funext <| leftInverse_invFun hf theorem Injective.hasLeftInverse (hf : Injective f) : HasLeftInverse f := ⟨invFun f, leftInverse_invFun hf⟩ theorem injective_iff_hasLeftInverse : Injective f ↔ HasLeftInverse f := ⟨Injective.hasLeftInverse, HasLeftInverse.injective⟩ end InvFun section SurjInv variable {α : Sort u} {β : Sort v} {γ : Sort w} {f : α → β} /-- The inverse of a surjective function. (Unlike `invFun`, this does not require `α` to be inhabited.) -/ noncomputable def surjInv {f : α → β} (h : Surjective f) (b : β) : α := Classical.choose (h b) theorem surjInv_eq (h : Surjective f) (b) : f (surjInv h b) = b := Classical.choose_spec (h b) theorem rightInverse_surjInv (hf : Surjective f) : RightInverse (surjInv hf) f := surjInv_eq hf theorem leftInverse_surjInv (hf : Bijective f) : LeftInverse (surjInv hf.2) f := rightInverse_of_injective_of_leftInverse hf.1 (rightInverse_surjInv hf.2) theorem Surjective.hasRightInverse (hf : Surjective f) : HasRightInverse f := ⟨_, rightInverse_surjInv hf⟩ theorem surjective_iff_hasRightInverse : Surjective f ↔ HasRightInverse f := ⟨Surjective.hasRightInverse, HasRightInverse.surjective⟩ theorem bijective_iff_has_inverse : Bijective f ↔ ∃ g, LeftInverse g f ∧ RightInverse g f := ⟨fun hf ↦ ⟨_, leftInverse_surjInv hf, rightInverse_surjInv hf.2⟩, fun ⟨_, gl, gr⟩ ↦ ⟨gl.injective, gr.surjective⟩⟩ theorem injective_surjInv (h : Surjective f) : Injective (surjInv h) := (rightInverse_surjInv h).injective theorem surjective_to_subsingleton [na : Nonempty α] [Subsingleton β] (f : α → β) : Surjective f := fun _ ↦ let ⟨a⟩ := na; ⟨a, Subsingleton.elim _ _⟩ theorem Surjective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i} (hf : ∀ i, Surjective (f i)) : Surjective (Pi.map f) := fun g ↦ ⟨fun i ↦ surjInv (hf i) (g i), funext fun _ ↦ rightInverse_surjInv _ _⟩ /-- Composition by a surjective function on the left is itself surjective. -/ theorem Surjective.comp_left {g : β → γ} (hg : Surjective g) : Surjective (g ∘ · : (α → β) → α → γ) := .piMap fun _ ↦ hg theorem surjective_comp_left_iff [Nonempty α] {g : β → γ} : Surjective (g ∘ · : (α → β) → α → γ) ↔ Surjective g := by refine ⟨fun h c ↦ Nonempty.elim ‹_› fun a ↦ ?_, (·.comp_left)⟩ have ⟨f, hf⟩ := h fun _ ↦ c exact ⟨f a, congr_fun hf _⟩ theorem Bijective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i} (hf : ∀ i, Bijective (f i)) : Bijective (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2⟩ /-- Composition by a bijective function on the left is itself bijective. -/ theorem Bijective.comp_left {g : β → γ} (hg : Bijective g) : Bijective (g ∘ · : (α → β) → α → γ) := ⟨hg.injective.comp_left, hg.surjective.comp_left⟩ end SurjInv section Update variable {α : Sort u} {β : α → Sort v} {α' : Sort w} [DecidableEq α] {f : (a : α) → β a} {a : α} {b : β a} /-- Replacing the value of a function at a given point by a given value. -/ def update (f : ∀ a, β a) (a' : α) (v : β a') (a : α) : β a := if h : a = a' then Eq.ndrec v h.symm else f a @[simp] theorem update_self (a : α) (v : β a) (f : ∀ a, β a) : update f a v a = v := dif_pos rfl @[simp] theorem update_of_ne {a a' : α} (h : a ≠ a') (v : β a') (f : ∀ a, β a) : update f a' v a = f a := dif_neg h /-- On non-dependent functions, `Function.update` can be expressed as an `ite` -/ theorem update_apply {β : Sort*} (f : α → β) (a' : α) (b : β) (a : α) : update f a' b a = if a = a' then b else f a := by rcases Decidable.eq_or_ne a a' with rfl | hne <;> simp [*] @[nontriviality] theorem update_eq_const_of_subsingleton [Subsingleton α] (a : α) (v : α') (f : α → α') : update f a v = const α v := funext fun a' ↦ Subsingleton.elim a a' ▸ update_self .. theorem surjective_eval {α : Sort u} {β : α → Sort v} [h : ∀ a, Nonempty (β a)] (a : α) : Surjective (eval a : (∀ a, β a) → β a) := fun b ↦ ⟨@update _ _ (Classical.decEq α) (fun a ↦ (h a).some) a b, @update_self _ _ (Classical.decEq α) _ _ _⟩ theorem update_injective (f : ∀ a, β a) (a' : α) : Injective (update f a') := fun v v' h ↦ by have := congr_fun h a' rwa [update_self, update_self] at this lemma forall_update_iff (f : ∀ a, β a) {a : α} {b : β a} (p : ∀ a, β a → Prop) : (∀ x, p x (update f a b x)) ↔ p a b ∧ ∀ x, x ≠ a → p x (f x) := by rw [← and_forall_ne a, update_self] simp +contextual theorem exists_update_iff (f : ∀ a, β a) {a : α} {b : β a} (p : ∀ a, β a → Prop) : (∃ x, p x (update f a b x)) ↔ p a b ∨ ∃ x ≠ a, p x (f x) := by rw [← not_forall_not, forall_update_iff f fun a b ↦ ¬p a b] simp [-not_and, not_and_or] theorem update_eq_iff {a : α} {b : β a} {f g : ∀ a, β a} : update f a b = g ↔ b = g a ∧ ∀ x ≠ a, f x = g x := funext_iff.trans <| forall_update_iff _ fun x y ↦ y = g x theorem eq_update_iff {a : α} {b : β a} {f g : ∀ a, β a} : g = update f a b ↔ g a = b ∧ ∀ x ≠ a, g x = f x := funext_iff.trans <| forall_update_iff _ fun x y ↦ g x = y @[simp] lemma update_eq_self_iff : update f a b = f ↔ b = f a := by simp [update_eq_iff] @[simp] lemma eq_update_self_iff : f = update f a b ↔ f a = b := by simp [eq_update_iff] lemma ne_update_self_iff : f ≠ update f a b ↔ f a ≠ b := eq_update_self_iff.not lemma update_ne_self_iff : update f a b ≠ f ↔ b ≠ f a := update_eq_self_iff.not @[simp] theorem update_eq_self (a : α) (f : ∀ a, β a) : update f a (f a) = f := update_eq_iff.2 ⟨rfl, fun _ _ ↦ rfl⟩ theorem update_comp_eq_of_forall_ne' {α'} (g : ∀ a, β a) {f : α' → α} {i : α} (a : β i) (h : ∀ x, f x ≠ i) : (fun j ↦ (update g i a) (f j)) = fun j ↦ g (f j) := funext fun _ ↦ update_of_ne (h _) _ _ variable [DecidableEq α'] /-- Non-dependent version of `Function.update_comp_eq_of_forall_ne'` -/ theorem update_comp_eq_of_forall_ne {α β : Sort*} (g : α' → β) {f : α → α'} {i : α'} (a : β) (h : ∀ x, f x ≠ i) : update g i a ∘ f = g ∘ f := update_comp_eq_of_forall_ne' g a h theorem update_comp_eq_of_injective' (g : ∀ a, β a) {f : α' → α} (hf : Function.Injective f) (i : α') (a : β (f i)) : (fun j ↦ update g (f i) a (f j)) = update (fun i ↦ g (f i)) i a := eq_update_iff.2 ⟨update_self .., fun _ hj ↦ update_of_ne (hf.ne hj) _ _⟩ theorem update_apply_of_injective (g : ∀ a, β a) {f : α' → α} (hf : Function.Injective f) (i : α') (a : β (f i)) (j : α') : update g (f i) a (f j) = update (fun i ↦ g (f i)) i a j := congr_fun (update_comp_eq_of_injective' g hf i a) j /-- Non-dependent version of `Function.update_comp_eq_of_injective'` -/ theorem update_comp_eq_of_injective {β : Sort*} (g : α' → β) {f : α → α'} (hf : Function.Injective f) (i : α) (a : β) : Function.update g (f i) a ∘ f = Function.update (g ∘ f) i a := update_comp_eq_of_injective' g hf i a /-- Recursors can be pushed inside `Function.update`. The `ctor` argument should be a one-argument constructor like `Sum.inl`, and `recursor` should be an inductive recursor partially applied in all but that constructor, such as `(Sum.rec · g)`. In future, we should build some automation to generate applications like `Option.rec_update` for all inductive types. -/ lemma rec_update {ι κ : Sort*} {α : κ → Sort*} [DecidableEq ι] [DecidableEq κ] {ctor : ι → κ} (hctor : Function.Injective ctor) (recursor : ((i : ι) → α (ctor i)) → ((i : κ) → α i)) (h : ∀ f i, recursor f (ctor i) = f i) (h2 : ∀ f₁ f₂ k, (∀ i, ctor i ≠ k) → recursor f₁ k = recursor f₂ k) (f : (i : ι) → α (ctor i)) (i : ι) (x : α (ctor i)) : recursor (update f i x) = update (recursor f) (ctor i) x := by ext k by_cases h : ∃ i, ctor i = k · obtain ⟨i', rfl⟩ := h obtain rfl | hi := eq_or_ne i' i · simp [h] · have hk := hctor.ne hi simp [h, hi, hk, Function.update_of_ne] · rw [not_exists] at h rw [h2 _ f _ h] rw [Function.update_of_ne (Ne.symm <| h i)] @[simp] lemma _root_.Option.rec_update {α : Type*} {β : Option α → Sort*} [DecidableEq α] (f : β none) (g : ∀ a, β (.some a)) (a : α) (x : β (.some a)) : Option.rec f (update g a x) = update (Option.rec f g) (.some a) x := Function.rec_update (@Option.some.inj _) (Option.rec f) (fun _ _ => rfl) (fun | _, _, .some _, h => (h _ rfl).elim | _, _, .none, _ => rfl) _ _ _ theorem apply_update {ι : Sort*} [DecidableEq ι] {α β : ι → Sort*} (f : ∀ i, α i → β i) (g : ∀ i, α i) (i : ι) (v : α i) (j : ι) : f j (update g i v j) = update (fun k ↦ f k (g k)) i (f i v) j := by by_cases h : j = i · subst j simp · simp [h] theorem apply_update₂ {ι : Sort*} [DecidableEq ι] {α β γ : ι → Sort*} (f : ∀ i, α i → β i → γ i) (g : ∀ i, α i) (h : ∀ i, β i) (i : ι) (v : α i) (w : β i) (j : ι) : f j (update g i v j) (update h i w j) = update (fun k ↦ f k (g k) (h k)) i (f i v w) j := by by_cases h : j = i · subst j simp · simp [h] theorem pred_update (P : ∀ ⦃a⦄, β a → Prop) (f : ∀ a, β a) (a' : α) (v : β a') (a : α) : P (update f a' v a) ↔ a = a' ∧ P v ∨ a ≠ a' ∧ P (f a) := by rw [apply_update P, update_apply, ite_prop_iff_or] theorem comp_update {α' : Sort*} {β : Sort*} (f : α' → β) (g : α → α') (i : α) (v : α') : f ∘ update g i v = update (f ∘ g) i (f v) := funext <| apply_update _ _ _ _ theorem update_comm {α} [DecidableEq α] {β : α → Sort*} {a b : α} (h : a ≠ b) (v : β a) (w : β b) (f : ∀ a, β a) : update (update f a v) b w = update (update f b w) a v := by funext c simp only [update] by_cases h₁ : c = b <;> by_cases h₂ : c = a · rw [dif_pos h₁, dif_pos h₂] cases h (h₂.symm.trans h₁) · rw [dif_pos h₁, dif_pos h₁, dif_neg h₂] · rw [dif_neg h₁, dif_neg h₁] · rw [dif_neg h₁, dif_neg h₁] @[simp] theorem update_idem {α} [DecidableEq α] {β : α → Sort*} {a : α} (v w : β a) (f : ∀ a, β a) : update (update f a v) a w = update f a w := by funext b by_cases h : b = a <;> simp [update, h] @[simp] theorem _root_.Pi.map_update {ι : Sort*} [DecidableEq ι] {α β : ι → Sort*} {f : ∀ i, α i → β i} (g : ∀ i, α i) (i : ι) (a : α i) : Pi.map f (Function.update g i a) = Function.update (Pi.map f g) i (f i a) := by ext j obtain rfl | hij := eq_or_ne j i <;> simp [*] @[simp] theorem _root_.Pi.map_injective {ι : Sort*} {α β : ι → Sort*} [∀ i, Nonempty (α i)] {f : ∀ i, α i → β i} : Injective (Pi.map f) ↔ ∀ i, Injective (f i) where mp h i x y hxy := by classical have : Inhabited (∀ i, α i) := ⟨fun _ => Classical.choice inferInstance⟩ replace h := @h (Function.update default i x) (Function.update default i y) ?_ · simpa using congrFun h i rw [Pi.map_update, Pi.map_update, hxy] mpr := .piMap end Update noncomputable section Extend variable {α β γ : Sort*} {f : α → β} /-- Extension of a function `g : α → γ` along a function `f : α → β`. For every `a : α`, `f a` is sent to `g a`. `f` might not be surjective, so we use an auxiliary function `j : β → γ` by sending `b : β` not in the range of `f` to `j b`. If you do not care about the behavior outside the range, `j` can be used as a junk value by setting it to be `0` or `Classical.arbitrary` (assuming `γ` is nonempty). This definition is mathematically meaningful only when `f a₁ = f a₂ → g a₁ = g a₂` (spelled `g.FactorsThrough f`). In particular this holds if `f` is injective. A typical use case is extending a function from a subtype to the entire type. If you wish to extend `g : {b : β // p b} → γ` to a function `β → γ`, you should use `Function.extend Subtype.val g j`. -/ def extend (f : α → β) (g : α → γ) (j : β → γ) : β → γ := fun b ↦ open scoped Classical in if h : ∃ a, f a = b then g (Classical.choose h) else j b /-- g factors through f : `f a = f b → g a = g b` -/ def FactorsThrough (g : α → γ) (f : α → β) : Prop := ∀ ⦃a b⦄, f a = f b → g a = g b theorem extend_def (f : α → β) (g : α → γ) (e' : β → γ) (b : β) [Decidable (∃ a, f a = b)] : extend f g e' b = if h : ∃ a, f a = b then g (Classical.choose h) else e' b := by unfold extend congr lemma Injective.factorsThrough (hf : Injective f) (g : α → γ) : g.FactorsThrough f := fun _ _ h => congr_arg g (hf h) lemma FactorsThrough.extend_apply {g : α → γ} (hf : g.FactorsThrough f) (e' : β → γ) (a : α) : extend f g e' (f a) = g a := by classical simp only [extend_def, dif_pos, exists_apply_eq_apply] exact hf (Classical.choose_spec (exists_apply_eq_apply f a)) @[simp] theorem Injective.extend_apply (hf : Injective f) (g : α → γ) (e' : β → γ) (a : α) : extend f g e' (f a) = g a := (hf.factorsThrough g).extend_apply e' a @[simp] theorem extend_apply' (g : α → γ) (e' : β → γ) (b : β) (hb : ¬∃ a, f a = b) : extend f g e' b = e' b := by classical simp [Function.extend_def, hb] @[simp] theorem extend_id (g : α → γ) (e' : α → γ) : extend id g e' = g := funext <| injective_id.extend_apply g _ theorem Injective.extend_comp {α₁ α₂ α₃ : Sort*} {f₁₂ : α₁ → α₂} (h₁₂ : Function.Injective f₁₂) {f₂₃ : α₂ → α₃} (h₂₃ : Function.Injective f₂₃) (g : α₁ → γ) (e' : α₃ → γ) : extend (f₂₃ ∘ f₁₂) g e' = extend f₂₃ (extend f₁₂ g (e' ∘ f₂₃)) e' := by ext a by_cases h₃ : ∃ b, f₂₃ b = a · obtain ⟨b, rfl⟩ := h₃ rw [Injective.extend_apply h₂₃] by_cases h₂ : ∃ c, f₁₂ c = b · obtain ⟨c, rfl⟩ := h₂ rw [h₁₂.extend_apply] exact (h₂₃.comp h₁₂).extend_apply _ _ _ · rw [extend_apply' _ _ _ h₂, extend_apply', comp_apply] exact fun h ↦ h₂ (Exists.casesOn h fun c hc ↦ Exists.intro c (h₂₃ hc)) · rw [extend_apply' _ _ _ h₃, extend_apply'] exact fun h ↦ h₃ (Exists.casesOn h fun c hc ↦ Exists.intro (f₁₂ c) (hc)) lemma factorsThrough_iff (g : α → γ) [Nonempty γ] : g.FactorsThrough f ↔ ∃ (e : β → γ), g = e ∘ f := ⟨fun hf => ⟨extend f g (const β (Classical.arbitrary γ)), funext (fun x => by simp only [comp_apply, hf.extend_apply])⟩, fun h _ _ hf => by rw [Classical.choose_spec h, comp_apply, comp_apply, hf]⟩ lemma apply_extend {δ} {g : α → γ} (F : γ → δ) (f : α → β) (e' : β → γ) (b : β) : F (extend f g e' b) = extend f (F ∘ g) (F ∘ e') b := open scoped Classical in apply_dite F _ _ _ theorem extend_injective (hf : Injective f) (e' : β → γ) : Injective fun g ↦ extend f g e' := by intro g₁ g₂ hg refine funext fun x ↦ ?_ have H := congr_fun hg (f x) simp only [hf.extend_apply] at H exact H lemma FactorsThrough.extend_comp {g : α → γ} (e' : β → γ) (hf : FactorsThrough g f) : extend f g e' ∘ f = g := funext fun a => hf.extend_apply e' a @[simp] lemma extend_const (f : α → β) (c : γ) : extend f (fun _ ↦ c) (fun _ ↦ c) = fun _ ↦ c := funext fun _ ↦ open scoped Classical in ite_id _ @[simp] theorem extend_comp (hf : Injective f) (g : α → γ) (e' : β → γ) : extend f g e' ∘ f = g := funext fun a ↦ hf.extend_apply g e' a theorem Injective.surjective_comp_right' (hf : Injective f) (g₀ : β → γ) : Surjective fun g : β → γ ↦ g ∘ f := fun g ↦ ⟨extend f g g₀, Function.extend_comp hf _ _⟩ theorem Injective.surjective_comp_right [Nonempty γ] (hf : Injective f) : Surjective fun g : β → γ ↦ g ∘ f := hf.surjective_comp_right' fun _ ↦ Classical.choice ‹_› theorem surjective_comp_right_iff_injective {γ : Type*} [Nontrivial γ] : Surjective (fun g : β → γ ↦ g ∘ f) ↔ Injective f := by classical refine ⟨not_imp_not.mp fun not_inj surj ↦ not_subsingleton γ ⟨fun c c' ↦ ?_⟩, (·.surjective_comp_right)⟩ simp only [Injective, not_forall] at not_inj have ⟨a₁, a₂, eq, ne⟩ := not_inj have ⟨f, hf⟩ := surj (if · = a₂ then c else c') have h₁ := congr_fun hf a₁ have h₂ := congr_fun hf a₂ simp only [comp_apply, if_neg ne, reduceIte] at h₁ h₂ rw [← h₁, eq, h₂] theorem Bijective.comp_right (hf : Bijective f) : Bijective fun g : β → γ ↦ g ∘ f := ⟨hf.surjective.injective_comp_right, fun g ↦ ⟨g ∘ surjInv hf.surjective, by simp only [comp_assoc g _ f, (leftInverse_surjInv hf).comp_eq_id, comp_id]⟩⟩ end Extend namespace FactorsThrough protected theorem rfl {α β : Sort*} {f : α → β} : FactorsThrough f f := fun _ _ ↦ id theorem comp_left {α β γ δ : Sort*} {f : α → β} {g : α → γ} (h : FactorsThrough g f) (g' : γ → δ) : FactorsThrough (g' ∘ g) f := fun _x _y hxy ↦ congr_arg g' (h hxy) theorem comp_right {α β γ δ : Sort*} {f : α → β} {g : α → γ} (h : FactorsThrough g f) (g' : δ → α) : FactorsThrough (g ∘ g') (f ∘ g') := fun _x _y hxy ↦ h hxy end FactorsThrough theorem uncurry_def {α β γ} (f : α → β → γ) : uncurry f = fun p ↦ f p.1 p.2 := rfl section Bicomp variable {α β γ δ ε : Type*} /-- Compose a binary function `f` with a pair of unary functions `g` and `h`. If both arguments of `f` have the same type and `g = h`, then `bicompl f g g = f on g`. -/ def bicompl (f : γ → δ → ε) (g : α → γ) (h : β → δ) (a b) := f (g a) (h b) /-- Compose a unary function `f` with a binary function `g`. -/ def bicompr (f : γ → δ) (g : α → β → γ) (a b) := f (g a b) -- Suggested local notation: local notation f " ∘₂ " g => bicompr f g theorem uncurry_bicompr (f : α → β → γ) (g : γ → δ) : uncurry (g ∘₂ f) = g ∘ uncurry f := rfl theorem uncurry_bicompl (f : γ → δ → ε) (g : α → γ) (h : β → δ) : uncurry (bicompl f g h) = uncurry f ∘ Prod.map g h := rfl end Bicomp section Uncurry variable {α β γ δ : Type*} /-- Records a way to turn an element of `α` into a function from `β` to `γ`. The most generic use is to recursively uncurry. For instance `f : α → β → γ → δ` will be turned into `↿f : α × β × γ → δ`. One can also add instances for bundled maps. -/ class HasUncurry (α : Type*) (β : outParam Type*) (γ : outParam Type*) where /-- Uncurrying operator. The most generic use is to recursively uncurry. For instance `f : α → β → γ → δ` will be turned into `↿f : α × β × γ → δ`. One can also add instances for bundled maps. -/ uncurry : α → β → γ @[inherit_doc] prefix:max "↿" => HasUncurry.uncurry instance hasUncurryBase : HasUncurry (α → β) α β := ⟨id⟩ instance hasUncurryInduction [HasUncurry β γ δ] : HasUncurry (α → β) (α × γ) δ := ⟨fun f p ↦ ↿(f p.1) p.2⟩ end Uncurry /-- A function is involutive, if `f ∘ f = id`. -/ def Involutive {α} (f : α → α) : Prop := ∀ x, f (f x) = x theorem _root_.Bool.involutive_not : Involutive not := Bool.not_not namespace Involutive variable {α : Sort u} {f : α → α} (h : Involutive f) include h @[simp] theorem comp_self : f ∘ f = id := funext h protected theorem leftInverse : LeftInverse f f := h theorem leftInverse_iff {g : α → α} : g.LeftInverse f ↔ g = f := ⟨fun hg ↦ funext fun x ↦ by rw [← h x, hg, h], fun he ↦ he ▸ h.leftInverse⟩ protected theorem rightInverse : RightInverse f f := h protected theorem injective : Injective f := h.leftInverse.injective protected theorem surjective : Surjective f := fun x ↦ ⟨f x, h x⟩ protected theorem bijective : Bijective f := ⟨h.injective, h.surjective⟩ /-- Involuting an `ite` of an involuted value `x : α` negates the `Prop` condition in the `ite`. -/ protected theorem ite_not (P : Prop) [Decidable P] (x : α) : f (ite P x (f x)) = ite (¬P) x (f x) := by rw [apply_ite f, h, ite_not] /-- An involution commutes across an equality. Compare to `Function.Injective.eq_iff`. -/ protected theorem eq_iff {x y : α} : f x = y ↔ x = f y := h.injective.eq_iff' (h y) end Involutive lemma not_involutive : Involutive Not := fun _ ↦ propext not_not lemma not_injective : Injective Not := not_involutive.injective lemma not_surjective : Surjective Not := not_involutive.surjective lemma not_bijective : Bijective Not := not_involutive.bijective @[simp] lemma symmetric_apply_eq_iff {α : Sort*} {f : α → α} : Symmetric (f · = ·) ↔ Involutive f := by simp [Symmetric, Involutive] /-- The property of a binary function `f : α → β → γ` being injective. Mathematically this should be thought of as the corresponding function `α × β → γ` being injective. -/ def Injective2 {α β γ : Sort*} (f : α → β → γ) : Prop := ∀ ⦃a₁ a₂ b₁ b₂⦄, f a₁ b₁ = f a₂ b₂ → a₁ = a₂ ∧ b₁ = b₂ namespace Injective2 variable {α β γ : Sort*} {f : α → β → γ} /-- A binary injective function is injective when only the left argument varies. -/ protected theorem left (hf : Injective2 f) (b : β) : Function.Injective fun a ↦ f a b := fun _ _ h ↦ (hf h).left /-- A binary injective function is injective when only the right argument varies. -/ protected theorem right (hf : Injective2 f) (a : α) : Function.Injective (f a) := fun _ _ h ↦ (hf h).right protected theorem uncurry {α β γ : Type*} {f : α → β → γ} (hf : Injective2 f) : Function.Injective (uncurry f) := fun ⟨_, _⟩ ⟨_, _⟩ h ↦ (hf h).elim (congr_arg₂ _) /-- As a map from the left argument to a unary function, `f` is injective. -/ theorem left' (hf : Injective2 f) [Nonempty β] : Function.Injective f := fun _ _ h ↦ let ⟨b⟩ := ‹Nonempty β› hf.left b <| (congr_fun h b :) /-- As a map from the right argument to a unary function, `f` is injective. -/ theorem right' (hf : Injective2 f) [Nonempty α] : Function.Injective fun b a ↦ f a b := fun _ _ h ↦ let ⟨a⟩ := ‹Nonempty α› hf.right a <| (congr_fun h a :) theorem eq_iff (hf : Injective2 f) {a₁ a₂ b₁ b₂} : f a₁ b₁ = f a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := ⟨fun h ↦ hf h, fun ⟨h1, h2⟩ ↦ congr_arg₂ f h1 h2⟩ end Injective2 section Sometimes /-- `sometimes f` evaluates to some value of `f`, if it exists. This function is especially interesting in the case where `α` is a proposition, in which case `f` is necessarily a constant function, so that `sometimes f = f a` for all `a`. -/ noncomputable def sometimes {α β} [Nonempty β] (f : α → β) : β := open scoped Classical in if h : Nonempty α then f (Classical.choice h) else Classical.choice ‹_› theorem sometimes_eq {p : Prop} {α} [Nonempty α] (f : p → α) (a : p) : sometimes f = f a := dif_pos ⟨a⟩ theorem sometimes_spec {p : Prop} {α} [Nonempty α] (P : α → Prop) (f : p → α) (a : p) (h : P (f a)) : P (sometimes f) := by rwa [sometimes_eq] end Sometimes end Function variable {α β : Sort*} /-- A relation `r : α → β → Prop` is "function-like" (for each `a` there exists a unique `b` such that `r a b`) if and only if it is `(f · = ·)` for some function `f`. -/ lemma forall_existsUnique_iff {r : α → β → Prop} : (∀ a, ∃! b, r a b) ↔ ∃ f : α → β, ∀ {a b}, r a b ↔ f a = b := by refine ⟨fun h ↦ ?_, ?_⟩ · refine ⟨fun a ↦ (h a).choose, fun hr ↦ ?_, fun h' ↦ h' ▸ ?_⟩ exacts [((h _).choose_spec.2 _ hr).symm, (h _).choose_spec.1] · rintro ⟨f, hf⟩ simp [hf] /-- A relation `r : α → β → Prop` is "function-like" (for each `a` there exists a unique `b` such that `r a b`) if and only if it is `(f · = ·)` for some function `f`. -/ lemma forall_existsUnique_iff' {r : α → β → Prop} : (∀ a, ∃! b, r a b) ↔ ∃ f : α → β, r = (f · = ·) := by simp [forall_existsUnique_iff, funext_iff] /-- A symmetric relation `r : α → α → Prop` is "function-like" (for each `a` there exists a unique `b` such that `r a b`) if and only if it is `(f · = ·)` for some involutive function `f`. -/ protected lemma Symmetric.forall_existsUnique_iff' {r : α → α → Prop} (hr : Symmetric r) : (∀ a, ∃! b, r a b) ↔ ∃ f : α → α, Involutive f ∧ r = (f · = ·) := by refine ⟨fun h ↦ ?_, fun ⟨f, _, hf⟩ ↦ forall_existsUnique_iff'.2 ⟨f, hf⟩⟩ rcases forall_existsUnique_iff'.1 h with ⟨f, rfl : r = _⟩ exact ⟨f, symmetric_apply_eq_iff.1 hr, rfl⟩ /-- A symmetric relation `r : α → α → Prop` is "function-like" (for each `a` there exists a unique `b` such that `r a b`) if and only if it is `(f · = ·)` for some involutive function `f`. -/ protected lemma Symmetric.forall_existsUnique_iff {r : α → α → Prop} (hr : Symmetric r) : (∀ a, ∃! b, r a b) ↔ ∃ f : α → α, Involutive f ∧ ∀ {a b}, r a b ↔ f a = b := by simp [hr.forall_existsUnique_iff', funext_iff] /-- `s.piecewise f g` is the function equal to `f` on the set `s`, and to `g` on its complement. -/ def Set.piecewise {α : Type u} {β : α → Sort v} (s : Set α) (f g : ∀ i, β i) [∀ j, Decidable (j ∈ s)] : ∀ i, β i := fun i ↦ if i ∈ s then f i else g i /-! ### Bijectivity of `Eq.rec`, `Eq.mp`, `Eq.mpr`, and `cast` -/ theorem eq_rec_on_bijective {C : α → Sort*} : ∀ {a a' : α} (h : a = a'), Function.Bijective (@Eq.ndrec _ _ C · _ h) | _, _, rfl => ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩ theorem eq_mp_bijective {α β : Sort _} (h : α = β) : Function.Bijective (Eq.mp h) := by -- TODO: mathlib3 uses `eq_rec_on_bijective`, difference in elaboration here -- due to `@[macro_inline]` possibly? cases h exact ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩ theorem eq_mpr_bijective {α β : Sort _} (h : α = β) : Function.Bijective (Eq.mpr h) := by cases h exact ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩ theorem cast_bijective {α β : Sort _} (h : α = β) : Function.Bijective (cast h) := by cases h exact ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩ /-! Note these lemmas apply to `Type*` not `Sort*`, as the latter interferes with `simp`, and is trivial anyway. -/ @[simp] theorem eq_rec_inj {a a' : α} (h : a = a') {C : α → Type*} (x y : C a) : (Eq.ndrec x h : C a') = Eq.ndrec y h ↔ x = y := (eq_rec_on_bijective h).injective.eq_iff @[simp] theorem cast_inj {α β : Type u} (h : α = β) {x y : α} : cast h x = cast h y ↔ x = y := (cast_bijective h).injective.eq_iff theorem Function.LeftInverse.eq_rec_eq {γ : β → Sort v} {f : α → β} {g : β → α} (h : Function.LeftInverse g f) (C : ∀ a : α, γ (f a)) (a : α) : -- TODO: mathlib3 uses `(congr_arg f (h a)).rec (C (g (f a)))` for LHS @Eq.rec β (f (g (f a))) (fun x _ ↦ γ x) (C (g (f a))) (f a) (congr_arg f (h a)) = C a := eq_of_heq <| (eqRec_heq _ _).trans <| by rw [h] theorem Function.LeftInverse.eq_rec_on_eq {γ : β → Sort v} {f : α → β} {g : β → α} (h : Function.LeftInverse g f) (C : ∀ a : α, γ (f a)) (a : α) : -- TODO: mathlib3 uses `(congr_arg f (h a)).recOn (C (g (f a)))` for LHS @Eq.recOn β (f (g (f a))) (fun x _ ↦ γ x) (f a) (congr_arg f (h a)) (C (g (f a))) = C a := h.eq_rec_eq _ _ theorem Function.LeftInverse.cast_eq {γ : β → Sort v} {f : α → β} {g : β → α} (h : Function.LeftInverse g f) (C : ∀ a : α, γ (f a)) (a : α) : cast (congr_arg (fun a ↦ γ (f a)) (h a)) (C (g (f a))) = C a := by rw [cast_eq_iff_heq, h] /-- A set of functions "separates points" if for each pair of distinct points there is a function taking different values on them. -/ def Set.SeparatesPoints {α β : Type*} (A : Set (α → β)) : Prop := ∀ ⦃x y : α⦄, x ≠ y → ∃ f ∈ A, (f x : β) ≠ f y theorem InvImage.equivalence {α : Sort u} {β : Sort v} (r : β → β → Prop) (f : α → β) (h : Equivalence r) : Equivalence (InvImage r f) := ⟨fun _ ↦ h.1 _, h.symm, h.trans⟩ instance {α β : Type*} {r : α → β → Prop} {x : α × β} [Decidable (r x.1 x.2)] : Decidable (uncurry r x) := ‹Decidable _› instance {α β : Type*} {r : α × β → Prop} {a : α} {b : β} [Decidable (r (a, b))] : Decidable (curry r a b) := ‹Decidable _›
Integral.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Polynomial.Lifts import Mathlib.RingTheory.Algebraic.Integral import Mathlib.RingTheory.IntegralClosure.Algebra.Basic import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Localization.Integer /-! # Integral and algebraic elements of a fraction field ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommRing R] (M : Submonoid R) {S : Type*} [CommRing S] variable [Algebra R S] open Polynomial namespace IsLocalization section IntegerNormalization open Polynomial variable [IsLocalization M S] open scoped Classical in /-- `coeffIntegerNormalization p` gives the coefficients of the polynomial `integerNormalization p` -/ noncomputable def coeffIntegerNormalization (p : S[X]) (i : ℕ) : R := if hi : i ∈ p.support then Classical.choose (Classical.choose_spec (exist_integer_multiples_of_finset M (p.support.image p.coeff)) (p.coeff i) (Finset.mem_image.mpr ⟨i, hi, rfl⟩)) else 0 theorem coeffIntegerNormalization_of_coeff_zero (p : S[X]) (i : ℕ) (h : coeff p i = 0) : coeffIntegerNormalization M p i = 0 := by simp only [coeffIntegerNormalization, h, mem_support_iff, not_true, Ne, dif_neg, not_false_iff] @[deprecated (since := "2025-05-23")] alias coeffIntegerNormalization_of_not_mem_support := coeffIntegerNormalization_of_coeff_zero theorem coeffIntegerNormalization_mem_support (p : S[X]) (i : ℕ) (h : coeffIntegerNormalization M p i ≠ 0) : i ∈ p.support := by contrapose h rw [Ne, Classical.not_not, coeffIntegerNormalization, dif_neg h] /-- `integerNormalization g` normalizes `g` to have integer coefficients by clearing the denominators -/ noncomputable def integerNormalization (p : S[X]) : R[X] := ∑ i ∈ p.support, monomial i (coeffIntegerNormalization M p i) @[simp] theorem integerNormalization_coeff (p : S[X]) (i : ℕ) : (integerNormalization M p).coeff i = coeffIntegerNormalization M p i := by simp +contextual [integerNormalization, coeff_monomial, coeffIntegerNormalization_of_coeff_zero] theorem integerNormalization_spec (p : S[X]) : ∃ b : M, ∀ i, algebraMap R S ((integerNormalization M p).coeff i) = (b : R) • p.coeff i := by classical use Classical.choose (exist_integer_multiples_of_finset M (p.support.image p.coeff)) intro i rw [integerNormalization_coeff, coeffIntegerNormalization] split_ifs with hi · exact Classical.choose_spec (Classical.choose_spec (exist_integer_multiples_of_finset M (p.support.image p.coeff)) (p.coeff i) (Finset.mem_image.mpr ⟨i, hi, rfl⟩)) · rw [RingHom.map_zero, notMem_support_iff.mp hi, smul_zero] -- Porting note: was `convert (smul_zero _).symm, ...` theorem integerNormalization_map_to_map (p : S[X]) : ∃ b : M, (integerNormalization M p).map (algebraMap R S) = (b : R) • p := let ⟨b, hb⟩ := integerNormalization_spec M p ⟨b, Polynomial.ext fun i => by rw [coeff_map, coeff_smul] exact hb i⟩ variable {R' : Type*} [CommRing R'] theorem integerNormalization_eval₂_eq_zero (g : S →+* R') (p : S[X]) {x : R'} (hx : eval₂ g x p = 0) : eval₂ (g.comp (algebraMap R S)) x (integerNormalization M p) = 0 := let ⟨b, hb⟩ := integerNormalization_map_to_map M p _root_.trans (eval₂_map (algebraMap R S) g x).symm (by rw [hb, ← IsScalarTower.algebraMap_smul S (b : R) p, eval₂_smul, hx, mul_zero]) theorem integerNormalization_aeval_eq_zero [Algebra R R'] [Algebra S R'] [IsScalarTower R S R'] (p : S[X]) {x : R'} (hx : aeval x p = 0) : aeval x (integerNormalization M p) = 0 := by rw [aeval_def, IsScalarTower.algebraMap_eq R S R', integerNormalization_eval₂_eq_zero _ (algebraMap _ _) _ hx] end IntegerNormalization end IsLocalization namespace IsFractionRing open IsLocalization variable {A K C : Type*} [CommRing A] [IsDomain A] [Field K] [Algebra A K] [IsFractionRing A K] variable [CommRing C] theorem integerNormalization_eq_zero_iff {p : K[X]} : integerNormalization (nonZeroDivisors A) p = 0 ↔ p = 0 := by refine Polynomial.ext_iff.trans (Polynomial.ext_iff.trans ?_).symm obtain ⟨⟨b, nonzero⟩, hb⟩ := integerNormalization_spec (nonZeroDivisors A) p constructor <;> intro h i · -- Porting note: avoided some defeq abuse rw [coeff_zero, ← to_map_eq_zero_iff (K := K), hb i, h i, coeff_zero, smul_zero] · have hi := h i rw [Polynomial.coeff_zero, ← @to_map_eq_zero_iff A _ K, hb i, Algebra.smul_def] at hi apply Or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hi) intro h apply mem_nonZeroDivisors_iff_ne_zero.mp nonzero exact to_map_eq_zero_iff.mp h variable (A K C) /-- An element of a ring is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`. -/ theorem isAlgebraic_iff [Algebra A C] [Algebra K C] [IsScalarTower A K C] {x : C} : IsAlgebraic A x ↔ IsAlgebraic K x := by constructor <;> rintro ⟨p, hp, px⟩ · refine ⟨p.map (algebraMap A K), fun h => hp (Polynomial.ext fun i => ?_), ?_⟩ · have : algebraMap A K (p.coeff i) = 0 := _root_.trans (Polynomial.coeff_map _ _).symm (by simp [h]) exact to_map_eq_zero_iff.mp this · exact (Polynomial.aeval_map_algebraMap K _ _).trans px · exact ⟨integerNormalization _ p, mt integerNormalization_eq_zero_iff.mp hp, integerNormalization_aeval_eq_zero _ p px⟩ variable {A K C} /-- A ring is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`. -/ theorem comap_isAlgebraic_iff [Algebra A C] [Algebra K C] [IsScalarTower A K C] : Algebra.IsAlgebraic A C ↔ Algebra.IsAlgebraic K C := ⟨fun h => ⟨fun x => (isAlgebraic_iff A K C).mp (h.isAlgebraic x)⟩, fun h => ⟨fun x => (isAlgebraic_iff A K C).mpr (h.isAlgebraic x)⟩⟩ end IsFractionRing open IsLocalization section IsIntegral variable {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] variable [Algebra R Rₘ] [IsLocalization M Rₘ] variable [Algebra S Sₘ] [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] variable {M} open Polynomial theorem RingHom.isIntegralElem_localization_at_leadingCoeff {R S : Type*} [CommSemiring R] [CommSemiring S] (f : R →+* S) (x : S) (p : R[X]) (hf : p.eval₂ f x = 0) (M : Submonoid R) (hM : p.leadingCoeff ∈ M) {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] [Algebra R Rₘ] [IsLocalization M Rₘ] [Algebra S Sₘ] [IsLocalization (M.map f : Submonoid S) Sₘ] : (map Sₘ f M.le_comap_map : Rₘ →+* _).IsIntegralElem (algebraMap S Sₘ x) := by by_cases triv : (1 : Rₘ) = 0 · exact ⟨0, ⟨_root_.trans leadingCoeff_zero triv.symm, eval₂_zero _ _⟩⟩ haveI : Nontrivial Rₘ := nontrivial_of_ne 1 0 triv obtain ⟨b, hb⟩ := isUnit_iff_exists_inv.mp (map_units Rₘ ⟨p.leadingCoeff, hM⟩) refine ⟨p.map (algebraMap R Rₘ) * C b, ⟨?_, ?_⟩⟩ · refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_ rwa [leadingCoeff_map_of_leadingCoeff_ne_zero (algebraMap R Rₘ)] refine fun hfp => zero_ne_one (_root_.trans (zero_mul b).symm (hfp ▸ hb) : (0 : Rₘ) = 1) · refine eval₂_mul_eq_zero_of_left _ _ _ ?_ rw [eval₂_map, IsLocalization.map_comp, ← hom_eval₂ _ f (algebraMap S Sₘ) x] exact _root_.trans (congr_arg (algebraMap S Sₘ) hf) (RingHom.map_zero _) /-- Given a particular witness to an element being algebraic over an algebra `R → S`, We can localize to a submonoid containing the leading coefficient to make it integral. Explicitly, the map between the localizations will be an integral ring morphism -/ theorem is_integral_localization_at_leadingCoeff {x : S} (p : R[X]) (hp : aeval x p = 0) (hM : p.leadingCoeff ∈ M) : (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* _).IsIntegralElem (algebraMap S Sₘ x) := -- Porting note: added `haveI` haveI : IsLocalization (Submonoid.map (algebraMap R S) M) Sₘ := inferInstanceAs (IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ) (algebraMap R S).isIntegralElem_localization_at_leadingCoeff x p hp M hM /-- If `R → S` is an integral extension, `M` is a submonoid of `R`, `Rₘ` is the localization of `R` at `M`, and `Sₘ` is the localization of `S` at the image of `M` under the extension map, then the induced map `Rₘ → Sₘ` is also an integral extension -/ theorem isIntegral_localization [Algebra.IsIntegral R S] : (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* _).IsIntegral := by intro x obtain ⟨⟨s, ⟨u, hu⟩⟩, hx⟩ := surj (Algebra.algebraMapSubmonoid S M) x obtain ⟨v, hv⟩ := hu obtain ⟨v', hv'⟩ := isUnit_iff_exists_inv'.1 (map_units Rₘ ⟨v, hv.1⟩) refine @IsIntegral.of_mul_unit Rₘ _ _ _ (localizationAlgebra M S) x (algebraMap S Sₘ u) v' ?_ ?_ · replace hv' := congr_arg (@algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S)) hv' rw [RingHom.map_mul, RingHom.map_one, localizationAlgebraMap_def, IsLocalization.map_eq] at hv' exact hv.2 ▸ hv' · obtain ⟨p, hp⟩ := Algebra.IsIntegral.isIntegral (R := R) s exact hx.symm ▸ is_integral_localization_at_leadingCoeff p hp.2 (hp.1.symm ▸ M.one_mem) @[nolint unusedHavesSuffices] -- It claims the `have : IsLocalization` line is unnecessary, -- but remove it and the proof won't work. theorem isIntegral_localization' {R S : Type*} [CommRing R] [CommRing S] {f : R →+* S} (hf : f.IsIntegral) (M : Submonoid R) : (map (Localization (M.map (f : R →* S))) f (M.le_comap_map : _ ≤ Submonoid.comap (f : R →* S) _) : Localization M →+* _).IsIntegral := -- Porting note: added let _ := f.toAlgebra have : Algebra.IsIntegral R S := ⟨hf⟩ have : IsLocalization (Algebra.algebraMapSubmonoid S M) (Localization (Submonoid.map (f : R →* S) M)) := Localization.isLocalization isIntegral_localization variable (M) theorem IsLocalization.scaleRoots_commonDenom_mem_lifts (p : Rₘ[X]) (hp : p.leadingCoeff ∈ (algebraMap R Rₘ).range) : p.scaleRoots (algebraMap R Rₘ <| IsLocalization.commonDenom M p.support p.coeff) ∈ Polynomial.lifts (algebraMap R Rₘ) := by rw [Polynomial.lifts_iff_coeff_lifts] intro n rw [Polynomial.coeff_scaleRoots] by_cases h₁ : n ∈ p.support on_goal 1 => by_cases h₂ : n = p.natDegree · rwa [h₂, Polynomial.coeff_natDegree, tsub_self, pow_zero, _root_.mul_one] · have : n + 1 ≤ p.natDegree := lt_of_le_of_ne (Polynomial.le_natDegree_of_mem_supp _ h₁) h₂ rw [← tsub_add_cancel_of_le (le_tsub_of_add_le_left this), pow_add, pow_one, mul_comm, _root_.mul_assoc, ← map_pow] change _ ∈ (algebraMap R Rₘ).range apply mul_mem · exact RingHom.mem_range_self _ _ · rw [← Algebra.smul_def] exact ⟨_, IsLocalization.map_integerMultiple M p.support p.coeff ⟨n, h₁⟩⟩ · rw [Polynomial.notMem_support_iff] at h₁ rw [h₁, zero_mul] exact zero_mem (algebraMap R Rₘ).range theorem IsIntegral.exists_multiple_integral_of_isLocalization [Algebra Rₘ S] [IsScalarTower R Rₘ S] (x : S) (hx : IsIntegral Rₘ x) : ∃ m : M, IsIntegral R (m • x) := by rcases subsingleton_or_nontrivial Rₘ with _ | nontriv · haveI := (_root_.algebraMap Rₘ S).codomain_trivial exact ⟨1, Polynomial.X, Polynomial.monic_X, Subsingleton.elim _ _⟩ obtain ⟨p, hp₁, hp₂⟩ := hx -- Porting note: obtain doesn't support side goals have := lifts_and_natDegree_eq_and_monic (IsLocalization.scaleRoots_commonDenom_mem_lifts M p ?_) ?_ · obtain ⟨p', hp'₁, -, hp'₂⟩ := this refine ⟨IsLocalization.commonDenom M p.support p.coeff, p', hp'₂, ?_⟩ rw [IsScalarTower.algebraMap_eq R Rₘ S, ← Polynomial.eval₂_map, hp'₁, Submonoid.smul_def, Algebra.smul_def, IsScalarTower.algebraMap_apply R Rₘ S] exact Polynomial.scaleRoots_eval₂_eq_zero _ hp₂ · rw [hp₁.leadingCoeff] exact one_mem _ · rwa [Polynomial.monic_scaleRoots_iff] end IsIntegral variable {A K : Type*} [CommRing A] namespace IsIntegralClosure variable (A) variable {L : Type*} [Field K] [Field L] [Algebra A K] [Algebra A L] [IsFractionRing A K] variable (C : Type*) [CommRing C] [IsDomain C] [Algebra C L] [IsIntegralClosure C A L] variable [Algebra A C] [IsScalarTower A C L] open Algebra /-- If the field `L` is an algebraic extension of the integral domain `A`, the integral closure `C` of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_algebraic [Algebra.IsAlgebraic A L] (inj : ∀ x, algebraMap A L x = 0 → x = 0) : IsFractionRing C L := { map_units' := fun ⟨y, hy⟩ => IsUnit.mk0 _ (show algebraMap C L y ≠ 0 from fun h => mem_nonZeroDivisors_iff_ne_zero.mp hy ((injective_iff_map_eq_zero (algebraMap C L)).mp (algebraMap_injective C A L) _ h)) surj' := fun z => let ⟨x, hx, int⟩ := (Algebra.IsAlgebraic.isAlgebraic z).exists_integral_multiple ⟨⟨mk' C _ int, algebraMap _ _ x, mem_nonZeroDivisors_of_ne_zero fun h ↦ hx (inj _ <| by rw [IsScalarTower.algebraMap_apply A C L, h, RingHom.map_zero])⟩, by rw [algebraMap_mk', ← IsScalarTower.algebraMap_apply A C L, Algebra.smul_def, mul_comm]⟩ exists_of_eq := fun {x y} h => ⟨1, by simpa using algebraMap_injective C A L h⟩ } variable (K L) /-- If the field `L` is a finite extension of the fraction field of the integral domain `A`, the integral closure `C` of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_finite_extension [IsDomain A] [Algebra K L] [IsScalarTower A K L] [FiniteDimensional K L] : IsFractionRing C L := have : Algebra.IsAlgebraic A L := IsFractionRing.comap_isAlgebraic_iff.mpr (inferInstanceAs (Algebra.IsAlgebraic K L)) isFractionRing_of_algebraic A C fun _ hx => IsFractionRing.to_map_eq_zero_iff.mp ((map_eq_zero <| algebraMap K L).mp <| (IsScalarTower.algebraMap_apply _ _ _ _).symm.trans hx) end IsIntegralClosure namespace integralClosure variable {L : Type*} [Field K] [Field L] [Algebra A K] [IsFractionRing A K] open Algebra /-- If the field `L` is an algebraic extension of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_algebraic [Algebra A L] [Algebra.IsAlgebraic A L] (inj : ∀ x, algebraMap A L x = 0 → x = 0) : IsFractionRing (integralClosure A L) L := IsIntegralClosure.isFractionRing_of_algebraic A (integralClosure A L) inj variable (K L) /-- If the field `L` is a finite extension of the fraction field of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_finite_extension [IsDomain A] [Algebra A L] [Algebra K L] [IsScalarTower A K L] [FiniteDimensional K L] : IsFractionRing (integralClosure A L) L := IsIntegralClosure.isFractionRing_of_finite_extension A K L (integralClosure A L) end integralClosure namespace IsFractionRing variable (R S K) /-- `S` is algebraic over `R` iff a fraction ring of `S` is algebraic over `R` -/ theorem isAlgebraic_iff' [Field K] [IsDomain R] [Algebra R K] [Algebra S K] [NoZeroSMulDivisors R K] [IsFractionRing S K] [IsScalarTower R S K] : Algebra.IsAlgebraic R S ↔ Algebra.IsAlgebraic R K := by simp only [Algebra.isAlgebraic_def] constructor · intro h x letI := MulActionWithZero.nontrivial S K letI := FractionRing.liftAlgebra R K have := FractionRing.isScalarTower_liftAlgebra R K rw [IsFractionRing.isAlgebraic_iff R (FractionRing R) K, isAlgebraic_iff_isIntegral] obtain ⟨a : S, b, ha, rfl⟩ := div_surjective (A := S) x obtain ⟨f, hf₁, hf₂⟩ := h b rw [div_eq_mul_inv] refine .mul ?_ (.inv ?_) <;> exact isAlgebraic_iff_isIntegral.mp <| (h _).algebraMap.extendScalars (FaithfulSMul.algebraMap_injective R _) · intro h x obtain ⟨f, hf₁, hf₂⟩ := h (algebraMap S K x) use f, hf₁ rw [Polynomial.aeval_algebraMap_apply] at hf₂ exact (injective_iff_map_eq_zero (algebraMap S K)).1 (FaithfulSMul.algebraMap_injective _ _) _ hf₂ open nonZeroDivisors variable {S K} /-- If the `S`-multiples of `a` are contained in some `R`-span, then `Frac(S)`-multiples of `a` are contained in the equivalent `Frac(R)`-span. -/ theorem ideal_span_singleton_map_subset {L : Type*} [IsDomain R] [IsDomain S] [Field K] [Field L] [Algebra R K] [Algebra R L] [Algebra S L] [Algebra.IsAlgebraic R S] [IsFractionRing S L] [Algebra K L] [IsScalarTower R S L] [IsScalarTower R K L] {a : S} {b : Set S} (inj : Function.Injective (algebraMap R L)) (h : (Ideal.span ({a} : Set S) : Set S) ⊆ Submodule.span R b) : (Ideal.span ({algebraMap S L a} : Set L) : Set L) ⊆ Submodule.span K (algebraMap S L '' b) := by intro x hx obtain ⟨x', rfl⟩ := Ideal.mem_span_singleton.mp hx obtain ⟨y', z', rfl⟩ := IsLocalization.mk'_surjective S⁰ x' obtain ⟨y, z, hz0, yz_eq⟩ := Algebra.IsAlgebraic.exists_smul_eq_mul R y' (nonZeroDivisors.coe_ne_zero z') have injRS : Function.Injective (algebraMap R S) := by refine Function.Injective.of_comp (show Function.Injective (algebraMap S L ∘ algebraMap R S) from ?_) rwa [← RingHom.coe_comp, ← IsScalarTower.algebraMap_eq] have hz0' : algebraMap R S z ∈ S⁰ := map_mem_nonZeroDivisors (algebraMap R S) injRS (mem_nonZeroDivisors_of_ne_zero hz0) have mk_yz_eq : IsLocalization.mk' L y' z' = IsLocalization.mk' L y ⟨_, hz0'⟩ := by rw [Algebra.smul_def, mul_comm _ y, mul_comm _ y'] at yz_eq exact IsLocalization.mk'_eq_of_eq (by rw [mul_comm _ y, mul_comm _ y', yz_eq]) suffices hy : algebraMap S L (a * y) ∈ Submodule.span K ((algebraMap S L) '' b) by rw [mk_yz_eq, IsFractionRing.mk'_eq_div, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R K L, div_eq_mul_inv, ← mul_assoc, mul_comm, ← map_inv₀, ← Algebra.smul_def, ← map_mul] exact (Submodule.span K _).smul_mem _ hy refine Submodule.span_subset_span R K _ ?_ rw [Submodule.span_algebraMap_image_of_tower] -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify the value of `f` here: exact Submodule.mem_map_of_mem (f := LinearMap.restrictScalars _ _) (h (Ideal.mem_span_singleton.mpr ⟨y, rfl⟩)) end IsFractionRing @[deprecated (since := "2025-03-23")] alias isAlgebraic_of_isLocalization := IsLocalization.isAlgebraic open nonZeroDivisors in lemma isAlgebraic_of_isFractionRing {R S} (K L) [CommRing R] [CommRing S] [Field K] [CommRing L] [Algebra R S] [Algebra R K] [Algebra R L] [Algebra S L] [Algebra K L] [IsScalarTower R S L] [IsScalarTower R K L] [IsFractionRing S L] [Algebra.IsIntegral R S] : Algebra.IsAlgebraic K L := by constructor intro x obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective S⁰ x apply IsIntegral.isAlgebraic rw [IsLocalization.mk'_eq_mul_mk'_one] apply RingHom.IsIntegralElem.mul · apply IsIntegral.tower_top (R := R) apply IsIntegral.map (IsScalarTower.toAlgHom R S L) exact Algebra.IsIntegral.isIntegral x · change IsIntegral _ _ rw [← isAlgebraic_iff_isIntegral, ← IsAlgebraic.invOf_iff, isAlgebraic_iff_isIntegral] apply IsIntegral.tower_top (R := R) apply IsIntegral.map (IsScalarTower.toAlgHom R S L) exact Algebra.IsIntegral.isIntegral (s : S)
Basic.lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Johan Commelin, Bhavik Mehta -/ import Mathlib.CategoryTheory.Equivalence import Mathlib.CategoryTheory.Yoneda /-! # Adjunctions between functors `F ⊣ G` represents the data of an adjunction between two functors `F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint. We provide various useful constructors: * `mkOfHomEquiv` * `mk'`: construct an adjunction from the data of a hom set equivalence, unit and counit natural transformations together with proofs of the equalities `homEquiv_unit` and `homEquiv_counit` relating them to each other. * `leftAdjointOfEquiv` / `rightAdjointOfEquiv` construct a left/right adjoint of a given functor given the action on objects and the relevant equivalence of morphism spaces. * `adjunctionOfEquivLeft` / `adjunctionOfEquivRight` witness that these constructions give adjunctions. There are also typeclasses `IsLeftAdjoint` / `IsRightAdjoint`, which asserts the existence of a adjoint functor. Given `[F.IsLeftAdjoint]`, a chosen right adjoint can be obtained as `F.rightAdjoint`. `Adjunction.comp` composes adjunctions. `toEquivalence` upgrades an adjunction to an equivalence, given witnesses that the unit and counit are pointwise isomorphisms. Conversely `Equivalence.toAdjunction` recovers the underlying adjunction from an equivalence. ## Overview of the directory `CategoryTheory.Adjunction` * Adjoint lifting theorems are in the directory `Lifting`. * The file `AdjointFunctorTheorems` proves the adjoint functor theorems. * The file `Comma` shows that for a functor `G : D ⥤ C` the data of an initial object in each `StructuredArrow` category on `G` is equivalent to a left adjoint to `G`, as well as the dual. * The file `Evaluation` shows that products and coproducts are adjoint to evaluation of functors. * The file `FullyFaithful` characterizes when adjoints are full or faithful in terms of the unit and counit. * The file `Limits` proves that left adjoints preserve colimits and right adjoints preserve limits. * The file `Mates` establishes the bijection between the 2-cells ``` L₁ R₁ C --→ D C ←-- D G ↓ ↗ ↓ H G ↓ ↘ ↓ H E --→ F E ←-- F L₂ R₂ ``` where `L₁ ⊣ R₁` and `L₂ ⊣ R₂`. Specializing to a pair of adjoints `L₁ L₂ : C ⥤ D`, `R₁ R₂ : D ⥤ C`, it provides equivalences `(L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂)` and `(L₂ ≅ L₁) ≃ (R₁ ≅ R₂)`. * The file `Opposites` contains constructions to relate adjunctions of functors to adjunctions of their opposites. * The file `Reflective` defines reflective functors, i.e. fully faithful right adjoints. Note that many facts about reflective functors are proved in the earlier file `FullyFaithful`. * The file `Restrict` defines the restriction of an adjunction along fully faithful functors. * The file `Triple` proves that in an adjoint triple, the left adjoint is fully faithful if and only if the right adjoint is. * The file `Unique` proves uniqueness of adjoints. * The file `Whiskering` proves that functors `F : D ⥤ E` and `G : E ⥤ D` with an adjunction `F ⊣ G`, induce adjunctions between the functor categories `C ⥤ D` and `C ⥤ E`, and the functor categories `E ⥤ C` and `D ⥤ C`. ## Other files related to adjunctions * The file `CategoryTheory.Monad.Adjunction` develops the basic relationship between adjunctions and (co)monads. There it is also shown that given an adjunction `L ⊣ R` and an isomorphism `L ⋙ R ≅ 𝟭 C`, the unit is an isomorphism, and similarly for the counit. -/ namespace CategoryTheory open Category Functor -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] /-- `F ⊣ G` represents the data of an adjunction between two functors `F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint. We use the unit-counit definition of an adjunction. There is a constructor `Adjunction.mk'` which constructs an adjunction from the data of a hom set equivalence, a unit, and a counit, together with proofs of the equalities `homEquiv_unit` and `homEquiv_counit` relating them to each other. There is also a constructor `Adjunction.mkOfHomEquiv` which constructs an adjunction from a natural hom set equivalence. To construct adjoints to a given functor, there are constructors `leftAdjointOfEquiv` and `adjunctionOfEquivLeft` (as well as their duals). -/ @[stacks 0037] structure Adjunction (F : C ⥤ D) (G : D ⥤ C) where /-- The unit of an adjunction -/ unit : 𝟭 C ⟶ F.comp G /-- The counit of an adjunction -/ counit : G.comp F ⟶ 𝟭 D /-- Equality of the composition of the unit and counit with the identity `F ⟶ FGF ⟶ F = 𝟙` -/ left_triangle_components (X : C) : F.map (unit.app X) ≫ counit.app (F.obj X) = 𝟙 (F.obj X) := by cat_disch /-- Equality of the composition of the unit and counit with the identity `G ⟶ GFG ⟶ G = 𝟙` -/ right_triangle_components (Y : D) : unit.app (G.obj Y) ≫ G.map (counit.app Y) = 𝟙 (G.obj Y) := by cat_disch /-- The notation `F ⊣ G` stands for `Adjunction F G` representing that `F` is left adjoint to `G` -/ infixl:15 " ⊣ " => Adjunction namespace Functor /-- A class asserting the existence of a right adjoint. -/ class IsLeftAdjoint (left : C ⥤ D) : Prop where exists_rightAdjoint : ∃ (right : D ⥤ C), Nonempty (left ⊣ right) /-- A class asserting the existence of a left adjoint. -/ class IsRightAdjoint (right : D ⥤ C) : Prop where exists_leftAdjoint : ∃ (left : C ⥤ D), Nonempty (left ⊣ right) /-- A chosen left adjoint to a functor that is a right adjoint. -/ noncomputable def leftAdjoint (R : D ⥤ C) [IsRightAdjoint R] : C ⥤ D := (IsRightAdjoint.exists_leftAdjoint (right := R)).choose /-- A chosen right adjoint to a functor that is a left adjoint. -/ noncomputable def rightAdjoint (L : C ⥤ D) [IsLeftAdjoint L] : D ⥤ C := (IsLeftAdjoint.exists_rightAdjoint (left := L)).choose end Functor /-- The adjunction associated to a functor known to be a left adjoint. -/ noncomputable def Adjunction.ofIsLeftAdjoint (left : C ⥤ D) [left.IsLeftAdjoint] : left ⊣ left.rightAdjoint := IsLeftAdjoint.exists_rightAdjoint.choose_spec.some /-- The adjunction associated to a functor known to be a right adjoint. -/ noncomputable def Adjunction.ofIsRightAdjoint (right : C ⥤ D) [right.IsRightAdjoint] : right.leftAdjoint ⊣ right := IsRightAdjoint.exists_leftAdjoint.choose_spec.some namespace Adjunction attribute [reassoc (attr := simp)] left_triangle_components right_triangle_components /-- The hom set equivalence associated to an adjunction. -/ @[simps -isSimp] def homEquiv {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) (X : C) (Y : D) : (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y) where toFun := fun f => adj.unit.app X ≫ G.map f invFun := fun g => F.map g ≫ adj.counit.app Y left_inv := fun f => by dsimp rw [F.map_comp, assoc, ← Functor.comp_map, adj.counit.naturality, ← assoc] simp right_inv := fun g => by simp only [Functor.comp_obj, Functor.map_comp] rw [← assoc, ← Functor.comp_map, ← adj.unit.naturality] simp alias homEquiv_unit := homEquiv_apply alias homEquiv_counit := homEquiv_symm_apply end Adjunction -- These lemmas are not global simp lemmas because certain adjunctions -- are constructed using `Adjunction.mkOfHomEquiv`, and we certainly -- do not want `dsimp` to apply `homEquiv_unit` or `homEquiv_counit` -- in that case. However, when proving general API results about adjunctions, -- it may be advisable to add a local simp attribute to these lemmas. attribute [local simp] Adjunction.homEquiv_unit Adjunction.homEquiv_counit namespace Adjunction @[ext] lemma ext {F : C ⥤ D} {G : D ⥤ C} {adj adj' : F ⊣ G} (h : adj.unit = adj'.unit) : adj = adj' := by suffices h' : adj.counit = adj'.counit by cases adj; cases adj'; aesop ext X apply (adj.homEquiv _ _).injective rw [Adjunction.homEquiv_unit, Adjunction.homEquiv_unit, Adjunction.right_triangle_components, h, Adjunction.right_triangle_components] section variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) lemma isLeftAdjoint (adj : F ⊣ G) : F.IsLeftAdjoint := ⟨_, ⟨adj⟩⟩ lemma isRightAdjoint (adj : F ⊣ G) : G.IsRightAdjoint := ⟨_, ⟨adj⟩⟩ instance (R : D ⥤ C) [R.IsRightAdjoint] : R.leftAdjoint.IsLeftAdjoint := (ofIsRightAdjoint R).isLeftAdjoint instance (L : C ⥤ D) [L.IsLeftAdjoint] : L.rightAdjoint.IsRightAdjoint := (ofIsLeftAdjoint L).isRightAdjoint variable {X' X : C} {Y Y' : D} theorem homEquiv_id (X : C) : adj.homEquiv X _ (𝟙 _) = adj.unit.app X := by simp theorem homEquiv_symm_id (X : D) : (adj.homEquiv _ X).symm (𝟙 _) = adj.counit.app X := by simp theorem homEquiv_naturality_left_symm (f : X' ⟶ X) (g : X ⟶ G.obj Y) : (adj.homEquiv X' Y).symm (f ≫ g) = F.map f ≫ (adj.homEquiv X Y).symm g := by simp theorem homEquiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) : (adj.homEquiv X' Y) (F.map f ≫ g) = f ≫ (adj.homEquiv X Y) g := by rw [← Equiv.eq_symm_apply] simp only [Equiv.symm_apply_apply, homEquiv_naturality_left_symm] theorem homEquiv_naturality_right (f : F.obj X ⟶ Y) (g : Y ⟶ Y') : (adj.homEquiv X Y') (f ≫ g) = (adj.homEquiv X Y) f ≫ G.map g := by simp theorem homEquiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (adj.homEquiv X Y').symm (f ≫ G.map g) = (adj.homEquiv X Y).symm f ≫ g := by rw [Equiv.symm_apply_eq] simp only [homEquiv_naturality_right, Equiv.apply_symm_apply] @[reassoc] theorem homEquiv_naturality_left_square (f : X' ⟶ X) (g : F.obj X ⟶ Y') (h : F.obj X' ⟶ Y) (k : Y ⟶ Y') (w : F.map f ≫ g = h ≫ k) : f ≫ (adj.homEquiv X Y') g = (adj.homEquiv X' Y) h ≫ G.map k := by rw [← homEquiv_naturality_left, ← homEquiv_naturality_right, w] @[reassoc] theorem homEquiv_naturality_right_square (f : X' ⟶ X) (g : X ⟶ G.obj Y') (h : X' ⟶ G.obj Y) (k : Y ⟶ Y') (w : f ≫ g = h ≫ G.map k) : F.map f ≫ (adj.homEquiv X Y').symm g = (adj.homEquiv X' Y).symm h ≫ k := by rw [← homEquiv_naturality_left_symm, ← homEquiv_naturality_right_symm, w] theorem homEquiv_naturality_left_square_iff (f : X' ⟶ X) (g : F.obj X ⟶ Y') (h : F.obj X' ⟶ Y) (k : Y ⟶ Y') : (f ≫ (adj.homEquiv X Y') g = (adj.homEquiv X' Y) h ≫ G.map k) ↔ (F.map f ≫ g = h ≫ k) := ⟨fun w ↦ by simpa only [Equiv.symm_apply_apply] using homEquiv_naturality_right_square adj _ _ _ _ w, homEquiv_naturality_left_square adj f g h k⟩ theorem homEquiv_naturality_right_square_iff (f : X' ⟶ X) (g : X ⟶ G.obj Y') (h : X' ⟶ G.obj Y) (k : Y ⟶ Y') : (F.map f ≫ (adj.homEquiv X Y').symm g = (adj.homEquiv X' Y).symm h ≫ k) ↔ (f ≫ g = h ≫ G.map k) := ⟨fun w ↦ by simpa only [Equiv.apply_symm_apply] using homEquiv_naturality_left_square adj _ _ _ _ w, homEquiv_naturality_right_square adj f g h k⟩ @[simp] theorem left_triangle : whiskerRight adj.unit F ≫ whiskerLeft F adj.counit = 𝟙 _ := by ext; simp @[simp] theorem right_triangle : whiskerLeft G adj.unit ≫ whiskerRight adj.counit G = 𝟙 _ := by ext; simp @[reassoc (attr := simp)] theorem counit_naturality {X Y : D} (f : X ⟶ Y) : F.map (G.map f) ≫ adj.counit.app Y = adj.counit.app X ≫ f := adj.counit.naturality f @[reassoc (attr := simp)] theorem unit_naturality {X Y : C} (f : X ⟶ Y) : adj.unit.app X ≫ G.map (F.map f) = f ≫ adj.unit.app Y := (adj.unit.naturality f).symm lemma unit_comp_map_eq_iff {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) : adj.unit.app A ≫ G.map f = g ↔ f = F.map g ≫ adj.counit.app B := ⟨fun h => by simp [← h], fun h => by simp [h]⟩ lemma eq_unit_comp_map_iff {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) : g = adj.unit.app A ≫ G.map f ↔ F.map g ≫ adj.counit.app B = f := ⟨fun h => by simp [h], fun h => by simp [← h]⟩ theorem homEquiv_apply_eq {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) : adj.homEquiv A B f = g ↔ f = (adj.homEquiv A B).symm g := unit_comp_map_eq_iff adj f g theorem eq_homEquiv_apply {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) : g = adj.homEquiv A B f ↔ (adj.homEquiv A B).symm g = f := eq_unit_comp_map_iff adj f g /-- If `adj : F ⊣ G`, and `X : C`, then `F.obj X` corepresents `Y ↦ (X ⟶ G.obj Y)`. -/ @[simps] def corepresentableBy (X : C) : (G ⋙ coyoneda.obj (Opposite.op X)).CorepresentableBy (F.obj X) where homEquiv := adj.homEquiv _ _ homEquiv_comp := by simp /-- If `adj : F ⊣ G`, and `Y : D`, then `G.obj Y` represents `X ↦ (F.obj X ⟶ Y)`. -/ @[simps] def representableBy (Y : D) : (F.op ⋙ yoneda.obj Y).RepresentableBy (G.obj Y) where homEquiv := (adj.homEquiv _ _).symm homEquiv_comp := by simp end end Adjunction namespace Adjunction /-- This is an auxiliary data structure useful for constructing adjunctions. See `Adjunction.mk'`. This structure won't typically be used anywhere else. -/ structure CoreHomEquivUnitCounit (F : C ⥤ D) (G : D ⥤ C) where /-- The equivalence between `Hom (F X) Y` and `Hom X (G Y)` coming from an adjunction -/ homEquiv : ∀ X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y) /-- The unit of an adjunction -/ unit : 𝟭 C ⟶ F ⋙ G /-- The counit of an adjunction -/ counit : G ⋙ F ⟶ 𝟭 D /-- The relationship between the unit and hom set equivalence of an adjunction -/ homEquiv_unit : ∀ {X Y f}, (homEquiv X Y) f = unit.app X ≫ G.map f := by cat_disch /-- The relationship between the counit and hom set equivalence of an adjunction -/ homEquiv_counit : ∀ {X Y g}, (homEquiv X Y).symm g = F.map g ≫ counit.app Y := by cat_disch /-- This is an auxiliary data structure useful for constructing adjunctions. See `Adjunction.mkOfHomEquiv`. This structure won't typically be used anywhere else. -/ structure CoreHomEquiv (F : C ⥤ D) (G : D ⥤ C) where /-- The equivalence between `Hom (F X) Y` and `Hom X (G Y)` -/ homEquiv : ∀ X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y) /-- The property that describes how `homEquiv.symm` transforms compositions `X' ⟶ X ⟶ G Y` -/ homEquiv_naturality_left_symm : ∀ {X' X Y} (f : X' ⟶ X) (g : X ⟶ G.obj Y), (homEquiv X' Y).symm (f ≫ g) = F.map f ≫ (homEquiv X Y).symm g := by cat_disch /-- The property that describes how `homEquiv` transforms compositions `F X ⟶ Y ⟶ Y'` -/ homEquiv_naturality_right : ∀ {X Y Y'} (f : F.obj X ⟶ Y) (g : Y ⟶ Y'), (homEquiv X Y') (f ≫ g) = (homEquiv X Y) f ≫ G.map g := by cat_disch namespace CoreHomEquiv attribute [simp] homEquiv_naturality_left_symm homEquiv_naturality_right variable {F : C ⥤ D} {G : D ⥤ C} (adj : CoreHomEquiv F G) {X' X : C} {Y Y' : D} theorem homEquiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) : (adj.homEquiv X' Y) (F.map f ≫ g) = f ≫ (adj.homEquiv X Y) g := by rw [← Equiv.eq_symm_apply]; simp theorem homEquiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (adj.homEquiv X Y').symm (f ≫ G.map g) = (adj.homEquiv X Y).symm f ≫ g := by rw [Equiv.symm_apply_eq]; simp end CoreHomEquiv /-- This is an auxiliary data structure useful for constructing adjunctions. See `Adjunction.mkOfUnitCounit`. This structure won't typically be used anywhere else. -/ structure CoreUnitCounit (F : C ⥤ D) (G : D ⥤ C) where /-- The unit of an adjunction between `F` and `G` -/ unit : 𝟭 C ⟶ F.comp G /-- The counit of an adjunction between `F` and `G`s -/ counit : G.comp F ⟶ 𝟭 D /-- Equality of the composition of the unit, associator, and counit with the identity `F ⟶ (F G) F ⟶ F (G F) ⟶ F = NatTrans.id F` -/ left_triangle : whiskerRight unit F ≫ (associator F G F).hom ≫ whiskerLeft F counit = NatTrans.id (𝟭 C ⋙ F) := by cat_disch /-- Equality of the composition of the unit, associator, and counit with the identity `G ⟶ G (F G) ⟶ (F G) F ⟶ G = NatTrans.id G` -/ right_triangle : whiskerLeft G unit ≫ (associator G F G).inv ≫ whiskerRight counit G = NatTrans.id (G ⋙ 𝟭 C) := by cat_disch namespace CoreUnitCounit attribute [simp] left_triangle right_triangle end CoreUnitCounit variable {F : C ⥤ D} {G : D ⥤ C} attribute [local simp] CoreHomEquivUnitCounit.homEquiv_unit CoreHomEquivUnitCounit.homEquiv_counit /-- Construct an adjunction from the data of a `CoreHomEquivUnitCounit`, i.e. a hom set equivalence, unit and counit natural transformations together with proofs of the equalities `homEquiv_unit` and `homEquiv_counit` relating them to each other. -/ @[simps] def mk' (adj : CoreHomEquivUnitCounit F G) : F ⊣ G where unit := adj.unit counit := adj.counit left_triangle_components X := by rw [← adj.homEquiv_counit, (adj.homEquiv _ _).symm_apply_eq, adj.homEquiv_unit] simp right_triangle_components Y := by rw [← adj.homEquiv_unit, ← (adj.homEquiv _ _).eq_symm_apply, adj.homEquiv_counit] simp lemma mk'_homEquiv (adj : CoreHomEquivUnitCounit F G) : (mk' adj).homEquiv = adj.homEquiv := by ext rw [homEquiv_unit, adj.homEquiv_unit, mk'_unit] /-- Construct an adjunction between `F` and `G` out of a natural bijection between each `F.obj X ⟶ Y` and `X ⟶ G.obj Y`. -/ @[simps!] def mkOfHomEquiv (adj : CoreHomEquiv F G) : F ⊣ G := mk' { unit := { app := fun X => (adj.homEquiv X (F.obj X)) (𝟙 (F.obj X)) naturality := by intros simp [← adj.homEquiv_naturality_left, ← adj.homEquiv_naturality_right] } counit := { app := fun Y => (adj.homEquiv _ _).invFun (𝟙 (G.obj Y)) naturality := by intros simp [← adj.homEquiv_naturality_left_symm, ← adj.homEquiv_naturality_right_symm] } homEquiv := adj.homEquiv homEquiv_unit := fun {X Y f} => by simp [← adj.homEquiv_naturality_right] homEquiv_counit := fun {X Y f} => by simp [← adj.homEquiv_naturality_left_symm] } @[simp] lemma mkOfHomEquiv_homEquiv (adj : CoreHomEquiv F G) : (mkOfHomEquiv adj).homEquiv = adj.homEquiv := by ext X Y g simp [mkOfHomEquiv, ← adj.homEquiv_naturality_right (𝟙 _) g] /-- Construct an adjunction between functors `F` and `G` given a unit and counit for the adjunction satisfying the triangle identities. -/ @[simps!] def mkOfUnitCounit (adj : CoreUnitCounit F G) : F ⊣ G where unit := adj.unit counit := adj.counit left_triangle_components X := by have := adj.left_triangle rw [NatTrans.ext_iff, funext_iff] at this simpa [-CoreUnitCounit.left_triangle] using this X right_triangle_components Y := by have := adj.right_triangle rw [NatTrans.ext_iff, funext_iff] at this simpa [-CoreUnitCounit.right_triangle] using this Y /-- The adjunction between the identity functor on a category and itself. -/ def id : 𝟭 C ⊣ 𝟭 C where unit := 𝟙 _ counit := 𝟙 _ -- Satisfy the inhabited linter. instance : Inhabited (Adjunction (𝟭 C) (𝟭 C)) := ⟨id⟩ /-- If F and G are naturally isomorphic functors, establish an equivalence of hom-sets. -/ @[simps] def equivHomsetLeftOfNatIso {F F' : C ⥤ D} (iso : F ≅ F') {X : C} {Y : D} : (F.obj X ⟶ Y) ≃ (F'.obj X ⟶ Y) where toFun f := iso.inv.app _ ≫ f invFun g := iso.hom.app _ ≫ g left_inv f := by simp right_inv g := by simp /-- If G and H are naturally isomorphic functors, establish an equivalence of hom-sets. -/ @[simps] def equivHomsetRightOfNatIso {G G' : D ⥤ C} (iso : G ≅ G') {X : C} {Y : D} : (X ⟶ G.obj Y) ≃ (X ⟶ G'.obj Y) where toFun f := f ≫ iso.hom.app _ invFun g := g ≫ iso.inv.app _ left_inv f := by simp right_inv g := by simp /-- Transport an adjunction along a natural isomorphism on the left. -/ def ofNatIsoLeft {F G : C ⥤ D} {H : D ⥤ C} (adj : F ⊣ H) (iso : F ≅ G) : G ⊣ H := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => (equivHomsetLeftOfNatIso iso.symm).trans (adj.homEquiv X Y) } /-- Transport an adjunction along a natural isomorphism on the right. -/ def ofNatIsoRight {F : C ⥤ D} {G H : D ⥤ C} (adj : F ⊣ G) (iso : G ≅ H) : F ⊣ H := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => (adj.homEquiv X Y).trans (equivHomsetRightOfNatIso iso) } /-- The isomorpism which an adjunction `F ⊣ G` induces on `G ⋙ yoneda`. This states that `Adjunction.homEquiv` is natural in both arguments. -/ @[simps!] def compYonedaIso {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₁} D] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) : G ⋙ yoneda ≅ yoneda ⋙ (whiskeringLeft _ _ _).obj F.op := NatIso.ofComponents fun X => NatIso.ofComponents fun Y => (adj.homEquiv Y.unop X).toIso.symm /-- The isomorpism which an adjunction `F ⊣ G` induces on `F.op ⋙ coyoneda`. This states that `Adjunction.homEquiv` is natural in both arguments. -/ @[simps!] def compCoyonedaIso {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₁} D] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) : F.op ⋙ coyoneda ≅ coyoneda ⋙ (whiskeringLeft _ _ _).obj G := NatIso.ofComponents fun X => NatIso.ofComponents fun Y => (adj.homEquiv X.unop Y).toIso section variable {E : Type u₃} [ℰ : Category.{v₃} E] {H : D ⥤ E} {I : E ⥤ D} (adj₁ : F ⊣ G) (adj₂ : H ⊣ I) /-- Composition of adjunctions. -/ @[simps! -isSimp unit counit, stacks 0DV0] def comp : F ⋙ H ⊣ I ⋙ G := mk' { homEquiv := fun _ _ ↦ Equiv.trans (adj₂.homEquiv _ _) (adj₁.homEquiv _ _) unit := adj₁.unit ≫ whiskerRight (F.rightUnitor.inv ≫ whiskerLeft F adj₂.unit ≫ (associator _ _ _ ).inv) G ≫ (associator _ _ _).hom counit := (associator _ _ _ ).inv ≫ whiskerRight ((associator _ _ _ ).hom ≫ whiskerLeft _ adj₁.counit ≫ I.rightUnitor.hom) _ ≫ adj₂.counit } @[simp, reassoc] lemma comp_unit_app (X : C) : (adj₁.comp adj₂).unit.app X = adj₁.unit.app X ≫ G.map (adj₂.unit.app (F.obj X)) := by simp [Adjunction.comp] @[simp, reassoc] lemma comp_counit_app (X : E) : (adj₁.comp adj₂).counit.app X = H.map (adj₁.counit.app (I.obj X)) ≫ adj₂.counit.app X := by simp [Adjunction.comp] lemma comp_homEquiv : (adj₁.comp adj₂).homEquiv = fun _ _ ↦ Equiv.trans (adj₂.homEquiv _ _) (adj₁.homEquiv _ _) := mk'_homEquiv _ end section ConstructLeft -- Construction of a left adjoint. In order to construct a left -- adjoint to a functor G : D → C, it suffices to give the object part -- of a functor F : C → D together with isomorphisms Hom(FX, Y) ≃ -- Hom(X, GY) natural in Y. The action of F on morphisms can be -- constructed from this data. variable {F_obj : C → D} variable (e : ∀ X Y, (F_obj X ⟶ Y) ≃ (X ⟶ G.obj Y)) /-- Construct a left adjoint functor to `G`, given the functor's value on objects `F_obj` and a bijection `e` between `F_obj X ⟶ Y` and `X ⟶ G.obj Y` satisfying a naturality law `he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g`. Dual to `rightAdjointOfEquiv`. -/ @[simps!] def leftAdjointOfEquiv (he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g) : C ⥤ D where obj := F_obj map {X} {X'} f := (e X (F_obj X')).symm (f ≫ e X' (F_obj X') (𝟙 _)) map_comp := fun f f' => by rw [Equiv.symm_apply_eq, he, Equiv.apply_symm_apply] conv => rhs rw [assoc, ← he, id_comp, Equiv.apply_symm_apply] simp variable (he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g) /-- Show that the functor given by `leftAdjointOfEquiv` is indeed left adjoint to `G`. Dual to `adjunctionOfRightEquiv`. -/ @[simps!] def adjunctionOfEquivLeft : leftAdjointOfEquiv e he ⊣ G := mkOfHomEquiv { homEquiv := e homEquiv_naturality_left_symm := fun {X'} {X} {Y} f g => by have {X : C} {Y Y' : D} (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (e X Y').symm (f ≫ G.map g) = (e X Y).symm f ≫ g := by rw [Equiv.symm_apply_eq, he]; simp simp [← this, ← he] } end ConstructLeft section ConstructRight -- Construction of a right adjoint, analogous to the above. variable {G_obj : D → C} variable (e : ∀ X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G_obj Y)) private theorem he'' (he : ∀ X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g) {X' X Y} (f g) : F.map f ≫ (e X Y).symm g = (e X' Y).symm (f ≫ g) := by rw [Equiv.eq_symm_apply, he]; simp /-- Construct a right adjoint functor to `F`, given the functor's value on objects `G_obj` and a bijection `e` between `F.obj X ⟶ Y` and `X ⟶ G_obj Y` satisfying a naturality law `he : ∀ X Y Y' g h, e X' Y (F.map f ≫ g) = f ≫ e X Y g`. Dual to `leftAdjointOfEquiv`. -/ @[simps!] def rightAdjointOfEquiv (he : ∀ X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g) : D ⥤ C where obj := G_obj map {Y} {Y'} g := (e (G_obj Y) Y') ((e (G_obj Y) Y).symm (𝟙 _) ≫ g) map_comp := fun {Y} {Y'} {Y''} g g' => by rw [← Equiv.eq_symm_apply, ← he'' e he, Equiv.symm_apply_apply] conv => rhs rw [← assoc, he'' e he, comp_id, Equiv.symm_apply_apply] simp /-- Show that the functor given by `rightAdjointOfEquiv` is indeed right adjoint to `F`. Dual to `adjunctionOfEquivRight`. -/ @[simps!] def adjunctionOfEquivRight (he : ∀ X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g) : F ⊣ (rightAdjointOfEquiv e he) := mkOfHomEquiv { homEquiv := e homEquiv_naturality_left_symm := by intro X X' Y f g; rw [Equiv.symm_apply_eq]; simp [he] homEquiv_naturality_right := by intro X Y Y' g h simp [← he, reassoc_of% (he'' e)] } end ConstructRight /-- If the unit and counit of a given adjunction are (pointwise) isomorphisms, then we can upgrade the adjunction to an equivalence. -/ @[simps!] noncomputable def toEquivalence (adj : F ⊣ G) [∀ X, IsIso (adj.unit.app X)] [∀ Y, IsIso (adj.counit.app Y)] : C ≌ D where functor := F inverse := G unitIso := NatIso.ofComponents fun X => asIso (adj.unit.app X) counitIso := NatIso.ofComponents fun Y => asIso (adj.counit.app Y) end Adjunction open Adjunction /-- If the unit and counit for the adjunction corresponding to a right adjoint functor are (pointwise) isomorphisms, then the functor is an equivalence of categories. -/ lemma Functor.isEquivalence_of_isRightAdjoint (G : C ⥤ D) [IsRightAdjoint G] [∀ X, IsIso ((Adjunction.ofIsRightAdjoint G).unit.app X)] [∀ Y, IsIso ((Adjunction.ofIsRightAdjoint G).counit.app Y)] : G.IsEquivalence := (Adjunction.ofIsRightAdjoint G).toEquivalence.isEquivalence_inverse namespace Equivalence variable (e : C ≌ D) /-- The adjunction given by an equivalence of categories. (To obtain the opposite adjunction, simply use `e.symm.toAdjunction`. -/ @[simps] def toAdjunction : e.functor ⊣ e.inverse where unit := e.unit counit := e.counit lemma isLeftAdjoint_functor : e.functor.IsLeftAdjoint where exists_rightAdjoint := ⟨_, ⟨e.toAdjunction⟩⟩ lemma isRightAdjoint_inverse : e.inverse.IsRightAdjoint where exists_leftAdjoint := ⟨_, ⟨e.toAdjunction⟩⟩ lemma isLeftAdjoint_inverse : e.inverse.IsLeftAdjoint := e.symm.isLeftAdjoint_functor lemma isRightAdjoint_functor : e.functor.IsRightAdjoint := e.symm.isRightAdjoint_inverse lemma refl_toAdjunction : (refl (C := C)).toAdjunction = Adjunction.id := rfl lemma trans_toAdjunction {E : Type*} [Category E] (e' : D ≌ E) : (e.trans e').toAdjunction = e.toAdjunction.comp e'.toAdjunction := rfl end Equivalence namespace Functor /-- If `F` and `G` are left adjoints then `F ⋙ G` is a left adjoint too. -/ instance isLeftAdjoint_comp {E : Type u₃} [Category.{v₃} E] (F : C ⥤ D) (G : D ⥤ E) [F.IsLeftAdjoint] [G.IsLeftAdjoint] : (F ⋙ G).IsLeftAdjoint where exists_rightAdjoint := ⟨_, ⟨(Adjunction.ofIsLeftAdjoint F).comp (Adjunction.ofIsLeftAdjoint G)⟩⟩ /-- If `F` and `G` are right adjoints then `F ⋙ G` is a right adjoint too. -/ instance isRightAdjoint_comp {E : Type u₃} [Category.{v₃} E] {F : C ⥤ D} {G : D ⥤ E} [IsRightAdjoint F] [IsRightAdjoint G] : IsRightAdjoint (F ⋙ G) where exists_leftAdjoint := ⟨_, ⟨(Adjunction.ofIsRightAdjoint G).comp (Adjunction.ofIsRightAdjoint F)⟩⟩ /-- Transport being a right adjoint along a natural isomorphism. -/ lemma isRightAdjoint_of_iso {F G : C ⥤ D} (h : F ≅ G) [F.IsRightAdjoint] : IsRightAdjoint G where exists_leftAdjoint := ⟨_, ⟨(Adjunction.ofIsRightAdjoint F).ofNatIsoRight h⟩⟩ /-- Transport being a left adjoint along a natural isomorphism. -/ lemma isLeftAdjoint_of_iso {F G : C ⥤ D} (h : F ≅ G) [IsLeftAdjoint F] : IsLeftAdjoint G where exists_rightAdjoint := ⟨_, ⟨(Adjunction.ofIsLeftAdjoint F).ofNatIsoLeft h⟩⟩ /-- An equivalence `E` is left adjoint to its inverse. -/ noncomputable def adjunction (E : C ⥤ D) [IsEquivalence E] : E ⊣ E.inv := E.asEquivalence.toAdjunction /-- If `F` is an equivalence, it's a left adjoint. -/ instance (priority := 10) isLeftAdjoint_of_isEquivalence {F : C ⥤ D} [F.IsEquivalence] : IsLeftAdjoint F := F.asEquivalence.isLeftAdjoint_functor /-- If `F` is an equivalence, it's a right adjoint. -/ instance (priority := 10) isRightAdjoint_of_isEquivalence {F : C ⥤ D} [F.IsEquivalence] : IsRightAdjoint F := F.asEquivalence.isRightAdjoint_functor end Functor end CategoryTheory
Basic.lean
/- Copyright (c) 2024 Frédéric Marbach. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Marbach -/ import Mathlib.Algebra.Lie.NonUnitalNonAssocAlgebra import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.Subalgebra import Mathlib.RingTheory.Nilpotent.Exp import Mathlib.RingTheory.Noetherian.Basic /-! # Lie derivations This file defines *Lie derivations* and establishes some basic properties. ## Main definitions - `LieDerivation`: A Lie derivation `D` from the Lie `R`-algebra `L` to the `L`-module `M` is an `R`-linear map that satisfies the Leibniz rule `D [a, b] = [a, D b] - [b, D a]`. - `LieDerivation.inner`: The natural map from a Lie module to the derivations taking values in it. ## Main statements - `LieDerivation.eqOn_lieSpan`: two Lie derivations equal on a set are equal on its Lie span. - `LieDerivation.instLieAlgebra`: the set of Lie derivations from a Lie algebra to itself is a Lie algebra. ## Implementation notes - Mathematically, a Lie derivation is just a derivation on a Lie algebra. However, the current implementation of `RingTheory.Derivation` requires a commutative associative algebra, so is incompatible with the setting of Lie algebras. Initially, this file is a copy-pasted adaptation of the `RingTheory.Derivation.Basic.lean` file. - Since we don't have right actions of Lie algebras, the second term in the Leibniz rule is written as `- [b, D a]`. Within Lie algebras, skew symmetry restores the expected definition `[D a, b]`. -/ /-- A Lie derivation `D` from the Lie `R`-algebra `L` to the `L`-module `M` is an `R`-linear map that satisfies the Leibniz rule `D [a, b] = [a, D b] - [b, D a]`. -/ structure LieDerivation (R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] extends L →ₗ[R] M where protected leibniz' (a b : L) : toLinearMap ⁅a, b⁆ = ⁅a, toLinearMap b⁆ - ⁅b, toLinearMap a⁆ /-- The `LinearMap` underlying a `LieDerivation`. -/ add_decl_doc LieDerivation.toLinearMap namespace LieDerivation section variable {R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable (D : LieDerivation R L M) {D1 D2 : LieDerivation R L M} (a b : L) instance : FunLike (LieDerivation R L M) L M where coe D := D.toFun coe_injective' D1 D2 h := by cases D1; cases D2; congr; exact DFunLike.coe_injective h instance instLinearMapClass : LinearMapClass (LieDerivation R L M) R L M where map_add D := D.toLinearMap.map_add' map_smulₛₗ D := D.toLinearMap.map_smul theorem toFun_eq_coe : D.toFun = ⇑D := rfl /-- See Note [custom simps projection] -/ def Simps.apply (D : LieDerivation R L M) : L → M := D initialize_simps_projections LieDerivation (toFun → apply) attribute [coe] toLinearMap instance instCoeToLinearMap : Coe (LieDerivation R L M) (L →ₗ[R] M) := ⟨fun D => D.toLinearMap⟩ @[simp] theorem mk_coe (f : L →ₗ[R] M) (h₁) : ((⟨f, h₁⟩ : LieDerivation R L M) : L → M) = f := rfl @[simp, norm_cast] theorem coeFn_coe (f : LieDerivation R L M) : ⇑(f : L →ₗ[R] M) = f := rfl theorem coe_injective : @Function.Injective (LieDerivation R L M) (L → M) DFunLike.coe := DFunLike.coe_injective @[ext] theorem ext (H : ∀ a, D1 a = D2 a) : D1 = D2 := DFunLike.ext _ _ H theorem congr_fun (h : D1 = D2) (a : L) : D1 a = D2 a := DFunLike.congr_fun h a @[simp] lemma apply_lie_eq_sub (D : LieDerivation R L M) (a b : L) : D ⁅a, b⁆ = ⁅a, D b⁆ - ⁅b, D a⁆ := D.leibniz' a b /-- For a Lie derivation from a Lie algebra to itself, the usual Leibniz rule holds. -/ lemma apply_lie_eq_add (D : LieDerivation R L L) (a b : L) : D ⁅a, b⁆ = ⁅a, D b⁆ + ⁅D a, b⁆ := by rw [LieDerivation.apply_lie_eq_sub, sub_eq_add_neg, lie_skew] /-- Two Lie derivations equal on a set are equal on its Lie span. -/ theorem eqOn_lieSpan {s : Set L} (h : Set.EqOn D1 D2 s) : Set.EqOn D1 D2 (LieSubalgebra.lieSpan R L s) := by intro _ hx induction hx using LieSubalgebra.lieSpan_induction with | mem x hx => exact h hx | zero => simp | add x y _ _ hx hy => simp [hx, hy] | smul t x _ hx => simp [hx] | lie x y _ _ hx hy => simp [hx, hy] /-- If the Lie span of a set is the whole Lie algebra, then two Lie derivations equal on this set are equal on the whole Lie algebra. -/ theorem ext_of_lieSpan_eq_top (s : Set L) (hs : LieSubalgebra.lieSpan R L s = ⊤) (h : Set.EqOn D1 D2 s) : D1 = D2 := ext fun _ => eqOn_lieSpan h <| hs.symm ▸ trivial section open Finset Nat /-- The general Leibniz rule for Lie derivatives. -/ theorem iterate_apply_lie (D : LieDerivation R L L) (n : ℕ) (a b : L) : D^[n] ⁅a, b⁆ = ∑ ij ∈ antidiagonal n, choose n ij.1 • ⁅D^[ij.1] a, D^[ij.2] b⁆ := by induction n with | zero => simp | succ n ih => rw [sum_antidiagonal_choose_succ_nsmul (M := L) (fun i j => ⁅D^[i] a, D^[j] b⁆) n] simp only [Function.iterate_succ_apply', ih, map_sum, map_nsmul, apply_lie_eq_add, smul_add, sum_add_distrib, add_right_inj] refine sum_congr rfl fun ⟨i, j⟩ hij ↦ ?_ rw [n.choose_symm_of_eq_add (mem_antidiagonal.1 hij).symm] /-- Alternate version of the general Leibniz rule for Lie derivatives. -/ theorem iterate_apply_lie' (D : LieDerivation R L L) (n : ℕ) (a b : L) : D^[n] ⁅a, b⁆ = ∑ i ∈ range (n + 1), n.choose i • ⁅D^[i] a, D^[n - i] b⁆ := by rw [iterate_apply_lie D n a b] exact sum_antidiagonal_eq_sum_range_succ (fun i j ↦ n.choose i • ⁅D^[i] a, D^[j] b⁆) n end instance instZero : Zero (LieDerivation R L M) where zero := { toLinearMap := 0 leibniz' := fun a b => by simp only [LinearMap.zero_apply, lie_zero, sub_self] } @[simp] theorem coe_zero : ⇑(0 : LieDerivation R L M) = 0 := rfl @[simp] theorem coe_zero_linearMap : ↑(0 : LieDerivation R L M) = (0 : L →ₗ[R] M) := rfl theorem zero_apply (a : L) : (0 : LieDerivation R L M) a = 0 := rfl instance : Inhabited (LieDerivation R L M) := ⟨0⟩ instance instAdd : Add (LieDerivation R L M) where add D1 D2 := { toLinearMap := D1 + D2 leibniz' := fun a b ↦ by simp only [LinearMap.add_apply, coeFn_coe, apply_lie_eq_sub, lie_add, add_sub_add_comm] } @[simp] theorem coe_add (D1 D2 : LieDerivation R L M) : ⇑(D1 + D2) = D1 + D2 := rfl @[simp] theorem coe_add_linearMap (D1 D2 : LieDerivation R L M) : ↑(D1 + D2) = (D1 + D2 : L →ₗ[R] M) := rfl theorem add_apply : (D1 + D2) a = D1 a + D2 a := rfl protected theorem map_neg : D (-a) = -D a := map_neg D a protected theorem map_sub : D (a - b) = D a - D b := map_sub D a b instance instNeg : Neg (LieDerivation R L M) := ⟨fun D => mk (-D) fun a b => by simp only [LinearMap.neg_apply, coeFn_coe, apply_lie_eq_sub, neg_sub, lie_neg, sub_neg_eq_add, add_comm, ← sub_eq_add_neg] ⟩ @[simp] theorem coe_neg (D : LieDerivation R L M) : ⇑(-D) = -D := rfl @[simp] theorem coe_neg_linearMap (D : LieDerivation R L M) : ↑(-D) = (-D : L →ₗ[R] M) := rfl theorem neg_apply : (-D) a = -D a := rfl instance instSub : Sub (LieDerivation R L M) := ⟨fun D1 D2 => mk (D1 - D2 : L →ₗ[R] M) fun a b => by simp only [LinearMap.sub_apply, coeFn_coe, apply_lie_eq_sub, lie_sub, sub_sub_sub_comm]⟩ @[simp] theorem coe_sub (D1 D2 : LieDerivation R L M) : ⇑(D1 - D2) = D1 - D2 := rfl @[simp] theorem coe_sub_linearMap (D1 D2 : LieDerivation R L M) : ↑(D1 - D2) = (D1 - D2 : L →ₗ[R] M) := rfl theorem sub_apply {D1 D2 : LieDerivation R L M} : (D1 - D2) a = D1 a - D2 a := rfl section Scalar /-- A typeclass mixin saying that scalar multiplication and Lie bracket are left commutative. -/ class SMulBracketCommClass (S L α : Type*) [SMul S α] [LieRing L] [AddCommGroup α] [LieRingModule L α] : Prop where /-- `•` and `⁅⬝, ⬝⁆` are left commutative -/ smul_bracket_comm : ∀ (s : S) (l : L) (a : α), s • ⁅l, a⁆ = ⁅l, s • a⁆ variable {S T : Type*} variable [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] [SMulBracketCommClass S L M] variable [Monoid T] [DistribMulAction T M] [SMulCommClass R T M] [SMulBracketCommClass T L M] instance instSMul : SMul S (LieDerivation R L M) where smul r D := { toLinearMap := r • D leibniz' := fun a b => by simp only [LinearMap.smul_apply, coeFn_coe, apply_lie_eq_sub, smul_sub, SMulBracketCommClass.smul_bracket_comm] } @[simp] theorem coe_smul (r : S) (D : LieDerivation R L M) : ⇑(r • D) = r • ⇑D := rfl @[simp] theorem coe_smul_linearMap (r : S) (D : LieDerivation R L M) : ↑(r • D) = r • (D : L →ₗ[R] M) := rfl theorem smul_apply (r : S) (D : LieDerivation R L M) : (r • D) a = r • D a := rfl instance instSMulBase : SMulBracketCommClass R L M := ⟨fun s l a ↦ (lie_smul s l a).symm⟩ instance instSMulNat : SMulBracketCommClass ℕ L M := ⟨fun s l a => (lie_nsmul l a s).symm⟩ instance instSMulInt : SMulBracketCommClass ℤ L M := ⟨fun s l a => (lie_zsmul l a s).symm⟩ instance instAddCommGroup : AddCommGroup (LieDerivation R L M) := coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => rfl) fun _ _ => rfl /-- `coe_fn` as an `AddMonoidHom`. -/ def coeFnAddMonoidHom : LieDerivation R L M →+ L → M where toFun := (↑) map_zero' := coe_zero map_add' := coe_add @[simp] lemma coeFnAddMonoidHom_apply (D : LieDerivation R L M) : coeFnAddMonoidHom D = D := rfl instance : DistribMulAction S (LieDerivation R L M) := Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective coe_smul instance [SMul S T] [IsScalarTower S T M] : IsScalarTower S T (LieDerivation R L M) := ⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩ instance [SMulCommClass S T M] : SMulCommClass S T (LieDerivation R L M) := ⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩ end Scalar instance instModule {S : Type*} [Semiring S] [Module S M] [SMulCommClass R S M] [SMulBracketCommClass S L M] : Module S (LieDerivation R L M) := Function.Injective.module S coeFnAddMonoidHom coe_injective coe_smul end section variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] /-- The commutator of two Lie derivations on a Lie algebra is a Lie derivation. -/ instance instBracket : Bracket (LieDerivation R L L) (LieDerivation R L L) where bracket D1 D2 := LieDerivation.mk ⁅(D1 : Module.End R L), (D2 : Module.End R L)⁆ (fun a b => by simp only [Ring.lie_def, apply_lie_eq_add, coeFn_coe, LinearMap.sub_apply, Module.End.mul_apply, map_add, sub_lie, lie_sub, ← lie_skew b] abel) variable {D1 D2 : LieDerivation R L L} @[simp] lemma commutator_coe_linear_map : ↑⁅D1, D2⁆ = ⁅(D1 : Module.End R L), (D2 : Module.End R L)⁆ := rfl lemma commutator_apply (a : L) : ⁅D1, D2⁆ a = D1 (D2 a) - D2 (D1 a) := rfl instance : LieRing (LieDerivation R L L) where add_lie d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; abel lie_add d e f := by ext a; simp only [commutator_apply, add_apply, map_add]; abel lie_self d := by ext a; simp only [commutator_apply, zero_apply]; abel leibniz_lie d e f := by ext a; simp only [commutator_apply, add_apply, map_sub]; abel /-- The set of Lie derivations from a Lie algebra `L` to itself is a Lie algebra. -/ instance instLieAlgebra : LieAlgebra R (LieDerivation R L L) where lie_smul := fun r d e => by ext a; simp only [commutator_apply, map_smul, smul_sub, smul_apply] @[simp] lemma lie_apply (D₁ D₂ : LieDerivation R L L) (x : L) : ⁅D₁, D₂⁆ x = D₁ (D₂ x) - D₂ (D₁ x) := rfl end section variable (R L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] /-- The Lie algebra morphism from Lie derivations into linear endormophisms. -/ def toLinearMapLieHom : LieDerivation R L L →ₗ⁅R⁆ L →ₗ[R] L where toFun := toLinearMap map_add' := by intro D1 D2; dsimp map_smul' := by intro D1 D2; dsimp map_lie' := by intro D1 D2; dsimp /-- The map from Lie derivations to linear endormophisms is injective. -/ lemma toLinearMapLieHom_injective : Function.Injective (toLinearMapLieHom R L) := fun _ _ h ↦ ext fun a ↦ congrFun (congrArg DFunLike.coe h) a /-- Lie derivations over a Noetherian Lie algebra form a Noetherian module. -/ instance instNoetherian [IsNoetherian R L] : IsNoetherian R (LieDerivation R L L) := isNoetherian_of_linearEquiv (LinearEquiv.ofInjective _ (toLinearMapLieHom_injective R L)).symm end section Inner variable (R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] /-- The natural map from a Lie module to the derivations taking values in it. -/ @[simps!] def inner : M →ₗ[R] LieDerivation R L M where toFun m := { __ := (LieModule.toEnd R L M : L →ₗ[R] Module.End R M).flip m leibniz' := by simp } map_add' m n := by ext; simp map_smul' t m := by ext; simp instance instLieRingModule : LieRingModule L (LieDerivation R L M) where bracket x D := inner R L M (D x) add_lie x y D := by simp lie_add x D₁ D₂ := by simp leibniz_lie x y D := by simp @[simp] lemma lie_lieDerivation_apply (x y : L) (D : LieDerivation R L M) : ⁅x, D⁆ y = ⁅y, D x⁆ := rfl @[simp] lemma lie_coe_lieDerivation_apply (x : L) (D : LieDerivation R L M) : ⁅x, (D : L →ₗ[R] M)⁆ = ⁅x, D⁆ := by ext; simp instance instLieModule : LieModule R L (LieDerivation R L M) where smul_lie t x D := by ext; simp lie_smul t x D := by ext; simp protected lemma leibniz_lie (x : L) (D₁ D₂ : LieDerivation R L L) : ⁅x, ⁅D₁, D₂⁆⁆ = ⁅⁅x, D₁⁆, D₂⁆ + ⁅D₁, ⁅x, D₂⁆⁆ := by ext y simp [-lie_skew, ← lie_skew (D₁ x) (D₂ y), ← lie_skew (D₂ x) (D₁ y), sub_eq_neg_add] end Inner section ExpNilpotent variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [LieAlgebra ℚ L] (D : LieDerivation R L L) /-- In characteristic zero, the exponential of a nilpotent derivation is a Lie algebra automorphism. -/ noncomputable def exp (h : IsNilpotent D.toLinearMap) : L ≃ₗ⁅R⁆ L := { toLinearMap := IsNilpotent.exp D.toLinearMap map_lie' := by let _i := LieRing.toNonUnitalNonAssocRing L have : SMulCommClass R L L := LieAlgebra.smulCommClass R L have : IsScalarTower R L L := LieAlgebra.isScalarTower R L exact Module.End.exp_mul_of_derivation R L D.toLinearMap D.apply_lie_eq_add h invFun x := IsNilpotent.exp (- D.toLinearMap) x left_inv x := by simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, ← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.exp_neg_mul_exp_self, Module.End.one_apply] right_inv x := by simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, ← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.exp_mul_exp_neg_self, Module.End.one_apply] } lemma exp_apply (h : IsNilpotent D.toLinearMap) : exp D h = IsNilpotent.exp D.toLinearMap := rfl lemma exp_map_apply (h : IsNilpotent D.toLinearMap) (l : L) : exp D h l = IsNilpotent.exp D.toLinearMap l := DFunLike.congr_fun (exp_apply D h) l end ExpNilpotent end LieDerivation
vcharacter.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime order. From mathcomp Require Import ssralg poly finset fingroup morphism perm. From mathcomp Require Import automorphism quotient finalg action gproduct. From mathcomp Require Import zmodp commutator cyclic center pgroup sylow. From mathcomp Require Import frobenius vector ssrnum ssrint archimedean intdiv. From mathcomp Require Import algC algnum classfun character integral_char. (******************************************************************************) (* This file provides basic notions of virtual character theory: *) (* 'Z[S, A] == collective predicate for the phi that are Z-linear *) (* combinations of elements of S : seq 'CF(G) and have *) (* support in A : {set gT}. *) (* 'Z[S] == collective predicate for the Z-linear combinations of *) (* elements of S. *) (* 'Z[irr G] == the collective predicate for virtual characters. *) (* dirr G == the collective predicate for normal virtual characters, *) (* i.e., virtual characters of norm 1: *) (* mu \in dirr G <=> m \in 'Z[irr G] and '[mu] = 1 *) (* <=> mu or - mu \in irr G. *) (* --> othonormal subsets of 'Z[irr G] are contained in dirr G. *) (* dIirr G == an index type for normal virtual characters. *) (* dchi i == the normal virtual character of index i. *) (* of_irr i == the (unique) irreducible constituent of dchi i: *) (* dchi i = 'chi_(of_irr i) or - 'chi_(of_irr i). *) (* ndirr i == the index of - dchi i. *) (* dirr1 G == the normal virtual character index of 1 : 'CF(G), the *) (* principal character. *) (* dirr_dIirr j f == the index i (or dirr1 G if it does not exist) such that *) (* dchi i = f j. *) (* dirr_constt phi == the normal virtual character constituents of phi: *) (* i \in dirr_constt phi <=> [dchi i, phi] > 0. *) (* to_dirr phi i == the normal virtual character constituent of phi with an *) (* irreducible constituent i, when i \in irr_constt phi. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. Section Basics. Variables (gT : finGroupType) (B : {set gT}) (S : seq 'CF(B)) (A : {set gT}). Definition Zchar : {pred 'CF(B)} := [pred phi in 'CF(B, A) | dec_Cint_span (in_tuple S) phi]. Lemma cfun0_zchar : 0 \in Zchar. Proof. rewrite inE mem0v; apply/sumboolP; exists 0. by rewrite big1 // => i _; rewrite ffunE. Qed. Fact Zchar_zmod : zmod_closed Zchar. Proof. split; first exact: cfun0_zchar. move=> phi xi /andP[Aphi /sumboolP[a Da]] /andP[Axi /sumboolP[b Db]]. rewrite inE rpredB // Da Db -sumrB; apply/sumboolP; exists (a - b). by apply: eq_bigr => i _; rewrite -mulrzBr !ffunE. Qed. HB.instance Definition _ := GRing.isZmodClosed.Build (classfun B) Zchar Zchar_zmod. Lemma scale_zchar a phi : a \in Num.int -> phi \in Zchar -> a *: phi \in Zchar. Proof. by case/intrP=> m -> Zphi; rewrite scaler_int rpredMz. Qed. End Basics. Notation "''Z[' S , A ]" := (Zchar S A) (format "''Z[' S , A ]") : group_scope. Notation "''Z[' S ]" := 'Z[S, setT] (format "''Z[' S ]") : group_scope. Section Zchar. Variables (gT : finGroupType) (G : {group gT}). Implicit Types (A B : {set gT}) (S : seq 'CF(G)). Lemma zchar_split S A phi : phi \in 'Z[S, A] = (phi \in 'Z[S]) && (phi \in 'CF(G, A)). Proof. by rewrite !inE cfun_onT andbC. Qed. Lemma zcharD1E phi S : (phi \in 'Z[S, G^#]) = (phi \in 'Z[S]) && (phi 1%g == 0). Proof. by rewrite zchar_split cfunD1E. Qed. Lemma zcharD1 phi S A : (phi \in 'Z[S, A^#]) = (phi \in 'Z[S, A]) && (phi 1%g == 0). Proof. by rewrite zchar_split cfun_onD1 andbA -zchar_split. Qed. Lemma zcharW S A : {subset 'Z[S, A] <= 'Z[S]}. Proof. by move=> phi; rewrite zchar_split => /andP[]. Qed. Lemma zchar_on S A : {subset 'Z[S, A] <= 'CF(G, A)}. Proof. by move=> phi /andP[]. Qed. Lemma zchar_onS A B S : A \subset B -> {subset 'Z[S, A] <= 'Z[S, B]}. Proof. move=> sAB phi; rewrite zchar_split (zchar_split _ B) => /andP[->]. exact: cfun_onS. Qed. Lemma zchar_onG S : 'Z[S, G] =i 'Z[S]. Proof. by move=> phi; rewrite zchar_split cfun_onG andbT. Qed. Lemma irr_vchar_on A : {subset 'Z[irr G, A] <= 'CF(G, A)}. Proof. exact: zchar_on. Qed. Lemma support_zchar S A phi : phi \in 'Z[S, A] -> support phi \subset A. Proof. by move/zchar_on; rewrite cfun_onE. Qed. Lemma mem_zchar_on S A phi : phi \in 'CF(G, A) -> phi \in S -> phi \in 'Z[S, A]. Proof. move=> Aphi /(@tnthP _ _ (in_tuple S))[i Dphi]; rewrite inE /= {}Aphi {phi}Dphi. apply/sumboolP; exists [ffun j => (j == i)%:Z]. rewrite (bigD1 i) //= ffunE eqxx (tnth_nth 0) big1 ?addr0 // => j i'j. by rewrite ffunE (negPf i'j). Qed. (* A special lemma is needed because trivial fails to use the cfun_onT Hint. *) Lemma mem_zchar S phi : phi \in S -> phi \in 'Z[S]. Proof. by move=> Sphi; rewrite mem_zchar_on ?cfun_onT. Qed. Lemma zchar_nth_expansion S A phi : phi \in 'Z[S, A] -> {z | forall i, z i \in Num.int & phi = \sum_(i < size S) z i *: S`_i}. Proof. case/andP=> _ /sumboolP/sig_eqW[/= z ->]; exists (intr \o z) => //=. by apply: eq_bigr => i _; rewrite scaler_int. Qed. Lemma zchar_tuple_expansion n (S : n.-tuple 'CF(G)) A phi : phi \in 'Z[S, A] -> {z | forall i, z i \in Num.int & phi = \sum_(i < n) z i *: S`_i}. Proof. by move/zchar_nth_expansion; rewrite size_tuple. Qed. (* A pure seq version with the extra hypothesis of S's unicity. *) Lemma zchar_expansion S A phi : uniq S -> phi \in 'Z[S, A] -> {z | forall xi, z xi \in Num.int & phi = \sum_(xi <- S) z xi *: xi}. Proof. move=> Suniq /zchar_nth_expansion[z Zz ->] /=. pose zS xi := oapp z 0 (insub (index xi S)). exists zS => [xi | ]; rewrite {}/zS; first by case: (insub _) => /=. rewrite (big_nth 0) big_mkord; apply: eq_bigr => i _; congr (_ *: _). by rewrite index_uniq // valK. Qed. Lemma zchar_span S A : {subset 'Z[S, A] <= <<S>>%VS}. Proof. move=> _ /zchar_nth_expansion[z Zz ->] /=. by apply: rpred_sum => i _; rewrite rpredZ // memv_span ?mem_nth. Qed. Lemma zchar_trans S1 S2 A B : {subset S1 <= 'Z[S2, B]} -> {subset 'Z[S1, A] <= 'Z[S2, A]}. Proof. move=> sS12 phi; rewrite !(zchar_split _ A) andbC => /andP[->]; rewrite andbT. case/zchar_nth_expansion=> z Zz ->; apply: rpred_sum => i _. by rewrite scale_zchar // (@zcharW _ B) ?sS12 ?mem_nth. Qed. Lemma zchar_trans_on S1 S2 A : {subset S1 <= 'Z[S2, A]} -> {subset 'Z[S1] <= 'Z[S2, A]}. Proof. move=> sS12 _ /zchar_nth_expansion[z Zz ->]; apply: rpred_sum => i _. by rewrite scale_zchar // sS12 ?mem_nth. Qed. Lemma zchar_sub_irr S A : {subset S <= 'Z[irr G]} -> {subset 'Z[S, A] <= 'Z[irr G, A]}. Proof. exact: zchar_trans. Qed. Lemma zchar_subset S1 S2 A : {subset S1 <= S2} -> {subset 'Z[S1, A] <= 'Z[S2, A]}. Proof. move=> sS12; apply: zchar_trans setT _ => // f /sS12 S2f. by rewrite mem_zchar. Qed. Lemma zchar_subseq S1 S2 A : subseq S1 S2 -> {subset 'Z[S1, A] <= 'Z[S2, A]}. Proof. by move/mem_subseq; apply: zchar_subset. Qed. Lemma zchar_filter S A (p : pred 'CF(G)) : {subset 'Z[filter p S, A] <= 'Z[S, A]}. Proof. by apply: zchar_subset=> f; apply/mem_subseq/filter_subseq. Qed. End Zchar. Section VChar. Variables (gT : finGroupType) (G : {group gT}). Implicit Types (A B : {set gT}) (phi chi : 'CF(G)) (S : seq 'CF(G)). Lemma char_vchar chi : chi \is a character -> chi \in 'Z[irr G]. Proof. case/char_sum_irr=> r ->; apply: rpred_sum => i _. by rewrite mem_zchar ?mem_tnth. Qed. Lemma irr_vchar i : 'chi[G]_i \in 'Z[irr G]. Proof. exact/char_vchar/irr_char. Qed. Lemma cfun1_vchar : 1 \in 'Z[irr G]. Proof. by rewrite -irr0 irr_vchar. Qed. Lemma vcharP phi : reflect (exists2 chi1, chi1 \is a character & exists2 chi2, chi2 \is a character & phi = chi1 - chi2) (phi \in 'Z[irr G]). Proof. apply: (iffP idP) => [| [a Na [b Nb ->]]]; last by rewrite rpredB ?char_vchar. case/zchar_tuple_expansion=> z Zz ->; rewrite (bigID (fun i => 0 <= z i)) /=. set chi1 := \sum_(i | _) _; set nchi2 := \sum_(i | _) _. exists chi1; last exists (- nchi2); last by rewrite opprK. apply: rpred_sum => i zi_ge0; rewrite -tnth_nth rpredZ_nat ?irr_char //. by rewrite natrEint Zz. rewrite -sumrN rpred_sum // => i zi_lt0; rewrite -scaleNr -tnth_nth. rewrite rpredZ_nat ?irr_char // natrEint rpredN Zz oppr_ge0 ltW //. by rewrite real_ltNge ?Rreal_int. Qed. Lemma Aint_vchar phi x : phi \in 'Z[irr G] -> phi x \in Aint. Proof. case/vcharP=> [chi1 Nchi1 [chi2 Nchi2 ->]]. by rewrite !cfunE rpredB ?Aint_char. Qed. Lemma Cint_vchar1 phi : phi \in 'Z[irr G] -> phi 1%g \in Num.int. Proof. case/vcharP=> phi1 Nphi1 [phi2 Nphi2 ->]. by rewrite !cfunE rpredB // rpred_nat_num ?Cnat_char1. Qed. Lemma Cint_cfdot_vchar_irr i phi : phi \in 'Z[irr G] -> '[phi, 'chi_i] \in Num.int. Proof. case/vcharP=> chi1 Nchi1 [chi2 Nchi2 ->]. by rewrite cfdotBl rpredB // rpred_nat_num ?Cnat_cfdot_char_irr. Qed. Lemma cfdot_vchar_r phi psi : psi \in 'Z[irr G] -> '[phi, psi] = \sum_i '[phi, 'chi_i] * '[psi, 'chi_i]. Proof. move=> Zpsi; rewrite cfdot_sum_irr; apply: eq_bigr => i _; congr (_ * _). by rewrite aut_intr ?Cint_cfdot_vchar_irr. Qed. Lemma Cint_cfdot_vchar : {in 'Z[irr G] &, forall phi psi, '[phi, psi] \in Num.int}. Proof. move=> phi psi Zphi Zpsi; rewrite /= cfdot_vchar_r // rpred_sum // => k _. by rewrite rpredM ?Cint_cfdot_vchar_irr. Qed. Lemma Cnat_cfnorm_vchar : {in 'Z[irr G], forall phi, '[phi] \in Num.nat}. Proof. by move=> phi Zphi; rewrite /= natrEint cfnorm_ge0 Cint_cfdot_vchar. Qed. Fact vchar_mulr_closed : mulr_closed 'Z[irr G]. Proof. split; first exact: cfun1_vchar. move=> _ _ /vcharP[xi1 Nxi1 [xi2 Nxi2 ->]] /vcharP[xi3 Nxi3 [xi4 Nxi4 ->]]. by rewrite mulrBl !mulrBr !(rpredB, rpredD) // char_vchar ?rpredM. Qed. HB.instance Definition _ := GRing.isMulClosed.Build (classfun G) 'Z[irr G] vchar_mulr_closed. Lemma mul_vchar A : {in 'Z[irr G, A] &, forall phi psi, phi * psi \in 'Z[irr G, A]}. Proof. move=> phi psi; rewrite zchar_split => /andP[Zphi Aphi] /zcharW Zpsi. rewrite zchar_split rpredM //; apply/cfun_onP=> x A'x. by rewrite cfunE (cfun_onP Aphi) ?mul0r. Qed. Section CfdotPairwiseOrthogonal. Variables (M : {group gT}) (S : seq 'CF(G)) (nu : 'CF(G) -> 'CF(M)). Hypotheses (Inu : {in 'Z[S] &, isometry nu}) (oSS : pairwise_orthogonal S). Let freeS := orthogonal_free oSS. Let uniqS : uniq S := free_uniq freeS. Let Z_S : {subset S <= 'Z[S]}. Proof. by move=> phi; apply: mem_zchar. Qed. Let notS0 : 0 \notin S. Proof. by case/andP: oSS. Qed. Let dotSS := proj2 (pairwise_orthogonalP oSS). Lemma map_pairwise_orthogonal : pairwise_orthogonal (map nu S). Proof. have inj_nu: {in S &, injective nu}. move=> phi psi Sphi Spsi /= eq_nu; apply: contraNeq (memPn notS0 _ Sphi). by rewrite -cfnorm_eq0 -Inu ?Z_S // {2}eq_nu Inu ?Z_S // => /dotSS->. have notSnu0: 0 \notin map nu S. apply: contra notS0 => /mapP[phi Sphi /esym/eqP]. by rewrite -cfnorm_eq0 Inu ?Z_S // cfnorm_eq0 => /eqP <-. apply/pairwise_orthogonalP; split; first by rewrite /= notSnu0 map_inj_in_uniq. move=> _ _ /mapP[phi Sphi ->] /mapP[psi Spsi ->]. by rewrite (inj_in_eq inj_nu) // Inu ?Z_S //; apply: dotSS. Qed. Lemma cfproj_sum_orthogonal P z phi : phi \in S -> '[\sum_(xi <- S | P xi) z xi *: nu xi, nu phi] = if P phi then z phi * '[phi] else 0. Proof. move=> Sphi; have defS := perm_to_rem Sphi. rewrite cfdot_suml (perm_big _ defS) big_cons /= cfdotZl Inu ?Z_S //. rewrite big1_seq ?addr0 // => xi; rewrite mem_rem_uniq ?inE //. by case/and3P=> _ neq_xi Sxi; rewrite cfdotZl Inu ?Z_S // dotSS ?mulr0. Qed. Lemma cfdot_sum_orthogonal z1 z2 : '[\sum_(xi <- S) z1 xi *: nu xi, \sum_(xi <- S) z2 xi *: nu xi] = \sum_(xi <- S) z1 xi * (z2 xi)^* * '[xi]. Proof. rewrite cfdot_sumr; apply: eq_big_seq => phi Sphi. by rewrite cfdotZr cfproj_sum_orthogonal // mulrCA mulrA. Qed. Lemma cfnorm_sum_orthogonal z : '[\sum_(xi <- S) z xi *: nu xi] = \sum_(xi <- S) `|z xi| ^+ 2 * '[xi]. Proof. by rewrite cfdot_sum_orthogonal; apply: eq_bigr => xi _; rewrite normCK. Qed. Lemma cfnorm_orthogonal : '[\sum_(xi <- S) nu xi] = \sum_(xi <- S) '[xi]. Proof. rewrite -(eq_bigr _ (fun _ _ => scale1r _)) cfnorm_sum_orthogonal. by apply: eq_bigr => xi; rewrite normCK conjC1 !mul1r. Qed. End CfdotPairwiseOrthogonal. Lemma orthogonal_span S phi : pairwise_orthogonal S -> phi \in <<S>>%VS -> {z | z = fun xi => '[phi, xi] / '[xi] & phi = \sum_(xi <- S) z xi *: xi}. Proof. move=> oSS /free_span[|c -> _]; first exact: orthogonal_free. set z := fun _ => _ : algC; exists z => //; apply: eq_big_seq => u Su. rewrite /z cfproj_sum_orthogonal // mulfK // cfnorm_eq0. by rewrite (memPn _ u Su); case/andP: oSS. Qed. Section CfDotOrthonormal. Variables (M : {group gT}) (S : seq 'CF(G)) (nu : 'CF(G) -> 'CF(M)). Hypotheses (Inu : {in 'Z[S] &, isometry nu}) (onS : orthonormal S). Let oSS := orthonormal_orthogonal onS. Let freeS := orthogonal_free oSS. Let nS1 : {in S, forall phi, '[phi] = 1}. Proof. by move=> phi Sphi; case/orthonormalP: onS => _ -> //; rewrite eqxx. Qed. Lemma map_orthonormal : orthonormal (map nu S). Proof. rewrite !orthonormalE map_pairwise_orthogonal // andbT. by apply/allP=> _ /mapP[xi Sxi ->]; rewrite /= Inu ?nS1 // mem_zchar. Qed. Lemma cfproj_sum_orthonormal z phi : phi \in S -> '[\sum_(xi <- S) z xi *: nu xi, nu phi] = z phi. Proof. by move=> Sphi; rewrite cfproj_sum_orthogonal // nS1 // mulr1. Qed. Lemma cfdot_sum_orthonormal z1 z2 : '[\sum_(xi <- S) z1 xi *: xi, \sum_(xi <- S) z2 xi *: xi] = \sum_(xi <- S) z1 xi * (z2 xi)^*. Proof. rewrite cfdot_sum_orthogonal //; apply: eq_big_seq => phi /nS1->. by rewrite mulr1. Qed. Lemma cfnorm_sum_orthonormal z : '[\sum_(xi <- S) z xi *: nu xi] = \sum_(xi <- S) `|z xi| ^+ 2. Proof. rewrite cfnorm_sum_orthogonal //. by apply: eq_big_seq => xi /nS1->; rewrite mulr1. Qed. Lemma cfnorm_map_orthonormal : '[\sum_(xi <- S) nu xi] = (size S)%:R. Proof. by rewrite cfnorm_orthogonal // (eq_big_seq _ nS1) big_tnth sumr_const card_ord. Qed. Lemma orthonormal_span phi : phi \in <<S>>%VS -> {z | z = fun xi => '[phi, xi] & phi = \sum_(xi <- S) z xi *: xi}. Proof. case/orthogonal_span=> // _ -> {2}->; set z := fun _ => _ : algC. by exists z => //; apply: eq_big_seq => xi /nS1->; rewrite divr1. Qed. End CfDotOrthonormal. Lemma cfnorm_orthonormal S : orthonormal S -> '[\sum_(xi <- S) xi] = (size S)%:R. Proof. exact: cfnorm_map_orthonormal. Qed. Lemma vchar_orthonormalP S : {subset S <= 'Z[irr G]} -> reflect (exists I : {set Iirr G}, exists b : Iirr G -> bool, perm_eq S [seq (-1) ^+ b i *: 'chi_i | i in I]) (orthonormal S). Proof. move=> vcS; apply: (equivP orthonormalP). split=> [[uniqS oSS] | [I [b defS]]]; last first. split=> [|xi1 xi2]; rewrite ?(perm_mem defS). rewrite (perm_uniq defS) map_inj_uniq ?enum_uniq // => i j /eqP. by rewrite eq_signed_irr => /andP[_ /eqP]. case/mapP=> [i _ ->] /mapP[j _ ->]; rewrite eq_signed_irr. rewrite cfdotZl cfdotZr rmorph_sign mulrA cfdot_irr -signr_addb mulr_natr. by rewrite mulrb andbC; case: eqP => //= ->; rewrite addbb eqxx. pose I := [set i | ('chi_i \in S) || (- 'chi_i \in S)]. pose b i := - 'chi_i \in S; exists I, b. apply: uniq_perm => // [|xi]. rewrite map_inj_uniq ?enum_uniq // => i j /eqP. by rewrite eq_signed_irr => /andP[_ /eqP]. apply/idP/mapP=> [Sxi | [i Ii ->{xi}]]; last first. move: Ii; rewrite mem_enum inE orbC -/(b i). by case b_i: (b i); rewrite (scale1r, scaleN1r). have: '[xi] = 1 by rewrite oSS ?eqxx. have vc_xi := vcS _ Sxi; rewrite cfdot_sum_irr. case/natr_sum_eq1 => [i _ | i [_ /eqP norm_xi_i xi_i'_0]]. by rewrite -normCK rpredX // natr_norm_int ?Cint_cfdot_vchar_irr. suffices def_xi: xi = (-1) ^+ b i *: 'chi_i. exists i; rewrite // mem_enum inE -/(b i) orbC. by case: (b i) def_xi Sxi => // ->; rewrite scale1r. move: Sxi; rewrite [xi]cfun_sum_cfdot (bigD1 i) //. rewrite big1 //= ?addr0 => [|j ne_ji]; last first. apply/eqP; rewrite scaler_eq0 -normr_eq0 -[_ == 0](expf_eq0 _ 2) normCK. by rewrite xi_i'_0 ?eqxx. have:= norm_xi_i; rewrite (aut_intr _ (Cint_cfdot_vchar_irr _ _)) //. rewrite -subr_eq0 subr_sqr_1 mulf_eq0 subr_eq0 addr_eq0 /b scaler_sign. case/pred2P=> ->; last by rewrite scaleN1r => ->. rewrite scale1r => Sxi; case: ifP => // SNxi. have:= oSS _ _ Sxi SNxi; rewrite cfdotNr cfdot_irr eqxx; case: eqP => // _. by move/eqP; rewrite oppr_eq0 oner_eq0. Qed. Lemma vchar_norm1P phi : phi \in 'Z[irr G] -> '[phi] = 1 -> exists b : bool, exists i : Iirr G, phi = (-1) ^+ b *: 'chi_i. Proof. move=> Zphi phiN1. have: orthonormal phi by rewrite /orthonormal/= phiN1 eqxx. case/vchar_orthonormalP=> [xi /predU1P[->|] // | I [b def_phi]]. have: phi \in (phi : seq _) := mem_head _ _. by rewrite (perm_mem def_phi) => /mapP[i _ ->]; exists (b i), i. Qed. Lemma zchar_small_norm phi n : phi \in 'Z[irr G] -> '[phi] = n%:R -> (n < 4)%N -> {S : n.-tuple 'CF(G) | [/\ orthonormal S, {subset S <= 'Z[irr G]} & phi = \sum_(xi <- S) xi]}. Proof. move=> Zphi def_n lt_n_4. pose S := [seq '[phi, 'chi_i] *: 'chi_i | i in irr_constt phi]. have def_phi: phi = \sum_(xi <- S) xi. rewrite big_image big_mkcond {1}[phi]cfun_sum_cfdot. by apply: eq_bigr => i _; rewrite if_neg; case: eqP => // ->; rewrite scale0r. have orthS: orthonormal S. apply/orthonormalP; split=> [|_ _ /mapP[i phi_i ->] /mapP[j _ ->]]. rewrite map_inj_in_uniq ?enum_uniq // => i j; rewrite mem_enum => phi_i _. by move/eqP; rewrite eq_scaled_irr (negbTE phi_i) => /andP[_ /= /eqP]. rewrite eq_scaled_irr cfdotZl cfdotZr cfdot_irr mulrA mulr_natr mulrb. rewrite mem_enum in phi_i; rewrite (negbTE phi_i) andbC; case: eqP => // <-. have /natrP[m def_m] := natr_norm_int (Cint_cfdot_vchar_irr i Zphi). apply/eqP; rewrite eqxx /= -normCK def_m -natrX eqr_nat eqn_leq lt0n. rewrite expn_eq0 andbT -eqC_nat -def_m normr_eq0 [~~ _]phi_i andbT. rewrite (leq_exp2r _ 1) // -ltnS -(@ltn_exp2r _ _ 2) //. apply: leq_ltn_trans lt_n_4; rewrite -leC_nat -def_n natrX. rewrite cfdot_sum_irr (bigD1 i) //= -normCK def_m addrC -subr_ge0 addrK. by rewrite sumr_ge0 // => ? _; apply: mul_conjC_ge0. have <-: size S = n. by apply/eqP; rewrite -eqC_nat -def_n def_phi cfnorm_orthonormal. exists (in_tuple S); split=> // _ /mapP[i _ ->]. by rewrite scale_zchar ?irr_vchar // Cint_cfdot_vchar_irr. Qed. Lemma vchar_norm2 phi : phi \in 'Z[irr G, G^#] -> '[phi] = 2 -> exists i, exists2 j, j != i & phi = 'chi_i - 'chi_j. Proof. rewrite zchar_split cfunD1E => /andP[Zphi phi1_0]. case/zchar_small_norm => // [[[|chi [|xi [|?]]] //= S2]]. case=> /andP[/and3P[Nchi Nxi _] /= ochi] /allP/and3P[Zchi Zxi _]. rewrite big_cons big_seq1 => def_phi. have [b [i def_chi]] := vchar_norm1P Zchi (eqP Nchi). have [c [j def_xi]] := vchar_norm1P Zxi (eqP Nxi). have neq_ji: j != i. apply: contraTneq ochi; rewrite !andbT def_chi def_xi => ->. rewrite cfdotZl cfdotZr rmorph_sign cfnorm_irr mulr1 -signr_addb. by rewrite signr_eq0. have neq_bc: b != c. apply: contraTneq phi1_0; rewrite def_phi def_chi def_xi => ->. rewrite -scalerDr !cfunE mulf_eq0 signr_eq0 eq_le lt_geF //. by rewrite ltr_pDl ?irr1_gt0. rewrite {}def_phi {}def_chi {}def_xi !scaler_sign. case: b c neq_bc => [|] [|] // _; last by exists i, j. by exists j, i; rewrite 1?eq_sym // addrC. Qed. End VChar. Section Isometries. Variables (gT : finGroupType) (L G : {group gT}) (S : seq 'CF(L)). Implicit Type nu : {additive 'CF(L) -> 'CF(G)}. Lemma Zisometry_of_cfnorm (tauS : seq 'CF(G)) : pairwise_orthogonal S -> pairwise_orthogonal tauS -> map cfnorm tauS = map cfnorm S -> {subset tauS <= 'Z[irr G]} -> {tau : {linear 'CF(L) -> 'CF(G)} | map tau S = tauS & {in 'Z[S], isometry tau, to 'Z[irr G]}}. Proof. move=> oSS oTT /isometry_of_cfnorm[||tau defT Itau] // Z_T; exists tau => //. split=> [|_ /zchar_nth_expansion[u Zu ->]]. by apply: sub_in2 Itau; apply: zchar_span. rewrite big_seq linear_sum rpred_sum // => xi Sxi. by rewrite linearZ scale_zchar ?Z_T // -defT map_f ?mem_nth. Qed. Lemma Zisometry_of_iso f : free S -> {in S, isometry f, to 'Z[irr G]} -> {tau : {linear 'CF(L) -> 'CF(G)} | {in S, tau =1 f} & {in 'Z[S], isometry tau, to 'Z[irr G]}}. Proof. move=> freeS [If Zf]; have [tau Dtau Itau] := isometry_of_free freeS If. exists tau => //; split; first by apply: sub_in2 Itau; apply: zchar_span. move=> _ /zchar_nth_expansion[a Za ->]; rewrite linear_sum rpred_sum // => i _. by rewrite linearZ rpredZ_int ?Dtau ?Zf ?mem_nth. Qed. Lemma Zisometry_inj A nu : {in 'Z[S, A] &, isometry nu} -> {in 'Z[S, A] &, injective nu}. Proof. by move/isometry_raddf_inj; apply; apply: rpredB. Qed. Lemma isometry_in_zchar nu : {in S &, isometry nu} -> {in 'Z[S] &, isometry nu}. Proof. move=> Inu _ _ /zchar_nth_expansion[u Zu ->] /zchar_nth_expansion[v Zv ->]. rewrite !raddf_sum; apply: eq_bigr => j _ /=. rewrite !cfdot_suml; apply: eq_bigr => i _. by rewrite !raddfZ_int //= !cfdotZl !cfdotZr Inu ?mem_nth. Qed. End Isometries. Section AutVchar. Variables (u : {rmorphism algC -> algC}) (gT : finGroupType) (G : {group gT}). Local Notation "alpha ^u" := (cfAut u alpha). Implicit Type (S : seq 'CF(G)) (phi chi : 'CF(G)). Lemma cfAut_zchar S A psi : cfAut_closed u S -> psi \in 'Z[S, A] -> psi^u \in 'Z[S, A]. Proof. rewrite zchar_split => SuS /andP[/zchar_nth_expansion[z Zz Dpsi] Apsi]. rewrite zchar_split cfAut_on {}Apsi {psi}Dpsi rmorph_sum rpred_sum //= => i _. by rewrite cfAutZ_Cint // scale_zchar // mem_zchar ?SuS ?mem_nth. Qed. Lemma cfAut_vchar A psi : psi \in 'Z[irr G, A] -> psi^u \in 'Z[irr G, A]. Proof. by apply: cfAut_zchar; apply: irr_aut_closed. Qed. Lemma sub_aut_zchar S A psi : {subset S <= 'Z[irr G]} -> psi \in 'Z[S, A] -> psi^u \in 'Z[S, A] -> psi - psi^u \in 'Z[S, A^#]. Proof. move=> Z_S Spsi Spsi_u; rewrite zcharD1 !cfunE subr_eq0 rpredB //=. by rewrite aut_intr // Cint_vchar1 // (zchar_trans Z_S) ?(zcharW Spsi). Qed. Lemma conjC_vcharAut chi x : chi \in 'Z[irr G] -> (u (chi x))^* = u (chi x)^*. Proof. case/vcharP=> chi1 Nchi1 [chi2 Nchi2 ->]. by rewrite !cfunE !rmorphB !conjC_charAut. Qed. Lemma cfdot_aut_vchar phi chi : chi \in 'Z[irr G] -> '[phi^u , chi^u] = u '[phi, chi]. Proof. by case/vcharP=> chi1 Nchi1 [chi2 Nchi2 ->]; rewrite !raddfB /= !cfdot_aut_char. Qed. Lemma vchar_aut A chi : (chi^u \in 'Z[irr G, A]) = (chi \in 'Z[irr G, A]). Proof. rewrite !(zchar_split _ A) cfAut_on; congr (_ && _). apply/idP/idP=> [Zuchi|]; last exact: cfAut_vchar. rewrite [chi]cfun_sum_cfdot rpred_sum // => i _. rewrite scale_zchar ?irr_vchar //. by rewrite -(intr_aut u) -cfdot_aut_irr -aut_IirrE Cint_cfdot_vchar_irr. Qed. End AutVchar. Definition cfConjC_vchar := cfAut_vchar conjC. Section MoreVchar. Variables (gT : finGroupType) (G H : {group gT}). Lemma cfRes_vchar phi : phi \in 'Z[irr G] -> 'Res[H] phi \in 'Z[irr H]. Proof. case/vcharP=> xi1 Nx1 [xi2 Nxi2 ->]. by rewrite raddfB rpredB ?char_vchar ?cfRes_char. Qed. Lemma cfRes_vchar_on A phi : H \subset G -> phi \in 'Z[irr G, A] -> 'Res[H] phi \in 'Z[irr H, A]. Proof. rewrite zchar_split => sHG /andP[Zphi Aphi]; rewrite zchar_split cfRes_vchar //. apply/cfun_onP=> x /(cfun_onP Aphi); rewrite !cfunElock !genGid sHG => ->. exact: mul0rn. Qed. Lemma cfInd_vchar phi : phi \in 'Z[irr H] -> 'Ind[G] phi \in 'Z[irr G]. Proof. move=> /vcharP[xi1 Nx1 [xi2 Nxi2 ->]]. by rewrite raddfB rpredB ?char_vchar ?cfInd_char. Qed. Lemma sub_conjC_vchar A phi : phi \in 'Z[irr G, A] -> phi - (phi^*)%CF \in 'Z[irr G, A^#]. Proof. move=> Zphi; rewrite sub_aut_zchar ?cfAut_zchar // => _ /irrP[i ->]. exact: irr_vchar. exact: cfConjC_irr. Qed. Lemma Frobenius_kernel_exists : [Frobenius G with complement H] -> {K : {group gT} | [Frobenius G = K ><| H]}. Proof. move=> frobG; have [_ ntiHG] := andP frobG. have [[_ sHG regGH][_ tiHG /eqP defNH]] := (normedTI_memJ_P ntiHG, and3P ntiHG). suffices /sigW[K defG]: exists K, gval K ><| H == G by exists K; apply/andP. pose K1 := G :\: cover (H^# :^: G). have oK1: #|K1| = #|G : H|. rewrite cardsD (setIidPr _); last first. rewrite cover_imset; apply/bigcupsP=> x Gx. by rewrite sub_conjg conjGid ?groupV // (subset_trans (subsetDl _ _)). rewrite (cover_partition (partition_normedTI ntiHG)) -(Lagrange sHG). by rewrite (card_support_normedTI ntiHG) (cardsD1 1%g) group1 mulSn addnK. suffices extG i: {j | {in H, 'chi[G]_j =1 'chi[H]_i} & K1 \subset cfker 'chi_j}. pose K := [group of \bigcap_i cfker 'chi_(s2val (extG i))]. have nKH: H \subset 'N(K). by apply/norms_bigcap/bigcapsP=> i _; apply: subset_trans (cfker_norm _). have tiKH: K :&: H = 1%g. apply/trivgP; rewrite -(TI_cfker_irr H) /= setIC; apply/bigcapsP=> i _. apply/subsetP=> x /setIP[Hx /bigcapP/(_ i isT)/=]; rewrite !cfkerEirr !inE. by case: (extG i) => /= j def_j _; rewrite !def_j. exists K; rewrite sdprodE // eqEcard TI_cardMg // mul_subG //=; last first. by rewrite (bigcap_min (0 : Iirr H)) ?cfker_sub. rewrite -(Lagrange sHG) mulnC leq_pmul2r // -oK1 subset_leq_card //. by apply/bigcapsP=> i _; case: (extG i). case i0: (i == 0). exists 0 => [x Hx|]; last by rewrite irr0 cfker_cfun1 subsetDl. by rewrite (eqP i0) !irr0 !cfun1E // (subsetP sHG) ?Hx. have ochi1: '['chi_i, 1] = 0 by rewrite -irr0 cfdot_irr i0. pose a := 'chi_i 1%g; have Za: a \in Num.int by rewrite intrE Cnat_irr1. pose theta := 'chi_i - a%:A; pose phi := 'Ind[G] theta + a%:A. have /cfun_onP theta0: theta \in 'CF(H, H^#). by rewrite cfunD1E !cfunE cfun11 mulr1 subrr. have RItheta: 'Res ('Ind[G] theta) = theta. apply/cfun_inP=> x Hx; rewrite cfResE ?cfIndE // (big_setID H) /= addrC. apply: canLR (mulKf (neq0CG H)) _; rewrite (setIidPr sHG) mulr_natl. rewrite big1 ?add0r => [|y /setDP[/regGH tiHy H'y]]; last first. have [-> | ntx] := eqVneq x 1%g; first by rewrite conj1g theta0 ?inE ?eqxx. by rewrite theta0 ?tiHy // !inE ntx. by rewrite -sumr_const; apply: eq_bigr => y Hy; rewrite cfunJ. have ophi1: '[phi, 1] = 0. rewrite cfdotDl -cfdot_Res_r cfRes_cfun1 // cfdotBl !cfdotZl !cfnorm1. by rewrite ochi1 add0r addNr. have{ochi1} n1phi: '[phi] = 1. have: '[phi - a%:A] = '[theta] by rewrite addrK -cfdot_Res_l RItheta. rewrite !cfnormBd ?cfnormZ ?cfdotZr ?ophi1 ?ochi1 ?mulr0 //. by rewrite !cfnorm1 cfnorm_irr => /addIr. have Zphi: phi \in 'Z[irr G]. by rewrite rpredD ?cfInd_vchar ?rpredB ?irr_vchar // scale_zchar ?rpred1. have def_phi: {in H, phi =1 'chi_i}. move=> x Hx /=; rewrite !cfunE -[_ x](cfResE _ sHG) ?RItheta //. by rewrite !cfunE !cfun1E ?(subsetP sHG) ?Hx ?subrK. have [j def_chi_j]: {j | 'chi_j = phi}. apply/sig_eqW; have [[] [j]] := vchar_norm1P Zphi n1phi; last first. by rewrite scale1r; exists j. move/cfunP/(_ 1%g)/eqP; rewrite scaleN1r def_phi // cfunE -addr_eq0 eq_le. by rewrite lt_geF // ltr_pDl ?irr1_gt0. exists j; rewrite ?cfkerEirr def_chi_j //; apply/subsetP => x /setDP[Gx notHx]. rewrite inE cfunE def_phi // cfunE -/a cfun1E // Gx mulr1 cfIndE //. rewrite big1 ?mulr0 ?add0r // => y Gy; apply/theta0/(contra _ notHx) => Hxy. by rewrite -(conjgK y x) cover_imset -class_supportEr imset2_f ?groupV. Qed. End MoreVchar. Definition dirr (gT : finGroupType) (B : {set gT}) : {pred 'CF(B)} := [pred f | (f \in irr B) || (- f \in irr B)]. Arguments dirr {gT}. Section Norm1vchar. Variables (gT : finGroupType) (G : {group gT}). Fact dirr_oppr_closed : oppr_closed (dirr G). Proof. by move=> xi; rewrite !inE opprK orbC. Qed. HB.instance Definition _ := GRing.isOppClosed.Build (classfun G) (dirr G) dirr_oppr_closed. Lemma dirr_opp v : (- v \in dirr G) = (v \in dirr G). Proof. exact: rpredN. Qed. Lemma dirr_sign n v : ((-1)^+ n *: v \in dirr G) = (v \in dirr G). Proof. exact: rpredZsign. Qed. Lemma irr_dirr i : 'chi_i \in dirr G. Proof. by rewrite !inE mem_irr. Qed. Lemma dirrP f : reflect (exists b : bool, exists i, f = (-1) ^+ b *: 'chi_i) (f \in dirr G). Proof. apply: (iffP idP) => [| [b [i ->]]]; last by rewrite dirr_sign irr_dirr. case/orP=> /irrP[i Hf]; first by exists false, i; rewrite scale1r. by exists true, i; rewrite scaleN1r -Hf opprK. Qed. (* This should perhaps be the definition of dirr. *) Lemma dirrE phi : phi \in dirr G = (phi \in 'Z[irr G]) && ('[phi] == 1). Proof. apply/dirrP/andP=> [[b [i ->]] | [Zphi /eqP/vchar_norm1P]]; last exact. by rewrite rpredZsign irr_vchar cfnorm_sign cfnorm_irr. Qed. Lemma cfdot_dirr f g : f \in dirr G -> g \in dirr G -> '[f, g] = (if f == - g then -1 else (f == g)%:R). Proof. case/dirrP=> [b1 [i1 ->]] /dirrP[b2 [i2 ->]]. rewrite cfdotZl cfdotZr rmorph_sign mulrA -signr_addb cfdot_irr. rewrite -scaleNr -signrN !eq_scaled_irr signr_eq0 !(inj_eq signr_inj) /=. by rewrite -!negb_add addbN mulr_sign -mulNrn mulrb; case: ifP. Qed. Lemma dirr_norm1 phi : phi \in 'Z[irr G] -> '[phi] = 1 -> phi \in dirr G. Proof. by rewrite dirrE => -> -> /=. Qed. Lemma dirr_aut u phi : (cfAut u phi \in dirr G) = (phi \in dirr G). Proof. rewrite !dirrE vchar_aut; apply: andb_id2l => /cfdot_aut_vchar->. exact: fmorph_eq1. Qed. Definition dIirr (B : {set gT}) := (bool * (Iirr B))%type. Definition dirr1 (B : {set gT}) : dIirr B := (false, 0). Definition ndirr (B : {set gT}) (i : dIirr B) : dIirr B := (~~ i.1, i.2). Lemma ndirr_diff (i : dIirr G) : ndirr i != i. Proof. by case: i => [] [|] i. Qed. Lemma ndirrK : involutive (@ndirr G). Proof. by move=> [b i]; rewrite /ndirr /= negbK. Qed. Lemma ndirr_inj : injective (@ndirr G). Proof. exact: (inv_inj ndirrK). Qed. Definition dchi (B : {set gT}) (i : dIirr B) : 'CF(B) := (-1)^+ i.1 *: 'chi_i.2. Lemma dchi1 : dchi (dirr1 G) = 1. Proof. by rewrite /dchi scale1r irr0. Qed. Lemma dirr_dchi i : dchi i \in dirr G. Proof. by apply/dirrP; exists i.1; exists i.2. Qed. Lemma dIrrP phi : reflect (exists i, phi = dchi i) (phi \in dirr G). Proof. by apply: (iffP idP)=> [/dirrP[b]|] [i ->]; [exists (b, i) | apply: dirr_dchi]. Qed. Lemma dchi_ndirrE (i : dIirr G) : dchi (ndirr i) = - dchi i. Proof. by case: i => [b i]; rewrite /ndirr /dchi signrN scaleNr. Qed. Lemma cfdot_dchi (i j : dIirr G) : '[dchi i, dchi j] = (i == j)%:R - (i == ndirr j)%:R. Proof. case: i => bi i; case: j => bj j; rewrite cfdot_dirr ?dirr_dchi // !xpair_eqE. rewrite -dchi_ndirrE !eq_scaled_irr signr_eq0 !(inj_eq signr_inj) /=. by rewrite -!negb_add addbN negbK; case: andP => [[->]|]; rewrite ?subr0 ?add0r. Qed. Lemma dchi_vchar i : dchi i \in 'Z[irr G]. Proof. by case: i => b i; rewrite rpredZsign irr_vchar. Qed. Lemma cfnorm_dchi (i : dIirr G) : '[dchi i] = 1. Proof. by case: i => b i; rewrite cfnorm_sign cfnorm_irr. Qed. Lemma dirr_inj : injective (@dchi G). Proof. case=> b1 i1 [b2 i2] /eqP; rewrite eq_scaled_irr (inj_eq signr_inj) /=. by rewrite signr_eq0 -xpair_eqE => /eqP. Qed. Definition dirr_dIirr (B : {set gT}) J (f : J -> 'CF(B)) j : dIirr B := odflt (dirr1 B) [pick i | dchi i == f j]. Lemma dirr_dIirrPE J (f : J -> 'CF(G)) (P : pred J) : (forall j, P j -> f j \in dirr G) -> forall j, P j -> dchi (dirr_dIirr f j) = f j. Proof. rewrite /dirr_dIirr => dirrGf j Pj; case: pickP => [i /eqP //|]. by have /dIrrP[i-> /(_ i)/eqP] := dirrGf j Pj. Qed. Lemma dirr_dIirrE J (f : J -> 'CF(G)) : (forall j, f j \in dirr G) -> forall j, dchi (dirr_dIirr f j) = f j. Proof. by move=> dirrGf j; apply: (@dirr_dIirrPE _ _ xpredT). Qed. Definition dirr_constt (B : {set gT}) (phi: 'CF(B)) : {set (dIirr B)} := [set i | 0 < '[phi, dchi i]]. Lemma dirr_consttE (phi : 'CF(G)) (i : dIirr G) : (i \in dirr_constt phi) = (0 < '[phi, dchi i]). Proof. by rewrite inE. Qed. Lemma Cnat_dirr (phi : 'CF(G)) i : phi \in 'Z[irr G] -> i \in dirr_constt phi -> '[phi, dchi i] \in Num.nat. Proof. move=> PiZ; rewrite natrEint dirr_consttE andbC => /ltW -> /=. by case: i => b i; rewrite cfdotZr rmorph_sign rpredMsign Cint_cfdot_vchar_irr. Qed. Lemma dirr_constt_oppr (i : dIirr G) (phi : 'CF(G)) : (i \in dirr_constt (-phi)) = (ndirr i \in dirr_constt phi). Proof. by rewrite !dirr_consttE dchi_ndirrE cfdotNl cfdotNr. Qed. Lemma dirr_constt_oppI (phi: 'CF(G)) : dirr_constt phi :&: dirr_constt (-phi) = set0. Proof. apply/setP=> i; rewrite inE !dirr_consttE cfdotNl inE. apply/idP=> /andP [L1 L2]; have := ltr_pDl L1 L2. by rewrite subrr lt_def eqxx. Qed. Lemma dirr_constt_oppl (phi: 'CF(G)) i : i \in dirr_constt phi -> (ndirr i) \notin dirr_constt phi. Proof. by rewrite !dirr_consttE dchi_ndirrE cfdotNr oppr_gt0 => /ltW /le_gtF ->. Qed. Definition to_dirr (B : {set gT}) (phi : 'CF(B)) (i : Iirr B) : dIirr B := ('[phi, 'chi_i] < 0, i). Definition of_irr (B : {set gT}) (i : dIirr B) : Iirr B := i.2. Lemma irr_constt_to_dirr (phi: 'CF(G)) i : phi \in 'Z[irr G] -> (i \in irr_constt phi) = (to_dirr phi i \in dirr_constt phi). Proof. move=> Zphi; rewrite irr_consttE dirr_consttE cfdotZr rmorph_sign /=. by rewrite -real_normrEsign ?normr_gt0 ?Rreal_int // Cint_cfdot_vchar_irr. Qed. Lemma to_dirrK (phi: 'CF(G)) : cancel (to_dirr phi) (@of_irr G). Proof. by []. Qed. Lemma of_irrK (phi: 'CF(G)) : {in dirr_constt phi, cancel (@of_irr G) (to_dirr phi)}. Proof. case=> b i; rewrite dirr_consttE cfdotZr rmorph_sign /= /to_dirr mulr_sign. by rewrite fun_if oppr_gt0; case: b => [|/ltW/le_gtF] ->. Qed. Lemma cfdot_todirrE (phi: 'CF(G)) i (phi_i := dchi (to_dirr phi i)) : '[phi, phi_i] *: phi_i = '[phi, 'chi_i] *: 'chi_i. Proof. by rewrite cfdotZr rmorph_sign mulrC -scalerA signrZK. Qed. Lemma cfun_sum_dconstt (phi : 'CF(G)) : phi \in 'Z[irr G] -> phi = \sum_(i in dirr_constt phi) '[phi, dchi i] *: dchi i. Proof. move=> PiZ; rewrite [LHS]cfun_sum_constt. rewrite (reindex (to_dirr phi))=> [/= |]; last first. by exists (@of_irr _)=> //; apply: of_irrK . by apply: eq_big => i; rewrite ?irr_constt_to_dirr // cfdot_todirrE. Qed. Lemma cnorm_dconstt (phi : 'CF(G)) : phi \in 'Z[irr G] -> '[phi] = \sum_(i in dirr_constt phi) '[phi, dchi i] ^+ 2. Proof. move=> PiZ; rewrite {1 2}(cfun_sum_dconstt PiZ). rewrite cfdot_suml; apply: eq_bigr=> i IiD. rewrite cfdot_sumr (bigD1 i) //= big1 ?addr0 => [|j /andP [JiD IdJ]]. rewrite cfdotZr cfdotZl cfdot_dchi eqxx eq_sym (negPf (ndirr_diff i)). by rewrite subr0 mulr1 aut_natr ?Cnat_dirr. rewrite cfdotZr cfdotZl cfdot_dchi eq_sym (negPf IdJ) -natrB ?mulr0 //. by rewrite (negPf (contraNneq _ (dirr_constt_oppl JiD))) => // <-. Qed. Lemma dirr_small_norm (phi : 'CF(G)) n : phi \in 'Z[irr G] -> '[phi] = n%:R -> (n < 4)%N -> [/\ #|dirr_constt phi| = n, dirr_constt phi :&: dirr_constt (- phi) = set0 & phi = \sum_(i in dirr_constt phi) dchi i]. Proof. move=> PiZ Pln; rewrite ltnNge -leC_nat => Nl4. suffices Fd i: i \in dirr_constt phi -> '[phi, dchi i] = 1. split; last 2 [by apply/setP=> u; rewrite !inE cfdotNl oppr_gt0 lt_asym]. apply/eqP; rewrite -eqC_nat -sumr_const -Pln (cnorm_dconstt PiZ). by apply/eqP/eq_bigr=> i Hi; rewrite Fd // expr1n. rewrite {1}[phi]cfun_sum_dconstt //. by apply: eq_bigr => i /Fd->; rewrite scale1r. move=> IiD; apply: contraNeq Nl4 => phi_i_neq1. rewrite -Pln cnorm_dconstt // (bigD1 i) ?ler_wpDr ?sumr_ge0 //=. by move=> j /andP[JiD _]; rewrite exprn_ge0 ?natr_ge0 ?Cnat_dirr. have /natrP[m Dm] := Cnat_dirr PiZ IiD; rewrite Dm -natrX ler_nat (leq_sqr 2). by rewrite ltn_neqAle eq_sym -eqC_nat -ltC_nat -Dm phi_i_neq1 -dirr_consttE. Qed. Lemma cfdot_sum_dchi (phi1 phi2 : 'CF(G)) : '[\sum_(i in dirr_constt phi1) dchi i, \sum_(i in dirr_constt phi2) dchi i] = #|dirr_constt phi1 :&: dirr_constt phi2|%:R - #|dirr_constt phi1 :&: dirr_constt (- phi2)|%:R. Proof. rewrite addrC (big_setID (dirr_constt (- phi2))) /= cfdotDl; congr (_ + _). rewrite cfdot_suml -sumr_const -sumrN; apply: eq_bigr => i /setIP[p1i p2i]. rewrite cfdot_sumr (bigD1 (ndirr i)) -?dirr_constt_oppr //= dchi_ndirrE. rewrite cfdotNr cfnorm_dchi big1 ?addr0 // => j /andP[p2j i'j]. rewrite cfdot_dchi -(inv_eq ndirrK) [in rhs in - rhs]eq_sym (negPf i'j) subr0. rewrite (negPf (contraTneq _ p2i)) // => ->. by rewrite dirr_constt_oppr dirr_constt_oppl. rewrite cfdot_sumr (big_setID (dirr_constt phi1)) setIC /= addrC. rewrite big1 ?add0r => [|j /setDP[p2j p1'j]]; last first. rewrite cfdot_suml big1 // => i /setDP[p1i p2'i]. rewrite cfdot_dchi (negPf (contraTneq _ p1i)) => [|-> //]. rewrite (negPf (contraNneq _ p2'i)) ?subrr // => ->. by rewrite dirr_constt_oppr ndirrK. rewrite -sumr_const; apply: eq_bigr => i /setIP[p1i p2i]; rewrite cfdot_suml. rewrite (bigD1 i) /=; last by rewrite inE dirr_constt_oppr dirr_constt_oppl. rewrite cfnorm_dchi big1 ?addr0 // => j /andP[/setDP[p1j _] i'j]. rewrite cfdot_dchi (negPf i'j) (negPf (contraTneq _ p1j)) ?subrr // => ->. exact: dirr_constt_oppl. Qed. Lemma cfdot_dirr_eq1 : {in dirr G &, forall phi psi, ('[phi, psi] == 1) = (phi == psi)}. Proof. move=> _ _ /dirrP[b1 [i1 ->]] /dirrP[b2 [i2 ->]]. rewrite eq_signed_irr cfdotZl cfdotZr rmorph_sign cfdot_irr mulrA -signr_addb. rewrite pmulrn -rmorphMsign (eqr_int _ _ 1) -negb_add. by case: (b1 (+) b2) (i1 == i2) => [] []. Qed. Lemma cfdot_add_dirr_eq1 : {in dirr G & &, forall phi1 phi2 psi, '[phi1 + phi2, psi] = 1 -> psi = phi1 \/ psi = phi2}. Proof. move=> _ _ _ /dirrP[b1 [i1 ->]] /dirrP[b2 [i2 ->]] /dirrP[c [j ->]] /eqP. rewrite cfdotDl !cfdotZl !cfdotZr !rmorph_sign !cfdot_irr !mulrA -!signr_addb. rewrite 2!{1}signrE !mulrBl !mul1r -!natrM addrCA -subr_eq0 -!addrA. rewrite -!opprD addrA subr_eq0 -mulrSr -!natrD eqr_nat => eq_phi_psi. apply/pred2P; rewrite /= !eq_signed_irr -!negb_add !(eq_sym j) !(addbC c). by case: (i1 == j) eq_phi_psi; case: (i2 == j); do 2!case: (_ (+) c). Qed. End Norm1vchar. Prenex Implicits ndirr ndirrK to_dirr to_dirrK of_irr. Arguments of_irrK {gT G phi} [i] phi_i : rename.
AffineTransitionLimit.lean
/- Copyright (c) 2025 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.IdealSheaf.Functorial import Mathlib.AlgebraicGeometry.Morphisms.Separated import Mathlib.CategoryTheory.Filtered.Final /-! # Inverse limits of schemes with affine transition maps In this file, we develop API for inverse limits of schemes with affine transition maps, following EGA IV 8 and https://stacks.math.columbia.edu/tag/01YT. -/ universe uI u open AlgebraicGeometry CategoryTheory Limits -- We refrain from considering diagrams in the over category since inverse limits in the over -- category is isomorphic to limits in `Scheme`. Instead we use `D ⟶ (Functor.const I).obj S` to -- say that the diagram is over the base scheme `S`. variable {I : Type u} [Category.{u} I] {S X : Scheme.{u}} (D : I ⥤ Scheme.{u}) (t : D ⟶ (Functor.const I).obj S) (f : X ⟶ S) (c : Cone D) (hc : IsLimit c) include hc in /-- Suppose we have a cofiltered diagram of nonempty quasi-compact schemes, whose transition maps are affine. Then the limit is also nonempty. -/ @[stacks 01Z2] lemma Scheme.nonempty_of_isLimit [IsCofilteredOrEmpty I] [∀ {i j} (f : i ⟶ j), IsAffineHom (D.map f)] [∀ i, Nonempty (D.obj i)] [∀ i, CompactSpace (D.obj i)] : Nonempty c.pt := by classical cases isEmpty_or_nonempty I · have e := (isLimitEquivIsTerminalOfIsEmpty _ _ hc).uniqueUpToIso specULiftZIsTerminal exact Nonempty.map e.inv.base inferInstance · have i := Nonempty.some ‹Nonempty I› have : IsCofiltered I := ⟨⟩ let 𝒰 := (D.obj i).affineCover.finiteSubcover have (i' : _) : IsAffine (𝒰.obj i') := inferInstanceAs (IsAffine (Spec _)) obtain ⟨j, H⟩ : ∃ j : 𝒰.J, ∀ {i'} (f : i' ⟶ i), Nonempty ((𝒰.pullbackCover (D.map f)).obj j) := by simp_rw [← not_isEmpty_iff] by_contra! H choose i' f hf using H let g (j) := IsCofiltered.infTo (insert i (Finset.univ.image i')) (Finset.univ.image fun j : 𝒰.J ↦ ⟨_, _, by simp, by simp, f j⟩) (X := j) have (j : 𝒰.J) : IsEmpty ((𝒰.pullbackCover (D.map (g i (by simp)))).obj j) := by let F : (𝒰.pullbackCover (D.map (g i (by simp)))).obj j ⟶ (𝒰.pullbackCover (D.map (f j))).obj j := pullback.map _ _ _ _ (D.map (g _ (by simp))) (𝟙 _) (𝟙 _) (by rw [← D.map_comp, IsCofiltered.infTo_commutes] · simp [g] · simp · exact Finset.mem_image_of_mem _ (Finset.mem_univ _)) (by simp) exact Function.isEmpty F.base obtain ⟨x, -⟩ := (𝒰.pullbackCover (D.map (g i (by simp)))).covers (Nonempty.some inferInstance) exact (this _).elim x let F := Over.post D ⋙ Over.pullback (𝒰.map j) ⋙ Over.forget _ have (i' : _) : IsAffine (F.obj i') := have : IsAffineHom (pullback.snd (D.map i'.hom) (𝒰.map j)) := MorphismProperty.pullback_snd _ _ inferInstance isAffine_of_isAffineHom (pullback.snd (D.map i'.hom) (𝒰.map j)) have (i' : _) : Nonempty (F.obj i') := H i'.hom let e : F ⟶ (F ⋙ Scheme.Γ.rightOp) ⋙ Scheme.Spec := Functor.whiskerLeft F ΓSpec.adjunction.unit have (i : _) : IsIso (e.app i) := IsAffine.affine have : IsIso e := NatIso.isIso_of_isIso_app e let c' : LimitCone F := ⟨_, (IsLimit.postcomposeInvEquiv (asIso e) _).symm (isLimitOfPreserves Scheme.Spec (limit.isLimit (F ⋙ Scheme.Γ.rightOp)))⟩ have : Nonempty c'.1.pt := by apply (config := { allowSynthFailures := true }) PrimeSpectrum.instNonemptyOfNontrivial have (i' : _) : Nontrivial ((F ⋙ Scheme.Γ.rightOp).leftOp.obj i') := by apply (config := { allowSynthFailures := true }) Scheme.component_nontrivial simp exact CommRingCat.FilteredColimits.nontrivial (isColimitCoconeLeftOpOfCone _ (limit.isLimit (F ⋙ Scheme.Γ.rightOp))) let α : F ⟶ Over.forget _ ⋙ D := Functor.whiskerRight (Functor.whiskerLeft (Over.post D) (Over.mapPullbackAdj (𝒰.map j)).counit) (Over.forget _) exact this.map (((Functor.Initial.isLimitWhiskerEquiv (Over.forget i) c).symm hc).lift ((Cones.postcompose α).obj c'.1)).base include hc in open Scheme.IdealSheafData in /-- Suppose we have a cofiltered diagram of schemes whose transition maps are affine. The limit of a family of compatible nonempty quasicompact closed sets in the diagram is also nonempty. -/ lemma exists_mem_of_isClosed_of_nonempty [IsCofilteredOrEmpty I] [∀ {i j} (f : i ⟶ j), IsAffineHom (D.map f)] (Z : ∀ (i : I), Set (D.obj i)) (hZc : ∀ (i : I), IsClosed (Z i)) (hZne : ∀ i, (Z i).Nonempty) (hZcpt : ∀ i, IsCompact (Z i)) (hmapsTo : ∀ {i i' : I} (f : i ⟶ i'), Set.MapsTo (D.map f).base (Z i) (Z i')) : ∃ (s : c.pt), ∀ i, (c.π.app i).base s ∈ Z i := by let D' : I ⥤ Scheme := { obj i := (vanishingIdeal ⟨Z i, hZc i⟩).subscheme map {X Y} f := subschemeMap _ _ (D.map f) (by rw [map_vanishingIdeal, ← le_support_iff_le_vanishingIdeal] simpa [(hZc _).closure_subset_iff] using (hmapsTo f).subset_preimage) map_id _ := by simp [← cancel_mono (subschemeι _)] map_comp _ _ := by simp [← cancel_mono (subschemeι _)] } let ι : D' ⟶ D := { app i := subschemeι _, naturality _ _ _ := by simp [D'] } haveI {i j} (f : i ⟶ j) : IsAffineHom (D'.map f) := by suffices IsAffineHom (D'.map f ≫ ι.app j) from .of_comp _ (ι.app j) simp only [subschemeMap_subschemeι, D', ι] infer_instance haveI _ (i) : Nonempty (D'.obj i) := Set.nonempty_coe_sort.mpr (hZne i) haveI _ (i) : CompactSpace (D'.obj i) := isCompact_iff_compactSpace.mp (hZcpt i) let c' : Cone D' := { pt := (⨆ i, (vanishingIdeal ⟨Z i, hZc i⟩).comap (c.π.app i)).subscheme π := { app i := subschemeMap _ _ (c.π.app i) (by simp [le_map_iff_comap_le, le_iSup_of_le i]) naturality {i j} f := by simp [D', ← cancel_mono (subschemeι _)] } } let hc' : IsLimit c' := { lift s := IsClosedImmersion.lift (subschemeι _) (hc.lift ((Cones.postcompose ι).obj s)) (by suffices ∀ i, vanishingIdeal ⟨Z i, hZc i⟩ ≤ (s.π.app i ≫ ι.app i).ker by simpa [← le_map_iff_comap_le, ← Scheme.Hom.ker_comp] refine fun i ↦ .trans ?_ (Scheme.Hom.le_ker_comp _ _) simp [ι]) fac s i := by simp [← cancel_mono (subschemeι _), c', ι] uniq s m hm := by rw [← cancel_mono (subschemeι _)] refine hc.hom_ext fun i ↦ ?_ simp [ι, c', ← hm] } have : Nonempty (⨆ i, (vanishingIdeal ⟨Z i, hZc i⟩).comap (c.π.app i)).support := Scheme.nonempty_of_isLimit D' c' hc' simpa using this include hc in /-- A variant of `exists_mem_of_isClosed_of_nonempty` where the closed sets are only defined for the objects over a given `j : I`. -/ @[stacks 01Z3] lemma exists_mem_of_isClosed_of_nonempty' [IsCofilteredOrEmpty I] [∀ {i j} (f : i ⟶ j), IsAffineHom (D.map f)] {j : I} (Z : ∀ (i : I), (i ⟶ j) → Set (D.obj i)) (hZc : ∀ i hij, IsClosed (Z i hij)) (hZne : ∀ i hij, (Z i hij).Nonempty) (hZcpt : ∀ i hij, IsCompact (Z i hij)) (hstab : ∀ (i i' : I) (hi'i : i' ⟶ i) (hij : i ⟶ j), Set.MapsTo (D.map hi'i).base (Z i' (hi'i ≫ hij)) (Z i hij)) : ∃ (s : c.pt), ∀ i hij, (c.π.app i).base s ∈ Z i hij := by have {i₁ i₂ : Over j} (f : i₁ ⟶ i₂) : IsAffineHom ((Over.forget j ⋙ D).map f) := by dsimp; infer_instance simpa [Over.forall_iff] using exists_mem_of_isClosed_of_nonempty (Over.forget j ⋙ D) _ ((Functor.Initial.isLimitWhiskerEquiv (Over.forget j) c).symm hc) (fun i ↦ Z i.left i.hom) (fun _ ↦ hZc _ _) (fun _ ↦ hZne _ _) (fun _ ↦ hZcpt _ _) (fun {i₁ i₂} f ↦ by dsimp; rw [← Over.w f]; exact hstab ..)
Prod.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.LinearAlgebra.Prod import Mathlib.RingTheory.Finiteness.Defs /-! # Finitely generated product (sub)modules -/ open Function (Surjective) open Finsupp namespace Submodule variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] open Set variable {P : Type*} [AddCommMonoid P] [Module R P] theorem FG.prod {sb : Submodule R M} {sc : Submodule R P} (hsb : sb.FG) (hsc : sc.FG) : (sb.prod sc).FG := let ⟨tb, htb⟩ := fg_def.1 hsb let ⟨tc, htc⟩ := fg_def.1 hsc fg_def.2 ⟨LinearMap.inl R M P '' tb ∪ LinearMap.inr R M P '' tc, (htb.1.image _).union (htc.1.image _), by rw [LinearMap.span_inl_union_inr, htb.2, htc.2]⟩ end Submodule namespace Module namespace Finite variable {R M N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] instance prod [hM : Module.Finite R M] [hN : Module.Finite R N] : Module.Finite R (M × N) := ⟨by rw [← Submodule.prod_top] exact hM.1.prod hN.1⟩ end Finite end Module
all.v
From mathcomp Require Export all_boot. From mathcomp Require Export all_order. From mathcomp Require Export all_fingroup. From mathcomp Require Export all_algebra. From mathcomp Require Export all_solvable. From mathcomp Require Export all_field. From mathcomp Require Export all_character.
SpecialLinearGroup.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Wen Yang -/ import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Matrix.Transvection import Mathlib.RingTheory.RootsOfUnity.Basic /-! # The Special Linear group $SL(n, R)$ This file defines the elements of the Special Linear group `SpecialLinearGroup n R`, consisting of all square `R`-matrices with determinant `1` on the fintype `n` by `n`. In addition, we define the group structure on `SpecialLinearGroup n R` and the embedding into the general linear group `GeneralLinearGroup R (n → R)`. ## Main definitions * `Matrix.SpecialLinearGroup` is the type of matrices with determinant 1 * `Matrix.SpecialLinearGroup.group` gives the group structure (under multiplication) * `Matrix.SpecialLinearGroup.toGL` is the embedding `SLₙ(R) → GLₙ(R)` ## Notation For `m : ℕ`, we introduce the notation `SL(m,R)` for the special linear group on the fintype `n = Fin m`, in the locale `MatrixGroups`. ## Implementation notes The inverse operation in the `SpecialLinearGroup` is defined to be the adjugate matrix, so that `SpecialLinearGroup n R` has a group structure for all `CommRing R`. We define the elements of `SpecialLinearGroup` to be matrices, since we need to compute their determinant. This is in contrast with `GeneralLinearGroup R M`, which consists of invertible `R`-linear maps on `M`. We provide `Matrix.SpecialLinearGroup.hasCoeToFun` for convenience, but do not state any lemmas about it, and use `Matrix.SpecialLinearGroup.coeFn_eq_coe` to eliminate it `⇑` in favor of a regular `↑` coercion. ## References * https://en.wikipedia.org/wiki/Special_linear_group ## Tags matrix group, group, matrix inverse -/ namespace Matrix universe u v open LinearMap section variable (n : Type u) [DecidableEq n] [Fintype n] (R : Type v) [CommRing R] /-- `SpecialLinearGroup n R` is the group of `n` by `n` `R`-matrices with determinant equal to 1. -/ def SpecialLinearGroup := { A : Matrix n n R // A.det = 1 } end @[inherit_doc] scoped[MatrixGroups] notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R namespace SpecialLinearGroup variable {n : Type u} [DecidableEq n] [Fintype n] {R : Type v} [CommRing R] instance hasCoeToMatrix : Coe (SpecialLinearGroup n R) (Matrix n n R) := ⟨fun A => A.val⟩ /-- In this file, Lean often has a hard time working out the values of `n` and `R` for an expression like `det ↑A`. Rather than writing `(A : Matrix n n R)` everywhere in this file which is annoyingly verbose, or `A.val` which is not the simp-normal form for subtypes, we create a local notation `↑ₘA`. This notation references the local `n` and `R` variables, so is not valid as a global notation. -/ local notation:1024 "↑ₘ" A:1024 => ((A : SpecialLinearGroup n R) : Matrix n n R) section CoeFnInstance /-- This instance is here for convenience, but is literally the same as the coercion from `hasCoeToMatrix`. -/ instance instCoeFun : CoeFun (SpecialLinearGroup n R) fun _ => n → n → R where coe A := ↑ₘA end CoeFnInstance theorem ext_iff (A B : SpecialLinearGroup n R) : A = B ↔ ∀ i j, A i j = B i j := Subtype.ext_iff.trans Matrix.ext_iff.symm @[ext] theorem ext (A B : SpecialLinearGroup n R) : (∀ i j, A i j = B i j) → A = B := (SpecialLinearGroup.ext_iff A B).mpr instance subsingleton_of_subsingleton [Subsingleton n] : Subsingleton (SpecialLinearGroup n R) := by refine ⟨fun ⟨A, hA⟩ ⟨B, hB⟩ ↦ ?_⟩ ext i j rcases isEmpty_or_nonempty n with hn | hn; · exfalso; exact IsEmpty.false i rw [det_eq_elem_of_subsingleton _ i] at hA hB simp only [Subsingleton.elim j i, hA, hB] instance hasInv : Inv (SpecialLinearGroup n R) := ⟨fun A => ⟨adjugate A, by rw [det_adjugate, A.prop, one_pow]⟩⟩ instance hasMul : Mul (SpecialLinearGroup n R) := ⟨fun A B => ⟨A * B, by rw [det_mul, A.prop, B.prop, one_mul]⟩⟩ instance hasOne : One (SpecialLinearGroup n R) := ⟨⟨1, det_one⟩⟩ instance : Pow (SpecialLinearGroup n R) ℕ where pow x n := ⟨x ^ n, (det_pow _ _).trans <| x.prop.symm ▸ one_pow _⟩ instance : Inhabited (SpecialLinearGroup n R) := ⟨1⟩ instance [Fintype R] [DecidableEq R] : Fintype (SpecialLinearGroup n R) := Subtype.fintype _ instance [Finite R] : Finite (SpecialLinearGroup n R) := Subtype.finite /-- The transpose of a matrix in `SL(n, R)` -/ def transpose (A : SpecialLinearGroup n R) : SpecialLinearGroup n R := ⟨A.1.transpose, A.1.det_transpose ▸ A.2⟩ @[inherit_doc] scoped postfix:1024 "ᵀ" => SpecialLinearGroup.transpose section CoeLemmas variable (A B : SpecialLinearGroup n R) theorem coe_mk (A : Matrix n n R) (h : det A = 1) : ↑(⟨A, h⟩ : SpecialLinearGroup n R) = A := rfl @[simp] theorem coe_inv : ↑ₘ(A⁻¹) = adjugate A := rfl @[simp] theorem coe_mul : ↑ₘ(A * B) = ↑ₘA * ↑ₘB := rfl @[simp] theorem coe_one : (1 : SpecialLinearGroup n R) = (1 : Matrix n n R) := rfl @[simp] theorem det_coe : det ↑ₘA = 1 := A.2 @[simp] theorem coe_pow (m : ℕ) : ↑ₘ(A ^ m) = ↑ₘA ^ m := rfl @[simp] lemma coe_transpose (A : SpecialLinearGroup n R) : ↑ₘAᵀ = (↑ₘA)ᵀ := rfl theorem det_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) : det ↑ₘg ≠ 0 := by rw [g.det_coe] norm_num theorem row_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) (i : n) : g i ≠ 0 := fun h => g.det_ne_zero <| det_eq_zero_of_row_eq_zero i <| by simp [h] end CoeLemmas instance monoid : Monoid (SpecialLinearGroup n R) := Function.Injective.monoid _ Subtype.coe_injective coe_one coe_mul coe_pow instance : Group (SpecialLinearGroup n R) := { SpecialLinearGroup.monoid, SpecialLinearGroup.hasInv with inv_mul_cancel := fun A => by ext1 simp [adjugate_mul] } /-- A version of `Matrix.toLin' A` that produces linear equivalences. -/ def toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R where toFun A := LinearEquiv.ofLinear (Matrix.toLin' ↑ₘA) (Matrix.toLin' ↑ₘA⁻¹) (by rw [← toLin'_mul, ← coe_mul, mul_inv_cancel, coe_one, toLin'_one]) (by rw [← toLin'_mul, ← coe_mul, inv_mul_cancel, coe_one, toLin'_one]) map_one' := LinearEquiv.toLinearMap_injective Matrix.toLin'_one map_mul' A B := LinearEquiv.toLinearMap_injective <| Matrix.toLin'_mul ↑ₘA ↑ₘB theorem toLin'_apply (A : SpecialLinearGroup n R) (v : n → R) : SpecialLinearGroup.toLin' A v = Matrix.toLin' (↑ₘA) v := rfl theorem toLin'_to_linearMap (A : SpecialLinearGroup n R) : ↑(SpecialLinearGroup.toLin' A) = Matrix.toLin' ↑ₘA := rfl theorem toLin'_symm_apply (A : SpecialLinearGroup n R) (v : n → R) : A.toLin'.symm v = Matrix.toLin' (↑ₘA⁻¹) v := rfl theorem toLin'_symm_to_linearMap (A : SpecialLinearGroup n R) : ↑A.toLin'.symm = Matrix.toLin' ↑ₘA⁻¹ := rfl theorem toLin'_injective : Function.Injective ↑(toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R) := fun _ _ h => Subtype.coe_injective <| Matrix.toLin'.injective <| LinearEquiv.toLinearMap_injective.eq_iff.mpr h variable {S : Type*} [CommRing S] /-- A ring homomorphism from `R` to `S` induces a group homomorphism from `SpecialLinearGroup n R` to `SpecialLinearGroup n S`. -/ @[simps] def map (f : R →+* S) : SpecialLinearGroup n R →* SpecialLinearGroup n S where toFun g := ⟨f.mapMatrix ↑ₘg, by rw [← f.map_det] simp [g.prop]⟩ map_one' := Subtype.ext <| f.mapMatrix.map_one map_mul' x y := Subtype.ext <| f.mapMatrix.map_mul ↑ₘx ↑ₘy section center open Subgroup @[simp] theorem center_eq_bot_of_subsingleton [Subsingleton n] : center (SpecialLinearGroup n R) = ⊥ := eq_bot_iff.mpr fun x _ ↦ by rw [mem_bot, Subsingleton.elim x 1] theorem scalar_eq_self_of_mem_center {A : SpecialLinearGroup n R} (hA : A ∈ center (SpecialLinearGroup n R)) (i : n) : scalar n (A i i) = A := by obtain ⟨r : R, hr : scalar n r = A⟩ := mem_range_scalar_of_commute_transvectionStruct fun t ↦ Subtype.ext_iff.mp <| Subgroup.mem_center_iff.mp hA ⟨t.toMatrix, by simp⟩ simp [← congr_fun₂ hr i i, ← hr] theorem scalar_eq_coe_self_center (A : center (SpecialLinearGroup n R)) (i : n) : scalar n ((A : Matrix n n R) i i) = A := scalar_eq_self_of_mem_center A.property i /-- The center of a special linear group of degree `n` is the subgroup of scalar matrices, for which the scalars are the `n`-th roots of unity. -/ theorem mem_center_iff {A : SpecialLinearGroup n R} : A ∈ center (SpecialLinearGroup n R) ↔ ∃ (r : R), r ^ (Fintype.card n) = 1 ∧ scalar n r = A := by rcases isEmpty_or_nonempty n with hn | ⟨⟨i⟩⟩; · exact ⟨by aesop, by simp [Subsingleton.elim A 1]⟩ refine ⟨fun h ↦ ⟨A i i, ?_, ?_⟩, fun ⟨r, _, hr⟩ ↦ Subgroup.mem_center_iff.mpr fun B ↦ ?_⟩ · have : det ((scalar n) (A i i)) = 1 := (scalar_eq_self_of_mem_center h i).symm ▸ A.property simpa using this · exact scalar_eq_self_of_mem_center h i · suffices ↑ₘ(B * A) = ↑ₘ(A * B) from Subtype.val_injective this simpa only [coe_mul, ← hr] using (scalar_commute (n := n) r (Commute.all r) B).symm /-- An equivalence of groups, from the center of the special linear group to the roots of unity. -/ @[simps] def center_equiv_rootsOfUnity' (i : n) : center (SpecialLinearGroup n R) ≃* rootsOfUnity (Fintype.card n) R where toFun A := haveI : Nonempty n := ⟨i⟩ rootsOfUnity.mkOfPowEq (↑ₘA i i) <| by obtain ⟨r, hr, hr'⟩ := mem_center_iff.mp A.property replace hr' : A.val i i = r := by simp only [← hr', scalar_apply, diagonal_apply_eq] simp only [hr', hr] invFun a := ⟨⟨a • (1 : Matrix n n R), by aesop⟩, Subgroup.mem_center_iff.mpr fun B ↦ Subtype.val_injective <| by simp [coe_mul]⟩ left_inv A := by refine SetCoe.ext <| SetCoe.ext ?_ obtain ⟨r, _, hr⟩ := mem_center_iff.mp A.property simpa [← hr, Submonoid.smul_def, Units.smul_def] using smul_one_eq_diagonal r right_inv a := by obtain ⟨⟨a, _⟩, ha⟩ := a exact SetCoe.ext <| Units.ext <| by simp map_mul' A B := by dsimp ext simp only [rootsOfUnity.val_mkOfPowEq_coe, Subgroup.coe_mul, Units.val_mul] rw [← scalar_eq_coe_self_center A i, ← scalar_eq_coe_self_center B i] simp open scoped Classical in /-- An equivalence of groups, from the center of the special linear group to the roots of unity. See also `center_equiv_rootsOfUnity'`. -/ noncomputable def center_equiv_rootsOfUnity : center (SpecialLinearGroup n R) ≃* rootsOfUnity (max (Fintype.card n) 1) R := (isEmpty_or_nonempty n).by_cases (fun hn ↦ by rw [center_eq_bot_of_subsingleton, Fintype.card_eq_zero, max_eq_right_of_lt zero_lt_one, rootsOfUnity_one] exact MulEquiv.ofUnique) (fun _ ↦ (max_eq_left (NeZero.one_le : 1 ≤ Fintype.card n)).symm ▸ center_equiv_rootsOfUnity' (Classical.arbitrary n)) end center section cast /-- Coercion of SL `n` `ℤ` to SL `n` `R` for a commutative ring `R`. -/ instance : Coe (SpecialLinearGroup n ℤ) (SpecialLinearGroup n R) := ⟨fun x => map (Int.castRingHom R) x⟩ @[simp] theorem coe_matrix_coe (g : SpecialLinearGroup n ℤ) : ↑(g : SpecialLinearGroup n R) = (↑g : Matrix n n ℤ).map (Int.castRingHom R) := map_apply_coe (Int.castRingHom R) g lemma map_intCast_injective [CharZero R] : Function.Injective ((↑) : SpecialLinearGroup n ℤ → SpecialLinearGroup n R) := fun g h ↦ by simp_rw [ext_iff, map_apply_coe, RingHom.mapMatrix_apply, Int.coe_castRingHom, Matrix.map_apply, Int.cast_inj] tauto @[simp] lemma map_intCast_inj [CharZero R] {x y : SpecialLinearGroup n ℤ} : (x : SpecialLinearGroup n R) = y ↔ x = y := map_intCast_injective.eq_iff end cast section Neg variable [Fact (Even (Fintype.card n))] /-- Formal operation of negation on special linear group on even cardinality `n` given by negating each element. -/ instance instNeg : Neg (SpecialLinearGroup n R) := ⟨fun g => ⟨-g, by simpa [(@Fact.out <| Even <| Fintype.card n).neg_one_pow, g.det_coe] using det_smul (↑ₘg) (-1)⟩⟩ @[simp] theorem coe_neg (g : SpecialLinearGroup n R) : ↑(-g) = -(g : Matrix n n R) := rfl instance : HasDistribNeg (SpecialLinearGroup n R) := Function.Injective.hasDistribNeg _ Subtype.coe_injective coe_neg coe_mul @[simp] theorem coe_int_neg (g : SpecialLinearGroup n ℤ) : ↑(-g) = (-↑g : SpecialLinearGroup n R) := Subtype.ext <| (@RingHom.mapMatrix n _ _ _ _ _ _ (Int.castRingHom R)).map_neg ↑g end Neg section SpecialCases open scoped MatrixGroups theorem SL2_inv_expl_det (A : SL(2, R)) : det ![![A.1 1 1, -A.1 0 1], ![-A.1 1 0, A.1 0 0]] = 1 := by simpa [-det_coe, Matrix.det_fin_two, mul_comm] using A.2 theorem SL2_inv_expl (A : SL(2, R)) : A⁻¹ = ⟨![![A.1 1 1, -A.1 0 1], ![-A.1 1 0, A.1 0 0]], SL2_inv_expl_det A⟩ := by ext have := Matrix.adjugate_fin_two A.1 rw [coe_inv, this] simp theorem fin_two_induction (P : SL(2, R) → Prop) (h : ∀ (a b c d : R) (hdet : a * d - b * c = 1), P ⟨!![a, b; c, d], by rwa [det_fin_two_of]⟩) (g : SL(2, R)) : P g := by obtain ⟨m, hm⟩ := g convert h (m 0 0) (m 0 1) (m 1 0) (m 1 1) (by rwa [det_fin_two] at hm) ext i j; fin_cases i <;> fin_cases j <;> rfl theorem fin_two_exists_eq_mk_of_apply_zero_one_eq_zero {R : Type*} [Field R] (g : SL(2, R)) (hg : g 1 0 = 0) : ∃ (a b : R) (h : a ≠ 0), g = (⟨!![a, b; 0, a⁻¹], by simp [h]⟩ : SL(2, R)) := by induction g using Matrix.SpecialLinearGroup.fin_two_induction with | h a b c d h_det => replace hg : c = 0 := by simpa using hg have had : a * d = 1 := by rwa [hg, mul_zero, sub_zero] at h_det refine ⟨a, b, left_ne_zero_of_mul_eq_one had, ?_⟩ simp_rw [eq_inv_of_mul_eq_one_right had, hg] lemma isCoprime_row (A : SL(2, R)) (i : Fin 2) : IsCoprime (A i 0) (A i 1) := by refine match i with | 0 => ⟨A 1 1, -(A 1 0), ?_⟩ | 1 => ⟨-(A 0 1), A 0 0, ?_⟩ <;> · simp_rw [det_coe A ▸ det_fin_two A.1] ring lemma isCoprime_col (A : SL(2, R)) (j : Fin 2) : IsCoprime (A 0 j) (A 1 j) := by refine match j with | 0 => ⟨A 1 1, -(A 0 1), ?_⟩ | 1 => ⟨-(A 1 0), A 0 0, ?_⟩ <;> · simp_rw [det_coe A ▸ det_fin_two A.1] ring end SpecialCases end SpecialLinearGroup end Matrix namespace IsCoprime open Matrix MatrixGroups SpecialLinearGroup variable {R : Type*} [CommRing R] /-- Given any pair of coprime elements of `R`, there exists a matrix in `SL(2, R)` having those entries as its left or right column. -/ lemma exists_SL2_col {a b : R} (hab : IsCoprime a b) (j : Fin 2) : ∃ g : SL(2, R), g 0 j = a ∧ g 1 j = b := by obtain ⟨u, v, h⟩ := hab refine match j with | 0 => ⟨⟨!![a, -v; b, u], ?_⟩, rfl, rfl⟩ | 1 => ⟨⟨!![v, a; -u, b], ?_⟩, rfl, rfl⟩ <;> · rw [Matrix.det_fin_two_of, ← h] ring /-- Given any pair of coprime elements of `R`, there exists a matrix in `SL(2, R)` having those entries as its top or bottom row. -/ lemma exists_SL2_row {a b : R} (hab : IsCoprime a b) (i : Fin 2) : ∃ g : SL(2, R), g i 0 = a ∧ g i 1 = b := by obtain ⟨u, v, h⟩ := hab refine match i with | 0 => ⟨⟨!![a, b; -v, u], ?_⟩, rfl, rfl⟩ | 1 => ⟨⟨!![v, -u; a, b], ?_⟩, rfl, rfl⟩ <;> · rw [Matrix.det_fin_two_of, ← h] ring /-- A vector with coprime entries, right-multiplied by a matrix in `SL(2, R)`, has coprime entries. -/ lemma vecMulSL {v : Fin 2 → R} (hab : IsCoprime (v 0) (v 1)) (A : SL(2, R)) : IsCoprime ((v ᵥ* A.1) 0) ((v ᵥ* A.1) 1) := by obtain ⟨g, hg⟩ := hab.exists_SL2_row 0 have : v = g 0 := funext fun t ↦ by { fin_cases t <;> tauto } simpa only [this] using isCoprime_row (g * A) 0 /-- A vector with coprime entries, left-multiplied by a matrix in `SL(2, R)`, has coprime entries. -/ lemma mulVecSL {v : Fin 2 → R} (hab : IsCoprime (v 0) (v 1)) (A : SL(2, R)) : IsCoprime ((A.1 *ᵥ v) 0) ((A.1 *ᵥ v) 1) := by simpa only [← vecMul_transpose] using hab.vecMulSL A.transpose end IsCoprime namespace ModularGroup open MatrixGroups open Matrix Matrix.SpecialLinearGroup /-- The matrix `S = [[0, -1], [1, 0]]` as an element of `SL(2, ℤ)`. This element acts naturally on the Euclidean plane as a rotation about the origin by `π / 2`. This element also acts naturally on the hyperbolic plane as rotation about `i` by `π`. It represents the Mobiüs transformation `z ↦ -1/z` and is an involutive elliptic isometry. -/ def S : SL(2, ℤ) := ⟨!![0, -1; 1, 0], by simp [Matrix.det_fin_two_of]⟩ /-- The matrix `T = [[1, 1], [0, 1]]` as an element of `SL(2, ℤ)`. -/ def T : SL(2, ℤ) := ⟨!![1, 1; 0, 1], by simp [Matrix.det_fin_two_of]⟩ theorem coe_S : ↑S = !![0, -1; 1, 0] := rfl theorem coe_T : ↑T = (!![1, 1; 0, 1] : Matrix _ _ ℤ) := rfl theorem coe_T_inv : ↑(T⁻¹) = !![1, -1; 0, 1] := by simp [coe_inv, coe_T, adjugate_fin_two] theorem coe_T_zpow (n : ℤ) : (T ^ n).1 = !![1, n; 0, 1] := by induction n with | zero => rw [zpow_zero, coe_one, Matrix.one_fin_two] | succ n h => simp_rw [zpow_add, zpow_one, coe_mul, h, coe_T, Matrix.mul_fin_two] congrm !![_, ?_; _, _] rw [mul_one, mul_one, add_comm] | pred n h => simp_rw [zpow_sub, zpow_one, coe_mul, h, coe_T_inv, Matrix.mul_fin_two] congrm !![?_, ?_; _, _] <;> ring @[simp] theorem T_pow_mul_apply_one (n : ℤ) (g : SL(2, ℤ)) : (T ^ n * g) 1 = g 1 := by ext j simp [coe_T_zpow, Matrix.vecMul, dotProduct, Fin.sum_univ_succ] @[simp] theorem T_mul_apply_one (g : SL(2, ℤ)) : (T * g) 1 = g 1 := by simpa using T_pow_mul_apply_one 1 g @[simp] theorem T_inv_mul_apply_one (g : SL(2, ℤ)) : (T⁻¹ * g) 1 = g 1 := by simpa using T_pow_mul_apply_one (-1) g lemma S_mul_S_eq : (S : Matrix (Fin 2) (Fin 2) ℤ) * S = -1 := by simp only [S, Int.reduceNeg, cons_mul, Nat.succ_eq_add_one, Nat.reduceAdd, vecMul_cons, head_cons, zero_smul, tail_cons, neg_smul, one_smul, neg_cons, neg_zero, neg_empty, empty_vecMul, add_zero, zero_add, empty_mul, Equiv.symm_apply_apply] exact Eq.symm (eta_fin_two (-1)) lemma T_S_rel : S • S • S • T • S • T • S = T⁻¹ := by ext i j fin_cases i <;> fin_cases j <;> rfl end ModularGroup
SemiNormedGrp.lean
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Riccardo Brasca -/ import Mathlib.Analysis.Normed.Group.Constructions import Mathlib.Analysis.Normed.Group.Hom import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Elementwise /-! # The category of seminormed groups We define `SemiNormedGrp`, the category of seminormed groups and normed group homs between them, as well as `SemiNormedGrp₁`, the subcategory of norm non-increasing morphisms. -/ noncomputable section universe u open CategoryTheory /-- The category of seminormed abelian groups and bounded group homomorphisms. -/ structure SemiNormedGrp : Type (u + 1) where /-- The underlying seminormed abelian group. -/ carrier : Type u [str : SeminormedAddCommGroup carrier] attribute [instance] SemiNormedGrp.str namespace SemiNormedGrp instance : CoeSort SemiNormedGrp Type* where coe X := X.carrier /-- Construct a bundled `SemiNormedGrp` from the underlying type and typeclass. -/ abbrev of (M : Type u) [SeminormedAddCommGroup M] : SemiNormedGrp where carrier := M /-- The type of morphisms in `SemiNormedGrp` -/ @[ext] structure Hom (M N : SemiNormedGrp.{u}) where /-- The underlying `NormedAddGroupHom`. -/ hom' : NormedAddGroupHom M N instance : LargeCategory.{u} SemiNormedGrp where Hom X Y := Hom X Y id X := ⟨NormedAddGroupHom.id X⟩ comp f g := ⟨g.hom'.comp f.hom'⟩ instance : ConcreteCategory SemiNormedGrp (NormedAddGroupHom · ·) where hom f := f.hom' ofHom f := ⟨f⟩ /-- Turn a morphism in `SemiNormedGrp` back into a `NormedAddGroupHom`. -/ abbrev Hom.hom {M N : SemiNormedGrp.{u}} (f : Hom M N) := ConcreteCategory.hom (C := SemiNormedGrp) f /-- Typecheck a `NormedAddGroupHom` as a morphism in `SemiNormedGrp`. -/ abbrev ofHom {M N : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] (f : NormedAddGroupHom M N) : of M ⟶ of N := ConcreteCategory.ofHom (C := SemiNormedGrp) f /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (M N : SemiNormedGrp.{u}) (f : Hom M N) := f.hom initialize_simps_projections Hom (hom' → hom) /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[ext] lemma ext {M N : SemiNormedGrp} {f₁ f₂ : M ⟶ N} (h : ∀ (x : M), f₁ x = f₂ x) : f₁ = f₂ := ConcreteCategory.ext_apply h @[simp] lemma hom_id {M : SemiNormedGrp} : (𝟙 M : M ⟶ M).hom = NormedAddGroupHom.id M := rfl /- Provided for rewriting. -/ lemma id_apply (M : SemiNormedGrp) (r : M) : (𝟙 M : M ⟶ M) r = r := by simp @[simp] lemma hom_comp {M N O : SemiNormedGrp} (f : M ⟶ N) (g : N ⟶ O) : (f ≫ g).hom = g.hom.comp f.hom := rfl /- Provided for rewriting. -/ lemma comp_apply {M N O : SemiNormedGrp} (f : M ⟶ N) (g : N ⟶ O) (r : M) : (f ≫ g) r = g (f r) := by simp @[ext] lemma hom_ext {M N : SemiNormedGrp} {f g : M ⟶ N} (hf : f.hom = g.hom) : f = g := Hom.ext hf @[simp] lemma hom_ofHom {M N : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] (f : NormedAddGroupHom M N) : (ofHom f).hom = f := rfl @[simp] lemma ofHom_hom {M N : SemiNormedGrp} (f : M ⟶ N) : ofHom (Hom.hom f) = f := rfl @[simp] lemma ofHom_id {M : Type u} [SeminormedAddCommGroup M] : ofHom (NormedAddGroupHom.id M) = 𝟙 (of M) := rfl @[simp] lemma ofHom_comp {M N O : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] [SeminormedAddCommGroup O] (f : NormedAddGroupHom M N) (g : NormedAddGroupHom N O) : ofHom (g.comp f) = ofHom f ≫ ofHom g := rfl lemma ofHom_apply {M N : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] (f : NormedAddGroupHom M N) (r : M) : ofHom f r = f r := rfl lemma inv_hom_apply {M N : SemiNormedGrp} (e : M ≅ N) (r : M) : e.inv (e.hom r) = r := by simp lemma hom_inv_apply {M N : SemiNormedGrp} (e : M ≅ N) (s : N) : e.hom (e.inv s) = s := by simp theorem coe_of (V : Type u) [SeminormedAddCommGroup V] : (SemiNormedGrp.of V : Type u) = V := rfl theorem coe_id (V : SemiNormedGrp) : (𝟙 V : V → V) = id := rfl theorem coe_comp {M N K : SemiNormedGrp} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : M → K) = g ∘ f := rfl instance : Inhabited SemiNormedGrp := ⟨of PUnit⟩ instance {M N : SemiNormedGrp} : Zero (M ⟶ N) where zero := ofHom 0 @[simp] theorem hom_zero {V W : SemiNormedGrp} : (0 : V ⟶ W).hom = 0 := rfl theorem zero_apply {V W : SemiNormedGrp} (x : V) : (0 : V ⟶ W) x = 0 := rfl instance : Limits.HasZeroMorphisms.{u, u + 1} SemiNormedGrp where theorem isZero_of_subsingleton (V : SemiNormedGrp) [Subsingleton V] : Limits.IsZero V := by refine ⟨fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩⟩ · ext x; have : x = 0 := Subsingleton.elim _ _; simp only [this, map_zero] · ext; apply Subsingleton.elim instance hasZeroObject : Limits.HasZeroObject SemiNormedGrp.{u} := ⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩ theorem iso_isometry_of_normNoninc {V W : SemiNormedGrp} (i : V ≅ W) (h1 : i.hom.hom.NormNoninc) (h2 : i.inv.hom.NormNoninc) : Isometry i.hom := by apply AddMonoidHomClass.isometry_of_norm intro v apply le_antisymm (h1 v) calc ‖v‖ = ‖i.inv (i.hom v)‖ := by rw [← comp_apply, Iso.hom_inv_id, id_apply] _ ≤ ‖i.hom v‖ := h2 _ instance Hom.add {M N : SemiNormedGrp} : Add (M ⟶ N) where add f g := ofHom (f.hom + g.hom) @[simp] theorem hom_add {V W : SemiNormedGrp} (f g : V ⟶ W) : (f + g).hom = f.hom + g.hom := rfl instance Hom.neg {M N : SemiNormedGrp} : Neg (M ⟶ N) where neg f := ofHom (- f.hom) @[simp] theorem hom_neg {V W : SemiNormedGrp} (f : V ⟶ W) : (-f).hom = - f.hom := rfl instance Hom.sub {M N : SemiNormedGrp} : Sub (M ⟶ N) where sub f g := ofHom (f.hom - g.hom) @[simp] theorem hom_sub {V W : SemiNormedGrp} (f g : V ⟶ W) : (f - g).hom = f.hom - g.hom := rfl instance Hom.nsmul {M N : SemiNormedGrp} : SMul ℕ (M ⟶ N) where smul n f := ofHom (n • f.hom) @[simp] theorem hom_nsum {V W : SemiNormedGrp} (n : ℕ) (f : V ⟶ W) : (n • f).hom = n • f.hom := rfl instance Hom.zsmul {M N : SemiNormedGrp} : SMul ℤ (M ⟶ N) where smul n f := ofHom (n • f.hom) @[simp] theorem hom_zsum {V W : SemiNormedGrp} (n : ℤ) (f : V ⟶ W) : (n • f).hom = n • f.hom := rfl instance Hom.addCommGroup {V W : SemiNormedGrp} : AddCommGroup (V ⟶ W) := Function.Injective.addCommGroup _ ConcreteCategory.hom_injective rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) end SemiNormedGrp /-- `SemiNormedGrp₁` is a type synonym for `SemiNormedGrp`, which we shall equip with the category structure consisting only of the norm non-increasing maps. -/ structure SemiNormedGrp₁ : Type (u + 1) where /-- The underlying seminormed abelian group. -/ carrier : Type u [str : SeminormedAddCommGroup carrier] attribute [instance] SemiNormedGrp₁.str namespace SemiNormedGrp₁ instance : CoeSort SemiNormedGrp₁ Type* where coe X := X.carrier /-- Construct a bundled `SemiNormedGrp₁` from the underlying type and typeclass. -/ abbrev of (M : Type u) [SeminormedAddCommGroup M] : SemiNormedGrp₁ where carrier := M /-- The type of morphisms in `SemiNormedGrp₁` -/ @[ext] structure Hom (M N : SemiNormedGrp₁.{u}) where /-- The underlying `NormedAddGroupHom`. -/ hom' : NormedAddGroupHom M N normNoninc : hom'.NormNoninc instance : LargeCategory.{u} SemiNormedGrp₁ where Hom := Hom id X := ⟨NormedAddGroupHom.id X, NormedAddGroupHom.NormNoninc.id⟩ comp {_ _ _} f g := ⟨g.1.comp f.1, g.2.comp f.2⟩ instance instFunLike (X Y : SemiNormedGrp₁) : FunLike { f : NormedAddGroupHom X Y // f.NormNoninc } X Y where coe f := f.1.toFun coe_injective' _ _ h := Subtype.val_inj.mp (NormedAddGroupHom.coe_injective h) instance : ConcreteCategory SemiNormedGrp₁ fun X Y => { f : NormedAddGroupHom X Y // f.NormNoninc } where hom f := ⟨f.1, f.2⟩ ofHom f := ⟨f.1, f.2⟩ instance (X Y : SemiNormedGrp₁) : AddMonoidHomClass { f : NormedAddGroupHom X Y // f.NormNoninc } X Y where map_add f := map_add f.1 map_zero f := map_zero f.1 /-- Turn a morphism in `SemiNormedGrp₁` back into a norm-nonincreasing `NormedAddGroupHom`. -/ abbrev Hom.hom {M N : SemiNormedGrp₁.{u}} (f : Hom M N) := ConcreteCategory.hom (C := SemiNormedGrp₁) f /-- Promote a `NormedAddGroupHom` to a morphism in `SemiNormedGrp₁`. -/ abbrev mkHom {M N : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] (f : NormedAddGroupHom M N) (i : f.NormNoninc) : SemiNormedGrp₁.of M ⟶ SemiNormedGrp₁.of N := ConcreteCategory.ofHom ⟨f, i⟩ /-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/ def Hom.Simps.hom (M N : SemiNormedGrp₁.{u}) (f : Hom M N) : NormedAddGroupHom M N := f.hom initialize_simps_projections Hom (hom' → hom) instance (X Y : SemiNormedGrp₁) : CoeFun (X ⟶ Y) (fun _ => X → Y) where coe f := f.hom.1 theorem mkHom_apply {M N : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] (f : NormedAddGroupHom M N) (i : f.NormNoninc) (x) : mkHom f i x = f x := rfl /-! The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`. -/ @[ext] lemma ext {M N : SemiNormedGrp₁} {f₁ f₂ : M ⟶ N} (h : ∀ (x : M), f₁ x = f₂ x) : f₁ = f₂ := ConcreteCategory.ext_apply h @[simp] lemma hom_id {M : SemiNormedGrp₁} : (𝟙 M : M ⟶ M).hom = NormedAddGroupHom.id M := rfl /- Provided for rewriting. -/ lemma id_apply (M : SemiNormedGrp₁) (r : M) : (𝟙 M : M ⟶ M) r = r := by simp @[simp] lemma hom_comp {M N O : SemiNormedGrp₁} (f : M ⟶ N) (g : N ⟶ O) : (f ≫ g).hom.1 = g.hom.1.comp f.hom.1 := rfl /- Provided for rewriting. -/ lemma comp_apply {M N O : SemiNormedGrp₁} (f : M ⟶ N) (g : N ⟶ O) (r : M) : (f ≫ g) r = g (f r) := by simp @[ext] lemma hom_ext {M N : SemiNormedGrp₁} {f g : M ⟶ N} (hf : f.hom = g.hom) : f = g := Hom.ext (congr_arg Subtype.val hf) @[simp] lemma hom_mkHom {M N : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] (f : NormedAddGroupHom M N) (hf : f.NormNoninc) : (mkHom f hf).hom = f := rfl @[simp] lemma mkHom_hom {M N : SemiNormedGrp₁} (f : M ⟶ N) : mkHom (Hom.hom f) f.normNoninc = f := rfl @[simp] lemma mkHom_id {M : Type u} [SeminormedAddCommGroup M] : mkHom (NormedAddGroupHom.id M) NormedAddGroupHom.NormNoninc.id = 𝟙 (of M) := rfl @[simp] lemma mkHom_comp {M N O : Type u} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] [SeminormedAddCommGroup O] (f : NormedAddGroupHom M N) (g : NormedAddGroupHom N O) (hf : f.NormNoninc) (hg : g.NormNoninc) (hgf : (g.comp f).NormNoninc) : mkHom (g.comp f) hgf = mkHom f hf ≫ mkHom g hg := rfl @[simp] lemma inv_hom_apply {M N : SemiNormedGrp₁} (e : M ≅ N) (r : M) : e.inv (e.hom r) = r := by rw [← comp_apply] simp @[simp] lemma hom_inv_apply {M N : SemiNormedGrp₁} (e : M ≅ N) (s : N) : e.hom (e.inv s) = s := by rw [← comp_apply] simp instance (M : SemiNormedGrp₁) : SeminormedAddCommGroup M := M.str /-- Promote an isomorphism in `SemiNormedGrp` to an isomorphism in `SemiNormedGrp₁`. -/ @[simps] def mkIso {M N : SemiNormedGrp} (f : M ≅ N) (i : f.hom.hom.NormNoninc) (i' : f.inv.hom.NormNoninc) : SemiNormedGrp₁.of M ≅ SemiNormedGrp₁.of N where hom := mkHom f.hom.hom i inv := mkHom f.inv.hom i' instance : HasForget₂ SemiNormedGrp₁ SemiNormedGrp where forget₂ := { obj := fun X => SemiNormedGrp.of X map := fun f => SemiNormedGrp.ofHom f.1 } theorem coe_of (V : Type u) [SeminormedAddCommGroup V] : (SemiNormedGrp₁.of V : Type u) = V := rfl theorem coe_id (V : SemiNormedGrp₁) : ⇑(𝟙 V) = id := rfl theorem coe_comp {M N K : SemiNormedGrp₁} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : M → K) = g ∘ f := rfl instance : Inhabited SemiNormedGrp₁ := ⟨of PUnit⟩ instance (X Y : SemiNormedGrp₁) : Zero (X ⟶ Y) where zero := ⟨0, NormedAddGroupHom.NormNoninc.zero⟩ @[simp] theorem zero_apply {V W : SemiNormedGrp₁} (x : V) : (0 : V ⟶ W) x = 0 := rfl instance : Limits.HasZeroMorphisms.{u, u + 1} SemiNormedGrp₁ where theorem isZero_of_subsingleton (V : SemiNormedGrp₁) [Subsingleton V] : Limits.IsZero V := by refine ⟨fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩⟩ · ext x; have : x = 0 := Subsingleton.elim _ _; simp only [this, map_zero] · ext; apply Subsingleton.elim instance hasZeroObject : Limits.HasZeroObject SemiNormedGrp₁.{u} := ⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩ theorem iso_isometry {V W : SemiNormedGrp₁} (i : V ≅ W) : Isometry i.hom := by change Isometry (⟨⟨i.hom, map_zero _⟩, fun _ _ => map_add _ _ _⟩ : V →+ W) refine AddMonoidHomClass.isometry_of_norm _ ?_ intro v apply le_antisymm (i.hom.2 v) calc ‖v‖ = ‖i.inv (i.hom v)‖ := by rw [← comp_apply, Iso.hom_inv_id, id_apply] _ ≤ ‖i.hom v‖ := i.inv.2 _ end SemiNormedGrp₁
polyXY.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat seq. From mathcomp Require Import fintype tuple finfun bigop fingroup perm div. From mathcomp Require Import ssralg zmodp matrix mxalgebra. From mathcomp Require Import poly polydiv mxpoly binomial. (******************************************************************************) (* This file provides additional primitives and theory for bivariate *) (* polynomials (polynomials of two variables), represented as polynomials *) (* with (univariate) polynomial coefficients : *) (* 'Y == the (generic) second variable (:= 'X%:P). *) (* p^:P == the bivariate polynomial p['X], for p univariate. *) (* := map_poly polyC p (this notation is defined in poly.v). *) (* u.[x, y] == the bivariate polynomial u evaluated at 'X = x, 'Y = y. *) (* := u.[x%:P].[y]. *) (* sizeY u == the size of u in 'Y (1 + the 'Y-degree of u, if u != 0). *) (* := \max_(i < size u) size u`_i. *) (* swapXY u == the bivariate polynomial u['Y, 'X], for u bivariate. *) (* poly_XaY p == the bivariate polynomial p['X + 'Y], for p univariate. *) (* := p^:P \Po ('X + 'Y). *) (* poly_XmY p == the bivariate polynomial p['X * 'Y], for p univariate. *) (* := P^:P \Po ('X * 'Y). *) (* sub_annihilant p q == for univariate p, q != 0, a nonzero polynomial whose *) (* roots include all the differences of roots of p and q, in *) (* all field extensions (:= resultant (poly_XaY p) q^:P). *) (* div_annihilant p q == for polynomials p != 0, q with q.[0] != 0, a nonzero *) (* polynomial whose roots include all the quotients of roots *) (* of p by roots of q, in all field extensions *) (* (:= resultant (poly_XmY p) q^:P). *) (* The latter two "annhilants" provide uniform witnesses for an alternative *) (* proof of the closure of the algebraicOver predicate (see mxpoly.v). The *) (* fact that the annhilant does not depend on the particular choice of roots *) (* of p and q is crucial for the proof of the Primitive Element Theorem (file *) (* separable.v). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory. Local Notation "p ^ f" := (map_poly f p) : ring_scope. Local Notation eval := horner_eval. Notation "'Y" := 'X%:P : ring_scope. Notation "p ^:P" := (p ^ polyC) (format "p ^:P") : ring_scope. Notation "p .[ x , y ]" := (p.[x%:P].[y]) (left associativity, format "p .[ x , y ]") : ring_scope. Section PolyXY_NzRing. Variable R : nzRingType. Implicit Types (u : {poly {poly R}}) (p q : {poly R}) (x : R). Fact swapXY_key : unit. Proof. by []. Qed. Definition swapXY_def u : {poly {poly R}} := (u ^ map_poly polyC).['Y]. Definition swapXY := locked_with swapXY_key swapXY_def. Canonical swapXY_unlockable := [unlockable fun swapXY]. Definition sizeY u : nat := \max_(i < size u) (size u`_i). Definition poly_XaY p : {poly {poly R}} := p^:P \Po ('X + 'Y). Definition poly_XmY p : {poly {poly R}} := p^:P \Po ('X * 'Y). Definition sub_annihilant p q := resultant (poly_XaY p) q^:P. Definition div_annihilant p q := resultant (poly_XmY p) q^:P. Lemma swapXY_polyC p : swapXY p%:P = p^:P. Proof. by rewrite unlock map_polyC hornerC. Qed. Lemma swapXY_X : swapXY 'X = 'Y. Proof. by rewrite unlock map_polyX hornerX. Qed. Lemma swapXY_Y : swapXY 'Y = 'X. Proof. by rewrite swapXY_polyC map_polyX. Qed. Lemma swapXY_is_zmod_morphism : zmod_morphism swapXY. Proof. by move=> u v; rewrite unlock rmorphB !hornerE. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `swapXY_is_zmod_morphism` instead")] Definition swapXY_is_additive := swapXY_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build {poly {poly R}} {poly {poly R}} swapXY swapXY_is_zmod_morphism. Lemma coef_swapXY u i j : (swapXY u)`_i`_j = u`_j`_i. Proof. elim/poly_ind: u => [|u p IHu] in i j *; first by rewrite raddf0 !coef0. rewrite raddfD !coefD /= swapXY_polyC coef_map /= !coefC coefMX. rewrite !(fun_if (fun q : {poly R} => q`_i)) coef0 -IHu; congr (_ + _). by rewrite unlock rmorphM /= map_polyX hornerMX coefMC coefMX. Qed. Lemma swapXYK : involutive swapXY. Proof. by move=> u; apply/polyP=> i; apply/polyP=> j; rewrite !coef_swapXY. Qed. Lemma swapXY_map_polyC p : swapXY p^:P = p%:P. Proof. by rewrite -swapXY_polyC swapXYK. Qed. Lemma swapXY_eq0 u : (swapXY u == 0) = (u == 0). Proof. by rewrite (inv_eq swapXYK) raddf0. Qed. Lemma swapXY_is_monoid_morphism : monoid_morphism swapXY. Proof. split=> [|u v]; first by rewrite swapXY_polyC map_polyC. apply/polyP=> i; apply/polyP=> j; rewrite coef_swapXY !coefM !coef_sum. rewrite (eq_bigr _ (fun _ _ => coefM _ _ _)) exchange_big /=. apply: eq_bigr => j1 _; rewrite coefM; apply: eq_bigr=> i1 _. by rewrite !coef_swapXY. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `swapXY_is_monoid_morphism` instead")] Definition swapXY_is_multiplicative := (fun g => (g.2,g.1)) swapXY_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly {poly R}} {poly {poly R}} swapXY swapXY_is_monoid_morphism. Lemma swapXY_is_scalable : scalable_for (map_poly polyC \; *%R) swapXY. Proof. by move=> p u /=; rewrite -mul_polyC rmorphM /= swapXY_polyC. Qed. HB.instance Definition _ := GRing.isScalable.Build {poly R} {poly {poly R}} {poly {poly R}} (map_poly polyC \; *%R) swapXY swapXY_is_scalable. Lemma swapXY_comp_poly p u : swapXY (p^:P \Po u) = p^:P \Po swapXY u. Proof. rewrite -horner_map; congr _.[_]; rewrite -!map_poly_comp /=. by apply: eq_map_poly => x; rewrite /= swapXY_polyC map_polyC. Qed. Lemma max_size_coefXY u i : size u`_i <= sizeY u. Proof. have [ltiu | /(nth_default 0)->] := ltnP i (size u); last by rewrite size_poly0. exact: (bigmax_sup (Ordinal ltiu)). Qed. Lemma max_size_lead_coefXY u : size (lead_coef u) <= sizeY u. Proof. by rewrite lead_coefE max_size_coefXY. Qed. Lemma max_size_evalX u : size u.['X] <= sizeY u + (size u).-1. Proof. rewrite horner_coef (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP=> i _. rewrite (leq_trans (size_polyMleq _ _)) // size_polyXn addnS. by rewrite leq_add ?max_size_coefXY //= -ltnS (leq_trans _ (leqSpred _)). Qed. Lemma max_size_evalC u x : size u.[x%:P] <= sizeY u. Proof. rewrite horner_coef (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP=> i _. rewrite (leq_trans (size_polyMleq _ _)) // -polyC_exp size_polyC addnC -subn1. by rewrite (leq_trans _ (max_size_coefXY _ i)) // leq_subLR leq_add2r leq_b1. Qed. Lemma sizeYE u : sizeY u = size (swapXY u). Proof. apply/eqP; rewrite eqn_leq; apply/andP; split. apply/bigmax_leqP=> /= i _; apply/leq_sizeP => j /(nth_default 0) u_j_0. by rewrite -coef_swapXY u_j_0 coef0. apply/leq_sizeP=> j le_uY_j; apply/polyP=> i; rewrite coef_swapXY coef0. by rewrite nth_default // (leq_trans _ le_uY_j) ?max_size_coefXY. Qed. Lemma sizeY_eq0 u : (sizeY u == 0) = (u == 0). Proof. by rewrite sizeYE size_poly_eq0 swapXY_eq0. Qed. Lemma sizeY_mulX u : sizeY (u * 'X) = sizeY u. Proof. rewrite !sizeYE rmorphM /= swapXY_X rreg_size //. by have /monic_comreg[_ /rreg_lead] := monicX R. Qed. Lemma swapXY_poly_XaY p : swapXY (poly_XaY p) = poly_XaY p. Proof. by rewrite swapXY_comp_poly rmorphD /= swapXY_X swapXY_Y addrC. Qed. Lemma swapXY_poly_XmY p : swapXY (poly_XmY p) = poly_XmY p. Proof. by rewrite swapXY_comp_poly rmorphM /= swapXY_X swapXY_Y commr_polyX. Qed. Lemma poly_XaY0 : poly_XaY 0 = 0. Proof. by rewrite /poly_XaY rmorph0 comp_poly0. Qed. Lemma poly_XmY0 : poly_XmY 0 = 0. Proof. by rewrite /poly_XmY rmorph0 comp_poly0. Qed. End PolyXY_NzRing. Prenex Implicits swapXY sizeY poly_XaY poly_XmY sub_annihilant div_annihilant. Prenex Implicits swapXYK. Lemma swapXY_map (R S : nzRingType) (f : {additive R -> S}) u : swapXY (u ^ map_poly f) = swapXY u ^ map_poly f. Proof. by apply/polyP=> i; apply/polyP=> j; rewrite !(coef_map, coef_swapXY). Qed. Section PolyXY_ComNzRing. Variable R : comNzRingType. Implicit Types (u : {poly {poly R}}) (p : {poly R}) (x y : R). Lemma horner_swapXY u x : (swapXY u).[x%:P] = u ^ eval x. Proof. apply/polyP=> i /=; rewrite coef_map /= /eval horner_coef coef_sum -sizeYE. rewrite (horner_coef_wide _ (max_size_coefXY u i)); apply: eq_bigr=> j _. by rewrite -polyC_exp coefMC coef_swapXY. Qed. Lemma horner_polyC u x : u.[x%:P] = swapXY u ^ eval x. Proof. by rewrite -horner_swapXY swapXYK. Qed. Lemma horner2_swapXY u x y : (swapXY u).[x, y] = u.[y, x]. Proof. by rewrite horner_swapXY -{1}(hornerC y x) horner_map. Qed. Lemma horner_poly_XaY p v : (poly_XaY p).[v] = p \Po (v + 'X). Proof. by rewrite horner_comp !hornerE. Qed. Lemma horner_poly_XmY p v : (poly_XmY p).[v] = p \Po (v * 'X). Proof. by rewrite horner_comp !hornerE. Qed. End PolyXY_ComNzRing. Section PolyXY_Idomain. Variable R : idomainType. Implicit Types (p q : {poly R}) (x y : R). Lemma size_poly_XaY p : size (poly_XaY p) = size p. Proof. by rewrite size_comp_poly2 ?size_XaddC // size_map_polyC. Qed. Lemma poly_XaY_eq0 p : (poly_XaY p == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_poly_XaY. Qed. Lemma size_poly_XmY p : size (poly_XmY p) = size p. Proof. by rewrite size_comp_poly2 ?size_XmulC ?polyX_eq0 ?size_map_polyC. Qed. Lemma poly_XmY_eq0 p : (poly_XmY p == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_poly_XmY. Qed. Lemma lead_coef_poly_XaY p : lead_coef (poly_XaY p) = (lead_coef p)%:P. Proof. rewrite lead_coef_comp ?size_XaddC // -['Y]opprK -polyCN lead_coefXsubC. by rewrite expr1n mulr1 lead_coef_map_inj //; apply: polyC_inj. Qed. Lemma sub_annihilant_in_ideal p q : 1 < size p -> 1 < size q -> {uv : {poly {poly R}} * {poly {poly R}} | size uv.1 < size q /\ size uv.2 < size p & forall x y, (sub_annihilant p q).[y] = uv.1.[x, y] * p.[x + y] + uv.2.[x, y] * q.[x]}. Proof. rewrite -size_poly_XaY -(size_map_polyC q) => p1_gt1 q1_gt1. have [uv /= [ub_u ub_v Dr]] := resultant_in_ideal p1_gt1 q1_gt1. exists uv => // x y; rewrite -[r in r.[y]](hornerC _ x%:P) Dr. by rewrite !(hornerE, horner_comp). Qed. Lemma sub_annihilantP p q x y : p != 0 -> q != 0 -> p.[x] = 0 -> q.[y] = 0 -> (sub_annihilant p q).[x - y] = 0. Proof. move=> nz_p nz_q px0 qy0. have p_gt1: size p > 1 by have /rootP/root_size_gt1-> := px0. have q_gt1: size q > 1 by have /rootP/root_size_gt1-> := qy0. have [uv /= _ /(_ y)->] := sub_annihilant_in_ideal p_gt1 q_gt1. by rewrite (addrC y) subrK px0 qy0 !mulr0 addr0. Qed. Lemma sub_annihilant_neq0 p q : p != 0 -> q != 0 -> sub_annihilant p q != 0. Proof. rewrite resultant_eq0; set p1 := poly_XaY p => nz_p nz_q. have [nz_p1 nz_q1]: p1 != 0 /\ q^:P != 0 by rewrite poly_XaY_eq0 map_polyC_eq0. rewrite -leqNgt eq_leq //; apply/eqP/Bezout_coprimepPn=> // [[[u v]]] /=. rewrite !size_poly_gt0 -andbA => /and4P[nz_u ltuq nz_v _] Duv. have /eqP/= := congr1 (size \o (lead_coef \o swapXY)) Duv. rewrite ltn_eqF // !rmorphM !lead_coefM (leq_trans (leq_ltn_trans _ ltuq)) //=. rewrite -{2}[u]swapXYK -sizeYE swapXY_poly_XaY lead_coef_poly_XaY. by rewrite mulrC mul_polyC size_scale ?max_size_lead_coefXY ?lead_coef_eq0. rewrite swapXY_map_polyC lead_coefC size_map_polyC. set v1 := lead_coef _; have nz_v1: v1 != 0 by rewrite lead_coef_eq0 swapXY_eq0. rewrite [leqRHS]polySpred ?mulf_neq0 // size_mul //. by rewrite (polySpred nz_v1) addnC addnS polySpred // ltnS leq_addr. Qed. Lemma div_annihilant_in_ideal p q : 1 < size p -> 1 < size q -> {uv : {poly {poly R}} * {poly {poly R}} | size uv.1 < size q /\ size uv.2 < size p & forall x y, (div_annihilant p q).[y] = uv.1.[x, y] * p.[x * y] + uv.2.[x, y] * q.[x]}. Proof. rewrite -size_poly_XmY -(size_map_polyC q) => p1_gt1 q1_gt1. have [uv /= [ub_u ub_v Dr]] := resultant_in_ideal p1_gt1 q1_gt1. exists uv => // x y; rewrite -[r in r.[y]](hornerC _ x%:P) Dr. by rewrite !(hornerE, horner_comp). Qed. Lemma div_annihilant_neq0 p q : p != 0 -> q.[0] != 0 -> div_annihilant p q != 0. Proof. have factorX u: u != 0 -> root u 0 -> exists2 v, v != 0 & u = v * 'X. move=> nz_u /factor_theorem[v]; rewrite subr0 => Du; exists v => //. by apply: contraNneq nz_u => v0; rewrite Du v0 mul0r. have nzX: 'X != 0 := monic_neq0 (monicX _); have rootC0 := root_polyC _ 0. rewrite resultant_eq0 -leqNgt -rootE // => nz_p nz_q0; apply/eq_leq/eqP. have nz_q: q != 0 by apply: contraNneq nz_q0 => ->; rewrite root0. apply/Bezout_coprimepPn; rewrite ?map_polyC_eq0 ?poly_XmY_eq0 // => [[uv]]. rewrite !size_poly_gt0 -andbA ltnNge => /and4P[nz_u /negP ltuq nz_v _] Duv. pose u := swapXY uv.1; pose v := swapXY uv.2. suffices{ltuq}: size q <= sizeY u by rewrite sizeYE swapXYK -size_map_polyC. have{nz_u nz_v} [nz_u nz_v Dvu]: [/\ u != 0, v != 0 & q *: v = u * poly_XmY p]. rewrite !swapXY_eq0; split=> //; apply: (can_inj swapXYK). by rewrite linearZ rmorphM /= !swapXYK swapXY_poly_XmY Duv mulrC. have{Duv} [n ltvn]: {n | size v < n} by exists (size v).+1. elim: n {uv} => // n IHn in p (v) (u) nz_u nz_v Dvu nz_p ltvn *. have Dp0: root (poly_XmY p) 0 = root p 0 by rewrite root_comp !hornerE rootC0. have Dv0: root u 0 || root p 0 = root v 0 by rewrite -Dp0 -rootM -Dvu rootZ. have [v0_0 | nz_v0] := boolP (root v 0); last first. have nz_p0: ~~ root p 0 by apply: contra nz_v0; rewrite -Dv0 orbC => ->. apply: (@leq_trans (size (q * v.[0]))). by rewrite size_mul // (polySpred nz_v0) addnS leq_addr. rewrite -hornerZ Dvu !(horner_comp, hornerE) horner_map mulrC size_Cmul //. by rewrite horner_coef0 max_size_coefXY. have [v1 nz_v1 Dv] := factorX _ _ nz_v v0_0; rewrite Dv size_mulX // in ltvn. have /orP[/factorX[//|u1 nz_u1 Du] | p0_0]: root u 0 || root p 0 by rewrite Dv0. rewrite Du sizeY_mulX; apply: IHn nz_u1 nz_v1 _ nz_p ltvn. by apply: (mulIf (nzX _)); rewrite mulrAC -scalerAl -Du -Dv. have /factorX[|v2 nz_v2 Dv1]: root (swapXY v1) 0; rewrite ?swapXY_eq0 //. suffices: root (swapXY v1 * 'Y) 0 by rewrite mulrC mul_polyC rootZ ?polyX_eq0. have: root (swapXY (q *: v)) 0. by rewrite Dvu rmorphM rootM /= swapXY_poly_XmY Dp0 p0_0 orbT. by rewrite linearZ /= rootM rootC0 (negPf nz_q0) /= Dv rmorphM /= swapXY_X. rewrite ltnS (canRL swapXYK Dv1) -sizeYE sizeY_mulX sizeYE in ltvn. have [p1 nz_p1 Dp] := factorX _ _ nz_p p0_0. apply: IHn nz_u _ _ nz_p1 ltvn; first by rewrite swapXY_eq0. have: 'X * 'Y != 0 :> {poly {poly R}} by rewrite mulf_neq0 ?polyC_eq0 ?nzX. move/mulIf; apply. rewrite -scalerAl mulrA mulrAC -{1}swapXY_X -rmorphM /= -Dv1 swapXYK -Dv Dvu. by rewrite /poly_XmY Dp rmorphM /= map_polyX comp_polyM comp_polyX mulrA. Qed. End PolyXY_Idomain. Section PolyXY_Field. Variables (F E : fieldType) (FtoE : {rmorphism F -> E}). Local Notation pFtoE := (map_poly (GRing.RMorphism.sort FtoE)). Lemma div_annihilantP (p q : {poly E}) (x y : E) : p != 0 -> q != 0 -> y != 0 -> p.[x] = 0 -> q.[y] = 0 -> (div_annihilant p q).[x / y] = 0. Proof. move=> nz_p nz_q nz_y px0 qy0. have p_gt1: size p > 1 by have /rootP/root_size_gt1-> := px0. have q_gt1: size q > 1 by have /rootP/root_size_gt1-> := qy0. have [uv /= _ /(_ y)->] := div_annihilant_in_ideal p_gt1 q_gt1. by rewrite (mulrC y) divfK // px0 qy0 !mulr0 addr0. Qed. Lemma map_sub_annihilantP (p q : {poly F}) (x y : E) : p != 0 -> q != 0 ->(p ^ FtoE).[x] = 0 -> (q ^ FtoE).[y] = 0 -> (sub_annihilant p q ^ FtoE).[x - y] = 0. Proof. move=> nz_p nz_q px0 qy0; have pFto0 := map_poly_eq0 FtoE. rewrite map_resultant ?pFto0 ?lead_coef_eq0 ?map_poly_eq0 ?poly_XaY_eq0 //. rewrite map_comp_poly rmorphD /= map_polyC /= !map_polyX -!map_poly_comp /=. by rewrite !(eq_map_poly (map_polyC _)) !map_poly_comp sub_annihilantP ?pFto0. Qed. Lemma map_div_annihilantP (p q : {poly F}) (x y : E) : p != 0 -> q != 0 -> y != 0 -> (p ^ FtoE).[x] = 0 -> (q ^ FtoE).[y] = 0 -> (div_annihilant p q ^ FtoE).[x / y] = 0. Proof. move=> nz_p nz_q nz_y px0 qy0; have pFto0 := map_poly_eq0 FtoE. rewrite map_resultant ?pFto0 ?lead_coef_eq0 ?map_poly_eq0 ?poly_XmY_eq0 //. rewrite map_comp_poly rmorphM /= map_polyC /= !map_polyX -!map_poly_comp /=. by rewrite !(eq_map_poly (map_polyC _)) !map_poly_comp div_annihilantP ?pFto0. Qed. Lemma root_annihilant x p (pEx := (p ^ pFtoE).[x%:P]) : pEx != 0 -> algebraicOver FtoE x -> exists2 r : {poly F}, r != 0 & forall y, root pEx y -> root (r ^ FtoE) y. Proof. move=> nz_px [q nz_q qx0]. have [/size1_polyC Dp | p_gt1] := leqP (size p) 1. by rewrite {}/pEx Dp map_polyC hornerC map_poly_eq0 in nz_px *; exists p`_0. have nz_p: p != 0 by rewrite -size_poly_gt0 ltnW. have [m le_qm] := ubnP (size q); elim: m => // m IHm in q le_qm nz_q qx0 *. have nz_q1: q^:P != 0 by rewrite map_poly_eq0. have sz_q1: size q^:P = size q by rewrite size_map_polyC. have q1_gt1: size q^:P > 1. by rewrite sz_q1 -(size_map_poly FtoE) (root_size_gt1 _ qx0) ?map_poly_eq0. have [uv _ Dr] := resultant_in_ideal p_gt1 q1_gt1; set r := resultant p _ in Dr. have /eqP q1x0: (q^:P ^ pFtoE).[x%:P] == 0. by rewrite -swapXY_polyC -swapXY_map horner_swapXY !map_polyC polyC_eq0. have [|r_nz] := boolP (r == 0); last first. exists r => // y pxy0; rewrite -[r ^ _](hornerC _ x%:P) -map_polyC Dr. by rewrite rmorphD !rmorphM !hornerE q1x0 mulr0 addr0 rootM pxy0 orbT. rewrite resultant_eq0 => /gtn_eqF/Bezout_coprimepPn[]// [q2 p1] /=. rewrite size_poly_gt0 sz_q1 => /andP[/andP[nz_q2 ltq2] _] Dq. pose n := (size (lead_coef q2)).-1; pose q3 := map_poly (coefp n) q2. have nz_q3: q3 != 0 by rewrite map_poly_eq0_id0 ?lead_coef_eq0. apply: (IHm q3); rewrite ?(leq_ltn_trans (size_poly _ _)) ?(leq_trans ltq2) //. have /polyP/(_ n)/eqP: (q2 ^ pFtoE).[x%:P] = 0. apply: (mulIf nz_px); rewrite -hornerM -rmorphM Dq rmorphM hornerM /= q1x0. by rewrite mul0r mulr0. rewrite coef0; congr (_ == 0); rewrite !horner_coef coef_sum. rewrite size_map_poly !size_map_poly_id0 ?map_poly_eq0 ?lead_coef_eq0 //. by apply: eq_bigr => i _; rewrite -rmorphXn coefMC !coef_map. Qed. Lemma algebraic_root_polyXY x y : (let pEx p := (p ^ map_poly FtoE).[x%:P] in exists2 p, pEx p != 0 & root (pEx p) y) -> algebraicOver FtoE x -> algebraicOver FtoE y. Proof. by case=> p nz_px pxy0 /(root_annihilant nz_px)[r]; exists r; auto. Qed. End PolyXY_Field.
Find.lean
import Mathlib.Tactic.Find theorem add_comm_zero {n} : 0 + n = n + 0 := Nat.add_comm _ _ -- These results are too volatile to test with `#guard_msgs`, -- we just suppress them for now. #guard_msgs (drop info) in #find _ + _ = _ + _ #guard_msgs (drop info) in #find ?n + _ = _ + ?n #guard_msgs (drop info) in #find (_ : Nat) + _ = _ + _ #guard_msgs (drop info) in #find Nat → Nat #guard_msgs (drop info) in #find ?n ≤ ?m → ?n + _ ≤ ?m + _
generic_quotient.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice. From mathcomp Require Import seq fintype. (*****************************************************************************) (* Quotient Types *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* Provided a base type T, this files defines an interface for quotients Q *) (* of the type T with explicit functions for canonical surjection (\pi *) (* : T -> Q) and for choosing a representative (repr : Q -> T). It then *) (* provides a helper to quotient T by a decidable equivalence relation (e *) (* : rel T) if T is a choiceType (or encodable as a choiceType modulo e). *) (* *) (* Reference: Cyril Cohen, Pragmatic Quotient Types in Coq, ITP 2013 *) (* *) (* *** Generic Quotienting *** *) (* quotType T == the type of quotient types based on T *) (* The HB class is called Quotient. *) (* *) (* The quotType interface supports these operations (in quotient_scope): *) (* \pi_Q x == the class in Q of the element x of T *) (* \pi x == the class of x where Q is inferred from the context *) (* repr c == canonical representative in T of the class c *) (* x = y %[mod Q] := \pi_Q x = \pi_Q y *) (* <-> x and y are equal modulo Q *) (* x <> y %[mod Q] := \pi_Q x <> \pi_Q y *) (* x == y %[mod Q] := \pi_Q x == \pi_Q y *) (* x != y %[mod Q] := \pi_Q x != \pi_Q y *) (* *) (* The quotient_scope is delimited by %qT, *) (* The most useful lemmas are piE and reprK. *) (* *) (* List of factories: *) (* isQuotient.Build T Q (reprK : cancel repr pi) == builds the quotient *) (* whose canonical surjection function is (pi : T -> Q) and *) (* whose representative selection function is repr *) (* *** Morphisms *** *) (* One may declare existing functions and predicates as liftings of some *) (* morphisms for a quotient. *) (* PiMorph1 pi_f == where pi_f : {morph \pi : x / f x >-> fq x} *) (* declares fq : Q -> Q as the lifting of f : T -> T *) (* PiMorph2 pi_g == idem with pi_g : {morph \pi : x y / g x y >-> gq x y} *) (* PiMono1 pi_p == idem with pi_p : {mono \pi : x / p x >-> pq x} *) (* PiMono2 pi_r == idem with pi_r : {morph \pi : x y / r x y >-> rq x y} *) (* PiMorph11 pi_f == idem with pi_f : {morph \pi : x / f x >-> fq x} *) (* where fq : Q -> Q' and f : T -> T'. *) (* PiMorph eq == Most general declaration of compatibility, *) (* /!\ use with caution /!\ *) (* One can use the following helpers to build the liftings which may or *) (* may not satisfy the above properties (but if they do not, it is *) (* probably not a good idea to define them): *) (* lift_op1 Q f := lifts f : T -> T *) (* lift_op2 Q g := lifts g : T -> T -> T *) (* lift_fun1 Q p := lifts p : T -> R *) (* lift_fun2 Q r := lifts r : T -> T -> R *) (* lift_op11 Q Q' f := lifts f : T -> T' *) (* There is also the special case of constants and embedding functions *) (* that one may define and declare as compatible with Q using: *) (* lift_cst Q x := lifts x : T to Q *) (* PiConst c := declare the result c of the previous construction as *) (* compatible with Q *) (* lift_embed Q e := lifts e : R -> T to R -> Q *) (* PiEmbed f := declare the result f of the previous construction as *) (* compatible with Q *) (* *) (* *** Quotients that have an eqType structure *** *) (* Having a canonical (eqQuotType e) structure enables piE to replace terms *) (* of the form (x == y) by terms of the form (e x' y') if x and y are *) (* canonical surjections of some x' and y'. *) (* eqQuotType e == the type of quotients types on T which mirror *) (* the equivalence relation (e : rel T) *) (* the HB class is called EqQuotient. *) (* *) (* The most useful property is that an eqQuotType is an eqType. *) (* List of factories: *) (* isEqQuotient.Build T e Q m *) (* == builds an (eqQuotType e) structure on Q from the *) (* morphism property m *) (* where m : {mono \pi : x y / e x y >-> x == y} *) (* *) (* *** Equivalence and quotient by an equivalence *** *) (* EquivRel r er es et == builds an equiv_rel structure based on the *) (* reflexivity, symmetry and transitivity property *) (* of a boolean relation. *) (* {eq_quot e} == builds the quotType of T by equiv *) (* where e : rel T is an equiv_rel *) (* and T is a choiceType or a (choiceTypeMod e) *) (* it is canonically an eqType, a choiceType, *) (* a quotType and an eqQuotType *) (* x = y %[mod_eq e] := x = y %[mod {eq_quot e}] *) (* <-> x and y are equal modulo e *) (* ... *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope quotient_scope. Reserved Notation "\pi_ Q" (at level 0, format "\pi_ Q"). Reserved Notation "\pi" (format "\pi"). Reserved Notation "{pi_ Q a }" (Q at next level, format "{pi_ Q a }"). Reserved Notation "{pi a }" (format "{pi a }"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x == y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' == y '/' %[mod_eq e ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x = y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' = y '/' %[mod_eq e ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x != y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' != y '/' %[mod_eq e ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x <> y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' <> y '/' %[mod_eq e ] ']'"). Reserved Notation "{eq_quot e }" (format "{eq_quot e }"). Delimit Scope quotient_scope with qT. Local Open Scope quotient_scope. (*****************************************) (* Definition of the quotient interface. *) (*****************************************) HB.mixin Record isQuotient T (qT : Type) := { repr_of : qT -> T; quot_pi_subdef : T -> qT; repr_ofK_subproof : cancel repr_of quot_pi_subdef }. #[short(type="quotType")] HB.structure Definition Quotient T := { qT of isQuotient T qT }. Arguments repr_of [T qT] : rename. Section QuotientDef. Variable T : Type. Variable qT : quotType T. Definition pi_subdef := @quot_pi_subdef _ qT. Local Notation "\pi" := pi_subdef. Lemma repr_ofK : cancel (@repr_of _ _) \pi. Proof. exact: repr_ofK_subproof. Qed. End QuotientDef. Arguments repr_ofK {T qT}. (****************************) (* Protecting some symbols. *) (****************************) HB.lock Definition pi := pi_subdef. HB.lock Definition mpi := pi_subdef. HB.lock Definition repr := repr_of. (*******************) (* Fancy Notations *) (*******************) Arguments pi.body [T]%_type qT%_type. Notation "\pi_ Q" := (@pi _ Q) : quotient_scope. Notation "\pi" := (@pi _ _) (only parsing) : quotient_scope. Notation "x == y %[mod Q ]" := (\pi_Q x == \pi_Q y) : quotient_scope. Notation "x = y %[mod Q ]" := (\pi_Q x = \pi_Q y) : quotient_scope. Notation "x != y %[mod Q ]" := (\pi_Q x != \pi_Q y) : quotient_scope. Notation "x <> y %[mod Q ]" := (\pi_Q x <> \pi_Q y) : quotient_scope. Local Notation "\mpi" := (@mpi _ _). Canonical mpi_unlock := Unlockable mpi.unlock. Canonical pi_unlock := Unlockable pi.unlock. Canonical repr_unlock := Unlockable repr.unlock. Arguments repr {T qT} x. (************************) (* Exporting the theory *) (************************) Section QuotTypeTheory. Variable T : Type. Variable qT : quotType T. Lemma reprK : cancel repr \pi_qT. Proof. by move=> x; rewrite !unlock repr_ofK. Qed. Variant pi_spec (x : T) : T -> Type := PiSpec y of x = y %[mod qT] : pi_spec x y. Lemma piP (x : T) : pi_spec x (repr (\pi_qT x)). Proof. by constructor; rewrite reprK. Qed. Lemma mpiE : \mpi =1 \pi_qT. Proof. by move=> x; rewrite !unlock. Qed. Lemma quotW P : (forall y : T, P (\pi_qT y)) -> forall x : qT, P x. Proof. by move=> Py x; rewrite -[x]reprK; apply: Py. Qed. Lemma quotP P : (forall y : T, repr (\pi_qT y) = y -> P (\pi_qT y)) -> forall x : qT, P x. Proof. by move=> Py x; rewrite -[x]reprK; apply: Py; rewrite reprK. Qed. End QuotTypeTheory. Arguments reprK {T qT} x. (*******************) (* About morphisms *) (*******************) (* This was pi_morph T (x : T) := PiMorph { pi_op : T; _ : x = pi_op }. *) Structure equal_to T (x : T) := EqualTo { equal_val : T; _ : x = equal_val }. Lemma equal_toE (T : Type) (x : T) (m : equal_to x) : equal_val m = x. Proof. by case: m. Qed. Notation piE := (@equal_toE _ _). Canonical equal_to_pi T (qT : quotType T) (x : T) := @EqualTo _ (\pi_qT x) (\pi x) (erefl _). Arguments EqualTo {T x equal_val}. Section Morphism. Variables T U : Type. Variable (qT : quotType T). Variable (qU : quotType U). Variable (f : T -> T) (g : T -> T -> T) (p : T -> U) (r : T -> T -> U). Variable (fq : qT -> qT) (gq : qT -> qT -> qT) (pq : qT -> U) (rq : qT -> qT -> U). Variable (h : T -> U) (hq : qT -> qU). Hypothesis pi_f : {morph \pi : x / f x >-> fq x}. Hypothesis pi_g : {morph \pi : x y / g x y >-> gq x y}. Hypothesis pi_p : {mono \pi : x / p x >-> pq x}. Hypothesis pi_r : {mono \pi : x y / r x y >-> rq x y}. Hypothesis pi_h : forall (x : T), \pi_qU (h x) = hq (\pi_qT x). Variables (a b : T) (x : equal_to (\pi_qT a)) (y : equal_to (\pi_qT b)). (* Internal Lemmas : do not use directly *) Lemma pi_morph1 : \pi (f a) = fq (equal_val x). Proof. by rewrite !piE. Qed. Lemma pi_morph2 : \pi (g a b) = gq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed. Lemma pi_mono1 : p a = pq (equal_val x). Proof. by rewrite !piE. Qed. Lemma pi_mono2 : r a b = rq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed. Lemma pi_morph11 : \pi (h a) = hq (equal_val x). Proof. by rewrite !piE. Qed. End Morphism. Arguments pi_morph1 {T qT f fq}. Arguments pi_morph2 {T qT g gq}. Arguments pi_mono1 {T U qT p pq}. Arguments pi_mono2 {T U qT r rq}. Arguments pi_morph11 {T U qT qU h hq}. Notation "{pi_ Q a }" := (equal_to (\pi_Q a)) : quotient_scope. Notation "{pi a }" := (equal_to (\pi a)) : quotient_scope. (* Declaration of morphisms *) Notation PiMorph pi_x := (EqualTo pi_x). Notation PiMorph1 pi_f := (fun a (x : {pi a}) => EqualTo (pi_morph1 pi_f a x)). Notation PiMorph2 pi_g := (fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_morph2 pi_g a b x y)). Notation PiMono1 pi_p := (fun a (x : {pi a}) => EqualTo (pi_mono1 pi_p a x)). Notation PiMono2 pi_r := (fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_mono2 pi_r a b x y)). Notation PiMorph11 pi_f := (fun a (x : {pi a}) => EqualTo (pi_morph11 pi_f a x)). (* lifting helpers *) Notation lift_op1 Q f := (locked (fun x : Q => \pi_Q (f (repr x)) : Q)). Notation lift_op2 Q g := (locked (fun x y : Q => \pi_Q (g (repr x) (repr y)) : Q)). Notation lift_fun1 Q f := (locked (fun x : Q => f (repr x))). Notation lift_fun2 Q g := (locked (fun x y : Q => g (repr x) (repr y))). Notation lift_op11 Q Q' f := (locked (fun x : Q => \pi_Q' (f (repr x)) : Q')). (* constant declaration *) Notation lift_cst Q x := (locked (\pi_Q x : Q)). Notation PiConst a := (@EqualTo _ _ a (lock _)). (* embedding declaration, please don't redefine \pi *) Notation lift_embed qT e := (locked (fun x => \pi_qT (e x) : qT)). Lemma eq_lock T T' e : e =1 (@locked (T -> T') (fun x : T => e x)). Proof. by rewrite -lock. Qed. Prenex Implicits eq_lock. Notation PiEmbed e := (fun x => @EqualTo _ _ (e x) (eq_lock (fun _ => \pi _) _)). (********************) (* About eqQuotType *) (********************) HB.mixin Record isEqQuotient T (eq_quot_op : rel T) (Q : Type) of isQuotient T Q & hasDecEq Q := { pi_eq_quot : {mono \pi_Q : x y / eq_quot_op x y >-> x == y} }. #[short(type="eqQuotType")] HB.structure Definition EqQuotient T eq_quot_op := {Q of isEqQuotient T eq_quot_op Q & Quotient T Q & hasDecEq Q}. Canonical pi_eq_quot_mono T eq_quot_op eqT := PiMono2 (@pi_eq_quot T eq_quot_op eqT). (**************************************************************************) (* Even if a quotType is a natural subType, we do not make this subType *) (* canonical, to allow the user to define the subtyping he wants. However *) (* one can: *) (* - get the hasDecEq and the hasChoice by subtyping *) (* - get the subType structure and maybe declare it Canonical. *) (**************************************************************************) Definition quot_type_of T (qT : quotType T) : Type := qT. Arguments quot_type_of T%_type qT%_type : clear implicits. Notation quot_type Q := (quot_type_of _ Q). HB.instance Definition _ T (qT : quotType T) := Quotient.on (quot_type qT). Module QuotSubType. Section QuotSubType. Variable (T : eqType) (qT : quotType T). Definition Sub x (px : repr (\pi_qT x) == x) := \pi_qT x. Lemma qreprK x Px : repr (@Sub x Px) = x. Proof. by rewrite /Sub (eqP Px). Qed. Lemma sortPx (x : qT) : repr (\pi_qT (repr x)) == repr x. Proof. by rewrite !reprK eqxx. Qed. Lemma sort_Sub (x : qT) : x = Sub (sortPx x). Proof. by rewrite /Sub reprK. Qed. Lemma reprP K (PK : forall x Px, K (@Sub x Px)) u : K u. Proof. by rewrite (sort_Sub u); apply: PK. Qed. #[export] HB.instance Definition _ := isSub.Build _ _ (quot_type qT) reprP qreprK. #[export] HB.instance Definition _ := [Equality of quot_type qT by <:]. End QuotSubType. Module Exports. HB.reexport. End Exports. End QuotSubType. Export QuotSubType.Exports. HB.instance Definition _ (T : choiceType) (qT : quotType T) := [Choice of quot_type qT by <:]. HB.instance Definition _ (T : countType) (qT : quotType T) := [Countable of quot_type qT by <:]. HB.instance Definition _ (T : finType) (qT : quotType T) := [Finite of quot_type qT by <:]. Notation "[ 'Sub' Q 'of' T 'by' %/ ]" := (SubType.copy Q%type (quot_type_of T Q%type)) (format "[ 'Sub' Q 'of' T 'by' %/ ]") : form_scope. Notation "[ 'Sub' Q 'by' %/ ]" := (SubType.copy Q%type (quot_type Q)) (format "[ 'Sub' Q 'by' %/ ]") : form_scope. Notation "[ 'Equality' 'of' Q 'by' <:%/ ]" := (Equality.copy Q%type (quot_type Q)) (format "[ 'Equality' 'of' Q 'by' <:%/ ]") : form_scope. Notation "[ 'Choice' 'of' Q 'by' <:%/ ]" := (Choice.copy Q%type (quot_type Q)) (format "[ 'Choice' 'of' Q 'by' <:%/ ]") : form_scope. Notation "[ 'Countable' 'of' Q 'by' <:%/ ]" := (Countable.copy Q%type (quot_type Q)) (format "[ 'Countable' 'of' Q 'by' <:%/ ]") : form_scope. Notation "[ 'Finite' 'of' Q 'by' <:%/ ]" := (Finite.copy Q%type (quot_type Q)) (format "[ 'Finite' 'of' Q 'by' <:%/ ]") : form_scope. (****************************************************) (* Definition of a (decidable) equivalence relation *) (****************************************************) Section EquivRel. Variable T : Type. Lemma left_trans (e : rel T) : symmetric e -> transitive e -> left_transitive e. Proof. by move=> s t ? * ?; apply/idP/idP; apply: t; rewrite // s. Qed. Lemma right_trans (e : rel T) : symmetric e -> transitive e -> right_transitive e. Proof. by move=> s t ? * x; rewrite ![e x _]s; apply: left_trans. Qed. Variant equiv_class_of (equiv : rel T) := EquivClass of reflexive equiv & symmetric equiv & transitive equiv. Record equiv_rel := EquivRelPack { equiv :> rel T; _ : equiv_class_of equiv }. Variable e : equiv_rel. Definition equiv_class := let: EquivRelPack _ ce as e' := e return equiv_class_of e' in ce. Definition equiv_pack (r : rel T) ce of phant_id ce equiv_class := @EquivRelPack r ce. Lemma equiv_refl x : e x x. Proof. by case: e => [] ? []. Qed. Lemma equiv_sym : symmetric e. Proof. by case: e => [] ? []. Qed. Lemma equiv_trans : transitive e. Proof. by case: e => [] ? []. Qed. Lemma eq_op_trans (T' : eqType) : transitive (@eq_op T'). Proof. by move=> x y z /eqP -> /eqP ->. Qed. Lemma equiv_ltrans: left_transitive e. Proof. by apply: left_trans; [apply: equiv_sym|apply: equiv_trans]. Qed. Lemma equiv_rtrans: right_transitive e. Proof. by apply: right_trans; [apply: equiv_sym|apply: equiv_trans]. Qed. End EquivRel. #[global] Hint Resolve equiv_refl : core. Notation EquivRel r er es et := (@EquivRelPack _ r (EquivClass er es et)). Notation "[ 'equiv_rel' 'of' e ]" := (@equiv_pack _ _ e _ id) (format "[ 'equiv_rel' 'of' e ]") : form_scope. (**************************************************) (* Encoding to another type modulo an equivalence *) (**************************************************) Section EncodingModuloRel. Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : rel D). Variant encModRel_class_of (r : rel D) := EncModRelClassPack of (forall x, r x x -> r (ED (DE x)) x) & (r =2 e). Record encModRel := EncModRelPack { enc_mod_rel :> rel D; _ : encModRel_class_of enc_mod_rel }. Variable r : encModRel. Definition encModRelClass := let: EncModRelPack _ c as r' := r return encModRel_class_of r' in c. Definition encModRelP (x : D) : r x x -> r (ED (DE x)) x. Proof. by case: r => [] ? [] /= he _ /he. Qed. Definition encModRelE : r =2 e. Proof. by case: r => [] ? []. Qed. Definition encoded_equiv : rel E := [rel x y | r (ED x) (ED y)]. End EncodingModuloRel. Notation EncModRelClass m := (EncModRelClassPack (fun x _ => m x) (fun _ _ => erefl _)). Notation EncModRel r m := (@EncModRelPack _ _ _ _ _ r (EncModRelClass m)). Section EncodingModuloEquiv. Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : equiv_rel D). Variable (r : encModRel ED DE e). Lemma enc_mod_rel_is_equiv : equiv_class_of (enc_mod_rel r). Proof. split => [x|x y|y x z]; rewrite !encModRelE //; first by rewrite equiv_sym. by move=> exy /(equiv_trans exy). Qed. Definition enc_mod_rel_equiv_rel := EquivRelPack enc_mod_rel_is_equiv. Definition encModEquivP (x : D) : r (ED (DE x)) x. Proof. by rewrite encModRelP ?encModRelE. Qed. Local Notation e' := (encoded_equiv r). Lemma encoded_equivE : e' =2 [rel x y | e (ED x) (ED y)]. Proof. by move=> x y; rewrite /encoded_equiv /= encModRelE. Qed. Local Notation e'E := encoded_equivE. Lemma encoded_equiv_is_equiv : equiv_class_of e'. Proof. split => [x|x y|y x z]; rewrite !e'E //=; first by rewrite equiv_sym. by move=> exy /(equiv_trans exy). Qed. Canonical encoded_equiv_equiv_rel := EquivRelPack encoded_equiv_is_equiv. Lemma encoded_equivP x : e' (DE (ED x)) x. Proof. by rewrite /encoded_equiv /= encModEquivP. Qed. End EncodingModuloEquiv. (**************************************) (* Quotient by a equivalence relation *) (**************************************) Module EquivQuot. Section EquivQuot. Variables (D : Type) (C : choiceType) (CD : C -> D) (DC : D -> C). Variables (eD : equiv_rel D) (encD : encModRel CD DC eD). Notation eC := (encoded_equiv encD). Definition canon x := choose (eC x) (x). Record equivQuotient := EquivQuotient { erepr : C; _ : (frel canon) erepr erepr }. Definition type_of of (phantom (rel _) encD) := equivQuotient. Lemma canon_id : forall x, (invariant canon canon) x. Proof. move=> x /=; rewrite /canon (@eq_choose _ _ (eC x)). by rewrite (@choose_id _ (eC x) _ x) ?chooseP ?equiv_refl. by move=> y; apply: equiv_ltrans; rewrite equiv_sym /= chooseP. Qed. Definition pi := locked (fun x => EquivQuotient (canon_id x)). Lemma ereprK : cancel erepr pi. Proof. pose T : subType _ := HB.pack equivQuotient [isSub for erepr]. by unlock pi; case=> x hx; apply/(@val_inj _ _ T)/eqP. Qed. Local Notation encDE := (encModRelE encD). Local Notation encDP := (encModEquivP encD). Canonical encD_equiv_rel := EquivRelPack (enc_mod_rel_is_equiv encD). Lemma pi_CD (x y : C) : reflect (pi x = pi y) (eC x y). Proof. apply: (iffP idP) => hxy. apply: (can_inj ereprK); unlock pi canon => /=. rewrite -(@eq_choose _ (eC x) (eC y)); last first. by move=> z; rewrite /eC /=; apply: equiv_ltrans. by apply: choose_id; rewrite ?equiv_refl //. rewrite (equiv_trans (chooseP (equiv_refl _ _))) //=. move: hxy => /(f_equal erepr) /=; unlock pi canon => /= ->. by rewrite equiv_sym /= chooseP. Qed. Lemma pi_DC (x y : D) : reflect (pi (DC x) = pi (DC y)) (eD x y). Proof. apply: (iffP idP)=> hxy. apply/pi_CD; rewrite /eC /=. by rewrite (equiv_ltrans (encDP _)) (equiv_rtrans (encDP _)) /= encDE. rewrite -encDE -(equiv_ltrans (encDP _)) -(equiv_rtrans (encDP _)) /=. exact/pi_CD. Qed. Lemma equivQTP : cancel (CD \o erepr) (pi \o DC). Proof. by move=> x; rewrite /= (pi_CD _ (erepr x) _) ?ereprK /eC /= ?encDP. Qed. Local Notation qT := (type_of (Phantom (rel D) encD)). #[export] HB.instance Definition _ := isQuotient.Build D qT equivQTP. Lemma eqmodP x y : reflect (x = y %[mod qT]) (eD x y). Proof. by apply: (iffP (pi_DC _ _)); rewrite !unlock. Qed. #[export] HB.instance Definition _ := Choice.copy qT (can_type ereprK). Lemma eqmodE x y : x == y %[mod qT] = eD x y. Proof. exact: sameP eqP (@eqmodP _ _). Qed. #[export] HB.instance Definition _ := isEqQuotient.Build _ eD qT eqmodE. End EquivQuot. Module Exports. HB.reexport. End Exports. End EquivQuot. Export EquivQuot.Exports. Arguments EquivQuot.ereprK {D C CD DC eD encD}. Notation "{eq_quot e }" := (@EquivQuot.type_of _ _ _ _ _ _ (Phantom (rel _) e)) : quotient_scope. Notation "x == y %[mod_eq r ]" := (x == y %[mod {eq_quot r}]) : quotient_scope. Notation "x = y %[mod_eq r ]" := (x = y %[mod {eq_quot r}]) : quotient_scope. Notation "x != y %[mod_eq r ]" := (x != y %[mod {eq_quot r}]) : quotient_scope. Notation "x <> y %[mod_eq r ]" := (x <> y %[mod {eq_quot r}]) : quotient_scope. (***********************************************************) (* If the type is directly a choiceType, no need to encode *) (***********************************************************) Section DefaultEncodingModuloRel. Variables (D : choiceType) (r : rel D). Definition defaultEncModRelClass := @EncModRelClassPack D D id id r r (fun _ rxx => rxx) (fun _ _ => erefl _). Canonical defaultEncModRel := EncModRelPack defaultEncModRelClass. End DefaultEncodingModuloRel. (***************************************************) (* Recovering a potential countable type structure *) (***************************************************) Section CountEncodingModuloRel. Variables (D : Type) (C : countType) (CD : C -> D) (DC : D -> C). Variables (eD : equiv_rel D) (encD : encModRel CD DC eD). Notation eC := (encoded_equiv encD). HB.instance Definition _ := Countable.copy {eq_quot encD} (can_type EquivQuot.ereprK). End CountEncodingModuloRel. Section EquivQuotTheory. Variables (T : choiceType) (e : equiv_rel T) (Q : eqQuotType e). Lemma eqmodE x y : x == y %[mod_eq e] = e x y. Proof. by rewrite pi_eq_quot. Qed. Lemma eqmodP x y : reflect (x = y %[mod_eq e]) (e x y). Proof. by rewrite -eqmodE; apply/eqP. Qed. End EquivQuotTheory. Prenex Implicits eqmodE eqmodP. Section EqQuotTheory. Variables (T : Type) (e : rel T) (Q : eqQuotType e). Lemma eqquotE x y : x == y %[mod Q] = e x y. Proof. by rewrite pi_eq_quot. Qed. Lemma eqquotP x y : reflect (x = y %[mod Q]) (e x y). Proof. by rewrite -eqquotE; apply/eqP. Qed. End EqQuotTheory. Prenex Implicits eqquotE eqquotP.
FiniteInfinite.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau -/ import Mathlib.Data.DFinsupp.Defs import Mathlib.Data.Fintype.Pi /-! # Finiteness and infiniteness of the `DFinsupp` type ## Main results * `DFinsupp.fintype`: if the domain and codomain are finite, then `DFinsupp` is finite * `DFinsupp.infinite_of_left`: if the domain is infinite, then `DFinsupp` is infinite * `DFinsupp.infinite_of_exists_right`: if one fiber of the codomain is infinite, then `DFinsupp` is infinite -/ universe u u₁ u₂ v v₁ v₂ v₃ w x y l variable {ι : Type u} {γ : Type w} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂} section FiniteInfinite instance DFinsupp.fintype {ι : Sort _} {π : ι → Sort _} [DecidableEq ι] [∀ i, Zero (π i)] [Fintype ι] [∀ i, Fintype (π i)] : Fintype (Π₀ i, π i) := Fintype.ofEquiv (∀ i, π i) DFinsupp.equivFunOnFintype.symm instance DFinsupp.infinite_of_left {ι : Sort _} {π : ι → Sort _} [∀ i, Nontrivial (π i)] [∀ i, Zero (π i)] [Infinite ι] : Infinite (Π₀ i, π i) := by letI := Classical.decEq ι; choose m hm using fun i => exists_ne (0 : π i) exact Infinite.of_injective _ (DFinsupp.single_left_injective hm) /-- See `DFinsupp.infinite_of_right` for this in instance form, with the drawback that it needs all `π i` to be infinite. -/ theorem DFinsupp.infinite_of_exists_right {ι : Sort _} {π : ι → Sort _} (i : ι) [Infinite (π i)] [∀ i, Zero (π i)] : Infinite (Π₀ i, π i) := letI := Classical.decEq ι Infinite.of_injective (fun j => DFinsupp.single i j) DFinsupp.single_injective /-- See `DFinsupp.infinite_of_exists_right` for the case that only one `π ι` is infinite. -/ instance DFinsupp.infinite_of_right {ι : Sort _} {π : ι → Sort _} [∀ i, Infinite (π i)] [∀ i, Zero (π i)] [Nonempty ι] : Infinite (Π₀ i, π i) := DFinsupp.infinite_of_exists_right (Classical.arbitrary ι) end FiniteInfinite
Homogeneous.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Wieser -/ import Mathlib.Algebra.DirectSum.Internal import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Variables import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.MvPolynomial.WeightedHomogeneous import Mathlib.SetTheory.Cardinal.Basic /-! # Homogeneous polynomials A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. ## Main definitions/lemmas * `IsHomogeneous φ n`: a predicate that asserts that `φ` is homogeneous of degree `n`. * `homogeneousSubmodule σ R n`: the submodule of homogeneous polynomials of degree `n`. * `homogeneousComponent n`: the additive morphism that projects polynomials onto their summand that is homogeneous of degree `n`. * `sum_homogeneousComponent`: every polynomial is the sum of its homogeneous components. -/ namespace MvPolynomial variable {σ : Type*} {τ : Type*} {R : Type*} {S : Type*} /- TODO * show that `MvPolynomial σ R ≃ₐ[R] ⨁ i, homogeneousSubmodule σ R i` -/ open Finsupp /-- A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. -/ def IsHomogeneous [CommSemiring R] (φ : MvPolynomial σ R) (n : ℕ) := IsWeightedHomogeneous 1 φ n variable [CommSemiring R] theorem weightedTotalDegree_one (φ : MvPolynomial σ R) : weightedTotalDegree (1 : σ → ℕ) φ = φ.totalDegree := by simp only [totalDegree, weightedTotalDegree, weight, LinearMap.toAddMonoidHom_coe, linearCombination, Pi.one_apply, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe, id, Algebra.id.smul_eq_mul, mul_one] theorem weightedTotalDegree_rename_of_injective {σ τ : Type*} {e : σ → τ} {w : τ → ℕ} {P : MvPolynomial σ R} (he : Function.Injective e) : weightedTotalDegree w (rename e P) = weightedTotalDegree (w ∘ e) P := by classical unfold weightedTotalDegree rw [support_rename_of_injective he, Finset.sup_image] congr; ext; unfold weight; simp variable (σ R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def homogeneousSubmodule (n : ℕ) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsHomogeneous n } smul_mem' r a ha c hc := by rw [coeff_smul] at hc apply ha intro h apply hc rw [h] exact smul_zero r zero_mem' _ hd := False.elim (hd <| coeff_zero _) add_mem' {a b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h @[simp] lemma weightedHomogeneousSubmodule_one (n : ℕ) : weightedHomogeneousSubmodule R 1 n = homogeneousSubmodule σ R n := rfl variable {σ R} @[simp] theorem mem_homogeneousSubmodule (n : ℕ) (p : MvPolynomial σ R) : p ∈ homogeneousSubmodule σ R n ↔ p.IsHomogeneous n := Iff.rfl variable (σ R) /-- While equal, the former has a convenient definitional reduction. -/ theorem homogeneousSubmodule_eq_finsupp_supported (n : ℕ) : homogeneousSubmodule σ R n = Finsupp.supported _ R { d | d.degree = n } := by simp_rw [degree_eq_weight_one] exact weightedHomogeneousSubmodule_eq_finsupp_supported R 1 n variable {σ R} theorem homogeneousSubmodule_mul (m n : ℕ) : homogeneousSubmodule σ R m * homogeneousSubmodule σ R n ≤ homogeneousSubmodule σ R (m + n) := weightedHomogeneousSubmodule_mul 1 m n section theorem isHomogeneous_monomial {d : σ →₀ ℕ} (r : R) {n : ℕ} (hn : d.degree = n) : IsHomogeneous (monomial d r) n := by rw [degree_eq_weight_one] at hn exact isWeightedHomogeneous_monomial 1 d r hn variable (σ) theorem totalDegree_eq_zero_iff (p : MvPolynomial σ R) : p.totalDegree = 0 ↔ ∀ (m : σ →₀ ℕ) (_ : m ∈ p.support) (x : σ), m x = 0 := by rw [← weightedTotalDegree_one, weightedTotalDegree_eq_zero_iff _ p] exact nonTorsionWeight_of (Function.const σ one_ne_zero) theorem totalDegree_zero_iff_isHomogeneous {p : MvPolynomial σ R} : p.totalDegree = 0 ↔ IsHomogeneous p 0 := by rw [← weightedTotalDegree_one, ← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsHomogeneous] alias ⟨isHomogeneous_of_totalDegree_zero, _⟩ := totalDegree_zero_iff_isHomogeneous theorem isHomogeneous_C (r : R) : IsHomogeneous (C r : MvPolynomial σ R) 0 := by apply isHomogeneous_monomial simp only [Finsupp.degree, Finsupp.zero_apply, Finset.sum_const_zero] variable (R) theorem isHomogeneous_zero (n : ℕ) : IsHomogeneous (0 : MvPolynomial σ R) n := (homogeneousSubmodule σ R n).zero_mem theorem isHomogeneous_one : IsHomogeneous (1 : MvPolynomial σ R) 0 := isHomogeneous_C _ _ variable {σ} theorem isHomogeneous_X (i : σ) : IsHomogeneous (X i : MvPolynomial σ R) 1 := by apply isHomogeneous_monomial rw [Finsupp.degree, Finsupp.support_single_ne_zero _ one_ne_zero, Finset.sum_singleton] exact Finsupp.single_eq_same end namespace IsHomogeneous variable [CommSemiring S] {φ ψ : MvPolynomial σ R} {m n : ℕ} theorem coeff_eq_zero (hφ : IsHomogeneous φ n) {d : σ →₀ ℕ} (hd : d.degree ≠ n) : coeff d φ = 0 := by rw [degree_eq_weight_one] at hd exact IsWeightedHomogeneous.coeff_eq_zero hφ d hd theorem inj_right (hm : IsHomogeneous φ m) (hn : IsHomogeneous φ n) (hφ : φ ≠ 0) : m = n := by obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ rw [← hm hd, ← hn hd] theorem add (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ + ψ) n := (homogeneousSubmodule σ R n).add_mem hφ hψ theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ℕ) (h : ∀ i ∈ s, IsHomogeneous (φ i) n) : IsHomogeneous (∑ i ∈ s, φ i) n := (homogeneousSubmodule σ R n).sum_mem h theorem mul (hφ : IsHomogeneous φ m) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ * ψ) (m + n) := homogeneousSubmodule_mul m n <| Submodule.mul_mem_mul hφ hψ theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → ℕ) (h : ∀ i ∈ s, IsHomogeneous (φ i) (n i)) : IsHomogeneous (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by classical revert h refine Finset.induction_on s ?_ ?_ · intro simp only [isHomogeneous_one, Finset.sum_empty, Finset.prod_empty] · intro i s his IH h simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff] apply (h i (by grind)).mul (IH _) grind lemma C_mul (hφ : φ.IsHomogeneous m) (r : R) : (C r * φ).IsHomogeneous m := by simpa only [zero_add] using (isHomogeneous_C _ _).mul hφ lemma _root_.MvPolynomial.isHomogeneous_C_mul_X (r : R) (i : σ) : (C r * X i).IsHomogeneous 1 := (isHomogeneous_X _ _).C_mul _ lemma pow (hφ : φ.IsHomogeneous m) (n : ℕ) : (φ ^ n).IsHomogeneous (m * n) := by rw [show φ ^ n = ∏ _i ∈ Finset.range n, φ by simp] rw [show m * n = ∑ _i ∈ Finset.range n, m by simp [mul_comm]] apply IsHomogeneous.prod _ _ _ (fun _ _ ↦ hφ) lemma _root_.MvPolynomial.isHomogeneous_X_pow (i : σ) (n : ℕ) : (X (R := R) i ^ n).IsHomogeneous n := by simpa only [one_mul] using (isHomogeneous_X _ _).pow n lemma _root_.MvPolynomial.isHomogeneous_C_mul_X_pow (r : R) (i : σ) (n : ℕ) : (C r * X i ^ n).IsHomogeneous n := (isHomogeneous_X_pow _ _).C_mul _ lemma eval₂ (hφ : φ.IsHomogeneous m) (f : R →+* MvPolynomial τ S) (g : σ → MvPolynomial τ S) (hf : ∀ r, (f r).IsHomogeneous 0) (hg : ∀ i, (g i).IsHomogeneous n) : (eval₂ f g φ).IsHomogeneous (n * m) := by apply IsHomogeneous.sum intro i hi rw [← zero_add (n * m)] apply IsHomogeneous.mul (hf _) _ convert IsHomogeneous.prod _ _ (fun k ↦ n * i k) _ · rw [Finsupp.mem_support_iff] at hi rw [← Finset.mul_sum, ← hφ hi, weight_apply] simp_rw [smul_eq_mul, Finsupp.sum, Pi.one_apply, mul_one] · rintro k - apply (hg k).pow lemma map (hφ : φ.IsHomogeneous n) (f : R →+* S) : (map f φ).IsHomogeneous n := by simpa only [one_mul] using hφ.eval₂ _ _ (fun r ↦ isHomogeneous_C _ (f r)) (isHomogeneous_X _) lemma aeval [Algebra R S] (hφ : φ.IsHomogeneous m) (g : σ → MvPolynomial τ S) (hg : ∀ i, (g i).IsHomogeneous n) : (aeval g φ).IsHomogeneous (n * m) := hφ.eval₂ _ _ (fun _ ↦ isHomogeneous_C _ _) hg section CommRing -- In this section we shadow the semiring `R` with a ring `R`. variable {R σ : Type*} [CommRing R] {φ ψ : MvPolynomial σ R} {n : ℕ} theorem neg (hφ : IsHomogeneous φ n) : IsHomogeneous (-φ) n := (homogeneousSubmodule σ R n).neg_mem hφ theorem sub (hφ : IsHomogeneous φ n) (hψ : IsHomogeneous ψ n) : IsHomogeneous (φ - ψ) n := (homogeneousSubmodule σ R n).sub_mem hφ hψ end CommRing /-- The homogeneous degree bounds the total degree. See also `MvPolynomial.IsHomogeneous.totalDegree` when `φ` is non-zero. -/ lemma totalDegree_le (hφ : IsHomogeneous φ n) : φ.totalDegree ≤ n := by apply Finset.sup_le intro d hd rw [mem_support_iff] at hd simp_rw [Finsupp.sum, ← hφ hd, weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum, le_rfl] theorem totalDegree (hφ : IsHomogeneous φ n) (h : φ ≠ 0) : totalDegree φ = n := by apply le_antisymm hφ.totalDegree_le obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h simp only [← hφ hd, MvPolynomial.totalDegree, Finsupp.sum] replace hd := Finsupp.mem_support_iff.mpr hd simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one] -- Porting note: Original proof did not define `f` exact Finset.le_sup (f := fun s ↦ ∑ x ∈ s.support, s x) hd theorem rename_isHomogeneous {f : σ → τ} (h : φ.IsHomogeneous n) : (rename f φ).IsHomogeneous n := by rw [← φ.support_sum_monomial_coeff, map_sum]; simp_rw [rename_monomial] apply IsHomogeneous.sum _ _ _ fun d hd ↦ isHomogeneous_monomial _ _ intro d hd apply (Finsupp.sum_mapDomain_index_addMonoidHom fun _ ↦ .id ℕ).trans convert h (mem_support_iff.mp hd) simp only [weight_apply, AddMonoidHom.id_apply, Pi.one_apply, smul_eq_mul, mul_one] theorem rename_isHomogeneous_iff {f : σ → τ} (hf : f.Injective) : (rename f φ).IsHomogeneous n ↔ φ.IsHomogeneous n := by refine ⟨fun h d hd ↦ ?_, rename_isHomogeneous⟩ convert ← @h (d.mapDomain f) _ · simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one] exact Finsupp.sum_mapDomain_index_inj (h := fun _ ↦ id) hf · rwa [coeff_rename_mapDomain f hf] lemma finSuccEquiv_coeff_isHomogeneous {N : ℕ} {φ : MvPolynomial (Fin (N + 1)) R} {n : ℕ} (hφ : φ.IsHomogeneous n) (i j : ℕ) (h : i + j = n) : ((finSuccEquiv _ _ φ).coeff i).IsHomogeneous j := by intro d hd rw [finSuccEquiv_coeff_coeff] at hd have h' : (weight 1) (Finsupp.cons i d) = i + j := by simpa [Finset.sum_subset_zero_on_sdiff (g := d.cons i) (d.cons_support (y := i)) (by simp) (fun _ _ ↦ rfl), ← h] using hφ hd simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum_cons, add_right_inj] at h' ⊢ exact h' -- TODO: develop API for `optionEquivLeft` and get rid of the `[Fintype σ]` assumption lemma coeff_isHomogeneous_of_optionEquivLeft_symm [hσ : Finite σ] {p : Polynomial (MvPolynomial σ R)} (hp : ((optionEquivLeft R σ).symm p).IsHomogeneous n) (i j : ℕ) (h : i + j = n) : (p.coeff i).IsHomogeneous j := by obtain ⟨k, ⟨e⟩⟩ := Finite.exists_equiv_fin σ let e' := e.optionCongr.trans (_root_.finSuccEquiv _).symm let F := renameEquiv R e let F' := renameEquiv R e' let φ := F' ((optionEquivLeft R σ).symm p) have hφ : φ.IsHomogeneous n := hp.rename_isHomogeneous suffices IsHomogeneous (F (p.coeff i)) j by rwa [← (IsHomogeneous.rename_isHomogeneous_iff e.injective)] convert hφ.finSuccEquiv_coeff_isHomogeneous i j h using 1 dsimp only [φ, F', F, renameEquiv_apply] rw [finSuccEquiv_rename_finSuccEquiv, AlgEquiv.apply_symm_apply] simp open Polynomial in private lemma exists_eval_ne_zero_of_coeff_finSuccEquiv_ne_zero_aux {N : ℕ} {F : MvPolynomial (Fin (Nat.succ N)) R} {n : ℕ} (hF : IsHomogeneous F n) (hFn : ((finSuccEquiv R N) F).coeff n ≠ 0) : ∃ r, eval r F ≠ 0 := by have hF₀ : F ≠ 0 := by contrapose! hFn; simp [hFn] have hdeg : natDegree (finSuccEquiv R N F) < n + 1 := by linarith [natDegree_finSuccEquiv F, degreeOf_le_totalDegree F 0, hF.totalDegree hF₀] use Fin.cons 1 0 have aux : ∀ i ∈ Finset.range n, constantCoeff ((finSuccEquiv R N F).coeff i) = 0 := by intro i hi rw [Finset.mem_range] at hi apply (hF.finSuccEquiv_coeff_isHomogeneous i (n-i) (by omega)).coeff_eq_zero simp only [Finsupp.degree_zero] rw [← Nat.sub_ne_zero_iff_lt] at hi exact hi.symm simp_rw [eval_eq_eval_mv_eval', eval_one_map, Polynomial.eval_eq_sum_range' hdeg, eval_zero, one_pow, mul_one, map_sum, Finset.sum_range_succ, Finset.sum_eq_zero aux, zero_add] contrapose! hFn ext d rw [coeff_zero] obtain rfl | hd := eq_or_ne d 0 · apply hFn · contrapose! hd ext i rw [Finsupp.coe_zero, Pi.zero_apply] by_cases hi : i ∈ d.support · have := hF.finSuccEquiv_coeff_isHomogeneous n 0 (add_zero _) hd simp only [weight_apply, Pi.one_apply, smul_eq_mul, mul_one, Finsupp.sum] at this rw [Finset.sum_eq_zero_iff_of_nonneg (fun _ _ ↦ zero_le')] at this exact this i hi · simpa using hi section IsDomain -- In this section we shadow the semiring `R` with a domain `R`. variable {R σ : Type*} [CommRing R] [IsDomain R] {F G : MvPolynomial σ R} {n : ℕ} open Cardinal Polynomial private lemma exists_eval_ne_zero_of_totalDegree_le_card_aux {N : ℕ} {F : MvPolynomial (Fin N) R} {n : ℕ} (hF : F.IsHomogeneous n) (hF₀ : F ≠ 0) (hnR : n ≤ #R) : ∃ r, eval r F ≠ 0 := by induction N generalizing n with | zero => use 0 contrapose! hF₀ ext d simpa only [Subsingleton.elim d 0, eval_zero, coeff_zero] using hF₀ | succ N IH => have hdeg : natDegree (finSuccEquiv R N F) < n + 1 := by linarith [natDegree_finSuccEquiv F, degreeOf_le_totalDegree F 0, hF.totalDegree hF₀] obtain ⟨i, hi⟩ : ∃ i : ℕ, (finSuccEquiv R N F).coeff i ≠ 0 := by contrapose! hF₀ exact (finSuccEquiv _ _).injective <| Polynomial.ext <| by simpa using hF₀ have hin : i ≤ n := by contrapose! hi exact coeff_eq_zero_of_natDegree_lt <| (Nat.le_of_lt_succ hdeg).trans_lt hi obtain hFn | hFn := ne_or_eq ((finSuccEquiv R N F).coeff n) 0 · exact hF.exists_eval_ne_zero_of_coeff_finSuccEquiv_ne_zero_aux hFn have hin : i < n := hin.lt_or_eq.elim id <| by aesop obtain ⟨j, hj⟩ : ∃ j, i + (j + 1) = n := (Nat.exists_eq_add_of_lt hin).imp <| by omega obtain ⟨r, hr⟩ : ∃ r, (eval r) (Polynomial.coeff ((finSuccEquiv R N) F) i) ≠ 0 := IH (hF.finSuccEquiv_coeff_isHomogeneous _ _ hj) hi (.trans (by norm_cast; omega) hnR) set φ : R[X] := Polynomial.map (eval r) (finSuccEquiv _ _ F) with hφ have hφ₀ : φ ≠ 0 := fun hφ₀ ↦ hr <| by rw [← coeff_eval_eq_eval_coeff, ← hφ, hφ₀, Polynomial.coeff_zero] have hφR : φ.natDegree < #R := by refine lt_of_lt_of_le ?_ hnR norm_cast refine lt_of_le_of_lt natDegree_map_le ?_ suffices (finSuccEquiv _ _ F).natDegree ≠ n by omega rintro rfl refine leadingCoeff_ne_zero.mpr ?_ hFn simpa using (finSuccEquiv R N).injective.ne hF₀ obtain ⟨r₀, hr₀⟩ : ∃ r₀, Polynomial.eval r₀ φ ≠ 0 := φ.exists_eval_ne_zero_of_natDegree_lt_card hφ₀ hφR use Fin.cons r₀ r rwa [eval_eq_eval_mv_eval'] /-- See `MvPolynomial.IsHomogeneous.eq_zero_of_forall_eval_eq_zero` for a version that assumes `Infinite R`. -/ lemma eq_zero_of_forall_eval_eq_zero_of_le_card (hF : F.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = 0) (hnR : n ≤ #R) : F = 0 := by contrapose! h -- reduce to the case where σ is finite obtain ⟨k, f, hf, F, rfl⟩ := exists_fin_rename F have hF₀ : F ≠ 0 := by rintro rfl; simp at h have hF : F.IsHomogeneous n := by rwa [rename_isHomogeneous_iff hf] at hF obtain ⟨r, hr⟩ := exists_eval_ne_zero_of_totalDegree_le_card_aux hF hF₀ hnR obtain ⟨r, rfl⟩ := (Function.factorsThrough_iff _).mp <| (hf.factorsThrough r) use r rwa [eval_rename] /-- See `MvPolynomial.IsHomogeneous.funext` for a version that assumes `Infinite R`. -/ lemma funext_of_le_card (hF : F.IsHomogeneous n) (hG : G.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = eval r G) (hnR : n ≤ #R) : F = G := by rw [← sub_eq_zero] apply eq_zero_of_forall_eval_eq_zero_of_le_card (hF.sub hG) _ hnR simpa [sub_eq_zero] using h /-- See `MvPolynomial.IsHomogeneous.eq_zero_of_forall_eval_eq_zero_of_le_card` for a version that assumes `n ≤ #R`. -/ lemma eq_zero_of_forall_eval_eq_zero [Infinite R] {F : MvPolynomial σ R} {n : ℕ} (hF : F.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = 0) : F = 0 := by apply eq_zero_of_forall_eval_eq_zero_of_le_card hF h exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite R› /-- See `MvPolynomial.IsHomogeneous.funext_of_le_card` for a version that assumes `n ≤ #R`. -/ lemma funext [Infinite R] {F G : MvPolynomial σ R} {n : ℕ} (hF : F.IsHomogeneous n) (hG : G.IsHomogeneous n) (h : ∀ r : σ → R, eval r F = eval r G) : F = G := by apply funext_of_le_card hF hG h exact (Cardinal.nat_lt_aleph0 _).le.trans <| Cardinal.infinite_iff.mp ‹Infinite R› end IsDomain /-- The homogeneous submodules form a graded ring. This instance is used by `DirectSum.commSemiring` and `DirectSum.algebra`. -/ instance HomogeneousSubmodule.gcommSemiring : SetLike.GradedMonoid (homogeneousSubmodule σ R) where one_mem := isHomogeneous_one σ R mul_mem _ _ _ _ := IsHomogeneous.mul end IsHomogeneous noncomputable section open Finset /-- `homogeneousComponent n φ` is the part of `φ` that is homogeneous of degree `n`. See `sum_homogeneousComponent` for the statement that `φ` is equal to the sum of all its homogeneous components. -/ def homogeneousComponent [CommSemiring R] (n : ℕ) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R := weightedHomogeneousComponent 1 n section HomogeneousComponent open Finset Finsupp variable (n : ℕ) (φ ψ : MvPolynomial σ R) theorem homogeneousComponent_mem : homogeneousComponent n φ ∈ homogeneousSubmodule σ R n := weightedHomogeneousComponent_mem _ φ n theorem coeff_homogeneousComponent (d : σ →₀ ℕ) : coeff d (homogeneousComponent n φ) = if d.degree = n then coeff d φ else 0 := by rw [degree_eq_weight_one] convert coeff_weightedHomogeneousComponent n φ d theorem homogeneousComponent_apply : homogeneousComponent n φ = ∑ d ∈ φ.support with d.degree = n, monomial d (coeff d φ) := by simp_rw [degree_eq_weight_one] convert weightedHomogeneousComponent_apply n φ theorem homogeneousComponent_isHomogeneous : (homogeneousComponent n φ).IsHomogeneous n := weightedHomogeneousComponent_isWeightedHomogeneous n φ @[simp] theorem homogeneousComponent_zero : homogeneousComponent 0 φ = C (coeff 0 φ) := weightedHomogeneousComponent_zero φ (fun _ => Nat.succ_ne_zero Nat.zero) @[simp] theorem homogeneousComponent_C_mul (n : ℕ) (r : R) : homogeneousComponent n (C r * φ) = C r * homogeneousComponent n φ := weightedHomogeneousComponent_C_mul φ n r theorem homogeneousComponent_eq_zero' (h : ∀ d : σ →₀ ℕ, d ∈ φ.support → d.degree ≠ n) : homogeneousComponent n φ = 0 := by simp_rw [degree_eq_weight_one] at h exact weightedHomogeneousComponent_eq_zero' n φ h theorem homogeneousComponent_eq_zero (h : φ.totalDegree < n) : homogeneousComponent n φ = 0 := by apply homogeneousComponent_eq_zero' rw [totalDegree, Finset.sup_lt_iff (lt_of_le_of_lt (Nat.zero_le _) h)] at h intro d hd; exact ne_of_lt (h d hd) theorem sum_homogeneousComponent : (∑ i ∈ range (φ.totalDegree + 1), homogeneousComponent i φ) = φ := by ext1 d suffices φ.totalDegree < d.support.sum d → 0 = coeff d φ by simpa [coeff_sum, coeff_homogeneousComponent] exact fun h => (coeff_eq_zero_of_totalDegree_lt h).symm theorem homogeneousComponent_of_mem {m n : ℕ} {p : MvPolynomial σ R} (h : p ∈ homogeneousSubmodule σ R n) : homogeneousComponent m p = if m = n then p else 0 := weightedHomogeneousComponent_of_mem h end HomogeneousComponent end noncomputable section GradedAlgebra /-- The homogeneous submodules form a graded ring. This instance is used by `DirectSum.commSemiring` and `DirectSum.algebra`. -/ lemma HomogeneousSubmodule.gradedMonoid : SetLike.GradedMonoid (homogeneousSubmodule σ R) := WeightedHomogeneousSubmodule.gradedMonoid /-- The decomposition of `MvPolynomial σ R` into homogeneous submodules. -/ abbrev decomposition : DirectSum.Decomposition (homogeneousSubmodule σ R) := weightedDecomposition R (1 : σ → ℕ) /-- `MvPolynomial σ R` as a graded algebra, graded by the degree. We do not make this a global instance because one may want to consider a different graded algebra structure on `MvPolynomial σ R`, induced by another weight function. To make it a local instance, you may use `attribute [local instance] MvPolynomial.gradedAlgebra`. -/ abbrev gradedAlgebra : GradedAlgebra (homogeneousSubmodule σ R) := weightedGradedAlgebra R (1 : σ → ℕ) theorem decomposition.decompose'_apply (φ : MvPolynomial σ R) (i : ℕ) : (decomposition.decompose' φ i : MvPolynomial σ R) = homogeneousComponent i φ := weightedDecomposition.decompose'_apply R _ φ i theorem decomposition.decompose'_eq : decomposition.decompose' = fun φ : MvPolynomial σ R => DirectSum.mk (fun i : ℕ => ↥(homogeneousSubmodule σ R i)) (φ.support.image Finsupp.degree) fun m => ⟨homogeneousComponent m φ, homogeneousComponent_mem m φ⟩ := by rw [degree_eq_weight_one] rfl end GradedAlgebra end MvPolynomial
NReflectsIso.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.AlgebraicTopology.DoldKan.FunctorN import Mathlib.AlgebraicTopology.DoldKan.Decomposition import Mathlib.CategoryTheory.Idempotents.HomologicalComplex import Mathlib.CategoryTheory.Idempotents.KaroubiKaroubi /-! # N₁ and N₂ reflects isomorphisms In this file, it is shown that the functors `N₁ : SimplicialObject C ⥤ Karoubi (ChainComplex C ℕ)` and `N₂ : Karoubi (SimplicialObject C) ⥤ Karoubi (ChainComplex C ℕ))` reflect isomorphisms for any preadditive category `C`. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Idempotents Opposite Simplicial namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] open MorphComponents instance : (N₁ : SimplicialObject C ⥤ Karoubi (ChainComplex C ℕ)).ReflectsIsomorphisms := ⟨fun {X Y} f => by intro -- restating the result in a way that allows induction on the degree n suffices ∀ n : ℕ, IsIso (f.app (op ⦋n⦌)) by haveI : ∀ Δ : SimplexCategoryᵒᵖ, IsIso (f.app Δ) := fun Δ => this Δ.unop.len apply NatIso.isIso_of_isIso_app -- restating the assumption in a more practical form have h₁ := HomologicalComplex.congr_hom (Karoubi.hom_ext_iff.mp (IsIso.hom_inv_id (N₁.map f))) have h₂ := HomologicalComplex.congr_hom (Karoubi.hom_ext_iff.mp (IsIso.inv_hom_id (N₁.map f))) have h₃ := fun n => Karoubi.HomologicalComplex.p_comm_f_assoc (inv (N₁.map f)) n (f.app (op ⦋n⦌)) simp only [N₁_map_f, Karoubi.comp_f, HomologicalComplex.comp_f, AlternatingFaceMapComplex.map_f, N₁_obj_p, Karoubi.id_f, assoc] at h₁ h₂ h₃ -- we have to construct an inverse to f in degree n, by induction on n intro n induction n with -- degree 0 | zero => use (inv (N₁.map f)).f.f 0 have h₁₀ := h₁ 0 have h₂₀ := h₂ 0 dsimp at h₁₀ h₂₀ simp only [id_comp] at h₁₀ h₂₀ tauto | succ n hn => use φ { a := PInfty.f (n + 1) ≫ (inv (N₁.map f)).f.f (n + 1) b := fun i => inv (f.app (op ⦋n⦌)) ≫ X.σ i } simp only [MorphComponents.id, ← id_φ, ← preComp_φ, preComp, ← postComp_φ, postComp, PInfty_f_naturality_assoc, IsIso.hom_inv_id_assoc, assoc, IsIso.inv_hom_id_assoc, SimplicialObject.σ_naturality, h₁, h₂, h₃, and_self]⟩ theorem compatibility_N₂_N₁_karoubi : N₂ ⋙ (karoubiChainComplexEquivalence C ℕ).functor = karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C ⋙ N₁ ⋙ (karoubiChainComplexEquivalence (Karoubi C) ℕ).functor ⋙ Functor.mapHomologicalComplex (KaroubiKaroubi.equivalence C).inverse _ := by refine CategoryTheory.Functor.ext (fun P => ?_) fun P Q f => ?_ · refine HomologicalComplex.ext ?_ ?_ · ext n · rfl · dsimp simp only [karoubi_PInfty_f, comp_id, PInfty_f_naturality, id_comp] · rintro _ n (rfl : n + 1 = _) ext have h := (AlternatingFaceMapComplex.map P.p).comm (n + 1) n dsimp [N₂, karoubiChainComplexEquivalence, KaroubiHomologicalComplexEquivalence.Functor.obj] at h ⊢ simp only [assoc, Karoubi.eqToHom_f, eqToHom_refl, comp_id, karoubi_alternatingFaceMapComplex_d, karoubi_PInfty_f, ← HomologicalComplex.Hom.comm_assoc, ← h, app_idem_assoc] · ext n dsimp [KaroubiKaroubi.inverse, Functor.mapHomologicalComplex] simp only [karoubi_PInfty_f, HomologicalComplex.eqToHom_f, Karoubi.eqToHom_f, assoc, comp_id, PInfty_f_naturality, app_p_comp, karoubiChainComplexEquivalence_functor_obj_X_p, N₂_obj_p_f, eqToHom_refl, PInfty_f_naturality_assoc, app_comp_p, PInfty_f_idem_assoc] /-- We deduce that `N₂ : Karoubi (SimplicialObject C) ⥤ Karoubi (ChainComplex C ℕ))` reflects isomorphisms from the fact that `N₁ : SimplicialObject (Karoubi C) ⥤ Karoubi (ChainComplex (Karoubi C) ℕ)` does. -/ instance : (N₂ : Karoubi (SimplicialObject C) ⥤ Karoubi (ChainComplex C ℕ)).ReflectsIsomorphisms := ⟨fun f => by intro -- The following functor `F` reflects isomorphism because it is -- a composition of four functors which reflects isomorphisms. -- Then, it suffices to show that `F.map f` is an isomorphism. let F₁ := karoubiFunctorCategoryEmbedding SimplexCategoryᵒᵖ C let F₂ : SimplicialObject (Karoubi C) ⥤ _ := N₁ let F₃ := (karoubiChainComplexEquivalence (Karoubi C) ℕ).functor let F₄ := Functor.mapHomologicalComplex (KaroubiKaroubi.equivalence C).inverse (ComplexShape.down ℕ) let F := F₁ ⋙ F₂ ⋙ F₃ ⋙ F₄ -- Porting note: we have to help Lean4 find the `ReflectsIsomorphisms` instances -- could this be fixed by setting better instance priorities? haveI : F₁.ReflectsIsomorphisms := reflectsIsomorphisms_of_full_and_faithful _ haveI : F₂.ReflectsIsomorphisms := by infer_instance have : IsIso (F.map f) := by simp only [F, F₁] rw [← compatibility_N₂_N₁_karoubi, Functor.comp_map] apply Functor.map_isIso exact isIso_of_reflects_iso f F⟩ end DoldKan end AlgebraicTopology
Finiteness.lean
/- Copyright (c) 2023 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Tactic.Positivity.Core /-! # Finiteness tactic This file implements a basic `finiteness` tactic, designed to solve goals of the form `*** < ∞` and (equivalently) `*** ≠ ∞` in the extended nonnegative reals (`ENNReal`, aka `ℝ≥0∞`). It works recursively according to the syntax of the expression. It is implemented as an `aesop` rule set. ## Syntax Standard `aesop` syntax applies. Namely one can write * `finiteness (add unfold [def1, def2])` to make `finiteness` unfold `def1`, `def2` * `finiteness?` for the tactic to show what proof it found * etc * Note that `finiteness` disables `simp`, so `finiteness (add simp [lemma1, lemma2])` does not do anything more than a bare `finiteness`. We also provide `finiteness_nonterminal` as a version of `finiteness` that doesn't have to close the goal. Note to users: when tagging a lemma for finiteness, prefer tagging a lemma with `≠ ⊤`. Aesop can deduce `< ∞` from `≠ ∞` safely (`Ne.lt_top` is a safe rule), but not conversely (`ne_top_of_lt` is an unsafe rule): in simpler words, aesop tries to use `≠` as its intermediate representation that things are finite, so we do so as well. ## TODO Improve `finiteness` to also deal with other situations, such as balls in proper spaces with a locally finite measure. -/ open Aesop.BuiltinRules in attribute [aesop (rule_sets := [finiteness]) safe -50] assumption intros set_option linter.unusedTactic false in add_aesop_rules safe tactic (rule_sets := [finiteness]) (by positivity) /-- Tactic to solve goals of the form `*** < ∞` and (equivalently) `*** ≠ ∞` in the extended nonnegative reals (`ℝ≥0∞`). -/ macro (name := finiteness) "finiteness" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .reducible, terminal := true, enableSimp := false }) (rule_sets := [$(Lean.mkIdent `finiteness):ident, -default, -builtin])) /-- Tactic to solve goals of the form `*** < ∞` and (equivalently) `*** ≠ ∞` in the extended nonnegative reals (`ℝ≥0∞`). -/ macro (name := finiteness?) "finiteness?" c:Aesop.tactic_clause* : tactic => `(tactic| aesop? $c* (config := { introsTransparency? := some .reducible, terminal := true, enableSimp := false }) (rule_sets := [$(Lean.mkIdent `finiteness):ident, -default, -builtin])) /-- Tactic to solve goals of the form `*** < ∞` and (equivalently) `*** ≠ ∞` in the extended nonnegative reals (`ℝ≥0∞`). -/ macro (name := finiteness_nonterminal) "finiteness_nonterminal" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .reducible, terminal := false, enableSimp := false, warnOnNonterminal := false }) (rule_sets := [$(Lean.mkIdent `finiteness):ident, -default, -builtin])) /-! We register `finiteness` with the `hint` tactic. -/ register_hint finiteness
Basic.lean
/- Copyright (c) 2025 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson, Jun Kwon -/ import Mathlib.Data.Set.Basic import Mathlib.Data.Sym.Sym2 /-! # Multigraphs A multigraph is a set of vertices and a set of edges, together with incidence data that associates each edge `e` with an unordered pair `s(x,y)` of vertices called the *ends* of `e`. The pair of `e` and `s(x,y)` is called a *link*. The vertices `x` and `y` may be equal, in which case `e` is a *loop*. There may be more than one edge with the same ends. If a multigraph has no loops and has at most one edge for every given ends, it is called *simple*, and these objects are also formalized as `SimpleGraph`. This module defines `Graph α β` for a vertex type `α` and an edge type `β`, and gives basic API for incidence, adjacency and extensionality. The design broadly follows [Chou1994]. ## Main definitions For `G : Graph α β`, ... * `V(G)` denotes the vertex set of `G` as a term in `Set α`. * `E(G)` denotes the edge set of `G` as a term in `Set β`. * `G.IsLink e x y` means that the edge `e : β` has vertices `x : α` and `y : α` as its ends. * `G.Inc e x` means that the edge `e : β` has `x` as one of its ends. * `G.Adj x y` means that there is an edge `e` having `x` and `y` as its ends. * `G.IsLoopAt e x` means that `e` is a loop edge with both ends equal to `x`. * `G.IsNonloopAt e x` means that `e` is a non-loop edge with one end equal to `x`. ## Implementation notes Unlike the design of `SimpleGraph`, the vertex and edge sets of `G` are modelled as sets `V(G) : Set α` and `E(G) : Set β`, within ambient types, rather than being types themselves. This mimics the 'embedded set' design used in `Matroid`, which seems to be more convenient for formalizing real-world proofs in combinatorics. A specific advantage is that this allows subgraphs of `G : Graph α β` to also exist on an equal footing with `G` as terms in `Graph α β`, and so there is no need for a `Graph.subgraph` type and all the associated definitions and canonical coercion maps. The same will go for minors and the various other partial orders on multigraphs. The main tradeoff is that parts of the API will need to care about whether a term `x : α` or `e : β` is a 'real' vertex or edge of the graph, rather than something outside the vertex or edge set. This is an issue, but is likely amenable to automation. ## Notation Reflecting written mathematics, we use the compact notations `V(G)` and `E(G)` to refer to the `vertexSet` and `edgeSet` of `G : Graph α β`. If `G.IsLink e x y` then we refer to `e` as `edge` and `x` and `y` as `left` and `right` in names. -/ variable {α β : Type*} {x y z u v w : α} {e f : β} open Set /-- A multigraph with vertices of type `α` and edges of type `β`, as described by vertex and edge sets `vertexSet : Set α` and `edgeSet : Set β`, and a predicate `IsLink` describing whether an edge `e : β` has vertices `x y : α` as its ends. The `edgeSet` structure field can be inferred from `IsLink` via `edge_mem_iff_exists_isLink` (and this structure provides default values for `edgeSet` and `edge_mem_iff_exists_isLink` that use `IsLink`). While the field is not strictly necessary, when defining a graph we often immediately know what the edge set should be, and furthermore having `edgeSet` separate can be convenient for definitional equality reasons. -/ structure Graph (α β : Type*) where /-- The vertex set. -/ vertexSet : Set α /-- The binary incidence predicate, stating that `x` and `y` are the ends of an edge `e`. If `G.IsLink e x y` then we refer to `e` as `edge` and `x` and `y` as `left` and `right`. -/ IsLink : β → α → α → Prop /-- The edge set. -/ edgeSet : Set β := {e | ∃ x y, IsLink e x y} /-- If `e` goes from `x` to `y`, it goes from `y` to `x`. -/ isLink_symm : ∀ ⦃e⦄, e ∈ edgeSet → (Symmetric <| IsLink e) /-- An edge is incident with at most one pair of vertices. -/ eq_or_eq_of_isLink_of_isLink : ∀ ⦃e x y v w⦄, IsLink e x y → IsLink e v w → x = v ∨ x = w /-- An edge `e` is incident to something if and only if `e` is in the edge set. -/ edge_mem_iff_exists_isLink : ∀ e, e ∈ edgeSet ↔ ∃ x y, IsLink e x y := by exact fun _ ↦ Iff.rfl /-- If some edge `e` is incident to `x`, then `x ∈ V`. -/ left_mem_of_isLink : ∀ ⦃e x y⦄, IsLink e x y → x ∈ vertexSet namespace Graph variable {G : Graph α β} /-- `V(G)` denotes the `vertexSet` of a graph `G`. -/ scoped notation "V(" G ")" => Graph.vertexSet G /-- `E(G)` denotes the `edgeSet` of a graph `G`. -/ scoped notation "E(" G ")" => Graph.edgeSet G /-! ### Edge-vertex-vertex incidence -/ lemma IsLink.edge_mem (h : G.IsLink e x y) : e ∈ E(G) := (edge_mem_iff_exists_isLink ..).2 ⟨x, y, h⟩ protected lemma IsLink.symm (h : G.IsLink e x y) : G.IsLink e y x := G.isLink_symm h.edge_mem h lemma IsLink.left_mem (h : G.IsLink e x y) : x ∈ V(G) := G.left_mem_of_isLink h lemma IsLink.right_mem (h : G.IsLink e x y) : y ∈ V(G) := h.symm.left_mem lemma isLink_comm : G.IsLink e x y ↔ G.IsLink e y x := ⟨.symm, .symm⟩ lemma exists_isLink_of_mem_edgeSet (h : e ∈ E(G)) : ∃ x y, G.IsLink e x y := (edge_mem_iff_exists_isLink ..).1 h lemma edgeSet_eq_setOf_exists_isLink : E(G) = {e | ∃ x y, G.IsLink e x y} := Set.ext G.edge_mem_iff_exists_isLink lemma IsLink.left_eq_or_eq (h : G.IsLink e x y) (h' : G.IsLink e z w) : x = z ∨ x = w := G.eq_or_eq_of_isLink_of_isLink h h' lemma IsLink.right_eq_or_eq (h : G.IsLink e x y) (h' : G.IsLink e z w) : y = z ∨ y = w := h.symm.left_eq_or_eq h' lemma IsLink.left_eq_of_right_ne (h : G.IsLink e x y) (h' : G.IsLink e z w) (hzx : x ≠ z) : x = w := (h.left_eq_or_eq h').elim (False.elim ∘ hzx) id lemma IsLink.right_unique (h : G.IsLink e x y) (h' : G.IsLink e x z) : y = z := by obtain rfl | rfl := h.right_eq_or_eq h'.symm · rfl obtain rfl | rfl := h'.right_eq_or_eq h.symm <;> rfl lemma IsLink.left_unique (h : G.IsLink e x z) (h' : G.IsLink e y z) : x = y := h.symm.right_unique h'.symm lemma IsLink.eq_and_eq_or_eq_and_eq {x' y' : α} (h : G.IsLink e x y) (h' : G.IsLink e x' y') : (x = x' ∧ y = y') ∨ (x = y' ∧ y = x') := by obtain rfl | rfl := h.left_eq_or_eq h' · simp [h.right_unique h'] simp [h'.symm.right_unique h] lemma IsLink.isLink_iff (h : G.IsLink e x y) {x' y' : α} : G.IsLink e x' y' ↔ (x = x' ∧ y = y') ∨ (x = y' ∧ y = x') := by refine ⟨h.eq_and_eq_or_eq_and_eq, ?_⟩ rintro (⟨rfl, rfl⟩ | ⟨rfl,rfl⟩) · assumption exact h.symm lemma IsLink.isLink_iff_sym2_eq (h : G.IsLink e x y) {x' y' : α} : G.IsLink e x' y' ↔ s(x,y) = s(x',y') := by rw [h.isLink_iff, Sym2.eq_iff] /-! ### Edge-vertex incidence -/ /-- The unary incidence predicate of `G`. `G.Inc e x` means that the vertex `x` is one or both of the ends of the edge `e`. In the `Inc` namespace, we use `edge` and `vertex` to refer to `e` and `x`. -/ def Inc (G : Graph α β) (e : β) (x : α) : Prop := ∃ y, G.IsLink e x y -- Cannot be @[simp] because `x` can not be inferred by `simp`. lemma Inc.edge_mem (h : G.Inc e x) : e ∈ E(G) := h.choose_spec.edge_mem -- Cannot be @[simp] because `e` can not be inferred by `simp`. lemma Inc.vertex_mem (h : G.Inc e x) : x ∈ V(G) := h.choose_spec.left_mem -- Cannot be @[simp] because `y` can not be inferred by `simp`. lemma IsLink.inc_left (h : G.IsLink e x y) : G.Inc e x := ⟨y, h⟩ -- Cannot be @[simp] because `x` can not be inferred by `simp`. lemma IsLink.inc_right (h : G.IsLink e x y) : G.Inc e y := ⟨x, h.symm⟩ lemma Inc.eq_or_eq_of_isLink (h : G.Inc e x) (h' : G.IsLink e y z) : x = y ∨ x = z := h.choose_spec.left_eq_or_eq h' lemma Inc.eq_of_isLink_of_ne_left (h : G.Inc e x) (h' : G.IsLink e y z) (hxy : x ≠ y) : x = z := (h.eq_or_eq_of_isLink h').elim (False.elim ∘ hxy) id lemma IsLink.isLink_iff_eq (h : G.IsLink e x y) : G.IsLink e x z ↔ z = y := ⟨fun h' ↦ h'.right_unique h, fun h' ↦ h' ▸ h⟩ /-- The binary incidence predicate can be expressed in terms of the unary one. -/ lemma isLink_iff_inc : G.IsLink e x y ↔ G.Inc e x ∧ G.Inc e y ∧ ∀ z, G.Inc e z → z = x ∨ z = y := by refine ⟨fun h ↦ ⟨h.inc_left, h.inc_right, fun z h' ↦ h'.eq_or_eq_of_isLink h⟩, ?_⟩ rintro ⟨⟨x', hx'⟩, ⟨y', hy'⟩, h⟩ obtain rfl | rfl := h _ hx'.inc_right · obtain rfl | rfl := hx'.left_eq_or_eq hy' · assumption exact hy'.symm assumption /-- Given a proof that the edge `e` is incident with the vertex `x` in `G`, noncomputably find the other end of `e`. (If `e` is a loop, this is equal to `x` itself). -/ protected noncomputable def Inc.other (h : G.Inc e x) : α := h.choose @[simp] lemma Inc.isLink_other (h : G.Inc e x) : G.IsLink e x h.other := h.choose_spec @[simp] lemma Inc.inc_other (h : G.Inc e x) : G.Inc e h.other := h.isLink_other.inc_right lemma Inc.eq_or_eq_or_eq (hx : G.Inc e x) (hy : G.Inc e y) (hz : G.Inc e z) : x = y ∨ x = z ∨ y = z := by by_contra! hcon obtain ⟨x', hx'⟩ := hx obtain rfl := hy.eq_of_isLink_of_ne_left hx' hcon.1.symm obtain rfl := hz.eq_of_isLink_of_ne_left hx' hcon.2.1.symm exact hcon.2.2 rfl /-- `G.IsLoopAt e x` means that both ends of the edge `e` are equal to the vertex `x`. -/ def IsLoopAt (G : Graph α β) (e : β) (x : α) : Prop := G.IsLink e x x @[simp] lemma isLink_self_iff : G.IsLink e x x ↔ G.IsLoopAt e x := Iff.rfl lemma IsLoopAt.inc (h : G.IsLoopAt e x) : G.Inc e x := IsLink.inc_left h lemma IsLoopAt.eq_of_inc (h : G.IsLoopAt e x) (h' : G.Inc e y) : x = y := by obtain rfl | rfl := h'.eq_or_eq_of_isLink h <;> rfl -- Cannot be @[simp] because `x` can not be inferred by `simp`. lemma IsLoopAt.edge_mem (h : G.IsLoopAt e x) : e ∈ E(G) := h.inc.edge_mem -- Cannot be @[simp] because `e` can not be inferred by `simp`. lemma IsLoopAt.vertex_mem (h : G.IsLoopAt e x) : x ∈ V(G) := h.inc.vertex_mem /-- `G.IsNonloopAt e x` means that the vertex `x` is one but not both of the ends of the edge =`e`, or equivalently that `e` is incident with `x` but not a loop at `x` - see `Graph.isNonloopAt_iff_inc_not_isLoopAt`. -/ def IsNonloopAt (G : Graph α β) (e : β) (x : α) : Prop := ∃ y ≠ x, G.IsLink e x y lemma IsNonloopAt.inc (h : G.IsNonloopAt e x) : G.Inc e x := h.choose_spec.2.inc_left -- Cannot be @[simp] because `x` can not be inferred by `simp`. lemma IsNonloopAt.edge_mem (h : G.IsNonloopAt e x) : e ∈ E(G) := h.inc.edge_mem -- Cannot be @[simp] because `e` can not be inferred by `simp`. lemma IsNonloopAt.vertex_mem (h : G.IsNonloopAt e x) : x ∈ V(G) := h.inc.vertex_mem lemma IsLoopAt.not_isNonloopAt (h : G.IsLoopAt e x) (y : α) : ¬ G.IsNonloopAt e y := by rintro ⟨z, hyz, hy⟩ rw [← h.eq_of_inc hy.inc_left, ← h.eq_of_inc hy.inc_right] at hyz exact hyz rfl lemma IsNonloopAt.not_isLoopAt (h : G.IsNonloopAt e x) (y : α) : ¬ G.IsLoopAt e y := fun h' ↦ h'.not_isNonloopAt x h lemma isNonloopAt_iff_inc_not_isLoopAt : G.IsNonloopAt e x ↔ G.Inc e x ∧ ¬ G.IsLoopAt e x := ⟨fun h ↦ ⟨h.inc, h.not_isLoopAt _⟩, fun ⟨⟨y, hy⟩, hn⟩ ↦ ⟨y, mt (fun h ↦ h ▸ hy) hn, hy⟩⟩ lemma isLoopAt_iff_inc_not_isNonloopAt : G.IsLoopAt e x ↔ G.Inc e x ∧ ¬ G.IsNonloopAt e x := by simp +contextual [isNonloopAt_iff_inc_not_isLoopAt, iff_def, IsLoopAt.inc] lemma Inc.isLoopAt_or_isNonloopAt (h : G.Inc e x) : G.IsLoopAt e x ∨ G.IsNonloopAt e x := by simp [isNonloopAt_iff_inc_not_isLoopAt, h, em] /-! ### Adjacency -/ /-- `G.Adj x y` means that `G` has an edge whose ends are the vertices `x` and `y`. -/ def Adj (G : Graph α β) (x y : α) : Prop := ∃ e, G.IsLink e x y protected lemma Adj.symm (h : G.Adj x y) : G.Adj y x := ⟨_, h.choose_spec.symm⟩ lemma adj_comm (x y) : G.Adj x y ↔ G.Adj y x := ⟨.symm, .symm⟩ -- Cannot be @[simp] because `y` can not be inferred by `simp`. lemma Adj.left_mem (h : G.Adj x y) : x ∈ V(G) := h.choose_spec.left_mem -- Cannot be @[simp] because `x` can not be inferred by `simp`. lemma Adj.right_mem (h : G.Adj x y) : y ∈ V(G) := h.symm.left_mem lemma IsLink.adj (h : G.IsLink e x y) : G.Adj x y := ⟨e, h⟩ /-! ### Extensionality -/ /-- `edgeSet` can be determined using `IsLink`, so the graph constructed from `G.vertexSet` and `G.IsLink` using any value for `edgeSet` is equal to `G` itself. -/ @[simp] lemma mk_eq_self (G : Graph α β) {E : Set β} (hE : ∀ e, e ∈ E ↔ ∃ x y, G.IsLink e x y) : Graph.mk V(G) G.IsLink E (by simpa [show E = E(G) by simp [Set.ext_iff, hE, G.edge_mem_iff_exists_isLink]] using G.isLink_symm) (fun _ _ _ _ _ h h' ↦ h.left_eq_or_eq h') hE (fun _ _ _ ↦ IsLink.left_mem) = G := by obtain rfl : E = E(G) := by simp [Set.ext_iff, hE, G.edge_mem_iff_exists_isLink] cases G with | _ _ _ _ _ _ h _ => simp /-- Two graphs with the same vertex set and binary incidences are equal. (We use this as the default extensionality lemma rather than adding `@[ext]` to the definition of `Graph`, so it doesn't require equality of the edge sets.) -/ @[ext] protected lemma ext {G₁ G₂ : Graph α β} (hV : V(G₁) = V(G₂)) (h : ∀ e x y, G₁.IsLink e x y ↔ G₂.IsLink e x y) : G₁ = G₂ := by rw [← G₁.mk_eq_self G₁.edge_mem_iff_exists_isLink, ← G₂.mk_eq_self G₂.edge_mem_iff_exists_isLink] convert rfl using 2 · exact hV.symm · simp [funext_iff, h] simp [edgeSet_eq_setOf_exists_isLink, h] /-- Two graphs with the same vertex set and unary incidences are equal. -/ lemma ext_inc {G₁ G₂ : Graph α β} (hV : V(G₁) = V(G₂)) (h : ∀ e x, G₁.Inc e x ↔ G₂.Inc e x) : G₁ = G₂ := Graph.ext hV fun _ _ _ ↦ by simp_rw [isLink_iff_inc, h] end Graph
WithDensity.lean
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap import Mathlib.Probability.Kernel.MeasurableLIntegral /-! # With Density For an s-finite kernel `κ : Kernel α β` and a function `f : α → β → ℝ≥0∞` which is finite everywhere, we define `withDensity κ f` as the kernel `a ↦ (κ a).withDensity (f a)`. This is an s-finite kernel. ## Main definitions * `ProbabilityTheory.Kernel.withDensity κ (f : α → β → ℝ≥0∞)`: kernel `a ↦ (κ a).withDensity (f a)`. It is defined if `κ` is s-finite. If `f` is finite everywhere, then this is also an s-finite kernel. The class of s-finite kernels is the smallest class of kernels that contains finite kernels and which is stable by `withDensity`. Integral: `∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)` ## Main statements * `ProbabilityTheory.Kernel.lintegral_withDensity`: `∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)` -/ open MeasureTheory ProbabilityTheory open scoped MeasureTheory ENNReal NNReal namespace ProbabilityTheory.Kernel variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} variable {κ : Kernel α β} {f : α → β → ℝ≥0∞} /-- Kernel with image `(κ a).withDensity (f a)` if `Function.uncurry f` is measurable, and with image 0 otherwise. If `Function.uncurry f` is measurable, it satisfies `∫⁻ b, g b ∂(withDensity κ f hf a) = ∫⁻ b, f a b * g b ∂(κ a)`. -/ noncomputable def withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0∞) : Kernel α β := @dite _ (Measurable (Function.uncurry f)) (Classical.dec _) (fun hf => (⟨fun a => (κ a).withDensity (f a), by refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [withDensity_apply _ hs] exact hf.setLIntegral_kernel_prod_right hs⟩ : Kernel α β)) fun _ => 0 theorem withDensity_of_not_measurable (κ : Kernel α β) [IsSFiniteKernel κ] (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical exact dif_neg hf protected theorem withDensity_apply (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) : withDensity κ f a = (κ a).withDensity (f a) := by classical rw [withDensity, dif_pos hf] rfl protected theorem withDensity_apply' (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) (s : Set β) : withDensity κ f a s = ∫⁻ b in s, f a b ∂κ a := by rw [Kernel.withDensity_apply κ hf, withDensity_apply' _ s] nonrec lemma withDensity_congr_ae (κ : Kernel α β) [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) (hfg : ∀ a, f a =ᵐ[κ a] g a) : withDensity κ f = withDensity κ g := by ext a rw [Kernel.withDensity_apply _ hf,Kernel.withDensity_apply _ hg, withDensity_congr_ae (hfg a)] nonrec lemma withDensity_absolutelyContinuous [IsSFiniteKernel κ] (f : α → β → ℝ≥0∞) (a : α) : Kernel.withDensity κ f a ≪ κ a := by by_cases hf : Measurable (Function.uncurry f) · rw [Kernel.withDensity_apply _ hf] exact withDensity_absolutelyContinuous _ _ · rw [withDensity_of_not_measurable _ hf] simp [Measure.AbsolutelyContinuous.zero] @[simp] lemma withDensity_one (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ 1 = κ := by ext; rw [Kernel.withDensity_apply _ measurable_const]; simp @[simp] lemma withDensity_one' (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ (fun _ _ ↦ 1) = κ := Kernel.withDensity_one _ @[simp] lemma withDensity_zero (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ 0 = 0 := by ext; rw [Kernel.withDensity_apply _ measurable_const]; simp @[simp] lemma withDensity_zero' (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ (fun _ _ ↦ 0) = 0 := Kernel.withDensity_zero _ theorem lintegral_withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) : ∫⁻ b, g b ∂withDensity κ f a = ∫⁻ b, f a b * g b ∂κ a := by rw [Kernel.withDensity_apply _ hf, lintegral_withDensity_eq_lintegral_mul _ (Measurable.of_uncurry_left hf) hg] simp_rw [Pi.mul_apply] theorem integral_withDensity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0} (hg : Measurable (Function.uncurry g)) : ∫ b, f b ∂withDensity κ (fun a b => g a b) a = ∫ b, g a b • f b ∂κ a := by rw [Kernel.withDensity_apply, integral_withDensity_eq_integral_smul] · fun_prop · fun_prop theorem withDensity_add_left (κ η : Kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] (f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f := by by_cases hf : Measurable (Function.uncurry f) · ext a s simp only [Kernel.withDensity_apply _ hf, coe_add, Pi.add_apply, withDensity_add_measure, Measure.add_apply] · simp_rw [withDensity_of_not_measurable _ hf] rw [zero_add] theorem withDensity_kernel_sum [Countable ι] (κ : ι → Kernel α β) (hκ : ∀ i, IsSFiniteKernel (κ i)) (f : α → β → ℝ≥0∞) : withDensity (Kernel.sum κ) f = Kernel.sum fun i => withDensity (κ i) f := by by_cases hf : Measurable (Function.uncurry f) · ext1 a simp_rw [sum_apply, Kernel.withDensity_apply _ hf, sum_apply, withDensity_sum (fun n => κ n a) (f a)] · simp_rw [withDensity_of_not_measurable _ hf] exact sum_zero.symm lemma withDensity_add_right [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) : withDensity κ (f + g) = withDensity κ f + withDensity κ g := by ext a rw [coe_add, Pi.add_apply, Kernel.withDensity_apply _ hf, Kernel.withDensity_apply _ hg, Kernel.withDensity_apply, Pi.add_apply, MeasureTheory.withDensity_add_right] · fun_prop · exact hf.add hg lemma withDensity_sub_add_cancel [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) (hfg : ∀ a, g a ≤ᵐ[κ a] f a) : withDensity κ (fun a x ↦ f a x - g a x) + withDensity κ g = withDensity κ f := by rw [← withDensity_add_right _ hg] swap; · exact hf.sub hg refine withDensity_congr_ae κ ((hf.sub hg).add hg) hf (fun a ↦ ?_) filter_upwards [hfg a] with x hx rwa [Pi.add_apply, Pi.add_apply, tsub_add_cancel_iff_le] theorem withDensity_tsum [Countable ι] (κ : Kernel α β) [IsSFiniteKernel κ] {f : ι → α → β → ℝ≥0∞} (hf : ∀ i, Measurable (Function.uncurry (f i))) : withDensity κ (∑' n, f n) = Kernel.sum fun n => withDensity κ (f n) := by have h_sum_a : ∀ a, Summable fun n => f n a := fun a => Pi.summable.mpr fun b => ENNReal.summable have h_sum : Summable fun n => f n := Pi.summable.mpr h_sum_a ext a s hs rw [sum_apply' _ a hs, Kernel.withDensity_apply' κ _ a s] swap · have : Function.uncurry (∑' n, f n) = ∑' n, Function.uncurry (f n) := by ext1 p simp only [Function.uncurry_def] rw [tsum_apply h_sum, tsum_apply (h_sum_a _), tsum_apply] exact Pi.summable.mpr fun p => ENNReal.summable rw [this] fun_prop have : ∫⁻ b in s, (∑' n, f n) a b ∂κ a = ∫⁻ b in s, ∑' n, (fun b => f n a b) b ∂κ a := by congr with b rw [tsum_apply h_sum, tsum_apply (h_sum_a a)] rw [this, lintegral_tsum fun n => by fun_prop] congr with n rw [Kernel.withDensity_apply' _ (hf n) a s] /-- If a kernel `κ` is finite and a function `f : α → β → ℝ≥0∞` is bounded, then `withDensity κ f` is finite. -/ theorem isFiniteKernel_withDensity_of_bounded (κ : Kernel α β) [IsFiniteKernel κ] {B : ℝ≥0∞} (hB_top : B ≠ ∞) (hf_B : ∀ a b, f a b ≤ B) : IsFiniteKernel (withDensity κ f) := by by_cases hf : Measurable (Function.uncurry f) · exact ⟨⟨B * IsFiniteKernel.bound κ, ENNReal.mul_lt_top hB_top.lt_top (IsFiniteKernel.bound_lt_top κ), fun a => by rw [Kernel.withDensity_apply' κ hf a Set.univ] calc ∫⁻ b in Set.univ, f a b ∂κ a ≤ ∫⁻ _ in Set.univ, B ∂κ a := lintegral_mono (hf_B a) _ = B * κ a Set.univ := by simp only [Measure.restrict_univ, MeasureTheory.lintegral_const] _ ≤ B * IsFiniteKernel.bound κ := mul_le_mul_left' (measure_le_bound κ a Set.univ) _⟩⟩ · rw [withDensity_of_not_measurable _ hf] infer_instance /-- Auxiliary lemma for `IsSFiniteKernel.withDensity`. If a kernel `κ` is finite, then `withDensity κ f` is s-finite. -/ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : Kernel α β) [IsFiniteKernel κ] (hf_ne_top : ∀ a b, f a b ≠ ∞) : IsSFiniteKernel (withDensity κ f) := by -- We already have that for `f` bounded from above and a `κ` a finite kernel, -- `withDensity κ f` is finite. We write any function as a countable sum of bounded -- functions, and decompose an s-finite kernel as a sum of finite kernels. We then use that -- `withDensity` commutes with sums for both arguments and get a sum of finite kernels. by_cases hf : Measurable (Function.uncurry f) swap; · rw [withDensity_of_not_measurable _ hf]; infer_instance let fs : ℕ → α → β → ℝ≥0∞ := fun n a b => min (f a b) (n + 1) - min (f a b) n have h_le : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → f a b ≤ n := by intro a b n hn have : (f a b).toReal ≤ n := Nat.le_of_ceil_le hn rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this · refine this.trans (le_of_eq ?_) rw [ENNReal.ofReal_natCast] · norm_cast exact zero_le _ have h_zero : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → fs n a b = 0 := by intro a b n hn suffices min (f a b) (n + 1) = f a b ∧ min (f a b) n = f a b by simp_rw [fs, this.1, this.2, tsub_self (f a b)] exact ⟨min_eq_left ((h_le a b n hn).trans (le_add_of_nonneg_right zero_le_one)), min_eq_left (h_le a b n hn)⟩ have hf_eq_tsum : f = ∑' n, fs n := by have h_sum_a : ∀ a, Summable fun n => fs n a := by refine fun a => Pi.summable.mpr fun b => ?_ suffices ∀ n, n ∉ Finset.range ⌈(f a b).toReal⌉₊ → fs n a b = 0 from summable_of_ne_finset_zero this intro n hn_notMem rw [Finset.mem_range, not_lt] at hn_notMem exact h_zero a b n hn_notMem ext a b : 2 rw [tsum_apply (Pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a), ENNReal.tsum_eq_liminf_sum_nat] have h_finset_sum : ∀ n, ∑ i ∈ Finset.range n, fs i a b = min (f a b) n := fun n ↦ by induction n with | zero => simp | succ n hn => rw [Finset.sum_range_succ, hn] simp [fs] simp_rw [h_finset_sum] refine (Filter.Tendsto.liminf_eq ?_).symm refine Filter.Tendsto.congr' ?_ tendsto_const_nhds rw [Filter.EventuallyEq, Filter.eventually_atTop] exact ⟨⌈(f a b).toReal⌉₊, fun n hn => (min_eq_left (h_le a b n hn)).symm⟩ rw [hf_eq_tsum, withDensity_tsum _ fun n : ℕ => _] swap; · fun_prop refine isSFiniteKernel_sum (hκs := fun n => ?_) suffices IsFiniteKernel (withDensity κ (fs n)) by haveI := this; infer_instance refine isFiniteKernel_withDensity_of_bounded _ (ENNReal.coe_ne_top : ↑n + 1 ≠ ∞) fun a b => ?_ -- After https://github.com/leanprover/lean4/pull/2734, we need to do beta reduction before `norm_cast` beta_reduce norm_cast calc fs n a b ≤ min (f a b) (n + 1) := tsub_le_self _ ≤ n + 1 := min_le_right _ _ _ = ↑(n + 1) := by norm_cast /-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is everywhere finite, `withDensity κ f` is s-finite. -/ nonrec theorem IsSFiniteKernel.withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (hf_ne_top : ∀ a b, f a b ≠ ∞) : IsSFiniteKernel (withDensity κ f) := by have h_eq_sum : withDensity κ f = Kernel.sum fun i => withDensity (seq κ i) f := by rw [← withDensity_kernel_sum _ _] congr exact (kernel_sum_seq κ).symm rw [h_eq_sum] exact isSFiniteKernel_sum (hκs := fun n => isSFiniteKernel_withDensity_of_isFiniteKernel (seq κ n) hf_ne_top) /-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0`, `withDensity κ f` is s-finite. -/ instance (κ : Kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0) : IsSFiniteKernel (withDensity κ fun a b => f a b) := IsSFiniteKernel.withDensity κ fun _ _ => ENNReal.coe_ne_top nonrec lemma withDensity_mul [IsSFiniteKernel κ] {f : α → β → ℝ≥0} {g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) : withDensity κ (fun a x ↦ f a x * g a x) = withDensity (withDensity κ fun a x ↦ f a x) g := by ext a : 1 rw [Kernel.withDensity_apply] swap; · fun_prop change (Measure.withDensity (κ a) ((fun x ↦ (f a x : ℝ≥0∞)) * (fun x ↦ (g a x : ℝ≥0∞)))) = (withDensity (withDensity κ fun a x ↦ f a x) g) a rw [withDensity_mul] · rw [Kernel.withDensity_apply _ hg, Kernel.withDensity_apply] exact measurable_coe_nnreal_ennreal.comp hf · fun_prop · fun_prop end ProbabilityTheory.Kernel
Init.lean
/- Copyright (c) 2023 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg -/ import Mathlib.Init import Aesop /-! # Continuity Rule Set This module defines the `Continuous` Aesop rule set which is used by the `continuity` tactic. Aesop rule sets only become visible once the file in which they're declared is imported, so we must put this declaration into its own file. -/ declare_aesop_rule_sets [Continuous]
NthRewrite.lean
import Mathlib.Tactic.NthRewrite import Mathlib.Algebra.Group.Defs import Mathlib.Data.Vector.Defs import Mathlib.Algebra.Ring.Nat set_option autoImplicit true open Mathlib example [AddZeroClass G] {a : G} (h : a = a): a = (a + 0) := by nth_rewrite 2 [← add_zero a] at h exact h example [AddZeroClass G] {a : G} : a + a = a + (a + 0) := by nth_rw 2 [← add_zero a] structure F where (a : ℕ) (v : List.Vector ℕ a) (p : v.val = []) example (f : F) : f.v.val = [] := by nth_rw 1 [f.p] structure Cat where (O : Type) (H : O → O → Type) (i : (o : O) → H o o) (c : {X Y Z : O} → (f : H X Y) → (g : H Y Z) → H X Z) (li : ∀ {X Y : O} (f : H X Y), c (i X) f = f) (ri : ∀ {X Y : O} (f : H X Y), c f (i Y) = f) (a : ∀ {W X Y Z : O} (f : H W X) (g : H X Y) (h : H Y Z), c (c f g) h = c f (c g h)) example (C : Cat) (W X Y Z : C.O) (f : C.H X Y) (g : C.H W X) (h _k : C.H Y Z) : C.c (C.c g f) h = C.c g (C.c f h) := by nth_rw 1 [C.a] example (C : Cat) (X Y : C.O) (f : C.H X Y) : C.c f (C.i Y) = f := by nth_rw 1 [C.ri] example (x y z : ℕ) (h1 : x = y) (h2 : y = z) : x + x + x + y = y + y + x + x := by nth_rewrite 3 [h1, h2] -- h2 *is* used, this is different from mathlib3 nth_rewrite 3 [h2] rw [h1] rw [h2] axiom foo : [1] = [2] example : [[1], [1], [1]] = [[1], [2], [1]] := by nth_rw 2 [foo] axiom foo' : [6] = [7] axiom bar' : [[5],[5]] = [[6],[6]] example : [[7],[6]] = [[5],[5]] := by nth_rewrite 1 [foo'] nth_rewrite 1 [bar'] nth_rewrite 1 [← foo'] nth_rewrite 1 [← foo'] rfl example (a b c : ℕ) : c + a + b = a + c + b := by nth_rewrite 4 [add_comm] rfl axiom wowzer : (3, 3) = (5, 2) axiom kachow (n : ℕ) : (4, n) = (5, n) axiom pchew (n : ℕ) : (n, 5) = (5, n) axiom smash (n m : ℕ) : (n, m) = (1, 1) example : [(3, 3), (5, 9), (5, 9)] = [(4, 5), (3, 6), (1, 1)] := by nth_rewrite 1 [wowzer] nth_rewrite 3 [← pchew] nth_rewrite 1 [pchew] nth_rewrite 1 [smash] nth_rewrite 2 [smash] nth_rewrite 3 [smash] nth_rewrite 4 [smash] nth_rewrite 5 [smash] nth_rewrite 6 [smash] rfl example (x y : Prop) (h₁ : x ↔ y) (h₂ : x ↔ x ∧ x) : x ∧ x ↔ x := by nth_rewrite 3 [h₁] at h₂ nth_rewrite 1 [← h₁] at h₂ nth_rewrite 3 [h₂] rfl example (x y : ℕ) (h₁ : x = y) (h₂ : x = x + x) : x + x = x := by nth_rewrite 3 [h₁] at h₂ nth_rewrite 1 [← h₁] at h₂ nth_rewrite 3 [h₂] rfl example (x y : ℕ) (h : x = y) : x + x + x = x + y + y := by nth_rw 2 3 [h]
Wallis.lean
/- Copyright (c) 2021 Hanting Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hanting Zhang -/ import Mathlib.Analysis.SpecialFunctions.Integrals.Basic /-! # The Wallis formula for Pi This file establishes the Wallis product for `π` (`Real.tendsto_prod_pi_div_two`). Our proof is largely about analyzing the behaviour of the sequence `∫ x in 0..π, sin x ^ n` as `n → ∞`. See: https://en.wikipedia.org/wiki/Wallis_product The proof can be broken down into two pieces. The first step (carried out in `Analysis.SpecialFunctions.Integrals`) is to use repeated integration by parts to obtain an explicit formula for this integral, which is rational if `n` is odd and a rational multiple of `π` if `n` is even. The second step, carried out here, is to estimate the ratio `∫ (x : ℝ) in 0..π, sin x ^ (2 * k + 1) / ∫ (x : ℝ) in 0..π, sin x ^ (2 * k)` and prove that it converges to one using the squeeze theorem. The final product for `π` is obtained after some algebraic manipulation. ## Main statements * `Real.Wallis.W`: the product of the first `k` terms in Wallis' formula for `π`. * `Real.Wallis.W_eq_integral_sin_pow_div_integral_sin_pow`: express `W n` as a ratio of integrals. * `Real.Wallis.W_le` and `Real.Wallis.le_W`: upper and lower bounds for `W n`. * `Real.tendsto_prod_pi_div_two`: the Wallis product formula. -/ open scoped Real Topology Nat open Filter Finset intervalIntegral namespace Real namespace Wallis /-- The product of the first `k` terms in Wallis' formula for `π`. -/ noncomputable def W (k : ℕ) : ℝ := ∏ i ∈ range k, (2 * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3)) theorem W_succ (k : ℕ) : W (k + 1) = W k * ((2 * k + 2) / (2 * k + 1) * ((2 * k + 2) / (2 * k + 3))) := prod_range_succ _ _ theorem W_pos (k : ℕ) : 0 < W k := by induction' k with k hk · unfold W; simp · rw [W_succ] refine mul_pos hk (mul_pos (div_pos ?_ ?_) (div_pos ?_ ?_)) <;> positivity theorem W_eq_factorial_ratio (n : ℕ) : W n = 2 ^ (4 * n) * n ! ^ 4 / ((2 * n)! ^ 2 * (2 * n + 1)) := by induction' n with n IH · simp only [W, prod_range_zero, Nat.factorial_zero, mul_zero, pow_zero] norm_num · unfold W at IH ⊢ rw [prod_range_succ, IH, _root_.div_mul_div_comm, _root_.div_mul_div_comm] refine (div_eq_div_iff ?_ ?_).mpr ?_ any_goals exact ne_of_gt (by positivity) simp_rw [Nat.mul_succ, Nat.factorial_succ, pow_succ] push_cast ring_nf theorem W_eq_integral_sin_pow_div_integral_sin_pow (k : ℕ) : (π / 2)⁻¹ * W k = (∫ x : ℝ in (0)..π, sin x ^ (2 * k + 1)) / ∫ x : ℝ in (0)..π, sin x ^ (2 * k) := by rw [integral_sin_pow_even, integral_sin_pow_odd, mul_div_mul_comm, ← prod_div_distrib, inv_div] simp_rw [div_div_div_comm, div_div_eq_mul_div, mul_div_assoc] rfl theorem W_le (k : ℕ) : W k ≤ π / 2 := by rw [← div_le_one pi_div_two_pos, div_eq_inv_mul] rw [W_eq_integral_sin_pow_div_integral_sin_pow, div_le_one (integral_sin_pow_pos _)] apply integral_sin_pow_succ_le theorem le_W (k : ℕ) : ((2 : ℝ) * k + 1) / (2 * k + 2) * (π / 2) ≤ W k := by rw [← le_div_iff₀ pi_div_two_pos, div_eq_inv_mul (W k) _] rw [W_eq_integral_sin_pow_div_integral_sin_pow, le_div_iff₀ (integral_sin_pow_pos _)] convert integral_sin_pow_succ_le (2 * k + 1) rw [integral_sin_pow (2 * k)] simp theorem tendsto_W_nhds_pi_div_two : Tendsto W atTop (𝓝 <| π / 2) := by refine tendsto_of_tendsto_of_tendsto_of_le_of_le ?_ tendsto_const_nhds le_W W_le have : 𝓝 (π / 2) = 𝓝 ((1 - 0) * (π / 2)) := by rw [sub_zero, one_mul] rw [this] refine Tendsto.mul ?_ tendsto_const_nhds have h : ∀ n : ℕ, ((2 : ℝ) * n + 1) / (2 * n + 2) = 1 - 1 / (2 * n + 2) := by intro n rw [sub_div' (ne_of_gt (add_pos_of_nonneg_of_pos (mul_nonneg (two_pos : 0 < (2 : ℝ)).le (Nat.cast_nonneg _)) two_pos)), one_mul] congr 1; ring simp_rw [h] refine (tendsto_const_nhds.div_atTop ?_).const_sub _ refine Tendsto.atTop_add ?_ tendsto_const_nhds exact tendsto_natCast_atTop_atTop.const_mul_atTop two_pos end Wallis end Real /-- Wallis' product formula for `π / 2`. -/ theorem Real.tendsto_prod_pi_div_two : Tendsto (fun k => ∏ i ∈ range k, ((2 : ℝ) * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3))) atTop (𝓝 (π / 2)) := Real.Wallis.tendsto_W_nhds_pi_div_two
ContinuousMap.lean
/- Copyright (c) 2025 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.ContinuousMap.Compact import Mathlib.Topology.ContinuousMap.Algebra import Mathlib.MeasureTheory.Integral.IntegrableOn /-! # Specific results about `ContinuousMap`-valued integration In this file, we collect a few results regarding integrability, on a measure space `(X, μ)`, of a `C(Y, E)`-valued function, where `Y` is a compact topological space and `E` is a normed group. These are all elementary from a mathematical point of view, but they require a bit of care in order to be conveniently usable. In particular, to accommodate the need of families `f : X → Y → E` which such that `f x` is only continuous for *almost every* `x`, we give a variety of results about the integrability of `fun x ↦ ContinuousMap.mkD (f x) g` whose assumption only mention `f` (so that user don't have to convert between `f` and `fun x ↦ ContinuousMap.mkD (f x) g` by hand). ## Main results * `hasFiniteIntegral_of_bound`: given `f : X → C(Y, E)`, the natural way to show `HasFiniteIntegral f` is to give a `bound : X → ℝ`, which itself has finite integral, and such that `∀ᵐ x ∂μ, ∀ y : Y, ‖f x y‖ ≤ bound x`. * `hasFiniteIntegral_mkD_of_bound` is the `mkD` analog of the above: given `f : X → Y → E` such that `f x` is continuous for almost every `x`, as well as a bound as above, we prove `HasFiniteIntegral (fun x ↦ mkD (f x) g)`. Note that, conveniently, `mkD` only appears in the result. * `aeStronglyMeasurable_mkD_of_uncurry`: if now `X` is a topological space with the borel σ-algebra, and `f : X → Y → E` is continuous on `X × Y`, then `fun x ↦ mkD (f x) g` is `AEStronglyMeasurable`. Note that this is far from optimal: this function is in fact continuous, and one could avoid `mkD` entirely since `f x` is always continuous in that case. Nevertheless, this turns out to be most convenient, as we explain below. ## Implementation Note We claim that using "constructors with default values" such as `ContinuousMap.mkD` is the right way to approach integration valued in a functional space `ℱ`. More precisely: - if you happen to start from a bundled `f : X → ℱ` function, you should be able to use the general theory without any issues. - if instead you start with a family of bare functions `f : X → Y → E`, to integrate it in `ℱ`, you should always consider the family `fun x ↦ ℱ.mkD (f x) 0`, *even if your `f` always lands in `ℱ`*. This allows for a unified setting with the case where `f x` belongs to `ℱ` for *almost every `x`*, and also avoids entering dependent-types hell. -/ open MeasureTheory namespace ContinuousMap variable {X Y : Type*} [MeasurableSpace X] {μ : Measure X} [TopologicalSpace Y] variable {E : Type*} [NormedAddCommGroup E] /-- A natural criterion for `HasFiniteIntegral` of a `C(Y, E)`-valued function is the existence of some positive function with finite integral such that `∀ᵐ x ∂μ, ∀ y : Y, ‖f x y‖ ≤ bound x`. Note that there is no dominated convergence here (hence no first-countability assumption on `Y`). We are just using the properties of Banach-space-valued integration. -/ lemma hasFiniteIntegral_of_bound [CompactSpace Y] (f : X → C(Y, E)) (bound : X → ℝ) (bound_int : HasFiniteIntegral bound μ) (bound_ge : ∀ᵐ x ∂μ, ∀ y : Y, ‖f x y‖ ≤ bound x) : HasFiniteIntegral f μ := by rcases isEmpty_or_nonempty Y with (h|h) · simp · have bound_nonneg : 0 ≤ᵐ[μ] bound := by filter_upwards [bound_ge] with x bound_x using le_trans (norm_nonneg _) (bound_x h.some) refine .mono' bound_int ?_ filter_upwards [bound_ge, bound_nonneg] with x bound_ge_x bound_nonneg_x exact ContinuousMap.norm_le _ bound_nonneg_x |>.mpr bound_ge_x /-- A variant of `ContinuousMap.hasFiniteIntegral_of_bound` spelled in terms of `ContinuousMap.mkD`. -/ lemma hasFiniteIntegral_mkD_of_bound [CompactSpace Y] (f : X → Y → E) (g : C(Y, E)) (f_ae_cont : ∀ᵐ x ∂μ, Continuous (f x)) (bound : X → ℝ) (bound_int : HasFiniteIntegral bound μ) (bound_ge : ∀ᵐ x ∂μ, ∀ y : Y, ‖f x y‖ ≤ bound x) : HasFiniteIntegral (fun x ↦ mkD (f x) g) μ := by refine hasFiniteIntegral_of_bound _ bound bound_int ?_ filter_upwards [bound_ge, f_ae_cont] with x bound_ge_x cont_x simpa only [mkD_apply_of_continuous cont_x] using bound_ge_x /-- A variant of `ContinuousMap.hasFiniteIntegral_mkD_of_bound` for a family of functions which are continuous on a compact set. -/ lemma hasFiniteIntegral_mkD_restrict_of_bound {s : Set Y} [CompactSpace s] (f : X → Y → E) (g : C(s, E)) (f_ae_contOn : ∀ᵐ x ∂μ, ContinuousOn (f x) s) (bound : X → ℝ) (bound_int : HasFiniteIntegral bound μ) (bound_ge : ∀ᵐ x ∂μ, ∀ y ∈ s, ‖f x y‖ ≤ bound x) : HasFiniteIntegral (fun x ↦ mkD (s.restrict (f x)) g) μ := by refine hasFiniteIntegral_mkD_of_bound _ _ ?_ bound bound_int ?_ · simpa [← continuousOn_iff_continuous_restrict] · simpa lemma aeStronglyMeasurable_mkD_of_uncurry [CompactSpace Y] [TopologicalSpace X] [OpensMeasurableSpace X] [SecondCountableTopologyEither X (C(Y, E))] (f : X → Y → E) (g : C(Y, E)) (f_cont : Continuous (Function.uncurry f)) : AEStronglyMeasurable (fun x ↦ mkD (f x) g) μ := continuous_mkD_of_uncurry _ _ f_cont |>.aestronglyMeasurable open Set in lemma aeStronglyMeasurable_restrict_mkD_of_uncurry [CompactSpace Y] {s : Set X} [TopologicalSpace X] [OpensMeasurableSpace X] [SecondCountableTopologyEither X (C(Y, E))] (hs : MeasurableSet s) (f : X → Y → E) (g : C(Y, E)) (f_cont : ContinuousOn (Function.uncurry f) (s ×ˢ univ)) : AEStronglyMeasurable (fun x ↦ mkD (f x) g) (μ.restrict s) := continuousOn_mkD_of_uncurry _ _ f_cont |>.aestronglyMeasurable hs open Set in lemma aeStronglyMeasurable_mkD_restrict_of_uncurry {t : Set Y} [CompactSpace t] [TopologicalSpace X] [OpensMeasurableSpace X] [SecondCountableTopologyEither X (C(t, E))] (f : X → Y → E) (g : C(t, E)) (f_cont : ContinuousOn (Function.uncurry f) (univ ×ˢ t)) : AEStronglyMeasurable (fun x ↦ mkD (t.restrict (f x)) g) μ := continuous_mkD_restrict_of_uncurry _ _ f_cont |>.aestronglyMeasurable open Set in lemma aeStronglyMeasurable_restrict_mkD_restrict_of_uncurry {s : Set X} {t : Set Y} [CompactSpace t] [TopologicalSpace X] [OpensMeasurableSpace X] [SecondCountableTopologyEither X (C(t, E))] (hs : MeasurableSet s) (f : X → Y → E) (g : C(t, E)) (f_cont : ContinuousOn (Function.uncurry f) (s ×ˢ t)) : AEStronglyMeasurable (fun x ↦ mkD (t.restrict (f x)) g) (μ.restrict s) := continuousOn_mkD_restrict_of_uncurry _ _ f_cont |>.aestronglyMeasurable hs end ContinuousMap
algebraics_fundamentals.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype seq choice. From mathcomp Require Import div fintype path tuple bigop finset prime order. From mathcomp Require Import ssralg poly polydiv mxpoly countalg closed_field. From mathcomp Require Import ssrnum ssrint archimedean rat intdiv fingroup. From mathcomp Require Import finalg zmodp cyclic pgroup sylow vector falgebra. From mathcomp Require Import fieldext separable galois. (******************************************************************************) (* The main result in this file is the existence theorem that underpins the *) (* construction of the algebraic numbers in file algC.v. This theorem simply *) (* asserts the existence of an algebraically closed field with an *) (* automorphism of order 2, and dubbed the Fundamental_Theorem_of_Algebraics *) (* because it is essentially the Fundamental Theorem of Algebra for algebraic *) (* numbers (the more familiar version for complex numbers can be derived by *) (* continuity). *) (* Although our proof does indeed construct exactly the algebraics, we *) (* choose not to expose this in the statement of our Theorem. In algC.v we *) (* construct the norm and partial order of the "complex field" introduced by *) (* the Theorem; as these imply is has characteristic 0, we then get the *) (* algebraics as a subfield. To avoid some duplication a few basic properties *) (* of the algebraics, such as the existence of minimal polynomials, that are *) (* required by the proof of the Theorem, are also proved here. *) (* The main theorem of closed_field supplies us directly with an algebraic *) (* closure of the rationals (as the rationals are a countable field), so all *) (* we really need to construct is a conjugation automorphism that exchanges *) (* the two roots (i and -i) of X^2 + 1, and fixes a (real) subfield of *) (* index 2. This does not require actually constructing this field: the *) (* kHomExtend construction from galois.v supplies us with an automorphism *) (* conj_n of the number field Q[z_n] = Q[x_n, i] for any x_n such that Q[x_n] *) (* does not contain i (e.g., such that Q[x_n] is real). As conj_n will extend *) (* conj_m when Q[x_n] contains x_m, it therefore suffices to construct a *) (* sequence x_n such that *) (* (1) For each n, Q[x_n] is a REAL field containing Q[x_m] for all m <= n. *) (* (2) Each z in C belongs to Q[z_n] = Q[x_n, i] for large enough n. *) (* This, of course, amounts to proving the Fundamental Theorem of Algebra. *) (* Indeed, we use a constructive variant of Artin's algebraic proof of that *) (* Theorem to replace (2) by *) (* (3) Each monic polynomial over Q[x_m] whose constant term is -c^2 for some *) (* c in Q[x_m] has a root in Q[x_n] for large enough n. *) (* We then ensure (3) by setting Q[x_n+1] = Q[x_n, y] where y is the root of *) (* of such a polynomial p found by dichotomy in some interval [0, b] with b *) (* suitably large (such that p[b] >= 0), and p is obtained by decoding n into *) (* a triple (m, p, c) that satisfies the conditions of (3) (taking x_n+1=x_n *) (* if this is not the case), thereby ensuring that all such triples are *) (* ultimately considered. *) (* In more detail, the 600-line proof consists in six (uneven) parts: *) (* (A) - Construction of number fields (~ 100 lines): in order to make use of *) (* the theory developped in falgebra, fieldext, separable and galois we *) (* construct a separate fielExtType Q z for the number field Q[z], with *) (* z in C, the closure of rat supplied by countable_algebraic_closure. *) (* The morphism (ofQ z) maps Q z to C, and the Primitive Element Theorem *) (* lets us define a predicate sQ z characterizing the image of (ofQ z), *) (* as well as a partial inverse (inQ z) to (ofQ z). *) (* (B) - Construction of the real extension Q[x, y] (~ 230 lines): here y has *) (* to be a root of a polynomial p over Q[x] satisfying the conditions of *) (* (3), and Q[x] should be real and archimedean, which we represent by *) (* a morphism from Q x to some archimedean field R, as the ssrnum and *) (* fieldext structures are not compatible. The construction starts by *) (* weakening the condition p[0] = -c^2 to p[0] <= 0 (in R), then reducing *) (* to the case where p is the minimal polynomial over Q[x] of some y (in *) (* some Q[w] that contains x and all roots of p). Then we only need to *) (* construct a realFieldType structure for Q[t] = Q[x,y] (we don't even *) (* need to show it is consistent with that of R). This amounts to fixing *) (* the sign of all z != 0 in Q[t], consistently with arithmetic in Q[t]. *) (* Now any such z is equal to q[y] for some q in Q[x][X] coprime with p. *) (* Then up + vq = 1 for Bezout coefficients u and v. As p is monic, there *) (* is some b0 >= 0 in R such that p changes sign in ab0 = [0; b0]. As R *) (* is archimedean, some iteration of the binary search for a root of p in *) (* ab0 will yield an interval ab_n such that |up[d]| < 1/2 for d in ab_n. *) (* Then |q[d]| > 1/2M > 0 for any upper bound M on |v[X]| in ab0, so q *) (* cannot change sign in ab_n (as then root-finding in ab_n would yield a *) (* d with |Mq[d]| < 1/2), so we can fix the sign of z to that of q in *) (* ab_n. *) (* (C) - Construction of the x_n and z_n (~50 lines): x_ n is obtained by *) (* iterating (B), starting with x_0 = 0, and then (A) and the PET yield *) (* z_ n. We establish (1) and (3), and that the minimal polynomial of the *) (* preimage i_ n of i over the preimage R_ n of Q[x_n] is X^2 + 1. *) (* (D) - Establish (2), i.e., prove the FTA (~180 lines). We must depart from *) (* Artin's proof because deciding membership in the union of the Q[x_n] *) (* requires the FTA, i.e., we cannot (yet) construct a maximal real *) (* subfield of C. We work around this issue by first reducing to the case *) (* where Q[z] is Galois over Q and contains i, then using induction over *) (* the degree of z over Q[z_ n] (i.e., the degree of a monic polynomial *) (* over Q[z_n] that has z as a root). We can assume that z is not in *) (* Q[z_n]; then it suffices to find some y in Q[z_n, z] \ Q[z_n] that is *) (* also in Q[z_m] for some m > n, as then we can apply induction with the *) (* minimal polynomial of z over Q[z_n, y]. In any Galois extension Q[t] *) (* of Q that contains both z and z_n, Q[x_n, z] = Q[z_n, z] is Galois *) (* over both Q[x_n] and Q[z_n]. If Gal(Q[x_n,z] / Q[x_n]) isn't a 2-group *) (* take one of its Sylow 2-groups P; the minimal polynomial p of any *) (* generator of the fixed field F of P over Q[x_n] has odd degree, hence *) (* by (3) - p[X]p[-X] and thus p has a root y in some Q[x_m], hence in *) (* Q[z_m]. As F is normal, y is in F, with minimal polynomial p, and y *) (* is not in Q[z_n] = Q[x_n, i] since p has odd degree. Otherwise, *) (* Gal(Q[z_n,z] / Q[z_n]) is a proper 2-group, and has a maximal subgroup *) (* P of index 2. The fixed field F of P has a generator w over Q[z_n] *) (* with w^2 in Q[z_n] \ Q[x_n], i.e. w^2 = u + 2iv with v != 0. From (3) *) (* X^4 - uX^2 - v^2 has a root x in some Q[x_m]; then x != 0 as v != 0, *) (* hence w^2 = y^2 for y = x + iv/x in Q[z_m], and y generates F. *) (* (E) - Construct conj and conclude (~40 lines): conj z is defined as *) (* conj_ n z with the n provided by (2); since each conj_ m is a morphism *) (* of order 2 and conj z = conj_ m z for any m >= n, it follows that conj *) (* is also a morphism of order 2. *) (* Note that (C), (D) and (E) only depend on Q[x_n] not containing i; the *) (* order structure is not used (hence we need not prove that the ordering of *) (* Q[x_m] is consistent with that of Q[x_n] for m >= n). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. Local Notation "p ^ f" := (map_poly f p) : ring_scope. Local Notation "p ^@" := (p ^ in_alg _) (format "p ^@"): ring_scope. Local Notation "<< E ; u >>" := <<E; u>>%VS. Local Notation Qmorphism C := {rmorphism rat -> C}. Lemma rat_algebraic_archimedean (C : numFieldType) (QtoC : Qmorphism C) : integralRange QtoC -> Num.archimedean_axiom C. Proof. move=> algC x. without loss x_ge0: x / 0 <= x by rewrite -normr_id; apply. have [-> | nz_x] := eqVneq x 0; first by exists 1; rewrite normr0. have [p mon_p px0] := algC x; exists (\sum_(j < size p) `|numq p`_j|)%N. rewrite ger0_norm // real_ltNge ?rpred_nat ?ger0_real //. apply: contraL px0 => lb_x; rewrite rootE gt_eqF // horner_coef size_map_poly. have x_gt0 k: 0 < x ^+ k by rewrite exprn_gt0 // lt_def nz_x. move: lb_x; rewrite polySpred ?monic_neq0 // !big_ord_recr coef_map /=. rewrite -lead_coefE (monicP mon_p) natrD [QtoC _]rmorph1 mul1r => lb_x. case: _.-1 (lb_x) => [|n]; first by rewrite !big_ord0 !add0r ltr01. rewrite -ltrBlDl add0r -(ler_pM2r (x_gt0 n)) -exprS. apply: lt_le_trans; rewrite mulrDl mul1r ltr_pwDr // -sumrN. rewrite natr_sum mulr_suml ler_sum // => j _. rewrite coef_map /= fmorph_eq_rat (le_trans (real_ler_norm _)) //. by rewrite rpredN rpredM ?rpred_rat ?rpredX // ger0_real. rewrite normrN normrM ler_pM //. rewrite normf_div -!intr_norm -!abszE ler_piMr ?ler0n //. by rewrite invf_le1 ?ler1n ?ltr0n absz_gt0. rewrite normrX ger0_norm ?(ltrW x_gt0) // ler_weXn2l ?leq_ord //. by rewrite (le_trans _ lb_x) // natr1 ler1n. Qed. Definition decidable_embedding sT T (f : sT -> T) := forall y, decidable (exists x, y = f x). Lemma rat_algebraic_decidable (C : fieldType) (QtoC : Qmorphism C) : integralRange QtoC -> decidable_embedding QtoC. Proof. have QtoCinj: injective QtoC by apply: fmorph_inj. pose ZtoQ : int -> rat := intr; pose ZtoC : int -> C := intr. have ZtoQinj: injective ZtoQ by apply: intr_inj. have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> m; rewrite /= rmorph_int. move=> algC x; have /sig2_eqW[q mon_q qx0] := algC x; pose d := (size q).-1. have [n ub_n]: {n | forall y, root q y -> `|y| < n}. have [n1 ub_n1] := monic_Cauchy_bound mon_q. have /monic_Cauchy_bound[n2 ub_n2]: (-1) ^+ d *: (q \Po - 'X) \is monic. rewrite monicE lead_coefZ lead_coef_comp ?size_polyN ?size_polyX // -/d. by rewrite lead_coefN lead_coefX (monicP mon_q) (mulrC 1) signrMK. exists (Num.max n1 n2) => y; rewrite ltNge ler_normr !leUx rootE. apply: contraL => /orP[]/andP[] => [/ub_n1/gt_eqF->// | _ /ub_n2/gt_eqF]. by rewrite hornerZ horner_comp !hornerE opprK mulf_eq0 signr_eq0 => /= ->. have [p [a nz_a Dq]] := rat_poly_scale q; pose N := Num.bound `|n * a%:~R|. pose xa : seq rat := [seq (m%:R - N%:R) / a%:~R | m <- iota 0 N.*2]. have [/sig2_eqW[y _ ->] | xa'x] := @mapP _ _ QtoC xa x; first by left; exists y. right=> [[y Dx]]; case: xa'x; exists y => //. have{x Dx qx0} qy0: root q y by rewrite Dx fmorph_root in qx0. have /dvdzP[b Da]: (denq y %| a)%Z. have /Gauss_dvdzl <-: coprimez (denq y) (numq y ^+ d). by rewrite coprimez_sym coprimezXl //; apply: coprime_num_den. pose p1 : {poly int} := a *: 'X^d - p. have Dp1: p1 ^ intr = a%:~R *: ('X^d - q). by rewrite rmorphB /= linearZ /= map_polyXn scalerBr Dq scalerKV ?intr_eq0. apply/dvdzP; exists (\sum_(i < d) p1`_i * numq y ^+ i * denq y ^+ (d - i.+1)). apply: ZtoQinj; rewrite /ZtoQ rmorphM mulr_suml rmorph_sum /=. transitivity ((p1 ^ intr).[y] * (denq y ^+ d)%:~R). rewrite Dp1 !hornerE (rootP qy0) subr0. by rewrite !rmorphXn /= numqE exprMn mulrA. have sz_p1: (size (p1 ^ ZtoQ)%R <= d)%N. rewrite Dp1 size_scale ?intr_eq0 //; apply/leq_sizeP=> i. rewrite leq_eqVlt eq_sym -polySpred ?monic_neq0 // coefB coefXn. case: eqP => [-> _ | _ /(nth_default 0)->//]. by rewrite -lead_coefE (monicP mon_q). rewrite (horner_coef_wide _ sz_p1) mulr_suml; apply: eq_bigr => i _. rewrite -!mulrA -exprSr coef_map !rmorphM !rmorphXn /= numqE exprMn -mulrA. by rewrite -exprD -addSnnS subnKC. pose m := `|(numq y * b + N)%R|%N. have Dm: m%:R = `|y * a%:~R + N%:R|. by rewrite pmulrn abszE intr_norm Da rmorphD !rmorphM /= numqE mulrAC mulrA. have ltr_Qnat n1 n2 : (n1%:R < n2%:R :> rat = _) := ltr_nat _ n1 n2. have ub_y: `|y * a%:~R| < N%:R. apply: le_lt_trans (archi_boundP (normr_ge0 _)); rewrite !normrM. by rewrite ler_pM // (le_trans _ (ler_norm n)) ?ltW ?ub_n. apply/mapP; exists m. rewrite mem_iota /= add0n -addnn -ltr_Qnat Dm natrD. by rewrite (le_lt_trans (ler_normD _ _)) // normr_nat ltrD2. rewrite Dm ger0_norm ?addrK ?mulfK ?intr_eq0 // -lerBlDl sub0r. by rewrite (le_trans (ler_norm _)) ?normrN ?ltW. Qed. Lemma minPoly_decidable_closure (F : fieldType) (L : closedFieldType) (FtoL : {rmorphism F -> L}) x : decidable_embedding FtoL -> integralOver FtoL x -> {p | [/\ p \is monic, root (p ^ FtoL) x & irreducible_poly p]}. Proof. move=> isF /sig2W[p /monicP mon_p px0]. have [r Dp] := closed_field_poly_normal (p ^ FtoL); pose n := size r. rewrite lead_coef_map {}mon_p rmorph1 scale1r in Dp. pose Fpx q := (q \is a polyOver isF) && root q x. have FpxF q: Fpx (q ^ FtoL) = root (q ^ FtoL) x. by rewrite /Fpx polyOver_poly // => j _; apply/sumboolP; exists q`_j. pose p_ (I : {set 'I_n}) := \prod_(i <- enum I) ('X - (r`_i)%:P). have{px0 Dp} /ex_minset[I /minsetP[/andP[FpI pIx0] minI]]: exists I, Fpx (p_ I). exists setT; suffices ->: p_ setT = p ^ FtoL by rewrite FpxF. by rewrite Dp (big_nth 0) big_mkord /p_ big_enum; apply/eq_bigl => i /[1!inE]. have{p} [p DpI]: {p | p_ I = p ^ FtoL}. exists (p_ I ^ (fun y => if isF y is left Fy then sval (sig_eqW Fy) else 0)). rewrite -map_poly_comp map_poly_id // => y /(allP FpI) /=. by rewrite unfold_in; case: (isF y) => // Fy _; case: (sig_eqW _). have mon_pI: p_ I \is monic by apply: monic_prod_XsubC. have mon_p: p \is monic by rewrite -(map_monic FtoL) -DpI. exists p; rewrite -DpI; split=> //; split=> [|q nCq q_dv_p]. by rewrite -(size_map_poly FtoL) -DpI (root_size_gt1 _ pIx0) ?monic_neq0. rewrite -dvdp_size_eqp //; apply/eqP. without loss mon_q: q nCq q_dv_p / q \is monic. move=> IHq; pose a := lead_coef q; pose q1 := a^-1 *: q. have nz_a: a != 0 by rewrite lead_coef_eq0 (dvdpN0 q_dv_p) ?monic_neq0. have /IHq IHq1: q1 \is monic by rewrite monicE lead_coefZ mulVf. by rewrite -IHq1 ?size_scale ?dvdpZl ?invr_eq0. without loss{nCq} qx0: q mon_q q_dv_p / root (q ^ FtoL) x. have /dvdpP[q1 Dp] := q_dv_p; rewrite DpI Dp rmorphM rootM -implyNb in pIx0. have mon_q1: q1 \is monic by rewrite Dp monicMr in mon_p. move=> IH; apply: (IH) (implyP pIx0 _) => //; apply: contra nCq => /IH IHq1. rewrite natr1E -(subnn (size q1)) {1}IHq1 ?Dp ?dvdp_mulr //. rewrite polySpred ?monic_neq0 //. by rewrite eqSS size_monicM ?monic_neq0 // -!subn1 subnAC addKn. have /dvdp_prod_XsubC[m Dq]: q ^ FtoL %| p_ I by rewrite DpI dvdp_map. pose B := [set j in mask m (enum I)]; have{} Dq: q ^ FtoL = p_ B. apply/eqP; rewrite -eqp_monic ?monic_map ?monic_prod_XsubC //. congr (_ %= _): Dq; apply: perm_big => //. by rewrite uniq_perm ?mask_uniq ?enum_uniq // => j; rewrite mem_enum inE. rewrite -!(size_map_poly FtoL) Dq -DpI (minI B) // -?Dq ?FpxF //. by apply/subsetP=> j /[1!inE] /mem_mask; rewrite mem_enum. Qed. Lemma alg_integral (F : fieldType) (L : fieldExtType F) : integralRange (in_alg L). Proof. move=> x; have [/polyOver1P[p Dp]] := (minPolyOver 1 x, monic_minPoly 1 x). by rewrite Dp map_monic; exists p; rewrite // -Dp root_minPoly. Qed. Prenex Implicits alg_integral. Arguments map_poly_inj {F R} f [p1 p2]. Theorem Fundamental_Theorem_of_Algebraics : {L : closedFieldType & {conj : {rmorphism L -> L} | involutive conj & ~ conj =1 id}}. Proof. have maxn3 n1 n2 n3: {m | [/\ n1 <= m, n2 <= m & n3 <= m]%N}. by exists (maxn n1 (maxn n2 n3)); apply/and3P; rewrite -!geq_max. have [C [/= QtoC algC]] := countable_algebraic_closure rat. exists C; have [i Di2] := GRing.imaginary_exists C. pose Qfield := fieldExtType rat. pose Cmorph (L : Qfield) := {rmorphism L -> C}. have pcharQ (L : Qfield): [pchar L] =i pred0 := ftrans (pchar_lalg L) (pchar_num _). have sepQ (L : Qfield) (K E : {subfield L}): separable K E. by apply/separableP=> u _; apply: pcharf0_separable. pose genQfield z L := {LtoC : Cmorph L & {u | LtoC u = z & <<1; u>> = fullv}}. have /all_tag[Q /all_tag[ofQ genQz]] z: {Qz : Qfield & genQfield z Qz}. have [|p [/monic_neq0 nzp pz0 irr_p]] := minPoly_decidable_closure _ (algC z). exact: rat_algebraic_decidable. pose Qz := SubFieldExtType pz0 irr_p. pose QzC : {rmorphism _ -> _} := @subfx_inj _ _ QtoC z p. exists Qz, QzC, (subfx_root QtoC z p); first exact: subfx_inj_root. apply/vspaceP=> u; rewrite memvf; apply/Fadjoin1_polyP. by have [q] := subfxEroot pz0 nzp u; exists q. have pQof z p: p^@ ^ ofQ z = p ^ QtoC. by rewrite -map_poly_comp; apply: eq_map_poly => x; rewrite !fmorph_eq_rat. have pQof2 z p u: ofQ z p^@.[u] = (p ^ QtoC).[ofQ z u]. by rewrite -horner_map pQof. have PET_Qz z (E : {subfield Q z}): {u | <<1; u>> = E}. exists (separable_generator 1 E). by rewrite -eq_adjoin_separable_generator ?sub1v. pose gen z x := exists q, x = (q ^ QtoC).[z]. have PET2 x y: {z | gen z x & gen z y}. pose Gxy := (x, y) = let: (p, q, z) := _ in ((p ^ QtoC).[z], (q ^ QtoC).[z]). suffices [[[p q] z] []]: {w | Gxy w} by exists z; [exists p | exists q]. apply/sig_eqW; have /integral_algebraic[px nz_px pxx0] := algC x. have /integral_algebraic[py nz_py pyy0] := algC y. have [n [[p Dx] [q Dy]]] := pchar0_PET nz_px pxx0 nz_py pyy0 (pchar_num _). by exists (p, q, y *+ n - x); congr (_, _). have gen_inQ z x: gen z x -> {u | ofQ z u = x}. have [u Dz _] := genQz z => /sig_eqW[q ->]. by exists q^@.[u]; rewrite pQof2 Dz. have gen_ofP z u v: reflect (gen (ofQ z u) (ofQ z v)) (v \in <<1; u>>). apply: (iffP Fadjoin1_polyP) => [[q ->]|]; first by rewrite pQof2; exists q. by case=> q; rewrite -pQof2 => /fmorph_inj->; exists q. have /all_tag[sQ genP] z: {s : pred C & forall x, reflect (gen z x) (x \in s)}. apply: all_tag (fun x => reflect (gen z x)) _ => x. have [w /gen_inQ[u <-] /gen_inQ[v <-]] := PET2 z x. by exists (v \in <<1; u>>)%VS; apply: gen_ofP. have sQtrans: transitive (fun x z => x \in sQ z). move=> x y z /genP[p ->] /genP[q ->]; apply/genP; exists (p \Po q). by rewrite map_comp_poly horner_comp. have sQid z: z \in sQ z by apply/genP; exists 'X; rewrite map_polyX hornerX. have{gen_ofP} sQof2 z u v: (ofQ z u \in sQ (ofQ z v)) = (u \in <<1; v>>%VS). exact/genP/(gen_ofP z). have sQof z v: ofQ z v \in sQ z. by have [u Dz defQz] := genQz z; rewrite -[in sQ z]Dz sQof2 defQz memvf. have{gen_inQ} sQ_inQ z x z_x := gen_inQ z x (genP z x z_x). have /all_sig[inQ inQ_K] z: {inQ | {in sQ z, cancel inQ (ofQ z)}}. by apply: all_sig_cond (fun x u => ofQ z u = x) 0 _ => x /sQ_inQ. have ofQ_K z: cancel (ofQ z) (inQ z). by move=> x; have /inQ_K/fmorph_inj := sQof z x. have sQring z: divring_closed (sQ z). have sQ_1: 1 \in sQ z by rewrite -(rmorph1 (ofQ z)) sQof. by split=> // x y /inQ_K<- /inQ_K<- /=; rewrite -(rmorphB, fmorph_div) sQof. pose sQzM z := GRing.isZmodClosed.Build _ _ (sQring z : zmod_closed _). pose sQmM z := GRing.isMulClosed.Build _ _ (sQring z). pose sQiM z := GRing.isInvClosed.Build _ _ (sQring z). pose sQC z : divringClosed _ := HB.pack (sQ z) (sQzM z) (sQmM z) (sQiM z). pose morph_ofQ x z Qxz := forall u, ofQ z (Qxz u) = ofQ x u. have QtoQ z x: x \in sQ z -> {Qxz : 'AHom(Q x, Q z) | morph_ofQ x z Qxz}. move=> z_x; pose Qxz u := inQ z (ofQ x u). have QxzE u: ofQ z (Qxz u) = ofQ x u by apply/inQ_K/(sQtrans x). have Qxza : zmod_morphism Qxz. by move=> u v; apply: (canLR (ofQ_K z)); rewrite !rmorphB !QxzE. have Qxzm : monoid_morphism Qxz. by split=> [|u v]; apply: (canLR (ofQ_K z)); rewrite ?rmorph1 ?rmorphM /= ?QxzE. have QxzaM := GRing.isZmodMorphism.Build _ _ _ Qxza. have QxzmM := GRing.isMonoidMorphism.Build _ _ _ Qxzm. have QxzlM := GRing.isScalable.Build _ _ _ _ _ (rat_linear Qxza). pose QxzLRM : {lrmorphism _ -> _} := HB.pack Qxz QxzaM QxzmM QxzlM. by exists (linfun_ahom QxzLRM) => u; rewrite lfunE QxzE. pose sQs z s := all (mem (sQ z)) s. have inQsK z s: sQs z s -> map (ofQ z) (map (inQ z) s) = s. by rewrite -map_comp => /allP/(_ _ _)/inQ_K; apply: map_id_in. have inQpK z p: p \is a polyOver (sQ z) -> (p ^ inQ z) ^ ofQ z = p. by move=> /allP/(_ _ _)/inQ_K/=/map_poly_id; rewrite -map_poly_comp. have{gen PET2 genP} PET s: {z | sQs z s & <<1 & map (inQ z) s>>%VS = fullv}. have [y /inQsK Ds]: {y | sQs y s}. elim: s => [|x s /= [y IHs]]; first by exists 0. have [z /genP z_x /genP z_y] := PET2 x y. by exists z; rewrite /= {x}z_x; apply: sub_all IHs => x /sQtrans/= ->. have [w defQs] := PET_Qz _ <<1 & map (inQ y) s>>%AS; pose z := ofQ y w. have z_s: sQs z s. rewrite -Ds /sQs all_map; apply/allP=> u s_u /=. by rewrite sQof2 defQs seqv_sub_adjoin. have [[u Dz defQz] [Qzy QzyE]] := (genQz z, QtoQ y z (sQof y w)). exists z => //; apply/eqP; rewrite eqEsubv subvf /= -defQz. rewrite -(limg_ker0 _ _ (AHom_lker0 Qzy)) aimg_adjoin_seq aimg_adjoin aimg1. rewrite -[map _ _](mapK (ofQ_K y)) -(map_comp (ofQ y)) (eq_map QzyE) inQsK //. by rewrite -defQs -(canLR (ofQ_K y) Dz) -QzyE ofQ_K. pose rp s := \prod_(z <- s) ('X - z%:P). have map_rp (f : {rmorphism _ -> _}) s: rp _ s ^ f = rp _ (map f s). rewrite rmorph_prod /rp big_map; apply: eq_bigr => x _ /=. by rewrite rmorphB /= map_polyX map_polyC. pose is_Gal z := SplittingField.axiom (Q z). have galQ x: {z | x \in sQ z & is_Gal z}. have /sig2W[p mon_p pz0] := algC x. have [s Dp] := closed_field_poly_normal (p ^ QtoC). rewrite (monicP _) ?monic_map // scale1r in Dp; have [z z_s defQz] := PET s. exists z; first by apply/(allP z_s); rewrite -root_prod_XsubC -Dp. exists p^@; first exact: alg_polyOver. exists (map (inQ z) s); last by apply/vspaceP=> u; rewrite defQz memvf. by rewrite -(eqp_map (ofQ z)) pQof Dp map_rp inQsK ?eqpxx. pose is_realC x := {R : archiRealFieldType & {rmorphism Q x -> R}}. pose realC := {x : C & is_realC x}. pose has_Rroot (xR : realC) p c (Rx := sQ (tag xR)) := [&& p \is a polyOver Rx, p \is monic, c \in Rx & p.[0] == - c ^+ 2]. pose root_in (xR : realC) p := exists2 w, w \in sQ (tag xR) & root p w. pose extendsR (xR yR : realC) := tag xR \in sQ (tag yR). have add_Rroot xR p c: {yR | extendsR xR yR & has_Rroot xR p c -> root_in yR p}. rewrite {}/extendsR; case: (has_Rroot xR p c) / and4P; last by exists xR. case: xR => x [R QxR] /= [/inQpK <-]; move: (p ^ _) => {}p mon_p /inQ_K<- Dc. have{c Dc} p0_le0: (p ^ QxR).[0] <= 0. rewrite horner_coef0 coef_map -[p`_0]ofQ_K -coef_map -horner_coef0 (eqP Dc). by rewrite -rmorphXn -rmorphN ofQ_K /= rmorphN rmorphXn oppr_le0 sqr_ge0. have [s Dp] := closed_field_poly_normal (p ^ ofQ x). have{Dp} /all_and2[s_p p_s] y: root (p ^ ofQ x) y <-> (y \in s). by rewrite Dp (monicP mon_p) scale1r root_prod_XsubC. rewrite map_monic in mon_p; have [z /andP[z_x /allP/=z_s] _] := PET (x :: s). have{z_x} [[Qxz QxzE] Dx] := (QtoQ z x z_x, inQ_K z x z_x). pose Qx := <<1; inQ z x>>%AS. have pQwx q1: q1 \is a polyOver Qx -> {q | q1 = q ^ Qxz}. move/polyOverP=> Qx_q1; exists ((q1 ^ ofQ z) ^ inQ x). apply: (map_poly_inj (ofQ z)); rewrite -map_poly_comp (eq_map_poly QxzE). by rewrite inQpK ?polyOver_poly // => j _; rewrite -Dx sQof2 Qx_q1. have /all_sig[t_ Dt] u: {t | <<1; t>> = <<Qx; u>>} by apply: PET_Qz. suffices{p_s}[u Ry px0]: {u : Q z & is_realC (ofQ z (t_ u)) & ofQ z u \in s}. exists (Tagged is_realC Ry) => [|_] /=. by rewrite -Dx sQof2 Dt subvP_adjoin ?memv_adjoin. by exists (ofQ z u); rewrite ?p_s // sQof2 Dt memv_adjoin. without loss{z_s s_p} [u Dp s_y]: p mon_p p0_le0 / {u | minPoly Qx u = p ^ Qxz & ofQ z u \in s}. - move=> IHp; move: {2}_.+1 (ltnSn (size p)) => d. elim: d => // d IHd in p mon_p s_p p0_le0 *; rewrite ltnS => le_p_d. have /closed_rootP/sig_eqW[y py0]: size (p ^ ofQ x) != 1. rewrite size_map_poly size_poly_eq1 eqp_monic ?rpred1 //. by apply: contraTneq p0_le0 => ->; rewrite rmorph1 hornerC lt_geF ?ltr01. have /s_p s_y := py0; have /z_s/sQ_inQ[u Dy] := s_y. have /pQwx[q Dq] := minPolyOver Qx u. have mon_q: q \is monic by have:= monic_minPoly Qx u; rewrite Dq map_monic. have /dvdpP/sig_eqW[r Dp]: q %| p. rewrite -(dvdp_map Qxz) -Dq minPoly_dvdp //. by apply: polyOver_poly => j _; rewrite -sQof2 QxzE Dx. by rewrite -(fmorph_root (ofQ z)) Dy -map_poly_comp (eq_map_poly QxzE). have mon_r: r \is monic by rewrite Dp monicMr in mon_p. have [q0_le0 | q0_gt0] := lerP ((q ^ QxR).[0]) 0. by apply: (IHp q) => //; exists u; rewrite ?Dy. have r0_le0: (r ^ QxR).[0] <= 0. by rewrite -(ler_pM2r q0_gt0) mul0r -hornerM -rmorphM -Dp. apply: (IHd r mon_r) => // [w rw0|]. by rewrite s_p // Dp rmorphM rootM rw0. apply: leq_trans le_p_d; rewrite Dp size_Mmonic ?monic_neq0 // addnC. by rewrite -(size_map_poly Qxz q) -Dq size_minPoly !ltnS leq_addl. exists u => {s s_y}//; set y := ofQ z (t_ u); set p1 := minPoly Qx u in Dp. have /QtoQ[Qyz QyzE]: y \in sQ z := sQof z (t_ u). pose q1_ v := Fadjoin_poly Qx u (Qyz v). have{} QyzE v: Qyz v = (q1_ v).[u]. by rewrite Fadjoin_poly_eq // -Dt -sQof2 QyzE sQof. have /all_sig2[q_ coqp Dq] v: {q | v != 0 -> coprimep p q & q ^ Qxz = q1_ v}. have /pQwx[q Dq]: q1_ v \is a polyOver Qx by apply: Fadjoin_polyOver. exists q => // nz_v; rewrite -(coprimep_map Qxz) -Dp -Dq -gcdp_eqp1. have /minPoly_irr/orP[] // := dvdp_gcdl p1 (q1_ v). by rewrite gcdp_polyOver ?minPolyOver ?Fadjoin_polyOver. rewrite -/p1 {1}/eqp dvdp_gcd => /and3P[_ _ /dvdp_leq/=/implyP]. rewrite size_minPoly ltnNge size_poly (contraNneq _ nz_v) // => q1v0. by rewrite -(fmorph_eq0 Qyz) /= QyzE q1v0 horner0. pose h2 : R := 2^-1; have nz2: 2 != 0 :> R by rewrite pnatr_eq0. pose itv ab := [pred c : R | ab.1 <= c <= ab.2]. pose wid ab : R := ab.2 - ab.1; pose mid ab := (ab.1 + ab.2) * h2. pose sub_itv ab cd := cd.1 <= ab.1 :> R /\ ab.2 <= cd.2 :> R. pose xup q ab := [/\ q.[ab.1] <= 0, q.[ab.2] >= 0 & ab.1 <= ab.2 :> R]. pose narrow q ab (c := mid ab) := if q.[c] >= 0 then (ab.1, c) else (c, ab.2). pose find k q := iter k (narrow q). have findP k q ab (cd := find k q ab): xup q ab -> [/\ xup q cd, sub_itv cd ab & wid cd = wid ab / (2 ^ k)%:R]. - rewrite {}/cd; case: ab => a b xq_ab. elim: k => /= [|k]; first by rewrite divr1. case: (find k q _) => c d [[/= qc_le0 qd_ge0 le_cd] [/= le_ac le_db] Dcd]. have [/= le_ce le_ed] := midf_le le_cd; set e := _ / _ in le_ce le_ed. rewrite expnSr natrM invfM mulrA -{}Dcd /narrow /= -[mid _]/e. have [qe_ge0 // | /ltW qe_le0] := lerP 0 q.[e]. do ?split=> //=; [exact: (le_trans le_ed) | apply: canRL (mulfK nz2) _]. by rewrite mulrBl divfK // mulr_natr opprD addrACA subrr add0r. do ?split=> //=; [exact: (le_trans le_ac) | apply: canRL (mulfK nz2) _]. by rewrite mulrBl divfK // mulr_natr opprD addrACA subrr addr0. have find_root r q ab: xup q ab -> {n | forall x, x \in itv (find n q ab) ->`|(r * q).[x]| < h2}. - move=> xab; have ub_ab := poly_itv_bound _ ab.1 ab.2. have [Mu MuP] := ub_ab r; have /all_sig[Mq MqP] j := ub_ab q^`N(j). pose d := wid ab; pose dq := \poly_(i < (size q).-1) Mq i.+1. have d_ge0: 0 <= d by rewrite subr_ge0; case: xab. have [Mdq MdqP] := poly_disk_bound dq d. pose n := Num.bound (Mu * Mdq * d); exists n => c /andP[]. have{xab} [[]] := findP n _ _ xab; case: (find n q ab) => a1 b1 /=. rewrite -/d => qa1_le0 qb1_ge0 le_ab1 [/= le_aa1 le_b1b] Dab1 le_a1c le_cb1. have /MuP lbMu: c \in itv ab. by rewrite inE (le_trans le_aa1) ?(le_trans le_cb1). have Mu_ge0: 0 <= Mu by rewrite (le_trans _ lbMu). have Mdq_ge0: 0 <= Mdq. by rewrite (le_trans _ (MdqP 0 _)) ?normr0. suffices lb1 a2 b2 (ab1 := (a1, b1)) (ab2 := (a2, b2)) : xup q ab2 /\ sub_itv ab2 ab1 -> q.[b2] - q.[a2] <= Mdq * wid ab1. + apply: le_lt_trans (_ : Mu * Mdq * wid (a1, b1) < h2); last first. rewrite {}Dab1 mulrA ltr_pdivrMr ?ltr0n ?expn_gt0 //. rewrite (lt_le_trans (archi_boundP _)) ?mulr_ge0 ?ltr_nat // -/n. rewrite ler_pdivlMl ?ltr0n // -natrM ler_nat. by case: n => // n; rewrite expnS leq_pmul2l // ltn_expl. rewrite -mulrA hornerM normrM ler_pM //. have [/ltW qc_le0 | qc_ge0] := ltrP q.[c] 0. by apply: le_trans (lb1 c b1 _); rewrite ?ler0_norm ?ler_wpDl. by apply: le_trans (lb1 a1 c _); rewrite ?ger0_norm ?ler_wpDr ?oppr_ge0. case{c le_a1c le_cb1 lbMu}=> [[/=qa2_le0 qb2_ge0 le_ab2] [/=le_a12 le_b21]]. pose h := b2 - a2; have h_ge0: 0 <= h by rewrite subr_ge0. have [-> | nz_q] := eqVneq q 0. by rewrite !horner0 subrr mulr_ge0 ?subr_ge0. rewrite -(subrK a2 b2) (addrC h) (nderiv_taylor q (mulrC a2 h)). rewrite (polySpred nz_q) big_ord_recl /= mulr1 nderivn0 addrC addKr. have [le_aa2 le_b2b] := (le_trans le_aa1 le_a12, le_trans le_b21 le_b1b). have /MqP MqPx1: a2 \in itv ab by rewrite inE le_aa2 (le_trans le_ab2). apply: le_trans (le_trans (ler_norm _) (ler_norm_sum _ _ _)) _. apply: le_trans (_ : `|dq.[h] * h| <= _); last first. by rewrite normrM ler_pM ?normr_ge0 ?MdqP // ?ger0_norm ?lerB ?h_ge0. rewrite horner_poly ger0_norm ?mulr_ge0 ?sumr_ge0 // => [|j _]; last first. by rewrite mulr_ge0 ?exprn_ge0 // (le_trans _ (MqPx1 _)). rewrite mulr_suml ler_sum // => j _; rewrite normrM -mulrA -exprSr. by rewrite ler_pM // normrX ger0_norm. have [ab0 xab0]: {ab | xup (p ^ QxR) ab}. have /monic_Cauchy_bound[b pb_gt0]: p ^ QxR \is monic by apply: monic_map. by exists (0, `|b|); rewrite /xup normr_ge0 p0_le0 ltW ?pb_gt0 ?ler_norm. pose ab_ n := find n (p ^ QxR) ab0; pose Iab_ n := itv (ab_ n). pose lim v a := (q_ v ^ QxR).[a]; pose nlim v n := lim v (ab_ n).2. have lim0 a: lim 0 a = 0. rewrite /lim; suffices /eqP ->: q_ 0 == 0 by rewrite rmorph0 horner0. by rewrite -(map_poly_eq0 Qxz) Dq /q1_ !raddf0. have limN v a: lim (- v) a = - lim v a. rewrite /lim; suffices ->: q_ (- v) = - q_ v by rewrite rmorphN hornerN. apply: (map_poly_inj Qxz). by rewrite Dq /q1_ (raddfN _ v) (raddfN _ (Qyz v)) [RHS]raddfN /= Dq. pose lim_nz n v := exists2 e, e > 0 & {in Iab_ n, forall a, e < `|lim v a| }. have /(all_sig_cond 0)[n_ nzP] v: v != 0 -> {n | lim_nz n v}. move=> nz_v; do [move/(_ v nz_v); rewrite -(coprimep_map QxR)] in coqp. have /sig_eqW[r r_pq_1] := Bezout_eq1_coprimepP _ _ coqp. have /(find_root r.1)[n ub_rp] := xab0; exists n. have [M Mgt0 ubM]: {M | 0 < M & {in Iab_ n, forall a, `|r.2.[a]| <= M}}. have [M ubM] := poly_itv_bound r.2 (ab_ n).1 (ab_ n).2. exists (Num.max 1 M) => [|s /ubM vM]; first by rewrite lt_max ltr01. by rewrite le_max orbC vM. exists (h2 / M) => [|a xn_a]; first by rewrite divr_gt0 ?invr_gt0 ?ltr0n. rewrite ltr_pdivrMr // -(ltrD2l h2) -mulr2n -mulr_natl divff //. rewrite -normr1 -(hornerC 1 a) -[1%:P]r_pq_1 hornerD. rewrite ?(le_lt_trans (ler_normD _ _)) ?ltr_leD ?ub_rp //. by rewrite mulrC hornerM normrM ler_wpM2l ?ubM. have ab_le m n: (m <= n)%N -> (ab_ n).2 \in Iab_ m. move/subnKC=> <-; move: {n}(n - m)%N => n; rewrite /ab_. have /(findP m)[/(findP n)[[_ _]]] := xab0. rewrite /find -iterD -!/(find _ _) -!/(ab_ _) addnC !inE. by move: (ab_ _) => /= ab_mn le_ab_mn [/le_trans->]. pose lt v w := 0 < nlim (w - v) (n_ (w - v)). have posN v: lt 0 (- v) = lt v 0 by rewrite /lt subr0 add0r. have posB v w: lt 0 (w - v) = lt v w by rewrite /lt subr0. have posE n v: (n_ v <= n)%N -> lt 0 v = (0 < nlim v n). rewrite /lt subr0 /nlim => /ab_le; set a := _.2; set b := _.2 => Iv_a. have [-> | /nzP[e e_gt0]] := eqVneq v 0; first by rewrite !lim0 ltxx. move: (n_ v) => m in Iv_a b * => v_gte. without loss lt0v: v v_gte / 0 < lim v b. move=> IHv; apply/idP/idP => [v_gt0 | /ltW]; first by rewrite -IHv. rewrite lt_def -normr_gt0 ?(lt_trans _ (v_gte _ _)) ?ab_le //=. rewrite !leNgt -!oppr_gt0 -!limN; apply: contra => v_lt0. by rewrite -IHv // => c /v_gte; rewrite limN normrN. rewrite lt0v (lt_trans e_gt0) ?(lt_le_trans (v_gte a Iv_a)) //. rewrite ger0_norm // leNgt; apply/negP=> /ltW lev0. have [le_a le_ab] : _ /\ a <= b := andP Iv_a. have xab: xup (q_ v ^ QxR) (a, b) by move/ltW in lt0v. have /(find_root (h2 / e)%:P)[n1] := xab; have /(findP n1)[[_ _]] := xab. case: (find _ _ _) => c d /= le_cd [/= le_ac le_db] _ /(_ c)/implyP. rewrite inE lexx le_cd hornerM hornerC normrM le_gtF //. rewrite ger0_norm ?divr_ge0 ?invr_ge0 ?ler0n ?(ltW e_gt0) // mulrAC. rewrite ler_pdivlMr // ler_wpM2l ?invr_ge0 ?ler0n // ltW // v_gte //=. by rewrite inE -/b (le_trans le_a) //= (le_trans le_cd). pose lim_pos m v := exists2 e, e > 0 & forall n, (m <= n)%N -> e < nlim v n. have posP v: reflect (exists m, lim_pos m v) (lt 0 v). apply: (iffP idP) => [v_gt0|[m [e e_gt0 v_gte]]]; last first. by rewrite (posE _ _ (leq_maxl _ m)) (lt_trans e_gt0) ?v_gte ?leq_maxr. have [|e e_gt0 v_gte] := nzP v. by apply: contraTneq v_gt0 => ->; rewrite /lt subr0 /nlim lim0 ltxx. exists (n_ v), e => // n le_vn; rewrite (posE n) // in v_gt0. by rewrite -(ger0_norm (ltW v_gt0)) v_gte ?ab_le. have posNneg v: lt 0 v -> ~~ lt v 0. case/posP=> m [d d_gt0 v_gtd]; rewrite -posN. apply: contraL d_gt0 => /posP[n [e e_gt0 nv_gte]]. rewrite lt_gtF // (lt_trans (v_gtd _ (leq_maxl m n))) // -oppr_gt0. by rewrite /nlim -limN (lt_trans e_gt0) ?nv_gte ?leq_maxr. have posVneg v: v != 0 -> lt 0 v || lt v 0. case/nzP=> e e_gt0 v_gte; rewrite -posN; set w := - v. have [m [le_vm le_wm _]] := maxn3 (n_ v) (n_ w) 0; rewrite !(posE m) //. by rewrite /nlim limN -ltr_normr (lt_trans e_gt0) ?v_gte ?ab_le. have posD v w: lt 0 v -> lt 0 w -> lt 0 (v + w). move=> /posP[m [d d_gt0 v_gtd]] /posP[n [e e_gt0 w_gte]]. apply/posP; exists (maxn m n), (d + e) => [|k]; first exact: addr_gt0. rewrite geq_max => /andP[le_mk le_nk]; rewrite /nlim /lim. have ->: q_ (v + w) = q_ v + q_ w. by apply: (map_poly_inj Qxz); rewrite rmorphD /= !{1}Dq /q1_ !raddfD. by rewrite rmorphD hornerD ltrD ?v_gtd ?w_gte. have posM v w: lt 0 v -> lt 0 w -> lt 0 (v * w). move=> /posP[m [d d_gt0 v_gtd]] /posP[n [e e_gt0 w_gte]]. have /dvdpP[r /(canRL (subrK _))Dqvw]: p %| q_ (v * w) - q_ v * q_ w. rewrite -(dvdp_map Qxz) rmorphB rmorphM /= !Dq -Dp minPoly_dvdp //. by rewrite rpredB 1?rpredM ?Fadjoin_polyOver. by rewrite rootE !hornerE -!QyzE rmorphM subrr. have /(find_root ((d * e)^-1 *: r ^ QxR))[N ub_rp] := xab0. pose f := d * e * h2; apply/posP; exists (maxn N (maxn m n)), f => [|k]. by rewrite !mulr_gt0 ?invr_gt0 ?ltr0n. rewrite !geq_max => /and3P[/ab_le/ub_rp{}ub_rp le_mk le_nk]. rewrite -(ltrD2r f) -mulr2n -mulr_natr divfK // /nlim /lim Dqvw. rewrite rmorphD hornerD /= -addrA -ltrBlDl ler_ltD //. by rewrite rmorphM hornerM ler_pM ?ltW ?v_gtd ?w_gte. rewrite -ltr_pdivrMl ?mulr_gt0 // (le_lt_trans _ ub_rp) //. by rewrite -scalerAl hornerZ -rmorphM mulrN -normrN ler_norm. pose le v w := (v == w) || lt v w. pose abs v := if le 0 v then v else - v. have absN v: abs (- v) = abs v. rewrite /abs /le !(eq_sym 0) oppr_eq0 opprK posN. have [-> | /posVneg/orP[v_gt0 | v_lt0]] := eqVneq; first by rewrite oppr0. by rewrite v_gt0 /= -if_neg posNneg. by rewrite v_lt0 /= -if_neg -(opprK v) posN posNneg ?posN. have absE v: le 0 v -> abs v = v by rewrite /abs => ->. pose RyM := Num.IntegralDomain_isLtReal.Build (Q y) posD posM posNneg posB posVneg absN absE (rrefl _). pose Ry : realFieldType := HB.pack (Q y) RyM. have QisArchi : Num.NumDomain_bounded_isArchimedean Ry. by constructor; apply: (@rat_algebraic_archimedean Ry _ alg_integral). exists (HB.pack_for archiRealFieldType _ QisArchi); apply: idfun. have some_realC: realC. suffices /all_sig[f QfK] x: {a | in_alg (Q 0) a = x}. have fA : zmod_morphism f. exact: can2_zmod_morphism (inj_can_sym QfK (fmorph_inj _)) QfK. have fM : monoid_morphism f. exact: can2_monoid_morphism (inj_can_sym QfK (fmorph_inj _)) QfK. pose faM := GRing.isZmodMorphism.Build _ _ _ fA. pose fmM := GRing.isMonoidMorphism.Build _ _ _ fM. pose fRM : {rmorphism _ -> _} := HB.pack f faM fmM. by exists 0, rat; exact: fRM. have /Fadjoin1_polyP/sig_eqW[q]: x \in <<1; 0>>%VS by rewrite -sQof2 rmorph0. by exists q.[0]; rewrite -horner_map rmorph0. pose fix xR n : realC := if n isn't n'.+1 then some_realC else if unpickle (nth 0 (CodeSeq.decode n') 1) isn't Some (p, c) then xR n' else tag (add_Rroot (xR n') p c). pose x_ n := tag (xR n). have sRle m n: (m <= n)%N -> {subset sQ (x_ m) <= sQ (x_ n)}. move/subnK <-; elim: {n}(n - m)%N => // n IHn x /IHn{IHn}Rx. rewrite addSn /x_ /=; case: (unpickle _) => [[p c]|] //=. by case: (add_Rroot _ _ _) => yR /= /(sQtrans _ x)->. have xRroot n p c: has_Rroot (xR n) p c -> {m | n <= m & root_in (xR m) p}%N. case/and4P=> Rp mon_p Rc Dc; pose m := CodeSeq.code [:: n; pickle (p, c)]. have le_n_m: (n <= m)%N by apply/ltnW/(allP (CodeSeq.ltn_code _))/mem_head. exists m.+1; rewrite ?leqW /x_ //= CodeSeq.codeK pickleK. case: (add_Rroot _ _ _) => yR /= _; apply; apply/and4P. by split=> //; first apply: polyOverS Rp; apply: (sRle n). have /all_sig[z_ /all_and3[Ri_R Ri_i defRi]] n (x := x_ n): {z | [/\ x \in sQ z, i \in sQ z & <<<<1; inQ z x>>; inQ z i>> = fullv]}. - have [z /and3P[z_x z_i _] Dzi] := PET [:: x; i]. by exists z; rewrite -adjoin_seq1 -adjoin_cons. pose i_ n := inQ (z_ n) i; pose R_ n := <<1; inQ (z_ n) (x_ n)>>%AS. have memRi n: <<R_ n; i_ n>> =i predT by move=> u; rewrite defRi memvf. have sCle m n: (m <= n)%N -> {subset sQ (z_ m) <= sQ (z_ n)}. move/sRle=> Rmn _ /sQ_inQ[u <-]. have /Fadjoin_polyP[p /polyOverP Rp ->] := memRi m u. rewrite -horner_map inQ_K ?(@rpred_horner _ (sQC _)) //=. apply/polyOver_poly=> j _. by apply: sQtrans (Ri_R n); rewrite Rmn // -(inQ_K _ _ (Ri_R m)) sQof2. have R'i n: i \notin sQ (x_ n). rewrite /x_; case: (xR n) => x [Rn QxR] /=. apply: contraL (@ltr01 Rn) => /sQ_inQ[v Di]. suffices /eqP <-: - QxR v ^+ 2 == 1 by rewrite oppr_gt0 -leNgt sqr_ge0. rewrite -rmorphXn -rmorphN fmorph_eq1 -(fmorph_eq1 (ofQ x)) rmorphN eqr_oppLR. by rewrite rmorphXn /= Di Di2. have szX2_1: size ('X^2 + 1) = 3%N. by move=> R; rewrite size_polyDl ?size_polyXn ?size_poly1. have minp_i n (p_i := minPoly (R_ n) (i_ n)): p_i = 'X^2 + 1. have p_dv_X2_1: p_i %| 'X^2 + 1. rewrite minPoly_dvdp ?rpredD ?rpredX ?rpred1 ?polyOverX //. rewrite -(fmorph_root (ofQ _)) inQ_K // rmorphD rmorph1 /= map_polyXn. by rewrite rootE hornerD hornerXn hornerC Di2 addNr. apply/eqP; rewrite -eqp_monic ?monic_minPoly //; last first. by rewrite monicE lead_coefE szX2_1 coefD coefXn coefC addr0. rewrite -dvdp_size_eqp // eqn_leq dvdp_leq -?size_poly_eq0 ?szX2_1 //= ltnNge. by rewrite size_minPoly ltnS leq_eqVlt orbF adjoin_deg_eq1 -sQof2 !inQ_K. have /all_sig[n_ FTA] z: {n | z \in sQ (z_ n)}. without loss [z_i gal_z]: z / i \in sQ z /\ is_Gal z. have [y /and3P[/sQtrans y_z /sQtrans y_i _] _] := PET [:: z; i]. have [t /sQtrans t_y gal_t] := galQ y. by case/(_ t)=> [|n]; last exists n; rewrite ?y_z ?y_i ?t_y. apply/sig_eqW; have n := 0%N. have [p]: exists p, [&& p \is monic, root p z & p \is a polyOver (sQ (z_ n))]. have [p mon_p pz0] := algC z; exists (p ^ QtoC). by rewrite map_monic mon_p pz0 -(pQof (z_ n)); apply/polyOver_poly. have [d lepd] := ubnP (size p); elim: d => // d IHd in p n lepd * => pz0. have [t [t_C t_z gal_t]]: exists t, [/\ z_ n \in sQ t, z \in sQ t & is_Gal t]. have [y /and3P[y_C y_z _]] := PET [:: z_ n; z]. by have [t /(sQtrans y)t_y] := galQ y; exists t; rewrite !t_y. pose QtMixin := FieldExt_isSplittingField.Build _ (Q t) gal_t. pose Qt : splittingFieldType rat := HB.pack (Q t) QtMixin. have /QtoQ[CnQt CnQtE] := t_C. pose Rn : {subfield Qt} := (CnQt @: R_ n)%AS; pose i_t : Qt := CnQt (i_ n). pose Cn : {subfield Qt} := <<Rn; i_t>>%AS. have defCn: Cn = limg CnQt :> {vspace Q t} by rewrite /= -aimg_adjoin defRi. have memRn u: (u \in Rn) = (ofQ t u \in sQ (x_ n)). by rewrite /= aimg_adjoin aimg1 -sQof2 CnQtE inQ_K. have memCn u: (u \in Cn) = (ofQ t u \in sQ (z_ n)). have [v Dv genCn] := genQz (z_ n). by rewrite -Dv -CnQtE sQof2 defCn -genCn aimg_adjoin aimg1. have Dit: ofQ t i_t = i by rewrite CnQtE inQ_K. have Dit2: i_t ^+ 2 = -1. by apply: (fmorph_inj (ofQ t)); rewrite rmorphXn rmorphN1 /= Dit. have dimCn: \dim_Rn Cn = 2%N. rewrite -adjoin_degreeE adjoin_degree_aimg. by apply: succn_inj; rewrite -size_minPoly minp_i szX2_1. have /sQ_inQ[u_z Dz] := t_z; pose Rz := <<Cn; u_z>>%AS. have{p lepd pz0} le_Rz_d: (\dim_Cn Rz < d)%N. rewrite -ltnS -adjoin_degreeE -size_minPoly (leq_trans _ lepd) // !ltnS. have{pz0} [mon_p pz0 Cp] := and3P pz0. have{Cp} Dp: ((p ^ inQ (z_ n)) ^ CnQt) ^ ofQ t = p. by rewrite -map_poly_comp (eq_map_poly CnQtE) inQpK. rewrite -Dp size_map_poly dvdp_leq ?monic_neq0 -?(map_monic (ofQ _)) ?Dp //. rewrite defCn minPoly_dvdp //; try by rewrite -(fmorph_root (ofQ t)) Dz Dp. by apply/polyOver_poly=> j _; rewrite memv_img ?memvf. have [sRCn sCnRz]: (Rn <= Cn)%VS /\ (Cn <= Rz)%VS by rewrite !subv_adjoin. have sRnRz := subv_trans sRCn sCnRz. have{gal_z} galRz: galois Rn Rz. apply/and3P; split; [by []|by apply: sepQ|]. apply/splitting_normalField=> //. pose QzMixin := FieldExt_isSplittingField.Build _ (Q z) gal_z. pose Qz : splittingFieldType _ := HB.pack (Q z) QzMixin. pose u : Qz := inQ z z. have /QtoQ[Qzt QztE] := t_z; exists (minPoly 1 u ^ Qzt). have /polyOver1P[q ->] := minPolyOver 1 u; apply/polyOver_poly=> j _. by rewrite coef_map linearZZ rmorph1 rpredZ ?rpred1. have [s /eqP Ds] := splitting_field_normal 1 u. rewrite Ds; exists (map Qzt s); first by rewrite map_rp eqpxx. apply/eqP; rewrite eqEsubv; apply/andP; split. apply/Fadjoin_seqP; split=> // _ /mapP[w s_w ->]. by rewrite (subvP (adjoinSl u_z (sub1v _))) // -sQof2 Dz QztE. rewrite /= adjoinC (Fadjoin_idP _) -/Rz; last first. by rewrite (subvP (adjoinSl _ (sub1v _))) // -sQof2 Dz Dit. rewrite /= -adjoin_seq1 adjoin_seqSr //; apply/allP=> /=; rewrite andbT. rewrite -(mem_map (fmorph_inj (ofQ _))) -map_comp (eq_map QztE); apply/mapP. by exists u; rewrite ?inQ_K // -root_prod_XsubC -Ds root_minPoly. have galCz: galois Cn Rz by rewrite (galoisS _ galRz) ?sRCn. have [Cz | C'z]:= boolP (u_z \in Cn); first by exists n; rewrite -Dz -memCn. pose G := 'Gal(Rz / Cn)%G; have{C'z} ntG: G :!=: 1%g. rewrite trivg_card1 -galois_dim 1?(galoisS _ galCz) ?subvv //=. by rewrite -adjoin_degreeE adjoin_deg_eq1. pose extRz m := exists2 w, ofQ t w \in sQ (z_ m) & w \in [predD Rz & Cn]. suffices [m le_n_m [w Cw /andP[C'w Rz_w]]]: exists2 m, (n <= m)%N & extRz m. pose p := minPoly <<Cn; w>> u_z; apply: (IHd (p ^ ofQ t) m). apply: leq_trans le_Rz_d; rewrite size_map_poly size_minPoly ltnS. rewrite adjoin_degreeE adjoinC (addv_idPl Rz_w) agenv_id. rewrite ltn_divLR ?adim_gt0 // mulnC. rewrite muln_divCA ?field_dimS ?subv_adjoin // ltn_Pmulr ?adim_gt0 //. by rewrite -adjoin_degreeE ltnNge leq_eqVlt orbF adjoin_deg_eq1. rewrite map_monic monic_minPoly -Dz fmorph_root root_minPoly /=. have /polyOverP Cw_p: p \is a polyOver <<Cn; w>>%VS by apply: minPolyOver. apply/polyOver_poly=> j _; have /Fadjoin_polyP[q Cq {j}->] := Cw_p j. rewrite -horner_map (@rpred_horner _ (sQC _)) //. apply/polyOver_poly=> j _. by rewrite (sCle n) // -memCn (polyOverP Cq). have [evenG | oddG] := boolP (2.-group G); last first. have [P /and3P[sPG evenP oddPG]] := Sylow_exists 2 'Gal(Rz / Rn). have [w defQw] := PET_Qz t [aspace of fixedField P]. pose pw := minPoly Rn w; pose p := (- pw * (pw \Po - 'X)) ^ ofQ t. have sz_pw: (size pw).-1 = #|'Gal(Rz / Rn) : P|. rewrite size_minPoly adjoin_degreeE -dim_fixed_galois //= -defQw. congr (\dim_Rn _); apply/esym/eqP; rewrite eqEsubv adjoinSl ?sub1v //=. by apply/FadjoinP; rewrite memv_adjoin /= defQw -galois_connection. have mon_p: p \is monic. have mon_pw: pw \is monic := monic_minPoly _ _. rewrite map_monic mulNr -mulrN monicMl // monicE. rewrite !(lead_coefN, lead_coef_comp) ?size_polyN ?size_polyX //. by rewrite lead_coefX sz_pw -signr_odd odd_2'nat oddPG mulrN1 opprK. have Dp0: p.[0] = - ofQ t pw.[0] ^+ 2. rewrite -(rmorph0 (ofQ t)) horner_map hornerM rmorphM. by rewrite horner_comp !hornerN hornerX oppr0 /= rmorphN mulNr. have Rpw: pw \is a polyOver Rn by apply: minPolyOver. have Rp: p \is a polyOver (sQ (x_ n)). apply/polyOver_poly=> j _; rewrite -memRn; apply: polyOverP j => /=. by rewrite rpredM 1?polyOver_comp ?rpredN ?polyOverX. have Rp0: ofQ t pw.[0] \in sQ (x_ n) by rewrite -memRn rpred_horner ?rpred0. have [|{mon_p Rp Rp0 Dp0}m lenm p_Rm_0] := xRroot n p (ofQ t pw.[0]). by rewrite /has_Rroot mon_p Rp Rp0 -Dp0 /=. have{p_Rm_0} [y Ry pw_y]: {y | y \in sQ (x_ m) & root (pw ^ ofQ t) y}. apply/sig2W; have [y Ry] := p_Rm_0. rewrite [p]rmorphM /= map_comp_poly !rmorphN /= map_polyX. rewrite rootM rootN root_comp hornerN hornerX. by case/orP; [exists y | exists (- y)]; rewrite ?(rpredN (sQC _)). have [u Rz_u Dy]: exists2 u, u \in Rz & y = ofQ t u. have Rz_w: w \in Rz by rewrite -sub_adjoin1v defQw capvSl. have [sg [Gsg _ Dpw]] := galois_factors sRnRz galRz w Rz_w. set s := map _ sg in Dpw. have /mapP[u /mapP[g Gg Du] ->]: y \in map (ofQ t) s. by rewrite -root_prod_XsubC -/(rp C _) -map_rp -[rp _ _]Dpw. by exists u; rewrite // Du memv_gal. have{pw_y} pw_u: root pw u by rewrite -(fmorph_root (ofQ t)) -Dy. exists m => //; exists u; first by rewrite -Dy; apply: sQtrans Ry _. rewrite inE /= Rz_u andbT; apply: contra oddG => Cu. suffices: 2.-group 'Gal(Rz / Rn). apply: pnat_dvd; rewrite -!galois_dim // ?(galoisS _ galQr) ?sRCz //. rewrite dvdn_divLR ?field_dimS ?adim_gt0 //. by rewrite mulnC muln_divCA ?field_dimS ?dvdn_mulr. congr (2.-group _): evenP; apply/eqP. rewrite eqEsubset sPG -indexg_eq1 (pnat_1 _ oddPG) // -sz_pw. have (pu := minPoly Rn u): (pu %= pw) || (pu %= 1). by rewrite minPoly_irr ?minPoly_dvdp ?minPolyOver. rewrite /= -size_poly_eq1 {1}size_minPoly orbF => /eqp_size <-. rewrite size_minPoly /= adjoin_degreeE (@pnat_dvd _ 2) // -dimCn. rewrite dvdn_divLR ?divnK ?adim_gt0 ?field_dimS ?subv_adjoin //. exact/FadjoinP. have [w Rz_w deg_w]: exists2 w, w \in Rz & adjoin_degree Cn w = 2%N. have [P sPG iPG]: exists2 P : {group gal_of Rz}, P \subset G & #|G : P| = 2%N. have [_ _ [k oG]] := pgroup_pdiv evenG ntG. have [P [sPG _ oP]] := normal_pgroup evenG (normal_refl G) (leq_pred _). by exists P => //; rewrite -divgS // oP oG pfactorK // -expnB ?subSnn. have [w defQw] := PET_Qz _ [aspace of fixedField P]. exists w; first by rewrite -sub_adjoin1v defQw capvSl. rewrite adjoin_degreeE -iPG -dim_fixed_galois // -defQw; congr (\dim_Cn _). apply/esym/eqP; rewrite eqEsubv adjoinSl ?sub1v //=; apply/FadjoinP. by rewrite memv_adjoin /= defQw -galois_connection. have nz2: 2 != 0 :> Qt by move/pcharf0P: (pcharQ (Q t)) => ->. without loss{deg_w} [C'w Cw2]: w Rz_w / w \notin Cn /\ w ^+ 2 \in Cn. pose p := minPoly Cn w; pose v := p`_1 / 2. have /polyOverP Cp: p \is a polyOver Cn := minPolyOver Cn w. have Cv: v \in Cn by rewrite rpred_div ?rpred_nat ?Cp. move/(_ (v + w)); apply; first by rewrite rpredD // subvP_adjoin. split; first by rewrite rpredDl // -adjoin_deg_eq1 deg_w. rewrite addrC -[_ ^+ 2]subr0 -(rootP (root_minPoly Cn w)) -/p. rewrite sqrrD [_ - _]addrAC rpredD ?rpredX // -mulr_natr -mulrA divfK //. rewrite [w ^+ 2 + _]addrC mulrC -rpredN opprB horner_coef. have /monicP := monic_minPoly Cn w; rewrite lead_coefE size_minPoly deg_w. by rewrite 2!big_ord_recl big_ord1 => ->; rewrite mulr1 mul1r addrK Cp. without loss R'w2: w Rz_w C'w Cw2 / w ^+ 2 \notin Rn. move=> IHw; have [Rw2 | /IHw] := boolP (w ^+ 2 \in Rn); last exact. have R'it: i_t \notin Rn by rewrite memRn Dit. pose v := 1 + i_t; have R'v: v \notin Rn by rewrite rpredDl ?rpred1. have Cv: v \in Cn by rewrite rpredD ?rpred1 ?memv_adjoin. have nz_v: v != 0 by rewrite (memPnC R'v) ?rpred0. apply: (IHw (v * w)); last 1 [|] || by rewrite fpredMl // subvP_adjoin. by rewrite exprMn rpredM // rpredX. rewrite exprMn fpredMr //=; last by rewrite expf_eq0 (memPnC C'w) ?rpred0. by rewrite sqrrD Dit2 expr1n addrC addKr -mulrnAl fpredMl ?rpred_nat. pose rect_w2 u v := [/\ u \in Rn, v \in Rn & u + i_t * (v * 2) = w ^+ 2]. have{Cw2} [u [v [Ru Rv Dw2]]]: {u : Qt & {v | rect_w2 u v}}. rewrite /rect_w2 -(Fadjoin_poly_eq Cw2); set p := Fadjoin_poly Rn i_t _. have /polyOverP Rp: p \is a polyOver Rn by apply: Fadjoin_polyOver. exists p`_0, (p`_1 / 2); split; rewrite ?rpred_div ?rpred_nat //. rewrite divfK // (horner_coef_wide _ (size_Fadjoin_poly _ _ _)) -/p. by rewrite adjoin_degreeE dimCn big_ord_recl big_ord1 mulr1 mulrC. pose p := Poly [:: - (ofQ t v ^+ 2); 0; - ofQ t u; 0; 1]. have [|m lenm [x Rx px0]] := xRroot n p (ofQ t v). rewrite /has_Rroot 2!unfold_in/= lead_coefE horner_coef0 -memRn Rv. rewrite (@PolyK _ 1) ?oner_eq0 //= !eqxx. rewrite !(rpred0 (sQC _)) ?(rpred1 (sQC _)) ?(rpredN (sQC _)) //=. by rewrite !andbT (@rpredX _ (sQC _)) -memRn. suffices [y Cy Dy2]: {y | y \in sQ (z_ m) & ofQ t w ^+ 2 == y ^+ 2}. exists m => //; exists w; last by rewrite inE C'w. by move: Dy2; rewrite eqf_sqr => /pred2P[]->; rewrite ?(rpredN (sQC _)). exists (x + i * (ofQ t v / x)). rewrite (@rpredD _ (sQC _)) 1?(@rpredM _ (sQC _)) //=. exact: (sQtrans (x_ m)). by rewrite (@rpred_div _ (sQC _)) // (sQtrans (x_ m)) // (sRle n) // -memRn. rewrite rootE /horner (@PolyK _ 1) ?oner_eq0 //= ?addr0 ?mul0r in px0. rewrite add0r mul1r -mulrA -expr2 subr_eq0 in px0. have nz_x2: x ^+ 2 != 0. apply: contraNneq R'w2 => y2_0; rewrite -Dw2 mulrCA. suffices /eqP->: v == 0 by rewrite mul0r addr0. by rewrite y2_0 mulr0 eq_sym sqrf_eq0 fmorph_eq0 in px0. apply/eqP/esym/(mulIf nz_x2); rewrite -exprMn -rmorphXn -Dw2 rmorphD rmorphM. rewrite /= Dit mulrDl -expr2 mulrA divfK; last by rewrite expf_eq0 in nz_x2. rewrite mulr_natr addrC sqrrD exprMn Di2 mulN1r -(eqP px0) -mulNr opprB. by rewrite -mulrnAl -mulrnAr -rmorphMn -!mulrDl addrAC subrK. have inFTA n z: (n_ z <= n)%N -> z = ofQ (z_ n) (inQ (z_ n) z). by move/sCle=> le_zn; rewrite inQ_K ?le_zn. pose is_cj n cj := {in R_ n, cj =1 id} /\ cj (i_ n) = - i_ n. have /all_sig[cj_ /all_and2[cj_R cj_i]] n: {cj : 'AEnd(Q (z_ n)) | is_cj n cj}. have cj_P: root (minPoly (R_ n) (i_ n) ^ \1%VF) (- i_ n). rewrite minp_i -(fmorph_root (ofQ _)) !rmorphD !rmorph1 /= !map_polyXn. by rewrite rmorphN inQ_K // rootE hornerD hornerXn hornerC sqrrN Di2 addNr. have cj_M: ahom_in fullv (kHomExtend (R_ n) \1 (i_ n) (- i_ n)). by rewrite -defRi -k1HomE kHomExtendP ?sub1v ?kHom1. exists (AHom cj_M); split=> [y /kHomExtend_id->|]; first by rewrite ?id_lfunE. by rewrite (kHomExtend_val (kHom1 1 _)). pose conj_ n z := ofQ _ (cj_ n (inQ _ z)); pose conj z := conj_ (n_ z) z. have conjK n m z: (n_ z <= n)%N -> (n <= m)%N -> conj_ m (conj_ n z) = z. move/sCle=> le_z_n le_n_m; have /le_z_n/sQ_inQ[u <-] := FTA z. have /QtoQ[Qmn QmnE]: z_ n \in sQ (z_ m) by rewrite (sCle n). rewrite /conj_ ofQ_K -!QmnE !ofQ_K -!comp_lfunE; congr (ofQ _ _). move: u (memRi n u); apply/eqlfun_inP/FadjoinP; split=> /=. apply/eqlfun_inP=> y Ry; rewrite !comp_lfunE !cj_R //. by move: Ry; rewrite -!sQof2 QmnE !inQ_K //; apply: sRle. apply/eqlfunP; rewrite !comp_lfunE cj_i !linearN /=. suffices ->: Qmn (i_ n) = i_ m by rewrite cj_i ?opprK. by apply: (fmorph_inj (ofQ _)); rewrite QmnE !inQ_K. have conjE n z: (n_ z <= n)%N -> conj z = conj_ n z. move/leq_trans=> le_zn; set x := conj z; set y := conj_ n z. have [m [le_xm le_ym le_nm]] := maxn3 (n_ x) (n_ y) n. by have /conjK/=/can_in_inj := leqnn m; apply; rewrite ?conjK // le_zn. have conjA : zmod_morphism conj. move=> x y. have [m [le_xm le_ym le_xym]] := maxn3 (n_ x) (n_ y) (n_ (x - y)). by rewrite !(conjE m) // (inFTA m x) // (inFTA m y) -?rmorphB /conj_ ?ofQ_K. have conjM : monoid_morphism conj. split=> [|x y]; first pose n1 := n_ 1. by rewrite /conj -/n1 -(rmorph1 (ofQ (z_ n1))) /conj_ ofQ_K !rmorph1. have [m [le_xm le_ym le_xym]] := maxn3 (n_ x) (n_ y) (n_ (x * y)). by rewrite !(conjE m) // (inFTA m x) // (inFTA m y) -?rmorphM /conj_ ?ofQ_K. have conjaM := GRing.isZmodMorphism.Build _ _ _ conjA. have conjmM := GRing.isMonoidMorphism.Build _ _ _ conjM. pose conjRM : {rmorphism _ -> _} := HB.pack conj conjaM conjmM. exists conjRM => [z | /(_ i)/eqP/idPn[]] /=. by have [n [/conjE-> /(conjK (n_ z))->]] := maxn3 (n_ (conj z)) (n_ z) 0. rewrite /conj/conj_ cj_i rmorphN inQ_K // eq_sym -addr_eq0 -mulr2n -mulr_natl. rewrite mulf_neq0 ?(memPnC (R'i 0)) ?(rpred0 (sQC _)) //. by have /pcharf0P-> := ftrans (fmorph_pchar QtoC) (pchar_num _). Qed.
Block.lean
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Composition import Mathlib.Data.Matrix.ConjTranspose /-! # Block Matrices ## Main definitions * `Matrix.fromBlocks`: build a block matrix out of 4 blocks * `Matrix.toBlocks₁₁`, `Matrix.toBlocks₁₂`, `Matrix.toBlocks₂₁`, `Matrix.toBlocks₂₂`: extract each of the four blocks from `Matrix.fromBlocks`. * `Matrix.blockDiagonal`: block diagonal of equally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonalRingHom`. * `Matrix.blockDiag`: extract the blocks from the diagonal of a block diagonal matrix. * `Matrix.blockDiagonal'`: block diagonal of unequally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonal'RingHom`. * `Matrix.blockDiag'`: extract the blocks from the diagonal of a block diagonal matrix. -/ variable {l m n o p q : Type*} {m' n' p' : o → Type*} variable {R : Type*} {S : Type*} {α : Type*} {β : Type*} open Matrix namespace Matrix theorem dotProduct_block [Fintype m] [Fintype n] [Mul α] [AddCommMonoid α] (v w : m ⊕ n → α) : v ⬝ᵥ w = v ∘ Sum.inl ⬝ᵥ w ∘ Sum.inl + v ∘ Sum.inr ⬝ᵥ w ∘ Sum.inr := Fintype.sum_sum_type _ section BlockMatrices /-- We can form a single large matrix by flattening smaller 'block' matrices of compatible dimensions. -/ @[pp_nodot] def fromBlocks (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : Matrix (n ⊕ o) (l ⊕ m) α := of <| Sum.elim (fun i => Sum.elim (A i) (B i)) (fun j => Sum.elim (C j) (D j)) @[simp] theorem fromBlocks_apply₁₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : n) (j : l) : fromBlocks A B C D (Sum.inl i) (Sum.inl j) = A i j := rfl @[simp] theorem fromBlocks_apply₁₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : n) (j : m) : fromBlocks A B C D (Sum.inl i) (Sum.inr j) = B i j := rfl @[simp] theorem fromBlocks_apply₂₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : o) (j : l) : fromBlocks A B C D (Sum.inr i) (Sum.inl j) = C i j := rfl @[simp] theorem fromBlocks_apply₂₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : o) (j : m) : fromBlocks A B C D (Sum.inr i) (Sum.inr j) = D i j := rfl /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top left" submatrix. -/ def toBlocks₁₁ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix n l α := of fun i j => M (Sum.inl i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top right" submatrix. -/ def toBlocks₁₂ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix n m α := of fun i j => M (Sum.inl i) (Sum.inr j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom left" submatrix. -/ def toBlocks₂₁ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix o l α := of fun i j => M (Sum.inr i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom right" submatrix. -/ def toBlocks₂₂ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix o m α := of fun i j => M (Sum.inr i) (Sum.inr j) theorem fromBlocks_toBlocks (M : Matrix (n ⊕ o) (l ⊕ m) α) : fromBlocks M.toBlocks₁₁ M.toBlocks₁₂ M.toBlocks₂₁ M.toBlocks₂₂ = M := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl @[simp] theorem toBlocks_fromBlocks₁₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₁₁ = A := rfl @[simp] theorem toBlocks_fromBlocks₁₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₁₂ = B := rfl @[simp] theorem toBlocks_fromBlocks₂₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₂₁ = C := rfl @[simp] theorem toBlocks_fromBlocks₂₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₂₂ = D := rfl /-- Two block matrices are equal if their blocks are equal. -/ theorem ext_iff_blocks {A B : Matrix (n ⊕ o) (l ⊕ m) α} : A = B ↔ A.toBlocks₁₁ = B.toBlocks₁₁ ∧ A.toBlocks₁₂ = B.toBlocks₁₂ ∧ A.toBlocks₂₁ = B.toBlocks₂₁ ∧ A.toBlocks₂₂ = B.toBlocks₂₂ := ⟨fun h => h ▸ ⟨rfl, rfl, rfl, rfl⟩, fun ⟨h₁₁, h₁₂, h₂₁, h₂₂⟩ => by rw [← fromBlocks_toBlocks A, ← fromBlocks_toBlocks B, h₁₁, h₁₂, h₂₁, h₂₂]⟩ @[simp] theorem fromBlocks_inj {A : Matrix n l α} {B : Matrix n m α} {C : Matrix o l α} {D : Matrix o m α} {A' : Matrix n l α} {B' : Matrix n m α} {C' : Matrix o l α} {D' : Matrix o m α} : fromBlocks A B C D = fromBlocks A' B' C' D' ↔ A = A' ∧ B = B' ∧ C = C' ∧ D = D' := ext_iff_blocks theorem fromBlocks_map (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : α → β) : (fromBlocks A B C D).map f = fromBlocks (A.map f) (B.map f) (C.map f) (D.map f) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_transpose (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D)ᵀ = fromBlocks Aᵀ Cᵀ Bᵀ Dᵀ := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_conjTranspose [Star α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D)ᴴ = fromBlocks Aᴴ Cᴴ Bᴴ Dᴴ := by simp only [conjTranspose, fromBlocks_transpose, fromBlocks_map] @[simp] theorem fromBlocks_submatrix_sum_swap_left (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : p → l ⊕ m) : (fromBlocks A B C D).submatrix Sum.swap f = (fromBlocks C D A B).submatrix id f := by ext i j cases i <;> dsimp <;> cases f j <;> rfl @[simp] theorem fromBlocks_submatrix_sum_swap_right (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : p → n ⊕ o) : (fromBlocks A B C D).submatrix f Sum.swap = (fromBlocks B A D C).submatrix f id := by ext i j cases j <;> dsimp <;> cases f i <;> rfl theorem fromBlocks_submatrix_sum_swap_sum_swap {l m n o α : Type*} (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).submatrix Sum.swap Sum.swap = fromBlocks D C B A := by simp /-- A 2x2 block matrix is block diagonal if the blocks outside of the diagonal vanish -/ def IsTwoBlockDiagonal [Zero α] (A : Matrix (n ⊕ o) (l ⊕ m) α) : Prop := toBlocks₁₂ A = 0 ∧ toBlocks₂₁ A = 0 /-- Let `p` pick out certain rows and `q` pick out certain columns of a matrix `M`. Then `toBlock M p q` is the corresponding block matrix. -/ def toBlock (M : Matrix m n α) (p : m → Prop) (q : n → Prop) : Matrix { a // p a } { a // q a } α := M.submatrix (↑) (↑) @[simp] theorem toBlock_apply (M : Matrix m n α) (p : m → Prop) (q : n → Prop) (i : { a // p a }) (j : { a // q a }) : toBlock M p q i j = M ↑i ↑j := rfl /-- Let `p` pick out certain rows and columns of a square matrix `M`. Then `toSquareBlockProp M p` is the corresponding block matrix. -/ def toSquareBlockProp (M : Matrix m m α) (p : m → Prop) : Matrix { a // p a } { a // p a } α := toBlock M _ _ theorem toSquareBlockProp_def (M : Matrix m m α) (p : m → Prop) : toSquareBlockProp M p = of (fun i j : { a // p a } => M ↑i ↑j) := rfl /-- Let `b` map rows and columns of a square matrix `M` to blocks. Then `toSquareBlock M b k` is the block `k` matrix. -/ def toSquareBlock (M : Matrix m m α) (b : m → β) (k : β) : Matrix { a // b a = k } { a // b a = k } α := toSquareBlockProp M _ theorem toSquareBlock_def (M : Matrix m m α) (b : m → β) (k : β) : toSquareBlock M b k = of (fun i j : { a // b a = k } => M ↑i ↑j) := rfl theorem fromBlocks_smul [SMul R α] (x : R) (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : x • fromBlocks A B C D = fromBlocks (x • A) (x • B) (x • C) (x • D) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_neg [Neg R] (A : Matrix n l R) (B : Matrix n m R) (C : Matrix o l R) (D : Matrix o m R) : -fromBlocks A B C D = fromBlocks (-A) (-B) (-C) (-D) := by ext i j cases i <;> cases j <;> simp [fromBlocks] @[simp] theorem fromBlocks_zero [Zero α] : fromBlocks (0 : Matrix n l α) 0 0 (0 : Matrix o m α) = 0 := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_add [Add α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (A' : Matrix n l α) (B' : Matrix n m α) (C' : Matrix o l α) (D' : Matrix o m α) : fromBlocks A B C D + fromBlocks A' B' C' D' = fromBlocks (A + A') (B + B') (C + C') (D + D') := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_multiply [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (A' : Matrix l p α) (B' : Matrix l q α) (C' : Matrix m p α) (D' : Matrix m q α) : fromBlocks A B C D * fromBlocks A' B' C' D' = fromBlocks (A * A' + B * C') (A * B' + B * D') (C * A' + D * C') (C * B' + D * D') := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp only [fromBlocks, mul_apply, of_apply, Sum.elim_inr, Fintype.sum_sum_type, Sum.elim_inl, add_apply] theorem fromBlocks_diagonal_pow [Semiring α] [Fintype n] [Fintype m] [DecidableEq n] [DecidableEq m] (A : Matrix n n α) (D : Matrix m m α) (k : ℕ) : (fromBlocks A 0 0 D) ^ k = fromBlocks (A ^ k) 0 0 (D ^ k) := by induction k with | zero => ext (i | i) (j | j) <;> simp [one_apply] | succ n ih => simp [ih, pow_succ, fromBlocks_multiply] theorem fromBlocks_mulVec [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (x : l ⊕ m → α) : (fromBlocks A B C D) *ᵥ x = Sum.elim (A *ᵥ (x ∘ Sum.inl) + B *ᵥ (x ∘ Sum.inr)) (C *ᵥ (x ∘ Sum.inl) + D *ᵥ (x ∘ Sum.inr)) := by ext i cases i <;> simp [mulVec, dotProduct] theorem vecMul_fromBlocks [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (x : n ⊕ o → α) : x ᵥ* fromBlocks A B C D = Sum.elim ((x ∘ Sum.inl) ᵥ* A + (x ∘ Sum.inr) ᵥ* C) ((x ∘ Sum.inl) ᵥ* B + (x ∘ Sum.inr) ᵥ* D) := by ext i cases i <;> simp [vecMul, dotProduct] variable [DecidableEq l] [DecidableEq m] section Zero variable [Zero α] theorem toBlock_diagonal_self (d : m → α) (p : m → Prop) : Matrix.toBlock (diagonal d) p p = diagonal fun i : Subtype p => d ↑i := by ext i j by_cases h : i = j · simp [h] · simp [h, Subtype.val_injective.ne h] theorem toBlock_diagonal_disjoint (d : m → α) {p q : m → Prop} (hpq : Disjoint p q) : Matrix.toBlock (diagonal d) p q = 0 := by ext ⟨i, hi⟩ ⟨j, hj⟩ have : i ≠ j := fun heq => hpq.le_bot i ⟨hi, heq.symm ▸ hj⟩ simp [diagonal_apply_ne d this] @[simp] theorem fromBlocks_diagonal (d₁ : l → α) (d₂ : m → α) : fromBlocks (diagonal d₁) 0 0 (diagonal d₂) = diagonal (Sum.elim d₁ d₂) := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [diagonal] @[simp] lemma toBlocks₁₁_diagonal (v : l ⊕ m → α) : toBlocks₁₁ (diagonal v) = diagonal (fun i => v (Sum.inl i)) := by unfold toBlocks₁₁ funext i j simp only [Sum.inl.injEq, of_apply, diagonal_apply] @[simp] lemma toBlocks₂₂_diagonal (v : l ⊕ m → α) : toBlocks₂₂ (diagonal v) = diagonal (fun i => v (Sum.inr i)) := by unfold toBlocks₂₂ funext i j simp only [Sum.inr.injEq, of_apply, diagonal_apply] @[simp] lemma toBlocks₁₂_diagonal (v : l ⊕ m → α) : toBlocks₁₂ (diagonal v) = 0 := rfl @[simp] lemma toBlocks₂₁_diagonal (v : l ⊕ m → α) : toBlocks₂₁ (diagonal v) = 0 := rfl end Zero section HasZeroHasOne variable [Zero α] [One α] @[simp] theorem fromBlocks_one : fromBlocks (1 : Matrix l l α) 0 0 (1 : Matrix m m α) = 1 := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [one_apply] @[simp] theorem toBlock_one_self (p : m → Prop) : Matrix.toBlock (1 : Matrix m m α) p p = 1 := toBlock_diagonal_self _ p theorem toBlock_one_disjoint {p q : m → Prop} (hpq : Disjoint p q) : Matrix.toBlock (1 : Matrix m m α) p q = 0 := toBlock_diagonal_disjoint _ hpq end HasZeroHasOne end BlockMatrices section BlockDiagonal variable [DecidableEq o] section Zero variable [Zero α] [Zero β] /-- `Matrix.blockDiagonal M` turns a homogeneously-indexed collection of matrices `M : o → Matrix m n α'` into an `m × o`-by-`n × o` block matrix which has the entries of `M` along the diagonal and zero elsewhere. See also `Matrix.blockDiagonal'` if the matrices may not have the same size everywhere. -/ def blockDiagonal (M : o → Matrix m n α) : Matrix (m × o) (n × o) α := of <| (fun ⟨i, k⟩ ⟨j, k'⟩ => if k = k' then M k i j else 0 : m × o → n × o → α) -- TODO: set as an equation lemma for `blockDiagonal`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiagonal_apply' (M : o → Matrix m n α) (i k j k') : blockDiagonal M ⟨i, k⟩ ⟨j, k'⟩ = if k = k' then M k i j else 0 := rfl theorem blockDiagonal_apply (M : o → Matrix m n α) (ik jk) : blockDiagonal M ik jk = if ik.2 = jk.2 then M ik.2 ik.1 jk.1 else 0 := by cases ik cases jk rfl @[simp] theorem blockDiagonal_apply_eq (M : o → Matrix m n α) (i j k) : blockDiagonal M (i, k) (j, k) = M k i j := if_pos rfl theorem blockDiagonal_apply_ne (M : o → Matrix m n α) (i j) {k k'} (h : k ≠ k') : blockDiagonal M (i, k) (j, k') = 0 := if_neg h theorem blockDiagonal_map (M : o → Matrix m n α) (f : α → β) (hf : f 0 = 0) : (blockDiagonal M).map f = blockDiagonal fun k => (M k).map f := by ext simp only [map_apply, blockDiagonal_apply] rw [apply_ite f, hf] @[simp] theorem blockDiagonal_transpose (M : o → Matrix m n α) : (blockDiagonal M)ᵀ = blockDiagonal fun k => (M k)ᵀ := by ext simp only [transpose_apply, blockDiagonal_apply, eq_comm] split_ifs with h · rw [h] · rfl @[simp] theorem blockDiagonal_conjTranspose {α : Type*} [AddMonoid α] [StarAddMonoid α] (M : o → Matrix m n α) : (blockDiagonal M)ᴴ = blockDiagonal fun k => (M k)ᴴ := by simp only [conjTranspose, blockDiagonal_transpose] rw [blockDiagonal_map _ star (star_zero α)] @[simp] theorem blockDiagonal_zero : blockDiagonal (0 : o → Matrix m n α) = 0 := by ext simp [blockDiagonal_apply] @[simp] theorem blockDiagonal_diagonal [DecidableEq m] (d : o → m → α) : (blockDiagonal fun k => diagonal (d k)) = diagonal fun ik => d ik.2 ik.1 := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal_apply, diagonal_apply, Prod.mk_inj, ← ite_and] congr 1 rw [and_comm] @[simp] theorem blockDiagonal_one [DecidableEq m] [One α] : blockDiagonal (1 : o → Matrix m m α) = 1 := show (blockDiagonal fun _ : o => diagonal fun _ : m => (1 : α)) = diagonal fun _ => 1 by rw [blockDiagonal_diagonal] end Zero @[simp] theorem blockDiagonal_add [AddZeroClass α] (M N : o → Matrix m n α) : blockDiagonal (M + N) = blockDiagonal M + blockDiagonal N := by ext simp only [blockDiagonal_apply, Pi.add_apply, add_apply] split_ifs <;> simp section variable (o m n α) /-- `Matrix.blockDiagonal` as an `AddMonoidHom`. -/ @[simps] def blockDiagonalAddMonoidHom [AddZeroClass α] : (o → Matrix m n α) →+ Matrix (m × o) (n × o) α where toFun := blockDiagonal map_zero' := blockDiagonal_zero map_add' := blockDiagonal_add end @[simp] theorem blockDiagonal_neg [AddGroup α] (M : o → Matrix m n α) : blockDiagonal (-M) = -blockDiagonal M := map_neg (blockDiagonalAddMonoidHom m n o α) M @[simp] theorem blockDiagonal_sub [AddGroup α] (M N : o → Matrix m n α) : blockDiagonal (M - N) = blockDiagonal M - blockDiagonal N := map_sub (blockDiagonalAddMonoidHom m n o α) M N @[simp] theorem blockDiagonal_mul [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring α] (M : o → Matrix m n α) (N : o → Matrix n p α) : (blockDiagonal fun k => M k * N k) = blockDiagonal M * blockDiagonal N := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal_apply, mul_apply, ← Finset.univ_product_univ, Finset.sum_product] split_ifs with h <;> simp [h] section variable (α m o) /-- `Matrix.blockDiagonal` as a `RingHom`. -/ @[simps] def blockDiagonalRingHom [DecidableEq m] [Fintype o] [Fintype m] [NonAssocSemiring α] : (o → Matrix m m α) →+* Matrix (m × o) (m × o) α := { blockDiagonalAddMonoidHom m m o α with toFun := blockDiagonal map_one' := blockDiagonal_one map_mul' := blockDiagonal_mul } end @[simp] theorem blockDiagonal_pow [DecidableEq m] [Fintype o] [Fintype m] [Semiring α] (M : o → Matrix m m α) (n : ℕ) : blockDiagonal (M ^ n) = blockDiagonal M ^ n := map_pow (blockDiagonalRingHom m o α) M n @[simp] theorem blockDiagonal_smul {R : Type*} [Zero α] [SMulZeroClass R α] (x : R) (M : o → Matrix m n α) : blockDiagonal (x • M) = x • blockDiagonal M := by ext simp only [blockDiagonal_apply, Pi.smul_apply, smul_apply] split_ifs <;> simp end BlockDiagonal section BlockDiag /-- Extract a block from the diagonal of a block diagonal matrix. This is the block form of `Matrix.diag`, and the left-inverse of `Matrix.blockDiagonal`. -/ def blockDiag (M : Matrix (m × o) (n × o) α) (k : o) : Matrix m n α := of fun i j => M (i, k) (j, k) -- TODO: set as an equation lemma for `blockDiag`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiag_apply (M : Matrix (m × o) (n × o) α) (k : o) (i j) : blockDiag M k i j = M (i, k) (j, k) := rfl theorem blockDiag_map (M : Matrix (m × o) (n × o) α) (f : α → β) : blockDiag (M.map f) = fun k => (blockDiag M k).map f := rfl @[simp] theorem blockDiag_transpose (M : Matrix (m × o) (n × o) α) (k : o) : blockDiag Mᵀ k = (blockDiag M k)ᵀ := ext fun _ _ => rfl @[simp] theorem blockDiag_conjTranspose {α : Type*} [Star α] (M : Matrix (m × o) (n × o) α) (k : o) : blockDiag Mᴴ k = (blockDiag M k)ᴴ := ext fun _ _ => rfl section Zero variable [Zero α] [Zero β] @[simp] theorem blockDiag_zero : blockDiag (0 : Matrix (m × o) (n × o) α) = 0 := rfl @[simp] theorem blockDiag_diagonal [DecidableEq o] [DecidableEq m] (d : m × o → α) (k : o) : blockDiag (diagonal d) k = diagonal fun i => d (i, k) := ext fun i j => by obtain rfl | hij := Decidable.eq_or_ne i j · rw [blockDiag_apply, diagonal_apply_eq, diagonal_apply_eq] · rw [blockDiag_apply, diagonal_apply_ne _ hij, diagonal_apply_ne _ (mt _ hij)] exact Prod.fst_eq_iff.mpr @[simp] theorem blockDiag_blockDiagonal [DecidableEq o] (M : o → Matrix m n α) : blockDiag (blockDiagonal M) = M := funext fun _ => ext fun i j => blockDiagonal_apply_eq M i j _ theorem blockDiagonal_injective [DecidableEq o] : Function.Injective (blockDiagonal : (o → Matrix m n α) → Matrix _ _ α) := Function.LeftInverse.injective blockDiag_blockDiagonal @[simp] theorem blockDiagonal_inj [DecidableEq o] {M N : o → Matrix m n α} : blockDiagonal M = blockDiagonal N ↔ M = N := blockDiagonal_injective.eq_iff @[simp] theorem blockDiag_one [DecidableEq o] [DecidableEq m] [One α] : blockDiag (1 : Matrix (m × o) (m × o) α) = 1 := funext <| blockDiag_diagonal _ end Zero @[simp] theorem blockDiag_add [Add α] (M N : Matrix (m × o) (n × o) α) : blockDiag (M + N) = blockDiag M + blockDiag N := rfl section variable (o m n α) /-- `Matrix.blockDiag` as an `AddMonoidHom`. -/ @[simps] def blockDiagAddMonoidHom [AddZeroClass α] : Matrix (m × o) (n × o) α →+ o → Matrix m n α where toFun := blockDiag map_zero' := blockDiag_zero map_add' := blockDiag_add end @[simp] theorem blockDiag_neg [AddGroup α] (M : Matrix (m × o) (n × o) α) : blockDiag (-M) = -blockDiag M := map_neg (blockDiagAddMonoidHom m n o α) M @[simp] theorem blockDiag_sub [AddGroup α] (M N : Matrix (m × o) (n × o) α) : blockDiag (M - N) = blockDiag M - blockDiag N := map_sub (blockDiagAddMonoidHom m n o α) M N @[simp] theorem blockDiag_smul {R : Type*} [SMul R α] (x : R) (M : Matrix (m × o) (n × o) α) : blockDiag (x • M) = x • blockDiag M := rfl end BlockDiag section BlockDiagonal' variable [DecidableEq o] section Zero variable [Zero α] [Zero β] /-- `Matrix.blockDiagonal' M` turns `M : Π i, Matrix (m i) (n i) α` into a `Σ i, m i`-by-`Σ i, n i` block matrix which has the entries of `M` along the diagonal and zero elsewhere. This is the dependently-typed version of `Matrix.blockDiagonal`. -/ def blockDiagonal' (M : ∀ i, Matrix (m' i) (n' i) α) : Matrix (Σ i, m' i) (Σ i, n' i) α := of <| (fun ⟨k, i⟩ ⟨k', j⟩ => if h : k = k' then M k i (cast (congr_arg n' h.symm) j) else 0 : (Σ i, m' i) → (Σ i, n' i) → α) -- TODO: set as an equation lemma for `blockDiagonal'`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiagonal'_apply' (M : ∀ i, Matrix (m' i) (n' i) α) (k i k' j) : blockDiagonal' M ⟨k, i⟩ ⟨k', j⟩ = if h : k = k' then M k i (cast (congr_arg n' h.symm) j) else 0 := rfl theorem blockDiagonal'_eq_blockDiagonal (M : o → Matrix m n α) {k k'} (i j) : blockDiagonal M (i, k) (j, k') = blockDiagonal' M ⟨k, i⟩ ⟨k', j⟩ := rfl theorem blockDiagonal'_submatrix_eq_blockDiagonal (M : o → Matrix m n α) : (blockDiagonal' M).submatrix (Prod.toSigma ∘ Prod.swap) (Prod.toSigma ∘ Prod.swap) = blockDiagonal M := Matrix.ext fun ⟨_, _⟩ ⟨_, _⟩ => rfl theorem blockDiagonal'_apply (M : ∀ i, Matrix (m' i) (n' i) α) (ik jk) : blockDiagonal' M ik jk = if h : ik.1 = jk.1 then M ik.1 ik.2 (cast (congr_arg n' h.symm) jk.2) else 0 := by cases ik cases jk rfl @[simp] theorem blockDiagonal'_apply_eq (M : ∀ i, Matrix (m' i) (n' i) α) (k i j) : blockDiagonal' M ⟨k, i⟩ ⟨k, j⟩ = M k i j := dif_pos rfl theorem blockDiagonal'_apply_ne (M : ∀ i, Matrix (m' i) (n' i) α) {k k'} (i j) (h : k ≠ k') : blockDiagonal' M ⟨k, i⟩ ⟨k', j⟩ = 0 := dif_neg h theorem blockDiagonal'_map (M : ∀ i, Matrix (m' i) (n' i) α) (f : α → β) (hf : f 0 = 0) : (blockDiagonal' M).map f = blockDiagonal' fun k => (M k).map f := by ext simp only [map_apply, blockDiagonal'_apply] rw [apply_dite f, hf] @[simp] theorem blockDiagonal'_transpose (M : ∀ i, Matrix (m' i) (n' i) α) : (blockDiagonal' M)ᵀ = blockDiagonal' fun k => (M k)ᵀ := by ext ⟨ii, ix⟩ ⟨ji, jx⟩ simp only [transpose_apply, blockDiagonal'_apply] split_ifs <;> grind @[simp] theorem blockDiagonal'_conjTranspose {α} [AddMonoid α] [StarAddMonoid α] (M : ∀ i, Matrix (m' i) (n' i) α) : (blockDiagonal' M)ᴴ = blockDiagonal' fun k => (M k)ᴴ := by simp only [conjTranspose, blockDiagonal'_transpose] exact blockDiagonal'_map _ star (star_zero α) @[simp] theorem blockDiagonal'_zero : blockDiagonal' (0 : ∀ i, Matrix (m' i) (n' i) α) = 0 := by ext simp [blockDiagonal'_apply] @[simp] theorem blockDiagonal'_diagonal [∀ i, DecidableEq (m' i)] (d : ∀ i, m' i → α) : (blockDiagonal' fun k => diagonal (d k)) = diagonal fun ik => d ik.1 ik.2 := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal'_apply, diagonal] obtain rfl | hij := Decidable.eq_or_ne i j · simp · simp [hij] @[simp] theorem blockDiagonal'_one [∀ i, DecidableEq (m' i)] [One α] : blockDiagonal' (1 : ∀ i, Matrix (m' i) (m' i) α) = 1 := show (blockDiagonal' fun i : o => diagonal fun _ : m' i => (1 : α)) = diagonal fun _ => 1 by rw [blockDiagonal'_diagonal] end Zero @[simp] theorem blockDiagonal'_add [AddZeroClass α] (M N : ∀ i, Matrix (m' i) (n' i) α) : blockDiagonal' (M + N) = blockDiagonal' M + blockDiagonal' N := by ext simp only [blockDiagonal'_apply, Pi.add_apply, add_apply] split_ifs <;> simp section variable (m' n' α) /-- `Matrix.blockDiagonal'` as an `AddMonoidHom`. -/ @[simps] def blockDiagonal'AddMonoidHom [AddZeroClass α] : (∀ i, Matrix (m' i) (n' i) α) →+ Matrix (Σ i, m' i) (Σ i, n' i) α where toFun := blockDiagonal' map_zero' := blockDiagonal'_zero map_add' := blockDiagonal'_add end @[simp] theorem blockDiagonal'_neg [AddGroup α] (M : ∀ i, Matrix (m' i) (n' i) α) : blockDiagonal' (-M) = -blockDiagonal' M := map_neg (blockDiagonal'AddMonoidHom m' n' α) M @[simp] theorem blockDiagonal'_sub [AddGroup α] (M N : ∀ i, Matrix (m' i) (n' i) α) : blockDiagonal' (M - N) = blockDiagonal' M - blockDiagonal' N := map_sub (blockDiagonal'AddMonoidHom m' n' α) M N @[simp] theorem blockDiagonal'_mul [NonUnitalNonAssocSemiring α] [∀ i, Fintype (n' i)] [Fintype o] (M : ∀ i, Matrix (m' i) (n' i) α) (N : ∀ i, Matrix (n' i) (p' i) α) : (blockDiagonal' fun k => M k * N k) = blockDiagonal' M * blockDiagonal' N := by ext ⟨k, i⟩ ⟨k', j⟩ simp only [blockDiagonal'_apply, mul_apply, ← Finset.univ_sigma_univ, Finset.sum_sigma] rw [Fintype.sum_eq_single k] · simp only [dif_pos] split_ifs <;> simp · intro j' hj' exact Finset.sum_eq_zero fun _ _ => by rw [dif_neg hj'.symm, zero_mul] section variable (α m') /-- `Matrix.blockDiagonal'` as a `RingHom`. -/ @[simps] def blockDiagonal'RingHom [∀ i, DecidableEq (m' i)] [Fintype o] [∀ i, Fintype (m' i)] [NonAssocSemiring α] : (∀ i, Matrix (m' i) (m' i) α) →+* Matrix (Σ i, m' i) (Σ i, m' i) α := { blockDiagonal'AddMonoidHom m' m' α with toFun := blockDiagonal' map_one' := blockDiagonal'_one map_mul' := blockDiagonal'_mul } end @[simp] theorem blockDiagonal'_pow [∀ i, DecidableEq (m' i)] [Fintype o] [∀ i, Fintype (m' i)] [Semiring α] (M : ∀ i, Matrix (m' i) (m' i) α) (n : ℕ) : blockDiagonal' (M ^ n) = blockDiagonal' M ^ n := map_pow (blockDiagonal'RingHom m' α) M n @[simp] theorem blockDiagonal'_smul {R : Type*} [Zero α] [SMulZeroClass R α] (x : R) (M : ∀ i, Matrix (m' i) (n' i) α) : blockDiagonal' (x • M) = x • blockDiagonal' M := by ext simp only [blockDiagonal'_apply, Pi.smul_apply, smul_apply] split_ifs <;> simp end BlockDiagonal' section BlockDiag' /-- Extract a block from the diagonal of a block diagonal matrix. This is the block form of `Matrix.diag`, and the left-inverse of `Matrix.blockDiagonal'`. -/ def blockDiag' (M : Matrix (Σ i, m' i) (Σ i, n' i) α) (k : o) : Matrix (m' k) (n' k) α := of fun i j => M ⟨k, i⟩ ⟨k, j⟩ -- TODO: set as an equation lemma for `blockDiag'`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiag'_apply (M : Matrix (Σ i, m' i) (Σ i, n' i) α) (k : o) (i j) : blockDiag' M k i j = M ⟨k, i⟩ ⟨k, j⟩ := rfl theorem blockDiag'_map (M : Matrix (Σ i, m' i) (Σ i, n' i) α) (f : α → β) : blockDiag' (M.map f) = fun k => (blockDiag' M k).map f := rfl @[simp] theorem blockDiag'_transpose (M : Matrix (Σ i, m' i) (Σ i, n' i) α) (k : o) : blockDiag' Mᵀ k = (blockDiag' M k)ᵀ := ext fun _ _ => rfl @[simp] theorem blockDiag'_conjTranspose {α : Type*} [Star α] (M : Matrix (Σ i, m' i) (Σ i, n' i) α) (k : o) : blockDiag' Mᴴ k = (blockDiag' M k)ᴴ := ext fun _ _ => rfl section Zero variable [Zero α] [Zero β] @[simp] theorem blockDiag'_zero : blockDiag' (0 : Matrix (Σ i, m' i) (Σ i, n' i) α) = 0 := rfl @[simp] theorem blockDiag'_diagonal [DecidableEq o] [∀ i, DecidableEq (m' i)] (d : (Σ i, m' i) → α) (k : o) : blockDiag' (diagonal d) k = diagonal fun i => d ⟨k, i⟩ := ext fun i j => by obtain rfl | hij := Decidable.eq_or_ne i j · rw [blockDiag'_apply, diagonal_apply_eq, diagonal_apply_eq] · rw [blockDiag'_apply, diagonal_apply_ne _ hij, diagonal_apply_ne _ (mt (fun h => ?_) hij)] cases h rfl @[simp] theorem blockDiag'_blockDiagonal' [DecidableEq o] (M : ∀ i, Matrix (m' i) (n' i) α) : blockDiag' (blockDiagonal' M) = M := funext fun _ => ext fun _ _ => blockDiagonal'_apply_eq M _ _ _ theorem blockDiagonal'_injective [DecidableEq o] : Function.Injective (blockDiagonal' : (∀ i, Matrix (m' i) (n' i) α) → Matrix _ _ α) := Function.LeftInverse.injective blockDiag'_blockDiagonal' @[simp] theorem blockDiagonal'_inj [DecidableEq o] {M N : ∀ i, Matrix (m' i) (n' i) α} : blockDiagonal' M = blockDiagonal' N ↔ M = N := blockDiagonal'_injective.eq_iff @[simp] theorem blockDiag'_one [DecidableEq o] [∀ i, DecidableEq (m' i)] [One α] : blockDiag' (1 : Matrix (Σ i, m' i) (Σ i, m' i) α) = 1 := funext <| blockDiag'_diagonal _ end Zero @[simp] theorem blockDiag'_add [Add α] (M N : Matrix (Σ i, m' i) (Σ i, n' i) α) : blockDiag' (M + N) = blockDiag' M + blockDiag' N := rfl section variable (m' n' α) /-- `Matrix.blockDiag'` as an `AddMonoidHom`. -/ @[simps] def blockDiag'AddMonoidHom [AddZeroClass α] : Matrix (Σ i, m' i) (Σ i, n' i) α →+ ∀ i, Matrix (m' i) (n' i) α where toFun := blockDiag' map_zero' := blockDiag'_zero map_add' := blockDiag'_add end @[simp] theorem blockDiag'_neg [AddGroup α] (M : Matrix (Σ i, m' i) (Σ i, n' i) α) : blockDiag' (-M) = -blockDiag' M := map_neg (blockDiag'AddMonoidHom m' n' α) M @[simp] theorem blockDiag'_sub [AddGroup α] (M N : Matrix (Σ i, m' i) (Σ i, n' i) α) : blockDiag' (M - N) = blockDiag' M - blockDiag' N := map_sub (blockDiag'AddMonoidHom m' n' α) M N @[simp] theorem blockDiag'_smul {R : Type*} [SMul R α] (x : R) (M : Matrix (Σ i, m' i) (Σ i, n' i) α) : blockDiag' (x • M) = x • blockDiag' M := rfl end BlockDiag' section variable [CommRing R] theorem toBlock_mul_eq_mul {m n k : Type*} [Fintype n] (p : m → Prop) (q : k → Prop) (A : Matrix m n R) (B : Matrix n k R) : (A * B).toBlock p q = A.toBlock p ⊤ * B.toBlock ⊤ q := by ext i k simp only [toBlock_apply, mul_apply] rw [Finset.sum_subtype] simp [Pi.top_apply, Prop.top_eq_true] theorem toBlock_mul_eq_add {m n k : Type*} [Fintype n] (p : m → Prop) (q : n → Prop) [DecidablePred q] (r : k → Prop) (A : Matrix m n R) (B : Matrix n k R) : (A * B).toBlock p r = A.toBlock p q * B.toBlock q r + (A.toBlock p fun i => ¬q i) * B.toBlock (fun i => ¬q i) r := by classical ext i k simp only [toBlock_apply, mul_apply] exact (Fintype.sum_subtype_add_sum_subtype q fun x => A (↑i) x * B x ↑k).symm end end Matrix section Maps variable {R α β ι : Type*} lemma Matrix.map_toSquareBlock (f : α → β) {M : Matrix m m α} {ι} {b : m → ι} {i : ι} : (M.map f).toSquareBlock b i = (M.toSquareBlock b i).map f := submatrix_map _ _ _ _ lemma Matrix.comp_toSquareBlock {b : m → α} (M : Matrix m m (Matrix n n R)) (a : α) : letI equiv := Equiv.prodSubtypeFstEquivSubtypeProd.symm (M.comp m m n n R).toSquareBlock (fun i ↦ b i.1) a = ((M.toSquareBlock b a).comp _ _ n n R).reindex equiv equiv := rfl variable [Zero R] [DecidableEq m] lemma Matrix.comp_diagonal (d) : comp m m n n R (diagonal d) = (blockDiagonal d).reindex (.prodComm ..) (.prodComm ..) := by ext simp [diagonal, blockDiagonal, Matrix.ite_apply] end Maps
finset_builder.lean
import Mathlib.Order.Interval.Finset.Basic /-! # Examples of finset builder notation -/ open Finset variable {α : Type*} (p : α → Prop) [DecidablePred p] /-! ## `Data.Finset.Basic` -/ example (s : Finset α) : {x ∈ s | p x} = s.filter p := rfl /-! ## `Data.Fintype.Basic` -/ section Fintype variable [Fintype α] example : ({x | p x} : Finset α) = univ.filter p := rfl example : ({x : α | p x} : Finset α) = univ.filter p := rfl -- If the type of `s` (or the entire expression) is `Finset ?α`, elaborate as `Finset`; -- otherwise as `Set` example (s : Finset α) : {x ∈ s | p x} = s.filter p := rfl example (s : Finset α) : ({x ∈ s | p x} : Set α) = setOf fun x => x ∈ s ∧ p x := rfl example (s : Finset α) : {x ∈ (s : Set α) | p x} = setOf fun x => x ∈ s ∧ p x := rfl -- elaborate as `Set` if no expected type present example : {x | p x} = setOf p := rfl example : {x : α | p x} = setOf p := rfl variable [DecidableEq α] example (s : Finset α) : {x ∉ s | p x} = sᶜ.filter p := rfl example (a : α) : ({x ≠ a | p x} : Finset α) = ({a}ᶜ : Finset α).filter p := rfl -- elaborate as `Set` if the `s` or the expected type is not `Finset ?α` example (s : Set α) : {x ∉ s | p x} = setOf fun x => x ∉ s ∧ p x := rfl example (a : α) : {x ≠ a | p x} = setOf fun x => x ≠ a ∧ p x := rfl end Fintype /-! ## `Order.Interval.Finset.Basic` -/ section LocallyFiniteOrderBot variable [Preorder α] [LocallyFiniteOrderBot α] example (a : α) : ({x ≤ a | p x} : Finset α) = (Iic a).filter p := rfl example (a : α) : ({x < a | p x} : Finset α) = (Iio a).filter p := rfl -- elaborate as `Set` if the expected type is not `Finset ?α` example (a : α) : {x ≤ a | p x} = setOf fun x => x ≤ a ∧ p x := rfl example (a : α) : {x < a | p x} = setOf fun x => x < a ∧ p x := rfl end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [Preorder α] [LocallyFiniteOrderTop α] example (a : α) : ({x ≥ a | p x} : Finset α) = (Ici a).filter p := rfl example (a : α) : ({x > a | p x} : Finset α) = (Ioi a).filter p := rfl -- elaborate as `Set` if the expected type is not `Finset ?α` example (a : α) : {x ≥ a | p x} = setOf fun x => x ≥ a ∧ p x := rfl example (a : α) : {x > a | p x} = setOf fun x => x > a ∧ p x := rfl end LocallyFiniteOrderTop
Sinc.lean
/- Copyright (c) 2025 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Sinc import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic import Mathlib.MeasureTheory.Function.L1Space.Integrable /-! # Measurability and integrability of the sinc function ## Main statements * `measurable_sinc`: the sinc function is measurable. * `integrable_sinc`: the sinc function is integrable with respect to any finite measure on `ℝ`. -/ open MeasureTheory variable {α : Type*} {_ : MeasurableSpace α} {f : α → ℝ} {μ : Measure α} namespace Real @[fun_prop, measurability] lemma measurable_sinc : Measurable sinc := continuous_sinc.measurable @[fun_prop, measurability] lemma stronglyMeasurable_sinc : StronglyMeasurable sinc := measurable_sinc.stronglyMeasurable @[fun_prop] lemma integrable_sinc {μ : Measure ℝ} [IsFiniteMeasure μ] : Integrable sinc μ := by refine Integrable.mono' (g := fun _ ↦ 1) (by fun_prop) (by fun_prop) <| ae_of_all _ fun x ↦ ?_ rw [Real.norm_eq_abs] exact abs_sinc_le_one x end Real open Real @[fun_prop, measurability] protected theorem Measurable.sinc (hf : Measurable f) : Measurable fun x ↦ sinc (f x) := Real.measurable_sinc.comp hf @[fun_prop, measurability] protected theorem AEMeasurable.sinc (hf : AEMeasurable f μ) : AEMeasurable (fun x ↦ sinc (f x)) μ := Real.measurable_sinc.comp_aemeasurable hf @[fun_prop, measurability] protected theorem MeasureTheory.StronglyMeasurable.sinc (hf : StronglyMeasurable f) : StronglyMeasurable fun x ↦ sinc (f x) := Real.stronglyMeasurable_sinc.comp_measurable hf.measurable @[fun_prop, measurability] protected theorem MeasureTheory.AEStronglyMeasurable.sinc (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x ↦ sinc (f x)) μ := by rw [aestronglyMeasurable_iff_aemeasurable] at hf ⊢ exact hf.sinc
ssralg.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div seq. From mathcomp Require Import choice fintype finfun bigop prime binomial. From mathcomp Require Export nmodule. (******************************************************************************) (* Ring-like structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* Reference: Francois Garillot, Georges Gonthier, Assia Mahboubi, Laurence *) (* Rideau, Packaging mathematical structures, TPHOLs 2009 *) (* *) (* This file defines the following algebraic structures: *) (* *) (* semiPzRingType == non-commutative semi rings *) (* (NModule with a multiplication) *) (* The HB class is called PzSemiRing. *) (* nzSemiRingType == non-commutative non-trivial semi rings *) (* (NModule with a multiplication) *) (* The HB class is called NzSemiRing. *) (* comPzSemiRingType == commutative semi rings *) (* The HB class is called ComPzSemiRing. *) (* comNzSemiRingType == commutative non-trivial semi rings *) (* The HB class is called ComNzSemiRing. *) (* pzRingType == non-commutative rings *) (* (semi rings with an opposite) *) (* The HB class is called PzRing. *) (* nzRingType == non-commutative non-trivial rings *) (* (semi rings with an opposite) *) (* The HB class is called NzRing. *) (* comPzRingType == commutative rings *) (* The HB class is called ComPzRing. *) (* comNzRingType == commutative non-trivial rings *) (* The HB class is called ComNzRing. *) (* lSemiModType R == semimodule with left multiplication by external scalars *) (* in the semiring R *) (* The HB class is called LSemiModule. *) (* lmodType R == module with left multiplication by external scalars *) (* in the pzRing R *) (* The HB class is called Lmodule. *) (* lSemiAlgType R == left semialgebra, semiring with scaling that associates *) (* on the left *) (* The HB class is called LSemiAlgebra. *) (* lalgType R == left algebra, ring with scaling that associates on the *) (* left *) (* The HB class is called Lalgebra. *) (* semiAlgType R == semialgebra, semiring with scaling that associates both *) (* left and right *) (* The HB class is called SemiAlgebra. *) (* algType R == algebra, ring with scaling that associates both left *) (* and right *) (* The HB class is called Algebra. *) (*comSemiAlgType R == commutative semiAlgType *) (* The HB class is called ComSemiAlgebra. *) (* comAlgType R == commutative algType *) (* The HB class is called ComAlgebra. *) (* unitRingType == Rings whose units have computable inverses *) (* The HB class is called UnitRing. *) (* comUnitRingType == commutative UnitRing *) (* The HB class is called ComUnitRing. *) (* unitAlgType R == algebra with computable inverses *) (* The HB class is called UnitAlgebra. *) (*comUnitAlgType R == commutative UnitAlgebra *) (* The HB class is called ComUnitAlgebra. *) (* idomainType == integral, commutative, ring with partial inverses *) (* The HB class is called IntegralDomain. *) (* fieldType == commutative fields *) (* The HB class is called Field. *) (* decFieldType == fields with a decidable first order theory *) (* The HB class is called DecidableField. *) (* closedFieldType == algebraically closed fields *) (* The HB class is called ClosedField. *) (* *) (* and their joins with subType: *) (* *) (* subPzSemiRingType R P == join of pzSemiRingType and *) (* subType (P : pred R) such that val is a *) (* semiring morphism *) (* The HB class is called SubPzSemiRing. *) (* subNzSemiRingType R P == join of nzSemiRingType and *) (* subType (P : pred R) such that val is a *) (* semiring morphism *) (* The HB class is called SubNzSemiRing. *) (*subComPzSemiRingType R P == join of comPzSemiRingType and *) (* subType (P : pred R) such that val is a morphism*) (* The HB class is called SubComPzSemiRing. *) (*subComNzSemiRingType R P == join of comNzSemiRingType and *) (* subType (P : pred R) such that val is a morphism*) (* The HB class is called SubComNzSemiRing. *) (* subPzRingType R P == join of pzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubPzRing. *) (* subComPzRingType R P == join of comPzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubComPzRing. *) (* subNzRingType R P == join of nzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubNzRing. *) (* subComNzRingType R P == join of comNzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubComNzRing. *) (* subLSemiModType R V P == join of lSemiModType and subType (P : pred V) *) (* such that val is scalable *) (* The HB class is called SubLSemiModule. *) (* subLmodType R V P == join of lmodType and subType (P : pred V) *) (* such that val is scalable *) (* The HB class is called SubLmodule. *) (* subLSemiAlgType R V P == join of lSemiAlgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubLSemiAlgebra. *) (* subLalgType R V P == join of lalgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubLalgebra. *) (* subSemiAlgType R V P == join of semiAlgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubSemiAlgebra. *) (* subAlgType R V P == join of algType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubAlgebra. *) (* subUnitRingType R P == join of unitRingType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubUnitRing. *) (* subComUnitRingType R P == join of comUnitRingType and subType (P : pred R)*) (* such that val is a ring morphism *) (* The HB class is called SubComUnitRing. *) (* subIdomainType R P == join of idomainType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubIntegralDomain. *) (* subField R P == join of fieldType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubField. *) (* *) (* Morphisms between the above structures (see below for details): *) (* *) (* {rmorphism R -> S} == semi ring (resp. ring) morphism between *) (* semiPzRingType (resp. pzRingType) instances *) (* R and S. *) (* The HB class is called RMorphism. *) (* {linear U -> V | s} == semilinear (resp. linear) functions of type *) (* U -> V, where U is a left semimodule (resp. *) (* left module) over semiring (resp. ring) R, V is *) (* an N-module (resp. Z-module), and s is a scaling*) (* operator (detailed below) of type R -> V -> V. *) (* The HB class is called Linear. *) (* {lrmorphism A -> B | s} == semialgebra (resp. algebra) morphisms of type *) (* A -> B, where A is a left semialgebra *) (* (resp. left algebra) over semiring (resp. ring) *) (* R, B is an semiring (resp. ring), and s is a *) (* scaling operator (detailed below) of type *) (* R -> B -> B. *) (* The HB class is called LRMorphism. *) (* *) (* -> The scaling operator s above should be one of *:%R, *%R, or a *) (* combination nu \; *:%R or nu \; *%R with a semiring morphism nu; *) (* otherwise some of the theory (e.g., the linearZ rule) will not apply. *) (* To enable the overloading of the scaling operator, we use the following *) (* structures: *) (* *) (* GRing.Scale.preLaw R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.PreLaw. *) (* GRing.Scale.semiLaw R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.SemiLaw. *) (* GRing.Scale.law R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.Law. *) (* *) (* Closedness predicates for the algebraic structures: *) (* *) (* addrClosed V == predicate closed under addition on V : nmodType *) (* The HB class is called AddClosed. *) (* opprClosed V == predicate closed under opposite on V : zmodType *) (* The HB class is called OppClosed. *) (* zmodClosed V == predicate closed under opposite and addition on V *) (* The HB class is called ZmodClosed. *) (* mulr2Closed R == predicate closed under multiplication on *) (* R : semiPzRingType *) (* The HB class is called Mul2Closed. *) (* mulrClosed R == predicate closed under multiplication and for 1 *) (* The HB class is called MulClosed. *) (* semiring2Closed R == predicate closed under addition and multiplication *) (* The HB class is called Semiring2Closed. *) (* semiringClosed R == predicate closed under semiring operations *) (* The HB class is called SemiringClosed. *) (* smulClosed R == predicate closed under multiplication and for -1 *) (* The HB class is called SmulClosed. *) (* subringClosed R == predicate closed under ring operations *) (* The HB class is called SubringClosed. *) (* divClosed R == predicate closed under division *) (* The HB class is called DivClosed. *) (* sdivClosed R == predicate closed under division and opposite *) (* The HB class is called SdivClosed. *) (* submodClosed R == predicate closed under lSemiModType operations *) (* The HB class is called SubmodClosed. *) (* subalgClosed R == predicate closed under lSemiAlgType operations *) (* The HB class is called SubalgClosed. *) (* divringClosed R == predicate closed under unitRing operations *) (* The HB class is called DivringClosed. *) (* divalgClosed R S == predicate closed under (S : unitAlg R) operations *) (* The HB class is called DivalgClosed. *) (* *) (* The rpred* lemmas ensure that the set S remains stable under the specified *) (* operations, provided the corresponding closedness predicate is satisfied. *) (* This stability is crucial for constructing and reasoning about *) (* substructures within algebraic hierarchies. For example: *) (* *) (* - rpred0: Concludes 0 \in S if S is addrClosed. *) (* - rpredD: Concludes x + y \in S if x \in S and y \in S and S is addrClosed.*) (* - rpredN: Concludes -x \in S if x \in S and S is opprClosed. *) (* - rpredZ: Concludes a *: v \in S if v \in S and S is scalerClosed. *) (* *) (* Canonical properties of the algebraic structures: *) (* * Nmodule (additive abelian monoids): *) (* 0 == the zero (additive identity) of a Nmodule *) (* x + y == the sum of x and y (in a Nmodule) *) (* x *+ n == n times x, with n in nat (non-negative), i.e., *) (* x + (x + .. (x + x)..) (n terms); x *+ 1 is thus *) (* convertible to x, and x *+ 2 to x + x *) (* \sum_<range> e == iterated sum for a Nmodule (cf bigop.v) *) (* e`_i == nth 0 e i, when e : seq M and M has a nmodType *) (* structure *) (* support f == 0.-support f, i.e., [pred x | f x != 0] *) (* addr_closed S <-> collective predicate S is closed under finite *) (* sums (0 and x + y in S, for x, y in S) *) (* [SubChoice_isSubNmodule of U by <:] == nmodType mixin for a subType whose *) (* base type is a nmodType and whose predicate's is *) (* an addrClosed *) (* *) (* * Zmodule (additive abelian groups): *) (* - x == the opposite (additive inverse) of x *) (* x - y == the difference of x and y; this is only notation *) (* for x + (- y) *) (* x *- n == notation for - (x *+ n), the opposite of x *+ n *) (* oppr_closed S <-> collective predicate S is closed under opposite *) (* zmod_closed S <-> collective predicate S is closed under zmodType *) (* operations (0 and x - y in S, for x, y in S) *) (* This property coerces to oppr_pred and addr_pred. *) (* [SubChoice_isSubZmodule of U by <:] == zmodType mixin for a subType whose *) (* base type is a zmodType and whose predicate's *) (* is a zmodClosed *) (* *) (* * PzSemiRing (non-commutative semirings): *) (* R^c == the converse (semi)ring for R: R^c is convertible*) (* to R but when R has a canonical (semi)ring *) (* structure R^c has the converse one: *) (* if x y : R^c, then x * y = (y : R) * (x : R) *) (* 1 == the multiplicative identity element of a semiring*) (* n%:R == the semiring image of an n in nat; this is just *) (* notation for 1 *+ n, so 1%:R is convertible to 1 *) (* and 2%:R to 1 + 1 *) (* <number> == <number>%:R with <number> a sequence of digits *) (* x * y == the semiring product of x and y *) (* \prod_<range> e == iterated product for a semiring (cf bigop.v) *) (* x ^+ n == x to the nth power with n in nat (non-negative), *) (* i.e., x * (x * .. (x * x)..) (n factors); x ^+ 1 *) (* is thus convertible to x, and x ^+ 2 to x * x *) (* GRing.comm x y <-> x and y commute, i.e., x * y = y * x *) (* GRing.lreg x <-> x if left-regular, i.e., *%R x is injective *) (* GRing.rreg x <-> x if right-regular, i.e., *%R^~ x is injective *) (* [pchar R] == the characteristic of R, defined as the set of *) (* prime numbers p such that p%:R = 0 in R *) (* The set [pchar R] has at most one element, and is*) (* implemented as a pred_nat collective predicate *) (* (see prime.v); thus the statement p \in [pchar R]*) (* can be read as `R has characteristic p', while *) (* [pchar R] =i pred0 means `R has characteristic 0'*) (* when R is a field. *) (* pFrobenius_aut chRp == the Frobenius automorphism mapping x in R to *) (* x ^+ p, where chRp : p \in [pchar R] is a proof *) (* that R has (non-zero) characteristic p *) (* mulr_closed S <-> collective predicate S is closed under finite *) (* products (1 and x * y in S for x, y in S) *) (* semiring_closed S <-> collective predicate S is closed under semiring *) (* operations (0, 1, x + y and x * y in S) *) (* [SubNmodule_isSubPzSemiRing of R by <:] == *) (* [SubChoice_isSubPzSemiRing of R by <:] == semiPzRingType mixin for a *) (* subType whose base type is a pzSemiRingType and *) (* whose predicate's is a semiringClosed *) (* *) (* * NzSemiRing (non-commutative non-trivial semirings): *) (* [SubNmodule_isSubNzSemiRing of R by <:] == *) (* [SubChoice_isSubNzSemiRing of R by <:] == semiNzRingType mixin for a *) (* subType whose base type is a nzSemiRingType and *) (* whose predicate's is a semiringClosed *) (* *) (* * PzRing (non-commutative rings): *) (* GRing.sign R b := (-1) ^+ b in R : pzRingType, with b : bool *) (* This is a parsing-only helper notation, to be *) (* used for defining more specific instances. *) (* smulr_closed S <-> collective predicate S is closed under products *) (* and opposite (-1 and x * y in S for x, y in S) *) (* subring_closed S <-> collective predicate S is closed under ring *) (* operations (1, x - y and x * y in S) *) (* [SubZmodule_isSubPzRing of R by <:] == *) (* [SubChoice_isSubPzRing of R by <:] == pzRingType mixin for a subType whose *) (* base *) (* type is a pzRingType and whose predicate's is a *) (* subringClosed *) (* *) (* * NzRing (non-commutative non-trivial rings): *) (* [SubZmodule_isSubNzRing of R by <:] == *) (* [SubChoice_isSubNzRing of R by <:] == nzRingType mixin for a subType whose *) (* base *) (* type is a nzRingType and whose predicate's is a *) (* subringClosed *) (* *) (* * ComPzSemiRing (commutative PzSemiRings): *) (* [SubNmodule_isSubComPzSemiRing of R by <:] == *) (* [SubChoice_isSubComPzSemiRing of R by <:] == comPzSemiRingType mixin for a *) (* subType whose base type is a comPzSemiRingType *) (* and whose predicate's is a semiringClosed *) (* *) (* * ComNzSemiRing (commutative NzSemiRings): *) (* [SubNmodule_isSubComNzSemiRing of R by <:] == *) (* [SubChoice_isSubComNzSemiRing of R by <:] == comNzSemiRingType mixin for a *) (* subType whose base type is a comNzSemiRingType *) (* and whose predicate's is a semiringClosed *) (* *) (* * ComPzRing (commutative PzRings): *) (* [SubZmodule_isSubComPzRing of R by <:] == *) (* [SubChoice_isSubComPzRing of R by <:] == comPzRingType mixin for a *) (* subType whose base type is a comPzRingType and *) (* whose predicate's is a subringClosed *) (* *) (* * ComNzRing (commutative NzRings): *) (* [SubZmodule_isSubComNzRing of R by <:] == *) (* [SubChoice_isSubComNzRing of R by <:] == comNzRingType mixin for a *) (* subType whose base type is a comNzRingType and *) (* whose predicate's is a subringClosed *) (* *) (* * UnitRing (NzRings whose units have computable inverses): *) (* x \is a GRing.unit <=> x is a unit (i.e., has an inverse) *) (* x^-1 == the ring inverse of x, if x is a unit, else x *) (* x / y == x divided by y (notation for x * y^-1) *) (* x ^- n := notation for (x ^+ n)^-1, the inverse of x ^+ n *) (* invr_closed S <-> collective predicate S is closed under inverse *) (* divr_closed S <-> collective predicate S is closed under division *) (* (1 and x / y in S) *) (* sdivr_closed S <-> collective predicate S is closed under division *) (* and opposite (-1 and x / y in S, for x, y in S) *) (* divring_closed S <-> collective predicate S is closed under unitRing *) (* operations (1, x - y and x / y in S) *) (* [SubNzRing_isSubUnitRing of R by <:] == *) (* [SubChoice_isSubUnitRing of R by <:] == unitRingType mixin for a subType *) (* whose base type is a unitRingType and whose *) (* predicate's is a divringClosed and whose ring *) (* structure is compatible with the base type's *) (* *) (* * ComUnitRing (commutative rings with computable inverses): *) (* [SubChoice_isSubComUnitRing of R by <:] == comUnitRingType mixin for a *) (* subType whose base type is a comUnitRingType and *) (* whose predicate's is a divringClosed and whose *) (* ring structure is compatible with the base *) (* type's *) (* *) (* * IntegralDomain (integral, commutative, ring with partial inverses): *) (* [SubComUnitRing_isSubIntegralDomain R by <:] == *) (* [SubChoice_isSubIntegralDomain R by <:] == mixin axiom for a idomain *) (* subType *) (* *) (* * Field (commutative fields): *) (* GRing.Field.axiom inv == field axiom: x != 0 -> inv x * x = 1 for all x *) (* This is equivalent to the property above, but *) (* does not require a unitRingType as inv is an *) (* explicit argument. *) (* [SubIntegralDomain_isSubField of R by <:] == mixin axiom for a field *) (* subType *) (* *) (* * DecidableField (fields with a decidable first order theory): *) (* GRing.term R == the type of formal expressions in a unit ring R *) (* with formal variables 'X_k, k : nat, and *) (* manifest constants x%:T, x : R *) (* The notation of all the ring operations is *) (* redefined for terms, in scope %T. *) (* GRing.formula R == the type of first order formulas over R; the %T *) (* scope binds the logical connectives /\, \/, ~, *) (* ==>, ==, and != to formulae; GRing.True/False *) (* and GRing.Bool b denote constant formulae, and *) (* quantifiers are written 'forall/'exists 'X_k, f *) (* GRing.Unit x tests for ring units *) (* GRing.If p_f t_f e_f emulates if-then-else *) (* GRing.Pick p_f t_f e_f emulates fintype.pick *) (* foldr GRing.Exists/Forall q_f xs can be used *) (* to write iterated quantifiers *) (* GRing.eval e t == the value of term t with valuation e : seq R *) (* (e maps 'X_i to e`_i) *) (* GRing.same_env e1 e2 <-> environments e1 and e2 are extensionally equal *) (* GRing.qf_form f == f is quantifier-free *) (* GRing.holds e f == the intuitionistic CiC interpretation of the *) (* formula f holds with valuation e *) (* GRing.qf_eval e f == the value (in bool) of a quantifier-free f *) (* GRing.sat e f == valuation e satisfies f (only in a decField) *) (* GRing.sol n f == a sequence e of size n such that e satisfies f, *) (* if one exists, or [::] if there is no such e *) (* 'exists 'X_i, u1 == 0 /\ ... /\ u_m == 0 /\ v1 != 0 ... /\ v_n != 0 *) (* *) (* * LSemiModule (semimodule with left multiplication by external scalars). *) (* a *: v == v scaled by a, when v is in an LSemiModule V and *) (* a is in the scalar semiring of V *) (* scaler_closed S <-> collective predicate S is closed under scaling *) (* subsemimod_closed S <-> collective predicate S is closed under *) (* lSemiModType operations (0, +%R, and *:%R) *) (* [SubNmodule_isSubLSemiModule of V by <:] == *) (* [SubChoice_isSubLSemiModule of V by <:] == mixin axiom for a subType of an *) (* lSemiModType *) (* *) (* * Lmodule (module with left multiplication by external scalars). *) (* linear_closed S <-> collective predicate S is closed under linear *) (* combinations (a *: u + v in S when u, v in S) *) (* submod_closed S <-> collective predicate S is closed under lmodType *) (* operations (0 and a *: u + v in S) *) (* [SubZmodule_isSubLmodule of V by <:] == *) (* [SubChoice_isSubLmodule of V by <:] == mixin axiom for a subType of an *) (* lmodType *) (* *) (* * LSemiAlgebra *) (* (left semialgebra, semiring with scaling that associates on the left): *) (* R^o == the regular (semi)algebra of R: R^o is *) (* convertible to R, but when R has a *) (* nz(Semi)RingType structure then R^o extends it *) (* to an l(Semi)AlgType structure by letting R act *) (* on itself: if x : R and y : R^o then *) (* x *: y = x * (y : R) *) (* k%:A == the image of the scalar k in a left semialgebra; *) (* this is simply notation for k *: 1 *) (* [SubSemiRing_SubLSemiModule_isSubLSemiAlgebra of V by <:] *) (* == mixin axiom for a subType of an lSemiAlgType *) (* *) (* * Lalgebra (left algebra, ring with scaling that associates on the left): *) (* subalg_closed S <-> collective predicate S is closed under lalgType *) (* operations (1, a *: u + v and u * v in S) *) (* [SubNzRing_SubLmodule_isSubLalgebra of V by <:] == *) (* [SubChoice_isSubLalgebra of V by <:] == mixin axiom for a subType of an *) (* lalgType *) (* *) (* * SemiAlgebra (semiring with scaling that associates both left and right):*) (* [SubLSemiAlgebra_isSubSemiAlgebra of V by <:] == *) (* == mixin axiom for a subType of an semiAlgType *) (* *) (* * Algebra (ring with scaling that associates both left and right): *) (* [SubLalgebra_isSubAlgebra of V by <:] == *) (* [SubChoice_isSubAlgebra of V by <:] == mixin axiom for a subType of an *) (* algType *) (* *) (* * UnitAlgebra (algebra with computable inverses): *) (* divalg_closed S <-> collective predicate S is closed under all *) (* unitAlgType operations (1, a *: u + v and u / v *) (* are in S fo u, v in S) *) (* *) (* In addition to this structure hierarchy, we also develop a separate, *) (* parallel hierarchy for morphisms linking these structures: *) (* *) (* * RMorphism (semiring or ring morphisms): *) (* monoid_morphism f <-> f of type R -> S is a multiplicative monoid *) (* morphism, i.e., f maps 1 and * in R to 1 and * *) (* in S, respectively. R and S must have canonical *) (* pzSemiRingType instances. *) (* {rmorphism R -> S} == the interface type for semiring morphisms; both *) (* R and S must have pzSemiRingType instances *) (* When both R and S have pzRingType instances, it *) (* is a ring morphism. *) (* := GRing.RMorphism.type R S *) (* *) (* -> If R and S are UnitRings the f also maps units to units and inverses *) (* of units to inverses; if R is a field then f is a field isomorphism *) (* between R and its image. *) (* -> Additive properties (raddf_suffix, see below) are duplicated and *) (* specialised for RMorphism (as rmorph_suffix). This allows more *) (* precise rewriting and cleaner chaining: although raddf lemmas will *) (* recognize RMorphism functions, the converse will not hold (we cannot *) (* add reverse inheritance rules because of incomplete backtracking in *) (* the Canonical Projection unification), so one would have to insert a *) (* /= every time one switched from additive to multiplicative rules. *) (* *) (* * Linear (semilinear or linear functions): *) (* scalable_for s f <-> f of type U -> V is scalable for the scaling *) (* operator s of type R -> V -> V, i.e., *) (* f morphs a *: _ to s a _; R, U, and V must be a *) (* pzSemiRingType, an lSemiModType R, and an *) (* nmodType, respectively. *) (* := forall a, {morph f : u / a *: u >-> s a u} *) (* scalable f <-> f of type U -> V is scalable, i.e., f morphs *) (* scaling on U to scaling on V, a *: _ to a *: _; *) (* U and V must be lSemiModType R for the same *) (* pzSemiRingType R. *) (* := scalable_for *:%R f *) (* semilinear_for s f <-> f of type U -> V is semilinear for s of type *) (* R -> V -> V , i.e., f morphs a *: _ and addition *) (* on U to s a _ and addition on V, respectively; *) (* R, U, and V must be a pzSemiRingType, an *) (* lSemiModType R and an nmodType, respectively. *) (* := scalable_for s f * {morph f : x y / x + y} *) (* semilinear f <-> f of type U -> V is semilinear, i.e., f morphs *) (* scaling and addition on U to scaling and *) (* addition on V, respectively; U and V must be *) (* lSemiModType R for the same pzSemiRingType R. *) (* := semilinear_for *:% f *) (* semiscalar f <-> f of type U -> R is a semiscalar function, *) (* i.e., f morphs scaling and addition on U to *) (* multiplication and addition on R; R and U must *) (* be a pzSemiRingType and an lSemiModType R, *) (* respectively. *) (* := semilinear_for *%R f *) (* linear_for s f <-> f of type U -> V is linear for s of type *) (* R -> V -> V, i.e., *) (* f (a *: u + v) = s a (f u) + f v; *) (* R, U, and V must be a pzRingType, an lmodType R, *) (* and a zmodType, respectively. *) (* linear f <-> f of type U -> V is linear, i.e., *) (* f (f *: u + v) = a *: f u + f v; *) (* U and V must be lmodType R for the same *) (* pzRingType R. *) (* := linear_for *:%R f *) (* scalar f <-> f of type U -> R is a scalar function, i.e., *) (* f (a *: u + v) = a * f u + f v; *) (* R and U must be a pzRingType and an lmodType R, *) (* respectively. *) (* := linear_for *%R f *) (* {linear U -> V | s} == the interface type for functions (semi)linear *) (* for the scaling operator s of type R -> V -> V, *) (* i.e., a structure that encapsulates two *) (* properties semi_additive f and scalable_for s f *) (* for functions f : U -> V; R, U, and V must be a *) (* pzSemiRingType, an lSemiModType R, and an *) (* nmodType, respectively. *) (* {linear U -> V} == the interface type for (semi)linear functions, *) (* of type U -> V where both U and V must be *) (* lSemiModType R for the same pzSemiRingType R *) (* := {linear U -> V | *:%R} *) (* {scalar U} == the interface type for (semi)scalar functions, *) (* of type U -> R where U must be an lSemiModType R *) (* := {linear U -> R | *%R} *) (* (a *: u)%Rlin == transient forms that simplify to a *: u, a * u, *) (* (a * u)%Rlin nu a *: u, and nu a * u, respectively, and are *) (* (a *:^nu u)%Rlin created by rewriting with the linearZ lemma *) (* (a *^nu u)%Rlin The forms allows the RHS of linearZ to be matched*) (* reliably, using the GRing.Scale.law structure. *) (* -> Similarly to semiring morphisms, semiadditive properties are *) (* specialized for semilinear functions. *) (* -> Although {scalar U} is convertible to {linear U -> R^o}, it does not *) (* actually use R^o, so that rewriting preserves the canonical structure *) (* of the range of scalar functions. *) (* -> The generic linearZ lemma uses a set of bespoke interface structures to *) (* ensure that both left-to-right and right-to-left rewriting work even in *) (* the presence of scaling functions that simplify non-trivially (e.g., *) (* idfun \; *%R). Because most of the canonical instances and projections *) (* are coercions the machinery will be mostly invisible (with only the *) (* {linear ...} structure and %Rlin notations showing), but users should *) (* beware that in (a *: f u)%Rlin, a actually occurs in the f u subterm. *) (* -> The simpler linear_LR, or more specialized linearZZ and scalarZ rules *) (* should be used instead of linearZ if there are complexity issues, as *) (* well as for explicit forward and backward application, as the main *) (* parameter of linearZ is a proper sub-interface of {linear U -> V | s}. *) (* *) (* * LRMorphism (semialgebra or algebra morphisms): *) (* {lrmorphism A -> B | s} == the interface type for semiring (resp. ring) *) (* morphisms semilinear (resp. linear) for the *) (* scaling operator s of type R -> B -> B, i.e., *) (* the join of semiring (resp. ring) morphisms *) (* {rmorphism A -> B} and semilinear (resp. linear) *) (* functions {linear A -> B | s}; R, A, and B must *) (* be a pzSemiRingType (resp. pzRingType), an *) (* lSemiAlgType R (resp. lalgType R), and a *) (* pzSemiRingType (resp. pzRingType), respectively *) (* {lrmorphism A -> B} == the interface type for semialgebra (resp. *) (* algebra) morphisms, where A and B must be *) (* lSemiAlgType R (resp. lalgType R) for the same *) (* pzSemiRingType (resp. pzRingType) R *) (* := {lrmorphism A -> B | *:%R} *) (* -> Linear and rmorphism properties do not need to be specialized for *) (* as we supply inheritance join instances in both directions. *) (* Finally we supply some helper notation for morphisms: *) (* x^f == the image of x under some morphism *) (* This notation is only reserved (not defined) *) (* here; it is bound locally in sections where some *) (* morphism is used heavily (e.g., the container *) (* morphism in the parametricity sections of poly *) (* and matrix, or the Frobenius section here) *) (* \0 == the constant null function, which has a *) (* canonical linear structure, and simplifies on *) (* application (see ssrfun.v) *) (* f \+ g == the additive composition of f and g, i.e., the *) (* function x |-> f x + g x; f \+ g is canonically *) (* linear when f and g are, and simplifies on *) (* application (see ssrfun.v) *) (* f \- g == the function x |-> f x - g x, canonically *) (* linear when f and g are, and simplifies on *) (* application *) (* \- g == the function x |-> - f x, canonically linear *) (* when f is, and simplifies on application *) (* k \*: f == the function x |-> k *: f x, which is *) (* canonically linear when f is and simplifies on *) (* application (this is a shorter alternative to *) (* *:%R k \o f) *) (* GRing.in_alg A == the ring morphism that injects R into A, where A *) (* has an lalgType R structure; GRing.in_alg A k *) (* simplifies to k%:A *) (* a \*o f == the function x |-> a * f x, canonically linear *) (* when f is and its codomain is an algType *) (* and which simplifies on application *) (* a \o* f == the function x |-> f x * a, canonically linear *) (* when f is and its codomain is an lalgType *) (* and which simplifies on application *) (* f \* g == the function x |-> f x * g x; f \* g *) (* simplifies on application *) (* The Lemmas about these structures are contained in both the GRing module *) (* and in the submodule GRing.Theory, which can be imported when unqualified *) (* access to the theory is needed (GRing.Theory also allows the unqualified *) (* use of additive, linear, Linear, etc). The main GRing module should NOT be *) (* imported. *) (* Notations are defined in scope ring_scope (delimiter %R), except term *) (* and formula notations, which are in term_scope (delimiter %T). *) (* This library also extends the conventional suffixes described in library *) (* ssrbool.v with the following: *) (* 0 -- ring 0, as in addr0 : x + 0 = x *) (* 1 -- ring 1, as in mulr1 : x * 1 = x *) (* D -- ring addition, as in linearD : f (u + v) = f u + f v *) (* B -- ring subtraction, as in opprB : - (x - y) = y - x *) (* M -- ring multiplication, as in invfM : (x * y)^-1 = x^-1 * y^-1 *) (* Mn -- ring by nat multiplication, as in raddfMn : f (x *+ n) = f x *+ n *) (* N -- ring opposite, as in mulNr : (- x) * y = - (x * y) *) (* V -- ring inverse, as in mulVr : x^-1 * x = 1 *) (* X -- ring exponentiation, as in rmorphXn : f (x ^+ n) = f x ^+ n *) (* Z -- (left) module scaling, as in linearZ : f (a *: v) = s *: f v *) (* The operator suffixes D, B, M and X are also used for the corresponding *) (* operations on nat, as in natrX : (m ^ n)%:R = m%:R ^+ n. For the binary *) (* power operator, a trailing "n" suffix is used to indicate the operator *) (* suffix applies to the left-hand ring argument, as in *) (* expr1n : 1 ^+ n = 1 vs. expr1 : x ^+ 1 = x. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope ring_scope. Declare Scope term_scope. Declare Scope linear_ring_scope. Reserved Notation "+%R". Reserved Notation "-%R". Reserved Notation "*%R" (format " *%R"). Reserved Notation "*:%R" (format " *:%R"). Reserved Notation "n %:R" (left associativity, format "n %:R"). Reserved Notation "k %:A" (left associativity, format "k %:A"). Reserved Notation "[ 'pchar' F ]" (format "[ 'pchar' F ]"). Reserved Notation "[ 'char' F ]" (format "[ 'char' F ]"). Reserved Notation "x %:T" (left associativity, format "x %:T"). Reserved Notation "''X_' i" (at level 8, i at level 2, format "''X_' i"). (* Patch for recurring Coq parser bug: Coq seg faults when a level 200 *) (* notation is used as a pattern. *) Reserved Notation "''exists' ''X_' i , f" (at level 199, i at level 2, right associativity, format "'[hv' ''exists' ''X_' i , '/ ' f ']'"). Reserved Notation "''forall' ''X_' i , f" (at level 199, i at level 2, right associativity, format "'[hv' ''forall' ''X_' i , '/ ' f ']'"). Reserved Notation "x ^f" (left associativity, format "x ^f"). Reserved Notation "\0". Reserved Notation "f \+ g" (at level 50, left associativity). Reserved Notation "f \- g" (at level 50, left associativity). Reserved Notation "\- f" (at level 35, f at level 35). Reserved Notation "a \*o f" (at level 40). Reserved Notation "a \o* f" (at level 40). Reserved Notation "a \*: f" (at level 40). Reserved Notation "f \* g" (at level 40, left associativity). Reserved Notation "'{' 'additive' U '->' V '}'" (U at level 98, V at level 99, format "{ 'additive' U -> V }"). Reserved Notation "'{' 'rmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'rmorphism' U -> V }"). Reserved Notation "'{' 'lrmorphism' U '->' V '|' s '}'" (U at level 98, V at level 99, format "{ 'lrmorphism' U -> V | s }"). Reserved Notation "'{' 'lrmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'lrmorphism' U -> V }"). Reserved Notation "'{' 'linear' U '->' V '|' s '}'" (U at level 98, V at level 99, format "{ 'linear' U -> V | s }"). Reserved Notation "'{' 'linear' U '->' V '}'" (U at level 98, V at level 99, format "{ 'linear' U -> V }"). Reserved Notation "'{' 'scalar' U '}'" (format "{ 'scalar' U }"). Reserved Notation "R ^c" (format "R ^c"). Reserved Notation "R ^o" (format "R ^o"). Declare Scope ring_scope. Delimit Scope ring_scope with R. Declare Scope term_scope. Delimit Scope term_scope with T. Local Open Scope ring_scope. Module Export Dummy. Module GRing := Algebra. End Dummy. Module Import GRing. Export Algebra. Import Monoid.Theory. Local Notation "0" := (@zero _) : ring_scope. Local Notation "+%R" := (@add _) : function_scope. Local Notation "x + y" := (add x y) : ring_scope. Local Notation "x *+ n" := (natmul x n) : ring_scope. Local Notation "\sum_ ( i <- r | P ) F" := (\big[+%R/0]_(i <- r | P) F). Local Notation "\sum_ ( m <= i < n ) F" := (\big[+%R/0]_(m <= i < n) F). Local Notation "\sum_ ( i < n ) F" := (\big[+%R/0]_(i < n) F). Local Notation "\sum_ ( i 'in' A ) F" := (\big[+%R/0]_(i in A) F). Local Notation "s `_ i" := (nth 0 s i) : ring_scope. Section NmoduleTheory. Variable V : nmodType. Implicit Types x y : V. Lemma addrA : associative (@add V). Proof. exact: addrA. Qed. Lemma addrC : commutative (@add V). Proof. exact: addrC. Qed. Lemma add0r : left_id (@zero V) add. Proof. exact: add0r. Qed. Lemma addr0 : right_id (@zero V) add. Proof. exact: addr0. Qed. Lemma addrCA : @left_commutative V V +%R. Proof. exact: addrCA. Qed. Lemma addrAC : @right_commutative V V +%R. Proof. exact: addrAC. Qed. Lemma addrACA : @interchange V +%R +%R. Proof. exact: addrACA. Qed. Lemma mulr0n x : x *+ 0 = 0. Proof. exact: mulr0n. Qed. Lemma mulr1n x : x *+ 1 = x. Proof. exact: mulr1n. Qed. Lemma mulr2n x : x *+ 2 = x + x. Proof. exact: mulr2n. Qed. Lemma mulrS x n : x *+ n.+1 = x + (x *+ n). Proof. exact: mulrS. Qed. Lemma mulrSr x n : x *+ n.+1 = x *+ n + x. Proof. exact: mulrSr. Qed. Lemma mulrb x (b : bool) : x *+ b = (if b then x else 0). Proof. exact: mulrb. Qed. Lemma mul0rn n : 0 *+ n = 0 :> V. Proof. exact: mul0rn. Qed. Lemma mulrnDl n : {morph (fun x => x *+ n) : x y / x + y}. Proof. exact: mulrnDl. Qed. Lemma mulrnDr x m n : x *+ (m + n) = x *+ m + x *+ n. Proof. exact: mulrnDr. Qed. Lemma mulrnA x m n : x *+ (m * n) = x *+ m *+ n. Proof. exact: mulrnA. Qed. Lemma mulrnAC x m n : x *+ m *+ n = x *+ n *+ m. Proof. exact: mulrnAC. Qed. Lemma iter_addr n x y : iter n (+%R x) y = x *+ n + y. Proof. exact: iter_addr. Qed. Lemma iter_addr_0 n x : iter n (+%R x) 0 = x *+ n. Proof. exact: iter_addr_0. Qed. Lemma sumrMnl I r P (F : I -> V) n : \sum_(i <- r | P i) F i *+ n = (\sum_(i <- r | P i) F i) *+ n. Proof. exact: sumrMnl. Qed. Lemma sumrMnr x I r P (F : I -> nat) : \sum_(i <- r | P i) x *+ F i = x *+ (\sum_(i <- r | P i) F i). Proof. exact: sumrMnr. Qed. Lemma sumr_const (I : finType) (A : pred I) x : \sum_(i in A) x = x *+ #|A|. Proof. exact: sumr_const. Qed. Lemma sumr_const_nat m n x : \sum_(n <= i < m) x = x *+ (m - n). Proof. exact: sumr_const_nat. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use Algebra.nmod_closed instead.")] Definition addr_closed := nmod_closed. End NmoduleTheory. Local Notation "-%R" := (@opp _) : ring_scope. Local Notation "- x" := (opp x) : ring_scope. Local Notation "x - y" := (x + - y) : ring_scope. Local Notation "x *- n" := (- (x *+ n)) : ring_scope. Section ZmoduleTheory. Variable V : zmodType. Implicit Types x y : V. Lemma addNr : @left_inverse V V V 0 -%R +%R. Proof. exact: addNr. Qed. Lemma addrN : @right_inverse V V V 0 -%R +%R. Proof. exact: addrN. Qed. Definition subrr := addrN. Lemma addKr : @left_loop V V -%R +%R. Proof. exact: addKr. Qed. Lemma addNKr : @rev_left_loop V V -%R +%R. Proof. exact: addNKr. Qed. Lemma addrK : @right_loop V V -%R +%R. Proof. exact: addrK. Qed. Lemma addrNK : @rev_right_loop V V -%R +%R. Proof. exact: addrNK. Qed. Definition subrK := addrNK. Lemma subrKC x y : x + (y - x) = y. Proof. by rewrite addrC subrK. Qed. Lemma subKr x : involutive (fun y => x - y). Proof. exact: subKr. Qed. Lemma addrI : @right_injective V V V +%R. Proof. exact: addrI. Qed. Lemma addIr : @left_injective V V V +%R. Proof. exact: addIr. Qed. Lemma subrI : right_injective (fun x y => x - y). Proof. exact: subrI. Qed. Lemma subIr : left_injective (fun x y => x - y). Proof. exact: subIr. Qed. Lemma opprK : @involutive V -%R. Proof. exact: opprK. Qed. Lemma oppr_inj : @injective V V -%R. Proof. exact: oppr_inj. Qed. Lemma oppr0 : -0 = 0 :> V. Proof. exact: oppr0. Qed. Lemma oppr_eq0 x : (- x == 0) = (x == 0). Proof. exact: oppr_eq0. Qed. Lemma subr0 x : x - 0 = x. Proof. exact: subr0. Qed. Lemma sub0r x : 0 - x = - x. Proof. exact: sub0r. Qed. Lemma opprB x y : - (x - y) = y - x. Proof. exact: opprB. Qed. Lemma opprD : {morph -%R: x y / x + y : V}. Proof. exact: opprD. Qed. Lemma addrKA z x y : (x + z) - (z + y) = x - y. Proof. exact: addrKA. Qed. Lemma subrKA z x y : (x - z) + (z + y) = x + y. Proof. exact: subrKA. Qed. Lemma addr0_eq x y : x + y = 0 -> - x = y. Proof. exact: addr0_eq. Qed. Lemma subr0_eq x y : x - y = 0 -> x = y. Proof. exact: subr0_eq. Qed. Lemma subr_eq x y z : (x - z == y) = (x == y + z). Proof. exact: subr_eq. Qed. Lemma subr_eq0 x y : (x - y == 0) = (x == y). Proof. exact: subr_eq0. Qed. Lemma addr_eq0 x y : (x + y == 0) = (x == - y). Proof. exact: addr_eq0. Qed. Lemma eqr_opp x y : (- x == - y) = (x == y). Proof. exact: eqr_opp. Qed. Lemma eqr_oppLR x y : (- x == y) = (x == - y). Proof. exact: eqr_oppLR. Qed. Lemma mulNrn x n : (- x) *+ n = x *- n. Proof. exact: mulNrn. Qed. Lemma mulrnBl n : {morph (fun x => x *+ n) : x y / x - y}. Proof. exact: mulrnBl. Qed. Lemma mulrnBr x m n : n <= m -> x *+ (m - n) = x *+ m - x *+ n. Proof. exact: mulrnBr. Qed. Lemma sumrN I r P (F : I -> V) : (\sum_(i <- r | P i) - F i = - (\sum_(i <- r | P i) F i)). Proof. exact: sumrN. Qed. Lemma sumrB I r (P : pred I) (F1 F2 : I -> V) : \sum_(i <- r | P i) (F1 i - F2 i) = \sum_(i <- r | P i) F1 i - \sum_(i <- r | P i) F2 i. Proof. exact: sumrB. Qed. Lemma telescope_sumr n m (f : nat -> V) : n <= m -> \sum_(n <= k < m) (f k.+1 - f k) = f m - f n. Proof. exact: telescope_sumr. Qed. Lemma telescope_sumr_eq n m (f u : nat -> V) : n <= m -> (forall k, (n <= k < m)%N -> u k = f k.+1 - f k) -> \sum_(n <= k < m) u k = f m - f n. Proof. exact: telescope_sumr_eq. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition oppr_closed := oppr_closed S. Definition subr_2closed := subr_closed S. Definition zmod_closed := zmod_closed S. Lemma zmod_closedN : zmod_closed -> oppr_closed. Proof. exact: zmod_closedN. Qed. Lemma zmod_closedD : zmod_closed -> nmod_closed S. Proof. by move=> z; split; [case: z|apply/zmod_closedD]. Qed. End ClosedPredicates. End ZmoduleTheory. Arguments addrI {V} y [x1 x2]. Arguments addIr {V} x [x1 x2]. Arguments opprK {V}. Arguments oppr_inj {V} [x1 x2]. Arguments telescope_sumr_eq {V n m} f u. HB.mixin Record Nmodule_isPzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; }. #[short(type="pzSemiRingType")] HB.structure Definition PzSemiRing := { R of Nmodule_isPzSemiRing R & Nmodule R }. HB.factory Record isPzSemiRing R of Choice R := { zero : R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; }. HB.builders Context R of isPzSemiRing R. HB.instance Definition _ := @isNmodule.Build R zero add addrA addrC add0r. HB.instance Definition _ := @Nmodule_isPzSemiRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.end. Module PzSemiRingExports. Bind Scope ring_scope with PzSemiRing.sort. End PzSemiRingExports. HB.export PzSemiRingExports. HB.mixin Record PzSemiRing_isNonZero R of PzSemiRing R := { oner_neq0 : @one R != 0 }. #[short(type="nzSemiRingType")] HB.structure Definition NzSemiRing := { R of PzSemiRing_isNonZero R & PzSemiRing R }. #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing instead.")] Notation SemiRing R := (NzSemiRing R) (only parsing). Module SemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.sort instead.")] Notation sort := (NzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.on instead.")] Notation on R := (NzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.copy instead.")] Notation copy T U := (NzSemiRing.copy T U) (only parsing). End SemiRing. HB.factory Record Nmodule_isNzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; oner_neq0 : one != 0 }. HB.builders Context R of Nmodule_isNzSemiRing R. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0. HB.end. Module Nmodule_isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isNzSemiRing.Build instead.")] Notation Build R := (Nmodule_isNzSemiRing.Build R) (only parsing). End Nmodule_isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isNzSemiRing instead.")] Notation Nmodule_isSemiRing R := (Nmodule_isNzSemiRing R) (only parsing). HB.factory Record isNzSemiRing R of Choice R := { zero : R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; oner_neq0 : one != zero }. Module isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzSemiRing.Build instead.")] Notation Build R := (isNzSemiRing.Build R) (only parsing). End isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzSemiRing instead.")] Notation isSemiRing R := (isNzSemiRing R) (only parsing). HB.builders Context R of isNzSemiRing R. HB.instance Definition _ := @isNmodule.Build R zero add addrA addrC add0r. HB.instance Definition _ := @Nmodule_isNzSemiRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0. HB.end. Module NzSemiRingExports. Bind Scope ring_scope with NzSemiRing.sort. End NzSemiRingExports. HB.export NzSemiRingExports. Definition exp R x n := iterop n (@mul R) x (@one R). Arguments exp : simpl never. Definition comm R x y := @mul R x y = mul y x. Definition lreg R x := injective (@mul R x). Definition rreg R x := injective ((@mul R)^~ x). Local Notation "1" := (@one _) : ring_scope. Local Notation "n %:R" := (1 *+ n) : ring_scope. Local Notation "*%R" := (@mul _) : function_scope. Local Notation "x * y" := (mul x y) : ring_scope. Local Notation "x ^+ n" := (exp x n) : ring_scope. Local Notation "\prod_ ( i <- r | P ) F" := (\big[*%R/1]_(i <- r | P) F). Local Notation "\prod_ ( i | P ) F" := (\big[*%R/1]_(i | P) F). Local Notation "\prod_ ( i 'in' A ) F" := (\big[*%R/1]_(i in A) F). Local Notation "\prod_ ( m <= i < n ) F" := (\big[*%R/1%R]_(m <= i < n) F%R). (* The ``field'' characteristic; the definition, and many of the theorems, *) (* has to apply to rings as well; indeed, we need the Frobenius automorphism *) (* results for a non commutative ring in the proof of Gorenstein 2.6.3. *) Definition pchar (R : nzSemiRingType) : nat_pred := [pred p | prime p & p%:R == 0 :> R]. #[deprecated(since="mathcomp 2.4.0", note="Use pchar instead.")] Notation char := pchar (only parsing). Local Notation has_pchar0 L := (pchar L =i pred0). #[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")] Notation has_char0 L := (has_pchar0 L) (only parsing). (* Converse ring tag. *) Definition converse R : Type := R. Local Notation "R ^c" := (converse R) : type_scope. Section PzSemiRingTheory. Variable R : pzSemiRingType. Implicit Types x y : R. #[export] HB.instance Definition _ := Monoid.isLaw.Build R 1 *%R mulrA mul1r mulr1. #[export] HB.instance Definition _ := Monoid.isMulLaw.Build R 0 *%R mul0r mulr0. #[export] HB.instance Definition _ := Monoid.isAddLaw.Build R *%R +%R mulrDl mulrDr. Lemma mulr_suml I r P (F : I -> R) x : (\sum_(i <- r | P i) F i) * x = \sum_(i <- r | P i) F i * x. Proof. exact: big_distrl. Qed. Lemma mulr_sumr I r P (F : I -> R) x : x * (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) x * F i. Proof. exact: big_distrr. Qed. Lemma mulrnAl x y n : (x *+ n) * y = (x * y) *+ n. Proof. by elim: n => [|n IHn]; rewrite ?mul0r // !mulrS mulrDl IHn. Qed. Lemma mulrnAr x y n : x * (y *+ n) = (x * y) *+ n. Proof. by elim: n => [|n IHn]; rewrite ?mulr0 // !mulrS mulrDr IHn. Qed. Lemma mulr_natl x n : n%:R * x = x *+ n. Proof. by rewrite mulrnAl mul1r. Qed. Lemma mulr_natr x n : x * n%:R = x *+ n. Proof. by rewrite mulrnAr mulr1. Qed. Lemma natrD m n : (m + n)%:R = m%:R + n%:R :> R. Proof. exact: mulrnDr. Qed. Lemma natr1 n : n%:R + 1 = n.+1%:R :> R. Proof. by rewrite mulrSr. Qed. Lemma nat1r n : 1 + n%:R = n.+1%:R :> R. Proof. by rewrite mulrS. Qed. Definition natr_sum := big_morph (natmul 1) natrD (mulr0n 1). Lemma natrM m n : (m * n)%:R = m%:R * n%:R :> R. Proof. by rewrite mulrnA mulr_natr. Qed. Lemma expr0 x : x ^+ 0 = 1. Proof. by []. Qed. Lemma expr1 x : x ^+ 1 = x. Proof. by []. Qed. Lemma expr2 x : x ^+ 2 = x * x. Proof. by []. Qed. Lemma exprS x n : x ^+ n.+1 = x * x ^+ n. Proof. by case: n => //; rewrite mulr1. Qed. Lemma expr0n n : 0 ^+ n = (n == 0%N)%:R :> R. Proof. by case: n => // n; rewrite exprS mul0r. Qed. Lemma expr1n n : 1 ^+ n = 1 :> R. Proof. by elim: n => // n IHn; rewrite exprS mul1r. Qed. Lemma exprD x m n : x ^+ (m + n) = x ^+ m * x ^+ n. Proof. by elim: m => [|m IHm]; rewrite ?mul1r // !exprS -mulrA -IHm. Qed. Lemma exprSr x n : x ^+ n.+1 = x ^+ n * x. Proof. by rewrite -addn1 exprD expr1. Qed. Lemma expr_sum x (I : Type) (s : seq I) (P : pred I) F : x ^+ (\sum_(i <- s | P i) F i) = \prod_(i <- s | P i) x ^+ F i :> R. Proof. exact: (big_morph _ (exprD _)). Qed. Lemma commr_sym x y : comm x y -> comm y x. Proof. by []. Qed. Lemma commr_refl x : comm x x. Proof. by []. Qed. Lemma commr0 x : comm x 0. Proof. by rewrite /comm mulr0 mul0r. Qed. Lemma commr1 x : comm x 1. Proof. by rewrite /comm mulr1 mul1r. Qed. Lemma commrD x y z : comm x y -> comm x z -> comm x (y + z). Proof. by rewrite /comm mulrDl mulrDr => -> ->. Qed. Lemma commr_sum (I : Type) (s : seq I) (P : pred I) (F : I -> R) x : (forall i, P i -> comm x (F i)) -> comm x (\sum_(i <- s | P i) F i). Proof. move=> comm_x_F; rewrite /comm mulr_suml mulr_sumr. by apply: eq_bigr => i /comm_x_F. Qed. Lemma commrMn x y n : comm x y -> comm x (y *+ n). Proof. rewrite /comm => com_xy. by elim: n => [|n IHn]; rewrite ?commr0 // mulrS commrD. Qed. Lemma commrM x y z : comm x y -> comm x z -> comm x (y * z). Proof. by move=> com_xy; rewrite /comm mulrA com_xy -!mulrA => ->. Qed. Lemma commr_prod (I : Type) (s : seq I) (P : pred I) (F : I -> R) x : (forall i, P i -> comm x (F i)) -> comm x (\prod_(i <- s | P i) F i). Proof. exact: (big_ind _ (commr1 x) (@commrM x)). Qed. Lemma commr_nat x n : comm x n%:R. Proof. exact/commrMn/commr1. Qed. Lemma commrX x y n : comm x y -> comm x (y ^+ n). Proof. rewrite /comm => com_xy. by elim: n => [|n IHn]; rewrite ?commr1 // exprS commrM. Qed. Lemma exprMn_comm x y n : comm x y -> (x * y) ^+ n = x ^+ n * y ^+ n. Proof. move=> com_xy; elim: n => /= [|n IHn]; first by rewrite mulr1. by rewrite !exprS IHn !mulrA; congr (_ * _); rewrite -!mulrA -commrX. Qed. Lemma exprMn_n x m n : (x *+ m) ^+ n = x ^+ n *+ (m ^ n) :> R. Proof. elim: n => [|n IHn]; first by rewrite mulr1n. by rewrite exprS IHn mulrnAl mulrnAr -mulrnA exprS -expnSr. Qed. Lemma exprM x m n : x ^+ (m * n) = x ^+ m ^+ n. Proof. elim: m => [|m IHm]; first by rewrite expr1n. by rewrite mulSn exprD IHm exprS exprMn_comm //; apply: commrX. Qed. Lemma exprAC x m n : (x ^+ m) ^+ n = (x ^+ n) ^+ m. Proof. by rewrite -!exprM mulnC. Qed. Lemma expr_mod n x i : x ^+ n = 1 -> x ^+ (i %% n) = x ^+ i. Proof. move=> xn1; rewrite {2}(divn_eq i n) exprD mulnC exprM xn1. by rewrite expr1n mul1r. Qed. Lemma expr_dvd n x i : x ^+ n = 1 -> n %| i -> x ^+ i = 1. Proof. by move=> xn1 dvd_n_i; rewrite -(expr_mod i xn1) (eqnP dvd_n_i). Qed. Lemma natrX n k : (n ^ k)%:R = n%:R ^+ k :> R. Proof. by rewrite exprMn_n expr1n. Qed. Lemma mulrI_eq0 x y : lreg x -> (x * y == 0) = (y == 0). Proof. by move=> reg_x; rewrite -{1}(mulr0 x) (inj_eq reg_x). Qed. Lemma lreg1 : lreg (1 : R). Proof. by move=> x y; rewrite !mul1r. Qed. Lemma lregM x y : lreg x -> lreg y -> lreg (x * y). Proof. by move=> reg_x reg_y z t; rewrite -!mulrA => /reg_x/reg_y. Qed. Lemma lregMl (a b: R) : lreg (a * b) -> lreg b. Proof. by move=> rab c c' eq_bc; apply/rab; rewrite -!mulrA eq_bc. Qed. Lemma rregMr (a b: R) : rreg (a * b) -> rreg a. Proof. by move=> rab c c' eq_ca; apply/rab; rewrite !mulrA eq_ca. Qed. Lemma lregX x n : lreg x -> lreg (x ^+ n). Proof. by move=> reg_x; elim: n => [|n]; [apply: lreg1 | rewrite exprS; apply: lregM]. Qed. Lemma iter_mulr n x y : iter n ( *%R x) y = x ^+ n * y. Proof. by elim: n => [|n ih]; rewrite ?expr0 ?mul1r //= ih exprS -mulrA. Qed. Lemma iter_mulr_1 n x : iter n ( *%R x) 1 = x ^+ n. Proof. by rewrite iter_mulr mulr1. Qed. Lemma prodr_const (I : finType) (A : pred I) x : \prod_(i in A) x = x ^+ #|A|. Proof. by rewrite big_const -iteropE. Qed. Lemma prodr_const_nat n m x : \prod_(n <= i < m) x = x ^+ (m - n). Proof. by rewrite big_const_nat -iteropE. Qed. Lemma prodrXr x I r P (F : I -> nat) : \prod_(i <- r | P i) x ^+ F i = x ^+ (\sum_(i <- r | P i) F i). Proof. by rewrite (big_morph _ (exprD _) (erefl _)). Qed. Lemma prodrM_comm {I : eqType} r (P : pred I) (F G : I -> R) : (forall i j, P i -> P j -> comm (F i) (G j)) -> \prod_(i <- r | P i) (F i * G i) = \prod_(i <- r | P i) F i * \prod_(i <- r | P i) G i. Proof. move=> FG; elim: r => [|i r IHr]; rewrite !(big_nil, big_cons) ?mulr1//. case: ifPn => // Pi; rewrite IHr !mulrA; congr (_ * _); rewrite -!mulrA. by rewrite commr_prod // => j Pj; apply/commr_sym/FG. Qed. Lemma prodrMl_comm {I : finType} (A : pred I) (x : R) F : (forall i, A i -> comm x (F i)) -> \prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i. Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j _ /xF. Qed. Lemma prodrMr_comm {I : finType} (A : pred I) (x : R) F : (forall i, A i -> comm x (F i)) -> \prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|. Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j /xF. Qed. Lemma prodrMn (I : Type) (s : seq I) (P : pred I) (F : I -> R) (g : I -> nat) : \prod_(i <- s | P i) (F i *+ g i) = \prod_(i <- s | P i) (F i) *+ \prod_(i <- s | P i) g i. Proof. by elim/big_rec3: _ => // i y1 y2 y3 _ ->; rewrite mulrnAr mulrnAl -mulrnA. Qed. Lemma prodrMn_const n (I : finType) (A : pred I) (F : I -> R) : \prod_(i in A) (F i *+ n) = \prod_(i in A) F i *+ n ^ #|A|. Proof. by rewrite prodrMn prod_nat_const. Qed. Lemma natr_prod I r P (F : I -> nat) : (\prod_(i <- r | P i) F i)%:R = \prod_(i <- r | P i) (F i)%:R :> R. Proof. exact: (big_morph _ natrM). Qed. Lemma exprDn_comm x y n (cxy : comm x y) : (x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. elim: n => [|n IHn]; rewrite big_ord_recl mulr1 ?big_ord0 ?addr0 //=. rewrite exprS {}IHn /= mulrDl !big_distrr /= big_ord_recl mulr1 subn0. rewrite !big_ord_recr /= !binn !subnn !mul1r !subn0 bin0 !exprS -addrA. congr (_ + _); rewrite addrA -big_split /=; congr (_ + _). apply: eq_bigr => i _; rewrite !mulrnAr !mulrA -exprS -subSn ?(valP i) //. by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS -mulrnDr. Qed. Lemma exprD1n x n : (x + 1) ^+ n = \sum_(i < n.+1) x ^+ i *+ 'C(n, i). Proof. rewrite addrC (exprDn_comm n (commr_sym (commr1 x))). by apply: eq_bigr => i _; rewrite expr1n mul1r. Qed. Lemma sqrrD1 x : (x + 1) ^+ 2 = x ^+ 2 + x *+ 2 + 1. Proof. rewrite exprD1n !big_ord_recr big_ord0 /= add0r. by rewrite addrC addrA addrAC. Qed. Section ClosedPredicates. Variable S : {pred R}. Definition mulr_2closed := {in S &, forall u v, u * v \in S}. Definition mulr_closed := 1 \in S /\ mulr_2closed. Definition semiring_closed := nmod_closed S /\ mulr_closed. Lemma semiring_closedD : semiring_closed -> nmod_closed S. Proof. by case. Qed. Lemma semiring_closedM : semiring_closed -> mulr_closed. Proof. by case. Qed. End ClosedPredicates. End PzSemiRingTheory. Section NzSemiRingTheory. Variable R : nzSemiRingType. Implicit Types x y : R. Lemma oner_eq0 : (1 == 0 :> R) = false. Proof. exact: negbTE oner_neq0. Qed. Lemma lastr_eq0 (s : seq R) x : x != 0 -> (last x s == 0) = (last 1 s == 0). Proof. by case: s => [|y s] /negPf // ->; rewrite oner_eq0. Qed. Lemma lreg_neq0 x : lreg x -> x != 0. Proof. by move=> reg_x; rewrite -[x]mulr1 mulrI_eq0 ?oner_eq0. Qed. Definition pFrobenius_aut p of p \in pchar R := fun x => x ^+ p. (* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible definition. *) Section FrobeniusAutomorphism. Variable p : nat. Hypothesis pcharFp : p \in pchar R. Lemma pcharf0 : p%:R = 0 :> R. Proof. by apply/eqP; case/andP: pcharFp. Qed. Lemma pcharf_prime : prime p. Proof. by case/andP: pcharFp. Qed. Hint Resolve pcharf_prime : core. Lemma mulrn_pchar x : x *+ p = 0. Proof. by rewrite -mulr_natl pcharf0 mul0r. Qed. Lemma natr_mod_pchar n : (n %% p)%:R = n%:R :> R. Proof. by rewrite {2}(divn_eq n p) natrD mulrnA mulrn_pchar add0r. Qed. Lemma dvdn_pcharf n : (p %| n)%N = (n%:R == 0 :> R). Proof. apply/idP/eqP=> [/dvdnP[n' ->]|n0]; first by rewrite natrM pcharf0 mulr0. apply/idPn; rewrite -prime_coprime // => /eqnP pn1. have [a _ /dvdnP[b]] := Bezoutl n (prime_gt0 pcharf_prime). move/(congr1 (fun m => m%:R : R))/eqP. by rewrite natrD !natrM pcharf0 n0 !mulr0 pn1 addr0 oner_eq0. Qed. Lemma pcharf_eq : pchar R =i (p : nat_pred). Proof. move=> q; apply/andP/eqP=> [[q_pr q0] | ->]; last by rewrite pcharf0. by apply/eqP; rewrite eq_sym -dvdn_prime2 // dvdn_pcharf. Qed. Lemma bin_lt_pcharf_0 k : 0 < k < p -> 'C(p, k)%:R = 0 :> R. Proof. by move=> lt0kp; apply/eqP; rewrite -dvdn_pcharf prime_dvd_bin. Qed. Local Notation "x ^f" := (pFrobenius_aut pcharFp x). Lemma pFrobenius_autE x : x^f = x ^+ p. Proof. by []. Qed. Local Notation f'E := pFrobenius_autE. Lemma pFrobenius_aut0 : 0^f = 0. Proof. by rewrite f'E -(prednK (prime_gt0 pcharf_prime)) exprS mul0r. Qed. Lemma pFrobenius_aut1 : 1^f = 1. Proof. by rewrite f'E expr1n. Qed. Lemma pFrobenius_autD_comm x y (cxy : comm x y) : (x + y)^f = x^f + y^f. Proof. have defp := prednK (prime_gt0 pcharf_prime). rewrite !f'E exprDn_comm // big_ord_recr subnn -defp big_ord_recl /= defp. rewrite subn0 mulr1 mul1r bin0 binn big1 ?addr0 // => i _. by rewrite -mulr_natl bin_lt_pcharf_0 ?mul0r //= -{2}defp ltnS (valP i). Qed. Lemma pFrobenius_autMn x n : (x *+ n)^f = x^f *+ n. Proof. elim: n => [|n IHn]; first exact: pFrobenius_aut0. by rewrite !mulrS pFrobenius_autD_comm ?IHn //; apply: commrMn. Qed. Lemma pFrobenius_aut_nat n : (n%:R)^f = n%:R. Proof. by rewrite pFrobenius_autMn pFrobenius_aut1. Qed. Lemma pFrobenius_autM_comm x y : comm x y -> (x * y)^f = x^f * y^f. Proof. exact: exprMn_comm. Qed. Lemma pFrobenius_autX x n : (x ^+ n)^f = x^f ^+ n. Proof. by rewrite !f'E -!exprM mulnC. Qed. End FrobeniusAutomorphism. Section Char2. Hypothesis pcharR2 : 2 \in pchar R. Lemma addrr_pchar2 x : x + x = 0. Proof. by rewrite -mulr2n mulrn_pchar. Qed. End Char2. End NzSemiRingTheory. #[short(type="pzRingType")] HB.structure Definition PzRing := { R of PzSemiRing R & Zmodule R }. HB.factory Record Zmodule_isPzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; }. HB.builders Context R of Zmodule_isPzRing R. Local Notation "1" := one. Local Notation "x * y" := (mul x y). Lemma mul0r : @left_zero R R 0 mul. Proof. by move=> x; apply: (addIr (1 * x)); rewrite -mulrDl !add0r mul1r. Qed. Lemma mulr0 : @right_zero R R 0 mul. Proof. by move=> x; apply: (addIr (x * 1)); rewrite -mulrDr !add0r mulr1. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.end. HB.factory Record isPzRing R of Choice R := { zero : R; opp : R -> R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; addNr : left_inverse zero opp add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; }. HB.builders Context R of isPzRing R. HB.instance Definition _ := @isZmodule.Build R zero opp add addrA addrC add0r addNr. HB.instance Definition _ := @Zmodule_isPzRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr. HB.end. Module PzRingExports. Bind Scope ring_scope with PzRing.sort. End PzRingExports. HB.export PzRingExports. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")] Notation Frobenius_aut := pFrobenius_aut (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")] Notation charf0 := pcharf0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")] Notation charf_prime := pcharf_prime (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")] Notation mulrn_char := mulrn_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use natr_mod_pchar instead.")] Notation natr_mod_char := natr_mod_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")] Notation dvdn_charf := dvdn_pcharf (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")] Notation charf_eq := pcharf_eq (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")] Notation bin_lt_charf_0 := bin_lt_pcharf_0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")] Notation Frobenius_autE := pFrobenius_autE (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")] Notation Frobenius_aut0 := pFrobenius_aut0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")] Notation Frobenius_aut1 := pFrobenius_aut1 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")] Notation Frobenius_autD_comm := pFrobenius_autD_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")] Notation Frobenius_autMn := pFrobenius_autMn (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")] Notation Frobenius_aut_nat := pFrobenius_aut_nat (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")] Notation Frobenius_autM_comm := pFrobenius_autM_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")] Notation Frobenius_autX := pFrobenius_autX (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")] Notation addrr_char2 := addrr_pchar2 (only parsing). #[short(type="nzRingType")] HB.structure Definition NzRing := { R of NzSemiRing R & Zmodule R }. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing instead.")] Notation Ring R := (NzRing R) (only parsing). Module Ring. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.sort instead.")] Notation sort := (NzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.on instead.")] Notation on R := (NzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.copy instead.")] Notation copy T U := (NzRing.copy T U) (only parsing). End Ring. HB.factory Record Zmodule_isNzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; oner_neq0 : one != 0 }. Module Zmodule_isRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isNzRing.Build instead.")] Notation Build R := (Zmodule_isNzRing.Build R) (only parsing). End Zmodule_isRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isNzRing instead.")] Notation Zmodule_isRing R := (Zmodule_isNzRing R) (only parsing). HB.builders Context R of Zmodule_isNzRing R. HB.instance Definition _ := Zmodule_isPzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr. HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0. HB.end. HB.factory Record isNzRing R of Choice R := { zero : R; opp : R -> R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; addNr : left_inverse zero opp add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; oner_neq0 : one != zero }. Module isRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzRing.Build instead.")] Notation Build R := (isNzRing.Build R) (only parsing). End isRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzRing instead.")] Notation isRing R := (isNzRing R) (only parsing). HB.builders Context R of isNzRing R. HB.instance Definition _ := @isZmodule.Build R zero opp add addrA addrC add0r addNr. HB.instance Definition _ := @Zmodule_isNzRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr oner_neq0. HB.end. Module NzRingExports. Bind Scope ring_scope with NzRing.sort. End NzRingExports. HB.export NzRingExports. Notation sign R b := (exp (- @one R) (nat_of_bool b)) (only parsing). Local Notation "- 1" := (- (1)) : ring_scope. Section PzRingTheory. Variable R : pzRingType. Implicit Types x y : R. Lemma mulrN x y : x * (- y) = - (x * y). Proof. by apply: (addrI (x * y)); rewrite -mulrDr !subrr mulr0. Qed. Lemma mulNr x y : (- x) * y = - (x * y). Proof. by apply: (addrI (x * y)); rewrite -mulrDl !subrr mul0r. Qed. Lemma mulrNN x y : (- x) * (- y) = x * y. Proof. by rewrite mulrN mulNr opprK. Qed. Lemma mulN1r x : -1 * x = - x. Proof. by rewrite mulNr mul1r. Qed. Lemma mulrN1 x : x * -1 = - x. Proof. by rewrite mulrN mulr1. Qed. Lemma mulrBl x y z : (y - z) * x = y * x - z * x. Proof. by rewrite mulrDl mulNr. Qed. Lemma mulrBr x y z : x * (y - z) = x * y - x * z. Proof. by rewrite mulrDr mulrN. Qed. Lemma natrB m n : n <= m -> (m - n)%:R = m%:R - n%:R :> R. Proof. exact: mulrnBr. Qed. Lemma commrN x y : comm x y -> comm x (- y). Proof. by move=> com_xy; rewrite /comm mulrN com_xy mulNr. Qed. Lemma commrN1 x : comm x (-1). Proof. exact/commrN/commr1. Qed. Lemma commrB x y z : comm x y -> comm x z -> comm x (y - z). Proof. by move=> com_xy com_xz; apply: commrD => //; apply: commrN. Qed. Lemma commr_sign x n : comm x ((-1) ^+ n). Proof. exact: (commrX n (commrN1 x)). Qed. Lemma signr_odd n : (-1) ^+ (odd n) = (-1) ^+ n :> R. Proof. elim: n => //= n IHn; rewrite exprS -{}IHn. by case/odd: n; rewrite !mulN1r ?opprK. Qed. Lemma mulr_sign (b : bool) x : (-1) ^+ b * x = (if b then - x else x). Proof. by case: b; rewrite ?mulNr mul1r. Qed. Lemma signr_addb b1 b2 : (-1) ^+ (b1 (+) b2) = (-1) ^+ b1 * (-1) ^+ b2 :> R. Proof. by rewrite mulr_sign; case: b1 b2 => [] []; rewrite ?opprK. Qed. Lemma signrE (b : bool) : (-1) ^+ b = 1 - b.*2%:R :> R. Proof. by case: b; rewrite ?subr0 // opprD addNKr. Qed. Lemma signrN b : (-1) ^+ (~~ b) = - (-1) ^+ b :> R. Proof. by case: b; rewrite ?opprK. Qed. Lemma mulr_signM (b1 b2 : bool) x1 x2 : ((-1) ^+ b1 * x1) * ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 * x2). Proof. by rewrite signr_addb -!mulrA; congr (_ * _); rewrite !mulrA commr_sign. Qed. Lemma exprNn x n : (- x) ^+ n = (-1) ^+ n * x ^+ n :> R. Proof. by rewrite -mulN1r exprMn_comm // /comm mulN1r mulrN mulr1. Qed. Lemma sqrrN x : (- x) ^+ 2 = x ^+ 2. Proof. exact: mulrNN. Qed. Lemma sqrr_sign n : ((-1) ^+ n) ^+ 2 = 1 :> R. Proof. by rewrite exprAC sqrrN !expr1n. Qed. Lemma signrMK n : @involutive R ( *%R ((-1) ^+ n)). Proof. by move=> x; rewrite mulrA -expr2 sqrr_sign mul1r. Qed. Lemma mulrI0_lreg x : (forall y, x * y = 0 -> y = 0) -> lreg x. Proof. move=> reg_x y z eq_xy_xz; apply/eqP; rewrite -subr_eq0 [y - z]reg_x //. by rewrite mulrBr eq_xy_xz subrr. Qed. Lemma lregN x : lreg x -> lreg (- x). Proof. by move=> reg_x y z; rewrite !mulNr => /oppr_inj/reg_x. Qed. Lemma lreg_sign n : lreg ((-1) ^+ n : R). Proof. exact/lregX/lregN/lreg1. Qed. Lemma prodrN (I : finType) (A : pred I) (F : I -> R) : \prod_(i in A) - F i = (- 1) ^+ #|A| * \prod_(i in A) F i. Proof. rewrite -sum1_card; elim/big_rec3: _ => [|i x n _ _ ->]; first by rewrite mulr1. by rewrite exprS !mulrA mulN1r !mulNr commrX //; apply: commrN1. Qed. Lemma exprBn_comm x y n (cxy : comm x y) : (x - y) ^+ n = \sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. rewrite exprDn_comm; last exact: commrN. by apply: eq_bigr => i _; congr (_ *+ _); rewrite -commr_sign -mulrA -exprNn. Qed. Lemma subrXX_comm x y n (cxy : comm x y) : x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i). Proof. case: n => [|n]; first by rewrite big_ord0 mulr0 subrr. rewrite mulrBl !big_distrr big_ord_recl big_ord_recr /= subnn mulr1 mul1r. rewrite subn0 -!exprS opprD -!addrA; congr (_ + _); rewrite addrA -sumrB. rewrite big1 ?add0r // => i _; rewrite !mulrA -exprS -subSn ?(valP i) //. by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS subrr. Qed. Lemma subrX1 x n : x ^+ n - 1 = (x - 1) * (\sum_(i < n) x ^+ i). Proof. rewrite -!(opprB 1) mulNr -{1}(expr1n _ n). rewrite (subrXX_comm _ (commr_sym (commr1 x))); congr (- (_ * _)). by apply: eq_bigr => i _; rewrite expr1n mul1r. Qed. Lemma sqrrB1 x : (x - 1) ^+ 2 = x ^+ 2 - x *+ 2 + 1. Proof. by rewrite -sqrrN opprB addrC sqrrD1 sqrrN mulNrn. Qed. Lemma subr_sqr_1 x : x ^+ 2 - 1 = (x - 1) * (x + 1). Proof. by rewrite subrX1 !big_ord_recr big_ord0 /= addrAC add0r. Qed. Section ClosedPredicates. Variable S : {pred R}. Definition smulr_closed := -1 \in S /\ mulr_2closed S. Definition subring_closed := [/\ 1 \in S, subr_2closed S & mulr_2closed S]. Lemma smulr_closedM : smulr_closed -> mulr_closed S. Proof. by case=> SN1 SM; split=> //; rewrite -[1]mulr1 -mulrNN SM. Qed. Lemma smulr_closedN : smulr_closed -> oppr_closed S. Proof. by case=> SN1 SM x Sx; rewrite -mulN1r SM. Qed. Lemma subring_closedB : subring_closed -> zmod_closed S. Proof. by case=> S1 SB _; split; rewrite // -(subrr 1) SB. Qed. Lemma subring_closedM : subring_closed -> smulr_closed. Proof. by case=> S1 SB SM; split; rewrite ?(zmod_closedN (subring_closedB _)). Qed. Lemma subring_closed_semi : subring_closed -> semiring_closed S. Proof. by move=> ringS; split; [apply/zmod_closedD/subring_closedB | case: ringS]. Qed. End ClosedPredicates. End PzRingTheory. Section NzRingTheory. Variable R : nzRingType. Implicit Types x y : R. Lemma signr_eq0 n : ((-1) ^+ n == 0 :> R) = false. Proof. by rewrite -signr_odd; case: odd; rewrite ?oppr_eq0 oner_eq0. Qed. (* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible definition. *) Section FrobeniusAutomorphism. Variable p : nat. Hypothesis pcharFp : p \in pchar R. Hint Resolve pcharf_prime : core. Local Notation "x ^f" := (pFrobenius_aut pcharFp x). Lemma pFrobenius_autN x : (- x)^f = - x^f. Proof. apply/eqP; rewrite -subr_eq0 opprK addrC. by rewrite -(pFrobenius_autD_comm _ (commrN _)) // subrr pFrobenius_aut0. Qed. Lemma pFrobenius_autB_comm x y : comm x y -> (x - y)^f = x^f - y^f. Proof. by move/commrN/pFrobenius_autD_comm->; rewrite pFrobenius_autN. Qed. End FrobeniusAutomorphism. Lemma exprNn_pchar x n : (pchar R).-nat n -> (- x) ^+ n = - (x ^+ n). Proof. pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]]. have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) // pi_pdiv. have /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)). elim: e => // e IHe; rewrite expnSr !exprM {}IHe. by rewrite -pFrobenius_autE pFrobenius_autN. Qed. Section Char2. Hypothesis pcharR2 : 2 \in pchar R. Lemma oppr_pchar2 x : - x = x. Proof. by apply/esym/eqP; rewrite -addr_eq0 addrr_pchar2. Qed. Lemma subr_pchar2 x y : x - y = x + y. Proof. by rewrite oppr_pchar2. Qed. Lemma addrK_pchar2 x : involutive (+%R^~ x). Proof. by move=> y; rewrite /= -subr_pchar2 addrK. Qed. Lemma addKr_pchar2 x : involutive (+%R x). Proof. by move=> y; rewrite -{1}[x]oppr_pchar2 addKr. Qed. End Char2. End NzRingTheory. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")] Notation Frobenius_autN := pFrobenius_autN (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")] Notation Frobenius_autB_comm := pFrobenius_autB_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")] Notation exprNn_char := exprNn_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")] Notation oppr_char2 := oppr_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use subr_pchar2 instead.")] Notation subr_char2 := subr_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")] Notation addrK_char2 := addrK_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")] Notation addKr_char2 := addKr_pchar2 (only parsing). Section ConverseRing. #[export] HB.instance Definition _ (T : eqType) := Equality.on T^c. #[export] HB.instance Definition _ (T : choiceType) := Choice.on T^c. #[export] HB.instance Definition _ (U : nmodType) := Nmodule.on U^c. #[export] HB.instance Definition _ (U : zmodType) := Zmodule.on U^c. #[export] HB.instance Definition _ (R : pzSemiRingType) := let mul' (x y : R) := y * x in let mulrA' x y z := esym (mulrA z y x) in let mulrDl' x y z := mulrDr z x y in let mulrDr' x y z := mulrDl y z x in Nmodule_isPzSemiRing.Build R^c mulrA' mulr1 mul1r mulrDl' mulrDr' mulr0 mul0r. #[export] HB.instance Definition _ (R : pzRingType) := PzSemiRing.on R^c. #[export] HB.instance Definition _ (R : nzSemiRingType) := PzSemiRing_isNonZero.Build R^c oner_neq0. #[export] HB.instance Definition _ (R : nzRingType) := NzSemiRing.on R^c. End ConverseRing. Lemma rev_prodr (R : pzSemiRingType) (I : Type) (r : seq I) (P : pred I) (E : I -> R) : \prod_(i <- r | P i) (E i : R^c) = \prod_(i <- rev r | P i) E i. Proof. by rewrite rev_big_rev. Qed. Section SemiRightRegular. Variable R : pzSemiRingType. Implicit Types x y : R. Lemma mulIr_eq0 x y : rreg x -> (y * x == 0) = (y == 0). Proof. exact: (@mulrI_eq0 R^c). Qed. Lemma rreg1 : rreg (1 : R). Proof. exact: (@lreg1 R^c). Qed. Lemma rregM x y : rreg x -> rreg y -> rreg (x * y). Proof. by move=> reg_x reg_y; apply: (@lregM R^c). Qed. Lemma revrX x n : (x : R^c) ^+ n = (x : R) ^+ n. Proof. by elim: n => // n IHn; rewrite exprS exprSr IHn. Qed. Lemma rregX x n : rreg x -> rreg (x ^+ n). Proof. by move/(@lregX R^c x n); rewrite revrX. Qed. End SemiRightRegular. Lemma rreg_neq0 (R : nzSemiRingType) (x : R) : rreg x -> x != 0. Proof. exact: (@lreg_neq0 R^c). Qed. Section RightRegular. Variable R : pzRingType. Implicit Types x y : R. Lemma mulIr0_rreg x : (forall y, y * x = 0 -> y = 0) -> rreg x. Proof. exact: (@mulrI0_lreg R^c). Qed. Lemma rregN x : rreg x -> rreg (- x). Proof. exact: (@lregN R^c). Qed. End RightRegular. HB.mixin Record Nmodule_isLSemiModule (R : pzSemiRingType) V of Nmodule V := { scale : R -> V -> V; scalerA : forall a b v, scale a (scale b v) = scale (a * b) v; scale0r : forall v, scale 0 v = 0; scale1r : left_id 1 scale; scalerDr : right_distributive scale +%R; scalerDl : forall v, {morph scale^~ v: a b / a + b} }. #[short(type="lSemiModType")] HB.structure Definition LSemiModule (R : pzSemiRingType) := {M of Nmodule M & Nmodule_isLSemiModule R M}. Module LSemiModExports. Bind Scope ring_scope with LSemiModule.sort. End LSemiModExports. HB.export LSemiModExports. Local Notation "*:%R" := (@scale _ _) : function_scope. Local Notation "a *: v" := (scale a v) : ring_scope. #[short(type="lmodType")] HB.structure Definition Lmodule (R : pzRingType) := {M of Zmodule M & Nmodule_isLSemiModule R M}. (* FIXME: see #1126 and #1127 *) Arguments scalerA [R s] (a b)%_ring_scope v. Module LmodExports. Bind Scope ring_scope with Lmodule.sort. End LmodExports. HB.export LmodExports. HB.factory Record Zmodule_isLmodule (R : pzRingType) V of Zmodule V := { scale : R -> V -> V; scalerA : forall a b v, scale a (scale b v) = scale (a * b) v; scale1r : left_id 1 scale; scalerDr : right_distributive scale +%R; scalerDl : forall v, {morph scale^~ v: a b / a + b} }. HB.builders Context R V of Zmodule_isLmodule R V. Lemma scale0r v : scale 0 v = 0. Proof. by apply: (addIr (scale 1 v)); rewrite -scalerDl !add0r. Qed. HB.instance Definition _ := Nmodule_isLSemiModule.Build R V scalerA scale0r scale1r scalerDr scalerDl. HB.end. HB.factory Record LSemiModule_isLmodule (R : pzRingType) V of LSemiModule R V := {}. HB.builders Context R V of LSemiModule_isLmodule R V. Definition opp : V -> V := scale (- 1). Lemma addNr : left_inverse 0 opp +%R. Proof. move=> v; suff : scale (-1 + 1) v = 0 by rewrite scalerDl scale1r. by rewrite addNr scale0r. Qed. HB.instance Definition _ := Nmodule_isZmodule.Build V addNr. HB.end. Section LSemiModuleTheory. Variables (R : pzSemiRingType) (V : lSemiModType R). Implicit Types (a b c : R) (u v : V). Lemma scaler0 a : a *: 0 = 0 :> V. Proof. by rewrite -[0 in LHS](scale0r 0) scalerA mulr0 scale0r. Qed. Lemma scaler_nat n v : n%:R *: v = v *+ n. Proof. elim: n => /= [|n]; first by rewrite scale0r. by rewrite !mulrS scalerDl ?scale1r => ->. Qed. Lemma scalerMnl a v n : a *: v *+ n = (a *+ n) *: v. Proof. elim: n => [|n IHn]; first by rewrite !mulr0n scale0r. by rewrite !mulrSr IHn scalerDl. Qed. Lemma scalerMnr a v n : a *: v *+ n = a *: (v *+ n). Proof. elim: n => [|n IHn]; first by rewrite !mulr0n scaler0. by rewrite !mulrSr IHn scalerDr. Qed. Lemma scaler_suml v I r (P : pred I) F : (\sum_(i <- r | P i) F i) *: v = \sum_(i <- r | P i) F i *: v. Proof. exact: (big_morph _ (scalerDl v) (scale0r v)). Qed. Lemma scaler_sumr a I r (P : pred I) (F : I -> V) : a *: (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) a *: F i. Proof. exact: big_endo (scalerDr a) (scaler0 a) I r P F. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition scaler_closed := forall a, {in S, forall v, a *: v \in S}. Definition subsemimod_closed := nmod_closed S /\ scaler_closed. Lemma subsemimod_closedD : subsemimod_closed -> nmod_closed S. Proof. by case. Qed. Lemma subsemimod_closedZ : subsemimod_closed -> scaler_closed. Proof. by case. Qed. End ClosedPredicates. End LSemiModuleTheory. Section LmoduleTheory. Variables (R : pzRingType) (V : lmodType R). Implicit Types (a b c : R) (u v : V). Lemma scaleNr a v : - a *: v = - (a *: v). Proof. by apply: (addIr (a *: v)); rewrite -scalerDl !addNr scale0r. Qed. Lemma scaleN1r v : - 1 *: v = - v. Proof. by rewrite scaleNr scale1r. Qed. Lemma scalerN a v : a *: - v = - (a *: v). Proof. by apply: (addIr (a *: v)); rewrite -scalerDr !addNr scaler0. Qed. Lemma scalerBl a b v : (a - b) *: v = a *: v - b *: v. Proof. by rewrite scalerDl scaleNr. Qed. Lemma scalerBr a u v : a *: (u - v) = a *: u - a *: v. Proof. by rewrite scalerDr scalerN. Qed. Lemma scaler_sign (b : bool) v : (-1) ^+ b *: v = (if b then - v else v). Proof. by case: b; rewrite ?scaleNr scale1r. Qed. Lemma signrZK n : @involutive V ( *:%R ((-1) ^+ n)). Proof. by move=> u; rewrite scalerA -expr2 sqrr_sign scale1r. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition linear_closed := forall a, {in S &, forall u v, a *: u + v \in S}. Definition submod_closed := 0 \in S /\ linear_closed. Lemma linear_closedB : linear_closed -> subr_2closed S. Proof. by move=> Slin u v Su Sv; rewrite addrC -scaleN1r Slin. Qed. Lemma submod_closedB : submod_closed -> zmod_closed S. Proof. by case=> S0 /linear_closedB. Qed. Lemma submod_closed_semi : submod_closed -> subsemimod_closed S. Proof. move=> /[dup] /submod_closedB /zmod_closedD SD [S0 Slin]; split => // a v Sv. by rewrite -[a *: v]addr0 Slin. Qed. End ClosedPredicates. End LmoduleTheory. (* TOTHINK: Can I change `NzSemiRing` to `PzSemiRing`? *) HB.mixin Record LSemiModule_isLSemiAlgebra R V of NzSemiRing V & LSemiModule R V := { scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v }. #[short(type="lSemiAlgType")] HB.structure Definition LSemiAlgebra R := {A of LSemiModule R A & NzSemiRing A & LSemiModule_isLSemiAlgebra R A}. Module LSemiAlgExports. Bind Scope ring_scope with LSemiAlgebra.sort. End LSemiAlgExports. HB.export LSemiAlgExports. (* Scalar injection (see the definition of in_alg A below). *) Local Notation "k %:A" := (k *: 1) : ring_scope. #[short(type="lalgType")] HB.structure Definition Lalgebra R := {A of Lmodule R A & NzRing A & LSemiModule_isLSemiAlgebra R A}. Module LalgExports. Bind Scope ring_scope with Lalgebra.sort. End LalgExports. HB.export LalgExports. HB.factory Record Lmodule_isLalgebra R V of NzRing V & Lmodule R V := { scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v }. HB.builders Context R V of Lmodule_isLalgebra R V. HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R V scalerAl. HB.end. (* Regular ring algebra tag. *) Definition regular R : Type := R. Local Notation "R ^o" := (regular R) : type_scope. Section RegularAlgebra. #[export] HB.instance Definition _ (V : nmodType) := Nmodule.on V^o. #[export] HB.instance Definition _ (V : zmodType) := Zmodule.on V^o. #[export] HB.instance Definition _ (R : pzSemiRingType) := PzSemiRing.on R^o. #[export] HB.instance Definition _ (R : nzSemiRingType) := NzSemiRing.on R^o. #[export] HB.instance Definition _ (R : pzSemiRingType) := @Nmodule_isLSemiModule.Build R R^o mul mulrA mul0r mul1r mulrDr (fun v a b => mulrDl a b v). #[export] HB.instance Definition _ (R : nzSemiRingType) := LSemiModule_isLSemiAlgebra.Build R R^o mulrA. #[export] HB.instance Definition _ (R : pzRingType) := PzRing.on R^o. #[export] HB.instance Definition _ (R : nzRingType) := NzRing.on R^o. End RegularAlgebra. Section LSemiAlgebraTheory. Variables (R : pzSemiRingType) (A : lSemiAlgType R). Lemma mulr_algl (a : R) (x : A) : (a *: 1) * x = a *: x. Proof. by rewrite -scalerAl mul1r. Qed. End LSemiAlgebraTheory. Section LalgebraTheory. Variables (R : pzRingType) (A : lalgType R). Section ClosedPredicates. Variable S : {pred A}. Definition subalg_closed := [/\ 1 \in S, linear_closed S & mulr_2closed S]. Lemma subalg_closedZ : subalg_closed -> submod_closed S. Proof. by case=> S1 Slin _; split; rewrite // -(subrr 1) linear_closedB. Qed. Lemma subalg_closedBM : subalg_closed -> subring_closed S. Proof. by case=> S1 Slin SM; split=> //; apply: linear_closedB. Qed. End ClosedPredicates. End LalgebraTheory. (* Morphism hierarchy. *) (* Lifted multiplication. *) Section LiftedSemiRing. Variables (R : pzSemiRingType) (T : Type). Implicit Type f : T -> R. Definition mull_fun a f x := a * f x. Definition mulr_fun a f x := f x * a. Definition mul_fun f g x := f x * g x. End LiftedSemiRing. (* Lifted linear operations. *) Section LiftedScale. Variables (R : pzSemiRingType) (U : Type). Variables (V : lSemiModType R) (A : lSemiAlgType R). Definition scale_fun a (f : U -> V) x := a *: f x. Definition in_alg k : A := k%:A. End LiftedScale. Local Notation "\0" := (null_fun _) : function_scope. Local Notation "f \+ g" := (add_fun f g) : function_scope. Local Notation "f \- g" := (sub_fun f g) : function_scope. Local Notation "\- f" := (opp_fun f) : function_scope. Local Notation "a \*: f" := (scale_fun a f) : function_scope. Local Notation "x \*o f" := (mull_fun x f) : function_scope. Local Notation "x \o* f" := (mulr_fun x f) : function_scope. Local Notation "f \* g" := (mul_fun f g) : function_scope. Arguments in_alg {_} A _ /. Arguments mull_fun {_ _} a f _ /. Arguments mulr_fun {_ _} a f _ /. Arguments scale_fun {_ _ _} a f _ /. Arguments mul_fun {_ _} f g _ /. Section AdditiveTheory. Section SemiRingProperties. Variables (R S : pzSemiRingType) (f : {additive R -> S}). Lemma raddfMnat n x : f (n%:R * x) = n%:R * f x. Proof. by rewrite !mulr_natl raddfMn. Qed. Variables (U : lSemiModType R) (V : lSemiModType S) (h : {additive U -> V}). Lemma raddfZnat n u : h (n%:R *: u) = n%:R *: h u. Proof. by rewrite !scaler_nat raddfMn. Qed. End SemiRingProperties. Section MulFun. Variables (R : pzSemiRingType) (U : nmodType) (a : R) (f : {additive U -> R}). Fact mull_fun_is_nmod_morphism : nmod_morphism (a \*o f). Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mulr0// raddfD mulrDr. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build U R (a \*o f) mull_fun_is_nmod_morphism. Fact mulr_fun_is_nmod_morphism : nmod_morphism (a \o* f). Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mul0r// raddfD mulrDl. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build U R (a \o* f) mulr_fun_is_nmod_morphism. End MulFun. Section Properties. Variables (U V : zmodType) (f : {additive U -> V}). Lemma raddfN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma raddfB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed. Lemma raddf_inj : (forall x, f x = 0 -> x = 0) -> injective f. Proof. exact: raddf_inj. Qed. Lemma raddfMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. End Properties. Section RingProperties. Variables (R S : pzRingType) (f : {additive R -> S}). Lemma raddfMsign n x : f ((-1) ^+ n * x) = (-1) ^+ n * f x. Proof. by rewrite !(mulr_sign, =^~ signr_odd) (fun_if f) raddfN. Qed. Variables (U : lmodType R) (V : lmodType S) (h : {additive U -> V}). Lemma raddfZsign n u : h ((-1) ^+ n *: u) = (-1) ^+ n *: h u. Proof. by rewrite !(scaler_sign, =^~ signr_odd) (fun_if h) raddfN. Qed. End RingProperties. Section ScaleFun. Variables (R : pzSemiRingType) (U : nmodType) (V : lSemiModType R). Variables (a : R) (f : {additive U -> V}). #[export] HB.instance Definition _ := isNmodMorphism.Build V V ( *:%R a) (conj (scaler0 _ a) (scalerDr a)). #[export] HB.instance Definition _ := Additive.copy (a \*: f) (f \; *:%R a). End ScaleFun. End AdditiveTheory. #[deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")] Definition multiplicative (R S : pzSemiRingType) (f : R -> S) : Prop := {morph f : x y / x * y}%R * (f 1 = 1). (* FIXME: remove once PzSemiRing extends Monoid. *) Definition monoid_morphism (R S : pzSemiRingType) (f : R -> S) : Prop := (f 1 = 1) * {morph f : x y / x * y}%R. HB.mixin Record isMonoidMorphism (R S : pzSemiRingType) (f : R -> S) := { monoid_morphism_subproof : monoid_morphism f }. HB.structure Definition RMorphism (R S : pzSemiRingType) := {f of @isNmodMorphism R S f & isMonoidMorphism R S f}. (* FIXME: remove the @ once https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *) #[warning="-deprecated-since-mathcomp-2.5.0"] HB.factory Record isMultiplicative (R S : pzSemiRingType) (f : R -> S) := { rmorphism_subproof : multiplicative f }. HB.builders Context R S f of isMultiplicative R S f. #[warning="-HB.no-new-instance"] HB.instance Definition _ := isMonoidMorphism.Build R S f (rmorphism_subproof.2, rmorphism_subproof.1). HB.end. Module RMorphismExports. Notation "{ 'rmorphism' U -> V }" := (RMorphism.type U%type V%type) : type_scope. End RMorphismExports. HB.export RMorphismExports. Section RmorphismTheory. Section Properties. Variables (R S : pzSemiRingType) (f : {rmorphism R -> S}). Lemma rmorph0 : f 0 = 0. Proof. exact: raddf0. Qed. Lemma rmorphD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed. Lemma rmorphMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma rmorph_sum I r (P : pred I) E : f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i). Proof. exact: raddf_sum. Qed. Lemma rmorphism_monoidP : monoid_morphism f. Proof. exact: monoid_morphism_subproof. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `rmorphism_monoidP` instead")] Definition rmorphismMP : multiplicative f := (fun p => (p.2, p.1)) rmorphism_monoidP. Lemma rmorph1 : f 1 = 1. Proof. by case: rmorphism_monoidP. Qed. Lemma rmorphM : {morph f: x y / x * y}. Proof. by case: rmorphism_monoidP. Qed. Lemma rmorph_prod I r (P : pred I) E : f (\prod_(i <- r | P i) E i) = \prod_(i <- r | P i) f (E i). Proof. exact: (big_morph f rmorphM rmorph1). Qed. Lemma rmorphXn n : {morph f : x / x ^+ n}. Proof. by elim: n => [|n IHn] x; rewrite ?rmorph1 // !exprS rmorphM IHn. Qed. Lemma rmorph_nat n : f n%:R = n%:R. Proof. by rewrite rmorphMn rmorph1. Qed. Lemma rmorph_eq_nat x n : injective f -> (f x == n%:R) = (x == n%:R). Proof. by move/inj_eq <-; rewrite rmorph_nat. Qed. Lemma rmorph_eq1 x : injective f -> (f x == 1) = (x == 1). Proof. exact: rmorph_eq_nat 1%N. Qed. Lemma can2_monoid_morphism f' : cancel f f' -> cancel f' f -> monoid_morphism f'. Proof. move=> fK f'K. by split=> [|x y]; apply: (canLR fK); rewrite /= (rmorph1, rmorphM) ?f'K. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `can2_monoid_morphism` instead")] Definition can2_rmorphism f' (cff' : cancel f f') := (fun p => (p.2, p.1)) \o (can2_monoid_morphism cff'). End Properties. Lemma rmorph_pchar (R S : nzSemiRingType) (f : {rmorphism R -> S}) p : p \in pchar R -> p \in pchar S. Proof. by rewrite !inE -(rmorph_nat f) => /andP[-> /= /eqP->]; rewrite rmorph0. Qed. Section Projections. Variables (R S T : pzSemiRingType). Variables (f : {rmorphism S -> T}) (g : {rmorphism R -> S}). Fact idfun_is_monoid_morphism : monoid_morphism (@idfun R). Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R R idfun idfun_is_monoid_morphism. Fact comp_is_monoid_morphism : monoid_morphism (f \o g). Proof. by split=> [|x y] /=; rewrite ?rmorph1 ?rmorphM. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R T (f \o g) comp_is_monoid_morphism. End Projections. Section Properties. Variables (R S : pzRingType) (f : {rmorphism R -> S}). Lemma rmorphN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma rmorphB : {morph f: x y / x - y}. Proof. exact: raddfB. Qed. Lemma rmorphMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. Lemma rmorphMsign n : {morph f : x / (- 1) ^+ n * x}. Proof. exact: raddfMsign. Qed. Lemma rmorphN1 : f (- 1) = (- 1). Proof. by rewrite rmorphN rmorph1. Qed. Lemma rmorph_sign n : f ((- 1) ^+ n) = (- 1) ^+ n. Proof. by rewrite rmorphXn /= rmorphN1. Qed. End Properties. Section InSemiAlgebra. Variables (R : pzSemiRingType) (A : lSemiAlgType R). Fact in_alg_is_nmod_morphism : nmod_morphism (in_alg A). Proof. by split; [exact: scale0r | exact: scalerDl]. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build R A (in_alg A) in_alg_is_nmod_morphism. Fact in_alg_is_monoid_morphism : monoid_morphism (in_alg A). Proof. by split=> [|x y]; rewrite /= ?scale1r // mulr_algl scalerA. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R A (in_alg A) in_alg_is_monoid_morphism. Lemma in_algE a : in_alg A a = a%:A. Proof. by []. Qed. End InSemiAlgebra. End RmorphismTheory. #[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")] Notation rmorph_char := rmorph_pchar (only parsing). Module Scale. HB.mixin Record isPreLaw (R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := { op_nmod_morphism : forall a, nmod_morphism (op a); }. #[export] HB.structure Definition PreLaw R V := {op of isPreLaw R V op}. Definition preLaw := PreLaw.type. HB.mixin Record isSemiLaw (R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := { op0v : forall v, op 0 v = 0; op1v : op 1 =1 id; opA : forall a b v, op a (op b v) = op (a * b) v; }. #[export] HB.structure Definition SemiLaw R V := {op of isPreLaw R V op & isSemiLaw R V op}. Definition semiLaw := SemiLaw.type. HB.mixin Record isLaw (R : pzRingType) (V : zmodType) (op : R -> V -> V) := { N1op : op (-1) =1 -%R }. #[export] HB.structure Definition Law (R : pzRingType) (V : zmodType) := {op of isPreLaw R V op & isLaw R V op}. Definition law := Law.type. Section CompSemiLaw. Context (R : pzSemiRingType) (V : nmodType) (s : semiLaw R V). Context (aR : pzSemiRingType) (nu : {rmorphism aR -> R}). Fact comp_op0v v : (nu \; s) 0 v = 0. Proof. by rewrite /= rmorph0 op0v. Qed. Fact comp_op1v : (nu \; s) 1 =1 id. Proof. by move=> v; rewrite /= rmorph1 op1v. Qed. Fact comp_opA a b v : (nu \; s) a ((nu \; s) b v) = (nu \; s) (a * b) v. Proof. by rewrite /= opA rmorphM. Qed. End CompSemiLaw. Fact compN1op (R : pzRingType) (V : zmodType) (s : law R V) (aR : pzRingType) (nu : {rmorphism aR -> R}) : (nu \; s) (-1) =1 -%R. Proof. by move=> v; rewrite /= rmorphN1 N1op. Qed. Module Exports. HB.reexport. End Exports. End Scale. Export Scale.Exports. #[export] HB.instance Definition _ (R : pzSemiRingType) := Scale.isPreLaw.Build R R *%R (fun => mull_fun_is_nmod_morphism _ idfun). #[export] HB.instance Definition _ (R : pzSemiRingType) := Scale.isSemiLaw.Build R R *%R mul0r mul1r mulrA. #[export] HB.instance Definition _ (R : pzRingType) := Scale.isLaw.Build R R *%R (@mulN1r R). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) := Scale.isPreLaw.Build R V *:%R (fun => (scaler0 _ _, scalerDr _)). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) := Scale.isSemiLaw.Build R V *:%R scale0r scale1r (@scalerA _ _). #[export] HB.instance Definition _ (R : pzRingType) (U : lmodType R) := Scale.isLaw.Build R U *:%R (@scaleN1r R U). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V) (aR : pzSemiRingType) (nu : {rmorphism aR -> R}) := Scale.isPreLaw.Build aR V (nu \; s) (fun => Scale.op_nmod_morphism _). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.semiLaw R V) (aR : pzSemiRingType) (nu : {rmorphism aR -> R}) := Scale.isSemiLaw.Build aR V (nu \; s) (Scale.comp_op0v s nu) (Scale.comp_op1v s nu) (Scale.comp_opA s nu). #[export] HB.instance Definition _ (R : pzRingType) (V : zmodType) (s : Scale.law R V) (aR : pzRingType) (nu : {rmorphism aR -> R}) := Scale.isLaw.Build aR V (nu \; s) (Scale.compN1op s nu). #[export, non_forgetful_inheritance] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V) a := isNmodMorphism.Build V V (s a) (Scale.op_nmod_morphism a). Definition scalable_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := forall a, {morph f : u / a *: u >-> s a u}. HB.mixin Record isScalable (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := { semi_linear_subproof : scalable_for s f; }. HB.structure Definition Linear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) := {f of @isNmodMorphism U V f & isScalable R U V s f}. Definition semilinear_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) : Type := scalable_for s f * {morph f : x y / x + y}. Lemma nmod_morphism_semilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) : semilinear_for s f -> nmod_morphism f. Proof. by case=> sf Df; split => //; rewrite -[0 in LHS](scale0r 0) sf Scale.op0v. Qed. Definition additive_semilinear := nmod_morphism_semilinear. Lemma scalable_semilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.preLaw R V) (f : U -> V) : semilinear_for s f -> scalable_for s f. Proof. by case. Qed. HB.factory Record isSemilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) := { linear_subproof : semilinear_for s f; }. HB.builders Context R U V s f of isSemilinear R U V s f. HB.instance Definition _ := isNmodMorphism.Build U V f (additive_semilinear linear_subproof). HB.instance Definition _ := isScalable.Build R U V s f (scalable_semilinear linear_subproof). HB.end. Definition linear_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := forall a, {morph f : u v / a *: u + v >-> s a u + v}. Lemma zmod_morphism_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> zmod_morphism f. Proof. by move=> Lsf x y; rewrite -scaleN1r addrC Lsf Scale.N1op addrC. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism_linear` instead")] Definition additive_linear := zmod_morphism_linear. Lemma scalable_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> scalable_for s f. Proof. by move=> Lsf a v; rewrite -[a *:v](addrK v) (zmod_morphism_linear Lsf) Lsf addrK. Qed. Lemma semilinear_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> semilinear_for s f. Proof. move=> Lsf; split=> [a x|x y]; first exact: (scalable_linear Lsf). have f0: f 0 = 0 by rewrite -[0 in LHS]subr0 (zmod_morphism_linear Lsf) subrr. by rewrite -[y in LHS]opprK -[- y]add0r !(zmod_morphism_linear Lsf) f0 sub0r opprK. Qed. HB.factory Record isLinear (R : pzRingType) (U : lmodType R) (V : zmodType) (s : Scale.law R V) (f : U -> V) := { linear_subproof : linear_for s f; }. HB.builders Context R U V s f of isLinear R U V s f. HB.instance Definition _ := isZmodMorphism.Build U V f (zmod_morphism_linear linear_subproof). HB.instance Definition _ := isScalable.Build R U V s f (scalable_linear linear_subproof). HB.end. Module LinearExports. Notation scalable f := (scalable_for *:%R f). Notation semilinear f := (semilinear_for *:%R f). Notation semiscalar f := (semilinear_for *%R f). Notation linear f := (linear_for *:%R f). Notation scalar f := (linear_for *%R f). Module Linear. Section Linear. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V). (* Support for right-to-left rewriting with the generic linearZ rule. *) Local Notation mapUV := (@Linear.type R U V s). Definition map_class := mapUV. Definition map_at (a : R) := mapUV. Structure map_for a s_a := MapFor {map_for_map : mapUV; _ : s a = s_a}. Definition unify_map_at a (g : map_at a) := MapFor g (erefl (s a)). Structure wrapped := Wrap {unwrap : mapUV}. Definition wrap (f : map_class) := Wrap f. End Linear. End Linear. Notation "{ 'linear' U -> V | s }" := (@Linear.type _ U V s) : type_scope. Notation "{ 'linear' U -> V }" := {linear U -> V | *:%R} : type_scope. Notation "{ 'scalar' U }" := {linear U -> _ | *%R} (format "{ 'scalar' U }") : type_scope. (* Support for right-to-left rewriting with the generic linearZ rule. *) Coercion Linear.map_for_map : Linear.map_for >-> Linear.type. Coercion Linear.unify_map_at : Linear.map_at >-> Linear.map_for. Canonical Linear.unify_map_at. Coercion Linear.unwrap : Linear.wrapped >-> Linear.type. Coercion Linear.wrap : Linear.map_class >-> Linear.wrapped. Canonical Linear.wrap. End LinearExports. HB.export LinearExports. Section LinearTheory. Section GenericProperties. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V) (f : {linear U -> V | s}). Lemma linear0 : f 0 = 0. Proof. exact: raddf0. Qed. Lemma linearD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed. Lemma linearMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma linear_sum I r (P : pred I) E : f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i). Proof. exact: raddf_sum. Qed. Lemma linearZ_LR : scalable_for s f. Proof. exact: semi_linear_subproof. Qed. Lemma semilinearP : semilinear_for s f. Proof. split; [exact: linearZ_LR | exact: linearD]. Qed. Lemma linearP : linear_for s f. Proof. by move=> a u v /=; rewrite !semilinearP. Qed. End GenericProperties. Section GenericProperties. Variables (R : pzRingType) (U : lmodType R) (V : zmodType) (s : R -> V -> V). Variables (f : {linear U -> V | s}). Lemma linearN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma linearB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed. Lemma linearMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. End GenericProperties. Section BidirectionalLinearZ. (* The general form of the linearZ lemma uses some bespoke interfaces to *) (* allow right-to-left rewriting when a composite scaling operation such as *) (* conjC \; *%R has been expanded, say in a^* * f u. This redex is matched *) (* by using the Scale.law interface to recognize a "head" scaling operation *) (* h (here *%R), stow away its "scalar" c, then reconcile h c and s a, once *) (* s is known, that is, once the Linear.map structure for f has been found. *) (* In general, s and a need not be equal to h and c; indeed they need not *) (* have the same type! The unification is performed by the unify_map_at *) (* default instance for the Linear.map_for U s a h_c sub-interface of *) (* Linear.map; the h_c pattern uses the Scale.law structure to insure it is *) (* inferred when rewriting right-to-left. *) (* The wrap on the rhs allows rewriting f (a *: b *: u) into a *: b *: f u *) (* with rewrite !linearZ /= instead of rewrite linearZ /= linearZ /=. *) (* Without it, the first rewrite linearZ would produce *) (* (a *: apply (map_for_map (@check_map_at .. a f)) (b *: u)%R)%Rlin *) (* and matching the second rewrite LHS would bypass the unify_map_at default *) (* instance for b, reuse the one for a, and subsequently fail to match the *) (* b *: u argument. The extra wrap / unwrap ensures that this can't happen. *) (* In the RL direction, the wrap / unwrap will be inserted on the redex side *) (* as needed, without causing unnecessary delta-expansion: using an explicit *) (* identity function would have Coq normalize the redex to head normal, then *) (* reduce the identity to expose the map_for_map projection, and the *) (* expanded Linear.map structure would then be exposed in the result. *) (* Most of this machinery will be invisible to a casual user, because all *) (* the projections and default instances involved are declared as coercions. *) Lemma linearZ (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (S : pzSemiRingType) (h : Scale.preLaw S V) (c : S) (a : R) (h_c := h c) (f : Linear.map_for U s a h_c) (u : U) : f (a *: u) = h_c (Linear.wrap f u). Proof. by rewrite linearZ_LR; case: f => f /= ->. Qed. End BidirectionalLinearZ. Section LmodProperties. Variables (R : pzSemiRingType) (U V : lSemiModType R) (f : {linear U -> V}). Lemma linearZZ : scalable f. Proof. exact: linearZ_LR. Qed. Lemma semilinearPZ : semilinear f. Proof. exact: semilinearP. Qed. Lemma linearPZ : linear f. Proof. exact: linearP. Qed. Lemma can2_scalable f' : cancel f f' -> cancel f' f -> scalable f'. Proof. by move=> fK f'K a x; apply: (canLR fK); rewrite linearZZ f'K. Qed. Lemma can2_semilinear f' : cancel f f' -> cancel f' f -> semilinear f'. Proof. by move=> fK f'K; split=> ? ?; apply: (canLR fK); rewrite semilinearPZ !f'K. Qed. Lemma can2_linear f' : cancel f f' -> cancel f' f -> linear f'. Proof. by move=> fK f'K a x y /=; apply: (canLR fK); rewrite linearP !f'K. Qed. End LmodProperties. Section ScalarProperties. Variable (R : pzSemiRingType) (U : lSemiModType R) (f : {scalar U}). Lemma scalarZ : scalable_for *%R f. Proof. exact: linearZ_LR. Qed. Lemma semiscalarP : semiscalar f. Proof. exact: semilinearP. Qed. Lemma scalarP : scalar f. Proof. exact: linearP. Qed. End ScalarProperties. Section LinearLSemiMod. Section Idfun. Variables (R : pzSemiRingType) (U : lSemiModType R). Lemma idfun_is_scalable : scalable (@idfun U). Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R U U *:%R idfun idfun_is_scalable. End Idfun. Section Plain. Variables (R : pzSemiRingType) (W U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V) (f : {linear U -> V | s}) (g : {linear W -> U}). Lemma comp_is_scalable : scalable_for s (f \o g). Proof. by move=> a v /=; rewrite !linearZ_LR. Qed. #[export] HB.instance Definition _ := isScalable.Build R W V s (f \o g) comp_is_scalable. End Plain. Section SemiScale. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}). Lemma null_fun_is_scalable : scalable_for s (\0 : U -> V). Proof. by move=> a v /=; rewrite raddf0. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s \0 null_fun_is_scalable. Lemma add_fun_is_scalable : scalable_for s (add_fun f g). Proof. by move=> a u; rewrite /= !linearZ_LR raddfD. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (f \+ g) add_fun_is_scalable. End SemiScale. End LinearLSemiMod. Section LinearLmod. Variables (R : pzRingType) (U : lmodType R). Lemma opp_is_scalable : scalable (-%R : U -> U). Proof. by move=> a v /=; rewrite scalerN. Qed. #[export] HB.instance Definition _ := isScalable.Build R U U *:%R -%R opp_is_scalable. End LinearLmod. Section Scale. Variables (R : pzRingType) (U : lmodType R) (V : zmodType). Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}). Lemma sub_fun_is_scalable : scalable_for s (f \- g). Proof. by move=> a u; rewrite /= !linearZ_LR raddfB. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (f \- g) sub_fun_is_scalable. Lemma opp_fun_is_scalable : scalable_for s (\- f). Proof. by move=> a u; rewrite /= linearZ_LR raddfN. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (\- f) opp_fun_is_scalable. End Scale. Section LinearLSemiAlg. Variables (R : pzSemiRingType) (A : lSemiAlgType R) (U : lSemiModType R). Variables (a : A) (f : {linear U -> A}). Fact mulr_fun_is_scalable : scalable (a \o* f). Proof. by move=> k x /=; rewrite linearZ scalerAl. Qed. #[export] HB.instance Definition _ := isScalable.Build R U A *:%R (a \o* f) mulr_fun_is_scalable. End LinearLSemiAlg. End LinearTheory. HB.structure Definition LRMorphism (R : pzSemiRingType) (A : lSemiAlgType R) (B : pzSemiRingType) (s : R -> B -> B) := {f of @RMorphism A B f & isScalable R A B s f}. (* FIXME: remove the @ once https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *) Module LRMorphismExports. Notation "{ 'lrmorphism' A -> B | s }" := (@LRMorphism.type _ A%type B%type s) : type_scope. Notation "{ 'lrmorphism' A -> B }" := {lrmorphism A%type -> B%type | *:%R} : type_scope. End LRMorphismExports. HB.export LRMorphismExports. Section LRMorphismTheory. Variables (R : pzSemiRingType) (A B : lSemiAlgType R) (C : pzSemiRingType). Variables (s : R -> C -> C). Variables (f : {lrmorphism A -> B}) (g : {lrmorphism B -> C | s}). #[export] HB.instance Definition _ := RMorphism.on (@idfun A). #[export] HB.instance Definition _ := RMorphism.on (g \o f). Lemma rmorph_alg a : f a%:A = a%:A. Proof. by rewrite linearZ /= rmorph1. Qed. End LRMorphismTheory. HB.mixin Record PzSemiRing_hasCommutativeMul R of PzSemiRing R := { mulrC : commutative (@mul R) }. Module SemiRing_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzSemiRing_hasCommutativeMul.Build instead.")] Notation Build R := (PzSemiRing_hasCommutativeMul.Build R) (only parsing). End SemiRing_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzSemiRing_hasCommutativeMul instead.")] Notation SemiRing_hasCommutativeMul R := (PzSemiRing_hasCommutativeMul R) (only parsing). #[short(type="comPzSemiRingType")] HB.structure Definition ComPzSemiRing := {R of PzSemiRing R & PzSemiRing_hasCommutativeMul R}. Module ComPzSemiRingExports. Bind Scope ring_scope with ComPzSemiRing.sort. End ComPzSemiRingExports. HB.export ComPzSemiRingExports. HB.factory Record Nmodule_isComPzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; mul0r : left_zero zero mul; }. HB.builders Context R of Nmodule_isComPzSemiRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. Lemma mulr0 : right_zero zero mul. Proof. by move=> x; rewrite mulrC mul0r. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. #[short(type="comNzSemiRingType")] HB.structure Definition ComNzSemiRing := {R of NzSemiRing R & PzSemiRing_hasCommutativeMul R}. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing instead.")] Notation ComSemiRing R := (ComNzSemiRing R) (only parsing). Module ComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.sort instead.")] Notation sort := (ComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.on instead.")] Notation on R := (ComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.copy instead.")] Notation copy T U := (ComNzSemiRing.copy T U) (only parsing). End ComSemiRing. Module ComNzSemiRingExports. Bind Scope ring_scope with ComNzSemiRing.sort. End ComNzSemiRingExports. HB.export ComNzSemiRingExports. HB.factory Record Nmodule_isComNzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; mul0r : left_zero zero mul; oner_neq0 : one != zero }. Module Nmodule_isComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isComNzSemiRing.Build instead.")] Notation Build R := (Nmodule_isComNzSemiRing.Build R) (only parsing). End Nmodule_isComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isComNzSemiRing instead.")] Notation Nmodule_isComSemiRing R := (Nmodule_isComNzSemiRing R) (only parsing). HB.builders Context R of Nmodule_isComNzSemiRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. Lemma mulr0 : right_zero zero mul. Proof. by move=> x; rewrite mulrC mul0r. Qed. HB.instance Definition _ := Nmodule_isNzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. Section ComSemiRingTheory. Variable R : comPzSemiRingType. Implicit Types x y : R. #[export] HB.instance Definition _ := SemiGroup.isCommutativeLaw.Build R *%R mulrC. Lemma mulrCA : @left_commutative R R *%R. Proof. exact: mulmCA. Qed. Lemma mulrAC : @right_commutative R R *%R. Proof. exact: mulmAC. Qed. Lemma mulrACA : @interchange R *%R *%R. Proof. exact: mulmACA. Qed. Lemma exprMn n : {morph (fun x => x ^+ n) : x y / x * y}. Proof. by move=> x y; exact/exprMn_comm/mulrC. Qed. Lemma prodrXl n I r (P : pred I) (F : I -> R) : \prod_(i <- r | P i) F i ^+ n = (\prod_(i <- r | P i) F i) ^+ n. Proof. by rewrite (big_morph _ (exprMn n) (expr1n _ n)). Qed. Lemma prodr_undup_exp_count (I : eqType) r (P : pred I) (F : I -> R) : \prod_(i <- undup r | P i) F i ^+ count_mem i r = \prod_(i <- r | P i) F i. Proof. exact: big_undup_iterop_count. Qed. Lemma prodrMl {I : finType} (A : pred I) (x : R) F : \prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i. Proof. by rewrite big_split ?prodr_const. Qed. Lemma prodrMr {I : finType} (A : pred I) (x : R) F : \prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|. Proof. by rewrite big_split ?prodr_const. Qed. Lemma exprDn x y n : (x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. by rewrite exprDn_comm //; apply: mulrC. Qed. Lemma sqrrD x y : (x + y) ^+ 2 = x ^+ 2 + x * y *+ 2 + y ^+ 2. Proof. by rewrite exprDn !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed. End ComSemiRingTheory. (* FIXME: Generalize to `comPzSemiRingType` ? *) Section ComNzSemiRingTheory. Variable R : comNzSemiRingType. Implicit Types x y : R. Section FrobeniusAutomorphism. Variables (p : nat) (pcharRp : p \in pchar R). Lemma pFrobenius_aut_is_nmod_morphism : nmod_morphism (pFrobenius_aut pcharRp). Proof. by split=> [|x y]; [exact: pFrobenius_aut0 | exact/pFrobenius_autD_comm/mulrC]. Qed. Lemma pFrobenius_aut_is_monoid_morphism : monoid_morphism (pFrobenius_aut pcharRp). Proof. by split=> [|x y]; [exact: pFrobenius_aut1 | exact/pFrobenius_autM_comm/mulrC]. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build R R (pFrobenius_aut pcharRp) pFrobenius_aut_is_nmod_morphism. #[export] HB.instance Definition _ := isMonoidMorphism.Build R R (pFrobenius_aut pcharRp) pFrobenius_aut_is_monoid_morphism. End FrobeniusAutomorphism. Lemma exprDn_pchar x y n : (pchar R).-nat n -> (x + y) ^+ n = x ^+ n + y ^+ n. Proof. pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]]. have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) ?pi_pdiv. have{pcharRn} /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)). by elim: e => // e IHe; rewrite !expnSr !exprM IHe -pFrobenius_autE rmorphD. Qed. (* FIXME: Generalize to `comPzSemiRingType` ? *) Lemma rmorph_comm (S : nzSemiRingType) (f : {rmorphism R -> S}) x y : comm (f x) (f y). Proof. by red; rewrite -!rmorphM mulrC. Qed. Section ScaleLinear. Variables (U V : lSemiModType R) (b : R) (f : {linear U -> V}). Lemma scale_is_scalable : scalable ( *:%R b : V -> V). Proof. by move=> a v /=; rewrite !scalerA mulrC. Qed. #[export] HB.instance Definition _ := isScalable.Build R V V *:%R ( *:%R b) scale_is_scalable. Lemma scale_fun_is_scalable : scalable (b \*: f). Proof. by move=> a v /=; rewrite !linearZ. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V *:%R (b \*: f) scale_fun_is_scalable. End ScaleLinear. End ComNzSemiRingTheory. #[short(type="comPzRingType")] HB.structure Definition ComPzRing := {R of PzRing R & ComPzSemiRing R}. HB.factory Record PzRing_hasCommutativeMul R of PzRing R := { mulrC : commutative (@mul R) }. Module Ring_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzRing_hasCommutativeMul.Build instead.")] Notation Build R := (PzRing_hasCommutativeMul.Build R) (only parsing). End Ring_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzRing_hasCommutativeMul instead.")] Notation Ring_hasCommutativeMul R := (PzRing_hasCommutativeMul R) (only parsing). HB.builders Context R of PzRing_hasCommutativeMul R. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. HB.factory Record Zmodule_isComPzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; }. HB.builders Context R of Zmodule_isComPzRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. HB.instance Definition _ := Zmodule_isPzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr. HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC. HB.end. Module ComPzRingExports. Bind Scope ring_scope with ComPzRing.sort. End ComPzRingExports. HB.export ComPzRingExports. #[deprecated(since="mathcomp 2.5.0", note="Use pFrobenius_aut_is_monoid_morphism instead.")] Notation pFrobenius_aut_is_multiplicative := (fun p => (p.2, p.1) \o pFrobenius_aut_is_monoid_morphism) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")] Notation exprDn_char := exprDn_pchar (only parsing). #[short(type="comNzRingType")] HB.structure Definition ComNzRing := {R of NzRing R & ComNzSemiRing R}. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing instead.")] Notation ComRing R := (ComNzRing R) (only parsing). Module ComRing. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.sort instead.")] Notation sort := (ComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.on instead.")] Notation on R := (ComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.copy instead.")] Notation copy T U := (ComNzRing.copy T U) (only parsing). End ComRing. HB.factory Record Zmodule_isComNzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; oner_neq0 : one != zero }. Module Zmodule_isComRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isComNzRing.Build instead.")] Notation Build R := (Zmodule_isComNzRing.Build R) (only parsing). End Zmodule_isComRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isComNzRing instead.")] Notation Zmodule_isComRing R := (Zmodule_isComNzRing R) (only parsing). HB.builders Context R of Zmodule_isComNzRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. HB.instance Definition _ := Zmodule_isNzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr oner_neq0. HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC. HB.end. Module ComNzRingExports. Bind Scope ring_scope with ComNzRing.sort. End ComNzRingExports. HB.export ComNzRingExports. Section ComPzRingTheory. Variable R : comPzRingType. Implicit Types x y : R. Lemma exprBn x y n : (x - y) ^+ n = \sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. by rewrite exprBn_comm //; apply: mulrC. Qed. Lemma subrXX x y n : x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i). Proof. by rewrite -subrXX_comm //; apply: mulrC. Qed. Lemma sqrrB x y : (x - y) ^+ 2 = x ^+ 2 - x * y *+ 2 + y ^+ 2. Proof. by rewrite sqrrD mulrN mulNrn sqrrN. Qed. Lemma subr_sqr x y : x ^+ 2 - y ^+ 2 = (x - y) * (x + y). Proof. by rewrite subrXX !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed. Lemma subr_sqrDB x y : (x + y) ^+ 2 - (x - y) ^+ 2 = x * y *+ 4. Proof. rewrite sqrrD sqrrB -!(addrAC _ (y ^+ 2)) opprB. by rewrite [LHS]addrC addrA subrK -mulrnDr. Qed. End ComPzRingTheory. HB.mixin Record LSemiAlgebra_isSemiAlgebra R V of LSemiAlgebra R V := { scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y); }. #[short(type="semiAlgType")] HB.structure Definition SemiAlgebra (R : pzSemiRingType) := {A of LSemiAlgebra_isSemiAlgebra R A & LSemiAlgebra R A}. Module SemiAlgExports. Bind Scope ring_scope with SemiAlgebra.sort. End SemiAlgExports. HB.factory Record LSemiAlgebra_isComSemiAlgebra R V of ComPzSemiRing V & LSemiAlgebra R V := {}. HB.builders Context (R : pzSemiRingType) V of LSemiAlgebra_isComSemiAlgebra R V. Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y). Proof. by rewrite mulrC scalerAl mulrC. Qed. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalarAr. HB.end. #[short(type="algType")] HB.structure Definition Algebra (R : pzRingType) := {A of LSemiAlgebra_isSemiAlgebra R A & Lalgebra R A}. Module AlgExports. Bind Scope ring_scope with Algebra.sort. End AlgExports. HB.export AlgExports. HB.factory Record Lalgebra_isAlgebra (R : pzRingType) V of Lalgebra R V := { scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y); }. HB.builders Context (R : pzRingType) V of Lalgebra_isAlgebra R V. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalerAr. HB.end. HB.factory Record Lalgebra_isComAlgebra R V of ComPzRing V & Lalgebra R V := {}. HB.builders Context (R : pzRingType) V of Lalgebra_isComAlgebra R V. Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y). Proof. by rewrite mulrC scalerAl mulrC. Qed. HB.instance Definition lalgebra_is_algebra : Lalgebra_isAlgebra R V := Lalgebra_isAlgebra.Build R V scalarAr. HB.end. #[short(type="comSemiAlgType")] HB.structure Definition ComSemiAlgebra R := {V of ComNzSemiRing V & SemiAlgebra R V}. Module ComSemiAlgExports. Bind Scope ring_scope with ComSemiAlgebra.sort. End ComSemiAlgExports. HB.export ComSemiAlgExports. Section SemiAlgebraTheory. #[export] HB.instance Definition _ (R : comPzSemiRingType) := PzSemiRing_hasCommutativeMul.Build R^c (fun _ _ => mulrC _ _). #[export] HB.instance Definition _ (R : comPzSemiRingType) := ComPzSemiRing.on R^o. #[export] HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^c. #[export] HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^o. #[export] HB.instance Definition _ (R : comNzSemiRingType) := LSemiAlgebra_isComSemiAlgebra.Build R R^o. End SemiAlgebraTheory. #[short(type="comAlgType")] HB.structure Definition ComAlgebra R := {V of ComNzRing V & Algebra R V}. Module ComAlgExports. Bind Scope ring_scope with ComAlgebra.sort. End ComAlgExports. HB.export ComAlgExports. Section AlgebraTheory. #[export] HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^c. #[export] HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^o. #[export] HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^c. #[export] HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^o. End AlgebraTheory. Section SemiAlgebraTheory. Variables (R : pzSemiRingType) (A : semiAlgType R). Implicit Types (k : R) (x y : A). Lemma scalerCA k x y : k *: x * y = x * (k *: y). Proof. by rewrite -scalerAl scalerAr. Qed. Lemma mulr_algr a x : x * a%:A = a *: x. Proof. by rewrite -scalerAr mulr1. Qed. Lemma comm_alg a x : comm a%:A x. Proof. by rewrite /comm mulr_algr mulr_algl. Qed. Lemma exprZn k x n : (k *: x) ^+ n = k ^+ n *: x ^+ n. Proof. elim: n => [|n IHn]; first by rewrite !expr0 scale1r. by rewrite !exprS IHn -scalerA scalerAr scalerAl. Qed. Lemma scaler_prod I r (P : pred I) (F : I -> R) (G : I -> A) : \prod_(i <- r | P i) (F i *: G i) = \prod_(i <- r | P i) F i *: \prod_(i <- r | P i) G i. Proof. elim/big_rec3: _ => [|i x a _ _ ->]; first by rewrite scale1r. by rewrite -scalerAl -scalerAr scalerA. Qed. Lemma scaler_prodl (I : finType) (S : pred I) (F : I -> A) k : \prod_(i in S) (k *: F i) = k ^+ #|S| *: \prod_(i in S) F i. Proof. by rewrite scaler_prod prodr_const. Qed. Lemma scaler_prodr (I : finType) (S : pred I) (F : I -> R) x : \prod_(i in S) (F i *: x) = \prod_(i in S) F i *: x ^+ #|S|. Proof. by rewrite scaler_prod prodr_const. Qed. End SemiAlgebraTheory. Section AlgebraTheory. Variables (R : pzSemiRingType) (A : semiAlgType R). Variables (U : lSemiModType R) (a : A) (f : {linear U -> A}). Lemma mull_fun_is_scalable : scalable (a \*o f). Proof. by move=> k x /=; rewrite linearZ scalerAr. Qed. #[export] HB.instance Definition _ := isScalable.Build R U A *:%R (a \*o f) mull_fun_is_scalable. End AlgebraTheory. HB.mixin Record NzRing_hasMulInverse R of NzRing R := { unit_subdef : pred R; inv : R -> R; mulVr_subproof : {in unit_subdef, left_inverse 1 inv *%R}; divrr_subproof : {in unit_subdef, right_inverse 1 inv *%R}; unitrP_subproof : forall x y, y * x = 1 /\ x * y = 1 -> unit_subdef x; invr_out_subproof : {in [predC unit_subdef], inv =1 id} }. Module Ring_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing_hasMulInverse.Build instead.")] Notation Build R := (NzRing_hasMulInverse.Build R) (only parsing). End Ring_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing_hasMulInverse instead.")] Notation Ring_hasMulInverse R := (NzRing_hasMulInverse R) (only parsing). #[short(type="unitRingType")] HB.structure Definition UnitRing := {R of NzRing_hasMulInverse R & NzRing R}. Module UnitRingExports. Bind Scope ring_scope with UnitRing.sort. End UnitRingExports. HB.export UnitRingExports. Definition unit_pred {R : unitRingType} := Eval cbv [ unit_subdef NzRing_hasMulInverse.unit_subdef ] in (fun u : R => unit_subdef u). Arguments unit_pred _ _ /. Definition unit {R : unitRingType} := [qualify a u : R | unit_pred u]. Local Notation "x ^-1" := (inv x). Local Notation "x / y" := (x * y^-1). Local Notation "x ^- n" := ((x ^+ n)^-1). Section UnitRingTheory. Variable R : unitRingType. Implicit Types x y : R. Lemma divrr : {in unit, right_inverse 1 (@inv R) *%R}. Proof. exact: divrr_subproof. Qed. Definition mulrV := divrr. Lemma mulVr : {in unit, left_inverse 1 (@inv R) *%R}. Proof. exact: mulVr_subproof. Qed. Lemma invr_out x : x \isn't a unit -> x^-1 = x. Proof. exact: invr_out_subproof. Qed. Lemma unitrP x : reflect (exists y, y * x = 1 /\ x * y = 1) (x \is a unit). Proof. apply: (iffP idP) => [Ux | []]; last exact: unitrP_subproof. by exists x^-1; rewrite divrr ?mulVr. Qed. Lemma mulKr : {in unit, left_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite mulrA mulVr ?mul1r. Qed. Lemma mulVKr : {in unit, rev_left_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite mulrA mulrV ?mul1r. Qed. Lemma mulrK : {in unit, right_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite -mulrA divrr ?mulr1. Qed. Lemma mulrVK : {in unit, rev_right_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite -mulrA mulVr ?mulr1. Qed. Definition divrK := mulrVK. Lemma mulrI : {in @unit R, right_injective *%R}. Proof. by move=> x Ux; apply: can_inj (mulKr Ux). Qed. Lemma mulIr : {in @unit R, left_injective *%R}. Proof. by move=> x Ux; apply: can_inj (mulrK Ux). Qed. (* Due to noncommutativity, fractions are inverted. *) Lemma telescope_prodr n m (f : nat -> R) : (forall k, n < k < m -> f k \is a unit) -> n < m -> \prod_(n <= k < m) (f k / f k.+1) = f n / f m. Proof. move=> Uf ltnm; rewrite (telescope_big (fun i j => f i / f j)) ?ltnm//. by move=> k ltnkm /=; rewrite mulrA divrK// Uf. Qed. Lemma telescope_prodr_eq n m (f u : nat -> R) : n < m -> (forall k, n < k < m -> f k \is a unit) -> (forall k, (n <= k < m)%N -> u k = f k / f k.+1) -> \prod_(n <= k < m) u k = f n / f m. Proof. by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodr. Qed. Lemma commrV x y : comm x y -> comm x y^-1. Proof. have [Uy cxy | /invr_out-> //] := boolP (y \in unit). by apply: (canLR (mulrK Uy)); rewrite -mulrA cxy mulKr. Qed. Lemma unitrE x : (x \is a unit) = (x / x == 1). Proof. apply/idP/eqP=> [Ux | xx1]; first exact: divrr. by apply/unitrP; exists x^-1; rewrite -commrV. Qed. Lemma invrK : involutive (@inv R). Proof. move=> x; case Ux: (x \in unit); last by rewrite !invr_out ?Ux. rewrite -(mulrK Ux _^-1) -mulrA commrV ?mulKr //. by apply/unitrP; exists x; rewrite divrr ?mulVr. Qed. Lemma invr_inj : injective (@inv R). Proof. exact: inv_inj invrK. Qed. Lemma unitrV x : (x^-1 \in unit) = (x \in unit). Proof. by rewrite !unitrE invrK commrV. Qed. Lemma unitr1 : 1 \in @unit R. Proof. by apply/unitrP; exists 1; rewrite mulr1. Qed. Lemma invr1 : 1^-1 = 1 :> R. Proof. by rewrite -{2}(mulVr unitr1) mulr1. Qed. Lemma div1r x : 1 / x = x^-1. Proof. by rewrite mul1r. Qed. Lemma divr1 x : x / 1 = x. Proof. by rewrite invr1 mulr1. Qed. Lemma natr_div m d : d %| m -> d%:R \is a @unit R -> (m %/ d)%:R = m%:R / d%:R :> R. Proof. by rewrite dvdn_eq => /eqP def_m unit_d; rewrite -{2}def_m natrM mulrK. Qed. Lemma divrI : {in unit, right_injective (fun x y => x / y)}. Proof. by move=> x /mulrI/inj_comp; apply; apply: invr_inj. Qed. Lemma divIr : {in unit, left_injective (fun x y => x / y)}. Proof. by move=> x; rewrite -unitrV => /mulIr. Qed. Lemma unitr0 : (0 \is a @unit R) = false. Proof. by apply/unitrP=> [[x [_ /esym/eqP]]]; rewrite mul0r oner_eq0. Qed. Lemma invr0 : 0^-1 = 0 :> R. Proof. by rewrite invr_out ?unitr0. Qed. Lemma unitrN1 : -1 \is a @unit R. Proof. by apply/unitrP; exists (-1); rewrite mulrNN mulr1. Qed. Lemma invrN1 : (-1)^-1 = -1 :> R. Proof. by rewrite -{2}(divrr unitrN1) mulN1r opprK. Qed. Lemma invr_sign n : ((-1) ^- n) = (-1) ^+ n :> R. Proof. by rewrite -signr_odd; case: (odd n); rewrite (invr1, invrN1). Qed. Lemma unitrMl x y : y \is a unit -> (x * y \is a unit) = (x \is a unit). Proof. move=> Uy; wlog Ux: x y Uy / x \is a unit => [WHxy|]. by apply/idP/idP=> Ux; first rewrite -(mulrK Uy x); rewrite WHxy ?unitrV. rewrite Ux; apply/unitrP; exists (y^-1 * x^-1). by rewrite -!mulrA mulKr ?mulrA ?mulrK ?divrr ?mulVr. Qed. Lemma unitrMr x y : x \is a unit -> (x * y \is a unit) = (y \is a unit). Proof. move=> Ux; apply/idP/idP=> [Uxy | Uy]; last by rewrite unitrMl. by rewrite -(mulKr Ux y) unitrMl ?unitrV. Qed. Lemma unitr_prod {I : Type} (P : pred I) (E : I -> R) (r : seq I) : (forall i, P i -> E i \is a GRing.unit) -> (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. by move=> Eunit; elim/big_rec: _ => [/[!unitr1] |i x /Eunit/unitrMr->]. Qed. Lemma unitr_prod_in {I : eqType} (P : pred I) (E : I -> R) (r : seq I) : {in r, forall i, P i -> E i \is a GRing.unit} -> (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. by rewrite big_seq_cond => H; apply: unitr_prod => i /andP[]; exact: H. Qed. Lemma invrM : {in unit &, forall x y, (x * y)^-1 = y^-1 * x^-1}. Proof. move=> x y Ux Uy; have Uxy: (x * y \in unit) by rewrite unitrMl. by apply: (mulrI Uxy); rewrite divrr ?mulrA ?mulrK ?divrr. Qed. Lemma unitrM_comm x y : comm x y -> (x * y \is a unit) = (x \is a unit) && (y \is a unit). Proof. move=> cxy; apply/idP/andP=> [Uxy | [Ux Uy]]; last by rewrite unitrMl. suffices Ux: x \in unit by rewrite unitrMr in Uxy. apply/unitrP; case/unitrP: Uxy => z [zxy xyz]; exists (y * z). rewrite mulrA xyz -{1}[y]mul1r -{1}zxy cxy -!mulrA (mulrA x) (mulrA _ z) xyz. by rewrite mul1r -cxy. Qed. Lemma unitrX x n : x \is a unit -> x ^+ n \is a unit. Proof. by move=> Ux; elim: n => [|n IHn]; rewrite ?unitr1 // exprS unitrMl. Qed. Lemma unitrX_pos x n : n > 0 -> (x ^+ n \in unit) = (x \in unit). Proof. case: n => // n _; rewrite exprS unitrM_comm; last exact: commrX. by case Ux: (x \is a unit); rewrite // unitrX. Qed. Lemma exprVn x n : x^-1 ^+ n = x ^- n. Proof. elim: n => [|n IHn]; first by rewrite !expr0 ?invr1. case Ux: (x \is a unit); first by rewrite exprSr exprS IHn -invrM // unitrX. by rewrite !invr_out ?unitrX_pos ?Ux. Qed. Lemma exprB m n x : n <= m -> x \is a unit -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. by move/subnK=> {2}<- Ux; rewrite exprD mulrK ?unitrX. Qed. Lemma invr_neq0 x : x != 0 -> x^-1 != 0. Proof. move=> nx0; case Ux: (x \is a unit); last by rewrite invr_out ?Ux. by apply/eqP=> x'0; rewrite -unitrV x'0 unitr0 in Ux. Qed. Lemma invr_eq0 x : (x^-1 == 0) = (x == 0). Proof. by apply: negb_inj; apply/idP/idP; move/invr_neq0; rewrite ?invrK. Qed. Lemma invr_eq1 x : (x^-1 == 1) = (x == 1). Proof. by rewrite (inv_eq invrK) invr1. Qed. Lemma rev_unitrP (x y : R^c) : y * x = 1 /\ x * y = 1 -> x \is a unit. Proof. by case=> [yx1 xy1]; apply/unitrP; exists y. Qed. #[export] HB.instance Definition _ := NzRing_hasMulInverse.Build R^c mulrV mulVr rev_unitrP invr_out. #[export] HB.instance Definition _ := UnitRing.on R^o. End UnitRingTheory. Arguments invrK {R}. Arguments invr_inj {R} [x1 x2]. Arguments telescope_prodr_eq {R n m} f u. Lemma rev_prodrV (R : unitRingType) (I : Type) (r : seq I) (P : pred I) (E : I -> R) : (forall i, P i -> E i \is a GRing.unit) -> \prod_(i <- r | P i) (E i)^-1 = ((\prod_(i <- r | P i) (E i : R^c))^-1). Proof. move=> Eunit; symmetry. apply: (big_morph_in GRing.unit _ _ (unitr1 R^c) (@invrM _) (invr1 _)) Eunit. by move=> x y xunit; rewrite unitrMr. Qed. Section UnitRingClosedPredicates. Variables (R : unitRingType) (S : {pred R}). Definition invr_closed := {in S, forall x, x^-1 \in S}. Definition divr_2closed := {in S &, forall x y, x / y \in S}. Definition divr_closed := 1 \in S /\ divr_2closed. Definition sdivr_closed := -1 \in S /\ divr_2closed. Definition divring_closed := [/\ 1 \in S, subr_2closed S & divr_2closed]. Lemma divr_closedV : divr_closed -> invr_closed. Proof. by case=> S1 Sdiv x Sx; rewrite -[x^-1]mul1r Sdiv. Qed. Lemma divr_closedM : divr_closed -> mulr_closed S. Proof. by case=> S1 Sdiv; split=> // x y Sx Sy; rewrite -[y]invrK -[y^-1]mul1r !Sdiv. Qed. Lemma sdivr_closed_div : sdivr_closed -> divr_closed. Proof. by case=> SN1 Sdiv; split; rewrite // -(divrr (@unitrN1 _)) Sdiv. Qed. Lemma sdivr_closedM : sdivr_closed -> smulr_closed S. Proof. by move=> Sdiv; have [_ SM] := divr_closedM (sdivr_closed_div Sdiv); case: Sdiv. Qed. Lemma divring_closedBM : divring_closed -> subring_closed S. Proof. by case=> S1 SB Sdiv; split=> //; case: divr_closedM. Qed. Lemma divring_closed_div : divring_closed -> sdivr_closed. Proof. case=> S1 SB Sdiv; split; rewrite ?zmod_closedN //. exact/subring_closedB/divring_closedBM. Qed. End UnitRingClosedPredicates. Section UnitRingMorphism. Variables (R S : unitRingType) (f : {rmorphism R -> S}). Lemma rmorph_unit x : x \in unit -> f x \in unit. Proof. case/unitrP=> y [yx1 xy1]; apply/unitrP. by exists (f y); rewrite -!rmorphM // yx1 xy1 rmorph1. Qed. Lemma rmorphV : {in unit, {morph f: x / x^-1}}. Proof. move=> x Ux; rewrite /= -[(f x)^-1]mul1r. by apply: (canRL (mulrK (rmorph_unit Ux))); rewrite -rmorphM mulVr ?rmorph1. Qed. Lemma rmorph_div x y : y \in unit -> f (x / y) = f x / f y. Proof. by move=> Uy; rewrite rmorphM /= rmorphV. Qed. End UnitRingMorphism. #[short(type="comUnitRingType")] HB.structure Definition ComUnitRing := {R of ComNzRing R & UnitRing R}. Module ComUnitRingExports. Bind Scope ring_scope with ComUnitRing.sort. End ComUnitRingExports. HB.export ComUnitRingExports. (* TODO_HB: fix the name (was ComUnitRingMixin) *) HB.factory Record ComNzRing_hasMulInverse R of ComNzRing R := { unit : {pred R}; inv : R -> R; mulVx : {in unit, left_inverse 1 inv *%R}; unitPl : forall x y, y * x = 1 -> unit x; invr_out : {in [predC unit], inv =1 id} }. Module ComRing_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_hasMulInverse.Build instead.")] Notation Build R := (ComNzRing_hasMulInverse.Build R) (only parsing). End ComRing_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_hasMulInverse instead.")] Notation ComRing_hasMulInverse R := (ComNzRing_hasMulInverse R) (only parsing). HB.builders Context R of ComNzRing_hasMulInverse R. Fact mulC_mulrV : {in unit, right_inverse 1 inv *%R}. Proof. by move=> x Ux /=; rewrite mulrC mulVx. Qed. Fact mulC_unitP x y : y * x = 1 /\ x * y = 1 -> unit x. Proof. by case=> yx _; apply: unitPl yx. Qed. HB.instance Definition _ := NzRing_hasMulInverse.Build R mulVx mulC_mulrV mulC_unitP invr_out. HB.end. #[short(type="unitAlgType")] HB.structure Definition UnitAlgebra R := {V of Algebra R V & UnitRing V}. Module UnitAlgebraExports. Bind Scope ring_scope with UnitAlgebra.sort. End UnitAlgebraExports. HB.export UnitAlgebraExports. #[short(type="comUnitAlgType")] HB.structure Definition ComUnitAlgebra R := {V of ComAlgebra R V & UnitRing V}. Module ComUnitAlgebraExports. Bind Scope ring_scope with UnitAlgebra.sort. End ComUnitAlgebraExports. HB.export ComUnitAlgebraExports. Section ComUnitRingTheory. Variable R : comUnitRingType. Implicit Types x y : R. Lemma unitrM x y : (x * y \in unit) = (x \in unit) && (y \in unit). Proof. exact/unitrM_comm/mulrC. Qed. Lemma unitrPr x : reflect (exists y, x * y = 1) (x \in unit). Proof. by apply: (iffP (unitrP x)) => [[y []] | [y]]; exists y; rewrite // mulrC. Qed. Lemma mulr1_eq x y : x * y = 1 -> x^-1 = y. Proof. by move=> xy_eq1; rewrite -[LHS]mulr1 -xy_eq1; apply/mulKr/unitrPr; exists y. Qed. Lemma divr1_eq x y : x / y = 1 -> x = y. Proof. by move/mulr1_eq/invr_inj. Qed. Lemma divKr x : x \is a unit -> {in unit, involutive (fun y => x / y)}. Proof. by move=> Ux y Uy; rewrite /= invrM ?unitrV // invrK mulrC divrK. Qed. Lemma expr_div_n x y n : (x / y) ^+ n = x ^+ n / y ^+ n. Proof. by rewrite exprMn exprVn. Qed. Lemma unitr_prodP (I : eqType) (r : seq I) (P : pred I) (E : I -> R) : reflect {in r, forall i, P i -> E i \is a GRing.unit} (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. rewrite (big_morph [in unit] unitrM (@unitr1 _) ) big_all_cond. exact: 'all_implyP. Qed. Lemma prodrV (I : eqType) (r : seq I) (P : pred I) (E : I -> R) : (forall i, P i -> E i \is a GRing.unit) -> \prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1. Proof. by move=> /rev_prodrV->; rewrite rev_prodr (perm_big r)// perm_rev. Qed. (* TODO: HB.saturate *) #[export] HB.instance Definition _ := ComUnitRing.on R^c. #[export] HB.instance Definition _ := ComUnitRing.on R^o. (* /TODO *) End ComUnitRingTheory. Section UnitAlgebraTheory. Variable (R : comUnitRingType) (A : unitAlgType R). Implicit Types (k : R) (x y : A). Lemma scaler_injl : {in unit, @right_injective R A A *:%R}. Proof. move=> k Uk x1 x2 Hx1x2. by rewrite -[x1]scale1r -(mulVr Uk) -scalerA Hx1x2 scalerA mulVr // scale1r. Qed. Lemma scaler_unit k x : k \in unit -> (k *: x \in unit) = (x \in unit). Proof. move=> Uk; apply/idP/idP=> [Ukx | Ux]; apply/unitrP; last first. exists (k^-1 *: x^-1). by rewrite -!scalerAl -!scalerAr !scalerA !mulVr // !mulrV // scale1r. exists (k *: (k *: x)^-1); split. apply: (mulrI Ukx). by rewrite mulr1 mulrA -scalerAr mulrV // -scalerAl mul1r. apply: (mulIr Ukx). by rewrite mul1r -mulrA -scalerAl mulVr // -scalerAr mulr1. Qed. Lemma invrZ k x : k \in unit -> x \in unit -> (k *: x)^-1 = k^-1 *: x^-1. Proof. move=> Uk Ux; have Ukx: (k *: x \in unit) by rewrite scaler_unit. apply: (mulIr Ukx). by rewrite mulVr // -scalerAl -scalerAr scalerA !mulVr // scale1r. Qed. Section ClosedPredicates. Variables S : {pred A}. Definition divalg_closed := [/\ 1 \in S, linear_closed S & divr_2closed S]. Lemma divalg_closedBdiv : divalg_closed -> divring_closed S. Proof. by case=> S1 /linear_closedB. Qed. Lemma divalg_closedZ : divalg_closed -> subalg_closed S. Proof. by case=> S1 Slin Sdiv; split=> //; have [] := @divr_closedM A S. Qed. End ClosedPredicates. End UnitAlgebraTheory. Module ClosedExports. Notation addr_closed := nmod_closed. Notation oppr_closed := oppr_closed. Notation zmod_closed := zmod_closed. Notation mulr_closed := mulr_closed. Notation semiring_closed := semiring_closed. Notation smulr_closed := smulr_closed. Notation subring_closed := subring_closed. Notation scaler_closed := scaler_closed. Notation subsemimod_closed := subsemimod_closed. Notation linear_closed := linear_closed. Notation submod_closed := submod_closed. Notation subalg_closed := subalg_closed. Notation invr_closed := invr_closed. Notation divr_2closed := divr_2closed. Notation divr_closed := divr_closed. Notation sdivr_closed := sdivr_closed. Notation divring_closed := divring_closed. Notation divalg_closed := divalg_closed. Coercion zmod_closedD : zmod_closed >-> nmod_closed. Coercion zmod_closedN : zmod_closed >-> oppr_closed. Coercion semiring_closedD : semiring_closed >-> addr_closed. Coercion semiring_closedM : semiring_closed >-> mulr_closed. Coercion smulr_closedM : smulr_closed >-> mulr_closed. Coercion smulr_closedN : smulr_closed >-> oppr_closed. Coercion subring_closedB : subring_closed >-> zmod_closed. Coercion subring_closedM : subring_closed >-> smulr_closed. Coercion subring_closed_semi : subring_closed >-> semiring_closed. Coercion subsemimod_closedD : subsemimod_closed >-> addr_closed. Coercion subsemimod_closedZ : subsemimod_closed >-> scaler_closed. Coercion linear_closedB : linear_closed >-> subr_2closed. Coercion submod_closedB : submod_closed >-> zmod_closed. Coercion submod_closed_semi : submod_closed >-> subsemimod_closed. Coercion subalg_closedZ : subalg_closed >-> submod_closed. Coercion subalg_closedBM : subalg_closed >-> subring_closed. Coercion divr_closedV : divr_closed >-> invr_closed. Coercion divr_closedM : divr_closed >-> mulr_closed. Coercion sdivr_closed_div : sdivr_closed >-> divr_closed. Coercion sdivr_closedM : sdivr_closed >-> smulr_closed. Coercion divring_closedBM : divring_closed >-> subring_closed. Coercion divring_closed_div : divring_closed >-> sdivr_closed. Coercion divalg_closedBdiv : divalg_closed >-> divring_closed. Coercion divalg_closedZ : divalg_closed >-> subalg_closed. End ClosedExports. (* Reification of the theory of rings with units, in named style *) Section TermDef. Variable R : Type. Inductive term : Type := | Var of nat | Const of R | NatConst of nat | Add of term & term | Opp of term | NatMul of term & nat | Mul of term & term | Inv of term | Exp of term & nat. Inductive formula : Type := | Bool of bool | Equal of term & term | Unit of term | And of formula & formula | Or of formula & formula | Implies of formula & formula | Not of formula | Exists of nat & formula | Forall of nat & formula. End TermDef. Bind Scope term_scope with term. Bind Scope term_scope with formula. Arguments Add {R} t1%_T t2%_T. Arguments Opp {R} t1%_T. Arguments NatMul {R} t1%_T n%_N. Arguments Mul {R} t1%_T t2%_T. Arguments Inv {R} t1%_T. Arguments Exp {R} t1%_T n%_N. Arguments Equal {R} t1%_T t2%_T. Arguments Unit {R} t1%_T. Arguments And {R} f1%_T f2%_T. Arguments Or {R} f1%_T f2%_T. Arguments Implies {R} f1%_T f2%_T. Arguments Not {R} f1%_T. Arguments Exists {R} i%_N f1%_T. Arguments Forall {R} i%_N f1%_T. Arguments Bool {R} b. Arguments Const {R} x. Notation True := (Bool true). Notation False := (Bool false). Local Notation "''X_' i" := (Var _ i) : term_scope. Local Notation "n %:R" := (NatConst _ n) : term_scope. Local Notation "x %:T" := (Const x) : term_scope. Local Notation "0" := 0%:R%T : term_scope. Local Notation "1" := 1%:R%T : term_scope. Local Infix "+" := Add : term_scope. Local Notation "- t" := (Opp t) : term_scope. Local Notation "t - u" := (Add t (- u)) : term_scope. Local Infix "*" := Mul : term_scope. Local Infix "*+" := NatMul : term_scope. Local Notation "t ^-1" := (Inv t) : term_scope. Local Notation "t / u" := (Mul t u^-1) : term_scope. Local Infix "^+" := Exp : term_scope. Local Infix "==" := Equal : term_scope. Local Infix "/\" := And : term_scope. Local Infix "\/" := Or : term_scope. Local Infix "==>" := Implies : term_scope. Local Notation "~ f" := (Not f) : term_scope. Local Notation "x != y" := (Not (x == y)) : term_scope. Local Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope. Local Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope. Section Substitution. Variable R : Type. Fixpoint tsubst (t : term R) (s : nat * term R) := match t with | 'X_i => if i == s.1 then s.2 else t | _%:T | _%:R => t | t1 + t2 => tsubst t1 s + tsubst t2 s | - t1 => - tsubst t1 s | t1 *+ n => tsubst t1 s *+ n | t1 * t2 => tsubst t1 s * tsubst t2 s | t1^-1 => (tsubst t1 s)^-1 | t1 ^+ n => tsubst t1 s ^+ n end%T. Fixpoint fsubst (f : formula R) (s : nat * term R) := match f with | Bool _ => f | t1 == t2 => tsubst t1 s == tsubst t2 s | Unit t1 => Unit (tsubst t1 s) | f1 /\ f2 => fsubst f1 s /\ fsubst f2 s | f1 \/ f2 => fsubst f1 s \/ fsubst f2 s | f1 ==> f2 => fsubst f1 s ==> fsubst f2 s | ~ f1 => ~ fsubst f1 s | ('exists 'X_i, f1) => 'exists 'X_i, if i == s.1 then f1 else fsubst f1 s | ('forall 'X_i, f1) => 'forall 'X_i, if i == s.1 then f1 else fsubst f1 s end%T. End Substitution. Section EvalTerm. Variable R : unitRingType. (* Evaluation of a reified term into R a ring with units *) Fixpoint eval (e : seq R) (t : term R) {struct t} : R := match t with | ('X_i)%T => e`_i | (x%:T)%T => x | (n%:R)%T => n%:R | (t1 + t2)%T => eval e t1 + eval e t2 | (- t1)%T => - eval e t1 | (t1 *+ n)%T => eval e t1 *+ n | (t1 * t2)%T => eval e t1 * eval e t2 | t1^-1%T => (eval e t1)^-1 | (t1 ^+ n)%T => eval e t1 ^+ n end. Definition same_env (e e' : seq R) := nth 0 e =1 nth 0 e'. Lemma eq_eval e e' t : same_env e e' -> eval e t = eval e' t. Proof. by move=> eq_e; elim: t => //= t1 -> // t2 ->. Qed. Lemma eval_tsubst e t s : eval e (tsubst t s) = eval (set_nth 0 e s.1 (eval e s.2)) t. Proof. case: s => i u; elim: t => //=; do 2?[move=> ? -> //] => j. by rewrite nth_set_nth /=; case: (_ == _). Qed. (* Evaluation of a reified formula *) Fixpoint holds (e : seq R) (f : formula R) {struct f} : Prop := match f with | Bool b => b | (t1 == t2)%T => eval e t1 = eval e t2 | Unit t1 => eval e t1 \in unit | (f1 /\ f2)%T => holds e f1 /\ holds e f2 | (f1 \/ f2)%T => holds e f1 \/ holds e f2 | (f1 ==> f2)%T => holds e f1 -> holds e f2 | (~ f1)%T => ~ holds e f1 | ('exists 'X_i, f1)%T => exists x, holds (set_nth 0 e i x) f1 | ('forall 'X_i, f1)%T => forall x, holds (set_nth 0 e i x) f1 end. Lemma same_env_sym e e' : same_env e e' -> same_env e' e. Proof. exact: fsym. Qed. (* Extensionality of formula evaluation *) Lemma eq_holds e e' f : same_env e e' -> holds e f -> holds e' f. Proof. pose sv := set_nth (0 : R). have eq_i i v e1 e2: same_env e1 e2 -> same_env (sv e1 i v) (sv e2 i v). by move=> eq_e j; rewrite !nth_set_nth /= eq_e. elim: f e e' => //=. - by move=> t1 t2 e e' eq_e; rewrite !(eq_eval _ eq_e). - by move=> t e e' eq_e; rewrite (eq_eval _ eq_e). - by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto. - by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto. - by move=> f1 IH1 f2 IH2 e e' eq_e f12; move/IH1: (same_env_sym eq_e); eauto. - by move=> f1 IH1 e e'; move/same_env_sym; move/IH1; tauto. - by move=> i f1 IH1 e e'; move/(eq_i i)=> eq_e [x f_ex]; exists x; eauto. by move=> i f1 IH1 e e'; move/(eq_i i); eauto. Qed. (* Evaluation and substitution by a constant *) Lemma holds_fsubst e f i v : holds e (fsubst f (i, v%:T)%T) <-> holds (set_nth 0 e i v) f. Proof. elim: f e => //=; do [ by move=> *; rewrite !eval_tsubst | move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto | move=> f IHf e; move: (IHf e); tauto | move=> j f IHf e]. - case eq_ji: (j == i); first rewrite (eqP eq_ji). by split=> [] [x f_x]; exists x; rewrite set_set_nth eqxx in f_x *. split=> [] [x f_x]; exists x; move: f_x; rewrite set_set_nth eq_sym eq_ji; have:= IHf (set_nth 0 e j x); tauto. case eq_ji: (j == i); first rewrite (eqP eq_ji). by split=> [] f_ x; move: (f_ x); rewrite set_set_nth eqxx. split=> [] f_ x; move: (IHf (set_nth 0 e j x)) (f_ x); by rewrite set_set_nth 1?[i == j]eq_sym eq_ji; tauto. Qed. (* Boolean test selecting terms in the language of rings *) Fixpoint rterm (t : term R) := match t with | _^-1 => false | t1 + t2 | t1 * t2 => rterm t1 && rterm t2 | - t1 | t1 *+ _ | t1 ^+ _ => rterm t1 | _ => true end%T. (* Boolean test selecting formulas in the theory of rings *) Fixpoint rformula (f : formula R) := match f with | Bool _ => true | t1 == t2 => rterm t1 && rterm t2 | Unit t1 => false | f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => rformula f1 && rformula f2 | ~ f1 | ('exists 'X__, f1) | ('forall 'X__, f1) => rformula f1 end%T. (* Upper bound of the names used in a term *) Fixpoint ub_var (t : term R) := match t with | 'X_i => i.+1 | t1 + t2 | t1 * t2 => maxn (ub_var t1) (ub_var t2) | - t1 | t1 *+ _ | t1 ^+ _ | t1^-1 => ub_var t1 | _ => 0%N end%T. (* Replaces inverses in the term t by fresh variables, accumulating the *) (* substitution. *) Fixpoint to_rterm (t : term R) (r : seq (term R)) (n : nat) {struct t} := match t with | t1^-1 => let: (t1', r1) := to_rterm t1 r n in ('X_(n + size r1), rcons r1 t1') | t1 + t2 => let: (t1', r1) := to_rterm t1 r n in let: (t2', r2) := to_rterm t2 r1 n in (t1' + t2', r2) | - t1 => let: (t1', r1) := to_rterm t1 r n in (- t1', r1) | t1 *+ m => let: (t1', r1) := to_rterm t1 r n in (t1' *+ m, r1) | t1 * t2 => let: (t1', r1) := to_rterm t1 r n in let: (t2', r2) := to_rterm t2 r1 n in (Mul t1' t2', r2) | t1 ^+ m => let: (t1', r1) := to_rterm t1 r n in (t1' ^+ m, r1) | _ => (t, r) end%T. Lemma to_rterm_id t r n : rterm t -> to_rterm t r n = (t, r). Proof. elim: t r n => //. - by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2. - by move=> t IHt r n /= rt; rewrite {}IHt. - by move=> t IHt r n m /= rt; rewrite {}IHt. - by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2. - by move=> t IHt r n m /= rt; rewrite {}IHt. Qed. (* A ring formula stating that t1 is equal to 0 in the ring theory. *) (* Also applies to non commutative rings. *) Definition eq0_rform t1 := let m := ub_var t1 in let: (t1', r1) := to_rterm t1 [::] m in let fix loop r i := match r with | [::] => t1' == 0 | t :: r' => let f := 'X_i * t == 1 /\ t * 'X_i == 1 in 'forall 'X_i, (f \/ 'X_i == t /\ ~ ('exists 'X_i, f)) ==> loop r' i.+1 end%T in loop r1 m. (* Transformation of a formula in the theory of rings with units into an *) (* equivalent formula in the sub-theory of rings. *) Fixpoint to_rform f := match f with | Bool b => f | t1 == t2 => eq0_rform (t1 - t2) | Unit t1 => eq0_rform (t1 * t1^-1 - 1) | f1 /\ f2 => to_rform f1 /\ to_rform f2 | f1 \/ f2 => to_rform f1 \/ to_rform f2 | f1 ==> f2 => to_rform f1 ==> to_rform f2 | ~ f1 => ~ to_rform f1 | ('exists 'X_i, f1) => 'exists 'X_i, to_rform f1 | ('forall 'X_i, f1) => 'forall 'X_i, to_rform f1 end%T. (* The transformation gives a ring formula. *) Lemma to_rform_rformula f : rformula (to_rform f). Proof. suffices eq0_ring t1: rformula (eq0_rform t1) by elim: f => //= => f1 ->. rewrite /eq0_rform; move: (ub_var t1) => m; set tr := _ m. suffices: all rterm (tr.1 :: tr.2). case: tr => {}t1 r /= /andP[t1_r]. by elim: r m => [|t r IHr] m; rewrite /= ?andbT // => /andP[->]; apply: IHr. have: all rterm [::] by []. rewrite {}/tr; elim: t1 [::] => //=. - move=> t1 IHt1 t2 IHt2 r. move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r]. move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r]. by rewrite t1_r t2_r. - by move=> t1 IHt1 r /IHt1; case: to_rterm. - by move=> t1 IHt1 n r /IHt1; case: to_rterm. - move=> t1 IHt1 t2 IHt2 r. move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r]. move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r]. by rewrite t1_r t2_r. - move=> t1 IHt1 r. by move/IHt1; case: to_rterm => {r IHt1}t1 r /=; rewrite all_rcons. - by move=> t1 IHt1 n r /IHt1; case: to_rterm. Qed. (* Correctness of the transformation. *) Lemma to_rformP e f : holds e (to_rform f) <-> holds e f. Proof. suffices{e f} equal0_equiv e t1 t2: holds e (eq0_rform (t1 - t2)) <-> (eval e t1 == eval e t2). - elim: f e => /=; try tauto. + move=> t1 t2 e. by split; [move/equal0_equiv/eqP | move/eqP/equal0_equiv]. + by move=> t1 e; rewrite unitrE; apply: equal0_equiv. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 e; move: (IHf1 e); tauto. + by move=> n f1 IHf1 e; split=> [] [x] /IHf1; exists x. + by move=> n f1 IHf1 e; split=> Hx x; apply/IHf1. rewrite -(add0r (eval e t2)) -(can2_eq (subrK _) (addrK _)). rewrite -/(eval e (t1 - t2)); move: (t1 - t2)%T => {t1 t2} t. have sub_var_tsubst s t0: s.1 >= ub_var t0 -> tsubst t0 s = t0. elim: t0 {t} => //=. - by move=> n; case: ltngtP. - by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->]. - by move=> t1 IHt1 /IHt1->. - by move=> t1 IHt1 n /IHt1->. - by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->]. - by move=> t1 IHt1 /IHt1->. - by move=> t1 IHt1 n /IHt1->. pose fix rsub t' m r : term R := if r is u :: r' then tsubst (rsub t' m.+1 r') (m, u^-1)%T else t'. pose fix ub_sub m r : Prop := if r is u :: r' then ub_var u <= m /\ ub_sub m.+1 r' else true. suffices{t} rsub_to_r t r0 m: m >= ub_var t -> ub_sub m r0 -> let: (t', r) := to_rterm t r0 m in [/\ take (size r0) r = r0, ub_var t' <= m + size r, ub_sub m r & rsub t' m r = t]. - have:= rsub_to_r t [::] _ (leqnn _); rewrite /eq0_rform. case: (to_rterm _ _ _) => [t1' r1] [//|_ _ ub_r1 def_t]. rewrite -{2}def_t {def_t}. elim: r1 (ub_var t) e ub_r1 => [|u r1 IHr1] m e /= => [_|[ub_u ub_r1]]. by split=> /eqP. rewrite eval_tsubst /=; set y := eval e u; split=> t_eq0. apply/IHr1=> //; apply: t_eq0. rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)). rewrite sub_var_tsubst //= -/y. case Uy: (y \in unit); [left | right]; first by rewrite mulVr ?divrr. split=> [|[z]]; first by rewrite invr_out ?Uy. rewrite nth_set_nth /= eqxx. rewrite -!(eval_tsubst _ _ (m, Const _)) !sub_var_tsubst // -/y => yz1. by case/unitrP: Uy; exists z. move=> x def_x; apply/IHr1=> //; suff ->: x = y^-1 by []; move: def_x. rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)). rewrite sub_var_tsubst //= -/y; case=> [[xy1 yx1] | [xy nUy]]. by rewrite -[y^-1]mul1r -[1]xy1 mulrK //; apply/unitrP; exists x. rewrite invr_out //; apply/unitrP=> [[z yz1]]; case: nUy; exists z. rewrite nth_set_nth /= eqxx -!(eval_tsubst _ _ (m, _%:T)%T). by rewrite !sub_var_tsubst. have rsub_id r t0 n: ub_var t0 <= n -> rsub t0 n r = t0. by elim: r n => //= t1 r IHr n let0n; rewrite IHr ?sub_var_tsubst ?leqW. have rsub_acc r s t1 m1: ub_var t1 <= m1 + size r -> rsub t1 m1 (r ++ s) = rsub t1 m1 r. elim: r t1 m1 => [|t1 r IHr] t2 m1 /=; first by rewrite addn0; apply: rsub_id. by move=> letmr; rewrite IHr ?addSnnS. elim: t r0 m => /=; try do [ by move=> n r m hlt hub; rewrite take_size (ltn_addr _ hlt) rsub_id | by move=> n r m hlt hub; rewrite leq0n take_size rsub_id | move=> t1 IHt1 t2 IHt2 r m; rewrite geq_max; case/andP=> hub1 hub2 hmr; case: to_rterm {hub1 hmr}(IHt1 r m hub1 hmr) => t1' r1; case=> htake1 hub1' hsub1 <-; case: to_rterm {IHt2 hub2 hsub1}(IHt2 r1 m hub2 hsub1) => t2' r2 /=; rewrite geq_max; case=> htake2 -> hsub2 /= <-; rewrite -{1 2}(cat_take_drop (size r1) r2) htake2; set r3 := drop _ _; rewrite size_cat addnA (leq_trans _ (leq_addr _ _)) //; split=> {hsub2}//; first by [rewrite takel_cat // -htake1 size_take geq_min leqnn orbT]; rewrite -(rsub_acc r1 r3 t1') {hub1'}// -{htake1}htake2 {r3}cat_take_drop; by elim: r2 m => //= u r2 IHr2 m; rewrite IHr2 | do [ move=> t1 IHt1 r m; do 2!move=> /IHt1{}IHt1 | move=> t1 IHt1 n r m; do 2!move=> /IHt1{}IHt1]; case: to_rterm IHt1 => t1' r1 [-> -> hsub1 <-]; split=> {hsub1}//; by elim: r1 m => //= u r1 IHr1 m; rewrite IHr1]. move=> t1 IH r m letm /IH {IH} /(_ letm) {letm}. case: to_rterm => t1' r1 /= [def_r ub_t1' ub_r1 <-]. rewrite size_rcons addnS leqnn -{1}cats1 takel_cat ?def_r; last first. by rewrite -def_r size_take geq_min leqnn orbT. elim: r1 m ub_r1 ub_t1' {def_r} => /= [|u r1 IHr1] m => [_|[->]]. by rewrite addn0 eqxx. by rewrite -addSnnS => /IHr1 IH /IH[_ _ ub_r1 ->]. Qed. (* Boolean test selecting formulas which describe a constructible set, *) (* i.e. formulas without quantifiers. *) (* The quantifier elimination check. *) Fixpoint qf_form (f : formula R) := match f with | Bool _ | _ == _ | Unit _ => true | f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => qf_form f1 && qf_form f2 | ~ f1 => qf_form f1 | _ => false end%T. (* Boolean holds predicate for quantifier free formulas *) Definition qf_eval e := fix loop (f : formula R) : bool := match f with | Bool b => b | t1 == t2 => (eval e t1 == eval e t2)%bool | Unit t1 => eval e t1 \in unit | f1 /\ f2 => loop f1 && loop f2 | f1 \/ f2 => loop f1 || loop f2 | f1 ==> f2 => (loop f1 ==> loop f2)%bool | ~ f1 => ~~ loop f1 |_ => false end%T. (* qf_eval is equivalent to holds *) Lemma qf_evalP e f : qf_form f -> reflect (holds e f) (qf_eval e f). Proof. elim: f => //=; try by move=> *; apply: idP. - by move=> t1 t2 _; apply: eqP. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by right; case. by case/IHf2; [left | right; case]. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1F]; first by do 2 left. by case/IHf2; [left; right | right; case]. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by left. by case/IHf2; [left | right; move/(_ f1T)]. by move=> f1 IHf1 /IHf1[]; [right | left]. Qed. Implicit Type bc : seq (term R) * seq (term R). (* Quantifier-free formula are normalized into DNF. A DNF is *) (* represented by the type seq (seq (term R) * seq (term R)), where we *) (* separate positive and negative literals *) (* DNF preserving conjunction *) Definition and_dnf bcs1 bcs2 := \big[cat/nil]_(bc1 <- bcs1) map (fun bc2 => (bc1.1 ++ bc2.1, bc1.2 ++ bc2.2)) bcs2. (* Computes a DNF from a qf ring formula *) Fixpoint qf_to_dnf (f : formula R) (neg : bool) {struct f} := match f with | Bool b => if b (+) neg then [:: ([::], [::])] else [::] | t1 == t2 => [:: if neg then ([::], [:: t1 - t2]) else ([:: t1 - t2], [::])] | f1 /\ f2 => (if neg then cat else and_dnf) [rec f1, neg] [rec f2, neg] | f1 \/ f2 => (if neg then and_dnf else cat) [rec f1, neg] [rec f2, neg] | f1 ==> f2 => (if neg then and_dnf else cat) [rec f1, ~~ neg] [rec f2, neg] | ~ f1 => [rec f1, ~~ neg] | _ => if neg then [:: ([::], [::])] else [::] end%T where "[ 'rec' f , neg ]" := (qf_to_dnf f neg). (* Conversely, transforms a DNF into a formula *) Definition dnf_to_form := let pos_lit t := And (t == 0) in let neg_lit t := And (t != 0) in let cls bc := Or (foldr pos_lit True bc.1 /\ foldr neg_lit True bc.2) in foldr cls False. (* Catenation of dnf is the Or of formulas *) Lemma cat_dnfP e bcs1 bcs2 : qf_eval e (dnf_to_form (bcs1 ++ bcs2)) = qf_eval e (dnf_to_form bcs1 \/ dnf_to_form bcs2). Proof. by elim: bcs1 => //= bc1 bcs1 IH1; rewrite -orbA; congr orb; rewrite IH1. Qed. (* and_dnf is the And of formulas *) Lemma and_dnfP e bcs1 bcs2 : qf_eval e (dnf_to_form (and_dnf bcs1 bcs2)) = qf_eval e (dnf_to_form bcs1 /\ dnf_to_form bcs2). Proof. elim: bcs1 => [|bc1 bcs1 IH1] /=; first by rewrite /and_dnf big_nil. rewrite /and_dnf big_cons -/(and_dnf bcs1 bcs2) cat_dnfP /=. rewrite {}IH1 /= andb_orl; congr orb. elim: bcs2 bc1 {bcs1} => [|bc2 bcs2 IH] bc1 /=; first by rewrite andbF. rewrite {}IH /= andb_orr; congr orb => {bcs2}. suffices aux (l1 l2 : seq (term R)) g : let redg := foldr (And \o g) True in qf_eval e (redg (l1 ++ l2)) = qf_eval e (redg l1 /\ redg l2)%T. + by rewrite 2!aux /= 2!andbA -andbA -andbCA andbA andbCA andbA. by elim: l1 => [| t1 l1 IHl1] //=; rewrite -andbA IHl1. Qed. Lemma qf_to_dnfP e : let qev f b := qf_eval e (dnf_to_form (qf_to_dnf f b)) in forall f, qf_form f && rformula f -> qev f false = qf_eval e f. Proof. move=> qev; have qevT f: qev f true = ~~ qev f false. rewrite {}/qev; elim: f => //=; do [by case | move=> f1 IH1 f2 IH2 | ]. - by move=> t1 t2; rewrite !andbT !orbF. - by rewrite and_dnfP cat_dnfP negb_and -IH1 -IH2. - by rewrite and_dnfP cat_dnfP negb_or -IH1 -IH2. - by rewrite and_dnfP cat_dnfP /= negb_or IH1 -IH2 negbK. by move=> t1 ->; rewrite negbK. rewrite /qev; elim=> //=; first by case. - by move=> t1 t2 _; rewrite subr_eq0 !andbT orbF. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite and_dnfP /= => /IH1-> /IH2->. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite cat_dnfP /= => /IH1-> => /IH2->. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite cat_dnfP /= [qf_eval _ _]qevT -implybE => /IH1 <- /IH2->. by move=> f1 IH1 /IH1 <-; rewrite -qevT. Qed. Lemma dnf_to_form_qf bcs : qf_form (dnf_to_form bcs). Proof. by elim: bcs => //= [[clT clF] _ ->] /=; elim: clT => //=; elim: clF. Qed. Definition dnf_rterm cl := all rterm cl.1 && all rterm cl.2. Lemma qf_to_dnf_rterm f b : rformula f -> all dnf_rterm (qf_to_dnf f b). Proof. set ok := all dnf_rterm. have cat_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (bcs1 ++ bcs2). by move=> ok1 ok2; rewrite [ok _]all_cat; apply/andP. have and_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (and_dnf bcs1 bcs2). rewrite /and_dnf unlock; elim: bcs1 => //= cl1 bcs1 IH1; rewrite -andbA. case/and3P=> ok11 ok12 ok1 ok2; rewrite cat_ok ?{}IH1 {bcs1 ok1}//. elim: bcs2 ok2 => //= cl2 bcs2 IH2 /andP[ok2 /IH2->]. by rewrite /dnf_rterm !all_cat ok11 ok12 /= !andbT. elim: f b => //=; [ by do 2!case | | | | | by auto | | ]; try by repeat case/andP || intro; case: ifP; auto. by rewrite /dnf_rterm => ?? [] /= ->. Qed. Lemma dnf_to_rform bcs : rformula (dnf_to_form bcs) = all dnf_rterm bcs. Proof. elim: bcs => //= [[cl1 cl2] bcs ->]; rewrite {2}/dnf_rterm /=; congr (_ && _). by (congr andb; [elim: cl1 | elim: cl2]) => //= t cl ->; rewrite andbT. Qed. Section If. Variables (pred_f then_f else_f : formula R). Definition If := (pred_f /\ then_f \/ ~ pred_f /\ else_f)%T. Lemma If_form_qf : qf_form pred_f -> qf_form then_f -> qf_form else_f -> qf_form If. Proof. by move=> /= -> -> ->. Qed. Lemma If_form_rf : rformula pred_f -> rformula then_f -> rformula else_f -> rformula If. Proof. by move=> /= -> -> ->. Qed. Lemma eval_If e : let ev := qf_eval e in ev If = (if ev pred_f then ev then_f else ev else_f). Proof. by rewrite /=; case: ifP => _; rewrite ?orbF. Qed. End If. Section Pick. Variables (I : finType) (pred_f then_f : I -> formula R) (else_f : formula R). Definition Pick := \big[Or/False]_(p : {ffun pred I}) ((\big[And/True]_i (if p i then pred_f i else ~ pred_f i)) /\ (if pick p is Some i then then_f i else else_f))%T. Lemma Pick_form_qf : (forall i, qf_form (pred_f i)) -> (forall i, qf_form (then_f i)) -> qf_form else_f -> qf_form Pick. Proof. move=> qfp qft qfe; have mA := (big_morph qf_form) true andb. rewrite mA // big1 //= => p _. rewrite mA // big1 => [|i _]; first by case: pick. by rewrite fun_if if_same /= qfp. Qed. Lemma eval_Pick e (qev := qf_eval e) : let P i := qev (pred_f i) in qev Pick = (if pick P is Some i then qev (then_f i) else qev else_f). Proof. move=> P; rewrite ((big_morph qev) false orb) //= big_orE /=. apply/existsP/idP=> [[p] | true_at_P]. rewrite ((big_morph qev) true andb) //= big_andE /=. case/andP=> /forallP-eq_p_P. rewrite (@eq_pick _ _ P) => [|i]; first by case: pick. by move/(_ i): eq_p_P => /=; case: (p i) => //= /negPf. exists [ffun i => P i] => /=; apply/andP; split. rewrite ((big_morph qev) true andb) //= big_andE /=. by apply/forallP=> i; rewrite /= ffunE; case Pi: (P i) => //=; apply: negbT. rewrite (@eq_pick _ _ P) => [|i]; first by case: pick true_at_P. by rewrite ffunE. Qed. End Pick. Section MultiQuant. Variable f : formula R. Implicit Types (I : seq nat) (e : seq R). Lemma foldExistsP I e : (exists2 e', {in [predC I], same_env e e'} & holds e' f) <-> holds e (foldr Exists f I). Proof. elim: I e => /= [|i I IHi] e. by split=> [[e' eq_e] |]; [apply: eq_holds => i; rewrite eq_e | exists e]. split=> [[e' eq_e f_e'] | [x]]; last set e_x := set_nth 0 e i x. exists e'`_i; apply/IHi; exists e' => // j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->. case/IHi=> e' eq_e f_e'; exists e' => // j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP. Qed. Lemma foldForallP I e : (forall e', {in [predC I], same_env e e'} -> holds e' f) <-> holds e (foldr Forall f I). Proof. elim: I e => /= [|i I IHi] e. by split=> [|f_e e' eq_e]; [apply | apply: eq_holds f_e => i; rewrite eq_e]. split=> [f_e' x | f_e e' eq_e]; first set e_x := set_nth 0 e i x. apply/IHi=> e' eq_e; apply: f_e' => j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP. move/IHi: (f_e e'`_i); apply=> j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->. Qed. End MultiQuant. End EvalTerm. Prenex Implicits dnf_rterm. Definition integral_domain_axiom (R : pzRingType) := forall x y : R, x * y = 0 -> (x == 0) || (y == 0). HB.mixin Record ComUnitRing_isIntegral R of ComUnitRing R := { mulf_eq0_subproof : integral_domain_axiom R; }. #[mathcomp(axiom="integral_domain_axiom"), short(type="idomainType")] HB.structure Definition IntegralDomain := {R of ComUnitRing_isIntegral R & ComUnitRing R}. Module IntegralDomainExports. Bind Scope ring_scope with IntegralDomain.sort. End IntegralDomainExports. HB.export IntegralDomainExports. Section IntegralDomainTheory. Variable R : idomainType. Implicit Types x y : R. Lemma mulf_eq0 x y : (x * y == 0) = (x == 0) || (y == 0). Proof. apply/eqP/idP; first exact: mulf_eq0_subproof. by case/pred2P=> ->; rewrite (mulr0, mul0r). Qed. Lemma prodf_eq0 (I : finType) (P : pred I) (F : I -> R) : reflect (exists2 i, P i & (F i == 0)) (\prod_(i | P i) F i == 0). Proof. apply: (iffP idP) => [|[i Pi /eqP Fi0]]; last first. by rewrite (bigD1 i) //= Fi0 mul0r. elim: (index_enum _) => [|i r IHr]; first by rewrite big_nil oner_eq0. rewrite big_cons /=; have [Pi | _] := ifP; last exact: IHr. by rewrite mulf_eq0; case/orP=> // Fi0; exists i. Qed. Lemma prodf_seq_eq0 I r (P : pred I) (F : I -> R) : (\prod_(i <- r | P i) F i == 0) = has (fun i => P i && (F i == 0)) r. Proof. by rewrite (big_morph _ mulf_eq0 (oner_eq0 _)) big_has_cond. Qed. Lemma mulf_neq0 x y : x != 0 -> y != 0 -> x * y != 0. Proof. by move=> x0 y0; rewrite mulf_eq0; apply/norP. Qed. Lemma prodf_neq0 (I : finType) (P : pred I) (F : I -> R) : reflect (forall i, P i -> (F i != 0)) (\prod_(i | P i) F i != 0). Proof. by rewrite (sameP (prodf_eq0 _ _) exists_inP); apply: exists_inPn. Qed. Lemma prodf_seq_neq0 I r (P : pred I) (F : I -> R) : (\prod_(i <- r | P i) F i != 0) = all (fun i => P i ==> (F i != 0)) r. Proof. rewrite prodf_seq_eq0 -all_predC; apply: eq_all => i /=. by rewrite implybE negb_and. Qed. Lemma expf_eq0 x n : (x ^+ n == 0) = (n > 0) && (x == 0). Proof. elim: n => [|n IHn]; first by rewrite oner_eq0. by rewrite exprS mulf_eq0 IHn andKb. Qed. Lemma sqrf_eq0 x : (x ^+ 2 == 0) = (x == 0). Proof. exact: expf_eq0. Qed. Lemma expf_neq0 x m : x != 0 -> x ^+ m != 0. Proof. by move=> x_nz; rewrite expf_eq0; apply/nandP; right. Qed. Lemma natf_neq0_pchar n : (n%:R != 0 :> R) = (pchar R)^'.-nat n. Proof. have [-> | /prod_prime_decomp->] := posnP n; first by rewrite eqxx. rewrite !big_seq; elim/big_rec: _ => [|[p e] s /=]; first by rewrite oner_eq0. case/mem_prime_decomp=> p_pr _ _; rewrite pnatM pnatX eqn0Ngt orbC => <-. by rewrite natrM natrX mulf_eq0 expf_eq0 negb_or negb_and pnatE ?inE p_pr. Qed. Lemma natf0_pchar n : n > 0 -> n%:R == 0 :> R -> exists p, p \in pchar R. Proof. move=> n_gt0 nR_0; exists (pdiv n`_(pchar R)). apply: pnatP (pdiv_dvd _); rewrite ?part_pnat // ?pdiv_prime //. by rewrite ltn_neqAle eq_sym partn_eq1 // -natf_neq0_pchar nR_0 /=. Qed. Lemma pcharf'_nat n : (pchar R)^'.-nat n = (n%:R != 0 :> R). Proof. have [-> | n_gt0] := posnP n; first by rewrite eqxx. apply/idP/idP => [|nz_n]; last first. by apply/pnatP=> // p p_pr p_dvd_n; apply: contra nz_n => /dvdn_pcharf <-. apply: contraL => n0; have [// | p pcharRp] := natf0_pchar _ n0. have [p_pr _] := andP pcharRp; rewrite (eq_pnat _ (eq_negn (pcharf_eq pcharRp))). by rewrite p'natE // (dvdn_pcharf pcharRp) n0. Qed. Lemma pcharf0P : pchar R =i pred0 <-> (forall n, (n%:R == 0 :> R) = (n == 0)%N). Proof. split=> pcharF0 n; last by rewrite !inE pcharF0 andbC; case: eqP => // ->. have [-> | n_gt0] := posnP; first exact: eqxx. by apply/negP; case/natf0_pchar=> // p; rewrite pcharF0. Qed. Lemma eqf_sqr x y : (x ^+ 2 == y ^+ 2) = (x == y) || (x == - y). Proof. by rewrite -subr_eq0 subr_sqr mulf_eq0 subr_eq0 addr_eq0. Qed. Lemma mulfI x : x != 0 -> injective ( *%R x). Proof. move=> nz_x y z; apply: contra_eq => neq_yz. by rewrite -subr_eq0 -mulrBr mulf_neq0 ?subr_eq0. Qed. Lemma mulIf x : x != 0 -> injective ( *%R^~ x). Proof. by move=> nz_x y z; rewrite -!(mulrC x); apply: mulfI. Qed. Lemma divfI x : x != 0 -> injective (fun y => x / y). Proof. by move/mulfI/inj_comp; apply; apply: invr_inj. Qed. Lemma divIf y : y != 0 -> injective (fun x => x / y). Proof. by rewrite -invr_eq0; apply: mulIf. Qed. Lemma sqrf_eq1 x : (x ^+ 2 == 1) = (x == 1) || (x == -1). Proof. by rewrite -subr_eq0 subr_sqr_1 mulf_eq0 subr_eq0 addr_eq0. Qed. Lemma expfS_eq1 x n : (x ^+ n.+1 == 1) = (x == 1) || (\sum_(i < n.+1) x ^+ i == 0). Proof. by rewrite -![_ == 1]subr_eq0 subrX1 mulf_eq0. Qed. Lemma lregP x : reflect (lreg x) (x != 0). Proof. by apply: (iffP idP) => [/mulfI | /lreg_neq0]. Qed. Lemma rregP x : reflect (rreg x) (x != 0). Proof. by apply: (iffP idP) => [/mulIf | /rreg_neq0]. Qed. #[export] HB.instance Definition _ := IntegralDomain.on R^o. End IntegralDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")] Notation natf_neq0 := natf_neq0_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")] Notation natf0_char := natf0_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")] Notation charf'_nat := pcharf'_nat (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")] Notation charf0P := pcharf0P (only parsing). Arguments lregP {R x}. Arguments rregP {R x}. Definition field_axiom (R : unitRingType) := forall x : R, x != 0 -> x \in unit. HB.mixin Record UnitRing_isField R of UnitRing R := { fieldP : field_axiom R; }. #[mathcomp(axiom="field_axiom"), short(type="fieldType")] HB.structure Definition Field := { R of IntegralDomain R & UnitRing_isField R }. Module FieldExports. Bind Scope ring_scope with Field.sort. End FieldExports. HB.export FieldExports. #[export] HB.instance Definition regular_field (F : fieldType) := Field.on F^o. Lemma IdomainMixin (R : unitRingType): Field.axiom R -> IntegralDomain.axiom R. Proof. move=> m x y xy0; apply/norP=> [[]] /m Ux /m. by rewrite -(unitrMr _ Ux) xy0 unitr0. Qed. HB.factory Record ComUnitRing_isField R of ComUnitRing R := { fieldP : field_axiom R; }. HB.builders Context R of ComUnitRing_isField R. HB.instance Definition _ := ComUnitRing_isIntegral.Build R (IdomainMixin fieldP). HB.instance Definition _ := UnitRing_isField.Build R fieldP. HB.end. HB.factory Record ComNzRing_isField R of ComNzRing R := { inv : R -> R; mulVf : forall x, x != 0 -> inv x * x = 1; invr0 : inv 0 = 0; }. Module ComRing_isField. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_isField.Build instead.")] Notation Build R := (ComNzRing_isField.Build R) (only parsing). End ComRing_isField. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_isField instead.")] Notation ComRing_isField R := (ComNzRing_isField R) (only parsing). HB.builders Context R of ComNzRing_isField R. Fact intro_unit (x y : R) : y * x = 1 -> x != 0. Proof. move=> yx1; apply: contraNneq (@oner_neq0 R) => x0. by rewrite -yx1 x0 mulr0. Qed. Fact inv_out : {in predC (predC1 0), inv =1 id}. Proof. by move=> x /negbNE/eqP->; exact: invr0. Qed. HB.instance Definition _ : ComNzRing_hasMulInverse R := ComNzRing_hasMulInverse.Build R mulVf intro_unit inv_out. HB.instance Definition _ : ComUnitRing_isField R := ComUnitRing_isField.Build R (fun x x_neq_0 => x_neq_0). HB.end. Section FieldTheory. Variable F : fieldType. Implicit Types x y : F. Lemma unitfE x : (x \in unit) = (x != 0). Proof. by apply/idP/idP=> [/(memPn _)-> | /fieldP]; rewrite ?unitr0. Qed. Lemma mulVf x : x != 0 -> x^-1 * x = 1. Proof. by rewrite -unitfE; apply: mulVr. Qed. Lemma divff x : x != 0 -> x / x = 1. Proof. by rewrite -unitfE; apply: divrr. Qed. Definition mulfV := divff. Lemma mulKf x : x != 0 -> cancel ( *%R x) ( *%R x^-1). Proof. by rewrite -unitfE; apply: mulKr. Qed. Lemma mulVKf x : x != 0 -> cancel ( *%R x^-1) ( *%R x). Proof. by rewrite -unitfE; apply: mulVKr. Qed. Lemma mulfK x : x != 0 -> cancel ( *%R^~ x) ( *%R^~ x^-1). Proof. by rewrite -unitfE; apply: mulrK. Qed. Lemma mulfVK x : x != 0 -> cancel ( *%R^~ x^-1) ( *%R^~ x). Proof. by rewrite -unitfE; apply: divrK. Qed. Definition divfK := mulfVK. Lemma invfM : {morph @inv F : x y / x * y}. Proof. move=> x y; have [->|nzx] := eqVneq x 0; first by rewrite !(mul0r, invr0). have [->|nzy] := eqVneq y 0; first by rewrite !(mulr0, invr0). by rewrite mulrC invrM ?unitfE. Qed. Lemma invf_div x y : (x / y)^-1 = y / x. Proof. by rewrite invfM invrK mulrC. Qed. Lemma divKf x : x != 0 -> involutive (fun y => x / y). Proof. by move=> nz_x y; rewrite invf_div mulrC divfK. Qed. Lemma expfB_cond m n x : (x == 0) + n <= m -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. move/subnK=> <-; rewrite addnA addnK !exprD. have [-> | nz_x] := eqVneq; first by rewrite !mulr0 !mul0r. by rewrite mulfK ?expf_neq0. Qed. Lemma expfB m n x : n < m -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. by move=> lt_n_m; apply: expfB_cond; case: eqP => // _; apply: ltnW. Qed. Lemma prodfV I r (P : pred I) (E : I -> F) : \prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1. Proof. by rewrite (big_morph _ invfM (invr1 F)). Qed. Lemma prodf_div I r (P : pred I) (E D : I -> F) : \prod_(i <- r | P i) (E i / D i) = \prod_(i <- r | P i) E i / \prod_(i <- r | P i) D i. Proof. by rewrite big_split prodfV. Qed. Lemma telescope_prodf n m (f : nat -> F) : (forall k, n < k < m -> f k != 0) -> n < m -> \prod_(n <= k < m) (f k.+1 / f k) = f m / f n. Proof. move=> nz_f ltnm; apply: invr_inj; rewrite prodf_div !invf_div -prodf_div. by apply: telescope_prodr => // k /nz_f; rewrite unitfE. Qed. Lemma telescope_prodf_eq n m (f u : nat -> F) : (forall k, n < k < m -> f k != 0) -> n < m -> (forall k, n <= k < m -> u k = f k.+1 / f k) -> \prod_(n <= k < m) u k = f m / f n. Proof. by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodf. Qed. Lemma addf_div x1 y1 x2 y2 : y1 != 0 -> y2 != 0 -> x1 / y1 + x2 / y2 = (x1 * y2 + x2 * y1) / (y1 * y2). Proof. by move=> nzy1 nzy2; rewrite invfM mulrDl !mulrA mulrAC !mulfK. Qed. Lemma mulf_div x1 y1 x2 y2 : (x1 / y1) * (x2 / y2) = (x1 * x2) / (y1 * y2). Proof. by rewrite mulrACA -invfM. Qed. Lemma eqr_div x y z t : y != 0 -> t != 0 -> (x / y == z / t) = (x * t == z * y). Proof. move=> yD0 tD0; rewrite -[x in RHS](divfK yD0) -[z in RHS](divfK tD0) mulrAC. by apply/eqP/eqP => [->|/(mulIf yD0)/(mulIf tD0)]. Qed. Lemma eqr_sum_div I r P (f : I -> F) c a : c != 0 -> \big[+%R/0]_(x <- r | P x) (f x / c) == a = (\big[+%R/0]_(x <- r | P x) f x == a * c). Proof. by move=> ?; rewrite -mulr_suml -(divr1 a) eqr_div ?oner_eq0// mulr1 divr1. Qed. Lemma pchar0_natf_div : pchar F =i pred0 -> forall m d, d %| m -> (m %/ d)%:R = m%:R / d%:R :> F. Proof. move/pcharf0P=> pchar0F m [|d] d_dv_m; first by rewrite divn0 invr0 mulr0. by rewrite natr_div // unitfE pchar0F. Qed. Section FieldMorphismInj. Variables (R : nzRingType) (f : {rmorphism F -> R}). Lemma fmorph_eq0 x : (f x == 0) = (x == 0). Proof. have [-> | nz_x] := eqVneq x; first by rewrite rmorph0 eqxx. apply/eqP; move/(congr1 ( *%R (f x^-1)))/eqP. by rewrite -rmorphM mulVf // mulr0 rmorph1 ?oner_eq0. Qed. Lemma fmorph_inj : injective f. Proof. by apply/raddf_inj => x /eqP; rewrite fmorph_eq0 => /eqP. Qed. Lemma fmorph_eq : {mono f : x y / x == y}. Proof. exact: inj_eq fmorph_inj. Qed. Lemma fmorph_eq1 x : (f x == 1) = (x == 1). Proof. by rewrite -(inj_eq fmorph_inj) rmorph1. Qed. Lemma fmorph_pchar : pchar R =i pchar F. Proof. by move=> p; rewrite !inE -fmorph_eq0 rmorph_nat. Qed. End FieldMorphismInj. Section FieldMorphismInv. Variables (R : unitRingType) (f : {rmorphism F -> R}). Lemma fmorph_unit x : (f x \in unit) = (x != 0). Proof. have [-> |] := eqVneq x; first by rewrite rmorph0 unitr0. by rewrite -unitfE; apply: rmorph_unit. Qed. Lemma fmorphV : {morph f: x / x^-1}. Proof. move=> x; have [-> | nz_x] := eqVneq x 0; first by rewrite !(invr0, rmorph0). by rewrite rmorphV ?unitfE. Qed. Lemma fmorph_div : {morph f : x y / x / y}. Proof. by move=> x y; rewrite rmorphM /= fmorphV. Qed. End FieldMorphismInv. Section ModuleTheory. Variable V : lmodType F. Implicit Types (a : F) (v : V). Lemma scalerK a : a != 0 -> cancel ( *:%R a : V -> V) ( *:%R a^-1). Proof. by move=> nz_a v; rewrite scalerA mulVf // scale1r. Qed. Lemma scalerKV a : a != 0 -> cancel ( *:%R a^-1 : V -> V) ( *:%R a). Proof. by rewrite -invr_eq0 -{3}[a]invrK; apply: scalerK. Qed. Lemma scalerI a : a != 0 -> injective ( *:%R a : V -> V). Proof. by move=> nz_a; apply: can_inj (scalerK nz_a). Qed. Lemma scaler_eq0 a v : (a *: v == 0) = (a == 0) || (v == 0). Proof. have [-> | nz_a] := eqVneq a; first by rewrite scale0r eqxx. by rewrite (can2_eq (scalerK nz_a) (scalerKV nz_a)) scaler0. Qed. End ModuleTheory. Lemma pchar_lalg (A : lalgType F) : pchar A =i pchar F. Proof. by move=> p; rewrite inE -scaler_nat scaler_eq0 oner_eq0 orbF. Qed. End FieldTheory. #[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")] Notation char0_natf_div := pchar0_natf_div (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")] Notation fmorph_char := fmorph_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")] Notation char_lalg := pchar_lalg (only parsing). Arguments fmorph_inj {F R} f [x1 x2]. Arguments telescope_prodf_eq {F n m} f u. Definition decidable_field_axiom (R : unitRingType) (s : seq R -> pred (formula R)) := forall e f, reflect (holds e f) (s e f). HB.mixin Record Field_isDecField R of UnitRing R := { sat : seq R -> pred (formula R); satP : decidable_field_axiom sat; }. #[mathcomp(axiom="decidable_field_axiom"), short(type="decFieldType")] HB.structure Definition DecidableField := { F of Field F & Field_isDecField F }. Module DecFieldExports. Bind Scope ring_scope with DecidableField.sort. End DecFieldExports. HB.export DecFieldExports. #[export] HB.instance Definition _ (F : decFieldType) := DecidableField.on F^o. Section DecidableFieldTheory. Variable F : decFieldType. Implicit Type f : formula F. Fact sol_subproof n f : reflect (exists s, (size s == n) && sat s f) (sat [::] (foldr Exists f (iota 0 n))). Proof. apply: (iffP (satP _ _)) => [|[s]]; last first. case/andP=> /eqP sz_s /satP f_s; apply/foldExistsP. exists s => // i; rewrite !inE mem_iota -leqNgt add0n => le_n_i. by rewrite !nth_default ?sz_s. case/foldExistsP=> e e0 f_e; set s := take n (set_nth 0 e n 0). have sz_s: size s = n by rewrite size_take size_set_nth leq_max leqnn. exists s; rewrite sz_s eqxx; apply/satP; apply: eq_holds f_e => i. case: (leqP n i) => [le_n_i | lt_i_n]. by rewrite -e0 ?nth_default ?sz_s // !inE mem_iota -leqNgt. by rewrite nth_take // nth_set_nth /= eq_sym eqn_leq leqNgt lt_i_n. Qed. Definition sol n f := if sol_subproof n f is ReflectT sP then xchoose sP else nseq n 0. Lemma size_sol n f : size (sol n f) = n. Proof. rewrite /sol; case: sol_subproof => [sP | _]; last exact: size_nseq. by case/andP: (xchooseP sP) => /eqP. Qed. Lemma solP n f : reflect (exists2 s, size s = n & holds s f) (sat (sol n f) f). Proof. rewrite /sol; case: sol_subproof => [sP | sPn]. case/andP: (xchooseP sP) => _ ->; left. by case: sP => s; case/andP; move/eqP=> <-; move/satP; exists s. apply: (iffP (satP _ _)); first by exists (nseq n 0); rewrite ?size_nseq. by case=> s sz_s; move/satP=> f_s; case: sPn; exists s; rewrite sz_s eqxx. Qed. Lemma eq_sat f1 f2 : (forall e, holds e f1 <-> holds e f2) -> sat^~ f1 =1 sat^~ f2. Proof. by move=> eqf12 e; apply/satP/satP; case: (eqf12 e). Qed. Lemma eq_sol f1 f2 : (forall e, holds e f1 <-> holds e f2) -> sol^~ f1 =1 sol^~ f2. Proof. rewrite /sol => /eq_sat eqf12 n. do 2![case: sol_subproof] => //= [f1s f2s | ns1 [s f2s] | [s f1s] []]. - by apply: eq_xchoose => s; rewrite eqf12. - by case: ns1; exists s; rewrite -eqf12. by exists s; rewrite eqf12. Qed. End DecidableFieldTheory. Arguments satP {F e f} : rename. Arguments solP {F n f} : rename. Section QE_Mixin. Variable F : Field.type. Implicit Type f : formula F. Variable proj : nat -> seq (term F) * seq (term F) -> formula F. (* proj is the elimination of a single existential quantifier *) (* The elimination projector is well_formed. *) Definition wf_QE_proj := forall i bc (bc_i := proj i bc), dnf_rterm bc -> qf_form bc_i && rformula bc_i. (* The elimination projector is valid *) Definition valid_QE_proj := forall i bc (ex_i_bc := ('exists 'X_i, dnf_to_form [:: bc])%T) e, dnf_rterm bc -> reflect (holds e ex_i_bc) (qf_eval e (proj i bc)). Hypotheses (wf_proj : wf_QE_proj) (ok_proj : valid_QE_proj). Let elim_aux f n := foldr Or False (map (proj n) (qf_to_dnf f false)). Fixpoint quantifier_elim f := match f with | f1 /\ f2 => (quantifier_elim f1) /\ (quantifier_elim f2) | f1 \/ f2 => (quantifier_elim f1) \/ (quantifier_elim f2) | f1 ==> f2 => (~ quantifier_elim f1) \/ (quantifier_elim f2) | ~ f => ~ quantifier_elim f | ('exists 'X_n, f) => elim_aux (quantifier_elim f) n | ('forall 'X_n, f) => ~ elim_aux (~ quantifier_elim f) n | _ => f end%T. Lemma quantifier_elim_wf f : let qf := quantifier_elim f in rformula f -> qf_form qf && rformula qf. Proof. suffices aux_wf f0 n : let qf := elim_aux f0 n in rformula f0 -> qf_form qf && rformula qf. - by elim: f => //=; do ?[ move=> f1 IH1 f2 IH2; case/andP=> rf1 rf2; case/andP:(IH1 rf1)=> -> ->; case/andP:(IH2 rf2)=> -> -> // | move=> n f1 IH rf1; case/andP: (IH rf1)=> qff rf; rewrite aux_wf ]. rewrite /elim_aux => rf. suffices or_wf fs : let ofs := foldr Or False fs in all (@qf_form F) fs && all (@rformula F) fs -> qf_form ofs && rformula ofs. - apply: or_wf. suffices map_proj_wf bcs: let mbcs := map (proj n) bcs in all dnf_rterm bcs -> all (@qf_form _) mbcs && all (@rformula _) mbcs. by apply/map_proj_wf/qf_to_dnf_rterm. elim: bcs => [|bc bcs ihb] bcsr //= /andP[rbc rbcs]. by rewrite andbAC andbA wf_proj //= andbC ihb. elim: fs => //= g gs ihg; rewrite -andbA => /and4P[-> qgs -> rgs] /=. by apply: ihg; rewrite qgs rgs. Qed. Lemma quantifier_elim_rformP e f : rformula f -> reflect (holds e f) (qf_eval e (quantifier_elim f)). Proof. pose rc e n f := exists x, qf_eval (set_nth 0 e n x) f. have auxP f0 e0 n0: qf_form f0 && rformula f0 -> reflect (rc e0 n0 f0) (qf_eval e0 (elim_aux f0 n0)). + rewrite /elim_aux => cf; set bcs := qf_to_dnf f0 false. apply: (@iffP (rc e0 n0 (dnf_to_form bcs))); last first. - by case=> x; rewrite -qf_to_dnfP //; exists x. - by case=> x; rewrite qf_to_dnfP //; exists x. have: all dnf_rterm bcs by case/andP: cf => _; apply: qf_to_dnf_rterm. elim: {f0 cf}bcs => [|bc bcs IHbcs] /=; first by right; case. case/andP=> r_bc /IHbcs {IHbcs}bcsP. have f_qf := dnf_to_form_qf [:: bc]. case: ok_proj => //= [ex_x|no_x]. left; case: ex_x => x /(qf_evalP _ f_qf); rewrite /= orbF => bc_x. by exists x; rewrite /= bc_x. apply: (iffP bcsP) => [[x bcs_x] | [x]] /=. by exists x; rewrite /= bcs_x orbT. case/orP => [bc_x|]; last by exists x. by case: no_x; exists x; apply/(qf_evalP _ f_qf); rewrite /= bc_x. elim: f e => //. - by move=> b e _; apply: idP. - by move=> t1 t2 e _; apply: eqP. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by right; case. by case/IH2; [left | right; case]. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; first by do 2!left. by case/IH2; [left; right | right; case]. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by left. by case/IH2; [left | right; move/(_ f1e)]. - by move=> f IHf e /= /IHf[]; [right | left]. - move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf. by apply: (iffP (auxP _ _ _ rqf)) => [] [x]; exists x; apply/IHf. move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf. case: auxP => // [f_x|no_x]; first by right=> no_x; case: f_x => x /IHf[]. by left=> x; apply/IHf=> //; apply/idPn=> f_x; case: no_x; exists x. Qed. Definition proj_sat e f := qf_eval e (quantifier_elim (to_rform f)). Lemma proj_satP : DecidableField.axiom proj_sat. Proof. move=> e f; have fP := quantifier_elim_rformP e (to_rform_rformula f). by apply: (iffP fP); move/to_rformP. Qed. End QE_Mixin. HB.factory Record Field_QE_isDecField F of Field F := { proj : nat -> seq (term F) * seq (term F) -> formula F; wf_proj : wf_QE_proj proj; ok_proj : valid_QE_proj proj; }. HB.builders Context F of Field_QE_isDecField F. HB.instance Definition qe_is_def_field : Field_isDecField F := Field_isDecField.Build F (proj_satP wf_proj ok_proj). HB.end. (* Axiom == all non-constant monic polynomials have a root *) Definition closed_field_axiom (R : pzRingType) := forall n (P : nat -> R), n > 0 -> exists x : R, x ^+ n = \sum_(i < n) P i * (x ^+ i). HB.mixin Record DecField_isAlgClosed F of DecidableField F := { solve_monicpoly : closed_field_axiom F; }. #[mathcomp(axiom="closed_field_axiom"), short(type="closedFieldType")] HB.structure Definition ClosedField := { F of DecidableField F & DecField_isAlgClosed F }. Module ClosedFieldExports. Bind Scope ring_scope with ClosedField.sort. End ClosedFieldExports. HB.export ClosedFieldExports. #[export] HB.instance Definition _ (F : closedFieldType) := ClosedField.on F^o. Section ClosedFieldTheory. Variable F : closedFieldType. Lemma imaginary_exists : {i : F | i ^+ 2 = -1}. Proof. have /sig_eqW[i Di2] := @solve_monicpoly F 2 (nth 0 [:: -1]) isT. by exists i; rewrite Di2 !big_ord_recl big_ord0 mul0r mulr1 !addr0. Qed. End ClosedFieldTheory. Lemma lalgMixin (R : pzRingType) (A : lalgType R) (B : lmodType R) (f : B -> A) : phant B -> injective f -> scalable f -> forall mulB, {morph f : x y / mulB x y >-> x * y} -> forall a u v, a *: (mulB u v) = mulB (a *: u) v. Proof. by move=> _ injf fZ mulB fM a x y; apply: injf; rewrite !(fZ, fM) scalerAl. Qed. Lemma comRingMixin (R : comPzRingType) (T : pzRingType) (f : T -> R) : phant T -> injective f -> {morph f : x y / x * y} -> commutative (@mul T). Proof. by move=> _ inj_f fM x y; apply: inj_f; rewrite !fM mulrC. Qed. Lemma algMixin (R : pzRingType) (A : algType R) (B : lalgType R) (f : B -> A) : phant B -> injective f -> {morph f : x y / x * y} -> scalable f -> forall k (x y : B), k *: (x * y) = x * (k *: y). Proof. by move=> _ inj_f fM fZ a x y; apply: inj_f; rewrite !(fM, fZ) scalerAr. Qed. (* Mixins for stability properties *) HB.mixin Record isMul2Closed (R : pzSemiRingType) (S : {pred R}) := { rpredM : mulr_2closed S }. HB.mixin Record isMul1Closed (R : pzSemiRingType) (S : {pred R}) := { rpred1 : 1 \in S }. HB.mixin Record isInvClosed (R : unitRingType) (S : {pred R}) := { rpredVr : invr_closed S }. HB.mixin Record isScaleClosed (R : pzSemiRingType) (V : lSemiModType R) (S : {pred V}) := { rpredZ : scaler_closed S }. (* Structures for stability properties *) Local Notation addrClosed := addrClosed. Local Notation opprClosed := opprClosed. #[short(type="mulr2Closed")] HB.structure Definition Mul2Closed (R : pzSemiRingType) := {S of isMul2Closed R S}. #[short(type="mulrClosed")] HB.structure Definition MulClosed (R : pzSemiRingType) := {S of Mul2Closed R S & isMul1Closed R S}. #[short(type="semiring2Closed")] HB.structure Definition Semiring2Closed (R : pzSemiRingType) := {S of AddClosed R S & Mul2Closed R S}. #[short(type="semiringClosed")] HB.structure Definition SemiringClosed (R : pzSemiRingType) := {S of AddClosed R S & MulClosed R S}. #[short(type="smulClosed")] HB.structure Definition SmulClosed (R : pzRingType) := {S of OppClosed R S & MulClosed R S}. #[short(type="subringClosed")] HB.structure Definition SubringClosed (R : pzRingType) := {S of ZmodClosed R S & MulClosed R S}. #[short(type="divClosed")] HB.structure Definition DivClosed (R : unitRingType) := {S of MulClosed R S & isInvClosed R S}. #[short(type="sdivClosed")] HB.structure Definition SdivClosed (R : unitRingType) := {S of SmulClosed R S & isInvClosed R S}. #[short(type="submodClosed")] HB.structure Definition SubmodClosed (R : pzSemiRingType) (V : lSemiModType R) := {S of AddClosed V S & isScaleClosed R V S}. #[short(type="subalgClosed")] HB.structure Definition SubalgClosed (R : pzSemiRingType) (A : lSemiAlgType R) := {S of SemiringClosed A S & isScaleClosed R A S}. #[short(type="divringClosed")] HB.structure Definition DivringClosed (R : unitRingType) := {S of SubringClosed R S & isInvClosed R S}. #[short(type="divalgClosed")] HB.structure Definition DivalgClosed (R : pzRingType) (A : unitAlgType R) := {S of DivringClosed A S & isScaleClosed R A S}. (* Factories for stability properties *) HB.factory Record isMulClosed (R : pzSemiRingType) (S : {pred R}) := { rpred1M : mulr_closed S }. HB.builders Context R S of isMulClosed R S. HB.instance Definition _ := isMul2Closed.Build R S (proj2 rpred1M). HB.instance Definition _ := isMul1Closed.Build R S (proj1 rpred1M). HB.end. HB.factory Record isSmulClosed (R : pzRingType) (S : R -> bool) := { smulr_closed_subproof : smulr_closed S }. HB.builders Context R S of isSmulClosed R S. HB.instance Definition _ := isMulClosed.Build R S (smulr_closedM smulr_closed_subproof). HB.instance Definition _ := isOppClosed.Build R S (smulr_closedN smulr_closed_subproof). HB.end. HB.factory Record isSemiringClosed (R : pzSemiRingType) (S : R -> bool) := { semiring_closed_subproof : semiring_closed S }. HB.builders Context R S of isSemiringClosed R S. HB.instance Definition _ := isAddClosed.Build R S (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := isMulClosed.Build R S (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record isSubringClosed (R : pzRingType) (S : R -> bool) := { subring_closed_subproof : subring_closed S }. HB.builders Context R S of isSubringClosed R S. HB.instance Definition _ := isZmodClosed.Build R S (subring_closedB subring_closed_subproof). HB.instance Definition _ := isSmulClosed.Build R S (subring_closedM subring_closed_subproof). HB.end. HB.factory Record isDivClosed (R : unitRingType) (S : R -> bool) := { divr_closed_subproof : divr_closed S }. HB.builders Context R S of isDivClosed R S. HB.instance Definition _ := isMulClosed.Build R S (divr_closedM divr_closed_subproof). HB.instance Definition _ := isInvClosed.Build R S (divr_closedV divr_closed_subproof). HB.end. HB.factory Record isSdivClosed (R : unitRingType) (S : R -> bool) := { sdivr_closed_subproof : sdivr_closed S }. HB.builders Context R S of isSdivClosed R S. HB.instance Definition _ := isDivClosed.Build R S (sdivr_closed_div sdivr_closed_subproof). HB.instance Definition _ := isSmulClosed.Build R S (sdivr_closedM sdivr_closed_subproof). HB.end. HB.factory Record isSubSemiModClosed (R : pzSemiRingType) (V : lSemiModType R) (S : V -> bool) := { subsemimod_closed_subproof : subsemimod_closed S }. HB.builders Context R V S of isSubSemiModClosed R V S. HB.instance Definition _ := isAddClosed.Build V S (subsemimod_closedD subsemimod_closed_subproof). HB.instance Definition _ := isScaleClosed.Build R V S (subsemimod_closedZ subsemimod_closed_subproof). HB.end. HB.factory Record isSubmodClosed (R : pzRingType) (V : lmodType R) (S : V -> bool) := { submod_closed_subproof : submod_closed S }. HB.builders Context R V S of isSubmodClosed R V S. HB.instance Definition _ := isZmodClosed.Build V S (submod_closedB submod_closed_subproof). HB.instance Definition _ := isScaleClosed.Build R V S (subsemimod_closedZ (submod_closed_semi submod_closed_subproof)). HB.end. HB.factory Record isSubalgClosed (R : pzRingType) (A : lalgType R) (S : A -> bool) := { subalg_closed_subproof : subalg_closed S }. HB.builders Context R A S of isSubalgClosed R A S. HB.instance Definition _ := isSubmodClosed.Build R A S (subalg_closedZ subalg_closed_subproof). HB.instance Definition _ := isSubringClosed.Build A S (subalg_closedBM subalg_closed_subproof). HB.end. HB.factory Record isDivringClosed (R : unitRingType) (S : R -> bool) := { divring_closed_subproof : divring_closed S }. HB.builders Context R S of isDivringClosed R S. HB.instance Definition _ := isSubringClosed.Build R S (divring_closedBM divring_closed_subproof). HB.instance Definition _ := isSdivClosed.Build R S (divring_closed_div divring_closed_subproof). HB.end. HB.factory Record isDivalgClosed (R : comUnitRingType) (A : unitAlgType R) (S : A -> bool) := { divalg_closed_subproof : divalg_closed S }. HB.builders Context R A S of isDivalgClosed R A S. HB.instance Definition _ := isDivringClosed.Build A S (divalg_closedBdiv divalg_closed_subproof). HB.instance Definition _ := isSubalgClosed.Build R A S (divalg_closedZ divalg_closed_subproof). HB.end. Section NmodulePred. Variables (V : nmodType). Section Add. Variable S : addrClosed V. Lemma rpred0D : nmod_closed S. Proof. exact: nmod_closed_subproof. Qed. End Add. End NmodulePred. Section ZmodulePred. Variables (V : zmodType). Section Opp. Variable S : opprClosed V. End Opp. Section Sub. Variable S : zmodClosed V. Lemma zmodClosedP : zmod_closed S. Proof. split; [ exact: (@rpred0D V S).1 | exact: rpredB ]. Qed. End Sub. End ZmodulePred. Section SemiRingPred. Variables (R : pzSemiRingType). Section Mul. Variable S : mulrClosed R. Lemma rpred1M : mulr_closed S. Proof. exact: (conj rpred1 rpredM). Qed. Lemma rpred_prod I r (P : pred I) F : (forall i, P i -> F i \in S) -> \prod_(i <- r | P i) F i \in S. Proof. by move=> IH; elim/big_ind: _; [apply: rpred1 | apply: rpredM |]. Qed. Lemma rpredX n : {in S, forall u, u ^+ n \in S}. Proof. by move=> u Su; rewrite -(card_ord n) -prodr_const rpred_prod. Qed. End Mul. Lemma rpred_nat (S : semiringClosed R) n : n%:R \in S. Proof. by rewrite rpredMn ?rpred1. Qed. Lemma semiringClosedP (rngS : semiringClosed R) : semiring_closed rngS. Proof. split; [ exact: rpred0D | exact: rpred1M ]. Qed. End SemiRingPred. Section RingPred. Variables (R : pzRingType). Lemma rpredMsign (S : opprClosed R) n x : ((-1) ^+ n * x \in S) = (x \in S). Proof. by rewrite -signr_odd mulr_sign; case: ifP => // _; rewrite rpredN. Qed. Lemma rpredN1 (S : smulClosed R) : -1 \in S. Proof. by rewrite rpredN rpred1. Qed. Lemma rpred_sign (S : smulClosed R) n : (-1) ^+ n \in S. Proof. by rewrite rpredX ?rpredN1. Qed. Lemma subringClosedP (rngS : subringClosed R) : subring_closed rngS. Proof. split; [ exact: rpred1 | exact: (zmodClosedP rngS).2 | exact: rpredM ]. Qed. End RingPred. Section LmodPred. Variables (R : pzSemiRingType) (V : lSemiModType R). Lemma rpredZnat (S : addrClosed V) n : {in S, forall u, n%:R *: u \in S}. Proof. by move=> u Su; rewrite /= scaler_nat rpredMn. Qed. Lemma subsemimodClosedP (modS : submodClosed V) : subsemimod_closed modS. Proof. by split; [exact: rpred0D | exact: rpredZ]. Qed. End LmodPred. Section LmodPred. Variables (R : pzRingType) (V : lmodType R). Lemma rpredZsign (S : opprClosed V) n u : ((-1) ^+ n *: u \in S) = (u \in S). Proof. by rewrite -signr_odd scaler_sign fun_if if_arg rpredN if_same. Qed. Lemma submodClosedP (modS : submodClosed V) : submod_closed modS. Proof. split; first exact (@rpred0D V modS).1. by move=> a u v uS vS; apply: rpredD; first exact: rpredZ. Qed. End LmodPred. Section LalgPred. Variables (R : pzRingType) (A : lalgType R). Lemma subalgClosedP (algS : subalgClosed A) : subalg_closed algS. Proof. split; [ exact: rpred1 | | exact: rpredM ]. by move=> a u v uS vS; apply: rpredD; first exact: rpredZ. Qed. End LalgPred. Section UnitRingPred. Variable R : unitRingType. Section Div. Variable S : divClosed R. Lemma rpredV x : (x^-1 \in S) = (x \in S). Proof. by apply/idP/idP=> /rpredVr; rewrite ?invrK. Qed. Lemma rpred_div : {in S &, forall x y, x / y \in S}. Proof. by move=> x y Sx Sy; rewrite /= rpredM ?rpredV. Qed. Lemma rpredXN n : {in S, forall x, x ^- n \in S}. Proof. by move=> x Sx; rewrite /= rpredV rpredX. Qed. Lemma rpredMl x y : x \in S -> x \is a unit-> (x * y \in S) = (y \in S). Proof. move=> Sx Ux; apply/idP/idP=> [Sxy | /(rpredM _ _ Sx)-> //]. by rewrite -(mulKr Ux y); rewrite rpredM ?rpredV. Qed. Lemma rpredMr x y : x \in S -> x \is a unit -> (y * x \in S) = (y \in S). Proof. move=> Sx Ux; apply/idP/idP=> [Sxy | /rpredM-> //]. by rewrite -(mulrK Ux y); rewrite rpred_div. Qed. Lemma rpred_divr x y : x \in S -> x \is a unit -> (y / x \in S) = (y \in S). Proof. by rewrite -rpredV -unitrV; apply: rpredMr. Qed. Lemma rpred_divl x y : x \in S -> x \is a unit -> (x / y \in S) = (y \in S). Proof. by rewrite -(rpredV y); apply: rpredMl. Qed. End Div. Lemma divringClosedP (divS : divringClosed R) : divring_closed divS. Proof. split; [ exact: rpred1 | exact: rpredB | exact: rpred_div ]. Qed. Fact unitr_sdivr_closed : @sdivr_closed R unit. Proof. by split=> [|x y Ux Uy]; rewrite ?unitrN1 // unitrMl ?unitrV. Qed. #[export] HB.instance Definition _ := isSdivClosed.Build R unit_pred unitr_sdivr_closed. Implicit Type x : R. Lemma unitrN x : (- x \is a unit) = (x \is a unit). Proof. exact: rpredN. Qed. Lemma invrN x : (- x)^-1 = - x^-1. Proof. have [Ux | U'x] := boolP (x \is a unit); last by rewrite !invr_out ?unitrN. by rewrite -mulN1r invrM ?unitrN1 // invrN1 mulrN1. Qed. Lemma divrNN x y : (- x) / (- y) = x / y. Proof. by rewrite invrN mulrNN. Qed. Lemma divrN x y : x / (- y) = - (x / y). Proof. by rewrite invrN mulrN. Qed. Lemma invr_signM n x : ((-1) ^+ n * x)^-1 = (-1) ^+ n * x^-1. Proof. by rewrite -signr_odd !mulr_sign; case: ifP => // _; rewrite invrN. Qed. Lemma divr_signM (b1 b2 : bool) x1 x2: ((-1) ^+ b1 * x1) / ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 / x2). Proof. by rewrite invr_signM mulr_signM. Qed. End UnitRingPred. Section FieldPred. Variable F : fieldType. Implicit Types x y : F. Section ModuleTheory. Variable V : lmodType F. Implicit Types (a : F) (v : V). Lemma rpredZeq (S : submodClosed V) a v : (a *: v \in S) = (a == 0) || (v \in S). Proof. have [-> | nz_a] := eqVneq; first by rewrite scale0r rpred0. by apply/idP/idP; first rewrite -{2}(scalerK nz_a v); apply: rpredZ. Qed. End ModuleTheory. Section Predicates. Context (S : divClosed F). Lemma fpredMl x y : x \in S -> x != 0 -> (x * y \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpredMl. Qed. Lemma fpredMr x y : x \in S -> x != 0 -> (y * x \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpredMr. Qed. Lemma fpred_divl x y : x \in S -> x != 0 -> (x / y \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpred_divl. Qed. Lemma fpred_divr x y : x \in S -> x != 0 -> (y / x \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpred_divr. Qed. End Predicates. End FieldPred. HB.mixin Record isSubPzSemiRing (R : pzSemiRingType) (S : pred R) U of SubNmodule R S U & PzSemiRing U := { valM_subproof : monoid_morphism (val : U -> R); }. Module isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isSubPzSemiRing.Build instead.")] Notation Build R S U := (isSubPzSemiRing.Build R S U) (only parsing). End isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isSubPzSemiRing instead.")] Notation isSubSemiRing R S U := (isSubPzSemiRing R S U) (only parsing). #[short(type="subPzSemiRingType")] HB.structure Definition SubPzSemiRing (R : pzSemiRingType) (S : pred R) := { U of SubNmodule R S U & PzSemiRing U & isSubPzSemiRing R S U }. #[short(type="subNzSemiRingType")] HB.structure Definition SubNzSemiRing (R : nzSemiRingType) (S : pred R) := { U of SubNmodule R S U & NzSemiRing U & isSubPzSemiRing R S U }. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing instead.")] Notation SubSemiRing R := (SubNzSemiRing R) (only parsing). Module SubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.sort instead.")] Notation sort := (SubNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.on instead.")] Notation on R := (SubNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.copy instead.")] Notation copy T U := (SubNzSemiRing.copy T U) (only parsing). End SubSemiRing. Section multiplicative. Context (R : pzSemiRingType) (S : pred R) (U : SubPzSemiRing.type S). Notation val := (val : U -> R). #[export] HB.instance Definition _ := isMonoidMorphism.Build U R val valM_subproof. Lemma val1 : val 1 = 1. Proof. exact: rmorph1. Qed. Lemma valM : {morph val : x y / x * y}. Proof. exact: rmorphM. Qed. Lemma valM1 : monoid_morphism val. Proof. exact: valM_subproof. Qed. End multiplicative. HB.factory Record SubNmodule_isSubPzSemiRing (R : pzSemiRingType) S U of SubNmodule R S U := { mulr_closed_subproof : mulr_closed S }. HB.builders Context R S U of SubNmodule_isSubPzSemiRing R S U. HB.instance Definition _ := isMulClosed.Build R S mulr_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). Lemma mulrA : associative mulU. Proof. by move=> x y z; apply: val_inj; rewrite !SubK mulrA. Qed. Lemma mul1r : left_id oneU mulU. Proof. by move=> x; apply: val_inj; rewrite !SubK mul1r. Qed. Lemma mulr1 : right_id oneU mulU. Proof. by move=> x; apply: val_inj; rewrite !SubK mulr1. Qed. Lemma mulrDl : left_distributive mulU +%R. Proof. by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDl. Qed. Lemma mulrDr : right_distributive mulU +%R. Proof. by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDr. Qed. Lemma mul0r : left_zero 0%R mulU. Proof. by move=> x; apply: val_inj; rewrite SubK val0 mul0r. Qed. Lemma mulr0 : right_zero 0%R mulU. Proof. by move=> x; apply: val_inj; rewrite SubK val0 mulr0. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build U mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. Lemma valM : monoid_morphism (val : U -> R). Proof. by split=> [|x y] /=; rewrite !SubK. Qed. HB.instance Definition _ := isSubPzSemiRing.Build R S U valM. HB.end. HB.factory Record SubNmodule_isSubNzSemiRing (R : nzSemiRingType) S U of SubNmodule R S U := { mulr_closed_subproof : mulr_closed S }. Module SubNmodule_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNmodule_isSubNzSemiRing.Build instead.")] Notation Build R S U := (SubNmodule_isSubNzSemiRing.Build R S U) (only parsing). End SubNmodule_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNmodule_isSubNzSemiRing instead.")] Notation SubNmodule_isSubSemiRing R S U := (SubNmodule_isSubNzSemiRing R S U) (only parsing). HB.builders Context R S U of SubNmodule_isSubNzSemiRing R S U. HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U mulr_closed_subproof. Lemma oner_neq0 : (1 : U) != 0. Proof. by rewrite -(inj_eq val_inj) SubK raddf0 oner_neq0. Qed. HB.instance Definition _ := PzSemiRing_isNonZero.Build U oner_neq0. HB.end. #[short(type="subComPzSemiRingType")] HB.structure Definition SubComPzSemiRing (R : pzSemiRingType) S := {U of SubPzSemiRing R S U & ComPzSemiRing U}. HB.factory Record SubPzSemiRing_isSubComPzSemiRing (R : comPzSemiRingType) S U of SubPzSemiRing R S U := {}. HB.builders Context R S U of SubPzSemiRing_isSubComPzSemiRing R S U. Lemma mulrC : @commutative U U *%R. Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build U mulrC. HB.end. #[short(type="subComNzSemiRingType")] HB.structure Definition SubComNzSemiRing (R : nzSemiRingType) S := {U of SubNzSemiRing R S U & ComNzSemiRing U}. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing instead.")] Notation SubComSemiRing R := (SubComNzSemiRing R) (only parsing). Module SubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.sort instead.")] Notation sort := (SubComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.on instead.")] Notation on R := (SubComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.copy instead.")] Notation copy T U := (SubComNzSemiRing.copy T U) (only parsing). End SubComSemiRing. HB.factory Record SubNzSemiRing_isSubComNzSemiRing (R : comNzSemiRingType) S U of SubNzSemiRing R S U := {}. Module SubSemiRing_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing_isSubComNzSemiRing.Build instead.")] Notation Build R S U := (SubNzSemiRing_isSubComNzSemiRing.Build R S U) (only parsing). End SubSemiRing_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing_isSubComNzSemiRing instead.")] Notation SubSemiRing_isSubComSemiRing R S U := (SubNzSemiRing_isSubComNzSemiRing R S U) (only parsing). HB.builders Context R S U of SubNzSemiRing_isSubComNzSemiRing R S U. HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U. HB.end. #[short(type="subPzRingType")] HB.structure Definition SubPzRing (R : pzRingType) (S : pred R) := { U of SubPzSemiRing R S U & PzRing U & isSubZmodule R S U }. HB.factory Record SubZmodule_isSubPzRing (R : pzRingType) S U of SubZmodule R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context R S U of SubZmodule_isSubPzRing R S U. HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U (smulr_closedM (subring_closedM subring_closed_subproof)). HB.end. #[short(type="subNzRingType")] HB.structure Definition SubNzRing (R : nzRingType) (S : pred R) := { U of SubNzSemiRing R S U & NzRing U & isSubBaseAddUMagma R S U }. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing instead.")] Notation SubRing R := (SubNzRing R) (only parsing). Module SubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.sort instead.")] Notation sort := (SubNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.on instead.")] Notation on R := (SubNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.copy instead.")] Notation copy T U := (SubNzRing.copy T U) (only parsing). End SubRing. HB.factory Record SubZmodule_isSubNzRing (R : nzRingType) S U of SubZmodule R S U := { subring_closed_subproof : subring_closed S }. Module SubZmodule_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubZmodule_isSubNzRing.Build instead.")] Notation Build R S U := (SubZmodule_isSubNzRing.Build R S U) (only parsing). End SubZmodule_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubZmodule_isSubNzRing instead.")] Notation SubZmodule_isSubRing R S U := (SubZmodule_isSubNzRing R S U) (only parsing). HB.builders Context R S U of SubZmodule_isSubNzRing R S U. HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U (smulr_closedM (subring_closedM subring_closed_subproof)). HB.end. #[short(type="subComPzRingType")] HB.structure Definition SubComPzRing (R : pzRingType) S := {U of SubPzRing R S U & ComPzRing U}. HB.factory Record SubPzRing_isSubComPzRing (R : comPzRingType) S U of SubPzRing R S U := {}. HB.builders Context R S U of SubPzRing_isSubComPzRing R S U. Lemma mulrC : @commutative U U *%R. Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed. HB.instance Definition _ := PzRing_hasCommutativeMul.Build U mulrC. HB.end. #[short(type="subComNzRingType")] HB.structure Definition SubComNzRing (R : nzRingType) S := {U of SubNzRing R S U & ComNzRing U}. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing instead.")] Notation SubComRing R := (SubComNzRing R) (only parsing). Module SubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.sort instead.")] Notation sort := (SubComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.on instead.")] Notation on R := (SubComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.copy instead.")] Notation copy T U := (SubComNzRing.copy T U) (only parsing). End SubComRing. HB.factory Record SubNzRing_isSubComNzRing (R : comNzRingType) S U of SubNzRing R S U := {}. Module SubRing_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_isSubComNzRing.Build instead.")] Notation Build R S U := (SubNzRing_isSubComNzRing.Build R S U) (only parsing). End SubRing_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_isSubComNzRing instead.")] Notation SubRing_isSubComRing R S U := (SubNzRing_isSubComNzRing R S U) (only parsing). HB.builders Context R S U of SubNzRing_isSubComNzRing R S U. HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U. HB.end. HB.mixin Record isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) (S : pred V) W of SubNmodule V S W & LSemiModule R W := { valZ : scalable (val : W -> V); }. #[short(type="subLSemiModType")] HB.structure Definition SubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) (S : pred V) := { W of SubNmodule V S W & Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}. #[short(type="subLmodType")] HB.structure Definition SubLmodule (R : pzRingType) (V : lmodType R) (S : pred V) := { W of SubZmodule V S W & Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}. Section linear. Context (R : pzSemiRingType) (V : lSemiModType R). Context (S : pred V) (W : subLSemiModType S). Notation val := (val : W -> V). #[export] HB.instance Definition _ := isScalable.Build R W V *:%R val valZ. End linear. HB.factory Record isSubLmodule (R : pzRingType) (V : lmodType R) (S : pred V) W of SubZmodule V S W & Lmodule R W := { valZ : scalable (val : W -> V); }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of isSubLmodule R V S W. HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ. HB.end. HB.factory Record SubNmodule_isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) S W of SubNmodule V S W := { submod_closed_subproof : subsemimod_closed S }. HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W of SubNmodule_isSubLSemiModule R V S W. HB.instance Definition _ := isSubSemiModClosed.Build R V S submod_closed_subproof. Let inW v Sv : W := Sub v Sv. Let scaleW a (w : W) := inW (rpredZ a _ (valP w)). Lemma scalerA' a b v : scaleW a (scaleW b v) = scaleW (a * b) v. Proof. by apply: val_inj; rewrite !SubK scalerA. Qed. Lemma scale0r v : scaleW 0 v = 0. Proof. by apply: val_inj; rewrite SubK scale0r raddf0. Qed. Lemma scale1r : left_id 1 scaleW. Proof. by move=> x; apply: val_inj; rewrite SubK scale1r. Qed. Lemma scalerDr : right_distributive scaleW +%R. Proof. by move=> a u v; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK. Qed. Lemma scalerDl v : {morph scaleW^~ v : a b / a + b}. Proof. by move=> a b; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK scalerDl. Qed. HB.instance Definition _ := Nmodule_isLSemiModule.Build R W scalerA' scale0r scale1r scalerDr scalerDl. Fact valZ : scalable (val : W -> _). Proof. by move=> k w; rewrite SubK. Qed. HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ. HB.end. HB.factory Record SubZmodule_isSubLmodule (R : pzRingType) (V : lmodType R) S W of SubZmodule V S W := { submod_closed_subproof : submod_closed S }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of SubZmodule_isSubLmodule R V S W. HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W (submod_closed_semi submod_closed_subproof). HB.end. #[short(type="subLSemiAlgType")] HB.structure Definition SubLSemiAlgebra (R : pzSemiRingType) (V : lSemiAlgType R) S := {W of SubNzSemiRing V S W & @SubLSemiModule R V S W & LSemiAlgebra R W}. #[short(type="subLalgType")] HB.structure Definition SubLalgebra (R : pzRingType) (V : lalgType R) S := {W of SubNzRing V S W & @SubLmodule R V S W & Lalgebra R W}. HB.factory Record SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra (R : pzSemiRingType) (V : lSemiAlgType R) S W of SubNzSemiRing V S W & @SubLSemiModule R V S W := {}. HB.builders Context (R : pzSemiRingType) (V : lSemiAlgType R) S W of SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra R V S W. Lemma scalerAl (a : R) (u v : W) : a *: (u * v) = a *: u * v. Proof. by apply: val_inj; rewrite !(linearZ, rmorphM) /= linearZ scalerAl. Qed. HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R W scalerAl. HB.end. HB.factory Record SubNzRing_SubLmodule_isSubLalgebra (R : pzRingType) (V : lalgType R) S W of SubNzRing V S W & @SubLmodule R V S W := {}. Module SubRing_SubLmodule_isSubLalgebra. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_SubLmodule_isSubLalgebra.Build instead.")] Notation Build R V S U := (SubNzRing_SubLmodule_isSubLalgebra.Build R V S U) (only parsing). End SubRing_SubLmodule_isSubLalgebra. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_SubLmodule_isSubLalgebra instead.")] Notation SubRing_SubLmodule_isSubLalgebra R V S U := (SubNzRing_SubLmodule_isSubLalgebra R V S U) (only parsing). HB.builders Context (R : pzRingType) (V : lalgType R) S W of SubNzRing_SubLmodule_isSubLalgebra R V S W. HB.instance Definition _ := SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build R V S W. HB.end. #[short(type="subSemiAlgType")] HB.structure Definition SubSemiAlgebra (R : pzSemiRingType) (V : semiAlgType R) S := {W of @SubLSemiAlgebra R V S W & SemiAlgebra R W}. #[short(type="subAlgType")] HB.structure Definition SubAlgebra (R : pzRingType) (V : algType R) S := {W of @SubLalgebra R V S W & Algebra R W}. HB.factory Record SubLSemiAlgebra_isSubSemiAlgebra (R : pzSemiRingType) (V : semiAlgType R) S W of @SubLSemiAlgebra R V S W := {}. HB.builders Context (R : pzSemiRingType) (V : semiAlgType R) S W of SubLSemiAlgebra_isSubSemiAlgebra R V S W. Lemma scalerAr (k : R) (x y : W) : k *: (x * y) = x * (k *: y). Proof. by apply: val_inj; rewrite !(linearZ, rmorphM)/= linearZ scalerAr. Qed. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R W scalerAr. HB.end. HB.factory Record SubLalgebra_isSubAlgebra (R : pzRingType) (V : algType R) S W of @SubLalgebra R V S W := {}. HB.builders Context (R : pzRingType) (V : algType R) S W of SubLalgebra_isSubAlgebra R V S W. HB.instance Definition _ := SubLSemiAlgebra_isSubSemiAlgebra.Build R V S W. HB.end. #[short(type="subUnitRingType")] HB.structure Definition SubUnitRing (R : nzRingType) (S : pred R) := {U of SubNzRing R S U & UnitRing U}. HB.factory Record SubNzRing_isSubUnitRing (R : unitRingType) S U of SubNzRing R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : unitRingType) S U of SubNzRing_isSubUnitRing R S U. HB.instance Definition _ := isDivringClosed.Build R S divring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let invU (u : U) := inU (rpredVr _ (valP u)). Lemma mulVr : {in [pred x | val x \is a unit], left_inverse 1 invU *%R}. Proof. by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulVr. Qed. Lemma divrr : {in [pred x | val x \is a unit], right_inverse 1 invU *%R}. by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulrV. Qed. Lemma unitrP (x y : U) : y * x = 1 /\ x * y = 1 -> val x \is a unit. Proof. move=> -[/(congr1 val) yx1 /(congr1 val) xy1]. by apply: rev_unitrP (val y) _; rewrite !rmorphM rmorph1 /= in yx1 xy1. Qed. Lemma invr_out : {in [pred x | val x \isn't a unit], invU =1 id}. Proof. by move=> x /[!inE] xNU; apply: val_inj; rewrite SubK invr_out. Qed. HB.instance Definition _ := NzRing_hasMulInverse.Build U mulVr divrr unitrP invr_out. HB.end. #[short(type="subComUnitRingType")] HB.structure Definition SubComUnitRing (R : comUnitRingType) (S : pred R) := {U of SubComNzRing R S U & SubUnitRing R S U}. #[short(type="subIdomainType")] HB.structure Definition SubIntegralDomain (R : idomainType) (S : pred R) := {U of SubComNzRing R S U & IntegralDomain U}. HB.factory Record SubComUnitRing_isSubIntegralDomain (R : idomainType) S U of SubComUnitRing R S U := {}. HB.builders Context (R : idomainType) S U of SubComUnitRing_isSubIntegralDomain R S U. Lemma id : IntegralDomain.axiom U. Proof. move=> x y /(congr1 val)/eqP; rewrite rmorphM /=. by rewrite -!(inj_eq val_inj) rmorph0 -mulf_eq0. Qed. HB.instance Definition _ := ComUnitRing_isIntegral.Build U id. HB.end. #[short(type="subFieldType")] HB.structure Definition SubField (F : fieldType) (S : pred F) := {U of SubIntegralDomain F S U & Field U}. HB.factory Record SubIntegralDomain_isSubField (F : fieldType) S U of SubIntegralDomain F S U := { subfield_subproof : {mono (val : U -> F) : u / u \in unit} }. HB.builders Context (F : fieldType) S U of SubIntegralDomain_isSubField F S U. Lemma fieldP : Field.axiom U. Proof. by move=> u; rewrite -(inj_eq val_inj) rmorph0 -unitfE subfield_subproof. Qed. HB.instance Definition _ := UnitRing_isField.Build U fieldP. HB.end. HB.factory Record SubChoice_isSubPzSemiRing (R : pzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. HB.builders Context (R : pzSemiRingType) S U of SubChoice_isSubPzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record SubChoice_isSubNzSemiRing (R : nzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. Module SubChoice_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzSemiRing.Build instead.")] Notation Build R S U := (SubChoice_isSubNzSemiRing.Build R S U) (only parsing). End SubChoice_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzSemiRing instead.")] Notation SubChoice_isSubSemiRing R S U := (SubChoice_isSubNzSemiRing R S U) (only parsing). HB.builders Context (R : nzSemiRingType) S U of SubChoice_isSubNzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record SubChoice_isSubComPzSemiRing (R : comPzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. HB.builders Context (R : comPzSemiRingType) S U of SubChoice_isSubComPzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubPzSemiRing.Build R S U semiring_closed_subproof. HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubComNzSemiRing (R : comNzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. Module SubChoice_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzSemiRing.Build instead.")] Notation Build R S U := (SubChoice_isSubComNzSemiRing.Build R S U) (only parsing). End SubChoice_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzSemiRing instead.")] Notation SubChoice_isSubComSemiRing R S U := (SubChoice_isSubComNzSemiRing R S U) (only parsing). HB.builders Context (R : comNzSemiRingType) S U of SubChoice_isSubComNzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNzSemiRing.Build R S U semiring_closed_subproof. HB.instance Definition _ := SubNzSemiRing_isSubComNzSemiRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubPzRing (R : pzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context (R : pzRingType) S U of SubChoice_isSubPzRing R S U. HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U (subring_closedB subring_closed_subproof). HB.instance Definition _ := SubZmodule_isSubPzRing.Build R S U subring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubNzRing (R : nzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. Module SubChoice_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzRing.Build instead.")] Notation Build R S U := (SubChoice_isSubNzRing.Build R S U) (only parsing). End SubChoice_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzRing instead.")] Notation SubChoice_isSubRing R S U := (SubChoice_isSubNzRing R S U) (only parsing). HB.builders Context (R : nzRingType) S U of SubChoice_isSubNzRing R S U. HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U (subring_closedB subring_closed_subproof). HB.instance Definition _ := SubZmodule_isSubNzRing.Build R S U subring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubComPzRing (R : comPzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context (R : comPzRingType) S U of SubChoice_isSubComPzRing R S U. HB.instance Definition _ := SubChoice_isSubPzRing.Build R S U subring_closed_subproof. HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubComNzRing (R : comNzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. Module SubChoice_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzRing.Build instead.")] Notation Build R S U := (SubChoice_isSubComNzRing.Build R S U) (only parsing). End SubChoice_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzRing instead.")] Notation SubChoice_isSubComRing R S U := (SubChoice_isSubComNzRing R S U) (only parsing). HB.builders Context (R : comNzRingType) S U of SubChoice_isSubComNzRing R S U. HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U subring_closed_subproof. HB.instance Definition _ := SubNzRing_isSubComNzRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) S W of SubChoice V S W := { subsemimod_closed_subproof : subsemimod_closed S }. HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W of SubChoice_isSubLSemiModule R V S W. HB.instance Definition _ := SubChoice_isSubNmodule.Build V S W (subsemimod_closedD subsemimod_closed_subproof). HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W subsemimod_closed_subproof. HB.end. HB.factory Record SubChoice_isSubLmodule (R : pzRingType) (V : lmodType R) S W of SubChoice V S W := { submod_closed_subproof : submod_closed S }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of SubChoice_isSubLmodule R V S W. HB.instance Definition _ := SubChoice_isSubZmodule.Build V S W (submod_closedB submod_closed_subproof). HB.instance Definition _ := SubZmodule_isSubLmodule.Build R V S W submod_closed_subproof. HB.end. (* TODO: SubChoice_isSubLSemiAlgebra? *) HB.factory Record SubChoice_isSubLalgebra (R : pzRingType) (A : lalgType R) S W of SubChoice A S W := { subalg_closed_subproof : subalg_closed S }. HB.builders Context (R : pzRingType) (A : lalgType R) S W of SubChoice_isSubLalgebra R A S W. HB.instance Definition _ := SubChoice_isSubNzRing.Build A S W (subalg_closedBM subalg_closed_subproof). HB.instance Definition _ := SubZmodule_isSubLmodule.Build R A S W (subalg_closedZ subalg_closed_subproof). HB.instance Definition _ := SubNzRing_SubLmodule_isSubLalgebra.Build R A S W. HB.end. (* TODO: SubChoice_isSubSemiAlgebra? *) HB.factory Record SubChoice_isSubAlgebra (R : pzRingType) (A : algType R) S W of SubChoice A S W := { subalg_closed_subproof : subalg_closed S }. HB.builders Context (R : pzRingType) (A : algType R) S W of SubChoice_isSubAlgebra R A S W. HB.instance Definition _ := SubChoice_isSubLalgebra.Build R A S W subalg_closed_subproof. HB.instance Definition _ := SubLalgebra_isSubAlgebra.Build R A S W. HB.end. HB.factory Record SubChoice_isSubUnitRing (R : unitRingType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : unitRingType) S U of SubChoice_isSubUnitRing R S U. HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U (divring_closedBM divring_closed_subproof). HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U divring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubComUnitRing (R : comUnitRingType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : comUnitRingType) S U of SubChoice_isSubComUnitRing R S U. HB.instance Definition _ := SubChoice_isSubComNzRing.Build R S U (divring_closedBM divring_closed_subproof). HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U divring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubIntegralDomain (R : idomainType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : idomainType) S U of SubChoice_isSubIntegralDomain R S U. HB.instance Definition _ := SubChoice_isSubComUnitRing.Build R S U divring_closed_subproof. HB.instance Definition _ := SubComUnitRing_isSubIntegralDomain.Build R S U. HB.end. Module SubExports. Notation "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]" := (SubChoice_isSubNmodule.Build _ _ U rpred0D) (format "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]" := (SubChoice_isSubZmodule.Build _ _ U (zmodClosedP _)) (format "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]" := (SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _)) (format "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ SubNmodule_isSubNzSemiRing of U by <: ] instead.")] Notation "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]" := (SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _)) (format "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]" := (SubNzSemiRing_isSubComNzSemiRing.Build _ _ U) (format "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzSemiRing_isSubComNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]" := (SubNzSemiRing_isSubComNzSemiRing.Build _ _ U) (format "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubComNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]" := (SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubZmodule_isSubNzRing' of U by <: ] instead.")] Notation "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]" := (SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubNzRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]" := (SubNzRing_isSubComNzRing.Build _ _ U) (format "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_isSubComNzRing' of U by <: ] instead.")] Notation "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]" := (SubNzRing_isSubComNzRing.Build _ _ U) (format "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubComNzRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]" := (SubNmodule_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _)) (format "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]" := (SubChoice_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _)) (format "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]" := (SubZmodule_isSubLmodule.Build _ _ _ U (submodClosedP _)) (format "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]" := (SubChoice_isSubLmodule.Build _ _ _ U (submodClosedP _)) (format "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]" := (SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build _ _ _ U) (format "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]") : form_scope. (* TODO: SubChoice_isSubLSemiAlgebra? *) Notation "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" := (SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U) (format "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_SubLmodule_isSubLalgebra' of U by <: ] instead.")] Notation "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" := (SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U) (format "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]" := (SubChoice_isSubLalgebra.Build _ _ _ U (subalgClosedP _)) (format "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]" := (SubLSemiAlgebra_isSubSemiAlgebra.Build _ _ _ U) (format "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]") : form_scope. (* TODO: SubChoice_isSubSemiAlgebra? *) Notation "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]" := (SubLalgebra_isSubAlgebra.Build _ _ _ U) (format "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]" := (SubChoice_isSubAlgebra.Build _ _ _ U (subalgClosedP _)) (format "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]" := (SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_isSubUnitRing' of U by <: ] instead.")] Notation "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]" := (SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]" := (SubChoice_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]" := (SubChoice_isSubComUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]" := (SubComUnitRing_isSubIntegralDomain.Build _ _ U) (format "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]" := (SubChoice_isSubIntegralDomain.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]" := (SubIntegralDomain_isSubField.Build _ _ U (frefl _)) (format "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]") : form_scope. End SubExports. HB.export SubExports. Module Theory. Definition addrA := @addrA. Definition addrC := @addrC. Definition add0r := @add0r. Definition addNr := @addNr. Definition addr0 := addr0. Definition addrN := addrN. Definition subrr := subrr. Definition addrCA := addrCA. Definition addrAC := addrAC. Definition addrACA := addrACA. Definition addKr := addKr. Definition addNKr := addNKr. Definition addrK := addrK. Definition addrNK := addrNK. Definition subrK := subrK. Definition subKr := subKr. Definition addrI := @addrI. Definition addIr := @addIr. Definition subrI := @subrI. Definition subIr := @subIr. Arguments addrI {V} y [x1 x2]. Arguments addIr {V} x [x1 x2]. Arguments subrI {V} y [x1 x2]. Arguments subIr {V} x [x1 x2]. Definition opprK := @opprK. Arguments opprK {V}. Definition oppr_inj := @oppr_inj. Arguments oppr_inj {V} [x1 x2]. Definition oppr0 := oppr0. Definition oppr_eq0 := oppr_eq0. Definition opprD := opprD. Definition opprB := opprB. Definition addrKA := addrKA. Definition subrKA := subrKA. Definition subr0 := subr0. Definition sub0r := sub0r. Definition subr_eq := subr_eq. Definition addr0_eq := addr0_eq. Definition subr0_eq := subr0_eq. Definition subr_eq0 := subr_eq0. Definition addr_eq0 := addr_eq0. Definition eqr_opp := eqr_opp. Definition eqr_oppLR := eqr_oppLR. Definition sumrN := sumrN. Definition sumrB := sumrB. Definition sumrMnl := sumrMnl. Definition sumrMnr := sumrMnr. Definition sumr_const := sumr_const. Definition sumr_const_nat := sumr_const_nat. Definition telescope_sumr := telescope_sumr. Definition telescope_sumr_eq := @telescope_sumr_eq. Arguments telescope_sumr_eq {V n m} f u. Definition mulr0n := mulr0n. Definition mulr1n := mulr1n. Definition mulr2n := mulr2n. Definition mulrS := mulrS. Definition mulrSr := mulrSr. Definition mulrb := mulrb. Definition mul0rn := mul0rn. Definition mulNrn := mulNrn. Definition mulrnDl := mulrnDl. Definition mulrnDr := mulrnDr. Definition mulrnBl := mulrnBl. Definition mulrnBr := mulrnBr. Definition mulrnA := mulrnA. Definition mulrnAC := mulrnAC. Definition iter_addr := iter_addr. Definition iter_addr_0 := iter_addr_0. Definition mulrA := @mulrA. Definition mul1r := @mul1r. Definition mulr1 := @mulr1. Definition mulrDl := @mulrDl. Definition mulrDr := @mulrDr. Definition oner_neq0 := @oner_neq0. Definition oner_eq0 := oner_eq0. Definition mul0r := @mul0r. Definition mulr0 := @mulr0. Definition mulrN := mulrN. Definition mulNr := mulNr. Definition mulrNN := mulrNN. Definition mulN1r := mulN1r. Definition mulrN1 := mulrN1. Definition mulr_suml := mulr_suml. Definition mulr_sumr := mulr_sumr. Definition mulrBl := mulrBl. Definition mulrBr := mulrBr. Definition mulrnAl := mulrnAl. Definition mulrnAr := mulrnAr. Definition mulr_natl := mulr_natl. Definition mulr_natr := mulr_natr. Definition natrD := natrD. Definition nat1r := nat1r. Definition natr1 := natr1. Arguments natr1 {R} n. Arguments nat1r {R} n. Definition natrB := natrB. Definition natr_sum := natr_sum. Definition natrM := natrM. Definition natrX := natrX. Definition expr0 := expr0. Definition exprS := exprS. Definition expr1 := expr1. Definition expr2 := expr2. Definition expr0n := expr0n. Definition expr1n := expr1n. Definition exprD := exprD. Definition exprSr := exprSr. Definition expr_sum := expr_sum. Definition commr_sym := commr_sym. Definition commr_refl := commr_refl. Definition commr0 := commr0. Definition commr1 := commr1. Definition commrN := commrN. Definition commrN1 := commrN1. Definition commrD := commrD. Definition commrB := commrB. Definition commr_sum := commr_sum. Definition commr_prod := commr_prod. Definition commrMn := commrMn. Definition commrM := commrM. Definition commr_nat := commr_nat. Definition commrX := commrX. Definition exprMn_comm := exprMn_comm. Definition commr_sign := commr_sign. Definition exprMn_n := exprMn_n. Definition exprM := exprM. Definition exprAC := exprAC. Definition expr_mod := expr_mod. Definition expr_dvd := expr_dvd. Definition signr_odd := signr_odd. Definition signr_eq0 := signr_eq0. Definition mulr_sign := mulr_sign. Definition signr_addb := signr_addb. Definition signrN := signrN. Definition signrE := signrE. Definition mulr_signM := mulr_signM. Definition exprNn := exprNn. Definition sqrrN := sqrrN. Definition sqrr_sign := sqrr_sign. Definition signrMK := signrMK. Definition mulrI_eq0 := mulrI_eq0. Definition lreg_neq0 := lreg_neq0. Definition mulrI0_lreg := mulrI0_lreg. Definition lregN := lregN. Definition lreg1 := lreg1. Definition lregM := lregM. Definition lregX := lregX. Definition lreg_sign := lreg_sign. Definition lregP {R x} := @lregP R x. Definition mulIr_eq0 := mulIr_eq0. Definition mulIr0_rreg := mulIr0_rreg. Definition rreg_neq0 := rreg_neq0. Definition rregN := rregN. Definition rreg1 := rreg1. Definition rregM := rregM. Definition revrX := revrX. Definition rregX := rregX. Definition rregP {R x} := @rregP R x. Definition exprDn_comm := exprDn_comm. Definition exprBn_comm := exprBn_comm. Definition subrXX_comm := subrXX_comm. Definition exprD1n := exprD1n. Definition subrX1 := subrX1. Definition sqrrD1 := sqrrD1. Definition sqrrB1 := sqrrB1. Definition subr_sqr_1 := subr_sqr_1. Definition pcharf0 := pcharf0. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")] Definition charf0 := pcharf0. Definition pcharf_prime := pcharf_prime. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")] Definition charf_prime := pcharf_prime. Definition mulrn_pchar := mulrn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")] Definition mulrn_char := mulrn_pchar. Definition dvdn_pcharf := dvdn_pcharf. #[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")] Definition dvdn_charf := dvdn_pcharf. Definition pcharf_eq := pcharf_eq. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")] Definition charf_eq := pcharf_eq. Definition bin_lt_pcharf_0 := bin_lt_pcharf_0. #[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")] Definition bin_lt_charf_0 := bin_lt_pcharf_0. Definition pFrobenius_autE := pFrobenius_autE. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")] Definition Frobenius_autE := pFrobenius_autE. Definition pFrobenius_aut0 := pFrobenius_aut0. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")] Definition Frobenius_aut0 := pFrobenius_aut0. Definition pFrobenius_aut1 := pFrobenius_aut1. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")] Definition Frobenius_aut1 := pFrobenius_aut1. Definition pFrobenius_autD_comm := pFrobenius_autD_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")] Definition Frobenius_autD_comm := pFrobenius_autD_comm. Definition pFrobenius_autMn := pFrobenius_autMn. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")] Definition Frobenius_autMn := pFrobenius_autMn. Definition pFrobenius_aut_nat := pFrobenius_aut_nat. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")] Definition Frobenius_aut_nat := pFrobenius_aut_nat. Definition pFrobenius_autM_comm := pFrobenius_autM_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")] Definition Frobenius_autM_comm := pFrobenius_autM_comm. Definition pFrobenius_autX := pFrobenius_autX. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")] Definition Frobenius_autX := pFrobenius_autX. Definition pFrobenius_autN := pFrobenius_autN. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")] Definition Frobenius_autN := pFrobenius_autN. Definition pFrobenius_autB_comm := pFrobenius_autB_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")] Definition Frobenius_autB_comm := pFrobenius_autB_comm. Definition exprNn_pchar := exprNn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")] Definition exprNn_char := exprNn_pchar. Definition addrr_pchar2 := addrr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")] Definition addrr_char2 := addrr_pchar2. Definition oppr_pchar2 := oppr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")] Definition oppr_char2 := oppr_pchar2. Definition addrK_pchar2 := addrK_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")] Definition addrK_char2 := addrK_pchar2. Definition addKr_pchar2 := addKr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")] Definition addKr_char2 := addKr_pchar2. Definition iter_mulr := iter_mulr. Definition iter_mulr_1 := iter_mulr_1. Definition prodr_const := prodr_const. Definition prodr_const_nat := prodr_const_nat. Definition mulrC := @mulrC. Definition mulrCA := mulrCA. Definition mulrAC := mulrAC. Definition mulrACA := mulrACA. Definition exprMn := exprMn. Definition prodrXl := prodrXl. Definition prodrXr := prodrXr. Definition prodrN := prodrN. Definition prodrMn_const := prodrMn_const. Definition prodrM_comm := prodrM_comm. Definition prodrMl_comm := prodrMl_comm. Definition prodrMr_comm := prodrMr_comm. Definition prodrMl := prodrMl. Definition prodrMr := prodrMr. Definition prodrMn := prodrMn. Definition rev_prodr := rev_prodr. Definition natr_prod := natr_prod. Definition prodr_undup_exp_count := prodr_undup_exp_count. Definition exprDn := exprDn. Definition exprBn := exprBn. Definition subrXX := subrXX. Definition sqrrD := sqrrD. Definition sqrrB := sqrrB. Definition subr_sqr := subr_sqr. Definition subr_sqrDB := subr_sqrDB. Definition exprDn_pchar := exprDn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")] Definition exprDn_char := exprDn_pchar. Definition mulrV := mulrV. Definition divrr := divrr. Definition mulVr := mulVr. Definition invr_out := invr_out. Definition unitrP {R x} := @unitrP R x. Definition mulKr := mulKr. Definition mulVKr := mulVKr. Definition mulrK := mulrK. Definition mulrVK := mulrVK. Definition divrK := divrK. Definition mulrI := mulrI. Definition mulIr := mulIr. Definition divrI := divrI. Definition divIr := divIr. Definition telescope_prodr := telescope_prodr. Definition telescope_prodr_eq := @telescope_prodr_eq. Arguments telescope_prodr_eq {R n m} f u. Definition commrV := commrV. Definition unitrE := unitrE. Definition invrK := @invrK. Arguments invrK {R}. Definition invr_inj := @invr_inj. Arguments invr_inj {R} [x1 x2]. Definition unitrV := unitrV. Definition unitr1 := unitr1. Definition invr1 := invr1. Definition divr1 := divr1. Definition div1r := div1r. Definition natr_div := natr_div. Definition unitr0 := unitr0. Definition invr0 := invr0. Definition unitrN1 := unitrN1. Definition unitrN := unitrN. Definition invrN1 := invrN1. Definition invrN := invrN. Definition divrNN := divrNN. Definition divrN := divrN. Definition invr_sign := invr_sign. Definition unitrMl := unitrMl. Definition unitrMr := unitrMr. Definition invrM := invrM. Definition unitr_prod := unitr_prod. Definition unitr_prod_in := unitr_prod_in. Definition invr_eq0 := invr_eq0. Definition invr_eq1 := invr_eq1. Definition invr_neq0 := invr_neq0. Definition rev_unitrP := rev_unitrP. Definition rev_prodrV := rev_prodrV. Definition unitrM_comm := unitrM_comm. Definition unitrX := unitrX. Definition unitrX_pos := unitrX_pos. Definition exprVn := exprVn. Definition exprB := exprB. Definition invr_signM := invr_signM. Definition divr_signM := divr_signM. Definition rpred0D := @rpred0D. Definition rpred0 := rpred0. Definition rpredD := rpredD. Definition rpredNr := @rpredNr. Definition rpred_sum := rpred_sum. Definition rpredMn := rpredMn. Definition rpredN := rpredN. Definition rpredB := rpredB. Definition rpredBC := rpredBC. Definition rpredMNn := rpredMNn. Definition rpredDr := rpredDr. Definition rpredDl := rpredDl. Definition rpredBr := rpredBr. Definition rpredBl := rpredBl. Definition zmodClosedP := zmodClosedP. Definition rpredMsign := rpredMsign. Definition rpred1M := @rpred1M. Definition rpred1 := @rpred1. Definition rpredM := @rpredM. Definition rpred_prod := rpred_prod. Definition rpredX := rpredX. Definition rpred_nat := rpred_nat. Definition rpredN1 := rpredN1. Definition rpred_sign := rpred_sign. Definition semiringClosedP := semiringClosedP. Definition subringClosedP := subringClosedP. Definition rpredZsign := rpredZsign. Definition rpredZnat := rpredZnat. Definition submodClosedP := submodClosedP. Definition subalgClosedP := subalgClosedP. Definition rpredZ := @rpredZ. Definition rpredVr := @rpredVr. Definition rpredV := rpredV. Definition rpred_div := rpred_div. Definition rpredXN := rpredXN. Definition rpredZeq := rpredZeq. Definition pchar_lalg := pchar_lalg. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")] Definition char_lalg := pchar_lalg. Definition rpredMr := rpredMr. Definition rpredMl := rpredMl. Definition rpred_divr := rpred_divr. Definition rpred_divl := rpred_divl. Definition divringClosedP := divringClosedP. Definition eq_eval := eq_eval. Definition eval_tsubst := eval_tsubst. Definition eq_holds := eq_holds. Definition holds_fsubst := holds_fsubst. Definition unitrM := unitrM. Definition unitr_prodP := unitr_prodP. Definition prodrV := prodrV. Definition unitrPr {R x} := @unitrPr R x. Definition expr_div_n := expr_div_n. Definition mulr1_eq := mulr1_eq. Definition divr1_eq := divr1_eq. Definition divKr := divKr. Definition mulf_eq0 := mulf_eq0. Definition prodf_eq0 := prodf_eq0. Definition prodf_seq_eq0 := prodf_seq_eq0. Definition mulf_neq0 := mulf_neq0. Definition prodf_neq0 := prodf_neq0. Definition prodf_seq_neq0 := prodf_seq_neq0. Definition expf_eq0 := expf_eq0. Definition sqrf_eq0 := sqrf_eq0. Definition expf_neq0 := expf_neq0. Definition natf_neq0_pchar := natf_neq0_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")] Definition natf_neq0 := natf_neq0_pchar. Definition natf0_pchar := natf0_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")] Definition natf0_char := natf0_pchar. Definition pcharf'_nat := pcharf'_nat. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")] Definition charf'_nat := pcharf'_nat. Definition pcharf0P := pcharf0P. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")] Definition charf0P := pcharf0P. Definition eqf_sqr := eqf_sqr. Definition mulfI := mulfI. Definition mulIf := mulIf. Definition divfI := divfI. Definition divIf := divIf. Definition sqrf_eq1 := sqrf_eq1. Definition expfS_eq1 := expfS_eq1. Definition fieldP := @fieldP. Definition unitfE := unitfE. Definition mulVf := mulVf. Definition mulfV := mulfV. Definition divff := divff. Definition mulKf := mulKf. Definition mulVKf := mulVKf. Definition mulfK := mulfK. Definition mulfVK := mulfVK. Definition divfK := divfK. Definition divKf := divKf. Definition invfM := invfM. Definition invf_div := invf_div. Definition expfB_cond := expfB_cond. Definition expfB := expfB. Definition prodfV := prodfV. Definition prodf_div := prodf_div. Definition telescope_prodf := telescope_prodf. Definition telescope_prodf_eq := @telescope_prodf_eq. Arguments telescope_prodf_eq {F n m} f u. Definition addf_div := addf_div. Definition mulf_div := mulf_div. Definition eqr_div := eqr_div. Definition eqr_sum_div := eqr_sum_div. Definition pchar0_natf_div := pchar0_natf_div. #[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")] Definition char0_natf_div := pchar0_natf_div. Definition fpredMr := fpredMr. Definition fpredMl := fpredMl. Definition fpred_divr := fpred_divr. Definition fpred_divl := fpred_divl. Definition satP {F e f} := @satP F e f. Definition eq_sat := eq_sat. Definition solP {F n f} := @solP F n f. Definition eq_sol := eq_sol. Definition size_sol := size_sol. Definition solve_monicpoly := @solve_monicpoly. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `nmod_morphism` instead")] Definition semi_additive := semi_additive. Definition nmod_morphism := nmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism` instead")] Definition additive := additive. Definition zmod_morphism := zmod_morphism. Definition raddf0 := raddf0. Definition raddf_eq0 := raddf_eq0. Definition raddf_inj := raddf_inj. Definition raddfN := raddfN. Definition raddfD := raddfD. Definition raddfB := raddfB. Definition raddf_sum := raddf_sum. Definition raddfMn := raddfMn. Definition raddfMNn := raddfMNn. Definition raddfMnat := raddfMnat. Definition raddfMsign := raddfMsign. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_nmod_morphism` instead")] Definition can2_semi_additive := can2_semi_additive. Definition can2_nmod_morphism := can2_nmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_zmod_morphism` instead")] Definition can2_additive := can2_additive. Definition can2_zmod_morphism := can2_zmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")] Definition multiplicative := multiplicative. Definition monoid_morphism := monoid_morphism. Definition rmorph0 := rmorph0. Definition rmorphN := rmorphN. Definition rmorphD := rmorphD. Definition rmorphB := rmorphB. Definition rmorph_sum := rmorph_sum. Definition rmorphMn := rmorphMn. Definition rmorphMNn := rmorphMNn. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `rmorphism_monoidP` instead")] Definition rmorphismMP := rmorphismMP. Definition rmorphism_monoidP := rmorphism_monoidP. Definition rmorph1 := rmorph1. Definition rmorph_eq1 := rmorph_eq1. Definition rmorphM := rmorphM. Definition rmorphMsign := rmorphMsign. Definition rmorph_nat := rmorph_nat. Definition rmorph_eq_nat := rmorph_eq_nat. Definition rmorph_prod := rmorph_prod. Definition rmorphXn := rmorphXn. Definition rmorphN1 := rmorphN1. Definition rmorph_sign := rmorph_sign. Definition rmorph_pchar := rmorph_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")] Definition rmorph_char := rmorph_pchar. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_monoid_morphism` instead")] Definition can2_rmorphism := can2_rmorphism. Definition can2_monoid_morphism := can2_monoid_morphism. Definition rmorph_comm := rmorph_comm. Definition rmorph_unit := rmorph_unit. Definition rmorphV := rmorphV. Definition rmorph_div := rmorph_div. Definition fmorph_eq0 := fmorph_eq0. Definition fmorph_inj := @fmorph_inj. Arguments fmorph_inj {F R} f [x1 x2]. Definition fmorph_eq := fmorph_eq. Definition fmorph_eq1 := fmorph_eq1. Definition fmorph_pchar := fmorph_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")] Definition fmorph_char := fmorph_pchar. Definition fmorph_unit := fmorph_unit. Definition fmorphV := fmorphV. Definition fmorph_div := fmorph_div. Definition scalerA := scalerA. Definition scale1r := @scale1r. Definition scalerDr := @scalerDr. Definition scalerDl := @scalerDl. Definition scaler0 := scaler0. Definition scale0r := @scale0r. Definition scaleNr := scaleNr. Definition scaleN1r := scaleN1r. Definition scalerN := scalerN. Definition scalerBl := scalerBl. Definition scalerBr := scalerBr. Definition scaler_nat := scaler_nat. Definition scalerMnl := scalerMnl. Definition scalerMnr := scalerMnr. Definition scaler_suml := scaler_suml. Definition scaler_sumr := scaler_sumr. Definition scaler_eq0 := scaler_eq0. Definition scalerK := scalerK. Definition scalerKV := scalerKV. Definition scalerI := scalerI. Definition scalerAl := @scalerAl. Definition mulr_algl := mulr_algl. Definition scaler_sign := scaler_sign. Definition signrZK := signrZK. Definition scalerCA := scalerCA. Definition scalerAr := @scalerAr. Definition mulr_algr := mulr_algr. Definition comm_alg := comm_alg. Definition exprZn := exprZn. Definition scaler_prodl := scaler_prodl. Definition scaler_prodr := scaler_prodr. Definition scaler_prod := scaler_prod. Definition scaler_injl := scaler_injl. Definition scaler_unit := scaler_unit. Definition invrZ := invrZ. Definition raddfZnat := raddfZnat. Definition raddfZsign := raddfZsign. Definition in_algE := in_algE. Definition scalable_for := scalable_for. Definition semilinear_for := semilinear_for. Definition linear_for := linear_for. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `nmod_morphism_semilinear` instead")] Definition additive_semilinear := additive_semilinear. Definition nmod_morphism_semilinear := nmod_morphism_semilinear. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism_linear` instead")] Definition additive_linear := additive_linear. Definition zmod_morphism_linear := zmod_morphism_linear. Definition scalable_semilinear := scalable_semilinear. Definition scalable_linear := scalable_linear. Definition linear0 := linear0. Definition linearN := linearN. Definition linearD := linearD. Definition linearB := linearB. Definition linear_sum := linear_sum. Definition linearMn := linearMn. Definition linearMNn := linearMNn. Definition semilinearP := semilinearP. Definition linearP := linearP. Definition linearZ_LR := linearZ_LR. Definition linearZ := linearZ. Definition semilinearPZ := semilinearPZ. Definition linearPZ := linearPZ. Definition linearZZ := linearZZ. Definition semiscalarP := semiscalarP. Definition scalarP := scalarP. Definition scalarZ := scalarZ. Definition can2_scalable := can2_scalable. Definition can2_linear := can2_linear. Definition can2_semilinear := can2_semilinear. Definition rmorph_alg := rmorph_alg. Definition imaginary_exists := imaginary_exists. Definition raddf := (raddf0, raddfN, raddfD, raddfMn). Definition rmorphE := (rmorphD, rmorph0, rmorphB, rmorphN, rmorphMNn, rmorphMn, rmorph1, rmorphXn). Definition linearE := (linearD, linear0, linearB, linearMNn, linearMn, linearZ). Notation null_fun V := (null_fun V) (only parsing). Notation in_alg A := (in_alg A) (only parsing). End Theory. Module AllExports. HB.reexport. End AllExports. End GRing. Export AllExports. Export Scale.Exports. Export ClosedExports. #[deprecated(since="mathcomp 2.4.0", note="Try pzSemiRingType (the potentially-zero counterpart) first, or use nzSemiRingType instead.")] Notation semiRingType := (nzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try pzRingType (the potentially-zero counterpart) first, or use nzRingType instead.")] Notation ringType := (nzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try comPzSemiRingType (the potentially-zero counterpart) first, or use comNzSemiRingType instead.")] Notation comSemiRingType := (comNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try comPzRingType (the potentially-zero counterpart) first, or use comNzRingType instead.")] Notation comRingType := (comNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subPzSemiRingType (the potentially-zero counterpart) first, or use subNzSemiRingType instead.")] Notation subSemiRingType := (subNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subComPzSemiRingType (the potentially-zero counterpart) first, or use subComNzSemiRingType instead.")] Notation subComSemiRingType := (subComNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subPzRingType (the potentially-zero counterpart) first, or use subNzRingType instead.")] Notation subRingType := (subNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subComPzRingType (the potentially-zero counterpart) first, or use subComNzRingType instead.")] Notation subComNzRingType := (subComNzRingType) (only parsing). Notation addrClosed := addrClosed. Notation opprClosed := opprClosed. Variant Ione := IOne : Ione. Inductive Inatmul := | INatmul : Ione -> nat -> Inatmul | IOpp : Inatmul -> Inatmul. Variant Idummy_placeholder :=. Definition parse (x : Number.int) : Inatmul := match x with | Number.IntDecimal (Decimal.Pos u) => INatmul IOne (Nat.of_uint u) | Number.IntDecimal (Decimal.Neg u) => IOpp (INatmul IOne (Nat.of_uint u)) | Number.IntHexadecimal (Hexadecimal.Pos u) => INatmul IOne (Nat.of_hex_uint u) | Number.IntHexadecimal (Hexadecimal.Neg u) => IOpp (INatmul IOne (Nat.of_hex_uint u)) end. Definition print (x : Inatmul) : option Number.int := match x with | INatmul IOne n => Some (Number.IntDecimal (Decimal.Pos (Nat.to_uint n))) | IOpp (INatmul IOne n) => Some (Number.IntDecimal (Decimal.Neg (Nat.to_uint n))) | _ => None end. Arguments GRing.one {_}. Set Warnings "-via-type-remapping,-via-type-mismatch". Number Notation Idummy_placeholder parse print (via Inatmul mapping [[natmul] => INatmul, [opp] => IOpp, [one] => IOne]) : ring_scope. Set Warnings "via-type-remapping,via-type-mismatch". Arguments GRing.one : clear implicits. Notation "0" := (@zero _) : ring_scope. Notation "-%R" := (@opp _) : ring_scope. Notation "- x" := (opp x) : ring_scope. Notation "+%R" := (@add _) : function_scope. Notation "x + y" := (add x y) : ring_scope. Notation "x - y" := (add x (- y)) : ring_scope. Arguments natmul : simpl never. Notation "x *+ n" := (natmul x n) : ring_scope. Notation "x *- n" := (opp (x *+ n)) : ring_scope. Notation "s `_ i" := (seq.nth 0%R s%R i) : ring_scope. Notation support := 0.-support. Notation "1" := (@one _) : ring_scope. Notation "- 1" := (opp 1) : ring_scope. Notation "n %:R" := (natmul 1 n) : ring_scope. Arguments GRing.pchar R%_type. Notation "[ 'pchar' R ]" := (GRing.pchar R) : ring_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [pchar R] instead.")] Notation "[ 'char' R ]" := (GRing.pchar R) : ring_scope. Notation has_pchar0 R := (GRing.pchar R =i pred0). #[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")] Notation has_char0 R := (GRing.pchar R =i pred0). Notation pFrobenius_aut chRp := (pFrobenius_aut chRp). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")] Notation Frobenius_aut chRp := (pFrobenius_aut chRp). Notation "*%R" := (@mul _) : function_scope. Notation "x * y" := (mul x y) : ring_scope. Arguments exp : simpl never. Notation "x ^+ n" := (exp x n) : ring_scope. Notation "x ^-1" := (inv x) : ring_scope. Notation "x ^- n" := (inv (x ^+ n)) : ring_scope. Notation "x / y" := (mul x y^-1) : ring_scope. Notation "*:%R" := (@scale _ _) : function_scope. Notation "a *: m" := (scale a m) : ring_scope. Notation "k %:A" := (scale k 1) : ring_scope. Notation "\0" := (null_fun _) : ring_scope. Notation "f \+ g" := (add_fun f g) : ring_scope. Notation "f \- g" := (sub_fun f g) : ring_scope. Notation "\- f" := (opp_fun f) : ring_scope. Notation "a \*: f" := (scale_fun a f) : ring_scope. Notation "x \*o f" := (mull_fun x f) : ring_scope. Notation "x \o* f" := (mulr_fun x f) : ring_scope. Notation "f \* g" := (mul_fun f g) : ring_scope. Arguments mull_fun {_ _} a f _ /. Arguments mulr_fun {_ _} a f _ /. Arguments scale_fun {_ _ _} a f _ /. Arguments mul_fun {_ _} f g _ /. Notation "\sum_ ( i <- r | P ) F" := (\big[+%R/0%R]_(i <- r | P%B) F%R) : ring_scope. Notation "\sum_ ( i <- r ) F" := (\big[+%R/0%R]_(i <- r) F%R) : ring_scope. Notation "\sum_ ( m <= i < n | P ) F" := (\big[+%R/0%R]_(m <= i < n | P%B) F%R) : ring_scope. Notation "\sum_ ( m <= i < n ) F" := (\big[+%R/0%R]_(m <= i < n) F%R) : ring_scope. Notation "\sum_ ( i | P ) F" := (\big[+%R/0%R]_(i | P%B) F%R) : ring_scope. Notation "\sum_ i F" := (\big[+%R/0%R]_i F%R) : ring_scope. Notation "\sum_ ( i : t | P ) F" := (\big[+%R/0%R]_(i : t | P%B) F%R) (only parsing) : ring_scope. Notation "\sum_ ( i : t ) F" := (\big[+%R/0%R]_(i : t) F%R) (only parsing) : ring_scope. Notation "\sum_ ( i < n | P ) F" := (\big[+%R/0%R]_(i < n | P%B) F%R) : ring_scope. Notation "\sum_ ( i < n ) F" := (\big[+%R/0%R]_(i < n) F%R) : ring_scope. Notation "\sum_ ( i 'in' A | P ) F" := (\big[+%R/0%R]_(i in A | P%B) F%R) : ring_scope. Notation "\sum_ ( i 'in' A ) F" := (\big[+%R/0%R]_(i in A) F%R) : ring_scope. Notation "\prod_ ( i <- r | P ) F" := (\big[*%R/1%R]_(i <- r | P%B) F%R) : ring_scope. Notation "\prod_ ( i <- r ) F" := (\big[*%R/1%R]_(i <- r) F%R) : ring_scope. Notation "\prod_ ( m <= i < n | P ) F" := (\big[*%R/1%R]_(m <= i < n | P%B) F%R) : ring_scope. Notation "\prod_ ( m <= i < n ) F" := (\big[*%R/1%R]_(m <= i < n) F%R) : ring_scope. Notation "\prod_ ( i | P ) F" := (\big[*%R/1%R]_(i | P%B) F%R) : ring_scope. Notation "\prod_ i F" := (\big[*%R/1%R]_i F%R) : ring_scope. Notation "\prod_ ( i : t | P ) F" := (\big[*%R/1%R]_(i : t | P%B) F%R) (only parsing) : ring_scope. Notation "\prod_ ( i : t ) F" := (\big[*%R/1%R]_(i : t) F%R) (only parsing) : ring_scope. Notation "\prod_ ( i < n | P ) F" := (\big[*%R/1%R]_(i < n | P%B) F%R) : ring_scope. Notation "\prod_ ( i < n ) F" := (\big[*%R/1%R]_(i < n) F%R) : ring_scope. Notation "\prod_ ( i 'in' A | P ) F" := (\big[*%R/1%R]_(i in A | P%B) F%R) : ring_scope. Notation "\prod_ ( i 'in' A ) F" := (\big[*%R/1%R]_(i in A) F%R) : ring_scope. Notation "R ^c" := (converse R) : type_scope. Notation "R ^o" := (regular R) : type_scope. Bind Scope term_scope with term. Bind Scope term_scope with formula. Notation "''X_' i" := (Var _ i) : term_scope. Notation "n %:R" := (NatConst _ n) : term_scope. Notation "0" := 0%:R%T : term_scope. Notation "1" := 1%:R%T : term_scope. Notation "x %:T" := (Const x) : term_scope. Infix "+" := Add : term_scope. Notation "- t" := (Opp t) : term_scope. Notation "t - u" := (Add t (- u)) : term_scope. Infix "*" := Mul : term_scope. Infix "*+" := NatMul : term_scope. Notation "t ^-1" := (Inv t) : term_scope. Notation "t / u" := (Mul t u^-1) : term_scope. Infix "^+" := Exp : term_scope. Infix "==" := Equal : term_scope. Notation "x != y" := (GRing.Not (x == y)) : term_scope. Infix "/\" := And : term_scope. Infix "\/" := Or : term_scope. Infix "==>" := Implies : term_scope. Notation "~ f" := (Not f) : term_scope. Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope. Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope. (* Lifting Structure from the codomain of finfuns. *) Section Sum. Variables (aT : finType) (rT : nmodType). Variables (I : Type) (r : seq I) (P : pred I) (F : I -> {ffun aT -> rT}). Lemma sum_ffunE x : (\sum_(i <- r | P i) F i) x = \sum_(i <- r | P i) F i x. Proof. by elim/big_rec2: _ => // [|i _ y _ <-]; rewrite !ffunE. Qed. Lemma sum_ffun : \sum_(i <- r | P i) F i = [ffun x => \sum_(i <- r | P i) F i x]. Proof. by apply/ffunP=> i; rewrite sum_ffunE ffunE. Qed. End Sum. Section FinFunSemiRing. (* As rings require 1 != 0 in order to lift a ring structure over finfuns *) (* we need evidence that the domain is non-empty. *) Variable (aT : finType) (R : pzSemiRingType). Definition ffun_one : {ffun aT -> R} := [ffun => 1]. Definition ffun_mul (f g : {ffun aT -> R}) := [ffun x => f x * g x]. Fact ffun_mulA : associative ffun_mul. Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrA. Qed. Fact ffun_mul_1l : left_id ffun_one ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul1r. Qed. Fact ffun_mul_1r : right_id ffun_one ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr1. Qed. Fact ffun_mul_addl : left_distributive ffun_mul (@ffun_add _ _). Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDl. Qed. Fact ffun_mul_addr : right_distributive ffun_mul (@ffun_add _ _). Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDr. Qed. Fact ffun_mul_0l : left_zero (@ffun_zero _ _) ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul0r. Qed. Fact ffun_mul_0r : right_zero (@ffun_zero _ _) ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr0. Qed. #[export] HB.instance Definition _ := Nmodule_isPzSemiRing.Build {ffun aT -> R} ffun_mulA ffun_mul_1l ffun_mul_1r ffun_mul_addl ffun_mul_addr ffun_mul_0l ffun_mul_0r. Definition ffun_semiring : pzSemiRingType := {ffun aT -> R}. End FinFunSemiRing. Section FinFunSemiRing. Variable (aT : finType) (R : nzSemiRingType) (a : aT). Fact ffun1_nonzero : ffun_one aT R != 0. Proof. by apply/eqP => /ffunP/(_ a)/eqP; rewrite !ffunE oner_eq0. Qed. (* TODO_HB uncomment once ffun_ring below is fixed #[export] HB.instance Definition _ := PzSemiRing_isNonZero.Build {ffun aT -> R} ffun1_nonzero. *) End FinFunSemiRing. HB.instance Definition _ (aT : finType) (R : pzRingType) := Zmodule_isPzRing.Build {ffun aT -> R} (@ffun_mulA _ _) (@ffun_mul_1l _ _) (@ffun_mul_1r _ _) (@ffun_mul_addl _ _) (@ffun_mul_addr _ _). (* As nzRings require 1 != 0 in order to lift a ring structure over finfuns *) (* we need evidence that the domain is non-empty. *) Section FinFunRing. Variable (aT : finType) (R : nzRingType) (a : aT). (* TODO_HB: doesn't work in combination with ffun_semiring above *) HB.instance Definition _ := PzSemiRing_isNonZero.Build {ffun aT -> R} (@ffun1_nonzero _ _ a). Definition ffun_ring : nzRingType := {ffun aT -> R}. End FinFunRing. (* TODO_HB do FinFunComSemiRing once above is fixed *) Section FinFunComRing. Variable (aT : finType) (R : comPzRingType) (a : aT). Fact ffun_mulC : commutative (@ffun_mul aT R). Proof. by move=> f1 f2; apply/ffunP=> i; rewrite !ffunE mulrC. Qed. (* TODO_HB #[export] HB.instance Definition _ := Ring_hasCommutativeMul.Build (ffun_ring _ a) ffun_mulC. *) End FinFunComRing. Section FinFunLSemiMod. Variable (R : pzSemiRingType) (aT : finType) (rT : lSemiModType R). Implicit Types f g : {ffun aT -> rT}. Definition ffun_scale k f := [ffun a => k *: f a]. Fact ffun_scaleA k1 k2 f : ffun_scale k1 (ffun_scale k2 f) = ffun_scale (k1 * k2) f. Proof. by apply/ffunP=> a; rewrite !ffunE scalerA. Qed. Fact ffun_scale0r f : ffun_scale 0 f = 0. Proof. by apply/ffunP=> a; rewrite !ffunE scale0r. Qed. Fact ffun_scale1 : left_id 1 ffun_scale. Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE scale1r. Qed. Fact ffun_scale_addr k : {morph (ffun_scale k) : x y / x + y}. Proof. by move=> f g; apply/ffunP=> a; rewrite !ffunE scalerDr. Qed. Fact ffun_scale_addl u : {morph (ffun_scale)^~ u : k1 k2 / k1 + k2}. Proof. by move=> k1 k2; apply/ffunP=> a; rewrite !ffunE scalerDl. Qed. #[export] HB.instance Definition _ := Nmodule_isLSemiModule.Build R {ffun aT -> rT} ffun_scaleA ffun_scale0r ffun_scale1 ffun_scale_addr ffun_scale_addl. End FinFunLSemiMod. #[export] HB.instance Definition _ (R : pzRingType) (aT : finType) (rT : lmodType R) := LSemiModule.on {ffun aT -> rT}. (* External direct product. *) Section PairSemiRing. Variables R1 R2 : pzSemiRingType. Definition mul_pair (x y : R1 * R2) := (x.1 * y.1, x.2 * y.2). Fact pair_mulA : associative mul_pair. Proof. by move=> x y z; congr (_, _); apply: mulrA. Qed. Fact pair_mul1l : left_id (1, 1) mul_pair. Proof. by case=> x1 x2; congr (_, _); apply: mul1r. Qed. Fact pair_mul1r : right_id (1, 1) mul_pair. Proof. by case=> x1 x2; congr (_, _); apply: mulr1. Qed. Fact pair_mulDl : left_distributive mul_pair +%R. Proof. by move=> x y z; congr (_, _); apply: mulrDl. Qed. Fact pair_mulDr : right_distributive mul_pair +%R. Proof. by move=> x y z; congr (_, _); apply: mulrDr. Qed. Fact pair_mul0r : left_zero 0 mul_pair. Proof. by move=> x; congr (_, _); apply: mul0r. Qed. Fact pair_mulr0 : right_zero 0 mul_pair. Proof. by move=> x; congr (_, _); apply: mulr0. Qed. #[export] HB.instance Definition _ := Nmodule_isPzSemiRing.Build (R1 * R2)%type pair_mulA pair_mul1l pair_mul1r pair_mulDl pair_mulDr pair_mul0r pair_mulr0. Fact fst_is_monoid_morphism : monoid_morphism fst. Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R1 fst fst_is_monoid_morphism. Fact snd_is_monoid_morphism : monoid_morphism snd. Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R2 snd snd_is_monoid_morphism. End PairSemiRing. Section PairSemiRing. Variables R1 R2 : nzSemiRingType. Fact pair_one_neq0 : 1 != 0 :> R1 * R2. Proof. by rewrite xpair_eqE oner_eq0. Qed. #[export] HB.instance Definition _ := PzSemiRing_isNonZero.Build (R1 * R2)%type pair_one_neq0. End PairSemiRing. Section PairComSemiRing. Variables R1 R2 : comPzSemiRingType. Fact pair_mulC : commutative (@mul_pair R1 R2). Proof. by move=> x y; congr (_, _); apply: mulrC. Qed. #[export] HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build (R1 * R2)%type pair_mulC. End PairComSemiRing. (* TODO: HB.saturate *) #[export] HB.instance Definition _ (R1 R2 : comNzSemiRingType) := NzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : pzRingType) := PzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : nzRingType) := NzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : comPzRingType) := PzRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : comNzRingType) := NzRing.on (R1 * R2)%type. (* /TODO *) Section PairLSemiMod. Variables (R : pzSemiRingType) (V1 V2 : lSemiModType R). Definition scale_pair a (v : V1 * V2) : V1 * V2 := (a *: v.1, a *: v.2). Fact pair_scaleA a b u : scale_pair a (scale_pair b u) = scale_pair (a * b) u. Proof. by congr (_, _); apply: scalerA. Qed. Fact pair_scale0 u : scale_pair 0 u = 0. Proof. by case: u => u1 u2; congr (_, _); apply: scale0r. Qed. Fact pair_scale1 u : scale_pair 1 u = u. Proof. by case: u => u1 u2; congr (_, _); apply: scale1r. Qed. Fact pair_scaleDr : right_distributive scale_pair +%R. Proof. by move=> a u v; congr (_, _); apply: scalerDr. Qed. Fact pair_scaleDl u : {morph scale_pair^~ u: a b / a + b}. Proof. by move=> a b; congr (_, _); apply: scalerDl. Qed. #[export] HB.instance Definition _ := Nmodule_isLSemiModule.Build R (V1 * V2)%type pair_scaleA pair_scale0 pair_scale1 pair_scaleDr pair_scaleDl. Fact fst_is_scalable : scalable fst. Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R (V1 * V2)%type V1 *:%R fst fst_is_scalable. Fact snd_is_scalable : scalable snd. Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R (V1 * V2)%type V2 *:%R snd snd_is_scalable. End PairLSemiMod. Section PairLSemiAlg. Variables (R : pzSemiRingType) (A1 A2 : lSemiAlgType R). Fact pair_scaleAl a (u v : A1 * A2) : a *: (u * v) = (a *: u) * v. Proof. by congr (_, _); apply: scalerAl. Qed. #[export] HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R (A1 * A2)%type pair_scaleAl. (* TODO: HB.saturate *) #[export] HB.instance Definition _ := RMorphism.on (@fst A1 A2). #[export] HB.instance Definition _ := RMorphism.on (@snd A1 A2). (* /TODO *) End PairLSemiAlg. Section PairSemiAlg. Variables (R : pzSemiRingType) (A1 A2 : semiAlgType R). Fact pair_scaleAr a (u v : A1 * A2) : a *: (u * v) = u * (a *: v). Proof. by congr (_, _); apply: scalerAr. Qed. #[export] HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R (A1 * A2)%type pair_scaleAr. End PairSemiAlg. Section PairUnitRing. Variables R1 R2 : unitRingType. Definition pair_unitr := [qualify a x : R1 * R2 | (x.1 \is a GRing.unit) && (x.2 \is a GRing.unit)]. Definition pair_invr x := if x \is a pair_unitr then (x.1^-1, x.2^-1) else x. Lemma pair_mulVl : {in pair_unitr, left_inverse 1 pair_invr *%R}. Proof. rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _. by congr (_, _); apply: mulVr. Qed. Lemma pair_mulVr : {in pair_unitr, right_inverse 1 pair_invr *%R}. Proof. rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _. by congr (_, _); apply: mulrV. Qed. Lemma pair_unitP x y : y * x = 1 /\ x * y = 1 -> x \is a pair_unitr. Proof. case=> [[y1x y2x] [x1y x2y]]; apply/andP. by split; apply/unitrP; [exists y.1 | exists y.2]. Qed. Lemma pair_invr_out : {in [predC pair_unitr], pair_invr =1 id}. Proof. by rewrite /pair_invr => x /negPf/= ->. Qed. #[export] HB.instance Definition _ := NzRing_hasMulInverse.Build (R1 * R2)%type pair_mulVl pair_mulVr pair_unitP pair_invr_out. End PairUnitRing. (* TODO: HB.saturate *) #[export] HB.instance Definition _ (R1 R2 : comUnitRingType) := UnitRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R : pzSemiRingType) (A1 A2 : comSemiAlgType R) := SemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (V1 V2 : lmodType R) := LSemiModule.on (V1 * V2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : lalgType R) := LSemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : algType R) := SemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : comAlgType R) := Algebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : unitAlgType R) := Algebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : comUnitAlgType R) := Algebra.on (A1 * A2)%type. (* /TODO *) Lemma pairMnE (M1 M2 : zmodType) (x : M1 * M2) n : x *+ n = (x.1 *+ n, x.2 *+ n). Proof. by case: x => x y; elim: n => //= n; rewrite !mulrS => ->. Qed. (* begin hide *) (* Testing subtype hierarchy Section Test0. Variables (T : choiceType) (S : {pred T}). Inductive B := mkB x & x \in S. Definition vB u := let: mkB x _ := u in x. HB.instance Definition _ := [isSub for vB]. HB.instance Definition _ := [Choice of B by <:]. End Test0. Section Test1. Variables (R : unitRingType) (S : divringClosed R). HB.instance Definition _ := [SubChoice_isSubUnitRing of B S by <:]. End Test1. Section Test2. Variables (R : comUnitRingType) (A : unitAlgType R) (S : divalgClosed A). HB.instance Definition _ := [SubZmodule_isSubLmodule of B S by <:]. HB.instance Definition _ := [SubNzRing_SubLmodule_isSubLalgebra of B S by <:]. HB.instance Definition _ := [SubLalgebra_isSubAlgebra of B S by <:]. End Test2. Section Test3. Variables (F : fieldType) (S : divringClosed F). HB.instance Definition _ := [SubRing_isSubComNzRing of B S by <:]. HB.instance Definition _ := [SubComUnitRing_isSubIntegralDomain of B S by <:]. HB.instance Definition _ := [SubIntegralDomain_isSubField of B S by <:]. End Test3. *) (* end hide *) (* Algebraic structure of bool *) HB.instance Definition _ := Zmodule_isComNzRing.Build bool andbA andbC andTb andb_addl isT. Fact mulVb (b : bool) : b != 0 -> b * b = 1. Proof. by case: b. Qed. Fact invb_out (x y : bool) : y * x = 1 -> x != 0. Proof. by case: x; case: y. Qed. HB.instance Definition _ := ComNzRing_hasMulInverse.Build bool mulVb invb_out (fun x => fun => erefl x). Lemma bool_fieldP : Field.axiom bool. Proof. by []. Qed. HB.instance Definition _ := ComUnitRing_isField.Build bool bool_fieldP. (* Algebraic structure of nat *) HB.instance Definition _ := Nmodule_isComNzSemiRing.Build nat mulnA mulnC mul1n mulnDl mul0n erefl. HB.instance Definition _ (R : pzSemiRingType) := isMonoidMorphism.Build nat R (natmul 1) (mulr1n 1, natrM R). Lemma natr0E : 0 = 0%N. Proof. by []. Qed. Lemma natr1E : 1 = 1%N. Proof. by []. Qed. Lemma natn n : n%:R = n. Proof. by elim: n => [//|n IHn]; rewrite -nat1r IHn. Qed. Lemma natrDE n m : n + m = (n + m)%N. Proof. by []. Qed. Lemma natrME n m : n * m = (n * m)%N. Proof. by []. Qed. Lemma natrXE n m : n ^+ m = (n ^ m)%N. Proof. by []. Qed. Definition natrE := (natr0E, natr1E, natn, natrDE, natrME, natrXE).
Rfl.lean
/- Copyright (c) 2022 Newell Jensen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Newell Jensen -/ import Mathlib.Init import Lean.Meta.Tactic.Rfl /-! # `Lean.MVarId.liftReflToEq` Convert a goal of the form `x ~ y` into the form `x = y`, where `~` is a reflexive relation, that is, a relation which has a reflexive lemma tagged with the attribute `[refl]`. If this can't be done, returns the original `MVarId`. -/ namespace Mathlib.Tactic open Lean Meta Elab Tactic Rfl /-- This tactic applies to a goal whose target has the form `x ~ x`, where `~` is a reflexive relation, that is, a relation which has a reflexive lemma tagged with the attribute [refl]. -/ def rflTac : TacticM Unit := withMainContext do liftMetaFinishingTactic (·.applyRfl) /-- If `e` is the form `@R .. x y`, where `R` is a reflexive relation, return `some (R, x, y)`. As a special case, if `e` is `@HEq α a β b`, return ``some (`HEq, a, b)``. -/ def _root_.Lean.Expr.relSidesIfRefl? (e : Expr) : MetaM (Option (Name × Expr × Expr)) := do if let some (_, lhs, rhs) := e.eq? then return (``Eq, lhs, rhs) if let some (lhs, rhs) := e.iff? then return (``Iff, lhs, rhs) if let some (_, lhs, _, rhs) := e.heq? then return (``HEq, lhs, rhs) if let .app (.app rel lhs) rhs := e then unless (← (reflExt.getState (← getEnv)).getMatch rel).isEmpty do match rel.getAppFn.constName? with | some n => return some (n, lhs, rhs) | none => return none return none end Mathlib.Tactic
falgebra.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import choice fintype div tuple finfun bigop ssralg. From mathcomp Require Import finalg zmodp matrix vector poly. (******************************************************************************) (* Finite dimensional free algebras, usually known as F-algebras *) (* *) (* falgType K == the interface type for F-algebras over K; it simply *) (* joins the unitAlgType K and vectType K interfaces *) (* The HB class is called Falgebra. *) (* Any aT with an falgType structure inherits all the Vector, NzRing and *) (* Algebra operations, and supports the following additional operations: *) (* \dim_A M == (\dim M %/ dim A)%N -- free module dimension *) (* amull u == the linear function v |-> u * v, for u, v : aT *) (* amulr u == the linear function v |-> v * u, for u, v : aT *) (* 1, f * g, f ^+ n == the identity function, the composite g \o f, the nth *) (* iterate of f, for 1, f, g in 'End(aT) *) (* This is just the usual F-algebra structure on *) (* 'End(aT). It is NOT canonical by default, but can be *) (* activated by the line Import FalgLfun. Beware also *) (* that (f^-1)%VF is the linear function inverse, not *) (* the ring inverse of f (though they do coincide when *) (* f is injective). *) (* 1%VS == the line generated by 1 : aT *) (* (U * V)%VS == the smallest subspace of aT that contains all *) (* products u * v for u in U, v in V *) (* (U ^+ n)%VS == (U * U * ... * U), n-times. U ^+ 0 = 1%VS *) (* 'C[u]%VS == the centraliser subspace of the vector u *) (* 'C_U[v]%VS := (U :&: 'C[v])%VS *) (* 'C(V)%VS == the centraliser subspace of the subspace V *) (* 'C_U(V)%VS := (U :&: 'C(V))%VS *) (* 'Z(V)%VS == the center subspace of the subspace V *) (* agenv U == the smallest subalgebra containing U ^+ n for all n *) (* <<U; v>>%VS == agenv (U + <[v]>) (adjoin v to U) *) (* <<U & vs>>%VS == agenv (U + <<vs>>) (adjoin vs to U) *) (* {aspace aT} == a subType of {vspace aT} consisting of sub-algebras *) (* of aT (see below); for A : {aspace aT}, subvs_of A *) (* has a canonical falgType K structure *) (* is_aspace U <=> the characteristic predicate of {aspace aT} stating *) (* that U is closed under product and contains an *) (* identity element, := has_algid U && (U * U <= U)%VS *) (* algid A == the identity element of A : {aspace aT}, which need *) (* not be equal to 1 (indeed, in a Wedderburn *) (* decomposition it is not even a unit in aT) *) (* is_algid U e <-> e : aT is an identity element for the subspace U: *) (* e in U, e != 0 & e * u = u * e = u for all u in U *) (* has_algid U <=> there is an e such that is_algid U e *) (* [aspace of U] == a clone of an existing {aspace aT} structure on *) (* U : {vspace aT} (more instances of {aspace aT} will *) (* be defined in extFieldType) *) (* [aspace of U for A] == a clone of A : {aspace aT} for U : {vspace aT} *) (* 1%AS == the canonical sub-algebra 1%VS *) (* {:aT}%AS == the canonical full algebra *) (* <<U>>%AS == the canonical algebra for agenv U; note that this is *) (* unrelated to <<vs>>%VS, the subspace spanned by vs *) (* <<U; v>>%AS == the canonical algebra for <<U; v>>%VS *) (* <<U & vs>>%AS == the canonical algebra for <<U & vs>>%VS *) (* ahom_in U f <=> f : 'Hom(aT, rT) is a multiplicative homomorphism *) (* inside U, and in addition f 1 = 1 (even if U doesn't *) (* contain 1) *) (* Note that f @: U need not be a subalgebra when U is, *) (* as f could annilate U. *) (* 'AHom(aT, rT) == the type of algebra homomorphisms from aT to rT, *) (* where aT and rT ARE falgType structures. Elements of *) (* 'AHom(aT, rT) coerce to 'End(aT, rT) and aT -> rT *) (* 'AEnd(aT) == algebra endomorphisms of aT (:= 'AHom(aT, aT)) *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope aspace_scope. Declare Scope lrfun_scope. Local Open Scope ring_scope. Reserved Notation "{ 'aspace' T }" (format "{ 'aspace' T }"). Reserved Notation "<< U & vs >>" (format "<< U & vs >>"). Reserved Notation "<< U ; x >>" (format "<< U ; x >>"). Reserved Notation "''AHom' ( T , rT )" (format "''AHom' ( T , rT )"). Reserved Notation "''AEnd' ( T )" (format "''AEnd' ( T )"). Notation "\dim_ E V" := (divn (\dim V) (\dim E)) (at level 10, E at level 2, V at level 8, format "\dim_ E V") : nat_scope. Import GRing.Theory. (* Finite dimensional algebra *) #[short(type="falgType")] HB.structure Definition Falgebra (R : nzRingType) := { A of Vector R A & GRing.UnitAlgebra R A }. #[deprecated(since="mathcomp 2.0.0", note="Use falgType instead.")] Notation FalgType := falgType. (* Supply a default unitRing mixin for the default unitAlgType base type. *) HB.factory Record Algebra_isFalgebra (K : fieldType) A of Vector K A & GRing.Algebra K A := {}. HB.builders Context K A of Algebra_isFalgebra K A. Let vA : Vector.type K := A. Let am u := linfun (u \o* idfun : vA -> vA). Let uam := [pred u | lker (am u) == 0%VS]. Let vam := [fun u => if u \in uam then (am u)^-1%VF 1 else u]. Lemma amE u v : am u v = v * u. Proof. by rewrite lfunE. Qed. Lemma mulVr : {in uam, left_inverse 1 vam *%R}. Proof. by move=> u Uu; rewrite /= Uu -amE lker0_lfunVK. Qed. Lemma divrr : {in uam, right_inverse 1 vam *%R}. Proof. by move=> u Uu; apply/(lker0P Uu); rewrite !amE -mulrA mulVr // mul1r mulr1. Qed. Lemma unitrP : forall x y, y * x = 1 /\ x * y = 1 -> uam x. Proof. move=> u v [_ uv1]. by apply/lker0P=> w1 w2 /(congr1 (am v)); rewrite !amE -!mulrA uv1 !mulr1. Qed. Lemma invr_out : {in [predC uam], vam =1 id}. Proof. by move=> u /negbTE/= ->. Qed. HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build A mulVr divrr unitrP invr_out. HB.end. Module FalgebraExports. Bind Scope ring_scope with sort. End FalgebraExports. HB.export FalgebraExports. Notation "1" := (vline 1) : vspace_scope. HB.instance Definition _ (K : fieldType) n := Algebra_isFalgebra.Build K 'M[K]_n.+1. HB.instance Definition _ (R : comUnitRingType) := GRing.UnitAlgebra.on R^o. (* FIXME: remove once https://github.com/math-comp/hierarchy-builder/issues/197 is fixed *) Lemma regular_fullv (K : fieldType) : (fullv = 1 :> {vspace K^o})%VS. Proof. by apply/esym/eqP; rewrite eqEdim subvf dim_vline oner_eq0 dimvf. Qed. Section Proper. Variables (R : nzRingType) (aT : falgType R). Import VectorInternalTheory. Lemma FalgType_proper : dim aT > 0. Proof. rewrite lt0n; apply: contraNneq (oner_neq0 aT) => aT0. by apply/eqP/v2r_inj; do 2!move: (v2r _); rewrite aT0 => u v; rewrite !thinmx0. Qed. End Proper. Module FalgLfun. Section FalgLfun. Variable (R : comNzRingType) (aT : falgType R). Implicit Types f g : 'End(aT). HB.instance Definition _ := GRing.Algebra.copy 'End(aT) (lfun_algType (FalgType_proper aT)). Lemma lfun_mulE f g u : (f * g) u = g (f u). Proof. exact: lfunE. Qed. Lemma lfun_compE f g : (g \o f)%VF = f * g. Proof. by []. Qed. End FalgLfun. Section InvLfun. Variable (K : fieldType) (aT : falgType K). Implicit Types f g : 'End(aT). Definition lfun_invr f := if lker f == 0%VS then f^-1%VF else f. Lemma lfun_mulVr f : lker f == 0%VS -> f^-1%VF * f = 1. Proof. exact: lker0_compfV. Qed. Lemma lfun_mulrV f : lker f == 0%VS -> f * f^-1%VF = 1. Proof. exact: lker0_compVf. Qed. Fact lfun_mulRVr f : lker f == 0%VS -> lfun_invr f * f = 1. Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulVr. Qed. Fact lfun_mulrRV f : lker f == 0%VS -> f * lfun_invr f = 1. Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulrV. Qed. Fact lfun_unitrP f g : g * f = 1 /\ f * g = 1 -> lker f == 0%VS. Proof. case=> _ fK; apply/lker0P; apply: can_inj (g) _ => u. by rewrite -lfun_mulE fK lfunE. Qed. Lemma lfun_invr_out f : lker f != 0%VS -> lfun_invr f = f. Proof. by rewrite /lfun_invr => /negPf->. Qed. HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build 'End(aT) lfun_mulRVr lfun_mulrRV lfun_unitrP lfun_invr_out. Lemma lfun_invE f : lker f == 0%VS -> f^-1%VF = f^-1. Proof. by rewrite /f^-1 /= /lfun_invr => ->. Qed. End InvLfun. End FalgLfun. Section FalgebraTheory. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v : aT) (U V W : {vspace aT}). Import FalgLfun. Definition amull u : 'End(aT) := linfun (u \*o @idfun aT). Definition amulr u : 'End(aT) := linfun (u \o* @idfun aT). Lemma amull_inj : injective amull. Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mulr1. Qed. Lemma amulr_inj : injective amulr. Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mul1r. Qed. Fact amull_is_linear : linear amull. Proof. move=> a u v; apply/lfunP => w. by rewrite !lfunE /= scale_lfunE !lfunE /= mulrDl scalerAl. Qed. #[hnf] HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amull (GRing.semilinear_linear amull_is_linear). (* amull is a converse ring morphism *) Lemma amull1 : amull 1 = \1%VF. Proof. by apply/lfunP => z; rewrite id_lfunE lfunE /= mul1r. Qed. Lemma amullM u v : (amull (u * v) = amull v * amull u)%VF. Proof. by apply/lfunP => w; rewrite comp_lfunE !lfunE /= mulrA. Qed. Lemma amulr_is_linear : linear amulr. Proof. move=> a u v; apply/lfunP => w. by rewrite !lfunE /= !lfunE /= lfunE mulrDr /= scalerAr. Qed. Lemma amulr_is_monoid_morphism : monoid_morphism amulr. Proof. split=> [|x y]; first by apply/lfunP => w; rewrite id_lfunE !lfunE /= mulr1. by apply/lfunP=> w; rewrite comp_lfunE !lfunE /= mulrA. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `amulr_is_monoid_morphism` instead")] Definition amulr_is_multiplicative := (fun p => (p.2, p.1)) amulr_is_monoid_morphism. #[hnf] HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amulr (GRing.semilinear_linear amulr_is_linear). #[hnf] HB.instance Definition _ := GRing.isMonoidMorphism.Build aT (hom aT aT) amulr amulr_is_monoid_morphism. Lemma lker0_amull u : u \is a GRing.unit -> lker (amull u) == 0%VS. Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulrI. Qed. Lemma lker0_amulr u : u \is a GRing.unit -> lker (amulr u) == 0%VS. Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulIr. Qed. Lemma lfun1_poly (p : {poly aT}) : map_poly \1%VF p = p. Proof. by apply: map_poly_id => u _; apply: id_lfunE. Qed. Fact prodv_key : unit. Proof. by []. Qed. Definition prodv := locked_with prodv_key (fun U V => <<allpairs *%R (vbasis U) (vbasis V)>>%VS). Canonical prodv_unlockable := [unlockable fun prodv]. Local Notation "A * B" := (prodv A B) : vspace_scope. Lemma memv_mul U V : {in U & V, forall u v, u * v \in (U * V)%VS}. Proof. move=> u v /coord_vbasis-> /coord_vbasis->. rewrite mulr_suml; apply: memv_suml => i _. rewrite mulr_sumr; apply: memv_suml => j _. rewrite -scalerAl -scalerAr !memvZ // [prodv]unlock memv_span //. by apply/allpairsP; exists ((vbasis U)`_i, (vbasis V)`_j); rewrite !memt_nth. Qed. Lemma prodvP {U V W} : reflect {in U & V, forall u v, u * v \in W} (U * V <= W)%VS. Proof. apply: (iffP idP) => [sUVW u v Uu Vv | sUVW]. by rewrite (subvP sUVW) ?memv_mul. rewrite [prodv]unlock; apply/span_subvP=> _ /allpairsP[[u v] /= [Uu Vv ->]]. by rewrite sUVW ?vbasis_mem. Qed. Lemma prodv_line u v : (<[u]> * <[v]> = <[u * v]>)%VS. Proof. apply: subv_anti; rewrite -memvE memv_mul ?memv_line // andbT. apply/prodvP=> _ _ /vlineP[a ->] /vlineP[b ->]. by rewrite -scalerAr -scalerAl !memvZ ?memv_line. Qed. Lemma dimv1: \dim (1%VS : {vspace aT}) = 1. Proof. by rewrite dim_vline oner_neq0. Qed. Lemma dim_prodv U V : \dim (U * V) <= \dim U * \dim V. Proof. by rewrite unlock (leq_trans (dim_span _)) ?size_tuple. Qed. Lemma vspace1_neq0 : (1 != 0 :> {vspace aT})%VS. Proof. by rewrite -dimv_eq0 dimv1. Qed. Lemma vbasis1 : exists2 k, k != 0 & vbasis 1 = [:: k%:A] :> seq aT. Proof. move: (vbasis 1) (@vbasisP K aT 1); rewrite dim_vline oner_neq0. case/tupleP=> x X0; rewrite {X0}tuple0 => defX; have Xx := mem_head x nil. have /vlineP[k def_x] := basis_mem defX Xx; exists k; last by rewrite def_x. by have:= basis_not0 defX Xx; rewrite def_x scaler_eq0 oner_eq0 orbF. Qed. Lemma prod0v : left_zero 0%VS prodv. Proof. move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv 0 U)) //. by rewrite dimv0. Qed. Lemma prodv0 : right_zero 0%VS prodv. Proof. move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv U 0)) //. by rewrite dimv0 muln0. Qed. HB.instance Definition _ := Monoid.isMulLaw.Build {vspace aT} 0%VS prodv prod0v prodv0. Lemma prod1v : left_id 1%VS prodv. Proof. move=> U; apply/subv_anti/andP; split. by apply/prodvP=> _ u /vlineP[a ->] Uu; rewrite mulr_algl memvZ. by apply/subvP=> u Uu; rewrite -[u]mul1r memv_mul ?memv_line. Qed. Lemma prodv1 : right_id 1%VS prodv. Proof. move=> U; apply/subv_anti/andP; split. by apply/prodvP=> u _ Uu /vlineP[a ->]; rewrite mulr_algr memvZ. by apply/subvP=> u Uu; rewrite -[u]mulr1 memv_mul ?memv_line. Qed. Lemma prodvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 * V1 <= U2 * V2)%VS. Proof. move/subvP=> sU12 /subvP sV12; apply/prodvP=> u v Uu Vv. by rewrite memv_mul ?sU12 ?sV12. Qed. Lemma prodvSl U1 U2 V : (U1 <= U2 -> U1 * V <= U2 * V)%VS. Proof. by move/prodvS->. Qed. Lemma prodvSr U V1 V2 : (V1 <= V2 -> U * V1 <= U * V2)%VS. Proof. exact: prodvS. Qed. Lemma prodvDl : left_distributive prodv addv. Proof. move=> U1 U2 V; apply/esym/subv_anti/andP; split. by rewrite subv_add 2?prodvS ?addvSl ?addvSr. apply/prodvP=> _ v /memv_addP[u1 Uu1 [u2 Uu2 ->]] Vv. by rewrite mulrDl memv_add ?memv_mul. Qed. Lemma prodvDr : right_distributive prodv addv. Proof. move=> U V1 V2; apply/esym/subv_anti/andP; split. by rewrite subv_add 2?prodvS ?addvSl ?addvSr. apply/prodvP=> u _ Uu /memv_addP[v1 Vv1 [v2 Vv2 ->]]. by rewrite mulrDr memv_add ?memv_mul. Qed. HB.instance Definition _ := Monoid.isAddLaw.Build {vspace aT} prodv addv prodvDl prodvDr. Lemma prodvA : associative prodv. Proof. move=> U V W; rewrite -(span_basis (vbasisP U)) span_def !big_distrl /=. apply: eq_bigr => u _; rewrite -(span_basis (vbasisP W)) span_def !big_distrr. apply: eq_bigr => w _; rewrite -(span_basis (vbasisP V)) span_def /=. rewrite !(big_distrl, big_distrr) /=; apply: eq_bigr => v _. by rewrite !prodv_line mulrA. Qed. HB.instance Definition _ := Monoid.isLaw.Build {vspace aT} 1%VS prodv prodvA prod1v prodv1. Definition expv U n := iterop n.+1.-1 prodv U 1%VS. Local Notation "A ^+ n" := (expv A n) : vspace_scope. Lemma expv0 U : (U ^+ 0 = 1)%VS. Proof. by []. Qed. Lemma expv1 U : (U ^+ 1 = U)%VS. Proof. by []. Qed. Lemma expv2 U : (U ^+ 2 = U * U)%VS. Proof. by []. Qed. Lemma expvSl U n : (U ^+ n.+1 = U * U ^+ n)%VS. Proof. by case: n => //; rewrite prodv1. Qed. Lemma expv0n n : (0 ^+ n = if n is _.+1 then 0 else 1)%VS. Proof. by case: n => // n; rewrite expvSl prod0v. Qed. Lemma expv1n n : (1 ^+ n = 1)%VS. Proof. by elim: n => // n IHn; rewrite expvSl IHn prodv1. Qed. Lemma expvD U m n : (U ^+ (m + n) = U ^+ m * U ^+ n)%VS. Proof. by elim: m => [|m IHm]; rewrite ?prod1v // !expvSl IHm prodvA. Qed. Lemma expvSr U n : (U ^+ n.+1 = U ^+ n * U)%VS. Proof. by rewrite -addn1 expvD. Qed. Lemma expvM U m n : (U ^+ (m * n) = U ^+ m ^+ n)%VS. Proof. by elim: n => [|n IHn]; rewrite ?muln0 // mulnS expvD IHn expvSl. Qed. Lemma expvS U V n : (U <= V -> U ^+ n <= V ^+ n)%VS. Proof. move=> sUV; elim: n => [|n IHn]; first by rewrite !expv0 subvv. by rewrite !expvSl prodvS. Qed. Lemma expv_line u n : (<[u]> ^+ n = <[u ^+ n]>)%VS. Proof. elim: n => [|n IH]; first by rewrite expr0 expv0. by rewrite exprS expvSl IH prodv_line. Qed. (* Centralisers and centers. *) Definition centraliser1_vspace u := lker (amulr u - amull u). Local Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope. Definition centraliser_vspace V := (\bigcap_i 'C[tnth (vbasis V) i])%VS. Local Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope. Definition center_vspace V := (V :&: 'C(V))%VS. Local Notation "'Z ( V )" := (center_vspace V) : vspace_scope. Lemma cent1vP u v : reflect (u * v = v * u) (u \in 'C[v]%VS). Proof. by rewrite (sameP eqlfunP eqP) !lfunE /=; apply: eqP. Qed. Lemma cent1v1 u : 1 \in 'C[u]%VS. Proof. by apply/cent1vP; rewrite commr1. Qed. Lemma cent1v_id u : u \in 'C[u]%VS. Proof. exact/cent1vP. Qed. Lemma cent1vX u n : u ^+ n \in 'C[u]%VS. Proof. exact/cent1vP/esym/commrX. Qed. Lemma cent1vC u v : (u \in 'C[v])%VS = (v \in 'C[u])%VS. Proof. exact/cent1vP/cent1vP. Qed. Lemma centvP u V : reflect {in V, forall v, u * v = v * u} (u \in 'C(V))%VS. Proof. apply: (iffP subv_bigcapP) => [cVu y /coord_vbasis-> | cVu i _]. apply/esym/cent1vP/rpred_sum=> i _; apply: rpredZ. by rewrite -tnth_nth cent1vC memvE cVu. exact/cent1vP/cVu/vbasis_mem/mem_tnth. Qed. Lemma centvsP U V : reflect {in U & V, commutative *%R} (U <= 'C(V))%VS. Proof. by apply: (iffP subvP) => [cUV u v | cUV u] /cUV-/centvP; apply. Qed. Lemma subv_cent1 U v : (U <= 'C[v])%VS = (v \in 'C(U)%VS). Proof. by apply/subvP/centvP=> cUv u Uu; apply/cent1vP; rewrite 1?cent1vC cUv. Qed. Lemma centv1 V : 1 \in 'C(V)%VS. Proof. by apply/centvP=> v _; rewrite commr1. Qed. Lemma centvX V u n : u \in 'C(V)%VS -> u ^+ n \in 'C(V)%VS. Proof. by move/centvP=> cVu; apply/centvP=> v /cVu/esym/commrX->. Qed. Lemma centvC U V : (U <= 'C(V))%VS = (V <= 'C(U))%VS. Proof. by apply/centvsP/centvsP=> cUV u v UVu /cUV->. Qed. Lemma centerv_sub V : ('Z(V) <= V)%VS. Proof. exact: capvSl. Qed. Lemma cent_centerv V : (V <= 'C('Z(V)))%VS. Proof. by rewrite centvC capvSr. Qed. (* Building the predicate that checks is a vspace has a unit *) Definition is_algid e U := [/\ e \in U, e != 0 & {in U, forall u, e * u = u /\ u * e = u}]. Fact algid_decidable U : decidable (exists e, is_algid e U). Proof. have [-> | nzU] := eqVneq U 0%VS. by right=> [[e []]]; rewrite memv0 => ->. pose X := vbasis U; pose feq f1 f2 := [tuple of map f1 X ++ map f2 X]. have feqL f i: tnth (feq _ f _) (lshift _ i) = f X`_i. set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple. by rewrite ltn_ord (nth_map 0) ?size_tuple. have feqR f i: tnth (feq _ _ f) (rshift _ i) = f X`_i. set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple. by rewrite ltnNge leq_addr addKn /= (nth_map 0) ?size_tuple. apply: decP (vsolve_eq (feq _ amulr amull) (feq _ id id) U) _. apply: (iffP (vsolve_eqP _ _ _)) => [[e Ue id_e] | [e [Ue _ id_e]]]. suffices idUe: {in U, forall u, e * u = u /\ u * e = u}. exists e; split=> //; apply: contraNneq nzU => e0; rewrite -subv0. by apply/subvP=> u /idUe[<- _]; rewrite e0 mul0r mem0v. move=> u /coord_vbasis->; rewrite mulr_sumr mulr_suml. split; apply/eq_bigr=> i _; rewrite -(scalerAr, scalerAl); congr (_ *: _). by have:= id_e (lshift _ i); rewrite !feqL lfunE. by have:= id_e (rshift _ i); rewrite !feqR lfunE. have{id_e} /all_and2[ideX idXe]:= id_e _ (vbasis_mem (mem_tnth _ X)). exists e => // k; rewrite -[k]splitK. by case: (split k) => i; rewrite !(feqL, feqR) lfunE /= -tnth_nth. Qed. Definition has_algid : pred {vspace aT} := algid_decidable. Lemma has_algidP {U} : reflect (exists e, is_algid e U) (has_algid U). Proof. exact: sumboolP. Qed. Lemma has_algid1 U : 1 \in U -> has_algid U. Proof. move=> U1; apply/has_algidP; exists 1; split; rewrite ?oner_eq0 // => u _. by rewrite mulr1 mul1r. Qed. Definition is_aspace U := has_algid U && (U * U <= U)%VS. Structure aspace := ASpace {asval :> {vspace aT}; _ : is_aspace asval}. HB.instance Definition _ := [isSub for asval]. HB.instance Definition _ := [Choice of aspace by <:]. Definition clone_aspace U (A : aspace) := fun algU & phant_id algU (valP A) => @ASpace U algU : aspace. Fact aspace1_subproof : is_aspace 1. Proof. by rewrite /is_aspace prod1v -memvE has_algid1 memv_line. Qed. Canonical aspace1 : aspace := ASpace aspace1_subproof. Lemma aspacef_subproof : is_aspace fullv. Proof. by rewrite /is_aspace subvf has_algid1 ?memvf. Qed. Canonical aspacef : aspace := ASpace aspacef_subproof. Lemma polyOver1P p : reflect (exists q, p = map_poly (in_alg aT) q) (p \is a polyOver 1%VS). Proof. apply: (iffP idP) => [/allP/=Qp | [q ->]]; last first. by apply/polyOverP=> j; rewrite coef_map rpredZ ?memv_line. exists (map_poly (coord [tuple 1] 0) p). rewrite -map_poly_comp map_poly_id // => _ /Qp/vlineP[a ->] /=. by rewrite linearZ /= (coord_free 0) ?mulr1 // seq1_free ?oner_eq0. Qed. End FalgebraTheory. Delimit Scope aspace_scope with AS. Bind Scope aspace_scope with aspace. Arguments asval {K aT} a%_AS. Arguments aspace [K]%_type aT%_type. Arguments clone_aspace [K aT U%_VS A%_AS algU] _. Notation "{ 'aspace' T }" := (aspace T) : type_scope. Notation "A * B" := (prodv A B) : vspace_scope. Notation "A ^+ n" := (expv A n) : vspace_scope. Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope. Notation "'C_ U [ v ]" := (capv U 'C[v]) : vspace_scope. Notation "'C_ ( U ) [ v ]" := (capv U 'C[v]) (only parsing) : vspace_scope. Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope. Notation "'C_ U ( V )" := (capv U 'C(V)) : vspace_scope. Notation "'C_ ( U ) ( V )" := (capv U 'C(V)) (only parsing) : vspace_scope. Notation "'Z ( V )" := (center_vspace V) : vspace_scope. Notation "1" := (aspace1 _) : aspace_scope. Notation "{ : aT }" := (aspacef aT) : aspace_scope. Notation "[ 'aspace' 'of' U ]" := (@clone_aspace _ _ U _ _ id) (format "[ 'aspace' 'of' U ]") : form_scope. Notation "[ 'aspace' 'of' U 'for' A ]" := (@clone_aspace _ _ U A _ idfun) (format "[ 'aspace' 'of' U 'for' A ]") : form_scope. Arguments prodvP {K aT U V W}. Arguments cent1vP {K aT u v}. Arguments centvP {K aT u V}. Arguments centvsP {K aT U V}. Arguments has_algidP {K aT U}. Arguments polyOver1P {K aT p}. Section AspaceTheory. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v e : aT) (U V : {vspace aT}) (A B : {aspace aT}). Import FalgLfun. Lemma algid_subproof U : {e | e \in U & has_algid U ==> (U <= lker (amull e - 1) :&: lker (amulr e - 1))%VS}. Proof. apply: sig2W; case: has_algidP => [[e]|]; last by exists 0; rewrite ?mem0v. case=> Ae _ idAe; exists e => //; apply/subvP=> u /idAe[eu_u ue_u]. by rewrite memv_cap !memv_ker !lfun_simp /= eu_u ue_u subrr eqxx. Qed. Definition algid U := s2val (algid_subproof U). Lemma memv_algid U : algid U \in U. Proof. by rewrite /algid; case: algid_subproof. Qed. Lemma algidl A : {in A, left_id (algid A) *%R}. Proof. rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A. move/subvP=> idAe u /idAe/memv_capP[]. by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP. Qed. Lemma algidr A : {in A, right_id (algid A) *%R}. Proof. rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A. move/subvP=> idAe u /idAe/memv_capP[_]. by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP. Qed. Lemma unitr_algid1 A u : u \in A -> u \is a GRing.unit -> algid A = 1. Proof. by move=> Eu /mulrI; apply; rewrite mulr1 algidr. Qed. Lemma algid_eq1 A : (algid A == 1) = (1 \in A). Proof. by apply/eqP/idP=> [<- | /algidr <-]; rewrite ?memv_algid ?mul1r. Qed. Lemma algid_neq0 A : algid A != 0. Proof. have /andP[/has_algidP[u [Au nz_u _]] _] := valP A. by apply: contraNneq nz_u => e0; rewrite -(algidr Au) e0 mulr0. Qed. Lemma dim_algid A : \dim <[algid A]> = 1%N. Proof. by rewrite dim_vline algid_neq0. Qed. Lemma adim_gt0 A : (0 < \dim A)%N. Proof. by rewrite -(dim_algid A) dimvS // -memvE ?memv_algid. Qed. Lemma not_asubv0 A : ~~ (A <= 0)%VS. Proof. by rewrite subv0 -dimv_eq0 -lt0n adim_gt0. Qed. Lemma adim1P {A} : reflect (A = <[algid A]>%VS :> {vspace aT}) (\dim A == 1%N). Proof. rewrite eqn_leq adim_gt0 -(memv_algid A) andbC -(dim_algid A) -eqEdim eq_sym. exact: eqP. Qed. Lemma asubv A : (A * A <= A)%VS. Proof. by have /andP[] := valP A. Qed. Lemma memvM A : {in A &, forall u v, u * v \in A}. Proof. exact/prodvP/asubv. Qed. Lemma prodv_id A : (A * A)%VS = A. Proof. apply/eqP; rewrite eqEsubv asubv; apply/subvP=> u Au. by rewrite -(algidl Au) memv_mul // memv_algid. Qed. Lemma prodv_sub U V A : (U <= A -> V <= A -> U * V <= A)%VS. Proof. by move=> sUA sVA; rewrite -prodv_id prodvS. Qed. Lemma expv_id A n : (A ^+ n.+1)%VS = A. Proof. by elim: n => // n IHn; rewrite !expvSl prodvA prodv_id -expvSl. Qed. Lemma limg_amulr U v : (amulr v @: U = U * <[v]>)%VS. Proof. rewrite -(span_basis (vbasisP U)) limg_span !span_def big_distrl /= big_map. by apply: eq_bigr => u; rewrite prodv_line lfunE. Qed. Lemma memv_cosetP {U v w} : reflect (exists2 u, u\in U & w = u * v) (w \in U * <[v]>)%VS. Proof. rewrite -limg_amulr. by apply: (iffP memv_imgP) => [] [u] Uu ->; exists u; rewrite ?lfunE. Qed. Lemma dim_cosetv_unit V u : u \is a GRing.unit -> \dim (V * <[u]>) = \dim V. Proof. by move/lker0_amulr/eqP=> Uu; rewrite -limg_amulr limg_dim_eq // Uu capv0. Qed. Lemma memvV A u : (u^-1 \in A) = (u \in A). Proof. suffices{u} invA: invr_closed A by apply/idP/idP=> /invA; rewrite ?invrK. move=> u Au; have [Uu | /invr_out-> //] := boolP (u \is a GRing.unit). rewrite memvE -(limg_ker0 _ _ (lker0_amulr Uu)) limg_line lfunE /= mulVr //. suff ->: (amulr u @: A)%VS = A by rewrite -memvE -algid_eq1 (unitr_algid1 Au). by apply/eqP; rewrite limg_amulr -dimv_leqif_eq ?prodv_sub ?dim_cosetv_unit. Qed. Fact aspace_cap_subproof A B : algid A \in B -> is_aspace (A :&: B). Proof. move=> BeA; apply/andP. split; [apply/has_algidP | by rewrite subv_cap !prodv_sub ?capvSl ?capvSr]. exists (algid A); rewrite /is_algid algid_neq0 memv_cap memv_algid. by split=> // u /memv_capP[Au _]; rewrite ?algidl ?algidr. Qed. Definition aspace_cap A B BeA := ASpace (@aspace_cap_subproof A B BeA). Fact centraliser1_is_aspace u : is_aspace 'C[u]. Proof. rewrite /is_aspace has_algid1 ?cent1v1 //=. apply/prodvP=> v w /cent1vP-cuv /cent1vP-cuw. by apply/cent1vP; rewrite -mulrA cuw !mulrA cuv. Qed. Canonical centraliser1_aspace u := ASpace (centraliser1_is_aspace u). Fact centraliser_is_aspace V : is_aspace 'C(V). Proof. rewrite /is_aspace has_algid1 ?centv1 //=. apply/prodvP=> u w /centvP-cVu /centvP-cVw. by apply/centvP=> v Vv; rewrite /= -mulrA cVw // !mulrA cVu. Qed. Canonical centraliser_aspace V := ASpace (centraliser_is_aspace V). Lemma centv_algid A : algid A \in 'C(A)%VS. Proof. by apply/centvP=> u Au; rewrite algidl ?algidr. Qed. Canonical center_aspace A := [aspace of 'Z(A) for aspace_cap (centv_algid A)]. Lemma algid_center A : algid 'Z(A) = algid A. Proof. rewrite -(algidl (subvP (centerv_sub A) _ (memv_algid _))) algidr //=. by rewrite memv_cap memv_algid centv_algid. Qed. Lemma Falgebra_FieldMixin : GRing.integral_domain_axiom aT -> GRing.field_axiom aT. Proof. move=> domT u nz_u; apply/unitrP. have kerMu: lker (amulr u) == 0%VS. rewrite eqEsubv sub0v andbT; apply/subvP=> v; rewrite memv_ker lfunE /=. by move/eqP/domT; rewrite (negPf nz_u) orbF memv0. have /memv_imgP[v _ vu1]: 1 \in limg (amulr u); last rewrite lfunE /= in vu1. suffices /eqP->: limg (amulr u) == fullv by rewrite memvf. by rewrite -dimv_leqif_eq ?subvf ?limg_dim_eq // (eqP kerMu) capv0. exists v; split=> //; apply: (lker0P kerMu). by rewrite !lfunE /= -mulrA -vu1 mulr1 mul1r. Qed. Section SkewField. Hypothesis fieldT : GRing.field_axiom aT. Lemma skew_field_algid1 A : algid A = 1. Proof. by rewrite (unitr_algid1 (memv_algid A)) ?fieldT ?algid_neq0. Qed. Lemma skew_field_module_semisimple A M : let sumA X := (\sum_(x <- X) A * <[x]>)%VS in (A * M <= M)%VS -> {X | [/\ sumA X = M, directv (sumA X) & 0 \notin X]}. Proof. move=> sumA sAM_M; pose X := Nil aT; pose k := (\dim (A * M) - \dim (sumA X))%N. have: (\dim (A * M) - \dim (sumA X) < k.+1)%N by []. have: [/\ (sumA X <= A * M)%VS, directv (sumA X) & 0 \notin X]. by rewrite /sumA directvE /= !big_nil sub0v dimv0. elim: {X k}k.+1 (X) => // k IHk X [sAX_AM dxAX nzX]; rewrite ltnS => leAXk. have [sM_AX | /subvPn/sig2W[y My notAXy]] := boolP (M <= sumA X)%VS. by exists X; split=> //; apply/eqP; rewrite eqEsubv (subv_trans sAX_AM). have nz_y: y != 0 by rewrite (memPnC notAXy) ?mem0v. pose AY := sumA (y :: X). have sAY_AM: (AY <= A * M)%VS by rewrite [AY]big_cons subv_add ?prodvSr. have dxAY: directv AY. rewrite directvE /= !big_cons [_ == _]directv_addE dxAX directvE eqxx /=. rewrite -/(sumA X) eqEsubv sub0v andbT -limg_amulr. apply/subvP=> _ /memv_capP[/memv_imgP[a Aa ->]]/[!lfunE]/= AXay. rewrite memv0 (mulIr_eq0 a (mulIr _)) ?fieldT //. apply: contraR notAXy => /fieldT-Ua; rewrite -[y](mulKr Ua) /sumA. by rewrite -big_distrr -(prodv_id A) /= -prodvA big_distrr memv_mul ?memvV. apply: (IHk (y :: X)); first by rewrite !inE eq_sym negb_or nz_y. rewrite -subSn ?dimvS // (directvP dxAY) /= big_cons -(directvP dxAX) /=. rewrite subnDA (leq_trans _ leAXk) ?leq_sub2r // leq_subLR -add1n leq_add2r. by rewrite dim_cosetv_unit ?fieldT ?adim_gt0. Qed. Lemma skew_field_module_dimS A M : (A * M <= M)%VS -> \dim A %| \dim M. Proof. case/skew_field_module_semisimple=> X [<- /directvP-> nzX] /=. rewrite big_seq prime.dvdn_sum // => x /(memPn nzX)nz_x. by rewrite dim_cosetv_unit ?fieldT. Qed. Lemma skew_field_dimS A B : (A <= B)%VS -> \dim A %| \dim B. Proof. by move=> sAB; rewrite skew_field_module_dimS ?prodv_sub. Qed. End SkewField. End AspaceTheory. (* Note that local centraliser might not be proper sub-algebras. *) Notation "'C [ u ]" := (centraliser1_aspace u) : aspace_scope. Notation "'C ( V )" := (centraliser_aspace V) : aspace_scope. Notation "'Z ( A )" := (center_aspace A) : aspace_scope. Arguments adim1P {K aT A}. Arguments memv_cosetP {K aT U v w}. Section Closure. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v : aT) (U V W : {vspace aT}). (* Subspaces of an F-algebra form a Kleene algebra *) Definition agenv U := (\sum_(i < \dim {:aT}) U ^+ i)%VS. Local Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope. Local Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope. Lemma agenvEl U : agenv U = (1 + U * agenv U)%VS. Proof. pose f V := (1 + U * V)%VS; rewrite -/(f _); pose n := \dim {:aT}. have ->: agenv U = iter n f 0%VS. rewrite /agenv -/n; elim: n => [|n IHn]; first by rewrite big_ord0. rewrite big_ord_recl /= -{}IHn; congr (1 + _)%VS; rewrite big_distrr /=. by apply: eq_bigr => i; rewrite expvSl. have fS i j: i <= j -> (iter i f 0 <= iter j f 0)%VS. by elim: i j => [|i IHi] [|j] leij; rewrite ?sub0v //= addvS ?prodvSr ?IHi. suffices /(@trajectP _ f _ n.+1)[i le_i_n Dfi]: looping f 0%VS n.+1. by apply/eqP; rewrite eqEsubv -iterS fS // Dfi fS. apply: contraLR (dimvS (subvf (iter n.+1 f 0%VS))); rewrite -/n -ltnNge. rewrite -looping_uniq; elim: n.+1 => // i IHi; rewrite trajectSr rcons_uniq. rewrite {1}trajectSr mem_rcons inE negb_or eq_sym eqEdim fS ?leqW // -ltnNge. by rewrite -andbA => /and3P[lt_fi _ /IHi/leq_ltn_trans->]. Qed. Lemma agenvEr U : agenv U = (1 + agenv U * U)%VS. Proof. rewrite [lhs in lhs = _]agenvEl big_distrr big_distrl /=; congr (_ + _)%VS. by apply: eq_bigr => i _ /=; rewrite -expvSr -expvSl. Qed. Lemma agenv_modl U V : (U * V <= V -> agenv U * V <= V)%VS. Proof. rewrite big_distrl /= => idlU_V; apply/subv_sumP=> [[i _] /= _]. elim: i => [|i]; first by rewrite expv0 prod1v. by apply: subv_trans; rewrite expvSr -prodvA prodvSr. Qed. Lemma agenv_modr U V : (V * U <= V -> V * agenv U <= V)%VS. Proof. rewrite big_distrr /= => idrU_V; apply/subv_sumP=> [[i _] /= _]. elim: i => [|i]; first by rewrite expv0 prodv1. by apply: subv_trans; rewrite expvSl prodvA prodvSl. Qed. Fact agenv_is_aspace U : is_aspace (agenv U). Proof. rewrite /is_aspace has_algid1; last by rewrite memvE agenvEl addvSl. by rewrite agenv_modl // [V in (_ <= V)%VS]agenvEl addvSr. Qed. Canonical agenv_aspace U : {aspace aT} := ASpace (agenv_is_aspace U). Lemma agenvE U : agenv U = agenv_aspace U. Proof. by []. Qed. (* Kleene algebra properties *) Lemma agenvM U : (agenv U * agenv U)%VS = agenv U. Proof. exact: prodv_id. Qed. Lemma agenvX n U : (agenv U ^+ n.+1)%VS = agenv U. Proof. exact: expv_id. Qed. Lemma sub1_agenv U : (1 <= agenv U)%VS. Proof. by rewrite agenvEl addvSl. Qed. Lemma sub_agenv U : (U <= agenv U)%VS. Proof. by rewrite 2!agenvEl addvC prodvDr prodv1 -addvA addvSl. Qed. Lemma subX_agenv U n : (U ^+ n <= agenv U)%VS. Proof. by case: n => [|n]; rewrite ?sub1_agenv // -(agenvX n) expvS // sub_agenv. Qed. Lemma agenv_sub_modl U V : (1 <= V -> U * V <= V -> agenv U <= V)%VS. Proof. move=> s1V /agenv_modl; apply: subv_trans. by rewrite -[Us in (Us <= _)%VS]prodv1 prodvSr. Qed. Lemma agenv_sub_modr U V : (1 <= V -> V * U <= V -> agenv U <= V)%VS. Proof. move=> s1V /agenv_modr; apply: subv_trans. by rewrite -[Us in (Us <= _)%VS]prod1v prodvSl. Qed. Lemma agenv_id U : agenv (agenv U) = agenv U. Proof. apply/eqP; rewrite eqEsubv sub_agenv andbT. by rewrite agenv_sub_modl ?sub1_agenv ?agenvM. Qed. Lemma agenvS U V : (U <= V -> agenv U <= agenv V)%VS. Proof. move=> sUV; rewrite agenv_sub_modl ?sub1_agenv //. by rewrite -[Vs in (_ <= Vs)%VS]agenvM prodvSl ?(subv_trans sUV) ?sub_agenv. Qed. Lemma agenv_add_id U V : agenv (agenv U + V) = agenv (U + V). Proof. apply/eqP; rewrite eqEsubv andbC agenvS ?addvS ?sub_agenv //=. rewrite agenv_sub_modl ?sub1_agenv //. rewrite -[rhs in (_ <= rhs)%VS]agenvM prodvSl // subv_add agenvS ?addvSl //=. exact: subv_trans (addvSr U V) (sub_agenv _). Qed. Lemma subv_adjoin U x : (U <= <<U; x>>)%VS. Proof. by rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSl. Qed. Lemma subv_adjoin_seq U xs : (U <= <<U & xs>>)%VS. Proof. by rewrite (subv_trans (sub_agenv _)) // ?agenvS ?addvSl. Qed. Lemma memv_adjoin U x : x \in <<U; x>>%VS. Proof. by rewrite memvE (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed. Lemma seqv_sub_adjoin U xs : {subset xs <= <<U & xs>>%VS}. Proof. by apply/span_subvP; rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed. Lemma subvP_adjoin U x y : y \in U -> y \in <<U; x>>%VS. Proof. exact/subvP/subv_adjoin. Qed. Lemma adjoin_nil V : <<V & [::]>>%VS = agenv V. Proof. by rewrite span_nil addv0. Qed. Lemma adjoin_cons V x rs : <<V & x :: rs>>%VS = << <<V; x>> & rs>>%VS. Proof. by rewrite span_cons addvA agenv_add_id. Qed. Lemma adjoin_rcons V rs x : <<V & rcons rs x>>%VS = << <<V & rs>>%VS; x>>%VS. Proof. by rewrite -cats1 span_cat addvA span_seq1 agenv_add_id. Qed. Lemma adjoin_seq1 V x : <<V & [:: x]>>%VS = <<V; x>>%VS. Proof. by rewrite adjoin_cons adjoin_nil agenv_id. Qed. Lemma adjoinC V x y : << <<V; x>>; y>>%VS = << <<V; y>>; x>>%VS. Proof. by rewrite !agenv_add_id -!addvA (addvC <[x]>%VS). Qed. Lemma adjoinSl U V x : (U <= V -> <<U; x>> <= <<V; x>>)%VS. Proof. by move=> sUV; rewrite agenvS ?addvS. Qed. Lemma adjoin_seqSl U V rs : (U <= V -> <<U & rs>> <= <<V & rs>>)%VS. Proof. by move=> sUV; rewrite agenvS ?addvS. Qed. Lemma adjoin_seqSr U rs1 rs2 : {subset rs1 <= rs2} -> (<<U & rs1>> <= <<U & rs2>>)%VS. Proof. by move/sub_span=> s_rs12; rewrite agenvS ?addvS. Qed. End Closure. Notation "<< U >>" := (agenv_aspace U) : aspace_scope. Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope. Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope. Notation "<< U & vs >>" := << U + <<vs>> >>%AS : aspace_scope. Notation "<< U ; x >>" := << U + <[x]> >>%AS : aspace_scope. Section SubFalgType. (* The falgType structure of subvs_of A for A : {aspace aT}. *) (* We can't use the rpred-based mixin, because A need not contain 1. *) Variable (K : fieldType) (aT : falgType K) (A : {aspace aT}). Definition subvs_one := Subvs (memv_algid A). Definition subvs_mul (u v : subvs_of A) := Subvs (subv_trans (memv_mul (subvsP u) (subvsP v)) (asubv _)). Fact subvs_mulA : associative subvs_mul. Proof. by move=> x y z; apply/val_inj/mulrA. Qed. Fact subvs_mu1l : left_id subvs_one subvs_mul. Proof. by move=> x; apply/val_inj/algidl/(valP x). Qed. Fact subvs_mul1 : right_id subvs_one subvs_mul. Proof. by move=> x; apply/val_inj/algidr/(valP x). Qed. Fact subvs_mulDl : left_distributive subvs_mul +%R. Proof. move=> x y z; apply/val_inj/mulrDl. Qed. Fact subvs_mulDr : right_distributive subvs_mul +%R. Proof. move=> x y z; apply/val_inj/mulrDr. Qed. HB.instance Definition _ := GRing.Zmodule_isNzRing.Build (subvs_of A) subvs_mulA subvs_mu1l subvs_mul1 subvs_mulDl subvs_mulDr (algid_neq0 _). Lemma subvs_scaleAl k (x y : subvs_of A) : k *: (x * y) = (k *: x) * y. Proof. exact/val_inj/scalerAl. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build K (subvs_of A) subvs_scaleAl. Lemma subvs_scaleAr k (x y : subvs_of A) : k *: (x * y) = x * (k *: y). Proof. exact/val_inj/scalerAr. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build K (subvs_of A) subvs_scaleAr. HB.instance Definition _ := Algebra_isFalgebra.Build K (subvs_of A). Implicit Type w : subvs_of A. Lemma vsval_unitr w : vsval w \is a GRing.unit -> w \is a GRing.unit. Proof. case: w => /= u Au Uu; have Au1: u^-1 \in A by rewrite memvV. apply/unitrP; exists (Subvs Au1). by split; apply: val_inj; rewrite /= ?mulrV ?mulVr ?(unitr_algid1 Au). Qed. Lemma vsval_invr w : vsval w \is a GRing.unit -> val w^-1 = (val w)^-1. Proof. move=> Uu; have def_w: w / w * w = w by rewrite divrK ?vsval_unitr. by apply: (mulrI Uu); rewrite -[in u in u / _]def_w ?mulrK. Qed. End SubFalgType. Section AHom. Variable K : fieldType. Section Class_Def. Variables aT rT : falgType K. Definition ahom_in (U : {vspace aT}) (f : 'Hom(aT, rT)) := all2rel (fun x y : aT => f (x * y) == f x * f y) (vbasis U) && (f 1 == 1). Lemma ahom_inP {f : 'Hom(aT, rT)} {U : {vspace aT}} : reflect ({in U &, {morph f : x y / x * y >-> x * y}} * (f 1 = 1)) (ahom_in U f). Proof. apply: (iffP andP) => [[/allrelP fM /eqP f1] | [fM f1]]; last first. rewrite f1; split=> //; apply/allrelP => x y Ax Ay. by rewrite fM // vbasis_mem. split=> // x y /coord_vbasis -> /coord_vbasis ->. rewrite !mulr_suml ![f _]linear_sum mulr_suml; apply: eq_bigr => i _ /=. rewrite !mulr_sumr linear_sum; apply: eq_bigr => j _ /=. rewrite !linearZ -!scalerAr -!scalerAl 2!linearZ /=; congr (_ *: (_ *: _)). by apply/eqP/fM; apply: memt_nth. Qed. Lemma ahomP_tmp {f : 'Hom(aT, rT)} : reflect (monoid_morphism f) (ahom_in {:aT} f). Proof. apply: (iffP ahom_inP) => [[fM f1] | fRM_P]; last first. by split=> [x y|]; [rewrite fRM_P.2|rewrite fRM_P.1]. by split=> // x y; rewrite fM ?memvf. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ahomP_tmp` instead")] Lemma ahomP {f : 'Hom(aT, rT)} : reflect (multiplicative f) (ahom_in {:aT} f). Proof. by apply: (iffP ahomP_tmp) => [][]. Qed. Structure ahom := AHom {ahval :> 'Hom(aT, rT); _ : ahom_in {:aT} ahval}. HB.instance Definition _ := [isSub for ahval]. HB.instance Definition _ := [Equality of ahom by <:]. HB.instance Definition _ := [Choice of ahom by <:]. Fact linfun_is_ahom (f : {lrmorphism aT -> rT}) : ahom_in {:aT} (linfun f). Proof. by apply/ahom_inP; split=> [x y|]; rewrite !lfunE ?rmorphM ?rmorph1. Qed. Canonical linfun_ahom f := AHom (linfun_is_ahom f). End Class_Def. Arguments ahom_in [aT rT]. Arguments ahom_inP {aT rT f U}. #[warning="-deprecated-since-mathcomp-2.5.0"] Arguments ahomP {aT rT f}. Arguments ahomP_tmp {aT rT f}. Section LRMorphism. Variables aT rT sT : falgType K. Fact ahom_is_monoid_morphism (f : ahom aT rT) : monoid_morphism f. Proof. by apply/ahomP_tmp; case: f. Qed. #[hnf] HB.instance Definition _ (f : ahom aT rT) := GRing.isMonoidMorphism.Build aT rT f (ahom_is_monoid_morphism f). #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ahom_is_monoid_morphism` instead")] Definition ahom_is_multiplicative (f : ahom aT rT) : multiplicative f := (fun p => (p.2, p.1)) (ahom_is_monoid_morphism f). Lemma ahomWin (f : ahom aT rT) U : ahom_in U f. Proof. by apply/ahom_inP; split; [apply: in2W (rmorphM _) | apply: rmorph1]. Qed. Lemma id_is_ahom (V : {vspace aT}) : ahom_in V \1. Proof. by apply/ahom_inP; split=> [x y|] /=; rewrite !id_lfunE. Qed. Canonical id_ahom := AHom (id_is_ahom (aspacef aT)). Lemma comp_is_ahom (V : {vspace aT}) (f : 'Hom(rT, sT)) (g : 'Hom(aT, rT)) : ahom_in {:rT} f -> ahom_in V g -> ahom_in V (f \o g). Proof. move=> /ahom_inP fM /ahom_inP gM; apply/ahom_inP. by split=> [x y Vx Vy|] /=; rewrite !comp_lfunE gM // fM ?memvf. Qed. Canonical comp_ahom (f : ahom rT sT) (g : ahom aT rT) := AHom (comp_is_ahom (valP f) (valP g)). Lemma aimgM (f : ahom aT rT) U V : (f @: (U * V) = f @: U * f @: V)%VS. Proof. apply/eqP; rewrite eqEsubv; apply/andP; split; last first. apply/prodvP=> _ _ /memv_imgP[u Hu ->] /memv_imgP[v Hv ->]. by rewrite -rmorphM memv_img // memv_mul. apply/subvP=> _ /memv_imgP[w UVw ->]; rewrite memv_preim (subvP _ w UVw) //. by apply/prodvP=> u v Uu Vv; rewrite -memv_preim rmorphM memv_mul // memv_img. Qed. Lemma aimg1 (f : ahom aT rT) : (f @: 1 = 1)%VS. Proof. by rewrite limg_line rmorph1. Qed. Lemma aimgX (f : ahom aT rT) U n : (f @: (U ^+ n) = f @: U ^+ n)%VS. Proof. elim: n => [|n IH]; first by rewrite !expv0 aimg1. by rewrite !expvSl aimgM IH. Qed. Lemma aimg_agen (f : ahom aT rT) U : (f @: agenv U)%VS = agenv (f @: U). Proof. apply/eqP; rewrite eqEsubv; apply/andP; split. by rewrite limg_sum; apply/subv_sumP => i _; rewrite aimgX subX_agenv. apply: agenv_sub_modl; first by rewrite -(aimg1 f) limgS // sub1_agenv. by rewrite -aimgM limgS // [rhs in (_ <= rhs)%VS]agenvEl addvSr. Qed. Lemma aimg_adjoin (f : ahom aT rT) U x : (f @: <<U; x>> = <<f @: U; f x>>)%VS. Proof. by rewrite aimg_agen limgD limg_line. Qed. Lemma aimg_adjoin_seq (f : ahom aT rT) U xs : (f @: <<U & xs>> = <<f @: U & map f xs>>)%VS. Proof. by rewrite aimg_agen limgD limg_span. Qed. Fact ker_sub_ahom_is_aspace (f g : ahom aT rT) : is_aspace (lker (ahval f - ahval g)). Proof. rewrite /is_aspace has_algid1; last by apply/eqlfunP; rewrite !rmorph1. apply/prodvP=> a b /eqlfunP Dfa /eqlfunP Dfb. by apply/eqlfunP; rewrite !rmorphM /= Dfa Dfb. Qed. Canonical ker_sub_ahom_aspace f g := ASpace (ker_sub_ahom_is_aspace f g). End LRMorphism. Canonical fixedSpace_aspace aT (f : ahom aT aT) := [aspace of fixedSpace f]. End AHom. Arguments ahom_in [K aT rT]. Notation "''AHom' ( aT , rT )" := (ahom aT rT) : type_scope. Notation "''AEnd' ( aT )" := (ahom aT aT) : type_scope. Delimit Scope lrfun_scope with AF. Bind Scope lrfun_scope with ahom. Notation "\1" := (@id_ahom _ _) : lrfun_scope. Notation "f \o g" := (comp_ahom f g) : lrfun_scope.
HasLaw.lean
/- Copyright (c) 2025 Etienne Marion. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: EtienneMarion -/ import Mathlib.Probability.Density import Mathlib.Probability.Moments.Variance /-! # Law of a random variable We introduce a predicate `HasLaw X μ P` stating that the random variable `X` has law `μ` under the measure `P`. This is expressed as `P.map X = μ`. We also require `X` to be `P`-almost-everywhere measurable. Indeed, if `X` is not almost-everywhere measurable then `P.map X` is defined to be `0`, so that `HasLaw X 0 P` would be true. The measurability hypothesis ensures nice interactions with operations on the codomain of `X`. See for instance `HasLaw.comp`, `IndepFun.hasLaw_mul` and `IndepFun.hasLaw_add`. -/ open MeasureTheory open scoped ENNReal namespace ProbabilityTheory variable {Ω 𝓧 : Type*} {mΩ : MeasurableSpace Ω} {m𝓧 : MeasurableSpace 𝓧} (X : Ω → 𝓧) (μ : Measure 𝓧) /-- The predicate `HasLaw X μ P` registers the fact that the random variable `X` has law `μ` under the measure `P`, in other words that `P.map X = μ`. We also require `X` to be `AEMeasurable`, to allow for nice interactions with operations on the codomain of `X`. See for instance `HasLaw.comp`, `IndepFun.hasLaw_mul` and `IndepFun.hasLaw_add`. -/ @[fun_prop] structure HasLaw (P : Measure Ω := by volume_tac) : Prop where protected aemeasurable : AEMeasurable X P := by fun_prop protected map_eq : P.map X = μ attribute [fun_prop] HasLaw.aemeasurable variable {X μ} {P : Measure Ω} lemma HasLaw.congr {Y : Ω → 𝓧} (hX : HasLaw X μ P) (hY : Y =ᵐ[P] X) : HasLaw Y μ P where aemeasurable := hX.aemeasurable.congr hY.symm map_eq := by rw [Measure.map_congr hY, hX.map_eq] lemma _root_.MeasureTheory.MeasurePreserving.hasLaw (h : MeasurePreserving X P μ) : HasLaw X μ P where aemeasurable := h.measurable.aemeasurable map_eq := h.map_eq lemma HasLaw.measurePreserving (h₁ : HasLaw X μ P) (h₂ : Measurable X) : MeasurePreserving X P μ where measurable := h₂ map_eq := h₁.map_eq @[fun_prop] lemma HasLaw.comp {𝒴 : Type*} {m𝒴 : MeasurableSpace 𝒴} {ν : Measure 𝒴} {Y : 𝓧 → 𝒴} (hY : HasLaw Y ν μ) (hX : HasLaw X μ P) : HasLaw (Y ∘ X) ν P where aemeasurable := (hX.map_eq ▸ hY.aemeasurable).comp_aemeasurable hX.aemeasurable map_eq := by rw [← AEMeasurable.map_map_of_aemeasurable _ hX.aemeasurable, hX.map_eq, hY.map_eq] rw [hX.map_eq]; exact hY.aemeasurable @[fun_prop] lemma HasLaw.fun_comp {𝒴 : Type*} {m𝒴 : MeasurableSpace 𝒴} {ν : Measure 𝒴} {Y : 𝓧 → 𝒴} (hY : HasLaw Y ν μ) (hX : HasLaw X μ P) : HasLaw (fun ω ↦ Y (X ω)) ν P := hY.comp hX @[to_additive] lemma IndepFun.hasLaw_mul {M : Type*} [Monoid M] {mM : MeasurableSpace M} [MeasurableMul₂ M] {μ ν : Measure M} [SigmaFinite μ] [SigmaFinite ν] {X Y : Ω → M} (hX : HasLaw X μ P) (hY : HasLaw Y ν P) (hXY : IndepFun X Y P) : HasLaw (X * Y) (μ ∗ₘ ν) P where map_eq := by rw [hXY.map_mul_eq_map_mconv_map₀' hX.aemeasurable hY.aemeasurable, hX.map_eq, hY.map_eq] · rwa [hX.map_eq] · rwa [hY.map_eq] @[to_additive] lemma IndepFun.hasLaw_fun_mul {M : Type*} [Monoid M] {mM : MeasurableSpace M} [MeasurableMul₂ M] {μ ν : Measure M} [SigmaFinite μ] [SigmaFinite ν] {X Y : Ω → M} (hX : HasLaw X μ P) (hY : HasLaw Y ν P) (hXY : IndepFun X Y P) : HasLaw (fun ω ↦ X ω * Y ω) (μ ∗ₘ ν) P := hXY.hasLaw_mul hX hY lemma HasLaw.integral_comp {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {X : Ω → 𝓧} (hX : HasLaw X μ P) {f : 𝓧 → E} (hf : AEStronglyMeasurable f μ) : P[f ∘ X] = ∫ x, f x ∂μ := by rw [← hX.map_eq, integral_map hX.aemeasurable] · rfl · rwa [hX.map_eq] lemma HasLaw.lintegral_comp {X : Ω → 𝓧} (hX : HasLaw X μ P) {f : 𝓧 → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ ω, f (X ω) ∂P = ∫⁻ x, f x ∂μ := by rw [← hX.map_eq, lintegral_map' _ hX.aemeasurable] rwa [hX.map_eq] lemma HasLaw.integral_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [SecondCountableTopology E] {mE : MeasurableSpace E} [OpensMeasurableSpace E] {μ : Measure E} {X : Ω → E} (hX : HasLaw X μ P) : P[X] = ∫ x, x ∂μ := by rw [← Function.id_comp X, hX.integral_comp aestronglyMeasurable_id] simp lemma HasLaw.covariance_comp (hX : HasLaw X μ P) {f g : 𝓧 → ℝ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : cov[f ∘ X, g ∘ X; P] = cov[f, g; μ] := by rw [← hX.map_eq, covariance_map] · rw [hX.map_eq] exact hf.aestronglyMeasurable · rw [hX.map_eq] exact hg.aestronglyMeasurable · exact hX.aemeasurable lemma HasLaw.covariance_fun_comp (hX : HasLaw X μ P) {f g : 𝓧 → ℝ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : cov[fun ω ↦ f (X ω), fun ω ↦ g (X ω); P] = cov[f, g; μ] := hX.covariance_comp hf hg lemma HasLaw.variance_eq {μ : Measure ℝ} {X : Ω → ℝ} (hX : HasLaw X μ P) : Var[X; P] = Var[id; μ] := by rw [← hX.map_eq, variance_map aemeasurable_id hX.aemeasurable, Function.id_comp] lemma HasPDF.hasLaw [h : HasPDF X P μ] : HasLaw X (μ.withDensity (pdf X P μ)) P where aemeasurable := h.aemeasurable map_eq := map_eq_withDensity_pdf X P μ end ProbabilityTheory
Defs.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Algebra.Group.Defs import Mathlib.Order.Filter.Tendsto import Mathlib.Tactic.Monotonicity.Basic import Mathlib.Topology.Order /-! # Uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly generalize to uniform spaces, e.g. * uniform continuity (in this file) * completeness (in `Cauchy.lean`) * extension of uniform continuous functions to complete spaces (in `IsUniformEmbedding.lean`) * totally bounded sets (in `Cauchy.lean`) * totally bounded complete sets are compact (in `Cauchy.lean`) A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means "for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages of `X`. The two main examples are: * If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V` * If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V` Those examples are generalizations in two different directions of the elementary example where `X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological group structure on `ℝ` and its metric space structure. Each uniform structure on `X` induces a topology on `X` characterized by > `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (Prod.mk x) (𝓤 X)` where `Prod.mk x : X → X × X := (fun y ↦ (x, y))` is the partial evaluation of the product constructor. The dictionary with metric spaces includes: * an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X` * a ball `ball x r` roughly corresponds to `UniformSpace.ball x V := {y | (x, y) ∈ V}` for some `V ∈ 𝓤 X`, but the later is more general (it includes in particular both open and closed balls for suitable `V`). In particular we have: `isOpen_iff_ball_subset {s : Set X} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s` The triangle inequality is abstracted to a statement involving the composition of relations in `X`. First note that the triangle inequality in a metric space is equivalent to `∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`. Then, for any `V` and `W` with type `Set (X × X)`, the composition `V ○ W : Set (X × X)` is defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`. In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }` then the triangle inequality, as reformulated above, says `V ○ W` is contained in `{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`. In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`. Note that this discussion does not depend on any axiom imposed on the uniformity filter, it is simply captured by the definition of composition. The uniform space axioms ask the filter `𝓤 X` to satisfy the following: * every `V ∈ 𝓤 X` contains the diagonal `idRel = { p | p.1 = p.2 }`. This abstracts the fact that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that `x - x` belongs to every neighborhood of zero in the topological group case. * `V ∈ 𝓤 X → Prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x` in a metric space, and to continuity of negation in the topological group case. * `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds to cutting the radius of a ball in half and applying the triangle inequality. In the topological group case, it comes from continuity of addition at `(0, 0)`. These three axioms are stated more abstractly in the definition below, in terms of operations on filters, without directly manipulating entourages. ## Main definitions * `UniformSpace X` is a uniform space structure on a type `X` * `UniformContinuous f` is a predicate saying a function `f : α → β` between uniform spaces is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r` ## Notations Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## Implementation notes There is already a theory of relations in `Data/Rel.lean` where the main definition is `def Rel (α β : Type*) := α → β → Prop`. The relations used in the current file involve only one type, but this is not the reason why we don't reuse `Data/Rel.lean`. We use `Set (α × α)` instead of `Rel α α` because we really need sets to use the filter library, and elements of filters on `α × α` have type `Set (α × α)`. The structure `UniformSpace X` bundles a uniform structure on `X`, a topology on `X` and an assumption saying those are compatible. This may not seem mathematically reasonable at first, but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance] below. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} /-- The identity relation, or the graph of the identity function -/ def idRel {α : Type*} := { p : α × α | p.1 = p.2 } @[simp] theorem mem_idRel {a b : α} : (a, b) ∈ @idRel α ↔ a = b := Iff.rfl @[simp] theorem idRel_subset {s : Set (α × α)} : idRel ⊆ s ↔ ∀ a, (a, a) ∈ s := by simp [subset_def] theorem eq_singleton_left_of_prod_subset_idRel {X : Type*} {S T : Set X} (hS : S.Nonempty) (hT : T.Nonempty) (h_diag : S ×ˢ T ⊆ idRel) : ∃ x, S = {x} := by rcases hS, hT with ⟨⟨s, hs⟩, ⟨t, ht⟩⟩ refine ⟨s, eq_singleton_iff_nonempty_unique_mem.mpr ⟨⟨s, hs⟩, fun x hx ↦ ?_⟩⟩ rw [prod_subset_iff] at h_diag replace hs := h_diag s hs t ht replace hx := h_diag x hx t ht simp only [idRel, mem_setOf_eq] at hx hs rwa [← hs] at hx theorem eq_singleton_right_prod_subset_idRel {X : Type*} {S T : Set X} (hS : S.Nonempty) (hT : T.Nonempty) (h_diag : S ×ˢ T ⊆ idRel) : ∃ x, T = {x} := by rw [Set.prod_subset_iff] at h_diag replace h_diag := fun x hx y hy => (h_diag y hy x hx).symm exact eq_singleton_left_of_prod_subset_idRel hT hS (prod_subset_iff.mpr h_diag) theorem eq_singleton_prod_subset_idRel {X : Type*} {S T : Set X} (hS : S.Nonempty) (hT : T.Nonempty) (h_diag : S ×ˢ T ⊆ idRel) : ∃ x, S = {x} ∧ T = {x} := by obtain ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ := eq_singleton_left_of_prod_subset_idRel hS hT h_diag, eq_singleton_right_prod_subset_idRel hS hT h_diag refine ⟨x, ⟨hx, ?_⟩⟩ rw [hy, Set.singleton_eq_singleton_iff] exact (Set.prod_subset_iff.mp h_diag x (by simp only [hx, Set.mem_singleton]) y (by simp only [hy, Set.mem_singleton])).symm /-- The composition of relations -/ def compRel (r₁ r₂ : Set (α × α)) := { p : α × α | ∃ z : α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂ } @[inherit_doc] scoped[Uniformity] infixl:62 " ○ " => compRel open Uniformity @[simp] theorem mem_compRel {α : Type u} {r₁ r₂ : Set (α × α)} {x y : α} : (x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := Iff.rfl @[simp] theorem swap_idRel : Prod.swap '' idRel = @idRel α := Set.ext fun ⟨a, b⟩ => by simpa [image_swap_eq_preimage_swap] using eq_comm theorem Monotone.compRel [Preorder β] {f g : β → Set (α × α)} (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ○ g x := fun _ _ h _ ⟨z, h₁, h₂⟩ => ⟨z, hf h h₁, hg h h₂⟩ @[mono, gcongr] theorem compRel_mono {f g h k : Set (α × α)} (h₁ : f ⊆ h) (h₂ : g ⊆ k) : f ○ g ⊆ h ○ k := fun _ ⟨z, h, h'⟩ => ⟨z, h₁ h, h₂ h'⟩ theorem prodMk_mem_compRel {a b c : α} {s t : Set (α × α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) : (a, b) ∈ s ○ t := ⟨c, h₁, h₂⟩ @[deprecated (since := "2025-03-10")] alias prod_mk_mem_compRel := prodMk_mem_compRel @[simp] theorem id_compRel {r : Set (α × α)} : idRel ○ r = r := Set.ext fun ⟨a, b⟩ => by simp theorem compRel_assoc {r s t : Set (α × α)} : r ○ s ○ t = r ○ (s ○ t) := by ext ⟨a, b⟩; simp only [mem_compRel]; tauto theorem left_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ t) : s ⊆ s ○ t := fun ⟨_x, y⟩ xy_in => ⟨y, xy_in, h <| rfl⟩ theorem right_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ s) : t ⊆ s ○ t := fun ⟨x, _y⟩ xy_in => ⟨x, h <| rfl, xy_in⟩ theorem subset_comp_self {s : Set (α × α)} (h : idRel ⊆ s) : s ⊆ s ○ s := left_subset_compRel h theorem subset_iterate_compRel {s t : Set (α × α)} (h : idRel ⊆ s) (n : ℕ) : t ⊆ (s ○ ·)^[n] t := by induction n generalizing t with | zero => exact Subset.rfl | succ n ihn => exact (right_subset_compRel h).trans ihn /-- The relation is invariant under swapping factors. -/ def IsSymmetricRel (V : Set (α × α)) : Prop := Prod.swap ⁻¹' V = V @[deprecated (since := "2025-03-05")] alias SymmetricRel := IsSymmetricRel /-- The maximal symmetric relation contained in a given relation. -/ def symmetrizeRel (V : Set (α × α)) : Set (α × α) := V ∩ Prod.swap ⁻¹' V theorem symmetric_symmetrizeRel (V : Set (α × α)) : IsSymmetricRel (symmetrizeRel V) := by simp [IsSymmetricRel, symmetrizeRel, preimage_inter, inter_comm, ← preimage_comp] theorem symmetrizeRel_subset_self (V : Set (α × α)) : symmetrizeRel V ⊆ V := sep_subset _ _ @[mono] theorem symmetrize_mono {V W : Set (α × α)} (h : V ⊆ W) : symmetrizeRel V ⊆ symmetrizeRel W := inter_subset_inter h <| preimage_mono h theorem IsSymmetricRel.mk_mem_comm {V : Set (α × α)} (hV : IsSymmetricRel V) {x y : α} : (x, y) ∈ V ↔ (y, x) ∈ V := Set.ext_iff.1 hV (y, x) @[deprecated (since := "2025-03-05")] alias SymmetricRel.mk_mem_comm := IsSymmetricRel.mk_mem_comm theorem IsSymmetricRel.eq {U : Set (α × α)} (hU : IsSymmetricRel U) : Prod.swap ⁻¹' U = U := hU @[deprecated (since := "2025-03-05")] alias SymmetricRel.eq := IsSymmetricRel.eq theorem IsSymmetricRel.inter {U V : Set (α × α)} (hU : IsSymmetricRel U) (hV : IsSymmetricRel V) : IsSymmetricRel (U ∩ V) := by rw [IsSymmetricRel, preimage_inter, hU.eq, hV.eq] @[deprecated (since := "2025-03-05")] alias SymmetricRel.inter := IsSymmetricRel.inter theorem IsSymmetricRel.iInter {U : (i : ι) → Set (α × α)} (hU : ∀ i, IsSymmetricRel (U i)) : IsSymmetricRel (⋂ i, U i) := by simp_rw [IsSymmetricRel, preimage_iInter, (hU _).eq] lemma IsSymmetricRel.sInter {s : Set (Set (α × α))} (h : ∀ i ∈ s, IsSymmetricRel i) : IsSymmetricRel (⋂₀ s) := by rw [sInter_eq_iInter] exact IsSymmetricRel.iInter (by simpa) lemma isSymmetricRel_idRel : IsSymmetricRel (idRel : Set (α × α)) := by simp [IsSymmetricRel, idRel, eq_comm] lemma isSymmetricRel_univ : IsSymmetricRel (Set.univ : Set (α × α)) := by simp [IsSymmetricRel] lemma IsSymmetricRel.preimage_prodMap {U : Set (β × β)} (ht : IsSymmetricRel U) (f : α → β) : IsSymmetricRel (Prod.map f f ⁻¹' U) := Set.ext fun _ ↦ ht.mk_mem_comm /-- This core description of a uniform space is outside of the type class hierarchy. It is useful for constructions of uniform spaces, when the topology is derived from the uniform space. -/ structure UniformSpace.Core (α : Type u) where /-- The uniformity filter. Once `UniformSpace` is defined, `𝓤 α` (`_root_.uniformity`) becomes the normal form. -/ uniformity : Filter (α × α) /-- Every set in the uniformity filter includes the diagonal. -/ refl : 𝓟 idRel ≤ uniformity /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity protected theorem UniformSpace.Core.comp_mem_uniformity_sets {c : Core α} {s : Set (α × α)} (hs : s ∈ c.uniformity) : ∃ t ∈ c.uniformity, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| c.comp hs /-- An alternative constructor for `UniformSpace.Core`. This version unfolds various `Filter`-related definitions. -/ def UniformSpace.Core.mk' {α : Type u} (U : Filter (α × α)) (refl : ∀ r ∈ U, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ U, Prod.swap ⁻¹' r ∈ U) (comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) : UniformSpace.Core α := ⟨U, fun _r ru => idRel_subset.2 (refl _ ru), symm, fun _r ru => let ⟨_s, hs, hsr⟩ := comp _ ru mem_of_superset (mem_lift' hs) hsr⟩ /-- Defining a `UniformSpace.Core` from a filter basis satisfying some uniformity-like axioms. -/ def UniformSpace.Core.mkOfBasis {α : Type u} (B : FilterBasis (α × α)) (refl : ∀ r ∈ B, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ B, ∃ t ∈ B, t ⊆ Prod.swap ⁻¹' r) (comp : ∀ r ∈ B, ∃ t ∈ B, t ○ t ⊆ r) : UniformSpace.Core α where uniformity := B.filter refl := B.hasBasis.ge_iff.mpr fun _r ru => idRel_subset.2 <| refl _ ru symm := (B.hasBasis.tendsto_iff B.hasBasis).mpr symm comp := (HasBasis.le_basis_iff (B.hasBasis.lift' (monotone_id.compRel monotone_id)) B.hasBasis).2 comp /-- A uniform space generates a topological space -/ def UniformSpace.Core.toTopologicalSpace {α : Type u} (u : UniformSpace.Core α) : TopologicalSpace α := .mkOfNhds fun x ↦ .comap (Prod.mk x) u.uniformity theorem UniformSpace.Core.ext : ∀ {u₁ u₂ : UniformSpace.Core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl theorem UniformSpace.Core.nhds_toTopologicalSpace {α : Type u} (u : Core α) (x : α) : @nhds α u.toTopologicalSpace x = comap (Prod.mk x) u.uniformity := by apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun _ ↦ (basis_sets _).comap _) · exact fun a U hU ↦ u.refl hU rfl · intro a U hU rcases u.comp_mem_uniformity_sets hU with ⟨V, hV, hVU⟩ filter_upwards [preimage_mem_comap hV] with b hb filter_upwards [preimage_mem_comap hV] with c hc exact hVU ⟨b, hb, hc⟩ -- the topological structure is embedded in the uniform structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- A uniform space is a generalization of the "uniform" topological aspects of a metric space. It consists of a filter on `α × α` called the "uniformity", which satisfies properties analogous to the reflexivity, symmetry, and triangle properties of a metric. A metric space has a natural uniformity, and a uniform space has a natural topology. A topological group also has a natural uniformity, even when it is not metrizable. -/ class UniformSpace (α : Type u) extends TopologicalSpace α where /-- The uniformity filter. -/ protected uniformity : Filter (α × α) /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ protected symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ protected comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity /-- The uniformity agrees with the topology: the neighborhoods filter of each point `x` is equal to `Filter.comap (Prod.mk x) (𝓤 α)`. -/ protected nhds_eq_comap_uniformity (x : α) : 𝓝 x = comap (Prod.mk x) uniformity /-- The uniformity is a filter on α × α (inferred from an ambient uniform space structure on α). -/ def uniformity (α : Type u) [UniformSpace α] : Filter (α × α) := @UniformSpace.uniformity α _ /-- Notation for the uniformity filter with respect to a non-standard `UniformSpace` instance. -/ scoped[Uniformity] notation "𝓤[" u "]" => @uniformity _ u @[inherit_doc] scoped[Uniformity] notation "𝓤" => uniformity /-- Construct a `UniformSpace` from a `u : UniformSpace.Core` and a `TopologicalSpace` structure that is equal to `u.toTopologicalSpace`. -/ abbrev UniformSpace.ofCoreEq {α : Type u} (u : UniformSpace.Core α) (t : TopologicalSpace α) (h : t = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := t nhds_eq_comap_uniformity x := by rw [h, u.nhds_toTopologicalSpace] /-- Construct a `UniformSpace` from a `UniformSpace.Core`. -/ abbrev UniformSpace.ofCore {α : Type u} (u : UniformSpace.Core α) : UniformSpace α := .ofCoreEq u _ rfl /-- Construct a `UniformSpace.Core` from a `UniformSpace`. -/ abbrev UniformSpace.toCore (u : UniformSpace α) : UniformSpace.Core α where __ := u refl := by rintro U hU ⟨x, y⟩ (rfl : x = y) have : Prod.mk x ⁻¹' U ∈ 𝓝 x := by rw [UniformSpace.nhds_eq_comap_uniformity] exact preimage_mem_comap hU convert mem_of_mem_nhds this theorem UniformSpace.toCore_toTopologicalSpace (u : UniformSpace α) : u.toCore.toTopologicalSpace = u.toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by rw [u.nhds_eq_comap_uniformity, u.toCore.nhds_toTopologicalSpace] lemma UniformSpace.mem_uniformity_ofCore_iff {u : UniformSpace.Core α} {s : Set (α × α)} : s ∈ 𝓤[.ofCore u] ↔ s ∈ u.uniformity := Iff.rfl @[ext (iff := false)] protected theorem UniformSpace.ext {u₁ u₂ : UniformSpace α} (h : 𝓤[u₁] = 𝓤[u₂]) : u₁ = u₂ := by have : u₁.toTopologicalSpace = u₂.toTopologicalSpace := TopologicalSpace.ext_nhds fun x ↦ by rw [u₁.nhds_eq_comap_uniformity, u₂.nhds_eq_comap_uniformity] exact congr_arg (comap _) h cases u₁; cases u₂; congr protected theorem UniformSpace.ext_iff {u₁ u₂ : UniformSpace α} : u₁ = u₂ ↔ ∀ s, s ∈ 𝓤[u₁] ↔ s ∈ 𝓤[u₂] := ⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ theorem UniformSpace.ofCoreEq_toCore (u : UniformSpace α) (t : TopologicalSpace α) (h : t = u.toCore.toTopologicalSpace) : .ofCoreEq u.toCore t h = u := UniformSpace.ext rfl /-- Replace topology in a `UniformSpace` instance with a propositionally (but possibly not definitionally) equal one. -/ abbrev UniformSpace.replaceTopology {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := i nhds_eq_comap_uniformity x := by rw [h, u.nhds_eq_comap_uniformity] theorem UniformSpace.replaceTopology_eq {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : u.replaceTopology h = u := UniformSpace.ext rfl section UniformSpace variable [UniformSpace α] theorem nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (Prod.mk x) := UniformSpace.nhds_eq_comap_uniformity x theorem isOpen_uniformity {s : Set α} : IsOpen s ↔ ∀ x ∈ s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap_prodMk] theorem refl_le_uniformity : 𝓟 idRel ≤ 𝓤 α := (@UniformSpace.toCore α _).refl instance uniformity.neBot [Nonempty α] : NeBot (𝓤 α) := diagonal_nonempty.principal_neBot.mono refl_le_uniformity theorem refl_mem_uniformity {x : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) : (x, x) ∈ s := refl_le_uniformity h rfl theorem mem_uniformity_of_eq {x y : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) (hx : x = y) : (x, y) ∈ s := refl_le_uniformity h hx theorem symm_le_uniformity : map (@Prod.swap α α) (𝓤 _) ≤ 𝓤 _ := UniformSpace.symm theorem comp_le_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) ≤ 𝓤 α := UniformSpace.comp theorem lift'_comp_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) = 𝓤 α := comp_le_uniformity.antisymm <| le_lift'.2 fun _s hs ↦ mem_of_superset hs <| subset_comp_self <| idRel_subset.2 fun _ ↦ refl_mem_uniformity hs theorem tendsto_swap_uniformity : Tendsto (@Prod.swap α α) (𝓤 α) (𝓤 α) := symm_le_uniformity theorem comp_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| comp_le_uniformity hs /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is transitive. -/ theorem Filter.Tendsto.uniformity_trans {l : Filter β} {f₁ f₂ f₃ : β → α} (h₁₂ : Tendsto (fun x => (f₁ x, f₂ x)) l (𝓤 α)) (h₂₃ : Tendsto (fun x => (f₂ x, f₃ x)) l (𝓤 α)) : Tendsto (fun x => (f₁ x, f₃ x)) l (𝓤 α) := by refine le_trans (le_lift'.2 fun s hs => mem_map.2 ?_) comp_le_uniformity filter_upwards [mem_map.1 (h₁₂ hs), mem_map.1 (h₂₃ hs)] with x hx₁₂ hx₂₃ using ⟨_, hx₁₂, hx₂₃⟩ /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is symmetric. -/ theorem Filter.Tendsto.uniformity_symm {l : Filter β} {f : β → α × α} (h : Tendsto f l (𝓤 α)) : Tendsto (fun x => ((f x).2, (f x).1)) l (𝓤 α) := tendsto_swap_uniformity.comp h /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is reflexive. -/ theorem tendsto_diag_uniformity (f : β → α) (l : Filter β) : Tendsto (fun x => (f x, f x)) l (𝓤 α) := fun _s hs => mem_map.2 <| univ_mem' fun _ => refl_mem_uniformity hs theorem tendsto_const_uniformity {a : α} {f : Filter β} : Tendsto (fun _ => (a, a)) f (𝓤 α) := tendsto_diag_uniformity (fun _ => a) f theorem symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s := have : preimage Prod.swap s ∈ 𝓤 α := symm_le_uniformity hs ⟨s ∩ preimage Prod.swap s, inter_mem hs this, fun _ _ ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩, inter_subset_left⟩ theorem comp_symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ {a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s := let ⟨_t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ ⟨t', ht', ht'₁ _ _, Subset.trans (monotone_id.compRel monotone_id ht'₂) ht₂⟩ theorem uniformity_le_symm : 𝓤 α ≤ map Prod.swap (𝓤 α) := by rw [map_swap_eq_comap_swap]; exact tendsto_swap_uniformity.le_comap theorem uniformity_eq_symm : 𝓤 α = map Prod.swap (𝓤 α) := le_antisymm uniformity_le_symm symm_le_uniformity @[simp] theorem comap_swap_uniformity : comap (@Prod.swap α α) (𝓤 α) = 𝓤 α := (congr_arg _ uniformity_eq_symm).trans <| comap_map Prod.swap_injective theorem symmetrize_mem_uniformity {V : Set (α × α)} (h : V ∈ 𝓤 α) : symmetrizeRel V ∈ 𝓤 α := by apply (𝓤 α).inter_sets h rw [← image_swap_eq_preimage_swap, uniformity_eq_symm] exact image_mem_map h /-- Symmetric entourages form a basis of `𝓤 α` -/ theorem UniformSpace.hasBasis_symmetric : (𝓤 α).HasBasis (fun s : Set (α × α) => s ∈ 𝓤 α ∧ IsSymmetricRel s) id := hasBasis_self.2 fun t t_in => ⟨symmetrizeRel t, symmetrize_mem_uniformity t_in, symmetric_symmetrizeRel t, symmetrizeRel_subset_self t⟩ theorem uniformity_lift_le_swap {g : Set (α × α) → Filter β} {f : Filter β} (hg : Monotone g) (h : ((𝓤 α).lift fun s => g (preimage Prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f := calc (𝓤 α).lift g ≤ (Filter.map (@Prod.swap α α) <| 𝓤 α).lift g := lift_mono uniformity_le_symm le_rfl _ ≤ _ := by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h theorem uniformity_lift_le_comp {f : Set (α × α) → Filter β} (h : Monotone f) : ((𝓤 α).lift fun s => f (s ○ s)) ≤ (𝓤 α).lift f := calc ((𝓤 α).lift fun s => f (s ○ s)) = ((𝓤 α).lift' fun s : Set (α × α) => s ○ s).lift f := by rw [lift_lift'_assoc] · exact monotone_id.compRel monotone_id · exact h _ ≤ (𝓤 α).lift f := lift_mono comp_le_uniformity le_rfl theorem comp3_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ (t ○ t) ⊆ s := let ⟨_t', ht', ht's⟩ := comp_mem_uniformity_sets hs let ⟨t, ht, htt'⟩ := comp_mem_uniformity_sets ht' ⟨t, ht, (compRel_mono ((subset_comp_self (refl_le_uniformity ht)).trans htt') htt').trans ht's⟩ /-- See also `comp3_mem_uniformity`. -/ theorem comp_le_uniformity3 : ((𝓤 α).lift' fun s : Set (α × α) => s ○ (s ○ s)) ≤ 𝓤 α := fun _ h => let ⟨_t, htU, ht⟩ := comp3_mem_uniformity h mem_of_superset (mem_lift' htU) ht /-- See also `comp_open_symm_mem_uniformity_sets`. -/ theorem comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsSymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs use symmetrizeRel w, symmetrize_mem_uniformity w_in, symmetric_symmetrizeRel w have : symmetrizeRel w ⊆ w := symmetrizeRel_subset_self w calc symmetrizeRel w ○ symmetrizeRel w _ ⊆ w ○ w := by gcongr _ ⊆ s := w_sub theorem subset_comp_self_of_mem_uniformity {s : Set (α × α)} (h : s ∈ 𝓤 α) : s ⊆ s ○ s := subset_comp_self (refl_le_uniformity h) theorem comp_comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsSymmetricRel t ∧ t ○ t ○ t ⊆ s := by rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, _, w_sub⟩ rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩ use t, t_in, t_symm have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in calc t ○ t ○ t ⊆ w ○ (t ○ t) := by gcongr _ ⊆ w ○ w := by gcongr _ ⊆ s := w_sub /-! ### Balls in uniform spaces -/ namespace UniformSpace /-- The ball around `(x : β)` with respect to `(V : Set (β × β))`. Intended to be used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/ def ball (x : β) (V : Set (β × β)) : Set β := Prod.mk x ⁻¹' V open UniformSpace (ball) lemma mem_ball_self (x : α) {V : Set (α × α)} : V ∈ 𝓤 α → x ∈ ball x V := refl_mem_uniformity /-- The triangle inequality for `UniformSpace.ball` -/ theorem mem_ball_comp {V W : Set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W) := prodMk_mem_compRel h h' theorem ball_subset_of_comp_subset {V W : Set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) : ball x W ⊆ ball y V := fun _z z_in => h' (mem_ball_comp h z_in) theorem ball_mono {V W : Set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W := preimage_mono h theorem ball_inter (x : β) (V W : Set (β × β)) : ball x (V ∩ W) = ball x V ∩ ball x W := preimage_inter theorem ball_inter_left (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x V := ball_mono inter_subset_left x theorem ball_inter_right (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x W := ball_mono inter_subset_right x theorem ball_iInter {x : β} {V : ι → Set (β × β)} : ball x (⋂ i, V i) = ⋂ i, ball x (V i) := preimage_iInter theorem mem_ball_symmetry {V : Set (β × β)} (hV : IsSymmetricRel V) {x y} : x ∈ ball y V ↔ y ∈ ball x V := show (x, y) ∈ Prod.swap ⁻¹' V ↔ (x, y) ∈ V by unfold IsSymmetricRel at hV rw [hV] theorem ball_eq_of_symmetry {V : Set (β × β)} (hV : IsSymmetricRel V) {x} : ball x V = { y | (y, x) ∈ V } := by ext y rw [mem_ball_symmetry hV] exact Iff.rfl theorem mem_comp_of_mem_ball {V W : Set (β × β)} {x y z : β} (hV : IsSymmetricRel V) (hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W := by rw [mem_ball_symmetry hV] at hx exact ⟨z, hx, hy⟩ theorem mem_comp_comp {V W M : Set (β × β)} (hW' : IsSymmetricRel W) {p : β × β} : p ∈ V ○ M ○ W ↔ (ball p.1 V ×ˢ ball p.2 W ∩ M).Nonempty := by obtain ⟨x, y⟩ := p constructor · rintro ⟨z, ⟨w, hpw, hwz⟩, hzy⟩ exact ⟨(w, z), ⟨hpw, by rwa [mem_ball_symmetry hW']⟩, hwz⟩ · rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩ rw [mem_ball_symmetry hW'] at z_in exact ⟨z, ⟨w, w_in, hwz⟩, z_in⟩ end UniformSpace /-! ### Neighborhoods in uniform spaces -/ open UniformSpace theorem mem_nhds_uniformity_iff_right {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [nhds_eq_comap_uniformity, mem_comap_prodMk] theorem mem_nhds_uniformity_iff_left {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.2 = x → p.1 ∈ s } ∈ 𝓤 α := by rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right] simp only [mem_map, preimage_setOf_eq, Prod.snd_swap, Prod.fst_swap] theorem nhdsWithin_eq_comap_uniformity_of_mem {x : α} {T : Set α} (hx : x ∈ T) (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (T ×ˢ S)).comap (Prod.mk x) := by simp [nhdsWithin, nhds_eq_comap_uniformity, hx] theorem nhdsWithin_eq_comap_uniformity {x : α} (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (univ ×ˢ S)).comap (Prod.mk x) := nhdsWithin_eq_comap_uniformity_of_mem (mem_univ _) S /-- See also `isOpen_iff_isOpen_ball_subset`. -/ theorem isOpen_iff_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, ball x V ⊆ s := by simp_rw [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap, ball] theorem nhds_basis_uniformity' {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x : α} : (𝓝 x).HasBasis p fun i => ball x (s i) := by rw [nhds_eq_comap_uniformity] exact h.comap (Prod.mk x) theorem nhds_basis_uniformity {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x : α} : (𝓝 x).HasBasis p fun i => { y | (y, x) ∈ s i } := by replace h := h.comap Prod.swap rw [comap_swap_uniformity] at h exact nhds_basis_uniformity' h theorem nhds_eq_comap_uniformity' {x : α} : 𝓝 x = (𝓤 α).comap fun y => (y, x) := (nhds_basis_uniformity (𝓤 α).basis_sets).eq_of_same_basis <| (𝓤 α).basis_sets.comap _ theorem UniformSpace.mem_nhds_iff {x : α} {s : Set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, ball x V ⊆ s := by rw [nhds_eq_comap_uniformity, mem_comap] simp_rw [ball] theorem UniformSpace.ball_mem_nhds (x : α) ⦃V : Set (α × α)⦄ (V_in : V ∈ 𝓤 α) : ball x V ∈ 𝓝 x := by rw [UniformSpace.mem_nhds_iff] exact ⟨V, V_in, Subset.rfl⟩ theorem UniformSpace.ball_mem_nhdsWithin {x : α} {S : Set α} ⦃V : Set (α × α)⦄ (x_in : x ∈ S) (V_in : V ∈ 𝓤 α ⊓ 𝓟 (S ×ˢ S)) : ball x V ∈ 𝓝[S] x := by rw [nhdsWithin_eq_comap_uniformity_of_mem x_in, mem_comap] exact ⟨V, V_in, Subset.rfl⟩ theorem UniformSpace.mem_nhds_iff_symm {x : α} {s : Set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, IsSymmetricRel V ∧ ball x V ⊆ s := by rw [UniformSpace.mem_nhds_iff] constructor · rintro ⟨V, V_in, V_sub⟩ use symmetrizeRel V, symmetrize_mem_uniformity V_in, symmetric_symmetrizeRel V exact Subset.trans (ball_mono (symmetrizeRel_subset_self V) x) V_sub · rintro ⟨V, V_in, _, V_sub⟩ exact ⟨V, V_in, V_sub⟩ theorem UniformSpace.hasBasis_nhds (x : α) : HasBasis (𝓝 x) (fun s : Set (α × α) => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s := ⟨fun t => by simp [UniformSpace.mem_nhds_iff_symm, and_assoc]⟩ open UniformSpace theorem UniformSpace.mem_closure_iff_symm_ball {s : Set α} {x} : x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → IsSymmetricRel V → (s ∩ ball x V).Nonempty := by simp [mem_closure_iff_nhds_basis (hasBasis_nhds x), Set.Nonempty] theorem UniformSpace.mem_closure_iff_ball {s : Set α} {x} : x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → (ball x V ∩ s).Nonempty := by simp [mem_closure_iff_nhds_basis' (nhds_basis_uniformity' (𝓤 α).basis_sets)] theorem nhds_eq_uniformity {x : α} : 𝓝 x = (𝓤 α).lift' (ball x) := (nhds_basis_uniformity' (𝓤 α).basis_sets).eq_biInf theorem nhds_eq_uniformity' {x : α} : 𝓝 x = (𝓤 α).lift' fun s => { y | (y, x) ∈ s } := (nhds_basis_uniformity (𝓤 α).basis_sets).eq_biInf theorem mem_nhds_left (x : α) {s : Set (α × α)} (h : s ∈ 𝓤 α) : { y : α | (x, y) ∈ s } ∈ 𝓝 x := ball_mem_nhds x h theorem mem_nhds_right (y : α) {s : Set (α × α)} (h : s ∈ 𝓤 α) : { x : α | (x, y) ∈ s } ∈ 𝓝 y := mem_nhds_left _ (symm_le_uniformity h) theorem exists_mem_nhds_ball_subset_of_mem_nhds {a : α} {U : Set α} (h : U ∈ 𝓝 a) : ∃ V ∈ 𝓝 a, ∃ t ∈ 𝓤 α, ∀ a' ∈ V, UniformSpace.ball a' t ⊆ U := let ⟨t, ht, htU⟩ := comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 h) ⟨_, mem_nhds_left a ht, t, ht, fun a₁ h₁ a₂ h₂ => @htU (a, a₂) ⟨a₁, h₁, h₂⟩ rfl⟩ theorem tendsto_right_nhds_uniformity {a : α} : Tendsto (fun a' => (a', a)) (𝓝 a) (𝓤 α) := fun _ => mem_nhds_right a theorem tendsto_left_nhds_uniformity {a : α} : Tendsto (fun a' => (a, a')) (𝓝 a) (𝓤 α) := fun _ => mem_nhds_left a theorem lift_nhds_left {x : α} {g : Set α → Filter β} (hg : Monotone g) : (𝓝 x).lift g = (𝓤 α).lift fun s : Set (α × α) => g (ball x s) := by rw [nhds_eq_comap_uniformity, comap_lift_eq2 hg] simp_rw [ball, Function.comp_def] theorem lift_nhds_right {x : α} {g : Set α → Filter β} (hg : Monotone g) : (𝓝 x).lift g = (𝓤 α).lift fun s : Set (α × α) => g { y | (y, x) ∈ s } := by rw [nhds_eq_comap_uniformity', comap_lift_eq2 hg] simp_rw [Function.comp_def, preimage] theorem nhds_nhds_eq_uniformity_uniformity_prod {a b : α} : 𝓝 a ×ˢ 𝓝 b = (𝓤 α).lift fun s : Set (α × α) => (𝓤 α).lift' fun t => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ t } := by rw [nhds_eq_uniformity', nhds_eq_uniformity, prod_lift'_lift'] exacts [rfl, monotone_preimage, monotone_preimage] theorem Filter.HasBasis.biInter_biUnion_ball {p : ι → Prop} {U : ι → Set (α × α)} (h : HasBasis (𝓤 α) p U) (s : Set α) : (⋂ (i) (_ : p i), ⋃ x ∈ s, ball x (U i)) = closure s := by ext x simp [mem_closure_iff_nhds_basis (nhds_basis_uniformity h), ball] /-! ### Uniform continuity -/ /-- A function `f : α → β` is *uniformly continuous* if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `α`. -/ def UniformContinuous [UniformSpace β] (f : α → β) := Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α) (𝓤 β) /-- Notation for uniform continuity with respect to non-standard `UniformSpace` instances. -/ scoped[Uniformity] notation "UniformContinuous[" u₁ ", " u₂ "]" => @UniformContinuous _ _ u₁ u₂ /-- A function `f : α → β` is *uniformly continuous* on `s : Set α` if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal while remaining in `s ×ˢ s`. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `s`. -/ def UniformContinuousOn [UniformSpace β] (f : α → β) (s : Set α) : Prop := Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α ⊓ 𝓟 (s ×ˢ s)) (𝓤 β) theorem uniformContinuous_def [UniformSpace β] {f : α → β} : UniformContinuous f ↔ ∀ r ∈ 𝓤 β, { x : α × α | (f x.1, f x.2) ∈ r } ∈ 𝓤 α := Iff.rfl theorem uniformContinuous_iff_eventually [UniformSpace β] {f : α → β} : UniformContinuous f ↔ ∀ r ∈ 𝓤 β, ∀ᶠ x : α × α in 𝓤 α, (f x.1, f x.2) ∈ r := Iff.rfl theorem uniformContinuousOn_univ [UniformSpace β] {f : α → β} : UniformContinuousOn f univ ↔ UniformContinuous f := by rw [UniformContinuousOn, UniformContinuous, univ_prod_univ, principal_univ, inf_top_eq] theorem uniformContinuous_of_const [UniformSpace β] {c : α → β} (h : ∀ a b, c a = c b) : UniformContinuous c := have : (fun x : α × α => (c x.fst, c x.snd)) ⁻¹' idRel = univ := eq_univ_iff_forall.2 fun ⟨a, b⟩ => h a b le_trans (map_le_iff_le_comap.2 <| by simp [comap_principal, this]) refl_le_uniformity theorem uniformContinuous_id : UniformContinuous (@id α) := tendsto_id theorem uniformContinuous_const [UniformSpace β] {b : β} : UniformContinuous fun _ : α => b := uniformContinuous_of_const fun _ _ => rfl nonrec theorem UniformContinuous.comp [UniformSpace β] [UniformSpace γ] {g : β → γ} {f : α → β} (hg : UniformContinuous g) (hf : UniformContinuous f) : UniformContinuous (g ∘ f) := hg.comp hf /-- If a function `T` is uniformly continuous in a uniform space `β`, then its `n`-th iterate `T^[n]` is also uniformly continuous. -/ theorem UniformContinuous.iterate [UniformSpace β] (T : β → β) (n : ℕ) (h : UniformContinuous T) : UniformContinuous T^[n] := by induction n with | zero => exact uniformContinuous_id | succ n hn => exact Function.iterate_succ _ _ ▸ UniformContinuous.comp hn h theorem Filter.HasBasis.uniformContinuous_iff {ι'} [UniformSpace β] {p : ι → Prop} {s : ι → Set (α × α)} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)} (hb : (𝓤 β).HasBasis q t) {f : α → β} : UniformContinuous f ↔ ∀ i, q i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ t i := (ha.tendsto_iff hb).trans <| by simp only [Prod.forall] theorem Filter.HasBasis.uniformContinuousOn_iff {ι'} [UniformSpace β] {p : ι → Prop} {s : ι → Set (α × α)} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)} (hb : (𝓤 β).HasBasis q t) {f : α → β} {S : Set α} : UniformContinuousOn f S ↔ ∀ i, q i → ∃ j, p j ∧ ∀ x, x ∈ S → ∀ y, y ∈ S → (x, y) ∈ s j → (f x, f y) ∈ t i := ((ha.inf_principal (S ×ˢ S)).tendsto_iff hb).trans <| by simp_rw [Prod.forall, Set.inter_comm (s _), forall_mem_comm, mem_inter_iff, mem_prod, and_imp] end UniformSpace
Monovary.lean
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Set.Operations import Mathlib.Order.Lattice /-! # Monovariance of functions Two functions *vary together* if a strict change in the first implies a change in the second. This is in some sense a way to say that two functions `f : ι → α`, `g : ι → β` are "monotone together", without actually having an order on `ι`. This condition comes up in the rearrangement inequality. See `Algebra.Order.Rearrangement`. ## Main declarations * `Monovary f g`: `f` monovaries with `g`. If `g i < g j`, then `f i ≤ f j`. * `Antivary f g`: `f` antivaries with `g`. If `g i < g j`, then `f j ≤ f i`. * `MonovaryOn f g s`: `f` monovaries with `g` on `s`. * `AntivaryOn f g s`: `f` antivaries with `g` on `s`. -/ open Function Set variable {ι ι' α β γ : Type*} section Preorder variable [Preorder α] [Preorder β] [Preorder γ] {f : ι → α} {f' : α → γ} {g : ι → β} {s t : Set ι} /-- `f` monovaries with `g` if `g i < g j` implies `f i ≤ f j`. -/ def Monovary (f : ι → α) (g : ι → β) : Prop := ∀ ⦃i j⦄, g i < g j → f i ≤ f j /-- `f` antivaries with `g` if `g i < g j` implies `f j ≤ f i`. -/ def Antivary (f : ι → α) (g : ι → β) : Prop := ∀ ⦃i j⦄, g i < g j → f j ≤ f i /-- `f` monovaries with `g` on `s` if `g i < g j` implies `f i ≤ f j` for all `i, j ∈ s`. -/ def MonovaryOn (f : ι → α) (g : ι → β) (s : Set ι) : Prop := ∀ ⦃i⦄ (_ : i ∈ s) ⦃j⦄ (_ : j ∈ s), g i < g j → f i ≤ f j /-- `f` antivaries with `g` on `s` if `g i < g j` implies `f j ≤ f i` for all `i, j ∈ s`. -/ def AntivaryOn (f : ι → α) (g : ι → β) (s : Set ι) : Prop := ∀ ⦃i⦄ (_ : i ∈ s) ⦃j⦄ (_ : j ∈ s), g i < g j → f j ≤ f i protected theorem Monovary.monovaryOn (h : Monovary f g) (s : Set ι) : MonovaryOn f g s := fun _ _ _ _ hij => h hij protected theorem Antivary.antivaryOn (h : Antivary f g) (s : Set ι) : AntivaryOn f g s := fun _ _ _ _ hij => h hij @[simp] theorem MonovaryOn.empty : MonovaryOn f g ∅ := fun _ => False.elim @[simp] theorem AntivaryOn.empty : AntivaryOn f g ∅ := fun _ => False.elim @[simp] theorem monovaryOn_univ : MonovaryOn f g univ ↔ Monovary f g := ⟨fun h _ _ => h trivial trivial, fun h _ _ _ _ hij => h hij⟩ @[simp] theorem antivaryOn_univ : AntivaryOn f g univ ↔ Antivary f g := ⟨fun h _ _ => h trivial trivial, fun h _ _ _ _ hij => h hij⟩ lemma monovaryOn_iff_monovary : MonovaryOn f g s ↔ Monovary (fun i : s ↦ f i) fun i ↦ g i := by simp [Monovary, MonovaryOn] lemma antivaryOn_iff_antivary : AntivaryOn f g s ↔ Antivary (fun i : s ↦ f i) fun i ↦ g i := by simp [Antivary, AntivaryOn] protected theorem MonovaryOn.subset (hst : s ⊆ t) (h : MonovaryOn f g t) : MonovaryOn f g s := fun _ hi _ hj => h (hst hi) (hst hj) protected theorem AntivaryOn.subset (hst : s ⊆ t) (h : AntivaryOn f g t) : AntivaryOn f g s := fun _ hi _ hj => h (hst hi) (hst hj) theorem monovary_const_left (g : ι → β) (a : α) : Monovary (const ι a) g := fun _ _ _ => le_rfl theorem antivary_const_left (g : ι → β) (a : α) : Antivary (const ι a) g := fun _ _ _ => le_rfl theorem monovary_const_right (f : ι → α) (b : β) : Monovary f (const ι b) := fun _ _ h => (h.ne rfl).elim theorem antivary_const_right (f : ι → α) (b : β) : Antivary f (const ι b) := fun _ _ h => (h.ne rfl).elim theorem monovary_self (f : ι → α) : Monovary f f := fun _ _ => le_of_lt theorem monovaryOn_self (f : ι → α) (s : Set ι) : MonovaryOn f f s := fun _ _ _ _ => le_of_lt protected theorem Subsingleton.monovary [Subsingleton ι] (f : ι → α) (g : ι → β) : Monovary f g := fun _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim protected theorem Subsingleton.antivary [Subsingleton ι] (f : ι → α) (g : ι → β) : Antivary f g := fun _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim protected theorem Subsingleton.monovaryOn [Subsingleton ι] (f : ι → α) (g : ι → β) (s : Set ι) : MonovaryOn f g s := fun _ _ _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim protected theorem Subsingleton.antivaryOn [Subsingleton ι] (f : ι → α) (g : ι → β) (s : Set ι) : AntivaryOn f g s := fun _ _ _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim theorem monovaryOn_const_left (g : ι → β) (a : α) (s : Set ι) : MonovaryOn (const ι a) g s := fun _ _ _ _ _ => le_rfl theorem antivaryOn_const_left (g : ι → β) (a : α) (s : Set ι) : AntivaryOn (const ι a) g s := fun _ _ _ _ _ => le_rfl theorem monovaryOn_const_right (f : ι → α) (b : β) (s : Set ι) : MonovaryOn f (const ι b) s := fun _ _ _ _ h => (h.ne rfl).elim theorem antivaryOn_const_right (f : ι → α) (b : β) (s : Set ι) : AntivaryOn f (const ι b) s := fun _ _ _ _ h => (h.ne rfl).elim theorem Monovary.comp_right (h : Monovary f g) (k : ι' → ι) : Monovary (f ∘ k) (g ∘ k) := fun _ _ hij => h hij theorem Antivary.comp_right (h : Antivary f g) (k : ι' → ι) : Antivary (f ∘ k) (g ∘ k) := fun _ _ hij => h hij theorem MonovaryOn.comp_right (h : MonovaryOn f g s) (k : ι' → ι) : MonovaryOn (f ∘ k) (g ∘ k) (k ⁻¹' s) := fun _ hi _ hj => h hi hj theorem AntivaryOn.comp_right (h : AntivaryOn f g s) (k : ι' → ι) : AntivaryOn (f ∘ k) (g ∘ k) (k ⁻¹' s) := fun _ hi _ hj => h hi hj theorem Monovary.comp_monotone_left (h : Monovary f g) (hf : Monotone f') : Monovary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem Monovary.comp_antitone_left (h : Monovary f g) (hf : Antitone f') : Antivary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem Antivary.comp_monotone_left (h : Antivary f g) (hf : Monotone f') : Antivary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem Antivary.comp_antitone_left (h : Antivary f g) (hf : Antitone f') : Monovary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem MonovaryOn.comp_monotone_on_left (h : MonovaryOn f g s) (hf : Monotone f') : MonovaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij theorem MonovaryOn.comp_antitone_on_left (h : MonovaryOn f g s) (hf : Antitone f') : AntivaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij theorem AntivaryOn.comp_monotone_on_left (h : AntivaryOn f g s) (hf : Monotone f') : AntivaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij theorem AntivaryOn.comp_antitone_on_left (h : AntivaryOn f g s) (hf : Antitone f') : MonovaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij section OrderDual open OrderDual theorem Monovary.dual : Monovary f g → Monovary (toDual ∘ f) (toDual ∘ g) := swap theorem Antivary.dual : Antivary f g → Antivary (toDual ∘ f) (toDual ∘ g) := swap theorem Monovary.dual_left : Monovary f g → Antivary (toDual ∘ f) g := id theorem Antivary.dual_left : Antivary f g → Monovary (toDual ∘ f) g := id theorem Monovary.dual_right : Monovary f g → Antivary f (toDual ∘ g) := swap theorem Antivary.dual_right : Antivary f g → Monovary f (toDual ∘ g) := swap theorem MonovaryOn.dual : MonovaryOn f g s → MonovaryOn (toDual ∘ f) (toDual ∘ g) s := swap₂ theorem AntivaryOn.dual : AntivaryOn f g s → AntivaryOn (toDual ∘ f) (toDual ∘ g) s := swap₂ theorem MonovaryOn.dual_left : MonovaryOn f g s → AntivaryOn (toDual ∘ f) g s := id theorem AntivaryOn.dual_left : AntivaryOn f g s → MonovaryOn (toDual ∘ f) g s := id theorem MonovaryOn.dual_right : MonovaryOn f g s → AntivaryOn f (toDual ∘ g) s := swap₂ theorem AntivaryOn.dual_right : AntivaryOn f g s → MonovaryOn f (toDual ∘ g) s := swap₂ @[simp] theorem monovary_toDual_left : Monovary (toDual ∘ f) g ↔ Antivary f g := Iff.rfl @[simp] theorem monovary_toDual_right : Monovary f (toDual ∘ g) ↔ Antivary f g := forall_swap @[simp] theorem antivary_toDual_left : Antivary (toDual ∘ f) g ↔ Monovary f g := Iff.rfl @[simp] theorem antivary_toDual_right : Antivary f (toDual ∘ g) ↔ Monovary f g := forall_swap @[simp] theorem monovaryOn_toDual_left : MonovaryOn (toDual ∘ f) g s ↔ AntivaryOn f g s := Iff.rfl @[simp] theorem monovaryOn_toDual_right : MonovaryOn f (toDual ∘ g) s ↔ AntivaryOn f g s := forall₂_swap @[simp] theorem antivaryOn_toDual_left : AntivaryOn (toDual ∘ f) g s ↔ MonovaryOn f g s := Iff.rfl @[simp] theorem antivaryOn_toDual_right : AntivaryOn f (toDual ∘ g) s ↔ MonovaryOn f g s := forall₂_swap end OrderDual section PartialOrder variable [PartialOrder ι] @[simp] theorem monovary_id_iff : Monovary f id ↔ Monotone f := monotone_iff_forall_lt.symm @[simp] theorem antivary_id_iff : Antivary f id ↔ Antitone f := antitone_iff_forall_lt.symm @[simp] theorem monovaryOn_id_iff : MonovaryOn f id s ↔ MonotoneOn f s := monotoneOn_iff_forall_lt.symm @[simp] theorem antivaryOn_id_iff : AntivaryOn f id s ↔ AntitoneOn f s := antitoneOn_iff_forall_lt.symm lemma StrictMono.trans_monovary (hf : StrictMono f) (h : Monovary g f) : Monotone g := monotone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictMono.trans_antivary (hf : StrictMono f) (h : Antivary g f) : Antitone g := antitone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictAnti.trans_monovary (hf : StrictAnti f) (h : Monovary g f) : Antitone g := antitone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictAnti.trans_antivary (hf : StrictAnti f) (h : Antivary g f) : Monotone g := monotone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictMonoOn.trans_monovaryOn (hf : StrictMonoOn f s) (h : MonovaryOn g f s) : MonotoneOn g s := monotoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h ha hb <| hf ha hb hab lemma StrictMonoOn.trans_antivaryOn (hf : StrictMonoOn f s) (h : AntivaryOn g f s) : AntitoneOn g s := antitoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h ha hb <| hf ha hb hab lemma StrictAntiOn.trans_monovaryOn (hf : StrictAntiOn f s) (h : MonovaryOn g f s) : AntitoneOn g s := antitoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h hb ha <| hf ha hb hab lemma StrictAntiOn.trans_antivaryOn (hf : StrictAntiOn f s) (h : AntivaryOn g f s) : MonotoneOn g s := monotoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h hb ha <| hf ha hb hab end PartialOrder variable [LinearOrder ι] protected theorem Monotone.monovary (hf : Monotone f) (hg : Monotone g) : Monovary f g := fun _ _ hij => hf (hg.reflect_lt hij).le protected theorem Monotone.antivary (hf : Monotone f) (hg : Antitone g) : Antivary f g := (hf.monovary hg.dual_right).dual_right protected theorem Antitone.monovary (hf : Antitone f) (hg : Antitone g) : Monovary f g := (hf.dual_right.antivary hg).dual_left protected theorem Antitone.antivary (hf : Antitone f) (hg : Monotone g) : Antivary f g := (hf.monovary hg.dual_right).dual_right protected theorem MonotoneOn.monovaryOn (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonovaryOn f g s := fun _ hi _ hj hij => hf hi hj (hg.reflect_lt hi hj hij).le protected theorem MonotoneOn.antivaryOn (hf : MonotoneOn f s) (hg : AntitoneOn g s) : AntivaryOn f g s := (hf.monovaryOn hg.dual_right).dual_right protected theorem AntitoneOn.monovaryOn (hf : AntitoneOn f s) (hg : AntitoneOn g s) : MonovaryOn f g s := (hf.dual_right.antivaryOn hg).dual_left protected theorem AntitoneOn.antivaryOn (hf : AntitoneOn f s) (hg : MonotoneOn g s) : AntivaryOn f g s := (hf.monovaryOn hg.dual_right).dual_right end Preorder section LinearOrder variable [Preorder α] [LinearOrder β] [Preorder γ] {f : ι → α} {g : ι → β} {g' : β → γ} {s : Set ι} theorem MonovaryOn.comp_monotoneOn_right (h : MonovaryOn f g s) (hg : MonotoneOn g' (g '' s)) : MonovaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hi hj <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij theorem MonovaryOn.comp_antitoneOn_right (h : MonovaryOn f g s) (hg : AntitoneOn g' (g '' s)) : AntivaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hj hi <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij theorem AntivaryOn.comp_monotoneOn_right (h : AntivaryOn f g s) (hg : MonotoneOn g' (g '' s)) : AntivaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hi hj <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij theorem AntivaryOn.comp_antitoneOn_right (h : AntivaryOn f g s) (hg : AntitoneOn g' (g '' s)) : MonovaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hj hi <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij @[symm] protected theorem Monovary.symm (h : Monovary f g) : Monovary g f := fun _ _ hf => le_of_not_gt fun hg => hf.not_ge <| h hg @[symm] protected theorem Antivary.symm (h : Antivary f g) : Antivary g f := fun _ _ hf => le_of_not_gt fun hg => hf.not_ge <| h hg @[symm] protected theorem MonovaryOn.symm (h : MonovaryOn f g s) : MonovaryOn g f s := fun _ hi _ hj hf => le_of_not_gt fun hg => hf.not_ge <| h hj hi hg @[symm] protected theorem AntivaryOn.symm (h : AntivaryOn f g s) : AntivaryOn g f s := fun _ hi _ hj hf => le_of_not_gt fun hg => hf.not_ge <| h hi hj hg end LinearOrder section LinearOrder variable [LinearOrder α] [LinearOrder β] {f : ι → α} {g : ι → β} {s : Set ι} theorem monovary_comm : Monovary f g ↔ Monovary g f := ⟨Monovary.symm, Monovary.symm⟩ theorem antivary_comm : Antivary f g ↔ Antivary g f := ⟨Antivary.symm, Antivary.symm⟩ theorem monovaryOn_comm : MonovaryOn f g s ↔ MonovaryOn g f s := ⟨MonovaryOn.symm, MonovaryOn.symm⟩ theorem antivaryOn_comm : AntivaryOn f g s ↔ AntivaryOn g f s := ⟨AntivaryOn.symm, AntivaryOn.symm⟩ end LinearOrder
LineGraph.lean
/- Copyright (c) 2024 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.Combinatorics.SimpleGraph.Basic /-! # LineGraph ## Main definitions * `SimpleGraph.lineGraph` is the line graph of a simple graph `G`, with vertices as the edges of `G` and two vertices of the line graph adjacent if the corresponding edges share a vertex in `G`. ## Tags line graph -/ namespace SimpleGraph variable {V : Type*} {G : SimpleGraph V} /-- The line graph of a simple graph `G` has its vertex set as the edges of `G`, and two vertices of the line graph are adjacent if the corresponding edges share a vertex in `G`. -/ def lineGraph {V : Type*} (G : SimpleGraph V) : SimpleGraph G.edgeSet where Adj e₁ e₂ := e₁ ≠ e₂ ∧ (e₁ ∩ e₂ : Set V).Nonempty symm e₁ e₂ := by intro h; rwa [ne_comm, Set.inter_comm] lemma lineGraph_adj_iff_exists {e₁ e₂ : G.edgeSet} : (G.lineGraph).Adj e₁ e₂ ↔ e₁ ≠ e₂ ∧ ∃ v, v ∈ (e₁ : Sym2 V) ∧ v ∈ (e₂ : Sym2 V) := by simp [Set.Nonempty, lineGraph] @[simp] lemma lineGraph_bot : (⊥ : SimpleGraph V).lineGraph = ⊥ := by aesop (add simp lineGraph) end SimpleGraph
Bounded.lean
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.GroupTheory.GroupAction.Pointwise import Mathlib.Analysis.LocallyConvex.Basic import Mathlib.Analysis.LocallyConvex.BalancedCoreHull import Mathlib.Analysis.Seminorm import Mathlib.LinearAlgebra.Basis.VectorSpace import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.Algebra.IsUniformGroup.Basic import Mathlib.Topology.UniformSpace.Cauchy /-! # Von Neumann Boundedness This file defines natural or von Neumann bounded sets and proves elementary properties. ## Main declarations * `Bornology.IsVonNBounded`: A set `s` is von Neumann-bounded if every neighborhood of zero absorbs `s`. * `Bornology.vonNBornology`: The bornology made of the von Neumann-bounded sets. ## Main results * `Bornology.IsVonNBounded.of_topologicalSpace_le`: A coarser topology admits more von Neumann-bounded sets. * `Bornology.IsVonNBounded.image`: A continuous linear image of a bounded set is bounded. * `Bornology.isVonNBounded_iff_smul_tendsto_zero`: Given any sequence `ε` of scalars which tends to `𝓝[≠] 0`, we have that a set `S` is bounded if and only if for any sequence `x : ℕ → S`, `ε • x` tends to 0. This shows that bounded sets are completely determined by sequences, which is the key fact for proving that sequential continuity implies continuity for linear maps defined on a bornological space ## References * [Bourbaki, *Topological Vector Spaces*][bourbaki1987] -/ variable {𝕜 𝕜' E F ι : Type*} open Set Filter Function open scoped Topology Pointwise namespace Bornology section SeminormedRing section Zero variable (𝕜) variable [SeminormedRing 𝕜] [SMul 𝕜 E] [Zero E] variable [TopologicalSpace E] /-- A set `s` is von Neumann bounded if every neighborhood of 0 absorbs `s`. -/ def IsVonNBounded (s : Set E) : Prop := ∀ ⦃V⦄, V ∈ 𝓝 (0 : E) → Absorbs 𝕜 V s variable (E) @[simp] theorem isVonNBounded_empty : IsVonNBounded 𝕜 (∅ : Set E) := fun _ _ => Absorbs.empty variable {𝕜 E} theorem isVonNBounded_iff (s : Set E) : IsVonNBounded 𝕜 s ↔ ∀ V ∈ 𝓝 (0 : E), Absorbs 𝕜 V s := Iff.rfl theorem _root_.Filter.HasBasis.isVonNBounded_iff {q : ι → Prop} {s : ι → Set E} {A : Set E} (h : (𝓝 (0 : E)).HasBasis q s) : IsVonNBounded 𝕜 A ↔ ∀ i, q i → Absorbs 𝕜 (s i) A := by refine ⟨fun hA i hi => hA (h.mem_of_mem hi), fun hA V hV => ?_⟩ rcases h.mem_iff.mp hV with ⟨i, hi, hV⟩ exact (hA i hi).mono_left hV /-- Subsets of bounded sets are bounded. -/ theorem IsVonNBounded.subset {s₁ s₂ : Set E} (h : s₁ ⊆ s₂) (hs₂ : IsVonNBounded 𝕜 s₂) : IsVonNBounded 𝕜 s₁ := fun _ hV => (hs₂ hV).mono_right h @[simp] theorem isVonNBounded_union {s t : Set E} : IsVonNBounded 𝕜 (s ∪ t) ↔ IsVonNBounded 𝕜 s ∧ IsVonNBounded 𝕜 t := by simp only [IsVonNBounded, absorbs_union, forall_and] /-- The union of two bounded sets is bounded. -/ theorem IsVonNBounded.union {s₁ s₂ : Set E} (hs₁ : IsVonNBounded 𝕜 s₁) (hs₂ : IsVonNBounded 𝕜 s₂) : IsVonNBounded 𝕜 (s₁ ∪ s₂) := isVonNBounded_union.2 ⟨hs₁, hs₂⟩ @[nontriviality] theorem IsVonNBounded.of_boundedSpace [BoundedSpace 𝕜] {s : Set E} : IsVonNBounded 𝕜 s := fun _ _ ↦ .of_boundedSpace @[nontriviality] theorem IsVonNBounded.of_subsingleton [Subsingleton E] {s : Set E} : IsVonNBounded 𝕜 s := fun U hU ↦ .of_forall fun c ↦ calc s ⊆ univ := subset_univ s _ = c • U := .symm <| Subsingleton.eq_univ_of_nonempty <| (Filter.nonempty_of_mem hU).image _ @[simp] theorem isVonNBounded_iUnion {ι : Sort*} [Finite ι] {s : ι → Set E} : IsVonNBounded 𝕜 (⋃ i, s i) ↔ ∀ i, IsVonNBounded 𝕜 (s i) := by simp only [IsVonNBounded, absorbs_iUnion, @forall_swap ι] theorem isVonNBounded_biUnion {ι : Type*} {I : Set ι} (hI : I.Finite) {s : ι → Set E} : IsVonNBounded 𝕜 (⋃ i ∈ I, s i) ↔ ∀ i ∈ I, IsVonNBounded 𝕜 (s i) := by have _ := hI.to_subtype rw [biUnion_eq_iUnion, isVonNBounded_iUnion, Subtype.forall] theorem isVonNBounded_sUnion {S : Set (Set E)} (hS : S.Finite) : IsVonNBounded 𝕜 (⋃₀ S) ↔ ∀ s ∈ S, IsVonNBounded 𝕜 s := by rw [sUnion_eq_biUnion, isVonNBounded_biUnion hS] end Zero section ContinuousAdd variable [SeminormedRing 𝕜] [AddZeroClass E] [TopologicalSpace E] [ContinuousAdd E] [DistribSMul 𝕜 E] {s t : Set E} protected theorem IsVonNBounded.add (hs : IsVonNBounded 𝕜 s) (ht : IsVonNBounded 𝕜 t) : IsVonNBounded 𝕜 (s + t) := fun U hU ↦ by rcases exists_open_nhds_zero_add_subset hU with ⟨V, hVo, hV, hVU⟩ exact ((hs <| hVo.mem_nhds hV).add (ht <| hVo.mem_nhds hV)).mono_left hVU end ContinuousAdd section IsTopologicalAddGroup variable [SeminormedRing 𝕜] [AddGroup E] [TopologicalSpace E] [IsTopologicalAddGroup E] [DistribMulAction 𝕜 E] {s t : Set E} protected theorem IsVonNBounded.neg (hs : IsVonNBounded 𝕜 s) : IsVonNBounded 𝕜 (-s) := fun U hU ↦ by rw [← neg_neg U] exact (hs <| neg_mem_nhds_zero _ hU).neg_neg @[simp] theorem isVonNBounded_neg : IsVonNBounded 𝕜 (-s) ↔ IsVonNBounded 𝕜 s := ⟨fun h ↦ neg_neg s ▸ h.neg, fun h ↦ h.neg⟩ alias ⟨IsVonNBounded.of_neg, _⟩ := isVonNBounded_neg protected theorem IsVonNBounded.sub (hs : IsVonNBounded 𝕜 s) (ht : IsVonNBounded 𝕜 t) : IsVonNBounded 𝕜 (s - t) := by rw [sub_eq_add_neg] exact hs.add ht.neg end IsTopologicalAddGroup end SeminormedRing section MultipleTopologies variable [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] /-- If a topology `t'` is coarser than `t`, then any set `s` that is bounded with respect to `t` is bounded with respect to `t'`. -/ theorem IsVonNBounded.of_topologicalSpace_le {t t' : TopologicalSpace E} (h : t ≤ t') {s : Set E} (hs : @IsVonNBounded 𝕜 E _ _ _ t s) : @IsVonNBounded 𝕜 E _ _ _ t' s := fun _ hV => hs <| (le_iff_nhds t t').mp h 0 hV end MultipleTopologies lemma isVonNBounded_iff_tendsto_smallSets_nhds {𝕜 E : Type*} [NormedDivisionRing 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] {S : Set E} : IsVonNBounded 𝕜 S ↔ Tendsto (· • S : 𝕜 → Set E) (𝓝 0) (𝓝 0).smallSets := by rw [tendsto_smallSets_iff] refine forall₂_congr fun V hV ↦ ?_ simp only [absorbs_iff_eventually_nhds_zero (mem_of_mem_nhds hV), mapsTo', image_smul] alias ⟨IsVonNBounded.tendsto_smallSets_nhds, _⟩ := isVonNBounded_iff_tendsto_smallSets_nhds lemma isVonNBounded_iff_absorbing_le {𝕜 E : Type*} [NormedDivisionRing 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] {S : Set E} : IsVonNBounded 𝕜 S ↔ Filter.absorbing 𝕜 S ≤ 𝓝 0 := .rfl lemma isVonNBounded_pi_iff {𝕜 ι : Type*} {E : ι → Type*} [NormedDivisionRing 𝕜] [∀ i, AddCommGroup (E i)] [∀ i, Module 𝕜 (E i)] [∀ i, TopologicalSpace (E i)] {S : Set (∀ i, E i)} : IsVonNBounded 𝕜 S ↔ ∀ i, IsVonNBounded 𝕜 (eval i '' S) := by simp_rw [isVonNBounded_iff_tendsto_smallSets_nhds, nhds_pi, Filter.pi, smallSets_iInf, smallSets_comap_eq_comap_image, tendsto_iInf, tendsto_comap_iff, Function.comp_def, ← image_smul, image_image, eval, Pi.smul_apply, Pi.zero_apply] section Image variable {𝕜₁ 𝕜₂ : Type*} [NormedDivisionRing 𝕜₁] [NormedDivisionRing 𝕜₂] [AddCommGroup E] [Module 𝕜₁ E] [AddCommGroup F] [Module 𝕜₂ F] [TopologicalSpace E] [TopologicalSpace F] /-- A continuous linear image of a bounded set is bounded. -/ protected theorem IsVonNBounded.image {σ : 𝕜₁ →+* 𝕜₂} [RingHomSurjective σ] [RingHomIsometric σ] {s : Set E} (hs : IsVonNBounded 𝕜₁ s) (f : E →SL[σ] F) : IsVonNBounded 𝕜₂ (f '' s) := by have : map σ (𝓝 0) = 𝓝 0 := by rw [σ.isometry.isEmbedding.map_nhds_eq, σ.surjective.range_eq, nhdsWithin_univ, map_zero] have hf₀ : Tendsto f (𝓝 0) (𝓝 0) := f.continuous.tendsto' 0 0 (map_zero f) simp only [isVonNBounded_iff_tendsto_smallSets_nhds, ← this, tendsto_map'_iff] at hs ⊢ simpa only [comp_def, image_smul_setₛₗ] using hf₀.image_smallSets.comp hs end Image section sequence theorem IsVonNBounded.smul_tendsto_zero [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] {S : Set E} {ε : ι → 𝕜} {x : ι → E} {l : Filter ι} (hS : IsVonNBounded 𝕜 S) (hxS : ∀ᶠ n in l, x n ∈ S) (hε : Tendsto ε l (𝓝 0)) : Tendsto (ε • x) l (𝓝 0) := (hS.tendsto_smallSets_nhds.comp hε).of_smallSets <| hxS.mono fun _ ↦ smul_mem_smul_set variable [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [ContinuousSMul 𝕜 E] theorem isVonNBounded_of_smul_tendsto_zero {ε : ι → 𝕜} {l : Filter ι} [l.NeBot] (hε : ∀ᶠ n in l, ε n ≠ 0) {S : Set E} (H : ∀ x : ι → E, (∀ n, x n ∈ S) → Tendsto (ε • x) l (𝓝 0)) : IsVonNBounded 𝕜 S := by rw [(nhds_basis_balanced 𝕜 E).isVonNBounded_iff] by_contra! H' rcases H' with ⟨V, ⟨hV, hVb⟩, hVS⟩ have : ∀ᶠ n in l, ∃ x : S, ε n • (x : E) ∉ V := by filter_upwards [hε] with n hn rw [absorbs_iff_norm] at hVS push_neg at hVS rcases hVS ‖(ε n)⁻¹‖ with ⟨a, haε, haS⟩ rcases Set.not_subset.mp haS with ⟨x, hxS, hx⟩ refine ⟨⟨x, hxS⟩, fun hnx => ?_⟩ rw [← Set.mem_inv_smul_set_iff₀ hn] at hnx exact hx (hVb.smul_mono haε hnx) rcases this.choice with ⟨x, hx⟩ refine Filter.frequently_false l (Filter.Eventually.frequently ?_) filter_upwards [hx, (H (_ ∘ x) fun n => (x n).2).eventually (eventually_mem_set.mpr hV)] using fun n => id /-- Given any sequence `ε` of scalars which tends to `𝓝[≠] 0`, we have that a set `S` is bounded if and only if for any sequence `x : ℕ → S`, `ε • x` tends to 0. This actually works for any indexing type `ι`, but in the special case `ι = ℕ` we get the important fact that convergent sequences fully characterize bounded sets. -/ theorem isVonNBounded_iff_smul_tendsto_zero {ε : ι → 𝕜} {l : Filter ι} [l.NeBot] (hε : Tendsto ε l (𝓝[≠] 0)) {S : Set E} : IsVonNBounded 𝕜 S ↔ ∀ x : ι → E, (∀ n, x n ∈ S) → Tendsto (ε • x) l (𝓝 0) := ⟨fun hS _ hxS => hS.smul_tendsto_zero (Eventually.of_forall hxS) (le_trans hε nhdsWithin_le_nhds), isVonNBounded_of_smul_tendsto_zero (by exact hε self_mem_nhdsWithin)⟩ end sequence /-- If a set is von Neumann bounded with respect to a smaller field, then it is also von Neumann bounded with respect to a larger field. See also `Bornology.IsVonNBounded.restrict_scalars` below. -/ theorem IsVonNBounded.extend_scalars [NontriviallyNormedField 𝕜] {E : Type*} [AddCommGroup E] [Module 𝕜 E] (𝕝 : Type*) [NontriviallyNormedField 𝕝] [NormedAlgebra 𝕜 𝕝] [Module 𝕝 E] [TopologicalSpace E] [ContinuousSMul 𝕝 E] [IsScalarTower 𝕜 𝕝 E] {s : Set E} (h : IsVonNBounded 𝕜 s) : IsVonNBounded 𝕝 s := by obtain ⟨ε, hε, hε₀⟩ : ∃ ε : ℕ → 𝕜, Tendsto ε atTop (𝓝 0) ∧ ∀ᶠ n in atTop, ε n ≠ 0 := by simpa only [tendsto_nhdsWithin_iff] using exists_seq_tendsto (𝓝[≠] (0 : 𝕜)) refine isVonNBounded_of_smul_tendsto_zero (ε := (ε · • 1)) (by simpa) fun x hx ↦ ?_ have := h.smul_tendsto_zero (.of_forall hx) hε simpa only [Pi.smul_def', smul_one_smul] section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [TopologicalSpace E] [ContinuousSMul 𝕜 E] /-- Singletons are bounded. -/ theorem isVonNBounded_singleton (x : E) : IsVonNBounded 𝕜 ({x} : Set E) := fun _ hV => (absorbent_nhds_zero hV).absorbs @[simp] theorem isVonNBounded_insert (x : E) {s : Set E} : IsVonNBounded 𝕜 (insert x s) ↔ IsVonNBounded 𝕜 s := by simp only [← singleton_union, isVonNBounded_union, isVonNBounded_singleton, true_and] protected alias ⟨_, IsVonNBounded.insert⟩ := isVonNBounded_insert section ContinuousAdd variable [ContinuousAdd E] {s t : Set E} protected theorem IsVonNBounded.vadd (hs : IsVonNBounded 𝕜 s) (x : E) : IsVonNBounded 𝕜 (x +ᵥ s) := by rw [← singleton_vadd] -- TODO: dot notation timeouts in the next line exact IsVonNBounded.add (isVonNBounded_singleton x) hs @[simp] theorem isVonNBounded_vadd (x : E) : IsVonNBounded 𝕜 (x +ᵥ s) ↔ IsVonNBounded 𝕜 s := ⟨fun h ↦ by simpa using h.vadd (-x), fun h ↦ h.vadd x⟩ theorem IsVonNBounded.of_add_right (hst : IsVonNBounded 𝕜 (s + t)) (hs : s.Nonempty) : IsVonNBounded 𝕜 t := let ⟨x, hx⟩ := hs (isVonNBounded_vadd x).mp <| hst.subset <| image_subset_image2_right hx theorem IsVonNBounded.of_add_left (hst : IsVonNBounded 𝕜 (s + t)) (ht : t.Nonempty) : IsVonNBounded 𝕜 s := ((add_comm s t).subst hst).of_add_right ht theorem isVonNBounded_add_of_nonempty (hs : s.Nonempty) (ht : t.Nonempty) : IsVonNBounded 𝕜 (s + t) ↔ IsVonNBounded 𝕜 s ∧ IsVonNBounded 𝕜 t := ⟨fun h ↦ ⟨h.of_add_left ht, h.of_add_right hs⟩, and_imp.2 IsVonNBounded.add⟩ theorem isVonNBounded_add : IsVonNBounded 𝕜 (s + t) ↔ s = ∅ ∨ t = ∅ ∨ IsVonNBounded 𝕜 s ∧ IsVonNBounded 𝕜 t := by rcases s.eq_empty_or_nonempty with rfl | hs; · simp rcases t.eq_empty_or_nonempty with rfl | ht; · simp simp [hs.ne_empty, ht.ne_empty, isVonNBounded_add_of_nonempty hs ht] @[simp] theorem isVonNBounded_add_self : IsVonNBounded 𝕜 (s + s) ↔ IsVonNBounded 𝕜 s := by rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [isVonNBounded_add_of_nonempty, *] theorem IsVonNBounded.of_sub_left (hst : IsVonNBounded 𝕜 (s - t)) (ht : t.Nonempty) : IsVonNBounded 𝕜 s := ((sub_eq_add_neg s t).subst hst).of_add_left ht.neg end ContinuousAdd section IsTopologicalAddGroup variable [IsTopologicalAddGroup E] {s t : Set E} theorem IsVonNBounded.of_sub_right (hst : IsVonNBounded 𝕜 (s - t)) (hs : s.Nonempty) : IsVonNBounded 𝕜 t := (((sub_eq_add_neg s t).subst hst).of_add_right hs).of_neg theorem isVonNBounded_sub_of_nonempty (hs : s.Nonempty) (ht : t.Nonempty) : IsVonNBounded 𝕜 (s - t) ↔ IsVonNBounded 𝕜 s ∧ IsVonNBounded 𝕜 t := by simp [sub_eq_add_neg, isVonNBounded_add_of_nonempty, hs, ht] theorem isVonNBounded_sub : IsVonNBounded 𝕜 (s - t) ↔ s = ∅ ∨ t = ∅ ∨ IsVonNBounded 𝕜 s ∧ IsVonNBounded 𝕜 t := by simp [sub_eq_add_neg, isVonNBounded_add] end IsTopologicalAddGroup /-- The union of all bounded set is the whole space. -/ theorem isVonNBounded_covers : ⋃₀ setOf (IsVonNBounded 𝕜) = (Set.univ : Set E) := Set.eq_univ_iff_forall.mpr fun x => Set.mem_sUnion.mpr ⟨{x}, isVonNBounded_singleton _, Set.mem_singleton _⟩ variable (𝕜 E) -- See note [reducible non-instances] /-- The von Neumann bornology defined by the von Neumann bounded sets. Note that this is not registered as an instance, in order to avoid diamonds with the metric bornology. -/ abbrev vonNBornology : Bornology E := Bornology.ofBounded (setOf (IsVonNBounded 𝕜)) (isVonNBounded_empty 𝕜 E) (fun _ hs _ ht => hs.subset ht) (fun _ hs _ => hs.union) isVonNBounded_singleton variable {E} @[simp] theorem isBounded_iff_isVonNBounded {s : Set E} : @IsBounded _ (vonNBornology 𝕜 E) s ↔ IsVonNBounded 𝕜 s := isBounded_ofBounded_iff _ end NormedField end Bornology section IsUniformAddGroup variable (𝕜) [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [UniformSpace E] [IsUniformAddGroup E] [ContinuousSMul 𝕜 E] theorem TotallyBounded.isVonNBounded {s : Set E} (hs : TotallyBounded s) : Bornology.IsVonNBounded 𝕜 s := by if h : ∃ x : 𝕜, 1 < ‖x‖ then letI : NontriviallyNormedField 𝕜 := ⟨h⟩ rw [totallyBounded_iff_subset_finite_iUnion_nhds_zero] at hs intro U hU have h : Filter.Tendsto (fun x : E × E => x.fst + x.snd) (𝓝 0) (𝓝 0) := continuous_add.tendsto' _ _ (zero_add _) have h' := (nhds_basis_balanced 𝕜 E).prod (nhds_basis_balanced 𝕜 E) simp_rw [← nhds_prod_eq, id] at h' rcases h.basis_left h' U hU with ⟨x, hx, h''⟩ rcases hs x.snd hx.2.1 with ⟨t, ht, hs⟩ refine Absorbs.mono_right ?_ hs rw [ht.absorbs_biUnion] have hx_fstsnd : x.fst + x.snd ⊆ U := add_subset_iff.mpr fun z1 hz1 z2 hz2 ↦ h'' <| mk_mem_prod hz1 hz2 refine fun y _ => Absorbs.mono_left ?_ hx_fstsnd -- TODO: with dot notation, Lean timeouts on the next line. Why? exact Absorbent.vadd_absorbs (absorbent_nhds_zero hx.1.1) hx.2.2.absorbs_self else haveI : BoundedSpace 𝕜 := ⟨Metric.isBounded_iff.2 ⟨1, by simp_all [dist_eq_norm]⟩⟩ exact Bornology.IsVonNBounded.of_boundedSpace end IsUniformAddGroup variable (𝕜) in theorem Filter.Tendsto.isVonNBounded_range [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul 𝕜 E] {f : ℕ → E} {x : E} (hf : Tendsto f atTop (𝓝 x)) : Bornology.IsVonNBounded 𝕜 (range f) := letI := IsTopologicalAddGroup.toUniformSpace E haveI := isUniformAddGroup_of_addCommGroup (G := E) hf.cauchySeq.totallyBounded_range.isVonNBounded 𝕜 variable (𝕜) in protected theorem Bornology.IsVonNBounded.restrict_scalars_of_nontrivial [NormedField 𝕜] [NormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜'] [Nontrivial 𝕜'] [Zero E] [TopologicalSpace E] [SMul 𝕜 E] [MulAction 𝕜' E] [IsScalarTower 𝕜 𝕜' E] {s : Set E} (h : IsVonNBounded 𝕜' s) : IsVonNBounded 𝕜 s := by intro V hV refine (h hV).restrict_scalars <| AntilipschitzWith.tendsto_cobounded (K := ‖(1 : 𝕜')‖₊⁻¹) ?_ refine AntilipschitzWith.of_le_mul_nndist fun x y ↦ ?_ rw [nndist_eq_nnnorm, nndist_eq_nnnorm, ← sub_smul, nnnorm_smul, ← div_eq_inv_mul, mul_div_cancel_right₀ _ (nnnorm_ne_zero_iff.2 one_ne_zero)] variable (𝕜) in protected theorem Bornology.IsVonNBounded.restrict_scalars [NormedField 𝕜] [NormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜'] [Zero E] [TopologicalSpace E] [SMul 𝕜 E] [MulActionWithZero 𝕜' E] [IsScalarTower 𝕜 𝕜' E] {s : Set E} (h : IsVonNBounded 𝕜' s) : IsVonNBounded 𝕜 s := match subsingleton_or_nontrivial 𝕜' with | .inl _ => have : Subsingleton E := MulActionWithZero.subsingleton 𝕜' E IsVonNBounded.of_subsingleton | .inr _ => h.restrict_scalars_of_nontrivial _ section VonNBornologyEqMetric namespace NormedSpace section NormedField variable (𝕜) variable [NormedField 𝕜] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] theorem isVonNBounded_of_isBounded {s : Set E} (h : Bornology.IsBounded s) : Bornology.IsVonNBounded 𝕜 s := by rcases h.subset_ball 0 with ⟨r, hr⟩ rw [Metric.nhds_basis_ball.isVonNBounded_iff] rw [← ball_normSeminorm 𝕜 E] at hr ⊢ exact fun ε hε ↦ ((normSeminorm 𝕜 E).ball_zero_absorbs_ball_zero hε).mono_right hr variable (E) theorem isVonNBounded_ball (r : ℝ) : Bornology.IsVonNBounded 𝕜 (Metric.ball (0 : E) r) := isVonNBounded_of_isBounded _ Metric.isBounded_ball theorem isVonNBounded_closedBall (r : ℝ) : Bornology.IsVonNBounded 𝕜 (Metric.closedBall (0 : E) r) := isVonNBounded_of_isBounded _ Metric.isBounded_closedBall end NormedField variable (𝕜) variable [NontriviallyNormedField 𝕜] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] theorem isVonNBounded_iff {s : Set E} : Bornology.IsVonNBounded 𝕜 s ↔ Bornology.IsBounded s := by refine ⟨fun h ↦ ?_, isVonNBounded_of_isBounded _⟩ rcases (h (Metric.ball_mem_nhds 0 zero_lt_one)).exists_pos with ⟨ρ, hρ, hρball⟩ rcases NormedField.exists_lt_norm 𝕜 ρ with ⟨a, ha⟩ specialize hρball a ha.le rw [← ball_normSeminorm 𝕜 E, Seminorm.smul_ball_zero (norm_pos_iff.1 <| hρ.trans ha), ball_normSeminorm] at hρball exact Metric.isBounded_ball.subset hρball theorem isVonNBounded_iff' {s : Set E} : Bornology.IsVonNBounded 𝕜 s ↔ ∃ r : ℝ, ∀ x ∈ s, ‖x‖ ≤ r := by rw [NormedSpace.isVonNBounded_iff, isBounded_iff_forall_norm_le] theorem image_isVonNBounded_iff {α : Type*} {f : α → E} {s : Set α} : Bornology.IsVonNBounded 𝕜 (f '' s) ↔ ∃ r : ℝ, ∀ x ∈ s, ‖f x‖ ≤ r := by simp_rw [isVonNBounded_iff', Set.forall_mem_image] /-- In a normed space, the von Neumann bornology (`Bornology.vonNBornology`) is equal to the metric bornology. -/ theorem vonNBornology_eq : Bornology.vonNBornology 𝕜 E = PseudoMetricSpace.toBornology := by rw [Bornology.ext_iff_isBounded] intro s rw [Bornology.isBounded_iff_isVonNBounded] exact isVonNBounded_iff _ theorem isBounded_iff_subset_smul_ball {s : Set E} : Bornology.IsBounded s ↔ ∃ a : 𝕜, s ⊆ a • Metric.ball (0 : E) 1 := by rw [← isVonNBounded_iff 𝕜] constructor · intro h rcases (h (Metric.ball_mem_nhds 0 zero_lt_one)).exists_pos with ⟨ρ, _, hρball⟩ rcases NormedField.exists_lt_norm 𝕜 ρ with ⟨a, ha⟩ exact ⟨a, hρball a ha.le⟩ · rintro ⟨a, ha⟩ exact ((isVonNBounded_ball 𝕜 E 1).image (a • (1 : E →L[𝕜] E))).subset ha theorem isBounded_iff_subset_smul_closedBall {s : Set E} : Bornology.IsBounded s ↔ ∃ a : 𝕜, s ⊆ a • Metric.closedBall (0 : E) 1 := by constructor · rw [isBounded_iff_subset_smul_ball 𝕜] exact Exists.imp fun a ha => ha.trans <| Set.smul_set_mono <| Metric.ball_subset_closedBall · rw [← isVonNBounded_iff 𝕜] rintro ⟨a, ha⟩ exact ((isVonNBounded_closedBall 𝕜 E 1).image (a • (1 : E →L[𝕜] E))).subset ha end NormedSpace end VonNBornologyEqMetric
Units.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.Order.Ring.Abs /-! # Lemmas about units in `ℤ`, which interact with the order structure. -/ namespace Int theorem isUnit_iff_abs_eq {x : ℤ} : IsUnit x ↔ abs x = 1 := by rw [isUnit_iff_natAbs_eq, abs_eq_natAbs, ← Int.ofNat_one, natCast_inj] theorem isUnit_sq {a : ℤ} (ha : IsUnit a) : a ^ 2 = 1 := by rw [sq, isUnit_mul_self ha] @[simp] theorem units_sq (u : ℤˣ) : u ^ 2 = 1 := by rw [Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one, isUnit_sq u.isUnit] alias units_pow_two := units_sq @[simp] theorem units_mul_self (u : ℤˣ) : u * u = 1 := by rw [← sq, units_sq] @[simp] theorem units_inv_eq_self (u : ℤˣ) : u⁻¹ = u := by rw [inv_eq_iff_mul_eq_one, units_mul_self] theorem units_div_eq_mul (u₁ u₂ : ℤˣ) : u₁ / u₂ = u₁ * u₂ := by rw [div_eq_mul_inv, units_inv_eq_self] -- `Units.val_mul` is a "wrong turn" for the simplifier, this undoes it and simplifies further @[simp] theorem units_coe_mul_self (u : ℤˣ) : (u * u : ℤ) = 1 := by rw [← Units.val_mul, units_mul_self, Units.val_one] theorem neg_one_pow_ne_zero {n : ℕ} : (-1 : ℤ) ^ n ≠ 0 := by simp theorem sq_eq_one_of_sq_lt_four {x : ℤ} (h1 : x ^ 2 < 4) (h2 : x ≠ 0) : x ^ 2 = 1 := sq_eq_one_iff.mpr ((abs_eq (zero_le_one' ℤ)).mp (le_antisymm (lt_add_one_iff.mp (abs_lt_of_sq_lt_sq h1 zero_le_two)) (sub_one_lt_iff.mp (abs_pos.mpr h2)))) theorem sq_eq_one_of_sq_le_three {x : ℤ} (h1 : x ^ 2 ≤ 3) (h2 : x ≠ 0) : x ^ 2 = 1 := sq_eq_one_of_sq_lt_four (lt_of_le_of_lt h1 (lt_add_one (3 : ℤ))) h2 theorem units_pow_eq_pow_mod_two (u : ℤˣ) (n : ℕ) : u ^ n = u ^ (n % 2) := by conv => lhs rw [← Nat.mod_add_div n 2] rw [pow_add, pow_mul, units_sq, one_pow, mul_one] end Int
GodelBetaFunction.lean
/- Copyright (c) 2023 Shogo Saito. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shogo Saito. Adapted for mathlib by Hunter Monroe -/ import Mathlib.Data.Nat.ModEq import Mathlib.Data.Nat.ChineseRemainder import Mathlib.Data.Nat.Prime.Defs import Mathlib.Data.Nat.Pairing import Mathlib.Order.Fin.Basic import Mathlib.Data.Finset.Lattice.Fold import Mathlib.Data.Fintype.Basic import Mathlib.Data.Nat.Factorial.Basic /-! # Gödel's Beta Function Lemma This file proves Gödel's Beta Function Lemma, used to prove the First Incompleteness Theorem. It permits quantification over finite sequences of natural numbers in formal theories of arithmetic. This Beta Function has no connection with the unrelated Beta Function defined in analysis. Note that `Nat.beta` and `Nat.unbeta` provide similar functionality to `Encodable.encodeList` and `Encodable.decodeList`. We define these separately, because it is easier to prove that `Nat.beta` and `Nat.unbeta` are arithmetically definable, and this is hard to prove that for `Encodable.encodeList` and `Encodable.decodeList` directly. The arithmetic definability is needed for the proof of the First Incompleteness Theorem. ## Main result - `beta_unbeta_coe`: Gödel's Beta Function Lemma. ## Implementation note This code is a step towards eventually including a proof of Gödel's First Incompleteness Theorem and other key results from the repository https://github.com/iehality/lean4-logic. ## References * [R. Kaye, *Models of Peano arithmetic*][kaye1991] * <https://en.wikipedia.org/wiki/G%C3%B6del%27s_%CE%B2_function> ## Tags Gödel, beta function -/ namespace Nat lemma coprime_mul_succ {n m a} (ha : m - n ∣ a) : Coprime (n * a + 1) (m * a + 1) := Nat.coprime_of_dvd fun p pp hn hm => by have : p ∣ (m - n) * a := by simpa [Nat.succ_sub_succ, ← Nat.mul_sub_right_distrib] using Nat.dvd_sub hm hn have : p ∣ a := by rcases (Nat.Prime.dvd_mul pp).mp this with (hp | hp) · exact Nat.dvd_trans hp ha · exact hp apply pp.ne_one simpa [Nat.add_sub_cancel_left] using Nat.dvd_sub hn (this.mul_left n) variable {m : ℕ} private def supOfSeq (a : Fin m → ℕ) : ℕ := max m (Finset.sup .univ a) + 1 private def coprimes (a : Fin m → ℕ) : Fin m → ℕ := fun i => (i + 1) * (supOfSeq a)! + 1 lemma coprimes_lt (a : Fin m → ℕ) (i) : a i < coprimes a i := by have h₁ : a i < supOfSeq a := Nat.lt_add_one_iff.mpr (le_max_of_le_right <| Finset.le_sup (by simp)) have h₂ : supOfSeq a ≤ (i + 1) * (supOfSeq a)! + 1 := le_trans (self_le_factorial _) (le_trans (Nat.le_mul_of_pos_left (supOfSeq a)! (succ_pos i)) (le_add_right _ _)) simpa only [coprimes] using lt_of_lt_of_le h₁ h₂ open scoped Function in -- required for scoped `on` notation private lemma pairwise_coprime_coprimes (a : Fin m → ℕ) : Pairwise (Coprime on coprimes a) := by intro i j hij wlog ltij : i < j · exact (this a hij.symm (lt_of_le_of_ne (Fin.not_lt.mp ltij) hij.symm)).symm unfold Function.onFun coprimes have hja : j < supOfSeq a := lt_of_lt_of_le j.prop (le_step (le_max_left _ _)) exact coprime_mul_succ (Nat.dvd_factorial (by omega) (by simpa only [Nat.succ_sub_succ] using le_of_lt (lt_of_le_of_lt (sub_le j i) hja))) /-- Gödel's Beta Function. This is similar to `(Encodable.decodeList)[i]`, but it is easier to prove that it is arithmetically definable. -/ def beta (n i : ℕ) : ℕ := n.unpair.1 % ((i + 1) * n.unpair.2 + 1) /-- Inverse of Gödel's Beta Function. This is similar to `Encodable.encodeList`, but it is easier to prove that it is arithmetically definable. -/ def unbeta (l : List ℕ) : ℕ := (chineseRemainderOfFinset (l[·]) (coprimes (l[·])) Finset.univ (by simp [coprimes]) (by simpa using Set.pairwise_univ.mpr (pairwise_coprime_coprimes _)) : ℕ).pair (supOfSeq (l[·]))! /-- **Gödel's Beta Function Lemma** -/ lemma beta_unbeta_coe (l : List ℕ) (i : Fin l.length) : beta (unbeta l) i = l[i] := by simpa [beta, unbeta, coprimes] using mod_eq_of_modEq ((chineseRemainderOfFinset (l[·]) (coprimes (l[·])) Finset.univ (by simp [coprimes]) (by simpa using Set.pairwise_univ.mpr (pairwise_coprime_coprimes _))).prop i (by simp)) (coprimes_lt _ _) end Nat
Invertible.lean
/- Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.RingTheory.AlgebraTower /-! # Invertible polynomials This file is a stub containing some basic facts about invertible elements in the ring of polynomials. -/ open MvPolynomial noncomputable instance MvPolynomial.invertibleC (σ : Type*) {R : Type*} [CommSemiring R] (r : R) [Invertible r] : Invertible (C r : MvPolynomial σ R) := Invertible.map (C : R →+* MvPolynomial σ R) _ /-- A natural number that is invertible when coerced to a commutative semiring `R` is also invertible when coerced to any polynomial ring with rational coefficients. Short-cut for typeclass resolution. -/ noncomputable instance MvPolynomial.invertibleCoeNat (σ R : Type*) (p : ℕ) [CommSemiring R] [Invertible (p : R)] : Invertible (p : MvPolynomial σ R) := IsScalarTower.invertibleAlgebraCoeNat R _ _
DoubleFactorial.lean
/- Copyright (c) 2023 Jake Levinson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jake Levinson -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Tactic.Ring import Mathlib.Tactic.Positivity.Core import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Double factorials This file defines the double factorial, `n‼ := n * (n - 2) * (n - 4) * ...`. ## Main declarations * `Nat.doubleFactorial`: The double factorial. -/ open Nat namespace Nat /-- `Nat.doubleFactorial n` is the double factorial of `n`. -/ @[simp] def doubleFactorial : ℕ → ℕ | 0 => 1 | 1 => 1 | k + 2 => (k + 2) * doubleFactorial k -- This notation is `\!!` not two !'s @[inherit_doc] scoped notation:10000 n "‼" => Nat.doubleFactorial n lemma doubleFactorial_pos : ∀ n, 0 < n‼ | 0 | 1 => zero_lt_one | _n + 2 => mul_pos (succ_pos _) (doubleFactorial_pos _) theorem doubleFactorial_add_two (n : ℕ) : (n + 2)‼ = (n + 2) * n‼ := rfl theorem doubleFactorial_add_one (n : ℕ) : (n + 1)‼ = (n + 1) * (n - 1)‼ := by cases n <;> rfl theorem factorial_eq_mul_doubleFactorial : ∀ n : ℕ, (n + 1)! = (n + 1)‼ * n‼ | 0 => rfl | k + 1 => by rw [doubleFactorial_add_two, factorial, factorial_eq_mul_doubleFactorial _, mul_comm _ k‼, mul_assoc] lemma doubleFactorial_le_factorial : ∀ n, n‼ ≤ n ! | 0 => le_rfl | n + 1 => by rw [factorial_eq_mul_doubleFactorial]; exact Nat.le_mul_of_pos_right _ n.doubleFactorial_pos theorem doubleFactorial_two_mul : ∀ n : ℕ, (2 * n)‼ = 2 ^ n * n ! | 0 => rfl | n + 1 => by rw [mul_add, mul_one, doubleFactorial_add_two, factorial, pow_succ, doubleFactorial_two_mul _, succ_eq_add_one] ring theorem doubleFactorial_eq_prod_even : ∀ n : ℕ, (2 * n)‼ = ∏ i ∈ Finset.range n, 2 * (i + 1) | 0 => rfl | n + 1 => by rw [Finset.prod_range_succ, ← doubleFactorial_eq_prod_even _, mul_comm (2 * n)‼, (by ring : 2 * (n + 1) = 2 * n + 2)] rfl theorem doubleFactorial_eq_prod_odd : ∀ n : ℕ, (2 * n + 1)‼ = ∏ i ∈ Finset.range n, (2 * (i + 1) + 1) | 0 => rfl | n + 1 => by rw [Finset.prod_range_succ, ← doubleFactorial_eq_prod_odd _, mul_comm (2 * n + 1)‼, (by ring : 2 * (n + 1) + 1 = 2 * n + 1 + 2)] rfl end Nat namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for `Nat.doubleFactorial`. -/ @[positivity Nat.doubleFactorial _] def evalDoubleFactorial : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℕ), ~q(Nat.doubleFactorial $n) => assumeInstancesCommute return .positive q(Nat.doubleFactorial_pos $n) | _, _ => throwError "not Nat.doubleFactorial" example (n : ℕ) : 0 < n‼ := by positivity end Mathlib.Meta.Positivity
Action.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.BigOperators.Finprod import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.Order.Group.Multiset import Mathlib.Data.Finset.Basic import Mathlib.Algebra.Group.Action.Basic /-! # Lemmas about group actions on big operators This file contains results about two kinds of actions: * sums over `DistribSMul`: `r • ∑ x ∈ s, f x = ∑ x ∈ s, r • f x` * products over `MulDistribMulAction` (with primed name): `r • ∏ x ∈ s, f x = ∏ x ∈ s, r • f x` * products over `SMulCommClass` (with unprimed name): `b ^ s.card • ∏ x ∈ s, f x = ∏ x ∈ s, b • f x` Note that analogous lemmas for `Module`s like `Finset.sum_smul` appear in other files. -/ variable {M N γ : Type*} section variable [AddMonoid N] [DistribSMul M N] theorem List.smul_sum {r : M} {l : List N} : r • l.sum = (l.map (r • ·)).sum := map_list_sum (DistribSMul.toAddMonoidHom N r) l end section variable [Monoid M] [Monoid N] [MulDistribMulAction M N] theorem List.smul_prod' {r : M} {l : List N} : r • l.prod = (l.map (r • ·)).prod := map_list_prod (MulDistribMulAction.toMonoidHom N r) l end section variable [AddCommMonoid N] [DistribSMul M N] {r : M} theorem Multiset.smul_sum {s : Multiset N} : r • s.sum = (s.map (r • ·)).sum := (DistribSMul.toAddMonoidHom N r).map_multiset_sum s theorem Finset.smul_sum {f : γ → N} {s : Finset γ} : (r • ∑ x ∈ s, f x) = ∑ x ∈ s, r • f x := map_sum (DistribSMul.toAddMonoidHom N r) f s theorem smul_finsum_mem {f : γ → N} {s : Set γ} (hs : s.Finite) : r • ∑ᶠ x ∈ s, f x = ∑ᶠ x ∈ s, r • f x := (DistribSMul.toAddMonoidHom N r).map_finsum_mem f hs end section variable [Monoid M] [CommMonoid N] [MulDistribMulAction M N] theorem Multiset.smul_prod' {r : M} {s : Multiset N} : r • s.prod = (s.map (r • ·)).prod := (MulDistribMulAction.toMonoidHom N r).map_multiset_prod s theorem Finset.smul_prod' {r : M} {f : γ → N} {s : Finset γ} : (r • ∏ x ∈ s, f x) = ∏ x ∈ s, r • f x := map_prod (MulDistribMulAction.toMonoidHom N r) f s theorem smul_finprod' {ι : Sort*} [Finite ι] {f : ι → N} (r : M) : r • ∏ᶠ x : ι, f x = ∏ᶠ x : ι, r • (f x) := by cases nonempty_fintype (PLift ι) simp only [finprod_eq_prod_plift_of_mulSupport_subset (s := Finset.univ) (by simp), Finset.smul_prod'] variable {G : Type*} [Group G] [MulDistribMulAction G N] theorem Finset.smul_prod_perm [Fintype G] (b : N) (g : G) : (g • ∏ h : G, h • b) = ∏ h : G, h • b := by simp only [smul_prod', smul_smul] exact Finset.prod_bijective (g * ·) (Group.mulLeft_bijective g) (by simp) (fun _ _ ↦ rfl) theorem smul_finprod_perm [Finite G] (b : N) (g : G) : (g • ∏ᶠ h : G, h • b) = ∏ᶠ h : G, h • b := by cases nonempty_fintype G simp only [finprod_eq_prod_of_fintype, Finset.smul_prod_perm] end namespace List @[to_additive] theorem smul_prod [Monoid M] [MulOneClass N] [MulAction M N] [IsScalarTower M N N] [SMulCommClass M N N] (l : List N) (m : M) : m ^ l.length • l.prod = (l.map (m • ·)).prod := by induction l with | nil => simp | cons head tail ih => simp [← ih, smul_mul_smul_comm, pow_succ'] end List namespace Multiset @[to_additive] theorem smul_prod [Monoid M] [CommMonoid N] [MulAction M N] [IsScalarTower M N N] [SMulCommClass M N N] (s : Multiset N) (b : M) : b ^ card s • s.prod = (s.map (b • ·)).prod := Quot.induction_on s <| by simp [List.smul_prod] end Multiset namespace Finset theorem smul_prod [CommMonoid N] [Monoid M] [MulAction M N] [IsScalarTower M N N] [SMulCommClass M N N] (s : Finset N) (b : M) (f : N → N) : b ^ s.card • ∏ x ∈ s, f x = ∏ x ∈ s, b • f x := by have : Multiset.map (fun (x : N) ↦ b • f x) s.val = Multiset.map (fun x ↦ b • x) (Multiset.map f s.val) := by simp only [Multiset.map_map, Function.comp_apply] simp_rw [prod_eq_multiset_prod, card_def, this, ← Multiset.smul_prod _ b, Multiset.card_map] theorem prod_smul [CommMonoid N] [CommMonoid M] [MulAction M N] [IsScalarTower M N N] [SMulCommClass M N N] (s : Finset N) (b : N → M) (f : N → N) : ∏ i ∈ s, b i • f i = (∏ i ∈ s, b i) • ∏ i ∈ s, f i := by induction s using Finset.cons_induction_on with | empty => simp | cons _ _ hj ih => rw [prod_cons, ih, smul_mul_smul_comm, ← prod_cons hj, ← prod_cons hj] end Finset
Derivation.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.RingTheory.Derivation.Basic /-! # Derivations of multivariate polynomials In this file we prove that a derivation of `MvPolynomial σ R` is determined by its values on all monomials `MvPolynomial.X i`. We also provide a constructor `MvPolynomial.mkDerivation` that builds a derivation from its values on `X i`s and a linear equivalence `MvPolynomial.mkDerivationEquiv` between `σ → A` and `Derivation (MvPolynomial σ R) A`. -/ namespace MvPolynomial noncomputable section variable {σ R A : Type*} [CommSemiring R] [AddCommMonoid A] [Module R A] [Module (MvPolynomial σ R) A] section variable (R) /-- The derivation on `MvPolynomial σ R` that takes value `f i` on `X i`, as a linear map. Use `MvPolynomial.mkDerivation` instead. -/ def mkDerivationₗ (f : σ → A) : MvPolynomial σ R →ₗ[R] A := Finsupp.lsum R fun xs : σ →₀ ℕ => (LinearMap.ringLmapEquivSelf R R A).symm <| xs.sum fun i k => monomial (xs - Finsupp.single i 1) (k : R) • f i end theorem mkDerivationₗ_monomial (f : σ → A) (s : σ →₀ ℕ) (r : R) : mkDerivationₗ R f (monomial s r) = r • s.sum fun i k => monomial (s - Finsupp.single i 1) (k : R) • f i := sum_monomial_eq <| LinearMap.map_zero _ theorem mkDerivationₗ_C (f : σ → A) (r : R) : mkDerivationₗ R f (C r) = 0 := (mkDerivationₗ_monomial f _ _).trans (smul_zero _) theorem mkDerivationₗ_X (f : σ → A) (i : σ) : mkDerivationₗ R f (X i) = f i := (mkDerivationₗ_monomial f _ _).trans <| by simp [tsub_self] @[simp] theorem derivation_C (D : Derivation R (MvPolynomial σ R) A) (a : R) : D (C a) = 0 := D.map_algebraMap a @[simp] theorem derivation_C_mul (D : Derivation R (MvPolynomial σ R) A) (a : R) (f : MvPolynomial σ R) : C (σ := σ) a • D f = a • D f := by have : C (σ := σ) a • D f = D (C a * f) := by simp rw [this, C_mul', D.map_smul] /-- If two derivations agree on `X i`, `i ∈ s`, then they agree on all polynomials from `MvPolynomial.supported R s`. -/ theorem derivation_eqOn_supported {D₁ D₂ : Derivation R (MvPolynomial σ R) A} {s : Set σ} (h : Set.EqOn (D₁ ∘ X) (D₂ ∘ X) s) {f : MvPolynomial σ R} (hf : f ∈ supported R s) : D₁ f = D₂ f := Derivation.eqOn_adjoin (Set.forall_mem_image.2 h) hf theorem derivation_eq_of_forall_mem_vars {D₁ D₂ : Derivation R (MvPolynomial σ R) A} {f : MvPolynomial σ R} (h : ∀ i ∈ f.vars, D₁ (X i) = D₂ (X i)) : D₁ f = D₂ f := derivation_eqOn_supported h f.mem_supported_vars theorem derivation_eq_zero_of_forall_mem_vars {D : Derivation R (MvPolynomial σ R) A} {f : MvPolynomial σ R} (h : ∀ i ∈ f.vars, D (X i) = 0) : D f = 0 := show D f = (0 : Derivation R (MvPolynomial σ R) A) f from derivation_eq_of_forall_mem_vars h @[ext] theorem derivation_ext {D₁ D₂ : Derivation R (MvPolynomial σ R) A} (h : ∀ i, D₁ (X i) = D₂ (X i)) : D₁ = D₂ := Derivation.ext fun _ => derivation_eq_of_forall_mem_vars fun i _ => h i variable [IsScalarTower R (MvPolynomial σ R) A] theorem leibniz_iff_X (D : MvPolynomial σ R →ₗ[R] A) (h₁ : D 1 = 0) : (∀ p q, D (p * q) = p • D q + q • D p) ↔ ∀ s i, D (monomial s 1 * X i) = (monomial s 1 : MvPolynomial σ R) • D (X i) + (X i : MvPolynomial σ R) • D (monomial s 1) := by refine ⟨fun H p i => H _ _, fun H => ?_⟩ have hC : ∀ r, D (C r) = 0 := by intro r; rw [C_eq_smul_one, D.map_smul, h₁, smul_zero] have : ∀ p i, D (p * X i) = p • D (X i) + (X i : MvPolynomial σ R) • D p := by intro p i induction p using MvPolynomial.induction_on' with | monomial s r => rw [← mul_one r, ← C_mul_monomial, mul_assoc, C_mul', D.map_smul, H, C_mul', smul_assoc, smul_add, D.map_smul, smul_comm r (X i)] | add p q hp hq => rw [add_mul, map_add, map_add, hp, hq, add_smul, smul_add, add_add_add_comm] intro p q induction q using MvPolynomial.induction_on with | C c => rw [mul_comm, C_mul', hC, smul_zero, zero_add, D.map_smul, C_eq_smul_one, smul_one_smul] | add q₁ q₂ h₁ h₂ => simp only [mul_add, map_add, h₁, h₂, smul_add, add_smul]; abel | mul_X q i hq => simp only [this, ← mul_assoc, hq, mul_smul, smul_add, add_assoc] rw [smul_comm (X i), smul_comm (X i)] variable (R) /-- The derivation on `MvPolynomial σ R` that takes value `f i` on `X i`. -/ def mkDerivation (f : σ → A) : Derivation R (MvPolynomial σ R) A where toLinearMap := mkDerivationₗ R f map_one_eq_zero' := mkDerivationₗ_C _ 1 leibniz' := (leibniz_iff_X (mkDerivationₗ R f) (mkDerivationₗ_C _ 1)).2 fun s i => by simp only [mkDerivationₗ_monomial, X, monomial_mul, one_smul, one_mul] rw [Finsupp.sum_add_index'] <;> [skip; simp; (intros; simp only [Nat.cast_add, (monomial _).map_add, add_smul])] rw [Finsupp.sum_single_index, Finsupp.sum_single_index] <;> [skip; simp; simp] rw [tsub_self, add_tsub_cancel_right, Nat.cast_one, ← C_apply, C_1, one_smul, add_comm, Finsupp.smul_sum] refine congr_arg₂ (· + ·) rfl (Finset.sum_congr rfl fun j hj => ?_); dsimp only rw [smul_smul, monomial_mul, one_mul, add_comm s, add_tsub_assoc_of_le] rwa [Finsupp.single_le_iff, Nat.succ_le_iff, pos_iff_ne_zero, ← Finsupp.mem_support_iff] @[simp] theorem mkDerivation_X (f : σ → A) (i : σ) : mkDerivation R f (X i) = f i := mkDerivationₗ_X f i theorem mkDerivation_monomial (f : σ → A) (s : σ →₀ ℕ) (r : R) : mkDerivation R f (monomial s r) = r • s.sum fun i k => monomial (s - Finsupp.single i 1) (k : R) • f i := mkDerivationₗ_monomial f s r /-- `MvPolynomial.mkDerivation` as a linear equivalence. -/ def mkDerivationEquiv : (σ → A) ≃ₗ[R] Derivation R (MvPolynomial σ R) A := LinearEquiv.symm <| { invFun := mkDerivation R toFun := fun D i => D (X i) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl left_inv := fun _ => derivation_ext <| mkDerivation_X _ _ right_inv := fun _ => funext <| mkDerivation_X _ _ } end end MvPolynomial
Inv.lean
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp /-! # Derivatives of `x ↦ x⁻¹` and `f x / g x` In this file we prove `(x⁻¹)' = -1 / x ^ 2`, `((f x)⁻¹)' = -f' x / (f x) ^ 2`, and `(f x / g x)' = (f' x * g x - f x * g' x) / (g x) ^ 2` for different notions of derivative. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative -/ universe u open scoped Topology open Filter Asymptotics Set open ContinuousLinearMap (smulRight) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {x : 𝕜} {s : Set 𝕜} section Inverse /-! ### Derivative of `x ↦ x⁻¹` -/ theorem hasStrictDerivAt_inv (hx : x ≠ 0) : HasStrictDerivAt Inv.inv (-(x ^ 2)⁻¹) x := by suffices (fun p : 𝕜 × 𝕜 => (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹)) =o[𝓝 (x, x)] fun p => (p.1 - p.2) * 1 by refine .of_isLittleO <| this.congr' ?_ (Eventually.of_forall fun _ => mul_one _) refine Eventually.mono ((isOpen_ne.prod isOpen_ne).mem_nhds ⟨hx, hx⟩) ?_ rintro ⟨y, z⟩ ⟨hy, hz⟩ simp only [mem_setOf_eq] at hy hz -- hy : y ≠ 0, hz : z ≠ 0 field_simp [hx, hy, hz] ring refine (isBigO_refl (fun p : 𝕜 × 𝕜 => p.1 - p.2) _).mul_isLittleO ((isLittleO_one_iff 𝕜).2 ?_) rw [← sub_self (x * x)⁻¹] exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv₀ <| mul_ne_zero hx hx) theorem hasDerivAt_inv (x_ne_zero : x ≠ 0) : HasDerivAt (fun y => y⁻¹) (-(x ^ 2)⁻¹) x := (hasStrictDerivAt_inv x_ne_zero).hasDerivAt theorem hasDerivWithinAt_inv (x_ne_zero : x ≠ 0) (s : Set 𝕜) : HasDerivWithinAt (fun x => x⁻¹) (-(x ^ 2)⁻¹) s x := (hasDerivAt_inv x_ne_zero).hasDerivWithinAt theorem differentiableAt_inv_iff : DifferentiableAt 𝕜 (fun x => x⁻¹) x ↔ x ≠ 0 := ⟨fun H => NormedField.continuousAt_inv.1 H.continuousAt, fun H => (hasDerivAt_inv H).differentiableAt⟩ theorem deriv_inv : deriv (fun x => x⁻¹) x = -(x ^ 2)⁻¹ := by rcases eq_or_ne x 0 with (rfl | hne) · simp [deriv_zero_of_not_differentiableAt (mt differentiableAt_inv_iff.1 (not_not.2 rfl))] · exact (hasDerivAt_inv hne).deriv @[simp] theorem deriv_inv' : (deriv fun x : 𝕜 => x⁻¹) = fun x => -(x ^ 2)⁻¹ := funext fun _ => deriv_inv theorem derivWithin_inv (x_ne_zero : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => x⁻¹) s x = -(x ^ 2)⁻¹ := by rw [DifferentiableAt.derivWithin (differentiableAt_inv x_ne_zero) hxs] exact deriv_inv theorem hasFDerivAt_inv (x_ne_zero : x ≠ 0) : HasFDerivAt (fun x => x⁻¹) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x := hasDerivAt_inv x_ne_zero theorem hasStrictFDerivAt_inv (x_ne_zero : x ≠ 0) : HasStrictFDerivAt (fun x => x⁻¹) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x := hasStrictDerivAt_inv x_ne_zero theorem hasFDerivWithinAt_inv (x_ne_zero : x ≠ 0) : HasFDerivWithinAt (fun x => x⁻¹) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) : 𝕜 →L[𝕜] 𝕜) s x := (hasFDerivAt_inv x_ne_zero).hasFDerivWithinAt theorem fderiv_inv : fderiv 𝕜 (fun x => x⁻¹) x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) := by rw [← deriv_fderiv, deriv_inv] theorem fderivWithin_inv (x_ne_zero : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => x⁻¹) s x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) := by rw [DifferentiableAt.fderivWithin (differentiableAt_inv x_ne_zero) hxs] exact fderiv_inv variable {c : 𝕜 → 𝕜} {c' : 𝕜} theorem HasDerivWithinAt.fun_inv (hc : HasDerivWithinAt c c' s x) (hx : c x ≠ 0) : HasDerivWithinAt (fun y => (c y)⁻¹) (-c' / c x ^ 2) s x := by convert (hasDerivAt_inv hx).comp_hasDerivWithinAt x hc using 1 field_simp theorem HasDerivWithinAt.inv (hc : HasDerivWithinAt c c' s x) (hx : c x ≠ 0) : HasDerivWithinAt (c⁻¹) (-c' / c x ^ 2) s x := hc.fun_inv hx theorem HasDerivAt.fun_inv (hc : HasDerivAt c c' x) (hx : c x ≠ 0) : HasDerivAt (fun y => (c y)⁻¹) (-c' / c x ^ 2) x := by rw [← hasDerivWithinAt_univ] at * exact hc.inv hx theorem HasDerivAt.inv (hc : HasDerivAt c c' x) (hx : c x ≠ 0) : HasDerivAt (c⁻¹) (-c' / c x ^ 2) x := hc.fun_inv hx theorem derivWithin_fun_inv' (hc : DifferentiableWithinAt 𝕜 c s x) (hx : c x ≠ 0) : derivWithin (fun x => (c x)⁻¹) s x = -derivWithin c s x / c x ^ 2 := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.inv hx).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem derivWithin_inv' (hc : DifferentiableWithinAt 𝕜 c s x) (hx : c x ≠ 0) : derivWithin (c⁻¹) s x = -derivWithin c s x / c x ^ 2 := derivWithin_fun_inv' hc hx @[simp] theorem deriv_fun_inv'' (hc : DifferentiableAt 𝕜 c x) (hx : c x ≠ 0) : deriv (fun x => (c x)⁻¹) x = -deriv c x / c x ^ 2 := (hc.hasDerivAt.inv hx).deriv @[simp] theorem deriv_inv'' (hc : DifferentiableAt 𝕜 c x) (hx : c x ≠ 0) : deriv (c⁻¹) x = -deriv c x / c x ^ 2 := (hc.hasDerivAt.inv hx).deriv end Inverse section Division /-! ### Derivative of `x ↦ c x / d x` -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] {c d : 𝕜 → 𝕜'} {c' d' : 𝕜'} theorem HasDerivWithinAt.fun_div (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) (hx : d x ≠ 0) : HasDerivWithinAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) s x := by convert hc.fun_mul ((hasDerivAt_inv hx).comp_hasDerivWithinAt x hd) using 1 · simp only [div_eq_mul_inv, (· ∘ ·)] · field_simp ring theorem HasDerivWithinAt.div (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) (hx : d x ≠ 0) : HasDerivWithinAt (c / d) ((c' * d x - c x * d') / d x ^ 2) s x := hc.fun_div hd hx theorem HasStrictDerivAt.fun_div (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) (hx : d x ≠ 0) : HasStrictDerivAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) x := by convert hc.fun_mul ((hasStrictDerivAt_inv hx).comp x hd) using 1 · simp only [div_eq_mul_inv, (· ∘ ·)] · field_simp ring theorem HasStrictDerivAt.div (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) (hx : d x ≠ 0) : HasStrictDerivAt (c / d) ((c' * d x - c x * d') / d x ^ 2) x := hc.fun_div hd hx theorem HasDerivAt.fun_div (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) (hx : d x ≠ 0) : HasDerivAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) x := by rw [← hasDerivWithinAt_univ] at * exact hc.div hd hx theorem HasDerivAt.div (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) (hx : d x ≠ 0) : HasDerivAt (c / d) ((c' * d x - c x * d') / d x ^ 2) x := hc.fun_div hd hx theorem DifferentiableWithinAt.fun_div (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) (hx : d x ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => c x / d x) s x := (hc.hasDerivWithinAt.div hd.hasDerivWithinAt hx).differentiableWithinAt theorem DifferentiableWithinAt.div (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) (hx : d x ≠ 0) : DifferentiableWithinAt 𝕜 (c / d) s x := hc.fun_div hd hx @[simp, fun_prop] theorem DifferentiableAt.fun_div (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) (hx : d x ≠ 0) : DifferentiableAt 𝕜 (fun x => c x / d x) x := (hc.hasDerivAt.div hd.hasDerivAt hx).differentiableAt @[simp, fun_prop] theorem DifferentiableAt.div (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) (hx : d x ≠ 0) : DifferentiableAt 𝕜 (c / d) x := hc.fun_div hd hx @[fun_prop] theorem DifferentiableOn.fun_div (hc : DifferentiableOn 𝕜 c s) (hd : DifferentiableOn 𝕜 d s) (hx : ∀ x ∈ s, d x ≠ 0) : DifferentiableOn 𝕜 (fun x => c x / d x) s := fun x h => (hc x h).div (hd x h) (hx x h) @[fun_prop] theorem DifferentiableOn.div (hc : DifferentiableOn 𝕜 c s) (hd : DifferentiableOn 𝕜 d s) (hx : ∀ x ∈ s, d x ≠ 0) : DifferentiableOn 𝕜 (c / d) s := fun x h => (hc x h).div (hd x h) (hx x h) @[simp, fun_prop] theorem Differentiable.fun_div (hc : Differentiable 𝕜 c) (hd : Differentiable 𝕜 d) (hx : ∀ x, d x ≠ 0) : Differentiable 𝕜 (fun x => c x / d x) := fun x => (hc x).div (hd x) (hx x) @[simp, fun_prop] theorem Differentiable.div (hc : Differentiable 𝕜 c) (hd : Differentiable 𝕜 d) (hx : ∀ x, d x ≠ 0) : Differentiable 𝕜 (c / d) := fun x => (hc x).div (hd x) (hx x) theorem derivWithin_fun_div (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) (hx : d x ≠ 0) : derivWithin (fun x => c x / d x) s x = (derivWithin c s x * d x - c x * derivWithin d s x) / d x ^ 2 := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.div hd.hasDerivWithinAt hx).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem derivWithin_div (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) (hx : d x ≠ 0) : derivWithin (c / d) s x = (derivWithin c s x * d x - c x * derivWithin d s x) / d x ^ 2 := derivWithin_fun_div hc hd hx @[simp] theorem deriv_fun_div (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) (hx : d x ≠ 0) : deriv (fun x => c x / d x) x = (deriv c x * d x - c x * deriv d x) / d x ^ 2 := (hc.hasDerivAt.div hd.hasDerivAt hx).deriv @[simp] theorem deriv_div (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) (hx : d x ≠ 0) : deriv (c / d) x = (deriv c x * d x - c x * deriv d x) / d x ^ 2 := (hc.hasDerivAt.div hd.hasDerivAt hx).deriv end Division
Fibration.lean
/- Copyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Sara Rousta -/ import Mathlib.Order.UpperLower.Basic /-! # Upper/lower sets and fibrations -/ open Set namespace Relation variable {α β : Type*} {f : α → β} lemma Fibration.isLowerSet_image [LE α] [LE β] (hf : Fibration (· ≤ ·) (· ≤ ·) f) {s : Set α} (hs : IsLowerSet s) : IsLowerSet (f '' s) := by rintro _ y' e ⟨x, hx, rfl⟩; obtain ⟨y, e', rfl⟩ := hf e; exact ⟨_, hs e' hx, rfl⟩ alias _root_.IsLowerSet.image_fibration := Fibration.isLowerSet_image lemma fibration_iff_isLowerSet_image_Iic [Preorder α] [LE β] : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ x, IsLowerSet (f '' Iic x) := ⟨fun h x ↦ (isLowerSet_Iic x).image_fibration h, fun H x _ e ↦ H x e ⟨x, le_rfl, rfl⟩⟩ lemma fibration_iff_isLowerSet_image [Preorder α] [LE β] : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ s, IsLowerSet s → IsLowerSet (f '' s) := ⟨Fibration.isLowerSet_image, fun H ↦ fibration_iff_isLowerSet_image_Iic.mpr (H _ <| isLowerSet_Iic ·)⟩ lemma fibration_iff_image_Iic [Preorder α] [Preorder β] (hf : Monotone f) : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ x, f '' Iic x = Iic (f x) := ⟨fun H x ↦ le_antisymm (fun _ ⟨_, hy, e⟩ ↦ e ▸ hf hy) ((H.isLowerSet_image (isLowerSet_Iic x)).Iic_subset ⟨x, le_rfl, rfl⟩), fun H ↦ fibration_iff_isLowerSet_image_Iic.mpr (fun x ↦ (H x).symm ▸ isLowerSet_Iic (f x))⟩ lemma Fibration.isUpperSet_image [LE α] [LE β] (hf : Fibration (· ≥ ·) (· ≥ ·) f) {s : Set α} (hs : IsUpperSet s) : IsUpperSet (f '' s) := @Fibration.isLowerSet_image αᵒᵈ βᵒᵈ _ _ _ hf s hs alias _root_.IsUpperSet.image_fibration := Fibration.isUpperSet_image lemma fibration_iff_isUpperSet_image_Ici [Preorder α] [LE β] : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ x, IsUpperSet (f '' Ici x) := @fibration_iff_isLowerSet_image_Iic αᵒᵈ βᵒᵈ _ _ _ lemma fibration_iff_isUpperSet_image [Preorder α] [LE β] : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ s, IsUpperSet s → IsUpperSet (f '' s) := @fibration_iff_isLowerSet_image αᵒᵈ βᵒᵈ _ _ _ lemma fibration_iff_image_Ici [Preorder α] [Preorder β] (hf : Monotone f) : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ x, f '' Ici x = Ici (f x) := fibration_iff_image_Iic hf.dual end Relation
ReflectsPrecoherent.lean
/- Copyright (c) 2024 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.CategoryTheory.EffectiveEpi.Enough import Mathlib.CategoryTheory.EffectiveEpi.Preserves import Mathlib.CategoryTheory.Sites.Coherent.CoherentTopology /-! # Reflecting the property of being precoherent We prove that given a fully faithful functor `F : C ⥤ D` which preserves and reflects finite effective epimorphic families, such that for every object `X` of `D` there exists an object `W` of `C` with an effective epi `π : F.obj W ⟶ X`, the category `C` is `Precoherent` whenever `D` is. -/ namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) [F.PreservesFiniteEffectiveEpiFamilies] [F.ReflectsFiniteEffectiveEpiFamilies] [F.EffectivelyEnough] [Precoherent D] [F.Full] [F.Faithful] include F in lemma Functor.reflects_precoherent : Precoherent C where pullback {B₁ B₂} f α _ X₁ π₁ _ := by obtain ⟨β, _, Y₂, τ₂, H, i, ι, hh⟩ := Precoherent.pullback (F.map f) _ _ (fun a ↦ F.map (π₁ a)) inferInstance refine ⟨β, inferInstance, _, fun b ↦ F.preimage (F.effectiveEpiOver (Y₂ b) ≫ τ₂ b), F.finite_effectiveEpiFamily_of_map _ _ ?_, ⟨i, fun b ↦ F.preimage (F.effectiveEpiOver (Y₂ b) ≫ ι b), ?_⟩⟩ · simp only [Functor.map_preimage] infer_instance · intro b apply F.map_injective simp [hh b] end CategoryTheory
SymmDiff.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 -/ import Mathlib.Order.BooleanAlgebra.Set import Mathlib.Order.SymmDiff /-! # Symmetric differences of sets -/ assert_not_exists RelIso namespace Set universe u variable {α : Type u} {a : α} {s t u : Set α} open scoped symmDiff theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s := Iff.rfl protected theorem symmDiff_def (s t : Set α) : s ∆ t = s \ t ∪ t \ s := rfl theorem symmDiff_subset_union : s ∆ t ⊆ s ∪ t := @symmDiff_le_sup (Set α) _ _ _ @[simp] theorem symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t := symmDiff_eq_bot @[simp] theorem symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t := nonempty_iff_ne_empty.trans symmDiff_eq_empty.not theorem inter_symmDiff_distrib_left (s t u : Set α) : s ∩ t ∆ u = (s ∩ t) ∆ (s ∩ u) := inf_symmDiff_distrib_left _ _ _ theorem inter_symmDiff_distrib_right (s t u : Set α) : s ∆ t ∩ u = (s ∩ u) ∆ (t ∩ u) := inf_symmDiff_distrib_right _ _ _ theorem subset_symmDiff_union_symmDiff_left (h : Disjoint s t) : u ⊆ s ∆ u ∪ t ∆ u := h.le_symmDiff_sup_symmDiff_left theorem subset_symmDiff_union_symmDiff_right (h : Disjoint t u) : s ⊆ s ∆ t ∪ s ∆ u := h.le_symmDiff_sup_symmDiff_right end Set
Pow.lean
/- Copyright (c) 2015 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Yury Kudryashov -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Basic import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual import Mathlib.Tactic.Lift import Mathlib.Tactic.Monotonicity.Attr /-! # Lemmas about the interaction of power operations with order in terms of `CovariantClass` -/ open Function variable {β G M : Type*} section Monoid variable [Monoid M] section Preorder variable [Preorder M] namespace Left variable [MulLeftMono M] {a : M} @[to_additive Left.nsmul_nonneg] theorem one_le_pow_of_le (ha : 1 ≤ a) : ∀ n : ℕ, 1 ≤ a ^ n | 0 => by simp | k + 1 => by rw [pow_succ] exact one_le_mul (one_le_pow_of_le ha k) ha @[to_additive nsmul_nonpos] theorem pow_le_one_of_le (ha : a ≤ 1) (n : ℕ) : a ^ n ≤ 1 := one_le_pow_of_le (M := Mᵒᵈ) ha n @[to_additive nsmul_neg] theorem pow_lt_one_of_lt {a : M} {n : ℕ} (h : a < 1) (hn : n ≠ 0) : a ^ n < 1 := by rcases Nat.exists_eq_succ_of_ne_zero hn with ⟨k, rfl⟩ rw [pow_succ'] exact mul_lt_one_of_lt_of_le h (pow_le_one_of_le h.le _) end Left @[to_additive nsmul_nonneg] alias one_le_pow_of_one_le' := Left.one_le_pow_of_le @[to_additive nsmul_nonpos] alias pow_le_one' := Left.pow_le_one_of_le @[to_additive nsmul_neg] alias pow_lt_one' := Left.pow_lt_one_of_lt section Left variable [MulLeftMono M] {a : M} {n : ℕ} @[to_additive nsmul_left_monotone] theorem pow_right_monotone (ha : 1 ≤ a) : Monotone fun n : ℕ ↦ a ^ n := monotone_nat_of_le_succ fun n ↦ by rw [pow_succ]; exact le_mul_of_one_le_right' ha @[to_additive (attr := gcongr) nsmul_le_nsmul_left] theorem pow_le_pow_right' {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m := pow_right_monotone ha h @[to_additive nsmul_le_nsmul_left_of_nonpos] theorem pow_le_pow_right_of_le_one' {n m : ℕ} (ha : a ≤ 1) (h : n ≤ m) : a ^ m ≤ a ^ n := pow_le_pow_right' (M := Mᵒᵈ) ha h @[to_additive nsmul_pos] theorem one_lt_pow' (ha : 1 < a) {k : ℕ} (hk : k ≠ 0) : 1 < a ^ k := pow_lt_one' (M := Mᵒᵈ) ha hk @[to_additive] lemma le_self_pow (ha : 1 ≤ a) (hn : n ≠ 0) : a ≤ a ^ n := by simpa using pow_le_pow_right' ha (Nat.one_le_iff_ne_zero.2 hn) end Left section LeftLt variable [MulLeftStrictMono M] {a : M} {n m : ℕ} @[to_additive nsmul_left_strictMono] theorem pow_right_strictMono' (ha : 1 < a) : StrictMono ((a ^ ·) : ℕ → M) := strictMono_nat_of_lt_succ fun n ↦ by rw [pow_succ]; exact lt_mul_of_one_lt_right' (a ^ n) ha @[to_additive (attr := gcongr) nsmul_lt_nsmul_left] theorem pow_lt_pow_right' (ha : 1 < a) (h : n < m) : a ^ n < a ^ m := pow_right_strictMono' ha h end LeftLt section Right variable [MulRightMono M] {x : M} @[to_additive Right.nsmul_nonneg] theorem Right.one_le_pow_of_le (hx : 1 ≤ x) : ∀ {n : ℕ}, 1 ≤ x ^ n | 0 => (pow_zero _).ge | n + 1 => by rw [pow_succ] exact Right.one_le_mul (Right.one_le_pow_of_le hx) hx @[to_additive Right.nsmul_nonpos] theorem Right.pow_le_one_of_le (hx : x ≤ 1) {n : ℕ} : x ^ n ≤ 1 := Right.one_le_pow_of_le (M := Mᵒᵈ) hx @[to_additive Right.nsmul_neg] theorem Right.pow_lt_one_of_lt {n : ℕ} {x : M} (hn : 0 < n) (h : x < 1) : x ^ n < 1 := by rcases Nat.exists_eq_succ_of_ne_zero hn.ne' with ⟨k, rfl⟩ rw [pow_succ] exact mul_lt_one_of_le_of_lt (pow_le_one_of_le h.le) h /-- This lemma is useful in non-cancellative monoids, like sets under pointwise operations. -/ @[to_additive /-- This lemma is useful in non-cancellative monoids, like sets under pointwise operations. -/] lemma pow_le_pow_mul_of_sq_le_mul [MulLeftMono M] {a b : M} (hab : a ^ 2 ≤ b * a) : ∀ {n}, n ≠ 0 → a ^ n ≤ b ^ (n - 1) * a | 1, _ => by simp | n + 2, _ => by calc a ^ (n + 2) = a ^ (n + 1) * a := by rw [pow_succ] _ ≤ b ^ n * a * a := mul_le_mul_right' (pow_le_pow_mul_of_sq_le_mul hab (by omega)) _ _ = b ^ n * a ^ 2 := by rw [mul_assoc, sq] _ ≤ b ^ n * (b * a) := mul_le_mul_left' hab _ _ = b ^ (n + 1) * a := by rw [← mul_assoc, ← pow_succ] end Right section CovariantLTSwap variable [Preorder β] [MulLeftStrictMono M] [MulRightStrictMono M] {f : β → M} {n : ℕ} @[to_additive StrictMono.const_nsmul] theorem StrictMono.pow_const (hf : StrictMono f) : ∀ {n : ℕ}, n ≠ 0 → StrictMono (f · ^ n) | 0, hn => (hn rfl).elim | 1, _ => by simpa | Nat.succ <| Nat.succ n, _ => by simpa only [pow_succ] using (hf.pow_const n.succ_ne_zero).mul' hf /-- See also `pow_left_strictMonoOn₀`. -/ @[to_additive nsmul_right_strictMono] theorem pow_left_strictMono (hn : n ≠ 0) : StrictMono (· ^ n : M → M) := strictMono_id.pow_const hn @[to_additive (attr := mono, gcongr) nsmul_lt_nsmul_right] lemma pow_lt_pow_left' (hn : n ≠ 0) {a b : M} (hab : a < b) : a ^ n < b ^ n := pow_left_strictMono hn hab end CovariantLTSwap section CovariantLESwap variable [Preorder β] [MulLeftMono M] [MulRightMono M] @[to_additive (attr := mono, gcongr) nsmul_le_nsmul_right] theorem pow_le_pow_left' {a b : M} (hab : a ≤ b) : ∀ i : ℕ, a ^ i ≤ b ^ i | 0 => by simp | k + 1 => by rw [pow_succ, pow_succ] exact mul_le_mul' (pow_le_pow_left' hab k) hab @[to_additive Monotone.const_nsmul] theorem Monotone.pow_const {f : β → M} (hf : Monotone f) : ∀ n : ℕ, Monotone fun a => f a ^ n | 0 => by simpa using monotone_const | n + 1 => by simp_rw [pow_succ] exact (Monotone.pow_const hf _).mul' hf @[to_additive nsmul_right_mono] theorem pow_left_mono (n : ℕ) : Monotone fun a : M => a ^ n := monotone_id.pow_const _ @[to_additive (attr := gcongr)] lemma pow_le_pow {a b : M} (hab : a ≤ b) (ht : 1 ≤ b) {m n : ℕ} (hmn : m ≤ n) : a ^ m ≤ b ^ n := (pow_le_pow_left' hab _).trans (pow_le_pow_right' ht hmn) end CovariantLESwap end Preorder section SemilatticeSup variable [SemilatticeSup M] [MulLeftMono M] [MulRightMono M] {a b : M} {n : ℕ} lemma le_pow_sup : a ^ n ⊔ b ^ n ≤ (a ⊔ b) ^ n := sup_le (pow_le_pow_left' le_sup_left _) (pow_le_pow_left' le_sup_right _) end SemilatticeSup section SemilatticeInf variable [SemilatticeInf M] [MulLeftMono M] [MulRightMono M] {a b : M} {n : ℕ} lemma pow_inf_le : (a ⊓ b) ^ n ≤ a ^ n ⊓ b ^ n := le_inf (pow_le_pow_left' inf_le_left _) (pow_le_pow_left' inf_le_right _) end SemilatticeInf section LinearOrder variable [LinearOrder M] section CovariantLE variable [MulLeftMono M] -- This generalises to lattices. See `pow_two_semiclosed` @[to_additive nsmul_nonneg_iff] theorem one_le_pow_iff {x : M} {n : ℕ} (hn : n ≠ 0) : 1 ≤ x ^ n ↔ 1 ≤ x := ⟨le_imp_le_of_lt_imp_lt fun h => pow_lt_one' h hn, fun h => one_le_pow_of_one_le' h n⟩ @[to_additive] theorem pow_le_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n ≤ 1 ↔ x ≤ 1 := one_le_pow_iff (M := Mᵒᵈ) hn @[to_additive nsmul_pos_iff] theorem one_lt_pow_iff {x : M} {n : ℕ} (hn : n ≠ 0) : 1 < x ^ n ↔ 1 < x := lt_iff_lt_of_le_iff_le (pow_le_one_iff hn) @[to_additive] theorem pow_lt_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n < 1 ↔ x < 1 := lt_iff_lt_of_le_iff_le (one_le_pow_iff hn) @[to_additive] theorem pow_eq_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n = 1 ↔ x = 1 := by simp only [le_antisymm_iff] rw [pow_le_one_iff hn, one_le_pow_iff hn] end CovariantLE section CovariantLT variable [MulLeftStrictMono M] {a : M} {m n : ℕ} @[to_additive nsmul_le_nsmul_iff_left] theorem pow_le_pow_iff_right' (ha : 1 < a) : a ^ m ≤ a ^ n ↔ m ≤ n := (pow_right_strictMono' ha).le_iff_le @[to_additive nsmul_lt_nsmul_iff_left] theorem pow_lt_pow_iff_right' (ha : 1 < a) : a ^ m < a ^ n ↔ m < n := (pow_right_strictMono' ha).lt_iff_lt end CovariantLT section CovariantLESwap variable [MulLeftMono M] [MulRightMono M] @[to_additive lt_of_nsmul_lt_nsmul_right] theorem lt_of_pow_lt_pow_left' {a b : M} (n : ℕ) : a ^ n < b ^ n → a < b := (pow_left_mono _).reflect_lt @[to_additive min_lt_of_add_lt_two_nsmul] theorem min_lt_of_mul_lt_sq {a b c : M} (h : a * b < c ^ 2) : min a b < c := by simpa using min_lt_max_of_mul_lt_mul (h.trans_eq <| pow_two _) @[to_additive lt_max_of_two_nsmul_lt_add] theorem lt_max_of_sq_lt_mul {a b c : M} (h : a ^ 2 < b * c) : a < max b c := by simpa using min_lt_max_of_mul_lt_mul ((pow_two _).symm.trans_lt h) end CovariantLESwap section CovariantLTSwap variable [MulLeftStrictMono M] [MulRightStrictMono M] @[to_additive le_of_nsmul_le_nsmul_right] theorem le_of_pow_le_pow_left' {a b : M} {n : ℕ} (hn : n ≠ 0) : a ^ n ≤ b ^ n → a ≤ b := (pow_left_strictMono hn).le_iff_le.1 @[to_additive min_le_of_add_le_two_nsmul] theorem min_le_of_mul_le_sq {a b c : M} (h : a * b ≤ c ^ 2) : min a b ≤ c := by simpa using min_le_max_of_mul_le_mul (h.trans_eq <| pow_two _) @[to_additive le_max_of_two_nsmul_le_add] theorem le_max_of_sq_le_mul {a b c : M} (h : a ^ 2 ≤ b * c) : a ≤ max b c := by simpa using min_le_max_of_mul_le_mul ((pow_two _).symm.trans_le h) end CovariantLTSwap @[to_additive Left.nsmul_neg_iff] theorem Left.pow_lt_one_iff' [MulLeftStrictMono M] {n : ℕ} {x : M} (hn : 0 < n) : x ^ n < 1 ↔ x < 1 := haveI := mulLeftMono_of_mulLeftStrictMono M pow_lt_one_iff hn.ne' theorem Left.pow_lt_one_iff [MulLeftStrictMono M] {n : ℕ} {x : M} (hn : 0 < n) : x ^ n < 1 ↔ x < 1 := Left.pow_lt_one_iff' hn @[to_additive] theorem Right.pow_lt_one_iff [MulRightStrictMono M] {n : ℕ} {x : M} (hn : 0 < n) : x ^ n < 1 ↔ x < 1 := haveI := mulRightMono_of_mulRightStrictMono M ⟨fun H => not_le.mp fun k => H.not_ge <| Right.one_le_pow_of_le k, Right.pow_lt_one_of_lt hn⟩ end LinearOrder end Monoid section DivInvMonoid variable [DivInvMonoid G] [Preorder G] [MulLeftMono G] @[to_additive zsmul_nonneg] theorem one_le_zpow {x : G} (H : 1 ≤ x) {n : ℤ} (hn : 0 ≤ n) : 1 ≤ x ^ n := by lift n to ℕ using hn rw [zpow_natCast] apply one_le_pow_of_one_le' H @[to_additive zsmul_pos] lemma one_lt_zpow {x : G} (hx : 1 < x) {n : ℤ} (hn : 0 < n) : 1 < x ^ n := by lift n to ℕ using Int.le_of_lt hn rw [zpow_natCast] exact one_lt_pow' hx (Int.natCast_pos.mp hn).ne' end DivInvMonoid
gfunctor.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat fintype. From mathcomp Require Import bigop finset fingroup morphism automorphism. From mathcomp Require Import quotient gproduct. (******************************************************************************) (* This file provides basic interfaces for the notion of "generic" *) (* characteristic subgroups; these amount to subfunctors of the identity *) (* functor in some category of groups. *) (* See "Generic Proof Tools And Finite Group Theory", *) (* Francois Garillot, PhD, 2011, Chapter 3. *) (* The implementation proposed here is fairly basic, relying on first order *) (* function matching and on structure telescopes, both of which are somewhat *) (* limited and fragile. It should switch in the future to more general and *) (* more robust quotation matching. *) (* The definitions in this file (types, properties and structures) are all *) (* packaged under the GFunctor submodule, i.e., client code should refer to *) (* GFunctor.continuous, GFunctor.map, etc. Notations, Coercions and Lemmas *) (* are exported and thus directly available, however. *) (* We provide the following: *) (* object_map == the type of the (polymorphic) object map of a group *) (* functor; the %gF scope is bound to object_map. *) (* := forall gT : finGroupType, {set gT} -> {set gT}. *) (* We define two operations on object_map (with notations in the %gF scope): *) (* F1 \o F2 == the composite map; (F1 \o F2) G expands to F1 (F2 G). *) (* F1 %% F2 == F1 computed modulo F2; we have *) (* (F1 %% F2) G / F2 G = F1 (G / F2 G) *) (* We define the following (type-polymorphic) properties of an object_map F: *) (* group_valued F <-> F G is a group when G is a group *) (* closed F <-> F G is a subgroup o fG when G is a group *) (* continuous F <-> F is continuous with respect to morphism image: *) (* for any f : {morphism G >-> ..}, f @* (F G) is a *) (* a subgroup of F (f @* G); equivalently, F is *) (* functorial in the category Grp of groups. *) (* Most common "characteristic subgroup" are produced *) (* continuous object maps. *) (* iso_continuous F <-> F is continuous with respect to isomorphism image; *) (* equivalently, F is functorial in the Grp groupoid. *) (* The Puig and the Thompson J subgroups are examples *) (* of iso_continuous maps that are not continuous. *) (* pcontinuous F <-> F is continuous with respect to partial morphism *) (* image, i.e., functorial in the category of groups *) (* and partial morphisms. The center and p-core are *) (* examples of pcontinuous maps. *) (* hereditary F <-> inclusion in the image of F is hereditary, i.e., *) (* for any subgroup H of G, the intersection of H with *) (* F G is included in H. Note that F is pcontinuous *) (* iff it is continuous and hereditary; indeed proofs *) (* of pcontinuous F coerce to proofs of hereditary F *) (* and continuous F. *) (* monotonic F <-> F is monotonic with respect to inclusion: for any *) (* subgroup H of G, F H is a subgroup of F G. The *) (* derived and lower central series are examples of *) (* monotonic maps. *) (* Four structures provide interfaces to these properties: *) (* GFunctor.iso_map == structure for object maps that are group_valued, *) (* closed, and iso_continuous. *) (* [igFun by Fsub & !Fcont] == the iso_map structure for an object map F *) (* such that F G is canonically a group when G is, and *) (* given Fsub : closed F and Fcont : iso_continuous F. *) (* [igFun by Fsub & Fcont] == as above, but expecting Fcont : continuous F. *) (* [igFun of F] == clone an existing GFunctor.iso_map structure for F. *) (* GFunctor.map == structure for continuous object maps, inheriting *) (* from the GFunctor.iso_map structure. *) (* [gFun by Fcont] == the map structure for an F with a canonical iso_map *) (* structure, given Fcont : continuous F. *) (* [gFun of F] == clone an existing GFunctor.map structure for F. *) (* GFunctor.pmap == structure for pcontinuous object maps, inheriting *) (* from the GFunctor.map structure. *) (* [pgFun by Fher] == the pmap structure for an F with a canonical map *) (* structure, given Fher : hereditary F. *) (* [pgFun of F] == clone an existing GFunctor.pmap structure for F. *) (* GFunctor.mono_map == structure for monotonic, continuous object maps *) (* inheriting from the GFunctor.map structure. *) (* [mgFun by Fmon] == the mono_map structure for an F with a canonical *) (* map structure, given Fmon : monotonic F. *) (* [mgFun of F] == clone an existing GFunctor.mono_map structure for F *) (* Lemmas for these group functors use either a 'gF' prefix or an 'F' suffix. *) (* The (F1 \o F2) and (F1 %% F2) operations have canonical GFunctor.map *) (* structures when F1 is monotonic or hereditary, respectively. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope gFun_scope. Import GroupScope. Delimit Scope gFun_scope with gF. Module GFunctor. Definition object_map := forall gT : finGroupType, {set gT} -> {set gT}. Bind Scope gFun_scope with object_map. Section Definitions. Implicit Types gT hT : finGroupType. Variable F : object_map. (* Group closure. *) Definition group_valued := forall gT (G : {group gT}), group_set (F G). (* Subgroup closure. *) Definition closed := forall gT (G : {group gT}), F G \subset G. (* General functoriality, i.e., continuity of the object map *) Definition continuous := forall gT hT (G : {group gT}) (phi : {morphism G >-> hT}), phi @* F G \subset F (phi @* G). (* Functoriality on the Grp groupoid (arrows are restricted to isos). *) Definition iso_continuous := forall gT hT (G : {group gT}) (phi : {morphism G >-> hT}), 'injm phi -> phi @* F G \subset F (phi @* G). Lemma continuous_is_iso_continuous : continuous -> iso_continuous. Proof. by move=> Fcont gT hT G phi inj_phi; apply: Fcont. Qed. (* Functoriality on Grp with partial morphisms. *) Definition pcontinuous := forall gT hT (G D : {group gT}) (phi : {morphism D >-> hT}), phi @* F G \subset F (phi @* G). Lemma pcontinuous_is_continuous : pcontinuous -> continuous. Proof. by move=> Fcont gT hT G; apply: Fcont. Qed. (* Heredity with respect to inclusion *) Definition hereditary := forall gT (H G : {group gT}), H \subset G -> F G :&: H \subset F H. Lemma pcontinuous_is_hereditary : pcontinuous -> hereditary. Proof. move=> Fcont gT H G sHG; rewrite -{2}(setIidPl sHG) setIC. by do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom ?Fcont. Qed. (* Monotonicity with respect to inclusion *) Definition monotonic := forall gT (H G : {group gT}), H \subset G -> F H \subset F G. (* Self-expanding composition, and modulo *) Variables (F1 F2 : object_map). Definition comp : object_map := fun gT A => F1 (F2 A). Definition modulo : object_map := fun gT A => coset (F2 A) @*^-1 (F1 (A / (F2 A))). End Definitions. Section ClassDefinitions. Structure iso_map := IsoMap { apply : object_map; _ : group_valued apply; _ : closed apply; _ : iso_continuous apply }. Local Coercion apply : iso_map >-> object_map. Structure map := Map { iso_of_map : iso_map; _ : continuous iso_of_map }. Local Coercion iso_of_map : map >-> iso_map. Structure pmap := Pmap { map_of_pmap : map; _ : hereditary map_of_pmap }. Local Coercion map_of_pmap : pmap >-> map. Structure mono_map := MonoMap { map_of_mono : map; _ : monotonic map_of_mono }. Local Coercion map_of_mono : mono_map >-> map. Definition pack_iso F Fcont Fgrp Fsub := @IsoMap F Fgrp Fsub Fcont. Definition clone_iso (F : object_map) := fun Fgrp Fsub Fcont (isoF := @IsoMap F Fgrp Fsub Fcont) => fun isoF0 & phant_id (apply isoF0) F & phant_id isoF isoF0 => isoF. Definition clone (F : object_map) := fun isoF & phant_id (apply isoF) F => fun (funF0 : map) & phant_id (apply funF0) F => fun Fcont (funF := @Map isoF Fcont) & phant_id funF0 funF => funF. Definition clone_pmap (F : object_map) := fun (funF : map) & phant_id (apply funF) F => fun (pfunF0 : pmap) & phant_id (apply pfunF0) F => fun Fher (pfunF := @Pmap funF Fher) & phant_id pfunF0 pfunF => pfunF. Definition clone_mono (F : object_map) := fun (funF : map) & phant_id (apply funF) F => fun (mfunF0 : mono_map) & phant_id (apply mfunF0) F => fun Fmon (mfunF := @MonoMap funF Fmon) & phant_id mfunF0 mfunF => mfunF. End ClassDefinitions. Module Exports. Identity Coercion fun_of_object_map : object_map >-> Funclass. Coercion apply : iso_map >-> object_map. Coercion iso_of_map : map >-> iso_map. Coercion map_of_pmap : pmap >-> map. Coercion map_of_mono : mono_map >-> map. Coercion continuous_is_iso_continuous : continuous >-> iso_continuous. Coercion pcontinuous_is_continuous : pcontinuous >-> continuous. Coercion pcontinuous_is_hereditary : pcontinuous >-> hereditary. Notation "[ 'igFun' 'by' Fsub & Fcont ]" := (pack_iso (continuous_is_iso_continuous Fcont) (fun gT G => groupP _) Fsub) (format "[ 'igFun' 'by' Fsub & Fcont ]") : form_scope. Notation "[ 'igFun' 'by' Fsub & ! Fcont ]" := (pack_iso Fcont (fun gT G => groupP _) Fsub) (format "[ 'igFun' 'by' Fsub & ! Fcont ]") : form_scope. Notation "[ 'igFun' 'of' F ]" := (@clone_iso F _ _ _ _ id id) (format "[ 'igFun' 'of' F ]") : form_scope. Notation "[ 'gFun' 'by' Fcont ]" := (Map Fcont) (format "[ 'gFun' 'by' Fcont ]") : form_scope. Notation "[ 'gFun' 'of' F ]" := (@clone F _ id _ id _ id) (format "[ 'gFun' 'of' F ]") : form_scope. Notation "[ 'pgFun' 'by' Fher ]" := (Pmap Fher) (format "[ 'pgFun' 'by' Fher ]") : form_scope. Notation "[ 'pgFun' 'of' F ]" := (@clone_pmap F _ id _ id _ id) (format "[ 'pgFun' 'of' F ]") : form_scope. Notation "[ 'mgFun' 'by' Fmon ]" := (MonoMap Fmon) (format "[ 'mgFun' 'by' Fmon ]") : form_scope. Notation "[ 'mgFun' 'of' F ]" := (@clone_mono F _ id _ id _ id) (format "[ 'mgFun' 'of' F ]") : form_scope. End Exports. End GFunctor. Export GFunctor.Exports. Bind Scope gFun_scope with GFunctor.object_map. Arguments GFunctor.comp F1 F2 _ /. Notation "F1 \o F2" := (GFunctor.comp F1 F2) : gFun_scope. Notation "F1 %% F2" := (GFunctor.modulo F1 F2) : gFun_scope. Section FunctorGroup. Variables (F : GFunctor.iso_map) (gT : finGroupType) (G : {group gT}). Lemma gFgroupset : group_set (F gT G). Proof. by case: F. Qed. Canonical gFgroup := Group gFgroupset. End FunctorGroup. Canonical gFmod_group (F1 : GFunctor.iso_map) (F2 : GFunctor.object_map) (gT : finGroupType) (G : {group gT}) := [group of (F1 %% F2)%gF gT G]. Section IsoFunctorTheory. Implicit Types gT rT : finGroupType. Variable F : GFunctor.iso_map. Lemma gFsub gT (G : {group gT}) : F gT G \subset G. Proof. by case: F gT G. Qed. Lemma gFsub_trans gT (G : {group gT}) (A : {pred gT}) : G \subset A -> F gT G \subset A. Proof. exact/subset_trans/gFsub. Qed. Lemma gF1 gT : F gT 1 = 1. Proof. exact/trivgP/gFsub. Qed. Lemma gFiso_cont : GFunctor.iso_continuous F. Proof. by case F. Qed. Lemma gFchar gT (G : {group gT}) : F gT G \char G. Proof. apply/andP; split => //; first by apply: gFsub. apply/forall_inP=> f Af; rewrite -{2}(im_autm Af) -(autmE Af). by rewrite -morphimEsub ?gFsub ?gFiso_cont ?injm_autm. Qed. Lemma gFnorm gT (G : {group gT}) : G \subset 'N(F gT G). Proof. exact/char_norm/gFchar. Qed. Lemma gFnorms gT (G : {group gT}) : 'N(G) \subset 'N(F gT G). Proof. exact/char_norms/gFchar. Qed. Lemma gFnormal gT (G : {group gT}) : F gT G <| G. Proof. exact/char_normal/gFchar. Qed. Lemma gFchar_trans gT (G H : {group gT}) : H \char G -> F gT H \char G. Proof. exact/char_trans/gFchar. Qed. Lemma gFnormal_trans gT (G H : {group gT}) : H <| G -> F gT H <| G. Proof. exact/char_normal_trans/gFchar. Qed. Lemma gFnorm_trans gT (A : {pred gT}) (G : {group gT}) : A \subset 'N(G) -> A \subset 'N(F gT G). Proof. by move/subset_trans/(_ (gFnorms G)). Qed. Lemma injmF_sub gT rT (G D : {group gT}) (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> f @* (F gT G) \subset F rT (f @* G). Proof. move=> injf sGD; have:= gFiso_cont (injm_restrm sGD injf). by rewrite im_restrm morphim_restrm (setIidPr _) ?gFsub. Qed. Lemma injmF gT rT (G D : {group gT}) (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> f @* (F gT G) = F rT (f @* G). Proof. move=> injf sGD; have [sfGD injf'] := (morphimS f sGD, injm_invm injf). apply/esym/eqP; rewrite eqEsubset -(injmSK injf') ?gFsub_trans //. by rewrite !(subset_trans (injmF_sub _ _)) ?morphim_invm // gFsub_trans. Qed. Lemma gFisom gT rT (G D : {group gT}) R (f : {morphism D >-> rT}) : G \subset D -> isom G (gval R) f -> isom (F gT G) (F rT R) f. Proof. case/(restrmP f)=> g [gf _ _ _]; rewrite -{f}gf => /isomP[injg <-]. by rewrite sub_isom ?gFsub ?injmF. Qed. Lemma gFisog gT rT (G : {group gT}) (R : {group rT}) : G \isog R -> F gT G \isog F rT R. Proof. by case/isogP=> f injf <-; rewrite -injmF // sub_isog ?gFsub. Qed. End IsoFunctorTheory. Section FunctorTheory. Implicit Types gT rT : finGroupType. Variable F : GFunctor.map. Lemma gFcont : GFunctor.continuous F. Proof. by case F. Qed. Lemma morphimF gT rT (G D : {group gT}) (f : {morphism D >-> rT}) : G \subset D -> f @* (F gT G) \subset F rT (f @* G). Proof. move=> sGD; rewrite -(setIidPr (gFsub F G)). by rewrite -{3}(setIid G) -!(morphim_restrm sGD) gFcont. Qed. End FunctorTheory. Section PartialFunctorTheory. Implicit Types gT rT : finGroupType. Section BasicTheory. Variable F : GFunctor.pmap. Lemma gFhereditary : GFunctor.hereditary F. Proof. by case F. Qed. Lemma gFunctorI gT (G H : {group gT}) : F gT G :&: H = F gT G :&: F gT (G :&: H). Proof. rewrite -{1}(setIidPr (gFsub F G)) setIAC setIC. rewrite -(setIidPr (gFhereditary (subsetIl G H))). by rewrite setIC -setIA (setIidPr (gFsub F (G :&: H))). Qed. Lemma pmorphimF : GFunctor.pcontinuous F. Proof. move=> gT rT G D f; rewrite -morphimIdom -(setIidPl (gFsub F G)) setICA. apply: (subset_trans (morphimS f (gFhereditary (subsetIr D G)))). by rewrite (subset_trans (morphimF F _ _ )) ?morphimIdom ?subsetIl. Qed. Lemma gFid gT (G : {group gT}) : F gT (F gT G) = F gT G. Proof. apply/eqP; rewrite eqEsubset gFsub. by move/gFhereditary: (gFsub F G); rewrite setIid /=. Qed. End BasicTheory. Section Modulo. Variables (F1 : GFunctor.pmap) (F2 : GFunctor.map). Lemma gFmod_closed : GFunctor.closed (F1 %% F2). Proof. by move=> gT G; rewrite sub_cosetpre_quo ?gFsub ?gFnormal. Qed. Lemma gFmod_cont : GFunctor.continuous (F1 %% F2). Proof. move=> gT rT G f; have nF2 := gFnorm F2. have sDF: G \subset 'dom (coset (F2 _ G)) by rewrite nF2. have sDFf: G \subset 'dom (coset (F2 _ (f @* G)) \o f). by rewrite -sub_morphim_pre ?subsetIl // nF2. pose K := 'ker (restrm sDFf (coset (F2 _ (f @* G)) \o f)). have sFK: 'ker (restrm sDF (coset (F2 _ G))) \subset K. rewrite {}/K !ker_restrm ker_comp /= subsetI subsetIl !ker_coset /=. by rewrite -sub_morphim_pre ?subsetIl // morphimIdom ?morphimF. have sOF := gFsub F1 (G / F2 _ G); have sGG: G \subset G by []. rewrite -sub_quotient_pre; last first. by apply: subset_trans (nF2 _ _); rewrite morphimS ?gFmod_closed. suffices im_fact H : F2 _ G \subset gval H -> H \subset G -> factm sFK sGG @* (H / F2 _ G) = f @* H / F2 _ (f @* G). - rewrite -2?im_fact ?gFmod_closed ?gFsub //. by rewrite cosetpreK morphimF /= ?morphim_restrm ?setIid. by rewrite -sub_quotient_pre ?normG //= trivg_quotient sub1G. move=> sFH sHG; rewrite -(morphimIdom _ (H / _)) /= {2}morphim_restrm /= setIid. rewrite -morphimIG ?ker_coset // -(morphim_restrm sDF) morphim_factm. by rewrite morphim_restrm morphim_comp -quotientE morphimIdom. Qed. Canonical gFmod_igFun := [igFun by gFmod_closed & gFmod_cont]. Canonical gFmod_gFun := [gFun by gFmod_cont]. End Modulo. Variables F1 F2 : GFunctor.pmap. Lemma gFmod_hereditary : GFunctor.hereditary (F1 %% F2). Proof. move=> gT H G sHG; set FGH := _ :&: H; have nF2H := gFnorm F2 H. rewrite -sub_quotient_pre; last exact: subset_trans (subsetIr _ _) _. pose rH := restrm nF2H (coset (F2 _ H)); pose rHM := [morphism of rH]. have rnorm_simpl: rHM @* H = H / F2 _ H by rewrite morphim_restrm setIid. have nF2G := subset_trans sHG (gFnorm F2 G). pose rG := restrm nF2G (coset (F2 _ G)); pose rGM := [morphism of rG]. have sqKfK: 'ker rGM \subset 'ker rHM. rewrite !ker_restrm !ker_coset (setIidPr (gFsub F2 _)) setIC /=. exact: gFhereditary. have sHH := subxx H; rewrite -rnorm_simpl /= -(morphim_factm sqKfK sHH) /=. apply: subset_trans (gFcont F1 _); rewrite /= {2}morphim_restrm setIid /=. apply: subset_trans (morphimS _ (gFhereditary _ (quotientS _ sHG))) => /=. have ->: FGH / _ = restrm nF2H (coset _) @* FGH. by rewrite morphim_restrm setICA setIid. rewrite -(morphim_factm sqKfK sHH) morphimS //= morphim_restrm -quotientE. by rewrite setICA setIid (subset_trans (quotientI _ _ _)) // cosetpreK. Qed. Canonical gFmod_pgFun := [pgFun by gFmod_hereditary]. End PartialFunctorTheory. Section MonotonicFunctorTheory. Implicit Types gT rT : finGroupType. Lemma gFunctorS (F : GFunctor.mono_map) : GFunctor.monotonic F. Proof. by case: F. Qed. Section Composition. Variables (F1 : GFunctor.mono_map) (F2 : GFunctor.map). Lemma gFcomp_closed : GFunctor.closed (F1 \o F2). Proof. by move=> gT G; rewrite !gFsub_trans. Qed. Lemma gFcomp_cont : GFunctor.continuous (F1 \o F2). Proof. move=> gT rT G phi; rewrite (subset_trans (morphimF _ _ (gFsub _ _))) //. by rewrite (subset_trans (gFunctorS F1 (gFcont F2 phi))). Qed. Canonical gFcomp_igFun := [igFun by gFcomp_closed & gFcomp_cont]. Canonical gFcomp_gFun :=[gFun by gFcomp_cont]. End Composition. Variables F1 F2 : GFunctor.mono_map. Lemma gFcompS : GFunctor.monotonic (F1 \o F2). Proof. by move=> gT H G sHG; rewrite !gFunctorS. Qed. Canonical gFcomp_mgFun := [mgFun by gFcompS]. End MonotonicFunctorTheory. Section GFunctorExamples. Implicit Types gT : finGroupType. Definition idGfun gT := @id {set gT}. Lemma idGfun_closed : GFunctor.closed idGfun. Proof. by []. Qed. Lemma idGfun_cont : GFunctor.continuous idGfun. Proof. by []. Qed. Lemma idGfun_monotonic : GFunctor.monotonic idGfun. Proof. by []. Qed. Canonical bgFunc_id := [igFun by idGfun_closed & idGfun_cont]. Canonical gFunc_id := [gFun by idGfun_cont]. Canonical mgFunc_id := [mgFun by idGfun_monotonic]. Definition trivGfun gT of {set gT} := [1 gT]. Lemma trivGfun_cont : GFunctor.pcontinuous trivGfun. Proof. by move=> gT rT D G f; rewrite morphim1. Qed. Canonical trivGfun_igFun := [igFun by sub1G & trivGfun_cont]. Canonical trivGfun_gFun := [gFun by trivGfun_cont]. Canonical trivGfun_pgFun := [pgFun by trivGfun_cont]. End GFunctorExamples.
Defs.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro, Anne Baanen -/ import Mathlib.LinearAlgebra.Quotient.Defs import Mathlib.RingTheory.Congruence.Defs import Mathlib.RingTheory.Ideal.Defs /-! # Ideal quotients This file defines ideal quotients as a special case of submodule quotients and proves some basic results about these quotients. See `Algebra.RingQuot` for quotients of non-commutative rings. ## Main definitions - `Ideal.instHasQuotient`: the quotient of a commutative ring `R` by an ideal `I : Ideal R` - `Ideal.Quotient.commRing`: the ring structure of the ideal quotient - `Ideal.Quotient.mk`: map an element of `R` to the quotient `R ⧸ I` - `Ideal.Quotient.lift`: turn a map `R → S` into a map `R ⧸ I → S` - `Ideal.quotEquivOfEq`: quotienting by equal ideals gives isomorphic rings -/ universe u v w namespace Ideal open Set variable {R : Type u} [Ring R] (I J : Ideal R) {a b : R} variable {S : Type v} /-- The quotient `R/I` of a ring `R` by an ideal `I`, defined to equal the quotient of `I` as an `R`-submodule of `R`. -/ instance instHasQuotient : HasQuotient R (Ideal R) := Submodule.hasQuotient /-- Shortcut instance for commutative rings. -/ instance {R} [CommRing R] : HasQuotient R (Ideal R) := inferInstance namespace Quotient variable {I} {x y : R} instance one (I : Ideal R) : One (R ⧸ I) := ⟨Submodule.Quotient.mk 1⟩ /-- On `Ideal`s, `Submodule.quotientRel` is a ring congruence. -/ protected def ringCon (I : Ideal R) [I.IsTwoSided] : RingCon R where __ := QuotientAddGroup.con I.toAddSubgroup mul' {a₁ b₁ a₂ b₂} h₁ h₂ := by rw [Submodule.quotientRel_def] at h₁ h₂ ⊢ exact mul_sub_mul_mem I h₁ h₂ instance ring (I : Ideal R) [I.IsTwoSided] : Ring (R ⧸ I) := fast_instance% { __ : AddCommGroup (R ⧸ I) := inferInstance __ : Ring (Quotient.ringCon I).Quotient := inferInstance } instance commRing {R} [CommRing R] (I : Ideal R) : CommRing (R ⧸ I) := fast_instance% { mul_comm := by rintro ⟨a⟩ ⟨b⟩; exact congr_arg _ (mul_comm a b) } instance {R} [CommRing R] (I : Ideal R) : Ring (R ⧸ I) := fast_instance% inferInstance instance commSemiring {R} [CommRing R] (I : Ideal R) : CommSemiring (R ⧸ I) := fast_instance% inferInstance instance semiring {R} [CommRing R] (I : Ideal R) : Semiring (R ⧸ I) := fast_instance% inferInstance variable [I.IsTwoSided] -- Sanity test to make sure no diamonds have emerged in `commRing` example : (ring I).toAddCommGroup = Submodule.Quotient.addCommGroup I := rfl variable (I) in /-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/ def mk : R →+* R ⧸ I where toFun a := Submodule.Quotient.mk a map_zero' := rfl map_one' := rfl map_mul' _ _ := rfl map_add' _ _ := rfl instance : Coe R (R ⧸ I) := ⟨Ideal.Quotient.mk I⟩ /-- Two `RingHom`s from the quotient by an ideal are equal if their compositions with `Ideal.Quotient.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem ringHom_ext [NonAssocSemiring S] ⦃f g : R ⧸ I →+* S⦄ (h : f.comp (mk I) = g.comp (mk I)) : f = g := RingHom.ext fun x => Quotient.inductionOn' x <| (RingHom.congr_fun h :) instance : Nonempty (R ⧸ I) := ⟨mk I 37⟩ protected theorem eq : mk I x = mk I y ↔ x - y ∈ I := Submodule.Quotient.eq I @[simp] theorem mk_eq_mk (x : R) : (Submodule.Quotient.mk x : R ⧸ I) = mk I x := rfl theorem eq_zero_iff_mem : mk I a = 0 ↔ a ∈ I := Submodule.Quotient.mk_eq_zero _ theorem mk_eq_mk_iff_sub_mem (x y : R) : mk I x = mk I y ↔ x - y ∈ I := by rw [← eq_zero_iff_mem, map_sub, sub_eq_zero] @[simp] theorem mk_out (x : R ⧸ I) : Ideal.Quotient.mk I (Quotient.out x) = x := Quotient.out_eq x theorem mk_surjective : Function.Surjective (mk I) := fun y => Quotient.inductionOn' y fun x => Exists.intro x rfl instance : RingHomSurjective (mk I) := ⟨mk_surjective⟩ /-- If `I` is an ideal of a commutative ring `R`, if `q : R → R/I` is the quotient map, and if `s ⊆ R` is a subset, then `q⁻¹(q(s)) = ⋃ᵢ(i + s)`, the union running over all `i ∈ I`. -/ theorem quotient_ring_saturate (s : Set R) : mk I ⁻¹' (mk I '' s) = ⋃ x : I, (fun y => x.1 + y) '' s := by ext x simp only [mem_preimage, mem_image, mem_iUnion, Ideal.Quotient.eq] exact ⟨fun ⟨a, a_in, h⟩ => ⟨⟨_, I.neg_mem h⟩, a, a_in, by simp⟩, fun ⟨⟨i, hi⟩, a, ha, Eq⟩ => ⟨a, ha, by rw [← Eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub]; exact I.neg_mem hi⟩⟩ variable [Semiring S] (I) /-- Given a ring homomorphism `f : R →+* S` sending all elements of an ideal to zero, lift it to the quotient by this ideal. -/ def lift (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : R ⧸ I →+* S := { QuotientAddGroup.lift I.toAddSubgroup f.toAddMonoidHom H with map_one' := f.map_one map_mul' := fun a₁ a₂ => Quotient.inductionOn₂' a₁ a₂ f.map_mul } @[simp] theorem lift_mk (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : lift I f H (mk I a) = f a := rfl lemma lift_comp_mk (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : (lift I f H).comp (mk I) = f := rfl theorem lift_surjective_of_surjective {f : R →+* S} (H : ∀ a : R, a ∈ I → f a = 0) (hf : Function.Surjective f) : Function.Surjective (Ideal.Quotient.lift I f H) := by intro y obtain ⟨x, rfl⟩ := hf y use Ideal.Quotient.mk I x simp only [Ideal.Quotient.lift_mk] variable {S T U : Ideal R} [S.IsTwoSided] [T.IsTwoSided] [U.IsTwoSided] /-- The ring homomorphism from the quotient by a smaller ideal to the quotient by a larger ideal. This is the `Ideal.Quotient` version of `Quot.Factor` When the two ideals are of the form `I^m` and `I^n` and `n ≤ m`, please refer to the dedicated version `Ideal.Quotient.factorPow`. -/ def factor (H : S ≤ T) : R ⧸ S →+* R ⧸ T := Ideal.Quotient.lift S (mk T) fun _ hx => eq_zero_iff_mem.2 (H hx) @[simp] theorem factor_mk (H : S ≤ T) (x : R) : factor H (mk S x) = mk T x := rfl @[simp] theorem factor_eq : factor (le_refl S) = RingHom.id _ := by ext simp @[simp] theorem factor_comp_mk (H : S ≤ T) : (factor H).comp (mk S) = mk T := by ext x rw [RingHom.comp_apply, factor_mk] @[simp] theorem factor_comp (H1 : S ≤ T) (H2 : T ≤ U) : (factor H2).comp (factor H1) = factor (H1.trans H2) := by ext simp @[simp] theorem factor_comp_apply (H1 : S ≤ T) (H2 : T ≤ U) (x : R ⧸ S) : factor H2 (factor H1 x) = factor (H1.trans H2) x := by rw [← RingHom.comp_apply] simp lemma factor_surjective (H : S ≤ T) : Function.Surjective (factor H) := Ideal.Quotient.lift_surjective_of_surjective _ _ Ideal.Quotient.mk_surjective end Quotient variable {I J} [I.IsTwoSided] [J.IsTwoSided] /-- Quotienting by equal ideals gives equivalent rings. See also `Submodule.quotEquivOfEq` and `Ideal.quotientEquivAlgOfEq`. -/ def quotEquivOfEq (h : I = J) : R ⧸ I ≃+* R ⧸ J := { Submodule.quotEquivOfEq I J h with map_mul' := by rintro ⟨x⟩ ⟨y⟩ rfl } @[simp] theorem quotEquivOfEq_mk (h : I = J) (x : R) : quotEquivOfEq h (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J x := rfl @[simp] theorem quotEquivOfEq_symm (h : I = J) : (Ideal.quotEquivOfEq h).symm = Ideal.quotEquivOfEq h.symm := by ext; rfl end Ideal
SurjectiveOnStalks.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Morphisms.RingHomProperties import Mathlib.RingTheory.RingHom.Surjective import Mathlib.RingTheory.Spectrum.Prime.TensorProduct import Mathlib.Topology.LocalAtTarget /-! # Morphisms surjective on stalks We define the class of morphisms between schemes that are surjective on stalks. We show that this class is stable under composition and base change. We also show that (`AlgebraicGeometry.SurjectiveOnStalks.isEmbedding_pullback`) if `Y ⟶ S` is surjective on stalks, then for every `X ⟶ S`, `X ×ₛ Y` is a subset of `X × Y` (cartesian product as topological spaces) with the induced topology. -/ open CategoryTheory CategoryTheory.Limits Topology namespace AlgebraicGeometry universe u variable {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) /-- The class of morphisms `f : X ⟶ Y` between schemes such that `𝒪_{Y, f x} ⟶ 𝒪_{X, x}` is surjective for all `x : X`. -/ @[mk_iff] class SurjectiveOnStalks : Prop where surj_on_stalks : ∀ x, Function.Surjective (f.stalkMap x) theorem Scheme.Hom.stalkMap_surjective (f : X.Hom Y) [SurjectiveOnStalks f] (x) : Function.Surjective (f.stalkMap x) := SurjectiveOnStalks.surj_on_stalks x namespace SurjectiveOnStalks instance (priority := 900) [IsOpenImmersion f] : SurjectiveOnStalks f := ⟨fun _ ↦ (ConcreteCategory.bijective_of_isIso _).2⟩ instance : MorphismProperty.IsMultiplicative @SurjectiveOnStalks where id_mem _ := inferInstance comp_mem {X Y Z} f g hf hg := by refine ⟨fun x ↦ ?_⟩ rw [Scheme.stalkMap_comp] exact (hf.surj_on_stalks x).comp (hg.surj_on_stalks (f.base x)) instance comp {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [SurjectiveOnStalks f] [SurjectiveOnStalks g] : SurjectiveOnStalks (f ≫ g) := MorphismProperty.IsStableUnderComposition.comp_mem f g inferInstance inferInstance lemma eq_stalkwise : @SurjectiveOnStalks = stalkwise (Function.Surjective ·) := by ext; exact surjectiveOnStalks_iff _ instance : IsLocalAtTarget @SurjectiveOnStalks := eq_stalkwise ▸ stalkwiseIsLocalAtTarget_of_respectsIso RingHom.surjective_respectsIso instance : IsLocalAtSource @SurjectiveOnStalks := eq_stalkwise ▸ stalkwise_isLocalAtSource_of_respectsIso RingHom.surjective_respectsIso lemma Spec_iff {R S : CommRingCat.{u}} {φ : R ⟶ S} : SurjectiveOnStalks (Spec.map φ) ↔ RingHom.SurjectiveOnStalks φ.hom := by rw [eq_stalkwise, stalkwise_Spec_map_iff RingHom.surjective_respectsIso, RingHom.SurjectiveOnStalks] instance : HasRingHomProperty @SurjectiveOnStalks RingHom.SurjectiveOnStalks := eq_stalkwise ▸ .stalkwise RingHom.surjective_respectsIso variable {f} in lemma iff_of_isAffine [IsAffine X] [IsAffine Y] : SurjectiveOnStalks f ↔ RingHom.SurjectiveOnStalks (f.app ⊤).hom := by rw [← Spec_iff, MorphismProperty.arrow_mk_iso_iff @SurjectiveOnStalks (arrowIsoSpecΓOfIsAffine f)] theorem of_comp [SurjectiveOnStalks (f ≫ g)] : SurjectiveOnStalks f := by refine ⟨fun x ↦ ?_⟩ have := (f ≫ g).stalkMap_surjective x rw [Scheme.stalkMap_comp] at this exact Function.Surjective.of_comp this instance stableUnderBaseChange : MorphismProperty.IsStableUnderBaseChange @SurjectiveOnStalks := by apply HasRingHomProperty.isStableUnderBaseChange apply RingHom.IsStableUnderBaseChange.mk · exact (HasRingHomProperty.isLocal_ringHomProperty @SurjectiveOnStalks).respectsIso intros R S T _ _ _ _ _ H exact H.baseChange variable {f} in lemma mono_of_injective [SurjectiveOnStalks f] (hf : Function.Injective f.base) : Mono f := by refine (Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace).mono_of_mono_map ?_ apply SheafedSpace.mono_of_base_injective_of_stalk_epi · exact hf · exact fun x ↦ ConcreteCategory.epi_of_surjective _ (f.stalkMap_surjective x) /-- If `Y ⟶ S` is surjective on stalks, then for every `X ⟶ S`, `X ×ₛ Y` is a subset of `X × Y` (cartesian product as topological spaces) with the induced topology. -/ lemma isEmbedding_pullback {X Y S : Scheme.{u}} (f : X ⟶ S) (g : Y ⟶ S) [SurjectiveOnStalks g] : IsEmbedding (fun x ↦ ((pullback.fst f g).base x, (pullback.snd f g).base x)) := by let L := (fun x ↦ ((pullback.fst f g).base x, (pullback.snd f g).base x)) have H : ∀ R A B (f' : Spec A ⟶ Spec R) (g' : Spec B ⟶ Spec R) (iX : Spec A ⟶ X) (iY : Spec B ⟶ Y) (iS : Spec R ⟶ S) (e₁ e₂), IsOpenImmersion iX → IsOpenImmersion iY → IsOpenImmersion iS → IsEmbedding (L ∘ (pullback.map f' g' f g iX iY iS e₁ e₂).base) := by intro R A B f' g' iX iY iS e₁ e₂ _ _ _ have H : SurjectiveOnStalks g' := have : SurjectiveOnStalks (g' ≫ iS) := e₂ ▸ inferInstance .of_comp _ iS obtain ⟨φ, rfl⟩ : ∃ φ, Spec.map φ = f' := ⟨_, Spec.map_preimage _⟩ obtain ⟨ψ, rfl⟩ : ∃ ψ, Spec.map ψ = g' := ⟨_, Spec.map_preimage _⟩ algebraize [φ.hom, ψ.hom] rw [HasRingHomProperty.Spec_iff (P := @SurjectiveOnStalks)] at H convert ((iX.isOpenEmbedding.prodMap iY.isOpenEmbedding).isEmbedding.comp (PrimeSpectrum.isEmbedding_tensorProductTo_of_surjectiveOnStalks R A B H)).comp (Scheme.homeoOfIso (pullbackSpecIso R A B)).isEmbedding ext1 x obtain ⟨x, rfl⟩ := (Scheme.homeoOfIso (pullbackSpecIso R A B).symm).surjective x simp only [Scheme.homeoOfIso_apply, Function.comp_apply] ext · simp only [L, ← Scheme.comp_base_apply, pullback.lift_fst, Iso.symm_hom, Iso.inv_hom_id] erw [← Scheme.comp_base_apply, pullbackSpecIso_inv_fst_assoc] rfl · simp only [L, ← Scheme.comp_base_apply, pullback.lift_snd, Iso.symm_hom, Iso.inv_hom_id] erw [← Scheme.comp_base_apply, pullbackSpecIso_inv_snd_assoc] rfl let 𝒰 := S.affineOpenCover.openCover let 𝒱 (i) := ((𝒰.pullbackCover f).obj i).affineOpenCover.openCover let 𝒲 (i) := ((𝒰.pullbackCover g).obj i).affineOpenCover.openCover let U (ijk : Σ i, (𝒱 i).J × (𝒲 i).J) : TopologicalSpace.Opens (X.carrier × Y) := ⟨{ P | P.1 ∈ ((𝒱 ijk.1).map ijk.2.1 ≫ (𝒰.pullbackCover f).map ijk.1).opensRange ∧ P.2 ∈ ((𝒲 ijk.1).map ijk.2.2 ≫ (𝒰.pullbackCover g).map ijk.1).opensRange }, (continuous_fst.1 _ ((𝒱 ijk.1).map ijk.2.1 ≫ (𝒰.pullbackCover f).map ijk.1).opensRange.2).inter (continuous_snd.1 _ ((𝒲 ijk.1).map ijk.2.2 ≫ (𝒰.pullbackCover g).map ijk.1).opensRange.2)⟩ have : Set.range L ⊆ (iSup U :) := by simp only [Scheme.Cover.pullbackCover_J, Scheme.Cover.pullbackCover_obj, Set.range_subset_iff] intro z simp only [SetLike.mem_coe, TopologicalSpace.Opens.mem_iSup, Sigma.exists, Prod.exists] obtain ⟨is, s, hsx⟩ := 𝒰.exists_eq (f.base ((pullback.fst f g).base z)) have hsy : (𝒰.map is).base s = g.base ((pullback.snd f g).base z) := by rwa [← Scheme.comp_base_apply, ← pullback.condition, Scheme.comp_base_apply] obtain ⟨x : (𝒰.pullbackCover f).obj is, hx⟩ := Scheme.IsJointlySurjectivePreserving.exists_preimage_fst_triplet_of_prop (P := @IsOpenImmersion) inferInstance _ _ hsx.symm obtain ⟨y : (𝒰.pullbackCover g).obj is, hy⟩ := Scheme.IsJointlySurjectivePreserving.exists_preimage_fst_triplet_of_prop (P := @IsOpenImmersion) inferInstance _ _ hsy.symm obtain ⟨ix, x, rfl⟩ := (𝒱 is).exists_eq x obtain ⟨iy, y, rfl⟩ := (𝒲 is).exists_eq y refine ⟨is, ix, iy, ⟨x, hx⟩, ⟨y, hy⟩⟩ let 𝓤 := (Scheme.Pullback.openCoverOfBase 𝒰 f g).bind (fun i ↦ Scheme.Pullback.openCoverOfLeftRight (𝒱 i) (𝒲 i) _ _) refine isEmbedding_of_iSup_eq_top_of_preimage_subset_range _ ?_ U this _ (fun i ↦ (𝓤.map i).base) (fun i ↦ (𝓤.map i).continuous) ?_ ?_ · fun_prop · rintro i x ⟨⟨x₁, hx₁⟩, ⟨x₂, hx₂⟩⟩ obtain ⟨x₁', hx₁'⟩ := Scheme.IsJointlySurjectivePreserving.exists_preimage_fst_triplet_of_prop (P := @IsOpenImmersion) inferInstance _ _ hx₁.symm obtain ⟨x₂', hx₂'⟩ := Scheme.IsJointlySurjectivePreserving.exists_preimage_fst_triplet_of_prop (P := @IsOpenImmersion) inferInstance _ _ hx₂.symm obtain ⟨z, hz⟩ := Scheme.IsJointlySurjectivePreserving.exists_preimage_fst_triplet_of_prop (P := @IsOpenImmersion) inferInstance _ _ (hx₁'.trans hx₂'.symm) refine ⟨(pullbackFstFstIso _ _ _ _ _ _ (𝒰.map i.1) ?_ ?_).hom.base z, ?_⟩ · simp [pullback.condition] · simp [pullback.condition] · dsimp only rw [← hx₁', ← hz, ← Scheme.comp_base_apply] erw [← Scheme.comp_base_apply] congr 5 apply pullback.hom_ext <;> simp [𝓤, ← pullback.condition, ← pullback.condition_assoc] · intro i have := H (S.affineOpenCover.obj i.1) (((𝒰.pullbackCover f).obj i.1).affineOpenCover.obj i.2.1) (((𝒰.pullbackCover g).obj i.1).affineOpenCover.obj i.2.2) ((𝒱 i.1).map i.2.1 ≫ 𝒰.pullbackHom f i.1) ((𝒲 i.1).map i.2.2 ≫ 𝒰.pullbackHom g i.1) ((𝒱 i.1).map i.2.1 ≫ (𝒰.pullbackCover f).map i.1) ((𝒲 i.1).map i.2.2 ≫ (𝒰.pullbackCover g).map i.1) (𝒰.map i.1) (by simp [pullback.condition]) (by simp [pullback.condition]) inferInstance inferInstance inferInstance convert this using 7 apply pullback.hom_ext <;> simp [𝓤, Scheme.Cover.pullbackHom] end SurjectiveOnStalks end AlgebraicGeometry
EpiMono.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.LiftingProperties.Adjunction /-! # Preservation and reflection of monomorphisms and epimorphisms We provide typeclasses that state that a functor preserves or reflects monomorphisms or epimorphisms. -/ open CategoryTheory universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory.Functor variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {E : Type u₃} [Category.{v₃} E] /-- A functor preserves monomorphisms if it maps monomorphisms to monomorphisms. -/ class PreservesMonomorphisms (F : C ⥤ D) : Prop where /-- A functor preserves monomorphisms if it maps monomorphisms to monomorphisms. -/ preserves : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], Mono (F.map f) instance map_mono (F : C ⥤ D) [PreservesMonomorphisms F] {X Y : C} (f : X ⟶ Y) [Mono f] : Mono (F.map f) := PreservesMonomorphisms.preserves f /-- A functor preserves epimorphisms if it maps epimorphisms to epimorphisms. -/ class PreservesEpimorphisms (F : C ⥤ D) : Prop where /-- A functor preserves epimorphisms if it maps epimorphisms to epimorphisms. -/ preserves : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], Epi (F.map f) instance map_epi (F : C ⥤ D) [PreservesEpimorphisms F] {X Y : C} (f : X ⟶ Y) [Epi f] : Epi (F.map f) := PreservesEpimorphisms.preserves f /-- A functor reflects monomorphisms if morphisms that are mapped to monomorphisms are themselves monomorphisms. -/ class ReflectsMonomorphisms (F : C ⥤ D) : Prop where /-- A functor reflects monomorphisms if morphisms that are mapped to monomorphisms are themselves monomorphisms. -/ reflects : ∀ {X Y : C} (f : X ⟶ Y), Mono (F.map f) → Mono f theorem mono_of_mono_map (F : C ⥤ D) [ReflectsMonomorphisms F] {X Y : C} {f : X ⟶ Y} (h : Mono (F.map f)) : Mono f := ReflectsMonomorphisms.reflects f h /-- A functor reflects epimorphisms if morphisms that are mapped to epimorphisms are themselves epimorphisms. -/ class ReflectsEpimorphisms (F : C ⥤ D) : Prop where /-- A functor reflects epimorphisms if morphisms that are mapped to epimorphisms are themselves epimorphisms. -/ reflects : ∀ {X Y : C} (f : X ⟶ Y), Epi (F.map f) → Epi f theorem epi_of_epi_map (F : C ⥤ D) [ReflectsEpimorphisms F] {X Y : C} {f : X ⟶ Y} (h : Epi (F.map f)) : Epi f := ReflectsEpimorphisms.reflects f h instance preservesMonomorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [PreservesMonomorphisms F] [PreservesMonomorphisms G] : PreservesMonomorphisms (F ⋙ G) where preserves f h := by rw [comp_map] exact inferInstance instance preservesEpimorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [PreservesEpimorphisms F] [PreservesEpimorphisms G] : PreservesEpimorphisms (F ⋙ G) where preserves f h := by rw [comp_map] exact inferInstance instance reflectsMonomorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [ReflectsMonomorphisms F] [ReflectsMonomorphisms G] : ReflectsMonomorphisms (F ⋙ G) where reflects _ h := F.mono_of_mono_map (G.mono_of_mono_map h) instance reflectsEpimorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [ReflectsEpimorphisms F] [ReflectsEpimorphisms G] : ReflectsEpimorphisms (F ⋙ G) where reflects _ h := F.epi_of_epi_map (G.epi_of_epi_map h) theorem preservesEpimorphisms_of_preserves_of_reflects (F : C ⥤ D) (G : D ⥤ E) [PreservesEpimorphisms (F ⋙ G)] [ReflectsEpimorphisms G] : PreservesEpimorphisms F := ⟨fun f _ => G.epi_of_epi_map <| show Epi ((F ⋙ G).map f) from inferInstance⟩ theorem preservesMonomorphisms_of_preserves_of_reflects (F : C ⥤ D) (G : D ⥤ E) [PreservesMonomorphisms (F ⋙ G)] [ReflectsMonomorphisms G] : PreservesMonomorphisms F := ⟨fun f _ => G.mono_of_mono_map <| show Mono ((F ⋙ G).map f) from inferInstance⟩ theorem reflectsEpimorphisms_of_preserves_of_reflects (F : C ⥤ D) (G : D ⥤ E) [PreservesEpimorphisms G] [ReflectsEpimorphisms (F ⋙ G)] : ReflectsEpimorphisms F := ⟨fun f _ => (F ⋙ G).epi_of_epi_map <| show Epi (G.map (F.map f)) from inferInstance⟩ theorem reflectsMonomorphisms_of_preserves_of_reflects (F : C ⥤ D) (G : D ⥤ E) [PreservesMonomorphisms G] [ReflectsMonomorphisms (F ⋙ G)] : ReflectsMonomorphisms F := ⟨fun f _ => (F ⋙ G).mono_of_mono_map <| show Mono (G.map (F.map f)) from inferInstance⟩ theorem preservesMonomorphisms.of_iso {F G : C ⥤ D} [PreservesMonomorphisms F] (α : F ≅ G) : PreservesMonomorphisms G := { preserves := fun {X} {Y} f h => by suffices G.map f = (α.app X).inv ≫ F.map f ≫ (α.app Y).hom from this ▸ mono_comp _ _ rw [Iso.eq_inv_comp, Iso.app_hom, Iso.app_hom, NatTrans.naturality] } theorem preservesMonomorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) : PreservesMonomorphisms F ↔ PreservesMonomorphisms G := ⟨fun _ => preservesMonomorphisms.of_iso α, fun _ => preservesMonomorphisms.of_iso α.symm⟩ theorem preservesEpimorphisms.of_iso {F G : C ⥤ D} [PreservesEpimorphisms F] (α : F ≅ G) : PreservesEpimorphisms G := { preserves := fun {X} {Y} f h => by suffices G.map f = (α.app X).inv ≫ F.map f ≫ (α.app Y).hom from this ▸ epi_comp _ _ rw [Iso.eq_inv_comp, Iso.app_hom, Iso.app_hom, NatTrans.naturality] } theorem preservesEpimorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) : PreservesEpimorphisms F ↔ PreservesEpimorphisms G := ⟨fun _ => preservesEpimorphisms.of_iso α, fun _ => preservesEpimorphisms.of_iso α.symm⟩ theorem reflectsMonomorphisms.of_iso {F G : C ⥤ D} [ReflectsMonomorphisms F] (α : F ≅ G) : ReflectsMonomorphisms G := { reflects := fun {X} {Y} f h => by apply F.mono_of_mono_map suffices F.map f = (α.app X).hom ≫ G.map f ≫ (α.app Y).inv from this ▸ mono_comp _ _ rw [← Category.assoc, Iso.eq_comp_inv, Iso.app_hom, Iso.app_hom, NatTrans.naturality] } theorem reflectsMonomorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) : ReflectsMonomorphisms F ↔ ReflectsMonomorphisms G := ⟨fun _ => reflectsMonomorphisms.of_iso α, fun _ => reflectsMonomorphisms.of_iso α.symm⟩ theorem reflectsEpimorphisms.of_iso {F G : C ⥤ D} [ReflectsEpimorphisms F] (α : F ≅ G) : ReflectsEpimorphisms G := { reflects := fun {X} {Y} f h => by apply F.epi_of_epi_map suffices F.map f = (α.app X).hom ≫ G.map f ≫ (α.app Y).inv from this ▸ epi_comp _ _ rw [← Category.assoc, Iso.eq_comp_inv, Iso.app_hom, Iso.app_hom, NatTrans.naturality] } theorem reflectsEpimorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) : ReflectsEpimorphisms F ↔ ReflectsEpimorphisms G := ⟨fun _ => reflectsEpimorphisms.of_iso α, fun _ => reflectsEpimorphisms.of_iso α.symm⟩ theorem preservesEpimorphisms_of_adjunction {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) : PreservesEpimorphisms F := { preserves := fun {X} {Y} f hf => ⟨by intro Z g h H replace H := congr_arg (adj.homEquiv X Z) H rwa [adj.homEquiv_naturality_left, adj.homEquiv_naturality_left, cancel_epi, Equiv.apply_eq_iff_eq] at H⟩ } @[deprecated (since := "2025-07-27")] alias preservesEpimorphsisms_of_adjunction := preservesEpimorphisms_of_adjunction instance (priority := 100) preservesEpimorphisms_of_isLeftAdjoint (F : C ⥤ D) [IsLeftAdjoint F] : PreservesEpimorphisms F := preservesEpimorphisms_of_adjunction (Adjunction.ofIsLeftAdjoint F) theorem preservesMonomorphisms_of_adjunction {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) : PreservesMonomorphisms G := { preserves := fun {X} {Y} f hf => ⟨by intro Z g h H replace H := congr_arg (adj.homEquiv Z Y).symm H rwa [adj.homEquiv_naturality_right_symm, adj.homEquiv_naturality_right_symm, cancel_mono, Equiv.apply_eq_iff_eq] at H⟩ } instance (priority := 100) preservesMonomorphisms_of_isRightAdjoint (F : C ⥤ D) [IsRightAdjoint F] : PreservesMonomorphisms F := preservesMonomorphisms_of_adjunction (Adjunction.ofIsRightAdjoint F) instance (priority := 100) reflectsMonomorphisms_of_faithful (F : C ⥤ D) [Faithful F] : ReflectsMonomorphisms F where reflects {X} {Y} f _ := ⟨fun {Z} g h hgh => F.map_injective ((cancel_mono (F.map f)).1 (by rw [← F.map_comp, hgh, F.map_comp]))⟩ instance (priority := 100) reflectsEpimorphisms_of_faithful (F : C ⥤ D) [Faithful F] : ReflectsEpimorphisms F where reflects {X} {Y} f _ := ⟨fun {Z} g h hgh => F.map_injective ((cancel_epi (F.map f)).1 (by rw [← F.map_comp, hgh, F.map_comp]))⟩ section variable (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) /-- If `F` is a fully faithful functor, split epimorphisms are preserved and reflected by `F`. -/ noncomputable def splitEpiEquiv [Full F] [Faithful F] : SplitEpi f ≃ SplitEpi (F.map f) where toFun f := f.map F invFun s := ⟨F.preimage s.section_, by apply F.map_injective simp only [map_comp, map_preimage, map_id] apply SplitEpi.id⟩ left_inv := by cat_disch right_inv x := by cat_disch @[simp] theorem isSplitEpi_iff [Full F] [Faithful F] : IsSplitEpi (F.map f) ↔ IsSplitEpi f := by constructor · intro h exact IsSplitEpi.mk' ((splitEpiEquiv F f).invFun h.exists_splitEpi.some) · intro h exact IsSplitEpi.mk' ((splitEpiEquiv F f).toFun h.exists_splitEpi.some) /-- If `F` is a fully faithful functor, split monomorphisms are preserved and reflected by `F`. -/ noncomputable def splitMonoEquiv [Full F] [Faithful F] : SplitMono f ≃ SplitMono (F.map f) where toFun f := f.map F invFun s := ⟨F.preimage s.retraction, by apply F.map_injective simp only [map_comp, map_preimage, map_id] apply SplitMono.id⟩ left_inv := by cat_disch right_inv x := by cat_disch @[simp] theorem isSplitMono_iff [Full F] [Faithful F] : IsSplitMono (F.map f) ↔ IsSplitMono f := by constructor · intro h exact IsSplitMono.mk' ((splitMonoEquiv F f).invFun h.exists_splitMono.some) · intro h exact IsSplitMono.mk' ((splitMonoEquiv F f).toFun h.exists_splitMono.some) @[simp] theorem epi_map_iff_epi [hF₁ : PreservesEpimorphisms F] [hF₂ : ReflectsEpimorphisms F] : Epi (F.map f) ↔ Epi f := by constructor · exact F.epi_of_epi_map · intro h exact F.map_epi f @[simp] theorem mono_map_iff_mono [hF₁ : PreservesMonomorphisms F] [hF₂ : ReflectsMonomorphisms F] : Mono (F.map f) ↔ Mono f := by constructor · exact F.mono_of_mono_map · intro h exact F.map_mono f /-- If `F : C ⥤ D` is an equivalence of categories and `C` is a `split_epi_category`, then `D` also is. -/ theorem splitEpiCategoryImpOfIsEquivalence [IsEquivalence F] [SplitEpiCategory C] : SplitEpiCategory D := ⟨fun {X} {Y} f => by intro rw [← F.inv.isSplitEpi_iff f] apply isSplitEpi_of_epi⟩ end end CategoryTheory.Functor namespace CategoryTheory.Adjunction variable {C D : Type*} [Category C] [Category D] {F : C ⥤ D} {F' : D ⥤ C} {A B : C} theorem strongEpi_map_of_strongEpi (adj : F ⊣ F') (f : A ⟶ B) [F'.PreservesMonomorphisms] [F.PreservesEpimorphisms] [StrongEpi f] : StrongEpi (F.map f) := ⟨inferInstance, fun X Y Z => by intro rw [adj.hasLiftingProperty_iff] infer_instance⟩ instance strongEpi_map_of_isEquivalence [F.IsEquivalence] (f : A ⟶ B) [_h : StrongEpi f] : StrongEpi (F.map f) := F.asEquivalence.toAdjunction.strongEpi_map_of_strongEpi f instance (adj : F ⊣ F') {X : C} {Y : D} (f : F.obj X ⟶ Y) [hf : Mono f] [F.ReflectsMonomorphisms] : Mono (adj.homEquiv _ _ f) := F.mono_of_mono_map <| by rw [← (homEquiv adj X Y).symm_apply_apply f] at hf exact mono_of_mono_fac (adj.homEquiv_counit _ _ _).symm end CategoryTheory.Adjunction namespace CategoryTheory.Functor variable {C D : Type*} [Category C] [Category D] {F : C ⥤ D} {A B : C} (f : A ⟶ B) @[simp] theorem strongEpi_map_iff_strongEpi_of_isEquivalence [IsEquivalence F] : StrongEpi (F.map f) ↔ StrongEpi f := by constructor · intro have e : Arrow.mk f ≅ Arrow.mk (F.inv.map (F.map f)) := Arrow.isoOfNatIso F.asEquivalence.unitIso (Arrow.mk f) rw [StrongEpi.iff_of_arrow_iso e] infer_instance · intro infer_instance end CategoryTheory.Functor
countalg.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype bigop ssralg. (*****************************************************************************) (* The algebraic part of the algebraic hierarchy for countable types *) (* *) (* This file clones part of ssralg hierarchy for countable types; it does *) (* not cover the left module / algebra interfaces, providing only *) (* countNmodType == countable nmodType interface *) (* countZmodType == countable zmodType interface *) (* countPzSemiRingType == countable pzSemiRingType interface *) (* countNzSemiRingType == countable nzSemiRingType interface *) (* countPzRingType == countable pzRingType interface *) (* countNzRingType == countable nzRingType interface *) (* countComPzSemiRingType == countable comPzSemiRingType interface *) (* countComNzSemiRingType == countable comNzSemiRingType interface *) (* countComPzRingType == countable comPzRingType interface *) (* countComNzRingType == countable comNzRingType interface *) (* countUnitRingType == countable unitRingType interface *) (* countComUnitRingType == countable comUnitRingType interface *) (* countIdomainType == countable idomainType interface *) (* countFieldType == countable fieldType interface *) (* countDecFieldType == countable decFieldType interface *) (* countClosedFieldType == countable closedFieldType interface *) (* *) (* This file provides constructions for both simple extension and algebraic *) (* closure of countable fields. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory CodeSeq. Module CountRing. Import GRing.Theory. #[short(type="countNmodType")] HB.structure Definition Nmodule := {M of GRing.Nmodule M & Countable M}. #[short(type="countZmodType")] HB.structure Definition Zmodule := {M of GRing.Zmodule M & Countable M}. #[short(type="countPzSemiRingType")] HB.structure Definition PzSemiRing := {R of GRing.PzSemiRing R & Countable R}. #[short(type="countNzSemiRingType")] HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing instead.")] Notation SemiRing R := (NzSemiRing R) (only parsing). Module SemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.sort instead.")] Notation sort := (NzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.on instead.")] Notation on R := (NzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.copy instead.")] Notation copy T U := (NzSemiRing.copy T U) (only parsing). End SemiRing. #[short(type="countPzRingType")] HB.structure Definition PzRing := {R of GRing.PzRing R & Countable R}. #[short(type="countNzRingType")] HB.structure Definition NzRing := {R of GRing.NzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing instead.")] Notation Ring R := (NzRing R) (only parsing). Module Ring. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.sort instead.")] Notation sort := (NzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.on instead.")] Notation on R := (NzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.copy instead.")] Notation copy T U := (NzRing.copy T U) (only parsing). End Ring. #[short(type="countComPzSemiRingType")] HB.structure Definition ComPzSemiRing := {R of GRing.ComPzSemiRing R & Countable R}. #[short(type="countComNzSemiRingType")] HB.structure Definition ComNzSemiRing := {R of GRing.ComNzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing instead.")] Notation ComSemiRing R := (ComNzSemiRing R) (only parsing). Module ComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.sort instead.")] Notation sort := (ComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.on instead.")] Notation on R := (ComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.copy instead.")] Notation copy T U := (ComNzSemiRing.copy T U) (only parsing). End ComSemiRing. #[short(type="countComPzRingType")] HB.structure Definition ComPzRing := {R of GRing.ComPzRing R & Countable R}. #[short(type="countComNzRingType")] HB.structure Definition ComNzRing := {R of GRing.ComNzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing instead.")] Notation ComRing R := (ComNzRing R) (only parsing). Module ComRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.sort instead.")] Notation sort := (ComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.on instead.")] Notation on R := (ComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.copy instead.")] Notation copy T U := (ComNzRing.copy T U) (only parsing). End ComRing. #[short(type="countUnitRingType")] HB.structure Definition UnitRing := {R of GRing.UnitRing R & Countable R}. #[short(type="countComUnitRingType")] HB.structure Definition ComUnitRing := {R of GRing.ComUnitRing R & Countable R}. #[short(type="countIdomainType")] HB.structure Definition IntegralDomain := {R of GRing.IntegralDomain R & Countable R}. #[short(type="countFieldType")] HB.structure Definition Field := {R of GRing.Field R & Countable R}. #[short(type="countDecFieldType")] HB.structure Definition DecidableField := {R of GRing.DecidableField R & Countable R}. #[short(type="countClosedFieldType")] HB.structure Definition ClosedField := {R of GRing.ClosedField R & Countable R}. Module ReguralExports. HB.instance Definition _ (R : countType) := Countable.on R^o. HB.instance Definition _ (R : countNmodType) := Nmodule.on R^o. HB.instance Definition _ (R : countZmodType) := Zmodule.on R^o. HB.instance Definition _ (R : countPzSemiRingType) := PzSemiRing.on R^o. HB.instance Definition _ (R : countNzSemiRingType) := NzSemiRing.on R^o. HB.instance Definition _ (R : countPzRingType) := PzRing.on R^o. HB.instance Definition _ (R : countNzRingType) := NzRing.on R^o. HB.instance Definition _ (R : countComPzSemiRingType) := ComPzSemiRing.on R^o. HB.instance Definition _ (R : countComNzSemiRingType) := ComNzSemiRing.on R^o. HB.instance Definition _ (R : countComPzRingType) := ComPzRing.on R^o. HB.instance Definition _ (R : countComNzRingType) := ComNzRing.on R^o. HB.instance Definition _ (R : countUnitRingType) := UnitRing.on R^o. HB.instance Definition _ (R : countComUnitRingType) := ComUnitRing.on R^o. HB.instance Definition _ (R : countIdomainType) := IntegralDomain.on R^o. HB.instance Definition _ (R : countFieldType) := Field.on R^o. HB.instance Definition _ (R : countDecFieldType) := DecidableField.on R^o. HB.instance Definition _ (R : countClosedFieldType) := ClosedField.on R^o. End ReguralExports. HB.export ReguralExports. End CountRing. Import CountRing. HB.reexport. #[deprecated(since="mathcomp 2.4.0", note="Use countNzSemiRingType instead.")] Notation countSemiRingType := (countNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countNzRingType instead.")] Notation countRingType := (countNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzSemiRingType instead.")] Notation countComSemiRingType := (countComNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzRingType instead.")] Notation countComRingType := (countComNzRingType) (only parsing).
Defs.lean
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Order.Monoid.Unbundled.Basic import Mathlib.Order.Lattice /-! # Ordered Subtraction This file proves lemmas relating (truncated) subtraction with an order. We provide a class `OrderedSub` stating that `a - b ≤ c ↔ a ≤ c + b`. The subtraction discussed here could both be normal subtraction in an additive group or truncated subtraction on a canonically ordered monoid (`ℕ`, `Multiset`, `PartENat`, `ENNReal`, ...) ## Implementation details `OrderedSub` is a mixin type-class, so that we can use the results in this file even in cases where we don't have a `CanonicallyOrderedAdd` instance (even though that is our main focus). Conversely, this means we can use `CanonicallyOrderedAdd` without necessarily having to define a subtraction. The results in this file are ordered by the type-class assumption needed to prove it. This means that similar results might not be close to each other. Furthermore, we don't prove implications if a bi-implication can be proven under the same assumptions. Lemmas using this class are named using `tsub` instead of `sub` (short for "truncated subtraction"). This is to avoid naming conflicts with similar lemmas about ordered groups. We provide a second version of most results that require `[AddLeftReflectLE α]`. In the second version we replace this type-class assumption by explicit `AddLECancellable` assumptions. TODO: maybe we should make a multiplicative version of this, so that we can replace some identical lemmas about subtraction/division in `Ordered[Add]CommGroup` with these. TODO: generalize `Nat.le_of_le_of_sub_le_sub_right`, `Nat.sub_le_sub_right_iff`, `Nat.mul_self_sub_mul_self_eq` -/ variable {α : Type*} /-- `OrderedSub α` means that `α` has a subtraction characterized by `a - b ≤ c ↔ a ≤ c + b`. In other words, `a - b` is the least `c` such that `a ≤ b + c`. This is satisfied both by the subtraction in additive ordered groups and by truncated subtraction in canonically ordered monoids on many specific types. -/ class OrderedSub (α : Type*) [LE α] [Add α] [Sub α] : Prop where /-- `a - b` provides a lower bound on `c` such that `a ≤ c + b`. -/ tsub_le_iff_right : ∀ a b c : α, a - b ≤ c ↔ a ≤ c + b section Add @[simp] theorem tsub_le_iff_right [LE α] [Add α] [Sub α] [OrderedSub α] {a b c : α} : a - b ≤ c ↔ a ≤ c + b := OrderedSub.tsub_le_iff_right a b c variable [Preorder α] [Add α] [Sub α] [OrderedSub α] {a b : α} /-- See `add_tsub_cancel_right` for the equality if `AddLeftReflectLE α`. -/ theorem add_tsub_le_right : a + b - b ≤ a := tsub_le_iff_right.mpr le_rfl theorem le_tsub_add : b ≤ b - a + a := tsub_le_iff_right.mp le_rfl end Add /-! ### Preorder -/ section OrderedAddCommSemigroup section Preorder variable [Preorder α] section AddCommSemigroup variable [AddCommSemigroup α] [Sub α] [OrderedSub α] {a b c d : α} /- TODO: Most results can be generalized to [Add α] [@Std.Commutative α (· + ·)] -/ theorem tsub_le_iff_left : a - b ≤ c ↔ a ≤ b + c := by rw [tsub_le_iff_right, add_comm] theorem le_add_tsub : a ≤ b + (a - b) := tsub_le_iff_left.mp le_rfl /-- See `add_tsub_cancel_left` for the equality if `AddLeftReflectLE α`. -/ theorem add_tsub_le_left : a + b - a ≤ b := tsub_le_iff_left.mpr le_rfl theorem tsub_le_tsub_right (h : a ≤ b) (c : α) : a - c ≤ b - c := tsub_le_iff_left.mpr <| h.trans le_add_tsub theorem tsub_le_iff_tsub_le : a - b ≤ c ↔ a - c ≤ b := by rw [tsub_le_iff_left, tsub_le_iff_right] /-- See `tsub_tsub_cancel_of_le` for the equality. -/ theorem tsub_tsub_le : b - (b - a) ≤ a := tsub_le_iff_right.mpr le_add_tsub section Cov variable [AddLeftMono α] theorem tsub_le_tsub_left (h : a ≤ b) (c : α) : c - b ≤ c - a := tsub_le_iff_left.mpr <| le_add_tsub.trans <| add_le_add_right h _ @[gcongr] theorem tsub_le_tsub (hab : a ≤ b) (hcd : c ≤ d) : a - d ≤ b - c := (tsub_le_tsub_right hab _).trans <| tsub_le_tsub_left hcd _ theorem antitone_const_tsub : Antitone fun x => c - x := fun _ _ hxy => tsub_le_tsub rfl.le hxy /-- See `add_tsub_assoc_of_le` for the equality. -/ theorem add_tsub_le_assoc : a + b - c ≤ a + (b - c) := by rw [tsub_le_iff_left, add_left_comm] exact add_le_add_left le_add_tsub a /-- See `tsub_add_eq_add_tsub` for the equality. -/ theorem add_tsub_le_tsub_add : a + b - c ≤ a - c + b := by rw [add_comm, add_comm _ b] exact add_tsub_le_assoc theorem add_le_add_add_tsub : a + b ≤ a + c + (b - c) := by rw [add_assoc] exact add_le_add_left le_add_tsub a theorem le_tsub_add_add : a + b ≤ a - c + (b + c) := by rw [add_comm a, add_comm (a - c)] exact add_le_add_add_tsub theorem tsub_le_tsub_add_tsub : a - c ≤ a - b + (b - c) := by rw [tsub_le_iff_left, ← add_assoc, add_right_comm] exact le_add_tsub.trans (add_le_add_right le_add_tsub _) theorem tsub_tsub_tsub_le_tsub : c - a - (c - b) ≤ b - a := by rw [tsub_le_iff_left, tsub_le_iff_left, add_left_comm] exact le_tsub_add.trans (add_le_add_left le_add_tsub _) theorem tsub_tsub_le_tsub_add {a b c : α} : a - (b - c) ≤ a - b + c := tsub_le_iff_right.2 <| calc a ≤ a - b + b := le_tsub_add _ ≤ a - b + (c + (b - c)) := add_le_add_left le_add_tsub _ _ = a - b + c + (b - c) := (add_assoc _ _ _).symm /-- See `tsub_add_tsub_comm` for the equality. -/ theorem add_tsub_add_le_tsub_add_tsub : a + b - (c + d) ≤ a - c + (b - d) := by rw [add_comm c, tsub_le_iff_left, add_assoc, ← tsub_le_iff_left, ← tsub_le_iff_left] refine (tsub_le_tsub_right add_tsub_le_assoc c).trans ?_ rw [add_comm a, add_comm (a - c)] exact add_tsub_le_assoc /-- See `add_tsub_add_eq_tsub_left` for the equality. -/ theorem add_tsub_add_le_tsub_left : a + b - (a + c) ≤ b - c := by rw [tsub_le_iff_left, add_assoc] exact add_le_add_left le_add_tsub _ /-- See `add_tsub_add_eq_tsub_right` for the equality. -/ theorem add_tsub_add_le_tsub_right : a + c - (b + c) ≤ a - b := by rw [tsub_le_iff_left, add_right_comm] exact add_le_add_right le_add_tsub c end Cov /-! #### Lemmas that assume that an element is `AddLECancellable` -/ namespace AddLECancellable protected theorem le_add_tsub_swap (hb : AddLECancellable b) : a ≤ b + a - b := hb le_add_tsub protected theorem le_add_tsub (hb : AddLECancellable b) : a ≤ a + b - b := by rw [add_comm] exact hb.le_add_tsub_swap protected theorem le_tsub_of_add_le_left (ha : AddLECancellable a) (h : a + b ≤ c) : b ≤ c - a := ha <| h.trans le_add_tsub protected theorem le_tsub_of_add_le_right (hb : AddLECancellable b) (h : a + b ≤ c) : a ≤ c - b := hb.le_tsub_of_add_le_left <| by rwa [add_comm] end AddLECancellable /-! ### Lemmas where addition is order-reflecting -/ section Contra variable [AddLeftReflectLE α] theorem le_add_tsub_swap : a ≤ b + a - b := Contravariant.AddLECancellable.le_add_tsub_swap theorem le_add_tsub' : a ≤ a + b - b := Contravariant.AddLECancellable.le_add_tsub theorem le_tsub_of_add_le_left (h : a + b ≤ c) : b ≤ c - a := Contravariant.AddLECancellable.le_tsub_of_add_le_left h theorem le_tsub_of_add_le_right (h : a + b ≤ c) : a ≤ c - b := Contravariant.AddLECancellable.le_tsub_of_add_le_right h end Contra end AddCommSemigroup variable [AddCommMonoid α] [Sub α] [OrderedSub α] {a b : α} theorem tsub_nonpos : a - b ≤ 0 ↔ a ≤ b := by rw [tsub_le_iff_left, add_zero] alias ⟨_, tsub_nonpos_of_le⟩ := tsub_nonpos end Preorder /-! ### Partial order -/ variable [PartialOrder α] [AddCommSemigroup α] [Sub α] [OrderedSub α] {a b c d : α} theorem tsub_tsub (b a c : α) : b - a - c = b - (a + c) := by apply le_antisymm · rw [tsub_le_iff_left, tsub_le_iff_left, ← add_assoc, ← tsub_le_iff_left] · rw [tsub_le_iff_left, add_assoc, ← tsub_le_iff_left, ← tsub_le_iff_left] theorem tsub_add_eq_tsub_tsub (a b c : α) : a - (b + c) = a - b - c := (tsub_tsub _ _ _).symm theorem tsub_add_eq_tsub_tsub_swap (a b c : α) : a - (b + c) = a - c - b := by rw [add_comm] apply tsub_add_eq_tsub_tsub theorem tsub_right_comm : a - b - c = a - c - b := by rw [← tsub_add_eq_tsub_tsub, tsub_add_eq_tsub_tsub_swap] /-! ### Lemmas that assume that an element is `AddLECancellable`. -/ namespace AddLECancellable /-- See `AddLECancellable.tsub_eq_of_eq_add'` for a version assuming that `a = c + b` itself is cancellable rather than `b`. -/ protected theorem tsub_eq_of_eq_add (hb : AddLECancellable b) (h : a = c + b) : a - b = c := le_antisymm (tsub_le_iff_right.mpr h.le) <| by rw [h] exact hb.le_add_tsub /-- Weaker version of `AddLECancellable.tsub_eq_of_eq_add` assuming that `a = c + b` itself is cancellable rather than `b`. -/ protected lemma tsub_eq_of_eq_add' [AddLeftMono α] (ha : AddLECancellable a) (h : a = c + b) : a - b = c := (h ▸ ha).of_add_right.tsub_eq_of_eq_add h /-- See `AddLECancellable.eq_tsub_of_add_eq'` for a version assuming that `b = a + c` itself is cancellable rather than `c`. -/ protected theorem eq_tsub_of_add_eq (hc : AddLECancellable c) (h : a + c = b) : a = b - c := (hc.tsub_eq_of_eq_add h.symm).symm /-- Weaker version of `AddLECancellable.eq_tsub_of_add_eq` assuming that `b = a + c` itself is cancellable rather than `c`. -/ protected lemma eq_tsub_of_add_eq' [AddLeftMono α] (hb : AddLECancellable b) (h : a + c = b) : a = b - c := (hb.tsub_eq_of_eq_add' h.symm).symm /-- See `AddLECancellable.tsub_eq_of_eq_add_rev'` for a version assuming that `a = b + c` itself is cancellable rather than `b`. -/ protected theorem tsub_eq_of_eq_add_rev (hb : AddLECancellable b) (h : a = b + c) : a - b = c := hb.tsub_eq_of_eq_add <| by rw [add_comm, h] /-- Weaker version of `AddLECancellable.tsub_eq_of_eq_add_rev` assuming that `a = b + c` itself is cancellable rather than `b`. -/ protected lemma tsub_eq_of_eq_add_rev' [AddLeftMono α] (ha : AddLECancellable a) (h : a = b + c) : a - b = c := ha.tsub_eq_of_eq_add' <| by rw [add_comm, h] @[simp] protected theorem add_tsub_cancel_right (hb : AddLECancellable b) : a + b - b = a := hb.tsub_eq_of_eq_add <| by rw [add_comm] @[simp] protected theorem add_tsub_cancel_left (ha : AddLECancellable a) : a + b - a = b := ha.tsub_eq_of_eq_add <| add_comm a b protected theorem lt_add_of_tsub_lt_left (hb : AddLECancellable b) (h : a - b < c) : a < b + c := by rw [lt_iff_le_and_ne, ← tsub_le_iff_left] refine ⟨h.le, ?_⟩ rintro rfl simp [hb] at h protected theorem lt_add_of_tsub_lt_right (hc : AddLECancellable c) (h : a - c < b) : a < b + c := by rw [lt_iff_le_and_ne, ← tsub_le_iff_right] refine ⟨h.le, ?_⟩ rintro rfl simp [hc] at h protected theorem lt_tsub_of_add_lt_right (hc : AddLECancellable c) (h : a + c < b) : a < b - c := (hc.le_tsub_of_add_le_right h.le).lt_of_ne <| by rintro rfl exact h.not_ge le_tsub_add protected theorem lt_tsub_of_add_lt_left (ha : AddLECancellable a) (h : a + c < b) : c < b - a := ha.lt_tsub_of_add_lt_right <| by rwa [add_comm] end AddLECancellable /-! #### Lemmas where addition is order-reflecting. -/ section Contra variable [AddLeftReflectLE α] theorem tsub_eq_of_eq_add (h : a = c + b) : a - b = c := Contravariant.AddLECancellable.tsub_eq_of_eq_add h theorem eq_tsub_of_add_eq (h : a + c = b) : a = b - c := Contravariant.AddLECancellable.eq_tsub_of_add_eq h theorem tsub_eq_of_eq_add_rev (h : a = b + c) : a - b = c := Contravariant.AddLECancellable.tsub_eq_of_eq_add_rev h @[simp] theorem add_tsub_cancel_right (a b : α) : a + b - b = a := Contravariant.AddLECancellable.add_tsub_cancel_right @[simp] theorem add_tsub_cancel_left (a b : α) : a + b - a = b := Contravariant.AddLECancellable.add_tsub_cancel_left /-- A more general version of the reverse direction of `sub_eq_sub_iff_add_eq_add` -/ theorem tsub_eq_tsub_of_add_eq_add (h : a + d = c + b) : a - b = c - d := by calc a - b = a + d - d - b := by rw [add_tsub_cancel_right] _ = c + b - b - d := by rw [h, tsub_right_comm] _ = c - d := by rw [add_tsub_cancel_right] theorem lt_add_of_tsub_lt_left (h : a - b < c) : a < b + c := Contravariant.AddLECancellable.lt_add_of_tsub_lt_left h theorem lt_add_of_tsub_lt_right (h : a - c < b) : a < b + c := Contravariant.AddLECancellable.lt_add_of_tsub_lt_right h /-- This lemma (and some of its corollaries) also holds for `ENNReal`, but this proof doesn't work for it. Maybe we should add this lemma as field to `OrderedSub`? -/ theorem lt_tsub_of_add_lt_left : a + c < b → c < b - a := Contravariant.AddLECancellable.lt_tsub_of_add_lt_left theorem lt_tsub_of_add_lt_right : a + c < b → a < b - c := Contravariant.AddLECancellable.lt_tsub_of_add_lt_right end Contra section Both variable [AddLeftMono α] [AddLeftReflectLE α] theorem add_tsub_add_eq_tsub_right (a c b : α) : a + c - (b + c) = a - b := by refine add_tsub_add_le_tsub_right.antisymm (tsub_le_iff_right.2 <| ?_) apply le_of_add_le_add_right rw [add_assoc] exact le_tsub_add theorem add_tsub_add_eq_tsub_left (a b c : α) : a + b - (a + c) = b - c := by rw [add_comm a b, add_comm a c, add_tsub_add_eq_tsub_right] end Both end OrderedAddCommSemigroup /-! ### Lemmas in a linearly ordered monoid. -/ section LinearOrder variable {a b c : α} [LinearOrder α] [AddCommSemigroup α] [Sub α] [OrderedSub α] /-- See `lt_of_tsub_lt_tsub_right_of_le` for a weaker statement in a partial order. -/ theorem lt_of_tsub_lt_tsub_right (h : a - c < b - c) : a < b := lt_imp_lt_of_le_imp_le (fun h => tsub_le_tsub_right h c) h /-- See `lt_tsub_iff_right_of_le` for a weaker statement in a partial order. -/ theorem lt_tsub_iff_right : a < b - c ↔ a + c < b := lt_iff_lt_of_le_iff_le tsub_le_iff_right /-- See `lt_tsub_iff_left_of_le` for a weaker statement in a partial order. -/ theorem lt_tsub_iff_left : a < b - c ↔ c + a < b := lt_iff_lt_of_le_iff_le tsub_le_iff_left theorem lt_tsub_comm : a < b - c ↔ c < b - a := lt_tsub_iff_left.trans lt_tsub_iff_right.symm section Cov variable [AddLeftMono α] /-- See `lt_of_tsub_lt_tsub_left_of_le` for a weaker statement in a partial order. -/ theorem lt_of_tsub_lt_tsub_left (h : a - b < a - c) : c < b := lt_imp_lt_of_le_imp_le (fun h => tsub_le_tsub_left h a) h end Cov end LinearOrder section OrderedAddCommMonoid variable [PartialOrder α] [AddCommMonoid α] [Sub α] [OrderedSub α] @[simp] theorem tsub_zero (a : α) : a - 0 = a := AddLECancellable.tsub_eq_of_eq_add addLECancellable_zero (add_zero _).symm end OrderedAddCommMonoid
frobenius.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div. From mathcomp Require Import fintype bigop prime finset fingroup morphism. From mathcomp Require Import perm action quotient gproduct cyclic center. From mathcomp Require Import pgroup nilpotent sylow hall abelian. (******************************************************************************) (* Definition of Frobenius groups, some basic results, and the Frobenius *) (* theorem on the number of solutions of x ^+ n = 1. *) (* semiregular K H <-> *) (* the internal action of H on K is semiregular, i.e., no nontrivial *) (* elements of H and K commute; note that this is actually a symmetric *) (* condition. *) (* semiprime K H <-> *) (* the internal action of H on K is "prime", i.e., an element of K that *) (* centralises a nontrivial element of H must centralise all of H. *) (* normedTI A G L <=> *) (* A is nonempty, strictly disjoint from its conjugates in G, and has *) (* normaliser L in G. *) (* [Frobenius G = K ><| H] <=> *) (* G is (isomorphic to) a Frobenius group with kernel K and complement *) (* H. This is an effective predicate (in bool), which tests the *) (* equality with the semidirect product, and then the fact that H is a *) (* proper self-normalizing TI-subgroup of G. *) (* [Frobenius G with kernel H] <=> *) (* G is (isomorphic to) a Frobenius group with kernel K; same as above, *) (* but without the semi-direct product. *) (* [Frobenius G with complement H] <=> *) (* G is (isomorphic to) a Frobenius group with complement H; same as *) (* above, but without the semi-direct product. The proof that this form *) (* is equivalent to the above (i.e., the existence of Frobenius *) (* kernels) requires character theory and will only be proved in the *) (* vcharacter.v file. *) (* [Frobenius G] <=> G is a Frobenius group. *) (* Frobenius_action G H S to <-> *) (* The action to of G on S defines an isomorphism of G with a *) (* (permutation) Frobenius group, i.e., to is faithful and transitive *) (* on S, no nontrivial element of G fixes more than one point in S, and *) (* H is the stabilizer of some element of S, and non-trivial. Thus, *) (* Frobenius_action G H S 'P *) (* asserts that G is a Frobenius group in the classic sense. *) (* has_Frobenius_action G H <-> *) (* Frobenius_action G H S to holds for some sT : finType, S : {set st} *) (* and to : {action gT &-> sT}. This is a predicate in Prop, but is *) (* exactly reflected by [Frobenius G with complement H] : bool. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section Definitions. Variable gT : finGroupType. Implicit Types A G K H L : {set gT}. (* Corresponds to "H acts on K in a regular manner" in B & G. *) Definition semiregular K H := {in H^#, forall x, 'C_K[x] = 1}. (* Corresponds to "H acts on K in a prime manner" in B & G. *) Definition semiprime K H := {in H^#, forall x, 'C_K[x] = 'C_K(H)}. Definition normedTI A G L := [&& A != set0, trivIset (A :^: G) & 'N_G(A) == L]. Definition Frobenius_group_with_complement G H := (H != G) && normedTI H^# G H. Definition Frobenius_group G := [exists H : {group gT}, Frobenius_group_with_complement G H]. Definition Frobenius_group_with_kernel_and_complement G K H := (K ><| H == G) && Frobenius_group_with_complement G H. Definition Frobenius_group_with_kernel G K := [exists H : {group gT}, Frobenius_group_with_kernel_and_complement G K H]. Section FrobeniusAction. Variables G H : {set gT}. Variables (sT : finType) (S : {set sT}) (to : {action gT &-> sT}). Definition Frobenius_action := [/\ [faithful G, on S | to], [transitive G, on S | to], {in G^#, forall x, #|'Fix_(S | to)[x]| <= 1}, H != 1 & exists2 u, u \in S & H = 'C_G[u | to]]. End FrobeniusAction. Variant has_Frobenius_action G H : Prop := hasFrobeniusAction sT S to of @Frobenius_action G H sT S to. End Definitions. Arguments semiregular {gT} K%_g H%_g. Arguments semiprime {gT} K%_g H%_g. Arguments normedTI {gT} A%_g G%_g L%_g. Arguments Frobenius_group_with_complement {gT} G%_g H%_g. Arguments Frobenius_group {gT} G%_g. Arguments Frobenius_group_with_kernel {gT} G%_g K%_g. Arguments Frobenius_group_with_kernel_and_complement {gT} G%_g K%_g H%_g. Arguments Frobenius_action {gT} G%_g H%_g {sT} S%_g to%_act. Arguments has_Frobenius_action {gT} G%_g H%_g. Notation "[ 'Frobenius' G 'with' 'complement' H ]" := (Frobenius_group_with_complement G H) (G at level 50, format "[ 'Frobenius' G 'with' 'complement' H ]") : group_scope. Notation "[ 'Frobenius' G 'with' 'kernel' K ]" := (Frobenius_group_with_kernel G K) (format "[ 'Frobenius' G 'with' 'kernel' K ]") : group_scope. Notation "[ 'Frobenius' G ]" := (Frobenius_group G) (format "[ 'Frobenius' G ]") : group_scope. Notation "[ 'Frobenius' G = K ><| H ]" := (Frobenius_group_with_kernel_and_complement G K H) (K, H at level 35, format "[ 'Frobenius' G = K ><| H ]") : group_scope. Section FrobeniusBasics. Variable gT : finGroupType. Implicit Types (A B : {set gT}) (G H K L R X : {group gT}). Lemma semiregular1l H : semiregular 1 H. Proof. by move=> x _ /=; rewrite setI1g. Qed. Lemma semiregular1r K : semiregular K 1. Proof. by move=> x; rewrite setDv inE. Qed. Lemma semiregular_sym H K : semiregular K H -> semiregular H K. Proof. move=> regH x /setD1P[ntx Kx]; apply: contraNeq ntx. rewrite -subG1 -setD_eq0 -setIDAC => /set0Pn[y /setIP[Hy cxy]]. by rewrite (sameP eqP set1gP) -(regH y Hy) inE Kx cent1C. Qed. Lemma semiregularS K1 K2 A1 A2 : K1 \subset K2 -> A1 \subset A2 -> semiregular K2 A2 -> semiregular K1 A1. Proof. move=> sK12 sA12 regKA2 x /setD1P[ntx /(subsetP sA12)A2x]. by apply/trivgP; rewrite -(regKA2 x) ?inE ?ntx ?setSI. Qed. Lemma semiregular_prime H K : semiregular K H -> semiprime K H. Proof. move=> regH x Hx; apply/eqP; rewrite eqEsubset {1}regH // sub1G. by rewrite -cent_set1 setIS ?centS // sub1set; case/setD1P: Hx. Qed. Lemma semiprime_regular H K : semiprime K H -> 'C_K(H) = 1 -> semiregular K H. Proof. by move=> prKH tiKcH x Hx; rewrite prKH. Qed. Lemma semiprimeS K1 K2 A1 A2 : K1 \subset K2 -> A1 \subset A2 -> semiprime K2 A2 -> semiprime K1 A1. Proof. move=> sK12 sA12 prKA2 x /setD1P[ntx A1x]. apply/eqP; rewrite eqEsubset andbC -{1}cent_set1 setIS ?centS ?sub1set //=. rewrite -(setIidPl sK12) -!setIA prKA2 ?setIS ?centS //. by rewrite !inE ntx (subsetP sA12). Qed. Lemma cent_semiprime H K X : semiprime K H -> X \subset H -> X :!=: 1 -> 'C_K(X) = 'C_K(H). Proof. move=> prKH sXH /trivgPn[x Xx ntx]; apply/eqP. rewrite eqEsubset -{1}(prKH x) ?inE ?(subsetP sXH) ?ntx //=. by rewrite -cent_cycle !setIS ?centS ?cycle_subG. Qed. Lemma stab_semiprime H K X : semiprime K H -> X \subset K -> 'C_H(X) != 1 -> 'C_H(X) = H. Proof. move=> prKH sXK ntCHX; apply/setIidPl; rewrite centsC -subsetIidl. rewrite -{2}(setIidPl sXK) -setIA -(cent_semiprime prKH _ ntCHX) ?subsetIl //. by rewrite !subsetI subxx sXK centsC subsetIr. Qed. Lemma cent_semiregular H K X : semiregular K H -> X \subset H -> X :!=: 1 -> 'C_K(X) = 1. Proof. move=> regKH sXH /trivgPn[x Xx ntx]; apply/trivgP. rewrite -(regKH x) ?inE ?(subsetP sXH) ?ntx ?setIS //=. by rewrite -cent_cycle centS ?cycle_subG. Qed. Lemma regular_norm_dvd_pred K H : H \subset 'N(K) -> semiregular K H -> #|H| %| #|K|.-1. Proof. move=> nKH regH; have actsH: [acts H, on K^# | 'J] by rewrite astabsJ normD1. rewrite (cardsD1 1 K) group1 -(acts_sum_card_orbit actsH) /=. rewrite (eq_bigr (fun _ => #|H|)) ?sum_nat_const ?dvdn_mull //. move=> _ /imsetP[x /setIdP[ntx Kx] ->]; rewrite card_orbit astab1J. rewrite ['C_H[x]](trivgP _) ?indexg1 //=. apply/subsetP=> y /setIP[Hy cxy]; apply: contraR ntx => nty. by rewrite -[[set 1]](regH y) inE ?nty // Kx cent1C. Qed. Lemma regular_norm_coprime K H : H \subset 'N(K) -> semiregular K H -> coprime #|K| #|H|. Proof. move=> nKH regH. by rewrite (coprime_dvdr (regular_norm_dvd_pred nKH regH)) ?coprimenP. Qed. Lemma semiregularJ K H x : semiregular K H -> semiregular (K :^ x) (H :^ x). Proof. move=> regH yx; rewrite -conjD1g => /imsetP[y Hy ->]. by rewrite cent1J -conjIg regH ?conjs1g. Qed. Lemma semiprimeJ K H x : semiprime K H -> semiprime (K :^ x) (H :^ x). Proof. move=> prH yx; rewrite -conjD1g => /imsetP[y Hy ->]. by rewrite cent1J centJ -!conjIg prH. Qed. Lemma normedTI_P A G L : reflect [/\ A != set0, L \subset 'N_G(A) & {in G, forall g, ~~ [disjoint A & A :^ g] -> g \in L}] (normedTI A G L). Proof. apply: (iffP and3P) => [[nzA /trivIsetP tiAG /eqP <-] | [nzA sLN tiAG]]. split=> // g Gg; rewrite inE Gg (sameP normP eqP) /= eq_sym; apply: contraR. by apply: tiAG; rewrite ?mem_orbit ?orbit_refl. have [/set0Pn[a Aa] /subsetIP[_ nAL]] := (nzA, sLN); split=> //; last first. rewrite eqEsubset sLN andbT; apply/subsetP=> x /setIP[Gx nAx]. by apply/tiAG/pred0Pn=> //; exists a; rewrite /= (normP nAx) Aa. apply/trivIsetP=> _ _ /imsetP[x Gx ->] /imsetP[y Gy ->]; apply: contraR. rewrite -setI_eq0 -(mulgKV x y) conjsgM; set g := (y * x^-1)%g. have Gg: g \in G by rewrite groupMl ?groupV. rewrite -conjIg (inj_eq (act_inj 'Js x)) (eq_sym A) (sameP eqP normP). by rewrite -cards_eq0 cardJg cards_eq0 setI_eq0 => /tiAG/(subsetP nAL)->. Qed. Arguments normedTI_P {A G L}. Lemma normedTI_memJ_P A G L : reflect [/\ A != set0, L \subset G & {in A & G, forall a g, (a ^ g \in A) = (g \in L)}] (normedTI A G L). Proof. apply: (iffP normedTI_P) => [[-> /subsetIP[sLG nAL] tiAG] | [-> sLG tiAG]]. split=> // a g Aa Gg; apply/idP/idP=> [Aag | Lg]; last first. by rewrite memJ_norm ?(subsetP nAL). by apply/tiAG/pred0Pn=> //; exists (a ^ g)%g; rewrite /= Aag memJ_conjg. split=> // [ | g Gg /pred0Pn[ag /=]]; last first. by rewrite andbC => /andP[/imsetP[a Aa ->]]; rewrite tiAG. apply/subsetP=> g Lg; have Gg := subsetP sLG g Lg. by rewrite !inE Gg; apply/subsetP=> _ /imsetP[a Aa ->]; rewrite tiAG. Qed. Lemma partition_class_support A G : A != set0 -> trivIset (A :^: G) -> partition (A :^: G) (class_support A G). Proof. rewrite /partition cover_imset -class_supportEr eqxx => nzA ->. by apply: contra nzA => /imsetP[x _ /eqP]; rewrite eq_sym -!cards_eq0 cardJg. Qed. Lemma partition_normedTI A G L : normedTI A G L -> partition (A :^: G) (class_support A G). Proof. by case/and3P=> ntA tiAG _; apply: partition_class_support. Qed. Lemma card_support_normedTI A G L : normedTI A G L -> #|class_support A G| = (#|A| * #|G : L|)%N. Proof. case/and3P=> ntA tiAG /eqP <-; rewrite -card_conjugates mulnC. apply: card_uniform_partition (partition_class_support ntA tiAG). by move=> _ /imsetP[y _ ->]; rewrite cardJg. Qed. Lemma normedTI_S A B G L : A != set0 -> L \subset 'N(A) -> A \subset B -> normedTI B G L -> normedTI A G L. Proof. move=> nzA /subsetP nAL /subsetP sAB /normedTI_memJ_P[nzB sLG tiB]. apply/normedTI_memJ_P; split=> // a x Aa Gx. by apply/idP/idP => [Aax | /nAL/memJ_norm-> //]; rewrite -(tiB a) ?sAB. Qed. Lemma cent1_normedTI A G L : normedTI A G L -> {in A, forall x, 'C_G[x] \subset L}. Proof. case/normedTI_memJ_P=> [_ _ tiAG] x Ax; apply/subsetP=> y /setIP[Gy cxy]. by rewrite -(tiAG x) // /(x ^ y) -(cent1P cxy) mulKg. Qed. Lemma Frobenius_actionP G H : reflect (has_Frobenius_action G H) [Frobenius G with complement H]. Proof. apply: (iffP andP) => [[neqHG] | [sT S to [ffulG transG regG ntH [u Su defH]]]]. case/normedTI_P=> nzH /subsetIP[sHG _] tiHG. suffices: Frobenius_action G H (rcosets H G) 'Rs by apply: hasFrobeniusAction. pose Hfix x := 'Fix_(rcosets H G | 'Rs)[x]. have regG: {in G^#, forall x, #|Hfix x| <= 1}. move=> x /setD1P[ntx Gx]. apply: wlog_neg; rewrite -ltnNge => /ltnW/card_gt0P/=[Hy]. rewrite -(cards1 Hy) => /setIP[/imsetP[y Gy ->{Hy}] cHyx]. apply/subset_leq_card/subsetP=> _ /setIP[/imsetP[z Gz ->] cHzx]. rewrite -!sub_astab1 !astab1_act !sub1set astab1Rs in cHyx cHzx *. rewrite !rcosetE; apply/set1P/rcoset_eqP; rewrite mem_rcoset. apply: tiHG; [by rewrite !in_group | apply/pred0Pn; exists (x ^ y^-1)]. by rewrite conjD1g !inE conjg_eq1 ntx -mem_conjg cHyx conjsgM memJ_conjg. have ntH: H :!=: 1 by rewrite -subG1 -setD_eq0. split=> //; first 1 last; first exact: transRs_rcosets. by exists (val H); rewrite ?orbit_refl // astab1Rs (setIidPr sHG). apply/subsetP=> y /setIP[Gy cHy]; apply: contraR neqHG => nt_y. rewrite (index1g sHG) //; apply/eqP; rewrite eqn_leq indexg_gt0 andbT. apply: leq_trans (regG y _); last by rewrite setDE 2!inE Gy nt_y /=. by rewrite /Hfix (setIidPl _) -1?astabC ?sub1set. have sHG: H \subset G by rewrite defH subsetIl. split. apply: contraNneq ntH => /= defG. suffices defS: S = [set u] by rewrite -(trivgP ffulG) /= defS defH. apply/eqP; rewrite eq_sym eqEcard sub1set Su. by rewrite -(atransP transG u Su) card_orbit -defH defG indexgg cards1. apply/normedTI_P; rewrite setD_eq0 subG1 normD1 subsetI sHG normG. split=> // x Gx; rewrite -setI_eq0 conjD1g defH inE Gx conjIg conjGid //. rewrite -setDIl -setIIr -astab1_act setDIl => /set0Pn[y /setIP[Gy /setD1P[_]]]. case/setIP; rewrite 2!(sameP astab1P afix1P) => cuy cuxy; apply/astab1P. apply: contraTeq (regG y Gy) => cu'x. rewrite (cardD1 u) (cardD1 (to u x)) inE Su cuy inE /= inE cu'x cuxy. by rewrite (actsP (atrans_acts transG)) ?Su. Qed. Section FrobeniusProperties. Variables G H K : {group gT}. Hypothesis frobG : [Frobenius G = K ><| H]. Lemma FrobeniusWker : [Frobenius G with kernel K]. Proof. by apply/existsP; exists H. Qed. Lemma FrobeniusWcompl : [Frobenius G with complement H]. Proof. by case/andP: frobG. Qed. Lemma FrobeniusW : [Frobenius G]. Proof. by apply/existsP; exists H; apply: FrobeniusWcompl. Qed. Lemma Frobenius_context : [/\ K ><| H = G, K :!=: 1, H :!=: 1, K \proper G & H \proper G]. Proof. have [/eqP defG neqHG ntH _] := and4P frobG; rewrite setD_eq0 subG1 in ntH. have ntK: K :!=: 1 by apply: contraNneq neqHG => K1; rewrite -defG K1 sdprod1g. rewrite properEcard properEneq neqHG; have /mulG_sub[-> ->] := sdprodW defG. by rewrite -(sdprod_card defG) ltn_Pmulr ?cardG_gt1. Qed. Lemma Frobenius_partition : partition (gval K |: (H^# :^: K)) G. Proof. have [/eqP defG _ tiHG] := and3P frobG; have [_ tiH1G /eqP defN] := and3P tiHG. have [[_ /mulG_sub[sKG sHG] nKH tiKH] mulHK] := (sdprodP defG, sdprodWC defG). set HG := H^# :^: K; set KHG := _ |: _. have defHG: HG = H^# :^: G. have: 'C_G[H^# | 'Js] * K = G by rewrite astab1Js defN mulHK. move/subgroup_transitiveP/atransP. by apply; rewrite ?atrans_orbit ?orbit_refl. have /and3P[defHK _ nzHG] := partition_normedTI tiHG. rewrite -defHG in defHK nzHG tiH1G. have [tiKHG HG'K]: trivIset KHG /\ gval K \notin HG. apply: trivIsetU1 => // _ /imsetP[x Kx ->]; rewrite -setI_eq0. by rewrite -(conjGid Kx) -conjIg setIDA tiKH setDv conj0g. rewrite /partition andbC tiKHG !inE negb_or nzHG eq_sym -card_gt0 cardG_gt0 /=. rewrite eqEcard; apply/andP; split. rewrite /cover big_setU1 //= subUset sKG -/(cover HG) (eqP defHK). by rewrite class_support_subG // (subset_trans _ sHG) ?subD1set. rewrite -(eqnP tiKHG) big_setU1 //= (eqnP tiH1G) (eqP defHK). rewrite (card_support_normedTI tiHG) -(Lagrange sHG) (cardsD1 1) group1 mulSn. by rewrite leq_add2r -mulHK indexMg -indexgI tiKH indexg1. Qed. Lemma Frobenius_cent1_ker : {in K^#, forall x, 'C_G[x] \subset K}. Proof. have [/eqP defG _ /normedTI_memJ_P[_ _ tiHG]] := and3P frobG. move=> x /setD1P[ntx Kx]; have [_ /mulG_sub[sKG _] _ tiKH] := sdprodP defG. have [/eqP <- _ _] := and3P Frobenius_partition; rewrite big_distrl /=. apply/bigcupsP=> _ /setU1P[|/imsetP[y Ky]] ->; first exact: subsetIl. apply: contraR ntx => /subsetPn[z]; rewrite inE mem_conjg => /andP[Hzy cxz] _. rewrite -(conjg_eq1 x y^-1) -in_set1 -set1gE -tiKH inE andbC. rewrite -(tiHG _ _ Hzy) ?(subsetP sKG) ?in_group // Ky andbT -conjJg. by rewrite /(z ^ x) (cent1P cxz) mulKg. Qed. Lemma Frobenius_reg_ker : semiregular K H. Proof. move=> x /setD1P[ntx Hx]. apply/trivgP/subsetP=> y /setIP[Ky cxy]; apply: contraR ntx => nty. have K1y: y \in K^# by rewrite inE nty. have [/eqP/sdprod_context[_ sHG _ _ tiKH] _] := andP frobG. suffices: x \in K :&: H by rewrite tiKH inE. by rewrite inE (subsetP (Frobenius_cent1_ker K1y)) // inE cent1C (subsetP sHG). Qed. Lemma Frobenius_reg_compl : semiregular H K. Proof. by apply: semiregular_sym; apply: Frobenius_reg_ker. Qed. Lemma Frobenius_dvd_ker1 : #|H| %| #|K|.-1. Proof. apply: regular_norm_dvd_pred Frobenius_reg_ker. by have[/sdprodP[]] := Frobenius_context. Qed. Lemma ltn_odd_Frobenius_ker : odd #|G| -> #|H|.*2 < #|K|. Proof. move/oddSg=> oddG. have [/sdprodW/mulG_sub[sKG sHG] ntK _ _ _] := Frobenius_context. by rewrite dvdn_double_ltn ?oddG ?cardG_gt1 ?Frobenius_dvd_ker1. Qed. Lemma Frobenius_index_dvd_ker1 : #|G : K| %| #|K|.-1. Proof. have[defG _ _ /andP[sKG _] _] := Frobenius_context. by rewrite -divgS // -(sdprod_card defG) mulKn ?Frobenius_dvd_ker1. Qed. Lemma Frobenius_coprime : coprime #|K| #|H|. Proof. by rewrite (coprime_dvdr Frobenius_dvd_ker1) ?coprimenP. Qed. Lemma Frobenius_trivg_cent : 'C_K(H) = 1. Proof. by apply: (cent_semiregular Frobenius_reg_ker); case: Frobenius_context. Qed. Lemma Frobenius_index_coprime : coprime #|K| #|G : K|. Proof. by rewrite (coprime_dvdr Frobenius_index_dvd_ker1) ?coprimenP. Qed. Lemma Frobenius_ker_Hall : Hall G K. Proof. have [_ _ _ /andP[sKG _] _] := Frobenius_context. by rewrite /Hall sKG Frobenius_index_coprime. Qed. Lemma Frobenius_compl_Hall : Hall G H. Proof. have [defG _ _ _ _] := Frobenius_context. by rewrite -(sdprod_Hall defG) Frobenius_ker_Hall. Qed. End FrobeniusProperties. Lemma normedTI_J x A G L : normedTI (A :^ x) (G :^ x) (L :^ x) = normedTI A G L. Proof. rewrite {1}/normedTI normJ -conjIg -(conj0g x) !(can_eq (conjsgK x)). congr [&& _, _ == _ & _]; rewrite /cover (reindex_inj (@conjsg_inj _ x)). by apply: eq_big => Hy; rewrite ?orbit_conjsg ?cardJg. by rewrite bigcupJ cardJg (eq_bigl _ _ (orbit_conjsg _ _ _ _)). Qed. Lemma FrobeniusJcompl x G H : [Frobenius G :^ x with complement H :^ x] = [Frobenius G with complement H]. Proof. by congr (_ && _); rewrite ?(can_eq (conjsgK x)) // -conjD1g normedTI_J. Qed. Lemma FrobeniusJ x G K H : [Frobenius G :^ x = K :^ x ><| H :^ x] = [Frobenius G = K ><| H]. Proof. by congr (_ && _); rewrite ?FrobeniusJcompl // -sdprodJ (can_eq (conjsgK x)). Qed. Lemma FrobeniusJker x G K : [Frobenius G :^ x with kernel K :^ x] = [Frobenius G with kernel K]. Proof. apply/existsP/existsP=> [] [H]; last by exists (H :^ x)%G; rewrite FrobeniusJ. by rewrite -(conjsgKV x H) FrobeniusJ; exists (H :^ x^-1)%G. Qed. Lemma FrobeniusJgroup x G : [Frobenius G :^ x] = [Frobenius G]. Proof. apply/existsP/existsP=> [] [H]. by rewrite -(conjsgKV x H) FrobeniusJcompl; exists (H :^ x^-1)%G. by exists (H :^ x)%G; rewrite FrobeniusJcompl. Qed. Lemma Frobenius_ker_dvd_ker1 G K : [Frobenius G with kernel K] -> #|G : K| %| #|K|.-1. Proof. by case/existsP=> H; apply: Frobenius_index_dvd_ker1. Qed. Lemma Frobenius_ker_coprime G K : [Frobenius G with kernel K] -> coprime #|K| #|G : K|. Proof. by case/existsP=> H; apply: Frobenius_index_coprime. Qed. Lemma Frobenius_semiregularP G K H : K ><| H = G -> K :!=: 1 -> H :!=: 1 -> reflect (semiregular K H) [Frobenius G = K ><| H]. Proof. move=> defG ntK ntH. apply: (iffP idP) => [|regG]; first exact: Frobenius_reg_ker. have [nsKG sHG defKH nKH tiKH]:= sdprod_context defG; have [sKG _]:= andP nsKG. apply/and3P; split; first by rewrite defG. by rewrite eqEcard sHG -(sdprod_card defG) -ltnNge ltn_Pmull ?cardG_gt1. apply/normedTI_memJ_P; rewrite setD_eq0 subG1 sHG -defKH -(normC nKH). split=> // z _ /setD1P[ntz Hz] /mulsgP[y x Hy Kx ->]; rewrite groupMl // !inE. rewrite conjg_eq1 ntz; apply/idP/idP=> [Hzxy | Hx]; last by rewrite !in_group. apply: (subsetP (sub1G H)); have Hzy: z ^ y \in H by apply: groupJ. rewrite -(regG (z ^ y)); last by apply/setD1P; rewrite conjg_eq1. rewrite inE Kx cent1C (sameP cent1P commgP) -in_set1 -[[set 1]]tiKH inE /=. rewrite andbC groupM ?groupV -?conjgM //= commgEr groupMr //. by rewrite memJ_norm ?(subsetP nKH) ?groupV. Qed. Lemma prime_FrobeniusP G K H : K :!=: 1 -> prime #|H| -> reflect (K ><| H = G /\ 'C_K(H) = 1) [Frobenius G = K ><| H]. Proof. move=> ntK H_pr; have ntH: H :!=: 1 by rewrite -cardG_gt1 prime_gt1. have [defG | not_sdG] := eqVneq (K ><| H) G; last first. by apply: (iffP andP) => [] [defG]; rewrite defG ?eqxx in not_sdG. apply: (iffP (Frobenius_semiregularP defG ntK ntH)) => [regH | [_ regH x]]. split=> //; have [x defH] := cyclicP (prime_cyclic H_pr). by rewrite defH cent_cycle regH // !inE defH cycle_id andbT -cycle_eq1 -defH. case/setD1P=> nt_x Hx; apply/trivgP; rewrite -regH setIS //= -cent_cycle. by rewrite centS // prime_meetG // (setIidPr _) ?cycle_eq1 ?cycle_subG. Qed. Lemma Frobenius_subl G K K1 H : K1 :!=: 1 -> K1 \subset K -> H \subset 'N(K1) -> [Frobenius G = K ><| H] -> [Frobenius K1 <*> H = K1 ><| H]. Proof. move=> ntK1 sK1K nK1H frobG; have [_ _ ntH _ _] := Frobenius_context frobG. apply/Frobenius_semiregularP=> //. by rewrite sdprodEY ?coprime_TIg ?(coprimeSg sK1K) ?(Frobenius_coprime frobG). by move=> x /(Frobenius_reg_ker frobG) cKx1; apply/trivgP; rewrite -cKx1 setSI. Qed. Lemma Frobenius_subr G K H H1 : H1 :!=: 1 -> H1 \subset H -> [Frobenius G = K ><| H] -> [Frobenius K <*> H1 = K ><| H1]. Proof. move=> ntH1 sH1H frobG; have [defG ntK _ _ _] := Frobenius_context frobG. apply/Frobenius_semiregularP=> //. have [_ _ /(subset_trans sH1H) nH1K tiHK] := sdprodP defG. by rewrite sdprodEY //; apply/trivgP; rewrite -tiHK setIS. by apply: sub_in1 (Frobenius_reg_ker frobG); apply/subsetP/setSD. Qed. Lemma Frobenius_kerP G K : reflect [/\ K :!=: 1, K \proper G, K <| G & {in K^#, forall x, 'C_G[x] \subset K}] [Frobenius G with kernel K]. Proof. apply: (iffP existsP) => [[H frobG] | [ntK ltKG nsKG regK]]. have [/sdprod_context[nsKG _ _ _ _] ntK _ ltKG _] := Frobenius_context frobG. by split=> //; apply: Frobenius_cent1_ker frobG. have /andP[sKG nKG] := nsKG. have hallK: Hall G K. rewrite /Hall sKG //= coprime_sym coprime_pi' //. apply: sub_pgroup (pgroup_pi K) => p; have [P sylP] := Sylow_exists p G. have [[sPG pP p'GiP] sylPK] := (and3P sylP, Hall_setI_normal nsKG sylP). rewrite -p_rank_gt0 -(rank_Sylow sylPK) rank_gt0 => ntPK. rewrite inE /= -p'natEpi // (pnat_dvd _ p'GiP) ?indexgS //. have /trivgPn[z]: P :&: K :&: 'Z(P) != 1. by rewrite meet_center_nil ?(pgroup_nil pP) ?(normalGI sPG nsKG). rewrite !inE -andbA -sub_cent1=> /and4P[_ Kz _ cPz] ntz. by apply: subset_trans (regK z _); [apply/subsetIP | apply/setD1P]. have /splitsP[H /complP[tiKH defG]] := SchurZassenhaus_split hallK nsKG. have [_ sHG] := mulG_sub defG; have nKH := subset_trans sHG nKG. exists H; apply/Frobenius_semiregularP; rewrite ?sdprodE //. by apply: contraNneq (proper_subn ltKG) => H1; rewrite -defG H1 mulg1. apply: semiregular_sym => x Kx; apply/trivgP; rewrite -tiKH. by rewrite subsetI subsetIl (subset_trans _ (regK x _)) ?setSI. Qed. Lemma set_Frobenius_compl G K H : K ><| H = G -> [Frobenius G with kernel K] -> [Frobenius G = K ><| H]. Proof. move=> defG /Frobenius_kerP[ntK ltKG _ regKG]. apply/Frobenius_semiregularP=> //. by apply: contraTneq ltKG => H_1; rewrite -defG H_1 sdprodg1 properxx. apply: semiregular_sym => y /regKG sCyK. have [_ sHG _ _ tiKH] := sdprod_context defG. by apply/trivgP; rewrite /= -(setIidPr sHG) setIAC -tiKH setSI. Qed. Lemma Frobenius_kerS G K G1 : G1 \subset G -> K \proper G1 -> [Frobenius G with kernel K] -> [Frobenius G1 with kernel K]. Proof. move=> sG1G ltKG1 /Frobenius_kerP[ntK _ /andP[_ nKG] regKG]. apply/Frobenius_kerP; rewrite /normal proper_sub // (subset_trans sG1G) //. by split=> // x /regKG; apply: subset_trans; rewrite setSI. Qed. Lemma Frobenius_action_kernel_def G H K sT S to : K ><| H = G -> @Frobenius_action _ G H sT S to -> K :=: 1 :|: [set x in G | 'Fix_(S | to)[x] == set0]. Proof. move=> defG FrobG. have partG: partition (gval K |: (H^# :^: K)) G. apply: Frobenius_partition; apply/andP; rewrite defG; split=> //. by apply/Frobenius_actionP; apply: hasFrobeniusAction FrobG. have{FrobG} [ffulG transG regG ntH [u Su defH]]:= FrobG. apply/setP=> x /[!inE]; have [-> | ntx] := eqVneq; first exact: group1. rewrite /= -(cover_partition partG) /cover. have neKHy y: gval K <> H^# :^ y. by move/setP/(_ 1); rewrite group1 conjD1g setD11. rewrite big_setU1 /= ?inE; last by apply/imsetP=> [[y _ /neKHy]]. have [nsKG sHG _ _ tiKH] := sdprod_context defG; have [sKG nKG]:= andP nsKG. symmetry; case Kx: (x \in K) => /=. apply/set0Pn=> [[v /setIP[Sv]]]; have [y Gy ->] := atransP2 transG Su Sv. rewrite -sub1set -astabC sub1set astab1_act mem_conjg => Hxy. case/negP: ntx; rewrite -in_set1 -(conjgKV y x) -mem_conjgV conjs1g -tiKH. by rewrite defH setIA inE -mem_conjg (setIidPl sKG) (normsP nKG) ?Kx. apply/andP=> [[/bigcupP[_ /imsetP[y Ky ->] Hyx] /set0Pn[]]]; exists (to u y). rewrite inE (actsP (atrans_acts transG)) ?(subsetP sKG) // Su. rewrite -sub1set -astabC sub1set astab1_act. by rewrite conjD1g defH conjIg !inE in Hyx; case/and3P: Hyx. Qed. End FrobeniusBasics. Arguments normedTI_P {gT A G L}. Arguments normedTI_memJ_P {gT A G L}. Arguments Frobenius_kerP {gT G K}. Lemma Frobenius_coprime_quotient (gT : finGroupType) (G K H N : {group gT}) : K ><| H = G -> N <| G -> coprime #|K| #|H| /\ H :!=: 1%g -> N \proper K /\ {in H^#, forall x, 'C_K[x] \subset N} -> [Frobenius G / N = (K / N) ><| (H / N)]%g. Proof. move=> defG nsNG [coKH ntH] [ltNK regH]. have [[sNK _] [_ /mulG_sub[sKG sHG] _ _]] := (andP ltNK, sdprodP defG). have [_ nNG] := andP nsNG; have nNH := subset_trans sHG nNG. apply/Frobenius_semiregularP; first exact: quotient_coprime_sdprod. - by rewrite quotient_neq1 ?(normalS _ sKG). - by rewrite -(isog_eq1 (quotient_isog _ _)) ?coprime_TIg ?(coprimeSg sNK). move=> _ /(subsetP (quotientD1 _ _))/morphimP[x nNx H1x ->]. rewrite -cent_cycle -quotient_cycle //=. rewrite -strongest_coprime_quotient_cent ?cycle_subG //. - by rewrite cent_cycle quotientS1 ?regH. - by rewrite subIset ?sNK. - rewrite (coprimeSg (subsetIl N _)) ?(coprimeSg sNK) ?(coprimegS _ coKH) //. by rewrite cycle_subG; case/setD1P: H1x. by rewrite orbC abelian_sol ?cycle_abelian. Qed. Section InjmFrobenius. Variables (gT rT : finGroupType) (D G : {group gT}) (f : {morphism D >-> rT}). Implicit Types (H K : {group gT}) (sGD : G \subset D) (injf : 'injm f). Lemma injm_Frobenius_compl H sGD injf : [Frobenius G with complement H] -> [Frobenius f @* G with complement f @* H]. Proof. case/andP=> neqGH /normedTI_P[nzH /subsetIP[sHG _] tiHG]. have sHD := subset_trans sHG sGD; have sH1D := subset_trans (subD1set H 1) sHD. apply/andP; rewrite (can_in_eq (injmK injf)) //; split=> //. apply/normedTI_P; rewrite normD1 -injmD1 // -!cards_eq0 card_injm // in nzH *. rewrite subsetI normG morphimS //; split=> // _ /morphimP[x Dx Gx ->] ti'fHx. rewrite mem_morphim ?tiHG //; apply: contra ti'fHx; rewrite -!setI_eq0 => tiHx. by rewrite -morphimJ // -injmI ?conj_subG // (eqP tiHx) morphim0. Qed. Lemma injm_Frobenius H K sGD injf : [Frobenius G = K ><| H] -> [Frobenius f @* G = f @* K ><| f @* H]. Proof. case/andP=> /eqP defG frobG. by apply/andP; rewrite (injm_sdprod _ injf defG) // eqxx injm_Frobenius_compl. Qed. Lemma injm_Frobenius_ker K sGD injf : [Frobenius G with kernel K] -> [Frobenius f @* G with kernel f @* K]. Proof. case/existsP=> H frobG; apply/existsP. by exists (f @* H)%G; apply: injm_Frobenius. Qed. Lemma injm_Frobenius_group sGD injf : [Frobenius G] -> [Frobenius f @* G]. Proof. case/existsP=> H frobG; apply/existsP; exists (f @* H)%G. exact: injm_Frobenius_compl. Qed. End InjmFrobenius. Theorem Frobenius_Ldiv (gT : finGroupType) (G : {group gT}) n : n %| #|G| -> n %| #|'Ldiv_n(G)|. Proof. move=> nG; move: {2}_.+1 (ltnSn (#|G| %/ n)) => mq. elim: mq => // mq IHm in gT G n nG *; case/dvdnP: nG => q oG. have [q_gt0 n_gt0] : 0 < q /\ 0 < n by apply/andP; rewrite -muln_gt0 -oG. rewrite ltnS oG mulnK // => leqm. have:= q_gt0; rewrite leq_eqVlt => /predU1P[q1 | lt1q]. rewrite -(mul1n n) q1 -oG (setIidPl _) //. by apply/subsetP=> x Gx; rewrite inE -order_dvdn order_dvdG. pose p := pdiv q; have pr_p: prime p by apply: pdiv_prime. have lt1p: 1 < p := prime_gt1 pr_p; have p_gt0 := ltnW lt1p. have{leqm} lt_qp_mq: q %/ p < mq by apply: leq_trans leqm; rewrite ltn_Pdiv. have: n %| #|'Ldiv_(p * n)(G)|. have: p * n %| #|G| by rewrite oG dvdn_pmul2r ?pdiv_dvd. move/IHm=> IH; apply: dvdn_trans (IH _); first exact: dvdn_mull. by rewrite oG divnMr. rewrite -(cardsID 'Ldiv_n()) dvdn_addl. rewrite -setIA ['Ldiv_n(_)](setIidPr _) //. by apply/subsetP=> x; rewrite !inE -!order_dvdn; apply: dvdn_mull. rewrite -setIDA; set A := _ :\: _. have pA x: x \in A -> #[x]`_p = (n`_p * p)%N. rewrite !inE -!order_dvdn => /andP[xn xnp]. rewrite !p_part // -expnSr; congr (p ^ _)%N; apply/eqP. rewrite eqn_leq -{1}addn1 -(pfactorK 1 pr_p) -lognM ?expn1 // mulnC. rewrite dvdn_leq_log ?muln_gt0 ?p_gt0 //= ltnNge; apply: contra xn => xn. move: xnp; rewrite -[#[x]](partnC p) //. rewrite !Gauss_dvd ?coprime_partC //; case/andP=> _. rewrite p_part ?pfactor_dvdn // xn Gauss_dvdr // coprime_sym. exact: pnat_coprime (pnat_id _) (part_pnat _ _). rewrite -(partnC p n_gt0) Gauss_dvd ?coprime_partC //; apply/andP; split. rewrite -sum1_card (partition_big_imset (@cycle _)) /=. apply: dvdn_sum => _ /imsetP[x /setIP[Gx Ax] ->]. rewrite (eq_bigl (generator <[x]>)) => [|y]. rewrite sum1dep_card -totient_gen -[#[x]](partnC p) //. rewrite totient_coprime ?coprime_partC // dvdn_mulr // . by rewrite (pA x Ax) p_part // -expnSr totient_pfactor // dvdn_mull. rewrite /generator eq_sym andbC; case xy: {+}(_ == _) => //. rewrite !inE -!order_dvdn in Ax *. by rewrite -cycle_subG /order -(eqP xy) cycle_subG Gx. rewrite -sum1_card (partition_big_imset (fun x => x.`_p ^: G)) /=. apply: dvdn_sum => _ /imsetP[x /setIP[Gx Ax] ->]. set y := x.`_p; have oy: #[y] = (n`_p * p)%N by rewrite order_constt pA. rewrite (partition_big (fun x => x.`_p) [in y ^: G]) /= => [|z]; last first. by case/andP=> _ /eqP <-; rewrite /= class_refl. pose G' := ('C_G[y] / <[y]>)%G; pose n' := gcdn #|G'| n`_p^'. have n'_gt0: 0 < n' by rewrite gcdn_gt0 cardG_gt0. rewrite (eq_bigr (fun _ => #|'Ldiv_n'(G')|)) => [|_ /imsetP[a Ga ->]]. rewrite sum_nat_const -index_cent1 indexgI. rewrite -(dvdn_pmul2l (cardG_gt0 'C_G[y])) mulnA LagrangeI. have oCy: #|'C_G[y]| = (#[y] * #|G'|)%N. rewrite card_quotient ?subcent1_cycle_norm // Lagrange //. by rewrite subcent1_cycle_sub ?groupX. rewrite oCy -mulnA -(muln_lcm_gcd #|G'|) -/n' mulnA dvdn_mul //. rewrite muln_lcmr -oCy order_constt pA // mulnAC partnC // dvdn_lcm. by rewrite cardSg ?subsetIl // mulnC oG dvdn_pmul2r ?pdiv_dvd. apply: IHm; [exact: dvdn_gcdl | apply: leq_ltn_trans lt_qp_mq]. rewrite -(@divnMr n`_p^') // -muln_lcm_gcd mulnC divnMl //. rewrite leq_divRL // divn_mulAC ?leq_divLR ?dvdn_mulr ?dvdn_lcmr //. rewrite dvdn_leq ?muln_gt0 ?q_gt0 //= mulnC muln_lcmr dvdn_lcm. rewrite -(@dvdn_pmul2l n`_p) // mulnA -oy -oCy mulnCA partnC // -oG. by rewrite cardSg ?subsetIl // dvdn_mul ?pdiv_dvd. pose h := [fun z => coset <[y]> (z ^ a^-1)]. pose h' := [fun Z : coset_of <[y]> => (y * (repr Z).`_p^') ^ a]. rewrite -sum1_card (reindex_onto h h') /= => [|Z]; last first. rewrite conjgK coset_kerl ?cycle_id ?morph_constt ?repr_coset_norm //. rewrite /= coset_reprK 2!inE -order_dvdn dvdn_gcd => /and3P[_ _ p'Z]. by apply: constt_p_elt (pnat_dvd p'Z _); apply: part_pnat. apply: eq_bigl => z; apply/andP/andP=> [[]|[]]. rewrite inE -andbA => /and3P[Gz Az _] /eqP zp_ya. have czy: z ^ a^-1 \in 'C[y]. rewrite -mem_conjg -normJ conjg_set1 -zp_ya. by apply/cent1P; apply: commuteX. have Nz: z ^ a^-1 \in 'N(<[y]>) by apply: subsetP czy; apply: norm_gen. have G'z: h z \in G' by rewrite mem_morphim //= inE groupJ // groupV. rewrite inE G'z inE -order_dvdn dvdn_gcd order_dvdG //=. rewrite /order -morphim_cycle // -quotientE card_quotient ?cycle_subG //. rewrite -(@dvdn_pmul2l #[y]) // Lagrange; last first. by rewrite /= cycleJ cycle_subG mem_conjgV -zp_ya mem_cycle. rewrite oy mulnAC partnC // [#|_|]orderJ; split. by rewrite !inE -!order_dvdn mulnC in Az; case/andP: Az. set Z := coset _ _; have NZ := repr_coset_norm Z; have:= coset_reprK Z. case/kercoset_rcoset=> {NZ}// _ /cycleP[i ->] ->{Z}. rewrite consttM; last exact/commute_sym/commuteX/cent1P. rewrite (constt1P _) ?p_eltNK 1?p_eltX ?p_elt_constt // mul1g. by rewrite conjMg consttJ conjgKV -zp_ya consttC. rewrite 2!inE -order_dvdn; set Z := coset _ _ => /andP[Cz n'Z] /eqP def_z. have Nz: z ^ a^-1 \in 'N(<[y]>). rewrite -def_z conjgK groupMr; first by rewrite -(cycle_subG y) normG. by rewrite groupX ?repr_coset_norm. have{Cz} /setIP[Gz Cz]: z ^ a^-1 \in 'C_G[y]. case/morphimP: Cz => u Nu Cu /kercoset_rcoset[] // _ /cycleP[i ->] ->. by rewrite groupMr // groupX // inE groupX //; apply/cent1P. have{def_z} zp_ya: z.`_p = y ^ a. rewrite -def_z consttJ consttM. rewrite constt_p_elt ?p_elt_constt //. by rewrite (constt1P _) ?p_eltNK ?p_elt_constt ?mulg1. apply: commute_sym; apply/cent1P. by rewrite -def_z conjgK groupMl // in Cz; apply/cent1P. have ozp: #[z ^ a^-1]`_p = #[y] by rewrite -order_constt consttJ zp_ya conjgK. split; rewrite zp_ya // -class_lcoset lcoset_id // eqxx andbT. rewrite -(conjgKV a z) !inE groupJ //= -!order_dvdn orderJ; apply/andP; split. apply: contra (partn_dvd p n_gt0) _. by rewrite ozp -(muln1 n`_p) oy dvdn_pmul2l // dvdn1 neq_ltn lt1p orbT. rewrite -(partnC p n_gt0) mulnCA mulnA -oy -(@partnC p #[_]) // ozp. apply dvdn_mul => //; apply: dvdn_trans (dvdn_trans n'Z (dvdn_gcdr _ _)). rewrite {2}/order -morphim_cycle // -quotientE card_quotient ?cycle_subG //. rewrite -(@dvdn_pmul2l #|<[z ^ a^-1]> :&: <[y]>|) ?cardG_gt0 // LagrangeI. rewrite -[#|<[_]>|](partnC p) ?order_gt0 // dvdn_pmul2r // ozp. by rewrite cardSg ?subsetIr. Qed.