Debian Codegraph @

benchmarks.larceny/src/smlboyer.scm

raw
1 ;;; Translated from the SML version of the Boyer benchmark.
2
3 ;;; From 1terms.sch
4
5 ; terms.sch
6 ;
7 ; Translated from smlbench/boyer/terms.sml by William D Clinger
8 ; Last modified: 25 October 1996
9
10 ; The SML types for this, whose spirit I have attempted to preserve,
11 ; are just awful:
12
13 ; signature TERMS =
14 ; sig
15 ; type head;
16 ; datatype term =
17 ; Var of int
18 ; | Prop of head * term list;
19 ; datatype binding = Bind of int * term;
20 ; val get: string -> head
21 ; and headname: head -> string
22 ; and add_lemma: term -> unit
23 ; and apply_subst: binding list -> term -> term
24 ; and rewrite: term -> term
25 ; end;
26
27 ; In the Scheme version, a term has one of two forms:
28 ; * an integer
29 ; * a list of the form (<head> <terms>)
30 ; where <head> is a head and <terms> is a list of terms.
31
32 (define (Var i) i)
33 (define (Prop head terms) (cons head terms))
34
35 (define (Var? x) (not (pair? x)))
36 (define (Prop? x) (pair? x))
37
38 (define (Var.i x) x)
39 (define (Prop.head x) (car x))
40 (define (Prop.terms x) (cdr x))
41
42 (define Bind cons)
43 (define Bind.i car)
44 (define Bind.term cdr)
45
46 (define get)
47 (define headname)
48 (define add_lemma)
49 (define apply_subst)
50 (define rewrite)
51
52 ;(let ()
53
54 ; datatype term
55 ; = Var of int
56 ; | Prop of { name: string, props: (term * term) list ref } * term list
57 ;
58 ; type head = { name: string, props: (term * term) list ref }
59 ;
60 ; A head has the form (<name> . <props>),
61 ; where <name> is a string and <props> is a list of pairs of terms.
62 ; The <props> field can be updated destructively.
63
64 (define (head name props) (cons name props))
65
66 (define (head.name x) (car x))
67 (define (head.props x) (cdr x))
68 (define (head.props! x newprops) (set-cdr! x newprops))
69
70 (define lemmas '())
71
72 (set! headname car)
73
74 (set! get
75 (lambda (name)
76 (define (get_rec ls)
77 (cond ((null? ls)
78 (let ((entry (head name '())))
79 (set! lemmas (cons entry lemmas))
80 entry))
81 ((string=? name (head.name (car ls)))
82 (car ls))
83 (else
84 (get_rec (cdr ls)))))
85 (get_rec lemmas)))
86
87 (set! add_lemma
88 (lambda (lemma)
89 (let* ((terms (Prop.terms lemma))
90 (left (car terms))
91 (right (cadr terms))
92 (h (Prop.head left))
93 (r (head.props h)))
94 (head.props! h (cons (cons left right) r)))))
95
96 ; Given an int v, returns a procedure that, given a list
97 ; of bindings, returns the value associated with v or #f.
98 ; This won't work if #f is associated with v, but that
99 ; won't ever happen in this benchmark.
100
101 (define (get_binding v)
102 (define (get_rec bindings)
103 (cond ((null? bindings)
104 #f)
105 ((eqv? (Bind.i (car bindings)) v)
106 (Bind.term (car bindings)))
107 (else
108 (get_rec (cdr bindings)))))
109 get_rec)
110
111 (set! apply_subst
112 (lambda (alist)
113 (define (as_rec term)
114 (if (Var? term)
115 (or ((get_binding (Var.i term)) alist)
116 term)
117 (Prop (Prop.head term)
118 (map as_rec (Prop.terms term)))))
119 as_rec))
120
121 ; Given two terms, returns a list of bindings that unify
122 ; them, or returns #f if they are not unifiable.
123
124 (define (unify term1 term2)
125 (unify1 term1 term2 '()))
126
127 (define (unify1 term1 term2 unify_subst)
128 (if (Var? term2)
129 (let* ((v (Var.i term2))
130 (value ((get_binding v) unify_subst)))
131 (if value
132 (if (equal? value term1)
133 unify_subst
134 #f)
135 (cons (cons v term1) unify_subst)))
136 (if (Var? term1)
137 #f
138 (if (equal? (Prop.head term1)
139 (Prop.head term2))
140 (unify1_lst (Prop.terms term1)
141 (Prop.terms term2)
142 unify_subst)
143 #f))))
144
145 (define (unify1_lst ls1 ls2 unify_subst)
146 (cond ((and (null? ls1) (null? ls2))
147 unify_subst)
148 ((and (pair? ls1) (pair? ls2))
149 (let ((unify_subst
150 (unify1 (car ls1) (car ls2) unify_subst)))
151 (if unify_subst
152 (unify1_lst (cdr ls1) (cdr ls2) unify_subst)
153 #f)))
154 (else
155 #f)))
156
157 (set! rewrite
158 (lambda (term)
159 (if (Var? term)
160 term
161 (let ((head (Prop.head term)))
162 (rewrite_with_lemmas
163 (Prop head
164 (map rewrite (Prop.terms term)))
165 (head.props head))))))
166
167 (define (rewrite_with_lemmas term lemmas)
168 (if (null? lemmas)
169 term
170 (let* ((lemma (car lemmas))
171 (t1 (car lemma))
172 (t2 (cdr lemma))
173 (u (unify term t1)))
174 (if u
175 (rewrite ((apply_subst u) t2))
176 (rewrite_with_lemmas term (cdr lemmas))))))
177
178 ;;; From 1rules.sch
179
180 ; rules.sch
181 ;
182 ; Translated from smlbench/boyer/rules.sml by William D Clinger
183 ; Last modified: 22 October 1996
184
185 ; requires terms.sch
186
187 ; datatype cterm = CVar of int | CProp of string * cterm list;
188
189 (let ()
190
191 (define (CVar i) i)
192 (define (CProp s terms) (list s terms))
193
194 (define (CVar? x) (not (pair? x)))
195 (define (CProp? x) (pair? x))
196
197 (define (CVar.i x) x)
198 (define (CProp.name x) (car x))
199 (define (CProp.terms x) (cadr x))
200
201 (define (cterm_to_term x)
202 (if (CVar? x)
203 (Var (CVar.i x))
204 (Prop (get (CProp.name x))
205 (map cterm_to_term (CProp.terms x)))))
206
207 (define (add t) (add_lemma (cterm_to_term t)))
208
209 ; The following code was obtained from rules.sml by using a text editor to
210 ; * delete all occurrences of "CVar"
211 ; * delete all occurrences of "CProp"
212 ; * replace all commas by spaces
213 ; * replace all left and right square brackets by parentheses
214 ; * replace all occurrences of "add (" by "(add '".
215
216
217 (add '
218 ("equal"
219 ( ("compile" (5))
220
221 ("reverse"
222 ( ("codegen" ( ("optimize" (5)) ("nil" ()))))))));
223 (add '
224 ("equal"
225 ( ("eqp" (23 24))
226 ("equal" ( ("fix" (23)) ("fix" (24)))))));
227 (add '
228 ("equal"
229 ( ("gt" (23 24)) ("lt" (24 23)))));
230 (add '
231 ("equal"
232 ( ("le" (23 24)) ("ge" (24 23)))));
233 (add '
234 ("equal"
235 ( ("ge" (23 24)) ("le" (24 23)))));
236 (add '
237 ("equal"
238 ( ("boolean" (23))
239
240 ("or"
241 ( ("equal" (23 ("true" ())))
242 ("equal" (23 ("false" ()))))))));
243 (add '
244 ("equal"
245 ( ("iff" (23 24))
246
247 ("and"
248 ( ("implies" (23 24))
249 ("implies" (24 23)))))));
250 (add '
251 ("equal"
252 ( ("even1" (23))
253
254 ("if"
255 ( ("zerop" (23)) ("true" ())
256 ("odd" ( ("sub1" (23)))))))));
257 (add '
258 ("equal"
259 ( ("countps_" (11 15))
260 ("countps_loop" (11 15 ("zero" ()))))));
261 (add '
262 ("equal"
263 ( ("fact_" (8))
264 ("fact_loop" (8 ("one" ()))))));
265 (add '
266 ("equal"
267 ( ("reverse_" (23))
268 ("reverse_loop" (23 ("nil" ()))))));
269 (add '
270 ("equal"
271 ( ("divides" (23 24))
272 ("zerop" ( ("remainder" (24 23)))))));
273 (add '
274 ("equal"
275 ( ("assume_true" (21 0))
276 ("cons" ( ("cons" (21 ("true" ()))) 0)))));
277 (add '
278 ("equal"
279 ( ("assume_false" (21 0))
280 ("cons" ( ("cons" (21 ("false" ()))) 0)))));
281 (add '
282 ("equal"
283 ( ("tautology_checker" (23))
284 ("tautologyp" ( ("normalize" (23)) ("nil" ()))))));
285 (add '
286 ("equal"
287 ( ("falsify" (23))
288 ("falsify1" ( ("normalize" (23)) ("nil" ()))))));
289 (add '
290 ("equal"
291 ( ("prime" (23))
292
293 ("and"
294 ( ("not" ( ("zerop" (23))))
295
296 ("not"
297 ( ("equal" (23 ("add1" ( ("zero" ())))))))
298 ("prime1" (23 ("sub1" (23)))))))));
299 (add '
300 ("equal"
301 ( ("and" (15 16))
302
303 ("if"
304 (15
305 ("if" (16 ("true" ()) ("false" ())))
306 ("false" ()))))));
307 (add '
308 ("equal"
309 ( ("or" (15 16))
310
311 ("if"
312 (15 ("true" ())
313 ("if" (16 ("true" ()) ("false" ())))
314 ("false" ()))))));
315 (add '
316 ("equal"
317 ( ("not" (15))
318 ("if" (15 ("false" ()) ("true" ()))))));
319 (add '
320 ("equal"
321 ( ("implies" (15 16))
322
323 ("if"
324 (15
325 ("if" (16 ("true" ()) ("false" ())))
326 ("true" ()))))));
327 (add '
328 ("equal"
329 ( ("fix" (23))
330 ("if" ( ("numberp" (23)) 23 ("zero" ()))))));
331 (add '
332 ("equal"
333 ( ("if" ( ("if" (0 1 2)) 3 4))
334
335 ("if"
336 (0 ("if" (1 3 4))
337 ("if" (2 3 4)))))));
338 (add '
339 ("equal"
340 ( ("zerop" (23))
341
342 ("or"
343 ( ("equal" (23 ("zero" ())))
344 ("not" ( ("numberp" (23)))))))));
345 (add '
346 ("equal"
347 ( ("plus" ( ("plus" (23 24)) 25))
348 ("plus" (23 ("plus" (24 25)))))));
349 (add '
350 ("equal"
351 ( ("equal" ( ("plus" (0 1)) ("zero" ())))
352 ("and" ( ("zerop" (0)) ("zerop" (1)))))));
353 (add '
354 ("equal" ( ("difference" (23 23)) ("zero" ()))));
355 (add '
356 ("equal"
357 (
358 ("equal"
359 ( ("plus" (0 1)) ("plus" (0 2))))
360 ("equal" ( ("fix" (1)) ("fix" (2)))))));
361 (add '
362 ("equal"
363 (
364 ("equal" ( ("zero" ()) ("difference" (23 24))))
365 ("not" ( ("gt" (24 23)))))));
366 (add '
367 ("equal"
368 ( ("equal" (23 ("difference" (23 24))))
369
370 ("and"
371 ( ("numberp" (23))
372
373 ("or"
374 ( ("equal" (23 ("zero" ())))
375 ("zerop" (24)))))))));
376 (add '
377 ("equal"
378 (
379 ("meaning"
380 ( ("plus_tree" ( ("append" (23 24)))) 0))
381
382 ("plus"
383 ( ("meaning" ( ("plus_tree" (23)) 0))
384 ("meaning" ( ("plus_tree" (24)) 0)))))));
385 (add '
386 ("equal"
387 (
388 ("meaning"
389 ( ("plus_tree" ( ("plus_fringe" (23)))) 0))
390 ("fix" ( ("meaning" (23 0)))))));
391 (add '
392 ("equal"
393 ( ("append" ( ("append" (23 24)) 25))
394 ("append" (23 ("append" (24 25)))))));
395 (add '
396 ("equal"
397 ( ("reverse" ( ("append" (0 1))))
398
399 ("append" ( ("reverse" (1)) ("reverse" (0)))))));
400 (add '
401 ("equal"
402 ( ("times" (23 ("plus" (24 25))))
403
404 ("plus"
405 ( ("times" (23 24))
406 ("times" (23 25)))))));
407 (add '
408 ("equal"
409 ( ("times" ( ("times" (23 24)) 25))
410 ("times" (23 ("times" (24 25)))))));
411 (add '
412 ("equal"
413 (
414 ("equal" ( ("times" (23 24)) ("zero" ())))
415 ("or" ( ("zerop" (23)) ("zerop" (24)))))));
416 (add '
417 ("equal"
418 ( ("exec" ( ("append" (23 24)) 15 4))
419
420 ("exec" (24 ("exec" (23 15 4)) 4)))));
421 (add '
422 ("equal"
423 ( ("mc_flatten" (23 24))
424 ("append" ( ("flatten" (23)) 24)))));
425 (add '
426 ("equal"
427 ( ("member" (23 ("append" (0 1))))
428
429 ("or"
430 ( ("member" (23 0))
431 ("member" (23 1)))))));
432 (add '
433 ("equal"
434 ( ("member" (23 ("reverse" (24))))
435 ("member" (23 24)))));
436 (add '
437 ("equal"
438 ( ("length" ( ("reverse" (23))))
439 ("length" (23)))));
440 (add '
441 ("equal"
442 ( ("member" (0 ("intersect" (1 2))))
443
444 ("and"
445 ( ("member" (0 1)) ("member" (0 2)))))));
446 (add '
447 ("equal" ( ("nth" ( ("zero" ()) 8)) ("zero" ()))));
448 (add '
449 ("equal"
450 ( ("exp" (8 ("plus" (9 10))))
451
452 ("times"
453 ( ("exp" (8 9)) ("exp" (8 10)))))));
454 (add '
455 ("equal"
456 ( ("exp" (8 ("times" (9 10))))
457 ("exp" ( ("exp" (8 9)) 10)))));
458 (add '
459 ("equal"
460 ( ("reverse_loop" (23 24))
461 ("append" ( ("reverse" (23)) 24)))));
462 (add '
463 ("equal"
464 ( ("reverse_loop" (23 ("nil" ())))
465 ("reverse" (23)))));
466 (add '
467 ("equal"
468 ( ("count_list" (25 ("sort_lp" (23 24))))
469
470 ("plus"
471 ( ("count_list" (25 23))
472 ("count_list" (25 24)))))));
473 (add '
474 ("equal"
475 (
476 ("equal"
477 ( ("append" (0 1)) ("append" (0 2))))
478 ("equal" (1 2)))));
479 (add '
480 ("equal"
481 (
482 ("plus"
483 ( ("remainder" (23 24))
484 ("times" (24 ("quotient" (23 24))))))
485 ("fix" (23)))));
486 (add '
487 ("equal"
488 (
489 ("power_eval" ( ("big_plus" (11 8 1)) 1))
490 ("plus" ( ("power_eval" (11 1)) 8)))));
491 (add '
492 ("equal"
493 (
494 ("power_eval"
495 ( ("big_plus" (23 24 8 1)) 1))
496
497 ("plus"
498 (8
499
500 ("plus"
501 ( ("power_eval" (23 1))
502 ("power_eval" (24 1)))))))));
503 (add '
504 ("equal"
505 ( ("remainder" (24 ("one" ()))) ("zero" ()))));
506 (add '
507 ("equal"
508 ( ("lt" ( ("remainder" (23 24)) 24))
509 ("not" ( ("zerop" (24)))))));
510 (add '
511 ("equal" ( ("remainder" (23 23)) ("zero" ()))));
512 (add '
513 ("equal"
514 ( ("lt" ( ("quotient" (8 9)) 8))
515
516 ("and"
517 ( ("not" ( ("zerop" (8))))
518
519 ("or"
520 ( ("zerop" (9))
521 ("not" ( ("equal" (9 ("one" ()))))))))))));
522 (add '
523 ("equal"
524 ( ("lt" ( ("remainder" (23 24)) 23))
525
526 ("and"
527 ( ("not" ( ("zerop" (24))))
528 ("not" ( ("zerop" (23))))
529 ("not" ( ("lt" (23 24)))))))));
530 (add '
531 ("equal"
532 ( ("power_eval" ( ("power_rep" (8 1)) 1))
533 ("fix" (8)))));
534 (add '
535 ("equal"
536 (
537 ("power_eval"
538 (
539 ("big_plus"
540 ( ("power_rep" (8 1))
541 ("power_rep" (9 1)) ("zero" ())
542 1))
543 1))
544 ("plus" (8 9)))));
545 (add '
546 ("equal"
547 ( ("gcd" (23 24)) ("gcd" (24 23)))));
548 (add '
549 ("equal"
550 ( ("nth" ( ("append" (0 1)) 8))
551
552 ("append"
553 ( ("nth" (0 8))
554
555 ("nth"
556 (1 ("difference" (8 ("length" (0)))))))))));
557 (add '
558 ("equal"
559 ( ("difference" ( ("plus" (23 24)) 23))
560 ("fix" (24)))));
561 (add '
562 ("equal"
563 ( ("difference" ( ("plus" (24 23)) 23))
564 ("fix" (24)))));
565 (add '
566 ("equal"
567 (
568 ("difference"
569 ( ("plus" (23 24)) ("plus" (23 25))))
570 ("difference" (24 25)))));
571 (add '
572 ("equal"
573 ( ("times" (23 ("difference" (2 22))))
574
575 ("difference"
576 ( ("times" (2 23))
577 ("times" (22 23)))))));
578 (add '
579 ("equal"
580 ( ("remainder" ( ("times" (23 25)) 25))
581 ("zero" ()))));
582 (add '
583 ("equal"
584 (
585 ("difference"
586 ( ("plus" (1 ("plus" (0 2)))) 0))
587 ("plus" (1 2)))));
588 (add '
589 ("equal"
590 (
591 ("difference"
592 ( ("add1" ( ("plus" (24 25)))) 25))
593 ("add1" (24)))));
594 (add '
595 ("equal"
596 (
597 ("lt"
598 ( ("plus" (23 24)) ("plus" (23 25))))
599 ("lt" (24 25)))));
600 (add '
601 ("equal"
602 (
603 ("lt"
604 ( ("times" (23 25))
605 ("times" (24 25))))
606
607 ("and"
608 ( ("not" ( ("zerop" (25))))
609 ("lt" (23 24)))))));
610 (add '
611 ("equal"
612 ( ("lt" (24 ("plus" (23 24))))
613 ("not" ( ("zerop" (23)))))));
614 (add '
615 ("equal"
616 (
617 ("gcd"
618 ( ("times" (23 25))
619 ("times" (24 25))))
620 ("times" (25 ("gcd" (23 24)))))));
621 (add '
622 ("equal"
623 ( ("value" ( ("normalize" (23)) 0))
624 ("value" (23 0)))));
625 (add '
626 ("equal"
627 (
628 ("equal"
629 ( ("flatten" (23))
630 ("cons" (24 ("nil" ())))))
631
632 ("and"
633 ( ("nlistp" (23)) ("equal" (23 24)))))));
634 (add '
635 ("equal"
636 ( ("listp" ( ("gother" (23))))
637 ("listp" (23)))));
638 (add '
639 ("equal"
640 ( ("samefringe" (23 24))
641
642 ("equal" ( ("flatten" (23)) ("flatten" (24)))))));
643 (add '
644 ("equal"
645 (
646 ("equal"
647 ( ("greatest_factor" (23 24)) ("zero" ())))
648
649 ("and"
650 (
651 ("or"
652 ( ("zerop" (24))
653 ("equal" (24 ("one" ())))))
654 ("equal" (23 ("zero" ()))))))));
655 (add '
656 ("equal"
657 (
658 ("equal"
659 ( ("greatest_factor" (23 24)) ("one" ())))
660 ("equal" (23 ("one" ()))))));
661 (add '
662 ("equal"
663 ( ("numberp" ( ("greatest_factor" (23 24))))
664
665 ("not"
666 (
667 ("and"
668 (
669 ("or"
670 ( ("zerop" (24))
671 ("equal" (24 ("one" ())))))
672 ("not" ( ("numberp" (23)))))))))));
673 (add '
674 ("equal"
675 ( ("times_list" ( ("append" (23 24))))
676
677 ("times"
678 ( ("times_list" (23)) ("times_list" (24)))))));
679 (add '
680 ("equal"
681 ( ("prime_list" ( ("append" (23 24))))
682
683 ("and"
684 ( ("prime_list" (23)) ("prime_list" (24)))))));
685 (add '
686 ("equal"
687 ( ("equal" (25 ("times" (22 25))))
688
689 ("and"
690 ( ("numberp" (25))
691
692 ("or"
693 ( ("equal" (25 ("zero" ())))
694 ("equal" (22 ("one" ()))))))))));
695 (add '
696 ("equal"
697 ( ("ge" (23 24))
698 ("not" ( ("lt" (23 24)))))));
699 (add '
700 ("equal"
701 ( ("equal" (23 ("times" (23 24))))
702
703 ("or"
704 ( ("equal" (23 ("zero" ())))
705
706 ("and"
707 ( ("numberp" (23))
708 ("equal" (24 ("one" ()))))))))));
709 (add '
710 ("equal"
711 ( ("remainder" ( ("times" (24 23)) 24))
712 ("zero" ()))));
713 (add '
714 ("equal"
715 ( ("equal" ( ("times" (0 1)) ("one" ())))
716
717 ("and"
718 ( ("not" ( ("equal" (0 ("zero" ())))))
719 ("not" ( ("equal" (1 ("zero" ())))))
720 ("numberp" (0)) ("numberp" (1))
721 ("equal" ( ("sub1" (0)) ("zero" ())))
722 ("equal" ( ("sub1" (1)) ("zero" ()))))))));
723 (add '
724 ("equal"
725 (
726 ("lt"
727 ( ("length" ( ("delete" (23 11))))
728 ("length" (11))))
729 ("member" (23 11)))));
730 (add '
731 ("equal"
732 ( ("sort2" ( ("delete" (23 11))))
733 ("delete" (23 ("sort2" (11)))))));
734 (add ' ("equal" ( ("dsort" (23)) ("sort2" (23)))));
735 (add '
736 ("equal"
737 (
738 ("length"
739 (
740 ("cons"
741 (0
742
743 ("cons"
744 (1
745
746 ("cons"
747 (2
748
749 ("cons"
750 (3
751 ("cons" (4 ("cons" (5 6))))))))))))))
752 ("plus" ( ("six" ()) ("length" (6)))))));
753 (add '
754 ("equal"
755 (
756 ("difference"
757 ( ("add1" ( ("add1" (23)))) ("two" ())))
758 ("fix" (23)))));
759 (add '
760 ("equal"
761 (
762 ("quotient"
763 ( ("plus" (23 ("plus" (23 24))))
764 ("two" ())))
765
766 ("plus" (23 ("quotient" (24 ("two" ()))))))));
767 (add '
768 ("equal"
769 ( ("sigma" ( ("zero" ()) 8))
770
771 ("quotient"
772 ( ("times" (8 ("add1" (8)))) ("two" ()))))));
773 (add '
774 ("equal"
775 ( ("plus" (23 ("add1" (24))))
776
777 ("if"
778 ( ("numberp" (24))
779 ("add1" ( ("plus" (23 24))))
780 ("add1" (23)))))));
781 (add '
782 ("equal"
783 (
784 ("equal"
785 ( ("difference" (23 24))
786 ("difference" (25 24))))
787
788 ("if"
789 ( ("lt" (23 24))
790 ("not" ( ("lt" (24 25))))
791
792 ("if"
793 ( ("lt" (25 24))
794 ("not" ( ("lt" (24 23))))
795 ("equal" ( ("fix" (23)) ("fix" (25))))))))))
796 );
797 (add '
798 ("equal"
799 (
800 ("meaning"
801 ( ("plus_tree" ( ("delete" (23 24)))) 0))
802
803 ("if"
804 ( ("member" (23 24))
805
806 ("difference"
807 ( ("meaning" ( ("plus_tree" (24)) 0))
808 ("meaning" (23 0))))
809 ("meaning" ( ("plus_tree" (24)) 0)))))));
810 (add '
811 ("equal"
812 ( ("times" (23 ("add1" (24))))
813
814 ("if"
815 ( ("numberp" (24))
816
817 ("plus"
818 (23 ("times" (23 24))
819 ("fix" (23)))))))));
820 (add '
821 ("equal"
822 ( ("nth" ( ("nil" ()) 8))
823
824 ("if" ( ("zerop" (8)) ("nil" ()) ("zero" ()))))));
825 (add '
826 ("equal"
827 ( ("last" ( ("append" (0 1))))
828
829 ("if"
830 ( ("listp" (1)) ("last" (1))
831
832 ("if"
833 ( ("listp" (0))
834 ("cons" ( ("car" ( ("last" (0)))) 1))
835 1)))))));
836 (add '
837 ("equal"
838 ( ("equal" ( ("lt" (23 24)) 25))
839
840 ("if"
841 ( ("lt" (23 24))
842 ("equal" ( ("true" ()) 25))
843 ("equal" ( ("false" ()) 25)))))));
844 (add '
845 ("equal"
846 ( ("assignment" (23 ("append" (0 1))))
847
848 ("if"
849 ( ("assignedp" (23 0))
850 ("assignment" (23 0))
851 ("assignment" (23 1)))))));
852 (add '
853 ("equal"
854 ( ("car" ( ("gother" (23))))
855
856 ("if"
857 ( ("listp" (23))
858 ("car" ( ("flatten" (23)))) ("zero" ()))))));
859 (add '
860 ("equal"
861 ( ("flatten" ( ("cdr" ( ("gother" (23))))))
862
863 ("if"
864 ( ("listp" (23))
865 ("cdr" ( ("flatten" (23))))
866 ("cons" ( ("zero" ()) ("nil" ()))))))));
867 (add '
868 ("equal"
869 ( ("quotient" ( ("times" (24 23)) 24))
870
871 ("if"
872 ( ("zerop" (24)) ("zero" ())
873 ("fix" (23)))))));
874 (add '
875 ("equal"
876 ( ("get" (9 ("set" (8 21 12))))
877
878 ("if"
879 ( ("eqp" (9 8)) 21
880 ("get" (9 12))))))))
881
882 ;;; From 1boyer.sch
883
884 ; mlboyer.sch
885 ;
886 ; Translated from smlbench/boyer/boyer.sml by William D Clinger
887 ; Last modified: 25 October 1996
888
889 ; requires mlterms.sch
890
891 ; structure Boyer: BOYER
892
893 (define tautp)
894
895 ; structure Main: BMARK
896
897 (define doit)
898 (define testit)
899
900 ;(let ()
901
902 (define (mem x z)
903 (if (null? z)
904 #f
905 (or (equal? x (car z))
906 (mem x (cdr z)))))
907
908 (define (truep x lst)
909 (if (Prop? x)
910 (or (string=? (headname (Prop.head x)) "true")
911 (mem x lst))
912 (mem x lst)))
913
914 (define (falsep x lst)
915 (if (Prop? x)
916 (or (string=? (headname (Prop.head x)) "false")
917 (mem x lst))
918 (mem x lst)))
919
920 (define (tautologyp x true_lst false_lst)
921 (cond ((truep x true_lst)
922 #t)
923 ((falsep x false_lst)
924 #f)
925 ((Var? x)
926 #f)
927 ((string=? (headname (Prop.head x)) "if")
928 (let* ((terms (Prop.terms x))
929 (test (car terms))
930 (yes (cadr terms))
931 (no (caddr terms)))
932 (cond ((truep test true_lst)
933 (tautologyp yes true_lst false_lst))
934 ((falsep test false_lst)
935 (tautologyp no true_lst false_lst))
936 (else (and (tautologyp yes
937 (cons test true_lst)
938 false_lst)
939 (tautologyp no
940 true_lst
941 (cons test false_lst)))))))
942 (else #f)))
943
944 (set! tautp
945 (lambda (x)
946 (tautologyp (rewrite x) '() '())))
947
948 ;)
949
950 (let ((subst (list
951
952 (Bind 23
953 (Prop
954 (get "f")
955 (list (Prop
956 (get "plus")
957 (list (Prop (get "plus") (list (Var 0) (Var 1)))
958 (Prop (get "plus") (list (Var 2) (Prop (get "zero") '()))))))))
959 (Bind 24
960 (Prop
961 (get "f")
962 (list (Prop
963 (get "times")
964 (list (Prop (get "times") (list (Var 0) (Var 1)))
965 (Prop (get "plus") (list (Var 2) (Var 3))))))))
966 (Bind 25
967 (Prop
968 (get "f")
969 (list (Prop
970 (get "reverse")
971 (list (Prop
972 (get "append")
973 (list (Prop (get "append") (list (Var 0) (Var 1)))
974 (Prop (get "nil") '()))))))))
975 (Bind 20
976 (Prop
977 (get "equal")
978 (list (Prop (get "plus") (list (Var 0) (Var 1)))
979 (Prop (get "difference") (list (Var 23) (Var 24))))))
980 (Bind 22
981 (Prop
982 (get "lt")
983 (list (Prop (get "remainder") (list (Var 0) (Var 1)))
984 (Prop (get "member")
985 (list (Var 0)
986 (Prop (get "length") (list (Var 1))))))))))
987
988 (term
989 (Prop
990 (get "implies")
991 (list (Prop
992 (get "and")
993 (list (Prop (get "implies") (list (Var 23) (Var 24)))
994 (Prop
995 (get "and")
996 (list (Prop (get "implies") (list (Var 24) (Var 25)))
997 (Prop
998 (get "and")
999 (list (Prop (get "implies") (list (Var 25) (Var 20)))
1000 (Prop (get "implies") (list (Var 20) (Var 22)))))))))
1001 (Prop (get "implies") (list (Var 23) (Var 22)))))))
1002
1003 (set! testit
1004 (lambda (outstrm)
1005 (if (tautp ((apply_subst subst) term))
1006 (display "Proved!" outstrm)
1007 (display "Cannot prove!" outstrm))
1008 (newline outstrm)))
1009
1010 (set! doit
1011 (lambda ()
1012 (tautp ((apply_subst subst) term))))
1013 )
1014
1015 (define (main . args)
1016 (run-benchmark
1017 "smlboyer"
1018 smlboyer-iters
1019 doit
1020 (lambda (result) result)))