Mathematics and piano tuning

The following is a slightly edited version of a Twitter thread on @AlgebraFact.

The lowest C on a piano is called C1 in scientific pitch notation. The C one octave up is C2 and so forth. Middle C is C4.

The frequency of Cn is approximately 2n+4 Hz. This would be exact if C0 were 16 Hz, but it’s a little flat. In order to make A4 have frequency 440 Hz, CO must have frequency 16.3516.

Notes other than C take their number from the nearest C below. So A4 is the A above C4, middle C. The lowest note on a standard piano, the A below C1, is A0.

At one point in time C0 was defined to be exactly 16 Hz. The frequencies of notes have been defined slightly differently across time and location.

Mathematically perfect octaves, however, don’t sound quite right. The highest notes on a piano would sound flat if every octave were exactly twice the frequency of the previous octave. So we tune the lowest notes a little lower than the math would say to, and the high notes higher.

In the original thread I said that C0 was the lowest C on a piano when I should have said C1.

No discussion of mathematics and piano tuning would be complete without mentioning Fermi problems. As I discuss here,

These problems are named after Enrico Fermi, someone who was known for being able to make rough estimates with little or no data.

A famous example of a Fermi problem is “How many piano tuners are there in New York?” I don’t know whether this goes back to Fermi himself, but it’s the kind of question he would ask. Of course nobody knows exactly how many piano tuners there are in New York, but you could guess about how many piano owners there are, how often a piano needs to be tuned, and how many tuners it would take to service this demand.

Computing functions of roots without computing roots

Once in a while it’s necessary to calculate some function of the roots of a polynomial, and it may be possible to do this without first calculating the roots.

Quadratics

The quadratic formula gives explicit solutions to the equation

ax^2 + bx + c = 0

The two solutions for x are

x = \frac{-b \pm \sqrt\Delta}{2a}
where

\Delta = b^2 - 4ac

The awkward part is taking the square root of the discriminant Δ. But that’s not necessary if you only need to know the sum or the product of the roots.

The sum of the two roots is simply −b/a because the terms involving the discriminant cancel out.

The product of the roots works out to be c/a.

In my previous post, I needed the difference of two roots. This isn’t quite as simple as the sum, but it works out to √Δ/ a.

Higher-order polynomials

There are simple expressions for the sum and product of polynomial roots in general.

The sum of the roots is the negative of ratio of the second coefficient to the first. So for a cubic equation

ax^3 + bx^2 + cx + d = 0

the sum of the roots is again −b/a, just as in the quadratic case.

The product of the roots is the ratio of the last coefficient to the first, with a negative sign for odd degree polynomials. So in the cubic case, the product of the roots is −d/a.

More formal

To use symbols rather than words, let p(x) be the polynomial

p(x) = a_nx^n + a_{n-1}x^{n-1} + \cdots + a_0 = \sum_{i=0}^na_ix^i

and number the roots r1 through rn. Then

\begin{align*} \sum_{i=1}^n r_i &= -\frac{a_{n-1}}{a_n} \\ \prod_{i=1}^n r_i &= (-1)^n\frac{a_0}{a_n} \\ \end{align*}

History

The theorem above goes back to François Viète (1540 – 1603) and is known as the first and last of Vieta’s formulas. (There are others in between. We’ll get to that shortly.) The formulas are called Vieta’s formulas rather than Viète’s formulas because the former is based on the Latinized form of his name, Franciscus Vieta.

As I wrote about here, Viète discovered the following infinite product for π:

\frac{2}{\pi} = \frac{\sqrt{2}}{2}\frac{\sqrt{2+\sqrt{2}}}{2}\frac{\sqrt{2 + \sqrt{2+\sqrt{2}}}}{2} \cdots

Generalization

I don’t know whether Vieta’s formulas in their full generality go back to Viète. Often a pioneer blazes the trail and someone else comes behind them to improve the trail.

The sum of the roots of a polynomial is the sum of all products of roots involving one term. The product is the sum of all products of roots involving n terms. One could ask for the sum of all roots involving an intermediate number of terms. For example, if the roots of the cubic

equation

ax^2 + bx + c = 0

are α. β, and γ, one could as for the sum of all products of two roots

\alpha\beta + \beta\gamma + \alpha\gamma

and this turns out to be c/a.

If we number the roots of our polynomial r1 through rn then the sum of all distinct products of k roots is given by

\sum_{1\le i_1 < i_2 < \cdots < i_k\le n} \left(\prod_{j = 1}^k r_{i_j}\right)=(-1)^k\frac{a_{n-k}}{a_n}

The left-hand side of the equation above is complicated, but it amounts to the sum of all distinct products roots taken k at a time.

Proof

The proof is actually quite simple. Start by writing the polynomial in factored form.

p(x) = a_n\prod_{i=1}^n(x - r_i)

Now imagine multiplying out the product. Each term in the product comes from selecting either an x or a −r from each term and adding up all the possibilities.

The coefficient of xn−1 comes from summing all ways of selecting an x from all terms except one and selecting one negative root term. So the sum of the negatives of the roots is an-1 divided by the an term in front of the product. This proves the first Vieta formula.

The proof for the kth Vieta formula comes from applying the analogous combinatorial argument to the coefficient of xnk.

Discussion

Vieta’s formulas are very clever even though they’re simple to prove.

The quadratic case can be proved by brute force: find the roots, the compute their sum and product. It would be possible, but difficult, to do the same for the cubic case, though I don’t know whether Viète ever saw the formula for the roots of a cubic equation because he and Cardano were contemporaries. The case for fourth degree polynomials would be even harder, and the case for higher degree polynomials would be impossible even in principle.

It would be an understandable mistake to believe you have to generalize the quadratic formula to generalize the theorem about sums and product of roots. But you don’t. It’s common in mathematics to have a flash of insight, realizing that you don’t have to calculate something that it seems you have to calculate. Maybe the lack of convenient formulas for higher roots led Vieta to look at the problem more abstractly.

Vieta’s result is more impressive when you realize how awkward mathematical notation was in his day. Algebra didn’t even use parentheses until Vieta introduced them.

FWHM for a quadratic

This post contains a derives a result I needed recently. The derivation is simple but a little tedious, so I wanted to save it in case I need it again.

Full width half maximum

A common way to measure the width of a function peak in a function f(x) is to find the place x0 where f takes on its maximum, and find two points, x−1 to the left and x1 to the right, where f drops to half its peak value, i.e.

f±1 = f(x0) / 2.

The width of the peak is then defined to be the distance between these two points:

FWHM = x1x−1

where FWHM stands for “full width half maximum.” I’ve mentioned FWHM a few times before, such as here.

It’s also useful sometimes to find the full width at k times the maximum for values of k other than 1/2 and so we’ll solve the more general problem.

Quadratic case

Now suppose f is a quadratic function

f(x) = ax² + bx + c.

where a is not zero. We want to find the FWHM of f, and more generally find the distance between two points where f takes on values k times its maximum (or minimum).

Taking the derivative of f shows that the vertex of the parabola occurs when

2ax + b = 0

and so

x0 = −b/(2a).

and

f(x0) = c − b²/(4a).

Now we have to find two solutions to

f(x) = k f(x0)

which means

ax² + bx + ck(c − b²/(4a)) = 0.

This is a quadratic equation with constant term

c‘ = ck(cb²/(4a))

and so from the quadratic formula, the difference between the two roots is

√( b² − 4ac‘ ) / |a| = √( b² − 4a(1-k)c − kb² ) / |a|

When k = 1/2, this reduces to

FWHM = √(b²/2 − 2ac) / |a|.

Examples

Let’s try this on a couple examples to see if this checks out.

Maximum example

Let

f(x) = 20 − (x − 2)² = −x² + 4x + 16

Clearly the maximum is 20 and occurs at x = 2. The quadratic formula shows the two places where f takes half its maximum value are

x = 2 ± √10

and so the FWHM equals 2√10.

If we use the formula for FWHM above we get

√( 4²/(2) + 32) = √40 = 2√10.

Minimum example

Let’s do another example, this time looking for where a convex parabola takes on twice its minimum value. So here we set k = 2 and so the expression

√( b² − 4ac‘ ) / |a| = √( b² − 4a(1 − k)c − kb² ) / |a|

above reduces to

√(4acb²) / |a|.

Let

f(x) = 3x² + 2x + 1

Then the minimum of f occurs at −1/3 and the minimum equals 2/3. We want to find where f equals 4/3. The quadratic formula shows this occurs at

(−1 ± √2)/3

and so the distance between these two points is 2√2 / 3.

If we plug a = 3, b = 2, and c = 1 into

√(4acb²) / |a|

we get the same result

Number slang and numbered lists

Here’s a list of five numbers used as slang in various contexts.

  1. Location (CB and police radio)
  2. End of column (journalism)
  3. Best wishes (ham radio)
  4. All aircraft in area (US Navy)
  5. I love you (text messages)

The motivation for this post was an article Those HTML attributes you never use. I wanted to make a note of how to change the numbering of an ordered list in HTML, and this post is that note.

Related posts

Oscillations in RLC circuits

Electrical and mechanical oscillations satisfy analogous equations. This is the basis of using the word “analog” in electronics. You could study a mechanical system by building an analogous circuit and measuring that circuit in a lab.

Mass, dashpot, spring

Years ago I wrote a series of four posts about mechanical vibrations:

Everything in these posts maps over to electrical vibrations with a change of notation.

That series looked at the differential equation

m u'' + \gamma u' + k u = F \cos\omega t

where m is mass, γ is damping from a dashpot, and k is the stiffness of a spring.

Inductor, resistor, capacitor

Now we replace our mass, dashpot, and spring with an inductor, resistor, and capacitor.

Imagine a circuit with an L henry inductor, and R ohm resistor, and a C farad capacitor in series. Let Q(t) be the charge in coulombs over time and let E(t) be an applied voltage, i.e. an AC power source.

Charge formulation

One can use Kirchhoff’s law to derive

Here we have the correspondences

\begin{align*} u &\leftrightarrow Q \\ m &\leftrightarrow L \\ \gamma &\leftrightarrow R \\ k &\leftrightarrow 1/C \end{align*}

So charge is analogous to position, inductance is analogous to mass, resistance is analogous to damping, and capacitance is analogous to the reciprocal of stiffness.

The reciprocal of capacitance is called elastance, so we can say elastance is proportional to stiffness.

Current formulation

It’s more common to see the differential equation above written in terms of current I.

I = \frac{dQ}{dt}

If we take the derivative of both sides of

we get

LI'' + RI' + \frac{1}{C} I = E'

Natural frequency

With mechanical vibrations, as shown here, the natural frequency is

\omega_0 = \sqrt{\frac{k}{m}}

and with electrical oscillations this becomes

\omega_0 = \frac{1}{\sqrt{LC}}

Steady state

When a mechanical or electrical system is driven by sinusoidal forcing function, the system eventually settles down to a solution that is proportional to a phase shift of the driving function.

To be more explicit, the solution to the differential equation

m u'' + \gamma u' + k u = F \cos\omega t

has a transient component that decays exponentially and a steady state component proportional to cos(ωt-φ). The same is true of the equation

LI'' + RI' + \frac{1}{C} I = E'

The proportionality constant is conventionally denoted 1/Δ and so the steady state solution is

\frac{F}{\Delta} \cos(\omega t - \phi)

for the mechanical case and

\frac{T}{\Delta} \cos(\omega t - \phi)

for the electrical case.

The constant Δ satisfies

\Delta^2 = m^2(\omega_0^2 -\omega^2)^2 + \gamma^2 \omega^2

for the mechanical system and

\Delta^2 = L^2(\omega_0^2 -\omega^2)^2 + R^2 \omega^2

for the electrical system.

When the damping force γ or the resistance R is small, then the maximum amplitude occurs when the driving frequency ω is near the natural frequency ω0.

More on damped, driven oscillations here.