Changeset f876a66 in git for factory/facFqBivarUtil.cc


Ignore:
Timestamp:
May 24, 2011, 5:48:25 PM (13 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
11bf82dfd2d328940589f0fb6131155b53e10f7a
Parents:
0415f923fdb78a69504a400113e65cd371cb2150
Message:
added convex dense factorization to bivariate factorization
added logarithmic derivative computation to facFqBivarUtil
changes to in extension test


git-svn-id: file:///usr/local/Singular/svn/trunk@14242 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/facFqBivarUtil.cc

    r0415f9 rf876a66  
    2525#include "cf_iter.h"
    2626#include "facFqBivarUtil.h"
     27#include "cfNewtonPolygon.h"
     28#include "facHensel.h"
    2729
    2830
     
    4143  for (CFListIterator i= factors; i.hasItem(); i++)
    4244    i.getItem()= N (i.getItem());
    43   return;
     45}
     46
     47void decompress (CFFList& factors, const CFMap& N)
     48{
     49  for (CFFListIterator i= factors; i.hasItem(); i++)
     50    i.getItem()= CFFactor (N (i.getItem().factor()), i.getItem().exp());
    4451}
    4552
     
    113120
    114121static inline
    115 bool FqInExtensionHelper (const CanonicalForm& F, const CanonicalForm& gamma)
     122bool FqInExtensionHelper (const CanonicalForm& F, const CanonicalForm& gamma,
     123                          const CanonicalForm& delta, CFList& source,
     124                          CFList& dest)
    116125{
    117126  bool result= false;
     
    123132      return true;
    124133    else
    125       return result;
     134    {
     135      int pos= findItem (source, F);
     136      if (pos > 0)
     137        return false;
     138      Variable a;
     139      hasFirstAlgVar (F, a);
     140      int bound= ipower (getCharacteristic(), degree (getMipo (a)));
     141      CanonicalForm buf= 1;
     142      for (int i= 1; i < bound; i++)
     143      {
     144        buf *= gamma;
     145        if (buf == F)
     146        {
     147          source.append (buf);
     148          dest.append (power (delta, i));
     149          return false;
     150        }
     151      }
     152      return true;
     153    }
    126154  }
    127155  else
     
    129157    for (CFIterator i= F; i.hasTerms(); i++)
    130158    {
    131       result= FqInExtensionHelper (i.coeff(), gamma);
     159      result= FqInExtensionHelper (i.coeff(), gamma, delta, source, dest);
    132160      if (result == true)
    133161        return result;
     
    138166
    139167bool isInExtension (const CanonicalForm& F, const CanonicalForm& gamma,
    140                     const int k)
     168                    const int k, const CanonicalForm& delta,
     169                    CFList& source, CFList& dest)
    141170{
    142171  bool result;
     
    152181  else
    153182  {
    154     result= FqInExtensionHelper (F, gamma);
     183    result= FqInExtensionHelper (F, gamma, delta, source, dest);
    155184    return result;
    156185  }
     
    191220  if (k > 1)
    192221  {
    193     if (!isInExtension (g, delta, k))
     222    if (!isInExtension (g, gamma, k, delta, source, dest))
    194223    {
    195224      g= GFMapDown (g, k);
     
    199228  else if (k == 1)
    200229  {
    201     if (!isInExtension (g, delta, k));
     230    if (!isInExtension (g, gamma, k, delta, source, dest));
    202231      factors.append (g);
    203232  }
     
    209238  else if (!k && beta != Variable (1))
    210239  {
    211     if (!isInExtension (g, delta, k))
     240    if (!isInExtension (g, gamma, k, delta, source, dest))
    212241    {
    213242      g= mapDown (g, delta, gamma, alpha, source, dest);
     
    245274}
    246275
     276void normalize (CFFList& factors)
     277{
     278  for (CFFListIterator i= factors; i.hasItem(); i++)
     279    i.getItem()= CFFactor (i.getItem().factor()/Lc(i.getItem().factor()),
     280                           i.getItem().exp());
     281  return;
     282}
     283
    247284CFList subset (int index [], const int& s, const CFArray& elements,
    248285               bool& noSubset)
     
    392429}
    393430
     431CFArray
     432logarithmicDerivative (const CanonicalForm& F, const CanonicalForm& G, int l,
     433                       CanonicalForm& Q
     434                      )
     435{
     436  Variable x= Variable (2);
     437  Variable y= Variable (1);
     438  CanonicalForm xToL= power (x, l);
     439  CanonicalForm q,r;
     440  CanonicalForm logDeriv;
     441
     442  q= newtonDiv (F, G, xToL);
     443
     444  logDeriv= mulMod2 (q, deriv (G, y), xToL);
     445
     446  logDeriv= swapvar (logDeriv, x, y);
     447  int j= degree (logDeriv) + 1;
     448  CFArray result= CFArray (j);
     449  for (CFIterator i= logDeriv; i.hasTerms() && !logDeriv.isZero(); i++)
     450  {
     451    if (i.exp() == j - 1)
     452    {
     453      result [j - 1]= swapvar (i.coeff(), x, y);
     454      j--;
     455    }
     456    else
     457    {
     458      for (; i.exp() < j - 1; j--)
     459        result [j - 1]= 0;
     460      result [j - 1]= swapvar (i.coeff(), x, y);
     461      j--;
     462    }
     463  }
     464  for (; j > 0; j--)
     465    result [j - 1]= 0;
     466  Q= q;
     467  return result;
     468}
     469
     470CFArray
     471logarithmicDerivative (const CanonicalForm& F, const CanonicalForm& G, int l,
     472                       int oldL, const CanonicalForm& oldQ, CanonicalForm& Q
     473                      )
     474{
     475  Variable x= Variable (2);
     476  Variable y= Variable (1);
     477  CanonicalForm xToL= power (x, l);
     478  CanonicalForm xToOldL= power (x, oldL);
     479  CanonicalForm xToLOldL= power (x, l-oldL);
     480  CanonicalForm q,r;
     481  CanonicalForm logDeriv;
     482
     483  CanonicalForm bufF= mod (F, xToL);
     484  CanonicalForm oldF= mulMod2 (G, oldQ, xToL);
     485  bufF -= oldF;
     486  bufF= div (bufF, xToOldL);
     487
     488  q= newtonDiv (bufF, G, xToLOldL);
     489  q *= xToOldL;
     490  q += oldQ;
     491
     492  logDeriv= mulMod2 (q, deriv (G, y), xToL);
     493
     494  logDeriv= swapvar (logDeriv, x, y);
     495  int j= degree (logDeriv) + 1;
     496  CFArray result= CFArray (j);
     497  for (CFIterator i= logDeriv; i.hasTerms() && !logDeriv.isZero(); i++)
     498  {
     499    if (i.exp() == j - 1)
     500    {
     501      result [j - 1]= swapvar (i.coeff(), x, y);
     502      j--;
     503    }
     504    else
     505    {
     506      for (; i.exp() < j - 1; j--)
     507        result [j - 1]= 0;
     508      result [j - 1]= swapvar (i.coeff(), x, y);
     509      j--;
     510    }
     511  }
     512  for (; j > 0; j--)
     513    result [j - 1]= 0;
     514  Q= q;
     515  return result;
     516}
     517
     518void
     519writeInMatrix (CFMatrix& M, const CFArray& A, const int column,
     520               const int startIndex
     521              )
     522{
     523  ASSERT (A.size () - startIndex > 0, "wrong starting index");
     524  ASSERT (A.size () - startIndex == M.rows(), "wrong starting index");
     525  ASSERT (column > 0 && column <= M.columns(), "wrong column");
     526  if (A.size() - startIndex <= 0) return;
     527  int j= 1;
     528  for (int i= startIndex; i < A.size(); i++, j++)
     529    M (j, column)= A [i];
     530}
     531
     532CFArray getCoeffs (const CanonicalForm& F, const int k)
     533{
     534  ASSERT (F.isUnivariate(), "univariate input expected");
     535  if (degree (F, 2) < k)
     536    return CFArray();
     537
     538  CFArray result= CFArray (degree (F) - k + 1);
     539  CFIterator j= F;
     540  for (int i= degree (F); i >= k; i--)
     541  {
     542    if (j.exp() == i)
     543    {
     544      result [i - k]= j.coeff();
     545      j++;
     546      if (!j.hasTerms())
     547        return result;
     548    }
     549    else
     550      result[i - k]= 0;
     551  }
     552  return result;
     553}
     554
     555CFArray getCoeffs (const CanonicalForm& F, const int k, const Variable& alpha)
     556{
     557  ASSERT (F.isUnivariate(), "univariate input expected");
     558  if (degree (F, 2) < k)
     559    return CFArray ();
     560
     561  int d= degree (getMipo (alpha));
     562  CFArray result= CFArray ((degree (F) - k + 1)*d);
     563  CFIterator j= F;
     564  CanonicalForm buf;
     565  CFIterator iter;
     566  for (int i= degree (F); i >= k; i--)
     567  {
     568    if (j.exp() == i)
     569    {
     570      iter= j.coeff();
     571      for (int l= degree (j.coeff(), alpha); l >= 0; l--)
     572      {
     573        if (iter.exp() == l)
     574        {
     575          result [(i - k)*d + l]= iter.coeff();
     576          iter++;
     577          if (!iter.hasTerms())
     578            break;
     579        }
     580      }
     581      j++;
     582      if (!j.hasTerms())
     583        return result;
     584    }
     585    else
     586    {
     587      for (int l= 0; l < d; l++)
     588        result[(i - k)*d + l]= 0;
     589    }
     590  }
     591  return result;
     592}
     593
     594#ifdef HAVE_NTL
     595CFArray
     596getCoeffs (const CanonicalForm& G, const int k, const int l, const int degMipo,
     597           const Variable& alpha, const CanonicalForm& evaluation,
     598           const mat_zz_p& M)
     599{
     600  ASSERT (G.isUnivariate(), "univariate input expected");
     601  CanonicalForm F= G (G.mvar() - evaluation, G.mvar());
     602  if (F.isZero())
     603    return CFArray ();
     604
     605  Variable y= Variable (2);
     606  F= F (power (y, degMipo), y);
     607  F= F (y, alpha);
     608  zz_pX NTLF= convertFacCF2NTLzzpX (F);
     609  NTLF.rep.SetLength (l*degMipo);
     610  NTLF.rep= M*NTLF.rep;
     611  NTLF.normalize();
     612  F= convertNTLzzpX2CF (NTLF, y);
     613  int d= degMipo;
     614
     615  if (degree (F, 2) < k)
     616    return CFArray();
     617
     618  CFArray result= CFArray (degree (F) - k + 1);
     619
     620  CFIterator j= F;
     621  for (int i= degree (F); i >= k; i--)
     622  {
     623    if (j.exp() == i)
     624    {
     625      result [i - k]= j.coeff();
     626      j++;
     627      if (!j.hasTerms())
     628        return result;
     629    }
     630    else
     631      result[i - k]= 0;
     632  }
     633  return result;
     634}
     635#endif
     636
     637int * computeBounds (const CanonicalForm& F, int& n)
     638{
     639  n= degree (F, 1);
     640  int* result= new int [n];
     641  int sizeOfNewtonPolygon;
     642  int** newtonPolyg= newtonPolygon (F, sizeOfNewtonPolygon);
     643
     644  int minXIndex= 0, minYIndex= 0, maxXIndex= 0, maxYIndex= 0;
     645  int minX, minY, maxX, maxY;
     646  minX= newtonPolyg [0] [0];
     647  minY= newtonPolyg [0] [1];
     648  maxX= minX;
     649  maxY= minY;
     650  for (int i= 1; i < sizeOfNewtonPolygon; i++)
     651  {
     652    if (minX > newtonPolyg [i] [0])
     653    {
     654      minX= newtonPolyg [i] [0];
     655      minXIndex= i;
     656    }
     657    if (maxX < newtonPolyg [i] [0])
     658    {
     659      maxX= newtonPolyg [i] [0];
     660      maxXIndex= i;
     661    }
     662    if (minY > newtonPolyg [i] [1])
     663    {
     664      minY= newtonPolyg [i] [1];
     665      minYIndex= i;
     666    }
     667    if (maxY < newtonPolyg [i] [1])
     668    {
     669      maxY= newtonPolyg [i] [1];
     670      maxYIndex= i;
     671    }
     672  }
     673
     674  int k= maxX;
     675  bool hitMaxX= false;
     676  for (int i= 0; i < n; i++)
     677  {
     678    if (i + 1 > maxY || i + 1 < minY)
     679    {
     680      result [i]= 0;
     681      continue;
     682    }
     683    int* point= new int [2];
     684    point [0]= k;
     685    point [1]= i + 1;
     686    while (!isInPolygon (newtonPolyg, sizeOfNewtonPolygon, point) && k > 0)
     687    {
     688      k--;
     689      point [0]= k;
     690    }
     691    result [i]= k;
     692    k= maxX;
     693    delete [] point;
     694  }
     695
     696  return result;
     697}
     698
    394699int
    395700substituteCheck (const CanonicalForm& F, const Variable& x)
Note: See TracChangeset for help on using the changeset viewer.