atlas news
John D.Cook : Python
27 march
11h33
Computing sine and cosine of complex arguments with only real functions
John
Suppose you have a calculator or math library that only handles real arguments but you need to evaluate sin(3 4i). What do you do? If you’re using...
20 march
16h58
Embedded regex flags
John
The hardest part of using regular expressions is not crafting regular expressions per se. In my opinion, the two hardest parts are minor syntax...
17 march
13h22
Tone row operations
John
The previous post introduced the idea of a twelve-tone row, a permutation of the twelve pitch classes of a chromatic scale. The earlier post also...
10 march
16h08
Simplifying expressions in SymPy
John
The previous post looked at why Mathematica does not simplify the expression Sinh[ArcCosh[x]] the way you might think it should. This post will be a...
16 november
19h13
Adding an imaginary unit to a finite field
John
Let p be a prime number. Then the integers mod p form a finite field. The number of elements in a finite field must be a power of a prime, i.e. the...
21 august
13h55
A recipe for creating random fractals
John
Last week I gave an example of a randomly generated fractal and mentioned that it was a particularly special case of a more general algorithm for...
31 july
01h11
Base58Check encoding in Python
John
The previous post began by saying Bitcoin’s Wallet Import Format (WIF) is essentially Base58 encoding with a checksum. More specifically, WIF uses...
16 december
17h03
Perpetual Calendars
John
The previous post explained why the Gregorian calendar is the way it is, and that it consists of a whole number of weeks. It follows that the...
21 march
01h07
MD5 hash collision example
John
Marc Stevens gave an example of two alphanumeric strings that differ in only one byte that have the same MD5 hash value. It may seem like beating a...
04 march
18h55
Finite differences and Pascal’s triangle
John
The key to solving a lot of elementary what-number-comes-next puzzles is to take first or second differences. For example, if asked what the next...
10 february
15h45
Factoring pseudoprimes
John
Fermat’s little theorem says that if p is a prime number, then for any positive integer b p we have bpâ ’1 1 (mod p). This theorem gives a necessary...
01 january
21h12
Computing inverse factorial
John
I needed the inverse factorial function for my previous post. I was sure I’d written a post on computing the inverse factorial, and intended to reuse...
20 november
11h55
Kepler triangle
John
A Kepler triangle is a right triangle whose sides are in geometric progression. That is, if the sides have length a b c, then b a c b k. All Kepler...
28 september
23h24
Cross-platform way to enter Unicode characters
John
The previous post describes the hoops I jumped through to enter Unicode characters on a Mac. Here’s a script to run from the command line that will...
27 august
21h47
Curvature at Cairo
John
I was flipping through Gravitation [1] this weekend and was curious about an illustration on page 309. This post reproduces that graph. The graph is...
20h02
Calculating the intersection of two circles
John
Given the equations for two circles, how can you tell whether they intersect? And if they do intersect, how do you find the point(s) of intersection?...
18 july
19h04
Filtering on how words are being used
John
Yesterday I wrote about how you could use the spaCy Python library to find proper nouns in a document. Now suppose you want to refine this and find...
23 may
13h44
AM over GM
John
Suppose you take the arithmetic mean and the geometric mean of the first n integers. The ratio of these two means converges to e 2 as n grows [1]. In...
29 april
14h56
Golden integration
John
Let Ï be the golden ratio. The fractional parts of nÏ bounce around in the unit interval in a sort of random way. Technically, the sequence is quasi...
30 november
01h15
Elliptic functions of a complex argument in Python
John
I used Mathematica to create the graphics for my previous two posts because SciPy didn’t have the functions I needed. In particular, elliptic...
16 november
13h35
When a cubic or quartic has a double root
John
Thanks to the quadratic equation, it’s easy to tell whether a quadratic equation has a double root. The equation has a double root if and only if the...
15 october
14h40
Using Python as a statistical calculator
John
This post is for someone unfamiliar with SciPy who wants to use Python to do basic statistical calculations. More specifically, this post will look...
07 october
12h33
Unicode numbers
John
There are 10 digits in ASCII, and I bet you can guess what they are. In ASCII, a digit is a decimal is a number. Things are much wilder in Unicode....
06 october
21h39
Regex to match ICD-11 code
John
ICD codes are diagnostic codes created by the WHO. (Three TLAs in just the opening paragraph ) The latest version, ICD-11, went into effect in...
06 september
00h17
Literate programming to reduce errors
John
I had some errors in a recent blog post that might have been eliminated if I had programmatically generated the content of the post rather than...
04 september
11h00
Computing VIN checksums
John
I’ve had to work a little with VIN numbers lately, and so I looked back at a post I wrote on the subject three years ago. That post goes into the...
16 august
18h40
Dump a pickle file to a readable text file
John
I got a data file from a client recently in pickle format. I happen to know that pickle is a binary format for serializing Python objects, but trying...
15 august
13h24
Keeping data and code together with org-mode
John
With org-mode you can keep data, code, and documentation in one file. Suppose you have an org-mode file containing the following table. # NAME...
03 august
13h05
Inline computed content in org-mode
John
The previous post discussed how to use org-mode as a notebook. You can have blocks of code and blocks of results, analogous to cells in a Jupyter...
02 august
14h49
Org-mode as a lightweight notebook
John
You can think of org-mode as simply a kind of markdown, a plain text file that can be exported to fancier formats such as HTML or PDF. It’s a lot...
1781264331