Math Equations

Friday, December 27, 2013

Organizing your videos

If you are like me, that is if you save your downloaded videos even after you've watched them, then your video folder is likely to be very ugly. When looking for the latest episode of a show, you may find yourself scrolling through multiple pages of obscure file names like "The.Shawshank.Redemption.1994.SWESUB.AC3.720p.BRRip.avi". Wouldn't it be nice if all file names were simple, like "The Shawshank Redemption.avi"?

At least that's what I thought so I created an application to do the job of renaming files. It's called vorg and you can download it at GitHub. Not only does it rename the files, it also organizes similar files into subdirectories. I'll give you an example below. Try it out!

joel@desktop:~/Video$ vorg . --recursive --clean 1M --ask-clean

Downloading subtitles the easy way

Don't you just love it when you are watching your favorite tv series and you can't hear what's being said? Don't you just love going through the same process of downloading subtitles through your web browser for each episode?

You probably don't. Therefore, have a look at addic7ed-cli at GitHub. This is an application which, given the file name of an episode, downloads subtitles from addic7ed.com. One command line and you are done. The downloaded subtitle file will even be renamed to match the video file.

Frequency multiples

Many people know that an octave is a combination of two frequencies \(2f_1 = f_2\). For example, the tones A3 and A4 combined will yield an octave because f(A3) = 220 Hz and f(A4) = 440 Hz and so f(A4) = f(A3) * 2.

An octave. Original image taken from http://www.psrtutorial.com/music/articles/cp33.html.

Given a tone X, this post will show you how to approximate another tone Y such that f(Y) = f(X) * n for positive integers n other than 2.

For some integer k, Y is k half steps to the right of X on a piano. This means roughly f(Y) = f(X) * 2 ^ (k / 12) because of how pianos are tuned. We now have two expressions for f(Y), which we may equate:
$$f(X) * n = f(X) * 2 ^ {k / 12}\\
n = 2 ^ {k / 12}\\
\ln{n} = \ln{2 ^ {k / 12}} = \frac{k\ln{2}}{12}\\
k = \frac{12\ln{n}}{\ln{2}}$$

Let's try it! If n = 2 then the combination of the tones will be an octave, so we expect k to be the distance in half tones between for example A3 and A4, which is 12. As it turns out, the expression above does predict that k = 12.

We may delve further into the problem by letting n = 3. This gives us the somewhat unexpected result k = 19.02. We want k to be an integer so we have to round it. Our new general approximation is:
$$k = round(\frac{12\ln{n}}{\ln{2}})$$

I think we are ready to let the computer handle the rest. Python code:
    from math import log
    for i in xrange(1, 20):
        print int(round(12 * log(i) / log(2))),

Output: 0 12 19 24 28 31 34 36 38 40 42 43 44 46 47 48 49 50 51

I have marked these tones in the picture below. The funny thing is, the first six tones are the chord A major.

DB25 wire colors

These are the colors of the wires of the male-to-male parallel port cable that I bought at eBay. Those which I'm interested in are Di (0 <= i <= 7), i.e. all the way from non-striped red to non-striped light blue. Supposedly, these can be set to +0V or +5V relative to ground (e.g. striped white) by the operating system.

Pluscurves and minuscurves

To get the pluscurve of some curve C, you look for where its tangents intersect the axes. Say a tangent intersects the axes at (a, 0) and (0, b). Then (a, b) lies on the pluscurve of C.

Getting the minuscurve is a little trickier. I don't have a solid definition for it. However the basic idea is that, for any point (a, b)  (0, 0) on some curve C you draw a line, called a minusline, between (a, 0) and (0, b). Do this for all points (a, b) on C. The union of the points on all minuslines will look like one or several contiguous regions in the plane. The border of the regions is the minuscurve of C.

For example, the blue region in the picture below has an interesting border in the first quadrant. That border is a minuscurve. By the end of this post, you will be able to describe that shape algebraically!
A set of minuslines making up a contiguous region.
An interesting idea is that the pluscurve of the minuscurve of C might be C alone. Is this always the case? I don't know.

The pluscurve of ax + by + c = 0

The tangents of the line are simply the line itself. Assuming the line is non-horizontal and non-vertical it intersects the axes at (-c/a, 0) and (0, -c/b). Thus the pluscurve of the line is the point (-c/a, -c/b).

The plus- and minuscurves of xy = 1

xy = 1 in black and its pluscurve in dashed red.
The pluscurve seems to be xy = 4 whereas the minuscurve seems to be xy = 1/4. I used the nice cross-platform tool GeoGebra to visualise this. These are the GeoGebra files I created: plusminus. What about the more general case xy = c? Is the pluscurve xy = 4c? 4c²?

I'll now derive the answer to that question. See the figure below. H is the hyperbola xy = c. It is parametrised by the point P = (t, c/t). For every P there is a corresponding P⁺ which lies on the pluscurve H⁺ of H.
We find P⁺ by observing where the tangent intersects the axes. To do that we need the equation of the tangent. Some linear algebra and calculus yields \(\frac{-1}{2t}x + \frac{-t}{2c}y + 1 = 0\). The intersection points are then readily obtained as (2t, 0) and (0, 2c/t). This means \(P^+ = (2 t, \frac{2c}{t})\) and that H⁺ obeys \(x y = 2 t \frac{2c}{t} = 4c\).

The plus- and minuscurves of the unit circle

Once again I used GeoGebra. It seems that the first quadrant part of the pluscurve is one branch of the hyperbola \((x - 1)(y - 1) = (\sqrt{2} - 1)^2\) and that the curve is symmetric about both the x and y axes. The minuscurve appears to have no points on it. However, the minuscurve of the first quadrant portion of the unit circle does exist. It looks almost exactly like the ellipse \(x^2 - x y + y^2 - 3x - 3y + 2 = 0\) near the origin:
Trying to approximate the border of the shaded area with an ellipse.

The minuscurve of x + y = k (a parabola!)

Minuscurve of x + y = 1
Let's assume that k > 0 so that the set of minuslines of the curve looks like the picture above. For now, we are interested in the region \(0 \leq x \leq k\). The minuslines may be parametrized as lines passing through (t, 0) and (0, k - t). The equation of the lines is \(y = \frac{(k - t) - 0}{ 0 - t} (x - t) + 0 = \frac{t - k}{t} (x - t)\). For every x we want to find the t that gives the greatest y. Therefore we differentiate y with respect to t and look for \(\frac{dy}{dt} = 0\). (If we weren't so lazy we would assure ourselves that the second derivative is negative.)
$$y = \frac{tx - t^2 - kx + kt}{t} = x + k - t - \frac{kx}{t}\\
0 = \frac{dy}{dt} = \frac{kx}{t^2} - 1\\
t^2 = kx\\
t = \sqrt{kx}\\
y = x + k - \sqrt{kx} - \frac{kx}{\sqrt{kx}} = x + k - 2\sqrt{kx} = (\sqrt{k} - \sqrt{x})^2\\
\sqrt{y} = abs(\sqrt{k} - \sqrt{x}) = \sqrt{k} - \sqrt{x}\\
\sqrt{x} + \sqrt{y} = \sqrt{k}$$
This is actually a parabola! The major axis is y = x. We can see this if we square both sides and rotate it 45 degrees. We expect to get an equation of the form y = ax^2 + b. So, first
$$x + 2\sqrt{x}\sqrt{y} + y = k\\
2\sqrt{x}\sqrt{y} = k - x - y\\
4xy = (k - x - y)^2\\
x^2 - 2xy + y^2 - 2kx - 2ky + k^2 = 0.$$
Then, after rotation (see Wikipedia or page 466 of "Calculus" 7th ed. by Robert A. Adams), we have
$$2x^2 - 2\sqrt{2}ky + k^2 = 0\\
y = \frac{2x^2 + k^2}{2\sqrt{2}k}$$

Some closing thoughts

In the special cases we've tried, we have found that branches of plus- and minus curves of conics are also branches of conics. Because conics are rather simple being second degree equations and because simple things have meaning, plus- and minuscurves have meaning. Chances are we will find an application for them.

First post

I've been thinking for a while to start a blog: a place to write things which matter enough not to be forgotten. Anyone with the same interests as me will find my posts interesting and entertaining. Having said that I think it would be a good idea to tell you what my main interests are:

  • Mathematics - patterns like fractals; the roots of polynomials; most anything
  • Music - polyrhythms; generating music
  • Computers - solving problems which arise; how they work; the possibility of simulating life

Some sneak peeks that are sure to make you interested: