Skip to content

Commit

Permalink
:measure-time
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Mar 10, 2016
1 parent 5ea93b7 commit 3926a91
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/nal/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
(comment
:seq-interval-from-premises ;post
:shift-occurrence-forward ;pre
:shift-occurrence-backward ;pre
:measure-time ;pre
:concurrent
:linkage-temporal)
23 changes: 13 additions & 10 deletions src/nal/deriver/matching.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@
[pattern rules task-type]
(let [t1 (gensym) t2 (gensym)
task (gensym) belief (gensym)
t-occurence (gensym) b-occurence (gensym)
truth-kw (if (= :goal task-type) :desire :truth)]
`(fn [{p1# :statement ~t1 ~truth-kw :as ~task}
{p2# :statement ~t2 :truth :as ~belief}]
(match [p1# p2#] ~(quote-operators pattern)
~(traverse {:t1 t1
:t2 t2
:task task
:belief belief
:task-type task-type}
rules)
:else nil))))
(walk `(fn [{p1# :statement ~t1 ~truth-kw :t-occurence :occurence :as ~task}
{p2# :statement ~t2 :truth :b-occurence :occurence :as ~belief}]
(match [p1# p2#] ~(quote-operators pattern)
~(traverse {:t1 t1
:t2 t2
:task task
:belief belief
:task-type task-type}
rules)
:else nil))
(= :el :t-occurence) t-occurence
(= :el :b-occurence) b-occurence)))

(defn find-and-replace-symbols
"Replaces all terms in statemnt to placeholders that will be used in pattern
Expand Down
14 changes: 14 additions & 0 deletions src/nal/deriver/preconditions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
(defmethod compound-precondition :not-set?
[[_ arg]]
[`(or (not (coll? ~arg)) (not (sets (first ~arg))))])

(defmethod compound-precondition :measure-time
[_]
[`(not= :eternal :t-occurence)
`(not= :eternal :b-occurence)])

;-------------------------------------------------------------------------------
(defmulti precondition-transformation (fn [arg1 _] (first arg1)))

Expand Down Expand Up @@ -113,6 +119,14 @@
[[_ p1 p2 p3] conclusion]
`(substitute ~p1 ~p2 ~p3 ~conclusion))

(defmethod precondition-transformation :measure-time
[[_ arg] conclusion]
(let [mt (gensym)]
(walk `(let [k# 1 ~arg (- :t-occurence :b-occurence)]
~(walk conclusion
(= :el arg) [:interval arg]))
(= :el arg) mt)))

(defn check-precondition
[conclusion precondition]
(if (seq? precondition)
Expand Down
33 changes: 17 additions & 16 deletions src/nal/deriver/rules.clj
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@
"Define rules. Rules must be #R statements."
;TODO exception on duplication of the rule
[name & rules]
`(let [rules# (rules->> (quote ~rules)
contains-list? generate-all-lists
contains-list? generate-all-lists
identity rule
order-for-all-same? generate-all-orders
allow-swapping? swap
allow-backward? expand-backward-rules)
judgement-rules# (check-duplication (filter judgement? rules#))
question-rules# (check-duplication (filter question? rules#))
goal-rules# (check-duplication (filter goal? rules#))]
(println "Q rules:" (count question-rules#))
(println "J rules:" (count judgement-rules#))
(println "G rules:" (count goal-rules#))
(def ~name {:judgement (rules-map judgement-rules# :judgement)
:question (rules-map question-rules# :question)
:goal (rules-map goal-rules# :goal)})))
`(time
(let [rules# (rules->> (quote ~rules)
contains-list? generate-all-lists
contains-list? generate-all-lists
identity rule
order-for-all-same? generate-all-orders
allow-swapping? swap
allow-backward? expand-backward-rules)
judgement-rules# (check-duplication (filter judgement? rules#))
question-rules# (check-duplication (filter question? rules#))
goal-rules# (check-duplication (filter goal? rules#))]
(println "Q rules:" (count question-rules#))
(println "J rules:" (count judgement-rules#))
(println "G rules:" (count goal-rules#))
(def ~name {:judgement (rules-map judgement-rules# :judgement)
:question (rules-map question-rules# :question)
:goal (rules-map goal-rules# :goal)}))))
2 changes: 1 addition & 1 deletion src/nal/rules.clj
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
(&& (#Y --> S) (#Y --> P)) :post (:t/intersection))
:pre ((:!= S P)) ]

#_#R[(M --> S) (M --> P) |- (((&/ ($X --> P) I) =/> ($X --> S)) :post (:t/induction :linkage-temporal)
#R[(M --> S) (M --> P) |- (((&/ ($X --> P) I) =/> ($X --> S)) :post (:t/induction :linkage-temporal)
(($X --> S) =\> (&/ ($X --> P) I)) :post (:t/abduction :linkage-temporal)
((&/ ($X --> P) I) </> ($X --> S)) :post (:t/comparison :linkage-temporal)
(&/ (#Y --> P) I (#Y --> S)) :post (:t/intersection :linkage-temporal))
Expand Down

0 comments on commit 3926a91

Please sign in to comment.