-
Notifications
You must be signed in to change notification settings - Fork 257
[ add ] Pointwise lifting of algebra to Data.Vec.Functional (Functional vector module #1945 redux) #2817
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
base: master
Are you sure you want to change the base?
[ add ] Pointwise lifting of algebra to Data.Vec.Functional (Functional vector module #1945 redux) #2817
Changes from 1 commit
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,142 @@ | ||||||
------------------------------------------------------------------------ | ||||||
-- The Agda standard library | ||||||
-- | ||||||
-- Some Vector-related module Definitions | ||||||
------------------------------------------------------------------------ | ||||||
|
||||||
{-# OPTIONS --cubical-compatible --safe #-} | ||||||
|
||||||
module Data.Vec.Functional.Algebra.Base where | ||||||
|
||||||
open import Level using (Level; suc; _⊔_) | ||||||
open import Function using (_$_) | ||||||
open import Data.Nat using (ℕ) | ||||||
open import Data.Fin using (Fin) | ||||||
open import Data.Vec.Functional | ||||||
open import Algebra.Core | ||||||
open import Algebra.Bundles | ||||||
open import Algebra.Module | ||||||
open import Relation.Binary using (Rel) | ||||||
open import Data.Vec.Functional.Relation.Binary.Pointwise using (Pointwise) | ||||||
|
||||||
private variable | ||||||
a ℓ : Level | ||||||
A : Set ℓ | ||||||
n : ℕ | ||||||
|
||||||
-- Vector relation lifting | ||||||
VecRel : {A : Set a} → Rel A ℓ → Rel (Vector A n) ℓ | ||||||
VecRel _≈_ xs ys = Pointwise _≈_ xs ys | ||||||
|
||||||
-- Binary operation lifting | ||||||
lift₂ᴹ : {A : Set a} → Op₂ A → Op₂ (Vector A n) | ||||||
lift₂ᴹ _∙_ = zipWith _∙_ | ||||||
|
||||||
-- Unary operation lifting | ||||||
lift₁ᴹ : {A : Set a} → Op₁ A → Op₁ (Vector A n) | ||||||
lift₁ᴹ f = map f | ||||||
|
||||||
-- Vector RawMagma construction | ||||||
VecRawMagma : RawMagma a ℓ → (n : ℕ) → RawMagma a ℓ | ||||||
|
||||||
VecRawMagma M n = | ||||||
record | ||||||
{ Carrier = Vector M.Carrier n | ||||||
; _≈_ = VecRel M._≈_ | ||||||
; _∙_ = lift₂ᴹ M._∙_ | ||||||
} | ||||||
where module M = RawMagma M | ||||||
|
||||||
-- Vector RawMonoid construction | ||||||
VecRawMonoid : RawMonoid a ℓ → (n : ℕ) → RawMonoid a ℓ | ||||||
VecRawMonoid M n = | ||||||
record | ||||||
{ RawMagma (VecRawMagma M.rawMagma n) | ||||||
; ε = λ _ → M.ε | ||||||
} | ||||||
where | ||||||
module M = RawMonoid M | ||||||
|
||||||
-- Vector RawGroup construction | ||||||
VecRawGroup : RawGroup a ℓ → (n : ℕ) → RawGroup a ℓ | ||||||
VecRawGroup G n = | ||||||
record | ||||||
{ RawMonoid (VecRawMonoid G.rawMonoid n) | ||||||
; _⁻¹ = lift₁ᴹ G._⁻¹ | ||||||
} | ||||||
where module G = RawGroup G | ||||||
|
||||||
-- Vector RawNearSemiring construction | ||||||
VecRawNearSemiring : RawNearSemiring a ℓ → (n : ℕ) → RawNearSemiring a ℓ | ||||||
VecRawNearSemiring NS n = | ||||||
record | ||||||
{ Carrier = Vector NS.Carrier n | ||||||
; _≈_ = VecRel NS._≈_ | ||||||
; _+_ = lift₂ᴹ NS._+_ | ||||||
; _*_ = lift₂ᴹ NS._*_ | ||||||
; 0# = λ _ → NS.0# | ||||||
} | ||||||
where module NS = RawNearSemiring NS | ||||||
|
||||||
-- Vector RawSemiring construction | ||||||
VecRawSemiring : RawSemiring a ℓ → (n : ℕ) → RawSemiring a ℓ | ||||||
VecRawSemiring S n = | ||||||
record | ||||||
{ RawNearSemiring (VecRawNearSemiring S.rawNearSemiring n) | ||||||
; 1# = λ _ → S.1# | ||||||
} | ||||||
where module S = RawSemiring S | ||||||
|
||||||
-- Vector RawRing construction | ||||||
VecRawRing : RawRing a ℓ → (n : ℕ) → RawRing a ℓ | ||||||
VecRawRing R n = | ||||||
record | ||||||
{ RawSemiring (VecRawSemiring R.rawSemiring n) | ||||||
; -_ = lift₁ᴹ R.-_ | ||||||
} | ||||||
where module R = RawRing R | ||||||
|
||||||
e-mniang marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
-- Left scalar action obtained from the ring/semiring multiplication | ||||||
_*ₗ_ : {S : Set a} → Op₂ S → Opₗ S (Vector S n) | ||||||
_*ₗ_ _*_ r xs = map (λ x → _*_ r x) xs | ||||||
|
_*ₗ_ _*_ r xs = map (λ x → _*_ r x) xs | |
_*ₗ_ _*_ r xs = map (r *_) xs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, worth adding some global variable
declarations to avoid having to mention {S : Set a}
prefixes in types at all?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_*ᵣ_ _*_ xs r = map (λ x → _*_ x r) xs | |
_*ᵣ_ _*_ xs r = map (_* r) xs |
Uh oh!
There was an error while loading. Please reload this page.