I am new to Mathematica(v8) and am using it to program propositional logic.
I’m wondering what the difference is between the If and the Implies operators. For example,
both If[p,q] and Implies[p,q] return q for p=True (as expected).
But when I try to obtain SatisfiabilityInstances, I get the following:
SatisfiabilityInstances[If[p, q], {p, q}]
(*
{{True, True}}
*)
unless I ask it for more instances:
SatisfiabilityInstances[If[p, q], {p, q}, All]
SatisfiabilityInstances::boolv: “If[p,q] is not Boolean valued at {False,True}.
However:
SatisfiabilityInstances[Implies[p, q], {p, q}, All]
returns the expected out of:
(* {{True, True}, {False, True}, {False, False}} *)
What is causing this difference in the outputs?
It is what it said —
Ifis not Boolean, i.e. it returns not only true or false. TryIf[False,True]and you’ll see no result.If[a,b,c,d]can return any b, c and d, not only Boolean, for exampleIf[True,2]returns 2. So,Ifis for branching (even being functional) whileImpliesis a normal Boolean function.P.S. Ah,
Impliesalso can return2. So the difference is thatIf[False,True]returns nothing, soSatisfiabilityInstancesfunction can’t find true area.P.P.S. More precisely, if the first argument of
If[]isFalsethen it returns it’s third argument. When it is absent, it returns nothing.