Question

How do I translate the following argument into Prolog? It seems like it doesn't need predicates. (Note: I use & for a conjunction and | for a disjunction.)

G -> (H & J)

(H | J) -> S

S | R

Ⱶ G -> R

Also, how would I consult the Prolog database to determine that (G -> R) is false and the argument is therefore invalid? It has been a while.

(Yes, this is for homework. The professor asked us to prove the argument, but it is not valid if G, H, J, and S are true and R is false.)

Edit:

Based on Daniel's answer, I've written this:

boolean(true).
boolean(fail).
argument(G, H, J, R, S) :-
    boolean(G),
    boolean(H),
    boolean(J),
    boolean(R),
    boolean(S),
    (G -> R) ->
    (G -> (H , J)),
    ((H ; J) -> S),
    (S ; R).

But when I run it, I get this:

?- argument(G, H, J, R, S).
G = H, H = J, J = R, R = S, S = true.

How can I get it to show the fail case?

Edit #2:

Now I have this:

boolean(true).
boolean(false).
argument(G, H, J, R, S) :-
    boolean(G), boolean(H), boolean(J), boolean(R), boolean(S),
    (((G -> R); true) ->
    ((G -> (H , J); true),
    ((H ; J) -> S; true),
    (S ; R))); true.

It goes through all the successful cases, like you would expect Prolog to do, but I really want it to also show when the argument is invalid, i.e. when the predicate fails. I don't know how to do this.

Was it helpful?

Solution

In Prolog, conjunction is , and disjunction is ;. Implication is still just -> but the precedence isn't always intuitive so we tend to wrap implied cases in parentheses. So your first three cases are just:

G -> (H, J).
(H ; J) -> S.
S ; R.

I'm not sure what Ⱶ adds here, but if I were guessing I'd be inclined to translate this argument as:

(G -> R) :-
  G -> (H, J),
  (H ; J) -> S,
  (S ; R).

Since these are all Prolog variables this won't execute though. Prolog will need to be told what domains H, J and S belong to, at the very least.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top