# Hybrid Continued Fractions and n-adic algorithms, with applications to cryptography and "unimaginable' numbers

This paper continues the author's previous studies on continued fractions and Heron's algorithm, as from his former JMM2017 presentation (see CF.HA). Extending the notion of continued fraction to the p-adic fields, one can find continued fractions which converge in both real and p-adic topologies to the `same' quadratic irrational number, some of which are given by the Heron's algorithm using a generalized version of an author's theorem from the cited JMM presentation. The definition can be possibly generalized to other global fields, as left as an open question. We will end the part on hybrid convergence with many numerical examples. After that, we will recall the basic algorithms on the p-adic fields studied by the author and see some applications of theirs to computer science: applying Heron's algorithm to quickly compute p-adic square roots, finding new elementary cryptography procedures and some methods to get pseudo-random numbers, calculate last digits of some peculiar very big numbers.

## Authors

• 2 publications
• ### Product Subset Problem : Applications to number theory and cryptography

We consider applications of Subset Product Problem (SPP) in number theor...
02/10/2020 ∙ by K. A. Draziotis, et al. ∙ 0

• ### Strong Law of Large Numbers for Functionals of Random Fields With Unboundedly Increasing Covariances

The paper proves the Strong Law of Large Numbers for integral functional...
11/10/2020 ∙ by Illia Donhauzer, et al. ∙ 0

• ### Homonym Detection in Curated Bibliographies: Learning from dblp's Experience (full version)

Identifying (and fixing) homonymous and synonymous author profiles is on...
06/15/2018 ∙ by Marcel R. Ackermann, et al. ∙ 0

• ### Stronger Cryptography For Every Device, Everywhere

Generating secure random numbers is a central problem in cryptography th...
10/01/2018 ∙ by JV Roig, et al. ∙ 0

• ### The notion of "Unimaginable Numbers" in computational number theory

Literature considers under the name unimaginable numbers any positive in...
01/16/2019 ∙ by Antonino Leonardis, et al. ∙ 0

• ### Theory and practice

The author argues to Silicon Valley that the most important and powerful...
11/01/1991 ∙ by Donald E. Knuth, et al. ∙ 0

• ### A localized version of the basic triangle theorem

In this short note, we give a localized version of the basic triangle th...
08/09/2019 ∙ by Gérard Duchamp, et al. ∙ 0

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## Abstract

This paper continues the author’s previous studies on continued fractions and Heron’s algorithm, as from his former JMM2017 presentation (see [5]).

Extending the notion of continued fraction to the -adic fields, one can find continued fractions which converge in both real and -adic topologies to the “same” quadratic irrational number, some of which are given by the Heron’s algorithm using a generalized version of an author’s theorem from the cited JMM presentation. The definition can be possibly generalized to other global fields, as left as an open question. We will end the part on hybrid convergence with many numerical examples. After that, we will recall the basic algorithms on the -adic fields studied by the author and see some applications of theirs to computer science: applying Heron’s algorithm to quickly compute -adic square roots, finding new elementary cryptography procedures and some methods to get pseudo-random numbers, calculate last digits of some peculiar very big numbers.

## 1 Introduction

Heron’s algorithm is very important in history of mathematics, and is a particular case of Newton’s method for approximating zeroes of a function. We will recall in this work a theorem on Heron’s algorithm related to continued fractions proved in [5]. The theorem will also hold for a generalization of continued fractions (definition 2.1) which converges also in local -adic completions (for every prime divisor of a fixed natural squarefree number ), in the wake of the author’s previous work (see PhD thesis [9]). After recalling Lagrange’s theorem for quadratic irrationals, we will see that some of them have a common representation both as real and -adic ( as before) numbers. We must recall that Heron’s algorithm is also very important in -adic fields, where Newton’s method is better known as the fundamental Hensel’s lemma and gives a very fast algorithm for computing the -adic square root (compare [8]). Other generalizations of continued fractions may be studied for such hybrid convergences, and this is left as an open problem. In the end of the section we will leave an open question over possible generalizations of the definition to other fields and then give some numerical examples of the hybrid convergence in the generalized definition given here. In the last section we will see applications of general -adic algorithms, such as pseudo-randomizing methods (see [11], [12]) and fast computation of the last decimal digits for some “unimaginable numbers” (see [6]).

This work has been presented both at “The First Symposium of the International Pythagorean School – da Pitagora a Schützenberger: numeri inimmaginabilîîî” held in Cosenza, Italy (september 2018) and at the JMM 2019 held in Baltimore, MD.

See [15] and [10] for details on the theory of -adic numbers.

Given a prime number , the set of -adic integers can be represented as a power series in the letter with exponents growing towards and digits in a finite set of elements, generally . More generally, one can allow to be any given integer .

For instance, the number can be represented in the -adic ring as:

 …999999=∞∑i=09⋅10i

because indeed one expects that (as we will see in the “-adic algorithms” section):

 …999999 + 1 = …000000

In the prime case one obtains a field , which is the completion of rational numbers under the so-called -adic absolute value. The latter is defined for a fraction (for uniquely determined , not divisible by ) as:

 ∣∣∣±ptab∣∣∣p=p−t

so that in fact positive powers of converge to .

In the general case is a ring with the following properties:

• for any by writing all digits of the first ring in base .

• when and are coprime as approximants converge in both rings, giving this way the two projections, and the map is invertible by chinese remainder theorem.

• Thus considering all prime divisors of . As a side fact, when the ring has always zero-divisors.

Structure of the multiplicative group is discussed in [9].

###### Example 1.1.

Hexadecimal representations of -bits colors is just a shortened version of the actual bit representation:

 FF\textperiodcentered FF\textperiodcentered 0016 =1111′1111′1111′1111′0000′00002 (yellow) 00\textperiodcentered FF\textperiodcentered 7F16 =0000′0000′1111′1111′0111′11112 (water blue) 7F\textperiodcentered 3F\textperiodcentered 0016 =0111′1111′0011′1111′0000′00002 (brown)
###### Example 1.2.

Let’s see an example of a decimal zero-divisor (as explained in the “last digits of unimaginable numbers” section):

 …896109004106619977392256259918212890625. × …896109004106619977392256259918212890624. = …000000000000000000000000000000000000000.

### 1.2 Heron’s algorithm and Newton’s method

The Newton’s method for finding the roots of a polynomial consists in starting with an approximation of such a root, drawing the tangent at the point to the graph and intersecting this tangent with the -axis, obtaining ; the sequence obtained by this method converges to a root of the polynomial.

When one considers the polynomial and starts with , Newton’s method just sends to the arithmetic mean between and and is known as the Heron’s algorithm

for finding (the geometric mean)

. The intervals between and give a so-called sequence of chinese boxes.

We recall the main theorem from [5]:

###### Theorem 1.3 (Al 2017).

Suppose has (classical) continued fraction expansion with period of length or . Apply Heron’s algorithm to obtaining a sequence . Then is the -th approximant via the continued fraction. Vice versa, if the continued fraction has period length greater than , applying in the same way Heron’s algorithm one does not get the same sequence of approximants.

## 2 Continued fractions which converge in different absolute values

It is possible to define continued fractions in such a way that they converge in , but the definition is far from being unique and often depends on the results one wants to achieve (apart from author’s work, see also [2] and [3]). We will now consider a definition which ensures convergence for more than just one absolute value. Heron’s algorithm in -adic fields will be a particular case of Hensel’s lemma.

###### Definition 2.1.

We will consider a non-zero integer , which is specifically the product of different primes (). Then we may consider expressions of the form:

 x=[a0;a1,a2,…]n=a0+na1+na2+n⋮

where we consider integers such that and (inequality is obviously strict when from the coprimality condition). We may accept not to be restricted to values greater than as one does with usual continued fractions. We remark that -continued fractions are the classical ones, while -continued fractions are the almost-classical ones obtained using the “ceiling” integral part.

###### Theorem 2.2.

The -continued fraction defined above converges with respect to the -adic absolute value for any prime dividing and also with respect to the usual absolute value in the real numbers.

Proof 2.2. With the usual methods for continued fractions in local fields (see [9]) one can prove that it converges in all -adic fields (indeed, fixed a prime, the other primes dividing are invertible in so can be moved to the denominator of the fractions), or equivalently in the -adic ring . Moreover, we have:

 [a0;a1,a2,…]n=a0+1a1/n+1a2+1⋮=b0+1b1+1b2+1⋮

and this gives the convergence in the set of real numbers in a way analogous to the standard continued fractions.

As a brief recall, we consider the recurrence step for the approximants :

 (pkpk−1qkqk−1)(bk+1110)=(bk+1pk+pk−1pkbk+1qk+qk−1qk)

from which we get the following facts:

• the denominator recurrence is necessarily exponentially divergent ();

• the difference of two consecutive approximants is as well exponentially convergent to zero because simple calculations give:

 (bk+1pk+pk−1)qk−pk(bk+1qk+qk−1)qk+1qk=pk−1qk−pkqk−1qk+1qk=±1qk+1qk;
• thus, the sequence of approximants satisfies Cauchy’s condition and converges to a uniquely determined real number.

The following results are straightforward:

###### Proposition 2.3.

Theorem 1.3 about Heron’s algorithm holds also for -adic continued fraction expansions. Specifically, the proof is the same without supposing being an integer and considering the expansion. More precisely, given a non-square positive integer , the fact that has a hybrid -continued fraction expansion of the form is necessary and sufficient condition for each to be the -th approximant via the continued fraction.

###### Proposition 2.4.

Periodic hybrid continued fractions converge to the “same” algebraic (quadratic) number for each absolute value which is considered, meaning that it is the solution of the same degree equation over .

We conclude this section with some numerical examples after the following:

###### Remark 2.5.

Continued fractions may be considered also in other global fields and their completions (for instance with Gauss integers and complex numbers), with the due attentions. An interesting open question may be whether there is a similar hybrid convergence theory in such cases.

### 2.1 Examples

1. The first example is ; a simple calculation shows that meaning that subtracting we obtain a square root of . It converges in both the usual real absolute value and in the -adic one. Also, is an integral part for both in the real field and in as modulo . Thus the Heron’s algorithm gives the continued fraction approximants (and consequently converges) in both cases:

 a0 =3 =[3]5; a1 =32+73=236 =[3,6]5; a2 =236⋅2+7⋅623=1033276 =[3,6,6,6]5.
2. We give another perfectly similar example. We take , whose radical part has Heron’s approximants:

 a0 =4 =[4]5; a1 =42+218=378 =[4,8]5; a2 =378⋅2+21⋅837⋅2=2713592 =[4,8,8,8]5.
3. In the following example we consider a simple composite , i.e. . Here we have with first approximants in . Here it is not possible to have a square root without denominator so we can’t relate to the Heron’s algorithm of the square root of an integer.

4. In the case we may have instead an integral expression such as which converges in . This expression relates to Heron’s algorithm for :

 a0 =8 =[8]15; a1 =14316 =[8,16]15; a2 =406734576 =[8,16,16,16]15.
5. We conclude this part with a length-2 period case. We take , whose radical part has Heron’s approximants:

 a0 =4 =[4]3; a1 =42+228=194 =[4,4]3; a2 =194⋅2+22⋅419⋅2=713152 =[4,4,8,4]5.

## 3 n-adic algorithms and applications

Calculations with -adic numbers can be used for cryptography and for generating random numbers, as we will see in this section.

### 3.1 Basic results

###### Remark 3.1.

In the case of -adic fields, and more generally -adic rings (where is not necessarily a prime number) the equivalent of Newton’s approximation method of tangents is known as one of the most important theorems under the name of Hensel’s lemma. Thus the convergence of Heron’s algorithm can be studied using well known results about Hensel’s lemma, and one finds out that a precision of is always achieved within steps. Thus it has applications to -adic computations, where it is indeed a very fast algorithm for computing the square root of a number (compare corollary 4.2.3 from [8]).

We recall that -adic numbers, and more in general -adic numbers for any given integer , can be represented as a power series in the letter (or ) with exponents growing towards and digits in a finite set of (or ) elements, generally (the same as real numbers, but with possibly infinite digits only on the left of the decimal point, reflecting the different convergence). In this setup, we can implement algorithm for calculation with the following proposition (see [8]):

###### Proposition 3.2.

The fundamental operations (addition, opposite, multiplication, reciprocal) can be turned into an easy algorithm for calculations into the set -adically approximated to the -th digit” by the projection (or truncation) into , i.e. modulo any element with -adic absolute value less than . A similar result holds for -adic rings, given any integer . The algorithms can be (and have been by the author) implemented on a computer.

Moreover:

###### Proposition 3.3.

Any advanced operation which requires approximations by Hensel’s lemma (provided that the input satisfies lemma’s hypothesis) can be as well implemented as an algorithm, as already done by the author.

Some common examples are:

• exponentials and logarithms (or other functions determined by a power series) within their convergence radius.

### 3.2 Elementary criptography methods

Let us consider the strings of elements in the set , i.e. elements of . Fixing an element (it suffices that the last digit is coprime to ), this determines a simple symmetric encrypting key by normal -adic multiplication:

 x→xy

where the decrypting key is simply . It is likely that our further studies of these kind of algorithms will lead us to better encryption methods.

###### Example 3.4.

Decimal numbers from to can be encrypted using the key , which has as a reverse key the number by the well known peculiar factorization .

###### Example 3.5.

Alphanumeric strings can be considered as -adic numbers with digits (the last being a separator) and therefore encrypted using the properties of .

###### Example 3.6.

Using bit-mapped bases, we may as well consider the possibility to apply our cryptography methods to such expressions.

We know that using basis (which corresponds to representing digits with a black and white bitmap), or any other power of

, a number is invertible if and only if the last digit is odd; the only possible issue in the division algorithm is effectively calculating the reciprocal of this last digit, but this can be done by considering for this digit the

Representing digits as b/w bitmaps has many possible practical applications, as the technology to let an electronic device read such digits is already widespread (barcodes, QR-codes).

### 3.3 Randomizing algorithms

We can try the following randomizing methods given a seed (and ignoring trivial endings):

• transforming -continued fractions into sums and vice-versa (digits );

• considering or other -converging power series;

• iterating times the function in any -adic ring.

Indeed, the operation of going from natural numbers to -adic numbers and vice-versa is totally unpredictable and as such satisfies the 3rd law of randomness (see [12]).

###### Remark 3.7.

The Montecarlo method for calculating a probability, which is used in physics abundantly, can be used in reverse to verify that an experiment is random enough. Instead of determining the average value of the outcomes for an experiment in order to get an approximated expected value of its distribution, one checks that the known expected value is comparable with the statistically obtained one. We will specifically use the fact that in an

square the probability to have a distance from a corner less than is approximately .

We consider the third possibility, applying our fast algorithm for computing square roots. We show some heuristic data giving credit to the fact that it generates pseudo-random digits.

We start by creating a list of random couples with and . Grouping together of those couples, we count how many satisfy , and multiply the ratio by .

We iterate times this procedure and obtain a statistic with average

and variance

, confirming the pseudo-randomness of the algorithm by the 3rd law of pseudo-randomness (cannot be distinguished from a random one by a chosen method).

### 3.4 Last digits of “unimaginable numbers”

For some so-called “unimaginable” numbers (see [6]), like Graham’s number, we may calculate the last digits using -adic numbers.

###### Example 3.8.

In there are two non trivial idempotent elements (whose sum is and product is ) given by:

 165∞ :=limk→∞165k=…07743740081787109376; 52∞ :=limk→∞52k=…92256259918212890625.

Their last digits are in common with the unimaginable numbers and , given that is big enough to justify the “unimaginable” attribute.

We recall that the Graham number is defined in Knuth’s notation (see [6] for a wide discussion on hyper-operations) by the following recursive notation:

 a ↑b=a∗a∗a…∗a [b times]=ab a ↑↑b=a↑a↑a…↑a [b times] a ↑kb=a↑k−1a↑k−1a↑k−1a… [b times] g0 =4 g1 =3↑↑↑↑3 gk =3↑gk−13 G =g64

This literally unimaginable number was involved in the first proof for Graham’s problem in Conway’s theory, even though it has been recently substituted by the smaller (but still insanely big) number .

###### Example 3.9 (Last digits of Graham’s number).

We now consider the problem of computing the last digits of .

It can be proved that the following algorithm:

 a0=3; xi=ai (mod 10i); ai+1=3xi; x=limi→+∞xi

converges in and that also exists and .

This number can be seen to be the fixed point for the equation .

Observing that the -adic difference ends with an “unimaginable” number of zeroes, their last digits are the same for all practical purposes.

###### Remark 3.10.

More generally, an infinite tetration always converges in any -adic ring (see also [14]), as it must converge for any -adic value: either divides , thus the sequence converges to , or they are coprime and the convergence is similar to the one of continued exponentials (see [9]).

This number too can be viewed as a fixed point:

 x=kx→x=k↑↑∞:=limi→∞k↑↑i.

This is of course a generalization for .

### Acknowledgements

I want to thank my family and friends for supporting me, and also my former advisor R. Dvornicich for his suggestion on participating to JMM. Also a thank goes to my research funder G. d’Atri for his suggestions and support on this work.

This work has been partially supported by POR Calabria FESR-FSE 2014–2020, with the grant for research project “IoT&B”, CUP J48C17000230006.

• [1]