Next: Changing the Program Up: A Special Control Previous: Make Determinate

## Fail Goal Now

We are trying to solve the problem that arises when we realise, in the middle of satisfying subgoals for some goal, that the goal will never succeed ---even if we try other clauses which have heads that unify with the goal.

Here is a way of defining woman/1 in terms of man/1 where we base the idea that, in trying to establish that someone is a ``woman'', we prove that they are actually a ``man'' and there is therefore no point in trying to find some other proof that this person is a woman.

```
woman(X):-

man(X),

,

fail.

woman(X).
[-5pt]

```
Putting it a slightly different way, to solve for woman(jim) we try man(jim). If that succeeds then we want to abandon the attempt to prove woman(jim) without trying any other clauses for woman/1.

Note that the use of the cut ( !/0) stops any attempt to resatisfy man/1 once backtracking is forced through fail/1 failing. Note also that the second clause for woman/1 will not be used after the cut---fail combination has been met.

We call this use of cut in conjunction with fail/0 the cut---fail technique.

The above code for woman/1 is a special case of Prolog's implementation of negation as failure. Here is a possible definition of `\+`/1 using cut ( !/0) and call/1.

```
`\+`(Goal):-

call(Goal),

!,

fail.

`\+`(Goal).

```

Paul Brna
Mon May 24 20:14:48 BST 1999