Creating Conditional Expressions

GoldSim provides a number of operators and functions which allow you to create conditional expressions. As used here, a conditional expression is an expression (or part of an expression) which evaluates to (produces) a condition (rather than a value). A condition has two states: True or False.

The following expressions are all conditional expressions:

 

A>B

A=B

A>5 AND A<10

!A

The operators that can be used in conditional expressions, along with their precedence, are summarized below:

 

Precedence Level

Type

Operators

Highest

parentheses

()

 

logical NOT

!, NOT

 

relational

>, <, >=, <=

 

equality, inequality

= (or ==), <>

 

logical AND

&&, AND

Lowest

logical OR

||, OR

Conditional expressions are very useful, because they allow you to add if…then logic to your model. This can be accomplished by using GoldSim's if function in an expression.  For example, the expression

if(ETime>10 yr and ETime<20 yr then 33 else 44)

would be interpreted as "If the elapsed time is between 10 years and 20 years, the value is equal to 33, otherwise it is equal to 44".

Complex if…then logic can be defined by nesting this function, or by using a Selector element. Conditional expressions are also of great use when modeling discrete events and consequences.

     Warning: The equality operator (= or ==) should be used with caution. In particular, you should generally not use this operator when comparing calculated values in your model (which could be affected by small round-off errors). Note that both ETime and Time are calculated values (since they are always represented internally in seconds) and hence they are also potentially susceptible to small roundoff errors if used in conjunction with the equality operator.

   Note: Tool-tips for conditional outputs by default display true or false. You can specify what is displayed (e.g., on/off, yes/no, etc.) by editing the “Show condition result outputs as” field in the Results tab of the Options dialog (accessed from the main menu via Model|Options…)

Related Topics…

Learn more about: