Sohcahtoa!

February 9, 2010

Mathematics can ask you to remember things that have no obvious connection to common sense. Either because it’s arbitrary (the name of a function in respect to what it computes) or because you haven’t quite figured all the details out. In either cases, a few mnemonics are always useful!

The first series of mnemonics you’ll learn is to remember constants. Constants like \pi and e have special importance in modern mathematics—beyond plain creepy piphilia.

The notation for \pi is due to William Jones who first used it in print in 1707. He chose \pi probably because it had some mnemonic connection to perimeter, which make sense given the context. The notation was adopted and popularized by Euler, which in turn introduced the notation e for the base of the natural logarithm. It appeared in print in 1736.[1]

The constants \pi and e are both transcendental irrational numbers.

The discipline of remembering digits of either—and of \pi in particular—has risen to Olympic levels. For every day use knowing the values to 6 or 16 digits is probably quite sufficient1. To remember \pi to 20 digits, the following English poem does the trick:

3      Pie
141592 I wish I could determine Pi
65358  Eureka, cried the great inventor
9793   Christmas pudding, Christmas pie
23846  Is the problem’s very center

And, indeed, \pi \approx 3.14159265358979323846264338327950288\ldots. For e, we have the same kind of poem:

2718281 We require a mnemonic to remember e

And, indeed, quite so, e \approx 2.71828182845904523536\ldots. If you really want a whole lot of digits, you can have a look at Simon Plouffe’s page of world records.

*
* *

Trigonometric functions such as sine, cosine, and tangent are somewhat named arbitrarily. Maybe not tangent, because, more than the two others, it suggest something of a straight line, a slope. Fortunately, there’s a rather simple—if Japanese-sounding—mnemonic for those. Take a deep breath and say it out loud: SOHCAHTOA!

Indeed, sine is opposite over hypotenuse, cosine is adjacent over hypotenuse, and tangent is opposite over adjacent:

*
* *

Keeping up with a Japanese theme, a friend of mine, understanding nothing of the right-hand rule, came up with a simple mnemonic for remembering the vector cross product rules:

\mathbf{ij} = \mathbf{k}

\mathbf{jk} = \mathbf{i}

\mathbf{ki} = \mathbf{j}

\mathbf{ji} = -\mathbf{k}

\mathbf{kj} = -\mathbf{i}

\mathbf{ik} = -\mathbf{j}

There’s also:

\mathbf{ii} = \mathbf{jj} = \mathbf{kk} = \mathbf{0}

Let us look at a mitsudomoe crest:

You can imagine it spinning clockwise:

or counter-clockwise:


If the mitsudomoe is spinning clockwise, pen down \mathbf{i}, \mathbf{j}, and \mathbf{k} in a clockwise manner:

If you read the products clockwise, the answer is the next vector clockwise. Indeed, \mathbf{ij}=\mathbf{k}.

The same works if you use it counter-clockwise: the answer is the next vector in counter-clockwise order: \mathbf{ji} = -\mathbf{k}.

You can recompute the identities using the definition of cross-product based on the matrix determinant:

\mathbf{a} \times \mathbf{b} = \det \left[~\begin{array}{ccc}\mathbf{i} & \mathbf{j} & \mathbf{k}\\a_1 & a_2 &a_3\\b_1 &b_2 & b_3\end{array}~\right]

But that’s a lot of work.

*
* *

Mnemonics are always useful, if you manage to remember them. I mean it seriously. I think it’s easier to remember \pi to 6 digits than to remember a 20-word poem. The clockwise/counter-clockwise analogy is a lot easier to remember if you’re a visual like I am.

*
* *

The Hidari Mitsudomoe images are based on a work released under the creative commons. The derived works complies with the license. The hiragana ’sohcahtoa’ calligraphy is mine, I retain full rights on this image.

References

[1] Florian Cajori — A History of Mathematical Notations — Dover, 1993 (also available in two volumes: V.1 and V.2).


1 6–7 decimal digits corresponds to the safe precision of IEEE 754 float, 16 corresponds to double.


Features I’d like to see in my Editor.

February 2, 2010

Do you ever have pipe-dreams about what you should be able to do with your computer? Like those crazy virtual interfaces like they had in the movie Minority Report or like every CSI lab seems to have? (well, that’s at the movies, of course). What about just more down-to-earth matters such as making large, complex documents such as source code more legible? I have few ideas—maybe a bit wacky.

Read the rest of this entry »


Those Pesky Applications!

January 26, 2010

Regardless of which operating you’re using, you’re bound to encounter applications that cause you problems. Some applications cause you problems so often that you eventually place a custom launcher or even a keyboard short-cut to a command that kills the applications. Firefox used to be one, but since version 3, it’s been much better. I still have problems, though now it’s always related to the Flash plug-in (which is rather troublesome in 64 bits mode). Another one that cause me problems regularly, is EvilEvolution, the Exchange client for Linux.

Young_Folks'_History_of_Rome_illus216

One essential *nix command you should know, is kill. The kill command dispatches a signal to a process, by default, SIGTERM. This message instructs the process to terminate. It can ignore the signal, but in general, it will close gracefully after freeing resources. If the program ignores the signal or is in an unstable state, you can kill it “harder” by using kill -9, which sends the process an unmaskable SIGKILL. The process terminates instantly under most circumstances.

Read the rest of this entry »


Bundling Memory Accesses (Part I)

January 19, 2010

There’s always a question whether having “more bits” in a CPU will help. Is 64 bits better than 16? If so, how? Is it only that you have bigger integers to count further? Or maybe more accessible memory? Well, quite obviously, being able to address a larger memory or performing arithmetic on larger number is quite useful because, well, 640KB isn’t all that much, and counting on 16 bits doesn’t get your that far.

AMD Phenom

But there are other advantages to using the widest registers available for computation. Often, algorithms that scan the memory using only small chunks—like bytes or words—can be sped up quite a bit using bundled reads/writes. Let us see how.

Read the rest of this entry »


Why Validating Input so Hard in C?

January 12, 2010

Validating input from file or keyboard is probably the most difficult thing to get right in C. Not only is it difficult to get right regardless of the programming language, C really doesn’t do much to help you. There’s the standard library, mostly accessible through the two headers <stdlib.h> and <stdio.h>. However, the facilities provided by the C library are rustic at best. They haven’t aged well, and they’re clunky.

Rusty_pincers-small

For this post, I will limit I/O validation to grabbing input from text files, whether through a redirection, pipe, file, or console input. I may discuss binary or highly structured formats like XML in a later post, but let us first limit ourselves to a few simple cases.

Read the rest of this entry »


Stir Fried Stupid

January 5, 2010

A well structured library will contain functions that are grouped together in a same logical unit to help you perform a set of tasks more easily. This could be reading graphics files, or managing time and dates. Good libraries include just enough functions so that you have access to the complete functionality, but nothing superfluous.

Too often, libraries catch featuritis and grow large with less used functions that were added at some point to scratch a minor hitch. Worst, you discover functions hidden in a library that you’re not sure what to do with them, but sometimes, you find functions that are positively stupid. What is even more surprising is where you can find them. I found a couple in the GNU C Library.

Read the rest of this entry »


Channel Mixing and Pseudo-Inverses

December 29, 2009

Let’s say we want to mix three channels onto two because the communication device has only two available channels but we still want to emulate a three channel link. If we can afford coding, then it’s not a problem because we can build our own protocol so add any number of channels using a structured data stream. But what if we cannot control the channel coding at all? In CDs, for example, there’s no coding: there are two channels encoded in PCM and a standard CD player wouldn’t understand the sound if it was encoded otherwise.

The solution is to mix the three channels in a quasi-reversible way, and in a way that the two channels can be listened to without much interference. One possible way is to mix the third channel is to use a phase-dependant encoding. Early “quadraphonic” audio systems did something quite similar. You can also use a plain time-domain “mixing matrix” to mix the three channels onto two. Quite expygeously, let us choose the matrix:

M=\left[~\begin{array}{ccc} \frac{2}{3} &0&\frac{1}{3}\\ 0 &\frac{2}{3}&\frac{1}{3}\end{array}~\right]

Read the rest of this entry »


Lost+Found: Ghostly Geometry

December 22, 2009

Live Video Color Gamut

December 22, 2009

The other day—well, a year ago or so—I was invited to visit CBC’s digital TV studios in Montréal by the SMPTE Montréal. We were shown around, even in the somewhat small control rooms. Amongst all the displays, dials, monitors, and misc. blinkenlights, I noticed a small LCD display showing an hexagonal projection of the current show’s color gamut in YC_rC_b (or maybe YP_bP_r?), probably for quality assessment purposes. I thought it was pretty cool, actually.

example-cropped

Let’s see how we can realize this projection with as little CPU time as possible.

Read the rest of this entry »


Wallpaper: Believe… or don’t

December 20, 2009

Believe, or dont. 1920×1200