Celtic Kane

What is conditional logic?

Conditional logic is where you use conditional keywords (AND, OR, NOT, XOR) to form an expression. Conditional keywords are used a lot in programming (especially flags), but that’s beyond the scope of this page. This page will show you what the keywords do and how to use them to simplify equations.

Conditional logic with numbers

The most basic conditional logic is when you are given two binary numbers and a conditional logic keyword. Here’s a brief description of each keyword:

AND

: AND returns true (1) when both numbers are 1 — if not, it will return false (0)

OR

: OR returns 1 if either number is a 1, if not, it will return false

NOT

: NOT uses only one number, and it simply reverses the value. If given a 1, it will return 0 and vice versa

XOR

: XOR (called exclusive or) will only return 1 if one value or the other value is true…if both are true, it will return false

A few examples of basic conditional logic

1 OR 0

Returns 1 because at least 1 value is 1

T AND F

Returns 0 (or false — it’s the same) because both values have to be true for AND

T XOR T

Returns 0 (or false — it’s the same) because both values are true, and with exclusive OR, it’s either one or the other is true…not both.

Truth Tables

Occationally you’ll be asked to simplify a logic expression, and sometimes the best way to do that is a truth table. Let’s say we have the expression (A OR B) OR NOT(A AND B). Now, A and B could both be true, one could be true, both could be false, etc. We don’t know. But the question may be something like what is the expression equivalent to, and you’ll be given choices. The first step is to make your truth table. Basically what you do is make a table where you write out every possible combination of A and B, then find the result of the equation. Here’s our truth table:

(A OR B) OR NOT(A AND B)
A B Result
1 1 1
0 0 1
1 0 1
0 1 1

For those that couldn’t figure out the result yourself, here’s my though process for each line. If A=1,B=1…(1 OR 1) OR NOT(1 AND 1). 1 OR 1 returns 1. That gives us 1 OR NOT(1 AND 1). I don’t even have to continue because we’re going to have 1 OR (some value), and with OR statements, if one value is 1 then it automatically returns 1. If A=0 and B=0, we have (0 OR 0) OR NOT(0 AND 0). 0 OR 0 returns 0, so we have 0 OR NOT(0 AND 0). 0 and 0 returns 0, so we have 0 OR NOT(0). NOT(0) returns 1, so we have 0 OR 1, which is 1. For the last two, we really only have to do the first part (A OR B) because in both cases, A OR B will return 1, and just like in the first one, we can stop there.

On a WYSE test they’ll ask you to simplify the expression and they’ll give you some choices. All you have to do is look at the RESULTS column and decide what works. In this case, we always returned TRUE or 1, so either one of those answers would be valid as a simplification because no matter what value combination you use for A and B, you’ll always get 1 or TRUE.

de Morgan’s Law

I’ve never taken a computer science class, so I can’t fully describe de Morgan’s law but I can try to simplify it based on what I’ve seen it do on WYSE testing. Basically de Morgan’s law deals with distributing NOT statements within expressions. Since I don’t know the extent, I’ll just show you some examples:

NOT(A AND B)

When you distribute the NOT, each item in the parenthesis are affected. AND’s become OR’s and OR’s become AND’s. So our final expression is: NOT(A) OR NOT(B)

NOT(A OR B)

Same thing…returns NOT(A) AND NOT(B)

Why is this important? Sometimes you’ll be asked to simplify expressions that are either too long or have too many variables to do a truth table — de Morgan’s takes up a lot less time than a truth table, so I almost always try to simplify with this first. Also, it may be easier to use de Morgan’s on an expression first to simplify it down, then use a truth table on the simplified expression.

A quick note about simplification

When you’re using de Morgan’s law or other forms of simplification, you’ll have stuff cancel out (which is why it’s considered simplified). For example, if you have A and NOT(A), it will always be false. Why? Well, you can do a truth table, or you can just use logic. If A is 1, NOT(A) will be 0 — there is no way for both A and NOT(A) to both be 1, so it will always be false. Similarly, A OR NOT(A) will always be true, because regardless of what value you use, one will be 1 and one will be 0, and OR statements return true if either value is true.

Conclusion

This is just the basics of conditional logic. It gets much more complicated but this will give you a firm base to work off of when you get to more complicated things. If you’ve got a graphing calculator, and you aren’t doing a WYSE test (calculators are not allowed on CS WYSE tests) you can use your calculator to speed up truth tables. All you have to do is set a value for A and B, and type in the expression in using the 2nd->LOGIC menu.


Previous: Octal and Hexidecimal
Next: Sorting