fracDo {Rfractran} | R Documentation |
The FRACTRAN Interpreter Function
Description
This implements the FRACTRAN process, to wit For the first fraction f in the list for which nf is an integer, replace n by nf. Repeat this rule until no fraction in the list produces an integer when multiplied by n, then halt.
Usage
fracDo(input, fractions = NULL, nums, denoms, tries = 100,
stopFun = NULL, liveUpdate = TRUE, ...)
Arguments
input |
The starting integer for the given FRACTRAN code (fraction sequence) |
fractions |
The sequence of fractions. Must be in |
nums |
Vector of integers (or |
denoms |
Vector of integers (or |
tries |
A 'safety' limiter on the number of times to process the next integer generated. This avoids possible infinite runs or other time-wasters. |
stopFun |
Optional user-supplied function that can be used to terminate a FRACTRAN run early, or to take mid-run actions such as sending information to the console. See Details for more information. |
liveUpdate |
If set to TRUE, a few dots and words are sent to the console to indicate that the algorithm is still running. |
... |
Possible additional arguments for |
Details
Some FRACTRAN programs do not terminate, most famously the prime generators.
If a specific value is being looked for, an appropriate stopFun
can be supplied to check for that value. stopFun
must return a
single logical value (R, as always will convert numerics to logical if
necessary) indicating success as TRUE. The first argument
to stopFun
must accept a single bigq
value.
If there are more arguments, they must be entered after all named
arguments. Note that this function does not have to send TRUE; it could be
used solely to execute other commands mid-run.
See stopPrime
for one such example.
Value
A vector of all the bigq
values generated.
These all have denominator == 1, as they are the integers found in
each iteration of the FRACTRAN algorithm.
Author(s)
Carl Witthoft <carl@witthoft.com
References
https://esolangs.org/wiki/Fractran https://oeis.org/wiki/List_of_FRACTRAN_programs_to_compute_core_sequences
See Also
Examples
# addition: { 3/2 } . enter 2^a*3^b and get 3^(a+b) answer when terminated
addit <- fracDo(2^5*3^8,nums = 3, denoms = 2)
# Last value returned is what we want. But can't take log(bigq)
log(numerator(addit[length(addit)]),3)