flavour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
multivector.h
Go to the documentation of this file.
1 #include <stdarg.h>
2 #include <vector>
3 
4 namespace std{
5 
7 template < class T, int N>
8 class multivector: public vector< multivector<T, N-1> >{
9 public:
10  typedef vector< multivector< T,N-1> > v;
11 
13  multivector(): v() {}
15  multivector(const multivector& m): v(m){}
17 
22 multivector(const T& value, ...){
23  va_list listPointer;
24  va_start(listPointer,value);
25  int n=va_arg(listPointer,int);
26  v::insert(v::begin(),n,multivector<T,N-1>(value,listPointer));
27  va_end(listPointer);
28  }
29 
31 
34 multivector(const T& value, va_list & listPointer)
35  {
36  int n=va_arg(listPointer,int);
37  v::insert(v::begin(),n,multivector<T,N-1>(value,listPointer));
38  }
39 
40 };
41 
43 
45 template< class T >
46 class multivector<T,1>: public vector<T>{
47 public:
48  typedef vector< T > v;
50  multivector(): v() {}
52  multivector(const multivector& m): v(m){}
54 
57  multivector(const T& value, int x): v(x,value){}
59 
63  multivector(const T& value, va_list & listPointer):
64  v(va_arg(listPointer,int), value){}
65 };
66 
67 class Matrix: public multivector< ex, 2>{
68 public:
69 
70 Matrix(): multivector< ex,2>(0,3,3) {}
71 
72 Matrix(const Matrix& m): multivector< ex,2>(m) {}
74 Matrix(const char * m[3][3]): multivector< ex,2>(0,3,3){
75  for(uint i=0;i<3;i++)
76  for(uint j=0;j<3;j++) at(i)[j]=symbol(m[i][j]);
77  }
79 Matrix(const char * name,const char ** index1, const char ** index2): multivector< ex,2>(0,3,3){
80  for(uint i=0;i<3;i++)
81  for(uint j=0;j<3;j++){
82  string res=string(name)+"_{"+string(index1[i])+" "+string(index2[j])+"}";
83  //cout<<res<<endl;
84  at(i)[j]=symbol(res.c_str());
85  }
86  }
88 Matrix(ex m1, ex m2, ex m3): multivector< ex,2>(0,3,3) {
89  at(0)[0]=m1;
90  at(1)[1]=m2;
91  at(2)[2]=m3;
92 }
93 
95 Matrix(ex m1): multivector< ex,2>(0,3,3){
96  Matrix();
97  at(0)[0]=m1;
98  at(1)[1]=m1;
99  at(2)[2]=m1;
100  }
102 Matrix(ex t12, ex t13, ex t23, ex d13): multivector< ex,2>(0,3,3) {
103  Matrix();
104  ex c12=cos(t12), c13=cos(t13), c23=cos(t23);
105  ex s12=sin(t12), s13=sin(t13), s23=sin(t23);
106  ex e13=exp(I*d13);
107  ex e13t=ex(1)/e13;
108 
109  ex aux[3][3]={
110  {c12*c13,s12*c13,s13*e13t},
111  {-s12*c23-c12*s23*s13*e13,c12*c23-s12*s23*s13*e13,s23*c13},
112  {s12*s23-c12*c23*s13*e13,-c12*s23-s12*c23*s13*e13,c13*c23}
113  };
114  for(uint i=0;i<3; i++) at(i).assign(aux[i],aux[i]+3);
115  }
117 ex cs(ex t12){
118  return (exp(I*t12)+1/exp(I*t12))/2;
119  }
121 ex sn(ex t12){
122  return -I*(exp(I*t12)-1/exp(I*t12))/2;
123  }
125 Matrix conjugate() const {
126  Matrix res;
127  for(uint i=0;i<3;i++)
128  for(uint j=0;j<3;j++)
129  res[i][j]=at(j)[i].conjugate();
130 
131  return res;
132 }
133 };
134 
136 Matrix operator*(const Matrix & m1,const Matrix & m2){
137  Matrix res;
138  for(uint i=0;i<3;i++)
139  for(uint j=0;j<3;j++)
140  for(uint k=0;k<3;k++)
141  res[i][j]=res[i][j]+m1[i][k]*m2[k][j];
142  return res;
143 }
144 
146 Matrix operator+(const Matrix & m1,const Matrix & m2){
147  Matrix res;
148  for(uint i=0;i<3;i++)
149  for(uint j=0;j<3;j++)
150  res[i][j]=m1[i][j]+m2[i][j];
151  return res;
152 }
153 
154 
155 
156 }
Matrix(ex m1, ex m2, ex m3)
constructs a diagonal matrix
Definition: multivector.h:88
Matrix conjugate() const
computes the hermitian conjugate of the matrix
Definition: multivector.h:125
Matrix operator*(const Matrix &m1, const Matrix &m2)
computes the matrix product
Definition: multivector.h:136
multivector(const T &value, va_list &listPointer)
Auxiliary constructor (recursive)
Definition: multivector.h:34
A vector of vectors of vectors of... (N times) of class T objects.
Definition: multivector.h:8
Definition: multivector.h:4
multivector(const multivector &m)
Copy constructor.
Definition: multivector.h:15
Matrix(ex t12, ex t13, ex t23, ex d13)
constructs a unitary matrix in the standard form
Definition: multivector.h:102
unsigned int uint
Definition: script.cpp:4
multivector(const multivector &m)
Copy constructor.
Definition: multivector.h:52
Matrix(const char *name, const char **index1, const char **index2)
constructs a symbolic matrix with the symbols names given by the arguments
Definition: multivector.h:79
Matrix(ex m1)
constructs a diagonal matrix with all diagonal elements equal
Definition: multivector.h:95
multivector()
Default constructor.
Definition: multivector.h:50
multivector()
Default constructor.
Definition: multivector.h:13
Matrix(const char *m[3][3])
constructs a symbolic matrix with the symbols names given by the argument
Definition: multivector.h:74
multivector(const T &value, va_list &listPointer)
Auxiliary constructor.
Definition: multivector.h:63
multivector(const T &value,...)
Recommended constructor.
Definition: multivector.h:22
Matrix(const Matrix &m)
Definition: multivector.h:72
ex sn(ex t12)
used in the unitary constructor
Definition: multivector.h:121
vector< multivector< T, N-1 > > v
Definition: multivector.h:10
ex cs(ex t12)
used in the unitary constructor
Definition: multivector.h:117
multivector(const T &value, int x)
Recommended constructor.
Definition: multivector.h:57
Matrix operator+(const Matrix &m1, const Matrix &m2)
computes the matrix sum
Definition: multivector.h:146