The nicest numbers in Julia.
Author fkastner
24 Stars
Updated Last
5 Months Ago
Started In
February 2020


The nicest numbers in Julia

Stable Dev Build Status Coverage

This package implements a number type to represent numbers you can safely give to your students to work with.

The goal is that when common linear algebra or numerical algorithms work using NiceNumbers that then one can be sure that the algorithm can be reasonably easy worked through by hand with the given numbers.

Nice numbers as implemented in this package consist of a rational part and a square root part with a rational coefficient. Thus every NiceNumber is specified using two Rational{Int}s and one Int.


Just add the package from the Julia Pkg mode:

julia>] add NiceNumbers

Usage Example

julia> using NiceNumbers

julia> n = NiceNumber(2,3,5)
Nice number:

julia> n^2
Nice number:

julia> m = NiceNumber(3//5)
Nice number:

julia> n+m, n-m, n*m, n/m
(13//5+3⋅√5, 7//5+3⋅√5, 6//5+9//5⋅√5, 10//3+5⋅√5)

julia> sqrt(m)
Nice number:

julia> sqrt(n)
ERROR: sqrt(2+3⋅√5) is not nice anymore!

There is also a macro to simplify working with nice numbers:

julia> using LinearAlgebra

julia> n = norm([4,12,3] * 2)

julia> @nice m = norm([4,12,3] * 2)
Nice number:

julia> n == m

For further examples see the examples section of the documentation, especially the SVD example.

Used By Packages

No packages found.