So, I have this program that (using TKEclipse) allows me to query boolean expressions and answers with "Yes" or "No", depending on if the statement is true:
:-op(450,yfx,and).
:-op(500,yfx,or).
:-op(500,yfx,nor).
:-op(450,yfx,nand).
:-op(500,yfx,xor).
:-op(400,fy,--).
:-op(600,xfx,==>).
--Arg1:-not(Arg1).
Arg1 ==> Arg2 :- --Arg1 or Arg2.
Arg1 and Arg2 :- Arg1, Arg2.
Arg1 or _Arg2 :- Arg1.
_Arg1 or Arg2 :-Arg2.
Arg1 xor Arg2 :- Arg1, --Arg2.
Arg1 xor Arg2 :- --Arg1, Arg2.
Arg1 nor Arg2 :- --(Arg1 or Arg2).
Arg1 nand Arg2 :- --(Arg1 and Arg2).
t.
f:-!,fail.
For example:
Q:t and t
A:Yes
Q:t and f
A:No
Now I want to make the program accept variables using the predicate "bool_solve(Expr)". For example:
Q:bool_solve(X and t)
A:X = t
Yes
Q:bool_solve(X and Y)
A:X = t
Y = t
Yes
Q:bool_solve(X or Y)
A:X = t
Y = t
Yes
'more'
A:X = t
Y = f
Yes
'more'
A:X = f
Y = t
Yes
'more'
No
I know how to replace the variables with a specific value (like t) using this code:
bool_solve(Expr):-
term_variables(Expr,Vars),
findall(X,X=t, Vars).
term_variables is built-in and finds all the variables in an expression. I know how to unify with the result of the findall with the Expr variables, but I cannot evaluate the Expr. I tried calling it, but it does not work (failed instantiation).
TL;DR: I want to replace the "Goal" (X=t) of the findall predicate so that it evaluates the Expr, replacing all the variables with t or f.
Thank you in advance.