DesCOTS-QM 3.0 Definition of Formulas
Quality Entities can be referenced within a formula by means of their name in the QM.
The Entity Name must be written double-quoted. Double quotes within the name must be escaped (have a backslash before them).
Before a Quality Entity can be entered into the formula, it must have metrics assigned to it.
A Quality Entity is of the type defined by its metrics.
There are some special access operations which can be applied to Entities in case they have a Domain, Tuple or Function metrics :
|
OPERATOR |
DESCRIPTION |
EXAMPLE |
|
Domain Of |
Returns the Domain of Values in which the Entity will be evaluated, as a Set of Strings. |
DomainOf “Domain Entity” |
|
Tuple access |
An element of the tuple is accessed by means of its name written within double quotes and surrounded by brackets after the entity name. |
“Tuple Entity” [ “elementName” ] |
|
Function access |
Returns the return value of the Function (given certain values). Function parameters are separated by commas and typed after the entity, surrounded by parentheses. |
“Function Entity” ( 5, 0.95, ”Int Entity” ) |
The Type returned by a Tuple access is the Type of the metrics of the accessed element.
The Type returned by a Function access is the Type of metrics of the return parameter of that Function.
Function accesses which return a Tuple Type can have their elements accessed (with a Tuple Access)
Constant values can be of one of these types :
|
TYPE |
DESCRIPTION |
EXAMPLE |
|
Boolean |
Keywords true and false represent boolean constants |
True |
|
Integer, Real |
Any numeric character sequence, signed if negative. Reals' floating point decimals come after a dot. |
- 4.5 , 0.5223 |
|
String |
Any single-quoted character sequence. Single quotes within the constant must be escaped (have a backslash before them). Strings are case insensible. |
'constant' |
|
Range |
Defines a range of values bounded by two constants. Constants are separated by two dots |
0..1.0 , 'a'..'z' |
|
Set |
Set elements are sequentially entered, separated by commas and surrounded by curly braces “{“ |
{ 'constant1', 'constant2', 'constant3' } |
|
Tuple |
Tuple elements are sequentially entered, separated by commas and surrounded by brackets “[“ |
[ 'constant1', 'constant2', 'constant3' ] |
Ranges' bounds must be either Integer, Real or String.
Set elements must be all of the same Type.
|
OPERATOR |
DESCRIPTION |
SYNTAX |
RETURN TYPE |
|
NOT |
Logical negation |
|
boolean |
|
MINUS |
Returns a number's negative value. |
|
( integer | real ) |
|
ABS |
Returns a number's absolute value |
|
( integer | real ) |
|
ROUND |
Rounds a number to the nearest integer. (round-down if in middle) |
|
integer |
|
TRUNC |
Truncates a number to the nearest integer (round-down) |
|
integer |
|
SIZE |
Returns the cardinality (number of elements) in a Set or Range. |
|
integer |
|
EMPTY |
Returns a boolean telling if a set (or a range) is empty |
|
boolean |
|
DOMAIN OF |
Returns the Domain of Values available to an Entity with Domain Metrics |
|
set of string |
The SIZE operator when used with ranges can only be applied to Integer Ranges. Real and String Ranges have infinite cardinality
|
OPERATOR |
DESCRIPTION |
SYNTAX |
RETURN TYPE |
|
AND OR |
Logical AND, OR |
|
boolean |
|
EQUAL NOT EQUAL |
True if first operand is equal to second operand. For non-equality type an exclamation sign ! Before the equality sign. It is important for set and tuple operands to have compatible types. |
|
boolean |
|
GREATER GREATER OR EQUAL LOWER LOWER OR EQUAL |
True if first operandr is greater (or lesser) compared to the second operand. To test for equality type an equality sign = after the comparation sign. |
|
boolean |
|
PLUS, MINUS, MULTIPLICATION, DIVISION |
Arithmetic addition (+), substraction (-), multiplication (*) and division (/). |
|
( integer | real ) |
|
STRING CONCATENATION |
Puts together two Strings in a new one. The arithmetic addition symbol is used to identify this operator. A domain operand has the selected value in the domain. |
|
string |
|
INTEGER DIVISION |
Returns the integer part of the division between operands. |
|
integer |
|
MODULE |
Arithmetic module. |
|
integer |
|
IN |
True if the first operand is an element that appears in the given set. |
|
boolean |
|
UNION INTERSECTION |
Returns the union (or intersection) of the two Sets in a new Set. |
|
set |
A Set Type is considered to be compatible with another Set Type when their respective Element Types are also compatible.
A Tuple Type is considered to be compatible with another Tuple Type when their Elements' Types are also compatible (and appear in the same order in both Tuples)
Operators involving set Types (such as UNION, INTERSECTION) require the Type of the elements in both sets to be compatible.
The IN operator requires the Type of the first operand (tested for inclusion within the set or range) to be compatible with the Type of the elements in the set or range.
Operators UNION and INTERSECTION do not accept Real or String Ranges (infinite cardinality).
Quantifiers can be used in order to obtain information from sets of data with a big size, where manual testing could be uncomfortable and result in an incomprehensible, too-long formula.
The available quantifiers are :
|
QUANTIFIER |
DESCRIPTION |
Return Value |
|
Forall / Exists |
Tests if every / at least one element in the Set satisfies a given condition. |
boolean |
|
Max / Min / Sum |
Returns the maximum / minimum / sum of the elements in the Set (which satisfy a given condition) |
integer / real |
|
Any |
Returns a random element in the Set that satisfies a given condition. |
Type of the elements in the Set. |
All quantifiers need an starting set. Its elements will be tested for a condition, and then the logic of the quantifier will be applied in order to return its result. The syntax for quantifiers is :
FORALL | EXISTS | MAX | MIN | SUM | ANY ( variable, variable IN ( set | range ) [, condition ] )
Variable is any non-reserved literal string. The variable is considered to be declared within the quantifier..
Set is the starting set of values. Each element in the Set will be assigned to the variable when testing the condition.
Range is any finite range of values. Only Integer Ranges are allowed in quantifiers (Real and String ranges have infinite cardinality).
Condition is any boolean expression, which may contain any previously declared variable. This condition may be omitted ( no test will be done )
For example: FORALL (x, x IN “Set of Int Entity”, x / “Real Entity” >= 0.5 ) will assign to x each element of “Set of Int Entity” and then test if the division with “Real Entity” is greater or equal than 0.5. It would return true if every x satisfied that condition.
Another example : MAX ( y, y IN “Set Entity” ) would simply return the maximum element in the set, with no additional test.
A conditional statement can be used at the beginning of a formula in order to define it in terms of two sub formulas. The sub formula to evaluate will be chosen depending on the evaluation of the stated condition. The syntax of this initial conditional structure is :
IF condition THEN sub formula1 ELSE sub formula2 ENDIF
Both sub formulas must evaluate to the same Type.
Sub formulas can not have conditional statements.
Parenthesized expressions are explicitly forced to be evaluated before non-parenthesized ones.
All literal strings, such as boolean constant values or operators (keywords) and single or double-quoted names are not case sensitive.