Gymbo

Public Member Functions | Public Attributes | List of all members
gymbo::Sym Struct Reference

Struct representing a symbolic expression. More...

`#include <type.h>`

Collaboration diagram for gymbo::Sym:
[legend]

## Public Member Functions
| Sym ()
| Default constructor for Sym. More...
| Sym (SymType symtype, Sym *left)
| Constructor for Sym with a specified type and left child. More...
| Sym (SymType symtype, Sym *left, std::unordered_map< int, float > &assign)
| Sym (SymType symtype, Sym *left, Sym *right)
| Constructor for Sym with a specified type, left child, and right child. More...
| Sym (SymType symtype, Word32 val)
| Constructor for Sym with a specified type and Word32 value. More...
| Sym (SymType symtype, Sym *left, Sym *right, Word32 word, int var_idx)
Sym * | copy ()
void | gather_var_ids (std::unordered_set< int > &result) const
| Gathers variable indices from the symbolic expression. More...
Sym * | psimplify (const Mem &cvals)
| Simplifies the symbolic expression by evaluating constant subexpressions. More...
float | eval (const std::unordered_map< int, float > &cvals, const float eps) const
| Evaluates the symbolic expression given concrete variable values. More...
Grad | grad (const std::unordered_map< int, float > &cvals, const float eps) const
| Computes the gradient of the symbolic expression given concrete variable values. More...
std::string | toString (bool convert_to_num) const
| Converts the symbolic expression to a string representation. More...

## Public Attributes
SymType | symtype
Sym * | left
Sym * | right
Word32 | word
int | var_idx
std::unordered_map< int, float > | assign

## Detailed Description

Struct representing a symbolic expression.

## Constructor & Destructor Documentation

## ◆ Sym() [1/6]

gymbo::Sym::Sym | ( |  | ) |
| inline

Default constructor for Sym.

Map from var IDs to their assigned values

## ◆ Sym() [2/6]

gymbo::Sym::Sym | ( | SymType | symtype,
|  | Sym * | left
| ) |  |
| inline

Constructor for Sym with a specified type and left child.

Parameters

  symtype | The type of the symbolic expression.
  left | Pointer to the left child.

## ◆ Sym() [3/6]

gymbo::Sym::Sym | ( | SymType | symtype,
|  | Sym * | left,
|  | std::unordered_map< int, float > & | assign
| ) |  |
| inline

## ◆ Sym() [4/6]

gymbo::Sym::Sym | ( | SymType | symtype,
|  | Sym * | left,
|  | Sym * | right
| ) |  |
| inline

Constructor for Sym with a specified type, left child, and right child.

Parameters

  symtype | The type of the symbolic expression.
  left | Pointer to the left child.
  right | Pointer to the right child.

## ◆ Sym() [5/6]

gymbo::Sym::Sym | ( | SymType | symtype,
|  | Word32 | val
| ) |  |
| inline

Constructor for Sym with a specified type and Word32 value.

Parameters

  symtype | The type of the symbolic expression.
  val | Word32 value associated with the expression.

## ◆ Sym() [6/6]

gymbo::Sym::Sym | ( | SymType | symtype,
|  | Sym * | left,
|  | Sym * | right,
|  | Word32 | word,
|  | int | var_idx
| ) |  |
| inline

## Member Function Documentation

## ◆ copy()

Sym* gymbo::Sym::copy | ( |  | ) |
| inline

## ◆ eval()

float gymbo::Sym::eval | ( | const std::unordered_map< int, float > & | cvals,
|  | const float | eps
| ) |  | const
| inline

Evaluates the symbolic expression given concrete variable values.

Parameters

  cvals | Map of variable indices to concrete values.
  eps | The smallest positive value of the target type.

Returns
  Result of the symbolic expression evaluation.

## ◆ gather_var_ids()

void gymbo::Sym::gather_var_ids | ( | std::unordered_set< int > & | result | ) | const
| inline

Gathers variable indices from the symbolic expression.

Parameters

  result | Set to store gathered variable indices.

## ◆ grad()

Grad gymbo::Sym::grad | ( | const std::unordered_map< int, float > & | cvals,
|  | const float | eps
| ) |  | const
| inline

Computes the gradient of the symbolic expression given concrete variable values.

Parameters

  cvals | Map of variable indices to concrete values.
  eps | Small value to handle numerical instability.

Returns
  Gradient of the symbolic expression.

## ◆ psimplify()

Sym* gymbo::Sym::psimplify | ( | const Mem & | cvals | ) |
| inline

Simplifies the symbolic expression by evaluating constant subexpressions.

Parameters

  cvals | Map of variable indices to constant values.

Returns
  Simplified symbolic expression.

## ◆ toString()

std::string gymbo::Sym::toString | ( | bool | convert_to_num | ) | const
| inline

Converts the symbolic expression to a string representation.

Parameters

  convert_to_num | Whether to convert constants to numeric representations.

Returns
  String representation of the symbolic expression.

## Member Data Documentation

## ◆ assign

std::unordered_map<int, float> gymbo::Sym::assign

## ◆ left

Sym* gymbo::Sym::left

Pointer to the left child of the expression.

## ◆ right

Sym* gymbo::Sym::right

Pointer to the right child of the expression.

## ◆ symtype

SymType gymbo::Sym::symtype

The type of the symbolic expression.

## ◆ var_idx

int gymbo::Sym::var_idx

Index of the variable associated with the expression.

## ◆ word

Word32 gymbo::Sym::word

Additional data associated with the expression.

The documentation for this struct was generated from the following file:

- libgymbo/type.h