Skip to content

Commit 760a894

Browse files
authored
Add Boolean Rings (agda#1146)
* Add Boolean Rings * Changed To to an arrow per Felix' comment. * Removed superfluous brackets per Felix' comment. * missed on parenthesis. * Changed names to comply with NAMING.md * Added fixities for /\,\/ and neg and removed parentheses
1 parent e2cf0ab commit 760a894

File tree

2 files changed

+255
-0
lines changed

2 files changed

+255
-0
lines changed

Cubical/Algebra/BooleanRing.agda

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# OPTIONS --safe #-}
2+
module Cubical.Algebra.BooleanRing where
3+
4+
open import Cubical.Algebra.BooleanRing.Base public

Cubical/Algebra/BooleanRing/Base.agda

+251
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
{-# OPTIONS --safe #-}
2+
module Cubical.Algebra.BooleanRing.Base where
3+
4+
open import Cubical.Foundations.Prelude hiding (_∧_;_∨_)
5+
open import Cubical.Foundations.Structure
6+
open import Cubical.Data.Empty as ⊥
7+
open import Cubical.Algebra.Ring
8+
open import Cubical.Algebra.AbGroup.Base
9+
open import Cubical.Algebra.CommRing
10+
open import Cubical.Tactics.CommRingSolver
11+
12+
13+
private
14+
variable
15+
ℓ ℓ' : Level
16+
17+
record IsBooleanRing {B : Type ℓ}
18+
(𝟘 𝟙 : B) (_+_ _·_ : B B B) (-_ : B B) : Type ℓ where
19+
no-eta-equality
20+
21+
field
22+
isCommRing : IsCommRing 𝟘 𝟙 _+_ _·_ -_
23+
·Idem : (x : B) x · x ≡ x
24+
25+
open IsCommRing isCommRing public
26+
27+
record BooleanStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
28+
field
29+
𝟘 : A
30+
𝟙 : A
31+
_+_ : A A A
32+
_·_ : A A A
33+
-_ : A A
34+
isBooleanRing : IsBooleanRing 𝟘 𝟙 _+_ _·_ -_
35+
36+
infix 8 -_
37+
infixl 7 _·_
38+
infixl 6 _+_
39+
40+
open IsBooleanRing isBooleanRing public
41+
42+
BooleanRing : Type (ℓ-suc ℓ)
43+
BooleanRing ℓ = TypeWithStr ℓ BooleanStr
44+
45+
BooleanStr→CommRingStr : { A : Type ℓ } BooleanStr A CommRingStr A
46+
BooleanStr→CommRingStr x = record { isCommRing = IsBooleanRing.isCommRing (BooleanStr.isBooleanRing x) }
47+
48+
BooleanRing→CommRing : BooleanRing ℓ CommRing ℓ
49+
BooleanRing→CommRing (carrier , structure ) = carrier , BooleanStr→CommRingStr structure
50+
51+
module BooleanAlgebraStr (A : BooleanRing ℓ) where
52+
open BooleanStr (A . snd)
53+
_∨_ : ⟨ A ⟩ ⟨ A ⟩ ⟨ A ⟩
54+
a ∨ b = (a + b) + (a · b)
55+
_∧_ : ⟨ A ⟩ ⟨ A ⟩ ⟨ A ⟩
56+
a ∧ b = a · b
57+
¬_ : ⟨ A ⟩ ⟨ A ⟩
58+
¬ a = 𝟙 + a
59+
60+
infix 8 ¬_
61+
infixl 7 _∧_
62+
infixl 6 _∨_
63+
64+
variable x y z : ⟨ A ⟩
65+
66+
∧Idem : x ∧ x ≡ x
67+
∧Idem = ·Idem _
68+
69+
∧Assoc : x ∧ ( y ∧ z ) ≡ ( x ∧ y ) ∧ z
70+
∧Assoc = ·Assoc _ _ _
71+
72+
∧Comm : x ∧ y ≡ y ∧ x
73+
∧Comm = ·Comm _ _
74+
75+
∨Assoc : (x ∨ ( y ∨ z ) ≡ ( x ∨ y ) ∨ z )
76+
∨Assoc = solve! (BooleanRing→CommRing A)
77+
78+
∨Comm : x ∨ y ≡ y ∨ x
79+
∨Comm = solve! (BooleanRing→CommRing A)
80+
81+
∨IdR : x ∨ 𝟘 ≡ x
82+
∨IdR = solve! (BooleanRing→CommRing A)
83+
84+
∨IdL : 𝟘 ∨ x ≡ x
85+
∨IdL = solve! (BooleanRing→CommRing A)
86+
87+
∧IdR : x ∧ 𝟙 ≡ x
88+
∧IdR = ·IdR _
89+
90+
∧IdL : 𝟙 ∧ x ≡ x
91+
∧IdL = ·IdL _
92+
93+
∧AnnihilR : x ∧ 𝟘 ≡ 𝟘
94+
∧AnnihilR = RingTheory.0RightAnnihilates (CommRing→Ring (BooleanRing→CommRing A)) _
95+
96+
∧AnnihilL : 𝟘 ∧ x ≡ 𝟘
97+
∧AnnihilL = RingTheory.0LeftAnnihilates (CommRing→Ring (BooleanRing→CommRing A)) _
98+
99+
-IsId : x + x ≡ 𝟘
100+
-IsId {x = x} = RingTheory.+Idempotency→0 (CommRing→Ring (BooleanRing→CommRing A)) (x + x) 2x≡4x
101+
where
102+
2x≡4x : x + x ≡ (x + x) + (x + x)
103+
2x≡4x =
104+
x + x
105+
≡⟨ sym (·Idem (x + x)) ⟩
106+
(x + x) · (x + x)
107+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
108+
((x · x) + (x · x)) + ((x · x) + (x · x))
109+
≡⟨ cong₂ _+_ (cong₂ _+_ (·Idem x) (·Idem x)) (cong₂ _+_ (·Idem x) (·Idem x)) ⟩
110+
(x + x) + (x + x) ∎
111+
112+
∨Idem : x ∨ x ≡ x
113+
∨Idem { x = x } =
114+
x + x + x · x
115+
≡⟨ cong (λ y y + x · x) -IsId ⟩
116+
𝟘 + x · x
117+
≡⟨ +IdL (x · x) ⟩
118+
x · x
119+
≡⟨ ·Idem x ⟩
120+
x ∎
121+
122+
1Absorbs∨R : x ∨ 𝟙 ≡ 𝟙
123+
1Absorbs∨R {x = x} =
124+
(x + 𝟙) + (x · 𝟙)
125+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
126+
𝟙 + (x + x)
127+
≡⟨ cong (λ y 𝟙 + y) -IsId ⟩
128+
𝟙 + 𝟘
129+
≡⟨ +IdR 𝟙 ⟩
130+
𝟙 ∎
131+
132+
1Absorbs∨L : 𝟙 ∨ x ≡ 𝟙
133+
1Absorbs∨L {x = x} = ∨Comm ∙ 1Absorbs∨R
134+
135+
∧DistR∨ : x ∧ ( y ∨ z) ≡ (x ∧ y) ∨ (x ∧ z)
136+
∧DistR∨ {x = x} {y = y} { z = z} =
137+
x · ((y + z) + (y · z))
138+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
139+
x · y + x · z + x · (y · z)
140+
≡⟨ cong (λ a x · y + x · z + a · (y · z)) (sym (·Idem x)) ⟩
141+
x · y + x · z + x · x · (y · z)
142+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
143+
x · y + x · z + (x · y) · (x · z) ∎
144+
145+
∧DistL∨ : (x ∨ y) ∧ z ≡ (x ∧ z) ∨ (y ∧ z)
146+
∧DistL∨ = ∧Comm ∙ ∧DistR∨ ∙ cong₂ _∨_ ∧Comm ∧Comm
147+
148+
∨DistR∧ : x ∨ (y ∧ z) ≡ (x ∨ y) ∧ (x ∨ z)
149+
∨DistR∧ {x = x} {y = y} {z = z} =
150+
x + (y · z) + x · (y · z)
151+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
152+
x + 𝟘 + 𝟘 + y · z + 𝟘 + x · y · z
153+
≡⟨ cong (λ a a + 𝟘 + 𝟘 + y · z + 𝟘 + a · y · z) (sym (·Idem x)) ⟩
154+
x · x + 𝟘 + 𝟘 + y · z + 𝟘 + x · x · y · z
155+
≡⟨ cong (λ a x · x + 𝟘 + 𝟘 + y · z + a + x · x · y · z) (sym (-IsId {x = (x · y) · z})) ⟩
156+
x · x + 𝟘 + 𝟘 + y · z + (x · y · z + x · y · z) + x · x · y · z
157+
≡⟨ (cong₂ (λ a b x · x + a + b + y · z + (x · y · z + x · y · z) + x · x · y · z)) (xa-xxa≡0 z) (xa-xxa≡0 y) ⟩
158+
x · x + (x · z + x · x · z) + (x · y + x · x · y) + y · z + (x · y · z + x · y · z) + x · x · y · z
159+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
160+
(x + y + x · y) · (x + z + x · z) ∎ where
161+
xa≡xxa : (a : ⟨ A ⟩) x · a ≡ (x · x ) · a
162+
xa≡xxa a = cong (λ y y · a) (sym (·Idem x))
163+
xa-xxa≡0 : (a : ⟨ A ⟩) 𝟘 ≡ x · a + x · x · a
164+
xa-xxa≡0 a =
165+
𝟘
166+
≡⟨ sym -IsId ⟩
167+
x · a + x · a
168+
≡⟨ cong (λ y x · a + y · a) (sym (·Idem x)) ⟩
169+
x · a + x · x · a ∎
170+
171+
∨Distr∧R : (x ∧ y) ∨ z ≡ (x ∨ z) ∧ (y ∨ z)
172+
∨Distr∧R = ∨Comm ∙ ∨DistR∧ ∙ cong₂ _∧_ ∨Comm ∨Comm
173+
174+
∧AbsorbL∨ : x ∧ (x ∨ y) ≡ x
175+
∧AbsorbL∨ {x = x} {y = y} =
176+
x · ((x + y) + (x · y))
177+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
178+
x · x + (x · y + x · x · y)
179+
≡⟨ cong (λ z z + ((x · y) + (z · y))) (·Idem x) ⟩
180+
x + (x · y + x · y)
181+
≡⟨ cong (_+_ x) -IsId ⟩
182+
x + 𝟘
183+
≡⟨ +IdR x ⟩
184+
x ∎
185+
186+
∨AbsorbL∧ : x ∨ (x ∧ y) ≡ x
187+
∨AbsorbL∧ {x = x} { y = y} =
188+
x + x · y + x · (x · y)
189+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
190+
x + (x · y + x · x · y)
191+
≡⟨ cong (λ z x + (x · y + z · y)) (·Idem x) ⟩
192+
x + (x · y + x · y)
193+
≡⟨ cong (_+_ x) -IsId ⟩
194+
x + 𝟘
195+
≡⟨ +IdR x ⟩
196+
x ∎
197+
198+
¬Cancels∧R : x ∧ ¬ x ≡ 𝟘
199+
¬Cancels∧R {x = x} =
200+
x · (𝟙 + x)
201+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
202+
x + x · x
203+
≡⟨ cong (λ y x + y) (·Idem x) ⟩
204+
x + x
205+
≡⟨ -IsId ⟩
206+
𝟘 ∎
207+
208+
¬Cancels∧L : ¬ x ∧ x ≡ 𝟘
209+
¬Cancels∧L = ∧Comm ∙ ¬Cancels∧R
210+
211+
¬Completes∨R : x ∨ ¬ x ≡ 𝟙
212+
¬Completes∨R {x = x} =
213+
x + ¬ x + (x ∧ ¬ x)
214+
≡⟨ cong (λ z x + ¬ x + z) ¬Cancels∧R ⟩
215+
x + ¬ x + 𝟘
216+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
217+
x ∨ 𝟙
218+
≡⟨ 1Absorbs∨R ⟩
219+
𝟙 ∎
220+
221+
¬Completes∨L : (¬ x) ∨ x ≡ 𝟙
222+
¬Completes∨L = ∨Comm ∙ ¬Completes∨R
223+
224+
¬Invol : ¬ ¬ x ≡ x
225+
¬Invol {x = x} =
226+
𝟙 + (𝟙 + x)
227+
≡⟨ +Assoc 𝟙 𝟙 x ⟩
228+
(𝟙 + 𝟙) + x
229+
≡⟨ cong (λ y y + x) ( -IsId {x = 𝟙}) ⟩
230+
𝟘 + x
231+
≡⟨ +IdL x ⟩
232+
x ∎
233+
234+
¬0≡1 : ¬ 𝟘 ≡ 𝟙
235+
¬0≡1 = +IdR 𝟙
236+
237+
¬1≡0 : ¬ 𝟙 ≡ 𝟘
238+
¬1≡0 = -IsId {x = 𝟙}
239+
240+
DeMorgan¬∨ : ¬ (x ∨ y) ≡ ¬ x ∧ ¬ y
241+
DeMorgan¬∨ = solve! (BooleanRing→CommRing A)
242+
243+
DeMorgan¬∧ : ¬ (x ∧ y) ≡ ¬ x ∨ ¬ y
244+
DeMorgan¬∧ {x = x} {y = y} =
245+
𝟙 + x · y
246+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
247+
𝟘 + 𝟘 + 𝟙 + x · y
248+
≡⟨ cong₂ (λ a b ((a + b) + 𝟙) + (x · y)) (sym (-IsId {x = 𝟙 + x})) (sym (-IsId {x = y})) ⟩
249+
((𝟙 + x) + (𝟙 + x)) + (y + y) + 𝟙 + x · y
250+
≡⟨ solve! (BooleanRing→CommRing A) ⟩
251+
¬ x ∨ ¬ y ∎

0 commit comments

Comments
 (0)