Solvers and expressions

Configure expression evaluation and operator precedence.

enum class snt::exs::CompositionKind

Values:

enumerator Operand
enumerator Operator
enumerator Group
enum snt::exs::TokenType

List of operator types

Values:

enumerator EMPTY_TOKEN

Token is empty.

enumerator OPERATOR_TOKEN

Token is an operator.

enumerator ATOM_TOKEN

Token is an atom.

enum snt::exs::OperationType

Type of an operation

Values:

enumerator UNARY_OPERATION

Unary operation operates on the atom value.

enumerator BINARY_OPERATION

Binary operation operates between two atoms.

enumerator TERNARY_OPERATION

Ternary operation operates with three atoms.

enumerator GROUP_OPERATION

Group operation operates on various number of atoms.

enum snt::exs::OperatorType

List of all operators

Values:

enumerator NONE_OPERATOR

Item is not an operator.

enumerator ADD_OPERATOR

Addition of values.

enumerator SUBTRACT_OPERATOR

Subtraction of values.

enumerator MULTIPLY_OPERATOR

Multiplication of values.

enumerator DIVIDE_OPERATOR

Division of values.

enumerator POWER_OPERATOR

Power of a value.

enumerator MODULO_OPERATOR

Modulo of values.

enumerator NOT_OPERATOR

Logical negation.

enumerator AND_OPERATOR

Logical and.

enumerator OR_OPERATOR

Logical or.

enumerator EQUAL_OPERATOR

Logical equality.

enumerator NOT_EQUAL_OPERATOR

Logical difference.

enumerator LESS_EQUAL_OPERATOR

Logical less or equal.

enumerator GREATER_EQUAL_OPERATOR

Logical greater or equal.

enumerator LESS_OPERATOR

Logical less.

enumerator GREATER_OPERATOR

Logical greater.

enumerator CONDITION_OPERATOR

Conditional operator.

enumerator PARENTHESES_OPERATOR

Parentheses.

enumerator EXPONENT_OPERATOR

Exponents.

enumerator LOGARITHM_OPERATOR

Logarithm.

enumerator LOGARITHM_10_OPERATOR

Logarithm with a base 10.

enumerator LOGARITHM_BASE_OPERATOR

Logarithm with an arbitrary base.

enumerator POWER_BASE_OPERATOR

Power with an arbitrary base.

enumerator SQUARE_ROOT_OPERATOR

Square root.

enumerator CUBIC_ROOT_OPERATOR

Cubic root.

enumerator SINUS_OPERATOR

Sinus.

enumerator COSINUS_OPERATOR

Cosinus.

enumerator TANGENS_OPERATOR

Tangens.

enumerator NUM_OPERATOR_TYPES

Total number of operators.

using snt::exs::StepListType = std::vector<std::pair<OperationType, std::vector<int>>>
CompositionGraph snt::exs::build_composition_graph(const std::string &expression, OperatorList &operators, const StepList &steps)

Build a graph with the solver’s configured operators and reduction order. This structural pass does not evaluate atoms. Call through Solver::eval(expression, &graph) when evaluation must succeed first.

static std::string snt::exs::trim(const std::string &str, const std::string &whitespace = " \t")

Remove leading and trailing spaces from a string

Parameters:
  • str – String that should be trimmed

  • whitespace – String with whitespace characters that will be removed

struct BaseSettings

Base structure for expression solver settings

Subclassed by snt::dip::LogicalSettings, snt::dip::NumericalSettings

struct CompositionGraph

Per-expression structure, independent of atom types and evaluated values.

Public Members

std::vector<CompositionNode> nodes
std::size_t root
struct CompositionNode

A structural expression node. Child IDs refer to nodes in the same graph.

Public Members

CompositionKind kind
std::string text

Operand text or registered operator name.

int operator_type
std::optional<OperationType> operation

Absent for operands.

std::vector<std::size_t> children

Source order; operands have none.

class Exception : public snt::core::Exception

Subclassed by snt::exs::MissingException, snt::exs::ParserException

Public Functions

inline explicit Exception(core::ExceptionInfo info)
inline explicit Exception(std::string message, std::string details, std::string suggestion, std::string origin_file, size_t origin_line)
class Expression

Parsed expression with an ordered list of executable steps.

Public Functions

Expression(const std::string &expression)
void shift(int nchar = 1)
void remove(const std::string &string)
std::string pop_left()
std::string to_string()
void print()

Public Members

std::string left
std::string right
std::string expr
class MissingException : public snt::exs::Exception

Missing exception is triggered when functionality is not implemented yet

Public Functions

inline MissingException(std::string message, std::string file, std::size_t line)
class ParserException : public snt::exs::Exception

Parser exceptions are triggered by problems during expression parsing

Public Functions

inline explicit Exception(core::ExceptionInfo info)
inline explicit Exception(std::string message, std::string details, std::string suggestion, std::string origin_file, size_t origin_line)
template<class ATOM, class SETTINGS = BaseSettings>
class Solver

Main expression solver class

Note that internal solver and operator routines use static_cast to convert between AtomGrand and actual ATOM type. Although it may seem dangerous, within a particular solver we need to guarantee that AtomGrand will have only one derived type.

Template Parameters:
  • ATOM – Atom type

  • SETTINGS – Atom settings

Public Functions

inline Solver(const SETTINGS &set = {})

Default solver constructor

Parameters:

set – Solver settings

inline Solver(const OperatorList &o, const SETTINGS &set = {})

Solver constructor with modified operators

Parameters:
  • o – List of operators

  • set – Solver settings

inline Solver(const StepList &s, const SETTINGS &set = {})

Solver constructor with modified operator steps

Parameters:
  • s – List of operator steps

  • set – Solver settings

inline Solver(const OperatorList &o, const StepList &s, const SETTINGS &set = {})

Custom solver constructor

Parameters:
  • o – List of operators

  • s – List of operator steps

  • set – Solver settings

inline void set_settings(const SETTINGS &set = {})

Set solver settings

Parameters:

set – New structure with settings

inline ATOM eval(std::string expression, CompositionGraph *composition = nullptr)

Main solver routine

Parameters:
  • expression – Expression that should be solved

  • composition – Optional output for the expression’s composition graph.

Returns:

Final atom object with a solution

Public Members

SETTINGS settings

Setting structure.

OperatorList operators

List of used operators.

StepList steps

List of operator steps.

class StepList

Ordered execution steps generated from an EXS expression.

Public Functions

void append(OperationType t, const std::vector<int> &s)

Append one execution step.

Parameters:
  • t – Operation category to execute.

  • s – Operator identifiers executed for this step.

Public Members

StepListType steps