This document provides a comprehensive reference for the Vadalog grammar, covering all syntax rules, operators, and language constructs.

Program Structure

A Vadalog program consists of a sequence of clauses:

Clause Types

A clause can be one of three types:
  1. Annotation: Configuration directives (e.g., @bind, @output)
  2. Fact: Ground truth statements (e.g., person("john", 25).)
  3. Rule: Logical inference rules (e.g., adult(X) <- person(X, Age), Age >= 18.)

Facts

Facts are ground statements that establish base knowledge:
Examples:

Rules

Rules define logical inference patterns:

Rule Head

The head can be:
  • Regular atom: result(X, Y)
  • EGD (Equality Generating Dependency): X = Y
  • False head: #F (for constraints)
Examples:

Rule Body

The body consists of literals, conditions, and functions:

Literals

Literals can be positive, negative, or domain predicates:
Examples:

Conditions

Conditions define constraints and comparisons:

Comparison Operators

Set Membership

Examples:

Expressions

Expressions support arithmetic, logical, and functional operations:

Arithmetic Expressions

Logical Expressions

Set Operations

Comparison Expressions

Examples:

Aggregation Functions

Vadalog supports both monotonic and non-monotonic aggregations:

Monotonic Aggregations

Standard Aggregations

Examples:
Group-by variables appear in both the head and the body. The aggregation function takes only the expression to aggregate.

String Operations

Examples:

Similarity Operations

Examples:

Logical Operations

Interval Operations

Examples:

Data Type Conversions

Null Handling

Terms and Constants

Variable Terms

  • Variables: Start with uppercase (Name, Age, X)
  • Anonymous variables: Start with underscore (_, _1, _temp)

Constant Terms

  • Strings: Double-quoted ("hello", "john doe")
  • Integers: Numeric (42, -10)
  • Doubles: Decimal (3.14, -2.5)
  • Booleans: #T (true), #F (false)
  • Dates: 2024-01-15 or 2024-01-15 14:30:00

Collection Terms

  • Lists: [1, 2, 3] or ["a", "b", "c"]
  • Sets: {1, 2, 3} or {"a", "b", "c"}
  • Empty collections: [] (list), {} (set)

External Functions

Call external functions using namespace syntax:
Examples:

Parameter Operations

Dynamic parameter substitution:
Example:

Comments

Line comments start with %:

Operator Precedence

From highest to lowest precedence:
  1. Parentheses: ()
  2. Unary minus: -
  3. Multiplication/Division: *, /
  4. Addition/Subtraction: +, -
  5. Comparison: <, <=, >, >=, ==, !=
  6. Logical NOT: !
  7. Logical AND: &&
  8. Logical OR: ||
  9. Set operations: |, &

Best Practices

  1. Use meaningful predicate names: customer_analysis not ca
  2. Follow naming conventions: Variables uppercase, constants lowercase
  3. Group related rules: Keep similar logic together
  4. Comment complex logic: Explain non-obvious rules
  5. Use proper aggregations: mavg() for averages, msum() for sums
  6. Handle edge cases: Consider null values and empty results
This grammar reference provides the foundation for writing correct, efficient Vadalog programs.