evaluating basic logic statements

advertisement
EVALUATING BASIC LOGIC STATEMENTS & SYSTEM DESIGN
What is a Statement? – a meaningful, declarative sentence that can only be either true or false.
True = ON, HI, YES, CLOSED, NOT FALSE, any integer greater than 0
False = OFF, LO, NO, OPEN, NOT TRUE, zero
Examples of sentences that are (or make) statements:
STATEMENT




"Socrates is a man."
"A triangle has three sides."
"Paris is the capital of Spain."
x =6
EVALUATES AS:
TRUE
TRUE
FALSE
TRUE (only if there are 6 ‘x’s)
The first two (make statements that) are true, the third is (or makes a statement that is) false, the fourth is
an evaluative statement (assigns a value).
Examples of sentences that are not (or do not make) statements:






"Who are you?"
"Run!"
"Greenness walks slowly."
"I had one cucumber but the eggplant over there."
"The King of France is wise."
"Pegasus exists."
The first two examples are not declarative sentences and therefore are not (or do not make) statements.
The third and fourth are declarative sentences but, lacking meaning, are neither true nor false and
therefore are not (or do not make) statements. The fifth and sixth examples are meaningful declarative
sentences, but the fifth is neither true nor false since it does not make a statement.
EXPRESSIONS:
Evaluating logical statements always occurs by comparing 2 statements in an EXPRESSION:
AND – the expression evaluates to TRUE only if both statements are TRUE
OR – the expression evaluates to TRUE only if either statement is TRUE
NAND – the expression evaluates to TRUE only if neither statement is TRUE (This is called an inverse
statement)
NOR – the expression evaluates to TRUE only if neither statement is TRUE
NOT – the expression always evaluates as the OPPOSITE of the statement. This is not an evaluative or
comparative statement. It is called a LOGIC INVERTER.
TRUTH TABLE: Practically, a truth table is composed of one column for each input variable (for example,
A and B), and one final column for all of the possible results of the logical operation that the table is
meant to represent. Each row of the truth table contains one possible configuration of the input
variables (for instance, A=true B=false), and the result of the operation for those values.
AND, OR, NAND, NOR and NOT are called LOGICAL OPERATORS
AND
INPUT
A
B
0
0
1
0
0
1
1
1
OR
OUTPUT
A AND B
0
0
0
1
NOR
INPUT
A
B
0
0
1
0
0
1
1
1
NAND
INPUT
A
B
0
0
1
0
0
1
1
1
OUTPUT
A AND B
0
1
1
1
INPUT
A
B
0
0
1
0
0
1
1
1
OUTPUT
A AND B
1
0
0
0
NOT
OUTPUT
A AND B
1
0
0
0
INPUT
A
0
1
OUTPUT
A
1
0
ROBOT…OR NOT?
Using the logical statements defined above, construct an evaluative expression to represent the function
of each of the examples below:
VENDING MACHINE -
$2 coin has been inserted AND a $2 product is selected = 2$ product dispensed
no coin has been inserted AND a $2 product is selected = no product dispensed
2$ coin has been inserted AND no product is selected = no product dispensed
No coin has been inserted AND no product is selected = no product dispensed
AUTOMATIC DOOR RADIO-CONTROLLED CAR –
ELECTRICAL CIRCUIT –
A
B
CONDITIONAL EXPRESSIONS
The expressions you wrote above are called CONDITIONAL expressions. This means that the conditions
in the statement must be either TRUE or FALSE (depending on the expression) in order for the condition
to be evaluated as either TRUE or FALSE.
Conditional expressions are always written as
IF (STATEMENT A) LOGICAL OPERATOR (STATEMENT B) THEN (OUTPUT)
REMEMBER: Statement A and Statement B can only be evaluated to TRUE or FALSE and the
OUTPUT will only evaluate to TRUE or FALSE, depending on the operator.
For example:
An electrical circuit that includes 2 switches:
INPUT
OUTPUT
A
IF (A=ON AND B=ON) THEN OUTPUT=ON
B
Download