bridge/class-master/depend/pari/src/basemath/ifactor1.c
/* Gets called to complete ifac_crack's job when a factoring engine splits
 * the current factor into a product of three or more new factors. Makes room
 * for them if necessary, sorts them, gives them the right exponents and class.
 * Also returns the number of factors actually written, which may be less than
 * the number of components in facvec if there are duplicates.--- Vectors of
 * factors  (cf pollardbrent()) actually contain 'slots' of three GENs per
 * factor with the three fields interpreted as in our partial factorization
 * data structure.  Thus 'engines' can tell us what they already happen to
 * know about factors being prime or composite and/or appearing to a power
 * larger than the first.
 * Don't collect garbage.  No diagnostics: the factoring engine should have
 * printed what it found. facvec contains slots of three components per factor;
 * repeated factors are allowed  (and their classes shouldn't contradict each
 * other whereas their exponents will be added up) */
Gets called to complete ifac_crack's job when a factoring engine splits
the current factor into a product of three or more new factors. Makes room
for them if necessary, sorts them, gives them the right exponents and class.
Also returns the number of factors actually written, which may be less than
the number of components in facvec if there are duplicates.--- Vectors of
factors  (cf pollardbrent()) actually contain 'slots' of three GENs per
factor with the three fields interpreted as in our partial factorization
data structure.  Thus 'engines' can tell us what they already happen to
know about factors being prime or composite and/or appearing to a power
larger than the first.
Don't collect garbage.  No diagnostics: the factoring engine should have
printed what it found. facvec contains slots of three components per factor;
repeated factors are allowed  (and their classes shouldn't contradict each
other whereas their exponents will be added up)
Gets called to complete ifac_crack ' s job when a factoring engine splits the current factor into a product of three or more new factors . Makes room for them if necessary sorts them gives them the right exponents and class . Also returns the number of factors actually written which may be less than the number of components in facvec if there are duplicates . --- Vectors of factors ( cf pollardbrent () ) actually contain ' slots ' of three GENs per factor with the three fields interpreted as in our partial factorization data structure . Thus ' engines ' can tell us what they already happen to know about factors being prime or composite and / or appearing to a power larger than the first . Don ' t collect garbage . No diagnostics : the factoring engine should have printed what it found . facvec contains slots of three components per factor ; repeated factors are allowed ( and their classes shouldn ' t contradict each other whereas their exponents will be added up )
static long
ifac_insert_multiplet(GEN *partial, GEN *where, GEN facvec, long moebius_mode)
{
  long j,k=1, lfv=lg(facvec)-1, nf=lfv/3, room=(long)(*where-*partial);
  long needroom = lfv - room;
  GEN e, newexp, cur, sorted, auxvec = cgetg(nf+1, t_VEC), factor;
  long exponent = itos(EXPON(*where)); 
  if (DEBUGLEVEL >= 5) 
    err_printf("IFAC: incorporating set of %ld factor(s)\n", nf);
  if (needroom > 0) 
    ifac_realloc(partial, where, lg(*partial) + needroom + 3);
  for (j=nf; j; j--) auxvec[j] = facvec[3*j-2]; 
  sorted = indexsort(auxvec);
  for (j=nf; j; j--) sorted[j] = 3*sorted[j]-2;
  cur = facvec + sorted[nf];
  VALUE(*where) = VALUE(cur);
  newexp = EXPON(cur);
  if (newexp != gen_1) 
  {
    if (exponent == 1)
      e = isonstack(newexp)? icopy(newexp): newexp;
    else
      e = mului(exponent, newexp);
    EXPON(*where) = e;
  } 
  CLASS(*where) = CLASS(cur);
  if (DEBUGLEVEL >= 6) err_printf("\tstored (largest) factor no. %ld...\n", nf);
  for (j=nf-1; j; j--)
  {
    cur = facvec + sorted[j];
    factor = VALUE(cur);
    if (equalii(factor, VALUE(*where)))
    {
      if (DEBUGLEVEL >= 6)
        err_printf("\tfactor no. %ld is a duplicate%s\n", j, (j>1? "...": ""));
      newexp = EXPON(cur);
      if (newexp != gen_1) 
        e = addis(EXPON(*where), exponent * itos(newexp));
      else if (EXPON(*where) == gen_1 && exponent == 1)
        e = gen_2;
      else
        e = addis(EXPON(*where), exponent);
      EXPON(*where) = e;
      if (moebius_mode) return 0; 
      continue;
    }
    *where -= 3;
    CLASS(*where) = CLASS(cur);        
    newexp = EXPON(cur);
    if (newexp != gen_1) 
    {
      if (exponent == 1 && newexp == gen_2)
        e = gen_2;
      else 
        e = mului(exponent, newexp);
    }
    else
      e = (exponent == 1 ? gen_1 :
            (exponent == 2 ? gen_2 :
               utoipos(exponent))); 
    EXPON(*where) = e;
    VALUE(*where) = isonstack(factor) ? icopy(factor) : factor;
    k++;
    if (DEBUGLEVEL >= 6)
      err_printf("\tfactor no. %ld was unique%s\n", j, j>1? " (so far)...": "");
  }
  *sorted = evaltyp(t_INT) | evallg(nf+1);
  return k;
}
static long ifac_insert_multiplet ( GEN * partial , GEN * where , GEN facvec , long moebius_mode ) { long j , k = 1 , lfv = lg ( facvec ) - 1 , nf = lfv / 3 , room = ( long ) ( * where - * partial ) ; long needroom = lfv - room ; GEN e , newexp , cur , sorted , auxvec = cgetg ( nf + 1 , t_VEC ) , factor ; long exponent = itos ( EXPON ( * where ) ) ; if ( DEBUGLEVEL >= 5 ) err_printf ( " \n " , nf ) ; if ( needroom > 0 ) ifac_realloc ( partial , where , lg ( * partial ) + needroom + 3 ) ; for ( j = nf ; j ; j -- ) auxvec [ j ] = facvec [ 3 * j - 2 ] ; sorted = indexsort ( auxvec ) ; for ( j = nf ; j ; j -- ) sorted [ j ] = 3 * sorted [ j ] - 2 ; cur = facvec + sorted [ nf ] ; VALUE ( * where ) = VALUE ( cur ) ; newexp = EXPON ( cur ) ; if ( newexp != gen_1 ) { if ( exponent == 1 ) e = isonstack ( newexp ) ? icopy ( newexp ) : newexp ; else e = mului ( exponent , newexp ) ; EXPON ( * where ) = e ; } CLASS ( * where ) = CLASS ( cur ) ; if ( DEBUGLEVEL >= 6 ) err_printf ( " \t \n " , nf ) ; for ( j = nf - 1 ; j ; j -- ) { cur = facvec + sorted [ j ] ; factor = VALUE ( cur ) ; if ( equalii ( factor , VALUE ( * where ) ) ) { if ( DEBUGLEVEL >= 6 ) err_printf ( " \t \n " , j , ( j > 1 ? " " : " " ) ) ; newexp = EXPON ( cur ) ; if ( newexp != gen_1 ) e = addis ( EXPON ( * where ) , exponent * itos ( newexp ) ) ; else if ( EXPON ( * where ) == gen_1 && exponent == 1 ) e = gen_2 ; else e = addis ( EXPON ( * where ) , exponent ) ; EXPON ( * where ) = e ; if ( moebius_mode ) return 0 ; continue ; } * where -= 3 ; CLASS ( * where ) = CLASS ( cur ) ; newexp = EXPON ( cur ) ; if ( newexp != gen_1 ) { if ( exponent == 1 && newexp == gen_2 ) e = gen_2 ; else e = mului ( exponent , newexp ) ; } else e = ( exponent == 1 ? gen_1 : ( exponent == 2 ? gen_2 : utoipos ( exponent ) ) ) ; EXPON ( * where ) = e ; VALUE ( * where ) = isonstack ( factor ) ? icopy ( factor ) : factor ; k ++ ; if ( DEBUGLEVEL >= 6 ) err_printf ( " \t \n " , j , j > 1 ? " " : " " ) ; } * sorted = evaltyp ( t_INT ) | evallg ( nf + 1 ) ; return k ; }
Gets called to complete ifac_crack's job when a factoring engine splits
 the current factor into a product of three or more new factors.
Gets called to complete ifac_crack ' s job when a factoring engine splits the current factor into a product of three or more new factors .
/* one of the factors will go into the *where slot, so room is now 3 times
   * the number of slots we can use */ /* the old exponent */ /* squfof may return a single squared factor as a set */ /* one extra slot for paranoia, errm, future use */ /* create sort permutation from the values of the factors */ /* just the pointers */ /* and readjust the result for the triple spacing */ /* store factors, beginning at *where, and catching any duplicates */ /* new exponent > 1 */ /* if new exponent is 1, the old exponent already in place will do */ /* update exponent, ignore class which would already have been set,
       * then forget current factor */ /* new exp > 1 */ /* stop now, but with exponent updated */ /* class as given */ /* new exp > 1 */ /* exponent*newexp > 2 */ /* inherit parent's exponent */ /* keep components younger than *partial */ /* make the 'sorted' object safe for garbage collection (it should be in the
   * garbage zone from everybody's perspective, but it's easy to do it) */