I met some for me strange behaviour of the FORALL quantifier. Could You check it whether it is my misunderstanding or some issue?
Thanks Vranoch
(deffacts xx
(LVAR Number 1 "123456789011")
(LVAR Number 2 "445124785921") ; this value is different to other ones
(LVAR Number 3 "123456789011")
(LVAR Number 4 "123456789011")
(ITERINDEX IX_1 1)
)
; Rules should fire only if all values are mutually equal - they a ARE NOT, therefore these rules should NOT FIRE
; this rule compares all values to the first one (including itself). It should fire ONLY if all values are equal to the first obne
; This rule MISFIRES
(defrule FORALL_BAD
(forall
(ITERINDEX IX_1 ?IX_1)
(LVAR Number ?IX_1 ?IX_1_var)
(LVAR Number ?IX_2 ?IX_2_var)
(test (eq ?IX_1_var ?IX_2_var))
)
=>
(printout t "FIRED FORALL_BAD" crlf)
)
; This rule compares ALL NON IDENTICAL items
; this rule works correctly
(defrule FORALL_CORRECT
(forall
(LVAR Number ?IX_1 ?IX_1_var)
(LVAR Number ?IX_2 ?IX_2_var)
(test (eq ?IX_1_var ?IX_2_var))
(test (not (eq ?IX_1 ?IX_2)))
)
=>
(printout t "FIRED FORALL_CORRECT" crlf)
)
; this rule searches for ONE VALUE DIFFERENT with others
; this rule works correctly
(defrule NOT_EXISTS ""
(not
(exists
(LVAR Number ?IX_1 ?IX_1_var)
(LVAR Number ?IX_2 ?IX_2_var)
(test (neq ?IX_1_var ?IX_2_var))
(test (not (eq ?IX_1 ?IX_2)))
)
)
=>
(printout t "FIRED NOT_EXISTS" crlf)
)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your logic is not correct in the FORALL_BAD rule. It's satisified when every occurence of ITERINDEX has at least one ocurrence of matching LVARs. What you want is for every occurence of ITERINDEX to have no occurences of mismatched LVARs:
(defrule FORALL_GOOD
(forall
(ITERINDEX IX_1 ?IX_1)
(not (and (LVAR Number ?IX_1 ?IX_1_var)
(LVAR Number ?IX_2 ?IX_2_var)
(test (neq ?IX_1_var ?IX_2_var))))
)
=>
(printout t "FIRED FORALL_GOOD" crlf)
)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The ITERINDEX is just a technical support fact - iteration controll fact. The aim in this case was:
"fire if ALL LVARs have the same value as the one selected by the ITERINDEX".
How should in this case the rule stand? I tried to swap the ITERINDEX and LVAR but now it does not fire even when all values are equal:
(deffacts xx
(LVAR Number 1 "123456789011")
(LVAR Number 2 "123456789011")
; (LVAR Number 2 "445124785921")
(LVAR Number 3 "123456789011")
(LVAR Number 4 "123456789011")
(ITERINDEX IX_1 1)
)
(defrule FORALL_BAD_2
(forall
(LVAR Number ?IX_1 ?IX_1_var)
(ITERINDEX IX_1 ?IX_1)
(LVAR Number ?IX_2 ?IX_2_var)
(test (eq ?IX_1_var ?IX_2_var))
)
=>
(printout t "FIRED FORALL_BAD_2" crlf)
)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The "all" in forall applies to the first conditional element, not the subsequent ones. For example, the rule "for all blacks there is a matching red" would be written as:
The rule you're attempting to write is "for all blacks all of the reds have matching values." In this case, the "all" has been applied to both the first conditional element and the subsequent conditional elements. The question now becomes how to represent "all of the reds have matching values." You use the pattern CE to determine if "some" facts match that pattern and you can wrap the pattern CE with a not CE to determine if no facts match, but there's no conditional element to determine if "all" facts match a pattern. So in order to represent "all of the reds have matching values," it must be converted to the form "none of the reds have mismatched values" which can be represented using the not CE.
So rather than use a forall CE, it would be simpler to represent your rule as:
(defrule FORALL_BAD_2
(ITERINDEX IX_1 ?IX_1)
(not (and (LVAR Number ?IX_1 ?IX_1_var)
(LVAR Number ?IX_2 ?IX_2_var)
(test (neq ?IX_1_var ?IX_2_var))))
=>
(printout t "FIRED FORALL_BAD_2" crlf)
)
For a better understanding of what the forall is doing, remember that it's just inserting the patterns from the conditional element into a template of "and" and "not" conditional elements:
hello and good morning
I am writing to see who helps me with clips settings for reading a dream and this dream some descriptions tell me the lottery numbers. example if the person you have several questions and the select "YES" this returns me all the answers to this.
I'm starting to program and teacher who is teaching my class does not understand is that we work and can not understand well as work.
I would appreciate a little help me please.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Gary,
I met some for me strange behaviour of the FORALL quantifier. Could You check it whether it is my misunderstanding or some issue?
Thanks Vranoch
Your logic is not correct in the FORALL_BAD rule. It's satisified when every occurence of ITERINDEX has at least one ocurrence of matching LVARs. What you want is for every occurence of ITERINDEX to have no occurences of mismatched LVARs:
The ITERINDEX is just a technical support fact - iteration controll fact. The aim in this case was:
"fire if ALL LVARs have the same value as the one selected by the ITERINDEX".
How should in this case the rule stand? I tried to swap the ITERINDEX and LVAR but now it does not fire even when all values are equal:
The "all" in forall applies to the first conditional element, not the subsequent ones. For example, the rule "for all blacks there is a matching red" would be written as:
If you switch the conditional elements the behavior you'll get will be "for all reds there is a matching black":
The rule you're attempting to write is "for all blacks all of the reds have matching values." In this case, the "all" has been applied to both the first conditional element and the subsequent conditional elements. The question now becomes how to represent "all of the reds have matching values." You use the pattern CE to determine if "some" facts match that pattern and you can wrap the pattern CE with a not CE to determine if no facts match, but there's no conditional element to determine if "all" facts match a pattern. So in order to represent "all of the reds have matching values," it must be converted to the form "none of the reds have mismatched values" which can be represented using the not CE.
So rather than use a forall CE, it would be simpler to represent your rule as:
For a better understanding of what the forall is doing, remember that it's just inserting the patterns from the conditional element into a template of "and" and "not" conditional elements:
Thanks for a clarification Gary.
Vranoch
hello and good morning
I am writing to see who helps me with clips settings for reading a dream and this dream some descriptions tell me the lottery numbers. example if the person you have several questions and the select "YES" this returns me all the answers to this.
I'm starting to program and teacher who is teaching my class does not understand is that we work and can not understand well as work.
I would appreciate a little help me please.
If you have specific questions, just open a new topic and post them.