0
$\begingroup$

So I'm trying to write out a logical expression and a truth table for the function: if s then p else q.

The problem I'm having is I don't know how to represent that function in logic. I mean I know in most programming languages the code would look something like this ---> if s ? p : q. In other words if s output p otherwise output q. But how would that look in logic? I tried to come up with a truth table first but I'm not sure how to do that without the logical expression.

Thanks in advance!

$\endgroup$
  • $\begingroup$ Do you know a logic operator for "if s then p"? $\endgroup$ – Dre Oct 9 '13 at 16:18
  • 1
    $\begingroup$ @Dre Wouldn't it be s -> p $\endgroup$ – TheDifficultyOfAlgortihms Oct 9 '13 at 16:22
  • $\begingroup$ What about (s ⟹ p) ^ (¬s ⟹ q) ? $\endgroup$ – Adam Oct 9 '13 at 17:38
2
$\begingroup$

In your truth table, make 7 columns S, P, Q, $\lnot S$, S and P, $\lnot S$ and Q, and finally (S and P) or ($\lnot$ S and Q)

The last column corresponds to what you want:

(S and P) OR ($\lnot$ S and Q)

$\endgroup$
  • $\begingroup$ Just wondering why do I need two S columns? Wouldn't it be 6 rows? Thank you for the help. $\endgroup$ – TheDifficultyOfAlgortihms Oct 9 '13 at 16:40
  • 1
    $\begingroup$ Only one S column, the other is "not S" $\endgroup$ – MathStudent Oct 9 '13 at 16:40
  • $\begingroup$ @David you need to use \lnot, not \not in LaTeX notation to get the correct symbol $\endgroup$ – Dre Oct 9 '13 at 16:41
  • $\begingroup$ Oh, I see. Ok thank you. $\endgroup$ – TheDifficultyOfAlgortihms Oct 9 '13 at 16:42
0
$\begingroup$

Hint: You know that "if s then p" is $s \implies p$, can you think of a way to combine that and elementary logical operators to get "if s then p else q"

$\endgroup$
  • $\begingroup$ See I'm not quite sure how to represent that for some reason. I think it may be something like: (s -> p) OR (s -> q). Or it could be (s -> p) OR q. Or using De Morgan's law s -> p can be rewritten as (-s OR p) and then I'm assuming it is (-s OR P) OR Q. But I think I'm approaching this wrong. $\endgroup$ – TheDifficultyOfAlgortihms Oct 9 '13 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.