Algorithm Search⌘K

Modelintro

Production system

Also called production rule system, rule-based system.

A working memory of facts and a set of if-then rules, run by a cycle that matches rules, selects one and fires its actions.

A production system is a model of computation with three parts: a working memory of facts, a production memory of condition-action rules, and an interpreter that runs the recognize-act cycle. In each cycle the interpreter finds every rule instance whose conditions hold in the working memory, picks one of them by a conflict resolution strategy, and runs its actions, which add facts to the memory or remove facts from it. Newell and Simon used the model for human problem solving, and languages such as OPS5 and CLIPS made it a way to program expert systems. The model is Turing complete. Its monotone fragment, with additions only, is Datalog run by forward chaining.

The machine

A working memory element (WME) is a ground fact, such as (counter value 0)(\mathit{counter}\ \mathit{value}\ 0), with a time tag that tells when it entered the memory. A production has the form

r: c1,…,ck,¬d1,…,¬dl⇒a1,…,apr:\ c_1, \ldots, c_k, \neg d_1, \ldots, \neg d_l \Rightarrow a_1, \ldots, a_p

where the conditions cic_i and djd_j are patterns with variables, and each action aqa_q is make (add a WME), remove (delete the WME that matched a condition), modify (remove and make again with a new time tag), write or halt. An instantiation of rr is a pair of rr and a substitution σ\sigma of constants for the variables such that each ciσc_i \sigma matches a WME, each test on the variables holds, and no djσd_j \sigma matches a WME. The set of all instantiations is the conflict set. The interpreter runs this cycle:

  1. Match. Compute the conflict set for the current working memory.
  2. Select. If the conflict set is empty, stop. Otherwise choose one instantiation by the conflict resolution strategy. Refraction removes the instantiations that have already fired on the same WMEs.
  3. Act. Run the actions of the chosen instantiation in order. Stop on halt; else go to step 1.

A configuration is the working memory with its time tags and the record of fired instantiations. The strategy makes the machine deterministic; without one, the machine is nondeterministic and each choice gives a different run.

For example, take the WMEs 1: (goal count 2)(\mathit{goal}\ \mathit{count}\ 2) and 2: (counter value 0)(\mathit{counter}\ \mathit{value}\ 0), and two rules: step says that if (goal count N)(\mathit{goal}\ \mathit{count}\ N) and (counter value V)(\mathit{counter}\ \mathit{value}\ V) with V<NV < N, then modify the counter to V+1V + 1; stop says that if (goal count N)(\mathit{goal}\ \mathit{count}\ N) and (counter value N)(\mathit{counter}\ \mathit{value}\ N), then write "done" and halt.

cycle conflict set fired working memory after
1 step on 1 and 2 step 1, and 3: (counter value 1)(\mathit{counter}\ \mathit{value}\ 1)
2 step on 1 and 3 step 1, and 4: (counter value 2)(\mathit{counter}\ \mathit{value}\ 2)
3 stop on 1 and 4 stop halt

The modify action gives the counter a new time tag in each cycle, so refraction does not block step from firing again on the new WME.

The logic of the monotone fragment. When the rules have no negated conditions and their only action is make, a rule rr reads as the Horn rule h←b1,…,bkh \leftarrow b_1, \ldots, b_k for each fact hh that it makes. Then a WME stays in the memory once it is there, every run ends with the same memory, and that memory is the least model of the rules and the initial facts. With remove and with negated conditions, a rule such as h←b1,…,bk,not c1h \leftarrow b_1, \ldots, b_k, \mathit{not}\ c_1 no longer has a meaning on its own: the result depends on the order of firing, so the strategy is part of the program.

What it counts

The cost of a run has two parts. The first is the number of cycles, one for each firing. The second is the work of the match step in each cycle: the instantiations, and the partial matches of the conditions of each rule, that the interpreter finds and stores. The Rete and TREAT algorithms keep match state from one cycle to the next, so that a cycle costs time in proportion to the change in the memory and not to its size. Forgy and later authors reported, from measurements on OPS-style programs, that the match step takes most of the running time; this is an observation about programs, not a theorem.

For complexity, the input is the rule set and the working memory. The data complexity fixes the rules and lets the memory of nn WMEs grow; the combined complexity lets both grow. A rule with mm positive conditions has at most nmn^m instantiations, so for fixed rules the match step is polynomial.

Relation to other models

  • Post canonical systems rewrite strings by productions, and every applicable production may be used. A production system with no strategy is a nondeterministic rewriting system of this kind on sets of facts.
  • Markov algorithms are ordered string-rewriting rules, where the first rule that applies fires. This is a production system whose strategy is a fixed priority on rules.
  • Turing machines and production systems simulate each other with one cycle for each step (see below).
  • Datalog and Horn clauses. The monotone fragment is Datalog evaluated by forward chaining. Backward chaining runs the same rules from the goal.
  • STRIPS. A STRIPS operator, with preconditions, an add list and a delete list, is a production without negated conditions. A planner searches over the possible orders of firing; a production system commits to the choice of its strategy and does not go back.
  • Truth maintenance. A truth maintenance system keeps the reasons for the facts that the rules made, so that a fact can go away when its reasons do.

Known results in the model

Turing completeness. A production system with make, remove and a way to create new symbols, such as the genatom function of OPS5, can simulate a deterministic Turing machine. Represent each tape cell by a WME (cell c s l r)(\mathit{cell}\ c\ s\ l\ r) with its identifier cc, its symbol ss and the identifiers ll and rr of its neighbours, and the head by (head c q)(\mathit{head}\ c\ q). For each transition (q,s)→(q′,s′,R)(q, s) \to (q', s', \mathrm{R}), one rule matches the head and its cell, writes s′s' and moves the head to the right neighbour; a second rule with a negated condition handles the case where the right neighbour does not yet exist, and makes a new blank cell with a new identifier. Moves to the left are the same. At each moment at most one rule instance applies, so the strategy plays no part, and each step of the machine is one cycle. So whether a production system halts is undecidable.

Finite systems. If the actions cannot create new values, as with no new symbols and no arithmetic, every WME is one of finitely many ground facts. Then there are finitely many configurations, and whether a run halts is decidable.

Order independence of the monotone fragment. With make as the only action and no negated conditions, every fair run reaches the same final memory, the least model, after at most as many firings as there are ground facts. The forward chaining page proves this. The result fails as soon as either feature is added. With the memory {a}\{a\} and the rules a⇒make ba \Rightarrow \mathit{make}\ b and a,¬b⇒make ca, \neg b \Rightarrow \mathit{make}\ c, firing the first rule first ends with {a,b}\{a, b\}, and firing the second rule first ends with {a,b,c}\{a, b, c\}.

The match problem. Deciding whether one rule without negated conditions has an instantiation is the evaluation of a conjunctive query over the working memory. In combined complexity it is NP-complete (Chandra and Merlin 1977); the clique problem reduces to it, since a graph without loops, stored as edge WMEs in both directions, has a clique of size kk exactly when the rule with the conditions (edge xi xj)(\mathit{edge}\ x_i\ x_j) for all i<j≤ki < j \le k has an instantiation. In data complexity it takes O(nm)O(n^m) time for a rule with mm conditions.

The monotone fragment as Datalog. Computing the final memory of a monotone system is P-complete in data complexity and EXPTIME-complete in combined complexity, the known results for Datalog (Dantsin, Eiter, Gottlob and Voronkov 2001).

References

  1. Allen Newell and Herbert A. Simon, Human Problem Solving, Prentice-Hall (1972), the production system models of problem solving behaviour
  2. Emil L. Post, Formal reductions of the general combinatorial decision problem, American Journal of Mathematics 65(2), 197 to 215 (1943), productions on strings and the normal form theorem
  3. Charles L. Forgy, OPS5 user's manual, technical report CMU-CS-81-135, Carnegie Mellon University (1981), working memory elements and time tags, the recognize-act cycle, the actions, and the conflict resolution strategies
  4. Lee Brownston, Robert Farrell, Elaine Kant and Nancy Martin, Programming Expert Systems in OPS5, Addison-Wesley (1985), the description of the OPS5 language and its recognize-act cycle
  5. Charles L. Forgy, Rete: a fast algorithm for the many pattern/many object pattern match problem, Artificial Intelligence 19(1), 17 to 37 (1982), the match problem of production systems and the cost of the match step
  6. Ashok K. Chandra and Philip M. Merlin, Optimal implementation of conjunctive queries in relational data bases, Proceedings of the Ninth Annual ACM Symposium on Theory of Computing, 77 to 90 (1977), the NP-completeness of answering conjunctive queries
  7. Evgeny Dantsin, Thomas Eiter, Georg Gottlob and Andrei Voronkov, Complexity and expressive power of logic programming, ACM Computing Surveys 33(3), 374 to 425 (2001), the data and combined complexity of Datalog

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/W79EPH/text.yaml