An expression is a sequence of operators and operands that can be either vectors or scalars. A scalar is a vector with a length of one. It is possible, using round brackets, to nest sub-expressions. Expressions are evaluated according to a series of conversion, grouping, associativity and precedence rules depending on the operator used, the presence of round brackets and the type of operands.
Numeric values
Numerical values should be written with scientific notation (a numerical value followed by an integer exponent such as 1.234e-5) or using the following scale suffixes:
Suffix | Scale | Description |
---|---|---|
f, F | 10^{-15} | femto |
p, P | 10^{-12} | pico |
n, N | 10^{-9} | nano |
u, U, µ | 10^{-6} | micro |
MIL | 25.4*10^{-6} | mil |
m, M | 10^{-3} | milli |
k, K | 10^{3} | kilo |
MEG | 10^{6} | mega |
g, G | 10^{9} | giga |
t, T | 10^{12} | tera |
Characters that follow a number and do not represent a scale suffix and characters that follow a scale suffix are ignored. So the numbers: 1000, 1000.0, 1000Hz, 1e3, 1.0e3, 1KHz, and 1K all represent the same value.
Warning: |
---|
All suffixes can be entered either in lower case or upper case. Use MEG to indicate 10^{6}. The suffix m or M is always interpreted as milli (10^{-3}). Scale suffixes must be entered immediately after the number, spaces between the number and scale suffixes are not allowed. |
Hexadecimal and binary numbers
If a numeric value starts with the letters 0x or 0X, it is hexadecimal. If it starts with the letters 0b or 0B it is binary. Integer numeric values are limited to 32 bits.
Vectors
Vector names can be specified in either upper or lower case. Square brackets are used to index the elements of a vector. The notation expr[n] denotes the umpteenth element of the vector expr. For multidimensional vectors, the previous notation returns a vector of dimension dim-1 while the notation expr[m][n] returns the umpteenth element of the umpteenth subvector. To extract a sequence of elements from a vector you can use the notation expr[lower, upper] which creates a vector with only the elements between the lower and upper index.
The names of the vectors refer to the current document. To specify a vector of any document you must also specify the handle of the document separating it from the name of the vector with a dot:
document_handle.vector_name
For example:
H10AD56D4A9451745.V(1)
specifies the vector V(1) of the document whose handler is H10AD56D4A9451745.
Tip: |
---|
The document handler is displayed on the document properties tab. |
Operators
Operators are symbols that specify which operation must be performed on the operands. They perform some operations on the vectors contained in an expression.
Arithmetic Operators
Arithmetic operators allow you to perform basic arithmetic operations.
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
\ | Integer Division |
% | Remainder of integer division |
** | Power |
Comma Operator
The comma operator is the sequential evaluation operator and causes the program to examine the first expression preceding the comma before passing to the examination of the second expression following it.
Quote Operator
This operator separates the two elements of a complex number: x'y equals x+j(y). Use the operator to pass complex values to the functions.
Conditional Operators
A conditional expression is in the form:
conditional_expression ? expression1 : expression2
the conditional expression evaluates expression_condition, if its value is different from zero (true condition), returns the value of expression1. Otherwise it returns the value of expression2.
Semicolon Operator
The expression to be evaluated can be single or multiple. The semicolon operator separates the single expressions of a multiple expression.
For example, the following is a single expression:
P1 * sin(P0) + P2 / 2
while the following is a multiple expression:
a = P1 * sin(P0); b = P2 / 2; a + b
In a multiple expression it is allowed to assign any intermediate results to local variables (related to the expression). The final result of a multiple expression is that of the last evaluated expression.
Assignment operators
These operators evaluate the expression on their right and assign the result to the vector specified on their left. The effect of the assignment operator has local validity to the expression.
Operator | Description |
---|---|
= | Assignment |
+= | Addition assignment |
-= | Subtraction assignment |
*= | Multiplication assignment |
/= | Division assignment |
\= | Integer division assignment |
%= | Modulo assignment |
Relational operators
These operators produce a result of 0 if the relationship is false or 1 if the relationship is true.
Operator | Description |
---|---|
< | Less than. Returns 1 if the value of the first operand is less than the second otherwise returns zero. |
> | Greater than. Returns 1 if the value of the first operand is greater than the second otherwise returns zero. |
<= | Less than or equal to. Returns 1 if the value of the first operand is less than or equal to the second otherwise returns zero. |
>= | Greater than or equal to . Returns 1 if the value of the first operand is greater than or equal to the second otherwise returns zero. |
== | Equal to. Returns 1 if the value of the operands coincides otherwise returns zero. |
!= | Not equal to. Returns 1 if the operands have different values otherwise returns zero. |
<> | Not equal to. Returns 1 if the operands have different values otherwise returns zero. |
Logical operators
These operators produce a result of 0 or 1. Operands are worth 1 if they are different from zero otherwise they are worth zero.
Operator | Description |
---|---|
! | Logical negation (NOT). Produces the value 0 if the operand is different from zero and the value 1 if the operand is zero. |
&& | Logical AND. Produces the value 1 if both operands have values different from zero otherwise the result is zero. |
^^ | Logical XOR. Produces the value 1 if only one of the operands has a value different from zero otherwise the result is zero. |
|| | Logical OR. Produces the value 1 if at least one of the operands has a value different from zero otherwise the result is zero. |
Digital Operators
The following operators produce a result equal to: VLOW, VHIGH or VUNDEF. The value of the operands is determined by the variables VIL and VIH as follows:
HIGH for v>=VIH
LOW for v<=VIL
UNDEF for VIL<v<VIH
If one of the operands is worth UNDEF, the result is VUNDEF for all operators.
Operator | Description |
---|---|
NOT | Logical NOT. Produces the VLOW value if the operand is HIGH and the VHIGH value if the operand is LOW. |
AND | Logical AND. Produces the VHIGH value if both operands have HIGH value otherwise the result is VLOW. |
NAND | Logical NAND. Produces the VLOW value if both operands have HIGH value otherwise the result is VHIGH. |
XOR | Logical XOR. Produces VHIGH only if only one of the operands is HIGH otherwise the result is VLOW. |
OR | Logical OR. Produces VLOW if both operands have LOW value otherwise the result is VHIGH. |
NOR | Logical NOR. Produces VHIGH if both operands have LOW value otherwise the result is VLOW. |
Tip: |
---|
The values: VIL,VIH,VLOW,VHIGH and VUNDEF can be set in the tab Constants in the Job Properties dialog. The dialog can be activated by selecting the Settings » Job Properties command. or via the key combination CTRL+ALT+J. |
Bitwise operators
These operators result in a 32-bit integer number. The operands are converted to 32-bit integers and then the operator is applied.
Operator | Description |
---|---|
~ | Bitwise NOT. Produces the bit-by-bit complement of its operand. |
& | Bitwise AND. Compares each bit of the first operand with the corresponding bit of the second. If both bits are at 1 it sets the result bit to 1 otherwise it sets it to 0. |
^ | Bitwise XOR. Compares each bit of the first operand with the corresponding bit of the second. If only one of the bits is 1, set the result bit to 1, otherwise set it to 0. |
| | Bitwise OR. Compares each bit of the first operand with the corresponding bit of the second. If at least one of the bits is 1, set the result bit to 1, otherwise set it to 0. |
Constants
The following constants may be used in expressions:
Name | Description |
---|---|
BOLTZ | Boltzmann constant. |
c | Light speed. |
e | The constant e, basis of the natural logarithm. |
ECHARGE | The charge of an electron. |
FALSE | The value 0. |
i | Imaginary constant (0, 1). |
KELVIN | Absolute zero. -273.15 °C. |
LN10 | The natural logarithm of 10. |
LN2 | The natural logarithm of 2. |
LOG10E | The logarithm in base 10 of e. |
LOG2E | The logarithm in base 2 of e. |
NULL | The value 0. |
PI | The constant pi. |
PLANCK | Planck constant. |
SQRT2 | The square root of 2. |
TRUE | The value 1. |
TWOPI | The constant pi*2. |
Functions
The following table shows the mathematical functions that can be used. The functions can return a vector or a scalar.
When a real value is required and a complex vector is provided, the module of the complex vector is used.
The subject of trigonometric functions is in radians.
Name | Description |
---|---|
mag(v) magnitude(v) |
The result is a Real vector with each element containing the magnitude of each element in the Complex vector v. |
ph(v) phase(v) |
The result is a Real vector with each element containing the phase of each element in the Complex vector v. The returned value is in degrees. |
j(v) | i*v |
re(v) real(v) |
The real component of the vector v. |
im(v) imag(v) |
The imaginary part of vector v. |
db(v) | 20*log10(mag(v)). |
log(v) log10(v) |
The logarithm in base 10 of v. |
ln(v) | The natural logarithm of v. |
exp(v) | The exponential e^{v}. |
abs(v) | The absolute value of v. |
sqrt(v) | The square root of v. |
sin(v) | The sine of v. |
cos(v) | The cosine of v. |
tan(v) | The tangent of v. |
asin(v) | The arcsine of v. |
acos(v) | The arccosine of v. |
atan(v) | The inverse tangent of v. |
sinh(v) | The hyperbolic sine of v. |
cosh(v) | The hyperbolic cosine of v. |
tanh(v) | The hyperbolic tangent of v. |
norm(v,<i>) | Normalizes the vector. The i parameter is optional. If not provided, the vector is transformed so that the value of the largest element is equal to 1. If the parameter i is provided, the vector is normalized according to the i-th element of the vector. This function considers the module of the elements of the vector. |
rnd(v) | Transforms vector elements into a random integer value between 0 and the element value. |
pos(v) | To all the elements of the vector with the value greater than zero assigns the value 1 to all the others assigns the value 0. |
mean(v) | The result is a scalar (a length 1 vector) that is the mean of the elements of the vector. |
sum(v) | The result is a scalar (a length 1 vector) that is the sum of the elements of the vector. |
vecmax(v) | The result is a scalar (a length 1 vector) that is the maximum value in a vector. For complex vectors, the value returned is the maximum magnitude value. |
vecmin(v) | The result is a scalar (a length 1 vector) that is the minimum value in a vector. For complex vectors, the value returned is the minimum magnitude value. |
conj(v) | Returns the complex conjugate. |
rad(v) | Converts from degrees to radians. |
deg(v) | Converts from radians to degrees. |
vector(n) | Returns a vector of length n with integer values from 0 to n-1. If n is a vector, the value of the first element is considered. |
unitvec(v) | Returns a vector with all elements equal to 1. The length of the vector is equal to the value of the first element of the vector. If vector was complex, the length is mag(v[0]). |
length(v) | Returns a scalar with the length of the vector. |
interpolate(v) | The result of interpolating the vector onto the scale of the current document. The degree of interpolation is defined by the option Polynomial degree for interpolation function. |
deriv(v) | Calculates the derivative of the vector. This uses numeric differentiation by interpolating a polynomial and may not produce satisfactory results (particularly with iterated differentiation). The implementation only calculates the derivative with respect to the real component of that vector's scale. The polynomial degree is defined by the option Polynomial degree for derivation function. |
Four(v,f) | Calculates the spectral components of the vector v at frequency f relative to the vector set as the scale in the current document (normally the vector time result of a transient analysis). The vector v is interpolated on a scale corresponding to a period of the fundamental frequency in the interval: final_time-1/f and final_time. The interpolation function is regulated by the options: Polynomial degree for interpolation function and Number of interpolated points for Fourier analysis. The number of calculated harmonics is specified by the option Number of harmonics for Fourier analysis. |
Freq(v) | Calculates the frequencies of the harmonics related to a Fourier analysis. The number of harmonics is specified by the option; Number of harmonics for Fourier analysis. |
Tip: |
---|
The options can be set in the tab Vectors in the Application properties dialog box. The dialog can be activated by selecting the Settings » Application Properties command or via the key combination CTRL+ALT+A. |
User-defined functions and constants
You can define functions and constants to be used in expressions. You can define either simple functions represented by an expression or complex functions defined by a macro procedure. For more information on external functions, see Define functions and constants for expressions.