Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/collatz/lib/esm/index.mjs

Functions related to the Collatz/Syracuse/3N+1 problem.
Latest
import * as collatz from "https://deno.land/x/collatz@javascript-v1.2.0/lib/esm/index.mjs";

Classes

FailedSaneParameterCheck

Contains the results of computing a hailstone sequence.

Contains the results of computing the Tree Graph via Collatz.treeGraph(~). Contains the root node of a tree of TreeGraphNode's.

Nodes that form a "tree graph", structured as a tree, with their own node's value, as well as references to either possible child node, where a node can only ever have two children, as there are only ever two reverse values. Also records any possible "terminal sequence state", whether that be that the "orbit distance" has been reached, as an "out of bounds" stop, which is the regularly expected terminal state. Other terminal states possible however include the cycle state and cycle length (end) states.

Variables

The four known cycles (besides 0 cycling to itself), for the default parameterisation.

Error message constants.

SequenceState for Cycle Control

The current value up to which has been proven numerically, for the default parameterisation.

The current value down to which has been proven numerically, for the default parameterisation.

Functions

Assert Sane Parameters

Parameterised Collatz Function

Returns a list of successive values obtained by iterating a Collatz-esque function, until either 1 is reached, or the total amount of iterations exceeds maxTotalStoppingTime, unless totalStoppingTime is False, which will terminate the hailstone at the "stopping time" value, i.e. the first value less than the initial value. While the sequence has the capability to determine that it has encountered a cycle, the cycle from "1" wont be attempted or reported as part of a cycle, regardless of default or custom parameterisation, as "1" is considered a "total stop".

Parameterised Collatz Inverse Function

Returns the stopping time, the amount of iterations required to reach a value less than the initial value, or null if maxStoppingTime is exceeded. Alternatively, if totalStoppingTime is True, then it will instead count the amount of iterations to reach 1. If the sequence does not stop, but instead ends in a cycle, the result will be (Double.POSITIVE_INFINITY). If (P,a,b) are such that it is possible to get stuck on zero, the result will be the negative of what would otherwise be the "total stopping time" to reach 1, where 0 is considered a "total stop" that should not occur as it does form a cycle of length 1.

Returns a directed tree graph of the reverse function values up to a maximum nesting of maxOrbitDistance, with the initialValue as the root.