3 * Interface to symbolic matrices */
6 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
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.
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.
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
23 #ifndef __GINAC_MATRIX_H__
24 #define __GINAC_MATRIX_H__
27 #include <ginac/basic.h>
30 #ifndef NO_GINAC_NAMESPACE
32 #endif // ndef NO_GINAC_NAMESPACE
34 /** Symbolic matrices. */
35 class matrix : public basic
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);
43 // default constructor, destructor, copy constructor, assignment operator
48 matrix(matrix const & other);
49 matrix const & operator=(matrix const & other);
51 void copy(matrix const & other);
52 void destroy(bool call_parent);
56 matrix(unsigned r, unsigned c);
57 matrix(unsigned r, unsigned c, exvector const & m2);
59 // functions overriding virtual functions from bases classes
61 basic * duplicate() const;
62 void print(ostream & os, unsigned upper_precedence=0) const;
63 void printraw(ostream & os) const;
64 unsigned 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;
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
77 // non-virtual functions in this class
79 unsigned rows() const //! get number of rows.
81 unsigned cols() const //! get number of columns.
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() (unsigned ro, unsigned co) const;
87 matrix & set(unsigned ro, unsigned co, ex value);
88 matrix transpose(void) const;
89 ex determinant(bool normalized=true) 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;
96 int pivot(unsigned ro);
97 void ffe_swap(unsigned r1, unsigned c1, unsigned r2 ,unsigned c2);
98 void ffe_set(unsigned r, unsigned c, ex e);
99 ex ffe_get(unsigned r, unsigned c) const;
103 unsigned row; /**< number of rows */
104 unsigned col; /**< number of columns */
105 exvector m; /**< representation (cols indexed first) */
106 static unsigned precedence;
110 extern const matrix some_matrix;
111 extern type_info const & typeid_matrix;
113 // wrapper functions around member functions
115 inline unsigned nops(matrix const & m)
118 inline ex expand(matrix const & m, unsigned options=0)
119 { return m.expand(options); }
121 inline bool has(matrix const & m, ex const & other)
122 { return m.has(other); }
124 inline ex eval(matrix const & m, int level=0)
125 { return m.eval(level); }
127 inline ex evalf(matrix const & m, int level=0)
128 { return m.evalf(level); }
130 inline unsigned rows(matrix const & m)
133 inline unsigned cols(matrix const & m)
136 inline matrix transpose(matrix const & m)
137 { return m.transpose(); }
139 inline ex determinant(matrix const & m, bool normalized=true)
140 { return m.determinant(normalized); }
142 inline ex trace(matrix const & m)
143 { return m.trace(); }
145 inline ex charpoly(matrix const & m, ex const & lambda)
146 { return m.charpoly(lambda); }
148 inline matrix inverse(matrix const & m)
149 { return m.inverse(); }
152 inline const matrix &ex_to_matrix(const ex &e)
154 return static_cast<const matrix &>(*e.bp);
157 #ifndef NO_GINAC_NAMESPACE
159 #endif // ndef NO_GINAC_NAMESPACE
161 #endif // ndef __GINAC_MATRIX_H__