Codebase list cafeobj / b5d23e9
* Prototype implementation of new citp command :pctf. * Introduced new bterm inspection command 'bresolve'. Now binspect does not try to resolve but only abstract boolean term. bresolve does try resolving. tswd 8 years ago
8 changed file(s) with 156 addition(s) and 85 deletion(s). Raw diff Collapse all Expand all
24192419 :doc "TODO"
24202420 )
24212421
2422 ; (define ("binspect")
2423 ; :cateogory :proof
2424 ; :parser parse-citp-binspect
2425 ; :evaluator eval-citp-binspect
2426 ; :title "`binspect [in <module-name> :] <boolean-term> .`"
2427 ; :doc "TODO"
2428 ; )
2422 (define ("bresolve" ":bresoleve")
2423 :category :proof
2424 :parser identity
2425 :evaluator bresolve
2426 :title "{binspect :binspect}"
2427 :doc "TODO"
2428 )
24292429
24302430 ;;;
24312431
822822 (:rdr #..term-delimiting-chars. (:if-present in :symbol |:|)) (:seq-of :term) |.|)
823823 (binspect
824824 (:rdr #..term-delimiting-chars. (:if-present in :modexp |:|)) (:seq-of :term) |.|)
825 ((:+ |:bresolve| bresolve))
825826 )) ; end Top-Form
826827
827828 ;; some separated definitions of non-terminals.
7070 (defparameter non-exec-labels '(|:nonexec| |:non-exec| |:no-ex| |:noex| |:noexec|))
7171
7272 (defun axiom-is-non-exec? (ax)
73 ;; (format t "~&labels=~s" (axiom-labels ax))
7473 (intersection (axiom-labels ax) non-exec-labels))
7574
7675 (defun condition-has-match-condition (condition)
14241424 (let ((mod (if modexp
14251425 (eval-modexp modexp)
14261426 (get-context-module t))))
1427 (unless (eq mod (get-context-module))
1427 (unless (eq mod (get-context-module t))
14281428 (clear-term-memo-table *term-memo-table*))
14291429 (when (or (null mod) (modexp-is-error mod))
14301430 (if (null mod)
746746 (info (theory-info th)))
747747 (declare (type op-theory th)
748748 (type theory-info info))
749 #| this was done for efficiency concern. not good.
750 (setq res
751 (if (zero-rule-only th)
752 (%svref *theory-info-array*
753 (logandc2 (the fixnum (theory-info-code info)) .Z.))
754 info))
755 |#
756 (setf (method-theory-info-for-matching method info-table) info)))
749 ;;
750 (let((res (if (zero-rule-only th)
751 (%svref *theory-info-array*
752 (logandc2 (the fixnum (theory-info-code info)) .Z.))
753 info)))
754 (setf (method-theory-info-for-matching method info-table) res))))
757755
758756 ;;; GET-METHOD-PRECEDENCE
759757 ;;;
23212321 (setf (goal-targets .cur-goal.) nil)))))
23222322 t))
23232323
2324 ;;; ==============
23242325 ;;; :ctf or :ctf-
2325 ;;;
2326 ;;; ==============
23262327 (defun do-apply-ctf (cur-node term-or-equation)
23272328 (let ((*chaos-quiet* t)
23282329 (*rwl-search-no-state-report* t)
24632464
24642465 ;;; :pctf or :pctf-
24652466 ;;;
2466 (defun apply-pctf (s-forms dash? &optional (verbose *citp-verbose*))
2467 ;; TODO
2468 s-forms
2469 dash?
2470 verbose
2471 )
2467 (defun apply-pctf-internal (ptree-node s-form dash? &optional verbose)
2468 (declare (type ptree-node ptree-node))
2469 (let ((*chaos-quiet* t)
2470 (*rwl-search-no-state-report* t))
2471 (when (goal-is-discharged (ptree-node-goal ptree-node))
2472 (with-output-chaos-warning ()
2473 (format t "** The goal ~s has already been proved!." (goal-name (ptree-node-goal ptree-node)))
2474 (return-from apply-pctf-internal nil)))
2475 (format t "~%~a=> :goal{~a}" (if dash? "[pctf-]" "[pctf]") (goal-name (ptree-node-goal ptree-node)))
2476 (initialize-ptree-node ptree-node)
2477 (compile-module (goal-context (ptree-node-goal ptree-node)) t)
2478 (with-in-module ((goal-context (ptree-node-goal ptree-node)))
2479 (let ((term (simple-parse *current-module* s-form *cosmos*)))
2480 (multiple-value-bind (applied next-goals)
2481 (do-apply-ctf-with-constructors ptree-node term)
2482 (unless applied (return-from apply-pctf-internal nil))
2483 (unless next-goals
2484 ;; cancel side effects
2485 (initialize-ptree-node ptree-node)
2486 (return-from apply-pctf-internal nil))
2487 (format t "~%** Generated ~d goal~p" (length next-goals) (length next-goals))
2488 (when *citp-spoiler*
2489 ;; apply implicit rd
2490 (dolist (ngoal next-goals)
2491 (do-apply-rd ngoal nil 'ctf)
2492 (when (and dash? (goal-targets ngoal))
2493 ;; reset target
2494 (setf (goal-targets ngoal)
2495 (goal-targets (ptree-node-goal ptree-node))))))
2496 ;; add generated nodes as children
2497 (add-ptree-children ptree-node next-goals)
2498 (when verbose
2499 (dolist (gn (ptree-node-subnodes ptree-node))
2500 (pr-goal (ptree-node-goal gn))))
2501 (ptree-node-subnodes ptree-node))))))
2502
2503 (defun apply-pctf-to-node (target-node s-forms dash? &optional verbose)
2504 (unless s-forms (return-from apply-pctf-to-node nil))
2505 (let ((subs (apply-pctf-internal target-node (car s-forms) dash? verbose)))
2506 (if subs
2507 (dolist (target subs)
2508 (apply-pctf-to-node target (cdr s-forms) dash? verbose))
2509 (apply-pctf-to-node target-node (cdr s-forms) dash? verbose))))
2510
2511 (defun apply-pctf (ptree dash? s-forms &optional (verbose *citp-verbose*))
2512 (declare (type ptree ptree))
2513 (let ((target (get-next-proof-context ptree)))
2514 (unless target
2515 (format t "~%**> All goals have been proved!")
2516 (return-from apply-pctf nil))
2517 (reset-rewrite-counters)
2518 (begin-rewrite)
2519 (apply-pctf-to-node target s-forms dash? verbose)
2520 (end-rewrite)
2521 (report-citp-stat)
2522 (check-success ptree)))
24722523
24732524 ;;; -----------------------------------------------------
24742525 ;;; :csp or :csp-
109109 ;;; each non _and_ or _xor_ boolean sub-term is abstracted by a
110110 ;;; variable.
111111 (defstruct (abst-bterm (:print-function print-abst-bterm))
112 ; by variables
112 (module nil) ; context module
113113 (term nil) ; the original term
114114 (subst nil) ; list of substitution
115115 ; or instance of abst-bterm(for _and_ abstraction)
166166 (list-ac-subterms term *bool-and*)
167167 nil))
168168
169 (defun make-and-abstraction (term subterms)
169 (defun make-and-abstraction (term subterms module)
170170 (let ((subst nil))
171171 (dolist (sub subterms)
172172 (push (cons (get-hashed-bterm-variable sub) sub) subst))
173 (make-abst-and :term term :subst (nreverse subst))))
174
175 (defun abstract-boolean-term (term)
176 (let ((bterm (make-abst-bterm :term term))
173 (make-abst-and :term term :subst (nreverse subst) :module module)))
174
175 (defun abstract-boolean-term (term module)
176 (let ((bterm (make-abst-bterm :term term :module module))
177177 (xor-subs (xtract-xor-subterms term))
178178 (subst nil))
179179 ;; reset variable number & term hash
184184 (dolist (xs xor-subs)
185185 (let ((as (xtract-and-subterms xs)))
186186 (if as
187 (push (make-and-abstraction xs as) subst)
187 (push (make-and-abstraction xs as module) subst)
188188 (push (cons (get-hashed-bterm-variable xs) xs) subst))))
189189 ;; top operator is not xor
190190 (let ((as (xtract-and-subterms term)))
191 (when as
192 (push (make-and-abstraction term as) subst))))
191 (if as
192 (push (make-and-abstraction term as module) subst)
193 ;; we anly accept xor-and formal form
194 (with-output-chaos-error ('invalid-term)
195 (format t "Given term is not xor-and normal form.")))))
193196 (setf (abst-bterm-subst bterm) (nreverse subst))
194197 bterm))
195198
318321 ;;; resolve-abst-bterm : bterm
319322 ;;; retuns a list of substitution which makes bterm to be true.
320323 ;;;
324 (defvar .maximum-bterm-vars. 7)
325
321326 (defun resolve-abst-bterm (bterm &optional (module (get-context-module)))
322327 (declare (type abst-bterm bterm))
323 (let* ((abst-term (make-bterm-representation bterm))
324 (variables (term-variables abst-term))
325 (list-subst (assign-tf variables))
326 (answers nil))
327 (dolist (subst list-subst)
328 (let ((target (substitution-image-cp subst abst-term)))
329 (reset-reduced-flag target)
330 (when *debug-bterm*
331 (with-in-module ((get-context-module))
332 (format t "~%[resolver_target] ")
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))
341 (when *debug-bterm*
342 (with-in-module ((get-context-module))
343 (format t "~% --> ")
344 (term-print-with-sort $$term)))
345 (when (is-true? $$term)
346 (push subst answers))))
347 answers))
348
349 ;;; try-resolve-boolean-term : term -> Values (abst-bterm List(substitution))
328 (with-in-module (module)
329 (let* ((abst-term (make-bterm-representation bterm))
330 (variables (term-variables abst-term))
331 (answers nil))
332 (when (> (length variables) .maximum-bterm-vars.)
333 (with-output-chaos-warning ()
334 (format t "Sorry, but the current system can not handle more than ~d variables."
335 .maximum-bterm-vars.)
336 (return-from resolve-abst-bterm nil)))
337 (dolist (subst (assign-tf variables))
338 (let ((target (substitution-image-cp subst abst-term)))
339 (reset-reduced-flag target)
340 (when *debug-bterm*
341 (with-in-module ((get-context-module))
342 (format t "~%[resolver_target] ")
343 (term-print-with-sort target)
344 (print-next)
345 (format t "~% mod = ~a" *current-module*)
346 (print-next)
347 (print-method-brief (term-head target))
348 (print-next)
349 (format t " str: ~a" (method-rewrite-strategy (term-head target)))))
350 (setq target (reducer-no-stat target module :red))
351 (when *debug-bterm*
352 (with-in-module ((get-context-module))
353 (format t "~% --> ")
354 (term-print-with-sort $$term)))
355 (when (is-true? $$term)
356 (push subst answers))))
357 answers)))
358
359 ;;; make-abst-boolean-term : term -> Values (abst-bterm List(substitution))
350360 ;;;
351361 (defvar *abst-bterm* nil)
352362 (defvar *abst-bterm-representation* nil)
353363
354 (defun try-resolve-boolean-term (term module)
364 (defun make-abst-boolean-term (term module)
355365 (unless (sort= (term-sort term) *bool-sort*)
356366 (with-output-chaos-warning ()
357367 (format t "Given term is not of sort Bool. Ignored.")
358 (return-from try-resolve-boolean-term nil)))
368 (return-from make-abst-boolean-term nil)))
359369 (!setup-reduction module)
360370 (with-in-module (module)
361371 (reset-reduced-flag term)
362372 (let ((target (reducer-no-stat term module :red)))
363373 ;; abstract
364 (let ((bterm (abstract-boolean-term target)))
374 (let ((bterm (abstract-boolean-term target module)))
365375 (setq *abst-bterm* bterm)
366376 (setq *abst-bterm-representation*
367377 (make-bterm-representation bterm))
381391 (print-next)
382392 (term-print-with-sort var)
383393 (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))))))))
394 (term-print-with-sort mapping))))))))))
395
396 ;;; try-resolve-bterm
397 ;;;
398 (defun try-resolve-bterm ()
399 (unless *abst-bterm*
400 (with-output-chaos-error ('no-bterm)
401 (format t "No abstracted boolean term is specified. ~%Please do :binspect or binspect first.")))
402 (let ((bterm *abst-bterm*)
403 (module (abst-bterm-module *abst-bterm*)))
404 ;; find answers
405 (let ((ans (resolve-abst-bterm bterm module)))
406 (cond (ans
407 (with-in-module (module)
408 (format t "~%** The following assignment(s) can make the term 'true'.")
409 (let ((num 0))
410 (declare (type fixnum num))
411 (let ((*print-indent* (+ 2 *print-indent*)))
412 (dolist (sub ans)
413 (print-next)
414 (format t "(~d): " (incf num))
415 (print-substitution sub))))))
416 (t
417 (format t "~%** No solution was found.")))
418 (values bterm ans))))
399419
400420 ;;;
401421 (defun binspect-in-goal (goal-name preterm)
402422 (let* ((goal-node (get-target-goal-node goal-name))
403423 (context-module (goal-context (ptree-node-goal goal-node)))
404424 (target (do-parse-term* preterm context-module)))
405 (try-resolve-boolean-term target context-module)))
425 (make-abst-boolean-term target context-module)))
406426
407427 (defun binspect-in-module (mod-name preterm)
408428 (multiple-value-bind (target context-module)
409429 (do-parse-term* preterm mod-name)
410 (try-resolve-boolean-term target context-module)))
430 (make-abst-boolean-term target context-module)))
411431
412432 ;;; TOP LEVEL FUNCTION
413433 ;;; binspect-in
417437 (t
418438 (binspect-in-module goal-or-module-name preterm))))
419439
440 ;;; bresolve
441 ;;;
442 (defun bresolve ()
443 (try-resolve-bterm))
444
420445 ;;; EOF
222222 (let ((pctf-minus? (equal (car args) ":pctf-"))
223223 (list-terms (third args))
224224 (pre-terms nil))
225 (print list-terms)
226225 (dolist (lt list-terms)
227226 (push (second lt) pre-terms))
228227 (cons pctf-minus? (nreverse pre-terms))))
402401 (check-success *proof-tree*)))
403402
404403 ;;; :pctf
405 ;;;
404 ;;; ax-form ::= (pctf-? . forms) .
406405 (defun eval-citp-pctf (ax-form)
407406 (check-ptree)
408407 (with-in-module (*current-module*)
409408 (reset-rewrite-counters)
410409 (begin-rewrite)
411 ;; TODO
412 ax-form
413 ;; (apply-pctf (car ax-form) (cadr ax-form) (cddr ax-form))
410 (apply-pctf *proof-tree* (car ax-form) (cdr ax-form))
414411 (end-rewrite)
415412 (report-citp-stat)
416413 (check-success *proof-tree*)))