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 inf: An->A; (xi) |-> infi {xi} = (| inf ,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} = sup{x,y}.
static BinaryFunction min
          min: A×A->A; (x,y) |-> min {x,y} = inf{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 sup: An->A; (xi) |-> supi {xi} = (|- inf ,max|) (xi).
static BinaryFunction times
          times : A×A->A; (x,y) |-> xy.
static BinaryPredicate unequal
          !=.
 

Field Detail

plus

static final BinaryFunction plus
plus +: A×A->A; (x,y) |-> x+y.

derive plus' = (1, 1)
integrate: integral 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 in 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: integral −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: integral x0-x1 dx0 = x02/2 - x0*x1
integrate: integral x0-x1 dx1 = x0*x1 - x12/2

See Also:
Arithmetic.subtract(Arithmetic)

times

static final BinaryFunction times
times : A×A->A; (x,y) |-> xy.

derive times' = (y, x)
integrate: integral x0x1 dx0 = x02x1 / 2
integrate: integral x0x1 dx1 = x0x12 / 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: integral x-1 dx1 = log 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: integral x0/x1 dx0 = x02/(2*x1)
integrate: integral x0/x1 dx1 = x0.log(x1)

See Also:
Arithmetic.divide(Arithmetic)

power

static final BinaryFunction power
power ^: A×A->A; (x,y) |-> xy.

power' = (yxy-1, log(x)xy)
integrate: integral x0x1 dx0 = x0x1+1 / (x1+1)
integrate: integral x0x1 dx1 = x0x1 / log(x0)

See Also:
Arithmetic.power(Arithmetic)

min

static final BinaryFunction min
min: A×A->A; (x,y) |-> min {x,y} = inf{x,y}.

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

inf

static final Function inf
inf inf: An->A; (xi) |-> infi {xi} = (| inf ,min|) (xi).

Let (A,=<) be an ordered set.
lower bound
b in A is a lower bound of M subset of A :<=> for all x in M b=<x
infimum
inf M = s in A is the infimum of M subset of A :<=> s is a lower bound of M and for all b in 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} = sup{x,y}.

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

sup

static final Function sup
sup sup: An->A; (xi) |-> supi {xi} = (|- inf ,max|) (xi).

Let (A,=<) be an ordered set.
upper bound
b in A is an upper bound of M subset of A :<=> for all x in M x=<b
supremum
sup M = s in A is the supremum of M subset of A :<=> s is an upper bound of M and for all b in 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 and 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 or 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.2.0: 23 Apr 2008

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