09/01/2018
Recently on Freenode channel ##cpp, I saw some code using an include-all-you-can header. The idea was to help beginners to the language, help them start programming without having to remember which header was which, and which headers are needed.
Is that really a good idea?
Read the rest of this entry »
Leave a Comment » |
C-plus-plus, hacks, programming | Tagged: C, C Preprocessor, cmath, cpp, cstddef, cstdint, fstream, iomanip, iostream, list, Map, stl, Vector |
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
05/12/2017
About a week ago, some dude drops on IRC that he’s beat memcpy “by a lot”. That’d be interesting, except that we couldn’t get neither code nor test methodology out of him. But, how hard can making a better memcpy be? Turns out, harder than you think!

If you think this is a typical case of “reinventing the wheel”, I mostly agree with you. But while reinventing will be hard, can improvements be made?
Read the rest of this entry »
Leave a Comment » |
C-plus-plus, hacks | Tagged: assembly language, C, code optimization, Compiler, memcpy, movsb, movsd, movsq, vmovdqu |
Permalink
Posted by Steven Pigeon
28/11/2017
I’m currently working with one of my students on a laser-based range finder. To assess the precision of the device, I needed a calibration piece. Because of the setup, the piece should look like a stair.

The piece should allow a wide range of different readings, say from 1 to 10 centimeters in known increments, say, 1cm. The naïve way of building such a piece is to build a stair with 10 steps. However, if you do it like this, the piece is wide, cumbersomely so. Is there a much better way to do so?
Read the rest of this entry »
1 Comment |
hacks, Mathematics, Science | Tagged: Fibonacci Numbers, High Precision, Laser, Machining, permutation, Range, Range Finding, Zeckendorf, Zeckendorf's Theorem |
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
14/11/2017
Since we now have minimal ANSI support, we can use it. Of course, for cute things such as changing text color (red for error, green for OK, etc.), but that’s not very amusing. Let’s make some ANSI ART!!1!

Read the rest of this entry »
Leave a Comment » |
bit twiddling, hacks | Tagged: 24 bits, Amiga, ANSI, color, Mona Lisa, Monaka, Palm Trees, Semigraphics, TRS-80, TRS-80 Color Computer |
Permalink
Posted by Steven Pigeon
07/11/2017
ANSI art and poor resolution may appeal to the nostalgic, those in want of the time when BBS were still it and the IBM PC’s programmable character set was the nec plus ultra of semigraphics, but they’re not really useful. At best, we can use them to dispense ourselves from using ncurse and still getting some colors and effects

However, “semigraphics” may have their use in lossy data compression, were we allow some data to be lost to gain some more compression. That may be especially true when we have very little computing power or if we want to have many simple CPUs in parallel doing the decoding.
Read the rest of this entry »
Leave a Comment » |
data compression, hacks | Tagged: 5:6:5, BBS, compression, DXT1, IBM PC, Resolution, Semigraphics |
Permalink
Posted by Steven Pigeon