]> www.ginac.de Git - ginac.git/blob - ginac/symbol.h
Added series expansion for functions (classical) Li and S around x==0.
[ginac.git] / ginac / symbol.h
1 /** @file symbol.h
2  *
3  *  Interface to GiNaC's symbolic objects. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2005 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_SYMBOL_H__
24 #define __GINAC_SYMBOL_H__
25
26 #include <string>
27 #include "basic.h"
28 #include "ex.h"
29 #include "ptr.h"
30
31 namespace GiNaC {
32
33 /** Basic CAS symbol.  It has a name because it must know how to output itself.
34  *  It may be assigned an expression, but this feature is only intended for
35  *  programs like 'ginsh' that want to associate symbols with expressions.
36  *  If you want to replace symbols by expressions in your code, you should
37  *  use ex::subs() or use objects of class ex instead of class symbol in the
38  *  first place. */
39 class symbol : public basic
40 {
41         GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
42
43         friend class realsymbol;
44
45 // types
46         
47         /** Symbols as keys to expressions - only for ginsh. */
48         class assigned_ex_info : public refcounted {
49         public:
50                 assigned_ex_info() throw();  ///< Default ctor
51                 bool is_assigned;            ///< True if there is an expression assigned
52                 ex assigned_expression;      ///< The actual expression
53         };
54
55 // member functions
56         
57         // other constructors
58 public:
59         explicit symbol(const std::string & initname, unsigned domain = domain::complex);
60         symbol(const std::string & initname, const std::string & texname, unsigned domain = domain::complex);
61         symbol(const std::string & initname, unsigned rt, unsigned rtt, unsigned domain = domain::complex);
62         symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt, unsigned domain = domain::complex);
63         
64         // functions overriding virtual functions from base classes
65 public:
66         bool info(unsigned inf) const;
67         ex eval(int level = 0) const;
68         ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
69         ex series(const relational & s, int order, unsigned options = 0) const;
70         ex subs(const exmap & m, unsigned options = 0) const { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
71         ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
72         ex to_rational(exmap & repl) const;
73         ex to_polynomial(exmap & repl) const;
74         unsigned return_type() const { return ret_type; }
75         unsigned return_type_tinfo() const { return ret_type_tinfo; }
76         ex conjugate() const;
77 protected:
78         ex derivative(const symbol & s) const;
79         bool is_equal_same_type(const basic & other) const;
80         unsigned calchash() const;
81         
82         // non-virtual functions in this class
83 public:
84         void assign(const ex & value);
85         void unassign();
86         void set_name(const std::string & n) { name = n; }
87         std::string get_name() const { return name; }
88         unsigned get_domain() const { return domain; }
89 protected:
90         void do_print(const print_context & c, unsigned level) const;
91         void do_print_latex(const print_latex & c, unsigned level) const;
92         void do_print_tree(const print_tree & c, unsigned level) const;
93         void do_print_python_repr(const print_python_repr & c, unsigned level) const;
94 private:
95         std::string & autoname_prefix();
96         std::string default_TeX_name() const;
97
98 // member variables
99
100 protected:
101         ptr<assigned_ex_info> asexinfop; ///< assigned expression, only for private use by ginsh
102         unsigned serial;                 ///< unique serial number for comparison
103         std::string name;                ///< printname of this symbol
104         std::string TeX_name;            ///< LaTeX name of this symbol
105         unsigned domain;                 ///< domain of symbol, complex (default) or real
106         unsigned ret_type;               ///< value returned by return_type()
107         unsigned ret_type_tinfo;         ///< value returned by return_type_tinfo()
108 private:
109         static unsigned next_serial;
110 };
111
112
113 /** Specialization of symbol to real domain */
114 class realsymbol : public symbol
115 {
116         // constructors
117 public:
118         realsymbol();
119         explicit realsymbol(const std::string & initname, unsigned domain = domain::real);
120         realsymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::real);
121         realsymbol(const std::string & initname, unsigned rt, unsigned rtt, unsigned domain = domain::real);
122         realsymbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt, unsigned domain = domain::real);
123 };
124
125
126 // utility functions
127
128 /** Specialization of is_exactly_a<symbol>(obj) for symbol objects. */
129 template<> inline bool is_exactly_a<symbol>(const basic & obj)
130 {
131         return obj.tinfo() == TINFO_symbol;
132 }
133
134 /** Specialization of is_exactly_a<realsymbol>(obj) for realsymbol objects. */
135 template<> inline bool is_exactly_a<realsymbol>(const basic & obj)
136 {
137         return (obj.tinfo() == TINFO_symbol) && (static_cast<const symbol &>(obj).get_domain() == domain::real);
138 }
139
140 // wrapper functions around member functions
141 inline void unassign(symbol & symarg)
142 { symarg.unassign(); }
143
144 } // namespace GiNaC
145
146 #endif // ndef __GINAC_SYMBOL_H__