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