Flexible coinductive logic programming
aa r X i v : . [ c s . P L ] A ug Under consideration for publication in Theory and Practice of Logic Programming Flexible coinductive logic programming
FRANCESCO DAGNINO, DAVIDE ANCONA, ELENA ZUCCA
DIBRIS, University of Genova ( e-mail: [email protected], { davide.ancona,elena.zucca } @unige.it ) submitted 1 January 2003; revised 1 January 2003; accepted 1 January 2003 Abstract
Recursive definitions of predicates are usually interpreted either inductively or coinductively. Recently, amore powerful approach has been proposed, called flexible coinduction , to express a variety of intermediateinterpretations, necessary in some cases to get the correct meaning. We provide a detailed formal accountof an extension of logic programming supporting flexible coinduction. Syntactically, programs are enrichedby coclauses , clauses with a special meaning used to tune the interpretation of predicates. As usual, thedeclarative semantics can be expressed as a fixed point which, however, is not necessarily the least, northe greatest one, but is determined by the coclauses. Correspondingly, the operational semantics is a com-bination of standard SLD resolution and coSLD resolution. We prove that the operational semantics issound and complete with respect to declarative semantics restricted to finite comodels. This paper is underconsideration for acceptance in TPLP.
KEYWORDS : coinduction, operational semantics, declarative semantics, soundness, completeness
Standard inductive and coinductive semantics of logic programs sometimes are not enough toproperly define predicates on possibly infinite terms (Simon et al. 2007; Ancona 2013).Consider the logic program in Fig. 1, defining some predicates on lists of numbers representedwith the standard Prolog syntax. For simplicity, we consider built-in numbers, as in Prolog.In standard logic programming, terms are inductively defined, that is, are finite, and predicatesare inductively defined as well. In the example program, only finite lists are considered, such as,e.g., [1|[2|[]]] , and the three predicates are correctly defined on such lists.Coinductive logic programming (coLP) (Simon 2006) extends standard logic programmingwith the ability of reasoning about infinite objects and their properties. Terms are coinductively all pos ([ ]) ← all pos ([ N | L ]) ← N > , all pos ( L ) . member ( X , [ X | ]) ← member ( X , [ Y | L ]) ← X = Y , member ( X , L ) . maxElem ([ N ] , N ) ← maxElem ([ N | L ] , M ) ← maxElem ( L , M ) , M is max ( N , M ) . Fig. 1. An example of logic program: all pos ( l ) succeeds iff l contains only positive numbers, member ( x , l ) succeeds iff x is in l , maxElem ( l , x ) succeeds iff x is the greatest number in l . F. Dagnino, D. Ancona, and E. Zucca defined, that is, can be infinite, and predicates are coinductively defined as well. In the example,also infinite lists, such as [1|[2|[3|[4|...]]]] , are considered, and the coinductive interpreta-tion of all pos gives the expected meaning on such lists. However, this is not the case for theother two predicates: for member the correct interpretation is still the inductive one, as in thecoinductive semantics member ( x , l ) always succeeds for an infinite list l . For instance, for L theinfinite list of 0’s, member ( , L ) has an infinite proof tree where for each node we apply the sec-ond clause. Therefore, these two predicates cannot coexist in the same program, as they requiretwo different interpretations. The predicate maxElem shows an even worse situation. The inductive semantics again doesnot work on infinite lists, but also the coinductive one is not correct: maxElem ( l , n ) succeedswhenever n is greater than all the elements of l . The expected meaning lies between the inductiveand the coinductive semantics, hence, to get it, we need something beyond standard semantics.Recently, in the more general context of inference systems (Aczel 1977), flexible coinduction has been proposed by Dagnino and Ancona et al. (2017; 2017b; 2019), a generalisation able toexpress a variety of intermediate interpretations. As we recall in Section 2, clauses of a logicprogram can be seen as meta-rules of an inference system where judgments are ground atoms.Inference rules are ground instances of clauses, and a ground atom is valid if it has a finite prooftree in the inductive interpretation, a possibly infinite proof tree in the coinductive one.Guided by this abstract view, which provides solid foundations, we develop an extension oflogic programming supporting flexible coinduction.Syntactically, programs are enriched by coclauses , which resemble clauses but have a spe-cial meaning used to tune the interpretation of predicates. By adding coclauses, we can ob-tain a declarative semantics intermediate between the inductive and the coinductive one. Stan-dard (inductive) and coinductive logic programming are subsumed by a particular choice of co-clauses. Correspondingly, operational semantics is a combination of standard SLD resolution(Lloyd 1987; Apt 1997) and coSLD resolution as introduced by Simon et al. (2006; 2006; 2007).More precisely, as in coSLD resolution, it keeps trace of already considered goals, called coin-ductive hypotheses . However, when a goal unifying with a coinductive hypothesis is found,rather than being considered successful as in coSLD resolution, its standard SLD resolution istriggered in the program where also coclauses are considered. Our main result is that such oper-ational semantics is sound and complete with respect to the declarative one restricted to regularproof trees.An important additional result is that the operational semantics is not incidental, but, as thedeclarative semantics, turns out to correspond to a precise notion on the inference system de-noted by the logic program. Indeed, as detailed in a companion paper of Dagnino (2020), givenan inference system, we can always construct another one, with judgments enriched by circu-lar hypotheses, which, interpreted inductively, is equivalent to the regular interpretation of theoriginal inference system. In other words, there is a canonical way to derive a (semi-)algorithmto show that a judgment has a regular proof tree, and our operational semantics corresponds tothis algorithm. This more abstract view supports the reliability of the approach, and, indeed, the To overcome this issue, co-logic programming (Simon et al. 2007) marks predicates as either inductive or coinductive.The declarative semantics, however, becomes quite complex, because stratification is needed. We prefer to mantain this terminology, inherited from coSLD resolution, even though not corresponding to the prooftheoretic sense. proof of equivalence with declarative semantics can be nicely done in a modular way, that is, byrelying on a general result proved by Dagnino (2020).After basic notions in Section 2, in Section 3 we introduce logic programs with coclauses andtheir declarative semantics, and in Section 4 the operational semantics. We provide significantexamples in Section 5, the results in Section 6, related work and conclusive remarks in Section 7.
We recall basic concepts about inference systems (Aczel 1977), and present (standard inductiveand coinductive) logic programming (Lloyd 1987; Apt 1997; Simon 2006; Simon et al. 2006;Simon et al. 2007) as a particular instance of this general semantic framework.
Inference systems
Assume a set U called universe whose elements j are called judgements . An inference system I is a set of (inference) rules , which are pairs h Pr , c i , also written Prc , with Pr ⊆ U set of premises , and c ∈ U conclusion . We assume inference systems to be finitary , thatis, rules have a finite set of premises. A proof tree (a.k.a. derivation ) in I is a tree with nodes(labelled) in U such that, for each j with set of children Pr , there is a rule h Pr , j i in I . A prooftree for j is a proof tree with root j . The inference operator F I : ℘ ( U ) → ℘ ( U ) is defined by: F I ( X ) = { j ∈ U | h Pr , j i ∈ I for some Pr ⊆ X } A set X ⊆ U is closed if F I ( X ) ⊆ X , consistent if X ⊆ F I ( X ) , a fixed point if X = F I ( X ) .An interpretation of an inference system I is a set of judgements, that is, a subset of theuniverse U . The two standard interpretations, the inductive and the coinductive one, can bedefined in either model-theoretic or proof-theoretic terms (Leroy and Grall 2009). • The inductive interpretation µ J I K is the intersection of all closed sets, that is, the leastclosed set or, equivalently, the set of judgements with a finite proof tree. • The coinductive interpretation ν J I K is the union of all consistent sets, that is, the greatestconsistent set, or, equivalently, the set of judgements with an arbitrary (finite or not) prooftree.By the fixed point theorem (Tarski 1955), both µ J I K and ν J I K are fixed points of F I , the least andthe greatest one, respectively. We will write I ⊢ µ j for j ∈ µ J I K and I ⊢ ν j for j ∈ ν J I K . Logic programming
Assume a first order signature h P , F , V i with P set of predicate symbolsp , F set of function symbols f , and V countably infinite set of variable symbols X ( variables forshort). Each symbol comes with its arity , a natural number denoting the number of arguments.Variables have arity 0. A function symbol with arity 0 is a constant . Terms t , s , r are (possibly infinite) trees with nodes labeled by function or variable symbols,where the number of children of a node is the symbol arity . Atoms A , B , C are (possibly infinite)trees with the root labeled by a predicate symbol and other nodes by function or variable symbols,again accordingly with the arity. Terms and atoms are ground if they do not contain variables,and finite (or syntactic ) if they are finite trees. (Definite) clauses have shape A ← B , . . . , B n with n ≥ A , B , . . . , B n finite atoms. A clause where n = fact . A (definite) logic programP is a finite set of clauses. For a more formal definition based on paths see, e.g., the work of Ancona and Dovier (2015).
F. Dagnino, D. Ancona, and E. ZuccaSubstitutions θ , σ are partial maps from variables to terms with a finite domain. We write t θ for the application of θ to a term t , call t θ an instance of t , and analogously for atoms, set ofatoms, and clauses. A substitution θ is ground if, for all X ∈ dom ( θ ) , θ ( X ) is ground, syntactic if, for all X ∈ dom ( θ ) , θ ( X ) is a finite (syntactic) term.In order to see a logic program P as an inference system, we fix as universe the completeHerbrand base HB ∞ , that is, the set of all (finite and infinite) ground atoms . Then, P can be seenas a set of meta-rules defining an inference system k P k on HB ∞ . That is, k P k is the set of groundinstances of clauses in P , where A ← B , . . . , B n is seen as an inference rule h{ B , . . . , B n } , A i .In this way, typical notions related to declarative semantics of logic programs turn out to beinstances of analogous notions for inference systems. Notably, the (one step) inference operatorassociated to a program T P : ℘ ( HB ∞ ) → ℘ ( HB ∞ ) , defined by: T P ( I ) = { A ∈ HB ∞ | ( A ← B , . . . , B n ) ∈ k P k , { B , . . . , B n } ⊆ I } is exactly F k P k . An interpretation (a set I ⊆ HB ∞ ) is a model of a program P if T P ( I ) ⊆ I , thatis, it is closed with respect to k P k . Dually, an interpretation I is a comodel of a program P if I ⊆ T P ( I ) , that is, it is consistent with respect to k P k . Then, the inductive declarative semanticsof P is the least model of P and the coinductive declarative semantics is the greatest comodelof P . These two semantics coincide with the inductive and coinductive interpretations of k P k ,hence we denote them by µ J P K and ν J P K , respectively. We introduce logic programs with coclauses and define their declarative semantics. Consideragain the example in Fig. 1 where, as discussed in the Introduction, each predicate needed adifferent kind of interpretation.As shown in the previous section, the above logic program can be seen as an inference sys-tem. In this context, flexible coinduction has been proposed (Dagnino 2017; Ancona et al. 2017b;Dagnino 2019), a generalisation able to overcome these limitations. The key notion are corules ,special inference rules used to control the semantics of an inference system. More precisely, a generalized inference system , or inference system with corules , is a pair of inference systems h I , I co i , where the elements of I co are called corules. The interpretation of h I , I co i , denoted by ν fl J I , I co K , is constructed in two steps. • first, we take the inductive interpretation of the union I ∪ I co , that is, µ J I ∪ I co K , • then, the union of all sets, consistent with respect to I , which are subsets of µ J I ∪ I co K ,that is, the largest consistent subset of µ J I ∪ I co K .In proof-theoretic terms, ν fl J I , I co K is the set of judgements with an arbitrary (finite or not) prooftree in I , whose nodes all have a finite proof tree in I ∪ I co . Essentially, by corules we filter outsome, undesired, infinite proof trees. Dagnino (2019) proved that ν fl J I , I co K is a fixed point of F I .To introduce flexible coinduction in logic programming, first we slightly extend the syntax byintroducing (definite) coclauses , written A ⇐ B , . . . , B n , where A , B , . . . , B n are finite atoms. Acoclause where n = 0 is called a cofact . Coclauses syntactically resemble clauses, but are used in aspecial way, like corules for inference systems. More precisely, we have the following definition: Traditionally (Lloyd 1987), the inductive declarative semantics is restricted to finite atoms. We define also the inductivesemantics on the complete Herbrand base in order to work in a uniform context. Introduced (Simon 2006; Simon et al. 2006) to properly deal with predicates on infinite terms.
Definition 3.1 A logic program with coclauses is a pair h P , P co i where P and P co are sets of clauses. Its declara-tive semantics , denoted by ν fl J P , P co K , is the largest comodel of P which is a subset of µ J P ∪ P co K .In other words, the declarative semantics of h P , P co i is the coinductive semantics of P where,however, clauses are instantiated only on elements of µ J P ∪ P co K . Note that this is the interpreta-tion of the generalized inference system hk P k , k P co ki .Below is the version of the example in Fig. 1, equipped with coclauses. all pos ([ ]) ← all pos ([ N | L ]) ← N > , all pos ( L ) . all pos ( ) ⇐ member ( X , [ X | ]) ← member ( X , [ Y | L ]) ← X = Y , member ( X , L ) . maxElem ([ N ] , N ) ← maxElem ([ N | L ] , M ) ← maxElem ( L , M ) , M is max ( N , M ) . maxElem ([ N | ] , N ) ⇐ In this way, all the predicate definitions are correct w.r.t. the expected semantics: • all pos has coinductive semantics, as the coclause allows any infinite proof trees. • member has inductive semantics, as without coclauses no infinite proof tree is allowed. • maxElem has an intermediate semantics, as the coclause allows only infinite proof treeswhere nodes have shape maxElem ( l , x ) with x an element of l .As the example shows, coclauses allow the programmer to mix inductive and coinductive predi-cates, and to correctly define predicates which are neither inductive, nor purely coinductive. Forthis reason we call this paradigm flexible coinductive logic programming. Note that, as shown forinference systems with corules (Dagnino 2017; Ancona et al. 2017b; Dagnino 2019), inductiveand coinductive semantics are particular cases. Indeed, they can be recovered by special choicesof coclauses: the former is obtained when no coclause is specified, the latter when each atom in HB ∞ is an instance of the head of a cofact. In this section we define an operational counterpart of the declarative semantics of logic programswith coclauses introduced in the previous section.As in standard coLP (Simon 2006; Simon et al. 2006; Simon et al. 2007), to represent possiblyinfinite terms we use finite sets of equations between finite (syntactic) terms. For instance, theequation L ≖ [1,2|L] represents the infinite list [1,2,1,2,...] .Since the declarative semantics of logic programs with coclauses is a combination of induc-tive and coinductive semantics, their operational semantics combines standard SLD resolution(Lloyd 1987; Apt 1997) and coSLD resolution (Simon 2006; Simon et al. 2006; Simon et al. 2007).It is presented, rather than in the traditional small-step style, in big-step style, as introduced byAncona and Dovier (2015). This style turns out to be simpler since coinductive hypotheses (seebelow) can be kept local. Moreover, it naturally leads to an interpreter, and makes it simpler toprove its correctness with respect to declarative semantics (see the next section). F. Dagnino, D. Ancona, and E. Zucca ( EMPTY ) h P , P co i ; S (cid:13) h ε ; E i ⇒ E ( CO - HYP ) h P ∪ P co , /0 i ; /0 (cid:13) (cid:10) A ; E ∪ E A , B (cid:11) ⇒ E h P , P co i ; S (cid:13) h G , G ; E i ⇒ E h P , P co i ; S (cid:13) h G , A , G ; E i ⇒ E B ∈ SE ⊢ A = BP co = /0 ( STEP ) h P , P co i ; S ∪ { A } (cid:13) (cid:10) C ,..., C n ; E ∪ E A , B (cid:11) ⇒ E h P , P co i ; S (cid:13) h G , G ; E i ⇒ E h P , P co i ; S (cid:13) h G , A , G ; E i ⇒ E θ fresh renaming B θ ← C θ ,..., C n θ ∈ PE ⊢ A = B Fig. 2. Big-step operational semanticsWe introduce some notations. First of all, in this section we assume atoms and terms to befinite (syntactic). A goal is a pair h G ; E i , where G is a finite sequence of atoms. A goal is empty if G is the empty sequence, denoted ε . An equation has shape s ≖ t where s and t are terms, andwe denote by E a finite set of equations.Intuitively, a goal can be seen as a query to the program and the operational semantics hasto compute answers (a.k.a. solutions) to such a query. More in detail, the operational semantics,given a goal h G ; E i , provides another set of equations E , which represents answers to the goal.For instance, given the previous program, for the goal h maxElem(L,M) ; { L ≖ [1,2|L] }i , theoperational semantics returns the set of equations { L ≖ [1,2|L] , M ≖ } .The judgment of the operational semantics has shape h P , P co i ; S (cid:13) h G ; E i ⇒ E meaning that resolution of h G ; E i , under the coinductive hypotheses S (Simon et al. 2006), suc-ceeds in h P , P co i , producing a set of equations E . Set Var ( t ) the set of variables in a term, andanalogously for atoms, set of atoms, and equations. We assume Var ( S ) ⊆ Var ( E ) , modellingthe intuition that S keeps track of already considered atoms. This condition holds for the initialjudgement, and is preserved by rules in Fig. 2, hence it is not restrictive. Resolution starts withno coinductive hypotheses, that is, the top-level judgment has shape h P , P co i ; /0 (cid:13) h G ; E i ⇒ E .The operational semantics has two flavours: • If there are no corules ( P co = /0), then the judgment models standard SLD resolution, hencethe set of coinductive hypotheses is not significant. • Otherwise, the judgment models flexible coSLD resolution , which follows the same schemaof coSLD resolution, in the sense that it keeps track in S of the already considered atoms.However, when an atom A in the current goal unifies with a coinductive hypothesis, ratherthan just considering A successful as in coSLD resolution, standard SLD resolution of A istriggered in the program P ∪ P co , that is, also coclauses can be used.The judgement is inductively defined by the rules in Fig. 2, which rely on some auxiliary(standard) notions. A solution of an equation s ≖ t is a unifier of t and s , that is, a substitution θ such that s θ = t θ . A solution of a finite set of equations E is a solution of all the equations in E and E is solvable if there exists a solution of E . Two atoms A and B are unifiable in a set ofequations E , written E ⊢ A = B , if A = p ( s , . . . , s n ) , B = p ( t , . . . , t n ) and E ∪ { s ≖ t , . . . , s n ≖ t n } is solvable, and we denote by E A , B the set { s ≖ t , . . . , s n ≖ t n } .Rule ( EMPTY ) states that the resolution of an empty goal succeeds. In rule ( STEP ) , an atom A to beresolved is selected, and a clause of the program is chosen such that A unifies with the head of theclause in the current set of equations. Then, resolution of the original goal succeeds if both the ( S -2) ( S -2) ( C ) ( S -2) ( S -3]) ( MAX ) h{ , , } , /0 i ; /0 (cid:13) h mE([2|L],M3) , M2=max(1,M3) ; eq L , M ≖ M i⇒ eq L , M ≖ M , eqs h{ , , } , /0 i ; /0 (cid:13) h mE(L,M2) ; eq L , M ≖ M i⇒ eq L , M ≖ M , eqs ( MAX ) h{ , } , i ; mE(L,M) (cid:13) h mE(L,M2) , M1=max(2,M2) ; eq L i⇒ eq L , M ≖ M , eqs , M ≖ h{ , } , i ; mE(L,M) (cid:13) h mE([2|L],M1) , M=max(1,M1) ; eq L i⇒ eq L , M ≖ M , eqs , M ≖ ( MAX ) h{ , } , i ; /0 (cid:13) h mE(L,M) ; eq L i⇒ eq L , M ≖ M , eqs , M ≖ , M ≖ Fig. 3. Example of resolutionbody of the selected clause and the remaining atoms are resolved, enriching the set of equationscorrespondingly. As customary, the selected clause is renamed using fresh variables, to avoidvariable clashes in the set of equations obtained after unification. Note that, in the resolution ofthe body of the clause, the selected atom is added to the current set of coinductive hypotheses.This is not relevant for standard SLD resolution ( P co = /0). However, if P co = /0, this allows rule ( CO - HYP ) to handle the case when an atom A that has to be resolved unifies with a coinductivehypothesis in the current set of equations. In this case, standard SLD resolution of such atomin the program P ∪ P co is triggered, and resolution of the original goal succeeds if both suchstandard SLD resolution of the selected atom and resolution of the remaining goal succeed.In Fig. 3 we show an example of resolution. We use the shorter syntax =max , abbreviate by eq L the equation L ≖ [1,2|L] , by eqs the equations M ≖ , M ≖
2, by mE the predicate maxElem ,and by ( S ), ( C ) the rules ( STEP ) and ( CO - HYP ), respectively. When applying rule (
STEP ), wealso indicate the clause/coclause which has been used: we write 1,2,3 for the two clauses and thecoclause for the maxElem predicate (the first clause is never used in this example). Finally, to keepthe example readable and focus on key aspects, we make some simplifications: notably, (
MAX )stands for an omitted proof tree solving atoms of shape is max( , ) ; morever, equationsbetween lists are implicitly applied.As final remark, note that flexible coSLD resolution nicely subsumes both SLD and coSLD.The former, as already said, is obtained when the set of coclauses is empty, that is, the pro-gram is inductive. The latter is obtained when, for all predicate p of arity n , we have a cofact p ( X , . . . , X n ) . In this section we discuss some more sophisticated examples. ∞ -regular expressions: We define ∞ -regular expressions on an alphabet Σ , a variant of the for-malism defined by L¨oding and Tollk¨otter (2016) for denoting languages of finite and infinitewords, the latter also called ω -words, as follows: r :: = /0 | ε | a | r · r | r + r | r ⋆ | r ω where a ∈ Σ . The syntax of standard regular expressions is extended by r ω , denoting the ω -powerof the language A r denoted by r . That is, the set of words obtained by concatenating infinitelymany times words in A r . In this way, we can denote also languages containing infinite words.In Fig. 4 we define the predicate match , such that match ( W , R ) holds if the finite or infiniteword W , implemented as a list, belongs to the language denoted by R . For simplicity, we considerwords over the alphabet { , } . F. Dagnino, D. Ancona, and E. Zucca concat ([ ] , W , W ) ← concat ([ B | W ] , W , [ B | W ]) ← concat ( W , W , W ) . concat ( W , W , W ) ⇐ match ([ ] , eps ) ← match ([ ] , ) ← match ([ ] , ) ← match ( W , cat ( R , R )) ← match ( W , R ) , match ( W , R ) , concat ( W , W , W ) . match ( W , plus ( R , R )) ← match ( W , R ) . match ( W , plus ( R , R )) ← match ( W , R ) . match ( W , star ( R )) ← match star ( N , W , R ) . match ([ ] , omega ( R )) ← match ([ ] , R ) . match ([ B | W ] , omega ( R )) ← match ([ B | W ] , R ) , match ( W , omega ( R )) , concat ( W , W , W ) . match ( W , omega ( R )) ⇐ match star ( , [ ] , R ) ← match star ( s ( N ) , W , R ) ← match ( W , R ) , match star ( N , W , R ) , concat ( W , W , W ) . Fig. 4. A logic program for ∞ -regular expression recognition.Concatenation of words needs to be defined coinductively, to correctly work on infinite wordsas well. Note that, when w is infinite, w w is equal to w .On operators of regular expressions, match can be defined in the standard way (no coclauses).In particular, the definition for expressions of shape r ⋆ follows the explicit definition of the ⋆ -closure of a language: given a language L , a word w belongs to L ⋆ iff it can be decomposedas w . . . w n , for some n ≥
0, where n = w is empty, and w i ∈ L , for all i ∈ .. n . Thiscondition is checked by the auxiliary predicate match star .To define when a word w matches r ω we have two cases. If w is empty, then it is enough tocheck that the empty word matches r , as expressed by the first clause, because concatenatinginfinitely many times the empty word we get again the empty word. Otherwise, we have to de-compose w as w w where w is not empty and matches r and w matches r ω as well, as formallyexpressed by the second clause, To propertly handle infinite words, we need to concatenate in-finitely many non-empty words, hence we need to apply the second clause infinitely many times.The coclause allows all such infinite derivations. An LTL fragment:
In Fig. 5 we define the predicate sat s.t. sat ( w , ϕ ) succeeds iff the ω -word w over the alphabet { , } satisfies the formula ϕ of the fragment of the Linear Temporal Logicwith the temporal operators until ( U ) and always ( G ) and the predicate zero and its negation one . Since sat ([ B | W ] , always ( Ph )) succeeds iff all infinite suffixes of [ B | W ] satisfy formula Ph ,the coinductive interpretation has to be considered, hence a coclause is needed; for instance, sat ( W , always ( zero )) , with W = [ | W ] , succeeds because the atom sat ( W , always ( zero )) inthe body of the clause for always unifies with the coinductive hypothesis sat ( W , always ( zero )) (see rule ( CO - HYP ) in Figure 2) and the coclause allows it to succeed w.r.t. standard SLD resolution(indeed, atom sat ( W , zero ) succeeds, thanks to the first fact in the logic program).Differently to always , the interpretation of until has to be inductive because until ( ϕ , ϕ ) Predicates true and f alse could be easily defined as well. Actually, in this case the atom to be resolved and the coinductive hypothesis are syntactically equal. sat exists ( , W , Ph ) ← sat ( W , Ph ) . sat exists ( s ( N ) , [ B | W ] , Ph ) ← sat exists ( N , W , Ph ) . sat all ( , W , Ph ) ← sat all ( s ( N ) , [ B | W ] , Ph ) ← sat ([ B | W ] , Ph ) , sat all ( N , W , Ph ) . sat ([ | W ] , zero ) ← sat ([ | W ] , one ) ← sat ([ B | W ] , always ( Ph )) ← sat ([ B | W ] , Ph ) , sat ( W , always ( Ph )) . sat ( W , always ( Ph )) ⇐ sat ([ B | W ] , until ( Ph , Ph )) ← sat exists ( N , [ B | W ] , Ph ) , sat all ( N , [ B | W ] , Ph ) . Fig. 5. A logic program for satisfaction of an LTL fragment: sat exists ( N , W , Ph ) succeeds iffsuffix at N of ω -word W satisfies Ph , sat all ( N , W , Ph ) succeeds iff all suffixes of word W atindex < N satisfy Ph , sat ( W , Ph ) succeeds iff ω -word W satisfies Ph .succeeds iff ϕ is satisfied after a finite number of steps; for this reason, no coclause is givenfor this operator; for instance, sat ([ , , | W ] , until ( one , zero )) with W = [ | W ] succeeds w.r.t.standard SLD resolution, while sat ( W , until ( one , zero )) , sat ( W , until ( always ( one ) , zero )) , and sat ( W , until ( always ( one ) , always ( zero ))) fail. The clause for sat ([ B | W ] , until ( Ph , Ph )) fol-lows the standard definition of satisfaction for the U operator: there must exist a suffix of [ B | W ] at index N satisfying Ph ( sat exists ( N , [ B | W ] , Ph ) ) s.t. all suffixes of [ B | W ] at index less than N satisfy Ph ( sat all ( N , [ B | W ] , Ph ) ).An interesting example concerns the goal sat ([ , | W ] , until ( one , always ( zero ))) , where thetwo temporal operators are mixed together: it succeeds as expected, thanks to the two clauses for until and the fact that sat ( W , always ( zero )) succeeds, as shown above.Some of the issues faced in this example are also discussed by Gupta et al. (2011). Big-step semantics modeling infinite behaviour and observations
Defining a big-step operationalsemantics modelling divergence is a difficult task, especially in presence of observations. Anconaet al. (2018; 2020) show how corules can be successfully employed to tackle this problem, by pro-viding big-step semantics able to model divergence for several variations of the lambda-calculusand different kinds of observations. Following this approach, we present in Fig. 6 a similar exam-ple, but simpler, to keep it shorter: a logic program with coclauses defining the big-step semanticsof a toy language to output possibly infinite sequences of integers. Expressions are regular termsgenerated by the following grammar: e :: = skip | out n | seq ( e , e ) where skip is the idle expression, out n outputs n , and seq ( e , e ) is the sequential composition.The semantic judgement has shape e ⇒ h r , s i , represented by the atom eval ( e , r , s ) , where e is anexpression, r is either end or div , for converging or diverging computations, respectively, and s is a possibly infinite sequence of integers. Clauses for concat are pretty standard; in this casethe definition is purely inductive (hence, no coclause is needed) since the left operand of con-catenation is always a finite sequence. Clauses for eval are rather straightforward, but sequentialcomposition seq ( e , e ) deserves some comment: if the evaluation of e converges, then the com- For simplicity we consider only integers, but in fact the definition below allows any term as output. F. Dagnino, D. Ancona, and E. Zucca concat ([ ] , S , S ) ← concat ([ N | S ] , S , [ N | S ]) ← concat ( S , S , S ) . eval ( skip , end , [ ]) ← eval ( out ( N ) , end , [ N ]) ← eval ( seq ( E , E ) , R , S ) ← eval ( E , end , S ) , eval ( E , R , S ) , concat ( S , S , S ) . eval ( seq ( E , E ) , div , S ) ← eval ( E , div , S ) . eval ( E , div , [ ]) ⇐ eval ( seq ( E , E ) , div , S ) ⇐ eval ( E , end , [ N | S ]) , concat ([ N | S ] , S , S ) . Fig. 6. A logic program defining a big-step semantics with infinite behaviour and observations.putation can continue with the evaluation of e , otherwise the overall computation diverges and e is not evaluated.As opposite to the previous examples, here we do not need just cofacts, but also a coclause;both the cofact and the coclause ensure that for infinite derivations only div can be derived.Furthermore, the cofact handles diverging expressions which produce a finite output sequence,as in eval ( E , div , [ ]) or in eval ( seq ( out ( ) , E ) , div , [ ]) , with E = seq ( skip , E ) or E = seq ( E , E ) ,while the coclause deals with diverging expressions with infinite outputs, as in eval ( E , div , S ) with E = seq ( out ( ) , E ) and S = [ | S ] . The body of the coclause ensures that the left operand ofsequential composition converges, thus ensuring a correct productive definition. After formally relating the two approaches, we state soundness of the operational semantics withrespect to the declarative one. Then, we show that completeness does not hold in general, anddefine the regular version of the declarative semantics. Finally, we show that the operationalsemantics is equivalent to this restricted declarative semantics.
Relation between operational and declarative semantics
As in the standard case, the first stepis to bridge the gap between the two approaches: the former computing equations, the latterdefining truth of atoms. This can be achieved through the notions of answers to a goal.Given a set of equations E , sol ( E ) is the set of the solutions of E , that is, the ground substitu-tions unifying all the equations in E . Then, θ ∈ sol ( E ) is an answer to h G ; E i if Var ( G ) ⊆ dom ( θ ) .The judgment h P , P co i ; S (cid:13) h G ; E i ⇒ E described in Section 4 computes a set of answers tothe input goal. Indeed, solutions of the output set of equations are solutions of the input set aswell, since the following proposition holds. Proposition 6.1
1. If h P , P co i ; S (cid:13) h G ; E i ⇒ E then E ⊆ E and Var ( G ) ⊆ Var ( E ) .2. If E ⊆ E , then sol ( E ) ⊆ sol ( E ) . Proof (1) Straightforward induction on rules in Figure 2. (2) Trivial.On the other hand, we can define which answers are correct in an interpretation:1
Definition 6.1
For I ⊆ HB ∞ , the set of answers to h G ; E i correct in I is ans ( G , E , I ) = { θ ∈ sol ( E ) | G θ ⊆ I } .Hence, soundness of the operational semantics can be expressed as follows: all the answerscomputed for a given goal are correct in the declarative semantics. Theorem 6.1 ( Soundness w.r.t. declarative semantics )If h P , P co i ; /0 (cid:13) h G ; E i ⇒ E ′ holds, then sol ( E ′ ) ⊆ ans ( G , E , ν fl J P , P co K ) . Completeness issues
The converse of this theorem, that is, all correct answers can be computed,cannot hold in general, since, as shown by Ancona and Dovier (2015), coinductive declarativesemantics does not admit any complete procedure , hence our model as well, since it generalizesthe coinductive one. To explain why completeness does not hold in our case, we can adapt thefollowing example from Ancona and Dovier (2015) , where p is a predicate symbol of arity 1, z and s are function symbols of arity 0 and 1 respectively. p ( X ) ← p ( s ( X )) . p ( X ) ⇐ Let us define 0 = z , n + = s ( n ) and ω = s ( s ( . . . )) . The declarative semantics is the set { p ( x ) | x ∈ N ∪ { ω }} . In the operational semantics, instead, only p ( ω ) is considered true. Indeed, allderivations have to apply the rule ( CO - HYP ) , which imposes the equation X ≖ s ( X ) , whose uniquesolution is ω . Therefore, the operational semantics is not complete.Now the question is the following: can we characterize in a declarative way answers computedby the big-step semantics? In the example, there is a difference between the atoms p ( ω ) and p ( n ) ,with n ∈ N , because the former has a regular proof tree, namely, a tree with finitely many differentsubtrees, while the latter has only with non-regular, thus infinite, proof trees.Following this observation, we prove that the operational semantics is sound and completewith respect to the restriction of the declarative semantics to atoms derivable by regular prooftrees. As we will see, this set can be defined in model-theoretic terms, by restricting to finitecomodels of the program. Dagnino (2020) defined this restriction for an arbitrary (generalized)inference system. We report here relevant definitions and results. Regular declarative semantics
Let us write X ⊆ fin Y if X is a finite subset of Y . The regularinterpretation of h I , I co i is defined as ρ fl J I , I co K = [ { X ⊆ fin µ J I ∪ I co K | X ⊆ F I ( X ) } This definition is like the one of ν fl J I , I co K , except that we take the union only of thoseconsistent subsets of µ J I ∪ I co K which are finite .The set ρ fl J I , I co K is a fixed point of F I and,precisely, it is the rational fixed point (Ad´amek et al. 2006) of F I restricted to ℘ ( µ J I ∪ I co K ) ,hence we get ρ fl J I , I co K ⊆ ν fl J I , I co K .The proof-theoretic characterization relies on regular proof trees , which are proof trees with a That is, establishing whether an atom belongs to the coinductive declarative semantics is neither decidable nor semi-decidable, even when the Herbrand universe is restricted to the set of rational terms. Example 10 at page 8. Which could be an infinite set, hence it is not the same of the greatest finite consistent set. F. Dagnino, D. Ancona, and E. Zucca finite number of subtrees (Courcelle 1983). That is, as proved by Dagnino (2020), ρ fl J I , I co K isthe set of judgments with a regular proof tree in I whose nodes all have a finite proof tree in I ∪ I co .As special case, we get regular semantics of logic programs with coclauses. Definition 6.2
The regular declarative semantics of h P , P co i , denoted by ρ fl J P , P co K , is the union of all finitecomodels included in µ J P ∪ P co K .As above, ρ fl J P , P co K ⊆ ν fl J P , P co K , hence ans ( G , E , ρ fl J P , P co K ) ⊆ ans ( G , E , ν fl J P , P co K ) .We state now soundness and completeness of the operational semantics with respect to thissemantics. We write θ (cid:22) σ iff dom ( θ ) ⊆ dom ( σ ) and, for all X ∈ dom ( θ ) , θ ( X ) = σ ( X ) . It iseasy to see that (cid:22) is a partial order and, if θ (cid:22) σ and Var ( G ) ⊆ dom ( θ ) , then G θ = G σ . Theorem 6.2 ( Soundness w.r.t. regular declarative semantics )If h P , P co i ; /0 (cid:13) h G ; E i ⇒ E ′ , and θ ∈ sol ( E ′ ) , then θ ∈ ans ( G , E , ρ fl J P , P co K ) . Theorem 6.3 ( Completeness w.r.t. regular declarative semantics )If θ ∈ ans ( G , E , ρ fl J P , P co K ) , then h P , P co i ; /0 (cid:13) h G ; E i ⇒ E ′ , and θ (cid:22) σ for some E ′ and σ ∈ sol ( E ′ ) .That is, any answer computed for a given goal is correct in the regular declarative semantics,and any correct answer is included in a computed answer. Theorem 6.2 immediately entailsTheorem 6.1 as ans ( G , E , ρ fl J P , P co K ) ⊆ ans ( G , E , ν fl J P , P co K ) . Proof technique
In order to prove the equivalence of the two semantics, we rely on a propertywhich holds in general for the regular interpretation (Dagnino 2020): we can construct an equiv-alent inductive characterization. That is, given a generalized inference system h I , I co i on theuniverse U , we can construct an inference system I (cid:9) I co with judgments of shape H ⊲ j , for j ∈ U and H ⊆ fin U , such that the inductive interpretation of I (cid:9) I co coincides with the regularinterpretation of h I , I co i . The set H , whose elements are called coinductive hypotheses , is usedto detect cycles in the proof.In particular, for logic programs with coclauses, we get an inference system with judgmentsof shape S ⊲ A , for S finite set of ground atoms, and A ground atom, defined as follows. Definition 6.3
Given h P , P co i , the inference system P (cid:9) P co consists of the following (meta-)rules: ( HP ) S ⊲ A A ∈ S and A ∈ µ J P ∪ P co K ( RULE ) S ∪ { A } ⊲ B . . . S ∪ { A } ⊲ B n S ⊲ A ( A ← B , . . . , B n ) ∈ k P k The following proposition states the equivalence with the regular interpretation. The proof isgiven by Dagnino (2020) in the general case of inference systems with corules.
Proposition 6.2P (cid:9) P co ⊢ µ /0 ⊲ A iff A ∈ ρ fl J P , P co K .Note that the definition of P (cid:9) P co ⊢ µ S ⊲ A has many analogies with that of the operationalsemantics in Figure 2. The key difference is that the former handles ground , not necessarilyfinite, atoms, the latter not necessarily ground finite atoms (we use the same metavariables A and S for simplicity). In both cases already considered atoms are kept in an auxiliary set S . In3the former, to derive an atom A ∈ S , the side condition requires A to belong to the inductiveintepretation of the program P ∪ P co . In the latter, when an atom A unifies with one in S , standardSLD resolution is triggered in the program P ∪ P co .To summarize, P (cid:9) P co ⊢ µ S ⊲ A can be seen as an abstract version, at the level of the underlyinginference system, of operational semantics. Hence, the proof of soundness and completenesscan be based on proving a precise correspondence between these two inference systems, bothinterpreted inductively. This is very convenient since the proof can be driven in both directionsby induction on the defining rules.The correspondence is formally stated in the following two lemmas. Lemma 6.1 ( Soundness w.r.t. inductive characterization of regular semantics )For all S and h A , . . . , A n ; E i ,if h P , P co i ; S (cid:13) h A , . . . , A n ; E i ⇒ E ′ then, for all θ ∈ sol ( E ′ ) and i ∈ .. n , P (cid:9) P co ⊢ µ S θ ⊲ A i θ . Lemma 6.2 ( Completeness w.r.t. inductive characterization of regular semantics )For all S , h A , . . . , A n ; E i and θ ∈ sol ( E ) ,if P (cid:9) P co ⊢ µ S θ ⊲ A i θ , for all i ∈ .. n , then h P , P co i ; S (cid:13) h A , . . . , A n ; E i⇒ E ′ and θ (cid:22) σ , for some E ′ and σ ∈ sol ( E ′ ) .Soundness follows from Lemma 6.1 and Proposition 6.2, as detailed below. Proof of Theorem 6.2
Let us assume h P , P co i ; /0 (cid:13) h G ; E i ⇒ E ′ with G = A , . . . , A n , and consider θ ∈ sol ( E ′ ) . ByLemma 6.1, for all i ∈ .. n , P (cid:9) P co ⊢ µ /0 ⊲ A i θ holds, hence, by Proposition 6.2, we get A i θ ∈ ρ fl J P , P co K . Therefore, by Definition 6.2, we get θ ∈ ans ( G , E , ρ fl J P , P co K ) , as needed.Analogously, completeness follows from Lemma 6.2 and Proposition 6.2, as detailed below. Proof of Theorem 6.3
Let G = A , . . . , A n and θ ∈ ans ( G , E , ρ fl J P , P co K ) . Then, for all i ∈ .. n , we have A i θ ∈ ρ fl J P , P co K and, by Proposition 6.2, we get P (cid:9) P co ⊢ µ /0 ⊲ A i θ . Hence, the thesis follows by Lemma 6.2. We have provided a detailed formal account of an extension of logic programming where pro-grams are enriched by coclauses, which can be used to tune the interpretation of predicates onnon-well-founded structures. More in detail, following the same pattern as for standard logicprogramming, we have defined: • A declarative semantics (the union of all finite comodels which are subsets of a certain setof atoms determined by coclauses). • An operational semantics (a combination of standard SLD resolution and coSLD resolu-tion) shown to be sound and complete with respect to the declarative semantics.As in the standard case, the latter provides a semi-algorithm. Indeed, concrete strategies (such asbreadth-first visit of the SLD tree) can be used to ensure that the operational derivation, if any,is found. In this paper we do not deal with this part, however we expect it to be not too differentfrom the standard case.It has been shown (Ancona and Dovier 2015) that, taking as declarative semantics the coin-ductive semantics (largest comodel), there is not even a semi-algorithm to check that an atom4
F. Dagnino, D. Ancona, and E. Zucca belongs to that semantics. Hence, there is no hope to find a complete operational semantics. Onthe other hand, our paper provides, for an extension of logic programming usable in pratice tohandle non-well-founded structures, fully-developed foundations and results which are exactlythe analogous of those for standard logic programming.CoLP has been initially proposed by Simon et al. (2006; 2006; 2007) as a convenient sub-paradigm of logic programming to model circularity; it was soon recognized the limitation of itsexpressive power that does not allow mutually recursive inductive and coinductive predicates, orpredicates whose correct interpretation is neither the least, nor the greatest fixed point.Moura et al. (2013; 2014) and Ancona (2013) have proposed implementations of coLP basedon refinements of the Simon’s original proposal with the main aim of making them more portableand flexible. Ancona has extended coLP by introducing a finally clause, allowing the user to de-fine the specific behavior of a predicate when solved by coinductive hypothesis. Moura’s imple-mentation is embedded in a tabled Prolog related to the implementation of Logtalk, and is basedon a mechanism similar to finally clauses to specify customized behavior of predicates whensolved by coinductive hypothesis. While such mechanisms resemble coclauses, the correspond-ing formalization is purely operational and lacks a declarative semantics and corresponding proofprinciples for proving correctness of predicate definitions based on them.Ancona and Dovier (2015) have proposed an operational semantics of coLP based on the big-step approach, which is simpler than the operational semantics initially proposed by Simon et al.and proved it to be sound. They have also formally shown that there is no complete procedure fordeciding whether a regular goal belongs to the coinductive declarative semantics, but providedno completeness result restricted to regular derivations, neither mechanisms to extend coLP andmake it more flexible.Ancona et al. (2017a) were the first proposing a principled extension of coLP based on thenotion of cofact, with both a declarative and operational semantics; the latter is expressed in big-step style, following the approach of Ancona and Dovier, and is proved to be sound w.r.t. theformer. An implementation is provided through a SWI-Prolog meta-interpreter.Our present work differs from the extension of coLP with cofacts mentioned above for thefollowing novel contributions: • we consider the more general notion of coclause, which includes the notion of cofact, butis a more expressive extension of coLP; • we introduce the notion of regular declarative semantics and prove coSLD resolution ex-tended with coclauses is sound and complete w.r.t. the regular declarative semantics; • we show how generalized inference systems are closely related to logic programs withcoclauses and rely on this relationship to carry out proofs in a clean and principled way; • we extend the implementation of the SWI-Prolog meta-interpreter to support coclauses.While coSLD resolution and its proposed extensions are limited by the fact that cycles mustbe detected in derivations to allow resolution to succeed, a stream of work based on the notion of structural resolution (Komendantskaya et al. 2016; Komendantskaya et al. 2017) (S-resolutionfor short) aims to make coinductive resolution more powerful, by allowing to lazily detect infinitederivations which do not have cycles. In particular, recent results (Li 2017; Komendantskaya and Li 2017;Basold et al. 2019) investigate how it is possible to integrate coLP cycle detection into S-resolution, See https://github.com/davideancona/coLP-with-coclauses , where also examples of Sect. 5 are available.
References A CZEL , P. 1977. An introduction to inductive definitions. In
Handbook of Mathematical Logic , J. Barwise,Ed. Studies in Logic and the Foundations of Mathematics, vol. 90. Elsevier, 739 – 782.A D ´ AMEK , J., M
ILIUS , S.,
AND V ELEBIL , J. 2006. Iterative algebras at work.
Mathematical Structures inComputer Scienc 16,
6, 1085–1131.A
NCONA , D. 2013. Regular corecursion in prolog.
Comput. Lang. Syst. Struct. 39,
4, 142–162.A
NCONA , D., D
AGNINO , F., R OT , J., AND Z UCCA , E. 2020. A big step from finite to infinite computations.
Science of Computer Programming 197 , 102492.A
NCONA , D., D
AGNINO , F.,
AND Z UCCA , E. 2017a. Extending coinductive logic programming withco-facts. In
First Workshop on Coalgebra, Horn Clause Logic Programming and Types, CoALP-Ty’16 ,E. Komendantskaya and J. Power, Eds. Electronic Proceedings in Theoretical Computer Science, vol.258. Open Publishing Association, 1–18.A
NCONA , D., D
AGNINO , F.,
AND Z UCCA , E. 2017b. Generalizing inference systems by coaxioms. In
Pro-gramming Languages and Systems - 26th European Symposium on Programming, ESOP 2017 , H. Yang,Ed. Lecture Notes in Computer Science, vol. 10201. Springer, Berlin, 29–55.A
NCONA , D., D
AGNINO , F.,
AND Z UCCA , E. 2018. Modeling infinite behaviour by corules. In , T. D. Millstein, Ed. LIPIcs, vol.109. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, Dagstuhl, 21:1–21:31.A
NCONA , D.
AND D OVIER , A. 2015. A theoretical perspective of coinductive logic programming.
Fun-damenta Informaticae 140, PT , K. R. 1997. From logic programming to Prolog . Prentice Hall International series in computerscience. Prentice Hall.B
ASOLD , H., K
OMENDANTSKAYA , E.,
AND L I , Y. 2019. Coinduction in uniform: Foundations for core-cursive proof search with horn clauses. In ESOP 2019 , L. Caires, Ed. Lecture Notes in Computer Science,vol. 11423. Springer, 783–813.C
OURCELLE , B. 1983. Fundamental properties of infinite trees.
Theoretical Computer Science 25 , 95–169.D
AGNINO , F. 2017. Generalizing inference systems by coaxioms. M.S. thesis, DIBRIS, University ofGenova. Best italian master thesis in Theoretical Computer Science 2018.D
AGNINO , F. 2019. Coaxioms: flexible coinductive definitions by inference systems.
Logical Methods inComputer Science 15,
AGNINO , F. 2020. Foundations of regular coinduction. Tech. rep., DIBRIS, University of Genova. May.Available at https://arxiv.org/abs/2006.02887 . Submitted for journal publication.G
UPTA , G., S
AEEDLOEI , N., D E V RIES , B. W., M IN , R., M ARPLE , K.,
AND K LUZNIAK , F. 2011. In-finite computation, co-induction and computational logic. In
CALCO 2011 - Algebra and Coalgebra inComputer Science , A. Corradini, B. Klin, and C. Cˆırstea, Eds. Lecture Notes in Computer Science, vol.6859. Springer, 40–54.K
OMENDANTSKAYA , E.
ET AL . 2016. Coalgebraic logic programming: from semantics to implementation.
J. Logic and Computation 26,
2, 745.K
OMENDANTSKAYA , E.
ET AL . 2017. A productivity checker for logic programming.
Post-proc. LOP-STR’16 .K OMENDANTSKAYA , E.
AND L I , Y. 2017. Productive corecursion in logic programming. Theory Pract.Log. Program. 17, F. Dagnino, D. Ancona, and E. Zucca L EROY , X.
AND G RALL , H. 2009. Coinductive big-step operational semantics.
Information and Compu-tation 207,
2, 284–304.L I , Y. 2017. Structural resolution with coinductive loop detection. In Post-proceedings of CoALP-Ty’16 ,E. Komendantskaya and J. Power, Eds.L
LOYD , J. W. 1987.
Foundations of Logic Programming, 2nd Edition . Springer.L ¨
ODING , C.
AND T OLLK ¨ OTTER , A. 2016. Transformation between regular expressions and omega-automata. In , P. Faliszewski, A. Muscholl, and R. Niedermeier, Eds. LIPIcs, vol. 58. Schloss Dagstuhl - Leibniz-Zentrum f¨ur Informatik, 88:1–88:13.M
ANTADELIS , T., R
OCHA , R.,
AND M OURA , P. 2014. Tabling, rational terms, and coinduction finallytogether!
TPLP 14,
OURA , P. 2013. A portable and efficient implementation of coinductive logic programming. In
PracticalAspects of Declarative Languages - 15th International Symposium, PADL 2013, Rome, Italy, January21-22, 2013. Proceedings . 77–92.S
IMON , L. 2006. Extending logic programming with coinduction. Ph.D. thesis, University of Texas atDallas.S
IMON , L., B
ANSAL , A., M
ALLYA , A.,
AND G UPTA , G. 2007. Co-logic programming: Extending logicprogramming with coinduction. In
Automata, Languages and Programming, 34th International Collo-quium, ICALP 2007 , L. Arge, C. Cachin, T. Jurdzinski, and A. Tarlecki, Eds. Lecture Notes in ComputerScience, vol. 4596. Springer, 472–483.S
IMON , L., M
ALLYA , A., B
ANSAL , A.,
AND G UPTA , G. 2006. Coinductive logic programming. In
LogicProgramming, 22nd International Conference, ICLP 2006 , S. Etalle and M. Truszczynski, Eds. LectureNotes in Computer Science, vol. 4079. Springer, 330–345.T
ARSKI , A. 1955. A lattice-theoretical fixpoint theorem and its applications.
Pacific Journal of Mathemat-ics 5,
2, 285–309. Appendix A Proofs
In this section we report proofs omitted in Section 6.
Soundness
We prove Lemma 6.1. To carry out the proof, we rely on Proposition 6.2 and onthe following proposition, stating that the inductive declarative semantics of a logic programcoincides with the regular semantics of a logic program with no coclauses. The proof is given byDagnino (2020) in the general case of inference systems with corules.
Proposition Appendix A.1
Let P be a logic program, then µ J P K = ρ fl J P , /0 K . Proof of Lemma 6.1
The proof is by induction on rules of Figure 2. ( EMPTY ) There is nothing to prove. ( STEP ) We have G = G , A i , G , there is a fresh renaming B ← B , . . . , B k of a clause in P suchthat A i and B are unifiable in E , that is, E = E ∪ E A i , B is solvable, and h P , P co i ; S ∪ { A i } (cid:13) h B , . . . , B k ; E i ⇒ E and h P , P co i ; S (cid:13) h G , G ; E i ⇒ E ′ hold. Let θ ∈ sol ( E ′ ) , then, by in-duction hypothesis, we have, for all j ∈ .. n with j = i , P (cid:9) P co ⊢ µ S θ ⊲ A j θ holds. By Proposi-tion 6.1, we have E ⊆ E ⊆ E ′ , hence sol ( E ′ ) ⊆ sol ( E ) ⊆ sol ( E ) , thus θ ∈ sol ( E ) ⊆ sol ( E ) ,and, since E A i , B ⊆ E , θ is a unifier of A i and B , that is, A i θ = B θ . Then, by induction hypoth-esis, we also get, for all j ∈ .. k , P (cid:9) P co ⊢ µ ( S ∪ { A i } ) θ ⊲ B j θ holds. Since ( S ∪ { A i } ) θ = S θ ∪ { A i θ } and B θ ← B θ , . . . , B k θ ∈ k P k and A i θ = B θ , by rule ( UNFOLD ) of Definition 6.3,we get that P (cid:9) P co ⊢ µ S θ ⊲ A i θ holds as well. ( CO - HYP ) We have G = G , A i , G , there is an atom B ∈ S that unifies with A i in E , that is, E = E ∪ E A i , B is solvable, and h P ∪ P co , /0 i ; /0 (cid:13) h A i ; E i ⇒ E and h P , P co i ; S (cid:13) h G , G ; E i ⇒ E ′ hold. Let θ ∈ sol ( E ′ ) , then, by induction hypothesis, we get, for all j ∈ .. n with j = i , P (cid:9) P co ⊢ µ S θ ⊲ A j θ holds. By Proposition 6.1, we have E ⊆ E ⊆ E ′ , hence sol ( E ′ ) ⊆ sol ( E ) ⊆ sol ( E ) ,thus θ ∈ sol ( E ) ⊆ sol ( E ) , and, since E A i , B ⊆ E , θ is a unifier of A i and B , that is, A i θ = B θ . By induction hypothesis, we get ( P ∪ P co ) (cid:9) /0 ⊢ µ /0 ⊲ A i θ , hence, by Proposition 6.2 andProposition Appendix A.1, we get A i θ ∈ µ J P ∪ P co K . Furthermore, since A i θ = B θ and B ∈ S ,we have A i θ ∈ S θ . Therefore, by rule ( HP ) of Definition 6.3, we get that P (cid:9) P co ⊢ µ S θ ⊲ A i θ holds as well. Completeness
We need some preliminary results, then we prove Lemma 6.2.We start by observing a property of the operational semantics. In the following, we say thatsubstitutions θ and θ are compatible, denoted by θ k θ if, for all X ∈ dom ( θ ) ∩ dom ( θ ) , θ ( X ) = θ ( X ) , and we denote by θ ⊎ θ the union of two substitutions, which is well-definedonly for compatible substitutions. Note that, θ i (cid:22) θ ⊎ θ , for all i = ,
2, by definition.
Proposition Appendix A.2
Let h G ; E i be a goal, θ ∈ sol ( E ) , E ′ such that E ⊆ E ′ and θ (cid:22) σ , for some σ ∈ sol ( E ′ ) .If h P , P co i ; S (cid:13) h G ; E i ⇒ E and θ (cid:22) θ , for some θ ∈ sol ( E ) , then there exists E ′ such that E ⊆ E ′ , h P , P co i ; S (cid:13) h G ; E ′ i ⇒ E ′ and σ (cid:22) σ , for some σ ∈ sol ( E ′ ) .8 F. Dagnino, D. Ancona, and E. ZuccaProof
The proof is by induction on the big-step rules in Figure 2. ( EMPTY ) We have E = E , hence the thesis follows by taking E ′ = E ′ . ( STEP ) We know that G = G , A , G , B ← B , . . . , B n is a fresh renaming of a clause in P , E ∪ E A , B is solvable, h P , P co i ; S ∪ { A } (cid:13) h B , . . . , B n ; E ∪ E A , B i ⇒ E and h P , P co i ; S (cid:13) h G , G ; E i ⇒ E hold. We can assume that variables occurring in the selected clause do not belong to dom ( σ ) since such variables are fresh and dom ( σ ) is a finite set. Since E ∪ E A , B ⊆ E ⊆ E by Proposition 6.1, we have θ ∈ sol ( E ∪ E A , B ) and denote by θ ′ the restriction of θ to dom ( θ ) ∪ Var ( B ) . It is easy to see that, by construction, θ (cid:22) θ ′ and θ ′ ∈ sol ( E ∪ E A , B ) and θ ′ k σ , since dom ( θ ′ ) ∩ dom ( σ ) = dom ( θ ) and θ (cid:22) σ by hypothesis. Hence, σ ′ = θ ′ ⊎ σ is well-defined and θ ′ (cid:22) σ ′ . Since E ⊆ E , θ ∈ sol ( E ) and, if θ ′ is the restriction of θ to dom ( θ ′ ) ∪ Var ( E ) , then θ ′ ∈ sol ( E ) as well, and θ ′ (cid:22) θ ′ . Therefore, by induction hypothe-sis, we get that h P , P co i ; S ∪ { A } (cid:13) h B , . . . , B n ; E ′ ∪ E A , B i ⇒ E ′ holds and there is σ ′ ∈ sol ( E ′ ) such that θ ′ (cid:22) σ ′ , with E ⊆ E ′ . Since θ ′ (cid:22) θ and θ ′ (cid:22) σ ′ , again by induction hypothesis,we get that h P , P co i ; S (cid:13) (cid:10) G , G ; E ′ (cid:11) ⇒ E ′ holds and there is σ ∈ sol ( E ′ ) such that θ (cid:22) σ ,with E ⊆ E ′ . Then, the thesis follows by applying rule ( STEP ) . ( CO - HYP ) We know that G = G , A , G , E ∪ E A , B is solvable for some B ∈ S , h P ∪ P co , /0 i ; /0 (cid:13) h A ; E ∪ E A , B i ⇒ E and h P , P co i ; S (cid:13) h G , G ; E i ⇒ E hold. Since E ∪ E A , B ⊆ E ⊆ E by Proposition 6.1, we have θ ∈ sol ( E ∪ E A , B ) and denote by θ ′ the restriction of θ to dom ( θ ) ∪ Var ( B ) , but, as Var ( B ) ⊆ Var ( E ) , θ ∈ sol ( E ) and θ (cid:22) θ , we get θ ′ = θ , thus θ ∈ sol ( E ∪ E A , B ) . Hence, since θ (cid:22) σ , we get σ ∈ sol ( E ∪ E A , B ) and so it also belongsto sol ( E ′ ∪ E A , B ) , that is, in particular, E ′ ∪ E A , B is solvable. Since E ⊆ E , θ ∈ sol ( E ) and,if θ ′ is the restriction of θ to dom ( θ ) ∪ Var ( E ) , then θ ′ ∈ sol ( E ) as well, and θ (cid:22) θ ′ .Therefore, by induction hypothesis, we get h P ∪ P co , /0 i ; /0 (cid:13) h A ; E ′ ∪ E A , B i ⇒ E ′ and there is σ ′ ∈ sol ( E ′ ) such that θ ′ (cid:22) σ ′ , with E ⊆ E ′ . Since θ ′ (cid:22) θ and θ ′ (cid:22) σ ′ , again by inductionhypothesis, we get that h P , P co i ; S (cid:13) (cid:10) G , G ; E ′ (cid:11) ⇒ E ′ holds and there is σ ∈ sol ( E ′ ) suchthat θ (cid:22) σ , with E ⊆ E ′ . Then, the thesis follows by applying rule ( CO - HYP ) . Lemma Appendix A.1
Let h G ; E i be a goal, θ ∈ sol ( E ) and E and E be sets of equations such that θ (cid:22) θ and θ (cid:22) θ , for some θ ∈ sol ( E ) and θ ∈ sol ( E ) . If h P , P co i ; S (cid:13) h A ; E i ⇒ E and h P , P co i ; S (cid:13) h G , G ; E i ⇒ E , then there exists E such that h P , P co i ; S (cid:13) h G , A , G ; E i ⇒ E and θ (cid:22) θ ,for some θ ∈ sol ( E ) . Proof
We sketch the proof. By Proposition 6.1, we have E ⊆ E and by Proposition Appendix A.2we get h P , P co i ; S (cid:13) h G , G ; E i ⇒ E , with E ⊆ E and θ (cid:22) θ , for some θ ∈ sol ( E ) . Bytransitivity of (cid:22) we get θ (cid:22) θ . Then, the thesis follows by case analysis on the last applied rulein the derivation of h P , P co i ; S (cid:13) h A ; E i ⇒ E , by replacing the premise h P , P co i ; S (cid:13) h ε ; E i ⇒ E with the judgement h P , P co i ; S (cid:13) h G , G ; E i ⇒ E . Lemma Appendix A.2
Let A be an atom and E be a set of equations. For all θ ∈ sol ( E ) , if A θ ∈ µ J P ∪ P co K , then thereexists E ′ such that h P ∪ P co , /0 i ; /0 (cid:13) h A ; E i ⇒ E ′ and θ (cid:22) σ , for some σ ∈ sol ( E ′ ) .9 Proof
The proof is by induction on the derivation of A θ in k P ∪ P co k . Let A ′ ← A , . . . , A n ∈ k P ∪ P co k be the last applied rule in the finite derivation of A θ , hence we have A ′ = A θ . By definition of k P ∪ P co k , we know there is a fresh renaming of a clause in P ∪ P co , denote it by B ← B , . . . , B n ,and a substitution θ ′ such that B θ ′ = A ′ and B i θ ′ = A i , for all i ∈ .. n . Since the variables in thisclause are fresh, we can assume dom ( θ ) ∩ dom ( θ ′ ) = /0, hence θ ′′ = θ ⊎ θ ′ is well-defined and,by construction, we have θ (cid:22) θ ′′ , thus θ ′′ ∈ sol ( E ) , and A θ ′′ = B θ ′′ , that is, θ ′′ ∈ sol ( E A , B ) . Asa consequence θ ′′ is a solution of E ∪ E A , B , hence, by induction hypothesis, we get that, for all i ∈ .. n , h P ∪ P co , /0 i ; /0 (cid:13) h B i ; E ∪ E A , B i ⇒ E i holds and θ ′′ (cid:22) σ i , for some σ i ∈ sol ( E i ) .By applying n times Lemma Appendix A.1, we get h P ∪ P co , /0 i ; /0 (cid:13) h B , . . . , B n ; E ∪ E A , B i ⇒ E ′ and θ ′′ (cid:22) σ , for some σ ∈ sol ( E ′ ) . Then, the thesis follows by applying rule ( STEP ) to thisjudgement and h P ∪ P co , /0 i ; /0 (cid:13) h ε ; E ′ i ⇒ E ′ . Lemma Appendix A.3
For all S and h A ; E i ,if P (cid:9) P co ⊢ µ S θ ⊲ A θ , and θ ∈ sol ( E ) , then h P , P co i ; S (cid:13) h A ; E i⇒ E ′ and θ (cid:22) σ , for some E ′ and σ ∈ sol ( E ′ ) . Proof
The proof is by induction on the derivation of S θ ⊲ A θ (see Definition 6.3). ( HP ) We know that A θ ∈ S θ and A θ ∈ µ J P ∪ P co K , that is, θ ∈ ans bd ( A , E ) . By Lemma Appendix A.2,we get h P ∪ P co , /0 i ; /0 (cid:13) h A ; E i ⇒ E and θ (cid:22) θ , for some θ ∈ sol ( E ) . Since A θ ∈ S θ , weknow that there is B ∈ S such that A θ = B θ , that is θ ∈ sol ( E A , B ) , thus θ ∈ sol ( E ∪ E A , B ) .Therefore, by Proposition Appendix A.2, we get h P ∪ P co , /0 i ; /0 (cid:13) h A ; E ∪ E A , B i ⇒ E ′ and θ (cid:22) θ (cid:22) σ , for some σ ∈ sol ( E ′ ) . The thesis follows by applying rule ( CO - HYP ) to this judgementand h P , P co i ; S (cid:13) h ε ; E ′ i ⇒ E ′ . ( RULE ) We know there is a A ′ ← A , . . . , A n ∈ k P k such that A ′ = A θ and P (cid:9) P co ⊢ µ S θ ∪ { A θ } ⊲ A i is derivable, for all i ∈ .. n . By definition of k P ∪ P co k , we know there is a fresh renamingof a clause in P ∪ P co , denote it by B ← B , . . . , B n , and a substitution θ ′ such that B θ ′ = A ′ and B i θ ′ = A i , for all i ∈ .. n . Since the variables in this clause are fresh, we can assume dom ( θ ) ∩ dom ( θ ′ ) = /0, hence θ ′′ = θ ⊎ θ ′ is well-defined and, by construction, we have θ (cid:22) θ ′′ , thus θ ′′ ∈ sol ( E ) , and A θ ′′ = B θ ′′ , that is, θ ′′ ∈ sol ( E A , B ) and S θ ∪ { A θ } = ( S ∪ { A } ) θ ′′ .As a consequence θ ′′ is a solution of E ∪ E A , B , hence, by induction hypothesis, we get that, forall i ∈ .. n , h P , P co i ; S ∪ { A } (cid:13) h B i ; E ∪ E A , B i ⇒ E i holds and θ ′′ (cid:22) σ i , for some σ i ∈ sol ( E i ) .By applying n times Lemma Appendix A.1, we get h P , P co i ; S ∪{ A } (cid:13) h B , . . . , B n ; E ∪ E A , B i ⇒ E ′ and θ ′′ (cid:22) σ , for some σ ∈ sol ( E ′ ) . By transitivity we get θ (cid:22) σ . Then, the thesis followsby applying rule ( STEP ) to this judgement and h P ∪ P co , /0 i ; /0 (cid:13) h ε ; E ′ i ⇒ E ′ . Proof of Lemma 6.2
The proof is by induction on the number of atoms in G = A , . . . , A n . If G = ε , then the thesisfollows by rule ( EMPTY ) , taking E ′ = E and σ = θ . If G = G , A , G , we know by hypothesisthat P (cid:9) P co ⊢ µ S θ ⊲ A θ , hence, by Lemma Appendix A.3 we get h P , P co i ; S (cid:13) h A ; E i ⇒ E and θ (cid:22) θ , for some θ ∈ sol ( E ) . By induction hypothesis, we get h P , P co i ; S (cid:13) h G , G ; E i ⇒ E and θ (cid:22) θ , for some θ ∈ sol ( E ) , therefore, by Lemma Appendix A.1, we get h P , P co i ; S (cid:13) h G , A , G ; E i ⇒ E ′ and θ (cid:22) σ for some σ ∈ sol ( E ′ ))