W3C home > Mailing lists > Public > public-rif-wg@w3.org > January 2010

[PRD] Refraction and Modify examples

From: Christian De Sainte Marie <csma@fr.ibm.com>
Date: Tue, 26 Jan 2010 16:47:23 +0100
To: RIF <public-rif-wg@w3.org>
Message-ID: <OF547C4C89.A3282612-ONC12576B6.0065EB19-C12576B7.0056BDA7@fr.ibm.com>

Here are a couple examples that might be helpful when discussing my 
proposal wrt the amendment of refraction (and conflict resolution) and 
Modify in PRD.

NB: I did not run those exact examples, and I lost the ones I ran on CLIPS 
and JRules. Hence the "should" and "should not" loop. My only knowledge of 
Jess being from the user's manual, the "should" and "should not"s, here, 
are just to say that this is according to my understanding of from said 

Modify (is it atomic?):

Rule 1: Forall ?X, if ?X[_att -> _bar] then Modify( ?X[_att -> bar] )

Facts: _foo[_att -> _bar]

Translated in JRules using a Foo class and a Modify action, this should 
not loop, except if "refresh" is specified.

In CLIPS, it should loop. As I understand the working of Jess (from the 
user's manual), it should loop in Jess as well, except if the rule is set 
to no-loop. If this is correct, it shows that the Modify is not atomic in 
Jess (it is certainly not in CLIPS, and it is certainly in JRules).

Rule 2: Forall ?x, if ?X[_att-1 -> _bar] then Modify( ?X[_att-2 -> 

Facts: _foo[_att-1 -> _bar _att-2 -> _whatever]

In Jess, that should loop, unless the _foo template is declared 
slot-specific. I did not check that with CLIPS yet; neither did I with 
JRules and "refresh". But, again, if this is how Jess behaves, that proves 
even more that Modify is not an atomic action (in Jess, I mean).

Modify again (can we find a way to get the current PRD spec to work for 
Jess and JRules at the same time?):

Rule Modify_loop:
Forall ?x ?y
If ?x[_count -> ?y] And ?y > 0 Then Modify( ?x[ _count -> (?y - 1)] )

Rule Modify_noloop:
Forall ?x
If Exists ?y (?x[_count -> ?y] And ?y > 0)
Then Do((?y ?x[_count -> ?y]) Modify( ?x[ _count -> (?y - 1)] ))

Without using an "exists", the two rules above translate into CLIPS, 
JRules and Jess as the same rule, which looks like (here, in JRules):
rule modify_noloop{
when{ ?X:foo.Foo(?C:count;?C>0); }
then { modify ?X{count = ?C-1;} }
Which does not loop in JRules, but does loop in CLIPS, and which should 
loop in Jess, unless it is declared as a "no-loop".

To produce the modify_loop behavior, instead, JRules has to change the RHS 
modify refresh ?X{count = ?C-1;}
but, the, it loops if the RHS is
modify refresh ?X{count = ?C;}
as well, which contradicts the spec (since none of the variable bindings 
changed, it should not loop).

I think that we can find such cases, as well, where a RIF-Jess translator 
could not decide whether a rule should be declared "no-loop" only by 
looking at which variables are universally quantified and which are used 
in a Modify.

Refraction (does including the existentially quantified variables help?):

One easy case is:

Rule 3
If Exists ?x P(?x)
Then Print("Hello, World!")

Facts: P(a), P(b), P(c)

I assume that our engines all agree that rule 3 does not loop given the 
facts: if the bindings of the existential variables were taken into 
account in the PRD specification for refraction, Hello World! would be 
printed thrice.

A more interesting case, that aims at finding out whether existentials are 
dealt with specially as regards refraction

Facts: P(1)

Rule Exists-v1
If Exists ?x  P(?x)
Then Do( Retract( P(1) ) Assert( P(2) ) )

Rule Exists-v2
If Exists ?x P(?x)
Then Do( Assert( P(2) ) Retract( P(1) ))

In CLIPS, the first rule, Exists-v1, runs twice (with an error the second 
time, because of the attempt to retract the not exists fact P(1)), and the 
second rule, Exists-v2 runs only once. That is, CLIPS refracts the rule as 
long as the existence test remains satisfied, even if by another fact, 
provided that there is no intermediate state where no facts satisfies the 
existential. I tested JRules with another, more realistic example, that 
shows that JRules does the same. What about Jess?

Atomic actions (Does refraction and recency take intermediate states of 
the fact base after each atomic action into account or is it enough to 
take the effect of the action block, only, into account, as does PRD?)
In addition to the above examples that would all show that atomic effects 
must be taken into account for refraction, if they behave as expected, 
here is an example that purports to test the impact on conflict resolution 

Rule r1: If P(1) then Print("R1 fired")

Rule r2: if P(2) then Print("R2 fired")

Rule test-1: if foo() then Do( Assert( P(1) ) Assert( P(2) ))

Rule test-2: if foo() then Do( Assert( P(2) ) Assert( P(1) ))

Facts: foo()

Does the ruleset {r1, r2, test-1} fire R2 first and r1 second and does the 
ruleset {r1, r2, test-2} do the reverse? CLIPS does, I expect Jess and 
JRules to, as well.



9 rue de Verdun
94253 - Gentilly cedex - FRANCE
Tel. +33 1 49 08 35 00
Fax +33 1 49 08 35 10

Sauf indication contraire ci-dessus:/ Unless stated otherwise above:
Compagnie IBM France
Siege Social : 17 avenue de l'Europe, 92275 Bois-Colombes Cedex
RCS Nanterre 552 118 465
Forme Sociale : S.A.S.
Capital Social : 611.451.766,20 ?
SIREN/SIRET : 552 118 465 03644
Received on Tuesday, 26 January 2010 15:48:01 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:47:57 UTC