In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, a rule-based system is a computer system in which domain-specific
knowledge
Knowledge is an Declarative knowledge, awareness of facts, a Knowledge by acquaintance, familiarity with individuals and situations, or a Procedural knowledge, practical skill. Knowledge of facts, also called propositional knowledge, is oft ...
is represented in the form of rules and general-purpose
reasoning
Reason is the capacity of consciously applying logic by drawing valid conclusions from new or existing information, with the aim of seeking the truth. It is associated with such characteristically human activities as philosophy, religion, scien ...
is used to solve problems in the domain.
Two different kinds of rule-based systems emerged within the field of
artificial intelligence
Artificial intelligence (AI) is the capability of computer, computational systems to perform tasks typically associated with human intelligence, such as learning, reasoning, problem-solving, perception, and decision-making. It is a field of re ...
in the 1970s:
*
Production systems, which use ''if-then rules'' to derive ''actions'' from ''conditions''.
*
Logic programming
Logic programming is a programming, database and knowledge representation paradigm based on formal logic. A logic program is a set of sentences in logical form, representing knowledge about some problem domain. Computation is performed by applyin ...
systems, which use ''conclusion if conditions rules'' to derive ''conclusions'' from ''conditions''.
The differences and relationships between these two kinds of rule-based system has been a major source of misunderstanding and confusion.
Both kinds of rule-based systems use either
forward or
backward chaining, in contrast with
imperative programs, which execute commands listed sequentially. However, logic programming systems have a logical interpretation, whereas production systems do not.
Production system rules
A classic example of a production rule-based system is the domain-specific
expert system
In artificial intelligence (AI), an expert system is a computer system emulating the decision-making ability of a human expert.
Expert systems are designed to solve complex problems by reasoning through bodies of knowledge, represented mainly as ...
that uses rules to make deductions or choices.
For example, an expert system might help a doctor choose the correct diagnosis based on a cluster of symptoms, or select tactical moves to play a game.
Rule-based systems can be used to perform
lexical analysis
Lexical tokenization is conversion of a text into (semantically or syntactically) meaningful ''lexical tokens'' belonging to categories defined by a "lexer" program. In case of a natural language, those categories include nouns, verbs, adjectives ...
to
compile or
interpret computer programs, or in
natural language processing
Natural language processing (NLP) is a subfield of computer science and especially artificial intelligence. It is primarily concerned with providing computers with the ability to process data encoded in natural language and is thus closely related ...
.
Rule-based programming attempts to derive execution instructions from a starting set of data and rules. This is a more indirect method than that employed by an
imperative programming language, which lists execution steps sequentially.
Construction
A typical rule-based system has four basic components:
* A list of rules or rule base, which is a specific type of
knowledge base
In computer science, a knowledge base (KB) is a set of sentences, each sentence given in a knowledge representation language, with interfaces to tell new sentences and to ask questions about what is known, where either of these interfaces migh ...
.
* An
inference engine or
semantic reasoner, which infers information or takes action based on the interaction of input and the rule base. The interpreter executes a
production system program by performing the following match-resolve-act cycle:
:* Match: In this first phase, the condition sides of all productions are matched against the contents of working memory. As a result a set (the ''conflict set'') is obtained, which consists of instantiations of all satisfied productions. An instantiation of a production is an ordered list of working memory elements that satisfies the condition side of the production.
:*
Conflict-resolution: In this second phase, one of the production instantiations in the conflict set is chosen for execution. If no productions are satisfied, the interpreter halts.
:* Act: In this third phase, the actions of the production selected in the conflict-resolution phase are executed. These actions may change the contents of working memory. At the end of this phase, execution returns to the first phase.
* Temporary
working memory
Working memory is a cognitive system with a limited capacity that can Memory, hold information temporarily. It is important for reasoning and the guidance of decision-making and behavior. Working memory is often used synonymously with short-term m ...
, which is a database of facts.
* A
user interface
In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine fro ...
or other connection to the outside world through which input and output signals are received and sent.
Whereas the matching phase of the inference engine has a logical interpretation, the conflict resolution and action phases do not. Instead, "their semantics is usually described as a series of applications of various state-changing operators, which often gets quite involved (depending on the choices made in deciding which ECA rules fire, when, and so forth), and they can hardly be regarded as declarative".
Logic programming rules
The logic programming family of computer systems includes the programming language
Prolog
Prolog is a logic programming language that has its origins in artificial intelligence, automated theorem proving, and computational linguistics.
Prolog has its roots in first-order logic, a formal logic. Unlike many other programming language ...
, the database language
Datalog and the knowledge representation and problem-solving language
Answer Set Programming (ASP). In all of these languages, rules are written in the form of ''
clauses
In language, a clause is a Constituent (linguistics), constituent or Phrase (grammar), phrase that comprises a semantic predicand (expressed or not) and a semantic Predicate (grammar), predicate. A typical clause consists of a subject (grammar), ...
'':
:
A :- B1, ..., Bn.
and are read as declarative sentences in logical form:
:
A if B1 and ... and Bn.
In the simplest case of
Horn clauses (or "definite" clauses), which are a subset of
first-order logic
First-order logic, also called predicate logic, predicate calculus, or quantificational logic, is a collection of formal systems used in mathematics, philosophy, linguistics, and computer science. First-order logic uses quantified variables over ...
, all of the A, B
1, ..., B
n are
atomic formula
In mathematical logic, an atomic formula (also known as an atom or a prime formula) is a formula with no deeper propositional structure, that is, a formula that contains no logical connectives or equivalently a formula that has no strict subformu ...
e.
Although Horn clause logic programs are
Turing complete, for many practical applications, it is useful to extend Horn clause programs by allowing negative conditions, implemented by
negation as failure. Such extended logic programs have the knowledge representation capabilities of a
non-monotonic logic.
Differences and relationships between production rules and logic programming rules
The most obvious difference between the two kinds of systems is that production rules are typically written in the forward direction, ''if A then B'', and logic programming rules are typically written in the backward direction, ''B if A''. In the case of logic programming rules, this difference is superficial and purely syntactic. It does not affect the semantics of the rules. Nor does it affect whether the rules are used to reason backwards, Prolog style, to reduce the goal ''B'' to the subgoals ''A'', or whether they are used, Datalog style, to derive ''B'' from ''A''.
In the case of production rules, the forward direction of the syntax reflects the stimulus-response character of most production rules, with the stimulus ''A'' coming before the response ''B''. Moreover, even in cases when the response is simply to draw a conclusion ''B'' from an assumption ''A'', as in
modus ponens
In propositional logic, (; MP), also known as (), implication elimination, or affirming the antecedent, is a deductive argument form and rule of inference. It can be summarized as "''P'' implies ''Q.'' ''P'' is true. Therefore, ''Q'' must ...
, the match-resolve-act cycle is restricted to reasoning forwards from ''A'' to ''B''. Reasoning backwards in a production system would require the use of an entirely different kind of inference engine.
In his Introduction to Cognitive Science,
[https://www.google.co.uk/books/edition/Mind_second_edition/gjcR1U2HT7kC?hl=en&gbpv=1&pg=PP11&printsec=frontcover] Paul Thagard
Paul Richard Thagard (; born 1950) is a Canadian philosopher who specializes in cognitive science, philosophy of mind, and the philosophy of science and medicine. Thagard is a professor emeritus of philosophy at the University of Waterloo. He i ...
includes logic and rules as alternative approaches to modelling human thinking. He does not consider logic programs in general, but he considers Prolog to be, not a rule-based system, but "a programming language that uses logic representations and deductive techniques" (page 40).
He argues that rules, which have the form ''IF condition THEN action'', are "very similar" to logical conditionals, but they are simpler and have greater psychological plausibility (page 51). Among other differences between logic and rules, he argues that logic uses deduction, but rules use search (page 45) and can be used to reason either forward or backward (page 47). Sentences in logic "have to be interpreted as ''universally true''", but rules can be ''defaults'', which admit exceptions (page 44). He does not observe that all of these features of rules apply to logic programming systems.
See also
*
Logic programming
Logic programming is a programming, database and knowledge representation paradigm based on formal logic. A logic program is a set of sentences in logical form, representing knowledge about some problem domain. Computation is performed by applyin ...
*
Expert systems
In artificial intelligence (AI), an expert system is a computer system emulating the decision-making ability of a human expert.
Expert systems are designed to solve complex problems by Automated reasoning system, reasoning through bodies of knowl ...
*
Rewriting
*
RuleML
*
List of rule-based languages
*
Learning classifier system
*
Rule-based machine learning
*
Rule-based modeling
References
{{Semantic Web
Rule engines