-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaxioms32.v
697 lines (564 loc) · 19.5 KB
/
axioms32.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
From Coq
Require Import ZArith.ZArith Extraction.
Require Import mathcomp.ssreflect.ssreflect.
From mathcomp Require Import ssrbool eqtype ssrnat seq fintype ssrfun tuple.
From Bits
Require Import bits.
(* TODO:
* Complete missing lemmas
* Fix invalid extractions (addition is wrong on 63bits arch, for instance)
* Define as a functor over wordsize (and forallInt) and
instanciate at 8, 16, and 32 bits
* Implement an efficient [forall] for bitvectors, prove
equivalence with finType's forall.
* Either get an efficient version of the tests below, or
implement them in OCaml
*)
(** * An axiomatization of OCaml native integers *)
Definition wordsize := 32.
Axiom Int32: Type.
Extract Inlined Constant Int32 => "int".
(* Our trusted computing base sums up in these two operations and
their associated reflection principles in Coq. *)
Axiom forallInt32 : (Int32 -> bool) -> bool.
Extract Inlined Constant forallInt32 => "Forall.forall_int32".
Axiom eq: Int32 -> Int32 -> bool.
Extract Inlined Constant eq => "(=)".
Section Trust.
(* Axiom 1: Equality of integer is embedded within Coq's propositional equality: *)
Axiom eqInt32P : Equality.axiom eq.
Definition viewP (P: pred Int32) (PP: Int32 -> Prop) := forall x, reflect (PP x) (P x).
(* Axiom 2: If a property is true for all integers, then it is propositionally true *)
Axiom forallInt32P : forall P PP,
viewP P PP ->
reflect (forall x, PP x) (forallInt32 (fun x => P x)).
End Trust.
(* All the axiomatized properties below are exhautively tested. *)
Axiom zero : Int32.
Extract Inlined Constant zero => "0".
Axiom one : Int32.
Extract Inlined Constant one => "1".
Axiom succ : Int32 -> Int32.
Extract Constant succ => "(fun x -> (x + 1) land 0xffffffff)".
Axiom lor: Int32 -> Int32 -> Int32.
Extract Inlined Constant lor => "(lor)".
Axiom lsl: Int32 -> Int32 -> Int32.
Extract Inlined Constant lsl => "(fun x y -> (x lsl y) land 0xffffffff)".
Axiom land: Int32 -> Int32 -> Int32.
Extract Inlined Constant land => "(land)".
Axiom lt: Int32 -> Int32 -> bool.
Extract Inlined Constant lt => "(<)".
Axiom lsr: Int32 -> Int32 -> Int32.
Extract Inlined Constant lsr => "(lsr)".
Axiom neg: Int32 -> Int32.
Extract Inlined Constant neg => "(fun x -> (-x) land 0xffffffff)".
Axiom lnot: Int32 -> Int32.
Extract Inlined Constant lnot => "(fun x -> (lnot x) land 0xffffffff)".
Axiom lxor: Int32 -> Int32 -> Int32.
Extract Inlined Constant lxor => "(lxor)".
Axiom dec: Int32 -> Int32.
Extract Constant dec => "(fun x -> (x - 1) land 0xffffffff)".
Axiom add: Int32 -> Int32 -> Int32.
Extract Inlined Constant add => "(fun x y -> (x + y) land 0xffffffff)".
(* Conversion between machine integers and bit vectors *)
Fixpoint PbitsToInt32 (p: seq bool): Int32 :=
match p with
| true :: p => lor one (lsl (PbitsToInt32 p) one)
| false :: p => lsl (PbitsToInt32 p) one
| [::] => zero
end.
Definition bitsToInt32 (bs: BITS wordsize): Int32 := PbitsToInt32 bs.
Fixpoint bitsFromInt32S (k: nat)(n: Int32): seq bool :=
match k with
| 0 => [::]
| k.+1 =>
let p := bitsFromInt32S k (lsr n one) in
(eq (land n one) one) :: p
end.
Lemma bitsFromInt32P {k} (n: Int32): size (bitsFromInt32S k n) == k.
Proof.
elim: k n => // [k IH] n //=.
rewrite eqSS //.
Qed.
Canonical bitsFromInt32 (n: Int32): BITS wordsize
:= Tuple (bitsFromInt32P n).
(** * Cancelation of [bitsToInt32] on [bitsFromInt32] *)
Definition bitsToInt32K_test: bool :=
[forall bs , bitsFromInt32 (bitsToInt32 bs) == bs ].
(* Validation condition:
Experimentally, [bitsToInt32] must be cancelled by [bitsFromInt32] *)
Axiom bitsToInt32K_valid: bitsToInt32K_test.
Lemma bitsToInt32K: cancel bitsToInt32 bitsFromInt32.
Proof.
move=> bs; apply/eqP; move: bs.
by apply/forallP: bitsToInt32K_valid.
Qed.
(** * Injectivity of [bitsFromInt32] *)
Definition bitsFromInt32_inj_test: bool :=
forallInt32 (fun x =>
forallInt32 (fun y =>
(bitsFromInt32 x == bitsFromInt32 y) ==> (eq x y))).
(* Validation condition:
Experimentally, [bitsFromInt32] must be injective *)
Axiom bitsFromInt32_inj_valid: bitsFromInt32_inj_test.
Lemma bitsFromInt32_inj: injective bitsFromInt32.
Proof.
move=> x y /eqP H.
apply/eqInt32P.
move: H; apply/implyP.
move: y; apply/(forallInt32P (fun y => (bitsFromInt32 x == bitsFromInt32 y) ==> eq x y)).
move=> y; apply idP.
move: x; apply/forallInt32P; last by apply bitsFromInt32_inj_valid.
move=> x; apply idP.
Qed.
Lemma bitsFromInt32K: cancel bitsFromInt32 bitsToInt32.
Proof.
apply: inj_can_sym; auto using bitsToInt32K, bitsFromInt32_inj.
Qed.
(** * Bijection [Int32] vs. [BITS wordsize] *)
Lemma bitsFromInt32_bij: bijective bitsFromInt32.
Proof.
split with (g := bitsToInt32);
auto using bitsToInt32K, bitsFromInt32K.
Qed.
(** * Representation relation *)
(** We say that an [n : Int32] is the representation of a bitvector
[bs : BITS ] if they satisfy the axiom [repr_native]. Morally, it
means that both represent the same number (ie. the same
booleans). *)
Definition native_repr (i: Int32)(bs: BITS wordsize): bool
:= eq i (bitsToInt32 bs).
(** * Representation lemma: equality *)
Lemma eq_adj: forall i bs, eq i (bitsToInt32 bs) = (bitsFromInt32 i == bs) .
Proof.
move=> i bs.
apply/eqInt32P/eqP; intro; subst;
auto using bitsFromInt32K, bitsToInt32K.
Qed.
Lemma eq_repr:
forall i i' bs bs',
native_repr i bs -> native_repr i' bs' ->
(eq i i') = (bs == bs').
Proof.
move=> i i' bs bs'.
rewrite /native_repr.
repeat (rewrite eq_adj; move/eqP=> <-).
apply/eqInt32P/eqP; intro; subst; auto using bitsFromInt32_inj.
Qed.
(** * Representation lemma: individuals *)
Definition zero_test: bool
:= eq zero (bitsToInt32 #0).
(* Validation condition:
bit vector [#0] corresponds to machine [0] *)
Axiom zero_valid: zero_test.
Lemma zero_repr: native_repr zero #0.
Proof. apply zero_valid. Qed.
Definition one_test: bool
:= eq one (bitsToInt32 #1).
(* Validation condition:
bit vector [#1] corresponds to machine [1] *)
Axiom one_valid: one_test.
Lemma one_repr: native_repr one #1.
Proof. apply one_valid. Qed.
(** * Representation lemma: successor *)
Definition succ_test: bool
:= forallInt32 (fun i =>
native_repr (succ i) (incB (bitsFromInt32 i))).
(* Validation condition:
[succ "n"] corresponds to machine [n + 1] *)
Axiom succ_valid: succ_test.
Lemma succ_repr: forall i bs,
native_repr i bs -> native_repr (succ i) (incB bs).
Proof.
move=> i ?.
rewrite /native_repr eq_adj.
move/eqP=> <-.
apply/eqInt32P.
move: i; apply/forallInt32P; last by apply succ_valid.
move=> x; apply/eqInt32P.
Qed.
(** * Representation lemma: negation *)
Definition lnot_test: bool
:= forallInt32 (fun i =>
native_repr (lnot i) (invB (bitsFromInt32 i))).
(* Validation condition:
[invB "n"] corresponds to machine [lnot n] *)
Axiom lnot_valid: lnot_test.
Lemma lnot_repr: forall i bs,
native_repr i bs -> native_repr (lnot i) (invB bs).
Proof.
move=> i ?.
rewrite /native_repr eq_adj.
move/eqP=> <-.
apply/eqInt32P.
move: i; apply/forallInt32P; last by apply lnot_valid.
move=> i; apply/eqInt32P.
Qed.
(** * Representation lemma: logical and *)
Definition land_test: bool
:= forallInt32 (fun i =>
forallInt32 (fun i' =>
native_repr (land i i') (andB (bitsFromInt32 i) (bitsFromInt32 i')))).
(* Validation condition:
[land "m" "n"] corresponds to machine [m land n] *)
Axiom land_valid: land_test.
Lemma land_repr: forall i i' bs bs',
native_repr i bs -> native_repr i' bs' ->
native_repr (land i i') (andB bs bs').
Proof.
move=> i i' ? ?.
repeat (rewrite /native_repr eq_adj; move/eqP=> <-).
apply/eqInt32P.
move: i'; apply/(forallInt32P (fun i' => eq (land i i') (bitsToInt32 (andB (bitsFromInt32 i) (bitsFromInt32 i'))))).
move=> i'; apply/eqInt32P.
move: i; apply/forallInt32P; last by apply land_valid.
move=> i'; apply idP.
Qed.
(** * Representation lemma: logical or *)
Definition lor_test: bool
:= forallInt32 (fun i =>
forallInt32 (fun i' =>
native_repr (lor i i') (orB (bitsFromInt32 i) (bitsFromInt32 i')))).
(* Validation condition:
[lor "m" "n"] corresponds to machine [m lor n] *)
Axiom lor_valid: lor_test.
Lemma lor_repr: forall i i' bs bs',
native_repr i bs -> native_repr i' bs' ->
native_repr (lor i i') (orB bs bs').
Proof.
move=> i i' ? ?.
repeat (rewrite /native_repr eq_adj; move/eqP=> <-).
apply/eqInt32P.
move: i'; apply/(forallInt32P (fun i' => eq (lor i i') (bitsToInt32 (orB (bitsFromInt32 i) (bitsFromInt32 i'))))).
move=> i'; apply/eqInt32P.
move: i; apply/forallInt32P; last by apply lor_valid.
move=> i'; apply idP.
Qed.
(** * Representation lemma: logical xor *)
Definition lxor_test: bool
:= forallInt32 (fun i =>
forallInt32 (fun i' =>
native_repr (lxor i i') (xorB (bitsFromInt32 i) (bitsFromInt32 i')))).
(* Validation condition:
[lxor "m" "n"] corresponds to machine [m lxor n] *)
Axiom lxor_valid: lxor_test.
Lemma lxor_repr: forall i i' bs bs',
native_repr i bs -> native_repr i' bs' ->
native_repr (lxor i i') (xorB bs bs').
Proof.
move=> i i' ? ?.
repeat (rewrite /native_repr eq_adj; move/eqP=> <-).
apply/eqInt32P.
move: i'; apply/(forallInt32P (fun i' => eq (lxor i i') (bitsToInt32 (xorB (bitsFromInt32 i) (bitsFromInt32 i'))))).
move=> i'; apply/eqInt32P.
move: i; apply/forallInt32P; last by apply lxor_valid.
move=> i'; apply idP.
Qed.
(** * Representation of naturals *)
(** We extend the refinement relation (by composition) to natural
numbers, going through a [BITS wordsize] word. *)
Definition natural_repr (i: Int32)(n: nat): bool :=
[exists bs, native_repr i bs && (# n == bs)].
(** * Representation lemma: logical shift right *)
Definition lsr_test: bool
:= forallInt32 (fun i =>
forallInt32 (fun i' =>
(toNat (bitsFromInt32 i') <= wordsize) ==> native_repr (lsr i i') (shrBn (bitsFromInt32 i) (toNat (bitsFromInt32 i'))))).
(* Validation condition:
[lsr "m" "n"] corresponds to machine [m lsr n] *)
Axiom lsr_valid: lsr_test.
Lemma lsr_repr: forall i j bs k, k <= wordsize ->
native_repr i bs -> natural_repr j k ->
native_repr (lsr i j) (shrBn bs k).
Proof.
move=> i i' ? k ltn_k.
rewrite /native_repr eq_adj; move/eqP=> <-.
rewrite /natural_repr.
move/existsP=> [bs' /andP [H /eqP H']].
rewrite /native_repr eq_adj in H.
move/eqP: H=> H.
apply/eqInt32P.
have Hk: k = toNat (bitsFromInt32 i').
rewrite H.
have ->: k = toNat (fromNat (n := wordsize) k).
rewrite toNat_fromNatBounded=> //.
by apply (leq_ltn_trans (n := wordsize)).
by rewrite H'.
rewrite Hk.
rewrite Hk in ltn_k.
clear H H' Hk.
move: i' ltn_k; apply/(forallInt32P (fun i' => (toNat (bitsFromInt32 i') <= wordsize) ==> (eq (lsr i i') (bitsToInt32 (shrBn (bitsFromInt32 i) (toNat ((bitsFromInt32 i')))))))).
move=> i'.
apply/equivP.
apply/implyP.
split=> H H'.
move: (H H')=> H''.
by apply/eqInt32P.
move: (H H')=> H''.
by apply/eqInt32P.
move: i; apply/forallInt32P; last by apply lsr_valid.
move=> i'; apply idP.
Qed.
(** * Representation lemma: logical shift left *)
Definition lsl_test: bool
:= forallInt32 (fun i =>
forallInt32 (fun i' =>
(toNat (bitsFromInt32 i') <= wordsize) ==> native_repr (lsl i i') (shlBn (bitsFromInt32 i) (toNat (bitsFromInt32 i'))))).
(* Validation condition:
[lsl "m" "n"] corresponds to machine [m lsl n] *)
Axiom lsl_valid: lsl_test.
Lemma lsl_repr: forall i j bs k, k <= wordsize ->
native_repr i bs -> natural_repr j k ->
native_repr (lsl i j) (shlBn bs k).
Proof.
move=> i i' ? k ltn_k.
rewrite /native_repr eq_adj; move/eqP=> <-.
rewrite /natural_repr.
move/existsP=> [bs' /andP [H /eqP H']].
rewrite /native_repr eq_adj in H.
move/eqP: H=> H.
apply/eqInt32P.
have Hk: k = toNat (bitsFromInt32 i').
rewrite H.
have ->: k = toNat (fromNat (n := wordsize) k).
rewrite toNat_fromNatBounded=> //.
by apply (leq_ltn_trans (n := wordsize)).
by rewrite H'.
rewrite Hk.
rewrite Hk in ltn_k.
clear H H' Hk.
move: i' ltn_k; apply/(forallInt32P (fun i' => (toNat (bitsFromInt32 i') <= wordsize) ==> (eq (lsl i i') (bitsToInt32 (shlBn (bitsFromInt32 i) (toNat ((bitsFromInt32 i')))))))).
move=> i'.
apply/equivP.
apply/implyP.
split=> H H'.
move: (H H')=> H''.
by apply/eqInt32P.
move: (H H')=> H''.
by apply/eqInt32P.
move: i; apply/forallInt32P; last by apply lsl_valid.
move=> i'; apply idP.
Qed.
(** * Representation lemma: negation *)
Definition neg_test: bool
:= forallInt32 (fun i =>
native_repr (neg i) (negB (bitsFromInt32 i))).
(* Validation condition:
[negB "m"] corresponds to machine [- m] *)
Axiom neg_valid: neg_test.
Lemma neg_repr: forall i bs,
native_repr i bs -> native_repr (neg i) (negB bs).
Proof.
move=> i ?.
rewrite /native_repr eq_adj.
move/eqP=> <-.
apply/eqInt32P.
move: i; apply/forallInt32P; last by apply neg_valid.
move=> i; apply/eqInt32P.
Qed.
(** * Representation lemma: decrement *)
Definition dec_test: bool
:= forallInt32 (fun i =>
native_repr (dec i) (decB (bitsFromInt32 i))).
(* Validation condition:
[decB "m"] corresponds to machine [dec m] *)
Axiom dec_valid: dec_test.
Lemma dec_repr: forall i bs,
native_repr i bs -> native_repr (dec i) (decB bs).
Proof.
move=> i ?.
rewrite /native_repr eq_adj.
move/eqP=> <-.
apply/eqInt32P.
move: i; apply/forallInt32P; last by apply dec_valid.
move=> i; apply/eqInt32P.
Qed.
(** * Representation lemma: addition *)
Definition add_test: bool
:= forallInt32 (fun i =>
forallInt32 (fun i' =>
native_repr (add i i') (addB (bitsFromInt32 i) (bitsFromInt32 i')))).
(* Validation condition:
[decB "m"] corresponds to machine [dec m] *)
Axiom add_valid: add_test.
Lemma add_repr:
forall i i' bs bs',
native_repr i bs -> native_repr i' bs' ->
native_repr (add i i') (addB bs bs').
Proof.
move=> i i' ? ?.
repeat (rewrite /native_repr eq_adj; move/eqP=> <-).
apply/eqInt32P.
move: i'; apply/(forallInt32P (fun i' => eq (add i i') (bitsToInt32 (addB (bitsFromInt32 i) (bitsFromInt32 i'))))).
move=> i'; apply/eqInt32P.
move: i; apply/forallInt32P; last by apply add_valid.
move=> i'; apply idP.
Qed.
(** Extract the tests: they should all return true! *)
Require Import ExtrOcamlBasic.
Definition allb s := foldr (andb) true s.
Definition binop_tests x bitsX y bitsY :=
allb
[:: (bitsX == bitsY) ==> (eq x y) ;
native_repr (land x y) (andB bitsX bitsY) ;
native_repr (lor x y) (orB bitsX bitsY) ;
native_repr (lxor x y) (xorB bitsX bitsY) ;
native_repr (add x y) (addB bitsX bitsY)].
Definition shift_tests x toNatX y bitsY :=
allb
[:: native_repr (lsr y x) (shrBn bitsY toNatX) ;
native_repr (lsl y x) (shlBn bitsY toNatX)].
Definition unop_tests x :=
let bitsX := bitsFromInt32 x in
let toNatX := toNat bitsX in
allb
[:: native_repr (succ x) (incB bitsX) ;
native_repr (lnot x) (invB bitsX) ;
native_repr (neg x) (negB bitsX) ;
native_repr (dec x) (decB bitsX) ;
if (toNatX <= wordsize) then
forallInt32 (fun y =>
let bitsY := bitsFromInt32 y in
(binop_tests x bitsX y bitsY) && (shift_tests x toNatX y bitsY))
else
forallInt32 (fun y => binop_tests x bitsX y (bitsFromInt32 y))].
Definition tests
:= allb
[:: bitsToInt32K_test ;
zero_test ;
one_test ;
forallInt32
(fun x => unop_tests x)].
Lemma implies_unop : tests -> forall x, unop_tests x.
move=> /andP [_ /andP [_ /andP[_ /andP [H _]]]] x.
rewrite /succ_test.
move: H=> /forallInt32P H.
move: (H unop_tests)=> H'.
apply H'=> x'.
by apply idP.
Qed.
Lemma implies_binop : tests -> forall x y, binop_tests x (bitsFromInt32 x) y (bitsFromInt32 y).
move => H x y.
have H': unop_tests x by apply implies_unop.
move: H'=> /andP [_ /andP [_ /andP [_ /andP [_ /andP [H1 _]]]]].
case Hc: (toNat (bitsFromInt32 x) <= wordsize); rewrite Hc in H1.
have Hb: (binop_tests x (bitsFromInt32 x) y (bitsFromInt32 y)) && (shift_tests x (toNat (bitsFromInt32 x)) y (bitsFromInt32 y)).
move: H1=> /forallInt32P H1.
move: (H1 (fun y => (binop_tests x (bitsFromInt32 x) y (bitsFromInt32 y)) && (shift_tests x (toNat (bitsFromInt32 x)) y (bitsFromInt32 y))))=> H2.
apply H2=> y'.
by apply idP.
by move: Hb=> /andP [-> _].
move: H1=> /forallInt32P H1.
move: (H1 (fun y => binop_tests x (bitsFromInt32 x) y (bitsFromInt32 y)))=> H2.
apply H2=> y'.
by apply idP.
Qed.
Lemma implies_bitsToInt32K : tests -> bitsToInt32K_test.
by move=> /andP [H _].
Qed.
Lemma implies_bitsFromInt32_inj : tests -> bitsFromInt32_inj_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
apply/forallInt32P=> y.
apply idP.
by move: (implies_binop H x y)=> /andP [-> _].
Qed.
Lemma implies_zero : tests -> zero_test.
by move=> /andP [_ /andP [H _]].
Qed.
Lemma implies_one : tests -> one_test.
by move=> /andP [_ /andP [_ /andP[H _]]].
Qed.
Lemma implies_succ : tests -> succ_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
have H': unop_tests x by apply implies_unop.
by move: H'=> /andP [H1 _].
Qed.
Lemma implies_lnot : tests -> lnot_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
have H': unop_tests x by apply implies_unop.
by move: H'=> /andP [_ /andP [H1 _]].
Qed.
Lemma implies_land : tests -> land_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
apply/forallInt32P=> y.
apply idP.
by move: (implies_binop H x y)=> /andP [_ /andP [-> _]].
Qed.
Lemma implies_lor : tests -> lor_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
apply/forallInt32P=> y.
apply idP.
by move: (implies_binop H x y)=> /andP [_ /andP [_ /andP [-> _]]].
Qed.
Lemma implies_lxor : tests -> lxor_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
apply/forallInt32P=> y.
apply idP.
by move: (implies_binop H x y)=> /andP [_ /andP [_ /andP [_ /andP [-> _]]]].
Qed.
Lemma implies_shift : tests -> forall x y, toNat (bitsFromInt32 x) <= wordsize -> shift_tests x (toNat (bitsFromInt32 x)) y (bitsFromInt32 y).
move => H x y Hlt.
move: (implies_unop H x)=> /andP [_ /andP [_ /andP [_ /andP [_ /andP [H1 _]]]]].
rewrite Hlt in H1.
have Hb: (binop_tests x (bitsFromInt32 x) y (bitsFromInt32 y)) && (shift_tests x (toNat (bitsFromInt32 x)) y (bitsFromInt32 y)).
move: H1=> /forallInt32P H1.
move: (H1 (fun y => (binop_tests x (bitsFromInt32 x) y (bitsFromInt32 y)) && (shift_tests x (toNat (bitsFromInt32 x)) y (bitsFromInt32 y))))=> H2.
apply H2=> y'.
by apply idP.
by move: Hb=> /andP [_ ->].
Qed.
Lemma implies_lsr : tests -> lsr_test.
move=> H.
apply/forallInt32P=> y.
apply idP.
apply/forallInt32P=> x.
apply idP.
apply/implyP=> H'.
by move: (implies_shift H x y H')=> /andP [-> _].
Qed.
Lemma implies_lsl : tests -> lsl_test.
move=> H.
apply/forallInt32P=> y.
apply idP.
apply/forallInt32P=> x.
apply idP.
apply/implyP=> H'.
by move: (implies_shift H x y H')=> /andP [_ /andP [-> _]].
Qed.
Lemma implies_neg : tests -> neg_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
have H': unop_tests x by apply implies_unop.
by move: H'=> /andP [_ /andP [_ /andP [H1 _]]].
Qed.
Lemma implies_dec : tests -> dec_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
have H': unop_tests x by apply implies_unop.
by move: H'=> /andP [_ /andP [_ /andP [_ /andP [H1 _]]]].
Qed.
Lemma implies_add : tests -> add_test.
move=> H.
apply/forallInt32P=> x.
apply idP.
apply/forallInt32P=> y.
apply idP.
by move: (implies_binop H x y)=> /andP [_ /andP [_ /andP [_ /andP [_ /andP [-> _]]]]].
Qed.
Cd "src/extraction".
Extraction "axioms32.ml" tests.
Cd "../..".