MINT2
symMultiPolyTerm.cpp
Go to the documentation of this file.
2 #include "Mint/Utils.h"
3 #include <iostream>
4 
5 using namespace std;
6 using namespace MINT;
7 
8 symMultiPolyTerm::symMultiPolyTerm(int dimension, int order)
10 {
11  init(dimension, order);
12 }
14  : MINT::PolymorphVector< symPolyTerm >(other)
15 {
16 }
17 
18 bool symMultiPolyTerm::init(int dimension, int order){
19  return createTerms(dimension, order);
20 }
21 
22 bool symMultiPolyTerm::createTerms(int dimension, int order){
23  bool dbThis=false;
24 
25  std::vector<std::vector<int> > v;
26  createTerms(dimension, order, v);
27 
28  // next: remove duplicates, where we treat e.g. 32 as 23, i.e. order
29  // does not matter. The symPolyTerm then implements 32 as 32, 23, etc
30  // so what we "contract" here is expanded again there - efficient?
31  // ... probably not, but it follows the logic of the setup better.
32  for(unsigned int i=0; i < v.size(); i++) sort((v[i]).rbegin(), (v[i]).rend());
33  sort(v.rbegin(), v.rend());
34  std::vector< std::vector<int> >::iterator
35  lastUnique = unique(v.begin(), v.end());
36  v.erase(lastUnique, v.end());
37 
38  for(unsigned int j=0; j < v.size(); j++){
39  if(dbThis)cout << v[j] << endl;
40  symPolyTerm spt(v[j]);
41  this->push_back(spt);
42  }
43 
44  return true;
45 
46 }
47 bool symMultiPolyTerm::createTerms(int dimension, int order
48  , std::vector<std::vector<int> >& v){
49  if(dimension <=0) return true;
50 
51  std::vector<int> p(dimension,0);
52  p[0]=order;
53  v.push_back(p);
54 
55  for(int od = order-1; od > 0; od--){
56  std::vector<int> p(dimension,0);
57  p[0]=od;
58  std::vector<std::vector<int> > v2;
59  createTerms(dimension-1, order - od, v2);
60  for(unsigned int i=0; i < v2.size(); i++){
61  std::vector<int>& p2(p);
62  std::vector<int>& tv2(v2[i]);
63  for(unsigned int k=0; k < tv2.size() && k + 1 < p2.size(); k++){
64  p2[k+1] = tv2[k];
65  }
66  v.push_back(p2);
67  }
68  }
69  return true;
70 }
71 
72 void symMultiPolyTerm::print(std::ostream& os) const{
73  for(unsigned int i=0; i < this->size(); i++){
74  if(0 != i) os << "\n\t + ";
75  else os << "\t";
76 
77  os << (*this)[i];
78  }
79 }
80 std::ostream& operator<<(std::ostream& os, const symMultiPolyTerm& smpt){
81  smpt.print(os);
82  return os;
83 }
84 
85 
86 //
void push_back(const symPolyTerm &c)
std::ostream & operator<<(std::ostream &os, const symMultiPolyTerm &smpt)
void print(std::ostream &os=std::cout) const
symMultiPolyTerm(int dimension, int order=0)
bool init(int dimension, int order)
bool createTerms(int dimension, int order)