My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
libpolys
polys
templates
p_Minus_mm_Mult_qq__T.cc
Go to the documentation of this file.
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
***************************************************************/
19
LINKAGE
poly
p_Minus_mm_Mult_qq__T
(poly
p
, poly
m
, poly q,
int
& Shorter,
const
poly spNoether,
const
ring r)
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->cf), r->cf),
// - (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->cf);
67
#ifdef HAVE_ZERODIVISORS
68
if
(!n_IsZero__T(tb,r->cf)) {
69
#endif
70
tc =
pGetCoeff
(
p
);
71
if
(!n_Equal__T(tc, tb, r->cf))
72
{
73
shorter++;
74
tc = n_Sub__T(tc, tb, r->cf);
75
n_Delete__T
(&(
pGetCoeff
(
p
)), r->cf);
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->cf);
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->cf);
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->cf);
103
if
(!n_IsZero__T(tb,r->cf))
104
{
105
#endif
106
pSetCoeff0
(qm, n_Mult__T(
pGetCoeff
(q), tneg, r->cf));
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->cf);
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
}
137
else
// append (- m*q) to result
138
{
139
pSetCoeff0
(
m
, tneg);
140
if
(spNoether !=
NULL
)
141
{
142
int
ll = 0;
143
pNext
(a) = r->p_Procs->pp_Mult_mm_Noether(q,
m
, spNoether, ll, r);
144
shorter += ll;
145
}
146
else
147
{
148
pNext
(a) = r->p_Procs->pp_Mult_mm(q,
m
, r);
149
#ifdef HAVE_ZERODIVISORS
150
if
(!
rField_is_Domain
(r))
151
{
152
shorter +=
pLength
(q) -
pLength
(
pNext
(a));
153
}
154
#endif
155
}
156
pSetCoeff0
(
m
, tm);
157
}
158
159
n_Delete__T
(&tneg, r->cf);
160
if
(qm !=
NULL
)
p_FreeBinAddr
(qm, r);
161
Shorter = shorter;
162
p_Test
(
pNext
(&rp), r);
163
return
pNext
(&rp);
164
}
m
int m
Definition
cfEzgcd.cc:128
p
int p
Definition
cfModGcd.cc:4086
Equal
static BOOLEAN Equal(number a, number b, const coeffs)
Definition
flintcf_Q.cc:381
Greater
static bool Greater(mono_type m1, mono_type m2)
Definition
interpolation.cc:285
length
static BOOLEAN length(leftv result, leftv arg)
Definition
interval.cc:257
LINKAGE
#define LINKAGE
Definition
mod2.h:140
p_FreeBinAddr
#define p_FreeBinAddr(p, r)
Definition
monomials.h:217
p_GetComp
#define p_GetComp(p, r)
Definition
monomials.h:64
pIter
#define pIter(p)
Definition
monomials.h:37
pNext
#define pNext(p)
Definition
monomials.h:36
pSetCoeff0
#define pSetCoeff0(p, n)
Definition
monomials.h:59
p_AllocBin
#define p_AllocBin(p, bin, r)
Definition
monomials.h:210
pGetCoeff
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition
monomials.h:44
pAssume
#define pAssume(cond)
Definition
monomials.h:90
spolyrec
Definition
monomials.h:23
NULL
#define NULL
Definition
omList.c:12
omBin
omBin_t * omBin
Definition
omStructs.h:12
p_Minus_mm_Mult_qq__T
LINKAGE poly p_Minus_mm_Mult_qq__T(poly p, poly m, poly q, int &Shorter, const poly spNoether, const ring r)
Definition
p_Minus_mm_Mult_qq__T.cc:19
n_Delete__T
#define n_Delete__T(n, r)
Definition
p_polys.cc:5055
pLength
static int pLength(poly a)
Definition
p_polys.h:190
p_LmFreeAndNext
static poly p_LmFreeAndNext(poly p, ring)
Definition
p_polys.h:713
p_LmTest
#define p_LmTest(p, r)
Definition
p_polys.h:162
p_Test
#define p_Test(p, r)
Definition
p_polys.h:161
rField_is_Domain
static BOOLEAN rField_is_Domain(const ring r)
Definition
ring.h:493
Generated on
for My Project by
doxygen 1.17.0
for
Singular