Grammar#
This page describes the grammar of function expressions in FuncSketch.
Types#
FuncSketch supports the following types of values:
Type |
Description |
|---|---|
Integer |
32-bit signed integers. |
Real |
Double-precision floating-point numbers. |
When you write a number in a function expression, it is automatically recognized as follows:
Integerif it is an integer number without a decimal point (e.g.1,-12,0)Realif it is a number with a decimal point and/or an exponent (e.g.1.0,-12.34,1e+6)
Note
Future implementation may support boolean and complex numbers.
Implicit Conversions#
Integercan be implicitly converted toReal. This conversion is done automatically when anIntegervalue is used with aRealvalue in binary operations (e.g.1 + 2.0), or when anIntegervalue is passed to a function that takes aRealargument.
Operators#
The following operators are supported:
Operator |
Description |
|---|---|
|
Negation |
|
Addition |
|
Subtraction |
|
Multiplication |
|
Division |
|
Power \(x^y\) (Works the same as |
Note
** is right-associative (e.g. 2 ** 3 ** 4 is parsed as
2 ** (3 ** 4)).
Note
The right operand of ** cannot be directly preceded by -
unless it is a number literal (e.g. 2 ** -3 is valid).
To negate an identifier, a function call, or a parenthesized
expression, wrap it in parentheses
(e.g. 2 ** (-x) instead of 2 ** -x).
Operator Precedence#
Operators have the following precedence (from highest to lowest):
**(power)-(negation)*,/(multiplication, division)+,-(addition, subtraction)
You can use parentheses () to change the order of evaluation.
Identifiers#
In function expressions, the following identifiers exist:
Parameter of the function. Currently
xis the only parameter name.Constants. (e.g.
pi,e)Functions. (e.g.
sin,exp)
Identifiers before ( are treated as function names,
and other identifiers are treated as parameters or constants.
For example,
When
exp(x)is parsed, FuncSketch searches for a function namedexp.When
x + 1is parsed, FuncSketch searches for a constant or a parameter namedx.
For built-in names of constants and functions, see Built-in Constants and Built-in Functions.