Prolog. Prolog: Programmation en Logique R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp.

Similar documents
COMP2411 Lecture 20: Logic Programming Examples. (This material not in the book)

An introduction to logic programming with Prolog

Prolog. Intro to Logic Programming

Advanced Logic and Functional Programming

Last Week. Today. Prolog: recursion examples. Recursion in Prolog. CSC326 Programming Languages (Week 12,Friday)

First-Order Logic (FOL)

More Non-logical Features of Prolog

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or

Notes for Chapter 12 Logic Programming. The AI War Basic Concepts of Logic Programming Prolog Review questions

Implementação de Linguagens 2016/2017

Lecture 11: Feb. 10, 2016

CAP 5602 Summer, Lesson 4: Loops. The topics 1. the cut and some of its uses 2. the while loop 3. the do until loop

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy

Syntax and Meaning of Prolog Programs

simplicity hides complexity flow of control, negation, cut, 2 nd order programming, tail recursion procedural and declarative semantics and & or

Introduction to predicate calculus

Part I Logic programming paradigm

Symbolic Programming Declarative Programming

Lecture 16: Logic Programming in Prolog

PROLOG. First simple Prolog Program. Basic elements of Prolog. Clause. NSSICT/CH/Nov., 2012.

Chapter 5. Pure PROLOG. Foundations of Logic Programming

Chapter 16. Logic Programming Languages

PROLOG programming for artificial intelligence

Lecture 1: Conjunctive Queries

CSEN403 Concepts of Programming Languages. Topics: Logic Programming Paradigm: PROLOG Search Tree Recursion Arithmetic

Announcements. The current topic: Prolog. Logic programming. Logic programming. Lab 2 has been marked.

Range Restriction for General Formulas

Chapter 16. Logic Programming Languages ISBN

Datalog: Deductive Database Programming

CSC384: Intro to Artificial Intelligence Prolog Tutorials 3&4. Hojjat Ghaderi, Fall 2006, University of Toronto

Prolog. Logic Programming vs Prolog

ACSC300: Logic Programming

Logic Programming in Prolog

Introduction to Data Management CSE 344. Lecture 14: Datalog (guest lecturer Dan Suciu)

Prolog. IFT 6802 Introduction to Prolog. Declarative programming LOGIC PROGRAMMING BASICS. LOGIC PROGRAMMING BASICS (suite) Facts

Logic Languages. Hwansoo Han

A Motivational Introduction to Computational Logic and (Constraint) Logic Programming

Logic Programming. Efficiency Issues. Temur Kutsia

DATABASE THEORY. Lecture 12: Evaluation of Datalog (2) TU Dresden, 30 June Markus Krötzsch

PROgramming in LOGic PROLOG Recursion, Lists & Predicates

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 14. Example. Datalog syntax: rules. Datalog query. Meaning of Datalog rules

PROgramming in LOGic. Part II. By Forrest Pepper 12/7/07

CS 360: Programming Language Concepts Lecture 15 Logic Programming

The Idea Underlying Logic Programming. CSci 8980, Fall 2012 Specifying and Reasoning About Computational Systems An Introduction to Logic Programming

8. Negation 8-1. Deductive Databases and Logic Programming. (Sommer 2017) Chapter 8: Negation

COMP219: Artificial Intelligence. Lecture 6: Recursion in Prolog

Logic as a Programming Language

LOGIC AND DISCRETE MATHEMATICS

DATABASE THEORY. Lecture 15: Datalog Evaluation (2) TU Dresden, 26th June Markus Krötzsch Knowledge-Based Systems

Introduction to Data Management CSE 344. Lecture 14: Datalog

Lecture Notes on Prolog

What s the problem? fib(1,1). fib(2,1). fib(n,x) :- N>2, N1 is N-1, N2 is N-2, fib(n1,x2), fib(n2,x2).

Prolog. GNU Prolog ( SWI-Prolog (

Artificial Intelligence. Chapters Reviews. Readings: Chapters 3-8 of Russell & Norvig.

CMSC 330: Organization of Programming Languages

Introduction to Prolog

Chapter 9: Constraint Logic Programming

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Backtracking. Ch. 5 Controlling Backtracking. Backtracking. Backtracking Example. Example. Example

Prolog-2 nd Lecture. Prolog Predicate - Box Model

Principles of Programming Languages Topic: Logic Programming Professor Lou Steinberg

Principles of Programming Languages (II)

Datalog: Deductive Database Programming

Logical reasoning systems

Topic B: Backtracking and Lists

Lecture Notes on Prolog

Chapter 3: Pure Prolog

CSI 2165 Winter Diana Inkpen SITE University of Ottawa. Prolog Part III. Input and output. Prolog databases

Using Prolog as a CAS

This lecture covers: Prolog s execution strategy explained more precisely. Revision of the elementary Prolog data types

Constraint Solving. Systems and Internet Infrastructure Security

to read: Chapter 10, Russel & Norvig

CS 321 Programming Languages and Compilers. Prolog

IN112 Mathematical Logic

Lecture 6: Inductive Logic Programming

Announcements. Database Systems CSE 414. Datalog. What is Datalog? Why Do We Learn Datalog? HW2 is due today 11pm. WQ2 is due tomorrow 11pm

Prolog. Textbook and Software. Title PROLOG programming for artificial intelligence

Constraint Propagation for Efficient Inference in Markov Logic

A Motivational Introduction to Computational Logic and (Constraint) Logic Programming

CS 360: Programming Languages Lecture 10: Logic Programming with Prolog

DATABASE THEORY. Lecture 11: Introduction to Datalog. TU Dresden, 12th June Markus Krötzsch Knowledge-Based Systems

IN112 Mathematical Logic

6. Inference and resolution

Knowledge-Based Systems and Deductive Databases

Prolog. GNU Prolog ( SWI-Prolog (

Arithmetic Terms are Symbolic

The current topic: Prolog. Announcements. Meaning of a Prolog rule. Prolog syntax. Reminder: The deadline for Lab 2 re-mark requests is Friday.

Using Prolog as a CAS

Family Example: Some Facts. respects(barb,dan). respects(barb,katie). respects(dan,brian). respects(dan,barbara).

Situation Calculus and YAGI

CSE20: Discrete Mathematics

IKI30820 Logic Programming Logic Programming Paradigm Slide 01

Programming Paradigms Written Exam (6 CPs)

Computational Logic. SLD resolution. Damiano Zanardini

INTRODUCTION TO PROLOG

will take you everywhere.

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Chapter 16. Logic Programming Languages ISBN

Logic Programming. April 3, 2017

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation

Transcription:

Prolog Prolog: Programmation en Logique 1974 - R.A. Kowalski: Predicate logic as a programming language, Proc IFIP 1974, pp. 569-574: First-order predicate logic for the specification of data and relationships Computation = logical deduction 1972 - A. Colmerauer, P. Roussel: first Prolog-like interpreter

Logic Programming (LP) R.A. Kowalski (Imperial College): Algorithm = Logic + Control Imperative languages (C++, Java): data (what) operations on data (how) no separation between what and how

LP: Logic + Control Logical Formulas x (P(x) Q(x)) Logical Deduction ψ, ϕ ψ ϕ

What: Problem Description Horn clause: A B 1,B 2,,B n Equivalent to: A v B 1 v B 2 v v B n Meaning: A is true if B 1 is true, and B 2 is true,., and B n is true

What: Problem Description A B 1,,B n specification of facts concerning objects and relations between objects specification of rules concerning objects and relations between objects specification of queries concerning objects and relations

Problem Description Facts: A Rules: A B 1,,B n Queries: B 1,,B n

Meet the Royal Family

Example: Family Relations Facts: mother(juliana, beatrix) Rules: parent(x, Y) mother(x, Y) parent(x, Y) father(x, Y) variable constant Query: parent(juliana, beatrix)

Queries: Logic Program mother(juliana, beatrix) mother(beatrix, alexander) father(claus, alexander) parent(x, Y) mother(x, Y) parent(x, Y) father(x, Y) parent(claus, alexander) parent(beatrix, juliana)

Prolog Prolog: practical realisation of LP Prolog clause: A :- B 1, B 2,, B n. head Example: body mother(juliana, beatrix). parent(x, Y) :- mother(x,y). :- parent(juliana, beatrix).

Why is Prolog so Handy? Hotel suite design: front door window Living Room Bed Room window

front door window Living Room Bed Room window 1. Living-room window opposite the front door 2. Bed-room door at right angle with front door 3. Bed-room window adjacent to wall with bedroom door 4. Bed-room window should face East

C-like type dir = (north, south, east, west); livrm(fd, lw, bd : dir) : boolean; { livrm = opposite(fd, lw) and adjacent(fd, bd) } bedrm(bd, bw : dir) : boolean; { bedrm = adjacent(bd, bw) and (bw = east) } suite(fd, lw, bd, bw : dir) : boolean; { suite = livrm(fd, lw, bd) and bedrm(bd, bw) }

Continued for fd = north to west do for lw = north to west do for bd = north to west do for bw = north to west do if suite(fd, lw, bd, bw) then print(fd, lw, bd, bw)

In Prolog livrm(fd, Bd, Lw) :- opposite(fd, Lw), adjacent(fd, Bd). bedrm(bd, Bw) :- adjacent(bd, Bw), Bw = east. suite(fd, Lw, Bd, Be) :- livrm(fd, Lw, Bd), bedrm(bd, Bw). :- suite(fd, Lw, Bd, Bw).

Declarative Semantics Prolog clause: A :- B,B,,B 1 2 n. Meaning: A is true if B is true, and 1 B is true,., and 2 B is true n

Procedural Semantics Prolog as a procedural language Prolog clause = procedure procedure head A :- B 1, B 2,, B n. procedure body Query = procedure call :- B 1, B 2,, B n.

More General Programs Use often lists: [a, b, c, d] = [a [b, c, d]] head tail Element is first element (fact): member(a, [a [b, c, d]]). In general: member(x, [X _]).

Set Membership member(x, [X _]). member(x, [_ Y]) :- member(x, Y) Queries: :- member(a,[b,a,c]) :- member(d,[b,a,c])

Example 1 /*1*/ member(x, [X _]). procedure entry /*2*/ member(x, [_ Y]) :- procedure entry member(x, Y). /*3*/ :- member(a, [a, b, c]). call Step 1 :- member(a, [a, b, c]). /*1*/ member(x, [X _]). Instantiation: X = a match with /*1*/

Example 2 /*1*/ member(x, [X _]). procedure entry /*2*/ member(x, [_ Y]) :- procedure entry member(x, Y). /*3*/ :- member(a, [b, a, c]). call Step 1 :- member(a, [b, a, c]). /*1*/ member(x, [X _]). Instantiation: X = a no match with /*1*/

Example 2 (continued) /*1*/ member(x, [X _]). procedure entry /*2*/ member(x, [_ Y]) :- procedure entry member(x, Y). /*3*/ :- member(a, [b,a,c]). call Step 2 :- member(a, [b, a, c]). /*2*/ member(x, [_ Y]) :- member(x, Y). Match: X = a; Y = [a, c]

Example 2 (continued) /*1*/ member(x, [X _]). procedure entry /*2*/ member(x, [_ Y]) :- procedure entry member(x, Y). /*3*/ :- member(a, [b,a,c]). call Step 3 :- member(a, [a, c]). subcall /*1*/ member(x, [X _]). Match: X = a

Matching A call and procedure head match if: predicate symbols are equal arguments in corresponding positions are equal Example: :- member(a, [a, c]). /*1*/ member(a, [a _]).

Variables & Atoms mother(juliana, beatrix). Calls: :- mother(x, Y). X = juliana Y = beatrix :- mother(_, _). /* anonymous variable */ yes :- mother(juliana, juliana). no

Left-right Selection Rule Call: q. :- p. r. s. :- q, r, s. p :- q, r, s. :- r, s. :- s.

Top-bottom Selection Rule p(a). p(b). p(c). p(x) :- q(x). q(d). q(e). Call: :- p(y). Y = a; Y = b; Y = c; Y = d; Y = e; no

Backtracking Backtracking: systematic search for alternatives Example: search for paths in tree T a b c d e

Backtracking a b c d branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x,z), path(z,y). e

Backtracking b a d c e branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x, Z), path(z, Y). 1 :- path(a, d). /* query */ path(a, d) :- branch(a, Z), path (Z, d). branch(a, Z) Z = b branch(a, b). 1

Backtracking b a d c e branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x, Z), path(z, Y). 2 :- path(a, d). /* query */ path(a, d) :- branch(a, Z), path (Z, d). Z = b 2 path(b, d) X = b, Y = d path(b, d) :- branch(b, Z ), path(z, d).

Backtracking b a d c e branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x, Z), path(z, Y). path(b, d) :- branch(b, Z ), path(z, d). 3 branch(b, Z ) backtrack 3

Backtrack Point b a d c e branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x, Z), path(z, Y). 1 :- path(a, d). /* query */ path(a, d) :- branch(a, Z), path (Z, d). branch(a, Z) Z = c branch(a, c). 1

Backtracking b a d c e branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x, Z), path(z, Y). 2 :- path(a, d). /* query */ path(a, d) :- branch(a, Z), path (Z, d). Z = c 2 path(c, d) X = c, Y = d path(c, d) :- branch(c, Z ), path(z, d).

Backtracking b a d c e branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x, Z), path(z, Y). path(c, d) :- branch(c, Z ), path(z, d). 3 branch(c, Z ) Z = d branch(c, d) 3

Backtracking b a d c e branch(a, b). branch(a, c). branch(c, d). branch(c, e). path(x, X). path(x, Y) :- branch(x, Z), path(z, Y). path(c, d) :- branch(c, Z ), path(z, d). Z = d path(d, d) 4 X = d path(d, d) 4

Terminology From programming languages (Prolog as procedural language): nat(0). nat(s(x)) :- nat(x). term: nat(0), nat(s(x)), nat(x), :-(nat(s(x)), nat(x)), s(x), 0, X functor: s, nat, :- principal functor: nat in nat(s(x)), :- in :-(nat(s(x)), nat(x)), s in s(x) number: 0 variable: X

Inversion of Computation (1) Example: concatenation of lists U = V W with U, V, W lists and concatenation operator Usage: [a, b] = [a] W W = [b] [a, b] = V [b] V = [a] U = [a] [b] U = [a, b] [a, b] = V W?

Inversion of Computation (2) Prolog concatenation of lists: concat([], U, U). concat([x U], V, [X W]) :- concat(u, V, W). concat as constructor:?- concat([a, b], [c, d], X). X = [a, b, c, d] concat used for decomposition:?- concat(x, Y, [a, b, c, d]). X = [] Y = [a, b, c, d]

Inversion of Computation (3) concat used for decomposition:?- concat(x, Y, [a, b, c, d]). X = [] Y = [a, b, c, d]; X = [a] Y = [b, c, d]; X = [a, b] Y = [c, d];...

Order of Clauses (1) LP: order is irrelevant Prolog: order may be relevant Example: member(x,[_ Y]) :- member(x,y). member(x,[x _]). :- member(a,[b,a,c]).

Order of Clauses (2) /*1*/ member(x, [_ Y]) :- member(x, Y). /*2*/ member(x, [X _]).?- member(a, [a,b]). X = a, Y = [b] match with 1?- member(a, [b]). next call X = a, Y = [] match with 1?- member(a, []). fail 1 and 2 fail 1 and 2 fail 1, backtracking to 2 X = a match 2 yes! (but not efficient)

Order of Clauses (3) /*1*/ member(x, [_ Y]) :- member(x, Y). /*2*/ member(x, [X _]).?- member(x, [a, b]). X = X, Y = [b] match with 1?- member(x, [b]). next call X = X, Y = [] match with 1?- member(x, []). fail 1 and 2 X = b fail 1, match 2 X = b; backtracking X = a match 2 yes! (but not efficient)

Order of Clauses (4) /*1*/ member(x, [_ Y]) :- member(x, Y). /*2*/ member(x, [X _]).?- member(a, Z). X = a, Z = [_ Y] match 1?- member(a, Y). next call X = a, Y= [_ Y ] match 1?- member(a, Y ). next call. Stack overflow

Conclusions Order of Clauses LP: order clauses is irrelevant Prolog: Order has effect on efficiency of program Order may affect termination: terminating program + order change terminating program

Order of Conditions (1) Length of list with successor function s : N N, with s(x) = x + 1 Program: Use: /*1*/ length([], 0). /*2*/ length([_ X], N) :- length(x, M), N = s(m).?- length([a, b], N). N = s(s(0))

Order of Conditions (2) Program: Use: /*1*/ length([], 0). /*2*/ length([_ X], N) :- length(x, M), N = s(m).?- length(l, s(0)). L = [_A]; Stack overflow

Order of Conditions (3) /*1*/ length([], 0). /*2*/ length([_ X], N) :- length(x, M), N = s(m). Trace:?- length(l, s(0)). L = [_A X], N = s(0) match 2?- length(x, M), s(0) = s(m). subcall X = [], M = 0 match 1?- s(0) = s(0). match L = [_A]; backtracks (1 fails)

Order of Conditions (4) /*1*/ length([], 0). /*2*/ length([_ X], N) :- length(x, M), N = s(m). Trace:?- length(l, s(0)). L = [_A X], N = s(0) match 2?- length(x, M), s(0) = s(m). subcall X = [_B X ], N = M match 2?- length(x, M ), M = s(m ), subcall s(0) = s(m)....

Order of Conditions (5) Program: /*1*/ length([], 0). /*2*/ length([_ X], N) :- N = s(m), length(x, M). Use:?- length(l, s(0)). L = [_A]; no

Declarative vs Procedural Order of clauses and conditions in clauses in Prolog progams may be changed, but This may be at the expense of: loss of termination compromised efficiency Schema for procedural programming: special case first (top, left) general case (e.g. including a recursive call) last (bottom, right)

Fail & Cut Notation: fail and! Control predicates: affect backtracking Used for: efficiency reasons implementing tricks

Enforcing Backtracking: fail?- fail. no (no match) Program: p(a). p(b). Query:?- p(x). (match) X = a yes

Fail - no Recursion Program: p(a). p(b). p(x) :- q(x). q(c). Query:?- p(x), write(x), nl, fail. a b c backtracking no

Fail - with Recursion Program: /*1*/ member(x, [X _]). /*2*/ member(x, [_ Y]) :- member(x,y). Query/call:?- member(z,[a,b]), write(z), nl, fail. Z = X, X = a match 1?- write(a), nl, fail. a backtracking?- member(z,[a,b]), write(z), nl, fail. Z = X, Y = [b] match 2

Controlling Backtracking:! Procedural meaning of the cut!: A :- B1, B2,!, B3, B4. Search for alternatives Search for alternatives! Stop searching

Program: p(a). p(b). q(x) :- p(x), r(x). r(y) :-!, t(y). r(a). t(c). Cut Execution:?- q(z). Z = X?- p(x), r(x). X = a?- r(a). Y = a?- t(a). fail, no backtracking to r(a). Try X = b!

State Space and! a :- b, c. a :- f, g....?- a. b :- d,!, e. b :-.... d. fail fail?-!, e, c.?- b, c.?- d,!, e, c. fail?- f, g. fail

Various Applications of! Cut as commitment operator: Prolog: if X < 3 then Y = 0 if X 3 and X < 6 then Y = 2 if X 6 then Y = 4 t(x, 0) :- X < 3. t(x, 2) :- X >= 3, X < 6. t(x, 4) :- X >= 6.

Commitment Operator Cut as commitment operator: /*1*/ t(x, 0) :- X < 3. /*2*/ t(x, 2) :- X >= 3, X < 6. /*3*/ t(x, 4) :- X >= 6. Execution trace:?- t(1, Y), Y > 2. match 1?- 1 < 3, 0 > 2.?- 0 > 2. fail 1?- 1 >= 3, 1 < 6, 1 > 2. match 2?- fail 2?- 1 >= 6, 4 > 2. match 3, fail 3

Commitment Operator Cut as commitment operator: /*1*/ t(x, 0) :- X < 3,!. /*2*/ t(x, 2) :- X >= 3, X < 6,!. /*3*/ t(x, 4) :- X >= 6. Execution trace:?- t(1, Y), Y > 2. match 1?- 1 < 3,!, 0 > 2.?-!, 0 > 2. fail 1 no

Various Applications of! Cut used for removal of conditions: min(x, Y) is X if X Y min(x, Y) is Y if X > Y Prolog: min(x, Y, X) :- X =< Y. min(x, Y, Y) :- X > Y. Execution:?- min(3, 5, Z).?- 3 =< 5. match 1 Z = 3 yes

Removal of Conditions Cut used for removal of conditions: min(x, Y, Z) :- X =< Y,!, Z = X. min(x, Y, Y). Execution:?- min(3, 5, W).?- 3 =< 5,!, W = 3. match 1 W = 3 yes

Removal of Conditions Cut used for removal of conditions: min(x, Y, Z X) :- X =< Y,!. Z = X. why included? min(x, Y, Y). Execution:?- min(3, 5, 5). fail 1, match 2 yes

Change in Meaning? Cut used for removal of conditions: min(x, Y, Z) :- X =< Y, (! omitted) Z = X. min(x, Y, Y). Execution:?- min(3, 5, W), W = 5.?- 3 =< 5, 5 = 3, W = 5. match 1?- 5 = 3, W = 5. fail?- W = 5. match 2 (with Y = 5 = W) W = 5 yes

Negation by Failure Simulation of negation: not(p) is true if p is false (fails): not(x) :- call(x),!, fail. not(x). Example: p(a). q(x) :- p(x), not(r(x)). r(c).?- q(y). yes

Single Solution Circumvention of double search: /*1*/ member(x, [X _]) :-!. /*2*/ member(x,[_ Y]) :- member(x,y). Example:?- member(a, [a, b, a]). yes?- member(x, [a, b]). X = a; no

Green and Red Cuts Green cut: when omitted, does not change declarative (logical) meaning of program used to increase efficiency Red cut: when omitted, declarative meaning of program is changed used for efficiency used to enforce termination

Green and Red Cuts Green cut: commitment operator Red cut: removal of conditions cut-fail combination (see notes) single solution

Prolog Database The working environment of Prolog, containing all loaded Prolog programs is called: the database The database can be manipulated by the programs themselves Compare: Pascal program that modifies itself during execution

Prolog Database add new clauses Prolog Database parent(jim, bob). remove clauses pred(x,y) :- parent(x,y). pred(x,y) :- parent(x,z), pred(z,y).

Prolog Database assertz: add to the end of a definition assertz(parent(bob,ann)). Prolog Database parent(jim, bob). parent(bob,ann). pred(x,y) :- parent(x,y). pred(x,y) :- parent(x,z), pred(z,y).

Asserting Clauses Database collect_data(stop). collect_data(_) :- write( Next item: ), read(x), assertz(x), collect_data(x).?- input_data. Next item: name(peter). Next item: age(35). Next item: stop. input_data :- collect_data(start). name(peter). age(35). stop.

Database Manipulation Asserting (new) clauses: assert(c): position C unspecified asserta(c): at the beginning of the definition of the predicate assertz(c): at the end of the definition of the predicate Deleting clauses: retract(c): remove clause matching with C (top to bottom order)

Retracting Clauses retract: remove from the beginning of the of definition?- retract(parent(x,y)). X = jim Y = bob yes Prolog Database?- dynamic parent/2. parent(jim, bob). parent(bob,ann). parent(john,pete). parent(pete,linda).

Retracting Clauses?- retract_all_facts(parent(x,y)). yes?- dynamic parent/2. parent(jim, bob). parent(bob,ann). parent(john,pete). parent(pete,linda). Prolog Database retract_all_facts(x) :- retract(x), fail. retract_all_facts(_).