Skip to content

Conversation

yyyyx4
Copy link
Member

@yyyyx4 yyyyx4 commented Sep 28, 2025

This patch adds a simple function to approximate class numbers of imaginary-quadratic fields using the analytic class number formula. This approximation is accurate to a relative error factor of $<2$ even with comparatively low precision, making it useful in the context of class-group computations.

An obvious next step would be to generalize it to non-fundamental and/or positive discriminants. This is left for future work.

Copy link

github-actions bot commented Sep 28, 2025

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

…ing class numbers of negative fundamental discriminants
@yyyyx4 yyyyx4 force-pushed the public/approximate_class_numbers branch from c0a616a to 5430772 Compare September 29, 2025 10:47
h = pari.qfbclassno(disc)
return ZZ(h)

def quadratic_order_approximate_class_number(disc, *, bound=10**4):
Copy link
Contributor

@user202729 user202729 Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting it here is rather undiscoverable though. How about making it (also) a member of QuadraticField? (or is the construction of QuadraticField expensive? We can still put it in both places for discoverability though)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was even tempted to add it as an algorithm= option to the existing .class_number() method, but that seems questionable. Perhaps it would be enough to mention the existence of this function in the documentation of .class_number()? It is a rather obscure feature that most users will never require, after all...

sage: h = round(quadratic_order_approximate_class_number(-p, bound=10**5)); h
848...
sage: RR(h / hreal)
0.999...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least the formula should be deterministic so there shouldn't be a flaky test issue here, but for your information there's # abs tol 1e-3.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm unsure what's the best thing to do here. Does it make sense to simply hardcode the current output? It may change (slightly) with things like the choice of floating-point precision, so the value you get is not automatically deterministic just because the formula is. Hardcode the current output with some tolerance? Hardcode the actual class number with enough tolerance to make the approximation pass the test? (I think the last one would potentially mislead any human readers of the doctest.)

yyyyx4 and others added 2 commits October 2, 2025 23:03
Co-authored-by: user202729 <25191436+user202729@users.noreply.github.com>
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.

2 participants