Entering and Editing Expressions in Input Fields

When you place your cursor into an input field and begin to type, you will notice that GoldSim color-codes the text as you type. Red underlined text indicates that GoldSim cannot interpret that portion of the expression (e.g., due to incorrect syntax).  Once the item becomes valid, it will no longer be shown in red and underlined.  If you leave an input field that is invalid (e.g., change the focus to another field), the entire field will be highlighted in pink.

   Note: In addition to displaying errors and color-coding text as you type, as you enter characters into an input field, GoldSim automatically suggests the names of existing outputs (that are consistent with those characters) that you may want to link to at the bottom of the input field.

When you first place the focus in (i.e., click into) an input field (or if you stop typing within an input field), a tool-tip is displayed. If the expression is invalid, the tool-tip will explain why; if the expression is valid, it will display its current value. If you start typing (or move the focus to another field), the tool-tip will disappear. If you stop typing, the tool-tip will reappear. You can also view the tool-tip for an input field by simply holding the cursor over the field (while the focus is elsewhere). The tool-tip disappears when you move the cursor away.

The table below summarizes the mathematical and relational operators that are supported by GoldSim for use within expressions in input fields, along with their precedence:

 

Precedence

Type

Operators

Highest

parentheses

()

 

exponentiation

**,^

 

unary minus

-

 

multiplication, division

*, /

 

addition, subtraction

+, -

 

relational test

>, <, >=, <=

Lowest

equality test

=, ==, <>,!=

The precedence of the operators determines the manner in which expressions are interpreted and evaluated. For example, in the expression:

4 + 3 * 6

3 times 6 would be evaluated first, then 4 would be added to that quantity (resulting in a value of 22) because the “*” operator has a higher precedence than “+” operator. However, (4 + 3) * 6 would result in a different value (42) because the parentheses have higher precedence than the “*” operator.

   Warning: The precedence of the unary minus as listed in the table above (lower precedence than exponentiation) only applies when it precedes a variable (as opposed to a number).  That is, the expression  -X**2, where X = 3 would be interpreted as -9.  However, if a unary minus directly precedes a number, it is always considered to be part of the number itself, and hence the operator has a higher precedence that exponentiation.  That is, the expression     -3**2 would be interpreted as 9.

   Note: The equality (= = and =) and inequality (<> and !=) operators assume that two values are identical if they are the same to 12 significant figures.  Because double-precision arithmetic (used in the GoldSim code) has a precision of about 15 significant figures, random roundoff errors should generally not become significant. However, there is a caveat to this rule: if GoldSim compares a non-zero value to a zero value, they are never treated as identical, even if the non-zero value is extremely small.  For example, if A was exactly 1 and B was different from 1 at the 14th significant figure, then A=B would be true, but A-B=0 would be false.

In addition to the operators listed above, GoldSim also provides a number of built-in functions (e.g., sin, cos, log) and constants (e.g., π, e, the gravitational constant, Avogadro’s number) which can be used to build expressions.  GoldSim also provides three logical operators (And, Or, Not) which only operate on conditions.

When creating expressions, spaces are ignored. For example, the expressions “4*5” and “4   *   5” would both be interpreted as 20. You should feel free to add spaces to your expressions in order to improve their readability. The two exceptions to this rule are 1) when you are adding unit strings to expressions (e.g., m/sec, $/day) spaces within the unit string are not allowed; and 2) when you are using a unary minus with a number (e.g., -3C), spaces between the minus sign and the number are not allowed.

GoldSim color-codes expressions to make them easier to read. The colors used are:

 

 

Black:

 Numbers and functions

 

Green:

 Output names (links) and functions

 

Gray:

 Operators

 

Blue:

 Units

 

Underlined and Red:

 Invalid

 

Light Gray

 Not yet evaluated

In addition, if you use nested sets of parentheses in an expression, when you click inside the expression, GoldSim will highlight the nearest matching pair.

If the expression that you type into an input field is longer than the field in the dialog, the field will automatically expand when it has the focus such that the entire expression can be viewed.

   Note: The input field for an Expression element is larger than for other elements (i.e., it is always expanded and hence accommodates several rows without requiring the focus).

Related Topics…

Learn more about: