diff --git a/Cubical/Algebra/CommRing/Instances/Fast/Int.agda b/Cubical/Algebra/CommRing/Instances/Fast/Int.agda index e01dde2d62..eddd1e13e9 100644 --- a/Cubical/Algebra/CommRing/Instances/Fast/Int.agda +++ b/Cubical/Algebra/CommRing/Instances/Fast/Int.agda @@ -1,8 +1,12 @@ module Cubical.Algebra.CommRing.Instances.Fast.Int where open import Cubical.Foundations.Prelude +open import Cubical.Foundations.Function +open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing + +open import Cubical.Data.Nat as ℕ using (ℕ ; zero ; suc) open import Cubical.Data.Fast.Int as Int renaming (_+_ to _+ℤ_; _·_ to _·ℤ_ ; -_ to -ℤ_) open CommRingStr using (0r ; 1r ; _+_ ; _·_ ; -_ ; isCommRing) @@ -21,3 +25,113 @@ isCommRing (snd ℤCommRing) = isCommRingℤ isCommRingℤ = makeIsCommRing isSetℤ Int.+Assoc +IdR -Cancel Int.+Comm Int.·Assoc Int.·IdR ·DistR+ Int.·Comm + +private + variable + ℓ : Level + +module CanonicalHomFromℤ (R : CommRing ℓ) where + + private + module R where + open CommRingStr (snd R) public + open RingTheory (CommRing→Ring R) public + + suc-fromℕ : ∀ x → R.fromℕ (suc x) ≡ R.1r R.+ R.fromℕ x + suc-fromℕ zero = sym (R.+IdR R.1r) + suc-fromℕ (suc x) = refl + + fromℕ-pres+ : (x y : ℕ) → R.fromℕ (x ℕ.+ y) ≡ R.fromℕ x R.+ R.fromℕ y + fromℕ-pres+ zero y = sym (R.+IdL _) + fromℕ-pres+ (suc zero) y = suc-fromℕ y + fromℕ-pres+ (suc (suc x)) y = cong (R.1r R.+_) (fromℕ-pres+ (suc x) y) ∙ R.+Assoc _ _ _ + + fromℤ-pres- : (x : ℤ) → R.fromℤ (-ℤ x) ≡ R.- R.fromℤ x + fromℤ-pres- (pos zero) = sym R.0Selfinverse + fromℤ-pres- (pos (suc n)) = refl + fromℤ-pres- (negsuc n) = sym (R.-Idempotent _) + + suc-fromℤ : ∀ z → R.fromℤ (1 +ℤ z) ≡ R.1r R.+ R.fromℤ (z) + suc-fromℤ (pos n) = suc-fromℕ n + suc-fromℤ (negsuc zero) = sym (R.+InvR R.1r) + suc-fromℤ (negsuc (suc n)) = + sym (cong (R._+ (R.- R.fromℕ (suc n))) (R.+InvR _) ∙ R.+IdL _) + ∙∙ sym (R.+Assoc _ _ _) + ∙∙ cong (R.1r R.+_) (R.-Dist _ _) + + fromℤ-pres+' : (n m : ℕ) → + R.fromℤ (pos n +ℤ negsuc m) ≡ + R.fromℤ (pos n) R.+ R.fromℤ (negsuc m) + fromℤ-pres+' zero m = sym (R.+IdL _) + fromℤ-pres+' (suc n) m = + (cong R.fromℤ (sym (+Assoc 1 (pos n) (negsuc m))) + ∙ suc-fromℤ (pos n +ℤ negsuc m)) + ∙∙ cong (R.1r R.+_) (fromℤ-pres+' n m) + ∙∙ R.+Assoc _ _ _ + ∙ cong (R._+ R.fromℤ (negsuc m)) + (sym (suc-fromℕ n)) + + fromℤ-pres+ : (x y : ℤ) → R.fromℤ (x +ℤ y) ≡ R.fromℤ x R.+ R.fromℤ y + fromℤ-pres+ (pos n) (pos m) = fromℕ-pres+ n m + fromℤ-pres+ (pos n) (negsuc m) = fromℤ-pres+' n m + fromℤ-pres+ (negsuc n) (pos m) = fromℤ-pres+' m n ∙ R.+Comm _ _ + fromℤ-pres+ (negsuc n) (negsuc m) = + cong (R.-_) + (cong (R.1r R.+_) (cong R.fromℕ (sym (ℕ.+-suc n m))) + ∙ sym (suc-fromℕ (n ℕ.+ suc m)) + ∙ fromℕ-pres+ (suc n) (suc m)) + ∙ sym (R.-Dist _ _) + + fromℕ-pres· : (x y : ℕ) → R.fromℕ (x ℕ.· y) ≡ R.fromℕ x R.· R.fromℕ y + fromℕ-pres· zero y = sym (R.0LeftAnnihilates _) + fromℕ-pres· (suc x) y = + fromℕ-pres+ y (x ℕ.· y) + ∙∙ cong₂ (R._+_) (sym (R.·IdL _)) (fromℕ-pres· x y) + ∙∙ sym (R.·DistL+ _ _ _) + ∙ cong (R._· R.fromℕ y) (sym (suc-fromℕ x)) + fromℤ-pres· : (x y : ℤ) → R.fromℤ (x ·ℤ y) ≡ R.fromℤ x R.· R.fromℤ y + fromℤ-pres· (pos n) (pos m) = fromℕ-pres· n m + fromℤ-pres· (pos n) (negsuc m) = + cong R.fromℤ (sym (-DistR· (pos n) (pos (suc m)))) + ∙∙ (fromℤ-pres- (pos (n ℕ.· suc m)) + ∙ cong R.-_ (fromℕ-pres· n (suc m))) + ∙∙ sym (R.-DistR· _ _) + fromℤ-pres· (negsuc n) (pos m) = + cong R.fromℤ (sym (-DistL· (pos (suc n)) (pos m))) + ∙∙ (fromℤ-pres- (pos ((suc n) ℕ.· m)) + ∙ cong R.-_ (fromℕ-pres· (suc n) m)) + ∙∙ sym (R.-DistL· _ _) + fromℤ-pres· (negsuc n) (negsuc m) = + fromℕ-pres· (suc n) (suc m) + ∙∙ cong₂ R._·_ (sym (R.-Idempotent _)) refl + ∙∙ R.-Swap· _ _ + + isHomFromℤ : IsCommRingHom (ℤCommRing .snd) R.fromℤ (R .snd) + isHomFromℤ .IsCommRingHom.pres0 = refl + isHomFromℤ .IsCommRingHom.pres1 = refl + isHomFromℤ .IsCommRingHom.pres+ = fromℤ-pres+ + isHomFromℤ .IsCommRingHom.pres· = fromℤ-pres· + isHomFromℤ .IsCommRingHom.pres- = fromℤ-pres- + + fromℤHom : CommRingHom ℤCommRing R + fst fromℤHom = R.fromℤ + snd fromℤHom = isHomFromℤ + + module _ (φ : CommRingHom ℤCommRing R) where + + open IsCommRingHom (snd φ) + + isUniqueFromℕ : ∀ n → R.fromℕ n ≡ φ $cr pos n + isUniqueFromℕ zero = sym pres0 + isUniqueFromℕ (suc zero) = sym pres1 + isUniqueFromℕ (suc k@(suc n)) = cong₂ R._+_ (sym pres1) (isUniqueFromℕ k) + ∙ sym (pres+ 1 (pos k)) + + isUniqueFromℤ : ∀ n → R.fromℤ n ≡ φ $cr n + isUniqueFromℤ (pos n) = isUniqueFromℕ n + isUniqueFromℤ (negsuc n) = cong R.-_ (isUniqueFromℕ (suc n)) + ∙ sym (pres- (pos (suc n))) + + isContrHom[ℤCR,-] : isContr (CommRingHom ℤCommRing R) + fst isContrHom[ℤCR,-] = fromℤHom + snd isContrHom[ℤCR,-] = CommRingHom≡ ∘ funExt ∘ isUniqueFromℤ diff --git a/Cubical/Algebra/OrderedCommRing.agda b/Cubical/Algebra/OrderedCommRing.agda index 2aca413aff..ba0a384be4 100644 --- a/Cubical/Algebra/OrderedCommRing.agda +++ b/Cubical/Algebra/OrderedCommRing.agda @@ -1,3 +1,4 @@ module Cubical.Algebra.OrderedCommRing where open import Cubical.Algebra.OrderedCommRing.Base public +open import Cubical.Algebra.OrderedCommRing.Properties public diff --git a/Cubical/Algebra/OrderedCommRing/Base.agda b/Cubical/Algebra/OrderedCommRing/Base.agda index 29cd5dbb4b..0bf5ca7948 100644 --- a/Cubical/Algebra/OrderedCommRing/Base.agda +++ b/Cubical/Algebra/OrderedCommRing/Base.agda @@ -4,20 +4,25 @@ module Cubical.Algebra.OrderedCommRing.Base where -} open import Cubical.Foundations.Prelude +open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv +open import Cubical.Foundations.HLevels open import Cubical.Foundations.SIP +open import Cubical.Algebra.CommRing.Base + import Cubical.Functions.Logic as L -open import Cubical.Relation.Nullary.Base +open import Cubical.HITs.PropositionalTruncation as PT -open import Cubical.Algebra.CommRing.Base +open import Cubical.Reflection.RecordEquiv open import Cubical.Relation.Binary.Base -open import Cubical.Relation.Binary.Order.Poset hiding (isPseudolattice) -open import Cubical.Relation.Binary.Order.StrictOrder - +open import Cubical.Relation.Binary.Order.Poset hiding ( + isPseudolattice ; isPropIsPseudolattice) open import Cubical.Relation.Binary.Order.Pseudolattice +open import Cubical.Relation.Binary.Order.StrictOrder +open import Cubical.Relation.Nullary open BinaryRelation @@ -53,6 +58,8 @@ record IsOrderedCommRing ; _∧l_ to _⊓_ ; _∨l_ to _⊔_) public open IsStrictOrder isStrictOrder hiding (is-set) renaming (is-prop-valued to is-prop-valued< ; is-trans to is-trans<) public +unquoteDecl IsOrderedCommRingIsoΣ = declareRecordIsoΣ IsOrderedCommRingIsoΣ (quote IsOrderedCommRing) + record OrderedCommRingStr (ℓ' : Level) (R : Type ℓ) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where constructor orderedcommringstr field @@ -134,3 +141,26 @@ OrderedCommRing→CommRing : OrderedCommRing ℓ ℓ' → CommRing ℓ OrderedCommRing→CommRing R .fst = R .fst OrderedCommRing→CommRing R .snd = commringstr _ _ _ _ _ isCommRing where open OrderedCommRingStr (str R) + +isPropIsOrderedCommRing : {R : Type ℓ} + → (0r 1r : R) + → (_+_ _·_ : R → R → R) (-_ : R → R) + → (_<_ _≤_ : R → R → Type ℓ') + → isProp (IsOrderedCommRing 0r 1r _+_ _·_ -_ _<_ _≤_) +isPropIsOrderedCommRing 0r 1r _+_ _·_ -_ _<_ _≤_ = isOfHLevelRetractFromIso 1 + IsOrderedCommRingIsoΣ $ + isPropΣ (isPropIsCommRing _ _ _ _ _) λ isCR → + isPropΣ (isPropIsPseudolattice _) λ isPL → + isPropΣ (isPropIsStrictOrder _) λ isSO → + isProp× (isPropΠ3 λ _ _ _ → isPL .IsPseudolattice.is-prop-valued _ _) $ + isProp× (isPropΠ2 λ x y → isOfHLevel≃ 1 + (IsPoset.is-prop-valued (IsPseudolattice.isPoset isPL) x y) + (isProp¬ (y < x))) $ + isProp× (isPropΠ4 λ _ _ _ _ → isPL .IsPseudolattice.is-prop-valued _ _) $ + isProp× (isPropΠ4 λ _ _ _ _ → isSO .IsStrictOrder.is-prop-valued _ _) $ + isProp× (isPropΠ3 λ _ _ _ → PT.squash₁) $ + isProp× (isPropΠ5 λ _ _ _ _ _ → isSO .IsStrictOrder.is-prop-valued _ _) $ + isProp× (isPropΠ5 λ _ _ _ _ _ → isSO .IsStrictOrder.is-prop-valued _ _) $ + isProp× (isPropΠ5 λ _ _ _ _ _ → isPL .IsPseudolattice.is-prop-valued _ _) $ + isProp× (isPropΠ5 λ _ _ _ _ _ → isSO .IsStrictOrder.is-prop-valued _ _) + (isSO .IsStrictOrder.is-prop-valued _ _) diff --git a/Cubical/Algebra/OrderedCommRing/Instances/Fast/Int.agda b/Cubical/Algebra/OrderedCommRing/Instances/Fast/Int.agda index 45a38d41c6..93163da4ef 100644 --- a/Cubical/Algebra/OrderedCommRing/Instances/Fast/Int.agda +++ b/Cubical/Algebra/OrderedCommRing/Instances/Fast/Int.agda @@ -8,15 +8,20 @@ open import Cubical.Data.Empty as ⊥ open import Cubical.HITs.PropositionalTruncation +open import Cubical.Data.Nat as ℕ using (ℕ ; zero ; suc) +open import Cubical.Data.Nat.Order as ℕ using () renaming (_≤_ to _≤ℕ_ ; _<_ to _<ℕ_) +import Cubical.Data.Nat.Order.Inductive as ℕ open import Cubical.Data.Fast.Int as ℤ renaming (_+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_) open import Cubical.Data.Fast.Int.Order renaming (_<_ to _<ℤ_ ; _≤_ to _≤ℤ_) +open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Instances.Fast.Int open import Cubical.Algebra.OrderedCommRing +open import Cubical.Algebra.OrderedCommRing.Morphisms open import Cubical.Relation.Nullary @@ -64,3 +69,100 @@ isOrderedCommRing (snd ℤOrderedCommRing) = isOrderedCommRingℤ isOrderedCommRingℤ .·MonoR≤ = λ _ _ _ → 0≤o→≤-·o isOrderedCommRingℤ .·MonoR< = λ _ _ _ → 0n = ⊥.rec (R.is-asym _ _ fmn)) + + isOCRHomFromℤ : IsOrderedCommRingHom (snd ℤOrderedCommRing) R.fromℤ (snd R) + isOCRHomFromℤ .IsOrderedCommRingHom.isCommRingHom = isHomFromℤ + isOCRHomFromℤ .IsOrderedCommRingHom.pres≤ = fromℤ-pres≤ + isOCRHomFromℤ .IsOrderedCommRingHom.reflect< = fromℤ-reflect< + + isOCRMonoFromℤ : IsOrderedCommRingMono (snd ℤOrderedCommRing) R.fromℤ (snd R) + isOCRMonoFromℤ .IsOrderedCommRingMono.isOrderedCommRingHom = isOCRHomFromℤ + isOCRMonoFromℤ .IsOrderedCommRingMono.pres< = fromℤ-pres< + + fromℤOCR : OrderedCommRingHom ℤOrderedCommRing R + fst fromℤOCR = R.fromℤ + snd fromℤOCR = isOCRHomFromℤ + + fromℤOCRMono : OrderedCommRingMono ℤOrderedCommRing R + fst fromℤOCRMono = R.fromℤ + snd fromℤOCRMono = isOCRMonoFromℤ + + isUniqueFromℤOCR : (φ : OrderedCommRingHom ℤOrderedCommRing R) + → ∀ n → R.fromℤ n ≡ fst φ n + isUniqueFromℤOCR = isUniqueFromℤ ∘ OrderedCommRingHom→CommRingHom + + isUniqueFromℤOCRMono : (φ : OrderedCommRingMono ℤOrderedCommRing R) + → ∀ n → R.fromℤ n ≡ fst φ n + isUniqueFromℤOCRMono = isUniqueFromℤ ∘ OrderedCommRingMono→CommRingHom + + isContrHom[ℤOCR,-] : isContr (OrderedCommRingHom ℤOrderedCommRing R) + fst isContrHom[ℤOCR,-] = fromℤOCR + snd isContrHom[ℤOCR,-] = OrderedCommRingHom≡ ∘ funExt ∘ isUniqueFromℤOCR + + isContrMono[ℤOCR,-] : isContr (OrderedCommRingMono ℤOrderedCommRing R) + fst isContrMono[ℤOCR,-] = fromℤOCRMono + snd isContrMono[ℤOCR,-] = OrderedCommRingMono≡ ∘ funExt ∘ isUniqueFromℤOCRMono diff --git a/Cubical/Algebra/OrderedCommRing/Morphisms.agda b/Cubical/Algebra/OrderedCommRing/Morphisms.agda new file mode 100644 index 0000000000..09bb5c8684 --- /dev/null +++ b/Cubical/Algebra/OrderedCommRing/Morphisms.agda @@ -0,0 +1,372 @@ +module Cubical.Algebra.OrderedCommRing.Morphisms where + +open import Cubical.Foundations.Prelude +open import Cubical.Foundations.Function +open import Cubical.Foundations.Equiv +open import Cubical.Foundations.HLevels +open import Cubical.Foundations.SIP + +open import Cubical.Algebra.CommRing.Base +open import Cubical.Algebra.OrderedCommRing.Base + +open import Cubical.Data.Sigma + +open import Cubical.Reflection.RecordEquiv + +private + variable + ℓ ℓ' ℓ<≤ ℓ<≤' : Level + +record IsOrderedCommRingHom {A : Type ℓ} {B : Type ℓ'} + (R : OrderedCommRingStr ℓ<≤ A) + (f : A → B) + (S : OrderedCommRingStr ℓ<≤' B) + : Type (ℓ-max ℓ (ℓ-max ℓ' (ℓ-max ℓ<≤ ℓ<≤'))) + where + no-eta-equality + private + module R = OrderedCommRingStr R + module S = OrderedCommRingStr S + Rcring = str (OrderedCommRing→CommRing (_ , R)) + Scring = str (OrderedCommRing→CommRing (_ , S)) + + field + isCommRingHom : IsCommRingHom Rcring f Scring + pres≤ : ∀ x y → x R.≤ y → f x S.≤ f y + reflect< : ∀ x y → f x S.< f y → x R.< y + + open IsCommRingHom isCommRingHom public + +unquoteDecl IsOrderedCommRingHomIsoΣ = declareRecordIsoΣ IsOrderedCommRingHomIsoΣ (quote IsOrderedCommRingHom) + +OrderedCommRingHom : OrderedCommRing ℓ ℓ<≤ → OrderedCommRing ℓ' ℓ<≤' → Type _ +OrderedCommRingHom R S = + Σ[ f ∈ (⟨ R ⟩ → ⟨ S ⟩) ] IsOrderedCommRingHom (R .snd) f (S .snd) + +isPropIsOrderedCommRingHom : {A : Type ℓ} {B : Type ℓ'} + → (R : OrderedCommRingStr ℓ<≤ A) + → (f : A → B) + → (S : OrderedCommRingStr ℓ<≤' B) + → isProp (IsOrderedCommRingHom R f S) +isPropIsOrderedCommRingHom R f S = isOfHLevelRetractFromIso 1 + IsOrderedCommRingHomIsoΣ $ + isProp×2 (isPropIsCommRingHom _ f _) + (isPropΠ2 λ _ _ → isProp→ (S.is-prop-valued≤ _ _)) + (isPropΠ2 λ _ _ → isProp→ (R.is-prop-valued< _ _)) + where + open module R = OrderedCommRingStr R + open module S = OrderedCommRingStr S + +isSetOrderedCommRingHom : (R : OrderedCommRing ℓ ℓ<≤) (S : OrderedCommRing ℓ' ℓ<≤') + → isSet (OrderedCommRingHom R S) +isSetOrderedCommRingHom R S = isSetΣSndProp (isSetΠ λ _ → is-set) (λ f → + isPropIsOrderedCommRingHom (snd R) f (snd S)) + where open OrderedCommRingStr (str S) using (is-set) + +module _ + {R : OrderedCommRing ℓ ℓ<≤} + {S : OrderedCommRing ℓ' ℓ<≤'} + {f : ⟨ R ⟩ → ⟨ S ⟩} where + + private + module R = OrderedCommRingStr (str R) + module S = OrderedCommRingStr (str S) + RCR = OrderedCommRing→CommRing R + SCR = OrderedCommRing→CommRing S + + module _ + (p1 : f R.1r ≡ S.1r) + (p+ : ∀ x y → f (x R.+ y) ≡ f x S.+ f y) + (p· : ∀ x y → f (x R.· y) ≡ f x S.· f y) + (p<⁻ : ∀ x y → f x S.< f y → x R.< y) + where + + open IsOrderedCommRingHom + + private + p≤ : ∀ x y → x R.≤ y → f x S.≤ f y + p≤ x y = invEq (S.≤≃¬> (f x) (f y)) ∘ (_∘ p<⁻ y x) ∘ equivFun (R.≤≃¬> x y) + + makeIsOrderedCommRingHom : IsOrderedCommRingHom (str R) f (str S) + makeIsOrderedCommRingHom .isCommRingHom = makeIsCommRingHom p1 p+ p· + makeIsOrderedCommRingHom .pres≤ = p≤ + makeIsOrderedCommRingHom .reflect< = p<⁻ + + module _ (isHomf : IsOrderedCommRingHom (str R) f (str S)) where + + isOrderedCommRingHom→IsCommRingHom : IsCommRingHom (str RCR) f (str SCR) + isOrderedCommRingHom→IsCommRingHom = isCommRingHom + where open IsOrderedCommRingHom isHomf + +OrderedCommRingHom→CommRingHom : {A : OrderedCommRing ℓ ℓ<≤} + → {B : OrderedCommRing ℓ' ℓ<≤'} + → OrderedCommRingHom A B + → CommRingHom + (OrderedCommRing→CommRing A) + (OrderedCommRing→CommRing B) +fst (OrderedCommRingHom→CommRingHom f) = fst f +snd (OrderedCommRingHom→CommRingHom f) = isOrderedCommRingHom→IsCommRingHom (snd f) + +_$ocr_ : {R : OrderedCommRing ℓ ℓ<≤} {S : OrderedCommRing ℓ' ℓ<≤'} + → (φ : OrderedCommRingHom R S) → (x : ⟨ R ⟩) → ⟨ S ⟩ +φ $ocr x = φ .fst x + +opaque + OrderedCommRingHom≡ : {R : OrderedCommRing ℓ ℓ<≤} {S : OrderedCommRing ℓ' ℓ<≤'} + → {φ ψ : OrderedCommRingHom R S} + → fst φ ≡ fst ψ + → φ ≡ ψ + OrderedCommRingHom≡ = Σ≡Prop λ f → isPropIsOrderedCommRingHom _ f _ + + OrderedCommRingHomPathP : (R : OrderedCommRing ℓ ℓ<≤) (S T : OrderedCommRing ℓ' ℓ<≤') + → (p : S ≡ T) + → (φ : OrderedCommRingHom R S) + → (ψ : OrderedCommRingHom R T) + → PathP (λ i → R .fst → p i .fst) (φ .fst) (ψ .fst) + → PathP (λ i → OrderedCommRingHom R (p i)) φ ψ + OrderedCommRingHomPathP R S T p φ ψ q = ΣPathP (q , isProp→PathP (λ _ → + isPropIsOrderedCommRingHom _ _ _) _ _) + +record IsOrderedCommRingMono {A : Type ℓ} {B : Type ℓ'} + (R : OrderedCommRingStr ℓ<≤ A) + (f : A → B) + (S : OrderedCommRingStr ℓ<≤' B) + : Type (ℓ-max ℓ (ℓ-max ℓ' (ℓ-max ℓ<≤ ℓ<≤'))) + where + no-eta-equality + private + module R = OrderedCommRingStr R + module S = OrderedCommRingStr S + + field + isOrderedCommRingHom : IsOrderedCommRingHom R f S + pres< : (x y : A) → x R.< y → f x S.< f y + + open IsOrderedCommRingHom isOrderedCommRingHom public + +unquoteDecl IsOrderedCommRingMonoIsoΣ = declareRecordIsoΣ IsOrderedCommRingMonoIsoΣ (quote IsOrderedCommRingMono) + +OrderedCommRingMono : OrderedCommRing ℓ ℓ<≤ → OrderedCommRing ℓ' ℓ<≤' → Type _ +OrderedCommRingMono R S = + Σ[ f ∈ (⟨ R ⟩ → ⟨ S ⟩) ] IsOrderedCommRingMono (R .snd) f (S .snd) + +OrderedCommRingMono→OrderedCommRingHom : {A : OrderedCommRing ℓ ℓ<≤} + → {B : OrderedCommRing ℓ' ℓ<≤'} + → OrderedCommRingMono A B + → OrderedCommRingHom A B +fst (OrderedCommRingMono→OrderedCommRingHom f) = fst f +snd (OrderedCommRingMono→OrderedCommRingHom f) = isOrderedCommRingHom + where open IsOrderedCommRingMono (snd f) + +OrderedCommRingMono→CommRingHom : {A : OrderedCommRing ℓ ℓ<≤} + → {B : OrderedCommRing ℓ' ℓ<≤'} + → OrderedCommRingMono A B + → CommRingHom + (OrderedCommRing→CommRing A) + (OrderedCommRing→CommRing B) +OrderedCommRingMono→CommRingHom = + OrderedCommRingHom→CommRingHom ∘ OrderedCommRingMono→OrderedCommRingHom + +isPropIsOrderedCommRingMono : {A : Type ℓ} {B : Type ℓ'} + → (R : OrderedCommRingStr ℓ<≤ A) + → (f : A → B) + → (S : OrderedCommRingStr ℓ<≤' B) + → isProp (IsOrderedCommRingMono R f S) +isPropIsOrderedCommRingMono R f S = isOfHLevelRetractFromIso 1 + IsOrderedCommRingMonoIsoΣ $ + isProp× (isPropIsOrderedCommRingHom R f S) + (isPropΠ2 λ _ _ → isProp→ (S.is-prop-valued< _ _)) + where + open module S = OrderedCommRingStr S + +isSetOrderedCommRingMono : (R : OrderedCommRing ℓ ℓ<≤) (S : OrderedCommRing ℓ' ℓ<≤') + → isSet (OrderedCommRingMono R S) +isSetOrderedCommRingMono R S = isSetΣSndProp (isSetΠ λ _ → is-set) (λ f → + isPropIsOrderedCommRingMono (snd R) f (snd S)) + where open OrderedCommRingStr (str S) using (is-set) + +module _ + {R : OrderedCommRing ℓ ℓ<≤} + {S : OrderedCommRing ℓ' ℓ<≤'} + {f : ⟨ R ⟩ → ⟨ S ⟩} where + + private + module R = OrderedCommRingStr (str R) + module S = OrderedCommRingStr (str S) + + module _ + (p1 : f R.1r ≡ S.1r) + (p+ : ∀ x y → f (x R.+ y) ≡ f x S.+ f y) + (p· : ∀ x y → f (x R.· y) ≡ f x S.· f y) + (p< : ∀ x y → x R.< y → f x S.< f y) + (p<⁻ : ∀ x y → f x S.< f y → x R.< y) + where + + open IsOrderedCommRingMono + + makeIsOrderedCommRingMono : IsOrderedCommRingMono (str R) f (str S) + makeIsOrderedCommRingMono .isOrderedCommRingHom = makeIsOrderedCommRingHom p1 p+ p· p<⁻ + makeIsOrderedCommRingMono .pres< = p< + + module _ (isMonof : IsOrderedCommRingMono (str R) f (str S)) where + + isOrderedCommRingMono→reflect≤ : ∀ x y → f x S.≤ f y → x R.≤ y + isOrderedCommRingMono→reflect≤ x y = + invEq (R.≤≃¬> x y) ∘ (_∘ pres< y x) ∘ equivFun (S.≤≃¬> (f x) (f y)) + where open IsOrderedCommRingMono isMonof + + isOrderedCommRingMono→isOrderedCommRingHom : IsOrderedCommRingHom (str R) f (str S) + isOrderedCommRingMono→isOrderedCommRingHom = isOrderedCommRingHom + where open IsOrderedCommRingMono isMonof + + isOrderedCommRingMono→isInjective : ∀ x y → f x ≡ f y → x ≡ y + isOrderedCommRingMono→isInjective x y fx≡fy = R.is-antisym x y + (isOrderedCommRingMono→reflect≤ x y (subst (S._≤_ (f x)) fx≡fy (S.is-refl _))) + (isOrderedCommRingMono→reflect≤ y x (subst (S._≤_ (f y)) (sym fx≡fy) (S.is-refl _))) + +opaque + OrderedCommRingMono≡ : {R : OrderedCommRing ℓ ℓ<≤} {S : OrderedCommRing ℓ' ℓ<≤'} + → {φ ψ : OrderedCommRingMono R S} + → fst φ ≡ fst ψ + → φ ≡ ψ + OrderedCommRingMono≡ = Σ≡Prop λ f → isPropIsOrderedCommRingMono _ f _ + + OrderedCommRingMonoPathP : (R : OrderedCommRing ℓ ℓ<≤) (S T : OrderedCommRing ℓ' ℓ<≤') + → (p : S ≡ T) + → (φ : OrderedCommRingMono R S) + → (ψ : OrderedCommRingMono R T) + → PathP (λ i → R .fst → p i .fst) (φ .fst) (ψ .fst) + → PathP (λ i → OrderedCommRingMono R (p i)) φ ψ + OrderedCommRingMonoPathP R S T p φ ψ q = ΣPathP (q , isProp→PathP (λ _ → + isPropIsOrderedCommRingMono _ _ _) _ _) + +record IsOrderedCommRingEquiv {A : Type ℓ} {B : Type ℓ'} + (R : OrderedCommRingStr ℓ<≤ A) (e : A ≃ B) (S : OrderedCommRingStr ℓ<≤' B) + : Type (ℓ-max (ℓ-max (ℓ-max ℓ ℓ<≤) ℓ') ℓ<≤') + where + no-eta-equality + private + module R = OrderedCommRingStr R + module S = OrderedCommRingStr S + Rcring = str (OrderedCommRing→CommRing (_ , R)) + Scring = str (OrderedCommRing→CommRing (_ , S)) + f = equivFun e + + field + pres0 : f R.0r ≡ S.0r + pres1 : f R.1r ≡ S.1r + pres+ : (x y : A) → f (x R.+ y) ≡ f x S.+ f y + pres· : (x y : A) → f (x R.· y) ≡ f x S.· f y + pres- : (x : A) → f (R.- x) ≡ S.- (f x) + pres≤ : (x y : A) → (x R.≤ y) ≃ (f x S.≤ f y) + pres< : (x y : A) → (x R.< y) ≃ (f x S.< f y) + +unquoteDecl IsOrderedCommRingEquivIsoΣ = declareRecordIsoΣ IsOrderedCommRingEquivIsoΣ (quote IsOrderedCommRingEquiv) + +OrderedCommRingEquiv : OrderedCommRing ℓ ℓ<≤ → OrderedCommRing ℓ' ℓ<≤' → Type _ +OrderedCommRingEquiv R S = + Σ[ e ∈ (R .fst ≃ S .fst) ] IsOrderedCommRingEquiv (R .snd) e (S .snd) + + +OrderedCommRingEquiv→OrderedCommRingMono : {A : OrderedCommRing ℓ ℓ<≤} + → {B : OrderedCommRing ℓ' ℓ<≤'} + → OrderedCommRingEquiv A B + → OrderedCommRingMono A B +fst (OrderedCommRingEquiv→OrderedCommRingMono e) = equivFun (fst e) +snd (OrderedCommRingEquiv→OrderedCommRingMono e) = isOCRMono + where + module E = IsOrderedCommRingEquiv (snd e) + open IsCommRingHom + open IsOrderedCommRingHom renaming (isCommRingHom to isCRHom) + open IsOrderedCommRingMono renaming (isOrderedCommRingHom to isOCRHom) + + isOCRMono : IsOrderedCommRingMono _ _ _ + isOCRMono .isOCRHom .isCRHom .pres0 = E.pres0 + isOCRMono .isOCRHom .isCRHom .pres1 = E.pres1 + isOCRMono .isOCRHom .isCRHom .pres+ = E.pres+ + isOCRMono .isOCRHom .isCRHom .pres· = E.pres· + isOCRMono .isOCRHom .isCRHom .pres- = E.pres- + isOCRMono .isOCRHom .pres≤ = (equivFun ∘_) ∘ E.pres≤ + isOCRMono .isOCRHom .reflect< = (invEq ∘_) ∘ E.pres< + isOCRMono .pres< = (equivFun ∘_) ∘ E.pres< + +OrderedCommRingEquiv→OrderedCommRingHom : {A : OrderedCommRing ℓ ℓ<≤} + → {B : OrderedCommRing ℓ' ℓ<≤'} + → OrderedCommRingEquiv A B + → OrderedCommRingHom A B +OrderedCommRingEquiv→OrderedCommRingHom = + OrderedCommRingMono→OrderedCommRingHom ∘ OrderedCommRingEquiv→OrderedCommRingMono + +OrderedCommRingEquiv→CommRingHom : {A : OrderedCommRing ℓ ℓ<≤} + → {B : OrderedCommRing ℓ' ℓ<≤'} + → OrderedCommRingEquiv A B + → CommRingHom + (OrderedCommRing→CommRing A) + (OrderedCommRing→CommRing B) +OrderedCommRingEquiv→CommRingHom = + OrderedCommRingHom→CommRingHom ∘ OrderedCommRingEquiv→OrderedCommRingHom + +isPropIsOrderedCommRingEquiv : {A : Type ℓ} {B : Type ℓ'} + → (R : OrderedCommRingStr ℓ<≤ A) + → (e : A ≃ B) + → (S : OrderedCommRingStr ℓ<≤' B) + → isProp (IsOrderedCommRingEquiv R e S) +isPropIsOrderedCommRingEquiv R e S = isOfHLevelRetractFromIso 1 + IsOrderedCommRingEquivIsoΣ $ + isProp× (S.is-set _ _) $ + isProp× (S.is-set _ _) $ + isProp× (isPropΠ2 λ _ _ → S.is-set _ _) $ + isProp× (isPropΠ2 λ _ _ → S.is-set _ _) $ + isProp× (isPropΠ λ _ → S.is-set _ _) $ + isProp× (isPropΠ2 λ _ _ → isOfHLevel≃ 1 (R.is-prop-valued≤ _ _) (S.is-prop-valued≤ _ _)) + (isPropΠ2 λ _ _ → isOfHLevel≃ 1 (R.is-prop-valued< _ _) (S.is-prop-valued< _ _)) + where + open module R = OrderedCommRingStr R + open module S = OrderedCommRingStr S + +isSetOrderedCommRingEquiv : (R : OrderedCommRing ℓ ℓ<≤) (S : OrderedCommRing ℓ' ℓ<≤') + → isSet (OrderedCommRingEquiv R S) +isSetOrderedCommRingEquiv R S = isSetΣSndProp (isOfHLevel≃ 2 R.is-set S.is-set) (λ e → + isPropIsOrderedCommRingEquiv (snd R) e (snd S)) + where + open module R = OrderedCommRingStr (str R) + open module S = OrderedCommRingStr (str S) + +-- an easier way of establishing an equivalence of ordered commutative rings +module _ {R : OrderedCommRing ℓ ℓ<≤} {S : OrderedCommRing ℓ' ℓ<≤'} (e : ⟨ R ⟩ ≃ ⟨ S ⟩) + where + private + module R = OrderedCommRingStr (str R) + module S = OrderedCommRingStr (str S) + + module _ (isMono : IsOrderedCommRingMono (str R) (equivFun e) (str S)) where + + private + module M = IsOrderedCommRingMono isMono + + open IsOrderedCommRingEquiv + + makeIsOrderedCommRingEquivFromIsMono : IsOrderedCommRingEquiv (str R) e (str S) + makeIsOrderedCommRingEquivFromIsMono .pres0 = M.pres0 + makeIsOrderedCommRingEquivFromIsMono .pres1 = M.pres1 + makeIsOrderedCommRingEquivFromIsMono .pres+ = M.pres+ + makeIsOrderedCommRingEquivFromIsMono .pres· = M.pres· + makeIsOrderedCommRingEquivFromIsMono .pres- = M.pres- + makeIsOrderedCommRingEquivFromIsMono .pres≤ = λ x y → propBiimpl→Equiv + (R.is-prop-valued≤ _ _) (S.is-prop-valued≤ _ _) + (M.pres≤ x y) (isOrderedCommRingMono→reflect≤ isMono x y) + makeIsOrderedCommRingEquivFromIsMono .pres< = λ x y → propBiimpl→Equiv + (R.is-prop-valued< _ _) (S.is-prop-valued< _ _) + (M.pres< x y) (M.reflect< x y) + + module _ + (p1 : equivFun e R.1r ≡ S.1r) + (p+ : ∀ x y → equivFun e (x R.+ y) ≡ equivFun e x S.+ equivFun e y) + (p· : ∀ x y → equivFun e (x R.· y) ≡ equivFun e x S.· equivFun e y) + (p< : ∀ x y → x R.< y → equivFun e x S.< equivFun e y) + (p<⁻ : ∀ x y → equivFun e x S.< equivFun e y → x R.< y) + where + + makeIsOrderedCommRingEquiv : IsOrderedCommRingEquiv (str R) e (str S) + makeIsOrderedCommRingEquiv = makeIsOrderedCommRingEquivFromIsMono + (makeIsOrderedCommRingMono p1 p+ p· p< p<⁻) diff --git a/Cubical/Algebra/OrderedCommRing/Properties.agda b/Cubical/Algebra/OrderedCommRing/Properties.agda new file mode 100644 index 0000000000..eb1ea38212 --- /dev/null +++ b/Cubical/Algebra/OrderedCommRing/Properties.agda @@ -0,0 +1,685 @@ +module Cubical.Algebra.OrderedCommRing.Properties where + +open import Cubical.Foundations.Prelude +open import Cubical.Foundations.Function +open import Cubical.Foundations.Equiv +open import Cubical.Foundations.HLevels +open import Cubical.Foundations.Structure + +open import Cubical.Algebra.CommMonoid +open import Cubical.Algebra.CommRing +open import Cubical.Algebra.CommSemiring +open import Cubical.Algebra.OrderedCommRing.Base +open import Cubical.Algebra.Ring +open import Cubical.Algebra.Semigroup + +open import Cubical.Data.Empty as ⊥ +open import Cubical.Data.Sigma +open import Cubical.Data.Sum + +open import Cubical.HITs.PropositionalTruncation as PT + +open import Cubical.Relation.Binary.Order.Apartness +open import Cubical.Relation.Binary.Order.Poset hiding (isPseudolattice) +open import Cubical.Relation.Binary.Order.Pseudolattice +open import Cubical.Relation.Binary.Order.Quoset +open import Cubical.Relation.Binary.Order.QuosetReasoning +open import Cubical.Relation.Binary.Order.StrictOrder + +open import Cubical.Relation.Nullary + +open import Cubical.Tactics.CommRingSolver + +private + variable + ℓ ℓ' ℓ'' : Level + +OrderedCommRing→StrictOrder : OrderedCommRing ℓ ℓ' → StrictOrder ℓ ℓ' +OrderedCommRing→StrictOrder R .fst = R .fst +OrderedCommRing→StrictOrder R .snd = strictorderstr _ isStrictOrder where + open OrderedCommRingStr (str R) + +OrderedCommRing→Ring : OrderedCommRing ℓ ℓ' → Ring ℓ +OrderedCommRing→Ring = CommRing→Ring ∘ OrderedCommRing→CommRing + +OrderedCommRing→Poset : OrderedCommRing ℓ ℓ' → Poset ℓ ℓ' +OrderedCommRing→Poset = Pseudolattice→Poset ∘ OrderedCommRing→PseudoLattice + +OrderedCommRing→Quoset : OrderedCommRing ℓ ℓ' → Quoset ℓ ℓ' +OrderedCommRing→Quoset = StrictOrder→Quoset ∘ OrderedCommRing→StrictOrder + +OrderedCommRing→Apartness : OrderedCommRing ℓ ℓ' → Apartness ℓ ℓ' +OrderedCommRing→Apartness = StrictOrder→Apartness ∘ OrderedCommRing→StrictOrder + +module _ (R' : OrderedCommRing ℓ ℓ') where + private + R = fst R' + RCR = OrderedCommRing→CommRing R' + open RingTheory (OrderedCommRing→Ring R') + open OrderedCommRingStr (snd R') + + module OrderedCommRingReasoning where + open <-≤-Reasoning + (fst R') + (str (OrderedCommRing→Poset R')) + (str (OrderedCommRing→Quoset R')) + (λ x {y} {z} → <-≤-trans x y z) + (λ x {y} {z} → ≤-<-trans x y z) + (λ {x} {y} → <-≤-weaken x y) + public + + open <-syntax public + open ≤-syntax public + open ≡-syntax public + + _<+[_] : ∀ {x y} → x < y → ∀ z → x + z < y + z + _<+[_] x : ∀ x y → x ≤ y → ¬ (y < x) + ≤→¬> x y = equivFun (≤≃¬> x y) + + ¬<→≥ : ∀ x y → ¬ (x < y) → y ≤ x + ¬<→≥ x y = invEq (≤≃¬> y x) + + +MonoL< : ∀ x y z → x < y → z + x < z + y + +MonoL< x y z = subst2 _<_ (+Comm _ _) (+Comm _ _) ∘ +MonoR< x y z + + +Mono< : ∀ x y z w → x < y → z < w → x + z < y + w + +Mono< x y z w x _ _ zx≤zy ∘ ·MonoL< _ _ z 0 _ _ zx≤zy ∘ ·MonoR< _ _ z 0 _ _ (·MonoL≤ _ _ z (<-≤-weaken 0r z 0 _ _ (·MonoR≤ _ _ z (<-≤-weaken 0r z 0 y x ∘ <→≥)) + + abs ∣_∣ : R → R + abs z = z ⊔ (- z) + ∣_∣ = abs + +