Thursday, 23 April 2020

Why cavemen are called Ug

The earliest reference I can find to cavemen being called Og, Ug, Ugg, etc. is from A Child's History of the World by V.M. Hillyer (1924).

"The first people had hair growing, not just on their heads, but all over their bodies, like some shaggy dogs. They simply laid down on the ground when night came. They were bloodthirsty. They liked to drink the warm blood of animals they killed, as you would a glass of milk. They talked to each other with some sort of grunts—umfa umfa—glug glug."

I can't find anything before then on Google Books. Use of Glug or Ug as a name occurs in the 30's and 40's, sometimes in literature for children.

Wednesday, 15 April 2020

History of Russian peasant multiplication

I was curious about whether the Russian peasant multiplication method was ever used by Russian peasants.

I tracked it down to this French journal Journal de mathématiques élémentaires  (1896) pp. 22-23 which was edited by Gohierre de Longchamps.


Nous avons reçu de. M. Plackowo (à Tokarewka, gouvernement de Tamboff) la question suivante. Nous lui avons envoyé la solution qu'il désirait avoir de cette règle curieuse, practiquée par les paysans russe, règle qui évite la conaissance de la table de Pythagore. Cette démonstration est basée sur le système binaire de numération. Mais peut-être un de nos correspondants trouvera-t-il une solution plus simple.

We received from. Mr. Plackowo (in Tokarewka, Tamboff government) the following question. We sent him the solution he wanted of this curious method, practiced by Russian peasants, a method which avoids knowledge of the multiplication table. This demonstration is based on the binary number system. But perhaps one of our correspondents will find a simpler solution. 

I was able to find the reference to this because I am fortunate enough to have access to JSTOR. Google brought up this article:

Archibald, R. C. (1918). Undergraduate Mathematics Clubs. The American Mathematical Monthly, 25(3) 132-142


which contains a poor reference to the original publication:



Tamboff is known today as as Tambov while Tokarewka appears to be known as Tokaryovka.

The Bryan reference is here. The Bowen reference has more lousy referencing:


 Cosmos appears to be this, but I didn't find it online. It was only when I went looking for the E. Czuber reference that I found the proper reference in a German book (W. Ahrens (1918) "Altes und Neues aus der Unterhaltungsmathematik", p. 83) on Google Books ("dort Hinweis auf Journ. de mathém. élém. 1896, p. 22, 23, 37"), also quoting a comment "Wir möchten einen leisen Zweifel dazu äußern, daß russische Bauern wirklich auf diese Weise multiplizieren" (translation: we may express a slight doubt that Russian peasants really multiply this way") from the E. Czuber source. (I couldn't find the Czuber article online, though.)

Saturday, 30 January 2016

Editable garbage printed at bash prompt after printing binary file in an xterm

Sometimes I would have garbage printed at the bash prompt in xterm after printing a binary file, like

64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c62;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c64;1;2;6;9;15;18;21;22c

I've never got around to work out why, until now.

The reason is the presence of byte 9A in the file. See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html. This is the "DECID" control sequence, which should cause the terminal to send a response string (as if it had been typed by the operator). Equivalent to DA or "Send Device Attributes". The response string in this case is

64;1;2;6;9;15;18;21;22c

with some more bytes at the beginning (ESC ? or ESC >, I'm not sure which).

Friday, 8 January 2016

Meaning of lexical scope in Lisp

Lexical scope is described with the following:

Lexical scope. Here references to the established entity can occur only within certain program portions that are lexically (that is, textually) contained within the establishing construct

(Guy Steele et al (1989), Common Lisp the Language, 2nd edition, Chapter 3, Scope and Extent)

I think a nicer description is that lexical scope is early binding. It just so happens that all language constructs (lambdalet) that can create a binding for a variable that can be in effect when a function is defined happen to contain the textual region of the program where the variable is used.

I understood this from

Joel Moses (1970), The Function of FUNCTION in LISP

Saturday, 5 December 2015

Dealing with cyclical dependencies in C header files

Suppose source file A.c mostly deals with data structure A, which is defined in A.h. Likewise source file B.c mostly deals with data structure B, which is defined in B.h. A.h contains declarations of all the functions in A.c, and B.h contains declarations of all the functions in B.c.

Now we need to add a function to A.c which takes an argument of type B. To add a declaration of this function to A.h, we want a definition of type B to be in place in A.h. We do this by including B.h in A.h. This is intended to produce the effect that we can include A.h in another source file to declare the functions implemented in A.c, without requiring that source file to first include B.h.

Now suppose we add a function to B.c which takes an argument of type A. We do exactly the same in reverse.

What happens when a source file includes A.h now? A.h includes B.h at the start. B.h includes A.h at the start. We used include guards, so A.h is not included. When we reach a declaration of a function in B.h that has a parameter of type A, no definition of type A has been encountered yet, so there is an error.

This can be fixed by pulling the definitions of both A and B out into a separate header file, for example types.h. Forward declarations of types might work as well. (However, as far as I remember forward declaring a typedef isn't always accepted by C compilers.) In general, mixing function declarations and type definitions in header files may be problematical.

Friday, 11 September 2015

Law of Interface Responsiveness

Changes in response time between 0 and 1 seconds don't matter, because they're too small to notice.

Changes in response time between 1 and 10 seconds matter a lot, because the user will get bored waiting for it to finish.

Changes in response times above 10 seconds again don't matter, because the user is less likely to be sitting there waiting for it to finish, and will have gone and done something else.

Thursday, 3 September 2015

Mental arithmetic tips

For a sum like 8 * 26, imagine 26 -> 16 48, and when you have that clear in your head, smash them together to get 208.

To factorize a number less than a 1000, you only need to test divisibility by primes up to 31. There aren't that many of them: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 and 31.

To test for divisibility by 2, check if the last digit is divisible by 2. To check 3, check if the sum of the digits is divisible by 3. To check 5, check if the last digit is 5 or 0. To check 11, add and subtract alternative digits, for example 374 = 11 * 34, and 3 + 4 - 7 = 0.

The others are not so easy. For some of them, think of subtracting a multiple of the prime, for example

301 = 280 + 21 = 7 * 40 + 7 * 3 = 7 * 43.

Test the lower primes first, because they are more likely to succeed.

For the larger primes, you can memorize the composite numbers they are involved in:

23 * 23 = 529
23 * 29 = 667
23 * 31 = 713
29 * 29 = 841
29 * 31 = 899
31 * 31 = 961