prolog# Homework, want to solve with Prolog

Can I solve the homework for my logic class with Prolog?

```
5 people are interrogated. The statements from A and B are lost.
C says: If A is truthful then B is truthful.
D says: If C is truthful then A is truthful.
E says: If D is truthful then A is truthful.
1) Is it possible that C lies?
2) Is it possible that D lies?
3) Is it possible that E lies?
```

My latest attempt was

```
f(A, B, C, D, E):-
(C->(A->B)),
(D->(C->A)),
(E->(A->D)).
```

This compiles, but when I query Prolog with

```
f(A, B, C, D, E).
```

I get the error "Arguments are not sufficiently instantiated".

Solution

Can model with:

```
stat(truth).
stat(lies).
go(A, B, C, D, E) :-
maplist(stat, [A, B, C, D, E]),
stat_if(C, A, B),
stat_if(D, C, A),
stat_if(E, D, A).
stat_if(truth, A, B) :-
implies(A, B).
stat_if(lies, A, B) :-
\+ implies(A, B).
implies(truth, truth).
% If lying, cannot determine
implies(lies, _).
```

Then run with e.g.:

```
?- go(A, B, C, D, truth).
A = B, B = C, C = D, D = truth ;
A = D, D = truth,
B = C, C = lies ;
A = D, D = lies,
B = C, C = truth ;
A = B, B = D, D = lies,
C = truth ;
false.
?- go(A, B, C, D, lies).
false.
```

- Find the divisors of a number using Prolog by using recursion
- Prolog type definition in swi-prolog
- In SWI-Prolog, how can I find a solution that maximises or minimises some atom?
- Making prolog predicates deterministic
- Up-to-date Prolog implementation benchmarks?
- Creating a list of interleaved elements: Prolog
- What are the (perceived) shortcomings of the ISO standard for Prolog modules (ISO/IEC 13211-2)?
- Are HiLog terms still useful in modern Prolog?
- Prolog - replacing list elements
- Trouble obtaining a specific answer to a query in Prolog
- Prolog lists: combination of comma and |
- Solving a logical puzzle with Prolog gives a wrong answer
- How to identify valid bodies and convertible terms
- Find all subsequences of a list that cover the whole list in prolog
- How to flatten nested Prolog statements into a plain Horn clause
- Solving Caliban problems with prolog
- Why is there an error for the query: "query(member(one, [one,two,three]))." in Problog?
- PROLOG Make a list of words from big text file
- CLP(FD): solution number count speedup
- Why do i get : uncaught exception: error(existence_error(procedure,foggy/0),top_level/0)?
- Prolog falls into an infinite loop
- Problem with insert function into an organized list in Prolog
- Prolog Predicate for positive and negative integers
- Understanding recursive rules in Prolog
- How to collect maximal non-overlapping ascending/descending prefixes of a random sequence of numbers
- Prolog - first list is sublist of second list?
- Prolog: X is the grandfather of Y
- Why does this Prolog program not terminate?
- Blocks-World Problem in Prolog keeps oscillating between the same two states
- Moving elements in a list-of-lists in prolog