smats  0.0.1
Satisfability Modulo Arithmetic Theories Symbols
Loading...
Searching...
No Matches
smats::ExpressionCell< T > Class Template Referenceabstract

#include <expression_cell.h>

Inheritance diagram for smats::ExpressionCell< T >:
smats::BinaryExpressionCell< T > smats::ExpressionAdd< T > smats::ExpressionConstant< T > smats::ExpressionMul< T > smats::ExpressionNaN< T > smats::ExpressionVar< T > smats::UnaryExpressionCell< T > smats::ExpressionDiv< T > smats::ExpressionPow< T >

Classes

struct  Private
 

Public Member Functions

long use_count () const
 
ExpressionKind kind () const
 
virtual void hash (DelegatingHasher &) const =0
 
const Variablesvariables () const
 
bool is_polynomial () const
 
bool is_expanded () const
 
virtual bool equal_to (const ExpressionCell< T > &o) const =0
 
virtual bool less (const ExpressionCell< T > &o) const =0
 
void set_expanded ()
 
template<template< class > class E>
const E< T > & to () const
 
template<template< class > class E>
E< T > & to ()
 
Expression< T > to_expression () const
 
virtual T evaluate (const Environment< T > &env) const =0
 
virtual Expression< T > expand () const =0
 
virtual Expression< T > evaluate_partial (const Environment< T > &env) const =0
 
virtual Expression< T > substitute (const Substitution< T > &s) const =0
 
virtual Expression< T > differentiate (const Variable &x) const =0
 
virtual std::ostream & display (std::ostream &os) const =0
 
void invalidate_cache ()
 

Protected Member Functions

 ExpressionCell (ExpressionKind kind, bool is_expanded)
 
 ExpressionCell (ExpressionKind kind, bool is_polynomial, bool is_expanded)
 
virtual void compute_variables (std::optional< Variables > &variables) const =0
 
virtual void compute_is_polynomial (std::optional< bool > &is_polynomial) const =0
 

Private Attributes

const ExpressionKind kind_
 The kind of the expression.
 
std::optional< Variablesvariables_
 Cached variables in the expression.
 
std::optional< bool > is_polynomial_
 Cached information about whether the expression is a polynomial.
 
bool is_expanded_ {false}
 Whether the expression is already expanded.
 

Detailed Description

template<class T>
class smats::ExpressionCell< T >

Abstract class used as the base of concrete symbolic-expression classes.

Note
It provides virtual function, ExpressionCell<T>::display because operator<< is not allowed to be virtual.
All subclasses of ExpressionCell must be immutable and implement the static function
static std::shared_ptr<ExpressionCell> create() { return std::make_shared<ExpressionCell>(Private()); }
Definition expression_cell.h:179
to create instances of the ExpressionCell externally while guaranteeing the use of shared_ptr.
Template Parameters
Ttype of the expression evaluation

Constructor & Destructor Documentation

◆ ExpressionCell() [1/2]

template<class T >
smats::ExpressionCell< T >::ExpressionCell ( ExpressionKind kind,
bool is_expanded )
protected

Constructs ExpressionCell of kind with is_expanded .

Parameters
kindkind of the expression
is_expandedwhether the expression is already expanded

ExpressionCell

◆ ExpressionCell() [2/2]

template<class T >
smats::ExpressionCell< T >::ExpressionCell ( ExpressionKind kind,
bool is_polynomial,
bool is_expanded )
protected

Constructs ExpressionCell of kind with is_polynomial and is_expanded .

Parameters
kindkind of the expression
is_polynomialwhether the expression is a polynomial
is_expandedwhether the expression is already expanded

Member Function Documentation

◆ differentiate()

template<class T >
virtual Expression< T > smats::ExpressionCell< T >::differentiate ( const Variable & x) const
nodiscardpure virtual

Differentiates this symbolic expression with respect to the variable var.

Parameters
xvariable
Exceptions
std::runtime_exceptionif it is not differentiable.

Implemented in smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionDiv< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, smats::ExpressionPow< T >, and smats::ExpressionVar< T >.

◆ display()

template<class T >
virtual std::ostream & smats::ExpressionCell< T >::display ( std::ostream & os) const
pure virtual

Displays the expression in a human-readable format.

Parameters
osoutput stream
Returns
updated output stream

Implemented in smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionDiv< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, smats::ExpressionPow< T >, and smats::ExpressionVar< T >.

◆ equal_to()

template<class T >
virtual bool smats::ExpressionCell< T >::equal_to ( const ExpressionCell< T > & o) const
nodiscardpure virtual

Compare two expression cells to determine if they are equal.

Parameters
oother object to compare against
Returns
true the two object are equal
false if the two objects are different

Implemented in smats::BinaryExpressionCell< T >, smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, and smats::ExpressionVar< T >.

◆ evaluate()

template<class T >
virtual T smats::ExpressionCell< T >::evaluate ( const Environment< T > & env) const
nodiscardpure virtual

Evaluates under a given environment (by default, an empty environment).

Parameters
envenvironment
Exceptions
std::runtime_exceptionif NaN is detected during evaluation.

Implemented in smats::BinaryExpressionCell< T >, smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, and smats::ExpressionVar< T >.

◆ evaluate_partial()

template<class T >
virtual Expression< T > smats::ExpressionCell< T >::evaluate_partial ( const Environment< T > & env) const
nodiscardpure virtual

Returns an Expression obtained by replacing all occurrences of the variables in env in the current expression cell with the corresponding values in env.

Parameters
envenvironment
Exceptions
std::runtime_exceptionif NaN is detected during substitution.

Implemented in smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionDiv< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, smats::ExpressionPow< T >, and smats::ExpressionVar< T >.

◆ expand()

template<class T >
virtual Expression< T > smats::ExpressionCell< T >::expand ( ) const
nodiscardpure virtual

Expands out products and positive integer powers in expression.

Exceptions
std::runtime_exceptionif NaN is detected during expansion.

Implemented in smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionDiv< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, smats::ExpressionPow< T >, and smats::ExpressionVar< T >.

◆ hash()

template<class T >
virtual void smats::ExpressionCell< T >::hash ( DelegatingHasher & ) const
pure virtual

Sends all hash-relevant bytes for this ExpressionCell type into the given hasher, per the hash_append concept, except for kind(), because Expression already sends that.

Implemented in smats::BinaryExpressionCell< T >, smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, and smats::ExpressionVar< T >.

◆ invalidate_cache()

template<class T >
void smats::ExpressionCell< T >::invalidate_cache ( )

Invalidate the cached information.

This will force the expression to recompute the cached information the next time they are requested. Must be called whenever the expression is modified.

◆ is_expanded()

template<class T >
bool smats::ExpressionCell< T >::is_expanded ( ) const
inlinenodiscard

Check whether the expression cell is expanded.

Returns
true if the expression cell is expanded
false if the expression cell is not expanded

◆ is_polynomial()

template<class T >
bool smats::ExpressionCell< T >::is_polynomial ( ) const
nodiscard

Check whether the expression cell is polynomial.

Returns
true if the expression cell is polynomial
false if the expression cell is not polynomial

◆ kind()

template<class T >
ExpressionKind smats::ExpressionCell< T >::kind ( ) const
inlinenodiscard

Get read-only access to the kind of the expression cell.

Returns
kind of the expression cell

◆ less()

template<class T >
virtual bool smats::ExpressionCell< T >::less ( const ExpressionCell< T > & o) const
nodiscardpure virtual

Compare two expression cells to determine the order between them.

Parameters
oother object to compare against
Returns
true if this object is less than the other object
false if this object is not less than the other object

Implemented in smats::BinaryExpressionCell< T >, smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, and smats::ExpressionVar< T >.

◆ set_expanded()

template<class T >
void smats::ExpressionCell< T >::set_expanded ( )
inline

Sets this symbolic expression as already expanded.

◆ substitute()

template<class T >
virtual Expression< T > smats::ExpressionCell< T >::substitute ( const Substitution< T > & s) const
nodiscardpure virtual

Returns an Expression obtained by replacing all occurrences of the variables in s in the current expression cell with the corresponding expressions in s.

Parameters
ssubstitution
Exceptions
std::runtime_exceptionif NaN is detected during substitution.

Implemented in smats::ExpressionAdd< T >, smats::ExpressionConstant< T >, smats::ExpressionDiv< T >, smats::ExpressionMul< T >, smats::ExpressionNaN< T >, smats::ExpressionPow< T >, and smats::ExpressionVar< T >.

◆ to() [1/2]

template<class T >
template<template< class > class E>
E< T > & smats::ExpressionCell< T >::to ( )
inlinenodiscard

Casts this ExpressionCell to a subclass of ExpressionCell with the same template type.

Template Parameters
Esubclass of ExpressionCell
Returns
mutable reference to the casted ExpressionCell

◆ to() [2/2]

template<class T >
template<template< class > class E>
const E< T > & smats::ExpressionCell< T >::to ( ) const
inlinenodiscard

Casts this ExpressionCell to a subclass of ExpressionCell with the same template type.

Template Parameters
Esubclass of ExpressionCell
Returns
constant reference to the casted ExpressionCell

◆ to_expression()

template<class T >
Expression< T > smats::ExpressionCell< T >::to_expression ( ) const
inlinenodiscard

Create an Expression from this ExpressionCell.

Returns
Expression containing this ExpressionCell

◆ use_count()

template<class T >
long smats::ExpressionCell< T >::use_count ( ) const
inlinenodiscard

Get read-only access to the reference count of the expression cell.

Returns
reference count of the expression cell

◆ variables()

template<class T >
const Variables & smats::ExpressionCell< T >::variables ( ) const
nodiscard

Get read-only access to the variables of the expression cell.

Returns
variables of the expression cell

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