# Interests

## Mechanical Calculators

I collect (hand-held) mechanical calculators. I am aways looking for weird and interesting devices. Here are some calculators in my collection

*Curta*

(see the picture on the left) a hand held mechanical calculator which can add, subtract, multiply, divide and compute square roots (1948 - 1970s).

*Consul, the Educated Monkey*

a mechanical calculator in the form of a monkey, constructed of enameled sheet metal, around 1916.

*Correntator*

a slide adder from the 1920s.

*Addiator*

a mechanical addition/subtraction calculator (1920s).

## Reading Material

This is an incomplete list of {technical, fantasy} books I highly recommend to anyone iterested in cryptology, applied mathematics or fantasy.

### Cryptography, Mathematics and Computer Science

Books every computer scientist or applied mathematician should have on its bookshelf include

- The Art of Computer Programming (TAOCP), Donald E. Knuth, all four volumes
- Volume 1: Fundamental Algorithms, Third Edition (Reading, Massachusetts: Addison-Wesley, 1997), xx+650pp. ISBN 0-201-89683-4
- Volume 2: Seminumerical Algorithms, Third Edition (Reading, Massachusetts: Addison-Wesley, 1997), xiv+762pp. ISBN 0-201-89684-2
- Volume 3: Sorting and Searching, Second Edition (Reading, Massachusetts: Addison-Wesley, 1998), xiv+780pp.+foldout. ISBN 0-201-89685-0
- Volume 4a: Combinatorial Algorithms, Part 1 (Upper Saddle River, New Jersey: Addison-Wesley, 2011), xvi+883pp. ISBN 0-201-03804-8

- Prime Numbers: A Computational Perspective, Richard Crandall and Carl B. Pomerance, 2nd ed. 2005, XVI, 597 p, Springer

Crypto books which have (all) chapters available for free download

- Topics in Computational Number Theory Inspired by Peter L. Montgomery, Joppe W. Bos and Arjen K. Lenstra, Cambridge University Press, 2017
- Mathematics of Public Key Cryptography, Steven Galbraith, Cambridge University Press, 2012
- A Computational Introduction to Number Theory and Algebra, version 2, Victor Shoup, Cambridge University Press, 2008
- Handbook of Applied Cryptography, 5th printing, Alfred J. Menezes, Paul C. van Oorschot and Scott A. Vanstone, CRC Press, 2001
- Modern Computer Arithmetic, Richard P. Brent and Paul Zimmermann, Cambridge University Press, 2010

### Fantasy and Science Fiction

- The Discworld Series by Terry Pratchett
- Cryptonomicon by Neal Stephenson (2009)
- Malazan Book of the Fallen (series) by Steven Erikson (1999-2011)
- The Kingkiller Chronicle by Patrick Rothfuss (2007 - )
- Hyperion by Dan Simmons (1989)
- The Stormlight Archive by Brandon Sanderson (2010 - )
- The Wheel of Time by Robert Jordan (1990 - 2013)

## Programming & Tips

I enjoy learning about programming gems and tricks to compute things efficiently or in a different way (mainly for the C-programming language).

### Bit Twiddling Hacks

A comprehensive summary of tricks to compute various basic computer operations on single computer word integers can be found at the

*Bit Twiddling Hacks*page.

### Duff’s device

Tom Duff attempted to optimize the following routine, abstracted from code which copies an array of shorts into the Programmed IO data register of an Evans & Sutherland Picture System II:

send(to, from, count) register short *to, *from; register count; do { *to = *from++; } while(--count>0);

His idea was to unwind this loop but he had to deal with the partial leftover loop. He came up with the following routine which nicely abuses the C-programming language:

send(to, from, count) register short *to, *from; register count; register n=(count+7)/8; switch(count%8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while(--n>0); }

## Modular inversion

The following function computes modular inversion (a^{−1} mod modulus) for a prime modulus and a>1 (which both fit into a standard int datatype) very efficiently. This function is from this thread on the Mersenne forum.

int single_modinv (int a, int modulus) { int ps1, ps2, parity, dividend, divisor, rem, q, t; q = 1; rem = a; dividend = modulus; divisor = a; ps1 = 1; ps2 = 0; parity = 0; while (divisor > 1) { rem = dividend - divisor; t = rem - divisor; if (t >= 0) { q += ps1; rem = t; t -= divisor; if (t >= 0) { q += ps1; rem = t; t -= divisor; if (t >= 0) { q += ps1; rem = t; t -= divisor; if (t >= 0) { q += ps1; rem = t; t -= divisor; if (t >= 0) { q += ps1; rem = t; t -= divisor; if (t >= 0) { q += ps1; rem = t; t -= divisor; if (t >= 0) { q += ps1; rem = t; t -= divisor; if (t >= 0) { q += ps1; rem = t; if (rem >= divisor) { q = dividend / divisor; rem = dividend % divisor; q *= ps1; }}}}}}}}} q += ps2; parity = ~parity; dividend = divisor; divisor = rem; ps2 = ps1; ps1 = q; } if (parity == 0) return (ps1); else return (modulus - ps1); }