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

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