]> www.ginac.de Git - ginac.git/blob - ginac/power.h
65c86b7e8618cd68a3b4875e9eaa9dcad7d81a8f
[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-2001 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 "basic.h"
27 #include "ex.h"
28
29 #ifndef NO_NAMESPACE_GINAC
30 namespace GiNaC {
31 #endif // ndef NO_NAMESPACE_GINAC
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         // other constructors
47 public:
48         power(const ex & lh, const ex & rh);
49         power(const ex & lh, const numeric & rh);
50
51         // functions overriding virtual functions from bases classes
52 public:
53         basic * duplicate() const;
54         void print(std::ostream & os, unsigned upper_precedence = 0) const;
55         void printraw(std::ostream & os) const;
56         void printtree(std::ostream & os, unsigned indent) const;
57         void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence = 0) const;
58         bool info(unsigned inf) const;
59         unsigned nops() const;
60         ex & let_op(int i);
61         int degree(const symbol & s) const;
62         int ldegree(const symbol & s) const;
63         ex coeff(const symbol & s, int n = 1) const;
64         ex eval(int level=0) const;
65         ex evalf(int level=0) const;
66         ex series(const relational & s, int order, unsigned options = 0) const;
67         ex subs(const lst & ls, const lst & lr) const;
68         ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
69         ex to_rational(lst &repl_lst) const;
70         ex simplify_ncmul(const exvector & v) const;
71 protected:
72         ex derivative(const symbol & s) const;
73         int compare_same_type(const basic & other) const;
74         unsigned return_type(void) const;
75         unsigned return_type_tinfo(void) const;
76         ex expand(unsigned options = 0) const;
77         
78         // new virtual functions which can be overridden by derived classes
79         // none
80         
81         // non-virtual functions in this class
82 protected:
83         ex expand_add(const add & a, int n) const;
84         ex expand_add_2(const add & a) const;
85         ex expand_mul(const mul & m, const numeric & n) const;
86         //ex expand_commutative_3(const ex & basis, const numeric & exponent,
87         //                        unsigned options) const;
88         //ex expand_noncommutative(const ex & basis, const numeric & exponent, unsigned options) const;
89
90 // member variables
91
92 protected:
93         ex basis;
94         ex exponent;
95         static unsigned precedence;
96 };
97
98 // utility functions
99 inline const power &ex_to_power(const ex &e)
100 {
101         return static_cast<const power &>(*e.bp);
102 }
103
104 // wrapper functions
105
106 /** Symbolic exponentiation.  Returns a power-object as a new expression.
107  *
108  *  @param b the basis expression
109  *  @param e the exponent expression */
110 inline ex pow(const ex & b, const ex & e)
111 { return power(b,e); }
112
113 /** Square root expression.  Returns a power-object with exponent 1/2 as a new
114  *  expression.  */
115 ex sqrt(const ex & a);
116
117 #ifndef NO_NAMESPACE_GINAC
118 } // namespace GiNaC
119 #endif // ndef NO_NAMESPACE_GINAC
120
121 #endif // ndef __GINAC_POWER_H__