The Blog of Random

Po-Shen Loh Quadratic Method

I found out about the Po-Shen Loh method of solving quadratic equations a few years ago, and I’ve been meaning to write a post about it since, and only just got around to it.

You can read the original blog post by Dr Loh, which goes into the math behind the method. I’ll cover some of that math here too, as well as a code implementation of the method.

Method

Say we start with a quadratic equation:

π‘₯2+𝑏π‘₯+𝑐=0

where π‘Ž, 𝑏 and 𝑐 are real numbers. We want to factorise this into the form:

(π‘₯βˆ’π‘Ÿ1)(π‘₯βˆ’π‘Ÿ2)=0

where π‘Ÿ1 and π‘Ÿ2 are also real numbers, known as the roots of the quadratic. These are essentially points where, if the equation was plotted, the graph would cross the π‘₯-axis.

The standard method for solving quadratics is using a formula that we’ve all learned in school:

π‘₯=βˆ’π‘Β±π‘2βˆ’4π‘Žπ‘2π‘Ž

which gives us two values for π‘₯, where plugging them into the original quadratic equation would give us 0. These are the two roots, π‘Ÿ1 and π‘Ÿ2.

However, let’s try expanding our factorised equation back into the quadratic form:

(π‘₯βˆ’π‘Ÿ1)(π‘₯βˆ’π‘Ÿ2)=0π‘₯2βˆ’π‘Ÿ2π‘₯βˆ’π‘Ÿ1π‘₯+π‘Ÿ1π‘Ÿ2=0π‘₯2βˆ’(π‘Ÿ1+π‘Ÿ2)π‘₯+π‘Ÿ1π‘Ÿ2=0

We can see that βˆ’π‘=π‘Ÿ1+π‘Ÿ2 and 𝑐=π‘Ÿ1π‘Ÿ2. Now, we could try to guess which values for π‘Ÿ1 and π‘Ÿ2 fit for these constraints, which works for some simple quadratic equations with integer roots, but gets complicated to do for non-integer roots.

Instead, we can realise that π‘Ÿ1,π‘Ÿ2=βˆ’π‘2±𝑒 for some real number 𝑒. This is basically like saying that since π‘Ÿ1 and π‘Ÿ2 add up to βˆ’π‘, βˆ’π‘2 must be exactly in between them, and we can simply add or subtract a value 𝑒 to get to π‘Ÿ1 and π‘Ÿ2. For example, if we have π‘Ÿ1=3 and π‘Ÿ2=5, then βˆ’π‘=π‘Ÿ1+π‘Ÿ2=3+5=8. From this, we can see that βˆ’π‘2=4, and we can simply add and subtract 𝑒=1 to get back π‘Ÿ1=3 and π‘Ÿ2=5.

Next, we can see that 𝑐=π‘Ÿ1π‘Ÿ2. Since we already know that π‘Ÿ1=βˆ’π‘2+𝑒 and π‘Ÿ2=βˆ’π‘2βˆ’π‘’, we can simply multiply them together to get 𝑐:

𝑐=π‘Ÿ1π‘Ÿ2=(βˆ’π‘2+𝑒)(βˆ’π‘2βˆ’π‘’)=𝑏24βˆ’π‘’2

The third line leads from (π‘Ž+𝑏)(π‘Žβˆ’π‘)=π‘Ž2βˆ’π‘2. Since the values of 𝑏 and 𝑐 are already known from the original quadratic equation, we can simply rearrange this equation to get the value of 𝑒:

𝑐=𝑏24βˆ’π‘’2𝑒2=𝑏24βˆ’π‘π‘’=𝑏24βˆ’π‘

Finally, we can plug in this value into our previous equations for π‘Ÿ1 and π‘Ÿ2:

π‘Ÿ1=βˆ’π‘2+𝑏24βˆ’π‘π‘Ÿ2=βˆ’π‘2βˆ’π‘24βˆ’π‘

Now you might be thinking, β€œwell this is all great, but what if we have a coefficient in front of the π‘₯2 term?”. Great question, let’s see what happens! We start with:

π‘Žπ‘₯2+𝑏π‘₯+𝑐=0

where, again, π‘Ž, 𝑏 and 𝑐 are all real numbers. All we need to do to apply our previous method is to divide the entire equation by π‘Ž:

π‘₯2+π‘π‘Žπ‘₯+π‘π‘Ž=0

If we plug in our new values of 𝑏′=π‘π‘Ž and 𝑐′=π‘π‘Ž into the equation for our roots from earlier, we get:

π‘Ÿ1=βˆ’π‘β€²2+(𝑏′)24βˆ’π‘β€²=βˆ’π‘2π‘Ž+𝑏24π‘Ž2βˆ’π‘π‘Ž=βˆ’π‘2π‘Ž+𝑏2βˆ’4π‘Žπ‘4π‘Ž2=βˆ’π‘2π‘Ž+𝑏2βˆ’4π‘Žπ‘2π‘Ž=βˆ’π‘+𝑏2βˆ’4π‘Žπ‘2π‘Žπ‘Ÿ2=βˆ’π‘βˆ’π‘2βˆ’4π‘Žπ‘2π‘Ž

Seem familiar? These are the roots given by the original quadratic formula. If you were wondering where the formula comes from, this is it.

Why do it using this method then? I think the logical steps that lead to the roots using the Po-Shen Loh method are much more intuitive and easy to work with than trying to remember the quadratic formula, especially for someone who’s just learning about quadratics or doesn’t use them often enough to have it burned into their memory.

Code implementation

The algorithm above shouldn’t be too difficult to implement yourself if you have even a little bit of coding knowledge, since it’s mainly just additions, multiplications and square roots. I’ve written a short implementation of the algorithm in Python, but you can translate the code into whatever other language you’d like.

import math

# Enter your values for the coefficients a, b and c in axΒ²+bx+c=0
a = 1
b = 2
c = 1

# Calculate b' and c'
b_prime = b / a
c_prime = c / a

# Calculate u = √(b'²/4 - c')
u = math.sqrt((b_prime**2) / 4 - c_prime)

# Calculate the two roots
r1 = -b_prime / 2 + u
r2 = -b_prime / 2 - u

print(f"""
r1 = {r1}
r2 = {r2}
""")

While this code doesn’t handle it, the Po-Shen Loh method can also be used to handle complex roots.