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 };
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 };
139 
140 } // namespace GiNaC
141 
142 #endif // ndef GINAC_SYMBOL_H
GiNaC::print_python_repr
Context for python-parsable output.
Definition: print.h:139
GiNaC::possymbol::get_domain
unsigned get_domain() const override
Definition: symbol.h:129
GiNaC::symbol::next_serial
static unsigned next_serial
Definition: symbol.h:92
GiNaC::symbol::name
std::string name
printname of this symbol
Definition: symbol.h:89
GiNaC::symbol::get_domain
virtual unsigned get_domain() const
Definition: symbol.h:71
GiNaC::realsymbol::real_part
ex real_part() const override
Definition: symbol.h:108
GiNaC::symbol::normal
ex normal(exmap &repl, exmap &rev_lookup, lst &modifier) const override
Implementation of ex::normal() for symbols.
Definition: normal.cpp:2212
GiNaC::symbol::imag_part
ex imag_part() const override
Definition: symbol.cpp:239
GiNaC::domain::complex
@ complex
Definition: flags.h:69
GiNaC::domain::positive
@ positive
Definition: flags.h:71
GiNaC::relational
This class holds a relation consisting of two expressions and a logical relation between them.
Definition: relational.h:35
GiNaC::print_context
Base class for print_contexts.
Definition: print.h:103
GiNaC::symbol::archive
void archive(archive_node &n) const override
Save (a.k.a.
Definition: symbol.cpp:133
GiNaC::realsymbol::conjugate
ex conjugate() const override
Definition: symbol.h:107
GiNaC::status_flags::dynallocated
@ dynallocated
heap-allocated (i.e. created by new if we want to be clever and bypass the stack,
Definition: flags.h:202
GiNaC::symbol::get_TeX_name
std::string get_TeX_name() const
Definition: symbol.cpp:160
GiNaC::archive_node
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:49
GiNaC::symbol::conjugate
ex conjugate() const override
Definition: symbol.cpp:229
options
unsigned options
Definition: factor.cpp:2480
GiNaC::GINAC_DECLARE_UNARCHIVER
GINAC_DECLARE_UNARCHIVER(add)
m
mvec m
Definition: factor.cpp:771
GiNaC::realsymbol::get_domain
unsigned get_domain() const override
Definition: symbol.h:105
GiNaC::symbol::to_rational
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for symbols.
Definition: normal.cpp:2622
GiNaC::symbol::real_part
ex real_part() const override
Definition: symbol.cpp:234
GiNaC::symbol::set_TeX_name
void set_TeX_name(const std::string &n)
Definition: symbol.h:76
GiNaC
Definition: add.cpp:38
syms
exset syms
Definition: factor.cpp:2434
GiNaC::symbol::do_print_python_repr
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition: symbol.cpp:194
GiNaC::realsymbol::imag_part
ex imag_part() const override
Definition: symbol.h:109
GiNaC::symbol::read_archive
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: symbol.cpp:100
GiNaC::symbol::do_print_tree
void do_print_tree(const print_tree &c, unsigned level) const
Definition: symbol.cpp:185
GiNaC::symbol::info
bool info(unsigned inf) const override
Information about the object.
Definition: symbol.cpp:206
GINAC_DECLARE_REGISTERED_CLASS
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
GiNaC::ex
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
GiNaC::symbol::calchash
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
GiNaC::realsymbol
Specialization of symbol to real domain.
Definition: symbol.h:99
GiNaC::symbol::is_equal_same_type
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
Definition: symbol.cpp:271
ex.h
Interface to GiNaC's light-weight expression handles.
GiNaC::print_latex
Context for latex-parsable output.
Definition: print.h:123
GiNaC::symbol::do_print_latex
void do_print_latex(const print_latex &c, unsigned level) const
Definition: symbol.cpp:175
GiNaC::basic::subs_one_level
ex subs_one_level(const exmap &m, unsigned options) const
Helper function for subs().
Definition: basic.cpp:585
GiNaC::symbol::is_polynomial
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
Definition: symbol.cpp:244
GiNaC::possymbol
Specialization of symbol to real positive domain.
Definition: symbol.h:123
GiNaC::print_tree
Context for tree-like output for debugging.
Definition: print.h:147
GiNaC::symbol::TeX_name
std::string TeX_name
LaTeX name of this symbol.
Definition: symbol.h:90
GiNaC::symbol::get_name
std::string get_name() const
Definition: symbol.cpp:152
GiNaC::realsymbol::realsymbol
realsymbol()
Definition: symbol.cpp:55
GiNaC::symbol::derivative
ex derivative(const symbol &s) const override
Implementation of ex::diff() for single differentiation of a symbol.
Definition: symbol.cpp:255
GiNaC::basic::setflag
const basic & setflag(unsigned f) const
Set some status_flags.
Definition: basic.h:288
GiNaC::symbol::eval
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
Definition: symbol.h:49
GiNaC::domain::real
@ real
Definition: flags.h:70
GiNaC::container
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
c
size_t c
Definition: factor.cpp:770
GiNaC::exmap
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
GiNaC::symbol::symbol
symbol(const std::string &initname)
Definition: symbol.cpp:69
GiNaC::symbol::series
ex series(const relational &s, int order, unsigned options=0) const override
Implementation of ex::series() for symbols.
Definition: pseries.cpp:657
GiNaC::symbol::to_polynomial
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for symbols.
Definition: normal.cpp:2629
GiNaC::symbol::set_name
void set_name(const std::string &n)
Definition: symbol.h:75
archive.h
Archiving of GiNaC expressions.
basic.h
Interface to GiNaC's ABC.
GiNaC::possymbol::duplicate
possymbol * duplicate() const override
Create a clone of this object on the heap.
Definition: symbol.h:131
GiNaC::symbol
Basic CAS symbol.
Definition: symbol.h:39
n
size_t n
Definition: factor.cpp:1463
GiNaC::realsymbol::duplicate
realsymbol * duplicate() const override
Create a clone of this object on the heap.
Definition: symbol.h:111
GiNaC::possymbol::possymbol
possymbol()
Definition: symbol.cpp:59
GiNaC::basic
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105
GiNaC::symbol::evalf
ex evalf() const override
Evaluate object numerically.
Definition: symbol.h:50
GiNaC::symbol::serial
unsigned serial
unique serial number for comparison
Definition: symbol.h:88
ptr.h
Reference-counted pointer template.
GiNaC::symbol::subs
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition: symbol.h:52
GiNaC::symbol::do_print
void do_print(const print_context &c, unsigned level) const
Definition: symbol.cpp:170
order
int order
Definition: integration_kernel.cpp:248

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