forked from CakeML/candle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHANGES
25877 lines (19008 loc) · 878 KB
/
CHANGES
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
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
* *****************************************************************
* NB: This CHANGES file no longer gives a comprehensive list of *
* changes made to the system. In particular, most changes in the *
* Multivariate theories are excluded, simply because there are *
* so many of them that tracking them would be tedious. For more *
* detailed update lists, consult the git logs ("git log" if you *
* have the system downloaded) or the list of commits on the Web *
* page: https://github.com/jrh13/hol-light/commits/master *
* *****************************************************************
Mon 1st Aug 2022 Library/words.ml
Added a straightforward variant of existing word lemmas:
REAL_VAL_WORD_XOR =
|- !x y.
&(val(word_xor x y)) =
(&(val x) + &(val y)) - &2 * &(val(word_and x y))
Wed 27th Jul 2022 tactics.ml, define.ml, meson.ml, Examples/holby.ml, Examples/mizar.ml, 100/e_is_transcendental.ml
Made "prove" explicitly check that the result does not include any
additional assumptions. This seems usually what is expected (if not
TAC_PROOF can be used directly). There were just a few places
where the original behavior was used essentially, and those have
been updated.
Mon 25th Jul 2022 EC/computegroup.ml
Slightly improved the efficiency of ECGROUP_MUL_CONV using a more
refined reduction strategy.
Mon 25th Jul 2022 pair.ml
Added SUBLET_CONV, to apply a conversion to the RHSs of the toplevel
let-term but neither expand it as with let_CONV nor apply the
conversion to the body, e.g.
# SUBLET_CONV NUM_ADD_CONV
`let x = 5 + 2 and y = 8 + 17 and z = 3 + 7 in x + y + z`;;
val it : thm =
|- (let x = 5 + 2 and y = 8 + 17 and z = 3 + 7 in x + y + z) =
(let x = 7 and y = 25 and z = 10 in x + y + z)
Tue 10th May 2022 EC/edwards448.ml [new file], Library/grouptheory.ml
Added a formalization of the "Goldilocks" curve edwards448, based on Mike
Hamburg's paper "Ed448-Goldilocks" (https://eprint.iacr.org/2015/625.pdf).
So far, we just have the Edwards form of it as in that paper. This is all
highly analogous to curve25519.ml, except that the group order computation
is a bit more involved: to avoid using a more refined Hasse-type bound
we need to do a bit of explicit analysis of the low-order points because
the group order is less than half of the very naive bound.
Also made a couple of trivial variable name tweaks to grouptheory.ml to
avoid name clashes with "decode" and "encode" when loaded with some other
theories.
Fri 22nd Apr 2022 GL/*
Added an update from Marco Maggesi and Cosimo Perini Brogi to their GL
provability logic theory. This now includes a decision procedure (GL_RULE
and GL_TAC) for the GL logic that will prove a valid formula or generate
a countermodel for an invalid one (stored in "!the_gl_countermodel").
This example, in the provability interpretation, corresponds to a
formalized Goedel's Second Incompleteness Theorem: if a system is
consistent it does not prove its own consistency. The file GL/decid.ml
has a number of applications of this kind:
# GL_RULE `|-- (Not (Box False) --> Not (Box (Not (Box False))))`;;
val it : thm = |- |-- (Not Box False --> Not Box Not Box False)
Wed 6th Apr 2022 EC/* [new directory], Examples/nist_curves.ml [deleted]
Replaced the increasingly unwieldy and poorly-named "nist_curves.ml"
file with a new directory "EC" (for Elliptic Curves) that develops
elliptic curve theory in a more systematic way, with separate files
for all the specific curves, as well as adding new material,
particularly around Edwards curves. The general short Weierstrass,
Montgomery and Edwards forms are defined and their properties derived
separately to minimize interdependencies, and here the only field
characteristic assumptions made are common or natural ones: char = 2
and char = 3 are excluded for short Weierstrass, just char = 2 is
excluded for Montgomery, and in principle there are no restrictions at
all on the Edwards theory (though "edwards_nonsingular" cannot be
satisfied in a *finite* field of characteristic 2 since then every
element is a square).
Wed 6th Apr 2022 lists.ml
Added a little clausal rewrite for BUTLAST:
BUTLAST_CLAUSES =
|- BUTLAST [] = [] /\
(!a. BUTLAST [a] = []) /\
(!a h t. BUTLAST(CONS a (CONS h t)) = CONS a (BUTLAST(CONS h t)))
Mon 4th Apr 2022 Library/ringtheory.ml
Fixed a prenormalization bug where RING_RULE and RING_TAC were not
handling the general case of "ring_of_num r n".
Fri 1st Apr 2022 Library/ringtheory.ml
Added a few more trivial theorems about terms involving inversion being
zero in a field and a handy collection of the various individual closure
properties (RING_ADD, RING_POW etc.) into a single clausal theorem:
FIELD_DIV_EQ_0 =
|- !f x y.
field f /\ x IN ring_carrier f /\ y IN ring_carrier f
==> (ring_div f x y = ring_0 f <=> x = ring_0 f \/ y = ring_0 f)
FIELD_INV_EQ_0 =
|- !f x.
field f /\ x IN ring_carrier f
==> (ring_inv f x = ring_0 f <=> x = ring_0 f)
RING_1_DIV =
|- !r x. x IN ring_carrier r ==> ring_div r (ring_1 r) x = ring_inv r x
RING_CLAUSES =
|- (!r. ring_0 r IN ring_carrier r) /\
(!r. ring_1 r IN ring_carrier r) /\
(!r n. ring_of_num r n IN ring_carrier r) /\
(!r x. x IN ring_carrier r ==> ring_neg r x IN ring_carrier r) /\
(!r x. x IN ring_carrier r ==> ring_inv r x IN ring_carrier r) /\
(!r x y.
x IN ring_carrier r /\ y IN ring_carrier r
==> ring_add r x y IN ring_carrier r) /\
(!r x y.
x IN ring_carrier r /\ y IN ring_carrier r
==> ring_sub r x y IN ring_carrier r) /\
(!r x y.
x IN ring_carrier r /\ y IN ring_carrier r
==> ring_mul r x y IN ring_carrier r) /\
(!r x y.
x IN ring_carrier r /\ y IN ring_carrier r
==> ring_div r x y IN ring_carrier r) /\
(!r x n. x IN ring_carrier r ==> ring_pow r x n IN ring_carrier r)
Tue 29th Mar 2022 Library/grouptheory.ml
Added a couple more lemmas about orders of powers in groups:
GROUP_ELEMENT_ORDER_EQ_MUL_GEN =
|- !G x k n.
x IN group_carrier G /\ ~(k = 0)
==> (group_element_order G x = k * n <=>
k divides group_element_order G x /\
group_element_order G (group_pow G x k) = n)
GROUP_ELEMENT_ORDER_EQ_MUL =
|- !G x k n.
x IN group_carrier G /\ ~(k = 0) /\ k divides n
==> (group_element_order G x = k * n <=>
group_element_order G (group_pow G x k) = n)
Wed 23rd Mar 2022 Library/ringtheory.ml
Added one more trivial rewrite that's handy to hide explicit case splits
over the trivial case of integers modulo:
IN_INTEGER_MOD_RING_CARRIER =
|- !n a.
a IN ring_carrier(integer_mod_ring n) <=>
&n = &0 \/ &0 <= a /\ a < &n
Wed 16th Mar 2022 Library/ringtheory.ml
Added some basic support for generic field automation to the ring theory,
adapted and extended from material already there in "nist_curves.ml".
This includes an elimination-based tactic FIELD_TAC as well as a more
directed "pull division terms up" tactic RING_PULL_DIV_TAC and its
contextual conversion RING_PULL_DIV_CONV, these based on the following
new clausal theorem:
|- !f. field f
==> (!x y n.
x IN ring_carrier f /\ y IN ring_carrier f
==> ring_pow f (ring_div f x y) n =
ring_div f (ring_pow f x n) (ring_pow f y n)) /\
(!x1 y1 x2 y2.
x1 IN ring_carrier f /\
x2 IN ring_carrier f /\
y1 IN ring_carrier f /\
y2 IN ring_carrier f
==> ring_div f (ring_div f x1 y1) (ring_div f x2 y2) =
ring_div f (ring_mul f x1 y2) (ring_mul f x2 y1)) /\
(!x1 x2 y.
x1 IN ring_carrier f /\
x2 IN ring_carrier f /\
y IN ring_carrier f /\
~(y = ring_0 f)
==> ring_add f (ring_div f x1 y) (ring_div f x2 y) =
ring_div f (ring_add f x1 x2) y /\
ring_sub f (ring_div f x1 y) (ring_div f x2 y) =
ring_div f (ring_sub f x1 x2) y /\
(ring_div f x1 y = ring_div f x2 y <=> x1 = x2) /\
ring_add f (ring_div f x1 y) x2 =
ring_div f (ring_add f x1 (ring_mul f x2 y)) y /\
ring_add f x1 (ring_div f x2 y) =
ring_div f (ring_add f (ring_mul f x1 y) x2) y /\
ring_sub f (ring_div f x1 y) x2 =
ring_div f (ring_sub f x1 (ring_mul f x2 y)) y /\
ring_sub f x1 (ring_div f x2 y) =
ring_div f (ring_sub f (ring_mul f x1 y) x2) y /\
ring_mul f (ring_div f x1 y) x2 =
ring_div f (ring_mul f x1 x2) y /\
ring_mul f x1 (ring_div f x2 y) =
ring_div f (ring_mul f x1 x2) y /\
(ring_div f x1 y = x2 <=> x1 = ring_mul f x2 y) /\
(x1 = ring_div f x2 y <=> ring_mul f x1 y = x2)) /\
(!x y.
x IN ring_carrier f /\
y IN ring_carrier f /\
~(x = ring_0 f) /\
~(y = ring_0 f)
==> ~(ring_mul f x y = ring_0 f)) /\
(!x n.
x IN ring_carrier f /\ ~(x = ring_0 f)
==> ~(ring_pow f x n = ring_0 f))
Wed 16th Mar 2022 Library/pocklington.ml
Removed some functions around primality proving from "nist_curves.ml" and
put them in the main "pocklington.ml" file, as well as filling out the
functions a bit. The new functions are:
general_certify_prime - Like certify_prime with any factorizing function
guided_certify_prime - Taking a set of hereditary sub-factors as a hint
extract_primes_from_certificate - Getting such sub-factor hints from number
GUIDED_PROVE_PRIME, PRIME_RULE - Proving primality with sub-factor hints
Mon 14th Mar 2022 Library/integer.ml
Did a bit of renaming to resolve a name clash with the core "int_coprime"
theorem from int.ml, renaming int_coprime -> INT_COPRIME and the former
INT_COPRIME -> INT_COPRIME_ALT in this file, so now:
int_coprime =
|- !a b. coprime(a,b) <=> (?x y. a * x + b * y = &1)
INT_COPRIME =
|- !a b.
coprime(a,b) <=> (!d. d divides a /\ d divides b ==> d divides &1)
INT_COPRIME_ALT =
|- !a b.
coprime(a,b) <=> (!d. d divides a /\ d divides b <=> d divides &1)
Fri 11th Mar 2022 Library/ringtheory.ml
Added a few more handy facts about "integer_mod_ring", as well
as defining the ring/field of real numbers explicitly as a ring
structure and proving the usual facts about that too:
real_ring =
|- real_ring = ring ((:real),&0,&1,(--),(+),(*))
FIELD_REAL_RING =
|- field real_ring
INTEGER_MOD_RING_CARRIER_REM =
|- !n x. x rem &n IN ring_carrier (integer_mod_ring n)
INTEGER_MOD_RING_CLAUSES =
|- ring_carrier (integer_mod_ring 0) = (:int) /\
(!n. 0 < n
==> ring_carrier (integer_mod_ring n) = {m | &0 <= m /\ m < &n}) /\
(!n. ring_0 (integer_mod_ring n) = &0) /\
(!n. ring_1 (integer_mod_ring n) = &1 rem &n) /\
(!n. ring_neg (integer_mod_ring n) = (\a. --a rem &n)) /\
(!n. ring_add (integer_mod_ring n) = (\a b. (a + b) rem &n)) /\
(!n. ring_sub (integer_mod_ring n) = (\a b. (a - b) rem &n)) /\
(!n. ring_mul (integer_mod_ring n) = (\a b. (a * b) rem &n)) /\
(!n. ring_pow (integer_mod_ring n) = (\a k. a pow k rem &n)) /\
(!n. ring_of_num (integer_mod_ring n) = (\k. &k rem &n)) /\
(!n. ring_of_int (integer_mod_ring n) = (\x. x rem &n))
INTEGER_MOD_RING_SUB =
|- !n. ring_sub (integer_mod_ring n) = (\a b. (a - b) rem &n)
INTEGRAL_DOMAIN_REAL_RING =
|- integral_domain real_ring
REAL_FIELD_CLAUSES =
|- ring_carrier real_ring = (:real) /\
ring_0 real_ring = &0 /\
ring_1 real_ring = &1 /\
ring_neg real_ring = (--) /\
ring_add real_ring = (+) /\
ring_mul real_ring = (*) /\
ring_of_num real_ring = & /\
ring_sub real_ring = (-) /\
ring_inv real_ring = inv /\
ring_div real_ring = (/) /\
ring_pow real_ring = (pow)
REAL_RING_CHAR =
|- ring_char real_ring = 0
REAL_RING_CLAUSES =
|- ring_carrier real_ring = (:real) /\
ring_0 real_ring = &0 /\
ring_1 real_ring = &1 /\
ring_neg real_ring = (--) /\
ring_add real_ring = (+) /\
ring_mul real_ring = (*)
REAL_RING_DIV =
|- ring_div real_ring = (/)
REAL_RING_INV =
|- ring_inv real_ring = inv
REAL_RING_OF_INT =
|- ring_of_int real_ring = real_of_int
REAL_RING_OF_NUM =
|- ring_of_num real_ring = &
REAL_RING_POW =
|- ring_pow real_ring = (pow)
REAL_RING_SUB =
|- ring_sub real_ring = (-)
Fri 4th Mar 2022 Examples/nist_curves.ml
Added a formalization of curve25519, and Montgomery curves in general,
to the increasingly inaccurately-named "nist_curves.ml" file. Mainly
for ease of re-use of the existing short Weierstrass material, the
properties of Montgomery operations are first derived from their
Weierstrass versions via the standard mapping, even defining the
"wei25519" curve as the short Weierstrass variant (nomenclature taken
from Struik's "Alternative Elliptic Curve Representations"). After
that, all the usual things are proved about curve25519, including the
y-free doubling and differential addition operations (following
Bernstein and Lange, "Montgomery cuves and the Montgomery ladder") and
a y-recovery formula (from Okeya and Sakurai). Also filled out the
earlier curve material with some additional facts, most interestingly
a standard easily computable endomorphism of secp256k1.
Thu 24th Feb 2022 Library/grouptheory.ml
Added this somewhat technical lemma which is handy for explicitly
creating a group as an isomorphic image and not then doing a
separate proof of group-ness and the isomorphism with the original:
CREATE_ISOMORPHIC_COPY_OF_GROUP =
|- !f g G s z i m.
z IN s /\
(!x. x IN group_carrier G ==> f x IN s /\ g (f x) = x) /\
(!y. y IN s ==> g y IN group_carrier G /\ f (g y) = y) /\
g z = group_id G /\
(!x. x IN s ==> i x = f (group_inv G (g x))) /\
(!x y. x IN s /\ y IN s ==> m x y = f (group_mul G (g x) (g y)))
==> group_isomorphisms (G,group (s,z,i,m)) (f,g) /\
group_carrier (group (s,z,i,m)) = s /\
group_id (group (s,z,i,m)) = z /\
group_inv (group (s,z,i,m)) = i /\
group_mul (group (s,z,i,m)) = m
Wed 23rd Feb 2022 Library/ringtheory.ml
Added an explicit conversion INTEGER_MOD_RING_RED_CONV for computing
terms in "integer_mod_ring n" (for nonzero n, the case of n = 0 being
just the integers anyway). This also adds the theorem:
RING_INV_INTEGER_MOD_RING =
|- !n a.
ring_inv (integer_mod_ring n) (&a) =
(if (n = 0 \/ ~(n = 1) /\ a < n) /\ coprime(a,n)
then &(inverse_mod n a) else &0)
This introduces a dependency on the Library/pocklington.ml file for
some additional material about "inverse_mod".
Wed 23rd Feb 2022 calc_num.ml, int.ml, Library/pocklington.ml
Moved EXP_MOD_CONV from "Library/pocklington.ml" into the core (in the
process slightly improving the implementation) and added an analogous
integer form INT_POW_REM_CONV.
Wed 23rd Feb 2022 Library/pocklington.ml
Added INVERSE_MOD_CONV, an explicit calculation conversion for modular
inverse terms of the form `inverse_mod m n` for numerals m and n.
Tue 7th Dec 2021 Library/words.ml
Added one more little missing lemma:
BIT_WORD_BITVAL =
|- !b i. bit i (word(bitval b):N word) <=> i = 0 /\ b
Thu 25th Nov 2021 Examples/nist_curves.ml
Added the other SECG curves defined over prime order fields: secp192k1,
secp224k1 and secp256k1 (the Bitcoin curve). This extends the existing
NIST curve material with the same verification of basic data like
number of points on the curve, and adds some possible computational
formulas in projective and Jacobian coordinates for Weierstrass curves
like these with a = 0.
Wed 10th Nov 2021 Library/words.ml
Added a new construct "bits_of_num" analogous to "bits_of_word" but
for actual numbers not words. The suite of theorems about it helps
with some kinds of "effectively bitwise" reasoning on natural numbers
such as pushing division and modulus w.r.t. powers of 2 through sums
based on the intuition that the bit patterns are not overlapping
(DIV_MOD_DISJOINT_BITS, DISJOINT_BITS_CLAUSES)
bits_of_num =
|- !n. bits_of_num n = {i | numbit i n}
BITSUM_BOUND =
|- !s k.
FINITE s
==> (nsum s (\i. 2 EXP i) < 2 EXP k <=> s SUBSET {i | i < k})
BITSUM_DIVIDES =
|- !s k.
FINITE s
==> (2 EXP k divides nsum s (\i. 2 EXP i) <=>
DISJOINT {i | i < k} s)
BITS_OF_NUM_0 =
|- bits_of_num 0 = {}
BITS_OF_NUM_1 =
|- bits_of_num 1 = {0}
BITS_OF_NUM_ADD =
|- !m n.
DISJOINT (bits_of_num m) (bits_of_num n)
==> bits_of_num(m + n) = bits_of_num m UNION bits_of_num n
BITS_OF_NUM_DISJOINT_NUMSEG_EQ =
|- !n k. DISJOINT {i | i < k} (bits_of_num n) <=> 2 EXP k divides n
BITS_OF_NUM_DIV =
|- !n k. bits_of_num(n DIV 2 EXP k) = {i | k + i IN bits_of_num n}
BITS_OF_NUM_EQ =
|- !m n. bits_of_num m = bits_of_num n <=> m = n
BITS_OF_NUM_GALOIS =
|- !n s. bits_of_num n = s <=> FINITE s /\ nsum s (\i. 2 EXP i) = n
BITS_OF_NUM_MOD =
|- !n k. bits_of_num(n MOD 2 EXP k) = {i | i IN bits_of_num n /\ i < k}
BITS_OF_NUM_MUL =
|- (!n k. bits_of_num(2 EXP k * n) = IMAGE (\i. k + i) (bits_of_num n)) /\
(!n k. bits_of_num(n * 2 EXP k) = IMAGE (\i. k + i) (bits_of_num n))
BITS_OF_NUM_MUL_ALT =
|- (!n k.
bits_of_num(2 EXP k * n) =
{i | k <= i /\ i - k IN bits_of_num n}) /\
(!n k.
bits_of_num(n * 2 EXP k) =
{i | k <= i /\ i - k IN bits_of_num n})
BITS_OF_NUM_NSUM =
|- !s. FINITE s ==> bits_of_num(nsum s (\i. 2 EXP i)) = s
BITS_OF_NUM_POW2 =
|- !k. bits_of_num(2 EXP k) = {k}
BITS_OF_NUM_SUBSET_NUMSEG_EQ =
|- !n k. bits_of_num n SUBSET {i | i < k} <=> n < 2 EXP k
BITS_OF_NUM_SUBSET_NUMSEG_LT =
|- !n. bits_of_num n SUBSET {i | i < n}
BITS_OF_NUM_VAL =
|- !x. bits_of_num(val x) = bits_of_word x
BITS_OF_WORD_WORD =
|- !n. bits_of_word (word n) = {i | i < dimindex (:N)} INTER bits_of_num n
DISJOINT_BITS_CLAUSES =
|- (!k h l.
l < 2 EXP k
==> DISJOINT (bits_of_num(2 EXP k * h)) (bits_of_num l)) /\
(!k h l.
l < 2 EXP k
==> DISJOINT (bits_of_num(h * 2 EXP k)) (bits_of_num l)) /\
(!k h l.
l < 2 EXP k
==> DISJOINT (bits_of_num l) (bits_of_num(2 EXP k * h))) /\
(!k h l.
l < 2 EXP k
==> DISJOINT (bits_of_num l) (bits_of_num(h * 2 EXP k))) /\
(!m n k.
DISJOINT (bits_of_num m) (bits_of_num n)
==> DISJOINT (bits_of_num(2 EXP k * m))
(bits_of_num(2 EXP k * n))) /\
(!m n k.
DISJOINT (bits_of_num m) (bits_of_num n)
==> DISJOINT (bits_of_num(m * 2 EXP k))
(bits_of_num(n * 2 EXP k))) /\
(!m n k.
DISJOINT (bits_of_num m) (bits_of_num n)
==> DISJOINT (bits_of_num(m DIV 2 EXP k))
(bits_of_num(n DIV 2 EXP k))) /\
(!m n k.
DISJOINT (bits_of_num m) (bits_of_num n)
==> DISJOINT (bits_of_num(m MOD 2 EXP k))
(bits_of_num(n MOD 2 EXP k)))
DISJOINT_BITS_HILO =
|- !k h l.
l < 2 EXP k ==> DISJOINT (bits_of_num(2 EXP k * h)) (bits_of_num l)
DIV_MOD_DISJOINT_BITS =
|- (!m n.
DISJOINT (bits_of_num m) (bits_of_num n)
==> (m + n) DIV 2 EXP k = m DIV 2 EXP k + n DIV 2 EXP k) /\
(!m n.
DISJOINT (bits_of_num m) (bits_of_num n)
==> (m + n) MOD 2 EXP k = m MOD 2 EXP k + n MOD 2 EXP k)
FINITE_BITS_OF_NUM =
|- !n. FINITE (bits_of_num n)
IN_BITS_OF_NUM =
|- !n i. i IN bits_of_num n <=> ODD (n DIV 2 EXP i)
NSUM_BITS_DIV =
|- !s k.
FINITE s
==> nsum s (\i. 2 EXP i) DIV 2 EXP k =
nsum {i | i IN s /\ k <= i} (\i. 2 EXP (i - k))
NSUM_BITS_EQ =
|- !s t.
FINITE s /\ FINITE t
==> (nsum s (\i. 2 EXP i) = nsum t (\i. 2 EXP i) <=> s = t)
NSUM_BITS_MOD =
|- !s k.
FINITE s
==> nsum s (\i. 2 EXP i) MOD 2 EXP k =
nsum {i | i IN s /\ i < k} (\i. 2 EXP i)
NSUM_BITS_OF_NUM =
|- !n. nsum (bits_of_num n) (\i. 2 EXP i) = n
Tue 9th Nov 2021 int.ml, real.ml, Library/words.ml
Added a few miscelleneous lemmas:
IVAL_WORD_CONG =
|- !n. (ival (word n) == &n) (mod (&2 pow dimindex(:N)))
MULT_DIV =
|- (!m n p. p divides m ==> (m * n) DIV p = m DIV p * n) /\
(!m n p. p divides n ==> (m * n) DIV p = m * n DIV p)
REAL_OF_NUM_DIV =
|- !m n. &(m DIV n) = &m / &n - &(m MOD n) / &n
VAL_WORD_AND_NOT_MASK_WORD =
|- !x k.
val (word_and x (word_not (word(2 EXP k - 1)))) =
2 EXP k * val x DIV 2 EXP k
WORD_AND_MASK_WORDS =
|- !i j.
word_and (word(2 EXP j - 1)) (word(2 EXP k - 1)) =
word(2 EXP MIN j k - 1)
WORD_AND_NOT_MASK_WORD =
|- (!x k.
word_and x (word_not (word(2 EXP k - 1))) =
word(2 EXP k * val x DIV 2 EXP k)) /\
(!x k.
word_and (word_not (word(2 EXP k - 1))) x =
word(2 EXP k * val x DIV 2 EXP k))
WORD_OR_MASK_WORDS =
|- !i j.
word_or (word(2 EXP j - 1)) (word(2 EXP k - 1)) =
word(2 EXP MAX j k - 1)
WORD_USHR_MASK_WORD =
|- !k i.
k <= dimindex(:N)
==> word_ushr (word(2 EXP k - 1)) i = word(2 EXP (k - i) - 1)
Fri 5th Nov 2021 Library/words.ml
Added more word lemmas, mainly connected with selecting trailing bits and
emulating ctz in terms of clz, very much in line with material in
the "Manipulating Rightmost Bits" section of "Hacker's Delight":
BIT_WORD_XOR_ADD_1 =
|- !x i.
bit i (word_xor x (word_add x (word 1))) <=>
i < dimindex(:N) /\ (!j. j < i ==> bit j x)
BIT_WORD_XOR_NEG =
|- !x i.
bit i (word_xor x (word_neg x)) <=>
i < dimindex(:N) /\ (?j. j < i /\ bit j x)
BIT_WORD_XOR_SUB_1 =
|- !x i.
bit i (word_xor x (word_sub x (word 1))) <=>
i < dimindex(:N) /\ (!j. j < i ==> ~bit j x)
WORD_AND_NEG_CTZ =
|- !x. word_and x (word_neg x) = word_of_bits {word_ctz x}
WORD_AND_NOT_SUB_1_CTZ =
|- !x. word_and (word_not x) (word_sub x (word 1)) =
word(2 EXP word_ctz x - 1)
WORD_CLZ_BIT =
|- !k. word_clz (word_of_bits {k}) =
(if k < dimindex(:N) then dimindex(:N) - 1 - k else dimindex(:N))
WORD_CLZ_MASK_WORD =
|- !k. word_clz (word(2 EXP k - 1)) = dimindex(:N) - k
WORD_CTZ_BIT =
|- !k. word_ctz (word_of_bits {k}) = MIN k (dimindex(:N))
WORD_CTZ_EMULATION_AND_NEG =
|- !x. word_ctz x =
(if x = word 0
then dimindex(:N)
else dimindex(:N) - 1 - word_clz (word_and x (word_neg x)))
WORD_CTZ_EMULATION_AND_NEG_REV =
|- !x. word_clz (word_and x (word_neg x)) =
(if x = word 0
then dimindex(:N)
else dimindex(:N) - 1 - word_ctz x)
WORD_CTZ_EMULATION_XOR_SUB_1 =
|- !x. word_ctz x =
(if x = word 0
then dimindex(:N)
else dimindex(:N) -
1 -
word_clz (word_xor x (word_sub x (word 1))))
WORD_CTZ_EMULATION_XOR_SUB_1_REV =
|- !x. word_clz (word_xor x (word_sub x (word 1))) =
dimindex(:N) - 1 - word_ctz x
WORD_CTZ_MASK_WORD =
|- !k. word_ctz (word(2 EXP k - 1)) = (if k = 0 then dimindex(:N) else 0)
WORD_XOR_SUB_1_CTZ =
|- !x. word_xor x (word_sub x (word 1)) = word(2 EXP (word_ctz x + 1) - 1)
Tue 2nd Nov 2021 Library/words.ml
Added missing conversions WORD_JROL_CONV and WORD_JROR_CONV (for
word-word rotate operations) and included them in WORD_RED_CONV
and hence WORD_REDUCE_CONV.
Mon 1st Nov 2021 parser.ml
Fixed a trivial typo in the error message "closing square bracket
of list expected".
Tue 12th Oct 2021 Library/words.ml
Added a couple more word lemmas about pushing logical complements through
other constructs; the side-conditions make them a bit ugly but they can be
useful:
WORD_JOIN_NOT =
|- !v w.
dimindex(:P) <= dimindex(:M) + dimindex(:N)
==> word_join (word_not v) (word_not w) = word_not (word_join v w)
WORD_SUBWORD_NOT =
|- !x pos len.
dimindex(:N) <= len /\ pos + len <= dimindex(:M)
==> word_subword (word_not x) (pos,len) =
word_not (word_subword x (pos,len))
Sat 9th Oct 2021 Library/words.ml
Added a few more elementary word lemmas like a simple upper bound on
a concrete masking of a word:
VAL_WORD_AND_LE =
|- (!x y. val (word_and x y) <= val x) /\
(!x y. val (word_and x y) <= val y)
VAL_WORD_AND_LE_MIN =
|- !x y. val (word_and x y) <= MIN (val x) (val y)
VAL_WORD_AND_WORD_LE =
|- (!x n. val (word_and x (word n)) <= n) /\
(!x n. val (word_and (word n) x) <= n)
VAL_WORD_OR_LE_MAX =
|- !x y. MAX (val x) (val y) <= val (word_or x y)
Fri 8th Oct 2021 int.ml
Added a systematic set of missing analogs of real theorems for ints:
INT_ABS_BOUNDS : thm =
|- !x k. abs x <= k <=> --k <= x /\ x <= k
INT_EQ_LCANCEL_IMP : thm =
|- !x y z. ~(z = &0) /\ z * x = z * y ==> x = y
INT_EQ_RCANCEL_IMP : thm =
|- !x y z. ~(z = &0) /\ x * z = y * z ==> x = y
INT_LE_LCANCEL_IMP : thm =
|- !x y z. &0 < x /\ x * y <= x * z ==> y <= z
INT_LE_POW_2 : thm =
|- !x. &0 <= x pow 2
INT_LE_RCANCEL_IMP : thm =
|- !x y z. &0 < z /\ x * z <= y * z ==> x <= y
INT_LE_RMUL_EQ : thm =
|- !x y z. &0 < z ==> (x * z <= y * z <=> x <= y)
INT_LT_LADD_IMP : thm =
|- !x y z. y < z ==> x + y < x + z
INT_LT_LCANCEL_IMP : thm =
|- !x y z. &0 < x /\ x * y < x * z ==> y < z
INT_LT_LMUL : thm =
|- !x y z. &0 < x /\ y < z ==> x * y < x * z
INT_LT_LNEG : thm =
|- !x y. --x < y <=> &0 < x + y
INT_LT_POW_2 : thm =
|- !x. &0 < x pow 2 <=> ~(x = &0)
INT_LT_RCANCEL_IMP : thm =
|- !x y z. &0 < z /\ x * z < y * z ==> x < y
INT_LT_RMUL : thm =
|- !x y z. x < y /\ &0 < z ==> x * z < y * z
INT_LT_RNEG : thm =
|- !x y. x < --y <=> x + y < &0
INT_LT_SQUARE : thm =
|- !x. &0 < x * x <=> ~(x = &0)
INT_OF_NUM_SUB_CASES : thm =
|- !m n. &m - &n = (if n <= m then &(m - n) else -- &(n - m))
INT_POS_EQ_SQUARE : thm =
|- !x. &0 <= x <=> (?y. y pow 2 = real_of_int x)
INT_POW_EQ_1 : thm =
|- !x n. x pow n = &1 <=> abs x = &1 /\ (x < &0 ==> EVEN n) \/ n = 0
INT_POW_EQ_1_IMP : thm =
|- !x n. ~(n = 0) /\ x pow n = &1 ==> abs x = &1
INT_POW_EQ_EQ : thm =
|- !n x y.
x pow n = y pow n <=>
(if EVEN n then n = 0 \/ abs x = abs y else x = y)
INT_POW_EQ_ODD : thm =
|- !n x y. ODD n /\ x pow n = y pow n ==> x = y
INT_POW_EQ_ODD_EQ : thm =
|- !n x y. ODD n ==> (x pow n = y pow n <=> x = y)
INT_POW_LBOUND : thm =
|- !x n. &0 <= x ==> &1 + &n * x <= (&1 + x) pow n
INT_POW_LE2_ODD_EQ : thm =
|- !n x y. ODD n ==> (x pow n <= y pow n <=> x <= y)
INT_POW_LT2_ODD : thm =
|- !n x y. x < y /\ ODD n ==> x pow n < y pow n
INT_POW_LT2_ODD_EQ : thm =
|- !n x y. ODD n ==> (x pow n < y pow n <=> x < y)
Fri 8th Oct 2021 real.ml, int.ml
Added integer and real forms of this simple lemma:
INT_EVENPOW_ABS =
|- !x n. EVEN n ==> abs x pow n = x pow n
REAL_EVENPOW_ABS =
|- !x n. EVEN n ==> abs x pow n = x pow n
Wed 6th Oct 2021 int.ml
Added a natural integer analog of MOD_UNIQUE:
INT_REM_UNIQUE =
|- !m n p.
m rem n = p <=>
(n = &0 /\ m = p \/ &0 <= p /\ p < abs n) /\ (m == p) (mod n)
Tue 5th Oct 2021 Library/words.ml
Added a few trivial theorems about unsigned word max/min:
WORD_UMAX =
|- !x y. word_umax x y = (if val x <= val y then y else x)
WORD_UMAX_ASSOC =
|- !x y z. word_umax x (word_umax y z) = word_umax (word_umax x y) z
WORD_UMAX_SYM =
|- !x y. word_umax x y = word_umax y x
WORD_UMIN =
|- !x y. word_umin x y = (if val x <= val y then x else y)
WORD_UMIN_ASSOC =
|- !x y z. word_umin x (word_umin y z) = word_umin (word_umin x y) z
WORD_UMIN_SYM =
|- !x y. word_umin x y = word_umin y x
Fri 20th Aug 2021 Library/words.ml
Added three more word lemmas connecting shifts and subwords:
WORD_SHL_SUBWORD =
|- !x d l.
dimindex(:N) <= l + d
==> word_shl (word_subword x (0,l)) d = word_shl x d
WORD_SUBWORD_AS_USHR =
|- !x k l. dimindex(:N) <= k + l ==> word_subword x (k,l) = word_ushr x k
WORD_USHR_AS_SUBWORD =
|- !x k. word_ushr x k = word_subword x (k,dimindex(:N) - k)
Fri 30th Jul 2021 Library/words.ml
Made the trivial generalization to WORD_ARITH / WORD_ARITH_TAC of also
breaking apart conjunctions at the start. Added these lemmas
characterizing exactness of additions or additions-with-carry in terms
of a later word comparison on the result, all of which are just
proved automatically by WORD_ARITH_TAC.
WORD_ADC_LE_EXACT =
|- (!x y.
val(word_add (word_add x y) (word 1)) <= val x <=>
val(word_add (word_add x y) (word 1)) + 2 EXP dimindex(:N) =
val x + val y + 1) /\
(!x y.
val(word_add (word_add x y) (word 1)) <= val y <=>
val(word_add (word_add x y) (word 1)) + 2 EXP dimindex(:N) =
val x + val y + 1)
WORD_ADC_LE_INEXACT =
|- (!x y.
val(word_add (word_add x y) (word 1)) <= val x <=>
~(val(word_add (word_add x y) (word 1)) = val x + val y + 1)) /\
(!x y.
val(word_add (word_add x y) (word 1)) <= val y <=>
~(val(word_add (word_add x y) (word 1)) = val x + val y + 1))
WORD_ADD_LT_EXACT =
|- (!x y.
val(word_add x y) < val x <=>
val(word_add x y) + 2 EXP dimindex(:N) = val x + val y) /\
(!x y.
val(word_add x y) < val y <=>
val(word_add x y) + 2 EXP dimindex(:N) = val x + val y)
WORD_ADD_LT_INEXACT =
|- (!x y.
val(word_add x y) < val x <=>
~(val(word_add x y) = val x + val y)) /\
(!x y.
val(word_add x y) < val y <=>
~(val(word_add x y) = val x + val y))
WORD_LE_ADD_EXACT =
|- (!x y.
val x <= val(word_add x y) <=> val(word_add x y) = val x + val y) /\
(!x y.
val y <= val(word_add x y) <=> val(word_add x y) = val x + val y)
WORD_LT_ADC_EXACT =
|- (!x y.
val x < val(word_add (word_add x y) (word 1)) <=>
val(word_add (word_add x y) (word 1)) = val x + val y + 1) /\
(!x y.
val y < val(word_add (word_add x y) (word 1)) <=>
val(word_add (word_add x y) (word 1)) = val x + val y + 1)
Wed 28th Jul 2021 Library/words.ml
Added two more simple word lemmas (the de Morgan laws in this setting)
WORD_NOT_AND =
|- !x y. word_not (word_and x y) = word_or (word_not x) (word_not y)
WORD_NOT_OR =
|- !x y. word_not (word_or x y) = word_and (word_not x) (word_not y)
Tue 20th Jul 2021 Library/words.ml
Added another couple of elementary lemmas about AND with a word
consisting of a single bit expressed as a power of 2.
VAL_WORD_AND_POW2 =
|- (!x k. val(word_and x (word(2 EXP k))) = 2 EXP k * bitval(bit k x)) /\
(!x k. val(word_and (word(2 EXP k)) x) = 2 EXP k * bitval(bit k x))
WORD_AND_POW2 =
|- (!x k. word_and x (word(2 EXP k)) = word(2 EXP k * bitval(bit k x))) /\
(!x k. word_and (word(2 EXP k)) x = word(2 EXP k * bitval(bit k x)))
Fri 16th Jul 2021 Library/words.ml
Added one more little word lemma that zero-extension of a 1-bit
Boolean value is trivial:
WORD_ZX_BITVAL = |- !b. word_zx(word(bitval b)) = word(bitval b)
Wed 7th Jul 2021 Library/words.ml
Added a few miscellaneous word theorems with an emphasis on commuting
word_zx, mainly as a shortening, through other word operations:
BIT_GUARD =
|- !x i. bit i x <=> i < dimindex(:N) /\ bit i x
VAL_WORD_SUBWORD_DIMINDEX =
|- !pos w.
val (word_subword w (pos,dimindex(:N))) =
(val w DIV 2 EXP pos) MOD 2 EXP dimindex(:N)
VAL_WORD_SUBWORD_SIMPLE =
|- !w. val (word_subword w (0,dimindex(:N))) =
val w MOD 2 EXP dimindex(:N)
WORD_SUBWORD_AND =
|- !x y pos len.
word_subword (word_and x y) (pos,len) =
word_and (word_subword x (pos,len)) (word_subword y (pos,len))
WORD_SUBWORD_OR =
|- !x y pos len.
word_subword (word_or x y) (pos,len) =
word_or (word_subword x (pos,len)) (word_subword y (pos,len))
WORD_SUBWORD_XOR =
|- !x y pos len.
word_subword (word_xor x y) (pos,len) =
word_xor (word_subword x (pos,len)) (word_subword y (pos,len))
WORD_ZX_ADD =
|- !x y.
dimindex(:N) <= dimindex(:M)
==> word_zx (word_add x y) = word_add (word_zx x) (word_zx y)
WORD_ZX_AND =
|- !x y. word_zx (word_and x y) = word_and (word_zx x) (word_zx y)
WORD_ZX_MUL =
|- !x y.
dimindex(:N) <= dimindex(:M)
==> word_zx (word_mul x y) = word_mul (word_zx x) (word_zx y)
WORD_ZX_NEG =
|- !x. dimindex(:N) <= dimindex(:M)
==> word_zx (word_neg x) = word_neg (word_zx x)
WORD_ZX_NOT =
|- !x. dimindex(:N) <= dimindex(:M)
==> word_zx (word_not x) = word_not (word_zx x)
WORD_ZX_OR =
|- !x y. word_zx (word_or x y) = word_or (word_zx x) (word_zx y)
WORD_ZX_SHL =
|- !x n.