Skip to content

EPronovost/numeric-construction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

numeric-construction

Constructing Number Systems from First Principles

In the beginning, there was zero.


Algebraic Constructions

The Natural Numbers

The beginning of developing an axiomatic number system starts with the natural numbers { 0, 1, 2, 3, ... }, which are constructed using the Peano Axioms. In this approach, we define everything in terms of a "starting element" 0 and a "successor function" S(a). This set, combined with the addition operation, forms a commutative monoid, but fails to form an addative group, lacking inverses.

The Ring of Integers

To extend the natural numbers into a full ring, we include additive inverses (a.k.a. "negatives") for all the natural numbers. This yields the ring of integers.

The Field of Fractions of the Rationals

Similarly to how the natural numbers lacked additive inverses to make it a group, the integers lack multiplicative inverses to make it a field. As the integers form an integral domain, we can extend them to a field of fractions, yielding the rational numbers.


A Precise Number System

The limitations of the algebraic representation are obvious if you try to create a natural number for 10,000: Stack Overflow! It turns out this is a very inefficient way to represent numbers.

The next question I had is how can we define an infinite precision number system. Fixed-size approximations such as Float or Double are just that; addition is technically not even associative.

Finite Length Truncations

To solve this problem, we first create an object Truncation that represents any finite length decimal. This is modeled after IEEE floating points, with a sign bit, exponent, and significant. However, for infinite precision, the length of the significant is unbounded. However, as it is a vector, it must be finite. Along with these truncations, we define a Zero object. These are captured in Scala's BigDecimal type.

About

Constructing Number Systems from First Principles

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages