Skip to content

Commit cfc6d45

Browse files
authored
Initial Boolean Algebra (#1239)
* moved Initial Boolean algebra to new branch * Added Boolean maps * used copattern-matching for idemCommRing->BR * BoolBRStr now uses copattern-matching * moved BoolBR and BoolCR to instances of CommRing and BooleanRing repsectively * Renamed BooleanStr to BooleanRingStr * use copattern matching for BooleanRingStr->CommRingStr
1 parent 8ef2c34 commit cfc6d45

File tree

4 files changed

+128
-10
lines changed

4 files changed

+128
-10
lines changed

Cubical/Algebra/BooleanRing/Base.agda

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ record IsBooleanRing {B : Type ℓ}
2323

2424
open IsCommRing isCommRing public
2525

26-
record BooleanStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
26+
record BooleanRingStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
2727
field
2828
𝟘 : A
2929
𝟙 : A
@@ -39,22 +39,49 @@ record BooleanStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
3939
open IsBooleanRing isBooleanRing public
4040

4141
BooleanRing : Type (ℓ-suc ℓ)
42-
BooleanRing ℓ = TypeWithStr ℓ BooleanStr
43-
44-
BooleanStr→CommRingStr : { A : Type ℓ } BooleanStr A CommRingStr A
45-
BooleanStr→CommRingStr x = record { isCommRing = IsBooleanRing.isCommRing (BooleanStr.isBooleanRing x) }
42+
BooleanRing ℓ = TypeWithStr ℓ BooleanRingStr
43+
44+
module _ {A : Type ℓ} (BRStr : BooleanRingStr A) where
45+
open CommRingStr
46+
open BooleanRingStr( BRStr)
47+
BooleanRingStr→CommRingStr : CommRingStr A
48+
0r BooleanRingStr→CommRingStr = _
49+
1r BooleanRingStr→CommRingStr = _
50+
_+_ BooleanRingStr→CommRingStr = _
51+
_·_ BooleanRingStr→CommRingStr = _
52+
- BooleanRingStr→CommRingStr = _
53+
isCommRing BooleanRingStr→CommRingStr = isCommRing BRStr
4654

4755
BooleanRing→CommRing : BooleanRing ℓ CommRing ℓ
48-
BooleanRing→CommRing (carrier , structure ) = carrier , BooleanStr→CommRingStr structure
56+
BooleanRing→CommRing (carrier , structure ) = carrier , BooleanRingStr→CommRingStr structure
4957

50-
BooleanStr→RingStr : { A : Type ℓ } BooleanStr A RingStr A
51-
BooleanStr→RingStr S = CommRingStr→RingStr (BooleanStr→CommRingStr S)
58+
BooleanRingStr→RingStr : { A : Type ℓ } BooleanRingStr A RingStr A
59+
BooleanRingStr→RingStr S = CommRingStr→RingStr (BooleanRingStr→CommRingStr S)
5260

5361
BooleanRing→Ring : BooleanRing ℓ Ring ℓ
54-
BooleanRing→Ring (carrier , structure ) = carrier , BooleanStr→RingStr structure
62+
BooleanRing→Ring (carrier , structure ) = carrier , BooleanRingStr→RingStr structure
63+
64+
isIdemRing : {ℓ : Level} CommRing ℓ Type ℓ
65+
isIdemRing R = (r : ⟨ R ⟩) (str R) .CommRingStr._·_ r r ≡ r
66+
67+
module _ {ℓ : Level} (R : CommRing ℓ) (idem : isIdemRing R) where
68+
open BooleanRingStr
69+
open IsBooleanRing
70+
idemCommRing→BR : BooleanRing ℓ
71+
fst idemCommRing→BR = ⟨ R ⟩
72+
𝟘 (snd idemCommRing→BR) = _
73+
𝟙 (snd idemCommRing→BR) = _
74+
_+_ (snd idemCommRing→BR) = _
75+
_·_ (snd idemCommRing→BR) = _
76+
- snd idemCommRing→BR = _
77+
isCommRing (isBooleanRing (snd idemCommRing→BR)) = (str R) .CommRingStr.isCommRing
78+
·Idem (isBooleanRing (snd idemCommRing→BR)) = idem
79+
80+
BoolHom : {ℓ ℓ' : Level} (A : BooleanRing ℓ) (B : BooleanRing ℓ') Type _
81+
BoolHom A B = CommRingHom (BooleanRing→CommRing A) (BooleanRing→CommRing B)
5582

5683
module BooleanAlgebraStr (A : BooleanRing ℓ) where
57-
open BooleanStr (A . snd)
84+
open BooleanRingStr (A . snd)
5885
_∨_ : ⟨ A ⟩ ⟨ A ⟩ ⟨ A ⟩
5986
a ∨ b = (a + b) + (a · b)
6087
_∧_ : ⟨ A ⟩ ⟨ A ⟩ ⟨ A ⟩
@@ -257,3 +284,4 @@ module BooleanAlgebraStr (A : BooleanRing ℓ) where
257284
((𝟙 + x) + (𝟙 + x)) + (y + y) + 𝟙 + x · y
258285
≡⟨ solve! (BooleanRing→CommRing A) ⟩
259286
¬ x ∨ ¬ y ∎
287+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{-# OPTIONS --safe #-}
2+
3+
module Cubical.Algebra.BooleanRing.Initial where
4+
5+
open import Cubical.Foundations.Prelude
6+
open import Cubical.Foundations.Structure
7+
open import Cubical.Foundations.Function
8+
9+
open import Cubical.Algebra.BooleanRing.Base
10+
open import Cubical.Data.Bool renaming (elim to bool-ind)
11+
open import Cubical.Algebra.CommRing
12+
open import Cubical.Tactics.CommRingSolver
13+
14+
open import Cubical.Algebra.BooleanRing.Instances.Bool
15+
open import Cubical.Algebra.CommRing.Instances.Bool
16+
17+
module _ {ℓ : Level} (B : BooleanRing ℓ) where
18+
private
19+
B' = BooleanRing→CommRing B
20+
21+
open CommRingStr (snd B')
22+
open BooleanAlgebraStr B
23+
open IsCommRingHom
24+
25+
BoolBR→BAMap : Bool ⟨ B ⟩
26+
BoolBR→BAMap = bool-ind 1r 0r
27+
28+
BoolBR→BAIsCommRingHom : IsCommRingHom (snd BoolCR) BoolBR→BAMap (snd B')
29+
pres0 BoolBR→BAIsCommRingHom = refl
30+
pres1 BoolBR→BAIsCommRingHom = refl
31+
pres+ BoolBR→BAIsCommRingHom =
32+
λ { false false solve! B'
33+
; false true solve! B'
34+
; true false solve! B'
35+
; true true sym characteristic2
36+
}
37+
pres· BoolBR→BAIsCommRingHom =
38+
λ { false false solve! B'
39+
; false true solve! B'
40+
; true false solve! B'
41+
; true true solve! B'
42+
}
43+
pres- BoolBR→BAIsCommRingHom false = solve! B'
44+
pres- BoolBR→BAIsCommRingHom true = -IsId :> 1r ≡ - 1r
45+
46+
BoolBR→ : BoolHom BoolBR B
47+
BoolBR→ = BoolBR→BAMap , BoolBR→BAIsCommRingHom
48+
49+
BoolBR→IsUnique : (f : BoolHom BoolBR B) (fst f) ≡ fst (BoolBR→)
50+
BoolBR→IsUnique f = funExt (bool-ind (pres1 (snd f)) (pres0 (snd f)))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{-# OPTIONS --safe #-}
2+
3+
module Cubical.Algebra.BooleanRing.Instances.Bool where
4+
5+
open import Cubical.Foundations.Prelude
6+
open import Cubical.Algebra.BooleanRing.Base
7+
open import Cubical.Data.Bool renaming (elim to bool-ind)
8+
open import Cubical.Algebra.CommRing
9+
10+
open BooleanRingStr
11+
open IsBooleanRing
12+
13+
BoolBRStr : BooleanRingStr Bool
14+
𝟘 BoolBRStr = false
15+
𝟙 BoolBRStr = true
16+
_+_ BoolBRStr = _⊕_
17+
_·_ BoolBRStr = _and_
18+
- BoolBRStr = λ x x
19+
isCommRing (isBooleanRing BoolBRStr) = makeIsCommRing
20+
isSetBool ⊕-assoc ⊕-identityʳ
21+
(bool-ind refl refl) ⊕-comm and-assoc
22+
and-identityʳ (bool-ind (λ _ _ refl)
23+
(λ _ _ refl)) and-comm
24+
·Idem (isBooleanRing BoolBRStr) = bool-ind refl refl
25+
26+
BoolBR : BooleanRing ℓ-zero
27+
BoolBR = Bool , BoolBRStr
28+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{-# OPTIONS --safe #-}
2+
3+
module Cubical.Algebra.CommRing.Instances.Bool where
4+
5+
open import Cubical.Foundations.Prelude
6+
open import Cubical.Algebra.BooleanRing.Base
7+
open import Cubical.Algebra.CommRing
8+
9+
open import Cubical.Algebra.BooleanRing.Instances.Bool
10+
11+
BoolCR : CommRing ℓ-zero
12+
BoolCR = BooleanRing→CommRing BoolBR

0 commit comments

Comments
 (0)