on master help sign in
Merge pull request #2140 from BlackBrane/new-alg

Fix Field definition and separate Lattice and VectorSpace modules from Algebra

commit2a4b4a767041c41d8aad5ac57130bc1667df8296 authorDavid Christiansen <david@davidchristiansen.dk> dateFri 24 Apr 2015, 14:13 (11 years ago) parent162105260b8878
9 files changed+294−277
idris.cabal+1 libs/contrib/Classes/Verified.idr+13−10 libs/contrib/Control/Algebra.idr+17−159 libs/contrib/Control/Algebra/Lattice.idr+123 libs/contrib/Control/Algebra/NumericInstances.idr+104 libs/contrib/Control/Algebra/VectorSpace.idr+30 libs/contrib/Data/Matrix.idr+4−104 libs/contrib/contrib.ipkg+2 libs/prelude/Prelude/Algebra.idr−4
idris.cabal+1
@@ -114,6 +114,7 @@ Extra-source-files:
114114 libs/contrib/Classes/*.idr
115115 libs/contrib/Control/*.idr
116116 libs/contrib/Control/Isomorphism/*.idr
117+ libs/contrib/Control/Algebra/*.idr
117118 libs/contrib/Data/*.idr
118119 libs/contrib/Decidable/*.idr
119120 libs/contrib/Network/*.idr
libs/contrib/Classes/Verified.idr+13−10
@@ -1,6 +1,8 @@
11module Classes.Verified
22
33import Control.Algebra
4+import Control.Algebra.Lattice
5+import Control.Algebra.VectorSpace
46
57-- Due to these being basically unused and difficult to implement,
68-- they're in contrib for a bit. Once a design is found that lets them
@@ -78,6 +80,11 @@ class (VerifiedRing a, RingWithUnity a) => VerifiedRingWithUnity a where
7880 total ringWithUnityIsUnityL : (l : a) -> l <.> unity = l
7981 total ringWithUnityIsUnityR : (r : a) -> unity <.> r = r
8082
83+--class (VerifiedRingWithUnity a, Field a) => VerifiedField a where
84+-- total fieldInverseIsInverseL : (l : a) -> (notId : Not (l = neutral)) -> l <.> (inverseM l notId) = unity
85+-- total fieldInverseIsInverseR : (r : a) -> (notId : Not (r = neutral)) -> (inverseM r notId) <.> r = unity
86+
87+
8188class JoinSemilattice a => VerifiedJoinSemilattice a where
8289 total joinSemilatticeJoinIsAssociative : (l, c, r : a) -> join l (join c r) = join (join l c) r
8390 total joinSemilatticeJoinIsCommutative : (l, r : a) -> join l r = join r l
@@ -100,15 +107,11 @@ class (VerifiedJoinSemilattice a, VerifiedMeetSemilattice a) => VerifiedLattice
100107
101108class (VerifiedBoundedJoinSemilattice a, VerifiedBoundedMeetSemilattice a, VerifiedLattice a) => VerifiedBoundedLattice a where { }
102109
103−class (VerifiedRing a, Field a) => VerifiedField a where
104− total fieldInverseIsInverseL : (l : a) -> l <.> inverseM l = unity
105− total fieldInverseIsInverseR : (r : a) -> inverseM r <.> r = unity
106−
107−-- class (VerifiedRingWithUnity a, VerifiedAbelianGroup b, Module a b) => VerifiedModule a b where
108−-- total moduleScalarMultiplyComposition : (x,y : a) -> (v : b) -> x <#> (y <#> v) = (x <.> y) <#> v
109−-- total moduleScalarUnityIsUnity : (v : b) -> unity <#> v = v
110−-- total moduleScalarMultDistributiveWRTVectorAddition : (s : a) -> (v, w : b) -> s <#> (v <+> w) = (s <#> v) <+> (s <#> w)
111−-- total moduleScalarMultDistributiveWRTModuleAddition : (s, t : a) -> (v : b) -> (s <+> t) <#> v = (s <#> v) <+> (t <#> v)
112110
113−-- class (VerifiedField a, VerifiedModule a b) => VerifiedVectorSpace a b where {}
111+--class (VerifiedRingWithUnity a, VerifiedAbelianGroup b, Module a b) => VerifiedModule a b where
112+-- total moduleScalarMultiplyComposition : (x,y : a) -> (v : b) -> x <#> (y <#> v) = (x <.> y) <#> v
113+-- total moduleScalarUnityIsUnity : (v : b) -> unity {a} <#> v = v
114+-- total moduleScalarMultDistributiveWRTVectorAddition : (s : a) -> (v, w : b) -> s <#> (v <+> w) = (s <#> v) <+> (s <#> w)
115+-- total moduleScalarMultDistributiveWRTModuleAddition : (s, t : a) -> (v : b) -> (s <+> t) <#> v = (s <#> v) <+> (t <#> v)
114116
117+--class (VerifiedField a, VerifiedModule a b) => VerifiedVectorSpace a b where {}
libs/contrib/Control/Algebra.idr+17−159
@@ -1,11 +1,8 @@
11module Control.Algebra
22
3−import Data.Heap
4−
5−-- XXX: change?
63infixl 6 <->
7−infixl 6 <.>
8−infixl 5 <#>
4+infixl 7 <.>
5+
96
107||| Sets equipped with a single binary operation that is associative, along with
118||| a neutral element for that binary operation and inverses for all elements.
@@ -40,7 +37,6 @@ class Monoid a => Group a where
4037||| forall a, inverse a <+> a == neutral
4138class Group a => AbelianGroup a where { }
4239
43−
4440||| Sets equipped with two binary operations, one associative and commutative
4541||| supplied with a neutral element, and the other associative, with
4642||| distributivity laws relating the two operations. Must satisfy the following
@@ -64,7 +60,6 @@ class Group a => AbelianGroup a where { }
6460class AbelianGroup a => Ring a where
6561 (<.>) : a -> a -> a
6662
67−
6863||| Sets equipped with two binary operations, one associative and commutative
6964||| supplied with a neutral element, and the other associative supplied with a
7065||| neutral element, with distributivity laws relating the two operations. Must
@@ -91,137 +86,10 @@ class AbelianGroup a => Ring a where
9186class Ring a => RingWithUnity a where
9287 unity : a
9388
94−
95−||| Sets equipped with a binary operation that is commutative, associative and
96−||| idempotent. Must satisfy the following laws:
97−|||
98−||| + Associativity of join:
99−||| forall a b c, join a (join b c) == join (join a b) c
100−||| + Commutativity of join:
101−||| forall a b, join a b == join b a
102−||| + Idempotency of join:
103−||| forall a, join a a == a
104−|||
105−||| Join semilattices capture the notion of sets with a "least upper bound".
106−class JoinSemilattice a where
107− join : a -> a -> a
108−
109−instance JoinSemilattice Nat where
110− join = maximum
111−
112−instance Ord a => JoinSemilattice (MaxiphobicHeap a) where
113− join = merge
114−
115−||| Sets equipped with a binary operation that is commutative, associative and
116−||| idempotent. Must satisfy the following laws:
117−|||
118−||| + Associativity of meet:
119−||| forall a b c, meet a (meet b c) == meet (meet a b) c
120−||| + Commutativity of meet:
121−||| forall a b, meet a b == meet b a
122−||| + Idempotency of meet:
123−||| forall a, meet a a == a
124−|||
125−||| Meet semilattices capture the notion of sets with a "greatest lower bound".
126−class MeetSemilattice a where
127− meet : a -> a -> a
128−
129−instance MeetSemilattice Nat where
130− meet = minimum
131−
132−
133−||| Sets equipped with a binary operation that is commutative, associative and
134−||| idempotent and supplied with a unitary element. Must satisfy the following
135−||| laws:
136−|||
137−||| + Associativity of join:
138−||| forall a b c, join a (join b c) == join (join a b) c
139−||| + Commutativity of join:
140−||| forall a b, join a b == join b a
141−||| + Idempotency of join:
142−||| forall a, join a a == a
143−||| + Bottom (Unitary Element):
144−||| forall a, join a bottom == a
145−|||
146−||| Join semilattices capture the notion of sets with a "least upper bound"
147−||| equipped with a "bottom" element.
148−class JoinSemilattice a => BoundedJoinSemilattice a where
149− bottom : a
150−
151−
152−instance BoundedJoinSemilattice Nat where
153− bottom = Z
154−
155−
156−||| Sets equipped with a binary operation that is commutative, associative and
157−||| idempotent and supplied with a unitary element. Must satisfy the following
158−||| laws:
159−|||
160−||| + Associativity of meet:
161−||| forall a b c, meet a (meet b c) == meet (meet a b) c
162−||| + Commutativity of meet:
163−||| forall a b, meet a b == meet b a
164−||| + Idempotency of meet:
165−||| forall a, meet a a == a
166−||| + Top (Unitary Element):
167−||| forall a, meet a top == a
168−|||
169−||| Meet semilattices capture the notion of sets with a "greatest lower bound"
170−||| equipped with a "top" element.
171−class MeetSemilattice a => BoundedMeetSemilattice a where
172− top : a
173−
174−
175−
176−||| Sets equipped with two binary operations that are both commutative,
177−||| associative and idempotent, along with absorbtion laws for relating the two
178−||| binary operations. Must satisfy the following:
179−|||
180−||| + Associativity of meet and join:
181−||| forall a b c, meet a (meet b c) == meet (meet a b) c
182−||| forall a b c, join a (join b c) == join (join a b) c
183−||| + Commutativity of meet and join:
184−||| forall a b, meet a b == meet b a
185−||| forall a b, join a b == join b a
186−||| + Idempotency of meet and join:
187−||| forall a, meet a a == a
188−||| forall a, join a a == a
189−||| + Absorbtion laws for meet and join:
190−||| forall a b, meet a (join a b) == a
191−||| forall a b, join a (meet a b) == a
192−class (JoinSemilattice a, MeetSemilattice a) => Lattice a where { }
193−
194−
195−instance Lattice Nat where { }
196−
197−||| Sets equipped with two binary operations that are both commutative,
198−||| associative and idempotent and supplied with neutral elements, along with
199−||| absorbtion laws for relating the two binary operations. Must satisfy the
200−||| following:
201−|||
202−||| + Associativity of meet and join:
203−||| forall a b c, meet a (meet b c) == meet (meet a b) c
204−||| forall a b c, join a (join b c) == join (join a b) c
205−||| + Commutativity of meet and join:
206−||| forall a b, meet a b == meet b a
207−||| forall a b, join a b == join b a
208−||| + Idempotency of meet and join:
209−||| forall a, meet a a == a
210−||| forall a, join a a == a
211−||| + Absorbtion laws for meet and join:
212−||| forall a b, meet a (join a b) == a
213−||| forall a b, join a (meet a b) == a
214−||| + Neutral for meet and join:
215−||| forall a, meet a top == top
216−||| forall a, join a bottom == bottom
217−class (BoundedJoinSemilattice a, BoundedMeetSemilattice a) => BoundedLattice a where { }
218−
219−
220−-- Fields.
221−||| Sets equipped with two binary operations, both associative and commutative
222−||| supplied with a neutral element, with
223−||| distributivity laws relating the two operations. Must satisfy the following
224−||| laws:
89+||| Sets equipped with two binary operations – both associative, commutative and
90+||| possessing a neutral element – and distributivity laws relating the two
91+||| operations. All elements except the additive identity must have a
92+||| multiplicative inverse. Must satisfy the following laws:
22593|||
22694||| + Associativity of `<+>`:
22795||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
@@ -238,34 +106,24 @@ class (BoundedJoinSemilattice a, BoundedMeetSemilattice a) => BoundedLattice a w
238106||| + Unity for `<.>`:
239107||| forall a, a <.> unity == a
240108||| forall a, unity <.> a == a
241−||| + InverseM of `<.>`:
242−||| forall a, a <.> inverseM a == unity
243−||| forall a, inverseM a <.> a == unity
109+||| + InverseM of `<.>`, except for neutral
110+||| forall a /= neutral, a <.> inverseM a == unity
111+||| forall a /= neutral, inverseM a <.> a == unity
244112||| + Distributivity of `<.>` and `<->`:
245113||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
246114||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
247115class RingWithUnity a => Field a where
248− inverseM : a -> a
249−
116+ inverseM : (x : a) -> Not (x = neutral) -> a
250117
251−||| A module over a ring is an additive abelian group of 'vectors' endowed with a
252−||| scale operation multiplying vectors by ring elements, and distributivity laws
253−||| relating the scale operation to both ring addition and module addition.
254−||| Must satisfy the following laws:
255−|||
256−||| + Compatibility of scalar multiplication with ring multiplication:
257−||| forall a b v, a <#> (b <#> v) = (a <.> b) <#> v
258−||| + Ring unity is the identity element of scalar multiplication:
259−||| forall v, unity <#> v = v
260−||| + Distributivity of `<#>` and `<+>`:
261−||| forall a v w, a <#> (v <+> w) == (a <#> v) <+> (a <#> w)
262−||| forall a b v, (a <+> b) <#> v == (a <#> v) <+> (b <#> v)
263−class (RingWithUnity a, AbelianGroup b) => Module a b where
264− (<#>) : a -> b -> b
118+sum : (Foldable t, Monoid a) => t a -> a
119+sum = foldr (<+>) neutral
265120
121+product : (Foldable t, RingWithUnity a) => t a -> a
122+product = foldr (<.>) unity
266123
267−||| A vector space is a module over a ring that is also a field
268−class (Field a, Module a b) => VectorSpace a b where {}
124+power : RingWithUnity a => a -> Nat -> a
125+power _ Z = unity
126+power x (S n) = x <.> (Algebra.power x n)
269127
270128
271129-- XXX todo:
libs/contrib/Control/Algebra/Lattice.idrnew file+123
@@ -0,0 +1,123 @@
1+module Control.Algebra.Lattice
2+
3+import Control.Algebra
4+import Data.Heap
5+
6+
7+||| Sets equipped with a binary operation that is commutative, associative and
8+||| idempotent. Must satisfy the following laws:
9+|||
10+||| + Associativity of join:
11+||| forall a b c, join a (join b c) == join (join a b) c
12+||| + Commutativity of join:
13+||| forall a b, join a b == join b a
14+||| + Idempotency of join:
15+||| forall a, join a a == a
16+|||
17+||| Join semilattices capture the notion of sets with a "least upper bound".
18+class JoinSemilattice a where
19+ join : a -> a -> a
20+
21+instance JoinSemilattice Nat where
22+ join = maximum
23+
24+instance Ord a => JoinSemilattice (MaxiphobicHeap a) where
25+ join = merge
26+
27+||| Sets equipped with a binary operation that is commutative, associative and
28+||| idempotent. Must satisfy the following laws:
29+|||
30+||| + Associativity of meet:
31+||| forall a b c, meet a (meet b c) == meet (meet a b) c
32+||| + Commutativity of meet:
33+||| forall a b, meet a b == meet b a
34+||| + Idempotency of meet:
35+||| forall a, meet a a == a
36+|||
37+||| Meet semilattices capture the notion of sets with a "greatest lower bound".
38+class MeetSemilattice a where
39+ meet : a -> a -> a
40+
41+instance MeetSemilattice Nat where
42+ meet = minimum
43+
44+||| Sets equipped with a binary operation that is commutative, associative and
45+||| idempotent and supplied with a unitary element. Must satisfy the following
46+||| laws:
47+|||
48+||| + Associativity of join:
49+||| forall a b c, join a (join b c) == join (join a b) c
50+||| + Commutativity of join:
51+||| forall a b, join a b == join b a
52+||| + Idempotency of join:
53+||| forall a, join a a == a
54+||| + Bottom (Unitary Element):
55+||| forall a, join a bottom == a
56+|||
57+||| Join semilattices capture the notion of sets with a "least upper bound"
58+||| equipped with a "bottom" element.
59+class JoinSemilattice a => BoundedJoinSemilattice a where
60+ bottom : a
61+
62+instance BoundedJoinSemilattice Nat where
63+ bottom = Z
64+
65+||| Sets equipped with a binary operation that is commutative, associative and
66+||| idempotent and supplied with a unitary element. Must satisfy the following
67+||| laws:
68+|||
69+||| + Associativity of meet:
70+||| forall a b c, meet a (meet b c) == meet (meet a b) c
71+||| + Commutativity of meet:
72+||| forall a b, meet a b == meet b a
73+||| + Idempotency of meet:
74+||| forall a, meet a a == a
75+||| + Top (Unitary Element):
76+||| forall a, meet a top == a
77+|||
78+||| Meet semilattices capture the notion of sets with a "greatest lower bound"
79+||| equipped with a "top" element.
80+class MeetSemilattice a => BoundedMeetSemilattice a where
81+ top : a
82+
83+||| Sets equipped with two binary operations that are both commutative,
84+||| associative and idempotent, along with absorbtion laws for relating the two
85+||| binary operations. Must satisfy the following:
86+|||
87+||| + Associativity of meet and join:
88+||| forall a b c, meet a (meet b c) == meet (meet a b) c
89+||| forall a b c, join a (join b c) == join (join a b) c
90+||| + Commutativity of meet and join:
91+||| forall a b, meet a b == meet b a
92+||| forall a b, join a b == join b a
93+||| + Idempotency of meet and join:
94+||| forall a, meet a a == a
95+||| forall a, join a a == a
96+||| + Absorbtion laws for meet and join:
97+||| forall a b, meet a (join a b) == a
98+||| forall a b, join a (meet a b) == a
99+class (JoinSemilattice a, MeetSemilattice a) => Lattice a where { }
100+
101+instance Lattice Nat where { }
102+
103+||| Sets equipped with two binary operations that are both commutative,
104+||| associative and idempotent and supplied with neutral elements, along with
105+||| absorbtion laws for relating the two binary operations. Must satisfy the
106+||| following:
107+|||
108+||| + Associativity of meet and join:
109+||| forall a b c, meet a (meet b c) == meet (meet a b) c
110+||| forall a b c, join a (join b c) == join (join a b) c
111+||| + Commutativity of meet and join:
112+||| forall a b, meet a b == meet b a
113+||| forall a b, join a b == join b a
114+||| + Idempotency of meet and join:
115+||| forall a, meet a a == a
116+||| forall a, join a a == a
117+||| + Absorbtion laws for meet and join:
118+||| forall a b, meet a (join a b) == a
119+||| forall a b, join a (meet a b) == a
120+||| + Neutral for meet and join:
121+||| forall a, meet a top == top
122+||| forall a, join a bottom == bottom
123+class (BoundedJoinSemilattice a, BoundedMeetSemilattice a) => BoundedLattice a where { }
libs/contrib/Control/Algebra/NumericInstances.idrnew file+104
@@ -0,0 +1,104 @@
1+module Control.Algebra.NumericInstances
2+
3+import Control.Algebra
4+import Data.Complex
5+import Data.ZZ
6+
7+
8+instance Semigroup Integer where
9+ (<+>) = (+)
10+
11+instance Monoid Integer where
12+ neutral = 0
13+
14+instance Group Integer where
15+ inverse = (* -1)
16+
17+instance AbelianGroup Integer
18+
19+instance Ring Integer where
20+ (<.>) = (*)
21+
22+instance RingWithUnity Integer where
23+ unity = 1
24+
25+
26+instance Semigroup Int where
27+ (<+>) = (+)
28+
29+instance Monoid Int where
30+ neutral = 0
31+
32+instance Group Int where
33+ inverse = (* -1)
34+
35+instance AbelianGroup Int
36+
37+instance Ring Int where
38+ (<.>) = (*)
39+
40+instance RingWithUnity Int where
41+ unity = 1
42+
43+
44+instance Semigroup Float where
45+ (<+>) = (+)
46+
47+instance Monoid Float where
48+ neutral = 0
49+
50+instance Group Float where
51+ inverse = (* -1)
52+
53+instance AbelianGroup Float
54+
55+instance Ring Float where
56+ (<.>) = (*)
57+
58+instance RingWithUnity Float where
59+ unity = 1
60+
61+instance Field Float where
62+ inverseM f _ = 1 / f
63+
64+
65+instance Semigroup Nat where
66+ (<+>) = (+)
67+
68+instance Monoid Nat where
69+ neutral = 0
70+
71+instance Semigroup ZZ where
72+ (<+>) = (+)
73+
74+instance Monoid ZZ where
75+ neutral = 0
76+
77+instance Group ZZ where
78+ inverse = (* -1)
79+
80+instance AbelianGroup ZZ
81+
82+instance Ring ZZ where
83+ (<.>) = (*)
84+
85+instance RingWithUnity ZZ where
86+ unity = 1
87+
88+
89+instance Semigroup a => Semigroup (Complex a) where
90+ (<+>) (a :+ b) (c :+ d) = (a <+> c) :+ (b <+> d)
91+
92+instance Monoid a => Monoid (Complex a) where
93+ neutral = (neutral :+ neutral)
94+
95+instance Group a => Group (Complex a) where
96+ inverse (r :+ i) = (inverse r :+ inverse i)
97+
98+instance Ring a => AbelianGroup (Complex a) where {}
99+
100+instance Ring a => Ring (Complex a) where
101+ (<.>) (a :+ b) (c :+ d) = (a <.> c <-> b <.> d) :+ (a <.> d <+> b <.> c)
102+
103+instance RingWithUnity a => RingWithUnity (Complex a) where
104+ unity = (unity :+ neutral)
libs/contrib/Control/Algebra/VectorSpace.idrnew file+30
@@ -0,0 +1,30 @@
1+module Control.Algebra.VectorSpace
2+
3+import Control.Algebra
4+
5+infixl 5 <#>
6+infixr 2 <||>
7+
8+
9+||| A module over a ring is an additive abelian group of 'vectors' endowed with a
10+||| scale operation multiplying vectors by ring elements, and distributivity laws
11+||| relating the scale operation to both ring addition and module addition.
12+||| Must satisfy the following laws:
13+|||
14+||| + Compatibility of scalar multiplication with ring multiplication:
15+||| forall a b v, a <#> (b <#> v) = (a <.> b) <#> v
16+||| + Ring unity is the identity element of scalar multiplication:
17+||| forall v, unity <#> v = v
18+||| + Distributivity of `<#>` and `<+>`:
19+||| forall a v w, a <#> (v <+> w) == (a <#> v) <+> (a <#> w)
20+||| forall a b v, (a <+> b) <#> v == (a <#> v) <+> (b <#> v)
21+class (RingWithUnity a, AbelianGroup b) => Module a b where
22+ (<#>) : a -> b -> b
23+
24+||| A vector space is a module over a ring that is also a field
25+class (Field a, Module a b) => VectorSpace a b where {}
26+
27+||| An inner product space is a module – or vector space – over a ring, with a binary function
28+||| associating a ring value to each pair of vectors.
29+class Module a b => InnerProductSpace a b where
30+ (<||>) : b -> b -> a
libs/contrib/Data/Matrix.idr+4−104
@@ -1,6 +1,8 @@
11module Data.Matrix
22
3−import Control.Algebra
3+import Control.Algebra
4+import Control.Algebra.VectorSpace
5+import public Control.Algebra.NumericInstances
46
57import Data.Complex
68import Data.ZZ
@@ -40,8 +42,7 @@ instance Ring a => Ring (Vect n a) where
4042instance RingWithUnity a => RingWithUnity (Vect n a) where
4143 unity {n} = replicate n unity
4244
43−instance Field a => Field (Vect n a) where
44− inverseM = map inverseM
45+--instance Field a => Field (Vect n a) where
4546
4647instance RingWithUnity a => Module a (Vect n a) where
4748 (<#>) r v = map (r <.>) v
@@ -147,104 +148,3 @@ Id {d} = map (\n => basis n) $ allN d
147148
148149-- TODO: Prove properties of matrix algebra for 'Verified' algebraic classes
149150
150−-----------------------------------------------------------------------
151−-- Numberic data types as rings
152−-----------------------------------------------------------------------
153−
154−instance Semigroup Integer where
155− (<+>) = (+)
156−
157−instance Monoid Integer where
158− neutral = 0
159−
160−instance Group Integer where
161− inverse = (* -1)
162−
163−instance AbelianGroup Integer
164−
165−instance Ring Integer where
166− (<.>) = (*)
167−
168−instance RingWithUnity Integer where
169− unity = 1
170−
171−
172−instance Semigroup Int where
173− (<+>) = (+)
174−
175−instance Monoid Int where
176− neutral = 0
177−
178−instance Group Int where
179− inverse = (* -1)
180−
181−instance AbelianGroup Int
182−
183−instance Ring Int where
184− (<.>) = (*)
185−
186−instance RingWithUnity Int where
187− unity = 1
188−
189−
190−instance Semigroup Float where
191− (<+>) = (+)
192−
193−instance Monoid Float where
194− neutral = 0
195−
196−instance Group Float where
197− inverse = (* -1)
198−
199−instance AbelianGroup Float
200−
201−instance Ring Float where
202− (<.>) = (*)
203−
204−instance RingWithUnity Float where
205− unity = 1
206−
207−instance Field Float where
208− inverseM f = 1 / f
209−
210−
211−instance Semigroup Nat where
212− (<+>) = (+)
213−
214−instance Monoid Nat where
215− neutral = 0
216−
217−instance Semigroup ZZ where
218− (<+>) = (+)
219−
220−instance Monoid ZZ where
221− neutral = 0
222−
223−instance Group ZZ where
224− inverse = (* -1)
225−
226−instance AbelianGroup ZZ
227−
228−instance Ring ZZ where
229− (<.>) = (*)
230−
231−instance RingWithUnity ZZ where
232− unity = 1
233−
234−
235−instance Semigroup a => Semigroup (Complex a) where
236− (<+>) (a :+ b) (c :+ d) = (a <+> c) :+ (b <+> d)
237−
238−instance Monoid a => Monoid (Complex a) where
239− neutral = (neutral :+ neutral)
240−
241−instance Group a => Group (Complex a) where
242− inverse (r :+ i) = (inverse r :+ inverse i)
243−
244−instance Ring a => AbelianGroup (Complex a) where {}
245−
246−instance Ring a => Ring (Complex a) where
247− (<.>) (a :+ b) (c :+ d) = (a <.> c <-> b <.> d) :+ (a <.> d <+> b <.> c)
248−
249−instance RingWithUnity a => RingWithUnity (Complex a) where
250− unity = (unity :+ neutral)
libs/contrib/contrib.ipkg+2
@@ -2,6 +2,8 @@ package contrib
22
33opts = "--nobasepkgs --total -i ../prelude -i ../base"
44modules = Control.Algebra,
5+ Control.Algebra.Lattice, Control.Algebra.VectorSpace,
6+ Control.Algebra.NumericInstances,
57 Control.Isomorphism.Primitives,
68 Control.Partial,
79 Control.WellFounded,
libs/prelude/Prelude/Algebra.idr−4
@@ -2,11 +2,7 @@ module Prelude.Algebra
22
33import Builtins
44
5−-- XXX: change?
6−infixl 6 <->
75infixl 6 <+>
8−infixl 6 <.>
9−infixl 5 <#>
106
117%access public
128