This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\jdate

March 2003 \pagerangeLABEL:firstpageC

Planning for an Efficient Implementation of
Hypothetical Bousi\simProlog

Pascual Julián-Iranzo
Dept. of Information Technologies and Systems
This work was supported by the State Research Agency (AEI) of the Spanish Ministry of Science and Innovation under grant PID2019-104735RB-C42 (SAFER), by the Spanish Ministry of Economy and Competitiveness, under the grants TIN2016-76843-C4-2-R (MERINET), TIN2017-86217-R (CAVI-ART-2), and by the Comunidad de Madrid, under the grant S2018/TCS-4339 (BLOQUES-CM), co-funded by EIE Funds of the European Union.
   University of Castilla-La Mancha    Spain
[email protected]
   Fernando Sáenz-Pérez
Dept. of Software Engineering and Artificial Intelligence
   Universidad Complutense de Madrid    Spain
[email protected]
(2003)
Abstract

This paper explores the integration of hypothetical reasoning into an efficient implementation of the fuzzy logic language Bousi\simProlog. To this end, we first analyse what would be expected from a logic inference system, equipped with what is called embedded implication, to model solving goals with respect to assumptions. We start with a propositional system and incrementally build more complex systems and implementations to satisfy the requirements imposed by a system like Bousi\simProlog. Finally, we propose an inference system, operational semantics, and the translation function to generate efficient Prolog programs from Bousi\simProlog programs. This paper is under consideration for acceptance in TPLP.

doi:
S1471068401001193
keywords:
Fuzzy Logic Programming, Fuzzy Prolog, Bousi\simProlog, Hypothetical Reasoning, System Implementation

1 Introduction

Hypothetical reasoning allows deductions to be made in terms of assumed data. Applications include planning and scheduling [Wilson and Nuzzolo (2008)], logistics [Calantone et al. (2017)], behaviour [Bosse and Gerritsen (2009)], healthcare [Minutolo et al. (2016)], law [Bench-Capon and Prakken (2010)] and everything related to decision making in the scenarios envisioned. This so-called ‘what-if’ analysis [Rizzi (2009)] plays an important role in saving resources, time and money. For example, designing the pipe network of a gas company includes an assessment of the appropriateness of conversion stations and pipes in terms of gas production, sourcing and expected client demand.

In addition, real-world applications must typically handle not-yet-known data, foreseeing scenarios for which it is necessary to handle vague information. Fuzzy logic is suitable for such imprecise and subjective knowledge, and has been successfully applied to such different fields as process control (e.g., UAV flight control [Moreno and Vázquez (2014)], Japan Sendai Subway with its ATC/ATO security system, domestic appliances such as Samsung dishwashers…), deductive databases (FSQL [Galindo (2005)], a fuzzy version of SQL), and fuzzy expert systems (such as [Kunhimangalam et al. (2013)] in the healthcare domain).

Combining features from both hypothetical reasoning and fuzzy logic thus seems a reasonable field to study. This paper deals with such a combination for the inclusion of hypothetical reasoning (with features derived from intuitionistic logics) in the Bousi\simProlog  (BPL) fuzzy logic system [Rubio-Manzano and Julián-Iranzo (2014), Julián-Iranzo and Rubio-Manzano (2017)]. In particular, we focus on embedded implications, as in [Bonner (1994)]. Assumptions can be reused throughout proofs in this kind of logic, in contrast to substructural logics [Lopez and Pimentel (1999)]. Basically, the following inference rule, which uses so-called embedded implication ‘\Rightarrow[Bonner (1994)], captures the fact that hypothesis RR (a rule) is used (as many times as needed) to derive the proof for goal ϕ\phi in the context of program Π\Pi:

Π{R}ϕΠRϕ\Pi\vdash R\Rightarrow\phi\Pi\cup\{R\}\vdash\phi

This inference rule means that if the inference expression above the line can be inferred, then the one below the line can be inferred too. However, this inference rule, linked to the deduction theorem of classical logic, only models a small part of the characteristics and power of hypothetical reasoning.

This paper explores a path to an efficient implementation of hypothetical reasoning in Bousi\sim Prolog. As developed for SWI-Prolog [Wielemaker et al. (2012)], this Prolog system is considered here for implementations. Firstly, Sections 2 to 3 incrementally develop a hypothetical logic inference system. Specifically, Sections 3.2 and 3.3 introduce the requirements that Bousi\simProlog imposes on hypothetical reasoning that need to be tackled and how they can be addressed in the hypothetical logic inference system. Section 4 recalls the formalisation of Bousi\simProlog and adapts it to efficiently include hypothetical reasoning in this language and system. Finally, Section 5 gives the conclusions and sets out further work to be addressed. Three appendices contain a performance analysis, formal proofs and a discussion on related work.

2 Implementing a hypothetical propositional logic inference system

As a first step, we study how to introduce hypothetical reasoning in a propositional logic framework where a program Π\Pi comprises rules of the form AQ1QnA\leftarrow Q_{1}\land\ldots\land Q_{n}, where AA is a propositional letter, called the head of the rule; and QiQ_{i} are propositional letters or embedded implications which form the body. A rule AtrueA\leftarrow true is written as AA. An embedded implication is an expression of the form RiAiR_{i}\Rightarrow A_{i} where RiR_{i} is a rule (possibly with embedded implications in its body) and AiA_{i} is a propositional letter. Embedded implications cannot appear as the head of a rule. Note also that embedded implications can be nested. That is, the expression R1((RnAi))R_{1}\Rightarrow(\ldots\Rightarrow(R_{n}\Rightarrow A_{i})\ldots) is a well-formed expression of this language. In the following, we shall write nested embedded implications as R1RnAiR_{1}\Rightarrow\ldots\Rightarrow R_{n}\Rightarrow A_{i}, omitting the parentheses.

2.1 Hypothetical propositional SLD resolution

A basic hypothetical propositional logic transition system is first defined, to determine the operational semantics of the language.

Let Π\Pi be a program. Let EE be a set of tuples G,Π\langle G,\Pi\rangle (goal, program), each representing a state of a computation. Let HPSLDHPSLD(E×E)\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\subseteq(E\times E) be the transition relation as now defined in Definition 2.1. A successful inference sequence for a given state is a sequence ending in the state ,Π\langle\square,\Pi\rangle, where \square represents the empty clause.

Definition 2.1

Hypothetical Propositional SLD (HPSLD) resolution is defined as a transition system E,HPSLDHPSLD\langle E,\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\rangle, and whose transition relation HPSLDHPSLD\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}} is the smallest relation satisfying:
Rule 1: if R(AQ)ΠR\equiv(A\leftarrow Q)\in{\Pi}: (AQ),ΠHPSLDHPSLD(QQ),Π{\langle(\leftarrow\!\!A\!\wedge\!Q^{\prime}),\Pi\rangle}\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}{\langle(\leftarrow\!\!Q\!\wedge\!Q^{\prime}),\Pi\rangle}

Rule 2: if (A),ΠHPSLDHPSLD,Π\langle(\leftarrow A),\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\square,\Pi^{\prime}\rangle, with Π=Π{R}\Pi^{\prime}=\Pi\cup\{R\}, is a successful inference sequence: ((RA)Q),ΠHPSLDHPSLD(Q),Π{\langle(\leftarrow\!\!(R\!\Rightarrow\!A)\!\wedge\!Q),\Pi\rangle}\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}{\langle(\leftarrow\!Q),\Pi\rangle} \blacksquare

The following simple program, adapted from [Bonner (1994)], illustrates this definition.

Example 1

Given the program Π={a(db)e,bc,cd,e}\Pi=\{a\leftarrow(d\Rightarrow b)\wedge e,b\leftarrow c,c\leftarrow d,e\} and the goal a\leftarrow a, the successful derivation a,ΠHPSLDHPSLD(db)e,ΠHPSLDHPSLDe,ΠHPSLDHPSLD,Π\langle\leftarrow a,\Pi\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\leftarrow(d\Rightarrow b)\wedge e,\Pi\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\leftarrow e,\Pi\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\square,\Pi\rangle is possible thanks to the hypothetical query associated derivation: b,Π{d}HPSLDHPSLDc,Π{d}HPSLDHPSLDd,Π{d}HPSLDHPSLD,Π{d}\langle\leftarrow b,\Pi\cup\{d\}\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\leftarrow c,\Pi\cup\{d\}\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\leftarrow d,\Pi\cup\{d\}\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\square,\Pi\cup\{d\}\rangle where the initial program Π\Pi is expanded with the hypothesis dd.

This definition of hypothetical propositional resolution can be neatly implemented in Prolog with a meta-interpreter keeping track of the current program, which can be augmented as needed by the embedded implication. Proposals of other logic systems [Bonner (1994), Lopez and Pimentel (1999)] also suggest this kind of implementation (passing the program as an argument). The solving of an embedded implication can be implemented in a meta-interpreter with the clause: solve((Rϕ),Π)solve(ϕ,[R|Π])solve((R\Rightarrow\phi),\Pi)\leftarrow solve(\phi,[R|\Pi]) (cf. Appendix A). But passing the program as an argument in Prolog requires that its data structure be built in the heap, a costly operation. Another alternative is to use the dynamic database to assert the program rules. In contrast to other Prolog implementations, SWI-Prolog does not differentiate between compiling and asserting, producing a similar code for both operations which, in particular, retains multi-argument and deep indexing. In this way, accessing data in dynamic memory is typically faster than in the heap, even using techniques such as Key-Value associations implemented as a balanced binary tree (AVL tree).

A first approach to dealing with the embedded implication is to consult the program as a normal Prolog program with a definition for the embedded implication with the operator \Rightarrow: (XY)assertz(X)call(Y)retract(X).(X\Rightarrow Y)\leftarrow assertz(X)\land call(Y)\land retract(X). Thus, it is possible to answer goal p\leftarrow p for program {pqqp\leftarrow q\Rightarrow q}: solving pp amounts to asserting qq and subsequently solving goal q\leftarrow q. When qq has been proved, the assumption is retracted. However, this approach is not correct because alternatives can be lost. Consider the program {p(qr)qp\leftarrow(q\leftarrow r)\Rightarrow q, rr, rr}. Clearly, there should be two answers for goal pp but, after solving qq for the first answer, the hypothesis is retracted, so that further answers are lost.

Simply removing the retraction does not fix the issue because the hypothesis would then be beyond the scope of the implication. For example, in the program {p(qq)qp\leftarrow(q\Rightarrow q)\land q}, the goal p\leftarrow p would succeed when it should fail because the second call to qq is outside the scope of the embedded implication. Instead, a plausible approach is to attach each hypothesis to the program context it belongs to, and allow its selection only in that context, which is the technique explained in the next section.

2.2 Program contexts to implement embedded implications

Rule 2 in Definition 2.1 constructs a proof for the consequent AA in the context of Π{R}\Pi\cup\{R\}, where Π\Pi is the current program and RR is the antecedent of the embedded implication (hypothesis). Thus, each assumption builds a new program which can be understood as a program context for the proof of a consequent.

Definition 2.2

Given a program Π\Pi and an embedded implication query RAR\Rightarrow A, the hypothetical context (or simply a context) of a proof for AA is the program Π=Π{R}\Pi^{\prime}=\Pi\cup\{R\}.

Because embedded implication queries can be nested, R1R2RnAR_{1}\Rightarrow R_{2}\Rightarrow\ldots R_{n}\Rightarrow A, also hypothetical contexts can be chained Π0Π1Π2Πn\Pi_{0}\subseteq\Pi_{1}\subseteq\Pi_{2}\subseteq\ldots\subseteq\Pi_{n}, where Πi+1=Πi{Ri+1}\Pi_{i+1}=\Pi_{i}\cup\{R_{i+1}\}. Hypothetical contexts are partially ordered by the set inclusion relation \subseteq. For pragmatic reasons, contexts can be identified by a sequence of unique symbols, one for each new context in the inference sequence. For the chain of contexts Π0Π1Π2Πn\Pi_{0}\subseteq\Pi_{1}\subseteq\Pi_{2}\subseteq\ldots\subseteq\Pi_{n}, the sequence of symbols i1iji_{1}\ldots i_{j}, 1jn1\leq j\leq n, identifies the context Πj\Pi_{j}, where Π0\Pi_{0} stands for the initial user program (for which the empty sequence is assumed as its context identifier).

More formally, given a (possibly total ordered) set of indexes II, a context Πj\Pi_{j} can be identified by a univocal sequence of indexes sj=i1ijs_{j}=i_{1}\ldots i_{j}, 1jn1\leq j\leq n, called a context identifier, and alternatively denoted by Πsj\Pi_{s_{j}}. For a context Πs\Pi_{s}, with context identifier ss, and an embedded implication query RAR\Rightarrow A, a new context Πs.i\Pi_{s.i} is built, where the context identifier s.is.i is the concatenation of a fresh index iIi\in I to the sequence ss. The initial user program Π0\Pi_{0} is denoted by Πϵ\Pi_{\epsilon}, where ϵ\epsilon is the empty sequence.

The set of context identifiers SS is a prefix-ordered set, where the prefix relation \preceq on SS is defined as follows: for two context identifiers s1s_{1} and s2s_{2}, s1s2s_{1}\preceq s_{2} if and only if s1s_{1} is a prefix of s2s_{2}; that is, there exists a sequence of indexes ss such that s2=s1.ss_{2}=s_{1}.s. The prefix relation is reflexive ((sS)ss(\forall s\in S)~{}s\preceq s), anti-symmetric ((s1,s2S)s1s2s2s1s1=s2(\forall s_{1},s_{2}\in S)s_{1}\preceq s_{2}\wedge s_{2}\preceq s_{1}\to s_{1}=s_{2}), transitive ((s1,s2,s3S)s1s2s2s3s1s3(\forall s_{1},s_{2},s_{3}\in S)s_{1}\preceq s_{2}\wedge s_{2}\preceq s_{3}\to s_{1}\preceq s_{3}) and downward total ((s1,s2,s3S)s1s3s2s3(s1s2s2s1)(\forall s_{1},s_{2},s_{3}\in S)~{}s1\preceq s_{3}\wedge s_{2}\preceq s_{3}\to(s1\preceq s_{2}\vee s_{2}\preceq s_{1})) [Cuijpers (2013)]. The first three properties classify a prefix order as a partial order. Only the downward totality is special, meaning that, although the future evolution of a computation may be branching, from a given point of execution, the past is always totally ordered. In our framework, where the set of sequences has a minimum element (the empty sequence ϵ\epsilon), the evolution of a computation can be abstracted by a tree structure, where the branches are sequences representing a context identifier and each prefix in the sequence, a previous context identifier. By construction, for all context identifiers s1s_{1} and s2s_{2}, if s1s2s_{1}\preceq s_{2} then Πs1Πs2\Pi_{s_{1}}\subseteq\Pi_{s_{2}}.

As contexts are sets of rules, each rule can be identified as belonging to a context by the identifier of its program context. Thus, a context identifier can be associated with a rule.

Definition 2.3 (Scope of a rule)

Given a rule RR with context identifier sjs_{j}, its scope is any context Πsk\Pi_{s_{k}} such that sjsks_{j}\preceq s_{k}. \blacksquare

In the framework of hypothetical reasoning, a rule only can be selected for solving if it is within the scope of the current context. Alternatively, we often say that RR, with context identifier sjs_{j}, is included in (or belongs to) the context Πsk\Pi_{s_{k}}, because ΠsjΠsk\Pi_{s_{j}}\subseteq\Pi_{s_{k}} when sjsks_{j}\preceq s_{k}. Thus, from a context Πsk\Pi_{s_{k}} it is possible to access all rules whose context identifier sjs_{j} is a prefix of sks_{k}.

2.3 Translating hypothetical propositional programs into Prolog

Hypothetical propositional SLD resolution can be efficiently implemented by translating hypothetical propositional programs into Prolog in a such a way as to mimic this operational semantics. This translation is based on, first, providing a context identifier for each rule (either a user-program rule or the hypothesis in an embedded implication); and, second, transmitting the current context for which the rule is selected during inferencing. Each hypothesis receives a new index symbol (an integer for simplicity) which is added to the current context identifier sequence to form the identifier of the new context. This sequence can be implemented as a reversed integer list.

In contrast to the basic implementations in Section 2, user programs and hypotheses must be translated by adding the new arguments for the rule and current context identifiers:

Definition 2.4 (Propositional rule and goal translation)

The rule translation of Rp1inqiR\equiv p\leftarrow\land_{1\leq i\leq n}q_{i} for a rule context identifier SRS^{R} and a current context identifier SCS^{C}, is defined as p(SR,SC)chk(SR,SC)1inqi,p(S^{R},S^{C})\leftarrow chk(S^{R},S^{C})\land_{1\leq i\leq n}q^{\prime}_{i}, where chk(SR,SC)chk(S^{R},S^{C}) checks context inclusion (i.e., whether SRSCS^{R}\preceq S^{C}) and the goal translation qiq^{\prime}_{i}, for the current context identifier SCS^{C}, is either:

  • qiq_{i} for a built-in call; or

  • qi(C,SC)q_{i}(C,S^{C}) for a user-predicate call, where CC is a new free variable representing any context in the scope of the current context SCS^{C}; or

  • HGH^{\prime}\Rightarrow G^{\prime} for an embedded implication HGH\Rightarrow G, where: HH^{\prime} is the rule translation of HH for a rule context identifier SH=SC.IS^{H}=S^{C}.I (where II is a fresh index) and a new current context identifier SCS^{C^{\prime}}, and GG^{\prime} is the goal translation of GG for a current context identifier SHS^{H}. \blacksquare

Definition 2.4 deserves some comment. Firstly, variables (e.g., SRS^{R} or SCS^{C}) denote context identifiers, which may be unknown at translation time. In general, SRS^{R} (or SHS^{H}) denotes the context to which a rule RR (or HH) belongs, while SCS^{C} (or SCS^{C^{\prime}}) denotes the current context in which the rule will be selected for solving or the goal will be solved.

Since an embedded implication HGH\Rightarrow G generates a new context SH=SC.IS^{H}=S^{C}.I, the corresponding hypothetical rule HH will be annotated with SHS^{H}, which will be the current context in which the goal G will be solved. It is not possible to set the actual index II in the sequence SHS^{H} for the embedded implication until solving-time (also, depending on the goal, not all contexts will be needed). Actually solving an embedded implication will bind the elements in the sequence representing the context. As chk(ϵ,SC)chk(\epsilon,S^{C}) always holds, it can be omitted in the translation. The following example illustrates Definition 2.4 for a simple program rule:

Example 2

Assume the source program rule RpqqR\equiv p\leftarrow q\Rightarrow q. For a source rule RR, the rule context identifier SR=ϵS^{R}=\epsilon. Applying Definition 2.4 to translate RR for SRS^{R}, leads to: p(ϵ,SC)chk(ϵ,SC)(HG)p(\epsilon,S^{C})\leftarrow chk(\epsilon,S^{C})\wedge(H^{\prime}\Rightarrow G^{\prime}), where HGH^{\prime}\Rightarrow G^{\prime} is the translation of the embedding implication HGqqH\Rightarrow G\equiv q\Rightarrow q.

In order to translate HH, consider that HH is really seen as the rule qq (shorthand for qtrueq\leftarrow true, where truetrue is a built-in symbol). Then, recursively applying Definition 2.4, the translation of HH for the rule context identifier SH=SC.IS^{H}=S^{C}.I (where II is a fresh variable denoting an unknown index which will be resolved at run-time) is Hq(SC.I,SC)chk(SC.I,SC)trueH^{\prime}\equiv q(S^{C}.I,S^{C^{\prime}})\leftarrow chk(S^{C}.I,S^{C^{\prime}})\wedge true. The translation of GG is simply Gq(C,SC.I)G^{\prime}\equiv q(C,S^{C}.I), where CC is a fresh variable.

The translation of RR is: p(ϵ,SC)((q(SC.I,SC)chk(SC.I,SC)true)q(C,SC.I))p(\epsilon,S^{C})\leftarrow((q(S^{C}.I,S^{C^{\prime}})\leftarrow chk(S^{C}.I,S^{C^{\prime}})\wedge true)\Rightarrow q(C,S^{C}.I)) where the call to chk(ϵ,SC)chk(\epsilon,S^{C}) has been omitted because, as previously mentioned, it always succeeds.

Our actual implementation produces the following translated Prolog rule for RR, where truetrue calls are omitted:

    p([], A) :- (q([B|A], C) :- chk([B|A], C)) => q(_, [B|A])

where chkchk is straightforwardly implemented as: chk(S1, S2) :- append(_, S1, S2). \blacksquare

Solving the embedded implication can be implemented as follows:

Definition 2.5 (Solving the propositional implication clause)

Solving the propositional implication clause for SLD resolution is defined as:
(RG)get_ci(I)rule_context(R,S.I)assertz(R)call(G)(R\Rightarrow G)\leftarrow get\_ci(I)\land rule\_context(R,S.I)\land assertz(R)\land call(G).
where the predicate get_ciget\_ci/1 returns a unique integer each time it is called, and rule_contextrule\_context/2 simply provides access in its second argument to the context of RR. \blacksquare

Considering SLDSLD(E×E)\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\subseteq(E\times E) as the transition relation for propositional SLD resolution of a program Π\Pi, where EE is a set of states formed by tuples G,θ,Π\langle G,\theta,\Pi\rangle (goal, substitution, program), the following can be stated:

Proposition 2.6

For a program Π\Pi and goal A\leftarrow A, there exists (A),Π\langle(\leftarrow A),\Pi\rangle HPSLDHPSLD,Π\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HPSLD}}}}\langle\square,\Pi\rangle iff A,id,ΠSLDSLD,id,Π\langle\leftarrow A^{\prime},id,\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,id,\Pi^{\prime}\rangle, where Π\Pi^{\prime} is the propositional translation of each rule in Π\Pi, and AA^{\prime} is the propositional goal translation of AA. \blacksquare

See the proof of Proposition 3.6 in the predicate logic case, of which this is a particular case.

3 Implementing a hypothetical predicate logic inference system

In this section we discuss how to extend hypothetical reasoning from the framework of propositional logic to the framework of predicate logic as a prior step to the introduction of hypothetical reasoning into the fuzzy logic programming language Bousi\simProlog.

As in the propositional case, the programs of our hypothetical logic language are sets of rules of the form AQ1QnA\leftarrow Q_{1}\land\ldots\land Q_{n}, but composed of atomic formulas instead of only propositional letters. Rules are assumed to be universally quantified and the occurrence of extra variables in the body of a rule can be understood as existentially quantified. When translating embedded implications, the question of how to deal with their variables is an important one.

3.1 Hypothetical SLD resolution

Definition 2.1 can be extended to the non-propositional case by dealing with substitutions, which then become part of the notion of computation state. Let EE be a set of tuples G,σ,Π\langle G,\sigma,\Pi\rangle (goal, substitution, program), each representing a state of a computation. Let HSLDHSLD(E×E)\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\subseteq(E\times E) be the transition relation as defined in Definition 3.1 below. A successful inference sequence for a given state is a sequence ending in the state ,σ,Π\langle\square,\sigma^{\prime},\Pi\rangle.

Definition 3.1 (HSLD resolution)

Hypothetical SLD (HSLD) resolution is defined as a transition system E,\langle E, HSLDHSLD\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\rangle, whose transition relation HSLDHSLD\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}} is the smallest relation satisfying:
Rule 1: if R(AQ)ΠR\equiv(A\leftarrow Q)\in{\Pi} and mgu(A,A)=σmgu(A,A^{\prime})=\sigma: (AQ),θ,ΠHSLDHSLD(QQ)σ,θσ,Π{\langle(\leftarrow\!\!A^{\prime}\!\wedge\!Q^{\prime}),\theta,\Pi\rangle}\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}{\langle(\leftarrow\!\!Q\!\wedge\!Q^{\prime})\sigma,\theta\sigma,\Pi\rangle} Rule 2: if (A),id,ΠHSLDHSLD,σ,Π\langle(\leftarrow A),id,\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\sigma,\Pi^{\prime}\rangle is a successful inference sequence with Π=Π{R}\Pi^{\prime}=\Pi\cup\{R\}: ((RA)Q),θ,ΠHSLDHSLD(Qσ),θσ,Π{\langle(\leftarrow\!\!(R\!\Rightarrow\!A)\!\wedge\!Q),\theta,\Pi\rangle}\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}{\langle(\leftarrow\!Q\sigma),\theta\sigma,\Pi\rangle}

As in the propositional case, HSLD can be implemented as a meta-interpreter, and Definition 2.4 can easily be extended to the predicate logic case by using predicates instead of propositions:

Definition 3.2 (Rule and goal translation for predicate logic)

The rule translation of Rp(X¯)1inqi(Xi¯)R\equiv p(\overline{X})\leftarrow\land_{1\leq i\leq n}q_{i}(\overline{X_{i}}) for a rule context identifier SRS^{R} and a current context identifier SCS^{C}, is defined as the rule p(X¯,SR,SC)chk(SR,SC)1inqi,p(\overline{X},S^{R},S^{C})\leftarrow chk(S^{R},S^{C})\land_{1\leq i\leq n}q^{\prime}_{i}, where chk(SR,SC)chk(S^{R},S^{C}) checks context inclusion (i.e., whether SRSCS^{R}\preceq S^{C}) and the goal translation of qi(Xi¯)q_{i}(\overline{X_{i}}) for the current context identifier SCS^{C} is either:

  • qi(Xi¯)q_{i}(\overline{X_{i}}) for a built-in call; or

  • qi(Xi¯,C,SC)q_{i}(\overline{X_{i}},C,S^{C}) for a user-predicate call, where CC is a new free variable representing any context within the scope of the current context SCS^{C}; or

  • HGH^{\prime}\Rightarrow G^{\prime} for an embedded implication HGH\Rightarrow G, where: HH^{\prime} is the rule translation of HH for a rule context identifier SH=SC.IS^{H}=S^{C}.I (where II is a fresh index) and a new current context identifier SCS^{C^{\prime}}, and GG^{\prime} is the goal translation of GG for a current context identifier SHS^{H}. \blacksquare

The following example illustrates Definition 3.2 for a simple program that will be used in several places hereafter:

Example 3

Given the source program Π={R1:p(X)g(X)(q(X)r),R2:g(1),R3:rq(2)}\Pi=\{R_{1}:p(X)\leftarrow g(X)\land(q(X)\Rightarrow r),R_{2}:g(1),R_{3}:r\leftarrow q(2)\}, note that all rules are translated for the rule context identifier SR=ϵS^{R}=\epsilon. Specifically, applying Definition 3.2 to translate R1R_{1} for SRS^{R}, gives: p(X,ϵ,SC)chk(ϵ,SC)G1(H2G2)p(X,\epsilon,S^{C})\leftarrow chk(\epsilon,S^{C})\wedge G^{\prime}_{1}\wedge(H^{\prime}_{2}\Rightarrow G^{\prime}_{2}), where G1G^{\prime}_{1} is the goal translation of G1g(X)G_{1}\equiv g(X) and H2G2H^{\prime}_{2}\Rightarrow G^{\prime}_{2} is the translation of the embedding implication H2G2(q(X)r)H_{2}\Rightarrow G_{2}\equiv(q(X)\Rightarrow r).

Because G1g(X)G_{1}\equiv g(X) is a user-defined predicate, Definition 3.2 makes G1=g(X,C,SC)G^{\prime}_{1}=g(X,C,S^{C}). On the other hand, since H2q(X)trueH_{2}\equiv q(X)\leftarrow true, on recursively applying Definition 3.2, the translation of H2H_{2} for the rule context identifier SH=SC.IS^{H}=S^{C}.I (where II is a fresh variable denoting an unknown index which will be resolved at run-time) is H2q(X,SC.I,SC)chk(SC.I,SC)trueH^{\prime}_{2}\equiv q(X,S^{C}.I,S^{C^{\prime}})\leftarrow chk(S^{C}.I,S^{C^{\prime}})\wedge true. The translation of G2rG_{2}\equiv r for rule context identifier SHS^{H} is simply G2r(C,SC.I)G^{\prime}_{2}\equiv r(C^{\prime},S^{C}.I), where CC^{\prime} is a fresh variable. Finally, the translation of R1R_{1} is:

p(X,ϵ,SC)g(X,C,SC)((q(X,SC.I,SC)chk(SC.I,SC)true)r(C,SC.I))p(X,\epsilon,S^{C})\leftarrow g(X,C,S^{C})\wedge((q(X,S^{C}.I,S^{C^{\prime}})\leftarrow chk(S^{C}.I,S^{C^{\prime}})\wedge true)\Rightarrow r(C^{\prime},S^{C}.I))

where the call to chk(ϵ,SC)chk(\epsilon,S^{C}) has been omitted because, as previously mentioned, it always succeeds.

It is easy to determine that the translation of R2R_{2} is g(1,ϵ,SC)trueg(1,\epsilon,S^{C})\leftarrow true and the translation of R3R_{3} is r(ϵ,SC)q(2,C,SC)r(\epsilon,S^{C})\leftarrow q(2,C,S^{C}).

Our implementation produces the following translated Prolog program for the source program Π\Pi:

     p(A,[],B) :- g(A,_,B), ((q(A,[C|B],D):-chk([C|B],D)) => r(_,[C|B])).
     g(1,[],_).
     r([],A) :- q(2,_,A).

\blacksquare

Despite the two solutions above for solving the embedded implication by means of a meta-interpreter and program translation, our goal is to add this kind of implication to Bousi\simProlog, which requires complex rule transformations.

This raises two problems: First, in contrast to the solution in Definition 3.2, a more involved translation is required before asserting hypotheses. This first issue suggests avoiding program compilations at run-time by translating hypotheses at compile-time, but this leads to the second problem: When asserting a rule, all variables become universally quantified by default, but this is no longer true in the context of an embedded implication. Thus, it will be necessary to take account of substitutions in assumptions. Taking the logic system shown in Section 2.3 as a starting point, the following sections will cover these two issues.

3.2 Hypothesis precompilation

One possible approach to addressing the first problem is to translate and assert clauses at compile-time, so that a program does not need any translation at run-time. Although this involves all hypotheses in the program being translated and asserted, it is highly likely that the memory thus speculatively used will return a pay-off in terms of run-time gains.

Since it is not known how many times a given embedded implication will be selected for solving, some sort of registration is needed at run-time. First, the hypothesis can be translated and asserted at run-time and, whenever the embedded implication is selected for solving at run-time, the corresponding hypothesis is registered for the current context. Each registration will correspond to one alternative of the hypothesis and can be represented by an entry in a new dynamic predicate regreg/2: one argument for the rule reference and another for the context in which it was registered.

Therefore, registering a rule RR for a new context needs a univocal reference IRI^{R} to the rule. A new argument must thus be added to any predicate containing its reference, which can be achieved with a predicate similar to get_ciget\_ci (Definition 2.5). Definition 2.4 must be modified to add this argument to head clauses and to translate the embedded implication with the reference to the translated hypothesis. In addition to the call to the chkchk/2 predicate, each body rule must include a call to regreg/2 to retrieve, by backtracking, as many alternatives of the hypothesis as were registered in the course of the solving process.

In turn, solving the embedded implication needs to perform this registration of the hypothesis for the current context SCS^{C} augmented with this hypothesis. Then, the embedded implication is added, with two new arguments: the new element in the context identifier sequence ICI^{C} and the current context SCS^{C}, meaning it is no longer a binary operator: (IR,G,IC,SC)get_ci(IC)assertz(reg(IR,SC.IC))call(G)\Rightarrow(I^{R},G,I^{C},S^{C})\leftarrow get\_ci(I^{C})\land assertz(reg(I^{R},S^{C}.I^{C}))\land call(G)

The following examples informally illustrate the proposed translation (which will be formalised in Definition 3.5) and the behaviour of the translated program. From here on, context identifiers will be represented as reversed lists of unique indexes.

Example 4

The program {pqqp\leftarrow q\Rightarrow q} in Section 2 would be translated as:
Π={p(1,[],SC)(0,q(_,_,[IC|SC]),IC,SC),q(0,[_|_],SC)reg(0,CR)chk(CR,SC)}\Pi=\{p(1,[~{}],S^{C})\leftarrow~{}\Rightarrow(0,q(\_,\_,[I^{C}|S^{C}]),I^{C},S^{C}),q(0,[\_|\_],S^{C})\leftarrow~{}reg(0,C^{R})\land chk(C^{R},S^{C})\}.

In contrast to the method proposed in Section 2.3, the hypothesis qq of the embedded implication is compiled into a new rule. Three new arguments are added to the head of the rules: a unique rule index, the rule context identifier, and the current context identifier in which the rule will be used at run-time.

Solving the rule defining p/3p/3 will call the operator \Rightarrow, which will generate a unique identifier ICI^{C} and will register the rule defining q/3q/3 (the hypothesis) for the current context [IC|SC][I^{C}|S^{C}] before submitting the goal q(_,_,[IC|SC])q(\_,\_,[I^{C}|S^{C}]).

Solving by SLD resolution requires the program to be added as a third argument to the state tuple in the transition relation SLDSLD\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}, since it can be augmented by assertzassertz/1.

Example 5

For the program {p(qqq)p\leftarrow(q\Rightarrow q\Rightarrow q)}, the goal p\leftarrow p succeeds with two solutions. If the first (resp. second) context receives the identifier 0 (resp. 1), the program is translated as:

Π={p(2,nil,SC)([1],([0],q(_,_,[I0C,I1C|SC]),I0C,[I1C|SC]),I1C,A),q(0,[_,_|_],SC)reg(0,CR)chk(CR,SC),q(1,[_|_],SC)reg(1,CR)chk(CR,SC)}\begin{array}[]{ll}\Pi=&\{p(2,nil,S^{C})\leftarrow\Rightarrow([1],\Rightarrow([0],q(\_,\_,[I^{C}_{0},I^{C}_{1}|S^{C}]),I^{C}_{0},[I^{C}_{1}|S^{C}]),I^{C}_{1},A),\\ {}{}&q(0,[\_,\_|\_],S^{C})\leftarrow reg(0,C^{R})\land chk(C^{R},S^{C}),q(1,[\_|\_],S^{C})\leftarrow reg(1,C^{R})\land chk(C^{R},S^{C})\}\end{array}

where the facts: reg(1,[0])reg(1,[0]) and reg(0,[1,0])reg(0,[1,0]) are added while solving the embedded implications. Thus, the consequent q(_,_,[I0C,I1C|SC])q(\_,\_,[I^{C}_{0},I^{C}_{1}|S^{C}]) can be solved twice at context [1,0][1,0] because both hypotheses match the goal at their respective contexts ([1,0]([1,0] and [0])[0]).

An advantage of this approach with respect to that given in Section 2.3 is that assumptions via recursion require only one translated rule in the memory, rather than needing as many translated rules as assumptions. The following program illustrates this:

Π={p(0),p(N)N>0N1isN1(qp(N1))}\Pi=\{p(0),p(N)\leftarrow N>0\land N_{1}~{}is~{}N-1\land(q\Rightarrow p(N_{1}))\}

There is only one translated rule for qq (the same as in the previous example) and as many entries in regreg/2 as NN in the goal p(N)\leftarrow p(N).

3.3 Handling substitutions in assumptions

An assertion with free variables is a problem in this approach because it is translated at compile-time and the actual substitution is not known before solving-time.

Compared to the approach in Section 2.3 (and extended to the predicate logic case in Definition 3.2), where each assumption is asserted at run-time, now an assumption is asserted at compile-time without any trace of its actual substitution, which can lead to losing bindings for the shared variables between the hypothesis and its rule. The following program illustrates this issue:

Example 6

Consider again the program Π={p(X)g(X)(q(X)r),g(1),rq(2)}\Pi=\{p(X)\leftarrow g(X)\land(q(X)\Rightarrow r),g(1),r\leftarrow q(2)\} of Example 3. For this program, the goal p(X)\leftarrow p(X) succeeds because the translation of qq/1 is q(X,0,[_|_],SC)reg(0,CR)chk(CR,SC)q(X,0,[\_|\_],S^{C})\leftarrow reg(0,C^{R})\land chk(C^{R},S^{C}), and the call to rr succeeds because qq/1 is registered and the translation of q(2)q(2) unifies with the assertion, but it should not (as happens correctly following Definition 3.2). \blacksquare

Moreover, variable sharing is also a problem. Let us consider the following example:

Example 7

In the program Π={pg(X,Y)(q(X,Y)q(1,2)),\Pi=\{p\leftarrow g(X,Y)\land(q(X,Y)\Rightarrow q(1,2)), g(X,X)}g(X,X)\} the goal p\leftarrow p succeeds when it should not. \blacksquare

Substitutions must therefore be passed when solving an embedded implication by using its hypothesis: Each rule will contain an extra argument containing the list of shared variables. In addition, the list of shared variables will be added to the rule registration in the context of the embedded implication so that, at solving-time, the translated implication can map the current substitution to these variables. Finally, each rule body in the translation will include a call to the regreg predicate extended with an argument containing these shared variables, making it possible to transmit variable bindings at run-time. This is formalised in the next subsection.

3.4 Putting it all together

Satisfying the requirements set out above, we define rule registration as follows:

Definition 3.3 (Rule registration)

Rule registration is defined as: reg_rule(IR,[XS¯],IC,SC)assertz(reg(IR,[XS¯],SC.IC))reg\_rule(I^{R},[\overline{X^{S}}],I^{C},S^{C})\leftarrow assertz(reg(I^{R},[\overline{X^{S}}],S^{C}.I^{C})). \blacksquare

Then, the implementation of embedded implication solving, as introduced for the propositional case in Definition 2.5, is adapted as follows:

Definition 3.4 (Solving implication clause)

The solving implication clause for SLD resolution is defined as:
(IR,[XS¯],G,IC,SC)get_ci(IC)reg_rule(IR,[XS¯],IC,SC)call(G)\Rightarrow(I^{R},[\overline{X^{S}}],G,I^{C},S^{C})\leftarrow get\_ci(I^{C})\land reg\_rule(I^{R},[\overline{X^{S}}],I^{C},S^{C})\land call(G). \blacksquare

Considering what must be added to the translation (precompiling with registering, and variable sharing), rule and goal translation are defined as follows:

Definition 3.5 (Rule and goal translation)

Given a program Π\Pi, the rule translation of Rp(s¯)𝒬R\equiv p(\overline{s})\leftarrow\mathscr{Q} in Π\Pi, for the rule context identifier ϵ\epsilon and an empty list of variables, is the set of rules consisting of the rule:

  • p(s¯,[],IR,ϵ,SC)𝒬p(\overline{s},[~{}],I^{R},\epsilon,S^{C})\leftarrow\mathscr{Q}^{\prime} where IRI^{R} is a fresh rule identifier, SCS^{C} a variable that will be bound to a current context identifier, and 𝒬\mathscr{Q}^{\prime} is the goal translation of the possibly conjunctive goal 𝒬\mathscr{Q}.

  • and each rule HH^{\prime} resulting from each embedded implication in RR (as defined below).

The goal translation of a goal, 𝒬\mathscr{Q}, for a current context identifier SCS^{C}, is either:

  • qi(ti¯)q_{i}(\overline{t_{i}}) if 𝒬qi(ti¯)\mathscr{Q}\equiv q_{i}(\overline{t_{i}}) is a built-in call; or

  • qi(ti¯,L,I,C,SC)q_{i}(\overline{t_{i}},L,I,C,S^{C}) if 𝒬qi(ti¯)\mathscr{Q}\equiv q_{i}(\overline{t_{i}}) is a user predicate call, where LL , II and CC are new free variables representing any list of shared variables, any index and any context within the scope of the current context SCS^{C} respectively; or

  • 𝒬1𝒬2{\mathscr{Q}^{\prime}}_{1}\land{\mathscr{Q}^{\prime}}_{2} if 𝒬𝒬1𝒬2\mathscr{Q}\equiv{\mathscr{Q}}_{1}\land{\mathscr{Q}}_{2} is a conjunctive goal call, where 𝒬1{\mathscr{Q}^{\prime}}_{1} and 𝒬2{\mathscr{Q}^{\prime}}_{2} are respectively the goal translation of 𝒬1{\mathscr{Q}}_{1} and 𝒬2{\mathscr{Q}}_{2}; or

  • (IH,[XS],G,IC,SC)\Rightarrow(I^{H},[X^{\prime S}],G^{\prime},I^{C},S^{C}) if 𝒬(HG)\mathscr{Q}\equiv(H\Rightarrow G) is an embedded implication (i.e, HH is a rule and GG is an atom or an embedded implication), where IHI^{H} is a fresh rule identifier, [XS¯][\overline{X^{\prime S}}] is a list of shared variables between the assumptions in HH and the rest of the rule RR, ICI^{C} is a new free variable representing any index, SCS^{C} is the current context identifier:

    • GG^{\prime} is the goal translation of GG for a current context identifier SH=SC.ICS^{H}=S^{C}.I^{C}, and

    • HH^{\prime} is the rule translation of Hr(t¯)H\equiv r(\overline{t})\leftarrow\mathscr{B}, for the rule context identifier SH=SC.ICS^{H}=S^{C}.I^{C}, a current context identifier SCS^{C}, and a list of shared variables [XS¯][\overline{X^{\prime S}}], between the assumptions in HH and the rest of the rule RR:

      r(t¯,[XS¯],IH,SH,SC)reg(IH,[XS¯],CR)chk(CR,SC)r(\overline{t},[\overline{X^{\prime S}}],I^{H},S^{H},S^{C})\leftarrow reg(I^{H},[\overline{X^{\prime S}}],C^{R})\land chk(C^{R},S^{C})\land\mathscr{B}^{\prime}

      where IHI^{H} is a fresh rule identifier, regreg/3 is the predicate that stores each rule registration identified by IHI^{H} for its current context identifier CRC^{R} (cf. Definition 3.4), chk(CR,SC)chk(C^{R},S^{C}) checks whether CRSCC^{R}\preceq S^{C}, and \mathscr{B}^{\prime} is the goal translation of \mathscr{B}. As mentioned above, HH^{\prime} is added to the translated program. \blacksquare

Example 8

Consider once again the program in Example 3. Following Definition 3.5, the translation of the rule {Rp(X)g(X)(q(X)r)\{R\equiv p(X)\leftarrow g(X)\land(q(X)\Rightarrow r), for the rule context identifier ϵ\epsilon and no shared variables, is

p(X,[],1,ϵ,SC)g(X,L,I,C,SC)(0,[X],r(L,I,C,SC.IC),IC,SC),p(X,[~{}],1,\epsilon,S^{C})\leftarrow g(X,L,I,C,S^{C})\land\Rightarrow(0,[X],r(L^{\prime},I^{\prime},C^{\prime},S^{C}.I^{C}),I^{C},S^{C}),

because g(X,L,I,C,SC)g(X,L,I,C,S^{C}) is the translation of the goal g(X)g(X) for a current context identifier SCS^{C} and (0,[X],r(L,I,C,SC.IC),IC,SC)\Rightarrow(0,[X],r(L^{\prime},I^{\prime},C^{\prime},S^{C}.I^{C}),I^{C},S^{C}) is the goal translation of (HG)(q(X)r)(H\Rightarrow G)\equiv(q(X)\Rightarrow r) for SCS^{C}, where rule identifier IHI^{H} has been set to the fresh value 0, the list of variables shared between the assumptions in HH and the rest of the rule RR is [X][X], and r(L,I,C,SC.IC)r(L^{\prime},I^{\prime},C^{\prime},S^{C}.I^{C}) is the goal translation of GrG\equiv r for the current context identifier SH=SC.ICS^{H}=S^{C}.I^{C}.

Finally, rule Hq(X)trueH\equiv q(X)\leftarrow true, of the single embedded implication, is translated for the rule context identifier SHS^{H}, and is added as a new rule (identified by 0):

q(X,[X],0,SC.IC,SC)reg(0,[X],CR)chk(CR,SC)true.q(X,[X],0,S^{C}.I^{C},{S^{C}}^{\prime})\leftarrow reg(0,[X],C^{R})\land chk(C^{R},{S^{C}}^{\prime})\land true.

From Definition 3.5, it is easy to obtain the translation of the remaining rules.

Our actual implementation produces the following translated Prolog program for the source program Π\Pi:

p(A,[],1,[],B) :- g(A, _, _, _, B), (=>(0,[A], r(_, _, _, [C|B]),C, B)).
g(1,[],2,[],_).
r([],3,[],A) :- q(2, _, _, _, A).

q(A,[A],0,[_|_],C) :- reg(0, [A], B), chk(B, C).

It is noteworthy that the last translation fixes the problem mentioned in Example 6. \blacksquare

Considering SLDSLD(E×E)\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\subseteq(E\times E) as the transition relation for SLD resolution of a program Π\Pi, where the space state EE is a set of tuples G,θ,Π\langle G,\theta,\Pi\rangle (goal, substitution, program), the following can be stated:

Proposition 3.6

For a program Π\Pi and a goal 𝒬\leftarrow\mathscr{Q}, there exists (𝒬),id,ΠHSLDHSLD,σ,Π\langle(\leftarrow\mathscr{Q}),id,\Pi\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\sigma,\Pi\rangle iff 𝒬,id,Π\langle\leftarrow\mathscr{Q}^{\prime},id,\Pi^{\prime}\rangle SLDSLD,σ,Π′′\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,\sigma^{\prime},\Pi^{\prime\prime}\rangle, where σ=σ[𝒱ar(𝒬)]\sigma=\sigma^{\prime}[{\mathscr{V}}ar(\mathscr{Q})], Π\Pi^{\prime} is the translation of each rule in Π\Pi, 𝒬\mathscr{Q}^{\prime} is the goal translation of 𝒬\mathscr{Q}, and Π′′\Pi^{\prime\prime} is Π\Pi^{\prime} augmented with all the regreg/3 assertions from embedded implication solving. \blacksquare

Appendix A contains a performance analysis and Appendix B the proof of this proposition.

4 Applying hypothetical reasoning to Bousi\simProlog

Bousi\simProlog [Rubio-Manzano and Julián-Iranzo (2014), Julián-Iranzo and Rubio-Manzano (2017)] is an extension of Prolog and similarity-based logic programming [Fontana and Formato (1999), Fontana and Formato (2002), Loia et al. (2001), Sessa (2002)]. We have also developed FuzzyDES [Julián-Iranzo and Sáenz-Pérez (2017), Julián-Iranzo and Sáenz-Pérez (2018)] as an extension of a Datalog-based deductive database, embedding notions inherited from BPL. We then proposed an extension of FuzzyDES to include hypothetical reasoning [Julián-Iranzo and Sáenz-Pérez (2020)], which includes an operational semantics that can be adapted to the hypothetical extension of BPL (HBPL for short), as shown below.

4.1 Formal background

It is first convenient to review some concepts before extending BPL to include hypothetical reasoning.

BPL, among other features, incorporates a unification algorithm based on proximity relations. A proximity relation is a binary fuzzy relation :U×U[0,1]\mathscr{R}:U\times U\longrightarrow[0,1] on a universe UU satisfying, for any e,e1,e2,e3Ue,e_{1},e_{2},e_{3}\in U, the reflexive ((e,e)=1\mathscr{R}(e,e)=1) and symmetric ((e1,e2)=(e2,e1)\mathscr{R}(e_{1},e_{2})=\mathscr{R}(e_{2},e_{1}))) properties. If in addition it has the \triangle-transitive property ((e1,e3)(e1,e2)(e2,e3)\mathscr{R}(e_{1},e_{3})\geq\mathscr{R}(e_{1},e_{2})\mbox{\footnotesize$\triangle$}\mathscr{R}(e_{2},e_{3})), where the operator \triangle is an arbitrary t-norm, it is called a similarity relation. A proximity relation allows two symbols in a program to be weakly related. Given a binary fuzzy relation \mathscr{R} and a value λ\lambda, the λ\lambda-cut λ={x,y(x,y)λ}\mathscr{R}_{\lambda}=\{\langle x,y\rangle\mid\mathscr{R}(x,y)\geq\lambda\}. By abuse of language, the value λ\lambda is also called λ\lambda-cut (or cut value), which can be understood as a user-defined threshold intended to prune answers for a minimum degree of confidence.

A weak unification of terms builds upon the notion of weak unifier of level λ\lambda for two expressions 1\mathscr{E}_{1} and 2\mathscr{E}_{2} with respect to \mathscr{R} (or λ\lambda-unifier): a substitution θ\theta such that (1θ,2θ)λ\mathscr{R}(\mathscr{E}_{1}\theta,\mathscr{E}_{2}\theta)\geq\lambda, which is the unification degree of 1\mathscr{E}_{1} and 2\mathscr{E}_{2} with respect to θ\theta and \mathscr{R}. There are several weak unification algorithms [Julián-Iranzo and Sáenz-Pérez (2021)] based on this notion and on the proximity-based unification relation \Rightarrow, which defines a transition system (based on [Martelli and Montanari (1982)]). This relation, applied to a set of unification problems {ii|1in}\{\mathscr{E}_{i}\approx\mathscr{E}^{\prime}_{i}|1\leq i\leq n\} can yield either a successful or a failed sequence of transition steps. In the first case, both a successful substitution and a unification degree are obtained (detailed in, e.g., [Julián-Iranzo and Sáenz-Pérez (2021)]). The weak most general unifier (wmgu) θ\theta between two expressions, denoted by 𝗐𝗆𝗀𝗎λ(1,2){\sf\small wmgu}_{\mathscr{R}}^{\lambda}(\mathscr{E}_{1},\mathscr{E}_{2}), is defined as a λ\lambda-unifier of 1\mathscr{E}_{1} and 2\mathscr{E}_{2} such that there is no other λ\lambda-unifier σ\sigma which is more general than θ\theta. That is, there exists a substitution δ\delta such that, for any variable xx in 𝒟om(σ)𝒟om(θ){\mathscr{D}}om(\sigma)\cup{\mathscr{D}}om(\theta), (xσ,xθδ)λ\mathscr{R}(x\sigma,x\theta\delta)\geq\lambda. Although, unlike in the classical case, the wmgu is not unique, the weak unification algorithm computes a representative wmgu with approximation degree greater than or equal to any other wmgu.

4.2 Adapting WSLD resolution for hypothetical reasoning

To combine WSLD and hypothetical reasoning, it is necessary to augment the notion of computation state by adding to it the context of the computation (i.e., the current program).

Let EE be a set of tuples G,Π,θ,α\langle G,\Pi,\theta,\alpha\rangle (goal, program, substitution, approximation degree), each representing a state of a computation. Let HWSLDHWSLD(E×E)\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HWSLD}}}}\subseteq(E\times E) be the transition relation as defined below in Definition 4.1. A successful inference sequence for a given state is a sequence ending in the state ,Π,θ,α\langle\square,\Pi,\theta^{\prime},\alpha^{\prime}\rangle for some substitution θ\theta^{\prime} and approximation degree α\alpha^{\prime}, where \square represents an empty clause.

Definition 4.1 (HWSLD resolution)

Hypothetical Weak SLD (HWSLD) resolution is defined as a transition system E,HWSLDHWSLD\langle E,\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HWSLD}}}}\rangle, whose transition relation HWSLDHWSLD\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HWSLD}}}} is the smallest relation satisfying:
Rule 1: if R(AQ);δ<<ΠR\equiv\langle(A\leftarrow Q);\delta\rangle<\!\!\!<{\Pi}, σ=𝗐𝗆𝗀𝗎λ(A,A)fail\sigma={\sf\small wmgu}_{\mathscr{R}}^{\lambda}(A,A^{\prime})\neq fail, λβ=(Aσ,Aσ)\lambda\leq\beta=\mathscr{R}(A\sigma,A^{\prime}\sigma), \mathscr{R} is as defined in Π\Pi, and (δβα)λ(\delta\mbox{\footnotesize$\triangle$}\beta\mbox{\footnotesize$\triangle$}\alpha)\geq\lambda: (AQ),Π,θ,αHWSLDHWSLD(QQ)σ,Π,θσ,δβα{\langle(\leftarrow\!\!A^{\prime}\!\wedge\!Q^{\prime}),\Pi,\theta,\alpha\rangle}\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HWSLD}}}}{\langle(\leftarrow\!\!Q\!\wedge\!Q^{\prime})\sigma,\Pi,\theta\sigma,\delta\mbox{\footnotesize$\triangle$}\beta\mbox{\footnotesize$\triangle$}\alpha\rangle} Rule 2: if (A),Π,θ,α\langle(\leftarrow A^{\prime}),\Pi^{\prime},\theta,\alpha\rangle HWSLDHWSLD,Π,σ,α\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HWSLD}}}}\langle\square,\Pi^{\prime},\sigma,\alpha^{\prime}\rangle is a successful inference sequence:
((RA)Q),Π,θ,αHWSLDHWSLD(Q)σ,Π,θσ,αα{\langle(\leftarrow\!\!(R\!\Rightarrow\!A^{\prime})\!\wedge\!Q),\Pi,\theta,\alpha\rangle}\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HWSLD}}}}{\langle(\leftarrow\!Q)\sigma,\Pi,\theta\sigma,\alpha\mbox{\footnotesize$\triangle$}\alpha^{\prime}\rangle}, where AA is an atomic formula, QQ and QQ^{\prime} are conjunctions of atomic formulas, Π={R}Π\Pi^{\prime}=\{R\}\cup\Pi, and R<<ΠR<\!\!\!<\Pi indicates that RR is a standardised apart rule. \blacksquare

4.3 Expanded rules: translating hypothetical programs

A fuzzy logic program Π\Pi is translated into a logic program by linearising heads, making the weak unification explicit, and explicitly computing the approximation degree. Essentially, given a graded rule p(tn¯)Q;δΠ\langle p(\overline{t_{n}})\leftarrow Q;\delta\rangle\in\Pi, for each (p,q)=α\mathscr{R}(p,q)=\alpha with αλ\alpha\geq\lambda, the following clause is generated:

q(xn¯)(δα)x1t1xntnQq(\overline{x_{n}})\leftarrow(\delta\mbox{\footnotesize$\triangle$}\alpha)\wedge x_{1}\approx t_{1}\wedge\dots\wedge x_{n}\approx t_{n}\wedge Q

where \approx is the weak unification operator, tit_{i} are terms, xix_{i} are variables, δ\delta is the grade of the rule (which may represent the user confidence level in the rule), and δα\delta\mbox{\footnotesize$\triangle$}\alpha abbreviates the goal δαλ\delta\mbox{\footnotesize$\triangle$}\alpha\geq\lambda. Note that, by reflexivity, (p,p)=1\mathscr{R}(p,p)=1 is always in \mathscr{R}.

An operational semantics can be defined for expanded programs by means of a transition system with a set EE of states (goal, program, substitution, degree), adding a new inference rule to the tackling of assumptions:

Definition 4.2 (Operational semantics for expanded programs)

The operational semantics for expanded programs is a transition system E,EXPEXP\langle E,\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}}\rangle and whose transition relation EXPEXP\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}} is the smallest relation satisfying:
Rule 1: if β(0,1]\beta\in(0,1], and (βα)λ(\beta\mbox{\footnotesize$\triangle$}\alpha)\geq\lambda: (β¯Q),Π,θ,αEXPEXP(Q),Π,θ,βα\langle(\leftarrow\underline{\beta}\wedge Q^{\prime}),\Pi,\theta,\alpha\rangle\>\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}}\>\langle(\leftarrow Q^{\prime}),\Pi,\theta,\beta\mbox{\footnotesize$\triangle$}\alpha\rangle
Rule 2: if σ=𝗐𝗆𝗀𝗎λ(A,B)fail\sigma={\sf\small wmgu}_{\mathscr{R}}^{\lambda}(A,B)\neq fail, λβ=(Aσ,Bσ)\lambda\leq\beta=\mathscr{R}(A\sigma,B\sigma), \mathscr{R} is as defined in Π\Pi, and (βα)λ(\beta\mbox{\footnotesize$\triangle$}\alpha)\geq\lambda: (AB¯Q),Π,θ,αEXPEXP(Qσ),Π,θσ,βα\langle(\leftarrow\underline{A\approx B}\wedge Q^{\prime}),\Pi,\theta,\alpha\rangle\>\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}}\>\langle(\leftarrow Q^{\prime}\sigma),\Pi,\theta\sigma,\beta\mbox{\footnotesize$\triangle$}\alpha\rangle
Rule 3: if (p(xn¯)βx1t1xntnQ)<<Π(p(\overline{x_{n}})\leftarrow\beta\wedge x_{1}\approx t_{1}\wedge\dots\wedge x_{n}\approx t_{n}\wedge Q)<\!\!\!<{\Pi}: (p(sn¯)¯Q),Π,θ,αEXPEXP(βs1t1sntnQQ),Π,θ,α\langle(\leftarrow\underline{p(\overline{s_{n}})}\wedge Q^{\prime}),\Pi,\theta,\alpha\rangle\>\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}}\>\langle(\leftarrow\!\beta\!\wedge\!s_{1}\!\approx\!t_{1}\!\wedge\dots\wedge\!s_{n}\!\approx\!t_{n}\!\wedge\!Q\!\wedge\!Q^{\prime}),\Pi,\theta,\alpha\rangle
Rule 4: if (p(sn¯)),Π,,1EXPEXP,Π,σ,β\langle(\leftarrow p(\overline{s_{n}})),\Pi^{\prime},\emptyset,1\rangle\>\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}}\>\langle\square,\Pi^{\prime},\sigma,\beta\rangle, with Π={R}Π\Pi^{\prime}=\{R\}\cup\Pi, is a successful inference sequence: (Rp(sn¯)¯Q),Π,θ,αEXPEXP(Qσ),Π,θσ,βα\langle(\leftarrow\!\!\underline{R\!\!\Rightarrow\!\!p(\overline{s_{n}})}\!\wedge\!Q^{\prime}),\!\Pi,\!\theta,\!\alpha\rangle\!\>\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}}\>\!\langle(\leftarrow Q^{\prime}\sigma),\!\Pi,\!\theta\sigma,\!\beta\mbox{\footnotesize$\triangle$}\alpha\rangle{\scriptstyle} \blacksquare

In this system, transition steps are applied to underlined fragments.

Proposition 4.3

Given a program Π\Pi, with a proximity relation \mathscr{R}, and its expanded program Π\Pi^{\prime}, there exists a derivation Q,Π,θ,αHWSLDHWSLDQ,Π,θ,α\langle\leftarrow\!\!Q,\Pi,\theta,\alpha\rangle\>\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HWSLD}}}}\>\langle\leftarrow Q^{\prime},\Pi,\theta^{\prime},\alpha^{\prime}\rangle iff there exists a derivation Q,Π,θ,α\langle\leftarrow\!\!Q,\Pi^{\prime},\theta,\alpha\rangle EXPEXPQ,Π,θ,α\>\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny EXP}}}}\>\langle\leftarrow Q^{\prime},\Pi^{\prime},\theta^{\prime},\alpha^{\prime}\rangle which computes the same state. \blacksquare

The proof of this proposition follows a similar structure to the one for Proposition 3.6.

4.4 Implementing the expansion of programs

The generic implementation of expanded rules, including embedded implications, is done by applying the approach presented in Section 3.4 to the translation of expanded rules in Bousi\simProlog. Thus, instead of working with a program Π\Pi, the following definition refers to program contexts with identifiers SS and lists of shared variables [XS¯][\overline{X^{S}}].

Definition 4.4 (Translation of expanded rules and goals)

Let Π\Pi be a BPL program, \mathscr{R} a proximity relation on the syntactic domain generated by Π\Pi, \triangle the fixed t-norm associated with \mathscr{R}, and λ[0,1]\lambda\in[0,1] a cut value. Let Rp(s¯)1ikqi,δR\equiv\langle p(\overline{s})\leftarrow\land_{1\leq i\leq k}q^{\prime}_{i},\delta\rangle be a graded rule in Π\Pi. The rule translation of RR for a rule context identifier ϵ\epsilon, a current context identifier SCS^{C} and an empty list of shared variables is a set of expanded rules consisting of:

  • for each (p,q)=β\mathscr{R}(p,q)=\beta\in\mathscr{R}, generate the rule:

    q(X¯,[],IR,SR,SC,α)over_λ(β)unify( [(X1,s1,α1),,(Xn,sn,αn)])1ikqidegree_comp([δ,β,α1,,αn,α1,,αk],α)\begin{array}[]{ll}q(\overline{X},[],I^{R},S^{R},S^{C},\alpha)\leftarrow&over\_\lambda(\beta)\land unify($ $[(X_{1},s_{1},\alpha_{1}),\ldots,(X_{n},s_{n},\alpha_{n})])\land_{1\leq i\leq k}q^{\prime}_{i}\\ {}&\land\ degree\_comp([\delta,\beta,\alpha_{1},\ldots,\alpha_{n},\alpha^{\prime}_{1},\ldots,\alpha^{\prime}_{k}],\alpha)\end{array}
  • and each rule HH^{\prime} with rule context identifier SHS^{H} resulting from each embedded implication in RR (as defined next),

where IRI^{R} is a fresh rule identifier, over_λ(β)over\_\lambda(\beta) checks whether βλ\beta\geq\lambda (i.e., whether the rule can be applied because β\beta is over the λ\lambda-cut), unifyunify/1 computes the unification degrees of the pairs formed by the arguments passed to the variables X¯\overline{X} and the terms s¯\overline{s}, degree_compdegree\_comp/2 compounds the intermediate degrees to obtain the final degree α\alpha, and qiq^{\prime}_{i} is the goal translation of qi(ti¯)q_{i}(\overline{t_{i}}) for a current context identifier SCS^{C}.

The goal translation qiq^{\prime}_{i} of qi(ti¯)q_{i}(\overline{t_{i}}) for SCS^{C} is either:

  • qi(ti¯)q_{i}(\overline{t_{i}}) for a built-in call; or

  • qi(ti¯,L,I,C,SC,αi)q_{i}(\overline{t_{i}},L,I,C,S^{C},\alpha^{\prime}_{i}) for a user-predicate call qi(ti¯)q_{i}(\overline{t_{i}}), where LL, II, and CC are respectively new free variables representing any list of shared variables, any index, and any context within the scope of SCS^{C}, and αi\alpha^{\prime}_{i} is an approximation degree; or

  • (IH,[XS¯],G,IC,SC)\Rightarrow(I^{H},[\overline{X^{\prime S}}],G^{\prime},I^{C},S^{C}) for an embedded implication HGH\Rightarrow G, where IHI^{H} is a fresh rule identifier, [XS¯][\overline{X^{\prime S}}] is a list of shared variables between the assumptions in HH and the rest of the rule RR, ICI^{C} is a new free variable representing any index, and SCS^{C} is the current context identifier:

    • GG^{\prime} is the goal translation of GG, with degree αi\alpha^{\prime}_{i}, for the current context identifier SH=SC.ICS^{H}=S^{C}.I^{C}.

    • Also the rule translation of HH for the rule context identifier SH=SC.ICS^{H}=S^{C}.I^{C}, a current context identifier SCS^{C} and the list [XS¯][\overline{X^{\prime S}}] of shared variables, is generated:

      Let Hr(s¯)1ilui(ti¯),ξH\equiv\langle r(\overline{s})\leftarrow\land_{1\leq i\leq l}u_{i}(\overline{t_{i}}),\xi\rangle, then the translation of HH is a set of expanded rules such that for each (r,r)=γ\mathscr{R}(r,r^{\prime})=\gamma, the rule H’ is generated as:

      r(X¯,[XS¯],IR,SR,SC,α)over_λ(ξ)reg(IR,[XS¯],CR)chk(SR,SC)unify([(X1,s1,α1),,(Xn,sn,αn)])1iluidegree_comp([ξ,γ,α1,,αn,α1,,αl],α)\begin{array}[]{ll}r^{\prime}(\overline{X},[\overline{X^{S}}],I^{R},S^{R},S^{C},\alpha)\leftarrow&over\_\lambda(\xi)\land reg(I^{R},[\overline{X^{S}}],C^{R})\land chk(S^{R},S^{C})\\ {}&\land\ unify([(X_{1},s_{1},\alpha_{1}),\ldots,(X_{n},s_{n},\alpha_{n})])\land_{1\leq i\leq l}u^{\prime}_{i}\\ {}&\land\ degree\_comp([\xi,\gamma,\alpha_{1},\ldots,\alpha_{n},\alpha^{\prime}_{1},\ldots,\alpha^{\prime}_{l}],\alpha)\end{array}

      where regreg/3 is the predicate that stores each rule registration identified by IRI^{R} for its current context identifier CRC^{R} (cf. Definition 3.3), chk(SR,SC)chk(S^{R},S^{C}) checks whether SRSCS^{R}\preceq S^{C}, and sis^{\prime}_{i} is the goal translation of si(ti¯)s_{i}(\overline{t_{i}}) for a current context identifier SCS^{C}. \blacksquare

Example 9

Given the Bousi\simProlog program Π={R1:p(X)g(X)(q(X)r),0.8,R2:g(1),0.7,\Pi=\{R_{1}:\langle p(X)\leftarrow g(X)\land(q(X)\Rightarrow r),0.8\rangle,~{}~{}R_{2}:\langle g(1),0.7\rangle, R3:rq(2),0.9}R_{3}:\langle r\leftarrow q(2),0.9\rangle\}, a proximity relation \mathscr{R}, with an entry (p,s)=0.6\mathscr{R}(p,s)=0.6, and λ=0.5\lambda=0.5, following Definition 4.4, the translation of R1R_{1} for the rule context identifier ϵ\epsilon and no shared variables, generates the following set of rules:

  • For the entry (p,p)=1\mathscr{R}(p,p)=1,

    p(X1,[],1,ϵ,SC,D)over_λ(1)unify([X1,X,D1])g(X,L,I,C,SC,D1)(0,[X],r(L,I,C,SC.IC,D1),IC,SC)degree_comp([0.8,1,D1,D1],D)\begin{array}[]{l}p(X_{1},[~{}],1,\epsilon,S^{C},D)\leftarrow over\_\lambda(1)\land unify([X_{1},X,D_{1}])\land g(X,L,I,C,S^{C},D_{1})\\ ~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}\land\Rightarrow(0,[X],r(L^{\prime},I^{\prime},C^{\prime},S^{C}.I^{C},D^{\prime}_{1}),I^{C},S^{C})\land degree\_comp([0.8,1,D_{1},D^{\prime}_{1}],D)\end{array}

    because g(X,L,I,C,SC,D1)g(X,L,I,C,S^{C},D_{1}) is the translation of the goal g(X)g(X) for a current context identifier SCS^{C} and (0,[X],r(L,I,C,SC.IC,D1),IC,SC)\Rightarrow(0,[X],r(L^{\prime},I^{\prime},C^{\prime},S^{C}.I^{C},D^{\prime}_{1}),I^{C},S^{C}) is the goal translation of (HG)(q(X)r)(H\Rightarrow G)\equiv(q(X)\Rightarrow r) for SCS^{C}, where rule identifier IHI^{H} has been selected to the fresh value 0, the list of shared variables between the assumptions in HH and the rest of the rule RR is [X][X], and r(L,I,C,SC.IC,D1)r(L^{\prime},I^{\prime},C^{\prime},S^{C}.I^{C},D^{\prime}_{1}) is the goal translation of GrG\equiv r for the current context identifier SH=SC.ICS^{H}=S^{C}.I^{C}.

  • For the entry (p,s)=0.6\mathscr{R}(p,s)=0.6, in a similar way,

    s(X1,[],2,ϵ,SC,D)over_λ(0.6)unify([X1,X,D1])g(X,L,I,C,SC,D1)(0,[X],r(L,I,C,SC.IC,D1),IC,SC)degree_comp([0.8,0.6,D1,D1],D)\begin{array}[]{l}s(X_{1},[~{}],2,\epsilon,S^{C},D)\leftarrow over\_\lambda(0.6)\land unify([X_{1},X,D_{1}])\land g(X,L,I,C,S^{C},D_{1})\\ ~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}\land\Rightarrow(0,[X],r(L^{\prime},I^{\prime},C^{\prime},S^{C}.I^{C},D^{\prime}_{1}),I^{C},S^{C})\land degree\_comp([0.8,0.6,D_{1},D^{\prime}_{1}],D)\end{array}
  • Finally, the rule Hq(X)true,1H\equiv\langle q(X)\leftarrow true,1\rangle of the single embedded implication is translated for the rule context identifier SHS^{H} and is added as a new rule (identified by 0):

    q(X,[X],0,SC.IC,SC,D)over_λ(1)reg(0,[X],CR)chk(CR,SC)unify([X1,X,D1])truedegree_comp([1,1,D1],D).\begin{array}[]{l}q(X,[X],0,S^{C}.I^{C},{S^{C}}^{\prime},D)\leftarrow over\_\lambda(1)\land reg(0,[X],C^{R})\land chk(C^{R},{S^{C}}^{\prime})\land unify([X_{1},X,D_{1}])\\ ~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}~{}\land true\land degree\_comp([1,1,D_{1}],D).$$\end{array}

From Definition 4.4, it is easy to obtain the translation of the remaining rules:

  • For R2R_{2} and the single case in which (g,g)=1\mathscr{R}(g,g)=1, g(X1,[],3,ϵ,SC,D)over_λ(1)unify(g(X_{1},[],3,\epsilon,S^{C},D)\leftarrow over\_\lambda(1)\land unify( [X1,1,D1])degree_comp([0.7,1,D1],D)[X_{1},1,D_{1}])\land degree\_comp([0.7,1,D_{1}],D)

  • For R3R_{3} and the case (r,r)=1\mathscr{R}(r,r)=1, r([],4,ϵ,SC,D)over_λ(1)q(2,L,I,C,SC,D).r([],4,\epsilon,S^{C},D)\leftarrow over\_\lambda(1)\land q(2,L,I,C,S^{C},D). \blacksquare

For this generic definition, several optimisations are amenable, such as tail-recursion preservation, and deep indexing by linearising only the required head arguments.

5 Conclusions and Future Work

This paper has explored the inclusion of hypothetical reasoning in the fuzzy logic language and system Bousi\simProlog. We have proposed an operational semantics for hypothetical fuzzy logic programs, and an efficient implementation skeleton, which has been assessed in terms of a performance analysis (cf. Appendix A) of the proposed technique based on program contexts and precompilation of assumptions. This analysis confirms the performance benefits in most cases, but it depends on the host Prolog system: indeed, SICStus Prolog performs better and typically makes the compiled approach behave better than the meta-interpreted one. In addition, soundness and completeness of the translation are backed by formal results.

However, incorporation of the approach presented in this paper into the actual system BPL remains to be done, and thanks to the performance analysis presented in the appendix, we are confident that the final implementation will benefit from such an approach. Another extension would be to embody negative assumptions, for which an appropriate declarative semantics must be developed before thinking about an operational one. One may also think of inheriting both positive and negative assumptions of proximity equations, but this is a much more delicate matter performance-wise, because changing relation \mathscr{R} changes the compilation of the program. An incremental compilation could perhaps be devised, which would seem to be an appropriate way of tackling this question.

References

  • Bench-Capon and Prakken (2010) Bench-Capon, T. J. M. and Prakken, H. 2010. Using argument schemes for hypothetical reasoning in law. Artif. Intell. Law 18, 2, 153–174.
  • Bonner (1988) Bonner, A. J. 1988. A logic for hypothetical reasoning. In Proceedings of the 7th National Conference on Artificial Intelligence, St. Paul, MN, USA, August 21-26, 1988. AAAI Press / The MIT Press, 480–484.
  • Bonner (1990) Bonner, A. J. 1990. Hypothetical datalog: Complexity and expressibility. Theor. Comput. Sci. 76, 1, 3–51.
  • Bonner (1994) Bonner, A. J. 1994. Hypothetical reasoning with intuitionistic logic. Non-Standard Queries and Answers, Studies on Logic and Computation, 187–219.
  • Bonner (1997) Bonner, A. J. 1997. A logical semantics for hypothetical rulebases with deletion. J. Log. Program. 32, 2, 119–170.
  • Bosse and Gerritsen (2009) Bosse, T. and Gerritsen, C. 2009. A model for criminal decision making based on hypothetical reasoning about the future. In IEA/AIE 2009, Taiwan, June 24-27. LNCS, vol. 5579. Springer, 24–35.
  • Bourdeau (2014) Bourdeau, M. 2014. La théorie positive des hypothéses (in french). In In Proc of the Conf. on Hypothetical Reasoning. University of Tübingen, 23–29.
  • Bourdeau (2020) Bourdeau, M. 2020. Auguste Comte. In The Stanford Encyclopedia of Philosophy, E. N. Zalta, Ed. Metaphysics Research Lab, Stanford University.
  • Calantone et al. (2017) Calantone, R., Whipple, J. M., Wang, J. F., Sardashti, H., and Miller, J. W. 2017. A primer on moderated mediation analysis: Exploring logistics involvement in new product development. Journal of Business Logistics 38, 3, 151–169.
  • Cuijpers (2013) Cuijpers, P. J. L. 2013. Prefix orders as a general model of dynamics. In 9th International Workshop on Developments in Computational Models (DCM 2013). Universidad de Buenos Aires, 25–29.
  • Douven (2021) Douven, I. 2021. Abduction. In The Stanford Encyclopedia of Philosophy, E. N. Zalta, Ed. Metaphysics Research Lab, Stanford University.
  • Fontana and Formato (1999) Fontana, F. A. and Formato, F. 1999. Likelog: A logic programming language for flexible data retrieval. In Proceedings of the 1999 ACM Symposium on Applied Computing (SAC’99). 260–267.
  • Fontana and Formato (2002) Fontana, F. A. and Formato, F. 2002. A similarity-based resolution rule. Int. J. Intell. Syst. 17, 9, 853–872.
  • Gabbay (1985) Gabbay, D. M. 1985. N-PROLOG: An extension of PROLOG with hypothetical implication II - logical foundations, and negation as failure. J. Log. Program. 2, 4, 251–283.
  • Gabbay and Reyle (1984) Gabbay, D. M. and Reyle, U. 1984. N-PROLOG: An extension of PROLOG with hypothetical implications I. J. Log. Program. 1, 4, 319–355.
  • Galindo (2005) Galindo, J. 2005. New characteristics in FSQL, a fuzzy SQL for fuzzy databases. WSEAS Transactions on Information Science and Applications 2, 2, 161–169.
  • Julián-Iranzo and Rubio-Manzano (2017) Julián-Iranzo, P. and Rubio-Manzano, C. 2017. A sound and complete semantics for a similarity-based logic programming language. Fuzzy Sets and Systems, 1–26.
  • Julián-Iranzo and Sáenz-Pérez (2017) Julián-Iranzo, P. and Sáenz-Pérez, F. 2017. FuzzyDES or how DES met Bousi\simProlog. In International Conference on Fuzzy Systems (FUZZ-IEEE), Naples, Italy, July 9-12. 1–6.
  • Julián-Iranzo and Sáenz-Pérez (2018) Julián-Iranzo, P. and Sáenz-Pérez, F. 2018. A Fuzzy Datalog Deductive Database System. IEEE Transactions on Fuzzy Systems 26, 5, 2634–2648.
  • Julián-Iranzo and Sáenz-Pérez (2020) Julián-Iranzo, P. and Sáenz-Pérez, F. 2020. A System implementing Fuzzy Hypothetical Datalog. In International Conference on Fuzzy Systems (FUZZ-IEEE), UK, July 19-24. 1–8.
  • Julián-Iranzo and Sáenz-Pérez (2021) Julián-Iranzo, P. and Sáenz-Pérez, F. 2021. Proximity-based Unification: an Efficient Implementation Method. IEEE Transactions on Fuzzy Systems 29, 5, 1238–1251.
  • Kunhimangalam et al. (2013) Kunhimangalam, R., Ovallath, S., and Joseph, P. K. 2013. A novel fuzzy expert system for the identification of severity of carpal tunnel syndrome. BioMed Research International 2013.
  • Loia et al. (2001) Loia, V., Senatore, S., and Sessa, M. I. 2001. Similarity-based SLD resolution and its implementation in an extended Prolog system. In International Conference on Fuzzy Systems (FUZZ-IEEE). 650–653.
  • Lopez and Pimentel (1999) Lopez, P. and Pimentel, E. 1999. Hypothetical reasoning with substructural logics. In Proc. of Joint Conference on Declarative Programming. L’Aquila (Italia). 485–496.
  • Martelli and Montanari (1982) Martelli, A. and Montanari, U. 1982. An Efficient Unification Algorithm. ACM Transactions on Programming Languages and Systems 4, 258–282.
  • McCarty (1988a) McCarty, L. T. 1988a. Clausal intuitionistic logic I - fixed-point semantics. J. Log. Program. 5, 1, 1–31.
  • McCarty (1988b) McCarty, L. T. 1988b. Clausal intuitionistic logic II - tableau proof procedures. J. Log. Program. 5, 2, 93–132.
  • Miller et al. (1991) Miller, D., Nadathur, G., Pfenning, F., and Scedrov, A. 1991. Uniform proofs as a foundation for logic programming. Ann. Pure Appl. Log. 51, 1-2, 125–157.
  • Minutolo et al. (2016) Minutolo, A., Esposito, M., and Pietro, G. D. 2016. A hypothetical reasoning system for mobile health and wellness applications. In MobiHealth 2016. Lecture Notes of the Institute for Computer Sciences, Social Informatics and Telecommunications Engineering, vol. 192. Springer, 278–286.
  • Moreno and Vázquez (2014) Moreno, G. and Vázquez, A. 2014. A survey on community detection methods in social networks. Journal of Software Engineering and Applications 7, 273–298.
  • Rizzi (2009) Rizzi, S. 2009. What-If Analysis. Springer US, Boston, MA, 3525–3529.
  • Rubio-Manzano and Julián-Iranzo (2014) Rubio-Manzano, C. and Julián-Iranzo, P. 2014. Fuzzy Linguistic Prolog and its Applications. Journal of Intelligent and Fuzzy Systems 26, 1503–1516.
  • Sessa (2002) Sessa, M. I. 2002. Approximate reasoning by similarity-based SLD resolution. Theoretical Computer Science 275, 1-2, 389–426.
  • Wielemaker et al. (2012) Wielemaker, J., Schrijvers, T., Triska, M., and Lager, T. 2012. SWI-Prolog. Theory and Practice of Logic Programming 12, 1-2, 67–96.
  • Wilson and Nuzzolo (2008) Wilson, N. H. M. and Nuzzolo, A. 2008. Schedule-Based Modeling of Transportation Networks: Theory and applications Portada.

Appendix A Performance comparison: meta-interpreted vs. interpreted

This section analyses the performance of the different solving alternatives explained above: the meta-interpreter and the compiler-based solver interpreter. They are also compared, when applicable, to the native implementation and the solving in SWI-Prolog of the program under test. Two alternatives are first described for the meta-interpreter, and then the performance analysis is given, comparing them to the compiled approach in Section 3. The Prolog interpreter for non-hypothetical programs is also included in the comparison as a reference for the overhead caused by the compiled approach.

A.1 Hypothetical Meta-interpreters

Figure 1 illustrates the hypothetical propositional meta-interpreter, which has been enlarged to deal with disjunctive rules and built-in calls, where a fact is a rule with a truetrue body. The predicate builtinbuiltin/1 checks whether its argument represents a call to a built-in predicate (different from \land, \lor and \Rightarrow).

solve((ϕ1ϕ2),Π)solve(ϕ1,Π)solve(ϕ2,Π).solve((\phi_{1}\land\phi_{2}),\Pi)\leftarrow solve(\phi_{1},\Pi)\land solve(\phi_{2},\Pi).
solve((ϕ1ϕ2),Π)solve(ϕ1,Π)solve(ϕ2,Π).solve((\phi_{1}\lor\phi_{2}),\Pi)\leftarrow solve(\phi_{1},\Pi)\lor solve(\phi_{2},\Pi).
solve(ϕ,Π)builtin(ϕ)call(ϕ).solve(\phi,\Pi)\leftarrow builtin(\phi)\land call(\phi).
solve((Rϕ),Π)solve(ϕ,[R|Π]).solve((R\Rightarrow\phi),\Pi)\leftarrow solve(\phi,[R|\Pi]).
solve(ϕ,Π)member((ϕϕ),Π)solve(ϕ,Π).solve(\phi,\Pi)\leftarrow member((\phi\leftarrow\phi^{\prime}),\Pi)\land solve(\phi^{\prime},\Pi).
Figure 1: Meta-interpreter for hypothetical propositional logic programs

The meta-interpreter for hypothetical propositional logic programs depicted in Figure 1 is not applicable to predicate logic programs. For example, the goal p\leftarrow p for the program {pq(1)q(2),q(X)p\leftarrow q(1)\land q(2),q(X)} should succeed, but it does not because solving q(1)\leftarrow q(1) creates the substitution {X/1X/1}, which is not compatible with the second call q(2)\leftarrow q(2). Nonetheless, it can be easily adapted to the non-propositional case by modifying the last clause to:

solve(ϕ,Π)copy_term(Π,Π)member((ϕϕ),Π)solve(ϕ,Π).solve(\phi,\Pi)\leftarrow copy\_term(\Pi,\Pi^{\prime})\land member((\phi\leftarrow\phi^{\prime}),\Pi^{\prime})\land solve(\phi^{\prime},\Pi).

However, copying the entire program each time the unification of a rule or fact with the goal is sought, is hugely resource consuming. A more convenient approach is to look for a matching clause and copy only this clause, as follows:

solve(ϕ,Π)unif_member((ϕ_),Π,R)copy_term(R,(ϕϕ′′))ϕ=ϕsolve(ϕ′′,Π).solve(\phi,\Pi)\leftarrow unif\_member((\phi\leftarrow\_),\Pi,R)\land copy\_term(R,(\phi^{\prime}\leftarrow\phi^{\prime\prime}))\land\phi=\phi^{\prime}\land solve(\phi^{\prime\prime},\Pi).

where unif_member(X,L,Y)unif\_member(X,L,Y) stands for: YY is a member of LL that is unifiable with XX.

This can be slightly enhanced by using an ordered list for the program predicates (though preserving rule user ordering in each predicate), therefore reducing the serial access time complexity by a factor of 2, on average. Also, adding cuts for selecting the appropriate meta-interpreter clause will prune choice points in advance, and will also save some tests. Thus, an actual implementation in Prolog could be:

solve((Goal1, Goal2), Program) :-
  !, solve(Goal1, Program), solve(Goal2, Program).
solve((Goal1; Goal2), Program) :-
  !, (solve(Goal1, Program) ; solve(Goal2, Program)).
solve((Hyp => Goal), Program) :-
  !, insert_rule(Hyp, Program, NProgram), solve(Goal, NProgram).
solve(Goal, _Program) :-
  builtin(Goal), !, Goal.
solve(Goal, Program) :-
  unif_member((Goal :- _Body), Program, (UGoal :- UBody)),
  copy_term((UGoal :- UBody), (CGoal :- CBody)),
  CGoal=Goal, solve(CBody, Program).

Note that, in particular, the last clause will not be selected uselessly, as opposed to the skeleton shown in Figure 1. The predicate insert_rule/3 inserts a rule in the place corresponding to its ordering.

As suggested by an anonymous referee, there are more alternatives that may be considered. In particular, this meta-interpreter can be further enhanced by passing only assumed rules to solve/2, instead of the whole program. Then, the static user program can be accessed by the built-in predicate clause/2. Moreover, the assumed rules can be better represented by a tree, whose nodes are predicates (key of the tree), with their rules in a list, thereby improving access when many predicates are assumed. To implement this approach, the last clause of the former meta-interpreter is replaced by:

% Lookup in the consulted (static) program:
solve(Goal, Program) :-
  clause(Goal, Body), solve(Body, Program).
% Lookup in the augmented program:
solve(Goal, Program) :-
  functor(Goal, Functor, Arity), atomic_concat(Functor, Arity, Key),
  get_assoc(Key, Program, Rules),
  unif_member((Goal :- _Body), Rules, (UGoal :- UBody)),
  copy_term((UGoal :- UBody), (CGoal :- CBody)),
  CGoal=Goal, solve(CBody, Program).

Association lists are implemented with AVL trees, with 𝒪(logn)\mathscr{O}(\log{}n) worst-case (and expected) time operations, where nn denotes the number of elements in the association list [Wielemaker et al. (2012)]. This meta-interpreter uses get_assoc/3 in solve/2 to retrieve nodes in the tree and put_assoc/4 in insert_rule/3 (cf. its implementation in meta2.pl at the URL mentioned in the next subsection).

A.2 Performance Analysis

All experiments were run on an Intel Xeon CPU E3-1505M v5 with 4 physical cores at 2.8 GHz, 16GiB RAM, with the Windows 10 64-bit operating system. Benchmarks are run on the last stable version of SWI-Prolog 64-bit 8.2.4-1 at the time of writing this. Times in the Tables are given in seconds and are the result of averaging 10 runs (and discarding the first), and individual times were measured with the built-in predicate statistics/2. We have collected the time for the total run-time measurement (key cputime for SWI-Prolog), which returns the (user) CPU time, and the run-time (key runtime) which returns the total run-time, eliding the time for memory management (garbage collection) and system calls. Tables include the column CPUtime (for the total run-time), and Diftime (for the total run-time minus the run-time, primarily to reflect the cost of garbage collection). Garbage collection and stack trimming are carried out before each trial is run; then the time measurement can start. On completion of the trial, these operations are performed again before taking the elapsed time, in order to account for housekeeping tasks due to running the tests. Also, inferences is another measurement from the statistics predicate, which indicates the number of passes via the call and redo ports in order to execute a goal. All benchmarks and systems can be downloaded from http://www.fdi.ucm.es/profesor/fernan/iclp2021/Experiments.zip.

Several classical benchmark programs have been selected (they can be found at the SWI-Prolog  site), where some have been adapted to remove cuts. These programs are intended, firstly, to make clear the price to be paid for including hypothetical reasoning in the system; and, secondly, to compare meta-interpreted alternatives with respect to the compiled alternative. In any case, it should be recalled that a compiled approach is preferred for the implementation of a system such as BPL, because assuming a rule implies a recompilation. Furthermore, most of those programs have been adapted to build hypothetical versions by assuming either facts or a rule for the data generator. These versions add a preceding h before the classical test name. With respect to the factorial test program, facttr is the tail recursive version, and all benchmark sizes can be consulted at the URL above. As a stress test, several parametric hypothetical programs are included, to test embedded implications: The first (labelled as hypo1 in the following Tables): {pa1a2ana1a2anp\leftarrow a_{1}\Rightarrow a_{2}\Rightarrow\ldots\Rightarrow a_{n}\Rightarrow a_{1}\land a_{2}\land\ldots\land a_{n}} with a goal p\leftarrow p for n=2000n=2000; the second (hypo2): {p(0)a,p(N)N>0N1isN1(ap(N1))p(0)\leftarrow a,p(N)\leftarrow N>0\land N_{1}~{}is~{}N-1\land(a\Rightarrow p(N_{1}))} with a goal p(3000)\leftarrow p(3000) and requesting all solutions; and the third (hypo3): {paaap\leftarrow a\Rightarrow\ldots\Rightarrow a\Rightarrow a} with a goal p\leftarrow p for 30003000 assumptions, also requesting all solutions. The first program is intended to test the system by assuming a large batch of different predicates iteratively. The second recursively assumes facts of the same predicate and is intended to analyse the performance in the presence of backtracking by requesting all solutions. The third is similar to the second but iteratively adding those facts with nested assumptions.

Table A 1 collects the running measurements for classical tests and Table A 2 for hypothetical tests. Rows in the Table include the following labels: Meta1 for the first meta-interpreter as shown in this appendix, Meta2 for the second, improved, instance, Comp for the compiled approach as described in Definition 3.5, and Prolog for the native execution of (classical, non-hypothetical) tests in the Prolog system.

For classical tests (Table A 1) Meta2 performs better than Meta1 with significant speed-ups, and there is even a notable speed-up in the case of path, where recursively traversing the list of the program, including many arcs in the graph, takes a lot of effort that is avoided with Meta2, because the program is consulted. Looking now at the compiled alternatives Comp and Prolog, they perform better than the meta-interpreted versions. Comparing Comp to Prolog, they behave similarly in most cases other than in nrev and queens, where Prolog is faster (4.62×\times and 1.44×\times, respectively).

For hypothetical versions of classical tests (Table A 2, roughly similar conclusions can be drawn. Performance of Comp is almost always better than Meta2, and the latter is better than Meta1. Only in hpath is Meta2 faster by a small amount. Results can be different for other non-classical stress tests such as hypo1, for which Meta2 performs better. In this case, note that AVL trees play an important role in fast accessing of each rule (in hypo1 there is one assumed rule for each predicate, with a total of 2000). In turn, Comp takes more time, both in total time and memory management, even when the number of inferences is roughly a fifth compared to Meta1, but the time taken by memory management is noticeable compared to the other two alternatives. This system Comp performs better for hypo2 with a similar inference ratio with respect to Meta2. With respect to the last test hypo3, Meta2 is the slowest, while there is a small difference between Comp and the fastest, Meta1.

ata_switest_data_swi_classic.tex

Program System CPUtime Diftime Inferences
_data_swi
Table 1: Comparing Meta1, Meta2, Comp and Prolog for classical programs

ata_switest_data_swi_hypo.tex

Program System CPUtime Diftime Inferences
_data_swi
Table 2: Comparing Meta1, Meta2 and Comp for hypothetical programs

Appendix B Proof for Proposition 3.6

We divide the proof of Proposition 3.6 into two parts, starting with the proof of the statement “if there exists a derivation 𝒟((𝒬),id,ΠHSLDHSLD,σ,Π)\mathscr{D}\equiv(\langle(\leftarrow\mathscr{Q}),id,\Pi\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\sigma,\Pi\rangle) then there exists a derivation 𝒟(𝒬,id,ΠSLDSLD,σ,Π′′)\mathscr{D}^{\prime}\equiv(\langle\leftarrow\mathscr{Q}^{\prime},id,\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,\sigma^{\prime},\Pi^{\prime\prime}\rangle)”. This direction constitutes a kind of completeness result where we prove that derivations in the original program using the HSLD resolution rule can be reproduced by the SLD operational mechanism in the transformed program. In the second part, we prove the converse of the first statement, that is “there exists a derivation 𝒟:(𝒬),θ,ΠHSLDHSLD,σ,Π\mathscr{D}:\langle(\leftarrow\mathscr{Q}),\theta,\Pi\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\sigma,\Pi\rangle if there exists a derivation 𝒟:𝒬,θ,ΠSLDSLD,σ,Π′′\mathscr{D}^{\prime}:\langle\leftarrow\mathscr{Q}^{\prime},\theta,\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,\sigma^{\prime},\Pi^{\prime\prime}\rangle”, which guarantees that the present implementation does not compute answers which are not computed by the HSLD semantics, leading to a sort of soundness result.

B.1 Proof of Part I

Lemma B.1

Let Π\Pi be a program and 𝒢(A𝒬1){\cal G}\equiv(\leftarrow A\land\mathscr{Q}_{1}) a goal, if there exists the step 𝒮{\cal S}≡⟨(AQ_1), θ, Π _HSLD​​​   (Q_2σ), θσ, Π then there exists the following derivation in the translated program Π\Pi^{\prime}: (A’Q’_1), θ, Π’ _SLD​​​ +   (Q’_2(σδ)),θσδ,Π’Π_reg , where AA^{\prime}, 𝒬i\mathscr{Q}_{i}^{\prime} are the goal translations of AA, 𝒬i\mathscr{Q}_{i} respectively, and Πreg\Pi_{reg} is the set of all the regreg/3 assertions due to embedded implication solving. The domain of the substitution δ\delta shares variables with neither θ\theta nor σ\sigma, and θσ=θ(σδ)[𝒱ar(𝒢)]\theta\sigma=\theta(\sigma\cup\delta)[{\mathscr{V}}ar({\cal G})]. \blacksquare

Proof B.1.

We proceed by induction on the context identifier ss associated with the program context.

  1. 1.

    Base case(s=ϵs=\epsilon): In this case query AA must be an atom, that is, Ap(sn¯)A\equiv p(\overline{s_{n}}) and there must be a rule (p(tn¯))Π(p(\overline{t_{n}})\leftarrow\mathscr{B})\in\Pi for which σ=mgu({p(sn¯)=p(tn¯)})=mgu({sn=tn¯})\sigma=mgu(\{p(\overline{s_{n}})=p(\overline{t_{n}})\})=mgu(\{\overline{s_{n}=t_{n}}\}) (where si=tis_{i}=t_{i}, with 1in1\leq i\leq n, are unification problems) and step 𝒮{\cal S} is (⟨←p(¯s_n)Q_1, θ, Π _HSLD​​​   ⟨←(BQ_1)σ, θσ, Π )

    According to Definition 3.5, the rule translation of (p(tn¯))Π(p(\overline{t_{n}})\leftarrow\mathscr{B})\in\Pi is p(tn¯,[],0,ϵ,SC)p(\overline{t_{n}},[],0,\epsilon,S^{C})\leftarrow\mathscr{B}^{\prime} and the goal translation of p(sn¯)\leftarrow p(\overline{s_{n}}) is p(sn¯,L,I,C,S)\leftarrow p(\overline{s_{n}},L,I,C,S) where SCS^{C}, LL, II, CC and SS are fresh variables. It is then easy to verify that:

    mgu({p(sn¯,L,I,C,S)=p(tn¯,[],0,ϵ,SC)})=mgu({sn=tn¯,L=[],I=0,C=ϵ,S=SC})=σ{L/[],I/0,C/ϵ,S/SC}=σδ\begin{array}[]{l}mgu(\{p(\overline{s_{n}},L,I,C,S)=p(\overline{t_{n}},[],0,\epsilon,S^{C})\})\\ ~{}~{}~{}~{}~{}~{}=mgu(\{\overline{s_{n}=t_{n}},L=[],I=0,C=\epsilon,S=S^{C}\})\\ ~{}~{}~{}~{}~{}~{}=\sigma\{L/[],I/0,C/\epsilon,S/S^{C}\}=\sigma\cup\delta\end{array}

    where δ={L/[],I/0,C/ϵ,S/SC}\delta=\{L/[],I/0,C/\epsilon,S/S^{C}\}, and its domain does not share variables with σ\sigma. Hence, the following step is possible in the translated program Π\Pi^{\prime}: ⟨←p(¯s_n, L, I, C, ϵ)Q’_1, θ, Π’ _SLD​​​   ⟨←(BQ’_1)(σδ), θ(σδ), Π’ and θσ=θ(σδ)[𝒱ar(𝒢)]\theta\sigma=\theta(\sigma\cup\delta)[{\mathscr{V}}ar({\cal G})].

  2. 2.

    Inductive case (s>ϵs>\epsilon): The query A(HG)A\equiv(H\Rightarrow G), that is, an embedded implication (chain), and the step 𝒮{\cal S}≡⟨((H G)Q_1), θ, Π _HSLD​​​   (Q_1σ), θσ, Π Therefore, Rule 2 of Definition 3.1 was applied and the derivation D_1((G), id, Π_1 _HSLD​​​ *   ⟨□, σ,Π_1 ) must exist, where Π1=Π{H}\Pi_{1}=\Pi\cup\{H\} is a new program with context identifier 1>ϵ1>\epsilon. Then, by the Inductive hypothesis, the following derivation in the translated program Π\Pi^{\prime}: D’_1((G’), id, Π’ _SLD​​​ *   ⟨□, σδ,Π’Π_reg ) must exist, where GG^{\prime} is the goal translation of GG, Πreg\Pi_{reg} is the set of rule registrations and δ\delta is a substitution for which its domain shares variables with neither the original (not translated) goal GG nor the substitution σ\sigma.

    On the other hand, note that the translation of the goal (HG)(H\Rightarrow G) is (0,[X¯],G,IC,SC)\Rightarrow(0,[\overline{X}],G^{\prime},I^{C},S^{C}) plus the rule translation HH^{\prime} of HH.

    Now, using Definition 3.4 for solving embedded implication clauses and Definition 3.3 of rule registration, and the derivation 𝒟1\mathscr{D}^{\prime}_{1}, it is possible to build the following derivation 𝒟\mathscr{D}^{\prime}:

    ((0,[X¯],G,IC,SC)𝒬1),θ,ΠSLDSLD(get_ci(IC)reg_rule(0,[X¯],IC,SC)call(G)𝒬1),θ,ΠSLDSLD(reg_rule(0,[X¯],1,SC)call(G)𝒬1){IC/1},θ{IC/1},ΠSLDSLD(assertz(reg(0,[X¯],SC))call(G)𝒬1){IC/1},θ{IC/1},ΠSLDSLD(call(G)𝒬1){IC/1},θ{IC/1},Π{reg(0,[X¯],SC)}SLDSLD(G𝒬1){IC/1},θ{IC/1},Π{reg(0,[X¯],SC)}SLDSLDQ1(σ{IC/1}δ),(θσ){IC/1}δ,Π{reg(0,[X¯],SC)}Πreg\begin{array}[]{l}\langle\leftarrow(\Rightarrow(0,[\overline{X}],G^{\prime},I^{C},S^{C})\land\mathscr{Q}^{\prime}_{1}),\theta,\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(get\_ci(I^{C})\land reg\_rule(0,[\overline{X}],I^{C},S^{C})\land call(G^{\prime})\land\mathscr{Q}^{\prime}_{1}),\theta,\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(reg\_rule(0,[\overline{X}],1,S^{C})\land call(G^{\prime})\land\mathscr{Q}^{\prime}_{1})\{I^{C}/1\},\theta\cup\{I^{C}/1\},\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(assertz(reg(0,[\overline{X}],S^{C}))\land call(G^{\prime})\land\mathscr{Q}^{\prime}_{1})\{I^{C}/1\},\theta\cup\{I^{C}/1\},\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(call(G^{\prime})\land\mathscr{Q}^{\prime}_{1})\{I^{C}/1\},\theta\cup\{I^{C}/1\},\Pi^{\prime}\cup\{reg(0,[\overline{X}],S^{C})\}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(G^{\prime}\land\mathscr{Q}^{\prime}_{1})\{I^{C}/1\},\theta\cup\{I^{C}/1\},\Pi^{\prime}\cup\{reg(0,[\overline{X}],S^{C})\}\rangle\\ \stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow Q^{\prime}_{1}(\sigma\cup\{I^{C}/1\}\cup\delta),(\theta\sigma)\cup\{I^{C}/1\}\cup\delta,\Pi^{\prime}\cup\{reg(0,[\overline{X}],S^{C})\}\cup\Pi_{reg}\rangle\end{array}

    where the domain of {IC/1}δ\{I^{C}/1\}\cup\delta shares variables with neither θ\theta nor σ\sigma, and θσ=(θσ{IC/1}δ)[𝒱ar(𝒢)]\theta\sigma=(\theta\sigma\cup\{I^{C}/1\}\cup\delta)[{\mathscr{V}}ar({\cal G})].

Proposition B.2.

For a program Π\Pi and a goal 𝒬\leftarrow\mathscr{Q}, if there exists a derivation 𝒟(𝒬),id,ΠHSLDHSLD,σ,Π\mathscr{D}\equiv\langle(\leftarrow\mathscr{Q}),id,\Pi\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\sigma,\Pi\rangle then there exists a derivation 𝒟𝒬,id,ΠSLDSLD,σ,ΠΠreg\mathscr{D}^{\prime}\equiv\langle\leftarrow\mathscr{Q}^{\prime},id,\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,\sigma^{\prime},\Pi^{\prime}\cup\Pi_{reg}\rangle, where Π\Pi^{\prime} is the translation of each rule in Π\Pi, 𝒬\mathscr{Q}^{\prime} is the goal translation of 𝒬\mathscr{Q}, Πreg\Pi_{reg} is the set of rule registrations, that is, all the regreg/3 assertions due to embedded implication solving, and σ=σ[𝒱ar(𝒢)]\sigma=\sigma^{\prime}[{\mathscr{V}}ar({\cal G})]. \blacksquare

Proof B.3.

By induction on the length of the derivation 𝒟\mathscr{D} and Lemma B.1.

As mentioned above, Proposition B.2 constitutes a kind of completeness result. In the following we concentrate on the other direction, which leads to a sort of soundness result.

B.2 Proof of Part II

Proposition B.4.

Let Π\Pi^{\prime} be the translation of a program Π\Pi and 𝒢(𝒬1){\cal G}^{\prime}\equiv(\leftarrow\mathscr{Q}^{\prime}_{1}) the goal translation of a goal 𝒢(𝒬1){\cal G}\equiv(\leftarrow\mathscr{Q}_{1}), if there exists a derivation 𝒟𝒬,θδ,ΠSLDSLD,(θσ)δ,ΠΠreg\mathscr{D}^{\prime}\equiv\langle\leftarrow\mathscr{Q}^{\prime},\theta\cup\delta,\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,(\theta\sigma)\cup\delta^{\prime},\Pi^{\prime}\cup\Pi_{reg}\rangle, where Πreg\Pi_{reg} is the set of rule registrations, that is, all the regreg/3 assertions due to embedded implication solving, then there exists a derivation 𝒟(𝒬),θ,ΠHSLDHSLD,θσ,Π\mathscr{D}\equiv\langle(\leftarrow\mathscr{Q}),\theta,\Pi\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\theta\sigma,\Pi\rangle. The domains of the substitutions δ\delta and δ\delta^{\prime} share variables with neither θ\theta nor σ\sigma, and θσ=(θσ)δ[𝒱ar(𝒢)]\theta\sigma=(\theta\sigma)\cup\delta^{\prime}[{\mathscr{V}}ar({\cal G})]. \blacksquare

Proof B.5.

The proof proceeds by induction on the length of the derivation 𝒟\mathscr{D}^{\prime}. Without loss of generality, thanks to the independence of the computation rule in the SLD operational mechanism, several steps in the derivation 𝒟\mathscr{D}^{\prime} can be conveniently ordered. So, it is possible to group fragments of the derivation 𝒟\mathscr{D}^{\prime} in the translated program Π\Pi^{\prime}, which correspond with the steps in the derivation 𝒟\mathscr{D}, in the program Π\Pi.

  1. 1.

    Base case(n=1n=1): In this case the query 𝒬p(sn¯,[],I,C,ϵ)\mathscr{Q}^{\prime}\equiv p(\overline{s_{n}},[],I,C,\epsilon) (translation of 𝒬p(sn¯)\mathscr{Q}\equiv p(\overline{s_{n}}), since an initially launched goal is solved in the initial context ϵ\epsilon and its list of shared variables is empty) and there must be a rule p(tn¯,[],i,ϵ,SC)p(\overline{t_{n}},[],i,\epsilon,S^{C}), with rule index ii (translation of the fact p(tn¯)Πp(\overline{t_{n}})\in\Pi), for which

    mgu({p(sn¯,[],I,C,ϵ)=p(tn¯,[],i,ϵ,SC)})=mgu({sn=tn¯,[]=[],I=i,C=ϵ,ϵ=SC})=σ{I/i,C/ϵ,SC/ϵ}=σδ1\begin{array}[]{l}mgu(\{p(\overline{s_{n}},[],I,C,\epsilon)=p(\overline{t_{n}},[],i,\epsilon,S^{C})\})\\ ~{}~{}~{}~{}~{}~{}=mgu(\{\overline{s_{n}=t_{n}},[]=[],I=i,C=\epsilon,\epsilon=S^{C}\})\\ ~{}~{}~{}~{}~{}~{}=\sigma\{I/i,C/\epsilon,S^{C}/\epsilon\}=\sigma\cup\delta_{1}\end{array}

    where mgu({sn=tn¯})=σmgu(\{\overline{s_{n}=t_{n}}\})=\sigma must be solvable, δ1={I/i,C/ϵ,SC/ϵ}\delta_{1}=\{I/i,C/\epsilon,S^{C}/\epsilon\}, and its domain shares variables with neither θ\theta nor σ\sigma. Therefore, the following one-step derivation 𝒟\mathscr{D} is possible in the program Π\Pi: p(sn¯),θ,ΠHSLDHSLD,θσ,Π\langle\leftarrow p(\overline{s_{n}}),\theta,\Pi\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\theta\sigma,\Pi\rangle .

  2. 2.

    Inductive case (n>1n>1): In the analysis of the inductive case we consider two possibilities, depending on whether the first step is performed with a sub-goal, which is an instance of the atom (IH,[X],G,IC,SC)\Rightarrow(I^{H},[X^{\prime}],G^{\prime},I^{C},S^{C}), or not. This kind of sub-goal comes from embedded implications that appear in the body of some rule, or are submitted directly in the initial query proposed to the system.

    1. (a)

      First, consider that 𝒬p(sn¯,[],I,C,epsilon)𝒬1\mathscr{Q}^{\prime}\equiv\leftarrow p(\overline{s_{n}},[],I,C,epsilon)\land\mathscr{Q}^{\prime}_{1} (translation of 𝒬p(sn¯)𝒬1\mathscr{Q}\equiv\leftarrow p(\overline{s_{n}})\land\mathscr{Q}_{1}) and the first step is performed with a rule (p(tn¯,[],i,ϵ,SC))Π(p(\overline{t_{n}},[],i,\epsilon,S^{C})\leftarrow\mathscr{B}^{\prime})\in\Pi^{\prime}, with index rule ii (translation of (p(tn¯))Π(p(\overline{t_{n}})\leftarrow\mathscr{B})\in\Pi),111 Note that in the translated program Π\Pi^{\prime}, we can find rules of the form p(tn¯,[X¯],IH,SH,SC)reg(IH,[X¯],CR)chk(CR,SC)p(\overline{t_{n}},[\overline{X^{\prime}}],I^{H},S^{H},S^{C})\leftarrow reg(I^{H},[\overline{X^{\prime}}],C^{R})\land chk(C^{R},S^{C})\land\mathscr{B}^{\prime} coming from the translation of the embedded implications in the body of the rules in Π\Pi (see Definition 3.5). However, this type of rule does not contribute to the first step of a derivation. whose head unifies with the selected sub-goal:

      mgu({p(sn¯,[],I,C,epsilon)=p(tn¯,[],i,ϵ,SC)})=mgu({sn=tn¯,[]=[],I=i,C=ϵ,ϵ=SC})=σ{I/i,C/ϵ,SC/ϵ}=σ1δ1\begin{array}[]{l}mgu(\{p(\overline{s_{n}},[],I,C,epsilon)=p(\overline{t_{n}},[],i,\epsilon,S^{C})\})\\ ~{}~{}~{}~{}~{}~{}=mgu(\{\overline{s_{n}=t_{n}},[]=[],I=i,C=\epsilon,\epsilon=S^{C}\})\\ ~{}~{}~{}~{}~{}~{}=\sigma\{I/i,C/\epsilon,S^{C}/\epsilon\}=\sigma_{1}\cup\delta_{1}\end{array}

      where mgu({sn=tn¯})=σ1mgu(\{\overline{s_{n}=t_{n}}\})=\sigma_{1} must be solvable, δ1={I/i,C/ϵ,SC/ϵ}\delta_{1}=\{I/i,C/\epsilon,S^{C}/\epsilon\} and its domain shares variables neither with θ\theta nor with σ\sigma. Hence, derivation 𝒟\mathscr{D}^{\prime} proceeds thus:

      p(sn¯)𝒬1,θδ,ΠSLDSLD(𝒬1)(σ1δ1),(θδ)(σ1δ1),ΠSLDSLD,(θδ)(σ1δ1)(σ2δ2),ΠΠreg\begin{array}[]{l}\langle\leftarrow p(\overline{s_{n}})\land\mathscr{Q}^{\prime}_{1},\theta\cup\delta,\Pi^{\prime}\rangle\\ ~{}~{}~{}~{}~{}~{}\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(\mathscr{B}^{\prime}\land\mathscr{Q}^{\prime}_{1})(\sigma_{1}\cup\delta_{1}),(\theta\cup\delta)(\sigma_{1}\cup\delta_{1}),\Pi^{\prime}\rangle\\ ~{}~{}~{}~{}~{}~{}\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,(\theta\cup\delta)(\sigma_{1}\cup\delta_{1})(\sigma_{2}\cup\delta_{2}),\Pi^{\prime}\cup\Pi_{reg}\rangle\end{array}

      Now, because mgu({p(sn¯)=p(tn¯)})=mgu({sn=tn¯})=σ1mgu(\{p(\overline{s_{n}})=p(\overline{t_{n}})\})=mgu(\{\overline{s_{n}=t_{n}}\})=\sigma_{1} is solvable, there exists the step in Π\Pi: ⟨←p(¯s_n)Q_1, θ, Π _HSLD​​​   ⟨←(BQ’_1)σ_1, θσ_1, Π on the other hand, by the inductive hypothesis, there exists a derivation in Π\Pi such that: ⟨←(BQ_1)σ_1, θσ_1, Π _HSLD​​​ *   ⟨□,θσ_1σ_2,Π and the derivation 𝒟\mathscr{D} in Π\Pi can be constructed.

    2. (b)

      In this case, the first step is performed on a solving implication clause, that is 𝒬((i,[X¯],G,IC,SC)𝒬1)\mathscr{Q}^{\prime}\equiv\leftarrow(\Rightarrow(i,[\overline{X}],G^{\prime},I^{C},S^{C})\land\mathscr{Q}^{\prime}_{1}) which is the translation of 𝒬(HG)𝒬1\mathscr{Q}\equiv\leftarrow(H\Rightarrow G)\land\mathscr{Q}_{1}. For simplicity, we will assume that Gq(sn¯)G^{\prime}\equiv q(\overline{s_{n}}) and the goal translation Gq(sn¯,L,I,C,SC.IC)G\equiv q(\overline{s_{n}},L,I,C,S^{C}.I^{C}). Then the shape of the derivation 𝒟\mathscr{D}^{\prime} is:

      ((i,[X¯],G,IC,SC)𝒬1),θ,ΠSLDSLD(get_ci(IC)reg_rule(i,[X¯],IC,SC)call(G)𝒬1),θ,ΠSLDSLD(reg_rule(i,[X¯],j,SC)call(G)𝒬1){IC/j},θ{IC/j},ΠSLDSLD(assertz(reg(i,[X¯],SC))call(G)𝒬1){IC/j},θ{IC/j},ΠSLDSLD(call(G)𝒬1){IC/j},θ{IC/j},Π{reg(i,[X¯],SC)}SLDSLD(G𝒬1){IC/1},θ{IC/1},Π{reg(0,[X¯],SC)}SLD+SLDQ1(σ1{IC/1}δ1),(θσ1){IC/j}δ1,Π{reg(i,[X¯],SC)}Πreg1SLDSLD,(θσ1σ2){IC/j}δ1δ2,Π{reg(i,[X¯],SC)}Πreg1Πreg2\begin{array}[]{l}\langle\leftarrow(\Rightarrow(i,[\overline{X}],G^{\prime},I^{C},S^{C})\land\mathscr{Q}^{\prime}_{1}),\theta,\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(get\_ci(I^{C})\land reg\_rule(i,[\overline{X}],I^{C},S^{C})\land call(G^{\prime})\land\mathscr{Q}^{\prime}_{1}),\theta,\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(reg\_rule(i,[\overline{X}],j,S^{C})\land call(G^{\prime})\land\mathscr{Q}^{\prime}_{1})\{I^{C}/j\},\theta\cup\{I^{C}/j\},\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(assertz(reg(i,[\overline{X}],S^{C}))\land call(G^{\prime})\land\mathscr{Q}^{\prime}_{1})\{I^{C}/j\},\theta\cup\{I^{C}/j\},\Pi^{\prime}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(call(G^{\prime})\land\mathscr{Q}^{\prime}_{1})\{I^{C}/j\},\theta\cup\{I^{C}/j\},\Pi^{\prime}\cup\{reg(i,[\overline{X}],S^{C})\}\rangle\\ \stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow(G^{\prime}\land\mathscr{Q}^{\prime}_{1})\{I^{C}/1\},\theta\cup\{I^{C}/1\},\Pi^{\prime}\cup\{reg(0,[\overline{X}],S^{C})\}\rangle\\ \stackrel{{\scriptstyle\!\!\!+\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\leftarrow Q^{\prime}_{1}(\sigma_{1}\cup\{I^{C}/1\}\cup\delta_{1}),(\theta\sigma_{1})\cup\{I^{C}/j\}\cup\delta_{1},\Pi^{\prime}\cup\{reg(i,[\overline{X}],S^{C})\}\cup\Pi_{reg1}\rangle\\ \stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,(\theta\sigma_{1}\sigma_{2})\cup\{I^{C}/j\}\cup\delta_{1}\cup\delta_{2},\Pi^{\prime}\cup\{reg(i,[\overline{X}],S^{C})\}\cup\Pi_{reg1}\cup\Pi_{reg2}\rangle\end{array}

      with two clear parts. The first part corresponds to the HSLD step performed on (HG)(H\Rightarrow G) using Rule 2 of Definition 3.1. It groups the associated derivations submitted by the occurrence of embedded implications and their successive program contexts. Then there must exist the HSLD step (HG)𝒬1),θ,ΠHSLDHSLDQ1σ1,θσ1,Π\langle\leftarrow(H\Rightarrow G)\land\mathscr{Q}_{1}),\theta,\Pi\rangle\stackrel{{\scriptstyle\!\!\!\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle Q_{1}\sigma_{1},\theta\sigma_{1},\Pi\rangle in the program Π\Pi. As for the second part, by the inductive hypothesis, there must exist the HSLD derivation Q1σ1,θσ1,ΠSLDSLD,θσ1σ2,Π.\langle Q_{1}\sigma_{1},\theta\sigma_{1},\Pi\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,\theta\sigma_{1}\sigma_{2},\Pi\rangle. Combining both, the former step and the last derivation, we obtain the derivation 𝒟\mathscr{D}.

Corollary B.6.

Let Π\Pi^{\prime} be the translation of a program Π\Pi and 𝒢(𝒬1){\cal G}^{\prime}\equiv(\leftarrow\mathscr{Q}^{\prime}_{1}) the goal translation of a goal 𝒢(𝒬1){\cal G}\equiv(\leftarrow\mathscr{Q}_{1}), if there exists a derivation 𝒟𝒬,id,ΠSLDSLD,σ,ΠΠreg\mathscr{D}^{\prime}\equiv\langle\leftarrow\mathscr{Q}^{\prime},id,\Pi^{\prime}\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny SLD}}}}\langle\square,\sigma^{\prime},\Pi^{\prime}\cup\Pi_{reg}\rangle, where Πreg\Pi_{reg} is the set of rule registrations, that is, all the regreg/3 assertions due to embedded implication solving, then there exists a derivation 𝒟(𝒬),id,ΠHSLDHSLD,σ,Π\mathscr{D}\equiv\langle(\leftarrow\mathscr{Q}),id,\Pi\rangle\stackrel{{\scriptstyle\!\!\!*\;}}{{{\Rightarrow}_{\mbox{\tiny HSLD}}}}\langle\square,\sigma,\Pi\rangle, and σ=σ[𝒱ar(𝒢)]\sigma=\sigma^{\prime}[{\mathscr{V}}ar({\cal G})]. \blacksquare

Appendix C Related Work

The term ”hypothetical reasoning” appears in many important contexts in the philosophical and scientific literature. Auguste Comte, founder of Positivism, is one of the first thinkers to highlight the importance of hypotheses in science [Bourdeau (2020)]. Although Comte does not establish laws for hypothetical reasoning, he begins the path, influencing (according to Michel Bourdeau [Bourdeau (2014)]) other thinkers such as Peirce and its abductive reasoning. According to that American philosopher, human thought has three modes of reasoning: deductive, inductive and abductive. ”Abduction is the first step of scientific reasoning”, because, as he says, ”abduction is the process of forming explanatory hypotheses. It is the only logical operation that introduces a new idea” [Douven (2021)].

However, our work is centered in a more specific area with a long tradition in the field of Logic Programming, in which the purpose is prospective: to propose hypotheses in order to evaluate its consequences. Mainly, our work is influenced by those of Gabbay [Gabbay and Reyle (1984), Gabbay (1985)] and Bonner [Bonner (1988), Bonner (1990), Bonner (1994), Bonner (1997)] and, to a lesser extent, by those of L.T. McCarty [McCarty (1988a), McCarty (1988b)].

Gabbay first deals with hypothetical implications in logic programming. In [Gabbay and Reyle (1984)], they focused only on addition operations because deletion is problematic; thus they let it for another paper. Addition is essentially monotonic and deletion is not. We use a similar technique to the one followed by Gabbay for implementing hypothetical implications, by asserting the antecedent to the program database, trying to derive the consequent and finally retracting the antecedent. [Gabbay (1985)] investigates the logical properties of N-PROLOG and the way it relates to classical logic and the classical quantifiers. He also introduced negation as failure into N-PROLOG. He saw that success in the N-PROLOG computation of a goal GG from the database PP means logically that PGP\vdash G in intuitionistic logic. It is credited that was Gabbay the first one to realize the important connection between hypothetical reasoning and intuitionistic logic [Bonner (1994)].

In [McCarty (1988a)], he presents a clausal language that extends Horn-clause logic by adding negations and embedded implications (i.e., hypothetical implications –he was the one who first used this designation–) to the right-hand side of a rule, and interpreting these new rules intuitionistically in a set of partial models. Lately, in [McCarty (1988b)], he shown that clausal intuitionistic logic has a tableau proof procedure that generalizes Horn-clause refutation proofs and it is proved sound and complete.

As it has been said, Bonner has extensive experience in this field, starting from a language with embedded implications (close to ours) and exploring its applications and formal properties, including results on complexity [Bonner (1988), Bonner (1990), Bonner (1994)]. In his latest work on this topic [Bonner (1997)], he broke with his initial works and he developed a logic programming language with a dedicated syntax in which users can create hypotheses and draw inferences from them. He provides two specific operations with a modal-like notation: hypothetical insertion of facts into a database (Q[add:A]Q[add:A] meaning that “Q would be true if A were added to the database”), that has a well-established logic (intuitionistic logic) and hypothetical deletion (Q[del:A]Q[del:A] meaning that “Q would be true if A were deleted from the database”). In this paper, he develop a logical semantics for hypothetical insertions and deletions (including a proof theory, model theory, and fixpoint theory). He analyses the expressibility of the language and he shows that classical logic cannot express some simple hypothetical queries. However, we believe that the language introduced, with specific insertion and deletion operations, may have limitations compared to the one we have proposed in this work (e.g., only atoms can be inserted or deleted). Finally, he augmented the logic with negation-as-failure so that nonmonotonic queries can be expressed, a subject that we let as future work.

Finally, another piece of related work is λ\lambda-Prolog, which uses a syntax based on the so-called “hereditary Harrop formulas.” Thanks to this type of formulas, λ\lambda-Prolog subsumes a set of increasingly complex sublanguages, ranging from Horn clauses and higher-order Horn clauses to hereditary Harrop formulas. This type of formula, for example, allows rules with bodies that contain (hypothetical) implications whose hypotheses are in turn rules.

The use of higher-order Horn clauses and a non-deterministic goal-directed search-based operational semantics (which is complete with respect to an intuitionistic sequent calculus) [Miller et al. (1991)] allows λ\lambda-Prolog the ability to perform hypothetical reasoning. In practical and informal terms, the λ\lambda-Prolog operational mechanism performs operations similar to those performed by Comp to solve a hypothetical implication (HGH\Rightarrow G): Assert HH to the rules of the program (creating a new context) and launch the goal GG; if GG is successful, then (HGH\Rightarrow G) is also successful. It is nothing other than the rule ”AUGMENT” (P(DG)P\vdash(D\Rightarrow G) only if P+DGP+{D}\vdash G.), one of the operational rules that models the computation-as-goal-directed-search of λ\lambda-Prolog.

Therefore, both mechanisms are comparable, except that λ\lambda-Prolog fits into a more general and ambitious framework, while Comp simply tries to extend the language of Horn clauses and the resolution principle with additional features, among which the hypothetical reasoning is found, as a platform for a fuzzy logic programming system.

What specific expressive capabilities for hypothetical reasoning λ\lambda-Prolog incorporates depends on the implementation. For example, we know in the words of D. Miller himself222stackoverflow.com/questions/65176668/?prolog-rejecting-hypothetical-reasoning-queries about Teyjus, an implementation of λ\lambda-Prolog, that ”Teyjus does not permit implications to be used in top-level goals. This is a characteristic that may change in the future when the compilation model is extended also to these goals but, for now, it means that some of the examples presented, eg, in Section 3.2, cannot be run directly using this system.” Instead, the future implementation of Comp is planned to be able to allow this by compiling the goal in the context of the loaded program before submitting it.

Moreover, λ\lambda-Prolog does not work with ”negative assumptions”, a matter that we have let marked as future work, and that we will undertake by following some ideas already proposed for the implementation of a Fuzzy Datalog system [Julian-Iranzo and Saenz-Perez, 2018].

Despite all the above and the possible relations between the foundations of our proposal and λ\lambda-Prolog, as we have just commented in this section, our work has its roots in the previous work carried out by Gabbay and Bonner. On the other hand, the main contribution of this article is the development of efficient high-level implementation techniques for implementing a fuzzy logic programming system (HBPL) with the possibility of hypothetical reasoning based on BPL [Rubio-Manzano and Julián-Iranzo (2014), Julián-Iranzo and Rubio-Manzano (2017)]. In such a system, assumptions imply compilations which with our proposal are possible to perform at compile-time.