]> www.ginac.de Git - ginac.git/blob - ginac/matrix.h
- removed an obscure reference that broke internal functions.
[ginac.git] / ginac / matrix.h
1 /** @file matrix.h
2  *
3  *  Interface to symbolic matrices */
4
5 /*
6  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef __GINAC_MATRIX_H__
24 #define __GINAC_MATRIX_H__
25
26 #include <vector>
27 #include <ginac/basic.h>
28 #include <ginac/ex.h>
29
30 namespace GiNaC {
31
32 /** Symbolic matrices. */
33 class matrix : public basic
34 {
35 // friends
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);
39 // member functions
40
41     // default constructor, destructor, copy constructor, assignment operator
42     // and helpers:
43 public:
44     matrix();
45     ~matrix();
46     matrix(matrix const & other);
47     matrix const & operator=(matrix const & other);
48 protected:
49     void copy(matrix const & other);
50     void destroy(bool call_parent);
51
52     // other constructors
53 public:
54     matrix(int r, int c);
55     matrix(int r, int c, vector<ex> const & m2);
56    
57     // functions overriding virtual functions from bases classes
58 public:
59     basic * duplicate() const;
60     void printraw(ostream & os) const;
61     void print(ostream & os, unsigned upper_precedence=0) const;
62     int nops() 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;
69 protected:
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
73     // (none)
74     
75     // non-virtual functions in this class
76 public:
77     int rows() const            //! get number of rows.
78         { return row; }
79     int cols() const            //! get number of columns.
80         { return col; }
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;
88     ex trace(void) 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;
93 protected:
94     int pivot(int ro);
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;
98     
99 // member variables
100 protected:
101     int row;                    /**< number of rows      */
102     int col;                    /**< number of columns   */
103     vector<ex> m;               /**< representation (cols indexed first) */
104     static unsigned precedence;
105 };
106
107 // global constants
108 extern const matrix some_matrix;
109 extern type_info const & typeid_matrix;
110
111 // wrapper functions around member functions
112
113 inline int nops(matrix const & m)
114 { return m.nops(); }
115
116 inline ex expand(matrix const & m, unsigned options=0)
117 { return m.expand(options); }
118
119 inline bool has(matrix const & m, ex const & other)
120 { return m.has(other); }
121
122 inline ex eval(matrix const & m, int level=0)
123 { return m.eval(level); }
124
125 inline ex evalf(matrix const & m, int level=0)
126 { return m.evalf(level); }
127
128 inline int rows(matrix const & m)
129 { return m.rows(); }
130
131 inline int cols(matrix const & m)
132 { return m.cols(); }
133
134 inline matrix transpose(matrix const & m)
135 { return m.transpose(); }
136
137 inline ex determinant(matrix const & m, bool normalized=true)
138 { return m.determinant(normalized); }
139
140 inline ex trace(matrix const & m)
141 { return m.trace(); }
142
143 inline ex charpoly(matrix const & m, ex const & lambda)
144 { return m.charpoly(lambda); }
145
146 inline matrix inverse(matrix const & m)
147 { return m.inverse(); }
148
149 // utility functions
150 inline const matrix &ex_to_matrix(const ex &e)
151 {
152         return static_cast<const matrix &>(*e.bp);
153 }
154
155 } // namespace GiNaC
156
157 #endif // ndef __GINAC_MATRIX_H__