MPSolve  3.2.1
formal-monomial.h
Go to the documentation of this file.
1 /*
2  * This file is part of MPSolve 3.2.1
3  *
4  * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5  * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6  *
7  * Authors:
8  * Leonardo Robol <robol@mail.dm.unipi.it>
9  */
10 
20 #ifndef MPS_FORMAL_MONOMIAL_H_
21 #define MPS_FORMAL_MONOMIAL_H_
22 
23 MPS_BEGIN_DECLS
24 
25 struct mps_formal_monomial;
26 
27 typedef struct mps_formal_monomial mps_formal_monomial;
28 
29 mps_formal_monomial * mps_formal_monomial_new_with_string (const char *, long);
30 
31 mps_formal_monomial * mps_formal_monomial_new_with_strings (const char * real, const char * imag,
32  long degree);
33 
34 void mps_formal_monomial_free (mps_formal_monomial*);
35 
36 void mps_formal_monomial_print (mps_formal_monomial*);
37 
38 mps_formal_monomial * mps_formal_monomial_neg (mps_formal_monomial * m);
39 
40 mps_formal_monomial * mps_formal_monomial_mul_eq (mps_formal_monomial * m,
41  mps_formal_monomial * other);
42 
43 mps_formal_monomial * mps_formal_monomial_mul (mps_formal_monomial * m,
44  mps_formal_monomial * other);
45 
46 const char * mps_formal_monomial_get_str(mps_formal_monomial * m);
47 
48 int mps_formal_monomial_degree (mps_formal_monomial *m);
49 
50 MPS_END_DECLS
51 
52 #ifdef __cplusplus
53 
54 #include <iostream>
55 #include <gmpxx.h>
56 
57 namespace mps {
58  namespace formal {
59 
60  class Monomial {
61  public:
62 
67  Monomial();
68 
73  Monomial(const char * coeff_string, long degree);
74 
79  Monomial(const char * real_part, const char * imag_part, long degree);
80 
85  Monomial(const mpq_class coeff, long degree);
86 
91  Monomial(const mpq_class real, const mpq_class imag, long degree);
92 
96  Monomial(const Monomial& rhs);
97 
98  ~Monomial();
99 
103  const long degree() const { return mDegree; }
104 
108  const mpq_class coefficientReal() const { return mCoeffR; }
109 
113  const mpq_class coefficientImag() const { return mCoeffI; }
114 
118  bool isZero() const;
119 
123  bool isReal() const;
124 
128  bool isImag() const;
129 
130  Monomial operator-();
131 
135  Monomial& operator*=(const Monomial& other);
136 
140  Monomial operator*(const Monomial& other) const;
141 
145  friend std::ostream& operator<<(std::ostream& os, const Monomial& l);
146 
147  private:
148  mpq_class mCoeffR;
149  mpq_class mCoeffI;
150 
151  long mDegree;
152  };
153 
154  }
155 }
156 
157 #endif /* ifdef __cplusplus */
158 
159 #endif /* MPS_FORMAL_MONOMIAL_H_ */
160 
Definition: formal-monomial.h:60
Monomial operator*(const Monomial &other) const
Multiply two monomials together.
Definition: formal-monomial.cpp:186
const mpq_class coefficientReal() const
Access the real GMP coefficient stored inside the Monomial.
Definition: formal-monomial.h:108
bool isZero() const
Check if this is the zero monomial.
Definition: formal-monomial.cpp:147
bool isReal() const
Check whether the monomial has a real coefficient.
Definition: formal-monomial.cpp:153
friend std::ostream & operator<<(std::ostream &os, const Monomial &l)
Print a monomial to a stream.
Definition: formal-monomial.cpp:197
bool isImag() const
Check whether the monomial has a real coefficient.
Definition: formal-monomial.cpp:159
const long degree() const
Get the degree of the monomial.
Definition: formal-monomial.h:103
const mpq_class coefficientImag() const
Access the imaginary GMP coefficient stored inside the Monomial.
Definition: formal-monomial.h:113
Monomial()
Create a default Monomial, consisting of the 0 constant with conventional degree -1.
Definition: formal-monomial.cpp:82
Monomial & operator*=(const Monomial &other)
Multiply two monomials together.
Definition: formal-monomial.cpp:173