]> www.ginac.de Git - ginac.git/blob - ginac/power.h
- enforced GiNaC coding standards :-)
[ginac.git] / ginac / power.h
1 /** @file power.h
2  *
3  *  Interface to GiNaC's symbolic exponentiation (basis^exponent).
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef __GINAC_POWER_H__
23 #define __GINAC_POWER_H__
24
25 class power;
26 class numeric;
27 class add;
28
29 /** This class holds a two-component object, a basis and and exponent
30  *  representing exponentiation. */
31 class power : public basic
32 {
33     friend class mul;
34
35 // member functions
36
37     // default constructor, destructor, copy constructor assignment operator and helpers
38 public:
39     power();
40     ~power();
41     power(power const & other);
42     power const & operator=(power const & other);
43 protected:
44     void copy(power const & other);
45     void destroy(bool call_parent);
46
47     // other constructors
48 public:
49     power(ex const & lh, ex const & rh);
50     power(ex const & lh, numeric const & rh);
51
52     // functions overriding virtual functions from bases classes
53 public:
54     basic * duplicate() const;
55     void printraw(ostream & os) const;
56     void printtree(ostream & os, unsigned indent) const;
57     void print(ostream & os, unsigned upper_precedence=0) const;
58     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
59     bool info(unsigned inf) const;
60     int nops() const;
61     ex & let_op(int const i);
62     int degree(symbol const & s) const;
63     int ldegree(symbol const & s) const;
64     ex coeff(symbol const & s, int const n=1) const;
65     ex eval(int level=0) const;
66     ex evalf(int level=0) const;
67     ex diff(symbol const & s) const;
68     ex series(symbol const & s, ex const & point, int order) const;
69     ex subs(lst const & ls, lst const & lr) const;
70     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
71     ex simplify_ncmul(exvector const & v) const;
72 protected:
73     int compare_same_type(basic const & other) const;
74     unsigned return_type(void) const;
75     unsigned return_type_tinfo(void) const;
76     ex expand(unsigned options=0) const;
77     
78     // new virtual functions which can be overridden by derived classes
79     // none
80     
81     // non-virtual functions in this class
82 protected:
83     ex expand_add(add const & a, int const n) const;
84     ex expand_add_2(add const & a) const;
85     ex expand_mul(mul const & m, numeric const & n) const;
86     //ex expand_commutative_3(ex const & basis, numeric const & exponent,
87     //                         unsigned options) const;
88     // ex expand_noncommutative(ex const & basis, numeric const & exponent, unsigned options) const;
89
90 // member variables
91
92 protected:
93     ex basis;
94     ex exponent;
95     static unsigned precedence;
96 };
97
98 // global constants
99
100 extern const power some_power;
101 extern type_info const & typeid_power;
102
103 #define ex_to_power(X) static_cast<power const &>(*(X).bp)
104
105 // wrapper functions
106
107 /** Symbolic exponentiation.  Returns a power-object as a new expression.
108  *
109  *  @param b the basis expression
110  *  @param e the exponent expression */
111 inline ex pow(ex const & b, ex const & e)
112 { return power(b,e); }
113
114 /** Square root expression.  Returns a power-object with exponent 1/2 as a new
115  *  expression.  */
116 inline ex sqrt(ex const & a)
117 { return power(a,exHALF()); }
118
119 #endif // ndef __GINAC_POWER_H__
120