GiNaC 1.8.10
power.h
Go to the documentation of this file.
1
4
5/*
6 * GiNaC Copyright (C) 1999-2026 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef GINAC_POWER_H
23#define GINAC_POWER_H
24
25#include "basic.h"
26#include "ex.h"
27#include "archive.h"
28
29namespace GiNaC {
30
31class numeric;
32class add;
33class mul;
34
37class power : public basic
38{
40
41 friend class mul;
42
43// member functions
44
45 // other constructors
46public:
47 power(const ex & lh, const ex & rh) : basis(lh), exponent(rh) {}
48 template<typename T> power(const ex & lh, const T & rh) : basis(lh), exponent(rh) {}
49
50 // functions overriding virtual functions from base classes
51public:
52 unsigned precedence() const override {return 60;}
53 bool info(unsigned inf) const override;
54 size_t nops() const override;
55 ex op(size_t i) const override;
56 ex map(map_function & f) const override;
57 bool is_polynomial(const ex & var) const override;
58 int degree(const ex & s) const override;
59 int ldegree(const ex & s) const override;
60 ex coeff(const ex & s, int n = 1) const override;
61 ex eval() const override;
62 ex evalf() const override;
63 ex evalm() const override;
64 ex series(const relational & s, int order, unsigned options = 0) const override;
65 ex subs(const exmap & m, unsigned options = 0) const override;
66 bool has(const ex & other, unsigned options = 0) const override;
67 ex normal(exmap & repl, exmap & rev_lookup, lst & modifier) const override;
68 ex to_rational(exmap & repl) const override;
69 ex to_polynomial(exmap & repl) const override;
70 ex conjugate() const override;
71 ex real_part() const override;
72 ex imag_part() const override;
74 void archive(archive_node& n) const override;
76 void read_archive(const archive_node& n, lst& syms) override;
77protected:
78 ex derivative(const symbol & s) const override;
79 ex eval_ncmul(const exvector & v) const override;
80 unsigned return_type() const override;
81 return_type_t return_type_tinfo() const override;
82 ex expand(unsigned options = 0) const override;
83
84 // new virtual functions which can be overridden by derived classes
85 // none
86
87 // non-virtual functions in this class
88protected:
89 void print_power(const print_context & c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const;
90 void do_print_dflt(const print_dflt & c, unsigned level) const;
91 void do_print_latex(const print_latex & c, unsigned level) const;
92 void do_print_csrc(const print_csrc & c, unsigned level) const;
93 void do_print_python(const print_python & c, unsigned level) const;
94 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
95 void do_print_csrc_cl_N(const print_csrc_cl_N & c, unsigned level) const;
96
97 static ex expand_add(const add & a, long n, unsigned options);
98 static ex expand_add_2(const add & a, unsigned options);
99 static ex expand_mul(const mul & m, const numeric & n, unsigned options, bool from_expand = false);
100
101// member variables
102
103protected:
106};
108
109// wrapper functions
110
115inline ex pow(const ex & b, const ex & e)
116{
117 return dynallocate<power>(b, e);
118}
119template<typename T1, typename T2>
120inline ex pow(const T1 & b, const T2 & e)
121{
122 return dynallocate<power>(ex(b), ex(e));
123}
124
126inline ex sqrt(const ex & a)
127{
128 extern const ex _ex1_2;
129 return power(a,_ex1_2);
130}
131
132} // namespace GiNaC
133
134#endif // ndef GINAC_POWER_H
Archiving of GiNaC expressions.
Interface to GiNaC's ABC.
Sum of expressions.
Definition add.h:31
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition archive.h:48
friend class ex
Definition basic.h:107
Lightweight wrapper for GiNaC's symbolic objects.
Definition ex.h:72
ex() noexcept
Definition ex.h:262
Product of expressions.
Definition mul.h:31
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Definition numeric.h:81
This class holds a two-component object, a basis and and exponent representing exponentiation.
Definition power.h:38
static ex expand_mul(const mul &m, const numeric &n, unsigned options, bool from_expand=false)
Expand factors of m in m^n where m is a mul and n is an integer.
Definition power.cpp:1106
void do_print_dflt(const print_dflt &c, unsigned level) const
Definition power.cpp:105
void do_print_csrc(const print_csrc &c, unsigned level) const
Definition power.cpp:177
static ex expand_add(const add &a, long n, unsigned options)
expand a^n where a is an add and n is a positive integer.
Definition power.cpp:895
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition power.cpp:71
static ex expand_add_2(const add &a, unsigned options)
Special case of power::expand_add.
Definition power.cpp:1037
ex derivative(const symbol &s) const override
Implementation of ex::diff() for a power.
Definition power.cpp:742
friend class mul
Definition power.h:41
ex map(map_function &f) const override
Construct new expression by applying the specified function to all sub-expressions (one level only,...
Definition power.cpp:273
void do_print_python(const print_python &c, unsigned level) const
Definition power.cpp:208
void print_power(const print_context &c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const
Definition power.cpp:91
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition power.cpp:213
ex exponent
Definition power.h:105
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition power.h:52
power(const ex &lh, const ex &rh)
Definition power.h:47
void do_print_latex(const print_latex &c, unsigned level) const
Definition power.cpp:118
power(const ex &lh, const T &rh)
Definition power.h:48
return_type_t return_type_tinfo() const override
Definition power.cpp:771
bool info(unsigned inf) const override
Information about the object.
Definition power.cpp:222
ex eval_ncmul(const exvector &v) const override
Definition power.cpp:639
void do_print_csrc_cl_N(const print_csrc_cl_N &c, unsigned level) const
Definition power.cpp:162
unsigned return_type() const override
Definition power.cpp:766
Base class for print_contexts.
Definition print.h:101
Context for C source output using CLN numbers.
Definition print.h:180
Base context for C source output.
Definition print.h:156
Context for default (ginsh-parsable) output.
Definition print.h:113
Context for latex-parsable output.
Definition print.h:121
Context for python-parsable output.
Definition print.h:137
Context for python pretty-print output.
Definition print.h:129
This class holds a relation consisting of two expressions and a logical relation between them.
Definition relational.h:34
Basic CAS symbol.
Definition symbol.h:38
Interface to GiNaC's light-weight expression handles.
Definition add.cpp:35
ex real_part(const ex &thisex)
Definition ex.h:736
const numeric pow(const numeric &x, const numeric &y)
Definition numeric.h:250
const ex _ex1_2
Definition utils.cpp:380
bool is_polynomial(const ex &thisex, const ex &vars)
Definition ex.h:748
container< std::list > lst
Definition lst.h:31
ex to_rational(const ex &thisex, exmap &repl)
Definition ex.h:772
std::map< ex, ex, ex_is_less > exmap
Definition basic.h:49
B & dynallocate(Args &&... args)
Constructs a new (class basic or derived) B object on the heap.
Definition basic.h:333
GINAC_DECLARE_UNARCHIVER(add)
const numeric sqrt(const numeric &x)
Numeric square root.
Definition numeric.cpp:2479
ex series(const ex &thisex, const ex &r, int order, unsigned options=0)
Definition ex.h:796
ex conjugate(const ex &thisex)
Definition ex.h:733
ex subs(const ex &thisex, const exmap &m, unsigned options=0)
Definition ex.h:846
ex eval(const ex &thisex)
Definition ex.h:781
int degree(const ex &thisex, const ex &s)
Definition ex.h:751
int ldegree(const ex &thisex, const ex &s)
Definition ex.h:754
ex evalf(const ex &thisex)
Definition ex.h:784
ex normal(const ex &thisex)
Definition ex.h:769
ex op(const ex &thisex, size_t i)
Definition ex.h:826
ex coeff(const ex &thisex, const ex &s, int n=1)
Definition ex.h:757
ex evalm(const ex &thisex)
Definition ex.h:787
bool has(const ex &thisex, const ex &pattern, unsigned options=0)
Definition ex.h:742
std::vector< ex > exvector
Definition basic.h:47
size_t nops(const ex &thisex)
Definition ex.h:727
ex imag_part(const ex &thisex)
Definition ex.h:739
ex to_polynomial(const ex &thisex, exmap &repl)
Definition ex.h:775
ex expand(const ex &thisex, unsigned options=0)
Definition ex.h:730
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition registrar.h:151
Function object for map().
Definition basic.h:84
To distinguish between different kinds of non-commutative objects.
Definition registrar.h:42

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.