# collatz_function: The Collatz function In collatz: Functions Related to the Collatz/Syracuse/3n+1 Problem

 collatz_function R Documentation

## The Collatz function

### Description

Returns the output of a single application of a Collatz-esque function.

### Usage

```collatz_function(n, P = 2, a = 3, b = 1)
```

### Arguments

 `n` (numeric|bigz) The value on which to perform the Collatz-esque function `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.

### Details

This function will compute and return the result of applying one iteration of a parameterised Collatz-esque function. Although it will operate with integer inputs, for overflow safety, provide a gmp Big Integer ('bigz').

### Value

a numeric, either in-built or a bigz from the gmp library.

### Examples

```# Returns the output of a single application of a Collatz-esque function.
# Without `gmp` or parameterisation, we can try something simple like
collatz_function(5)
collatz_function(16)
# If we want change the default parameterisation we can;
collatz_function(4, 5, 2, 3)
# Or if we only want to change one of them
collatz_function(3, a=-2)
# All the above work fine, but the function doesn't offer protection against
# overflowing integers by default. To venture into the world of arbitrary
# integer inputs we can use an `as.bigz` from `gmp`. Compare the two;
collatz_function(99999999999999999999)
collatz_function(as.bigz("99999999999999999999"))
```

collatz documentation built on Sept. 5, 2022, 9:06 a.m.