glucat  0.8.2
matrix_multi.h
Go to the documentation of this file.
1 #ifndef _GLUCAT_MATRIX_MULTI_H
2 #define _GLUCAT_MATRIX_MULTI_H
3 /***************************************************************************
4  GluCat : Generic library of universal Clifford algebra templates
5  matrix_multi.h : Declare a class for the matrix representation of a multivector
6  -------------------
7  begin : Sun 2001-12-09
8  copyright : (C) 2001-2016 by Paul C. Leopardi
9  ***************************************************************************
10 
11  This library is free software: you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with this library. If not, see <http://www.gnu.org/licenses/>.
23 
24  ***************************************************************************
25  This library is based on a prototype written by Arvind Raja and was
26  licensed under the LGPL with permission of the author. See Arvind Raja,
27  "Object-oriented implementations of Clifford algebras in C++: a prototype",
28  in Ablamowicz, Lounesto and Parra (eds.)
29  "Clifford algebras with numeric and symbolic computations", Birkhauser, 1996.
30  ***************************************************************************
31  See also Arvind Raja's original header comments in glucat.h
32  ***************************************************************************/
33 
34 #include "glucat/global.h"
35 #include "glucat/errors.h"
36 #include "glucat/index_set.h"
38 #include "glucat/framed_multi.h"
39 
40 #include <boost/numeric/ublas/fwd.hpp>
41 
42 #include <fstream>
43 #include <string>
44 #include <utility>
45 #include <vector>
46 
47 namespace glucat
48 {
49  namespace ublas = boost::numeric::ublas;
50 
51  // Forward declarations for friends
52 
53  template< typename Scalar_T, const index_t LO, const index_t HI >
54  class framed_multi; // forward
55 
56  template< typename Scalar_T, const index_t LO, const index_t HI >
57  class matrix_multi; // forward
58 
60  template< typename Scalar_T, const index_t LO, const index_t HI >
61  const matrix_multi<Scalar_T,LO,HI>
62  operator* (const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs);
63 
65  template< typename Scalar_T, const index_t LO, const index_t HI >
66  const matrix_multi<Scalar_T,LO,HI>
67  operator^ (const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs);
68 
70  template< typename Scalar_T, const index_t LO, const index_t HI >
71  const matrix_multi<Scalar_T,LO,HI>
72  operator& (const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs);
73 
75  template< typename Scalar_T, const index_t LO, const index_t HI >
76  const matrix_multi<Scalar_T,LO,HI>
77  operator% (const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs);
78 
80  template< typename Scalar_T, const index_t LO, const index_t HI >
81  Scalar_T
82  star(const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs);
83 
85  template< typename Scalar_T, const index_t LO, const index_t HI >
86  const matrix_multi<Scalar_T,LO,HI>
87  operator/ (const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs);
88 
90  template< typename Scalar_T, const index_t LO, const index_t HI >
91  const matrix_multi<Scalar_T,LO,HI>
92  operator| (const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs);
93 
95  template< typename Scalar_T, const index_t LO, const index_t HI >
96  std::istream&
97  operator>> (std::istream& s, matrix_multi<Scalar_T,LO,HI>& val);
98 
100  template< typename Scalar_T, const index_t LO, const index_t HI >
101  std::ostream&
102  operator<< (std::ostream& os, const matrix_multi<Scalar_T,LO,HI>& val);
103 
105  template< typename Scalar_T, const index_t LO, const index_t HI >
106  const index_set<LO,HI>
107  reframe (const matrix_multi<Scalar_T,LO,HI>& lhs, const matrix_multi<Scalar_T,LO,HI>& rhs,
108  matrix_multi<Scalar_T,LO,HI>& lhs_reframed, matrix_multi<Scalar_T,LO,HI>& rhs_reframed);
109 
111  template< typename Scalar_T, const index_t LO, const index_t HI >
112  const matrix_multi<Scalar_T,LO,HI>
113  sqrt(const matrix_multi<Scalar_T,LO,HI>& val, const matrix_multi<Scalar_T,LO,HI>& i, bool prechecked);
114 
116  template< typename Scalar_T, const index_t LO, const index_t HI >
117  const matrix_multi<Scalar_T,LO,HI>
118  matrix_sqrt(const matrix_multi<Scalar_T,LO,HI>& val, const matrix_multi<Scalar_T,LO,HI>& i);
119 
121  template< typename Scalar_T, const index_t LO, const index_t HI >
122  const matrix_multi<Scalar_T,LO,HI>
123  log(const matrix_multi<Scalar_T,LO,HI>& val, const matrix_multi<Scalar_T,LO,HI>& i, bool prechecked);
124 
126  template< typename Scalar_T, const index_t LO, const index_t HI >
127  const matrix_multi<Scalar_T,LO,HI>
128  matrix_log(const matrix_multi<Scalar_T,LO,HI>& val, const matrix_multi<Scalar_T,LO,HI>& i);
129 
131  template< typename Scalar_T = double, const index_t LO = DEFAULT_LO, const index_t HI = DEFAULT_HI >
132  class matrix_multi :
133  public clifford_algebra< Scalar_T, index_set<LO,HI>, matrix_multi<Scalar_T,LO,HI> >
134  {
135  public:
138  typedef Scalar_T scalar_t;
140  typedef std::pair<const index_set_t, Scalar_T> term_t;
141  typedef std::vector<Scalar_T> vector_t;
144  template< typename Other_Scalar_T, const index_t Other_LO, const index_t Other_HI >
145  friend class framed_multi;
146  template< typename Other_Scalar_T, const index_t Other_LO, const index_t Other_HI >
147  friend class matrix_multi;
148 
149  private:
150  typedef ublas::row_major orientation_t;
151  typedef ublas::compressed_matrix< int, orientation_t >
153 #if defined(_GLUCAT_USE_DENSE_MATRICES)
154  typedef ublas::matrix< Scalar_T, orientation_t > matrix_t;
155 #else
156  typedef ublas::compressed_matrix< Scalar_T, orientation_t >
158 #endif
159  typedef typename matrix_t::size_type matrix_index_t;
160 
161  public:
163  static const std::string classname();
167  matrix_multi();
169  template< typename Other_Scalar_T >
172  template< typename Other_Scalar_T >
174  const index_set_t frm, const bool prechecked = false);
176  matrix_multi(const multivector_t& val,
177  const index_set_t frm, const bool prechecked = false);
179  matrix_multi(const index_set_t ist, const Scalar_T& crd = Scalar_T(1));
181  matrix_multi(const index_set_t ist, const Scalar_T& crd,
182  const index_set_t frm, const bool prechecked = false);
184  matrix_multi(const Scalar_T& scr, const index_set_t frm = index_set_t());
186  matrix_multi(const int scr, const index_set_t frm = index_set_t());
188  matrix_multi(const vector_t& vec,
189  const index_set_t frm, const bool prechecked = false);
191  matrix_multi(const std::string& str);
193  matrix_multi(const std::string& str,
194  const index_set_t frm, const bool prechecked = false);
196  matrix_multi(const char* str)
197  { *this = matrix_multi(std::string(str)); };
199  matrix_multi(const char* str,
200  const index_set_t frm, const bool prechecked = false)
201  { *this = matrix_multi(std::string(str), frm, prechecked); };
203  template< typename Other_Scalar_T >
206  template< typename Other_Scalar_T >
208  const index_set_t frm, const bool prechecked = false);
210  const matrix_multi_t fast_matrix_multi(const index_set_t frm) const;
212  template< typename Other_Scalar_T >
214 
215  private:
217  template< typename Matrix_T >
218  matrix_multi(const Matrix_T& mtx, const index_set_t frm);
220  matrix_multi(const matrix_t& mtx, const index_set_t frm);
222  const basis_matrix_t basis_element(const index_set<LO,HI>& ist) const;
223 
224  public:
226 
229 
231  static const matrix_multi_t random(const index_set_t frm, Scalar_T fill = Scalar_T(1));
232 
233  // Friend declarations
234 
235  friend const matrix_multi_t
236  operator* <>(const matrix_multi_t& lhs, const matrix_multi_t& rhs);
237  friend const matrix_multi_t
238  operator^ <>(const matrix_multi_t& lhs, const matrix_multi_t& rhs);
239  friend const matrix_multi_t
240  operator& <>(const matrix_multi_t& lhs, const matrix_multi_t& rhs);
241  friend const matrix_multi_t
242  operator% <>(const matrix_multi_t& lhs, const matrix_multi_t& rhs);
243  friend Scalar_T
244  star <>(const matrix_multi_t& lhs, const matrix_multi_t& rhs);
245  friend const matrix_multi_t
246  operator/ <>(const matrix_multi_t& lhs, const matrix_multi_t& rhs);
247  friend const matrix_multi_t
248  operator| <>(const matrix_multi_t& lhs, const matrix_multi_t& rhs);
249 
250  friend std::istream&
251  operator>> <>(std::istream& s, multivector_t& val);
252  friend std::ostream&
253  operator<< <>(std::ostream& os, const multivector_t& val);
254  friend std::ostream&
255  operator<< <>(std::ostream& os, const term_t& term);
256 
257  template< typename Other_Scalar_T, const index_t Other_LO, const index_t Other_HI >
258  friend const index_set<Other_LO,Other_HI>
261  template< typename Other_Scalar_T, const index_t Other_LO, const index_t Other_HI >
264  template< typename Other_Scalar_T, const index_t Other_LO, const index_t Other_HI >
267 
269  multivector_t& operator+= (const term_t& rhs);
270 
271  private:
272  // Data members
273 
278  };
279 
280  // Non-members
281 
283  template< typename Scalar_T, const index_t LO, const index_t HI >
285  exp(const matrix_multi<Scalar_T,LO,HI>& val);
286 
287 }
288 
289 namespace std
290 {
292  template <typename Scalar_T, const glucat::index_t LO, const glucat::index_t HI>
293  struct numeric_limits< glucat::matrix_multi<Scalar_T,LO,HI> > :
294  public numeric_limits<Scalar_T>
295  { };
296 }
297 #endif // _GLUCAT_MATRIX_MULTI_H
const framed_multi< Other_Scalar_T, LO, HI > fast_framed_multi() const
Use inverse generalized FFT to construct a framed_multi_t.
std::vector< Scalar_T > vector_t
Definition: matrix_multi.h:141
Scalar_T star(const Multivector< Scalar_T, LO, HI > &lhs, const RHS< Scalar_T, LO, HI > &rhs)
Hestenes scalar product.
static const matrix_multi_t random(const index_set_t frm, Scalar_T fill=Scalar_T(1))
Random multivector within a frame.
const Multivector< Scalar_T, LO, HI > sqrt(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Square root of multivector with specified complexifier.
const Multivector< Scalar_T, LO, HI > operator/(const Multivector< Scalar_T, LO, HI > &lhs, const Scalar_T &scr)
Quotient of multivector and scalar.
ublas::row_major orientation_t
Definition: matrix_multi.h:150
const Multivector< Scalar_T, LO, HI > operator*(const Multivector< Scalar_T, LO, HI > &lhs, const Scalar_T &scr)
Product of multivector and scalar.
A framed_multi<Scalar_T,LO,HI> is a framed approximation to a multivector.
Definition: framed_multi.h:65
const Multivector< Scalar_T, LO, HI > log(const Multivector< Scalar_T, LO, HI > &val, const Multivector< Scalar_T, LO, HI > &i, const bool prechecked=false)
Natural logarithm of multivector with specified complexifier.
_GLUCAT_CLIFFORD_ALGEBRA_OPERATIONS multivector_t & operator=(const multivector_t &rhs)
Assignment operator.
const matrix_multi_t fast_matrix_multi(const index_set_t frm) const
Use generalized FFT to construct a matrix_multi_t.
matrix_multi multivector_t
Definition: matrix_multi.h:136
index_set_t m_frame
Index set representing the frame for the subalgebra which contains the multivector.
Definition: matrix_multi.h:275
A matrix_multi<Scalar_T,LO,HI> is a matrix approximation to a multivector.
Definition: framed_multi.h:68
const basis_matrix_t basis_element(const index_set< LO, HI > &ist) const
Create a basis element matrix within the current frame.
const Multivector< Scalar_T, LO, HI > operator^(const Multivector< Scalar_T, LO, HI > &lhs, const RHS< Scalar_T, LO, HI > &rhs)
Outer product.
index_set< LO, HI > index_set_t
Definition: matrix_multi.h:139
std::pair< const index_set_t, Scalar_T > term_t
Definition: matrix_multi.h:140
const framed_multi< Scalar_T, LO, HI > exp(const framed_multi< Scalar_T, LO, HI > &val)
Exponential of multivector.
const matrix_multi< Scalar_T, LO, HI > matrix_log(const matrix_multi< Scalar_T, LO, HI > &val, const matrix_multi< Scalar_T, LO, HI > &i)
Natural logarithm of multivector with specified complexifier.
error< multivector_t > error_t
Definition: matrix_multi.h:142
friend const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > matrix_log(const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &val, const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &i)
const Multivector< Scalar_T, LO, HI > operator%(const Multivector< Scalar_T, LO, HI > &lhs, const RHS< Scalar_T, LO, HI > &rhs)
Left contraction.
ublas::compressed_matrix< Scalar_T, orientation_t > matrix_t
Definition: matrix_multi.h:157
Specific exception class.
Definition: errors.h:57
friend const index_set< Other_LO, Other_HI > reframe(const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &lhs, const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &rhs, matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &lhs_reframed, matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &rhs_reframed)
framed_multi< Scalar_T, LO, HI > framed_multi_t
Definition: matrix_multi.h:143
matrix_t::size_type matrix_index_t
Definition: matrix_multi.h:159
const index_set< LO, HI > reframe(const matrix_multi< Scalar_T, LO, HI > &lhs, const matrix_multi< Scalar_T, LO, HI > &rhs, matrix_multi< Scalar_T, LO, HI > &lhs_reframed, matrix_multi< Scalar_T, LO, HI > &rhs_reframed)
Find a common frame for operands of a binary operator.
friend const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > matrix_sqrt(const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &val, const matrix_multi< Other_Scalar_T, Other_LO, Other_HI > &i)
matrix_multi(const char *str)
Construct a multivector from a char*: eg: "3+2{1,2}-6.1e-2{2,3}".
Definition: matrix_multi.h:196
static const std::string classname()
Class name used in messages.
matrix_t m_matrix
Matrix value representing the multivector within the folded frame.
Definition: matrix_multi.h:277
const matrix_multi< Scalar_T, LO, HI > matrix_sqrt(const matrix_multi< Scalar_T, LO, HI > &val, const matrix_multi< Scalar_T, LO, HI > &i)
Square root of multivector with specified complexifier.
Index set class based on std::bitset<> in Gnu standard C++ library.
Definition: index_set.h:45
const Multivector< Scalar_T, LO, HI > operator|(const Multivector< Scalar_T, LO, HI > &lhs, const RHS< Scalar_T, LO, HI > &rhs)
Transformation via twisted adjoint action.
multivector_t & operator+=(const term_t &rhs)
Add a term, if non-zero.
~matrix_multi()
Destructor.
Definition: matrix_multi.h:165
ublas::compressed_matrix< int, orientation_t > basis_matrix_t
Definition: matrix_multi.h:152
const Multivector< Scalar_T, LO, HI > operator &(const Multivector< Scalar_T, LO, HI > &lhs, const RHS< Scalar_T, LO, HI > &rhs)
Inner product.
std::istream & operator>>(std::istream &s, framed_multi< Scalar_T, LO, HI > &val)
Read multivector from input.
multivector_t matrix_multi_t
Definition: matrix_multi.h:137
#define _GLUCAT_CLIFFORD_ALGEBRA_OPERATIONS
matrix_multi()
Default constructor.
matrix_multi(const char *str, const index_set_t frm, const bool prechecked=false)
Construct a multivector, within a given frame, from a char*: eg: "3+2{1,2}-6.1e-2{2,3}".
Definition: matrix_multi.h:199