3 * Interface to symbolic matrices */
6 * GiNaC Copyright (C) 1999 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 /** Symbolic matrices. */
31 class matrix : public basic
34 friend ex determinant_numeric(const matrix & m);
35 friend ex determinant_symbolic_perm(const matrix & m);
36 friend ex determinant_symbolic_minor(const matrix & m);
39 // default constructor, destructor, copy constructor, assignment operator
44 matrix(matrix const & other);
45 matrix const & operator=(matrix const & other);
47 void copy(matrix const & other);
48 void destroy(bool call_parent);
53 matrix(int r, int c, vector<ex> const & m2);
55 // functions overriding virtual functions from bases classes
57 basic * duplicate() const;
58 void printraw(ostream & os) const;
59 void print(ostream & os, unsigned upper_precedence=0) const;
61 ex & let_op(int const i);
62 ex expand(unsigned options=0) const;
63 bool has(ex const & other) const;
64 ex eval(int level=0) const;
65 ex evalf(int level=0) const;
66 // ex subs(lst const & ls, lst const & lr) const;
68 int compare_same_type(basic const & other) const;
69 unsigned return_type(void) const { return return_types::noncommutative; };
70 // new virtual functions which can be overridden by derived classes
73 // non-virtual functions in this class
75 int rows() const //! get number of rows.
77 int cols() const //! get number of columns.
79 matrix add(matrix const & other) const;
80 matrix sub(matrix const & other) const;
81 matrix mul(matrix const & other) const;
82 ex const & operator() (int ro, int co) const;
83 matrix & set(int ro, int co, ex value);
84 matrix transpose(void) const;
85 ex determinant(bool normalized=true) const;
87 ex charpoly(ex const & lambda) const;
88 matrix inverse(void) const;
89 matrix fraction_free_elim(matrix const & vars, matrix const & v) const;
90 matrix solve(matrix const & v) const;
93 void ffe_swap(int r1, int c1, int r2 ,int c2);
94 void ffe_set(int r, int c, ex e);
95 ex ffe_get(int r, int c) const;
99 int row; /**< number of rows */
100 int col; /**< number of columns */
101 vector<ex> m; /**< representation (cols indexed first) */
102 static unsigned precedence;
106 extern const matrix some_matrix;
107 extern type_info const & typeid_matrix;
109 // wrapper functions around member functions
111 inline int nops(matrix const & m)
114 inline ex expand(matrix const & m, unsigned options=0)
115 { return m.expand(options); }
117 inline bool has(matrix const & m, ex const & other)
118 { return m.has(other); }
120 inline ex eval(matrix const & m, int level=0)
121 { return m.eval(level); }
123 inline ex evalf(matrix const & m, int level=0)
124 { return m.evalf(level); }
126 inline int rows(matrix const & m)
129 inline int cols(matrix const & m)
132 inline matrix transpose(matrix const & m)
133 { return m.transpose(); }
135 inline ex determinant(matrix const & m, bool normalized=true)
136 { return m.determinant(normalized); }
138 inline ex trace(matrix const & m)
139 { return m.trace(); }
141 inline ex charpoly(matrix const & m, ex const & lambda)
142 { return m.charpoly(lambda); }
144 inline matrix inverse(matrix const & m)
145 { return m.inverse(); }
149 #define ex_to_matrix(X) (static_cast<matrix const &>(*(X).bp))
151 #endif // ndef __GINAC_MATRIX_H__