Skip to content
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

Improve random_element for number field orders and ideals #6273

Closed
loefflerd mannequin opened this issue Jun 13, 2009 · 15 comments
Closed

Improve random_element for number field orders and ideals #6273

loefflerd mannequin opened this issue Jun 13, 2009 · 15 comments

Comments

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Jun 13, 2009

At the moment, random_element for number field orders returns a random integer coerced into the order, which isn't very useful. A much better solution would be to use the random_element method of the underlying free ZZ-module.

More generally, one could ask for the same functionality for fractional ideals (and the above would be the special case for the ideal (1).)

Component: number theory

Keywords: number field ideal order

Author: John Cremona

Reviewer: Nick Alexander

Merged: sage-4.1.alpha0

Issue created by migration from https://trac.sagemath.org/ticket/6273

@JohnCremona
Copy link
Member

comment:1

I have implemented this. using the random_element() function for ZZ and integral bases. It works for absolute and relative orders and ideals.

I started out using the random_element() function for the module class, but that did not work in the relative situation. It is a little strange that the classes for orders and ideals do not derive from free ZZ-modules.

@JohnCremona
Copy link
Member

Changed keywords from none to number field ideal order

@JohnCremona JohnCremona added this to the sage-4.0.2 milestone Jun 13, 2009
@williamstein
Copy link
Contributor

comment:3

REVIEW:

I think it would be better to do

 def random_element(self, *args, **kwds)

then in the docstring say that the inputs are identical to ZZ.random_element, whatever those are. This will if ZZ.random_element is ever improved, changed, or extended in any way (and let's hope it is), then this docstring won't have to change.

Then in the call to ZZ.random_element, just do ZZ.random_element(*args, **kwds). This shorter and more robust.

-- William

@JohnCremona
Copy link
Member

comment:4

Replying to @williamstein:

REVIEW:

I think it would be better to do

 def random_element(self, *args, **kwds)

then in the docstring say that the inputs are identical to ZZ.random_element, whatever those are. This will if ZZ.random_element is ever improved, changed, or extended in any way (and let's hope it is), then this docstring won't have to change.

Then in the call to ZZ.random_element, just do ZZ.random_element(*args, **kwds). This shorter and more robust.

-- William

OK, I'll do that. John

@JohnCremona
Copy link
Member

comment:5

Attachment: trac_6273.patch.gz

The revised patch does what was asked for in the review!

@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 15, 2009

Reviewer: Nick Alexander

@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 15, 2009

Author: John Cremona

@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 15, 2009

comment:6

In the relative case, the parents are wrong. I am fixing this right now.

@ncalexan ncalexan mannequin added s: needs work and removed s: needs review labels Jun 15, 2009
@JohnCremona
Copy link
Member

comment:7

Sorry about that. I'll review your fix as soon as I can. John

@JohnCremona
Copy link
Member

comment:8

Attachment: trac_6273-replacement.patch.gz

The new patch sorts out the parent problem ok, with suitable new doctests. I note that you now delegate the random function for orders to that of ideals -- this means that the new code is not used for non-maximal order, unfortunately. But then the same was true for my version.

So I would have given this a positive review, while noting that at some point non-maximal orders will need to be dealt with too.

Unfortunately:

sage -t  "devel/sage-6273/sage/rings/number_field/number_field_ideal.py"
**********************************************************************
File "/home/john/sage-4.0.2.rc0/devel/sage-6273/sage/rings/number_field/number_field_ideal.py", line 1045:
    sage: I.basis()
Expected:
    [3, -a + 1, (-3/2*b - 1497/2)*a, (-1/2*b - 499/2)*a - b - 499]
Got:
    [3, a + 2, (3/2*b + 1497/2)*a, (b + 499)*a - b - 499]

so it's still "needs work"

@JohnCremona JohnCremona changed the title Improve random_element for number field orders and ideals (easy) [with patch, needs work (still)] Improve random_element for number field orders and ideals (easy) Jun 15, 2009
@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 15, 2009

comment:9

Replying to @JohnCremona:

The new patch sorts out the parent problem ok, with suitable new doctests. I note that you now delegate the random function for orders to that of ideals -- this means that the new code is not used for non-maximal order, unfortunately. But then the same was true for my version.

So I would have given this a positive review, while noting that at some point non-maximal orders will need to be dealt with too.

Unfortunately:

sage -t  "devel/sage-6273/sage/rings/number_field/number_field_ideal.py"
**********************************************************************
File "/home/john/sage-4.0.2.rc0/devel/sage-6273/sage/rings/number_field/number_field_ideal.py", line 1045:
    sage: I.basis()
Expected:
    [3, -a + 1, (-3/2*b - 1497/2)*a, (-1/2*b - 499/2)*a - b - 499]
Got:
    [3, a + 2, (3/2*b + 1497/2)*a, (b + 499)*a - b - 499]

so it's still "needs work"

Let's just comment out both basis lines (since basis works, and it's essentially random). Can you make non-maximal orders work with the previous code? If so, do it and I will review.

@JohnCremona
Copy link
Member

Attachment: trac_6273_new.patch.gz

Replaces both previous

@JohnCremona
Copy link
Member

comment:10

I removed the lines showing the bases (which were not part of the test exactly, just there for illustration). I reinstated my original for orders, since it works for non-maximal orders, and added a new doctest to show that; but I kept in the additional doctests from the review patch to show that theparent are now correct (which I also borrowed from the review patch).

This one tests ok on both 32- and 64-bit, and I hope contains the best of both earlier patches with none of the problems! And in view of the trouble this took to get right, I removed the "(easy)" from the ticket's title!

@JohnCremona JohnCremona changed the title [with patch, needs work (still)] Improve random_element for number field orders and ideals (easy) Improve random_element for number field orders and ideals Jun 16, 2009
@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 16, 2009

comment:11

I'm a fan!

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jun 24, 2009

Merged: sage-4.1.alpha0

@rlmill rlmill mannequin removed the s: positive review label Jun 24, 2009
@rlmill rlmill mannequin closed this as completed Jun 24, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants