The program for derivation of syllogisms, condensed version.





; "Factoring out" is a sword with two blades. Typical result of the
; factoring out is that code is shorter, more concise, approaching
; the essence of the problem, but in the same time, much harder
; to understand. Here is my last program for derivation of syllogisms,
; in condensed version.

(load "http://www.instprog.com/Instprog.default-library.lsp")
(dolist (fig1 '((S M)(M S)))
  (dolist (fig2 '((M P)(P M)))
    (dolist-multi((majqc minqc conqc)(map first (setf qc '((all-are '(for-all if begin))
                                                           (some-are '(exists and begin))
                                                           (some-arent '(exists and not))
                                                           (no-are '(for-all if not))))))
      (when (for-all (fn(m (truew (fn(p)((eval ((setf d (eval (append '(case (p 0)) qc))) 0))
                                         (fn(a)(eval (list (d 1)
                                                           (find (p 1) a)
                                                           (list (d 2) (find (p 2) a))
                                                           true)))
                                         m))))(if (and (= (length (unique (flat m))) 3)
                                                       (truew (setf major (cons majqc fig2)))
                                                       (truew (setf minor (cons minqc fig1))))
                                                  (truew (setf concl (cons conqc '(S P))))
                                                  true))
                    (sublists (sublists '(S M P))))
        (println= "\n" (++ syllogism) "\n\n  " major "\n  " minor "\n  " concl)))))


; For better explained, longer code and results, see here:

 How many syllogisms are there?  


Also, you can take a look on

 Jeff Dalton's version in Common Lisp 








--

No comments:

Post a Comment