Learn R Programming

FunWithNumbers (version 1.2)

juggatz: Function which calculates the "Juggler" sequence ~~

Description

The "Juggler" sequence is similar to the Collatz sequence, but generates exponential changes rather than multiplicative changes to calculate each term. See Details for the algorithm.

Usage

juggatz(x, maxiter = 1000, prec = 100)

Value

A vector of mpfr integers representing the sequence, either to convergence or as limited by maxiter

Arguments

x

The numeric, mpfr, or bigz integer to start with.

maxiter

A "safety switch" to avoid possible lengthy runtimes (when starting with very very large numbers), terminating the function prior to convergence.

prec

This specifies the number of binary digits of precision to use when the function converts numeric input x to a mpfr object.

Author

Carl Witthoft, carl@witthoft.com

Details

The Juggler algorithm uses the following rules: x[j+1] = floor( if even, x[j]^0.5; if odd x[j]^1.5). Since the mpfr-class objects represent approximations to the various powers and roots calculated, juggatz dynamically adjusts the number of bits of precision for the next value in the sequence. This ensures that the correct decision as to even or odd is made at each step.

Examples

Run this code
 (juggatz(10))
# 8 'mpfr' numbers of precision  10 .. 100  bits 
# [1] 10  3  5 11 36  6  2  1
(juggatz(37))
# 18 'mpfr' numbers of precision 10 .. 1000 bits 
# [1]  37  225  3375  196069 86818724  9317
# [7]  899319 852846071 24906114455136 4990602  2233  105519
# [13] 34276462  5854  76  8  2  1

Run the code above in your browser using DataLab