Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Logic programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Concepts== Logic programs enjoy a rich variety of semantics and problem solving methods, as well as a wide range of applications in programming, databases, knowledge representation and problem solving. ===Algorithm = Logic + Control=== The procedural interpretation of logic programs, which uses backward reasoning to reduce goals to subgoals, is a special case of the use of a problem-solving strategy to '''control''' the use of a declarative, '''logical''' representation of knowledge to obtain the behaviour of an '''algorithm'''. More generally, different problem-solving strategies can be applied to the same logical representation to obtain different algorithms. Alternatively, different algorithms can be obtained with a given problem-solving strategy by using different logical representations.<ref>{{cite journal|author=R.A.Kowalski|title=Algorithm=Logic + Control|journal=[[Communications of the ACM]]|volume=22| issue = 7|date=July 1979|pages=424–436|doi=10.1145/359131.359136|s2cid = 2509896|doi-access=free}}</ref> The two main problem-solving strategies are [[backward chaining|backward reasoning]] (goal reduction) and [[forward chaining|forward reasoning]], also known as top-down and bottom-up reasoning, respectively. In the simple case of a propositional Horn clause program and a top-level atomic goal, backward reasoning determines an [[and-or tree]], which constitutes the search space for solving the goal. The top-level goal is the root of the tree. Given any node in the tree and any clause whose head matches the node, there exists a set of child nodes corresponding to the sub-goals in the body of the clause. These child nodes are grouped together by an "and". The alternative sets of children corresponding to alternative ways of solving the node are grouped together by an "or". Any search strategy can be used to search this space. Prolog uses a sequential, last-in-first-out, backtracking strategy, in which only one alternative and one sub-goal are considered at a time. For example, subgoals can be solved in parallel, and clauses can also be tried in parallel. The first strategy is called '''{{Visible anchor|and-parallel}}''' and the second strategy is called '''{{Visible anchor|or-parallel}}'''. Other search strategies, such as intelligent backtracking,<ref>{{cite book |last1=Bruynooghe |first1=M. |last2=Pereira |first2=L.M. |date=1984 |chapter=Deduction revision by intelligent backtracking |pages=194–215 |title=Implementations of Prolog |publisher=Ellis Horwood |location=Chichester, England}}</ref> or best-first search to find an optimal solution,<ref>{{cite conference |last=Nakamura |first=K. |date=July 1985 |title=Heuristic Prolog: logic program execution by heuristic search |conference=Conference on Logic Programming |pages=148–155 |location=Berlin, Heidelberg |publisher=Springer Berlin Heidelberg}}</ref> are also possible. In the more general, non-propositional case, where sub-goals can share variables, other strategies can be used, such as choosing the subgoal that is most highly instantiated or that is sufficiently instantiated so that only one procedure applies.<ref>{{cite journal |last1=Genesereth |first1=M.R. |last2=Ginsberg |first2=M.L. |date=1985 |title=Logic programming |journal=[[Communications of the ACM]] |volume=28 |issue=9 |pages=933–941|doi=10.1145/4284.4287 |s2cid=15527861 |doi-access=free }}</ref> Such strategies are used, for example, in [[concurrent logic programming]]. In most cases, backward reasoning from a query or goal is more efficient than forward reasoning. But sometimes with Datalog and Answer Set Programming, there may be no query that is separate from the set of clauses as a whole, and then generating all the facts that can be derived from the clauses is a sensible problem-solving strategy. Here is another example, where forward reasoning beats backward reasoning in a more conventional computation task, where the goal <code>?- fibonacci(n, Result)</code> is to find the n<sup>th</sup> fibonacci number: <syntaxhighlight lang="prolog"> fibonacci(0, 0). fibonacci(1, 1). fibonacci(N, Result) :- N > 1, N1 is N - 1, N2 is N - 2, fibonacci(N1, F1), fibonacci(N2, F2), Result is F1 + F2. </syntaxhighlight> Here the relation <code>fibonacci(N, M)</code> stands for the function <code>fibonacci(N) = M</code>, and the predicate <code>N is Expression</code> is Prolog notation for the predicate that instantiates the variable <code>N</code> to the value of <code>Expression</code>. Given the goal of computing the fibonacci number of <code>n</code>, backward reasoning reduces the goal to the two subgoals of computing the fibonacci numbers of n-1 and n-2. It reduces the subgoal of computing the fibonacci number of n-1 to the two subgoals of computing the fibonacci numbers of n-2 and n-3, redundantly computing the fibonacci number of n-2. This process of reducing one fibonacci subgoal to two fibonacci subgoals continues until it reaches the numbers 0 and 1. Its complexity is of the order 2<sup>n</sup>. In contrast, forward reasoning generates the sequence of fibonacci numbers, starting from 0 and 1 without any recomputation, and its complexity is linear with respect to n. Prolog cannot perform forward reasoning directly. But it can achieve the effect of forward reasoning within the context of backward reasoning by means of [[tabling]]: Subgoals are maintained in a table, along with their solutions. If a subgoal is re-encountered, it is solved directly by using the solutions already in the table, instead of re-solving the subgoals redundantly.<ref>{{cite journal |last1=Swift |first1=T. |last2=Warren |first2=D.S. |date=January 2012 |title=XSB: Extending Prolog with tabled logic programming |journal=[[Theory and Practice of Logic Programming]] |volume=12 |issue=1–2 |pages=157–187|doi=10.1017/S1471068411000500 |arxiv=1012.5123 |s2cid=6153112 }}</ref> === Relationship with functional programming === {{See also|Functional programming#Comparison to logic programming}} Logic programming can be viewed as a generalisation of functional programming, in which functions are a special case of relations.<ref name=dis>{{cite book|author1=Daniel Friedman|author2=William Byrd|author3=Oleg Kiselyov|author4=Jason Hemann|title=The Reasoned Schemer, Second Edition|year=2018|publisher=The MIT Press}}</ref> For example, the function, mother(X) = Y, (every X has only one mother Y) can be represented by the relation mother(X, Y). In this respect, logic programs are similar to [[relational databases]], which also represent functions as relations. Compared with relational syntax, functional syntax is more compact for nested functions. For example, in functional syntax the definition of maternal grandmother can be written in the nested form: <syntaxhighlight lang="prolog"> maternal_grandmother(X) = mother(mother(X)). </syntaxhighlight> The same definition in relational notation needs to be written in the unnested, flattened form: <syntaxhighlight lang="prolog"> maternal_grandmother(X, Y) :- mother(X, Z), mother(Z, Y). </syntaxhighlight> However, nested syntax can be regarded as syntactic sugar for unnested syntax. [[Ciao (programming language)|Ciao]] Prolog, for example, transforms functional syntax into relational form and executes the resulting logic program using the standard Prolog execution strategy.<ref>A. Casas, D. Cabeza, M. V. Hermenegildo. A Syntactic Approach to Combining Functional Notation, Lazy Evaluation and Higher-Order in LP Systems. The 8th International Symposium on Functional and Logic Programming (FLOPS'06), pages 142-162, April 2006.</ref> Moreover, the same transformation can be used to execute nested relations that are not functional. For example: <syntaxhighlight lang="prolog"> grandparent(X) := parent(parent(X)). parent(X) := mother(X). parent(X) := father(X). mother(charles) := elizabeth. father(charles) := phillip. mother(harry) := diana. father(harry) := charles. ?- grandparent(X,Y). X = harry, Y = elizabeth. X = harry, Y = phillip. </syntaxhighlight> === Relationship with relational programming === The term ''relational programming'' has been used to cover a variety of programming languages that treat functions as a special case of relations. Some of these languages, such as [[miniKanren]]<ref name=dis /> and relational linear programming<ref>Kersting, K., Mladenov, M. and Tokmakov, P., 2017. Relational linear programming. Artificial Intelligence, 244, pp.188-216.</ref> are logic programming languages in the sense of this article. However, the relational language RML is an imperative programming language <ref>Beyer, D., 2006, May. Relational programming with CrocoPat. In Proceedings of the 28th International Conference on Software engineering (pp. 807-810).</ref> whose core construct is a relational expression, which is similar to an expression in first-order predicate logic. Other relational programming languages are based on the relational calculus<ref>{{cite journal |last1=MacLennan |first1=Bruce James |editor1-last=Wexelblat |editor1-first=Richard L. |editor1-link=Richard Wexelblat |title=Overview of relational programming |journal=ACM SIGPLAN Notices |date=March 1983 |volume=18 |issue=3 |pages=36-45 |doi=10.1145/988209.988213 |url=https://dl.acm.org/doi/10.1145/988209.988213 |access-date=8 May 2025 |publisher=Association for Computing Machinery |location=New York, NY |issn=0362-1340 |oclc=25073822|hdl=10945/29034 |hdl-access=free }}</ref> or relational algebra.<ref>Behnke, R., Berghammer, R., Meyer, E. and Schneider, P., 1998. RELVIEW—A system for calculating with relations and relational programming. In Fundamental Approaches to Software Engineering: First International Conference, FASE'98 Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS'98 Lisbon, Portugal, March 28–April 4, 1998 Proceedings 1 (pp. 318-321). Springer Berlin Heidelberg.</ref> === Semantics of Horn clause programs === {{main|Syntax and semantics of logic programming}} Viewed in purely logical terms, there are two approaches to the declarative semantics of Horn clause logic programs: One approach is the original ''[[logical consequence]] semantics'', which understands solving a goal as showing that the goal is a theorem that is true in all [[Structure (mathematical logic)#Structures and first-order logic|models]] of the program. In this approach, computation is [[Automated theorem proving|theorem-proving]] in [[first-order logic]]; and both [[backward chaining|backward reasoning]], as in SLD resolution, and [[forward chaining|forward reasoning]], as in hyper-resolution, are correct and complete theorem-proving methods. Sometimes such theorem-proving methods are also regarded as providing a separate [[proof-theoretic semantics|proof-theoretic (or operational) semantics]] for logic programs. But from a logical point of view, they are proof methods, rather than semantics. The other approach to the declarative semantics of Horn clause programs is the ''[[satisfiability]] semantics'', which understands solving a goal as showing that the goal is true (or satisfied) in some [[intended interpretation|intended (or standard) model]] of the program. For Horn clause programs, there always exists such a standard model: It is the unique ''minimal model'' of the program. Informally speaking, a minimal model is a model that, when it is viewed as the set of all (variable-free) facts that are true in the model, contains no smaller set of facts that is also a model of the program. For example, the following facts represent the minimal model of the family relationships example in the introduction of this article. All other variable-free facts are false in the model: <syntaxhighlight lang="prolog"> mother_child(elizabeth, charles). father_child(charles, william). father_child(charles, harry). parent_child(elizabeth, charles). parent_child(charles, william). parent_child(charles, harry). grandparent_child(elizabeth, william). grandparent_child(elizabeth, harry). </syntaxhighlight> The satisfiability semantics also has an alternative, more mathematical characterisation as the [[least fixed point]] of the function that uses the rules in the program to derive new facts from existing facts in one step of inference. Remarkably, the same problem-solving methods of forward and backward reasoning, which were originally developed for the logical consequence semantics, are equally applicable to the satisfiability semantics: Forward reasoning generates the minimal model of a Horn clause program, by deriving new facts from existing facts, until no new additional facts can be generated. Backward reasoning, which succeeds by reducing a goal to subgoals, until all subgoals are solved by facts, ensures that the goal is true in the minimal model, without generating the model explicitly.<ref>{{cite journal|last1=Van Emden|first1=M.H.|last2=Kowalski|first2=R.A.|date=October 1976|title=The semantics of predicate logic as a programming language|journal=[[Journal of the ACM]]|volume=23|issue=4|pages=733–742|doi=10.1145/321978.321991 |s2cid=11048276 |doi-access=free}}</ref> The difference between the two declarative semantics can be seen with the definitions of addition and multiplication in [[Peano arithmetic#Defining arithmetic operations and relations|successor arithmetic]], which represents the natural numbers <code>0, 1, 2, ...</code> as a sequence of terms of the form <code>0, s(0), s(s(0)), ...</code>. In general, the term <code>s(X)</code> represents the successor of <code>X,</code> namely <code>X + 1.</code> Here are the standard definitions of addition and multiplication in functional notation: <pre> X + 0 = X. X + s(Y) = s(X + Y). i.e. X + (Y + 1) = (X + Y) + 1 X × 0 = 0. X × s(Y) = X + (X × Y). i.e. X × (Y + 1) = X + (X × Y). </pre> Here are the same definitions as a logic program, using <code>add(X, Y, Z)</code> to represent <code>X + Y = Z,</code> and <code>multiply(X, Y, Z)</code> to represent <code>X × Y = Z</code>: <syntaxhighlight lang="prolog"> add(X, 0, X). add(X, s(Y), s(Z)) :- add(X, Y, Z). multiply(X, 0, 0). multiply(X, s(Y), W) :- multiply(X, Y, Z), add(X, Z, W). </syntaxhighlight> The two declarative semantics both give the same answers for the same existentially quantified conjunctions of addition and multiplication goals. For example <code>2 × 2 = X</code> has the solution <code>X = 4</code>; and <code>X × X = X + X</code> has two solutions <code>X = 0</code> and <code>X = 2</code>: <syntaxhighlight lang="prolog"> ?- multiply(s(s(0)), s(s(0)), X). X = s(s(s(s(0)))). ?- multiply(X, X, Y), add(X, X, Y). X = 0, Y = 0. X = s(s(0)), Y = s(s(s(s(0)))). </syntaxhighlight> However, with the logical-consequence semantics, there are non-standard models of the program, in which, for example, <code>add(s(s(0)), s(s(0)), s(s(s(s(s(0)))))),</code> i.e. <code>2 + 2 = 5</code> is true. But with the satisfiability semantics, there is only one model, namely the standard model of arithmetic, in which <code>2 + 2 = 5</code> is false. In both semantics, the goal <syntaxhighlight lang="prolog" inline>?- add(s(s(0)), s(s(0)), s(s(s(s(s(0))))))</syntaxhighlight> fails. In the satisfiability semantics, the failure of the goal means that the truth value of the goal is false. But in the logical consequence semantics, the failure means that the truth value of the goal is unknown. ===Negation as failure=== {{Main|Negation as failure}} [[Negation as failure]] (NAF), as a way of concluding that a negative condition <code>not p</code> holds by showing that the positive condition <code>p</code> fails to hold, was already a feature of early Prolog systems. The resulting extension of [[SLD resolution]] is called [[SLD resolution#SLDNF|SLDNF]]. A similar construct, called "thnot", also existed in [[Micro-Planner (programming language)|Micro-Planner]]. The logical semantics of NAF was unresolved until [[Keith Clark (computer scientist)|Keith Clark]]<ref>{{cite book |last=Clark |first=K.L. |title=Logic and Data Bases |chapter=Negation as Failure |author-link=Keith Clark (computer scientist) |date=1977 |pages=293–322 |doi=10.1007/978-1-4684-3384-5_11 |location=Boston, MA |publisher=Springer US|isbn=978-1-4684-3386-9 }}</ref> showed that, under certain natural conditions, NAF is an efficient, correct (and sometimes complete) way of reasoning with the logical consequence semantics using the [[Negation as failure#Completion semantics|''completion'']] of a logic program in first-order logic. Completion amounts roughly to regarding the set of all the program clauses with the same predicate in the head, say: :<code>A :- Body<sub>1</sub>.</code> :<code> ...</code> :<code>A :- Body<sub>k</sub>.</code> as a definition of the predicate: :<code>A iff (Body<sub>1</sub> or ... or Body<sub>k</sub>)</code> where <code>iff</code> means "if and only if". The completion also includes axioms of equality, which correspond to [[Unification (computer science)|unification]]. Clark showed that proofs generated by SLDNF are structurally similar to proofs generated by a natural deduction style of reasoning with the completion of the program. Consider, for example, the following program: <syntaxhighlight lang="prolog"> should_receive_sanction(X, punishment) :- is_a_thief(X), not should_receive_sanction(X, rehabilitation). should_receive_sanction(X, rehabilitation) :- is_a_thief(X), is_a_minor(X), not is_violent(X). is_a_thief(tom). </syntaxhighlight> Given the goal of determining whether tom should receive a sanction, the first rule succeeds in showing that tom should be punished: <syntaxhighlight lang="prolog"> ?- should_receive_sanction(tom, Sanction). Sanction = punishment. </syntaxhighlight> This is because tom is a thief, and it cannot be shown that tom should be rehabilitated. It cannot be shown that tom should be rehabilitated, because it cannot be shown that tom is a minor. If, however, we receive new information that tom is indeed a minor, the previous conclusion that tom should be punished is replaced by the new conclusion that tom should be rehabilitated: <syntaxhighlight lang="prolog"> minor(tom). ?- should_receive_sanction(tom, Sanction). Sanction = rehabilitation. </syntaxhighlight> This property of withdrawing a conclusion when new information is added, is called non-monotonicity, and it makes logic programming a [[non-monotonic logic]]. But, if we are now told that tom is violent, the conclusion that tom should be punished will be reinstated: <syntaxhighlight lang="prolog"> violent(tom). ?- should_receive_sanction(tom, Sanction). Sanction = punishment. </syntaxhighlight> The completion of this program is: <syntaxhighlight lang="prolog"> should_receive_sanction(X, Sanction) iff Sanction = punishment, is_a_thief(X), not should_receive_sanction(X, rehabilitation) or Sanction = rehabilitation, is_a_thief(X), is_a_minor(X), not is_violent(X). is_a_thief(X) iff X = tom. is_a_minor(X) iff X = tom. is_violent(X) iff X = tom. </syntaxhighlight> The notion of completion is closely related to [[John McCarthy (computer scientist)|John McCarthy's]] [[Circumscription (logic)|circumscription]] semantics for default reasoning,<ref>{{cite journal | last1=Gelfond |first1=M. |last2=Przymusinska |first2=H. |last3=Przymusinski |first3=T. |date=1989 |title=On the relationship between circumscription and negation as failure |journal=[[Artificial Intelligence (journal)|Artificial Intelligence]] |volume=38 |issue=1 |pages=75–94|doi=10.1016/0004-3702(89)90068-4 }}</ref> and to [[Raymond Reiter|Ray Reiter's]] [[closed world assumption]].<ref>{{cite journal |last=Shepherdson |first=J.C. |date=1984 |title=Negation as failure: a comparison of Clark's completed data base and Reiter's closed world assumption |journal=[[The Journal of Logic Programming]] |volume=1 |issue=1 |pages=51–79|doi=10.1016/0743-1066(84)90023-2 }}</ref> The completion semantics for negation is a logical consequence semantics, for which SLDNF provides a proof-theoretic implementation. However, in the 1980s, the satisfiability semantics became more popular for logic programs with negation. In the satisfiability semantics, negation is interpreted according to the classical definition of truth in an intended or standard model of the logic program. In the case of logic programs with negative conditions, there are two main variants of the satisfiability semantics: In the [[well-founded semantics]], the intended model of a logic program is a unique, three-valued, minimal model, which always exists. The well-founded semantics generalises the notion of [[inductive definition]] in mathematical logic.<ref>{{cite journal |last1=Denecker |first1=M. |last2=Ternovska |first2=E. |title=A logic of nonmonotone inductive definitions |journal=[[ACM Transactions on Computational Logic]] |volume=9 |issue=2 |pages=14:1–14:52 |date=2008|doi=10.1145/1342991.1342998 |s2cid=13156469 |url=https://lirias.kuleuven.be/handle/123456789/222628 |arxiv=cs/0501025 }}</ref> [[XSB|XSB Prolog]]<ref>{{cite conference |last1=Rao |first1=P. |last2=Sagonas |first2=K. |last3=Swift |first3=T. |last4=Warren |first4=D.S. |last5=Freire |first5=J. |title=XSB: A system for efficiently computing well-founded semantics |conference=Logic Programming And Nonmonotonic Reasoning: 4th International Conference, LPNMR'97 |location=Dagstuhl Castle, Germany |date=July 28–31, 1997 |pages=430–440 |publisher=Springer Berlin Heidelberg |doi=10.1007/3-540-63255-7_33}}</ref> implements the well-founded semantics using SLG resolution.<ref>{{cite journal |author1=W. Chen |author2=D. S. Warren |title=Tabled Evaluation with Delaying for General Logic Programs |journal=[[Journal of the ACM]] |volume=43 |issue=1 |pages=20–74 |date=January 1996 |doi=10.1145/227595.227597|s2cid=7041379 |doi-access=free }}</ref> In the alternative [[stable model semantics]], there may be no intended models or several intended models, all of which are minimal and two-valued. The stable model semantics underpins [[answer set programming]] (ASP). Both the well-founded and stable model semantics apply to arbitrary logic programs with negation. However, both semantics coincide for [[Syntax and semantics of logic programming#Stratified negation|stratified]] logic programs. For example, the program for sanctioning thieves is (locally) stratified, and all three semantics for the program determine the same intended model: <syntaxhighlight lang="prolog"> should_receive_sanction(tom, punishment). is_a_thief(tom). is_a_minor(tom). is_violent(tom). </syntaxhighlight> Attempts to understand negation in logic programming have also contributed to the development of [[Argumentation framework|abstract argumentation frameworks]].<ref>{{cite journal |author=Phan Minh Dung |title=On the acceptability of arguments and its fundamental role in nonmonotonic reasoning, logic programming, and n–person games |journal=Artificial Intelligence |volume=77 |issue= 2|pages=321–357 |year=1995 |doi=10.1016/0004-3702(94)00041-X|doi-access=free }}</ref> In an argumentation interpretation of negation, the initial argument that tom should be punished because he is a thief, is attacked by the argument that he should be rehabilitated because he is a minor. But the fact that tom is violent undermines the argument that tom should be rehabilitated and reinstates the argument that tom should be punished. ===Metalogic programming=== [[Metaprogramming]], in which programs are treated as data, was already a feature of early Prolog implementations.<ref>Colmerauer, A. and Roussel, P., 1996. The birth of Prolog. In History of programming languages---II (pp. 331-367).</ref><ref name="Warren">Warren, D.H., Pereira, L.M. and Pereira, F., 1977. Prolog-the language and its implementation compared with Lisp. ACM SIGPLAN Notices, 12(8), pp.109-115.</ref> For example, the Edinburgh DEC10 implementation of Prolog included "an interpreter and a compiler, both written in Prolog itself".<ref name="Warren"/> The simplest metaprogram is the so-called "[[Vanilla (computing)|vanilla]]" meta-interpreter: <syntaxhighlight lang="prolog"> solve(true). solve((B,C)):- solve(B),solve(C). solve(A):- clause(A,B),solve(B). </syntaxhighlight> where true represents an empty conjunction, and (B,C) is a composite term representing the conjunction of B and C. The predicate clause(A,B) means that there is a clause of the form A :- B. Metaprogramming is an application of the more general use of a ''[[metalogic]]'' or ''[[metalanguage]]'' to describe and reason about another language, called the ''object language''. Metalogic programming allows object-level and metalevel representations to be combined, as in natural language. For example, in the following program, the atomic formula <code>attends(Person, Meeting)</code> occurs both as an object-level formula, and as an argument of the metapredicates <code>prohibited</code> and <code>approved.</code> <syntaxhighlight lang="prolog"> prohibited(attends(Person, Meeting)) :- not(approved(attends(Person, Meeting))). should_receive_sanction(Person, scolding) :- attends(Person, Meeting), lofty(Person), prohibited(attends(Person, Meeting)). should_receive_sanction(Person, banishment) :- attends(Person, Meeting), lowly(Person), prohibited(attends(Person, Meeting)). approved(attends(alice, tea_party)). attends(mad_hatter, tea_party). attends(dormouse, tea_party). lofty(mad_hatter). lowly(dormouse). ?- should_receive_sanction(X,Y). Person = mad_hatter, Sanction = scolding. Person = dormouse, Sanction = banishment. </syntaxhighlight> ===Relationship with the [[Computational-representational understanding of mind]]=== In his popular Introduction to Cognitive Science,<ref>{{Cite book|title=Mind: Introduction to Cognitive Science|last=Thagard|first=Paul|publisher=The MIT Press|year=2005|isbn=9780262701099|pages=11}}https://www.google.co.uk/books/edition/Mind_second_edition/gjcR1U2HT7kC?hl=en&gbpv=1&pg=PP11&printsec=frontcover</ref> [[Paul Thagard]] includes logic and [[Rule-based system|rules]] as alternative approaches to modelling human thinking. 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 states that "unlike logic, rule-based systems can also easily represent strategic information about what to do" (page 45). For example, "IF you want to go home for the weekend, and you have bus fare, THEN you can catch a bus". He does not observe that the same strategy of reducing a goal to subgoals can be interpreted, in the manner of logic programming, as applying backward reasoning to a logical conditional: <syntaxhighlight lang="prolog"> can_go(you, home) :- have(you, bus_fare), catch(you, bus). </syntaxhighlight> All of these characteristics of rule-based systems - search, forward and backward reasoning, default reasoning, and goal-reduction - are also defining characteristics of logic programming. This suggests that Thagard's conclusion (page 56) that: <blockquote> Much of human knowledge is naturally described in terms of rules, and many kinds of thinking such as planning can be modeled by rule-based systems. </blockquote> also applies to logic programming. Other arguments showing how logic programming can be used to model aspects of human thinking are presented by [[Keith Stenning]] and [[Michiel van Lambalgen]] in their book, Human Reasoning and Cognitive Science.<ref>{{cite book | last = Stenning | first = Keith |author2=van Lambalgen, Michiel | title = Human reasoning and cognitive science | url = https://archive.org/details/humanreasoni_sten_2008_000_10735669 | url-access = registration | publisher = [[MIT Press]] | year = 2008| isbn = 978-0-262-19583-6 }}https://philpapers.org/archive/STEHRA-5.pdf</ref> They show how the non-monotonic character of logic programs can be used to explain human performance on a variety of psychological tasks. They also show (page 237) that "closed–world reasoning in its guise as logic programming has an appealing neural implementation, unlike classical logic." In The Proper Treatment of Events,<ref>Van Lambalgen, M. and Hamm, F., 2008. The proper treatment of events. John Wiley & Sons. https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=3126320bb6e37ca3727fed404828b53fc56ff063</ref> Michiel van Lambalgen and Fritz Hamm investigate the use of constraint logic programming to code "temporal notions in natural language by looking at the way human beings construct time". ===Knowledge representation=== The use of logic to represent procedural knowledge and strategic information was one of the main goals contributing to the early development of logic programming. Moreover, it continues to be an important feature of the Prolog family of logic programming languages today. However, many applications of logic programming, including Prolog applications, increasingly focus on the use of logic to represent purely declarative knowledge. These applications include both the representation of general [[Commonsense reasoning|commonsense]] knowledge and the representation of domain specific [[Expert system|expertise]]. Commonsense includes knowledge about cause and effect, as formalised, for example, in the [[situation calculus]], [[event calculus]] and [[action language]]s. Here is a simplified example, which illustrates the main features of such formalisms. The first clause states that a fact holds immediately after an event initiates (or causes) the fact. The second clause is a ''[[frame problem|frame axiom]]'', which states that a fact that holds at a time continues to hold at the next time unless it is terminated by an event that happens at the time. This formulation allows more than one event to occur at the same time: <syntaxhighlight lang="prolog"> holds(Fact, Time2) :- happens(Event, Time1), Time2 is Time1 + 1, initiates(Event, Fact). holds(Fact, Time2) :- happens(Event, Time1), Time2 is Time1 + 1, holds(Fact, Time1), not(terminated(Fact, Time1)). terminated(Fact, Time) :- happens(Event, Time), terminates(Event, Fact). </syntaxhighlight> Here <code>holds</code> is a meta-predicate, similar to <code>solve</code> above. However, whereas <code>solve</code> has only one argument, which applies to general clauses, the first argument of <code>holds</code> is a fact and the second argument is a time (or state). The atomic formula <code>holds(Fact, Time)</code> expresses that the <code>Fact</code> holds at the <code>Time</code>. Such time-varying facts are also called [[Fluent (artificial intelligence)|fluents]]. The atomic formula <code>happens(Event, Time)</code> expresses that the Event happens at the <code>Time</code>. The following example illustrates how these clauses can be used to reason about causality in a toy [[blocks world]]. Here, in the initial state at time 0, a green block is on a table and a red block is stacked on the green block (like a traffic light). At time 0, the red block is moved to the table. At time 1, the green block is moved onto the red block. Moving an object onto a place terminates the fact that the object is on any place, and initiates the fact that the object is on the place to which it is moved: <syntaxhighlight lang="prolog"> holds(on(green_block, table), 0). holds(on(red_block, green_block), 0). happens(move(red_block, table), 0). happens(move(green_block, red_block), 1). initiates(move(Object, Place), on(Object, Place)). terminates(move(Object, Place2), on(Object, Place1)). ?- holds(Fact, Time). Fact = on(green_block,table), Time = 0. Fact = on(red_block,green_block), Time = 0. Fact = on(green_block,table), Time = 1. Fact = on(red_block,table), Time = 1. Fact = on(green_block,red_block), Time = 2. Fact = on(red_block,table), Time = 2. </syntaxhighlight> Forward reasoning and backward reasoning generate the same answers to the goal <code>holds(Fact, Time)</code>. But forward reasoning generates fluents ''progressively'' in temporal order, and backward reasoning generates fluents ''regressively'', as in the domain-specific use of [[situation calculus#Regression|regression]] in the [[situation calculus]].<ref>Reiter, R., 1991. The frame problem in the situation calculus: A simple solution (sometimes) and a completeness result for goal regression. Artificial and Mathematical Theory of Computation, 3.</ref> Logic programming has also proved to be useful for representing domain-specific expertise in [[expert system]]s.<ref>Merritt, D., 2012. Building expert systems in Prolog. Springer Science & Business Media. https://ds.amu.edu.et/xmlui/bitstream/handle/123456789/4434/%28Text%20Book%29%20Building%20Expert%20Systems%20in%20Prolog.pdf?sequence=1&isAllowed=y</ref> But human expertise, like general-purpose commonsense, is mostly implicit and [[Tacit knowledge|tacit]], and it is often difficult to represent such implicit knowledge in explicit rules. This difficulty does not arise, however, when logic programs are used to represent the existing, explicit rules of a business organisation or legal authority. For example, here is a representation of a simplified version of the first sentence of the British Nationality Act, which states that a person who is born in the UK becomes a British citizen at the time of birth if a parent of the person is a British citizen at the time of birth: <syntaxhighlight lang="prolog"> initiates(birth(Person), citizen(Person, uk)):- time_of(birth(Person), Time), place_of(birth(Person), uk), parent_child(Another_Person, Person), holds(citizen(Another_Person, uk), Time). </syntaxhighlight> Historically, the representation of a large portion of the British Nationality Act as a logic program in the 1980s<ref>{{cite journal|last1=Sergot|first1=M.J.|last2=Sadri|first2=F.|last3=Kowalski|first3=R.A.|last4=Kriwaczek|first4=F.|last5=Hammond|first5=P|last6=Cory|first6=H.T.|date=1986|url=http://www.doc.ic.ac.uk/~rak/papers/British%20Nationality%20Act.pdf|title=The British Nationality Act as a logic program|journal=[[Communications of the ACM]]|volume=29|issue=5|pages=370–386|doi=10.1145/5689.5920 |s2cid=5665107 }}</ref> was "hugely influential for the development of computational representations of legislation, showing how logic programming enables intuitively appealing representations that can be directly deployed to generate automatic inferences".<ref>{{cite journal|last1=Prakken|first1=H.|last2=Sartor|first2=G.|date=October 2015|url=https://www.sciencedirect.com/science/article/pii/S0004370215000910/pdfft?md5=4dc0cf07e5c2a6926d285431b987a859&pid=1-s2.0-S0004370215000910-main.pdf|title=Law and logic: a review from an argumentation perspective|journal=[[Artificial Intelligence (journal)|Artificial Intelligence]]|volume=227|pages=214–245|doi=10.1016/j.artint.2015.06.005|s2cid=4261497 }}</ref> More recently, the PROLEG system,<ref>Satoh, K., 2023. PROLEG: Practical legal reasoning system. In Prolog: The Next 50 Years (pp. 277-283). Cham: Springer Nature Switzerland.</ref> initiated in 2009 and consisting of approximately 2500 rules and exceptions of civil code and supreme court case rules in Japan, has become possibly the largest legal rule base in the world.<ref name=":02">{{Cite journal |last1=Körner |first1=Philipp |last2=Leuschel |first2=Michael |last3=Barbosa |first3=João |last4=Costa |first4=Vítor Santos |last5=Dahl |first5=Verónica |last6=Hermenegildo |first6=Manuel V. |last7=Morales |first7=Jose F. |last8=Wielemaker |first8=Jan |last9=Diaz |first9=Daniel |last10=Abreu |first10=Salvador |last11=Ciatto |first11=Giovanni |date=November 2022 |title=Fifty Years of Prolog and Beyond |journal=Theory and Practice of Logic Programming |language=en |volume=22 |issue=6 |pages=776–858 |doi=10.1017/S1471068422000102 |issn=1471-0684|doi-access=free |arxiv=2201.10816 }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)