mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-09-21 18:32:44 +03:00
Add some algebra implementations
This commit is contained in:
parent
fd9de745ae
commit
a2bdf8e6d7
@ -42,14 +42,14 @@ notXorCancel False b = rewrite xorFalseNeutral b in
|
||||
notInvolutive b
|
||||
|
||||
export
|
||||
xorAssociative : (a, b, c : Bool) -> xor (xor a b) c = xor a (xor b c)
|
||||
xorAssociative : (a, b, c : Bool) -> xor a (xor b c) = xor (xor a b) c
|
||||
xorAssociative False b c =
|
||||
rewrite xorFalseNeutral b in
|
||||
sym $ xorFalseNeutral (xor b c)
|
||||
xorFalseNeutral $ xor b c
|
||||
xorAssociative True b c =
|
||||
rewrite xorTrueNot b in
|
||||
rewrite xorTrueNot (xor b c) in
|
||||
sym $ notXor b c
|
||||
notXor b c
|
||||
|
||||
export
|
||||
xorCommutative : (a, b : Bool) -> xor a b = xor b a
|
||||
|
@ -583,3 +583,13 @@ export
|
||||
sucMinR : (l : Nat) -> minimum l (S l) = l
|
||||
sucMinR Z = Refl
|
||||
sucMinR (S l) = cong S $ sucMinR l
|
||||
|
||||
-- Algebra -----------------------------
|
||||
|
||||
public export
|
||||
Semigroup Nat where
|
||||
(<+>) = plus
|
||||
|
||||
public export
|
||||
Monoid Nat where
|
||||
neutral = Z
|
||||
|
21
libs/contrib/Control/Algebra/Implementations.idr
Normal file
21
libs/contrib/Control/Algebra/Implementations.idr
Normal file
@ -0,0 +1,21 @@
|
||||
module Control.Algebra.Implementations
|
||||
|
||||
import Control.Algebra
|
||||
|
||||
-- This file is for algebra implementations with nowhere else to go.
|
||||
|
||||
%default total
|
||||
|
||||
-- Functions ---------------------------
|
||||
|
||||
Semigroup (ty -> ty) where
|
||||
(<+>) = (.)
|
||||
|
||||
SemigroupV (ty -> ty) where
|
||||
semigroupOpIsAssociative _ _ _ = Refl
|
||||
|
||||
Monoid (ty -> ty) where
|
||||
neutral = id
|
||||
|
||||
MonoidV (ty -> ty) where
|
||||
monoidNeutralIsNeutralR _ = Refl
|
@ -1,6 +1,5 @@
|
||||
module Control.Algebra.Laws
|
||||
|
||||
import Prelude
|
||||
import Control.Algebra
|
||||
|
||||
%default total
|
||||
|
18
libs/contrib/Control/Monad/Algebra.idr
Normal file
18
libs/contrib/Control/Monad/Algebra.idr
Normal file
@ -0,0 +1,18 @@
|
||||
module Control.Monad.Algebra
|
||||
|
||||
import Control.Algebra
|
||||
import Control.Monad.Identity
|
||||
|
||||
%default total
|
||||
|
||||
public export
|
||||
SemigroupV ty => SemigroupV (Identity ty) where
|
||||
semigroupOpIsAssociative (Id l) (Id c) (Id r) =
|
||||
rewrite semigroupOpIsAssociative l c r in Refl
|
||||
|
||||
public export
|
||||
MonoidV ty => MonoidV (Identity ty) where
|
||||
monoidNeutralIsNeutralL (Id l) =
|
||||
rewrite monoidNeutralIsNeutralL l in Refl
|
||||
monoidNeutralIsNeutralR (Id r) =
|
||||
rewrite monoidNeutralIsNeutralR r in Refl
|
74
libs/contrib/Data/Bool/Algebra.idr
Normal file
74
libs/contrib/Data/Bool/Algebra.idr
Normal file
@ -0,0 +1,74 @@
|
||||
module Data.Bool.Algebra
|
||||
|
||||
import Control.Algebra
|
||||
import Data.Bool.Xor
|
||||
|
||||
%default total
|
||||
|
||||
-- && is Bool -> Lazy Bool -> Bool,
|
||||
-- but Bool -> Bool -> Bool is required
|
||||
and : Bool -> Bool -> Bool
|
||||
and True True = True
|
||||
and _ _ = False
|
||||
|
||||
Semigroup Bool where
|
||||
(<+>) = xor
|
||||
|
||||
SemigroupV Bool where
|
||||
semigroupOpIsAssociative = xorAssociative
|
||||
|
||||
Monoid Bool where
|
||||
neutral = False
|
||||
|
||||
MonoidV Bool where
|
||||
monoidNeutralIsNeutralL True = Refl
|
||||
monoidNeutralIsNeutralL False = Refl
|
||||
|
||||
Group Bool where
|
||||
-- Each Bool is its own additive inverse.
|
||||
inverse = id
|
||||
|
||||
groupInverseIsInverseR True = Refl
|
||||
groupInverseIsInverseR False = Refl
|
||||
|
||||
AbelianGroup Bool where
|
||||
groupOpIsCommutative = xorCommutative
|
||||
|
||||
Ring Bool where
|
||||
(<.>) = and
|
||||
|
||||
ringOpIsAssociative True True True = Refl
|
||||
ringOpIsAssociative True True False = Refl
|
||||
ringOpIsAssociative True False True = Refl
|
||||
ringOpIsAssociative True False False = Refl
|
||||
ringOpIsAssociative False True True = Refl
|
||||
ringOpIsAssociative False False True = Refl
|
||||
ringOpIsAssociative False True False = Refl
|
||||
ringOpIsAssociative False False False = Refl
|
||||
|
||||
ringOpIsDistributiveL True True True = Refl
|
||||
ringOpIsDistributiveL True True False = Refl
|
||||
ringOpIsDistributiveL True False True = Refl
|
||||
ringOpIsDistributiveL True False False = Refl
|
||||
ringOpIsDistributiveL False True True = Refl
|
||||
ringOpIsDistributiveL False False True = Refl
|
||||
ringOpIsDistributiveL False True False = Refl
|
||||
ringOpIsDistributiveL False False False = Refl
|
||||
|
||||
ringOpIsDistributiveR True True True = Refl
|
||||
ringOpIsDistributiveR True True False = Refl
|
||||
ringOpIsDistributiveR True False True = Refl
|
||||
ringOpIsDistributiveR True False False = Refl
|
||||
ringOpIsDistributiveR False True True = Refl
|
||||
ringOpIsDistributiveR False False True = Refl
|
||||
ringOpIsDistributiveR False True False = Refl
|
||||
ringOpIsDistributiveR False False False = Refl
|
||||
|
||||
RingWithUnity Bool where
|
||||
unity = True
|
||||
|
||||
unityIsRingIdL True = Refl
|
||||
unityIsRingIdL False = Refl
|
||||
|
||||
unityIsRingIdR True = Refl
|
||||
unityIsRingIdR False = Refl
|
15
libs/contrib/Data/List/Algebra.idr
Normal file
15
libs/contrib/Data/List/Algebra.idr
Normal file
@ -0,0 +1,15 @@
|
||||
module Data.List.Algebra
|
||||
|
||||
import Control.Algebra
|
||||
import Data.List
|
||||
|
||||
%default total
|
||||
|
||||
public export
|
||||
SemigroupV (List ty) where
|
||||
semigroupOpIsAssociative = appendAssociative
|
||||
|
||||
public export
|
||||
MonoidV (List ty) where
|
||||
monoidNeutralIsNeutralL = appendNilRightNeutral
|
||||
monoidNeutralIsNeutralR _ = Refl
|
15
libs/contrib/Data/Morphisms/Algebra.idr
Normal file
15
libs/contrib/Data/Morphisms/Algebra.idr
Normal file
@ -0,0 +1,15 @@
|
||||
module Data.Morphisms.Algebra
|
||||
|
||||
import Control.Algebra
|
||||
import Data.Morphisms
|
||||
|
||||
%default total
|
||||
|
||||
public export
|
||||
SemigroupV (Endomorphism ty) where
|
||||
semigroupOpIsAssociative (Endo _) (Endo _) (Endo _) = Refl
|
||||
|
||||
public export
|
||||
MonoidV (Endomorphism ty) where
|
||||
monoidNeutralIsNeutralL (Endo _) = Refl
|
||||
monoidNeutralIsNeutralR (Endo _) = Refl
|
15
libs/contrib/Data/Nat/Algebra.idr
Normal file
15
libs/contrib/Data/Nat/Algebra.idr
Normal file
@ -0,0 +1,15 @@
|
||||
module Data.Nat.Algebra
|
||||
|
||||
import Control.Algebra
|
||||
import Data.Nat
|
||||
|
||||
%default total
|
||||
|
||||
public export
|
||||
SemigroupV Nat where
|
||||
semigroupOpIsAssociative = plusAssociative
|
||||
|
||||
public export
|
||||
MonoidV Nat where
|
||||
monoidNeutralIsNeutralL = plusZeroRightNeutral
|
||||
monoidNeutralIsNeutralR = plusZeroLeftNeutral
|
@ -5,13 +5,18 @@ modules = Control.ANSI,
|
||||
Control.ANSI.CSI,
|
||||
Control.Delayed,
|
||||
Control.Linear.LIO,
|
||||
Control.Monad.Algebra,
|
||||
Control.Monad.Syntax,
|
||||
|
||||
Control.Algebra,
|
||||
Control.Algebra.Laws,
|
||||
Control.Algebra.Implementations,
|
||||
|
||||
Data.Bool.Algebra,
|
||||
|
||||
Data.Linear.Array,
|
||||
|
||||
Data.List.Algebra,
|
||||
Data.List.TailRec,
|
||||
Data.List.Equalities,
|
||||
Data.List.Reverse,
|
||||
@ -22,6 +27,9 @@ modules = Control.ANSI,
|
||||
|
||||
Data.Logic.Propositional,
|
||||
|
||||
Data.Morphisms.Algebra,
|
||||
|
||||
Data.Nat.Algebra,
|
||||
Data.Nat.Ack,
|
||||
Data.Nat.Equational,
|
||||
Data.Nat.Fact,
|
||||
|
Loading…
Reference in New Issue
Block a user