Changeset 686ce3 in git for factory/facFqBivarUtil.cc


Ignore:
Timestamp:
Jan 17, 2011, 4:35:50 PM (13 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
da2bd09796fb2e16163e9e0cdb0c34e541a200de
Parents:
54667770cf90dd8ee3b56fbe6b4116e50118c921
Message:
added substitution of x^n->x


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

Legend:

Unmodified
Added
Removed
  • factory/facFqBivarUtil.cc

    r546677 r686ce3  
    389389}
    390390
     391static int
     392substituteCheck (const CanonicalForm& F, const CanonicalForm& G)
     393{
     394  if (F.inCoeffDomain() || G.inCoeffDomain())
     395    return 0;
     396  Variable x= Variable (1);
     397  if (degree (F, x) <= 1 || degree (G, x) <= 1)
     398    return 0;
     399  CanonicalForm f= swapvar (F, F.mvar(), x);
     400  CanonicalForm g= swapvar (G, G.mvar(), x);
     401  int sizef= 0;
     402  int sizeg= 0;
     403  for (CFIterator i= f; i.hasTerms(); i++, sizef++)
     404  {
     405    if (i.exp() == 1)
     406      return 0;
     407  }
     408  for (CFIterator i= g; i.hasTerms(); i++, sizeg++)
     409  {
     410    if (i.exp() == 1)
     411      return 0;
     412  }
     413  int * expf= new int [sizef];
     414  int * expg= new int [sizeg];
     415  int j= 0;
     416  for (CFIterator i= f; i.hasTerms(); i++, j++)
     417  {
     418    expf [j]= i.exp();
     419  }
     420  j= 0;
     421  for (CFIterator i= g; i.hasTerms(); i++, j++)
     422  {
     423    expg [j]= i.exp();
     424  }
     425
     426  int indf= sizef - 1;
     427  int indg= sizeg - 1;
     428  if (expf[indf] == 0)
     429    indf--;
     430  if (expg[indg] == 0)
     431    indg--;
     432
     433  if ((expg[indg]%expf [indf] != 0 && expf[indf]%expg[indg] != 0) ||
     434      (expg[indg] == 1 && expf[indf] == 1))
     435  {
     436    delete [] expg;
     437    delete [] expf;
     438    return 0;
     439  }
     440
     441  int result;
     442  if (expg [indg]%expf [indf] == 0)
     443    result= expf[indf];
     444  else
     445    result= expg[indg];
     446  for (int i= indf - 1; i >= 0; i--)
     447  {
     448    if (expf [i]%result != 0)
     449    {
     450      delete [] expf;
     451      delete [] expg;
     452      return 0;
     453    }
     454  }
     455
     456  for (int i= indg - 1; i >= 0; i--)
     457  {
     458    if (expg [i]%result != 0)
     459    {
     460      delete [] expf;
     461      delete [] expg;
     462      return 0;
     463    }
     464  }
     465
     466  delete [] expg;
     467  delete [] expf;
     468  return result;
     469}
     470
     471int recSubstituteCheck (const CanonicalForm& F, const int d)
     472{
     473  if (F.inCoeffDomain())
     474    return 0;
     475  Variable x= Variable (1);
     476  if (degree (F, x) <= 1)
     477    return 0;
     478  CanonicalForm f= swapvar (F, F.mvar(), x);
     479  int sizef= 0;
     480  for (CFIterator i= f; i.hasTerms(); i++, sizef++)
     481  {
     482    if (i.exp() == 1)
     483      return 0;
     484  }
     485  int * expf= new int [sizef];
     486  int j= 0;
     487  for (CFIterator i= f; i.hasTerms(); i++, j++)
     488  {
     489    expf [j]= i.exp();
     490  }
     491
     492  int indf= sizef - 1;
     493  if (expf[indf] == 0)
     494    indf--;
     495
     496  if ((d%expf [indf] != 0 && expf[indf]%d != 0) || (expf[indf] == 1))
     497  {
     498    delete [] expf;
     499    return 0;
     500  }
     501
     502  int result;
     503  if (d%expf [indf] == 0)
     504    result= expf[indf];
     505  else
     506    result= d;
     507  for (int i= indf - 1; i >= 0; i--)
     508  {
     509    if (expf [i]%result != 0)
     510    {
     511      delete [] expf;
     512      return 0;
     513    }
     514  }
     515
     516  delete [] expf;
     517  return result;
     518}
     519
     520int substituteCheck (const CFList& L)
     521{
     522  ASSERT (L.length() > 1, "expected a list of at least two elements");
     523  if (L.length() < 2)
     524    return 0;
     525  CFListIterator i= L;
     526  i++;
     527  int result= substituteCheck (L.getFirst(), i.getItem());
     528  if (result <= 1)
     529    return result;
     530  i++;
     531  for (;i.hasItem(); i++)
     532  {
     533    result= recSubstituteCheck (i.getItem(), result);
     534    if (result <= 1)
     535      return result;
     536  }
     537  return result;
     538}
     539
     540void
     541subst (const CanonicalForm& F, CanonicalForm& A, const int d, const Variable& x)
     542{
     543  if (d <= 1)
     544  {
     545    A= F;
     546    return;
     547  }
     548  if (degree (F, x) <= 0)
     549  {
     550    A= F;
     551    return;
     552  }
     553  CanonicalForm C= 0;
     554  CanonicalForm f= swapvar (F, x, F.mvar());
     555  for (CFIterator i= f; i.hasTerms(); i++)
     556    C += i.coeff()*power (f.mvar(), i.exp()/ d);
     557  A= swapvar (C, x, F.mvar());
     558}
     559
     560CanonicalForm
     561reverseSubst (const CanonicalForm& F, const int d, const Variable& x)
     562{
     563  if (d <= 1)
     564    return F;
     565  if (degree (F, x) <= 0)
     566    return F;
     567  CanonicalForm f= swapvar (F, x, F.mvar());
     568  CanonicalForm result= 0;
     569  for (CFIterator i= f; i.hasTerms(); i++)
     570    result += i.coeff()*power (f.mvar(), d*i.exp());
     571  return swapvar (result, x, F.mvar());
     572}
     573
     574void
     575reverseSubst (CFList& L, const int d, const Variable& x)
     576{
     577  for (CFListIterator i= L; i.hasItem(); i++)
     578    i.getItem()= reverseSubst (i.getItem(), d, x);
     579}
     580
Note: See TracChangeset for help on using the changeset viewer.