File: listrev.scm

package info (click to toggle)
minlog 4.0.99.20100221-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,060 kB
  • sloc: lisp: 112,614; makefile: 231; sh: 11
file content (823 lines) | stat: -rw-r--r-- 20,698 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
; $Id: listrev.scm 2299 2008-09-25 14:21:01Z schwicht $
(if (not (assoc "nat" ALGEBRAS))
    (myerror "First execute (libload \"nat.scm\")"))

(display "loading listrev.scm ...") (newline)

(add-param-alg "list" 'prefix-typeop
	       '("Nil" "list")
	       '("Cons" "list=>alpha1=>list"))

; Notice that listrev.scm and list.scm cannot be loaded together.
; Reason: In :0::1::2::3 the ":" is a prefix-op (for listrev.scm), but
; in 3::2::1::0: the ":" is a postfix-op (for list.scm).

; Infix notation allowed (and type parameters omitted) for binary 
; constructors, as follows.  This would also work for prefix notation.
; Example: :: for Cons.  :z::y::x
; Here : is prefix for z

(add-token
 "::" 'add-op ;hence left associative
 (lambda (xs x)
   (let ((type (term-to-type x))
	 (listtype (term-to-type xs)))
     (if (and (alg-form? listtype)
	      (string=? "list" (alg-form-to-name listtype))
	      (equal? type (car (alg-form-to-types listtype))))
	 (mk-term-in-app-form
	  (make-term-in-const-form
	   (let* ((constr (constr-name-to-constr "Cons"))
		  (tvars (const-to-tvars constr))
		  (subst (make-substitution tvars (list type))))
	     (const-substitute constr subst #f)))
	  xs x)
	 (myerror "parse error" "types do not fit for" listtype "::" type)))))

(add-display
 (py "list alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "Cons"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'add-op "::"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))

(add-token
 ":" 'prefix-op
 (lambda (x)
   (mk-term-in-app-form
    (make-term-in-const-form
     (let* ((constr (constr-name-to-constr "Cons"))
	    (tvars (const-to-tvars constr))
	    (subst (make-substitution tvars (list (term-to-type x)))))
       (const-substitute constr subst #f)))
    (make-term-in-const-form
     (let* ((constr (constr-name-to-constr "Nil"))
	    (tvars (const-to-tvars constr))
	    (subst (make-substitution tvars (list (term-to-type x)))))
       (const-substitute constr subst #f)))
    x)))

(add-display
 (py "list alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let* ((op (term-in-app-form-to-final-op x))
	      (args (term-in-app-form-to-args x))
	      (revargs (reverse args)))
	 (if (and (term-in-const-form? op)
		  (string=? "Cons" (const-to-name
				    (term-in-const-form-to-const op)))
		  (= 2 (length args))
		  (term-in-const-form? (cadr revargs))
		  (string=? "Nil" (const-to-name
				   (term-in-const-form-to-const
				    (cadr revargs)))))
	     (list 'prefix-op ":" (term-to-token-tree (car revargs)))
	     #f))
       #f)))

(add-program-constant
 "ListAppend" (py "list alpha=>list alpha=>list alpha"))

(add-token
 ":+:" 'mul-op
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form
     (let* ((const (pconst-name-to-pconst "ListAppend"))
	    (tvars (const-to-tvars const))
	    (listtype (term-to-type x))
	    (type (car (alg-form-to-types listtype)))
	    (subst (make-substitution tvars (list type))))
       (const-substitute const subst #f)))
    x y)))

(add-display
 (py "list alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "ListAppend"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'mul-op ":+:"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))

(add-var-name "x" (py "alpha"))
(add-var-name "xs" (py "list alpha"))

(add-computation-rule
 (pt "xs1:+:(Nil alpha)")
 (pt "xs1"))

(add-computation-rule
 (pt "xs1:+:(xs2::x3)")
 (pt "xs1:+:xs2::x3"))

; "ListAppendTotal"
(set-goal (pf "Total(ListAppend alpha)"))
(use "Total")
(use-with "All-AllPartial" (py "list alpha")
	  (make-cterm (pv "xs^") (pf "Total((ListAppend alpha)xs^)"))
	  "?")
(assume "xs1")
(use "Total" 'right)
(use-with "All-AllPartial"  (py "list alpha")
	  (make-cterm (pv "xs^") (pf "Total(xs1:+:xs^)"))
	  "?")
(ind)

; Base
(ng)
(use-with
 "AllPartial-All" (py "list alpha") (make-cterm (pv "xs^") (pf "Total xs^"))
 "?" (pt "xs1"))
(assume "xs^" "H1")
(use "H1")

; Step
(assume "xs" "x" "IH")
(ng)
(use-with (make-proof-in-aconst-form
	   (constr-name-to-constr-total-aconst "Cons"))
	  (py "alpha") (pt "xs1:+:xs") (pt "x") "IH" "?")
(use-with
 "AllPartial-All" (py "alpha") (make-cterm (pv "x^") (pf "Total x^"))
 "?" (pt "x"))
(assume "x^" "H1")
(use "H1")
; Proof finished.
(save "ListAppendTotal")


; "ListAppendNil"
(set-goal (pf "all xs Equal((Nil alpha):+:xs)xs"))
(ind)
(use "Eq-Refl")
(assume "xs" "x" "IH")
(ng)
(simp "IH")
(use "Eq-Refl")
; Proof finished.
(save "ListAppendNil")

(add-rewrite-rule (pt "(Nil alpha):+:xs") (pt "xs"))


; ; "ListAppendNilPartial"
; (set-goal (pf "all xs^(STotal xs^ -> Equal((Nil alpha):+:xs^)xs^)"))
; (ind)
; (use "Eq-Refl")
; (assume "xs^" "x^" "SE xs^" "IH")
; (ng)
; (simp "IH")
; (use "Eq-Refl")
; ; Proof finished.
; (save "ListAppendNilPartial")


(add-program-constant "ListLength" (py "list alpha=>nat") t-deg-zero)

(add-token
 "Lh" 'prefix-op 
 (lambda (x) (make-term-in-app-form
	      (make-term-in-const-form
	       (let* ((const (pconst-name-to-pconst "ListLength"))
		      (tvars (const-to-tvars const))
		      (listtype (term-to-type x))
		      (type (car (alg-form-to-types listtype)))
		      (subst (make-substitution tvars (list type))))
		 (const-substitute const subst #f)))
	      x)))

(add-display
 (py "nat")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-op x)))
	 (if (and (term-in-const-form? op)
		  (string=? "ListLength"
			    (const-to-name (term-in-const-form-to-const op))))
	     (list 'prefix-op "Lh"
		   (term-to-token-tree (term-in-app-form-to-arg x)))
	     #f))
       #f)))

(add-computation-rule (pt "Lh(Nil alpha)") (pt "Zero"))
(add-computation-rule (pt "Lh(xs::x)") (pt "Succ Lh xs"))


; "ListLengthTotal"
(set-goal (pf "Total(ListLength alpha)"))
(use "Total")
(use-with "All-AllPartial" (py "list alpha")
	  (make-cterm (pv "xs^") (pf "Total((ListLength alpha)xs^)"))
	  "?")
(ind)
; Base
(ng)
(use (make-proof-in-aconst-form (finalg-to-e-to-total-aconst (py "nat"))))
(use "Truth-Axiom")
; Step
(assume "xs" "x" "IH")
(ng)
(use (make-proof-in-aconst-form (finalg-to-e-to-total-aconst (py "nat"))))
(ng)
(use (make-proof-in-aconst-form (finalg-to-total-to-e-aconst (py "nat"))))
(use "IH")
; Proof finished.
(save "ListLengthTotal")


; "LhAppend"
(set-goal (pf "all xs1,xs2 Lh(xs1:+:xs2)=Lh xs1+Lh xs2"))
(assume "xs1")
(ind)
; Base
(ng)
(use "Truth-Axiom")
; Step
(assume "xs2" "x" "IH")
(ng)
(simp "IH")
(use "Truth-Axiom")
; Proof finished.
(save "LhAppend")

(add-rewrite-rule (pt "Lh(xs1:+:xs2)") (pt "Lh xs1+Lh xs2"))


; Now for projection ListProj.  We use the rule (Nil alpha)__n ->
; (Inhab alpha)

(add-program-constant
 "ListProj" (py "list alpha=>nat=>alpha") t-deg-zero 'const 1)

(add-token
 "__" 'mul-op ;hence left associative
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form
     (let* ((const (pconst-name-to-pconst "ListProj"))
	    (tvars (const-to-tvars const))
	    (listtype (term-to-type x))
	    (type (car (alg-form-to-types listtype)))
	    (subst (make-substitution tvars (list type))))
       (const-substitute const subst #f)))
    x y)))

(add-display
 (py "alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "ListProj"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'mul-op "__"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))

(add-token
 "Proj" 'prefix-op
 (lambda (x) (make-term-in-app-form
	      (make-term-in-const-form
	       (let* ((const (pconst-name-to-pconst "ListProj"))
		      (tvars (const-to-tvars const))
		      (listtype (term-to-type x))
		      (type (car (alg-form-to-types listtype)))
		      (subst (make-substitution tvars (list type))))
		 (const-substitute const subst #f)))
	      x)))

(add-display
 (py "nat=>alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "ListProj"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 1 (length args)))
	     (list 'prefix-op "Proj"
		   (term-to-token-tree (car args)))
	     #f))
       #f)))

(add-computation-rule (pt "Proj(Nil alpha)") (pt "[nat](Inhab alpha)"))

(add-computation-rule
 (pt "Proj(xs::x)")
 (pt "[n][if (n<Lh xs) (xs__n)
             [if (n=Lh xs) x (Inhab alpha)]]"))

; (pp (nt (pt "(:0::1::2::3)__1")))
; 1
; (pp (nt (pt "(:True::True::False::True)__1")))
; True
; (pp (nt (pt "(Nil boole)__27")))
; (Inhab boole)

; "ListProjTotal"
(set-goal (pf "Total(ListProj alpha)"))
(use "Total")
(use-with "All-AllPartial" (py "list alpha")
	  (make-cterm (pv "xs^") (pf "Total(Proj xs^)"))
	  "?")
(ind)
; Base
(ng)
(use "Total")
(use "All-AllPartial")
(ng)
(assume "n")
; ?_10: Total(Inhab alpha)
(use "InhabTotal")

; Step
(assume "xs" "x" "IH")
(ng)
(use "Total")
(use "All-AllPartial")
(assume "n")
(ng)
(cases (pt "n<Lh xs"))
(assume "n<Lh xs")
(ng)
(use "Total")
(use "IH")
(use (make-proof-in-aconst-form (finalg-to-e-to-total-aconst (py "nat"))))
(ng)
(use "Truth-Axiom")
(assume "n<Lh xs -> F")
(ng)
(cases (pt "n=Lh xs"))
(assume "n=Lh xs")
(ng)
(use-with
 "AllPartial-All" (py "alpha") (make-cterm (pv "x^") (pf "Total x^"))
 "?" (pt "x"))
(assume "x^" "H1")
(use "H1")
(assume "n=Lh xs -> F")
(ng)
(use "InhabTotal")
; Proof finished.
(save "ListProjTotal")

(add-program-constant
 "ListFBar" (py "(nat=>alpha)=>nat=>list alpha") t-deg-zero)

(add-token
 "fbar" 'pair-op ;hence right associative
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form
     (let* ((const (pconst-name-to-pconst "ListFBar"))
	    (tvars (const-to-tvars const))
	    (fcttype (term-to-type x))
	    (type (car (alg-form-to-types fcttype)))
	    (subst (make-substitution tvars (list type))))
       (const-substitute const subst #f)))
    x y)))

(add-display
 (py "list alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "ListFBar"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'pair-op "fbar"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))

(add-computation-rule (pt "nat=>alpha fbar 0") (pt "(Nil alpha)"))

(add-computation-rule (pt "nat=>alpha fbar Succ n")
		      (pt "(nat=>alpha fbar n)::(nat=>alpha n)"))

; (pp (nt (pt "Succ fbar 4")))
; (pp (nt (pt "([n]n+3)fbar 4")))


; "ListFBarTotal"
(set-goal (pf "Total(ListFBar alpha)"))
(use "Total")
(use-with "All-AllPartial" (py "nat=>alpha")
	  (make-cterm (pv "(nat=>alpha)^")
		      (pf "Total((ListFBar alpha)(nat=>alpha)^)"))
	  "?")
(assume "nat=>alpha")
(use "Total" 'right)
(use-with "All-AllPartial"  (py "nat")
	  (make-cterm (pv "n^") (pf "Total((nat=>alpha)fbar n^)"))
	  "?")
(ind)

; Base
(ng)
(use-with (make-proof-in-aconst-form
	   (constr-name-to-constr-total-aconst "Nil"))
	  (py "alpha"))

; Step
(assume "n" "IH")
(ng)
(use-with (make-proof-in-aconst-form
	   (constr-name-to-constr-total-aconst "Cons"))
	  (py "alpha") (pt "(nat=>alpha)fbar n") (pt "(nat=>alpha)n") "IH" "?")
(use-with
 "AllPartial-All" (py "alpha") (make-cterm (pv "x^") (pf "Total x^"))
 "?" (pt "(nat=>alpha)n"))
(assume "x^" "H1")
(use "H1")
; Proof finished.
(save "ListFBarTotal")


; We use (a bar n) as notation for ((Proj a)fbar n).

(add-token
 "bar" 'add-op ;hence left associative
 (lambda (a n)
   (let* ((listtype (term-to-type a))
	  (type (car (alg-form-to-types listtype)))
	  (projconst (let* ((const (pconst-name-to-pconst "ListProj"))
			    (tvars (const-to-tvars const))
			    (subst (make-substitution tvars (list type))))
		       (const-substitute const subst #f)))
	  (fbarconst (let* ((const (pconst-name-to-pconst "ListFBar"))
			    (tvars (const-to-tvars const))
			    (subst (make-substitution tvars (list type))))
		       (const-substitute const subst #f))))
     (mk-term-in-app-form
      (make-term-in-const-form fbarconst)
      (make-term-in-app-form (make-term-in-const-form projconst)
			     a)
      n))))

(add-display
 (py "list alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if
	  (and (term-in-const-form? op)
	       (string=? "ListFBar" 
			 (const-to-name (term-in-const-form-to-const op)))
	       (= 2 (length args)))
	  (let* ((arg1 (car args))
		 (arg1op (term-in-app-form-to-final-op arg1))
		 (arg1args (term-in-app-form-to-args arg1)))
	    (if
	     (and (term-in-const-form? arg1op)
		  (string=? "ListProj"
			    (const-to-name
			     (term-in-const-form-to-const arg1op)))
		  (= 1 (length arg1args)))
	     (list 'add-op "bar"
		   (term-to-token-tree (car arg1args))
		   (term-to-token-tree (cadr args)))
	     #f))
	  #f))
       #f)))

; (pp (pt "(list boole)bar nat"))
; (pp (pt "Proj(list boole)"))

(set-goal (pf "all (nat=>alpha)^,n Lh((nat=>alpha)^ fbar n)=n"))
(assume "(nat=>alpha)^")
(ind)
(use "Truth-Axiom")
(assume "n" "IH")
(use "IH")

(add-rewrite-rule (pt "Lh((nat=>alpha)^ fbar n)") (pt "n"))


(add-program-constant
 "ListMap" (py "(alpha1=>alpha2)=>list alpha1=>list alpha2") t-deg-zero)

(add-token
 "map" 'pair-op ;hence right associative
 (lambda (x y)
   (mk-term-in-app-form
    (make-term-in-const-form
     (let* ((const (pconst-name-to-pconst "ListMap"))
	    (tvars (const-to-tvars const))
	    (listtype (term-to-type y))
	    (type1 (car (alg-form-to-types listtype)))
	    (type2 (arrow-form-to-val-type (term-to-type x)))
	    (subst (make-substitution tvars (list type1 type2))))
       (const-substitute const subst #f)))
    x y)))

(add-display
 (py "list alpha")
 (lambda (x)
   (if (term-in-app-form? x)
       (let ((op (term-in-app-form-to-final-op x))
	     (args (term-in-app-form-to-args x)))
	 (if (and (term-in-const-form? op)
		  (string=? "ListMap"
			    (const-to-name (term-in-const-form-to-const op)))
		  (= 2 (length args)))
	     (list 'pair-op "map"
		   (term-to-token-tree (car args))
		   (term-to-token-tree (cadr args)))
	     #f))
       #f)))

(add-var-name "phi" (py "alpha1=>alpha2"))

(add-computation-rule (pt "phi map(Nil alpha1)") (pt "(Nil alpha2)"))

(add-var-name "y" (py "alpha1"))
(add-var-name "ys" (py "list alpha1"))
(add-var-name "z" (py "alpha2"))
(add-var-name "zs" (py "list alpha2"))

(add-computation-rule (pt "phi map ys::y") (pt "(phi map ys)::phi y"))

; (pp (nt (pt "Pred map :2::3::4")))


; "ListMapTotal"
(set-goal (pf "Total(ListMap alpha1 alpha2)"))
(use "Total")
(use-with "All-AllPartial" (py "alpha1=>alpha2")
	  (make-cterm (pv "phi^") (pf "Total((ListMap alpha1 alpha2)phi^)"))
	  "?")
(assume "phi")
(use "Total" 'right)
(use-with "All-AllPartial" (py "list alpha1")
	  (make-cterm (pv "ys^") (pf "Total(phi map ys^)"))
	  "?")
(ind)

; Base
(ng)
(use-with (make-proof-in-aconst-form
	   (constr-name-to-constr-total-aconst "Nil"))
	  (py "alpha2"))

; Step
(assume "ys" "y" "IH")
(ng)
(use-with (make-proof-in-aconst-form
	   (constr-name-to-constr-total-aconst "Cons"))
	  (py "alpha2") (pt "phi map ys") (pt "phi y") "IH" "?")
(use-with
 "AllPartial-All" (py "alpha2") (make-cterm (pv "z^") (pf "Total z^"))
 "?" (pt "phi y"))
(assume "z^" "H1")
(use "H1")
; Proof finished.
(save "ListMapTotal")


; "LhMap"
(set-goal (pf "all phi,ys Lh(phi map ys)=Lh ys"))
(assume "phi")
(ind)
(use "Truth-Axiom")
(assume "ys" "y" "IH")
(use "IH")
; Proof finished.
(save "LhMap")


; "LhMapPartial"
(set-goal (pf "all phi^,ys^(STotal ys^ -> Lh(phi^ map ys^)=Lh ys^)"))
(assume "phi^")
(ind)
(use "Truth-Axiom")
(assume "ys^" "y^" "SE ys^" "IH")
(use "IH")
; Proof finished.
(save "LhMapPartial")


; "MapAppend"
(set-goal (pf "all phi,ys1,ys2
               Equal(phi map (ys1:+:ys2))((phi map ys1):+:(phi map ys2))"))
(assume "phi" "ys1")
(ind)
(ng)
(use-with "Eq-Refl" (py "list alpha2")(pt "phi map ys1"))
(assume "ys" "y" "IH")
(ng)
(simp "IH")
(use "Eq-Refl")
; Proof finished.
(save "MapAppend")


; "MapAppendPartial"
(set-goal
 (pf "all phi^,ys^1,ys^2(
       STotal ys^2 ->
       Equal(phi^ map (ys^1:+:ys^2))((phi^ map ys^1):+:(phi^ map ys^2)))"))
(assume "phi^" "ys^1")
(ind)
(ng)
(use-with "Eq-Refl" (py "list alpha2")(pt "phi^ map ys^1"))
(assume "ys^" "y^" "SE ys^" "IH")
(ng)
(simp "IH")
(use "Eq-Refl")
; Proof finished.
(save "MapAppendPartial")


; "MapFbar"
(set-goal
 (pf "all (nat=>alpha1)^,phi^,n 
       Equal(phi^ map (nat=>alpha1)^ fbar n)
            (([n]phi^((nat=>alpha1)^ n))fbar n)"))
(assume "(nat=>alpha1)^" "phi^")
(ind)
(use "Eq-Refl")
(assume "n" "IH")
(ng #t)
(simp "IH")
(use "Eq-Refl")
; Proof finished.
(save "MapFbar")

(add-rewrite-rule
 (pt "phi^ map (nat=>alpha1)^ fbar n")
 (pt "([n]phi^((nat=>alpha1)^ n))fbar n"))


; We add a bounded universal quantifier.  AllBList n P means that for
; all lists of length n of booleans the property P holds.

(add-program-constant
 "AllBList" (py "nat=>(list boole=>boole)=>boole") t-deg-zero)

(add-computation-rule (pt "AllBList 0 list boole=>boole")
		      (pt "(list boole=>boole)(Nil boole)"))
(add-computation-rule
 (pt "AllBList(Succ n)list boole=>boole")
 (pt "(AllBList n([list boole]list boole=>boole(list boole::True)))andb
      (AllBList n([list boole]list boole=>boole(list boole::False)))"))


; "AllBListTotal"
(set-goal (pf "Total AllBList"))
(use "Total")
(use "All-AllPartial")
(ind)
; Base
(use "Total" 'right)
(use "All-AllPartial")
(assume "(list boole=>boole)")
(use (make-proof-in-aconst-form (finalg-to-e-to-total-aconst (py "boole"))))
(use "Truth-Axiom")
; Step
(assume "n" "IH")
(use "Total" 'right)
(assume "(list boole=>boole)^" "Tf")
(ng)
(assert (pf "all boole^1(Total boole^1 -> all boole^2(Total boole^2 -> 
                         Total(boole^1 andb boole^2)))"))
  (assume "boole^1" "T1" "boole^2" "T2")
  (use "Total")
  (use "Total")
  (use "AndConstTotal")
  (use "T1")
  (use "T2")
(assume "TA")
(use "TA")
; Case True
(use "Total")
(use "IH")
(use "Total")
(use "All-AllPartial")
(assume "list boole")
(ng)
(use "Total")
(use "Tf")
(use (make-proof-in-aconst-form
      (finalg-to-e-to-total-aconst (py "list boole"))))
(use "Truth-Axiom")
; Case False
(use "Total")
(use "IH")
(use "Total")
(use "All-AllPartial")
(assume "list boole")
(ng)
(use "Total")
(use "Tf")
(use (make-proof-in-aconst-form
      (finalg-to-e-to-total-aconst (py "list boole"))))
(use "Truth-Axiom")
; Proof finished
(save "AllBListTotal")


; "ListLhZero"
(set-goal
 (pf "all xs^(STotal xs^ -> Lh xs^ =0 -> Equal xs^(Nil alpha))"))
(cases)
(assume "H")
(use "Eq-Refl")
(assume "xs^" "x^" "H" "IH")
(use "Efq")
(use "IH")
; Proof finished.
(save "ListLhZero")


; "AllBListIntro"
(set-goal
 (pf "all n,(list boole=>boole)(
       all (list boole)^(
        Lh (list boole)^ =n -> (list boole=>boole) (list boole)^) -> 
       AllBList n (list boole=>boole))"))
(ind)
(assume "(list boole=>boole)")
(ng)
(strip)
(use 1)
(use "Truth-Axiom")
(assume "n" "IH" "(list boole=>boole)" "H")
(ng)
(split)
(use "IH")
(ng)
(assume "(list boole)^" "Lh (list boole)^ =n")
(use "H")
(use "Lh (list boole)^ =n")
(use "IH")
(ng)
(assume "(list boole)^" "Lh (list boole)^ =n")
(use "H")
(use "Lh (list boole)^ =n")
; Proof finished.
(save "AllBListIntro")


; "AllBListElim"
(set-goal
 (pf "all n,(list boole=>boole)(
       AllBList n (list boole=>boole) -> 
       all (list boole)
        (Lh (list boole)=n -> (list boole=>boole)(list boole)))"))
(ind)
(assume "(list boole=>boole)" "H1")
(cases)
(assume "Trivial")
(use "H1")
(assume "list boole" "boole" "Absurd")
(use "Efq")
(use "Absurd")
(assume "n" "IH" "(list boole=>boole)" "H1")
(cases)
(assume "Absurd")
(use "Efq")
(use "Absurd")
(assume "list boole")
(cases)
(use-with "IH"
	  (pt "[(list boole)_1](list boole=>boole)((list boole)_1::True)")
	  "?" (pt "list boole"))
(ng)
(use "H1")
(use-with "IH"
	  (pt "[(list boole)_1](list boole=>boole)((list boole)_1::False)")
	  "?" (pt "list boole"))
(ng)
(use "H1")
; Proof finished.
(save "AllBListElim")

(remove-var-name "x" "xs" "phi" "y" "ys" "z" "zs")