Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cubical/Algebra/AbGroup/Instances/Int/Fast.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Cubical.Algebra.AbGroup.Instances.Int.Fast where

open import Cubical.Foundations.Prelude
open import Cubical.Data.Int.Fast
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Algebra.Group.Instances.Int.Fast

ℤAbGroup : AbGroup ℓ-zero
ℤAbGroup = Group→AbGroup ℤGroup +Comm
23 changes: 23 additions & 0 deletions Cubical/Algebra/CommRing/Instances/Int/Fast.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Cubical.Algebra.CommRing.Instances.Int.Fast where

open import Cubical.Foundations.Prelude

open import Cubical.Algebra.CommRing
open import Cubical.Data.Int.Fast as Int renaming (_+_ to _+ℤ_; _·_ to _·ℤ_ ; -_ to -ℤ_)

open CommRingStr using (0r ; 1r ; _+_ ; _·_ ; -_ ; isCommRing)

ℤCommRing : CommRing ℓ-zero
fst ℤCommRing =
0r (snd ℤCommRing) = pos 0
1r (snd ℤCommRing) = pos 1
_+_ (snd ℤCommRing) = _+ℤ_
_·_ (snd ℤCommRing) = _·ℤ_
- snd ℤCommRing = -ℤ_
isCommRing (snd ℤCommRing) = isCommRingℤ
where
abstract
isCommRingℤ : IsCommRing (pos 0) (pos 1) _+ℤ_ _·ℤ_ -ℤ_
isCommRingℤ = makeIsCommRing isSetℤ Int.+Assoc +IdR
-Cancel Int.+Comm Int.·Assoc
Int.·IdR ·DistR+ Int.·Comm
56 changes: 56 additions & 0 deletions Cubical/Algebra/Group/Instances/Int/Fast.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module Cubical.Algebra.Group.Instances.Int.Fast where

open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function

open import Cubical.Data.Int.Fast renaming (_+_ to _+ℤ_ ; _-_ to _-ℤ_ ; _·_ to _·ℤ_ ; -_ to -ℤ_)

open import Cubical.Data.Nat using (ℕ ; zero ; suc)
open import Cubical.Data.Fin.Inductive.Base

open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties


open GroupStr

ℤGroup : Group₀
fst ℤGroup = ℤ
1g (snd ℤGroup) = 0
_·_ (snd ℤGroup) = _+ℤ_
inv (snd ℤGroup) = -ℤ_
isGroup (snd ℤGroup) = isGroupℤ
where
abstract
isGroupℤ : IsGroup (pos 0) (_+ℤ_) (-ℤ_)
isGroupℤ = makeIsGroup isSetℤ
+Assoc +IdR +IdL
-Cancel -Cancel'

ℤHom : (n : ℤ) → GroupHom ℤGroup ℤGroup
fst (ℤHom n) x = n ·ℤ x
snd (ℤHom n) =
makeIsGroupHom λ x y → ·DistR+ n x y

negEquivℤ : GroupEquiv ℤGroup ℤGroup
fst negEquivℤ =
isoToEquiv
(iso (GroupStr.inv (snd ℤGroup))
(GroupStr.inv (snd ℤGroup))
(GroupTheory.invInv ℤGroup)
(GroupTheory.invInv ℤGroup))
snd negEquivℤ =
makeIsGroupHom -Dist+

sumFinGroupℤComm : (G : Group₀) (h : GroupIso G ℤGroup) {n : ℕ}
(f : Fin n → fst G) → sumFinℤ {n = n} (λ a → Iso.fun (fst h) (f a))
≡ Iso.fun (fst h) (sumFinGroup G {n = n} f)
sumFinGroupℤComm G h {n = zero} f = sym (IsGroupHom.pres1 (snd h))
sumFinGroupℤComm G h {n = suc n} f =
cong₂ _+ℤ_ (λ _ → Iso.fun (fst h) (f flast))
(sumFinGroupℤComm G h {n = n} (f ∘ injectSuc {n = n}))
∙ sym (IsGroupHom.pres· (snd h) (f flast)
(sumFinGroup G {n = n} (λ x → f (injectSuc {n = n} x))))
2 changes: 1 addition & 1 deletion Cubical/Algebra/OrderedCommRing/Base.agda
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Cubical.Algebra.OrderedCommRing.Base where
{-
Definition of an commutative ordered ring.
Definition of an ordered commutative ring.
-}

open import Cubical.Foundations.Prelude
Expand Down
66 changes: 66 additions & 0 deletions Cubical/Algebra/OrderedCommRing/Instances/Int.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module Cubical.Algebra.OrderedCommRing.Instances.Int where

open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv

open import Cubical.Data.Empty as ⊥

open import Cubical.HITs.PropositionalTruncation

open import Cubical.Data.Int as ℤ
renaming (_+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_)
open import Cubical.Data.Int.Order
renaming (_<_ to _<ℤ_ ; _≤_ to _≤ℤ_)

open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int

open import Cubical.Algebra.OrderedCommRing

open import Cubical.Relation.Nullary

open import Cubical.Relation.Binary.Order.StrictOrder
open import Cubical.Relation.Binary.Order.StrictOrder.Instances.Int

open import Cubical.Relation.Binary.Order.Pseudolattice
open import Cubical.Relation.Binary.Order.Pseudolattice.Instances.Int

open CommRingStr
open OrderedCommRingStr
open PseudolatticeStr
open StrictOrderStr

ℤOrderedCommRing : OrderedCommRing ℓ-zero ℓ-zero
fst ℤOrderedCommRing = ℤ
0r (snd ℤOrderedCommRing) = 0
1r (snd ℤOrderedCommRing) = 1
_+_ (snd ℤOrderedCommRing) = _+ℤ_
_·_ (snd ℤOrderedCommRing) = _·ℤ_
-_ (snd ℤOrderedCommRing) = -ℤ_
_<_ (snd ℤOrderedCommRing) = _<ℤ_
_≤_ (snd ℤOrderedCommRing) = _≤ℤ_
isOrderedCommRing (snd ℤOrderedCommRing) = isOrderedCommRingℤ
where
open IsOrderedCommRing

isOrderedCommRingℤ : IsOrderedCommRing 0 1 _+ℤ_ _·ℤ_ -ℤ_ _<ℤ_ _≤ℤ_
isOrderedCommRingℤ .isCommRing = ℤCommRing .snd .isCommRing
isOrderedCommRingℤ .isPseudolattice = ℤ≤Pseudolattice .snd .is-pseudolattice
isOrderedCommRingℤ .isStrictOrder = ℤ<StrictOrder .snd .isStrictOrder
isOrderedCommRingℤ .<-≤-weaken = λ _ _ → <-weaken
isOrderedCommRingℤ .≤≃¬> = λ x y →
propBiimpl→Equiv isProp≤ (isProp¬ (y <ℤ x))
(λ x≤y y<x → isIrrefl< (≤<-trans x≤y y<x))
(λ ¬y<x → case x ≟ y return (λ _ → x ≤ℤ y) of λ {
(lt x<y) → <-weaken x<y ;
(eq x≡y) → subst (x ≤ℤ_) x≡y isRefl≤ ;
(gt y<z) → ⊥.rec (¬y<x y<z) })
isOrderedCommRingℤ .+MonoR≤ = λ _ _ z → ≤-+o {o = z}
isOrderedCommRingℤ .+MonoR< = λ _ _ z → <-+o {o = z}
isOrderedCommRingℤ .posSum→pos∨pos = λ _ _ → ∣_∣₁ ∘ 0<+ _ _
isOrderedCommRingℤ .<-≤-trans = λ _ _ _ → <≤-trans
isOrderedCommRingℤ .≤-<-trans = λ _ _ _ → ≤<-trans
isOrderedCommRingℤ .·MonoR≤ = λ _ _ _ → 0≤o→≤-·o
isOrderedCommRingℤ .·MonoR< = λ _ _ _ → 0<o→<-·o
isOrderedCommRingℤ .0<1 = isRefl≤
69 changes: 69 additions & 0 deletions Cubical/Algebra/OrderedCommRing/Instances/Int/Fast.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module Cubical.Algebra.OrderedCommRing.Instances.Int.Fast where

open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv

open import Cubical.Data.Empty as ⊥

open import Cubical.HITs.PropositionalTruncation

open import Cubical.Data.Int.Fast as ℤ
renaming (_+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_)
open import Cubical.Data.Int.Fast.Order
renaming (_<_ to _<ℤ_ ; _≤_ to _≤ℤ_)

open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int.Fast

open import Cubical.Algebra.OrderedCommRing

open import Cubical.Relation.Nullary

open import Cubical.Relation.Binary.Order.StrictOrder
open import Cubical.Relation.Binary.Order.StrictOrder.Instances.Int.Fast

open import Cubical.Relation.Binary.Order.Pseudolattice
open import Cubical.Relation.Binary.Order.Pseudolattice.Instances.Int.Fast

open import Cubical.Relation.Binary
open BinaryRelation

open CommRingStr
open OrderedCommRingStr
open PseudolatticeStr
open StrictOrderStr

ℤOrderedCommRing : OrderedCommRing ℓ-zero ℓ-zero
fst ℤOrderedCommRing = ℤ
0r (snd ℤOrderedCommRing) = 0
1r (snd ℤOrderedCommRing) = 1
_+_ (snd ℤOrderedCommRing) = _+ℤ_
_·_ (snd ℤOrderedCommRing) = _·ℤ_
-_ (snd ℤOrderedCommRing) = -ℤ_
_<_ (snd ℤOrderedCommRing) = _<ℤ_
_≤_ (snd ℤOrderedCommRing) = _≤ℤ_
isOrderedCommRing (snd ℤOrderedCommRing) = isOrderedCommRingℤ
where
open IsOrderedCommRing

isOrderedCommRingℤ : IsOrderedCommRing 0 1 _+ℤ_ _·ℤ_ -ℤ_ _<ℤ_ _≤ℤ_
isOrderedCommRingℤ .isCommRing = ℤCommRing .snd .isCommRing
isOrderedCommRingℤ .isPseudolattice = ℤ≤Pseudolattice .snd .is-pseudolattice
isOrderedCommRingℤ .isStrictOrder = ℤ<StrictOrder .snd .isStrictOrder
isOrderedCommRingℤ .<-≤-weaken = λ x y → <-weaken {x} {y}
isOrderedCommRingℤ .≤≃¬> = λ x y →
propBiimpl→Equiv (isProp≤ {x} {y}) (isProp¬ (y <ℤ x))
(λ x≤y y<x → isIrrefl< (≤<-trans {x} {y} x≤y y<x))
(λ ¬y<x → case x ≟ y return (λ _ → x ≤ℤ y) of λ {
(lt x<y) → <-weaken {x} {y} x<y ;
(eq x≡y) → subst (x ≤ℤ_) x≡y isRefl≤ ;
(gt y<z) → ⊥.rec (¬y<x y<z) })
isOrderedCommRingℤ .+MonoR≤ = λ x y z → ≤-+o {x} {y} {z}
isOrderedCommRingℤ .+MonoR< = λ x y z → <-+o {x} {y} {z}
isOrderedCommRingℤ .posSum→pos∨pos = λ _ _ → ∣_∣₁ ∘ 0<+ _ _
isOrderedCommRingℤ .<-≤-trans = λ x y z → <≤-trans {x} {y} {z}
isOrderedCommRingℤ .≤-<-trans = λ x y z → ≤<-trans {x} {y} {z}
isOrderedCommRingℤ .·MonoR≤ = λ x y z → 0≤o→≤-·o {z} {x} {y}
isOrderedCommRingℤ .·MonoR< = λ x y z → 0<o→<-·o {z} {x} {y}
isOrderedCommRingℤ .0<1 = isRefl≤
5 changes: 5 additions & 0 deletions Cubical/Data/Int/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ abs : ℤ → ℕ
abs (pos n) = n
abs (negsuc n) = suc n

sign : ℤ → ℤ
sign (pos zero) = pos zero
sign (pos (suc n)) = pos (suc zero)
sign (negsuc n) = negsuc zero

_ℕ-_ : ℕ → ℕ → ℤ
a ℕ- 0 = pos a
0 ℕ- suc b = negsuc b
Expand Down
6 changes: 6 additions & 0 deletions Cubical/Data/Int/Fast.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This is the fast version of the integers.
-- It uses the preferred version of the integers, but with more efficient operations.
module Cubical.Data.Int.Fast where

open import Cubical.Data.Int.Fast.Base public
open import Cubical.Data.Int.Fast.Properties public
30 changes: 19 additions & 11 deletions Cubical/Data/Int/Fast/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Cubical.Data.Int.Fast.Base where

open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat as ℕ hiding (_+_ ; _·_)
open import Cubical.Data.Int.Base hiding (_ℕ-_ ; _+_ ; _-_ ; _·_) public
open import Cubical.Data.Int.Base hiding (_ℕ-_ ; _+_ ; _-_ ; _·_ ; sumFinℤ ; sumFinℤId) public
open import Cubical.Data.Fin.Inductive.Base

infixl 7 _·_
infixl 6 _+_ _-_
Expand All @@ -15,18 +16,25 @@ _ℕ-_ : ℕ → ℕ → ℤ
m ℕ- n = ℕ-hlp (m ℕ.∸ n) (n ℕ.∸ m)

_+_ : ℤ → ℤ → ℤ
pos n + pos n= pos (n ℕ.+ n)
negsuc n + negsuc n = negsuc (suc (n ℕ.+ n))
pos n + negsuc n = n ℕ- (suc n)
negsuc n + pos n= n ℕ- (suc n)
pos m + pos n = pos (m ℕ.+ n)
negsuc m + negsuc n = negsuc (suc (m ℕ.+ n))
pos m + negsuc n = m ℕ- (suc n)
negsuc m + pos n = n ℕ- (suc m)

_-_ : ℤ → ℤ → ℤ
m - n = m + (- n)

_·_ : ℤ → ℤ → ℤ
pos n · pos n₁ = pos (n ℕ.· n₁)
pos zero · negsuc n₁ = pos zero
pos (suc n) · negsuc n₁ = negsuc (predℕ (suc n ℕ.· suc n₁))
negsuc n · pos zero = pos zero
negsuc n · pos (suc n₁) = negsuc (predℕ (suc n ℕ.· suc n₁))
negsuc n · negsuc n₁ = pos (suc n ℕ.· suc n₁)
pos m · pos n = pos (m ℕ.· n)
pos zero · negsuc n = pos zero
pos (suc m) · negsuc n = negsuc (predℕ (suc m ℕ.· suc n))
negsuc m · pos zero = pos zero
negsuc m · pos (suc n) = negsuc (predℕ (suc m ℕ.· suc n))
negsuc m · negsuc n = pos (suc m ℕ.· suc n)

sumFinℤ : {n : ℕ} (f : Fin n → ℤ) → ℤ
sumFinℤ {n = n} f = sumFinGen {n = n} _+_ 0 f

sumFinℤId : (n : ℕ) {f g : Fin n → ℤ}
→ ((x : _) → f x ≡ g x) → sumFinℤ {n = n} f ≡ sumFinℤ {n = n} g
sumFinℤId n t i = sumFinℤ {n = n} λ x → t x i
Loading