File: renamings.lisp

package info (click to toggle)
acl2 8.3dfsg-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 309,408 kB
  • sloc: lisp: 3,311,842; javascript: 22,569; cpp: 9,029; ansic: 7,872; perl: 6,501; xml: 3,838; java: 3,738; makefile: 3,383; ruby: 2,633; sh: 2,489; ml: 763; python: 741; yacc: 721; awk: 260; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (1016 lines) | stat: -rw-r--r-- 32,596 bytes parent folder | download | duplicates (2)
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
;;; renamings.lisp
;;; Renamings variables of a term. Renamings substitutions. Properties.
;;; Created 24-10-99. Last modified: 15-02-2001
;;; =============================================================================


#| To certify this book:

(in-package "ACL2")

(certify-book "renamings")

|#

(in-package "ACL2")
(include-book "subsumption")


;;; ******************************************************
;;; RENAMING SUBSTITUTIONS. THE "RENAMED" EQUIVALENCE.
;;; A PARTICULAR RENAMING: NUMBER-RENAME
;;; ******************************************************

;;; In this book:
;;; - The equivalence relation "renamed": one term t1 is a renamed version
;;;   of t2 if (subs t1 t2) and (subs t2 t1).
;;; - Definition of the concept of renaming substitutions and the main
;;;   property of renamings with respect to the renamed equivalence: t2 is
;;;   a renamed version of t1 iff there exists a renaming s.t. its
;;;   domain contains the variables of t1 and applied to t1 is equal to
;;;   t2.
;;; - Definition and properties of a particular kind of renaming
;;;   (number-renaming) and guard verification. This "number-renaming"
;;;   will be defined for terms and for lists of terms.


;;; ============================================================================
;;; 1. The "renamed" equivalence
;;; ============================================================================

;;; ====== RENAMED

(defun renamed (t1 t2)
  (if (subs t1 t2)
      (if (subs t2 t1) t nil)
    nil))

(defequiv renamed
  :hints (("Goal" :in-theory
	   (enable subsumption-transitive))))

;;; And congruences:

(defcong renamed iff (subs t1 t2) 1
    :hints (("Goal" :in-theory
	   (enable subsumption-transitive))))

(defcong renamed iff (subs t1 t2) 2
    :hints (("Goal" :in-theory
	   (enable subsumption-transitive))))



;;; ============================================================================
;;; 2. Renaming variables: definition and properties.
;;; ============================================================================

;;; ----------------------------------------------------------------------------
;;; 2.1 Definition
;;; ----------------------------------------------------------------------------

;;; ======= VARIABLE-SUBSTITUTION

(defun variable-substitution (sigma)
  (if (atom sigma)
      t
    (and (variable-p (cdar sigma))
	 (variable-substitution (cdr sigma)))))

(local
 (defthm variable-substitution-value-variable-p
   (implies (and (variable-substitution sigma)
		 (variable-p term))
	    (variable-p (val term sigma)))))

;;; ======= RENAMING

(defun renaming (sigma)
  (and (variable-substitution sigma)
       (setp (co-domain sigma))))


;;; In the following, we will prove the main property of renamings: "t2
;;; is a renamed version of t1 iff there exists a renaming sigma
;;; s.t. its domain is a set containing the variables of t1 and that
;;; applied to t1 is equal to t2"


;;; ----------------------------------------------------------------------------
;;; 2.2 Renaming implies renamed
;;; ----------------------------------------------------------------------------


;;; ············································································
;;; 2.2.1 An important lemma
;;; ············································································

;;; We will show that the inverse substitution of a renaming is its
;;; inverse function, in some sense.

(encapsulate
 ()

 (local
  (defthm val-val-inverse-lemma
    (implies (and
	      (member x (domain sigma))
	      (equal (val x sigma) y))
	     (member y (co-domain sigma)))))

;;; If sigma is a substitution such that its co-domain is a set of
;;; variables, then sigma^{-1}(sigma(x)) = x, for all x in
;;; domain(sigma). Remeber that a renaming is a substitution such that
;;; its co-domain are sets of variables (no duplicated
;;; elements)

 (local
  (defthm val-val-inverse-renaming
    (implies (and (renaming sigma)
		  (member x (domain sigma)))
	     (equal (val (val x sigma) (inverse sigma)) x))))

;;; The main theorem:
;;; If the variables of t1 are in the domain of sigma, then
;;; sigma^{-1}(sigma(t1)) = t1, whenever sigma is a substitution with a
;;; set of variables as its co-domain. This theorema will be needed also
;;; in subsumption-well-founded.lisp

  (defthm renaming-inverse
    (implies (and
	      (renaming sigma)
	      (subsetp (variables flg term) (domain sigma)))
	     (equal
	      (apply-subst flg (inverse sigma) (apply-subst flg sigma term))
	      term))))


;;; ············································································
;;; 2.2.2 And the intended property
;;; ············································································


(defthm renaming-implies-renamed
  (implies (and
	    (renaming sigma)
	    (subsetp (variables t term) (domain sigma)))
	   (renamed (instance term sigma) term))
  :hints (("Goal" :use (:instance subs-completeness
				  (t1 (instance term sigma))
				  (t2 term)
				  (sigma (inverse sigma))))))

;;; ----------------------------------------------------------------------------
;;; 2.3 Renamed implies renaming
;;; ----------------------------------------------------------------------------

;;; We will show that when (subs t1 t2) and (subs t2 t1), then
;;; (normal-form-subst t (matching t1 t2) t1) is a renaming s.t.
;;; applied to t1 is equal to t2.

;;; Note that the condition (subs term t2) and (subs t2 term) can be
;;; stated in terms of apply-subst: that is the same to say that
;;; there exists two substitutions sigma and delta such that:
;;;  (equal (apply-subst flg delta (apply-subst flg sigma term))
;;;		   term)

;;; Let sigmar = (normal-form-subst flg sigma term). We have to prove
;;; the two following properties:
;;;  * (variable-substitution sigmar)
;;;  * (co-domain sigmar) is a setp.


;;; ············································································
;;; 2.3.1 sigmar is a variable-substitution
;;; ············································································

(local
 (encapsulate
  ()

  (local
   (defthm renamed-implies-variable-val-lemma
     (implies (and flg (variable-p (apply-subst flg delta (val term sigma))))
	      (variable-p (val term sigma)))
     :rule-classes nil))


  (local
   (defthm renamed-implies-variable-val
     (implies (and
	       (equal (apply-subst flg delta (apply-subst flg sigma term))
		      term)
	       (member x (variables flg term)))
	      (variable-p (val x sigma)))
     :hints (("Subgoal *1/1"
	      :use renamed-implies-variable-val-lemma))))

  (local
   (defthm renamed-implies-variable-substitution-main-lemma
     (implies (and
	       (equal (apply-subst flg delta (apply-subst flg sigma term))
		      term)
	       (subsetp l (variables flg term)))
	      (variable-substitution (restriction sigma l)))
     :hints (("Goal" :induct (len l)))))

  (defthm renamed-implies-variable-substitution
    (implies
     (equal (apply-subst flg delta (apply-subst flg sigma term)) term)
     (variable-substitution (normal-form-subst flg sigma term)))
    :hints (("Goal" :use
	     (:instance renamed-implies-variable-substitution-main-lemma
			(l (make-set (variables flg term)))))))))

;;; ············································································
;;; 2.3.2 An important lemma
;;; ············································································

;;; When (equal (apply-subst flg delta (apply-subst flg sigma term))
;;; term) then two different variables of term cannot have the the value
;;; with respect to sigma


(local
 (encapsulate
  ()

  (local
   (defthm renamed-implies-injective-val-lemma
     (implies (and
	       (equal (instance (val x sigma) delta) x)
	       (equal (instance (val y sigma) delta) y)
	       (not (equal x y)))
	      (not (equal (val x sigma) (val y sigma))))
     :rule-classes nil))

  (local
   (defthm identity-on-term-identity-val
     (implies (and
	       (equal (apply-subst flg delta (apply-subst flg sigma term))
		      term)
	       (member x (variables flg term)))
	      (equal (instance (val x sigma) delta) x))
     :rule-classes nil))

  (defthm  renamed-implies-injective-val
    (implies (and
	      (equal (apply-subst flg delta (apply-subst flg sigma term))
		     term)
	      (member x (variables flg term))
	      (member y (variables flg term))
	      (not (equal x y)))
	     (not (equal (val x sigma) (val y sigma))))
    :hints (("Goal" :use ((:instance renamed-implies-injective-val-lemma)
			  (:instance identity-on-term-identity-val)
			  (:instance identity-on-term-identity-val
				     (x y))))))))


;;; ············································································
;;; 2.3.2 co-domain of sigmar is a setp
;;; ············································································



(local
 (encapsulate

  ()

  (local
   (defthm  renamed-implies-setp-codomain-main-lemma
     (implies (and
	       (equal (apply-subst flg delta (apply-subst flg sigma term))
		      term)
	       (setp l)
	       (subsetp l (variables flg term)))
	      (setp (co-domain (restriction sigma l))))
     :hints (("Goal" :induct (setp l))
	     ("Subgoal *1/2'4'" :induct (len l2)))))


 (defthm renamed-implies-setp-codomain
    (implies
     (equal (apply-subst flg delta (apply-subst flg sigma term)) term)
     (setp (co-domain (normal-form-subst flg sigma term))))
    :hints (("Goal" :use
	     (:instance renamed-implies-setp-codomain-main-lemma
			(l (make-set (variables flg term)))))))))

;;; ············································································
;;; 2.3.3 sigmar is a renaming
;;; ············································································

(local
 (defthm renamed-implies-renaming-main-lemma
   (implies
    (equal (apply-subst flg delta (apply-subst flg sigma term)) term)
    (renaming (normal-form-subst flg sigma term)))
   :rule-classes nil))


(defthm renamed-implies-renaming
  (let ((ren (normal-form-subst t (matching t1 t2) t1)))
    (implies (renamed t1 t2)
	     (and (renaming ren)
		  (equal (instance t1 ren) t2))))
  :hints (("Goal" :use
	   (:instance renamed-implies-renaming-main-lemma
		      (term t1) (sigma (matching t1 t2))
		      (delta (matching t2 t1))
		      (flg t)))))


;;; ============================================================================
;;; 3. Number renamings: a special kind of renaming.
;;; ============================================================================

;;; We will define number-renaming. We rename the term enumerating the
;;; variables, starting from a given number x and incrementing by y.


;;; ----------------------------------------------------------------------------
;;; 3.1 Number renaming.
;;; ----------------------------------------------------------------------------


;;; As we said before, this is a special kind of renaming. Every
;;; variable is substituted in a sound way for a number. This could be
;;; done very easiliy in two rounds. First compute the renaming
;;; substitution and then apply the renaming to obtain the renamed
;;; version of the term. Since this will be a procedure to apply very
;;; often, we implement here in a more eficcient way: the renaming and
;;; the renamed term are computed at the same time.

;;; The definition:

(defun number-rename-aux (flg term sigma x y)
  (declare (xargs :guard (and (term-p-aux flg term)
			      (acl2-numberp x)
			      (acl2-numberp y)
			      (alistp-acl2-numberp sigma))
		  :verify-guards nil))
  (if flg
      (if (variable-p term)
	  (let ((find-term (assoc term sigma)))
	    (if find-term
		(mv (cdr find-term) sigma)
	      (let ((z (if (endp sigma) x (+ y (cdar sigma)))))
		(mv z (cons (cons term z) sigma)))))
	(mv-let (renamed-args renaming-args)
		(number-rename-aux nil (cdr term) sigma x y)
		(mv (cons (car term) renamed-args) renaming-args)))
    (if (endp term)
	(mv term sigma)
      (mv-let (renamed-car renaming-car)
	      (number-rename-aux t (car term) sigma x y)
	      (mv-let (renamed-cdr renaming-cdr)
		      (number-rename-aux nil (cdr term) renaming-car x y)
		      (mv (cons renamed-car renamed-cdr)
			  renaming-cdr))))))
;;; REMARK : x is only needed when sigma is endp and no
;;; longer. It can be considered as a constant.




;;; Guard verification

(local
 (defthm alistp-acl2-numberp-alistp
   (implies (alistp-acl2-numberp l)
	    (alistp l))
   :rule-classes :forward-chaining))

(local
 (defthm alistp-acl2-numberp-second-number-rename-aux
   (implies (and (alistp-acl2-numberp sigma)
		 (acl2-numberp x))
	    (alistp-acl2-numberp
	     (second (number-rename-aux flg term sigma x y))))))


(verify-guards number-rename-aux)

;;; ----------------------------------------------------------------------------
;;; 3.2 Number-rename-aux: closure properties
;;; ----------------------------------------------------------------------------
;;; The results in this subsection are needed for further guard
;;; verification of functions using number-rename-aux and for the proof
;;; of closure properties of number-rename



(local
 (defthm number-rename-aux-substitution-s-p
   (implies (and (acl2-numberp x)
		 (term-s-p-aux flg term)
		 (substitution-s-p sigma))
	    (substitution-s-p
	     (second (number-rename-aux flg term sigma x y))))))

;;; Needed for closure property:


(local
 (encapsulate
  ()

  (local
   (defthm number-rename-aux-equal-len
     (equal (len (first (number-rename-aux nil term sigma x y)))
	    (len term))))

  (defthm number-rename-aux-term-s-p-aux
    (implies (and (acl2-numberp x)
		  (term-s-p-aux flg term)
		  (alistp-acl2-numberp sigma))
	     (term-s-p-aux
	      flg (first (number-rename-aux flg term sigma x y)))))))




;;; ----------------------------------------------------------------------------
;;; 3.3 Number-rename-aux: main properties.
;;; ----------------------------------------------------------------------------

;;; ············································································
;;; 3.3.1 Previous (local) lemmas about coincide.
;;; ············································································

;;; We will need these lemmas because we are going to talk about
;;; extensions (see the definition in terms.lisp, subsection 2.3)

;;; ====== COINCIDE. See definition and properties in terms.lisp

(local
 (encapsulate
  ()

  (local
   (defthm coincide-main-property
     (implies (and (coincide sigma1 sigma2 l)
		   (member x l))
	      (equal (equal (val x sigma1) (val x sigma2)) t))))

;;; REMARK: The form of the rule avoids non-termination
;;; This rule is also local in terms.lisp. We don't want terms.lisp to
;;; export everywhere. That's the reason why we repeat here the rule.


  (defthm coincide-conmutative
    (implies (coincide a b l)
	     (coincide b a l)))


  (in-theory (disable coincide-conmutative))

  (defthm coincide-cons
    (implies (and
	      (not (member x l))
	      (coincide sigma sigma1 l))
	     (coincide (cons (cons x y) sigma) sigma1 l)))


  (defthm coincide-subsetp-transitive
    (implies (and (coincide sigma sigma1 l)
		  (coincide sigma1 sigma2 m)
		  (subsetp  l m))
	     (coincide sigma sigma2 l)))

  (in-theory (disable coincide-subsetp-transitive))))


;;; ············································································
;;; 3.3.2 Previous (local) lemmas about acl2-numberp-list-increment
;;; ············································································

;;; We will define and prove some local properties of the concept of
;;; being a list of numbers l such that each of its elements is obtained
;;; incrementing the previous one by a constant y.

;;; ====== ACL2-NUMBERP-LIST-INCREMENT

(local
 (defun acl2-numberp-list-increment (l y)
   (cond ((endp l) t)
	 ((endp (cdr l)) (acl2-numberp (first l)))
	 (t (and (acl2-numberp (first l))
		 (= y (- (first l) (second l)))
		 (acl2-numberp-list-increment (cdr l) y))))))

(local
 (encapsulate
  ()

  (local
   (defthm acl2-numberp-list-increment-setp-1-lema
     (implies (and (acl2-numberp-list-increment l y)
		   (consp l)
		   (> y 0)
		   (> x (first l)))
	      (not (member x l)))))

  (local
   (defthm acl2-numberp-list-increment-setp-1
     (implies (and (acl2-numberp-list-increment l y)
		   (> y 0))
	      (setp l))))

  (local
   (defthm acl2-numberp-list-increment-setp-2-lema
     (implies (and (acl2-numberp-list-increment l y)
		   (consp l)
		   (< y 0)
		   (< x (first l)))
	      (not (member x l)))))

  (local
   (defthm acl2-numberp-list-increment-setp-2
     (implies (and (acl2-numberp-list-increment l y)
		   (< y 0))
	      (setp l))))


  (defthm acl2-numberp-list-increment-setp
    (implies (and (acl2-numberp-list-increment l y)
		  (not (=  y 0)))
	     (setp l))
    :hints (("Goal" :cases ((> y 0) (< y 0)))))))



;;; ············································································
;;; 3.3.3 number-rename-aux: properties of the variables of the returned term
;;; ············································································

;;; We will prove that (first (number-rename-aux flg term sigma x y) is a
;;; term having numeric variables, and:
;;; * if y>0, they are greater than x
;;; * if y<0, they are smaller than x

;;; ===== ACL2-NUMBERP-LIST-SMALLER-THAN

(defun acl2-numberp-list-smaller-than (l x)
  (if (endp l)
      t
    (and (acl2-numberp (first l))
	 (<= (first l) x) (acl2-numberp-list-smaller-than (cdr l) x))))

;;; ===== ACL2-NUMBERP-LIST-BIGGER-THAN

(defun acl2-numberp-list-bigger-than (l x)
  (if (endp l)
      t
    (and
     (acl2-numberp (first l))
     (>= (first l) x) (acl2-numberp-list-bigger-than (cdr l) x))))


(local
 (encapsulate
  ()

  (local
   (defthm acl2-numberp-list-bigger-than-append
     (iff (acl2-numberp-list-bigger-than (append l1 l2) x)
	  (and (acl2-numberp-list-bigger-than l1 x)
	       (acl2-numberp-list-bigger-than l2 x)))))

  (defthm number-renamed-aux-variables->=-x
    (implies (and (acl2-numberp-list-bigger-than (co-domain sigma) x)
		  (> y 0)
		  (acl2-numberp x))
	     (and
	      (acl2-numberp-list-bigger-than
	       (variables
		flg (first (number-rename-aux flg term sigma x y))) x)
	      (acl2-numberp-list-bigger-than
	       (co-domain
		(second (number-rename-aux flg term sigma x y))) x))))


  (local
   (defthm acl2-numberp-list-smaller-than-append
     (iff (acl2-numberp-list-smaller-than (append l1 l2) x)
	  (and (acl2-numberp-list-smaller-than l1 x)
	       (acl2-numberp-list-smaller-than l2 x)))))

  (defthm number-renamed-aux-variables-<=-x
    (implies (and (acl2-numberp-list-smaller-than (co-domain sigma) x)
		  (< y 0)
		  (acl2-numberp x))
	     (and
	      (acl2-numberp-list-smaller-than
	       (variables
		flg (first (number-rename-aux flg term sigma x y))) x)
	      (acl2-numberp-list-smaller-than
	       (co-domain
		(second (number-rename-aux flg term sigma x y))) x))))))


;;; ············································································
;;; 3.3.4 number-rename-aux: Main property of the co-domain of the
;;; returned substitution.
;;; ············································································


(local
 (defthm number-rename-co-domain-acl2-numberp-list-increment
   (implies (and (acl2-numberp-list-increment (co-domain sigma) y)
		 (acl2-numberp x)
		 (acl2-numberp y))
	    (acl2-numberp-list-increment
	     (co-domain (second (number-rename-aux flg term sigma x y))) y))))

;;; ············································································
;;; 3.3.5 number-rename-aux: the substitution returned is a renaming
;;; ············································································


(local
 (encapsulate
  ()

  (local
   (defthm acl2-numberp-list-increment-implies-variable-substitution
     (implies (acl2-numberp-list-increment (co-domain sigma) y)
	      (variable-substitution sigma))))

  (local
   (defthm acl2-numberp-list-increment-implies-renaming
     (implies (and
	       (acl2-numberp-list-increment (co-domain sigma) y)
	       (acl2-numberp y)
	       (not (= y 0)))
	      (renaming sigma))))


  (defthm number-rename-renaming
    (implies (and (acl2-numberp x) (acl2-numberp y) (not (= y 0)))
	     (renaming (second (number-rename-aux flg term nil x y))))
    :hints (("Goal" :use (:instance
			  acl2-numberp-list-increment-implies-renaming
			  (sigma
			   (second
			    (number-rename-aux flg term nil x y)))))))))



;;; ············································································
;;; 3.3.3 Subsumption properties of number-rename-aux
;;; ············································································


;;; 3.3.3.1
;;; The substituion returned by  number-rename-aux, applied to the input
;;; term returns the returned term (i.e term subsumes the
;;; number-rename-aux term)
;;; ··········································································

;;; Two previos lemmas:


(local
 (defthm number-rename-invariants
   (let ((number-renaming-aux
	  (second (number-rename-aux flg t1 sigma x y))))
     (implies (alistp sigma)
	      (and
	       (alistp number-renaming-aux)
	       (subsetp (domain sigma) (domain number-renaming-aux))
	       (extension number-renaming-aux sigma)
	       (subsetp (variables flg t1) (domain number-renaming-aux)))))
   :hints (("Goal"
	    :in-theory (enable
			subsetp-transitive
			coincide-conmutative
			coincide-subsetp-transitive)))))

(local
 (defthm number-rename-incremental
   (implies (alistp sigma)
	    (equal (apply-subst
		    flg1
		    (second (number-rename-aux
			     flg2 t2
			     (second (number-rename-aux
				      flg1 t1 sigma x1 y1)) x2 y2))
		    t1)
		   (apply-subst
		    flg1
		    (second (number-rename-aux flg1 t1 sigma x1 y1))
		    t1)))
   :hints (("Goal" :use
	    (:instance coincide-in-term
		       (flg flg1)
		       (sigma2
			(second
			 (number-rename-aux
			  flg2 t2
			  (second (number-rename-aux flg1 t1 sigma x1 y1))
			  x2 y2)))
		       (term t1)
		       (sigma1
			(second (number-rename-aux flg1 t1 sigma x1 y1)))
		       (l
			(domain
			 (second
			  (number-rename-aux flg1 t1 sigma x1 y1)))))))))


;;; And the main result:
(local
 (defthm term-subsumes-number-renamed-aux-term
   (implies (alistp sigma)
	    (equal
	     (apply-subst flg (second (number-rename-aux flg term sigma
							 x y))
			  term)
	     (first (number-rename-aux flg term sigma x y))))))



;;; 3.3.3.2
;;; The term returned by number-rename-aux subsumes the input term
;;; ···································································

(local
 (encapsulate
  ()
  (local
   (defthm number-renamed-aux-term-subsumes-term-lemma
     (implies (and (acl2-numberp x) (acl2-numberp y) (not (= y 0)))
	      (equal
	       (apply-subst
		flg
		(inverse (second (number-rename-aux flg term nil x y)))
		(apply-subst flg (second (number-rename-aux flg term nil
							    x y))
			     term))
	       term))
     :hints (("Goal"
	      :in-theory (disable renaming
				  term-subsumes-number-renamed-aux-term)))
     :rule-classes nil))

  (defthm number-renamed-aux-term-subsumes-term
    (implies (and (acl2-numberp x) (acl2-numberp y) (not (= y 0)))
	     (equal
	      (apply-subst
	       flg
	       (inverse (second (number-rename-aux flg term nil x y)))
	       (first (number-rename-aux flg term nil x y)))
	      term))
    :hints (("Goal"
	     :use (:instance number-renamed-aux-term-subsumes-term-lemma))))))


;;; ----------------------------------------------------------------------------
;;; 3.4 Number-rename: definition and main (non-local) properties
;;; ----------------------------------------------------------------------------

;;; Here we compile the results of section 3.

(defun number-rename (term x y)
  (declare (xargs :guard (and (term-p term)
			      (acl2-numberp x)
			      (acl2-numberp y))))
  (mv-let (renamed renaming)
	  (number-rename-aux t term nil x y)
	  (declare (ignore renaming))
	  renamed))


;;; The following lemma can be useful: number-rename never returns the
;;; term nil (instead, it could return the number x). So there are no
;;; confussion between nil as fail and nil as term.

(defthm number-rename-not-nil
  (implies (acl2-numberp x)
	   (number-rename term x y)))

;;; Subsumption properties:

(defthm term-subsumes-number-renamed-term
  (subs term (number-rename term x y))

  :hints (("Goal" :use
	   (:instance subs-completeness
		       (t1 term)
		       (t2 (number-rename term x y))
		       (sigma
			(second (number-rename-aux t term nil x y)))))))

(defthm number-renamed-term-subsumes-term
  (implies (and (acl2-numberp x) (acl2-numberp y) (not (= y 0)))
	   (subs (number-rename term x y) term))

  :hints (("Goal" :use
	   (:instance subs-completeness
		       (t2 term)
		       (t1 (number-rename term x y))
		       (sigma
			(inverse
			 (second (number-rename-aux t term nil x y))))))))


;;; Variables of (number-rename term x y) are:
;;; * if y>0, they are all bigger than x
;;; * if y<0, they are all smaller than x

(defthm number-renamed-variables->=-x
   (implies (and (acl2-numberp x) (> y 0))
	    (acl2-numberp-list-bigger-than
	     (variables t (number-rename term x y))
	     x)))


(defthm number-renamed-variables-<=-x
   (implies (and (acl2-numberp x) (< y 0))
	    (acl2-numberp-list-smaller-than
	     (variables t (number-rename term x y))
	     x)))

;;; An useful property for standardization apart:
(encapsulate
 ()

 (local
  (defthm smaller-bigger-disjointp
    (implies (and
	      (< x1 x2)
	      (acl2-numberp-list-smaller-than l1 x1)
	      (acl2-numberp-list-bigger-than l2 x2))
	     (disjointp l1 l2))))

 (defthm number-rename-standardization-apart
   (implies (and (acl2-numberp x1)
		 (acl2-numberp x2)
		 (< x1 x2)
		 (< y1 0)
		 (< 0 y2))
	    (disjointp (variables t (number-rename t1 x1 y1))
		       (variables t (number-rename t2 x2 y2))))
   :hints (("Goal" :use
	    (:instance
	     smaller-bigger-disjointp
	     (l1 (variables t (number-rename t1 x1 y1)))
	     (l2 (variables t (number-rename t2 x2 y2))))))))


;;; Closure property:


(defthm number-rename-term-s-p
  (implies (and (acl2-numberp x) (term-s-p term))
	   (term-s-p (number-rename term x y))))


;;; Needed for guard verification:

(defthm number-rename-term-p
  (implies (and (acl2-numberp x) (term-p term))
	   (term-p (number-rename term x y)))
  :hints (("Goal" :use (:functional-instance
			number-rename-term-s-p
			(signat (lambda (x n) (eqlablep x)))
			(term-s-p-aux term-p-aux)))))

;;; We have extracted the main properties of number-rename, so we now
;;; disable its definition:
(in-theory (disable number-rename))


;;; A rewriting congruence rule:

(defthm number-renamed-term-renamed-term
  (implies (and (acl2-numberp x) (acl2-numberp y) (not (= y 0)))
	   (renamed (number-rename term x y) term)))


;;; ----------------------------------------------------------------------------
;;; 3.5 Number-rename-list: definition and main (non-local) properties
;;; ----------------------------------------------------------------------------

;;; Renaming lists of terms
;;; Although we are going just to repeat the above development, now for
;;; lists of terms, we think it is convinient to define separately
;;; number-rename from number-rename-list, although they are diferent
;;; particular cases of the same function: number-rename-aux.

;;; Sometimes (see for example critical-pairs.lisp) we will need to
;;; rename several terms at the same time (for example, both terms of a
;;; rewriting rule). In such cases we want the same variable to be
;;; replaced for the same number, wherever that variable occurs in the
;;; list (even in diferent terms of the list). That's the reason why we
;;; define number-rename-list and its properties as non-local in this
;;; book.

(defun number-rename-list (l x y)
  (declare (xargs :guard (and (term-p-aux nil l)
			      (acl2-numberp x)
			      (acl2-numberp y))))
  (mv-let (renamed renaming)
	  (number-rename-aux nil l nil x y)
	  (declare (ignore renaming))
	  renamed))


;;; Subsumption properties:

(defthm list-subsumes-number-renamed-list-
  (subs-list l (number-rename-list l x y))

  :hints (("Goal" :use
	   (:instance subs-list-completeness
		       (l1 l)
		       (l2 (number-rename-list l x y))
		       (sigma
			(second (number-rename-aux nil l nil x y)))))))

(defthm number-renamed-list-subsumes-list
  (implies (and (acl2-numberp x) (acl2-numberp y) (not (= y 0)))
	   (subs-list (number-rename-list l x y) l))

  :hints (("Goal" :use
	   (:instance subs-list-completeness
		       (l2 l)
		       (l1 (number-rename-list l x y))
		       (sigma
			(inverse
			 (second (number-rename-aux nil l nil x y))))))))


;;; Variables of (number-rename term x y) are:
;;; * if y>0, they are all bigger than x
;;; * if y<0, they are all smaller than x

(defthm number-renamed-list-variables->=-x
   (implies (and (acl2-numberp x) (> y 0))
	    (acl2-numberp-list-bigger-than
	     (variables nil (number-rename-list term x y))
	     x)))


(defthm number-renamed-list-variables-<=-x
   (implies (and (acl2-numberp x) (< y 0))
	    (acl2-numberp-list-smaller-than
	     (variables nil (number-rename-list term x y))
	     x)))

;;; An useful property for standardization apart:
(encapsulate
 ()

 (local
  (defthm smaller-bigger-disjointp
    (implies (and
	      (< x1 x2)
	      (acl2-numberp-list-smaller-than l1 x1)
	      (acl2-numberp-list-bigger-than l2 x2))
	     (disjointp l1 l2))))

 (defthm number-rename-list-standardization-apart
   (implies (and (acl2-numberp x1)
		 (acl2-numberp x2)
		 (< x1 x2)
		 (< y1 0)
		 (< 0 y2))
	    (disjointp (variables nil (number-rename-list l1 x1 y1))
		       (variables nil (number-rename-list l2 x2 y2))))
   :hints (("Goal" :use
	    (:instance
	     smaller-bigger-disjointp
	     (l1 (variables nil (number-rename-list l1 x1 y1)))
	     (l2 (variables nil (number-rename-list l2 x2 y2))))))))


;;; Closure property:


(defthm number-rename-list-term-s-p-aux-nil
  (implies (and (acl2-numberp x) (term-s-p-aux nil l))
	   (term-s-p-aux nil (number-rename-list l x y))))


;;; Needed for guard verification:

(defthm number-rename-list-term-p-aux-nil
  (implies (and (acl2-numberp x) (term-p-aux nil l))
	   (term-p-aux nil (number-rename-list l x y)))
  :hints (("Goal" :use (:functional-instance
			number-rename-list-term-s-p-aux-nil
			(signat (lambda (x n) (eqlablep x)))
			(term-s-p-aux term-p-aux)))))

;;; We have extracted the main properties of number-rename-list, so we now
;;; disable its definition:
(in-theory (disable number-rename-list))