Basic Syntax of Vadalog

Preliminaries

Let C, V, N be sets of constants, variables or marked nulls, respectively.

The elements of such sets are known as terms. A syntactic expression of the form r(t1, t2, …​, tn) is known as atom, where t1, t2, …​ tn are terms. An atom is said to be ground if it only contains constants. A ground atom is also known as fact.

Rules

A rule is an expression of the form h :- b1, …​, bn where b1, …​, bn are the atoms of the body and h is the atom of the head.

The variables in the body are universally quantified, while the variables that appear in the head, but not in the body are existentially quantified.

A successful assignment of all the variables of the body of a rule results in a derivation for the rule head predicate, which is a successful activation of the rule. Vadalog programs use the set semantics, defined in a standard way in presence of existential quantification by the chase procedure.

Let us present some examples of rules.

Example 1
a(X) :- b(X).

It generates facts for atom a, given facts for atom b. X is a variable.

Example 2
a(X,Z) :- b(X,Y),c(Y,Z).
Example 3
a(X,Z) :- a(X,Y),a(Y,Z).

Given two facts for a, it generates a third one.

A Vadalog (logic) program (or ontology) is a set P of rules and facts.

The following is an example shows a simple Vadalog program.

Example 4
a(1).
c(1,2).
b(Y,X) :- a(X),c(X,Y).

@output("b").

a(1) is a fact, b(Y,X) :- a(X),c(X,Y) is a rule. Observe that @output("b") is an annotation and specifies that the facts for b are in the output.

Linear rules

Linear rules are rules with one single atom in the body. They define facts of the head predicate, given facts of the single body predicate.

Example 7
employee(1).
employee(2).
department(Y,X) :- employee(X).
@output("department").

For each employee X there exists a department Y. The expected result is:

Expected result
department(z1,1). department(z2,2).

Facts

The simplest form of linear rule is a fact: a ground head-less linear rule.

Example 8
employee("Jack").
employee("Ruth").

Datalog rules

Datalog rules are rules with multiple atoms in the body. They basically define facts of the head predicate, given facts of the body.

Example 9
project(Z,X) :- employee(X), department(Y,X).

For each employee X in a department Y, there exists a project Z in which he participates.

If the atoms in the body do not have variables in common, the Cartesian product is assumed.

Example 10
employee("Jack").
employee("Ruth").
department("science").
department("finance").
canWork(X,Y,Z) :- employee(X), department(Y).
@output("canWork").

Any employee X can work in any department Y on some unknown project Z. The expected result is:

Expected result
canWork("Jack","science",z1). canWork("Jack","finance",z2). canWork("Ruth","science",z3). canWork("Ruth","finance",z4).

Constants within rules

Constants can appear in the atoms of the rules.

When they appear in the head, they denote specific constant values to be generated in the head facts.

When they appear in the body, they denote specific filters, or selection criteria, to be applied to the facts considered in the rule.

Example 11
employee("Mark").
junior("Mark").
contract(X,"basic",20) :- employee(X),junior(X).
@output("contract").

A junior employee will have a "basic" contract, with stipend 20. The expected result is:

Expected result
contract("Mark","basic",20).
Example 12
employee("Mark","junior").
employee("Ruth","senior").
contract(X,"basic",20) :- employee(X,"junior").
contract(X,"advanced",40) :- employee(X,"senior").
@output("contract").

Any junior employee X will have a "basic" contract with stipend 20. Any senior employee X will have an "advanced" contract with stipend 40. Basically, the constants filter the facts to which the rules apply, in such a way that the one for basic contracts applies only to Mark, and the one for advanced contracts applies only to Ruth. The expected result is:

Expected result
contract("Mark","basic",20). contract("Ruth","advanced",40).

Programs

A program is a set of rules.

as it is a set, the order in which the rules are written do not play any role in the reasoning.

Comments

Line comments in Vadalog program are denoted by %. The syntax is then the following:

% this is a comment