source: git/kernel/p_Minus_mm_Mult_qq__T.cc @ f2f460

spielwiese
Last change on this file since f2f460 was 886483, checked in by Hans Schönemann <hannes@…>, 18 years ago
*hannes: fix shorter git-svn-id: file:///usr/local/Singular/svn/trunk@8946 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.8 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: p_Minus_mm_Mult_qq__T.cc,v 1.4 2006-02-15 13:01:22 Singular Exp $
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_RING2TOM
70  if ((long) tb != 0) {
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_RING2TOM
89  }
90#endif
91  n_Delete(&tb, r);
92  pIter(q);
93  if (q == NULL || p == NULL) goto Finish; // are we done ?
94  // no, so update qm
95  goto SumTop;
96
97
98  Greater:
99#ifdef HAVE_RING2TOM
100  tb = n_Mult(pGetCoeff(q), tneg, r);
101  if ((long) tb != 0)
102  {
103#endif
104  pSetCoeff0(qm, n_Mult(pGetCoeff(q), tneg, r));
105  a = pNext(a) = qm;       // append qm to result and advance q
106#ifdef HAVE_RING2TOM
107  }
108  else
109  { shorter++; }
110  n_Delete(&tb, r);
111#endif 
112  pIter(q);
113  if (q == NULL) // are we done?
114  {
115    qm = NULL;
116    goto Finish;
117  }
118  // construct new qm
119  goto AllocTop;
120
121  Smaller:
122  a = pNext(a) = p;// append p to result and advance p
123  pIter(p);
124  if (p == NULL) goto Finish;
125  goto CmpTop;
126
127
128  Finish: // q or p is NULL: Clean-up time
129  if (q == NULL) // append rest of p to result
130  {
131    pNext(a) = p;
132    if (p == NULL) last = a;
133  }
134  else  // append (- m*q) to result
135  {
136    pSetCoeff0(m, tneg);
137    last = a;
138    if (spNoether != NULL)
139    {
140      int ll = 0;
141      pNext(a) = r->p_Procs->pp_Mult_mm_Noether(q, m, spNoether, ll, r, last);
142      shorter += ll;
143    }
144    else
145      pNext(a) = r->p_Procs->pp_Mult_mm(q, m, r, last);
146    pSetCoeff0(m, tm);
147  }
148
149  n_Delete(&tneg, r);
150  if (qm != NULL) p_FreeBinAddr(qm, r);
151  Shorter = shorter;
152  p_Test(pNext(&rp), r);
153  return pNext(&rp);
154}
Note: See TracBrowser for help on using the repository browser.