Determine the Tree Graph to some depth by iteratively reversing values.
Usage
tree_graph(
initial_value,
max_orbit_distance,
P = 2,
a = 3,
b = 1,
cycle_prevention = list()
)
Arguments
- initial_value
(int) The root value of the directed tree graph.
- max_orbit_distance
(int) Maximum amount of times to iterate the reverse function. There is no natural termination to populating the tree graph, equivalent to the termination of hailstone sequences or stopping time attempts, so this is not an optional argument like max_stopping_time or max_total_stopping_time, as it is the intended target of orbits to obtain, rather than a limit to avoid uncapped computation.
- P
(numeric|bigz): Modulus used to divide n, iff n is equivalent to (0 mod P). Default is 2.
- a
(numeric|bigz) Factor by which to multiply n. Default is 3.
- b
(numeric|bigz) Value to add to the scaled value of n. Default is 1.
- cycle_prevention
(set[int]) Used to prevent cycles from precipitating by keeping track of all values added across previous nest depths. Only to be used internally by the function recursing. Does not expect input.
Details
Returns nested dictionaries that model the directed tree graph up to a maximum nesting of max_orbit_distance, with the initial_value as the root.
Examples
#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
#>
#>
#>
#>