Data and processes in computing
Data and processes in computing

This free course is available to start right now. Review the full course description and key learning outcomes and create an account and enrol if you want a free statement of participation.

Free course

Data and processes in computing

5.2 Operations on Boolean values

The idea of a binary operation, and the use of infix notation, is not confined to numbers. Infix notation may be used for any process with two inputs from the same set. We look now at two binary operations on Boolean values that are often used.

The first of these takes two Boolean values, and returns true if both of the input values are true and returns false otherwise. It is a binary operation, and we shall write it using the infix notation ∧, where the symbol ∧ can be read as “and”. So ab is true only when a and b are both true. We can describe the function corresponding to this operation as below (The operation ∧ is also known as conjunction).

function (infix) (ab on Bool) return in Bool

pre   true.

post   The returned value is true if both a = true and b = true, and is false otherwise.

Alternatively, we could give the semantics of ∧ by listing the returned value in each of four cases, giving the four possible combinations of input values. Using this approach, we could express the postcondition as follows.

post The returned value is c, where

  • if a = true and b = true then c = true

  • if a = true and b = false then c = false

  • if a = false and b = true then c = false

  • if a = false and b = false then c = false.

A second binary operation on Boolean values returns true if either (or both) of the two Boolean values is true. We write this operation using the infix symbol ∨ , where ∧ can be read as “or”. The corresponding function is described below. The operation ∨ is also known as disjunction.

function (infix) (ab on Bool) return in Bool

pre   true.

post   The returned value is false if both a = false and b = false, and is true otherwise.

Activity 25

Give the semantics of ∨ by listing the returned value in each of four cases, giving the four possible combinations of input values.

Discussion

We can express the postcondition in the description above as follows.

post The returned value is c, where

  • if a = true and b = true then c = true

  • if a = true and b = false then c = true

  • if a = false and b = true then c = true

  • if a = false and b = false then c = false.

Another useful process on Boolean values inputs a single Boolean value, and returns the reverse of that value. This process, called negation, is not a binary operation, since it has one input only. We call this function NOT, and we have

NOT(false) = true, and NOT(true) = false.

Activity 26

  • (a) Give a full description of the function NOT.

  • (b) If a = true and b = false, evaluate each of:

    • (i) ab;

    • (ii) NOT(ab);

    • (iii) a ∧ (ab).

Discussion

(a) A description is given below.

function NOT(a in Bool) return in Bool

pre   true.

post   The returned value is false if a = true and is true if a = false.

(b) (i) Substituting for a and b, we have truefalse = true.

(ii) We should evaluate the term in brackets first: truefalse = true. Then NOT(true) = false. So NOT(ab) = false.

(iii) Again, evaluate the term in brackets first: (truefalse) = true. Then the given expression becomes truetrue which evaluates to true.

M263_1

Take your learning further

Making the decision to study can be a big step, which is why you'll want a trusted University. The Open University has 50 years’ experience delivering flexible learning and 170,000 students are studying with us right now. Take a look at all Open University courses.

If you are new to university level study, find out more about the types of qualifications we offer, including our entry level Access courses and Certificates.

Not ready for University study then browse over 900 free courses on OpenLearn and sign up to our newsletter to hear about new free courses as they are released.

Every year, thousands of students decide to study with The Open University. With over 120 qualifications, we’ve got the right course for you.

Request an Open University prospectus