Fork me on GitHub
#clara
<
2018-01-06
>
alex-dixon15:01:06

May not have had enough coffee yet but….how do I do something like this without getting an unbound variable error?

[SomeFact (= a ?a) (= b ?b)]
[:not [:and [Fact1 (= e ?e) (= a ?a)]
                   [Fact2 (= e ?e) (= b ?b]]] 

mikerod17:01:47

@alex-dixon I am not sure if @wparker has an issue logged on this subject but odd things can happen sometime in rule compilation due to how Clara compiler converts these Boolean conditions to disjunctive normal form. DNF

mikerod17:01:25

So the conditions in the :and are being split by an :or.

mikerod17:01:06

I need to look a bit though. Thought the case above was covered.

mikerod17:01:32

Basic negated conjunctions should be supported.

alex-dixon17:01:18

By the way is [:not {:exists valid in any way?

alex-dixon17:01:38

@mikerod or is that just equivalent to [:not .. ] ?

mikerod17:01:29

Should mean the same thing.

mikerod17:01:38

Not sure if it works out that way though. Hah

mikerod17:01:42

I’d avoid it.

mikerod17:01:30

Some of the negation transformation stuff probably could be improved. I think Will had thoughts on that. I thought he logged an issue. I want to look at what is compiled in your example about to see why you’d have an inbound variable issue

mikerod17:01:43

I am not on laptop now. Will be in a few.

mikerod17:01:58

(I don’t run Clara repl experiments on my phone unfortunately)

alex-dixon18:01:56

Ok. Started working on spec stuff. Equally stuck there so let me know lol

alex-dixon21:01:55

Was just looking at it hah

mikerod22:01:42

There are severael issues here. The work that was done before only worked in a fairly small set of situations

alex-dixon22:01:42

So that’s identical

mikerod22:01:00

if you can, the workaround is to just move out the conjunction to a different rule I believe

alex-dixon22:01:32

Ok. Let me unwind my attempts that aren’t working and attempt that

mikerod22:01:04

(defrule r1
  
   [Fact1 (= e ?e) (= a ?a)]
   [Fact2 (= e ?e) (= b ?b)]
  =>
  (insert! (->Fact3 ?e ?a ?b)))


(defrule r2
  [SomeFact (= a ?a) (= b ?b)]
  [:not [Fact3 (= a ?a) (= b ?b)]]
  =>
  (prn {:a ?a
        :b ?b
        :e ?e}))

mikerod22:01:16

I believe that is the extraction

mikerod22:01:00

That would pair all Fact1 and Fact2 facts together in the r1 join to make the Fact3 facts

mikerod22:01:23

Then r2 would be looking for the non-existence of any of those join results to match the same a and b of a SomeFact fact

alex-dixon22:01:45

Just to clarify my understanding is the :and necessary in r1?

mikerod22:01:10

I just quickly extracted it and forgot I had the :and there still

mikerod22:01:16

I’d leave it out 😛

mikerod22:01:31

edited to avoid more confusion

alex-dixon22:01:10

Will try asap. Had to take a break

alex-dixon22:01:25

Thanks for your responses

mikerod22:01:05

No problem. That is unfortunate that there are still several caveats to nesting conditions within negation

mikerod22:01:54

A lot of the time it can be solved by just pulling everything complex out of the :not and put it into a different rule where an “bridge”/intermediate fact is used to communicate the logic across the rules

mikerod22:01:55

I read through some of the outstanding issues on negation. However, I thought that I remember Will mentioning that he maybe had a few more broad concerns with the current way of dealing with them

mikerod22:01:16

Basically, the currently process is to extract rules out from within the :not transparently

mikerod22:01:30

In a way that is similar to what I proposed that you do in the above.

mikerod22:01:01

I’m surprised that https://github.com/cerner/clara-rules/issues/347 is still an issue though. I think the fix for it to me seems to be very similar to the work that was done in https://github.com/cerner/clara-rules/pull/342 If so, I think that one would be pretty easy to fix.