3 * Interface to symbolic matrices
5 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef __GINAC_MATRIX_H__
23 #define __GINAC_MATRIX_H__
26 #include <ginac/basic.h>
29 /** Symbolic matrices. */
30 class matrix : public basic
33 friend ex determinant_numeric(const matrix & m);
34 friend ex determinant_symbolic_perm(const matrix & m);
35 friend ex determinant_symbolic_minor(const matrix & m);
38 // default constructor, destructor, copy constructor, assignment operator
43 matrix(matrix const & other);
44 matrix const & operator=(matrix const & other);
46 void copy(matrix const & other);
47 void destroy(bool call_parent);
52 matrix(int r, int c, vector<ex> const & m2);
54 // functions overriding virtual functions from bases classes
56 basic * duplicate() const;
57 void printraw(ostream & os) const;
58 void print(ostream & os, unsigned upper_precedence=0) const;
60 ex & let_op(int const i);
61 ex expand(unsigned options=0) const;
62 bool has(ex const & other) const;
63 ex eval(int level=0) const;
64 ex evalf(int level=0) const;
65 // ex subs(lst const & ls, lst const & lr) const;
67 int compare_same_type(basic const & other) const;
68 unsigned return_type(void) const { return return_types::noncommutative; };
69 // new virtual functions which can be overridden by derived classes
72 // non-virtual functions in this class
74 int rows() const //! get number of rows.
76 int cols() const //! get number of columns.
78 matrix add(matrix const & other) const;
79 matrix sub(matrix const & other) const;
80 matrix mul(matrix const & other) const;
81 ex const & operator() (int ro, int co) const;
82 matrix & set(int ro, int co, ex value);
83 matrix transpose(void) const;
84 ex determinant(bool normalized=true) const;
86 ex charpoly(ex const & lambda) const;
87 matrix inverse(void) const;
88 matrix fraction_free_elim(matrix const & vars, matrix const & v) const;
89 matrix solve(matrix const & v) const;
92 void ffe_swap(int r1, int c1, int r2 ,int c2);
93 void ffe_set(int r, int c, ex e);
94 ex ffe_get(int r, int c) const;
98 int row; /**< number of rows */
99 int col; /**< number of columns */
100 vector<ex> m; /**< representation (cols indexed first) */
101 static unsigned precedence;
105 extern const matrix some_matrix;
106 extern type_info const & typeid_matrix;
108 // wrapper functions around member functions
110 inline int nops(matrix const & m)
113 inline ex expand(matrix const & m, unsigned options=0)
114 { return m.expand(options); }
116 inline bool has(matrix const & m, ex const & other)
117 { return m.has(other); }
119 inline ex eval(matrix const & m, int level=0)
120 { return m.eval(level); }
122 inline ex evalf(matrix const & m, int level=0)
123 { return m.evalf(level); }
125 inline int rows(matrix const & m)
128 inline int cols(matrix const & m)
131 inline matrix transpose(matrix const & m)
132 { return m.transpose(); }
134 inline ex determinant(matrix const & m, bool normalized=true)
135 { return m.determinant(normalized); }
137 inline ex trace(matrix const & m)
138 { return m.trace(); }
140 inline ex charpoly(matrix const & m, ex const & lambda)
141 { return m.charpoly(lambda); }
143 inline matrix inverse(matrix const & m)
144 { return m.inverse(); }
148 #define ex_to_matrix(X) (static_cast<matrix const &>(*(X).bp))
150 #endif // ndef __GINAC_MATRIX_H__