Skip to contents

Getting Started

After following the “Get Started + Install” guide;

library(collatz)
# Optionally
library(gmp)

tree_graph

Compute a tree graph, which takes both a value to initialise the tree from, and an “orbit distance” for how many layers deep in the tree to compute;

tree_graph(16, 3)
#> $`16`
#> $`16`$`32`
#> $`16`$`32`$`64`
#> $`16`$`32`$`64`$`128`
#> [1] NA
#> 
#> $`16`$`32`$`64`$`21`
#> [1] NA
#> 
#> 
#> 
#> $`16`$`5`
#> $`16`$`5`$`10`
#> $`16`$`5`$`10`$`20`
#> [1] NA
#> 
#> $`16`$`5`$`10`$`3`
#> [1] NA

It will also stop on finding a cycle;

tree_graph(4, 3)
#> $`4`
#> $`4`$`8`
#> $`4`$`8`$`16`
#> $`4`$`8`$`16`$`32`
#> [1] NA
#> 
#> $`4`$`8`$`16`$`5`
#> [1] NA
#> 
#> 
#> 
#> $`4`$`1`
#> $`4`$`1`$`2`
#> $`4`$`1`$`2`$CYCLE_INIT
#> [1] 4

And can be parameterised;

tree_graph(1, 1, -3, -2, -5)
#> $`1`
#> $`1`$`-3`
#> [1] NA

If b is a multiple of a, but not of Pa, then 0 can have a reverse;

tree_graph(0, 1, 17, 2, -6)
#> $`0`
#> $`0`$CYCLE_INIT
#> [1] 0
#> 
#> $`0`$`3`
#> [1] NA

The tree graph can run on bigz;

tree_graph((27+as.bigz("576460752303423488")), 3)
#> $`576460752303423515`
#> $`576460752303423515`$`1152921504606847030`
#> $`576460752303423515`$`1152921504606847030`$`2305843009213694060`
#> $`576460752303423515`$`1152921504606847030`$`2305843009213694060`$`4611686018427388120`
#> [1] NA
#> 
#> 
#> $`576460752303423515`$`1152921504606847030`$`384307168202282343`
#> $`576460752303423515`$`1152921504606847030`$`384307168202282343`$`768614336404564686`
#> [1] NA