Assume I have the following set of definstances which show the inputs and outputs of various stages of an electric circuit. I don't include all the classes and instances as I don't think it's relevant to my problem. I will include a photo that will help you understand how this problem works.
Here input1 goes to adder A1 as both inputs. Input3 and input4 go to Π2 multiplier as inputs.
definstances facts(
([command_10_inp1] of command_data
(clock 10)
(object [input_1])
(value 6))
([command_10_inp2] of command_data
(clock 10)
(object [input_2])
(value 4))
([command_10_inp3] of command_data
(clock 10)
(object [input_3])
(value 25))
([command_10_inp4] of command_data
(clock 10)
(object [input_4])
(value 12))
([command_1_inp1] of command_data
(clock 1)
(object [input_1])
(value 21))
([command_1_inp2] of command_data
(clock 1)
(object [input_2])
(value 28))
([command_1_inp3] of command_data
(clock 1)
(object [input_3])
(value 10))
([command_1_inp4] of command_data
(clock 1)
(object [input_4])
(value 25))
([command_2_inp1] of command_data
(clock 2)
(object [input_1])
(value 7))
([command_2_inp2] of command_data
(clock 2)
(object [input_2])
(value 25))
([command_2_inp3] of command_data
(clock 2)
(object [input_3])
(value 13))
([command_2_inp4] of command_data
(clock 2)
(object [input_4])
(value 15))
([command_3_inp1] of command_data
(clock 3)
(object [input_1])
(value 11))
([command_3_inp2] of command_data
(clock 3)
(object [input_2])
(value 17))
([command_3_inp3] of command_data
(clock 3)
(object [input_3])
(value 24))
([command_3_inp4] of command_data
(clock 3)
(object [input_4])
(value 31))
([command_4_inp1] of command_data
(clock 4)
(object [input_1])
(value 18))
([command_4_inp2] of command_data
(clock 4)
(object [input_2])
(value 11))
([command_4_inp3] of command_data
(clock 4)
(object [input_3])
(value 28))
([command_4_inp4] of command_data
(clock 4)
(object [input_4])
(value 21))
([command_5_inp1] of command_data
(clock 5)
(object [input_1])
(value 25))
([command_5_inp2] of command_data
(clock 5)
(object [input_2])
(value 24))
([command_5_inp3] of command_data
(clock 5)
(object [input_3])
(value 30))
([command_5_inp4] of command_data
(clock 5)
(object [input_4])
(value 10))
([command_6_inp1] of command_data
(clock 6)
(object [input_1])
(value 12))
([command_6_inp2] of command_data
(clock 6)
(object [input_2])
(value 19))
([command_6_inp3] of command_data
(clock 6)
(object [input_3])
(value 11))
([command_6_inp4] of command_data
(clock 6)
(object [input_4])
(value 19))
([command_7_inp1] of command_data
(clock 7)
(object [input_1])
(value 1))
([command_7_inp2] of command_data
(clock 7)
(object [input_2])
(value 31))
([command_7_inp3] of command_data
(clock 7)
(object [input_3])
(value 7))
([command_7_inp4] of command_data
(clock 7)
(object [input_4])
(value 22))
([command_8_inp1] of command_data
(clock 8)
(object [input_1])
(value 0))
([command_8_inp2] of command_data
(clock 8)
(object [input_2])
(value 31))
([command_8_inp3] of command_data
(clock 8)
(object [input_3])
(value 3))
([command_8_inp4] of command_data
(clock 8)
(object [input_4])
(value 23))
([command_9_inp1] of command_data
(clock 9)
(object [input_1])
(value 31))
([command_9_inp2] of command_data
(clock 9)
(object [input_2])
(value 1))
([command_9_inp3] of command_data
(clock 9)
(object [input_3])
(value 6))
([command_9_inp4] of command_data
(clock 9)
(object [input_4])
(value 8))
([reading_10_m1] of reading_data
(clock 10)
(object [m1])
(value 12))
([reading_10_m2] of reading_data
(clock 10)
(object [m2])
(value 31))
([reading_10_m3] of reading_data
(clock 10)
(object [m3])
(value 12))
([reading_10_out] of reading_data
(clock 10)
(object [out1])
(value 28))
([reading_1_m1] of reading_data
(clock 1)
(object [m1])
(value 10))
([reading_1_m2] of reading_data
(clock 1)
(object [m2])
(value 24))
([reading_1_m3] of reading_data
(clock 1)
(object [m3])
(value 26))
([reading_1_out] of reading_data
(clock 1)
(object [out1])
(value 18))
([reading_2_m1] of reading_data
(clock 2)
(object [m1])
(value 0))
([reading_2_m2] of reading_data
(clock 2)
(object [m2])
(value 0))
([reading_2_m3] of reading_data
(clock 2)
(object [m3])
(value 3))
([reading_2_out] of reading_data
(clock 2)
(object [out1])
(value 3))
([reading_3_m1] of reading_data
(clock 3)
(object [m1])
(value 22))
([reading_3_m2] of reading_data
(clock 3)
(object [m2])
(value 6))
([reading_3_m3] of reading_data
(clock 3)
(object [m3])
(value 8))
([reading_3_out] of reading_data
(clock 3)
(object [out1])
(value 14))
([reading_4_m1] of reading_data
(clock 4)
(object [m1])
(value 4))
([reading_4_m2] of reading_data
(clock 4)
(object [m2])
(value 12))
([reading_4_m3] of reading_data
(clock 4)
(object [m3])
(value 12))
([reading_4_out] of reading_data
(clock 4)
(object [out1])
(value 0))
([reading_5_m1] of reading_data
(clock 5)
(object [m1])
(value 18))
([reading_5_m2] of reading_data
(clock 5)
(object [m2])
(value 16))
([reading_5_m3] of reading_data
(clock 5)
(object [m3])
(value 12))
([reading_5_out] of reading_data
(clock 5)
(object [out1])
(value 12))
([reading_6_m1] of reading_data
(clock 6)
(object [m1])
(value 8))
([reading_6_m2] of reading_data
(clock 6)
(object [m2])
(value 24))
([reading_6_m3] of reading_data
(clock 6)
(object [m3])
(value 17))
([reading_6_out] of reading_data
(clock 6)
(object [out1])
(value 9))
([reading_7_m1] of reading_data
(clock 7)
(object [m1])
(value 2))
([reading_7_m2] of reading_data
(clock 7)
(object [m2])
(value 0))
([reading_7_m3] of reading_data
(clock 7)
(object [m3])
(value 26))
([reading_7_out] of reading_data
(clock 7)
(object [out1])
(value 26))
([reading_8_m1] of reading_data
(clock 8)
(object [m1])
(value 0))
([reading_8_m2] of reading_data
(clock 8)
(object [m2])
(value 0))
([reading_8_m3] of reading_data
(clock 8)
(object [m3])
(value 0))
([reading_8_out] of reading_data
(clock 8)
(object [out1])
(value 0))
([reading_9_m1] of reading_data
(clock 9)
(object [m1])
(value 30))
([reading_9_m2] of reading_data
(clock 9)
(object [m2])
(value 30))
([reading_9_m3] of reading_data
(clock 9)
(object [m3])
(value 12))
([reading_9_out] of reading_data
(clock 9)
(object [out1])
(value 28))
)
)
By using the following assert rules I can get a list of all the facts along with which input or sensor they belong to :
(defrule assert-inputs
(object (is-a command_data) (clock ?clock) (object ?object) (value ?value))
=>
(assert (fact ?clock ?object ?value)))
(defrule assert-outputs
(object (is-a reading_data) (clock ?clock) (object ?object) (value ?value))
=>
(assert (fact ?clock ?object ?value)))
I want to somehow be able to handle all inputs in the facts and be able to see what happens after they pass an adder or a multiplier. I managed to do this for A1 because it takes as input only input1 two times like this :
(defrule check_a1
(fact ?clock ?object ?value)
(test (eq ?object [input_1]))
=>
(assert (fact ?clock [m1t] (mod(+ ?value ?value)(** 2 5)))))
However Π2 multiplier takes as input two different values input3 and input4. By using the following I can manage to print all the facts that are either of input3 or input4. The problem is I don't know how to use them in the same manner as I used them above when they were only one since for every new fact I want to create I have two different values. Is there an easy way to access these values? I tried to bind them to a different variable and access them like nth$ 1 and nth$ 2 but I couldn't make it work.
(defrule check_p2
(fact ?clock ?object ?value)
(test (or (eq ?object [input_3]) (eq ?object [input_4])))
=>
(printout t ?clock " " ?object " " ?value crlf))
If you want to grab two different facts with the same clock value, different values, and objects [input_3] and [input_4], use this rule:
(defrule check_p2
(fact ?clock [input_3] ?value3)
(fact ?clock [input_4] ?value4)
=>
; Your action here
)