User Tools

Site Tools


Expressions

What are Expressions?

An expression in EASA is a mathematical or logical statement that involves a combination of:

  • Numbers
  • Object names
  • Mathematical operators
  • Logical operators
  • Constants

An example of an expression is as follows:

(5.0* W-t/2.0)^2

where first the object value of W will be multiplied by five, then one-half of the value t will be subtracted from the first term, and finally, the previous result will be raised to the power two.


Object References

The Builder allows the use of object names within expressions. When the name of an object is entered as part of an expression it becomes an object reference, the value of the object referred to will be substituted into the expression just before the expression is evaluated while the EASAP is running.


Valid Object Names

To be used in expressions, object names must adhere to a few rules. Names must:

  • Consist of only alphabetic letters (a-z) and numbers (0-9)
  • Not be the same as an operator or constant name
  • Not have digits anywhere except at the end
  • Not contain the name of an operator or special constant

Valid object name examples: x, xx, aVariable, var1, var2

Invalid object name examples: 3x, my2variable

Use of object names is case sensitive, be consistent in object names to minimize errors.

Tip: As a rule, it is a good idea to name all your objects using the rules for expression use because you will not always be able to anticipate when you’ll use an object in an expression.


Operators

Operators are used in expressions to perform mathematical or logical operations. For mathematical operations, operators exist to allow the basics, like addition, subtraction, multiplication, and division, but others exist for performing more advanced operations, like trigonometric functions, logarithmic functions, etc.

The table below contains the set of mathematical operators available for use in expressions.

Operators Function
+, -, * , /, ^Add, Subtract, Multiply, Divide, Raise to power of
%Modulo or remainder, e.g. 7%3 returns 1
sqrt(..)Square root
abs(..)Return absolute value
round(..)Round to closest integer
fpart(..)Returns decimal value of argument, e.g. fpart(2.345) returns 0.345
ceil(..)Returns next integer greater than or equal to argument
floor(..)Returns next integer less than or equal to argument
sin(..), cos(..), tan(..), cotan(..)Trigonometric functions: Arguments within parentheses have units of radians
asin(..), acos(..), atan(..), acotan(..)Trigonometric functions: Angles returned from function have units of radians
sinh(..), cosh(..), tanh(..)Hyperbolic functions
ln(..), exp(..), [base]log(..)Logarithmic functions
fac(..)Factorial of integer argument, n, i.e. n *(n-1)*(n-2)*…*1
sfac(..)Semi-factorial of integer argument, n, i.e. n * (n -2)*(n-4)*…*4*2 if n is even, or n *(n-2)*(n-4)*…*3*1 if n is odd

Logical operators can be used to create expressions that will produce different values depending on a logical condition. The result of an expression using a logical operator will be 0.0 for false or 1.0 for true. Complete logical expressions can be nested within a larger mathematical expression to allow the value of the overall expression to be a function of one or many logical conditions. The table below contains the set of logical operators available for use in expressions.

Operators Function
==, !=Equal to, Not equal to
&&, ||And, Or
>, <Greater than, Less than
>=, <=Greater than or equal to, Less than or equal to
!Not (Reverts true to false & false to true)

Operator Precedence

This list shows the order in which operators are evaluated within an expression.

Parentheses may be used to override the order of evaluation.

  1. !
  2. sin, cos, tan, ln, exp , sqrt, abs, round… etc.
  3. *, /,%
  4. log
  5. +, -
  6. >, >=, <, <=
  7. ==, !=
  8. ||
  9. &&

Special Constants

EASA’s Expression Language also contains a few common constants for use in expressions. The constants are provided in the table below.

Constant Value
pi3.14159265…
euler2.7182818…
true1.0
false0.0

Constants and object references in expressions are case-sensitive→ constants must be lower case.


Mathematical Expressions

Below are a number of mathematical expression examples using hypothetical SCALAR references.

Consider the REALBOX's:

  • A = 1.0
  • B = 2.0
  • C = 3.0
Expression Value
2*(A + B)^2 - C2*(9) - 3 = 15
cos(B*pi)1.0
(A>=2)*B + (A<2)*C0.0*2 + 1.0*3 = 3
10log(2*(B+C))1.0 (note: 10log is 'log base ten')

Logical Expressions

A logical expression evaluates to a true or false value. Below are some examples using hypothetical object references and initial values:

Expression Value
C==“choice2”false (0.0)
(C==“choice1”) && (A<3)true (1.0)
(A>3)||(A<1)false (0.0)
!((B==“TRUE”)&&(A==1))true (1.0)

Characters and text strings have different syntax for equality checking equality is different for than for numbers. For text/characters:

  • An explicit value on the right-hand side of the equality operator must be placed within double quotes,
    • A==“choice1”

For numbers:

  • Double quotes are not necessary
    • A==3

Due to the reserved use of double-quotes, a string equality test will fail when the text actually contains double quotes. In this case use a STRING or REPEATED STRING.

Usually it only makes sense to use string constants or string variables for equality comparisons. The table below illustrates the behavior if they are used in more general expressions.

Expression Value
C<choice2false (0.0)
C>choice2false (0.0)
2*”choice2NaN (not a number)
2* CNaN (not a number)

Combined Logical and Mathematical Expressions

Since the possible values of logical expressions of TRUE and FALSE have numerical values of 1.0 and 0.0, respectively, logical expressions can be mixed with mathematical expressions to create a combined expression. Some combined expression examples are contained within the table below. The example expressions will make use of object references using the object names: A, B, C and D, where A = 2.0, B = 5.0, C = choice1 (CHOICE LIST) and D = 3 (INTEGERBOX).

Expression Value
(C==“choice1”)*A + (C==“choice2”)*B(1.0)*2.0 + (0.0)*5.0 = 2.0
(C!=“choice2”)*B(1.0)*5.0 = 5.0
(D>4)*(A+B) + (D⇐4)*(B-A)(0.0)*(7.0) + (1.0)*(3.0) = 3.0

Use of Expressions

Expressions are intended to be used both by Authors in the generation of EASAPs and by Users in the EASAP itself as a substitute for entering numbers.


Object Parameter Values

As an Author, you will use expressions when setting the values of object parameters. Common uses for parameters include:

  • Set Upper Bound: and Lower Bound: values as functions of other object values
  • Using logical expressions for Show if: and Enable if: parameters

Many more examples can be found at the Diagramming and Coupling To Software Applications pages. When an expression is typed into a Parameter Value box, error checking is performed to ensure that the expression is valid. If the expression is deemed to be valid, it will be colored blue. If deemed invalid, it will be colored red. In some cases, the validity of an expression cannot be determined definitively, and in such cases, the expression will be colored black. In a comma separated list of expressions, only the invalid expressions in the list will be colored red, the rest will be blue or black.

Before saving an EASAP or checking an EASAP’s user interface using the Toggle to Preview button, all invalid expressions must be fixed or a pop-up error message will appear.


Object Name Auto-Completion

A typical mistake that can be made when entering an expression is to type in an incorrect object name. To help with this issue, the EASAP Builder will display a drop-down list of available object names that can be selected as you type in your expressions. The list of objects will be filtered by the characters you type. An example of the object name auto-completion dropdown is shown below.

The list of available objects shown in the auto-completion dropdown is derived from the global list of objects. It is therefore exhaustive and may contain objects that are not appropriate selections. For instance, it might contain LIST when only a SCALAR is valid.



Page Tools