<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Well-founded Semantics for Recursive SHACL</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Adrian Chmurovič</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Mantas Šimkus</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computing Science, Umeå University</institution>
          ,
          <country country="SE">Sweden</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Faculty of Informatics</institution>
          ,
          <addr-line>TU Wien</addr-line>
          ,
          <country country="AT">Austria</country>
        </aff>
      </contrib-group>
      <fpage>2</fpage>
      <lpage>13</lpage>
      <abstract>
        <p>W3C has recently introduced SHACL as a new standard for integrity constraints on RDF graphs. Unfortunately, the standard defines the semantics of non-recursive constraints only, which has spurred recent research eforts into finding a suitable, mathematically crisp semantics for constraints with cyclic dependencies. To this end, Corman et al. [1] introduced a semantics related to supported models known in logic programming, while Andreşel et al. [2] presented a semantics based on stable models known in Answer Set Programming (ASP). In this paper, we argue that recursive SHACL can be naturally equipped with a semantics inspired in the well-founded semantics for (recursive) DATALOG queries with default negation. This semantics is not only intuitive, but it is also computationally tractable, unlike the previous proposals. To draw a connection with the classic definition of well-founded semantics in logic programming, we provide a simple translation of recursive SHACL under the well-founded semantics into propositional logic programs under the well-founded semantics. This translation is not only of theoretical interest: It can be eficiently implemented using the functionality of standard RDF triple stores (specifically, by issuing a small number of SPARQL queries), followed by an eficient evaluation using an existing engine for computing the well-founded model of a propositional logic program.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;graph-structured data</kwd>
        <kwd>integrity constraints</kwd>
        <kwd>SHACL</kwd>
        <kwd>RDF</kwd>
        <kwd>well-founded semantics</kwd>
        <kwd>answer set programming</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>Graph-structured data is becoming increasingly prominent and popular, mainly because it does
not require the development of rigid database schemas. This is important in emerging scenarios
where data has complex structure, where it may be highly incomplete, or where its structure
evolves over time, which makes the development of a fixed database schema challenging. This
has spurred research into topics like Knowledge Graphs, Property Graphs, Graph Databases, RDF
graphs, etc. The flexible nature of graph-structured data does not mean we are uninterested in
the quality and the structural integrity of the stored data. In traditional relational databases, the
so-called integrity constraints provide means to enforce a strict structure and maintain quality of
stored information, and we would like to have similar tools for graph-structure data. However,
this is not easy: we need to strike a good balance between the power to assert some control over
the structure of data, and being relaxed enough to not negate the benefits of the graph-based
data model.</p>
      <p>
        To address the above challenge, W3C has recently introduced SHACL1 as a new standard
for expressing constraints on RDF graphs (we refer the reader to [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] for an excellent tutorial
on SHACL). Constraints in SHACL are specified using validation rules, which have features
reminiscent of logic programming and concept expressions expressed in Description Logics.
Unfortunately, the SHACL standard only defines the semantics of non-recursive SHACL
constraints, while the semantics of SHACL with cyclic dependencies, or recursion, was intentionally
left unspecified: it is currently up to the developers of SHACL validators to come up with
ad-hoc solutions to handle recursion. This has spurred recent research eforts into finding a
suitable, mathematically crisp semantics for recursive SHACL constraints. Corman et al. have
introduced a semantics that is related to the notion of supported models known in logic programs,
while Andreşel et al. have explored a semantics based on stable models known in Answer Set
Programming (ASP) [
        <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
        ]. The supported model semantics of Corman et al. has two weaknesses:
(a) the problem of deciding validity is intractable, (b) it allows for unfounded (self-supported)
justifications of inferences, which sometimes leads to counter-intuitive validation results. The
stable model semantics does not sufer from (b) but still has problem (a): the intractability
(specifically, NP-hardness) of validation in the two semantics is caused by the possible simultaneous
presence of recursion and negation in constraints. NP-hardness already applies when the size of
input constraints is assumed to be xfied by a constant (i.e., in data complexity), which becomes
a major challenge for implementing validators for recursive SHACL as RDF graphs in practice
are often very big. Interestingly, in the case of the supported model semantics, NP-hardness
holds already for constraints with stratified negation. In this paper, we argue that recursive
SHACL can be naturally equipped with a semantics inspired in the well-founded semantics for
logic programs, a semantics that also plays a major role in (recursive) DATALOG queries with
default negation. This semantics is not only intuitive (e.g., it avoids problem (b)), but it is also
computationally tractable.
      </p>
      <p>The rest of this paper is organized as follows:
• We conclude this introduction with a rather detailed motivating example to illustrate the
basic ideas and the challenge addressed in this paper.
• In Section 2, we recall the well-founded semantics for propositional logic programs based
on the notion of unfounded sets, and provide an example on how the (unique) well-founded
model of a program can be computed.
• In Section 3, we recall the (abstract) syntax of SHACL and recall the (2-valued) supported
model semantics of SHACL. This most basic semantics is illustrated with an example that
shows an undesired self-justification cycle.
• In Section 4, we present our well-founded semantics for SHACL, based on a notion of
unfounded sets (adapted from the notion used for logic programs).
• In Section 5, we describe a transformation that allows to reduce the validation problem
to the task of computing the well-founded model of a propositional logic program. This
transformation can be implemented eficiently and leads to a way of performing SHACL
validation under the new semantics using some of the existing deductive database engines.
• In Section 6, we conclude this paper, including a discussion of some of the challenges and
future directions in the research on SHACL.
./(!#0%+' *+
( )
()
()
1203*4%%</p>
      <p>Alex
'
()%&amp;"*+,./(!#0%+' *+
'
()%&amp;"*+,</p>
      <p>!"#$%&amp;"
Blake</p>
      <p>Cameron</p>
      <p>Drew
'
()%&amp;"*+,</p>
      <sec id="sec-1-1">
        <title>ProfessorShape ←</title>
      </sec>
      <sec id="sec-1-2">
        <title>EmployeeShape ←</title>
      </sec>
      <sec id="sec-1-3">
        <title>StudentShape ←</title>
      </sec>
      <sec id="sec-1-4">
        <title>EmployeeShape ∧ (∃isMentorOf.StudentShape)</title>
        <p>Employee ∨ ∃hasSuperior.EmployeeShape</p>
      </sec>
      <sec id="sec-1-5">
        <title>Student ∨ (EmployeeShape ∧ ¬ProfessorShape)</title>
        <p>Example 1. Consider the example knowledge graph (KG) in Figure 1, containing some information
about members of an educational institution. The KG mentions four persons called Alex, Blake,
Cameron and Drew, which correspond to the four nodes of the KG. Alex is (explicitly) stated to
be an employee in this institution, which is indicated by their membership in the class Employee.
Cameron is a (regular) student in this institution, which is indicated by their membership in the
class Student. Blake is a mentor of Cameron, which is indicated via the edge between them labeled
with the property isMentorOf. Blake has Alex as a superior in this institution, captured via an
edge labeled with hasSuperior. Furthermore, Cameron has Drew as another mentor. Finally, the
KG has two facts that are quite questionable: Alex is a mentor of Alex, and Drew is a superior of
Drew. The presence of these two facts is clearly unintended (and should be dealt with using an
appropriate validation machinery).</p>
        <p>The KG presented so far does not carry any semantic information on the expected relations
between the diferent kinds of objects that are present, it contains no schema information nor integrity
constraints. The SHACL standard specifies a language for expressing such information. Consider
the three expressions (P), (E) and (S) in Figure 1, which intuitively correspond to three validation
rules that allow to identify nodes of three types: nodes corresponding to professors, employees, and
students, respectively. Each of these three types has a name (i.e., ProfessorShape , EmployeeShape ,
and StudentShape) that is associated to its definition using a (possibly quite complex)
logicbased expression. In the DATALOG terminology, we have ProfessorShape , EmployeeShape , and
StudentShape as monadic intensional predicates, while Employee, Student are unary extensional
predicates, and isMentorOf, hasSuperior are binary extensional predicates. Specifically, (P) tells us
that a person is considered to be a professor (has type ProfessorShape ) if they are an employee (of
type EmployeeShape ) and they mentor at least one student (an object with type StudentShape).
According to the rule (E), a person is an employee (has type EmployeeShape ) if that is stated
explicitly (via membership in the class Employee), or the person has a superior that is in turn of
type EmployeeShape . The last rule (S) tells us that an object is of type StudentShape if the object
is explicitly stated to be an instance of the class Student, or the object is of type EmployeeShape
but not of type ProfessorShape . Intuitively, in our example, the employees of the institution that
are not professors can be seen as students who can, e.g., take courses.</p>
        <p>As a final step, we need to specify which nodes of the graph are expected to satisfy selected types.
This is done via a specification of target nodes. In the basic case, we can list pairs of nodes and the
expected type (shape) names. For example, consider the following target specification:
1 = {(Blake, ProfessorShape), (Cameron, StudentShape)}
Intuitively, our KG equipped with the validation rules (P), (E) and (S) validates the targets in
1. Indeed, Cameron satisfies StudentShape because they are explicitly stated as an instance of
Student. Since Blake has Alex as a superior and Alex is explicitly stated to be an employee, we
have that Blake satisfies EmployeeShape. Given that Blake mentors Cameron, we infer that
Blake satisfies ProfessorShape. Unsurprisingly, we can have targets that we don’t expect to be
validated by our KG and the above validation rules (under a reasonable validation semantics): this
holds, e.g., for  = {(Blake, StudentShape)} and  = {(Cameron, ProfessorShape)}.</p>
        <p>In practice, we want more succinct representations of target specifications. The SHACL
standard describes the so-called class and property (domain and range) targets. E.g., with  =
{(Student, EmployeeShape)} we ask each instance of Student to satisfy EmployeeShape (this
requirement will clearly be violated in our KG).</p>
        <p>
          Let’s consider the 2-valued supported model semantics of Corman et at. [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ]. Here we simply
try to assign to each node some set of shape names such that: (i) a node  is a assigned a shape
name  if  satisfies the shape expression associated to , and (ii) the target specification is
respected. Unfortunately, under this semantics, the target 1 above cannot be validated by our
KG, which is certainly not desirable. The problem here is that Alex rules out the existence of any
shape assignment as required for validation. If we assign ProfessorShape to Alex, then Alex
must be a mentor of some object with StudentShape. Since Alex only mentors themselves, and
StudentShape is incompatible with ProfessorShape, our candidate shape assignment fails. If
we decide to not assign ProfessorShape to Alex, then Alex must not mentor any object with
StudentShape. However, Alex mentors themselves and obviously satisfies StudentShape. Thus
again the shape assignment has failed. Overall, the 2-valued supported model semantics has a
significant disadvantage: If we have some issue in the graph that bars the existence of a total shape
assignment, then the validation fails for all target specifications, even those without any connection
to the problematic part of the knowledge graph. The 2-valued stable model semantics in [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ] has the
same problem, and thus [
          <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
          ] also consider 3-valued versions of their semantics.
        </p>
        <p>Consider the knowledge graph obtained by dropping the node Alex, i.e., deleting the class
membership and property assertions that involve Alex. Then a total shape assignment becomes possible:
simply assign StudentShape to Cameron and assign ProfessorShape and EmployeeShape to
Drew. In fact, this is the only assignment possible. However, this situation is questionable because
the knowledge graph states that Drew supervises themselves, which in turn causes an unfounded
inference: Drew is an employee because Drew is an employee. Thus this graph validates the target
specification  = {(Drew, ProfessorShape)} despite the absence of evidence that Drew is an
employee in the organization. The two problems that were discussed in this example are addressed
by the well-founded semantics for SHACL that we discuss here.</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>2. Preliminaries</title>
      <p>
        We now recall the well-founded semantics for propositional logic programs with negation [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
We assume a countably infinite set Npa of propositional atoms, also called positive literals. A
negative literal is an expression of the form ¬, where  ∈ Npa. A literal is either a positive or a
negative literal. A rule  is an expression of the form ℎ ← 1, . . . ,  where ℎ is a propositional
atom, and 1, . . . ,  are literals. The atom ℎ is called the head of  , denoted head( ). We let
body( ) = {1, . . . , }. A program  is any finite set of rules.
      </p>
      <p>A (3-valued) interpretation  is any set of literals such that {, ¬} ̸⊆  for any . Intuitively,
if  is a propositional atom such that  ∈ , then  is true in . If ¬ ∈ , then  is false in . If
neither  ∈  nor ¬ ∈ , then the truth value of  is undefined in .</p>
      <p>A set  of propositional atoms is called an unfounded set w.r.t. an interpretation  and a
program  , if at least one of the following holds for all rules  ∈  :
(i) head( ) ̸∈  ,
(ii) there is a positive literal  ∈ body( ) such that  ∈  or ¬ ∈ , or
(iii) there is a negative literal ¬ ∈ body( ) such that  ∈ .</p>
      <p>For any program  and interpretation , there is a unique ⊆ -maximal unfounded set w.r.t. 
and , which we denote  (). For a program  , we define a pair  and  of operators that
map interpretations to interpretations as follows:
 () = {head( ) | body( ) ⊆ ,  ∈  }
 () =  () ∪ {¬ |  ∈  ()}
Intuitively, by applying the operator  on an interpretation , we augment  with some new
literals: (i) first we include  () that contains immediate consequences of the rules in  and
the literals in , and then (ii) we add the negation of all atoms that can be safely assumed false
according to  (). The operator  is monotonic, i.e.,  (1) ⊆  (2) holds whenever
1 ⊆ 2. Thus  has the least fixpoint lfp( ) which we call the well-founded model of
 , and denote it by WFS ( ). In more detail, we can compute WFS ( ) by considering the
sequence 0, 1, . . . with 0 = ∅ and  =  (− 1) for  &gt; 0. Due to the monotonicity of  ,
this sequence reaches a  such that +1 =  . Then WFS ( ) =  .</p>
      <p>Example 2. Consider the program  consisting of the following rules:
 ← , 
 ← , 
 ← 
 ← ¬

 ← ¬

Let us compute WFS ( ). We start with 0 = ∅. We have  (0) = ∅ and  (0) = {, }. Thus
1 =  (0) = {¬, ¬}. To compute 2, first note that  (1) = {} and  (1) = {, }.
Then 2 =  (1) = {, ¬, ¬}. Observe that  (2) = {, } and  (2) = {}, and thus
3 = 2. Hence WFS ( ) = {, ¬, ¬}.</p>
    </sec>
    <sec id="sec-3">
      <title>3. SHACL Constraints</title>
      <p>
        We recall the (abstract) syntax of SHACL constraints, mainly following the approach in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
We assume countably infinite, mutually disjoint sets Nnode, Nclass, Nprop, Nshape, Nvar of nodes,
class names, property names, shape names, and variables, respectively. If  ∈ Nprop, then − is
the inverse property of . We let N±prop = Nprop ∪ {− |  ∈ Nprop} and let (− )− =  for any
 ∈ Nprop. Each  ∈ N±prop is a basic property. A property path is an expression  built using
the grammar
      </p>
      <p>::=  |  ∘  |  ∪  | *
where  ∈ N±prop.</p>
      <p>A data graph is a pair  = (Δ , ·  ), where Δ ⊆ Nnode is a set of nodes (called domain),
and ·  is a function that assigns to every class name  ∈ Nclass some set of nodes  ⊆ Δ ,
and to every property name  ∈ Nprop some binary relation  ⊆ Δ × Δ . For a property
name , we let (− ) = {(′, ) | (, ′) ∈  }. Furthermore, the function ·  is extended to all
property paths as follows:
(1 ∘ 2) = (1) ∘ (2)
(1 ∪ 2) = (1) ∪ (2)</p>
      <p>(* ) = ( )*
SHACL constraints. A shape expression  is an expression built according to the following
grammar:</p>
      <p>::=  |  | ¬ |  | ¬ |  ∧  |  ∨  |  | ∃.
where  ∈ Nnode,  ∈ Nclass,  ∈ Nshape,  ∈ Nvar, and  is a complex path. A shape
constraint is an expression of the form  ←  , where  ∈ Nshape and  is a shape expression. In
the following, when considering a set  of shape constraints, we always require that (a)  1 =  2
for any pair  ←  1 and  ←  2 of shape constraints in , and (b) for every shape name 
that appears in , there is  such that  ←  ∈ . The above just says that every shape name
that appears in  has exactly one “definition”. Concretely, for such a constraint set  and a
shape name  that appears in , we let () denote the unique  such that  ←  ∈ . A shape
expression is ground if it contains no variables. In what follows we only consider ground shape
expressions, with a small exception in Section 5 where variables are used as an auxiliary tool to
obtain a translation into logic programs. Note that the SHACL standard does not allow variables
in shape expressions. We also note that the syntax above does not support property pair equality,
property pair disjointness, cardinality constraints, and negation of complex expressions; these
features are described in the W3C standard, but we omit them here for presentation reasons
(they will be added and discussed in the extended version of this paper).</p>
      <p>
        A target is a pair (ℓ, ), where ℓ ∈ Nnode ∪ Nclass ∪ N±prop and  ∈ Nshape. A SHACL document
is a pair (,  ), where  is a set of shape constraints and  is a set of targets. We will next
discuss the validation of a graph  against a SHACL document (,  ). For this we require that
the nodes that explicitly appear in  or  are also included in the domain Δ .
Supported model semantics. We present next the basic 2-valued semantics of recursive
SHACL due to Corman et al. [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. A shape assignment for  is any function  that maps every
shape name  ∈ Nshape to a subset  () ⊆ Δ . For a data graph  and a shape assignment 
for , we define a function · , that maps every shape expression  to a set  , of nodes as
shown in Figure 2. We say a graph  is valid against a SHACL document (,  ), if there exists
a shape assignment  such that:
1.  () =  , for all constraints  ←  ∈ , and
2. for all (ℓ, ) ∈  we have:
• if ℓ is a node  ∈ Nnode, then  ∈  (),
• if ℓ is a class name , then  ⊆  (),
• if ℓ is a property name , then { | (, ′) ∈  } ⊆  (), and
• if ℓ = − for a property name , then {′ | (, ′) ∈  } ⊆  ().
      </p>
      <p>Example 3. Consider a SHACL document (,  ) consisting of the following:
 = {1 ← ∃ .¬, 2 ← ¬
1, 3 ←
 ∧ ¬4, 4 ←</p>
      <p>∧ ¬3, 5 ← ∃ .5}
 = {(, 1), (, 2), (, 5)}
Consider a data graph  with Δ = {, } and
 = {}</p>
      <p>= {}  = {(, )}  = {(, )}
It easy to see that  is valid against (,  ), which is witnessed, e.g., by the shape assignment
 such that  (1) =  (5) = {},  (2) =  (3) = {},  (4) = ∅. This example already
illustrates a drawback of the supported model semantics:  is inferred to satisfy 5 because it has
an -connection to a node that satisfies 5. However,  has only a singe -connection to itself, i.e.,
we have self-justification.</p>
      <p>Consider the targets 1 = {(, 3)}, 2 = {(, 4)}, 3 = {(, 3), (, 4)}. Observe that  is
valid against (, 1) and (, 2) individually, but  does not validate 3 as we cannot assign both 3</p>
      <p>⌈⌉ = { ∈ Δ | ¬() ̸∈ }
⌈¬⌉ = { ∈ Δ | () ̸∈ }
[] = {}
[] = { |  ∈ }
[¬] = { |  ∈ Δ ∖ }
[ 1 ∧  2] = [ 1] ∩ [ 2]
[ 1 ∨  2] = [ 1] ∪ [ 2]
[∃. ] = { | ∃′ : (, ′) ∈  ∧ ′ ∈ [ ]}
and 4 to  in a single shape assignment. This phenomenon could be undesired in certain situations:
when a stronger notion of validation is desired, we may expect that a graph validates  ′ ∪  ′′
whenever it validates  ′ and  ′′. The well-founded semantics introduced next has this feature.</p>
      <p>
        Note that by introducing an inconsistency in , e.g., by adding the constraint 6 ← ¬ 6, we
lose the existence of a shape assignment, and thus no target gets validated, including  = ∅.
This is partially resolved by considering a 3-valued supported model semantics, which does
not require determining the truth value of all shape names [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. However, this does not resolve
the problem of self-justifications, which can be dealt with by using the 2-valued and 3-valued
stable model semantics of Andreşel et al. [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. See also [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] for an approach based on Magic Sets
to increase inconsistency tolerance of the 2-valued stable model semantics in SHACL.
      </p>
    </sec>
    <sec id="sec-4">
      <title>4. Well-founded Semantics for SHACL</title>
      <p>
        We are now ready to define a well-founded semantics for SHACL. We do this by adapting the
notion of unfounded sets and fixpoint computations from [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. We first need our version of
3-valued interpretations in the context of SHACL.
      </p>
      <p>A shape atom is an expression of the form (), where  ∈ Nshape and  ∈ Nnode. A negated
shape atom is an expression ¬(), where () is an atom. A (shape) literal is a possibly negated
shape atom. A (3-valued) interpretation (for SHACL constraints) is any set  of shape literals
such that there is no () ∈  with ¬() ∈ . Intuitively, an atom () ∈  means that there
is a justification that  holds at , a literal ¬() ∈  means that there is no reason for  to hold
at , while {(), ¬()} ∩  = ∅ corresponds to the case where the the satisfaction of  at  is
undefined . For a set  of shape atoms, let ¬. = {¬() | () ∈ }.</p>
      <p>Definition 1. For a given graph  and an interpretation , we define two functions ⌊·⌋  and ⌈·⌉ 
that map every shape expression to a set of nodes. These functions are defined in Figure 3.
Assume a data graph  and a constraint  ←  . Suppose we “believe” a set  of shape literals,
i.e., we assume that all literals in  are true. Then ⌊ ⌋ and ⌈ ⌉ return us the nodes of  where
 is certainly true and where  is possibly true, respectively. Thus ⌊ ⌋
 can be used to infer
positive shape literals: if  ∈ ⌊ ⌋, then we can infer (). We can use ⌈ ⌉ to infer negative
information: if  ̸∈ ⌈ ⌉, then we can infer ¬(). These inferences are formalized next.
Definition 2. Assume a data graph  and a set  of constraints. We define an operator ,(· )
that maps interpretations into interpretations as follows:</p>
      <p>,() = {() |  ←  ∈ ,  ∈ ⌊ ⌋}
We are now ready to define the notion of an unfounded set of shape atoms.</p>
      <p>Definition 3 (Unfounded set). Assume an interpretation , a data graph , and a set  of
constraints. A set  of shape atoms is called an unfounded set w.r.t. ,  and , if  ̸∈ ⌈()⌉∪¬.
for all () ∈  .</p>
      <p>Assume a data graph , a set  of shape atoms, and suppose we “believe” a set  of shape
literals. Intuitively, the atoms in  form an unfounded set (and can thus be simultaneously
set to false) if none of the shape atoms () ∈  can possibly be implied by the associated
constraint, assuming the negation of the atoms in  holds (in addition to  being true).</p>
      <p>The following property follows from the fact that 1 ∪ 2 is an unfounded set w.r.t. ,  and
 whenever 1, 2 are two unfounded sets w.r.t. ,  and .</p>
      <p>Proposition 1. Assume an interpretation , a data graph , and a set  of constraints. There
exists a unique set  such that
1.  is an unfounded set w.r.t. ,  and , and
2. there is no  ′ ⊃  that is unfounded set w.r.t. ,  and .</p>
      <p>The unique set  in the proposition above is called the greatest unfounded set w.r.t. ,  and .
Assume a data graph  and a set  of constraints. We let , be the operator that maps every
interpretation  to the greatest unfounded set w.r.t. ,  and . Thus, ,() is the maximal
set of shape atoms that we can safely set to false if we assume that the literals in  are true.
We can now finally define a well-founded semantics for SHACL. We define an operator ,
that maps interpretations into interpretations as follows: It combines the positive consequences
based on the , operator and the negated atoms of the greatest unfounded set produced by
the , operator. More formally, we define:</p>
      <p>,() = ,() ∪ ¬.,()
The above operator is monotone, i.e., ,(1) ⊆ ,(2) whenever 1, 2 are two
interpretations with 1 ⊆ 2. Thus , has the least fixpoint, i.e., there exists  such that (i)
,() = , and (ii) there is no ′ ⊂  with ,(′) = ′. We use WFS (, ) to denote
the least fixpoint of ,, and call it the well-founded model of  and . WFS (, ) can be
obtained by constructing a sequence 0, 1, 2, . . . such that 0 = ∅ and +1 = ,()
until eventually an index  is reached were  = +1. Then WFS (, ) =  .</p>
      <p>We can now define validation under the well-founded semantics. We say a graph  is valid
against a SHACL document (,  ) (under the well-founded semantics), if for all (ℓ, ) ∈ 
we have:
• if ℓ is a node  ∈ Nnode, then () ∈ WFS (, ),
• if ℓ is a class name , then () ∈ WFS (, ) for all  ∈  ,
• if ℓ is a property name , then () ∈ WFS (, ) for all  with (, ) ∈  ,
• if ℓ = − for  ∈ Nprop, then () ∈ WFS (, ) for all  with (, ) ∈  .
Example 4. Consider the data graph  and the constraint set  from Example 1. It is not
dififcult to check that WFS (, ) contains ProfessorShape(Blake), StudentShape(Cameron),</p>
      <sec id="sec-4-1">
        <title>EmployeeShape(Alex ), EmployeeShape(Blake). Observe also that ProfessorShape(Alex ) ̸∈</title>
      </sec>
      <sec id="sec-4-2">
        <title>WFS (, ) and ¬ProfessorShape(Alex ) ̸∈ WFS (, ), i.e., membership of Alex in</title>
        <p>ProfessorShape is undetermined, which is intuitive as discussed in Example 1. For the
remaining shape atoms over the signature of  and , we have that WFS (, )
contains their negation. Thus  is valid against (, {(Blake, ProfessorShape)}) but not valid
w.r.t. (, {(Drew , ProfessorShape)}).</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5. From SHACL to Propositional Logic Programs</title>
      <p>Assume a graph  and a set  of constraints. We show how to compute a propositional logic
program , from  and  such that the well-founded model of , corresponds to the
well-founded model of  and . We define our target program as , = ⋃︀←  ∈ , , where
each , is defined as follows.</p>
      <p>Assume a constraint  ←  . First, perform the following replacement in  exhaustively
until no further replacement is possible: find a position in  where a negative shape literal ¬
occurs, and replace ¬ by a fresh variable ¬. Second, perform the following replacement in 
exhaustively: find a position in  where a positive shape literal  occurs, and replace  by a fresh
variable . After these steps, we have that the shape expression  ′ that is produced from  has
a tuple of variables ⃗ = (1¬1 , . . . ,</p>
      <p>¬ , ++11 , . . . ,  ). Then the program , consists of the
propositional rule () ← ¬ 1(1), . . . , ¬(), +1(+1), . . . , () for every node  and
every node tuple ⃗ = (1, . . . , ) such that  ∈ ( ′[⃗/]),∅. Here  [⃗/⃗] denotes the shape
⃗
expression that is obtained from  by performing the substitution of variables ⃗ by nodes ⃗.
Proposition 2. If  is a graph and  is a constraint set, then WFS (, ) = WFS (,). The
size of , is exponential in the size of  and , but it is only polynomial in case the number of
shape names in every constraint is bounded by a constant.</p>
      <p>
        Note that, for a given  ←  , the relevant node tuples (, 1, . . . , ) above can be computed
by posing a single SPARQL query over , in a similar way as in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. This opens a way to
implement validation under the new semantics by exploiting existing SPARQL endpoints. We
also remark that, by introducing fresh shape names, we can rewrite a given SHACL document
in a way that its shape expressions contain at most 2 shape names, thus obtaining a polynomial
transformation from SHACL to propositional logic programs under the well-founded semantics.
However, our initial experiments show that aiming for a guaranteed polynomial time translation
does not necessarily lead to increased eficiency of validation.
      </p>
    </sec>
    <sec id="sec-6">
      <title>6. Discussion</title>
      <p>
        In this paper we have defined a well-founded semantics for SHACL constraints with cyclic
dependencies. This semantics is not only intuitive and based on well-established principles
in logic programming and deductive databases, but it also has advantages over the previous
approaches (based on supported and stable models) in terms of semantic and computational
properties, i.e., it avoids unfounded justifications and is tractable. We note that our semantics
has a direct connection to the so-called cautious validation under the 3-valued stable model
semantics in [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], which is due to the classic result by Przymusinski [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
      </p>
      <p>
        We have also established a connection between the SHACL semantics introduced here and
the well-founded semantics for logic programs. We are currently working on an implementation
of a SHACL validator that directly exploits this connection: Given a graph  and a constraint
set , it issues SPARQL queries over  in order to compute a propositional logic program ,,
which can then be sent to a dedicated reasoner to compute the well-founded model of ,.
Our initial experiments using the DLV engine [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] suggest that this is a viable approach; these
results will be presented in the extended version of this paper.
      </p>
      <p>
        There are many research questions for future work. For instance, the computational
complexity of satisfiability and implication of SHACL constraints under the well-founded semantics
is a natural next topic for investigations. Some initial results in this area for the semantics
introduced previously were presented in [
        <xref ref-type="bibr" rid="ref10 ref9">9, 10</xref>
        ]. Due to the syntactic form of shape expressions,
many of those previous results are related to known positive and negative decidability and
complexity results in the area of Description Logics. More broadly, SHACL is related to the
problem of reconciling the open-world assumption (as in OWL and Description Logics) with the
closed-world assumption (as in databases and logic programming). E.g., validation in SHACL
under the supported model semantics can be seen as checking the satisfiability of a Description
Logic ontology where all but some selected concept names are closed predicates. Supporting
ontological inferences in the context of SHACL validation is an interesting research direction,
which is also hinted at by the SHACL standard. More details on the challenges of combining
open- and closed-world assumptions can be found in [
        <xref ref-type="bibr" rid="ref11 ref12">11, 12</xref>
        ]. Another natural direction is
to study explanations and repairs of violations of SHACL constraints under the well-founded
semantics: these topics are natural as the SHACL standard calls for (but does not specify the
details of) the so-called validation reports to support users and applications. Some initial work
on explaining and repairing violations of SHACL constraints was reported in [
        <xref ref-type="bibr" rid="ref13 ref14">13, 14</xref>
        ].
      </p>
    </sec>
    <sec id="sec-7">
      <title>Acknowledgments</title>
      <p>This work was partially supported by the Wallenberg AI, Autonomous Systems and Software
Program (WASP) funded by the Knut and Alice Wallenberg Foundation. It was also partially
supported by the Austrian Science Fund (FWF) projects P30360 and P30873, and by the Vienna
Business Agency’s project CoRec.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>J.</given-names>
            <surname>Corman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. L.</given-names>
            <surname>Reutter</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Savkovic</surname>
          </string-name>
          ,
          <article-title>Semantics and validation of recursive SHACL</article-title>
          ,
          <source>in: Proc. of ISWC</source>
          <year>2018</year>
          , volume
          <volume>11136</volume>
          <source>of LNCS</source>
          , Springer,
          <year>2018</year>
          , pp.
          <fpage>318</fpage>
          -
          <lpage>336</lpage>
          . URL: https: //doi.org/10.1007/978-3-
          <fpage>030</fpage>
          -00671-6_
          <fpage>19</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>M.</given-names>
            <surname>Andreşel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Corman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ortiz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. L.</given-names>
            <surname>Reutter</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Savkovic</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Šimkus</surname>
          </string-name>
          ,
          <article-title>Stable model semantics for recursive SHACL</article-title>
          ,
          <source>in: WWW '20: The Web Conference</source>
          <year>2020</year>
          , ACM / IW3C2,
          <year>2020</year>
          , pp.
          <fpage>1570</fpage>
          -
          <lpage>1580</lpage>
          . URL: https://doi.org/10.1145/3366423.3380229.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>P.</given-names>
            <surname>Pareti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Konstantinidis</surname>
          </string-name>
          ,
          <article-title>A review of SHACL: from data validation to schema reasoning for RDF graphs</article-title>
          , in: [15],
          <year>2021</year>
          . URL: https://doi.org/10.1007/978-3-
          <fpage>030</fpage>
          -95481-
          <issue>9</issue>
          _
          <fpage>6</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Van Gelder</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K. A.</given-names>
            <surname>Ross</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. S.</given-names>
            <surname>Schlipf</surname>
          </string-name>
          ,
          <article-title>The well-founded semantics for general logic programs</article-title>
          ,
          <source>J. ACM</source>
          <volume>38</volume>
          (
          <year>1991</year>
          )
          <fpage>619</fpage>
          -
          <lpage>649</lpage>
          . URL: https://doi.org/10.1145/116825.116838.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>S.</given-names>
            <surname>Ahmetaj</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Loehnert</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ortiz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Šimkus</surname>
          </string-name>
          ,
          <article-title>Magic shapes for validation in SHACL</article-title>
          ,
          <source>Proceedings of the VLDB Endowment. Volume 15 Issue</source>
          <volume>10</volume>
          (to appear) (
          <year>2022</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>J.</given-names>
            <surname>Corman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Florenzano</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. L.</given-names>
            <surname>Reutter</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Savkovic</surname>
          </string-name>
          ,
          <article-title>Validating SHACL constraints over a SPARQL endpoint</article-title>
          ,
          <source>in: Proc. of ISWC</source>
          <year>2019</year>
          , volume
          <volume>11778</volume>
          <source>of LNCS</source>
          , Springer,
          <year>2019</year>
          , pp.
          <fpage>145</fpage>
          -
          <lpage>163</lpage>
          . URL: https://doi.org/10.1007/978-3-
          <fpage>030</fpage>
          -30793-
          <issue>6</issue>
          _
          <fpage>9</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>T. C.</given-names>
            <surname>Przymusinski</surname>
          </string-name>
          ,
          <article-title>The well-founded semantics coincides with the three-valued stable semantics</article-title>
          ,
          <source>Fundam. Inform</source>
          .
          <volume>13</volume>
          (
          <year>1990</year>
          )
          <fpage>445</fpage>
          -
          <lpage>463</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>N.</given-names>
            <surname>Leone</surname>
          </string-name>
          , G. Pfeifer,
          <string-name>
            <given-names>W.</given-names>
            <surname>Faber</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Eiter</surname>
          </string-name>
          , G. Gottlob,
          <string-name>
            <given-names>S.</given-names>
            <surname>Perri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Scarcello</surname>
          </string-name>
          ,
          <article-title>The dlv system for knowledge representation and reasoning</article-title>
          .,
          <source>ACM Trans. Comput. Log</source>
          .
          <volume>7</volume>
          (
          <year>2006</year>
          )
          <fpage>499</fpage>
          -
          <lpage>562</lpage>
          . URL: http://dblp.uni-trier.de/db/journals/tocl/tocl7.html#LeonePFEGPS06.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>P.</given-names>
            <surname>Pareti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Konstantinidis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Mogavero</surname>
          </string-name>
          ,
          <article-title>Satisfiability and containment of recursive SHACL</article-title>
          ,
          <source>Journal of Web Semantics</source>
          <volume>74</volume>
          (
          <year>2022</year>
          )
          <article-title>100721</article-title>
          . URL: https:// www.sciencedirect.com/science/article/pii/S1570826822000130. doi:https://doi.org/ 10.1016/j.websem.
          <year>2022</year>
          .
          <volume>100721</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>M.</given-names>
            <surname>Leinberger</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Seifer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Rienstra</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Lämmel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Staab</surname>
          </string-name>
          ,
          <article-title>Deciding SHACL shape containment through description logics reasoning</article-title>
          ,
          <source>in: Proc. of ISWC 2020</source>
          , Springer,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>M.</given-names>
            <surname>Knorr</surname>
          </string-name>
          ,
          <article-title>On combining ontologies and rules</article-title>
          , in: [15],
          <year>2021</year>
          , pp.
          <fpage>22</fpage>
          -
          <lpage>58</lpage>
          . URL: https: //doi.org/10.1007/978-3-
          <fpage>030</fpage>
          -95481-
          <issue>9</issue>
          _
          <fpage>2</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>T.</given-names>
            <surname>Schneider</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Šimkus</surname>
          </string-name>
          ,
          <article-title>Ontologies and data management: A brief survey</article-title>
          ,
          <source>Künstliche Intell</source>
          .
          <volume>34</volume>
          (
          <year>2020</year>
          )
          <fpage>329</fpage>
          -
          <lpage>353</lpage>
          . URL: https://doi.org/10.1007/s13218-020-00686-3.
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>S.</given-names>
            <surname>Ahmetaj</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>David</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ortiz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Polleres</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Shehu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Šimkus</surname>
          </string-name>
          ,
          <article-title>Reasoning about Explanations for Non-validation in SHACL</article-title>
          ,
          <source>in: Proc. of KR</source>
          <year>2021</year>
          ,
          <year>2021</year>
          , pp.
          <fpage>12</fpage>
          -
          <lpage>21</lpage>
          . URL: https://doi.org/10.24963/kr.2021/2.
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>R.</given-names>
            <surname>David</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Ahmetaj</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Polleres</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Šimkus</surname>
          </string-name>
          ,
          <article-title>Repairing SHACL constraint violations using answer set programming</article-title>
          ,
          <source>in: Proc. of ISWC</source>
          <year>2022</year>
          (to appear), Springer,
          <year>2022</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>M.</given-names>
            <surname>Šimkus</surname>
          </string-name>
          , I. Varzinczak (Eds.),
          <source>Reasoning Web. Declarative Artificial Intelligence - 17th International Summer School</source>
          <year>2021</year>
          ,
          <year>2021</year>
          , Tutorial Lectures, volume
          <volume>13100</volume>
          <source>of LNCS</source>
          , Springer,
          <year>2022</year>
          . URL: https://doi.org/10.1007/978-3-
          <fpage>030</fpage>
          -95481-9.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>