Skip to content

Commit dea72f0

Browse files
committed
feat: add implication equivalence + tests
Improve tests reporter to work over compilation mode of emacs and click to goto error line Fix #29
1 parent 076b70e commit dea72f0

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
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/package.lisp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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
@@ -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)

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+
))

0 commit comments

Comments
 (0)