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.
boolean(G), ...
line into a separate predicate, thenwrite/1
their values out before enteringargument/5
, and then write yes or no depending on whether it succeeds. You could also at that point say\+ argument(...
which negates the call. – Daniel Lyons