Orbital library

orbital.math.functional
Interface Operations


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:

a.equals(b) if and only if a == b

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.

Author:
André Platzer
See Also:
Arithmetic, Comparable, Functor, Functionals.compose(Function, Function), Functionals.genericCompose(BinaryFunction, Object, Object), Functionals.Catamorphism
Structure:
depends 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

plus

static final BinaryFunction plus
plus +: A×A→A; (x,y) ↦ x+y.

derive plus' = (1, 1)
integrate: ∫x0+x1 dxi = xi2/2 + x0*x1

See Also:
Arithmetic.add(Arithmetic)
Attributes:
associative, neutral, inverses, commutative

sum

static final Function sum
sum ∑: An→A; (xi) ↦ ∑i xi = (|0,+|) (xi).

derive sum' = (1)n∈N
integrate: ?

Treats its argument as a list like Functionals.Catamorphism.

See Also:
Functionals.Catamorphism, ValueFactory.ZERO(), plus

minus

static final Function minus
minus −: A→A; x ↦ −x.

derive minus' = −1
integrate: ∫−x dx = −x2/2

See Also:
Arithmetic.minus()

subtract

static final BinaryFunction subtract
subtract -: A×A→A; (x,y) ↦ x-y.

derive subtract' = (1, -1)
integrate: ∫x0-x1 dx0 = x02/2 - x0*x1
integrate: ∫x0-x1 dx1 = x0*x1 - x12/2

See Also:
Arithmetic.subtract(Arithmetic)

times

static final BinaryFunction times
times ⋅: A×A→A; (x,y) ↦ x⋅y.

derive times' = (y, x)
integrate: ∫x0⋅x1 dx0 = x02⋅x1 / 2
integrate: ∫x0⋅x1 dx1 = x0⋅x12 / 2

See Also:
Arithmetic.multiply(Arithmetic), Arithmetic.scale(Arithmetic)
Attributes:
associative, neutral, commutative, distributive #plus

product

static final Function product
product ∏: An→A; (xi) ↦ ∏i xi = (|1,⋅|) (xi).

derive product' = ?
integrate: ?

Treats its argument as a list like Functionals.Catamorphism.

See Also:
Functionals.Catamorphism, ValueFactory.ONE(), times

inverse

static final Function inverse
inverse -1: A→A; x ↦ x-1.

derive inverse' = -1/x2
integrate: ∫x-1 dx1 = ㏒ x

See Also:
Arithmetic.inverse()

divide

static final BinaryFunction divide
divide ∕: A×A→A; (x,y) ↦ x∕y.

derive divide' = (1∕y, -x∕y2)
integrate: ∫x0∕x1 dx0 = x02∕(2*x1)
integrate: ∫x0∕x1 dx1 = x0·㏒(x1)

See Also:
Arithmetic.divide(Arithmetic)

power

static final BinaryFunction power
power ^: A×A→A; (x,y) ↦ xy.

power' = (y⋅xy-1, ㏒(x)⋅xy)
integrate: ∫x0x1 dx0 = x0x1+1 / (x1+1)
integrate: ∫x0x1 dx1 = x0x1 / ㏒(x0)

See Also:
Arithmetic.power(Arithmetic)

min

static final BinaryFunction min
min: A×A→A; (x,y) ↦ min {x,y} = ⊓{x,y}.

See Also:
Comparable.compareTo(Object)
Attributes:
associative, commutative, idempotent, distributive #max

inf

static final Function inf
inf ⊓: An→A; (xi) ↦ ⊓i {xi} = (|∞,min|) (xi).

Let (A,≤) be an ordered set.
lower bound
b∈A is a lower bound of M⊆A :⇔ ∀x∈M b≤x
infimum
inf M = s∈A is the infimum of M⊆A :⇔ s is a lower bound of M ∧ ∀b∈A (b lower bound of M ⇒ b≤s)

Treats its argument as a list like Functionals.Catamorphism.

See Also:
Functionals.Catamorphism, min

max

static final BinaryFunction max
max: A×A→A; (x,y) ↦ max {x,y} = ⊔{x,y}.

See Also:
Comparable.compareTo(Object)
Attributes:
associative, commutative, idempotent, distributive #min

sup

static final Function sup
sup ⊔: An→A; (xi) ↦ ⊔i {xi} = (|-∞,max|) (xi).

Let (A,≤) be an ordered set.
upper bound
b∈A is an upper bound of M⊆A :⇔ ∀x∈M x≤b
supremum
sup M = s∈A is the supremum of M⊆A :⇔ s is an upper bound of M ∧ ∀b∈A (b upper bound of M ⇒ s≤b)

Treats its argument as a list like Functionals.Catamorphism.

See Also:
Functionals.Catamorphism, max

equal

static final BinaryPredicate equal
=. In first-order logic, equality "=" is uniquely determined by

Attributes:
equivalent, congruent for all f, P, substitutive

unequal

static final BinaryPredicate unequal
≠.

Inequality is defined as x≠y :⇔ ¬(x=y).

See Also:
equal
Attributes:
irreflexive, symmetric

compare

static final BinaryFunction compare
Compares two arithmetic numbers.

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.

See Also:
Comparable
Attributes:
strict order

less

static final BinaryPredicate less
<.

It is true that x<y ⇔ x≤y ∧ x≠y.

See Also:
Comparable
Attributes:
strict order

greater

static final BinaryPredicate greater
>.

It is defined as x>y :⇔ y<x.

See Also:
Comparable
Attributes:
strict order

lessEqual

static final BinaryPredicate lessEqual
≤.

It is true that x≤y ⇔ x<y ∨ x<y.

See Also:
Comparable
Attributes:
order

greaterEqual

static final BinaryPredicate greaterEqual
≥.

It is defined as x≥y :⇔ y≤x.

See Also:
Comparable
Attributes:
order

operations

static final Operations operations
Class alias object.

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

Copyright © 1996-2009 André Platzer
All Rights Reserved.