On a number of previous occasions, I have used the *pseudoinverse* of a matrix solve systems of equations, and do other things such as channel mixing. However, the demonstration I gave before isn’t entirely correct. Let’s see now why it’s important to make the difference between a left and a right pseudoinverse.

## Choosing the Right Pseudoinverse

January 17, 2017## Strings in C++ Switch/Case statements

January 10, 2017Something that used to bug me—used to, because I am so accustomed to work around it that I rarely notice the problem—is that in neither C nor C++ you can use strings (`const char *` or `std::string`) in switch/case statement. Indeed, the switch/case statement works only on integral values (an `enum`, an integral type such as `char` and `int`, or an object type with implicit cast to an integral type). But strings aren’t of integral types!

In pure C, we’re pretty much done for. The C preprocessor is too weak to help us built compile-time expression out of strings (or, more exactly, `const char *`), and there’sn’t much else in the language to help us. However, things are a bit different in C++.

## Logarithms (Part I?)

January 3, 2017The traditional—but certainly not the best—way to compute the value of the logarithm of some number is to use a Taylor series, for example

but that expansion is only valid for , or so, because it is the Taylor expansion of "around 1", and the convergence radius of this particular expression isn't very large. Furthermore, it needs a great deal of terms before converging.

## Size(_t) matters!

December 27, 2016Sometime last week, a tweet from @nixCraft prompted the question, quite ironically, how do you get the maximum (largest positive) value for an integer?

## π, π, Archimedes!

December 20, 2016This week, another derivation for a famous formula: Archimedes’

formula for π.

Some time in the 3rd century BC, Archimedes used the perimeter of a regular polygon, starting with an hexagon and repeatedly doubling the number of sides, to estimate the value for π. He arrived at the approximation

.

How he arrived to this result is a bit mysterious until we completely understand how he got that result. Let’s see together how he did it.

## Binet’s Formula

December 13, 2016You will encounter a large number of formulas in your life, and quite many of them just seem to come out of the blue. That’s fortunately quite false, despite it being not always easy to retrace the formulas’ authors’ steps. One that appears as suspicious as it seems magic, is Binet’s Fibonacci Number formula:

,

where

is the golden number.

But it’s not quite out of nowhere, and, if you know how to solve recurrences using the characteristic equation, it’s in fact quite straightforward. Let’s see how.

## Pretty Printing a Tree in a Terminal

December 6, 2016More often than I’d like, simple tasks turn out to be not that simple. For example, displaying (beautifully) a binary tree for debugging purpose in a terminal. Of course, one could still use lots of parentheses, but that does not lend itself to a very fast assessment of the tree. We could, however, use box drawing characters, as in DOS’s goode olde tymes, since they’re now part of the Unicode standard.