Created
July 30, 2012 14:42
-
-
Save adolfont/3207431 to your computer and use it in GitHub Desktop.
Partial Implementation of KE Method rules - 2
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
(ns ke) | |
; formulas | |
(defrecord AtomicFormula [name]) | |
(defrecord UnaryFormula [connective subformula]) | |
(defrecord BinaryFormula [connective left-subformula right-subformula]) | |
(defrecord SignedFormula [sign formula]) | |
; patterns | |
(defn unary-signed-pattern | |
"Returns true if a signed formula is in a given pattern" | |
[sign unary-connective signed-formula] | |
(and (= sign (:sign signed-formula)) (= unary-connective (:connective (:formula signed-formula))))) | |
; builders | |
(defn unary-signed-remove-sign-remove-connective-include-sign-builder | |
"Creates a new signed formula from another signed formula" | |
[sign signed-formula] | |
(->SignedFormula sign (:subformula (:formula signed-formula)))) | |
; rules | |
;; unary linear rules | |
(defn make-unary-rule | |
[sign-1 connective sign-2] | |
(fn [signed-formula-premise] | |
(if (unary-signed-pattern sign-1 connective signed-formula-premise) | |
(unary-signed-remove-sign-remove-connective-include-sign-builder sign-2 signed-formula-premise) | |
signed-formula-premise))) | |
;;; T-NOT | |
(def t-not-rule | |
"Applies the T-NOT rule if the premise is a T-NOT signed-formula" | |
(make-unary-rule :true :not :false)) | |
;;; F-NOT | |
(def f-not-rule | |
"Applies the F-NOT rule if the premise is a F-NOT signed-formula" | |
(make-unary-rule :false :not :true)) |
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
(ns ke-tests | |
(:use clojure.test) | |
(:use ke)) | |
; Atomic Formulas | |
(def anAtom (->AtomicFormula "A")) | |
(deftest test-atom-get-name | |
(is (= "A" (:name anAtom)))) | |
; Unary Formulas | |
(def aUnaryFormula (->UnaryFormula :not anAtom)) | |
(deftest test-unary-formula-get-connective | |
(is (= :not (:connective aUnaryFormula)))) | |
(deftest test-unary-formula-get-subformula | |
(is (= anAtom (:subformula aUnaryFormula)))) | |
; Binary Formulas | |
(def aBinaryFormula (->BinaryFormula :and anAtom aUnaryFormula)) | |
(deftest test-binary-formula-get-connective | |
(is (= :and (:connective aBinaryFormula)))) | |
(deftest test-binary-formula-get-left-subformula | |
(is (= anAtom (:left-subformula aBinaryFormula)))) | |
(deftest test-binary-formula-get-right-subformula | |
(is (= aUnaryFormula (:right-subformula aBinaryFormula)))) | |
; Signed Formulas | |
(def aSignedFormula (->SignedFormula :true aBinaryFormula)) | |
(deftest test-signed-formula-get-sign | |
(is (= :true (:sign aSignedFormula)))) | |
(deftest test-signed-formula-get-formula | |
(is (= aBinaryFormula (:formula aSignedFormula)))) | |
; Some formula for next tests | |
(def atom-a (->AtomicFormula "A")) | |
(def t-a (->SignedFormula :true atom-a)) | |
(def f-a (->SignedFormula :false atom-a)) | |
(def not-a (->UnaryFormula :not atom-a)) | |
(def t-not-a (->SignedFormula :true not-a)) | |
(def f-not-a (->SignedFormula :false not-a)) | |
; Unary Signed Patterns | |
(deftest test-unary-signed-pattern | |
(is (unary-signed-pattern :true :not t-not-a))) | |
; Unary Signed Builders | |
(deftest test-unary-signed-remove-sign-remove-connective-include-sign | |
(is (= f-a (unary-signed-remove-sign-remove-connective-include-sign-builder :false t-not-a)))) | |
; Unary Linear Rules | |
;; GENERAL RULE FOR T-NOT AND F-NOT | |
;; --> I DON'T KNOW HOW TO TEST make-unary-rule | |
;; T-NOT | |
(deftest test-t-not-rule | |
(is (= f-a (t-not-rule t-not-a)))) | |
;; F-NOT | |
(deftest test-f-not-rule | |
(is (= t-a (f-not-rule f-not-a)))) | |
;; TODO: represent tableaus -> the input is a partial tableau! | |
(run-tests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment