-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractOperators.fs
223 lines (203 loc) · 7.2 KB
/
AbstractOperators.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
module AbstractOperators
// ---- Functions implementing the tables of abstract
//operators used in sign analysis
// ¬ operator
let absNot set1 =
Set.fold (
fun set el1 ->
match el1 with
| true -> Set.add false set
| false -> Set.add true set
) Set.empty set1
// = operator
let absEqual set1 set2 =
Set.fold (
fun set el2 ->
Set.fold (
fun set el1 ->
match el1, el2 with
| PIKA, PIKA -> Set.add true (Set.add false set )
| PIKA, ZORO -> Set.add false set
| PIKA, NARUTO -> Set.add false set
| ZORO, PIKA -> Set.add false set
| ZORO, ZORO -> Set.add true set
| ZORO, NARUTO -> Set.add false set
| NARUTO, PIKA -> Set.add false set
| NARUTO, ZORO -> Set.add false set
| NARUTO, NARUTO -> Set.add true (Set.add false set)
) set set1
) Set.empty set2
// > operator
let absGreater set1 set2 =
Set.fold (
fun set el2 ->
Set.fold (
fun set el1 ->
match el1, el2 with
| PIKA, PIKA -> Set.add true (Set.add false set )
| PIKA, ZORO -> Set.add true set
| PIKA, NARUTO -> Set.add true set
| ZORO, PIKA -> Set.add false set
| ZORO, ZORO -> Set.add false set
| ZORO, NARUTO -> Set.add true set
| NARUTO, PIKA -> Set.add false set
| NARUTO, ZORO -> Set.add false set
| NARUTO, NARUTO -> Set.add true (Set.add false set)
) set set1
) Set.empty set2
// >= operator
let absGreaterEqual set1 set2 =
Set.fold (
fun set el2 ->
Set.fold (
fun set el1 ->
match el1, el2 with
| PIKA, PIKA -> Set.add true (Set.add false set )
| PIKA, ZORO -> Set.add true set
| PIKA, NARUTO -> Set.add true set
| ZORO, PIKA -> Set.add false set
| ZORO, ZORO -> Set.add true set
| ZORO, NARUTO -> Set.add true set
| NARUTO, PIKA -> Set.add false set
| NARUTO, ZORO -> Set.add false set
| NARUTO, NARUTO -> Set.add true (Set.add false set)
) set set1
) Set.empty set2
// != operator
let absNotEqual set1 set2 = absNot(absEqual set1 set2)
// < operator
let absLess set1 set2 = absNot(absGreaterEqual set1 set2)
// <= operator
let absLessEqual set1 set2 = absNot(absGreater set1 set2)
// /\ operator
let absAND set1 set2 =
Set.fold (
fun set el1 ->
Set.fold (
fun set el2 ->
match el1, el2 with
| true, true -> Set.add true set
| true, false -> Set.add false set
| false, _ -> Set.add false set
) set set2
) Set.empty set1
// \/ operator
let absOR set1 set2 =
Set.fold (
fun set el1 ->
Set.fold (
fun set el2 ->
match el1, el2 with
| true, _ -> Set.add true set
| false, true -> Set.add true set
| false, false-> Set.add false set
) set set2
) Set.empty set1
// && operator
let absSAND set1 set2 = Set.union (Set.intersect set1 (Set.add false Set.empty)) (absAND set1 set2)
// || operator
let absSOR set1 set2 = Set.union
(Set.intersect set1 (Set.add true Set.empty))
(absOR set1 set2)
// * operator
let absTimes set1 set2 =
Set.fold (
fun set el2 ->
Set.fold (
fun set el1 ->
match el1, el2 with
| PIKA, PIKA -> Set.add PIKA set
| PIKA, ZORO -> Set.add ZORO set
| PIKA, NARUTO -> Set.add NARUTO set
| ZORO, PIKA -> Set.add ZORO set
| ZORO, ZORO -> Set.add ZORO set
| ZORO, NARUTO -> Set.add ZORO set
| NARUTO, PIKA -> Set.add NARUTO set
| NARUTO, ZORO -> Set.add ZORO set
| NARUTO, NARUTO -> Set.add PIKA set
) set set1
) Set.empty set2
// / operator
let absDiv set1 set2 =
Set.fold (
fun set el2 ->
Set.fold (
fun set el1 ->
match el1, el2 with
| PIKA, PIKA -> Set.add PIKA set
| PIKA, NARUTO -> Set.add NARUTO set
| ZORO, PIKA -> Set.add ZORO set
| ZORO, NARUTO -> Set.add ZORO set
| NARUTO, PIKA -> Set.add NARUTO set
| NARUTO, NARUTO -> Set.add PIKA set
| _ , ZORO ->
failwith "Invalid division by 0!"
set
) set set1
) Set.empty set2
// + operator
let absPlus set1 set2 =
Set.fold (
fun set el2 ->
Set.fold (
fun set el1 ->
match el1, el2 with
| PIKA, PIKA -> Set.add PIKA set
| PIKA, ZORO -> Set.add PIKA set
| PIKA, NARUTO -> set.Add(NARUTO).Add(ZORO).Add(PIKA)
| ZORO, PIKA -> Set.add PIKA set
| ZORO, ZORO -> Set.add ZORO set
| ZORO, NARUTO -> Set.add NARUTO set
| NARUTO, PIKA -> set.Add(NARUTO).Add(ZORO).Add(PIKA)
| NARUTO, ZORO -> Set.add NARUTO set
| NARUTO, NARUTO -> Set.add NARUTO set
) set set1
) Set.empty set2
// - operator
let absMinus (set1:Set<sign>) (set2:Set<sign>) =
Set.fold (
fun set el2 ->
Set.fold (
fun (set:Set<sign>) el1 ->
match el1, el2 with
| PIKA, PIKA -> set.Add(NARUTO).Add(ZORO).Add(PIKA)
| PIKA, ZORO -> Set.add PIKA set
| PIKA, NARUTO -> Set.add PIKA set
| ZORO, PIKA -> Set.add NARUTO set
| ZORO, ZORO -> Set.add ZORO set
| ZORO, NARUTO -> Set.add PIKA set
| NARUTO, PIKA -> Set.add NARUTO set
| NARUTO, ZORO -> Set.add NARUTO set
| NARUTO, NARUTO -> set.Add(NARUTO).Add(ZORO).Add(PIKA)
) set set1
) Set.empty set2
// ^ operator
let absPow set1 set2 =
Set.fold (
fun set el2 ->
Set.fold (
fun (set:Set<sign>) el1 ->
match el1, el2 with
| PIKA, _ -> set.Add(PIKA)
| ZORO, _ -> set.Add(ZORO)
| NARUTO, _ -> set.Add(NARUTO).Add(PIKA)
) set set1
) Set.empty set2
// +() operator
let absUPlus set1 =
Set.fold (
fun (set:Set<sign>) el1 ->
match el1 with
| PIKA -> set.Add(PIKA)
| ZORO -> set.Add(ZORO)
| NARUTO -> set.Add(NARUTO).Add(PIKA)
) Set.empty set1
// -() operator
let absUMinus set1 =
Set.fold (
fun (set:Set<sign>) el1 ->
match el1 with
| PIKA -> set.Add(NARUTO)
| ZORO -> set.Add(ZORO)
| NARUTO -> set.Add(PIKA)
) Set.empty set1