]> www.ginac.de Git - ginac.git/blob - ginac/inifcns.h
New branch "experimental_fclasses" created for testing new function system.
[ginac.git] / ginac / inifcns.h
1 /** @file inifcns.h
2  *
3  *  Interface to GiNaC's initially known functions. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2006 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_INIFCNS_H__
24 #define __GINAC_INIFCNS_H__
25
26 #include "numeric.h"
27 #include "function.h"
28 #include "ex.h"
29
30 namespace GiNaC {
31
32 /** Absolute value. */
33 class abs_function : public function
34 {
35         GINAC_DECLARE_FUNCTION_1P(abs_function)
36 public:
37         virtual ex conjugate() const;
38         virtual ex eval(int level = 0) const;
39         virtual ex evalf(int level = 0) const;
40         virtual ex power_law(const ex& exp) const;
41 protected:
42         void do_print_csrc_float(const print_context& c, unsigned level) const;
43         void do_print_latex(const print_context& c, unsigned level) const;
44 };
45
46 template<typename T1> inline abs_function abs(const T1& x1) { return abs_function(x1); }
47 inline abs_function abs(double x1) { return abs_function(x1); }
48 inline abs_function abs(float x1) { return abs_function(x1); }
49
50 /** Complex conjugate. */
51 GINAC_FUNCTION_1P(conjugate,
52                 GINAC_FUNCTION_conjugate
53                 GINAC_FUNCTION_eval
54                 GINAC_FUNCTION_evalf
55                 GINAC_FUNCTION_print_latex)
56
57 /** Complex sign. */
58 GINAC_FUNCTION_1P(csgn,
59                 GINAC_FUNCTION_conjugate
60                 GINAC_FUNCTION_eval
61                 GINAC_FUNCTION_evalf
62                 GINAC_FUNCTION_power_law
63                 GINAC_FUNCTION_series)
64
65 /** Step function. */
66 class step_function : public function
67 {
68         GINAC_DECLARE_FUNCTION_1P(step_function)
69 public:
70         virtual ex conjugate() const;
71         virtual ex eval(int level = 0) const;
72         virtual ex evalf(int level = 0) const;
73         virtual ex series(const relational& r, int order, unsigned options = 0) const;
74 };
75
76 template<typename T1> inline step_function step(const T1& x1) { return step_function(x1); }
77
78 /** Factorial function. */
79 class factorial_function : public function
80 {
81         GINAC_DECLARE_FUNCTION_1P(factorial_function)
82 public:
83         virtual ex conjugate() const;
84         virtual ex eval(int level = 0) const;
85         virtual ex evalf(int level = 0) const;
86 protected:
87         void do_print_dflt_latex(const print_context& c, unsigned level) const;
88 };
89
90 template<typename T1> inline factorial_function factorial(const T1& x1) { return factorial_function(x1); }
91
92 /** Binomial function. */
93 class binomial_function : public function
94 {
95         GINAC_DECLARE_FUNCTION_2P(binomial_function)
96 public:
97         virtual ex conjugate() const;
98         virtual ex eval(int level = 0) const;
99         virtual ex evalf(int level = 0) const;
100 protected:
101         ex sym(const ex& x, const numeric& y) const;
102 };
103
104 template<typename T1, typename T2> inline binomial_function binomial(const T1& x1, const T2& x2) { return binomial_function(x1, x2); }
105
106 /** Order term function (for truncated power series). */
107 class Order_function : public function
108 {
109         GINAC_DECLARE_FUNCTION_1P(Order_function)
110 public:
111         virtual ex conjugate() const;
112         virtual ex derivative(const symbol& s) const;
113         virtual ex eval(int level = 0) const;
114         virtual ex series(const relational& r, int order, unsigned options = 0) const;
115 protected:
116         void do_print_latex(const print_context& c, unsigned level) const;
117 };
118
119 template<typename T1> inline Order_function Order(const T1& x1) { return Order_function(x1); }
120
121 /** Abstract derivative of functions. */
122 class function_derivative_function : public function
123 {
124         GINAC_DECLARE_FUNCTION_2P(function_derivative_function)
125 public:
126         virtual ex derivative(const symbol& s) const;
127         virtual ex eval(int level = 0) const;
128 protected:
129         void do_print_dflt(const print_context& c, unsigned level) const;
130         void do_print_tree(const print_tree& c, unsigned level) const;
131 };
132
133 template<typename T1, typename T2>
134 inline function_derivative_function function_derivative(const T1& x1, const T2& x2) { return function_derivative_function(x1, x2); }
135
136 ex lsolve(const ex& eqns, const ex& symbols, unsigned options = solve_algo::automatic);
137
138 /** Find a real root of real-valued function f(x) numerically within a given
139  *  interval. The function must change sign across interval. Uses Newton-
140  *  Raphson method combined with bisection in order to guarantee convergence.
141  *
142  *  @param f  Function f(x)
143  *  @param x  Symbol f(x)
144  *  @param x1  lower interval limit
145  *  @param x2  upper interval limit
146  *  @exception runtime_error (if interval is invalid). */
147 const numeric fsolve(const ex& f, const symbol& x, const numeric& x1, const numeric& x2);
148
149 } // namespace GiNaC
150
151 #endif // ndef __GINAC_INIFCNS_H__