]> www.ginac.de Git - ginac.git/blob - ginac/power.h
8533a0693ed1639807fbc301d585bbccc7e94e66
[ginac.git] / ginac / power.h
1 /** @file power.h
2  *
3  *  Interface to GiNaC's symbolic exponentiation (basis^exponent).
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_POWER_H__
23 #define __GINAC_POWER_H__
24
25 #include <ginac/basic.h>
26 #include <ginac/ex.h>
27
28 class numeric;
29 class add;
30
31 /** This class holds a two-component object, a basis and and exponent
32  *  representing exponentiation. */
33 class power : public basic
34 {
35     friend class mul;
36
37 // member functions
38
39     // default constructor, destructor, copy constructor assignment operator and helpers
40 public:
41     power();
42     ~power();
43     power(power const & other);
44     power const & operator=(power const & other);
45 protected:
46     void copy(power const & other);
47     void destroy(bool call_parent);
48
49     // other constructors
50 public:
51     power(ex const & lh, ex const & rh);
52     power(ex const & lh, numeric const & rh);
53
54     // functions overriding virtual functions from bases classes
55 public:
56     basic * duplicate() const;
57     void printraw(ostream & os) const;
58     void printtree(ostream & os, unsigned indent) const;
59     void print(ostream & os, unsigned upper_precedence=0) const;
60     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
61     bool info(unsigned inf) const;
62     int nops() const;
63     ex & let_op(int const i);
64     int degree(symbol const & s) const;
65     int ldegree(symbol const & s) const;
66     ex coeff(symbol const & s, int const n=1) const;
67     ex eval(int level=0) const;
68     ex evalf(int level=0) const;
69     ex diff(symbol const & s) const;
70     ex series(symbol const & s, ex const & point, int order) const;
71     ex subs(lst const & ls, lst const & lr) const;
72     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
73     ex simplify_ncmul(exvector const & v) const;
74 protected:
75     int compare_same_type(basic const & other) const;
76     unsigned return_type(void) const;
77     unsigned return_type_tinfo(void) const;
78     ex expand(unsigned options=0) const;
79     
80     // new virtual functions which can be overridden by derived classes
81     // none
82     
83     // non-virtual functions in this class
84 protected:
85     ex expand_add(add const & a, int const n) const;
86     ex expand_add_2(add const & a) const;
87     ex expand_mul(mul const & m, numeric const & n) const;
88     //ex expand_commutative_3(ex const & basis, numeric const & exponent,
89     //                         unsigned options) const;
90     // ex expand_noncommutative(ex const & basis, numeric const & exponent, unsigned options) const;
91
92 // member variables
93
94 protected:
95     ex basis;
96     ex exponent;
97     static unsigned precedence;
98 };
99
100 // global constants
101
102 extern const power some_power;
103 extern type_info const & typeid_power;
104
105 #define ex_to_power(X) static_cast<power const &>(*(X).bp)
106
107 // wrapper functions
108
109 /** Symbolic exponentiation.  Returns a power-object as a new expression.
110  *
111  *  @param b the basis expression
112  *  @param e the exponent expression */
113 inline ex pow(ex const & b, ex const & e)
114 { return power(b,e); }
115
116 /** Square root expression.  Returns a power-object with exponent 1/2 as a new
117  *  expression.  */
118 inline ex sqrt(ex const & a)
119 { return power(a,exHALF()); }
120
121 #endif // ndef __GINAC_POWER_H__
122