r1 - 08 Jun 2006 - 20:44:08 - TimPetersonYou are here: TWiki >  GRAPEcluster Web  >  Documentation > FunctionBasics

Functions

The basic element of data processing is the Function. It is so named because it fits the mathematical definition of a function, determining an output value based on its input. In general, each Function receives input data from somewhere, processes it somehow, and produces output data. Some types of Functions may omit one or more of these steps; for example output data may be generated internally rather than being the result of processing input data. Functions can receive as input the output from some other function. Functions are not limited to one input and one output, so they can feed off multiple input functions and produce multiple pieces of output data. By connecting different types of Functions together, a complex processing sequence can be created.

In order for one Function to interact with other Functions, there needs to be a defined interface specifying what input and output each Function can produce. Each Function has a set of inputs and a set of outputs. Each input or output has a name, uniquely identifying it within the Function. An input specifies a set of data types which it can accept from other Functions, in case there may be multiple possible representations of the same information. An output, likewise, specifies a set of data types in which it is willing to produce data. By matching a data type of an output of one Function with a data type of an input of another Function, the two can be linked, and will thenceforth pass data from one to the other.

Inputs can have one or more acceptable data types, and can optionally accept data from multiple outputs. There are then four useful combinations of these properties. A single input takes data of one data type from one output. A polymorphic input takes data of any of a number of types, but still from only one output. A multiple input again accepts only one data type, but can receive data from any number of outputs. Finally, the multiple polymorphic input, a combination of the previous two varieties, will accept any of several data types from as many outputs as is desired.

Outputs have the same possibilities as inputs, although the meaning is slightly different because outputs have no limit on the number of inputs they can supply with data. A single output produces a single value of a single type, but can provide this data to multiple inputs. A polymorphic output produces a single value, but this value can be expressed in different data types. Different connected inputs can request the data in different data types, according to their needs, and the output will oblige by producing data of the proper type for each. A multiple output uses a single data type, but it can produce a list of any number of values of that type as a single datum. One consqeuence of this is that a multiple input can receive its multiple values from either a group of single outputs, one multiple output, or a combination of the two. Finally, the multiple polymorphic output produces a list of homogeneous values, in any supported type requested by the various connected inputs, with different lists of values produced for each data type.

Many types of functions need to receive not only input data but also auxiliary parameters specifying details of how the processing should be carried out. Furthermore, it may also be desirable for these parameters to be controlled by other Functions in the system. Thus, Functions can have parameter inputs, which are single value, single data type inputs with the added feature of a default value. Whenever the parameter input is not connected to any outputs, its value becomes that of the default value. In this way, a parameter can be controlled either by the user or by another Function, depending on the circumstances.

Functions are lazy. That is, they never recompute the value of an output unless the associated input(s) have changed in value. In addition, they only recompute the value of an output when another function requests the value of that output. As a result, a function can endure numerous changes in its input data or, alternatively, numerous requests for its output data, without any ill effects. Only when the output data is required in order to recompute a dependent function is the value actually computed.

Examples

In their simplest forms, an input will accept only one type of data from one other output at a time, and an output will produce only one type of data. For example, if numbers were being processed by the system, there might be a Function which performs a certain operation on a number, such as the square root. The square root takes one number as input, and produces one number as output. The square root operation can only operate on one number, so the input to the square root Function must likewise accept only one number.

Continuing with the number processing theme, suppose we wanted to create a Function that performs addition. This Function would need two inputs, the augend and the addend which are to be summed. These inputs would still accept a single data type, a number, and a single value each. There would again be one number output, the sum.

While addition is commutative, subtraction is not. Thus, a subtraction Function would need to differentiate its inputs so that the order is known. For this reason, inputs can be named. Naming one "minuend" and the other "subtrahend" would allow the user to connect inputs to the Function in the correct order.

So far, all of our Functions have had only one output. Suppose we wanted to create a Function that would produce the quotient and remainder of two numbers simultaneously. It would then need two outputs to handle the different output values. This could be accomplished by endowing it with two inputs named "dividend" and "divisor," and two outputs named "quotient" and "remainder."

A single input can have the capability of accepting input from more than one other Function's output. This could be useful for creating a Function that will determine the maximum of its input values. It would have one input, accepting only numbers, which can connect to multiple outputs. The Function would then be able to operate on the input values from all of the connected Functions and compute the maximum. Better yet, it could simultaneously compute not only the maximum but also the minimum and average. It would then have three outputs, named according to these three computed quantities.

Complementing the multiple-valued input is the multiple-valued output. This could be used to sort a list of numbers. The multiple input provides to the Function an ordered list of the input values it receives from its connected outputs. The sorting Function would then sort that list and send it out through the multiple output. Multiple outputs can in turn be used as input to multiple inputs, and the list of output data will be inserted into the list of input data as if there were a group of single-valued outputs all feeding into that one input.

-- TimPeterson - 08 Jun 2006

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
General Information
Technology
  • Resources

Documentation
Repository
Related Projects
  • GUI Development
  • MovieMaker?
  • GUI
  • 3D Input Devices
  • Fly Through Path

Related Sites

 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback