]> www.ginac.de Git - ginac.git/blob - ginac/matrix.h
- docs now under automake control
[ginac.git] / ginac / matrix.h
1 /** @file matrix.h
2  *
3  *  Interface to symbolic matrices
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #ifndef __GINAC_MATRIX_H__
23 #define __GINAC_MATRIX_H__
24
25 #include <vector>
26 #include <ginac/basic.h>
27 #include <ginac/ex.h>
28
29 /** Symbolic matrices. */
30 class matrix : public basic
31 {
32 // friends
33     friend ex determinant_numeric(const matrix & m);
34     friend ex determinant_symbolic_perm(const matrix & m);
35     friend ex determinant_symbolic_minor(const matrix & m);
36 // member functions
37
38     // default constructor, destructor, copy constructor, assignment operator
39     // and helpers:
40 public:
41     matrix();
42     ~matrix();
43     matrix(matrix const & other);
44     matrix const & operator=(matrix const & other);
45 protected:
46     void copy(matrix const & other);
47     void destroy(bool call_parent);
48
49     // other constructors
50 public:
51     matrix(int r, int c);
52     matrix(int r, int c, vector<ex> const & m2);
53    
54     // functions overriding virtual functions from bases classes
55 public:
56     basic * duplicate() const;
57     void printraw(ostream & os) const;
58     void print(ostream & os, unsigned upper_precedence=0) const;
59     int nops() const;
60     ex & let_op(int const i);
61     ex expand(unsigned options=0) const;
62     bool has(ex const & other) const;
63     ex eval(int level=0) const;
64     ex evalf(int level=0) const;
65     // ex subs(lst const & ls, lst const & lr) const;
66 protected:
67     int compare_same_type(basic const & other) const;
68     unsigned return_type(void) const { return return_types::noncommutative; };
69     // new virtual functions which can be overridden by derived classes
70     // (none)
71     
72     // non-virtual functions in this class
73 public:
74     int rows() const            //! get number of rows.
75         { return row; }
76     int cols() const            //! get number of columns.
77         { return col; }
78     matrix add(matrix const & other) const;
79     matrix sub(matrix const & other) const;
80     matrix mul(matrix const & other) const;
81     ex const & operator() (int ro, int co) const;
82     matrix & set(int ro, int co, ex value);
83     matrix transpose(void) const;
84     ex determinant(bool normalized=true) const;
85     ex trace(void) const;
86     ex charpoly(ex const & lambda) const;
87     matrix inverse(void) const;
88     matrix fraction_free_elim(matrix const & vars, matrix const & v) const;
89     matrix solve(matrix const & v) const;
90 protected:
91     int pivot(int ro);
92     void ffe_swap(int r1, int c1, int r2 ,int c2);
93     void ffe_set(int r, int c, ex e);
94     ex ffe_get(int r, int c) const;
95     
96 // member variables
97 protected:
98     int row;                    /**< number of rows      */
99     int col;                    /**< number of columns   */
100     vector<ex> m;               /**< representation (cols indexed first) */
101     static unsigned precedence;
102 };
103
104 // global constants
105 extern const matrix some_matrix;
106 extern type_info const & typeid_matrix;
107
108 // wrapper functions around member functions
109
110 inline int nops(matrix const & m)
111 { return m.nops(); }
112
113 inline ex expand(matrix const & m, unsigned options=0)
114 { return m.expand(options); }
115
116 inline bool has(matrix const & m, ex const & other)
117 { return m.has(other); }
118
119 inline ex eval(matrix const & m, int level=0)
120 { return m.eval(level); }
121
122 inline ex evalf(matrix const & m, int level=0)
123 { return m.evalf(level); }
124
125 inline int rows(matrix const & m)
126 { return m.rows(); }
127
128 inline int cols(matrix const & m)
129 { return m.cols(); }
130
131 inline matrix transpose(matrix const & m)
132 { return m.transpose(); }
133
134 inline ex determinant(matrix const & m, bool normalized=true)
135 { return m.determinant(normalized); }
136
137 inline ex trace(matrix const & m)
138 { return m.trace(); }
139
140 inline ex charpoly(matrix const & m, ex const & lambda)
141 { return m.charpoly(lambda); }
142
143 inline matrix inverse(matrix const & m)
144 { return m.inverse(); }
145
146 // macros
147
148 #define ex_to_matrix(X) (static_cast<matrix const &>(*(X).bp))
149
150 #endif // ndef __GINAC_MATRIX_H__