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__
27 /** Symbolic matrices. */
28 class matrix : public basic
31 friend ex determinant_numeric(const matrix & m);
32 friend ex determinant_symbolic_perm(const matrix & m);
33 friend ex determinant_symbolic_minor(const matrix & m);
36 // default constructor, destructor, copy constructor, assignment operator
41 matrix(matrix const & other);
42 matrix const & operator=(matrix const & other);
44 void copy(matrix const & other);
45 void destroy(bool call_parent);
50 matrix(int r, int c, vector<ex> const & m2);
52 // functions overriding virtual functions from bases classes
54 basic * duplicate() const;
55 void printraw(ostream & os) const;
56 void print(ostream & os, unsigned upper_precedence=0) const;
58 ex & let_op(int const i);
59 ex expand(unsigned options=0) const;
60 bool has(ex const & other) const;
61 ex eval(int level=0) const;
62 ex evalf(int level=0) const;
63 // ex subs(lst const & ls, lst const & lr) const;
65 int compare_same_type(basic const & other) const;
66 unsigned return_type(void) const { return return_types::noncommutative; };
67 // new virtual functions which can be overridden by derived classes
70 // non-virtual functions in this class
72 int rows() const //! get number of rows.
74 int cols() const //! get number of columns.
76 matrix add(matrix const & other) const;
77 matrix sub(matrix const & other) const;
78 matrix mul(matrix const & other) const;
79 ex const & operator() (int ro, int co) const;
80 matrix & set(int ro, int co, ex value);
81 matrix transpose(void) const;
82 ex determinant(bool normalized=true) const;
84 ex charpoly(ex const & lambda) const;
85 matrix inverse(void) const;
86 matrix fraction_free_elim(matrix const & vars, matrix const & v) const;
87 matrix solve(matrix const & v) const;
90 void ffe_swap(int r1, int c1, int r2 ,int c2);
91 void ffe_set(int r, int c, ex e);
92 ex ffe_get(int r, int c) const;
96 int row; /**< number of rows */
97 int col; /**< number of columns */
98 vector<ex> m; /**< representation (cols indexed first) */
99 static unsigned precedence;
103 extern const matrix some_matrix;
104 extern type_info const & typeid_matrix;
106 // wrapper functions around member functions
108 inline int nops(matrix const & m)
111 inline ex expand(matrix const & m, unsigned options=0)
112 { return m.expand(options); }
114 inline bool has(matrix const & m, ex const & other)
115 { return m.has(other); }
117 inline ex eval(matrix const & m, int level=0)
118 { return m.eval(level); }
120 inline ex evalf(matrix const & m, int level=0)
121 { return m.evalf(level); }
123 inline int rows(matrix const & m)
126 inline int cols(matrix const & m)
129 inline matrix transpose(matrix const & m)
130 { return m.transpose(); }
132 inline ex determinant(matrix const & m, bool normalized=true)
133 { return m.determinant(normalized); }
135 inline ex trace(matrix const & m)
136 { return m.trace(); }
138 inline ex charpoly(matrix const & m, ex const & lambda)
139 { return m.charpoly(lambda); }
141 inline matrix inverse(matrix const & m)
142 { return m.inverse(); }
146 #define ex_to_matrix(X) (static_cast<matrix const &>(*(X).bp))
148 #endif // ndef __GINAC_MATRIX_H__