Powers#
Powers are a way to write that we have multiplied a number by itself a given number of times. For example 4 squared is \(4^2 = 4 \times 4\) and 5 cubed would be \(5^3 = 5 \times 5 \times 5\). So more generally, for any positive whole number \(n\):
We call \(x\) the base.
We call \(n\) the index of the base or its power.
We would either say \(x^n\) as ‘\(x\) raised to the power of \(n\)’, ‘\(x\) to the power of \(n\)’ or ‘\(x\) to the \(n\)’.
Example
We can write \(T \times T \times T \times T \times T\) as \(T^5\). (Note that \(T\) is the base and the power is 5).
Example
When a negative number is raised to an even power then the answer is positive:
In Python, powers are represented using **
.
(-2)**4
16
Negative Powers#
We can also have negative numbers as powers, these give fractions called reciprocals. For example \(2^{−1} = \frac{1}{2}\). So more generally:
Example
We can write \(\frac{1}{qqqqqq}\) as \(\frac{1}{q^6}\), which is the same as \(q^{-6}\).
from sympy import symbols
q = symbols('q')
1/(q*q*q*q*q*q) == q**(-6)
True
We can simplify multiple terms like in the examples below by collecting together the terms which are the same.
Example
We can simplify \(cccdcd\) to \(c^4d^2\). (Note that we have collected all the c and d together separately)
c, d = symbols('c d')
c*c*c*d*c*d == c**4*d**2
True
Example
We can simplify \(\frac{xxyzzzz}{abbb}\) to \(\frac{x^2yz^4}{ab^3}\), which we can then write as \(x^2yz^4a^{-1}b^{-3}\).
Special Cases#
Any non zero number raised to the power of 1 is itself, for example \(3^1 = 3\) and \(15^1 = 15\). So we have:
If a number is rasied to the power of 0 then the answer is 1. For example \(4^0 = 1\) and \((−454.786)^0 = 1\). So we have:
x = symbols('x')
x**0
Rules for Powers#
We have the following three rules for when working with powers:
\(x^a \times x^b = x^{a+b}\)
\(\frac{x^a}{x^b} = x^{a-b}\)
\((x^a)^b = x^{a\times b}\)
Example
We can simplify \(\frac{y^3z^2y^4}{z^6}\) to \(y^{3+4}z^{2-6}\), which we can then write as \(y^7z^{-4}\) (we have used rules 1 and 2 here).
from sympy import simplify
x,y,z = symbols('x y z')
simplify(y**3*z**2*y**4/z**6)
Example
We can simplify \((a^3b^2ca)^2\) to \((a^4b^2c)^2\) to \((a^4)^2(b^2)^2(c)^2\), which we can then write as \(a^8b^4c^2\) using rule 3.
a,b,c = symbols('a b c')
simplify((a**3*b**2*c*a)**2)
Roots#
The opposite of squaring a number, say \(4^2 = 16\), is finding the square root, in this case \(\sqrt{16} = 4\). Note the notation for square root is \(\sqrt{}\). The same is true for cubing and cube roots which are denoted \(\sqrt[3]{}\); for example \(3 \times 3 \times 3 = 27\), so \(\sqrt[3]{27} = 3\). In general the opposite of raising a number \(x\) to the power of \(n\) is to find the \(n^\text{th}\) root, which is denoted \(\sqrt[n]{}\).
We also use fractional powers as another, often more useful way, to write roots. So we have that \(\sqrt{x} = x^\frac{1}{2}\) and \(\sqrt[3]{x} = x^\frac{1}{3}\). More generally we have:
Example
A numerical example: since \(\sqrt[5]{32} = 2\) we could also write \(32^\frac{1}{5}\) = 2
32**(1/5)
2.0
Example
We can write \(\frac{\sqrt{x}}{x} = \frac{x^\frac{1}{2}}{x} = x^{\frac{1}{2}-1}=x^{-\frac{1}{2}}\).
simplify(x**(1/2)/x)
Example
Simplify the following:
Solution: We begin by expanding the brackets in the numerator:
Sometimes, sympy
is not able to find the best simplification.
This is noted in the sympy
documention.
simplify((a*b**3)**(1/3)*(a*c**4)**2/(a**(4/3)*b))