jmathlib.core.tokens
Class SparseNumberToken

java.lang.Object
  extended by jmathlib.core.interpreter.RootObject
      extended by jmathlib.core.tokens.Token
          extended by jmathlib.core.tokens.OperandToken
              extended by jmathlib.core.tokens.DataToken
                  extended by jmathlib.core.tokens.SparseNumberToken
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ErrorCodes, TokenConstants

public class SparseNumberToken
extends DataToken

Class representing numbers used in expression holds a 2D array of complex numers in a 3d array values[y][x][REAL/IMAGINARY] All operations on a DoubleNumberToken create a new DoubleNumberToken

See Also:
Serialized Form

Field Summary
static DoubleNumberToken j
          Constant value set to j
static DoubleNumberToken one
          Constant value set to 1
static DoubleNumberToken two
          Constant value set to 2
static DoubleNumberToken zero
          Constant value set to 0
 
Fields inherited from class jmathlib.core.tokens.DataToken
dataType, noElem, sizeA, sizeX, sizeY
 
Fields inherited from class jmathlib.core.tokens.Token
priority
 
Fields inherited from interface jmathlib.core.constants.TokenConstants
ADDSUB_PRIORITY, AND_PRIORITY, ANDAND_PRIORITY, ASSIGN_PRIORITY, BRACKET_PRIORITY, COMPARE_PRIORITY, CONCAT, MATRIX, MULDIV_PRIORITY, OR_PRIORITY, OROR_PRIORITY, PARAMETER, POWER_PRIORITY, RELATION_PRIORITY, SINGLE, ttDelimiter, ttNotSet, ttOperand, ttOperator
 
Fields inherited from interface jmathlib.core.constants.ErrorCodes
ERR_BRACKET_OPEN, ERR_BRACKET_ORDER, ERR_FUNCTION_NOT_FOUND, ERR_FUNCTION_NOT_IMPLEMENTED, ERR_INSUFFICIENT_PARAMETERS, ERR_INVALID_PARAMETER, ERR_LVALUE_REQUIRED, ERR_MATRIX_SINGULAR, ERR_NOT_SQUARE_MATRIX, ERR_OPNOTSUPPORTED, ERR_TOO_MANY_PARAMETERS, ERR_USER_ERROR, ERR_VARIABLE_NOTDEFINED, OK, OK_FUNCTION_PROCESS
 
Constructor Summary
SparseNumberToken()
          Constructor creating empty number token
SparseNumberToken(double _value)
          Constructor creating a scalar taking the numbers value as a double
SparseNumberToken(double[] _values)
          Constructor taking the numbers value as a pair of double values representing real and imaginary part
SparseNumberToken(double[][] _values)
          Constructor taking the numbers value as a double[][]
SparseNumberToken(double[][][] _values)
          Constructor taking the numbers value as a double[][][]
SparseNumberToken(double[][] _real, double[][] _imaginary)
          Constructor taking the numbers value as two double[][]
SparseNumberToken(double _real, double _imaginary)
          Constructor taking the numbers value as a pair of double values representing real and imaginary part
SparseNumberToken(java.lang.String _value)
          Constructor creating a scalar taking the numbers value as a string
SparseNumberToken(java.lang.String _real, java.lang.String _imaginary)
          Constructor taking the numbers value as a string
 
Method Summary
 OperandToken abs()
          Standard functions - absolute value
 OperandToken acos()
          trigonometric functions - calculate the arc cosine of this token
 double[] acos(double[] arg)
          Calculates the arccosine of a complex number
 OperandToken acosh()
          Trigonometric function - calculates the inverse hyperbolic cosine
 double[] acosh(double[] arg)
          Calculates the inverse hyperbolic cosine of a complex number
 OperandToken add(OperandToken arg)
          add arg to this object for a number token
 double arg(int y, int x)
          calculate the arg of the complex number at y, x
 OperandToken asin()
          trigonometric functions - calculate the arc sine of this token
 double[] asin(double[] arg)
          Calculates the arcsine of a complex number
 OperandToken asinh()
          Trigonometric function - calculates the inverse hyperbolic sine
 double[] asinh(double[] arg)
          Calculates the inverse hyperbolic sine of a complex number
 OperandToken atan()
          trigonometric functions - calculate the arc tangent of this token
 double[] atan(double[] arg)
          Calculates the arctangent of a complex number
 OperandToken atanh()
          Trigonometric function - calculates the inverse hyperbolic tangent
 double[] atanh(double[] arg)
          Calculates the inverse hyperbolic tangent of a complex number
 OperandToken ceil()
          Standard functions - rounds the value up
 OperandToken conjugate()
          Complex function - calculates the complex conjugate of the number
 OperandToken cos()
          trigonometric functions - calculate the cosine of this token
 double[] cos(double[] arg)
          Calculates the cosine of a complex number
 OperandToken cosh()
          Trigonometric function - calculates the hyperbolic cosine
 double[] cosh(double[] arg)
          Calculates the hyperbolic cosine of a complex number
 OperandToken ctranspose()
          calculate the conjugate transpose of a matrix
 OperandToken degreesToRadians()
           
 double[] divide(double[] arg1, double[] arg2)
          divide two complex numbers and return a complex number again, pay special attention to infinity and not a number
 OperandToken divide(OperandToken arg)
          divide this object by arg for a number token
 boolean equals(java.lang.Object arg)
          Check if two tokens are equal
 OperandToken evaluate(Token[] operands)
          Evaluate the token.
 OperandToken exp()
          Standard functions - calculates the exponent
 double[] exp(double[] arg)
          Calculates the exponent of a complex number
 OperandToken factorial()
          Standard functions - calculates the factorial of the number
 double factorial(double amount)
          Calulates the factorial of a real value
 OperandToken floor()
          Standard functions - rounds the value down
 DataToken getElementSized(int y, int x)
          return a new Number Token of size y*x
 double[][] getImValues()
           
 int getIntValue(int y, int x)
           
 double[][] getReValues()
           
 double getValue()
           
 double getValueAbs(int y, int x)
           
 double getValueArg(int y, int x)
           
 double[] getValueComplex(int y, int x)
           
 double getValueIm()
           
 double getValueIm(int y, int x)
           
 double getValueRe(int y, int x)
           
 double[][] getValuesImg()
           
 double[][] getValuesSSSSS()
           
 boolean isComplex()
           
 boolean isImaginary()
           
 boolean isInteger()
           
 boolean isNull()
          Checks if this operand is zero
 boolean isNumeric()
          Checks if this operand is a numeric value
 boolean isReal()
           
 boolean isScalar()
           
 OperandToken leftDivide(OperandToken arg)
          left divide
 OperandToken ln()
          Standard functions - calculates the natural logarythm
 OperandToken log()
          Standard functions - calculates the logarythm
 double[] log(double[] arg)
          Calculates the logarythm of a complex number
 OperandToken max(RootObject arg)
          Standard functions - calculates the maximum of two values
 OperandToken min(RootObject arg)
          Standard functions - calculates the minimum of two values
 double[] multiply(double[] arg1, double[] arg2)
          Multiplies two complex numbers
 OperandToken multiply(OperandToken arg)
          multiply arg by this object for a number token
 OperandToken negate()
          standard function - returns the negative of the number
 OperandToken power(OperandToken arg)
          Raise this object to the power of arg
 OperandToken radiansToDegrees()
           
 OperandToken round()
          Standard functions - rounds the value to the nearest integer
 OperandToken scalarDivide(OperandToken arg)
          scalar divide arg by this object for a number token
 OperandToken scalarLeftDivide(OperandToken arg)
          scalar left divide
 OperandToken scalarMultiply(OperandToken arg)
          scalar multiply arg by this object for a number token
 void setElement(int y, int x, OperandToken num)
           
 void setElement(int n, OperandToken num)
           
 void setSize(int dy, int dx)
          increase/decrease the size of the current DoubleNumberToken to size y*x
 void setValue(int y, int x, double _real, double _imag)
          Set value at position y, x
 void setValueComplex(int y, int x, double[] _value)
          Set value at position y, x
 OperandToken sin()
          trigonometric functions - calculate the sine of this token
 double[] sin(double[] arg)
          Calculates the sine of a complex number
 OperandToken sinh()
          Trigonometric function - calculates the hyperbolic sine
 double[] sinh(double[] arg)
          Calculates the hyperbolic sine of a complex number
 OperandToken sqrt()
          Standard functions - calculates the square root
 double[] sqrt(double[] arg)
          Calculates the sqrt of a complex number
 OperandToken subtract(OperandToken arg)
          subtract arg from this object for a number token
 OperandToken tan()
          trigonometric functions - calculate the tangent of this token
 double[] tan(double[] arg)
          Calculates the tangent of a complex number
 OperandToken tanh()
          Trigonometric function - calculates the hyperbolic tan
 double[] tanh(double[] arg)
          Calculates the hyperbolic tangent of a complex number
 java.lang.String toString()
          return the number as a string
 java.lang.String toString(double[] _values)
          create string representation of (complex) double values
 OperandToken transpose()
          calculate the transpose of a matrix
 
Methods inherited from class jmathlib.core.tokens.DataToken
checkEqualDimensions, getDataType, getDimensions, getElement, getElement, getNumberOfElements, getSize, getSizeX, getSizeY
 
Methods inherited from class jmathlib.core.tokens.OperandToken
asArray, Children, derivative, expand, integral, isLeaf, mpower, mPower, simplify, subst
 
Methods inherited from class jmathlib.core.tokens.Token
isDisplayResult, setDisplayResult, toMathMlString
 
Methods inherited from class jmathlib.core.interpreter.RootObject
clone, getContextList, getDebug, getFunctionManager, getGlobalVariables, getGraphicsManager, getInterpreter, getPluginsManager, getVariable, getVariables, getWorkingDirectory, setConstants, setDebug, setWorkingDirectory, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

one

public static final DoubleNumberToken one
Constant value set to 1


zero

public static final DoubleNumberToken zero
Constant value set to 0


two

public static final DoubleNumberToken two
Constant value set to 2


j

public static final DoubleNumberToken j
Constant value set to j

Constructor Detail

SparseNumberToken

public SparseNumberToken()
Constructor creating empty number token


SparseNumberToken

public SparseNumberToken(java.lang.String _value)
Constructor creating a scalar taking the numbers value as a string

Parameters:
_value - = the numbers value as a string

SparseNumberToken

public SparseNumberToken(double _value)
Constructor creating a scalar taking the numbers value as a double

Parameters:
_value - = the numbers value as a double

SparseNumberToken

public SparseNumberToken(double[][] _values)
Constructor taking the numbers value as a double[][]

Parameters:
_value - = the numbers value as a 2D array of double

SparseNumberToken

public SparseNumberToken(java.lang.String _real,
                         java.lang.String _imaginary)
Constructor taking the numbers value as a string

Parameters:
_real - = the numbers real value as a string
_imaginary - = the numbers imaginary value as a string

SparseNumberToken

public SparseNumberToken(double _real,
                         double _imaginary)
Constructor taking the numbers value as a pair of double values representing real and imaginary part

Parameters:
_real - = the numbers real value as a double
_imaginary - = the numbers imaginary value as a double

SparseNumberToken

public SparseNumberToken(double[] _values)
Constructor taking the numbers value as a pair of double values representing real and imaginary part

Parameters:
_values - = the values as a array containing the real and imaginary values

SparseNumberToken

public SparseNumberToken(double[][] _real,
                         double[][] _imaginary)
Constructor taking the numbers value as two double[][]

Parameters:
_real - = the numbers value as a 2D array of double
_imaginary - = the numbers value as a 2D array of double

SparseNumberToken

public SparseNumberToken(double[][][] _values)
Constructor taking the numbers value as a double[][][]

Parameters:
_values - = the numbers value as a 3D array of double
Method Detail

getElementSized

public DataToken getElementSized(int y,
                                 int x)
return a new Number Token of size y*x

Overrides:
getElementSized in class DataToken

setSize

public void setSize(int dy,
                    int dx)
increase/decrease the size of the current DoubleNumberToken to size y*x

Overrides:
setSize in class DataToken
Parameters:
dy - number of rows
dx - number of columns

getValue

public double getValue()
Returns:
the real value of the first number

getValueRe

public double getValueRe(int y,
                         int x)
Returns:
the real value of the number at position y, x

getIntValue

public int getIntValue(int y,
                       int x)
Returns:
the real value of the number at position y, x as an integer

getValueIm

public double getValueIm()
Returns:
the imaginary value of the first number

getValueIm

public double getValueIm(int y,
                         int x)
Returns:
the imaginary value of the number at position y, x

getValueAbs

public double getValueAbs(int y,
                          int x)
Returns:
the absolute value of the number at position y, x

getValueArg

public double getValueArg(int y,
                          int x)
Returns:
the angle of the number at position y, x in radians

getValuesSSSSS

public double[][] getValuesSSSSS()
Returns:
the value of the number (old notation)

getReValues

public double[][] getReValues()
Returns:
the real values of the number

getImValues

public double[][] getImValues()
Returns:
the imaginary values of the number

getValuesImg

public double[][] getValuesImg()
Returns:
the imaginary value of the number

setElement

public void setElement(int y,
                       int x,
                       OperandToken num)
Overrides:
setElement in class DataToken

setElement

public void setElement(int n,
                       OperandToken num)
Overrides:
setElement in class DataToken

getValueComplex

public double[] getValueComplex(int y,
                                int x)
Parameters:
y - = y position in matrix
x - = x position in matrix
Returns:
an array of double representing the element at y,x

setValueComplex

public void setValueComplex(int y,
                            int x,
                            double[] _value)
Set value at position y, x

Parameters:
y - = y position in matrix
x - = x position in matrix
_value - = the value to set it to as an array of doubles
imag - = imaginary value

setValue

public void setValue(int y,
                     int x,
                     double _real,
                     double _imag)
Set value at position y, x

Parameters:
y - = y position in matrix
x - = x position in matrix
real - = real value
imag - = imaginary value

toString

public java.lang.String toString()
return the number as a string

Specified by:
toString in class Token
Returns:
a string representation of the token

toString

public java.lang.String toString(double[] _values)
create string representation of (complex) double values

Parameters:
_values[]={REAL,IMAGINARY} - real and imaginary part of number

evaluate

public OperandToken evaluate(Token[] operands)
Evaluate the token. This causes it to return itself

Specified by:
evaluate in class Token
Parameters:
operands - = an array of RootObject containing the tokens operands
Returns:
the result of the token evaluation as a RootObject

equals

public boolean equals(java.lang.Object arg)
Check if two tokens are equal

Overrides:
equals in class java.lang.Object
Parameters:
arg - = the object to check against

arg

public double arg(int y,
                  int x)
calculate the arg of the complex number at y, x


add

public OperandToken add(OperandToken arg)
add arg to this object for a number token

Overrides:
add in class OperandToken
Parameters:
= - the value to add to it
Returns:
the result as an OperandToken

subtract

public OperandToken subtract(OperandToken arg)
subtract arg from this object for a number token

Overrides:
subtract in class OperandToken
Parameters:
= - the value to subtract
Returns:
the result as an OperandToken

power

public OperandToken power(OperandToken arg)
Raise this object to the power of arg

Overrides:
power in class OperandToken
Parameters:
= - the value to raise it to the power of
Returns:
the result as an OperandToken

multiply

public OperandToken multiply(OperandToken arg)
multiply arg by this object for a number token

Overrides:
multiply in class OperandToken
Parameters:
arg - = the value to multiply it by
Returns:
the result as an OperandToken

multiply

public double[] multiply(double[] arg1,
                         double[] arg2)
Multiplies two complex numbers

Parameters:
arg1 - = the first complex number as an array of double
arg2 - = the second complex number as an array of double
Returns:
the result as an array of double

divide

public OperandToken divide(OperandToken arg)
divide this object by arg for a number token

Overrides:
divide in class OperandToken
Parameters:
arg - = the value to divide it by
Returns:
the result as an OperandToken

divide

public double[] divide(double[] arg1,
                       double[] arg2)
divide two complex numbers and return a complex number again, pay special attention to infinity and not a number

Parameters:
arg1 - = the first complex number as an array of double
arg2 - = the second complex number as an array of double
Returns:
the result as an array of double

scalarMultiply

public OperandToken scalarMultiply(OperandToken arg)
scalar multiply arg by this object for a number token

Overrides:
scalarMultiply in class OperandToken
Parameters:
arg - = the amount to multiply it by
Returns:
the result as an OperandToken

scalarDivide

public OperandToken scalarDivide(OperandToken arg)
scalar divide arg by this object for a number token

Overrides:
scalarDivide in class OperandToken
Parameters:
arg - = the amount to divide it by
Returns:
the result as an OperandToken

leftDivide

public OperandToken leftDivide(OperandToken arg)
left divide

Overrides:
leftDivide in class OperandToken
Returns:
the result as an OperandToken

scalarLeftDivide

public OperandToken scalarLeftDivide(OperandToken arg)
scalar left divide

Overrides:
scalarLeftDivide in class OperandToken
Returns:
the result as an OperandToken

transpose

public OperandToken transpose()
calculate the transpose of a matrix

Overrides:
transpose in class OperandToken
Returns:
the result as an OperandToken

ctranspose

public OperandToken ctranspose()
calculate the conjugate transpose of a matrix

Overrides:
ctranspose in class OperandToken
Returns:
the result as an OperandToken

sin

public OperandToken sin()
trigonometric functions - calculate the sine of this token

Returns:
the result as an OperandToken

sin

public double[] sin(double[] arg)
Calculates the sine of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

cos

public OperandToken cos()
trigonometric functions - calculate the cosine of this token

Returns:
the result as an OperandToken

cos

public double[] cos(double[] arg)
Calculates the cosine of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

tan

public OperandToken tan()
trigonometric functions - calculate the tangent of this token

Returns:
the result as an OperandToken

tan

public double[] tan(double[] arg)
Calculates the tangent of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

asin

public OperandToken asin()
trigonometric functions - calculate the arc sine of this token

Returns:
the result as an OperandToken

asin

public double[] asin(double[] arg)
Calculates the arcsine of a complex number

Parameters:
arg - = the value as an array of double
Returns:
the result as an array of double

acos

public OperandToken acos()
trigonometric functions - calculate the arc cosine of this token

Returns:
the result as an OperandToken

acos

public double[] acos(double[] arg)
Calculates the arccosine of a complex number

Parameters:
arg - = the value as an array of double
Returns:
the result as an array of double

atan

public OperandToken atan()
trigonometric functions - calculate the arc tangent of this token

Returns:
the result as an OperandToken

atan

public double[] atan(double[] arg)
Calculates the arctangent of a complex number

Parameters:
arg - = the value as an array of double
Returns:
the result as an array of double

sinh

public OperandToken sinh()
Trigonometric function - calculates the hyperbolic sine

Returns:
the result as an OperandToken

sinh

public double[] sinh(double[] arg)
Calculates the hyperbolic sine of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

cosh

public OperandToken cosh()
Trigonometric function - calculates the hyperbolic cosine

Returns:
the result as an OperandToken

cosh

public double[] cosh(double[] arg)
Calculates the hyperbolic cosine of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

tanh

public OperandToken tanh()
Trigonometric function - calculates the hyperbolic tan

Returns:
the result as an OperandToken

tanh

public double[] tanh(double[] arg)
Calculates the hyperbolic tangent of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

asinh

public OperandToken asinh()
Trigonometric function - calculates the inverse hyperbolic sine

Returns:
the result as an OperandToken

asinh

public double[] asinh(double[] arg)
Calculates the inverse hyperbolic sine of a complex number

Parameters:
arg - = the value as an array of double
Returns:
the result as an array of double

acosh

public OperandToken acosh()
Trigonometric function - calculates the inverse hyperbolic cosine

Returns:
the result as an OperandToken

acosh

public double[] acosh(double[] arg)
Calculates the inverse hyperbolic cosine of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

atanh

public OperandToken atanh()
Trigonometric function - calculates the inverse hyperbolic tangent

Returns:
the result as an OperandToken

atanh

public double[] atanh(double[] arg)
Calculates the inverse hyperbolic tangent of a complex number

Parameters:
arg - = the angle as an array of double
Returns:
the result as an array of double

exp

public OperandToken exp()
Standard functions - calculates the exponent

Returns:
the result as an OperandToken

exp

public double[] exp(double[] arg)
Calculates the exponent of a complex number

Parameters:
arg - = the value as an array of double
Returns:
the result as an array of double

ln

public OperandToken ln()
Standard functions - calculates the natural logarythm

Returns:
the result as an OperandToken

log

public OperandToken log()
Standard functions - calculates the logarythm

Returns:
the result as an OperandToken

log

public double[] log(double[] arg)
Calculates the logarythm of a complex number

Parameters:
arg - = the value as an array of double
Returns:
the result as an array of double

sqrt

public OperandToken sqrt()
Standard functions - calculates the square root

Returns:
the result as an OperandToken

sqrt

public double[] sqrt(double[] arg)
Calculates the sqrt of a complex number

Parameters:
arg - = the value as an array of double
Returns:
the result as an array of double

abs

public OperandToken abs()
Standard functions - absolute value

Returns:
the result as an OperandToken

floor

public OperandToken floor()
Standard functions - rounds the value down

Returns:
the result as an OperandToken

ceil

public OperandToken ceil()
Standard functions - rounds the value up

Returns:
the result as an OperandToken

round

public OperandToken round()
Standard functions - rounds the value to the nearest integer

Returns:
the result as an OperandToken

negate

public OperandToken negate()
standard function - returns the negative of the number

Overrides:
negate in class OperandToken
Returns:
the result as an OperandToken

min

public OperandToken min(RootObject arg)
Standard functions - calculates the minimum of two values

Returns:
the result as an OperandToken

max

public OperandToken max(RootObject arg)
Standard functions - calculates the maximum of two values

Returns:
the result as an OperandToken

factorial

public OperandToken factorial()
Standard functions - calculates the factorial of the number

Overrides:
factorial in class OperandToken
Returns:
the result as an OperandToken

factorial

public double factorial(double amount)
Calulates the factorial of a real value

Parameters:
amount - = the number to calc the factorial of
Returns:
the result as a double

conjugate

public OperandToken conjugate()
Complex function - calculates the complex conjugate of the number


isNull

public boolean isNull()
Checks if this operand is zero

Overrides:
isNull in class OperandToken
Returns:
true if this number == 0 or that all values are 0 for a matrix

isNumeric

public boolean isNumeric()
Checks if this operand is a numeric value

Overrides:
isNumeric in class OperandToken
Returns:
true if this is a number, false if it's an algebraic expression

isScalar

public boolean isScalar()
Returns:
true if this number token is a scalar (1*1 matrix)

isReal

public boolean isReal()
Returns:
true if this number token is a real matrix, without an imaginary part

isInteger

public boolean isInteger()
Returns:
true if this number token is an integral matrix, without an imaginary part

isImaginary

public boolean isImaginary()
Returns:
true if this number token is an imaginary matrix, without a real part

isComplex

public boolean isComplex()
Returns:
true if this number token is a complex matrix with both real and imaginary parts

degreesToRadians

public OperandToken degreesToRadians()

radiansToDegrees

public OperandToken radiansToDegrees()