Daily Archives: 9/5/2006

Toying with a lesser known Goldbach Conjecture…

While reading Beiler’s Recreations in the Theory of Numbers, I ran across this rather odd conjecture attributed to Goldbach: that all odd numbers are either prime, or can be expressed as the sum of a prime and twice a square. That seemed rather interesting. There were two known exceptions, in particular 5777 and 5993, which could not be so expressed. It turns out that even among primes, most primes can be written as a similar sum. Those that cannot are apparently called “Stern Primes”. I thought that I’d write a little Python gizmo to check that out.

Sure enough, one small Python script later, and 3m49s of runtime, we get….

3 is not the sum of a prime and twice a square
17 is not the sum of a prime and twice a square
137 is not the sum of a prime and twice a square
227 is not the sum of a prime and twice a square
977 is not the sum of a prime and twice a square
1187 is not the sum of a prime and twice a square
1493 is not the sum of a prime and twice a square
5777 is not the sum of a prime and twice a square
5993 is not the sum of a prime and twice a square

The first eight are all prime (in fact, the only known Stern primes). The last two are composite.
There are no other such numbers smaller than ten million (yes, the script tried them all).

You can read more about this conjecture here and the WIkipedia entry on Stern primes here.

[tags]Mathematics[/tags]

Addendum: I rewrote the program in C, and ran it up until max value = 1,073,741,824. The C version took only 1m41s on my faster workstation, and verified that there were no additional odd numbers that could not be so expressed that were smaller than 2^30th.

Creating Vector Artwork from Raster Scans

A couple of days ago, I got bitten by the bug again to think about trying to actually commit some of my braincells to the learning of some Mayan hieroglyphs, and maybe make a program which actually could draw dates written in the Mayan long count calendar. To do that, I needed some bitmaps of the glyphs. Luckily, if you dig around, you can find a zip file with all sorts of Maya glyphs in it. An example glyph looks like:

Glyph 10500

Not bad, but not exactly pretty either. The resolution is pretty low, and it isn’t even antialiased. I had some idea that I could load this into a program for vector based image editing like inkscape and then trace the outlines, and indeed, if you import the bitmap, you can then use the “Trace Bitmap” function, and turn it into a nice .SVG format vector file. But there are over 1000 glyphs in that catalog, and doing each one separately seemed like it would be a real drag.

A tiny bit more research revealed that inkscape uses the “potrace” library, which you can also install as a standalone command-line program. Woohoo! It accepts simple black and white PBM files (use the netpbm utilities or ImageMagick to convert your gifs to PBM files) and can output in a variety of formats, including Postscript, SVG, or even antialiased PGM files. When I ran potrace on the bitmap above, and wrote out an antialiased pgm file, I got:

Antialiased Glyph 100500

Much nicer. If you have a browser which supports SVG files, you can view it in its native format.

The conversion isn’t always perfect, but it seems to be a darned good start, and you can actually edit the SVG files to fix what minor problems remain.

[tags]Inkscape,Maya,Hieroglyps,Raster to Vector,potrace[/tags]