Changeset f63d2e8 in git for factory/facMul.cc


Ignore:
Timestamp:
Jan 7, 2014, 2:40:44 PM (10 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', 'e7cc1ebecb61be8b9ca6c18016352af89940b21a')
Children:
9fbf02f68394ff576e8b5825b51326cca02d8cdd
Parents:
7ed4f6c34d2b1133b547efc14dffe495b47b317e
git-author:
Martin Lee <martinlee84@web.de>2014-01-07 14:40:44+01:00
git-committer:
Martin Lee <martinlee84@web.de>2014-01-20 16:45:04+01:00
Message:
chg: more concise functions for Kronecker substitution and reversion of the very same
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/facMul.cc

    r7ed4f6c rf63d2e8  
    6363  int k= 0;
    6464  int degfSubK;
    65   int repLength, j;
    66   CanonicalForm coeff, ff;
    67   fmpz* tmp;
     65  int repLength;
     66  fmpq_poly_t buf;
     67  fmpq_poly_t mipo;
     68  convertFacCF2Fmpq_poly_t (mipo, getMipo(alpha));
    6869  while (degf >= k)
    6970  {
    70     coeff= 0;
    7171    degfSubK= degf - k;
    7272    if (degfSubK >= d)
     
    7575      repLength= degfSubK + 1;
    7676
    77     for (j= 0; j < repLength; j++)
    78     {
    79       tmp= fmpz_poly_get_coeff_ptr (F, j+k);
    80       if (!fmpz_is_zero (tmp))
    81       {
    82         ff= convertFmpz2CF (tmp);
    83         coeff += ff*power (alpha, j); //TODO faster reduction mod alpha
    84       }
    85     }
    86     result += coeff*power (x, i);
     77    fmpq_poly_init2 (buf, repLength);
     78    _fmpq_poly_set_length (buf, repLength);
     79    _fmpz_vec_set (buf->coeffs, F->coeffs + k, repLength);
     80    _fmpq_poly_normalise (buf);
     81    fmpq_poly_rem (buf, buf, mipo);
     82
     83    result += convertFmpq_poly_t2FacCF (buf, alpha)*power (x, i);
     84    fmpq_poly_clear (buf);
    8785    i++;
    8886    k= d*i;
    8987  }
     88  fmpq_poly_clear (mipo);
    9089  result /= den;
    9190  return result;
     
    11541153#endif
    11551154
    1156 void kronSubQa (fmpq_poly_t result, const CanonicalForm& A, int d1, int d2)
     1155/*void kronSubQa (fmpq_poly_t result, const CanonicalForm& A, int d1, int d2)
    11571156{
    11581157  int degAy= degree (A);
     
    11971196  fmpq_clear (coeff);
    11981197  _fmpq_poly_normalise (result);
     1198}*/
     1199
     1200void kronSubQa (fmpz_poly_t result, const CanonicalForm& A, int d1, int d2)
     1201{
     1202  int degAy= degree (A);
     1203  fmpz_poly_init2 (result, d1*(degAy + 1));
     1204  _fmpz_poly_set_length (result, d1*(degAy + 1));
     1205
     1206  fmpz_poly_t buf;
     1207
     1208  int k;
     1209  CFIterator j;
     1210  for (CFIterator i= A; i.hasTerms(); i++)
     1211  {
     1212    if (i.coeff().inCoeffDomain())
     1213    {
     1214      k= d1*i.exp();
     1215      convertFacCF2Fmpz_poly_t (buf, i.coeff());
     1216      _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length);
     1217      fmpz_poly_clear (buf);
     1218    }
     1219    else
     1220    {
     1221      for (j= i.coeff(); j.hasTerms(); j++)
     1222      {
     1223        k= d1*i.exp();
     1224        k += d2*j.exp();
     1225        convertFacCF2Fmpz_poly_t (buf, j.coeff());
     1226        _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length);
     1227        fmpz_poly_clear (buf);
     1228      }
     1229    }
     1230  }
     1231  _fmpz_poly_normalise (result);
    11991232}
    12001233
     
    12941327
    12951328  fmpz_poly_t buf;
    1296   fmpz_t coeff1, coeff2;
    1297 
    1298   int k, kk, j, bufRepLength;
     1329
     1330  int k, kk;
    12991331  for (CFIterator i= A; i.hasTerms(); i++)
    13001332  {
     
    13031335    k= i.exp()*d;
    13041336    kk= (degAy - i.exp())*d;
    1305     bufRepLength= (int) fmpz_poly_length (buf);
    1306     for (j= 0; j < bufRepLength; j++)
    1307     {
    1308       fmpz_poly_get_coeff_fmpz (coeff1, subA1, j+k);
    1309       fmpz_poly_get_coeff_fmpz (coeff2, buf, j);
    1310       fmpz_add (coeff1, coeff1, coeff2);
    1311       fmpz_poly_set_coeff_fmpz (subA1, j + k, coeff1);
    1312       fmpz_poly_get_coeff_fmpz (coeff1, subA2, j + kk);
    1313       fmpz_add (coeff1, coeff1, coeff2);
    1314       fmpz_poly_set_coeff_fmpz (subA2, j + kk, coeff1);
    1315     }
     1337    _fmpz_vec_add (subA1->coeffs+k, subA1->coeffs + k, buf->coeffs, buf->length);
     1338    _fmpz_vec_add (subA2->coeffs+kk, subA2->coeffs + kk, buf->coeffs, buf->length);
    13161339    fmpz_poly_clear (buf);
    13171340  }
    1318   fmpz_clear (coeff1);
    1319   fmpz_clear (coeff2);
     1341
    13201342  _fmpz_poly_normalise (subA1);
    13211343  _fmpz_poly_normalise (subA2);
     
    13261348  Variable y= Variable (2);
    13271349  Variable x= Variable (1);
    1328 
    1329   fmpz_poly_t f;
    1330   fmpz_poly_init (f);
    1331   fmpz_poly_set (f, F);
    13321350
    13331351  fmpz_poly_t buf;
    13341352  CanonicalForm result= 0;
    13351353  int i= 0;
    1336   int degf= fmpz_poly_degree(f);
     1354  int degf= fmpz_poly_degree(F);
    13371355  int k= 0;
    1338   int degfSubK, repLength, j;
    1339   fmpz_t coeff;
     1356  int degfSubK, repLength;
    13401357  while (degf >= k)
    13411358  {
     
    13471364
    13481365    fmpz_poly_init2 (buf, repLength);
    1349     fmpz_init (coeff);
    1350     for (j= 0; j < repLength; j++)
    1351     {
    1352       fmpz_poly_get_coeff_fmpz (coeff, f, j + k);
    1353       fmpz_poly_set_coeff_fmpz (buf, j, coeff);
    1354     }
     1366    _fmpz_poly_set_length (buf, repLength);
     1367    _fmpz_vec_set (buf->coeffs, F->coeffs+k, repLength);
    13551368    _fmpz_poly_normalise (buf);
    13561369
     
    13591372    k= d*i;
    13601373    fmpz_poly_clear (buf);
    1361     fmpz_clear (coeff);
    1362   }
    1363   fmpz_poly_clear (f);
     1374  }
    13641375
    13651376  return result;
    13661377}
    13671378
    1368 CanonicalForm
     1379/*CanonicalForm
    13691380reverseSubstQa (const fmpq_poly_t F, int d1, int d2, const Variable& alpha,
    13701381                const fmpq_poly_t mipo)
     
    14361447  fmpq_poly_clear (f);
    14371448  return result;
     1449}*/
     1450
     1451CanonicalForm
     1452reverseSubstQa (const fmpz_poly_t F, int d1, int d2, const Variable& alpha,
     1453                const fmpq_poly_t mipo)
     1454{
     1455  Variable y= Variable (2);
     1456  Variable x= Variable (1);
     1457
     1458  fmpq_poly_t buf;
     1459  CanonicalForm result= 0, result2;
     1460  int i= 0;
     1461  int degf= fmpz_poly_degree(F);
     1462  int k= 0;
     1463  int degfSubK;
     1464  int repLength;
     1465  while (degf >= k)
     1466  {
     1467    degfSubK= degf - k;
     1468    if (degfSubK >= d1)
     1469      repLength= d1;
     1470    else
     1471      repLength= degfSubK + 1;
     1472
     1473    int j= 0;
     1474    result2= 0;
     1475    while (j*d2 < repLength)
     1476    {
     1477      fmpq_poly_init2 (buf, d2);
     1478      _fmpq_poly_set_length (buf, d2);
     1479      _fmpz_vec_set (buf->coeffs, F->coeffs + k*j*d2, d2);
     1480      _fmpq_poly_normalise (buf);
     1481      fmpq_poly_rem (buf, buf, mipo);
     1482      result2 += convertFmpq_poly_t2FacCF (buf, alpha)*power (x, j);
     1483      j++;
     1484      fmpq_poly_clear (buf);
     1485    }
     1486    if (repLength - j*d2 != 0 && j*d2 - repLength < d2)
     1487    {
     1488      j--;
     1489      repLength -= j*d2;
     1490      fmpq_poly_init2 (buf, repLength);
     1491      _fmpq_poly_set_length (buf, repLength);
     1492      j++;
     1493      _fmpz_vec_set (buf->coeffs, F->coeffs + k + j*d2, repLength);
     1494      _fmpq_poly_normalise (buf);
     1495      fmpq_poly_rem (buf, buf, mipo);
     1496      result2 += convertFmpq_poly_t2FacCF (buf, alpha)*power (x, j);
     1497      fmpq_poly_clear (buf);
     1498    }
     1499
     1500    result += result2*power (y, i);
     1501    i++;
     1502    k= d1*i;
     1503  }
     1504
     1505  return result;
    14381506}
    14391507
     
    16751743  int degg= fmpz_poly_degree(g);
    16761744
    1677 
    16781745  fmpz_poly_t buf1,buf2, buf3;
    16791746
     
    20782145}
    20792146
    2080 CanonicalForm
     2147/*CanonicalForm
    20812148mulMod2FLINTQa (const CanonicalForm& F, const CanonicalForm& G,
    20822149                const CanonicalForm& M)
     
    21082175  fmpq_poly_clear (FLINTG);
    21092176  return result;
     2177}*/
     2178
     2179CanonicalForm
     2180mulMod2FLINTQa (const CanonicalForm& F, const CanonicalForm& G,
     2181                const CanonicalForm& M)
     2182{
     2183  Variable a;
     2184  if (!hasFirstAlgVar (F,a) && !hasFirstAlgVar (G, a))
     2185    return mulMod2FLINTQ (F, G, M);
     2186  CanonicalForm A= F, B= G;
     2187
     2188  int degFx= degree (F, 1);
     2189  int degFa= degree (F, a);
     2190  int degGx= degree (G, 1);
     2191  int degGa= degree (G, a);
     2192
     2193  int d2= degFa+degGa+1;
     2194  int d1= degFx + 1 + degGx;
     2195  d1 *= d2;
     2196
     2197  CanonicalForm f= bCommonDen (F);
     2198  CanonicalForm g= bCommonDen (G);
     2199  A *= f;
     2200  B *= g;
     2201
     2202  fmpz_poly_t FLINTF, FLINTG;
     2203  kronSubQa (FLINTF, A, d1, d2);
     2204  kronSubQa (FLINTG, B, d1, d2);
     2205
     2206  fmpz_poly_mullow (FLINTF, FLINTF, FLINTG, d1*degree (M));
     2207
     2208  fmpq_poly_t mipo;
     2209  convertFacCF2Fmpq_poly_t (mipo, getMipo (a));
     2210  A= reverseSubstQa (FLINTF, d1, d2, a, mipo);
     2211  fmpz_poly_clear (FLINTF);
     2212  fmpz_poly_clear (FLINTG);
     2213  return A/(f*g);
    21102214}
    21112215
Note: See TracChangeset for help on using the changeset viewer.