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>
32 /** Symbolic matrices. */
33 class matrix : public basic
36 friend ex determinant_numeric(const matrix & m);
37 friend ex determinant_symbolic_perm(const matrix & m);
38 friend ex determinant_symbolic_minor(const matrix & m);
41 // default constructor, destructor, copy constructor, assignment operator
46 matrix(matrix const & other);
47 matrix const & operator=(matrix const & other);
49 void copy(matrix const & other);
50 void destroy(bool call_parent);
55 matrix(int r, int c, vector<ex> const & m2);
57 // functions overriding virtual functions from bases classes
59 basic * duplicate() const;
60 void printraw(ostream & os) const;
61 void print(ostream & os, unsigned upper_precedence=0) const;
63 ex & let_op(int const i);
64 ex expand(unsigned options=0) const;
65 bool has(ex const & other) const;
66 ex eval(int level=0) const;
67 ex evalf(int level=0) const;
68 // ex subs(lst const & ls, lst const & lr) const;
70 int compare_same_type(basic const & other) const;
71 unsigned return_type(void) const { return return_types::noncommutative; };
72 // new virtual functions which can be overridden by derived classes
75 // non-virtual functions in this class
77 int rows() const //! get number of rows.
79 int cols() const //! get number of columns.
81 matrix add(matrix const & other) const;
82 matrix sub(matrix const & other) const;
83 matrix mul(matrix const & other) const;
84 ex const & operator() (int ro, int co) const;
85 matrix & set(int ro, int co, ex value);
86 matrix transpose(void) const;
87 ex determinant(bool normalized=true) const;
89 ex charpoly(ex const & lambda) const;
90 matrix inverse(void) const;
91 matrix fraction_free_elim(matrix const & vars, matrix const & v) const;
92 matrix solve(matrix const & v) const;
95 void ffe_swap(int r1, int c1, int r2 ,int c2);
96 void ffe_set(int r, int c, ex e);
97 ex ffe_get(int r, int c) const;
101 int row; /**< number of rows */
102 int col; /**< number of columns */
103 vector<ex> m; /**< representation (cols indexed first) */
104 static unsigned precedence;
108 extern const matrix some_matrix;
109 extern type_info const & typeid_matrix;
111 // wrapper functions around member functions
113 inline int nops(matrix const & m)
116 inline ex expand(matrix const & m, unsigned options=0)
117 { return m.expand(options); }
119 inline bool has(matrix const & m, ex const & other)
120 { return m.has(other); }
122 inline ex eval(matrix const & m, int level=0)
123 { return m.eval(level); }
125 inline ex evalf(matrix const & m, int level=0)
126 { return m.evalf(level); }
128 inline int rows(matrix const & m)
131 inline int cols(matrix const & m)
134 inline matrix transpose(matrix const & m)
135 { return m.transpose(); }
137 inline ex determinant(matrix const & m, bool normalized=true)
138 { return m.determinant(normalized); }
140 inline ex trace(matrix const & m)
141 { return m.trace(); }
143 inline ex charpoly(matrix const & m, ex const & lambda)
144 { return m.charpoly(lambda); }
146 inline matrix inverse(matrix const & m)
147 { return m.inverse(); }
150 inline const matrix &ex_to_matrix(const ex &e)
152 return static_cast<const matrix &>(*e.bp);
157 #endif // ndef __GINAC_MATRIX_H__