Logically Backwards and Forwards

I tried to ask Ovid (the author of AI::Prolog) about forward-chaining logic, but I realized that I didn’t really know what I was asking. Let this post serve as a brainstorming session to find that.

A smart game AI would like to be able to make inferences based on what any particular NPC knows. For instance, if I own a house, and it contains a couch, it would be reasonable to assume that I own that couch. That’s easy using backward chaining logic in Prolog:

    owns(X,Y) :- owns(X,Z), contains(Z,Y).

But there’s also the idea that knowledge changes. For instance, I’d like to specify something like (pseudo-syntax):

    owns(me,X) --> !owns(me,X)  { GET MAD! }

That is, if a piece of knowledge enters the database that causes owns(me,X) to go from true to false for a particular X, obviously it has been stolen. I’ll say that the new knowledge invokes a predicate transition. So one way to do this would be, for every transition hook, to poll once every certain while and check whether it has changed. That sucks though. The way it should work is the opposite way from general backward-chaining logic. It much more like dataflow.

Hmm… that defines the problem pretty well. I’m just wondering if that’s the way I want to do it. Is it transitions that I am really interested in? I think it is. If it weren’t, then I suppose I would just query the expression and bind the value out.

So in order to define such a transition, I need to tell owns/2 that when it changes, I need to update and possibly act. Huh, that’s interesting. It seems to be a knowledge base problem more than a combinator problem. The only thing I suppose I’m wondering is if there’s a better way to update knowledge than to re-run the rule.

Well, that defined the problem. How’s that for unstructured prose?


One thought on “Logically Backwards and Forwards

  1. Hey, I was just thinking about this entry and I think I may have figured out the perfect pattern for your problem. The Observer/Observed pattern (see Design Patterns). In an OO language, you would bind me and X when me takes ownership of X (when X is bound in owns(me, X)). Then, when ownership changes, X would notify me of such change in ownership and me could then GET MAD. But, then again, this is an object oriented solution to a logical language problem, so I don’t know how much this helps…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s