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
37 GINAC_DECLARE_REGISTERED_CLASS(matrix, basic)
40 friend ex determinant_numeric(const matrix & m);
41 friend ex determinant_symbolic_perm(const matrix & m);
42 friend ex determinant_symbolic_minor(const matrix & m);
46 // default constructor, destructor, copy constructor, assignment operator
51 matrix(const matrix & other);
52 const matrix & operator=(const matrix & other);
54 void copy(const matrix & other);
55 void destroy(bool call_parent);
59 matrix(unsigned r, unsigned c);
60 matrix(unsigned r, unsigned c, const exvector & m2);
62 // functions overriding virtual functions from bases classes
64 basic * duplicate() const;
65 void print(ostream & os, unsigned upper_precedence=0) const;
66 void printraw(ostream & os) const;
67 unsigned nops() const;
69 ex expand(unsigned options=0) const;
70 bool has(const ex & other) const;
71 ex eval(int level=0) const;
72 ex evalf(int level=0) const;
73 // ex subs(const lst & ls, const lst & lr) const;
75 int compare_same_type(const basic & other) const;
76 unsigned return_type(void) const { return return_types::noncommutative; };
77 // new virtual functions which can be overridden by derived classes
80 // non-virtual functions in this class
82 unsigned rows() const //! get number of rows.
84 unsigned cols() const //! get number of columns.
86 matrix add(const matrix & other) const;
87 matrix sub(const matrix & other) const;
88 matrix mul(const matrix & other) const;
89 const ex & operator() (unsigned ro, unsigned co) const;
90 matrix & set(unsigned ro, unsigned co, ex value);
91 matrix transpose(void) const;
92 ex determinant(bool normalized=true) const;
94 ex charpoly(const ex & lambda) const;
95 matrix inverse(void) const;
96 matrix fraction_free_elim(const matrix & vars, const matrix & v) const;
97 matrix solve(const matrix & v) const;
99 int pivot(unsigned ro);
100 void ffe_swap(unsigned r1, unsigned c1, unsigned r2 ,unsigned c2);
101 void ffe_set(unsigned r, unsigned c, ex e);
102 ex ffe_get(unsigned r, unsigned c) const;
106 unsigned row; /**< number of rows */
107 unsigned col; /**< number of columns */
108 exvector m; /**< representation (cols indexed first) */
109 static unsigned precedence;
113 extern const matrix some_matrix;
114 extern const type_info & typeid_matrix;
116 // wrapper functions around member functions
118 inline unsigned nops(const matrix & m)
121 inline ex expand(const matrix & m, unsigned options=0)
122 { return m.expand(options); }
124 inline bool has(const matrix & m, const ex & other)
125 { return m.has(other); }
127 inline ex eval(const matrix & m, int level=0)
128 { return m.eval(level); }
130 inline ex evalf(const matrix & m, int level=0)
131 { return m.evalf(level); }
133 inline unsigned rows(const matrix & m)
136 inline unsigned cols(const matrix & m)
139 inline matrix transpose(const matrix & m)
140 { return m.transpose(); }
142 inline ex determinant(const matrix & m, bool normalized=true)
143 { return m.determinant(normalized); }
145 inline ex trace(const matrix & m)
146 { return m.trace(); }
148 inline ex charpoly(const matrix & m, const ex & lambda)
149 { return m.charpoly(lambda); }
151 inline matrix inverse(const matrix & m)
152 { return m.inverse(); }
155 inline const matrix &ex_to_matrix(const ex &e)
157 return static_cast<const matrix &>(*e.bp);
160 #ifndef NO_GINAC_NAMESPACE
162 #endif // ndef NO_GINAC_NAMESPACE
164 #endif // ndef __GINAC_MATRIX_H__