Addition, Subtraction, Multiplication and Division#

We will all be familiar with the following operations: addition (+), subtraction (−), multiplication (×) and division (÷) but for the sake of completeness we will review some simple rules and conventions.

Operator

Mathematical Representation

Pythonic Representation

Ordering

Addition

\(A + B\)

A + B

\(A + B = B + A\)

Subtraction

\(A - B\)

A - B

\(A - B \neq B - A\)

Multiplication

\(A \times B\)

A * B

\(A \times B = B \times A\)

Division

\(A \div B\)

A / B

\(A \div B \neq B \div A\)

Addition and Multiplication are Distributive#

For numbers \(x\), \(y\) and \(a\) the distributive rule for addition and multiplication is:

\[ a \times (x + y) = (a \times x) + (a \times y) \]

Example

For example, support we have \(x = 3\), \(y = 5\) and \(a=6\) then:

  1. \( a \times (x + y) = 6 \times (3 + 5) = 6 \times 8 = 48 \)

  2. \((a \times x) + (a \times y) = (6 \times 3) + (6 \times 5) = 18 + 30 = 48\)

So \(a \times (x + y) = (a \times x) + (a \times y)\) and the distributive rule holds.


We show this with Python code below.

x = 3
y = 5 
a = 6
a * (x + y)
48
(a * x) + (a * y)
48

Factorisation#

Factorisation is used to tidy up equations in order to make them easier to read and understand.

Example

We can factorise the equation \(y = 8x + 12\) if we note that both \(8x\) and \(12\) are divisible by \(4\), this gives us \(y = 4(2x + 3)\).


Again, we can see that these are equivalent with Python.

8 * x + 12 == 4 * (2 * x + 3)
True

Example

We can factorise the equation \(y = 3x^2 + 6x\) if we note that both \(3x^3\) and \(6x\) are divisble by \(3x^3\) this gives us, \(y=3x(x^2 + 2)\).


3 * x ** 3 + 6 * x == 3 * x * (x ** 2 + 2)
True

Multiplying Out Terms#

Multiplying out terms (or expanding out brackets) makes use of the distributive law to remove brackets from an equation and is the opposite of factorisation.

Example

We can multiply out \(y = 5(x + 3)\) to give \(y = (5 \times x) + (5 \times 3) = 5x + 15\).


5 * (x + 3) == 5 * x + 15
True

Example

We can multiply out the equation \(y = 3z(2x^4 + 7)\) to give:

\[ y = (3z\times 2x^4) + (3z \times 7) = 6zx^4 + 21z \]

z = 2

3 * z * (2 * x ** 4 + 7) == 6 * z * x ** 4 + 21 * z
True

Example

We can multiply out the equation \(y = 3a[(a + 3b) - 5(2b-a)]\) to give:

\[\begin{split} \begin{aligned} y & = 3a [(a + 3b) - (5 \times 2b - 5 \times a)] = 3a [(a + 3b) - (10b - 5a)] \\ & = 3a (6a - 7b) = 18a^2 - 21ab \end{aligned} \end{split}\]

a = 2
b = 8

3 * a * ((a + 3 * b) - 5 * (2 * b - a)) == 18 * a ** 2 - 21 * a * b
True

Adding and Subtracting Negative Numbers#

  1. Adding a negative number is like subtracting a positive number.

  2. Subtracting a negative number is like adding a positive number.

Example

Suppose we have \(x=4\) and \(y = -3\).

\[\begin{split} \begin{aligned} x + y = 4 + (-3) = 4 - 3 = 1 \\ x - y = 4 - (-3) = 4 + 3 = 7 \end{aligned} \end{split}\]

x = 4 
y = -3
x + y
1
x - y
7

Order of Operations: BODMAS#

Consider the calculation below:

\[ 6 + (7 \times 3 ^ 2 + 1) \]

In what order should we calculate our operations? BODMAS tells us that we should carry out the operations in the order listed below:

  1. First Brackets.

  2. Then Orders (this is powers and roots).

  3. Then Division.

  4. Then Multiplication.

  5. Then Addition.

  6. Then Subtraction.

Example

So returning back to \(6 + (7 \times 3 ^ 2 + 1)\):

  • Start inside the Brackets and do the Orders first: \(6 + (7 \times 9 + 1)\)

  • Then Mulitply the 7 and 9: \(6 + (63 + 1)\)

  • Then Add the 63 and 1: \(6 + (64)\)

  • Brackets are done so the last operation is to Add the 6 and 64: \(70\)


Python naturally follows BODMAS.

6 + (7 * 3 ** 2 + 1)
70

Chemistry Examples#

Molecular Mass

Calculate the molecular mass of CuSO4·5H2O (hydrated copper sulphate).

Solution: The molar mass of the elements are as follows:

  • Cu: 64 amu

  • S: 32 amu

  • O: 16 amu

  • H: 1 amu

So we compute the molecular mass as:

\[\begin{split} \begin{aligned} \textrm{Mass of CuSO}_4\cdot5\textrm{H}_2\textrm{O} & = 64 + 32 + (16 \times 4) + 5 \times ((1 \times 2) + 16) \\ & = 64 + 32 + 64 + 5 \times (2 + 16) \\ & = 64 + 32 + 64 + 5 \times 18 \\ & = 64 + 32 + 64 + 90 \\ & = 250 \end{aligned} \end{split}\]

In Python, this would look like

Cu = 64 
S = 32 
O = 16
H = 1

Cu + S + O * 4 + 5 * (H * 2 + O)
250

Van der Waals Equation

Below is the van der Waals equation:

\[ \left(p + \frac{an^2}{V^2}\right)(V-nb) = nRT \]

which relates the pressure \(p\), the volume \(V\) and the absolute temperature \(T\) of an amount \(n\) of a gas where \(a\) and \(b\) are constants.

Suppose we have 1.0 mol of argon gas occupying a volume of 25×10-3 m3 at a pressure of 1.0×105 Pa and \(a\) is 0.10 Pa m6mol-2 and \(b\) is 4.0×10-5 m3mol-1. Calculate the left hand side of the equation.

Solution: Using BODMAS, we start with the brackets. In this question, we have two sets of brackets so starting with the first.

  • We begin with the first of them on the left side by substituting the values from the question: \(\left(p + \frac{an^2}{V^2}\right) = \left(1 \times 10^5 + \frac{0.1 \times 1^2}{(25\times 10^{-3})^2}\right)\)

  • Do the orders: \(\left(p + \frac{an^2}{V^2}\right) = \left(1 \times 10^5 + \frac{0.1 \times 1}{625\times10^{-6}}\right)\)

  • The Divide and Multiply: \(\left(p + \frac{an^2}{V^2}\right) = (1\times 10^5 + 160)\)

  • The finally Add: \(\left(p + \frac{an^2}{V^2}\right) = 1.0016\times 10^5\)

We now calculate the second bracket.

  • First substitute the values from the question: \((V-nb) = (25\times10^{-3} - 1 \times 4 \times 10^{-5})\)

  • Then Multiply: \((V-nb) = (25\times10^{-3} - 4 \times 10^{-5})\)

  • Then Subtract: \((V-nb) = 2.496\times 10^{-2}\)

Finally, as both brackets have been calculated, we can find their product.

\[ \left(p + \frac{an^2}{V^2}\right)(V-nb) = 1.0016\times 10^5 \times 2.496\times 10^{-2} = 2.5\times10^3 \textrm{ Pa m}^3 \]

to 2 significant figures.


This can be computed easily with Python.

n = 1.0
V = 25e-3
p  = 1e5

a = 0.1
b = 4.0e-5

(p + (a * n ** 2) / (V ** 2)) * (V - n * b)
2499.9936000000002