GiNaC  1.8.0
symbol.h
Go to the documentation of this file.
1 
5 /*
6  * GiNaC Copyright (C) 1999-2020 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 "basic.h"
27 #include "ex.h"
28 #include "ptr.h"
29 #include "archive.h"
30 
31 #include <string>
32 #include <typeinfo>
33 
34 namespace GiNaC {
35 
38 class symbol : public basic
39 {
41  // other constructors
42 public:
43  explicit symbol(const std::string & initname);
44  symbol(const std::string & initname, const std::string & texname);
45 
46  // functions overriding virtual functions from base classes
47 public:
48  bool info(unsigned inf) const override;
49  ex eval() const override { return *this; } // for performance reasons
50  ex evalf() const override { return *this; } // overwrites basic::evalf() for performance reasons
51  ex series(const relational & s, int order, unsigned options = 0) const override;
52  ex subs(const exmap & m, unsigned options = 0) const override { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
53  ex normal(exmap & repl, exmap & rev_lookup, lst & modifier) const override;
54  ex to_rational(exmap & repl) const override;
55  ex to_polynomial(exmap & repl) const override;
56  ex conjugate() const override;
57  ex real_part() const override;
58  ex imag_part() const override;
59  bool is_polynomial(const ex & var) const override;
61  void archive(archive_node& n) const override;
63  void read_archive(const archive_node& n, lst& syms) override;
64 protected:
65  ex derivative(const symbol & s) const override;
66  bool is_equal_same_type(const basic & other) const override;
67  unsigned calchash() const override;
68 
69  // new virtual functions which can be overridden by derived classes
70 public:
71  virtual unsigned get_domain() const { return domain::complex; }
72 
73  // non-virtual functions in this class
74 public:
75  void set_name(const std::string & n) { name = n; }
76  void set_TeX_name(const std::string & n) { TeX_name = n; }
77  std::string get_name() const;
78  std::string get_TeX_name() const;
79 protected:
80  void do_print(const print_context & c, unsigned level) const;
81  void do_print_latex(const print_latex & c, unsigned level) const;
82  void do_print_tree(const print_tree & c, unsigned level) const;
83  void do_print_python_repr(const print_python_repr & c, unsigned level) const;
84 
85 // member variables
86 
87 protected:
88  unsigned serial;
89  mutable std::string name;
90  std::string TeX_name;
91 private:
92  static unsigned next_serial;
93 };
95 
96 
98 class realsymbol : public symbol
99 {
100 public:
101  realsymbol();
102  explicit realsymbol(const std::string & initname);
103  realsymbol(const std::string & initname, const std::string & texname);
104 
105  unsigned get_domain() const override { return domain::real; }
106 
107  ex conjugate() const override { return *this; }
108  ex real_part() const override { return *this; }
109  ex imag_part() const override { return 0; }
110 
111  realsymbol* duplicate() const override
112  {
113  realsymbol * bp = new realsymbol(*this);
115  return bp;
116  }
117 };
118 GINAC_DECLARE_UNARCHIVER(realsymbol);
119 
120 
122 class possymbol : public realsymbol
123 {
124 public:
125  possymbol();
126  explicit possymbol(const std::string & initname);
127  possymbol(const std::string & initname, const std::string & texname);
128 
129  unsigned get_domain() const override { return domain::positive; }
130 
131  possymbol* duplicate() const override
132  {
133  possymbol * bp = new possymbol(*this);
135  return bp;
136  }
137 };
138 GINAC_DECLARE_UNARCHIVER(possymbol);
139 
140 } // namespace GiNaC
141 
142 #endif // ndef GINAC_SYMBOL_H
std::string get_name() const
Definition: symbol.cpp:152
ex conjugate() const override
Definition: symbol.h:107
exset syms
Definition: factor.cpp:2434
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
Definition: symbol.cpp:271
Reference-counted pointer template.
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: symbol.cpp:100
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for symbols.
Definition: normal.cpp:2629
void do_print(const print_context &c, unsigned level) const
Definition: symbol.cpp:170
ex normal(exmap &repl, exmap &rev_lookup, lst &modifier) const override
Implementation of ex::normal() for symbols.
Definition: normal.cpp:2212
const basic & setflag(unsigned f) const
Set some status_flags.
Definition: basic.h:288
Definition: add.cpp:38
This class holds a relation consisting of two expressions and a logical relation between them...
Definition: relational.h:34
unsigned calchash() const override
Compute the hash value of an object and if it makes sense to store it in the objects status_flags...
Definition: symbol.cpp:278
Archiving of GiNaC expressions.
This class is the ABC (abstract base class) of GiNaC&#39;s class hierarchy.
Definition: basic.h:104
Context for python-parsable output.
Definition: print.h:138
possymbol * duplicate() const override
Create a clone of this object on the heap.
Definition: symbol.h:131
realsymbol * duplicate() const override
Create a clone of this object on the heap.
Definition: symbol.h:111
ex derivative(const symbol &s) const override
Implementation of ex::diff() for single differentiation of a symbol.
Definition: symbol.cpp:255
virtual unsigned get_domain() const
Definition: symbol.h:71
bool info(unsigned inf) const override
Information about the object.
Definition: symbol.cpp:206
void do_print_latex(const print_latex &c, unsigned level) const
Definition: symbol.cpp:175
void set_name(const std::string &n)
Definition: symbol.h:75
Context for latex-parsable output.
Definition: print.h:122
std::string name
printname of this symbol
Definition: symbol.h:89
Specialization of symbol to real domain.
Definition: symbol.h:98
unsigned serial
unique serial number for comparison
Definition: symbol.h:88
unsigned options
Definition: factor.cpp:2480
unsigned get_domain() const override
Definition: symbol.h:105
mvec m
Definition: factor.cpp:771
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for symbols.
Definition: normal.cpp:2622
ex subs_one_level(const exmap &m, unsigned options) const
Helper function for subs().
Definition: basic.cpp:585
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition: symbol.h:52
ex imag_part() const override
Definition: symbol.h:109
ex conjugate() const override
Definition: symbol.cpp:229
void set_TeX_name(const std::string &n)
Definition: symbol.h:76
symbol(const std::string &initname)
Definition: symbol.cpp:69
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition: symbol.cpp:194
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
std::string TeX_name
LaTeX name of this symbol.
Definition: symbol.h:90
void archive(archive_node &n) const override
Save (a.k.a.
Definition: symbol.cpp:133
ex evalf() const override
Evaluate object numerically.
Definition: symbol.h:50
size_t n
Definition: factor.cpp:1463
Interface to GiNaC&#39;s light-weight expression handles.
Base class for print_contexts.
Definition: print.h:102
static unsigned next_serial
Definition: symbol.h:92
ex real_part() const override
Definition: symbol.cpp:234
ex real_part() const override
Definition: symbol.h:108
Interface to GiNaC&#39;s ABC.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:48
Lightweight wrapper for GiNaC&#39;s symbolic objects.
Definition: ex.h:72
void do_print_tree(const print_tree &c, unsigned level) const
Definition: symbol.cpp:185
Specialization of symbol to real positive domain.
Definition: symbol.h:122
unsigned get_domain() const override
Definition: symbol.h:129
int order
Basic CAS symbol.
Definition: symbol.h:38
std::string get_TeX_name() const
Definition: symbol.cpp:160
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
GINAC_DECLARE_UNARCHIVER(add)
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
Definition: symbol.h:49
ex imag_part() const override
Definition: symbol.cpp:239
heap-allocated (i.e. created by new if we want to be clever and bypass the stack, ...
Definition: flags.h:202
size_t c
Definition: factor.cpp:770
ex series(const relational &s, int order, unsigned options=0) const override
Implementation of ex::series() for symbols.
Definition: pseries.cpp:657
Context for tree-like output for debugging.
Definition: print.h:146
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
Definition: symbol.cpp:244

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.