Expression evaluation: Difference between revisions

From Knowledge Base
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 99: Line 99:
!Description
!Description
!Example
!Example
|-
|<code>equalText(a, b)</code>
|Returns whether ''a'' and ''b'' are the same string
|<code>equalText("OK", "ok")</code> → <code>false</code>
|-
|-
|<code>abs(x)</code>
|<code>abs(x)</code>
Line 190: Line 194:
|<code>acoth</code>
|<code>acoth</code>
|}
|}
All trigonometric functions operate in radians.
All trigonometric functions operate in radians. For input in degrees, you can convert the argument using <code>unit(x, 'deg')</code>.
 
For example: <code>sin(unit(60, 'deg')) = 0.866... = sin(pi / 3)</code>.


=== Constants ===
=== Constants ===
Line 239: Line 245:


* <code>$B2 < 0.1</code>
* <code>$B2 < 0.1</code>
* <code>$$C3 != "OK"</code>
* <code>not equalText($$C3, "OK")</code>
* <code>$$6 != "OK" or $6 >= 0.012</code>
* <code>not equalText($$6, "OK") or $6 >= 0.012</code>
* <code>($$A1 == "OK" and $$A2 == "OK") or $$A3 == "NG"</code>
* <code>(equalText($$A1, "OK") and equalText($$A2, "OK")) or equalText($$A3, "NG")</code>


[[Category:Inspection User Guid]]
[[Category:Inspection User Guid]]

Latest revision as of 11:15, 26 October 2023

Expression definition

Feature references

An expression may reference any feature inspection so far in the workflow for the current part.

  • To reference the entered value of a numeric feature (or the numeric field of a categorical feature), use $x, where x is the balloon label of the feature.
  • To reference the selected value of a categorical feature (even if it has a numeric value as well), use $$x, where x is the balloon label of the feature.
  • Features without balloon labels cannot be referenced.

Logical operations

The following logical operations are supported:
Operator Evaluates to true only when... Example
== Both arguments are equal 1 == 2false
!= Both arguments are not equal 1 != 2true
< Left argument is smaller 1 < 2true
> Right argument is smaller 1 > 2false
<= Left argument is smaller or equal 1 <= 2true
>= Right argument is smaller or equal 1 >= 2false
or Either input is true (1 > 2) or (4 > 3)true
and Both inputs are true (1 > 2) and (2 >= 3)false
xor Exactly one input is true true xor truefalse
not The input is false not truefalse

Logical operations can be infinitely nested. For example, ((1 == 1) and (1 < 2)) or not ((3 > 4) and (2 > 1)) evaluates to true.

Mathematical operations

The following mathematical operations are supported:
Operator Description Example
+ Addition 1 + 23
- Subtraction 2 - 0.51.5
* Multiplication 2 * 36
/ Division 9 / 24.5
^ Exponentiation 4 ^ 216
% Remainder 12 % 52
! Factorial 4!24

Functions

The following functions are supported:
Name Description Example
equalText(a, b) Returns whether a and b are the same string equalText("OK", "ok")false
abs(x) Returns the absolute value of x abs(-3)3
round(x) Round x to the nearest integer round(1.5)2
ceil(x) Rounds x up ceil(1.1)2
floor(x) Rounds x down ceil(2.9)2
log(x) Computes the logarithm base e of x log(5)1.60944...
log(x, b) Computes the logarithm base b of x log(5, 10)0.69897...
sqrt(x) Returns the square root of x sqrt(64)8
min(...) Returns the smallest of its arguments min(1, 2, 3)1
max(...) Returns the largest of its arguments max(1, 2, 3)3
mean(...) Returns the average of its arguments mean(1, 5, 10)2.666...
median(...) Returns the middle of its arguments.

If there are an even number of arguments, it returns the average of the middle two.

median(2, 5, 7)5
std(...) Returns the standard deviation of its arguments. mode(1, 5, 13, 20)8
sum(...) Returns the sum of its arguments. sum(1, 2, 3, 4)10
The following trigonometric functions are available:
Trigonometric function Hyperbolic function Inverse function Inverse hyperbolic function
sin sinh asin asinh
cos cosh acos acosh
tan tanh atan atanh
sec sech asec asech
csc csch acsc acsch
cot coth acot acoth

All trigonometric functions operate in radians. For input in degrees, you can convert the argument using unit(x, 'deg').

For example: sin(unit(60, 'deg')) = 0.866... = sin(pi / 3).

Constants

The following constants are predefined:
Name Description Value
pi or PI Pi (π) 3.141592653589793
e or E Euler's number (e) 2.718281828459045
phi Golden ratio (φ) 1.618033988749895

Usage

Inspection calculations

During inspection, you may enter mathematical expressions following the rules outlined above and the evaluated (calculated) result will be entered for the feature's value. For example, you can enter 0.6712 - 0.431 into the measurement value field and the feature will be measured as 0.2402 upon leaving the input field.

Focusing back into the input field before submitting the inspection will reveal the expression as it was originally entered for editing. The raw expressions are discarded upon submitting the inspection.

You can also use the values entered for features that have already been measured in your expressions. For example, to enter a value that is equal to twice the value of the feature with balloon label F3, you can enter $F3 * 2.

Clicking the $ button or pressing Ctrl + Space while focused in a measurement field will open a list of features that can be referenced. If the button or menu is not visible, no features can be referenced. Features can only be referenced if they meet both of the following conditions:

  • The feature has a non-empty balloon label.
  • There is a numeric value entered for the feature in the current part workflow.

Conditional features

Features can have conditional expressions that are evaluated each time any feature in the workflow is measured. Any features whose conditional expressions do not evaluate to true will be hidden.

The following rules apply to conditional feature expressions:

  • Expressions can reference the value of another feature with $x, where x is the feature's balloon label.
  • Expressions can reference the selected value of a categorical feature with $$x. If numeric entry is still allowed for a categorical feature, any entered numeric value can be referenced with $x like a normal feature.
  • Be careful not to reference features that come after the current one during inspection because they may not have values entered yet.

Conditional expressions can be configured from the feature instructions step of the feature editor.

Examples

  • $B2 < 0.1
  • not equalText($$C3, "OK")
  • not equalText($$6, "OK") or $6 >= 0.012
  • (equalText($$A1, "OK") and equalText($$A2, "OK")) or equalText($$A3, "NG")