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__
30 #ifndef NO_NAMESPACE_GINAC
32 #endif // ndef NO_NAMESPACE_GINAC
34 /** Symbolic matrices. */
35 class matrix : public basic
37 GINAC_DECLARE_REGISTERED_CLASS(matrix, basic)
41 matrix(unsigned r, unsigned c);
42 matrix(unsigned r, unsigned c, const exvector & m2);
44 // functions overriding virtual functions from bases classes
46 basic * duplicate() const;
47 void print(std::ostream & os, unsigned upper_precedence=0) const;
48 void printraw(std::ostream & os) const;
49 unsigned nops() const;
52 ex expand(unsigned options=0) const;
53 bool has(const ex & other) const;
54 ex eval(int level=0) const;
55 ex evalf(int level=0) const;
56 // ex subs(const lst & ls, const lst & lr) const;
58 int compare_same_type(const basic & other) const;
59 unsigned return_type(void) const { return return_types::noncommutative; };
60 // new virtual functions which can be overridden by derived classes
63 // non-virtual functions in this class
65 unsigned rows(void) const //! Get number of rows.
67 unsigned cols(void) const //! Get number of columns.
69 matrix add(const matrix & other) const;
70 matrix sub(const matrix & other) const;
71 matrix mul(const matrix & other) const;
72 const ex & operator() (unsigned ro, unsigned co) const;
73 matrix & set(unsigned ro, unsigned co, ex value);
74 matrix transpose(void) const;
75 ex determinant(unsigned algo = determinant_algo::automatic) const;
77 ex charpoly(const symbol & lambda) const;
78 matrix inverse(void) const;
79 matrix solve(const matrix & vars, const matrix & rhs,
80 unsigned algo = solve_algo::automatic) const;
82 ex determinant_minor(void) const;
83 int gauss_elimination(const bool det = false);
84 int division_free_elimination(const bool det = false);
85 int fraction_free_elimination(const bool det = false);
86 int pivot(unsigned ro, unsigned co, bool symbolic = true);
90 unsigned row; /**< number of rows */
91 unsigned col; /**< number of columns */
92 exvector m; /**< representation (cols indexed first) */
93 static unsigned precedence;
97 // wrapper functions around member functions
99 inline unsigned nops(const matrix & m)
102 inline ex expand(const matrix & m, unsigned options = 0)
103 { return m.expand(options); }
105 inline bool has(const matrix & m, const ex & other)
106 { return m.has(other); }
108 inline ex eval(const matrix & m, int level = 0)
109 { return m.eval(level); }
111 inline ex evalf(const matrix & m, int level = 0)
112 { return m.evalf(level); }
114 inline unsigned rows(const matrix & m)
117 inline unsigned cols(const matrix & m)
120 inline matrix transpose(const matrix & m)
121 { return m.transpose(); }
123 inline ex determinant(const matrix & m, unsigned options = determinant_algo::automatic)
124 { return m.determinant(options); }
126 inline ex trace(const matrix & m)
127 { return m.trace(); }
129 inline ex charpoly(const matrix & m, const symbol & lambda)
130 { return m.charpoly(lambda); }
132 inline matrix inverse(const matrix & m)
133 { return m.inverse(); }
136 inline const matrix &ex_to_matrix(const ex &e)
138 return static_cast<const matrix &>(*e.bp);
141 extern ex lst_to_matrix(const ex &l);
143 #ifndef NO_NAMESPACE_GINAC
145 #endif // ndef NO_NAMESPACE_GINAC
147 #endif // ndef __GINAC_MATRIX_H__