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