source: git/dyn_modules/callgfanlib/initialReduction.cc @ fa167e

jengelh-datetimespielwiese
Last change on this file since fa167e was fa167e, checked in by Yue Ren <ren@…>, 9 years ago
new: pReduce(poly g, const number p)
  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include <kernel/polys.h>
2#include <libpolys/polys/monomials/p_polys.h>
3#include <singularWishlist.h>
4
5#include <Singular/ipid.h>
6
7/***
8 * changes a polynomial g with the help p-t such that
9 * 1) each term of g has a distinct monomial in x
10 * 2) no term of g has a coefficient divisible by p
11 * in particular, this means that all g_\alpha can be obtained
12 * by reading the coefficients and that g is initially reduced
13 * with respect to p-t
14 **/
15static bool pReduce(poly g, const number p)
16{
17  poly toBeChecked = pNext(g);
18  pNext(g) = NULL; poly gEnd = g;
19  poly gCache;
20
21  number coeff, pPower; int power; poly subst;
22  while(toBeChecked)
23  {
24    for (gCache = g; gCache; pIter(gCache))
25      if (p_LeadmonomDivisibleBy(gCache,toBeChecked,currRing)) break;
26    if (gCache)
27    {
28      n_Power(p,p_GetExp(toBeChecked,1,currRing)-p_GetExp(gCache,1,currRing),&pPower,currRing->cf);
29      coeff = n_Mult(p_GetCoeff(toBeChecked,currRing),pPower,currRing->cf);
30      p_SetCoeff(gCache,n_Add(p_GetCoeff(gCache,currRing),coeff,currRing->cf),currRing);
31      n_Delete(&pPower,currRing->cf); n_Delete(&coeff,currRing->cf);
32      toBeChecked=p_LmDeleteAndNext(toBeChecked,currRing);
33    }
34    else
35    {
36      if (n_DivBy(p_GetCoeff(toBeChecked,currRing),p,currRing->cf))
37      {
38        coeff=n_Div(p_GetCoeff(toBeChecked,currRing),p,currRing->cf);
39        power=1;
40        while (n_DivBy(coeff,p,currRing->cf))
41        {
42          coeff=n_Div(p_GetCoeff(pNext(g),currRing),p,currRing->cf);
43          power++;
44          if (power<1)
45          {
46            WerrorS("pReduce: overflow in exponent");
47            return true;
48          }
49        }
50        subst=p_LmInit(toBeChecked,currRing);
51        p_AddExp(subst,1,power,currRing);
52        p_SetCoeff(subst,coeff,currRing);
53        p_Setm(subst,currRing); pTest(subst);
54        toBeChecked=p_LmDeleteAndNext(toBeChecked,currRing);
55        toBeChecked=p_Add_q(toBeChecked,subst,currRing);
56        pTest(toBeChecked);
57      }
58      else
59      {
60        pNext(gEnd)=toBeChecked;
61        pIter(gEnd); pIter(toBeChecked);
62        pNext(gEnd)=NULL;
63      }
64    }
65  }
66  return false;
67}
68
69#ifndef NDEBUG
70BOOLEAN pReduce(leftv res, leftv args)
71{
72  leftv u = args;
73  if ((u != NULL) && (u->Typ() == POLY_CMD))
74  {
75    poly g; number p = n_Init(3,currRing->cf);
76    omUpdateInfo();
77    Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
78    g = (poly) u->CopyD();
79    pReduce(g,p);
80    p_Delete(&g,currRing);
81    omUpdateInfo();
82    Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
83    g = (poly) u->CopyD();
84    pReduce(g,p);
85    n_Delete(&p,currRing->cf);
86    res->rtyp = POLY_CMD;
87    res->data = (char*) g;
88    return FALSE;
89  }
90  return TRUE;
91}
92#endif //NDEBUG
93
94
95
Note: See TracBrowser for help on using the repository browser.