Mutually exclusive rules

54 views
Skip to first unread message

Haianos

unread,
Feb 21, 2023, 1:22:32 PM2/21/23
to CLIPSESG
Hi,

My apologies if this question has been answered already, but I could not find any resolution here or in the manual.

Is it possible to define mutually exclusive rules activation?

Let's consider the following example

```
(deftemplate fact1
  (slot attribute
    (type SYMBOL)))

(deftemplate fact2
  (slot attribute
    (type SYMBOL)))
   
(defrule RuleA
  (declare (salience 10))
  (fact1 (attribute A))
  (not (fact2 (attribute A)))
  =>
  (printout t "RuleA executed" crlf)
)

(defrule RuleB
  (declare (salience 9))
  (fact2 (attribute B))
  (not (fact1 (attribute B)))
  (not (RuleA))
  =>
  (printout t "RuleB executed" crlf)
)
```

Here I would expect that `RuleB` is not activated because of the constraint `(not (RuleA))`, however the `agenda` returns

```
10     RuleA: f-1,*
9      RuleB: f-2,*,*
```

I would expect this to work, given the salience priority assigned (so `RuleA` evaluated before `RuleB`).

However, if I change `(not (RuleA))` to `(RuleA)` I obtained the expected result. Why?

Thank you!

CLIPS Support

unread,
Feb 21, 2023, 1:57:26 PM2/21/23
to CLIPSESG
There is no explicit mechanism for making rules mutually exclusive by determining if there is an activation for another rule. When you include (not (RuleA)) in the condition of RuleB, that's not checking for an activation of RuleA, it's checking for the existence of an ordered fact named RuleA.

You could make the rules mutually exclusive by modifying RuleA like this:

(defrule RuleA
  (declare (salience 10))
  (fact1 (attribute A))
  (not (fact2 (attribute A)))
  =>
  (assert (RuleA))

  (printout t "RuleA executed" crlf)
)

Or RuleB like this:

(defrule RuleB
  (declare (salience 9))
  (fact2 (attribute B))
  (not (fact1 (attribute B)))
  (not (and (fact1 (attribute A))
            (not (fact2 (attribute A)))))

  =>
  (printout t "RuleB executed" crlf)
)

Ruben Safir

unread,
Feb 22, 2023, 12:08:01 AM2/22/23
to clip...@googlegroups.com
On 2/21/23 13:57, CLIPS Support wrote:
> Is it possible to define mutually exclusive rules activation?

This question usually indicates that the user doesn't understand either
the power of the rationality of CLIPS. It is not a general programming
language like python.

You can make it do it and even create your own functions, but you miss
the point.

Reassess the problem.
--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

Haianos

unread,
Feb 22, 2023, 1:17:39 AM2/22/23
to CLIPSESG
Thank you for the clear answer! :-)

  • OK, then I can re-use the same symbols for facts and rules, they aren't conflicting -> I wasn't aware of that. Thanks for clarifying
  • The solution is then trivial. I particularly like the first solution, creating a dependency on a fact, if the a rule has been fired already. This suits my use case.
Thanks!

Haianos

unread,
Feb 22, 2023, 1:41:34 AM2/22/23
to CLIPSESG
Hi Ruben,

Thank you for your useless answer, which clearly show that you don't understand the fundamentals of social interactions, and the rationale behind having forums, groups and communities.

Typically I don't answer to such messages, but I do an exception for you.

Yes, my question may be trivial or ill-posed, and yes, I am new to CLIPS. Obviously is not a general purpose language, no-one has never mentioned that. That said, you don't know me (as I don't know you), so please refrain of making any assumption about each other knowledge, which honestly, no body cares.

More on the technical side: using `deffunction` is probably not the first thing I should do here, as my understand is that writing procedural code is not really the point of CLIPS (isn't it?).
Beside, I found this comment a bit conflicting: you first claim CLIPS is not a general purpose language and should not be used as such, and then you point me out `deffunction` to write procedural code (hence more generic)? I am very confused by your answer...

Forum, groups, etc are all means where people make legit questions, and possibly/potentially get answers from more knowledge people. Showing some supposed superiority on understanding something is out-of-scope, as well as using them as a mean to dispose any personal frustrations.

Here a non-exhaustive list of things you could have done instead:
  1. Educate me by answering directly to my problem
  2. Help me to re-assess the problem
  3. Illuminate me with your knowledge to understand the power of the rationale of CLIPS
  4. Point me out any source or material I may have missed to understand my problem
  5. Write yourself some documentation/tutorial to avoid beginners like me to pose those questions
  6. Absolutely nothing, and ignore my answer.
You still have a chance to redeem yourself, staying in-topic with action point 3, 4 and 5, given that luckily you do not represent CLIPS community and my question got answered very clearly and politely (option 1).

Alternatively, option 6 (doing nothing) is still there for you. Take a walk, it is beautiful out there! :-)

denis.be...@gmail.com

unread,
Feb 22, 2023, 2:08:46 AM2/22/23
to CLIPSESG
Just a side remark about CLIPS being a general-purpose language. 

First, let it be clear that, in the most abstract (and probably useless) sense, CLIPS is general purpose: it has the full power of a Universal Turing Machine.

Now, on the practical side of things.
As the developer of a very large system in CLIPS (https://github.com/denis-berthier/CSP-Rules-V2.1), I have faced a few limitations.
CLIPS misses a lot of things to be general purpose in the commonly understood sense in programming. I'll name only three that I have found very boring to circumvent (other users will probably have different ones):
- the lack of fundamental data structures (e.g. binary vectors, matrices...) and functions to deal with them;
- as a functional language, the lack of real lists: all the lists in CLIPS are "flat";
- as an inference engine, the lack of integrated functions for managing independent Rete networks, which would somehow allow to use it as a multi-agent system (this is available only via writing C code and interfaces).

However, I don't want to leave a bad impression of CLIPS: it is a wonderful tool, if you make the effort to learn to use it properly (and only in the proper cases: there are projects that would be better coded in conventional languages).



Haianos

unread,
Feb 22, 2023, 4:29:30 AM2/22/23
to CLIPSESG
Thanks Denis for sharing. Probably OT of this thread (question resolved after all!), but I am interested to follow-up on you last comment


> it is a wonderful tool, if you make the effort to learn to use it properly (and only in the proper cases: there are projects that would be better coded in conventional languages).

Beside the joy of learning, I am still unsure CLIPS is the right tool for my project. I would say so, intuitively, but I may be wrong. Given your experience, have you elaborated some general criteria to determine whether use CLIPS and when going for a conventional/procedural approach?
In my specific case, I would have to embed CLIPS into my application anyway, and somehow some complexity that CLIPS may resolve comes with the cost of building up the interfaces.
Any comment/suggestion is welcome! :-)

denis.be...@gmail.com

unread,
Feb 22, 2023, 6:48:00 AM2/22/23
to CLIPSESG
I'm aware this was OT, but the topic was evoked in a previous post.
It's always difficult to formulate general criteria in CS. Concerning CLIPS (and inference engines in general), I'd tend to say: don't use it if you can do easily without it.
The main feature of an inference engine is its pattern matching ability.To give you a concrete example, I've just generated (with a rule generator I've written in the functional part of CLIPS) about 1200 additional CLIPS rules to my software, each of which has between 30 and 45 conditions (a really very large and unusual number, but all the conditions are similar). Due to the systematic way the rules are generated, there's almost no sharing of conditions between rules (contrary to  what would probably happen if I had written them manually). I feared this would crush CLIPS; but no. Response time remains perfectly normal (it's measured in seconds, not minutes). My purpose in mentioning this is to show how efficient the pattern matcher is. If your rules-to-be have very complex conditions, don't worry about CLIPS being able to deal with them (which doesn't prevent you from decomposing them into simpler ones it it can be done).

If your application involves only relatively simple decision trees, but a lot of procedural code, I wouldn't recommend using an inference engine. Now, it may be the case that only part of your application could really benefit from using an inference engine. Then you will have to face the problem of interfacing, for which I have no experience with CLIPS - but I remember some very old experience between C/Fortran and Common Lips and I'd prefer to swim across the Channel in winter than do it again. (just joking: that was doable, but terribly boring).

Haianos

unread,
Feb 22, 2023, 7:38:00 AM2/22/23
to CLIPSESG
On Wednesday, 22 February 2023 at 12:48:00 UTC+1 denis.be...@gmail.com wrote:
I'm aware this was OT, but the topic was evoked in a previous post.
Yes, sure, no worries! :-)
 
It's always difficult to formulate general criteria in CS. Concerning CLIPS (and inference engines in general), I'd tend to say: don't use it if you can do easily without it.
Yes, I am aware it is a very generic question. but collecting other devs opinion may help me to resume my thoughts. Thank you!
 
The main feature of an inference engine is its pattern matching ability.To give you a concrete example, I've just generated (with a rule generator I've written in the functional part of CLIPS) about 1200 additional CLIPS rules to my software, each of which has between 30 and 45 conditions (a really very large and unusual number, but all the conditions are similar). Due to the systematic way the rules are generated, there's almost no sharing of conditions between rules (contrary to  what would probably happen if I had written them manually). I feared this would crush CLIPS; but no. Response time remains perfectly normal (it's measured in seconds, not minutes). My purpose in mentioning this is to show how efficient the pattern matcher is. If your rules-to-be have very complex conditions, don't worry about CLIPS being able to deal with them (which doesn't prevent you from decomposing them into simpler ones it it can be done).
This sounds very impressive.
 
So, to resume: in your project (CSP-Rules), CLIPS rules are actually generated, hence you generate code into the CLIPS language, or at least partially, right?
Generating the rule definitions from another DSL/specification is something I've considered as well.


If your application involves only relatively simple decision trees, but a lot of procedural code, I wouldn't recommend using an inference engine. Now, it may be the case that only part of your application could really benefit from using an inference engine. Then you will have to face the problem of interfacing, for which I have no experience with CLIPS - but I remember some very old experience between C/Fortran and Common Lips and I'd prefer to swim across the Channel in winter than do it again. (just joking: that was doable, but terribly boring).
Haha well, some people still love swimming in winter :-)

Interfacing can be quite some work, but I am not too worried about it. I personally enjoy that part, and I can delegate to other devs as well. Ofc make sense if the benefits are enough wrt doing everything procedural.
In my specific case:
- pattern matching would be an ideal solution;
- in my application the rules won't be fixed, but it is the user (or another developer) that defines them, so it changes case by case. Hard to say how many rules we may have beforehand, but probably < 250.
- another option would to be develop some basic tools to allow the developer to add rules, or he/she would have to implement everything each time from scratch.
- so it could be convenient to have a common language for that, where modules are defined (or a set of rules generated by some common patterns/templates).
- the "logic" would be separated from the rest, probably easier to test in isolation.
- I could re-use this work in other contexts.

The above kind of summarizes my reasoning towards CLIPS. As an alternative I could develop some utilities ad-hoc, as long as the decision tree is small enough to don't hit any performance issue.
I bet it is hard to say without having more details on my specific project, however if anything of the above does not technically sound, feel free to shoot! :-)
Maybe there are some people out there having faced this thoughts already...

Ruben Safir

unread,
Feb 22, 2023, 8:21:08 AM2/22/23
to clip...@googlegroups.com
On 2/22/23 01:41, Haianos wrote:
>
> Thank you for your useless answer, which clearly show that you don't
> understand the fundamentals of social interactions, and the rationale
> behind having forums, groups and communities.


Fuck off

Ruben Safir

unread,
Feb 22, 2023, 8:23:29 AM2/22/23
to clip...@googlegroups.com
On 2/22/23 01:41, Haianos wrote:
> Educate me by answering directly to my problem


Try reading the docs first
https://www.clipsrules.net/Documentation.html

I gave you the right answe the first time, and your being an ignrant jerk.

If you even too 10 minutes to read the ducmentation and do the tutorial
you would be a lot less clueless, not to mention rude.

Ruben Safir

unread,
Feb 22, 2023, 8:24:26 AM2/22/23
to clip...@googlegroups.com
On 2/22/23 04:29, Haianos wrote:
> Beside the joy of learning, I am still unsure CLIPS is the right tool
> for my project.


But you are sure that yoou can be insulting

Ruben Safir

unread,
Feb 22, 2023, 8:31:49 AM2/22/23
to clip...@googlegroups.com
On 2/22/23 01:41, Haianos wrote:
> Hi Ruben,
>
> Thank you for your useless answer,


On the internet, nobody knows your a dog. Your being a closed minded
punk. I recommend reform.

CLIPS is designed to think about problems in a different way. Just put
down your keyboard and try the documentation and tutorials.

http://www.nylxs.com/classes/

Textbook: Artificial Intelligence – Structures and Strategies for
Complex Problem
Solving, Sixth Edition, George F. Luger, ISBN-13:978-0-321-54589-3, Addision
Wesley, 2009.

and it will be using CLIPS

CLIPS

CLIPS TUTORIAL
Notes on AI from Kent State
MIT Program on AI

http://www.cs.kent.edu/~mscherge/AI/CLIPS/AI_CLIPS_Tutorial.ppt
http://www.cs.kent.edu/~mscherge/AI/index.html
https://ocw.mit.edu/courses/6-034-artificial-intelligence-fall-2010/

denis.be...@gmail.com

unread,
Feb 22, 2023, 12:11:58 PM2/22/23
to CLIPSESG
H: So, to resume: in your project (CSP-Rules), CLIPS rules are actually generated, hence you generate code into the CLIPS language, or at least partially, right?

Generating the rule definitions from another DSL/specification is something I've considered as well.
DB: for the most part, the rules I use come by families; each family has a single generator. But now, I somehow regret to have spoken of this. As a beginner in CLIPS, this is absolutely not what you should consider now.

H:  in my application the rules won't be fixed, but it is the user (or another developer) that defines them, so it changes case by case. Hard to say how many rules we may have beforehand, but probably < 250.
DB: I don't understand. If the rules are not fixed, what remains in the application? Don't expect "the user" to write CLIPS rules himself. This is propaganda of AI sellers of the 70s. No "user" will want to learn CLIPS syntax.

The only general recommendation I can make has nothing original: try to write a few rules that do something that can easily be tested*. Increase your application progressively.
Depending on more or less modularity, testing a rule base is often very different from testing procedural software. As in "normal" software, try to be as much modular as possible, but this is not always possible.

(*)When you write a rule, you can test each condition one after the other, by pasting the beginning of the rule into CLIPS and typing =>) to end it. Simple as it is, it's very convenient for a beginner to find syntax errors.

Ruben Safir

unread,
Feb 23, 2023, 10:33:57 AM2/23/23
to clip...@googlegroups.com
On 2/22/23 01:41, Haianos wrote:
> Here a non-exhaustive list of things you could have done instead:
>
> 1. Educate me by answering directly to my problem

I charge education - $800/Hour

> 2. Help me to re-assess the problem

I did but b=you don't listen

> 3. Illuminate me with your knowledge to understand the power of the
> rationale of CLIPS

I did and it is all in the tuorials


> 4. Point me out any source or material I may have missed to understand
> my problem

Umm - did you READ the tuorials


> 5. Write yourself some documentation/tutorial to avoid beginners like
> me to pose those questions

I don't HAVE to - I write for the NYLXS Journal, BUT - it is already
done for you by someone else and you IGNRED and then came here with your
lack of elbow work.

> 6. Absolutely nothing, and ignore my answer.


I probably should be I am compussive at times and find it educational to
notate how ignorant and purposefully obstructive this generation has
become since they are raised on smart phones.

Get off your phone and do a little work first and take my advice as I
wrote it...

YOUR APPORACH to the problem needs to be rethought. You don't need
coding examples. You need a smack on the nose and to go back and do the
tutorials and become engrossed with the coding philospophy that drives
CLIPS.
Reply all
Reply to author
Forward
0 new messages