CSc 372 - Comparative Programming Languages
22 : Prolog -- Negation

Christian Collberg

Department of Computer Science

University of Arizona


The Cut


1 Cuts & Negation

The cut (!) is is ued to affect Prolog's backtracking. It can be used to

2 Cuts & Negation

3 The Cut

The cut succeeds and commits Prolog to all the choices made since the parent goal was called.

Cut does two things:

commit:
Don't consider any later clauses for this goal.
prune:
Throw away alternative solutions to the left of the cut.

4 The Cut

Cut1

5 The Cut

Cut2


The Boxflow Model


6 The Boxflow Model

Boxflow1

7 The Boxflow Model

Boxflow2

8 The Cut

Boxflow-Cut


Classifying Cuts


9 Classifying Cuts

grue
No effect on logic, improves efficiency.
green
Prune away
  • irrelevant proofs
  • proofs which are bound to fail
blue
Prune away
  • proofs a smart Prolog implementation would not try, but a dumb one might.
red
Remove unwanted logical solutions.

10 Green Cuts - Merge

Produce an ordered list of integers from two ordered lists of integers.


1#1

11 Green Cuts - Merge

Merge1

12 Green Cuts

13 Green Cuts - Merge


2#2

14 Green Cuts - Merge

Merge2

15 Red Cuts - Abs


3#3

16 Red Cuts - Abs


4#4

17 Red Cuts - Intersection

Find the intersection of two lists A & B, i.e. all elements of A which are also in B.


5#5

18 Red Cuts - Intersection


6#6

19 Red Cuts - Intersection

Intersect1

20 Red Cuts - Intersection

Intersect2

21 Red Cuts - Intersection

Intersect3

22 Red Cuts - Intersection


7#7

23 Red Cuts - Intersection

Intersect4

24 Blue Cuts

First clause indexing will select the right clause in constant time:

8#8
First clause indexing will select the right clause in linear time:

9#9

25 Blue Cuts


10#10

26 Red Cuts - Once


11#11

27 Red Cuts - Once

Red cuts prune away logical solutions. A clause with a red cut has no logical reading.


12#12

28 Red Cuts - Abs


13#13

29 IF-THEN-ELSE


14#14


15#15

30 IF-THEN-ELSE


16#16


Negation


31 Open vs. Closed World

How should we handle negative information?

Open World Assumption:

If a clause P is not currently asserted then P is neither true nor false.

Closed World Assumption:

If a clause P is not currently asserted then the negation of P is currently asserted.

32 Open vs. Closed World


17#17

Open World Assumption:

Dahlin, Thern, and Andersson are strikers, but there may be others we don't know about.

Closed World Assumption:

X is a striker if and only if X is one of Dahlin, Thern, and Andersson.

33 Negation in Prolog


18#18

34 Prolog Execution - Not

35 Prolog Execution - Not

Boxflow-Not

36 Negation Example - Disjoint

Do the lists X & Y not have any elements in common?


21#21

37 Prolog Negation Problems


22#22

38 Prolog Negation Problems


23#23

39 Prolog Negation Problems


24#24

40 Open World Assumption

We can program the open world assumption:
25#25

41 Open World Assumption


26#26

42 Open World Assumption


27#27



Christian Collberg 2008-10-21