User:Thepigdog/Value container

A Value Set is an object, which represents the set of values a variable may have. The value set behaves mathematically as a single value, while internally representing multiple values. To achieve this the the Value Set tracks the value along with the context, or world, in which they occurred.

Multiple solutions to an equation
In mathematics, an expression must represent a single value. For example consider the equation,


 * $$x^2 = 4$$

which implies,
 * $$x = 2 \lor x = -2 $$

But this is a bit long winded, and it does not allow us to work with multiple values at the same time. If further conditions or constraints are added to x we would like to consider each value to see if it matches the constraint. So naively we would like to write,
 * $$x = \pm 2 $$

Naively then,


 * $$x + x \in 2, 0, -2 $$

but this is wrong. Each x must represent a single value in the expression. Either x is 2 or x = -2. This can be resolved by keeping track of the two values so that we make sure that the values are used consistently, and this is what a value set does.

Worlds
A world is a possibility, or alternative, associated with a proposition. The value for x is either 2 or -2. By identifying these values with worlds we can track values so that values from different worlds are not combined. The value container for x, for the equations above is,


 * $$x = [2:A, -2:B] $$

which says that x = 2 in world A and -2 in world B. Note that A and B are names used to identify worlds. The only property of these worlds we are interested in is there identity, and I am using A and B here, purely to represent this identity. The worlds A and B are defined by,
 * A is the world in which proposition x = 2 may be asserted.
 * B is the world in which proposition x = -2 may be asserted.

A world is somewhat like a set and set notation is used to represent the intersection of worlds. The intersection of worlds is a world where the conjunction of the propositions is true.

A value container is not a set, but it contains a set,


 * $$s(X) = \{2:A, -2:B\} $$

The : operator is used to tag the value with the world.

World Sets
A world set is a set of worlds that represent all possibilities. So $$ \{A, B\} $$ is a world set as either x = 2 (in world A) or x= -2 (in world B).

Worlds from the same world set are mutually exclusive, so it is not possible that the propositions for both worlds A and B are true at the same time.
 * $$x = 2 \land x = -2 = \text{false} $$

Law for functions of a value container
A value container contains a set of tagged values. The tagged value set for a container X is written $$s(X)$$.


 * $$s(F(X)) = \{ f_v(x_v):f_w \cap x_w | f_v:f_w \in s(F) \land x_v:x_w \in s(X) \} $$

where F is a function and X is a value container, and F(X) is the container obtained by applying F to X.

This law may be applied with Currying to give laws for the application of functions to multiple parameters. For example,


 * $$s(X + Y) = \{ x_v + y_v):x_w \cap y_w | x_v:x_w \in s(X) \land y_v:y_w \in s(Y) \} $$

may be derived. From the previous example,

$$x + x = [2:A, -2:B] + [2:A, -2:B] = [4:A \cap A,0:A \cap B,0:B \cap A,-4:B \cap B] = [4:A, -4:B] $$

because,
 * $$ A \cap A = A $$
 * $$ A \cap B = \empty $$

Terms from empty worlds may be dropped.

Use of value containers
Value containers allow the construction of inverse functions for functions that are a many to one mapping. In many cases this allows us to use inverse functions to solve equations. By choosing the evaluation order so as to minimize the number of values in the value set, efficient evaluation may be achieved.

It is helpful to regard an equation like,
 * $$ f(x, y) = z $$

as a relationship between 3 values. Based on which values are provided the value that is not provided may be calculated. This simple approach allows the evaluation of variables constrained by logic in most situations.

The standard form of value containers
The standard form of value containers is to not merge tagged values, even if they have the same value. Each tagged value always has the intersection of all the worlds from which it was formed.

This convention allows a simple rule for determining if a world is empty. If a world no longer is present in a value container, then the world is empty. For example,

$$ x^2 = 4 \land y^2 = 9 \land x*y > 0 \land x+y > 0 $$

gives,
 * $$x = [2:A, -2:B] $$
 * $$y = [3:C, -3:D] $$
 * $$x*y > 0 \land x+y > 0 = [true:A \cap C] $$

and as B and D are not in the last value container then B and D are empty, which gives,


 * $$x = [2:A] = 2 $$
 * $$y = [3:C] = 3 $$

The constraint evaluation paradigm
Value containers may be used to implement a simple form of logic in a computer language, based on narrowing. This paradigm is based almost completely on the evaluation of expressions. Narrowing occurs when worlds are shown to be empty.

Evaluation order
The evaluation order must be flexible so as evaluation to proceed in the order best suited to reducing the number of values in value containers. The measure used to choose this order is the product of the number of values in the input to the calculation.