]> www.ginac.de Git - ginac.git/blob - ginac/power.h
clifford_unit: fix possible bugs due to wrong operator[!=]= usage.
[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-2008 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  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 class mul;
34
35 /** This class holds a two-component object, a basis and and exponent
36  *  representing exponentiation. */
37 class power : public basic
38 {
39         GINAC_DECLARE_REGISTERED_CLASS(power, basic)
40         
41         friend class mul;
42         
43 // member functions
44         
45         // other constructors
46 public:
47         power(const ex & lh, const ex & rh) : inherited(&power::tinfo_static), basis(lh), exponent(rh) {}
48         template<typename T> power(const ex & lh, const T & rh) : inherited(&power::tinfo_static), basis(lh), exponent(rh) {}
49         
50         // functions overriding virtual functions from base classes
51 public:
52         unsigned precedence() const {return 60;}
53         bool info(unsigned inf) const;
54         size_t nops() const;
55         ex op(size_t i) const;
56         ex map(map_function & f) const;
57         bool is_polynomial(const ex & var) const;
58         int degree(const ex & s) const;
59         int ldegree(const ex & s) const;
60         ex coeff(const ex & s, int n = 1) const;
61         ex eval(int level=0) const;
62         ex evalf(int level=0) const;
63         ex evalm() const;
64         ex series(const relational & s, int order, unsigned options = 0) const;
65         ex subs(const exmap & m, unsigned options = 0) const;
66         bool has(const ex & other, unsigned options = 0) const;
67         ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
68         ex to_rational(exmap & repl) const;
69         ex to_polynomial(exmap & repl) const;
70         ex conjugate() const;
71         ex real_part() const;
72         ex imag_part() const;
73 protected:
74         ex derivative(const symbol & s) const;
75         ex eval_ncmul(const exvector & v) const;
76         unsigned return_type() const;
77         tinfo_t return_type_tinfo() 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         void print_power(const print_context & c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const;
86         void do_print_dflt(const print_dflt & c, unsigned level) const;
87         void do_print_latex(const print_latex & c, unsigned level) const;
88         void do_print_csrc(const print_csrc & c, unsigned level) const;
89         void do_print_python(const print_python & c, unsigned level) const;
90         void do_print_python_repr(const print_python_repr & c, unsigned level) const;
91         void do_print_csrc_cl_N(const print_csrc_cl_N & c, unsigned level) const;
92
93         ex expand_add(const add & a, int n, unsigned options) const;
94         ex expand_add_2(const add & a, unsigned options) const;
95         ex expand_mul(const mul & m, const numeric & n, unsigned options, bool from_expand = false) const;
96         
97 // member variables
98         
99 protected:
100         ex basis;
101         ex exponent;
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 {
112         return power(b, e);
113 }
114 template<typename T1, typename T2>
115 inline ex pow(const T1 & b, const T2 & e)
116 {
117         return power(ex(b), ex(e));
118 }
119
120 /** Square root expression.  Returns a power-object with exponent 1/2. */
121 inline ex sqrt(const ex & a)
122 {
123         extern const ex _ex1_2;
124         return power(a,_ex1_2);
125 }
126
127 } // namespace GiNaC
128
129 #endif // ndef __GINAC_POWER_H__