<<

Operational/Interpretive Unfolding of Multi-adjoint Programs1

Pascual Julián Ginés Moreno Jaime Penabad Dept. de Informática Dept. de Informática Dept. de Matemáticas Universidad de CLM Universidad de CLM Universidad de CLM Escuela Superior de Informática Escuela Politécnica Superior Escuela Politécnica Superior Campus Univ. 13071 Ciudad Real Campus Univ. 02071 Albacete Campus Univ. 02071 Albacete [email protected] [email protected] [email protected]

Abstract 1 Introduction

Multi-adjoint logic programming represents a Multi-adjoint logic programming [12, 13] is an very recent, extremely exible attempt for in- extremely exible framework combining fuzzy troducing fuzzy logic into logic programming logic and logic programming, which largely im- (LP). In this setting, the execution of a goal proves older approaches previously introduced w.r.t. a given program is done in two separate in this eld (see, for instance [10, 6, 3, 11, phases. During the operational one, admissi- 17, 2], where dierent fuzzy variants of Pro- ble steps are systematically applied in a sim- log have been proposed). An special mention ilar way to classical resolution steps in pure deserves the fuzzy dialect of Prolog presented LP, thus returning a computed in [5], since it is very close to the language together with an expression where all atoms used here. However, we nd two slight dier- have been exploited. This last expression is ences: whereas the multi-adjoint approach is then interpreted under a given lattice during based on weighted" clauses (with and with- the so called interpretive phase, hence return- out body) whose truth degrees are elements of ing a value which represents the fuzzy compo- any appropriate lattice, in the Fuzzy Prolog of nent (truth degree) of the computed answer. [5], truth degrees are based on Borel Algebras On the other hand, unfolding is a well (union intervals), and they are only applied to known transformation rule widely used in facts (i.e., clauses with no body). declarative programming for optimizing and Informally speaking, a multiadjoint logic specializing programs, among other applica- program can be seen as a set of rules each tions. In essence, it is usually based on the one annotated by a truth degree and a goal application of operational steps on the body is a query to the system plus a substitution of program rules. The novelty of this pa- (initially the identity substitution). In the per consists in showing that this process can multi-adjoint logic programming framework, also be made in terms of interpretive steps. goals are evaluated, in a given program, in We present two strongly related kinds of un- two separate computational phases. During folding (operational and interpretive), which, the operational one, admissible steps (a gen- apart from exhibiting strong correctness prop- eralization of the classical in- erties (i.e. they preserve the semantics of com- ference rule) are systematically applied by a puted substitutions and truth degrees) they are able to signicantly simplify the two exe- 1This work has been partially supported by the EU, under FEDER, and the Spanish Science and Edu- cution phases when solving goals. cation Ministry (MEC) under grant TIN 2004-07943- C04-03. backward reasoning procedure in a similar way (multi-adjoint logic) language proposed in [13] to classical resolution steps in pure LP, thus re- and then used in [7], the interpretive phase is turning a computed substitution together with not modeled in terms of an state transition an expression where all atoms have been ex- system, which prevents the denition/ appli- ploited. This last expression is then inter- cation of the (interpretive) unfolding rule by preted under a given lattice during what we means of interpretive steps. As a consequence, call the interpretive phase, hence returning all results presented there are restricted to the a pair htruth degree; substitutioni which is the operational phase. In this paper we overcome fuzzy counterpart of the classical notion of all these limitations, and we prove that the in- computed answer traditionally used in LP. terpretive unfolding, apart from exhibiting the Program transformation is an optimization analogous strong correctness properties (i.e. it technique for computer programs that start- preserves the semantics of computed substi- tutions and truth degrees) of the operational ing with an initial program P0 derives a se- unfolding originally presented in [7], is able to quence P1,..., Pn of transformed programs by applying elementary transformation rules simplify and accelerate the interpretive phase (fold/unfold) which improve the original pro- when solving goals w.r.t. a given program. gram. The fold/unfold transformation ap- proach was rst introduced in [4] to optimize On the other hand, we have recently functional programs and then used for logic introduced in [8] a transformation rule, the programs [16] and (lazy) functional logic pro- so-called T-Norm replacement, which can be grams [1]. Program transformation also can seen as a primitive precedent of the present be seen as a methodology for software devel- interpretive unfolding. In fact, the four vari- opment, hence its importance. The basic idea ants of T-Norm replacements, also perform is to divide the program development activity, low-level manipulations on fuzzy expression starting with a (possibly naive) problem spec- involving T-Norm operations on program ication written in a programming language, rules. However, our new approach improves into a sequence of small transformation steps. this poorer technique in the following points: Unfolding is a well-known, widely used, semantics-preserving program transformation • It manages a much more powerful and rule. In essence, it is usually based on the expressive language (the multi-adjoint application of operational steps on the body logic programming language) but with a of program rules [14]. The unfolding transfor- simpler syntax, a clearer procedural (opera- mation is able to improve programs, generat- tional/interpretive) semantics and, in general, ing more ecient code. Unfolding is the basis a better formalization. for developing sophisticated and powerful pro- Now, neither interpretive steps, nor inter- gramming tools, such as fold/unfold transfor- • pretive unfolding, are dependent of a selection mation systems or partial evaluators, etc. function (computation rule), as it does occur The main contribution of this paper con- with any other fuzzy unfolding-based trans- sists in showing that, in the framework of formation rule described in the literature, multi-adjoint logic programming, the unfold- since the evaluation order of expressions is ing process can be better understood, if re- xed by the interpretive semantics. sembling the two separate phases of the under- laying procedural semantics of multi-adjoint • As a co-lateral consequence of the previous logic programming languages, we distinguish point and, as we will see when presenting between operational and interpretive unfold- 5.2, it is the rst time that our cor- ing steps. Therefore, we present two strongly rectness results admit a clearer proof scheme related kinds of unfolding: the operational which is not linked to previous instrumental (rstly introduced in [7]) an the interpretive. results about the independence of any kind of It is important to remark that in the original computation rule. • Moreover, it is also the rst time that @i(x1, @i(x2,..., @i(xn−1, xn) ...)). More- our fuzzy variants of unfolding rules, recover over, the truth function for an n-ary ag- the source-to-source language nature char- gregation operator [[@]] : [0, 1]n → [0, 1] is acter in [7] and [8], where some auxiliary required to be non-monotonous and fulll object languages (with complex constructors [[@]](1,..., 1) = 1 and [[@]](0,..., 0) = 0. and intrincated artices with no sense for Additionally, our language L contains the nal user) were mandatory to code the values of a multiadjoint lattice, hL,  residual programs obtained after performing , ←1, &1,..., ←n, &ni, equipped with a collec- operational unfolding or T-Norm replacement. tion of adjoint pairs h←i, &ii, where each &i is a conjunctor 1 intended to the evaluation The structure of the paper is as follows. In of modus ponens. In general, the set of truth Section 2, we summarize the main features of values L may be the carrier of any complete the programming language we use in this work. bounded lattice, but, in the examples, we shall Section 3 denes the procedural semantics of select L as the set of real numbers in the in- the language, establishing a clean separation terval [0, 1]. between the operational and the interpretive A rule is a formula A ←i B, where A is an phase of a computation. In Section 4 we recall atomic formula (usually called the head) and the denition of operational unfolding and we B (which is called the body) is a formula built dene the new notion of interpretive unfold- from atomic formulas B1,...,Bn  n ≥ 0 , ing. Section 5 focuses in the properties rela- truth values of L and conjunctions, disjunc- tive to the correctness of the unfolding trans- tions and aggregations. Rules with an empty formations. Finally, in Section 6 we give our body are called facts.A goal is a body sub- conclusions and propose future work. mitted as a query to the system. Variables in a rule are assumed governed by universal quantiers. 2 Multi-Adjoint Logic Programs Roughly speaking, a multiadjoint logic pro- gram is a set of pairs hR; αi, where R is a rule This section is a short summary of the main and α is a truth degree (a value of L) express- features of our language. Contrary to other ing the condence which the user of the system previous work [7] we start from the scratch has in the truth of the rule R. Often, we will by manipulating an extended version of the write R with α instead of hR; αi. Observe multiadjoint logic programing language pre- that, truth degrees are axiomatically assigned sented in [12, 13]. We send the reader to these (for instance) by an expert. works for a complete formulation. We work with a rst order language, L, con- taining variables, function symbols, predicate 3 Procedural Semantics symbols, constants, quantiers, and , and ∀ ∃ The procedural semantics of the multiadjoint several (arbitrary) connectives to increase lan- logic language can be thought as an op- guage expressiveness: L erational phase followed by an interpretive one. Although this point of view is present in & , & ,..., & (conjunctions) 1 2 k [12, 13], in this section we establish a cleaner ∨ , ∨ ,..., ∨ (disjunctions) 1 2 l separation between both phases. We also give ← , ← ,..., ← (implications) 1 2 m a novel denition of the interpretive phase, @ , @ ,..., @ (aggregations) 1 2 n with a procedural taste, useful not only for clarify the whole computational mechanism, Although the connectives &i, ∨i and @i are binary operators, we usually general- but also crucial for formalizing the concept of ize them as functions with an arbitrary interpretive unfolding in Section 4.2. number of arguments. In the following, 1 It is noteworthy that a symbol &j of L does not we often write @i(x1, . . . , xn) instead of always need to be part of an adjoint pair. 3.1 Operational phase Rule 3.

The operational mechanism uses a generaliza- hQ[A]; σi→AS h(Q[A/⊥]); σi if is the selected atom in , tion of modus ponens that, given a goal A and (1) A Q 0 (2) there is no rule in P whose a program rule hA ←iB, vi, if there is a sub- 2 head unies with . stitution θ = mgu({A = A0}) , we substitute A the atom A by the expression (v&iB)θ. In the following, we dene the concepts Formulas involved in admissible computation of admissible computation step, admissible steps are renamed before being used. Note also derivation and admissible computed answer, that, Rule 3 is introduced to cope with (possi- associated to the operational phase. In the for- ble) unsuccessful admissible derivations.When malization of these concepts, we write C[A], or needed, we shall use the symbols →AS1, →AS2 more generally C[A1, .., An], to denote a for- and →AS3 to distinguish between computation mula where A, or A1, .., An respectively, are steps performed by applying one of the spe- sub-expressions (usually atoms) which arbi- cic admissible rules. Also, when required, the trarily occur in the possibly empty con- exact program rule used in the corresponding text C[]. Moreover, expression C[A/A0] (and its step will be annotated as a superindex of the obvious generalization) means the replacement →AS symbol. of A by A0 in context C[]. Also we use Var(s) for referring to the set of distinct variables Denition 3.2 Let be a program and let occurring in the syntactic object s, whereas P be a goal. An admissible derivation is a θ[Var(s)] denotes the substitution obtained Q sequence ∗ 0 . When 0 is a from θ by restricting its domain, Dom(θ), to hQ; idi →AS hQ ; θi Q formula not containing atoms, the pair 0 , Var(s). hQ ; σi where σ = θ[Var(Q)], is called an admissible computed answer (a.c.a.) for that derivation. Denition 3.1 (Admissible Steps) Let Q be a goal and let σ be a substitution. The pair hQ; σi is an state and we denote by E the set We illustrate these concepts by means of the of states. Given a program P, an admissible following example. computation is formalized as a state transi- tion system, whose transition relation → ⊆ AS Example 3.3 Let be the following program (E × E) is the smallest relation satisfying the P following admissible rules: and let ([0, 1], ≤) be the lattice where ≤ is the usual order on real numbers. Rule 1. R : hp(X)← q(X,Y )& r(Y ); α = 0.8i if 1 prod G hQ[A]; σi→AS h(Q[A/v&iB])θ; σθi R : hq(a, Y )← s(Y ); α = 0.7i is the selected atom in , 2 prod (1) A Q R : hq(Y, a)← r(Y ); α = 0.8i 0 , 3 luka (2) θ = mgu({A = A}) R : hr(Y )← ; α = 0.7i 0 in and is not 4 luka (3) hA ←iB; vi P B R : hs(b)← ; α = 0.9i empty. 5 luka The labels prod, G and luka mean for Rule 2. product logic, Gödel and hQ[A]; σi→AS h(Q[A/v])θ; σθi if Šukasiewicz logic, respectively. That is, is the selected atom in , (1) A Q [[&prod]](x, y) = x · y, [[&G]](x, y) = min(x, y), 0 , and (2) θ = mgu({A = A}) and [[&luka]](x, y) = max(0, x + y − 1). 0 in . (3) hA ←i; vi P In the following admissible derivation for the program and the goal , 2 P ←p(X)&Gr(a) Let mgu(E) denote the most general unier of we underline the selected expression in each an equation set E (see [9] for a formal denition of this concept). admissible step: hp(X)&Gr(a); idi state hr; σi is called an interpretive computed R →AS1 1 answer (i.c.a.).

h(0.8&prod(q(X1,Y1)&Gr(Y1)))&Gr(a); σ1i Usually, we refer to a complete derivation as R2 →AS1 the sequence of admissible/interpretive steps h(0.8&prod((0.7&prods(Y2))&Gr(Y2)))&Gr(a); σ2i of the form ∗ 0 ∗ , hQ; idi →AS hQ ; σi →IS hr; σi R →AS2 5 where hQ0; σ[Var(Q)]i and hr; σ[Var(Q)]i are, respectively, the a.c.a. and the i.c.a. for h(0.8&prod((0.7&prod0.9)&Gr(b)))&Gr(a); σ3i R the derivation. Sometimes, we denote it by →AS2 4 ∗ and we say that is hQ; idi →AS/IS hr; σi hr; σi h(0.8&prod((0.7&prod0.9)&G0.7))&Gr(a); σ4i the nal computed answer of the derivation. R →AS2 4 Example 3.6 We complete the previous h(0.8&prod((0.7&prod0.9)&G0.7))&G0.7; σ5i, derivation of Example 3.3 by executing the where necessary interpretive steps to obtain the σ1 = {X/X1}, interpretive computed answer (i.c.a.) with σ2 = {X/a, X1/a, Y1/Y2} respect to lattice ([0, 1], ≤). σ3 = {X/a, X1/a, Y1/b, Y2/b} h(0.8& ((0.7& 0.9)& 0.7))& 0.7; {X/a}i σ4 = {X/a, X1/a, Y1/b, Y2/b, Y3/b} prod prod G G σ5 = {X/a, X1/a, Y1/b, Y2/b, Y3/b, Y4/a} →IS h(0.8&prod(0.63&G0.7))&G0.7; {X/a}i →IS h(0.8&prod0.63)&G0.7; {X/a}i So, since σ5[Var(Q)] = {X/a}, the a.c.a. →IS h0.504&G0.7; {X/a}i associated to this admissible derivation is: →IS h0.504; {X/a}i h(0.8&prod((0.7&prod0.9)&G0.7))&G0.7; {X/a}i. Then the i.c.a for this complete derivation is the pair h0.504; {X/a}i. 3.2 Interpretive phase If we exploit all atoms of a goal, by applying 4 Fuzzy Unfolding Transformations admissible steps as much as needed during the operational phase, then it becomes a formula The unfolding transformation traditionally with no atoms which can be then directly in- considered in pure LP consists in the replace- terpreted in the multiadjoint lattice L. This ment of a program clause C by the set of justies the following notions of interpretive clauses obtained after applying a symbolic computation step, interpretive derivation and computation step in all its possible forms on interpretive computed answer. the body of C [14]. As detailed in [7], we have adapted this Denition 3.4 (Interpretive Step) Let P transformation to deal with multiadjoint be a program, Q a goal and σ a substitution. logic programs by dening it in terms of op- We formalize the notion of interpretive com- erational steps (see Denition 3.1). Also, in putation as a state transition system, whose [7], we proved that the application of unfold- transition relation →IS ⊆ (E × E) is dened as ing transformation step to multiadjoint logic programs is able to speed up goal evaluation hQ[@(r1, r2)]; σi→IShQ[@(r1,r2)/[[@]](r1,r2)];σi by reducing the length of admissible deriva- tions during the operational phase. where [[@]] is the truth function of connective The main objective of the present section @ in the lattice hL, i associated to P. is to recall the denition of operational un- Denition 3.5 Let P be a program and folding and to dene and unfolding rule for hQ; σi an a.c.a., that is, Q is a goal not con- interpretive steps. Note that our new notion taining atoms. An interpretive derivation is a of interpretive unfolding is intended to facili- sequence ∗ 0 . When 0 tate the evaluation of truth degrees during the hQ; σi →IS hQ ; σi Q = r ∈ L, being hL, i the lattice associated to P, the interpretive phase. 4.1 Operational Unfolding We illustrate the denition of operational un- folding and its advantages by means of the fol- The following denition is recalled from [7], lowing example. but we have slightly simplied it in the sense that now, the operational unfolding is formu- Example 4.2 Consider again program P lated as a source-to-source language transfor- shown in Example 3.3.It is easy to see that mation instead of a (more involved) source-to- the unfolding of rule R2 in program P (ex- object language transformation. ploiting the second admissible rule of De- nition 3.1) generates the new program Denition 4.1 (Operational Unfolding) (P − , where is the new unfolded Let be a program and let {R2}) ∪ {R6} R6 P R :(A ←i rule with . with be a (non unit) program q(a, b)←prod0.9 α = 0.7 B α = v) ∈ P On the other hand, if we want to unfold now rule. Then, the operational unfolding of rule , we must rstly build the following rule in program is the new program R1 R P onestep admissible derivations: 0 P = (P − {R}) ∪ U where U = {Aσ ←i 0 0 R6 B with α = v | hB; idi→AS hB ; σi}. hq(X,Y )&Gr(Y ); idi →AS1 h(0.7& 0.9)& r(b); {X/a, Y/b}i, and There are some remarks to do regarding our prod G R3 denition. Similarly to the classical SLD hq(X,Y )&Gr(Y ); idi →AS1 resolution based unfolding rule presented in h(0.8&lukar(Y1))&Gr(a); {X/Y1, Y/a}i. [16], the substitutions computed by admissi- ble steps during the operational unfolding, are So, the resulting unfolded rules are R7: incorporated to the transformed rules in a nat- p(a)←prod(0.7&prod0.9)&Gr(b) with α = 0.8, ural way, i.e., by applying them to the head and R8 : p(Y1)←prod(0.8 &luka r(Y1)) &G r(a) of the rule. On the other hand, regarding with α = 0.8. the propagation of truth degrees, we solve this Moreover, by performing a new admissible problem in a very easy way: the unfolded rule step with the second rule of Denition 3.1 on directly inherits the truth degree α of the orig- the body of rule R7, we obtain the new un- inal rule. folded rule R9 : p(a) ←prod(0.7&prod0.9)&G0.7 However, a deeper analysis of the oper- with α = 0.8. So, the nal program is the ational unfolding transformation reveals us set of rules {R3, R4, R5, R6, R8, R9}. It is that the body of transformed rules also con- important to note that the application of this tains 'compiledin' information on both com- last rule to the goal proposed in Example 3.3 ponents of nal computed answers (i.e., truth simulates the eects of the rst four admissi- degree and substitution). Regarding truth de- ble steps shown in the derivation of the same grees, we observe that the body of the trans- example, which evidences the improvements formed rule includes symbol ⊥ if we performed achieved by operational unfolding on trans- formed programs. a →AS3 admissible step, or the truth degree together with the corresponding adjoint con- junction of the second rule involved in the un- 4.2 Interpretive Unfolding folded step when the applied admissible step The present section denes the notion of inter- was based on or , respectively. So, →AS2 →AS1 pretive unfolding. This kind of unfolding is de- the propagation of truth degrees during un- voted to accelerate truth degrees calculations folding is done at two dierent levels: during the second, interpretive, phase of the 1. by directly assigning the truth degree of procedural semantics. Since in Denition 3.4 the original rule as the truth degree of the we have opted for a procedural characteriza- transformed one, and tion of the interpretive phase, (by formalizing it in terms of an state transition system) thus 2. by introducing new truth degrees (of avoiding the use of semantic concepts (which other rules or alternatively ⊥) in its body. were necessary, for instance, in [13] and [7]), this fact has strongly helped us to clarify the Example 4.4 Let's perform now some in- formalization of our interpretive unfolding rule terpretive unfolding steps on the rules ob- as follows. tained by operational unfolding in Example 4.2. By interpretive unfolding of kind IU1 Denition 4.3 (Interpretive Unfolding) of rule R (note that [[& ]](0.9, 0.7) = Let be a program and let 9 prod P R :(A ←i 0.63) we obtain the new unfolded rule R : with be a (non unit) program 10 B α = v) ∈ P p(a) ← 0.63& 0.7 with α = 0.8. More- rule. Then, the interpretive unfolding of rule prod G over, by applying a new IU1 interpretive un- in program with respect to the lattice R P folding step on this last rule, we obtain R : associated to is the new program 11 hL, i P p(a) ← 0.63 with α = 0.8. Finally, rule 0 0 with 0 such prod P = (P − {R}) ∪ {A ←i B α = v } R becomes the fact R : p(a) ← with that: 11 12 prod α = 0.504 after a nal IU2 interpretive un- folding step. So, the nal program is the set of IU1 if expression r @r appear in B then B0 = 1 2 rules and now the B[r @r /[[@]](r , r )], where @ is a con- {R3, R4, R5, R6, R8, R12} 1 2 1 2 derivation shown in example 3.3 can reduce its nective, and v0 = v; length in six steps thanks to the use of clause IU2 if , where , then 0 is empty B = r r ∈ L B R12. More exactly, we have avoided three ad- 0 and v = [[&i]](v, r), where (←i, &i) is an missible and three interpretive steps, thanks to adjoint pair in . hL, i the fact that rule R12 comes from R1 after having been modied by three operational plus Observe that the rst variant of interpretive three interpretive unfolding operations. Again, unfolding ( ), simply consists in applying IU1 this shows the improvements achieved by the an interpretive step on the body of a rule. In combined use of operational/interpretive un- this sense, an alternative formalization, more folding, on transformed programs. similar to Denition 4.1, but replacing the use 0 of →AS by →IS , might be: P = (P −{R})∪U 0 5 Properties of the Transformations where U = {A ←i B with α = v | hB; idi →IS 0 In fact, both formulations simply hB ; idi}. In this section, we formalize and prove the best consists in replacing a program rule whose R properties one can expect of a transformation body contains a connective , by an analogous @ system like the our, which is based on the two rule, with the same truth degree, but with the kinds of unfolding described before. Namely, calculated truth degree of (w.r.t. the lat- @ on the theoretical side, the total corre- tice associated to the program) in its body. • spondence between i.c.a.'s for goals executed Anyway, it is important to contrast the IU1 against original/transformed programs, and transformation (in any of its alternative for- on the practical side, the gains in eciency mats), with the T-Norm replacement rule of • on unfolded programs by reducing the num- [8], since our new transformation compacts in ber of (both, admissible and interpretive) steps a single formulation three low-level variants of needed to solve a goal. this primitive transformation. Before presenting our combined, global re- Focusing now in the case, we observe IU2 sult, we proceed separately with the particular that the second format proposed before for for- properties of each kind of unfolding. We start malizing , can not be applied now: not only IU1 by recalling from [7] the benets of using op- the truth degree of the transformed rule diers erational unfolding in isolation. from the original one, but also, and what is better, the IU2 transformation is able to sim- Theorem 5.1 (Strong Correctness of plify program rules by directly eliminating its Operational Unfolding) Let P be a bodies, and hence, producing facts. program, and let Q be a goal. If P0 is a The following example illustrates the appli- program obtained by operational unfolding cation of interpretive unfolding and some of of , then, n 0 in i P hQ; idi →AS hQ ; θi P their advantages. m 0 0 in 0, where hQ; idi →AS hQ ; θ i P 1. Q0 does not contain atoms, Strong (⇒). Let k l , where D :[hQ; idi →AS he; θi →IS hr; θi] 0 2. θ = θ [Var(Q)], and k +l = n, be the (generic) complete derivation for Q in P that we plan to simulate by con- 3. . m ≤ n structing a new derivation D0 in P0. Consider also the rule with The proof of this theorem is detailed in [7]. It R :(A ←i B[r1@r2] α = is important to note that the main advantages v) ∈ P such that, by interpretive unfolding of in program , we obtain 0 of operational unfolding can be already appre- R P R :(A ←i with . Remem- ciated during the rst (operational or admis- B[r1@r2/[[@]](r1, r2)] α = v) 0 0 0 sible) phase of goal executions. The rst two ber that R ∈ P and R ∈ P , but R ∈/ P 0 claims of the theorem imply the exact corre- and R ∈/ P. Since interpretive unfolding only spondence between a.c.a.'s in both programs, aects expressions with connectives and ele- which also implies that i.c.a.'s are preserved ments belonging to L, the set of atoms in the heads and bodies of both and 0 are ex- with independence of the lattice hL, i used R R to interpret the a.c.a.'s. Besides this, prot is actly the same. Moreover, since interpretive also achieved in eciency, by diminishing the steps are not dependent of any kind of selec- length of admissible derivations (claim 3). tion function (or computation rule), we can assume w.l.o.g. that the rst steps in the in- Now we proceed with interpretive unfold- terpretive phase in are applied to each ex- ing, where we obtain the counterpart of the D pression of the form introduced in by previous theorem. Advantages in this case are r1@r2 e previous admissible steps done with rule . only appreciated during the second (interpre- R That is, we can safely suppose that derivation tive) phase of goal executions. In this sense, has the form k l1 although we can not properly speak about D D :[hQ; idi →AS he; θi →IS 0 l2 , with . This im- a.c.a.'s preservation, we prove that it is pos- he ; θi →IS hr; θi] l1 + l2 = l sible to maintain the set of i.c.a's associated plies that we can easily construct the following admissible derivation 0 k 0 to a given goal (when a.c.a.'s are interpreted D :[hQ; idi →AS he ; θi] 0 with respect to the same lattice used during in P , where: the interpretive unfolding process). Regard- • the length of D0 coincides with the number ing the reduction of the length of derivation in of admissible steps, k, applied in D, transformed programs, interpretive unfolding • the atom reduced in the i-th step of D0 co- is able to reduce the number of interpretive incides with the atom reduced in the i-th step steps needed to solve a goal, similarly as oper- of D, for 1 ≤ i ≤ k, and ational unfolding did w.r.t. admissible steps. • the rule used in the i-th step of D0 is the same that the one used in the i-th step of , Theorem 5.2 (Strong Correctness of In- D for 1 ≤ i ≤ k, except when this last one is R: terpretive Unfolding) Let P be a program in this case, we use R0 in D0. and let Q be a goal. If P0 is a program ob- tained by interpretive unfolding of P, then, Observe that the a.c.a.'s associated to both n in , i m derivations are not exactly the same (which hQ; idi →AS/IS hr; θi P hQ; idi →AS/IS hr; θi in P0, where reveals that interpretive unfolding is not able to preserve a.c.a.'s, as operational unfolding 1. r ∈ L, being hL, i the lattice associated does) but they are strongly related: both share to P used during the interpretive unfold- the same substitution θ, whereas expressions e ing process, and and e0 are very similar. In fact, any admissible step done with rule R0 in D0, introduces a (just 2. m ≤ n. interpreted) value of the form [[@]](r1, r2) in 0, whereas the corresponding steps done with n order to prove this theorem, we treat sep- e I rule in , leaves descendants of the (non yet arately both claims of the double implication. R D interpreted) expression r1@r2 in e. Formally, if Pj is the set of positions of the j occurrences Theorem 5.3 (Strong Correctness of the of r1@r2 introduced in e by the application of Transformation System) Let (P0,..., Pk) j admissible steps using R in D (or, equiva- be a transformation sequence where each pro- lently, Pj is the set of positions of the j occur- gram in the sequence, except the initial one 0 rences of [[@]](r1, r2) introduced in e by the P0, is obtained from the immediately preceding application of j admissible steps using R0 in one by applying operational/interpretive un- 0), then 0 . Hence, folding. Then, n in i D e = e[r1@r2/[[@]](r1, r2)]Pj hQ; idi →AS/IS hr; θi P0 0 can be seen as a partially interpreted version m 0 in , where e hQ; idi →AS/IS hr; θ i Pk of e, and then it is easy to see that, by simply 1. , being the lattice associated applying several interpretive steps on the cor- r ∈ L hL, i to P used during the interpretive unfold- responding j occurrences of r @r in e, we can 1 2 ing process, replace them by [[@]](r1, r2), until reaching the 0 intended expression e . From here, we can n- 2. θ0 = θ[Var(Q)], and ish the complete derivations in both programs by applying the same interpretive steps, until 3. m ≤ n. obtaining the same i.c.a. hr, θi. Regarding the reduction of the length of 6 Conclusions and Future Work the derivation on transformed programs, we have seen that any step done with the un- The present paper must be seen as a nal step in the development of the research line folded rule R0 in derivation D0, avoids a later interpretive step which, on the other hand, we started in [8] and continued in [7], where is unavoidable when building a derivation we have tried to adapt and to study the role played by a classical transformation rule like using rules of the original program P. So, unfolding, in the setting of fuzzy logic pro- the complete derivation simulating D in P0 gramming whit labeled rules. In our investiga- has the form: [hQ; idi →k he0; θi →l2 hr; θi], AS IS tions, we have dealt with dierent fuzzy logic where as we said l ≤ l, which implies that 2 programming languages sharing all them the m = k + l2 ≤ k + l = n what completes the proof of the strong completeness. common feature that they are based on pro- gram clauses/rules with "weights" expressing the truth degree or condence factor one may Strong Soundness ( ). ⇐ have in their application. The present paper It is perfectly analogous (even easier to prove) resumes and improves all our contributions in to the previous case. this research line, by considering one of the most recent and exible languages in the eld Finally, the strong correctness of interpretive [13]. We have highlighted that, our unfolding- unfolding follows from both, the strong based transformation rules for multi-adjoint soundness (⇐) and the strong completeness logic programs, inherit both the simplicity and (⇒), as we wanted to prove. computational power of the original language. When formalizing extended versions of previ- To nish this section, we present the fol- ous unfolding-based transformation rules, we lowing result which combines the use of have been able now of avoiding instrumen- operational/interpretive unfolding by consid- tal and noisy elements like intermediate lan- ering a transformation sequence of programs guages, computation rules, independence re- (P0,..., Pk), k ≥ 0. The following theorem sults, and so on. It is important to note that, formalizes the best properties of the resulting all the results presented in this paper are also transformation system, namely, its strong applicable to the Fuzzy Prolog of [5]3, with the correctness and the guarantee for producing improvements on residual programs. The 3In this approach, the interpretive phase is mod- eled in terms of constraint solving, which similarly whole result directly follows as a simple to ours avoids the use of computation rules and other corollary from 5.1 and 5.2. related perturbations. advantage that an implementation for the lan- [6] M. Ishizuka and N. Kanai. Prolog-ELF guage is already available in this case. (we are Incorporating Fuzzy Logic. In Proc. of planning to implement our unfolding transfor- IJCAI'85, pp. 701703, 1985. mations on such platform). For the future, there exist many topics [7] P. Julián, G. Moreno, and J. Penabad. On to undertake, closely connected with this re- Fuzzy Unfolding. A Multi-Adjoint Ap- search line: fuzzy unfolding semantics, fuzzy proach. Fuzzy Sets and Systems, pp. 22, variants of other transformation rules like fold- 2005. Accepted for publication. ing, and partial evaluation techniques applied [8] P. Julián, G. Moreno, and J. Penabad. to reductants calculi. We are also planning Unfolding-based Improvements on Fuzzy to extend our unfolding rules to fuzzy logic Logic Programs. In ENTCS. pp. 32, 2005. languages that, instead on weighted rules, be Accepted for publication. based on similarity relations [2, 15]. In this sense, we hope to take advantage of the (par- [9] J.-L. Lassez, M. J. Maher, and K. Mar- tial) correspondences between both kind of riott. Unication Revisited. In Founda- languages analyzed in [13]. tions of Deductive Databases and Logic Programming, pp. 587625, 1988. Acknowledgements We are grateful to Su- sana Muñoz, for providing us free access to [10] R.C.T. Lee. Fuzzy Logic and the Res- worthy material, and the anonymous referees olution Principle. Journal of the ACM, by their suggestive judgments. 19(1):119129, 1972. [11] D. Li and D. Liu. A fuzzy Prolog database References system. John Wiley & Sons, 1990.

[1] M. Alpuente, M. Falaschi, G. Moreno, [12] J. Medina, M. Ojeda, and P. Vojtá². and G. Vidal. Rules + Strategies for Multi-adjoint logic programming with Transforming Lazy Functional Logic Pro- continuous semantics. Proc. of LP- grams. Theoretical Computer Science, NMR'01, LNAI 2173:351364, 2001. 311:479525, 2004. [13] J. Medina, M. Ojeda, and P. Vo- [2] F. Arcelli and F. Formato. Likelog: A jtá². Similarity-based Unication:a multi- logic programming language for exible adjoint approach. Fuzzy Sets and Sys- data retrieval. In Proc. of SAC'99, pp. tems, 146:4362, 2004. 260267. ACM, Articial Intelligence and [14] A. Pettorossi and M. Proietti. Rules and Computational Logic, 1999. Strategies for Transforming Functional [3] J. F. Baldwin, T. P. Martin, and B. W. and Logic Programs. ACM Computing Pilsworth. Fril- Fuzzy and Evidential Surveys, 28(2):360414, 1996. Reasoning in Articial Intelligence. John [15] M.I. Sessa. Approximate reasoning by Wiley & Sons, Inc., 1995. similarity-based SLD resolution. Fuzzy Sets and Systems, 275:389426, 2002. [4] R.M. Burstall and J. Darlington. A Transformation System for Developing [16] H. Tamaki and T. Sato. Unfold/Fold Recursive Programs. Journal of the Transformations of Logic Programs. In ACM, 24(1):4467, 1977. Proc. of ICLP'84, pp. 127139, 1984. [5] S. Guadarrama, S. Muñoz, and [17] P. Vojtá² and L. Paulík. Soundness and C. Vaucheret. Fuzzy Prolog: A new completeness of non-classical extended approach using soft constraints prop- SLD-resolution. In Proc. ELP'96, pp. agation. Fuzzy Sets and Systems, 289301. LNCS 1050, 1996. 144(1):127150, 2004.