source: git/libpolys/polys/templates/p_Minus_mm_Mult_qq__T.cc @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    p_Minus_mm_Mult_qq__Template.cc
6 *  Purpose: template for p_Minus_m_Mult_q
7 *  Author:  obachman (Olaf Bachmann)
8 *  Created: 8/00
9 *******************************************************************/
10
11/***************************************************************
12 *
13 * Returns:  p - m*q
14 *           Shorter, where Shorter == Length(p) + Length(q) - Length(p - m*q);
15 * Destroys: p
16 * Const:    m, q
17 *
18 ***************************************************************/
19LINKAGE poly p_Minus_mm_Mult_qq__T(poly p, poly m, poly q, int& Shorter, const poly spNoether, const ring r, poly &last)
20{
21  p_Test(p, r);
22  p_Test(q, r);
23  p_LmTest(m, r);
24
25#if PDEBUG > 0
26  int l_debug = pLength(p) + pLength(q);
27#endif
28
29  Shorter = 0;
30  // we are done if q == NULL || m == NULL
31  if (q == NULL || m == NULL) return p;
32
33  spolyrec rp;
34  poly a = &rp,                    // collects the result
35    qm = NULL;                     // stores q*m
36
37
38  number tm = pGetCoeff(m),           // coefficient of m
39    tneg = n_Neg__T(n_Copy__T(tm, r), r),    // - (coefficient of m)
40    tb,                            // used for tm*coeff(a1)
41    tc;                            // used as intermediate number
42
43
44  int shorter = 0;
45  DECLARE_LENGTH(const unsigned long length = r->ExpL_Size);
46  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
47
48  const unsigned long* m_e = m->exp;
49  omBin bin = r->PolyBin;
50
51  if (p == NULL) goto Finish;           // return tneg*q if (p == NULL)
52
53  pAssume(p_GetComp(q, r) == 0 || p_GetComp(m, r) == 0);
54
55  AllocTop:
56  p_AllocBin(qm, bin, r);
57  SumTop:
58  p_MemSum__T(qm->exp, q->exp, m_e, length);
59  p_MemAddAdjust__T(qm, r);
60
61  CmpTop:
62  // compare qm = m*q and p w.r.t. monomial ordering
63  p_MemCmp__T(qm->exp, p->exp, length, ordsgn, goto Equal, goto Greater, goto Smaller );
64
65  Equal:   // qm equals p
66  tb = n_Mult__T(pGetCoeff(q), tm, r);
67#ifdef HAVE_ZERODIVISORS
68  if (!n_IsZero__T(tb,r)) {
69#endif
70  tc = pGetCoeff(p);
71  if (!n_Equal__T(tc, tb, r))
72  {
73    shorter++;
74    tc = n_Sub__T(tc, tb, r);
75    n_Delete__T(&(pGetCoeff(p)), r);
76    pSetCoeff0(p,tc); // adjust coeff of p
77    a = pNext(a) = p; // append p to result and advance p
78    pIter(p);
79  }
80  else
81  { // coeffs are equal, so their difference is 0:
82    shorter += 2;
83    n_Delete__T(&tc, r);
84    p = p_LmFreeAndNext(p, r);
85  }
86#ifdef HAVE_ZERODIVISORS
87  }
88  else
89  { // coeff itself is zero
90    shorter += 1;
91  }
92#endif
93  n_Delete__T(&tb, r);
94  pIter(q);
95  if (q == NULL || p == NULL) goto Finish; // are we done ?
96  // no, so update qm
97  goto SumTop;
98
99
100  Greater:
101#ifdef HAVE_ZERODIVISORS
102  tb = n_Mult__T(pGetCoeff(q), tneg, r);
103  if (!n_IsZero__T(tb,r))
104  {
105#endif
106    pSetCoeff0(qm, n_Mult__T(pGetCoeff(q), tneg, r));
107    a = pNext(a) = qm;       // append qm to result and advance q
108#ifdef HAVE_ZERODIVISORS
109  }
110  else
111  {
112    shorter++;
113  }
114  n_Delete__T(&tb, r);
115#endif
116  pIter(q);
117  if (q == NULL) // are we done?
118  {
119    qm = NULL;
120    goto Finish;
121  }
122  // construct new qm
123  goto AllocTop;
124
125  Smaller:
126  a = pNext(a) = p;// append p to result and advance p
127  pIter(p);
128  if (p == NULL) goto Finish;
129  goto CmpTop;
130
131
132  Finish: // q or p is NULL: Clean-up time
133  if (q == NULL) // append rest of p to result
134  {
135    pNext(a) = p;
136    if (p == NULL) last = a;
137  }
138  else  // append (- m*q) to result
139  {
140    pSetCoeff0(m, tneg);
141    last = a;
142    if (spNoether != NULL)
143    {
144      int ll = 0;
145      pNext(a) = r->p_Procs->pp_Mult_mm_Noether(q, m, spNoether, ll, r, last);
146      shorter += ll;
147    }
148    else
149    {
150      pNext(a) = r->p_Procs->pp_Mult_mm(q, m, r, last);
151#ifdef HAVE_RINGS
152      if (! rField_is_Domain(r))
153      {
154        shorter += pLength(q) - pLength(pNext(a));
155      }
156#endif
157    }
158    pSetCoeff0(m, tm);
159  }
160
161  n_Delete__T(&tneg, r);
162  if (qm != NULL) p_FreeBinAddr(qm, r);
163  Shorter = shorter;
164  p_Test(pNext(&rp), r);
165  return pNext(&rp);
166}
Note: See TracBrowser for help on using the repository browser.