7

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?

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
QuietThud
  • 351
  • 1
  • 12

2 Answers2

4

It is what it said -- If is not Boolean, i.e. it returns not only true or false. Try If[False,True] and you'll see no result. If[a,b,c,d] can return any b, c and d, not only Boolean, for example If[True,2] returns 2. So, If is for branching (even being functional) while Implies is a normal Boolean function.

P.S. Ah, Implies also can return 2. So the difference is that If[False,True] returns nothing, so SatisfiabilityInstances function can't find true area.

P.P.S. More precisely, if the first argument of If[] is False then it returns it's third argument. When it is absent, it returns nothing.

Dims
  • 47,675
  • 117
  • 331
  • 600
  • Can you direct me to a good tutorial? I've read the Mathematica Documentation but wasn't aware that it's possible to give 'If' four values (only three for if-else). 'If[a,b,c,d]' returns 'd' without any truth values assigned--why is that? @Dims – QuietThud Oct 27 '12 at 05:01
  • @QuietThud `If[ condition, true clause, false clause, non-true-or-false-clause]` – Dr. belisarius Oct 27 '12 at 05:36
  • Thank you @belisarius. =) I'd appreciate a recommendation as far as a Math. programming learning source goes--the Documentation works better as a reference. – QuietThud Oct 27 '12 at 05:52
  • @QuietThud http://mathematica.stackexchange.com/questions/18/where-can-i-find-examples-of-good-mathematica-programming-practice – Dr. belisarius Oct 27 '12 at 05:58
3

You may try:

SatisfiabilityInstances[If[p, q, Not[q]], {p, q}, All]
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190