28 template <
class R,
class O>
class MPoly {
32 typedef typename monom_t::coeff_t
coeff_t;
45 MPoly(
int,
const monom_t *);
98 const_iterator
begin ()
const {
return rep.begin(); }
100 const_reverse_iterator
rbegin ()
const {
return rep.rbegin(); }
103 const_iterator
end ()
const {
return rep.end(); }
104 reverse_iterator
rend () {
return rep.rend(); }
105 const_reverse_iterator
rend ()
const {
return rep.rend(); }
130 template <
class R,
class O>
132 for (
int i = 0;
i<s;
i++) *
this += t[
i];
135 template<
class R,
class O>
139 char*
str =
new char[n+2];
141 str[n]=
';'; str[n+1]=
'\0';
152 template<
class R,
class O>
164 template <
class R,
class O>
172 template <
class R,
class O>
176 if (m.GetCoeff()!=(C)0)
177 MPOLYNOMIAL__insert<R,O>(rep, rep.begin(), m);
181 template <
class R,
class O>
184 if (P==0)
return *
this;
185 if (*
this==0) {*
this = P;
return *
this;}
187 MPOLYNOMIAL__plus<R,O>(rep,P.
rep,begin());
191 template <
class R,
class O>
193 if (m.GetCoeff()!=(
typename R::value_type::coeff_t)0){
194 MPOLYNOMIAL__insert<R,O>(rep,rep.begin(),-m);
199 template <
class R,
class O>
203 if (P==0)
return *
this;
204 if (*
this==0) {*
this = -P;
return *
this;}
205 MPOLYNOMIAL__sub<R,O>(rep,P.
rep,begin());
209 template <
class R,
class O>
211 if ( (*
this!=0) && (m.GetCoeff() !=(
typename R::value_type::coeff_t)0) ) {
213 for (iterator
i = P.begin();
i != P.end();
i++) {
216 while (((*i).GetDegree(n) >= m.GetDegree(n) ) && ( n >= 0)) n--;
225 template <
class R,
class O>
229 for (iterator
i = begin();
i != end();
i++) {
237 template <
class R,
class O>
241 for (iterator
i = begin();
i != end();
i++) {
250 template <
class R,
class O>
253 if ( (*
this !=0) && (Q !=0) ) {
256 copy = (&rep == &Q.
rep);
269 for(i=begin();i != end();++
i) (*i)*=(*iQ);
275 for (; iQ != NQ->
end();iQ++) {
277 for (iP = P.
begin(); iP != P.
end(); iP++) {
279 j = MPOLYNOMIAL__insert<R,O>(this->rep,
j,*m);
283 if (copy)
delete(NQ);
289 template <
class R,
class O>
291 if (*
this!=0 && Q!=0){
295 copy = (&rep == &Q.
rep);
302 int n=Q.
begin()->Lvar();
303 if (n<=(*this).begin()->Lvar())
304 while (((*this).begin()->GetDegree(n) >= Q.
begin()->GetDegree(n) ) && ( n >= 0)) n--;
311 (*
this)-=(*((*this).begin()));
316 else (*
this)/= *(Q.
begin());
326 template <
class R,
class O>
inline
330 if (this->rep.empty())
335 if (this->rep.empty())
338 return( this->rep.size()==1 && (*
this -
MPoly<R,O>(n)) ==0);
340 template <
class R,
class O>
inline
346 template <
class R,
class O>
inline
352 template <
class R,
class O>
inline
353 bool operator < (const MPoly<R,O> & P,
const MPoly<R,O> & Q) {
356 while (iP != P.
end() && iQ != Q.
end() && IsComparable(*iP,*iQ)) {
364 return O::less(*iP,*iQ);
367 template <
class R,
class O>
inline
372 template <
class R,
class O>
inline
377 template <
class R,
class O>
inline
378 bool operator <= (const MPoly<R,O> & P,
const MPoly<R,O> & Q){
385 template <
class R,
class O>
inline
391 template <
class R,
class O>
inline
397 template <
class R,
class O>
inline
403 template <
class R,
class O>
inline
409 template <
class R,
class O>
inline
416 template <
class R,
class O>
inline
422 template <
class R,
class O>
inline
427 template <
class R,
class O>
inline
435 template <
class R,
class O>
inline
437 std::string s,ss =
"";
447 ss += s.substr(0,p+1);
451 buf = (
char *)
malloc(
sizeof(
char)*ss.length() +1);
452 strcpy(buf,ss.c_str());
458 template <
class R,
class O>
inline
459 std::ostream & operator << (std::ostream & os, const MPoly<R,O> & P){
463 while ( i != P.
end() )
472 template <
class R,
class O,
class T>
480 if (n & 1) result *= temp;
489 template <
class R,
class O>
494 for(it=P.
begin(); it!=P.
end(); it++) {
501 temp_pol=
pow(Q,t) * temp;
bool operator!=(int n) const
Definition: MPoly.hpp:71
R::value_type monom_t
Definition: MPoly.hpp:31
int size() const
Definition: MPoly.hpp:107
const_iterator end() const
Definition: MPoly.hpp:103
MPOLY * yypol
Definition: parser.hpp:644
MPoly()
Definition: MPoly.hpp:42
R rep
Definition: MPoly.hpp:110
Multivariate polynomials.
Definition: MPoly.hpp:28
M div(const M &m1, const M &m2)
Definition: Monom.hpp:217
iterator end()
Definition: MPoly.hpp:102
MPoly(const self_t &P)
Definition: MPoly.hpp:46
self_t & operator/=(const monom_t &)
reverse_iterator rbegin()
Definition: MPoly.hpp:99
int yyparse(void)
Definition: parser.hpp:701
MPoly< R, O > pow(const MPoly< R, O > &P, T n)
Definition: MPoly.hpp:473
const_reverse_iterator rbegin() const
Definition: MPoly.hpp:100
self_t & operator=(const self_t &)
Definition: MPoly.hpp:165
YY_BUFFER_STATE yy_scan_string(yyconst char *yy_str)
Definition: lex.yy.c:1277
R::iterator iterator
Definition: MPoly.hpp:34
MPoly< R, O > self_t
Definition: MPoly.hpp:39
reverse_iterator rend()
Definition: MPoly.hpp:104
const_reverse_iterator rend() const
Definition: MPoly.hpp:105
R::const_reverse_iterator const_reverse_iterator
Definition: MPoly.hpp:37
MPoly(const int &i)
Definition: MPoly.hpp:49
self_t & operator-=(const monom_t &)
bool operator!=(const MPoly< R, O > &P, const MPoly< R, O > &Q)
Definition: MPoly.hpp:347
bool operator==(int n) const
Definition: MPoly.hpp:327
MPoly< R, O > operator/(const MPoly< R, O > &P, const MPoly< R, O > &Q)
Definition: MPoly.hpp:392
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
monom_t::coeff_t coeff_t
Definition: MPoly.hpp:32
MPoly(const monom_t &m)
Definition: MPoly.hpp:43
MSKCONST char * str
Definition: mosek.h:2317
self_t operator-() const
Definition: MPoly.hpp:386
C coeff_t
Definition: Monom.hpp:26
MPoly< R, O > operator-(const MPoly< R, O > &P, const MPoly< R, O > &Q)
Definition: MPoly.hpp:404
self_t & operator*=(const coeff_t &)
bool operator==(const MPoly< R, O > &P, const MPoly< R, O > &Q)
Definition: MPoly.hpp:341
int leading_var(const MPoly< R, O > &P)
Definition: MPoly.hpp:423
R::reverse_iterator reverse_iterator
Definition: MPoly.hpp:36
int MPOLYNOMIAL__degree(const R &p)
Definition: MPOLYNOMIAL.hpp:99
Mon mon
Definition: solver_bb_floating.cpp:136
MSKrealt * c
Definition: mosek.h:2678
MPoly< R, O > operator*(const MPoly< R, O > &P, const typename MPoly< R, O >::monom_t &m)
Definition: MPoly.hpp:410
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
bool operator>(const MPoly< R, O > &P, const MPoly< R, O > &Q)
Definition: MPoly.hpp:368
int MPOLYNOMIAL__lvar(const R &p)
Definition: MPOLYNOMIAL.hpp:89
MSKrescodee r
Definition: mosek.h:2321
R::const_iterator const_iterator
Definition: MPoly.hpp:35
bool operator>=(const MPoly< R, O > &P, const MPoly< R, O > &Q)
Definition: MPoly.hpp:373
void MPOLYNOMIAL__copy(T &p, const T &q)
Definition: MPOLYNOMIAL.hpp:108
Parser for polynomials.
Definition: parser.hpp:642
MPoly< R, O > operator+(const MPoly< R, O > &P, const MPoly< R, O > &Q)
Definition: MPoly.hpp:398
int Degree(const MPoly< R, O > &P)
Definition: MPoly.hpp:428
self_t & operator+=(const monom_t &)
bool has_positive_sign(const X &x)
Definition: has_sign.hpp:5
MPoly< R, O > subs(MPoly< R, O > P, int i, MPoly< R, O > Q)
Definition: MPoly.hpp:490
MPoly(const coeff_t &c)
Definition: MPoly.hpp:44
iterator begin()
Definition: MPoly.hpp:97
const_iterator begin() const
Definition: MPoly.hpp:98
std::istream & operator>>(std::istream &is, MPoly< R, O > &P)
Definition: MPoly.hpp:436
O order_t
Definition: MPoly.hpp:33