Package jline.api.lqn

Class LqnLld

java.lang.Object
jline.api.lqn.LqnLld

public final class LqnLld extends Object
A queue-dependent rate multiplier of the NLP program: an expression in the number of jobs present, 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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    A failure inside a user expression, named as python names it.
    static final class 
    A malformed expression, what python's compile refuses with a SyntaxError.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    What the program needs of a rate multiplier, checked here: python's _check_lld, verbatim.
    static LqnLld
    Parse an expression.
    Evaluate at a (possibly complex) population.
    double
    evalReal(double n)
    Evaluate at a real population; the real part of the value.
    static String
    pyG(double x)
    Python's '%g' % x: six significant digits, trailing zeros dropped.
    static String
    pyRepr(double x)
    Python's repr of a float: the shortest round-tripping digits, fixed notation between 1e-4 and 1e16 and scientific with a two-digit exponent outside it.
    The source text this expression was compiled from.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • compile

      public static LqnLld compile(String src)
      Parse an expression.
      Parameters:
      src - the expression in n
      Returns:
      the compiled expression
      Throws:
      LqnLld.SyntaxErr - when the text is not an expression of the grammar
    • source

      public String source()
      The source text this expression was compiled from.
    • eval

      public LqnNlpComplex eval(LqnNlpComplex n)
      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

      public static String check(String src)
      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

      public static String pyRepr(double x)
      Python's repr of a float: the shortest round-tripping digits, fixed notation between 1e-4 and 1e16 and scientific with a two-digit exponent outside it.
    • pyG

      public static String pyG(double x)
      Python's '%g' % x: six significant digits, trailing zeros dropped.