public abstract class Function<X,Y> extends java.lang.Object implements java.io.Serializable, javolution.lang.Realtime
This abstract class represents a mapping between two sets such that there is a unique element in the second set assigned to each element in the first set.
Functions can be discrete or continuous and multivariate functions
(functions with multiple variables) are also supported as illustrated
below:[code]
// Defines local variables.
Variable.Local
Functions are often given by formula (e.g. f(x) = x²-x+1,
f(x,y)= x·y
) but the general function instance might tabulate
the values, solve an equation, etc.
Modifier and Type | Method and Description |
---|---|
<Z> Function<Z,Y> |
compose(Function<Z,X> that)
Returns the composition of this function with the one specified.
|
Function<X,Y> |
differentiate(Variable<X> v)
Returns the first derivative of this function with respect to
the specified variable.
|
Function<X,Y> |
divide(Function<X,Y> that)
Returns the quotient of this function with the one specified.
|
boolean |
equals(java.lang.Object obj)
Indicates if this function is equals to the specified object.
|
abstract Y |
evaluate()
Evaluates this function using its
variables current
values. |
Y |
evaluate(X... args)
Evaluates this function for the specified arguments values
(convenience method).
|
Y |
evaluate(X arg)
Evaluates this function for the specified argument value
(convenience method).
|
Variable<X> |
getVariable(java.lang.String symbol)
Retrieves the variable from this function having the specified
symbol (convenience method).
|
abstract java.util.List<Variable<X>> |
getVariables()
Returns a lexically ordered list of the variables (or arguments)
for this function (empty list for constant functions).
|
int |
hashCode()
Returns the hash code for this function (consistent with
equals(Object) . |
Function<X,Y> |
integrate(Variable<X> v)
Returns an integral of this function with respect to
the specified variable.
|
Function<X,Y> |
minus(Function<X,Y> that)
Returns the difference of this function with the one specified.
|
Function<X,Y> |
plus(Function<X,Y> that)
Returns the sum of this function with the one specified.
|
Function<X,Y> |
pow(int n)
Returns this function raised at the specified exponent.
|
Function<X,Y> |
times(Function<X,Y> that)
Returns the product of this function with the one specified.
|
java.lang.String |
toString()
Returns the text representation of this function as a
java.lang.String . |
abstract javolution.text.Text |
toText()
Returns the textual representation of this real-time object
(equivalent to
toString except that the returned value
can be allocated from the local context space). |
public abstract java.util.List<Variable<X>> getVariables()
public abstract Y evaluate()
variables
current
values.FunctionException
- if any of this function's variable is not set.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object to be compared with.true
if this function and the specified argument
represent the same function; false
otherwise.public int hashCode()
equals(Object)
.hashCode
in class java.lang.Object
public final Variable<X> getVariable(java.lang.String symbol)
null
if none.public final Y evaluate(X arg)
LocalContext
and
can safely be called upon functions with global
variables
.arg
- the single variable value used for the evaluation.FunctionException
- if getVariables().size() != 1
public final Y evaluate(X... args)
LocalContext
and
can safely be called upon functions with global
variables
.args
- the variables values used for the evaluation.java.lang.IllegalArgumentException
- if args.length != getVariables().size())
public <Z> Function<Z,Y> compose(Function<Z,X> that)
that
- the function for which the return value is passed as
argument to this function.(this o that)
FunctionException
- if this function is not monovariate.public Function<X,Y> differentiate(Variable<X> v)
v
- the variable for which the derivative is calculated.d[this]/dv
FunctionException
- if the derivative is undefined.public Function<X,Y> integrate(Variable<X> v)
v
- the variable for which the integral is calculated.S[this·dv]
public Function<X,Y> plus(Function<X,Y> that)
that
- the function to be added.this + that
.public Function<X,Y> minus(Function<X,Y> that)
that
- the function to be subtracted.this - that
.public Function<X,Y> times(Function<X,Y> that)
that
- the function multiplier.this · that
.public Function<X,Y> divide(Function<X,Y> that)
that
- the function divisor.this / that
.public Function<X,Y> pow(int n)
n
- the exponent.thisn
java.lang.IllegalArgumentException
- if n <= 0
public abstract javolution.text.Text toText()
toString
except that the returned value
can be allocated from the local context space).toText
in interface javolution.lang.Realtime
public final java.lang.String toString()
java.lang.String
.toString
in class java.lang.Object
toText().toString()