3 * Interface to GiNaC's symbolic exponentiation (basis^exponent). */
6 * GiNaC Copyright (C) 1999-2016 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36 /** This class holds a two-component object, a basis and and exponent
37 * representing exponentiation. */
38 class power : public basic
40 GINAC_DECLARE_REGISTERED_CLASS(power, basic)
48 power(const ex & lh, const ex & rh) : basis(lh), exponent(rh) {}
49 template<typename T> power(const ex & lh, const T & rh) : basis(lh), exponent(rh) {}
51 // functions overriding virtual functions from base classes
53 unsigned precedence() const override {return 60;}
54 bool info(unsigned inf) const override;
55 size_t nops() const override;
56 ex op(size_t i) const override;
57 ex map(map_function & f) const override;
58 bool is_polynomial(const ex & var) const override;
59 int degree(const ex & s) const override;
60 int ldegree(const ex & s) const override;
61 ex coeff(const ex & s, int n = 1) const override;
62 ex eval() const override;
63 ex evalf() const override;
64 ex evalm() const override;
65 ex series(const relational & s, int order, unsigned options = 0) const override;
66 ex subs(const exmap & m, unsigned options = 0) const override;
67 bool has(const ex & other, unsigned options = 0) const override;
68 ex normal(exmap & repl, exmap & rev_lookup) const override;
69 ex to_rational(exmap & repl) const override;
70 ex to_polynomial(exmap & repl) const override;
71 ex conjugate() const override;
72 ex real_part() const override;
73 ex imag_part() const override;
74 /** Save (a.k.a. serialize) object into archive. */
75 void archive(archive_node& n) const override;
76 /** Read (a.k.a. deserialize) object from archive. */
77 void read_archive(const archive_node& n, lst& syms) override;
79 ex derivative(const symbol & s) const override;
80 ex eval_ncmul(const exvector & v) const override;
81 unsigned return_type() const override;
82 return_type_t return_type_tinfo() const override;
83 ex expand(unsigned options = 0) const override;
85 // new virtual functions which can be overridden by derived classes
88 // non-virtual functions in this class
90 void print_power(const print_context & c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const;
91 void do_print_dflt(const print_dflt & c, unsigned level) const;
92 void do_print_latex(const print_latex & c, unsigned level) const;
93 void do_print_csrc(const print_csrc & c, unsigned level) const;
94 void do_print_python(const print_python & c, unsigned level) const;
95 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
96 void do_print_csrc_cl_N(const print_csrc_cl_N & c, unsigned level) const;
98 static ex expand_add(const add & a, long n, unsigned options);
99 static ex expand_add_2(const add & a, unsigned options);
100 static ex expand_mul(const mul & m, const numeric & n, unsigned options, bool from_expand = false);
108 GINAC_DECLARE_UNARCHIVER(power);
112 /** Symbolic exponentiation. Returns a power-object as a new expression.
114 * @param b the basis expression
115 * @param e the exponent expression */
116 inline ex pow(const ex & b, const ex & e)
118 return dynallocate<power>(b, e);
120 template<typename T1, typename T2>
121 inline ex pow(const T1 & b, const T2 & e)
123 return dynallocate<power>(ex(b), ex(e));
126 /** Square root expression. Returns a power-object with exponent 1/2. */
127 inline ex sqrt(const ex & a)
129 extern const ex _ex1_2;
130 return power(a,_ex1_2);
135 #endif // ndef GINAC_POWER_H