3 * Interface to symbolic matrices */
6 * GiNaC Copyright (C) 1999-2001 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__
32 /** Symbolic matrices. */
33 class matrix : public basic
35 GINAC_DECLARE_REGISTERED_CLASS(matrix, basic)
39 matrix(unsigned r, unsigned c);
40 matrix(unsigned r, unsigned c, const exvector & m2);
42 // functions overriding virtual functions from bases classes
44 void print(std::ostream & os, unsigned upper_precedence=0) const;
45 void printraw(std::ostream & os) const;
46 unsigned nops() const;
49 ex expand(unsigned options=0) const;
50 bool has(const ex & other) const;
51 ex eval(int level=0) const;
52 ex evalf(int level=0) const;
53 ex subs(const lst & ls, const lst & lr) const;
54 ex eval_indexed(const basic & i) const;
55 ex add_indexed(const ex & self, const ex & other) const;
56 bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
58 unsigned return_type(void) const { return return_types::noncommutative; };
59 // new virtual functions which can be overridden by derived classes
62 // non-virtual functions in this class
64 unsigned rows(void) const /// Get number of rows.
66 unsigned cols(void) const /// Get number of columns.
68 matrix add(const matrix & other) const;
69 matrix sub(const matrix & other) const;
70 matrix mul(const matrix & other) const;
71 const ex & operator() (unsigned ro, unsigned co) const;
72 matrix & set(unsigned ro, unsigned co, ex value);
73 matrix transpose(void) const;
74 ex determinant(unsigned algo = determinant_algo::automatic) const;
76 ex charpoly(const symbol & lambda) const;
77 matrix inverse(void) const;
78 matrix solve(const matrix & vars, const matrix & rhs,
79 unsigned algo = solve_algo::automatic) const;
81 ex determinant_minor(void) const;
82 int gauss_elimination(const bool det = false);
83 int division_free_elimination(const bool det = false);
84 int fraction_free_elimination(const bool det = false);
85 int pivot(unsigned ro, unsigned co, bool symbolic = true);
89 unsigned row; ///< number of rows
90 unsigned col; ///< number of columns
91 exvector m; ///< representation (cols indexed first)
92 static unsigned precedence;
96 // wrapper functions around member functions
98 inline unsigned nops(const matrix & m)
101 inline ex expand(const matrix & m, unsigned options = 0)
102 { return m.expand(options); }
104 inline bool has(const matrix & m, const ex & other)
105 { return m.has(other); }
107 inline ex eval(const matrix & m, int level = 0)
108 { return m.eval(level); }
110 inline ex evalf(const matrix & m, int level = 0)
111 { return m.evalf(level); }
113 inline unsigned rows(const matrix & m)
116 inline unsigned cols(const matrix & m)
119 inline matrix transpose(const matrix & m)
120 { return m.transpose(); }
122 inline ex determinant(const matrix & m, unsigned options = determinant_algo::automatic)
123 { return m.determinant(options); }
125 inline ex trace(const matrix & m)
126 { return m.trace(); }
128 inline ex charpoly(const matrix & m, const symbol & lambda)
129 { return m.charpoly(lambda); }
131 inline matrix inverse(const matrix & m)
132 { return m.inverse(); }
135 inline const matrix &ex_to_matrix(const ex &e)
137 return static_cast<const matrix &>(*e.bp);
140 extern ex lst_to_matrix(const ex &l);
144 #endif // ndef __GINAC_MATRIX_H__