# Logical Expression and truth table

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.

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

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)

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

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"

• 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. – TheDifficultyOfAlgortihms Oct 9 '13 at 16:33