Hi Thomas,
To understand my statement below, you have to understand how the Rete
algorithm works, and why its necessary, and how it is implemented. But
the short answer is that if you do the tests on the LHS of rules, only
the minimum number of tests are done. If you do them on the RHS, then
all possible tests will be done. The Rete algorithm, and especially
the enhanced version Jess is using, an greatly reduce the number of
tests that are needed, often by orders of magnitude. This is the
essence of Rete.
Furthermore, the process of 'activating' a rule and firing it requires
some computational expense. Under some circumstances, this can itself
get to be rather high - for instance, when you've got hundreds of
concurrently activated rules. Jess is tuned to perform best when tests
of this sort are done on rule LHSs.
I think Thomas Westergard wrote:
>
> Hi,
>
> I don't understand why 'good' is better than
> 'bad'?
> The only advantage i see is if you know that only
> the first variable (eg A) has a condition.
>
> What if you have a condition for every variable,
> or
> condition for the first and the last (this could
> occur
> if you are writing a lot of rules and you want to
> keep
> the same order among the variables). Then, is it
> still
> more efficient to use the '&:' operator than the
> 'if'?
>
> I could imagine also that when a rule has several
> conditions for a single variable it is - if not
> faster -
> more "handy" to use 'if' when structuring.
>
> What if variables are dependent?
>
> To avoid problems like this, is it not better
> in *general* to use if-statements in RHS?
>
> Last: is there a (forthcoming) book
> on Jess that deals with its later versions?
> Something like an updated version of
> Mark Watson's book Artificial Intelligence for
> Java
> would be interesting. The current release is
> becoming out of date with respect to Jess and
> integration with Java.
>
> ThomasW
> [EMAIL PROTECTED]
>
> %
> % condition not only in the first variables
> %
> (defrule bad
> (A ?a)
> (B ?b)
> (C ?c)
> (D ?d)
> (E ?e)
> =>
> (if (eq ?a nothing) then ...)
> (if (eq ?e nothing) then ...)
> )
> % OR
> (defrule good (A ?a&:(eq ?a nothing)) (B ?b) (C
> ?c) (D ?d) (E ?e&:(eq ?e nothing)) => ...)
> %
> % several conditions for same variable
> %
> (defrule bad
> (A ?a)
> (B ?b)
> (C ?c)
> (D ?d)
> (E ?e)
> =>
> (if (< ?a nothing)
> (> ?a something)
> (<= ?a everything)
> (>= ?a somethingelse)
> (not ?a everythingelse)
> then ...
> )
> )
> % OR
> (defrule good (A ?a&:( (< ?a nothing)
> (> ?a something)
> (<= ?a everything)
> (>= ?a somethingelse)
> (not ?a everythingelse)
> ) ) (B ?b) (C ?c) (D ?d) (E ?e) => ...
> )
> %
> % variables dependent
> %
> (defrule bad
> (A ?a)
> (B ?b)
> (C ?c)
> (D ?d)
> (E ?e)
> =>
> (if (< ?a ?e)
> (> ?a ?d)
> (<= ?a ?c)
> (>= ?a ?b)
> (not ?a 0)
> then ...
> ))
> % OR
> (defrule good (A ?a&:( (< ?a ?e)
> (> ?a ?d)
> (<= ?a ?c)
> (>= ?a ?b)
> (not ?a 0)
> ) ) (B ?b) (C ?c) (D ?d) (E ?e) => ...
> )
>
> --- "Ernest J. Friedman-Hill"
> <[EMAIL PROTECTED]> wrote:
> > It is virtually always better to do all your
> > tests on the LHSs of your
> > rules. For a rule with one one CE, like this
> > one, it doesn't matter
> > much, but for a rule like
> >
> > (defrule good (A ?a&:(eq ?a nothing)) (B
> > ?b) (C ?c) => ...)
> > (defrule bad (A ?a) (B ?b) (C ?c) => (if
> > (eq ?a nothing ) ...)
> >
> > the difference can be huge. Making "good"
> > faster than "bad" is, in fact,
> > the whole point of the Rete algorithm.
> >
> > I think Christo Andonyadis wrote:
> > >
> > > Which is better/faster:
> > >
> > > (something ?s)
> > > =>
> > > (if (eq ?s nothing) then
> > > (assert (somethingelse nothingatall))
> > > )
> > >
> > > OR
> > >
> > > (something ?s&:(eq ?s nothing))
> > > =>
> > > (assert (somethingelse nothingatall))
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, send the words 'unsubscribe
> > jess-users [EMAIL PROTECTED]'
> > > in the BODY of a message to
> > [EMAIL PROTECTED], NOT to the
> > > list. List problems? Notify
> > [EMAIL PROTECTED]
> > >
> >
> ---------------------------------------------------------------------
> > >
> > >
> >
> >
> >
> ---------------------------------------------------------
> > Ernest Friedman-Hill
> > Distributed Systems Research Phone:
> > (925) 294-2154
> > Sandia National Labs FAX:
> > (925) 294-2234
> > Org. 8920, MS 9214
> > [EMAIL PROTECTED]
> > PO Box 969
> > http://herzberg.ca.sandia.gov
> > Livermore, CA 94550
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, send the words 'unsubscribe
> > jess-users [EMAIL PROTECTED]'
> > in the BODY of a message to
> > [EMAIL PROTECTED], NOT to the
> > list. List problems? Notify
> > [EMAIL PROTECTED]
> >
> ---------------------------------------------------------------------
> >
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list. List problems? Notify [EMAIL PROTECTED]
> ---------------------------------------------------------------------
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9214 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------