README.md

The expansions package

Expansions of integer and real numbers, and odometers.

Installation

To install on Windows:

devtools::find_rtools()
devtools::install_github('stla/expansions', build_vignettes=TRUE)

On Linux:

devtools::install_github('stla/expansions', build_vignettes=TRUE)

Examples

Decimal integer to integer base:

n <- 14
(n_to_base3 <- intAtBase(n, base=3) )
## [1] 2 1 1
sum(n_to_base3*c(1,3,3^2)) == n
## [1] TRUE

Cantor expansion:

# Cartesian product {0,1}x{0,1,2}x{0,1}:
sapply(0:11, function(x) intToAry(x, sizes=c(2,3,2)))
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,]    0    1    0    1    0    1    0    1    0     1     0     1
## [2,]    0    0    1    1    2    2    0    0    1     1     2     2
## [3,]    0    0    0    0    0    0    1    1    1     1     1     1

Float expansion in integer base, number between 0 and 1:

x <- 0.625
( x_to_base2 <- floatExpand01(0.625, base=2) )
## [1] 1 0 1
sum(x_to_base2 / 2^(1:3)) == x
## [1] TRUE

Float expansion in integer base, positive number:

x <- 1.125
( x_to_base2 <- floatExpand(1.125, base=2) )
## $digits
## [1] 1 0 0 1
## 
## $exponent
## [1] 1
sum(x_to_base2$digits / 2^(1:4)) * 2^x_to_base2$exponent == x
## [1] TRUE

Odometer:

odometer(c(1,0,1), base=2)
## [1] 0 1 1

Addition of adic integers:

sumadic(c(0,1,1), c(1,0,1), base=2)
## [1] 1 1 0 1

To know more:

http://stla.github.io/stlapblog/posts/expansions_package.html



stla/expansions documentation built on May 30, 2019, 5:46 p.m.