GiNaC 1.8.10
power.h
Go to the documentation of this file.
1
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.
#define GINAC_DECLARE_UNARCHIVER(classname)
Helper macros to register a class with (un)archiving (a.k.a.
Definition archive.h:218
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
This class holds archived versions of GiNaC expressions (class ex).
Definition archive.h:254
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition basic.h:104
Wrapper template for making GiNaC classes out of STL containers.
Definition container.h:72
Lightweight wrapper for GiNaC's symbolic objects.
Definition ex.h:72
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
ex normal(exmap &repl, exmap &rev_lookup, lst &modifier) const override
Implementation of ex::normal() for powers.
Definition normal.cpp:2437
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
int degree(const ex &s) const override
Return degree of highest power in object s.
Definition power.cpp:299
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition power.cpp:71
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition power.cpp:613
int ldegree(const ex &s) const override
Return degree of lowest power in object s.
Definition power.cpp:314
static ex expand_add_2(const add &a, unsigned options)
Special case of power::expand_add.
Definition power.cpp:1037
ex real_part() const override
Definition power.cpp:665
ex derivative(const symbol &s) const override
Implementation of ex::diff() for a power.
Definition power.cpp:742
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
ex eval() const override
Perform automatic term rewriting rules in this class.
Definition power.cpp:372
void do_print_python(const print_python &c, unsigned level) const
Definition power.cpp:208
ex series(const relational &s, int order, unsigned options=0) const override
Implementation of ex::series() for powers.
Definition pseries.cpp:1084
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for powers.
Definition normal.cpp:2703
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
ex op(size_t i) const override
Return operand/member at position i.
Definition power.cpp:266
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
ex conjugate() const override
Definition power.cpp:644
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for powers.
Definition normal.cpp:2713
ex coeff(const ex &s, int n=1) const override
Return coefficient of degree n in object s.
Definition power.cpp:329
bool has(const ex &other, unsigned options=0) const override
Test for occurrence of a pattern.
Definition power.cpp:588
ex evalm() const override
Evaluate sums, products and integer powers of matrices.
Definition power.cpp:576
return_type_t return_type_tinfo() const override
Definition power.cpp:771
size_t nops() const override
Number of operands/members.
Definition power.cpp:261
ex expand(unsigned options=0) const override
Expand expression, i.e.
Definition power.cpp:776
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
ex imag_part() const override
Definition power.cpp:701
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
Definition power.cpp:285
ex evalf() const override
Evaluate object numerically.
Definition power.cpp:563
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.
unsigned options
Definition factor.cpp:2473
size_t n
Definition factor.cpp:1431
size_t c
Definition factor.cpp:756
exset syms
Definition factor.cpp:2427
mvec m
Definition factor.cpp:757
Definition add.cpp:35
const numeric pow(const numeric &x, const numeric &y)
Definition numeric.h:250
const ex _ex1_2
Definition utils.cpp:380
std::map< ex, ex, ex_is_less > exmap
Definition basic.h:49
const numeric sqrt(const numeric &x)
Numeric square root.
Definition numeric.cpp:2479
std::vector< ex > exvector
Definition basic.h:47
#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.