1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: p_Inline.cc |
---|
6 | * Purpose: implementation of p_* related inline routines |
---|
7 | * Author: obachman (Olaf Bachmann) |
---|
8 | * Created: 8/00 |
---|
9 | * Version: $Id: p_Inline.cc,v 1.2 2000-09-04 13:39:01 obachman Exp $ |
---|
10 | *******************************************************************/ |
---|
11 | #ifndef P_INLINE_CC |
---|
12 | #define P_INLINE_CC |
---|
13 | |
---|
14 | #if !defined(NO_P_INLINE) || defined(POLYS_IMPL_CC) |
---|
15 | |
---|
16 | #include "polys-impl.h" |
---|
17 | #include "p_Numbers.h" |
---|
18 | |
---|
19 | // returns a copy of p |
---|
20 | P_INLINE poly p_Copy(poly p, const ring r = currRing) |
---|
21 | { |
---|
22 | assume(r != NULL && r->p_Procs != NULL); |
---|
23 | return r->p_Procs->p_Copy(p, r); |
---|
24 | } |
---|
25 | |
---|
26 | // deletes *p, and sets *p to NULL |
---|
27 | P_INLINE void p_Delete(poly *p, const ring r = currRing) |
---|
28 | { |
---|
29 | assume(r != NULL && r->p_Procs != NULL); |
---|
30 | r->p_Procs->p_Delete(p, r); |
---|
31 | } |
---|
32 | |
---|
33 | // returns p+q, destroys p and q |
---|
34 | P_INLINE poly p_Add_q(poly p, poly q, const ring r = currRing) |
---|
35 | { |
---|
36 | int shorter; |
---|
37 | assume(r != NULL && r->p_Procs != NULL); |
---|
38 | return r->p_Procs->p_Add_q(p, q, shorter, r); |
---|
39 | } |
---|
40 | |
---|
41 | // returns p*n, destroys p |
---|
42 | P_INLINE poly p_Mult_nn(poly p, number n, const ring r = currRing) |
---|
43 | { |
---|
44 | assume(r != NULL && r->p_Procs != NULL); |
---|
45 | return r->p_Procs->p_Mult_nn(p, n, r); |
---|
46 | } |
---|
47 | |
---|
48 | // returns p*n, does not destroy p |
---|
49 | P_INLINE poly pp_Mult_nn(poly p, number n, const ring r = currRing) |
---|
50 | { |
---|
51 | assume(r != NULL && r->p_Procs != NULL); |
---|
52 | return r->p_Procs->pp_Mult_nn(p, n, r); |
---|
53 | } |
---|
54 | |
---|
55 | // returns Copy(p)*m, does neither destroy p nor m |
---|
56 | P_INLINE poly pp_Mult_mm(poly p, poly m, const ring r = currRing) |
---|
57 | { |
---|
58 | assume(r != NULL && r->p_Procs != NULL); |
---|
59 | return r->p_Procs->pp_Mult_mm(p, m, NULL, r); |
---|
60 | } |
---|
61 | |
---|
62 | // returns p*m, destroys p, const: m |
---|
63 | P_INLINE poly p_Mult_mm(poly p, poly m, const ring r = currRing) |
---|
64 | { |
---|
65 | assume(r != NULL && r->p_Procs != NULL); |
---|
66 | return r->p_Procs->p_Mult_mm(p, m, r); |
---|
67 | } |
---|
68 | |
---|
69 | // return p - m*Copy(q), destroys p; const: p,m |
---|
70 | P_INLINE poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, const ring r = currRing) |
---|
71 | { |
---|
72 | int shorter; |
---|
73 | assume(r != NULL && r->p_Procs != NULL); |
---|
74 | return r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r); |
---|
75 | } |
---|
76 | // returns -p, destroys p |
---|
77 | P_INLINE poly p_Neg(poly p, const ring r = currRing) |
---|
78 | { |
---|
79 | assume(r != NULL && r->p_Procs != NULL); |
---|
80 | return r->p_Procs->p_Neg(p, r); |
---|
81 | } |
---|
82 | |
---|
83 | extern poly _p_Mult_q(poly p, poly q, const int copy, const ring r); |
---|
84 | // returns p*q, destroys p and q |
---|
85 | P_INLINE poly p_Mult_q(poly p, poly q, const ring r = currRing) |
---|
86 | { |
---|
87 | if (p == NULL) |
---|
88 | { |
---|
89 | r->p_Procs->p_Delete(&q, r); |
---|
90 | return NULL; |
---|
91 | } |
---|
92 | if (q == NULL) |
---|
93 | { |
---|
94 | r->p_Procs->p_Delete(&p, r); |
---|
95 | return NULL; |
---|
96 | } |
---|
97 | |
---|
98 | if (pNext(p) == NULL) |
---|
99 | { |
---|
100 | |
---|
101 | q = r->p_Procs->p_Mult_mm(q, p, r); |
---|
102 | r->p_Procs->p_Delete(&p, r); |
---|
103 | return q; |
---|
104 | } |
---|
105 | |
---|
106 | if (pNext(q) == NULL) |
---|
107 | { |
---|
108 | p = r->p_Procs->p_Mult_mm(p, q, r); |
---|
109 | r->p_Procs->p_Delete(&q, r); |
---|
110 | return p; |
---|
111 | } |
---|
112 | |
---|
113 | return _p_Mult_q(p, q, 0, r); |
---|
114 | } |
---|
115 | // returns p*q, does neither destroy p nor q |
---|
116 | P_INLINE poly pp_Mult_qq(poly p, poly q, const ring r = currRing) |
---|
117 | { |
---|
118 | if (p == NULL || q == NULL) return NULL; |
---|
119 | |
---|
120 | if (pNext(p) == NULL) |
---|
121 | return r->p_Procs->pp_Mult_mm(q, p, NULL, r); |
---|
122 | |
---|
123 | if (pNext(q) == NULL) |
---|
124 | return r->p_Procs->pp_Mult_mm(p, q, NULL, r); |
---|
125 | |
---|
126 | return _p_Mult_q(p, q, 1, r); |
---|
127 | } |
---|
128 | |
---|
129 | // returns p + m*q destroys p, const: q, m |
---|
130 | P_INLINE poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, const ring r=currRing) |
---|
131 | { |
---|
132 | poly res; |
---|
133 | int shorter; |
---|
134 | pSetCoeff0(m, p_nNeg(pGetCoeff(m), r)); |
---|
135 | |
---|
136 | res = r->p_Procs->p_Minus_mm_Mult_qq(p, m, q, shorter, NULL, r); |
---|
137 | pSetCoeff0(m, p_nNeg(pGetCoeff(m), r)); |
---|
138 | return res; |
---|
139 | } |
---|
140 | |
---|
141 | P_INLINE int p_LmCmp(poly p, poly q, const ring r = currRing) |
---|
142 | { |
---|
143 | assume(p != NULL && q != NULL); |
---|
144 | p_LmCmpAction(p, q, r, return 0, return 1, return -1); |
---|
145 | } |
---|
146 | |
---|
147 | #endif // defined(P_INLINE) || defined(POLYS_CC) |
---|
148 | #endif // P_INLINE_CC |
---|
149 | |
---|