# Computing maximal orders in relative extensions

As part of a project, I am translating some MAGMA code to SAGE. The relevant piece of code computes the maximal order of the relative extension of `Qa12`

, a number field of degree 20, by the polynomial `y^2 - kappa12`

:

```
subOrderK:=ext<OO | y^2-kappa12>;
subOrderK:=AbsoluteOrder(subOrderK);
D:=Discriminant(subOrderK);
for p in PrimeDivisors(D) do
subOrderK:=pMaximalOrder(subOrderK,p);
end for;
OOK:=subOrderK;
```

Here `OO`

is the ring of integers (i.e. the maximal order) of `Qa12`

.
As I did not see a way to translate this word for word (if I am missing something, please point it out), I tried a different approach. Here is my code (in SAGE):

```
L.<c> = Qa12.extension(y^2-kappa12)
L.<alpha> = L.absolute_field()
subOrderK = L.order(alpha)
D = subOrderK.discriminant()
for p in factor(D):
subOrderK = L.maximal_order(p[0])
OOK = subOrderK
```

Note that `y^2-kappa12`

has coefficients coerced in `Qa12`

and we make sure that it is indeed irreducible in `Qa12`

(i.e. we make sure that `kappa12`

is not the square of an element of `Qa12`

).
You may notice immediately that my for-loop is a rather clumsy translation of the corresponding loop in the MAGMA code. I was hoping that SAGE would "remember" the previous value of `subOrderK`

, thus having the same effect as the MAGMA-command `pMaximalOrder(subOrderK,p)`

. However, my problem arises even earlier than that:
the number computed by `subOrderK.discriminant()`

is absurdly huge - too big, in fact, for there to be any hope to factorise it in any reasonable amount of time.

The obvious alternative of simply writing

```
L.<c> = Qa12.extension(y^2-kappa12)
L.<alpha> = L.absolute_field()
OOK = L.maximal_order()
```

is also extremely time-intensive; I have not yet seen this finish.

I was hoping someone could help either with improving my code, or with a radically different approach to the problem.

NOTE: Though I have tried to make this question understandable, if some parts remain opaque, please do say so. I'll do my best to correct it.

Just as a point of information, this author has also posted the question at [stackoverflow](http://stackoverflow.com/questions/11850418/computing-maximal-orders-in-large-number-fields-with-sage).