Showing posts with label math. Show all posts
Showing posts with label math. Show all posts

Saturday, April 14, 2018

A World of Pure Imagination

In the philosophy of mathematics—hold on, hold on, I promise this is good—there's a perennial debate about whether numbers are real or just something we made up. This argument elicits a kind of irritated shrug from most people, but there is a fairly reliable way to evoke some pushback and/or incredulity: assert that imaginary numbers exist.

An imaginary number is the square root of a negative number, which of course doesn't make sense; any number multiplied by itself comes out positive. But mathematics is all about laying down axioms and seeing what logically follows. We can just declare that √-1 = i instead of a calculator error.

Alright, you think, but we can't just declare things into existence. What does an imaginary number even mean in the real world? You can have 3 apples, or maybe even -3 apples if you owe someone, but 3i apples has no concrete, physical interpretation, right?

Well, it turns out that by allowing complex numbers—a set that includes both real and imaginary numbers—we open up a new space for doing mathematics and physics. In fact, if we want to explain the bewildering diversity of chemical elements or the solidity of matter, we have to explore this imaginary space. Could anything be more concrete?

Take a look and you'll see...

Before we delve into the physics, let's make sure we have a little intuition about complex numbers. The imaginary unit, i, is the square root of -1. Just based on that, we see imaginary numbers cycle:

i*i = -1, because that's our definition

(i*i)*i = -1*i = -i

(i*i)*(i*i) = -1*-1 = 1

And (i*i*i*i)*i = 1*i = i again

This cycle lends itself to a neat geometric interpretation. Instead of the humdrum xy-plane, we can imagine a complex plane like this:

By Svjo [CC BY-SA 4.0], from Wikimedia Commons
Here, the horizontal axis is real and the vertical axis imaginary. Complex numbers are pairs that have the form a + bi, representing coordinates (or a vector) on our plane. If we draw a circle counter-clockwise through the points 1, i, -1, and -i, you see they follow the same cycle as our imaginary multiplication. So you can rotate through the complex plane just by multiplying two vectors.

It might look like we've only renamed a plain plane, but this space gives us flexibility the real numbers lack. Real numbers sometimes fall down on the job when you’re trying to solve polynomial equations. But if you say i is a root of -1, you can always find a complex number that does the trick. Geometrically, this lets us access points on the complex plane through simple multiplication, without having to rely on more cumbersome machinery.

Okay, finding polynomial roots probably sounds pretty boring, so we're not going to dwell on that. We'll mostly think in terms of complex rotation and how that permits us to peak into weird, non-Euclidean spaces where up and down no longer work the way they should. But know that in the background, these imaginary roots are letting us do a bunch of linear algebra by providing solutions to otherwise unsolvable equations.

We'll begin with a spin...

Let's turn back to physics. Explaining how the properties of chemical elements—the gregariousness of carbon, the aloofness of neon—arise from quantum mechanics goes like this: the protons and neutrons of an atom are squeezed into a tiny nucleus while the electrons whizz by in concentric orbital shells. How “filled” the outermost shell is (mostly) determines the chemical properties of an element. So whatever keeps these negative nancies from clumping together is responsible for, well, basically all macroscopic structure.

The culprit is the Pauli exclusion principle, which says that particles with half-integer spin (electrons) cannot occupy the same quantum state. Spin is intrinsic angular momentum, measured in units of ħ. If you measure the spin of an electron along some axis, you get either +1/2 (referred to as spin up) or -1/2 (upside down—spin down), with no other possible outcomes.

To keep track of the spin state of an electron, we can write a wave function that looks like this:

|↑⟩

Flip the electron upside down and the spin state is:

|↓⟩

Then flip it back right side up and you get:

-|↑⟩

Wait, what? We seemed to have gained a minus sign somehow. In fact, you have to rotate an electron a full 720° to cycle back to the state you started with. The minus sign doesn't matter much in measurement because anything we observe in quantum mechanics involves the square of the wave function, but it being in the math is pivotal.

Say a transporter accident duplicates Kirk and the two end up fighting.

Credit: Paramount Pictures and/or CBS Studios
There’s a brawl, both men lose their shirts, and one emerges victoriously. How does Spock tell if the original Kirk won or lost? If Kirk is a subatomic particle, we’re left with two possible states that look the same when measured. Either original Kirk wins and duplicate Kirk loses:

|W⟩|L⟩

Or vice versa:

|L⟩|W⟩

Each one will scream, "Spock... it’s... me!" but there's no evil mustache to differentiate them. With identical quantum particles, this symmetry of exchange is mathematically equivalent to taking one particle and flipping it around 360°; in both cases you end up with observationally indistinguishable states.

But there are still two outcomes. Whenever we're dealing with multiple possibilities in quantum mechanics, it's time for you-know-who and his poor cat. Just as the cat can be in a superposition of alive and dead, a Kirk particle can be in a superposition of winning and losing.

Nothing weird happens when you mix and match bosons (particles with integer spin like photons). They exchange symmetrically and their superposition looks like this:

|W⟩|L⟩ + |L⟩|W⟩

But electrons (and other half-integer fermions) are antisymmetric; a 360° flip gives us that minus sign. So their superposition is:

|W⟩|L⟩ - |L⟩|W⟩

As both sides of this expression are indistinguishable, subtracting one from the other equals 0. Any place where the wave function is 0, we have a 0% chance of finding a particle. So two electrons will never end up in a fight in the first place. (Kirk, then, is clearly a boson.) Replace "fight" with "spin up state in the 1s shell of a hydrogen atom" and you've got the beginnings of chemistry and matter.

What we'll see will defy explanation...

Okay, so how do we make sense of the weird minus sign a rotated electron acquires? This perplexing behavior originates with their 1/2 spin, which we can only understand if we venture back into the world of imaginary numbers, to a place called Hilbert space.

Physicists discovered that electrons were spin-1/2 as a result of the Stern-Gerlach experiment, where Stern and Gerlach sent silver atoms (and their attendant electrons) through a magnetic field. Spin up particles were deflected one direction, spin down particles a slightly different direction. That there were only two possible values along a given axis was weird enough, but follow-up experiments revealed even stranger behavior.

By Theresa Knott from en.wikipedia - Own work, CC BY-SA 3.0, Link
If you collect all the |↑⟩ electrons and send them through another S-G apparatus, only |↑⟩ electrons come through. You're giving me a look, I can tell; what's weird about that? Well, we're still dealing with quantum mechanics, so we always have to consider superposition. Maybe the state after detection is |↑⟩ + |↓⟩ and there's a chance one will come out |↓⟩.

Experiment says no. This is a little weird. It means +1/2 spin doesn't overlap at all with -1/2 spin (positively or negatively). That should only be the case for vectors at right angles to each other. Somehow, these up and down arrows behave as if they're orthogonal.

Say we've been measuring spin along the z-axis until now. We can set up a second S-G apparatus that measures along x (or y) and then send |↑z⟩ electrons through that. The z- and x-axes are at right angles, so there should definitely be no overlap. But electrons are capricious; they split evenly between |↑x⟩ and |↓x⟩, even though an arrow only pointing up clearly has no component in any other direction.

A pattern is emerging here. The 180° separation between |↑⟩ and |↓⟩ acts like a right angle. Right angles act like they’re only separated by 45°. And a full 360° rotation just turns a vector backward, giving it the minus sign at the center of all this. All our angles are halved. The space electrons inhabit is weird, as if someone tried to grab hold of all the axes and pull them together like a bouquet of flowers.

Try to imagine that if you can, but don't worry if you can't; we're not describing a Euclidean space. You can sort of squeeze the z- and x-axes closer together, but any attempt to bring the y-axis in while also maintaining the 90° separation between any up and down and 45° separation between any right angle just won't work.

The only way we can fit the y-axis in there is to deploy a new degree of rotation distinct from Euclidean directions. That sounds like a job for the complex plane. In fact, our inability to properly imagine this space is directly analogous to not being able to find real roots for a system of equations, which as we know is where complex numbers shine. Vectors that are too close in real space can be rotated away from each other in complex space to give us the properties we need.

From this mathematical curiosity—a space where rotation and orthogonality are governed by complex numbers—we find an accurate description of the subatomic particles that serve as matter's scaffolding. Electrons are best thought of not as tiny, spinning balls of charge but as wave functions rotating through a complex 2D vector space.

So what does it mean to have 3i apples? Nothing. But what does it mean to have 3 apple juice? The physical reality of complex numbers only manifests at the quantum level. To many philosophers, this indispensable presence demands ontological commitment. This is a way of saying, "Well, I guess if anything is real, that is." And how are we to say otherwise? Complex numbers might come from a world of pure imagination, but they're necessary for describing this world; shouldn't that count for something?

Credit: Warner Bros. for this picture and the song lyrics.

Friday, August 18, 2017

Less Is More

The eclipse is only a couple days away, so I've been checking weather reports for the last week or so hoping the forecast will be clear. It varies from site to site and day to day, which is kind of frustrating.

Our inability to precisely predict the weather reminds me of some standard opposition to climate science. That is, if we can't even predict next week's weather in one city, how can we possibly predict the world climate a decade from now? There's a similar argument against evolution: if there's a single "missing link," how can we possibly claim to know the history of life? If we don't know the exact sequence leading from, say, our common ancestor with chimpanzees to anatomically modern humans, how can we be sure that life in general underwent evolution?

The problem with this line of thinking is that it misses why science has managed to be successful at all. Science does not make accurate predictions because we have perfect knowledge of a system. In fact, the opposite is often the case. Science succeeds in part because of our ability to abstract away that which is unimportant and reveal the underlying patterns. Consequently, a little bit of ignorance helps us miss those details which might distract us.

The eclipse itself is a great example of how having all the information can (literally and figuratively!) blind us. Our eyes are not well equipped for looking at the sun because it can be many orders of magnitude brighter than everything else we see. To fit a scene with such drastically varying brightness levels into our head, we lose some contrast resolution and end up not being able to see dim, feeble objects—especially those in the sky. That means we miss out on all the stars up during the day as well as anything even remotely near the sun.

During a total solar eclipse, the conveniently sized moon perfectly blocks the disk of the sun and a local night falls. The stars and planets come out, and the wispy corona that wreathes the sun materializes before our eyes. If we have good enough telescopes, we can measure the deflection of starlight around the sun, which tells us how its mass perturbs space itself.

1919 Solar Elcipse. This picture is in the public domain, but I guess I'll credit Arthur Eddington?
And yet we can only do this because we have less information, because we are no longer being blinded by the flood of photons.

Now perhaps I'm engaging in some rhetorical trickery here. I started off talking about how missing individual pieces of the puzzle doesn't prevent science from abstracting away the pieces to find the underlying rules, and then I shifted to discussing how having all the pieces hinders us. But I do think there's a connection here, because the truth is we don't always realize when the details have led us astray; it's not usually as obvious as the blazing sun.

The problem has to do with our affinity for patterns and the mathematical tools we've developed for describing them. As the history of geocentrism demonstrates, our tools are too powerful for their own good. Because planetary orbits are pretty complicated, geocentrists employed epicycles—circles on top of circles—to describe how the planets moved through the sky. (Copernicus did this as well, actually, because he couldn't give up the notion of perfectly circle orbits at constant speed.) Add enough epicycles to your system and you can accurately map out any set of planetary observations, with all the messy details included.

And I do mean any set. (You can watch the whole thing, but skip to about a minute for the good part.)

Video uploaded by Santiago Ginnobili.

Aha! We have discovered that Homer Simpson is really a complex set of epicycles. But no, that seems to have things exactly backward. Homer Simpson comes from the imagination of Matt Groening. That we happen to be able to describe the character's appearance using a set of epicycles does not give us any insight into why the character looks the way he does.

And yet packing in all the detail can give us the illusion of understanding. You see, that complicated set of Homeric epicycles can also be represented as a Fourier series, a sum of sine functions where each function—with a differing amplitude and frequency—represents one epicycle. That is, we can come up with an equation that describes Homer Simpson, and all we have to do is plug in the right numbers. It is easy to imagine, then, that there is a physical reason for each of us those amplitudes and frequencies. Once we've found a reason for each number, we would seem to have a very satisfying scientific explanation for the existence of Homer.

But we know, of course, that there is none, because Homer is not really built up of epicycles and all the detail we've admitted into the system has led us astray.

Okay, but then how do we discover the truth when the details get in the way? How do we "hide" them so we can see what's underneath? Abstraction is the answer. To see how that works, let's get away from early astronomy and back to the bright, messy sun.

At work, I recently came across a very neat technique used for studying the spectra of solar system bodies. So let's say we want to know more about a comet that's recently swung by the inner solar system. When we point our telescope at it, what do we see?

Not a real spectrum of any comet. Just something I cobbled together.
If we put a spectrograph on the back of the telescope—a device that breaks up light into individual wavelengths like a prism—we get this weird hump with spikes running through it. This graph shows how intense the light is at each wavelength, running from violet on the left to red on the right.

The problem with this graph is that most of what we're seeing is just reflected light from the sun. If we want to know about the comet itself, we have to find a way to eclipse (sorry) the sun's spectrum.

This process is known as continuum-subtraction. The shape of our comet spectrum is determined by two factors: absorption/emission lines (the spikes) and the temperature of the sun (the overall hump). We have to separate those two if we want to get rid of the sun. We start by abstracting away the details—those messy spikes—leaving us with the continuum.

To do that, we need to find the best fit line for the spectrum. As with the Homeric epicycles up above, our mathematical tools are powerful enough to write some equation that perfectly fits the line. Instead of a Fourier series, it would be a polynomial—a sum of powers of x with coefficients. You know some basic polynomials: a line is a first order polynomial, a parabola a second order one. For this, we might need, say, a 384th degree polynomial, but we could do it. And again, we could imagine that each power of x and each coefficient has some physical cause.

But then the details are distracting us again. The truth is that most of the jagged bits of the spectrum originate from (a) atmospheric interference, the heat of the telescope, and other noise, and (b) absorption and emission lines that are superimposed on top of the continuum spectrum. So let's keep our epicycles to a minimum and use a simple second or third order polynomial instead.

My parabola. You can't have it.
With the comet continuum in hand, we can then subtract it from the comet spectrum. Doing that leaves behind only the spikes.

There are bits of code out there to perform this operation. I don't recommend subtracting each bit by hand.
The spikes that rise above the noise (which we can calculate) are the light being emitted and absorbed by the comet at particular wavelengths. The location of each line along the spectrum is a result of what element or compound is interacting with the light. With the continuum removed, we know what the actual flux is and can determine how much of the stuff is on the surface of the comet.

Another neat trick lets us figure out the albedo of the comet—how much it reflects the light of the sun. Its albedo also depends on its composition. (Think about how much brighter the earth's icy poles are than its liquid oceans.) You might think we can figure that out just by pointing our telescope at the comet and seeing if the object is bright, but its brightness results from its proximity to the sun, distance from us, size, and finally albedo. The first two parameters are easy to figure out if we track its orbit; the last two require some disentangling.

Step one is to point the telescope at a star with similar characteristics to the sun—a solar analog—and see what its spectrum looks like in our telescope. We can't point the telescope at the sun itself, because a telescope designed to look at faint comets and stars would be blinded by the sun. We also don't want to just take someone else's spectrum of the sun, because then we're comparing observations from different telescopes in different environments. Best to use the same equipment.

Now, any solar analog we find out there isn't going to be an exact duplicate of the sun. So like before, we're better served by ignoring the details of the star's spectrum and finding a solar continuum. If we compare the solar continuum to the comet continuum, we'll see that even though the comet's light is mostly reflected sunlight, there are differences. Not every bit of light that strikes the comet's surface is reflected back. Some will be absorbed, and this absorption is wavelength-dependent. What we can do is divide the comet continuum by the solar continuum and come up with the fraction of each wavelength of light that is reflected—the albedo as a function of color.

If the albedo is low, then the comet is naturally dark. If it's dark but appears bright in the telescope, it must be very large. Conversely, if the albedo is high, the comet is shiny. A dim but shiny comet must be small. So that's size and albedo worked out, too.

I think that about covers it. With these techniques, we can abstract away the distracting details—the light of the sun, the noise in our instruments—and come away with facts about a ball of ice and rock hurtling through space. A comet is a messy, complicated object and nothing but its orbit is easily reducible to a simple law, but we can nevertheless know more about it by pretending we see less of it.

Thursday, January 12, 2017

When You Think Upon a Star

Among the sciences, astronomy benefits from widespread public appeal. Hilariously large numbers and gorgeous images make it an attractive source for science news. The result is that some difficult notions from astronomy have managed to penetrate successfully into public awareness. For example, this meme, which I've run across several times:

I got this image here (which, incidentally, is a blog post doing exactly what I'm about to do), but I've seen this meme in other forms elsewhere and have no idea what its original source is.
I'd like to say that I feel conflicted about this meme—that I'm happy the joke relies on knowledge of astronomy (the immense size of the universe versus the finite speed of light), despite the specific fact it calls upon being incorrect (visible stars are almost certainly still alive)—but that would be a lie, because I'm an enormous pedant.

However, in this post I'm going to steer my pedantry in what I hope is a slightly more interesting (and less annoying) direction, toward mathematical reasoning. That is, while I think it's great that the public has been able to learn certain specific facts about astronomy (and other sciences), I think it would be far more valuable if the public learned how to apply mathematical reasoning to claims they encounter.

Here's why: as a recent graduate with an official degree in astronomy and all that jazz, I happen to simply know the fact that, in general, the stars we can see with the naked eye are close enough, and live long enough, to still be alive by the time their light reaches us.

But even if I didn't know that fact, I could arrive at it by constructing an argument from some more readily available facts. And this argument, although mathematical in nature, doesn't involve anything more complicated than a bit of algebra, such that anyone who gets out of high school should be able to reach the same conclusion.

Now, the joke's humor relies on some common facts from astronomy: stars are far away, light is slow compared to the size of the universe, stars eventually die. But before we get into the mathematical meat of evaluating this claim, let's think about another common fact: our sun is 4.5 billion years old (give or take), and it's roughly halfway through its life, so it's got another several billion years to go.

In order for the sun to be dead by the time an alien civilization see its light, that civilization would have to be farther away in light years than the sun's remaining age in years. That is, the alien civilization would have to be many billions of light years away. So if we take our sun as typical, then the above meme is only true if we can see, by the naked eye, stars that are billions of light years away. We can't, and as I'll show in a bit, we don't even have to assume our sun is typical for this argument to work (which it isn't, really). But this is the structure of the mathematical argument: compare the lifetimes of stars we can see with the naked eye to their distances from us.

A few more astronomical facts are necessary to work this out, some of which can be gotten by a bit of googling, and one which, I admit, most people probably aren't aware of. This fact, which makes evaluating the claim very easy, is that the more luminous a (main sequence) star is, the shorter it lives. This means the most luminous stars (which are the most likely to be visible by the naked eye at great light travel times) are the best candidates for stars that are dead by the time their light reaches us. If the claim fails for these stars, it fails for all stars.

The most luminous stars live about a million years and are about a million times brighter than the sun. Now, it's always possible that a star we're seeing just happens to be at the end of its life, but all else being equal, if we pick stars at random out of the sky, then on average they will be halfway through their lives, just like (coincidentally) our sun (not strictly true, because there is some selection bias to the stars we can see).

To be visible by the naked eye, a star needs to have an apparent magnitude of 6 or lower.

For the sun to be magnitude 6 (it's currently an obscenely bright -27), it would have to be about 60 light years away. (There's some math involving logarithms here, but there are tools online that could get you this answer.)

How bright a star appears to us is proportional to its intrinsic brightness and inversely proportional to the square of its distance from us. That is, if star A and star B are identical but star B is twice as far away, it looks 1/4 as bright as star A.

And that's everything we need to evaluate the claim. Now here's how we construct the argument. A star is dead by the time its light reaches us if its remaining lifetime in years is less than its distance in light years. It is visible with the naked eye if its intrinsic brightness relative to the Sun is greater than the square root of its distance relative to the Sun's distance at magnitude 6.

Let me unpack that second statement a bit. Say a star is intrinsically four times as bright as the sun. If it's also magnitude 6 (just visible), then it needs to be farther away than the sun. Specifically, a star four times as bright as the Sun will be just visible at twice the distance (square root of 4) of the magnitude 6 sun: 120 light years. If it is farther away, it is too dim for us to wish upon it.

The brightest stars are 1,000,000 times more luminous than the sun, which means they are the same apparent brightness as the Sun when they are 1,000 times farther away. If the sun is just visible at 60 light years, then the brightest stars are just visible at 60,000 light years. Is 60,000 light years greater than the (on average) half a million years the star will have left to live? No. At that distance, the star could only be dead by the time we see it if it were already 95% of the way through its life. For less luminous stars which live longer, that percentage gets even higher, which makes it much less likely that we ever see such a star.

When we learned algebra via word problems, we were supposed to be learning how to solve problems like these. And while most of us probably managed to get through those word problems successfully, it's been my observation that most of us don't apply this kind of analysis outside of school, to things like evaluating claims that have mathematical content. While it's not vital to the health of a democracy that we be pedantic about random Facebook memes, it might be useful for us to be able to think carefully about scientific claims, at least when the facts and math involved don't require a PhD.

Outside of learning a bunch of astronomical facts, one of the most valuable (academic) lessons I acquired while getting my degree was learning how to bring mathematical tools to bear on a problem. I'm sure this blog post doesn't really have what it takes to impart that same lesson on others, but I hope it reveals a bit of the process. If I could wish upon a star (and I were feeling altruistic), I might wish for an educational system that did a better job of that.

Thursday, January 21, 2016

Passwordocalypse

This is the second year in a row that I've seen an article decrying our collective cyber stupidity because of the awful passwords we use to protect ourselves. And this is the second year in a row that I've rolled my eyes very hard at the article because of its mathematical ignorance. This is the first year I've decided to blog about it, though.

The article linked to above lists the most popular passwords found in databases of stolen passwords. At the top of the list are groaners such as "password", "123456", and “qwerty”. How could those be the most popular, when everyone knows China is hacking its way into our country and we're using passwords to protect our finances, identities, and porn habits? How could everyone be so stupid?

Well, the truth is, very few people have to be stupid for those passwords to be the most popular. In fact, there's an easy to imagine scenario in which no one is so cyber-challenged. Let's see how.

The most popular password is the one that gets used more than any other individual password. This doesn't mean it's used by a majority of people, obviously, just as Donald Trump isn't supported by a majority of Republicans. Additionally, when we're ranking password popularity, we're doing so by login rather than by person, because that's how the data comes to us. So password popularity is measured as logins/password.

And what's being railed against in the above article is that the passwords with the highest login/password are bad ones. But what makes a password bad? Ease of guessing--those that take the least time to crack are the least secure.

This quality is quantified in a password's information entropy, which is a measure of the number of bits needed to specify the password. In other contexts, a piece of data's information entropy tells you how much that data can be compressed. The higher the entropy, the more bits needed to specify the data, the fewer bits you can get rid of and still preserve it.

When I think entropy, I think physics. Most people probably do, too, knowing it has something to do with thermodynamics and disorder. You probably know the second law of thermodynamics, which is usually stated as something like, "The entropy (disorder) of a system tends to increase."

The "tends to" there indicates that this is a probabilistic law. That is, if you have a box with octillions of gas molecules all bouncing around at different speeds and directions, it's hard to say exactly what they're going to do, but you can say what they're likely to do. And it turns out that a box of gas is more likely to go to a high entropy state than a low one. The reason is that there are many more high entropy states than low ones available.

This is where the connection to disorder comes in. The canonical example is probably an egg. An intact egg is a very ordered thing. It has a specific shape, and you can't change the shape of the egg without changing the fact that it's an intact egg. Thus order means low entropy, because there are only a small number of ways for an egg to be an egg.

Scrambled eggs, on the other hand, are disordered and high entropy. The high entropy results from the fact that you can rearrange your egg particles (eggs are made of egg particles, right?) in many, many different ways but still end up with the same basic breakfast: scrambled eggs.

How does this connect back to information and passwords? Because as the entropy of a system increases, it takes longer and longer to accurately describe the system in detail. With low entropy, high order systems, there might be one law of nature telling you why the system is shaped the way it is, which means it's easy to specify it in detail. But with a high entropy system, there are many microstates that are approximately the same, so you need to be more and more detailed if you want to specify a particular one. "No, the one with particle 1,036,782,561 going this way, not that way."

So high entropy data doesn't compress as easily because there are many high entropy systems, which means it takes a lot of bits to differentiate between two chunks of data. And this is also why high entropy passwords are more secure: because if you're randomly guessing a password, it takes you much, much longer to get through all the available high entropy passwords than it does the low entropy passwords.

But that's also why the least secure passwords will always be the most popular ones. Compared to the secure passwords, there just aren't that many bad passwords out there, because bad passwords are low entropy. The login/password for bad passwords is going to be high essentially by definition. Here's a toy model to demonstrate.

Mathematically, the entropy of a system (s) is proportional to the log of the number of microstates (n) that correspond to a single macrostate. Computer people like to do things in binary, so they use a log base of two: S = log2(n). Now let’s take some real data and see what we find. Using this website, I have found the entropy of each of the 25 most popular passwords. Their average entropy is 20.12. Using my password manager, I've found the average entropy of 10 randomly generated strong passwords (I got lazy, but the variation in entropy was low): 80.84.

So the average good password is ~4 times as strong as the average bad password. If we assume there are only 25 bad passwords (there are many more, but more makes the point even stronger), and that the population of logins (p) uses either good passwords or bad passwords, we can write an expression comparing password popularity (logins/password). For our model, let’s see what it would take for good passwords to be just as popular as bad passwords:

pbad/nbad = pgood/ngood

How do the number of good passwords compare to the number of bad ones? Well, from the log formula up there, if we multiply the strength of a bad password by 4, we get 4S = 4log2(n). From the rules of logs, we can take that 4 on the outside of the log and bring it in: 4S = log2(n4). So if you have n bad passwords, then you have n4 good passwords.

pbad/nbad = pgood/nbad4

Solving for the ratio of logins using bad passwords to good, we get:

pbad/pgood = 1/nbad3

Now let’s plug in nbad = 25.

pbad/pgood = 1/15625 = 0.000064

This means that as long as more than 0.0064% of all logins use bad passwords, they will be the most popular. Stating the converse, 99.9935% of all logins can use strong passwords, and the bad ones will still be more common.

Of course, in the real world, there are more than 25 bad passwords (and waaaay more than 254 good passwords), and people aren't divided up into binary good and bad password users. But I think this demonstrates that very few people need actually be stupid for the above article to be true.

And as I said, it's possible that no one is stupid because this is based on logins rather than users. All it takes is that more than 0.0064% of the time you need to pick a username and password for a site, it's a site for rating cat videos and you rightly don't care about security.

Saturday, March 21, 2015

Euler Unmasked

We're going from straight philosophy in my last post to straight math in this one. But if you're an ancient Greek thinker type person, math and philosophy are the same thing, anyway.

So about a year and a half ago, I made a post that touched briefly on the relationship between trig functions and exponential functions as a way of justifying my tendency to make things more complex than they need to be. I mentioned there that I didn't have a firm enough mathematical grasp to explain how these two mathy bits are related. Well, the topic of Euler'sidentity came up a little while ago in my writing group, so I decided to do some research and figure out just how it is that trig functions and exponential functions come together.

For those of you that don't click links, Euler's identity says:




This is a pretty remarkable and frankly incredible equation, but it's true. It manages to link probably the three most famous mathematical constants in a very simple way. The identity arises from Euler's formula, which says:




If you replace x with π, then isin(π) = 0 and cos(π) = -1, so with a little rearranging you can get Euler's identity. But this raises the question of why it should be true that exponential functions and trig functions are connected by the imaginary unit.

First, a quick primer for those who need it. In the common parlance, something that is "exponentially" better is "really super" better. This kind of talk tends to aggravate the mathematically aware, however. Really, exponential functions are ones where adding a constant increment to the input multiplies the output by a constant factor.

So if you hear something like, "Kyrgyzstan's GDP has doubled every year for the last ten years," then that's exponential growth. The factor is 2, and the increment is yearly. But this also applies to, say, the interest rate on your savings account, which as we all know is not exactly "really super" better than anything except possibly 0. There, your balance is getting multiplied by something like 1.0025 every year, which is every bit as exponential as Kyrgyzstan's doubling GDP (totally made up).

The point is, however, that exponential functions (with a factor greater than 1) demonstrate constant (monotonic) growth. If you increase the x value, the y value will increase, too.

Trig functions, on the other hand, are the realm of waves, which go up and down and up and down. They are all about rhythmic or periodic behavior. But as their name suggests, the trigonometric functions are actually based on the angles formed by triangles. Trig functions are really expressions of the Pythagorean formula, A2 + B2 = C2. The relationship between this formula and periodic motion is that for some constant value of C, increasing A will decrease B, and vice versa.

So it's hard to see how exponential functions and trig functions could be related. As I hinted up above, the answer is through i.

i, the imaginary unit, is what the square root of negative one is defined to be. Imaginary numbers kind of get a bad rap, partly because of their name. They seem like something mathematicians just made up that couldn't possibly be real. The funny thing is people had the same opinion about negative numbers for a very long time. After all, how can you possibly have -3 apples? On this whole controversy, the great mathematician Carl Friedrich Gauss had this to say:
That this subject [imaginary numbers] has hitherto been surrounded by mysterious obscurity, is to be attributed largely to an ill-adapted notation. If, for instance, +1, -1, √-1 had been called direct, inverse, and lateral units, instead of positive, negative, and imaginary (or even impossible), such an obscurity would have been out of the question.
While his preferred notation might seem somewhat opaque, it does lend itself very well to a geometric interpretation of numbers. If you look at a Cartesian plot, you can think of Gauss's direct, inverse, and lateral numbers this way. 




The direct unit (+1) moves you one to the right on the graph. The inverse unit (-1) moves you one to the left. And the lateral unit (√-1) moves you up one. Rather than being on the number line we're used to, imaginary numbers can be thought of as being at right angles to it.

This idea lets you plot numbers that are a combination of "real" and "imaginary." So if you have the complex number 3 + 2i, that's just 3 units to the right and 2 units up.


As you see, plotting numbers this way means you can draw right triangles that are related to those numbers. This is the first way that we can connect imaginary numbers to the trig functions. Getting from imaginary numbers to exponential functions will take a little more work, though.

If i is the square root of -1, we can play around with exponentiation to find an interesting pattern. i2 = (√-1)2, which by definition equals -1. i3 = (√-1)3, or (√-1)* (√-1)2, or i*-1, which just comes out to -i. i4 = i2 * i2, or -1 * -1, which equals 1. Multiply that by i, and you of course have i again. So through exponentiation, we have discovered something of a pattern.

i1 = i
i2 = -1
i3 = -i
i4 = 1
i5 = i

The exponents of i loop back in on themselves. You might even say they exhibit periodic behavior, like the trig functions.

Our next step is probably the toughest bit. Bear with me. So, if you recall from my foray into Fourier, many functions can be expressed as an infinite series of sines and cosines that eventually converge on a desired function. These infinite series turn out to be very useful to mathematicians, because not all patterns can be expressed as "elementary" functions, but only as infinite series of some other type of function. One type of infinite series is the power series, which looks like this:




To get different functions, just plug in different values for the coefficients an. The way you figure out which coefficients correspond to the function you want is basically by assuming your function can fit into some power series and then just playing around for awhile until you find a pattern that fits. Let me demonstrate.

One of the defining features of the exponential function, ex, is that it is its own derivative. This means that its rate of change is equal to its value. So the derivative of ex is also ex, and so on.

One of the first tools you learn in calculus is that the derivative of a power function like x4 is 4x3. You multiply by the exponent, and then lower the exponent by one. If the exponent is already 0, then your derivative is 0. So if you take the derivative of our above model power series, you get:





And if you take the derivative of that, you get:





And if you take the derivative of that, you get:





And one more time, because there's a pattern I want you to see:





Now remember, all of these series are equal to the function ex, because ex is its own derivative. The missing ingredients are the values of an. If we evaluate ex at x=0, we have e0, and anything to the 0th power is equal to 1. In the above series, when x is 0, everything except the leading term is also 0. So we have:

1 = a0 = a1 = 2a2 = 6a3 = 24a4

and so on. So with a little bit of algebra, you can figure out the value of any an. It's just 1 divided by the factor preceding the coefficient. But there's a pattern here. 24 = 4*3*2*1. 6 = 3*2*1. 2 = 2*1. The value of the coefficient is equal to 1 over the index of the coefficient multiplied by each integer lower than it. This is known as a factorial in mathematics and looks like this:

5! = 5*4*3*2*1 = 120

With that information in hand, we know what the power series of the exponential function is:







I've gone through this process once so that you don't think I'm pulling this stuff out of a hat, but you can do the same thing to find the power series of a lot of different functions, including the trig functions. For example, the power series of sin(x) is:







And the power series of cos(x) is:







Weirdly, the sine and cosine power series look kind of similar to the exponential function, but with terms missing and some negative signs thrown in. This curious fact turns out to be very important for connecting exponential and trig functions. Let's remember that the key to that connection is i.

Let's see what happens if we try to find the power series of eix rather than ex. To do that, we just replace all instances of x with ix in our series above. That gets us:






Hey, that means we're finding powers of i. But we already did that up above. That follows a pattern, so we can just fill in from that pattern and get:







Now, just for the heck of it, let's separate our series into terms without i and terms with i. So we have:







Look familiar? That's the power series for cosine plus i times the power series for sine. In other words...




Just as Euler told us.

All of this may seem like some kind of tedious mathematical trick. After all, how do we know that the power series representation of a function behaves identically to the function itself in all instances? The truth is, it doesn't, and that's one of the things you have to be careful of when finding series expansions. It does happen to work in this case, though.

But there are ways in which this proof can help motivate understanding. One way to think of the idea is that the introduction of i into the exponential function breaks the function down into four interacting parts: one increasing in the direction of 1, another increasing in the direction of -1, and two others increasing in the direction of i and -i. Different values of x contribute more to one direction than another, and the whole thing repeats with a period of 2πi.

To see if this picture holds true, let's take another look at the powers of i. We saw that powers of i cycle from i to -1 to -i to 1 and then back to i again. But we were only looking at integer powers of i. What happens if we replace the integer with an unknown variable x? That is, how do we evaluate ix?

A neat tool that can sometimes work in mathematics is to perform some operation on an expression and then also perform the inverse of that operation. Doing so doesn't change the expression, but it does let us look at it in a different light. So how about we take the natural log of ix and then exponentiate the expression. That gets us:





The laws of logarithms mean we can move that x to outside the log, giving us:





We know how to evaluate ex, but it’s not immediately clear how to evaluate ln(i). Here it's useful to remember what ln means. The natural log of some number is the power to which you must raise e in order to get that number. So if you have, say, ln(e2), then our answer is 2, because e to the power of 2 obviously equals e2. So let's look at it this way: e to what power equals i?

Now we bring in Euler's formula again.

eix = i when cos(x) = 0 and isin(x) = i

This is true for x = π/2, because cos(π/2) = 0 and sin(π/2) = 1.

So then ln(i) = iπ/2, which means that ix = eiπx/2 = cos(xπ/2) + isin(xπ/2). With that conversion, we can evaluate i to any power at all, not just integer powers. But to reaffirm that this isn't some trick, let's go ahead and see what evaluating it to integer powers means.








This is the exact same pattern we saw above, but this time through the lens of Euler's formula rather than the logic of manipulating √-1. For non-integer values of x, you get complex numbers that, when treated as vectors on the complex plane, are all a distance of 1 from the origin, creating a circle of radius 1. Through purely algebraic means, this connects back up with the geometrical interpretation of imaginary numbers suggested by Gauss.

Okay, I'm done now. I hope this sheds some light on the interconnectedness of math, which can be demonstrated by taking the rules you're familiar with and applying them to unfamiliar situations. When people speak of the beauty of math, this is it. In the real world, we often find depth and meaning through metaphors that connect disparate ideas. That's what art and literature are all about. Math does the same thing, but with numbers, letters, and funny symbols.

(On the other hand, I may have written this post just to play around with LaTeX.)

Friday, November 22, 2013

“We won’t go into the details.”

I’m pretty sure I’ve talked a lot more about my math class than my physics class this semester. With the semester winding to a close, I don’t have much time life to even the score. But here’s an attempt. The reason for the relative silence on the subject of physics is, however, math-related.

As I mentioned in an earlier post, the third semester of intro physics is usually referred to as modern physics. At my community college, it’s “Waves, Optics, and Modern Physics.” The course covers a lot of disparate material. While the first half of the semester was pretty much all optics, the second half has been the modern physics component.

What does “modern physics” mean? Well, looking at the syllabus, it means a 7-week span in which we talked about relativity, quantum mechanics, atomic physics, and nuclear physics. All of these are entire fields unto themselves, but we spent no more than a week or two on each topic.

I predicted during the summer that I wouldn’t mind the abbreviated nature of the course, but that prediction turned out to be wrong. Here’s why.

The first two semesters of physics at my community college were, while not perfect by any stretch of the imagination, revelatory in comparison to the third semester. I enjoyed them a great deal because physical insight arose from mathematical foundations. With calculus, much of introductory physics becomes clear.

You can sit down and derive the equations of kinematics that govern how objects move in space. You can write integrals that tell you how charges behave next to particular surfaces. Rather than being told to plug and chug through a series of equations, you’re asked to use your knowledge of calculus to come up with ways to solve problems.

This is in stark contrast to what I remember of high school physics. There, we were given formulas plucked from textbooks and told to use them in a variety of word problems. Kinetic energy was 1/2mv2, because science. There was no physical insight to be gained, because there was no deeper understanding of the math behind the physics.

And so it is in modern physics as well. The mantra of my physics textbook has become, “We won’t go into the details.” Where before the textbook might say, “We leave the details as an exercise for the reader,” now there is no expectation that we could possibly comprehend the details. The math is “fairly complex,” we are told, but here are some formulas we can use in carefully circumscribed problems.

It happened during the optics unit, too. Light, when acting as a wave, reflects and refracts and diffracts. Why? Well, if you use a principle with no physical basis, you can derive some of the behaviors that light exhibits. But why would you use such a principle? Because you can derive some of the behaviors that light exhibits, of course.

But it’s much worse in modern physics. The foundation of quantum mechanics is the Schrödinger equation, which is a partial differential equation that treats particles as waves. Solutions to this equation are functions called Ψ (psi). What is Ψ? Well, it’s a function that, with some inputs, produces a complex number. Complex numbers have no physical meaning, however. For example, what would it mean to be the square root of negative one meters away from someone? Exactly.

So to get something useful out of Ψ, you have to square it. Doing so gives you the probability of finding a particle in some particular place or state. Why? Because you can’t be the square root of negative one meters away from someone, that’s why. The textbook draws a parallel between Ψ and the photon picture of diffraction, in which the square of something also represents a probability, but gives us no mathematical reason to believe this. Our professor didn’t even try and was in fact quite flippant about the hand-waving nature of the whole operation.

If you stick a particle (like an electron) inside of a box (like an atom), quantum mechanics and the Schrödinger equation tell you that the electron can only exist at specific energy levels. How do we find those energy levels? (This is the essence of atomic physics and chemistry, by the way.) Well, it involves “solving a transcendental equation by numerical approximation.” Great, let’s get started! “We won’t go into the details,” the textbook continues. Oh, I see.

Later, the textbook talks about quantum tunneling, the strange phenomenon by which particles on one side of a barrier can suddenly appear on the other side. How does this work? Well, it turns out the math is “fairly involved.” Oh, I see.

This kind of treatment goes on for much of the text.

Modern physics treats us as if we are high school students again. Explanations are either entirely absent or sketchy at best. Math is handed down on high in the form of equations to be used when needed. Insight is nowhere to be found.

Unfortunately, there might not be a great solution to this frustrating conundrum. While the basics of kinematics and electromagnetism can be understood with a couple semesters of calculus, modern physics seems to require a stronger mathematical foundation. But you can’t very well tell students to get back to the physics after a couple more years of math. That’s a surefire way to lose your students’ interest.

So we’re left with a primer course, where our appetites are whetted to the extent that our rudimentary tools allow. My interest in physics has not been stimulated, however. I’m no less interested than I was before, but what’s really on my mind is the math. More than the physics, I want to know the math behind it. No, I’m not saying I want to be a mathematician now. I’m just saying that I can’t be a physicist without being a little bit a mathematician.

Thursday, November 14, 2013

Complexification


This post may seem a little out there, but that might be the point.

Last week in differential equations we learned about a process our textbook called complexification. (You can go ahead and google that, but near as I can tell what you’ll find is only vaguely related to what my textbook is talking about.) Complexification is a way to take a differential equation that looks like it’s about sines and cosines and instead make it about complex exponentials. What does that mean?

Well, I think most people know a little bit about sine and cosine functions. At the very least, I think most people know what a sine wave looks like.

Shout out to Wikipedia.
Such a wave is produced by a function that looks something like f(x) = sin(x). Sine and cosine come from relationships between triangles and circles, but they can be used to model periodic, fluctuating motion. For example, the way in which alternating current goes back and forth between positive and negative is sinusoidal.

On the other hand, exponential functions don’t seem at all related. Exponential functions look something like f(x) = ex, and their graphs have shapes such as this:

Thanks again, Wikipedia.

Exponential functions are used to model systems such as population growth or the spread of a disease. These are systems where growth starts out small, but as the quantity being measured grows larger, so too does the rate of growth.

Now, at first blush there doesn’t appear to be a lot of common ground between sine functions and exponential functions. But it turns out there is, if you throw in complex numbers. What’s a complex number? It’s a number that includes i, the imaginary unit, which is defined to be the square root of -1. You may have heard of this before, or you may have only heard that you can’t take the square root of a negative number. Well, you can: you just call it i.

So what’s the connection? The connection is Euler’s formula, which looks like this:

eix = cos(x) + isin(x).

Explaining why this formula is true turns out to be very complicated and a bit beyond what I can do. So just trust me on this one. (Or look it up yourself and try to figure it out.) Regardless, by complexifying, you have found a connection between exponentials and sinusoids.

How does that help with differential equations? The answer is that complexifying your differential equation can often make it simpler to solve.

Take the following differential equation:

d2y/dt2 + ky = cos(x).

This could be a model of an undamped harmonic oscillator with a sinusoidal forcing function. It’s not really important what that means, except to say you would guess (guessing happens a lot in differential equations) that the solution to this equation involves sinusoidal functions. The problem is, you don’t know if it will involve sine, cosine, or some combination of the two. You can figure it out, but it takes a lot of messy algebra.

A simpler way to do it is by complexifying. You can guess instead that the solution will involve complex exponentials, and you can justify this guess through Euler’s formula. After all, there is a plain old cosine just sitting around in Euler’s formula, implying that the solution to your equation could involve a term such as eix.

This idea of complexification got me thinking about the topic of explaining things to people. You see, I think I tend to do a bit of complexifying myself a lot of the time. Now, I don’t mean I throw complex numbers into the mix when I don’t technically have to; rather, I think I complexify by adding more than is necessary to my explanations of things. I do this instead of simplifying.

Why would I do this? After all, simplifying your explanation is going to make it easier for people to understand. Complexifying, by comparison, should make things harder to understand. But complexifying can also show connections that weren’t immediately obvious beforehand. I mean, we just saw that complexifying shows a connection between exponential functions and sinusoidal functions. Another example is Euler’s identity, which can be arrived at by performing some algebra on Euler’s formula. It looks like this:

eiπ + 1 = 0

This is considered by some to be one of the most astounding equations in all of mathematics. It elegantly connects five of the most important numbers we’ve discovered. Stare at it for awhile and take it in. Can that identity really be true? Can those numbers really be connected like that? Yup.

That, I think, is the benefit of complexifying: letting us see what is not immediately obvious.

It turns out last week was also Carl Sagan’s birthday. This generated some hubbub, with some praising the man and others wishing we would just stop talking about him already. Carl Sagan was admittedly before my time, but he has had an impact on me nonetheless. No, he didn’t inspire me to study science or pick up the telescope or anything like that. But I am rather fond of his pale blue dot speech, to the extent that there’s even a minor plot point about it in one of my half-finished novels.

Now, I read some rather interesting criticism of Sagan and his pale blue dot stuff on a blog I frequent. A commenter was of the opinion that Sagan always made science seem grandiose and inaccessible. That’s an interesting take, but I happen to disagree. Instead, I think we might be able to conclude that Sagan engaged in a bit of complexifying. No, he certainly didn’t make his material more difficult to understand than it had to be; he was a very gifted communicator. What he did do, however, and this is especially apparent with the pale blue dot, is make his material seem very big, very out there. You might say he added more than was necessary.

In doing so, he showed connections that were not immediately obvious. The whole point of his pale blue dot speech is that we are very small fish in a very big pond, and that this connects us to each other. The distances and differences between people are, relatively speaking, absolutely miniscule. From the outer reaches of the solar system, all of humanity is just a pixel.

But there are more connections to be made. Not only are all us connected to each other; we’re also connected to the universe itself. Because, you see, from the outer reaches of the solar system, we’re just a pixel next to other pixels, and those other pixels are planets, stars, and interstellar gases. We’re all stardust, as has been said.

This idea that seeing the world as a tiny speck is transformative has been called by some (or maybe just Frank White) the overview effect. Many astronauts have reported experiencing euphoria and awe as a result of this effect. But going to space is expensive, especially compared to listening to Carl Sagan.

So yeah, maybe Sagan was a bit grandiose in the way he doled out his science. But I don’t think that’s a bad thing. I just think it shows the connection between Sagan and my differential equations class.