]> www.ginac.de Git - ginac.git/blob - ginac/matrix.h
lortensor class
[ginac.git] / ginac / matrix.h
1 /** @file matrix.h
2  *
3  *  Interface to symbolic matrices */
4
5 /*
6  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifndef __GINAC_MATRIX_H__
24 #define __GINAC_MATRIX_H__
25
26 #include <vector>
27 #include <ginac/basic.h>
28 #include <ginac/ex.h>
29
30 #ifndef NO_GINAC_NAMESPACE
31 namespace GiNaC {
32 #endif // ndef NO_GINAC_NAMESPACE
33
34 /** Symbolic matrices. */
35 class matrix : public basic
36 {
37 // friends
38     friend ex determinant_numeric(const matrix & m);
39     friend ex determinant_symbolic_perm(const matrix & m);
40     friend ex determinant_symbolic_minor(const matrix & m);
41 // member functions
42
43     // default constructor, destructor, copy constructor, assignment operator
44     // and helpers:
45 public:
46     matrix();
47     ~matrix();
48     matrix(matrix const & other);
49     matrix const & operator=(matrix const & other);
50 protected:
51     void copy(matrix const & other);
52     void destroy(bool call_parent);
53
54     // other constructors
55 public:
56     matrix(int r, int c);
57     matrix(int r, int c, exvector const & m2);
58    
59     // functions overriding virtual functions from bases classes
60 public:
61     basic * duplicate() const;
62     void print(ostream & os, unsigned upper_precedence=0) const;
63     void printraw(ostream & os) const;
64     int nops() const;
65     ex & let_op(int const i);
66     ex expand(unsigned options=0) const;
67     bool has(ex const & other) const;
68     ex eval(int level=0) const;
69     ex evalf(int level=0) const;
70     // ex subs(lst const & ls, lst const & lr) const;
71 protected:
72     int compare_same_type(basic const & other) const;
73     unsigned return_type(void) const { return return_types::noncommutative; };
74     // new virtual functions which can be overridden by derived classes
75     // (none)
76     
77     // non-virtual functions in this class
78 public:
79     int rows() const            //! get number of rows.
80         { return row; }
81     int cols() const            //! get number of columns.
82         { return col; }
83     matrix add(matrix const & other) const;
84     matrix sub(matrix const & other) const;
85     matrix mul(matrix const & other) const;
86     ex const & operator() (int ro, int co) const;
87     matrix & set(int ro, int co, ex value);
88     matrix transpose(void) const;
89     ex determinant(bool normalized=true) const;
90     ex trace(void) const;
91     ex charpoly(ex const & lambda) const;
92     matrix inverse(void) const;
93     matrix fraction_free_elim(matrix const & vars, matrix const & v) const;
94     matrix solve(matrix const & v) const;
95 protected:
96     int pivot(int ro);
97     void ffe_swap(int r1, int c1, int r2 ,int c2);
98     void ffe_set(int r, int c, ex e);
99     ex ffe_get(int r, int c) const;
100     
101 // member variables
102 protected:
103     int row;                    /**< number of rows      */
104     int col;                    /**< number of columns   */
105     exvector m;               /**< representation (cols indexed first) */
106     static unsigned precedence;
107 };
108
109 // global constants
110 extern const matrix some_matrix;
111 extern type_info const & typeid_matrix;
112
113 // wrapper functions around member functions
114
115 inline int nops(matrix const & m)
116 { return m.nops(); }
117
118 inline ex expand(matrix const & m, unsigned options=0)
119 { return m.expand(options); }
120
121 inline bool has(matrix const & m, ex const & other)
122 { return m.has(other); }
123
124 inline ex eval(matrix const & m, int level=0)
125 { return m.eval(level); }
126
127 inline ex evalf(matrix const & m, int level=0)
128 { return m.evalf(level); }
129
130 inline int rows(matrix const & m)
131 { return m.rows(); }
132
133 inline int cols(matrix const & m)
134 { return m.cols(); }
135
136 inline matrix transpose(matrix const & m)
137 { return m.transpose(); }
138
139 inline ex determinant(matrix const & m, bool normalized=true)
140 { return m.determinant(normalized); }
141
142 inline ex trace(matrix const & m)
143 { return m.trace(); }
144
145 inline ex charpoly(matrix const & m, ex const & lambda)
146 { return m.charpoly(lambda); }
147
148 inline matrix inverse(matrix const & m)
149 { return m.inverse(); }
150
151 // utility functions
152 inline const matrix &ex_to_matrix(const ex &e)
153 {
154         return static_cast<const matrix &>(*e.bp);
155 }
156
157 #ifndef NO_GINAC_NAMESPACE
158 } // namespace GiNaC
159 #endif // ndef NO_GINAC_NAMESPACE
160
161 #endif // ndef __GINAC_MATRIX_H__