Re: [sage-devel] Re: Issue with orders in number fields

2023-09-07 Thread Nils Bruin
Hm, interesting. The current code for ZZ.__getitem__ (i.e., ZZ[a]) does 
this:

if isinstance(x, NumberFieldElement_base):
K, _ = parent(x).subfield(x)
return K.order(K.gen())

However, this functionality is also available in K.order:

sage: K.order(a,allow_subfield=True)
Order in Number Field in a with defining polynomial x^4 - 2
sage: K.order(a^2,allow_subfield=True)
Order in Number Field in beta with defining polynomial x^2 - 2*x - 1 with 
beta = -a^2 + 1

so the code could actually just be:
 
 if isinstance(x, NumberFieldElement_base):
return K.order(x,allow_subfield=True)

and then Justin's problem would be solved. It's more economical in that no 
(isomorphic) copy of the field is created. It looks like it does cause 
different problems, though: it looks like K.order wants a standardised 
basis, so:

 sage: K.order(a+1).gens()
(1, a, a^2, a^3)
sage: K.order(a^2+a+1).gens()
(1, 7*a^3 + a, 2*a^3 + a^2, 9*a^3)

So K.order(a) does not need to return an order with a power basis on a. 
Perhaps that's the deeper reason why ZZ[a] does its trickery: certainly one 
would expect an order with power basis on a from that construction.


-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/24916bb3-be70-49fc-a278-1af859a0401fn%40googlegroups.com.


Re: [sage-devel] Re: Issue with orders in number fields

2023-09-07 Thread David Roe
If you want the order generated by a, you can do

sage: K.=NumberField(x^2-10)
sage: OK=K.maximal_order()
sage: O = K.order(a)
sage: O.index_in(OK)
1

Note that this correctly fails in Nils' example:
sage: K.order(a^2)
...
ValueError: the rank of the span of gens is wrong

David

On Thu, Sep 7, 2023 at 11:54 AM Nils Bruin  wrote:

> Hi Justin,
>
> You can see the problem from:
>
> sage: O.ambient()
> Number Field in a0 with defining polynomial x^2 - 10 with a0 = a
>
> As you can see, the ambient field of O is not identical to K (which is the
> ambient field of OK). It is a field with an *embedding* into K, though, and
> it happens to be an isomorphism here.
>
> Mathematically, I think sage is right to have some reservation here. If we
> do
>
> sage: K.=NumberField(x^4-2)
> sage: OK=K.ring_of_integers()
> sage: b=a^2
> sage: O=ZZ[b]
> sage: O.ambient()
> Number Field in a0 with defining polynomial x^2 - 2 with a0 = a^2
>
> I think you see the problem: the field of fractions of ZZ[b] does not need
> to be (and in the above example isn't) equal to the parent of b.
>
> In this case, O wouldn't have a finite index in OK.
>
> For programmatic consistency, we generally avoid programming in
> "shortcuts" based on specific values: while ZZ[a] happens to be an order in
> the parent K of a if a generates it over QQ, we'd generally *not* special
> case that to then create ZZ[a] as an order in K, but still create this
> separate field with generator a0.
>
> It's perhaps inconvenient and pedantic, but I would think this one may
> even still be on the instructive side for having to explain to a student.
>
> On Wednesday, 6 September 2023 at 17:21:12 UTC-7 Justin C. Walker wrote:
>
>> Hi, all,
>>
>> I think I understand what’s going wrong, but I don’t understand how to
>> fix the following problem:
>>
>> sage: K.=NumberField(x^2-10)
>> sage: OK=K.maximal_order()
>> sage: O=ZZ[a]
>> sage: a in OK
>> True
>> sage: a in K
>> True
>> sage: a in O
>> True
>> sage: O.index_in(OK)
>>
>> ---
>> ValueErrorTraceback (most recent call
>> last)
>> ...Blooie
>> ValueError: other must have the same ambient number field as self.
>>
>> Have we just painted ourselves into a (figurative) corner?
>>
>> Pointers?  Suggestions?
>>
>> Thanks for any help.
>>
>> Justin
>>
>> --
>> Justin C. Walker, Curmudgeon at Large
>> Institute for the Absorption of Federal Funds
>> ---
>> While creating wives, God promised men
>> that good and obedient wives would be
>> found in all corners of the world.
>> Then He made the earth round.
>> --
>>
>>
>>
>>
>>
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-devel/91b7f3ea-fd89-446e-8a26-3e474414d32cn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAChs6_m%2BDdvtLUq5ouCEkNK6qo31upfkHqCLF_0R0DwTgmU1Nw%40mail.gmail.com.


[sage-devel] Re: Issue with orders in number fields

2023-09-07 Thread Nils Bruin
Hi Justin,

You can see the problem from:

sage: O.ambient()
Number Field in a0 with defining polynomial x^2 - 10 with a0 = a

As you can see, the ambient field of O is not identical to K (which is the 
ambient field of OK). It is a field with an *embedding* into K, though, and 
it happens to be an isomorphism here.

Mathematically, I think sage is right to have some reservation here. If we 
do

sage: K.=NumberField(x^4-2)
sage: OK=K.ring_of_integers()
sage: b=a^2
sage: O=ZZ[b]
sage: O.ambient()
Number Field in a0 with defining polynomial x^2 - 2 with a0 = a^2

I think you see the problem: the field of fractions of ZZ[b] does not need 
to be (and in the above example isn't) equal to the parent of b.

In this case, O wouldn't have a finite index in OK.

For programmatic consistency, we generally avoid programming in "shortcuts" 
based on specific values: while ZZ[a] happens to be an order in the parent 
K of a if a generates it over QQ, we'd generally *not* special case that to 
then create ZZ[a] as an order in K, but still create this separate field 
with generator a0.

It's perhaps inconvenient and pedantic, but I would think this one may even 
still be on the instructive side for having to explain to a student.

On Wednesday, 6 September 2023 at 17:21:12 UTC-7 Justin C. Walker wrote:

> Hi, all,
>
> I think I understand what’s going wrong, but I don’t understand how to fix 
> the following problem:
>
> sage: K.=NumberField(x^2-10)
> sage: OK=K.maximal_order()
> sage: O=ZZ[a]
> sage: a in OK
> True
> sage: a in K
> True
> sage: a in O
> True
> sage: O.index_in(OK)
> ---
> ValueErrorTraceback (most recent call last)
> ...Blooie
> ValueError: other must have the same ambient number field as self.
>
> Have we just painted ourselves into a (figurative) corner?
>
> Pointers?  Suggestions?
>
> Thanks for any help.
>
> Justin
>
> --
> Justin C. Walker, Curmudgeon at Large
> Institute for the Absorption of Federal Funds
> ---
> While creating wives, God promised men
> that good and obedient wives would be
> found in all corners of the world.
> Then He made the earth round.
> --
>
>
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/91b7f3ea-fd89-446e-8a26-3e474414d32cn%40googlegroups.com.