Standard inductive and coinductive semantics of logic programs sometimes are not enough to properly define predicates on possibly infinite terms [SimonBMG07, Ancona13].
Consider the logic program in intro-example, defining some predicates on lists of numbers represented with 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 predicates are 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) [Simon06] extends standard logic programming with the ability of reasoning about infinite objects and their properties. Terms are coinductively 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 interpretation of gives the expected meaning on such lists. However, this is not the case for the other two predicates: for the correct interpretation is still the inductive one, as in the coinductive semantics always succeeds for an infinite list . For instance, for the infinite list of ’s, has an infinite proof tree where for each node we apply the second clause. Therefore, these two predicates cannot coexist in the same program, as they require two different interpretations.111To overcome this issue, co-logic programming SimonBMG07 marks predicates as either inductive or coinductive. The declarative semantics, however, becomes quite complex, because stratification is needed.
The predicate shows an even worse situation. The inductive semantics again does not work on infinite lists, but also the coinductive one is not correct: succeeds whenever is greater than all the elements of . The expected meaning lies between the inductive and the coinductive semantics, hence, to get it, we need something beyond standard semantics.
Recently, in the more general context of inference systems [Aczel77], flexible coinduction has been proposed by Dagnino and Ancona et al. Dagnino17,AnconaDZ@esop17,Dagnino19, a generalisation able to express a variety of intermediate interpretations. As we recall in Section 2, clauses of a logic program 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 proof tree 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 of logic programming supporting flexible coinduction.
Syntactically, programs are enriched by coclauses, which resemble clauses but have a special meaning used to tune the interpretation of predicates. By adding coclauses, we can obtain a declarative semantics intermediate between the inductive and the coinductive one. Standard (inductive) and coinductive logic programming are subsumed by a particular choice of coclauses. Correspondingly, operational semantics is a combination of standard SLD resolution [Lloyd87, Apt97] and coSLD resolution as introduced by Simon et al. Simon06,SimonMBG06,SimonBMG07. More precisely, as in coSLD resolution, it keeps trace of already considered goals, called coinductive hypotheses.222We prefer to mantain this terminology, inherited from coSLD resolution, even though not corresponding to the proof theoretic sense. However, when a goal unifying with a coinductive hypothesis is found, rather than being considered successful as in coSLD resolution, its standard SLD resolution is triggered in the program where also coclauses are considered. Our main result is that such operational semantics is sound and complete with respect to the declarative one restricted to regular proof trees.
An important additional result is that the operational semantics is not incidental, but, as the declarative semantics, turns out to correspond to a precise notion on the inference system denoted by the logic program. Indeed, as detailed in a companion paper of Dagnino Dagnino20, given an inference system, we can always construct another one, with judgments enriched by circular hypotheses, which, interpreted inductively, is equivalent to the regular interpretation of the original inference system. In other words, there is a canonical way to derive a (semi-)algorithm to show that a judgment has a regular proof tree, and our operational semantics corresponds to this algorithm. This more abstract view supports the reliability of the approach, and, indeed, the proof of equivalence with declarative semantics can be nicely done in a modular way, that is, by relying on a general result proved by Dagnino Dagnino20.
2 Logic programs as inference systems
We recall basic concepts about inference systems [Aczel77], and present (standard inductive and coinductive) logic programming [Lloyd87, Apt97, Simon06, SimonMBG06, SimonBMG07] as a particular instance of this general semantic framework.
Assume a set called universe whose elements are called judgements. An inference system is a set of (inference) rules, which are pairs , also written , with set of premises, and conclusion. We assume inference systems to be finitary, that is, rules have a finite set of premises. A proof tree (a.k.a. derivation) in is a tree with nodes (labelled) in such that, for each with set of children , there is a rule in . A proof tree for is a proof tree with root . The inference operator is defined by:
A set is closed if , consistent if , a fixed point if .
An interpretation of an inference system is a set of judgements, that is, a subset of the universe . The two standard interpretations, the inductive and the coinductive one, can be defined in either model-theoretic or proof-theoretic terms [LeroyG09].
The inductive interpretation is the intersection of all closed sets, that is, the least closed set or, equivalently, the set of judgements with a finite proof tree.
The coinductive interpretation is the union of all consistent sets, that is, the greatest consistent set, or, equivalently, the set of judgements with an arbitrary (finite or not) proof tree.
By the fixed point theorem [Tarski55], both and are fixed points of , the least and the greatest one, respectively. We will write for and for .
Assume a first order signature with set of predicate symbols , set of function symbols , and countably infinite set of variable symbols (variables for short). Each symbol comes with its arity, a natural number denoting the number of arguments. Variables have arity . A function symbol with arity is a constant.
Terms , , are (possibly infinite) trees with nodes labeled by function or variable symbols, where the number of children of a node is the symbol arity333For a more formal definition based on paths see, e.g., the work of Ancona and Dovier AnconaD15.. Atoms , , 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 with , , , …, finite atoms. A clause where is called a fact. A (definite) logic program is a finite set of clauses.
Substitutions are partial maps from variables to terms with a finite domain. We write for the application of to a term , call an instance of , and analogously for atoms, set of atoms, and clauses. A substitution is ground if, for all , is ground, syntactic if, for all , is a finite (syntactic) term.
In order to see a logic program as an inference system, we fix as universe the complete Herbrand base , that is, the set of all (finite and infinite) ground atoms444Traditionally [Lloyd87], the inductive declarative semantics is restricted to finite atoms. We define also the inductive semantics on the complete Herbrand base in order to work in a uniform context.. Then, can be seen as a set of meta-rules defining an inference system on . That is, is the set of ground instances of clauses in , where is seen as an inference rule . In this way, typical notions related to declarative semantics of logic programs turn out to be instances of analogous notions for inference systems. Notably, the (one step) inference operator associated to a program , defined by:
is exactly . An interpretation (a set ) is a model of a program if , that is, it is closed with respect to . Dually, an interpretation is a comodel of a program if , that is, it is consistent with respect to . Then, the inductive declarative semantics of is the least model of and the coinductive declarative semantics555Introduced Simon06,SimonMBG06 to properly deal with predicates on infinite terms. is the greatest comodel of . These two semantics coincide with the inductive and coinductive interpretations of , hence we denote them by and , respectively.
We introduce logic programs with coclauses and define their declarative semantics. Consider again the example in intro-example where, as discussed in the Introduction, each predicate needed a different kind of interpretation.
As shown in the previous section, the above logic program can be seen as an inference system. In this context, flexible coinduction has been proposed Dagnino17,AnconaDZ@esop17,Dagnino19, 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 , where the elements of are called corules. The interpretation of , denoted by , is constructed in two steps.
first, we take the inductive interpretation of the union , that is, ,
then, the union of all sets, consistent with respect to , which are subsets of , that is, the largest consistent subset of .
In proof-theoretic terms, is the set of judgements with an arbitrary (finite or not) proof tree in , whose nodes all have a finite proof tree in . Essentially, by corules we filter out some, undesired, infinite proof trees. Dagnino Dagnino19 proved that is a fixed point of .
To introduce flexible coinduction in logic programming, first we slightly extend the syntax by introducing (definite) coclauses, written , where , , …, are finite atoms. A coclause where n = 0 is called a cofact. Coclauses syntactically resemble clauses, but are used in a special way, like corules for inference systems. More precisely, we have the following definition:
A logic program with coclauses is a pair where and are sets of clauses. Its declarative semantics, denoted by , is the largest comodel of which is a subset of .
In other words, the declarative semantics of is the coinductive semantics of where, however, clauses are instantiated only on elements of . Note that this is the interpretation of the generalized inference system .
Below is the version of the example in intro-example, equipped with coclauses.
In this way, all the predicate definitions are correct w.r.t. the expected semantics:
has coinductive semantics, as the coclause allows any infinite proof trees.
has inductive semantics, as without coclauses no infinite proof tree is allowed.
has an intermediate semantics, as the coclause allows only infinite proof trees where nodes have shape with an element of .
As the example shows, coclauses allow the programmer to mix inductive and coinductive predicates, and to correctly define predicates which are neither inductive, nor purely coinductive. For this reason we call this paradigm flexible coinductive logic programming. Note that, as shown for inference systems with corules [Dagnino17, AnconaDZ@esop17, Dagnino19], inductive and coinductive semantics are particular cases. Indeed, they can be recovered by special choices of coclauses: the former is obtained when no coclause is specified, the latter when each atom in is an instance of the head of a cofact.
4 Big-step operational semantics
In this section we define an operational counterpart of the declarative semantics of logic programs with coclauses introduced in the previous section.
As in standard coLP [Simon06, SimonMBG06, SimonBMG07], to represent possibly infinite terms we use finite sets of equations between finite (syntactic) terms. For instance, the equation represents the infinite list [1,2,1,2,…].
Since the declarative semantics of logic programs with coclauses is a combination of inductive and coinductive semantics, their operational semantics combines standard SLD resolution [Lloyd87, Apt97] and coSLD resolution [Simon06, SimonMBG06, SimonBMG07]. It is presented, rather than in the traditional small-step style, in big-step style, as introduced by Ancona and Dovier AnconaD15. This style turns out to be simpler since coinductive hypotheses (see below) can be kept local. Moreover, it naturally leads to an interpreter, and makes it simpler to prove its correctness with respect to declarative semantics (see the next section).
We introduce some notations. First of all, in this section we assume atoms and terms to be finite (syntactic). A goal is a pair , where is a finite sequence of atoms. A goal is empty if is the empty sequence, denoted . An equation has shape where and are terms, and we denote by a finite set of equations.
Intuitively, a goal can be seen as a query to the program and the operational semantics has to compute answers (a.k.a. solutions) to such a query. More in detail, the operational semantics, given a goal , provides another set of equations , which represents answers to the goal. For instance, given the previous program, for the goal , the operational semantics returns the set of equations .
The judgment of the operational semantics has shape
meaning that resolution of , under the coinductive hypotheses [SimonMBG06], succeeds in , producing a set of equations . Set the set of variables in a term, and analogously for atoms, set of atoms, and equations. We assume , modelling the intuition that keeps track of already considered atoms. This condition holds for the initial judgement, and is preserved by rules in opsem, hence it is not restrictive. Resolution starts with no coinductive hypotheses, that is, the top-level judgment has shape .
The operational semantics has two flavours:
If there are no corules (), then the judgment models standard SLD resolution, hence the set of coinductive hypotheses is not significant.
Otherwise, the judgment models flexible coSLD resolution, which follows the same schema of coSLD resolution, in the sense that it keeps track in of the already considered atoms. However, when an atom in the current goal unifies with a coinductive hypothesis, rather than just considering successful as in coSLD resolution, standard SLD resolution of is triggered in the program , that is, also coclauses can be used.
The judgement is inductively defined by the rules in opsem, which rely on some auxiliary (standard) notions. A solution of an equation is a unifier of and , that is, a substitution such that . A solution of a finite set of equations is a solution of all the equations in and is solvable if there exists a solution of . Two atoms and are unifiable in a set of equations , written , if , and is solvable, and we denote by the set .
Rule empty states that the resolution of an empty goal succeeds. In rule step, an atom to be resolved is selected, and a clause of the program is chosen such that unifies with the head of the clause in the current set of equations. Then, resolution of the original goal succeeds if both the body of the selected clause and the remaining atoms are resolved, enriching the set of equations correspondingly. As customary, the selected clause is renamed using fresh variables, to avoid variable clashes in the set of equations obtained after unification. Note that, in the resolution of the body of the clause, the selected atom is added to the current set of coinductive hypotheses. This is not relevant for standard SLD resolution (). However, if , this allows rule co-hyp to handle the case when an atom that has to be resolved unifies with a coinductive hypothesis in the current set of equations. In this case, standard SLD resolution of such atom in the program is triggered, and resolution of the original goal succeeds if both such standard SLD resolution of the selected atom and resolution of the remaining goal succeed.
In example we show an example of resolution. We use the shorter syntax =max, abbreviate by the equation , by the equations , by mE the predicate maxElem, and by s, c the rules step and co-hyp, respectively. When applying rule step, we also indicate the clause/coclause which has been used: we write 1,2,3 for the two clauses and the coclause for the maxElem predicate (the first clause is never used in this example). Finally, to keep the 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, equations between 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 program is inductive. The latter is obtained when, for all predicate of arity , we have a cofact .
In this section we discuss some more sophisticated examples.
We define -regular expressions on an alphabet , a variant of the formalism defined by Löding and Tollkötter LodingT16 for denoting languages of finite and infinite words, the latter also called -words, as follows:
where . The syntax of standard regular expressions is extended by , denoting the -power of the language denoted by . That is, the set of words obtained by concatenating infinitely many times words in . In this way, we can denote also languages containing infinite words.
In regex-example we define the predicate , such that holds if the finite or infinite word , implemented as a list, belongs to the language denoted by . For simplicity, we consider words over the alphabet .
Concatenation of words needs to be defined coinductively, to correctly work on infinite words as well. Note that, when is infinite, is equal to .
On operators of regular expressions, can be defined in the standard way (no coclauses). In particular, the definition for expressions of shape follows the explicit definition of the -closure of a language: given a language , a word belongs to iff it can be decomposed as , for some , where means is empty, and , for all . This condition is checked by the auxiliary predicate .
To define when a word matches we have two cases. If is empty, then it is enough to check that the empty word matches , as expressed by the first clause, because concatenating infinitely many times the empty word we get again the empty word. Otherwise, we have to decompose as where is not empty and matches and matches as well, as formally expressed by the second clause, To propertly handle infinite words, we need to concatenate infinitely 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 ltl-example we define the predicate s.t. succeeds iff the -word over the alphabet satisfies the formula of the fragment of the Linear Temporal Logic with the temporal operators () and () and the predicate and its negation666Predicates and could be easily defined as well. .
Since succeeds iff all infinite suffixes of satisfy formula , the coinductive interpretation has to be considered, hence a coclause is needed; for instance, , with , succeeds because the atom in the body of the clause for unifies777Actually, in this case the atom to be resolved and the coinductive hypothesis are syntactically equal. with the coinductive hypothesis (see rule co-hyp in Figure 2) and the coclause allows it to succeed w.r.t. standard SLD resolution (indeed, atom succeeds, thanks to the first fact in the logic program).
Differently to , the interpretation of has to be inductive because succeeds iff is satisfied after a finite number of steps; for this reason, no coclause is given for this operator; for instance, with succeeds w.r.t. standard SLD resolution, while , , and fail. The clause for follows the standard definition of satisfaction for the operator: there must exist a suffix of at index satisfying () s.t. all suffixes of at index less than satisfy ().
An interesting example concerns the goal , where the two temporal operators are mixed together: it succeeds as expected, thanks to the two clauses for and the fact that succeeds, as shown above.
Some of the issues faced in this example are also discussed by Gupta et al. GuptaSDMMK11.
Big-step semantics modeling infinite behaviour and observations
Defining a big-step operational semantics modelling divergence is a difficult task, especially in presence of observations. Ancona et al. AnconaDZ@ecoop18,AnconaDRZ20 show how corules can be successfully employed to tackle this problem, by providing big-step semantics able to model divergence for several variations of the lambda-calculus and different kinds of observations. Following this approach, we present in big-step-example a similar example, but simpler, to keep it shorter: a logic program with coclauses defining the big-step semantics of a toy language to output possibly infinite sequences888For simplicity we consider only integers, but in fact the definition below allows any term as output. of integers. Expressions are regular terms generated by the following grammar:
where is the idle expression, outputs , and is the sequential composition. The semantic judgement has shape , represented by the atom , where is an expression, is either or , for converging or diverging computations, respectively, and is a possibly infinite sequence of integers.
Clauses for are pretty standard; in this case the definition is purely inductive (hence, no coclause is needed) since the left operand of concatenation is always a finite sequence. Clauses for are rather straightforward, but sequential composition deserves some comment: if the evaluation of converges, then the computation can continue with the evaluation of , otherwise the overall computation diverges and 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 can be derived. Furthermore, the cofact handles diverging expressions which produce a finite output sequence, as in or in , with or , while the coclause deals with diverging expressions with infinite outputs, as in with and . The body of the coclause ensures that the left operand of sequential composition converges, thus ensuring a correct productive definition.
6 Soundness and completeness
After formally relating the two approaches, we state soundness of the operational semantics with respect to the declarative one. Then, we show that completeness does not hold in general, and define the regular version of the declarative semantics. Finally, we show that the operational semantics is equivalent to this restricted declarative semantics.
Relation between operational and declarative semantics
As in the standard case, the first step is to bridge the gap between the two approaches: the former computing equations, the latter defining truth of atoms. This can be achieved through the notions of answers to a goal.
Given a set of equations , is the set of the solutions of , that is, the ground substitutions unifying all the equations in . Then, is an answer to if .
The judgment described in Section 4 computes a set of answers to the input goal. Indeed, solutions of the output set of equations are solutions of the input set as well, since the following proposition holds.
If then and .
If , then .
(1) Straightforward induction on rules in Figure 2. (2) Trivial.
On the other hand, we can define which answers are correct in an interpretation:
For , the set of answers to correct in is .
Hence, soundness of the operational semantics can be expressed as follows: all the answers computed for a given goal are correct in the declarative semantics.
Theorem 6.1 (Soundness w.r.t. declarative semantics)
If holds, then .
The converse of this theorem, that is, all correct answers can be computed, cannot hold in general, since, as shown by Ancona and Dovier AnconaD15, coinductive declarative semantics does not admit any complete procedure999That 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., hence our model as well, since it generalizes the coinductive one. To explain why completeness does not hold in our case, we can adapt the following example from Ancona and Dovier AnconaD15101010Example 10 at page 8., where is a predicate symbol of arity , and are function symbols of arity and respectively.
Let us define , and . The declarative semantics is the set . In the operational semantics, instead, only is considered true. Indeed, all derivations have to apply the rule co-hyp, which imposes the equation , whose unique solution is . Therefore, the operational semantics is not complete.
Now the question is the following: can we characterize in a declarative way answers computed by the big-step semantics? In the example, there is a difference between the atoms and , with , because the former has a regular proof tree, namely, a tree with finitely many different subtrees, while the latter has only with non-regular, thus infinite, proof trees.
Following this observation, we prove that the operational semantics is sound and complete with respect to the restriction of the declarative semantics to atoms derivable by regular proof trees. As we will see, this set can be defined in model-theoretic terms, by restricting to finite comodels of the program. Dagnino Dagnino20 defined this restriction for an arbitrary (generalized) inference system. We report here relevant definitions and results.
Regular declarative semantics
Let us write if is a finite subset of . The regular interpretation of is defined as
This definition is like the one of , except that we take the union111111Which could be an infinite set, hence it is not the same of the greatest finite consistent set. only of those consistent subsets of which are finite.The set is a fixed point of and, precisely, it is the rational fixed point [AdamekMV06] of restricted to , hence we get .
The proof-theoretic characterization relies on regular proof trees, which are proof trees with a finite number of subtrees [Courcelle83]. That is, as proved by Dagnino Dagnino20, is the set of judgments with a regular proof tree in whose nodes all have a finite proof tree in .
As special case, we get regular semantics of logic programs with coclauses.
The regular declarative semantics of , denoted by , is the union of all finite comodels included in .
As above, , hence .
We state now soundness and completeness of the operational semantics with respect to this semantics. We write iff and, for all , . It is easy to see that is a partial order and, if and , then .
Theorem 6.2 (Soundness w.r.t. regular declarative semantics)
If , and , then .
Theorem 6.3 (Completeness w.r.t. regular declarative semantics)
If , then , and for some and .
In order to prove the equivalence of the two semantics, we rely on a property which holds in general for the regular interpretation [Dagnino20]: we can construct an equivalent inductive characterization. That is, given a generalized inference system on the universe , we can construct an inference system with judgments of shape , for and , such that the inductive interpretation of coincides with the regular interpretation of . The set , whose elements are called coinductive hypotheses , is used to detect cycles in the proof.
In particular, for logic programs with coclauses, we get an inference system with judgments of shape , for finite set of ground atoms, and ground atom, defined as follows.
Given , the inference system consists of the following (meta-)rules:
The following proposition states the equivalence with the regular interpretation. The proof is given by Dagnino Dagnino20 in the general case of inference systems with corules.
Note that the definition of has many analogies with that of the operational semantics in Figure 2. The key difference is that the former handles ground, not necessarily finite, atoms, the latter not necessarily ground finite atoms (we use the same metavariables and for simplicity). In both cases already considered atoms are kept in an auxiliary set . In the former, to derive an atom , the side condition requires to belong to the inductive intepretation of the program . In the latter, when an atom unifies with one in , standard SLD resolution is triggered in the program .
To summarize, can be seen as an abstract version, at the level of the underlying inference system, of operational semantics. Hence, the proof of soundness and completeness can be based on proving a precise correspondence between these two inference systems, both interpreted inductively. This is very convenient since the proof can be driven in both directions by 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 and ,
if then, for all and , .
Lemma 6.2 (Completeness w.r.t. inductive characterization of regular semantics)
For all , and ,
if , for all , then and , for some and .
Soundness follows from Lemma 6.1 and Proposition 6.2, as detailed below. Theorem 6.2 Let us assume with , and consider . By Lemma 6.1, for all , holds, hence, by Proposition 6.2, we get . Therefore, by Definition 6.2, we get , as needed.
7 Related work and conclusion
We have provided a detailed formal account of an extension of logic programming where programs are enriched by coclauses, which can be used to tune the interpretation of predicates on non-well-founded structures. More in detail, following the same pattern as for standard logic programming, we have defined:
A declarative semantics (the union of all finite comodels which are subsets of a certain set of atoms determined by coclauses).
An operational semantics (a combination of standard SLD resolution and coSLD resolution) 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 as breadth-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 different from the standard case.
It has been shown [AnconaD15] that, taking as declarative semantics the coinductive semantics (largest comodel), there is not even a semi-algorithm to check that an atom belongs to that semantics. Hence, there is no hope to find a complete operational semantics. On the other hand, our paper provides, for an extension of logic programming usable in pratice to handle non-well-founded structures, fully-developed foundations and results which are exactly the analogous of those for standard logic programming.
CoLP has been initially proposed by Simon et al. Simon06,SimonMBG06,SimonBMG07 as a convenient sub-paradigm of logic programming to model circularity; it was soon recognized the limitation of its expressive power that does not allow mutually recursive inductive and coinductive predicates, or predicates whose correct interpretation is neither the least, nor the greatest fixed point.
Moura et al. Moura13,Moura14 and Ancona Ancona13 have proposed implementations of coLP based on refinements of the Simon’s original proposal with the main aim of making them more portable and flexible. Ancona has extended coLP by introducing a finally clause, allowing the user to define the specific behavior of a predicate when solved by coinductive hypothesis. Moura’s implementation is embedded in a tabled Prolog related to the implementation of Logtalk, and is based on a mechanism similar to finally clauses to specify customized behavior of predicates when solved by coinductive hypothesis. While such mechanisms resemble coclauses, the corresponding formalization is purely operational and lacks a declarative semantics and corresponding proof principles for proving correctness of predicate definitions based on them.
Ancona and Dovier AnconaD15 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 for deciding whether a regular goal belongs to the coinductive declarative semantics, but provided no completeness result restricted to regular derivations, neither mechanisms to extend coLP and make it more flexible.
Ancona et al. AnconaDZ17 were the first proposing a principled extension of coLP based on the notion 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. the former. An implementation is provided through a SWI-Prolog meta-interpreter.
Our present work differs from the extension of coLP with cofacts mentioned above for the following novel contributions:
we consider the more general notion of coclause, which includes the notion of cofact, but is a more expressive extension of coLP;
we introduce the notion of regular declarative semantics and prove coSLD resolution extended 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 with coclauses and rely on this relationship to carry out proofs in a clean and principled way;
we extend the implementation121212See https://github.com/davideancona/coLP-with-coclauses, where also examples of examples are available. of the SWI-Prolog meta-interpreter to support coclauses.
While coSLD resolution and its proposed extensions are limited by the fact that cycles must be detected in derivations to allow resolution to succeed, a stream of work based on the notion of structural resolution [KPS12-2, KJS17] (S-resolution for short) aims to make coinductive resolution more powerful, by allowing to lazily detect infinite derivations which do not have cycles. In particular, recent results [Y17, KY17, BKL19] investigate how it is possible to integrate coLP cycle detection into S-resolution, by proposing a comprehensive theory. Trying to integrate S-resolution with coclauses is an interesting topic for future work aiming to make coLP even more flexible.
Another direction for further research consists in elaborating and extending the examples of logic programs with coclauses provided in Section 5, to formally prove their correctness, and experiment their effectiveness with the implemented meta-interpreter.
Appendix A Proofs
In this section we report proofs omitted in Section 6.
We prove Lemma 6.1. To carry out the proof, we rely on Proposition 6.2 and on the following proposition, stating that the inductive declarative semantics of a logic program coincides with the regular semantics of a logic program with no coclauses. The proof is given by Dagnino Dagnino20 in the general case of inference systems with corules.
Let be a logic program, then .
There is nothing to prove.
We have , there is a fresh renaming of a clause in such that and are unifiable in , that is, is solvable, and and hold. Let , then, by induction hypothesis, we have, for all with , holds. By Proposition 6.1, we have , hence , thus , and, since , is a unifier of and , that is, . Then, by induction hypothesis, we also get, for all , holds. Since and and , by rule unfold of Definition 6.3, we get that holds as well.
We have , there is an atom that unifies with in , that is, is solvable, and and hold. Let , then, by induction hypothesis, we get, for all with ,