File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1111(defun propositionp (symbol )
1212 " Check if the given SYMBOL can be a proposition (letters)"
1313 (and (atom symbol )
14- (not (valid-operatorp symbol ))))
14+ (not (valid-operatorp symbol ))
15+ (not (member (symbol-name symbol ) ' (" T" " F" ) :test #' string-equal ))))
1516
1617(defun set-of-propositions (exp )
1718 " Given a propositional expression EXP return the list of
9192 (t nil )))
9293
9394
95+ (defun replace-tf (exp )
96+ (cond ((atom exp )
97+ (cond ((string-equal (symbol-name exp ) " T" ) t )
98+ ((string-equal (symbol-name exp ) " F" ) nil )
99+ (t exp )))
100+ (t (cons (replace-tf (car exp ))
101+ (replace-tf (cdr exp ))))))
102+
94103(defun eval-operations (exp-tree)
95104 " Generate all the truth-table cases and evaluated it based on EXP-TREE"
96105 (let ((cases (group-cases-to-propositions exp-tree)))
99108 (let ((prop (car pair))
100109 (value (cadr pair)))
101110 (nsubst value prop exp )))
102- (eval exp )))
111+ (eval (replace-tf exp ) )))
103112 (let ((exps (stack-of-expressions exp-tree)))
104113 (loop for case in cases
105114 collect (append case
Original file line number Diff line number Diff line change 3333 (ok (equal-expression ' (~ (~ p))
3434 ' p)
3535 " EQUAL EXPRESSION 2" )))
36+
37+ (deftest truth-table-tests-with-false-and-true
38+ (testing " == Truth-table tests with F and T as constant!"
39+ (ok (equal (eval-expression ' (^ p f))
40+ " FF" )
41+ " CONTRADICTION: p ^ f" )
42+
43+ (ok (equal (eval-expression ' (v p t ))
44+ " TT" )
45+ " TAUTOLOGY: p v t" )
46+
47+ (ok (equal (eval-expression (parse-logic " (~p v q <=> p => q) <=> t" ))
48+ " TTTT" )
49+ " TAUTOLOGY OF CONDITIONAL DEFINITION" )))
You can’t perform that action at this time.
0 commit comments