]> www.ginac.de Git - ginac.git/blob - ginac/matrix.h
added predefined epsilon tensor
[ginac.git] / ginac / matrix.h
1 /** @file matrix.h
2  *
3  *  Interface to symbolic matrices */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 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 "basic.h"
28 #include "ex.h"
29
30 namespace GiNaC {
31
32 /** Symbolic matrices. */
33 class matrix : public basic
34 {
35         GINAC_DECLARE_REGISTERED_CLASS(matrix, basic)
36         
37         // other ctors
38 public:
39         matrix(unsigned r, unsigned c);
40         matrix(unsigned r, unsigned c, const exvector & m2);
41         
42         // functions overriding virtual functions from bases classes
43 public:
44         void print(std::ostream & os, unsigned upper_precedence=0) const;
45         void printraw(std::ostream & os) const;
46         unsigned nops() const;
47         ex op(int i) const;
48         ex & let_op(int i);
49         ex expand(unsigned options=0) const;
50         bool has(const ex & other) const;
51         ex eval(int level=0) const;
52         ex evalf(int level=0) const;
53         ex subs(const lst & ls, const lst & lr) const;
54         ex eval_indexed(const basic & i) const;
55         bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
56 protected:
57         unsigned return_type(void) const { return return_types::noncommutative; };
58         // new virtual functions which can be overridden by derived classes
59         // (none)
60         
61         // non-virtual functions in this class
62 public:
63         unsigned rows(void) const        /// Get number of rows.
64                 { return row; }
65         unsigned cols(void) const        /// Get number of columns.
66                 { return col; }
67         matrix add(const matrix & other) const;
68         matrix sub(const matrix & other) const;
69         matrix mul(const matrix & other) const;
70         const ex & operator() (unsigned ro, unsigned co) const;
71         matrix & set(unsigned ro, unsigned co, ex value);
72         matrix transpose(void) const;
73         ex determinant(unsigned algo = determinant_algo::automatic) const;
74         ex trace(void) const;
75         ex charpoly(const symbol & lambda) const;
76         matrix inverse(void) const;
77         matrix solve(const matrix & vars, const matrix & rhs,
78                      unsigned algo = solve_algo::automatic) const;
79 protected:
80         ex determinant_minor(void) const;
81         int gauss_elimination(const bool det = false);
82         int division_free_elimination(const bool det = false);
83         int fraction_free_elimination(const bool det = false);
84         int pivot(unsigned ro, unsigned co, bool symbolic = true);
85         
86 // member variables
87 protected:
88         unsigned row;             ///< number of rows
89         unsigned col;             ///< number of columns
90         exvector m;               ///< representation (cols indexed first)
91         static unsigned precedence;
92 };
93
94
95 // wrapper functions around member functions
96
97 inline unsigned nops(const matrix & m)
98 { return m.nops(); }
99
100 inline ex expand(const matrix & m, unsigned options = 0)
101 { return m.expand(options); }
102
103 inline bool has(const matrix & m, const ex & other)
104 { return m.has(other); }
105
106 inline ex eval(const matrix & m, int level = 0)
107 { return m.eval(level); }
108
109 inline ex evalf(const matrix & m, int level = 0)
110 { return m.evalf(level); }
111
112 inline unsigned rows(const matrix & m)
113 { return m.rows(); }
114
115 inline unsigned cols(const matrix & m)
116 { return m.cols(); }
117
118 inline matrix transpose(const matrix & m)
119 { return m.transpose(); }
120
121 inline ex determinant(const matrix & m, unsigned options = determinant_algo::automatic)
122 { return m.determinant(options); }
123
124 inline ex trace(const matrix & m)
125 { return m.trace(); }
126
127 inline ex charpoly(const matrix & m, const symbol & lambda)
128 { return m.charpoly(lambda); }
129
130 inline matrix inverse(const matrix & m)
131 { return m.inverse(); }
132
133 // utility functions
134 inline const matrix &ex_to_matrix(const ex &e)
135 {
136         return static_cast<const matrix &>(*e.bp);
137 }
138
139 extern ex lst_to_matrix(const ex &l);
140
141 } // namespace GiNaC
142
143 #endif // ndef __GINAC_MATRIX_H__