libSBML C++ API 5.8.0
Formats an AST formula tree as an SBML formula string.
|char *||SBML_formulaToString (const ASTNode_t *tree)|
|Converts an AST to a string representation of a formula using a syntax basically derived from SBML Level 1. |
|char* SBML_formulaToString||(||const ASTNode_t *||tree||)|
Converts an AST to a string representation of a formula using a syntax basically derived from SBML Level 1.
The text-string form of mathematical formulas produced by SBML_formulaToString() and read by SBML_parseFormula() use a simple C-inspired infix notation taken from SBML Level 1. A formula in this text-string form therefore can be handed to a program that understands SBML Level 1 mathematical expressions, or used as part of a formula translation system. The syntax is described in detail in the documentation for ASTNode.
Note that this facility is provided as a convenience by libSBML—the MathML standard does not actually define a "string-form" equivalent to MathML expression trees, so the choice of formula syntax is somewhat arbitrary. The approach taken by libSBML is to use the syntax defined by SBML Level 1 (which in fact used a text-string representation of formulas and not MathML). This formula syntax is based mostly on C programming syntax, and may contain operators, function calls, symbols, and white space characters. The following table provides the precedence rules for the different entities that may appear in formula strings.
In the table above, operand implies the construct is an operand, prefix implies the operation is applied to the following arguments, unary implies there is one argument, and binary implies there are two arguments. The values in the Precedence column show how the order of different types of operation are determined. For example, the expression
a * b + c is evaluated as
(a * b) + c because the
* operator has higher precedence. The Associates column shows how the order of similar precedence operations is determined; for example,
a - b + c is evaluated as
(a - b) + c because the
- operators are left-associative.
The function call syntax consists of a function name, followed by optional white space, followed by an opening parenthesis token, followed by a sequence of zero or more arguments separated by commas (with each comma optionally preceded and/or followed by zero or more white space characters, followed by a closing parenthesis token. The function name must be chosen from one of the pre-defined functions in SBML or a user-defined function in the model. The following table lists the names of certain common mathematical functions; this table corresponds to Table 6 in the SBML Level 1 Version 2 specification:
|Name||Args||Formula or meaning||Argument Constraints||Result constraints|
|x||absolute value of x|
|x||arc cosine of x in radians||-1.0 ≤ x ≤ 1.0||0 ≤ acos(x) ≤ π|
|x||arc sine of x in radians||-1.0 ≤ x ≤ 1.0||0 ≤ asin(x) ≤ π|
|x||arc tangent of x in radians||0 ≤ atan(x) ≤ π|
|x||smallest number not less than x whose value is an exact integer|
|x||cosine of x|
|x||e x, where e is the base of the natural logarithm|
|x||the largest number not greater than x whose value is an exact integer|
|x||natural logarithm of x||x > 0|
|x||base 10 logarithm of x||x > 0|
|x, y||x y|
|x||√x||x > 0||sqrt(x) ≥ 0|
|x||sine of x|
|x||tangent of x||x ≠ n*π/2, for odd integer n|
log(x)represents the natural logarithm, whereas in MathML, the natural logarithm is
<ln/>. Application writers are urged to be careful when translating between text forms and MathML forms, especially if they provide a direct text-string input facility to users of their software systems.
|tree||the AST to be converted.|