on master help sign in
Update Matrix.idr
3409a3eCliff Harvey
libs/base/Data/Matrix.idr+29−1
@@ -156,9 +156,34 @@ Zero {d} = replicate d zero
156-- Matrix Algebra Properties
156-- Matrix Algebra Properties
157-----------------------------------------------------------------------
157-----------------------------------------------------------------------
158
158
159+instance Semigroup a => Semigroup (Vect n a) where
160+ (<+>) v w = zipWith (<+>) v w
159
161
160−-- TODO: Prove properties of matrix algebra for 'Verified' algebraic classes
162+instance Monoid a => Monoid (Vect n a) where
163+ neutral {n} = replicate n neutral
164+
165+instance Group a => Group (Vect n a) where
166+ inverse = map inverse
167+
168+instance AbelianGroup a => AbelianGroup (Vect n a) where {}
169+
170+instance Ring a => Ring (Vect n a) where
171+ (<*>) v w = zipWith (<*>) v w
172+
173+instance RingWithUnity a => RingWithUnity (Vect n a) where
174+ unity {n} = replicate n unity
175+
176+instance Field a => Field (Vect n a) where
177+ inverseM = map inverseM
161
178
179+instance (Field a, AbelianGroup a) => VectorSpace a (Vect n a) where
180+ (<#>) s v = map (s <*>) v
181+
182+instance (Field a, AbelianGroup a) => VectorSpace a (Vect n (Vect n a)) where
183+ (<#>) s m = map (s <#>) m
184+
185+
186+-- TODO: Prove properties of matrix algebra for 'Verified' algebraic classes
162
187
163-----------------------------------------------------------------------
188-----------------------------------------------------------------------
164-- Numberic data types as rings
189-- Numberic data types as rings
@@ -217,6 +242,9 @@ instance Ring Float where
217instance RingWithUnity Float where
242instance RingWithUnity Float where
218 unity = 1
243 unity = 1
219
244
245+instance Field Float where
246+ inverseM f = 1 / f
247+
220
248
221instance Semigroup Nat where
249instance Semigroup Nat where
222 (<+>) = (+)
250 (<+>) = (+)