Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - basemath - subcyclo.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 19837-cc815bb) Lines: 524 554 94.6 %
Date: 2016-12-10 05:49:10 Functions: 38 39 97.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : #include "pari.h"
      15             : #include "paripriv.h"
      16             : 
      17             : /*************************************************************************/
      18             : /**                                                                     **/
      19             : /**              Routines for handling subgroups of (Z/nZ)^*            **/
      20             : /**              without requiring discrete logarithms.                 **/
      21             : /**                                                                     **/
      22             : /*************************************************************************/
      23             : /* Subgroups are [gen,ord,bits] where
      24             :  * gen is a vecsmall of generators
      25             :  * ord is theirs relative orders
      26             :  * bits is a bit vector of the elements, of length(n). */
      27             : 
      28             : /*The algorithm is similar to testpermutation*/
      29             : static void
      30        4865 : znstar_partial_coset_func(long n, GEN H, void (*func)(void *data,long c)
      31             :     , void *data, long d, long c)
      32             : {
      33             :   GEN gen, ord, cache;
      34             :   long i, j, card;
      35             : 
      36        9730 :   if (!d) { (*func)(data,c); return; }
      37             : 
      38        2856 :   cache = const_vecsmall(d,c);
      39        2856 :   (*func)(data,c);  /* AFTER cache: may contain gerepileupto statement */
      40        2856 :   gen = gel(H,1);
      41        2856 :   ord = gel(H,2);
      42        2856 :   card = ord[1]; for (i = 2; i <= d; i++) card *= ord[i];
      43       68201 :   for(i=1; i<card; i++)
      44             :   {
      45       65345 :     long k, m = i;
      46       65345 :     for(j=1; j<d && m%ord[j]==0 ;j++) m /= ord[j];
      47       65345 :     cache[j] = Fl_mul(cache[j],gen[j],n);
      48       65345 :     for (k=1; k<j; k++) cache[k] = cache[j];
      49       65345 :     (*func)(data, cache[j]);
      50             :   }
      51             : }
      52             : 
      53             : static void
      54        1232 : znstar_coset_func(long n, GEN H, void (*func)(void *data,long c)
      55             :     , void *data, long c)
      56             : {
      57        1232 :   znstar_partial_coset_func(n, H, func,data, lg(gel(H,1))-1, c);
      58        1232 : }
      59             : 
      60             : /* Add the element of the bitvec of the coset c modulo the subgroup of H
      61             :  * generated by the first d generators to the bitvec bits.*/
      62             : 
      63             : static void
      64        3633 : znstar_partial_coset_bits_inplace(long n, GEN H, GEN bits, long d, long c)
      65             : {
      66        3633 :   pari_sp av = avma;
      67        3633 :   znstar_partial_coset_func(n,H, (void (*)(void *,long)) &F2v_set,
      68             :       (void *) bits, d, c);
      69        3633 :   avma = av;
      70        3633 : }
      71             : 
      72             : static void
      73         616 : znstar_coset_bits_inplace(long n, GEN H, GEN bits, long c)
      74             : {
      75         616 :   znstar_partial_coset_bits_inplace(n, H, bits, lg(gel(H,1))-1, c);
      76         616 : }
      77             : 
      78             : static GEN
      79        3017 : znstar_partial_coset_bits(long n, GEN H, long d, long c)
      80             : {
      81        3017 :   GEN bits = zero_F2v(n);
      82        3017 :   znstar_partial_coset_bits_inplace(n,H,bits,d,c);
      83        3017 :   return bits;
      84             : }
      85             : 
      86             : /* Compute the bitvec of the elements of the subgroup of H generated by the
      87             :  * first d generators.*/
      88             : static GEN
      89        3017 : znstar_partial_bits(long n, GEN H, long d)
      90             : {
      91        3017 :   return znstar_partial_coset_bits(n, H, d, 1);
      92             : }
      93             : 
      94             : /* Compute the bitvec of the elements of H. */
      95             : GEN
      96           0 : znstar_bits(long n, GEN H)
      97             : {
      98           0 :   return znstar_partial_bits(n,H,lg(gel(H,1))-1);
      99             : }
     100             : 
     101             : /* Compute the subgroup of (Z/nZ)^* generated by the elements of
     102             :  * the vecsmall V */
     103             : GEN
     104        1799 : znstar_generate(long n, GEN V)
     105             : {
     106        1799 :   pari_sp av = avma;
     107        1799 :   GEN gen = cgetg(lg(V),t_VECSMALL);
     108        1799 :   GEN ord = cgetg(lg(V),t_VECSMALL), res = mkvec2(gen,ord);
     109        1799 :   GEN bits = znstar_partial_bits(n,NULL,0);
     110        1799 :   long i, r = 0;
     111        4277 :   for(i=1; i<lg(V); i++)
     112             :   {
     113        2478 :     ulong v = uel(V,i), g = v;
     114        2478 :     long o = 0;
     115        2478 :     while (!F2v_coeff(bits, (long)g)) { g = Fl_mul(g, v, (ulong)n); o++; }
     116        2478 :     if (!o) continue;
     117        1218 :     r++;
     118        1218 :     gen[r] = v;
     119        1218 :     ord[r] = o+1;
     120        1218 :     cgiv(bits); bits = znstar_partial_bits(n,res,r);
     121             :   }
     122        1799 :   setlg(gen,r+1);
     123        1799 :   setlg(ord,r+1); return gerepilecopy(av, mkvec3(gen,ord,bits));
     124             : }
     125             : 
     126             : static ulong
     127        1862 : znstar_order(GEN H) { return zv_prod(gel(H,2)); }
     128             : 
     129             : /* Return the lists of element of H.
     130             :  * This can be implemented with znstar_coset_func instead. */
     131             : GEN
     132        1610 : znstar_elts(long n, GEN H)
     133             : {
     134        1610 :   long card = znstar_order(H);
     135        1610 :   GEN gen = gel(H,1), ord = gel(H,2);
     136        1610 :   GEN sg = cgetg(1 + card, t_VECSMALL);
     137             :   long k, j, l;
     138        1610 :   sg[1] = 1;
     139        2597 :   for (j = 1, l = 1; j < lg(gen); j++)
     140             :   {
     141         987 :     long c = l * (ord[j]-1);
     142         987 :     for (k = 1; k <= c; k++) sg[++l] = Fl_mul(sg[k], gen[j], n);
     143             :   }
     144        1610 :   vecsmall_sort(sg); return sg;
     145             : }
     146             : 
     147             : /* Take a znstar H and n dividing the modulus of H.
     148             :  * Output H reduced to modulus n */
     149             : GEN
     150          35 : znstar_reduce_modulus(GEN H, long n)
     151             : {
     152          35 :   pari_sp ltop=avma;
     153          35 :   GEN gen=cgetg(lgcols(H),t_VECSMALL);
     154             :   long i;
     155         119 :   for(i=1; i < lg(gen); i++)
     156          84 :     gen[i] = mael(H,1,i)%n;
     157          35 :   return gerepileupto(ltop, znstar_generate(n,gen));
     158             : }
     159             : 
     160             : /* Compute conductor of H */
     161             : long
     162         154 : znstar_conductor(long n, GEN H)
     163             : {
     164         154 :   pari_sp av = avma;
     165         154 :   long i, j, cnd = n;
     166         154 :   GEN F = factoru(n), P = gel(F,1), E = gel(F,2);
     167         378 :   for (i = lg(P)-1; i > 0; i--)
     168             :   {
     169         224 :     long p = P[i], e = E[i], q = n;
     170         224 :     if (DEBUGLEVEL>=4) err_printf("SubCyclo: testing %ld^%ld\n",p,e);
     171         322 :     for (  ; e >= 1; e--)
     172             :     {
     173         266 :       long z = 1;
     174         266 :       q /= p;
     175        3129 :       for (j = 1; j < p; j++)
     176             :       {
     177        3031 :         z += q;
     178        3031 :         if (!F2v_coeff(gel(H,3),z) && ugcd(z,n)==1) break;
     179             :       }
     180         266 :       if (j < p)
     181             :       {
     182         168 :         if (DEBUGLEVEL>=4) err_printf("SubCyclo: %ld not found\n",z);
     183         168 :         break;
     184             :       }
     185          98 :       cnd /= p;
     186          98 :       if (DEBUGLEVEL>=4) err_printf("SubCyclo: new conductor:%ld\n",cnd);
     187             :     }
     188             :   }
     189         154 :   if (DEBUGLEVEL>=6) err_printf("SubCyclo: conductor:%ld\n",cnd);
     190         154 :   avma = av; return cnd;
     191             : }
     192             : 
     193             : /* Compute the orbits of a subgroups of Z/nZ given by a generator
     194             :  * or a set of generators given as a vector.
     195             :  */
     196             : GEN
     197         126 : znstar_cosets(long n, long phi_n, GEN H)
     198             : {
     199             :   long    k;
     200         126 :   long    c = 0;
     201         126 :   long    card   = znstar_order(H);
     202         126 :   long    index  = phi_n/card;
     203         126 :   GEN     cosets = cgetg(index+1,t_VECSMALL);
     204         126 :   pari_sp ltop = avma;
     205         126 :   GEN     bits   = zero_F2v(n);
     206         742 :   for (k = 1; k <= index; k++)
     207             :   {
     208         616 :     for (c++ ; F2v_coeff(bits,c) || ugcd(c,n)!=1; c++);
     209         616 :     cosets[k]=c;
     210         616 :     znstar_coset_bits_inplace(n, H, bits, c);
     211             :   }
     212         126 :   avma=ltop;
     213         126 :   return cosets;
     214             : }
     215             : 
     216             : 
     217             : /*************************************************************************/
     218             : /**                                                                     **/
     219             : /**                     znstar/HNF interface                            **/
     220             : /**                                                                     **/
     221             : /*************************************************************************/
     222             : static GEN
     223         756 : vecmod_to_vecsmall(GEN z)
     224             : {
     225         756 :   long i, l = lg(z);
     226         756 :   GEN x = cgetg(l, t_VECSMALL);
     227        1750 :   for (i=1; i<l; i++) {
     228         994 :     GEN c = gel(z,i);
     229         994 :     if (typ(c) == t_INTMOD) c = gel(c,2);
     230         994 :     x[i] = itos(c);
     231             :   }
     232         756 :   return x;
     233             : }
     234             : /* Convert a true znstar output by znstar to a `small znstar' */
     235             : GEN
     236         756 : znstar_small(GEN zn)
     237             : {
     238         756 :   GEN Z = cgetg(4,t_VEC);
     239         756 :   gel(Z,1) = icopy(gmael3(zn,3,1,1));
     240         756 :   gel(Z,2) = vec_to_vecsmall(gel(zn,2));
     241         756 :   gel(Z,3) = vecmod_to_vecsmall(gel(zn,3)); return Z;
     242             : }
     243             : 
     244             : /* Compute generators for the subgroup of (Z/nZ)* given in HNF. */
     245             : GEN
     246        1673 : znstar_hnf_generators(GEN Z, GEN M)
     247             : {
     248        1673 :   long j, h, l = lg(M);
     249        1673 :   GEN gen = cgetg(l, t_VECSMALL);
     250        1673 :   pari_sp ltop = avma;
     251        1673 :   GEN zgen = gel(Z,3);
     252        1673 :   ulong n = itou(gel(Z,1));
     253        3976 :   for (j = 1; j < l; j++)
     254             :   {
     255        2303 :     GEN Mj = gel(M,j);
     256        2303 :     gen[j] = 1;
     257        6006 :     for (h = 1; h < l; h++)
     258             :     {
     259        3703 :       ulong u = itou(gel(Mj,h));
     260        3703 :       if (!u) continue;
     261        2471 :       gen[j] = Fl_mul(uel(gen,j), Fl_powu(uel(zgen,h), u, n), n);
     262             :     }
     263             :   }
     264        1673 :   avma = ltop; return gen;
     265             : }
     266             : 
     267             : GEN
     268        1610 : znstar_hnf(GEN Z, GEN M)
     269             : {
     270        1610 :   return znstar_generate(itos(gel(Z,1)),znstar_hnf_generators(Z,M));
     271             : }
     272             : 
     273             : GEN
     274        1610 : znstar_hnf_elts(GEN Z, GEN H)
     275             : {
     276        1610 :   pari_sp ltop = avma;
     277        1610 :   GEN G = znstar_hnf(Z,H);
     278        1610 :   long n = itos(gel(Z,1));
     279        1610 :   return gerepileupto(ltop, znstar_elts(n,G));
     280             : }
     281             : 
     282             : /*************************************************************************/
     283             : /**                                                                     **/
     284             : /**                     polsubcyclo                                     **/
     285             : /**                                                                     **/
     286             : /*************************************************************************/
     287             : 
     288             : static GEN
     289         154 : gscycloconductor(GEN g, long n, long flag)
     290             : {
     291         154 :   if (flag==2) retmkvec2(gcopy(g), stoi(n));
     292         154 :   return g;
     293             : }
     294             : 
     295             : static long
     296          98 : lift_check_modulus(GEN H, long n)
     297             : {
     298             :   long h;
     299          98 :   switch(typ(H))
     300             :   {
     301             :     case t_INTMOD:
     302           7 :       if (!equalsi(n, gel(H,1)))
     303           7 :         pari_err_MODULUS("galoissubcyclo", stoi(n), gel(H,1));
     304           0 :       H = gel(H,2);
     305             :     case t_INT:
     306          91 :       h = smodis(H,n);
     307          91 :       if (ugcd(h,n) != 1) pari_err_COPRIME("galoissubcyclo", H,stoi(n));
     308          91 :       return h;
     309             :   }
     310           0 :   pari_err_TYPE("galoissubcyclo [subgroup]", H);
     311           0 :   return 0;/*not reached*/
     312             : }
     313             : 
     314             : /* Compute z^ex using the baby-step/giant-step table powz
     315             :  * with only one multiply.
     316             :  * In the modular case, the result is not reduced. */
     317             : static GEN
     318      217224 : polsubcyclo_powz(GEN powz, long ex)
     319             : {
     320      217224 :   long m = lg(gel(powz,1))-1, q = ex/m, r = ex%m; /*ex=m*q+r*/
     321      217224 :   GEN g = gmael(powz,1,r+1), G = gmael(powz,2,q+1);
     322      217224 :   return (lg(powz)==4)? mulreal(g,G): gmul(g,G);
     323             : }
     324             : 
     325             : static GEN
     326        3080 : polsubcyclo_complex_bound(pari_sp av, GEN V, long prec)
     327             : {
     328        3080 :   GEN pol = real_i(roots_to_pol(V,0));
     329        3080 :   return gerepileuptoint(av, ceil_safe(gsupnorm(pol,prec)));
     330             : }
     331             : 
     332             : /* Newton sums mod le. if le==NULL, works with complex instead */
     333             : static GEN
     334        5908 : polsubcyclo_cyclic(long n, long d, long m ,long z, long g, GEN powz, GEN le)
     335             : {
     336        5908 :   GEN V = cgetg(d+1,t_VEC);
     337        5908 :   ulong base = 1;
     338             :   long i,k;
     339             :   pari_timer ti;
     340        5908 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     341       52416 :   for (i=1; i<=d; i++, base = Fl_mul(base,z,n))
     342             :   {
     343       46508 :     pari_sp av = avma;
     344       46508 :     long ex = base;
     345       46508 :     GEN s = gen_0;
     346      235088 :     for (k=0; k<m; k++, ex = Fl_mul(ex,g,n))
     347             :     {
     348      188580 :       s = gadd(s, polsubcyclo_powz(powz,ex));
     349      188580 :       if ((k&0xff)==0) s = gerepileupto(av,s);
     350             :     }
     351       46508 :     if (le) s = modii(s, le);
     352       46508 :     gel(V,i) = gerepileupto(av, s);
     353             :   }
     354        5908 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "polsubcyclo_cyclic");
     355        5908 :   return V;
     356             : }
     357             : 
     358             : struct _subcyclo_orbits_s
     359             : {
     360             :   GEN powz;
     361             :   GEN *s;
     362             :   ulong count;
     363             :   pari_sp ltop;
     364             : };
     365             : 
     366             : static void
     367       28644 : _subcyclo_orbits(struct _subcyclo_orbits_s *data, long k)
     368             : {
     369       28644 :   GEN powz = data->powz;
     370       28644 :   GEN *s = data->s;
     371             : 
     372       28644 :   if (!data->count) data->ltop = avma;
     373       28644 :   *s = gadd(*s, polsubcyclo_powz(powz,k));
     374       28644 :   data->count++;
     375       28644 :   if ((data->count & 0xffUL) == 0) *s = gerepileupto(data->ltop, *s);
     376       28644 : }
     377             : 
     378             : /* Newton sums mod le. if le==NULL, works with complex instead */
     379             : static GEN
     380         252 : polsubcyclo_orbits(long n, GEN H, GEN O, GEN powz, GEN le)
     381             : {
     382         252 :   long i, d = lg(O);
     383         252 :   GEN V = cgetg(d,t_VEC);
     384             :   struct _subcyclo_orbits_s data;
     385         252 :   long lle = le?lg(le)*2+1: 2*lg(gmael(powz,1,2))+3;/*dvmdii uses lx+ly space*/
     386         252 :   data.powz = powz;
     387        1484 :   for(i=1; i<d; i++)
     388             :   {
     389        1232 :     GEN s = gen_0;
     390        1232 :     pari_sp av = avma;
     391        1232 :     (void)new_chunk(lle);
     392        1232 :     data.count = 0;
     393        1232 :     data.s     = &s;
     394        1232 :     znstar_coset_func(n, H, (void (*)(void *,long)) _subcyclo_orbits,
     395        1232 :       (void *) &data, O[i]);
     396        1232 :     avma = av; /* HACK */
     397        1232 :     gel(V,i) = le? modii(s,le): gcopy(s);
     398             :   }
     399         252 :   return V;
     400             : }
     401             : 
     402             : static GEN
     403        8512 : polsubcyclo_start(long n, long d, long o, GEN borne, long *ptr_val,long *ptr_l)
     404             : {
     405             :   pari_sp av;
     406             :   GEN le, z, gl;
     407             :   long i, l, e, val;
     408        8512 :   l = n+1; e = 1;
     409        8512 :   while(!uisprime(l)) { l += n; e++; }
     410        8512 :   if (DEBUGLEVEL >= 4) err_printf("Subcyclo: prime l=%ld\n",l);
     411        8512 :   gl = utoipos(l); av = avma;
     412        8512 :   if (!borne)
     413             :   { /* Use vecmax(Vec((x+o)^d)) = max{binomial(d,i)*o^i ;1<=i<=d} */
     414         154 :     i = d-(1+d)/(1+o);
     415         154 :     borne = mulii(binomial(utoipos(d),i),powuu(o,i));
     416             :   }
     417        8512 :   if (DEBUGLEVEL >= 4) err_printf("Subcyclo: bound=2^%ld\n",expi(borne));
     418        8512 :   val = logint(shifti(borne,2), gl) + 1;
     419        8512 :   avma = av;
     420        8512 :   if (DEBUGLEVEL >= 4) err_printf("Subcyclo: val=%ld\n",val);
     421        8512 :   le = powiu(gl,val);
     422        8512 :   z = utoipos( Fl_powu(pgener_Fl(l), e, l) );
     423        8512 :   z = Zp_sqrtnlift(gen_1,utoipos(n),z,gl,val);
     424        8512 :   *ptr_val = val;
     425        8512 :   *ptr_l = l;
     426        8512 :   return gmodulo(z,le);
     427             : }
     428             : 
     429             : /*Fill in the powz table:
     430             :  *  powz[1]: baby-step
     431             :  *  powz[2]: giant-step
     432             :  *  powz[3] exists only if the field is real (value is ignored). */
     433             : static GEN
     434        3080 : polsubcyclo_complex_roots(long n, long real, long prec)
     435             : {
     436        3080 :   long i, m = (long)(1+sqrt((double) n));
     437        3080 :   GEN bab, gig, powz = cgetg(real?4:3, t_VEC);
     438             : 
     439        3080 :   bab = cgetg(m+1,t_VEC);
     440        3080 :   gel(bab,1) = gen_1;
     441        3080 :   gel(bab,2) = rootsof1u_cx(n, prec); /* = e_n(1) */
     442        3080 :   for (i=3; i<=m; i++) gel(bab,i) = gmul(gel(bab,2),gel(bab,i-1));
     443        3080 :   gig = cgetg(m+1,t_VEC);
     444        3080 :   gel(gig,1) = gen_1;
     445        3080 :   gel(gig,2) = gmul(gel(bab,2),gel(bab,m));;
     446        3080 :   for (i=3; i<=m; i++) gel(gig,i) = gmul(gel(gig,2),gel(gig,i-1));
     447        3080 :   gel(powz,1) = bab;
     448        3080 :   gel(powz,2) = gig;
     449        3080 :   if (real) gel(powz,3) = gen_0;
     450        3080 :   return powz;
     451             : }
     452             : 
     453             : static GEN
     454       22736 : muliimod_sz(GEN x, GEN y, GEN l, long siz)
     455             : {
     456       22736 :   pari_sp av = avma;
     457             :   GEN p1;
     458       22736 :   (void)new_chunk(siz); /* HACK */
     459       22736 :   p1 = mulii(x,y);
     460       22736 :   avma = av; return modii(p1,l);
     461             : }
     462             : 
     463             : static GEN
     464        3080 : polsubcyclo_roots(long n, GEN zl)
     465             : {
     466        3080 :   GEN le = gel(zl,1), z = gel(zl,2);
     467        3080 :   long i, lle = lg(le)*3; /*Assume dvmdii use lx+ly space*/
     468        3080 :   long m = (long)(1+sqrt((double) n));
     469        3080 :   GEN bab, gig, powz = cgetg(3,t_VEC);
     470             :   pari_timer ti;
     471        3080 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     472        3080 :   bab = cgetg(m+1,t_VEC);
     473        3080 :   gel(bab,1) = gen_1;
     474        3080 :   gel(bab,2) = icopy(z);
     475        3080 :   for (i=3; i<=m; i++) gel(bab,i) = muliimod_sz(z,gel(bab,i-1),le,lle);
     476        3080 :   gig = cgetg(m+1,t_VEC);
     477        3080 :   gel(gig,1) = gen_1;
     478        3080 :   gel(gig,2) = muliimod_sz(z,gel(bab,m),le,lle);;
     479        3080 :   for (i=3; i<=m; i++) gel(gig,i) = muliimod_sz(gel(gig,2),gel(gig,i-1),le,lle);
     480        3080 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "polsubcyclo_roots");
     481        3080 :   gel(powz,1) = bab;
     482        3080 :   gel(powz,2) = gig; return powz;
     483             : }
     484             : 
     485             : GEN
     486         154 : galoiscyclo(long n, long v)
     487             : {
     488         154 :   ulong av = avma;
     489             :   GEN grp, G, z, le, L, elts;
     490             :   long val, l, i, j, k;
     491         154 :   GEN zn = znstar(stoi(n));
     492         154 :   long card = itos(gel(zn,1));
     493         154 :   GEN gen = vec_to_vecsmall(lift_shallow(gel(zn,3)));
     494         154 :   GEN ord = gtovecsmall(gel(zn,2));
     495             : 
     496         154 :   z = polsubcyclo_start(n,card/2,2,NULL,&val,&l);
     497         154 :   le = gel(z,1); z = gel(z,2);
     498         154 :   L = cgetg(1+card,t_VEC);
     499         154 :   gel(L,1) = z;
     500         336 :   for (j = 1, i = 1; j < lg(gen); j++)
     501             :   {
     502         182 :     long c = i * (ord[j]-1);
     503         182 :     for (k = 1; k <= c; k++) gel(L,++i) = Fp_powu(gel(L,k), gen[j], le);
     504             :   }
     505         154 :   G = abelian_group(ord);
     506         154 :   elts = group_elts(G, card); /*not stack clean*/
     507         154 :   grp = cgetg(9, t_VEC);
     508         154 :   gel(grp,1) = polcyclo(n,v);
     509         154 :   gel(grp,2) = mkvec3(stoi(l), stoi(val), icopy(le));
     510         154 :   gel(grp,3) = gcopy(L);
     511         154 :   gel(grp,4) = FpV_invVandermonde(L,  NULL, le);
     512         154 :   gel(grp,5) = gen_1;
     513         154 :   gel(grp,6) = gcopy(elts);
     514         154 :   gel(grp,7) = gcopy(gel(G,1));
     515         154 :   gel(grp,8) = gcopy(gel(G,2));
     516         154 :   return gerepileupto(av, grp);
     517             : }
     518             : 
     519             : /* Convert a bnrinit(Q,n) to a znstar(n)
     520             :  * complex is set to 0 if the bnr is real and to 1 if it is complex.
     521             :  * Not stack clean */
     522             : GEN
     523          14 : bnr_to_znstar(GEN bnr, long *complex)
     524             : {
     525             :   GEN gen, F, v, bid;
     526             :   long l, i;
     527          14 :   checkbnr(bnr);
     528          14 :   bid = bnr_get_bid(bnr);
     529          14 :   gen = bid_get_gen(bid);
     530          14 :   F = bid_get_ideal(bid);
     531          14 :   if (lg(F) != 2)
     532           7 :     pari_err_DOMAIN("bnr_to_znstar", "bnr", "!=", strtoGENstr("Q"), bnr);
     533             :   /* F is the finite part of the conductor, complex is the infinite part*/
     534           7 :   F = gcoeff(F, 1, 1);
     535           7 :   *complex = signe(gel(bid_get_arch(bid), 1));
     536           7 :   l = lg(gen); v = cgetg(l, t_VEC);
     537          42 :   for (i = 1; i < l; ++i)
     538             :   {
     539          35 :     GEN x = gel(gen,i);
     540          35 :     if (typ(x) == t_COL) x = gel(x,1);
     541          35 :     gel(v,i) = gmodulo(absi(x), F);
     542             :   }
     543           7 :   return mkvec3(bnr_get_no(bnr), bnr_get_cyc(bnr), v);
     544             : }
     545             : 
     546             : GEN
     547         203 : galoissubcyclo(GEN N, GEN sg, long flag, long v)
     548             : {
     549         203 :   pari_sp ltop= avma, av;
     550         203 :   GEN H, V, B, zl, L, T, le, powz, O, Z = NULL;
     551         203 :   long i, card, phi_n, val,l, n, cnd, complex=1;
     552             :   pari_timer ti;
     553             : 
     554         203 :   if (flag<0 || flag>2) pari_err_FLAG("galoissubcyclo");
     555         203 :   if (v < 0) v = 0;
     556         203 :   if (!sg) sg = gen_1;
     557         203 :   switch(typ(N))
     558             :   {
     559             :     case t_INT:
     560         119 :       n = itos(N);
     561         119 :       if (n < 1)
     562           7 :         pari_err_DOMAIN("galoissubcyclo", "degree", "<=", gen_0, stoi(n));
     563         112 :       break;
     564             :     case t_VEC:
     565          84 :       if (lg(N)==7) N = bnr_to_znstar(N,&complex);
     566          77 :       if (lg(N)==4)
     567             :       { /* znstar */
     568          77 :         GEN gen = abgrp_get_gen(N);
     569          77 :         Z = N;
     570          77 :         if (typ(gen)!=t_VEC) pari_err_TYPE("galoissubcyclo",gen);
     571          77 :         if (lg(gen) == 1) n = 1;
     572          77 :         else if (typ(gel(gen,1)) == t_INTMOD)
     573             :         {
     574          70 :           GEN z = gel(gen,1);
     575          70 :           n = itos(gel(z,1));
     576             :         } else
     577             :         {
     578           7 :           pari_err_TYPE("galoissubcyclo",N);
     579           0 :           return NULL;/*Not reached*/
     580             :         }
     581          70 :         break;
     582             :       }
     583             :     default: /*fall through*/
     584           0 :       pari_err_TYPE("galoissubcyclo",N);
     585           0 :       return NULL;/*Not reached*/
     586             :   }
     587         182 :   if (n==1) { avma = ltop; return deg1pol_shallow(gen_1,gen_m1,v); }
     588             : 
     589         182 :   switch(typ(sg))
     590             :   {
     591             :      case t_INTMOD: case t_INT:
     592          98 :       V = mkvecsmall( lift_check_modulus(sg,n) );
     593          91 :       break;
     594             :     case t_VECSMALL:
     595           0 :       V = gcopy(sg);
     596           0 :       for (i=1; i<lg(V); i++) { V[i] %= n; if (V[i] < 0) V[i] += n; }
     597           0 :       break;
     598             :     case t_VEC:
     599             :     case t_COL:
     600           0 :       V = cgetg(lg(sg),t_VECSMALL);
     601           0 :       for(i=1;i<lg(sg);i++) V[i] = lift_check_modulus(gel(sg,i),n);
     602           0 :       break;
     603             :     case t_MAT:
     604          84 :       if (lg(sg) == 1 || lg(sg) != lgcols(sg))
     605           7 :         pari_err_TYPE("galoissubcyclo [H not in HNF]", sg);
     606          77 :       if (!Z) pari_err_TYPE("galoissubcyclo [N not a bnrinit or znstar]", sg);
     607          70 :       if ( lg(gel(Z,2)) != lg(sg) ) pari_err_DIM("galoissubcyclo");
     608          63 :       V = znstar_hnf_generators(znstar_small(Z),sg);
     609          63 :       break;
     610             :     default:
     611           0 :       pari_err_TYPE("galoissubcyclo",sg);
     612           0 :       return NULL;/*Not reached*/
     613             :   }
     614         154 :   if (!complex) V = vecsmall_append(V,n-1); /*add complex conjugation*/
     615         154 :   H = znstar_generate(n,V);
     616         154 :   if (DEBUGLEVEL >= 6)
     617             :   {
     618           0 :     err_printf("Subcyclo: elements:");
     619           0 :     for (i=1;i<n;i++)
     620           0 :       if (F2v_coeff(gel(H,3),i)) err_printf(" %ld",i);
     621           0 :     err_printf("\n");
     622             :   }
     623             :   /* field is real iff z -> conj(z) = z^-1 = z^(n-1) is in H */
     624         154 :   complex = !F2v_coeff(gel(H,3),n-1);
     625         154 :   if (DEBUGLEVEL >= 6) err_printf("Subcyclo: complex=%ld\n",complex);
     626         154 :   if (DEBUGLEVEL >= 1) timer_start(&ti);
     627         154 :   cnd = znstar_conductor(n,H);
     628         154 :   if (DEBUGLEVEL >= 1) timer_printf(&ti, "znstar_conductor");
     629         154 :   if (flag == 1)  { avma=ltop; return stoi(cnd); }
     630         154 :   if (cnd == 1)
     631             :   {
     632          28 :     avma = ltop;
     633          28 :     return gscycloconductor(deg1pol_shallow(gen_1,gen_m1,v),1,flag);
     634             :   }
     635         126 :   if (n != cnd)
     636             :   {
     637          35 :     H = znstar_reduce_modulus(H, cnd);
     638          35 :     n = cnd;
     639             :   }
     640         126 :   card = znstar_order(H);
     641         126 :   phi_n = eulerphiu(n);
     642         126 :   if (card == phi_n)
     643             :   {
     644           0 :     avma = ltop;
     645           0 :     return gscycloconductor(polcyclo(n,v),n,flag);
     646             :   }
     647         126 :   O = znstar_cosets(n, phi_n, H);
     648         126 :   if (DEBUGLEVEL >= 1) timer_printf(&ti, "znstar_cosets");
     649         126 :   if (DEBUGLEVEL >= 6) err_printf("Subcyclo: orbits=%Ps\n",O);
     650         126 :   if (DEBUGLEVEL >= 4)
     651           0 :     err_printf("Subcyclo: %ld orbits with %ld elements each\n",phi_n/card,card);
     652         126 :   av = avma;
     653         126 :   powz = polsubcyclo_complex_roots(n,!complex,LOWDEFAULTPREC);
     654         126 :   L = polsubcyclo_orbits(n,H,O,powz,NULL);
     655         126 :   B = polsubcyclo_complex_bound(av,L,LOWDEFAULTPREC);
     656         126 :   zl = polsubcyclo_start(n,phi_n/card,card,B,&val,&l);
     657         126 :   powz = polsubcyclo_roots(n,zl);
     658         126 :   le = gel(zl,1);
     659         126 :   L = polsubcyclo_orbits(n,H,O,powz,le);
     660         126 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     661         126 :   T = FpV_roots_to_pol(L,le,v);
     662         126 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "roots_to_pol");
     663         126 :   T = FpX_center(T,le,shifti(le,-1));
     664         126 :   return gerepileupto(ltop, gscycloconductor(T,n,flag));
     665             : }
     666             : 
     667             : /* Z = znstar(n) cyclic. n = 1,2,4,p^a or 2p^a,
     668             :  * and d | phi(n) = 1,1,2,(p-1)p^(a-1) */
     669             : static GEN
     670        3017 : polsubcyclo_g(long n, long d, GEN Z, long v)
     671             : {
     672        3017 :   pari_sp ltop = avma;
     673             :   long o, p, r, g, gd, l , val;
     674             :   GEN zl, L, T, le, B, powz;
     675             :   pari_timer ti;
     676        3017 :   if (d==1) return deg1pol_shallow(gen_1,gen_m1,v); /* get rid of n=1,2 */
     677        3017 :   if ((n & 3) == 2) n >>= 1;
     678             :   /* n = 4 or p^a, p odd */
     679        3017 :   o = itos(gel(Z,1));
     680        3017 :   g = itos(gmael3(Z,3,1,2));
     681        3017 :   p = n / ugcd(n,o); /* p^a / gcd(p^a,phi(p^a)) = p*/
     682        3017 :   r = ugcd(d,n); /* = p^(v_p(d)) < n */
     683        3017 :   n = r*p; /* n is now the conductor */
     684        3017 :   o = n-r; /* = phi(n) */
     685        3017 :   if (o == d) return polcyclo(n,v);
     686        2954 :   o /= d;
     687        2954 :   gd = Fl_powu(g%n, d, n);
     688             :   /*FIXME: If degree is small, the computation of B is a waste of time*/
     689        2954 :   powz = polsubcyclo_complex_roots(n,(o&1)==0,LOWDEFAULTPREC);
     690        2954 :   L = polsubcyclo_cyclic(n,d,o,g,gd,powz,NULL);
     691        2954 :   B = polsubcyclo_complex_bound(ltop,L,LOWDEFAULTPREC);
     692        2954 :   zl = polsubcyclo_start(n,d,o,B,&val,&l);
     693        2954 :   le = gel(zl,1);
     694        2954 :   powz = polsubcyclo_roots(n,zl);
     695        2954 :   L = polsubcyclo_cyclic(n,d,o,g,gd,powz,le);
     696        2954 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     697        2954 :   T = FpV_roots_to_pol(L,le,v);
     698        2954 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "roots_to_pol");
     699        2954 :   return gerepileupto(ltop, FpX_center(T,le,shifti(le,-1)));
     700             : }
     701             : 
     702             : GEN
     703        3045 : polsubcyclo(long n, long d, long v)
     704             : {
     705        3045 :   pari_sp ltop = avma;
     706             :   GEN L, Z;
     707        3045 :   if (v<0) v = 0;
     708        3045 :   if (d<=0) pari_err_DOMAIN("polsubcyclo","d","<=",gen_0,stoi(d));
     709        3038 :   if (n<=0) pari_err_DOMAIN("polsubcyclo","n","<=",gen_0,stoi(n));
     710        3031 :   Z = znstar(stoi(n));
     711        3031 :   if (!dvdis(gel(Z,1), d)) { avma = ltop; return cgetg(1, t_VEC); }
     712        3031 :   if (lg(gel(Z,2)) == 2)
     713             :   { /* faster but Z must be cyclic */
     714        3017 :     avma = ltop;
     715        3017 :     return polsubcyclo_g(n, d, Z, v);
     716             :   }
     717          14 :   L = subgrouplist(gel(Z,2), mkvec(stoi(d)));
     718          14 :   if (lg(L) == 2)
     719           7 :     return gerepileupto(ltop, galoissubcyclo(Z, gel(L,1), 0, v));
     720             :   else
     721             :   {
     722           7 :     GEN V = cgetg(lg(L),t_VEC);
     723             :     long i;
     724           7 :     for (i=1; i< lg(V); i++) gel(V,i) = galoissubcyclo(Z, gel(L,i), 0, v);
     725           7 :     return gerepileupto(ltop, V);
     726             :   }
     727             : }
     728             : 
     729             : struct aurifeuille_t {
     730             :   GEN z, le;
     731             :   ulong l;
     732             :   long e;
     733             : };
     734             : 
     735             : /* Let z a primitive n-th root of 1, n > 1, A an integer such that
     736             :  * Aurifeuillian factorization of Phi_n(A) exists ( z.A is a square in Q(z) ).
     737             :  * Let G(p) the Gauss sum mod p prime:
     738             :  *      sum_x (x|p) z^(xn/p) for p odd,  i - 1 for p = 2 [ i := z^(n/4) ]
     739             :  * We have N(-1) = Nz = 1 (n != 1,2), and
     740             :  *      G^2 = (-1|p) p for p odd,  G^2 = -2i for p = 2
     741             :  * In particular, for odd A, (-1|A) A = g^2 is a square. If A = prod p^{e_p},
     742             :  * sigma_j(g) = \prod_p (sigma_j G(p)))^e_p = \prod_p (j|p)^e_p g = (j|A) g
     743             :  * n odd  : z^2 is a primitive root, A = g^2
     744             :  *   Phi_n(A) = N(A - z^2) = N(g - z) N(g + z)
     745             :  *
     746             :  * n = 2 (4) : -z^2 is a primitive root, -A = g^2
     747             :  *   Phi_n(A) = N(A - (-z^2)) = N(g^2 - z^2)  [ N(-1) = 1 ]
     748             :  *                            = N(g - z) N(g + z)
     749             :  *
     750             :  * n = 4 (8) : i z^2 primitive root, -Ai = g^2
     751             :  *   Phi_n(A) = N(A - i z^2) = N(-Ai -  z^2) = N(g - z) N(g + z)
     752             :  * sigma_j(g) / g =  (j|A)  if j = 1 (4)
     753             :  *                  (-j|A)i if j = 3 (4)
     754             :  *   */
     755             : /* factor Phi_n(A), Astar: A* = squarefree kernel of A, P = odd prime divisors
     756             :  * of n */
     757             : static GEN
     758        5278 : factor_Aurifeuille_aux(GEN A, long Astar, long n, GEN P,
     759             :                        struct aurifeuille_t *S)
     760             : {
     761             :   pari_sp av;
     762        5278 :   GEN f, a, b, s, powers, z = S->z, le = S->le;
     763        5278 :   long j, k, maxjump, lastj, e = S->e;
     764        5278 :   ulong l = S->l;
     765             :   char *invertible;
     766             : 
     767        5278 :   if ((n & 7) == 4)
     768             :   { /* A^* even */
     769        5215 :     GEN i = Fp_powu(z, n>>2, le), z2 = Fp_sqr(z, le);
     770             : 
     771        5215 :     invertible = stack_malloc(n); /* even indices unused */
     772        5215 :     for (j = 1; j < n; j+=2) invertible[j] = 1;
     773        5271 :     for (k = 1; k < lg(P); k++)
     774             :     {
     775          56 :       long p = P[k];
     776          56 :       for (j = p; j < n; j += 2*p) invertible[j] = 0;
     777             :     }
     778        5215 :     lastj = 1; maxjump = 2;
     779       10990 :     for (j= 3; j < n; j+=2)
     780        5775 :       if (invertible[j]) {
     781        5663 :         long jump = j - lastj;
     782        5663 :         if (jump > maxjump) maxjump = jump;
     783        5663 :         lastj = j;
     784             :       }
     785        5215 :     powers = cgetg(maxjump+1, t_VEC); /* powers[k] = z^k, odd indices unused */
     786        5215 :     gel(powers,2) = z2;
     787        5271 :     for (k = 4; k <= maxjump; k+=2)
     788         112 :       gel(powers,k) = odd(k>>1)? Fp_mul(gel(powers, k-2), z2, le)
     789          56 :                                : Fp_sqr(gel(powers, k>>1), le);
     790             : 
     791        5215 :     if (Astar == 2)
     792             :     { /* important special case (includes A=2), split for efficiency */
     793        5194 :       if (!equalis(A, 2))
     794             :       {
     795          14 :         GEN f = sqrti(shifti(A,-1)), mf = Fp_neg(f,le), fi = Fp_mul(f,i,le);
     796          14 :         a = Fp_add(mf, fi, le);
     797          14 :         b = Fp_sub(mf, fi, le);
     798             :       }
     799             :       else
     800             :       {
     801        5180 :         a = addsi(-1,i);
     802        5180 :         b = subsi(-1,i);
     803             :       }
     804        5194 :       av = avma;
     805        5194 :       s = z; f = subii(a, s); lastj = 1;
     806       10640 :       for (j = 3, k = 0; j < n; j+=2)
     807        5446 :         if (invertible[j])
     808             :         {
     809        5376 :           s = Fp_mul(gel(powers, j-lastj), s, le); /* z^j */
     810        5376 :           lastj = j;
     811        5376 :           f = Fp_mul(f, subii((j & 3) == 1? a: b, s), le);
     812        5376 :           if (++k == 0x1ff) { gerepileall(av, 2, &s, &f); k = 0; }
     813             :         }
     814             :     }
     815             :     else
     816             :     {
     817          21 :       GEN ma, mb, B = Fp_mul(A, i, le), gl = utoipos(l);
     818             :       long t;
     819          21 :       Astar >>= 1;
     820          21 :       t = Astar & 3; if (Astar < 0) t = 4-t; /* t = 1 or 3 */
     821          21 :       if (t == 1) B = Fp_neg(B, le);
     822          21 :       a = Zp_sqrtlift(B, Fp_sqrt(B, gl), gl, e);
     823          21 :       b = Fp_mul(a, i, le);
     824          21 :       ma = Fp_neg(a, le);
     825          21 :       mb = Fp_neg(b, le);
     826          21 :       av = avma;
     827          21 :       s = z; f = subii(a, s); lastj = 1;
     828         350 :       for (j = 3, k = 0; j<n; j+=2)
     829         329 :         if (invertible[j])
     830             :         {
     831             :           GEN t;
     832         287 :           if ((j & 3) == 1) t = (kross(j, Astar) < 0)? ma: a;
     833         154 :           else              t = (kross(j, Astar) < 0)? mb: b;
     834         287 :           s = Fp_mul(gel(powers, j-lastj), s, le); /* z^j */
     835         287 :           lastj = j;
     836         287 :           f = Fp_mul(f, subii(t, s), le);
     837         287 :           if (++k == 0x1ff) { gerepileall(av, 2, &s, &f); k = 0; }
     838             :         }
     839             :     }
     840             :   }
     841             :   else /* A^* odd */
     842             :   {
     843             :     ulong g;
     844          63 :     if ((n & 3) == 2)
     845             :     { /* A^* = 3 (mod 4) */
     846           0 :       A = negi(A); Astar = -Astar;
     847           0 :       z = Fp_neg(z, le);
     848           0 :       n >>= 1;
     849             :     }
     850             :     /* A^* = 1 (mod 4) */
     851          63 :     g = Fl_sqrt(umodiu(A,l), l);
     852          63 :     a = Zp_sqrtlift(A, utoipos(g), utoipos(l), e);
     853          63 :     b = negi(a);
     854             : 
     855          63 :     invertible = stack_malloc(n);
     856          63 :     for (j = 1; j < n; j++) invertible[j] = 1;
     857         168 :     for (k = 1; k < lg(P); k++)
     858             :     {
     859         105 :       long p = P[k];
     860         105 :       for (j = p; j < n; j += p) invertible[j] = 0;
     861             :     }
     862          63 :     lastj = 2; maxjump = 1;
     863        1141 :     for (j= 3; j < n; j++)
     864        1078 :       if (invertible[j]) {
     865         714 :         long jump = j - lastj;
     866         714 :         if (jump > maxjump) maxjump = jump;
     867         714 :         lastj = j;
     868             :       }
     869          63 :     powers = cgetg(maxjump+1, t_VEC); /* powers[k] = z^k */
     870          63 :     gel(powers,1) = z;
     871         147 :     for (k = 2; k <= maxjump; k++)
     872         210 :       gel(powers,k) = odd(k)? Fp_mul(gel(powers, k-1), z, le)
     873         126 :                             : Fp_sqr(gel(powers, k>>1), le);
     874          63 :     av = avma;
     875          63 :     s = z; f = subii(a, s); lastj = 1;
     876        1204 :     for(j = 2, k = 0; j < n; j++)
     877        1141 :       if (invertible[j])
     878             :       {
     879         777 :         s = Fp_mul(gel(powers, j-lastj), s, le);
     880         777 :         lastj = j;
     881         777 :         f = Fp_mul(f, subii(kross(j,Astar)==1? a: b, s), le);
     882         777 :         if (++k == 0x1ff) { gerepileall(av, 2, &s, &f); k = 0; }
     883             :       }
     884             :   }
     885        5278 :   return f;
     886             : }
     887             : 
     888             : /* fd = factoru(odd part of d = d or d/4). Return eulerphi(d) */
     889             : static ulong
     890        5278 : phi(long d, GEN fd)
     891             : {
     892        5278 :   GEN P = gel(fd,1), E = gel(fd,2);
     893        5278 :   long i, l = lg(P);
     894        5278 :   ulong phi = 1;
     895        5439 :   for (i = 1; i < l; i++)
     896             :   {
     897         161 :     ulong p = P[i], e = E[i];
     898         161 :     phi *= upowuu(p, e-1)*(p-1);
     899             :   }
     900        5278 :   if (!odd(d)) phi <<= 1;
     901        5278 :   return phi;
     902             : }
     903             : 
     904             : static void
     905        5278 : Aurifeuille_init(GEN a, long d, GEN fd, struct aurifeuille_t *S)
     906             : {
     907        5278 :   GEN sqrta = sqrtr_abs(itor(a, LOWDEFAULTPREC));
     908        5278 :   GEN bound = ceil_safe(powru(addrs(sqrta,1), phi(d, fd)));
     909        5278 :   GEN zl = polsubcyclo_start(d, 0, 0, bound, &(S->e), (long*)&(S->l));
     910        5278 :   S->le = gel(zl,1);
     911        5278 :   S->z  = gel(zl,2);
     912        5278 : }
     913             : 
     914             : GEN
     915        5215 : factor_Aurifeuille_prime(GEN p, long d)
     916             : {
     917        5215 :   pari_sp av = avma;
     918             :   struct aurifeuille_t S;
     919             :   GEN fd;
     920             :   long pp;
     921        5215 :   if ((d & 3) == 2) { d >>= 1; p = negi(p); }
     922        5215 :   fd = factoru(odd(d)? d: d>>2);
     923        5215 :   pp = itos(p);
     924        5215 :   Aurifeuille_init(p, d, fd, &S);
     925        5215 :   return gerepileuptoint(av, factor_Aurifeuille_aux(p, pp, d, gel(fd,1), &S));
     926             : }
     927             : 
     928             : /* an algebraic factor of Phi_d(a), a != 0 */
     929             : GEN
     930          63 : factor_Aurifeuille(GEN a, long d)
     931             : {
     932          63 :   pari_sp av = avma;
     933             :   GEN fd, P, A;
     934          63 :   long i, lP, va = vali(a), sa, astar, D;
     935             :   struct aurifeuille_t S;
     936             : 
     937          63 :   if (d <= 0)
     938           0 :     pari_err_DOMAIN("factor_Aurifeuille", "degre", "<=",gen_0,stoi(d));
     939          63 :   if ((d & 3) == 2) { d >>= 1; a = negi(a); }
     940          63 :   if ((va & 1) == (d & 1)) { avma = av; return gen_1; }
     941          63 :   sa = signe(a);
     942          63 :   if (odd(d))
     943             :   {
     944             :     long a4;
     945          28 :     if (d == 1)
     946             :     {
     947           0 :       if (!Z_issquareall(a, &A)) return gen_1;
     948           0 :       return gerepileuptoint(av, addis(A,1));
     949             :     }
     950          28 :     A = va? shifti(a, -va): a;
     951          28 :     a4 = mod4(A); if (sa < 0) a4 = 4 - a4;
     952          28 :     if (a4 != 1) { avma = av; return gen_1; }
     953             :   }
     954          35 :   else if ((d & 7) == 4)
     955          35 :     A = shifti(a, -va);
     956             :   else
     957             :   {
     958           0 :     avma = av; return gen_1;
     959             :   }
     960             :   /* v_2(d) = 0 or 2. Kill 2 from factorization (minor efficiency gain) */
     961          63 :   fd = factoru(odd(d)? d: d>>2); P = gel(fd,1); lP = lg(P);
     962          63 :   astar = sa;
     963          63 :   if (odd(va)) astar <<= 1;
     964         147 :   for (i = 1; i < lP; i++)
     965          84 :     if (odd( (Z_lvalrem(A, P[i], &A)) ) ) astar *= P[i];
     966          63 :   if (sa < 0)
     967             :   { /* negate in place if possible */
     968          14 :     if (A == a) A = icopy(A);
     969          14 :     setabssign(A);
     970             :   }
     971          63 :   if (!Z_issquare(A)) { avma = av; return gen_1; }
     972             : 
     973          63 :   D = odd(d)? 1: 4;
     974          63 :   for (i = 1; i < lP; i++) D *= P[i];
     975          63 :   if (D != d) { a = powiu(a, d/D); d = D; }
     976             : 
     977          63 :   Aurifeuille_init(a, d, fd, &S);
     978          63 :   return gerepileuptoint(av, factor_Aurifeuille_aux(a, astar, d, P, &S));
     979             : }

Generated by: LCOV version 1.11