GiNaC 1.8.7
GiNaC::constant Class Reference

This class holds constants, symbols with specific numerical value. More...

#include <constant.h>

Inheritance diagram for GiNaC::constant:
GiNaC::basic GiNaC::refcounted

Public Member Functions

 constant (const std::string &initname, evalffunctype efun=nullptr, const std::string &texname=std::string(), unsigned domain=domain::complex)
 constant (const std::string &initname, const numeric &initnumber, const std::string &texname=std::string(), unsigned domain=domain::complex)
bool info (unsigned inf) const override
 Information about the object.
ex evalf () const override
 Evaluate object numerically.
bool is_polynomial (const ex &var) const override
 Check whether this is a polynomial in the given variables.
ex conjugate () const override
ex real_part () const override
ex imag_part () const override
void archive (archive_node &n) const override
 Save (serialize) the object into archive node.
void read_archive (const archive_node &n, lst &syms) override
 Load (deserialize) the object from an archive node.
Public Member Functions inherited from GiNaC::basic
virtual ~basic ()
 basic destructor, virtual because class ex will delete objects of derived classes via a basic*.
 basic (const basic &other)
const basicoperator= (const basic &other)
 basic assignment operator: the other object might be of a derived class.
virtual basicduplicate () const
 Create a clone of this object on the heap.
virtual ex eval () const
 Perform automatic non-interruptive term rewriting rules.
virtual ex evalm () const
 Evaluate sums, products and integer powers of matrices.
virtual ex eval_integ () const
 Evaluate integrals, if result is known.
virtual ex eval_indexed (const basic &i) const
 Perform automatic symbolic evaluations on indexed expression that contains this object as the base expression.
virtual void print (const print_context &c, unsigned level=0) const
 Output to stream.
virtual void dbgprint () const
 Little wrapper around print to be called within a debugger.
virtual void dbgprinttree () const
 Little wrapper around printtree to be called within a debugger.
virtual unsigned precedence () const
 Return relative operator precedence (for parenthezing output).
virtual size_t nops () const
 Number of operands/members.
virtual ex op (size_t i) const
 Return operand/member at position i.
virtual ex operator[] (const ex &index) const
virtual ex operator[] (size_t i) const
virtual exlet_op (size_t i)
 Return modifiable operand/member at position i.
virtual exoperator[] (const ex &index)
virtual exoperator[] (size_t i)
virtual bool has (const ex &other, unsigned options=0) const
 Test for occurrence of a pattern.
virtual bool match (const ex &pattern, exmap &repls) const
 Check whether the expression matches a given pattern.
virtual ex subs (const exmap &m, unsigned options=0) const
 Substitute a set of objects by arbitrary expressions.
virtual ex map (map_function &f) const
 Construct new expression by applying the specified function to all sub-expressions (one level only, not recursively).
virtual void accept (GiNaC::visitor &v) const
virtual int degree (const ex &s) const
 Return degree of highest power in object s.
virtual int ldegree (const ex &s) const
 Return degree of lowest power in object s.
virtual ex coeff (const ex &s, int n=1) const
 Return coefficient of degree n in object s.
virtual ex expand (unsigned options=0) const
 Expand expression, i.e.
virtual ex collect (const ex &s, bool distributed=false) const
 Sort expanded expression in terms of powers of some object(s).
virtual ex series (const relational &r, int order, unsigned options=0) const
 Default implementation of ex::series().
virtual ex normal (exmap &repl, exmap &rev_lookup, lst &modifier) const
 Default implementation of ex::normal().
virtual ex to_rational (exmap &repl) const
 Default implementation of ex::to_rational().
virtual ex to_polynomial (exmap &repl) const
virtual numeric integer_content () const
virtual ex smod (const numeric &xi) const
 Apply symmetric modular homomorphism to an expanded multivariate polynomial.
virtual numeric max_coefficient () const
 Implementation ex::max_coefficient().
virtual exvector get_free_indices () const
 Return a vector containing the free indices of an expression.
virtual ex add_indexed (const ex &self, const ex &other) const
 Add two indexed expressions.
virtual ex scalar_mul_indexed (const ex &self, const numeric &other) const
 Multiply an indexed expression with a scalar.
virtual bool contract_with (exvector::iterator self, exvector::iterator other, exvector &v) const
 Try to contract two indexed expressions that appear in the same product.
virtual unsigned return_type () const
virtual return_type_t return_type_tinfo () const
template<class T>
void print_dispatch (const print_context &c, unsigned level) const
 Like print(), but dispatch to the specified class.
void print_dispatch (const registered_class_info &ri, const print_context &c, unsigned level) const
 Like print(), but dispatch to the specified class.
ex subs_one_level (const exmap &m, unsigned options) const
 Helper function for subs().
ex diff (const symbol &s, unsigned nth=1) const
 Default interface of nth derivative ex::diff(s, n).
int compare (const basic &other) const
 Compare objects syntactically to establish canonical ordering.
bool is_equal (const basic &other) const
 Test for syntactic equality.
const basichold () const
 Stop further evaluation.
unsigned gethash () const
const basicsetflag (unsigned f) const
 Set some status_flags.
const basicclearflag (unsigned f) const
 Clear some status_flags.
Public Member Functions inherited from GiNaC::refcounted
 refcounted () noexcept
unsigned int add_reference () noexcept
unsigned int remove_reference () noexcept
unsigned int get_refcount () const noexcept
void set_refcount (unsigned int r) noexcept

Protected Member Functions

ex derivative (const symbol &s) const override
 Implementation of ex::diff() for a constant always returns 0.
bool is_equal_same_type (const basic &other) const override
 Returns true if two objects of same type are equal.
unsigned calchash () const override
 Compute the hash value of an object and if it makes sense to store it in the objects status_flags, do so.
void do_print (const print_context &c, unsigned level) const
void do_print_tree (const print_tree &c, unsigned level) const
void do_print_latex (const print_latex &c, unsigned level) const
void do_print_python_repr (const print_python_repr &c, unsigned level) const
Protected Member Functions inherited from GiNaC::basic
 basic ()
virtual ex eval_ncmul (const exvector &v) const
virtual bool match_same_type (const basic &other) const
 Returns true if the attributes of two objects are similar enough for a match.
virtual int compare_same_type (const basic &other) const
 Returns order relation between two objects of same type.
void ensure_if_modifiable () const
 Ensure the object may be modified without hurting others, throws if this is not the case.
void do_print (const print_context &c, unsigned level) const
 Default output to stream.
void do_print_tree (const print_tree &c, unsigned level) const
 Tree output to stream.
void do_print_python_repr (const print_python_repr &c, unsigned level) const
 Python parsable output to stream.

Private Attributes

std::string name
 printname of this constant
std::string TeX_name
 LaTeX name.
evalffunctype ef
ex number
 numerical value this constant evalf()s to
unsigned serial
 unique serial number for comparison
unsigned domain
 numerical value this constant evalf()s to

Static Private Attributes

static unsigned next_serial = 0

Additional Inherited Members

Protected Attributes inherited from GiNaC::basic
unsigned flags
 of type status_flags
unsigned hashvalue
 hash value

Detailed Description

This class holds constants, symbols with specific numerical value.

Each object of this class must either provide their own function to evaluate it to class numeric or provide the constant as a numeric (if it's an exact number).

Definition at line 40 of file constant.h.

Constructor & Destructor Documentation

◆ constant() [1/2]

GiNaC::constant::constant ( const std::string & initname,
evalffunctype efun = nullptr,
const std::string & texname = std::string(),
unsigned domain = domain::complex )

◆ constant() [2/2]

GiNaC::constant::constant ( const std::string & initname,
const numeric & initnumber,
const std::string & texname = std::string(),
unsigned domain = domain::complex )

Member Function Documentation

◆ info()

bool GiNaC::constant::info ( unsigned inf) const
overridevirtual

◆ evalf()

ex GiNaC::constant::evalf ( ) const
overridevirtual

Evaluate object numerically.

Reimplemented from GiNaC::basic.

Definition at line 151 of file constant.cpp.

References ef, GiNaC::basic::ex, and number.

◆ is_polynomial()

bool GiNaC::constant::is_polynomial ( const ex & var) const
overridevirtual

Check whether this is a polynomial in the given variables.

Reimplemented from GiNaC::basic.

Definition at line 161 of file constant.cpp.

References GiNaC::basic::ex.

◆ conjugate()

ex GiNaC::constant::conjugate ( ) const
overridevirtual

Reimplemented from GiNaC::basic.

Definition at line 166 of file constant.cpp.

References domain, GiNaC::basic::ex, GiNaC::domain::positive, and GiNaC::domain::real.

◆ real_part()

ex GiNaC::constant::real_part ( ) const
overridevirtual

Reimplemented from GiNaC::basic.

Definition at line 173 of file constant.cpp.

References domain, GiNaC::basic::ex, GiNaC::domain::positive, and GiNaC::domain::real.

◆ imag_part()

ex GiNaC::constant::imag_part ( ) const
overridevirtual

Reimplemented from GiNaC::basic.

Definition at line 180 of file constant.cpp.

References domain, GiNaC::basic::ex, GiNaC::domain::positive, and GiNaC::domain::real.

◆ archive()

void GiNaC::constant::archive ( archive_node & n) const
overridevirtual

Save (serialize) the object into archive node.

Archive the object.

Losely speaking, this method turns an expression into a byte stream (which can be saved and restored later on, or sent via network, etc.)

Reimplemented from GiNaC::basic.

Definition at line 102 of file constant.cpp.

References GiNaC::archive_node::add_string(), and name.

◆ read_archive()

void GiNaC::constant::read_archive ( const archive_node & n,
lst & syms )
overridevirtual

Load (deserialize) the object from an archive node.

Construct object from archive_node.

Note
This method is essentially a constructor. However, constructors can't be virtual. So, if unarchiving routines are implemented as constructors one would need to define such a constructor in every class, even if all it does is simply calling constructor of a superclass.

Reimplemented from GiNaC::basic.

Definition at line 83 of file constant.cpp.

References GiNaC::Catalan, GiNaC::Euler, GiNaC::archive_node::find_string(), and GiNaC::Pi.

◆ derivative()

ex GiNaC::constant::derivative ( const symbol & s) const
overrideprotectedvirtual

Implementation of ex::diff() for a constant always returns 0.

See also
ex::diff

Reimplemented from GiNaC::basic.

Definition at line 192 of file constant.cpp.

References GiNaC::_ex0, and GiNaC::basic::ex.

◆ is_equal_same_type()

bool GiNaC::constant::is_equal_same_type ( const basic & other) const
overrideprotectedvirtual

Returns true if two objects of same type are equal.

Normally needs not be reimplemented as long as it wasn't overwritten by some parent class, since it just calls compare_same_type(). The reason why this function exists is that sometimes it is easier to determine equality than an order relation and then it can be overridden.

Reimplemented from GiNaC::basic.

Definition at line 208 of file constant.cpp.

References GiNaC::basic::basic(), constant(), GINAC_ASSERT, GiNaC::is_exactly_a(), and serial.

◆ calchash()

unsigned GiNaC::constant::calchash ( ) const
overrideprotectedvirtual

Compute the hash value of an object and if it makes sense to store it in the objects status_flags, do so.

The method inherited from class basic computes a hash value based on the type and hash values of possible members. For this reason it is well suited for container classes but atomic classes should override this implementation because otherwise they would all end up with the same hashvalue.

Reimplemented from GiNaC::basic.

Definition at line 216 of file constant.cpp.

References GiNaC::golden_ratio_hash(), GiNaC::status_flags::hash_calculated, GiNaC::basic::hashvalue, serial, and GiNaC::basic::setflag().

◆ do_print()

void GiNaC::constant::do_print ( const print_context & c,
unsigned level ) const
protected

Definition at line 114 of file constant.cpp.

References name, and GiNaC::print_context::s.

Referenced by GiNaC::GINAC_IMPLEMENT_REGISTERED_CLASS_OPT().

◆ do_print_tree()

void GiNaC::constant::do_print_tree ( const print_tree & c,
unsigned level ) const
protected

◆ do_print_latex()

void GiNaC::constant::do_print_latex ( const print_latex & c,
unsigned level ) const
protected

Definition at line 126 of file constant.cpp.

References GiNaC::print_context::s, and TeX_name.

Referenced by GiNaC::GINAC_IMPLEMENT_REGISTERED_CLASS_OPT().

◆ do_print_python_repr()

void GiNaC::constant::do_print_python_repr ( const print_python_repr & c,
unsigned level ) const
protected

Definition at line 131 of file constant.cpp.

References name, GiNaC::print_context::s, and TeX_name.

Referenced by GiNaC::GINAC_IMPLEMENT_REGISTERED_CLASS_OPT().

Member Data Documentation

◆ name

std::string GiNaC::constant::name
private

printname of this constant

Definition at line 72 of file constant.h.

Referenced by archive(), constant(), constant(), do_print(), do_print_python_repr(), and do_print_tree().

◆ TeX_name

std::string GiNaC::constant::TeX_name
private

LaTeX name.

Definition at line 73 of file constant.h.

Referenced by constant(), constant(), do_print_latex(), and do_print_python_repr().

◆ ef

evalffunctype GiNaC::constant::ef
private

Definition at line 74 of file constant.h.

Referenced by constant(), constant(), and evalf().

◆ number

ex GiNaC::constant::number
private

numerical value this constant evalf()s to

Definition at line 75 of file constant.h.

Referenced by constant(), and evalf().

◆ serial

unsigned GiNaC::constant::serial
private

unique serial number for comparison

Definition at line 76 of file constant.h.

Referenced by calchash(), constant(), constant(), and is_equal_same_type().

◆ next_serial

unsigned GiNaC::constant::next_serial = 0
staticprivate

Definition at line 77 of file constant.h.

Referenced by constant(), and constant().

◆ domain

unsigned GiNaC::constant::domain
private

numerical value this constant evalf()s to

Definition at line 78 of file constant.h.

Referenced by conjugate(), constant(), constant(), imag_part(), info(), and real_part().


The documentation for this class was generated from the following files:

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