Class LqnLld
n, evaluated over complex numbers.
Python's export_nlp takes such a multiplier as python source and
evals it. The other codebases cannot, so they share this SMALL GRAMMAR,
identical in MATLAB, the JAR and C++:
expr := term (('+'|'-') term)*
term := unary (('*'|'/') unary)*
unary := ('+'|'-') unary | power
power := atom ('**' unary)?
atom := NUMBER | 'n' | FUNC '(' expr ')' | '(' expr ')'
FUNC := exp | log | sqrt | sin | cos | tanh, optionally prefixed 'np.' or 'math.'
abs and np.abs evaluate to the REAL modulus, which is not
analytic, so check(java.lang.String) reports it as python does. min and
max (any prefix) take the smaller or larger of their real arguments and
refuse a complex one, as python's builtins raise a TypeError on it. Any other
identifier fails at evaluation with python's NameError, and a malformed
expression is refused as not a python expression.
The expression MUST BE ANALYTIC: the program's Jacobian differentiates it by
complex step, and an operation that silently drops the imaginary part (abs, a
comparison, an interpolation) would leave the Newton step wrong rather than slow.
check(java.lang.String) is a verbatim port of python's _check_lld, which compares
the complex step against a central difference to catch exactly that.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA failure inside a user expression, named as python names it.static final classA malformed expression, what python'scompilerefuses with a SyntaxError. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringWhat the program needs of a rate multiplier, checked here: python's_check_lld, verbatim.static LqnLldParse an expression.Evaluate at a (possibly complex) population.doubleevalReal(double n) Evaluate at a real population; the real part of the value.static StringpyG(double x) Python's'%g' % x: six significant digits, trailing zeros dropped.static StringpyRepr(double x) Python'sreprof a float: the shortest round-tripping digits, fixed notation between 1e-4 and 1e16 and scientific with a two-digit exponent outside it.source()The source text this expression was compiled from.
-
Method Details
-
compile
Parse an expression.- Parameters:
src- the expression inn- Returns:
- the compiled expression
- Throws:
LqnLld.SyntaxErr- when the text is not an expression of the grammar
-
source
The source text this expression was compiled from. -
eval
Evaluate at a (possibly complex) population.- Throws:
LqnLld.PyError- what python would raise evaluating the same source
-
evalReal
public double evalReal(double n) Evaluate at a real population; the real part of the value. -
check
What the program needs of a rate multiplier, checked here: python's_check_lld, verbatim.Positive and real on the range of populations a station can hold, and ANALYTIC, since the Jacobian differentiates it by complex step. Comparing the complex step against a central difference catches abs, min, max, a comparison or an interpolation, which all evaluate perfectly well and all silently return a complex step of zero or nonsense.
- Parameters:
src- the expression- Returns:
- the empty string when usable, else the reason it is not
-
pyRepr
Python'sreprof a float: the shortest round-tripping digits, fixed notation between 1e-4 and 1e16 and scientific with a two-digit exponent outside it. -
pyG
Python's'%g' % x: six significant digits, trailing zeros dropped.
-