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 20277-2bd9113) Lines: 525 553 94.9 %
Date: 2017-02-21 05:49:51 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        5313 : 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       10626 :   if (!d) { (*func)(data,c); return; }
      37             : 
      38        3024 :   cache = const_vecsmall(d,c);
      39        3024 :   (*func)(data,c);  /* AFTER cache: may contain gerepileupto statement */
      40        3024 :   gen = gel(H,1);
      41        3024 :   ord = gel(H,2);
      42        3024 :   card = ord[1]; for (i = 2; i <= d; i++) card *= ord[i];
      43       68537 :   for(i=1; i<card; i++)
      44             :   {
      45       65513 :     long k, m = i;
      46       65513 :     for(j=1; j<d && m%ord[j]==0 ;j++) m /= ord[j];
      47       65513 :     cache[j] = Fl_mul(cache[j],gen[j],n);
      48       65513 :     for (k=1; k<j; k++) cache[k] = cache[j];
      49       65513 :     (*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        4081 : znstar_partial_coset_bits_inplace(long n, GEN H, GEN bits, long d, long c)
      65             : {
      66        4081 :   pari_sp av = avma;
      67        4081 :   znstar_partial_coset_func(n,H, (void (*)(void *,long)) &F2v_set,
      68             :       (void *) bits, d, c);
      69        4081 :   avma = av;
      70        4081 : }
      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        3465 : znstar_partial_coset_bits(long n, GEN H, long d, long c)
      80             : {
      81        3465 :   GEN bits = zero_F2v(n);
      82        3465 :   znstar_partial_coset_bits_inplace(n,H,bits,d,c);
      83        3465 :   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        3465 : znstar_partial_bits(long n, GEN H, long d)
      90             : {
      91        3465 :   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        2079 : znstar_generate(long n, GEN V)
     105             : {
     106        2079 :   pari_sp av = avma;
     107        2079 :   GEN gen = cgetg(lg(V),t_VECSMALL);
     108        2079 :   GEN ord = cgetg(lg(V),t_VECSMALL), res = mkvec2(gen,ord);
     109        2079 :   GEN bits = znstar_partial_bits(n,NULL,0);
     110        2079 :   long i, r = 0;
     111        4949 :   for(i=1; i<lg(V); i++)
     112             :   {
     113        2870 :     ulong v = uel(V,i), g = v;
     114        2870 :     long o = 0;
     115        2870 :     while (!F2v_coeff(bits, (long)g)) { g = Fl_mul(g, v, (ulong)n); o++; }
     116        2870 :     if (!o) continue;
     117        1386 :     r++;
     118        1386 :     gen[r] = v;
     119        1386 :     ord[r] = o+1;
     120        1386 :     cgiv(bits); bits = znstar_partial_bits(n,res,r);
     121             :   }
     122        2079 :   setlg(gen,r+1);
     123        2079 :   setlg(ord,r+1); return gerepilecopy(av, mkvec3(gen,ord,bits));
     124             : }
     125             : 
     126             : static ulong
     127        2142 : 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        1890 : znstar_elts(long n, GEN H)
     133             : {
     134        1890 :   long card = znstar_order(H);
     135        1890 :   GEN gen = gel(H,1), ord = gel(H,2);
     136        1890 :   GEN sg = cgetg(1 + card, t_VECSMALL);
     137             :   long k, j, l;
     138        1890 :   sg[1] = 1;
     139        3045 :   for (j = 1, l = 1; j < lg(gen); j++)
     140             :   {
     141        1155 :     long c = l * (ord[j]-1);
     142        1155 :     for (k = 1; k <= c; k++) sg[++l] = Fl_mul(sg[k], gen[j], n);
     143             :   }
     144        1890 :   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         868 : vecmod_to_vecsmall(GEN z)
     224             : {
     225         868 :   long i, l = lg(z);
     226         868 :   GEN x = cgetg(l, t_VECSMALL);
     227        2002 :   for (i=1; i<l; i++) {
     228        1134 :     GEN c = gel(z,i);
     229        1134 :     if (typ(c) == t_INTMOD) c = gel(c,2);
     230        1134 :     x[i] = itos(c);
     231             :   }
     232         868 :   return x;
     233             : }
     234             : /* Convert a true znstar output by znstar to a `small znstar' */
     235             : GEN
     236         868 : znstar_small(GEN zn)
     237             : {
     238         868 :   GEN Z = cgetg(4,t_VEC);
     239         868 :   gel(Z,1) = icopy(gmael3(zn,3,1,1));
     240         868 :   gel(Z,2) = vec_to_vecsmall(gel(zn,2));
     241         868 :   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        1953 : znstar_hnf_generators(GEN Z, GEN M)
     247             : {
     248        1953 :   long j, h, l = lg(M);
     249        1953 :   GEN gen = cgetg(l, t_VECSMALL);
     250        1953 :   pari_sp ltop = avma;
     251        1953 :   GEN zgen = gel(Z,3);
     252        1953 :   ulong n = itou(gel(Z,1));
     253        4648 :   for (j = 1; j < l; j++)
     254             :   {
     255        2695 :     GEN Mj = gel(M,j);
     256        2695 :     gen[j] = 1;
     257        7014 :     for (h = 1; h < l; h++)
     258             :     {
     259        4319 :       ulong u = itou(gel(Mj,h));
     260        4319 :       if (!u) continue;
     261        2891 :       gen[j] = Fl_mul(uel(gen,j), Fl_powu(uel(zgen,h), u, n), n);
     262             :     }
     263             :   }
     264        1953 :   avma = ltop; return gen;
     265             : }
     266             : 
     267             : GEN
     268        1890 : znstar_hnf(GEN Z, GEN M)
     269             : {
     270        1890 :   return znstar_generate(itos(gel(Z,1)),znstar_hnf_generators(Z,M));
     271             : }
     272             : 
     273             : GEN
     274        1890 : znstar_hnf_elts(GEN Z, GEN H)
     275             : {
     276        1890 :   pari_sp ltop = avma;
     277        1890 :   GEN G = znstar_hnf(Z,H);
     278        1890 :   long n = itos(gel(Z,1));
     279        1890 :   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             :   return 0;/*LCOV_EXCL_LINE*/
     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      219268 : polsubcyclo_powz(GEN powz, long ex)
     319             : {
     320      219268 :   long m = lg(gel(powz,1))-1, q = ex/m, r = ex%m; /*ex=m*q+r*/
     321      219268 :   GEN g = gmael(powz,1,r+1), G = gmael(powz,2,q+1);
     322      219268 :   return (lg(powz)==4)? mulreal(g,G): gmul(g,G);
     323             : }
     324             : 
     325             : static GEN
     326        3115 : polsubcyclo_complex_bound(pari_sp av, GEN V, long prec)
     327             : {
     328        3115 :   GEN pol = real_i(roots_to_pol(V,0));
     329        3115 :   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        5978 : polsubcyclo_cyclic(long n, long d, long m ,long z, long g, GEN powz, GEN le)
     335             : {
     336        5978 :   GEN V = cgetg(d+1,t_VEC);
     337        5978 :   ulong base = 1;
     338             :   long i,k;
     339             :   pari_timer ti;
     340        5978 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     341       52948 :   for (i=1; i<=d; i++, base = Fl_mul(base,z,n))
     342             :   {
     343       46970 :     pari_sp av = avma;
     344       46970 :     long ex = base;
     345       46970 :     GEN s = gen_0;
     346      237594 :     for (k=0; k<m; k++, ex = Fl_mul(ex,g,n))
     347             :     {
     348      190624 :       s = gadd(s, polsubcyclo_powz(powz,ex));
     349      190624 :       if ((k&0xff)==0) s = gerepileupto(av,s);
     350             :     }
     351       46970 :     if (le) s = modii(s, le);
     352       46970 :     gel(V,i) = gerepileupto(av, s);
     353             :   }
     354        5978 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "polsubcyclo_cyclic");
     355        5978 :   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        8561 : polsubcyclo_start(long n, long d, long o, long e, GEN borne, long *ptr_val,long *ptr_l)
     404             : {
     405             :   pari_sp av;
     406             :   GEN le, z, gl;
     407             :   long i, l, val;
     408        8561 :   l = e*n+1;
     409        8561 :   while(!uisprime(l)) { l += n; e++; }
     410        8561 :   if (DEBUGLEVEL >= 4) err_printf("Subcyclo: prime l=%ld\n",l);
     411        8561 :   gl = utoipos(l); av = avma;
     412        8561 :   if (!borne)
     413             :   { /* Use vecmax(Vec((x+o)^d)) = max{binomial(d,i)*o^i ;1<=i<=d} */
     414           0 :     i = d-(1+d)/(1+o);
     415           0 :     borne = mulii(binomial(utoipos(d),i),powuu(o,i));
     416             :   }
     417        8561 :   if (DEBUGLEVEL >= 4) err_printf("Subcyclo: bound=2^%ld\n",expi(borne));
     418        8561 :   val = logint(shifti(borne,2), gl) + 1;
     419        8561 :   avma = av;
     420        8561 :   if (DEBUGLEVEL >= 4) err_printf("Subcyclo: val=%ld\n",val);
     421        8561 :   le = powiu(gl,val);
     422        8561 :   z = utoipos( Fl_powu(pgener_Fl(l), e, l) );
     423        8561 :   z = Zp_sqrtnlift(gen_1,utoipos(n),z,gl,val);
     424        8561 :   *ptr_val = val;
     425        8561 :   *ptr_l = l;
     426        8561 :   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        3115 : polsubcyclo_complex_roots(long n, long real, long prec)
     435             : {
     436        3115 :   long i, m = (long)(1+sqrt((double) n));
     437        3115 :   GEN bab, gig, powz = cgetg(real?4:3, t_VEC);
     438             : 
     439        3115 :   bab = cgetg(m+1,t_VEC);
     440        3115 :   gel(bab,1) = gen_1;
     441        3115 :   gel(bab,2) = rootsof1u_cx(n, prec); /* = e_n(1) */
     442        3115 :   for (i=3; i<=m; i++) gel(bab,i) = gmul(gel(bab,2),gel(bab,i-1));
     443        3115 :   gig = cgetg(m+1,t_VEC);
     444        3115 :   gel(gig,1) = gen_1;
     445        3115 :   gel(gig,2) = gmul(gel(bab,2),gel(bab,m));;
     446        3115 :   for (i=3; i<=m; i++) gel(gig,i) = gmul(gel(gig,2),gel(gig,i-1));
     447        3115 :   gel(powz,1) = bab;
     448        3115 :   gel(powz,2) = gig;
     449        3115 :   if (real) gel(powz,3) = gen_0;
     450        3115 :   return powz;
     451             : }
     452             : 
     453             : static GEN
     454       23009 : muliimod_sz(GEN x, GEN y, GEN l, long siz)
     455             : {
     456       23009 :   pari_sp av = avma;
     457             :   GEN p1;
     458       23009 :   (void)new_chunk(siz); /* HACK */
     459       23009 :   p1 = mulii(x,y);
     460       23009 :   avma = av; return modii(p1,l);
     461             : }
     462             : 
     463             : static GEN
     464        3115 : polsubcyclo_roots(long n, GEN zl)
     465             : {
     466        3115 :   GEN le = gel(zl,1), z = gel(zl,2);
     467        3115 :   long i, lle = lg(le)*3; /*Assume dvmdii use lx+ly space*/
     468        3115 :   long m = (long)(1+sqrt((double) n));
     469        3115 :   GEN bab, gig, powz = cgetg(3,t_VEC);
     470             :   pari_timer ti;
     471        3115 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     472        3115 :   bab = cgetg(m+1,t_VEC);
     473        3115 :   gel(bab,1) = gen_1;
     474        3115 :   gel(bab,2) = icopy(z);
     475        3115 :   for (i=3; i<=m; i++) gel(bab,i) = muliimod_sz(z,gel(bab,i-1),le,lle);
     476        3115 :   gig = cgetg(m+1,t_VEC);
     477        3115 :   gel(gig,1) = gen_1;
     478        3115 :   gel(gig,2) = muliimod_sz(z,gel(bab,m),le,lle);;
     479        3115 :   for (i=3; i<=m; i++) gel(gig,i) = muliimod_sz(gel(gig,2),gel(gig,i-1),le,lle);
     480        3115 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "polsubcyclo_roots");
     481        3115 :   gel(powz,1) = bab;
     482        3115 :   gel(powz,2) = gig; return powz;
     483             : }
     484             : 
     485             : GEN
     486         168 : galoiscyclo(long n, long v)
     487             : {
     488         168 :   ulong av = avma;
     489             :   GEN grp, G, z, le, L, elts;
     490             :   long val, l, i, j, k;
     491         168 :   GEN zn = znstar(stoi(n));
     492         168 :   long card = itos(gel(zn,1));
     493         168 :   GEN gen = vec_to_vecsmall(lift_shallow(gel(zn,3)));
     494         168 :   GEN ord = gtovecsmall(gel(zn,2));
     495         168 :   GEN T = polcyclo(n,v);
     496         168 :   const long step = 3;
     497         168 :   GEN borneabs = powuu((2*step)*step,n);
     498         168 :   z = polsubcyclo_start(n,card/2,2,2*usqrt(n),borneabs,&val,&l);
     499         168 :   le = gel(z,1); z = gel(z,2);
     500         168 :   L = cgetg(1+card,t_VEC);
     501         168 :   gel(L,1) = z;
     502         378 :   for (j = 1, i = 1; j < lg(gen); j++)
     503             :   {
     504         210 :     long c = i * (ord[j]-1);
     505         210 :     for (k = 1; k <= c; k++) gel(L,++i) = Fp_powu(gel(L,k), gen[j], le);
     506             :   }
     507         168 :   G = abelian_group(ord);
     508         168 :   elts = group_elts(G, card); /*not stack clean*/
     509         168 :   grp = cgetg(9, t_VEC);
     510         168 :   gel(grp,1) = T;
     511         168 :   gel(grp,2) = mkvec3(stoi(l), stoi(val), icopy(le));
     512         168 :   gel(grp,3) = L;
     513         168 :   gel(grp,4) = FpV_invVandermonde(L,  NULL, le);
     514         167 :   gel(grp,5) = gen_1;
     515         167 :   gel(grp,6) = elts;
     516         167 :   gel(grp,7) = gel(G,1);
     517         167 :   gel(grp,8) = gel(G,2);
     518         167 :   return gerepilecopy(av, grp);
     519             : }
     520             : 
     521             : /* Convert a bnrinit(Q,n) to a znstar(n)
     522             :  * complex is set to 0 if the bnr is real and to 1 if it is complex.
     523             :  * Not stack clean */
     524             : GEN
     525          14 : bnr_to_znstar(GEN bnr, long *complex)
     526             : {
     527             :   GEN gen, F, v, bid;
     528             :   long l, i;
     529          14 :   checkbnr(bnr);
     530          14 :   bid = bnr_get_bid(bnr);
     531          14 :   gen = bid_get_gen(bid);
     532          14 :   F = bid_get_ideal(bid);
     533          14 :   if (lg(F) != 2)
     534           7 :     pari_err_DOMAIN("bnr_to_znstar", "bnr", "!=", strtoGENstr("Q"), bnr);
     535             :   /* F is the finite part of the conductor, complex is the infinite part*/
     536           7 :   F = gcoeff(F, 1, 1);
     537           7 :   *complex = signe(gel(bid_get_arch(bid), 1));
     538           7 :   l = lg(gen); v = cgetg(l, t_VEC);
     539          42 :   for (i = 1; i < l; ++i)
     540             :   {
     541          35 :     GEN x = gel(gen,i);
     542          35 :     if (typ(x) == t_COL) x = gel(x,1);
     543          35 :     gel(v,i) = gmodulo(absi(x), F);
     544             :   }
     545           7 :   return mkvec3(bnr_get_no(bnr), bnr_get_cyc(bnr), v);
     546             : }
     547             : 
     548             : GEN
     549         203 : galoissubcyclo(GEN N, GEN sg, long flag, long v)
     550             : {
     551         203 :   pari_sp ltop= avma, av;
     552         203 :   GEN H, V, B, zl, L, T, le, powz, O, Z = NULL;
     553         203 :   long i, card, phi_n, val,l, n, cnd, complex=1;
     554             :   pari_timer ti;
     555             : 
     556         203 :   if (flag<0 || flag>2) pari_err_FLAG("galoissubcyclo");
     557         203 :   if (v < 0) v = 0;
     558         203 :   if (!sg) sg = gen_1;
     559         203 :   switch(typ(N))
     560             :   {
     561             :     case t_INT:
     562         119 :       n = itos(N);
     563         119 :       if (n < 1)
     564           7 :         pari_err_DOMAIN("galoissubcyclo", "degree", "<=", gen_0, stoi(n));
     565         112 :       break;
     566             :     case t_VEC:
     567          84 :       if (lg(N)==7) N = bnr_to_znstar(N,&complex);
     568          77 :       if (lg(N)==4)
     569             :       { /* znstar */
     570          77 :         GEN gen = abgrp_get_gen(N);
     571          77 :         Z = N;
     572          77 :         if (typ(gen)!=t_VEC) pari_err_TYPE("galoissubcyclo",gen);
     573          77 :         if (lg(gen) == 1) n = 1;
     574          77 :         else if (typ(gel(gen,1)) == t_INTMOD)
     575             :         {
     576          70 :           GEN z = gel(gen,1);
     577          70 :           n = itos(gel(z,1));
     578             :         } else
     579             :         {
     580           7 :           pari_err_TYPE("galoissubcyclo",N);
     581             :           return NULL;/*LCOV_EXCL_LINE*/
     582             :         }
     583          70 :         break;
     584             :       }
     585             :     default: /*fall through*/
     586           0 :       pari_err_TYPE("galoissubcyclo",N);
     587             :       return NULL;/*LCOV_EXCL_LINE*/
     588             :   }
     589         182 :   if (n==1) { avma = ltop; return deg1pol_shallow(gen_1,gen_m1,v); }
     590             : 
     591         182 :   switch(typ(sg))
     592             :   {
     593             :      case t_INTMOD: case t_INT:
     594          98 :       V = mkvecsmall( lift_check_modulus(sg,n) );
     595          91 :       break;
     596             :     case t_VECSMALL:
     597           0 :       V = gcopy(sg);
     598           0 :       for (i=1; i<lg(V); i++) { V[i] %= n; if (V[i] < 0) V[i] += n; }
     599           0 :       break;
     600             :     case t_VEC:
     601             :     case t_COL:
     602           0 :       V = cgetg(lg(sg),t_VECSMALL);
     603           0 :       for(i=1;i<lg(sg);i++) V[i] = lift_check_modulus(gel(sg,i),n);
     604           0 :       break;
     605             :     case t_MAT:
     606          84 :       if (lg(sg) == 1 || lg(sg) != lgcols(sg))
     607           7 :         pari_err_TYPE("galoissubcyclo [H not in HNF]", sg);
     608          77 :       if (!Z) pari_err_TYPE("galoissubcyclo [N not a bnrinit or znstar]", sg);
     609          70 :       if ( lg(gel(Z,2)) != lg(sg) ) pari_err_DIM("galoissubcyclo");
     610          63 :       V = znstar_hnf_generators(znstar_small(Z),sg);
     611          63 :       break;
     612             :     default:
     613           0 :       pari_err_TYPE("galoissubcyclo",sg);
     614             :       return NULL;/*LCOV_EXCL_LINE*/
     615             :   }
     616         154 :   if (!complex) V = vecsmall_append(V,n-1); /*add complex conjugation*/
     617         154 :   H = znstar_generate(n,V);
     618         154 :   if (DEBUGLEVEL >= 6)
     619             :   {
     620           0 :     err_printf("Subcyclo: elements:");
     621           0 :     for (i=1;i<n;i++)
     622           0 :       if (F2v_coeff(gel(H,3),i)) err_printf(" %ld",i);
     623           0 :     err_printf("\n");
     624             :   }
     625             :   /* field is real iff z -> conj(z) = z^-1 = z^(n-1) is in H */
     626         154 :   complex = !F2v_coeff(gel(H,3),n-1);
     627         154 :   if (DEBUGLEVEL >= 6) err_printf("Subcyclo: complex=%ld\n",complex);
     628         154 :   if (DEBUGLEVEL >= 1) timer_start(&ti);
     629         154 :   cnd = znstar_conductor(n,H);
     630         154 :   if (DEBUGLEVEL >= 1) timer_printf(&ti, "znstar_conductor");
     631         154 :   if (flag == 1)  { avma=ltop; return stoi(cnd); }
     632         154 :   if (cnd == 1)
     633             :   {
     634          28 :     avma = ltop;
     635          28 :     return gscycloconductor(deg1pol_shallow(gen_1,gen_m1,v),1,flag);
     636             :   }
     637         126 :   if (n != cnd)
     638             :   {
     639          35 :     H = znstar_reduce_modulus(H, cnd);
     640          35 :     n = cnd;
     641             :   }
     642         126 :   card = znstar_order(H);
     643         126 :   phi_n = eulerphiu(n);
     644         126 :   if (card == phi_n)
     645             :   {
     646           0 :     avma = ltop;
     647           0 :     return gscycloconductor(polcyclo(n,v),n,flag);
     648             :   }
     649         126 :   O = znstar_cosets(n, phi_n, H);
     650         126 :   if (DEBUGLEVEL >= 1) timer_printf(&ti, "znstar_cosets");
     651         126 :   if (DEBUGLEVEL >= 6) err_printf("Subcyclo: orbits=%Ps\n",O);
     652         126 :   if (DEBUGLEVEL >= 4)
     653           0 :     err_printf("Subcyclo: %ld orbits with %ld elements each\n",phi_n/card,card);
     654         126 :   av = avma;
     655         126 :   powz = polsubcyclo_complex_roots(n,!complex,LOWDEFAULTPREC);
     656         126 :   L = polsubcyclo_orbits(n,H,O,powz,NULL);
     657         126 :   B = polsubcyclo_complex_bound(av,L,LOWDEFAULTPREC);
     658         126 :   zl = polsubcyclo_start(n,phi_n/card,card,1,B,&val,&l);
     659         126 :   powz = polsubcyclo_roots(n,zl);
     660         126 :   le = gel(zl,1);
     661         126 :   L = polsubcyclo_orbits(n,H,O,powz,le);
     662         126 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     663         126 :   T = FpV_roots_to_pol(L,le,v);
     664         126 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "roots_to_pol");
     665         126 :   T = FpX_center(T,le,shifti(le,-1));
     666         126 :   return gerepileupto(ltop, gscycloconductor(T,n,flag));
     667             : }
     668             : 
     669             : /* Z = znstar(n) cyclic. n = 1,2,4,p^a or 2p^a,
     670             :  * and d | phi(n) = 1,1,2,(p-1)p^(a-1) */
     671             : static GEN
     672        3052 : polsubcyclo_g(long n, long d, GEN Z, long v)
     673             : {
     674        3052 :   pari_sp ltop = avma;
     675             :   long o, p, r, g, gd, l , val;
     676             :   GEN zl, L, T, le, B, powz;
     677             :   pari_timer ti;
     678        3052 :   if (d==1) return deg1pol_shallow(gen_1,gen_m1,v); /* get rid of n=1,2 */
     679        3052 :   if ((n & 3) == 2) n >>= 1;
     680             :   /* n = 4 or p^a, p odd */
     681        3052 :   o = itos(gel(Z,1));
     682        3052 :   g = itos(gmael3(Z,3,1,2));
     683        3052 :   p = n / ugcd(n,o); /* p^a / gcd(p^a,phi(p^a)) = p*/
     684        3052 :   r = ugcd(d,n); /* = p^(v_p(d)) < n */
     685        3052 :   n = r*p; /* n is now the conductor */
     686        3052 :   o = n-r; /* = phi(n) */
     687        3052 :   if (o == d) return polcyclo(n,v);
     688        2989 :   o /= d;
     689        2989 :   gd = Fl_powu(g%n, d, n);
     690             :   /*FIXME: If degree is small, the computation of B is a waste of time*/
     691        2989 :   powz = polsubcyclo_complex_roots(n,(o&1)==0,LOWDEFAULTPREC);
     692        2989 :   L = polsubcyclo_cyclic(n,d,o,g,gd,powz,NULL);
     693        2989 :   B = polsubcyclo_complex_bound(ltop,L,LOWDEFAULTPREC);
     694        2989 :   zl = polsubcyclo_start(n,d,o,1,B,&val,&l);
     695        2989 :   le = gel(zl,1);
     696        2989 :   powz = polsubcyclo_roots(n,zl);
     697        2989 :   L = polsubcyclo_cyclic(n,d,o,g,gd,powz,le);
     698        2989 :   if (DEBUGLEVEL >= 6) timer_start(&ti);
     699        2989 :   T = FpV_roots_to_pol(L,le,v);
     700        2989 :   if (DEBUGLEVEL >= 6) timer_printf(&ti, "roots_to_pol");
     701        2989 :   return gerepileupto(ltop, FpX_center(T,le,shifti(le,-1)));
     702             : }
     703             : 
     704             : GEN
     705        3080 : polsubcyclo(long n, long d, long v)
     706             : {
     707        3080 :   pari_sp ltop = avma;
     708             :   GEN L, Z;
     709        3080 :   if (v<0) v = 0;
     710        3080 :   if (d<=0) pari_err_DOMAIN("polsubcyclo","d","<=",gen_0,stoi(d));
     711        3073 :   if (n<=0) pari_err_DOMAIN("polsubcyclo","n","<=",gen_0,stoi(n));
     712        3066 :   Z = znstar(stoi(n));
     713        3066 :   if (!dvdis(gel(Z,1), d)) { avma = ltop; return cgetg(1, t_VEC); }
     714        3066 :   if (lg(gel(Z,2)) == 2)
     715             :   { /* faster but Z must be cyclic */
     716        3052 :     avma = ltop;
     717        3052 :     return polsubcyclo_g(n, d, Z, v);
     718             :   }
     719          14 :   L = subgrouplist(gel(Z,2), mkvec(stoi(d)));
     720          14 :   if (lg(L) == 2)
     721           7 :     return gerepileupto(ltop, galoissubcyclo(Z, gel(L,1), 0, v));
     722             :   else
     723             :   {
     724           7 :     GEN V = cgetg(lg(L),t_VEC);
     725             :     long i;
     726           7 :     for (i=1; i< lg(V); i++) gel(V,i) = galoissubcyclo(Z, gel(L,i), 0, v);
     727           7 :     return gerepileupto(ltop, V);
     728             :   }
     729             : }
     730             : 
     731             : struct aurifeuille_t {
     732             :   GEN z, le;
     733             :   ulong l;
     734             :   long e;
     735             : };
     736             : 
     737             : /* Let z a primitive n-th root of 1, n > 1, A an integer such that
     738             :  * Aurifeuillian factorization of Phi_n(A) exists ( z.A is a square in Q(z) ).
     739             :  * Let G(p) the Gauss sum mod p prime:
     740             :  *      sum_x (x|p) z^(xn/p) for p odd,  i - 1 for p = 2 [ i := z^(n/4) ]
     741             :  * We have N(-1) = Nz = 1 (n != 1,2), and
     742             :  *      G^2 = (-1|p) p for p odd,  G^2 = -2i for p = 2
     743             :  * In particular, for odd A, (-1|A) A = g^2 is a square. If A = prod p^{e_p},
     744             :  * sigma_j(g) = \prod_p (sigma_j G(p)))^e_p = \prod_p (j|p)^e_p g = (j|A) g
     745             :  * n odd  : z^2 is a primitive root, A = g^2
     746             :  *   Phi_n(A) = N(A - z^2) = N(g - z) N(g + z)
     747             :  *
     748             :  * n = 2 (4) : -z^2 is a primitive root, -A = g^2
     749             :  *   Phi_n(A) = N(A - (-z^2)) = N(g^2 - z^2)  [ N(-1) = 1 ]
     750             :  *                            = N(g - z) N(g + z)
     751             :  *
     752             :  * n = 4 (8) : i z^2 primitive root, -Ai = g^2
     753             :  *   Phi_n(A) = N(A - i z^2) = N(-Ai -  z^2) = N(g - z) N(g + z)
     754             :  * sigma_j(g) / g =  (j|A)  if j = 1 (4)
     755             :  *                  (-j|A)i if j = 3 (4)
     756             :  *   */
     757             : /* factor Phi_n(A), Astar: A* = squarefree kernel of A, P = odd prime divisors
     758             :  * of n */
     759             : static GEN
     760        5278 : factor_Aurifeuille_aux(GEN A, long Astar, long n, GEN P,
     761             :                        struct aurifeuille_t *S)
     762             : {
     763             :   pari_sp av;
     764        5278 :   GEN f, a, b, s, powers, z = S->z, le = S->le;
     765        5278 :   long j, k, maxjump, lastj, e = S->e;
     766        5278 :   ulong l = S->l;
     767             :   char *invertible;
     768             : 
     769        5278 :   if ((n & 7) == 4)
     770             :   { /* A^* even */
     771        5215 :     GEN i = Fp_powu(z, n>>2, le), z2 = Fp_sqr(z, le);
     772             : 
     773        5215 :     invertible = stack_malloc(n); /* even indices unused */
     774        5215 :     for (j = 1; j < n; j+=2) invertible[j] = 1;
     775        5271 :     for (k = 1; k < lg(P); k++)
     776             :     {
     777          56 :       long p = P[k];
     778          56 :       for (j = p; j < n; j += 2*p) invertible[j] = 0;
     779             :     }
     780        5215 :     lastj = 1; maxjump = 2;
     781       10990 :     for (j= 3; j < n; j+=2)
     782        5775 :       if (invertible[j]) {
     783        5663 :         long jump = j - lastj;
     784        5663 :         if (jump > maxjump) maxjump = jump;
     785        5663 :         lastj = j;
     786             :       }
     787        5215 :     powers = cgetg(maxjump+1, t_VEC); /* powers[k] = z^k, odd indices unused */
     788        5215 :     gel(powers,2) = z2;
     789        5271 :     for (k = 4; k <= maxjump; k+=2)
     790         112 :       gel(powers,k) = odd(k>>1)? Fp_mul(gel(powers, k-2), z2, le)
     791          56 :                                : Fp_sqr(gel(powers, k>>1), le);
     792             : 
     793        5215 :     if (Astar == 2)
     794             :     { /* important special case (includes A=2), split for efficiency */
     795        5194 :       if (!equalis(A, 2))
     796             :       {
     797          14 :         GEN f = sqrti(shifti(A,-1)), mf = Fp_neg(f,le), fi = Fp_mul(f,i,le);
     798          14 :         a = Fp_add(mf, fi, le);
     799          14 :         b = Fp_sub(mf, fi, le);
     800             :       }
     801             :       else
     802             :       {
     803        5180 :         a = subiu(i,1);
     804        5180 :         b = subsi(-1,i);
     805             :       }
     806        5194 :       av = avma;
     807        5194 :       s = z; f = subii(a, s); lastj = 1;
     808       10640 :       for (j = 3, k = 0; j < n; j+=2)
     809        5446 :         if (invertible[j])
     810             :         {
     811        5376 :           s = Fp_mul(gel(powers, j-lastj), s, le); /* z^j */
     812        5376 :           lastj = j;
     813        5376 :           f = Fp_mul(f, subii((j & 3) == 1? a: b, s), le);
     814        5376 :           if (++k == 0x1ff) { gerepileall(av, 2, &s, &f); k = 0; }
     815             :         }
     816             :     }
     817             :     else
     818             :     {
     819          21 :       GEN ma, mb, B = Fp_mul(A, i, le), gl = utoipos(l);
     820             :       long t;
     821          21 :       Astar >>= 1;
     822          21 :       t = Astar & 3; if (Astar < 0) t = 4-t; /* t = 1 or 3 */
     823          21 :       if (t == 1) B = Fp_neg(B, le);
     824          21 :       a = Zp_sqrtlift(B, Fp_sqrt(B, gl), gl, e);
     825          21 :       b = Fp_mul(a, i, le);
     826          21 :       ma = Fp_neg(a, le);
     827          21 :       mb = Fp_neg(b, le);
     828          21 :       av = avma;
     829          21 :       s = z; f = subii(a, s); lastj = 1;
     830         350 :       for (j = 3, k = 0; j<n; j+=2)
     831         329 :         if (invertible[j])
     832             :         {
     833             :           GEN t;
     834         287 :           if ((j & 3) == 1) t = (kross(j, Astar) < 0)? ma: a;
     835         154 :           else              t = (kross(j, Astar) < 0)? mb: b;
     836         287 :           s = Fp_mul(gel(powers, j-lastj), s, le); /* z^j */
     837         287 :           lastj = j;
     838         287 :           f = Fp_mul(f, subii(t, s), le);
     839         287 :           if (++k == 0x1ff) { gerepileall(av, 2, &s, &f); k = 0; }
     840             :         }
     841             :     }
     842             :   }
     843             :   else /* A^* odd */
     844             :   {
     845             :     ulong g;
     846          63 :     if ((n & 3) == 2)
     847             :     { /* A^* = 3 (mod 4) */
     848           0 :       A = negi(A); Astar = -Astar;
     849           0 :       z = Fp_neg(z, le);
     850           0 :       n >>= 1;
     851             :     }
     852             :     /* A^* = 1 (mod 4) */
     853          63 :     g = Fl_sqrt(umodiu(A,l), l);
     854          63 :     a = Zp_sqrtlift(A, utoipos(g), utoipos(l), e);
     855          63 :     b = negi(a);
     856             : 
     857          63 :     invertible = stack_malloc(n);
     858          63 :     for (j = 1; j < n; j++) invertible[j] = 1;
     859         168 :     for (k = 1; k < lg(P); k++)
     860             :     {
     861         105 :       long p = P[k];
     862         105 :       for (j = p; j < n; j += p) invertible[j] = 0;
     863             :     }
     864          63 :     lastj = 2; maxjump = 1;
     865        1141 :     for (j= 3; j < n; j++)
     866        1078 :       if (invertible[j]) {
     867         714 :         long jump = j - lastj;
     868         714 :         if (jump > maxjump) maxjump = jump;
     869         714 :         lastj = j;
     870             :       }
     871          63 :     powers = cgetg(maxjump+1, t_VEC); /* powers[k] = z^k */
     872          63 :     gel(powers,1) = z;
     873         147 :     for (k = 2; k <= maxjump; k++)
     874         210 :       gel(powers,k) = odd(k)? Fp_mul(gel(powers, k-1), z, le)
     875         126 :                             : Fp_sqr(gel(powers, k>>1), le);
     876          63 :     av = avma;
     877          63 :     s = z; f = subii(a, s); lastj = 1;
     878        1204 :     for(j = 2, k = 0; j < n; j++)
     879        1141 :       if (invertible[j])
     880             :       {
     881         777 :         s = Fp_mul(gel(powers, j-lastj), s, le);
     882         777 :         lastj = j;
     883         777 :         f = Fp_mul(f, subii(kross(j,Astar)==1? a: b, s), le);
     884         777 :         if (++k == 0x1ff) { gerepileall(av, 2, &s, &f); k = 0; }
     885             :       }
     886             :   }
     887        5278 :   return f;
     888             : }
     889             : 
     890             : /* fd = factoru(odd part of d = d or d/4). Return eulerphi(d) */
     891             : static ulong
     892        5278 : phi(long d, GEN fd)
     893             : {
     894        5278 :   GEN P = gel(fd,1), E = gel(fd,2);
     895        5278 :   long i, l = lg(P);
     896        5278 :   ulong phi = 1;
     897        5439 :   for (i = 1; i < l; i++)
     898             :   {
     899         161 :     ulong p = P[i], e = E[i];
     900         161 :     phi *= upowuu(p, e-1)*(p-1);
     901             :   }
     902        5278 :   if (!odd(d)) phi <<= 1;
     903        5278 :   return phi;
     904             : }
     905             : 
     906             : static void
     907        5278 : Aurifeuille_init(GEN a, long d, GEN fd, struct aurifeuille_t *S)
     908             : {
     909        5278 :   GEN sqrta = sqrtr_abs(itor(a, LOWDEFAULTPREC));
     910        5278 :   GEN bound = ceil_safe(powru(addrs(sqrta,1), phi(d, fd)));
     911        5278 :   GEN zl = polsubcyclo_start(d, 0, 0, 1, bound, &(S->e), (long*)&(S->l));
     912        5278 :   S->le = gel(zl,1);
     913        5278 :   S->z  = gel(zl,2);
     914        5278 : }
     915             : 
     916             : GEN
     917        5215 : factor_Aurifeuille_prime(GEN p, long d)
     918             : {
     919        5215 :   pari_sp av = avma;
     920             :   struct aurifeuille_t S;
     921             :   GEN fd;
     922             :   long pp;
     923        5215 :   if ((d & 3) == 2) { d >>= 1; p = negi(p); }
     924        5215 :   fd = factoru(odd(d)? d: d>>2);
     925        5215 :   pp = itos(p);
     926        5215 :   Aurifeuille_init(p, d, fd, &S);
     927        5215 :   return gerepileuptoint(av, factor_Aurifeuille_aux(p, pp, d, gel(fd,1), &S));
     928             : }
     929             : 
     930             : /* an algebraic factor of Phi_d(a), a != 0 */
     931             : GEN
     932          63 : factor_Aurifeuille(GEN a, long d)
     933             : {
     934          63 :   pari_sp av = avma;
     935             :   GEN fd, P, A;
     936          63 :   long i, lP, va = vali(a), sa, astar, D;
     937             :   struct aurifeuille_t S;
     938             : 
     939          63 :   if (d <= 0)
     940           0 :     pari_err_DOMAIN("factor_Aurifeuille", "degre", "<=",gen_0,stoi(d));
     941          63 :   if ((d & 3) == 2) { d >>= 1; a = negi(a); }
     942          63 :   if ((va & 1) == (d & 1)) { avma = av; return gen_1; }
     943          63 :   sa = signe(a);
     944          63 :   if (odd(d))
     945             :   {
     946             :     long a4;
     947          28 :     if (d == 1)
     948             :     {
     949           0 :       if (!Z_issquareall(a, &A)) return gen_1;
     950           0 :       return gerepileuptoint(av, addiu(A,1));
     951             :     }
     952          28 :     A = va? shifti(a, -va): a;
     953          28 :     a4 = mod4(A); if (sa < 0) a4 = 4 - a4;
     954          28 :     if (a4 != 1) { avma = av; return gen_1; }
     955             :   }
     956          35 :   else if ((d & 7) == 4)
     957          35 :     A = shifti(a, -va);
     958             :   else
     959             :   {
     960           0 :     avma = av; return gen_1;
     961             :   }
     962             :   /* v_2(d) = 0 or 2. Kill 2 from factorization (minor efficiency gain) */
     963          63 :   fd = factoru(odd(d)? d: d>>2); P = gel(fd,1); lP = lg(P);
     964          63 :   astar = sa;
     965          63 :   if (odd(va)) astar <<= 1;
     966         147 :   for (i = 1; i < lP; i++)
     967          84 :     if (odd( (Z_lvalrem(A, P[i], &A)) ) ) astar *= P[i];
     968          63 :   if (sa < 0)
     969             :   { /* negate in place if possible */
     970          14 :     if (A == a) A = icopy(A);
     971          14 :     setabssign(A);
     972             :   }
     973          63 :   if (!Z_issquare(A)) { avma = av; return gen_1; }
     974             : 
     975          63 :   D = odd(d)? 1: 4;
     976          63 :   for (i = 1; i < lP; i++) D *= P[i];
     977          63 :   if (D != d) { a = powiu(a, d/D); d = D; }
     978             : 
     979          63 :   Aurifeuille_init(a, d, fd, &S);
     980          63 :   return gerepileuptoint(av, factor_Aurifeuille_aux(a, astar, d, P, &S));
     981             : }

Generated by: LCOV version 1.11