]> www.ginac.de Git - ginac.git/blob - ginac/power.h
- rotate_31() and golden_hash_ratio() moved to utils.h
[ginac.git] / ginac / power.h
1 /** @file power.h
2  *
3  *  Interface to GiNaC's symbolic exponentiation (basis^exponent). */
4
5 /*
6  *  GiNaC Copyright (C) 1999 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifndef __GINAC_POWER_H__
24 #define __GINAC_POWER_H__
25
26 #include <ginac/basic.h>
27 #include <ginac/ex.h>
28
29 namespace GiNaC {
30
31 class numeric;
32 class add;
33
34 /** This class holds a two-component object, a basis and and exponent
35  *  representing exponentiation. */
36 class power : public basic
37 {
38     friend class mul;
39
40 // member functions
41
42     // default constructor, destructor, copy constructor assignment operator and helpers
43 public:
44     power();
45     ~power();
46     power(power const & other);
47     power const & operator=(power const & other);
48 protected:
49     void copy(power const & other);
50     void destroy(bool call_parent);
51
52     // other constructors
53 public:
54     power(ex const & lh, ex const & rh);
55     power(ex const & lh, numeric const & rh);
56
57     // functions overriding virtual functions from bases classes
58 public:
59     basic * duplicate() const;
60     void printraw(ostream & os) const;
61     void printtree(ostream & os, unsigned indent) const;
62     void print(ostream & os, unsigned upper_precedence=0) const;
63     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
64     bool info(unsigned inf) const;
65     int nops() const;
66     ex & let_op(int const i);
67     int degree(symbol const & s) const;
68     int ldegree(symbol const & s) const;
69     ex coeff(symbol const & s, int const n=1) const;
70     ex eval(int level=0) const;
71     ex evalf(int level=0) const;
72     ex diff(symbol const & s) const;
73     ex series(symbol const & s, ex const & point, int order) const;
74     ex subs(lst const & ls, lst const & lr) const;
75     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
76     ex simplify_ncmul(exvector const & v) const;
77 protected:
78     int compare_same_type(basic const & other) const;
79     unsigned return_type(void) const;
80     unsigned return_type_tinfo(void) const;
81     ex expand(unsigned options=0) const;
82     
83     // new virtual functions which can be overridden by derived classes
84     // none
85     
86     // non-virtual functions in this class
87 protected:
88     ex expand_add(add const & a, int const n) const;
89     ex expand_add_2(add const & a) const;
90     ex expand_mul(mul const & m, numeric const & n) const;
91     //ex expand_commutative_3(ex const & basis, numeric const & exponent,
92     //                         unsigned options) const;
93     // ex expand_noncommutative(ex const & basis, numeric const & exponent, unsigned options) const;
94
95 // member variables
96
97 protected:
98     ex basis;
99     ex exponent;
100     static unsigned precedence;
101 };
102
103 // global constants
104
105 extern const power some_power;
106 extern type_info const & typeid_power;
107
108 // utility functions
109 inline const power &ex_to_power(const ex &e)
110 {
111         return static_cast<const power &>(*e.bp);
112 }
113
114 // wrapper functions
115
116 /** Symbolic exponentiation.  Returns a power-object as a new expression.
117  *
118  *  @param b the basis expression
119  *  @param e the exponent expression */
120 inline ex pow(ex const & b, ex const & e)
121 { return power(b,e); }
122
123 /** Square root expression.  Returns a power-object with exponent 1/2 as a new
124  *  expression.  */
125 inline ex sqrt(ex const & a)
126 { return power(a,exHALF()); }
127
128 } // namespace GiNaC
129
130 #endif // ndef __GINAC_POWER_H__