Sinclair QL Beginner's Manual page 67

Hide thumbs Also See for QL:
Table of Contents

Advertisement

NOT (red AND square)
then for a red triangle the whole expression is true. There must be a rule in programming to make it
clear what is meant. The rule is that NOT takes precedence over AND so the interpretation:
(NOT red) AND square
is the correct one This is the same as:
NOT red AND square
To get the other interpretation you must use brackets. If you need to use a complex logical expression
it is best to use brackets and NOT if their usage naturally reflects what you want. But you can if you
wish always remove brackets by using the following laws (attributed to Augustus De Morgan)
NOT (a AND b)
NOT (a OR b)
For example:
Test this by entering
100 REMark NOT and brackets
110 PRINT "Enter two values"\"1 for TRUE or 0 for FALSE"
120 INPUT "tall "; tall
130 INPUT "fair "; fair
140 IF NOT (tall AND fair) THEN PRINT "FIRST"
150 IF NOT tall OR NOT fair THEN PRINT "SECOND"
Whatever combination of numbers you give as input, the output will always be either two words or
none, never one. This will suggest that the two compound logical expressions are equivalent.
XOR-Exclusive OR
Suppose a golf professional wanted an assistant who could either run the shop or give golf lessons. If
an applicant turned up with both abilities he might not get the job because the golf professional might
fear that such an able assistant would try to take over. He would accept a good golfer who could not
run the shop. He would also accept a poor golfer who could run the shop. This is an exclusive OR
situation: either is acceptable but not both. The following program would test applicants:
100 REMark XOR test
110 PRINT "Enter 1 for yes or 0 for no."
120 INPUT "Can you run a shop?", shop
130 INPUT "Can you teach golf?", golf
140 IF shop XOR golf THEN PRINT "Suitable"
The only combinations of answers that will cause the output "Suitable" are (0 and 1) or
(1 and 0). The rules for XOR are given below.
Able to run shop
FALSE
FALSE
TRUE
TRUE
NOT a OR NOT b
is the same as
NOT a AND NOT b
is the same as
NOT (tall AND fair) is the same as
NOT tall OR NOT fair
NOT (hungry OR thirsty) is the same as
NOT hungry AND NOT thirsty
Able to teach
FALSE
TRUE
FALSE
TRUE
Shop XOR teach
FALSE
TRUE
TRUE
FALSE
effect
No job
Gets the job
Gets the job
No job

Advertisement

Table of Contents
loading

Table of Contents