Common — library colibrilib.bddbitv — module IBDDS
1
module IBDDS

Implemented: the structural layer (positions and snodes)

2
use bool.Bool
3
use colibrilib.bdd.Node
4
use colibrilib.bdd.NodeSet
5
use colibrilib.bdd.NodeH
6
use colibrilib.bdd.Key
7
use list.List
8
use list.Mem
9
use list.Length
10
use list.Append as Lists
11
use option.Option
12
use ref.Ref
13
use colibrilib.sbdd.SNode
14
use colibrilib.bdd.IArray63
15
use int.Int
16
use colibrilib.int63.Int63
17
use set.Set
18
use colibrilib.pbdd.PBDD
19
use colibrilib.pbdd.PBDD2
20
use colibrilib.zarith.Zbit
21
use colibrilib.zbit.ZbitInt
22
use seq.Seq
23
use mach.array.Array63
24
use int.MinMax
25
use int.Power
26
use colibrilib.ibdd.IBDD

The BDD of the bits 0 <= i < n of id + off, for the index id (subst_add with off already normalized)

    Valid (1.2s) (colibri2 34) (cvc4 7) (split_vc) (depth 1)
30
let partial
subst_add
(n: int63) (off: int) : IArray63.t PBDD.t
31
requires { 0 <= n }
32
ensures { result.IArray63.length = n }
33
ensures { forall i. 0 <= i < n -> numbits (result i).dom_indexes <= n }
34
ensures { forall i. 0 <= i < n -> (result i).dom_snodes = Set.empty }
35
ensures { forall i id sn. 0 <= i < n -> ((result i).PBDD.v id sn <-> bittest (id + off) i) }
36
=
37
let a = Array63.make n (PBDD.tfalse ()) in
38
let c = ref (PBDD.tfalse ()) in
39
for i = 0 to n - 1 do
40
invariant { forall k. 0 <= k < i -> numbits (a[k]).dom_indexes <= n }
41
invariant { forall k. 0 <= k < i -> (a[k]).dom_snodes = Set.empty }
42
invariant { forall k id sn. 0 <= k < i -> ((a[k]).PBDD.v id sn <-> bittest (id + off) k) }
43
invariant { numbits (!c).dom_indexes <= i }
44
invariant { (!c).dom_snodes = Set.empty }
45
invariant { forall id sn. (!c).PBDD.v id sn <-> carry id off i }
46
let ib = PBDD.bdd_of_index i in
47
let ob = if Zbit.test_bit off i then PBDD.ttrue () else PBDD.tfalse () in
48
let x = PBDD.dxor ob ib in
49
let lemma bit (id: int) : unit
50
ensures { bittest (id + off) i <-> ((bittest id i <-> bittest off i) <-> carry id off i) }
51
= bittest_add id off (to_int i)
52
in
53
let r = PBDD.dxor x !c in
54
assert { forall id sn. r.PBDD.v id sn <-> xorb (xorb (ob.PBDD.v id sn) (ib.PBDD.v id sn)) ((!c).PBDD.v id sn) };
55
assert { forall id sn. ob.PBDD.v id sn <-> bittest off i };
56
assert { forall id sn. r.PBDD.v id sn <-> bittest (id + off) i };
57
{proof…}
58
assert { numbits ib.dom_indexes <= i + 1 };
59
assert { numbits x.dom_indexes <= i + 1 };
60
assert { numbits r.dom_indexes <= n };
61
{qed}
62
label L in
63
a[i] <- r;
64
assert { forall k. 0 <= k < i -> a[k] = (a at L)[k] };
65
assert { a[i] = r };
66
let lemma inv (k id: int) (sn: snodes) : unit
67
requires { 0 <= k <= i }
68
ensures { (a[k]).PBDD.v id sn <-> bittest (id + off) k }
69
= if k < to_int i then begin
70
assert { a[k] = (a at L)[k] };
71
assert { ((a at L)[k]).PBDD.v id sn <-> bittest (id + off) k }
72
end else begin
73
assert { k = i /\ a[k] = r };
74
assert { r.PBDD.v id sn <-> bittest (id + off) i }
75
end
76
in
77
{proof…}
78
assert { forall k. 0 <= k <= i -> numbits (a[k]).dom_indexes <= n };
79
let lemma cy (id: int) : unit
80
ensures { carry id off (i + 1) <->
81
((bittest id i /\ bittest off i) \/ ((bittest id i \/ bittest off i) /\ carry id off i)) }
82
= () in
83
let ghost c0 = !c in
84
{qed}
85
c := PBDD.dor (PBDD.dand ob ib) (PBDD.dand x !c);
86
{proof…}
87
assert { forall id sn. (!c).PBDD.v id sn <->
88
((ob.PBDD.v id sn /\ ib.PBDD.v id sn) \/ (x.PBDD.v id sn /\ c0.PBDD.v id sn)) };
89
assert { forall id sn. (!c).PBDD.v id sn <-> carry id off (i + 1) };
90
{qed}
91
done;
92
IArray63.of_array a

The positions from_..to_ of the window s set to false (null in bddbitv.ml)

    Valid (1.4s) (colibri2 17) (cvc4 6) (split_vc 2) (depth 2)
96
let partial
null
(from_ to_ s: int63) (t: PBDD.t) : PBDD.t
97
requires { 0 <= from_ <= to_ < Int63.max_int }
98
requires { 0 <= s }
99
requires { numbits t.dom_indexes <= s }
100
ensures { numbits result.dom_indexes <= s }
101
ensures { Set.subset result.dom_snodes t.dom_snodes }
102
ensures { forall sn q. bittest (PBDD2.v result s sn) q <->
103
(bittest (PBDD2.v t s sn) q /\ not (from_ <= q <= to_)) }
104
ensures { Set.subset (support_snodes result) (support_snodes t) }
105
=
106
let z = ZbitInt.lsl_int (ZbitInt.mask_int (to_int to_ - to_int from_ + 1)) (to_int from_) in
107
mask_nonneg (to_int to_ - to_int from_ + 1);
108
asr_nonneg pure { mask (to_int to_ - to_int from_ + 1) } (- to_int from_);
109
let lemma bits (q:int) : unit
110
ensures { bittest z q <-> from_ <= q <= to_ }
111
= if 0 <= q then def_asr pure { mask (to_int to_ - to_int from_ + 1) } (- to_int from_) q
112
in
113
if z > 0 then numbits_top_bit z;
114
let m = get (cst z) s in
115
let r = PBDD2.dand (PBDD2.dnot m) t in
116
lor_numbits m.dom_indexes t.dom_indexes;
117
let lemma bit (sn:PBDD2.env) (q:int) : unit
118
ensures { bittest (PBDD2.v r s sn) q <->
119
(bittest (PBDD2.v t s sn) q /\ not (from_ <= q <= to_)) }
120
= if 0 <= q && numbits q <= to_int s then begin
121
lt_lsl_of_numbits q (to_int s);
122
assert { bittest (mask (lsl 1 s)) q };
123
assert { PBDD2.v m s sn = land z (mask (lsl 1 s)) };
124
assert { bittest (PBDD2.v r s sn) q <->
125
(not (bittest (PBDD2.v m s sn) q) /\ bittest (PBDD2.v t s sn) q) }
126
end
127
in
128
r
129
Valid (398ms) (cvc4)
130
let lemma
of_bits_eq
(f: int -> bool) (x n: int) : unit
131
requires { 0 <= x /\ 0 <= n /\ numbits x <= n }
132
requires { forall i. 0 <= i < n -> (f i <-> bittest x i) }
133
ensures { of_bits f n = x }
134
=
135
let lemma bit (i:int) : unit
136
requires { 0 <= i }
137
ensures { bittest (of_bits f n) i <-> bittest x i }
138
= if x > 0 && i >= n then numbits_high_clear x i
139
in
140
ext_bittest (of_bits f n) x

r is b restricted to the positions 0..m of the window s

    Valid (89ms) (colibri2)
143
let ghost
no_neg_mask
(r b: PBDD.t) (s m: int) : unit
144
requires { forall p sn. 0 <= p -> numbits p <= s -> (r.PBDD.v p sn <-> (p <= m /\ b.PBDD.v p sn)) }
145
requires { forall p sn1 sn2. 0 <= p <= m -> numbits p <= s -> agree p sn1 sn2 ->
146
(b.PBDD.v p sn1 <-> b.PBDD.v p sn2) }
147
ensures { no_neg r s }
148
=
149
let lemma pt (p: int) (sn1 sn2: snodes) : unit
150
requires { 0 <= p /\ numbits p <= s /\ agree p sn1 sn2 }
151
ensures { r.PBDD.v p sn1 <-> r.PBDD.v p sn2 }
152
= if p <= m then assert { b.PBDD.v p sn1 <-> b.PBDD.v p sn2 }
153
in ()

Reading a shifted snode is reading the snode at a shifted position

    Valid (110ms) (colibri2)
156
let ghost
sem_shift
(env: Node.t -> int) (p k: int) (nd: snode) : unit
157
requires { nd.SNode.scal \/ in_bounds (to_int nd.SNode.s - k) }
158
ensures { sem env p (shift_snode nd k) <-> sem env (p - k) nd }
159
ensures { reads_at p (shift_snode nd k) <-> reads_at (p - k) nd }
160
= ()

b does not read a negative bit at the positions q of the window s that are kept by a shift of off

164
predicate
no_neg_off
(b: PBDD.t) (s off: int) =
165
forall q sn1 sn2. 0 <= q -> 0 <= q + off -> numbits q <= s -> agree q sn1 sn2 ->
166
(b.PBDD.v q sn1 <-> b.PBDD.v q sn2)
167
Valid (45ms) (colibri2)
168
lemma
no_neg_off_of
: forall b s off. no_neg b s -> no_neg_off b s off

The bit p of the result is the bit p - off of t, for the positions p <= maxpos (the snodes are shifted by off). Differs from bddbitv.ml: the test maxpos - off < 0 (the same as off > maxpos) is not repeated.

    Valid (1.5s) (colibri2 139) (cvc4 49) (split_vc 9) (depth 5)
174
let partial
shift_left_gen
(maxpos off: int63) (t: PBDD.t) (t_size: int63) : PBDD.t
175
requires { 0 <= maxpos < Int63.max_int /\ 0 <= t_size }
176
requires { numbits t.dom_indexes <= t_size }
177
requires { in_bounds (to_int maxpos - to_int off) /\ in_bounds (- to_int off) }
178
requires { 0 < off -> forall sn q. maxpos < q -> not (bittest (PBDD2.v t t_size sn) q) }
179
ensures { numbits result.dom_indexes <= numbits maxpos }
180
ensures { forall env p. 0 <= p <= maxpos ->
181
(bittest (PBDD2.v result (numbits maxpos) (sem env)) p <->
182
(off <= p /\ bittest (PBDD2.v t t_size (sem env)) (p - off))) }
183
ensures { no_neg_off t t_size off -> no_neg_le result maxpos }
184
ensures { forall nd''. Set.mem nd'' (support_snodes result) ->
185
exists nd. Set.mem nd (support_snodes t) /\ (nd.scal \/ in_bounds (to_int nd.s - to_int off)) /\
186
nd'' = shift_snode nd (to_int off) }
187
raises { Overflow -> exists nd. Set.mem nd t.dom_snodes /\ not nd.scal /\ not (in_bounds (to_int nd.s - to_int off)) }
188
=
189
numbits_ge_pos 0 (to_int maxpos);
190
numbits_le_self (to_int maxpos);
191
let size = Int63.of_int (Zbit.numbits (to_int maxpos)) in
192
numbits_lsl_lt (to_int maxpos);
193
if off = 0 then begin
194
let r = resize t t_size size in
195
let lemma nn (p: int) (sn1 sn2: snodes) : unit
196
requires { no_neg_off t t_size off /\ 0 <= p <= maxpos /\ agree p sn1 sn2 }
197
ensures { r.PBDD.v p sn1 <-> r.PBDD.v p sn2 }
198
=
199
numbits_ge_pos p (to_int maxpos);
200
lt_lsl_of_numbits p (to_int size);
201
assert { bittest (mask (lsl 1 size)) p };
202
bit_cenv r (to_int size) p sn1; bit_cenv r (to_int size) p sn2;
203
if numbits p <= to_int t_size then begin
204
bit_cenv t (to_int t_size) p sn1; bit_cenv t (to_int t_size) p sn2
205
end
206
in
207
r
208
end else if off > maxpos then begin
209
let r = PBDD2.tfalse () in
210
r
211
end
212
else begin
213
let input_size =
214
if off < 0 then begin
215
numbits_le_self (to_int maxpos - to_int off);
216
Int63.of_int (Zbit.numbits (to_int (maxpos - off)))
217
end else size in
218
let br = resize t t_size input_size in
219
let bdd =
220
if off < 0 then null 0 (-off - 1) input_size br
221
else null (maxpos - off + 1) maxpos input_size br in
222
let off' =
223
if off < 0 then to_int (-off)
224
else Zbit.lsl63 1 input_size - to_int off in
225
let subst = subst_add input_size off' in
226
support_snodes_dom bdd;
227
let bdd' = PBDD.compose_shift subst off bdd in
228
let r = resize bdd' input_size size in
229
let lemma bit (env: Node.t -> int) (p: int) : unit
230
requires { 0 <= p <= maxpos }
231
ensures { bittest (PBDD2.v r size (sem env)) p <->
232
(off <= p /\ bittest (PBDD2.v t t_size (sem env)) (p - off)) }
233
=
234
let ghost sn = sem env in
235
lt_lsl_of_numbits p (to_int size);
236
assert { bittest (PBDD2.v r size sn) p <-> bdd'.PBDD.v p (sn p) };
237
let ghost e = pure { fun nd -> sn p (shift_snode nd off) } in
238
let ghost q = pure { of_bits (subst_bits subst p (sn p)) input_size } in
239
assert { bdd'.PBDD.v p (sn p) <-> bdd.PBDD.v q e };
240
let ghost x = if to_int off < 0 || to_int off <= p then p - to_int off
241
else p + off' in
242
let lemma sub (i:int) : unit
243
requires { 0 <= i < input_size }
244
ensures { (subst i).PBDD.v p (sn p) <-> bittest x i }
245
= if 0 < to_int off && to_int off <= p then bittest_sub_lsl (p + off') (to_int input_size) i
246
in
247
numbits_lt_lsl x (to_int input_size);
248
of_bits_eq pure { subst_bits subst p (sn p) } x (to_int input_size);
249
assert { q = x };
250
let ghost sn' = pure { fun (_:int) -> e } in
251
assert { bdd.PBDD.v q e <-> bittest (PBDD2.v bdd input_size sn') q };
252
if to_int off < 0 || to_int off <= p then begin
253
let lemma pt (nd: snode) : unit
254
requires { Set.mem nd (support_snodes bdd) }
255
ensures { e nd = sn q nd }
256
= sem_shift env p (to_int off) nd
257
in
258
support_snodes_v bdd q e (sn q);
259
assert { bdd.PBDD.v q (sn q) <-> bittest (PBDD2.v bdd input_size sn) q };
260
assert { bittest (PBDD2.v bdd input_size sn) q <-> bittest (PBDD2.v t t_size sn) q }
261
end else begin
262
assert { not (bittest (PBDD2.v bdd input_size sn') q) }
263
end
264
in
265
(* the masked input at the position [q] of its window *)
266
let lemma bdd_pt (q: int) (y: snodes) : unit
267
requires { 0 <= q /\ numbits q <= input_size }
268
ensures { bdd.PBDD.v q y <->
269
(numbits q <= t_size /\ t.PBDD.v q y /\
270
not (if to_int off < 0 then 0 <= q <= - to_int off - 1
271
else maxpos - off + 1 <= q <= maxpos)) }
272
=
273
bit_cenv bdd (to_int input_size) q y;
274
bit_cenv br (to_int input_size) q y;
275
lt_lsl_of_numbits q (to_int input_size);
276
assert { bittest (mask (lsl 1 input_size)) q };
277
if numbits q <= to_int t_size then bit_cenv t (to_int t_size) q y
278
in
279
let lemma nn (p: int) (sn1 sn2: snodes) : unit
280
requires { no_neg_off t t_size off /\ 0 <= p <= maxpos /\ agree p sn1 sn2 }
281
ensures { r.PBDD.v p sn1 <-> r.PBDD.v p sn2 }
282
=
283
lt_lsl_of_numbits p (to_int size);
284
assert { bittest (mask (lsl 1 size)) p };
285
bit_cenv r (to_int size) p sn1; bit_cenv r (to_int size) p sn2;
286
bit_cenv bdd' (to_int input_size) p sn1; bit_cenv bdd' (to_int input_size) p sn2;
287
let ghost x = if to_int off < 0 || to_int off <= p then p - to_int off else p + off' in
288
let lemma sub (i:int) (sn: snodes) : unit
289
requires { 0 <= i < input_size }
290
ensures { (subst i).PBDD.v p sn <-> bittest x i }
291
= if 0 < to_int off && to_int off <= p then bittest_sub_lsl (p + off') (to_int input_size) i
292
in
293
numbits_lt_lsl x (to_int input_size);
294
let lemma cs (sn: snodes) : unit
295
ensures { bdd'.PBDD.v p sn <-> bdd.PBDD.v x (shifted sn (to_int off)) }
296
= of_bits_eq pure { subst_bits subst p sn } x (to_int input_size)
297
in
298
let ghost e1 = shifted sn1 (to_int off) in
299
let ghost e2 = shifted sn2 (to_int off) in
300
cs sn1; cs sn2;
301
let ghost x1 = pure { fun nd -> Set.mem nd (support_snodes bdd) /\ e1 nd } in
302
let ghost x2 = pure { fun nd -> Set.mem nd (support_snodes bdd) /\ e2 nd } in
303
support_snodes_v bdd x e1 x1;
304
support_snodes_v bdd x e2 x2;
305
bdd_pt x x1; bdd_pt x x2;
306
if to_int off < 0 || to_int off <= p then begin
307
let lemma ag (nd: snode) : unit
308
requires { reads_at (x) nd }
309
ensures { Set.mem nd x1 <-> Set.mem nd x2 }
310
= if pure { Set.mem nd (support_snodes bdd) } then
311
sem_shift (fun _ -> 0) p (to_int off) nd
312
in
313
assert { agree x x1 x2 };
314
if numbits x <= to_int t_size then assert { t.PBDD.v x x1 <-> t.PBDD.v x x2 }
315
end else begin
316
assert { maxpos - off + 1 <= x };
317
if x > to_int maxpos && numbits x <= to_int t_size then begin
318
assert { not (bittest (PBDD2.v t t_size (cenv x1)) x) };
319
assert { not (bittest (PBDD2.v t t_size (cenv x2)) x) };
320
bit_cenv t (to_int t_size) x x1; bit_cenv t (to_int t_size) x x2
321
end
322
end
323
in
324
let lemma supp_img (nd'': snode) : unit
325
requires { Set.mem nd'' (support_snodes r) }
326
ensures { exists nd. Set.mem nd (support_snodes t) /\ (nd.scal \/ in_bounds (to_int nd.s - to_int off)) /\
327
nd'' = shift_snode nd (to_int off) }
328
=
329
assert { Set.mem nd'' (support_snodes bdd') };
330
assert { forall j. 0 <= j < input_size -> Set.is_empty (support_snodes (subst j)) }
331
in
332
r
333
end

shift_left of bddbitv.ml (the input is masked first)

    Valid (679ms) (colibri2 36) (cvc4 7) (split_vc) (depth 1)
336
let partial
shift_left
(off sz: int63) (t: t) : t
337
requires { 0 <= off /\ 0 <= sz }
338
ensures { forall env. value result env = land (lsl (value t env) off) (mask sz) }
339
ensures { forall sn. not (result.tail.PBDD.v 0 sn) }
340
raises { Overflow -> exists nd. Set.mem nd t.bdd.dom_snodes /\ not nd.scal /\ not (in_bounds (to_int nd.s - to_int off)) }
341
=
342
if off >= sz then begin
343
let r = zero () in
344
let lemma eq (env: Node.t -> int) : unit
345
ensures { value r env = land (lsl (value t env) off) (mask sz) }
346
=
347
let lemma bit (p:int) : unit
348
requires { 0 <= p }
349
ensures { not (bittest (land (lsl (value t env) off) (mask sz)) p) }
350
= if p < to_int sz then def_asr (value t env) (- to_int off) p
351
in
352
ext_bittest (value r env) pure { land (lsl (value t env) off) (mask sz) }
353
in
354
r
355
end else begin
356
let maxpos = sz - 1 in
357
numbits_ge_pos 0 (to_int maxpos);
358
numbits_le_self (to_int maxpos);
359
let s = Int63.of_int (Zbit.numbits (to_int maxpos)) in
360
let b0 = mask_bdd t.size maxpos t.bdd in
361
no_neg_mask b0 t.bdd (to_int t.size) (to_int maxpos);
362
let b1 = shift_left_gen maxpos off b0 t.size in
363
let b2 = mask_bdd s maxpos b1 in
364
no_neg_mask b2 b1 (to_int s) (to_int maxpos);
365
let r = mk b2 s in
366
let lemma eq (env: Node.t -> int) : unit
367
ensures { value r env = land (lsl (value t env) off) (mask sz) }
368
=
369
let lemma bit (p:int) : unit
370
requires { 0 <= p }
371
ensures { bittest (value r env) p <-> bittest (land (lsl (value t env) off) (mask sz)) p }
372
= def_asr (value t env) (- to_int off) p;
373
{proof…}
374
let ghost e = sem env in
375
let ghost x = value t env in
376
assert { value r env = land (mask (to_int maxpos + 1)) (PBDD2.v b1 (to_int s) e) };
377
assert { PBDD2.v b0 (to_int t.size) e = land (mask (to_int maxpos + 1)) x };
378
if pure { bittest (land (lsl x off) (mask sz)) p } then begin
379
assert { p < to_int sz /\ bittest (lsl x off) p };
380
assert { to_int off <= p /\ bittest x (p - to_int off) };
381
assert { bittest (PBDD2.v b0 (to_int t.size) e) (p - to_int off) };
382
assert { bittest (PBDD2.v b1 (to_int s) e) p }
383
end
384
{qed}
385
in
386
ext_bittest (value r env) pure { land (lsl (value t env) off) (mask sz) }
387
in
388
r
389
end

shift_right of bddbitv.ml (logical shift)

    Valid (945ms) (colibri2 38) (cvc4 8) (cvc5) (split_vc) (depth 1)
392
let partial
shift_right
(off sz: int63) (t: t) : t
393
requires { 0 <= off /\ 0 <= sz }
394
requires { to_int sz + to_int sz <= Int63.max_int }
395
ensures { forall env. value result env = asr (land (value t env) (mask sz)) off }
396
ensures { forall sn. not (result.tail.PBDD.v 0 sn) }
397
raises { Overflow -> exists nd. Set.mem nd t.bdd.dom_snodes /\ not nd.scal /\ not (in_bounds (to_int nd.s + to_int off)) }
398
=
399
if off >= sz then begin
400
let r = zero () in
401
let lemma eq (env: Node.t -> int) : unit
402
ensures { value r env = asr (land (value t env) (mask sz)) off }
403
=
404
let lemma bit (p:int) : unit
405
requires { 0 <= p }
406
ensures { not (bittest (asr (land (value t env) (mask sz)) off) p) }
407
= def_asr pure { land (value t env) (mask sz) } (to_int off) p
408
in
409
ext_bittest (value r env) pure { asr (land (value t env) (mask sz)) off }
410
in
411
r
412
end else begin
413
let maxpos = sz - 1 in
414
numbits_ge_pos 0 (to_int maxpos);
415
numbits_le_self (to_int maxpos);
416
let s = Int63.of_int (Zbit.numbits (to_int maxpos)) in
417
let b0' = mask_bdd t.size maxpos t.bdd in
418
let b0 = resize b0' t.size s in
419
assert { no_neg b0 s };
420
let b1 = shift_left_gen maxpos (- off) b0 s in
421
let b2 = mask_bdd s maxpos b1 in
422
no_neg_mask b2 b1 (to_int s) (to_int maxpos);
423
let r = mk b2 s in
424
let lemma eq (env: Node.t -> int) : unit
425
ensures { value r env = asr (land (value t env) (mask sz)) off }
426
=
427
let lemma bit (p:int) : unit
428
requires { 0 <= p }
429
ensures { bittest (value r env) p <-> bittest (asr (land (value t env) (mask sz)) off) p }
430
=
431
def_asr pure { land (value t env) (mask sz) } (to_int off) p;
432
if p <= to_int maxpos then begin
433
assert { bittest (value r env) p <-> bittest (PBDD2.v b2 s (sem env)) p };
434
assert { bittest (mask (maxpos + 1)) p };
435
assert { bittest (PBDD2.v b2 s (sem env)) p <-> bittest (PBDD2.v b1 s (sem env)) p };
436
assert { to_int s = numbits (to_int maxpos) };
437
assert { bittest (PBDD2.v b1 s (sem env)) p <->
438
(- to_int off <= p /\ bittest (PBDD2.v b0 s (sem env)) (p - (- to_int off))) };
439
assert { bittest (PBDD2.v b1 s (sem env)) p <->
440
bittest (PBDD2.v b0 s (sem env)) (p + to_int off) };
441
if p + to_int off <= to_int maxpos then begin
442
lt_lsl_of_numbits (p + to_int off) (to_int s);
443
assert { bittest (mask (lsl 1 s)) (p + to_int off) }
444
end
445
end
446
in
447
ext_bittest (value r env) pure { asr (land (value t env) (mask sz)) off }
448
in
449
r
450
end

The BDD of the bit pos of t, without index (get_bit of bddbitv.ml: a cofactor by the cube of pos)

    Valid (369ms) (colibri2)
454
let partial
get_bit
(pos: int63) (t: t) : PBDD.t
455
requires { 0 <= pos }
456
ensures { result.dom_indexes = 0 }
457
ensures { Set.subset result.dom_snodes t.bdd.dom_snodes }
458
ensures { forall id sn. result.PBDD.v id sn <-> (numbits pos <= t.size /\ t.bdd.PBDD.v pos sn) }
459
=
460
if Zbit.numbits (to_int pos) <= to_int t.size then PBDD.get_pos t.bdd pos t.size
461
else PBDD.tfalse ()

The positions q above level are the ones of pos

464
predicate
covers
(q pos level: int) = forall j. level < j -> (bittest q j <-> bittest pos j)

The positions lo..hi filled with sign seen from the position c (switch_pos with Var.map in sign_extend and arith_shift_right): at the position q the snodes of sign are shifted by q - c. The positions below level are read from the index, the others are the ones of pos.

    Valid (1.7s) (colibri2 57) (cvc4 7) (split_vc 11) (depth 3)
471
let rec partial
fill
(sign: PBDD.t) (empty: IArray63.t PBDD.t) (lo hi c level pos: int63) : PBDD.t
472
requires { sign.dom_indexes = 0 }
473
requires { empty.IArray63.length = 0 }
474
requires { -1 <= level /\ lsl 1 (level + 1) <= Int63.max_int }
475
requires { 0 <= c /\ 0 <= pos }
476
requires { forall j. 0 <= j <= level -> not (bittest pos j) }
477
variant { level + 1 }
478
ensures { numbits result.dom_indexes <= level + 1 }
479
ensures { forall q nd. 0 <= q -> covers q pos level -> lo <= q <= hi ->
480
Set.mem nd (support_snodes sign) -> nd.scal \/ in_bounds (to_int nd.s + (c - q)) }
481
ensures { forall id sn q. 0 <= q -> covers q pos level ->
482
(forall j. 0 <= j <= level -> (bittest q j <-> bittest id j)) ->
483
(result.PBDD.v id sn <->
484
(lo <= q <= hi /\ sign.PBDD.v 0 (shifted sn (q - c)))) }
485
raises { Overflow -> exists q nd. 0 <= q /\ covers q pos level /\ lo <= q <= hi /\
486
Set.mem nd (support_snodes sign) /\ not nd.scal /\ not (in_bounds (to_int nd.s + (c - q))) }
487
=
488
if level < 0 then begin
489
let lemma base (q: int) : unit
490
requires { 0 <= q /\ covers q pos level }
491
ensures { q = pos }
492
= ext_bittest q (to_int pos)
493
in
494
if lo <= pos && pos <= hi then begin
495
let r =
496
try PBDD.compose_shift empty (pos - c) sign
497
with Overflow ->
498
assert { exists nd. Set.mem nd (support_snodes sign) /\ not nd.scal /\
499
not (in_bounds (to_int nd.s + (c - pos))) };
500
raise Overflow
501
end in
502
ext_bittest pure { of_bits (fun i -> (empty i).PBDD.v 0 Set.empty) 0 } 0;
503
r
504
end else PBDD.tfalse ()
505
end else begin
506
mask_nonneg (to_int level);
507
let pos' = Int63.lor pos (Int63.lsl 1 level) in
508
(* for the exception raised by the recursive call on [pos'] *)
509
let lemma up (q: int) : unit
510
requires { covers q pos' (level - 1) }
511
ensures { covers q pos level }
512
=
513
let lemma bit (j: int) : unit
514
ensures { bittest (lsl 1 level) j <-> j = level }
515
= if 0 <= j then def_asr 1 (- to_int level) j
516
in ()
517
in
518
let a = fill sign empty lo hi c (level - 1) pos' in
519
let b = fill sign empty lo hi c (level - 1) pos in
520
let r = PBDD.ite_index level a b in
521
let lemma split (q: int) : unit
522
requires { 0 <= q /\ covers q pos level }
523
ensures { if bittest q level then covers q pos' (level - 1) else covers q pos (level - 1) }
524
=
525
let lemma bit (j: int) : unit
526
ensures { bittest (lsl 1 level) j <-> j = level }
527
= if 0 <= j then def_asr 1 (- to_int level) j
528
in ()
529
in
530
let lemma value (id: int) (sn: snodes) (q: int) : unit
531
requires { 0 <= q /\ covers q pos level }
532
requires { forall j. 0 <= j <= level -> (bittest q j <-> bittest id j) }
533
ensures { r.PBDD.v id sn <-> (lo <= q <= hi /\ sign.PBDD.v 0 (shifted sn (q - c))) }
534
=
535
split q;
536
if bittest id (to_int level) then
537
assert { bittest q level /\ (r.PBDD.v id sn <-> a.PBDD.v id sn) }
538
else
539
assert { not (bittest q level) /\ (r.PBDD.v id sn <-> b.PBDD.v id sn) }
540
in
541
numbits_set pure { lor a.dom_indexes b.dom_indexes } (to_int level);
542
lor_numbits a.dom_indexes b.dom_indexes;
543
r
544
end

The bit c of t read from the position p does not depend on the snodes that read a negative bit

    Valid (791ms) (colibri2 6) (cvc4 2) (split_vc) (depth 1)
548
let ghost
sign_agree
(t: t) (sign: PBDD.t) (c p: int) (sn1 sn2: snodes) : unit
549
requires { 0 <= c /\ 0 <= p }
550
requires { forall id sn. sign.PBDD.v id sn <-> (numbits c <= t.size /\ t.bdd.PBDD.v c sn) }
551
requires { forall nd. Set.mem nd (support_snodes sign) -> nd.scal \/ in_bounds (to_int nd.s + (c - p)) }
552
requires { agree p sn1 sn2 }
553
ensures { sign.PBDD.v 0 (shifted sn1 (p - c)) <-> sign.PBDD.v 0 (shifted sn2 (p - c)) }
554
=
555
let ghost x1 = pure { fun nd -> Set.mem nd (support_snodes sign) /\ shifted sn1 (p - c) nd } in
556
let ghost x2 = pure { fun nd -> Set.mem nd (support_snodes sign) /\ shifted sn2 (p - c) nd } in
557
support_snodes_v sign 0 (shifted sn1 (p - c)) x1;
558
support_snodes_v sign 0 (shifted sn2 (p - c)) x2;
559
let lemma ag (nd: snode) : unit
560
requires { reads_at (c) nd }
561
ensures { Set.mem nd x1 <-> Set.mem nd x2 }
562
= if pure { Set.mem nd (support_snodes sign) } then
563
sem_shift (fun _ -> 0) p (p - c) nd
564
in
565
assert { agree c x1 x2 };
566
if numbits c <= to_int t.size then assert { t.bdd.PBDD.v c x1 <-> t.bdd.PBDD.v c x2 }

fill of the bit c of t on the window s

    Valid (118ms) (colibri2 10) (split_vc) (depth 1)
569
let ghost
no_neg_fill
(t: t) (sign f: PBDD.t) (lo hi c s: int) : unit
570
requires { 0 <= c /\ 0 <= s }
571
requires { forall id sn. sign.PBDD.v id sn <-> (numbits c <= t.size /\ t.bdd.PBDD.v c sn) }
572
requires { forall q nd. 0 <= q -> covers q 0 (s - 1) -> lo <= q <= hi ->
573
Set.mem nd (support_snodes sign) -> nd.scal \/ in_bounds (to_int nd.s + (c - q)) }
574
requires { forall id sn q. 0 <= q -> covers q 0 (s - 1) ->
575
(forall j. 0 <= j <= s - 1 -> (bittest q j <-> bittest id j)) ->
576
(f.PBDD.v id sn <-> (lo <= q <= hi /\ sign.PBDD.v 0 (shifted sn (q - c)))) }
577
ensures { no_neg f s }
578
=
579
let lemma pt (p: int) (sn1 sn2: snodes) : unit
580
requires { 0 <= p /\ numbits p <= s /\ agree p sn1 sn2 }
581
ensures { f.PBDD.v p sn1 <-> f.PBDD.v p sn2 }
582
=
583
let lemma hc (j: int) : unit
584
requires { s - 1 < j }
585
ensures { not (bittest p j) }
586
= if p > 0 then numbits_high_clear p j
587
in
588
assert { covers p 0 (s - 1) };
589
if lo <= p <= hi then sign_agree t sign c p sn1 sn2
590
in
591
()

The union of two BDDs without negative reads

    Valid (88ms) (colibri2)
594
let ghost
no_neg_or
(r a b: PBDD.t) (s: int) : unit
595
requires { no_neg a s /\ no_neg b s }
596
requires { forall p sn. r.PBDD.v p sn <-> (a.PBDD.v p sn \/ b.PBDD.v p sn) }
597
ensures { no_neg r s }
598
= ()

The intersection of two BDDs without negative reads

    Valid (90ms) (colibri2)
601
let ghost
no_neg_and
(r a b: PBDD.t) (s: int) : unit
602
requires { no_neg a s /\ no_neg b s }
603
requires { forall p sn. r.PBDD.v p sn <-> (a.PBDD.v p sn /\ b.PBDD.v p sn) }
604
ensures { no_neg r s }
605
= ()

The union of two BDDs without negative reads up to m

    Valid (83ms) (colibri2)
608
let ghost
no_neg_le_or
(r a b: PBDD.t) (m: int) : unit
609
requires { no_neg_le a m /\ no_neg_le b m }
610
requires { forall p sn. r.PBDD.v p sn <-> (a.PBDD.v p sn \/ b.PBDD.v p sn) }
611
ensures { no_neg_le r m }
612
= ()

The window s is included in the positions 0..m

    Valid (45ms) (colibri2)
615
let ghost
no_neg_of_le
(b: PBDD.t) (s m: int) : unit
616
requires { no_neg_le b m }
617
requires { forall p. 0 <= p -> numbits p <= s -> p <= m }
618
ensures { no_neg b s }
619
= ()

The bits 0..sz-1 of x seen as a signed integer

622
function
sext
(sz x: int) : int =
623
if bittest x (sz - 1) then lor x (lnot (mask sz)) else land x (mask sz)
624
Valid (1.4s) (cvc4)
625
let lemma
sext_bit
(sz x j: int) : unit
626
requires { 1 <= sz /\ 0 <= j }
627
ensures { bittest (sext sz x) j <-> if j < sz then bittest x j else bittest x (sz - 1) }
628
= ()

arith_shift_right of bddbitv.ml, with off already clamped to sz

    Valid (3.0s) (colibri2 78) (cvc4 24) (cvc5) (split_vc 30) (depth 5)
631
let partial
arith_shift_right
(off sz: int63) (t: t) : t
632
requires { 0 <= off <= sz /\ 1 <= sz }
633
requires { to_int sz + to_int sz <= Int63.max_int }
634
ensures { forall env. value result env = land (asr (sext sz (value t env)) off) (mask sz) }
635
ensures { forall sn. not (result.tail.PBDD.v 0 sn) }
636
raises { Overflow -> exists nd k. Set.mem nd t.bdd.dom_snodes /\ 0 <= k <= off /\
637
not (in_bounds (to_int nd.s + k)) }
638
=
639
let maxpos = sz - 1 in
640
let sign = get_bit maxpos t in
641
let t' = shift_right off sz t in
642
numbits_ge_pos 0 (to_int maxpos);
643
numbits_le_self (to_int maxpos);
644
let s = Int63.of_int (Zbit.numbits (to_int maxpos)) in
645
if maxpos > 0 then begin
646
numbits_lsl_le (to_int maxpos);
647
lsl_succ 1 (to_int s - 1)
648
end;
649
lsl_le_max_int (to_int s);
650
let b = get t' s in
651
let empty = IArray63.of_array (Array63.make 0 (PBDD.tfalse ())) in
652
PBDD.support_snodes_dom sign;
653
let f = fill sign empty (maxpos - off + 1) maxpos maxpos (s - 1) 0 in
654
(* the specification of [fill] at the position [q] *)
655
let lemma fpost (q: int) (snn: snodes) : unit
656
requires { 0 <= q /\ covers q 0 (s - 1) }
657
ensures { f.PBDD.v q snn <->
658
(maxpos - off + 1 <= q /\ q <= maxpos /\ sign.PBDD.v 0 (shifted snn (q - maxpos))) }
659
= assert { forall j. 0 <= j <= s - 1 -> (bittest q j <-> bittest q j) }
660
in
661
lor_numbits f.dom_indexes b.dom_indexes;
662
let fb = PBDD2.dor f b in
663
no_neg_fill t sign f (to_int maxpos - to_int off + 1) (to_int maxpos) (to_int maxpos) (to_int s);
664
no_neg_or fb f b (to_int s);
665
let r = mk fb s in
666
let lemma eq (env: Node.t -> int) : unit
667
ensures { value r env = land (asr (sext sz (value t env)) off) (mask sz) }
668
=
669
let ghost sn = sem env in
670
let lemma bit (p: int) : unit
671
requires { 0 <= p }
672
ensures { bittest (value r env) p <->
673
bittest (land (asr (sext sz (value t env)) off) (mask sz)) p }
674
=
675
def_asr pure { sext sz (value t env) } (to_int off) p;
676
def_asr pure { land (value t env) (mask sz) } (to_int off) p;
677
sext_bit (to_int sz) (value t env) (p + to_int off);
678
assert { bittest (value r env) p <->
679
(bittest (PBDD2.v f s sn) p \/ bittest (PBDD2.v b s sn) p) };
680
if p <= to_int maxpos then begin
681
numbits_ge_pos p (to_int maxpos);
682
lt_lsl_of_numbits p (to_int s);
683
assert { bittest (PBDD2.v b s sn) p <-> bittest (value t' env) p };
684
if p > 0 then numbits_high_clear p (to_int s);
685
assert { covers p 0 (s - 1) };
686
assert { bittest (PBDD2.v f s sn) p <-> f.PBDD.v p (sn p) };
687
assert { bittest (PBDD2.v f s sn) p <->
688
(maxpos - off + 1 <= p /\ sign.PBDD.v 0 (shifted (sn p) (p - maxpos))) };
689
if to_int maxpos - to_int off + 1 <= p then begin
690
let lemma pt (nd: snode) : unit
691
requires { Set.mem nd (support_snodes sign) }
692
ensures { shifted (sn p) (p - maxpos) nd = sn maxpos nd }
693
= assert { nd.scal \/ in_bounds (to_int nd.s + (maxpos - p)) };
694
sem_shift env p (p - to_int maxpos) nd
695
in
696
support_snodes_v sign 0 pure { shifted (sn p) (p - maxpos) } pure { sn maxpos };
697
assert { sign.PBDD.v 0 (sn maxpos) <-> bittest (value t env) maxpos }
698
end
699
end else begin
700
if numbits p <= to_int s then begin
701
if p > 0 then numbits_high_clear p (to_int s);
702
assert { covers p 0 (s - 1) };
703
assert { bittest (PBDD2.v f s sn) p <-> f.PBDD.v p (sn p) };
704
assert { not (maxpos - off + 1 <= p <= maxpos) };
705
fpost p (sn p);
706
assert { not (bittest (PBDD2.v f s sn) p) }
707
end;
708
assert { not (bittest (PBDD2.v b s sn) p) }
709
end
710
in
711
ext_bittest (value r env) pure { land (asr (sext sz (value t env)) off) (mask sz) }
712
in
713
r

sign_extend of bddbitv.ml: the bits 0..from-1 of t sign–extended to sz bits

    Valid (7.5s) (colibri2 61) (cvc4 17) (split_vc 11) (depth 4)
717
let partial
sign_extend
(from sz: int63) (t: t) : t
718
requires { 1 <= from <= sz }
719
requires { to_int sz + to_int sz <= Int63.max_int }
720
ensures { forall env. value result env = land (sext from (value t env)) (mask sz) }
721
ensures { forall sn. not (result.tail.PBDD.v 0 sn) }
722
raises { Overflow -> exists nd k. Set.mem nd t.bdd.dom_snodes /\ from - sz <= k < 0 /\
723
not (in_bounds (to_int nd.s + k)) }
724
=
725
let c = from - 1 in
726
let sign = get_bit c t in
727
let maxpos = sz - 1 in
728
numbits_ge_pos 0 (to_int maxpos);
729
numbits_le_self (to_int maxpos);
730
let s = Int63.of_int (Zbit.numbits (to_int maxpos)) in
731
if maxpos > 0 then begin
732
numbits_lsl_le (to_int maxpos);
733
lsl_succ 1 (to_int s - 1)
734
end;
735
lsl_le_max_int (to_int s);
736
let g = get t s in
737
let b = mask_bdd s c g in
738
no_neg_mask b g (to_int s) (to_int c);
739
let empty = IArray63.of_array (Array63.make 0 (PBDD.tfalse ())) in
740
PBDD.support_snodes_dom sign;
741
let f = fill sign empty from maxpos c (s - 1) 0 in
742
lor_numbits f.dom_indexes b.dom_indexes;
743
let fb = PBDD2.dor f b in
744
no_neg_fill t sign f (to_int from) (to_int maxpos) (to_int c) (to_int s);
745
no_neg_or fb f b (to_int s);
746
let r = mk fb s in
747
let lemma eq (env: Node.t -> int) : unit
748
ensures { value r env = land (sext from (value t env)) (mask sz) }
749
=
750
let ghost sn = sem env in
751
let lemma bit (p: int) : unit
752
requires { 0 <= p }
753
ensures { bittest (value r env) p <-> bittest (land (sext from (value t env)) (mask sz)) p }
754
=
755
sext_bit (to_int from) (value t env) p;
756
assert { bittest (value r env) p <->
757
(bittest (PBDD2.v f s sn) p \/ bittest (PBDD2.v b s sn) p) };
758
if p <= to_int maxpos then begin
759
numbits_ge_pos p (to_int maxpos);
760
lt_lsl_of_numbits p (to_int s);
761
assert { bittest (PBDD2.v b s sn) p <-> (p < from /\ bittest (value t env) p) };
762
if p > 0 then numbits_high_clear p (to_int s);
763
assert { covers p 0 (s - 1) };
764
assert { bittest (PBDD2.v f s sn) p <-> f.PBDD.v p (sn p) };
765
assert { bittest (PBDD2.v f s sn) p <->
766
(from <= p /\ sign.PBDD.v 0 (shifted (sn p) (p - c))) };
767
if to_int from <= p then begin
768
let lemma pt (nd: snode) : unit
769
requires { Set.mem nd (support_snodes sign) }
770
ensures { shifted (sn p) (p - c) nd = sn c nd }
771
= assert { nd.scal \/ in_bounds (to_int nd.s + (c - p)) };
772
sem_shift env p (p - to_int c) nd
773
in
774
support_snodes_v sign 0 pure { shifted (sn p) (p - c) } pure { sn c };
775
assert { sign.PBDD.v 0 (sn c) <-> bittest (value t env) c }
776
end
777
end else begin
778
if numbits p <= to_int s then begin
779
if p > 0 then numbits_high_clear p (to_int s);
780
assert { covers p 0 (s - 1) };
781
assert { bittest (PBDD2.v f s sn) p <-> f.PBDD.v p (sn p) };
782
assert { not (bittest (PBDD2.v f s sn) p) }
783
end;
784
assert { not (bittest (PBDD2.v b s sn) p) }
785
end
786
in
787
ext_bittest (value r env) pure { land (sext from (value t env)) (mask sz) }
788
in
789
r

The positions from_..to_ of the window s (mask' in bddbitv.ml)

    Valid (705ms) (colibri2 16) (cvc4) (split_vc) (depth 1)
792
let partial
mask_range
(from_ to_ s: int63) : PBDD.t
793
requires { 0 <= from_ <= to_ < Int63.max_int }
794
requires { 0 <= s }
795
ensures { numbits result.dom_indexes <= s }
796
ensures { result.dom_snodes = Set.empty }
797
ensures { forall sn q. bittest (PBDD2.v result s sn) q <-> (from_ <= q <= to_ /\ numbits q <= s) }
798
=
799
let z = ZbitInt.lsl_int (ZbitInt.mask_int (to_int to_ - to_int from_ + 1)) (to_int from_) in
800
mask_nonneg (to_int to_ - to_int from_ + 1);
801
asr_nonneg pure { mask (to_int to_ - to_int from_ + 1) } (- to_int from_);
802
let lemma bits (q:int) : unit
803
ensures { bittest z q <-> from_ <= q <= to_ }
804
= if 0 <= q then def_asr pure { mask (to_int to_ - to_int from_ + 1) } (- to_int from_) q
805
in
806
if z > 0 then numbits_top_bit z;
807
let m = get (cst z) s in
808
let lemma bit (sn:PBDD2.env) (q:int) : unit
809
ensures { bittest (PBDD2.v m s sn) q <-> (from_ <= q <= to_ /\ numbits q <= s) }
810
= if 0 <= q && numbits q <= to_int s then begin
811
lt_lsl_of_numbits q (to_int s);
812
assert { bittest (mask (lsl 1 s)) q }
813
end
814
in
815
m

Rotation to the right by off of the bits 0..sz-1 of x

818
function
rotr
(sz off x: int) : int =
819
of_bits (fun p -> if p + off < sz then bittest x (p + off) else bittest x (p + off - sz)) sz
820
Valid (94ms) (colibri2)
821
let lemma
rotr_bit
(sz off x p: int) : unit
822
requires { 0 <= p }
823
ensures { bittest (rotr sz off x) p <->
824
(p < sz /\ if p + off < sz then bittest x (p + off) else bittest x (p + off - sz)) }
825
= ()

rotate_right of bddbitv.ml, with off already reduced modulo sz. Differs from bddbitv.ml, less efficient: the result is masked (one dand), the spec of shift_left_gen does not cover the positions above maxpos.

    Valid (1.2s) (colibri2 61) (cvc4 36) (cvc5 2) (split_vc 3) (depth 2)
831
let partial
rotate_right
(off sz: int63) (t: t) : t
832
requires { 0 <= off < sz }
833
requires { to_int sz + to_int sz <= Int63.max_int }
834
ensures { forall env. value result env = rotr sz off (value t env) }
835
ensures { forall sn. not (result.tail.PBDD.v 0 sn) }
836
raises { Overflow -> exists nd k. Set.mem nd t.bdd.dom_snodes /\ - sz <= k <= sz /\
837
not (in_bounds (to_int nd.s - k)) }
838
=
839
let maxpos = sz - 1 in
840
numbits_ge_pos 0 (to_int maxpos);
841
numbits_le_self (to_int maxpos);
842
let s = Int63.of_int (Zbit.numbits (to_int maxpos)) in
843
numbits_lsl_lt (to_int maxpos);
844
let b = get t s in
845
let lemma inb (env: Node.t -> int) (q: int) : unit
846
requires { 0 <= q <= maxpos }
847
ensures { bittest (PBDD2.v b s (sem env)) q <-> bittest (value t env) q }
848
= numbits_ge_pos q (to_int maxpos);
849
lt_lsl_of_numbits q (to_int s);
850
assert { bittest (mask (lsl 1 s)) q }
851
in
852
if off = 0 then begin
853
let mb = mask_bdd s maxpos b in
854
no_neg_mask mb b (to_int s) (to_int maxpos);
855
let r = mk mb s in
856
let lemma eq (env: Node.t -> int) : unit
857
ensures { value r env = rotr sz off (value t env) }
858
=
859
let lemma bit (p: int) : unit
860
requires { 0 <= p }
861
ensures { bittest (value r env) p <-> bittest (rotr sz off (value t env)) p }
862
= rotr_bit (to_int sz) (to_int off) (value t env) p;
863
if p <= to_int maxpos then inb env p
864
in
865
ext_bittest (value r env) pure { rotr sz off (value t env) }
866
in
867
r
868
end else begin
869
let i0 = mask_range off maxpos s in
870
lor_numbits i0.dom_indexes b.dom_indexes;
871
let a0 = PBDD2.dand i0 b in
872
no_snode_no_neg i0 (to_int s);
873
no_neg_and a0 i0 b (to_int s);
874
assert { forall nd. Set.mem nd a0.dom_snodes -> Set.mem nd t.bdd.dom_snodes };
875
let b0 = shift_left_gen maxpos (- off) a0 s in
876
let i1 = mask_range 0 (off - 1) s in
877
lor_numbits i1.dom_indexes b.dom_indexes;
878
let a1 = PBDD2.dand i1 b in
879
no_snode_no_neg i1 (to_int s);
880
no_neg_and a1 i1 b (to_int s);
881
assert { forall nd. Set.mem nd a1.dom_snodes -> Set.mem nd t.bdd.dom_snodes };
882
let lemma ov (nd: snode) : unit
883
requires { Set.mem nd a1.dom_snodes /\ not nd.scal /\ not (in_bounds (to_int nd.s - (to_int maxpos - to_int off + 1))) }
884
ensures { exists nd k. Set.mem nd t.bdd.dom_snodes /\ - sz <= k <= sz /\ not nd.scal /\ not (in_bounds (to_int nd.s - k)) }
885
= let ghost k = to_int maxpos - to_int off + 1 in
886
assert { - to_int sz <= k <= to_int sz /\ to_int nd.s - k = to_int nd.s - (to_int maxpos - to_int off + 1) };
887
assert { Set.mem nd t.bdd.dom_snodes }
888
in
889
let b1 = shift_left_gen maxpos (maxpos - off + 1) a1 s in
890
lor_numbits b0.dom_indexes b1.dom_indexes;
891
let o = PBDD2.dor b0 b1 in
892
no_neg_le_or o b0 b1 (to_int maxpos);
893
let mo = mask_bdd s maxpos o in
894
no_neg_mask mo o (to_int s) (to_int maxpos);
895
let r = mk mo s in
896
let lemma eq (env: Node.t -> int) : unit
897
ensures { value r env = rotr sz off (value t env) }
898
=
899
let ghost sn = sem env in
900
let lemma bit (p: int) : unit
901
requires { 0 <= p }
902
ensures { bittest (value r env) p <-> bittest (rotr sz off (value t env)) p }
903
=
904
rotr_bit (to_int sz) (to_int off) (value t env) p;
905
if p <= to_int maxpos then begin
906
assert { bittest (value r env) p <-> bittest (PBDD2.v o s sn) p };
907
assert { bittest (PBDD2.v b0 s sn) p <-> bittest (PBDD2.v a0 s sn) (p + off) };
908
assert { bittest (PBDD2.v b1 s sn) p <->
909
(maxpos - off + 1 <= p /\ bittest (PBDD2.v a1 s sn) (p - (maxpos - off + 1))) };
910
if p + to_int off <= to_int maxpos then begin
911
inb env (p + to_int off);
912
numbits_ge_pos (p + to_int off) (to_int maxpos);
913
assert { bittest (PBDD2.v a0 s sn) (p + off) <-> bittest (value t env) (p + off) }
914
end else begin
915
assert { not (bittest (PBDD2.v a0 s sn) (p + off)) };
916
assert { bittest (PBDD2.v b1 s sn) p <-> bittest (PBDD2.v a1 s sn) (p + off - sz) };
917
inb env (p + to_int off - to_int sz);
918
numbits_ge_pos (p + to_int off - to_int sz) (to_int maxpos);
919
assert { bittest (PBDD2.v a1 s sn) (p + off - sz) <-> bittest (value t env) (p + off - sz) }
920
end
921
end else
922
assert { not (bittest (mask (maxpos + 1)) p) }
923
in
924
ext_bittest (value r env) pure { rotr sz off (value t env) }
925
in
926
r
927
end

rotate_left of bddbitv.ml, with off already reduced modulo sz. Differs from bddbitv.ml, less efficient: the result is masked (one dand), as in rotate_right.

    Valid (3.4s) (colibri2 61) (cvc4 38) (cvc5 8) (split_vc 6) (depth 2)
932
let partial
rotate_left
(off sz: int63) (t: t) : t
933
requires { 0 <= off < sz }
934
requires { to_int sz + to_int sz <= Int63.max_int }
935
ensures { forall env. value result env = rotr sz (if off = 0 then 0 else sz - off) (value t env) }
936
ensures { forall sn. not (result.tail.PBDD.v 0 sn) }
937
raises { Overflow -> exists nd k. Set.mem nd t.bdd.dom_snodes /\ - sz <= k <= sz /\
938
not (in_bounds (to_int nd.s - k)) }
939
=
940
let maxpos = sz - 1 in
941
numbits_ge_pos 0 (to_int maxpos);
942
numbits_le_self (to_int maxpos);
943
let s = Int63.of_int (Zbit.numbits (to_int maxpos)) in
944
numbits_lsl_lt (to_int maxpos);
945
let b = get t s in
946
let lemma inb (env: Node.t -> int) (q: int) : unit
947
requires { 0 <= q <= maxpos }
948
ensures { bittest (PBDD2.v b s (sem env)) q <-> bittest (value t env) q }
949
= numbits_ge_pos q (to_int maxpos);
950
lt_lsl_of_numbits q (to_int s);
951
assert { bittest (mask (lsl 1 s)) q }
952
in
953
if off = 0 then begin
954
let mb = mask_bdd s maxpos b in
955
no_neg_mask mb b (to_int s) (to_int maxpos);
956
let r = mk mb s in
957
let lemma eq (env: Node.t -> int) : unit
958
ensures { value r env = rotr sz (if off = 0 then 0 else sz - off) (value t env) }
959
=
960
let lemma bit (p: int) : unit
961
requires { 0 <= p }
962
ensures { bittest (value r env) p <-> bittest (rotr sz (if off = 0 then 0 else sz - off) (value t env)) p }
963
= rotr_bit (to_int sz) (if off = 0 then 0 else to_int sz - to_int off) (value t env) p;
964
if p <= to_int maxpos then inb env p
965
in
966
ext_bittest (value r env) pure { rotr sz (if off = 0 then 0 else sz - off) (value t env) }
967
in
968
r
969
end else begin
970
let i0 = mask_range 0 (maxpos - off) s in
971
lor_numbits i0.dom_indexes b.dom_indexes;
972
let a0 = PBDD2.dand i0 b in
973
no_snode_no_neg i0 (to_int s);
974
no_neg_and a0 i0 b (to_int s);
975
assert { forall nd. Set.mem nd a0.dom_snodes -> Set.mem nd t.bdd.dom_snodes };
976
let b0 = shift_left_gen maxpos off a0 s in
977
let i1 = mask_range (maxpos - off + 1) maxpos s in
978
lor_numbits i1.dom_indexes b.dom_indexes;
979
let a1 = PBDD2.dand i1 b in
980
no_snode_no_neg i1 (to_int s);
981
no_neg_and a1 i1 b (to_int s);
982
assert { forall nd. Set.mem nd a1.dom_snodes -> Set.mem nd t.bdd.dom_snodes };
983
let lemma ov (nd: snode) : unit
984
requires { Set.mem nd a1.dom_snodes /\ not nd.scal /\ not (in_bounds (to_int nd.s + (to_int maxpos - to_int off + 1))) }
985
ensures { exists nd k. Set.mem nd t.bdd.dom_snodes /\ - sz <= k <= sz /\ not nd.scal /\ not (in_bounds (to_int nd.s - k)) }
986
= let ghost k = - (to_int maxpos - to_int off + 1) in
987
assert { - to_int sz <= k <= to_int sz /\ to_int nd.s - k = to_int nd.s + (to_int maxpos - to_int off + 1) };
988
assert { Set.mem nd t.bdd.dom_snodes }
989
in
990
let b1 = shift_left_gen maxpos (- (maxpos - off + 1)) a1 s in
991
lor_numbits b0.dom_indexes b1.dom_indexes;
992
let o = PBDD2.dor b0 b1 in
993
no_neg_le_or o b0 b1 (to_int maxpos);
994
let mo = mask_bdd s maxpos o in
995
no_neg_mask mo o (to_int s) (to_int maxpos);
996
let r = mk mo s in
997
let lemma eq (env: Node.t -> int) : unit
998
ensures { value r env = rotr sz (if off = 0 then 0 else sz - off) (value t env) }
999
=
1000
let ghost sn = sem env in
1001
let lemma bit (p: int) : unit
1002
requires { 0 <= p }
1003
ensures { bittest (value r env) p <-> bittest (rotr sz (if off = 0 then 0 else sz - off) (value t env)) p }
1004
=
1005
rotr_bit (to_int sz) (if off = 0 then 0 else to_int sz - to_int off) (value t env) p;
1006
if p <= to_int maxpos then begin
1007
assert { bittest (value r env) p <-> bittest (PBDD2.v o s sn) p };
1008
if to_int off <= p then begin
1009
assert { bittest (PBDD2.v b0 s sn) p <-> bittest (PBDD2.v a0 s sn) (p - off) };
1010
assert { not (bittest (PBDD2.v a1 s sn) (p + sz - off)) };
1011
assert { not (bittest (PBDD2.v b1 s sn) p) };
1012
inb env (p - to_int off);
1013
numbits_ge_pos (p - to_int off) (to_int maxpos);
1014
assert { bittest (PBDD2.v a0 s sn) (p - off) <-> bittest (value t env) (p - off) }
1015
end else begin
1016
assert { not (bittest (PBDD2.v b0 s sn) p) };
1017
assert { bittest (PBDD2.v b1 s sn) p <-> bittest (PBDD2.v a1 s sn) (p - (- (maxpos - off + 1))) };
1018
assert { p - (- (maxpos - off + 1)) = p + sz - off };
1019
assert { bittest (PBDD2.v b1 s sn) p <-> bittest (PBDD2.v a1 s sn) (p + sz - off) };
1020
inb env (p + to_int sz - to_int off);
1021
numbits_ge_pos (p + to_int sz - to_int off) (to_int maxpos);
1022
assert { bittest (PBDD2.v a1 s sn) (p + sz - off) <-> bittest (value t env) (p + sz - off) }
1023
end
1024
end else
1025
assert { not (bittest (mask (maxpos + 1)) p) }
1026
in
1027
ext_bittest (value r env) pure { rotr sz (if off = 0 then 0 else sz - off) (value t env) }
1028
in
1029
r
1030
end

extract i j of bddbitv.ml: the bits i..j of t

    Valid (1.8s) (colibri2 36) (cvc4 8) (split_vc 2) (depth 2)
1033
let partial
extract
(i j: int63) (t: t) : t
1034
requires { 0 <= i <= j < Int63.max_int }
1035
requires { lsl 1 t.size <= Int63.max_int }
1036
requires { in_bounds (lsl 1 t.size + to_int i) }
1037
ensures { forall env. value result env = land (asr (value t env) i) (mask (j - i + 1)) }
1038
ensures { forall sn. not (result.tail.PBDD.v 0 sn) }
1039
raises { Overflow -> exists nd. Set.mem nd t.bdd.dom_snodes /\ not nd.scal /\ not (in_bounds (to_int nd.s + i)) }
1040
=
1041
numbits_ge_pos 0 t.bdd.dom_indexes;
1042
let maxpos = Int63.lsl 1 t.size - 1 in
1043
mask_nonneg (to_int t.size);
1044
mask_numbits (to_int t.size);
1045
let m = mask_range i j t.size in
1046
lor_numbits m.dom_indexes t.bdd.dom_indexes;
1047
let a = PBDD2.dand m t.bdd in
1048
no_snode_no_neg m (to_int t.size);
1049
no_neg_and a m t.bdd (to_int t.size);
1050
let b = shift_left_gen maxpos (- i) a t.size in
1051
let lemma le (p: int) : unit
1052
requires { 0 <= p /\ numbits p <= t.size }
1053
ensures { p <= maxpos }
1054
= lt_lsl_of_numbits p (to_int t.size)
1055
in
1056
no_neg_of_le b (to_int t.size) (to_int maxpos);
1057
let r = mk b t.size in
1058
let lemma eq (env: Node.t -> int) : unit
1059
ensures { value r env = land (asr (value t env) i) (mask (j - i + 1)) }
1060
=
1061
let ghost sn = sem env in
1062
let lemma bit (p: int) : unit
1063
requires { 0 <= p }
1064
ensures { bittest (value r env) p <-> bittest (land (asr (value t env) i) (mask (j - i + 1))) p }
1065
=
1066
def_asr (value t env) (to_int i) p;
1067
if p <= to_int maxpos then begin
1068
assert { value r env = PBDD2.v b t.size sn };
1069
assert { bittest (value r env) p <-> bittest (PBDD2.v a t.size sn) (p + i) };
1070
assert { bittest (PBDD2.v a t.size sn) (p + i) <->
1071
(p + i <= j /\ bittest (value t env) (p + i)) }
1072
end else begin
1073
if numbits p <= to_int t.size then lt_lsl_of_numbits p (to_int t.size);
1074
assert { not (bittest (value r env) p) };
1075
if numbits (p + to_int i) <= to_int t.size then lt_lsl_of_numbits (p + to_int i) (to_int t.size);
1076
assert { not (bittest (value t env) (p + i)) }
1077
end
1078
in
1079
ext_bittest (value r env) pure { land (asr (value t env) i) (mask (j - i + 1)) }
1080
in
1081
r

repeat of bddbitv.ml: n copies of the bits 0..from-1 of t. Differs from bddbitv.ml, less efficient: the result is masked (one dand), as in rotate_right.

    Valid (2.0s) (colibri2 68) (cvc4 18) (cvc5 2) (split_vc 13) (depth 4)
1086
let partial
repeat
(from n: int63) (t: t) : t
1087
requires { 1 <= from /\ 1 <= n }
1088
requires { to_int from * to_int n + to_int from * to_int n <= Int63.max_int }
1089
ensures { forall env p. bittest (value result env) p <->
1090
exists k. 0 <= k < n /\ k * from <= p < k * from + from /\
1091
bittest (value t env) (p - k * from) }
1092
raises { Overflow -> exists nd k. Set.mem nd t.bdd.dom_snodes /\ 0 < k < from * n /\
1093
not (in_bounds (to_int nd.s - k)) }
1094
=
1095
let maxpos = from * n - 1 in
1096
numbits_ge_pos 0 (to_int maxpos);
1097
numbits_le_self (to_int maxpos);
1098
let s = Int63.of_int (Zbit.numbits (to_int maxpos)) in
1099
numbits_lsl_lt (to_int maxpos);
1100
numbits_ge_pos 0 t.bdd.dom_indexes;
1101
let mt = mask_bdd t.size (from - 1) t.bdd in
1102
no_neg_mask mt t.bdd (to_int t.size) (to_int from - 1);
1103
let b0 = resize mt t.size s in
1104
let lemma nn0 (p: int) (sn1 sn2: snodes) : unit
1105
requires { 0 <= p /\ numbits p <= s /\ agree p sn1 sn2 }
1106
ensures { b0.PBDD.v p sn1 <-> b0.PBDD.v p sn2 }
1107
= if numbits p <= to_int t.size then assert { mt.PBDD.v p sn1 <-> mt.PBDD.v p sn2 }
1108
in
1109
assert { no_neg b0 s };
1110
let lemma inb (env: Node.t -> int) (q: int) : unit
1111
requires { 0 <= q <= maxpos }
1112
ensures { bittest (PBDD2.v b0 s (sem env)) q <-> (q < from /\ bittest (value t env) q) }
1113
= numbits_ge_pos q (to_int maxpos);
1114
lt_lsl_of_numbits q (to_int s);
1115
assert { bittest (mask (lsl 1 s)) q }
1116
in
1117
let lemma high (sn: PBDD2.env) (q: int) : unit
1118
requires { maxpos < q }
1119
ensures { not (bittest (PBDD2.v b0 s sn) q) }
1120
= assert { from <= from * n };
1121
assert { not (bittest (mask from) q) }
1122
in
1123
let lemma init (env: Node.t -> int) (p: int) : unit
1124
requires { 0 <= p <= maxpos }
1125
ensures { bittest (PBDD2.v b0 s (sem env)) p <->
1126
exists k. 0 <= k < 1 /\ k * from <= p < k * from + from /\
1127
bittest (value t env) (p - k * from) }
1128
= inb env p;
1129
assert { 0 * from = 0 }
1130
in
1131
let r = ref b0 in
1132
for i = 1 to n - 1 do
1133
invariant { numbits (!r).dom_indexes <= s }
1134
invariant { no_neg_le !r maxpos }
1135
invariant { forall env p. 0 <= p <= maxpos ->
1136
(bittest (PBDD2.v !r s (sem env)) p <->
1137
exists k. 0 <= k < i /\ k * from <= p < k * from + from /\
1138
bittest (value t env) (p - k * from)) }
1139
assert { 0 <= (n - i) * from };
1140
assert { 0 <= i * from <= from * n };
1141
let sh = shift_left_gen maxpos (i * from) b0 s in
1142
lor_numbits (!r).dom_indexes sh.dom_indexes;
1143
let lemma step (env: Node.t -> int) (p: int) : unit
1144
requires { 0 <= p <= maxpos }
1145
ensures { bittest (PBDD2.v sh s (sem env)) p <->
1146
(i * from <= p < i * from + from /\ bittest (value t env) (p - i * from)) }
1147
= if to_int i * to_int from <= p then inb env (p - to_int i * to_int from)
1148
in
1149
let r0 = !r in
1150
let r' = PBDD2.dor r0 sh in
1151
no_neg_le_or r' r0 sh (to_int maxpos);
1152
let lemma inv (env: Node.t -> int) (p: int) : unit
1153
requires { 0 <= p <= maxpos }
1154
ensures { bittest (PBDD2.v r' s (sem env)) p <->
1155
exists k. 0 <= k < i + 1 /\ k * from <= p < k * from + from /\
1156
bittest (value t env) (p - k * from) }
1157
=
1158
step env p;
1159
assert { bittest (PBDD2.v r' s (sem env)) p <->
1160
(bittest (PBDD2.v r0 s (sem env)) p \/ bittest (PBDD2.v sh s (sem env)) p) };
1161
assert { (exists k. 0 <= k < i + 1 /\ k * from <= p < k * from + from /\
1162
bittest (value t env) (p - k * from)) <->
1163
((exists k. 0 <= k < i /\ k * from <= p < k * from + from /\
1164
bittest (value t env) (p - k * from)) \/
1165
(i * from <= p < i * from + from /\ bittest (value t env) (p - i * from))) }
1166
in
1167
r := r'
1168
done;
1169
let mr = mask_bdd s maxpos !r in
1170
no_neg_mask mr !r (to_int s) (to_int maxpos);
1171
let res = mk mr s in
1172
let lemma bit (env: Node.t -> int) (p: int) : unit
1173
ensures { bittest (value res env) p <->
1174
exists k. 0 <= k < n /\ k * from <= p < k * from + from /\
1175
bittest (value t env) (p - k * from) }
1176
= if p < 0 then
1177
assert { forall k. 0 <= k -> 0 <= k * from }
1178
else if p > to_int maxpos then begin
1179
assert { not (bittest (mask (maxpos + 1)) p) };
1180
assert { forall k. 0 <= k < n -> k * from + from <= n * from }
1181
end else begin
1182
assert { bittest (mask (maxpos + 1)) p };
1183
assert { bittest (value res env) p <-> bittest (PBDD2.v !r s (sem env)) p }
1184
end
1185
in
1186
res
1187
Valid (79ms) (colibri2)
1188
let rec lemma
subst_sn_mem
(l: list (snode, PBDD.t)) (id: int) (sn: snodes) (nd: snode) : unit
1189
variant { l }
1190
ensures { PBDD.mem_key nd l -> exists f. Mem.mem (nd, f) l /\ subst_sn l id sn nd = f.PBDD.v id sn }
1191
ensures { not (PBDD.mem_key nd l) -> subst_sn l id sn nd = sn nd }
1192
= match l with Nil -> () | Cons _ l' -> subst_sn_mem l' id sn nd end
1193
Valid (107ms) (cvc4)
1194
let rec ghost
subst_sn_eq
(l: list (snode, PBDD.t)) (id: int) (sn1 sn2: snodes) (nd: snode) : unit
1195
requires { forall nd' g. Mem.mem (nd', g) l -> (g.PBDD.v id sn1 <-> g.PBDD.v id sn2) }
1196
requires { PBDD.mem_key nd l \/ (Set.mem nd sn1 <-> Set.mem nd sn2) }
1197
variant { l }
1198
ensures { Set.mem nd (subst_sn l id sn1) <-> Set.mem nd (subst_sn l id sn2) }
1199
= match l with
1200
| Nil -> ()
1201
| Cons (nd', g) l' ->
1202
if pure { nd = nd' } then
1203
assert { Set.mem nd (subst_sn l id sn1) = g.PBDD.v id sn1 /\
1204
Set.mem nd (subst_sn l id sn2) = g.PBDD.v id sn2 }
1205
else begin
1206
assert { PBDD.mem_key nd l -> PBDD.mem_key nd l' };
1207
subst_sn_eq l' id sn1 sn2 nd;
1208
assert { Set.mem nd (subst_sn l id sn1) = Set.mem nd (subst_sn l' id sn1) /\
1209
Set.mem nd (subst_sn l id sn2) = Set.mem nd (subst_sn l' id sn2) }
1210
end
1211
end

The substitution of snodes by BDDs without negative reads

    Valid (612ms) (colibri2 7) (split_vc) (depth 1)
1214
let ghost
no_neg_compose
(t: t) (l: list (snode, PBDD.t)) (c: PBDD.t) : unit
1215
requires { forall nd g. Mem.mem (nd, g) l -> no_neg_le g (lsl 1 t.size - 1) }
1216
requires { forall id sn. c.PBDD.v id sn = t.bdd.PBDD.v id (subst_sn l id sn) }
1217
ensures { no_neg c t.size }
1218
=
1219
let lemma pt (p: int) (sn1 sn2: snodes) : unit
1220
requires { 0 <= p /\ numbits p <= t.size /\ agree p sn1 sn2 }
1221
ensures { c.PBDD.v p sn1 <-> c.PBDD.v p sn2 }
1222
=
1223
lt_lsl_of_numbits p (to_int t.size);
1224
let lemma ag (nd: snode) : unit
1225
requires { reads_at (p) nd }
1226
ensures { Set.mem nd (subst_sn l p sn1) <-> Set.mem nd (subst_sn l p sn2) }
1227
= subst_sn_eq l p sn1 sn2 nd
1228
in
1229
assert { agree p (subst_sn l p sn1) (subst_sn l p sn2) }
1230
in
1231
()

The environment where the node n1 has the value x

1234
function
upd_env
(env: Node.t -> int) (n1: Node.t) (x: int) : Node.t -> int =
1235
fun n -> if n = n1 then x else env n

The renaming of the snodes of a BDD without index by shift_snode _ off (compose_shift with the empty substitution)

    Valid (470ms) (colibri2 11) (cvc4) (split_vc) (depth 1)
1239
let partial
rename_tail
(off: int63) (g: PBDD.t) : PBDD.t
1240
requires { g.dom_indexes = 0 }
1241
ensures { result.dom_indexes = 0 }
1242
ensures { forall nd. Set.mem nd (support_snodes g) -> nd.scal \/ in_bounds (to_int nd.s - to_int off) }
1243
ensures { forall sn. result.PBDD.v 0 sn = g.PBDD.v 0 (shifted sn (to_int off)) }
1244
ensures { forall nd''. Set.mem nd'' (support_snodes result) ->
1245
exists nd. Set.mem nd (support_snodes g) /\ (nd.scal \/ in_bounds (to_int nd.s - to_int off)) /\
1246
nd'' = shift_snode nd (to_int off) }
1247
raises { Overflow -> exists nd. Set.mem nd (support_snodes g) /\ not nd.scal /\ not (in_bounds (to_int nd.s - to_int off)) }
1248
=
1249
let empty = IArray63.of_array (Array63.make 0 (PBDD.tfalse ())) in
1250
let r = PBDD.compose_shift empty off g in
1251
let lemma z (sn: snodes) : unit
1252
ensures { r.PBDD.v 0 sn = g.PBDD.v 0 (shifted sn (to_int off)) }
1253
= ext_bittest pure { of_bits (fun i -> (empty i).PBDD.v 0 sn) 0 } 0
1254
in
1255
numbits_ge_pos 0 r.dom_indexes;
1256
r

The bits of t moved by off positions: to the left when off >= 0 (the new low bits are false), to the right otherwise; the snodes of the tail are renamed.

    Valid (2.8s) (colibri2 57) (cvc4 17) (cvc5 2) (split_vc 7) (depth 4)
1261
let partial
shift_i
(off: int63) (t: t) : t
1262
requires { t.size <= 60 }
1263
requires { - 0x1000_0000_0000_0000 <= off <= 0x1000_0000_0000_0000 }
1264
ensures { result.size <= numbits (lsl 1 t.size + max 0 off - 1) }
1265
ensures { forall env p. 0 <= p ->
1266
(bit result p (sem env p) <-> (off <= p /\ bit t (p - off) (sem env (p - off)))) }
1267
ensures { (forall sn. not (t.tail.PBDD.v 0 sn)) -> forall sn. not (result.tail.PBDD.v 0 sn) }
1268
ensures { forall nd''. (Set.mem nd'' (support_snodes result.bdd) \/ Set.mem nd'' (support_snodes result.tail)) ->
1269
exists nd. (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) /\
1270
(nd.scal \/ in_bounds (to_int nd.s - to_int off)) /\
1271
nd'' = shift_snode nd (to_int off) }
1272
raises { Overflow -> exists nd. Set.mem nd (all_snodes t) /\ not nd.scal /\ not (in_bounds (to_int nd.s - to_int off)) }
1273
=
1274
lsl_le_2_60 (to_int t.size);
1275
let w0 = Int63.lsl 1 t.size in
1276
let m0 = if off >= 0 then w0 + off - 1 else w0 - 1 in
1277
numbits_ge_pos 0 (to_int m0);
1278
let sr = Int63.of_int (Zbit.numbits (to_int m0)) in
1279
assert { sr <= 61 };
1280
lsl_le_max_int (to_int sr);
1281
let maxpos = Int63.lsl 1 sr - 1 in
1282
let se = if off >= 0 then sr else Int63.of_int (Zbit.numbits (to_int (maxpos - off))) in
1283
let t_ext = get_t t se in
1284
let wnd = shift_left_gen maxpos off t_ext se in
1285
let tl = rename_tail off t.tail in
1286
no_neg_of_le wnd (to_int sr) (to_int maxpos);
1287
numbits_lsl_lt (to_int m0);
1288
assert { to_int m0 < lsl 1 sr };
1289
mask_nonneg (to_int sr);
1290
(* [tl] reads non-negative bits from the position [2^sr] on *)
1291
let lemma nnt (sn1 sn2: snodes) : unit
1292
requires { agree (lsl 1 sr) sn1 sn2 }
1293
ensures { tl.PBDD.v 0 sn1 <-> tl.PBDD.v 0 sn2 }
1294
=
1295
let lemma same (nd: snode) : unit
1296
requires { Set.mem nd (support_snodes t.tail) }
1297
ensures { shifted sn1 (to_int off) nd = shifted sn2 (to_int off) nd }
1298
=
1299
tail_support_nonneg t nd;
1300
sem_shift (fun _ -> 0) pure { lsl 1 sr } (to_int off) nd;
1301
let nd' = shift_snode nd (to_int off) in
1302
assert { reads_at (lsl 1 sr) nd' }
1303
in
1304
PBDD.support_snodes_v t.tail 0 (shifted sn1 (to_int off)) (shifted sn2 (to_int off))
1305
in
1306
assert { no_neg_tail tl sr };
1307
let r = mk_t wnd tl sr in
1308
(* the bits of the result *)
1309
let lemma bitr (env: Node.t -> int) (p: int) : unit
1310
requires { 0 <= p }
1311
ensures { bit r p (sem env p) <-> (off <= p /\ bit t (p - off) (sem env (p - off))) }
1312
=
1313
if numbits p <= to_int sr then begin
1314
lt_lsl_of_numbits p (to_int sr);
1315
PBDD2.def_v wnd (to_int sr) (sem env) p;
1316
if to_int off <= p then begin
1317
let q = p - to_int off in
1318
if to_int off >= 0 then numbits_lt_lsl q (to_int sr)
1319
else begin
1320
numbits_lsl_lt (to_int maxpos - to_int off);
1321
numbits_lt_lsl q (to_int se)
1322
end;
1323
PBDD2.def_v t_ext (to_int se) (sem env) q
1324
end
1325
end else begin
1326
tail_v tl p (sem env p);
1327
tail_v t.tail (p - to_int off) (sem env (p - to_int off));
1328
if p < pure { lsl 1 sr } then numbits_lt_lsl p (to_int sr);
1329
if numbits (p - to_int off) <= to_int t.size then lt_lsl_of_numbits (p - to_int off) (to_int t.size);
1330
let lemma pt (nd: snode) : unit
1331
requires { Set.mem nd (support_snodes t.tail) }
1332
ensures { shifted (sem env p) (to_int off) nd <-> sem env (p - to_int off) nd }
1333
=
1334
let nd' = shift_snode nd (to_int off) in
1335
sem_def env p nd'; sem_def env (p - to_int off) nd
1336
in
1337
PBDD.support_snodes_v t.tail 0 (shifted (sem env p) (to_int off)) (sem env (p - to_int off))
1338
end
1339
in
1340
let lemma image (nd'': snode) : unit
1341
requires { Set.mem nd'' (support_snodes r.bdd) \/ Set.mem nd'' (support_snodes r.tail) }
1342
ensures { exists nd. (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) /\
1343
(nd.scal \/ in_bounds (to_int nd.s - to_int off)) /\
1344
nd'' = shift_snode nd (to_int off) }
1345
=
1346
assert { r.tail = tl };
1347
if pure { Set.mem nd'' (support_snodes r.bdd) } then assert { Set.mem nd'' (support_snodes wnd) }
1348
in
1349
r

The BDD of the snode {n; s} once n has the value of t1, on the window size: t1 shifted by -s. Differs from bddbitv.ml: when s < 0, t1 is masked to the window first (one dand), otherwise its bits above maxpos would wrap around to the low positions in shift_left_gen.

    Valid (2.0s) (colibri2 47) (cvc4 6) (cvc5 3) (split_vc 5) (depth 4)
1356
let partial
shifted_bdd
(sz: int63) (s: int63) (t1: t) : PBDD.t
1357
requires { 0 <= sz /\ lsl 1 sz <= Int63.max_int }
1358
ensures { numbits result.dom_indexes <= sz }
1359
ensures { forall env p. 0 <= p < lsl 1 sz ->
1360
(result.PBDD.v p (sem env p) <-> bittest (value t1 env) (p + s)) }
1361
ensures { no_neg_le result (lsl 1 sz - 1) }
1362
raises { Overflow -> not (in_bounds (lsl 1 sz - 1 + s)) \/ not (in_bounds (- s)) \/
1363
exists nd1. Set.mem nd1 t1.bdd.dom_snodes /\ not nd1.scal /\ not (in_bounds (to_int nd1.s + s)) }
1364
=
1365
mask_nonneg (to_int sz);
1366
mask_numbits (to_int sz);
1367
let maxpos = Int63.lsl 1 sz - 1 in
1368
numbits_ge_pos 0 t1.bdd.dom_indexes;
1369
if s > Int63.max_int - maxpos || s = Int63.min_int then raise Overflow;
1370
let t1' = if s < 0 then mask_bdd t1.size maxpos t1.bdd else t1.bdd in
1371
if s < 0 then no_neg_mask t1' t1.bdd (to_int t1.size) (to_int maxpos);
1372
let f = shift_left_gen maxpos (- s) t1' t1.size in
1373
let lemma pt (env: Node.t -> int) (p: int) : unit
1374
requires { 0 <= p <= maxpos }
1375
ensures { f.PBDD.v p (sem env p) <-> bittest (value t1 env) (p + s) }
1376
=
1377
numbits_ge_pos p (to_int maxpos);
1378
assert { f.PBDD.v p (sem env p) <-> bittest (PBDD2.v f sz (sem env)) p };
1379
assert { bittest (PBDD2.v f sz (sem env)) p <->
1380
(- s <= p /\ bittest (PBDD2.v t1' t1.size (sem env)) (p + s)) };
1381
if 0 <= p + to_int s then begin
1382
if to_int s < 0 then assert { bittest (mask (maxpos + 1)) (p + s) };
1383
assert { bittest (PBDD2.v t1' t1.size (sem env)) (p + s) <-> bittest (value t1 env) (p + s) }
1384
end
1385
in
1386
f

The environment where each node n has the value of f n

1389
function
norm_env
(env: Node.t -> int) (f: Node.t -> t) : Node.t -> int =
1390
fun n -> value (f n) env

normalize of bddbitv.ml: each node n replaced by f n

    Valid (1.1s) (colibri2 41) (cvc4 7) (split_vc 5) (depth 3)
1393
let partial
normalize
(t: t) (f: Node.t -> t) : t
1394
requires { lsl 1 t.size <= Int63.max_int }
1395
requires { no_scal t.bdd }
1396
ensures { forall env. value result env = value t (norm_env env f) }
1397
raises { Overflow -> exists nd. Set.mem nd (support_snodes t.bdd) /\
1398
(not (in_bounds (lsl 1 t.size - 1 + nd.s)) \/ not (in_bounds (- nd.s)) \/
1399
exists nd1. Set.mem nd1 (f nd.n).bdd.dom_snodes /\ not nd1.scal /\ not (in_bounds (to_int nd1.s + nd.s))) }
1400
=
1401
let rec partial build (l: list Key.t) : list (snode, PBDD.t)
1402
requires { Distinct.distinct l }
1403
requires { forall n s a. Mem.mem (Key.Var n s a) l -> Set.mem { SNode.n = n; SNode.s = s; SNode.scal = a } (support_snodes t.bdd) }
1404
variant { l }
1405
ensures { PBDD.distinct_keys result }
1406
ensures { forall nd. PBDD.mem_key nd result <-> Mem.mem (Key.Var nd.n nd.s nd.scal) l }
1407
ensures { forall nd g. Mem.mem (nd, g) result -> numbits g.dom_indexes <= t.size /\
1408
forall env p. 0 <= p < lsl 1 t.size ->
1409
(g.PBDD.v p (sem env p) <-> bittest (value (f nd.n) env) (p + nd.s)) }
1410
ensures { forall nd g. Mem.mem (nd, g) result -> no_neg_le g (lsl 1 t.size - 1) }
1411
raises { Overflow -> exists nd. Set.mem nd (support_snodes t.bdd) /\
1412
(not (in_bounds (lsl 1 t.size - 1 + nd.s)) \/ not (in_bounds (- nd.s)) \/
1413
exists nd1. Set.mem nd1 (f nd.n).bdd.dom_snodes /\ not nd1.scal /\ not (in_bounds (to_int nd1.s + nd.s))) }
1414
= match l with
1415
| Nil -> Nil
1416
| Cons (Key.Var n s a) l' ->
1417
let r = build l' in
1418
let nd = { SNode.n = n; SNode.s = s; SNode.scal = a } in
1419
let g =
1420
try shifted_bdd t.size s (f n) with Overflow ->
1421
assert { Set.mem nd (support_snodes t.bdd) /\
1422
(not (in_bounds (lsl 1 t.size - 1 + nd.s)) \/ not (in_bounds (- nd.s)) \/
1423
exists nd1. Set.mem nd1 (f nd.n).bdd.dom_snodes /\ not nd1.scal /\ not (in_bounds (to_int nd1.s + nd.s))) };
1424
raise Overflow
1425
end in
1426
let res = Cons (nd, g) r in
1427
let lemma post (nd': snode) (g': PBDD.t) (env: Node.t -> int) (p: int) : unit
1428
requires { Mem.mem (nd', g') res /\ 0 <= p < lsl 1 t.size }
1429
ensures { g'.PBDD.v p (sem env p) <-> bittest (value (f nd'.n) env) (p + nd'.s) }
1430
= if pure { nd' = nd /\ g' = g } then assert { nd'.n = n /\ nd'.s = s }
1431
in
1432
res
1433
| Cons (Key.Index _) l' -> build l'
1434
end
1435
in
1436
let l = build (PBDD.vars t.bdd) in
1437
let c = PBDD.compose_snodes (to_int t.size) l t.bdd in
1438
no_neg_compose t l c;
1439
let r = mk c t.size in
1440
let lemma eq (env: Node.t -> int) : unit
1441
ensures { value r env = value t (norm_env env f) }
1442
=
1443
let ghost env' = norm_env env f in
1444
let lemma bit (p: int) : unit
1445
requires { 0 <= p }
1446
ensures { bittest (value r env) p <-> bittest (value t env') p }
1447
=
1448
if numbits p <= to_int t.size then begin
1449
lt_lsl_of_numbits p (to_int t.size);
1450
let lemma same (nd: snode) : unit
1451
requires { Set.mem nd (support_snodes t.bdd) }
1452
ensures { subst_sn l p (sem env p) nd = sem env' p nd }
1453
= subst_sn_mem l p (sem env p) nd
1454
in
1455
support_snodes_v t.bdd p pure { subst_sn l p (sem env p) } pure { sem env' p }
1456
end
1457
in
1458
ext_bittest (value r env) (value t env')
1459
in
1460
r

subst of bddbitv.ml: the node n1 replaced by t1 in t

    Valid (1.2s) (colibri2 43) (cvc4 8) (split_vc 4) (depth 3)
1463
let partial
subst
(t: t) (n1: Node.t) (t1: t) : t
1464
requires { lsl 1 t.size <= Int63.max_int }
1465
requires { no_scal t.bdd }
1466
ensures { forall env. value result env = value t (upd_env env n1 (value t1 env)) }
1467
raises { Overflow -> exists nd. Set.mem nd (support_snodes t.bdd) /\ nd.n = n1 /\
1468
(not (in_bounds (lsl 1 t.size - 1 + nd.s)) \/ not (in_bounds (- nd.s)) \/
1469
exists nd1. Set.mem nd1 t1.bdd.dom_snodes /\ not nd1.scal /\ not (in_bounds (to_int nd1.s + nd.s))) }
1470
=
1471
let rec partial build (l: list Key.t) : list (snode, PBDD.t)
1472
requires { Distinct.distinct l }
1473
requires { forall n s a. Mem.mem (Key.Var n s a) l -> Set.mem { SNode.n = n; SNode.s = s; SNode.scal = a } (support_snodes t.bdd) }
1474
variant { l }
1475
ensures { PBDD.distinct_keys result }
1476
ensures { forall nd. PBDD.mem_key nd result <-> (Mem.mem (Key.Var nd.n nd.s nd.scal) l /\ nd.n = n1) }
1477
ensures { forall nd f. Mem.mem (nd, f) result -> numbits f.dom_indexes <= t.size /\
1478
forall env p. 0 <= p < lsl 1 t.size ->
1479
(f.PBDD.v p (sem env p) <-> bittest (value t1 env) (p + nd.s)) }
1480
ensures { forall nd f. Mem.mem (nd, f) result -> no_neg_le f (lsl 1 t.size - 1) }
1481
raises { Overflow -> exists nd. Set.mem nd (support_snodes t.bdd) /\ nd.n = n1 /\
1482
(not (in_bounds (lsl 1 t.size - 1 + nd.s)) \/ not (in_bounds (- nd.s)) \/
1483
exists nd1. Set.mem nd1 t1.bdd.dom_snodes /\ not nd1.scal /\ not (in_bounds (to_int nd1.s + nd.s))) }
1484
= match l with
1485
| Nil -> Nil
1486
| Cons (Key.Var n s a) l' ->
1487
let r = build l' in
1488
if Node.equal n n1 then begin
1489
let nd = { SNode.n = n; SNode.s = s; SNode.scal = a } in
1490
let f =
1491
try shifted_bdd t.size s t1 with Overflow ->
1492
assert { Set.mem nd (support_snodes t.bdd) /\ nd.n = n1 /\
1493
(not (in_bounds (lsl 1 t.size - 1 + nd.s)) \/ not (in_bounds (- nd.s)) \/
1494
exists nd1. Set.mem nd1 t1.bdd.dom_snodes /\ not nd1.scal /\ not (in_bounds (to_int nd1.s + nd.s))) };
1495
raise Overflow
1496
end in
1497
let res = Cons (nd, f) r in
1498
let lemma post (nd': snode) (g': PBDD.t) (env: Node.t -> int) (p: int) : unit
1499
requires { Mem.mem (nd', g') res /\ 0 <= p < lsl 1 t.size }
1500
ensures { g'.PBDD.v p (sem env p) <-> bittest (value t1 env) (p + nd'.s) }
1501
= if pure { nd' = nd /\ g' = f } then assert { nd'.s = s }
1502
in
1503
res
1504
end else r
1505
| Cons (Key.Index _) l' -> build l'
1506
end
1507
in
1508
let l = build (PBDD.vars t.bdd) in
1509
let c = PBDD.compose_snodes (to_int t.size) l t.bdd in
1510
no_neg_compose t l c;
1511
let r = mk c t.size in
1512
let lemma eq (env: Node.t -> int) : unit
1513
ensures { value r env = value t (upd_env env n1 (value t1 env)) }
1514
=
1515
let ghost env' = upd_env env n1 (value t1 env) in
1516
let lemma bit (p: int) : unit
1517
requires { 0 <= p }
1518
ensures { bittest (value r env) p <-> bittest (value t env') p }
1519
=
1520
if numbits p <= to_int t.size then begin
1521
lt_lsl_of_numbits p (to_int t.size);
1522
let lemma same (nd: snode) : unit
1523
requires { Set.mem nd (support_snodes t.bdd) }
1524
ensures { subst_sn l p (sem env p) nd = sem env' p nd }
1525
= subst_sn_mem l p (sem env p) nd
1526
in
1527
support_snodes_v t.bdd p pure { subst_sn l p (sem env p) } pure { sem env' p }
1528
end
1529
in
1530
ext_bittest (value r env) (value t env')
1531
in
1532
r

The value of the BDD a at the position p for the node values env

    Valid (1.0s) (colibri2 10) (split_vc 4) (depth 3)
1535
let rec
eval
(env: Node.t -> int) (a: PBDD.t) (p: int) : bool
1536
variant { nb_nodes a }
1537
ensures { result <-> a.PBDD.v p (sem env p) }
1538
= match PBDD.inspect a with
1539
| PBDD.Bool b -> b
1540
| PBDD.IteIndex i th el ->
1541
if Zbit.test_bit p i then eval env th p else eval env el p
1542
| PBDD.IteSnode nd th el ->
1543
if (if nd.scal then env nd.n < 0
1544
else p + to_int nd.s >= 0 && ZbitInt.test_bit_int (env nd.n) (p + to_int nd.s))
1545
then eval env th p else eval env el p
1546
end

compute of bddbitv.ml. Differs from bddbitv.ml: OCaml computes get_cst (normalize p (fun n -> cst (f n))); here the BDD is evaluated at each of the 2^size positions (one path each, no BDD allocated).

    Valid (1.3s) (colibri2 20) (cvc4 2) (split_vc 2) (depth 2)
1553
let
compute
(env: Node.t -> int) (t: t) : int
1554
requires { lsl 1 t.size <= Int63.max_int }
1555
ensures { result = value t env }
1556
=
1557
let r = ref 0 in
1558
let n = Int63.lsl 1 t.size in
1559
for p = 0 to n - 1 do
1560
invariant { 0 <= !r }
1561
invariant { forall q. bittest !r q <-> (0 <= q < p /\ bittest (value t env) q) }
1562
if eval env t.bdd (to_int p) then begin
1563
mask_nonneg (to_int p);
1564
r := Zbit.lor !r (ZbitInt.lsl_int 1 (to_int p))
1565
end
1566
done;
1567
let lemma bit (q: int) : unit
1568
requires { 0 <= q }
1569
ensures { bittest !r q <-> bittest (value t env) q }
1570
= if q < to_int n then numbits_lt_lsl q (to_int t.size)
1571
else if numbits q <= to_int t.size then lt_lsl_of_numbits q (to_int t.size)
1572
in
1573
ext_bittest !r (value t env);
1574
!r

A position from which the snodes of the keys of l no longer change with the position (the program of stab_bound)

    Valid (410ms) (colibri2)
1578
let rec
stab_prog
(env: Node.t -> int) (l: list Key.t) : int
1579
variant { l }
1580
ensures { result = stab_bound env (snodes_of l) }
1581
= match l with
1582
| Nil -> 0
1583
| Cons (Key.Var n s _) l' ->
1584
let b = stab_prog env l' in
1585
let x = env n in
1586
let c = Zbit.numbits (if x < 0 then - x else x) + (if s < 0 then - to_int s else 0) in
1587
if b <= c then c else b
1588
| Cons (Key.Index _) l' -> stab_prog env l'
1589
end
1590
Valid (76ms) (colibri2)
1591
let ghost
bits_lt
(x n: int) : unit
1592
requires { 0 <= x /\ 0 <= n }
1593
requires { forall q. n <= q -> not (bittest x q) }
1594
ensures { x < lsl 1 n }
1595
=
1596
if x > 0 then begin
1597
numbits_top_bit x;
1598
numbits_lsl_lt x;
1599
assert { numbits x <= n };
1600
lsl_power (numbits x); lsl_power n;
1601
Power_monotonic 2 (numbits x) n
1602
end else mask_nonneg n

The integer value of a term, possibly negative or with a tail, for the values env of the nodes: the bits up to a position from which they are all equal (the loop is on the 2^size positions of the window as compute, plus the stabilization of the tail).

    Valid (1.2s) (colibri2 29) (cvc4 2) (split_vc) (depth 1)
1608
let
compute_i
(env: Node.t -> int) (t: t) : int
1609
ensures { is_value t env result }
1610
=
1611
let l = PBDD.vars t.tail in
1612
let ghost gl = snodes_of l in
1613
assert { forall nd. Set.mem nd (support_snodes t.tail) -> Mem.mem nd gl };
1614
mask_nonneg (to_int t.size);
1615
let w = ZbitInt.lsl_int 1 (to_int t.size) in
1616
let n = w + stab_prog env l in
1617
let r = ref 0 in
1618
for p = 0 to n - 1 do
1619
invariant { 0 <= !r }
1620
invariant { forall q. bittest !r q <-> (0 <= q < p /\ bit t q (sem env q)) }
1621
let b =
1622
if p < w then begin
1623
if p < w then numbits_lt_lsl p (to_int t.size);
1624
eval env t.bdd p
1625
end else begin
1626
if numbits p <= to_int t.size then lt_lsl_of_numbits p (to_int t.size);
1627
tail_v t.tail p (sem env p);
1628
eval env t.tail p
1629
end in
1630
if b then begin
1631
mask_nonneg p;
1632
r := Zbit.lor !r (ZbitInt.lsl_int 1 p)
1633
end
1634
done;
1635
if numbits n <= to_int t.size then lt_lsl_of_numbits n (to_int t.size);
1636
tail_v t.tail n (sem env n);
1637
let top = eval env t.tail n in
1638
bits_lt !r n;
1639
let z = if top then !r - ZbitInt.lsl_int 1 n else !r in
1640
let lemma bitz (p: int) : unit
1641
requires { 0 <= p }
1642
ensures { bittest z p <-> bit t p (sem env p) }
1643
=
1644
if p >= n then stream_stable t env gl p;
1645
if top then begin
1646
if p < n then bittest_sub_lsl !r n p
1647
else bittest_sub_lsl_high !r n p
1648
end
1649
in
1650
z

to_knownbits of bddbitv.ml: (known0, known1), the bits that can be 1 and the bits that are always 1 (the OCaml code then calls KnownBits.mk)

    Valid (433ms) (cvc4)
1655
let partial
to_knownbits
(t: t) : (known0: int, known1: int)
1656
requires { lsl 1 t.size <= Int63.max_int }
1657
ensures { forall q. bittest known0 q <-> (0 <= q /\ numbits q <= t.size /\ exists s. t.bdd.PBDD.v q s) }
1658
ensures { forall q. bittest known1 q <-> (0 <= q /\ numbits q <= t.size /\ forall s. t.bdd.PBDD.v q s) }
1659
ensures { forall env. Zbit.subset known1 (value t env) /\ Zbit.subset (value t env) known0 }
1660
=
1661
let e = PBDD.exist_snodes t.bdd in
1662
let a = PBDD.forall_snodes t.bdd in
1663
numbits_ge_pos 0 t.bdd.dom_indexes;
1664
let k0 = cst_value t.size e in
1665
let k1 = cst_value t.size a in
1666
assert { forall q. bittest k0 q <-> bittest (PBDD2.v e t.size (fun _ -> Set.empty)) q };
1667
assert { forall q. bittest k1 q <-> bittest (PBDD2.v a t.size (fun _ -> Set.empty)) q };
1668
(k0, k1)

A BDD that does not depend on the snodes outside of sx has its support in sx

    Valid (107ms) (cvc4)
1672
let ghost
supp_by
(c: PBDD.t) (sx: snodes) : unit
1673
requires { forall nd id sn. not (Set.mem nd sx) ->
1674
(c.PBDD.v id (Set.add nd sn) <-> c.PBDD.v id (Set.remove nd sn)) }
1675
ensures { Set.subset (support_snodes c) sx }
1676
=
1677
let lemma pt (nd: snode) : unit
1678
requires { Set.mem nd (support_snodes c) }
1679
ensures { Set.mem nd sx }
1680
= if pure { not (Set.mem nd sx) } then begin
1681
let ghost (id, sn) = PBDD.support_snodes_dep c nd in
1682
assert { c.PBDD.v id (Set.add nd sn) <-> c.PBDD.v id (Set.remove nd sn) }
1683
end
1684
in ()

The row c gives the value of nd: for each value of the other snodes, one value of nd makes it true

1688
predicate
functional
(nd: snode) (c: PBDD.t) =
1689
forall id sn. c.PBDD.v id (Set.add nd sn) \/ c.PBDD.v id (Set.remove nd sn)

Löwenheim's formula (lowenheim_formula of bddbitv.ml) for the snode nd in the equation a = false: r is the consistency condition, q a reproductive solution for nd. Differs from bddbitv.ml: ite pos false (ite neg true nd) is written dand (dnot pos) (dor neg nd) (same cost).

    Valid (1.8s) (colibri2 36) (cvc4 10) (split_vc) (depth 1)
1696
let partial
lowenheim
(nd: snode) (a: PBDD.t) : (q: PBDD.t, r: PBDD.t)
1697
ensures { numbits q.dom_indexes <= numbits a.dom_indexes }
1698
ensures { numbits r.dom_indexes <= numbits a.dom_indexes }
1699
ensures { Set.subset r.dom_snodes (Set.remove nd a.dom_snodes) }
1700
ensures { Set.subset q.dom_snodes (Set.add nd a.dom_snodes) }
1701
ensures { forall id sn. r.PBDD.v id sn <->
1702
(a.PBDD.v id (Set.add nd sn) /\ a.PBDD.v id (Set.remove nd sn)) }
1703
ensures { forall id sn. q.PBDD.v id sn <->
1704
(not (a.PBDD.v id (Set.add nd sn)) /\ (a.PBDD.v id (Set.remove nd sn) \/ Set.mem nd sn)) }
1705
ensures { forall id sn. not (r.PBDD.v id sn) -> not (a.PBDD.v id (Map.set sn nd (q.PBDD.v id sn))) }
1706
ensures { forall id sn. not (a.PBDD.v id sn) -> not (r.PBDD.v id sn) /\ (q.PBDD.v id sn <-> sn nd) }
1707
ensures { forall id sn b. r.PBDD.v id (Map.set sn nd b) <-> r.PBDD.v id sn }
1708
ensures { Set.subset (support_snodes r) (Set.remove nd (support_snodes a)) }
1709
ensures { Set.subset (support_snodes q) (Set.add nd (support_snodes a)) }
1710
ensures { functional nd a -> Set.subset (support_snodes q) (Set.remove nd (support_snodes a)) }
1711
=
1712
let (pos, neg) = PBDD.cofactors_snode nd a in
1713
let o = PBDD.dor neg (PBDD.bdd_of_snode nd) in
1714
let q = PBDD.dand (PBDD.dnot pos) o in
1715
let r = PBDD.dand pos neg in
1716
lor_numbits neg.dom_indexes 0;
1717
lor_numbits pos.dom_indexes o.dom_indexes;
1718
lor_numbits pos.dom_indexes neg.dom_indexes;
1719
let lemma sets (sn: snodes) (b: bool) : unit
1720
ensures { Set.add nd sn = Map.set sn nd True /\ Set.remove nd sn = Map.set sn nd False }
1721
ensures { Set.add nd (Map.set sn nd b) = Set.add nd sn /\ Set.remove nd (Map.set sn nd b) = Set.remove nd sn }
1722
ensures { sn nd -> Set.add nd sn = sn }
1723
ensures { not (sn nd) -> Set.remove nd sn = sn }
1724
=
1725
assert { forall x. Set.mem x (Set.add nd sn) <-> Map.set sn nd True x };
1726
assert { forall x. Set.mem x (Set.remove nd sn) <-> Map.set sn nd False x };
1727
assert { forall x. Set.mem x (Set.add nd (Map.set sn nd b)) <-> Set.mem x (Set.add nd sn) };
1728
assert { forall x. Set.mem x (Set.remove nd (Map.set sn nd b)) <-> Set.mem x (Set.remove nd sn) };
1729
assert { sn nd -> forall x. Set.mem x (Set.add nd sn) <-> sn x };
1730
assert { not (sn nd) -> forall x. Set.mem x (Set.remove nd sn) <-> sn x }
1731
in
1732
let lemma supp (x: snode) : unit
1733
requires { Set.mem x (support_snodes r) }
1734
ensures { x <> nd /\ Set.mem x (support_snodes a) }
1735
=
1736
let ghost (id, sn) = PBDD.support_snodes_dep r x in
1737
if pure { x = nd } then begin
1738
assert { r.PBDD.v id (Set.add nd sn) <-> r.PBDD.v id (Set.remove nd sn) }
1739
end else if pure { not (Set.mem x (support_snodes a)) } then begin
1740
PBDD.support_snodes_v a id pure { Set.add nd (Set.add x sn) } pure { Set.add nd (Set.remove x sn) };
1741
PBDD.support_snodes_v a id pure { Set.remove nd (Set.add x sn) } pure { Set.remove nd (Set.remove x sn) }
1742
end
1743
in
1744
let lemma qind (x: snode) (id: int) (sn: snodes) : unit
1745
requires { not (Set.mem x (Set.add nd (support_snodes a))) }
1746
ensures { q.PBDD.v id (Set.add x sn) <-> q.PBDD.v id (Set.remove x sn) }
1747
=
1748
PBDD.support_snodes_v a id pure { Set.add nd (Set.add x sn) } pure { Set.add nd (Set.remove x sn) };
1749
PBDD.support_snodes_v a id pure { Set.remove nd (Set.add x sn) } pure { Set.remove nd (Set.remove x sn) }
1750
in
1751
supp_by q pure { Set.add nd (support_snodes a) };
1752
let lemma qfun (_: unit) : unit
1753
requires { functional nd a }
1754
ensures { Set.subset (support_snodes q) (Set.remove nd (support_snodes a)) }
1755
=
1756
let lemma qind2 (x: snode) (id: int) (sn: snodes) : unit
1757
requires { not (Set.mem x (Set.remove nd (support_snodes a))) }
1758
ensures { q.PBDD.v id (Set.add x sn) <-> q.PBDD.v id (Set.remove x sn) }
1759
=
1760
if pure { x = nd } then begin
1761
assert { Set.add nd (Set.add x sn) = Set.add nd sn };
1762
assert { Set.remove nd (Set.add x sn) = Set.remove nd sn };
1763
assert { Set.add nd (Set.remove x sn) = Set.add nd sn };
1764
assert { Set.remove nd (Set.remove x sn) = Set.remove nd sn };
1765
assert { a.PBDD.v id (Set.add nd sn) \/ a.PBDD.v id (Set.remove nd sn) }
1766
end else qind x id sn
1767
in
1768
supp_by q pure { Set.remove nd (support_snodes a) }
1769
in
1770
(q, r)

t does not depend on the snode nd at the positions p with p + nd.s < 0 (where it reads a negative bit)

    Valid (71ms) (colibri2 3) (split_vc) (depth 1)
1774
let ghost
false_below
(nd: snode) (t: t) : unit
1775
ensures { forall p sn. 0 <= p -> numbits p <= t.size ->
1776
(t.bdd.PBDD.v p sn <-> t.bdd.PBDD.v p (if not (reads_at p nd) then Set.remove nd sn else sn)) }
1777
=
1778
let lemma pt (p: int) (sn: snodes) : unit
1779
requires { 0 <= p /\ numbits p <= t.size /\ not (reads_at p nd) }
1780
ensures { t.bdd.PBDD.v p sn <-> t.bdd.PBDD.v p (Set.remove nd sn) }
1781
= assert { agree p sn (Set.remove nd sn) }
1782
in ()

The simple case of solve: nd = {n; shift} is the only snode of the node n in the support of t; sz_n is sizes n. q gives the value of n, r is the consistency condition. Differs from bddbitv.ml: the window of q is grown to the positions read by t (2^size + shift, OCaml uses 2^size); this only matters for equations that read bits of n outside of its size. Less efficient: q is masked (one dand), as in rotate_right.

    Valid (4.6s) (colibri2 142) (cvc4 83) (cvc5 25) (split_vc 62) (depth 5)
1792
let partial
solve_simple
(t: t) (nd: snode) (sz_n: int63) : (q: t, r: t)
1793
requires { no_scal t.bdd /\ not nd.scal }
1794
requires { forall nd'. Set.mem nd' (support_snodes t.bdd) -> nd'.n = nd.n -> nd' = nd }
1795
requires { 0 <= sz_n <= 0x2000_0000_0000_0000 }
1796
requires { t.size <= 60 }
1797
requires { - 0x1000_0000_0000_0000 <= nd.s <= 0x1000_0000_0000_0000 }
1798
ensures { forall env x. value r (upd_env env nd.n x) = value r env }
1799
ensures { forall env. value r env = 0 -> value t (upd_env env nd.n (value q env)) = 0 }
1800
ensures { forall env. value t env = 0 -> 0 <= env nd.n < lsl 1 sz_n -> value q env = env nd.n }
1801
ensures { forall env. value t env = 0 -> value r env = 0 }
1802
raises { Overflow -> exists nd'. Set.mem nd' (Set.add nd t.bdd.dom_snodes) /\ not nd'.scal /\
1803
not (in_bounds (to_int nd'.s - nd.s)) }
1804
=
1805
let shift = nd.s in
1806
lsl_le_2_60 (to_int t.size);
1807
lsl_le_max_int (to_int t.size);
1808
mask_nonneg (to_int t.size);
1809
let maxpos = Int63.lsl 1 t.size - 1 in
1810
numbits_ge_pos 0 t.bdd.dom_indexes;
1811
let a = t.bdd in
1812
false_below nd t;
1813
let (ql, rl) = lowenheim nd a in
1815
(* [a] does not read a negative bit; [rl] neither; [ql] reads [nd] at a negative bit only at the positions dropped by the shift *)
1816
begin ensures { no_neg rl t.size /\ no_neg_off ql t.size shift }
1817
let lemma aag (p: int) (x y: snodes) : unit
1818
requires { 0 <= p /\ numbits p <= t.size /\ agree p x y }
1819
ensures { a.PBDD.v p x <-> a.PBDD.v p y }
1820
= if p + to_int shift < 0 then begin
1821
assert { agree p (Set.remove nd x) (Set.remove nd y) };
1822
assert { t.bdd.PBDD.v p (Set.remove nd x) <-> t.bdd.PBDD.v p (Set.remove nd y) }
1823
end else
1824
assert { t.bdd.PBDD.v p x <-> t.bdd.PBDD.v p y }
1825
in
1826
let lemma nr (p: int) (sn1 sn2: snodes) : unit
1827
requires { 0 <= p /\ numbits p <= t.size /\ agree p sn1 sn2 }
1828
ensures { rl.PBDD.v p sn1 <-> rl.PBDD.v p sn2 }
1829
= aag p (Set.add nd sn1) (Set.add nd sn2);
1830
aag p (Set.remove nd sn1) (Set.remove nd sn2)
1831
in
1832
assert { no_neg rl t.size };
1833
let lemma nq (q: int) (sn1 sn2: snodes) : unit
1834
requires { 0 <= q /\ 0 <= q + shift /\ numbits q <= t.size /\ agree q sn1 sn2 }
1835
ensures { ql.PBDD.v q sn1 <-> ql.PBDD.v q sn2 }
1836
= aag q (Set.add nd sn1) (Set.add nd sn2);
1837
aag q (Set.remove nd sn1) (Set.remove nd sn2);
1838
assert { Set.mem nd sn1 <-> Set.mem nd sn2 }
1839
in
1840
assert { no_neg_off ql t.size shift }
1841
end;
1842
let r = mk rl t.size in
1843
let w = Int63.lsl 1 t.size + (if shift > 0 then shift else 0) in
1844
let s = if sz_n > w then sz_n else w in
1845
let n_maxpos = s - 1 in
1846
numbits_ge_pos 0 (to_int n_maxpos);
1847
numbits_le_self (to_int n_maxpos);
1848
let n_size = Int63.of_int (Zbit.numbits (to_int n_maxpos)) in
1849
assert { Set.subset ql.PBDD.dom_snodes (Set.add nd t.bdd.dom_snodes) };
1850
let qs = shift_left_gen n_maxpos shift ql t.size in
1851
let lo = if shift > 0 then shift else 0 in
1852
let hi = maxpos + shift in
1853
mask_nonneg (to_int s);
1854
mask_numbits (to_int s);
1855
let z = if hi >= lo then Zbit.land (ZbitInt.mask_int (to_int s))
1856
(Zbit.lnot (ZbitInt.lsl_int (ZbitInt.mask_int (to_int hi - to_int lo + 1)) (to_int lo)))
1857
else ZbitInt.mask_int (to_int s) in
1858
land_nonneg_l pure { mask s } pure { lnot (lsl (mask (to_int hi - to_int lo + 1)) (to_int lo)) };
1859
numbits_subset z pure { mask s };
1860
let m = get (cst z) n_size in
1861
let nd0 = { SNode.n = nd.n; SNode.s = 0; SNode.scal = False } in
1862
let bm = PBDD2.dand (PBDD2.bdd_of_snode nd0) m in
1863
let qq = PBDD2.dor qs bm in
1864
lor_numbits qs.dom_indexes pure { lor 0 m.dom_indexes };
1865
lor_numbits 0 m.dom_indexes;
1866
begin ensures { no_neg_le bm n_maxpos }
1867
let lemma nbm (p: int) (sn1 sn2: snodes) : unit
1868
requires { 0 <= p /\ agree p sn1 sn2 }
1869
ensures { bm.PBDD.v p sn1 <-> bm.PBDD.v p sn2 }
1870
= PBDD.support_snodes_dom m;
1871
PBDD.support_snodes_v m p sn1 sn2;
1872
assert { to_int nd0.SNode.s = 0 };
1873
assert { Set.mem nd0 sn1 <-> Set.mem nd0 sn2 }
1874
in ()
1875
end;
1876
no_neg_le_or qq qs bm (to_int n_maxpos);
1877
let mq = mask_bdd n_size n_maxpos qq in
1878
no_neg_mask mq qq (to_int n_size) (to_int n_maxpos);
1879
let rq = mk mq n_size in
1880
(* A: [a] and [t] agree at node level *)
1881
let lemma la (env: Node.t -> int) (p: int) : unit
1882
requires { 0 <= p <= maxpos }
1883
ensures { a.PBDD.v p (sem env p) <-> t.bdd.PBDD.v p (sem env p) }
1884
=
1885
numbits_ge_pos p (to_int maxpos);
1886
if p + to_int shift < 0 then begin
1887
assert { not (sem env p nd) };
1888
PBDD.support_snodes_v t.bdd p pure { Set.remove nd (sem env p) } pure { sem env p }
1889
end
1890
in
1891
(* B: [a] only depends on the support of [t] and on [nd] *)
1892
let lemma lb (p: int) (x y: snodes) : unit
1893
requires { 0 <= p <= maxpos }
1894
requires { forall nd'. (Set.mem nd' (support_snodes t.bdd) \/ nd' = nd) -> (x nd' <-> y nd') }
1895
ensures { a.PBDD.v p x <-> a.PBDD.v p y }
1896
=
1897
numbits_ge_pos p (to_int maxpos);
1898
PBDD.support_snodes_v t.bdd p pure { Set.remove nd x } pure { Set.remove nd y };
1899
PBDD.support_snodes_v t.bdd p x y
1900
in
1901
(* C: the bits of [r] *)
1902
let lemma lc (env: Node.t -> int) (p: int) : unit
1903
requires { 0 <= p <= maxpos }
1904
ensures { bittest (value r env) p <->
1905
(a.PBDD.v p (Set.add nd (sem env p)) /\ a.PBDD.v p (Set.remove nd (sem env p))) }
1906
=
1907
numbits_ge_pos p (to_int maxpos);
1908
assert { bittest (value r env) p <-> rl.PBDD.v p (sem env p) }
1909
in
1910
(* D: the bits of [q] *)
1911
let lemma ld (env: Node.t -> int) (p': int) : unit
1912
requires { 0 <= p' }
1913
ensures { bittest (value rq env) p' <->
1914
(p' < s /\ if lo <= p' <= hi then ql.PBDD.v (p' - shift) (sem env (p' - shift))
1915
else bittest (env nd.n) p') }
1916
=
1917
if p' < to_int s then begin
1918
numbits_ge_pos p' (to_int n_maxpos);
1919
lt_lsl_of_numbits p' (to_int n_size);
1920
assert { bittest (mask (lsl 1 n_size)) p' };
1921
assert { bittest (mask (n_maxpos + 1)) p' };
1922
assert { bittest (value rq env) p' <-> bittest (PBDD2.v qq n_size (sem env)) p' };
1923
assert { nd0.SNode.n = nd.n /\ to_int nd0.SNode.s = 0 };
1924
sem_def env p' nd0;
1925
assert { sem env p' nd0 <-> bittest (env nd.n) p' };
1926
assert { numbits p' <= n_size };
1927
assert { bittest (snode_mask nd0 n_size (sem env)) p' <-> sem env p' nd0 };
1928
assert { bittest (snode_mask nd0 n_size (sem env)) p' <-> bittest (env nd.n) p' };
1929
assert { bittest (PBDD2.v m n_size (sem env)) p' <-> bittest z p' };
1930
assert { bittest (PBDD2.v qq n_size (sem env)) p' <->
1931
(bittest (PBDD2.v qs n_size (sem env)) p' \/ (bittest (env nd.n) p' /\ bittest z p')) };
1932
assert { bittest (PBDD2.v qs n_size (sem env)) p' <->
1933
(shift <= p' /\ bittest (PBDD2.v ql t.size (sem env)) (p' - shift)) };
1934
if to_int hi >= to_int lo then def_asr pure { mask (to_int hi - to_int lo + 1) } (- to_int lo) p';
1935
assert { bittest z p' <-> not (lo <= p' <= hi) };
1936
if to_int lo <= p' && p' <= to_int hi then begin
1937
numbits_ge_pos (p' - to_int shift) (to_int maxpos);
1938
assert { bittest (PBDD2.v ql t.size (sem env)) (p' - shift) <->
1939
ql.PBDD.v (p' - shift) (sem env (p' - shift)) };
1940
assert { bittest (value rq env) p' <-> ql.PBDD.v (p' - shift) (sem env (p' - shift)) }
1941
end else begin
1942
if to_int shift <= p' then begin
1943
if numbits (p' - to_int shift) <= to_int t.size then
1944
lt_lsl_of_numbits (p' - to_int shift) (to_int t.size)
1945
end;
1946
assert { bittest (value rq env) p' <-> bittest (env nd.n) p' }
1947
end
1948
end else begin
1949
assert { not (bittest (mask (n_maxpos + 1)) p') };
1950
assert { not (bittest (PBDD2.v mq n_size (sem env)) p') };
1951
assert { value rq env = PBDD2.v mq n_size (sem env) };
1952
assert { not (bittest (value rq env) p') }
1953
end
1954
in
1955
(* E: reproductive *)
1956
let lemma le (env: Node.t -> int) : unit
1957
requires { value t env = 0 /\ 0 <= env nd.n < lsl 1 sz_n }
1958
ensures { value rq env = env nd.n }
1959
=
1960
let lemma bit (p': int) : unit
1961
requires { 0 <= p' }
1962
ensures { bittest (value rq env) p' <-> bittest (env nd.n) p' }
1963
=
1964
ld env p';
1965
if p' >= to_int s then begin
1966
numbits_lt_lsl (env nd.n) (to_int sz_n);
1967
if env nd.n > 0 then numbits_high_clear (env nd.n) p'
1968
end else if to_int lo <= p' && p' <= to_int hi then begin
1969
let ghost j = p' - to_int shift in
1970
numbits_ge_pos j (to_int maxpos);
1971
lt_lsl_of_numbits j (to_int t.size);
1972
assert { not (bittest (value t env) j) };
1973
assert { not (t.bdd.PBDD.v j (sem env j)) };
1974
la env j;
1975
assert { sem env j nd <-> bittest (env nd.n) p' };
1976
if bittest (env nd.n) p' then lb j pure { Set.add nd (sem env j) } pure { sem env j }
1977
else lb j pure { Set.remove nd (sem env j) } pure { sem env j }
1978
end
1979
in
1980
ext_bittest (value rq env) (env nd.n)
1981
in
1982
(* F: solution *)
1983
let lemma lf (env: Node.t -> int) : unit
1984
requires { value r env = 0 }
1985
ensures { value t (upd_env env nd.n (value rq env)) = 0 }
1986
=
1987
let ghost env' = upd_env env nd.n (value rq env) in
1988
let lemma bit (p: int) : unit
1989
requires { 0 <= p }
1990
ensures { not (bittest (value t env') p) }
1991
=
1992
if numbits p <= to_int t.size then begin
1993
lt_lsl_of_numbits p (to_int t.size);
1994
la env' p;
1995
lc env p;
1996
assert { not (bittest (value r env) p) };
1997
let ghost sn = sem env p in
1998
if p + to_int shift < 0 then begin
1999
assert { not (sem env' p nd) };
2000
lb p pure { sem env' p } pure { Set.remove nd sn };
2001
PBDD.support_snodes_v t.bdd p pure { Set.remove nd (Set.add nd sn) } pure { Set.remove nd (Set.remove nd sn) };
2002
assert { a.PBDD.v p (Set.add nd sn) <-> a.PBDD.v p (Set.remove nd sn) }
2003
end else begin
2004
let ghost p' = p + to_int shift in
2005
ld env p';
2006
assert { lo <= p' <= hi /\ p' < s };
2007
assert { sem env' p nd <-> ql.PBDD.v p sn };
2008
if pure { ql.PBDD.v p sn } then lb p pure { sem env' p } pure { Set.add nd sn }
2009
else lb p pure { sem env' p } pure { Set.remove nd sn }
2010
end
2011
end
2012
in
2013
ext_bittest (value t env') 0
2014
in
2015
let lemma lz (env: Node.t -> int) : unit
2016
requires { value t env = 0 }
2017
ensures { value r env = 0 }
2018
=
2019
let lemma bit (p: int) : unit
2020
ensures { not (bittest (value r env) p) }
2021
=
2022
if 0 <= p && numbits p <= to_int t.size then begin
2023
lt_lsl_of_numbits p (to_int t.size);
2024
lc env p;
2025
la env p;
2026
assert { not (bittest (value t env) p) };
2027
assert { not (t.bdd.PBDD.v p (sem env p)) };
2028
if pure { sem env p nd } then lb p pure { Set.add nd (sem env p) } pure { sem env p }
2029
else lb p pure { Set.remove nd (sem env p) } pure { sem env p }
2030
end
2031
in
2032
ext_bittest (value r env) 0
2033
in
2034
let lemma lr (env: Node.t -> int) (x: int) : unit
2035
ensures { value r (upd_env env nd.n x) = value r env }
2036
=
2037
let ghost env' = upd_env env nd.n x in
2038
let lemma bit (p: int) : unit
2039
requires { 0 <= p }
2040
ensures { bittest (value r env') p <-> bittest (value r env) p }
2041
=
2042
if numbits p <= to_int t.size then begin
2043
lt_lsl_of_numbits p (to_int t.size);
2044
lc env' p;
2045
lc env p;
2046
lb p pure { Set.add nd (sem env' p) } pure { Set.add nd (sem env p) };
2047
lb p pure { Set.remove nd (sem env' p) } pure { Set.remove nd (sem env p) }
2048
end
2049
in
2050
ext_bittest (value r env') (value r env)
2051
in
2052
(rq, r)

get_var_less_shift of bddbitv.ml: a node with the fewest snodes in vars, with all its snodes

2056
(* ---- Solving a term with a tail ---- *)

The term is zero (all its bits are false) for the node values env

2059
predicate
zero_at
(t: t) (env: Node.t -> int) =
2060
forall p. 0 <= p -> not (bit t p (sem env p))
2061
Valid (52ms) (colibri2)
2062
let ghost
dom_zero
(x: int) : unit
2063
requires { 0 <= x /\ numbits x <= 0 }
2064
ensures { x = 0 }
2065
= if x > 0 then numbits_ge_pos 1 x

Löwenheim's formula on the window and on the tail, for a node n read only at the shift 0: r is the consistency condition (it does not depend on n) and q a reproductive solution for n.

    Valid (1.9s) (colibri2 37) (cvc4 16) (cvc5 5) (split_vc 3) (depth 2)
2070
let partial
solve_s0
(t: t) (n: Node.t) : (q: t, r: t)
2071
requires { forall nd. (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) ->
2072
nd.SNode.n = n -> to_int nd.s = 0 /\ not nd.SNode.scal }
2073
ensures { forall env x p. 0 <= p ->
2074
(bit r p (sem (upd_env env n x) p) <-> bit r p (sem env p)) }
2075
ensures { forall env z. is_value q env z -> zero_at r env -> zero_at t (upd_env env n z) }
2076
ensures { forall env. zero_at t env -> zero_at r env /\ is_value q env (env n) }
2077
=
2078
let nd = { SNode.n = n; SNode.s = 0; SNode.scal = False } in
2079
let (qw, rw) = lowenheim nd t.bdd in
2080
let (qt, rt) = lowenheim nd t.tail in
2081
dom_zero qt.dom_indexes; dom_zero rt.dom_indexes;
2082
numbits_ge_pos 0 t.bdd.dom_indexes;
2083
(* the invariants of the window and tail of [q] and [r] *)
2084
let lemma nnw (p: int) (sn1 sn2: snodes) : unit
2085
requires { 0 <= p /\ numbits p <= t.size /\ agree p sn1 sn2 }
2086
ensures { (qw.PBDD.v p sn1 <-> qw.PBDD.v p sn2) /\ (rw.PBDD.v p sn1 <-> rw.PBDD.v p sn2) }
2087
=
2088
assert { agree p (Set.add nd sn1) (Set.add nd sn2) };
2089
assert { agree p (Set.remove nd sn1) (Set.remove nd sn2) };
2090
assert { Set.mem nd sn1 <-> Set.mem nd sn2 }
2091
in
2092
let lemma nnt (sn1 sn2: snodes) : unit
2093
requires { agree (lsl 1 t.size) sn1 sn2 }
2094
ensures { (qt.PBDD.v 0 sn1 <-> qt.PBDD.v 0 sn2) /\ (rt.PBDD.v 0 sn1 <-> rt.PBDD.v 0 sn2) }
2095
=
2096
assert { agree (lsl 1 t.size) (Set.add nd sn1) (Set.add nd sn2) };
2097
assert { agree (lsl 1 t.size) (Set.remove nd sn1) (Set.remove nd sn2) };
2098
mask_nonneg (to_int t.size);
2099
assert { Set.mem nd sn1 <-> Set.mem nd sn2 }
2100
in
2101
let q = mk_t qw qt t.size in
2102
let r = mk_t rw rt t.size in
2103
(* the snodes of the node [n] in the supports are [nd] *)
2104
let lemma only_nd (a: PBDD.t) (nd': snode) : unit
2105
requires { Set.mem nd' (support_snodes a) /\ nd'.SNode.n = n }
2106
requires { Set.subset (support_snodes a) (Set.union (support_snodes t.bdd) (support_snodes t.tail)) }
2107
ensures { nd' = nd }
2108
= assert { nd'.s = nd.s }
2109
in
2110
(* (1) [r] does not depend on [n] *)
2111
let lemma ind (env: Node.t -> int) (x: int) (p: int) : unit
2112
requires { 0 <= p }
2113
ensures { bit r p (sem (upd_env env n x) p) <-> bit r p (sem env p) }
2114
=
2115
let env' = upd_env env n x in
2116
let lemma agw (nd': snode) : unit
2117
requires { Set.mem nd' (support_snodes rw) }
2118
ensures { sem env' p nd' <-> sem env p nd' }
2119
=
2120
assert { Set.mem nd' (support_snodes t.bdd) /\ nd' <> nd };
2121
if pure { nd'.SNode.n = n } then assert { nd' = nd };
2122
sem_def env' p nd'; sem_def env p nd'
2123
in
2124
let lemma agt (nd': snode) : unit
2125
requires { Set.mem nd' (support_snodes rt) }
2126
ensures { sem env' p nd' <-> sem env p nd' }
2127
=
2128
assert { Set.mem nd' (support_snodes t.tail) /\ nd' <> nd };
2129
if pure { nd'.SNode.n = n } then assert { nd' = nd };
2130
sem_def env' p nd'; sem_def env p nd'
2131
in
2132
PBDD.support_snodes_v rw p (sem env' p) (sem env p);
2133
tail_v rt p (sem env' p); tail_v rt p (sem env p);
2134
PBDD.support_snodes_v rt 0 (sem env' p) (sem env p)
2135
in
2136
(* (3) the reproductive property *)
2137
let lemma repr (env: Node.t -> int) (p: int) : unit
2138
requires { 0 <= p /\ not (bit t p (sem env p)) }
2139
ensures { not (bit r p (sem env p)) }
2140
ensures { bit q p (sem env p) <-> bittest (env n) p }
2141
=
2142
sem_def env p nd;
2143
tail_v t.tail p (sem env p)
2144
in
2145
(* (2) the soundness *)
2146
let lemma sound (env: Node.t -> int) (z: int) (p: int) : unit
2147
requires { 0 <= p /\ not (bit r p (sem env p)) /\ (bit q p (sem env p) <-> bittest z p) }
2148
ensures { not (bit t p (sem (upd_env env n z) p)) }
2149
=
2150
let env' = upd_env env n z in
2151
let sn = sem env p in
2152
let sn' = sem env' p in
2153
let b = bit q p sn in
2154
let lemma agw (nd': snode) : unit
2155
requires { Set.mem nd' (support_snodes t.bdd) }
2156
ensures { sn' nd' <-> (Map.set sn nd b) nd' }
2157
=
2158
if pure { nd'.SNode.n = n } then begin
2159
assert { nd' = nd };
2160
sem_def env' p nd
2161
end else sem_def env' p nd'; sem_def env p nd'
2162
in
2163
let lemma agt (nd': snode) : unit
2164
requires { Set.mem nd' (support_snodes t.tail) }
2165
ensures { sn' nd' <-> (Map.set sn nd b) nd' }
2166
=
2167
if pure { nd'.SNode.n = n } then begin
2168
assert { nd' = nd };
2169
sem_def env' p nd
2170
end else sem_def env' p nd'; sem_def env p nd'
2171
in
2172
tail_v t.tail p sn'; tail_v t.tail p (Map.set sn nd b);
2173
tail_v rt p sn; tail_v qt p sn;
2174
PBDD.support_snodes_v t.bdd p sn' (Map.set sn nd b);
2175
PBDD.support_snodes_v t.tail 0 sn' (Map.set sn nd b)
2176
in
2177
q, r

The snodes of the shifted term t' are the shifted snodes of t: the snodes of n, read at the shift sh in t, have the shift 0 in t' (and no scalar of n appears)

    Valid (164ms) (colibri2 3) (split_vc 2) (depth 2)
2182
let ghost
shifted_zero
(t t': t) (n: Node.t) (sh: int63) : unit
2183
requires { forall nd''. (Set.mem nd'' (support_snodes t'.bdd) \/ Set.mem nd'' (support_snodes t'.tail)) ->
2184
exists nd. (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) /\
2185
(nd.scal \/ in_bounds (to_int nd.s - to_int sh)) /\
2186
nd'' = shift_snode nd (to_int sh) }
2187
requires { forall nd. (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) ->
2188
nd.SNode.n = n -> nd.SNode.s = sh /\ not nd.SNode.scal }
2189
ensures { forall nd. (Set.mem nd (support_snodes t'.bdd) \/ Set.mem nd (support_snodes t'.tail)) ->
2190
nd.SNode.n = n -> to_int nd.SNode.s = 0 /\ not nd.SNode.scal }
2191
=
2192
let lemma one (nd'': snode) : unit
2193
requires { Set.mem nd'' (support_snodes t'.bdd) \/ Set.mem nd'' (support_snodes t'.tail) }
2194
requires { nd''.SNode.n = n }
2195
ensures { to_int nd''.SNode.s = 0 /\ not nd''.SNode.scal }
2196
= ()
2197
in ()

The equation t = 0 solved for the node n read only at the shift sh: the shift of t by sh moves it to the shift 0 (solve_s0); when sh < 0 the bits of t below -sh do not depend on n and are added to the consistency condition.

    Valid (724ms) (colibri2 45) (cvc4 13) (cvc5) (split_vc 2) (depth 2)
2203
let partial
solve_single
(t: t) (n: Node.t) (sh: int63) : (q: t, r: t)
2204
requires { t.size <= 60 }
2205
requires { - 0x1000_0000_0000_0000 <= sh <= 0x1000_0000_0000_0000 }
2206
requires { Set.mem { SNode.n = n; SNode.s = sh; SNode.scal = False } (support_snodes t.bdd) \/
2207
Set.mem { SNode.n = n; SNode.s = sh; SNode.scal = False } (support_snodes t.tail) }
2208
requires { forall nd. (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) ->
2209
nd.SNode.n = n -> nd.SNode.s = sh /\ not nd.SNode.scal }
2210
ensures { forall env x p. 0 <= p -> (bit r p (sem (upd_env env n x) p) <-> bit r p (sem env p)) }
2211
ensures { forall env z. is_value q env z -> zero_at r env -> zero_at t (upd_env env n z) }
2212
ensures { forall env. zero_at t env -> zero_at r env /\ is_value q env (env n) }
2213
raises { Overflow -> exists nd. Set.mem nd (all_snodes t) /\ not nd.scal /\ not (in_bounds (to_int nd.s - to_int sh)) }
2214
=
2215
lsl_le_2_60 (to_int t.size);
2216
shift_bound t { SNode.n = n; SNode.s = sh; SNode.scal = False };
2217
let t' = shift_i sh t in
2218
shifted_zero t t' n sh;
2219
begin
2220
let (q, r0) = solve_s0 t' n in
2221
(* the bits of [t'] are the bits of [t] moved by [sh] *)
2222
let lemma moved (env: Node.t -> int) (p: int) : unit
2223
requires { 0 <= p /\ to_int sh <= p }
2224
ensures { bit t' p (sem env p) <-> bit t (p - to_int sh) (sem env (p - to_int sh)) }
2225
= ()
2226
in
2227
let lemma below (env: Node.t -> int) (p: int) : unit
2228
requires { 0 <= p < sh }
2229
ensures { not (bit t' p (sem env p)) }
2230
= ()
2231
in
2232
if sh >= 0 then begin
2233
let lemma zt (env: Node.t -> int) : unit
2234
ensures { zero_at t' env <-> zero_at t env }
2235
=
2236
if pure { zero_at t' env } then begin
2237
let lemma pt (p: int) : unit
2238
requires { 0 <= p }
2239
ensures { not (bit t p (sem env p)) }
2240
= moved env (p + to_int sh); assert { p + to_int sh - to_int sh = p }
2241
in ()
2242
end;
2243
if pure { zero_at t env } then begin
2244
let lemma pt (p: int) : unit
2245
requires { 0 <= p }
2246
ensures { not (bit t' p (sem env p)) }
2247
= if p < to_int sh then below env p else moved env p
2248
in ()
2249
end
2250
in
2251
let lemma sol (env: Node.t -> int) (z: int) : unit
2252
requires { is_value q env z /\ zero_at r0 env }
2253
ensures { zero_at t (upd_env env n z) }
2254
= zt (upd_env env n z)
2255
in
2256
(q, r0)
2257
end else begin
2258
let k = - sh in
2259
mask_nonneg (to_int k);
2260
mask_numbits (to_int k);
2261
let m = ZbitInt.mask_int (to_int k) in
2262
let c = cst_z m in
2263
let low = logand_i t c in
2264
let r = logor_i low r0 in
2265
(* the bits of [t] below [k] do not depend on [n] *)
2266
let lemma lowind (env: Node.t -> int) (x: int) (p: int) : unit
2267
requires { 0 <= p < k }
2268
ensures { bit t p (sem (upd_env env n x) p) <-> bit t p (sem env p) }
2269
=
2270
let env' = upd_env env n x in
2271
let lemma pt (nd: snode) : unit
2272
requires { Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail) }
2273
ensures { sem env' p nd <-> sem env p nd }
2274
=
2275
sem_def env' p nd; sem_def env p nd;
2276
if pure { nd.SNode.n = n } then assert { to_int nd.SNode.s = sh }
2277
in
2278
if numbits p <= to_int t.size then PBDD.support_snodes_v t.bdd p (sem env' p) (sem env p)
2279
else begin
2280
tail_v t.tail p (sem env' p); tail_v t.tail p (sem env p);
2281
PBDD.support_snodes_v t.tail 0 (sem env' p) (sem env p)
2282
end
2283
in
2284
let lemma lowbit (env: Node.t -> int) (p: int) : unit
2285
requires { 0 <= p }
2286
ensures { bit low p (sem env p) <-> (p < k /\ bit t p (sem env p)) }
2287
=
2288
if p < to_int k then mask_bits (to_int k) p else mask_bits_high (to_int k) p
2289
in
2290
let lemma zt (env: Node.t -> int) : unit
2291
ensures { zero_at t env <-> (zero_at t' env /\ zero_at low env) }
2292
=
2293
if pure { zero_at t env } then begin
2294
let lemma pt (p: int) : unit
2295
requires { 0 <= p }
2296
ensures { not (bit t' p (sem env p)) /\ not (bit low p (sem env p)) }
2297
= moved env p; lowbit env p
2298
in ()
2299
end;
2300
if pure { zero_at t' env /\ zero_at low env } then begin
2301
let lemma pt (p: int) : unit
2302
requires { 0 <= p }
2303
ensures { not (bit t p (sem env p)) }
2304
= lowbit env p;
2305
if p >= to_int k then begin
2306
moved env (p - to_int k);
2307
assert { p - to_int k - to_int sh = p }
2308
end
2309
in ()
2310
end
2311
in
2312
let lemma lowzero_env (env: Node.t -> int) (x: int) : unit
2313
requires { zero_at low env }
2314
ensures { zero_at low (upd_env env n x) }
2315
=
2316
let lemma pt (p: int) : unit
2317
requires { 0 <= p }
2318
ensures { not (bit low p (sem (upd_env env n x) p)) }
2319
= lowbit env p; lowbit (upd_env env n x) p;
2320
if p < to_int k then lowind env x p
2321
in ()
2322
in
2323
let lemma sol (env: Node.t -> int) (z: int) : unit
2324
requires { is_value q env z /\ zero_at r env }
2325
ensures { zero_at t (upd_env env n z) }
2326
=
2327
assert { zero_at low env /\ zero_at r0 env };
2328
lowzero_env env z;
2329
zt (upd_env env n z)
2330
in
2331
(q, r)
2332
end
2333
end

The keys of the node n in l have the shift s

    Valid (962ms) (cvc5)
2336
let rec
same_shift
(n: Node.t) (s: int63) (l: list Key.t) : bool
2337
variant { l }
2338
ensures { result <-> forall n' s' a'. Mem.mem (Key.Var n' s' a') l -> n' = n -> s' = s /\ not a' }
2339
= match l with
2340
| Nil -> true
2341
| Cons (Key.Var n' s' a') l' -> (if Node.equal n' n then s' = s && not a' else true) && same_shift n s l'
2342
| Cons (Key.Index _) l' -> same_shift n s l'
2343
end

A node read at one shift in all1 and all2

    Valid (134ms) (colibri2)
2346
let rec
find_single
(l all1 all2: list Key.t) : option (Node.t, int63)
2347
variant { l }
2348
ensures { match result with
2349
| None -> forall n s a. Mem.mem (Key.Var n s a) l -> a \/
2350
s < - 0x1000_0000_0000_0000 \/ s > 0x1000_0000_0000_0000 \/
2351
(exists n' s' a'. Mem.mem (Key.Var n' s' a') all1 /\ n' = n /\ (s' <> s \/ a')) \/
2352
(exists n' s' a'. Mem.mem (Key.Var n' s' a') all2 /\ n' = n /\ (s' <> s \/ a'))
2353
| Some (n, s) -> Mem.mem (Key.Var n s False) l /\
2354
- 0x1000_0000_0000_0000 <= s <= 0x1000_0000_0000_0000 /\
2355
(forall n' s' a'. Mem.mem (Key.Var n' s' a') all1 -> n' = n -> s' = s /\ not a') /\
2356
(forall n' s' a'. Mem.mem (Key.Var n' s' a') all2 -> n' = n -> s' = s /\ not a')
2357
end }
2358
= match l with
2359
| Nil -> None
2360
| Cons (Key.Var n s a) l' ->
2361
if not a && s >= - 0x1000_0000_0000_0000 && s <= 0x1000_0000_0000_0000 &&
2362
same_shift n s all1 && same_shift n s all2 then Some (n, s)
2363
else find_single l' all1 all2
2364
| Cons (Key.Index _) l' -> find_single l' all1 all2
2365
end

No snode in the keys

    Valid (702ms) (cvc5)
2368
let rec
no_key_var
(l: list Key.t) : bool
2369
variant { l }
2370
ensures { result <-> forall n s a. not (Mem.mem (Key.Var n s a) l) }
2371
= match l with
2372
| Nil -> true
2373
| Cons (Key.Var _ _ _) _ -> false
2374
| Cons (Key.Index _) l' -> no_key_var l'
2375
end

The bits of t only depend on its support

    Valid (73ms) (cvc4)
2378
let ghost
bit_supp
(t: t) (p: int) (sn1 sn2: snodes) : unit
2379
requires { 0 <= p }
2380
requires { forall nd. (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) ->
2381
(sn1 nd <-> sn2 nd) }
2382
ensures { bit t p sn1 <-> bit t p sn2 }
2383
=
2384
PBDD.support_snodes_v t.bdd p sn1 sn2;
2385
PBDD.support_snodes_v t.tail 0 sn1 sn2
2386
Valid (53ms) (colibri2)
2387
let ghost
set_eq
(sn: snodes) (nd: snode) : unit
2388
ensures { Set.add nd sn = Map.set sn nd True /\ Set.remove nd sn = Map.set sn nd False }
2389
=
2390
assert { forall x. Set.mem x (Set.add nd sn) <-> Map.set sn nd True x };
2391
assert { forall x. Set.mem x (Set.remove nd sn) <-> Map.set sn nd False x }

sn and sn' agree on the scalars

2394
predicate
scal_agree
(sn sn': snodes) = forall nd'. nd'.SNode.scal -> (Set.mem nd' sn <-> Set.mem nd' sn')

The cofactor of t for the value b of nd only reads scalars

2397
predicate
cof_scal
(t: t) (nd: snode) (b: bool) =
2398
forall p sn sn'. 0 <= p -> scal_agree sn sn' -> (bit t p (Map.set sn nd b) <-> bit t p (Map.set sn' nd b))

The cofactor of t for the value b of nd is never zero

2401
predicate
cof_nz
(t: t) (nd: snode) (b: bool) (sn: snodes) =
2402
exists p. 0 <= p /\ bit t p (Map.set sn nd b)
2403
2404
predicate
cof_taut
(t: t) (nd: snode) (b: bool) = forall sn. cof_nz t nd b sn

The scalar nd cannot be solved: not both cofactors read only scalars, and no cofactor that reads only scalars is never zero

2408
predicate
scal_hard
(t: t) (nd: snode) =
2409
not (cof_scal t nd True /\ cof_scal t nd False) /\
2410
not (cof_scal t nd True /\ cof_taut t nd True) /\
2411
not (cof_scal t nd False /\ cof_taut t nd False)
2412
Valid (109ms) (cvc5)
2413
let rec
all_scal
(l: list Key.t) : bool
2414
variant { l }
2415
ensures { result <-> forall n s a. Mem.mem (Key.Var n s a) l -> a }
2416
= match l with
2417
| Nil -> true
2418
| Cons (Key.Var _ _ a) l' -> a && all_scal l'
2419
| Cons (Key.Index _) l' -> all_scal l'
2420
end

The window and the tail of the cofactor of t for the value b of nd

    Valid (1.2s) (colibri2 8) (cvc4 3) (split_vc 5) (depth 3)
2423
let partial
cof_bdds
(t: t) (nd: snode) (b: bool) : (cw: PBDD.t, ct: PBDD.t)
2424
ensures { cw.PBDD.dom_indexes = t.bdd.PBDD.dom_indexes /\ ct.PBDD.dom_indexes = 0 }
2425
ensures { forall id sn. cw.PBDD.v id sn <-> t.bdd.PBDD.v id (Map.set sn nd b) }
2426
ensures { forall id sn. ct.PBDD.v id sn <-> t.tail.PBDD.v 0 (Map.set sn nd b) }
2427
ensures { forall p sn. 0 <= p ->
2428
(bit t p (Map.set sn nd b) <-> if numbits p <= t.size then cw.PBDD.v p sn else ct.PBDD.v 0 sn) }
2429
=
2430
let (pw, nw) = PBDD.cofactors_snode nd t.bdd in
2431
let (pt, nt) = PBDD.cofactors_snode nd t.tail in
2432
let cw = if b then pw else nw in
2433
let ct = if b then pt else nt in
2434
let lemma cv (id: int) (sn: snodes) : unit
2435
ensures { cw.PBDD.v id sn <-> t.bdd.PBDD.v id (Map.set sn nd b) }
2436
ensures { ct.PBDD.v id sn <-> t.tail.PBDD.v 0 (Map.set sn nd b) }
2437
= set_eq sn nd; tail_v t.tail id (Map.set sn nd b)
2438
in
2439
(cw, ct)

cof_scal, checked on the snodes of the cofactor

    Valid (422ms) (colibri2 29) (cvc4 7) (cvc5 2) (split_vc 3) (depth 2)
2442
let partial
cof_scal_check
(t: t) (nd: snode) (b: bool) : bool
2443
ensures { result <-> cof_scal t nd b }
2444
=
2445
let (cw, ct) = cof_bdds t nd b in
2446
mask_nonneg (to_int t.size);
2447
let kw = PBDD.vars cw in
2448
let kt = PBDD.vars ct in
2449
if all_scal kw && all_scal kt then begin
2450
let lemma sc (p: int) (sn sn': snodes) : unit
2451
requires { 0 <= p /\ scal_agree sn sn' }
2452
ensures { bit t p (Map.set sn nd b) <-> bit t p (Map.set sn' nd b) }
2453
=
2454
let lemma ag (k: list Key.t) (c: PBDD.t) (nd': snode) : unit
2455
requires { forall n s a. Mem.mem (Key.Var n s a) k <-> Set.mem { SNode.n = n; SNode.s = s; SNode.scal = a } (support_snodes c) }
2456
requires { forall n s a. Mem.mem (Key.Var n s a) k -> a }
2457
requires { Set.mem nd' (support_snodes c) }
2458
ensures { sn nd' <-> sn' nd' }
2459
= assert { Mem.mem (Key.Var nd'.SNode.n nd'.SNode.s nd'.SNode.scal) k }
2460
in
2461
let lemma sw (nd': snode) : unit
2462
requires { Set.mem nd' (support_snodes cw) }
2463
ensures { sn nd' <-> sn' nd' }
2464
= ag kw cw nd'
2465
in
2466
let lemma st (nd': snode) : unit
2467
requires { Set.mem nd' (support_snodes ct) }
2468
ensures { sn nd' <-> sn' nd' }
2469
= ag kt ct nd'
2470
in
2471
PBDD.support_snodes_v cw p sn sn'; PBDD.support_snodes_v ct 0 sn sn'
2472
in
2473
true
2474
end else begin
2475
let lemma nc (k: list Key.t) (c: PBDD.t) (w: bool) : unit
2476
requires { forall n s a. Mem.mem (Key.Var n s a) k -> Set.mem { SNode.n = n; SNode.s = s; SNode.scal = a } (support_snodes c) }
2477
requires { not (forall n s a. Mem.mem (Key.Var n s a) k -> a) }
2478
requires { c = cw /\ w \/ c = ct /\ not w }
2479
ensures { not (cof_scal t nd b) }
2480
=
2481
let ghost (n', s') = any (Node.t, int63) ensures { let (n, s) = result in Mem.mem (Key.Var n s False) k } in
2482
let ghost nd' = { SNode.n = n'; SNode.s = s'; SNode.scal = False } in
2483
assert { Set.mem nd' (support_snodes c) };
2484
let ghost (id, sn) = PBDD.support_snodes_dep c nd' in
2485
assert { scal_agree (Set.add nd' sn) (Set.remove nd' sn) };
2486
if w then begin
2487
let ghost p = pure { land (mask t.size) id } in
2488
land_nonneg_l pure { mask t.size } id;
2489
numbits_subset p pure { mask t.size };
2490
mask_numbits (to_int t.size);
2491
PBDD.support_v cw id p (Set.add nd' sn);
2492
PBDD.support_v cw id p (Set.remove nd' sn);
2493
assert { bit t p (Map.set (Set.add nd' sn) nd b) <> bit t p (Map.set (Set.remove nd' sn) nd b) }
2494
end else begin
2495
let ghost p = pure { lsl 1 t.size } in
2496
numbits_lsl (to_int t.size);
2497
tail_v ct id (Set.add nd' sn); tail_v ct id (Set.remove nd' sn);
2498
assert { bit t p (Map.set (Set.add nd' sn) nd b) <> bit t p (Map.set (Set.remove nd' sn) nd b) }
2499
end
2500
in
2501
if not (all_scal kw) then nc kw cw true else nc kt ct false;
2502
false
2503
end

The positions where the cofactor of t for the value b of nd is not zero exist: exists p. bit t p (Map.set sn nd b)

    Valid (1.1s) (colibri2 21) (cvc4 3) (split_vc 6) (depth 5)
2507
let partial
cof_glob
(t: t) (nd: snode) (b: bool) : PBDD.t
2508
ensures { result.PBDD.dom_indexes = 0 }
2509
ensures { forall id sn. result.PBDD.v id sn <-> exists p. 0 <= p /\ bit t p (Map.set sn nd b) }
2510
=
2511
let (cw, ct) = cof_bdds t nd b in
2512
numbits_ge_pos 0 t.bdd.dom_indexes;
2513
let gw = PBDD.exist_window cw t.size in
2514
let g = PBDD.dor gw ct in
2515
lor_zero ();
2516
mask_nonneg (to_int t.size);
2517
let lemma gv (id: int) (sn: snodes) : unit
2518
ensures { g.PBDD.v id sn <-> exists p. 0 <= p /\ bit t p (Map.set sn nd b) }
2519
=
2520
if pure { ct.PBDD.v id sn } then begin
2521
tail_v ct id sn;
2522
let ghost p = pure { lsl 1 t.size } in
2523
numbits_lsl (to_int t.size);
2524
assert { bit t p (Map.set sn nd b) }
2525
end;
2526
if pure { exists p. 0 <= p /\ bit t p (Map.set sn nd b) } then begin
2527
let ghost p = any int ensures { 0 <= result /\ bit t result (Map.set sn nd b) } in
2528
if numbits p > to_int t.size then begin
2529
tail_v ct id sn; assert { ct.PBDD.v id sn }
2530
end else begin
2531
assert { cw.PBDD.v p sn };
2532
assert { gw.PBDD.v id sn }
2533
end
2534
end;
2535
if pure { gw.PBDD.v id sn } then begin
2536
let ghost p = any int ensures { 0 <= result /\ numbits result <= t.size /\ cw.PBDD.v result sn } in
2537
assert { bit t p (Map.set sn nd b) }
2538
end
2539
in
2540
g

A term with no index that reads only scalars

    Valid (89ms) (colibri2 17) (split_vc) (depth 1)
2543
let partial
scal_term
(g: PBDD.t) : t
2544
requires { g.PBDD.dom_indexes = 0 }
2545
requires { forall sn sn'. scal_agree sn sn' -> (g.PBDD.v 0 sn <-> g.PBDD.v 0 sn') }
2546
ensures { forall p sn. 0 <= p -> (bit result p sn <-> g.PBDD.v 0 sn) }
2547
=
2548
let lemma nn (p: int) (sn1 sn2: snodes) : unit
2549
requires { agree p sn1 sn2 }
2550
ensures { g.PBDD.v p sn1 <-> g.PBDD.v p sn2 }
2551
= tail_v g p sn1; tail_v g p sn2;
2552
assert { scal_agree sn1 sn2 }
2553
in
2554
let lemma nt (sn1 sn2: snodes) : unit
2555
requires { agree 1 sn1 sn2 }
2556
ensures { g.PBDD.v 0 sn1 <-> g.PBDD.v 0 sn2 }
2557
= assert { scal_agree sn1 sn2 }
2558
in
2559
numbits_ge_pos 0 0;
2560
let r = mk_t g g 0 in
2561
let lemma pt (p: int) (sn: snodes) : unit
2562
requires { 0 <= p }
2563
ensures { bit r p sn <-> g.PBDD.v 0 sn }
2564
= tail_v g p sn
2565
in
2566
r

The node n has no other snode than nd in l

    Valid (140ms) (colibri2 9) (split_vc 2) (depth 2)
2569
let rec
same_atom
(nd: snode) (l: list Key.t) : bool
2570
variant { l }
2571
ensures { result <-> forall n' s' a'. Mem.mem (Key.Var n' s' a') l -> n' = nd.SNode.n ->
2572
s' = nd.SNode.s /\ a' = nd.SNode.scal }
2573
= match l with
2574
| Nil -> true
2575
| Cons (Key.Var n' s' a') l' ->
2576
assert { forall n'' s'' a''. Mem.mem (Key.Var n'' s'' a'') l <->
2577
((n'' = n' /\ s'' = s' /\ a'' = a') \/ Mem.mem (Key.Var n'' s'' a'') l') };
2578
let h = if Node.equal n' nd.SNode.n then s' = nd.SNode.s && Bool.(=) a' nd.SNode.scal else true in
2579
assert { h <-> (n' = nd.SNode.n -> s' = nd.SNode.s /\ a' = nd.SNode.scal) };
2580
assert { Mem.mem (Key.Var n' s' a') l };
2581
assert { (forall n'' s'' a''. Mem.mem (Key.Var n'' s'' a'') l -> n'' = nd.SNode.n ->
2582
s'' = nd.SNode.s /\ a'' = nd.SNode.scal)
2583
<-> (h /\ forall n'' s'' a''. Mem.mem (Key.Var n'' s'' a'') l' -> n'' = nd.SNode.n ->
2584
s'' = nd.SNode.s /\ a'' = nd.SNode.scal) };
2585
h && same_atom nd l'
2586
| Cons (Key.Index _) l' ->
2587
assert { forall n'' s'' a''. Mem.mem (Key.Var n'' s'' a'') l <-> Mem.mem (Key.Var n'' s'' a'') l' };
2588
same_atom nd l'
2589
end
2590
2591
type
isolve
=
IZero
|
IUnsat
|
ISubst
Node.t t t |
IUnsolved
2592
2593
predicate
in_supports
(t: t) (nd: snode) =
2594
Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)

Every node of the term is read at several shifts, or at a shift that is too big (the cases that int_solve_t does not solve)

2598
predicate
hard
(t: t) =
2599
(exists nd. in_supports t nd) /\
2600
forall nd. in_supports t nd ->
2601
(exists nd'. in_supports t nd' /\ nd'.SNode.n = nd.SNode.n /\ nd' <> nd) \/
2602
(nd.SNode.scal /\ scal_hard t nd) \/
2603
(not nd.SNode.scal /\ (nd.SNode.s < - 0x1000_0000_0000_0000 \/ nd.SNode.s > 0x1000_0000_0000_0000))

The contract of int_solve_t

2606
predicate
isolve_ok
(t: t) (r: isolve) =
2607
match r with
2608
| IZero -> forall env. zero_at t env
2609
| IUnsat -> forall env. not (zero_at t env)
2610
| ISubst n q r ->
2611
(forall env x p. 0 <= p -> (bit r p (sem (upd_env env n x) p) <-> bit r p (sem env p))) /\
2612
(forall env z. is_value q env z -> zero_at r env -> zero_at t (upd_env env n z)) /\
2613
(forall env. zero_at t env -> zero_at r env /\ is_value q env (env n))
2614
| IUnsolved -> t.size > 60 \/ hard t
2615
end

t = 0 when the scalar nd is the only snode of its node and the cofactor for its value b reads only scalars and is never zero: the sign of the node is not b; q forces this sign (n & ~sgn n or n | ~sgn n, idempotent) and r is the other cofactor.

    Valid (42ms) (colibri2 3) (split_vc) (depth 1)
2621
let ghost
taut_at
(t: t) (nd: snode) (b: bool) (sn: snodes) : int
2622
requires { cof_taut t nd b }
2623
ensures { 0 <= result /\ bit t result (Map.set sn nd b) }
2624
= assert { cof_nz t nd b sn };
2625
any int ensures { 0 <= result /\ bit t result (Map.set sn nd b) }
2626
Valid (1.2s) (colibri2 93) (cvc4 6) (split_vc 6) (depth 4)
2627
let partial
solve_force
(t: t) (nd: snode) (b: bool) : (q: t, r: t)
2628
requires { nd.SNode.scal }
2629
requires { forall nd'. (Set.mem nd' (support_snodes t.bdd) \/ Set.mem nd' (support_snodes t.tail)) ->
2630
nd'.SNode.n = nd.SNode.n -> nd' = nd }
2631
requires { cof_scal t nd b /\ cof_taut t nd b }
2632
ensures { forall env x p. 0 <= p -> (bit r p (sem (upd_env env nd.SNode.n x) p) <-> bit r p (sem env p)) }
2633
ensures { forall env z. is_value q env z -> zero_at r env -> zero_at t (upd_env env nd.SNode.n z) }
2634
ensures { forall env. zero_at t env -> zero_at r env /\ is_value q env (env nd.SNode.n) }
2635
=
2636
let n = nd.SNode.n in
2637
let nb = not b in
2638
let (pw, nw) = PBDD.cofactors_snode nd t.bdd in
2639
let (pt, nt) = PBDD.cofactors_snode nd t.tail in
2640
let cw = if nb then pw else nw in
2641
let ct = if nb then pt else nt in
2642
let lemma cv (id: int) (sn: snodes) : unit
2643
ensures { cw.PBDD.v id sn <-> t.bdd.PBDD.v id (Map.set sn nd nb) }
2644
ensures { ct.PBDD.v id sn <-> t.tail.PBDD.v id (Map.set sn nd nb) }
2645
= set_eq sn nd
2646
in
2647
let lemma nn (p: int) (sn1 sn2: snodes) : unit
2648
requires { 0 <= p /\ numbits p <= t.size /\ agree p sn1 sn2 }
2649
ensures { cw.PBDD.v p sn1 <-> cw.PBDD.v p sn2 }
2650
= assert { agree p (Map.set sn1 nd nb) (Map.set sn2 nd nb) }
2651
in
2652
let lemma nt (sn1 sn2: snodes) : unit
2653
requires { agree (lsl 1 t.size) sn1 sn2 }
2654
ensures { ct.PBDD.v 0 sn1 <-> ct.PBDD.v 0 sn2 }
2655
= assert { agree (lsl 1 t.size) (Map.set sn1 nd nb) (Map.set sn2 nd nb) }
2656
in
2657
let r = mk_t cw ct t.size in
2658
let ghost c = if nb then -1 else 0 in
2659
let lemma rsem (env: Node.t -> int) (p: int) : unit
2660
requires { 0 <= p }
2661
ensures { bit r p (sem env p) <-> bit t p (sem (upd_env env n c) p) }
2662
=
2663
assert { bit r p (sem env p) <-> bit t p (Map.set (sem env p) nd nb) };
2664
let lemma sp (nd': snode) : unit
2665
requires { Set.mem nd' (support_snodes t.bdd) \/ Set.mem nd' (support_snodes t.tail) }
2666
ensures { Map.set (sem env p) nd nb nd' <-> sem (upd_env env n c) p nd' }
2667
= sem_def env p nd'; sem_def (upd_env env n c) p nd'
2668
in
2669
bit_supp t p pure { Map.set (sem env p) nd nb } pure { sem (upd_env env n c) p }
2670
in
2671
(* [t] only depends on the sign of [n] *)
2672
let lemma tsign (env: Node.t -> int) (x y: int) (p: int) : unit
2673
requires { 0 <= p /\ (x < 0 <-> y < 0) }
2674
ensures { bit t p (sem (upd_env env n x) p) <-> bit t p (sem (upd_env env n y) p) }
2675
=
2676
let lemma sp (nd': snode) : unit
2677
requires { Set.mem nd' (support_snodes t.bdd) \/ Set.mem nd' (support_snodes t.tail) }
2678
ensures { sem (upd_env env n x) p nd' <-> sem (upd_env env n y) p nd' }
2679
= sem_def (upd_env env n x) p nd'; sem_def (upd_env env n y) p nd'
2680
in
2681
bit_supp t p pure { sem (upd_env env n x) p } pure { sem (upd_env env n y) p }
2682
in
2683
let m = umonome n in
2684
let sg = lognot_i (uscalar n) in
2685
let q = if b then logand_i m sg else logor_i m sg in
2686
let lemma qbit (env: Node.t -> int) (p: int) : unit
2687
requires { 0 <= p }
2688
ensures { bit q p (sem env p) <->
2689
if b then bittest (env n) p /\ not (env n < 0) else bittest (env n) p \/ not (env n < 0) }
2690
= sem_def env p { SNode.n = n; SNode.s = 0; SNode.scal = False };
2691
sem_def env p { SNode.n = n; SNode.s = 0; SNode.scal = True }
2692
in
2693
(* the sign of the value of [q] is [nb] *)
2694
let lemma qsign (env: Node.t -> int) (z: int) : unit
2695
requires { is_value q env z }
2696
ensures { z < 0 <-> nb }
2697
=
2698
numbits_ge_pos 0 (iabs z);
2699
numbits_ge_pos 0 (iabs (env n));
2700
let ghost p = numbits (iabs z) + numbits (iabs (env n)) in
2701
bittest_sign z p;
2702
bittest_sign (env n) p;
2703
qbit env p
2704
in
2705
let lemma e1 (env: Node.t -> int) (x: int) (p: int) : unit
2706
requires { 0 <= p }
2707
ensures { bit r p (sem (upd_env env n x) p) <-> bit r p (sem env p) }
2708
= rsem env p; rsem (upd_env env n x) p;
2709
assert { upd_env (upd_env env n x) n c = upd_env env n c }
2710
in
2711
let lemma e2 (env: Node.t -> int) (z: int) : unit
2712
requires { is_value q env z /\ zero_at r env }
2713
ensures { zero_at t (upd_env env n z) }
2714
=
2715
qsign env z;
2716
let lemma pt (p: int) : unit
2717
requires { 0 <= p }
2718
ensures { not (bit t p (sem (upd_env env n z) p)) }
2719
= rsem env p; tsign env z c p
2720
in ()
2721
in
2722
let lemma e3 (env: Node.t -> int) : unit
2723
requires { zero_at t env }
2724
ensures { zero_at r env /\ is_value q env (env n) }
2725
=
2726
if pure { env n < 0 <-> b } then begin
2727
let ghost p0 = taut_at t nd b pure { sem env 0 } in
2728
assert { scal_agree (sem env 0) (sem env p0) };
2729
sem_def env p0 nd;
2730
assert { Map.set (sem env p0) nd b = sem env p0 };
2731
assert { bit t p0 (Map.set (sem env p0) nd b) };
2732
absurd
2733
end;
2734
assert { upd_env env n (env n) = env };
2735
let lemma pt (p: int) : unit
2736
requires { 0 <= p }
2737
ensures { not (bit r p (sem env p)) }
2738
= rsem env p; tsign env (env n) c p
2739
in
2740
let lemma pv (p: int) : unit
2741
requires { 0 <= p }
2742
ensures { bittest (env n) p <-> bit q p (sem env p) }
2743
= qbit env p
2744
in ()
2745
in
2746
(q, r)

t = 0 when the scalar nd is the only snode of its node and both cofactors read only scalars: Löwenheim on the Boolean conditions g_b = exists p. t_p of the cofactors. The sign of n becomes phi = ~g1 /\ (g0 \/ sgn n), q = ite(sgn n <> phi, phi, n) (bit by bit; idempotent), r = g1 /\ g0.

    Valid (1.4s) (colibri2 68) (cvc4 24) (split_vc 11) (depth 3)
2753
let partial
solve_bool
(t: t) (nd: snode) : (q: t, r: t)
2754
requires { nd.SNode.scal }
2755
requires { forall nd'. (Set.mem nd' (support_snodes t.bdd) \/ Set.mem nd' (support_snodes t.tail)) ->
2756
nd'.SNode.n = nd.SNode.n -> nd' = nd }
2757
requires { cof_scal t nd True /\ cof_scal t nd False }
2758
ensures { isolve_ok t (ISubst nd.SNode.n q r) }
2759
=
2760
let n = nd.SNode.n in
2761
let g1 = cof_glob t nd true in
2762
let g0 = cof_glob t nd false in
2763
(* [g_c] reads only the scalars, and not [nd] *)
2764
let lemma gs (c: bool) (sn sn': snodes) : unit
2765
requires { scal_agree sn sn' }
2766
ensures { c -> (g1.PBDD.v 0 sn <-> g1.PBDD.v 0 sn') }
2767
ensures { not c -> (g0.PBDD.v 0 sn <-> g0.PBDD.v 0 sn') }
2768
= assert { cof_scal t nd c by (c = True \/ c = False) };
2769
let lemma w (p: int) : unit
2770
requires { 0 <= p }
2771
ensures { bit t p (Map.set sn nd c) <-> bit t p (Map.set sn' nd c) } = () in
2772
assert { (exists p. 0 <= p /\ bit t p (Map.set sn nd c)) <->
2773
(exists p. 0 <= p /\ bit t p (Map.set sn' nd c)) }
2774
in
2775
let lemma gs1 (sn sn': snodes) : unit
2776
requires { scal_agree sn sn' }
2777
ensures { (g1.PBDD.v 0 sn <-> g1.PBDD.v 0 sn') /\ (g0.PBDD.v 0 sn <-> g0.PBDD.v 0 sn') }
2778
= gs true sn sn'; gs false sn sn'
2779
in
2780
let bn = PBDD2.bdd_of_snode nd in
2781
let phi = PBDD.dand (PBDD.dnot g1) (PBDD.dor g0 bn) in
2782
let x = PBDD.dxor bn phi in
2783
let rb = PBDD.dand g1 g0 in
2784
lor_zero ();
2785
let lemma sa (sn sn': snodes) : unit
2786
requires { scal_agree sn sn' }
2787
ensures { phi.PBDD.v 0 sn <-> phi.PBDD.v 0 sn' }
2788
ensures { x.PBDD.v 0 sn <-> x.PBDD.v 0 sn' }
2789
ensures { rb.PBDD.v 0 sn <-> rb.PBDD.v 0 sn' }
2790
= gs1 sn sn'
2791
in
2792
let tphi = scal_term phi in
2793
let tx = scal_term x in
2794
let r = scal_term rb in
2795
let q = logor_i (logand_i (umonome n) (lognot_i tx)) (logand_i tphi tx) in
2796
(* the scalars of [env] *)
2797
let lemma scal_p (env: Node.t -> int) (p: int) : unit
2798
ensures { scal_agree (sem env p) (sem env 0) }
2799
= ()
2800
in
2801
(* the Boolean condition of [t] for the sign [c] of [n] *)
2802
let lemma lz (env: Node.t -> int) (c: bool) : unit
2803
ensures { (exists p. 0 <= p /\ bit t p (Map.set (sem env p) nd c)) <->
2804
(if c then g1.PBDD.v 0 (sem env 0) else g0.PBDD.v 0 (sem env 0)) }
2805
=
2806
let lemma pt (p: int) : unit
2807
requires { 0 <= p }
2808
ensures { bit t p (Map.set (sem env p) nd c) <-> bit t p (Map.set (sem env 0) nd c) }
2809
= scal_p env p;
2810
assert { cof_scal t nd c by (c = True \/ c = False) }
2811
in
2812
let lemma pt0 (p: int) : unit
2813
requires { 0 <= p /\ bit t p (Map.set (sem env p) nd c) }
2814
ensures { exists p'. 0 <= p' /\ bit t p' (Map.set (sem env 0) nd c) }
2815
= pt p
2816
in
2817
assert { (exists p. 0 <= p /\ bit t p (Map.set (sem env p) nd c)) <->
2818
(exists p. 0 <= p /\ bit t p (Map.set (sem env 0) nd c)) };
2819
if c then assert { g1.PBDD.v 0 (sem env 0) <-> exists p. 0 <= p /\ bit t p (Map.set (sem env 0) nd True) }
2820
else assert { g0.PBDD.v 0 (sem env 0) <-> exists p. 0 <= p /\ bit t p (Map.set (sem env 0) nd False) }
2821
in
2822
(* [t] at the value [z] of [n] *)
2823
let lemma tz (env: Node.t -> int) (z: int) (p: int) : unit
2824
requires { 0 <= p }
2825
ensures { bit t p (sem (upd_env env n z) p) <-> bit t p (Map.set (sem env p) nd (z < 0)) }
2826
=
2827
let lemma sp (nd': snode) : unit
2828
requires { Set.mem nd' (support_snodes t.bdd) \/ Set.mem nd' (support_snodes t.tail) }
2829
ensures { sem (upd_env env n z) p nd' <-> Map.set (sem env p) nd (z < 0) nd' }
2830
= sem_def (upd_env env n z) p nd'; sem_def env p nd'
2831
in
2832
bit_supp t p pure { sem (upd_env env n z) p } pure { Map.set (sem env p) nd (z < 0) }
2833
in
2834
let lemma zt (env: Node.t -> int) : unit
2835
ensures { zero_at t env <-> not (if env n < 0 then g1.PBDD.v 0 (sem env 0) else g0.PBDD.v 0 (sem env 0)) }
2836
=
2837
assert { upd_env env n (env n) = env };
2838
let lemma pt (p: int) : unit
2839
requires { 0 <= p }
2840
ensures { bit t p (sem env p) <-> bit t p (Map.set (sem env p) nd (env n < 0)) }
2841
= tz env (env n) p
2842
in
2843
lz env (env n < 0)
2844
in
2845
(* [g_c] does not read [n] *)
2846
let lemma gn (env: Node.t -> int) (y: int) : unit
2847
ensures { g1.PBDD.v 0 (sem (upd_env env n y) 0) <-> g1.PBDD.v 0 (sem env 0) }
2848
ensures { g0.PBDD.v 0 (sem (upd_env env n y) 0) <-> g0.PBDD.v 0 (sem env 0) }
2849
=
2850
let lemma pt (c: bool) (p: int) : unit
2851
requires { 0 <= p }
2852
ensures { bit t p (Map.set (sem (upd_env env n y) 0) nd c) <-> bit t p (Map.set (sem env 0) nd c) }
2853
=
2854
let lemma sp (nd': snode) : unit
2855
requires { Set.mem nd' (support_snodes t.bdd) \/ Set.mem nd' (support_snodes t.tail) }
2856
ensures { Map.set (sem (upd_env env n y) 0) nd c nd' <-> Map.set (sem env 0) nd c nd' }
2857
= sem_def (upd_env env n y) 0 nd'; sem_def env 0 nd'
2858
in
2859
bit_supp t p pure { Map.set (sem (upd_env env n y) 0) nd c } pure { Map.set (sem env 0) nd c }
2860
in
2861
assert { forall p. 0 <= p -> (bit t p (Map.set (sem (upd_env env n y) 0) nd True) <-> bit t p (Map.set (sem env 0) nd True)) };
2862
assert { forall p. 0 <= p -> (bit t p (Map.set (sem (upd_env env n y) 0) nd False) <-> bit t p (Map.set (sem env 0) nd False)) };
2863
(* the definition of [g_c] (cof_glob) at the two points *)
2864
let ghost sn1 = sem (upd_env env n y) 0 in
2865
let ghost sn0 = sem env 0 in
2866
assert { g1.PBDD.v 0 sn1 <-> exists p. 0 <= p /\ bit t p (Map.set sn1 nd True) };
2867
assert { g1.PBDD.v 0 sn0 <-> exists p. 0 <= p /\ bit t p (Map.set sn0 nd True) };
2868
assert { g0.PBDD.v 0 sn1 <-> exists p. 0 <= p /\ bit t p (Map.set sn1 nd False) };
2869
assert { g0.PBDD.v 0 sn0 <-> exists p. 0 <= p /\ bit t p (Map.set sn0 nd False) }
2870
in
2871
let lemma qbit (env: Node.t -> int) (p: int) : unit
2872
requires { 0 <= p }
2873
ensures { bit q p (sem env p) <->
2874
if x.PBDD.v 0 (sem env p) then phi.PBDD.v 0 (sem env p) else bittest (env n) p }
2875
= sem_def env p { SNode.n = n; SNode.s = 0; SNode.scal = False }
2876
in
2877
let lemma phiv (env: Node.t -> int) : unit
2878
ensures { phi.PBDD.v 0 (sem env 0) <->
2879
not (g1.PBDD.v 0 (sem env 0)) /\ (g0.PBDD.v 0 (sem env 0) \/ env n < 0) }
2880
ensures { x.PBDD.v 0 (sem env 0) <-> not (phi.PBDD.v 0 (sem env 0) <-> env n < 0) }
2881
= sem_def env 0 nd
2882
in
2883
let lemma r_n (env: Node.t -> int) (y: int) (p: int) : unit
2884
requires { 0 <= p }
2885
ensures { bit r p (sem (upd_env env n y) p) <-> bit r p (sem env p) }
2886
= scal_p env p; scal_p (upd_env env n y) p; gn env y;
2887
sa (sem env p) (sem env 0); sa (sem (upd_env env n y) p) (sem (upd_env env n y) 0)
2888
in
2889
let lemma rz (env: Node.t -> int) : unit
2890
ensures { zero_at r env <-> not (g1.PBDD.v 0 (sem env 0) /\ g0.PBDD.v 0 (sem env 0)) }
2891
=
2892
let lemma pt (p: int) : unit
2893
requires { 0 <= p }
2894
ensures { bit r p (sem env p) <-> rb.PBDD.v 0 (sem env 0) }
2895
= scal_p env p; sa (sem env p) (sem env 0)
2896
in
2897
assert { bit r 0 (sem env 0) <-> rb.PBDD.v 0 (sem env 0) }
2898
in
2899
(* the sign of the value of [q] is [phi] *)
2900
let lemma qsign (env: Node.t -> int) (z: int) : unit
2901
requires { is_value q env z }
2902
ensures { z < 0 <-> phi.PBDD.v 0 (sem env 0) }
2903
=
2904
numbits_ge_pos 0 (iabs z);
2905
numbits_ge_pos 0 (iabs (env n));
2906
let ghost p = numbits (iabs z) + numbits (iabs (env n)) in
2907
bittest_sign z p;
2908
bittest_sign (env n) p;
2909
qbit env p; phiv env;
2910
scal_p env p; sa (sem env p) (sem env 0)
2911
in
2912
let lemma e2 (env: Node.t -> int) (z: int) : unit
2913
requires { is_value q env z /\ zero_at r env }
2914
ensures { zero_at t (upd_env env n z) }
2915
=
2916
qsign env z; rz env; phiv env;
2917
assert { not (if z < 0 then g1.PBDD.v 0 (sem env 0) else g0.PBDD.v 0 (sem env 0)) };
2918
lz env (z < 0);
2919
let lemma pt (p: int) : unit
2920
requires { 0 <= p }
2921
ensures { not (bit t p (sem (upd_env env n z) p)) }
2922
= tz env z p
2923
in ()
2924
in
2925
let lemma e3 (env: Node.t -> int) : unit
2926
requires { zero_at t env }
2927
ensures { zero_at r env /\ is_value q env (env n) }
2928
=
2929
zt env; rz env; phiv env;
2930
assert { not (x.PBDD.v 0 (sem env 0)) };
2931
let lemma pv (p: int) : unit
2932
requires { 0 <= p }
2933
ensures { bittest (env n) p <-> bit q p (sem env p) }
2934
= qbit env p; scal_p env p; sa (sem env p) (sem env 0)
2935
in ()
2936
in
2937
(q, r)

cof_taut, checked on the BDD of exists p. bit t p

    Valid (481ms) (colibri2 9) (cvc4) (split_vc) (depth 1)
2940
let partial
cof_taut_check
(t: t) (nd: snode) (b: bool) : bool
2941
ensures { result <-> cof_taut t nd b }
2942
= let g = cof_glob t nd b in
2943
let (e, ghost wid, ghost w) = PBDD.is_equal g (PBDD.ttrue ()) in
2944
let lemma gt (sn: snodes) : unit
2945
ensures { g.PBDD.v 0 sn <-> exists p. 0 <= p /\ bit t p (Map.set sn nd b) }
2946
= ()
2947
in
2948
if e then begin
2949
let lemma tt (sn: snodes) : unit
2950
ensures { cof_nz t nd b sn }
2951
= gt sn; assert { g.PBDD.v 0 sn }
2952
in
2953
assert { forall sn. cof_nz t nd b sn };
2954
assert { cof_taut t nd b }
2955
end else begin
2956
let lemma nt (_: unit) : unit
2957
ensures { not (cof_taut t nd b) }
2958
= assert { cof_taut t nd b -> cof_nz t nd b w };
2959
assert { not (g.PBDD.v wid w) };
2960
assert { not (exists p. 0 <= p /\ bit t p (Map.set w nd b)) }
2961
in ()
2962
end;
2963
e

The cases of a scalar that is the only snode of its node

    Valid (391ms) (colibri2 33) (cvc4) (split_vc 3) (depth 2)
2966
let partial
solve_scal
(t: t) (nd: snode) : option (t, t)
2967
requires { nd.SNode.scal }
2968
requires { forall nd'. (Set.mem nd' (support_snodes t.bdd) \/ Set.mem nd' (support_snodes t.tail)) ->
2969
nd'.SNode.n = nd.SNode.n -> nd' = nd }
2970
ensures { match result with
2971
| Some (q, r) -> isolve_ok t (ISubst nd.SNode.n q r)
2972
| None -> scal_hard t nd
2973
end }
2974
=
2975
let s1 = cof_scal_check t nd true in
2976
let s0 = cof_scal_check t nd false in
2977
if s1 && s0 then begin
2978
let (q, r) = solve_bool t nd in Some (q, r)
2979
end else begin
2980
if s1 && cof_taut_check t nd true then begin
2981
let (q, r) = solve_force t nd true in Some (q, r)
2982
end else if s0 && cof_taut_check t nd false then begin
2983
let (q, r) = solve_force t nd false in Some (q, r)
2984
end else None
2985
end

A scalar, the only snode of its node, that solve_scal solves

    Valid (558ms) (colibri2 11) (cvc5 2) (split_vc) (depth 1)
2988
let rec partial
find_scal
(t: t) (l all1 all2: list Key.t) : isolve
2989
variant { l }
2990
requires { forall n s a. Mem.mem (Key.Var n s a) all1 \/ Mem.mem (Key.Var n s a) all2 <->
2991
in_supports t { SNode.n = n; SNode.s = s; SNode.scal = a } }
2992
ensures { match result with
2993
| IUnsolved -> forall n s. Mem.mem (Key.Var n s True) l ->
2994
(exists n' s' a'. (Mem.mem (Key.Var n' s' a') all1 \/ Mem.mem (Key.Var n' s' a') all2) /\
2995
n' = n /\ (s' <> s \/ not a')) \/
2996
scal_hard t { SNode.n = n; SNode.s = s; SNode.scal = True }
2997
| r -> isolve_ok t r
2998
end }
2999
= match l with
3000
| Nil -> IUnsolved
3001
| Cons (Key.Var n s a) l' ->
3002
let nd = { SNode.n = n; SNode.s = s; SNode.scal = True } in
3003
if a && same_atom nd all1 && same_atom nd all2 then begin
3004
match solve_scal t nd with
3005
| Some (q, r) -> ISubst n q r
3006
| None -> find_scal t l' all1 all2
3007
end
3008
end else find_scal t l' all1 all2
3009
| Cons (Key.Index _) l' -> find_scal t l' all1 all2
3010
end

The equation t = 0 on terms with a tail (negative values and unbounded nodes). Solved when the term has no node, or when a node is read at one shift only (the solution is then exact for every value of the node); IUnsolved only when the term is too big or every node is read at several shifts (hard).

    Valid (1.4s) (colibri2 39) (cvc4 4) (cvc5 6) (split_vc 7) (depth 3)
3017
let partial
int_solve_t
(t: t) : isolve
3018
ensures { isolve_ok t result }
3019
raises { Overflow -> exists nd. Set.mem nd (all_snodes t) /\ exists sh: int. not (in_bounds (to_int nd.s - sh)) }
3020
=
3021
if t.size > 60 then IUnsolved
3022
else begin
3023
let kb = PBDD.vars t.bdd in
3024
let kt = PBDD.vars t.tail in
3025
if no_key_var kb && no_key_var kt then begin
3026
(* a constant term *)
3027
let lemma cst_ind (env: Node.t -> int) (p: int) (sn: snodes) : unit
3028
requires { 0 <= p }
3029
ensures { bit t p (sem env p) <-> bit t p sn }
3030
=
3031
PBDD.support_snodes_v t.bdd p (sem env p) sn;
3032
tail_v t.tail p (sem env p); tail_v t.tail p sn;
3033
PBDD.support_snodes_v t.tail 0 (sem env p) sn
3034
in
3035
if is_zero_t t then begin
3036
let lemma z (env: Node.t -> int) : unit
3037
ensures { zero_at t env }
3038
= ()
3039
in
3040
IZero
3041
end else begin
3042
assert { exists p sn. 0 <= p /\ bit t p sn };
3043
let ghost (p0, sn0) = any (int, snodes) ensures { let (p, sn) = result in 0 <= p /\ bit t p sn } in
3044
let lemma nz (env: Node.t -> int) : unit
3045
ensures { not (zero_at t env) }
3046
= cst_ind env p0 sn0
3047
in
3048
IUnsat
3049
end
3050
end else match find_single kb kb kt with
3051
| Some (n, sh) -> let (q, r) = solve_single t n sh in ISubst n q r
3052
| None ->
3053
match find_single kt kb kt with
3054
| Some (n, sh) -> let (q, r) = solve_single t n sh in ISubst n q r
3055
| None ->
3056
match find_scal t kb kb kt with
3057
| IUnsolved ->
3058
match find_scal t kt kb kt with
3059
| IUnsolved ->
3060
let lemma hardp (_: unit) : unit
3061
ensures { hard t }
3062
=
3063
let lemma ex (_: unit) : unit
3064
ensures { exists nd. in_supports t nd }
3065
= if not (no_key_var kb) then begin
3066
let ghost (n, s, a) = any (Node.t, int63, bool) ensures { let (n, s, a) = result in Mem.mem (Key.Var n s a) kb } in
3067
assert { in_supports t { SNode.n = n; SNode.s = s; SNode.scal = a } }
3068
end else begin
3069
let ghost (n, s, a) = any (Node.t, int63, bool) ensures { let (n, s, a) = result in Mem.mem (Key.Var n s a) kt } in
3070
assert { in_supports t { SNode.n = n; SNode.s = s; SNode.scal = a } }
3071
end
3072
in
3073
let lemma al (nd: snode) : unit
3074
requires { in_supports t nd }
3075
ensures { (exists nd'. in_supports t nd' /\ nd'.SNode.n = nd.SNode.n /\ nd' <> nd) \/
3076
(nd.SNode.scal /\ scal_hard t nd) \/
3077
(not nd.SNode.scal /\ (nd.SNode.s < - 0x1000_0000_0000_0000 \/ nd.SNode.s > 0x1000_0000_0000_0000)) }
3078
=
3079
let lemma sib (n' : Node.t) (s': int63) (a': bool) : unit
3080
requires { Mem.mem (Key.Var n' s' a') kb \/ Mem.mem (Key.Var n' s' a') kt }
3081
requires { n' = nd.SNode.n /\ (s' <> nd.SNode.s \/ a' <> nd.SNode.scal) }
3082
ensures { exists nd'. in_supports t nd' /\ nd'.SNode.n = nd.SNode.n /\ nd' <> nd }
3083
= assert { in_supports t { SNode.n = n'; SNode.s = s'; SNode.scal = a' } }
3084
in
3085
if pure { Set.mem nd (support_snodes t.bdd) } then begin
3086
assert { Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) kb }
3087
end else begin
3088
assert { Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) kt }
3089
end;
3090
if nd.SNode.scal then begin
3091
assert { nd = { SNode.n = nd.SNode.n; SNode.s = nd.SNode.s; SNode.scal = True } };
3092
assert { Mem.mem (Key.Var nd.SNode.n nd.SNode.s True) kb \/ Mem.mem (Key.Var nd.SNode.n nd.SNode.s True) kt };
3093
assert { (exists n' s' a'. (Mem.mem (Key.Var n' s' a') kb \/ Mem.mem (Key.Var n' s' a') kt) /\
3094
n' = nd.SNode.n /\ (s' <> nd.SNode.s \/ not a')) \/
3095
scal_hard t nd }
3096
end else begin
3097
assert { nd.SNode.s < - 0x1000_0000_0000_0000 \/ nd.SNode.s > 0x1000_0000_0000_0000 \/
3098
(exists n' s' a'. (Mem.mem (Key.Var n' s' a') kb \/ Mem.mem (Key.Var n' s' a') kt) /\
3099
n' = nd.SNode.n /\ (s' <> nd.SNode.s \/ a')) }
3100
end
3101
in ()
3102
in
3103
IUnsolved
3104
| r -> r
3105
end
3106
| r -> r
3107
end
3108
end
3109
end
3110
end

The bit of a term without node does not depend on the valuation

    Valid (98ms) (cvc4)
3113
let ghost
bit_indep
(t: t) (env env': Node.t -> int) (p: int) : unit
3114
requires { 0 <= p }
3115
requires { forall nd. not (in_supports t nd) }
3116
ensures { bit t p (sem env p) <-> bit t p (sem env' p) }
3117
=
3118
PBDD.support_snodes_v t.bdd p (sem env p) (sem env' p);
3119
tail_v t.tail p (sem env p); tail_v t.tail p (sem env' p);
3120
PBDD.support_snodes_v t.tail 0 (sem env p) (sem env' p)

The integer value of a term without node

    Valid (667ms) (colibri2 5) (cvc4) (cvc5 2) (split_vc 4) (depth 4)
3123
let
int_is_cst
(t: t) : option int
3124
ensures { match result with
3125
| Some z -> forall env. is_value t env z
3126
| None -> exists nd. in_supports t nd
3127
end }
3128
=
3129
let kb = PBDD.vars t.bdd in
3130
let kt = PBDD.vars t.tail in
3131
if no_key_var kb && no_key_var kt then begin
3132
let env0 = fun (_: Node.t) -> (0: int) in
3133
let z = compute_i env0 t in
3134
let lemma all (env: Node.t -> int) : unit
3135
ensures { is_value t env z }
3136
=
3137
let lemma pt (p: int) : unit
3138
requires { 0 <= p }
3139
ensures { bittest z p <-> bit t p (sem env p) }
3140
= bit_indep t env0 env p
3141
in ()
3142
in
3143
Some z
3144
end else None

(known0, known1): the bits that can be 1 and the bits that are always 1, for a term with a tail (negative when the tail is)

    Valid (786ms) (colibri2 95) (cvc4 16) (split_vc 46) (depth 4)
3148
let partial
int_to_knownbits
(t: t) : (known0: int, known1: int)
3149
requires { lsl 1 t.size <= Int63.max_int }
3150
ensures { forall q. 0 <= q -> (bittest known0 q <-> exists sn. bit t q sn) }
3151
ensures { forall q. 0 <= q -> (bittest known1 q <-> forall sn. bit t q sn) }
3152
=
3153
let e = PBDD.exist_snodes t.bdd in
3154
let a = PBDD.forall_snodes t.bdd in
3155
let et = PBDD.exist_snodes t.tail in
3156
let alt = PBDD.forall_snodes t.tail in
3157
numbits_ge_pos 0 t.bdd.dom_indexes;
3158
mask_nonneg (to_int t.size);
3159
let w = ZbitInt.lsl_int 1 (to_int t.size) in
3160
mask_nonneg w;
3161
let hi = Zbit.lnot (ZbitInt.mask_int w) in
3162
let k0w = cst_value t.size e in
3163
let k1w = cst_value t.size a in
3164
let te = cst_value 0 et in
3165
let ta = cst_value 0 alt in
3166
let k0 = if Zbit.test_bit te 0 then Zbit.lor k0w hi else k0w in
3167
let k1 = if Zbit.test_bit ta 0 then Zbit.lor k1w hi else k1w in
3168
let lemma k0_def (q: int) : unit
3169
requires { 0 <= q }
3170
ensures { bittest k0 q <-> (bittest k0w q \/ (bittest te 0 /\ bittest hi q)) }
3171
= ()
3172
in
3173
let lemma k1_def (q: int) : unit
3174
requires { 0 <= q }
3175
ensures { bittest k1 q <-> (bittest k1w q \/ (bittest ta 0 /\ bittest hi q)) }
3176
= ()
3177
in
3178
let lemma hibit (q: int) : unit
3179
requires { 0 <= q }
3180
ensures { bittest hi q <-> w <= q }
3181
= if q < w then mask_bits w q else mask_bits_high w q
3182
in
3183
(* the window positions and the tail positions *)
3184
let lemma win_pos (q: int) : unit
3185
requires { 0 <= q /\ q < w }
3186
ensures { numbits q <= to_int t.size }
3187
= numbits_lt_lsl q (to_int t.size)
3188
in
3189
let lemma tail_pos (q: int) : unit
3190
requires { 0 <= q /\ w <= q }
3191
ensures { not (numbits q <= to_int t.size) }
3192
= if numbits q <= to_int t.size then lt_lsl_of_numbits q (to_int t.size)
3193
in
3194
let lemma te_s (_: unit) : unit
3195
ensures { bittest te 0 <-> exists sn. t.tail.PBDD.v 0 sn }
3196
=
3197
let lemma pt (sn: snodes) : unit
3198
ensures { bittest te 0 <-> et.PBDD.v 0 sn }
3199
= PBDD2.def_v et 0 (fun _ -> sn) 0
3200
in
3201
pt Set.empty;
3202
assert { et.PBDD.v 0 Set.empty <-> exists sn. t.tail.PBDD.v 0 sn }
3203
in
3204
let lemma ta_s (_: unit) : unit
3205
ensures { bittest ta 0 <-> forall sn. t.tail.PBDD.v 0 sn }
3206
=
3207
let lemma pt (sn: snodes) : unit
3208
ensures { bittest ta 0 <-> alt.PBDD.v 0 sn }
3209
= PBDD2.def_v alt 0 (fun _ -> sn) 0
3210
in
3211
pt Set.empty;
3212
assert { alt.PBDD.v 0 Set.empty <-> forall sn. t.tail.PBDD.v 0 sn }
3213
in
3214
let lemma bits0 (q: int) : unit
3215
requires { 0 <= q }
3216
ensures { bittest k0 q <-> exists sn. bit t q sn }
3217
=
3218
hibit q;
3219
let lemma w1 (sn: snodes) : unit
3220
ensures { bittest k0w q <-> (numbits q <= to_int t.size /\ e.PBDD.v q sn) }
3221
= PBDD2.def_v e (to_int t.size) (fun _ -> sn) q
3222
in
3223
if q < w then begin
3224
win_pos q;
3225
let lemma w3 (sn: snodes) : unit
3226
ensures { bit t q sn <-> t.bdd.PBDD.v q sn }
3227
= ()
3228
in
3229
let lemma w4 (sn: snodes) : unit
3230
ensures { e.PBDD.v q sn <-> (exists sn'. t.bdd.PBDD.v q sn') }
3231
= ()
3232
in
3233
assert { bittest k0w q <-> e.PBDD.v q Set.empty /\ numbits q <= to_int t.size };
3234
assert { bittest k0 q <-> (exists sn'. t.bdd.PBDD.v q sn') };
3235
assert { (exists sn. bit t q sn) <-> (exists sn'. t.bdd.PBDD.v q sn') }
3236
end else tail_pos q;
3237
if q >= w then begin
3238
let lemma w2 (sn: snodes) : unit
3239
ensures { bit t q sn <-> t.tail.PBDD.v 0 sn }
3240
= ()
3241
in ()
3242
end
3243
in
3244
let lemma bits1 (q: int) : unit
3245
requires { 0 <= q }
3246
ensures { bittest k1 q <-> forall sn. bit t q sn }
3247
=
3248
hibit q;
3249
let lemma w1 (sn: snodes) : unit
3250
ensures { bittest k1w q <-> (numbits q <= to_int t.size /\ a.PBDD.v q sn) }
3251
= PBDD2.def_v a (to_int t.size) (fun _ -> sn) q
3252
in
3253
if q < w then begin
3254
win_pos q;
3255
let lemma w3 (sn: snodes) : unit
3256
ensures { bit t q sn <-> t.bdd.PBDD.v q sn }
3257
= ()
3258
in
3259
let lemma w4 (sn: snodes) : unit
3260
ensures { a.PBDD.v q sn <-> (forall sn'. t.bdd.PBDD.v q sn') }
3261
= ()
3262
in
3263
assert { bittest k1w q <-> a.PBDD.v q Set.empty /\ numbits q <= to_int t.size };
3264
assert { bittest k1 q <-> (forall sn'. t.bdd.PBDD.v q sn') };
3265
assert { (forall sn. bit t q sn) <-> (forall sn'. t.bdd.PBDD.v q sn') }
3266
end else tail_pos q;
3267
if q >= w then begin
3268
let lemma w2 (sn: snodes) : unit
3269
ensures { bit t q sn <-> t.tail.PBDD.v 0 sn }
3270
= ()
3271
in ()
3272
end
3273
in
3274
(k0, k1)
3275
3276
(* ---- Substitution of the nodes by terms with a tail ---- *)

The bit q of u (false below 0)

3279
function
ubit
(u: t) (q: int) (env: Node.t -> int) : bool = 0 <= q /\ bit u q (sem env q)
3280
Valid (69ms) (colibri2)
3281
let ghost
ubit_value
(u: t) (env: Node.t -> int) (z q: int) : unit
3282
requires { is_value u env z }
3283
ensures { ubit u q env <-> bittest z q }
3284
= ()

env' gives to the nodes selected by sel the value of their term

3287
predicate
sub_env
(sel: Node.t -> option t) (env env': Node.t -> int) =
3288
(forall m u. sel m = Some u -> is_value u env (env' m)) /\ (forall m. sel m = None -> env' m = env m)

The scalar atom of the node n

3291
function
scal_of
(n: Node.t) : snode = { SNode.n = n; SNode.s = (0:int63); SNode.scal = True }

Each snode of l is replaced by the scalar atom of its node

    Valid (789ms) (colibri2 16) (cvc4) (split_vc) (depth 1)
3294
let rec partial
scal_list
(l: list Key.t) : list (snode, PBDD.t)
3295
requires { Distinct.distinct l }
3296
variant { l }
3297
ensures { PBDD.distinct_keys result }
3298
ensures { forall nd. PBDD.mem_key nd result <-> Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) l }
3299
ensures { forall nd g. Mem.mem (nd, g) result ->
3300
g.PBDD.dom_indexes = 0 /\ forall id sn. g.PBDD.v id sn = sn (scal_of nd.SNode.n) }
3301
= match l with
3302
| Nil -> Nil
3303
| Cons (Key.Var n s a) l' ->
3304
let g = PBDD.bdd_of_snode { SNode.n = n; SNode.s = 0; SNode.scal = True } in
3305
assert { forall id sn. g.PBDD.v id sn = sn (scal_of n) };
3306
let r = scal_list l' in
3307
let res = Cons ({ SNode.n = n; SNode.s = s; SNode.scal = a }, g) r in
3308
let lemma post (nd: snode) (g': PBDD.t) : unit
3309
requires { Mem.mem (nd, g') res }
3310
ensures { g'.PBDD.dom_indexes = 0 /\ forall id sn. g'.PBDD.v id sn = sn (scal_of nd.SNode.n) }
3311
= if pure { nd = { SNode.n = n; SNode.s = s; SNode.scal = a } /\ g' = g } then assert { nd.SNode.n = n }
3312
else assert { Mem.mem (nd, g') r }
3313
in
3314
res
3315
| Cons (Key.Index _) l' -> scal_list l'
3316
end

The sign of a term: its tail where every atom is the scalar of its node (the stream at infinity)

    Valid (3.0s) (colibri2 14) (cvc4 5) (split_vc) (depth 1)
3320
let partial
sign_bdd
(u: t) : PBDD.t
3321
ensures { result.PBDD.dom_indexes = 0 }
3322
ensures { forall id sn. result.PBDD.v id sn <-> u.tail.PBDD.v 0 (fun nd -> sn (scal_of nd.SNode.n)) }
3323
ensures { forall env p. result.PBDD.v p (sem env p) <-> u.tail.PBDD.v 0 (sem_inf env) }
3324
ensures { forall p sn1 sn2. agree p sn1 sn2 -> (result.PBDD.v p sn1 <-> result.PBDD.v p sn2) }
3325
=
3326
let kt = PBDD.vars u.tail in
3327
let l = scal_list kt in
3328
let r = PBDD.compose_snodes 0 l u.tail in
3329
dom_zero r.dom_indexes;
3330
let lemma pv (id: int) (sn: snodes) : unit
3331
ensures { r.PBDD.v id sn <-> u.tail.PBDD.v 0 (fun nd -> sn (scal_of nd.SNode.n)) }
3332
=
3333
tail_v u.tail id (subst_sn l id sn);
3334
let lemma pt (nd: snode) : unit
3335
requires { Set.mem nd (support_snodes u.tail) }
3336
ensures { subst_sn l id sn nd <-> sn (scal_of nd.SNode.n) }
3337
= subst_sn_mem l id sn nd;
3338
assert { Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) kt }
3339
in
3340
PBDD.support_snodes_v u.tail 0 (subst_sn l id sn) pure { fun nd -> sn (scal_of nd.SNode.n) }
3341
in
3342
let lemma ps (env: Node.t -> int) (p: int) : unit
3343
ensures { r.PBDD.v p (sem env p) <-> u.tail.PBDD.v 0 (sem_inf env) }
3344
=
3345
pv p (sem env p);
3346
assert { (fun nd -> sem env p (scal_of nd.SNode.n)) = sem_inf env }
3347
in
3348
let lemma pa (p: int) (sn1 sn2: snodes) : unit
3349
requires { agree p sn1 sn2 }
3350
ensures { r.PBDD.v p sn1 <-> r.PBDD.v p sn2 }
3351
=
3352
pv p sn1; pv p sn2;
3353
assert { forall m. reads_at p (scal_of m) };
3354
assert { (fun nd -> sn1 (scal_of nd.SNode.n)) = (fun nd -> sn2 (scal_of nd.SNode.n)) }
3355
in
3356
r

The substitution of a term u for a snode read at the shift s cannot be represented

3360
predicate
bad_sub
(u: t) (s: int) =
3361
u.size > 60 \/ s > 0x1000_0000_0000_0000 \/ s < - 0x1000_0000_0000_0000 \/
3362
(exists nd. Set.mem nd (all_snodes u) /\ not nd.scal /\ not (in_bounds (to_int nd.s + s)))

The window size needed to substitute the nodes of l: the size of the shift by -s of their term

    Valid (685ms) (colibri2 35) (cvc4 2) (cvc5 6) (split_vc 4) (depth 3)
3366
let rec
size_needed
(sel: Node.t -> option t) (l: list Key.t) (acc: int63) : int63
3367
requires { 0 <= acc <= 61 }
3368
variant { l }
3369
ensures { acc <= result <= 61 }
3370
ensures { forall n s a u. Mem.mem (Key.Var n s a) l -> sel n = Some u -> not a ->
3371
u.size <= 60 /\ - 0x1000_0000_0000_0000 <= s <= 0x1000_0000_0000_0000 /\
3372
numbits (lsl 1 u.size + max 0 (- to_int s) - 1) <= result }
3373
raises { Overflow -> exists n s a u. Mem.mem (Key.Var n s a) l /\ sel n = Some u /\ not a /\
3374
(u.size > 60 \/ s > 0x1000_0000_0000_0000 \/ s < - 0x1000_0000_0000_0000) }
3375
= match l with
3376
| Nil -> acc
3377
| Cons (Key.Var n s a) l' ->
3378
let acc' =
3379
if a then acc else
3380
match sel n with
3381
| None -> acc
3382
| Some u ->
3383
if u.size > 60 || s > 0x1000_0000_0000_0000 || s < - 0x1000_0000_0000_0000 then begin
3384
assert { Mem.mem (Key.Var n s a) l /\ sel n = Some u };
3385
raise Overflow
3386
end;
3387
lsl_le_2_60 (to_int u.size);
3388
let m0 = if s <= 0 then Int63.lsl 1 u.size - s - 1 else Int63.lsl 1 u.size - 1 in
3389
numbits_ge_pos 0 (to_int m0);
3390
assert { m0 < lsl 1 61 };
3391
let r = Int63.of_int (Zbit.numbits (to_int m0)) in
3392
numbits_lt_lsl (to_int m0) 61;
3393
if r > acc then r else acc
3394
end in
3395
size_needed sel l' acc'
3396
| Cons (Key.Index _) l' -> size_needed sel l' acc
3397
end

The shifted term u >> s for the substitution of the snode {n; s}

    Valid (949ms) (colibri2 6) (split_vc) (depth 1)
3400
let partial
subst_term
(u: t) (s: int63) (sz: int63) : t
3401
requires { u.size <= 60 /\ 0 <= sz <= 61 }
3402
requires { - 0x1000_0000_0000_0000 <= s <= 0x1000_0000_0000_0000 }
3403
requires { numbits (lsl 1 u.size + max 0 (- to_int s) - 1) <= sz }
3404
ensures { result.size <= sz }
3405
ensures { forall env p. 0 <= p -> (bit result p (sem env p) <-> ubit u (p + to_int s) env) }
3406
raises { Overflow -> exists nd. Set.mem nd (all_snodes u) /\ not nd.scal /\ not (in_bounds (to_int nd.s + to_int s)) }
3407
=
3408
let v = shift_i (- s) u in
3409
v

The windows of size sz substituted for the snodes of l

    Valid (968ms) (colibri2 24) (cvc4 16) (cvc5 2) (split_vc 5) (depth 3)
3412
let rec partial
build_w
(sel: Node.t -> option t) (l: list Key.t) (sz: int63) : list (snode, PBDD.t)
3413
requires { 0 <= sz <= 61 }
3414
requires { Distinct.distinct l }
3415
requires { forall n s a u. Mem.mem (Key.Var n s a) l -> sel n = Some u -> not a ->
3416
u.size <= 60 /\ - 0x1000_0000_0000_0000 <= s <= 0x1000_0000_0000_0000 /\
3417
numbits (lsl 1 u.size + max 0 (- to_int s) - 1) <= sz }
3418
variant { l }
3419
ensures { PBDD.distinct_keys result }
3420
ensures { forall nd. PBDD.mem_key nd result <->
3421
(Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) l /\ sel nd.SNode.n <> None) }
3422
ensures { forall nd g. Mem.mem (nd, g) result -> numbits g.PBDD.dom_indexes <= sz /\ no_neg g sz /\
3423
exists u. sel nd.SNode.n = Some u /\
3424
if nd.SNode.scal then forall env p. g.PBDD.v p (sem env p) <-> u.tail.PBDD.v 0 (sem_inf env)
3425
else forall env p. 0 <= p -> numbits p <= sz ->
3426
(g.PBDD.v p (sem env p) <-> ubit u (p + to_int nd.SNode.s) env) }
3427
raises { Overflow -> exists n s a u. Mem.mem (Key.Var n s a) l /\ sel n = Some u /\ not a /\ bad_sub u (to_int s) }
3428
= match l with
3429
| Nil -> Nil
3430
| Cons (Key.Var n s a) l' ->
3431
let r = build_w sel l' sz in
3432
match sel n with
3433
| None -> r
3434
| Some u ->
3435
let g = if a then sign_bdd u else get_t (subst_term u s sz) sz in
3436
if a then dom_zero g.PBDD.dom_indexes;
3437
let nd = { SNode.n = n; SNode.s = s; SNode.scal = a } in
3438
let res = Cons (nd, g) r in
3439
let lemma post (nd': snode) (g': PBDD.t) : unit
3440
requires { Mem.mem (nd', g') res }
3441
ensures { numbits g'.PBDD.dom_indexes <= sz /\ no_neg g' sz /\
3442
exists u. sel nd'.SNode.n = Some u /\
3443
if nd'.SNode.scal then forall env p. g'.PBDD.v p (sem env p) <-> u.tail.PBDD.v 0 (sem_inf env)
3444
else forall env p. 0 <= p -> numbits p <= sz ->
3445
(g'.PBDD.v p (sem env p) <-> ubit u (p + to_int nd'.SNode.s) env) }
3446
= if pure { nd' = nd /\ g' = g } then assert { nd'.SNode.n = n /\ nd'.SNode.s = s /\ nd'.SNode.scal = a }
3447
in
3448
res
3449
end
3450
| Cons (Key.Index _) l' -> build_w sel l' sz
3451
end

The tails substituted for the snodes of l, valid from the position 2^sz

    Valid (832ms) (colibri2 30) (cvc4 17) (cvc5 3) (split_vc 3) (depth 3)
3454
let rec partial
build_t
(sel: Node.t -> option t) (l: list Key.t) (sz: int63) : list (snode, PBDD.t)
3455
requires { 0 <= sz <= 61 }
3456
requires { Distinct.distinct l }
3457
requires { forall n s a u. Mem.mem (Key.Var n s a) l -> sel n = Some u -> not a ->
3458
u.size <= 60 /\ - 0x1000_0000_0000_0000 <= s <= 0x1000_0000_0000_0000 /\
3459
numbits (lsl 1 u.size + max 0 (- to_int s) - 1) <= sz }
3460
variant { l }
3461
ensures { PBDD.distinct_keys result }
3462
ensures { forall nd. PBDD.mem_key nd result <->
3463
(Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) l /\ sel nd.SNode.n <> None) }
3464
ensures { forall nd g. Mem.mem (nd, g) result -> g.PBDD.dom_indexes = 0 /\ no_neg_tail g sz /\
3465
exists u. sel nd.SNode.n = Some u /\
3466
if nd.SNode.scal then forall env p. g.PBDD.v 0 (sem env p) <-> u.tail.PBDD.v 0 (sem_inf env)
3467
else forall env p. 0 <= p -> lsl 1 sz <= p ->
3468
(g.PBDD.v 0 (sem env p) <-> ubit u (p + to_int nd.SNode.s) env) }
3469
raises { Overflow -> exists n s a u. Mem.mem (Key.Var n s a) l /\ sel n = Some u /\ not a /\ bad_sub u (to_int s) }
3470
= match l with
3471
| Nil -> Nil
3472
| Cons (Key.Var n s a) l' ->
3473
let r = build_t sel l' sz in
3474
match sel n with
3475
| None -> r
3476
| Some u ->
3477
let g =
3478
if a then begin
3479
let g = sign_bdd u in
3480
let lemma nt (sn1 sn2: snodes) : unit
3481
requires { agree (lsl 1 sz) sn1 sn2 }
3482
ensures { g.PBDD.v 0 sn1 <-> g.PBDD.v 0 sn2 }
3483
= tail_v g pure { lsl 1 sz } sn1; tail_v g pure { lsl 1 sz } sn2
3484
in
3485
let lemma pt (env: Node.t -> int) (p: int) : unit
3486
ensures { g.PBDD.v 0 (sem env p) <-> u.tail.PBDD.v 0 (sem_inf env) }
3487
= tail_v g p (sem env p)
3488
in
3489
g
3490
end else begin
3491
let v = subst_term u s sz in
3492
numbits_ge_pos 0 v.bdd.dom_indexes;
3493
no_neg_tail_mono v.tail (to_int v.size) (to_int sz);
3494
let g = v.tail in
3495
let lemma pt (env: Node.t -> int) (p: int) : unit
3496
requires { 0 <= p /\ lsl 1 sz <= p }
3497
ensures { g.PBDD.v 0 (sem env p) <-> ubit u (p + to_int s) env }
3498
=
3499
if numbits p <= to_int sz then numbits_lt_lsl p (to_int sz)
3500
in
3501
g
3502
end in
3503
let nd = { SNode.n = n; SNode.s = s; SNode.scal = a } in
3504
let res = Cons (nd, g) r in
3505
let lemma post (nd': snode) (g': PBDD.t) : unit
3506
requires { Mem.mem (nd', g') res }
3507
ensures { g'.PBDD.dom_indexes = 0 /\ no_neg_tail g' sz /\
3508
exists u. sel nd'.SNode.n = Some u /\
3509
if nd'.SNode.scal then forall env p. g'.PBDD.v 0 (sem env p) <-> u.tail.PBDD.v 0 (sem_inf env)
3510
else forall env p. 0 <= p -> lsl 1 sz <= p ->
3511
(g'.PBDD.v 0 (sem env p) <-> ubit u (p + to_int nd'.SNode.s) env) }
3512
= if pure { nd' = nd /\ g' = g } then assert { nd'.SNode.n = n /\ nd'.SNode.s = s /\ nd'.SNode.scal = a }
3513
in
3514
res
3515
end
3516
| Cons (Key.Index _) l' -> build_t sel l' sz
3517
end

The substitution in a BDD x without negative reads

    Valid (83ms) (colibri2 6) (split_vc) (depth 1)
3520
let ghost
no_neg_compose_raw
(x c: PBDD.t) (sz: int) (l: list (snode, PBDD.t)) : unit
3521
requires { 0 <= sz /\ no_neg x sz }
3522
requires { forall nd g. Mem.mem (nd, g) l -> no_neg g sz }
3523
requires { forall id sn. c.PBDD.v id sn = x.PBDD.v id (subst_sn l id sn) }
3524
ensures { no_neg c sz }
3525
=
3526
let lemma pt (p: int) (sn1 sn2: snodes) : unit
3527
requires { 0 <= p /\ numbits p <= sz /\ agree p sn1 sn2 }
3528
ensures { c.PBDD.v p sn1 <-> c.PBDD.v p sn2 }
3529
=
3530
let lemma ag (nd: snode) : unit
3531
requires { reads_at (p) nd }
3532
ensures { Set.mem nd (subst_sn l p sn1) <-> Set.mem nd (subst_sn l p sn2) }
3533
= subst_sn_eq l p sn1 sn2 nd
3534
in
3535
assert { agree p (subst_sn l p sn1) (subst_sn l p sn2) }
3536
in ()

The substitution in the tail x

    Valid (95ms) (colibri2 9) (split_vc) (depth 1)
3539
let ghost
no_neg_tail_compose
(x c: PBDD.t) (sx sz: int) (l: list (snode, PBDD.t)) : unit
3540
requires { 0 <= sx <= sz /\ no_neg_tail x sx }
3541
requires { forall nd g. Mem.mem (nd, g) l -> no_neg_tail g sz }
3542
requires { forall sn. c.PBDD.v 0 sn = x.PBDD.v 0 (subst_sn l 0 sn) }
3543
ensures { no_neg_tail c sz }
3544
=
3545
lsl_power sx; lsl_power sz;
3546
Power_monotonic 2 sx sz;
3547
let lemma pt (sn1 sn2: snodes) : unit
3548
requires { agree (lsl 1 sz) sn1 sn2 }
3549
ensures { c.PBDD.v 0 sn1 <-> c.PBDD.v 0 sn2 }
3550
=
3551
let lemma ag (nd: snode) : unit
3552
requires { reads_at (lsl 1 sx) nd }
3553
ensures { Set.mem nd (subst_sn l 0 sn1) <-> Set.mem nd (subst_sn l 0 sn2) }
3554
= subst_sn_eq l 0 sn1 sn2 nd
3555
in
3556
assert { agree (lsl 1 sx) (subst_sn l 0 sn1) (subst_sn l 0 sn2) }
3557
in ()

The nodes selected by sel are replaced by their terms: the snode {n; s} by the term shifted by s positions to the right (normalize and subst of bddbitv.ml for terms with a tail). Overflow when a window or a shift is too big.

    Valid (1.1s) (colibri2 65) (cvc4 20) (cvc5 3) (split_vc 14) (depth 4)
3563
let partial
compose_i
(t: t) (sel: Node.t -> option t) : t
3564
ensures { forall env env'. sub_env sel env env' ->
3565
forall p. 0 <= p -> (bit result p (sem env p) <-> bit t p (sem env' p)) }
3566
raises { Overflow -> t.size > 60 \/ exists nd u. in_supports t nd /\ sel nd.SNode.n = Some u /\
3567
not nd.SNode.scal /\ bad_sub u (to_int nd.SNode.s) }
3568
=
3569
if t.size > 60 then raise Overflow;
3570
let kb = PBDD.vars t.bdd in
3571
let kt = PBDD.vars t.tail in
3572
let lemma kb_sup (n: Node.t) (s: int63) (a: bool) : unit
3573
ensures { Mem.mem (Key.Var n s a) kb \/ Mem.mem (Key.Var n s a) kt -> in_supports t { SNode.n = n; SNode.s = s; SNode.scal = a } }
3574
= () in
3575
let lemma wit (n: Node.t) (s: int63) (a: bool) (u: t) : unit
3576
ensures { (Mem.mem (Key.Var n s a) kb \/ Mem.mem (Key.Var n s a) kt) -> sel n = Some u ->
3577
not a -> (u.size > 60 \/ s > 0x1000_0000_0000_0000 \/ s < - 0x1000_0000_0000_0000 \/ bad_sub u (to_int s)) ->
3578
exists nd u'. in_supports t nd /\ sel nd.SNode.n = Some u' /\ not nd.SNode.scal /\ bad_sub u' (to_int nd.SNode.s) }
3579
= if pure { (Mem.mem (Key.Var n s a) kb \/ Mem.mem (Key.Var n s a) kt) /\ sel n = Some u } then begin
3580
let nd = pure { { SNode.n = n; SNode.s = s; SNode.scal = a } } in
3581
assert { in_supports t nd /\ sel nd.SNode.n = Some u }
3582
end in
3583
let sz0 = size_needed sel kb t.size in
3584
let sz = size_needed sel kt sz0 in
3585
let x = get_t t sz in
3586
(* the snodes of [x] are the ones of [t] *)
3587
let lemma supp_x (nd: snode) : unit
3588
requires { Set.mem nd (support_snodes x) }
3589
ensures { Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail) }
3590
=
3591
let ghost (id, sn) = PBDD.support_snodes_dep x nd in
3592
if pure { not (Set.mem nd (support_snodes t.bdd) \/ Set.mem nd (support_snodes t.tail)) } then begin
3593
let ghost p = pure { land (mask sz) id } in
3594
mask_nonneg (to_int sz);
3595
land_nonneg_l pure { mask sz } id;
3596
numbits_subset p pure { mask sz };
3597
mask_numbits (to_int sz);
3598
PBDD.support_v x id p (Set.add nd sn);
3599
PBDD.support_v x id p (Set.remove nd sn);
3600
tail_v t.tail p (Set.add nd sn); tail_v t.tail p (Set.remove nd sn);
3601
PBDD.support_snodes_v t.bdd p (Set.add nd sn) (Set.remove nd sn);
3602
PBDD.support_snodes_v t.tail 0 (Set.add nd sn) (Set.remove nd sn)
3603
end
3604
in
3605
let kx = PBDD.vars x in
3606
let lemma kx_sup (n: Node.t) (s: int63) (a: bool) : unit
3607
ensures { Mem.mem (Key.Var n s a) kx -> in_supports t { SNode.n = n; SNode.s = s; SNode.scal = a } }
3608
= () in
3609
let lw = build_w sel kx sz in
3610
let lt = build_t sel kt sz in
3611
let win = PBDD.compose_snodes (to_int sz) lw x in
3612
let tl = PBDD.compose_snodes 0 lt t.tail in
3613
dom_zero tl.dom_indexes;
3614
no_neg_compose_raw x win (to_int sz) lw;
3615
no_neg_tail_compose t.tail tl (to_int t.size) (to_int sz) lt;
3616
let r = mk_t win tl sz in
3617
(* the bits of the result *)
3618
let lemma bitr (env env': Node.t -> int) (p: int) : unit
3619
requires { 0 <= p /\ sub_env sel env env' }
3620
ensures { bit r p (sem env p) <-> bit t p (sem env' p) }
3621
=
3622
let sn = sem env p in
3623
let sn' = sem env' p in
3624
if numbits p <= to_int sz then begin
3625
let lemma agw (nd: snode) : unit
3626
requires { Set.mem nd (support_snodes x) }
3627
ensures { subst_sn lw p sn nd <-> sn' nd }
3628
=
3629
subst_sn_mem lw p sn nd;
3630
sem_def env' p nd; sem_def env p nd;
3631
if pure { sel nd.SNode.n <> None } then begin
3632
assert { Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) kx };
3633
assert { PBDD.mem_key nd lw };
3634
let ghost _ = any PBDD.t ensures { Mem.mem (nd, result) lw /\ subst_sn lw p sn nd = result.PBDD.v p sn } in
3635
let ghost u = any t ensures { sel nd.SNode.n = Some result } in
3636
if nd.SNode.scal then value_sign u env (env' nd.SNode.n)
3637
else ubit_value u env (env' nd.SNode.n) (p + to_int nd.SNode.s)
3638
end
3639
in
3640
PBDD.support_snodes_v x p (subst_sn lw p sn) sn'
3641
end else begin
3642
tail_v tl p sn; tail_v t.tail p sn'; tail_v t.tail p (subst_sn lt 0 sn);
3643
mask_nonneg (to_int sz);
3644
if p < pure { lsl 1 sz } then numbits_lt_lsl p (to_int sz);
3645
if numbits p <= to_int t.size then lt_lsl_of_numbits p (to_int t.size);
3646
let lemma agt (nd: snode) : unit
3647
requires { Set.mem nd (support_snodes t.tail) }
3648
ensures { subst_sn lt 0 sn nd <-> sn' nd }
3649
=
3650
subst_sn_mem lt 0 sn nd;
3651
sem_def env' p nd; sem_def env p nd;
3652
if pure { sel nd.SNode.n <> None } then begin
3653
assert { Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) kt };
3654
assert { PBDD.mem_key nd lt };
3655
let ghost _ = any PBDD.t ensures { Mem.mem (nd, result) lt /\ subst_sn lt 0 sn nd = result.PBDD.v 0 sn } in
3656
let ghost u = any t ensures { sel nd.SNode.n = Some result } in
3657
if nd.SNode.scal then value_sign u env (env' nd.SNode.n)
3658
else ubit_value u env (env' nd.SNode.n) (p + to_int nd.SNode.s)
3659
end
3660
in
3661
PBDD.support_snodes_v t.tail 0 (subst_sn lt 0 sn) sn'
3662
end
3663
in
3664
r
3665
Valid (72ms) (colibri2 9) (split_vc 2) (depth 2)
3666
let
get_var_less_shift
(vars: list Key.t) : option (Node.t, int, list snode)
3667
ensures { match result with
3668
| None -> forall n s a. not (Mem.mem (Key.Var n s a) vars)
3669
| Some (n, _, l) -> l <> Nil /\
3670
forall nd. Mem.mem nd l <-> (Mem.mem (Key.Var nd.n nd.s nd.scal) vars /\ nd.n = n)
3671
end }
3672
=
3673
let h = NodeH.create 10 in
3674
let rec add_all (l: list Key.t) : unit
3675
variant { l }
3676
writes { h }
3677
ensures { forall k nd. Mem.mem nd (h.NodeH.contents k) <->
3678
(Mem.mem nd ((old h.NodeH.contents) k) \/ (Mem.mem (Key.Var nd.n nd.s nd.scal) l /\ nd.n = k)) }
3679
= match l with
3680
| Nil -> ()
3681
| Cons (Key.Index _) l' -> add_all l'
3682
| Cons (Key.Var n s a) l' -> NodeH.add_cons h n { SNode.n = n; SNode.s = s; SNode.scal = a }; add_all l'
3683
end
3684
in
3685
add_all vars;
3686
let res = NodeH.fold_min h in
3687
match res with
3688
| None ->
3689
let lemma none (n: Node.t) (s: int63) (a: bool) : unit
3690
ensures { not (Mem.mem (Key.Var n s a) vars) }
3691
= let nd = { SNode.n = n; SNode.s = s; SNode.scal = a } in
3692
assert { not (Mem.mem nd (h.NodeH.contents n)) }
3693
in ()
3694
| Some (n, _, l) -> assert { forall nd. Mem.mem nd l -> nd.n = n }
3695
end;
3696
res
3697
3698
type
solve
=
Zero
|
Unsat
|
Subst
Node.t t t |
TryLater
3699
Valid (117ms) (cvc4)
3700
let lemma
no_snode_value
(t: t) (sn1 sn2: PBDD2.env) : unit
3701
requires { Set.is_empty (support_snodes t.bdd) }
3702
ensures { v t sn1 = v t sn2 }
3703
=
3704
let lemma bit (p: int) : unit
3705
ensures { bittest (v t sn1) p <-> bittest (v t sn2) p }
3706
= PBDD.support_snodes_v t.bdd p (sn1 p) (sn2 p)
3707
in
3708
ext_bittest (v t sn1) (v t sn2)

The valuation of the absolute snodes: {n; k} is the bit k of n

3711
function
abs
(env: Node.t -> int) : snodes = fun nd -> if nd.SNode.scal then env nd.SNode.n < 0 else bittest (env nd.SNode.n) nd.SNode.s

b only reads the absolute snodes with a non–negative shift

3714
predicate
nn_dep
(b: PBDD.t) =
3715
forall id sn1 sn2. agree 0 sn1 sn2 -> (b.PBDD.v id sn1 <-> b.PBDD.v id sn2)

The snodes of the support of a nn_dep BDD have a non–negative shift

    Valid (124ms) (colibri2 2) (cvc4) (split_vc) (depth 1)
3718
let ghost
nn_dep_supp
(b: PBDD.t) (nd: snode) : unit
3719
requires { nn_dep b /\ Set.mem nd (support_snodes b) }
3720
ensures { nd.SNode.scal \/ 0 <= nd.SNode.s }
3721
=
3722
if pure { not nd.SNode.scal /\ nd.SNode.s < 0 } then begin
3723
let ghost (_, sn) = PBDD.support_snodes_dep b nd in
3724
assert { agree 0 (Set.add nd sn) (Set.remove nd sn) }
3725
end
3726
Valid (76ms) (colibri2 6) (split_vc) (depth 1)
3727
let ghost
nn_dep_compose
(x c: PBDD.t) (l: list (snode, PBDD.t)) : unit
3728
requires { nn_dep x }
3729
requires { forall nd g. Mem.mem (nd, g) l -> nn_dep g }
3730
requires { forall id sn. c.PBDD.v id sn = x.PBDD.v id (subst_sn l id sn) }
3731
ensures { nn_dep c }
3732
=
3733
let lemma pt (id: int) (sn1 sn2: snodes) : unit
3734
requires { agree 0 sn1 sn2 }
3735
ensures { c.PBDD.v id sn1 <-> c.PBDD.v id sn2 }
3736
=
3737
let lemma ag (nd: snode) : unit
3738
requires { reads_at (0) nd }
3739
ensures { Set.mem nd (subst_sn l id sn1) <-> Set.mem nd (subst_sn l id sn2) }
3740
= subst_sn_eq l id sn1 sn2 nd
3741
in
3742
assert { agree 0 (subst_sn l id sn1) (subst_sn l id sn2) }
3743
in ()

Lists of absolute snodes sorted by decreasing shift

3746
predicate
sorted_desc
(l: list snode) =
3747
match l with
3748
| Nil -> true
3749
| Cons x l' -> (forall y. Mem.mem y l' -> to_int y.SNode.s <= to_int x.SNode.s) /\ sorted_desc l'
3750
end

Insertion in a list sorted by decreasing shift, without duplicate

    Valid (1.5s) (colibri2 5) (cvc5) (split_vc 2) (depth 2)
3753
let rec
insert_bit
(nd: snode) (l: list snode) : list snode
3754
requires { Distinct.distinct l /\ sorted_desc l }
3755
variant { l }
3756
ensures { Distinct.distinct result /\ sorted_desc result }
3757
ensures { forall x. Mem.mem x result <-> (x = nd \/ Mem.mem x l) }
3758
= match l with
3759
| Nil -> Cons nd Nil
3760
| Cons x l' ->
3761
if Node.equal x.SNode.n nd.SNode.n && x.SNode.s = nd.SNode.s && (if x.SNode.scal then nd.SNode.scal else not nd.SNode.scal) then begin
3762
assert { x = nd };
3763
l
3764
end else if x.SNode.s >= nd.SNode.s then Cons x (insert_bit nd l')
3765
else Cons nd l
3766
end
3767
Valid (82ms) (colibri2)
3768
let rec
sort_bits
(l: list snode) : list snode
3769
variant { l }
3770
ensures { Distinct.distinct result /\ sorted_desc result }
3771
ensures { forall x. Mem.mem x result <-> Mem.mem x l }
3772
= match l with
3773
| Nil -> Nil
3774
| Cons x l' -> insert_bit x (sort_bits l')
3775
end

The (simultaneous) substitution l is the identity when its BDDs give the values of their snodes

    Valid (118ms) (cvc4)
3779
let rec lemma
subst_sn_id
(l: list (snode, PBDD.t)) (id: int) (sn: snodes) (nd: snode) : unit
3780
requires { forall nd f. Mem.mem (nd, f) l -> (f.PBDD.v id sn <-> sn nd) }
3781
variant { l }
3782
ensures { subst_sn l id sn nd = sn nd }
3783
= match l with
3784
| Nil -> ()
3785
| Cons (nd', f) l' ->
3786
subst_sn_id l' id sn nd;
3787
assert { subst_sn l id sn nd = if nd = nd' then f.PBDD.v id sn else subst_sn l' id sn nd }
3788
end

The BDD f on the absolute snodes, read at the position 0, seen from the position kk

    Valid (1.8s) (colibri2 20) (cvc4 9) (split_vc 3) (depth 2)
3792
let partial
relativize1
(empty: IArray63.t PBDD.t) (kk: int63) (f: PBDD.t) : PBDD.t
3793
requires { empty.IArray63.length = 0 }
3794
requires { numbits f.dom_indexes <= 0 /\ nn_dep f }
3795
requires { 0 <= kk < 0x2000_0000_0000_0000 }
3796
ensures { numbits result.dom_indexes <= 0 }
3797
ensures { forall sn1 sn2. agree kk sn1 sn2 -> (result.PBDD.v kk sn1 <-> result.PBDD.v kk sn2) }
3798
ensures { forall env. result.PBDD.v kk (sem env kk) <-> f.PBDD.v 0 (abs env) }
3799
=
3801
(* the shifts of [f] are non-negative and the one of [nd] is below 2^61: their difference fits in an int63 *)
3802
let g =
3803
try PBDD.compose_shift empty kk f
3804
with Overflow ->
3805
let lemma nn (nd': snode) : unit
3806
requires { Set.mem nd' (support_snodes f) }
3807
ensures { nd'.SNode.scal \/ 0 <= nd'.SNode.s }
3808
= nn_dep_supp f nd' in
3809
absurd
3810
end in
3811
let k = to_int kk in
3812
let lemma value (env: Node.t -> int) : unit
3813
ensures { g.PBDD.v k (sem env k) <-> f.PBDD.v 0 (abs env) }
3814
=
3815
ext_bittest pure { of_bits (fun i -> (empty i).PBDD.v k (sem env k)) 0 } 0;
3816
let lemma pt (nd': snode) : unit
3817
requires { Set.mem nd' (support_snodes f) }
3818
ensures { sem env k (shift_snode nd' k) <-> abs env nd' }
3819
= nn_dep_supp f nd';
3820
sem_shift env k k nd';
3821
assert { sem env 0 nd' <-> abs env nd' }
3822
in
3823
PBDD.support_snodes_v f 0 pure { fun nd' -> sem env k (shift_snode nd' k) } pure { abs env }
3824
in
3825
(* [g] reads at [k] the snodes of [f] shifted by [k] *)
3826
let lemma tr (x y: snodes) : unit
3827
requires { forall nd'. Set.mem nd' (support_snodes f) -> (Set.mem nd' x <-> Set.mem nd' y) }
3828
ensures { f.PBDD.v 0 x <-> f.PBDD.v 0 y }
3829
= PBDD.support_snodes_v f 0 x y
3830
in
3831
let lemma gy (sn: snodes) : unit
3832
ensures { g.PBDD.v k sn <->
3833
f.PBDD.v 0 (fun nd' -> Set.mem nd' (support_snodes f) /\ sn (shift_snode nd' k)) }
3834
=
3835
ext_bittest pure { of_bits (fun i -> (empty i).PBDD.v k sn) 0 } 0;
3836
tr pure { fun nd -> sn (shift_snode nd k) }
3837
pure { fun nd' -> Set.mem nd' (support_snodes f) /\ sn (shift_snode nd' k) }
3838
in
3839
let lemma nng (sn1 sn2: snodes) : unit
3840
requires { agree k sn1 sn2 }
3841
ensures { g.PBDD.v k sn1 <-> g.PBDD.v k sn2 }
3842
=
3843
let ghost y1 = pure { fun nd' -> Set.mem nd' (support_snodes f) /\ sn1 (shift_snode nd' k) } in
3844
let ghost y2 = pure { fun nd' -> Set.mem nd' (support_snodes f) /\ sn2 (shift_snode nd' k) } in
3845
gy sn1; gy sn2;
3846
assert { g.PBDD.v k sn1 <-> f.PBDD.v 0 y1 };
3847
assert { g.PBDD.v k sn2 <-> f.PBDD.v 0 y2 };
3848
let lemma ag (nd': snode) : unit
3849
requires { reads_at (0) nd' }
3850
ensures { Set.mem nd' y1 <-> Set.mem nd' y2 }
3851
= if pure { Set.mem nd' (support_snodes f) } then begin
3852
nn_dep_supp f nd';
3853
sem_shift (fun _ -> 0) k k nd'
3854
end
3855
in
3856
assert { agree 0 y1 y2 };
3857
assert { f.PBDD.v 0 y1 <-> f.PBDD.v 0 y2 }
3858
in
3859
g

The relativized solutions: at the position k, the absolute snodes {m; j} of the solution of {n; k} read the bit j of m (the Var.map ~f:(relativize_var shift) of bddbitv.ml)

    Valid (968ms) (colibri2 9) (cvc4 8) (cvc5 2) (split_vc 2) (depth 2)
3864
let rec partial
relativize
(empty: IArray63.t PBDD.t) (sols: list (snode, PBDD.t)) : list (snode, PBDD.t)
3865
requires { empty.IArray63.length = 0 }
3866
requires { forall nd f. Mem.mem (nd, f) sols -> numbits f.dom_indexes <= 0 /\ 0 <= nd.SNode.s }
3867
requires { forall nd f. Mem.mem (nd, f) sols -> nn_dep f }
3868
requires { forall nd f. Mem.mem (nd, f) sols -> nd.SNode.s < 0x2000_0000_0000_0000 }
3869
variant { sols }
3870
ensures { forall nd. PBDD.mem_key nd result <-> PBDD.mem_key nd sols }
3871
ensures { forall nd g sn1 sn2. Mem.mem (nd, g) result -> agree nd.SNode.s sn1 sn2 ->
3872
(g.PBDD.v nd.SNode.s sn1 <-> g.PBDD.v nd.SNode.s sn2) }
3873
ensures { forall nd g. Mem.mem (nd, g) result -> numbits g.dom_indexes <= 0 /\
3874
exists f. Mem.mem (nd, f) sols /\
3875
forall env. g.PBDD.v nd.SNode.s (sem env nd.SNode.s) <-> f.PBDD.v 0 (abs env) }
3876
= match sols with
3877
| Nil -> Nil
3878
| Cons (nd, f) l ->
3879
assert { Mem.mem (nd, f) sols };
3880
let r = relativize empty l in
3881
let g = relativize1 empty nd.SNode.s f in
3882
let res = Cons (nd, g) r in
3883
let lemma post2 (nd': snode) (g': PBDD.t) (sn1 sn2: snodes) : unit
3884
requires { Mem.mem (nd', g') res /\ agree nd'.SNode.s sn1 sn2 }
3885
ensures { g'.PBDD.v nd'.SNode.s sn1 <-> g'.PBDD.v nd'.SNode.s sn2 }
3886
= ()
3887
in
3888
let lemma post (nd': snode) (g': PBDD.t) : unit
3889
requires { Mem.mem (nd', g') res }
3890
ensures { numbits g'.PBDD.dom_indexes <= 0 /\
3891
exists f'. Mem.mem (nd', f') sols /\
3892
forall env. g'.PBDD.v nd'.SNode.s (sem env nd'.SNode.s) <-> f'.PBDD.v 0 (abs env) }
3893
= if pure { nd' = nd /\ g' = g } then assert { Mem.mem (nd, f) sols }
3894
in
3895
res
3896
end
3897
3898
use colibrilib.tagtbl.Pos as PosT
3899
use colibrilib.tagtbl.Interval

The BDD of the position k in rels

3902
function
find_rel
(k: int) (l: list (snode, PBDD.t)) : option PBDD.t =
3903
match l with
3904
| Nil -> None
3905
| Cons (nd, g) l' -> if to_int nd.SNode.s = k then Some g else find_rel k l'
3906
end

The table of l by position, the first BDD of a position on top

    Valid (748ms) (colibri2 5) (cvc4) (cvc5) (split_vc) (depth 1)
3909
let rec
add_rels
(h: PosT.t (option PBDD.t)) (l: list (snode, PBDD.t)) : unit
3910
requires { forall nd g. Mem.mem (nd, g) l -> PosT.mem nd.SNode.s h }
3911
variant { l }
3912
ensures { forall k: int63. PosT.([]) (old h) k = None -> PosT.([]) h k = find_rel (to_int k) l }
3913
ensures { forall k: int63. PosT.([]) (old h) k <> None -> PosT.([]) h k <> None }
3914
= match l with
3915
| Nil -> ()
3916
| Cons (nd, g) l' -> add_rels h l'; PosT.set h nd.SNode.s (Some g)
3917
end

The table of l, for the positions below s

    Valid (58ms) (colibri2 7) (split_vc) (depth 1)
3920
let
table_rels
(s: int63) (l: list (snode, PBDD.t)) : PosT.t (option PBDD.t)
3921
requires { 0 <= s }
3922
requires { forall nd g. Mem.mem (nd, g) l -> 0 <= nd.SNode.s < s }
3923
ensures { forall k: int63. PosT.([]) result k = find_rel (to_int k) l }
3924
ensures { result.PosT.defined = Interval.interval 0 s }
3925
ensures { PosT.max_tags result = s - 1 }
3926
=
3927
let h = PosT.create (s - 1) None (pure { Interval.interval 0 s }) in
3928
add_rels h l;
3929
h
3930
Valid (117ms) (colibri2)
3931
let rec lemma
find_rel_mem
(k: int) (l: list (snode, PBDD.t)) : unit
3932
variant { l }
3933
ensures { match find_rel k l with
3934
| Some g -> exists nd. Mem.mem (nd, g) l /\ to_int nd.SNode.s = k
3935
| None -> forall nd g. Mem.mem (nd, g) l -> to_int nd.SNode.s <> k
3936
end }
3937
= match l with Nil -> () | Cons _ l' -> find_rel_mem k l' end

The value of the solved node n: at the positions of rels their BDD, else the bit of n itself (switch_pos in the Gauss–Jordan case of solve)

    Valid (1.9s) (colibri2 46) (cvc4 4) (split_vc 5) (depth 3)
3942
let rec partial
qfill
(n: Node.t) (h: PosT.t (option PBDD.t)) (ghost rels: list (snode, PBDD.t)) (level pos: int63) : PBDD.t
3943
requires { forall k: int63. PosT.([]) h k = find_rel (to_int k) rels }
3944
requires { forall nd g. Mem.mem (nd, g) rels -> nd.SNode.s <= PosT.max_tags h }
3945
requires { h.PosT.defined = Interval.interval 0 (PosT.max_tags h + 1) }
3946
requires { -1 <= level /\ lsl 1 (level + 1) <= Int63.max_int }
3947
requires { 0 <= pos }
3948
requires { forall j. 0 <= j <= level -> not (bittest pos j) }
3949
requires { forall nd g. Mem.mem (nd, g) rels -> numbits g.dom_indexes <= 0 }
3950
variant { level + 1 }
3951
ensures { numbits result.dom_indexes <= level + 1 }
3952
ensures { forall id sn. 0 <= id -> covers id pos level ->
3953
(result.PBDD.v id sn <->
3954
match find_rel id rels with
3955
| Some g -> g.PBDD.v id sn
3956
| None -> sn { SNode.n = n; SNode.s = (0:int63); SNode.scal = False }
3957
end) }
3958
=
3959
if level < 0 then begin
3960
let lemma base (q: int) : unit
3961
requires { 0 <= q /\ covers q pos level }
3962
ensures { q = pos }
3963
= ext_bittest q (to_int pos)
3964
in
3965
let r = if pos <= PosT.max_tags h then PosT.find h pos else None in
3966
find_rel_mem (to_int pos) rels;
3967
match r with
3968
| Some g -> g
3969
| None ->
3970
assert { find_rel (to_int pos) rels = None };
3971
PBDD.bdd_of_snode { SNode.n = n; SNode.s = 0; SNode.scal = False }
3972
end
3973
end else begin
3974
mask_nonneg (to_int level);
3975
let pos' = Int63.lor pos (Int63.lsl 1 level) in
3976
let a = qfill n h rels (level - 1) pos' in
3977
let b = qfill n h rels (level - 1) pos in
3978
let r = PBDD.ite_index level a b in
3979
let lemma split (q: int) : unit
3980
requires { 0 <= q /\ covers q pos level }
3981
ensures { if bittest q level then covers q pos' (level - 1) else covers q pos (level - 1) }
3982
=
3983
let lemma bit (j: int) : unit
3984
ensures { bittest (lsl 1 level) j <-> j = level }
3985
= if 0 <= j then def_asr 1 (- to_int level) j
3986
in ()
3987
in
3988
let lemma value (id: int) (sn: snodes) : unit
3989
requires { 0 <= id /\ covers id pos level }
3990
ensures { r.PBDD.v id sn <->
3991
match find_rel id rels with
3992
| Some g -> g.PBDD.v id sn
3993
| None -> sn { SNode.n = n; SNode.s = (0:int63); SNode.scal = False }
3994
end }
3995
=
3996
split id;
3997
if bittest id (to_int level) then begin
3998
assert { r.PBDD.v id sn <-> a.PBDD.v id sn };
3999
assert { covers id pos' (level - 1) }
4000
end else begin
4001
assert { r.PBDD.v id sn <-> b.PBDD.v id sn };
4002
assert { covers id pos (level - 1) }
4003
end
4004
in
4005
numbits_set pure { lor a.dom_indexes b.dom_indexes } (to_int level);
4006
lor_numbits a.dom_indexes b.dom_indexes;
4007
r
4008
end
4009
Valid (83ms) (colibri2)
4010
let rec lemma
mem_mem_key
(l: list (snode, PBDD.t)) (nd: snode) (h: PBDD.t) : unit
4011
requires { Mem.mem (nd, h) l }
4012
variant { l }
4013
ensures { PBDD.mem_key nd l }
4014
= match l with Nil -> () | Cons _ l' -> if pure { Mem.mem (nd, h) l' } then mem_mem_key l' nd h end
4015
Valid (119ms) (cvc4)
4016
let rec lemma
mem_key_mem
(l: list (snode, PBDD.t)) (nd: snode) : unit
4017
requires { PBDD.mem_key nd l }
4018
variant { l }
4019
ensures { exists h. Mem.mem (nd, h) l }
4020
= match l with Nil -> () | Cons (nd', _) l' -> if pure { nd' <> nd } then mem_key_mem l' nd end
4021
Valid (57ms) (colibri2)
4022
let rec lemma
sorted_head
(x: snode) (l: list snode) (y: snode) : unit
4023
requires { sorted_desc (Cons x l) /\ Mem.mem y (Cons x l) }
4024
ensures { to_int y.SNode.s <= to_int x.SNode.s }
4025
= ()
4026
Valid (129ms) (colibri2)
4027
let rec lemma
distinct_keys_uniq
(l: list (snode, PBDD.t)) (nd: snode) (f g: PBDD.t) : unit
4028
requires { PBDD.distinct_keys l /\ Mem.mem (nd, f) l /\ Mem.mem (nd, g) l }
4029
variant { l }
4030
ensures { f = g }
4031
= match l with
4032
| Nil -> ()
4033
| Cons (nd', _) l' ->
4034
let rec lemma mk (l: list (snode, PBDD.t)) (h: PBDD.t) : unit
4035
requires { Mem.mem (nd, h) l }
4036
variant { l }
4037
ensures { PBDD.mem_key nd l }
4038
= match l with Nil -> () | Cons _ l -> if pure { not (Mem.mem (nd, h) l) } then () else mk l h end
4039
in
4040
if pure { nd' <> nd } then distinct_keys_uniq l' nd f g
4041
else begin
4042
if pure { Mem.mem (nd, f) l' } then mk l' f;
4043
if pure { Mem.mem (nd, g) l' } then mk l' g
4044
end
4045
end

The snodes of l with a non–negative shift (a prefix of l)

    Valid (444ms) (colibri2)
4048
let rec
keep_nonneg
(l: list snode) : list snode
4049
requires { Distinct.distinct l /\ sorted_desc l }
4050
variant { l }
4051
ensures { Distinct.distinct result /\ sorted_desc result }
4052
ensures { forall nd. Mem.mem nd result <-> (Mem.mem nd l /\ 0 <= nd.SNode.s) }
4053
= match l with
4054
| Nil -> Nil
4055
| Cons nd l' -> if nd.SNode.s >= 0 then Cons nd (keep_nonneg l') else Nil
4056
end

The constant BDDs of the bits 0 <= i < n of p

    Valid (416ms) (colibri2 35) (cvc4 5) (split_vc 2) (depth 2)
4059
let
consts
(n: int63) (p: int) : IArray63.t PBDD.t
4060
requires { 0 <= n }
4061
ensures { result.IArray63.length = n }
4062
ensures { forall i. 0 <= i < n -> (result i).dom_indexes = 0 }
4063
ensures { forall i. 0 <= i < n -> (result i).dom_snodes = Set.empty }
4064
ensures { forall i id sn. 0 <= i < n -> ((result i).PBDD.v id sn <-> bittest p i) }
4065
=
4066
let f = PBDD.tfalse () in
4067
let a = Array63.make n f in
4068
for i = 0 to n - 1 do
4069
invariant { forall k. i <= k < n -> a[k] = f }
4070
invariant { forall k. 0 <= k < n -> (a[k]).dom_indexes = 0 /\ (a[k]).dom_snodes = Set.empty }
4071
invariant { forall k id sn. 0 <= k < i -> ((a[k]).PBDD.v id sn <-> bittest p k) }
4072
label L in
4073
if Zbit.test_bit p i then begin
4074
let tt = PBDD.ttrue () in
4075
assert { forall id sn. tt.PBDD.v id sn };
4076
a[i] <- tt;
4077
assert { a[i] = tt };
4078
assert { forall id sn. (a[i]).PBDD.v id sn }
4079
end else begin
4080
assert { forall id sn. not (f.PBDD.v id sn) };
4081
assert { a[i] = f }
4082
end;
4083
assert { forall k. 0 <= k < i -> a[k] = (a at L)[k] };
4084
let lemma inv (k id: int) (sn: snodes) : unit
4085
requires { 0 <= k <= i }
4086
ensures { (a[k]).PBDD.v id sn <-> bittest p k }
4087
= if k < to_int i then begin
4088
assert { a[k] = (a at L)[k] };
4089
assert { ((a at L)[k]).PBDD.v id sn <-> bittest p k }
4090
end else begin
4091
assert { k = i };
4092
if Zbit.test_bit p i then assert { (a[k]).PBDD.v id sn }
4093
else assert { not ((a[k]).PBDD.v id sn) }
4094
end
4095
in ()
4096
done;
4097
IArray63.of_array a

The equation of the position p of the window of t, on the absolute snodes: the snode {m; s} becomes {m; s + p} (read at the position 0, it is the bit s + p of m)

    Valid (1.1s) (colibri2 37) (cvc4 8) (split_vc 6) (depth 3)
4102
let partial
instance
(t: t) (p: int63) : PBDD.t
4103
requires { lsl 1 t.size <= Int63.max_int }
4104
requires { 0 <= p < lsl 1 t.size }
4105
ensures { result.dom_indexes = 0 }
4106
ensures { forall id sn. result.PBDD.v id sn <-> t.bdd.PBDD.v p (shifted sn (- p)) }
4107
ensures { forall env. result.PBDD.v 0 (abs env) <-> t.bdd.PBDD.v p (sem env p) }
4108
ensures { nn_dep result }
4109
ensures { no_scal t.bdd -> no_scal result }
4110
ensures { forall nd. Set.mem nd (support_snodes t.bdd) -> nd.scal \/ in_bounds (to_int nd.s + p) }
4111
raises { Overflow -> exists nd. Set.mem nd (support_snodes t.bdd) /\
4112
not (in_bounds (to_int nd.s + p)) }
4113
=
4114
numbits_ge_pos 0 t.bdd.dom_indexes;
4115
let c = consts t.size (to_int p) in
4116
let x = PBDD.compose_shift c (- p) t.bdd in
4117
mask_nonneg (to_int t.size);
4118
(* the index of the composition is [p] *)
4119
let lemma idx (id: int) (sn: snodes) : unit
4120
ensures { of_bits (subst_bits c id sn) t.size = p }
4121
=
4122
numbits_lt_lsl (to_int p) (to_int t.size);
4123
of_bits_eq pure { subst_bits c id sn } (to_int p) (to_int t.size)
4124
in
4125
let lemma xv (id: int) (sn: snodes) : unit
4126
ensures { x.PBDD.v id sn <-> t.bdd.PBDD.v p (shifted sn (- p)) }
4127
= idx id sn
4128
in
4129
let r = PBDD.exist_window x t.size in
4130
let lemma rv (id: int) (sn: snodes) : unit
4131
ensures { r.PBDD.v id sn <-> t.bdd.PBDD.v p (shifted sn (- p)) }
4132
= xv 0 sn
4133
in
4134
let lemma ab (env: Node.t -> int) : unit
4135
ensures { r.PBDD.v 0 (abs env) <-> t.bdd.PBDD.v p (sem env p) }
4136
=
4137
let lemma pt (nd: snode) : unit
4138
requires { Set.mem nd (support_snodes t.bdd) }
4139
ensures { shifted (abs env) (- p) nd <-> sem env p nd }
4140
= sem_shift env 0 (- to_int p) nd;
4141
let nd' = shift_snode nd (- to_int p) in
4142
assert { abs env nd' <-> sem env 0 nd' }
4143
in
4144
rv 0 (abs env);
4145
PBDD.support_snodes_v t.bdd (to_int p) pure { shifted (abs env) (- p) } pure { sem env p }
4146
in
4147
let lemma nsc (_: unit) : unit
4148
requires { no_scal t.bdd }
4149
ensures { no_scal r }
4150
=
4151
let lemma ind (nd: snode) (id: int) (sn: snodes) : unit
4152
requires { not (Set.mem nd (fun nd -> not nd.SNode.scal)) }
4153
ensures { r.PBDD.v id (Set.add nd sn) <-> r.PBDD.v id (Set.remove nd sn) }
4154
=
4155
rv id (Set.add nd sn); rv id (Set.remove nd sn);
4156
PBDD.support_snodes_v t.bdd (to_int p) pure { shifted (Set.add nd sn) (- p) } pure { shifted (Set.remove nd sn) (- p) }
4157
in
4158
supp_by r pure { fun nd -> not nd.SNode.scal }
4159
in
4160
let lemma nn (id: int) (sn1 sn2: snodes) : unit
4161
requires { agree 0 sn1 sn2 }
4162
ensures { r.PBDD.v id sn1 <-> r.PBDD.v id sn2 }
4163
=
4164
rv id sn1; rv id sn2;
4165
let ghost y1 = pure { fun nd -> Set.mem nd (support_snodes t.bdd) /\ shifted sn1 (- p) nd } in
4166
let ghost y2 = pure { fun nd -> Set.mem nd (support_snodes t.bdd) /\ shifted sn2 (- p) nd } in
4167
PBDD.support_snodes_v t.bdd (to_int p) pure { shifted sn1 (- p) } y1;
4168
PBDD.support_snodes_v t.bdd (to_int p) pure { shifted sn2 (- p) } y2;
4169
let lemma ag (nd: snode) : unit
4170
requires { reads_at (p) nd }
4171
ensures { Set.mem nd y1 <-> Set.mem nd y2 }
4172
= if pure { Set.mem nd (support_snodes t.bdd) } then
4173
sem_shift (fun _ -> 0) 0 (- to_int p) nd
4174
in
4175
assert { agree p y1 y2 };
4176
numbits_lt_lsl (to_int p) (to_int t.size)
4177
in
4178
r
4179
4180
(* ---- Rows of a system of equations [c = false] on the absolute snodes ---- *)

The system: some row is true when it is not satisfied

4183
predicate
orl
(cs: list PBDD.t) (id: int) (sn: snodes) = exists c. Mem.mem c cs /\ c.PBDD.v id sn

The snodes of the supports of the rows

4186
predicate
in_rows
(cs: list PBDD.t) (nd: snode) =
4187
exists c. Mem.mem c cs /\ Set.mem nd (support_snodes c)

The rows have no index and only read non–negative shifts

4190
predicate
good_rows
(cs: list PBDD.t) =
4191
forall c. Mem.mem c cs -> numbits c.dom_indexes <= 0 /\ nn_dep c
4192
Valid (125ms) (colibri2)
4193
let rec
mem_key_var
(nd: snode) (l: list Key.t) : bool
4194
variant { l }
4195
ensures { result <-> Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) l }
4196
= match l with
4197
| Nil -> false
4198
| Cons (Key.Var n s a) l' -> (Node.equal n nd.SNode.n && s = nd.SNode.s && (if a then nd.SNode.scal else not nd.SNode.scal)) || mem_key_var nd l'
4199
| Cons (Key.Index _) l' -> mem_key_var nd l'
4200
end
4201
Valid (120ms) (colibri2)
4202
let
has_snode
(nd: snode) (c: PBDD.t) : bool
4203
ensures { result <-> Set.mem nd (support_snodes c) }
4204
= mem_key_var nd (PBDD.vars c)

The rows that read nd and the other ones

    Valid (230ms) (colibri2)
4207
let rec
split_rows
(nd: snode) (cs: list PBDD.t) : (w: list PBDD.t, o: list PBDD.t)
4208
variant { cs }
4209
ensures { forall c. Mem.mem c w <-> (Mem.mem c cs /\ Set.mem nd (support_snodes c)) }
4210
ensures { forall c. Mem.mem c o <-> (Mem.mem c cs /\ not (Set.mem nd (support_snodes c))) }
4211
ensures { Length.length w + Length.length o = Length.length cs }
4212
= match cs with
4213
| Nil -> (Nil, Nil)
4214
| Cons c cs' ->
4215
let (w, o) = split_rows nd cs' in
4216
if has_snode nd c then (Cons c w, o) else (w, Cons c o)
4217
end
4218
Valid (1.8s) (cvc4)
4219
let partial
is_functional
(nd: snode) (c: PBDD.t) : bool
4220
ensures { result <-> functional nd c }
4221
=
4222
let (p, n) = PBDD.cofactors_snode nd c in
4223
assert { forall id sn. p.PBDD.v id sn = c.PBDD.v id (Set.add nd sn) };
4224
assert { forall id sn. n.PBDD.v id sn = c.PBDD.v id (Set.remove nd sn) };
4225
let z = PBDD.dand (PBDD.dnot p) (PBDD.dnot n) in
4226
assert { forall id sn. z.PBDD.v id sn <->
4227
(not (c.PBDD.v id (Set.add nd sn)) /\ not (c.PBDD.v id (Set.remove nd sn))) };
4228
let f = PBDD.tfalse () in
4229
let (b, _, _) = PBDD.is_equal z f in
4230
assert { b <-> forall id sn. not (z.PBDD.v id sn) };
4231
b
4232
Valid (162ms) (colibri2)
4233
let rec partial
find_functional
(nd: snode) (cs: list PBDD.t) : option (PBDD.t, list PBDD.t)
4234
variant { cs }
4235
ensures { match result with
4236
| None -> forall c. Mem.mem c cs -> not (functional nd c)
4237
| Some (c, o) -> Mem.mem c cs /\ functional nd c /\
4238
(forall c'. Mem.mem c' cs <-> (c' = c \/ Mem.mem c' o)) /\
4239
(forall c'. Mem.mem c' o -> Mem.mem c' cs) /\
4240
Length.length o + 1 = Length.length cs
4241
end }
4242
= match cs with
4243
| Nil -> None
4244
| Cons c cs' ->
4245
if is_functional nd c then Some (c, cs')
4246
else match find_functional nd cs' with
4247
| None -> None
4248
| Some (c', o) -> Some (c', Cons c o)
4249
end
4250
end

The disjunction of the rows

    Valid (2.9s) (colibri2 9) (cvc4 5) (split_vc 7) (depth 3)
4253
let rec
or_rows
(cs: list PBDD.t) : PBDD.t
4254
requires { good_rows cs }
4255
variant { cs }
4256
ensures { numbits result.dom_indexes <= 0 /\ nn_dep result }
4257
ensures { forall id sn. result.PBDD.v id sn <-> orl cs id sn }
4258
ensures { forall nd. Set.mem nd (support_snodes result) -> in_rows cs nd }
4259
= match cs with
4260
| Nil -> PBDD.tfalse ()
4261
| Cons c cs' ->
4262
let o = or_rows cs' in
4263
let r = PBDD.dor c o in
4264
lor_numbits c.dom_indexes o.dom_indexes;
4265
supp_by r pure { fun nd -> in_rows cs nd };
4266
r
4267
end

The row c where nd has the value of q

    Valid (220ms) (colibri2 11) (split_vc) (depth 1)
4270
let partial
subst1
(nd: snode) (q c: PBDD.t) : PBDD.t
4271
requires { numbits q.dom_indexes <= 0 /\ numbits c.dom_indexes <= 0 }
4272
ensures { numbits result.dom_indexes <= 0 }
4273
ensures { forall id sn. result.PBDD.v id sn <-> c.PBDD.v id (Map.set sn nd (q.PBDD.v id sn)) }
4274
ensures { forall nd'. Set.mem nd' (support_snodes result) ->
4275
(nd' <> nd /\ Set.mem nd' (support_snodes c)) \/ Set.mem nd' (support_snodes q) }
4276
=
4277
let l = Cons (nd, q) Nil in
4278
let r = PBDD.compose_snodes 0 l c in
4279
let lemma sv (id: int) (sn: snodes) : unit
4280
ensures { subst_sn l id sn = Map.set sn nd (q.PBDD.v id sn) }
4281
= ()
4282
in
4283
let lemma ind (nd': snode) (id: int) (sn: snodes) : unit
4284
requires { not ((nd' <> nd /\ Set.mem nd' (support_snodes c)) \/ Set.mem nd' (support_snodes q)) }
4285
ensures { r.PBDD.v id (Set.add nd' sn) <-> r.PBDD.v id (Set.remove nd' sn) }
4286
=
4287
PBDD.support_snodes_v q id (Set.add nd' sn) (Set.remove nd' sn);
4288
PBDD.support_snodes_v c id (Map.set (Set.add nd' sn) nd (q.PBDD.v id sn))
4289
(Map.set (Set.remove nd' sn) nd (q.PBDD.v id sn))
4290
in
4291
supp_by r pure { fun nd' -> (nd' <> nd /\ Set.mem nd' (support_snodes c)) \/ Set.mem nd' (support_snodes q) };
4292
r

c' is the row c where nd has the value of q

4295
predicate
is_subst
(nd: snode) (q c c': PBDD.t) =
4296
(forall id sn. c'.PBDD.v id sn <-> c.PBDD.v id (Map.set sn nd (q.PBDD.v id sn))) /\
4297
(forall nd'. Set.mem nd' (support_snodes c') ->
4298
(nd' <> nd /\ Set.mem nd' (support_snodes c)) \/ Set.mem nd' (support_snodes q))

The rows of cs where nd has the value of q, before acc

    Valid (792ms) (colibri2 17) (cvc4 2) (split_vc) (depth 1)
4301
let rec partial
subst_rows
(nd: snode) (q: PBDD.t) (cs acc: list PBDD.t) : list PBDD.t
4302
requires { good_rows cs /\ good_rows acc }
4303
requires { nn_dep q /\ numbits q.dom_indexes <= 0 }
4304
variant { cs }
4305
ensures { good_rows result }
4306
ensures { forall c'. Mem.mem c' result -> Mem.mem c' acc \/ exists c. Mem.mem c cs /\ is_subst nd q c c' }
4307
ensures { forall c. Mem.mem c cs -> exists c'. Mem.mem c' result /\ is_subst nd q c c' }
4308
ensures { forall c. Mem.mem c acc -> Mem.mem c result }
4309
ensures { Length.length result = Length.length cs + Length.length acc }
4310
= match cs with
4311
| Nil -> acc
4312
| Cons c cs' ->
4313
let c' = subst1 nd q c in
4314
let lemma sv (id: int) (sn: snodes) : unit
4315
ensures { subst_sn (Cons (nd, q) Nil) id sn = Map.set sn nd (q.PBDD.v id sn) }
4316
= ()
4317
in
4318
nn_dep_compose c c' (Cons (nd, q) Nil);
4319
assert { is_subst nd q c c' };
4320
Cons c' (subst_rows nd q cs' acc)
4321
end

One step of the elimination of the snode v: rows does not read v and is satisfied iff cs is, with v given by q

    Valid (1.0s) (colibri2 65) (cvc4 13) (cvc5) (split_vc 10) (depth 2)
4325
let partial
gj_step
(v: snode) (cs: list PBDD.t) : (q: PBDD.t, rows: list PBDD.t)
4326
requires { good_rows cs /\ 0 <= v.SNode.s }
4327
ensures { good_rows rows /\ nn_dep q /\ numbits q.dom_indexes <= 0 }
4328
ensures { Length.length rows <= Length.length cs }
4329
ensures { forall nd. in_rows rows nd -> in_rows cs nd /\ nd <> v }
4330
ensures { forall nd. Set.mem nd (support_snodes q) -> nd = v \/ in_rows cs nd }
4331
ensures { forall id sn. not (orl rows id sn) -> not (orl cs id (Map.set sn v (q.PBDD.v id sn))) }
4332
ensures { forall id sn. not (orl cs id sn) -> not (orl rows id sn) /\ (q.PBDD.v id sn <-> sn v) }
4333
=
4334
let (w, o) = split_rows v cs in
4335
(* the rows that do not read [v] are unchanged by [v] *)
4336
let lemma ov (id: int) (sn: snodes) (b: bool) (c: PBDD.t) : unit
4337
requires { Mem.mem c o }
4338
ensures { c.PBDD.v id (Map.set sn v b) <-> c.PBDD.v id sn }
4339
= PBDD.support_snodes_v c id pure { Map.set sn v b } sn
4340
in
4341
(* [q] and [r] of Löwenheim do not read a negative shift *)
4342
let lemma nnl (a q r: PBDD.t) : unit
4343
requires { nn_dep a }
4344
requires { forall id sn. r.PBDD.v id sn <-> (a.PBDD.v id (Set.add v sn) /\ a.PBDD.v id (Set.remove v sn)) }
4345
requires { forall id sn. q.PBDD.v id sn <->
4346
(not (a.PBDD.v id (Set.add v sn)) /\ (a.PBDD.v id (Set.remove v sn) \/ Set.mem v sn)) }
4347
ensures { nn_dep q /\ nn_dep r }
4348
=
4349
let lemma pt (id: int) (sn1 sn2: snodes) : unit
4350
requires { agree 0 sn1 sn2 }
4351
ensures { (r.PBDD.v id sn1 <-> r.PBDD.v id sn2) /\ (q.PBDD.v id sn1 <-> q.PBDD.v id sn2) }
4352
= assert { agree 0 (Set.add v sn1) (Set.add v sn2) };
4353
assert { agree 0 (Set.remove v sn1) (Set.remove v sn2) };
4354
assert { Set.mem v sn1 <-> Set.mem v sn2 }
4355
in ()
4356
in
4357
match w with
4358
| Nil ->
4359
(* [v] is not read: it is free *)
4360
let q = PBDD.bdd_of_snode v in
4361
let lemma nq (id: int) (sn1 sn2: snodes) : unit
4362
requires { agree 0 sn1 sn2 }
4363
ensures { q.PBDD.v id sn1 <-> q.PBDD.v id sn2 }
4364
= assert { reads_at 0 v }
4365
in
4366
let lemma st (id: int) (sn: snodes) : unit
4367
ensures { orl cs id (Map.set sn v (q.PBDD.v id sn)) <-> orl cs id sn }
4368
=
4369
let lemma pc (c: PBDD.t) : unit
4370
requires { Mem.mem c cs }
4371
ensures { c.PBDD.v id (Map.set sn v (q.PBDD.v id sn)) <-> c.PBDD.v id sn }
4372
= assert { Mem.mem c o }; ov id sn pure { q.PBDD.v id sn } c
4373
in ()
4374
in
4375
(q, cs)
4376
| _ ->
4377
match find_functional v w with
4378
| Some (c, w') ->
4379
(* Gauss: [c] gives [v], substituted in the other rows *)
4380
assert { Mem.mem c cs };
4381
let (q, rc) = lowenheim v c in
4382
nnl c q rc;
4383
let sw = subst_rows v q w' o in
4384
let rows = Cons rc sw in
4385
let lemma sol (id: int) (sn: snodes) : unit
4386
requires { not (orl rows id sn) }
4387
ensures { not (orl cs id (Map.set sn v (q.PBDD.v id sn))) }
4388
=
4389
let lemma pc (c1: PBDD.t) : unit
4390
requires { Mem.mem c1 cs }
4391
ensures { not (c1.PBDD.v id (Map.set sn v (q.PBDD.v id sn))) }
4392
=
4393
if pure { Mem.mem c1 o } then ov id sn pure { q.PBDD.v id sn } c1
4394
else if pure { c1 = c } then ()
4395
else begin
4396
assert { Mem.mem c1 w' };
4397
let ghost c' = any PBDD.t ensures { Mem.mem result sw /\ is_subst v q c1 result } in
4398
assert { not (c'.PBDD.v id sn) }
4399
end
4400
in ()
4401
in
4402
let lemma rep (id: int) (sn: snodes) : unit
4403
requires { not (orl cs id sn) }
4404
ensures { not (orl rows id sn) /\ (q.PBDD.v id sn <-> sn v) }
4405
=
4406
assert { not (c.PBDD.v id sn) };
4407
assert { q.PBDD.v id sn <-> sn v };
4408
let lemma ms (_: unit) : unit
4409
ensures { forall c1. Mem.mem c1 w' -> (c1.PBDD.v id (Map.set sn v (q.PBDD.v id sn)) <-> c1.PBDD.v id sn) }
4410
=
4411
let lemma pc (c1: PBDD.t) : unit
4412
requires { Mem.mem c1 w' }
4413
ensures { c1.PBDD.v id (Map.set sn v (q.PBDD.v id sn)) <-> c1.PBDD.v id sn }
4414
= PBDD.support_snodes_v c1 id pure { Map.set sn v (q.PBDD.v id sn) } sn
4415
in ()
4416
in
4417
let lemma pr (c': PBDD.t) : unit
4418
requires { Mem.mem c' rows }
4419
ensures { not (c'.PBDD.v id sn) }
4420
=
4421
if pure { c' = rc } then ()
4422
else if pure { Mem.mem c' o } then ()
4423
else begin
4424
let ghost _ = any PBDD.t ensures { Mem.mem result w' /\ is_subst v q result c' } in
4425
()
4426
end
4427
in ()
4428
in
4429
let lemma sup (nd: snode) : unit
4430
requires { in_rows rows nd }
4431
ensures { in_rows cs nd /\ nd <> v }
4432
=
4433
let ghost c' = any PBDD.t ensures { Mem.mem result rows /\ Set.mem nd (support_snodes result) } in
4434
if pure { c' = rc } then assert { Set.mem nd (support_snodes c) }
4435
else if pure { Mem.mem c' o } then ()
4436
else begin
4437
let ghost c1 = any PBDD.t ensures { Mem.mem result w' /\ is_subst v q result c' } in
4438
if pure { Set.mem nd (support_snodes q) } then assert { Set.mem nd (support_snodes c) }
4439
else assert { Set.mem nd (support_snodes c1) /\ Mem.mem c1 cs }
4440
end
4441
in
4442
let lemma supq (nd: snode) : unit
4443
requires { Set.mem nd (support_snodes q) }
4444
ensures { nd = v \/ in_rows cs nd }
4445
= assert { Set.mem nd (support_snodes c) }
4446
in
4447
(q, rows)
4448
| None ->
4449
(* no row gives [v]: Löwenheim on the disjunction of its rows *)
4450
let a = or_rows w in
4451
let (q, r) = lowenheim v a in
4452
nnl a q r;
4453
let rows = Cons r o in
4454
let lemma sol (id: int) (sn: snodes) : unit
4455
requires { not (orl rows id sn) }
4456
ensures { not (orl cs id (Map.set sn v (q.PBDD.v id sn))) }
4457
=
4458
let lemma pc (c1: PBDD.t) : unit
4459
requires { Mem.mem c1 cs }
4460
ensures { not (c1.PBDD.v id (Map.set sn v (q.PBDD.v id sn))) }
4461
= if pure { Mem.mem c1 o } then ov id sn pure { q.PBDD.v id sn } c1
4462
in ()
4463
in
4464
let lemma rep (id: int) (sn: snodes) : unit
4465
requires { not (orl cs id sn) }
4466
ensures { not (orl rows id sn) /\ (q.PBDD.v id sn <-> sn v) }
4467
= assert { not (a.PBDD.v id sn) }
4468
in
4469
let lemma sup (nd: snode) : unit
4470
requires { in_rows rows nd }
4471
ensures { in_rows cs nd /\ nd <> v }
4472
=
4473
let ghost c' = any PBDD.t ensures { Mem.mem result rows /\ Set.mem nd (support_snodes result) } in
4474
if pure { c' = r } then assert { Set.mem nd (support_snodes a) /\ nd <> v }
4475
in
4476
let lemma supq (nd: snode) : unit
4477
requires { Set.mem nd (support_snodes q) }
4478
ensures { nd = v \/ in_rows cs nd }
4479
= if pure { nd <> v } then assert { Set.mem nd (support_snodes a) }
4480
in
4481
(q, rows)
4482
end
4483
end

The elimination of the snodes l in the rows cs (Gauss–Jordan, row by row): rs is the consistency condition and sols gives a reproductive solution for each snode of l

    Valid (379ms) (colibri2 39) (split_vc) (depth 1)
4488
let rec partial
gj_rows
(cs: list PBDD.t) (l: list snode) : (rs: list PBDD.t, sols: list (snode, PBDD.t))
4489
requires { good_rows cs }
4490
requires { Distinct.distinct l }
4491
requires { forall nd. Mem.mem nd l -> 0 <= nd.SNode.s }
4492
variant { l }
4493
ensures { good_rows rs }
4494
ensures { Length.length rs <= Length.length cs }
4495
ensures { forall nd f. Mem.mem (nd, f) sols -> nn_dep f /\ numbits f.dom_indexes <= 0 }
4496
ensures { PBDD.distinct_keys sols }
4497
ensures { forall nd. PBDD.mem_key nd sols <-> Mem.mem nd l }
4498
ensures { forall nd. in_rows rs nd -> in_rows cs nd /\ not (Mem.mem nd l) }
4499
ensures { forall id sn. not (orl rs id sn) -> not (orl cs id (subst_sn sols id sn)) }
4500
ensures { forall id sn. not (orl cs id sn) ->
4501
not (orl rs id sn) /\ (forall nd f. Mem.mem (nd, f) sols -> (f.PBDD.v id sn <-> sn nd)) }
4502
= match l with
4503
| Nil ->
4504
let lemma idsub (id: int) (sn: snodes) : unit
4505
ensures { subst_sn Nil id sn = sn }
4506
= ()
4507
in
4508
(cs, Nil)
4509
| Cons v l' ->
4510
let (q, rows) = gj_step v cs in
4511
let (rs, sols) = gj_rows rows l' in
4512
let q' = PBDD.compose_snodes 0 sols q in
4513
nn_dep_compose q q' sols;
4514
let res = Cons (v, q') sols in
4515
let lemma sol (id: int) (sn: snodes) : unit
4516
requires { not (orl rs id sn) }
4517
ensures { not (orl cs id (subst_sn res id sn)) }
4518
=
4519
let ghost sn1 = subst_sn sols id sn in
4520
assert { not (orl rows id sn1) };
4521
assert { q'.PBDD.v id sn <-> q.PBDD.v id sn1 };
4522
assert { subst_sn res id sn = Map.set sn1 v (q'.PBDD.v id sn) }
4523
in
4524
let lemma rep (id: int) (sn: snodes) : unit
4525
requires { not (orl cs id sn) }
4526
ensures { not (orl rs id sn) }
4527
ensures { forall nd f. Mem.mem (nd, f) res -> (f.PBDD.v id sn <-> sn nd) }
4528
=
4529
assert { not (orl rows id sn) /\ (q.PBDD.v id sn <-> sn v) };
4530
let lemma idn (nd: snode) : unit
4531
ensures { subst_sn sols id sn nd = sn nd }
4532
= subst_sn_id sols id sn nd
4533
in
4534
PBDD.support_snodes_v q id pure { subst_sn sols id sn } sn;
4535
assert { q'.PBDD.v id sn <-> sn v }
4536
in
4537
(rs, res)
4538
end

The row k of rs is true

4541
predicate
row_bit
(rs: list PBDD.t) (k: int) (sn: snodes) =
4542
match rs with
4543
| Nil -> false
4544
| Cons r rs' -> if k = 0 then r.PBDD.v 0 sn else row_bit rs' (k - 1) sn
4545
end
4546
Valid (144ms) (colibri2 6) (split_vc 2) (depth 2)
4547
let rec lemma
row_bit_orl
(rs: list PBDD.t) (sn: snodes) : unit
4548
variant { rs }
4549
ensures { orl rs 0 sn <-> exists k. 0 <= k /\ row_bit rs k sn }
4550
= match rs with
4551
| Nil -> ()
4552
| Cons r rs' ->
4553
row_bit_orl rs' sn;
4554
if pure { r.PBDD.v 0 sn } then assert { row_bit rs 0 sn };
4555
assert { forall k. 0 <= k -> row_bit rs' k sn -> row_bit rs (k + 1) sn };
4556
assert { forall k. 0 < k -> row_bit rs k sn -> row_bit rs' (k - 1) sn }
4557
end
4558
Valid (74ms) (colibri2)
4559
let rec lemma
row_bit_neg
(rs: list PBDD.t) (k: int) (sn: snodes) : unit
4560
requires { k < 0 }
4561
variant { rs }
4562
ensures { not (row_bit rs k sn) }
4563
= match rs with Nil -> () | Cons _ rs' -> row_bit_neg rs' (k - 1) sn end
4564
Valid (231ms) (cvc4)
4565
let ghost
sem0_abs
(env: Node.t -> int) : unit
4566
ensures { sem env 0 = abs env }
4567
= assert { forall nd. sem env 0 nd = abs env nd }
4568
Valid (77ms) (colibri2)
4569
let rec
rows_len
(rs: list PBDD.t) : int63
4570
requires { Length.length rs <= 0x1000_0000_0000_0000 }
4571
variant { rs }
4572
ensures { result = Length.length rs }
4573
= match rs with Nil -> 0 | Cons _ rs' -> 1 + rows_len rs' end
4574
Valid (73ms) (colibri2)
4575
let rec lemma
row_bit_len
(rs: list PBDD.t) (k: int) (sn: snodes) : unit
4576
requires { Length.length rs <= k }
4577
variant { rs }
4578
ensures { not (row_bit rs k sn) }
4579
= match rs with Nil -> () | Cons _ rs' -> row_bit_len rs' (k - 1) sn end

The row k of rs

    Valid (77ms) (colibri2 4) (split_vc) (depth 1)
4582
let rec
row_at
(rs: list PBDD.t) (k: int63) : option PBDD.t
4583
requires { 0 <= k }
4584
variant { rs }
4585
ensures { match result with
4586
| None -> forall sn. not (row_bit rs k sn)
4587
| Some r -> Mem.mem r rs /\ forall sn. row_bit rs k sn <-> r.PBDD.v 0 sn
4588
end }
4589
= match rs with
4590
| Nil -> None
4591
| Cons r rs' -> if k = 0 then Some r else row_at rs' (k - 1)
4592
end

The window whose position k is the row k of rs, relativized (the positions covers _ pos level)

    Valid (1.4s) (colibri2 41) (cvc4 6) (split_vc 2) (depth 2)
4596
let rec partial
rfill
(empty: IArray63.t PBDD.t) (rs: list PBDD.t) (ghost top: int) (level pos: int63) : PBDD.t
4597
requires { empty.IArray63.length = 0 }
4598
requires { good_rows rs }
4599
requires { 0 <= top <= 60 /\ -1 <= level < top }
4600
requires { 0 <= pos /\ numbits pos <= top }
4601
requires { forall j. 0 <= j <= level -> not (bittest pos j) }
4602
variant { level + 1 }
4603
ensures { numbits result.dom_indexes <= level + 1 }
4604
ensures { forall id env. 0 <= id -> covers id pos level ->
4605
(result.PBDD.v id (sem env id) <-> row_bit rs id (abs env)) }
4606
ensures { forall id sn1 sn2. 0 <= id -> covers id pos level -> agree id sn1 sn2 ->
4607
(result.PBDD.v id sn1 <-> result.PBDD.v id sn2) }
4608
=
4609
if level < 0 then begin
4610
let lemma base (q: int) : unit
4611
requires { 0 <= q /\ covers q pos level }
4612
ensures { q = pos }
4613
= ext_bittest q (to_int pos)
4614
in
4615
lt_lsl_of_numbits (to_int pos) top;
4616
lsl_le_2_60 top;
4617
match row_at rs pos with
4618
| Some r -> relativize1 empty pos r
4619
| None -> PBDD.tfalse ()
4620
end
4621
end else begin
4622
mask_nonneg (to_int level);
4623
lsl_le_max_int (to_int level + 1);
4624
let pos' = Int63.lor pos (Int63.lsl 1 level) in
4625
let lemma bitl (j: int) : unit
4626
ensures { bittest (lsl 1 level) j <-> j = level }
4627
= if 0 <= j then def_asr 1 (- to_int level) j
4628
in
4629
numbits_lsl (to_int level);
4630
lor_numbits (to_int pos) pure { lsl 1 level };
4631
let a = rfill empty rs top (level - 1) pos' in
4632
let b = rfill empty rs top (level - 1) pos in
4633
let r = PBDD.ite_index level a b in
4634
let lemma split (q: int) : unit
4635
requires { 0 <= q /\ covers q pos level }
4636
ensures { if bittest q level then covers q pos' (level - 1) else covers q pos (level - 1) }
4637
= ()
4638
in
4639
numbits_set pure { lor a.dom_indexes b.dom_indexes } (to_int level);
4640
lor_numbits a.dom_indexes b.dom_indexes;
4641
r
4642
end

The term whose bit k is the row k of rs (the consistency condition of the rows, without their disjunction)

    Valid (730ms) (colibri2 40) (cvc4) (split_vc) (depth 1)
4646
let partial
rows_term
(rs: list PBDD.t) : t
4647
requires { good_rows rs }
4648
requires { Length.length rs <= 0x1000_0000_0000_0000 }
4649
ensures { forall env p. 0 <= p -> (bittest (value result env) p <-> row_bit rs p (abs env)) }
4650
=
4651
let m = rows_len rs in
4652
if m = 0 then begin
4653
let z = cst 0 in
4654
let lemma zb (env: Node.t -> int) (p: int) : unit
4655
requires { 0 <= p }
4656
ensures { bittest (value z env) p <-> row_bit rs p (abs env) }
4657
= assert { value z env = 0 }
4658
in
4659
z
4660
end else begin
4661
let m1 = m - 1 in
4662
numbits_ge_pos 0 (to_int m1);
4663
numbits_le_self (to_int m1);
4664
let sz = Int63.of_int (Zbit.numbits (to_int m1)) in
4665
numbits_lsl_lt (to_int m1);
4666
assert { sz <= 61 };
4667
lsl_le_max_int (to_int sz);
4668
lsl_power (to_int sz);
4669
assert { lsl 1 sz <= 2 * m };
4670
let empty = IArray63.of_array (Array63.make 0 (PBDD.tfalse ())) in
4671
let w = rfill empty rs pure { to_int sz } (sz - 1) 0 in
4672
let lemma cov (id: int) : unit
4673
requires { 0 <= id /\ numbits id <= sz }
4674
ensures { covers id 0 (sz - 1) }
4675
=
4676
let lemma hc (j: int) : unit
4677
requires { sz - 1 < j }
4678
ensures { not (bittest id j) }
4679
= if id > 0 then numbits_high_clear id j
4680
in ()
4681
in
4682
let lemma nn (p: int) (sn1 sn2: snodes) : unit
4683
requires { 0 <= p /\ numbits p <= sz /\ agree p sn1 sn2 }
4684
ensures { w.PBDD.v p sn1 <-> w.PBDD.v p sn2 }
4685
= cov p
4686
in
4687
let rr = mk w sz in
4688
let lemma vb (env: Node.t -> int) (p: int) : unit
4689
requires { 0 <= p }
4690
ensures { bittest (value rr env) p <-> row_bit rs p (abs env) }
4691
=
4692
PBDD2.def_v w (to_int sz) (sem env) p;
4693
if numbits p <= to_int sz then cov p
4694
else begin
4695
if p < pure { lsl 1 sz } then numbits_lt_lsl p (to_int sz);
4696
row_bit_len rs p (abs env)
4697
end
4698
in
4699
rr
4700
end Valid (460ms) (cvc5)
4701
let rec
rows_vars
(cs: list PBDD.t) : list Key.t
4702
variant { cs }
4703
ensures { forall n s a. Mem.mem (Key.Var n s a) result <-> in_rows cs { SNode.n = n; SNode.s = s; SNode.scal = a } }
4704
= match cs with
4705
| Nil -> Nil
4706
| Cons c cs' -> Lists.(++) (PBDD.vars c) (rows_vars cs')
4707
end
4708
Valid (257ms) (colibri2)
4709
let rec lemma
row_bit_eq
(rs: list PBDD.t) (k: int) (sn1 sn2: snodes) : unit
4710
requires { forall nd. in_rows rs nd -> sn1 nd = sn2 nd }
4711
variant { rs }
4712
ensures { row_bit rs k sn1 <-> row_bit rs k sn2 }
4713
= match rs with
4714
| Nil -> ()
4715
| Cons r rs' ->
4716
if k = 0 then PBDD.support_snodes_v r 0 sn1 sn2
4717
else row_bit_eq rs' (k - 1) sn1 sn2
4718
end
4719
Valid (144ms) (colibri2)
4720
let ghost
orl_eq
(cs: list PBDD.t) (id: int) (sn1 sn2: snodes) : unit
4721
requires { forall nd. in_rows cs nd -> sn1 nd = sn2 nd }
4722
ensures { orl cs id sn1 <-> orl cs id sn2 }
4723
=
4724
let lemma pc (c: PBDD.t) : unit
4725
requires { Mem.mem c cs }
4726
ensures { c.PBDD.v id sn1 <-> c.PBDD.v id sn2 }
4727
= PBDD.support_snodes_v c id sn1 sn2
4728
in ()

solve_gj cannot solve b0: some node of its support has a size out of the bounds or a shift of at least 2^61

4732
predicate
gj_bad
(sizes: Node.t -> int63) (rows: list PBDD.t) =
4733
exists nd. in_rows rows nd /\
4734
(sizes nd.SNode.n < 0 \/ sizes nd.SNode.n > 0x2000_0000_0000_0000 \/
4735
exists nd'. in_rows rows nd' /\ nd'.SNode.n = nd.SNode.n /\
4736
nd'.SNode.s >= 0x2000_0000_0000_0000)

The Gauss–Jordan case of solve on rows, one row per position of the window of t (instances): the elimination of the bits of the node with the fewest bits, row by row (gj_rows); the consistency condition has one bit per remaining row (rows_term). Differs from bddbitv.ml: OCaml builds one BDD of the absolute snodes (convert_to_pos0, exponential when the shifts are far apart) and evaluates r on the window of t; the window of q covers the eliminated bits; Zero when the equation is always true (OCaml returns Unsat); the snodes of n with a negative shift are not eliminated (they read a negative bit: always false); TryLater for the bounds that do not fit.

    Valid (2.1s) (colibri2 175) (cvc4 46) (cvc5 7) (split_vc 94) (depth 5)
4749
let partial
solve_gj
(sizes: Node.t -> int63) (t: t) (rows: list PBDD.t) : solve
4750
requires { lsl 1 t.size <= Int63.max_int }
4751
requires { no_scal t.bdd /\ forall c. Mem.mem c rows -> no_scal c }
4752
requires { good_rows rows /\ Length.length rows <= 0x1000_0000_0000_0000 }
4753
requires { forall env. orl rows 0 (abs env) <-> value t env <> 0 }
4754
ensures { match result with
4755
| Zero -> forall env. value t env = 0
4756
| Unsat -> forall env. value t env <> 0
4757
| Subst n q r ->
4758
(forall env x. value r (upd_env env n x) = value r env) /\
4759
(forall env. value r env = 0 -> value t (upd_env env n (value q env)) = 0) /\
4760
(forall env. value t env = 0 ->
4761
value r env = 0 /\ (0 <= env n < lsl 1 (sizes n) -> value q env = env n))
4762
| TryLater -> gj_bad sizes rows
4763
end }
4764
=
4765
let vs = rows_vars rows in
4766
match get_var_less_shift vs with
4767
| None ->
4768
(* no snode: the rows are constant *)
4769
let a = or_rows rows in
4770
let lemma no_nd (nd: snode) : unit
4771
ensures { not (Set.mem nd (support_snodes a)) }
4772
= if pure { Set.mem nd (support_snodes a) } then begin
4773
assert { in_rows rows { SNode.n = nd.SNode.n; SNode.s = nd.SNode.s; SNode.scal = nd.SNode.scal } };
4774
assert { Mem.mem (Key.Var nd.SNode.n nd.SNode.s nd.SNode.scal) vs }
4775
end
4776
in
4777
assert { Set.is_empty (support_snodes a) };
4778
let lemma indep (sn1 sn2: snodes) : unit
4779
ensures { orl rows 0 sn1 <-> orl rows 0 sn2 }
4780
= PBDD.support_snodes_v a 0 sn1 sn2
4781
in
4782
let (z, _, _) = PBDD.is_equal a (PBDD.tfalse ()) in
4783
if z then begin
4784
let lemma zero (env: Node.t -> int) : unit
4785
ensures { value t env = 0 }
4786
= assert { not (a.PBDD.v 0 (abs env)) }
4787
in
4788
Zero
4789
end else begin
4790
let ghost (id, sn) = any (int, snodes) ensures { let (id, sn) = result in a.PBDD.v id sn } in
4791
let lemma one (env: Node.t -> int) : unit
4792
ensures { value t env <> 0 }
4793
= PBDD.support_v a id 0 sn; indep sn (abs env)
4794
in
4795
Unsat
4796
end
4797
| Some (n, _, l0) ->
4798
let l = keep_nonneg (sort_bits l0) in
4799
match l with
4800
| Nil ->
4801
(* [b0] does not depend on the snodes with a negative shift *)
4802
let lemma ne (_: unit) : unit
4803
ensures { false }
4804
=
4805
match l0 with
4806
| Nil -> ()
4807
| Cons x _ ->
4808
assert { Mem.mem x l0 };
4809
assert { in_rows rows x };
4810
let ghost c = any PBDD.t ensures { Mem.mem result rows /\ Set.mem x (support_snodes result) } in
4811
nn_dep_supp c x
4812
end
4813
in absurd
4814
| Cons maxb _ ->
4815
let szn = sizes n in
4816
if maxb.SNode.s >= 0x2000_0000_0000_0000 || szn < 0 || szn > 0x2000_0000_0000_0000 then begin
4817
assert { Mem.mem maxb l };
4818
assert { in_rows rows maxb /\ maxb.SNode.n = n };
4819
TryLater
4820
end
4821
else begin
4822
let (rs, sols) = gj_rows rows l in
4823
let w = maxb.SNode.s + 1 in
4824
let s = if szn > w then szn else w in
4825
numbits_ge_pos 0 (to_int s - 1);
4826
numbits_le_self (to_int s - 1);
4827
let n_size = Int63.of_int (Zbit.numbits (to_int s - 1)) in
4828
numbits_lsl_lt (to_int s - 1);
4829
assert { to_int n_size <= 62 };
4830
assert { lsl 1 n_size <= Int63.max_int };
4831
let empty = IArray63.of_array (Array63.make 0 (PBDD.tfalse ())) in
4832
assert { forall nd f. Mem.mem (nd, f) sols -> Mem.mem nd l };
4833
let rels = relativize empty sols in
4834
let lemma rpos (nd: snode) (g: PBDD.t) : unit
4835
requires { Mem.mem (nd, g) rels }
4836
ensures { 0 <= nd.SNode.s < s }
4837
= mem_mem_key rels nd g;
4838
mem_key_mem sols nd;
4839
sorted_head maxb (match l with Nil -> Nil | Cons _ l' -> l' end) nd
4840
in
4841
let h = table_rels s rels in
4842
let qb = qfill n h rels (n_size - 1) 0 in
4843
begin ensures { no_neg qb n_size }
4844
let lemma nq (id: int) (sn1 sn2: snodes) : unit
4845
requires { 0 <= id /\ numbits id <= n_size /\ agree id sn1 sn2 }
4846
ensures { qb.PBDD.v id sn1 <-> qb.PBDD.v id sn2 }
4847
=
4848
let lemma hc (j: int) : unit
4849
requires { n_size - 1 < j }
4850
ensures { not (bittest id j) }
4851
= if id > 0 then numbits_high_clear id j
4852
in
4853
assert { covers id 0 (n_size - 1) };
4854
assert { reads_at id { SNode.n = n; SNode.s = (0:int63); SNode.scal = False } };
4855
find_rel_mem id rels;
4856
assert { match find_rel id rels with
4857
| Some g -> g.PBDD.v id sn1 <-> g.PBDD.v id sn2
4858
| None -> sn1 { SNode.n = n; SNode.s = (0:int63); SNode.scal = False } <-> sn2 { SNode.n = n; SNode.s = (0:int63); SNode.scal = False }
4859
end }
4860
in ()
4861
end;
4862
let q = mk qb n_size in
4863
let rr = rows_term rs in
4864
(* the snodes of [n] in [b0] are the ones of [l], or have a negative shift *)
4865
let lemma inl (nd: snode) : unit
4866
requires { in_rows rows nd /\ nd.SNode.n = n }
4867
ensures { (Mem.mem nd l \/ nd.SNode.s < 0) /\ not nd.SNode.scal }
4868
= let ghost c = any PBDD.t ensures { Mem.mem result rows /\ Set.mem nd (support_snodes result) } in
4869
assert { no_scal c };
4870
nn_dep_supp c nd
4871
in
4872
let lemma inl2 (nd: snode) : unit
4873
requires { Mem.mem nd l }
4874
ensures { nd.SNode.n = n /\ 0 <= nd.SNode.s < s /\ not nd.SNode.scal }
4875
= sorted_head maxb (match l with Nil -> Nil | Cons _ l' -> l' end) nd;
4876
assert { in_rows rows nd };
4877
let ghost c = any PBDD.t ensures { Mem.mem result rows /\ Set.mem nd (support_snodes result) } in
4878
assert { no_scal c }
4879
in
4880
(* [rr] is zero iff the rows are false *)
4881
let lemma rbit (env: Node.t -> int) : unit
4882
ensures { value rr env = 0 <-> not (orl rs 0 (abs env)) }
4883
=
4884
row_bit_orl rs (abs env);
4885
if pure { orl rs 0 (abs env) } then begin
4886
let ghost k = any int ensures { 0 <= result /\ row_bit rs result (abs env) } in
4887
assert { bittest (value rr env) k }
4888
end else ext_bittest (value rr env) 0
4889
in
4890
(* the bits of [q] *)
4891
let lemma qbit (env: Node.t -> int) (p: int) : unit
4892
requires { 0 <= p }
4893
ensures { bittest (value q env) p <->
4894
(numbits p <= n_size /\
4895
match find_rel p rels with
4896
| Some g -> g.PBDD.v p (sem env p)
4897
| None -> bittest (env n) p
4898
end) }
4899
=
4900
if numbits p <= to_int n_size then begin
4901
if p > 0 then numbits_high_clear p (to_int n_size);
4902
assert { covers p 0 (n_size - 1) };
4903
assert { bittest (value q env) p <-> qb.PBDD.v p (sem env p) };
4904
assert { qb.PBDD.v p (sem env p) <->
4905
match find_rel p rels with
4906
| Some g -> g.PBDD.v p (sem env p)
4907
| None -> sem env p { SNode.n = n; SNode.s = (0:int63); SNode.scal = False }
4908
end };
4909
assert { sem env p { SNode.n = n; SNode.s = (0:int63); SNode.scal = False } <-> bittest (env n) p }
4910
end
4911
in
4912
(* the bit of a solved snode *)
4913
let lemma solk (env: Node.t -> int) (nd: snode) (f: PBDD.t) : unit
4914
requires { Mem.mem (nd, f) sols }
4915
ensures { bittest (value q env) nd.SNode.s <-> f.PBDD.v 0 (abs env) }
4916
=
4917
inl2 nd;
4918
numbits_lt_lsl (to_int nd.SNode.s) (to_int n_size);
4919
mem_mem_key sols nd f;
4920
mem_key_mem rels nd;
4921
let k = to_int nd.SNode.s in
4922
find_rel_mem k rels;
4923
qbit env k;
4924
match find_rel k rels with
4925
| None -> ()
4926
| Some g ->
4927
let ghost nd' = any snode ensures { Mem.mem (result, g) rels /\ to_int result.SNode.s = k } in
4928
let ghost f' = any PBDD.t ensures { Mem.mem (nd', result) sols /\
4929
forall env. g.PBDD.v nd'.SNode.s (sem env nd'.SNode.s) <-> result.PBDD.v 0 (abs env) } in
4930
mem_mem_key sols nd' f';
4931
inl2 nd';
4932
assert { nd' = nd };
4933
distinct_keys_uniq sols nd f f'
4934
end
4935
in
4936
let lemma indep (env: Node.t -> int) (x: int) : unit
4937
ensures { value rr (upd_env env n x) = value rr env }
4938
=
4939
let lemma same (nd: snode) : unit
4940
requires { in_rows rs nd }
4941
ensures { abs (upd_env env n x) nd = abs env nd }
4942
= if pure { nd.SNode.n = n } then inl nd
4943
in
4944
let lemma bit (p: int) : unit
4945
requires { 0 <= p }
4946
ensures { bittest (value rr (upd_env env n x)) p <-> bittest (value rr env) p }
4947
= row_bit_eq rs p pure { abs (upd_env env n x) } pure { abs env }
4948
in
4949
ext_bittest (value rr (upd_env env n x)) (value rr env)
4950
in
4951
let lemma sol (env: Node.t -> int) : unit
4952
requires { value rr env = 0 }
4953
ensures { value t (upd_env env n (value q env)) = 0 }
4954
=
4955
rbit env;
4956
let ghost env' = upd_env env n (value q env) in
4957
let lemma same (nd: snode) : unit
4958
requires { in_rows rows nd }
4959
ensures { subst_sn sols 0 (abs env) nd = abs env' nd }
4960
=
4961
subst_sn_mem sols 0 (abs env) nd;
4962
if pure { PBDD.mem_key nd sols } then begin
4963
let ghost f = any PBDD.t ensures { Mem.mem (nd, result) sols /\ subst_sn sols 0 (abs env) nd = result.PBDD.v 0 (abs env) } in
4964
solk env nd f;
4965
inl2 nd
4966
end
4967
in
4968
orl_eq rows 0 pure { subst_sn sols 0 (abs env) } pure { abs env' };
4969
assert { not (orl rows 0 (abs env')) }
4970
in
4971
let lemma repro (env: Node.t -> int) : unit
4972
requires { value t env = 0 }
4973
ensures { value rr env = 0 }
4974
ensures { 0 <= env n < lsl 1 (sizes n) -> value q env = env n }
4975
=
4976
rbit env;
4977
assert { not (orl rows 0 (abs env)) };
4978
if 0 <= env n && env n < Zbit.lsl 1 (to_int szn) then begin
4979
let lemma bit (p: int) : unit
4980
requires { 0 <= p }
4981
ensures { bittest (value q env) p <-> bittest (env n) p }
4982
=
4983
qbit env p;
4984
if numbits p <= to_int n_size then begin
4985
find_rel_mem p rels;
4986
match find_rel p rels with
4987
| None -> ()
4988
| Some g ->
4989
let ghost nd' = any snode ensures { Mem.mem (result, g) rels /\ to_int result.SNode.s = p } in
4990
mem_mem_key rels nd' g;
4991
mem_key_mem sols nd';
4992
let ghost f = any PBDD.t ensures { Mem.mem (nd', result) sols } in
4993
solk env nd' f;
4994
inl2 nd';
4995
qbit env p
4996
end
4997
end else begin
4998
numbits_lt_lsl (env n) (to_int szn);
4999
if env n > 0 then numbits_high_clear (env n) p
5000
end
5001
in
5002
ext_bittest (value q env) (env n)
5003
end
5004
in
5005
Subst n q rr
5006
end
5007
end
5008
end

The window sizes solved by Gauss–Jordan (one row per position)

5011
let constant
gj_max_size
: int63 = 12

c is the row of a position of t

5014
predicate
is_inst
(t: t) (c: PBDD.t) =
5015
exists p [t.bdd.PBDD.v p]. 0 <= p < lsl 1 t.size /\
5016
forall id sn. c.PBDD.v id sn <-> t.bdd.PBDD.v p (shifted sn (- p))
5017
Valid (874ms) (colibri2)
5018
let ghost
inst_intro
(t: t) (c: PBDD.t) (p: int) : unit
5019
requires { 0 <= p < lsl 1 t.size }
5020
requires { forall id sn. c.PBDD.v id sn <-> t.bdd.PBDD.v p (shifted sn (- p)) }
5021
ensures { is_inst t c }
5022
= let ghost _f = pure { t.bdd.PBDD.v p } in ()

rows are rows of the positions of t

5025
predicate
inst_rows
(t: t) (rows: list PBDD.t) = forall c. Mem.mem c rows -> is_inst t c

The rows of the positions 0 <= p < k of t, before acc

    Valid (406ms) (colibri2 22) (cvc4 2) (split_vc 2) (depth 2)
5028
let rec partial
instances
(t: t) (k: int63) (acc: list PBDD.t) : list PBDD.t
5029
requires { lsl 1 t.size <= Int63.max_int }
5030
requires { 0 <= k <= lsl 1 t.size }
5031
requires { good_rows acc /\ inst_rows t acc }
5032
requires { no_scal t.bdd -> forall c. Mem.mem c acc -> no_scal c }
5033
variant { k }
5034
ensures { good_rows result /\ inst_rows t result }
5035
ensures { no_scal t.bdd -> forall c. Mem.mem c result -> no_scal c }
5036
ensures { Length.length result = Length.length acc + k }
5037
ensures { forall env. orl result 0 (abs env) <->
5038
(orl acc 0 (abs env) \/ exists p. 0 <= p < k /\ t.bdd.PBDD.v p (sem env p)) }
5039
raises { Overflow -> exists nd p. Set.mem nd (support_snodes t.bdd) /\ 0 <= p < k /\
5040
not (in_bounds (to_int nd.s + p)) }
5041
=
5042
if k = 0 then acc
5043
else begin
5044
let c = instance t (k - 1) in
5045
let acc' = Cons c acc in
5046
inst_intro t c (to_int k - 1);
5047
let r = instances t (k - 1) acc' in
5048
let lemma pt (env: Node.t -> int) : unit
5049
ensures { orl r 0 (abs env) <->
5050
(orl acc 0 (abs env) \/ exists p. 0 <= p < k /\ t.bdd.PBDD.v p (sem env p)) }
5051
= assert { orl acc' 0 (abs env) <-> (c.PBDD.v 0 (abs env) \/ orl acc 0 (abs env)) }
5052
in
5053
r
5054
end

The value of t is not zero iff one of the rows of its positions is true

    Valid (937ms) (colibri2)
5058
let ghost
value_rows
(t: t) (rows: list PBDD.t) (env: Node.t -> int) : unit
5059
requires { orl rows 0 (abs env) <-> exists p. 0 <= p < lsl 1 t.size /\ t.bdd.PBDD.v p (sem env p) }
5060
ensures { orl rows 0 (abs env) <-> value t env <> 0 }
5061
=
5062
if pure { orl rows 0 (abs env) } then begin
5063
let ghost p = any int ensures { 0 <= result < lsl 1 t.size /\ t.bdd.PBDD.v result (sem env result) } in
5064
numbits_lt_lsl p (to_int t.size);
5065
assert { bittest (value t env) p }
5066
end else begin
5067
let lemma bit (p: int) : unit
5068
requires { 0 <= p }
5069
ensures { not (bittest (value t env) p) }
5070
= if numbits p <= to_int t.size then lt_lsl_of_numbits p (to_int t.size)
5071
in
5072
ext_bittest (value t env) 0
5073
end

solve of bddbitv.ml: Zero (t = 0), Unsat (t <> 0), Subst n q r (t = 0 solved for n: q gives n when r = 0), TryLater (no claim). Differs from bddbitv.ml: see solve_simple and solve_gj; TryLater for the sizes outside their bounds.

solve cannot solve t: a node read at one shift with a size or a shift out of the bounds, or (every node read at several shifts) a term that is too big or solve_gj fails on the rows of its positions

5083
predicate
solve_later
(sizes: Node.t -> int63) (t: t) =
5084
(exists sn. v t sn <> 0) /\
5085
(not (no_scal t.bdd) \/
5086
(exists nd. Set.mem nd (support_snodes t.bdd) /\
5087
(forall nd'. Set.mem nd' (support_snodes t.bdd) -> nd'.SNode.n = nd.SNode.n -> nd' = nd) /\
5088
not (t.size <= 60 /\ - 0x1000_0000_0000_0000 <= nd.SNode.s <= 0x1000_0000_0000_0000 /\
5089
0 <= sizes nd.SNode.n <= 0x2000_0000_0000_0000)) \/
5090
(t.size > gj_max_size \/
5091
exists rows. inst_rows t rows /\ gj_bad sizes rows))
5092
Valid (896ms) (colibri2 56) (cvc4 6) (cvc5 2) (split_vc 10) (depth 5)
5093
let partial
solve
(sizes: Node.t -> int63) (t: t) : solve
5094
ensures { match result with
5095
| Zero -> forall env. value t env = 0
5096
| Unsat -> forall env. value t env <> 0
5097
| Subst n q r ->
5098
(forall env x. value r (upd_env env n x) = value r env) /\
5099
(forall env. value r env = 0 -> value t (upd_env env n (value q env)) = 0) /\
5100
(forall env. value t env = 0 ->
5101
value r env = 0 /\ (0 <= env n < lsl 1 (sizes n) -> value q env = env n))
5102
| TryLater -> solve_later sizes t
5103
end }
5104
raises { Overflow -> (exists nd nd'. Set.mem nd (support_snodes t.bdd) /\
5105
Set.mem nd' (Set.add nd t.bdd.dom_snodes) /\ not nd'.scal /\ not (in_bounds (to_int nd'.s - nd.s))) \/
5106
(exists nd. Set.mem nd (support_snodes t.bdd) /\ not (in_bounds (lsl 1 t.size - 1 + nd.s))) }
5107
=
5108
if is_zero t then Zero
5109
else if has_scal_bdd t.bdd then begin
5110
assert { exists sn. v t sn <> 0 };
5111
TryLater
5112
end else match get_var_less_shift (PBDD.vars t.bdd) with
5113
| None ->
5114
assert { Set.is_empty (support_snodes t.bdd) };
5115
Unsat
5116
| Some (n, _, Cons nd Nil) ->
5117
let szn = sizes n in
5118
if t.size <= 60 && - 0x1000_0000_0000_0000 <= nd.s && nd.s <= 0x1000_0000_0000_0000
5119
&& 0 <= szn && szn <= 0x2000_0000_0000_0000 then begin
5120
assert { Set.mem nd (support_snodes t.bdd) };
5121
let (q, r) =
5122
try solve_simple t nd szn with Overflow ->
5123
assert { exists nd'. Set.mem nd' (Set.add nd t.bdd.dom_snodes) /\ not nd'.scal /\
5124
not (in_bounds (to_int nd'.s - nd.s)) };
5125
raise Overflow
5126
end in
5127
Subst n q r
5128
end else begin
5129
assert { Set.mem nd (support_snodes t.bdd) };
5130
assert { exists sn. v t sn <> 0 };
5131
assert { forall nd'. Set.mem nd' (support_snodes t.bdd) -> nd'.SNode.n = nd.SNode.n -> nd' = nd };
5132
TryLater
5133
end
5134
| Some _ ->
5135
if t.size <= gj_max_size then begin
5136
lsl_le_max_int (to_int t.size);
5137
let rows = instances t (Int63.lsl 1 t.size) Nil in
5138
let lemma vr (env: Node.t -> int) : unit
5139
ensures { orl rows 0 (abs env) <-> value t env <> 0 }
5140
= value_rows t rows env
5141
in
5142
lsl_le_2_60 (to_int t.size);
5143
let res = solve_gj sizes t rows in
5144
assert { exists sn. v t sn <> 0 };
5145
res
5146
end else begin
5147
assert { exists sn. v t sn <> 0 };
5148
TryLater
5149
end
5150
end
5151
5152
end