-
Notifications
You must be signed in to change notification settings - Fork 6
/
operators.sml
191 lines (160 loc) · 3.35 KB
/
operators.sml
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
structure Operators = struct
open Util
datatype idx_const =
ICBool of bool
| ICTT
| ICAdmit
| ICNat of int
| ICTime of TimeType.time
datatype idx_un_op =
ToReal
| Log2
| Ceil
| Floor
| B2n
| Neg
| IUDiv of int
| IUExp of string
datatype idx_bin_op =
AddI
| MultI
| MaxI
| MinI
| IApp
| EqI
| AndI
| ExpNI
| LtI
| GeI
| BoundedMinusI
(* binary logical connectives *)
datatype bin_conn =
And
| Or
| Imply
| Iff
(* binary predicates on indices *)
datatype bin_pred =
EqP
| LeP
| LtP
| GeP
| GtP
| BigO
(* existential quantifier might carry other information such as a unification variable to update when this existential quantifier gets instantiated *)
datatype 'a quan =
Forall
| Exists of 'a
type nat = int
datatype expr_const =
ECTT
| ECNat of nat
| ECInt of int
datatype expr_un_op =
EUFst
| EUSnd
datatype bin_op =
EBApp
| EBPair
| EBAdd
| EBNew
| EBRead
datatype tri_op =
Write
datatype expr_EI =
EEIAppI
| EEIAscTime
datatype expr_ET =
EETAppT
| EETAsc
datatype expr_T =
ETNever
| ETBuiltin
fun str_idx_const c =
case c of
ICBool b => str_bool b
| ICTT => "()"
| ICAdmit => "admit"
| ICNat n => str_int n
| ICTime x => TimeType.str_time x
fun str_idx_un_op opr =
case opr of
ToReal => "$"
| Log2 => "log2"
| Ceil => "ceil"
| Floor => "floor"
| B2n => "b2n"
| Neg => "not"
| IUDiv d => sprintf "(/ $)" [str_int d]
| IUExp s => sprintf "(^ $)" [s]
fun str_idx_bin_op opr =
case opr of
AddI => "+"
| MultI => " *"
| MaxI => "max"
| MinI => "min"
| IApp => ""
| EqI => "=="
| AndI => "&&"
| ExpNI => "^"
| LtI => "<"
| GeI => ">="
| BoundedMinusI => "-"
fun str_bin_conn opr =
case opr of
And => "/\\"
| Or => "\\/"
| Imply => "->"
| Iff => "<->"
fun str_bin_pred opr =
case opr of
EqP => "="
| LeP => "<="
| LtP => "<"
| GeP => ">="
| GtP => ">"
| BigO => "<=="
fun strip_quan q =
case q of
Forall => Forall
| Exists _ => Exists ()
fun str_quan q =
case q of
Forall => "forall"
| Exists _ => "exists"
fun str_bin_op opr =
case opr of
EBApp => "$"
| EBPair => "pair"
| EBAdd => "+"
| EBNew => "new"
| EBRead => "read"
fun str_expr_EI opr =
case opr of
EEIAppI => "EEIAppI"
| EEIAscTime => "EEIAscTime"
fun str_expr_ET opr =
case opr of
EETAppT => "EETAppT"
| EETAsc => "EETAsc"
fun str_expr_T opr =
case opr of
ETNever => "ETNever"
| ETBuiltin => "ETBuiltin"
fun str_expr_const c =
case c of
ECTT => "()"
| ECInt n => str_int n
| ECNat n => sprintf "#$" [str_int n]
fun str_expr_un_op opr =
case opr of
EUFst => "fst"
| EUSnd => "snd"
fun str_expr_bin_op opr =
case opr of
EBApp => "app"
| EBPair => "pair"
| EBNew => "new"
| EBRead => "read"
| EBAdd => "add"
end