## accessing some pari types

jocaps
Messages : 118
Inscription : lun. avr. 17, 2017 4:32 pm

### accessing some pari types

Hi,

I want to know how to access some member variable of a pari type that comes out of giac/giacpy. Here is an example:

Code : Tout sélectionner

``````from giacpy import giac
giac("printpow(1)")
giac("pari()")
nfinit = giac("nfinit")
galoisinit = giac("galoisinit")

f = giac("t^3-3*t+1") #splitting field has primitive element which is a root of f
G=galoisinit(nfinit(f))
G.group
``````
G.group gives me an error in giac. This is internally defined in Pari as the 6-th element of G (G is a sort of a list).
What I wanted to do is the following:

Code : Tout sélectionner

``````permtopol=giac("galoispermtopol")
permtopol(G,G.group)
#even permtopol(G,G[5]) does not work, result is "undef"
``````
In gp this outputs as [t,t^2-2,-t^2-t+4]

If interested, these are all the roots of t^3-3*t+1 expressed as an algebraic expression with respect to one specific root of the polynomial.

I could of course, straight away run a gp script.. but I wanted to take advantage of python and giacpy here as well (I am doing a lot of algebra here which giacpy has better features than pari)

Jose

frederic han
Messages : 1113
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

### Re: accessing some pari types

Why not using rootof?

Code : Tout sélectionner

``````>>> from giacpy import giac,rootof
>>> t=giac('t')
>>> f=t**3-3*t+1
>>> f.factor(rootof(f))
(t+rootof([[-1,0],[1,0,-3,1]]))*(t+rootof([[-1,0,2],[1,0,-3,1]]))*(t+rootof([[1,1,-2],[1,0,-3,1]]))
>>> f.factors(rootof(f))
[t+rootof([[-1,0],[1,0,-3,1]]),1,t+rootof([[-1,0,2],[1,0,-3,1]]),1,t+rootof([[1,1,-2],[1,0,-3,1]]),1]
``````
NB: indeed your pari compution has also a problem in giac/xcas so it won't work in giacpy.

jocaps
Messages : 118
Inscription : lun. avr. 17, 2017 4:32 pm

### Re: accessing some pari types

Hi Frederic,

Thank you for your answer. I do not understand the output of rootof, I do not see [t,t^2-2,-t^2-t+4] in the output of your sample code. Could you explain a bit?

More generally, if f is a polynomial over Q (of arbitrary degree) such that the splitting field of f is Q(a) for some root "a" of f, then I would like to have all the roots of f expressed as a polynomial of "a".

Jose

parisse
Messages : 5346
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

### Re: accessing some pari types

Well, there is a confusion in the meaning of t, your t is alpha=rootof([[1,0],[1,0,-3,1]]), rootof(P,M) where P and M are list polynomials means P(alpha) where M(alpha)=0 (M irreducible).
The last command of Frederic is the list of factors of t^3-3t+1, i.e. t+(-alpha), t+(-alpha^2+2), t+(alpha^2+alpha-2). Inside giac, you can get a more readable answer (without rootof) by running

Code : Tout sélectionner

``````rootof(t^3-3t+1):=alpha;
factor(t^3-3t+1,alpha);
``````

frederic han
Messages : 1113
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

### Re: accessing some pari types

On giacpy you can do this.

Code : Tout sélectionner

``````In [1]: from giacpy import giac,rootof
// Giac share root-directory:/usr/share/giac/
// Giac share root-directory:/usr/share/giac/

In [2]: t=giac('t')

In [3]: f=t**3-3*t+1

In [4]: j=rootof(f)

In [5]: (j**4).normal()
Out[5]: rootof([[3,-1,0],[1,0,-3,1]])

In [6]: f.factor(j)
Out[6]: (t+rootof([[-1,0],[1,0,-3,1]]))*(t+rootof([[-1,0,2],[1,0,-3,1]]))*(t+rootof([[1,1,-2],[1,0,-3,1]]))

In [7]: giac(str(j)+":=j")  # this trick let the rootof be printed as j. But the variable j inside giac will be assigned to this rootof so don't forget to purge it.
Out[7]: j

In [8]: f.factor(j)
Out[8]: (t+(-j))*(t+(-j**2+2))*(t+(j**2+j-2))

In [9]: j.purge()
Out[9]: rootof([1,0],poly1[1,0,-3,1])

In [10]: f.factor(j)
Out[10]: (t+rootof([[-1,0],[1,0,-3,1]]))*(t+rootof([[-1,0,2],[1,0,-3,1]]))*(t+rootof([[1,1,-2],[1,0,-3,1]]))
``````
NB on windows the giac.dll provided by giacpy is built without NTL (because I think that my NTL built had optimisations for my processor and it gives crashes with lower processors) (so?) the following example seems too long on windows.

Code : Tout sélectionner

``````# example from afactor.xws (in xcas examples)
u=rootof([1,0,-1176,0,345744,-537824])
giac(str(u)+":=u")
X,Y=giac('X,Y')
F2=Y**20+X**20+5*X**16*Y**4+Y**5*X**5+9*X**8*Y**4-6*X**14*Y**2-18*X**10*Y**6-18*X**6*Y**10+10*X**12*Y**8+10*X**8*Y**12+5*Y**16*X**4+9*Y**8*X**4-6*Y**14*X**2
F2.factor()
print("factorisation of F2 over QQ[u]:")
from time import time
t=time()
print(F2.factor(u))  # 5.5s on linux64bit, but too long on win32 because giacpy is built without NTL?
print(time()-t)
``````

frederic han
Messages : 1113
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

### Re: accessing some pari types

NB: rootof is not any root of the polynomial but the greatest for lex ordering. So it makes sense to take approximations:
with j from the above example

Code : Tout sélectionner

``````In [11]: j.approx()
Out[11]: 1.53208888624
``````

frederic han
Messages : 1113
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

### Re: accessing some pari types

Indeed with giacpy-0.5.3-cp27-cp27m-win32.whl that was built with NTL I am able to compute this factorisation on a core i7 but only 6times slower that with linux 64bits.

Code : Tout sélectionner

``````>>> from time import time
>>> t=time(); F2.factor(u); time()-t
(Y**4+u/14*Y*X+X**4)*(Y**16+(-u)/14*Y**13*X+4*Y**12*X**4+(u**2-1176)/196*Y**10*X**2+(-3*u)/14*Y**9*X**5+6*Y**8*X**8+(-u**3+1176*u)/2744*Y**7*X**3+(u**2-1176)/98*Y**6*X**6+(-3*u)/14*Y**5*X**9+4*Y**4*X**12+(u**4-1176*u**2+345744)/38416*Y**4*X**4+(-u**3+1176*u)/2744*Y**3*X**7+(u**2-1176)/196*Y**2*X**10+(-u)/14*Y*X**13+X**16)
36.61199998855591
``````

jocaps
Messages : 118
Inscription : lun. avr. 17, 2017 4:32 pm

### Re: accessing some pari types

parisse a écrit :Well, there is a confusion in the meaning of t, your t is alpha=rootof([[1,0],[1,0,-3,1]]), rootof(P,M) where P and M are list polynomials means P(alpha) where M(alpha)=0 (M irreducible).
The last command of Frederic is the list of factors of t^3-3t+1, i.e. t+(-alpha), t+(-alpha^2+2), t+(alpha^2+alpha-2). Inside giac, you can get a more readable answer (without rootof) by running

Code : Tout sélectionner

``````rootof(t^3-3t+1):=alpha;
factor(t^3-3t+1,alpha);
``````
Ah, I follow now. Thanks Bernard. I think this explains it to me.
frederic han a écrit :NB: rootof is not any root of the polynomial but the greatest for lex ordering. So it makes sense to take approximations:
with j from the above example

Code : Tout sélectionner

``````In [11]: j.approx()
Out[11]: 1.53208888624
``````
This I do not quite understand. What is meant by root of the polynomial with the greatest lex ordering (how do you lex order the roots? do you mean you take the complex number as tuple of two reals and lex order them?)? Sorry for the ignorance, maybe there is a terminology that is commonly used that I do not really know.

Jose

parisse
Messages : 5346
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

### Re: accessing some pari types

It's not lex ordering. The root is choosen with the largest real part. In case of equality, the largest module, and for conjugates, positive imaginary part.

jocaps
Messages : 118
Inscription : lun. avr. 17, 2017 4:32 pm

### Re: accessing some pari types

Thanks. Regarding the ntl issue and windows I can remind everyone about the link of the discussion (crash in factor if giac is linked with ntl in windows):
http://xcas.e.ujf-grenoble.fr/XCAS/view ... f=3&t=1901

What if I am able to compile giac with mpir, will the lack of ntl still make factor slower? I am able to compile giac with mpir in windows (and visual studio).

Jose

parisse
Messages : 5346
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

### Re: accessing some pari types

giac factor without NTL and PARI is slower for some polynomials, those who have many factors in Z/pZ and only a few in Z. If giac is compiled without NTL but with PARI, it should not be too slow.

frederic han
Messages : 1113
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

### Re: accessing some pari types

I have rebuilt NTL with:
'NATIVE' => 'off'
'TUNE' => 'generic'
in DoConfig

now I can't reproduce the crash on a core i3. Is it OK for you?
so with this package
http://webusers.imj-prg.fr/~frederic.ha ... -win32.whl
you should be able to run the above:

Code : Tout sélectionner

``````F2.factor(u)
``````