3 * Interface to GiNaC's symbolic exponentiation (basis^exponent). */
6 * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
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.
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.
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
23 #ifndef __GINAC_POWER_H__
24 #define __GINAC_POWER_H__
34 /** This class holds a two-component object, a basis and and exponent
35 * representing exponentiation. */
36 class power : public basic
38 GINAC_DECLARE_REGISTERED_CLASS(power, basic)
46 power(const ex & lh, const ex & rh) : inherited(TINFO_power), basis(lh), exponent(rh) {}
47 template<typename T> power(const ex & lh, const T & rh) : inherited(TINFO_power), basis(lh), exponent(rh) {}
49 // functions overriding virtual functions from base classes
51 unsigned precedence() const {return 60;}
52 bool info(unsigned inf) const;
54 ex op(size_t i) const;
55 ex map(map_function & f) const;
56 int degree(const ex & s) const;
57 int ldegree(const ex & s) const;
58 ex coeff(const ex & s, int n = 1) const;
59 ex eval(int level=0) const;
60 ex evalf(int level=0) const;
62 ex series(const relational & s, int order, unsigned options = 0) const;
63 ex subs(const exmap & m, unsigned options = 0) const;
64 ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
65 ex to_rational(lst &repl_lst) const;
66 ex to_polynomial(lst &repl_lst) const;
67 exvector get_free_indices() const;
69 ex derivative(const symbol & s) const;
70 ex eval_ncmul(const exvector & v) const;
71 unsigned return_type() const;
72 unsigned return_type_tinfo() const;
73 ex expand(unsigned options = 0) const;
75 // new virtual functions which can be overridden by derived classes
78 // non-virtual functions in this class
80 void print_power(const print_context & c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const;
81 void do_print_dflt(const print_dflt & c, unsigned level) const;
82 void do_print_latex(const print_latex & c, unsigned level) const;
83 void do_print_csrc(const print_csrc & c, unsigned level) const;
84 void do_print_python(const print_python & c, unsigned level) const;
85 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
87 ex expand_add(const add & a, int n) const;
88 ex expand_add_2(const add & a) const;
89 ex expand_mul(const mul & m, const numeric & n) const;
100 /** Efficient specialization of is_exactly_a<power>(obj) for power objects. */
101 template<> inline bool is_exactly_a<power>(const basic & obj)
103 return obj.tinfo()==TINFO_power;
108 /** Symbolic exponentiation. Returns a power-object as a new expression.
110 * @param b the basis expression
111 * @param e the exponent expression */
112 inline ex pow(const ex & b, const ex & e)
116 template<typename T1, typename T2>
117 inline ex pow(const T1 & b, const T2 & e)
119 return power(ex(b), ex(e));
122 /** Square root expression. Returns a power-object with exponent 1/2. */
123 inline ex sqrt(const ex & a)
125 extern const ex _ex1_2;
126 return power(a,_ex1_2);
131 #endif // ndef __GINAC_POWER_H__