Decimal precision for continued-function OEIS submission

57 views
Skip to first unread message

Patrick Millican

unread,
Feb 23, 2026, 4:10:50 PMFeb 23
to SeqFan
I am interested in publishing sequences to the OEIS that involve the continued-function expansions of fundamental constants like pi. Since the values of the terms in these sequences are almost all zero (i.e., the sequences are really sparse), my submissions will be the indices of the nonzero entries in the expansions. However, in order to have interesting results, I will need to carry out the expansion to millions of terms, which will entail a great deal of precision in the digits of pi (and whatever other constants I decide to perform an expansion of). Coding this up in Python and using the mpmath library, I have gone out to 10,000,000 entries in the continued-function expansion with an assumed precision in pi of 500 places to the right of the decimal, and I have encountered no detectable numerical stability with that combination. How many more digits (if any) do I need to go out, and is my approach even salvageably correct (e.g., should I switch from Python to Fortran/Mathematica because Python is a hopeless language for these calculations)?

Thank you!

Tim Peters

unread,
Feb 23, 2026, 4:49:24 PMFeb 23
to seq...@googlegroups.com
Sorry, I don't know what "conctinued-function" means. I thought perhaps you meant "continued fraction',, but there are no zeroes in the continued fraction expansion of an irrational number (as far from "sparse" as it gets - for example, pi is

3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, ...

).

As to Python, installing the gmpy2 extension module will give access to about the fastest bigint arithmetic implementation that exists (GNU's hyper-optimized GMP libraries). The mpmath package you're already using automatically detects whether gmpy2 is installed, and uses it for its arithmetic if so. Very much faster for very large ints.

If perhaps you did mean continued fractions, as a rule of thumb, N terms give about N decimal digits of precision. If you only have 500 digits of pi, 1000 terms of its continued fraction epansion is already vast overkill.

If nobody else volunteers a response that's more relevant to you, consider using more words? I really can't guess at what you're doing or what you want. A concrete, fully spelled-out, example would help a lot.

On Mon, Feb 23, 2026 at 3:10 PM Patrick Millican <pjmil...@gmail.com> wrote:
I am interested in publishing sequences to the OEIS that involve the continued-function expansions of fundamental constants like pi. Since the values of the terms in these sequences are almost all zero (i.e., the sequences are really sparse), my submissions will be the indices of the nonzero entries in the expansions. However, in order to have interesting results, I will need to carry out the expansion to millions of terms, which will entail a great deal of precision in the digits of pi (and whatever other constants I decide to perform an expansion of). Coding this up in Python and using the mpmath library, I have gone out to 10,000,000 entries in the continued-function expansion with an assumed precision in pi of 500 places to the right of the decimal, and I have encountered no detectable numerical stability with that combination. How many more digits (if any) do I need to go out, and is my approach even salvageably correct (e.g., should I switch from Python to Fortran/Mathematica because Python is a hopeless language for these calculations)?

Thank you!

--
You received this message because you are subscribed to the Google Groups "SeqFan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seqfan+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/seqfan/7a0b5343-7afd-420e-8704-467bafb54568n%40googlegroups.com.

Patrick Millican

unread,
Feb 23, 2026, 9:28:15 PMFeb 23
to SeqFan
I am referring to continued-function expansions, in fact! Continued-fraction expansions are continued-function expansions where the function is 1/x, but I'm working with a different family of functions.

In the case of pi to 500 digits and 10,000,000 terms in the expansion, the expansion is 3; 0, 0, 0, 0, ..., with the first nonzero entry being 1 in the 73rd place. There are only 6 further nonzero entries between the 73rd and 1,000th entry. Are you saying that I need 1,000 digits of pi to accurately report the first 1,000 entries of a continued-function expansion? Of course, I can go ahead and submit the indices of those entries to the OEIS as my sequence, but I was really hoping to make a more comprehensive go of it and extend my knowledge of the continued-function expansion out to entries in the millions.

I will go ahead and verify that I have the gmpy2 library installed. The real bottleneck I've had so far is running this in a reasonable time on my personal laptop, so the more efficiently I can do this, the better. 

Tim Peters

unread,
Feb 23, 2026, 11:20:17 PMFeb 23
to seq...@googlegroups.com
On Mon, Feb 23, 2026 at 8:28 PM Patrick Millican <pjmil...@gmail.com> wrote:
I am referring to continued-function expansions, in fact! Continued-fraction expansions are continued-function expansions where the function is 1/x, but I'm working with a different family of functions.

Ah -got it. Thanks! I have no experience with those, alas. 
 
In the case of pi to 500 digits and 10,000,000 terms in the expansion, the expansion is 3; 0, 0, 0, 0, ..., with the first nonzero entry being 1 in the 73rd place. There are only 6 further nonzero entries between the 73rd and 1,000th entry. Are you saying that I need 1,000 digits of pi to accurately report the first 1,000 entries of a continued-function expansion?

Wouldn't know. I was talking specifically about continued fractions (1.x). You can use mpmath's interval arithmetic facilities to investigate. For example,

import mpmath
mpmath.mp.dps = 1000
mpmath.iv.dps = 1000
p = mpmath.iv.pi
count = 0
f = mpmath.floor
while True:
    fa = f(p.a)
    fb = f(p.b)
    if fa != fb:
        print()
        print("diverged after", count)
        break
    count += 1
    print(int(fa), end=" ")
    p -= fa
    p = 1.0 / p

That uses mpmath's idea of an interval containing pi to about 1000 decimal digits to compute the cf expansion of pi. It displays the first 969 partial quotients until the interval becomes ambiguous (contains more than one integer), so quits with a "diverged" message.
 
Of course, I can go ahead and submit the indices of those entries to the OEIS as my sequence, but I was really hoping to make a more comprehensive go of it and extend my knowledge of the continued-function expansion out to entries in the millions.

I will go ahead and verify that I have the gmpy2 library installed. The real bottleneck I've had so far is running this in a reasonable time on my personal laptop, so the more efficiently I can do this, the better. 

If "import gmpy2" blows up, just use "pip install gmpy2" from a command line to install it 

Good luck!

Allan Wechsler

unread,
Feb 24, 2026, 12:39:16 AMFeb 24
to SeqFan
You are not using 1/x as the function in your "continued function" expansion, but you don't say what function you are using. It's hard to assess your approach or answer any questions without that information.

Also, if you have 0 terms, this implies that you are not following the scheme where one reports the integer part and passes the fractional part to the function for the next iteration. Again, more details about your procedure would be enlightening.

I have not personally encountered the term "continued function". Do you have a reference to the literature?

-- Allan


--
You received this message because you are subscribed to the Google Groups "SeqFan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seqfan+un...@googlegroups.com.

Patrick Millican

unread,
Feb 25, 2026, 8:24:03 PM (13 days ago) Feb 25
to SeqFan
This is exactly what I was hoping for. Thank you very much!

Marc LeBrun

unread,
Feb 26, 2026, 1:06:14 PM (12 days ago) Feb 26
to Patrick Millican, seq...@googlegroups.com
Patrick, you may be on to something interesting, but I agree with Allan that keeping obscure what you're talking about isn't helpful.  Since you force us to guess:

A natural interpretation of "continued function expansion" for some real number x is, for some function f that maps 0..1 --> 1..oo, the sequence of integers you get by iteratively applying the rule:
   if x < 1 then x --> f(x), else emit the integer part of x and set x to the fractional part of x
When f is 1/x you get continued fraction expansions, when f is 10x you get decimal expansions, and so on.

An interesting observation is that the expansions are periodic/finite for 10x just when x is rational, for 1/x just when x is "quadratic" and so on.

I once played with f = sqrt(x) (which I think I shared on the math-fun list a few years back) that I believe is perhaps period for cubics.

Bill Gosper, as I recall, speaks of "continued logarithms" in his "Continue Fraction Arithmetic" write up from the 1970's.

There's probably plenty of other precedent.  Googling "continued function" returns lots of spoor.

Is this what you are exploring?


Gareth McCaughan

unread,
Feb 26, 2026, 1:51:55 PM (12 days ago) Feb 26
to seq...@googlegroups.com
On 26/02/2026 18:05, Marc LeBrun wrote:
> Patrick, you may be on to something interesting, but I agree with
> Allan that keeping obscure what you're talking about isn't helpful.
>  Since you force us to guess:
>
> A natural interpretation of "continued function expansion" for some
> real number x is, for some function f that maps 0..1 --> 1..oo, the
> sequence of integers you get by iteratively applying the rule:
>    if x < 1 then x --> f(x), else emit the integer part of x and set x
> to the fractional part of x
> When f is 1/x you get continued fraction expansions, when f is 10x you
> get decimal expansions, and so on.

This doesn't seem right. x -> 10x doesn't map 0..1 to 1..oo, after all.

I think what you mean is: given f mapping 0..1 to 0..oo, repeat { emit
floor(x); x <- f(x-floor(x)) }.

This _does_ do the right thing for f : x -> 10x.

> I once played with f = sqrt(x) (which I think I shared on the math-fun
> list a few years back) that I believe is perhaps period for cubics.

This maps 0..1 to 0..1, and once you've got a number < 1 no amount of
sqrting will make it be >= 1. What am I missing here?

https://personal.math.ubc.ca/~gerg/papers/downloads/UECFE.pdf proves
that there exists _some_ f whose continued-function expansions are
periodic precisely for real numbers satisfying a cubic equation but the
proof is very nonconstructive (and I think works for any countable dense
integer-periodic subset of the reals in place of "those satisfying a
cubic equation").

(I thought at first that the paper looks at the case f(x) = 1/sqrt(x)
which conceivably might be what you have in mind, and reports results
that in particular imply that its expansions aren't periodic for all
things satisfying a cubic equation, but actually the paper's notation is
a bit funny and I think what it's actually looking at is f(x) = 1/x^2.)

--
g

Marc LeBrun

unread,
Feb 26, 2026, 2:48:23 PM (12 days ago) Feb 26
to seq...@googlegroups.com
Gareth, correct on all counts, sorry for the haste. Right, thanks for the jog -- I think I might have been playing with x --> 1/x^2 -- that f produces expansions like
x = a0 + 1/sqrt( a1 + 1/sqrt( a2 + ...
and was wondering about what x were finite/periodic. Thanks!
> --
> You received this message because you are subscribed to the Google Groups "SeqFan" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to seqfan+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/seqfan/ae3b2fc2-8493-4a23-8307-39d13032caf8%40pobox.com.

Allan Wechsler

unread,
Feb 26, 2026, 2:55:23 PM (12 days ago) Feb 26
to SeqFan
I am away from my computer, and composing text on my phone is painful, but I will try. 

I'm now inclined to be charitable to Patrick Millican. My interpretation is that Patrick is working on some kind of successive-approximation scheme whose details he doesn't wish to share until he has more convincing results. I can think of several perfectly respectable reasons for that sort of discretion. But Patrick (I infer) was having trouble doing his competitions because he didn't have an easy procedure for keeping track of how much precision he had exhausted so far. 

If I had understood the question, I would have suggested running his algorithm twice, with two starting values bracketing pi in some tiny interval, and looking for the place where the two resulting sequences start to differ. The sequences before that point can be presumed to hold for pi as well.

Then Tim Peters suggested a Python package that does basically this automatically for arbitrary precision, and Patrick pronounced himself satisfied.

I am pleased that Tim was able to figure out what Patrick needed to continue his research, and I'll be interested in hearing more whenever Patrick feels comfortable sharing it.

-- Allan

--
You received this message because you are subscribed to the Google Groups "SeqFan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seqfan+un...@googlegroups.com.

M F Hasler

unread,
Feb 27, 2026, 8:57:33 AM (11 days ago) Feb 27
to seq...@googlegroups.com
I agree with 3 things :
- it's a quite unknown theory, a reference should have been given already in the original message
- you can't really ask for help and disclose 99% of the required information
- if you want "UNREASONABLE EFFECTUALNESS" you should definitely choose a different function from the one that gives you so many zeros that it's more practical to list the indices of nonzero terms.

Also consider: will anyone ever look this up in the OEIS? Especially given the arbitrariness of the choice of the function, quoting:
"The purpose of this paper is to demonstrate that the function f can be chosen so that the expansions of prescribed real numbers can have essentially any desired behavior."

Regards,
Maximilian

Gareth McCaughan

unread,
Feb 27, 2026, 11:37:20 AM (11 days ago) Feb 27
to seq...@googlegroups.com
On 27/02/2026 13:56, M F Hasler wrote:
I agree with 3 things :
- it's a quite unknown theory, a reference should have been given already in the original message
- you can't really ask for help and disclose 99% of the required information
- if you want "UNREASONABLE EFFECTUALNESS" you should definitely choose a different function from the one that gives you so many zeros that it's more practical to list the indices of nonzero terms.

Also consider: will anyone ever look this up in the OEIS? Especially given the arbitrariness of the choice of the function, quoting:
"The purpose of this paper is to demonstrate that the function f can be chosen so that the expansions of prescribed real numbers can have essentially any desired behavior."

To be clear, so far as I know there's no particular connection between that particular paper and Patrick Millican who posted here. In particular, Patrick isn't the one claiming "unreasonable effectualness", and his particular choice of function may well not be arbitrary in the way that the ones mostly considered in that paper are.

(I do agree that it would have been better if he'd been clearer about what he was asking.)

--
g

Marc LeBrun

unread,
Feb 27, 2026, 2:35:04 PM (11 days ago) Feb 27
to seq...@googlegroups.com
Good discussion, thanks all. (I personally especially appreciate Allan's gentle reminder to incline toward charity here -- there's little enough elsewhere).

Gareth: "Also consider: will anyone ever look this up in the OEIS?"

Use cases are good guidance. On the other hand "anyone ever" is a pretty wide scope, far more than just us typing in lookups on a website in 2026. In some distant future some cyborg might hit on an amazing connection that might not otherwise be as readily apparent if some sequence isn't in the cache. The OEIS will never run out of A-numbers, but curation is challenging.

Gareth: "choose a different function from the one that gives you so many zeros"

Yes. One reason "continued function" schemes are potentially interesting is that they "implement" real numbers as streams of integers. Then operations on numbers can be described as a kind of plumbing -- "spigot arithmetic". It's natural to ask about the information characteristcs of this stream "channel". Radix-based systems like decimal or binary have a constant information density -- each digit conveys the same amount of information. Continued fractions are variable: 1's convey the least info, and the larger the term the more it tells you (I'm pretty sure someone's figured out the average "entropy" of CFs). Bounding CF-like streams led Gosper and others to look into "continued logarithms". It suggested a highly parallel stream computer architecture, where the silicon is mostly churning instead of idle. Anyway, Patrick may have goals which require highly dilute streams, but, in general, it's nicer when the information is denser.

(I've also wondered about schemes that would implement complex numbers as streams of Gaussian integers -- what would various root systems etc look like?)

Gareth McCaughan

unread,
Feb 28, 2026, 4:55:26 PM (10 days ago) Feb 28
to seq...@googlegroups.com
On 27/02/2026 19:34, Marc LeBrun wrote:
Gareth: "Also consider: will anyone ever look this up in the OEIS?"

...

Gareth: "choose a different function from the one that gives you so many zeros"

Neither of those was actually me. They were both M F Hasler. Did something go awry in my email client's treatment of quoted text?

--
g

Marc LeBrun

unread,
Feb 28, 2026, 7:44:11 PM (10 days ago) Feb 28
to seq...@googlegroups.com
Gareth McCaughan. "...Did something go awry in my email client's treatment of quoted text?"

No, actually I confused my email reader's rendering when trying to prune down the message. Apologies for the misattribution! Thanks for the correction.

Reply all
Reply to author
Forward
0 new messages