bool.anubis
3.43 KB
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
The Anubis project.
Utilities around the booleans.
(reformated by AP, 2014/07/31)
*** (1) Logical operations for booleans.
public define macro Bool Bool x | Bool y. the disjunction (logical 'or')
public define macro Bool Bool x & Bool y. the conjunction (logical 'and')
The above two macros are already defined in 'library/predefined.anubis'.
public define macro Bool xor(Bool x, Bool y). the exclusive disjunction
public define macro Bool not (Bool x). the negation (logical 'not')
public define macro Bool ~ Bool x. the negation again, with a shorter syntax
*** (2) Logical operations for boolean predicates.
Same as above, but applying to data of type $T -> Bool ('predicates')
instead of data of type Bool ('booleans'), and of course returning predicates.
public define $T -> Bool $T -> Bool p | $T -> Bool q.
public define $T -> Bool $T -> Bool p & $T -> Bool q.
public define $T -> Bool xor($T -> Bool p, $T -> Bool q).
public define $T -> Bool not ($T -> Bool p).
public define $T -> Bool ~ $T -> Bool p.
*** (3) Logical 'or' and 'and' for a predicate applied to a list of elements.
'mapand(p,l)' is true if 'p' returns true for all elements of 'l'.
'mapor(p,l)' is true if 'p' returns true for at least one element of 'l'.
public define Bool mapand ($T -> Bool p, List($T) l).
public define Bool mapor ($T -> Bool p, List($T) l).
Of course, 'mapand(p,[])' is true and 'mapor(p,[])' is false.
*** (4) Non equality (with boolean value).
This is just the negation of equality.
public define macro Bool $T x /= $T y. true if x is not equal to y
public define macro Bool $T x != $T y. the same one with the C syntax
--- That's all for the public part ! ------------------------------
public define macro Bool // moved to predefined.anubis
$T x /= $T y
=
if x = y then false else true.
public define macro Bool
$T x != $T y
=
if x = y then false else true.
public define macro Bool
not
(
Bool x
) =
if x then false else true.
public define macro Bool
~ Bool x
=
if x then false else true.
public define macro Bool
xor
(
Bool x,
Bool y
) =
if x = y then false else true.
public define $T -> Bool
$T -> Bool f | $T -> Bool g
=
($T x) |-> if f(x) then true else g(x).
public define $T -> Bool
$T -> Bool f & $T -> Bool g
=
($T x) |-> if f(x) then g(x) else false.
public define $T -> Bool
xor
(
$T -> Bool p,
$T -> Bool q
) =
($T x) |-> if p(x) = q(x) then false else true.
public define $T -> Bool
not
(
$T -> Bool f
) =
($T t) |-> not(f(t)).
public define Bool
mapand
(
$T -> Bool test,
List($T) l
) =
if l is
{
[ ] then true,
[h . t] then
if test(h)
then mapand(test,t)
else false
}.
public define Bool
mapor
(
$T -> Bool test,
List($T) l
) =
if l is
{
[ ] then false,
[h . t] then
if test(h)
then true
else mapor(test,t)
}.