File: comp-gcd-cond.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (1166 lines) | stat: -rw-r--r-- 45,680 bytes parent folder | download | duplicates (4)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
;; Copyright (C) 2017, Regents of the University of Texas
;; Written by Cuong Chau
;; License: A 3-clause BSD license.  See the LICENSE file distributed with
;; ACL2.

;; Cuong Chau <ckcuong@cs.utexas.edu>
;; May 2019

(in-package "ADE")

(include-book "gcd-cond")
(include-book "../fifo/queue2")
(include-book "../fifo/queue3")

(local (include-book "arithmetic-3/top" :dir :system))

(local (in-theory (disable nth)))

;; ======================================================================

;;; Table of Contents:
;;;
;;; 1. DE Module Generator of COMP-GCD-COND
;;; 2. Multi-Step State Lemma
;;; 3. Single-Step-Update Property
;;; 4. Relationship Between the Input and Output Sequences

;; ======================================================================

;; 1. DE Module Generator of COMP-GCD-COND
;;
;; Construct a DE module generator for COMP-GCD-COND using the link-joint
;; model.  Prove the value and state lemmas for this module generator.

(defconst *comp-gcd-cond$prim-go-num* 1)
(defconst *comp-gcd-cond$go-num* (+ *comp-gcd-cond$prim-go-num*
                                    *queue2$go-num*
                                    *queue3$go-num*
                                    *gcd-cond$go-num*))

(defun comp-gcd-cond$data-ins-len (data-size)
  (declare (xargs :guard (natp data-size)))
  (+ 3 (* 2 (mbe :logic (nfix data-size)
                 :exec  data-size))))

(defun comp-gcd-cond$ins-len (data-size)
  (declare (xargs :guard (natp data-size)))
  (+ (comp-gcd-cond$data-ins-len data-size)
     *comp-gcd-cond$go-num*))

;; DE module generator of COMP-GCD-COND

(module-generator
 comp-gcd-cond* (data-size)
 (si 'comp-gcd-cond data-size)
 (list* 'full-in 'empty-out0- 'empty-out1-
        (append (sis 'data-in 0 (* 2 data-size))
                (sis 'go 0 *comp-gcd-cond$go-num*)))
 (list* 'in-act 'out-act 'out-act0 'out-act1 'flag
        (append (sis 'data0-out 0 data-size)
                (sis 'data1-out 0 (* 2 data-size))))
 '(a0 b0 a1 b1 q2 q3)
 (list
  ;; LINKS
  ;; A0
  (list 'a0
        (list* 'a0-status (sis 'a0-out 0 data-size))
        (si 'link data-size)
        (list* 'in-act 'q2-in-act (sis 'a0-in 0 data-size)))

  ;; B0
  (list 'b0
        (list* 'b0-status (sis 'b0-out 0 data-size))
        (si 'link data-size)
        (list* 'in-act 'q3-in-act (sis 'b0-in 0 data-size)))

  ;; A1
  (list 'a1
        (list* 'a1-status (sis 'a1-out 0 data-size))
        (si 'link data-size)
        (list* 'q2-out-act 'out-act (sis 'q2-data-out 0 data-size)))

  ;; B1
  (list 'b1
        (list* 'b1-status (sis 'b1-out 0 data-size))
        (si 'link data-size)
        (list* 'q3-out-act 'out-act (sis 'q3-data-out 0 data-size)))

  ;; STATUS
  '(in-status (ready-in-) b-or (a0-status b0-status))
  '(out-status (ready-out) b-and (a1-status b1-status))

  ;; JOINTS
  ;; 2-link queue Q2
  (list 'q2
        (list* 'q2-in-act 'q2-out-act
               (sis 'q2-data-out 0 data-size))
        (si 'queue2 data-size)
        (list* 'a0-status 'a1-status
               (append (sis 'a0-out 0 data-size)
                       (sis 'go
                            (+ *comp-gcd-cond$prim-go-num*
                               *gcd-cond$go-num*)
                            *queue2$go-num*))))

  ;; 3-link queue Q3
  (list 'q3
        (list* 'q3-in-act 'q3-out-act
               (sis 'q3-data-out 0 data-size))
        (si 'queue3 data-size)
        (list* 'b0-status 'b1-status
               (append (sis 'b0-out 0 data-size)
                       (sis 'go
                            (+ *comp-gcd-cond$prim-go-num*
                               *gcd-cond$go-num*
                               *queue2$go-num*)
                            *queue3$go-num*))))

  ;; In
  (list 'in-cntl
        '(in-act)
        'joint-cntl
        (list 'full-in 'ready-in- (si 'go 0)))
  (list 'in-op0
        (sis 'a0-in 0 data-size)
        (si 'v-buf data-size)
        (sis 'data-in 0 data-size))
  (list 'in-op1
        (sis 'b0-in 0 data-size)
        (si 'v-buf data-size)
        (sis 'data-in data-size data-size))

  ;; Out
  (list 'branch-out
        (list* 'out-act 'out-act0 'out-act1 'flag
               (append (sis 'data0-out 0 data-size)
                       (sis 'data1-out 0 (* 2 data-size))))
        (si 'gcd-cond data-size)
        (list* 'ready-out 'empty-out0- 'empty-out1-
               (append (append (sis 'a1-out 0 data-size)
                               (sis 'b1-out 0 data-size))
                       (sis 'go
                            *comp-gcd-cond$prim-go-num*
                            *gcd-cond$go-num*)))))

 (declare (xargs :guard (natp data-size))))

(make-event
 `(progn
    ,@(state-accessors-gen 'comp-gcd-cond '(a0 b0 a1 b1 q2 q3) 0)))

;; DE netlist generator.  A generated netlist will contain an instance of
;; COMP-GCD-COND.

(defund comp-gcd-cond$netlist (data-size)
  (declare (xargs :guard (and (natp data-size)
                              (<= 2 data-size))))
  (cons (comp-gcd-cond* data-size)
        (union$ (queue2$netlist data-size)
                (queue3$netlist data-size)
                (gcd-cond$netlist data-size)
                :test 'equal)))

;; Recognizer for COMP-GCD-COND

(defund comp-gcd-cond& (netlist data-size)
  (declare (xargs :guard (and (alistp netlist)
                              (and (natp data-size)
                                   (<= 2 data-size)))))
  (b* ((subnetlist (delete-to-eq (si 'comp-gcd-cond data-size) netlist)))
    (and (equal (assoc (si 'comp-gcd-cond data-size) netlist)
                (comp-gcd-cond* data-size))
         (link& subnetlist data-size)
         (joint-cntl& subnetlist)
         (v-buf& subnetlist data-size)
         (gcd-cond& subnetlist data-size)
         (queue2& subnetlist data-size)
         (queue3& subnetlist data-size))))

;; Sanity check

(local
 (defthmd check-comp-gcd-cond$netlist-64
   (and (net-syntax-okp (comp-gcd-cond$netlist 64))
        (net-arity-okp (comp-gcd-cond$netlist 64))
        (comp-gcd-cond& (comp-gcd-cond$netlist 64) 64))))

;; Constraints on the state of COMP-GCD-COND

(defund comp-gcd-cond$st-format (st data-size)
  (b* ((a0 (nth *comp-gcd-cond$a0* st))
       (b0 (nth *comp-gcd-cond$b0* st))
       (a1 (nth *comp-gcd-cond$a1* st))
       (b1 (nth *comp-gcd-cond$b1* st))
       (q2 (nth *comp-gcd-cond$q2* st))
       (q3 (nth *comp-gcd-cond$q3* st)))
    (and (natp data-size)
         (<= 3 data-size)

         (link$st-format a0 data-size)
         (link$st-format b0 data-size)
         (link$st-format a1 data-size)
         (link$st-format b1 data-size)

         (queue2$st-format q2 data-size)
         (queue3$st-format q3 data-size))))

(defthm comp-gcd-cond$st-format=>constraint
  (implies (comp-gcd-cond$st-format st data-size)
           (and (natp data-size)
                (<= 3 data-size)))
  :hints (("Goal" :in-theory (enable comp-gcd-cond$st-format)))
  :rule-classes :forward-chaining)

(defund comp-gcd-cond$valid-st (st data-size)
  (b* ((a0 (nth *comp-gcd-cond$a0* st))
       (b0 (nth *comp-gcd-cond$b0* st))
       (a1 (nth *comp-gcd-cond$a1* st))
       (b1 (nth *comp-gcd-cond$b1* st))
       (q2 (nth *comp-gcd-cond$q2* st))
       (q3 (nth *comp-gcd-cond$q3* st)))
    (and (comp-gcd-cond$st-format st data-size)

         (link$valid-st a0 data-size)
         (link$valid-st b0 data-size)
         (link$valid-st a1 data-size)
         (link$valid-st b1 data-size)

         (queue2$valid-st q2 data-size)
         (queue3$valid-st q3 data-size))))

(defthmd comp-gcd-cond$valid-st=>constraint
  (implies (comp-gcd-cond$valid-st st data-size)
           (and (natp data-size)
                (<= 3 data-size)))
  :hints (("Goal"
           :in-theory (enable comp-gcd-cond$valid-st)))
  :rule-classes :forward-chaining)

(defthmd comp-gcd-cond$valid-st=>st-format
  (implies (comp-gcd-cond$valid-st st data-size)
           (comp-gcd-cond$st-format st data-size))
  :hints (("Goal" :in-theory (e/d (comp-gcd-cond$valid-st)
                                  ()))))

;; Extract the input and output signals for COMP-GCD-COND

(progn
  ;; Extract the input data

  (defun comp-gcd-cond$data-in (inputs data-size)
    (declare (xargs :guard (and (true-listp inputs)
                                (natp data-size))))
    (take (* 2 (mbe :logic (nfix data-size)
                    :exec  data-size))
          (nthcdr 3 inputs)))

  (defthm len-comp-gcd-cond$data-in
    (equal (len (comp-gcd-cond$data-in inputs data-size))
           (* 2 (nfix data-size))))

  (in-theory (disable comp-gcd-cond$data-in))

  ;; Extract the inputs for the Q2 joint

  (defund comp-gcd-cond$q2-inputs (inputs st data-size)
    (b* ((go-signals (nthcdr (comp-gcd-cond$data-ins-len data-size) inputs))

         (q2-go-signals (take *queue2$go-num*
                              (nthcdr (+ *comp-gcd-cond$prim-go-num*
                                         *gcd-cond$go-num*)
                                      go-signals)))

         (a0 (nth *comp-gcd-cond$a0* st))
         (a0.s (nth *link$s* a0))
         (a0.d (nth *link$d* a0))
         (a1 (nth *comp-gcd-cond$a1* st))
         (a1.s (nth *link$s* a1)))

      (list* (f-buf (car a0.s)) (f-buf (car a1.s))
             (append (v-threefix (strip-cars a0.d))
                     q2-go-signals))))

  ;; Extract the inputs for the Q3 joint

  (defund comp-gcd-cond$q3-inputs (inputs st data-size)
    (b* ((go-signals (nthcdr (comp-gcd-cond$data-ins-len data-size) inputs))

         (q3-go-signals (take *queue3$go-num*
                              (nthcdr (+ *comp-gcd-cond$prim-go-num*
                                         *gcd-cond$go-num*
                                         *queue2$go-num*)
                                      go-signals)))

         (b0 (nth *comp-gcd-cond$b0* st))
         (b0.s (nth *link$s* b0))
         (b0.d (nth *link$d* b0))
         (b1 (nth *comp-gcd-cond$b1* st))
         (b1.s (nth *link$s* b1)))

      (list* (f-buf (car b0.s)) (f-buf (car b1.s))
             (append (v-threefix (strip-cars b0.d))
                     q3-go-signals))))

  ;; Extract the inputs for the branch-out joint

  (defund comp-gcd-cond$br-inputs (inputs st data-size)
    (b* ((empty-out0- (nth 1 inputs))
         (empty-out1- (nth 2 inputs))
         (go-signals (nthcdr (comp-gcd-cond$data-ins-len data-size)
                             inputs))

         (br-go-signals (take *gcd-cond$go-num*
                              (nthcdr *comp-gcd-cond$prim-go-num*
                                      go-signals)))

         (a1 (nth *comp-gcd-cond$a1* st))
         (a1.s (nth *link$s* a1))
         (a1.d (nth *link$d* a1))
         (b1 (nth *comp-gcd-cond$b1* st))
         (b1.s (nth *link$s* b1))
         (b1.d (nth *link$d* b1))

         (br-full-in (f-and (car a1.s) (car b1.s))))

      (list* br-full-in empty-out0- empty-out1-
             (append (append (v-threefix (strip-cars a1.d))
                             (v-threefix (strip-cars b1.d)))
                     br-go-signals))))

  ;; Extract the "in-act" signal

  (defund comp-gcd-cond$in-act (inputs st data-size)
    (b* ((full-in (nth 0 inputs))
         (go-signals (nthcdr (comp-gcd-cond$data-ins-len data-size) inputs))
         (go-in (nth 0 go-signals))
         (a0 (nth *comp-gcd-cond$a0* st))
         (a0.s (nth *link$s* a0))
         (b0 (nth *comp-gcd-cond$b0* st))
         (b0.s (nth *link$s* b0)))
      (joint-act full-in
                 (f-or (car a0.s) (car b0.s))
                 go-in)))

  (defthm comp-gcd-cond$in-act-inactive-lemma
    (implies (not (nth 0 inputs))
             (not (comp-gcd-cond$in-act inputs st data-size)))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$in-act))))

  ;; Extract the "out-act0" signal

  (defund comp-gcd-cond$out-act0 (inputs st data-size)
    (gcd-cond$act0 (comp-gcd-cond$br-inputs inputs st data-size)
                   data-size))

  (defthm comp-gcd-cond$out-act0-inactive-lemma
    (implies (equal (nth 1 inputs) t)
             (not (comp-gcd-cond$out-act0 inputs st data-size)))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$br-inputs
                                       comp-gcd-cond$out-act0))))

  ;; Extract the "out-act1" signal

  (defund comp-gcd-cond$out-act1 (inputs st data-size)
    (gcd-cond$act1 (comp-gcd-cond$br-inputs inputs st data-size)
                   data-size))

  (defthm comp-gcd-cond$out-act1-inactive-lemma
    (implies (equal (nth 2 inputs) t)
             (not (comp-gcd-cond$out-act1 inputs st data-size)))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$br-inputs
                                       comp-gcd-cond$out-act1))))

  (defthm comp-gcd-cond$out-act-mutually-exclusive
    (implies (and (comp-gcd-cond$valid-st st data-size)
                  (comp-gcd-cond$out-act0 inputs st data-size))
             (not (comp-gcd-cond$out-act1 inputs st data-size)))
    :hints (("Goal" :in-theory (e/d (branch$act0
                                     branch$act1
                                     gcd-cond$data-in
                                     gcd-cond$br-inputs
                                     gcd-cond$flag
                                     gcd-cond$act0
                                     gcd-cond$act1
                                     comp-gcd-cond$valid-st
                                     comp-gcd-cond$br-inputs
                                     comp-gcd-cond$out-act0
                                     comp-gcd-cond$out-act1)
                                    (b-nor3)))))

  ;; Extract the "out-act" signal

  (defund comp-gcd-cond$out-act (inputs st data-size)
    (f-or (comp-gcd-cond$out-act0 inputs st data-size)
          (comp-gcd-cond$out-act1 inputs st data-size)))

  (defthm comp-gcd-cond$out-act-inactive-lemma
    (implies (and (equal (nth 1 inputs) t)
                  (equal (nth 2 inputs) t))
             (not (comp-gcd-cond$out-act inputs st data-size)))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$out-act))))

  ;; Extract the "flag" signal

  (defund comp-gcd-cond$flag (inputs st data-size)
    (gcd-cond$flag (comp-gcd-cond$br-inputs inputs st data-size)
                   data-size))

  ;; Extract the 1st output data item

  (defund comp-gcd-cond$data0-out (inputs st data-size)
    (gcd-cond$data0-out (comp-gcd-cond$br-inputs inputs st data-size)
                        data-size))

  (defthm len-comp-gcd-cond$data0-out-1
    (implies (comp-gcd-cond$st-format st data-size)
             (equal (len (comp-gcd-cond$data0-out inputs st data-size))
                    data-size))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$st-format
                                       comp-gcd-cond$data0-out))))

  (defthm len-comp-gcd-cond$data0-out-2
    (implies (comp-gcd-cond$valid-st st data-size)
             (equal (len (comp-gcd-cond$data0-out inputs st data-size))
                    data-size))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$valid-st))))

  (defthm bvp-comp-gcd-cond$data0-out
    (implies (and (comp-gcd-cond$valid-st st data-size)
                  (comp-gcd-cond$out-act0 inputs st data-size))
             (bvp (comp-gcd-cond$data0-out inputs st data-size)))
    :hints (("Goal" :in-theory (enable gcd-cond$act0
                                       gcd-cond$br-inputs
                                       gcd-cond$data-in
                                       branch$act0
                                       comp-gcd-cond$br-inputs
                                       comp-gcd-cond$valid-st
                                       comp-gcd-cond$st-format
                                       comp-gcd-cond$out-act0
                                       comp-gcd-cond$data0-out))))

  ;; Extract the 2nd output data item

  (defund comp-gcd-cond$data1-out (inputs st data-size)
    (gcd-cond$data1-out (comp-gcd-cond$br-inputs inputs st data-size)
                        data-size))

  (defthm len-comp-gcd-cond$data1-out-1
    (implies (comp-gcd-cond$st-format st data-size)
             (equal (len (comp-gcd-cond$data1-out inputs st data-size))
                    (* 2 data-size)))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$st-format
                                       comp-gcd-cond$data1-out))))

  (defthm len-comp-gcd-cond$data1-out-2
    (implies (comp-gcd-cond$valid-st st data-size)
             (equal (len (comp-gcd-cond$data1-out inputs st data-size))
                    (* 2 data-size)))
    :hints (("Goal" :in-theory (enable comp-gcd-cond$valid-st))))

  (defthm bvp-comp-gcd-cond$data1-out
    (implies (and (comp-gcd-cond$valid-st st data-size)
                  (comp-gcd-cond$out-act1 inputs st data-size))
             (bvp (comp-gcd-cond$data1-out inputs st data-size)))
    :hints (("Goal" :in-theory (enable gcd-cond$act1
                                       gcd-cond$br-inputs
                                       gcd-cond$data-in
                                       branch$act1
                                       comp-gcd-cond$br-inputs
                                       comp-gcd-cond$valid-st
                                       comp-gcd-cond$st-format
                                       comp-gcd-cond$out-act1
                                       comp-gcd-cond$data1-out))))

  ;; Extract the output data

  (defund comp-gcd-cond$data-outs (inputs st data-size)
    (cons (comp-gcd-cond$flag inputs st data-size)
          (append (comp-gcd-cond$data0-out inputs st data-size)
                  (comp-gcd-cond$data1-out inputs st data-size))))

  (defun comp-gcd-cond$outputs (inputs st data-size)
    (list* (comp-gcd-cond$in-act inputs st data-size)
           (comp-gcd-cond$out-act inputs st data-size)
           (comp-gcd-cond$out-act0 inputs st data-size)
           (comp-gcd-cond$out-act1 inputs st data-size)
           (comp-gcd-cond$flag inputs st data-size)
           (append (comp-gcd-cond$data0-out inputs st data-size)
                   (comp-gcd-cond$data1-out inputs st data-size))))
  )

(encapsulate
  ()

  (local
   (defthm gcd-cond$value-alt
     (b* ((inputs (list* full-in empty-out0- empty-out1-
                         (append a b go-signals))))
       (implies
        (and (natp data-size)
             (<= 3 data-size)
             (gcd-cond& netlist data-size)
             (true-listp a)
             (equal (len a) data-size)
             (true-listp b)
             (equal (len b) data-size)
             (true-listp go-signals)
             (equal (len go-signals)
                    *gcd-cond$go-num*))
        (equal (se (si 'gcd-cond data-size) inputs st netlist)
               (list* (gcd-cond$act inputs data-size)
                      (gcd-cond$act0 inputs data-size)
                      (gcd-cond$act1 inputs data-size)
                      (gcd-cond$flag inputs data-size)
                      (append (gcd-cond$data0-out inputs data-size)
                              (gcd-cond$data1-out inputs data-size))))))
     :hints (("Goal"
              :use (:instance gcd-cond$value
                              (data-in (append a b)))))))

  ;; The value lemma for COMP-GCD-COND

  (defthm comp-gcd-cond$value
    (b* ((inputs (list* full-in empty-out0- empty-out1-
                        (append data-in go-signals))))
      (implies
       (and (comp-gcd-cond& netlist data-size)
            (equal (len data-in) (* 2 data-size))
            (true-listp go-signals)
            (equal (len go-signals) *comp-gcd-cond$go-num*)
            (comp-gcd-cond$st-format st data-size))
       (equal (se (si 'comp-gcd-cond data-size) inputs st netlist)
              (comp-gcd-cond$outputs inputs st data-size))))
    :hints (("Goal"
             :do-not-induct t
             :expand (:free (inputs data-size)
                            (se (si 'comp-gcd-cond data-size)
                                inputs st netlist))
             :in-theory (e/d (de-rules
                              comp-gcd-cond&
                              comp-gcd-cond*$destructure
                              gcd-cond$act
                              comp-gcd-cond$st-format
                              comp-gcd-cond$br-inputs
                              comp-gcd-cond$in-act
                              comp-gcd-cond$out-act
                              comp-gcd-cond$out-act0
                              comp-gcd-cond$out-act1
                              comp-gcd-cond$flag
                              comp-gcd-cond$data0-out
                              comp-gcd-cond$data1-out)
                             (nfix
                              append
                              append-v-threefix
                              de-module-disabled-rules)))))

  ;; This function specifies the next state of COMP-GCD-COND.

  (defun comp-gcd-cond$step (inputs st data-size)
    (b* ((data-in (comp-gcd-cond$data-in inputs data-size))
         (a (take data-size data-in))
         (b (nthcdr data-size data-in))

         (a0 (nth *comp-gcd-cond$a0* st))
         (b0 (nth *comp-gcd-cond$b0* st))
         (a1 (nth *comp-gcd-cond$a1* st))
         (b1 (nth *comp-gcd-cond$b1* st))
         (q2 (nth *comp-gcd-cond$q2* st))
         (q3 (nth *comp-gcd-cond$q3* st))

         (q2-inputs (comp-gcd-cond$q2-inputs inputs st data-size))
         (q2-in-act (queue2$in-act q2-inputs q2 data-size))
         (q2-out-act (queue2$out-act q2-inputs q2 data-size))
         (q2-data-out (queue2$data-out q2))

         (q3-inputs (comp-gcd-cond$q3-inputs inputs st data-size))
         (q3-in-act (queue3$in-act q3-inputs q3 data-size))
         (q3-out-act (queue3$out-act q3-inputs q3 data-size))
         (q3-data-out (queue3$data-out q3))

         (in-act (comp-gcd-cond$in-act inputs st data-size))
         (out-act (comp-gcd-cond$out-act inputs st data-size))

         (a0-inputs (list* in-act q2-in-act a))
         (b0-inputs (list* in-act q3-in-act b))
         (a1-inputs (list* q2-out-act out-act q2-data-out))
         (b1-inputs (list* q3-out-act out-act q3-data-out)))

      (list
       ;; A0
       (link$step a0-inputs a0 data-size)
       ;; B0
       (link$step b0-inputs b0 data-size)
       ;; A1
       (link$step a1-inputs a1 data-size)
       ;; B1
       (link$step b1-inputs b1 data-size)

       ;; Joint Q2
       (queue2$step q2-inputs q2 data-size)
       ;; Joint Q3
       (queue3$step q3-inputs q3 data-size))))

  ;; The state lemma for COMP-GCD-COND

  (defthm comp-gcd-cond$state
    (b* ((inputs (list* full-in empty-out0- empty-out1-
                        (append data-in go-signals))))
      (implies (and (comp-gcd-cond& netlist data-size)
                    (true-listp data-in)
                    (equal (len data-in) (* 2 data-size))
                    (true-listp go-signals)
                    (equal (len go-signals) *comp-gcd-cond$go-num*)
                    (comp-gcd-cond$st-format st data-size))
               (equal (de (si 'comp-gcd-cond data-size) inputs st netlist)
                      (comp-gcd-cond$step inputs st data-size))))
    :hints (("Goal"
             :do-not-induct t
             :expand (:free (inputs data-size)
                            (de (si 'comp-gcd-cond data-size)
                                inputs st netlist))
             :in-theory (e/d (de-rules
                              comp-gcd-cond&
                              comp-gcd-cond*$destructure
                              comp-gcd-cond$st-format
                              comp-gcd-cond$br-inputs
                              comp-gcd-cond$data-in
                              comp-gcd-cond$in-act
                              comp-gcd-cond$out-act
                              comp-gcd-cond$out-act0
                              comp-gcd-cond$out-act1
                              comp-gcd-cond$q2-inputs
                              comp-gcd-cond$q3-inputs
                              gcd-cond$act)
                             (nfix
                              append
                              append-v-threefix
                              de-module-disabled-rules)))))

  (in-theory (disable comp-gcd-cond$step))
  )

;; ======================================================================

;; 2. Multi-Step State Lemma

;; Conditions on the inputs

(defund comp-gcd-cond$input-format (inputs data-size)
  (declare (xargs :guard (and (true-listp inputs)
                              (natp data-size))))
  (b* ((full-in     (nth 0 inputs))
       (empty-out0- (nth 1 inputs))
       (empty-out1- (nth 2 inputs))
       (data-in (comp-gcd-cond$data-in inputs data-size))
       (go-signals (nthcdr (comp-gcd-cond$data-ins-len data-size)
                           inputs)))
    (and
     (booleanp full-in)
     (booleanp empty-out0-)
     (booleanp empty-out1-)
     (or (not full-in) (bvp data-in))
     (true-listp go-signals)
     (= (len go-signals) *comp-gcd-cond$go-num*)
     (equal inputs
            (list* full-in empty-out0- empty-out1-
                   (append data-in go-signals))))))

(local
 (defthm comp-gcd-cond$input-format=>q2$input-format
   (implies (and (comp-gcd-cond$input-format inputs data-size)
                 (comp-gcd-cond$valid-st st data-size))
            (queue2$input-format
             (comp-gcd-cond$q2-inputs inputs st data-size)
             data-size))
   :hints (("Goal"
            :in-theory (e/d (queue2$input-format
                             queue2$data-in
                             comp-gcd-cond$input-format
                             comp-gcd-cond$valid-st
                             comp-gcd-cond$q2-inputs)
                            ())))))

(local
 (defthm comp-gcd-cond$input-format=>q3$input-format
   (implies (and (comp-gcd-cond$input-format inputs data-size)
                 (comp-gcd-cond$valid-st st data-size))
            (queue3$input-format
             (comp-gcd-cond$q3-inputs inputs st data-size)
             data-size))
   :hints (("Goal"
            :in-theory (e/d (queue3$input-format
                             queue3$data-in
                             comp-gcd-cond$input-format
                             comp-gcd-cond$valid-st
                             comp-gcd-cond$q3-inputs)
                            ())))))

(defthm booleanp-comp-gcd-cond$in-act
  (implies (and (comp-gcd-cond$input-format inputs data-size)
                (comp-gcd-cond$valid-st st data-size))
           (booleanp (comp-gcd-cond$in-act inputs st data-size)))
  :hints (("Goal" :in-theory (enable comp-gcd-cond$input-format
                                     comp-gcd-cond$valid-st
                                     comp-gcd-cond$in-act)))
  :rule-classes (:rewrite :type-prescription))

(defthm booleanp-comp-gcd-cond$out-act0
  (implies (and (comp-gcd-cond$input-format inputs data-size)
                (comp-gcd-cond$valid-st st data-size))
           (booleanp (comp-gcd-cond$out-act0 inputs st data-size)))
  :hints (("Goal" :in-theory (enable branch$act0
                                     gcd-cond$br-inputs
                                     gcd-cond$data-in
                                     gcd-cond$flag
                                     gcd-cond$act0
                                     comp-gcd-cond$input-format
                                     comp-gcd-cond$valid-st
                                     comp-gcd-cond$out-act0
                                     comp-gcd-cond$br-inputs)))
  :rule-classes (:rewrite :type-prescription))

(defthm booleanp-comp-gcd-cond$out-act1
  (implies (and (comp-gcd-cond$input-format inputs data-size)
                (comp-gcd-cond$valid-st st data-size))
           (booleanp (comp-gcd-cond$out-act1 inputs st data-size)))
  :hints (("Goal" :in-theory (enable branch$act1
                                     gcd-cond$br-inputs
                                     gcd-cond$data-in
                                     gcd-cond$flag
                                     gcd-cond$act1
                                     comp-gcd-cond$input-format
                                     comp-gcd-cond$valid-st
                                     comp-gcd-cond$out-act1
                                     comp-gcd-cond$br-inputs)))
  :rule-classes (:rewrite :type-prescription))

(defthm booleanp-comp-gcd-cond$out-act
  (implies (and (comp-gcd-cond$input-format inputs data-size)
                (comp-gcd-cond$valid-st st data-size))
           (booleanp (comp-gcd-cond$out-act inputs st data-size)))
  :hints (("Goal" :in-theory (enable comp-gcd-cond$out-act)))
  :rule-classes (:rewrite :type-prescription))

(simulate-lemma comp-gcd-cond)

;; ======================================================================

;; 3. Single-Step-Update Property

;; Specify the functionality of COMP-GCD-COND

(defund comp-gcd-cond$op (x)
  (append (car x) (cdr x)))

;; The operation of COMP-GCD-COND over a data sequence

(defun comp-gcd-cond$op-map (x)
  (if (atom x)
      nil
    (cons (comp-gcd-cond$op (car x))
          (comp-gcd-cond$op-map (cdr x)))))

(defthm len-of-comp-gcd-cond$op-map
  (equal (len (comp-gcd-cond$op-map x))
         (len x)))

(defthm comp-gcd-cond$op-map-of-append
  (equal (comp-gcd-cond$op-map (append x y))
         (append (comp-gcd-cond$op-map x)
                 (comp-gcd-cond$op-map y))))

;; The extraction function for COMP-GCD-COND that extracts the future output
;; sequence from the current state.

(defund comp-gcd-cond$extract (st)
  (b* ((a0 (nth *comp-gcd-cond$a0* st))
       (b0 (nth *comp-gcd-cond$b0* st))
       (a1 (nth *comp-gcd-cond$a1* st))
       (b1 (nth *comp-gcd-cond$b1* st))
       (q2 (nth *comp-gcd-cond$q2* st))
       (q3 (nth *comp-gcd-cond$q3* st))

       (a-seq (append (extract-valid-data (list a0))
                      (queue2$extract q2)
                      (extract-valid-data (list a1))))
       (b-seq (append (extract-valid-data (list b0))
                      (queue3$extract q3)
                      (extract-valid-data (list b1)))))
    (comp-gcd-cond$op-map (pairlis$ a-seq b-seq))))

(defthm comp-gcd-cond$extract-not-empty-1
  (implies (and (comp-gcd-cond$out-act0 inputs st data-size)
                (comp-gcd-cond$valid-st st data-size))
           (< 0 (len (comp-gcd-cond$extract st))))
  :hints (("Goal"
           :in-theory (e/d (branch$act0
                            gcd-cond$br-inputs
                            gcd-cond$act0
                            comp-gcd-cond$br-inputs
                            comp-gcd-cond$out-act0
                            comp-gcd-cond$valid-st
                            comp-gcd-cond$extract)
                           ())))
  :rule-classes :linear)

(defthm comp-gcd-cond$extract-not-empty-2
  (implies (and (comp-gcd-cond$out-act1 inputs st data-size)
                (comp-gcd-cond$valid-st st data-size))
           (< 0 (len (comp-gcd-cond$extract st))))
  :hints (("Goal"
           :in-theory (e/d (branch$act1
                            gcd-cond$br-inputs
                            gcd-cond$act1
                            comp-gcd-cond$br-inputs
                            comp-gcd-cond$out-act1
                            comp-gcd-cond$valid-st
                            comp-gcd-cond$extract)
                           ())))
  :rule-classes :linear)

;; Specify and prove a state invariant

(progn
  (defund comp-gcd-cond$inv (st)
    (b* ((a0 (nth *comp-gcd-cond$a0* st))
         (b0 (nth *comp-gcd-cond$b0* st))
         (a1 (nth *comp-gcd-cond$a1* st))
         (b1 (nth *comp-gcd-cond$b1* st))
         (q2 (nth *comp-gcd-cond$q2* st))
         (q3 (nth *comp-gcd-cond$q3* st))

         (a-seq (append (extract-valid-data (list a0 a1))
                        (queue2$extract q2)))
         (b-seq (append (extract-valid-data (list b0 b1))
                        (queue3$extract q3))))
      (equal (len a-seq) (len b-seq))))

  (local
   (defthm comp-gcd-cond$q2-in-act-inactive
     (implies (equal (nth *link$s*
                          (nth *comp-gcd-cond$a0* st))
                     '(nil))
              (not (queue2$in-act (comp-gcd-cond$q2-inputs
                                   inputs st data-size)
                                  (nth *comp-gcd-cond$q2* st)
                                  data-size)))
     :hints (("Goal"
              :in-theory (enable comp-gcd-cond$q2-inputs)))))

  (local
   (defthm comp-gcd-cond$q3-in-act-inactive
     (implies (equal (nth *link$s*
                          (nth *comp-gcd-cond$b0* st))
                     '(nil))
              (not (queue3$in-act (comp-gcd-cond$q3-inputs
                                   inputs st data-size)
                                  (nth *comp-gcd-cond$q3* st)
                                  data-size)))
     :hints (("Goal"
              :in-theory (enable comp-gcd-cond$q3-inputs)))))

  (local
   (defthm comp-gcd-cond$q2-out-act-inactive
     (implies (equal (nth *link$s*
                          (nth *comp-gcd-cond$a1* st))
                     '(t))
              (not (queue2$out-act (comp-gcd-cond$q2-inputs
                                    inputs st data-size)
                                   (nth *comp-gcd-cond$q2* st)
                                   data-size)))
     :hints (("Goal"
              :in-theory (enable comp-gcd-cond$q2-inputs)))))

  (local
   (defthm comp-gcd-cond$q3-out-act-inactive
     (implies (equal (nth *link$s*
                          (nth *comp-gcd-cond$b1* st))
                     '(t))
              (not (queue3$out-act (comp-gcd-cond$q3-inputs
                                    inputs st data-size)
                                   (nth *comp-gcd-cond$q3* st)
                                   data-size)))
     :hints (("Goal"
              :in-theory (enable comp-gcd-cond$q3-inputs)))))

  (defthm comp-gcd-cond$inv-preserved
    (implies (and (comp-gcd-cond$input-format inputs data-size)
                  (comp-gcd-cond$valid-st st data-size)
                  (comp-gcd-cond$inv st))
             (comp-gcd-cond$inv
              (comp-gcd-cond$step inputs st data-size)))
    :hints (("Goal"
             :use (comp-gcd-cond$input-format=>q2$input-format
                   comp-gcd-cond$input-format=>q3$input-format)
             :in-theory (e/d (f-sr
                              queue2$extracted-step
                              queue3$extracted-step
                              branch$act0
                              branch$act1
                              gcd-cond$act0
                              gcd-cond$act1
                              gcd-cond$flag
                              gcd-cond$data-in
                              gcd-cond$br-inputs
                              comp-gcd-cond$valid-st
                              comp-gcd-cond$inv
                              comp-gcd-cond$step
                              comp-gcd-cond$br-inputs
                              comp-gcd-cond$in-act
                              comp-gcd-cond$out-act
                              comp-gcd-cond$out-act0
                              comp-gcd-cond$out-act1)
                             (comp-gcd-cond$input-format=>q2$input-format
                              comp-gcd-cond$input-format=>q3$input-format
                              b-nor3
                              b-not)))))
  )

;; The extracted next-state function for COMP-GCD-COND.  Note that this
;; function avoids exploring the internal computation of COMP-GCD-COND.

(defund comp-gcd-cond$extracted-step (inputs st data-size)
  (b* ((a (take data-size (comp-gcd-cond$data-in inputs data-size)))
       (b (nthcdr data-size (comp-gcd-cond$data-in inputs data-size)))
       (data (comp-gcd-cond$op (cons a b)))
       (extracted-st (comp-gcd-cond$extract st))
       (n (1- (len extracted-st))))
    (cond
     ((equal (comp-gcd-cond$out-act inputs st data-size) t)
      (cond
       ((equal (comp-gcd-cond$in-act inputs st data-size) t)
        (cons data (take n extracted-st)))
       (t (take n extracted-st))))
     (t (cond
         ((equal (comp-gcd-cond$in-act inputs st data-size) t)
          (cons data extracted-st))
         (t extracted-st))))))

;; The single-step-update property

(local
 (defthm comp-gcd-cond$input-format-lemma-1
   (implies (comp-gcd-cond$input-format inputs data-size)
            (booleanp (nth 0 inputs)))
   :hints (("Goal" :in-theory (enable comp-gcd-cond$input-format)))
   :rule-classes (:rewrite :type-prescription)))

(local
 (defthm comp-gcd-cond$input-format-lemma-2
   (implies (comp-gcd-cond$input-format inputs data-size)
            (booleanp (nth 1 inputs)))
   :hints (("Goal" :in-theory (enable comp-gcd-cond$input-format)))
   :rule-classes (:rewrite :type-prescription)))

(local
 (defthm comp-gcd-cond$input-format-lemma-3
   (implies (comp-gcd-cond$input-format inputs data-size)
            (booleanp (nth 2 inputs)))
   :hints (("Goal" :in-theory (enable comp-gcd-cond$input-format)))
   :rule-classes (:rewrite :type-prescription)))

(local
 (defthm comp-gcd-cond$input-format-lemma-4
   (implies (and (comp-gcd-cond$input-format inputs data-size)
                 (nth 0 inputs))
            (bvp (comp-gcd-cond$data-in inputs data-size)))
   :hints (("Goal" :in-theory (enable comp-gcd-cond$input-format)))))

(encapsulate
  ()

  (local
   (defthm comp-gcd-cond$q2-data-in-rewrite
     (b* ((a0 (nth *comp-gcd-cond$a0* st))
          (a0.d (nth *link$d* a0)))
       (implies (and (bvp (strip-cars a0.d))
                     (equal (len a0.d) data-size))
                (equal (queue2$data-in
                        (comp-gcd-cond$q2-inputs inputs st data-size)
                        data-size)
                       (strip-cars a0.d))))
     :hints (("Goal"
              :in-theory (enable queue2$data-in
                                 comp-gcd-cond$q2-inputs)))))

  (local
   (defthm comp-gcd-cond$q3-data-in-rewrite
     (b* ((b0 (nth *comp-gcd-cond$b0* st))
          (b0.d (nth *link$d* b0)))
       (implies (and (bvp (strip-cars b0.d))
                     (equal (len b0.d) data-size))
                (equal (queue3$data-in
                        (comp-gcd-cond$q3-inputs inputs st data-size)
                        data-size)
                       (strip-cars b0.d))))
     :hints (("Goal"
              :in-theory (enable queue3$data-in
                                 comp-gcd-cond$q3-inputs)))))

  (local
   (defthm comp-gcd-cond$extracted-step-correct-aux
     (and (equal (cons e (append (queue2$extract st)
                                 x))
                 (append (cons e (queue2$extract st))
                         x))
          (equal (cons e (append (queue3$extract st)
                                 x))
                 (append (cons e (queue3$extract st))
                         x)))))

  (defthm comp-gcd-cond$extracted-step-correct
    (b* ((next-st (comp-gcd-cond$step inputs st data-size)))
      (implies (and (comp-gcd-cond$input-format inputs data-size)
                    (comp-gcd-cond$valid-st st data-size)
                    (comp-gcd-cond$inv st))
               (equal (comp-gcd-cond$extract next-st)
                      (comp-gcd-cond$extracted-step inputs st data-size))))
    :hints (("Goal"
             :use (comp-gcd-cond$input-format=>q2$input-format
                   comp-gcd-cond$input-format=>q3$input-format)
             :in-theory (e/d (f-sr
                              joint-act
                              queue2$extracted-step
                              queue3$extracted-step
                              branch$act0
                              branch$act1
                              gcd-cond$act0
                              gcd-cond$act1
                              gcd-cond$flag
                              gcd-cond$data-in
                              gcd-cond$br-inputs
                              comp-gcd-cond$extracted-step
                              comp-gcd-cond$valid-st
                              comp-gcd-cond$inv
                              comp-gcd-cond$step
                              comp-gcd-cond$br-inputs
                              comp-gcd-cond$in-act
                              comp-gcd-cond$out-act
                              comp-gcd-cond$out-act0
                              comp-gcd-cond$out-act1
                              comp-gcd-cond$extract)
                             (comp-gcd-cond$input-format=>q2$input-format
                              comp-gcd-cond$input-format=>q3$input-format
                              comp-gcd-cond$out-act-mutually-exclusive
                              b-nor3
                              b-not
                              b-or
                              strip-cars
                              acl2::append-of-cons)))))
  )

;; ======================================================================

;; 4. Relationship Between the Input and Output Sequences

;; Prove that comp-gcd-cond$valid-st is an invariant.

(defthm comp-gcd-cond$valid-st-preserved
  (implies (and (comp-gcd-cond$input-format inputs data-size)
                (comp-gcd-cond$valid-st st data-size))
           (comp-gcd-cond$valid-st (comp-gcd-cond$step inputs st data-size)
                                   data-size))
  :hints (("Goal"
           :use (comp-gcd-cond$input-format=>q2$input-format
                 comp-gcd-cond$input-format=>q3$input-format)
           :in-theory (e/d (f-sr
                            joint-act
                            branch$act0
                            branch$act1
                            gcd-cond$act0
                            gcd-cond$act1
                            gcd-cond$flag
                            gcd-cond$data-in
                            gcd-cond$br-inputs
                            comp-gcd-cond$valid-st
                            comp-gcd-cond$st-format
                            comp-gcd-cond$step
                            comp-gcd-cond$br-inputs
                            comp-gcd-cond$in-act
                            comp-gcd-cond$out-act
                            comp-gcd-cond$out-act0
                            comp-gcd-cond$out-act1)
                           (comp-gcd-cond$input-format=>q2$input-format
                            comp-gcd-cond$input-format=>q3$input-format
                            b-not
                            b-or
                            b-nor3
                            take-of-too-many)))))

(encapsulate
  ()

  (local
   (defthm comp-gcd-cond$data-outs-rewrite
     (b* ((a1 (nth *comp-gcd-cond$a1* st))
          (a1.d (nth *link$d* a1))
          (b1 (nth *comp-gcd-cond$b1* st))
          (b1.d (nth *link$d* b1)))
       (implies (and (comp-gcd-cond$valid-st st data-size)
                     (comp-gcd-cond$out-act inputs st data-size))
                (equal (comp-gcd-cond$data1-out inputs st data-size)
                       (comp-gcd-cond$op (cons (strip-cars a1.d)
                                               (strip-cars b1.d))))))
     :hints (("Goal" :in-theory (e/d (branch$act0
                                      branch$act1
                                      gcd-cond$data-in
                                      gcd-cond$br-inputs
                                      gcd-cond$act0
                                      gcd-cond$act1
                                      gcd-cond$data1-out
                                      comp-gcd-cond$valid-st
                                      comp-gcd-cond$out-act
                                      comp-gcd-cond$out-act0
                                      comp-gcd-cond$out-act1
                                      comp-gcd-cond$br-inputs
                                      comp-gcd-cond$data1-out
                                      comp-gcd-cond$op)
                                     ())))))

  (defthm comp-gcd-cond$extract-lemma
    (implies
     (and (comp-gcd-cond$valid-st st data-size)
          (comp-gcd-cond$inv st)
          (comp-gcd-cond$out-act inputs st data-size))
     (equal (list (comp-gcd-cond$data1-out inputs st data-size))
            (nthcdr (1- (len (comp-gcd-cond$extract st)))
                    (comp-gcd-cond$extract st))))
    :hints (("Goal"
             :do-not-induct t
             :in-theory (e/d (left-associativity-of-append
                              branch$act0
                              branch$act1
                              gcd-cond$br-inputs
                              gcd-cond$act0
                              gcd-cond$act1
                              comp-gcd-cond$valid-st
                              comp-gcd-cond$inv
                              comp-gcd-cond$extract
                              comp-gcd-cond$br-inputs
                              comp-gcd-cond$out-act
                              comp-gcd-cond$out-act0
                              comp-gcd-cond$out-act1)
                             (acl2::append-of-cons
                              associativity-of-append
                              append)))))
  )

;; Extract the accepted input sequence

(seq-gen comp-gcd-cond in in-act 0
         (cons (take data-size
                     (comp-gcd-cond$data-in inputs data-size))
               (nthcdr data-size
                       (comp-gcd-cond$data-in inputs data-size))))

;; Extract the valid output sequence

(seq-gen comp-gcd-cond out out-act 1
         (comp-gcd-cond$data1-out inputs st data-size)
         :netlist-data (nthcdr (+ 5 data-size) outputs))

;; The multi-step input-output relationship

(in-out-stream-lemma comp-gcd-cond :op comp-gcd-cond$op :inv t)