GiNaC 1.8.10
symbol.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2026 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef GINAC_SYMBOL_H
23#define GINAC_SYMBOL_H
24
25#include "basic.h"
26#include "ex.h"
27#include "ptr.h"
28#include "archive.h"
29
30#include <string>
31#include <typeinfo>
32
33namespace GiNaC {
34
37class symbol : public basic
38{
40 // other constructors
41public:
42 explicit symbol(const std::string & initname);
43 symbol(const std::string & initname, const std::string & texname);
44
45 // functions overriding virtual functions from base classes
46public:
47 bool info(unsigned inf) const override;
48 ex eval() const override { return *this; } // for performance reasons
49 ex evalf() const override { return *this; } // overwrites basic::evalf() for performance reasons
50 ex series(const relational & s, int order, unsigned options = 0) const override;
51 ex subs(const exmap & m, unsigned options = 0) const override { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
52 ex normal(exmap & repl, exmap & rev_lookup, lst & modifier) const override;
53 ex to_rational(exmap & repl) const override;
54 ex to_polynomial(exmap & repl) const override;
55 ex conjugate() const override;
56 ex real_part() const override;
57 ex imag_part() const override;
58 bool is_polynomial(const ex & var) const override;
60 void archive(archive_node& n) const override;
62 void read_archive(const archive_node& n, lst& syms) override;
63protected:
64 ex derivative(const symbol & s) const override;
65 bool is_equal_same_type(const basic & other) const override;
66 unsigned calchash() const override;
67
68 // new virtual functions which can be overridden by derived classes
69public:
70 virtual unsigned get_domain() const { return domain::complex; }
71
72 // non-virtual functions in this class
73public:
74 void set_name(const std::string & n) { name = n; }
75 void set_TeX_name(const std::string & n) { TeX_name = n; }
76 std::string get_name() const;
77 std::string get_TeX_name() const;
78protected:
79 void do_print(const print_context & c, unsigned level) const;
80 void do_print_latex(const print_latex & c, unsigned level) const;
81 void do_print_tree(const print_tree & c, unsigned level) const;
82 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
83
84// member variables
85
86protected:
87 unsigned serial;
88 mutable std::string name;
89 std::string TeX_name;
90private:
91 static unsigned next_serial;
92};
94
95
97class realsymbol : public symbol
98{
99public:
100 realsymbol();
101 explicit realsymbol(const std::string & initname);
102 realsymbol(const std::string & initname, const std::string & texname);
103
104 unsigned get_domain() const override { return domain::real; }
105
106 ex conjugate() const override { return *this; }
107 ex real_part() const override { return *this; }
108 ex imag_part() const override { return 0; }
109
110 realsymbol* duplicate() const override
111 {
112 realsymbol * bp = new realsymbol(*this);
114 return bp;
115 }
116};
118
119
121class possymbol : public realsymbol
122{
123public:
124 possymbol();
125 explicit possymbol(const std::string & initname);
126 possymbol(const std::string & initname, const std::string & texname);
127
128 unsigned get_domain() const override { return domain::positive; }
129
130 possymbol* duplicate() const override
131 {
132 possymbol * bp = new possymbol(*this);
134 return bp;
135 }
136};
138
139} // namespace GiNaC
140
141#endif // ndef GINAC_SYMBOL_H
Archiving of GiNaC expressions.
#define GINAC_DECLARE_UNARCHIVER(classname)
Helper macros to register a class with (un)archiving (a.k.a.
Definition archive.h:218
Interface to GiNaC's ABC.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition archive.h:48
This class holds archived versions of GiNaC expressions (class ex).
Definition archive.h:254
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition basic.h:104
const basic & setflag(unsigned f) const
Set some status_flags.
Definition basic.h:287
ex subs_one_level(const exmap &m, unsigned options) const
Helper function for subs().
Definition basic.cpp:584
Wrapper template for making GiNaC classes out of STL containers.
Definition container.h:72
Lightweight wrapper for GiNaC's symbolic objects.
Definition ex.h:72
Specialization of symbol to real positive domain.
Definition symbol.h:122
possymbol * duplicate() const override
Create a clone of this object on the heap.
Definition symbol.h:130
unsigned get_domain() const override
Definition symbol.h:128
Base class for print_contexts.
Definition print.h:101
Context for latex-parsable output.
Definition print.h:121
Context for python-parsable output.
Definition print.h:137
Context for tree-like output for debugging.
Definition print.h:145
Specialization of symbol to real domain.
Definition symbol.h:98
ex real_part() const override
Definition symbol.h:107
unsigned get_domain() const override
Definition symbol.h:104
realsymbol * duplicate() const override
Create a clone of this object on the heap.
Definition symbol.h:110
ex imag_part() const override
Definition symbol.h:108
ex conjugate() const override
Definition symbol.h:106
This class holds a relation consisting of two expressions and a logical relation between them.
Definition relational.h:34
@ dynallocated
heap-allocated (i.e. created by new if we want to be clever and bypass the stack,
Definition flags.h:201
Basic CAS symbol.
Definition symbol.h:38
unsigned serial
unique serial number for comparison
Definition symbol.h:87
std::string TeX_name
LaTeX name of this symbol.
Definition symbol.h:89
void set_name(const std::string &n)
Definition symbol.h:74
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition symbol.cpp:99
static unsigned next_serial
Definition symbol.h:91
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for symbols.
Definition normal.cpp:2651
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
Definition symbol.cpp:243
virtual unsigned get_domain() const
Definition symbol.h:70
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition symbol.cpp:193
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
Definition symbol.h:48
ex normal(exmap &repl, exmap &rev_lookup, lst &modifier) const override
Implementation of ex::normal() for symbols.
Definition normal.cpp:2241
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
Definition symbol.cpp:270
std::string get_TeX_name() const
Definition symbol.cpp:159
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:277
ex evalf() const override
Evaluate object numerically.
Definition symbol.h:49
ex series(const relational &s, int order, unsigned options=0) const override
Implementation of ex::series() for symbols.
Definition pseries.cpp:655
ex real_part() const override
Definition symbol.cpp:233
void do_print(const print_context &c, unsigned level) const
Definition symbol.cpp:169
void do_print_tree(const print_tree &c, unsigned level) const
Definition symbol.cpp:184
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for symbols.
Definition normal.cpp:2658
ex conjugate() const override
Definition symbol.cpp:228
ex derivative(const symbol &s) const override
Implementation of ex::diff() for single differentiation of a symbol.
Definition symbol.cpp:254
void do_print_latex(const print_latex &c, unsigned level) const
Definition symbol.cpp:174
std::string name
printname of this symbol
Definition symbol.h:88
bool info(unsigned inf) const override
Information about the object.
Definition symbol.cpp:205
std::string get_name() const
Definition symbol.cpp:151
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition symbol.h:51
void set_TeX_name(const std::string &n)
Definition symbol.h:75
ex imag_part() const override
Definition symbol.cpp:238
Interface to GiNaC's light-weight expression handles.
unsigned options
Definition factor.cpp:2473
size_t n
Definition factor.cpp:1431
size_t c
Definition factor.cpp:756
exset syms
Definition factor.cpp:2427
mvec m
Definition factor.cpp:757
Definition add.cpp:35
std::map< ex, ex, ex_is_less > exmap
Definition basic.h:49
Reference-counted pointer template.
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition registrar.h:151

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