Codebase list cafeobj / d5209d4
Fixed sbcl acz match problem. Now it works, but this is not a complete fix. TODO. tswd 8 years ago
6 changed file(s) with 395 addition(s) and 467 deletion(s). Raw diff Collapse all Expand all
389389
390390 ;;; x = term
391391 ;;; y = ((term . eqn-num) ... )
392 #||
393 (defun delete-one-term
394 (x y)
392 ;;; #||
393 (defun delete-one-term (x y)
395394 (block exit
396395 (if (null y)
397396 'none
398 (if (term-is-applform? x)
399 ;; application form
400 (let ((head (term-head x))
401 (pos nil))
402 (setq pos
403 (position-if
404 #'(lambda (tv)
405 (let ((term (car tv)))
406 (and (term-is-applform? term)
407 (method-is-of-same-operator head
408 (term-head term)))))
409 (the list y)))
397 (if (term-is-applform? x)
398 ;; application form
399 (let ((head (term-head x))
400 (pos nil))
401 (setq pos (position-if #'(lambda (tv)
402 (let ((term (car tv)))
403 (and (term-is-applform? term)
404 (method-is-of-same-operator head
405 (term-head term)))))
406 (the list y)))
410407 ;; (break "0")
411 (unless pos
408 (unless pos
412409 (return-from exit :never-match))
413 (if (zerop pos)
414 (if (term-equational-equal x (caar y))
415 (return-from exit (cdr y))
416 (return-from exit 'none))
417 (let ((last y)
418 (rest (cdr y))
419 (cur-pos 1))
420 (declare (type fixnum cur-pos))
421 (loop
422 (when (= cur-pos pos)
423 (if (term-equational-equal x
424 (caar rest))
425 (progn
426 ;; delete pattern
427 (rplacd last (cdr rest))
428 (return-from exit y))
429 (return-from exit 'none)))
430 (incf cur-pos)
431 (setq last rest rest (cdr rest))))
432 ))
433 ;;
434 (if (term-equational-equal x (caar y))
435 (cdr y)
436 (let ((last y) (rest (cdr y)))
437 (loop (when (null rest) (return 'none))
438 (when (term-equational-equal x (caar rest))
439 ;; delete pattern
440 (rplacd last (cdr rest))
441 ;; new
442 (return y))
443 (setq last rest rest (cdr rest))))
444 ))
445 )))
446 ||#
447
448 ;; #||
410 (if (zerop pos)
411 (if (term-equational-equal x (caar y))
412 (return-from exit (cdr y))
413 (return-from exit 'none))
414 (let ((last y)
415 (rest (cdr y))
416 (cur-pos 1))
417 (declare (type fixnum cur-pos))
418 (loop
419 (when (= cur-pos pos)
420 (if (term-equational-equal x (caar rest))
421 (progn
422 ;; delete pattern
423 (rplacd last (cdr rest))
424 (return-from exit y))
425 (return-from exit 'none)))
426 (incf cur-pos)
427 (setq last rest rest (cdr rest))))))
428 ;; term is not application form
429 (if (term-equational-equal x (caar y))
430 (cdr y)
431 (let ((last y) (rest (cdr y)))
432 (loop (when (null rest) (return 'none))
433 (when (term-equational-equal x (caar rest))
434 ;; delete pattern
435 (rplacd last (cdr rest))
436 ;; new
437 (return y))
438 (setq last rest rest (cdr rest)))))))
439 ))
440
441 #||
449442 (defun delete-one-term
450443 (x y)
451444 (if (null y)
462455 (setq last rest rest (cdr rest))))
463456 ))
464457 )
465 ;; ||#
458 ||#
466459
467460 (defvar *ac-failure-eq* nil)
468461
558551 .z. (theory-info-code minfo-2)))
559552 (push (make-equation t1 t2) new-eqns)
560553 (progn
561 (when *match-debug*
554 (with-match-debug ()
562555 (setq *ac-failure-eq* (cons t1 t2)))
563556 (setq new-eqns nil)
564557 (return nil)) )))))))
567560 (progn
568561 (dolist (eq (nreverse new-eqns))
569562 (add-equation-to-m-system new-sys eq))
570 (when *match-debug*
563 (with-match-debug ()
571564 (format t "~%** ac-solution-from-state")
572565 (print-m-system new-sys))
573566 new-sys)
574567 (progn
575 (when *match-debug*
568 (with-match-debug ()
576569 (format t "~%** no ac solution")
577570 (print-next)
578571 (princ " - t1 = ") (term-print (car *ac-failure-eq*))
579572 (print-next)
580 (princ " - t2 = ") (term-print (cdr *ac-failure-eq*))
581 )
573 (princ " - t2 = ") (term-print (cdr *ac-failure-eq*)))
582574 nil))))
583575
584576 (#+GCL si:define-inline-function #-GCL defun test_same_term_list (x y)
643635 (declare (type list list))
644636 (let ((ms-list nil))
645637 (declare (type list ms-list))
646 #||
647 (when *match-debug*
648 (mapc #'(lambda (x) (format t "~&,,,~s" x)) list))
649 ||#
650638 (dolist (x list) ;;(copy-tree list)
651639 (declare (type list x))
652640 (let ((ms-elt (assoc-if #'(lambda (y)
653641 (declare (type list y))
654 #||
655 (when *match-debug*
656 (format t "~%..x|~d| " (cdr x))
657 (term-print (car x))
658 (format t "~&..y|~d| " (cdr y))
659 (term-print (car y))
660 (trace term-equational-equal))
661 ||#
662642 (and (= (the fixnum (cdr x))
663643 (the fixnum (cdr y)))
664644 (term-equational-equal (car y) (car x))))
665645 ms-list)))
666646 (if ms-elt
667647 (progn
668 #||
669 (when *match-debug*
670 (format t "~%..inc: ~s" ms-elt))
671 ||#
672648 (incf (the fixnum (cdr ms-elt))))
673649 (progn
674 #||
675 (when *match-debug*
676 (format t "~%..add: ~s" x))
677 ||#
678650 (push (cons x 1) ms-list)))))
679 #||
680 (when *match-debug*
681 (untrace term-equational-equal))
682 ||#
683651 ms-list))
684652
685653 ;;; check for multi-set equality
900868 (push (cons term eqn-number)
901869 rhs-constants)
902870 (progn
903 (when *match-debug*
871 (with-match-debug ()
904872 (format t "~%- :never-match : lhs-vars ")
905873 (print-chaos-object lhs-vars))
906874 ;; (format t "~&failure case #3")
914882 (push (cons term eqn-number)
915883 rhs-funs)
916884 (progn
917 (when *match-debug*
885 (with-match-debug ()
918886 (format t "~%- :never-match : lhs-vars ")
919887 (print-chaos-object lhs-vars))
920888 ;; (format t "~&failure case #4")
994962 (type fixnum rhs-c-max rhs-f-max rhs-full-bits
995963 dummy-bit lhs-r-mask))
996964 ;;
997 (when *match-debug*
998 (format t "~%..lhs-f-ms=~s, lhs-f-r=~s lhs-v-ms=~s, lhs-v-r=~s, l-m=~d l-gcd=~d" lhs-f-ms lhs-f-r lhs-v-ms lhs-v-r l-m l-gcd)
999 (format t "~&..all-rhs-funs=~s, rhs-c-ms=~s, rhs-c-r=~s, rhs-f-ms=~s, rhs-f-r=~s, r-m=~d, r-gcd=~d" all-rhs-funs rhs-c-ms rhs-c-r rhs-f-ms rhs-f-r r-m r-gcd))
965 ;; (when *match-debug*
966 ;; (format t "~%..lhs-f-ms=~s, lhs-f-r=~s lhs-v-ms=~s, lhs-v-r=~s, l-m=~d l-gcd=~d" lhs-f-ms lhs-f-r lhs-v-ms lhs-v-r l-m l-gcd)
967 ;; (format t "~&..all-rhs-funs=~s, rhs-c-ms=~s, rhs-c-r=~s, rhs-f-ms=~s, rhs-f-r=~s, r-m=~d, r-gcd=~d" all-rhs-funs rhs-c-ms rhs-c-r rhs-f-ms rhs-f-r r-m r-gcd))
1000968 ;; one more easy failure check
1001969 (when (or (> l-m r-m) ; a lhs item is repeated more than any rhs
1002970 (not (integerp (/ r-gcd l-gcd))))
258258 (when (term-equational-equal ,term_!* $$_term2)
259259 (return t))))
260260
261 ;;; acz-state-pool
262
263 #||
264 (defvar .acz-state-pool. nil)
265
266 (defmacro allocate-acz-state ()
267 ` (if .acz-state-pool.
268 (pop .acz-state-pool.)
269 (make-match-ACZ-state)))
270
271 (defmacro deallocate-acz-state (acz-state)
272 `(push ,acz-state .acz-state-pool.))
273
274 (eval-when (:execute :load-toplevel)
275 (dotimes (x 20) (push (make-match-ACZ-state) .acz-state-pool.)))
276 ||#
277
278261 (defmacro allocate-acz-state ()
279262 (make-match-ACZ-state))
280
281 #||
282 (defmacro deallocate-acz-state (acz-state)
283 nil)
284 ||#
285263
286264 #+CMU (declaim (ext:start-block match-acz-state-initialize
287265 match-acz-next-state
294272 (unless (eq (car x) (car y))
295273 (return nil))
296274 (setq x (cdr x))
297 (setq y (cdr y))
298 ))
275 (setq y (cdr y))))
299276
300277 ;;; NOTE this is a version for ACZ-internal use only.
301278 ;;; it simply takes care of the "from which equation" info.
573550 (when *match-debug*
574551 (format t "~%*** acz solution: ")
575552 (print-m-system new-sys)
576 (format t "~%***")
577 )
553 (format t "~%***"))
578554 (values new-sys made-zero))
579555 (progn
580 (when *match-debug*
581 (format t "~%*** no possible solution in this case")
556 (with-match-debug()
557 (format t "~%***[acz] no possible solution in this case")
582558 (print-next)
583559 (princ "t1 = ") (term-print (car *acz-failure-pat*))
584560 (print-next)
585 (princ "t2 = ") (term-print (cdr *acz-failure-pat*))
586 )
587 (values nil nil)))
588 )))
561 (princ "t2 = ") (term-print (cdr *acz-failure-pat*)))
562 (values nil nil))))))
589563
590564
591565 ;;; ACZ State Intialization
597571
598572 (defun match-ACZ-state-initialize (sys env)
599573 (declare (type list sys env))
574 (with-match-debug ()
575 (format t "~%** match-acz-state-initialize -------------------------------------")
576 (print-next)
577 (print-match-system-sys sys)
578 (print-next)
579 (print-match-system-env env))
600580 (block TOP
601581 (let ((eqn-number -1)
602582 (sys-methods (alloc-svec (length sys)))
611591 (type list all-lhs-vars all-lhs-funs all-rhs-constants
612592 all-rhs-funs))
613593 (dolist (equation sys)
614 (setf eqn-number
615 (1+ eqn-number))
594 (setf eqn-number (1+ eqn-number))
616595 (let* ((lhs-1 (equation-t1 equation))
617596 (rhs-1 (equation-t2 equation))
618597 (lh-meth (term-method lhs-1))
619 (rhs-meth (if (and (term-is-applform? rhs-1)
620 (not (term-is-builtin-constant? rhs-1)))
598 (rhs-meth (if (term-is-applform? rhs-1)
621599 (term-method rhs-1)
622 nil))
600 nil))
623601 (lhs-2 (list-ACZ-subterms lhs-1 lh-meth))
624 (rhs-2
625 (if (and rhs-meth
626 (method-is-AC-restriction-of rhs-meth lh-meth))
627 (list-ACZ-subterms rhs-1 rhs-meth)
628 (list rhs-1)))
602 (rhs-2 (if (and rhs-meth
603 (method-is-AC-restriction-of rhs-meth lh-meth))
604 (list-ACZ-subterms rhs-1 rhs-meth)
605 (list rhs-1)))
629606 (lhs-vars nil)
630607 (lhs-constants nil)
631608 (lhs-funs nil)
632609 (rhs-constants nil)
633 (rhs-funs nil)
634 )
610 (rhs-funs nil))
635611 (declare (type term rhs-1 rhs-1)
636612 (type method lh-meth)
637613 (type (or null method) rhs-meth)
638 (type list lhs-2 rhs-2 lhs-vars lhs-constants lhs-funs
614 (type list lhs-2 rhs-2 lhs-vars
615 lhs-constants lhs-funs
639616 rhs-constants rhs-funs))
640617 ;;
641618 (setf (svref sys-methods eqn-number) lh-meth)
644621 (dolist (term lhs-2)
645622 ;; for each subterm of lhs
646623 ;; note: unit elements are already eliminated from lhs-2.
647 ;;
648624 (cond ((term-is-variable? term)
649625 (let ((image (if env (environment-image env term) term)))
650626 (cond ((null image)
655631 (push (cons image eqn-number) lhs-constants))
656632 ((method-is-AC-restriction-of lh-meth
657633 (term-method image))
658 (dolist (term2 (list-ACZ-subterms
659 image (term-head image)))
634 (dolist (term2 (list-ACZ-subterms image (term-head image)))
660635 (cond ((term-is-variable? term2)
661636 (push (cons term2 eqn-number)
662637 lhs-vars))
674649 (push (cons term eqn-number) lhs-constants)
675650 )
676651 (t (push (cons term eqn-number) lhs-funs))))
652 (with-match-debug ()
653 (format t "~%[acz] lhs-funs = ~d, lhs-constants = ~d, lhs-vars = ~d"
654 (length lhs-funs) (length lhs-constants) (length lhs-vars))
655 (format t "~%[acz] lhs-funs")
656 (dolist (lf lhs-funs)
657 (print lf))
658 (format t "~%[acz] lhs-constants")
659 (dolist (lc lhs-constants)
660 (print lc))
661 (format t "~%[acz] lhs-vars")
662 (dolist (lv lhs-vars)
663 (print lv)))
677664 ;;
678665 ;; now that the lhs is partitioned - lets play with the rhs
679666 ;;
688675 (if (eq new :never-match)
689676 (if lhs-vars
690677 (push (cons term eqn-number) rhs-constants)
691 (return-from TOP (values nil t)))
692 (setq lhs-constants new))))))
678 (progn
679 (with-match-debug ()
680 (format t "~%++ :never-match 1"))
681 (return-from TOP (values nil t))))
682 (setq lhs-constants new))))))
693683 (t (let ((new (delete-one-term term lhs-funs)))
694684 (if (eq 'none new)
695685 (push (cons term eqn-number) rhs-funs)
696 (if (eq new :never-match)
697 (if lhs-vars
698 (push (cons term eqn-number) rhs-funs)
699 (return-from TOP (values nil t)))
700 (setq lhs-funs new)))))))
686 (if (eq new :never-match)
687 (if lhs-vars
688 (push (cons term eqn-number) rhs-funs)
689 (progn
690 (with-match-debug ()
691 (format t "~%++ :never-match 2"))
692 (return-from TOP (values nil t))))
693 (setq lhs-funs new)))))))
701694 ;; now there are no duplicates (things appearing on both sides)
702695 (let ((lhs-c-count (length lhs-constants))
703696 (lhs-f-count (length lhs-funs))
704697 (lhs-v-count (length lhs-vars))
705698 (rhs-c-count (length rhs-constants))
706 (rhs-f-count (length rhs-funs))
707 )
699 (rhs-f-count (length rhs-funs)))
708700 (declare (type fixnum lhs-c-count lhs-f-count lhs-v-count
709701 rhs-c-count rhs-f-count))
710702 ;; check trivial failure conditions
714706 (> lhs-f-count rhs-f-count)) ; too many funs to match
715707 ;; this assumption may be dubius in ACZ --- can arbitrary
716708 ;; funs eventually reduce to identity?
709 (with-match-debug ()
710 (format t "~%++ fail exit 1"))
717711 (return-from TOP (values nil t))) ; FAIL most miserably
718712 (setq all-lhs-funs (nconc lhs-funs all-lhs-funs))
719713 (setq all-lhs-vars (nconc lhs-vars all-lhs-vars))
725719 (null all-lhs-vars))
726720 (if (and (null all-rhs-constants) ; this is rare
727721 (null all-rhs-funs))
728 (return-from TOP (values (make-trivial-match-ACZ-state
729 :sys (new-m-system)) nil))
730 (return-from TOP (values nil t))))
722 (progn
723 (with-match-debug ()
724 (format t "~%++ done 1"))
725 (return-from TOP (values (make-trivial-match-ACZ-state :sys (new-m-system))
726 nil)))
727 (progn
728 (with-match-debug ()
729 (format t "~%++ nomatch done 1"))
730 (return-from TOP (values nil t)))))
731731 ;; maybe check for more simple cases, like one-var vs the world.
732732 ((and *use-one-var-opt*
733733 (null all-lhs-funs) ; only one var left on lhs
741741 (cdar all-lhs-vars))
742742 (nconc all-rhs-constants
743743 all-rhs-funs))))
744 (return-from TOP (values (make-trivial-match-ACZ-state :sys fresh-sys)
745 nil))))
744 (with-match-debug ()
745 (format t "~%++ done 2"))
746 (return-from TOP (values (make-trivial-match-ACZ-state :sys fresh-sys) nil))))
746747 (t
747748 (let* ((lhs-f-count (length all-lhs-funs))
748749 (lhs-v-count (1+ (length all-lhs-vars))) ; note this is "wrong"
801802 ;; TCW 14 Mar 91 need to restrict this for ACZ
802803 (when (or (> l-f-m r-m) ; a lhs item is repeated more than any rhs
803804 (not (integerp (/ r-gcd l-gcd))))
804 ;; (deallocate-acz-state state)
805 (with-match-debug ()
806 (format t "~%++ nomatch done 4"))
805807 (return-from TOP (values nil t))) ; FAIL most miserably
806808 ;; NOW, get down to the real work....
807809 ;; setup the repeat mask (first of v's)
881883 (declare (type fixnum my-compat))
882884 (do ()
883885 ((> dummy-bit rhs-c-max)
884 (progn ;; (deallocate-acz-state state)
885 (return-from TOP (values nil t))))
886 (progn
887 (with-match-debug ()
888 (format t "~%++ nomatch done 5"))
889 (return-from TOP (values nil t))))
886890 (unless (zerop (make-and dummy-bit my-compat))
887891 (setf (svref rhs-c-sol i) dummy-bit)
888892 (return))
897901 (do ()
898902 ((> dummy-bit rhs-f-max)
899903 (progn
900 ;; (deallocate-acz-state state)
904 (with-match-debug ()
905 (format t "~%++ nomatch-done 6"))
901906 (return-from TOP (values nil t))))
902907 (unless (zerop (make-and dummy-bit my-compat))
903908 (setf (svref rhs-f-sol i) dummy-bit)
944949 (setf (match-ACZ-state-no-more state) nil)
945950 (setf (match-ACZ-state-acz-state-p state) 'acz-state)
946951 ;;
947 (when *match-debug*
952 (with-match-debug ()
948953 (format t "~%acz-init: state=~&")
949954 (match-ACZ-unparse-match-ACZ-state state))
950955 ;;
951956 (values state nil)))))))
952957
953 #||
954
955 (defun match-ACZ-state-initialize (sys env)
956 (match-AC-state-initialize sys env :have-unit))
957 ||#
958
959958 (defun match-ACZ-next-state-sub (state)
960959 (do* ((m 0) ; only initialize these vars
961960 (rhs-c-sol (match-ACZ-state-rhs-c-sol state))
10071006 (values (trivial-match-ACZ-state-sys state) nil nil)))
10081007 (if (not (match-ACZ-state-p state))
10091008 (progn (format t "~% match-ACZ-Next-State given non match-ACZ-state:~A~%" state)
1010 (values nil t nil))
1009 (values nil nil t))
10111010 (let ((sys nil)
10121011 (no-more (match-acz-state-no-more state))
10131012 (zero nil))
10261025 )
10271026 (if no-more
10281027 (match-acz-next-state state)
1029 (values sys state nil)
1030 )
1031 )
1032 )
1033 ))))
1028 (values sys state nil))))))))
10341029
10351030 (defun match-acz-next-state-aux (state)
1036 (when *match-debug*
1031 (with-match-debug ()
10371032 (format t "~%** ACZ next state"))
10381033 (if (match-ACZ-state-no-more state)
10391034 (progn
10471042 (rhs-f-count (match-ACZ-state-rhs-f-count state))
10481043 ;; (rhs-full-bits (match-ACZ-state-rhs-full-bits state)) ;@@
10491044 (lhs-r-mask (match-ACZ-state-lhs-r-mask state))
1050 (made-zero nil)
1051 )
1045 (made-zero nil))
10521046 (nil) ; do forever
10531047 (declare (type fixnum n rhs-f-count rhs-f-max lhs-r-mask)
10541048 (type #+GCL vector #-GCL simple-vector
10871081 (dotimes (i (length lhs-v) t)
10881082 (declare (type fixnum i))
10891083 (if (< i 1) nil
1090 (unless (sort<=
1091 (term-sort
1092 (car (theory-zero
1093 (method-theory (svref
1094 ops
1095 (cdr
1096 (svref
1097 lhs-v
1098 i)))))))
1099 (term-sort (car (svref lhs-v i))))
1084 (unless (sort<= (term-sort (car (theory-zero (method-theory (svref ops (cdr (svref lhs-v i)))))))
1085 (term-sort (car (svref lhs-v i))))
11001086 (return nil))))))
11011087 (let ((sol nil))
11021088 (multiple-value-setq (sol made-zero)
11081094 ;; failed at f-level
11091095 ;; (deallocate-acz-state state)
11101096 (return (values nil t nil))))
1111 (setq n (1- n)))
1112 )
1097 (setq n (1- n))))
11131098 ((< (the fixnum (svref rhs-f-sol n)) rhs-f-max)
11141099 (match-ACZ-Rotate-Left rhs-f-sol n)
11151100 (when (and ; this is a compatible position for this bit
11301115 (setf (svref rhs-f-sol n) 1) ; reset this row to one
11311116 (setq n (1+ n)))))))
11321117
1133 #||
1134 (defun match-ACZ-next-state (state)
1135 (match-AC-next-state state))
1136 ||#
1137
11381118 #+CMU (declaim (ext:end-block))
11391119
11401120 ;; printout of important parts of ACZ state.
11411121 (defun match-ACZ-unparse-match-ACZ-state (ACZ-st)
1142 (format t "~%no more=~A~%" (match-ACZ-state-no-more ACZ-st))
1143 (format t "operators: ~%")
1144 (map nil #'print-chaos-object(match-ACZ-state-methods ACZ-st))
1145 (format t "RHS-f: ~%")
1146 (map nil #'print-chaos-object (match-ACZ-state-RHS-f ACZ-st))
1147 (format t "RHS-c: ~%")
1148 (map nil #'print-chaos-object (match-ACZ-state-RHS-c ACZ-st))
1149 (format t "LHS-v: ~%")
1150 (map nil #'print-chaos-object (match-ACZ-state-LHS-v ACZ-st))
1151 (format t "LHS-f: ~%")
1152 (map nil #'print-chaos-object (match-ACZ-state-LHS-f ACZ-st))
1153 (format t " rhs-c-count=~A, rhs-f-count=~A~%"
1154 (match-ACZ-state-RHS-c-count ACZ-st)
1155 (match-ACZ-state-RHS-f-count ACZ-st))
1156 (format t " lhs-c-count=~A, lhs-f-count=~A, lhs-v-count=~A~%"
1157 (match-ACZ-state-LHS-c-count ACZ-st)
1158 (match-ACZ-state-LHS-f-count ACZ-st)
1159 (match-ACZ-state-LHS-v-count ACZ-st))
1160 (let ((*print-base* 2)) ; these be bitvectors, print them as such
1161 (format t "-------------------~%rhs-c-sol= ~A~&rhs-f-sol=~A~%"
1162 (match-ACZ-state-RHS-c-sol ACZ-st) (match-ACZ-state-RHS-f-sol ACZ-st))
1163 (format t " rhs-c-max=~A, rhs-f-max=~A, rhs-full-bits=~A~%"
1164 (match-ACZ-state-RHS-c-max ACZ-st)
1165 (match-ACZ-state-RHS-f-max ACZ-st)
1166 (match-ACZ-state-RHS-full-bits ACZ-st))
1167 (format t " rhs-c-compat=~A, rhs-f-compat=~A~%"
1168 (match-ACZ-state-RHS-c-compat ACZ-st)
1169 (match-ACZ-state-RHS-f-compat ACZ-st))
1170 (format t " rhs-c-r=~A, rhs-f-r=~A~%"
1171 (match-ACZ-state-RHS-c-r ACZ-st)
1172 (match-ACZ-state-RHS-f-r ACZ-st))
1173 (format t " lhs-f-r=~A, lhs-v-r=~A~%"
1174 (match-ACZ-state-LHS-f-r ACZ-st)
1175 (match-ACZ-state-LHS-v-r ACZ-st))
1176 (format t " lhs-mask=~A~%"
1177 (match-ACZ-state-LHS-mask ACZ-st))
1178 (terpri)
1179 (format t " lhs-f-mask=~A~%"
1180 (match-ACZ-state-LHS-f-mask ACZ-st))
1181 (format t " lhs-r-mask=~A~%"
1182 (match-ACZ-state-LHS-r-mask ACZ-st))
1183 ))
1122 (format t "[ACZ State]")
1123 (let ((*print-indent* (+ 2 *print-indent*)))
1124 (format t "~%no more=~A" (match-ACZ-state-no-more ACZ-st))
1125 (format t "~%operators:")
1126 (map nil #'(lambda (x) (print-next) (print-chaos-object x))(match-ACZ-state-methods ACZ-st))
1127 (format t "~%RHS-f:")
1128 (map nil #'(lambda (x) (print-next) (print-chaos-object x)) (match-ACZ-state-RHS-f ACZ-st))
1129 (format t "~%RHS-c:")
1130 (map nil #'(lambda (x) (print-next) (print-chaos-object x)) (match-ACZ-state-RHS-c ACZ-st))
1131 (format t "~%LHS-v:")
1132 (map nil #'(lambda (x) (print-next) (print-chaos-object x)) (match-ACZ-state-LHS-v ACZ-st))
1133 (format t "~%LHS-f:")
1134 (map nil #'(lambda (x) (print-next) (print-chaos-object x)) (match-ACZ-state-LHS-f ACZ-st))
1135 (format t "~%rhs-c-count=~A, rhs-f-count=~A"
1136 (match-ACZ-state-RHS-c-count ACZ-st)
1137 (match-ACZ-state-RHS-f-count ACZ-st))
1138 (format t "~%lhs-c-count=~A, lhs-f-count=~A, lhs-v-count=~A"
1139 (match-ACZ-state-LHS-c-count ACZ-st)
1140 (match-ACZ-state-LHS-f-count ACZ-st)
1141 (match-ACZ-state-LHS-v-count ACZ-st))
1142 (let ((*print-base* 2)) ; these be bitvectors, print them as such
1143 (format t "-------------------~%rhs-c-sol= ~A~&rhs-f-sol=~A~%"
1144 (match-ACZ-state-RHS-c-sol ACZ-st) (match-ACZ-state-RHS-f-sol ACZ-st))
1145 (format t " rhs-c-max=~A, rhs-f-max=~A, rhs-full-bits=~A~%"
1146 (match-ACZ-state-RHS-c-max ACZ-st)
1147 (match-ACZ-state-RHS-f-max ACZ-st)
1148 (match-ACZ-state-RHS-full-bits ACZ-st))
1149 (format t " rhs-c-compat=~s, rhs-f-compat=~s~%"
1150 (match-ACZ-state-RHS-c-compat ACZ-st)
1151 (match-ACZ-state-RHS-f-compat ACZ-st))
1152 (format t " rhs-c-r=~s, rhs-f-r=~s~%"
1153 (match-ACZ-state-RHS-c-r ACZ-st)
1154 (match-ACZ-state-RHS-f-r ACZ-st))
1155 (format t " lhs-f-r=~s, lhs-v-r=~s~%"
1156 (match-ACZ-state-LHS-f-r ACZ-st)
1157 (match-ACZ-state-LHS-v-r ACZ-st))
1158 (format t " lhs-mask=~s~%"
1159 (match-ACZ-state-LHS-mask ACZ-st))
1160 (format t " lhs-f-mask=~s~%"
1161 (match-ACZ-state-LHS-f-mask ACZ-st))
1162 (format t " lhs-r-mask=~s~%"
1163 (match-ACZ-state-LHS-r-mask ACZ-st))
1164 )))
11841165
11851166 (defun match-ACZ-trivial-unparse (state)
11861167 (let ((sys (trivial-match-ACZ-state-sys state))
11871168 (no-more-p (trivial-match-ACZ-state-no-more-p state)))
11881169 sys
1189 (format t "~% acz-unparse-trivial no-more-p = ~A~%" no-more-p)
1190 )
1191 )
1170 (format t "~% acz-unparse-trivial no-more-p = ~A~%" no-more-p)))
11921171
11931172 (defun match-ACZ-args-nss (x) (match-ACZ-unparse-match-ACZ-state (car x)) (terpri))
11941173 (setf (get 'match-ACZ-next-state-sub 'print-args) 'match-ACZ-args-nss)
4949 ;;; 1 means that the decomposition has been already done and that there is
5050 ;;; no more next state
5151
52 #|
53 (defstruct (match-empty-state (:constructor create-match-empty-state (flag sys)))
54 (flag 0 :type bit)
55 sys )
56
57 (defmacro match-empty-state-flag (_s*) `(car ,_s*))
58 (defmacro match-empty-state-sys (s_*) `(cdr ,s_*))
59 (defmacro create-match-empty-state (_***flag _***sys) `(cons ,_***flag ,_***sys))
60
61 (defvar .match-empty-state. nil)
62 (eval-when (:execute :load-toplevel)
63 (setq .match-empty-state. (create-match-empty-state 0 nil)))
64
65 (defun the-match-empty-state () .match-empty-state.)
66
67 |#
68
6952 ;;; INITIALIZATION
7053
7154 ;;; Initialize an empty state. It check if the top symbols of each equation of
7962 (dolist (equation (m-system-to-list sys))
8063 (let ((lhs (equation-t1 equation))
8164 (rhs (equation-t2 equation)))
82 #||
83 (when (or (term-is-builtin-constant? rhs)
84 (term-is-variable? rhs))
85 (return-from no-match (values nil t)))
86 ||#
8765 (unless (term-type-eq lhs rhs)
8866 (return-from no-match (values nil t)))
8967 (unless (or (match-empty-equal lhs rhs)
9068 (and (term-is-application-form? lhs)
9169 (method-is-of-same-operator+ (term-head lhs)
9270 (term-head rhs))))
93 (return-from no-match (values nil t))))
94 )
71 (return-from no-match (values nil t)))))
9572 (values (create-match-empty-state 0 sys) nil)))
96
9773
9874 ;;; NEXT STATE
9975
10076 (defun match-empty-next-state (empty-st)
101 (declare (type list empty-st)
102 (values list list (or null t)))
103 #||
104 (unless empty-st
105 (with-output-chaos-warning ()
106 (format t "match empty next PANIC: illegal situation, the null state!"))
107 (break)
108 (return-from match-empty-next-state (values nil nil t)))
109 ||#
77 (declare (type list empty-st))
11078 (let ((flag (match-empty-state-flag empty-st))
11179 (sys (match-empty-state-sys empty-st)))
11280 (declare (type fixnum flag)
11381 (type list sys))
82
83 (with-match-debug ()
84 (format t "~%[empty-next-state] : given m-system~%")
85 (print-match-system-sys sys))
86
11487 (if (= flag 1)
11588 ;; no more state
11689 (values nil nil t)
117 (multiple-value-bind (new-m-sys no-match)
118 (match-decompose&merge (create-match-system (new-environment)
119 sys))
120 (if no-match
121 (values nil nil t)
122 (progn
123 (setf (match-empty-state-flag empty-st) 1)
124 (values (match-system-to-m-system new-m-sys)
125 empty-st
126 nil)))))))
90 (multiple-value-bind (new-m-sys no-match)
91 (match-decompose&merge (create-match-system (new-environment)
92 sys))
93 (if no-match
94 (values nil nil t)
95 (progn
96 (setf (match-empty-state-flag empty-st) 1)
97 (values (match-system-to-m-system new-m-sys)
98 empty-st
99 nil)))))))
127100
128101 ;;; EQUALITY
129102
124124 ;;; Initialize a match-state in which a match system "m-sys" has been inserted.
125125 ;;; "m-s" is supposed to be merged and ready for mutation i.e. decomposed
126126 ;;;
127 ;;; *NOT-USED*
128 ;;;(defun match-state-initialize (t1 t2)
129 ;;; (multiple-value-bind (m-sys no-match)
130 ;;; (match-system.dec-merg (match-system.new t1 t2))
131 ;;; (if no-match
132 ;;; (values nil t)
133 ;;; (multiple-value-bind (sys th-info)
134 ;;; (match-system.extract-one-system m-sys)
135 ;;; (values (match-state-create
136 ;;; m-sys sys th-info (theory-state-match-initialize th-info sys))
137 ;;; nil)
138 ;;; ))))
139127
140128 ;;; EMPTY-STATE, see "match-e.lisp"
141129
165153 ;; computes the next solution of th-match-state we quit this loop either if
166154 ;; there is no more new th-match-state or a new match system has been computed.
167155 (loop
168 (multiple-value-bind (sys new-th-match-state no-more)
169 (theory-state-match-next-state theory-info th-match-state)
170 (declare (type list sys)
171 (type t new-th-match-state)
172 (type (or null t) no-more))
173 (if no-more
174 (return (values nil t))
175 ;; "match-add-m-system" performs the decomposition and merging
176 ;; and must not destroy the current match system.
177 (multiple-value-bind (new-m-sys no-match)
178 ;; create a new merged match-system containing the old one
179 ;; and add sys.
180 (match-add-m-system (match-state-match-system st) sys)
181 ;; if there is no-match, continue (the loop)
182 ;; else try to returns the new match-state.
183 (unless no-match
184 (multiple-value-bind (sys-to-solve theory-info)
185 (m-system-extract-one-system (match-system-sys new-m-sys))
186 (declare (type list sys-to-solve)
187 (type theory-info theory-info))
188 (if (null sys-to-solve)
189 (return (values (match-state-create new-m-sys
190 nil
191 (theory-info *the-empty-theory*)
192 (the-match-empty-state))
193 nil))
194 (multiple-value-bind (th-st no-match)
195 (theory-state-match-initialize theory-info
196 sys-to-solve
197 (match-system-env new-m-sys))
198 ;; if no match, try another theory-state
199 (unless no-match
200 ;; else modify the th-match-state of st
201 (setf (match-state-theory-state st) new-th-match-state)
202 ;; and returns
203 (return (values (match-state-create
204 (match-system-modif-m-sys
205 new-m-sys
206 sys-to-solve)
207 sys-to-solve
208 theory-info
209 th-st)
210 nil))))))))
211 )))))
156 (multiple-value-bind (sys new-th-match-state no-more)
157 (theory-state-match-next-state theory-info th-match-state)
158 (declare (type list sys)
159 (type t new-th-match-state)
160 (type (or null t) no-more))
161 (if no-more
162 (return (values nil t))
163 ;; "match-add-m-system" performs the decomposition and merging
164 ;; and must not destroy the current match system.
165 (multiple-value-bind (new-m-sys no-match)
166 ;; create a new merged match-system containing the old one
167 ;; and add sys.
168 (match-add-m-system (match-state-match-system st) sys)
169 ;;
170 (with-match-debug ()
171 (let ((fun (theory-info-match-next-fun theory-info)))
172 (format t "~%<--[Match-next-state] funcalled ~s" fun)))
173 ;; if there is no-match, continue (the loop)
174 ;; else try to returns the new match-state.
175 (with-match-debug ()
176 (if no-match
177 (format t "[NEXT-MATCH-STATE] retun with no-match.")))
178 (unless no-match
179 (multiple-value-bind (sys-to-solve theory-info)
180 (m-system-extract-one-system (match-system-sys new-m-sys))
181 (declare (type list sys-to-solve)
182 (type theory-info theory-info))
183 (if (null sys-to-solve)
184 (return (values (match-state-create new-m-sys
185 nil
186 (theory-info *the-empty-theory*)
187 (the-match-empty-state))
188 nil))
189 (multiple-value-bind (th-st no-match)
190 (theory-state-match-initialize theory-info
191 sys-to-solve
192 (match-system-env new-m-sys))
193 ;; if no match, try another theory-state
194 (unless no-match
195 ;; else modify the th-match-state of st
196 (setf (match-state-theory-state st) new-th-match-state)
197 ;; and returns
198 (return (values (match-state-create (match-system-modif-m-sys new-m-sys sys-to-solve)
199 sys-to-solve
200 theory-info
201 th-st)
202 nil))))))))
203 )))))
212204 ;;; EOF
267267 (type list res)
268268 (values (or null t)))
269269 (with-match-debug ()
270 (princ "** !match-decompose-match:")
270 (format t "~%** !match-decompose-match:")
271271 (print-next)
272 (princ "-t1") (term-print-with-sort t1)
272 (princ "-t1: ") (term-print-with-sort t1)
273273 (print-next)
274 (princ "-t2") (term-print-with-sort t2)
275 (print-next)
276 (princ "-result:")
277 (dolist (x res)
278 (print-next)
279 (print-chaos-object x)))
274 (princ "-t2: ") (term-print-with-sort t2))
280275 (cond
281276 ;; [1] t1 is variable
282277 ((term-is-variable? t1)
293288 (if *one-way-match*
294289 (progn
295290 (with-match-debug ()
291 (print-next)
296292 (princ ">> FAIL for t2 is variable."))
297293 t) ; fail
298294 (!match-decompose-match t2 t1 res)))
301297 ((term-is-builtin-constant? t1)
302298 (let ((ans (not (term-builtin-equal t1 t2))))
303299 (with-match-debug ()
300 (print-next)
304301 (if ans
305302 (princ ">> SUCCESS, builtin-equal.")
306303 (princ ">> FAIL, builtin not equal.")))
315312 nil)
316313 (progn
317314 (with-match-debug ()
315 (print-next)
318316 (princ ">> FAIL, t2 is builtin."))
319317 t))
320318 ;; t2 also is an application form.
331329 (t2-subterms (term-subterms t2)))
332330 (declare (type list t1-subterms t2-subterms))
333331 (with-match-debug ()
334 (print ">> empty theory: do the full decompose..."))
332 (format t "~%>> empty theory: do the full decompose..."))
335333 (loop ; for each subterm try decomposition.
336334 (unless t1-subterms (return nil))
337335 (let ((ng (!match-decompose-match (car t1-subterms)
349347 ;;
350348 (progn
351349 (with-match-debug ()
352 (print ">> has theory: add their pair."))
350 (format t "~%>> has theory: add their pair."))
353351 (push (make-equation t1 t2) (cdr res))
354352 nil))
355353
360358 (if (term-is-on-demand? t2)
361359 (progn
362360 (with-match-debug ()
363 (print ">> term t2 is on demand."))
361 (format t "~%>> term t2 is on demand."))
364362 (mark-term-as-not-on-demand t2)
365363 (if (normalize-term t2)
366364 ;; no reduction has been performed.
381379 (term-head t2)))))
382380 (progn
383381 (with-match-debug ()
384 (print ">> theory Z."))
382 (format t "~%>> theory Z."))
385383 (push (make-equation t1 t2) (cdr res))
386384 nil)
387385 ;; will never match
388386 t)) )))))))
389387
390 ;; (declaim (inline match-decompose-equation))
391388
392389 (defun match-decompose-equation (t1 t2 &optional (sigma nil))
393390 (declare (type term t1 t2))
532529 (dolist (e m)
533530 (let ((t1 (equation-t1 e))
534531 (t2 (equation-t2 e)))
535 (format t "~%===========")
532 (format t "~%[m-system]===========")
536533 (format t "~&t1 = ") (term-print-with-sort t1)
537534 (format t "~&t2 = ") (term-print-with-sort t2))))
538535
693690 ;;; must not be modified.
694691 ;;; U: used by "match-system.dec-merg" and "match-add-m-system"
695692
696 ; (defun match-insert-if-coherent-with (new-env test-env new-sys eq-list &optional (check-match nil))
697 ; ;; note that new-env and new-sys are both initialy of the form (nil.nil)
698 ; (block the-end
699 ; (with-match-debug ()
700 ; (format T "~%insert:--------------------------------------")
701 ; (print-next)
702 ; (format t "new-env = ")
703 ; (if (car new-env)
704 ; (dolist (eq new-env)
705 ; (print-next)
706 ; (format t " LHS = ") (term-print-with-sort (equation-t1 eq))(terpri)
707 ; (print-next)
708 ; (format t " RHS = ") (term-print-with-sort (equation-t2 eq))(terpri))
709 ; (princ "empty"))
710 ; (print-next)
711 ; (format t "test-env = ")
712 ; (if (car test-env)
713 ; (dolist (eq test-env)
714 ; (print-next)
715 ; (format t " LHS = ") (term-print-with-sort (equation-t1 eq)) (terpri)
716 ; (print-next)
717 ; (format t " RHS = ") (term-print-with-sort (equation-t2 eq)) (terpri))
718 ; (princ "empty")))
719 ; (dolist (eq eq-list)
720 ; (let ((t1 (equation-t1 eq))
721 ; (t2 (equation-t2 eq)))
722 ; (with-match-debug ()
723 ; (print-next)
724 ; (format t " t1 = ") (term-print-with-sort t1) (terpri)
725 ; (print-next)
726 ; (format t " t2 = ") (term-print-with-sort t2) (terpri))
727 ; (cond ((term-is-variable? t1)
728 ; ;; checking of the sort information; redundant with
729 ; ;; `decompose-equation'.
730 ; (unless (sort<= (term-sort t2) (variable-sort t1)
731 ; *current-sort-order*)
732 ; (with-match-debug ()
733 ; (print-next)
734 ; (format t "-- non coherent, sort match fail."))
735 ; (return-from the-end t))
736 ; ;; new-env may be modified.
737 ; (let ((image-of-t1 (variable-image test-env t1)))
738 ; (if image-of-t1
739 ; (unless (term-equational-equal image-of-t1 t2)
740 ; (with-match-debug ()
741 ; (format t "~%-- non coherent, var binding conflicts in env."))
742 ; (return-from the-end t)) ; i.e no-coherent
743 ; (let ((image-of-t1-in-new (variable-image new-env t1)))
744 ; (if image-of-t1-in-new
745 ; (unless (term-equational-equal image-of-t1-in-new
746 ; t2)
747 ; (with-match-debug ()
748 ; (format t "~%-- non coherent, var binding in new-env."))
749 ; (return-from the-end t))
750 ; (add-equation-to-environment new-env eq))))))
751 ; (check-match
752 ; (when (term-is-variable? t2)
753 ; (return-from the-end t))
754 ; (if (and (term-is-applform? t2)
755 ; (term-is-applform? t1))
756 ; (let ((t1-head (term-head t1))
757 ; (t2-head (term-head t2)))
758 ; (if (method-is-of-same-operator+ t1-head t2-head)
759 ; (add-equation-to-m-system new-sys eq)
760 ; (let ((match-info (method-theory-info-for-matching! t1-head)))
761 ; (if (test-theory .Z. (theory-info-code match-info))
762 ; (add-equation-to-m-system new-sys eq)
763 ; (progn
764 ; (with-match-debug ()
765 ; (format t "~%-- non coherent, func conflict."))
766 ; (return-from the-end t))))))
767 ; (add-equation-to-m-system new-sys eq)))
768 ; ;;
769 ; (t (add-equation-to-m-system new-sys eq)))))
770
771 ; ;; add now all the equation of test-env into new-env (copy test-env)
772 ; (cond ((null (car test-env)) ())
773 ; ((null (car new-env))
774 ; (let ((l (environment-copy1 test-env)))
775 ; (rplaca new-env (car l))
776 ; (rplacd new-env (cdr l))) )
777 ; (t (nconc new-env test-env)))
778 ; (with-match-debug ()
779 ; (format t "~% insert: return -- coherent -------------------"))
780 ; nil ; i.e. the new-env is coherent
781 ; ))
693 (defun match-insert-if-coherent-with (new-env test-env new-sys eq-list &optional (check-match nil))
694 ;; note that new-env and new-sys are both initialy of the form (nil.nil)
695 (block the-end
696 (with-match-debug ()
697 (format T "~%insert:--------------------------------------")
698 (print-next)
699 (format t "new-env = ")
700 (if (car new-env)
701 (dolist (eq new-env)
702 (print-next)
703 (format t "~% LHS = ") (term-print-with-sort (equation-t1 eq))
704 (print-next)
705 (format t " RHS = ") (term-print-with-sort (equation-t2 eq))
706 (princ "empty")))
707 (print-next)
708 (format t "test-env = ")
709 (if (car test-env)
710 (dolist (eq test-env)
711 (format t "~% LHS = ") (term-print-with-sort (equation-t1 eq))
712 (print-next)
713 (format t " RHS = ") (term-print-with-sort (equation-t2 eq)))
714 (princ "empty"))
715 (terpri))
716 (dolist (eq eq-list)
717 (let ((t1 (equation-t1 eq))
718 (t2 (equation-t2 eq)))
719 (cond ((term-is-variable? t1)
720 ;; checking of the sort information; redundant with
721 ;; `decompose-equation'.
722 (unless (sort<= (term-sort t2) (variable-sort t1)
723 *current-sort-order*)
724 (with-match-debug ()
725 (print-next)
726 (format t "-- non coherent, sort match fail."))
727 (return-from the-end t))
728 ;; new-env may be modified.
729 (let ((image-of-t1 (variable-image test-env t1)))
730 (if image-of-t1
731 (unless (term-equational-equal image-of-t1 t2)
732 (with-match-debug ()
733 (format t "~%-- non coherent, var binding conflicts in env."))
734 (return-from the-end t)) ; i.e no-coherent
735 (let ((image-of-t1-in-new (variable-image new-env t1)))
736 (if image-of-t1-in-new
737 (unless (term-equational-equal image-of-t1-in-new
738 t2)
739 (with-match-debug ()
740 (format t "~%-- non coherent, var binding in new-env."))
741 (return-from the-end t))
742 (add-equation-to-environment new-env eq))))))
743 (check-match
744 (when (term-is-variable? t2)
745 (with-match-debug ()
746 (format t "~%-- non coherent, t2 is variable."))
747 (return-from the-end t))
748 (if (and (term-is-applform? t2)
749 (term-is-applform? t1))
750 (let ((t1-head (term-head t1))
751 (t2-head (term-head t2)))
752 (if (method-is-of-same-operator+ t1-head t2-head)
753 (add-equation-to-m-system new-sys eq)
754 (let ((match-info (method-theory-info-for-matching! t1-head)))
755 (if (test-theory .Z. (theory-info-code match-info))
756 (add-equation-to-m-system new-sys eq)
757 (progn
758 (with-match-debug ()
759 (format t "~%-- non coherent, func conflict."))
760 (return-from the-end t))))))
761 (add-equation-to-m-system new-sys eq)))
762 ;;
763 (t (add-equation-to-m-system new-sys eq)))))
764
765 ;; add now all the equation of test-env into new-env (copy test-env)
766 (cond ((null (car test-env)) ())
767 ((null (car new-env))
768 (let ((l (environment-copy1 test-env)))
769 (rplaca new-env (car l))
770 (rplacd new-env (cdr l))) )
771 (t (nconc new-env test-env)))
772 (with-match-debug ()
773 (format t "~%insert: return -- coherent -------------------")
774
775 )
776 nil ; i.e. the new-env is coherent
777 ))
778
779 #||
782780 (defun match-insert-if-coherent-with (new-env test-env new-sys eq-list &optional (check-match nil))
783781 ;; note that new-env and new-sys are both initialy of the form (nil.nil)
784782 (block the-end
828826 (t (nconc new-env test-env)))
829827 nil ; i.e. the new-env is coherent
830828 ))
829 ||#
831830
832831 ;;; MATCH-SYSTEM ===========================================================
833832 ;;;
895894 (if (term-is-variable? term1)
896895 (create-match-system (create-environment term1 term2)
897896 (new-m-system))
898 (create-match-system (new-environment)
899 (create-m-system term1 term2))))
897 (create-match-system (new-environment)
898 (create-m-system term1 term2))))
900899
901900 ;;; returns from a match-system a system (equivalent)
902901 ;;;
943942 )
944943 (return-from no-match (values nil t)))
945944
945 (with-match-debug ()
946 (format t "~%[Match-add-m-system]: given ---------------~%")
947 (print-match-system match-system)
948 (format t "~% m-sys")
949 (dolist (eq (m-system-to-list m-sys))
950 (let ((t1 (equation-t1 eq))
951 (t2 (equation-t2 eq)))
952 (print-next)
953 (princ "t1: ")(term-print-with-sort t1)
954 (print-next)
955 (princ "t2: ")(term-print-with-sort t2))))
956
946957 ;; new-system is modified but not match-system
947958 (setq new-system (add-m-system new-system (match-system-sys match-system)))
948 (return-from no-match
949 (values (create-match-system new-environment
950 new-system)
951 nil)))))
959 (let ((nsys (create-match-system new-environment new-system)))
960 (with-match-debug ()
961 (format t "~%[MATCH-ADD-M-SYSTEM]: generated new sys ----~%")
962 (print-match-system nsys))
963 (return-from no-match (values nsys nil))))))
952964
953965 ;;; Decompose&Merge
954966 ;;; Returns the decompose and merging of the given match-system
956968 (defun match-decompose&merge (m-sys &optional sigma)
957969 (block no-match
958970 (let ((sys (match-system-sys m-sys))
959 (env (match-system-env m-sys))
960 (new-env (new-environment) )
961 (new-sys (new-m-system)))
971 (env (match-system-env m-sys))
972 (new-env (new-environment) )
973 (new-sys (new-m-system)))
962974 (declare (type list new-env new-sys))
963975 (dolist (eq (m-system-to-list sys))
964976 (multiple-value-bind (eq-list clash-of-symbol)
965977 (match-decompose-equation (equation-t1 eq) (equation-t2 eq) sigma)
966978 (if clash-of-symbol
967979 (return-from no-match (values nil t))
968 (when (match-insert-if-coherent-with new-env
969 env
970 new-sys
971 eq-list)
972 (return-from no-match (values nil t))))))
973 (values (create-match-system new-env
974 new-sys)
975 nil))))
980 (when (match-insert-if-coherent-with new-env
981 env
982 new-sys
983 eq-list)
984 (return-from no-match (values nil t))))))
985 (let ((msys (create-match-system new-env new-sys)))
986 (with-match-debug ()
987 (format t "~%[Match-Decompose&Merge]: match system created: ----~%")
988 (print-match-system msys))
989 (values msys nil)))))
990
976991
977992 ;;; Extracts from the non fully decomposed part of "m-s" the biggest system to
978993 ;;; be solved into the theory "th". "th" and "sys" are returned.
7373 (defun first-match (t1 t2 &optional (sigma nil))
7474 (declare (type term t1 t2)
7575 (values list list (or null t) (or null t)))
76 (when *match-debug*
77 (format t "~%* First Match --------------------------------~%")
78 (princ " t1 = ") (term-print-with-sort t1)
79 (terpri)
80 (princ " t2 = ") (term-print-with-sort t2)
81 (terpri)
82 (format t " unify? = ~s" *do-unify*)
83 (terpri)
84 (format t " one way match? = ~s" *one-way-match*)
76 (with-match-debug ()
77 (format t "~%* First Match --------------------------------")
78 (print-next)
79 (princ "t1 = ") (term-print-with-sort t1)
80 (print-next)
81 (princ "t2 = ") (term-print-with-sort t2)
82 (print-next)
83 (format t "unify? = ~s" *do-unify*)
84 (print-next)
85 (format t "one way match? = ~s" *one-way-match*)
8586 (force-output))
8687 ;;
8788 (multiple-value-bind (m-sys no-match)
8990 (match-decompose&merge (create-match-system (new-environment)
9091 (create-m-system t1 t2))
9192 sigma)
92 (when *match-debug*
93 (with-match-debug()
9394 (format t "~%result of match-deocmpose&merge, no-match=~a" no-match)
9495 (force-output))
9596 ;; Note: if the two terms are similar then "m-sys" is empty.
9899 (let ((gst (new-global-state)))
99100 (declare (type list gst))
100101 (cond ((m-system-is-empty? (match-system-sys m-sys))
101 (when *match-debug*
102 (with-match-debug ()
102103 (format t "~% return with success"))
103104 (let ((subst (match-system-to-substitution m-sys)))
104 (when *match-debug*
105 (with-match-debug ()
105106 (print-substitution subst))
106107 (values gst
107108 subst
112113 (t (multiple-value-bind (sys theory-info)
113114 (match-system-extract-one m-sys)
114115 (declare (type list sys) (type theory-info theory-info))
115 (when *match-debug*
116 (with-match-debug()
116117 (format t "~% extracted a system ")
117118 (print-m-system sys)
118119 (format t "~% theory = ")
127128 (if no-match
128129 (values nil nil t nil)
129130 (let ((next-gst nil))
130 (when *match-debug*
131 (with-match-debug ()
131132 (format t "~%First match calls next-match")
132133 (format t "~% old gst: ")
133134 (print-global-state gst)
140141 sys
141142 theory-info
142143 th-st)))
143 (when *match-debug*
144 (with-match-debug ()
144145 (format t "~% next gst :")
145146 (print-global-state next-gst))
146147 (multiple-value-bind (new-gst subst no-match)
158159 (block the-end
159160 (let (st)
160161 (while (global-state-is-not-empty gst)
161 (when *match-debug*
162 (with-match-debug()
162163 (format t "~%* Next-match : global-state = ")
163164 (print-global-state gst))
164165 (setq st (global-state-top gst))
166167 (next-match-state st)
167168 (declare (type (or null match-state) new-st)
168169 (type (or null t) no-more))
169 (when *match-debug*
170 (with-match-debug ()
170171 (format t "~%** Next-match : next-match-state returns no-more = ~a" no-more)
171172 (unless no-more
172173 (format t "~%-- new state =")
183184 ;; popping: the reasoning is that a successful state
184185 ;; also terminates .
185186 (setq gst (global-state-pop gst))
186 (when *match-debug*
187 (with-match-debug ()
187188 (format t "~%* Next-match : return-with subst"))
188189 (return-from the-end
189190 (values gst
190191 (match-system-to-substitution m-sys)
191192 nil)))))))))
192 (when *match-debug*
193 (with-match-debug ()
193194 (format t "~%* Next-match : return with no-match"))
194195 ;; no match
195196 (values nil nil t)))