0

Prolog Beginner - Is this a bad idea?

 2 years ago
source link: https://www.codesd.com/item/prolog-beginner-is-this-a-bad-idea.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Prolog Beginner - Is this a bad idea?

advertisements

The application I'm working on is a "configurator" of sorts. It's written in C# and I even wrote a rules engine to go with it. The idea is that there are a bunch of propositional logic statements, and the user can make selections. Based on what they've selected, some other items become required or completely unavailable.

The propositional logic statements generally take the following forms:

A => ~X
ABC => ~(X+Y)
A+B => Q
A(~(B+C)) => ~Q A <=> B

The symbols:

=>  -- Implication
<=> -- Material Equivalence
~   -- Not
+   -- Or
Two letters side-by-side -- And

I'm very new to Prolog, but it seems like it might be able to handle all of the "rules processing" for me, allowing me to get out of my current rules engine (it works, but it's not as fast or easy to maintain as I would like).

In addition, all of the available options fall in a hierarchy. For instance:

Outside
   Color
      Red
      Blue
      Green
   Material
      Wood
      Metal

If an item at the second level (feature, such as Color) is implied, then an item at the third level (option, such as Red) must be selected. Similarly if we know that a feature is false, then all of the options under it are also false.

The catch is that every product has it's own set of rules. Is it a reasonable approach to set up a knowledge base containing these operators as predicates, then at runtime start buliding all of the rules for the product?

The way I imagine it might work would be to set up the idea of components, features, and options. Then set up the relationships between then (for instance, if the feature is false, then all of its options are false). At runtime, add the product's specific rules. Then pass all of the user's selections to a function, retrieving as output which items are true and which items are false.

I don't know all the implications of what I'm asking about, as I'm just getting into Prolog, but I'm trying to avoid going down a bad path and wasting lots of time in the process.

Some questions that might help target what I'm trying to find out:

  1. Does this sound do-able?
  2. Am I barking up the wrong tree?
  3. Are there any drawbacks or concerns to trying to create all of these rules at runtime?
  4. Is there a better system for this kind of thing out there that I might be able to squeeze into a C# app (Silverlight, to be exact)?
  5. Are there other competing systems that I should examine?
  6. Do you have any general advice about this sort of thing?

Thanks in advance for your advice!


  1. Sure, but Prolog has a learning curve.
  2. Rule-based inference is Prolog's game, though you may have to rewrite many rules into Horn clauses. A+B => Q is doable (it becomes q :- a. q :- b. or q :- (a;b).) but your other examples must be rewritten, including A => ~X.
  3. Depends on your Prolog compiler, specifically whether it supports indexing for dynamic predicates.
  4. Search around for terms like "forward checking", "inference engine" and "business rules". Various communities keep inventing different terminologies for this problem.
  5. Constraint Handling Rules (CHR) is a logic programming language, implemented as a Prolog extension, that is much closer to rule-based inference/forward chaining/business rules engines. If you want to use it, you'll still have to learn basic Prolog, though.
  6. Keep in mind that Prolog is a programming language, not a silver bullet for logical inference. It cuts some corners of first-order logic to keep things efficiently computable. This is why it only handles Horn clauses: they can be mapped one-to-one with procedures/subroutines.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK