This section explains how you can use Aion to develop your algorithm or mathematical model.

## Creating A Simple Algorithm¶

The algorithm in figure Figure 73 is a trivial example algorithm.

Figure 73 A Simple Example

Entering mathematics in Aion is slightly different than what you might find with common word processors. In a traditional word processor you typically enter expressions from left to write. Aion builds mathematical expressions by inserting operators directly. The Aion approach provides several advantages:

• By inserting the operators directly, you provide Aion with more information with fewer steps. Aion uses this information to automatically add parenthesis for you.

• The Aion approach leads to fewer errors. Aion looks at the capabilities of each operator and uses that information to disable operators and functions that are incompatible with what’s possible where the cursor is positioned. Aion guides you so that you are less likely to create mathematical constructs that won’t work.

### Inserting A Simple Assignment¶

To insert $$a = 5$$, first insert an assignment operator. You can do this by one of three different methods:

• By selecting Insert | Basic Math | Assignment, or

• by clicking on the $$? = \; ?$$ button in the Basic Math Dock, or

• by typing ‘’\=’’ followed by a space on your keyboard to invoke the bashslash command for the assignment operator.

As soon as you do this, you will see:

$? = \; ?$

Place the cursor on the left hand ‘’?’’ and insert a variable. If your variable name starts with a traditional letter, you can simply type in the letter. Variables can have subscripted names such as $$a _ x$$. Once you type in the first letter, say ‘’a’’, the cursor will be positioned to enter the subscript. You can reposition the cursor using the mouse or by pressing the left arrow once of you wish to enter a longer name such as $${ available } _ x$$. If you wish to enter a variable name that starts with a greek character or special character, e.g. $$\alpha _ x$$, you must explicitly insert a variable by:

• Selecting Insert | Basic Math | Variable, or by

• Clicking on the $$a _ x$$ button in the Basic Math dock, or by

• typing ‘’\var’’ to invoke the backslash command for inserting variables.

Once you enter the variable name, you can position the cursor over the ‘’?’’ on the right side of the equals sign.

To enter a literal constant value, e.g. ‘’5’’, you can simply type in the numeric value. You can also explicitly insert a literal value by inserting a literal value math element via the menus, the Basic Math dock, or the ‘’\lit’’ backslash command.

If you wish to insert a more complex literal, such as $$5.4 \times 10 ^{-6} + 3.5 \times 10 ^ {-5} i$$, you would type ‘’5.4E-6+3.5E-5i’’. Aion will automatically convert the notation to Scientific notation for you. If you prefer, you can also use ‘’j’’ instead of ‘’i’’.

To complete the example, move the cursor to the end of the line, press return to insert a new paragraph, and repeat the directions above to insert $$b = 3$$.

### Inserting A More Complex Operation¶

You can insert more complex operations, such as $$c = a + b$$, using the same basic approach described in Inserting A Simple Assignment.

First place the cursor at an appropriate location and insert the assignment using the $$? = \; ?$$ button on the Basic Math dock or by typing ‘’\=’’.

Place the cursor at the left side ‘’?’’ and type ‘’c’’.

Place the cursor at the right side ‘’?’’ and insert an addition operator by:

• Typing ‘’+’’, or by

• Selecting Insert | Basic Math | Operators | Basic | Addition, or by

• Clicking on the $$? + \; ?$$ button on the Basic Math Dock, or by

• Typing ‘’\+’’ followed by a space to invoke the backslash command for the addition operator.

At this point, you expression will look like:

$c = \; ? \; + \; ?$

Place the cursor at the left hand ‘’?’’ and type a. Place the cursor at the right hand ‘’?’’ and type ‘b’.

You can use the approaches described in Inserting A More Complex Operation and Inserting A Simple Assignment to build arbitrarily complex mathematical expressions.

### Displaying The Results¶

To display the results of the operation you entered in Inserting A More Complex Operation, move the cursor to the end of the current line, press ‘’Enter’’ to start a new paragraph and type in ‘’The sum of a+b is ‘’.

After ‘’is’’, insert a field by:

• Selecting Insert | Field…, or by:

• Clicking on the on the Insert Dock, or by:

• Typing ‘’\vf’’ followed by space to invoke the value field backslash command.

You should see the Insert Field dialog, shown in Figure 91. Set the variable name to ‘’c’’ and click OK. For details on using fields, see Fields.

## L-Values And R-Values¶

We will sometimes refer to values as L-values or R-values.

An L-value is value that is being modified or changed. In Computer Science, the ‘’L’’ in L-value means ‘’locator’’ value or value we can define the location of. In the context of Aion, L-values are the values being modified by a mathematical expression.

An R-value is a value that is calculated or is providing a value. R-values are referenced by the expression but otherwise untouched. R-values are often temporary values.

Loosely speaking, L-values will be on the left side of an assignment while R-values will generally be on the right side of an assignment, although this definition is technically wrong.

Consider the expression below:

$a _ { r, c + 3 } = x + y$

Where $$a$$ is a matrix.

The value $$a$$ is an L-value because the variable $$a$$ is being modified by the expression. The values $$r$$, $$c + 3$$, and $$x + y$$ are R-values because they are referenced.

## Root Operators¶

There are a small number of operators that you can insert directly in-line with text and can then contain other operators. These operators, listed in Table 4, are referred to as Root Operators because they can be used as the starting point or root of a mathematical expression.

Table 4 The Root Operators

Operator

Function

$$? =\; ?$$

You can use the assignment operator to assign a value to a variable. You can also use this operator to define your own functions.

The $$? = \; ?$$ operator can also be used within an mathematical expression, as an R-value, to test if two values are equal.

$$? \in\; ?$$

You can use this operator to explicitly tell Aion the type of a variable, including both simple values and matrices.

The $$\in$$ operator can also be used as an R-value to check if a value is contained within a set, including the sets $$\mathbb{B}$$, $$\mathbb{Z}$$, $$\mathbb{R}$$, $$\mathbb{C}$$, and $$\varnothing$$.

$$? \rightarrow\; ?$$

You can use this operator to conditionally evaluate an expression. An an example, the statement $$a = 5 \rightarrow \; b = 7$$ will only assign the value 7 to $$b$$ if $$a$$ is 5.

The $$? \rightarrow\; ?$$ operator can also be used as an R-value as a logical conditional operator.

$$\forall \; ? \; \in \; ? :$$

You can use this operator to iterate across any value containing multiple values, including sets, matrices, tuples, and ranges. The operator will evaluate a mathematical expression for each value.

$$\text{while}\; ? :$$

You can use this operator to repeatedly evaluate a mathematical expression while a condition is met.

$$\text{if}\; ? :$$

You can use the $$\text{if}\; ? :$$ operator to evaluate a mathematical expression only if a condition is true.

$$\text{else if}\; ? :$$

You can use the $$\text{else if}\; ? :$$ operator in conjunction with the $$\text{if}\; ? :$$ to test and conditionally evaluate multiple conditions.

$$\text{else} :$$

You can use the $$\text{else} :$$ operator in conjunction with the $$\text{if}\; ? :$$ and $$\text{else if}\; ? :$$ operators to evaluate a mathematical expression only if all preceding $$\text{if}\; ? :$$ and $$\text{else if}\; ? :$$ operators were not evaluated.

## A More Complex Example¶

The algorithm in figure Figure 74 shows a somewhat more complex example that demonstrates a number of features.

Figure 74 A More Complex Example

The expressions $$x _ i \in \mathbb{R}$$ and $$y _ i \in \mathbb{R}$$ indicate that the variables $$x$$ and $$y$$ must be matrices containing real values.

Aion will normal use heuristics to identify the best way to store and track each variable. You can use the $$\in$$ operator to override the heuristics used by Aion to make these determinations. For details, see How Variable Types Are Determined.

The statement $$N = 100$$ will assign the value 100 to $$N$$. Note that because 100 is an integer number and because we haven’t told Aion what type of number $$N$$ should be, Aion will make an initial guess that $$N$$ should be an integer.

If later, we set $$N = 102.5$$, Aion would see that $$N$$ is being assigned a real number and would adjust it’s guess for $$N$$ since the integers are a subset of the real numbers.

The $$\forall \; i \text{ over } 1, \ldots, N :$$ operator tells Aion that you want the variable $$i$$ to contain the integer values from 1 to N, inclusive, evaluating the expressions on the right for each value of i.

Because we haven’t told Aion that $$i$$ should be an integer, real number, etc., Aion will look at all the locations where $$i$$ is used as an L-value and make a determination as to the best way to store $$i$$.

In this scenario, Aion will evaluate the range, $$1, \ldots, N$$. Aion will identify that both 1 and $$N$$ are integers and that the range increments by 1 which is also an integer, determining that all the values provided by the range are integers. Aion will then make a guess that $$i$$ can also be an integer.

The compound operator, shown in Figure 75, groups multiple mathematical expressions together, treating them much like a single expression.

Figure 75 The Compound Operator

In this example, the compound operator is being used to evaluate several expressions for each value of $$i$$.

The mathematical expression

$x _ i = 10 \pi \frac{i - 0.5 N}{N}$

simply calculates a value for $$x _ i$$ from $$-5 \pi$$ to $$5 \pi$$ for each value of $$i$$.

The expression

$\begin{split}y _ i = \begin{cases} 1 & \text{if} \left ( x _ i \right ) = 0 \\ \frac{\sin \left ( x _ i \right )}{ x _ i} & \text{otherwise} \end{cases}\end{split}$

Calculates the sinc function of $$x - i$$. Note the use of a case or brace conditional operator to avoid dividing by zero.

## Using Sets, Tuples, And Strings¶

The algorithm in figure Figure 76 shows a trivial use of sets and strings. Note that, for this example, we’ve included fields showing the results from the mathematical expressions.

Figure 76 A Basic Example Using Sets, Tuples, And Strings

In this example, we assign two sets, $$A$$, and $$B$$, and then calculate the union and symmetric difference of each set.

Note that sets can contain anything, including other sets, tuples, matrices, and simple values. You can iterate across sets using the $$\forall$$ operator.

To insert a literal set, we can use the set operator, $$\left \lbrace a, b \right \rbrace$$. Once the cursor is within the set, simply add the values you want added, including variables. You can add additional values by typing a comma (‘’,’’). If the cursor is placed before the first element in the set, the element is prepended in visual order.

Sets $$A$$ and $$B$$ contain 4 and 3 text strings respectively. You enter a string by:

• Typing either a single or double quote character. When quotes are used, the text string will be displayed surrounded by the quote you specify. The ending quote is inserted automatically.

• Inserting a literal element using the Insert | Literal menu item, by clicking on $$1.2$$ in the Basic Math Dock, or using the ‘’\lit backslash command. Once the empty literal element is inserted as indicated by a gray pound symbol (#), start the text string using one of “, ‘, or <. If ‘’<’’ is used then the text string will be displayed surrounded by angle brackets as shown in Figure 76

The statements

$U = A \cup B \qquad D = A \bigtriangleup B$

calculate the union and symmetric difference of sets $$A$$ and $$B$$ respectively.

The next two paragraphs simply display the output of $$A$$ and $$B$$ using fields.

The statements

$s _ { all } = \left ( \right ) \qquad s = \left ( \right )$

Define two tuples named $$s _ { all }$$ and $$s$$. These tuples will contain text strings. Tuples are similar to sets in that they can contain anything, including other tuples. Tuples differ from sets in that the contents are ordered and can repeat.

You can access and modify the contents of individual items in a tuple using the subscript operator $$b _ i$$ much the same way we can access elements of a matrix. Note that because tuples can contain anything Aion has no viable way to identify the type of tuple members.

You can also iterate through the contents of a tuple using the $$\forall$$ operator. The $$\forall$$ operator will iterate in order starting at element 1.

Aion stores strings as tuples. A text string is simply a tuple containing integer values where each integer value is the Unicode code point for each character. For details regarding Unicode, see https://www.unicode.org.

The statement

$\forall s \in U : s _ { all } = s _ { all } \cdot s$

Iterates through the set $$U$$, concatenating each text string contained in $$U$$ to the tuple $$s _ {all}$$.

You may note that Figure 74 showed the $$\forall$$ operator as with the word ‘’over’’ whereas the example Figure 76 shows the $$\forall$$ operator using the symbol $$\in$$. The $$\forall$$ operator will automatically adjust based on the type of data being iterated over.

The statement

$C = \text{Alph} \; s _ { all }$

Calls the Aion function ‘’Alph’’. You can insert this function using the Function Dock or by using the backslash command ‘’alphabet’’. This function returns a set containing all the unique values in the parameter(s).

The remaining paragraphs in the example simply use fields to display results. Note that the displayed values are shown as strings or as a set of hexidecimal integer values. The format of the value fields were adjusted using the Format | Field… menu option to customize how the fields were presented.

You will also note that the unicode point values are displayed in ascending order. Aion sets are implemented using a unique internal data structure that allows sets to be iterated across in ascending order. For details, see Implicit Ordering, Sets, And Sorting.

## Literal Types¶

Aion supports ten fundamental data types. The first four types:

• Boolean

• Integer

• Real values, and

• Complex

are the four fundamental or simple types. All other types are based on these four fundamental types.

### Boolean Literals¶

You can insert the boolean literals ‘’true’’ and ‘’false’’ using the $$\text{true}$$ and $$\text{false}$$ special values. You can add these values using the Insert | Sets & Logic | Boolean true value and Insert | Sets & Logic | Boolean false value menu options, using the buttons on the Sets/Logic Dock or by using the ‘’\true’’ or ‘’\false’’ backslash commands.

You can also use the value ‘’0’’ for false and any non-zero numeric value for true.

### Numeric Literals¶

Numeric literals can be added using the literal operator. You can add a numeric literal using the Insert | Basic Math | Numeric Literal menu option or the $$1.2$$ button on the Basic Math Dock. Alternately you can use the ‘’\lit’’ backslash command.

As a shortcut, you can enter a literal at an empty position in a mathematical expression by typing a digit.

#### Integer Literals¶

Integer literals, entered using the literal operator, are identified as whole number values without a decimal point. Integer literals can also be written in ANSI-C hexidecimal or binary notation. You can enter hexidecimal integers using the form ‘’0xdddd…’’ where dddd… indicates one or more hexidecimal digits. You can enter binary integers using the for ‘’0bdddd…’’ where ‘’dddd…’’ indicates one or more binary digits.

#### Real Literals¶

Real literals, entered using the literal operator, are identified as whole or fractional number values that either contain a decimal point or are in scientific notation.

The values $$5.1$$, $$5.$$, and $$5 \times 10 ^ 5$$ would all be considered real literal values, whereas $$500000$$ would be considered an integer value.

#### Complex Literals¶

Complex literals, entered using the literal operator, are identified as any literal containing an imaginary component indicated by an ending $$i$$ or $$j$$. The values $$5i$$, $$4.2 + 0i$$, $$5.123 \times 10 ^ 5 + 1.2 \times 10 ^ 3 j$$ would all be considered complex values.

#### Text String Literals¶

Text string or string literals, entered using the literal operator, are identified by a leading “, ‘, or <. The values $$\text{"Aion"}$$, $$\text{'Aion'}$$, and $$\left \langle \text{Aion} \right \rangle$$ would all be considered valid text strings.

#### Other Literal Types¶

Other literal types are entered using operators appropriate for those types.

You can use the matrix operator, , to add literal matrices.

You can use the set operator, $$\left \lbrace a, b \right \rbrace$$, to add literal sets.

You can use the tuple operator, $$\left ( a, b \right )$$, to add literal tuples.

## Variable Types¶

Aion supports ten fundamental data types matching the literal types discussed in Literal Types.

### Boolean Variables¶

Boolean variables can hold either a ‘’false’’ value or ‘’true’’ value and support a unique set of operations. You can expect to find boolean values and their associated boolean operators used heavily in your algorithms or mathematical models.

You can use the special values ‘’true’’ and ‘’false’’ as explicit boolean values. Alternately, you can use a literal ‘’0’’ as a boolean ‘’false’’. Any non-zero literal value, such as ‘’1’’, will be treated as a boolean ‘’true’’.

There are a number of operators that are specific to boolean variables and, more generally, boolean values.

#### Unary And Overbar Not Operators¶

The unary not operator, $$\neg \; ?$$, and overbar not operator, $$\overline{x}$$, are similar in that they flip the state of the provided value. Table 5 shows the relationship for the negation operator.

 $$y = \neg x \qquad y = \overline{x}$$ $$x$$ $$y$$ false true true false

#### Logical And Operator¶

The logical and operator provides a ‘’true’’ result only if both values are true. Table 6 shows the relationship for the logical and operator.

 $$y = a \; \land \; b$$ $$a$$ $$b$$ $$y$$ false false false true false false false true false true true true

#### Logical Or Operator¶

The logical or operator provides a ‘’true’’ result if either provided value is true. Table 7 shows the relationship for the logical or operator.

 $$y = a \; \lor \; b$$ $$a$$ $$b$$ $$y$$ false false false true false true false true true true true true

#### Logical Conditional Operator¶

The logical conditional operator provides a ‘’true’’ value if either the first parameter is false or if both parameters are true. Table 8 shows the relationship for the logical conditional operator.

 $$y = a \; \rightarrow \; b$$ $$a$$ $$b$$ $$y$$ false false true false true true true false false true true true

#### Logical Biconditional Operator¶

The logical biconditional operator provides a ‘’true’’ value if both values evaluate to the same boolean representation. Table 9 shows the relationship for the logical biconditional operator.

 $$y = a \; \Leftrightarrow \; b$$ $$a$$ $$b$$ $$y$$ false false true false true false true false false true true true

Note

While the logical biconditional operator may appear to be the same as a test for equality, it does differ slightly.

Note all non-zero numeric values evaluate to true when used in boolean expressions; therefore the statement $$3 \; \Leftrightarrow\; 4$$ will evaluate to ‘’true’’ whereas $$3 \;=\; 4$$ will evaluate to ‘’false’’.

#### Logical Exclusive Or Operator¶

The logical Exclusive Or operator provides a ‘’true’’ value if either of the supplied values evaluate to ‘’true’’ but not if both values evaluate to ‘’true’’. Table 9 shows the relationship for the logical exclusive or operator.

 $$y = a \, \lor\mspace{-17mu}-\; b$$ $$a$$ $$b$$ $$y$$ false false false false true true true false true true true false

### Integer Variables¶

Integer variables hold whole number values. In Aion, integers are stored as signed 64-bit values and can represent values between -9,223,372,036,854,775,808 and +9,223,372,036,854,775,807. Arithmetic on integers that exceed these values will cause the result to roll over.

### Real Variables¶

Real variables can hold both whole numbers and fractional values. Aion, stores real values as 64-bit quantities conforming to the IEEE 754-2008 standard. The real value representation supports a wide range of values and graceful loss of precision within increasing values. Table 11 gives the capabilities of the real value format used by Aion.

Table 11 Real Value Limits

Parameter

Value

Most positive representable value

$$+1.7976931348623157081 \times 10 ^ {+308}$$

Most negative representable value

$$-1.7976931348623157081 \times 10 ^ {+308}$$

Smallest representable value greater than 0

$$+2.2250738585072013831 \times 10 ^ {-308}$$

Machine Epsilon

$$+2.2204460492503130808 \times 10 ^ {-16}$$

Most positive integer value that can be represented without loss of precision.

+9,007,199,254,740,992

The internal format of the real number representation is shown, in detail in Figure 77.

Figure 77 Real Number Format

Each box represents a single bit or base-2 digit. The mantissa is 53 bits in length and the exponent is 11 bits in length. If encoded as separate integer fields, the exponent’s value can range from 0 to +2047 and the mantissa’s value can range from 0 to 9,007,199,254,740,991.

The internal real number representation is converted to a number by the relation:

$(-1) ^ { sign } \left ( 1 + mantissa \right ) \times 2 ^ { exponent - 1023 }$

Note that real numbers have a limited range for the mantissa and the mantissa is scaled by a power of 2. This representation causes the real number format to have limited accuracy and some values, such as 1/3, can not be represented precisely. The Machine Epsilon represents the limit of this accuracy for values close to 1.0.

Furthermore, note that this limited accuracy can accumulate. You must be mindful of the limited precision when developing your algorithm as these errors can accumulate when performing highly iterative computations. Errors can also become dominant when multiplying small differences by large scale factors.

Note

Due to limited accuracy of the double precision floating point representation of real numbers, comparison of real numbers using the $$? =\; ?$$ operator may lead to unexpected results. When comparing real numbers, you should consider checking for a close match rather than an exact match using expressions such as $$\frac{\left | a - b \right |}{\text{max} \left ( \left | a \right |, \left | b \right | \right )} < 10 \mathit{E}$$.

In the example above, $$\mathit{E}$$ would be the machine Epsilon. The exact threshold used should be chosen with care based on an evaluation of the algorithm being employed.

### Complex Variables¶

Complex variables require 128-bits per stored value and are tracked as pairs of real values. For this reason complex variables have all of the capabilities and limitations discussed in Real Variables.

### Arrays And Matrices¶

Aion supports four different types of matrices:

• Boolean matrices,

• Integer matrices

• Real matrices

• Complex matricies

Matrices are always tracked and managed as two dimensional objects although matrices can be one row or one column in height or width. You can use row or column matrices as arrays.

If needed, you can define tuples of matrices to simulate tensors although some operations, such as tensor contraction, are not currently supported.

You can use the subscript operators $$b _ i$$ and $$b _ { i,j }$$ to access individual elements in a matrix. Matrix row and column values are 1 based. Backslash commands for $$b _ i$$ and $$b _ { i,j }$$ are ‘’\__’’ and ‘’\_’’ respectively.

The $$b _ i$$ operator is primarily intended for use on row or column matrices and tuples but can be used on matrices of 2 dimensions. Elements are indexed from left to right and top to bottom as shown in Figure 78

Figure 78 Using A Single Index On Matrices

In addition, you can take slices of matrices and you can combine matrices.

#### Matrix Slices¶

You can use the subscript operators to take slices of matrices and tuples by using any multi-valued type as a subscript value. The multi-valued type must contain positive whole number values that correlate to row and column numbers. Figure 79 shows several ways you can use slices.

Figure 79 Slicing Matrices

Note that, if you choose, you can also use slices in place of pivot matrices to reorder rows and columns.

#### Combining Matrices¶

You can also combine matrices as well as matrices and individual values using matrix combine operators, and . These matrix operators can be used in combination and with the matrix operator, , to build complex matrices. Figure 80 shows the use of these operators.

Figure 80 Combining Matrices

Note

At this time, Aion does not automatically add square brackets to matrix combine operators. You may need to explicitly add brackets through the Operator Format Dialog.

Note

When combining matrices of different sizes, Aion will append rows and or columns with zeros, if needed. You can see this with matrix $$F$$ in Figure 80.

Note

Combining large matrices can be a processor intensive operation and may be time consuming.

#### Dynamic Resizing¶

Matrices will resize automatically whenever you assign a new element that is outside of their current size using either subscript operator. Elements that must be added implicitly when a matrix is resized will be populated with ‘’0’’.

Note

Aion matrices include provisions to handle resizing efficiently; however, resizing a matrix will sometimes require significant processor overhead. If you know the correct size of a matrix, you may want to consider pre-initializing the matrix by setting the value of the bottom right element first or by using the matrix zero functions $$Z _ B$$, $$Z _ Z$$, $$Z _ R$$, or $$Z _ C$$.

#### Capabilities Of Different Types Of Matrices¶

Each type of matrix has different capabilities. Table 12 lists the key capabilities provided by each type of matrix.

Table 12 Capabilities Of Each Matrix Type

Capability

Boolean

Integer

Real

Complex

Approximate storage per element

1 bit

8 bytes

8 bytes

16 bytes

Supports subscript operator

Supports slices, matrix combining operations, and transpose

Supports addition and subtraction of matrices

Supports matrix multiplication and multiplication against basic types.

Supports division by basic types

Supports identity and zero matrices

Supports conversion between diagnonal arrays and matrices

Supports dynamic resizing

Supports complex conjugate

Does nothing

Supports Hermitian transpose

Same as transpose

Supports separation into real and imaginary parts.

Supports flipping rows/columns in a matrix

Supports tests for square

Supports tests for symmetric

Supports tests for skew symmetric

Supports tests for Hermitian and skew Hermitian

Supports tests for Hermitian and skew Hermitian

Supports tests for normal

Supports calculation of matrix rank

Supports calculation of determinant

Supports calculation of matrix inverse

Supports common decomposition operations (e.g. PLU, LQ, QR, SVD, etc.)

Supports Hessenberg decomposition operations

Supports Schur decomposition operations

Supports calculation of eigenvectors and eigenvalues

Supports calculation of DFT and inverse DFT

Supports calculation of approximate condition number and norms

Supports solving of $$A X = Y$$ for $$X$$ as a function of $$A$$ and $$Y$$.

Supports solving of least squares solutions to over/under determined systems.

Supports calculation of the matrix kernel

Fast calculation of per-element floor, ceiling, and nearest integer

In many cases, Aion will silently convert upwards from one matrix type to another. If you attempt to perform an operation on an integer matrix that is only supported by real matrices, Aion will convert the integer matrix to a real matrix before performing the requested operation. Conversion is always upward, that is boolean matrix → integer matrix → real matrix → complex matrix.

Note

Note that conversion between matrix types can be time consuming. You may want to avoid these type conversions in performance critical applications by selecting the correct matrix type.

### Sets¶

Aion sets are special variables that can contain any other type of value, including other sets, tuples, matrices, and simple values. You can use sets to store collections of objects and can quickly test for the presence of objects in sets using operators such as $$\in$$ and $$\subseteq$$.

You can use set operators, such as $$\cup$$, $$\cap$$, $$\setminus$$, and $$\bigtriangleup$$ to manipulate sets.

Iterating across sets using the $$\forall$$ operator will iterate values in ascending order. If the set contains subsets or tuples, ordering will take into account the values within sub-elements. You can use this feature to facilate certain types of models such as discrete event simulations. See Implicit Ordering, Sets, And Sorting for details.

### Tuples¶

Tuples are special variables that can contain any other type of value, including other tuples, sets, matrices, and simple values. You can use tuples to track complex collections of data. Tuples, in contradiction to their name can store any number of items. Values in a tuple can be referenced or modified using the subscript operator $$b _ i$$. Tuple indexes start at ‘’1’’ and are always single dimension.

Like matrices, you can extend a tuple simply by adding a new value at a specified location. The tuple will automatically resize. In this case, implicitly added entries will contain ‘’0’’.

## Classes of Variable Types¶

Aion categorizes the data types into four different classes based on the properties and capabilities of each type. Table 13 lists the various classes and their properties.

Table 13 Variable Classes

Class

Description

Scalar

Indicates types that hold a single numeric value and can be compared using the relational operators $$<$$, $$>$$, $$\leq$$, and $$\geq$$.

Basic

Indicates either scalar types or the complex type.

Iterable

Indicates types that contain one or more values that we can iterate through using subscripting operators and/or the $$\forall$$ operator.

Matrix

Indicates types that hold values of a single type and track those values in a fixed arrangement.

Table 14 indicates to which classes each data type belongs to.

 Data Type Scalar Basic Iterable Matrix Boolean ✓ ✓ Integer ✓ ✓ Real ✓ ✓ Complex ✓ Set ✓ Tuple ✓ Boolean Matrix ✓ ✓ Integer Matrix ✓ ✓ Real Matrix ✓ ✓ Complex Matrix ✓ ✓

## How Variable Types Are Determined¶

Because Aion compiles your algorithm or model directly into executable code and because Aion endeavors to make your algorithm as efficient as possible, variable types must remain consistent throughout your entire model.

When Aion compiles your algorithm, Aion will analyze each location where a variable is used as an L-value and identify a best type to use for the variable. At each subsequent location the variable is used as an L-value, Aion will look at the current best type for that mathematical expression as well as the past best type and identify the a new best type. Table 15 describes how these types are identified. Note that the result type for each operator will also be driven by the types of the provided parameters but will follow different rules.

Table 15 Variable Type Promotion

Last Expression Best Type

Current Expression Best Type

New Best Type

Boolean

Boolean

Boolean

Integer

Integer

Real

Real

Complex

Complex

Set, Tuple, Matrix

Variant

Integer

Boolean, Integer

Integer

Real

Real

Complex

Complex

Set, Tuple, Matrix

Variant

Real

Boolean, Integer, Real

Real

Complex

Complex

Set, Tuple, Matrix

Variant

Complex

Boolean, Integer, Real, Complex

Complex

Set, Tuple, Matrix

Variant

Set

Boolean, Integer, Real, Complex, Tuple, Matrix

Variant

Set

Set

Tuple

Boolean, Integer, Real, Complex, Set, Matrix

Variant

Tuple

Tuple

Boolean Matrix

Boolean, Integer, Real, Complex, Set, Tuple

Variant

Boolean Matrix

Boolean Matrix

Integer Matrix

Integer Matrix

Real Matrix

Real Matrix

Complex Matrix

Complex Matrix

Integer Matrix

Boolean, Integer, Real, Complex, Set, Tuple

Variant

Boolean Matrix, Integer Matrix

Integer Matrix

Real Matrix

Real Matrix

Complex Matrix

Complex Matrix

Real Matrix

Boolean, Integer, Real, Complex, Set, Tuple

Variant

Boolean Matrix, Integer Matrix, Real Matrix

Real Matrix

Complex Matrix

Complex Matrix

Complex Matrix

Boolean, Integer, Real, Complex, Set, Tuple

Variant

Boolean Matrix, Integer Matrix, Real Matrix, Complex Matrix

Complex Matrix

In short, for simple types and for matrix types:

$\mathbb{B} \rightarrow \mathbb{Z} \rightarrow \mathbb{R} \rightarrow \mathbb{C}$

Figure 81 provides examples of the variable type promotion process in action.

Figure 81 Variable Type Promotion Example

For simple variables and matrices, you can also force a variable to be a specific type using the $$\in$$ operator. To force the type of a simple variable, simply indicate that the variable is an element of one of the sets $$\mathbb{B}$$, $$\mathbb{Z}$$, $$\mathbb{R}$$, or $$\mathbb{C}$$.

The expressions below would set the variable $$a$$ to an integer and the variable $$b$$ to a complex value.

$a \in \mathbb{Z} \quad b \in \mathbb{C}$

To force the type of a matrix, you combine the use if $$\in$$ with the use of a subscript operator. The expressions below would set the variable $$A$$ to a boolean matrix and the variable $$B$$ to a real matrix.

$A _ { i, j } \in \mathbb{B} \quad B _ { i } \in \mathbb{R}$

When setting the type of a matrix, the index can be any variable, including variables not defined or used elsewhere. The value, name, and type of the variables will be ignored.

Lastly, for simple variable types, you can force the type directly in an assignment by placing the $$\in$$ operator on the left side of the assignment. The expression below would assign the value 5 to the variable $$c$$ while forcing $$c$$ to be a complex value.

$c \in \mathbb{C} = 5$

## Variant Types¶

In cases where the variable type has not been explicitly set using the $$\in$$ operator and the variable type can not be determined based on the rules described above, the variable will treated as a special variant type.

You will most often encounter the variant type when operating on the contents of sets and tuples.

The variant type can contain any of the values described in Variable Types and provides most of the capabilities supported by other variable types. Note that Aion will report an error if the value contained in the variant type does not support a requested operation.

Note that the variant type is slower than any other supported type so you will generally obtain better performance if the type is either explicitly set or can be determined based on variable usage.

Note

Currently some functions do not support the variant type. Inesonic, LLC will address this in future releases of Aion.

## Implicit Ordering, Sets, And Sorting¶

Aion understands the concept of implicit ordering with every available type of value although that ordering is not exposed through the relational operators for all types. Implicit ordering simply defines a deterministic relationship between any two values when stored in sets and other objects.

The Aion set classes are implemented as a specialized hash table. To thwart cryptographic attacks Aion injects a random seed, calculated once globally each time your algorithm or model is run. The use of implied ordering guarantees consistent behavior of Aion sets even with this additional entropy.

You can make use of implicit ordering to control how iteration occurs across sets and for the Aion pre-defined sorting functions ‘’Sort’’ and ‘’SortReverse’’.

Elements are sorted first by the type of value in the order:

• Boolean values

• Integer values

• Real values

• Complex values

• Sets

• Tuples

• Boolean matrices

• Integer matrices

• Real matrices

• Complex matrices

The order within each type is then determined by rules specific for each type. Table 16 documents the rules for each type.

Table 16 Implicit Ordering Rules For Each Type

Type

Ordering Rules

Boolean

$$\text{false} \prec \text{true}$$

Integer

In ascending order based on value.

Real

In ascending order based on value.

Complex

In ascending order by real value then by imaginary value.

Set

Number of members then by the implicit ordering by member in each set.

Tuple

Sorted based on the implicit order of each member then by the number of members where larger tuples will follow shorter tuples.

Matrices

By number of rows, then by number of columns, then by a raw byte level comparison of the internal data representation.

• Sets of integers and real values to be traversed in ascending order.

• Sets containing strings will be traversed in apparent alphabetical order of the strings.

• If the sets contain tuples of the same length and the first entry in the tuple is an integer or real value, the entries will be iterated, in order, based on the value of the first tuple entry. You can use implicit ordering to facilitate the development of discrete event simulations and similar types of models.

The example in Figure 82 demonstrates a simple discrete event simulation that relies on implicit ordering. The example in Figure 83 demonstrates how implicit ordering is used with the ‘’Sort’’ function.

Figure 82 A Simple Discrete Event Simulation Using Implied Ordering

Figure 83 A Simple Sorting Example

## Functions¶

You can use functions provided by Aion to perform many tasks. You can also create and use your own functions.

By default, functions will not display parenthesis around the parameter. If a function has several parameters or if the function is not the last math operator in a mathematical expression, parameters will be enabled. You can force parenthesis using the Operator Format Dialog or the Operator Dock.

You can add parameters to functions in the same way you add entries to sets and tuples, by separating the parameters with a comma. All functions must have at least one parameter value.

### Using Aion Standard Functions¶

Aion includes a wide range of standard functions you can use to perform many tasks. The Aion standard functions provide a wide range of capabilities.

Standard functions are often available in several forms indicated by different number and type of parameter. As an example, you can obtain a single random value in a normal distribution using either the $$\text{NormalVariate}\; \mu$$ function or the $$\text{NormalVariate}\left ( \mu, \sigma \right)$$ function. If you wish to populate a matrix of random values in a normal distribution, you would instead use either the $$\text{NormalVariate}\left ( n _ {rows }, n _ { columns }, \mu \right )$$ function or the $$\text{NormalVariate}\left ( n _ {rows }, n _ { columns }, \mu, \sigma \right )$$ function.

A complete list of standard functions can be found in the Function Reference.

### Creating User Defined Functions¶

You create a user defined function using the assignment operator, $$? = \; ?$$. The left hand of the assignment should be populated with a function operator. The right side should contain mathematical expression required to evaluate the function. The example below shows how you could write a sinc function.

$\begin{split}\text{sinc} x = \begin{cases} 1.0 & \text{if}\; x =\; 0 \\ \frac{\sin x}{x} & otherwise \end{cases}\end{split}$

With the above we could modify example Figure 74 to be as shown in Figure 84.

Figure 84 A More Complex Example Using A Function

You can use the compound operator, shown in Figure 75, to create functions that are extremely complex. Figure 85 demonstrates the use of the compound operator in a simple function.

Figure 85 Example Function Using A Compound Operator

You may note that we snuck a new operator in Figure 85. The ‘’therefore’’ operator, $$\therefore$$, can be used in conjunction with the compound operator to present or return a value calculated within a compound operator. You can use the $$\therefore$$ operator anywhere in a compound operator noting that the compound operator will stop further evaluation once the $$\therefore$$ operator is encountered.

The ‘’therefore’’ operator can be found on the Control Flow Dock, shown in Figure 63. You can also insert the ‘’therefore’’ operator using the menu option Insert | Control Flow | Therefore or by using the ‘’\therefore’’ backslash command.

By default, function parameters are assumed to be variant. You can enforce the type of a function parameter by including a $$\in$$ operator with each parameter as shown in Figure 86.

Figure 86 Setting Function Parameter Types

Alternately, you can enforce the type of a parameter by specifying the type within the function itself using the $$\in$$ operator as shown in Figure 87.

Figure 87 An Alternate Way To Set Function Parameter Types

You can define user defined functions anywhere in your algorithm or model, including after they’re used.

### Recursion¶

Recursion is a technique where a function references itself with different parameters. While all algorithms can be implemented without recursion, the use of recursion is often simpler and more intuitive.

Aion fully supports recursion as shown in Figure 88 which implements a common recursive sorting algorithm called the quick sort algorithm.

Figure 88 The Quick Sort Algorithm

## Variable Scope - Where Are My Variables Visible¶

Variable scope is a term used in computer science to indicate where a variable is valid and usable. Variables with the same name but defined within different scopes are treated as different variables.

While rules for scoping in traditional computer languages such as C++ can be extremely complex, the rules for variable scope within Aion are simple.

• Variables defined or referenced outside of a compound operator are accessible everywhere.

• Variables defined in function parameters are accessible within functions only.

• Variables defined in compound operators, such as the one shown in Figure 87, will be visible only within the compound operator. You can use the same variable name in different compound operators.

## Imports¶

Aion supports a feature called imports which allows one document to reference the contents of another document. The imports feature effectively concatenates multiple documents together into a single larger document where the documents you’ve imported as inserted in front of your document.

The imports feature is powerful, facilitating a number of addtional use cases for Aion:

• You can define widely used functions and constants in a separate document that can be shared by multiple algorithms or models.

• You can split large efforts into multiple pieces to facilitate work. Individual contributors can then build their own models that import their algorithm in separate documents to independently validate their work.

• You can use imports to develop your algorithm in one document, develop a second, third, fourth document to calculate coefficients or parameters, an additional document to test or model your algorithm in a larger system, and a final document to write reports documenting your results.

When compiling your algorithm or model, the imports for any given document are processed before the contents of the document. Once an imported document is processed, it will not be processed again even if it’s imported multiple times by different documents.

Note that documents can import other documents which can, in-turn, import additional documents. The compilation process will report an error if any imported document can-not be found.

If you are actively modifying a document that is being imported, the document as seen in the document view(s) will be used. This allows you to more easily work on complex algorithms or models that span many documents.

Figure 89 demonstrates the behavior of imports.

Figure 89 The Aion Import Algorithm

• Document ‘’A’’ imports documents ‘’B’’, ‘’C’’, and ‘’D’’. The compiler will first process the imports required by document ‘’A’’, in order, before processing the actual content of document ‘’A’’.

• The compiler will process document ‘’B’’.

• The compiler will then process document ‘’C’’; however, document ‘’C’’ has imports of it’s own, specifically document ‘’B’’, and document ‘’E’’.

• Document ‘’B’’ has already been processed so document ‘’C’’ ‘s requirement for document ‘’B’’ has been satisfied.

• Document ‘’E’’ has not been processed so the compiler will process document ‘’E’’ next.

• Once all the imports for document ‘’C’’ are processed, the content of document ‘’C’’ will be processed.

• The compiler will then process document ‘’D’’. Document ‘’D’’ has two imports of its own, documents ‘’E’’ and ‘’F’’.

• Document ‘’E’’ has already been processed for document ‘’C’’ so document ‘’D’’ ‘s requirement for document ‘’E’’ has already been satisfied.

• Document ‘’F’’ has not been processed so it will be processed next.

• Once all imports for document ‘’D’’ are processed, the content of document ‘’D’’ will be processed.

• Once all the imports for document ‘’A’’ are processed, the content of document ‘’A’’ will be processed.

You can add imports to a document using the File | Imports… menu option. Invoking this option will bring up the Imports Dialog, shown in Figure 90.

Figure 90 The Imports Dialog

You can add imports using the Add Imports button. You can re-order the imports by selecting an import and using the up/down arrows. You can remove imports by selecting an import and clicking Remove Import.

Each imported line will point to a file. You can tell Aion to track the location of each imported file based on either their absolute path or based on the location of the imported file relative to the file importing them.

You can use relative imports when a group of files are part of a common project that may be in different absolute locations on each person’s machine. You can use absolute imports when importing a file, such as a list of constants, that are widely used and have the same filepath independent of who is using Aion.