Package jline.api.lqn

Class LqnNlpComplex

java.lang.Object
jline.api.lqn.LqnNlpComplex

public final class LqnNlpComplex extends Object
An immutable complex scalar for the COMPLEX-STEP derivatives of the NLP program.

The program differentiates its rate functions and its fork closure by complex step: f(x + ih) has imaginary part h*f'(x) + O(h^3), which is exact to machine precision for an analytic f. Only the handful of operations the program and the queue-dependent rate grammar (LqnLld) need are here, written so that an argument with a zero imaginary part goes through exactly the real arithmetic (python's complex arithmetic, which this mirrors, has the same property).

cplx records whether the value is of COMPLEX TYPE in python's sense: once a complex operand enters an expression the result stays complex even if its imaginary part happens to cancel, and a few operations (python's max, min, math.*) refuse a complex argument whatever its value.

  • Field Details

    • re

      public final double re
    • im

      public final double im
    • cplx

      public final boolean cplx
  • Constructor Details

    • LqnNlpComplex

      public LqnNlpComplex(double re, double im, boolean cplx)
  • Method Details

    • real

      public static LqnNlpComplex real(double x)
      A real number.
    • of

      public static LqnNlpComplex of(double re, double im)
      A complex number, complex-typed whatever its imaginary part.
    • isComplex

      public boolean isComplex()
    • add

      public LqnNlpComplex add(LqnNlpComplex b)
    • sub

      public LqnNlpComplex sub(LqnNlpComplex b)
    • neg

      public LqnNlpComplex neg()
    • mul

      public LqnNlpComplex mul(LqnNlpComplex b)
    • mul

      public LqnNlpComplex mul(double s)
    • div

      public LqnNlpComplex div(LqnNlpComplex b)
      Division as CPython's _Py_c_quot: scaled by the larger component of the divisor, so a real divisor divides exactly.
      Throws:
      ArithmeticException - on a zero divisor, as python raises ZeroDivisionError
    • exp

      public LqnNlpComplex exp()
    • log

      public LqnNlpComplex log()
      Principal logarithm; a negative real argument gives NaN, as numpy's real log does.
    • sqrt

      public LqnNlpComplex sqrt()
      Principal square root; a negative real argument gives NaN, as numpy's real sqrt does.
    • sin

      public LqnNlpComplex sin()
    • cos

      public LqnNlpComplex cos()
    • tanh

      public LqnNlpComplex tanh()
    • abs

      public LqnNlpComplex abs()
      The modulus, a REAL number: python's abs of a complex is a float.
    • pow

      public LqnNlpComplex pow(LqnNlpComplex y)
      Python's **. Two reals take the real power, except that a negative base under a fractional exponent turns complex as python's does. A complex operand with an integral real exponent of modulus at most 100 is raised by repeated multiplication (CPython's c_powi); anything else is exp(y*log(x)).
    • toString

      public String toString()
      Overrides:
      toString in class Object