/usr/share/acl2-8.0dfsg/books/hints/basic-tests.lisp is in acl2-books-source 8.0dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 | ; Copyright (C) 2013, Regents of the University of Texas
; Written by Matt Kaufmann (some years before that)
; License: A 3-clause BSD license. See the LICENSE file distributed with ACL2.
; This file contains some basic tests of various hint mechanisms.
; Note that because of must-fail, REBUILD doesn't work for this book.
(in-package "ACL2")
(include-book "misc/eval" :dir :system)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Test override-hints.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun rev (x)
(if (atom x)
nil
(append (rev (cdr x)) (list (car x)))))
(defun my-tester1 (id state)
(declare (xargs :stobjs state))
; Note that (parse-clause-id "Subgoal *1/3'5'") = ((0 1) (3) . 5).
(value (and (equal id '((0 1) (3) . 5))
(list :error
(msg "QUITTING.")))))
(add-default-hints '((my-tester1 id state)))
(must-fail
; Error after Subgoal *1/3'5', upon attempt to generalize.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))))
(must-succeed
; Succeeds because explicit hint takes priority over default hint.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/3'5'" :expand ((nth u v))))))
(add-override-hints '((append '(:no-thanks t) keyword-alist)))
(must-succeed
; Explicit hint fires just fine with override hint, but this time
; we do not see "Thanks".
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/3'5'" :expand ((nth u v))))))
(set-override-hints
; Basically the same as above, except that we will see a message printed for
; every attempt to select a hint.
'((mv-let (col state)
(fmx "**Applying override hints**")
(declare (ignore col))
(value (append '(:no-thanks t) keyword-alist)))))
(must-succeed
; As above, explicit hint fires just fine with override hint.
; But now we see a message printed for every attempt to select a hint.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/3'5'" :expand ((nth u v))))))
(must-fail
; Error after Subgoal *1/3'5'. still.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))))
(set-override-hints '((remove-keyword :error keyword-alist)))
(must-fail
; Still fails, because we't check for :error in computed hint results at every
; stage, not just at the end of applying override-hints.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))))
(set-override-hints nil)
(set-default-hints nil)
(must-fail
; Fails, of course.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/2" :in-theory (disable rev))
("Subgoal *1/1" :in-theory (disable rev))
("Subgoal *1/1'" :in-theory (disable true-listp rev (rev))))))
(set-override-hints '((remove-keyword :in-theory keyword-alist)))
(must-succeed
; Now, succeeds because of override-hints above. Notice that we get no
; "Thanks", because there are no hint-settings left after removing the
; :in-theory hint-settings.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/2" :in-theory (disable rev))
("Subgoal *1/1" :in-theory (disable rev))
("Subgoal *1/1'" :in-theory (disable true-listp rev (rev))))))
(must-succeed
; Also succeeds because of override-hints above.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Goal" :in-theory (disable rev)))))
(must-fail
; Fails because computed hint fires, since "Goal" hint is not selected (because
; it becomes the empty hint).
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Goal" :in-theory (disable rev))
(quote (:hands-off rev)))))
; Now, arrange that we never eliminate a hint entirely:
(set-override-hints '((let ((temp (remove-keyword :in-theory keyword-alist)))
(or temp
(and keyword-alist
'(:no-op t))))))
(must-fail
; Fails even though "Goal" hint is replaced by ("Goal" (:no-op t)), which is
; selected, because preprocess-clause hits (but puts a hidden-clause note in
; the history, and nothing is printed) and hence the computed hint is applied
; to "Goal" on the second try; try (trace$ waterfall-step) to see that a HIT
; signal is returned by preprocess-clause. Actually a HIT signal is then also
; returned for "Goal" on settled-down-clause.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Goal" :in-theory (disable rev))
(and (equal id *initial-clause-id*)
(quote (:hands-off rev))))))
(must-succeed
; As just above, but we avoid the issue with "Goal" making extra trips through
; the waterfall. Thus, succeeds because "Subgoal *1/3'" hint is replaced by
; ("Subgoal *1/3'" (:no-op t)), which is selected.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/3'" :in-theory (disable rev))
(and (equal id (parse-clause-id "Subgoal *1/3'"))
(quote (:hands-off rev))))))
; Just to make sure that :in-theory and :hands-off would both have caused
; failures above:
(remove-override-hints '((let ((temp (remove-keyword :in-theory keyword-alist)))
(or temp
(and keyword-alist
'(:no-op t))))))
(assert-event (null (override-hints (w state))))
(must-fail
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/3'" :in-theory (disable rev)))))
(must-fail
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints ((and (equal id (parse-clause-id "Subgoal *1/3'"))
(quote (:hands-off rev))))))
; Now we implement the feature requested by Peter Dillinger, where we can limit
; induction levels without printing "Thanks" for the hint when that is all we
; are doing. First, we do this without worrying about "Thanks".
(set-override-hints '((if (and (>= (length (cdar id)) 2)
; Avoid bothering with children of top-level induction goals:
(null (cdr (access clause-id id :case-lst)))
(zerop (access clause-id id :primes)))
(list* :do-not-induct :otf keyword-alist)
keyword-alist)))
(must-fail
; We should see:
#||
So we now return to *1.1.2, which is
(IMPLIES (AND (NOT (CONSP L2))
(EQUAL (APPEND BAD X2) (APPEND X2 BAD)))
(EQUAL (LIST* L1 X1 X2)
(APPEND X2 (LIST* X1 L1 L2)))).
Normally we would attempt to prove *1.1.2 by induction. However, a
:DO-NOT-INDUCT hint was supplied to abort the proof attempt.
||#
(thm (equal (append (append x x) x)
(append x x x))))
; As above, but no "Thanks" for the hints this time:
(set-override-hints '((if (and (>= (length (cdar id)) 2)
; Avoid bothering with children of top-level induction goals:
(null (cdr (access clause-id id :case-lst)))
(zerop (access clause-id id :primes)))
(list* :do-not-induct :otf
(or keyword-alist
'(:no-thanks t)))
keyword-alist)))
(must-fail
; Should see the same :DO-NOT-INDUCT failure message as above, but this time we
; should not see any "Thanks" messages for hints.
(thm (equal (append (append x x) x)
(append x x x))))
(must-fail
; As above, but we should see a "Thanks" message for (only) the indicated
; goal.
(thm (equal (append (append x x) x)
(append x x x))
:hints (("Subgoal *1.1/2" :in-theory (enable car-cons)))))
; Now we test that add-override-hints does indeed add to the end. First, we
; add to the beginning and see that we get the "Thanks" as just above, because
; the new override-hint is added before we see whether to add :no-thanks.
(encapsulate
()
(add-override-hints '((if (equal (parse-clause-id "Subgoal *1.1/2")
id)
(list* :in-theory '(enable car-cons) keyword-alist)
keyword-alist))
:at-end nil)
(must-fail
; As above, with a "Thanks" message for "Subgoal *1.1/2".
(thm (equal (append (append x x) x)
(append x x x)))))
; Same as above, using no explicit :at-end but checking that default is nil.
(encapsulate
()
(add-override-hints '((if (equal (parse-clause-id "Subgoal *1.1/2")
id)
(list* :in-theory '(enable car-cons) keyword-alist)
keyword-alist)))
(must-fail
; As above, with a "Thanks" message for"Subgoal *1.1/2".
(thm (equal (append (append x x) x)
(append x x x)))))
; Let's check that the add-override-hints was local to the above encapsulates.
(assert-event (equal (length (override-hints (w state))) 1))
; Now we add the new override-hint to the end, by which time we have already
; added the :no-thanks hint -- so we should see no "Thanks".
(encapsulate
()
(add-override-hints '((if (equal (parse-clause-id "Subgoal *1.1/2")
id)
(list* :in-theory '(enable car-cons) keyword-alist)
keyword-alist))
:at-end t)
(must-fail
; As above, with no "Thanks" message for"Subgoal *1.1/2".
(thm (equal (append (append x x) x)
(append x x x)))))
; Same as above, but add-override-hints! is non-local.
(encapsulate
()
(add-override-hints! '((if (equal (parse-clause-id "Subgoal *1.1/2")
id)
(list* :in-theory '(enable car-cons) keyword-alist)
keyword-alist))
:at-end t)
(must-fail
; As above, with no "Thanks" message for"Subgoal *1.1/2".
(thm (equal (append (append x x) x)
(append x x x)))))
; Let's check that the add-override-hints! was NOT local to the above
; encapsulates.
(assert-event (equal (length (override-hints (w state))) 2))
(set-default-hints nil)
(set-override-hints nil)
; The following does not produce a "Thanks" message, because we treat computed
; hints as nil when they produce only the :computed-hints-replacement keyword,
; even after applying override hints. See the discussion of
; :computed-hint-replacement in :doc override-hints.
(encapsulate
()
(add-override-hints '((remove-keyword :expand keyword-alist)))
(must-succeed
(thm (equal x x)
:hints
((quote (:computed-hint-replacement t :expand ((nth u v))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Test :backtrack hints.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Parts of the following basic example correspond to the slides presentated at
; ACL2 Workshop 2011 for the paper "Integrating Testing and Interactive Theorem
; Proving" by Harsh Raju Chamarthi, Peter C. Dillinger, Matt Kaufmann, and
; Panagiotis Manolios.
; This basic example works equally well with default-hints and override-hints.
; The advantage in general of override-hints is that they fire even if the user
; has supplied an explicit hint. The last part below shows a failure of
; default-hints, to illustrate why override-hints are preferable.
;;;;; basic definitions ;;;;;
(defun app (x y)
(if (consp x)
(cons (car x) (app (cdr x) y))
y))
(defun rev0 (x) ; called rev0 to avoid name clash with earlier rev
(if (consp x)
(app (rev0 (cdr x)) (cons (car x) nil))
nil))
(defthm app-assoc
(equal (app (app x y) z)
(app x (app y z))))
; Fails (bad generalization produces non-theorem, Subgoal *1/2''):
(must-fail
(thm
(equal (rev0 (app a b))
(app (rev0 b) (rev0 a)))))
(defun test-clause (cl state)
(declare (xargs :stobjs state :mode :program))
(pprogn
(fms "Test-clause:~|~x0~|"
(list (cons #\0 cl))
*standard-co* state nil)
(er-let* ((term/val
(simple-translate-and-eval
(conjoin cl)
(cons (cons 'rv 3) (pairlis$ (all-vars1-lst cl nil) nil))
nil "" 'test-clause (w state) state t)))
(value (not (cdr term/val))))))
;;;;; using override-hint ;;;;;
(defun test-gen-checkpoint (keyword-alist)
`(:backtrack
(cond
((eq processor 'generalize-clause)
(er-let*
((res (test-clause (car clause-list) state)))
(value (cond (res '(:do-not '(generalize)))
(t nil)))))
(t (value nil)))
,@keyword-alist))
(add-override-hints
'((test-gen-checkpoint keyword-alist)))
; Succeeds:
(must-succeed
(thm
(equal (rev0 (app a b))
(app (rev0 b) (rev0 a)))))
(remove-override-hints
'((test-gen-checkpoint keyword-alist)))
; Fails again (override-hint was removed)
(must-fail
(thm
(equal (rev0 (app a b))
(app (rev0 b) (rev0 a)))))
(defun test-gen-checkpoint2 ()
`(:backtrack
(cond
((eq processor 'generalize-clause)
(er-let*
((res (test-clause (car clause-list) state)))
(value (cond (res '(:do-not '(generalize)))
(t nil)))))
(t (value nil)))))
(add-default-hints
'((test-gen-checkpoint2)))
; Succeeds:
(must-succeed
(thm
(equal (rev0 (app a b))
(app (rev0 b) (rev0 a)))
:hints (("Subgoal *1/2'" :in-theory (enable nth)))))
; The rest of this is to show the advantage of override-hints over
; default-hints. (Technical point: It takes a bit of effort to defeat
; default-hints, because settled-down-clause hits and pops us up to the top of
; the waterfall for a second try. So we actually need two hints in front of
; test-gen-checkpoint2 in order to keep it from firing.)
(defun silly-expand-hint ()
`(:computed-hint-replacement t :expand ((nth u v))))
(add-default-hints
'((silly-expand-hint)))
; Fails, because default-hint doesn't apply
(must-fail
(thm
(equal (rev0 (app a b))
(app (rev0 b) (rev0 a)))
:hints (("Subgoal *1/2'" :expand ((nth y z))))))
; End of basic example of the use of :backtrack hints.
(defconst *backtrack-failure*
'(:backtrack
(and (eq processor 'generalize-clause)
(list :error
(msg "ACL2 tried to generalize on a clause with function ~
symbols ~&0. We are aborting with a :BACKTRACK hint."
(all-fnnames-lst clause))))))
(defun my-tester2 (state)
(declare (xargs :stobjs state))
(value *backtrack-failure*))
(set-default-hints '((my-tester2 state)))
(must-fail
; Error after Subgoal *1/3'5', upon attempt to generalize.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))))
(must-fail
; Fails as above even though explicit hints take priority over default hints,
; because the default :backtrack hint is incorporated into the running
; :hint-settings at "Goal". The :backtrack computed hint is evaluated at every
; goal -- try (trace$ process-backtrack-hint) -- but returns (value nil) until
; it returns an error when we hit on generalization, when evaluation produces
; an :error hint. Of course, this time we get a "Thanks" for the indicated
; subgoal.
(thm (implies (true-listp x)
(equal (rev (rev x)) x))
:hints (("Subgoal *1/3'5'" :expand ((nth u v))))))
(encapsulate
()
; The following is a mistake, because PROCESSOR is not legal in ordinary
; computed hints, but only in :backtrack hints.
(set-default-hints '((and (eq processor 'generalize-clause)
'(:in-theory (disable append)))))
(must-fail
; The translation error message should say that PROCESSOR is only legal for
; :backtrack hints.
(thm (equal (append (append x y) z)
(append x y z))))
)
; The following is just as above, but the error message should say that
; PROCESSOR, CLAUSE-LIST, and KEYWORD-ALIST are only legal for :backtrack hint
; or override-hints.
(encapsulate
()
(set-default-hints '((and (eq processor 'generalize-clause)
(null clause-list)
keyword-alist
'(:in-theory (disable append)))))
(must-fail
(thm (equal (append (append x y) z)
(append x y z)))))
; Translation error as above, but because of FOO there is no bother of
; mentioning :backtrack hints or override-hints.
(encapsulate
()
(set-default-hints '((and (eq processor 'generalize-clause)
(null clause-list)
keyword-alist
foo
'(:in-theory (disable append)))))
(must-fail
(thm (equal (append (append x y) z)
(append x y z)))))
; More interesting example suggesting an approach for testing:
(defun test-clause-list (processor clause-list state)
; Return (value t) if we find a counterexample, else (value nil).
(declare (xargs :stobjs state
:mode :program))
(let* ((term (conjoin-clauses clause-list))
(vars (all-vars term)))
(er-let* ((pair
(simple-translate-and-eval term
(pairlis$ vars nil)
nil
"The clause with values bound to nil"
'my-tester
(w state)
state
nil)))
(cond ((cdr pair) (value nil))
(t (assert$
(null (cdr clause-list))
(pprogn
(io? prove nil state
(processor clause-list)
(fms "The attempt at ~x0 produced the ~
clause~|~%~x1,~|~%which is false when the ~
variables are bound to nil. So we abandon ~
that step.~|"
(list (cons #\0 processor)
(cons #\1
(prettyify-clause
(car clause-list)
(let*-abstractionp state)
(w state))))
(proofs-co state)
state
(term-evisc-tuple nil state)))
(value t))))))))
(defun my-tester3 ()
`(:computed-hint-replacement
t
:backtrack
(cond ((eq processor 'fertilize-clause)
(er-let* ((val (test-clause-list processor clause-list state)))
(value (cond (val '(:do-not '(fertilize)))
(t nil)))))
(t (value nil)))))
(set-default-hints '((my-tester3)))
; For the following, after Subgoal *1.2/2'4' we get:
#||
The attempt at FERTILIZE-CLAUSE produced the clause
(IMPLIES (NOT (CONSP Y)) (EQUAL (APPEND X2 (CONS X1 X2)) (APPEND X2 Y))),
which is false when the variables are bound to nil. So we abandon
that step.
[Note: A hint was supplied for our processing of the goal above, because
of a :backtrack hint that is preventing heuristic use of equalities.
Thanks!]
We generalize this conjecture, replacing (APPEND X2 X2) by BAD. This
produces
Subgoal *1.2/2'5'
||#
(must-fail
(thm (equal (append x y x) (append y x y))))
; The following behaves identically to the above, still thanking us for the
; hint on "Subgoal *1.2/2'4'", because the :no-thanks hint is applied to "Goal"
; and then removed from the lst of two computed hints but stored in the
; hint-settings, and then settled-down-clause hits on "Goal", which eliminates
; the :no-thanks hint-setting.
(encapsulate
()
(add-default-hints '((quote (:no-thanks t))))
(must-fail
(thm (equal (append x y x) (append y x y)))))
; So to make sure that :no-thanks always applies, we use
; :computed-hint-replacement. But then we always select that hint, since
; add-default-hints adds to the front (unless :at-end is supplied). In
; particular, the :backtrack hint no longer fires at "Subgoal *1.2/2'4'" --
; instead, fertilization is applied. So what we really want is an
; override-hint, which follows this test.
(encapsulate
()
(add-default-hints '((quote (:computed-hint-replacement t :no-thanks t))))
(must-fail
(thm (equal (append x y x) (append y x y)))))
; So this time the :backtrack hint fires at "Subgoal *1.2/2'4'", and thus we
; avoid fertilization there.
(encapsulate
()
(add-override-hints '((cond ((or (null keyword-alist)
(assoc-keyword :no-thanks keyword-alist))
keyword-alist)
(t
(append '(:no-thanks t) keyword-alist)))))
(must-fail
(thm (equal (append x y x) (append y x y)))))
(set-default-hints nil)
(set-override-hints nil)
; Silly success:
(must-succeed
(thm (equal (car (append x y))
(if (consp x) (car x) (car y)))
:hints
(("Goal"
:backtrack
(quote (:expand ((nth u v))))))))
; Simple success, demonstrating backtrack hint:
(encapsulate
()
(local (in-theory (disable append)))
(must-succeed
(thm (equal (car (append x y))
(if (consp x) (car x) (car y)))
:hints
(("Goal"
:backtrack
(quote (:in-theory (enable append))))))))
; Success, demonstrating that backtrack hint allows the use of
; :computed-hint-replacement (but :computed-hint-replacement plays no
; interesting role in this case):
(encapsulate
()
(local (in-theory (disable append)))
(must-succeed
(thm (equal (car (append x y))
(if (consp x) (car x) (car y)))
:hints
(("Goal"
:backtrack
(quote (:computed-hint-replacement t :in-theory (enable append))))))))
; Success, demonstrating interaction of backtrack hint with
; computed-hint-replacement:
(encapsulate
()
(local (in-theory (disable append)))
(must-succeed
(thm (equal (car (append x y))
(if (consp x) (car x) (car y)))
:hints
(("Goal"
:backtrack
(quote (:computed-hint-replacement
((quote (:in-theory (enable append))))
:no-op t)))))))
; Here is a test that combines backtrack hints and override-hints.
(defun my-computed-hint (state)
(declare (xargs :mode :program :stobjs state))
(pprogn (fms "*** HELLO ***~%" nil *standard-co* state nil)
(value nil)))
(add-override-hints
'((quote (:backtrack (if (member-eq processor '(apply-top-hints-clause
preprocess-clause
simplify-clause))
(value nil)
(my-computed-hint state))))))
; If you now do (thm (equal (append (append x x) x) (append x x x))), you'll see
; the string "*** HELLO ***" printed after every simplification checkpoint.
; Note that the member-eq test above rules out those processors in
; *preprocess-clause-ledge* that do not correspond to simplification
; checkpoints.
; Also note that the above call of add-override-hints arranges for all hints to
; be ignored! That's because the application of this override-hint selects a
; hint of the form (:backtrack <expr>) where <expr> evaluates to (mv nil nil
; state) -- so any other hint is ignored (superseded by this :backtrack hint),
; but this :backtrack hint actually has no effect on the proof.
(set-override-hints nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Test :or hints and custom hints.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstub property (x) t)
(defstub constrp (x) t)
(encapsulate ((fff (x) t))
(local (defun fff (x) x))
(skip-proofs (defthm constrp-fff (constrp (fff x)))))
(skip-proofs (defthm property-fff (property (fff x))))
(encapsulate ((ggg (x) t))
(local (defun ggg (x) x))
(skip-proofs (defthm constrp-ggg (constrp (ggg x))
:rule-classes nil)))
(defstub ppp (x) t)
(not-thm?
(property (ggg aaa))
; This proof will fail but you will see 5 cases: 4 from the
; :cases and a constraint.
:hints
(("Goal" :use (:instance (:functional-instance property-fff (fff ggg))
(x bbb))
:cases ((ppp 1) (ppp 2) (ppp 3))))
:otf-flg t)
(thm?
(property (ggg aaa))
; This proof will succeed.
:hints
(("Goal" :use ((:instance (:functional-instance property-fff (fff ggg))
(x aaa))
(:instance constrp-ggg (x x)))
:cases ((ppp 1) (ppp 2) (ppp 3)))
("Goal'" :use ((:instance constrp-ggg (x x))))))
; These examples test :or
(defstub property (x) t)
(defaxiom bar
(implies (property (fff x)) (property x))
:rule-classes nil)
(defaxiom mum
(implies (property (ggg x)) (property x))
:rule-classes nil)
(defaxiom aaa (property (fff x)))
(defaxiom bbb (property (ggg x)))
(in-theory (disable aaa bbb))
; This is just to see the the io. The proof will fail.
(not-thm?
(property ccc)
;;; ------------ this will fail ---------------
:hints
(("Goal"
:OR
((:use (:instance bar (x disj-case-1)) :do-not '(generalize))
(:use (:instance bar (x disj-case-2)) :do-not '(fertilize)))))
:otf-flg t)
(not-thm?
(property ccc)
;;; ------------ this will fail ---------------
:hints
(("Goal"
:OR
((:use (:instance bar (x disj-case-1)) :do-not '(generalize))
(:use (:instance bar (x disj-case-2)) :do-not '(fertilize)))))
:otf-flg nil)
(thm?
(property ccc)
;;; ------------ this will succeed on the first branch ---------
:hints
(("Goal"
:OR
((:in-theory (enable aaa) :use (:instance bar (x ccc)))
(:in-theory (enable bbb) :use (:instance mum (x ddd)))))))
(thm?
(property ccc)
;;; ------------ this will succeed on the second branch ---------
:hints
(("Goal"
:OR
((:in-theory (enable aaa) :use (:instance bar (x ddd)))
(:in-theory (enable bbb) :use (:instance mum (x ccc)))))))
(not-thm?
(property ccc)
;;; ------------ this will fail ---------
:hints
(("Goal"
:OR
((:in-theory (enable aaa) :use (:instance bar (x ddd)))
(:in-theory (enable bbb) :use (:instance mum (x ddd)))))))
(thm?
(property ccc)
;;; ------------ this will succeed ---------
:hints
(("Goal"
:OR
(( :use (:instance bar (x ccc)))
(:in-theory (enable bbb) :use (:instance mum (x ddd)))))))
(not-thm?
(property ccc)
;;; ------------ this will fail ---------
:hints
(("Goal"
:OR
((:induct (append ccc x))
(:in-theory (enable bbb) :use (:instance mum (x ddd)))))))
; These examples test custom keyword hints:
(add-custom-keyword-hint :syn-use
(pprogn
(fms "~%Expanding :syn-use generator~%"
nil *standard-co* state nil)
(value
(splice-keyword-alist
:syn-use
(list :use val)
keyword-alist))))
(not-thm?
(equal x y)
; This hint will expand at pre-process time. You will be able to
; tell because it will print a message every time it is run.
; You will see one expansion message. The proof will fail.
:hints (("Goal" :in-theory (disable car-cons)
:syn-use car-cons
:do-not '(generalize))
("Goal'" :in-theory (enable car-cons))))
(not-thm?
(equal x y)
; This will cause an error because of an ill-formed common hint mixed
; with syn-use.
:hints (("Goal" :in-theory (disable car-cons)
:syn-use car-cons
:do-not '(generalized)) ; error!
("Goal'" :in-theory (enable car-cons))))
(remove-custom-keyword-hint :syn-use) ; Added by Matt K.
(add-custom-keyword-hint :syn-use
(pprogn
(fms "~%Expanding :syn-use generator~%"
nil *standard-co* state nil)
(value
(splice-keyword-alist
:syn-use
(list :use val)
keyword-alist)))
:checker
(pprogn
(fms "~%Expanding :syn-use checker~%"
nil *standard-co* state nil)
(cond ((eq val 'cdr-cons)
(er soft ctx
"Syn-use doesn't allow you to use ~
~x0!"
val))
(t (value t)))))
(not-thm?
(equal x y)
; This hint will expand at pre-process time. You will see the checker
; and then the generator. The proof will fail.
:hints (("Goal" :in-theory (disable car-cons)
:syn-use car-cons
:do-not '(generalize))
("Goal'" :in-theory (enable car-cons))))
(not-thm?
(equal x y)
; This will cause an error because of the syn-use checker will fail.
:hints (("Goal" :in-theory (disable car-cons)
:syn-use cdr-cons
:do-not '(generalized)) ; error!
("Goal'" :in-theory (enable car-cons))))
(add-custom-keyword-hint :eror
(value
(splice-keyword-alist
:eror
`(:ERROR ,(msg "The value ~x0 is illegal!" val))
keyword-alist)))
(not-thm?
(equal (append (append a b) c)
(append a (append b c)))
; This will throw an error on translation.
:hints (("Subgoal *1/1'" :eror (a b c))))
(remove-custom-keyword-hint :eror) ; added by Matt K.
(add-custom-keyword-hint :eror
(value
(if (equal clause clause)
(splice-keyword-alist
:eror
`(:ERROR ,(msg "The value ~x0 is illegal!" val))
keyword-alist)
nil)))
(not-thm?
(equal (append (append a b) c)
(append a (append b c)))
; This will throw an error when Subgoal 1.1' arises
:hints (("Subgoal *1/1'" :eror (a b c))))
(remove-custom-keyword-hint :syn-use) ; added by Matt K.
(add-custom-keyword-hint :syn-use
(pprogn
(fms "~%Expanding :syn-use generator~%"
nil *standard-co* state nil)
(value
(if (equal clause clause)
(splice-keyword-alist
:syn-use
(list :use val)
keyword-alist)
nil)))
:checker
(pprogn
(fms "~%Expanding :syn-use checker~%"
nil *standard-co* state nil)
(cond ((eq val 'cdr-cons)
(er soft ctx
"Syn-use doesn't allow you to use ~
~x0!"
val))
(t (value t)))))
(thm?
(equal (append (append a b) c)
(append a (append b c)))
; You will see the checker expanded TWICE in pre-processing. The
; first expansion is when we are trying to eagerly eliminate the
; :syn-use hint. That fails. So then we just run the all the
; checkers and we see it again. Then the checker and the generator
; are run again in Subgoal *1/1'.
:hints (("Subgoal *1/1'" :in-theory (disable car-cons)
:syn-use car-cons
:do-not '(generalize))))
(add-custom-keyword-hint :count-down
(value
(if (zp val)
(splice-keyword-alist
:count-down
'(:NO-OP t)
keyword-alist)
(splice-keyword-alist
:count-down
`(:count-down ,(- val 1))
keyword-alist))))
(thm?
(equal (append (append a b) c)
(append a (append b c)))
:hints (("Subgoal *1/1'" :count-down 7)))
(thm?
(equal (append (append a b) c)
(append a (append b c)))
; Proof succeeds after a no-op hint is added
:hints (("Subgoal *1/1'" :count-down 2)))
(remove-custom-keyword-hint :count-down)
(not-thm?
(equal (append (append a b) c)
(append a (append b c)))
; Error: illegal keyword
:hints (("Subgoal *1/1'" :count-down 2)))
(add-custom-keyword-hint :count-down
(value
(if (and (equal clause clause)
(zp val))
(splice-keyword-alist
:count-down
'(:NO-OP t)
keyword-alist)
(splice-keyword-alist
:count-down
`(:count-down ,(- val 1))
keyword-alist)))
:checker
(if (natp val)
(value t)
(er soft ctx
":count-down wants a nat and ~x0 ain't one."
val)))
(not-thm?
(equal (append (append a b) c)
(append a (append b c)))
; Error at pre-process
:hints (("Subgoal *1/1'" :count-down t)))
(thm?
(equal (append (append a b) c)
(append a (append b c)))
:hints (("Subgoal *1/1'" :count-down 7)))
(thm?
(equal (append (append a b) c)
(append a (append b c)))
; Success
:hints (("Subgoal *1/1'" :count-down 2)))
(add-custom-keyword-hint :recurse
(er-progn
(value (cw "--- Here goes ---"))
(defthm append-right-id
(implies (true-listp x)
(equal (append x nil) x)))
(value (cw "--- Done ---"))
(value (if (equal clause clause)
(splice-keyword-alist
:recurse
'(:NO-OP t)
keyword-alist)
nil))))
(thm?
(equal (append (append a b) c)
(append a (append b c)))
; Scary Success. This was designed to test the ens tracking and we didn't find
; anything amiss.
; This was labeled as "scary" above because it seemed conceivable that we would
; be able to provoke a slow array warning.
:hints (("Subgoal *1/2" :in-theory (disable cdr-cons
CONS-CAR-CDR
car-cdr-elim))
("Subgoal *1/2'" :no-op t
:recurse t
)
("Subgoal *1/2''" :in-theory (disable cdr-cons cons-car-cdr))
("Subgoal *1/2'4'" :in-theory (enable cdr-cons))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Illustration of ideas in :doc hints-and-the-waterfall
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set-default-hints nil)
(set-override-hints nil)
; The following example is for advanced users of computed hints, and assumes an
; understanding of documentation topic hints-and-the-waterfall.
; Below we find two versions of nonlinearp-default-hint. The first is from
; books/arithmetic-5/lib/basic-ops/default-hint.lisp, with the comment slightly
; modified. The second is the result of removing a test and winding up with an
; infinite loop.
; For each version, we attempt to prove a trivial theorem that requires
; induction. The first attempt succeeds, while the second fails. In fact, we
; impose a time limit because the second attempt goes into an infinite loop.
; We explain this example by first explaining what the two versions of
; nonlinearp-default-hint have in common. Each is a function that can generate
; a computed hint in either of the following two situations:
; (A) If the goal is stable under simplification -- i.e., if the goal or an
; ancestor of it has passed through the simplifier without being changed --
; then assuming nonlinear arithmetic is currently off, a computed hint is
; generated that turns on nonlinear arithmetic for the current goal and all
; its descendents, at least until another hint turns nonlinear arithmetic
; off.
; (B) If we are at the top of the waterfall, nonlinear arithmetic is currently
; enabled, and at least one proof process has applied to the current goal
; or an ancestor of it, then a computed hint MAY BE generated that turns
; off nonlinear arithmetic.
; In (B), "MAY BE" can be replaced by "is" for the second version of
; nonlinearp-default-hint, which is the one that can cause an infinite loop.
; The first version of nonlinearp-default-hint restricts (B) by refusing to
; generate a computed hint if the most recently applied proof process is the
; "settled down" process. As we now explain, this refusal is what prevents an
; infinite loop.
; Consider the second version of nonlinearp-default-hint below, in which the
; clause is allowed to have just settled down when generating a hint that
; re-disables nonlinear arithmetic. The following sequence occurs.
; (1) The initial goal for theorem TEST1 passes unchanged through the
; simplification process (induction is the first successful proof
; activity). Thus the "settled-down" proof process hits, sending the goal
; back to the top of the waterfall.
; (2) The goal passes through the waterfall, again passing through the
; simplifier unchanged. This time it then passes through the
; "settled-down" process without hitting, since it had already settled
; down. So it reaches the point where we look for a computed hint to
; select with variable STABLE-UNDER-SIMPLIFICATIONP bound to T.
; Nonlinearp-default-hint generates a computed hint to turn on nonlinear
; arithmetic (situation (A) above) and sends the goal back to the top of
; the waterfall, with this hint as the selected hint.
; NOTE: the history of the goal is modified to remove the indication that
; it has settled down. Quoting from :doc hints-and-the-waterfall, about
; computed hints being selected in the case that
; STABLE-UNDER-SIMPLIFICATIONP is T:
; A subtlety is that in this case, if the most recent hit had been from
; settling down, then the prover ``changes its mind'' and considers that
; the goal has not yet settled down after all as it continues through the
; waterfall.
; (3) The hint is applied to enable nonlinear arithmetic, and the goal passes
; through the waterfall. Because its history says that it has not yet
; reached the point of settling down (see the "NOTE" in (2) above), the
; "settled-down" proof process hits, sending the goal back to the top of
; the waterfall.
; (4) In the search for an applicable hint, we are in situation (B) above and
; hence the nonlinearp-default-hint applies to disable nonlinear
; arithmetic. (Remember, we are considering the second version of
; nonlinearp-default-hint below, which does not consider settling down.)
; Then the goal passes through the waterfall, and exactly as in (2) above,
; situation (A) above applies, so nonlinearp-default-hint generates a
; computed hint to turn on nonlinear arithmetic and sends the goal back to
; the top of the waterfall, with this hint as the selected hint.
; We now have a loop (3), (4), (3), (4), (3), (4), .... So why does the first
; version of nonlinearp-default-hint break this loop? At the start of (4),
; situation (B) no longer applies because the goal has just settled down from
; (3), and hence the first (most recent) element of the history is a
; 'SETTLED-DOWN-CLAUSE entry. Indeed, we can see that the proof of TEST1 in
; the first encapsulate form below generates a comment that "We now enable
; non-linear arithmetic" but no such comment about disabling.
(encapsulate
()
(local
(defun nonlinearp-default-hint (stable-under-simplificationp hist pspv)
(declare
(xargs
:guard ; Guard change for tau after ACL2 Version 5.0 by J Moore:
(and (consp pspv)
(consp (car pspv))
(consp (car (car pspv)))
(consp (cdr (car (car pspv))))
(consp (cdr (cdr (car (car pspv)))))
(consp (cdr (cdr (cdr (car (car pspv))))))
(consp (cdr (cdr (cdr (cdr (car (car pspv)))))))
(consp (cdr (cdr (cdr (cdr (cdr (car (car pspv))))))))
(consp (cdr (cdr (cdr (cdr (cdr (cdr (car (car pspv)))))))))
(consp (car (cdr (cdr (cdr (cdr (cdr (cdr (car (car pspv)))))))))))))
(cond (stable-under-simplificationp
(if (not (access rewrite-constant
(access prove-spec-var pspv :rewrite-constant)
:nonlinearp))
(prog2$
(cw "~%~%[Note: We now enable non-linear arithmetic.]~%~%")
'(:computed-hint-replacement t
:nonlinearp t))
nil))
((access rewrite-constant
(access prove-spec-var pspv :rewrite-constant)
:nonlinearp)
(if (and (consp hist)
(consp (car hist))
;; The following is discussed below:
(not (equal (caar hist) 'SETTLED-DOWN-CLAUSE)))
(prog2$
(cw "~%~%[Note: We now disable non-linear arithmetic.]~%~%")
'(:computed-hint-replacement t
:nonlinearp nil))
nil))
(t
nil))))
(local
(add-default-hints
'((nonlinearp-default-hint stable-under-simplificationp hist pspv))))
(local
(defthm test1
(equal (len (append x nil))
(len x))
:rule-classes nil)))
(encapsulate
()
(local
(defun nonlinearp-default-hint (stable-under-simplificationp hist pspv)
(declare
(xargs
:guard ; Guard change for tau after ACL2 Version 5.0 by J Moore:
(and (consp pspv)
(consp (car pspv))
(consp (car (car pspv)))
(consp (cdr (car (car pspv))))
(consp (cdr (cdr (car (car pspv)))))
(consp (cdr (cdr (cdr (car (car pspv))))))
(consp (cdr (cdr (cdr (cdr (car (car pspv)))))))
(consp (cdr (cdr (cdr (cdr (cdr (car (car pspv))))))))
(consp (cdr (cdr (cdr (cdr (cdr (cdr (car (car pspv)))))))))
(consp (car (cdr (cdr (cdr (cdr (cdr (cdr (car (car pspv)))))))))))))
(cond (stable-under-simplificationp
(if (not (access rewrite-constant
(access prove-spec-var pspv :rewrite-constant)
:nonlinearp))
(prog2$
(cw "~%~%[Note: We now enable non-linear arithmetic.]~%~%")
'(:computed-hint-replacement t
:nonlinearp t))
nil))
((access rewrite-constant
(access prove-spec-var pspv :rewrite-constant)
:nonlinearp)
(if (and (consp hist)
(consp (car hist))
;; The extra test is removed this time:
;; (not (equal (caar hist) 'SETTLED-DOWN-CLAUSE))
)
(prog2$
(cw "~%~%[Note: We now disable non-linear arithmetic.]~%~%")
'(:computed-hint-replacement t
:nonlinearp nil))
nil))
(t
nil))))
(local
(add-default-hints
'((nonlinearp-default-hint stable-under-simplificationp hist pspv))))
(must-fail
(with-prover-time-limit
; The proof of the previous test1 has succeeded in Sept. 2009 on a 2.2GHz
; Opteron (tm) Processor 850 in under 1/20 seconds of real time. So the time
; limit below seems generous. It was still sufficient to see over 240 trips
; through the infinite loop.
1/5
(defthm test1
(equal (len (append x nil))
(len x))
:rule-classes nil))))
|