]> www.ginac.de Git - ginac.git/blob - ginac/power.h
00f02b1f09f1dd7b3b706c839dc7ad1f3aa2f60d
[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 namespace GiNaC {
30
31 class numeric;
32 class add;
33
34 /** This class holds a two-component object, a basis and and exponent
35  *  representing exponentiation. */
36 class power : public basic
37 {
38         GINAC_DECLARE_REGISTERED_CLASS(power, basic)
39         
40         friend class mul;
41         
42 // member functions
43         
44         // other ctors
45 public:
46         power(const ex & lh, const ex & rh);
47         power(const ex & lh, const numeric & rh);
48         
49         // functions overriding virtual functions from bases classes
50 public:
51         void print(const print_context & c, unsigned level = 0) const;
52         unsigned precedence(void) const {return 60;}
53         bool info(unsigned inf) const;
54         unsigned nops() const;
55         ex & let_op(int i);
56         ex map(map_func f) const;
57         int degree(const ex & s) const;
58         int ldegree(const ex & s) const;
59         ex coeff(const ex & s, int n = 1) const;
60         ex eval(int level=0) const;
61         ex evalf(int level=0) const;
62         ex series(const relational & s, int order, unsigned options = 0) const;
63         ex subs(const lst & ls, const lst & lr, bool no_pattern = false) const;
64         ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
65         ex to_rational(lst &repl_lst) const;
66         exvector get_free_indices(void) const;
67         ex simplify_ncmul(const exvector & v) const;
68 protected:
69         ex derivative(const symbol & s) const;
70         unsigned return_type(void) const;
71         unsigned return_type_tinfo(void) const;
72         ex expand(unsigned options = 0) const;
73         
74         // new virtual functions which can be overridden by derived classes
75         // none
76         
77         // non-virtual functions in this class
78 protected:
79         ex expand_add(const add & a, int n) const;
80         ex expand_add_2(const add & a) const;
81         ex expand_mul(const mul & m, const numeric & n) const;
82         //ex expand_commutative_3(const ex & basis, const numeric & exponent,
83         //                        unsigned options) const;
84         //ex expand_noncommutative(const ex & basis, const numeric & exponent, unsigned options) const;
85         
86 // member variables
87         
88 protected:
89         ex basis;
90         ex exponent;
91 };
92
93 // utility functions
94 inline const power &ex_to_power(const ex &e)
95 {
96         return static_cast<const power &>(*e.bp);
97 }
98
99 // wrapper functions
100
101 /** Symbolic exponentiation.  Returns a power-object as a new expression.
102  *
103  *  @param b the basis expression
104  *  @param e the exponent expression */
105 inline ex pow(const ex & b, const ex & e)
106 {
107         return power(b, e);
108 }
109
110 /** Square root expression.  Returns a power-object with exponent 1/2. */
111 ex sqrt(const ex & a);
112
113 } // namespace GiNaC
114
115 #endif // ndef __GINAC_POWER_H__