convert_rational_fraction_to_nary: Convert a rational fraction into its base-n representation...

View source: R/carithmetic.R

convert_rational_fraction_to_naryR Documentation

Convert a rational fraction into its base-n representation using Horner's method and GMP library.

Description

This function computes the representation of a rational fraction in a specified base (n-ary form), using the GNU Multiple Precision (GMP) library for arbitrary precision arithmetic. The process involves repeated division by the base, using Horner's method for efficient computation. The function detects and marks repeating sequences in the n-ary expansion.

Usage

convert_rational_fraction_to_nary(p, q, base, ndigits = 1000)

Arguments

p

A 'bigz' object representing the numerator of the fraction.

q

A 'bigz' object representing the denominator of the fraction.

base

The base in which to express the fraction.

ndigits

The maximum number of digits to compute before stopping or detecting a repeat.

Details

'gmp::as.bigz()' is used to allow for arbitrarily large integers for the numerator and denominator of the rational fraction.

For more theoretical background, see: http://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm

Value

A list containing: - 'p': The numerator. - 'q': The denominator. - 'nary_representation': The n-ary number as a string. - 'expansion': Numeric vector of computed digits. - 'initial_part': Non-repeating part of the expansion. - 'repeating_part': Repeating sequence of digits in the expansion. - 'terms': List of intermediary terms used in computation.

Examples

library(gmp)
# Convert the fraction 1/9007199254740992 to binary
convert_rational_fraction_to_nary_gmp(as.bigz("1"), as.bigz("9007199254740992"), base = 2)


ddarmon/MUsaic documentation built on June 19, 2024, 6:43 p.m.