The nestedhexplugin consists of a set of external atoms and a parser for an extended syntax for more user convenience. The plugin allows for evaluating subprograms and reasoning about their answer sets. In particular, cautious and brave reasoning, and the inspection of answer sets of subprograms are supported.
file
or string
q(x1,...,xn)
is cautiously / bravely true in the specified programEvaluates the program specified by p (which must be a filename if type t=file and the a string containing the rules if t=string).
Prior to evaluation, p is extended by facts specified in higher-order notation by input predicate i. The arity of i is the maximum arity m of all facts to be added + 2.
For adding a fact of form f(c1,...,ck), predicate i is supposed to specify element i(f, k, c1,...,ck, empty,...,empty), where the number of terms of form empty is m - k, i.e., the empty terms fill additional argument positions in i which are not needed for a certain fact due to smaller arity.
Parameter q specifies the query predicate of arity n.
The external atom evaluates to true for all values x1,...,xn such that q(x1,...,xn) is cautiously/bravely true in p extended with the input from i.
Example:
inp(p, 2, a, x). % Maximum arity we want to pass is 2 (predicate p). inp(p, 2, b, y). % Therefore input predicate inp has arity 2+2=4. inp(r, 1, b, empty). % r has only arity 1, thus we fill the remaining % arguments with empty. out(A) :- &hexCautious[string, "q(X) :- p(X, Y), not r(X).", inp, q](A).
This will deliver out(a)
because the input adds p(a,x)
, p(b,y)
and r(b)
,
thus the single answer set of the subprogram contains q(a)
.
file
or string
qt
and qp
, see below.Evaluates the program p of type t extended with input from i as described above.
If qt=program
and qp
is missing, then the external atom is true for all pairs (x, n)
with 0 <= x < n
,
where n
is the number of answer sets of the program. Elements x
are intended to identify answer sets.
If qt=answerset
and qp
is an integer, then the external atom is true for all pairs (x, a)
which encode the true atoms in the answer set identified by qp
. A pair (x, a)
consists of
an integer identifier x
for this atom and its arity a
.
If qt=atom
and qp
is an integer, then the external atom is true for all pairs (x, t)
which encode the atom identified by qp
. If the identified atom has arity a
, then pairs (x, t)
for 0 <= x <= a
consist of encode the term t
at argument position x
, where x=0
denotes the predicate name.
Example:
inp(p, 1, a). inp(p, 1, b). inp(r, 1, b). as(AS, C) :- &hexInspection[string, "q(X) :- p(X), not r(X).", inp, program](AS, C). atoms(Atom, Arity) :- as(AS, C), &hexInspection[string, "q(X) :- p(X), not r(X).", inp, answerset, AS](Atom, Arity). parameters(Atom, Index, Term) :- atoms(Atom, Arity), &hexInspection[string, "q(X) :- p(X), not r(X).", inp, atom, Atom](Index, Term).
This will deliver as(0,1)
to encode that the program has one answer set,
atoms(v1,1)
for some integer v1
(exact value is unspecified) as a reference to the unary atom q(a)
in the answer set of the subprogram,
and parameters(v1, 0, q)
and parameters(v1, 1, a)
as an encoding of this atom.
Similarily, there will be further atoms which encode the input atoms to the subprogram (because they are also in its answer set).
The plugin further provides a convenient syntax for subprogram queries using dedicated HEX-atoms,
which are internally rewritten to the above external atoms.
Especially the passing of input to the subprogram is much more convenient using this syntax.
The rewriter can be activated by specifying the command-line option --nestedhex
.
F
and a string containing the rules otherwise.q(x1,...,xn)
is cautiously (C(F)HEX
) / bravely (B(F)HEX
) true in the specified program
The input definition is a comma-separated list of elements of form p=q/k
or q/k
, which specifies
that the k
-ary predicate q
from the program containing the HEX-atom is mapped
to the (also k
-ary) predicate p
in the subprogram, i.e.,
every true atom q(x1,...,xk)
is added as fact p(x1,...,xk)
.
If the part p=
is missing, then this implicitly defines q=q/k
, i.e.,
the input is mapped to the same predicate.
Example:
set1(a). set1(b). set2(b). out(A) :- CHEX["q(X) :- p(X), not r(X)."; p=set1/1, r=set2/1; q](A).
This will deliver out(a)
because the input adds p(a)
, p(b)
and r(b)
,
thus the single answer set of the subprogram contains q(a)
.
F
and a string containing the rules otherwise.&hexInspection[t, p, i, q](x1,...,xn)
.&hexInspection[t, p, i, qt, qp](x1,x2)
.qt
and qp
, see below.
For a given query type qt
and query parameter qp
, the meaning of the output arguments is as described for &hexInspection[t, p, i, qt, qp](x1,x2)
.
Example:
set1(a). set1(b). set2(b). as(AS, C) :- IHEX["q(X) :- p(X), not r(X)."; p=set1/1, r=set2/1; program](AS, C). atoms(Atom, Arity) :- as(AS, C), IHEX["q(X) :- p(X), not r(X)."; p=set1/1, r=set2/1; answerset, AS](Atom, Arity). parameters(Atom, Index, Term) :- atoms(Atom, Arity), IHEX["q(X) :- p(X), not r(X)."; p=set1/1, r=set2/1; atom, Atom](Index, Term).
This will deliver as(0,1)
to encode that the program has one answer set,
atoms(v1,1)
for some integer v1
(exact value is unspecified) as a reference to the unary atom q(a)
in the answer set of the subprogram,
and parameters(v1, 0, q)
and parameters(v1, 1, a)
as an encoding of this atom.
Similarily, there will be further atoms which encode the input atoms to the subprogram (because they are also in its answer set).
General
dlvhex source code @ github.com
Description-Of-A-Project
Popular Plugins
Action Plugin
DecisionDiagrams Plugin
Description Logics Plugin
Description Logics Lite Plugin
MELD: Belief Merging Plugin
Nested HEX Plugin
MCSIE Plugin
String Plugin
dlvhex-semweb Project
Documentation
User Guide
README
doxygen
Writing Plugins in C++
Writing Plugins in Python