|
Orbital library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ValueFactory
Scalar value and arithmetic object value constructor factory.
This class is the central factory facade for instantiating new arithmetic objects. It also provides "pluggable value factory implementation" that allow other vendor's implementation of arithmetic objects to be used.
Since our general arithmetic objects are modelled as interfaces to provide a maximum of
flexibility, you need factory methods to create an arithmetic object value. The class
ValueFactory is that central factory class which can
create arithmetic object values from all kinds of primitive types.
This indirection introduces a more loosely coupled binding between users and providers
of arithmetic object classes.
When using a static final singleton factory like from Values.getDefault()
,
closed-world JIT compilers can optimize the resulting code to prevent performance loss.
Indeed, because of this delegative construction the
factory method can chose the best implementation class suitable for a specific primitive type
and size.
Values
,
Values.getInstance()
,
Values.getDefault()
,
Arrays
Method Summary | |
---|---|
Polynomial |
asPolynomial(Tensor coefficients)
Returns a polynomial view of a tensor. |
UnivariatePolynomial |
asPolynomial(Vector a)
Returns a polynomial view of a vector. |
Tensor |
asTensor(Polynomial p)
Returns a vector view of the coefficients of a polynomial. |
Vector |
asVector(Matrix m)
Returns a vector view of the specified matrix. |
Vector |
asVector(Tensor t)
Returns a vector view of the specified tensor. |
Vector |
asVector(UnivariatePolynomial p)
Returns a vector view of the coefficients of a polynomial. |
Vector |
BASE(int n,
int i)
Gets a vector ei of an ONB of Rn. |
Complex |
cartesian(double a,
double b)
|
Complex |
cartesian(Real a,
Real b)
Creates a new complex from cartesian coordinates. |
Complex |
complex(double a)
|
Complex |
complex(double a,
double b)
|
Complex |
complex(float a,
float b)
|
Complex |
complex(int a,
int b)
|
Complex |
complex(long a,
long b)
|
Complex |
complex(Real a)
Returns a new (real) complex whose value is equal to a + i*0. |
Complex |
complex(Real a,
Real b)
Returns a new complex whose value is equal to a + i*b. |
Vector |
CONST(int n,
Arithmetic c)
Gets a constant Vector, with all elements set to c . |
Matrix |
constant(Matrix m)
Returns an unmodifiable view of the specified matrix. |
Polynomial |
constant(Polynomial p)
Returns an unmodifiable view of the specified polynomial. |
Tensor |
constant(Tensor t)
Returns an unmodifiable view of the specified tensor. |
UnivariatePolynomial |
constant(UnivariatePolynomial p)
Returns an unmodifiable view of the specified polynomial. |
Vector |
constant(Vector v)
Returns an unmodifiable view of the specified vector. |
Matrix |
DIAGONAL(Vector diagon)
Gets diagonal Matrix, with all elements set to 0, except the leading diagonal mi,i set to vi. |
Real |
E()
e = 2.71828... |
Fraction |
fraction(Arithmetic a)
Returns a new fraction a⁄1 ∈ S-1M = MS. |
Fraction |
fraction(Arithmetic a,
Arithmetic s)
Returns a new fraction a⁄s ∈ S-1M = MS. |
Function |
getCoercer()
Get the transformation function for coercing arithmetic objects. |
Function |
getCoercer(boolean commutative)
Get the transformation function for coercing arithmetic objects taking into account commutativity. |
Function |
getNormalizer()
Get the transformation function for normalizing arithmetic objects. |
Complex |
i()
The imaginary unit i∈C. |
Complex |
I()
The imaginary unit i∈C. |
Matrix |
IDENTITY(java.awt.Dimension dim)
Gets the identity Matrix, with all elements set to 0, except the leading diagonal mi,i set to 1. |
Matrix |
IDENTITY(int height,
int width)
Gets the identity Matrix, with all elements set to 0, except the leading diagonal mi,i set to 1. |
Complex |
INFINITY()
complex infinity ∞∈C. |
Integer |
MINUS_ONE()
-1∈Z. |
Polynomial |
MONOMIAL(Arithmetic exponent)
The monomial 1·Xi. |
Polynomial |
MONOMIAL(Arithmetic coefficient,
Arithmetic exponent)
The monomial c·Xi. |
UnivariatePolynomial |
MONOMIAL(Arithmetic coefficient,
int exponent)
The univariate monomial c·Xe. |
Polynomial |
MONOMIAL(Arithmetic coefficient,
int[] exponents)
The monomial c·X0i[0]...Xn-1i[n-1]. |
UnivariatePolynomial |
MONOMIAL(int exponent)
The univariate monomial 1·Xe. |
Polynomial |
MONOMIAL(int[] exponents)
The monomial 1·X0i[0]...Xn-1i[n-1]. |
Real |
NaN()
not a number ⊥∈R∪{⊥}. |
Scalar |
narrow(Scalar val)
Returns a minimized Scalar whose value is equal to that of the specified scalar. |
Real |
NEGATIVE_INFINITY()
-∞∈R. |
Matrix |
newInstance(java.awt.Dimension dimension)
Creates a new instance of matrix with the specified dimension. |
Vector |
newInstance(int dimension)
Creates a new instance of vector with the specified dimension. |
Tensor |
newInstance(int[] dimensions)
Creates a new instance of tensor with the specified dimensions. |
Matrix |
newInstance(int height,
int width)
|
Integer |
ONE()
1∈Z. |
Arithmetic |
parse(java.lang.String s)
Returns an arithmetic object whose value is equal to that of the representation in the specified string. |
Real |
PI()
π = 3.14159265... |
Complex |
polar(double r,
double phi)
|
Complex |
polar(Real r,
Real phi)
Creates a new complex from polar coordinates with r*eiφ. |
UnivariatePolynomial |
polynomial(Arithmetic[] coefficients)
Returns a (univariate) polynomial with the specified coefficients. |
UnivariatePolynomial |
polynomial(double[] coefficients)
|
UnivariatePolynomial |
polynomial(int[] coefficients)
|
Polynomial |
polynomial(java.util.Map exponentCoefficientMap)
Returns a polynomial with the specified (partial) coefficient map. |
Polynomial |
polynomial(java.lang.Object coefficients)
Returns a polynomial with the specified coefficients. |
Real |
POSITIVE_INFINITY()
+∞∈R. |
Quotient |
quotient(Arithmetic a,
Function mod)
Returns a new quotient ā=[a]∈M/mod of the given value reduced with the quotient operator. |
Quotient |
quotient(Arithmetic a,
Polynomial m)
(traps type unification error). |
Quotient |
quotient(Euclidean a,
Euclidean m)
Returns a new quotient ā=[a]∈M/(m) of the given value reduced modulo m. |
Quotient |
quotient(Euclidean a,
Function mod)
(disambiguates type unification). |
Quotient |
quotient(Euclidean a,
UnivariatePolynomial m)
(disambiguates type unification). |
Quotient |
quotient(int a,
int m)
(Convenience) Returns a new quotient ā=[a]∈M/(m) of the given value reduced modulo m. |
Quotient |
quotient(Polynomial a,
java.util.Set m,
java.util.Comparator monomialOrder)
Returns a new quotient ā=[a]∈M/(m) of the given value reduced modulo (m). |
Rational |
rational(int p)
|
Rational |
rational(Integer p)
Returns a new (integer) rational whose value is equal to p/1. |
Rational |
rational(Integer p,
Integer q)
Returns a new rational whose value is equal to p/q. |
Rational |
rational(int p,
int q)
|
void |
setCoercer(boolean commuatative,
Function coerce)
Set the transformation function for coercion. |
void |
setCoercer(Function coerce)
Set the transformation function for coercion. |
void |
setNormalizer(Function normalizer)
Set the transformation function for normalizing arithmetic objects. |
Symbol |
symbol(java.lang.String signifier)
Returns a new algebraic symbol. |
Vector |
tensor(Arithmetic[] values)
Returns a vector containing the specified arithmetic objects. |
Matrix |
tensor(Arithmetic[][] values)
Returns a matrix containing the specified arithmetic objects. |
Tensor |
tensor(Arithmetic[][][] values)
|
Tensor |
tensor(java.util.Map indexCoefficientMap)
Returns a tensor of rank k containing the specified (partial) map from index to arithmetic object. |
Tensor |
tensor(java.lang.Object values)
Returns a tensor of rank k containing the specified arithmetic objects. |
Vector |
valueOf(Arithmetic[] values)
Returns a Vector containing the specified arithmetic objects. |
Matrix |
valueOf(Arithmetic[][] values)
Returns a Matrix containing the specified arithmetic objects. |
Real |
valueOf(java.math.BigDecimal val)
Returns a scalar whose value is equal to that of the specified big number. |
Integer |
valueOf(java.math.BigInteger val)
Returns a scalar whose value is equal to that of the specified big number. |
Integer |
valueOf(byte val)
|
Integer |
valueOf(java.lang.Byte val)
|
Real |
valueOf(double val)
Returns a scalar whose value is equal to that of the specified primitive type. |
Real |
valueOf(java.lang.Double val)
|
Vector |
valueOf(double[] values)
|
Matrix |
valueOf(double[][] values)
|
Real |
valueOf(float val)
Returns a scalar whose value is equal to that of the specified primitive type. |
Real |
valueOf(java.lang.Float val)
|
Integer |
valueOf(int val)
Returns a scalar whose value is equal to that of the specified primitive type. |
Vector |
valueOf(int[] values)
|
Matrix |
valueOf(int[][] values)
|
Integer |
valueOf(java.lang.Integer val)
|
Integer |
valueOf(long val)
Returns a scalar whose value is equal to that of the specified primitive type. |
Integer |
valueOf(java.lang.Long val)
|
Scalar |
valueOf(java.lang.Number val)
Returns a Scalar whose value is equal to that of the specified number. |
Integer |
valueOf(short val)
|
Integer |
valueOf(java.lang.Short val)
|
Arithmetic |
valueOf(java.lang.String s)
Returns an arithmetic object whose value is equal to that of the representation in the specified string. |
Integer |
ZERO()
0∈Z. |
Matrix |
ZERO(java.awt.Dimension dim)
Gets zero Matrix, with all elements set to 0. |
Vector |
ZERO(int n)
Gets zero Vector, with all elements set to 0 . |
Tensor |
ZERO(int[] dimensions)
Gets zero tensor, with all elements set to 0. |
Matrix |
ZERO(int height,
int width)
|
Method Detail |
---|
Integer ZERO()
Integer ONE()
Integer MINUS_ONE()
Real POSITIVE_INFINITY()
INFINITY()
,
NEGATIVE_INFINITY()
Real NEGATIVE_INFINITY()
INFINITY()
,
POSITIVE_INFINITY()
Real PI()
Real E()
Real NaN()
Complex I()
i()
.
i()
Complex i()
I()
.
I()
Complex INFINITY()
INFINITY()
Integer valueOf(int val)
BigInteger.valueOf(long)
Integer valueOf(java.lang.Integer val)
Integer valueOf(long val)
BigInteger.valueOf(long)
Integer valueOf(java.lang.Long val)
Integer valueOf(byte val)
Integer valueOf(java.lang.Byte val)
Integer valueOf(short val)
Integer valueOf(java.lang.Short val)
Integer valueOf(java.math.BigInteger val)
Real valueOf(double val)
BigInteger.valueOf(long)
Real valueOf(java.lang.Double val)
Real valueOf(float val)
BigInteger.valueOf(long)
Real valueOf(java.lang.Float val)
Real valueOf(java.math.BigDecimal val)
Scalar valueOf(java.lang.Number val)
valueOf(double)
Rational rational(Integer p, Integer q)
p
- the numerator of p/q.q
- the denominator p/q.Rational rational(int p, int q)
Rational rational(Integer p)
p
- the numerator of p/1.Rational rational(int p)
Complex complex(Real a, Real b)
a
- real part.b
- imaginary part.
cartesian(Real, Real)
Complex complex(double a, double b)
Complex complex(float a, float b)
Complex complex(int a, int b)
Complex complex(long a, long b)
Complex complex(Real a)
a
- real part.
complex(Real, Real)
Complex complex(double a)
Complex cartesian(Real a, Real b)
a
- real part.b
- imaginary part.
polar(Real, Real)
Complex cartesian(double a, double b)
Complex polar(Real r, Real phi)
r
- = |z| is the length.phi
- = φ is the angle ∠ in radians.
cartesian(Real, Real)
Complex polar(double r, double phi)
Vector valueOf(Arithmetic[] values)
Note that the resulting vector may or may not be backed by the specified array.
tensor(Arithmetic[])
Vector valueOf(double[] values)
Vector valueOf(int[] values)
Vector newInstance(int dimension)
dimension
- the dimension of the vector.
Vector ZERO(int n)
0
.
Vector BASE(int n, int i)
0
except element i
set to 1
.
These ei are the standard base of Rn:
∀x∈Rn ∃! xk∈R: x = x1*e1 + ... + xn*en.
Vector CONST(int n, Arithmetic c)
c
.
Vector constant(Vector v)
Matrix valueOf(Arithmetic[][] values)
Matrix components are expected row-wise, which means that
as the first index in values
, the row i is used
and as the second index in values
, the column j is used.
Note that the resulting vector may or may not be backed by the specified array.
values
- the element values of the matrix to create.
The matrix may be backed by this exact array per reference.tensor(Arithmetic[][])
Matrix valueOf(double[][] values)
Matrix valueOf(int[][] values)
Matrix newInstance(java.awt.Dimension dimension)
dimension
- the dimension of the matrix.
Matrix newInstance(int height, int width)
Matrix ZERO(java.awt.Dimension dim)
Matrix ZERO(int height, int width)
Matrix IDENTITY(java.awt.Dimension dim)
Matrix IDENTITY(int height, int width)
Functions.delta
,
IDENTITY(Dimension)
Matrix DIAGONAL(Vector diagon)
Functions.delta
Matrix constant(Matrix m)
Vector tensor(Arithmetic[] values)
Note that the resulting vector may or may not be backed by the specified array.
Matrix tensor(Arithmetic[][] values)
Matrix components are expected row-wise, which means that
as the first index in values
, the row i is used
and as the second index in values
, the column j is used.
Note that the resulting vector may or may not be backed by the specified array.
values
- the element values of the matrix to create.
The matrix may be backed by this exact array per reference.Tensor tensor(Arithmetic[][][] values)
Tensor tensor(java.lang.Object values)
Note that the resulting tensor may or may not be backed by the specified array.
Tensors of type Vector
, and Matrix
are returned for tensors of rank 1 or 2.
values
- the element values of the tensor to create.
The tensor may be backed by this exact array per reference.arithmetic objects
or of primitive typesTensor tensor(java.util.Map indexCoefficientMap)
Note that the resulting tensor may or may not be backed by the specified array.
Tensors of type Vector
, and Matrix
are returned for tensors of rank 1 or 2.
indexCoefficientMap
- a map mapping index to element value.
Tensor newInstance(int[] dimensions)
Tensors of type Vector
, and Matrix
are returned for tensors of rank 1 or 2.
dimensions
- the dimensions n1×n2×…×nr
of the tensor.
Tensor ZERO(int[] dimensions)
Tensor constant(Tensor t)
The resulting tensor is a read-only view of this tensor. So, this method allows modules to provide users with "read-only" access to constant tensors.
Query operations on the returned tensor "read through" to the specified tensor,
and attempts to modify the returned tensor, whether direct or via its iterator,
result in an UnsupportedOperationException
.
Note that cloning a constant tensor will not return a constant tensor, but a clone of the specified tensor t.
Polynomial polynomial(java.lang.Object coefficients)
Note that the resulting polynomial may or may not be backed by the specified array.
Polynomials of type UnivariatePolynomial
, are returned for
polynomials in one variable.
coefficients
- a multi-dimensional array a containing the
coefficients of the polynomial.
arithmetic objects
or of primitive typesPolynomial polynomial(java.util.Map exponentCoefficientMap)
Note that the resulting polynomial may or may not be backed by the specified map.
Polynomials of type UnivariatePolynomial
, are returned for
polynomials in one variable.
exponentCoefficientMap
- a map mapping exponent to coefficient.
Polynomial asPolynomial(Tensor coefficients)
The returned polynomial is a view of the tensor. It interprets the components of the tensor as the coefficients of a polynomial.
coefficients
- a tensor a containing the
coefficients of the polynomial.
polynomial(Object)
,
asTensor(Polynomial)
Tensor asTensor(Polynomial p)
The returned tensor is a view of the polynomial. It interprets the coefficients of the polynomial as the components of a tensor.
java.lang.ClassCastException
- if p does not have S=Nn as indices,
and thus is not a multivariate polynomial in the proper sense.asPolynomial(Tensor)
Polynomial constant(Polynomial p)
Polynomial MONOMIAL(Arithmetic coefficient, Arithmetic exponent)
coefficient
- the coefficient c of the monomial.exponent
- the exponent i of the monomial.Polynomial MONOMIAL(Arithmetic coefficient, int[] exponents)
coefficient
- the coefficient c of the monomial.exponents
- the exponents i of the monomial.
The number of variables is n:=exponents.length
.Polynomial MONOMIAL(Arithmetic exponent)
1
∈Z.
exponent
- the exponent i of the monomial.MONOMIAL(Arithmetic,Arithmetic)
Polynomial MONOMIAL(int[] exponents)
1
∈Z.
exponents
- the exponents i of the monomial.
The number of variables is n:=exponents.length
.MONOMIAL(Arithmetic,int[])
UnivariatePolynomial MONOMIAL(Arithmetic coefficient, int exponent)
coefficient
- the coefficient c of the monomial.exponent
- the exponents e of the monomial.UnivariatePolynomial MONOMIAL(int exponent)
1
∈Z.
exponent
- the exponents e of the monomial.MONOMIAL(Arithmetic,int)
UnivariatePolynomial polynomial(Arithmetic[] coefficients)
Note that the resulting polynomial may or may not be backed by the specified array.
coefficients
- an array a containing the
coefficients of the polynomial.
asPolynomial(Vector)
,
Facade (method)UnivariatePolynomial polynomial(double[] coefficients)
polynomial(Arithmetic[])
,
polynomial(Object)
UnivariatePolynomial polynomial(int[] coefficients)
polynomial(Arithmetic[])
,
polynomial(Object)
UnivariatePolynomial asPolynomial(Vector a)
The returned polynomial is a view of the vector. It interprets the components of the vector as the coefficients of a polynomial.
polynomial(Arithmetic[])
,
asVector(UnivariatePolynomial)
Vector asVector(UnivariatePolynomial p)
The returned vector is a view of the polynomial. It interprets the coefficients of the polynomial as the components of a vector.
UnivariatePolynomial.getCoefficients()
,
asPolynomial(Vector)
UnivariatePolynomial constant(UnivariatePolynomial p)
Quotient quotient(Arithmetic a, Function mod)
Note that unlike quotients of Euclidean rings
and due to the black-box behaviour of the quotient operator
these quotients do not guarantee an implementation of Arithmetic.inverse()
.
mod
- is the quotient operator applied (see Quotient.getQuotientOperator()
).Quotient quotient(Euclidean a, Euclidean m)
Will use special remainder classes
modulo m in Euclidean rings. These remainder classes are those
induced by the Euclidean remainder
operator. Quotients of Euclidean rings have the big
advantage of supporting a simple calculation of multiplicative
inverses modulo m.
Quotient quotient(Polynomial a, java.util.Set m, java.util.Comparator monomialOrder)
Will use special remainder classes modulo (m) for a Groebner
basis m of (multivariate) polynomial rings. These remainder
classes are those induced by the
reduction
operator.
m
- the Groebner basis
modulo whose generated ideal (m) to form the quotients.monomialOrder
- the monomial order applied for reducing polynomials.Quotient quotient(Euclidean a, UnivariatePolynomial m)
Being identical to quotient(Euclidean,Euclidean)
,
this method only helps resolving the argument type ambiguity
for polynomials. This type ambiguity will not occur at all, if
templates have been enabled.
quotient(Euclidean,Euclidean)
Quotient quotient(Euclidean a, Function mod)
Being identical to quotient(Arithmetic,Function)
,
this method only helps resolving the argument type ambiguity
for polynomials. This type ambiguity will not occur at all, if
templates have been enabled.
a
- the valuemod
- is the quotient operator applied (see Quotient.getQuotientOperator()
).quotient(Arithmetic,Function)
Quotient quotient(Arithmetic a, Polynomial m)
This method only helps resolving the argument type ambiguity
for polynomials. This type ambiguity will not occur at all, if
templates have been enabled.
Even though Polynomialsa
. Therefore it (usually)
is not a quotient operator as expected by quotient(Arithmetic,Function)
.
However, if you have disabled templates, then your compiler will not be able
to detect the type unification error occurring in the generic arguments.
java.lang.ClassCastException
- if a and m are not both instances of Euclidean.quotient(Arithmetic,Function)
Quotient quotient(int a, int m)
This is only a convenience constructor for a special case of M=Z, M/(m)=Z/mZ. Although this case appears rather often, it is by far not the only case of quotients, of course.
quotient(Euclidean,Euclidean)
Fraction fraction(Arithmetic a, Arithmetic s)
Note that this implementation does not check whether denominators are in the
submonoid S, but only check for them to have the right type S. Since if S really is a
monoid, it would suffice to check this at the instantiation, here.
However, additionally this implementation does not check the prerequisite of Arithmetic.inverse()
to have a numerator in the submonoid S, but only check for its type, again.
The only alternative would require users to provide predicates checking for containement in the submonoid S, all the time.
Also note that due to computational aspects, we generally assume the underlying ring to be an integrity domain for equality checking, of course.
Fraction fraction(Arithmetic a)
Symbol symbol(java.lang.String signifier)
Arithmetic parse(java.lang.String s) throws java.lang.NumberFormatException
s
- the string to be parsed.
java.lang.NumberFormatException
- if the string does not contain a parsable arithmetic object.valueOf(String)
Arithmetic valueOf(java.lang.String s) throws java.lang.NumberFormatException
s
- the string to be parsed.
java.lang.NumberFormatException
- if the string does not contain a parsable arithmetic object.parse(String)
Vector asVector(Matrix m)
asVector(Tensor)
Vector asVector(Tensor t)
The tensor is interpreted row-wise as a vector.
Scalar narrow(Scalar val)
Function getCoercer()
infimum type
(the most restrictive one).
So whenever possible an integer will be preferred over a rational,
a rational over a real and that over a complex.
That is they are instances of the common superclass.
This transformation function is often used to implement sly arithmetic operations with
full dynamic dispatch by Operations
.
RuntimeException
will be thrown.Operations
,
setCoercer(orbital.logic.functor.Function)
Function getCoercer(boolean commutative)
getCoercer()
,
except that when commutative=true
, the arithmetic objects
passed to it can be swapped to get compatible objects.
commutative
- whether the returned transformation is allowed to
commute (swap) its arguments provided that this is correct for the given types.getCoercer()
void setCoercer(Function coerce) throws java.lang.SecurityException
The transformation function set here must fulfill the same criteria that the default one
does as described in the getCoercer()
method. To simply hook an additional
transformation, implement your transformation function on top of the one got from
getCoercer()
.
java.lang.SecurityException
getCoercer()
void setCoercer(boolean commuatative, Function coerce) throws java.lang.SecurityException
The transformation function set here must fulfill the same criteria that the default one
does as described in the getCoercer()
method. To simply hook an additional
transformation, implement your transformation function on top of the one got from
getCoercer()
.
commutative
- whether the given coercer will be allowed to
commute (swap) its arguments provided that this is correct for the given types.
java.lang.SecurityException
getCoercer(boolean)
Function getNormalizer()
setNormalizer(orbital.logic.functor.Function)
void setNormalizer(Function normalizer) throws java.lang.SecurityException
The transformation function set here must fulfill the same criteria that the default one
does as described in the getNormalizer()
method. To simply hook an additional
transformation, implement your transformation function on top of the one got from
getNormalizer()
.
java.lang.SecurityException
getNormalizer()
|
Orbital library 1.3.0: 11 Apr 2009 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |