-
Notifications
You must be signed in to change notification settings - Fork 268
[ add ] Bool action on a RawMonoid plus properties
#2450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
d666858
7d4d3a0
1caa018
eac420a
c0aac32
38117b8
2adec97
94f8e98
08ecae5
2f104b6
7ca5cd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| {-# OPTIONS --cubical-compatible --safe #-} | ||
|
|
||
| open import Algebra.Bundles using (RawMonoid) | ||
| open import Data.Bool.Base as Bool using (Bool; true; false; if_then_else_) | ||
| open import Data.Nat.Base as ℕ using (ℕ; zero; suc) | ||
| open import Data.Vec.Functional as Vector using (Vector) | ||
|
|
||
|
|
@@ -21,7 +22,7 @@ open RawMonoid M renaming ( _∙_ to _+_ ; ε to 0# ) | |
| open import Algebra.Definitions.RawMagma rawMagma public | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Multiplication by natural number | ||
| -- Multiplication by natural number: action of the (0,+)-rawMonoid | ||
| ------------------------------------------------------------------------ | ||
| -- Standard definition | ||
|
|
||
|
|
@@ -65,3 +66,18 @@ suc n ×′ x = n ×′ x + x | |
|
|
||
| sum : ∀ {n} → Vector Carrier n → Carrier | ||
| sum = Vector.foldr _+_ 0# | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- 'Conjunction' with a Boolean: action of the Boolean (true,∧)-rawMonoid | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| infixr 8 _∧_ | ||
|
|
||
| _∧_ : Bool → Carrier → Carrier | ||
| b ∧ x = if b then x else 0# | ||
|
jamesmckinna marked this conversation as resolved.
Outdated
|
||
|
|
||
| -- tail-recursive optimisation | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optimisation of what? It doesn't seem like an optimisation of the above? What am I missing?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the TCOptimised forms of (monoid) sum and multiplication, the 'optimisation' lies in avoiding having to explicitly track terms of the form
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As witnessed by
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still feels like a stretch. I do like the optimization of an action not doing a (statically known) null operation, a lot. I'm still worried that this particular case is a coincidence rather than fundamental!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I think it extends to the |
||
| infixl 8 _∧′_∙_ | ||
|
|
||
| _∧′_∙_ : Bool → Carrier → Carrier → Carrier | ||
| b ∧′ x ∙ y = if b then x + y else y | ||
Uh oh!
There was an error while loading. Please reload this page.