Implemented boolean term inspect command (:binspect, binspect)
':show proof' now shows the proof tree in horizontal.
tswd
8 years ago
818 | 818 | |}|) |
819 | 819 | ((:+ |:show| |:sh| |:describe| |:desc|) :args) |
820 | 820 | (|:spoiler| (:one-of (on) (off) (|.|))) |
821 | ((:+ |:binspect|) | |
821 | (|:binspect| | |
822 | 822 | (:rdr #..term-delimiting-chars. (:if-present in :symbol |:|)) (:seq-of :term) |.|) |
823 | (binspect | |
824 | (:rdr #..term-delimiting-chars. (:if-present in :modexp |:|)) (:seq-of :term) |.|) | |
823 | 825 | )) ; end Top-Form |
824 | 826 | |
825 | 827 | ;; some separated definitions of non-terminals. |
1528 | 1528 | (declare (ignore list-new-var)) |
1529 | 1529 | list-copied-term))) |
1530 | 1530 | |
1531 | ;;; print-term-struct | |
1532 | ;;; | |
1533 | (defun print-term-struct (term module &optional (stream *standard-output*)) | |
1534 | (with-in-module (module) | |
1535 | (let ((*standard-output* stream)) | |
1536 | (print-next) | |
1537 | (cond ((term-is-applform? term) | |
1538 | (format t "~a" (method-name (term-head term))) | |
1539 | (dotimes (x (length (term-subterms term))) | |
1540 | (let ((*print-indent* (+ 2 *print-indent*))) | |
1541 | (print-term-struct (term-arg-n term x) module)))) | |
1542 | ((term-is-builtin-constant? term) | |
1543 | (term-print term)) | |
1544 | (t (print-chaos-object term)))))) | |
1545 | ||
1531 | 1546 | ;;; EOF |
553 | 553 | (print-mod-name *memoized-module*) |
554 | 554 | (dump-term-hash *term-memo-table*))) |
555 | 555 | |
556 | ;;; | |
557 | ;;; print-term-horizontal | |
558 | ;;; | |
559 | (defun print-term-horizontal (term module &optional (stream *standard-output*)) | |
560 | (with-in-module (module) | |
561 | (let ((*standard-output* stream)) | |
562 | (print-next) | |
563 | (cond ((term-is-applform? term) | |
564 | (format t "~{~a~}" (method-symbol (term-head term))) | |
565 | (dotimes (x (length (term-subterms term))) | |
566 | (let ((*print-indent* (+ 4 *print-indent*))) | |
567 | (print-term-horizontal (term-arg-n term x) module)))) | |
568 | ((term-is-builtin-constant? term) | |
569 | (term-print term)) | |
570 | (t (print-chaos-object term)))))) | |
556 | 571 | ;;; EOF |
207 | 207 | (block next |
208 | 208 | (when (term-is-reduced? gt) |
209 | 209 | (return-from next nil)) |
210 | #|| | |
211 | (with-citp-debug () | |
212 | (with-in-module (module) | |
213 | (print-chaos-object (term-head gt)) | |
214 | (terpri) | |
215 | (print-chaos-object module) | |
216 | (format t "~%strat: ~a" (method-rewrite-strategy (term-head gt))))) | |
217 | ||# | |
210 | 218 | (reducer-no-stat gt module reduction-mode) |
211 | 219 | (unless (= rule-count-save (number-rewritings)) |
212 | 220 | (setq applied? t)))) |
1442 | 1450 | (result nil)) |
1443 | 1451 | (when cur-targets |
1444 | 1452 | (compile-module (goal-context cur-goal) t) |
1453 | (when next-goal | |
1454 | (compile-module (goal-context next-goal) t)) | |
1445 | 1455 | (dolist (target cur-targets) |
1446 | 1456 | (multiple-value-bind (c-result cur-target original-sentence) |
1447 | 1457 | (do-check-sentence target (or next-goal cur-goal) tactic) |
1468 | 1478 | (goal-name cur-goal))) |
1469 | 1479 | (return-from apply-rd (values nil nil))) |
1470 | 1480 | (if (goal-targets cur-goal) |
1471 | (do-apply-rd cur-goal (prepare-next-goal ptree-node) tactic) | |
1481 | (do-apply-rd cur-goal (prepare-next-goal ptree-node .tactic-rd.) tactic) | |
1472 | 1482 | (values nil nil)))) |
1473 | 1483 | |
1474 | 1484 | ;;; ========================== |
2492 | 2502 | (dolist (ax ax-forms) |
2493 | 2503 | (push (parse-axiom-declaration (parse-module-element-1 ax)) axs)) |
2494 | 2504 | (multiple-value-bind (applied next-goals) |
2495 | (do-apply-csp ptree-node axs) | |
2505 | (do-apply-csp ptree-node (nreverse axs)) | |
2496 | 2506 | (declare (ignore applied)) |
2497 | 2507 | (unless next-goals |
2498 | 2508 | (return-from apply-csp nil)) |
199 | 199 | ;;; |
200 | 200 | (defun make-and-representation (abst-and) |
201 | 201 | (declare (type abst-and abst-and)) |
202 | (make-right-assoc-normal-form *bool-and* | |
203 | (mapcar #'car (abst-and-subst abst-and)))) | |
202 | (let ((repre (make-right-assoc-normal-form *bool-and* | |
203 | (mapcar #'car (abst-and-subst abst-and))))) | |
204 | (update-lowest-parse repre) | |
205 | repre)) | |
204 | 206 | |
205 | 207 | (defun make-xor-representation (bterm) |
206 | 208 | (declare (type abst-bterm bterm)) |
207 | (make-right-assoc-normal-form *bool-xor* | |
208 | (mapcar #'(lambda (x) (if (abst-and-p x) | |
209 | (make-and-representation x) | |
210 | (car x))) | |
211 | (abst-bterm-subst bterm)))) | |
209 | (let ((repre (make-right-assoc-normal-form *bool-xor* | |
210 | (mapcar #'(lambda (x) (if (abst-and-p x) | |
211 | (make-and-representation x) | |
212 | (car x))) | |
213 | (abst-bterm-subst bterm))))) | |
214 | (update-lowest-parse repre) | |
215 | repre)) | |
212 | 216 | |
213 | 217 | (defun make-bterm-representation (bterm) |
214 | 218 | (let ((subst (abst-bterm-subst bterm))) |
322 | 326 | (answers nil)) |
323 | 327 | (dolist (subst list-subst) |
324 | 328 | (let ((target (substitution-image-cp subst abst-term))) |
329 | (reset-reduced-flag target) | |
325 | 330 | (when *debug-bterm* |
326 | 331 | (with-in-module ((get-context-module)) |
327 | 332 | (format t "~%[resolver_target] ") |
328 | (term-print-with-sort target))) | |
329 | (reducer-no-stat target module :red) | |
333 | (term-print-with-sort target) | |
334 | (print-next) | |
335 | (format t "~% mod = ~a" *current-module*) | |
336 | (print-next) | |
337 | (print-method-brief (term-head target)) | |
338 | (print-next) | |
339 | (format t " str: ~a" (method-rewrite-strategy (term-head target))))) | |
340 | (setq target (reducer-no-stat target module :red)) | |
330 | 341 | (when *debug-bterm* |
331 | 342 | (with-in-module ((get-context-module)) |
332 | 343 | (format t "~% --> ") |
333 | (term-print-with-sort target))) | |
334 | (when (is-true? target) | |
344 | (term-print-with-sort $$term))) | |
345 | (when (is-true? $$term) | |
335 | 346 | (push subst answers)))) |
336 | 347 | answers)) |
337 | 348 | |
340 | 351 | (defvar *abst-bterm* nil) |
341 | 352 | (defvar *abst-bterm-representation* nil) |
342 | 353 | |
343 | (defun try-resolve-boolean-term (term &optional (module (get-context-module))) | |
354 | (defun try-resolve-boolean-term (term module) | |
344 | 355 | (unless (sort= (term-sort term) *bool-sort*) |
345 | 356 | (with-output-chaos-warning () |
346 | 357 | (format t "Given term is not of sort Bool. Ignored.") |
347 | 358 | (return-from try-resolve-boolean-term nil))) |
348 | (multiple-value-bind (target app?) | |
349 | (normalize-term-in module term) | |
350 | (declare (ignore app?)) | |
351 | ;; abstract | |
352 | (let ((bterm (abstract-boolean-term target))) | |
353 | (setq *abst-bterm* bterm) | |
354 | (setq *abst-bterm-representation* | |
355 | (make-bterm-representation bterm)) | |
356 | (let ((*print-indent* (+ 2 *print-indent*))) | |
357 | (format t "~%** Abstracted boolean term:") | |
358 | (with-in-module (module) | |
359 | (print-next) | |
360 | (term-print-with-sort *abst-bterm-representation*) | |
361 | (format t "~%,where") | |
362 | (let ((*print-indent* (+ 2 *print-indent*))) | |
363 | (dolist (var (term-variables *abst-bterm-representation*)) | |
364 | (let ((mapping (find-bvar-subst var bterm))) | |
365 | (unless mapping | |
366 | (with-output-chaos-error ('internal-err) | |
367 | (format t "Could not find the mapping of variable ~a." (variable-name var)))) | |
368 | (print-next) | |
369 | (term-print-with-sort var) | |
370 | (princ " |-> ") | |
371 | (term-print-with-sort mapping)))) | |
372 | ;; find answers | |
373 | (let ((ans (resolve-abst-bterm bterm module))) | |
374 | (cond (ans | |
375 | (format t "~%** The following assignment(s) can make the term 'true'.") | |
376 | (let ((num 0)) | |
377 | (declare (type fixnum num)) | |
378 | (let ((*print-indent* (+ 2 *print-indent*))) | |
379 | (dolist (sub ans) | |
380 | (print-next) | |
381 | (format t "(~d): " (incf num)) | |
382 | (print-substitution sub))))) | |
383 | (t | |
384 | (format t "~%** No solution was found."))) | |
385 | (values bterm ans))))))) | |
359 | (!setup-reduction module) | |
360 | (with-in-module (module) | |
361 | (reset-reduced-flag term) | |
362 | (let ((target (reducer-no-stat term module :red))) | |
363 | ;; abstract | |
364 | (let ((bterm (abstract-boolean-term target))) | |
365 | (setq *abst-bterm* bterm) | |
366 | (setq *abst-bterm-representation* | |
367 | (make-bterm-representation bterm)) | |
368 | (let ((*print-indent* (+ 2 *print-indent*))) | |
369 | (format t "~%** Abstracted boolean term:") | |
370 | (with-in-module (module) | |
371 | (print-next) | |
372 | (term-print-with-sort *abst-bterm-representation*) | |
373 | (print-term-graph *abst-bterm-representation* *chaos-verbose*) | |
374 | (format t "~% where") | |
375 | (let ((*print-indent* (+ 2 *print-indent*))) | |
376 | (dolist (var (term-variables *abst-bterm-representation*)) | |
377 | (let ((mapping (find-bvar-subst var bterm))) | |
378 | (unless mapping | |
379 | (with-output-chaos-error ('internal-err) | |
380 | (format t "Could not find the mapping of variable ~a." (variable-name var)))) | |
381 | (print-next) | |
382 | (term-print-with-sort var) | |
383 | (princ " |-> ") | |
384 | (term-print-with-sort mapping)))) | |
385 | ;; find answers | |
386 | (let ((ans (resolve-abst-bterm bterm module))) | |
387 | (cond (ans | |
388 | (format t "~%** The following assignment(s) can make the term 'true'.") | |
389 | (let ((num 0)) | |
390 | (declare (type fixnum num)) | |
391 | (let ((*print-indent* (+ 2 *print-indent*))) | |
392 | (dolist (sub ans) | |
393 | (print-next) | |
394 | (format t "(~d): " (incf num)) | |
395 | (print-substitution sub))))) | |
396 | (t | |
397 | (format t "~%** No solution was found."))) | |
398 | (values bterm ans)))))))) | |
386 | 399 | |
387 | 400 | ;;; |
388 | 401 | (defun binspect-in-goal (goal-name preterm) |
828 | 828 | ;;; |
829 | 829 | ;;; print-proof-tree |
830 | 830 | ;;; |
831 | (defvar *show-proof-mode* :horizontal) | |
832 | ||
831 | 833 | (defun print-proof-tree (goal-name &optional (describe nil)) |
832 | 834 | (unless *proof-tree* |
833 | 835 | (with-output-chaos-warning () |
840 | 842 | (ptree-root *proof-tree*)))) |
841 | 843 | (if describe |
842 | 844 | (describe-proof-tree target-node) |
843 | (!print-proof-tree target-node (get-next-proof-context *proof-tree*))))) | |
844 | ||
845 | (defun !print-proof-tree (root-node next-target &optional (stream *standard-output*)) | |
845 | (!print-proof-tree target-node (get-next-proof-context *proof-tree*) *show-proof-mode*)))) | |
846 | ||
847 | (defun !print-proof-tree (root-node next-target mode &optional (stream *standard-output*)) | |
848 | (if (eq mode :horizontal) | |
849 | (!print-proof-horizontal root-node next-target stream) | |
850 | (!print-proof-vertical root-node next-target stream))) | |
851 | ||
852 | (defun !print-proof-vertical (root-node next-target stream) | |
846 | 853 | (let* ((leaf? #'(lambda (node) (null (dag-node-subnodes node)))) |
847 | 854 | (leaf-name #'(lambda (node) |
848 | 855 | (with-output-to-string (s) |
862 | 869 | (print-next nil *print-indent* stream) |
863 | 870 | (print-trees (list (augment-tree root-node)) stream))) |
864 | 871 | |
872 | (defun !print-proof-horizontal (node next-target stream) | |
873 | (let ((*standard-output* stream)) | |
874 | (let ((goal (ptree-node-goal node))) | |
875 | (with-in-module ((goal-context goal)) | |
876 | (when (eq node next-target) | |
877 | (princ ">")) | |
878 | (if (goal-tactic goal) | |
879 | (format t "~a ~a" (goal-tactic goal) (goal-name goal)) | |
880 | (format t "~a" (goal-name goal))) | |
881 | (when (node-is-discharged? node) | |
882 | (princ "*")))) | |
883 | (let ((subnodes (ptree-node-subnodes node))) | |
884 | (when subnodes | |
885 | (let ((*print-indent* (+ 4 *print-indent*))) | |
886 | (dolist (sub subnodes) | |
887 | (print-next-prefix #\Space) | |
888 | (!print-proof-horizontal sub next-target stream))))))) | |
889 | ||
890 | ||
865 | 891 | (defun describe-proof-tree (node) |
866 | 892 | (declare (type ptree-node node)) |
867 | 893 | (flet ((proved? () |