Skip to content

Conversation

mantepse
Copy link
Contributor

@mantepse mantepse commented Oct 8, 2025

fixes #41005

When requesting more terms, we check whether the b-file of the oeis provides them.

@maxale
Copy link
Contributor

maxale commented Oct 8, 2025

I'd suggest to separate number= from a request to get terms from b-file. For example, b-file may contain 10,000 terms while the user may like to get only 1,000 of them.

Copy link

github-actions bot commented Oct 8, 2025

Documentation preview for this PR (built with commit 9ed0b41; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@mantepse
Copy link
Contributor Author

mantepse commented Oct 8, 2025

I'd suggest to separate number= from a request to get terms from b-file. For example, b-file may contain 10,000 terms while the user may like to get only 1,000 of them.

Do you think it's possible/ worthwhile to download only a part? How many mb could it be?

@maxale
Copy link
Contributor

maxale commented Oct 8, 2025

@mantepse My concern is not about the size of b-files. Most of them have at most a few thousand terms and are not that large. So, it's fine to download b-file as a whole. My point is that the user may still want just some particular number of terms even if a larger number of terms is available. Also, value number=True is quite counterintuitive. I think it better to have another parameter for fetching bfile (e.g., download=True, online=True, or alike) and allow it be specified alongside with number=.

@mantepse
Copy link
Contributor Author

mantepse commented Oct 8, 2025

Ah, but that's exactly what it does. If they want 100 terms and Oeis knows 100 terms, then s.first_terms(100) will return 100 terms. If necessary, the b file will then be fetched.

@maxale
Copy link
Contributor

maxale commented Oct 8, 2025

Oh, I do not see that from reading the description:

       - ``number`` -- integer, ``True`` or ``None`` (default); the
          number of terms returned (if less than the number of
          available terms).  When set to ``True``, fetches the
          b-file.  When set to ``None``, returns all the known terms.

There are two things: whether or not we want to fetch the b-file, and the number of terms to return. They seem to be intermixed in an unobvious way here. To my view we should either

  • always get terms from the b-file, and then not even mention that; or
  • get them from b-file only by an explicit request, and this request should be spelled differently from the number of terms (number=) we want.

Also, you mention "number of available terms" - what is that? The number of terms in the OEIS entry, or the number of terms in the b-file?

@mantepse
Copy link
Contributor Author

mantepse commented Oct 9, 2025

Also, you mention "number of available terms" - what is that? The number of terms in the OEIS entry, or the number of terms in the b-file?

I meant the latter. What I had in mind was the following: as a user, if I want to check or make a conjecture from the first few terms, I don't care how they are obtained. So, in most cases I will want to get all of them. So, the two proposals amount to

sage: s.first_terms(True)

or, with the other proposal

sage: s.first_terms(fetch_all=True)

If for some reason I want 50 terms if at all possible, I would do

sage: s.first_terms(50)

and probably

sage: s.first_terms(50, fetch_all=True)

I guess one reason not to download the b-file, but other than that getting as many terms as possible is if I run through very many sequences. In this case downloading could be too expensive. (I checked, it does make a difference even if only checking 20 sequences.) So, this would be

sage: s.first_terms()[:50]

versus

sage: s.first_terms(50, fetch_all=False)

However, in this case one possibly should download the database anyway.

I'm not completely decided what's really better. I must say that, generally, the number argument does not make much sense to me.

@maxale
Copy link
Contributor

maxale commented Oct 9, 2025

I never used number= myself either. But allowing it to have value True somehow defeats its purpose. I would rather always (by default) get terms from b-file, but provided an option for getting a short version version of just displayed terms. If we don't want to introduce an additional parameter, should we use special value number=0 for that purpose?

That is,

  • s.first_terms() gives all terms (from b-file)
  • s.first_terms(0) gives all terms that are displayed in the OEIS entry (not from b-file)
  • s.first_terms(50) gives 50 terms (from whatever source)

@mantepse
Copy link
Contributor Author

How about using infinity oo instead of True?

@mantepse
Copy link
Contributor Author

Note that currently the full entry of the sequence is obtained at once. Getting the b file takes additional time, and actually quite a bit.

@maxale
Copy link
Contributor

maxale commented Oct 10, 2025

So, we proposed two possibilities:

  • number=None (default) for terms from b-file, number=0 for displayed terms;
  • number=None (default) for displayed terms, number=oo for terms from b-file.

I'm fine with either, but a big question remains - do we fetch b-file by default?

@mantepse
Copy link
Contributor Author

No, fetching the b-file by default is not a good idea. The initial terms are in the same download as the description, so we cannot be lazy here. But the b-file is an additional download and should be avoided if possible.

@maxale
Copy link
Contributor

maxale commented Oct 10, 2025

Ok, please proceed with your last suggestion then.

@maxale
Copy link
Contributor

maxale commented Oct 11, 2025

Thanks! It just came to me that it'd be beneficial to have an interface global parameter controlling the default behavior for fetching b-file. E.g., I run once oeis.allow_bfiles(True) and then .fist_terms() for every sequence gets all the terms from b-file. Can this feature be implemented as well?

@mantepse
Copy link
Contributor Author

I would rather not. In what way would it be easier than calling first_terms(oo)?

@maxale
Copy link
Contributor

maxale commented Oct 11, 2025

For some yes, for other - not. It's an alternative approach to handling things, which I personally prefer more.

Here is analogy with next_prime() function - we can call it each time with next_prime(n, proof=False), but instead we can call once proof.arithmetic(False) and then just call next_prime(n) without setting proof=False explicitly.

@mantepse
Copy link
Contributor Author

done, please check! (oeis.options is your friend)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functionality for fetching OEIS sequence terms from b-files

2 participants