Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
ordering number field elements
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Cremona  
View profile  
 More options May 22 2009, 7:23 am
From: John Cremona <john.crem...@gmail.com>
Date: Fri, 22 May 2009 12:23:43 +0100
Local: Fri, May 22 2009 7:23 am
Subject: ordering number field elements
Elements of number fields currently have no custom cmp() function
which means that x>y is always True and x<y is always False when x!=y.

We need to be able to sort lists of number field elements properly,
which requires implementing this.

I suggest something like

if x.parent()==y.parent():  return cmp(list(x),list(y))
else: return cmp(x.parent(),y.parent())

Would that work ok?  in practice people would most often sort elements
of the same field of course.

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Alexander  
View profile  
 More options May 22 2009, 10:52 am
From: Nick Alexander <ncalexan...@gmail.com>
Date: Fri, 22 May 2009 07:52:02 -0700
Local: Fri, May 22 2009 10:52 am
Subject: Re: [sage-nt] ordering number field elements

On 22-May-09, at 4:23 AM, John Cremona wrote:

> Elements of number fields currently have no custom cmp() function
> which means that x>y is always True and x<y is always False when x!=y.

Really?  I don't understand how we always get roots in the same order  
in that case.

> We need to be able to sort lists of number field elements properly,
> which requires implementing this.

> I suggest something like

> if x.parent()==y.parent():  return cmp(list(x),list(y))
> else: return cmp(x.parent(),y.parent())

+1

Nick


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Cremona  
View profile  
 More options May 22 2009, 11:10 am
From: John Cremona <john.crem...@gmail.com>
Date: Fri, 22 May 2009 16:10:05 +0100
Local: Fri, May 22 2009 11:10 am
Subject: Re: [sage-nt] Re: ordering number field elements
2009/5/22 Nick Alexander <ncalexan...@gmail.com>:

> On 22-May-09, at 4:23 AM, John Cremona wrote:

>> Elements of number fields currently have no custom cmp() function
>> which means that x>y is always True and x<y is always False when x!=y.

> Really?  I don't understand how we always get roots in the same order
> in that case.

That is a mystery.  Perhaps the order in which the roots are produced
is not so random.  I was hoping that someone would confirm my claim!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
N. Bruin  
View profile  
 More options May 22 2009, 12:29 pm
From: "N. Bruin" <nbr...@sfu.ca>
Date: Fri, 22 May 2009 09:29:35 -0700 (PDT)
Local: Fri, May 22 2009 12:29 pm
Subject: Re: ordering number field elements
On May 22, 4:23 am, John Cremona <john.crem...@gmail.com> wrote:

> Elements of number fields currently have no custom cmp() function
> which means that x>y is always True and x<y is always False when x!=y.

> We need to be able to sort lists of number field elements properly,
> which requires implementing this.

Do we? Unlikely comparisons have been discussed before. Python 3.0
returns TypeErrors on many comparisons, e.g. Python complex numbers do
not allow comparison. Hence, I don't think there is any pressure from
the language environment in sage to make all objects comparable. There
is not a very good mathematical reason to do it either,  unless you
are considering a special class of number fields with a fixed real
embedding.

To get the effect you are describing above (roughly), one could do

sorted(L,key=list)

which is both short and requires people to acknowledge that they are
making a (necessary) choice about how L is supposed to be sorted. I
would think explicit is better than implicit for this too.

Is the main reason to force things like roots to produce deterministic
output to facilitate doctesting? Would it be bad to put the sort
command in the doctest?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Cremona  
View profile  
 More options May 22 2009, 1:36 pm
From: John Cremona <john.crem...@gmail.com>
Date: Fri, 22 May 2009 18:36:28 +0100
Local: Fri, May 22 2009 1:36 pm
Subject: Re: [sage-nt] Re: ordering number field elements
2009/5/22 N. Bruin <nbr...@sfu.ca>:

> On May 22, 4:23 am, John Cremona <john.crem...@gmail.com> wrote:
>> Elements of number fields currently have no custom cmp() function
>> which means that x>y is always True and x<y is always False when x!=y.

>> We need to be able to sort lists of number field elements properly,
>> which requires implementing this.

> Do we? Unlikely comparisons have been discussed before. Python 3.0
> returns TypeErrors on many comparisons, e.g. Python complex numbers do
> not allow comparison. Hence, I don't think there is any pressure from
> the language environment in sage to make all objects comparable. There
> is not a very good mathematical reason to do it either,  unless you
> are considering a special class of number fields with a fixed real
> embedding.

I am not thinking about a mathematically sensible sorting, i.e. not a
partial order in the mathematical sense.  I actually want sorted lists
for implementing modular symbols where it is important to be able to
look things up quickly.

If that can be done (deterministically and fast) some other way, I
would be happy.

> To get the effect you are describing above (roughly), one could do

> sorted(L,key=list)

That is neat;  my python knowledge has just expanded a bit!

> which is both short and requires people to acknowledge that they are
> making a (necessary) choice about how L is supposed to be sorted. I
> would think explicit is better than implicit for this too.

> Is the main reason to force things like roots to produce deterministic
> output to facilitate doctesting? Would it be bad to put the sort
> command in the doctest?

That is very sneaky!

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William Stein  
View profile  
 More options May 22 2009, 1:40 pm
From: William Stein <wst...@gmail.com>
Date: Fri, 22 May 2009 10:40:29 -0700
Local: Fri, May 22 2009 1:40 pm
Subject: Re: [sage-nt] Re: ordering number field elements
2009/5/22 John Cremona <john.crem...@gmail.com>:

Some notes:  In sage-3.4.2, number field elements do not even have a
sensible hash -- it is  just some default hash inherited from Element
(?), which is "hash of the string representation".  If you fix this by
defining __hash__ (which I expect you did), then because of how Cython
works, the cmp code will be deactivated unless one explicitly defines
__richcmp__.  Anyways, in sage-4.0.rc0, number field elements *do*
have a proper hash function (=the hash of the defining polynomial),
since I had to implement this as part of the Pynac switch.

William

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Roe  
View profile  
 More options May 22 2009, 6:43 pm
From: David Roe <roed...@gmail.com>
Date: Fri, 22 May 2009 15:43:16 -0700
Local: Fri, May 22 2009 6:43 pm
Subject: Re: [sage-nt] Re: ordering number field elements

Another thing to note if you're using sorted lists is the python module
bisect.  Try
sage: import bisect
sage: bisect.<tab>
David

On Fri, May 22, 2009 at 10:36 AM, John Cremona <john.crem...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »