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