## Substitute Me for Him

Category : Uncategorized

I’ve been listening to a lot of songs by The Who lately, and even heard them play at the Outside Lands festival on Sunday night! They didn’t do “Substitute,” an early hit and one of my favorites, but the idea of substituting comes up a lot in Math. Sometimes you’re substituting a letter for a number or the value of a letter in one equation where you see the letter in another equation.

Today’s math challenge from the Center of Math’s Twitter post can be solved using substitution:

So there are two mystery numbers, represented by the letters x and y, which make the two equations work:

x + 1/y = 10

and

y + 1/x = 5/12

First we’ll solve for y:

y = 5/12 – 1/x

And we’ll substitute that value for y where we see y in the first equation:

x + 1/(5/12 – 1/x) = 10

To subtract 5/12 – 1/x we’ll need to get them over a common denominator, 12x:

x + 1/(5x – 12)/12x = 10

The reciprocal of (5x – 12)/12x is 12x/(5x – 12):

x + 12x/(5x – 12) = 10

Now we’ll add the terms on the left side by getting them both over a common denominator:

x(5x – 12) /(5x – 12) + 12x/(5x – 12) = 10

Multiply x by (5x – 12) and you get 5x^{2} – 12x.

(5x^{2} – 12x + 12x) /(5x – 12) = 10

Simplify the numerator and you’re left with

5x^{2} /(5x – 12) = 10

Multiply both sides by (5x – 12):

5x^{2} = 10(5x – 12)

Distribute the 10:

5x^{2} = 50x – 120

You’re left with a quadratic equation.

5x^{2} – 50x + 120 = 0

We can factor a five out of all three terms.

5(x^{2} – 10x + 24) = 0

5 times something is equal to zero so that “something” must be zero:

x^{2} – 10x + 24 = 0

The quadratic factors into

(x – 6)(x – 4) = 0

The solutions for x are

x = 6, 4

Remember y = 5/12 – 1/x, so we’ll plug in each value of x to get its corresponding value for y:

y = 5/12 – 1/(6) = 5/12 – 2/12

y = 3/12 or 1/4

When x = 4, y = 5/12 – 1/(4) = 5/12 – 3/12 = 2/12 = 1/6.

We check that both of those pairs work in the equations and they do. The values for x are 6 and 4.

### Check by Graphing

But the problem asks for “all the possible values of x.” How do we know there are no other possible values? We could graph the original equations and see where they cross. I used the online grapher at geogebra.org. The first equation is in blue and the second is in pink:

This region is the only place where the blue and pink curves even get close to one another. We know they cross where x is 4 and 6. Let’s zoom in to those points:

There are our solutions: (4, 1/6) and (6, 1/4).

### The Pythonic Way

I figured there had to be a way to use programming to come up with answers, so I created a couple of functions to return True if the two parameters, x and y, work in the equations:

def eq1(x,y): '''Returns True if x + 1/y = 10''' return x + 1/y == 10 def eq2(x,y): '''Returns True if y + 1/x = 5/12''' return y + 1/x == 5/12

Python 3 has no issues dividing integers like Python 2 did, so I checked a solution I knew would work in equation 1: x = 8 and y = 1/2.

>>> eq1(8,1/2) True

But when I tried a similar one in the second equation, I was surprised to find it didn’t work:

>> eq2(1,-12/7) False

Why is this? Let’s print out 1 – 7/12:

>>> 1 - 7/12 0.41666666666666663

Now let’s print out 5/12:

>> 5/12 0.4166666666666667

There’s a tiny rounding difference at the end of the decimals that will mean they’ll never be technically equal. But we can call them equal if they’re close enough to each other. We’ll use the absolute value of the left side minus the right side:

def eq1(x,y): '''Returns True if x + 1/y gets close to 10''' return abs(x + 1/y - 10) < 0.0001 def eq2(x,y): '''Returns True if y + 1/x gets close to 5/12''' return abs(y + 1/x - 5/12) < 0.0001

This works. Now we just need to go through a bunch of values between, say, -20 and 20. x will be the integers, and y will be the reciprocals, like 1/20, 1/19 and so on.

#try the numbers between -20 and 20 for x in range(-20,20): for z in range(-20,20): y = 1/z if eq1(x,y) and eq2(x,y): print(x,y)

However, this produces an error:

ZeroDivisionError: division by zero

We need to make sure we don’t use z = 0 because that makes y = 1/0 and you can’t divide by zero. A good thing to learn in Python is exception handling. We’ll “try” the process above, and if we run into the Zero Division Error, just go on to the next number.

#try the numbers between -20 and 20 for x in range(-20,20): for z in range(-20,20): #let y be the reciprocal of z try: y = 1/z if eq1(x,y) and eq2(x,y): print(x,y) #if we run into a dividing by zero #error, never mind and go on to the #next number except ZeroDivisionError: continue

Run this and it quickly prints out our solutions:

4 0.16666666666666666 6 0.25

I’m sure there are other ways to solve this problem, too!

Here’s a video of The Who singing Substitute at the Monterey Pop Festival in 1967: