Skip to content

Commit 5be88db

Browse files
committed
changed names of constructor functions
1 parent 9482c35 commit 5be88db

6 files changed

Lines changed: 62 additions & 61 deletions

File tree

fuzzySets.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.4
22
name: fuzzySets
3-
version: 1.0.0
3+
version: 1.0.1
44
category: Math
55
license: BSD-3-Clause
66
author: Lukas Balog <lukasbalog66@gmail.com>

src/Fuzzy/Relations/LRelation.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Fuzzy.Relations.LRelation (
1212
mkEmptyRel,
1313
mkSingletonRel,
1414
mkUniversalRel,
15-
toPairs
15+
toList
1616
) where
1717

1818
import Lattices.ResiduatedLattice
@@ -121,5 +121,5 @@ mkUniversalRel u = LRelation (const top) (listToUniverse u)
121121

122122

123123
-- | Return relation as a list of pairs
124-
toPairs :: (ResiduatedLattice l, Eq a) => LRelation a l -> [((a, a), l)]
125-
toPairs (LRelation f u) = [(x, f x) | x <- u]
124+
toList :: (ResiduatedLattice l, Eq a) => LRelation a l -> [((a, a), l)]
125+
toList (LRelation f u) = [(x, f x) | x <- u]

src/Fuzzy/Sets/LSet.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Fuzzy.Sets.LSet(
77
FuzzySet(member, universe),
88
fromPairs,
99
fromFunction,
10-
toPairs,
10+
toList,
1111
mkEmptySet,
1212
mkSingletonSet,
1313
mkUniversalSet
@@ -31,7 +31,7 @@ data (ResiduatedLattice l) => LSet a l = LSet
3131

3232
instance (Eq a, Show a, Show l, ResiduatedLattice l) => Show (LSet a l) where
3333
show :: LSet a l -> String
34-
show set = "FuzzySet { " ++ show (toPairs set) ++ " }"
34+
show set = "FuzzySet { " ++ show (toList set) ++ " }"
3535

3636

3737
instance (ResiduatedLattice l, Eq a) => FuzzySet (LSet a l) a l where
@@ -57,24 +57,24 @@ fromPairs xs = LSet f u
5757
5858
>>> let f x = if x == 1 then 0.8 else 0.3
5959
>>> let set = fromFunction f [1, 2, 3] :: LSet Int UILukasiewicz
60-
>>> toPairs set
60+
>>> toList set
6161
[(1,0.8),(2,0.3),(3,0.3)]
6262
-}
6363
fromFunction :: (ResiduatedLattice l) => (a -> l) -> [a] -> LSet a l
6464
fromFunction = LSet
6565

6666

6767
-- | Convert fuzzy set to list of pairs
68-
toPairs :: (ResiduatedLattice l, Eq a) => LSet a l -> [(a, l)]
69-
toPairs (LSet f universe) = [(u, f u) | u <- universe]
68+
toList :: (ResiduatedLattice l, Eq a) => LSet a l -> [(a, l)]
69+
toList(LSet f universe) = [(u, f u) | u <- universe]
7070

7171

7272
{- | Construct an empty fuzzy set
7373
7474
==== __Examples__
7575
7676
>>> let emptySet = mkEmptySet :: LSet Int UILukasiewicz
77-
>>> toPairs emptySet
77+
>>> toList emptySet
7878
[]
7979
-}
8080
mkEmptySet :: (ResiduatedLattice l) => LSet a l
@@ -85,7 +85,7 @@ mkEmptySet = LSet (const bot) []
8585
==== __Examples__
8686
8787
>>> let singletonSet = mkSingletonSet [1, 2, 3] (2, 0.8) :: LSet Int UILukasiewicz
88-
>>> toPairs singletonSet
88+
>>> toList singletonSet
8989
[(1,0.0),(2,0.8),(3,0.0)]
9090
-}
9191
mkSingletonSet :: (ResiduatedLattice l, Eq a) => [a] -> (a, l) -> LSet a l
@@ -101,7 +101,7 @@ mkSingletonSet u (x, l) = LSet f u
101101
==== __Examples__
102102
103103
>>> let universalSet = mkUniversalSet [1, 2, 3] :: LSet Int UILukasiewicz
104-
>>> toPairs universalSet
104+
>>> toList universalSet
105105
[(1,1.0),(2,1.0),(3,1.0)]
106106
-}
107107
mkUniversalSet :: (ResiduatedLattice l, Eq a) => [a] -> LSet a l

src/Fuzzy/Sets/Properties.hs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import FuzzySet
2525
>>> isEmpty emptySet
2626
True
2727
28-
>>> let nonEmptySet = fromPairs [(1, 0.2), (2, 0.0)] :: LSet Int UILukasiewicz
28+
>>> let nonEmptySet = fromList [(1, 0.2), (2, 0.0)] :: LSet Int UILukasiewicz
2929
>>> isEmpty nonEmptySet
3030
False
3131
-}
@@ -42,7 +42,7 @@ one `u` in 'universe' for which 'member' u is greater than 'bot'.
4242
>>> isSingleton singletonSet
4343
True
4444
45-
>>> let nonSingletonSet = fromPairs [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
45+
>>> let nonSingletonSet = fromList [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
4646
>>> isSingleton nonSingletonSet
4747
False
4848
-}
@@ -54,11 +54,11 @@ isSingleton set = length (filter (> bot) (truthDegrees set)) == 1
5454
5555
==== __Examples__
5656
57-
>>> let crispSet = fromPairs [(1, 1.0), (2, 0.0)] :: LSet Int UILukasiewicz
57+
>>> let crispSet = fromList [(1, 1.0), (2, 0.0)] :: LSet Int UILukasiewicz
5858
>>> isCrisp crispSet
5959
True
6060
61-
>>> let nonCrispSet = fromPairs [(1, 0.5), (2, 0.7)] :: LSet Int UILukasiewicz
61+
>>> let nonCrispSet = fromList [(1, 0.5), (2, 0.7)] :: LSet Int UILukasiewicz
6262
>>> isCrisp nonCrispSet
6363
False
6464
-}
@@ -77,7 +77,7 @@ This means that the fuzzy set equals its universe.
7777
>>> isUniversal universalSet
7878
True
7979
80-
>>> let nonUniversalSet = fromPairs [(1, 1.0), (2, 0.8)] :: LSet Int UILukasiewicz
80+
>>> let nonUniversalSet = fromList [(1, 1.0), (2, 0.8)] :: LSet Int UILukasiewicz
8181
>>> isUniversal nonUniversalSet
8282
False
8383
-}
@@ -96,7 +96,7 @@ height _ = top
9696

9797
{- | Support is a list of all elements with non 'bot' 'member'
9898
99-
>>> let set = fromPairs [(1, 0), (2, 0.8), (3, 0), (4, 0.5), (6, 0)]
99+
>>> let set = fromList [(1, 0), (2, 0.8), (3, 0), (4, 0.5), (6, 0)]
100100
[2, 4]
101101
-}
102102
support :: (FuzzySet set a l) => set -> [a]
@@ -110,7 +110,7 @@ In other words it's a list of items with 'member' equal to 'top'
110110
111111
==== __Examples__
112112
113-
>>> let set = fromPairs [(1, 1:0), (2, 0.8), (3, 1.0), (4, 0.5), (6, 1.0)]
113+
>>> let set = fromList [(1, 1:0), (2, 0.8), (3, 1.0), (4, 0.5), (6, 1.0)]
114114
>>> core set
115115
[1, 3, 6]
116116
@@ -125,8 +125,8 @@ Membership of values from A is smaller than B for every item of universe
125125
126126
==== __Examples__
127127
128-
>>> let setA = fromPairs [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
129-
>>> let setB = fromPairs [(1, 0.3), (2, 0.7)] :: LSet Int UILukasiewicz
128+
>>> let setA = fromList [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
129+
>>> let setB = fromList [(1, 0.3), (2, 0.7)] :: LSet Int UILukasiewicz
130130
>>> strictSubsethood setA setB
131131
True
132132
@@ -142,12 +142,12 @@ Member of all values from universe in set A is equal to member of all values in
142142
143143
==== __Examples__
144144
145-
>>> let setA = fromPairs [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
146-
>>> let setB = fromPairs [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
145+
>>> let setA = fromList [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
146+
>>> let setB = fromList [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
147147
>>> strictEquality setA setB
148148
True
149149
150-
>>> let setC = fromPairs [(1, 0.3), (2, 0.5)] :: LSet Int UILukasiewicz
150+
>>> let setC = fromList [(1, 0.3), (2, 0.5)] :: LSet Int UILukasiewicz
151151
>>> strictEquality setA setC
152152
False
153153
-}
@@ -160,8 +160,8 @@ If the result is 1, we can conclude that A ⊆ B.
160160
161161
==== __Examples__
162162
163-
>>> let setA = fromPairs [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
164-
>>> let setB = fromPairs [(1, 0.3), (2, 0.7)] :: LSet Int UILukasiewicz
163+
>>> let setA = fromList [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
164+
>>> let setB = fromList [(1, 0.3), (2, 0.7)] :: LSet Int UILukasiewicz
165165
>>> gradedSubsethood setA setB
166166
1.0
167167
@@ -181,12 +181,12 @@ If the result is 1, the fuzzy sets are equal.
181181
182182
==== __Examples__
183183
184-
>>> let setA = fromPairs [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
185-
>>> let setB = fromPairs [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
184+
>>> let setA = fromList [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
185+
>>> let setB = fromList [(1, 0.2), (2, 0.5)] :: LSet Int UILukasiewicz
186186
>>> gradedEquality setA setB
187187
1.0
188188
189-
>>> let setC = fromPairs [(1, 0.3), (2, 0.5)] :: LSet Int UILukasiewicz
189+
>>> let setC = fromList [(1, 0.3), (2, 0.5)] :: LSet Int UILukasiewicz
190190
>>> gradedEquality setA setC
191191
0.9
192192
-}

src/FuzzySet.hs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mkUniversalSet = mkFuzzySet (const top)
4949
5050
==== __Examples__
5151
52-
>>> let set = fromPairs [(1, 0.1), (2, 0.2), (3. 0.4)]
52+
>>> let set = fromList [(1, 0.1), (2, 0.2), (3. 0.4)]
5353
>>> alphaCut 0.15 set
5454
[2, 3]
5555
@@ -71,16 +71,16 @@ alphaCut alpha set = [x | x <- u, f x >= alpha]
7171
7272
==== __Examples__
7373
74-
>>> let set1 = fromPairs [(1, 0.2), (2, 0.7), (3, 0.1)] :: LSet Int UILukasiewicz
75-
>>> let set2 = fromPairs [(1, 0.3), (2, 0.4)] :: LSet Int UILukasiewicz
76-
>>> let set3 = fromPairs [(1, 0.5), (2, 0.1), (4, 0.8)] :: LSet Int UILukasiewicz
77-
>>> toPairs $ union set1 set2
74+
>>> let set1 = fromList [(1, 0.2), (2, 0.7), (3, 0.1)] :: LSet Int UILukasiewicz
75+
>>> let set2 = fromList [(1, 0.3), (2, 0.4)] :: LSet Int UILukasiewicz
76+
>>> let set3 = fromList [(1, 0.5), (2, 0.1), (4, 0.8)] :: LSet Int UILukasiewicz
77+
>>> toList $ union set1 set2
7878
[(1, 0.3),(2, 0.7), (3, 0.1)]
7979
80-
>>> toPairs $ union set1 set3
80+
>>> toList $ union set1 set3
8181
[(1, 0.5), (2, 0.7), (3, 0.1), (4, 0.8)]
8282
83-
>>> toPairs $ union set1 mkEmptySet
83+
>>> toList $ union set1 mkEmptySet
8484
[(1, 0.2), (2, 0.7), (3, 0.1)]
8585
-}
8686
union :: (FuzzySet set a l) => set -> set -> set
@@ -99,16 +99,16 @@ unions sets@(set:_) = foldr union (mkUniversalSet (universe set)) sets
9999
100100
==== __Examples__
101101
102-
>>> let set1 = fromPairs [(1, 0.2), (2, 0.7), (3, 0.1)]
103-
>>> let set2 = fromPairs [(1, 0.3), (2, 0.4)]
104-
>>> let set3 = fromPairs [(1, 0.5), (2, 0.1), (4, 0.8)] :: LSet Int UILukasiewicz
105-
>>> toPairs $ intersection set1 set2
102+
>>> let set1 = fromList [(1, 0.2), (2, 0.7), (3, 0.1)]
103+
>>> let set2 = fromList [(1, 0.3), (2, 0.4)]
104+
>>> let set3 = fromList [(1, 0.5), (2, 0.1), (4, 0.8)] :: LSet Int UILukasiewicz
105+
>>> toList $ intersection set1 set2
106106
[(1, 0.2), (2, 0.4), (3, 0.0)]
107107
108-
>>> toPairs $ intersection set1 set3
108+
>>> toList $ intersection set1 set3
109109
[(1, 0.2), (2, 0.1), (3, 0.0), (4, 0.0)]
110110
111-
>>> toPairs $ intersection set1 mkEmptySet
111+
>>> toList $ intersection set1 mkEmptySet
112112
[(1, 0.0), (2, 0.0), (3, 0.0)]
113113
-}
114114
intersection :: (FuzzySet set a l) => set -> set -> set
@@ -125,12 +125,12 @@ intersections = foldr intersection mkEmptySet
125125
126126
==== __Examples__
127127
128-
>>> let set1 = fromPairs [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
129-
>>> toPairs $ complement set1
128+
>>> let set1 = fromList [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
129+
>>> toList $ complement set1
130130
[(1, 0.8),(2, 0.3)]
131131
132-
>>> let set2 = fromPairs [(1, 1), (2, 1)]
133-
>>> toPairs $ complement set2
132+
>>> let set2 = fromList [(1, 1), (2, 1)]
133+
>>> toList $ complement set2
134134
[(1, 0), (2, 0)]
135135
-}
136136
complement :: (FuzzySet set a l) => set -> set
@@ -142,9 +142,9 @@ complement set = mkFuzzySet (negation . f) (universe set)
142142
143143
==== __Examples__
144144
145-
>>> let set1 = fromPairs [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
146-
>>> let set2 = fromPairs [(1, 0.3), (2, 0.4)] :: LSet Int UILukasiewicz
147-
>>> toPairs $ setTnorm set1 set2
145+
>>> let set1 = fromList [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
146+
>>> let set2 = fromList [(1, 0.3), (2, 0.4)] :: LSet Int UILukasiewicz
147+
>>> toList $ setTnorm set1 set2
148148
[(1,0.2), (2,0.4)]
149149
-}
150150
setTnorm :: (FuzzySet set a l) => set -> set -> set
@@ -158,9 +158,9 @@ setTnorm set1 set2 = mkFuzzySet (\x -> f x `tnorm` g x) u
158158
159159
==== __Examples__
160160
161-
>>> let set1 = fromPairs [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
162-
>>> let set2 = fromPairs [(1, 0.3), (2, 0.4)] :: LSet Int UILukasiewicz
163-
>>> toPairs $ setResiduum set1 set2
161+
>>> let set1 = fromList [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
162+
>>> let set2 = fromList [(1, 0.3), (2, 0.4)] :: LSet Int UILukasiewicz
163+
>>> toList $ setResiduum set1 set2
164164
[(1,1.0), (2,0.7)]
165165
-}
166166
setResiduum :: (FuzzySet set a l) => set -> set -> set
@@ -174,9 +174,9 @@ setResiduum set1 set2 = mkFuzzySet (\x -> f x --> g x) u
174174
175175
==== __Examples__
176176
177-
>>> let set = fromPairs [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
177+
>>> let set = fromList [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
178178
>>> let modifiedSet = mapMembership set (\x -> x + 1)
179-
>>> toPairs modifiedSet
179+
>>> toList modifiedSet
180180
[(1,0.0),(2,0.0),(3,0.2)]
181181
-}
182182
mapMembership :: (FuzzySet set a l) => set -> (a -> a) -> set
@@ -190,9 +190,9 @@ mapMembership set g = mkFuzzySet (f . g) u
190190
191191
==== __Examples__
192192
193-
>>> let set = fromPairs [(1, 0.2), (2, 0.7), (3, 0.4)] :: LSet Int UILukasiewicz
193+
>>> let set = fromList [(1, 0.2), (2, 0.7), (3, 0.4)] :: LSet Int UILukasiewicz
194194
>>> let filteredSet = filterMembership set (\x -> x > 1)
195-
>>> toPairs filteredSet
195+
>>> toList filteredSet
196196
[(1,0.0),(2,0.7),(3,0.4)]
197197
-}
198198
filterMembership :: (FuzzySet set a l) => set -> (a -> Bool) -> set
@@ -207,9 +207,9 @@ filterMembership set pred = mkFuzzySet h u
207207
208208
==== __Examples__
209209
210-
>>> let set = fromPairs [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
210+
>>> let set = fromList [(1, 0.2), (2, 0.7)] :: LSet Int UILukasiewicz
211211
>>> let modifiedSet = mapU set (\x -> x * 2)
212-
>>> toPairs modifiedSet
212+
>>> toList modifiedSet
213213
[(2,0.2),(4,0.7)]
214214
-}
215215
mapU :: (FuzzySet set a l) => set -> (a -> a) -> set
@@ -223,9 +223,9 @@ mapU set g = mkFuzzySet f u
223223
224224
==== __Examples__
225225
226-
>>> let set = fromPairs [(1, 0.2), (2, 0.7), (3, 0.4)] :: LSet Int UILukasiewicz
226+
>>> let set = fromList [(1, 0.2), (2, 0.7), (3, 0.4)] :: LSet Int UILukasiewicz
227227
>>> let filteredSet = filterU set (\x -> x > 1)
228-
>>> toPairs filteredSet
228+
>>> toList filteredSet
229229
[(2,0.7),(3,0.4)]
230230
-}
231231
filterU :: (FuzzySet set a l) => set -> (a -> Bool) -> set

src/Lattices/UnitInterval.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Lattices.UnitInterval(
66
) where
77

88
import Lattices.ResiduatedLattice
9+
import Data.Ord (clamp)
910

1011
-- | unit interval on real numbers [0,1]
1112
newtype UnitInterval = UnitInterval Double
@@ -23,4 +24,4 @@ instance Show UnitInterval where
2324

2425
-- | Unit interval constructor. Ensures values are in bounds
2526
mkUnitInterval :: Double -> UnitInterval
26-
mkUnitInterval x = UnitInterval $ max 0 $ min 1 x
27+
mkUnitInterval x = UnitInterval $ clamp (0, 1) x

0 commit comments

Comments
 (0)