GiNaC 1.8.7
power.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2023 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#include "archive.h"
29
30namespace GiNaC {
31
32class numeric;
33class add;
34class mul;
35
38class power : public basic
39{
41
42 friend class mul;
43
44// member functions
45
46 // other constructors
47public:
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) {}
50
51 // functions overriding virtual functions from base classes
52public:
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, lst & modifier) 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;
75 void archive(archive_node& n) const override;
77 void read_archive(const archive_node& n, lst& syms) override;
78protected:
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;
84
85 // new virtual functions which can be overridden by derived classes
86 // none
87
88 // non-virtual functions in this class
89protected:
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;
97
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);
101
102// member variables
103
104protected:
107};
109
110// wrapper functions
111
116inline ex pow(const ex & b, const ex & e)
117{
118 return dynallocate<power>(b, e);
119}
120template<typename T1, typename T2>
121inline ex pow(const T1 & b, const T2 & e)
122{
123 return dynallocate<power>(ex(b), ex(e));
124}
125
127inline ex sqrt(const ex & a)
128{
129 extern const ex _ex1_2;
130 return power(a,_ex1_2);
131}
132
133} // namespace GiNaC
134
135#endif // ndef GINAC_POWER_H
Archiving of GiNaC expressions.
Interface to GiNaC's ABC.
Sum of expressions.
Definition: add.h:32
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:49
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
Product of expressions.
Definition: mul.h:32
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Definition: numeric.h:82
This class holds a two-component object, a basis and and exponent representing exponentiation.
Definition: power.h:39
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:1108
void do_print_dflt(const print_dflt &c, unsigned level) const
Definition: power.cpp:107
ex normal(exmap &repl, exmap &rev_lookup, lst &modifier) const override
Implementation of ex::normal() for powers.
Definition: normal.cpp:2438
void do_print_csrc(const print_csrc &c, unsigned level) const
Definition: power.cpp:179
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:897
int degree(const ex &s) const override
Return degree of highest power in object s.
Definition: power.cpp:301
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: power.cpp:73
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition: power.cpp:615
int ldegree(const ex &s) const override
Return degree of lowest power in object s.
Definition: power.cpp:316
static ex expand_add_2(const add &a, unsigned options)
Special case of power::expand_add.
Definition: power.cpp:1039
ex real_part() const override
Definition: power.cpp:667
void archive(archive_node &n) const override
Save (a.k.a.
Definition: power.cpp:80
ex derivative(const symbol &s) const override
Implementation of ex::diff() for a power.
Definition: power.cpp:744
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:275
ex eval() const override
Perform automatic term rewriting rules in this class.
Definition: power.cpp:374
ex basis
Definition: power.h:105
void do_print_python(const print_python &c, unsigned level) const
Definition: power.cpp:210
ex series(const relational &s, int order, unsigned options=0) const override
Implementation of ex::series() for powers.
Definition: pseries.cpp:1085
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for powers.
Definition: normal.cpp:2704
void print_power(const print_context &c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const
Definition: power.cpp:93
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition: power.cpp:215
ex exponent
Definition: power.h:106
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition: power.h:53
ex op(size_t i) const override
Return operand/member at position i.
Definition: power.cpp:268
void do_print_latex(const print_latex &c, unsigned level) const
Definition: power.cpp:120
power(const ex &lh, const T &rh)
Definition: power.h:49
ex conjugate() const override
Definition: power.cpp:646
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for powers.
Definition: normal.cpp:2714
ex coeff(const ex &s, int n=1) const override
Return coefficient of degree n in object s.
Definition: power.cpp:331
bool has(const ex &other, unsigned options=0) const override
Test for occurrence of a pattern.
Definition: power.cpp:590
ex evalm() const override
Evaluate sums, products and integer powers of matrices.
Definition: power.cpp:578
return_type_t return_type_tinfo() const override
Definition: power.cpp:773
size_t nops() const override
Number of operands/members.
Definition: power.cpp:263
ex expand(unsigned options=0) const override
Expand expression, i.e.
Definition: power.cpp:778
bool info(unsigned inf) const override
Information about the object.
Definition: power.cpp:224
ex eval_ncmul(const exvector &v) const override
Definition: power.cpp:641
void do_print_csrc_cl_N(const print_csrc_cl_N &c, unsigned level) const
Definition: power.cpp:164
unsigned return_type() const override
Definition: power.cpp:768
ex imag_part() const override
Definition: power.cpp:703
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
Definition: power.cpp:287
ex evalf() const override
Evaluate object numerically.
Definition: power.cpp:565
Base class for print_contexts.
Definition: print.h:103
Context for C source output using CLN numbers.
Definition: print.h:182
Base context for C source output.
Definition: print.h:158
Context for default (ginsh-parsable) output.
Definition: print.h:115
Context for latex-parsable output.
Definition: print.h:123
Context for python-parsable output.
Definition: print.h:139
Context for python pretty-print output.
Definition: print.h:131
This class holds a relation consisting of two expressions and a logical relation between them.
Definition: relational.h:35
Basic CAS symbol.
Definition: symbol.h:39
Interface to GiNaC's light-weight expression handles.
unsigned options
Definition: factor.cpp:2475
size_t n
Definition: factor.cpp:1432
size_t c
Definition: factor.cpp:757
exset syms
Definition: factor.cpp:2429
mvec m
Definition: factor.cpp:758
int order
Definition: add.cpp:38
const numeric pow(const numeric &x, const numeric &y)
Definition: numeric.h:251
const ex _ex1_2
Definition: utils.cpp:381
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
GINAC_DECLARE_UNARCHIVER(add)
const numeric sqrt(const numeric &x)
Numeric square root.
Definition: numeric.cpp:2480
std::vector< ex > exvector
Definition: basic.h:48
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
Function object for map().
Definition: basic.h:85
To distinguish between different kinds of non-commutative objects.
Definition: registrar.h:44

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