MINT2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
symPolyTerm Class Reference

#include <symPolyTerm.h>

Public Member Functions

 symPolyTerm (const std::vector< int > &pos)
 
 symPolyTerm (int a)
 
 symPolyTerm (int a, int b)
 
 symPolyTerm (int a, int b, int c)
 
 symPolyTerm (int a, int b, int c, int d)
 
 symPolyTerm (int a, int b, int c, int d, int e)
 
 symPolyTerm (int a, int b, int c, int d, int e, int f)
 
 symPolyTerm (const symPolyTerm &other)
 
 ~symPolyTerm ()
 
void print (std::ostream &os=std::cout) const
 
double eval (double x, double y) const
 
double eval (double x, double y, double z) const
 
double eval (double x, double y, double z, double u) const
 
double eval (double x, double y, double z, double u, double v) const
 
double eval (double x, double y, double z, double u, double v, double w) const
 
double eval (const std::vector< double > &x) const
 
double eval (const std::vector< double * > &x) const
 
double eval (const std::vector< const double * > &x) const
 
const std::string & name () const
 

Private Member Functions

bool init ()
 
void makeName ()
 
void makeAllPermutations ()
 

Private Attributes

std::vector< int > _powers
 
std::vector< std::vector< int > > _allPermutations
 
std::string _name
 

Detailed Description

Definition at line 7 of file symPolyTerm.h.

Constructor & Destructor Documentation

◆ symPolyTerm() [1/8]

symPolyTerm::symPolyTerm ( const std::vector< int > &  pos)

Definition at line 10 of file symPolyTerm.cpp.

11  : _powers(pos)
12 {
13  init();
14 }
std::vector< int > _powers
Definition: symPolyTerm.h:8

◆ symPolyTerm() [2/8]

symPolyTerm::symPolyTerm ( int  a)

Definition at line 15 of file symPolyTerm.cpp.

16  : _powers(1)
17 {
18  _powers[0] = a;
19  init();
20 }
std::vector< int > _powers
Definition: symPolyTerm.h:8

◆ symPolyTerm() [3/8]

symPolyTerm::symPolyTerm ( int  a,
int  b 
)

Definition at line 21 of file symPolyTerm.cpp.

22  : _powers(2)
23 {
24  _powers[0] = a;
25  _powers[1] = b;
26  init();
27 }
std::vector< int > _powers
Definition: symPolyTerm.h:8

◆ symPolyTerm() [4/8]

symPolyTerm::symPolyTerm ( int  a,
int  b,
int  c 
)

Definition at line 28 of file symPolyTerm.cpp.

29  : _powers(3)
30 {
31  _powers[0] = a;
32  _powers[1] = b;
33  _powers[2] = c;
34  init();
35 }
std::vector< int > _powers
Definition: symPolyTerm.h:8

◆ symPolyTerm() [5/8]

symPolyTerm::symPolyTerm ( int  a,
int  b,
int  c,
int  d 
)

Definition at line 36 of file symPolyTerm.cpp.

37  : _powers(4)
38 {
39  _powers[0] = a;
40  _powers[1] = b;
41  _powers[2] = c;
42  _powers[3] = d;
43  init();
44 }
std::vector< int > _powers
Definition: symPolyTerm.h:8

◆ symPolyTerm() [6/8]

symPolyTerm::symPolyTerm ( int  a,
int  b,
int  c,
int  d,
int  e 
)

Definition at line 45 of file symPolyTerm.cpp.

46  : _powers(4)
47 {
48  _powers[0] = a;
49  _powers[1] = b;
50  _powers[2] = c;
51  _powers[3] = d;
52  _powers[4] = e;
53  init();
54 }
std::vector< int > _powers
Definition: symPolyTerm.h:8

◆ symPolyTerm() [7/8]

symPolyTerm::symPolyTerm ( int  a,
int  b,
int  c,
int  d,
int  e,
int  f 
)

Definition at line 55 of file symPolyTerm.cpp.

56  : _powers(4)
57 {
58  _powers[0] = a;
59  _powers[1] = b;
60  _powers[2] = c;
61  _powers[3] = d;
62  _powers[4] = e;
63  _powers[5] = f;
64  init();
65 }
std::vector< int > _powers
Definition: symPolyTerm.h:8

◆ symPolyTerm() [8/8]

symPolyTerm::symPolyTerm ( const symPolyTerm other)

Definition at line 67 of file symPolyTerm.cpp.

68  : _powers(other._powers)
70  , _name(other._name)
71 {
72 }
std::vector< int > _powers
Definition: symPolyTerm.h:8
std::string _name
Definition: symPolyTerm.h:12
std::vector< std::vector< int > > _allPermutations
Definition: symPolyTerm.h:10

◆ ~symPolyTerm()

symPolyTerm::~symPolyTerm ( )
inline

Definition at line 29 of file symPolyTerm.h.

29 {}

Member Function Documentation

◆ eval() [1/8]

double symPolyTerm::eval ( double  x,
double  y 
) const

Definition at line 136 of file symPolyTerm.cpp.

136  {
137  static std::vector<const double* > ptrs(2);
138  ptrs[0] = &x;
139  ptrs[1] = &y;
140  return eval(ptrs);
141 }
double eval(double x, double y) const

◆ eval() [2/8]

double symPolyTerm::eval ( double  x,
double  y,
double  z 
) const

Definition at line 142 of file symPolyTerm.cpp.

142  {
143  std::vector<const double* > ptrs(3);
144  ptrs[0] = &x;
145  ptrs[1] = &y;
146  ptrs[2] = &z;
147  return eval(ptrs);
148 }
double eval(double x, double y) const

◆ eval() [3/8]

double symPolyTerm::eval ( double  x,
double  y,
double  z,
double  u 
) const

Definition at line 149 of file symPolyTerm.cpp.

150  {
151  static std::vector<const double* > ptrs(4);
152  ptrs[0] = &x;
153  ptrs[1] = &y;
154  ptrs[2] = &z;
155  ptrs[3] = &u;
156  return eval(ptrs);
157 }
double eval(double x, double y) const

◆ eval() [4/8]

double symPolyTerm::eval ( double  x,
double  y,
double  z,
double  u,
double  v 
) const

Definition at line 158 of file symPolyTerm.cpp.

159  {
160  std::vector<const double* > ptrs(5);
161  ptrs[0] = &x;
162  ptrs[1] = &y;
163  ptrs[2] = &z;
164  ptrs[3] = &u;
165  ptrs[4] = &v;
166  return eval(ptrs);
167 }
double eval(double x, double y) const

◆ eval() [5/8]

double symPolyTerm::eval ( double  x,
double  y,
double  z,
double  u,
double  v,
double  w 
) const

Definition at line 168 of file symPolyTerm.cpp.

169  {
170  static std::vector<const double* > ptrs(6);
171  ptrs[0] = &x;
172  ptrs[1] = &y;
173  ptrs[2] = &z;
174  ptrs[3] = &u;
175  ptrs[4] = &v;
176  ptrs[5] = &w;
177  return eval(ptrs);
178 }
double eval(double x, double y) const

◆ eval() [6/8]

double symPolyTerm::eval ( const std::vector< double > &  x) const

Definition at line 180 of file symPolyTerm.cpp.

180  {
181  if(x.size() != _powers.size()){
182  cout << "symPolyTerm::eval: size mismatch|!!!"
183  << " me: " << _powers.size() << " vs x: " << x.size()
184  << "\n _powers: " << _powers
185  << "\n x: " << x
186  << endl;
187  throw "can't deal with this";
188  }
189 
190  double sum(0);
191  for(unsigned int i = 0; i < _allPermutations.size(); i++){
192  const std::vector<int>& thisPerm(_allPermutations[i]);
193  double prod(1);
194  for(unsigned int j = 0; j < thisPerm.size(); j++){
195  prod *= pow((x[j]), thisPerm[j]);
196  }
197  sum += prod;
198  }
199  return sum;
200 }
std::vector< int > _powers
Definition: symPolyTerm.h:8
std::vector< std::vector< int > > _allPermutations
Definition: symPolyTerm.h:10

◆ eval() [7/8]

double symPolyTerm::eval ( const std::vector< double * > &  x) const

Definition at line 202 of file symPolyTerm.cpp.

202  {
203  if(x.size() != _powers.size()){
204  cout << "symPolyTerm::eval: size mismatch|!!!"
205  << " me: " << _powers.size() << " vs x: " << x.size()
206  << "\n _powers: " << _powers
207  << "\n x: " << x
208  << endl;
209  throw "can't deal with this";
210  }
211 
212  double sum(0);
213  for(unsigned int i = 0; i < _allPermutations.size(); i++){
214  const std::vector<int>& thisPerm(_allPermutations[i]);
215  double prod(1);
216  for(unsigned int j = 0; j < thisPerm.size(); j++){
217  prod *= pow((*(x[j])), thisPerm[j]);
218  }
219  sum += prod;
220  }
221  return sum;
222 }
std::vector< int > _powers
Definition: symPolyTerm.h:8
std::vector< std::vector< int > > _allPermutations
Definition: symPolyTerm.h:10

◆ eval() [8/8]

double symPolyTerm::eval ( const std::vector< const double * > &  x) const

Definition at line 224 of file symPolyTerm.cpp.

224  {
225  if(x.size() != _powers.size()){
226  cout << "symPolyTerm::eval: size mismatch|!!!"
227  << " me: " << _powers.size() << " vs x: " << x.size()
228  << "\n _powers: " << _powers
229  << "\n x: " << x
230  << endl;
231  throw "can't deal with this";
232  }
233 
234  double sum(0);
235  for(unsigned int i = 0; i < _allPermutations.size(); i++){
236  const std::vector<int>& thisPerm(_allPermutations[i]);
237  double prod(1);
238  for(unsigned int j = 0; j < thisPerm.size(); j++){
239  prod *= pow((*(x[j])), thisPerm[j]);
240  }
241  sum += prod;
242  }
243  return sum;
244 }
std::vector< int > _powers
Definition: symPolyTerm.h:8
std::vector< std::vector< int > > _allPermutations
Definition: symPolyTerm.h:10

◆ init()

bool symPolyTerm::init ( )
private

Definition at line 74 of file symPolyTerm.cpp.

74  {
75  makeName();
77  return true;
78 }
void makeAllPermutations()
Definition: symPolyTerm.cpp:87
void makeName()
Definition: symPolyTerm.cpp:80

◆ makeAllPermutations()

void symPolyTerm::makeAllPermutations ( )
private

Definition at line 87 of file symPolyTerm.cpp.

87  {
88 
89  _allPermutations.clear();
90  _allPermutations.push_back(_powers);
91 
92  for(unsigned int i=0; i < _powers.size()-1; i++){
93  for(unsigned int j=i+1; j < _powers.size(); j++){
94  unsigned int n = _allPermutations.size();
95  for(unsigned int k = 0; k < n; k++){
96  std::vector<int> ptemp( _allPermutations[k] );
97  swap(ptemp[i],ptemp[j]);
98  _allPermutations.push_back(ptemp);
99  }
100  }
101  }
102 
103  sort(_allPermutations.begin(), _allPermutations.end());
104 
105  std::vector< std::vector<int> >::iterator
106  lastUnique = unique(_allPermutations.begin(), _allPermutations.end());
107 
108  _allPermutations.erase(lastUnique, _allPermutations.end());
109 
110  return;
111 }
std::vector< int > _powers
Definition: symPolyTerm.h:8
std::vector< std::vector< int > > _allPermutations
Definition: symPolyTerm.h:10

◆ makeName()

void symPolyTerm::makeName ( )
private

Definition at line 80 of file symPolyTerm.cpp.

80  {
81  _name = "";
82  for(unsigned int i=0; i < _powers.size(); i++){
84  }
85 }
std::vector< int > _powers
Definition: symPolyTerm.h:8
std::string _name
Definition: symPolyTerm.h:12
std::string anythingToString(const T &anything)
Definition: Utils.h:62

◆ name()

const std::string& symPolyTerm::name ( ) const
inline

Definition at line 45 of file symPolyTerm.h.

45 {return _name;}
std::string _name
Definition: symPolyTerm.h:12

◆ print()

void symPolyTerm::print ( std::ostream &  os = std::cout) const

Definition at line 114 of file symPolyTerm.cpp.

114  {
115  bool firstTerm(true);
116 
117  // os << " P(x_j; " << name() << " ) = ";
118  for(unsigned int i = 0; i < _allPermutations.size(); i++){
119  if(! firstTerm ) os << " + ";
120  const std::vector<int>& thisPerm(_allPermutations[i]);
121  double thisSum=0;
122  for(unsigned int j = 0; j < thisPerm.size(); j++){
123  thisSum += thisPerm[j];
124  if(0 == j) os << " ";
125  if(0 != thisPerm[j]){
126  os << "x_" << j;
127  if(1 != thisPerm[j]) os << "^" << thisPerm[j];
128  os << " ";
129  firstTerm = false;
130  }
131  }
132  if(0 == thisSum) os << "1 ";
133  }
134 }
std::vector< std::vector< int > > _allPermutations
Definition: symPolyTerm.h:10

Member Data Documentation

◆ _allPermutations

std::vector< std::vector<int> > symPolyTerm::_allPermutations
private

Definition at line 10 of file symPolyTerm.h.

◆ _name

std::string symPolyTerm::_name
private

Definition at line 12 of file symPolyTerm.h.

◆ _powers

std::vector<int> symPolyTerm::_powers
private

Definition at line 8 of file symPolyTerm.h.


The documentation for this class was generated from the following files: