Next Previous Contents

## 5. Operators

## 5.1 operators

The Tela operators, from lower to higher precedence:

> `

>     Operator       Association   Meaning
>     --------       -----------   -------
>     :              -             Range creation, ex: 1:10, -5:2.3:7
>     ||             left          Logical OR, similar to C
>     &&             left          Logical AND, similar to C
>     !              right         Logical NOT
>     ==, !=         left          Equality and nonequality
>     >, >=, <, <=   left          Comparisons
>     +, -           left          Addition and subtraction
>     *, /, mod      left          Multiplication, real division, modulus
>     **             left          Matrix multiplication
>     -, +           right         Unary minus and plus
>     ^              right         Raising to power

> `

The special symbols '++' and '--' are not actually operators but statements. See help ++.

See also the help for each individual operators: :, ||, &&, ==, comparison, +, -, *, /, mod, **, power, !. See also: special (type help special).

## 5.2 special

> `

>     The Tela special characters
>     ---------------------------

> `

> `

>     Char(s)   Meanings, usages
>     -------   ----------------
>     ( )       Parentheses, expression grouping       (a+b)*(a-c)
>     [ ]       Brackets, array indexing               A[i,2:N-1]
>               Function call                          [a,b] = f(x,y,z);
>               Function definition                    function [a,b] = f(x,y,z) {};
>     <[ ]>     Mapped array indexing                  A<[ivec,jvec]>
>     #( )      Array constructor                      #(1,2; 3,4)
>     { }       Statement grouping                     {i++; j++};
>     ++        Incrementation                         i++;
>     --        Decrementation                         i--;
>     ;         Statement separator                    {i++; j++};
>               Separator in for statement             for (i=1; i<=imax; i++) {};
>               Separator of obligatory/optional args  function y=f(x; y) {};
>               Separator in array constructor         #(1,2; 3,4)
>     ,         Separator of parameters                x = f(x,y) + 3;
>               Separator in array constructor         #(1,2; 3,4)

> `

More information available: [, <[, ++.

See also: operators.

## 5.3 mod

Reserved word: mod

a mod b gives the modulus, a modulo b. a and b may be also complex; in that case the modulus is taken separately for the real and imaginary parts. The modulus operator has the same precedence as the pointwise multiplication '*' and real division '/'.

See also: *, /, operators

## 5.4 +

Special symbol: +

a + b is the normal addition operator. If both a and b are scalars, the result is a scalar. If one of them is array, the result is an array of the same size. If both are arrays, their dimensions must agree and the result is an array.

Unary plus (+a) returns 'a' as is.

See also: -, ++, operators

## 5.5 *

Special symbol: *

a * b is the normal (pointwise) multiplication operator. If both a and b are scalars, the result is a scalar. If one of them is array, the result is an array of the same size. If both are arrays, their dimensions must agree and the result is an array.

See also: **, operators

## 5.6 /

Special symbol: /

a / b is the normal (pointwise) division operator. If both a and b are scalars, the result is a scalar. If one of them is array, the result is an array of the same size. If both are arrays, their dimensions must agree and the result is an array.

See also: *, mod, operators

## 5.7 -

Special symbol: -

a - b is the subtraction operator. If both a and b are scalars, the result is a scalar. If one of them is array, the result is an array of the same size. If both are arrays, their dimensions must agree and the result is an array.

Unary minus (-a) is the negative of a.

See also: +, ++, operators

## 5.8 **

Special symbol: **

T**U is the generalized matrix product of T and U. If T has components T[i,..,j,k] and U has components U[a,b,c,...], then (T**U)[i,..,j,b,c,...] = sum(T[i,..,j,k]*U[k,b,c,...],k=1:kmax), i.e. it is a contraction of tensors T and U with respect to the innermost dimensions, which must agree. In case of matrices ** thus gives the ordinary matrix product. If one or both operands are scalars, T**U is the same as T*U (pointwise multiplication).

See also: *, operators

## 5.9 : void range

Special symbol: ':'

a:step:b creates a vector of values #(a,a+step,a+2*step,...) such that all elements are less or equal than b. a:b creates a range using unit step. A lone ':' stands for the Void value. When used as an array subscript, it stands for the entire range, for example A[:,3] refers to the third column of matrix A.

See also: operators

## 5.10 ++, --

Special symbols: ++, --

The statement a++ increments a by one. The statement a-- decrements a by one. Notice that these are not operators but statements in Tela.

See also: +

## 5.11 or ||

Special symbol: ||

a || b is the logical OR of a and b. The operands must be integer valued. For array operand(s), the OR operation is applied componentwise.

See also: &&, operators

## 5.12 and &&

Special symbol: &&

a && b is the logical AND of a and b. The operands must be integer valued. For array operand(s), the AND operation is applied componentwise.

See also: ||, operators

## 5.13 not !

Special symbol: !, operators (type help operators)

!a is the logical NOT of a. The operand must be integer valued. If the operand is an integer array, the result is integer array also, otherwise the result is integer scalar.

On command prompt, '!' executes an operating system command, if it is the first character on line. In t-files this extra meaning of '!' does not exist, but you must use the 'system' function explicitly.

## 5.14 equal, ==, notequal, !=

Special symbols: ==, !=

a == b is the equality test operator. If both operands are scalars, the result is either 1 or 0. If one operand is numeric array and the other one is scalar, the result is an integer array of 0's and 1's of the same size as the array operand. If both operands are arrays of the same size, the result is again an integer array of 0's and 1's. But if the operands are arrays of different size, the result is 0 (integer scalar). Strings are handled as integer arrays of their ASCII codes, according to their internal representation. For other types of objects, for example functions, the result is 1 only if the objects are exactly equal.

a != b is the 'not-equal' operator. It is analogous to '=='.

Unlike order-related comparison operators (<, >, <=, >=), the '==' and '!=' operators never generate an error message for any operands.

See also: comparison, operators

## 5.15 comparison: lt, gt, le, ge

Special symbols: <, >, <=, >=

These operators obviously test whether the first operand is less than, greater than, less or equal than, or greater or equal than the second operand. If both operands are scalars, the result is scalar (1 or 0). If one operand is array and the other one is scalar, the result is an integer array of 0's and 1's. If both operands are arrays, their dimensions must agree. The result is then again an integer array of 0's and 1's.

The operands may not be nonnumeric, nor they may include complex numbers.

See also: ==, operators

## 5.16 power

Special symbol: ^

a ^ b is a-raised-to-the-power-b. If both a and b are scalars, the result is a scalar. If one of them is array, the result is an array of the same size. If both are arrays, their dimensions must agree and the result is an array.

See also: *, **, operators

## 5.18 Mapped indexing

> `

>     Special symbols: <[, ]>

>     Besides ordinary array indexing, accomplished with [ ], you can use
>     mapped indexing using <[ ]>. Assume A is an array with N = rank(A).
>     Assume that I1...IN are integer arrays, and that their dimensions
>     mutually agree. Then A<[I1,I2,...,IN]> is a collection of A's
>     components, and its size is equal to the size of each Ik.

>     Unlike ordinary array indexing, in mapped indexing the size of the
>     result is not determined by A, but the size of the index
>     arrays. Mapped indexing can not easily be returned to ordinary
>     indexing, hence it is included as a separate operation in Tela.

> `

See also: [.

Next Previous Contents