Orbital library

orbital.math.functional
Class Functionals

java.lang.Object
  extended by orbital.logic.functor.Functionals
      extended by orbital.math.functional.Functionals

public class Functionals
extends Functionals

Provides important compositional functionals for mathematical functions. For that, this module class contains several static methods that work like Functionals, i.e. high-order functions that have a Function in their signature.

The Functionals class comes in two versions:

Evolves: This class might under some circumstances be renamed or unified with the orbital.logic.functor.Functionals, which is not very likely to happen, since both classes address fairly different levels of composition.

Since:
Orbital1.0
Author:
André Platzer
See Also:
Functionals, Function, BinaryFunction, Collection, Iterator, Facade Pattern
Note:
compose methods cannot have a return-type of Function.Composite etc. since they optimize away compositions with 1 and 0.

Nested Class Summary
 
Nested classes/interfaces inherited from class orbital.logic.functor.Functionals
Functionals.Anamorphism, Functionals.Catamorphism, Functionals.Hylomorphism, Functionals.Paramorphism
 
Field Summary
static Functionals functionals
          Class alias object.
 
Fields inherited from class orbital.logic.functor.Functionals
apply, compose
 
Constructor Summary
protected Functionals()
          prevent instantiation - module class
 
Method Summary
static Function bind(BinaryFunction f)
          Binds both arguments of a BinaryFunction together.
static Function bindFirst(BinaryFunction f, java.lang.Object x)
          Binds the first argument of a BinaryFunction to a fixed value.
static Function bindSecond(BinaryFunction f, java.lang.Object y)
          Binds the second argument of a BinaryFunction to a fixed value.
static BinaryFunction compose(BinaryFunction f, BinaryFunction g, BinaryFunction h)
          compose: (f,g,h) ↦ f ∘ (g × h) := f(g,h) .
static Function compose(BinaryFunction f, Function g, Function h)
          compose: (f,g,h) ↦ f ∘ (g × h) := f(g,h) .
static Function compose(Function f, Function g)
          compose: (f,g) ↦ f ∘ g := f(g).
static double foldRight(BinaryFunction f, double c, double[] a)
           
static MathFunctor genericCompose(BinaryFunction f, java.lang.Object g, java.lang.Object h)
          generic compose calls the compose function appropriate for the type of g and h.
static MathFunctor genericCompose(Function f, java.lang.Object g)
          generic compose calls the compose function appropriate for the type of g.
static MathFunctor.Composite genericCompose(java.lang.Object f)
          generic compose uses component compose function appropriate for the type of g.
static double[] map(BinaryFunction f, double[] x, double[] y)
           
static float[] map(BinaryFunction f, float[] x, float[] y)
           
static int[] map(BinaryFunction f, int[] x, int[] y)
           
static long[] map(BinaryFunction f, long[] x, long[] y)
           
static Matrix map(BinaryFunction f, Matrix x, Matrix y)
           
static Tensor map(BinaryFunction f, Tensor x, Tensor y)
          Maps two lists of arguments with a binary function.
static Vector map(BinaryFunction f, Vector x, Vector y)
           
static double[] map(Function f, double[] a)
           
static float[] map(Function f, float[] a)
           
static int[] map(Function f, int[] a)
           
static long[] map(Function f, long[] a)
           
static Matrix map(Function f, Matrix a)
           
static Tensor map(Function f, Tensor a)
          Maps a list of arguments with a function.
static Vector map(Function f, Vector a)
           
static Function nest(Function f, int n)
          Nests a function n times within itself.
static Predicate not(Predicate p)
          Negates predicates
static BinaryFunction onFirst(Function f)
          Applies a function on the first argument, ignoring the second.
static BinaryFunction onSecond(Function f)
          Applies a function on the second argument, ignoring the first.
static BinaryFunction pointwise(BinaryFunction elemental)
          A BinaryFunction that performs an operation pointwise.
static Function pointwise(Function elemental)
          A function that performs an operation pointwise.
static BinaryFunction swap(BinaryFunction f)
          Swaps the two arguments of a BinaryFunction.
 
Methods inherited from class orbital.logic.functor.Functionals
asFunction, asFunction, asFunction, banana, barbedwire, barbedwire, bind, bind, bind, bindFirst, bindSecond, compose, compose, compose, compose, compose, compose, compose, cross, curry, envelope, fixedPoint, fixedPoint, foldLeft, foldLeft, foldLeft, foldRight, foldRight, foldRight, foldRight, genericCompose, lense, listable, listable, map, map, map, map, map, map, map, map, map, map, map, map, map, map, map, mapInto, mapInto, onFirst, onSecond, onVoid, onVoid, paramorphism, swap, uncurry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

functionals

public static final Functionals functionals
Class alias object.

Constructor Detail

Functionals

protected Functionals()
prevent instantiation - module class

Method Detail

compose

public static Function compose(Function f,
                               Function g)
compose: (f,g) ↦ f ∘ g := f(g).

Returns:
x↦f ∘ g (x) = f(g(x)).
See Also:
Facade Pattern, Function.Composite

compose

public static BinaryFunction compose(BinaryFunction f,
                                     BinaryFunction g,
                                     BinaryFunction h)
compose: (f,g,h) ↦ f ∘ (g × h) := f(g,h) .

Returns:
(x,y)↦f(g(x,y),h(x,y)).
See Also:
Facade Pattern, BinaryFunction.Composite

compose

public static Function compose(BinaryFunction f,
                               Function g,
                               Function h)
compose: (f,g,h) ↦ f ∘ (g × h) := f(g,h) .

Returns:
x↦f(g(x),h(x)).
See Also:
Facade Pattern, BinaryCompositeFunction

genericCompose

public static MathFunctor genericCompose(Function f,
                                         java.lang.Object g)
generic compose calls the compose function appropriate for the type of g.

Parameters:
g - having one of the types Function, Function[], Function[][], and Arithmetic. In the latter case, composition is done using a constant function.
See Also:
Facade Pattern

genericCompose

public static MathFunctor.Composite genericCompose(java.lang.Object f)
generic compose uses component compose function appropriate for the type of g.

Parameters:
f - an object having one of the types Function[], Function[][], BinaryFunction[], BinaryFunction[][].
See Also:
Facade Pattern

genericCompose

public static MathFunctor genericCompose(BinaryFunction f,
                                         java.lang.Object g,
                                         java.lang.Object h)
generic compose calls the compose function appropriate for the type of g and h.

Parameters:
g - having one of the types listed for h.
h - having one of the types Function, BinaryFunction and Arithmetic. In the latter case, composition is done using a constant function.
See Also:
Facade Pattern

bindFirst

public static Function bindFirst(BinaryFunction f,
                                 java.lang.Object x)
Binds the first argument of a BinaryFunction to a fixed value.

bindFirst: Map(A1×A2,B)→Map(A2,B); f↦f(x,·). The unary left-adjoint.

Returns:
f(x,·):A2→B; y ↦ f(y) := f(x, y)

bindSecond

public static Function bindSecond(BinaryFunction f,
                                  java.lang.Object y)
Binds the second argument of a BinaryFunction to a fixed value.

bindSecond: Map(A1×A2,B)→Map(A1,B); f↦f(·,y). The unary right-adjoint.

Returns:
f(·,y):A1→B; x ↦ f(x) := f(x, y)

bind

public static Function bind(BinaryFunction f)
Binds both arguments of a BinaryFunction together.

bind: Map(A×A,B)→Map(A,B); f↦g. The unitary adjoint function.

derive: bind' = ∂f/∂x (x,x) + ∂f/∂y (x,x).

If, for example, f is a bilinear form β:V×V→K this method will return its square form Q:V→K;x↦Q(x):=β(x,x).

Returns:
g:A→B; x ↦ g(x) := f(x, x)

onFirst

public static BinaryFunction onFirst(Function f)
Applies a function on the first argument, ignoring the second.

onFirst: f→g; (x,y) ↦ g(x,y) := f(x).

Evolves: might be renamed.


onSecond

public static BinaryFunction onSecond(Function f)
Applies a function on the second argument, ignoring the first.

onSecond: f→g; (x,y) ↦ g(x,y) := f(y).

Evolves: might be renamed.


swap

public static BinaryFunction swap(BinaryFunction f)
Swaps the two arguments of a BinaryFunction.

swap: Map(A1×A2,B)→Map(A2×A1,B); f↦f.

derive: swap' = (fy(y,x), fx(y,x)).

Returns:
f:A2×A1→B; (x,y) ↦ f(x,y) := f(y,x)

map

public static Tensor map(Function f,
                         Tensor a)
Maps a list of arguments with a function.

See Also:
Functionals.listable(orbital.logic.functor.Function)

map

public static Vector map(Function f,
                         Vector a)

map

public static Matrix map(Function f,
                         Matrix a)

map

public static Tensor map(BinaryFunction f,
                         Tensor x,
                         Tensor y)
Maps two lists of arguments with a binary function.

See Also:
Functionals.listable(orbital.logic.functor.BinaryFunction)

map

public static Vector map(BinaryFunction f,
                         Vector x,
                         Vector y)

map

public static Matrix map(BinaryFunction f,
                         Matrix x,
                         Matrix y)

foldRight

public static double foldRight(BinaryFunction f,
                               double c,
                               double[] a)
See Also:
Functionals.foldRight(orbital.logic.functor.BinaryFunction, Object, Object[])

map

public static double[] map(Function f,
                           double[] a)
See Also:
Functionals.map(orbital.logic.functor.Function, Object[])

map

public static int[] map(Function f,
                        int[] a)

map

public static long[] map(Function f,
                         long[] a)

map

public static float[] map(Function f,
                          float[] a)

map

public static double[] map(BinaryFunction f,
                           double[] x,
                           double[] y)
See Also:
Functionals.map(orbital.logic.functor.BinaryFunction, Object[], Object[])

map

public static int[] map(BinaryFunction f,
                        int[] x,
                        int[] y)

map

public static long[] map(BinaryFunction f,
                         long[] x,
                         long[] y)

map

public static float[] map(BinaryFunction f,
                          float[] x,
                          float[] y)

nest

public static Function nest(Function f,
                            int n)
Nests a function n times within itself.

nest: (f,n) ↦ fn = f ∘ f ∘ ... ∘ f (n times).
nest(f,n).apply(A) gives an expression with f applied n times to A.

Parameters:
f - the function to be nested.
n - the number of times the f should be composed.
Preconditions:
n>=0

pointwise

public static Function pointwise(Function elemental)
A function that performs an operation pointwise.

For Arithmetic objects this will be the elemental function applied on x. For Function objects this will be a composition of this pointwise operation with x.

Parameters:
elemental - the elemental function f to perform on Arithmetic x.
Returns:
x ↦ if x instanceof Arithmetic but not of MathFunctor then f(x) else f ∘ x fi.

pointwise

public static BinaryFunction pointwise(BinaryFunction elemental)
A BinaryFunction that performs an operation pointwise.

For Arithmetic objects this will be the elemental function applied on x and y. For functor objects this will be a composition of this pointwise operation with x and y.

Parameters:
elemental - the elemental function to perform on Arithmetic x.
Returns:
(x,y) ↦ if x and y instanceof Arithmetic but not of MathFunctor then f(x,y) else f ∘ (x,y) fi.

not

public static Predicate not(Predicate p)
Negates predicates

Parameters:
p -
Returns:

Orbital library
1.3.0: 11 Apr 2009

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