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