datalog — Logtalk 3.100.1

object

# `datalog`

Portable Datalog engine with stratified negation and incremental updates.

Availability:
`logtalk_load(datalog(loader))`
Author: Paulo Moura
Version: 0:1:1
Date: 2026-03-30
Compilation flags:
`static, context_switching_calls`
Implements:
`public` datalog_protocol
Uses:
list
numberlist
type
varlist
Remarks:
(none)
Inherited public predicates:
add_rule/3 assert_fact/1 begin/0 clear/0 commit/0 explain/2 facts/1 load_program/1 materialize/0 predicate_stratum/3 query/1 query/2 remove_rule/1 retract_fact/1 rollback/0 rules/1 strata/1 update/3

## Public predicates

(no local declarations; see entity ancestors if any)

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

### `rule_/3`

Table of loaded rules represented as rule id, head, and body literals.

Compilation flags:
`dynamic`
Template:
`rule_(Id,Head,Body)`
Mode and number of proofs:
`rule_(?nonvar,?callable,?list)` - `zero_or_more`

### `edb_fact_/1`

Table of extensional database (EDB) facts.

Compilation flags:
`dynamic`
Template:
`edb_fact_(Fact)`
Mode and number of proofs:
`edb_fact_(?callable)` - `zero_or_more`

### `idb_fact_/1`

Table of intensional database (IDB) currently derived facts.

Compilation flags:
`dynamic`
Template:
`idb_fact_(Fact)`
Mode and number of proofs:
`idb_fact_(?callable)` - `zero_or_more`

### `support_count_/2`

Table of derivation support counts for currently derived facts.

Compilation flags:
`dynamic`
Template:
`support_count_(Fact,Count)`
Mode and number of proofs:
`support_count_(?callable,?integer)` - `zero_or_more`

### `support_edge_/3`

Table of concrete derivation edges as fact, rule id, and supporting literals.

Compilation flags:
`dynamic`
Template:
`support_edge_(Fact,RuleId,Supports)`
Mode and number of proofs:
`support_edge_(?callable,?nonvar,?list)` - `zero_or_more`

### `predicate_stratum_/3`

Table of computed predicate strata represented as name, arity, and stratum number.

Compilation flags:
`dynamic`
Template:
`predicate_stratum_(Name,Arity,Stratum)`
Mode and number of proofs:
`predicate_stratum_(?atom,?integer,?integer)` - `zero_or_more`

### `snapshot_/6`

Transaction snapshot of rules, EDB facts, IDB facts, support counts, support edges, and predicate strata.

Compilation flags:
`dynamic`
Template:
`snapshot_(Rules,EdbFacts,IdbFacts,SupportCounts,SupportEdges,PredicateStrata)`
Mode and number of proofs:
`snapshot_(?list,?list,?list,?list,?list,?list)` - `zero_or_one`

### `restore_snapshot/6`

Restores a saved transaction snapshot into the current engine state.

Compilation flags:
`static`
Template:
`restore_snapshot(Rules,EdbFacts,IdbFacts,SupportCounts,SupportEdges,PredicateStrata)`
Mode and number of proofs:
`restore_snapshot(+list,+list,+list,+list,+list,+list)` - `one`

### `restore_edb_facts/1`

Restores EDB facts from a saved list.

Compilation flags:
`static`
Template:
`restore_edb_facts(Facts)`
Mode and number of proofs:
`restore_edb_facts(+list(callable))` - `one`

### `restore_idb_facts/1`

Restores IDB facts from a saved list.

Compilation flags:
`static`
Template:
`restore_idb_facts(Facts)`
Mode and number of proofs:
`restore_idb_facts(+list(callable))` - `one`

### `restore_support_counts/1`

Restores support counts from a saved list.

Compilation flags:
`static`
Template:
`restore_support_counts(Supports)`
Mode and number of proofs:
`restore_support_counts(+list)` - `one`

### `restore_support_edges/1`

Restores support edges from a saved list.

Compilation flags:
`static`
Template:
`restore_support_edges(Edges)`
Mode and number of proofs:
`restore_support_edges(+list)` - `one`

### `restore_predicate_strata/1`

Restores predicate strata from a saved list.

Compilation flags:
`static`
Template:
`restore_predicate_strata(Strata)`
Mode and number of proofs:
`restore_predicate_strata(+list)` - `one`

### `strata_from_numbers/2`

Builds grouped strata terms from a sorted list of stratum numbers.

Compilation flags:
`static`
Template:
`strata_from_numbers(StratumNumbers,Strata)`
Mode and number of proofs:
`strata_from_numbers(+list(integer),-list)` - `one`

### `predicates_in_stratum/2`

Returns predicates in a given stratum as sorted `predicate(Name, Arity)` terms.

Compilation flags:
`static`
Template:
`predicates_in_stratum(Stratum,Predicates)`
Mode and number of proofs:
`predicates_in_stratum(+integer,-list)` - `one`

### `has_aggregate_rules/0`

True when at least one loaded rule body contains an aggregate literal.

Compilation flags:
`static`
Mode and number of proofs:
`has_aggregate_rules` - `zero_or_one`

### `aggregate_body_predicate/2`

Enumerates predicate indicators referenced in aggregate goals from a body literal list.

Compilation flags:
`static`
Template:
`aggregate_body_predicate(Body,Predicate)`
Mode and number of proofs:
`aggregate_body_predicate(+list,-compound)` - `zero_or_more`

### `derive_aggregate_literal/2`

Evaluates an aggregate literal and returns a normalized support term.

Compilation flags:
`static`
Template:
`derive_aggregate_literal(AggregateLiteral,Support)`
Mode and number of proofs:
`derive_aggregate_literal(+compound,-nonvar)` - `zero_or_one`

### `derive_aggregate_goals/1`

Succeeds when all aggregate goals are true for the current bindings.

Compilation flags:
`static`
Template:
`derive_aggregate_goals(Goals)`
Mode and number of proofs:
`derive_aggregate_goals(+list(callable))` - `zero_or_one`

### `optimize_rule_body/2`

Normalizes a rule body by placing positive ground literals first, then positive non-ground literals, then aggregates, and finally negative literals.

Compilation flags:
`static`
Template:
`optimize_rule_body(Body,OptimizedBody)`
Mode and number of proofs:
`optimize_rule_body(+list,-list)` - `one`

### `partition_body_literals/5`

Partitions body literals into positive-ground, positive-non-ground, aggregate, and negative lists preserving relative order.

Compilation flags:
`static`
Template:
`partition_body_literals(Body,PositiveGround,PositiveNonGround,Aggregates,Negatives)`
Mode and number of proofs:
`partition_body_literals(+list,-list,-list,-list,-list)` - `one`

### `literal_bucket/2`

Classifies a body literal into one of the normalization buckets.

Compilation flags:
`static`
Template:
`literal_bucket(Literal,Bucket)`
Mode and number of proofs:
`literal_bucket(+nonvar,-atom)` - `one`

## Operators

(none)