GiNaC 1.8.7
symbol.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2023 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
34namespace GiNaC {
35
38class symbol : public basic
39{
41 // other constructors
42public:
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
47public:
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;
64protected:
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
70public:
71 virtual unsigned get_domain() const { return domain::complex; }
72
73 // non-virtual functions in this class
74public:
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;
79protected:
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
87protected:
88 unsigned serial;
89 mutable std::string name;
90 std::string TeX_name;
91private:
92 static unsigned next_serial;
93};
95
96
98class realsymbol : public symbol
99{
100public:
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
122class possymbol : public realsymbol
123{
124public:
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
Archiving of GiNaC expressions.
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:49
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105
const basic & setflag(unsigned f) const
Set some status_flags.
Definition: basic.h:288
ex subs_one_level(const exmap &m, unsigned options) const
Helper function for subs().
Definition: basic.cpp:585
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
@ positive
Definition: flags.h:71
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
Specialization of symbol to real positive domain.
Definition: symbol.h:123
possymbol * duplicate() const override
Create a clone of this object on the heap.
Definition: symbol.h:131
unsigned get_domain() const override
Definition: symbol.h:129
Base class for print_contexts.
Definition: print.h:103
Context for latex-parsable output.
Definition: print.h:123
Context for python-parsable output.
Definition: print.h:139
Context for tree-like output for debugging.
Definition: print.h:147
Specialization of symbol to real domain.
Definition: symbol.h:99
ex real_part() const override
Definition: symbol.h:108
unsigned get_domain() const override
Definition: symbol.h:105
realsymbol * duplicate() const override
Create a clone of this object on the heap.
Definition: symbol.h:111
ex imag_part() const override
Definition: symbol.h:109
ex conjugate() const override
Definition: symbol.h:107
This class holds a relation consisting of two expressions and a logical relation between them.
Definition: relational.h:35
@ dynallocated
heap-allocated (i.e. created by new if we want to be clever and bypass the stack,
Definition: flags.h:202
Basic CAS symbol.
Definition: symbol.h:39
unsigned serial
unique serial number for comparison
Definition: symbol.h:88
std::string TeX_name
LaTeX name of this symbol.
Definition: symbol.h:90
void set_name(const std::string &n)
Definition: symbol.h:75
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: symbol.cpp:100
static unsigned next_serial
Definition: symbol.h:92
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for symbols.
Definition: normal.cpp:2652
symbol(const std::string &initname)
Definition: symbol.cpp:69
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
Definition: symbol.cpp:244
virtual unsigned get_domain() const
Definition: symbol.h:71
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition: symbol.cpp:194
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
Definition: symbol.h:49
ex normal(exmap &repl, exmap &rev_lookup, lst &modifier) const override
Implementation of ex::normal() for symbols.
Definition: normal.cpp:2242
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
Definition: symbol.cpp:271
std::string get_TeX_name() const
Definition: symbol.cpp:160
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
ex evalf() const override
Evaluate object numerically.
Definition: symbol.h:50
ex series(const relational &s, int order, unsigned options=0) const override
Implementation of ex::series() for symbols.
Definition: pseries.cpp:656
ex real_part() const override
Definition: symbol.cpp:234
void do_print(const print_context &c, unsigned level) const
Definition: symbol.cpp:170
void do_print_tree(const print_tree &c, unsigned level) const
Definition: symbol.cpp:185
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for symbols.
Definition: normal.cpp:2659
ex conjugate() const override
Definition: symbol.cpp:229
void archive(archive_node &n) const override
Save (a.k.a.
Definition: symbol.cpp:133
ex derivative(const symbol &s) const override
Implementation of ex::diff() for single differentiation of a symbol.
Definition: symbol.cpp:255
void do_print_latex(const print_latex &c, unsigned level) const
Definition: symbol.cpp:175
std::string name
printname of this symbol
Definition: symbol.h:89
bool info(unsigned inf) const override
Information about the object.
Definition: symbol.cpp:206
std::string get_name() const
Definition: symbol.cpp:152
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition: symbol.h:52
void set_TeX_name(const std::string &n)
Definition: symbol.h:76
ex imag_part() const override
Definition: symbol.cpp:239
Interface to GiNaC's light-weight expression handles.
unsigned options
Definition: factor.cpp:2475
size_t n
Definition: factor.cpp:1432
size_t c
Definition: factor.cpp:757
exset syms
Definition: factor.cpp:2429
mvec m
Definition: factor.cpp:758
int order
Definition: add.cpp:38
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
GINAC_DECLARE_UNARCHIVER(add)
Reference-counted pointer template.
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153

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