Menu

forall behaviour

Help
vranoch
2015-01-16
2015-01-16
  • vranoch

    vranoch - 2015-01-16

    Hello,

    I wanted to ask about a behaviour of the forall element. When referred facts exist then it works correctly but when they do not exist at all then it evaluates to TRUE. Current behaviour is more like "Does not exist any item NOT MATCHING item" rather then "ALL items match" (the question is wheher the term ALL include also NONE)

    (deffacts x
        (Alert Type "")
        (Alert Vehicle "")
    ;   (Alert Vehicle RegistrationNumbers RegistrationNumber 1 "abcd")
    ;   (Alert Vehicle RegistrationNumbers RegistrationNumber 2 "xyz")
    )
    
    (defrule x_10 ""
        (forall (Alert Vehicle RegistrationNumbers RegistrationNumber ?V99_II10 ?V99_II10_var)
            (test (str-index  "abcd" ?V99_II10_var))
        )
    =>
        (printout t "FORALL" crlf)
    )
    

    Thanks for a clarification.

    Vranoch

     
    • Gary Riley

      Gary Riley - 2015-01-16

      The forall conditional element is simply a translation to other conditional elements. It doesn’t have specialized behavior that you would be unable to implement if it didn’t exist. So when you see patterns of this form:

      (forall <x> <y>)
      

      It's translated to this form:

      (not (and <x>
                (not <y>)))
      

      If there are no matches for pattern <x>, then regardless of matches for pattern <y> the outermost not conditional element is matched.

      I think of the forall wording as "for all occurrences of pattern <x>, pattern <y> is matched." The term all doesn't include existence. For all is basically the same thing as for every. For example:

      if
         claimant's-SSN-provided and
         forall dependents-claimed
                dependent's-SSN-provided
      then
         all-SSNs-provided
      

      If I haven’t claimed any dependents, then the forall is satisfied which is the desired logic. If I haven’t claimed anyone, then I don’t need to supply SSNs for them, so the forall needs to be satisified if there are no dependents-claimed matches.

      If you want logic that requires at least one occurrence of the first pattern in the forall CE, then you need to add this externally to the forall CE:

      (exists <x>)
      (forall <x> <y>)
      

      As a historical note, the semantics and naming of the forall conditional element came from ART, the tool on which the syntax of CLIPS was based.

      Cheers,

      Gary

      On Jan 16, 2015, at 3:16 AM, vranoch vranoch@users.sf.net wrote:

      Hello,

      I wanted to ask about a behaviour of the forall element. When referred facts exist then it works correctly but when they do not exist at all then it evaluates to TRUE. Current behaviour is more like "Does not exist any item NOT MATCHING item" rather then "ALL items match" (the question is wheher the term ALL include also NONE)

      (deffacts x
      (Alert Type "")
      (Alert Vehicle "")
      ; (Alert Vehicle RegistrationNumbers RegistrationNumber 1 "abcd")
      ; (Alert Vehicle RegistrationNumbers RegistrationNumber 2 "xyz")
      )

      (defrule x_10 ""
      (forall (Alert Vehicle RegistrationNumbers RegistrationNumber ?V99_II10 ?V99_II10_var)
      (test (str-index "abcd" ?V99_II10_var))
      )
      =>
      (printout t "FORALL" crlf)
      )
      Thanks for a clarification.

      Vranoch

      forall behaviour https://sourceforge.net/p/clipsrules/discussion/776946/thread/9cde9785/?limit=25#8363
      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/clipsrules/discussion/776946/ https://sourceforge.net/p/clipsrules/discussion/776946
      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/ https://sourceforge.net/auth/subscriptions

       

      Last edit: Gary Riley 2015-01-16

Log in to post a comment.