20/02/2018
I’ve discussed algorithms for computing square roots a couple of times already, and then some. While sorting notes, I’ve came across something interesting: Archytas’ method for computing square roots.

Archytas’ method is basically the old Babylonian method, where you first set
,
,
and iterate
,
,
until desired precision is achieved (or the scribe is exhausted).
Read the rest of this entry »
Leave a Comment » |
algorithms, hacks, Mathematics | Tagged: Archytas, Newton's Method, Old Babylonian, Square root |
Permalink
Posted by Steven Pigeon
06/02/2018
So 3-cells context elementary automata seem too “self-correcting” to be useful pseudo-random generators. What if we fixed that boundary problem and have the automaton run on a cylinder (with both end joined)? What if we augment the context from 3 to 5 cells?
Read the rest of this entry »
Leave a Comment » |
algorithms, Mathematics | Tagged: Cellular automaton, Chaos, pseudo-random number generator, Rule 0x69969669, Rule 0xa55a5aa5 |
Permalink
Posted by Steven Pigeon
30/01/2018
I was rather discontented with last week’s post results. Most automata seemed to produce self-correcting patterns, even when seeded randomly—one could argue that rand() isn’t the strongest random generator, but that wasn’t the problem. No, indeed, most automata exhibit self-correcting behavior, forming the same self-similar pattern, or worse, the same periodic pattern.

So I made a few more experiments with random seeds and larger images. The code isn’t very complicated and isn’t of interest in itself, but it reveals a couple of interesting things.
Read the rest of this entry »
Leave a Comment » |
algorithms, Mathematics | Tagged: Cellular automaton, Chaos, pseudo-random number generator, Rule 105, Rule 60 |
Permalink
Posted by Steven Pigeon
23/01/2018
A while ago, Wolfram (re)introduced elementary cellular automata, a special case of cellular automata that lives in one dimension. One cutesy aspect of these automata is that the rules are easy to describe and number. As any automata, it is given a context, a region of interest, and gives an output depending on the context. For example, we can have the rules:
| Context |
output |
| 000 |
1 |
| 001 |
0 |
| 010 |
1 |
| 011 |
0 |
| 100 |
1 |
| 101 |
0 |
| 110 |
1 |
| 111 |
1 |
The output column can be viewed as a number, in this case 11010101, 0xd5, or 213. This is rule 213.
It may be tempting to use those to generate chaos, noise, and random numbers. But is it that a good idea?
Read the rest of this entry »
1 Comment |
algorithms, Mathematics | Tagged: Cellular automaton, Chaos, pseudo-random number generator, Rule 110, Rule 34, Wolfram |
Permalink
Posted by Steven Pigeon
02/01/2018
Quite a while ago, I wrote a post on how to compute an arbitrarily large Fibonacci number
in essentially
steps. Turns out, that technique generalizes to other recurrence relations, and of any order.

Read the rest of this entry »
Leave a Comment » |
algorithms, Mathematics | Tagged: fast exponentiation, Fibonacci, linear algebra, Matrix Product, Recurrence, Recurrence relation, Strassen, Strassen's algorithm |
Permalink
Posted by Steven Pigeon
26/12/2017
We don’t usually think of linear algebra being compatible with derivatives, but it very useful to be able to know the derivative of certain elements in order to adjust them—basically using gradient-descent.
We might therefore ask ourselves questions like, how do I compute the derivative of a scalar product relative to one of the vector elements? Of a matrix-vector product? Through a matrix inverse? Through a product of matrices? Let’s answer the first two questions for now.
Read the rest of this entry »
2 Comments |
algorithms, machine learning, Mathematics | Tagged: Derivative, dot product, Machine Learning, Matrix, scalar product, Vector |
Permalink
Posted by Steven Pigeon
19/12/2017
A Taylor series for a function
around
that is
times differentiable is given by

or
,
where
is the
th derivative of
at
.
Have you ever wondered where the coefficients in a Taylor series come from? Well, let’s see!
Read the rest of this entry »
Leave a Comment » |
algorithms, hacks, Mathematics | Tagged: Analytic, Analytical Function, Derivatives, Numerical Approximation, numerical method, Taylor, Taylor Series |
Permalink
Posted by Steven Pigeon
12/12/2017
Getting good text data for language-model training isn’t as easy as it sounds. First, you have to find a large corpus. Second, you must clean it up!

Read the rest of this entry »
Leave a Comment » |
algorithms, Bash (Shell), hacks | Tagged: ASCII, bash, CRLF, grep, Gutenberg project, ISO-8859-15, sed, tr, UTF-8, Windows codepage |
Permalink
Posted by Steven Pigeon
21/11/2017
Von Neumann proposed the middle square method of generating pseudo-random numbers in 1949, in a paper published a bit later. The method is simple: you take a seed, say 4 digits long, you square it, and extract the middle 4 digits, which become the next seed. For example:
.
While it seems random enough, is it?
Read the rest of this entry »
6 Comments |
algorithms, Mathematics | Tagged: GraphViz, middle square, pseudo-random number generator, square, von Neumann |
Permalink
Posted by Steven Pigeon
10/10/2017
Last week, we noticed a fun connection between lattices and fractions, which helped us get rational approximations to real numbers. Since only points close to the (real-sloped) line are of interests, only those points representing fractions are candidates for rational approximation, and the closer to the line they are, the better.
But what if we find a point real close to the line? What information can we use to refine our guess?
Read the rest of this entry »
2 Comments |
algorithms, Mathematics | Tagged: epsilon, Iterative, machine precision, Pi, rational approximation |
Permalink
Posted by Steven Pigeon