Single-fact operators
| Data type | Operators |
|---|---|
| all | ==, >, <, >=, <=, <>, != |
| integer | (monadic) -, *, /, +, -, ( ) |
| double | (monadic) -, *, /, +, -, ( ) |
| boolean | &&, ||, !, not, ( ) for associativity |
| string | substring, contains, contains_any, rlike, starts_with, ends_with, concat, concat_ws, replace, join, index_of, string_length, to_lower, to_upper, split, is_empty, strip |
| set | | (union), & (intersection), ( ) for associativity |
Comparison operators
The comparison operators are==,>,<,>=,<=,<> (alternate syntax
!=). They can be used to compare literals of any data type and return a
Boolean, depending whether the comparison is satisfied or not. Only values of
the same type can be compared.
==: equals to>: greater than<: less than>=: greater or equal<=: less or equal<>: not equal!=: not equal
Arithmetic operators
The arithmetic operators are* (multiplication), / (division), +
(addition), - (subtraction). Infix *, /, +, - can be applied to all
numeric (integer and double) operands, with an implicit upcast to double if any
double is involved.
The operator + (plus) also performs string concatenation with an implicit
upcast to string if any string is involved.
The operator - (minus) also exists in its monadic version, which simply
inverts the sign of a numeric value.
Division by 0 always fails, causing the program to abort.
Operations associate to the left, except that multiplication and division
operators have higher precedence than addition and subtraction operators.
Precedence can be altered with parentheses.
Boolean operators
The Boolean operators are and (&&), or (||) or not. They can be used to
combine Boolean data types.
Logical operators
Vadalog supports explicit logical operators as functions in addition to implicit logical operations through rule structure. These explicit operators (and(), or(), not(), etc.) allow for combining and manipulating Boolean expressions within a single rule. The operators can evaluate complex logical conditions and can be assigned to variables for further processing.
Key distinction:
- Implicit AND/OR: Multiple conditions in a rule body are implicitly AND-ed. Multiple rules with the same head represent OR.
- Explicit operators: Functions like
and(),or(),not(),xor(),if()allow complex boolean logic within expressions and can be assigned to variables.
and(args)- Logical AND of multiple conditionsor(args)- Logical OR of multiple conditionsnot(expression)- Logical NOT/negationxor(expression1, expression2)- Exclusive ORnand(expression1, expression2)- NOT ANDnor(expression1, expression2)- NOT ORxnor(expression1, expression2)- Exclusive NORimplies(expression1, expression2)- Logical implicationiff(expression1, expression2)- If and only ifif(condition, true_value, false_value)- Conditional expression
and(args)
The and(args) operator evaluates to true if all the conditions in args are true. You can assign the result to a variable and use ==#T to enforce that all conditions must be true.
Example 1: Basic and(args) usage
This example shows the use of the and(args) operator to evaluate multiple conditions on the variable X. The rule b(X, IsIn) checks if X is greater than 2, less than 5, and equal to 3. The result of this conjunction is stored in IsIn.
or(args)
The or(args) operator evaluates to true if any of the conditions in args are true. You can assign the result to a variable and use ==#T to enforce that at least one condition must be true.
Example 2: Basic or(args) usage
This example illustrates the use of the or(args) operator to evaluate multiple conditions on the variable X. The rule b(X, IsIn) checks if X is less than 2, equal to 4, or equal to 6. The result of this disjunction is stored in IsIn.
not(expression)
The not(expression) operator negates the Boolean value of the expression. It returns #T if the expression is #F, and #F if the expression is #T.
Example 3: Basic not(expression) usage
This example demonstrates the use of the not operator to negate a condition.
xor(expression1, expression2)
The xor(expression1, expression2) operator (exclusive or) evaluates to true if exactly one of the two expressions is true, but not both.
Example 4: Basic xor(expression1, expression2) usage
This example shows the exclusive or operation between two conditions.
nand(expression1, expression2)
The nand(expression1, expression2) operator (not and) evaluates to true if at least one of the expressions is false.
Example 5: Basic nand(expression1, expression2) usage
This example demonstrates the NAND operation.
nor(expression1, expression2)
The nor(expression1, expression2) operator (not or) evaluates to true only if both expressions are false.
Example 6: Basic nor(expression1, expression2) usage
This example demonstrates the NOR operation.
xnor(expression1, expression2)
The xnor(expression1, expression2) operator (exclusive nor) evaluates to true if both expressions have the same Boolean value.
Example 7: Basic xnor(expression1, expression2) usage
This example demonstrates the XNOR operation.
implies(expression1, expression2)
The implies(expression1, expression2) operator (implication) evaluates to false only if the first expression is true and the second is false.
Example 8: Basic implies(expression1, expression2) usage
This example demonstrates logical implication.
iff(expression1, expression2)
The iff(expression1, expression2) operator (if and only if) evaluates to true if both expressions have the same Boolean value.
Example 9: Basic iff(expression1, expression2) usage
This example demonstrates the if and only if operation.
if(condition, true_value, false_value)
The if(condition, true_value, false_value) operator provides conditional logic. It returns true_value if the condition is true, otherwise it returns false_value.
Example 10: Basic if(condition, true_value, false_value) usage
This example demonstrates conditional logic using the if operator to classify numbers as positive or non-positive.
if operator
This example uses the if operator to check if a string is empty and return appropriate labels.
if operator
This example uses the if operator to check if a string is not null and return appropriate labels.
if statements for credit rating
This example demonstrates complex nested if statements to implement a credit rating system based on credit scores. Each nested if evaluates a range of credit scores and assigns a corresponding rating value.
and(args) with condition enforcement
In this example, the and(args) operator is used to evaluate conditions on X, and the result is compared to #T to enforce that all conditions must be true. The rule b(X) only succeeds if X is greater than 2, less than 5, and equal to 3.
String operators
The String operators aresubstring, contains, contains_any, rlike, starts_with, ends_with, concat, concat_ws, +, index_of, string_length, to_lower, to_upper, split, replace, join, is_empty, and strip. These operators allow manipulation and comparison of String values.
substring
A rule using substring returns a substring from the specified start to end index, using zero-based indexing:
showLineNumbers
contains
A rule with contains returns true if the string contains substring:
showLineNumbers
contains can also be used directly as a boolean condition in the rule body (see Implicit Boolean Conditions).
starts_with
A rule with starts_with returns true if the string starts with start_string:
showLineNumbers
ends_with
A rule with ends_with returns true if the string ends with end_string:
showLineNumbers
contains_any
A rule with contains_any returns true if the string contains any of the keywords in the keywords_array:
showLineNumbers
rlike
A rule with rlike returns true if the string matches the given regular expression pattern:
showLineNumbers
concat
A rule with concat returns the concatenation of string and concat_string:
showLineNumbers
string_length
A rule with string_length returns an integer representing the length of the string:
showLineNumbers
to_lower
A rule with to_lower converts string to lowercase:
showLineNumbers
to_upper
A rule with to_upper converts string to uppercase:
showLineNumbers
split
A rule with split divides string by a specified delimiter, producing a list of substrings:
showLineNumbers
index_of
A rule with index_of finds the index of substring within string, returning -1 if not found:
showLineNumbers
substring (single parameter)
You can also use substring with a single parameter to get the substring from a starting position to the end:
showLineNumbers
concat_ws
A rule with concat_ws concatenates strings with a specified separator:
showLineNumbers
replace
A rule with replace replaces occurrences of a substring with another string:
showLineNumbers
join
A rule with join joins array elements into a string with a specified delimiter:
showLineNumbers
is_empty
A rule with is_empty checks if a string is empty or contains only whitespace:
showLineNumbers
strip
A rule with strip removes leading and trailing whitespace from a string:
showLineNumbers
Set operators
Vadalog supports set operations on arrays using the union (|) and intersection (&) operators.
Union (|)
The union operator combines two arrays, removing duplicates:
showLineNumbers
Intersection (&)
The intersection operator finds common elements between two arrays:
showLineNumbers
Implicit Boolean Conditions
Boolean-returning functions can be used directly as conditions in rule bodies without explicit comparison to#T. This provides a more natural syntax for filtering.
Direct Boolean Functions as Conditions
showLineNumbers
Negated Boolean Conditions with !
Use ! to negate boolean expressions directly in conditions:
showLineNumbers
Distinction: not vs !
not: Used for negating atoms (checking if a predicate doesn’t exist)!: Used for negating boolean expressions
showLineNumbers

