File: sexpr-fixpoint-spec.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 991,452 kB
  • sloc: lisp: 15,567,759; javascript: 22,820; cpp: 13,929; ansic: 12,092; perl: 7,150; java: 4,405; xml: 3,884; makefile: 3,507; sh: 3,187; ruby: 2,633; ml: 763; python: 746; yacc: 723; awk: 295; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (1132 lines) | stat: -rw-r--r-- 43,338 bytes parent folder | download | duplicates (3)
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
; S-Expressions for 4-Valued Logic
; Copyright (C) 2010-2012 Centaur Technology
;
; Contact:
;   Centaur Technology Formal Verification Group
;   7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
;   http://www.centtech.com/
;
; License: (An MIT/X11-style license)
;
;   Permission is hereby granted, free of charge, to any person obtaining a
;   copy of this software and associated documentation files (the "Software"),
;   to deal in the Software without restriction, including without limitation
;   the rights to use, copy, modify, merge, publish, distribute, sublicense,
;   and/or sell copies of the Software, and to permit persons to whom the
;   Software is furnished to do so, subject to the following conditions:
;
;   The above copyright notice and this permission notice shall be included in
;   all copies or substantial portions of the Software.
;
;   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;   DEALINGS IN THE SOFTWARE.
;
; Original author: Sol Swords <sswords@centtech.com>

; sexpr-fixpoint-spec.lisp
;

(in-package "ACL2")
(include-book "sexpr-fixpoint")
(include-book "sexpr-advanced")
(include-book "misc/bash" :dir :system)

(local (in-theory (disable set::double-containment
                           set::nonempty-means-set)))

(set-default-hints '('(:do-not-induct t)))

(local (in-theory (disable append-of-nil)))


;; BOZO probably move all of this stuff into libraries ---------------------

(defthm keys-equiv-cdr-when-not-consp-car
  (implies (not (consp (car a)))
           (keys-equiv (cdr a) a))
  :hints (("Goal" :in-theory (enable hons-assoc-equal))
          (witness))
  :rule-classes ((:rewrite :backchain-limit-lst 0)))

(defthmd keys-equiv-iff-set-equiv-alist-keys
  ;; BOZO move to fast-alists book?
  (iff (keys-equiv env1 env2)
       (set-equiv (alist-keys env1) (alist-keys env2)))
  :hints(("goal" :in-theory (e/d (hons-assoc-equal-iff-member-alist-keys)
                                 (set-equiv
                                  alist-keys-member-hons-assoc-equal)))
         (witness)))


;; (defthm member-equal-remove
;;   (iff (member-equal j (remove k x))
;;        (and (not (equal j k))
;;             (member-equal j x)))
;;   :hints (("goal" :induct (len x))))

(encapsulate
  ()
  (local (defthmd lemma
           (iff (set-equiv a (cons b c))
                (and (member-equal b a)
                     (set-equiv (remove b a) (remove b c))))
           :hints ((set-reasoning))))

  (defthmd set-equiv-breakdown-cons
    (equal (set-equiv a (cons b c))
           (and (member-equal b a)
                (set-equiv (remove b a) (remove b c))))
    :hints(("Goal" :use ((:instance lemma))))))

(defthmd set-equiv-breakdown-cons2
  (equal (set-equiv (cons b c) a)
         (and (member-equal b a)
              (set-equiv (remove b a) (remove b c))))
  :hints(("Goal" :use ((:instance set-equiv-breakdown-cons)))))


(local
 (defthm remove-when-not-member
   (implies (not (member-equal k x))
            (equal (remove k x)
                   (append x nil)))
   :hints(("Goal" :induct t
           :in-theory (enable remove)))))



;;; Matt K. mod, 12/2018: I'm renaming remove-assoc, formerly just below, as
;;; remove-assoc-hons (not to conflict with hons-remove-assoc in
;;; std/alists/hons-remove-assoc.lisp), to avoid conflict with remove-assoc now
;;; built into ACl2.  I'm also replacing "remove-assoc" everywhere below by
;;; "remove-assoc-hons".
(defun remove-assoc-hons (key al)
  (declare (xargs :guard t))
  (if (atom al)
      nil
    (if (or (atom (car al))
            (hons-equal (caar al) key))
        (remove-assoc-hons key (cdr al))
      (cons (car al) (remove-assoc-hons key (cdr al))))))

(encapsulate nil
  (local (set-default-hints nil))
  (defthm lookup-in-remove-assoc-hons
    (equal (hons-assoc-equal k (remove-assoc-hons key al))
           (and (not (equal key k))
                (hons-assoc-equal k al)))))

(defthm alist-keys-remove-assoc-hons
  (equal (alist-keys (remove-assoc-hons k a))
         (remove k (alist-keys a)))
  :hints (("goal" :induct t)))

(defthm keys-equiv-cdr-remove-assoc-hons-car
  (implies (and (keys-equiv a b)
                (no-duplicatesp-equal (alist-keys a))
                (consp (car a)))
           (equal (keys-equiv (cdr a)
                              (remove-assoc-hons (caar a) b))
                  t))
  :hints (("goal" :in-theory (enable keys-equiv-iff-set-equiv-alist-keys
                                     alist-keys)
           :do-not-induct t)
          (set-reasoning))
  :otf-flg t)

(defthm alist-equiv-cons-append-remove
  (implies (hons-assoc-equal k a)
           (alist-equiv (cons (cons k (cdr (hons-assoc-equal k a)))
                              (append (remove-assoc-hons k a)
                                      b))
                        (append a b)))
  :hints(("Goal" :in-theory (enable alist-equiv-iff-agree-on-bad-guy))))


;; --------------- end of library stuff ----------------------------




(encapsulate ()
  (local
   (defthm hons-assoc-equal-caar
     (implies (and (keys-equiv x y)
                   (consp (car x)))
              (hons-assoc-equal (caar x) y))))

  (defthm 4v-env-equiv-remove-assoc-hons
    (implies (and (not (4v-env-equiv a (remove-assoc-hons k b)))
                  (not (hons-assoc-equal k a)))
             (not (4v-env-equiv (cons (cons k v) a)
                                b)))
    :hints (("goal" :do-not-induct t
             :in-theory (disable 4v-fix))
            (witness :ruleset 4v-env-equiv-witnessing)
            (witness :ruleset 4v-env-equiv-hons-assoc-equal-ex))
    :otf-flg t))

(defthm 4v-alist-<=-append
  (implies (and (keys-equiv a b)
                (4v-alist-<= a b)
                (4v-alist-<= c d))
           (4v-alist-<= (append a c)
                        (append b d)))
  :hints (("goal" :do-not-induct t
           :in-theory (disable 4v-fix))
          (witness)
          (witness :ruleset (4v-alist-<=-4v-hons-assoc-equal-example))))

(defthm 4v-sexpr-alist-<=-acons
  (implies (not (hons-assoc-equal k al1))
           (iff (4v-sexpr-alist-<= (cons (cons k v) al1) al2)
                (and (4v-sexpr-<= v (cdr (hons-assoc-equal k al2)))
                     (4v-sexpr-alist-<= al1 al2))))
  :hints (("Goal" :do-not-induct t)
          (witness :ruleset (4v-sexpr-alist-<=-hons-assoc-equal-example
                             4v-sexpr-alist-<=-witnessing))))

(defthm 4v-sexpr-<=-restrict
  (implies (and (4v-sexpr-alist-<= a b)
                (keys-equiv a b))
           (4v-sexpr-<= (4v-sexpr-restrict x a)
                        (4v-sexpr-restrict x b)))
  :hints(("Goal" :in-theory (e/d (keys-equiv-iff-set-equiv-alist-keys)
                                 (4v-alist-<= 4v-sexpr-restrict 4v-sexpr-eval
                                              4v-<=)))
         (witness)))

(defthm 4v-sexpr-<=-restrict-x
  (implies (4v-sexpr-<= a b)
           (4v-sexpr-<= (4v-sexpr-restrict a (list (cons k *4vx-sexpr*)))
                        b))
  :hints (("goal" :in-theory (e/d (4v-<=-trans2) (4v-<=)))
          (Witness) (witness)))

(defthm 4v-sexpr-restrict-4v-sexpr-restrict
  (4v-sexpr-equiv (4v-sexpr-restrict (4v-sexpr-restrict x al1) al2)
                  (4v-sexpr-restrict x (append (4v-sexpr-restrict-alist al1 al2)
                                            al2)))
  :hints (("goal" :do-not-induct t)
          (witness))
  :otf-flg t)





(defquant 4v-sexpr-fixpointp (ups vals)
  (forall k (implies (hons-assoc-equal k ups)
                     (4v-sexpr-equiv (4v-sexpr-restrict
                                      (cdr (hons-assoc-equal k ups))
                                      vals)
                                     (cdr (hons-assoc-equal k vals))))))

(verify-guards 4v-sexpr-fixpointp)

(defexample 4v-sexpr-fixpointp-lookup-example
  :pattern (4v-sexpr-restrict (cdr (hons-assoc-equal k updatefns)) env)
  :templates (k)
  :instance-rulename 4v-sexpr-fixpointp-instancing)


(encapsulate nil
  (local (witness-disable set-consp-witnessing))
  (defthm 4v-sexpr-fixpointp-cdr-updatefns
    (implies (and (4v-sexpr-fixpointp updatefns vals)
                  (no-duplicatesp-equal (alist-keys updatefns)))
             (4v-sexpr-fixpointp (cdr updatefns) vals))
    :hints (("goal" :in-theory (enable hons-assoc-equal alist-keys no-duplicatesp-equal))
            (witness))))

(defun 4v-sexpr-fixpoint-spec (ups)
  (if (atom ups)
      nil
    (b* ((rest (4v-sexpr-fixpoint-spec (cdr ups)))
         ((when (atom (car ups))) rest)
         (name (caar ups))
         (upfn (cdar ups))
         (composed-with-rest
          (4v-sexpr-restrict upfn rest))
         (fixpoint (4v-sexpr-restrict composed-with-rest
                                   `((,name x))))
         (rest-restrict (4v-sexpr-restrict-alist
                         rest `((,name . ,fixpoint)))))
      (acons name fixpoint rest-restrict))))


(defthm sexpr-fixpoint-spec-hons-assoc-equal-iff
  (iff (hons-assoc-equal x (4v-sexpr-fixpoint-spec ups))
       (hons-assoc-equal x ups))
  :hints (("goal" :induct t)))




(defthmd 4v-sexpr-equiv-fixpoint-eval
  (let ((ev-bottom (4v-sexpr-eval x (cons (cons name 'x) env))))
    (equal (4v-sexpr-eval x (cons (cons name ev-bottom) env))
           ev-bottom))
  :hints (("goal" :use ((:instance 4v-sexpr-eval-monotonicp
                                   (env (cons (cons name 'x) env))
                                   (env1 (cons (cons name (4v-sexpr-eval x (cons
                                                                            (cons name 'x)
                                                                            env)))
                                               env)))))))




(defexample 4v-sexpr-fixpointp-hons-assoc-equal-ex
  :pattern (hons-assoc-equal k ups)
  :templates (k)
  :instance-rulename 4v-sexpr-fixpointp-instancing)

(defcong 4v-sexpr-alist-equiv iff (4v-sexpr-fixpointp ups fixpoint) 2
  :hints ((witness :ruleset (4v-sexpr-fixpointp-witnessing
                             4v-sexpr-fixpointp-hons-assoc-equal-ex))))


(defthm atom-fixpoint
  (implies (not (consp ups))
           (4v-sexpr-fixpointp ups x))
  :hints ((witness :ruleset 4v-sexpr-fixpointp-witnessing)))

(defthm atom-car-fixpoint
  (implies (not (consp (car ups)))
           (iff (4v-sexpr-fixpointp (cdr ups) x)
                (4v-sexpr-fixpointp ups x)))
  :hints (("Goal" :in-theory (enable hons-assoc-equal))
          (witness :ruleset (4v-sexpr-fixpointp-witnessing
                             4v-sexpr-fixpointp-hons-assoc-equal-ex))))



(local (defthm switch-append
         (implies (not (hons-assoc-equal x al))
                  (alist-equiv (append al (list (cons x v)))
                               (cons (cons x v) al)))
         :hints (("goal" :in-theory (enable
                                     alist-equiv-iff-agree-on-bad-guy)))))

(local (defthm switch-append-cons
         (implies (not (hons-assoc-equal x al))
                  (alist-equiv (append al (cons (cons x v) al2))
                               (cons (cons x v) (append al al2))))
         :hints (("goal" :in-theory (enable alist-equiv-iff-agree-on-bad-guy)))))





(encapsulate
  nil
  (local (set-default-hints nil))
  (make-event
   (b* (((er res)
         (simplify-with-prover
          '(implies (not (hons-assoc-equal name env1))
                        (let* ((x (4v-sexpr-restrict x env1))
                               (ev-bottom (4v-sexpr-eval x (cons (cons name 'x) env))))
                          (equal (4v-sexpr-eval x (cons (cons name ev-bottom)
                                                        env))
                                 ev-bottom)))
          nil '4v-sexpr-equiv-fixpoint-eval-special state))
        (res (prettyify-clause-lst res t (w state))))
     (value
      `(defthm 4v-sexpr-equiv-fixpoint-eval-special
         ,(car res)
         :hints (("goal" :use ((:instance 4v-sexpr-equiv-fixpoint-eval
                                          (x (4v-sexpr-restrict x env1)))))))))))


(local (defthm fixpoint-eval-lookup
         (implies (and (4v-sexpr-fixpointp ups fixpoint)
                       (hons-assoc-equal k ups))
                  (4v-sexpr-equiv
                   (cdr (hons-assoc-equal k fixpoint))
                   (4v-sexpr-restrict (cdr (hons-assoc-equal k ups))
                                   fixpoint)))
         :hints ((witness :ruleset 4v-sexpr-fixpointp-hons-assoc-equal-ex))))

(defthm 4v-sexpr-fixpointp-4v-sexpr-fixpoint-spec
  (implies (no-duplicatesp-equal (alist-keys ups))
           (4v-sexpr-fixpointp ups (4v-sexpr-fixpoint-spec ups)))
  :hints (("goal" :induct (4v-sexpr-fixpoint-spec ups)
           :in-theory (e/d (no-duplicatesp-equal alist-keys
                                                 hons-assoc-equal)
                           (;sexpr-eval-4v-sexpr-restrict
                            ;4v-sexpr-restrict-4v-sexpr-restrict
                            4v-sexpr-restrict-alist
                            4v-sexpr-eval 4v-sexpr-restrict
                            default-car default-cdr))
           :do-not-induct t)
          (witness :ruleset 4v-sexpr-fixpointp-witnessing)
          (witness :ruleset 4v-sexpr-equiv-witnessing))
  :otf-flg t)



(defquant 4v-sexpr-fixpoint-lower-boundp (ups lb)
  (forall (fp env)
          (implies (and (keys-equiv ups fp)
                        (4v-alist-<= ;; 4v-env-equiv
                         (4v-sexpr-eval-alist ups (make-fal fp env))
                                      fp))
                   (4v-alist-<= (4v-sexpr-eval-alist lb env) fp))))

(verify-guards 4v-sexpr-fixpoint-lower-boundp)

(defun 4v-sexpr-fixpointp-strong (ups fixpoint)
  (declare (xargs :guard t))
  (and (4v-sexpr-fixpointp ups fixpoint)
       (keys-equiv ups fixpoint)
       (not (intersectp-equal (alist-keys ups)
                              (4v-sexpr-vars-list (alist-vals fixpoint))))))

;; This was my previous definition for a fixpoint lower bound.  However, it's
;; not quite strong enough.  The previous definition implies this one (as we'll
;; prove.)
(defquant 4v-sexpr-fixpoint-lower-boundp2 (ups vals)
  (forall fixpoint (implies (4v-sexpr-fixpointp-strong ups fixpoint)
                            (4v-sexpr-alist-<= vals fixpoint))))










(defun 4v-sexpr-fixpointp-alt1 (ups fp)
  (4v-sexpr-alist-equiv (4v-sexpr-restrict-alist ups fp)
                        fp))

(defthmd 4v-sexpr-alist-equiv-fixpoint
  (implies (and (4v-sexpr-fixpointp ups fixpoint)
                (keys-equiv ups fixpoint))
           (4v-sexpr-alist-equiv (4v-sexpr-restrict-alist ups fixpoint)
                                 fixpoint))
  :hints ((witness :ruleset
                   (4v-sexpr-alist-equiv-witnessing
                    4v-sexpr-fixpointp-hons-assoc-equal-ex))))


(defthm 4v-sexpr-fixpointp-is-alt1
  (implies (keys-equiv ups fixpoint)
           (iff (4v-sexpr-fixpointp ups fixpoint)
                (4v-sexpr-fixpointp-alt1 ups fixpoint)))
  :hints(("Goal" :in-theory (enable 4v-sexpr-alist-equiv-fixpoint)
          :do-not-induct t)
         (witness :ruleset (4v-sexpr-fixpointp-witnessing
                            4v-sexpr-alist-equiv-example))))

(defexample 4v-sexpr-fixpoint-lower-boundp-eval-alist-ex
  :pattern (4v-sexpr-eval-alist x (append fp env))
  :templates (fp env)
  :instance-rulename 4v-sexpr-fixpoint-lower-boundp-instancing)




(defthm 4v-sexpr-fixpoint-lower-boundp2-if-lower-boundp
  (implies (4v-sexpr-fixpoint-lower-boundp ups lb)
           (4v-sexpr-fixpoint-lower-boundp2 ups lb))
  :hints (("goal" :do-not-induct t
           :in-theory (e/d (4v-sexpr-alist-equiv-is-alt
                            4v-sexpr-alist-<=-is-alt)
                           (4v-sexpr-eval)))
          (witness :ruleset (4v-sexpr-fixpoint-lower-boundp-witnessing
                             4v-sexpr-fixpoint-lower-boundp2-witnessing))
          (witness :ruleset (4v-sexpr-alist-<=-alt-witnessing
                             4v-sexpr-alist-<=-alt-eval-alist-ex))
          (witness :ruleset 4v-sexpr-alist-equiv-alt-eval-alist-ex)
;;           (witness :ruleset 4v-sexpr-<=-witnessing)
          (and stable-under-simplificationp
               '(:use ((:instance 4v-sexpr-fixpoint-lower-boundp-necc
                                  (fp (4v-sexpr-eval-alist fixpoint0 env0))
                                  (env env0)))))
          )
  :otf-flg t)




(defthm lower-boundp-nil-for-no-update-fns
  (4v-sexpr-fixpoint-lower-boundp ups nil)
  :hints (("goal" :do-not-induct t
           :in-theory (disable 4v-sexpr-eval))
          (witness :ruleset (4v-sexpr-fixpoint-lower-boundp-witnessing))))




(defcong 4v-sexpr-alist-equiv iff (4v-sexpr-fixpoint-lower-boundp ups lb) 1
  :hints (("goal" :do-not-induct t
           :in-theory (disable 4v-sexpr-eval))
          (witness :ruleset (4v-sexpr-fixpoint-lower-boundp-witnessing))
          (witness :ruleset (4v-sexpr-fixpoint-lower-boundp-eval-alist-ex))
          ))

(defthm 4v-sexpr-alist-equiv-nil-any-atom
  (implies (atom x)
           (equal (4v-sexpr-alist-equiv x nil) t))
  :hints (("goal" :do-not-induct t)
          (witness :ruleset 4v-sexpr-alist-equiv-witnessing))
  :rule-classes nil)

(defthm 4v-sexpr-fixpoint-lower-boundp-atom-ups
  (implies (and (syntaxp (not (equal ups ''nil)))
                (atom ups))
           (iff (4v-sexpr-fixpoint-lower-boundp ups lb)
                (4v-sexpr-fixpoint-lower-boundp nil lb)))
  :hints (("goal" :use ((:instance 4v-sexpr-alist-equiv-nil-any-atom
                                   (x ups))))))


(defthm lower-boundp-when-atom-car
  (implies (and (not (4v-sexpr-fixpoint-lower-boundp ups lb))
                (not (consp (car ups))))
           (not (4v-sexpr-fixpoint-lower-boundp (cdr ups) lb)))
  :hints (("goal" :do-not-induct t
           :in-theory (disable 4v-sexpr-eval)
           :cases ((consp ups)))
          (witness :ruleset (4v-sexpr-fixpoint-lower-boundp-witnessing))
          (witness :ruleset (4v-sexpr-fixpoint-lower-boundp-eval-alist-ex))
          )
  :otf-flg t)












(defthm alist-keys-4v-sexpr-fixpoint-spec
  (equal (alist-keys (4v-sexpr-fixpoint-spec ups))
         (alist-keys ups))
  :hints (("goal" :induct t)))

;; (defthm keys-equiv-4v-sexpr-eval-alist
;;   (keys-equiv (4v-sexpr-eval-alist al env)
;;               (double-rewrite al))
;;   :hints(("Goal" :in-theory (enable keys-equiv-iff-set-equiv-alist-keys))))

;; (defthm keys-equiv-4v-sexpr-fixpoint-spec
;;   (keys-equiv (4v-sexpr-fixpoint-spec ups)
;;               (double-rewrite ups))
;;   :hints(("Goal" :in-theory (enable keys-equiv-iff-set-equiv-alist-keys))))

;; (defcong keys-equiv keys-equiv (cons a b) 2
;;   :hints (("goal" :do-not-induct t)
;;           (witness)))



;; (local
;;  (progn
;;    (defthmd replace-fixpoint-in-hons-assoc-equal
;;      (implies (key-and-env-equiv (cons (cons k v) a) b)
;;               (4v-equiv (cdr (hons-assoc-equal k b))
;;                         v)))

;;    (defthm 4v-<=-cons-append-env
;;      (implies (and (4v-alist-<= (cons (cons k v) a) fp0)
;;                    (keys-equiv (double-rewrite (cons (cons k v) a)) fp0))
;;               (4v-<=
;;                (4v-sexpr-eval
;;                 x (cons (cons k v) (append a env)))
;;                (4v-sexpr-eval
;;                 x (append fp0 env))))
;;      :hints (("goal" :use ((:instance 4v-alist-<=-append
;;                                       (a (cons (cons k v) a))
;;                                       (b fp0)
;;                                       (c env) (d env)))
;;               :do-not-induct t
;;               :in-theory (disable 4v-alist-<=-append 4v-fix 4v-<=)))
;;      :otf-flg t)

;;    (defthm keys-equiv-cons-caar
;;      (implies (consp (car x))
;;               (keys-equiv (cons (cons (caar x) v) (cdr x))
;;                           (double-rewrite x))))

;;    (defthm key-and-env-equiv-remove-assoc-hons
;;      (implies (and (not (4v-env-equiv a (remove-assoc-hons k b)))
;;                    (not (hons-assoc-equal k a)))
;;               (not (key-and-env-equiv (cons (cons k v) a) b)))
;;      :hints (("goal" :do-not-induct t
;;               :in-theory (e/d (key-and-env-equiv)
;;                               (4v-fix
;;                                4v-env-equiv-to-key-and-env-equiv)))
;;              (witness :ruleset 4v-env-equiv-witnessing)
;;              (witness :ruleset 4v-env-equiv-hons-assoc-equal-ex))
;;      :otf-flg t)


;;    (defthm keys-equiv-cons-eval-alist
;;      (implies (and (keys-equiv ups fp0)
;;                    (consp (car ups)))
;;               (equal (keys-equiv (cons (cons (caar ups) v)
;;                                        (4v-sexpr-eval-alist (cdr ups) a))
;;                                  fp0)
;;                      t))
;;      :hints (("goal" :in-theory (enable keys-equiv-iff-set-equiv-alist-keys))))



;;    (defthmd 4v-alist-<=-acons->remove
;;      (implies (not (hons-assoc-equal k a))
;;               (iff (4v-alist-<= (cons (cons k v) a) b)
;;                    (and (4v-<= v (4v-lookup k b))
;;                         (4v-alist-<= a (remove-assoc-hons k b)))))
;;      :hints (("goal" :do-not-induct t
;;               :in-theory (disable 4v-fix))
;;              (witness :ruleset 4v-alist-<=-witnessing)
;;              (witness :ruleset 4v-alist-<=-hons-assoc-equal-example))
;;      :otf-flg t)

;;    (defthm hack
;;      (implies
;;       (and
;;        (4v-alist-<=
;;         (4v-sexpr-eval-alist (4v-sexpr-fixpoint-spec (cdr update-fns))
;;                              (cons (cons (caar update-fns)
;;                                          (cdr (hons-assoc-equal (caar update-fns)
;;                                                                 fp0)))
;;                                    env0))
;;         (remove-assoc-hons (caar update-fns) fp0))
;;        (consp update-fns)
;;        (consp (car update-fns))
;;        (4v-sexpr-fixpoint-lower-boundp (cdr update-fns)
;;                                        (4v-sexpr-fixpoint-spec (cdr update-fns)))
;;        (not (hons-assoc-equal (caar update-fns)
;;                               (cdr update-fns)))
;;        (no-duplicatesp-equal (alist-keys (cdr update-fns)))
;;        (keys-equiv update-fns fp0)
;;        (key-and-env-equiv (cons (cons (caar update-fns)
;;                                       (4v-sexpr-eval (cdar update-fns)
;;                                                      (append fp0 env0)))
;;                                 (4v-sexpr-eval-alist (cdr update-fns)
;;                                                      (append fp0 env0)))
;;                           fp0))
;;       (4v-<=
;;        (4v-sexpr-eval
;;         (cdar update-fns)
;;         (cons
;;          (cons (caar update-fns) 'x)
;;          (append (4v-sexpr-eval-alist (4v-sexpr-fixpoint-spec (cdr update-fns))
;;                                       (cons (cons (caar update-fns) 'x) env0))
;;                  env0)))
;;        (CDR (HONS-ASSOC-EQUAL (CAAR UPDATE-FNS)
;;                               FP0))))
;;      :hints (("goal" :do-not-induct t
;;               :in-theory (e/d (alist-keys
;;                                4v-alist-<=-acons->remove
;;                                4v-alist-<=-trans2
;;                                replace-fixpoint-in-hons-assoc-equal)
;;                               (4v-sexpr-restrict-alist
;;                                4v-sexpr-eval
;;                                4v-alist-<=-acons-1
;;                                4v-fix 4v-<=)))))))

(defthmd 4v-alist-<=-acons->remove
     (implies (not (hons-assoc-equal k a))
              (iff (4v-alist-<= (cons (cons k v) a) b)
                   (and (4v-<= v (4v-lookup k b))
                        (4v-alist-<= a (remove-assoc-hons k b)))))
     :hints (("goal" :do-not-induct t
              :in-theory (disable 4v-fix))
             (witness :ruleset 4v-alist-<=-witnessing)
             (witness :ruleset 4v-alist-<=-hons-assoc-equal-example))
     :otf-flg t)




;; Notation: We'll use
;; -    * to apply a substitution (aka 4v-sexpr-restrict(-alist))
;; -    : to construct a substitution pair
;; -    :: to append substitutions.
;; -    \ to remove a binding from a substitution

;; Sketch of proof that we compute a least fixpoint:
;; Induct on length of update-fns.  Base case is trivial.
;; In the inductive case, let update-fns = ((s1 : up1) :: upsr), i.e. s1
;; is the first signal bound and up1 is its update function.  By IH we
;; have computed lbr, lower bound for upsr.  Meaning, for any fpr, envr
;; where fpr has the same keys as upsr and satisfying
;; upsr (fpr :: envr) <= fpr,
;; we have lbr(envr) <= fpr.

;; Our result is:
;; lbf = (s1 : ((up1 * lbr) * (s1 : X)))
;;        :: (lbr * (s1 : ((up1 * lbr) * (s1 : X)))).

;; We need to show that for any fp, env where the bound signals of fp are
;; the same as those of ups and ups (fp :: env) <= fp,
;; we have lbf(env) <= fp.

;; Suppose we have such an fp, env.  Decomposing, we have
;; upsr (fp :: env) <= fp\s1, and
;; up1 (fp :: env)  <= s1(fp).

;; and we need to show
;; ((up1 * lbr) * (s1 : X))(env) <= s1(fp) and
;; (lbr * (s1 : ((up1 * lbr) * (s1 : X)))) (env) <= fp\s1.


;; Evaluation rule for substitution (4v-sexpr-eval-4v-sexpr-restrict(-alist)):
;; (a * b)(env) = a(b(env) :: env).

;; So we reduce the above obligations to:
;; (up1 * lbr)((s1 : X) :: env)
;; = up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) <= s1(fp)
;; and
;; lbr ((s1 : ((up1 * lbr) * (s1 : X)) (env)) :: env) =
;; lbr ((s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= s1\fp1.

;; Looking at the second obligation, we need to show
;; lbr ((s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= s1\fp1.
;;
;; Using the IH, let fpr, envr as above be fp\s1 and
;; ((s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env).
;; If we can show
;; upsr (fpr :: envr) <= fpr, i.e.
;; upsr (fp\s1 :: (s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= fp\s1,
;; then we have lbr(envr) <= fpr, i.e.
;; lbr ((s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= fp\s1,
;; and we'll be done.

;; But we already know
;; upsr (fp :: env) <= fp\s1.  By monotonicity of upsr and transitivity
;; of <=, we can just show
;; fp\s1 :: (s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) <= fp.
;; This decomposes to:
;; fp\s1 <= fp\s1 (trivial)
;; and up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) <= s1(fp),
;; which is just the first obligation above.

;; Looking at the first obligation, we need to show
;; up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) <= s1(fp)m
;; but we have
;; up1 (fp :: env) <= s1(fp).  It suffices to show that
;; up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) has the
;; same keys as fp (trivial) and ... <= fp.
;; That is,
;; lbr ((s1 : X) :: env) :: (s1 : X) <= fp,
;; which decomposes to
;; X <= s1(fp), (trivial),
;; and
;; lbr ((s1 : X) :: env) <= fp\s1.

;; Here we apply the IH again: let fpr, envr as above be fp\s1 and
;; ((s1 : X) :: env).
;; If we can show
;; upsr (fpr :: envr) <= fpr, i.e.
;; upsr (fp\s1 :: (s1 : X) :: env) <= fp\s1,
;; then we have lbr(envr) <= fpr, i.e.
;; lbr ((s1 : X) :: env) <= fp\s1,
;; and we'll be done.

;; But we already know
;; upsr (fp :: env) <= fp\s1.  By monotonicity of upsr and transitivity
;; of <=, we can just show
;; fp\s1 :: (s1 : X) <= fp.
;; This decomposes to:
;; fp\s1 <= fp\s1 (trivial)
;; and X <= s1(fp), also trivial.


;; Working from bottom up:
(defthm |fp\s1 :: (s1 : X) <= fp|
  (4v-alist-<= (append (remove-assoc-hons s1 fp)
                       (list (cons s1 *4vx*)))
               fp)
  :hints ((witness :ruleset 4v-alist-<=-witnessing)))

(defthmd 4v-alist-<=-append-cons-append
  (implies (and (set-equiv (double-rewrite (cons bk (alist-keys a)))
                            (double-rewrite (alist-keys d)))
                (4v-alist-<= (append a (list (cons bk bv)))
                             d)
                (4v-alist-<= c e))
           (4v-alist-<= (append a (cons (cons bk bv) c))
                        (append d e)))
  :hints (("goal" :do-not-induct t
           :in-theory (e/d* (hons-assoc-equal-iff-member-alist-keys
;; hons-assoc-equal-when-not-member-alist-keys
                             )
                            (alist-keys-member-hons-assoc-equal
                             4v-fix 4v-<= default-car default-cdr
                             append member-when-atom member-equal
                             alist-keys-when-atom
                             ;; set-equiv-asym set-equiv-trans
                             (:rules-of-class :type-prescription :here))))
          (witness :ruleset (4v-alist-<=-witnessing
                             4v-alist-<=-4v-lookup-example))
          (witness :ruleset set-equiv-member-template)))


;(why 4v-alist-<=-trans2)
;(why 4V-ALIST-<=-SEXPR-EVAL-ALIST-MONOTONIC-ENV)
;(why 4v-alist-<=-append-cons-append)


;; Assuming
;; upsr (fp :: env) <= fp\s1,
;; prove
;; upsr (fp\s1 :: (s1 : X) :: env) <= fp\s1.
(defthm |upsr (fp\s1 :: (s1 : X) :: env) <= fp\s1|
  (implies (and (4v-alist-<= (4v-sexpr-eval-alist upsr (append fp env))
                             (remove-assoc-hons s1 fp))
                (set-equiv (alist-keys fp)
                            (cons s1 (alist-keys upsr))))
           (4v-alist-<= (4v-sexpr-eval-alist upsr
                                             (append (remove-assoc-hons s1 fp)
                                                     (cons (cons s1 *4vx*)
                                                           env)))
                        (remove-assoc-hons s1 fp)))
  :hints(("Goal" :in-theory
          (e/d (4v-alist-<=-trans2
                hons-assoc-equal-iff-member-alist-keys
                set-equiv-breakdown-cons
                4v-alist-<=-append-cons-append)
               (switch-append-cons
                switch-append
                alist-keys-member-hons-assoc-equal))
          :do-not-induct t)))



;; Given
;; upsr (fp :: env) <= fp\s1
;; and lbr a FLB of upsr,
;; show
;; lbr ((s1 : X) :: env) <= fp\s1.
(defthm |lbr ((s1 : X) :: env) <= fp\s1|
  (implies (and (4v-sexpr-fixpoint-lower-boundp upsr lbr)
                (4v-alist-<=
                 (4v-sexpr-eval-alist upsr (append fp env))
                 (remove-assoc-hons s1 fp))
                (set-equiv (alist-keys fp)
                            (cons s1 (alist-keys upsr)))
                (not (member-equal s1 (alist-keys upsr))))
           (4v-alist-<=
            (4v-sexpr-eval-alist
             lbr
             (cons (cons s1 *4vx*) env))
            (remove-assoc-hons s1 fp)))
  :hints (("goal" :use
           ((:instance 4v-sexpr-fixpoint-lower-boundp-necc
                       (ups upsr)
                       (lb lbr)
                       (fp (remove-assoc-hons s1 fp))
                       (env (cons (cons s1 *4vx*) env))))
           :in-theory (e/d (set-equiv-breakdown-cons)
                           (alist-keys-member-hons-assoc-equal
                            switch-append
                            switch-append-cons))
           :do-not-induct t))
  :otf-flg t)




;; Looking at the first obligation, we need to show
;; up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) <= s1(fp)
;; but we have
;; up1 (fp :: env) <= s1(fp).  It suffices to show that "..." has the
;; same keys as fp (trivial) and ... <= fp.
;; That is,
;; lbr ((s1 : X) :: env) :: (s1 : X) <= fp,
;; which decomposes to
;; lbr ((s1 : X) :: env) <= fp\s1 (same as the second obligation above)
;; and
;; X <= s1(fp), trivial.

(defthm |lbr ((s1 : X) :: env) :: (s1 : X) <= fp|
  (implies (4v-alist-<=
            (4v-sexpr-eval-alist
             lbr (cons (cons s1 *4vx*) env))
            (remove-assoc-hons s1 fp))
           (4v-alist-<=
            (append (4v-sexpr-eval-alist
                     lbr (cons (cons s1 *4vx*) env))
                    (list (cons s1 *4vx*)))
            fp))
  :hints (("goal" :do-not-induct t
           :in-theory (disable 4v-fix 4v-sexpr-eval))
          (witness :ruleset (4v-alist-<=-witnessing
                             4v-alist-<=-4v-lookup-example))))

;; given lbr ((s1 : X) :: env) <= fp\s1
;; and up1 (fp :: env) <= s1(fp),
;; show up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) <= s1(fp).

(defthm |up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) <= s1(fp)|
  (implies (and (4v-alist-<=
                 (4v-sexpr-eval-alist
                  lbr (cons (cons s1 *4vx*) env))
                 (remove-assoc-hons s1 fp))
                (4v-<= (4v-sexpr-eval up1 (append fp env))
                       (4v-lookup s1 fp))
                (set-equiv (alist-keys fp)
                            (cons s1 (alist-keys lbr))))
           (4v-<=
            (4v-sexpr-eval
             up1
             (append (4v-sexpr-eval-alist
                      lbr (cons (cons s1 *4vx*) env))
                     (cons (cons s1 *4vx*) env)))
            (4v-lookup s1 fp)))
  :hints (("goal" :in-theory
           (e/d (4v-<=-trans2
                 4v-alist-<=-append-cons-append)
                (4v-<= switch-append
                       switch-append-cons 4v-lookup))
           :do-not-induct t)))



(defthmd 4v-alist-<=-append->remove
     (implies (not (hons-assoc-equal k a))
              (iff (4v-alist-<= (append a (list (cons k v))) b)
                   (and (4v-<= v (4v-lookup k b))
                        (4v-alist-<= a (remove-assoc-hons k b)))))
     :hints (("goal" :do-not-induct t
              :in-theory (disable 4v-fix))
             (witness :ruleset 4v-alist-<=-witnessing)
             (witness :ruleset 4v-alist-<=-hons-assoc-equal-example))
     :otf-flg t)

;; But we already know
;; upsr (fp :: env) <= fp\s1.  By monotonicity of upsr and transitivity
;; of <=, we can just show
;; fp\s1 :: (s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) <= fp.
;; This decomposes to:
;; fp\s1 <= fp\s1 (trivial)
;; and up1(lbr((s1 : X) :: env) :: (s1 : X) :: env) <= s1(fp),
;; which is just the first obligation above.

(defthm
  |upsr (fp\s1 :: (s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= fp\s1|
  (implies (and (4v-alist-<=
                 (4v-sexpr-eval-alist upsr (append fp env))
                 (remove-assoc-hons s1 fp))
                (4v-<= (4v-sexpr-eval up1 (append fp env))
                       (4v-lookup s1 fp))
                (set-equiv (alist-keys fp)
                            (cons s1 (alist-keys upsr)))
                (set-equiv (alist-keys lbr)
                            (alist-keys upsr))
                (not (member-equal s1 (alist-keys upsr)))
                (4v-sexpr-fixpoint-lower-boundp upsr lbr))
           (4v-alist-<=
            (4v-sexpr-eval-alist
             upsr
             (append (remove-assoc-hons s1 fp)
                     (cons (cons s1 (4v-sexpr-eval
                                     up1
                                     (append (4v-sexpr-eval-alist
                                              lbr
                                              (cons (cons s1 *4vx*) env))
                                             (cons (cons s1 *4vx*)
                                                   env))))
                           env)))
            (remove-assoc-hons s1 fp)))
  :hints(("Goal" :in-theory
          (e/d (4v-alist-<=-trans2
                hons-assoc-equal-iff-member-alist-keys
                set-equiv-breakdown-cons
                set-equiv-breakdown-cons2
                4v-alist-<=-append->remove
                4v-alist-<=-append-cons-append)
               (switch-append-cons
                switch-append 4v-<= 4v-fix 4v-lookup
                alist-keys-member-hons-assoc-equal))
          :do-not-induct t)))


;; Using the IH, let fpr, envr as above be fp\s1 and
;; ((s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env).
;; If we can show
;; upsr (fpr :: envr) <= fpr, i.e.
;; upsr (fp\s1 :: (s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= fp\s1,
;; then we have lbr(envr) <= fpr, i.e.
;; lbr ((s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= fp\s1,
;; and we'll be done.


(defthm |lbr ((s1 : up1(lbr((s1 : X) :: env) :: (s1 : X) :: env)) :: env) <= fp\s1|
  (implies (and (4v-alist-<=
                 (4v-sexpr-eval-alist upsr (append fp env))
                 (remove-assoc-hons s1 fp))
                (4v-<= (4v-sexpr-eval up1 (append fp env))
                       (4v-lookup s1 fp))
                (set-equiv (alist-keys fp)
                            (cons s1 (alist-keys upsr)))
                (set-equiv (alist-keys lbr)
                            (alist-keys upsr))
                (not (member-equal s1 (alist-keys upsr)))
                (4v-sexpr-fixpoint-lower-boundp upsr lbr))
           (4v-alist-<=
            (4v-sexpr-eval-alist
             lbr
             (cons (cons s1 (4v-sexpr-eval
                             up1
                             (append (4v-sexpr-eval-alist
                                      lbr
                                      (cons (cons s1 *4vx*) env))
                                     (cons (cons s1 *4vx*)
                                           env))))
                   env))
            (remove-assoc-hons s1 fp)))
  :hints (("goal" :use ((:instance 4v-sexpr-fixpoint-lower-boundp-necc
                                   (ups upsr)
                                   (lb lbr)
                                   (fp (remove-assoc-hons s1 fp))
                                   (env (cons (cons s1 (4v-sexpr-eval
                                                        up1
                                                        (append (4v-sexpr-eval-alist
                                                                 lbr
                                                                 (cons (cons s1 *4vx*) env))
                                                                (cons (cons s1 *4vx*)
                                                                      env))))
                                              env))))
           :in-theory
           (e/d (4v-alist-<=-trans2
                 hons-assoc-equal-iff-member-alist-keys
                 set-equiv-breakdown-cons
                 set-equiv-breakdown-cons2
                 4v-alist-<=-append->remove
                 4v-alist-<=-append-cons-append)
                (switch-append-cons
                 switch-append 4v-<= 4v-fix 4v-lookup
                 alist-keys-member-hons-assoc-equal)))))


;; Our result is:
;; lbf = (s1 : ((up1 * lbr) * (s1 : X)))
;;        :: (lbr * (s1 : ((up1 * lbr) * (s1 : X)))).
(defthm inductive-step
  (implies (and (4v-sexpr-fixpoint-lower-boundp upsr lbr)
                (set-equiv (alist-keys upsr)
                            (alist-keys lbr))
                (not (member-equal s1 (alist-keys upsr))))
           (4v-sexpr-fixpoint-lower-boundp
            (cons (cons s1 up1) upsr)
            (cons (cons s1 (4v-sexpr-restrict
                            (4v-sexpr-restrict up1 lbr)
                            (list (cons s1
                                        *4vx-sexpr*))))
                  (4v-sexpr-restrict-alist
                   lbr (list (cons s1 (4v-sexpr-restrict
                                       (4v-sexpr-restrict up1 lbr)
                                       (list (cons s1
                                                   *4vx-sexpr*)))))))))
  :hints (("goal" :do-not-induct t
           :in-theory (e/d (4v-alist-<=-acons->remove
                            keys-equiv-iff-set-equiv-alist-keys
                            hons-assoc-equal-iff-member-alist-keys)
                           (4v-<= 4v-fix 4v-lookup
                                  switch-append switch-append-cons
                                  alist-keys-member-hons-assoc-equal
                                  4v-sexpr-eval)))
          (witness :ruleset 4v-sexpr-fixpoint-lower-boundp-witnessing))
  :otf-flg t)



(defthm 4v-sexpr-fixpoint-lower-boundp-4v-sexpr-fixpoint-spec
  (implies (no-duplicatesp-equal (alist-keys update-fns))
           (4v-sexpr-fixpoint-lower-boundp
            update-fns
            (4v-sexpr-fixpoint-spec update-fns)))
  :hints (("goal" :induct t
           :in-theory (disable 4v-sexpr-restrict-4v-sexpr-restrict))))

(defthm 4v-sexpr-fixpoint-lower-boundp2-4v-sexpr-fixpoint-spec
  (implies (no-duplicatesp-equal (alist-keys update-fns))
           (4v-sexpr-fixpoint-lower-boundp2
            update-fns
            (4v-sexpr-fixpoint-spec update-fns))))














;; (defthm 4v-sexpr-fixpoint-lower-boundp-4v-sexpr-fixpoint-spec
;;   (implies (no-duplicatesp-equal (alist-keys update-fns))
;;            (4v-sexpr-fixpoint-lower-boundp
;;             update-fns
;;             (4v-sexpr-fixpoint-spec update-fns)))
;;   :hints (("goal" :induct (4v-sexpr-fixpoint-spec update-fns)
;;            :in-theory (e/d (alist-keys
;;                             4v-alist-<=-acons->remove
;;                             4v-alist-<=-trans2)
;;                            (4v-sexpr-restrict-alist
;;                             4v-sexpr-eval
;;                             4v-sexpr-restrict
;;                             4v-alist-<=-acons-1
;;                             default-car default-cdr
;;                             keys-equiv-when-alist-keys
;;                             subsetp-car-member
;;                             member-equal
;;                             4v-fix 4v-<=))
;;            :do-not-induct t)
;;           (witness :ruleset 4v-sexpr-fixpoint-lower-boundp-witnessing)
;;           (and stable-under-simplificationp
;;                '(:use ((:instance 4v-sexpr-fixpoint-lower-boundp-necc
;;                                   (ups (cdr update-fns))
;;                                   (fp (remove-assoc-hons (caar update-fns) fp0))
;;                                   (env (cons (cons (caar update-fns)
;;                                                    (cdr (hons-assoc-equal
;;                                                          (caar update-fns)
;;                                                          fp0)))
;;                                              env0))
;;                                   (lb (4v-sexpr-fixpoint-spec
;;                                        (cdr update-fns))))))))
;;   :otf-flg t)










;; (defthmd 4v-sexpr-fixpointp-iff-4v-sexpr-alist-equiv
;;   (implies (keys-equiv ups fixpoint)
;;            (iff (4v-sexpr-fixpointp ups fixpoint)
;;                 (4v-sexpr-alist-equiv (4v-sexpr-restrict-alist ups fixpoint)
;;                                       fixpoint)))
;;   :hints(("Goal" :in-theory (enable 4v-sexpr-alist-equiv-fixpoint)
;;           :do-not-induct t)
;;          (witness :ruleset (4v-sexpr-fixpointp-witnessing
;;                             4v-sexpr-alist-equiv-example))))