Operators
Vadalog supports built-in operations over values of data types. These operations allow comparing values, performing arithmetic, and manipulating strings and datetime values. Operations are supported through symbolic operators, which can be prefix, infix or functional-style. Vadalog supports single-fact operators (simply called operators) and multi-facts operators (called aggregation operators).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 on whether the comparison is satisfied.
==: 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 + also performs string concatenation with an implicit upcast to string if any string is involved.
The operator - 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 (||), and 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.
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)
b(3, #T) (all others #F)
To enforce that all conditions must be true:
b(3).
or(args)
b(1, #T). and b(4, #T). (others #F)
not(expression)
b(1, #T). b(2, #F). b(3, #T).
xor(expression1, expression2)
Evaluates to true if exactly one of the two expressions is true.
nand(expression1, expression2)
Evaluates to true if at least one of the expressions is false.
nor(expression1, expression2)
Evaluates to true only if both expressions are false.
xnor(expression1, expression2)
Evaluates to true if both expressions have the same Boolean value.
implies(expression1, expression2)
Evaluates to false only if the first expression is true and the second is false.
iff(expression1, expression2)
Evaluates to true if both expressions have the same Boolean value.
if(condition, true_value, false_value)
Returns true_value if the condition is true, otherwise false_value.
b("positive", 1). b("non-positive", -1).
Nested if for credit rating:
String Operators
substring
contains
starts_with / ends_with
contains_any
rlike
Checks if a string matches a regular expression pattern:
concat / concat_ws
string_length
to_lower / to_upper
split
index_of
Returns the index of a substring within a string, or -1 if not found:
replace
join
is_empty
Returns #T if the string is empty or contains only whitespace:
strip
Removes leading and trailing whitespace:
Set Operators
Union (|)
Combines two arrays, removing duplicates:
Intersection (&)
Finds common elements between two arrays:
Implicit Boolean Conditions
Boolean-returning functions can be used directly as conditions in rule bodies without explicit comparison to#T:
! to negate boolean expressions directly:
not and !:
not: Used for negating atoms (checking if a predicate doesn’t exist)!: Used for negating boolean expressions

