on master help sign in
Move Algebra to contrib properly
commit41d0309f2b300d0afc2748fe9d6048e21c1438ff authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateThu 19 Mar 2015, 17:10 (12 years ago) parentaf65583
10 files changed+120−351
libs/contrib/Classes/Verified.idr+114 libs/contrib/Data/Heap.idr+1−3 libs/contrib/Data/Matrix.idr+2−8 libs/contrib/contrib.ipkg+3−1 libs/prelude/Prelude/Algebra.idr−294 libs/prelude/Prelude/Applicative.idr−11 libs/prelude/Prelude/Functor.idr−6 libs/prelude/Prelude/List.idr−6 libs/prelude/Prelude/Monad.idr−10 libs/prelude/Prelude/Nat.idr−12
libs/contrib/Classes/Verified.idrnew file+114
@@ -0,0 +1,114 @@
1+module Classes.Verified
2+
3+import Control.Algebra
4+
5+-- Due to these being basically unused and difficult to implement,
6+-- they're in contrib for a bit. Once a design is found that lets them
7+-- be implemented for a number of instances, and we get those
8+-- implementations, then some of them can move back to base (or even
9+-- prelude, in the cases of Functor, Applicative, Monad, Semigroup,
10+-- and Monoid).
11+
12+class Functor f => VerifiedFunctor (f : Type -> Type) where
13+ functorIdentity : {a : Type} -> (x : f a) -> map id x = id x
14+ functorComposition : {a : Type} -> {b : Type} -> (x : f a) ->
15+ (g1 : a -> b) -> (g2 : b -> c) ->
16+ map (g2 . g1) x = (map g2 . map g1) x
17+
18+
19+
20+class (Applicative f, VerifiedFunctor f) => VerifiedApplicative (f : Type -> Type) where
21+ applicativeMap : (x : f a) -> (g : a -> b) ->
22+ map g x = pure g <*> x
23+ applicativeIdentity : (x : f a) -> pure id <*> x = x
24+ applicativeComposition : (x : f a) -> (g1 : f (a -> b)) -> (g2 : f (b -> c)) ->
25+ ((pure (.) <*> g2) <*> g1) <*> x = g2 <*> (g1 <*> x)
26+ applicativeHomomorphism : (x : a) -> (g : a -> b) ->
27+ (<*>) {f} (pure g) (pure x) = pure {f} (g x)
28+ applicativeInterchange : (x : a) -> (g : f (a -> b)) ->
29+ g <*> pure x = pure (\g' : a -> b => g' x) <*> g
30+
31+
32+class (Monad m, VerifiedApplicative m) => VerifiedMonad (m : Type -> Type) where
33+ monadApplicative : (mf : m (a -> b)) -> (mx : m a) ->
34+ mf <*> mx = mf >>= \f =>
35+ mx >>= \x =>
36+ pure (f x)
37+ monadLeftIdentity : (x : a) -> (f : a -> m b) -> return x >>= f = f x
38+ monadRightIdentity : (mx : m a) -> mx >>= return = mx
39+ monadAssociativity : (mx : m a) -> (f : a -> m b) -> (g : b -> m c) ->
40+ (mx >>= f) >>= g = mx >>= (\x => f x >>= g)
41+
42+
43+class Semigroup a => VerifiedSemigroup a where
44+ total semigroupOpIsAssociative : (l, c, r : a) -> l <+> (c <+> r) = (l <+> c) <+> r
45+
46+instance VerifiedSemigroup (List a) where
47+ semigroupOpIsAssociative = appendAssociative
48+
49+--instance VerifiedSemigroup Nat where
50+-- semigroupOpIsAssociative = plusAssociative
51+
52+
53+class (VerifiedSemigroup a, Monoid a) => VerifiedMonoid a where
54+ total monoidNeutralIsNeutralL : (l : a) -> l <+> neutral = l
55+ total monoidNeutralIsNeutralR : (r : a) -> neutral <+> r = r
56+
57+-- instance VerifiedMonoid Nat where
58+-- monoidNeutralIsNeutralL = plusZeroRightNeutral
59+-- monoidNeutralIsNeutralR = plusZeroLeftNeutral
60+
61+instance VerifiedMonoid (List a) where
62+ monoidNeutralIsNeutralL = appendNilRightNeutral
63+ monoidNeutralIsNeutralR xs = Refl
64+
65+class (VerifiedMonoid a, Group a) => VerifiedGroup a where
66+ total groupInverseIsInverseL : (l : a) -> l <+> inverse l = neutral
67+ total groupInverseIsInverseR : (r : a) -> inverse r <+> r = neutral
68+
69+class (VerifiedGroup a, AbelianGroup a) => VerifiedAbelianGroup a where
70+ total abelianGroupOpIsCommutative : (l, r : a) -> l <+> r = r <+> l
71+
72+class (VerifiedAbelianGroup a, Ring a) => VerifiedRing a where
73+ total ringOpIsAssociative : (l, c, r : a) -> l <.> (c <.> r) = (l <.> c) <.> r
74+ total ringOpIsDistributiveL : (l, c, r : a) -> l <.> (c <+> r) = (l <.> c) <+> (l <.> r)
75+ total ringOpIsDistributiveR : (l, c, r : a) -> (l <+> c) <.> r = (l <.> r) <+> (c <.> r)
76+
77+class (VerifiedRing a, RingWithUnity a) => VerifiedRingWithUnity a where
78+ total ringWithUnityIsUnityL : (l : a) -> l <.> unity = l
79+ total ringWithUnityIsUnityR : (r : a) -> unity <.> r = r
80+
81+class JoinSemilattice a => VerifiedJoinSemilattice a where
82+ total joinSemilatticeJoinIsAssociative : (l, c, r : a) -> join l (join c r) = join (join l c) r
83+ total joinSemilatticeJoinIsCommutative : (l, r : a) -> join l r = join r l
84+ total joinSemilatticeJoinIsIdempotent : (e : a) -> join e e = e
85+
86+class MeetSemilattice a => VerifiedMeetSemilattice a where
87+ total meetSemilatticeMeetIsAssociative : (l, c, r : a) -> meet l (meet c r) = meet (meet l c) r
88+ total meetSemilatticeMeetIsCommutative : (l, r : a) -> meet l r = meet r l
89+ total meetSemilatticeMeetIsIdempotent : (e : a) -> meet e e = e
90+
91+class (VerifiedJoinSemilattice a, BoundedJoinSemilattice a) => VerifiedBoundedJoinSemilattice a where
92+ total boundedJoinSemilatticeBottomIsBottom : (e : a) -> join e bottom = e
93+
94+class (VerifiedMeetSemilattice a, BoundedMeetSemilattice a) => VerifiedBoundedMeetSemilattice a where
95+ total boundedMeetSemilatticeTopIsTop : (e : a) -> meet e top = e
96+
97+class (VerifiedJoinSemilattice a, VerifiedMeetSemilattice a) => VerifiedLattice a where
98+ total latticeMeetAbsorbsJoin : (l, r : a) -> meet l (join l r) = l
99+ total latticeJoinAbsorbsMeet : (l, r : a) -> join l (meet l r) = l
100+
101+class (VerifiedBoundedJoinSemilattice a, VerifiedBoundedMeetSemilattice a, VerifiedLattice a) => VerifiedBoundedLattice a where { }
102+
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)
112+
113+-- class (VerifiedField a, VerifiedModule a b) => VerifiedVectorSpace a b where {}
114+
libs/contrib/Data/Heap.idr+1−3
@@ -5,6 +5,7 @@
55
66module Data.Heap
77
8+
89%default total
910%access public
1011
@@ -128,9 +129,6 @@ instance Ord a => Semigroup (MaxiphobicHeap a) where
128129instance Ord a => Monoid (MaxiphobicHeap a) where
129130 neutral = empty
130131
131−instance Ord a => JoinSemilattice (MaxiphobicHeap a) where
132− join = merge
133−
134132--------------------------------------------------------------------------------
135133-- Properties
136134--------------------------------------------------------------------------------
libs/contrib/Data/Matrix.idr+2−8
@@ -1,5 +1,7 @@
11module Data.Matrix
22
3+import Control.Algebra
4+
35import Data.Complex
46import Data.ZZ
57import Data.Fin
@@ -212,14 +214,6 @@ instance Semigroup Nat where
212214instance Monoid Nat where
213215 neutral = 0
214216
215−instance VerifiedSemigroup Nat where
216− semigroupOpIsAssociative = plusAssociative
217−
218−instance VerifiedMonoid Nat where
219− monoidNeutralIsNeutralL = plusZeroRightNeutral
220− monoidNeutralIsNeutralR = plusZeroLeftNeutral
221−
222−
223217instance Semigroup ZZ where
224218 (<+>) = (+)
225219
libs/contrib/contrib.ipkg+3−1
@@ -1,7 +1,9 @@
11package contrib
22
33opts = "--nobasepkgs --total -i ../prelude -i ../base"
4−modules = Control.Isomorphism.Primitives,
4+modules = Control.Algebra,
5+ Control.Isomorphism.Primitives,
6+ Classes.Verified,
57 Data.Fun, Data.Rel, Data.Buffer,
68 Data.Hash, Data.Matrix,
79 Data.ZZ, Data.Sign,
libs/prelude/Prelude/Algebra.idr−294
@@ -22,8 +22,6 @@ infixl 5 <#>
2222class Semigroup a where
2323 (<+>) : a -> a -> a
2424
25−class Semigroup a => VerifiedSemigroup a where
26− total semigroupOpIsAssociative : (l, c, r : a) -> l <+> (c <+> r) = (l <+> c) <+> r
2725
2826||| Sets equipped with a single binary operation that is associative, along with
2927||| a neutral element for that binary operation. Must satisfy the following
@@ -37,295 +35,3 @@ class Semigroup a => VerifiedSemigroup a where
3735class Semigroup a => Monoid a where
3836 neutral : a
3937
40−class (VerifiedSemigroup a, Monoid a) => VerifiedMonoid a where
41− total monoidNeutralIsNeutralL : (l : a) -> l <+> neutral = l
42− total monoidNeutralIsNeutralR : (r : a) -> neutral <+> r = r
43−
44−||| Sets equipped with a single binary operation that is associative, along with
45−||| a neutral element for that binary operation and inverses for all elements.
46−||| Must satisfy the following laws:
47−||| + Associativity of `<+>`:
48−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
49−||| + Neutral for `<+>`:
50−||| forall a, a <+> neutral == a
51−||| forall a, neutral <+> a == a
52−||| + Inverse for `<+>`:
53−||| forall a, a <+> inverse a == neutral
54−||| forall a, inverse a <+> a == neutral
55−class Monoid a => Group a where
56− inverse : a -> a
57−
58−class (VerifiedMonoid a, Group a) => VerifiedGroup a where
59− total groupInverseIsInverseL : (l : a) -> l <+> inverse l = neutral
60− total groupInverseIsInverseR : (r : a) -> inverse r <+> r = neutral
61−
62−(<->) : Group a => a -> a -> a
63−(<->) left right = left <+> (inverse right)
64−
65−||| Sets equipped with a single binary operation that is associative and
66−||| commutative, along with a neutral element for that binary operation and
67−||| inverses for all elements. Must satisfy the following laws:
68−|||
69−||| + Associativity of `<+>`:
70−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
71−||| + Commutativity of `<+>`:
72−||| forall a b, a <+> b == b <+> a
73−||| + Neutral for `<+>`:
74−||| forall a, a <+> neutral == a
75−||| forall a, neutral <+> a == a
76−||| + Inverse for `<+>`:
77−||| forall a, a <+> inverse a == neutral
78−||| forall a, inverse a <+> a == neutral
79−class Group a => AbelianGroup a where { }
80−
81−class (VerifiedGroup a, AbelianGroup a) => VerifiedAbelianGroup a where
82− total abelianGroupOpIsCommutative : (l, r : a) -> l <+> r = r <+> l
83−
84−||| Sets equipped with two binary operations, one associative and commutative
85−||| supplied with a neutral element, and the other associative, with
86−||| distributivity laws relating the two operations. Must satisfy the following
87−||| laws:
88−|||
89−||| + Associativity of `<+>`:
90−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
91−||| + Commutativity of `<+>`:
92−||| forall a b, a <+> b == b <+> a
93−||| + Neutral for `<+>`:
94−||| forall a, a <+> neutral == a
95−||| forall a, neutral <+> a == a
96−||| + Inverse for `<+>`:
97−||| forall a, a <+> inverse a == neutral
98−||| forall a, inverse a <+> a == neutral
99−||| + Associativity of `<.>`:
100−||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
101−||| + Distributivity of `<.>` and `<->`:
102−||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
103−||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
104−class AbelianGroup a => Ring a where
105− (<.>) : a -> a -> a
106−
107−class (VerifiedAbelianGroup a, Ring a) => VerifiedRing a where
108− total ringOpIsAssociative : (l, c, r : a) -> l <.> (c <.> r) = (l <.> c) <.> r
109− total ringOpIsDistributiveL : (l, c, r : a) -> l <.> (c <+> r) = (l <.> c) <+> (l <.> r)
110− total ringOpIsDistributiveR : (l, c, r : a) -> (l <+> c) <.> r = (l <.> r) <+> (c <.> r)
111−
112−||| Sets equipped with two binary operations, one associative and commutative
113−||| supplied with a neutral element, and the other associative supplied with a
114−||| neutral element, with distributivity laws relating the two operations. Must
115−||| satisfy the following laws:
116−|||
117−||| + Associativity of `<+>`:
118−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
119−||| + Commutativity of `<+>`:
120−||| forall a b, a <+> b == b <+> a
121−||| + Neutral for `<+>`:
122−||| forall a, a <+> neutral == a
123−||| forall a, neutral <+> a == a
124−||| + Inverse for `<+>`:
125−||| forall a, a <+> inverse a == neutral
126−||| forall a, inverse a <+> a == neutral
127−||| + Associativity of `<.>`:
128−||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
129−||| + Neutral for `<.>`:
130−||| forall a, a <.> unity == a
131−||| forall a, unity <.> a == a
132−||| + Distributivity of `<.>` and `<->`:
133−||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
134−||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
135−class Ring a => RingWithUnity a where
136− unity : a
137−
138−class (VerifiedRing a, RingWithUnity a) => VerifiedRingWithUnity a where
139− total ringWithUnityIsUnityL : (l : a) -> l <.> unity = l
140− total ringWithUnityIsUnityR : (r : a) -> unity <.> r = r
141−
142−||| Sets equipped with a binary operation that is commutative, associative and
143−||| idempotent. Must satisfy the following laws:
144−|||
145−||| + Associativity of join:
146−||| forall a b c, join a (join b c) == join (join a b) c
147−||| + Commutativity of join:
148−||| forall a b, join a b == join b a
149−||| + Idempotency of join:
150−||| forall a, join a a == a
151−|||
152−||| Join semilattices capture the notion of sets with a "least upper bound".
153−class JoinSemilattice a where
154− join : a -> a -> a
155−
156−class JoinSemilattice a => VerifiedJoinSemilattice a where
157− total joinSemilatticeJoinIsAssociative : (l, c, r : a) -> join l (join c r) = join (join l c) r
158− total joinSemilatticeJoinIsCommutative : (l, r : a) -> join l r = join r l
159− total joinSemilatticeJoinIsIdempotent : (e : a) -> join e e = e
160−
161−||| Sets equipped with a binary operation that is commutative, associative and
162−||| idempotent. Must satisfy the following laws:
163−|||
164−||| + Associativity of meet:
165−||| forall a b c, meet a (meet b c) == meet (meet a b) c
166−||| + Commutativity of meet:
167−||| forall a b, meet a b == meet b a
168−||| + Idempotency of meet:
169−||| forall a, meet a a == a
170−|||
171−||| Meet semilattices capture the notion of sets with a "greatest lower bound".
172−class MeetSemilattice a where
173− meet : a -> a -> a
174−
175−class MeetSemilattice a => VerifiedMeetSemilattice a where
176− total meetSemilatticeMeetIsAssociative : (l, c, r : a) -> meet l (meet c r) = meet (meet l c) r
177− total meetSemilatticeMeetIsCommutative : (l, r : a) -> meet l r = meet r l
178− total meetSemilatticeMeetIsIdempotent : (e : a) -> meet e e = e
179−
180−||| Sets equipped with a binary operation that is commutative, associative and
181−||| idempotent and supplied with a unitary element. Must satisfy the following
182−||| laws:
183−|||
184−||| + Associativity of join:
185−||| forall a b c, join a (join b c) == join (join a b) c
186−||| + Commutativity of join:
187−||| forall a b, join a b == join b a
188−||| + Idempotency of join:
189−||| forall a, join a a == a
190−||| + Bottom (Unitary Element):
191−||| forall a, join a bottom == a
192−|||
193−||| Join semilattices capture the notion of sets with a "least upper bound"
194−||| equipped with a "bottom" element.
195−class JoinSemilattice a => BoundedJoinSemilattice a where
196− bottom : a
197−
198−class (VerifiedJoinSemilattice a, BoundedJoinSemilattice a) => VerifiedBoundedJoinSemilattice a where
199− total boundedJoinSemilatticeBottomIsBottom : (e : a) -> join e bottom = e
200−
201−||| Sets equipped with a binary operation that is commutative, associative and
202−||| idempotent and supplied with a unitary element. Must satisfy the following
203−||| laws:
204−|||
205−||| + Associativity of meet:
206−||| forall a b c, meet a (meet b c) == meet (meet a b) c
207−||| + Commutativity of meet:
208−||| forall a b, meet a b == meet b a
209−||| + Idempotency of meet:
210−||| forall a, meet a a == a
211−||| + Top (Unitary Element):
212−||| forall a, meet a top == a
213−|||
214−||| Meet semilattices capture the notion of sets with a "greatest lower bound"
215−||| equipped with a "top" element.
216−class MeetSemilattice a => BoundedMeetSemilattice a where
217− top : a
218−
219−class (VerifiedMeetSemilattice a, BoundedMeetSemilattice a) => VerifiedBoundedMeetSemilattice a where
220− total boundedMeetSemilatticeTopIsTop : (e : a) -> meet e top = e
221−
222−||| Sets equipped with two binary operations that are both commutative,
223−||| associative and idempotent, along with absorbtion laws for relating the two
224−||| binary operations. Must satisfy the following:
225−|||
226−||| + Associativity of meet and join:
227−||| forall a b c, meet a (meet b c) == meet (meet a b) c
228−||| forall a b c, join a (join b c) == join (join a b) c
229−||| + Commutativity of meet and join:
230−||| forall a b, meet a b == meet b a
231−||| forall a b, join a b == join b a
232−||| + Idempotency of meet and join:
233−||| forall a, meet a a == a
234−||| forall a, join a a == a
235−||| + Absorbtion laws for meet and join:
236−||| forall a b, meet a (join a b) == a
237−||| forall a b, join a (meet a b) == a
238−class (JoinSemilattice a, MeetSemilattice a) => Lattice a where { }
239−
240−class (VerifiedJoinSemilattice a, VerifiedMeetSemilattice a) => VerifiedLattice a where
241− total latticeMeetAbsorbsJoin : (l, r : a) -> meet l (join l r) = l
242− total latticeJoinAbsorbsMeet : (l, r : a) -> join l (meet l r) = l
243−
244−||| Sets equipped with two binary operations that are both commutative,
245−||| associative and idempotent and supplied with neutral elements, along with
246−||| absorbtion laws for relating the two binary operations. Must satisfy the
247−||| following:
248−|||
249−||| + Associativity of meet and join:
250−||| forall a b c, meet a (meet b c) == meet (meet a b) c
251−||| forall a b c, join a (join b c) == join (join a b) c
252−||| + Commutativity of meet and join:
253−||| forall a b, meet a b == meet b a
254−||| forall a b, join a b == join b a
255−||| + Idempotency of meet and join:
256−||| forall a, meet a a == a
257−||| forall a, join a a == a
258−||| + Absorbtion laws for meet and join:
259−||| forall a b, meet a (join a b) == a
260−||| forall a b, join a (meet a b) == a
261−||| + Neutral for meet and join:
262−||| forall a, meet a top == top
263−||| forall a, join a bottom == bottom
264−class (BoundedJoinSemilattice a, BoundedMeetSemilattice a) => BoundedLattice a where { }
265−
266−class (VerifiedBoundedJoinSemilattice a, VerifiedBoundedMeetSemilattice a, VerifiedLattice a) => VerifiedBoundedLattice a where { }
267−
268−-- Fields.
269−||| Sets equipped with two binary operations, both associative and commutative
270−||| supplied with a neutral element, with
271−||| distributivity laws relating the two operations. Must satisfy the following
272−||| laws:
273−|||
274−||| + Associativity of `<+>`:
275−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
276−||| + Commutativity of `<+>`:
277−||| forall a b, a <+> b == b <+> a
278−||| + Neutral for `<+>`:
279−||| forall a, a <+> neutral == a
280−||| forall a, neutral <+> a == a
281−||| + Inverse for `<+>`:
282−||| forall a, a <+> inverse a == neutral
283−||| forall a, inverse a <+> a == neutral
284−||| + Associativity of `<.>`:
285−||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
286−||| + Unity for `<.>`:
287−||| forall a, a <.> unity == a
288−||| forall a, unity <.> a == a
289−||| + InverseM of `<.>`:
290−||| forall a, a <.> inverseM a == unity
291−||| forall a, inverseM a <.> a == unity
292−||| + Distributivity of `<.>` and `<->`:
293−||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
294−||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
295−class RingWithUnity a => Field a where
296− inverseM : a -> a
297−
298−class (VerifiedRing a, Field a) => VerifiedField a where
299− total fieldInverseIsInverseL : (l : a) -> l <.> inverseM l = unity
300− total fieldInverseIsInverseR : (r : a) -> inverseM r <.> r = unity
301−
302−||| A module over a ring is an additive abelian group of 'vectors' endowed with a
303−||| scale operation multiplying vectors by ring elements, and distributivity laws
304−||| relating the scale operation to both ring addition and module addition.
305−||| Must satisfy the following laws:
306−|||
307−||| + Compatibility of scalar multiplication with ring multiplication:
308−||| forall a b v, a <#> (b <#> v) = (a <.> b) <#> v
309−||| + Ring unity is the identity element of scalar multiplication:
310−||| forall v, unity <#> v = v
311−||| + Distributivity of `<#>` and `<+>`:
312−||| forall a v w, a <#> (v <+> w) == (a <#> v) <+> (a <#> w)
313−||| forall a b v, (a <+> b) <#> v == (a <#> v) <+> (b <#> v)
314−class (RingWithUnity a, AbelianGroup b) => Module a b where
315− (<#>) : a -> b -> b
316−
317−class (VerifiedRingWithUnity a, VerifiedAbelianGroup b, Module a b) => VerifiedModule a b where
318− total moduleScalarMultiplyComposition : (x,y : a) -> (v : b) -> x <#> (y <#> v) = (x <.> y) <#> v
319− total moduleScalarUnityIsUnity : (v : b) -> unity {a} <#> v = v
320− total moduleScalarMultDistributiveWRTVectorAddition : (s : a) -> (v, w : b) -> s <#> (v <+> w) = (s <#> v) <+> (s <#> w)
321− total moduleScalarMultDistributiveWRTModuleAddition : (s, t : a) -> (v : b) -> (s <+> t) <#> v = (s <#> v) <+> (t <#> v)
322−
323−||| A vector space is a module over a ring that is also a field
324−class (Field a, Module a b) => VectorSpace a b where {}
325−
326−class (VerifiedField a, VerifiedModule a b) => VerifiedVectorSpace a b where {}
327−
328−-- XXX todo:
329−-- Structures where "abs" make sense.
330−-- Euclidean domains, etc.
331−-- Where to put fromInteger and fromRational?
libs/prelude/Prelude/Applicative.idr−11
@@ -19,17 +19,6 @@ instance Applicative id where
1919 pure a = a
2020 f <*> a = f a
2121
22−class (Applicative f, VerifiedFunctor f) => VerifiedApplicative (f : Type -> Type) where
23− applicativeMap : (x : f a) -> (g : a -> b) ->
24− map g x = pure g <*> x
25− applicativeIdentity : (x : f a) -> pure id <*> x = x
26− applicativeComposition : (x : f a) -> (g1 : f (a -> b)) -> (g2 : f (b -> c)) ->
27− ((pure (.) <*> g2) <*> g1) <*> x = g2 <*> (g1 <*> x)
28− applicativeHomomorphism : (x : a) -> (g : a -> b) ->
29− (<*>) {f} (pure g) (pure x) = pure {f} (g x)
30− applicativeInterchange : (x : a) -> (g : f (a -> b)) ->
31− g <*> pure x = pure (\g' : a -> b => g' x) <*> g
32−
3322infixl 2 <*
3423(<*) : Applicative f => f a -> f b -> f a
3524a <* b = map const a <*> b
libs/prelude/Prelude/Functor.idr−6
@@ -18,11 +18,5 @@ infixl 4 <$>
1818(<$>) : Functor f => (m : a -> b) -> f a -> f b
1919m <$> x = map m x
2020
21−class Functor f => VerifiedFunctor (f : Type -> Type) where
22− functorIdentity : {a : Type} -> (x : f a) -> map id x = id x
23− functorComposition : {a : Type} -> {b : Type} -> (x : f a) ->
24− (g1 : a -> b) -> (g2 : b -> c) ->
25− map (g2 . g1) x = (map g2 . map g1) x
26−
2721instance Functor id where
2822 map f a = f a
libs/prelude/Prelude/List.idr−6
@@ -809,12 +809,6 @@ hasAnyByNilFalse p (x::xs) =
809809hasAnyNilFalse : Eq a => (l : List a) -> hasAny [] l = False
810810hasAnyNilFalse l = ?hasAnyNilFalseBody
811811
812−instance VerifiedSemigroup (List a) where
813− semigroupOpIsAssociative = appendAssociative
814−
815−instance VerifiedMonoid (List a) where
816− monoidNeutralIsNeutralL = appendNilRightNeutral
817− monoidNeutralIsNeutralR xs = Refl
818812
819813--------------------------------------------------------------------------------
820814-- Proofs
libs/prelude/Prelude/Monad.idr−10
@@ -14,16 +14,6 @@ infixl 5 >>=
1414class Applicative m => Monad (m : Type -> Type) where
1515 (>>=) : m a -> (a -> m b) -> m b
1616
17−class (Monad m, VerifiedApplicative m) => VerifiedMonad (m : Type -> Type) where
18− monadApplicative : (mf : m (a -> b)) -> (mx : m a) ->
19− mf <*> mx = mf >>= \f =>
20− mx >>= \x =>
21− pure (f x)
22− monadLeftIdentity : (x : a) -> (f : a -> m b) -> return x >>= f = f x
23− monadRightIdentity : (mx : m a) -> mx >>= return = mx
24− monadAssociativity : (mx : m a) -> (f : a -> m b) -> (g : b -> m c) ->
25− (mx >>= f) >>= g = mx >>= (\x => f x >>= g)
26−
2717instance Monad id where
2818 a >>= f = f a
2919
libs/prelude/Prelude/Nat.idr−12
@@ -239,18 +239,6 @@ instance Monoid Multiplicative where
239239instance Monoid Additive where
240240 neutral = getAdditive Z
241241
242−instance MeetSemilattice Nat where
243− meet = minimum
244−
245−instance JoinSemilattice Nat where
246− join = maximum
247−
248−instance Lattice Nat where { }
249−
250−instance BoundedJoinSemilattice Nat where
251− bottom = Z
252−
253−
254242||| Casts negative `Ints` to 0.
255243instance Cast Int Nat where
256244 cast i = fromInteger (cast i)