|
Orbital library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Operations
Provides central arithmetic operations for algebraic types.
Operations contains BinaryFunction abstractions of
mathematical operations like + - ⋅ / ^
etc.
For Arithmetic objects, the corresponding elemental function in orbital.math.Arithmetic is called,
for functions the operations are defined pointwise.
So these Operations can be applied to arithmetic objects as well as functions in the same manner!
All function objects in this class provide canonical equality:
Operation functions are very useful to implement sly arithmetic operations with full dynamic dispatch. They are then performed with the correct type concerning all argument types, automatically. Simply use an idiom like
public Arithmetic add(Arithmetic b) { // base case: "add" for two instances of ThisClass if (b instanceof ThisClass) return new ThisClass(value() + ((ThisClass) b).value()); // dynamic dispatch with regard to dynamic types of all arguments // for sly defer to "add" of most restrictive type return (Arithmetic) Operations.plus.apply(this, b); }Which implicitly uses the tranformation function
ValueFactory.getCoercer()
.
The static functions provided in Operations delegate type handling like in
Arithmetic operands[] = (Arithmetic[]) Values.getDefaultInstance().getCoercer().apply(new Arithmetic[] {x, y}); return operands[0].add(operands[1]);
In addition, Operations contains arithmetized versions of the comparison predicates
of Predicates
.
The essential difference is that the implementations in Operations
respect coercing, type compatibility, and precision.
Arithmetic
,
Comparable
,
Functor
,
Functionals.compose(Function, Function)
,
Functionals.genericCompose(BinaryFunction, Object, Object)
,
Functionals.Catamorphism
ValueFactory.getCoercer()
Field Summary | |
---|---|
static BinaryFunction |
compare
Compares two arithmetic numbers. |
static BinaryFunction |
divide
divide ∕: A×A→A; (x,y) ↦ x∕y. |
static BinaryPredicate |
equal
=. |
static BinaryPredicate |
greater
>. |
static BinaryPredicate |
greaterEqual
≥. |
static Function |
inf
inf ⊓: An→A; (xi) ↦ ⊓i {xi} = (|∞,min|) (xi). |
static Function |
inverse
inverse -1: A→A; x ↦ x-1. |
static BinaryPredicate |
less
<. |
static BinaryPredicate |
lessEqual
≤. |
static BinaryFunction |
max
max: A×A→A; (x,y) ↦ max {x,y} = ⊔{x,y}. |
static BinaryFunction |
min
min: A×A→A; (x,y) ↦ min {x,y} = ⊓{x,y}. |
static Function |
minus
minus −: A→A; x ↦ −x. |
static Operations |
operations
Class alias object. |
static BinaryFunction |
plus
plus +: A×A→A; (x,y) ↦ x+y. |
static BinaryFunction |
power
power ^: A×A→A; (x,y) ↦ xy. |
static Function |
product
product ∏: An→A; (xi) ↦ ∏i xi = (|1,⋅|) (xi). |
static BinaryFunction |
subtract
subtract -: A×A→A; (x,y) ↦ x-y. |
static Function |
sum
sum ∑: An→A; (xi) ↦ ∑i xi = (|0,+|) (xi). |
static Function |
sup
sup ⊔: An→A; (xi) ↦ ⊔i {xi} = (|-∞,max|) (xi). |
static BinaryFunction |
times
times ⋅: A×A→A; (x,y) ↦ x⋅y. |
static BinaryPredicate |
unequal
≠. |
Field Detail |
---|
static final BinaryFunction plus
derive plus' = (1, 1)
integrate: ∫x0+x1 dxi = xi2/2 + x0*x1
Arithmetic.add(Arithmetic)
static final Function sum
derive sum' = (1)n∈N
integrate: ?
Treats its argument as a list like Functionals.Catamorphism
.
Functionals.Catamorphism
,
ValueFactory.ZERO()
,
plus
static final Function minus
derive minus' = −1
integrate: ∫−x dx = −x2/2
Arithmetic.minus()
static final BinaryFunction subtract
derive subtract' = (1, -1)
integrate: ∫x0-x1 dx0 = x02/2 - x0*x1
integrate: ∫x0-x1 dx1 = x0*x1 - x12/2
Arithmetic.subtract(Arithmetic)
static final BinaryFunction times
derive times' = (y, x)
integrate: ∫x0⋅x1 dx0 = x02⋅x1 / 2
integrate: ∫x0⋅x1 dx1 = x0⋅x12 / 2
Arithmetic.multiply(Arithmetic)
,
Arithmetic.scale(Arithmetic)
static final Function product
derive product' = ?
integrate: ?
Treats its argument as a list like Functionals.Catamorphism
.
Functionals.Catamorphism
,
ValueFactory.ONE()
,
times
static final Function inverse
derive inverse' = -1/x2
integrate: ∫x-1 dx1 = ㏒ x
Arithmetic.inverse()
static final BinaryFunction divide
derive divide' = (1∕y, -x∕y2)
integrate: ∫x0∕x1 dx0 = x02∕(2*x1)
integrate: ∫x0∕x1 dx1 = x0·㏒(x1)
Arithmetic.divide(Arithmetic)
static final BinaryFunction power
power' = (y⋅xy-1, ㏒(x)⋅xy)
integrate: ∫x0x1 dx0 = x0x1+1 / (x1+1)
integrate: ∫x0x1 dx1 = x0x1 / ㏒(x0)
Arithmetic.power(Arithmetic)
static final BinaryFunction min
Comparable.compareTo(Object)
static final Function inf
Treats its argument as a list like Functionals.Catamorphism
.
Functionals.Catamorphism
,
min
static final BinaryFunction max
Comparable.compareTo(Object)
static final Function sup
Treats its argument as a list like Functionals.Catamorphism
.
Functionals.Catamorphism
,
max
static final BinaryPredicate equal
static final BinaryPredicate unequal
Inequality is defined as x≠y :⇔ ¬(x=y).
equal
static final BinaryFunction compare
Result will be <0 if x<y, and >0 if x>y and =0 if x=y. The result will be representable as an int.
Comparable
static final BinaryPredicate less
It is true that x<y ⇔ x≤y ∧ x≠y.
Comparable
static final BinaryPredicate greater
It is defined as x>y :⇔ y<x.
Comparable
static final BinaryPredicate lessEqual
It is true that x≤y ⇔ x<y ∨ x<y.
Comparable
static final BinaryPredicate greaterEqual
It is defined as x≥y :⇔ y≤x.
Comparable
static final Operations operations
To alias the methods in this class for longer terms, use an idiom like
// alias object Functions F = Functions.functions; Operations op = Operations.operations; // use alias Function f = (Function) op.times.apply(F.sin, op.plus.apply(F.square, F.cos)); // instead of the long form Function f = (Function) Operations.times.apply(Functions.sin, Operations.plus.apply(Functions.square, Functions.cos));
|
Orbital library 1.3.0: 11 Apr 2009 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |