Math with units

What’s the average fuel economy of two cars, one with 40 mpg, and the other with 10 mpg? It all depends on what you mean by “average”. (That’s 6 and 24 liters per 100 km.)

Mathematicians often deal with pure math — that is, numbers without units. (40 + 10) / 2 = 25 might be a correct equation, but it might not be the appropriate one for our problem. In real life, most numbers have a unit: 3 days, 5 cars, 8 people, 11 dollars. When numbers come with units, there are additional rules for doing math.

Addition and Subtraction

Adding is counting. Subtracting is counting backwards. When counting, one must stay with the same unit. “1 apple, 2 apples, 3 apples” is counting. “1 apple, 2 oranges, 3 pears” is a shopping list.

  • 1 apple + 2 apples = 3 apples
  • 5 hours – 3 hours = 2 hours
  • 1 apple + 1 hour = ??? (doesn’t make sense)

You are, of course, allowed to convert units, if they’re convertible:

  • 1 week + 1 day = 8 days (because 1 week = 7 days)
  • 1 kg + 300 g = 1.3 kg (because 1 kg = 1000 g)

You are also allowed to generalize the units, if it unifies them:

  • 1 apple + 1 pear = ??? (strictly speaking, doesn’t make sense)
  • 1 piece of fruit (which happens to be an apple) + 1 piece of fruit (which happens to be a pear) = 2 pieces of fruit (in this case, an apple and a pear)

When you generalize the units, you lose information. You can go from “an apple and a pear” to “two pieces of fruit”, but if all you know is “two pieces of fruit”, it’s impossible to recover “an apple and a pear”. When you convert units, no information is lost, because if two units are convertible to each other, they’re just different ways of saying the same thing.

Even when the numbers have the same (or convertible) units, it doesn’t always make real-life sense to add them up. For example, Tom is 30 years old and once spent 4 hours trying to learn to juggle. We can absolutely write this equation:

  • 30 years + 4 hours = 262,804 hours*

And it would tell us absolutely nothing. Sure, this is a silly example, but it can get subtle. Let’s go back to the two cars, one with 40 mpg and the other 10 mpg. We can do this math, no problem:

  • 40 mpg + 10 mpg = 50 mpg

And it feels like it could almost be meaningful — the two cars combined can reach a gas mileage of 50 mpg! Except, we live in a world where you can’t just smash one car engine into another and they somehow merge into a better engine. This equation tells us nothing about the real world, and is just as silly as the one with Tom juggling.

(* assuming each year has exactly 365 days, and each day has exactly 24 hours, which isn’t true but also isn’t relevant to the point I’m making.)

Multiplication

In unit-less math, multiplication is often simply thought of as repeated additions. With units, we have a new rule: units accumulate.

When doing math with units, there’s an important distinction between addition and multiplication: addition is one-dimensional, and multiplication is, well, multi-dimensional. One could say, addition extends, multiplication expands.

Multiplication often results in compound units, which are common in physics:

  • 2 kW * 5 hours = 10 kWh (electricity consumption)
  • 4 N * 10 m = 40 Nm (torque)
    • Similarly, 4 lbs * 10 ft = 40 ft·lbs*

But, unlike additions where numbers with different units just can’t be added together, any two units can be multiplied together:

  • 1 apple * 1 hour = 1 apple·hour

What’s an apple·hour, you say? Well, haven’t you heard of the vegan vampire who sucks shelf life out of apples? Nutritionists suggest a minimum of 8 apple·hours per day for a healthy diet. You can do it by extracting 8 hours from one fresh apple, or 1 hour each from 8 stale apples. Same thing.

Yeah okay, I made that up. Truth is, almost no real-life situations require us to use “apple·hour” as a unit. Like juggling Tom, it’s valid math, but it probably doesn’t make real-life sense.

(* The dot signifies multiplication. Commonly used compound units, such as kWh, often omit the dot, but it’s absolutely correct to write kW·h instead of kWh.)

Division

When units compound, they multiply and divide just like numbers do. Multiplied units go on top, divided units go on the bottom.

  • 10 meters / 2 seconds = 5 m/s (velocity)
  • 5 m/s * 8 kg = 40 kg·m/s (momentum)
  • 300 miles / 10 gallons = 30 mi/gal (a.k.a. mpg)

They even cancel out like numbers do:

  • 5 m/s * 2 s = 10 m
  • 30 mpg * 5 gallons = 150 miles

Side note…

Physicists can sometimes be a little silly with their compound units. For example, acceleration is measured in m/s², because that’s what the equation bears out:

  • (60 m/s – 10 m/s) / 5 s = 10 m/s² (also knows as m·s-2)

It really just means “meters per second, per second”. It might be clearer if we give “m/s” a new name. Let’s create a new unit called “vroom” where 1 vroom = 1 m/s. Then the equation above is much simplified:

  • (60 vrooms – 10 vrooms) / 5 s = 10 vrooms/s

Can you just create a unit, like that? Sure I can. Scientists do it all the time. I didn’t so much create a unit as give a nickname to a complicated unit. There are many such nicknames in physics:

  • 1 N (newton) = 1 kg·m/s²
  • 1 V (volt) = 1 kg·m²/(s³·A)
  • 1 Pa (pascal) = 1 N/m² = 1 kg/(m·s²)

They only difference is, everybody knows what a newton is; I doubt anyone knows what a “vroom” is, which is why I had to define it first.

Unit-less numbers

But wait! I hear you say. I do multiplications every day and I never had to compound the units? Well, there are three major possibilities.

Some numbers are truly unit-less

One example is percentages, which, in the US, often show up in the form of taxes and tips.

  • $50 * 15% = $7.50

In science, we say these unit-less number have “a unit of 1”. Just like in pure math, where 1 times anything equals that thing itself, a unit of 1 multiplied by any other unit equals that unit itself.

An equally valid way to look at this is to think of 15% as “15 dollars per 100 dollars”. The units cancel out in the division:

  • $15 / $100 = 0.15 (a.k.a. 15%)

Radians, which is a way of measuring angles, is also unit-less, because it’s (arc) length divided by (radius) length, resulting in a unit of 1.

In real life, such unit-less numbers are often written with a unit anyway. This is a memory aid for the benefit of the person doing the math, and a reminder to the reader what this number is meant to be. With radians, one often writes “rad.” With percentages, one often writes “%” (where 1% = 0.01). It is technically valid math to swap out one unit-less number for another:

  • $50 * 0.15 rad. = $7.50

But, like apple·hours, it’s just silly.

Some units are implicitly compound

Suppose Tom, Dick, and Harry each has $10 in their wallets. How much money do they have in total?

Well, $10 * 3 = $30, right?

That’s the correct answer, but very strictly speaking, it implicitly cancelled out the compound units. We said “each” person has $10 in their wallets. Therefore, the most accurate equation should be:

  • $10/person * 3 persons = $30

Certain situations are so familiar to us that we don’t even think about cancelling out the units anymore. This certainly makes mental math faster, but occasionally, when the situation is subtly different, not being careful with the units will lead to mistakes (read on to see one that made the news).

You are actually using compound units

A football field is 100 meters long and 50 meters wide. How large is it?

  • 100 m * 50 m = 5,000 m²

What do you suppose the m² means? That’s just short hand for “meter·meter”. Likewise, m³ is just shorthand for “meter·meter·meter”.

Computers aren’t always friendly with superscripts, which is why we’ve come up with alternate notations for commonly used units. If you’re buying a house, you’ll see “sq ft” (or “sq m”) a lot, which is just another way of writing ft² (or m²). That’s a compound unit.

Pure numbers as units

Even when doing pure math without units, the English language practically treats some numbers as units. Fractions are one such example:

  • 2 sevenths + 3 sevenths = 5 sevenths
    • In other words, 2/7 + 3/7 = 5/7

Just like with “real” units, when they are different, one has to be converted:

  • 1 half + 1 quarter = 3 quarters (because 1 half = 2 quarters)
    • In other words, 1/2 + 1/4 = 3/4
    • Compare: 1 week + 1 day = 8 days (because 1 week = 7 days)

Sometimes we convert both (called “finding the common denominator”):

  • 1 half + 1 third = 5 sixths (because 1 half = 3 sixths, 1 third = 2 sixths)
    • In other words, 1/2 + 1/3 = 5/6
    • Compare: 1 kg + 1 oz = 1,028 g (because 1 kg = 1,000 g, 1 oz = 28 g)

When they multiply, the “units” multiply too just like any other:

  • 2 thirds * 3 quarters = 6 third·quarters
    • Compare: 2 kW * 5 h = 10 kWh

What’s a third·quarter, you ask? That’s a third of a quarter, of course, a.k.a. a twelfth. Thus:

  • 2 thirds * 3 quarters = 6 twelfths = 1 half
    • In other words, 2/3 * 3/4 = 6/12 = 1/2

Words like “thousands”, “millions”, etc. are often treated as units as well:

  • 3 thousands + 2 thousands = 5 thousands (correct English would be “5 thousand”)
  • 3 thousands * 2 thousands = 6 thousand·thousands (i.e. 6 million)
  • 3 millions / 2 thousands = 1.5 million/thousand (i.e. 1.5 thousands, i.e. 1,500)

Remember when I said not being careful with units could lead to mistakes? A while ago, some US journalists made just such a mistake on TV. The question was, essentially, “how much money does each person get, if we spread $500 million equally among the entire US population, 327 million people?” What they should have done was:

  • 500 million·dollars / 327 million·persons = 1.x million·dollars/(million·person) = 1.x dollars/person

However, they relied on their (broken) instinct and did the following (faulty) mental math:

  • (all in millions) 500 dollars / 327 persons = (in millions) 1.x dollars/person

Look, it’s a brain fart, and it happens to the best of us. Don’t think it won’t happen to you. Check your units.

Taking Averages

When doing divisions with units, the units that go on the bottom are usually said to be “per”:

  • 10 m / 2 s = 5 m/s (“meters per second”)
  • 400 miles / 10 gallons = 40 mpg (“miles per gallon”)

Divisions like this are often used to find averages (more precisely, arithmetic means). The car moved, on average, 5 meters per second. The car goes, on average, 40 miles per gallon of gas.

If we know the average speed (or gas mileage) of something, we can then make estimates about that thing, assuming the average holds.

  • How many meters will the car move in a minute?
    • 5 m/s * 1 minute = 300 m (because 1 minute = 60 seconds)
  • How many miles can the car go on 5 gallons of gas?
    • 40 mpg * 5 gal = 200 miles

Notice in both estimates, some units cancel out. You divide by time to get an average, you multiply by time to get an estimate. How you take your average decides what that average can be used to estimate. In most of the world, fuel economy is measured in the opposite way: gallons per mile (or actually, liters per km). This means our estimates must also be done in reverse:

  • How much gas does the car use on average?
    • 20 L / 320 km = 0.06 L/km
    • For readability, this is more commonly quoted as 6 L/(100 km).
  • How much gas do I need to cover a 200 km trip?
    • 6 L/(100 km) * 200 km = 12 L

Compare the questions:

  • With “mpg”: how much distance can the car go, with a given amount of gas?
  • With “L/km”: how much gas does the car use, over a given amount of distance?

To answer the “wrong” question — e.g. “how much gas do I need to cover 100 miles on a 40 mpg car” — the average must first be inverted:

  • 40 miles per gallon = 1/40 gallons per mile
  • 1/40 gallons per mile * 100 miles = 2.5 gallons

Equivalently, do division instead of multiplication. The “gallon” ends up back on top because it gets divided twice:

  • 100 miles / 40 (miles/gallon) = 2.5 gallons

There are often multiple ways of taking averages, and they’re equally correct. It all depends on what you want to do with that average, and some are more useful than others.

Average of Average

Back to the problem we had at the beginning: what’s the average fuel economy of two cars, one with 40 mpg and the other 10 mpg?

By now, you should see why this equation is practically meaningless:

  • (40 mpg + 10 mpg) / 2 = 25 mpg

2 what? Without a unit, we can’t make sense of the average.

Well, 2 cars, duh.

That’s better. Now we have something that might be meaningful:

  • (40 mpg + 10 mpg) / 2 cars = 25 mpg/car

Sometimes we use a slash “/” for “per”; sometimes we just use the letter “p”. Let’s not mix them up, though. Using the slash-notation, that’s 25 miles/(gallon·car).

In very limited scenarios, this could be a useful average. For example, you might be a test engineer for the car manufacturer, and every day you come into work, you pick a car, put exactly one gallon of gas in the tank, drive it around a race track until it’s out of fuel, and stop. That could be called a gallon·car. If there’s a team of five of you, and each of you do two such tests per day, then that’s 10 gallon·cars per day. If those 10 tests add up to, say, 250 miles in total, you could say on average, the cars you tested had a fuel economy of 25 miles/(gallon·car).

Now, an average is only useful if it can be used to estimate stuff. Let’s say the race track you test the cars on need to be refreshed every time 1 millions miles are driven on it. You know the average fuel economy is 25 miles/(gallon·car), so you can drive 40,000 gallon·cars on the track before you all need to take a week-long vacation while asphalt is redone. If your team drives 10 gallon·cars per day, that’s over 10 years before the track needs to be maintained. As the business owner of this testing facility, you’d be wise to save up 10% of the maintenance cost each year.

… if you know of anyone who does anything remotely close to what I just made up, do get in touch and let me know. The crux of the issue is, I don’t think I’ve ever driven “one gallon’s worth of miles” and stop. That’s why this scenario sounds far fetched.*

If we flip the mpg into gpm, then we’d have something far more useful. Let’s say you and your roommate work at the same place. You have a 40 mpg car, and they have a 10 mpg one. You both decide to sell your cars and get a new one for carpooling.

  • 40 mpg = 1/40 gallons per mile (i.e. 0.025 gallons per mile)
  • 10 mpg = 1/10 gallons per mile (i.e. 0.1 gallons per mile)
  • (0.025 gallons per mile + 0.1 gallons per mile) / 2 cars = 0.06 gallons/(car·mile)

If your commute is 30 miles round-trip each day, then every day, you’ll drive 30 “good” car·miles, and your roommate will drive 30 “bad” car·miles, for a total of 60 car·miles. As an example, in 10 days, you’ll use:

  • 0.06 gallons/(car·mile) * 60 (car·miles)/day * 10 days = 36 gallons (of gas)

We can flip the average back into mpg form:

  • 0.06 gallons/(car·mile) = 16 (car·mile)/gallon

That is to say, when you each had your own car, for every gallon of gas, you’re driving 16 “average car·miles” between the two of you. For carpooling, if you get a car with 16 mpg, you’d still be driving 16 miles for every gallon of gas, same as before. (Except, now that you’re carpooling, the two of you are only driving 30 car·miles in total each day, not 60! That cuts your gas expenses (and pollution) in half.)

Both are correct averages, but wouldn’t you say 0.06 gallons/(car·mile) is much more useful than 25 miles/(gallon·car)?

(* The only realistic scenario I can think of, where a car’s usage is metered by the amount of gas used instead of distance, is when one fills up the (fixed-sized) tank and drive until it’s empty, which is why “mpg” actually makes sense for quoting a single car’s fuel economy. However, when multiple cars are involved, “per gallon per car” is almost never relevant, but “per mile per car” often is.)

Side note…

It’s not uncommon to invert the numbers, take their arithmetic mean, and invert back the result. It’s called a harmonic mean (so called because it was first used in ancient music theory to calculate harmonies). To take an average of 10 and 40:

  • The arithmetic mean (i.e. the “regular” average) is 25
  • The harmonic mean is 16, because \frac{\frac{1}{10}+\frac{1}{40}}{2}=\frac{1}{16}