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