package datalog
Module Datalog.DefaultSource
Default literal base, where symbols are just strings
Default symbols: hashconsed strings
Default implementation
This is a ready-to-use instance of BottomUp.Make, with hashconsed strings as symbols. It also features some handy conversion functions from BottomUpAST.
include BottomUp.S with type symbol := symbol
Literals and clauses
A datalog atom, i.e. pred(arg_1, ..., arg_n). The first element of the array is the predicate, then arguments follow
A datalog clause, i.e. head :- body_1, ..., body_n
Constructors and destructors
Helper to build a literal. Arguments are either variables or constants
Create a clause from a conclusion and a list of premises
Deconstruct a clause
Comparisons
A datalog clause is safe iff all variables in its head also occur in its body
Pretty-printing
Pretty print the literal
Pretty print the clause
Higher level API
This part of the API can be used to avoid building variables yourself. Calling quantify3 f with call f with 3 distinct variables, and f can use those variables to, for instance, build a clause
The Datalog unit resolution algorithm
A database of facts and clauses, with incremental fixpoint computation
type explanation = | Axiom| Resolution of clause * literal| ExtExplanation of string * BottomUp.Univ.t(*Explanation for a clause or fact. It is extensible through universal types.
*)
Add the clause/fact to the DB as an axiom, updating fixpoint. UnsafeRule will be raised if the rule is not safe (see check_safe)
Add a fact (ground unit clause)
Add a goal to the DB. The goal is used to trigger backward chaining (calling goal handlers that could help solve the goal)
match the given literal with facts of the DB, calling the handler on each fact that match
Like db_match, but the additional int list is used to select bindings of variables in the literal. Their bindings, in the same order, are given to the callback.
Fold on all clauses in the current DB (including fixpoint)
Add a function to be called on new literals. Only one function per symbol can be registered.
Explain the given fact by returning a list of facts that imply it under the current clauses, or raise Not_found
Immediate premises of the fact (ie the facts that resolved with a clause to give the literal), plus the clause that has been used.
Get all the explanations that explain why this clause is true