symbolic4
|
#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 |
Functions | |
expression * | new_expression (expression_type type, expression_identifier identifier, uint8_t child_count,...) |
Allocates and initializes a new expression with the arguments provided. More... | |
expression * | new_literal (int8_t sign, uintmax_t numerator, uintmax_t denominator) |
Allocates and initializes a new literal expression. More... | |
expression * | new_symbol (expression_identifier identifier, const char *value) |
Allocates and initializes a new symbol/variable expression. More... | |
expression * | new_trigonometic_periodicity (uint8_t period) |
expression * | copy_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) |
expression * | guess_symbol (const expression *source, const char *custom_priorities, uint8_t rank) |
expression * | get_symbol (const expression *source) |
expression * | double_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 struct expression expression |
typedef struct numeric_value numeric_value |
Definition at line 40 of file expression.h.
Enumerator | |
---|---|
ETSF_NULL | |
ETSF_INFIX | |
ETSF_TIKZ |
Definition at line 101 of file expression.h.
enum expression_type |
Enumerator | |
---|---|
EXPT_NULL | |
EXPT_VALUE | |
EXPT_OPERATION | |
EXPT_FUNCTION | |
EXPT_STRUCTURE | |
EXPT_CONTROL |
Definition at line 31 of file expression.h.
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.
[in,out] | parent | The destination parent. |
[in] | child | The child to be appended. |
Definition at line 383 of file expression.c.
void collect_symbols | ( | expression * | symbols, |
const expression * | source | ||
) |
Definition at line 815 of file expression.c.
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.
[in] | source | The expression to copy. |
Definition at line 286 of file expression.c.
uint8_t count_occurrences | ( | const expression * | haystack, |
expression * | needle, | ||
bool | persistent | ||
) |
Definition at line 664 of file expression.c.
expression* double_to_literal | ( | double | source | ) |
Definition at line 896 of file expression.c.
void embed_in_list_if_necessary | ( | expression * | source | ) |
Definition at line 417 of file expression.c.
int8_t expression_contains_division | ( | const expression * | source | ) |
Definition at line 622 of file expression.c.
bool expression_is_constant | ( | const expression * | source | ) |
Definition at line 593 of file expression.c.
bool expression_is_greater_than | ( | const expression * | a, |
expression * | b, | ||
bool | persistent | ||
) |
Definition at line 547 of file expression.c.
bool expression_is_numerical | ( | const expression * | source | ) |
Definition at line 646 of file expression.c.
bool expression_is_reziprocal | ( | const expression * | source | ) |
Definition at line 636 of file expression.c.
bool expression_is_smaller_than | ( | const expression * | a, |
expression * | b, | ||
bool | persistent | ||
) |
Definition at line 570 of file expression.c.
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.
[in,out] | buffer | The buffer where the resulting string shall be written into. |
[in] | source | The expression to be serialized. |
[in] | format | The serialization format. |
Definition at line 1031 of file expression.c.
bool expressions_are_equivalent | ( | const expression * | a, |
expression * | b, | ||
bool | persistent | ||
) |
Definition at line 526 of file expression.c.
bool expressions_are_identical | ( | const expression * | a, |
expression * | b, | ||
bool | persistent | ||
) |
Definition at line 467 of file expression.c.
void free_all_except | ( | expression * | source | ) |
Definition at line 353 of file expression.c.
void free_expression | ( | expression * | source, |
bool | persistent | ||
) |
Definition at line 315 of file expression.c.
void free_expressions | ( | uint8_t | expression_count, |
... | |||
) |
Definition at line 338 of file expression.c.
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.
[in] | string | The keyword string. |
Definition at line 987 of file expression.c.
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.
[in] | identifier | The expression identifier. |
Definition at line 950 of file expression.c.
expression* get_symbol | ( | const expression * | source | ) |
Definition at line 878 of file expression.c.
expression* guess_symbol | ( | const expression * | source, |
const char * | custom_priorities, | ||
uint8_t | rank | ||
) |
Definition at line 830 of file expression.c.
double literal_to_double | ( | expression * | source | ) |
Definition at line 908 of file expression.c.
void literal_to_double_symbol | ( | expression * | source | ) |
Definition at line 912 of file expression.c.
void merge_nested_lists | ( | expression * | source, |
bool | recursive | ||
) |
Definition at line 424 of file expression.c.
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.
[in] | type | The expression type. |
[in] | identifier | The expression identifier. |
[in] | child_count | The number of children. It must match the actual number of children provided. |
[in] | ... | The child expressions. They may be calls to new_expression() . |
Definition at line 183 of file expression.c.
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.
[in] | sign | (either 1 or -1) |
[in] | numerator | The numeric numerator. |
[in] | denominator | The numeric denominator. |
Definition at line 225 of file expression.c.
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.
[in] | identifier | (either EXPI_SYMBOL or EXPI_VARIABLE ) |
[in] | value | The symbolic value. |
Definition at line 252 of file expression.c.
expression* new_trigonometic_periodicity | ( | uint8_t | period | ) |
Definition at line 258 of file expression.c.
void order_children | ( | expression * | source | ) |
Definition at line 769 of file expression.c.
void remove_child_at_index | ( | expression * | source, |
uint8_t | index | ||
) |
Definition at line 397 of file expression.c.
void remove_null_children | ( | expression * | source | ) |
Definition at line 403 of file expression.c.
void replace_expression | ( | expression * | a, |
expression * | b | ||
) |
Definition at line 309 of file expression.c.
void replace_null_with_zero | ( | expression * | source | ) |
Definition at line 703 of file expression.c.
void replace_occurences | ( | expression * | source, |
const expression * | child, | ||
const expression * | replacement | ||
) |
Definition at line 688 of file expression.c.
void set_parents | ( | expression * | source | ) |
Definition at line 455 of file expression.c.
uint8_t swap_expressions | ( | expression * | a, |
expression * | b | ||
) |
Definition at line 718 of file expression.c.
bool symbol_is_constant | ( | const expression * | source | ) |
Definition at line 611 of file expression.c.
expression_identifier keyword_identifiers[] |
Definition at line 91 of file expression.c.
char* keyword_strings[] |
Definition at line 28 of file expression.c.