GiNaC 1.8.10
constant.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_CONSTANT_H
23#define GINAC_CONSTANT_H
24
25#include "basic.h"
26#include "ex.h"
27#include "archive.h"
28
29#include <string>
30
31namespace GiNaC {
32
33typedef ex (*evalffunctype)();
34
39class constant : public basic
40{
42 // other constructors
43public:
44 constant(const std::string & initname, evalffunctype efun = nullptr, const std::string & texname = std::string(), unsigned domain = domain::complex);
45 constant(const std::string & initname, const numeric & initnumber, const std::string & texname = std::string(), unsigned domain = domain::complex);
46
47 // functions overriding virtual functions from base classes
48public:
49 bool info(unsigned inf) const override;
50 ex evalf() const override;
51 bool is_polynomial(const ex & var) const override;
52 ex conjugate() const override;
53 ex real_part() const override;
54 ex imag_part() const override;
55 void archive(archive_node& n) const override;
56 void read_archive(const archive_node& n, lst& syms) override;
57protected:
58 ex derivative(const symbol & s) const override;
59 bool is_equal_same_type(const basic & other) const override;
60 unsigned calchash() const override;
61
62 // non-virtual functions in this class
63public:
64 std::string get_name() const { return name; }
65 std::string get_TeX_name() const { return TeX_name; }
66protected:
67 void do_print(const print_context & c, unsigned level) const;
68 void do_print_tree(const print_tree & c, unsigned level) const;
69 void do_print_latex(const print_latex & c, unsigned level) const;
70 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
71
72// member variables
73private:
74 std::string name;
75 std::string TeX_name;
78 unsigned serial;
79 static unsigned next_serial;
80 unsigned domain;
81};
83
84extern const constant Pi;
85extern const constant Catalan;
86extern const constant Euler;
87
88} // namespace GiNaC
89
90#endif // ndef GINAC_CONSTANT_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
This class holds constants, symbols with specific numerical value.
Definition constant.h:40
evalffunctype ef
Definition constant.h:76
ex number
numerical value this constant evalf()s to
Definition constant.h:77
ex evalf() const override
Evaluate object numerically.
Definition constant.cpp:149
std::string name
printname of this constant
Definition constant.h:74
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition constant.cpp:81
unsigned serial
unique serial number for comparison
Definition constant.h:78
std::string get_name() const
Definition constant.h:64
void do_print_latex(const print_latex &c, unsigned level) const
Definition constant.cpp:124
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
Definition constant.cpp:206
void do_print(const print_context &c, unsigned level) const
Definition constant.cpp:112
std::string TeX_name
LaTeX name.
Definition constant.h:75
bool info(unsigned inf) const override
Information about the object.
Definition constant.cpp:137
ex real_part() const override
Definition constant.cpp:171
static unsigned next_serial
Definition constant.h:79
ex derivative(const symbol &s) const override
Implementation of ex::diff() for a constant always returns 0.
Definition constant.cpp:190
std::string get_TeX_name() const
Definition constant.h:65
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition constant.cpp:129
unsigned domain
numerical value this constant evalf()s to
Definition constant.h:80
void do_print_tree(const print_tree &c, unsigned level) const
Definition constant.cpp:117
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 constant.cpp:214
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
Definition constant.cpp:159
ex conjugate() const override
Definition constant.cpp:164
ex imag_part() const override
Definition constant.cpp:178
Wrapper template for making GiNaC classes out of STL containers.
Definition container.h:72
Domain of an object.
Definition flags.h:65
Lightweight wrapper for GiNaC's symbolic objects.
Definition ex.h:72
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Definition numeric.h:81
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
Basic CAS symbol.
Definition symbol.h:38
Interface to GiNaC's light-weight expression handles.
size_t n
Definition factor.cpp:1431
size_t c
Definition factor.cpp:756
exset syms
Definition factor.cpp:2427
Definition add.cpp:35
const constant Euler("Euler", EulerEvalf, "\\gamma_E", domain::positive)
Euler's constant.
Definition constant.h:86
ex(* evalffunctype)()
Definition constant.h:33
const constant Pi("Pi", PiEvalf, "\\pi", domain::positive)
Pi.
Definition constant.h:84
const constant Catalan("Catalan", CatalanEvalf, "G", domain::positive)
Catalan's constant.
Definition constant.h:85
#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.