Loading...
Searching...
No Matches
doc_summary_of_string_math Class Reference

## Detailed Description

  The text-string form of mathematical formulas produced by formulaToString() and read by 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. The following are illustrative examples of formulas expressed using this syntax:

      0.10 * k4^2

      (vm * s1)/(km + s1)

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.

Token | Operation | Class | Precedence | Associates
--- | --- | --- | --- | ---
name | symbol reference | operand | 6 | n/a
`(`expression`)` | expression grouping | operand | 6 | n/a
`f(`...`)` | function call | prefix | 6 | left
`-` | negation | unary | 5 | right
`^` | power | binary | 4 | left
`*` | multiplication | binary | 3 | left
`/` | divison | binary | 3 | left
`+` | addition | binary | 2 | left
`-` | subtraction | binary | 2 | left
`,` | argument delimiter | binary | 1 | left
A table of the expression operators and their precedence in the text-string format for mathematical expressions used by SBML_parseFormula().

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 `+` and `-` 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
--- | --- | --- | --- | ---
`abs` | x | absolute value of x |  |
`acos` | x | arc cosine of x in radians | -1.0 ≤ x ≤ 1.0 | 0 ≤ acos(x) ≤ π
`asin` | x | arc sine of x in radians | -1.0 ≤ x ≤ 1.0 | 0 ≤ asin(x) ≤ π
`atan` | x | arc tangent of x in radians |  | 0 ≤ atan(x) ≤ π
`ceil` | x | smallest number not less than x whose value is an exact integer |  |
`cos` | x | cosine of x |  |
`exp` | x | e x, where e is the base of the natural logarithm |  |
`floor` | x | largest number not greater than x whose value is an exact integer |  |
`log` | x | natural logarithm of x | x > 0 |
`log10` | x | base 10 logarithm of x | x > 0 |
`pow` | x, y | x y |  |
`sqr` | x | x2 |  |
`sqrt` | x | √x | x > 0 | sqrt(x) ≥ 0
`sin` | x | sine of x |  |
`tan` | x | tangent of x | x ≠ n*π/2, for odd integer n |
The names of mathematical functions defined in the SBML Level 1 Version 2 text-string formula syntax.

Warning
  There are differences between the symbols used to represent the common mathematical functions and the corresponding MathML token names. This is a potential source of incompatibilities. Note in particular that in this text-string syntax, `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.