Created
September 11, 2011 21:52
-
-
Save mjg123/1210177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn bool-combinations [vs] | |
(loop [vs vs | |
a '({})] | |
(if (empty? vs) | |
a | |
(recur | |
(rest vs) | |
(flatten | |
(map | |
#(list | |
(assoc % (first vs) true) | |
(assoc % (first vs) false)) | |
a)))))) | |
(defmacro pr-truth-table* [vs pred] | |
`(for [{:syms ~vs} (bool-combinations '~vs)] | |
(println (apply str (interpose "\t" ~vs)) "\t" ~pred))) | |
(defn variables-in [exp] | |
(-> (filter #(= (name %) (.toUpperCase (name %))) (flatten exp)) distinct sort)) | |
(defmacro pr-truth-table [pred] | |
`(let [vs# (variables-in '~pred)] | |
(println (apply str (interpose "\t" vs#)) "\t" '~pred) | |
(pr-truth-table* vs# ~pred))) | |
(pr-truth-table (and A (not B))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Creating a “truth table” is not hard, you can use an useful tool (CKod, at http://ckod.sourceforge.net/_/) to make a “truth table”.
Good luck to you!