symbolic4
expression.h File Reference
#include "symbolic4.h"

Go to the source code of this file.

Data Structures

struct  numeric_value
 
struct  expression
 

Typedefs

typedef struct numeric_value numeric_value
 
typedef struct expression expression
 

Enumerations

enum  expression_type {
  EXPT_NULL, EXPT_VALUE, EXPT_OPERATION, EXPT_FUNCTION,
  EXPT_STRUCTURE, EXPT_CONTROL
}
 
enum  expression_identifier {
  EXPI_NULL, EXPI_LITERAL, EXPI_SYMBOL, EXPI_VARIABLE,
  EXPI_EQUATION, EXPI_ADDITION, EXPI_SUBTRACTION, EXPI_MULTIPLICATION,
  EXPI_DIVISION, EXPI_EXPONENTATION, EXPI_ABS, EXPI_LN,
  EXPI_LOG, EXPI_SIN, EXPI_COS, EXPI_TAN,
  EXPI_ARCSIN, EXPI_ARCCOS, EXPI_ARCTAN, EXPI_SIMPLIFY,
  EXPI_SOLVE, EXPI_FACTORS, EXPI_VALUE, EXPI_DERIVATIVE,
  EXPI_INTEGRAL, EXPI_AREA, EXPI_STATIONARY_POINTS, EXPI_INFLECTION_POINTS,
  EXPI_TANGENT, EXPI_NORMAL, EXPI_ANGLE, EXPI_V_MAG,
  EXPI_V_NORMALIZED, EXPI_V_ANGLE, EXPI_V_DOT_PRODUCT, EXPI_V_CROSS_PRODUCT,
  EXPI_V_TRIPLE_PRODUCT, EXPI_APPROXIMATE, EXPI_POLYNOMIAL_SPARSE, EXPI_POLYNOMIAL_DENSE,
  EXPI_LIST, EXPI_MATRIX, EXPI_EXTENSION, EXPI_COMMA,
  EXPI_LEFT_PARENTHESIS, EXPI_RIGHT_PARENTHESIS, EXPI_PARSE
}
 
enum  expression_to_string_format { ETSF_NULL, ETSF_INFIX, ETSF_TIKZ }
 

Functions

expressionnew_expression (expression_type type, expression_identifier identifier, uint8_t child_count,...)
 Allocates and initializes a new expression with the arguments provided. More...
 
expressionnew_literal (int8_t sign, uintmax_t numerator, uintmax_t denominator)
 Allocates and initializes a new literal expression. More...
 
expressionnew_symbol (expression_identifier identifier, const char *value)
 Allocates and initializes a new symbol/variable expression. More...
 
expressionnew_trigonometic_periodicity (uint8_t period)
 
expressioncopy_expression (const expression *source)
 Returns a deep copy of an expression. More...
 
void replace_expression (expression *a, expression *b)
 
void free_expression (expression *source, bool persistent)
 
void free_expressions (uint8_t expression_count,...)
 
void free_all_except (expression *source)
 
void append_child (expression *parent, expression *child)
 Appends a child to an expression. More...
 
void set_parents (expression *source)
 
bool expressions_are_identical (const expression *a, expression *b, bool persistent)
 
bool expressions_are_equivalent (const expression *a, expression *b, bool persistent)
 
bool expression_is_greater_than (const expression *a, expression *b, bool persistent)
 
bool expression_is_smaller_than (const expression *a, expression *b, bool persistent)
 
bool expression_is_constant (const expression *source)
 
bool symbol_is_constant (const expression *source)
 
int8_t expression_contains_division (const expression *source)
 
bool expression_is_reziprocal (const expression *source)
 
bool expression_is_numerical (const expression *source)
 
uint8_t count_occurrences (const expression *haystack, expression *needle, bool persistent)
 
void collect_symbols (expression *symbols, const expression *source)
 
void remove_child_at_index (expression *source, uint8_t index)
 
void remove_null_children (expression *source)
 
void embed_in_list_if_necessary (expression *source)
 
void merge_nested_lists (expression *source, bool recursive)
 
uint8_t swap_expressions (expression *a, expression *b)
 
void replace_occurences (expression *source, const expression *child, const expression *replacement)
 
void replace_null_with_zero (expression *source)
 
void order_children (expression *source)
 
expressionguess_symbol (const expression *source, const char *custom_priorities, uint8_t rank)
 
expressionget_symbol (const expression *source)
 
expressiondouble_to_literal (double source)
 
double literal_to_double (expression *source)
 
void literal_to_double_symbol (expression *source)
 
const char * get_expression_string (expression_identifier identifier)
 Returns the keyword string corresponding to the identifier. More...
 
expression_identifier get_expression_identifier (const char *string)
 Returns the identifier corresponding to the keyword string. More...
 
void expression_to_string (char *buffer, const expression *source, expression_to_string_format format)
 Serializes an expression into a specified format. More...
 

Variables

char * keyword_strings []
 
expression_identifier keyword_identifiers []
 

Typedef Documentation

◆ expression

typedef struct expression expression

◆ numeric_value

typedef struct numeric_value numeric_value

Enumeration Type Documentation

◆ expression_identifier

Enumerator
EXPI_NULL 
EXPI_LITERAL 
EXPI_SYMBOL 
EXPI_VARIABLE 
EXPI_EQUATION 
EXPI_ADDITION 
EXPI_SUBTRACTION 
EXPI_MULTIPLICATION 
EXPI_DIVISION 
EXPI_EXPONENTATION 
EXPI_ABS 
EXPI_LN 
EXPI_LOG 
EXPI_SIN 
EXPI_COS 
EXPI_TAN 
EXPI_ARCSIN 
EXPI_ARCCOS 
EXPI_ARCTAN 
EXPI_SIMPLIFY 
EXPI_SOLVE 
EXPI_FACTORS 
EXPI_VALUE 
EXPI_DERIVATIVE 
EXPI_INTEGRAL 
EXPI_AREA 
EXPI_STATIONARY_POINTS 
EXPI_INFLECTION_POINTS 
EXPI_TANGENT 
EXPI_NORMAL 
EXPI_ANGLE 
EXPI_V_MAG 
EXPI_V_NORMALIZED 
EXPI_V_ANGLE 
EXPI_V_DOT_PRODUCT 
EXPI_V_CROSS_PRODUCT 
EXPI_V_TRIPLE_PRODUCT 
EXPI_APPROXIMATE 
EXPI_POLYNOMIAL_SPARSE 
EXPI_POLYNOMIAL_DENSE 
EXPI_LIST 
EXPI_MATRIX 
EXPI_EXTENSION 
EXPI_COMMA 
EXPI_LEFT_PARENTHESIS 
EXPI_RIGHT_PARENTHESIS 
EXPI_PARSE 

Definition at line 40 of file expression.h.

◆ expression_to_string_format

Enumerator
ETSF_NULL 
ETSF_INFIX 
ETSF_TIKZ 

Definition at line 101 of file expression.h.

◆ expression_type

Enumerator
EXPT_NULL 
EXPT_VALUE 
EXPT_OPERATION 
EXPT_FUNCTION 
EXPT_STRUCTURE 
EXPT_CONTROL 

Definition at line 31 of file expression.h.

Function Documentation

◆ append_child()

void append_child ( expression parent,
expression child 
)

Appends a child to an expression.

When DEBUG_MODE is set to 0 (production mode), the children pointer is resized to hold the new child.

Parameters
[in,out]parentThe destination parent.
[in]childThe child to be appended.

Definition at line 383 of file expression.c.

◆ collect_symbols()

void collect_symbols ( expression symbols,
const expression source 
)

Definition at line 815 of file expression.c.

◆ copy_expression()

expression* copy_expression ( const expression source)

Returns a deep copy of an expression.

This function recursively (post-order traversal) copies an expression and all its children. The copied expression is returned.

Note
  • Null-children are not included in the copy.
Parameters
[in]sourceThe expression to copy.
Returns
  • Pointer to the copy.

Definition at line 286 of file expression.c.

◆ count_occurrences()

uint8_t count_occurrences ( const expression haystack,
expression needle,
bool  persistent 
)

Definition at line 664 of file expression.c.

◆ double_to_literal()

expression* double_to_literal ( double  source)

Definition at line 896 of file expression.c.

◆ embed_in_list_if_necessary()

void embed_in_list_if_necessary ( expression source)

Definition at line 417 of file expression.c.

◆ expression_contains_division()

int8_t expression_contains_division ( const expression source)

Definition at line 622 of file expression.c.

◆ expression_is_constant()

bool expression_is_constant ( const expression source)

Definition at line 593 of file expression.c.

◆ expression_is_greater_than()

bool expression_is_greater_than ( const expression a,
expression b,
bool  persistent 
)

Definition at line 547 of file expression.c.

◆ expression_is_numerical()

bool expression_is_numerical ( const expression source)

Definition at line 646 of file expression.c.

◆ expression_is_reziprocal()

bool expression_is_reziprocal ( const expression source)

Definition at line 636 of file expression.c.

◆ expression_is_smaller_than()

bool expression_is_smaller_than ( const expression a,
expression b,
bool  persistent 
)

Definition at line 570 of file expression.c.

◆ expression_to_string()

void expression_to_string ( char *  buffer,
const expression source,
expression_to_string_format  format 
)

Serializes an expression into a specified format.

This function calls expression_to_infix() or expression_to_tkiz(), depending on the specified format. It automatically converts all polynomials to expressions and sets parents. No further simplification is applied. The result can be tweaked by changing the bools use_abbrevations and use_spaces, defined in symbolic4.c.

Parameters
[in,out]bufferThe buffer where the resulting string shall be written into.
[in]sourceThe expression to be serialized.
[in]formatThe serialization format.
See also

Definition at line 1031 of file expression.c.

◆ expressions_are_equivalent()

bool expressions_are_equivalent ( const expression a,
expression b,
bool  persistent 
)

Definition at line 526 of file expression.c.

◆ expressions_are_identical()

bool expressions_are_identical ( const expression a,
expression b,
bool  persistent 
)

Definition at line 467 of file expression.c.

◆ free_all_except()

void free_all_except ( expression source)

Definition at line 353 of file expression.c.

◆ free_expression()

void free_expression ( expression source,
bool  persistent 
)

Definition at line 315 of file expression.c.

◆ free_expressions()

void free_expressions ( uint8_t  expression_count,
  ... 
)

Definition at line 338 of file expression.c.

◆ get_expression_identifier()

expression_identifier get_expression_identifier ( const char *  string)

Returns the identifier corresponding to the keyword string.

The keyword_strings array is searched for the first occurrence of the given string. When found, the identifier from keyword_identifiers with the same index is returned. This function is case insensitive and handles abbrevations.

Parameters
[in]stringThe keyword string.
Returns
  • The identifier corresponding to the string.
See also

Definition at line 987 of file expression.c.

◆ get_expression_string()

const char* get_expression_string ( expression_identifier  identifier)

Returns the keyword string corresponding to the identifier.

The keyword_identifiers array is searched for the first occurrence of the given identifier. When found, the string from keyword_strings with the same index is returned. If use_abbrevations is set to true, the abbrevation (the next string, if existent) is returned.

Parameters
[in]identifierThe expression identifier.
Returns
  • The string corresponding to the identifier.
See also

Definition at line 950 of file expression.c.

◆ get_symbol()

expression* get_symbol ( const expression source)

Definition at line 878 of file expression.c.

◆ guess_symbol()

expression* guess_symbol ( const expression source,
const char *  custom_priorities,
uint8_t  rank 
)

Definition at line 830 of file expression.c.

◆ literal_to_double()

double literal_to_double ( expression source)

Definition at line 908 of file expression.c.

◆ literal_to_double_symbol()

void literal_to_double_symbol ( expression source)

Definition at line 912 of file expression.c.

◆ merge_nested_lists()

void merge_nested_lists ( expression source,
bool  recursive 
)

Definition at line 424 of file expression.c.

◆ new_expression()

expression* new_expression ( expression_type  type,
expression_identifier  identifier,
uint8_t  child_count,
  ... 
)

Allocates and initializes a new expression with the arguments provided.

This function returns a new expression which is initialized with the arguments provided and in sign = 1. This function is especially useful when being nested to build up more complex expressions in one line. Children are not copied.

Parameters
[in]typeThe expression type.
[in]identifierThe expression identifier.
[in]child_countThe number of children. It must match the actual number of children provided.
[in]...The child expressions. They may be calls to new_expression().
Returns
  • The initialized expression.
See also

Definition at line 183 of file expression.c.

◆ new_literal()

expression* new_literal ( int8_t  sign,
uintmax_t  numerator,
uintmax_t  denominator 
)

Allocates and initializes a new literal expression.

This function returns a new literal which is initialized with the arguments provided. The result is automatically reduced.

Parameters
[in]sign(either 1 or -1)
[in]numeratorThe numeric numerator.
[in]denominatorThe numeric denominator.
Returns
  • The initialized literal.
See also

Definition at line 225 of file expression.c.

◆ new_symbol()

expression* new_symbol ( expression_identifier  identifier,
const char *  value 
)

Allocates and initializes a new symbol/variable expression.

This function returns a new literal which is initialized with the argument provided.

Parameters
[in]identifier(either EXPI_SYMBOL or EXPI_VARIABLE)
[in]valueThe symbolic value.
Returns
  • The initialized symbol.
See also

Definition at line 252 of file expression.c.

◆ new_trigonometic_periodicity()

expression* new_trigonometic_periodicity ( uint8_t  period)

Definition at line 258 of file expression.c.

◆ order_children()

void order_children ( expression source)

Definition at line 769 of file expression.c.

◆ remove_child_at_index()

void remove_child_at_index ( expression source,
uint8_t  index 
)

Definition at line 397 of file expression.c.

◆ remove_null_children()

void remove_null_children ( expression source)

Definition at line 403 of file expression.c.

◆ replace_expression()

void replace_expression ( expression a,
expression b 
)

Definition at line 309 of file expression.c.

◆ replace_null_with_zero()

void replace_null_with_zero ( expression source)

Definition at line 703 of file expression.c.

◆ replace_occurences()

void replace_occurences ( expression source,
const expression child,
const expression replacement 
)

Definition at line 688 of file expression.c.

◆ set_parents()

void set_parents ( expression source)

Definition at line 455 of file expression.c.

◆ swap_expressions()

uint8_t swap_expressions ( expression a,
expression b 
)

Definition at line 718 of file expression.c.

◆ symbol_is_constant()

bool symbol_is_constant ( const expression source)

Definition at line 611 of file expression.c.

Variable Documentation

◆ keyword_identifiers

expression_identifier keyword_identifiers[]

Definition at line 91 of file expression.c.

◆ keyword_strings

char* keyword_strings[]

Definition at line 28 of file expression.c.