[[https://travis-ci.org/jagot/Rootionals.jl][https://travis-ci.org/jagot/Rootionals.jl.svg?branch=master]] [[https://coveralls.io/github/jagot/Rootionals.jl?branch=master][https://coveralls.io/repos/github/jagot/Rootionals.jl/badge.svg?branch=master]] [[https://codecov.io/github/jagot/Rootionals.jl?branch=master][https://codecov.io/github/jagot/Rootionals.jl/coverage.svg?branch=master]]

A light-weight implementation of fractional roots (numbers such as 1/√2). For a more comprehensive package, see [[https://github.com/anj1/AlgebraicNumbers.jl][AlgebraicNumbers.jl]]; the dependencies of this package are however much larger.

- Usage example A /rootional/ is defined by two vectors, the first containing the bases as integers, and the second the exponents as rationals.

We first load the package: #+BEGIN_SRC julia :exports code using Rootionals R = Rootional #+END_SRC

#+RESULTS: : Rootionals.Rootional

The square root of two is defined by specifying the base (2) and the exponent (1//2), as the arguments to the constructor: #+BEGIN_SRC julia :exports both R([2], [1//2]) #+END_SRC

#+RESULTS: : √2

An equivalent way is #+BEGIN_SRC julia :exports both sqrt(R(2)) #+END_SRC

#+RESULTS: : √2

If we instead want to represent its inverse, we write: #+BEGIN_SRC julia :exports both R([2], [-1//2]) #+END_SRC

#+RESULTS: : 1/√2 or more naturally #+BEGIN_SRC julia 1/sqrt(R(2)) #+END_SRC

#+RESULTS: : 1/√2

More complicated rootionals can of course be formed: #+BEGIN_SRC julia :exports both R([3, 2, 6], [3//4, -2, -1//3]) #+END_SRC

#+RESULTS: : (∜3)³/2²∛6

07/01/2017

over 1 year ago

13 commits