on master help sign in
Update Matrix.idr

Instantiate algebraic classes for Vect's of those classes

commit3409a3ef6fe373380ab63dbc0431864c8f962022 authorCliff Harvey <cs.hbar@gmail.com> dateSun 2 Nov 2014, 02:25 (12 years ago) parentb2f6153
1 file changed+29−1
libs/base/Data/Matrix.idr+29−1
libs/base/Data/Matrix.idr+29−1
@@ -156,9 +156,34 @@ Zero {d} = replicate d zero
156156-- Matrix Algebra Properties
157157-----------------------------------------------------------------------
158158
159+instance Semigroup a => Semigroup (Vect n a) where
160+ (<+>) v w = zipWith (<+>) v w
159161
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
161178
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
162187
163188-----------------------------------------------------------------------
164189-- Numberic data types as rings
@@ -217,6 +242,9 @@ instance Ring Float where
217242instance RingWithUnity Float where
218243 unity = 1
219244
245+instance Field Float where
246+ inverseM f = 1 / f
247+
220248
221249instance Semigroup Nat where
222250 (<+>) = (+)