a time to repeat

Consider the following decimal expansions:

$$\begin{aligned} \textstyle \frac{1}{ 1 } &= 1.0 & \textstyle \frac{1}{ 11 } &= 0.[09] & % 0.09090909090909091 \\ \textstyle \frac{1}{ 21 } &= 0.[04761\,9] \\ % 0.047619047619047616 \\ % \textstyle \frac{1}{ 2 } &= 0.5 & \textstyle \frac{1}{ 12 } &= 0.08[3] & % 0.08333333333333333 \\ \textstyle \frac{1}{ 22 } &= 0.0[45] \\ % 0.045454545454545456 \\ % \textstyle \frac{1}{ 3 } &= 0.[3] & % 0.3333333333333333 \\ \textstyle \frac{1}{ 13 } &= 0.[07692\,3] & % 0.07692307692307693 \\ \textstyle \frac{1}{ 23 } &= 0.[04347\,82608\,69565\,21739\,13] \\ % 0.043478260869565216 \\ % \textstyle \frac{1}{ 4 } &= 0.25 & \textstyle \frac{1}{ 14 } &= 0.0[71428\,5] & % 0.07142857142857142 \\ \textstyle \frac{1}{ 24 } &= 0.041[6] \\ % 0.041666666666666664 \\ % \textstyle \frac{1}{ 5 } &= 0.2 & \textstyle \frac{1}{ 15 } &= 0.0[6] & % 0.06666666666666667 \\ \textstyle \frac{1}{ 25 } &= 0.04 \\ % \textstyle \frac{1}{ 6 } &= 0.1[6] & % 0.16666666666666666 \\ \textstyle \frac{1}{ 16 } &= 0.0625 & \textstyle \frac{1}{ 26 } &= 0.0[38461\,5] \\ % 0.038461538461538464 \\ % \textstyle \frac{1}{ 7 } &= 0.[14285\,7] & % 0.14285714285714285 \\ \textstyle \frac{1}{ 17 } &= 0.[05882\,35294\,11764\,7] & % 0.058823529411764705 \\ \textstyle \frac{1}{ 27 } &= 0.[037] \\ % 0.037037037037037035 \\ % \textstyle \frac{1}{ 8 } &= 0.125 & \textstyle \frac{1}{ 18 } &= 0.0[5] & % 0.05555555555555555 \\ \textstyle \frac{1}{ 28 } &= 0.035[71428\,5] \\ % 0.03571428571428571 \\ % \textstyle \frac{1}{ 9 } &= 0.[1] & % 0.1111111111111111 \\ \textstyle \frac{1}{ 19 } &= 0.[05263\,15789\,47368\,421] & % 0.05263157894736842 \\ \textstyle \frac{1}{ 29 } &= 0.[03448\,27586\,20689\,65517\,24137\,931] \\ % 0.034482758620689655 \\ % \textstyle \frac{1}{ 10 } &= 0.1 & \textstyle \frac{1}{ 20 } &= 0.05 & \textstyle \frac{1}{ 30 } &= 0.0[3] \\ % 0.03333333333333333 \\ \end{aligned}$$

Each of these either terminates, like $\frac18 = 0.125$, or repeats, like $\frac{1}{27} = 0.[037]$. What determines the length of these repeating sequences?

Read more…

the fastest bird in the west

Here's a delightful little story about the SR-71 Blackbird, attributed to Major Brian Shul, USAF (Retired), that I'm going to duplicate here so that it's less likely disappear from the internet.

You can listen to Shul tell the story in a Youtube video, if that floats your boat (or flies your plane, I suppose). Doing both is amusing because the reported speed seems to have gotten larger as Shul has retold it. All good stories grow in retelling.

There were a lot of things we couldn't do in an SR-71, but we were the fastest guys on the block and loved reminding our fellow aviators of this fact. People often asked us if, because of this fact, it was fun to fly the jet. Fun would not be the first word I would use to describe flying this plane. Intense, maybe. Even cerebral. But there was one day in our Sled experience when we would have to say that it was pure fun to be the fastest guys out there, at least for a moment.


        An air-to-air overhead front view of an SR-71A strategic
        reconnaissance aircraft. The SR-71, unofficially known as the
        Blackbird, is a long-range, advanced, strategic reconnaissance
        aircraft developed from the Lockheed A-12 Oxcart and YF-12A
        aircraft. The United States Air Force retired its fleet of SR-71s
        on Jan. 26, 1990, but returned them in 1995 until
        January 1997. Throughout its nearly 24-year career, the SR-71
        remained the world's fastest and highest-flying operational
        aircraft. Location: Beale Air Force Base, California,
        USA. Evaporating fuel can be seen streaking down the fuselage and
        top of the wings from the aerial refueling port aft of the
        cockpit.

Read more…

it's only fitting

Here's a quick-n-dirty Gaussian curve fitter, which I seem to reinvent about twice a year. There are a number of canned solutions that I can never remember how to use, but I also frequently find myself wanting to fit weird functions.

Below in a minimum working example. But the short-short version is

def func(x, *params): ...
x,y = read_some_data()
guess_params = [...]

from scipy import optimize
better_params, covariance = optimize.curve_fit(
    func, x, y, p0=guess_params)

Read more…

fractal time and time again

In the Mandelbrot set — that is, the complex numbers $c$ for which the recurrence

$$\begin{aligned} z_{n+1} = z_n^2 + c \end{aligned}$$

remains finite — there are different regions of recurrence. Here's the classic picture. Let's play a bit.

The Mandelbrot set fractal

Read more…

there were microtonal bells

I am interested in hearing from perfect-pitchers and ethnomusicologists about this delightful physics-of-music video.

I'm particularly interested in an aside observation that the "least dissonant" major third based on this overtone analysis is a little flat relative to the equal-temperament major third. In choral singing, the conductor is always complaining that the major third needs to tune a bit higher.

division and conquest

Suppose I have some random process described by a binomial distribution, with "success" probability $p$. For $n$ trials, the expected number of "successes" obeys

$$\begin{aligned} P(k) &= {n\choose k} p^k (1-p)^{n-k} \end{aligned}$$

Now suppose I do a bunch of different sets of trials, such as practice exams of varying lengths. I want to model each practice exam as being drawn from a distribution of the appropriate size with the same probability. What's the right way to combine them?

Read more…

revenge of the kludge

I'm playing with termux-api, which exposes a bunch of Android API things to the termux command-line environment. I'm kind of afraid that I'm going to hack together an app using the command line. Excellent and hilarious and a terrible idea. The kind of procrastination that looks like work.

Read more…

your princess is in another window

I've been playing with tmux for making it possible to do more things from one terminal window. Today I realized that you can type tmux commands in one shell, and affect the contents of other windows. You can send keypresses. I knew from the interactive help (C-b ?) that you can send a pane within a window to a new window, but you can also capture panes from one window in another. The command language is the same that you can type at the C-b : command prompt; you can put them in a file and process (from anywhere) with tmux source.

But the cuteness for now is that I can do

make continuous 2>&1 | tmux splitw -dI &
make serve 2>&1 | tmux splitw -dI &

and have two long-running processes putting their outputs into one window, while I can control them from another.

Update: I learned a nicer way.

Read more…

apps from the shell

The incantation that I was looking for to start an Android app from within the shell is

am start --user 0 -n net.gsantner.markor/net.gsantner.markor.activity.MainActivity

The problem is identifying the name at the back.

Read more…

improbable units

When you compute the Poisson-distributed probability of observing $k$ events in some time interval, you find

$$\begin{aligned} P(k) &= \frac{e^{-λ} λ^k}{k!} \end{aligned}$$

where $λ$ is the mean number of observed events. Here $λ$ needs to be dimensionless, because it's in the argument to the exponent and it's being raise to some power. But if you graduate to the exponential distribution, which describes the waiting time between successive events, then $λ$ acquires units of inverse time:

$$\begin{aligned} \mathrm dP(t) &= λ e^{-λ t} \mathrm dt \end{aligned}$$

Things that magically change units bother me. What's happening here?

Read more…

on the phone again

What I'd like to be able to do here is to edit the blog on the phone. But that's going to take a fair amount of automation, because doing anything on the phone is hard.

However, I think I've gotten it.

Read more…

everything looks like a π

Here's a cute little computation. Suppose you pick two uniform random numbers. What's the probability that their ratio rounds to an even number? It's straightforward enough to get "this is a sum that looks like it's probably famous." But it turns out that different definitions of rounding pull in different transcendental constants.

Read more…

death is failure

In the probability of discrete events like coin tosses, you usually write $p$ to represent the probability of a success and $q=1-p$ to represent the probability of failure.

actuarial text

i'm on the phone

I've been trying to get to a point where I can edit my nikola blog stuff on my phone, and I am slowly figuring out how. Android does lots of careful sandboxing, and I have to work to undo it — especially since my preferred Android text editor, Markor, is intentionally unaware of any kind of sharing. I'm going to end up doing stuff in make, I'm afraid.

Read more…

markdown made easy

The installation for Jason Blevins' markdown-mode is so easy that I thought I wouldn't bother to write it down … but then I looked in my note-taking place and I couldn't find it.

It's as simple as M-x package-install RET markdown-mode RET.

Everybody is using a package manager these days, and it's great.