Relational Methods in Computer Science Volume 185 || Fork Algebras

  • Upload
    gunther

  • View
    214

  • Download
    1

Embed Size (px)

Citation preview

  • Chapter 4

    Fork Algebras

    Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    In this chapter we present the class of fork algebras, an extension of relation al-gebras with an extra operator called fork. We will present results relating fork algebras both to logic and to computer science. The interpretability of first-order theories as equational theories in fork algebras will provide a tool for expressing program specifications as fork algebra equations. Furthermore, the finite axiomati-zability of this class of algebras will be shown to have deep influence in the process of program development within a relational calculus based on fork algebras.

    4.1 Motivation Let us consider a simple and well-known problem such as testing whether a given string is a palindrome. This problem is known to be non-computable by a finite automaton. It can, however, be computed by a non-deterministic push-down au-tomaton, since push-down automata are capable of storing a copy of their data. Therefore, we can suggest that programs that solve the palindrome problem must be able to duplicate data. A direct solution for our problem could be: making two copies of the input list, reversing one of them, while leaving the other untouched, and, finally, comparing both results. In order to do so, it would be convenient to have a copying operation.

    In a relational framework, the desired copying operation should be regarded as a relation, receiving an object x as input, and two copies of x as output. But what do we mean by "two copies of x"? We do not want a ternary relation, for we wish to retain the input-output character of programs. One way of making the best of both worlds, so to speak, is to turn the output into a pair of form [x, xl. Thus, we will have the following copying relation - which will be denoted by 2 -, described by

    2 = {(u,[u, u]) :u E U} where U is the underlying universe of our relations.

    In order to obtain such pairs as outputs, the domain underlying our relations must be closed under the pairing operation [_, -l, having a structured universe rather than a mere set of points. The structured character of our universe U renders natural the introduction of some structural operations on binary relations, namely fork and direct product.

    C. Brink et al. (eds.), Relational Methods in Computer Science Springer-Verlag/Wien 1997

  • Chapter 4. Fork Algebras

    We call fork of relations Rand S the relation R'V S = {(u, [v, w]) : uRv I\. uSw},

    and define the direct product of relations Rand S as R S = {([u, v), [w, z]) : uRw I\. vSz}.

    55

    (4.1)

    These new operations enable us to describe some interesting behavior, especially when seen from the programming point of view. In particular, if we recall that Iu is the identity relation on the set U, we can now define our copying relation by

    2= Iu'Vlu. Furthermore, since we now have structured objects, it is natural to have oper-

    ations to "unpack" them, i.e., relations 7r and p satisfying

    7r = {([u,v), u) : u, v E U} and p = {([u, v), v) : u, v E U} If we recall that V is the greatest relation, these projections, which decompose

    objects into their components, are convenient shorthand for some special relations, since they can be defined as

    and (4.2) It also happens that the converse of (4.2) holds true, in fact, fork can also be

    defined from projections [Berghammer, Haeberer+ 1993]. It is a school exercise to show that

    (4.3) This result implies that projections could have been chosen, instead of fork, as our primitive operations. While for a category theoretician this approach could seem natural, from the programming viewpoint, fork arises as more natural, in much the same way that data types are defined from constructors, and not from their observers.

    4.2 Proper and abstract fork algebras A second reading of (4.1) shows a notational difference between pairs within relations - between parentheses - and pairs produced by the pairing operation [_, _]. Furthermore, there are conceptual differences between both kinds of ob-jects. While the meaning of pairs (a, b) is the usual one, pairs [a, b] may be different, for their sole purpose is storing data. Since set theoretical pairs fulfill this requirement, they could be natural candidates for replacing [_, _]. However, we are looking for a programming calculus, so we need an abstract counterpart of fork which is suitable for symbolic manipulations. Thus, a finite characteriza-tion of fork is desirable. When choosing set theoretical pairs for [_, _], we come to a blind alley, for, as Nemeti, Sain, Mikulas, and Simon [Mikulas, Sain+ 1992; Sain, Nemeti 1994] have proved, this class of algebras is not finitely axiomatizable.

    From (4.3), it follows that relation algebras containing projection elements allow a definition of fork. One example of such class of algebras is quasiprojective

  • 56 Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    relation algebras [Tarski, Givant 19871. It happens that there are quasiprojective relation algebras on which it is not possible to define a useful pairing operation [_, -1, for the functionality of such operation cannot be guaranteed.

    Fork algebras are extensions of relation algebras by a new binary operator called fork. In their original version, proper fork algebras were made of strings, Le., the operation [_, -1 was interpreted as string concatenation [Veloso, Haeberer 1991]. The definition of projections becomes clumsy under these circumstances, since a projection is required for each position in the strings. Moreover, concatenation is not injective, and thus not useful for coding pairs. As a second-stage improvement, proper fork algebras were made of trees of finite height [Baum, Haeberer+ 1992]. In this case, projections can be easily defined, but the class of algebras as a whole is then non finitely axiomatizable, for an isomorphism can be defined between finite trees and set-theoretical ordered pairs. In the current version of fork algebras, all that is required is that [_, -1 be injective. This characterization of fork algebras allows - as will be shown in Theorem 4.3.15 - finite axiomatizability, and it suffices for obtaining a relational programming calculus as the one to be described in Sect. 4.5.

    In the rest of this section we introduce some basic definitions concerning fork algebras. We shall be interested in both proper1 (or standard) and abstract ver-sions of fork algebras. Much as Boolean algebras provide an abstract theory of set-theoretical operations, fork algebras provide an abstract theory of operations on structured binary relations.

    In order to define the class of proper fork algebras (PFAs), we will first define the class of *PFAs by

    Definition 4.2.1 A *PFA is a two-sorted structure with domains A and U

    (A, U,U,-,0,i, -,Iu, '\7,*) such that

    (A, u, -,0, i, -, Iu) is an algebra of concrete relations with global supremum V,

    *: U X U -+ U is an injective function when restricted to V, R '\7 S = {(x, *( y, z)) : x R y and x S z } .

    Definition 4.2.2 The class of PFAs is defined as Rd *PFA, where Rd takes reducts of similarity type (U, ,0,i, -'!u, '\7), Le., while the universe keeps un-changed, the type U and the operation * are eliminated from the similarity type.

    In Defs. 4.2.1 and 4.2.2, the function * performs the roles of pairing and en-coding of pairs of objects into single objects. As we have mentioned previously, there may be * functions which are far from being set-theoretical pair formation.

    lit is important to remark that proper fork algebras are quasi-concrete structures, since, as was pointed out by Andreka and Nemeti in a private communication, concrete structures must be fully characterized by their underlying domain, which does not happen with proper fork algebras because of the (hidden) operation *.

  • Chapter 4. Fork Algebras 57

    For instance, let us consider a PFA whose universe U is the set {a}. Let us take as V the equivalence relation {( a, a) }. If we define the function *: V -+ U by

    *(a, a) = a, it follows that * is an injective function. We will also see that ({ a}, *) cannot be isomorphic to a structure (A, C, J) for any set A. If such a structure exists, let us have i : {a} -+ A, establishing an isomorphism between both structures. Since i is a homomorphism, it must be i(*(a,a)) = (i(a),i(a)). From the definition of *, we conclude i(a) = (i(a), i(a)), which, accordingly to the set theoretical definition of C, J, is forbidden by the regularity axiom.

    If by FullPFA we denote the subclass of proper fork algebras with universe P( U x U) for some set U, a first characterization of the algebraic structure of PFAs is given by the following theorem, whose proof follows easily from [Jonsson, Tarski 1951)2. Theorem 4.2.3 PFA = SPFullPFA.

    Since first-order definable classes are closed under isomorphism, i.e. the lan-guage of first-order logic does not allow the distinction between isomorphic struc-tures, a further treatment of the class of PFAs is necessary in order to obtain finite axiomatizability. Definition 4.2.4 We define the class of representable fork algebras (RFAs), the candidate for finite axiomatization, as I PFA.

    In the following definition we will present the class of abstract fork algebras (AFAs for short). We will show in Theorem 4.3.15 that this class provides an abstract characterization of RFAs (and thus of PFAs). Definition 4.2.5 An abstract fork algebra is an algebraic structure

    (R, U, -, JL,;, -, ll, V') satisfying the following axioms:

    1. Axioms stating that (R, U, -, JL,;, -, ll) is a relation algebra, 2. RV'S= (R;(llV'lr))n (S;(lrV'll)) , 3. (RV'S);(TV'Q)-=(R;T-)n(S;Q"), 4. (llV'lr)-V' (lrV'll)- !;;::; ll.

    As a definitional extension of AFAs, we introduce relations 1f and p by 1f = (llV'lrf and p = (lrV'llf

    In Theorem 4.3.10 we will show that 1f and p characterize functional relations. Furthermore, it will be shown in Theorem 4.3.15 that axioms 2 to 4 in Definition 4.2.5 induce the existence of an injective function * satisfying the relationship

    and

    2 Along the next theorems, by S we denote the operation of taking subalgebras of a given class of algebras. P takes direct products of algebras in a given class, and I takes isomorphic copies.

  • 58 Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    4.3 Algebraic and metalogical properties of fork algebras It is well known that relation algebras have weak expressive power, since their logical counterpart - denoted by .ex in [Tarski, Givant 1987] (much of which is summarised in Sect. 2.8) - is equipollent in means of expression and proof with a three-variable fragment of first-order predicate logic (see [Tarski, Givant 1987, pp. 76-89] for a detailed proof of this). It is shown in [Tarski, Givant 1987], for instance, that the formula

    \:Ix, y, Z (3u (-,x = u 1\ -'y = u 1\ -,z = u))3 from Tarski's elementary theory of binary relations [Tarski 1941] cannot be ex-pressed by any formula from Tarski's calculus of binary relations. Such lack of expressiveness has an impact in programming, for first-order specifications of pro-grams are not likely to have faithful translations into the calculus of relations. Thus, some modification is necessary. If we examine the formula above and ana-lyze the reasons why it is not expressible, we notice that some information which should be kept about the individual variables is lost. In order to keep that in-formation, an attempt was made at having relations over a structured universe, instead of relations on a plain set. As a consequence of considering a structured universe, this extension of relation algebras has a greater expressive power than that of relation algebras.

    The construction of programs from specifications requires a specification lan-guage, a programming language, and a set of rules that allow us to obtain programs from specifications. The framework we propose in Sect. 4.5 uses first-order logic with equality as its specification language, and the program construction process is carried out within the framework of fork algebras. We immediately notice that both settings are incompatible from the point of view of their languages, hence some theoretical results are required to bridge the gap between them.

    In [Tarski, Givant 1987, 2.4 and 2.5], Tarski and Givant present a way to prove such relationship, when they define the notion of equipollence of two formalisms relative to a common equipollent extension. Definition 4.3.1 We say that two formalisms Fl and F2 (F2 an extension of Fl ) are equipollent in means of expression if, for every sentence X of F l , there exists a

    sentence Y of F2 such that X and Yare equivalent in the formalism F2, and for every sentence Y of F2 there exists a sentence X of Fl such that X and Yare equivalent in the formalism F2 ,

    equipollent in means of proof if, for every set of sentences W of Fl and for every sentence X of Fl we deduce X from W in F2 iff we deduce X from W in Fl.

    Since equipollence is defined between a formalism and an extension of it, for the task of comparing two formalisms where none of them is an extension of the other, a further treatment is required. In order to overcome this difficulty, we will introduce the notion of equipollence of two formal systems relative to a common extension.

    3Notice that this formula has four variables ranging over individuals.

  • Chapter 4. Fork Algebras 59

    Definition 4.3.2 We say that two formalisms F1 and F2 are equipollent in means of expression relative to a formalism F3 if F3 is a common

    extension of F1 and F2 (i.e., the sets of sentences of F1 and F2 are subsets of the set of sentences of F3 ) which is equipollent, in means of expression, with each one of them.

    equipollent in means of proof relative to a formalism F3 if F3 is a common exten-sion of F1 and F2 that is equipollent with each one of them in means of proof.

    Once the notion of equipollence is defined, Theorem 4.3.6 below establishes a close relationship between the equational theory of fork algebras and a large class of theories of first-order logic with equality [Frias, Baum 1995]. This class of first-order theories will be of particular interest, since first-order logic with equality provides an adequate basis for program specification.

    Let us call * the first-order logic of one binary injective function, i.e., the first-order logic language has only one non logical constant which is a binary function symbol standing for an injective function.

    Let us call v = (3, f-v) the formal system whose set of formulas 3 is the set of equations in the language of fork algebras, and inferences are performed by replacing equals by equals according to the axioms of abstract fork algebras.

    Let us call + = (3, f-+) the extension of first-order logic whose set of formulas 3 is defined by: atomic formulas: t1At2 where A is a fork algebra term and t1 and ~ are terms

    built from variables and the binary function symbol *, or equations A = B where both A and B are fork algebra terms.

    formulas: Atomic formulas are formulas, and first-order formulas built up from atomic formulas are formulas.

    Besides the logical axioms, we add the following extralogical ones:

    A sentence stating that * is injective, \Ix, y (x(A n B)y ++ xAy 1\ xBy), \Ix, y (xA-y ++ yAx), \Ix, y (xJLy ++ false), \Ix, y (xlly ++ x = y),

    \Ix, y (x(A U B)y ++ xAy V xBy), \Ix, y (XAiBy ++ 3z (xAz 1\ zBy)), \Ix, y (xAy ++ ...,xAy), \Ix, y (xlry ++ true),

    \Ix, y (xAV By ++ 3u, v (y = *('il, v) 1\ xAu 1\ xBv)). Once we have defined the three formalisms, we will show some theorems relating them.

    Theorem 4.3.3 + is a definitional extension of *, and thus, from [Tarski, Givant 1987] it follows that + and * are equipollent in means of expression and proof.

    Theorem 4.3.3 can be generalized to a language with predicate and function symbols besides the function symbol *. If we simultaneously add new sym-bols 31,32 , ... , 3n , .. to *, and the same amount of binary relation symbols R1, R2 , , Rn , ... in +, the following result holds:

  • 60 Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    Fig. 4.1 Equipollence of C* and "'v relative to C+. Theorem 4.3.4 Given a formula CP(XI, ... , Xk) in C*, there exists a fork term t

  • Chapter 4. Fork Algebras 61

    Definition 4.3.8 7(tl [XI,I,'" ,x1.il == t2[X2,1,'" ,X2,j]) = ((III;J(tl ))V'(Ih;J(t2)));2-;lr, 7(Pn(tIlXI,I,"" XI,;I],"" tm[Xm,I,"" Xm,im ])) = (III ;J(tl)V' V'IIm ;J(tm)) ;Pn, 7(-,a[XI, ... , Xn]) = 7(a), 7( a[XI,I' ... ,Xl,;] V ,8[X2,1' ... ,X2,j]) = III; 7( a) U II2 ; 7(,8), 7( a[XI,I' ... , xd /\ ,8[X2,1' ... , X2,j]) = III; 7( a) n II2 ; 7(,8), 7(3x (a[x, Xl,"" Xn])) = II; ;7(a), 7(\iX (a[x, Xl,"" Xn])) = III \7(a).

    In the definitions 4.3.7 and 4.3.8, the symbols II; stand for terms based on the relations 7r and p, and are meant to project the values for the variables in each subformula. In order to clarify this point, let us consider the following example. Example 4.3.9 Let us have some finite axiomatization of the theory of lists, i.e., a finite set of first-order formulas T characterizing the relevant properties of lists. Let

  • 62 Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    Theorem 4.3.10 The objects (lIV'lr)- and (lrV'II)- are functional. Moreover, the equation (lIV'lr)-- ;(lrV'II)- = lr holds in every AFA.

    This theorem establishes that the relations (lIV'lr)- and (lrV'II)- satisfy the definition of quasiprojections as given in [Tarski, Givant 1987, p. 96]. We will call (lIV'lr)- the first quasiprojection and (lrV'lIf the second quasiprojection of an AFA. We will denote the first quasiprojection by 7r and the second by p. If we recall that quasiprojective relation algebras (QRA for short) are relation algebras with a couple of functional relations A and B satisfying A - ; B = lr, from Theorem 4.3.10 we immediately obtain the following result. Theorem 4.3.11 The relation algebra reduct of any AFA is a QRA. If we want to show that the axioms characterizing AFAs offer an axiomatization of PFAs, we can proceed as follows. It is a standard exercise to show that all AFAs' axioms hold in the class of PFAs. Now, all we have to do is prove a representation theorem, asserting that every AFA is isomorphic to a PFA. Both results together guarantee that AFAs and RFAs are the same class of algebras.

    By checking that the axioms characterizing AFAs are satisfied in any PFA, we establish the following theorem. Theorem 4.3.12 RFA ~ AFA.

    Following with the proof of the finitization theorem, it remains to prove the other inclusion, i.e., every AFA is a PFA. This inclusion will be obtained as an instance of the following theorem.

    In order to complete the proof of the finitization theorem, we must now prove the other inclusion, i.e., every AFA is a RFA. This inclusion will be obtained as an instance of the theorem below. Theorem 4.3.13 Consider A E AFA with RA reduct A'. Given an RA homo-morphism 1i : A' -+ B into a proper relation algebra B, there is an expansion of B to B* E PFA so that 1i : A -+ B* is an AFA homomorphism. Proof: The algebra B consists of relations over a set U, with unit element V ~ U x U.

    So

    Since the quasiprojections 7r, PEA', we have 1i (7r), 1i (p) E B. According to Theorem 4.3.10, A' satisfies

    7r - ; P = lr, 7r - ; 7r ~ II and p - ; p ~ II.

    1i(7rf;1i(p) = 1i(lr) = V, and "l-l(7r) and 1i(p) are functional. We define the relation F ~ (U x U) x U by

    ((a, b), c) E F ( c, a) E 1i ( 7r) and (c, b) E 1i (p ). By making some easy calculations with concrete relations, we prove that V ~ damF, F is functional on V, and F is injective on V. Hence, the restriction of F to V renders a well defined injective function *: V -+ U such that

    *( a, b) = c ( c, a) E 1i ( 7r) and (c, b) E 1i (p ).

  • Chapter 4. Fork Algebras 63

    We expand B to a PFA B* by

    R'V 3 = {(x, *(y, z)) : (x, Y) E R, (x, z) E 3, and (y, z) E V}. In order to show that 'V is well defined, we leave the proving that

    (4.4) as an exercise.

    We now wish to show that 1- is an AFA homomorphism from A into B*, i.e., that 1- preserves fork.

    Consider R,3 EA. By Ax. 2 in Definition 4.2.5 R'V 3 = (R; 1f~) n (3; p~). Therefore,

    Since 1- : A' -+ B is an RA homomorphism, we have

    1-((R; 7r~) n (3; p~)) = (1-(R);1-(7r)~) n (1- (3);1- (pf) which by 4.4 equals 1- (R) 'V 1- (3). Theorem 4.3.14 Every AFA is isomorphic to some PFA.

    D

    Proof: Given A E AFA, its RA reduct A' is a ORA by Theorem 4.3.11. Since, by [Tarski, Givant 1987, p. 242], every ORA is a representable relation algebra, we have an RA isomorphism 1- : A' -+ B onto a proper relation algebra B.

    By Theorem 4.3.13, B can be expanded to a PFA B*, so that 1- : A -+ B* is an AFA isomorphism. D

    Summarizing the results presented in theorems 4.3.12 and 4.3.14, we prove the main result concerning the finitization problem.

    Theorem 4.3.15 AFA = RFA.

    Proof: By Theorem 4.3.14, AFA~ I PFA= RFA, and by Theorem 4.3.12, RFA ~ AFA. D

    Figure 4.2, inspired by the finitization theorem, shows that its algebraic portion (AFA A PFA), which reflects the theorem's thesis, induces its logic portion (Th(AFA) ( ==) Th(PFA)), which reflects the elementary equivalence between both theories. Moreover, the arrow AFA --+ Th(PFA) shows the soundness of our axiomatization, and the arrow PFA --+ Th(AFA) reflects its completeness. Theorem 4.3.16 Th(AFA) = Th(PFA), i.e., AFAs and PFAs are elementarily equivalent classes of algebras.

    It is not difficult to show that the theory of AFAs is incomplete. This can be proved by taking two AFA's Al and A2 such that Th(AI) f. Th(A2). Let us consider Al to be an atomless PFA, and A2 one with atoms. The formula

    =:Ix (0 f. x 1\ Vy(0 ~ Y ~ x -+ y = x)) clearly holds for A2, while it is false for AI, thus stating the next theorem.

  • 64 Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    AFA ..... ' ----..... , PFA

    Th(AFA) ..... ' ----, Th(PFA) =

    Fig. 4.2 Consequences of the finitization theorem.

    Theorem 4.3.17 Th(AFA) is incomplete, i.e., there are sentences in Th(AFA) which are neither true nor false.

    The next result we will present shows that the equational theory of AFAs is undecidable, i.e., there is no finitary method or algorithm informing wether or not a given equation is provable from the axioms of AFAs. From the programming calculus viewpoint, this result shows that program derivations require the use of heuristics and rationales (experiences from previous derivations) to be applied by a user with knowledge about the methodology.

    Theorem 4.3.18 The equational and first-order theories of AFA's are undecid-able.

    Proof: Firstly, we will prove that the equational theory of AFA's is undecidable. As a consequence of the equipollence in means of proof between * and v, for every sentence

  • Chapter 4. Fork Algebras 65

    We shall see that this notion of fork model is directly related to the notion of model in first-order logic. We know from Theorem 4.3.4 that every satisfiable first-order formula can be translated as an AFA term that admits its own fork model. Now we will see that the converse of this proposition also holds. Theorem 4.3.20 If

  • 66 Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    1. (R V' S) ; 7r = R n (S ; lr), 2. (RV'S);p=Sn(R;lr), 3. ((RV'S);7r)V'((RV'S);p)=RV'S, 4. damR = (ITV' R); 7r, 5. (RV'S);7r=damS;R, 6. (R V' S) ; P = dam R ; S , 7. U ~ R and V ~ S implies U V' V ~ R V' S , 8. R;(SV'T)~(R;S)V'(R;T); 9. 2~;(lrV'lr) ~ lrlr,

    10. If F is a functional relation, then F;( R V' S) = (F; R) V' (F; S), 11. dam(R V' S) = damR n damS, 12. If T = T ;(IT IT), T; 7r ~ (R V' S) ; 7r and T; p ~ (R V' S) ; P then T ~

    RV'S, 13. 2; 7r = 2; p = IT, 14. dam7r = damp = ITIT, 15. 2 is a functional relation, 16. 2;(RS) = RV' S, 17. 2 is an injective relation, 18. If R #- JL, and R ~ lrV'lr then R; 7r #- JL, and r; p #- JL, 19. If RV' S #- JL, then R #- JL and S #- JL, 20. (RV'S);(TQ)=(R;T)V'(S;Q), 21. (RS);(UV)=(R;U)(S;V), 22. (R S) ~ = (R ~ S~), 23. mn(RV' S) ~ mn(RS) = mnRmnS, 24. (RV'S)n(UV'V)=(Rn U)V'(Sn V), 25. (RS)n(UV)=(Rn U)(Sn V), 26. (RS)nIT=(RS)n(ITIT), 27. If R, S, T, U are distinct of JL, and R S = T U, then R = T and

    S = U, 28. (R V' S) ; 7r ; T = (( R ; T) V' S) ; 7r and (R V' S) ; p; T = (R V' (S ; T)) ; p , 29. damR ~ damS =? (RV'S);7r = R and damS C damR =?

    (RV'S);p=S, 30. If R ~ Sand T ~ U then (R T) ~ (S U).

    4.5 A fork-algebraic programming calculus A programming calculus can be viewed as a set of rules to obtain programs from specifications in a systematic way.

  • Chapter 4. Fork Algebras 67

    A very interesting and popular approach is the one based on functional pro-gramming languages [Bird 1990]. In these functional frameworks, specifications and programs are expressed in the same language, and transformation rules are defined in a suitable, frequently ad-hoc, metalanguage. A drawback of functional settings, however, is the lack of expressiveness of their specification languages, which are confined to functional expressions. Since these functional expressions can be viewed as programs (probably inefficient ones), in order to specify a prob-lem in a functional framework, we must have in advance at least one algorithm that solves it.

    On the other hand, relational calculi have a more expressive specification lan-guage (due to the existence of the converse and the complement of relations), allowing for more declarative specifications. However, choosing a relational frame-work does not guarantee that a calculus is totally adequate. These frameworks, as the one proposed by Moller in [Moller 1991b], despite having a powerful specifica-tion language, also have some methodological drawbacks. The process of program derivation seeks to use only abstract properties of relations, on which variables ranging over individuals (often called dummy variables) are avoided. Neverthe-less, since there is no complete set of abstract rules capturing all the information of the relational (semantical) framework, the process goes back and forth between abstract and concrete properties of relations.

    When using fork algebras as a programming calculus [Baum, Frias+ 1996; Frias, Aguayo 1994; Frias, Aguayo+ 1993; Frias, Gordillo 1995; Haeberer, Baum+ 1994; Haeberer, Veloso 1991], we have (as shown in Theorem 4.3.6), the expressiveness of first-order logic. Furthermore, as the arrow PFA ---t Th(AFA) from Fig. 4.2 shows, the axioms of AFA's provide a complete characterization of PFA's. These results enable us to use first-order logic as a specification language and certain fork algebra equations as programs, and to reason about the properties of specifications and programs within the theory. Moreover, Theorem 4.3.16, which establishes the elementary equivalence between Th(AFA) and Th(PFA), allows the formulation of strategies and heuristics of the program construction process in the shape of first-order formulas about relations.

    A very popular strategy used in the solution of problems and in the design of programs is Divide and Conquer (D& C). Its basic idea is to decompose a problem into two or more subproblems and then combine their solutions to solve the original problem. Divide and Conquer has been extensively studied and several variants to it have been proposed, most of them regarding the type of subproblems into which the original problem is decomposed. Many of the best known algorithms used to solve classic programming problems (sorting, searching, etc.) stem from the application of recursive Divide and Conquer principle (i.e., the original problem itself becomes a subproblem for even simpler data). Some examples of this are QuickSort and MergeSort for the problem of sorting, and BinarySearch for the problem of searching. Actually, Divide and Conquer is a combination of two simpler strategies, namely, Case Analysis ( C_A) and Recomposition. The former's idea is to express a problem as a sum of other problems, usually by decomposing its domain. Whereas the technique of Recomposition decomposes complex data

  • 68 Armando Haeberer, Marcelo Frias, Gabriel Baum, Paulo Veloso

    into simpler pieces, where each piece will be processed by some subalgorithm. The results arising from those subalgorithms are later composed into a single output.

    In the context of our theory, strategies can be expressed as first-order formulas over relations. In that way, for example, a formula that characterizes the applica-tion of Case Analysis will state that it is possible to decompose a problem into a number of subproblems PI, ... , P" over mutually disjoint domains. Formally, the strategy can be represented by the formula

    C_A(P, PI' ... ' P,,) +-t A domP; n domPj = JL /\ P = U Pi l~i ... ' Q", Join) +-t P = Split;( QI ... Q,,); Join, where the relations Split and Join stand for programs so that the former effectively decomposes the data, and the latter combines the results of QI' ... ' Q" in order to provide a solution for P.

    By joining the strategies of Recomposition and Trivialization, we obtain the formalization of Divide and Conquer

    D&C(P, Po, Split, QI' ... ' Q", Join) +-t 3Q (Trivialization(P, Po, Q) /\ Recomposition( Q, Split, QI, ... , Q", Join)),

    where the original program P may appear inside some of the terms Ql> ... ' Q", but does not affect the term Po.

    Each strategy comes with an explanation about how to construct a program solving the original problem. It is easy to see how the previously given strategies induce the structure of the programs. For example, it is clear from the definition of Case Analysis that whenever C_A(P, Po, Pt} holds, we can infer that P = POuPI , thus rendering a program (equation) ofthe desired shape, and solving the problem

  • Chapter 4. Fork Algebras 69

    P. In the same way, when D&C(P, Po, Split, Ql, ... , Qk, Join) holds, we have a program of the shape P = Po U Split;( Ql ... Qk); Join solving P.

    Once we have shown how to express strategies as first-order relational formulas, we are ready to explain the process of program construction. The derivation of a program (ground equation with algorithmic operators), using strategies as the ones shown above, consists essentially in:

    1. Providing a specification for P in the form of equations or first-order formu-las. These specifications define the theory of P (Th(P)). A possible way to obtain this specification could be using the translation T.

    2. Selecting a strategy. This is a design decision which will define the general form of the solution we are seeking. A strategy for solving a problem P, would be a formula S(P, R1 , .. , Rk ) as the ones shown above, together with the explanation about how to construct a program P = T from it.

    3. Performing calculations in fork algebras, so that we find ground terms Ql, ... , Qk such that Th(AFA), Th(P) f- S(P, Ql, ... , Qk).

    4. Iterating steps 2 and 3, choosing new strategies, not only for P, but also for any subterm of Ql, ... , Qk.

    When we decide to stop applying the steps above, the methodology guarantees we have found a term T (according to the strategies applied) satisfying

    Th(AFA), Th(P), S(P, Ql, ... , Qk) f- P = T. If we now interpret the equation P = T in a programming language (for

    example, the relational product ; is viewed as sequential composition of programs, and recursive equations as loops), we will obtain an algorithm for solving the problem according to the strategies chosen.

    4.6 Conclusion In this chapter we have shown some of the applicatiorlS of fork algebras in logic and computer science, as well as theoretical results. We have also presented a programming calculus based on fork algebras. This calculus, because of the finite axiomatizability of fork algebras, and the interpretability of first-order theories as equational theories in fork algebras has clear advantages over many other func-tional and relational calculi. These advantages stem from the fact that problem specifications have a natural representation in fork algebras, and the fact that a finite characterization of the calculi simplifies program manipulation.

    /ColorImageDict > /JPEG2000ColorACSImageDict > /JPEG2000ColorImageDict > /AntiAliasGrayImages false /CropGrayImages true /GrayImageMinResolution 150 /GrayImageMinResolutionPolicy /OK /DownsampleGrayImages true /GrayImageDownsampleType /Bicubic /GrayImageResolution 150 /GrayImageDepth -1 /GrayImageMinDownsampleDepth 2 /GrayImageDownsampleThreshold 1.50000 /EncodeGrayImages true /GrayImageFilter /DCTEncode /AutoFilterGrayImages true /GrayImageAutoFilterStrategy /JPEG /GrayACSImageDict > /GrayImageDict > /JPEG2000GrayACSImageDict > /JPEG2000GrayImageDict > /AntiAliasMonoImages false /CropMonoImages true /MonoImageMinResolution 1200 /MonoImageMinResolutionPolicy /OK /DownsampleMonoImages true /MonoImageDownsampleType /Bicubic /MonoImageResolution 600 /MonoImageDepth -1 /MonoImageDownsampleThreshold 1.50000 /EncodeMonoImages true /MonoImageFilter /CCITTFaxEncode /MonoImageDict > /AllowPSXObjects false /CheckCompliance [ /None ] /PDFX1aCheck false /PDFX3Check false /PDFXCompliantPDFOnly false /PDFXNoTrimBoxError true /PDFXTrimBoxToMediaBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXSetBleedBoxToMediaBox true /PDFXBleedBoxToTrimBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXOutputIntentProfile (None) /PDFXOutputConditionIdentifier () /PDFXOutputCondition () /PDFXRegistryName () /PDFXTrapped /False

    /CreateJDFFile false /Description >>> setdistillerparams> setpagedevice