clara

http://www.clara-rules.org/
alex-dixon 2018-01-06T15:44:06.000028Z

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]]] 

2018-01-06T17:06:47.000128Z

@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

2018-01-06T17:07:25.000023Z

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

2018-01-06T17:12:06.000040Z

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

2018-01-06T17:12:32.000005Z

Basic negated conjunctions should be supported.

alex-dixon 2018-01-06T17:14:00.000155Z

Hm ok

alex-dixon 2018-01-06T17:14:18.000059Z

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

alex-dixon 2018-01-06T17:16:38.000134Z

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

2018-01-06T17:22:29.000167Z

Should mean the same thing.

2018-01-06T17:22:38.000063Z

Not sure if it works out that way though. Hah

2018-01-06T17:22:42.000005Z

I’d avoid it.

2018-01-06T17:23:30.000073Z

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

2018-01-06T17:23:43.000023Z

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

2018-01-06T17:23:58.000015Z

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

alex-dixon 2018-01-06T18:37:56.000035Z

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

alex-dixon 2018-01-06T21:59:55.000001Z

Was just looking at it hah

2018-01-06T22:00:42.000027Z

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

alex-dixon 2018-01-06T22:00:42.000099Z

So that’s identical

2018-01-06T22:01:00.000036Z

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

alex-dixon 2018-01-06T22:01:32.000113Z

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

2018-01-06T22:02:04.000021Z

(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}))

2018-01-06T22:02:16.000041Z

I believe that is the extraction

2018-01-06T22:03:00.000053Z

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

2018-01-06T22:03:23.000009Z

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-dixon 2018-01-06T22:04:45.000058Z

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

2018-01-06T22:13:58.000046Z

@alex-dixon no, sorry

2018-01-06T22:14:10.000104Z

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

2018-01-06T22:14:16.000054Z

I’d leave it out 😛

2018-01-06T22:14:31.000059Z

edited to avoid more confusion

👍 1
alex-dixon 2018-01-06T22:15:10.000091Z

Will try asap. Had to take a break

alex-dixon 2018-01-06T22:15:25.000006Z

Thanks for your responses

2018-01-06T22:17:05.000048Z

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

2018-01-06T22:17:54.000053Z

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

2018-01-06T22:18:55.000022Z

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

2018-01-06T22:19:16.000065Z

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

2018-01-06T22:19:30.000063Z

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

2018-01-06T22:21:01.000088Z

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.