source: git/kernel/p_Minus_mm_Mult_qq__T.cc @ 76e501

spielwiese
Last change on this file since 76e501 was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • 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 *  Version: $Id$
10 *******************************************************************/
11
12/***************************************************************
13 *
14 * Returns:  p - m*q
15 *           Shorter, where Shorter == Length(p) + Length(q) - Length(p - m*q);
16 * Destroys: p
17 * Const:    m, q
18 *
19 ***************************************************************/
20LINKAGE poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, int& Shorter, const poly spNoether, const ring r, poly &last)
21{
22  p_Test(p, r);
23  p_Test(q, r);
24  p_LmTest(m, r);
25
26#if PDEBUG > 0
27  int l_debug = pLength(p) + pLength(q);
28#endif
29
30  Shorter = 0;
31  // we are done if q == NULL || m == NULL
32  if (q == NULL || m == NULL) return p;
33
34  spolyrec rp;
35  poly a = &rp,                    // collects the result
36    qm = NULL,                     // stores q*m
37    c;                             // used for temporary storage
38
39
40  number tm = pGetCoeff(m),           // coefficient of m
41    tneg = n_Neg(n_Copy(tm, r), r),    // - (coefficient of m)
42    tb,                            // used for tm*coeff(a1)
43    tc;                            // used as intermediate number
44
45
46  int shorter = 0;
47  DECLARE_LENGTH(const unsigned long length = r->ExpL_Size);
48  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
49
50  const unsigned long* m_e = m->exp;
51  omBin bin = r->PolyBin;
52
53  if (p == NULL) goto Finish;           // return tneg*q if (p == NULL)
54
55  pAssume(p_GetComp(q, r) == 0 || p_GetComp(m, r) == 0);
56
57  AllocTop:
58  p_AllocBin(qm, bin, r);
59  SumTop:
60  p_MemSum(qm->exp, q->exp, m_e, length);
61  p_MemAddAdjust(qm, r);
62
63  CmpTop:
64  // compare qm = m*q and p w.r.t. monomial ordering
65  p_MemCmp(qm->exp, p->exp, length, ordsgn, goto Equal, goto Greater, goto Smaller );
66
67  Equal:   // qm equals p
68  tb = n_Mult(pGetCoeff(q), tm, r);
69#ifdef HAVE_ZERODIVISORS
70  if (!nIsZero(tb)) {
71#endif
72  tc = pGetCoeff(p);
73  if (!n_Equal(tc, tb, r))
74  {
75    shorter++;
76    tc = n_Sub(tc, tb, r);
77    n_Delete(&(pGetCoeff(p)), r);
78    pSetCoeff0(p,tc); // adjust coeff of p
79    a = pNext(a) = p; // append p to result and advance p
80    pIter(p);
81  }
82  else
83  { // coeffs are equal, so their difference is 0:
84    shorter += 2;
85    n_Delete(&tc, r);
86    p = p_LmFreeAndNext(p, r);
87  }
88#ifdef HAVE_ZERODIVISORS
89  }
90  else
91  { // coeff itself is zero
92    shorter += 1;
93  }
94#endif
95  n_Delete(&tb, r);
96  pIter(q);
97  if (q == NULL || p == NULL) goto Finish; // are we done ?
98  // no, so update qm
99  goto SumTop;
100
101
102  Greater:
103#ifdef HAVE_ZERODIVISORS
104  tb = n_Mult(pGetCoeff(q), tneg, r);
105  if (!nIsZero(tb))
106  {
107#endif
108    pSetCoeff0(qm, n_Mult(pGetCoeff(q), tneg, r));
109    a = pNext(a) = qm;       // append qm to result and advance q
110#ifdef HAVE_ZERODIVISORS
111  }
112  else
113  {
114    shorter++;
115  }
116  n_Delete(&tb, r);
117#endif
118  pIter(q);
119  if (q == NULL) // are we done?
120  {
121    qm = NULL;
122    goto Finish;
123  }
124  // construct new qm
125  goto AllocTop;
126
127  Smaller:
128  a = pNext(a) = p;// append p to result and advance p
129  pIter(p);
130  if (p == NULL) goto Finish;
131  goto CmpTop;
132
133
134  Finish: // q or p is NULL: Clean-up time
135  if (q == NULL) // append rest of p to result
136  {
137    pNext(a) = p;
138    if (p == NULL) last = a;
139  }
140  else  // append (- m*q) to result
141  {
142    pSetCoeff0(m, tneg);
143    last = a;
144    if (spNoether != NULL)
145    {
146      int ll = 0;
147      pNext(a) = r->p_Procs->pp_Mult_mm_Noether(q, m, spNoether, ll, r, last);
148      shorter += ll;
149    }
150    else
151    {
152      pNext(a) = r->p_Procs->pp_Mult_mm(q, m, r, last);
153#ifdef HAVE_RINGS
154      if (! rField_is_Domain(r))
155      {
156        shorter += pLength(q) - pLength(pNext(a));
157      }
158#endif
159    }
160    pSetCoeff0(m, tm);
161  }
162
163  n_Delete(&tneg, r);
164  if (qm != NULL) p_FreeBinAddr(qm, r);
165  Shorter = shorter;
166  p_Test(pNext(&rp), r);
167  return pNext(&rp);
168}
Note: See TracBrowser for help on using the repository browser.