-
-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix random polynomial bias #37118
Fix random polynomial bias #37118
Conversation
It is more useful in practice
Actually, I think the API is too confusing (it is to myself right now). I will rewrite it tomorrow. Sorry for the confusion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now even more complicated to make something that is actually wrong be a returned value. Again, the zero polynomial is not monic. It should not be returned when monic=True
, ever. It is a contradiction. Remove the _allow_zero
, then apply fire to it. Then repeat for everything related to this.
Additionally, I see no point in having other methods that simply are setting options in another method. That is why we have arguments, right? These methods are creating extra maintenance complications and polluting tab completion IMO.
This commit removes all `monic_or_zero` methods.
FYI, I want total_possible = 1 + sum(q^i for i in range(g + 1))
if randrange(total_possible) == 0:
u = R(0)
else:
u = R.random_element(degree=(0, g)).monic() And this doesn't even work for say function fields |
Putting aside that calling a random output an exact computation is a bit strange, assuming you meant a random monic polynomial or zero, if |
I'll make a |
I am still somewhat confused by your use-case for having random monic polynomials and zero (with seemingly some prescribed uniform-like (used very loosely here) distribution). I have convinced myself more that there should not be an extra parameter for |
Actually, I just discussed this with @yyyyx4 and I think we don't actually need the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I am glad things are clarified.
Let me remind you about my comment that having methods that simply call another with a default is not good practice. You already have the argument, it makes the code more complicated with more to maintain (and potential to cause conflicts), and pollutes tab completion. random_monic_polynomial
should be removed.
You also need to include a check if monic=True
and the only degree(s) possible are -1
. Related, if degree[1] < -1
then you also need to error out.
I don’t find it useful to have a # random
output, but instead to test the desired properties of the output polynomial (e.g., the degree is within the correct range).
I have made changes according to your review, thanks! Regarding your review
I actually find it to be the opposite. It's useful for the user to have a quick idea what the output looks like as a mental picture, and for me it makes me read the documentations faster. So I kept those. |
This seems to capture precisely the difference between an example and a test: Examples are for users, tests are for the machine. |
IMO, this is a fallacy. If I happen to get ``0`, this does not look like a degree 10 polynomial. This is different than if the output order is random (in which case, there are generally ways to convert the test into something deterministic; e.g., sorting).
Indeed, the last part of what you said is the key point, and not only for the test. |
This isn't quite accurate. Let me be very clear (sorry for the directness, don't read this as me being upset): The |
As I noted in the discussion under :issue:`37118`, it seems that the output of `sage -t` and the REPL differ, so I am not sure if this commit is correct.
This happens for a few things; we sort certain outputs for tests that we wouldn’t otherwise (in order to have the consistency in testing the output). So just take the output of |
Interesting, I have done that.
…On 10 Feb 2024, 23:13 +0000, Travis Scrimshaw ***@***.***>, wrote:
> I have a question about the failing doctest. The output from sage -t and from the Sage REPL is different. This is from sage -t (also from GitHub actions):
This happens for a few things; we sort certain outputs for tests that we wouldn’t otherwise (in order to have the consistency in testing the output). So just take the output of sage -t.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Just a side note, I recently learned about FLINT, and in particular its |
It would be faster, but only for certain base rings (which already have specialized implementations IIRC). So it could be used in those specialized classes. Also there are 2 doctests failing in |
From what I understand Oh lmao my Is there a way to mark the entire test as |
If you add |
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. One last little thing to do. It would also be good if the lines you changed were at 80 char/line or less too.
# using Neville's method for recursively generating the | ||
# Lagrange interpolation polynomial | ||
# using Neville's method for recursively generating the | ||
# Lagrange interpolation polynomial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert. The indentation is useful and such a change can just create (merge) conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I blame this on my editor.
I thought the maximum line width in Sage is 100, and (if I didn't miss any) my changes should wrap at that |
For code, we try to do 100 (but there can be reasons for breaking this and this is less enforced), but docstrings we generally try to keep shorter. |
I will be back and fix the rest in a few hours. |
Hopefully this is ready now |
Documentation preview for this PR (built with commit 9d1d0a1; changes) is ready! 🎉 |
Thanks. This is good with me now. Testing output can be a bit more lax about it, but it is still a good approximate guide. |
For a polynomial ring
R
sayGF(11)["x"]
, beforeR.random_element
is very far from random, now it is uniformly random.