-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRubik63.v
3939 lines (3630 loc) · 139 KB
/
Rubik63.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
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
Require Import PrimInt63 Cyclic63 List BasicRubik.
(** Cubes positions. There are 7*6*5*4*3*2 positions. **)
(** We code them as 6 * 5 * 4 * (3 * 3 * 7 = 63) **)
Inductive tc6 := OTC6 | TC6 (_ _ _ _ _ _ : int).
Inductive tc5 := OTC5 | TC5 (_ _ _ _ _ : tc6).
Inductive tc4 := OTC4 | TC4 (_ _ _ _ : tc5).
(** Orientations: there is 3 possible orientations **)
(** about of 8 cubes, one is fixed and one has the orientations **)
(** that depend of the others so 3^6 **)
Inductive to1 := OTO1 | TO1 (_ _ _: tc4).
Inductive to2 := OTO2 | TO2 (_ _ _: to1).
Inductive to3 := OTO3 | TO3 (_ _ _: to2).
Inductive to4 := OTO4 | TO4 (_ _ _: to3).
Inductive to5 := OTO5 | TO5 (_ _ _: to4).
(** As we order by increasing arity this is top **)
Inductive tc2 := OTC2: tc2 | TC2 (_ _ : to5).
(** Some 63 bits operations **)
Open Scope uint63_scope.
Definition p2t63 x := snd (positive_to_int x) - 1.
Definition shiftr63 x n := addmuldiv (63 - n) 0 x.
Definition shiftl63 x n := addmuldiv n x 0.
Compute shiftr63 24 2.
(** Check if a given position is in a state **)
Definition int63i x n :=
let u := p2t63 n in
let v := shiftr63 x u in
let w := shiftl63 (shiftr63 v 1) 1 in
match compare v w with Eq => false | _ => true end.
Definition tc6i l c n:=
match c, l with
| TC6 m _ _ _ _ _, C1 :: _ => int63i m n
| TC6 _ m _ _ _ _, C2 :: _ => int63i m n
| TC6 _ _ m _ _ _, C3 :: _ => int63i m n
| TC6 _ _ _ m _ _, C4 :: _ => int63i m n
| TC6 _ _ _ _ m _, C5 :: _ => int63i m n
| TC6 _ _ _ _ _ m, C6 :: _ => int63i m n
| _, _ => false
end.
Definition tc5i l c n:=
match c, l with
| TC5 m _ _ _ _, C1 :: l1 => tc6i l1 m n
| TC5 _ m _ _ _, C2 :: l1 => tc6i l1 m n
| TC5 _ _ m _ _, C3 :: l1 => tc6i l1 m n
| TC5 _ _ _ m _, C4 :: l1 => tc6i l1 m n
| TC5 _ _ _ _ m, C5 :: l1 => tc6i l1 m n
| _, _ => false
end.
Definition tc4i l c n:=
match c, l with
| TC4 m _ _ _, C1 :: l1 => tc5i l1 m n
| TC4 _ m _ _, C2 :: l1 => tc5i l1 m n
| TC4 _ _ m _, C3 :: l1 => tc5i l1 m n
| TC4 _ _ _ m, C4 :: l1 => tc5i l1 m n
| _, _ => false
end.
Definition to1i l c l1 n :=
match c, l with
| TO1 m _ _, O1 :: _ => tc4i l1 m n
| TO1 _ m _, O2 :: _ => tc4i l1 m n
| TO1 _ _ m, O3 :: _ => tc4i l1 m n
| _, _ => false
end.
Definition to2i l c l1 n :=
match c, l with
| TO2 m _ _, O1 :: l2 => to1i l2 m l1 n
| TO2 _ m _, O2 :: l2 => to1i l2 m l1 n
| TO2 _ _ m, O3 :: l2 => to1i l2 m l1 n
| _, _ => false
end.
Definition to3i l c l1 n:=
match c, l with
| TO3 m _ _, O1 :: l2 => to2i l2 m l1 n
| TO3 _ m _, O2 :: l2 => to2i l2 m l1 n
| TO3 _ _ m, O3 :: l2 => to2i l2 m l1 n
| _, _ => false
end.
Definition to4i l c l1 n:=
match c, l with
| TO4 m _ _, O1 :: l2 => to3i l2 m l1 n
| TO4 _ m _, O2 :: l2 => to3i l2 m l1 n
| TO4 _ _ m, O3 :: l2 => to3i l2 m l1 n
| _, _ => false
end.
Definition to5i l c l1 n :=
match c, l with
| TO5 m _ _, O1 :: l2 => to4i l2 m l1 n
| TO5 _ m _, O2 :: l2 => to4i l2 m l1 n
| TO5 _ _ m, O3 :: l2 => to4i l2 m l1 n
| _, _ => false
end.
Definition tc2i l l1 n c :=
match c, l with
| TC2 m _, C1 :: l2 => to5i l1 m l2 n
| TC2 _ m, C2 :: l2 => to5i l1 m l2 n
| _, _ => false
end.
(** Add a position in a state **)
Definition int63a x n := x + shiftl63 1 (p2t63 n).
Definition tc6a l c n :=
match l, c with
| C1 :: _, TC6 m m0 m1 m2 m3 m4 => TC6 (int63a m n) m0 m1 m2 m3 m4
| C2 :: _, TC6 m0 m m1 m2 m3 m4 => TC6 m0 (int63a m n) m1 m2 m3 m4
| C3 :: _, TC6 m0 m1 m m2 m3 m4 => TC6 m0 m1 (int63a m n) m2 m3 m4
| C4 :: _, TC6 m0 m1 m2 m m3 m4 => TC6 m0 m1 m2 (int63a m n) m3 m4
| C5 :: _, TC6 m0 m1 m2 m3 m m4 => TC6 m0 m1 m2 m3 (int63a m n) m4
| C6 :: _, TC6 m0 m1 m2 m3 m4 m => TC6 m0 m1 m2 m3 m4 (int63a m n)
| C1 :: _, OTC6 => TC6 (int63a 0 n) 0 0 0 0 0
| C2 :: _, OTC6 => TC6 0 (int63a 0 n) 0 0 0 0
| C3 :: _, OTC6 => TC6 0 0 (int63a 0 n) 0 0 0
| C4 :: _, OTC6 => TC6 0 0 0 (int63a 0 n) 0 0
| C5 :: _, OTC6 => TC6 0 0 0 0 (int63a 0 n) 0
| C6 :: _, OTC6 => TC6 0 0 0 0 0 (int63a 0 n)
| _, _ => c
end.
Definition tc5a l c n :=
match l, c with
| C1 :: l1, TC5 m m0 m1 m2 m3 => TC5 (tc6a l1 m n) m0 m1 m2 m3
| C2 :: l1, TC5 m0 m m1 m2 m3 => TC5 m0 (tc6a l1 m n) m1 m2 m3
| C3 :: l1, TC5 m0 m1 m m2 m3 => TC5 m0 m1 (tc6a l1 m n) m2 m3
| C4 :: l1, TC5 m0 m1 m2 m m3 => TC5 m0 m1 m2 (tc6a l1 m n) m3
| C5 :: l1, TC5 m0 m1 m2 m3 m => TC5 m0 m1 m2 m3 (tc6a l1 m n)
| C1 :: l1, OTC5 => TC5 (tc6a l1 OTC6 n) OTC6 OTC6 OTC6 OTC6
| C2 :: l1, OTC5 => TC5 OTC6 (tc6a l1 OTC6 n) OTC6 OTC6 OTC6
| C3 :: l1, OTC5 => TC5 OTC6 OTC6 (tc6a l1 OTC6 n) OTC6 OTC6
| C4 :: l1, OTC5 => TC5 OTC6 OTC6 OTC6 (tc6a l1 OTC6 n) OTC6
| C5 :: l1, OTC5 => TC5 OTC6 OTC6 OTC6 OTC6 (tc6a l1 OTC6 n)
| _, _ => c
end.
Definition tc4a l c n :=
match l, c with
| C1 :: l1, TC4 m m0 m1 m2 => TC4 (tc5a l1 m n) m0 m1 m2
| C2 :: l1, TC4 m0 m m1 m2 => TC4 m0 (tc5a l1 m n) m1 m2
| C3 :: l1, TC4 m0 m1 m m2 => TC4 m0 m1 (tc5a l1 m n) m2
| C4 :: l1, TC4 m0 m1 m2 m => TC4 m0 m1 m2 (tc5a l1 m n)
| C1 :: l1, OTC4 => TC4 (tc5a l1 OTC5 n) OTC5 OTC5 OTC5
| C2 :: l1, OTC4 => TC4 OTC5 (tc5a l1 OTC5 n) OTC5 OTC5
| C3 :: l1, OTC4 => TC4 OTC5 OTC5 (tc5a l1 OTC5 n) OTC5
| C4 :: l1, OTC4 => TC4 OTC5 OTC5 OTC5 (tc5a l1 OTC5 n)
| _, _ => c
end.
Definition to1a l c l1 n:=
match l, c with
| O1 :: _, TO1 m m0 m1 => TO1 (tc4a l1 m n) m0 m1
| O2 :: _, TO1 m0 m m1 => TO1 m0 (tc4a l1 m n) m1
| O3 :: _, TO1 m0 m1 m => TO1 m0 m1 (tc4a l1 m n)
| O1 :: _, OTO1 => TO1 (tc4a l1 OTC4 n) OTC4 OTC4
| O2 :: _, OTO1 => TO1 OTC4 (tc4a l1 OTC4 n) OTC4
| O3 :: _, OTO1 => TO1 OTC4 OTC4 (tc4a l1 OTC4 n)
| _, _ => c
end.
Definition to2a l c l1 n :=
match l, c with
| O1 :: l2, TO2 m m0 m1 => TO2 (to1a l2 m l1 n) m0 m1
| O2 :: l2, TO2 m0 m m1 => TO2 m0 (to1a l2 m l1 n) m1
| O3 :: l2, TO2 m0 m1 m => TO2 m0 m1 (to1a l2 m l1 n)
| O1 :: l2, OTO2 => TO2 (to1a l2 OTO1 l1 n) OTO1 OTO1
| O2 :: l2, OTO2 => TO2 OTO1 (to1a l2 OTO1 l1 n) OTO1
| O3 :: l2, OTO2 => TO2 OTO1 OTO1 (to1a l2 OTO1 l1 n)
| _, _ => c
end.
Definition to3a l c l1 n :=
match l, c with
| O1 :: l2, TO3 m m0 m1 => TO3 (to2a l2 m l1 n) m0 m1
| O2 :: l2, TO3 m0 m m1 => TO3 m0 (to2a l2 m l1 n) m1
| O3 :: l2, TO3 m0 m1 m => TO3 m0 m1 (to2a l2 m l1 n)
| O1 :: l2, OTO3 => TO3 (to2a l2 OTO2 l1 n) OTO2 OTO2
| O2 :: l2, OTO3 => TO3 OTO2 (to2a l2 OTO2 l1 n) OTO2
| O3 :: l2, OTO3 => TO3 OTO2 OTO2 (to2a l2 OTO2 l1 n)
| _, _ => c
end.
Definition to4a l c l1 n :=
match l, c with
| O1 :: l2, TO4 m m0 m1 => TO4 (to3a l2 m l1 n) m0 m1
| O2 :: l2, TO4 m0 m m1 => TO4 m0 (to3a l2 m l1 n) m1
| O3 :: l2, TO4 m0 m1 m => TO4 m0 m1 (to3a l2 m l1 n)
| O1 :: l2, OTO4 => TO4 (to3a l2 OTO3 l1 n) OTO3 OTO3
| O2 :: l2, OTO4 => TO4 OTO3 (to3a l2 OTO3 l1 n) OTO3
| O3 :: l2, OTO4 => TO4 OTO3 OTO3 (to3a l2 OTO3 l1 n)
| _, _ => c
end.
Definition to5a l c l1 n :=
match l, c with
| O1 :: l2, TO5 m m0 m1 => TO5 (to4a l2 m l1 n) m0 m1
| O2 :: l2, TO5 m0 m m1 => TO5 m0 (to4a l2 m l1 n) m1
| O3 :: l2, TO5 m0 m1 m => TO5 m0 m1 (to4a l2 m l1 n)
| O1 :: l2, OTO5 => TO5 (to4a l2 OTO4 l1 n) OTO4 OTO4
| O2 :: l2, OTO5 => TO5 OTO4 (to4a l2 OTO4 l1 n) OTO4
| O3 :: l2, OTO5 => TO5 OTO4 OTO4 (to4a l2 OTO4 l1 n)
| _, _ => c
end.
Definition tc2a l l1 n c :=
match l, c with
| C1 :: l2, TC2 m m0 => TC2 (to5a l1 m l2 n) m0
| C2 :: l2, TC2 m0 m => TC2 m0 (to5a l1 m l2 n)
| C1 :: l2, OTC2 => TC2 (to5a l1 OTO5 l2 n) OTO5
| C2 :: l2, OTC2 => TC2 OTO5 (to5a l1 OTO5 l2 n)
| _, _ => c
end.
(** Iteration **)
Section Iter.
Variable A : Type.
Variable next: A -> list cube -> list orientation -> positive -> A.
Fixpoint int63it_aux (m : nat) (p : positive)
(c1 : int) (lc : list cube) (lo : list orientation)
(a : A) {struct m} :=
match m with
| O => a
| S m1 =>
let c2 := shiftr63 c1 1 in
let a1 := match compare c1 (shiftl63 c2 1) with
| Eq => a
| _ => next a lc lo p
end in
int63it_aux m1 (Pos.succ p) c2 lc lo a1
end.
Definition int63it a lc lo c := int63it_aux 63 1%positive c a lc lo.
Definition tc6it lc lo a c :=
match c with
| TC6 m0 m1 m2 m3 m4 m5 =>
int63it (C1 :: lc) lo
(int63it (C2 :: lc) lo
(int63it (C3 :: lc) lo
(int63it (C4 :: lc) lo
(int63it (C5 :: lc) lo
(int63it (C6 :: lc) lo a m5) m4) m3) m2) m1) m0
| _ => a
end.
Definition tc5it lc lo a c :=
match c with
| TC5 m0 m1 m2 m3 m4 => tc6it (C1 :: lc) lo
(tc6it (C2 :: lc) lo
(tc6it (C3 :: lc) lo
(tc6it (C4 :: lc) lo
(tc6it (C5 :: lc) lo a m4 ) m3) m2) m1) m0
| _ => a
end.
Definition tc4it lc lo a c :=
match c with
| TC4 m0 m1 m2 m3 => tc5it (C1 :: lc) lo
(tc5it (C2 :: lc) lo
(tc5it (C3 :: lc) lo
(tc5it (C4 :: lc) lo a m3) m2) m1) m0
| _ => a
end.
Definition to1it lc lo a c :=
match c with
| TO1 m0 m1 m2 => tc4it lc (O1 :: lo)
(tc4it lc (O2 :: lo)
(tc4it lc (O3 :: lo) a m2) m1) m0
| _ => a
end.
Definition to2it lc lo a c :=
match c with
| TO2 m0 m1 m2 => to1it lc (O1 :: lo)
(to1it lc (O2 :: lo)
(to1it lc (O3 :: lo) a m2) m1) m0
| _ => a
end.
Definition to3it lc lo a c :=
match c with
| TO3 m0 m1 m2 => to2it lc (O1 :: lo)
(to2it lc (O2 :: lo)
(to2it lc (O3 :: lo) a m2) m1) m0
| _ => a
end.
Definition to4it lc lo a c :=
match c with
| TO4 m0 m1 m2 => to3it lc (O1 :: lo)
(to3it lc (O2 :: lo)
(to3it lc (O3 :: lo) a m2) m1) m0
| _ => a
end.
Definition to5it lc lo a c :=
match c with
| TO5 m0 m1 m2 => to4it lc (O1 :: lo)
(to4it lc (O2 :: lo)
(to4it lc (O3 :: lo) a m2) m1) m0
| _ => a
end.
Definition tc2it a c :=
match c with
| TC2 m0 m1 => to5it (C1 :: nil) nil (to5it (C2 :: nil) nil a m1) m0
| _ => a
end.
End Iter.
Compute int63it _ (fun x l1 l2 y => y :: x) nil nil nil 2345.
(** Check that all states have been checked **)
Definition int63all c:=
match compare c 9223372036854775807 with Eq => true | _ => false end.
Definition tc6all c :=
match c with
| TC6 m0 m1 m2 m3 m4 m5 =>
(int63all m0 && int63all m1 && int63all m2 && int63all m3 &&
int63all m4 && int63all m5)%bool
| _ => false
end.
Definition tc5all c :=
match c with
| TC5 m0 m1 m2 m3 m4 =>
(tc6all m0 && tc6all m1 && tc6all m2 && tc6all m3 && tc6all m4)%bool
| _ => false
end.
Definition tc4all c :=
match c with
| TC4 m0 m1 m2 m3 =>
(tc5all m0 && tc5all m1 && tc5all m2 && tc5all m3)%bool
| _ => false
end.
Definition to1all c :=
match c with
| TO1 m0 m1 m2 =>
(tc4all m0 && tc4all m1 && tc4all m2)%bool
| _ => false
end.
Definition to2all c :=
match c with
| TO2 m0 m1 m2 =>
(to1all m0 && to1all m1 && to1all m2)%bool
| _ => false
end.
Definition to3all c :=
match c with
| TO3 m0 m1 m2 =>
(to2all m0 && to2all m1 && to2all m2)%bool
| _ => false
end.
Definition to4all c :=
match c with
| TO4 m0 m1 m2 =>
(to3all m0 && to3all m1 && to3all m2)%bool
| _ => false
end.
Definition to5all c :=
match c with
| TO5 m0 m1 m2 =>
(to4all m0 && to4all m1 && to4all m2)%bool
| _ => false
end.
Definition tc2all c :=
match c with
| TC2 m0 m1 =>
(to5all m0 && to5all m1)%bool
| _ => false
end.
(** encoding/decoding: a state as a number **)
Fixpoint encode_aux l n :=
match l with
| nil => nil
| m :: l1 => (match cube_compare n m with Lt => cube_pred m | _ => m end) ::
encode_aux l1 n
end.
Fixpoint encode l n:=
match l, n with
| m :: l1, (S n1) => m :: encode (encode_aux l1 m) n1
| _, _ => nil
end.
Fixpoint decode_aux l n :=
match l with
| nil => nil
| m :: l1 => (match cube_compare n m with Gt => m | _ => cube_succ m end) ::
decode_aux l1 n
end.
Fixpoint decode l :=
match l with
| m :: l1 => m :: decode_aux (decode l1) m
| _ => nil
end.
(*
Compute decode (encode (C1 :: C2 :: C3 :: nil) 3).
Compute decode (encode (C1 :: C3 :: C2 :: nil) 3).
Compute decode (encode (C2 :: C1 :: C3 :: nil) 3).
Compute decode (encode (C2 :: C3 :: C1 :: nil) 3).
Compute decode (encode (C3 :: C1 :: C2 :: nil) 3).
Compute decode (encode (C3 :: C2 :: C1 :: nil) 3).
*)
Section Memo.
Variable A: Set.
Variable f: list cube -> A.
CoInductive memo_val: Type := mval: A -> memo_val.
Definition val_make (l : list cube) := mval (f (rev l)).
CoInductive MStream: Set :=
MSeq (a : memo_val) (m1 m2 m3 m4 m5 m6 m7: MStream).
CoFixpoint memo_make (l : list cube): MStream:=
MSeq (val_make l) (memo_make (C1 :: l))
(memo_make (C2 :: l)) (memo_make (C3 :: l)) (memo_make (C4 :: l))
(memo_make (C5 :: l)) (memo_make (C6 :: l)) (memo_make (C7 :: l)).
Fixpoint memo_get_val (l : list cube) (m : MStream) {struct l} : A :=
match l with
nil => match m with MSeq (mval a) _ _ _ _ _ _ _ => a end
| C1 :: l1 => match m with MSeq _ m1 _ _ _ _ _ _ =>
memo_get_val l1 m1
end
| C2 :: l1 => match m with MSeq _ _ m1 _ _ _ _ _ =>
memo_get_val l1 m1
end
| C3 :: l1 => match m with MSeq _ _ _ m1 _ _ _ _ =>
memo_get_val l1 m1
end
| C4 :: l1 => match m with MSeq _ _ _ _ m1 _ _ _ =>
memo_get_val l1 m1
end
| C5 :: l1 => match m with MSeq _ _ _ _ _ m1 _ _ =>
memo_get_val l1 m1
end
| C6 :: l1 => match m with MSeq _ _ _ _ _ _ m1 _ =>
memo_get_val l1 m1
end
| C7 :: l1 => match m with MSeq _ _ _ _ _ _ _ m1 =>
memo_get_val l1 m1
end
end.
Lemma memo_get_val_correct l1 : memo_get_val l1 (memo_make nil) = f l1.
Proof.
revert l1.
assert (H : forall l1 l2, memo_get_val l1 (memo_make l2) = f (rev l2 ++ l1)).
induction l1 as [ | a l1 Hrec].
intros l2; rewrite app_nil_r; auto.
intros l2; case a; clear a; simpl; rewrite Hrec; simpl; rewrite <- app_assoc; auto.
intros l1; rewrite H; auto.
Qed.
End Memo.
Definition encode_memo_list := memo_make _ (fun x => encode x 6) nil.
Definition encode_memo l := memo_get_val _ l encode_memo_list.
Definition encode_state s :=
match s with
| State i7 i6 i5 i4 i3 i2 i1 o1 o2 o3 o4 o5 o6 o7 =>
match encode_memo (i7 :: i6 :: i5 :: i4 :: i3 :: i2 :: nil) with
| p7 :: p6 :: p5 :: p4 :: p3 :: p2 :: l =>
(p2 :: p4 :: p5 :: p6 :: nil,
o5 :: o4 :: o3 :: o2 :: o1 :: nil, cube3_encode o6 p3 p7)
| _ => (nil, nil, 1%positive)
end
end.
Definition decode_memo_list := memo_make _ decode nil.
Definition decode_memo l := memo_get_val _ l decode_memo_list.
Definition decode_state lc lo n :=
match lc, lo with
| p6 :: p5 :: p4 :: p2 :: nil, o1 :: o2 :: o3 :: o4 :: o5 :: nil =>
let (pp, p7) := cube3_decode n in
let (o6, p3) := pp in
let o7 := oinv (oadd o1 (oadd o2 (oadd o3 (oadd o4 (oadd o5 o6))))) in
match decode_memo (p7 :: p6 :: p5 :: p4 :: p3 :: p2 :: C1 :: nil) with
i7 :: i6 :: i5 :: i4 :: i3 :: i2 :: i1 :: nil =>
State i7 i6 i5 i4 i3 i2 i1 o1 o2 o3 o4 o5 o6 o7
| _ => init_state
end
| _, _ => init_state
end.
Definition next (s : tc2 * tc2) lc lo n :=
let s1 := decode_state lc lo n in
fold_left
(fun (s : tc2 * tc2) f =>
let (states, nstates) := s in
let (u, n) := encode_state (f s1) in
let (lc , lo) := u in
if tc2i lc lo n states then s else
let states1 := tc2a lc lo n states in
let nstates1 := tc2a lc lo n nstates in (states1, nstates1))
movel s.
Definition addn s n :=
let (u, n) := encode_state n in
let (lc , lo) := u in
if tc2i lc lo n s then s else tc2a lc lo n s.
Definition count (n : Z) (l : list cube)
(l1 : list orientation) (p: positive):= Z.succ n.
Definition countn s := tc2it _ count 0%Z s.
Fixpoint iter_aux n (s : tc2 * tc2) :=
match n with
O => s
| S n1 => let (m,p) := s in
iter_aux n1 (tc2it _ next (m, OTC2) p)
end.
Definition s0 := addn OTC2 init_state.
Definition iter n := iter_aux n (s0, s0).
Definition countns n := let x := iter n in (countn (fst x), countn (snd x)).
(*
Time Compute countns 0.
Time Compute countns 1.
Time Compute countns 2.
Time Compute countns 3.
Time Compute countns 4.
Time Compute countns 5.
Time Compute countns 6.
Time Compute countns 7.
Time Compute countns 8.
Time Compute countns 9.
Time Compute countns 10.
Time Compute countns 11.
Time Compute countns 12.
*)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(* *)
(* PROOF PART *)
(* *)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(*****************************************************************************)
(* *)
(* Some properties of int63 *)
(* *)
(*****************************************************************************)
Lemma phi_addmuldiv63 (x y p : int):
(to_Z p <= 63)%Z ->
(to_Z (addmuldiv p x y) =
((to_Z x * 2 ^ to_Z p + to_Z y / 2 ^ (63 - to_Z p)) mod 2^63))%Z.
Proof. apply addmuldiv_spec. Qed.
Definition phi0: to_Z 0 = 0%Z := (refl_equal 0%Z).
Definition phi1: to_Z 1 = 1%Z := (refl_equal 1%Z).
Definition phi63: to_Z 63 = 63%Z := (refl_equal 63%Z).
Definition phi_toZ (x : int) : (0 <= to_Z x < 2 ^ 63)%Z := (to_Z_bounded x).
Lemma phi_nonneg (x : int) : (0 <= to_Z x)%Z.
Proof. case (to_Z_bounded x); auto. Qed.
Definition phi_add (x y : int) :
(to_Z (x + y) = ((to_Z x + to_Z y) mod 2 ^ 63))%Z := (add_spec x y).
Definition phi_sub (x y : int) :
(to_Z (x - y) = ((to_Z x - to_Z y) mod 2 ^ 63))%Z := (sub_spec x y).
Lemma phi_shiftr63 p n :
(to_Z n <= 63)%Z -> to_Z (shiftr63 p n) = (to_Z p / 2 ^ (to_Z n))%Z.
Proof.
intro H; unfold shiftr63.
case (phi_toZ n); intros Hn1 Hn2.
case (phi_toZ p); intros Hp1 Hp2.
rewrite phi_addmuldiv63; auto with zarith.
2: rewrite phi_sub; rewrite Zmod_small; rewrite phi63; auto with zarith.
rewrite phi0; rewrite Zmult_0_l; rewrite Zplus_0_l.
rewrite phi_sub; rewrite phi63.
rewrite (Zmod_small (63 - to_Z n)%Z).
2: split; auto with zarith.
replace (63 - (63 - to_Z n))%Z with (to_Z n); auto with zarith.
apply Z.mod_small; split; auto with zarith.
apply Z.div_pos; auto with zarith.
case (Zle_lt_or_eq _ _ Hp1); intros HH.
2: rewrite <- HH; rewrite Zdiv_0_l; auto with zarith.
apply Z.le_lt_trans with (to_Z p/ 2 ^ 0)%Z; auto with zarith.
case (Zle_lt_or_eq _ _ Hn1); intros HH1.
2: rewrite <- HH1; auto with zarith.
apply Zdiv_le_compat_l; auto with zarith.
split; auto with zarith.
apply Zpow_facts.Zpower_lt_monotone; auto with zarith.
rewrite Zpow_facts.Zpower_0_r; rewrite Zdiv_1_r; auto.
Qed.
Lemma phi_shiftl63 p n :
(to_Z n <= 63)%Z -> (to_Z p * 2 ^ (to_Z n) < 2 ^63)%Z ->
(to_Z (shiftl63 p n) = to_Z p * (2 ^ (to_Z n)))%Z.
Proof.
intros H H1; unfold shiftl63.
case (phi_toZ n); intros Hn1 Hn2.
case (phi_toZ p); intros Hp1 Hp2.
rewrite phi_addmuldiv63; auto with zarith.
rewrite phi0; rewrite Zdiv_0_l; rewrite Zplus_0_r.
rewrite Zmod_small; auto with zarith.
Qed.
Lemma phi_p2t63 p :
(Zpos p <= 63 -> to_Z (p2t63 p) = Zpos p - 1)%Z.
Proof.
intros Hp; unfold p2t63.
rewrite phi_sub; rewrite phi1.
assert (Z.pos p = to_Z (snd (positive_to_int p))).
generalize Hp.
rewrite (positive_to_int_spec p).
case (fst (positive_to_int p)); auto.
intros p1 H; contradict H.
rewrite N2Z.inj_pos.
apply Zlt_not_le.
replace 63%Z with (1 * 63 + 0)%Z; auto with zarith.
apply Z.add_lt_le_mono; auto with zarith.
2 : apply phi_nonneg.
apply Zmult_lt_compat2; auto with zarith.
now compute.
rewrite <- H.
apply Zmod_small.
assert (0 < Zpos p)%Z; auto with zarith.
Qed.
Local Definition phi_compare63 (x y: int) :
match x ?= y with
Lt => (to_Z x < to_Z y)%Z
| Gt => (to_Z y < to_Z x)%Z
| Eq => (to_Z x = to_Z y)%Z
end.
Proof.
rewrite compare_spec.
now case Z.compare_spec.
Qed.
(*****************************************************************************)
(* *)
(* Valid Memory Address *)
(* *)
(*****************************************************************************)
(** What it means to be a valid adress in memory **)
Definition valid63 p := (p <= 63)%positive.
Definition validtc6 (l : list cube) :=
match l with p :: nil => (c2N p < 6)%nat | _ => False end.
Definition validtc5 l :=
match l with
| p :: l1 => (c2N p < 5)%nat /\ validtc6 l1
| _ => False
end.
Definition validtc4 l :=
match l with
| p :: l1 => (c2N p < 4)%nat /\ validtc5 l1
| _ => False
end.
Definition validtc2 l :=
match l with
| p :: l1 => (c2N p < 2)%nat /\ validtc4 l1
| _ => False end.
Definition validto1 (l : list orientation) := length l = 1%nat.
Definition validto2 (l : list orientation) := length l = 2%nat.
Definition validto3 (l : list orientation) := length l = 3%nat.
Definition validto4 (l : list orientation) := length l = 4%nat.
Definition validto5 (l : list orientation) := length l = 5%nat.
Lemma validtc6_inv l :
validtc6 l ->
exists p1, l = p1 :: nil /\
(p1 = C1 \/ p1 = C2 \/ p1 = C3 \/ p1 = C4 \/
p1 = C5 \/ p1 = C6).
Proof.
case l; clear l; try (intros HH; case HH; fail).
intros c l1; case l1; simpl; auto.
2: intros c1 l2 H; case H.
intros H; exists c; split; auto.
revert H.
case c; auto; do 3 (right; auto).
contradict H; simpl; auto with arith.
Qed.
Lemma validtc5_inv l : validtc5 l ->
exists p1, exists l1, l = p1 :: l1 /\
(p1 = C1 \/ p1 = C2 \/ p1 = C3 \/ p1 = C4 \/ p1 = C5) /\
(validtc6 l1)%Z.
Proof.
case l; clear l; try (intros HH; case HH; fail).
intros p1 l1 [Hp1 Hl1]; exists p1; exists l1; do 2 split; auto.
generalize Hp1; case p1; simpl; auto;
intros HH; contradict HH; apply Nat.lt_nge; auto with arith.
Qed.
Lemma validtc4_inv l : validtc4 l ->
exists p1, exists l1, l = p1 :: l1 /\
(p1 = C1 \/ p1 = C2 \/ p1 = C3 \/ p1 = C4) /\
(validtc5 l1)%Z.
Proof.
case l; clear l; try (intros HH; case HH; fail).
intros p1 l1 [Hp1 Hl1]; exists p1; exists l1; split; auto.
generalize Hp1; case p1; simpl; auto;
intros HH; contradict HH; apply Nat.lt_nge; auto with arith.
Qed.
Lemma validtc2_inv l : validtc2 l ->
exists p1, exists l1, l = p1 :: l1 /\ (p1 = C1 \/ p1 = C2) /\ (validtc4 l1).
Proof.
case l; clear l; try (intros HH; case HH; fail).
intros p1 l1 [Hp1 Hl1]; exists p1; exists l1; split; auto.
generalize Hp1; case p1; simpl; auto;
intros HH; contradict HH; apply Nat.lt_nge; auto with arith.
Qed.
(*****************************************************************************)
(* *)
(* Correction of insertion *)
(* *)
(*****************************************************************************)
(* int63i is correct *)
Lemma spec_int63i s p : (Zpos p <= 63)%Z ->
(to_Z s / 2 ^ (Zpos p - 1) mod 2 = if int63i s p then 1 else 0)%Z.
Proof.
intro H; unfold int63i.
case (phi_toZ s); intros Hs1 Hs2.
assert (F1: (to_Z 1 <= 63)%Z).
rewrite phi1; intros HH; discriminate.
assert (F2: (to_Z (shiftr63 (shiftr63 s (p2t63 p)) 1) = to_Z s / 2 ^ (Zpos p))%Z).
repeat (rewrite phi_shiftr63; auto); rewrite phi_p2t63; auto with zarith.
rewrite Zdiv_Zdiv; auto with zarith.
rewrite <- Zpower_exp; try rewrite phi1; auto with zarith.
replace (Zpos p - 1 + 1)%Z with (Zpos p); auto with zarith.
assert (F3: (to_Z (shiftr63 (shiftr63 s (p2t63 p)) 1) * 2 ^ to_Z 1 < 2 ^ 63)%Z).
rewrite phi1; rewrite F2; rewrite Zpow_facts.Zpower_1_r.
change (2^63)%Z with (2^62 * 2)%Z.
apply Zmult_lt_compat_r; auto with zarith.
apply Zdiv_lt_upper_bound; auto with zarith.
apply Z.lt_le_trans with (1 := Hs2).
change (2 ^ 63)%Z with (2 ^ 62 * 2 ^ 1)%Z.
apply Zmult_le_compat_l; auto with zarith.
apply Zpow_facts.Zpower_le_monotone; auto with zarith.
assert (F4: (to_Z (p2t63 p) < 63)%Z).
rewrite phi_p2t63; auto with zarith.
assert (F5: (2 ^ Zpos p = 2 ^ (Zpos p - 1) * 2)%Z).
assert (FF: (0 < Zpos p)%Z); try (red; auto; fail).
replace (2 ^ (Zpos p))%Z with (2 ^ (Zpos p -1 + 1))%Z.
rewrite Zpower_exp; auto with zarith.
apply f_equal2 with (f := Zpower); auto with zarith.
match goal with |- context[?X ?= ?Y] =>
generalize (phi_compare63 X Y); case compare
end; rewrite phi_shiftl63; auto; rewrite F2; rewrite phi_shiftr63; auto with zarith;
rewrite phi1; rewrite Zpow_facts.Zpower_1_r; rewrite phi_p2t63; auto;
set (u := (to_Z s/ (2 ^ (Zpos p - 1)))%Z); pattern u at 1;
rewrite (Z_div_mod_eq_full u 2%Z); auto with zarith; unfold u; rewrite Zdiv_Zdiv;
auto with zarith; replace (2 ^ (Zpos p - 1) * 2)%Z with (2 ^(Zpos p))%Z; auto with zarith;
rewrite Zmult_comm; fold u; case (Z_mod_lt u 2); auto with zarith.
Qed.
Lemma int63ai s p : (Zpos p <= 63)%Z ->
int63i s p = false -> int63i (int63a s p) p = true.
Proof.
intros H H1.
assert (F0: (0 < Zpos p)%Z); try (red; auto; fail).
assert (F1: (0 < 2 ^ (Zpos p - 1))%Z); auto with zarith.
case (phi_toZ s); intros Hs1 Hs2.
generalize (spec_int63i s p H); rewrite H1; intros H2.
generalize (spec_int63i (int63a s p) p H).
case int63i; auto.
unfold int63a.
rewrite phi_add; rewrite phi_shiftl63; rewrite phi_p2t63;
try (rewrite phi1; rewrite Zmult_1_l); auto with zarith.
2: apply Zpow_facts.Zpower_lt_monotone; auto with zarith.
rewrite (fun x => Zmod_small x (2^63)%Z).
- generalize (Z_div_plus_full (to_Z s) 1%Z (2 ^ (Zpos p - 1))%Z).
rewrite Zmult_1_l; intros HH; rewrite HH; clear HH; auto with zarith.
rewrite Zplus_mod; rewrite H2; rewrite Zplus_0_l; repeat rewrite Zmod_small;
auto with zarith.
- split; auto with zarith.
replace (to_Z s) with (2^(Zpos p) * (to_Z s / 2 ^ (Zpos p)) + (to_Z s mod (2^ (Zpos p - 1))))%Z.
+ apply Z.lt_le_trans with (2 ^ Zpos p * (to_Z s / 2 ^ Zpos p) + 2 ^ Zpos p)%Z.
rewrite <- Zplus_assoc; apply Zplus_lt_compat_l.
apply Z.le_lt_trans with (2 ^ (Zpos p - 1) - 1 + 2 ^ (Zpos p - 1))%Z.
* apply Zplus_le_compat_r.
case (Z_mod_lt (to_Z s) (2 ^ (Zpos p - 1))); auto with zarith.
* replace (2 ^Zpos p)%Z with (2^(Zpos p -1) * 2 ^1)%Z.
-- rewrite Zpow_facts.Zpower_1_r; auto with zarith.
-- rewrite <- Zpower_exp; auto with zarith; apply f_equal2 with (f := Zpower); auto with zarith.
* replace (2 ^ Zpos p * (to_Z s / 2 ^ Zpos p) + 2 ^ Zpos p)%Z with
(2 ^ Zpos p * (to_Z s / 2 ^ Zpos p + 1))%Z; try ring.
replace (2 ^ 63)%Z with (2 ^ (Zpos p) * (2^ (63 - Zpos p)))%Z.
-- apply Zmult_le_compat_l; auto with zarith.
assert (to_Z s / 2 ^ Zpos p < 2 ^ (63 - Zpos p))%Z; auto with zarith.
apply Zdiv_lt_upper_bound; auto with zarith.
rewrite <- Zpower_exp; auto with zarith.
replace (63 - Zpos p + Zpos p)%Z with 63%Z; auto; ring.
-- rewrite <- Zpower_exp; auto with zarith.
apply f_equal2 with (f := Zpower); auto; ring.
+ apply sym_equal.
pattern (to_Z s) at 1; rewrite (Z_div_mod_eq_full (to_Z s) (2 ^ Zpos p)%Z).
* apply f_equal2 with (f := Zplus); auto.
pattern (to_Z s) at 1; rewrite (Z_div_mod_eq_full (to_Z s) (2 ^ (Zpos p - 1))%Z).
-- rewrite Zplus_mod.
replace (2 ^(Zpos p))%Z with (2^(Zpos p - 1) * (2 ^ 1))%Z.
++ rewrite Zmult_mod_distr_l; rewrite Zpow_facts.Zpower_1_r; rewrite H2.
rewrite Zmult_0_r; rewrite Zplus_0_l.
rewrite Zmod_mod; apply Zmod_small.
case (Z_mod_lt (to_Z s) (2 ^ (Zpos p - 1))%Z); auto with zarith.
++ rewrite <- Zpower_exp; auto with zarith.
apply f_equal2 with (f := Zpower); auto with zarith.
Qed.
Lemma int63aif s p q : (Zpos p <= 63)%Z -> (Zpos q <= 63)%Z ->
int63i s p = false -> p <> q -> int63i (int63a s p) q = int63i s q.
Proof.
intros Hp Hq H Hd.
assert (F0: (0 < Zpos p)%Z); try (red; auto; fail).
assert (F1: (0 < 2 ^ (Zpos p - 1))%Z).
now apply Z.pow_pos_nonneg; auto with zarith.
assert (F2: (0 < Zpos q)%Z); try (red; auto; fail).
assert (F3: (0 < 2 ^ (Zpos q - 1))%Z).
now apply Z.pow_pos_nonneg; auto with zarith.
generalize (spec_int63i s p Hp); rewrite H; intros H1.
case (phi_toZ s); intros Hs1 Hs2.
generalize (spec_int63i s q Hq) (spec_int63i (int63a s p) q Hq).
replace ((to_Z s / 2 ^ (Zpos q - 1)) mod 2)%Z with
((to_Z (int63a s p) / 2 ^ (Zpos q - 1)) mod 2)%Z.
now intros HH; rewrite HH; case int63i; case int63i; auto;
intros; discriminate.
unfold int63a.
rewrite phi_add; rewrite phi_shiftl63; rewrite phi_p2t63;
try (rewrite phi1; rewrite Zmult_1_l); auto with zarith.
2: apply Zpow_facts.Zpower_lt_monotone; auto with zarith.
assert (F : (to_Z s = 2 ^ (Zpos p) * (to_Z s / 2 ^ (Zpos p)) +
(to_Z s mod (2^ (Zpos p - 1))))%Z).
pattern (to_Z s) at 1; rewrite (Z_div_mod_eq_full (to_Z s) (2 ^ Zpos p)%Z).
apply f_equal2 with (f := Zplus); auto.
pattern (to_Z s) at 1; rewrite (Z_div_mod_eq_full (to_Z s) (2 ^ (Zpos p - 1))%Z).
rewrite Zplus_mod.
replace (2 ^(Zpos p))%Z with (2^(Zpos p - 1) * (2 ^ 1))%Z.
rewrite Zmult_mod_distr_l; rewrite Zpow_facts.Zpower_1_r; rewrite H1.
rewrite Zmult_0_r; rewrite Zplus_0_l.
rewrite Zmod_mod; apply Zmod_small.
now case (Z_mod_lt (to_Z s) (2 ^ (Zpos p - 1))%Z); auto with zarith.
rewrite <- Zpower_exp; auto with zarith.
now apply f_equal2 with (f := Zpower); auto with zarith.
rewrite (fun x => Zmod_small x (2 ^ 63)%Z).
case (Zle_or_lt (Zpos p) (Zpos q)); intros H2.
case (Zle_lt_or_eq _ _ H2); clear H2; intros H2.
replace (2 ^ (Zpos q - 1))%Z with (2^(Zpos p + (Zpos q - Zpos p -1)))%Z.
rewrite Zpower_exp; try rewrite <- Zdiv_Zdiv; auto with zarith.
pattern (to_Z s) at 1; rewrite F.
rewrite <- Zplus_assoc; rewrite Z.add_comm; rewrite Zmult_comm.
rewrite Z_div_plus_full; auto with zarith.
rewrite (Zdiv_small (to_Z s mod 2 ^ (Zpos p - 1)
+ 2 ^ (Zpos p - 1))%Z); auto with zarith.
now rewrite Zplus_0_l; rewrite Zdiv_Zdiv; auto with zarith.
case (Z_mod_lt (to_Z s) (2^(Zpos p - 1))%Z); auto with zarith;
intros Hm1 Hm2.
split; auto with zarith.
replace (2 ^ Zpos p)%Z with (2^1 * (2 ^ (Zpos p - 1)))%Z.
now rewrite Zpow_facts.Zpower_1_r; auto with zarith.
now rewrite <- Zpower_exp; auto with zarith;
apply f_equal2 with (f := Zpower); auto with zarith.
now apply f_equal2 with (f := Zpower); auto with zarith.
now case Hd; injection H2; auto.
replace (2 ^ (Zpos p - 1))%Z with (2 ^ (Zpos p - Zpos q) * 2 ^ (Zpos q - 1))%Z.
2: rewrite <- Zpower_exp; auto with zarith.
2: now apply f_equal2 with (f := Zpower); auto with zarith.
rewrite Z_div_plus_full; auto with zarith.
rewrite Zplus_mod.
replace (2 ^ (Zpos p - Zpos q) mod 2)%Z with 0%Z.
now rewrite Zplus_0_r; apply Zmod_mod; auto.
replace (Zpos p - Zpos q)%Z with (1 + (Zpos p - Zpos q - 1))%Z; try ring.
rewrite Zpower_exp; auto with zarith.
now rewrite Zpow_facts.Zpower_1_r; rewrite Zmult_comm;
rewrite Z_mod_mult; auto.
split; auto with zarith.
rewrite F.
apply Z.lt_le_trans with (2 ^ Zpos p * (to_Z s / 2 ^ Zpos p) + 2 ^ Zpos p)%Z.
rewrite <- Zplus_assoc; apply Zplus_lt_compat_l.
apply Z.le_lt_trans with (2 ^ (Zpos p - 1) - 1 + 2 ^ (Zpos p - 1))%Z.
apply Zplus_le_compat_r.
now case (Z_mod_lt (to_Z s) (2 ^ (Zpos p - 1))); auto with zarith.
replace (2 ^Zpos p)%Z with (2^(Zpos p -1) * 2 ^1)%Z.
now rewrite Zpow_facts.Zpower_1_r; auto with zarith.
now rewrite <- Zpower_exp; auto with zarith; apply f_equal2 with (f := Zpower);
auto with zarith.
replace (2 ^ Zpos p * (to_Z s / 2 ^ Zpos p) + 2 ^ Zpos p)%Z with
(2 ^ Zpos p * (to_Z s / 2 ^ Zpos p + 1))%Z; try ring.
replace (2 ^63)%Z with (2 ^ (Zpos p) * (2^(63 - Zpos p)))%Z.
apply Zmult_le_compat_l; auto with zarith.
assert (to_Z s / 2 ^ Zpos p < 2 ^ (63 - Zpos p))%Z; auto with zarith.
apply Zdiv_lt_upper_bound; auto with zarith.
rewrite <- Zpower_exp; auto with zarith.
now replace (63 - Zpos p + Zpos p)%Z with 63%Z; auto; ring.
rewrite <- Zpower_exp; auto with zarith.
apply f_equal2 with (f := Zpower); auto; ring.
Qed.
Lemma int63_0: forall p, (Zpos p <= 63)%Z -> int63i 0 p = false.
Proof.
intros p Hp.
generalize (spec_int63i 0 p).
rewrite phi0; rewrite Zdiv_0_l; rewrite Zmod_0_l.
case int63i; auto; intros HH2.
absurd (0 = 1)%Z; auto with zarith.
Qed.
Lemma tc6ai: forall s l p, validtc6 l -> valid63 p ->
tc6i l s p = false -> tc6i l (tc6a l s p) p = true.
Proof.
intros s l p H Hp.
assert (Hp1: (Zpos p <= 63)%Z); auto.
case (validtc6_inv _ H); clear H.
intros p1 [H1 [H2 | [H2 | [H2 | [H2 | [H2 | H2]]]]]]; rewrite H1 , H2;
case s; simpl; intros; apply int63ai; auto with zarith; apply int63_0; auto.
Qed.
Lemma tc6aif: forall s l1 l2 p1 p2, validtc6 l1 -> validtc6 l2 ->
valid63 p1 -> valid63 p2 ->
tc6i l1 s p1 = false -> (l1 <> l2 \/ p1 <> p2) -> tc6i l2 (tc6a l1 s p1) p2 = tc6i l2 s p2.
Proof.
intros s l1 l2 p1 p2 Hl1 Hl2 Hp1 Hp2; case (validtc6_inv _ Hl1); clear Hl1;
case (validtc6_inv _ Hl2); clear Hl2.
assert (Hpp1: (Zpos p1 <= 63)%Z); auto.
assert (Hpp2: (Zpos p2 <= 63)%Z); auto.