Skip to content

Commit 73c9c32

Browse files
authored
Merge pull request #45 from ryukinix/fixing-old-issues
feat: resolve 5+ years old issues
2 parents c1bca55 + 48dee31 commit 73c9c32

9 files changed

+59
-24
lines changed

run-test.lisp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
(load "fix-quicklisp")
22
(ql:quickload :lisp-inference/tests :silent t)
3+
4+
(defun rove/utils/reporter::print-source-location-as-file-path (stream file line column)
5+
(declare (ignore column))
6+
(format stream "~&at ~A~@[:~A~]~%"
7+
(rove/utils/reporter::enough-namestring* file)
8+
line))
39
(setf rove:*enable-colors* t)
410
(if (rove:run :lisp-inference/tests)
511
(sb-ext:exit :code 0)

src/equivalences.lisp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@
4949
(make-negation (make-conjunction (make-negation (first-operand exp))
5050
(make-negation (second-operand exp)))))
5151
(t exp))))
52+
53+
(defun implication (exp)
54+
"Implication equivalence ::
55+
(=> p q) <=> (v (~ p) q)"
56+
(if (implicationp exp)
57+
(make-disjunction (make-negation (first-operand exp))
58+
(second-operand exp))
59+
exp))

src/inferences.lisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
(operands (first-operand exp))))
4343
exp))
4444

45-
(defun addiction (exp p)
46-
"Addiction in inference rule ::
45+
(defun addition (exp p)
46+
"Addition in inference rule ::
4747
p => (v p q)"
4848
(make-disjunction exp p))
4949

src/package.lisp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
(:use #:cl #:cl-user)
88
(:export #:double-negation ;; equivalences
99
#:de-morgan
10+
#:implication
1011
#:modus-ponens ;; inferences
1112
#:modus-tollens
1213
#:syllogism-disjunctive
13-
#:addiction
14+
#:addition
1415
#:conjunction
1516
#:simplification-first
1617
#:simplification-second
@@ -33,7 +34,9 @@
3334
#:^
3435
#:v
3536
#:=>
37+
#:->
3638
#:<=>
39+
#:<->
3740
#:[+]
3841
#:make-conjunction
3942
#:make-negation

src/parser.lisp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@
7676
(defun implicationp (exp)
7777
"Verify if the expression is an implication"
7878
(and (binary-operationp exp)
79-
(operationp exp '=>)))
79+
(or (operationp exp '=>)
80+
(operationp exp '->))))
8081

8182
(defun biconditionalp (exp)
8283
"Verify if the expression is a biconditional"
8384
(and (binary-operationp exp)
84-
(operationp exp '<=>)))
85+
(or (operationp exp '<=>)
86+
(operationp exp '<->))))
8587

8688
(defun swap-operand-operator (exp)
8789
(if (and (listp exp)

src/truth-table.lisp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
;; the function is O(2^n) time, so I think is not a good idea put inside of it.
7676

7777
;; RECURSIVE BOMB, BE CAREFUL
78-
(defun stack-of-expressions (exp)
78+
(defun %stack-of-expressions (exp)
7979
"Based on propositional EXP generate a stack of expressions
8080
to be evaluated on truth-table generation"
8181
(cond ((and (valid-operationp exp)
@@ -93,6 +93,8 @@
9393
expressions))
9494
(t nil)))
9595

96+
(defun stack-of-expressions (exp)
97+
(remove-duplicates (%stack-of-expressions exp) :test #'equal))
9698

9799
(defun replace-tf (exp)
98100
(cond ((atom exp)

t/test-equivalence-rules.lisp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
(in-package #:lisp-inference/tests/test-equivalence-rules)
22

33
(deftest test-equivalence-rules
4-
(testing "== Equivalence rules!"
5-
(ok (equal (de-morgan '(^ p q))
6-
'(~ (v (~ p) (~ q))))
7-
"Equivalence: DE-MORGAN 1")
8-
(ok (equal (de-morgan '(~ (v p q)))
9-
'(^ (~ p) (~ q)))
10-
"Equivalence: DE-MORGAN 2")
4+
(testing "== Equivalence rules!"
5+
(ok (equal (de-morgan '(^ p q))
6+
'(~ (v (~ p) (~ q))))
7+
"Equivalence: DE-MORGAN 1")
8+
(ok (equal (de-morgan '(~ (v p q)))
9+
'(^ (~ p) (~ q)))
10+
"Equivalence: DE-MORGAN 2")
1111

12-
(ok (equal (de-morgan '(~ (^ (~ p) (~ q))))
13-
'(v p q))
14-
"Equivalence: DE-MORGAN 3")
12+
(ok (equal (de-morgan '(~ (^ (~ p) (~ q))))
13+
'(v p q))
14+
"Equivalence: DE-MORGAN 3")
1515

16-
(ok (equal (double-negation '(~ (~ p)))
17-
'p)
18-
"Equivalence: DOUBLE-NEGATION 1")
16+
(ok (equal (double-negation '(~ (~ p)))
17+
'p)
18+
"Equivalence: DOUBLE-NEGATION 1")
1919

20-
(ok (equal (double-negation 'p)
21-
'p)
22-
"Equivalence: DOUBLE-NEGATION 2")))
20+
(ok (equal (double-negation 'p)
21+
'p)
22+
"Equivalence: DOUBLE-NEGATION 2")
23+
(ok (equal (implication '(=> p q))
24+
'(v (~ p) q))
25+
"Equivalence: IMPLICATION EQUIVALENCE")
26+
27+
(ok (equal (implication '(-> p (~ q)))
28+
'(v (~ p) (~ q)))
29+
"Equivalence: IMPLICATION EQUIVALENCE 2")
30+
31+
))

t/test-inference-rules.lisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
'(=> X Z))
2020
"Inference: SYLLOGISM-HYPOTHETICAL")
2121

22-
(ok (equal (addiction 'p 'q)
22+
(ok (equal (addition 'p 'q)
2323
'(v p q))
24-
"Inference: ADDICTION")
24+
"Inference: ADDITION")
2525

2626
(ok (equal (conjunction '(=> p q) 'p)
2727
'(^ (=> P Q) P))

t/test-truth-table.lisp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@
5353
(print-truth-table '(^ (=> p q) r)))
5454
'simple-error)
5555
"Raise a error when there is more propositions than specified at *MAX-PROPOSITIONS*"))
56+
57+
58+
(deftest truth-table-without-duplicated-stack-of-expressions
59+
(ok (equal (inference::stack-of-expressions '(^ (~ p) (~ p)))
60+
'((~ p) (^ (~ p) (~ p))))))

0 commit comments

Comments
 (0)