Stratification checks for ExDatalog programs.
A Datalog program with negation must be stratifiable — there must be no cycle in the dependency graph that contains a negative edge. If such a cycle exists, evaluation order is ambiguous and the program is rejected.
This module:
- Builds a dependency graph from the program's rules.
- Computes strongly connected components (SCCs) using Tarjan's algorithm.
- Checks that no SCC contains a negative edge.
- Assigns a stratum to each relation.
Summary
Functions
Assigns strata to all relations in the program.
Checks whether the program has unstratifiable negation.
Types
Functions
@spec assign_strata(ExDatalog.Program.t()) :: %{ required(String.t()) => non_neg_integer() }
Assigns strata to all relations in the program.
Returns a map from relation name to stratum number (0-based).
Every declared relation is included — relations that appear only in
facts (not in any rule) are assigned stratum 0. Only valid for
programs that pass check/1.
@spec check(ExDatalog.Program.t()) :: :ok | {:error, [ExDatalog.Validator.Error.t()]}
Checks whether the program has unstratifiable negation.
Returns :ok if all SCCs are stratifiable, or {:error, errors} listing
every SCC that contains a negative edge.