Every algebraic structure is built on a binary operation, so we begin by studying operations and the properties they may have.

Binary Operations

A binary operation on a set S is a rule that assigns to every ordered pair (a, b) of elements of S a unique element a b, which is also in S. The last condition is called closure: the result never leaves the set. Addition and multiplication are binary operations on the integers Z. Subtraction is a binary operation on Z but not on the natural numbers N, since 2 − 5 = −3 is not in N. Division is not a binary operation on Z, since 1 ÷ 2 is not an integer and division by 0 is not defined. On a finite set, an operation can be shown by a Cayley table (operation table), in which the entry in row a and column b is a * b.

Definition: Binary operation. A rule that combines any two elements a and b of a set S to give a unique element a * b that also belongs to S.

Properties of Operations

An operation on S is closed if a b ∈ S for all a, b ∈ S. It is associative if (a b) c = a (b c) for all a, b, c. It is commutative if a b = b a for all a, b. An element e is an identity if a e = e a = a for all a. For example, 0 is the identity for addition and 1 for multiplication. If an identity exists, an element b is an inverse of a if a b = b a = e. In Z under addition the inverse of a is −a. Under multiplication on the rationals other than 0, the inverse of a is 1/a.

Modular Arithmetic

Computers often work with arithmetic modulo n. The set Zn = {0, 1, …, n − 1} with addition modulo n, written +n, takes the remainder after division by n, so 4 +5 3 = 2. Multiplication modulo n, ×n, is defined in the same way. These operations are closed, associative and commutative. They are the basis of many examples in this unit, and of hashing, checksums and cryptography.

Table 2.1: Properties of common operations

Set and operation Closed Associative Commutative Identity
Z, + Yes Yes Yes 0
Z, − Yes No No None
N, × Yes Yes Yes 1
Matrices, × Yes Yes No I

Example 2.1: Testing an operation

Problem: On Z define a * b = a + b + 1. Test closure, associativity and commutativity, and find the identity and the inverse of a.

Solution:

  1. Closure: a + b + 1 is an integer, so * is closed.
  2. Associative: (a b) c = a + b + c + 2 = a (b c). Yes.
  3. Commutative: a + b + 1 = b + a + 1. Yes.
  4. Identity: a * e = a means a + e + 1 = a, so e = −1.
  5. Inverse: a * b = −1 means a + b + 1 = −1, so b = −2 − a.

Result: The identity is −1 and the inverse of a is −2 − a.

op = lambda a, b: a + b + 1
e = -1
print(all(op(a, e) == a for a in range(-5, 6)))
print([(a, -2 - a, op(a, -2 - a)) for a in (0, 3, -4)])

Output

True
[(0, -2, -1), (3, -5, -1), (-4, 2, -1)]

Common mistakes

  • Forgetting to check closure, which is part of the definition of a binary operation.
  • Taking 0 as the identity for every operation. The identity depends on the operation.
  • Assuming that every operation is commutative. Matrix multiplication is not.

Key takeaways

  • A binary operation on S gives a result in S for every pair.
  • The key properties are closure, associativity, commutativity, identity and inverse.
  • A Cayley table shows an operation on a finite set.
  • Addition and multiplication modulo n are closed on Zn.

Practice questions

  1. Is subtraction a binary operation on N?
  2. What is the identity for multiplication on the integers?
  3. Find 5 +7 4.

Answers to the practice questions

  1. No, since a − b may not be a natural number.
  2. (5 + 4) mod 7 = 2.

Sources

  • Official BCA syllabus Mathematics Foundations to Computer Science II, course code 25BCA402DS01, Unit II