Fork me on GitHub
#clara
<
2016-02-18
>
devn20:02:39

Heya @ryanbrush -- dumb question for you

devn20:02:22

Say I create a session, and insert 3 (->Temperature 100 "ABC") facts, and then retract (->Temperature 100 "ABC") once on that session

devn20:02:04

Should there be 0 (->Temperature 100 "ABC") facts?

wparker20:02:35

Are these top-level insert calls i.e. (clara.rules/insert session fact) or logical insertions and retractions? @devn

devn20:02:49

top-level

wparker21:02:10

A quick trial suggests that top-level retracts one at a time

wparker21:02:39

Logical retractions of equal facts from the same production currently have a truth maintenance bug; see https://github.com/rbrush/clara-rules/issues/171

devn21:02:40

session (-> (mk-session [grouping-query
                                 grouping-convert-query])
                    (insert-all [(->Temperature 30 "MCI")
                                 (->Temperature 10 "MCI")
                                 (->Temperature 80 "MCI")
                                 (->Temperature 80 "MCI")]))

        retracted-session (-> session
                              (retract (->Temperature 80 "MCI")
                                       (->Temperature 80 "MCI")))

devn21:02:07

@wparker: oof, good catch.

devn21:02:47

@wparker: I guess my question is, after running the same trial myself is: should it?

wparker21:02:13

I’d expect that to have temperatures of 30 and 10

wparker21:02:17

Does it not?

devn21:02:27

It does.

wparker21:02:57

So you insert 2 temperatures of 80 and then retract 2 of them; I’d expect there to be none left

devn21:02:07

I guess I halfway expected that, for instance, some deeper identity of a fact beyond just its equality with a corresponding fact in the session would have some bearing.

devn21:02:48

So if I bound (->Temperature 80 "MCI") to high-temp, and then used high-temp twice in the insert-all

devn21:02:38

When I do a (retract session high-termp), it would actually retract both facts

devn21:02:39

I was surprised, but I guess after thinking about it, it doesn't really matter which of the facts is retracted.

wparker21:02:42

Oh, I think I see

wparker21:02:03

Yeah, at least for now I think the memory just uses equality and retracts one each time

wparker21:02:26

The key bit of code is the remove-first-of-each calls in the memory

devn21:02:48

I was thinking that you know, under the covers, an instance of (-> Foo 1) would have an object ID or something taken into account underneath

devn21:02:58

but it makes sense that it doesn't

wparker21:02:22

Yes, it just uses Clojure equality

devn21:02:32

So, @wparker here's one more question for you simple_smile

devn21:02:10

Is this actually a good test of truth maintenance in action for a grouping accumulator?

devn21:02:27

Or is it merely testing that top-level retract does what it's supposed to?

devn21:02:45

@wparker: reading through the issue you filed, and thinking "boy, generative tests in this case would make a lot of sense."

wparker21:02:08

I’m not super familiar with how accumulators work in the engine, but one thing to keep in mind there is that reduce-to-accum creates a retraction function

wparker21:02:06

Regarding generative tests: that could be helpful, but I haven’t come up with any good ideas on how to make them (I haven’t thought about it that deeply though).

ryanbrush22:02:18

@wparker @devn A good suite of generative tests would be great, and may have found a number of issues in logical edge cases. This would require generating rules with different criteria and ensuring consistency to really do well, and how to do so doesn't seem obvious. But I like the thought if anyone wants to play with it.

ryanbrush22:02:06

As for retraction, Clara used Clojure equality semantics by design. This seems like the least surprising behavior to treat facts as values....just like the number 1 is 1 no matter what its "identity". Seems like the Clojure way to me, and is analogous to removing an item from a map or set.