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

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