Add sinwave, fft and fft2d examples.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / normalize / mterm.hh
1 #ifndef __MTERM__
2 #define __MTERM__
3
4 #include <stdio.h>
5 #include <assert.h>
6 #include "tlib.hh"
7 #include "signals.hh"
8 #include "sigprint.hh"
9 #include "simplify.hh"
10 #include "normalize.hh"
11 #include "sigorderrules.hh"
12 #include <map>
13 #include <list>
14
15 using namespace std;
16
17 /**
18 * Implements a multiplicative term, a term of type
19 * k*x^n*y^m*... and its arithmetic
20 */
21 class mterm
22 {
23
24 Tree fCoef; ///< constant part of the term (usually 1 or -1)
25 map<Tree,int> fFactors; ///< non constant terms and their power
26
27 public:
28 mterm (); ///< create a 0 mterm
29 mterm (int k); ///< create a simple integer mterm
30 mterm (double k); ///< create a simple float mterm
31 mterm (Tree t); ///< create a mterm from a multiplicative exp
32 mterm (const mterm& m); ///< create a copy of a mterm
33
34 void cleanup(); ///< remove usued factors
35 bool isNotZero() const; ///< true if mterm doesn't represent number 0
36 bool isNegative() const; ///< true if mterm has a negative coefficient
37
38 const mterm& operator = (const mterm& m); ///< replace the content with a copy of m
39
40 const mterm& operator *= (Tree m); ///< multiply in place by a multiplicative exp
41 const mterm& operator /= (Tree m); ///< divide in place by a multiplicative exp
42
43 const mterm& operator += (const mterm& m); ///< add in place an mterm of same signature
44 const mterm& operator -= (const mterm& m); ///< add in place an mterm of same signature
45
46 const mterm& operator *= (const mterm& m); ///< multiply in place by a mterm
47 const mterm& operator /= (const mterm& m); ///< divide in place by a mterm
48
49 mterm operator * (const mterm& m) const; ///< mterms multiplication
50 mterm operator / (const mterm& m) const; ///< mterms division
51 ostream& print(ostream& dst) const; ///< print a mterm k*x1**n1*x2**n2...
52
53 int complexity() const; ///< return an evaluation of the complexity
54 Tree normalizedTree(bool sign=false,
55 bool neg=false) const; ///< return the normalized tree of the mterm
56 Tree signatureTree() const; ///< return a signature (a normalized tree)
57
58 bool hasDivisor (const mterm& n) const; ///< return true if this can be divided by n
59 friend mterm gcd (const mterm& m1, const mterm& m2); /// greatest common divisor of two mterms
60 };
61
62 inline ostream& operator << (ostream& s, const mterm& m) { return m.print(s); }
63
64
65 #endif