]> www.ginac.de Git - ginac.git/blob - ginac/flags.h
7c51b75d2ecd7d29cb29dcb8c3b3fe35240e9208
[ginac.git] / ginac / flags.h
1 /** @file flags.h
2  *
3  *  Collection of all flags used through the GiNaC framework. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef __GINAC_FLAGS_H__
24 #define __GINAC_FLAGS_H__
25
26 namespace GiNaC {
27
28 /** Flags to control the behavior of expand(). */
29 class expand_options {
30 public:
31         enum {
32                 expand_indexed = 0x0001,      ///< expands (a+b).i to a.i+b.i
33                 expand_function_args = 0x0002 ///< expands the arguments of functions
34         };
35 };
36
37 /** Flags to control the behavior of subs(). */
38 class subs_options {
39 public:
40         enum {
41                 no_pattern = 0x0001,             ///< disable pattern matching
42                 subs_no_pattern = 0x0001, // for backwards compatibility
43                 algebraic = 0x0002,              ///< enable algebraic substitutions
44                 subs_algebraic = 0x0002,  // for backwards compatibility
45                 pattern_is_product = 0x0004,     ///< used internally by expairseq::subschildren()
46                 pattern_is_not_product = 0x0008, ///< used internally by expairseq::subschildren()
47                 no_index_renaming = 0x0010
48         };
49 };
50
51 /** Domain of an object */
52 class domain {
53 public:
54         enum {
55                 complex,
56                 real
57         };
58 };
59
60 /** Flags to control series expansion. */
61 class series_options {
62 public:
63         enum {
64                 /** Suppress branch cuts in series expansion.  Branch cuts manifest
65                  *  themselves as step functions, if this option is not passed.  If
66                  *  it is passed and expansion at a point on a cut is performed, then
67                  *  the analytic continuation of the function is expanded. */
68                 suppress_branchcut = 0x0001
69         };
70 };
71
72 /** Switch to control algorithm for determinant computation. */
73 class determinant_algo {
74 public:
75         enum {
76                 /** Let the system choose.  A heuristics is applied for automatic
77                  *  determination of a suitable algorithm. */
78                 automatic,
79                 /** Gauss elimination.  If \f$m_{i,j}^{(0)}\f$ are the entries of the
80                  *  original matrix, then the matrix is transformed into triangular
81                  *  form by applying the rules
82                  *  \f[
83                  *      m_{i,j}^{(k+1)} = m_{i,j}^{(k)} - m_{i,k}^{(k)} m_{k,j}^{(k)} / m_{k,k}^{(k)}
84                  *  \f]
85                  *  The determinant is then just the product of diagonal elements.
86                  *  Choose this algorithm only for purely numerical matrices. */
87                 gauss,
88                 /** Division-free elimination.  This is a modification of Gauss
89                  *  elimination where the division by the pivot element is not
90                  *  carried out.  If \f$m_{i,j}^{(0)}\f$ are the entries of the
91                  *  original matrix, then the matrix is transformed into triangular
92                  *  form by applying the rules
93                  *  \f[
94                  *      m_{i,j}^{(k+1)} = m_{i,j}^{(k)} m_{k,k}^{(k)} - m_{i,k}^{(k)} m_{k,j}^{(k)}
95                  *  \f]
96                  *  The determinant can later be computed by inspecting the diagonal
97                  *  elements only.  This algorithm is only there for the purpose of
98                  *  cross-checks.  It is never fast. */
99                 divfree,
100                 /** Laplace elimination.  This is plain recursive elimination along
101                  *  minors although multiple minors are avoided by the algorithm.
102                  *  Although the algorithm is exponential in complexity it is
103                  *  frequently the fastest one when the matrix is populated by
104                  *  complicated symbolic expressions. */
105                 laplace,
106                 /** Bareiss fraction-free elimination.  This is a modification of
107                  *  Gauss elimination where the division by the pivot element is
108                  *  <EM>delayed</EM> until it can be carried out without computing
109                  *  GCDs.  If \f$m_{i,j}^{(0)}\f$ are the entries of the original
110                  *  matrix, then the matrix is transformed into triangular form by
111                  *  applying the rules
112                  *  \f[
113                  *      m_{i,j}^{(k+1)} = (m_{i,j}^{(k)} m_{k,k}^{(k)} - m_{i,k}^{(k)} m_{k,j}^{(k)}) / m_{k-1,k-1}^{(k-1)}
114                  *  \f]
115                  *  (We have set \f$m_{-1,-1}^{(-1)}=1\f$ in order to avoid a case
116                  *  distinction in above formula.)  It can be shown that nothing more
117                  *  than polynomial long division is needed for carrying out the
118                  *  division.  The determinant can then be read of from the lower
119                  *  right entry.  This algorithm is rarely fast for computing
120                  *  determinants. */
121                 bareiss
122         };
123 };
124
125 /** Switch to control algorithm for linear system solving. */
126 class solve_algo {
127 public:
128         enum {
129                 /** Let the system choose.  A heuristics is applied for automatic
130                  *  determination of a suitable algorithm. */
131                 automatic,
132                 /** Gauss elimination.  If \f$m_{i,j}^{(0)}\f$ are the entries of the
133                  *  original matrix, then the matrix is transformed into triangular
134                  *  form by applying the rules
135                  *  \f[
136                  *      m_{i,j}^{(k+1)} = m_{i,j}^{(k)} - m_{i,k}^{(k)} m_{k,j}^{(k)} / m_{k,k}^{(k)}
137                  *  \f]
138                  *  This algorithm is well-suited for numerical matrices but generally
139                  *  suffers from the expensive division (and computation of GCDs) at
140                  *  each step. */
141                 gauss,
142                 /** Division-free elimination.  This is a modification of Gauss
143                  *  elimination where the division by the pivot element is not
144                  *  carried out.  If \f$m_{i,j}^{(0)}\f$ are the entries of the
145                  *  original matrix, then the matrix is transformed into triangular
146                  *  form by applying the rules
147                  *  \f[
148                  *      m_{i,j}^{(k+1)} = m_{i,j}^{(k)} m_{k,k}^{(k)} - m_{i,k}^{(k)} m_{k,j}^{(k)}
149                  *  \f]
150                  *  This algorithm is only there for the purpose of cross-checks.
151                  *  It suffers from exponential intermediate expression swell.  Use it
152                  *  only for small systems. */
153                 divfree,
154                 /** Bareiss fraction-free elimination.  This is a modification of
155                  *  Gauss elimination where the division by the pivot element is
156                  *  <EM>delayed</EM> until it can be carried out without computing
157                  *  GCDs.  If \f$m_{i,j}^{(0)}\f$ are the entries of the original
158                  *  matrix, then the matrix is transformed into triangular form by
159                  *  applying the rules
160                  *  \f[
161                  *      m_{i,j}^{(k+1)} = (m_{i,j}^{(k)} m_{k,k}^{(k)} - m_{i,k}^{(k)} m_{k,j}^{(k)}) / m_{k-1,k-1}^{(k-1)}
162                  *  \f]
163                  *  (We have set \f$m_{-1,-1}^{(-1)}=1\f$ in order to avoid a case
164                  *  distinction in above formula.)  It can be shown that nothing more
165                  *  than polynomial long division is needed for carrying out the
166                  *  division.  This is generally the fastest algorithm for solving
167                  *  linear systems.  In contrast to division-free elimination it only
168                  *  has a linear expression swell.  For two-dimensional systems, the
169                  *  two algorithms are equivalent, however. */
170                 bareiss
171         };
172 };
173
174 /** Flags to store information about the state of an object.
175  *  @see basic::flags */
176 class status_flags {
177 public:
178         enum {
179                 dynallocated    = 0x0001, ///< heap-allocated (i.e. created by new if we want to be clever and bypass the stack, @see ex::construct_from_basic() )
180                 evaluated       = 0x0002, ///< .eval() has already done its job
181                 expanded        = 0x0004, ///< .expand(0) has already done its job (other expand() options ignore this flag)
182                 hash_calculated = 0x0008, ///< .calchash() has already done its job
183                 not_shareable   = 0x0010  ///< don't share instances of this object between different expressions unless explicitly asked to (used by ex::compare())
184         };
185 };
186
187 /** Possible attributes an object can have. */
188 class info_flags {
189 public:
190         enum {
191                 // answered by class numeric
192                 numeric,
193                 real,
194                 rational,
195                 integer,
196                 crational,
197                 cinteger,
198                 positive,
199                 negative,
200                 nonnegative,
201                 posint,
202                 negint,
203                 nonnegint,
204                 even,
205                 odd,
206                 prime,
207
208                 // answered by class relation
209                 relation,
210                 relation_equal,
211                 relation_not_equal,
212                 relation_less,
213                 relation_less_or_equal,
214                 relation_greater,
215                 relation_greater_or_equal,
216
217                 // answered by class symbol
218                 symbol,
219
220                 // answered by class lst
221                 list,
222
223                 // answered by class exprseq
224                 exprseq,
225
226                 // answered by classes numeric, symbol, add, mul, power
227                 polynomial,
228                 integer_polynomial,
229                 cinteger_polynomial,
230                 rational_polynomial,
231                 crational_polynomial,
232                 rational_function,
233                 algebraic,
234
235                 // answered by class indexed
236                 indexed,      // class can carry indices
237                 has_indices,  // object has at least one index
238
239                 // answered by class idx
240                 idx
241         };
242 };
243
244 class return_types {
245 public:
246         enum {
247                 commutative,
248                 noncommutative,
249                 noncommutative_composite
250         };
251 };
252
253 /** Strategies how to clean up the function remember cache.
254  *  @see remember_table */
255 class remember_strategies {
256 public:
257         enum {
258                 delete_never,   ///< Let table grow undefinitely
259                 delete_lru,     ///< Least recently used
260                 delete_lfu,     ///< Least frequently used
261                 delete_cyclic   ///< First (oldest) one in list
262         };
263 };
264
265 } // namespace GiNaC
266
267 #endif // ndef __GINAC_FLAGS_H__