-
Notifications
You must be signed in to change notification settings - Fork 6
/
dk_bool.dk
125 lines (109 loc) · 2.79 KB
/
dk_bool.dk
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
#REQUIRE cc.
(; Bool ;)
(; Declaration ;)
bool : cc.uT.
Bool : Type.
[] cc.eT bool --> Bool.
(; Constructors ;)
true : Bool.
false : Bool.
(; Pattern-matching ;)
def match :
P : (Bool -> cc.uT) ->
cc.eT (P true) ->
cc.eT (P false) ->
b : Bool ->
cc.eT (P b).
[P : Bool -> cc.uT,
Ht : cc.eT (P true),
Hf : cc.eT (P false) ]
match P Ht Hf true --> Ht
[P : Bool -> cc.uT,
Ht : cc.eT (P true),
Hf : cc.eT (P false) ]
match P Ht Hf false --> Hf.
(; Operations ;)
(; polymorphic if .. then .. else .. ;)
def ite :
A : cc.uT ->
Bool ->
cc.eT A ->
cc.eT A ->
cc.eT A.
[ A : cc.uT,
x : cc.eT A,
y : cc.eT A,
b : Bool ]
ite A b x y
-->
match (b : Bool => A) x y b.
def match__true :
Bool ->
A : cc.uT ->
cc.eT A ->
cc.eT A ->
cc.eT A.
[ A : cc.uT, b : Bool, t : cc.eT A, e : cc.eT A]
match__true b A t e --> ite A b t e.
def match__false :
Bool ->
A : cc.uT ->
cc.eT A ->
cc.eT A ->
cc.eT A.
[ A : cc.uT, b : Bool, t : cc.eT A, e : cc.eT A]
match__false b A t e --> ite A b e t.
(; boolean if .. then .. else .. ;)
def iteb : Bool -> Bool -> Bool -> Bool
:= ite bool.
(; negation ;)
def not : Bool -> Bool.
[] not true --> false
[] not false --> true
[ b : Bool ] not (not b) --> b.
(; binary operators ;)
def and : Bool -> Bool -> Bool.
[ b : Bool ] and b true --> b
[ b : Bool ] and true b --> b
[ b : Bool ] and b false --> false
[ b : Bool ] and false b --> false.
def or : Bool -> Bool -> Bool.
[ b : Bool ] or b true --> true
[ b : Bool ] or true b --> true
[ b : Bool ] or b false --> b
[ b : Bool ] or false b --> b.
def xor : Bool -> Bool -> Bool.
[ b : Bool ] xor b true --> not b
[ b : Bool ] xor true b --> not b
[ b : Bool ] xor b false --> b
[ b : Bool ] xor false b --> b.
def imp : Bool -> Bool -> Bool.
[ b : Bool ] imp b true --> true
[ b : Bool ] imp true b --> b
[ b : Bool ] imp b false --> not b
[ b : Bool ] imp false b --> true.
def eqv : Bool -> Bool -> Bool.
[ b : Bool ] eqv b true --> b
[ b : Bool ] eqv true b --> b
[ b : Bool ] eqv b false --> not b
[ b : Bool ] eqv false b --> not b.
(; Associativity ;)
[ b1 : Bool, b2 : Bool, b3 : Bool ]
and b1 (and b2 b3) --> and (and b1 b2) b3.
[ b1 : Bool, b2 : Bool, b3 : Bool ]
or b1 (or b2 b3) --> or (or b1 b2) b3.
[ b1 : Bool, b2 : Bool, b3 : Bool ]
xor b1 (xor b2 b3) --> xor (xor b1 b2) b3.
(; Distributivity ;)
[ b1 : Bool, b2 : Bool, b3 : Bool ]
and b1 (or b2 b3) --> or (and b1 b2) (and b1 b3).
[ b1 : Bool, b2 : Bool, b3 : Bool ]
and (or b1 b2) b3 --> or (and b1 b3) (and b2 b3).
[ b1 : Bool, b2 : Bool ]
not (and b1 b2) --> or (not b1) (not b2).
[ b1 : Bool, b2 : Bool ]
not (or b1 b2) --> and (not b1) (not b2).
[ b1 : Bool, b2 : Bool ]
not (xor b1 b2) --> eqv (not b1) (not b2).
[ b1 : Bool, b2 : Bool ]
not (eqv b1 b2) --> xor (not b1) (not b2).