On calculating the greatest common divisor in Gaussian field

60 views
Skip to first unread message

Zhibin Liang

unread,
May 30, 2012, 11:37:40 PM5/30/12
to Sage-nt
Dear all,

Let K.<i> be a Gaussian field with i=sqrt(-1). I want to calculate
greatest divisor of two element. For example,
I want (1+i,2+2*i)=1+i, but sage outputs 1 instead. Does somebody
solve this problem for me? Here is the programme:


Q.<T>=PolynomialRing(Rationals())
K.<i>=NumberField(T^2+1)
gcd(1+i,2+2*i)

the result is 1

--

Very best wishes
Zhibin Liang

Building 104 Room 103
Nanhudongyuanyiqu
Wangjing, Chaoyang District
Beijing China,
100102

David Harvey

unread,
May 31, 2012, 1:01:35 AM5/31/12
to <sage-nt@googlegroups.com>

On May 31, 2012, at 1:37 PM, Zhibin Liang wrote:

> Dear all,
>
> Let K.<i> be a Gaussian field with i=sqrt(-1). I want to calculate
> greatest divisor of two element. For example,
> I want (1+i,2+2*i)=1+i, but sage outputs 1 instead. Does somebody
> solve this problem for me? Here is the programme:
>
>
> Q.<T>=PolynomialRing(Rationals())
> K.<i>=NumberField(T^2+1)
> gcd(1+i,2+2*i)

sage: K.ideal(1 + i, 2 + 2*i).gens_reduced()[0]
i + 1

david

John Cremona

unread,
May 31, 2012, 4:59:41 AM5/31/12
to sag...@googlegroups.com
The reason for the output of 1 is just a pedantic one: 1+i and 2+i
are elements of a field: their parent is

sage: (1+i).parent()
Number Field in i with defining polynomial T^2 + 1

One can force the computation to take place in the ring of integers:

sage: R = K.ring_of_integers()
sage: a=R(1+i)
sage: b=R(2+2*i)
sage: gcd(a,b)
...
TypeError: unable to find gcd of i + 1 and 2*i + 2

since there's no gcd method for a:

sage: type(a)
<type 'sage.rings.number_field.number_field_element_quadratic.OrderElement_quadratic'>
sage: a.parent()
Maximal Order in Number Field in i with defining polynomial T^2 + 1

Possible fix: define a gcd function for elements of an order which
coerces into the field, constructs the ideal (as in David's solution),
tests if it is principal, returns a generator if it is and raises an
error only if it is not principal (which would be never for fields of
class number 1). Is that worth doing? In which case a trac ticket
could be opened. It seems an easy enough thing to implement, except
possibly for non-maximal orders.

John

>
> --
> You received this message because you are subscribed to the Google Groups "sage-nt" group.
> To post to this group, send an email to sag...@googlegroups.com.
> To unsubscribe from this group, send email to sage-nt+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sage-nt?hl=en-GB.
>

Chris Wuthrich

unread,
May 31, 2012, 5:29:01 AM5/31/12
to sag...@googlegroups.com
>  In which case a trac ticket
> could be opened.

I would like to point out that I did _long ago_ write somethings
exactly for Z[i], which includes the gcd. The abadoned ticket is

http://trac.sagemath.org/sage_trac/ticket/7545

(probably it does not work at all anymore).

Note also that pari-gp has everything for Z[i].

? gcd(1+I,2+2*I)
%1 = 1 + I

So one could also just take it from there.

Chris.

John Cremona

unread,
May 31, 2012, 6:13:59 AM5/31/12
to sag...@googlegroups.com
On 31 May 2012 10:29, Chris Wuthrich <christian...@gmail.com> wrote:
>>  In which case a trac ticket
>> could be opened.
>
> I would like to point out that I did _long ago_ write somethings
> exactly for Z[i], which includes the gcd. The abadoned ticket is
>
> http://trac.sagemath.org/sage_trac/ticket/7545
>
> (probably it does not work at all anymore).

Thanks, I had completely forgotten that.

John

>
> Note also that pari-gp has everything for Z[i].
>
>  ? gcd(1+I,2+2*I)
>  %1 = 1 + I
>
> So one could also just take it from there.
>
> Chris.
>
Reply all
Reply to author
Forward
0 new messages