1.4. Code Examples¶
1.4.1. Example 1¶
In this first example, two vectors of \(n\) constants, \(black\) and \(white\), are defined and the independence of each constant with the rest is provided as a set of negative constraints.
Iterator command \(T\) is used twice with the same index \(i\) resulting in a coordinated replacement.
The following code returns the two CVECTORs of \(n\) constants.
CV('black', n)
CV('white', n)
For instance, if \(n=3\), the code defines the constants:
These CVECTORs are used below to define two sets of negative duples with:
EXC(T('black', i), M('white', R('black', T('black', i))))
EXC(T('white', i), M('black', R('white', T('white', i))))
which results in the following duples:
1.4.2. Example 2¶
The next example makes a random selection of constants from \(black\) and calculates its idempotent summation.
For each constant not selected in \(black\), the corresponding constant in \(white\) is appended to the summation so exactly \(n\) constants are always added.
The resulting element for the summation is assigned to the right-hand side of a positive duple.
First, we define the constants, and set the \(black\) and \(white\) CVECTORs as being complementary component by component,
n = 3
C('r')
CV('black', n)
CV('white', n)
COMP('black', 'white')
then we carry out a random selection of components of \(black\) that get stored in a descriptor \(x\) of type VECTOR, and use \(x\) to define a positive duple with the code:
p = 0.05
atLeastOne = False
notAll = True
x = SOME('black', p, atLeastOne, notAll)
INC('r', M(x, R('white', COMP(x))))
A possible return for \(x\) could have components \(black[0], black[1]\) and the positive duple would then be:
With the recent changes it is simple to define real-valued fields:
C('cold')
C('warm')
INC('cold', N('temperature', 8))
INC('warm', N('temperature', 25))
This will return a series of constants representing the field and its value: