HeadlinesBriefing favicon HeadlinesBriefing.com

CasNum: Arbitrary Precision Math via Compass and Straightedge

Hacker News •
×

CasNum is a Python library that implements arbitrary precision arithmetic using compass and straightedge constructions, essentially recreating Euclid's geometry as a computational engine. The project represents numbers as points on a plane and implements all arithmetic operations through geometric constructions, including a modified Game Boy emulator where every ALU opcode runs entirely through geometric calculations.

Built on a compass-and-straightedge 'engine' that performs five fundamental constructions—line through points, circle through center, line-line intersections, line-circle intersections, and circle-circle intersections—CasNum represents numbers as points (x,0) and implements addition, multiplication, and even logical operations through geometric methods. The library includes optimizations like efficient multiplication by 2 and modular arithmetic that removes high powers of two for better performance.

The project demonstrates practical applications including an RSA implementation and integration with PyBoy, a Game Boy emulator. Running Pokémon Red through this system takes approximately 15 minutes to boot due to the computational overhead, though subsequent runs achieve 0.5-1 FPS through caching. The creator describes CasNum as for developers who believe that if you didn't solve a 4th-degree polynomial just to increment a loop counter, you didn't really increment it.