Skip to content

Commit 29063bb

Browse files
authored
[ add ] Bool action on a RawMonoid plus properties (#2450)
* Add new `Bool` action on a `RawMonoid` plus properties * response to review comments on draft * reset: `CHANGELOG` * restore: new `CHANGELOG` entries * change: notation * refactor: use new notation, plus add new lemma * refactor: tweak notation * refactor: proof following Jacques' suggestion
1 parent c1256ae commit 29063bb

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ Additions to existing modules
172172
Central : Op₂ A → A → Set _
173173
```
174174

175+
* In `Algebra.Definitions.RawMonoid` action of a Boolean on a RawMonoid:
176+
```agda
177+
_?>₀_ : Bool → Carrier → Carrier
178+
_?>_∙_ : Bool → Carrier → Carrier → Carrier
179+
```
180+
175181
* In `Algebra.Lattice.Properties.BooleanAlgebra.XorRing`:
176182
```agda
177183
⊕-∧-isBooleanRing : IsBooleanRing _⊕_ _∧_ id ⊥ ⊤
@@ -192,6 +198,14 @@ Additions to existing modules
192198
-ᴹ‿distrib-*ᵣ : ∀ m r → (-ᴹ m) *ᵣ r ≈ᴹ -ᴹ (m *ᵣ r)
193199
```
194200

201+
* In `Algebra.Properties.Monoid.Mult` properties of the Boolean action on a RawMonoid:
202+
```agda
203+
?>₀-homo-true : true ?>₀ x ≈ x
204+
?>₀-assocˡ : b ?>₀ b′ ?>₀ x ≈ (b ∧ b′) ?>₀ x
205+
b?>x∙y≈b?>₀x+y : b ?> x ∙ y ≈ (b ?>₀ x) + y
206+
b?>₀x≈b?>x∙0 : b ?>₀ x ≈ b ?> x ∙ 0#
207+
```
208+
195209
* In `Algebra.Properties.RingWithoutOne`:
196210
```agda
197211
[-x][-y]≈xy : ∀ x y → - x * - y ≈ x * y

src/Algebra/Definitions/RawMonoid.agda

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ open import Algebra.Bundles using (RawMonoid)
1010

1111
module Algebra.Definitions.RawMonoid {a ℓ} (M : RawMonoid a ℓ) where
1212

13+
open import Data.Bool.Base as Bool using (Bool; true; false; if_then_else_)
1314
open import Data.Nat.Base as ℕ using (ℕ; zero; suc)
1415
open import Data.Vec.Functional as Vector using (Vector)
16+
1517
open RawMonoid M renaming ( _∙_ to _+_ ; ε to 0# )
1618

1719
------------------------------------------------------------------------
@@ -21,7 +23,7 @@ open RawMonoid M renaming ( _∙_ to _+_ ; ε to 0# )
2123
open import Algebra.Definitions.RawMagma rawMagma public
2224

2325
------------------------------------------------------------------------
24-
-- Multiplication by natural number
26+
-- Multiplication by natural number: action of the (0,+)-rawMonoid
2527
------------------------------------------------------------------------
2628
-- Standard definition
2729

@@ -65,3 +67,18 @@ suc n ×′ x = n ×′ x + x
6567

6668
sum : {n} Vector Carrier n Carrier
6769
sum = Vector.foldr _+_ 0#
70+
71+
------------------------------------------------------------------------
72+
-- 'Guard' with a Boolean: action of the Boolean (true,∧)-rawMonoid
73+
------------------------------------------------------------------------
74+
75+
infixr 8 _?>₀_
76+
77+
_?>₀_ : Bool Carrier Carrier
78+
b ?>₀ x = if b then x else 0#
79+
80+
-- accumulator optimisation
81+
infixl 8 _?>_∙_
82+
83+
_?>_∙_ : Bool Carrier Carrier Carrier
84+
b ?> x ∙ y = if b then x + y else y

src/Algebra/Properties/Monoid/Mult.agda

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
{-# OPTIONS --cubical-compatible --safe #-}
88

99
open import Algebra.Bundles using (Monoid)
10+
11+
module Algebra.Properties.Monoid.Mult {a ℓ} (M : Monoid a ℓ) where
12+
13+
open import Data.Bool.Base as Bool using (true; false; _∧_)
1014
open import Data.Nat.Base as ℕ using (ℕ; zero; suc; NonZero)
1115
open import Relation.Binary.Core using (_Preserves_⟶_; _Preserves₂_⟶_⟶_)
1216
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
1317

14-
module Algebra.Properties.Monoid.Mult {a ℓ} (M : Monoid a ℓ) where
15-
1618
-- View of the monoid operator as addition
1719
open Monoid M
1820
renaming
@@ -26,15 +28,15 @@ open Monoid M
2628
; ε to 0#
2729
)
2830

29-
open import Relation.Binary.Reasoning.Setoid setoid
30-
3131
open import Algebra.Definitions _≈_
32+
open import Algebra.Properties.Semigroup semigroup
33+
open import Relation.Binary.Reasoning.Setoid setoid
3234

3335
------------------------------------------------------------------------
3436
-- Definition
3537

3638
open import Algebra.Definitions.RawMonoid rawMonoid public
37-
using (_×_)
39+
using (_×_; _?>₀_; _?>_∙_)
3840

3941
------------------------------------------------------------------------
4042
-- Properties of _×_
@@ -59,10 +61,7 @@ open import Algebra.Definitions.RawMonoid rawMonoid public
5961

6062
×-homo-+ : x m n (m ℕ.+ n) × x ≈ m × x + n × x
6163
×-homo-+ x 0 n = sym (+-identityˡ (n × x))
62-
×-homo-+ x (suc m) n = begin
63-
x + (m ℕ.+ n) × x ≈⟨ +-cong refl (×-homo-+ x m n) ⟩
64-
x + (m × x + n × x) ≈⟨ sym (+-assoc x (m × x) (n × x)) ⟩
65-
x + m × x + n × x ∎
64+
×-homo-+ x (suc m) n = sym (uv≈w⇒xu∙v≈xw (sym (×-homo-+ x m n)) x)
6665

6766
×-idem : {c} _+_ IdempotentOn c
6867
n .{{_ : NonZero n}} n × c ≈ c
@@ -78,3 +77,20 @@ open import Algebra.Definitions.RawMonoid rawMonoid public
7877
n × x + m × n × x ≈⟨ +-congˡ (×-assocˡ x m n) ⟩
7978
n × x + (m ℕ.* n) × x ≈⟨ ×-homo-+ x n (m ℕ.* n) ⟨
8079
(suc m ℕ.* n) × x ∎
80+
81+
-- _?>₀_ is homomorphic with respect to Bool._∧_.
82+
83+
?>₀-homo-true : x true ?>₀ x ≈ x
84+
?>₀-homo-true _ = refl
85+
86+
?>₀-assocˡ : b b′ x b ?>₀ b′ ?>₀ x ≈ (b ∧ b′) ?>₀ x
87+
?>₀-assocˡ false _ _ = refl
88+
?>₀-assocˡ true _ _ = refl
89+
90+
b?>x∙y≈b?>₀x+y : b x y b ?> x ∙ y ≈ b ?>₀ x + y
91+
b?>x∙y≈b?>₀x+y true _ _ = refl
92+
b?>x∙y≈b?>₀x+y false _ y = sym (+-identityˡ y)
93+
94+
b?>₀x≈b?>x∙0 : b x b ?>₀ x ≈ b ?> x ∙ 0#
95+
b?>₀x≈b?>x∙0 true _ = sym (+-identityʳ _)
96+
b?>₀x≈b?>x∙0 false x = refl

0 commit comments

Comments
 (0)