When Will Deforestation Stop? A. B. Ferguson and Philip Wadler. Abstract

Size: px
Start display at page:

Download "When Will Deforestation Stop? A. B. Ferguson and Philip Wadler. Abstract"

Transcription

1 When Will Deforestation Stop? A. B. Ferguson and Philip Wadler Abstract A compositional style of programming is often advocated by functional programmers. However, there is a certain eciency penalty involved in creating the requisite intermediate structures. Deforestation is a program transformation technique which removes such structures for some such programs. This paper is an investigation into the issues of termination of the transformation process. 1 Introduction Function composition is the basis of a style of programming practiced outside, as well as within the normal bounds of functional programming. The notion of constructing programs from a set of simple basic operations, and a collection of combining forms (sometimes richer than simple composition) is found in the imperative language APL [Ive62], is central to the strict applicative language FP [Bac77] and its successors, and is even present in the Unix shell P [Bou78], as well as in languages such as Miranda [Tur85]. n The familiar example i=1 i2 may be expressed as in APL, or similarly in Backus's FP as or (somewhat articially) as a Unix pipe: k +=(square( n (1))) (=+) ( square) (upto1 ) upto 1 n squares sum Indeed, even Prolog, a language whose syntax is at rst sight wholely uncompositional lends itself to this style: our example can be expressed sumnsquares (N ; S) :?upto (1; N ; L1); squarelist (L1 ; L2); sum (L2 ; S) Our concern is not with the presence or absence of composition operators per se, but with a programming style which treats a problem as a collection of essentially separable sub-problems to be combined to form a solution, rather than a monolithic entity whose various aspects are inextricably intertwined. Lazy functional programming may be seen as the epitome of this paradigm in many ways, and it is with this particular area that this paper will be concerned. The semantics 1

2 of a lazy language allow compositional programs to include non-terminating components, and still terminate themselves. For example, we may obtain a list of the rst n primes from one function to compute all the primes, and another to select the desired elements. Operationally, the desired piecewise generation of the linking structures is maintained by the lazy evaluation strategy (which is important due to considerations of space eciency). Our example may be written in this style as (sum map square upto 1) n in which each of the key steps (generate the rst n integers, square each, sum the result) is captured as a function, and composition is used to `glue' them together as required. Although this solution is satisfactory in terms of being correct, operationally reasonable, and clearly expressed, it has one disadvantage over a non-compositional solution: it is less ecient, due to the necessity of having to build, and immediately destroy, two intermediate lists ([1; 2; : : : ; n] and [1; 4; : : : ; n 2 ]). A program which recties this fault is: sumnsquares 0 1 n where sumnsquares a m n = if m > n then a else sumnsquares (a + square m) (m + 1) n This has the same semantics and operational behaviour, but is more ecient. Our modied solution performs exactly the same numerical computations, but eliminates all the list operations present in the original. However, it has the disadvantage of being considerably less clear. The ideal solution would be to allow the programmer to write the former version, but have an automated assistant produce the latter. If a suitably simple characterisation of a set of sucient preconditions can be arrived at, the details of the transformation can be hidden entirely inside a compiler, with the programmer able to reason about the eciency of the resulting code independently if this becomes necessary. This is what was done in this paper's immediate ancestor [Wad87b]; here we will present a reformulation of some of the same material, which will facilitate our main result, concerning termination of the transformation. We shall present the following: Section 2.1 { The language used Section 2.2 { Treeless Form : a description of a form of program which is free from intermediate structures Section 2.3 { Restricted Treeless Form : a subset of the above Section 2.4 { The Deforestation Theorem : a condition sucient to guarantee the desired behaviour of the algorithm Section 2.5 { The Deforestation Algorithm : an algorithm to produce a treeless program from treeless components 2

3 Section 2.6 { Termination : a proof Section 3 { Related Work Section 4 { Conclusion 2 An Alternative View of the Deforestation Algorithm 2.1 Language Consider a language with terms t ::= v (variable) j c t1 : : : t n (constructor) j f t1 : : : t n (function application) j g t0 : : : t n (function with pattern match) and function denitions or f v1 : : : v n = t g p1 v1 : : : v n =. t1 g p m v1 : : : v n = t m where p ::= c v1 : : : v k This describes a rst order language, with functions possibly involving the matching of a single simple pattern (i.e. only one constructor deep). Compilation to such a form requires only well known techniques, being essentially equivalent to compiling to simple case expressions [Aug85, Wad87a]. (The key step is replacing a pattern match several constructors deep with a corresponding number of simple pattern matches, introducing appropriate new functions.) The intended semantics is the usual normal order reduction of the lambda calculus. Pattern matching, however, is strict: when a pattern matching function is applied, the rst argument is evaluated to head normal form before the body is entered. Figure 1 shows some sample denitions. 2.2 Treeless Form A term is treeless if it is linear (no variable may appear more than once) and conforms to the following grammar: tt ::= v j c tt1 : : : tt n (constructors applied to anything treeless) j f v1 : : : v n (only variables occur as arguments) j g v0 : : : v n (pattern match only on a variable) 3

4 ip (Leaf n) = Leaf n ip (Branch t1 t2) = Branch (ip t2 ) (ip t1 ) seconds Nil = Nil seconds (Cons x xs) = Cons x (seconds 0 xs) seconds 0 Nil = Nil seconds 0 (Cons x xs) = seconds xs thirds Nil = Nil thirds (Cons x xs) = Cons x (thirds 0 xs) thirds 0 Nil = Nil thirds 0 (Cons x xs) = thirds 00 xs thirds 00 Nil = Nil thirds 00 (Cons x xs) = thirds xs Figure 1: Sample denitions where each f or g is a treeless function denition: that is, the rhs of the denition of an f, and each rhs of the denition of a g, is a restricted treeless term. The linearity restriction is required so as to ensure that functions may be unfolded without risk of duplicating work. The grammar requires that terms be at most a single function deep, and constrains functions (and hence case analyses) to variables only. This prevents a previously computed value being passed to a function, and so there is no possibility of the function examining such a value, thus having the eect of disallowing intermediate structures. Note that treelessness is an intensional, not an extensional, property of a function: for any given treeless function denition, a non-treeless version may be contrived which is equivalent in all respects save eciency; unfortunately the converse is not true. For example, atten 1 and atten 2 (gure 2) are respectively non-treeless and treeless denitions of the same function. (Note, however that there is little dierence in terms of actual eciency; the apparent intermediate structure in the rst is never actually examined, but instead is incorporated directly into the result.) Functions for which no treeless denitions exist include reverse, because of the need for a structure to accumulate the segment of the list reversed so far, but not available for output; and attening a tree into a list of its nodes, this being due to the particular nature of the treeless form we require, which means that although the denition tatten (Leaf n) l = Cons n l tatten (Branch t1 t2 ) l = tatten t1 (tatten t2 l) involves no data structure operations other than those for input and output, it is not considered treeless. 4

5 atten 1 Nil = Nil atten 1 (Cons xs xss) = append xs (atten 1 xss) atten 2 Nil = Nil atten 2 (Cons xs xss) = atten 0 2 xs xss atten 0 2 Nil xss = atten 2 xss atten 0 2 (Cons x xs) xss = Cons x (atten 0 2 xs xss) Figure 2: Alternative denitions of atten This is similarly true for the linearity requirement: for example the term x + x is non-treeless, and x 2 a treeless equivalent. Clearly terms such as copy x = Pair x x have no linear equivalents. 2.3 Restricted Treeless Form In order to present our main result, we will make a number of further restrictions on the terms we will consider as terms suitable for deforestation. These seem somewhat arbitrary at rst, and are indeed motivated by technical considerations pertaining to the proof, but fortunately none involve any actual loss of power. We are at present unsure as to whether any of the restrictions are important in practice; some may be necessary preconditions for termination of our transformation, or it may transpire that they are purely artifacts of the formalism we have chosen. Firstly, we introduce the notion of a restricted treeless term: rtt ::= rtt 0 j rtt 0 ::= v j j c rtt 0 1 : : : rtt 0 n f v1 : : : v n g v0 : : : v n where right hand sides of the denition of each f or g are restricted treeless terms. This denes the subset of treeless terms containing only a single constructor (with that being outermost, as already required). In a sense, this is a symmetrical restriction to the requirement present in the original grammar that patterns be only one constructor deep, in the respect that when a function (pattern-matching or otherwise) is nested inside a pattern-matching function, constructors are `consumed' no more slowly than they are `produced'. It is easy to see that this restriction involves no loss of generality, as any term may be made to conform to it by introducing a new function denition for each sub-term starting with a constructor which appears where one is disallowed (that is, in t 0 terms of the grammar). Also, rather than attempting to treat general terms we shall consider only function terms (that is, those with no constructors) as being suitable input for our deforester, as 5

6 follows: ft ::= v j f ft 1 : : : ft n j g ft 0 : : : ft n This restriction clearly also involves no loss of generality: any term admitted by the more general schema can be converted to such a form by replacing each constructor with a suitably dened function. 2.4 The Deforestation Theorem Theorem: A linear term comprised of functions with treeless denitions may be eectively transformed to an equivalent term, in treeless form, which will be no less ecient. We shall not prove our claim about eciency, but instead appeal to the informal argument that we will produce a program no more folded than the original, and that the linearity condition ensures that where we unfold, we do not worsen eciency. Treelessness is seen rather easily by inspection of our transformation rules. We shall present a proof about the size of terms encountered by the transformer, and then argue that this is sucient to ensure termination. In fact, the transformed term will be strictly more ecient, provided the original required an intermediate structure. This is in the sense of a `real' intermediate structure, one which is built and then destroyed internally, as opposed to one which is constructed, and then passed to a function which does not re-examine it. For example, atten 1 has already been cited as a non-treeless function denition which is no less ecient than its treeless equivalent. Our theorem requires that all the constituent functions already have treeless denitions: this precludes the deforestation of recursive or mutually recursive function denitions. Note that if we remove the restriction on linearity, a weaker property still holds: terms may still be eectively transformed, but the resulting terms may be less ecient, and may of course themselves be non-linear. Examples: ip (ip t) and seconds (thirds l) are suitable candidates for transformation, according to the preconditions of the theorem; their deforested equivalents are shown in gure 3. The second example illustrates one questionable feature of deforestation: the resulting program can be substantially larger than the original. Here the treeless program is proportional in size to the product of the sizes of the original functions (including the auxiliary functions for each). If we were to transform a similar program consisting of n nested applications of the function selecting every m th element of a list (a program of size proportional to n + m), the resultant program would be of size proportional to m n. This exponential growth seems to suggest that programs might become unacceptably large after being deforested: we consider this to be unlikely in practise, and expect only modest growth in program size, which would not constitute any particular drawback. (This aspect of deforestation bears a passing resemblance to ML typechecking, which can be shown to be of PSPACE-complete time complexity, but which is not in practice found to 6

7 ip (ip t) transforms to: seconds (thirds l) transforms to: g t where g (Leaf n) = Leaf n g (Branch t1 t2 ) = Branch (g t1) (g t2 ) g1 l where g1 Nil = Nil g1 (Cons x xs) = Cons x (g2 xs) g2 Nil = Nil g2 (Cons x xs) = g3 xs g3 Nil = Nil g3 (Cons x xs) = g4 xs g4 Nil = Nil g4 (Cons x xs) = g5 xs g5 Nil = Nil g5 (Cons x xs) = g6 xs g6 Nil = Nil g6 (Cons x xs) = g1 xs Figure 3: Results of transforming two terms be at all inecient. Our problem is of course worse: the time complexity of deforestation is explicitly exponential!) It is an open question as to how often we may expect to nd terms suitable for transformation; it is certainly the case that most programs of signicant size will have at least portions which are non-linear, or where a recursive function is dened by a compositional term, preventing us from synthesising treeless denitions for such components. It is hoped that linear, non-recursive sub-terms will prove to be suciently common to allow the transformation of a signicant proportion of the terms present in a program. 2.5 The Deforestation Algorithm We will now give a set of transformation rules which will convert a term into a treeless equivalent. We shall assume that the term satises the preconditions of the deforestation theorem; that is, it consists of a linear composition of treeless functions. This requires of a practical transformer that treeless denitions be produced for all a term's components beforehand, and of course if the term is recursive, it will not be possible to do so. 7

8 T [[v]] = v (1) T [[c t1 : : : t n ]] = c (T [[t1]]) : : :(T [[t n ]]) (2) T [[ f t1 : : : t n ]] = T [[ t[t1=v1; : : : ; t n =v n ] ]] where f is dened by (3) f v1 : : : v n = t T [[ g (c t 0 1 : : : t 0 m) t1 : : : t n ]] = T [[ t[t1=v1; : : : ; t n =v n ; t 0 1=u1; : : : t 0 m=u m ] ]] (4) where g has a dening equation g (c u1 : : : u m ) v1 : : : v n = t T [[ g v0t1 : : : t n ]] = let g 0 p1v 0 1 : : : v 0 m = T [[ g p1t1 : : : t n ]]. g 0 p m v 0 1 : : : v 0 m = T [[ g p m t1 : : : t n ]] in g 0 v0v 0 1 : : : v 0 m where g is dened by g p1v1 : : : v n = t 0 1. g p m v1 : : : v n = t 0 m and v 0 1 : : : v 0 m = vars ( g v0t1 : : : t n )? v0 (5) For correctness, we must have that Figure 4: Transformation Rules T [[t]] = t 0 ) E[[t]] = E[[t 0 ]] where E[[t]] denotes the semantic function on terms, and T [[t]] denotes the transformation: that is, transformed term and original must compute the same value. Use t to denote a context of nested pattern matching functions, as follows: t ::= t j g ( t ) t1 : : : t n where g is some pattern matching function. For example, the expression ip (ip t) is such a context for the term t (for the given denition of ip), as is t itself. The rules for the transformation are shown in gure 4. The transformation rules essentially use case analysis on the leftmost syntactic construct which is not a pattern-matching function: there are two cases for a leftmost variable, depending on whether it occurs at the outermost level or not, and likewise for constructors; only a single case for a non pattern-matching function is required when that occurs 8

9 leftmost. An innite chain of pattern matches is not possible, the input terms being nite, so a construct other than a pattern-matching function must occur somewhere. Observe rst of all that the cases given are exhaustive, since an outermost variable or constructor is covered by the rst two rules; a variable or constructor nested inside any number of pattern matching functions is covered by the last two; and a non-pattern matching function, nested or otherwise, is covered by rule (3). Secondly we note that the transformation preserves equivalence: the rst two rules do not alter the basic form of the expression; the third and fourth are simply unfold steps; and the last performs instantiation of a pattern match, by transforming the expression with each of the possible patterns in turn, and generating a new function to perform case analysis on the instantiated variable. This last possibility is valid due to the strictness of the pattern matching, which ensures that a chain of pattern matches will necessarily require matching against the innermost pattern. Also, everything produced by this transformation will be in treeless form, since each rule rhs is treeless under the assumption that the recursive calls result in treeless terms: in rule (1) the result is a variable; in rule (2) a constructor is applied to the results of further transformation, and so will be treeless provided the transformed components are; the unfold steps give terms to be further transformed en masse; the fth rule results in a function call with all-variable arguments, with rhs's being the results of further transformation. Note that although the inputs are in restricted treeless form, the output is not: it is a general treeless term. This is because our rule for dealing with constructors may well emit several consecutively; we could alter the rules to prevent this, but this seems unnecessary (and possibly undesirable, since this would result in a more folded, and hence less ecient term). However this does mean that when we are recursively transforming a term, by rst deforesting its components, we must convert our result to the restricted form, as described above. The result of this transformation, is however not necessarily nite. For example, consider the transformation of the term ip (ip t), shown in gure 5. The transformation rules are applied until we obtain two sub-problems which are renamings of the original. What we should do now is fold, replacing each instance of the terms to be transformed with a call to the function already introduced. In general, however, it is necessary to introduce new functions, as the recurring term may not coincide with a pattern-matching function already introduced, so our policy will be to introduce new function denitions for terms which appear more than once, and use these to fold the potentially innite term. Clearly it is not possible to do this with the transformation rules as they stand, as a function to fold the recurring terms as they are output would not be computable, requiring as it would equality over innite and non-total objects. The problem is that in unfolding we have thrown away the information we require to eectively compare terms. We can however retain this information by labelling each unfold with the corresponding function call, as shown in gure 6. We now introduce the function shown in gure 7. (Note that the construct e as p is used to refer to an argument both as a meta-variable, and by pattern-matching.) The function F folds the potentially innite term output by the labelled transformation rules to a nite version by noting the terms already encountered by the transformer, in 9

10 T [[ip (ip t)]] = g t where g (Leaf n) = T [[ip (ip (Leaf n))]] g (Branch t1 t2) = T [[ip (ip (Branch t1 t2))]] (By 5) T [[ip (ip (Leaf n))]] = T [[ip (Leaf n)]] (By 4) = T [[Leaf n]] (By 4) = Leaf n (By 2, 1) T [[ip (ip (Branch t1 t2 ))]] = T [[ip (Branch (ip t2 ) (ip t1 ))]] (By 4) = T [[Branch (ip (ip t1 )) (ip (ip t2 ))]] (By 4) = Branch (T [[ip (ip t1 )]]) (T [[ip (ip t2 )]]) (By 2) T [[ip (ip t)]] = g t where g (Leaf n) = Leaf n g (Branch t1 t2 ) = Branch (g t1 ) (g t2 ) Figure 5: Steps in the transformation of ip (ip t) the form of a set of function denitions. When re-encountering (a renaming of) such a term, we fold this subsequent occurrence with the appropriate denition. To see that this function preserves treelessness, note that each of the equation rhs's is a (general) treeless term under the assumption that each recursive call yields a treeless result. While this corresponds reasonably closely to the basic notion of folding outlined initially, note that this function is based on weak intensional equality over terms, rather than strong extensional equality. That is, we identify terms when they are syntactically equivalent, rather than attempting to see if they compute the same result. Whenever our original term satises the preconditions of the Deforestation Theorem, we will be able to produce a term folded to be nite, and the folding process may terminate even if this is not the case. For instance, the function atten 1 is not a simple composition of treeless terms, but here the Deforestation Algorithm does terminate; when this occurs for linear programs, the result will still be treeless, by the above argument. Termination will not occur in general: certainly for any linear program with no treeless equivalent, our transformation will be non-terminating. If a program is non-linear, but conforms to our grammar for transformable terms, the transformation will terminate, but the output may not be treeless, as well as possibly less ecient. The test for inclusion in the set of denitions, d 2 R ds, uses the normal rules for set membership, but based on equality up to renaming of bound variables. x 2 R fg ^= False (f v1 : : : v n = t) 2 R ff 0 v 0 1 : : : v 0 m = t 0 g ^= False; if f 6= f 0 (f v1 : : : v n = t) 2 R ff v 0 1 : : : v 0 n = t 0 g ^= t = [v1=v 0 1; : : : ; v n =v 0 n]t 0 x 2 R a [ b ^= (x 2 R a) _ (x 2 R b) 10

11 T [[v]] = v (1) T [[c t1 : : : t n ]] = c (T [[t1]]) : : :(T [[t n ]]) (2) T [[e as f t1 : : : t n ]] = Label e T [[ t[t1=v1; : : : ; t n =v n ] ]] where f is dened by (3) f v1 : : : v n = t T [[e as g (c t 0 1 : : : t 0 m) t1 : : : t n ]] = Label e T [[ t[t1=v1; : : : ; t n =v n ; t 0 1=u1; : : : t 0 m=u m ] ]] (4) where g has a dening equation g (c u1 : : : u m ) v1 : : : v n = t T [[ g v0t1 : : : t n ]] = let g 0 p1v 0 1 : : : v 0 m = T [[ g p1t1 : : : t n ]]. g 0 p m v 0 1 : : : v 0 m = T [[ g p m t1 : : : t n ]] in g 0 v0v 0 1 : : : v 0 m where g is dened by g p1v1 : : : v n = t 0 1. g p m v1 : : : v n = t 0 m and v 0 1 : : : v 0 m = vars ( g v0t1 : : : t n )? v0 (5) Figure 6: Labelled Transformation Rules 11

12 F [[v]] ds = v F [[c t1 : : : t n ]] ds = c (F [[t1]] ds) : : : (F [[t n ]] ds) F let g p1u1 : : : u n = t1 in g p m u1 : : : u n = t m g u0u1 : : : u n = let g p1u1 : : : u n = F [[t1]] ds in ds. g p m u1 : : : u n = F [[t m ]] ds g u0u1 : : : u n F [[Label l t]] ds = f v1 : : : v k ; if (f v1 : : : v k = t) 2 R ds = let f 0 v1 : : : v k = F [[t]] (ff 0 v1 : : : v k = tg [ ds) in f 0 v1 : : : v k where f 0 is a new function name v1 : : : v k = vars t Figure 7: Function for folding labelled terms 12

13 2.6 Proof of Termination We can observe from gure 5 that in the course of the transformation the number of functions remains the same, while at most one constructor is present at any stage; in fact this is also true of our other example, seconds (thirds l) (although we have not shown the steps), which is interesting in view of the exponential growth of the resulting program. This gives us some notion as to how to proceed with the proof. We shall show that there exists a bound on the size of the terms produced by recursive calls to the transformer relative to that of the original term. Any measure will suce, so long as it itself bounds the size of terms in some way. Thus, since a nite alphabet of symbols is used, terms will eventually re-occur, and will be folded to produce a nite result. As a rst step, we observe that for any composition of treeless functions, the transformation steps do not increase the depth in functions (the nesting). This is intuitively clear from the observation that unfolded function bodies are themselves only a single function deep. Dene nesting as follows: N [[v]] = 0 N [[c t1 : : : t n ]] = max f(n [[t1]]) : : : (N [[t n ]])g N [[f t1 : : : t n ]] = 1 + max f(n [[t1]]) : : :(N [[t n ]])g N [[g t1 : : : t n ]] = 1 + max f(n [[t0]]) : : :(N [[t n ]])g A comment of the strategy employed here: nesting is not, of itself, a measure which bounds the size of terms, as our measure ignores constructors and counts only nonconstructor functions, although a measure which counted both clearly would. We choose the former as it would not be straightforward to show a bound on such a measure directly, as the relationship between the numbers of constructors and the numbers of other functions is not as clear as the bound we may obtain of the quantities considered separately. Thus we postpone our treatment of constructors until our second lemma. Lemma 1: After a given number of transformation steps, the remaining terms to be transformed will have a nesting at most that of the original term. Proof: Assume Lemma holds for some n 0 steps. We require to prove that a further step will not increase nesting, showing Lemma holds for n + 1 steps, sucient for result for any number of steps. Prove: for each transformation step T [[t]] = : : : T [[t i ]] : : :, Case (1) v : nothing to prove 8i N [[t i ]] N [[t]] Case (2) c t1 : : : t n : From the denition, N [[c t1 : : : t n ]] = max fn [[t1]] : : : N [[t n ]]g therefore N [[t i ]] N [[c t1 : : : t n ]] 13

14 Case (3) (f t1 : : : t n ) ; where f v1 : : : v n = t : From the denition : N [[f t1 : : : t n ]] = 1 + max fn [[t1]] : : : N [[t n ]]g Since f is treeless, N [[t]] 1 N [[t]] + max fn [[t1]] : : : N [[t n ]]g N [[t[t1=v1; : : : ; t n =v n ]]] Therefore, adding the context to each side: N [[ t[t1=v1; : : : ; t n v n ] ]] N [[ (f t1 : : : t n ) ]] Case (4) (g (c t 0 1 : : : t 0 m) t1 : : : t n ) : where t = g (c v 0 1 : : : v 0 m) v1 : : : v n From the denition, N [[g (c t 0 1 : : : t 0 m) t1 : : : t n ]] = 1 + max fn [[t1]] : : :N [[t n ]]; N [[t 0 1]] : : : N [[t 0 m]]g g is treeless, so N [[t]] 1, N [[t]] + max fn [[t1]] : : : N [[t n ]]; N [[t 0 1]] : : : N [[t 0 m]]g N [[t[t1=v1; : : : ; t n =v n ; t 0 1=v 0 1; : : : t 0 m=v 0 m]]] (by an obvious property of substitution) Adding the context: N [[ t[t1=v1; : : : ; t n =v n ; t 0 1=v 0 1; : : : t 0 m=v 0 m] ]] N [[ (g (c t 0 1 : : : t 0 m) t1 : : : t n ) ]] Case (5) (g v t1 : : : t n ) : From the denition: N [[g v t1 : : : t n ]] = 1 + max fn [[t1]] : : : N [[t n ]]g Using the denition again, = N [[g (c v 0 1 : : : v 0 m) t1 : : : t n ]] for all patterns c v 0 1 : : : v 0 m Adding the context: N [[ (g (c v 0 1 : : : v 0 m) t1 : : : t n ) ]] N [[ g v t1 : : : t n ]] Thus we have proved that the nesting of terms to be transformed is never increasing, and is therefore bounded. Further, the number of constructors in the terms encountered to be recursively transformed is at most one. To see this informally, observe that the original term t has none, as it is simply a composition of (non-constructor) functions, and that none of the rules increase number of constructors apart from (3) and (5). However, these rules will only be applied when there are no constructors in the expression, since in each case the subexpressions of the redex contain no constructors. This is trivially true for (3) { no subexpressions { and can be seen to be true for rule (5) as well since constructors are always on the outside of an unfolded term, and cannot be contained within a redex. 14

15 Dene: ct ::= (c ft 1 : : : ft n ) fct ::= ft j ct where t is a context of pattern-matching functions, as before, but with the occurrences of general terms replaced by function terms: i.e. t ::= t j g ( t ) ft 1 : : : ft n Note that although this assumption would seem to limit the applicability of our rules, the next lemma, together with our restriction to input terms which conform to the grammar ft, indicates that they remain exhaustive. The grammar fct denes terms having at most one constructor, and if one is present, occurring nested within only pattern-matching functions; thus any constructor in the term lies at the position of the `redex'. Lemma 2: After a given number of transformation steps, the terms remaining to be transformed will conform to the grammar fct. Proof: Again, assume Lemma holds for some n 0 steps, and prove that a further step will not falsify the desired property, showing Lemma holds for n + 1 steps, sucient for result for any number of steps. Prove: for each transformation step T [[t]] = : : : T [[t i ]] : : :, Case (1) v : nothing to prove 8i t 2 fct ) t i 2 fct Case (2) c t1 : : : t n : c t1 : : : t n 2 fct ) c t1 : : : t n 2 c ft 1 : : : ft n (matches ct case, with null context) ) t i 2 ft i ) t i 2 fct Case (3) (f t1 : : : t n ) ; where f v1 : : : v n = t : (f t1 : : : t n ) 2 fct ) (f t1 : : : t n ) 2 ft (f inside context matches ft) ) t i 2 ft Since f is treeless, t 2 tt ) t 2 fct ) t[t1=v1; : : : ; t n =v n ] 2 fct (since an ft is allowed anywhere a v is) 15

16 Case (4) (g (c t 0 1 : : : t 0 m) t1 : : : t n ) ; where g (c v 0 1 : : : v 0 m) v1 : : : v n ) = t : (g (c t 0 1 : : : t 0 m) t1 : : : t n ) 2 fct ) t i 2 ft; t 0 i 2 ft Since g is treeless, t 2 tt ) t 2 fct ) t[t1=v1; : : : ; t n =v n ; t 0 1=v 0 1; : : : ; t 0 m=v 0 m] 2 fct (similar to above) Case (5) (g v t1 : : : t n ) : (g v t1 : : : t n ) 2 fct ) (g v t1 : : : t n ) 2 ft ) (g (c v 0 1 : : : v 0 m) t1 : : : t n ) 2 ct ) (g (c v 0 1 : : : v 0 m) t1 : : : t n ) 2 fct So having initial term t 2 fct means that for all terms t 0 to be transformed subsequently, t 0 2 fct and thus each has at most one constructor. The bound on nesting, together with the the above result about constructors, means that terms are bounded in size, and for a nite alphabet of symbols, there are only nitely many such terms. To see that we do indeed have only nitely many symbols, notice that our equality test identies all variables, and although we do make up new function names, these are never incorporated into the terms we recursively transform, and only appear directly in the output. Thus, in eect, our set of symbols is simply the function names in the original program, which is clearly bounded. This further guarantees that when we attempt to collapse the generated term, only nitely many sub-terms will be encountered before all remaining ones are renamings of some of their forerunners, and so will be all folded to appropriately introduced denitions. 3 Related Work As already noted, this paper is the successor to the initial work on deforestation [Wad87b]. Another relative of this paper is the work on listlessness [Wad84, Wad85], which is concerned specically with the elimination of intermediate lists, and is not a source-to-source transformation, but gives a non-functional result. Listlessness does allow non-linear functions (that is, a list may be traversed more than once, e.g. the mean calculation sum l =length l), and is higher-order, unlike the present transformation (although extensions are envisaged). Torben Mogensen suggests an interesting variant on deforestation: removing intermediate structures from Prolog programs. If we restrict our attention to a subset of the language excluding meta-logical constructs, then in principle fold-unfold transformations are valid. 16

17 4 Conclusion The claim has been made that Deforestation would be a suitable candidate for inclusion in an advanced compiler for a functional language, after the fashion of the many program transformations employed in the LML compiler ([Aug87, Joh87]). In order for this to be convincing, we must be assured of termination; that is what, by means of a reformulation, we have established here. Our reformulation may have other benets: anyone who has tried to transform terms by hand using the old formulation using case-expressions will realise that for some programs the size of sub-terms to be transformed becomes rather large; this is because that version of the transformation operates on terms which are, in a sense, maximally unfolded, meaning that functions with cases are unfolded before anything protable may be done with them. By not unfolding these until it becomes appropriate, the version presented here keeps the term size as small as possible. Not only does this make hand transformations less painful, but much more signicantly for our purposes, it is likely to be somewhat less wasteful of space when automated. References [Aug85] L. Augustsson, Compiling pattern matching. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, Nancy, France, September LNCS 201, Springer-Verlag, [Aug87] L. Augustsson, Compiling lazy functional languages, Part II. Ph.D. dissertation, Department of Computer Science, Chalmers Tekniska Hogskola, Goteborg, Sweden, [Bac77] J. Backus, Can Programming Be liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs Turing Award Lecture, Communications of the ACM, Volume 21, Number 8. [Bou78] S. R. Bourne, \UNIX Time-Sharing System: The Unix Shell". In Bell Sys. Tech. J. 57(6) [Ive62] K. Iverson, A programming Language, Wiley, New York, [Joh87] T. Johnsson, Compiling lazy functional languages. Ph.D. dissertation, Department of Computer Science, Chalmers Tekniska Hogskola, Goteborg, Sweden, [Tur85] D. A. Turner, Miranda: A non-strict functional language with polymorphic types. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, Nancy, France, September LNCS 201, Springer-Verlag, [Wad84] P. L. Wadler, Listlessness is better than laziness: Lazy evaluation and garbage collection at compile-time. In Proceedings of the ACM Symposium on Lisp and Functional Programming, Austin, Texas, August

18 [Wad85] P. L. Wadler, Listlessness is better than laziness II: Composing listless functions. In Proceedings of the Workshop on Programs as Data Objects, Copenhagen, October LNCS 217, Springer-Verlag, [Wad87a] P. L. Wadler, Ecient compilation of pattern-matching. In The Implementation of Functional Programming Languages, Prentice Hall, 1987, S. L. Peyton Jones. [Wad87b] P. L. Wadler, Deforestation: Transforming programs to eliminate trees. European Symposium On Programming (ESOP), Nancy, France, March

Functional Database Query Languages as. Typed Lambda Calculi of Fixed Order. Gerd G. Hillebrand and Paris C. Kanellakis

Functional Database Query Languages as. Typed Lambda Calculi of Fixed Order. Gerd G. Hillebrand and Paris C. Kanellakis Functional Database Query Languages as Typed Lambda Calculi of Fixed Order Gerd G. Hillebrand and Paris C. Kanellakis Department of Computer Science Brown University Providence, Rhode Island 02912 CS-94-26

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

How to Pop a Deep PDA Matters

How to Pop a Deep PDA Matters How to Pop a Deep PDA Matters Peter Leupold Department of Mathematics, Faculty of Science Kyoto Sangyo University Kyoto 603-8555, Japan email:leupold@cc.kyoto-su.ac.jp Abstract Deep PDA are push-down automata

More information

Notes on Inductive Sets and Induction

Notes on Inductive Sets and Induction Notes on Inductive Sets and Induction Finite Automata Theory and Formal Languages TMV027/DIT21 Ana Bove, March 15th 2018 Contents 1 Induction over the Natural Numbers 2 1.1 Mathematical (Simple) Induction........................

More information

Mathematical Foundations of Programming. Nicolai Kraus. Draft of February 15, 2018

Mathematical Foundations of Programming. Nicolai Kraus. Draft of February 15, 2018 Very short lecture notes: Mathematical Foundations of Programming University of Nottingham, Computer Science, module code G54FOP, Spring 2018 Nicolai Kraus Draft of February 15, 2018 What is this? This

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Subtyping Motivation With our usual typing rule for applications the term is not well typed. ` t 1 : T 11!T 12 ` t

More information

Outline. A recursive function follows the structure of inductively-defined data.

Outline. A recursive function follows the structure of inductively-defined data. Outline A recursive function follows the structure of inductively-defined data. With lists as our example, we shall study 1. inductive definitions (to specify data) 2. recursive functions (to process data)

More information

Lecture 14 - P v.s. NP 1

Lecture 14 - P v.s. NP 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) February 27, 2018 Lecture 14 - P v.s. NP 1 In this lecture we start Unit 3 on NP-hardness and approximation

More information

Backwards Strictness Analysis: Proved and Improved. Kei Davis. Philip Wadler. University of Glasgow. Glasgow G12 8QQ. Abstract

Backwards Strictness Analysis: Proved and Improved. Kei Davis. Philip Wadler. University of Glasgow. Glasgow G12 8QQ. Abstract Backwards Strictness Analysis: Proved and Improved Kei Davis Philip Wadler Dept. of Computing Science University of Glasgow Glasgow G12 8QQ United Kingdom Abstract Given a syntax tree representing an expression,

More information

Computing the acceptability semantics. London SW7 2BZ, UK, Nicosia P.O. Box 537, Cyprus,

Computing the acceptability semantics. London SW7 2BZ, UK, Nicosia P.O. Box 537, Cyprus, Computing the acceptability semantics Francesca Toni 1 and Antonios C. Kakas 2 1 Department of Computing, Imperial College, 180 Queen's Gate, London SW7 2BZ, UK, ft@doc.ic.ac.uk 2 Department of Computer

More information

Denotational Semantics

Denotational Semantics 5 Denotational Semantics In the operational approach, we were interested in how a program is executed. This is contrary to the denotational approach, where we are merely interested in the effect of executing

More information

Basic System and Subsystem Structures in the Dataflow Algebra. A. J. Cowling

Basic System and Subsystem Structures in the Dataflow Algebra. A. J. Cowling Verification Testing Research Group, Department of Computer Science, University of Sheffield, Regent Court, 211, Portobello Street, Sheffield, S1 4DP, United Kingdom Email: A.Cowling @ dcs.shef.ac.uk Telephone:

More information

Preface These notes were prepared on the occasion of giving a guest lecture in David Harel's class on Advanced Topics in Computability. David's reques

Preface These notes were prepared on the occasion of giving a guest lecture in David Harel's class on Advanced Topics in Computability. David's reques Two Lectures on Advanced Topics in Computability Oded Goldreich Department of Computer Science Weizmann Institute of Science Rehovot, Israel. oded@wisdom.weizmann.ac.il Spring 2002 Abstract This text consists

More information

Transformation Rules for Locally Stratied Constraint Logic Programs

Transformation Rules for Locally Stratied Constraint Logic Programs Transformation Rules for Locally Stratied Constraint Logic Programs Fabio Fioravanti 1, Alberto Pettorossi 2, Maurizio Proietti 3 (1) Dipartimento di Informatica, Universit dell'aquila, L'Aquila, Italy

More information

Higher-Order Chaotic Iteration Sequences

Higher-Order Chaotic Iteration Sequences Higher-Order Chaotic Iteration Sequences Mads Rosendahl DIKU, University of Copenhagen Universitetsparken 1, DK-2100 Copenhagen Ø, Denmark E-mail rose@diku.dk 1993 Abstract Chaotic iteration sequences

More information

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and 7 RC Simulates RA. We now show that DRC (and hence TRC) is at least as expressive as RA. That is, given an RA expression E that mentions at most C, there is an equivalent DRC expression E that mentions

More information

Convergence of program transformers in the metric space of trees

Convergence of program transformers in the metric space of trees Science of Computer Programming 37 (2000) 163 205 www.elsevier.nl/locate/scico Convergence of program transformers in the metric space of trees Morten Heine B. SHrensen Department of Computer Science,

More information

A call-by-name lambda-calculus machine

A call-by-name lambda-calculus machine A call-by-name lambda-calculus machine Jean-Louis Krivine University Paris VII, C.N.R.S. 2 place Jussieu 75251 Paris cedex 05 (krivine@pps.jussieu.fr) Introduction We present, in this paper, a particularly

More information

Computation of Floating Mode Delay in Combinational Circuits: Theory and Algorithms. Kurt Keutzer. Synopsys. Abstract

Computation of Floating Mode Delay in Combinational Circuits: Theory and Algorithms. Kurt Keutzer. Synopsys. Abstract Computation of Floating Mode Delay in Combinational Circuits: Theory and Algorithms Srinivas Devadas MIT Cambridge, MA Kurt Keutzer Synopsys Mountain View, CA Sharad Malik Princeton University Princeton,

More information

Non-Idempotent Typing Operators, beyond the λ-calculus

Non-Idempotent Typing Operators, beyond the λ-calculus Non-Idempotent Typing Operators, beyond the λ-calculus Soutenance de thèse Pierre VIAL IRIF (Univ. Paris Diderot and CNRS) December 7, 2017 Non-idempotent typing operators P. Vial 0 1 /46 Certification

More information

Principles of Program Analysis: Control Flow Analysis

Principles of Program Analysis: Control Flow Analysis Principles of Program Analysis: Control Flow Analysis Transparencies based on Chapter 3 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis. Springer Verlag

More information

Compositionality in SLD-derivations and their abstractions Marco Comini, Giorgio Levi and Maria Chiara Meo Dipartimento di Informatica, Universita di

Compositionality in SLD-derivations and their abstractions Marco Comini, Giorgio Levi and Maria Chiara Meo Dipartimento di Informatica, Universita di Compositionality in SLD-derivations and their abstractions Marco Comini Giorgio Levi and Maria Chiara Meo Dipartimento di Informatica Universita di Pisa Corso Italia 40 56125 Pisa Italy fcomini levi meog@di.unipi.it

More information

Decision Problems Concerning. Prime Words and Languages of the

Decision Problems Concerning. Prime Words and Languages of the Decision Problems Concerning Prime Words and Languages of the PCP Marjo Lipponen Turku Centre for Computer Science TUCS Technical Report No 27 June 1996 ISBN 951-650-783-2 ISSN 1239-1891 Abstract This

More information

Incompatibility Paradoxes

Incompatibility Paradoxes Chapter 22 Incompatibility Paradoxes 22.1 Simultaneous Values There is never any difficulty in supposing that a classical mechanical system possesses, at a particular instant of time, precise values of

More information

A Preference Semantics. for Ground Nonmonotonic Modal Logics. logics, a family of nonmonotonic modal logics obtained by means of a

A Preference Semantics. for Ground Nonmonotonic Modal Logics. logics, a family of nonmonotonic modal logics obtained by means of a A Preference Semantics for Ground Nonmonotonic Modal Logics Daniele Nardi and Riccardo Rosati Dipartimento di Informatica e Sistemistica, Universita di Roma \La Sapienza", Via Salaria 113, I-00198 Roma,

More information

Upper and Lower Bounds on the Number of Faults. a System Can Withstand Without Repairs. Cambridge, MA 02139

Upper and Lower Bounds on the Number of Faults. a System Can Withstand Without Repairs. Cambridge, MA 02139 Upper and Lower Bounds on the Number of Faults a System Can Withstand Without Repairs Michel Goemans y Nancy Lynch z Isaac Saias x Laboratory for Computer Science Massachusetts Institute of Technology

More information

Kirsten Lackner Solberg. Dept. of Math. and Computer Science. Odense University, Denmark

Kirsten Lackner Solberg. Dept. of Math. and Computer Science. Odense University, Denmark Inference Systems for Binding Time Analysis Kirsten Lackner Solberg Dept. of Math. and Computer Science Odense University, Denmark e-mail: kls@imada.ou.dk June 21, 1993 Contents 1 Introduction 4 2 Review

More information

Every formula evaluates to either \true" or \false." To say that the value of (x = y) is true is to say that the value of the term x is the same as th

Every formula evaluates to either \true or \false. To say that the value of (x = y) is true is to say that the value of the term x is the same as th A Quick and Dirty Sketch of a Toy Logic J Strother Moore January 9, 2001 Abstract For the purposes of this paper, a \logic" consists of a syntax, a set of axioms and some rules of inference. We dene a

More information

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth Today 1. What is the Lambda Calculus? Type Systems 2. Its Syntax and Semantics 3. Church Booleans and Church Numerals 4. Lazy vs. Eager Evaluation (call-by-name vs. call-by-value) Lecture 2 Oct. 27th,

More information

Proving Completeness for Nested Sequent Calculi 1

Proving Completeness for Nested Sequent Calculi 1 Proving Completeness for Nested Sequent Calculi 1 Melvin Fitting abstract. Proving the completeness of classical propositional logic by using maximal consistent sets is perhaps the most common method there

More information

A Proof-Theoretic Approach to Irrelevance: Richard E. Fikes. KSL, Stanford University. et al., 1994b].

A Proof-Theoretic Approach to Irrelevance: Richard E. Fikes. KSL, Stanford University. et al., 1994b]. A Proof-Theoretic Approach to Irrelevance: Foundations and Applications Alon Y. Levy AT&T Bell Laboratories Murray Hill, NJ, 7974 levy@research.att.com Richard E. Fikes KSL, Stanford University Palo Alto,

More information

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers 1 Introduction In this lecture, we make an attempt to extend the typed λ-calculus for it to support more advanced data structures

More information

The Proof of IP = P SP ACE

The Proof of IP = P SP ACE The Proof of IP = P SP ACE Larisse D. Voufo March 29th, 2007 For a long time, the question of how a verier can be convinced with high probability that a given theorem is provable without showing the whole

More information

Written Qualifying Exam. Spring, Friday, May 22, This is nominally a three hour examination, however you will be

Written Qualifying Exam. Spring, Friday, May 22, This is nominally a three hour examination, however you will be Written Qualifying Exam Theory of Computation Spring, 1998 Friday, May 22, 1998 This is nominally a three hour examination, however you will be allowed up to four hours. All questions carry the same weight.

More information

Multiple Intermediate Structure Deforestation by Shortcut Fusion

Multiple Intermediate Structure Deforestation by Shortcut Fusion Multiple Intermediate Structure Deforestation by Shortcut Fusion Alberto Pardo 1, João P. Fernandes 2,3, and João Saraiva 2 1 Instituto de Computación, Universidad de la República, Uruguay pardo@fing.edu.uy

More information

A fast algorithm to generate necklaces with xed content

A fast algorithm to generate necklaces with xed content Theoretical Computer Science 301 (003) 477 489 www.elsevier.com/locate/tcs Note A fast algorithm to generate necklaces with xed content Joe Sawada 1 Department of Computer Science, University of Toronto,

More information

distinct models, still insists on a function always returning a particular value, given a particular list of arguments. In the case of nondeterministi

distinct models, still insists on a function always returning a particular value, given a particular list of arguments. In the case of nondeterministi On Specialization of Derivations in Axiomatic Equality Theories A. Pliuskevicien_e, R. Pliuskevicius Institute of Mathematics and Informatics Akademijos 4, Vilnius 2600, LITHUANIA email: logica@sedcs.mii2.lt

More information

Lecture Notes on Heyting Arithmetic

Lecture Notes on Heyting Arithmetic Lecture Notes on Heyting Arithmetic 15-317: Constructive Logic Frank Pfenning Lecture 8 September 21, 2017 1 Introduction In this lecture we discuss the data type of natural numbers. They serve as a prototype

More information

Lecture 10: Gentzen Systems to Refinement Logic CS 4860 Spring 2009 Thursday, February 19, 2009

Lecture 10: Gentzen Systems to Refinement Logic CS 4860 Spring 2009 Thursday, February 19, 2009 Applied Logic Lecture 10: Gentzen Systems to Refinement Logic CS 4860 Spring 2009 Thursday, February 19, 2009 Last Tuesday we have looked into Gentzen systems as an alternative proof calculus, which focuses

More information

An Operational Semantics for the Dataflow Algebra. A. J. Cowling

An Operational Semantics for the Dataflow Algebra. A. J. Cowling Verification and Testing Research Group, Department of Computer Science, University of Sheffield, Regent Court, 211, Portobello Street, Sheffield, S1 4DP, United Kingdom Email: A.Cowling @ dcs.shef.ac.uk

More information

The Locally Nameless Representation

The Locally Nameless Representation Noname manuscript No. (will be inserted by the editor) The Locally Nameless Representation Arthur Charguéraud Received: date / Accepted: date Abstract This paper provides an introduction to the locally

More information

TDDD08 Tutorial 1. Who? From? When? 6 september Victor Lagerkvist (& Wªodek Drabent)

TDDD08 Tutorial 1. Who? From? When? 6 september Victor Lagerkvist (& Wªodek Drabent) TDDD08 Tutorial 1 Who? From? Victor Lagerkvist (& Wªodek Drabent) Theoretical Computer Science Laboratory, Linköpings Universitet, Sweden When? 6 september 2015 1 / 18 Preparations Before you start with

More information

Extracted from a working draft of Goldreich s FOUNDATIONS OF CRYPTOGRAPHY. See copyright notice.

Extracted from a working draft of Goldreich s FOUNDATIONS OF CRYPTOGRAPHY. See copyright notice. 106 CHAPTER 3. PSEUDORANDOM GENERATORS Using the ideas presented in the proofs of Propositions 3.5.3 and 3.5.9, one can show that if the n 3 -bit to l(n 3 ) + 1-bit function used in Construction 3.5.2

More information

A Stochastic l-calculus

A Stochastic l-calculus A Stochastic l-calculus Content Areas: probabilistic reasoning, knowledge representation, causality Tracking Number: 775 Abstract There is an increasing interest within the research community in the design

More information

3.2 Equivalence, Evaluation and Reduction Strategies

3.2 Equivalence, Evaluation and Reduction Strategies 3.2 Equivalence, Evaluation and Reduction Strategies The λ-calculus can be seen as an equational theory. More precisely, we have rules i.e., α and reductions, for proving that two terms are intensionally

More information

Parametric Polymorphism and Operational Improvement

Parametric Polymorphism and Operational Improvement Parametric Polymorphism and Operational Improvement JENNIFER HACKETT, University of Nottingham, UK GRAHAM HUTTON, University of Nottingham, UK Parametricity, in both operational and denotational forms,

More information

ALMOST ODD RANDOM SUM-FREE SETS NEIL J. CALKIN AND P. J. CAMERON. 1. introduction

ALMOST ODD RANDOM SUM-FREE SETS NEIL J. CALKIN AND P. J. CAMERON. 1. introduction ALMOST ODD RANDOM SUM-FREE SETS NEIL J. CALKIN AND P. J. CAMERON Abstract. We show that if S 1 is a strongly complete sum-free set of positive integers, and if S 0 is a nite sum-free set, then with positive

More information

every symbol we can dene inside which of its arguments reduction is allowed or not. This kind of rewriting is called context-sensitive rewriting. It i

every symbol we can dene inside which of its arguments reduction is allowed or not. This kind of rewriting is called context-sensitive rewriting. It i Termination of context-sensitive rewriting H. Zantema Utrecht University, Department of Computer Science, P.O. box 80.089, 3508 TB Utrecht, The Netherlands e-mail: hansz@cs.ruu.nl Abstract Context-sensitive

More information

Lecture Notes on Emptiness Checking, LTL Büchi Automata

Lecture Notes on Emptiness Checking, LTL Büchi Automata 15-414: Bug Catching: Automated Program Verification Lecture Notes on Emptiness Checking, LTL Büchi Automata Matt Fredrikson André Platzer Carnegie Mellon University Lecture 18 1 Introduction We ve seen

More information

PRIME GENERATING LUCAS SEQUENCES

PRIME GENERATING LUCAS SEQUENCES PRIME GENERATING LUCAS SEQUENCES PAUL LIU & RON ESTRIN Science One Program The University of British Columbia Vancouver, Canada April 011 1 PRIME GENERATING LUCAS SEQUENCES Abstract. The distribution of

More information

Safety Analysis versus Type Inference for Partial Types

Safety Analysis versus Type Inference for Partial Types Safety Analysis versus Type Inference for Partial Types Jens Palsberg palsberg@daimi.aau.dk Michael I. Schwartzbach mis@daimi.aau.dk Computer Science Department, Aarhus University Ny Munkegade, DK-8000

More information

Chapter 4: Computation tree logic

Chapter 4: Computation tree logic INFOF412 Formal verification of computer systems Chapter 4: Computation tree logic Mickael Randour Formal Methods and Verification group Computer Science Department, ULB March 2017 1 CTL: a specification

More information

KRIPKE S THEORY OF TRUTH 1. INTRODUCTION

KRIPKE S THEORY OF TRUTH 1. INTRODUCTION KRIPKE S THEORY OF TRUTH RICHARD G HECK, JR 1. INTRODUCTION The purpose of this note is to give a simple, easily accessible proof of the existence of the minimal fixed point, and of various maximal fixed

More information

UNIFORM PROOFS AS A FOUNDATION FOR LOGIC PROGRAMMING. Computer and Information Science Department University of Pennsylvania, Philadelphia, PA 19104

UNIFORM PROOFS AS A FOUNDATION FOR LOGIC PROGRAMMING. Computer and Information Science Department University of Pennsylvania, Philadelphia, PA 19104 UNIFORM PROOFS AS A FOUNDATION FOR LOGIC PROGRAMMING Dale Miller Gopalan Nadathur Frank Pfenning Andre Scedrov Computer and Information Science Department University of Pennsylvania, Philadelphia, PA 19104

More information

The Call-by-Need Lambda Calculus

The Call-by-Need Lambda Calculus The Call-by-Need Lambda Calculus John Maraist, Martin Odersky School of Computer and Information Science, University of South Australia Warrendi Road, The Levels, Adelaide, South Australia 5095 fmaraist,oderskyg@cis.unisa.edu.au

More information

The Skorokhod reflection problem for functions with discontinuities (contractive case)

The Skorokhod reflection problem for functions with discontinuities (contractive case) The Skorokhod reflection problem for functions with discontinuities (contractive case) TAKIS KONSTANTOPOULOS Univ. of Texas at Austin Revised March 1999 Abstract Basic properties of the Skorokhod reflection

More information

Prefixed Tableaus and Nested Sequents

Prefixed Tableaus and Nested Sequents Prefixed Tableaus and Nested Sequents Melvin Fitting Dept. Mathematics and Computer Science Lehman College (CUNY), 250 Bedford Park Boulevard West Bronx, NY 10468-1589 e-mail: melvin.fitting@lehman.cuny.edu

More information

2 C. A. Gunter ackground asic Domain Theory. A poset is a set D together with a binary relation v which is reexive, transitive and anti-symmetric. A s

2 C. A. Gunter ackground asic Domain Theory. A poset is a set D together with a binary relation v which is reexive, transitive and anti-symmetric. A s 1 THE LARGEST FIRST-ORDER-AXIOMATIZALE CARTESIAN CLOSED CATEGORY OF DOMAINS 1 June 1986 Carl A. Gunter Cambridge University Computer Laboratory, Cambridge C2 3QG, England Introduction The inspiration for

More information

Consequence Relations and Natural Deduction

Consequence Relations and Natural Deduction Consequence Relations and Natural Deduction Joshua D. Guttman Worcester Polytechnic Institute September 9, 2010 Contents 1 Consequence Relations 1 2 A Derivation System for Natural Deduction 3 3 Derivations

More information

CS411 Notes 3 Induction and Recursion

CS411 Notes 3 Induction and Recursion CS411 Notes 3 Induction and Recursion A. Demers 5 Feb 2001 These notes present inductive techniques for defining sets and subsets, for defining functions over sets, and for proving that a property holds

More information

Notation for Logical Operators:

Notation for Logical Operators: Notation for Logical Operators: always true always false... and...... or... if... then...... if-and-only-if... x:x p(x) x:x p(x) for all x of type X, p(x) there exists an x of type X, s.t. p(x) = is equal

More information

Part IV Basic procs 131 Chapter 10 Possible delay, Delay, Prex In this chapter the procs pdly, dly and pref are introduced. Those procs make it possible to compare chronicles in several ways. Important

More information

Stochastic dominance with imprecise information

Stochastic dominance with imprecise information Stochastic dominance with imprecise information Ignacio Montes, Enrique Miranda, Susana Montes University of Oviedo, Dep. of Statistics and Operations Research. Abstract Stochastic dominance, which is

More information

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth.

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth. Type Systems Lecture 2 Oct. 27th, 2004 Sebastian Maneth http://lampwww.epfl.ch/teaching/typesystems/2004 Today 1. What is the Lambda Calculus? 2. Its Syntax and Semantics 3. Church Booleans and Church

More information

Introduction to Logic in Computer Science: Autumn 2006

Introduction to Logic in Computer Science: Autumn 2006 Introduction to Logic in Computer Science: Autumn 2006 Ulle Endriss Institute for Logic, Language and Computation University of Amsterdam Ulle Endriss 1 Plan for Today Today s class will be an introduction

More information

Introduction to lambda calculus Part 2

Introduction to lambda calculus Part 2 Introduction to lambda calculus Part 2 Antti-Juhani Kaijanaho 2017-01-24... 1 Untyped lambda calculus 1.1 Syntax... x, y, z Var t, u Term t, u ::= x t u λx t... In this document, I will be using the following

More information

A Fixed Point Representation of References

A Fixed Point Representation of References A Fixed Point Representation of References Susumu Yamasaki Department of Computer Science, Okayama University, Okayama, Japan yamasaki@momo.cs.okayama-u.ac.jp Abstract. This position paper is concerned

More information

CPSC 421: Tutorial #1

CPSC 421: Tutorial #1 CPSC 421: Tutorial #1 October 14, 2016 Set Theory. 1. Let A be an arbitrary set, and let B = {x A : x / x}. That is, B contains all sets in A that do not contain themselves: For all y, ( ) y B if and only

More information

1 Introduction A one-dimensional burst error of length t is a set of errors that are conned to t consecutive locations [14]. In this paper, we general

1 Introduction A one-dimensional burst error of length t is a set of errors that are conned to t consecutive locations [14]. In this paper, we general Interleaving Schemes for Multidimensional Cluster Errors Mario Blaum IBM Research Division 650 Harry Road San Jose, CA 9510, USA blaum@almaden.ibm.com Jehoshua Bruck California Institute of Technology

More information

Lecture 3. 1 Terminology. 2 Non-Deterministic Space Complexity. Notes on Complexity Theory: Fall 2005 Last updated: September, 2005.

Lecture 3. 1 Terminology. 2 Non-Deterministic Space Complexity. Notes on Complexity Theory: Fall 2005 Last updated: September, 2005. Notes on Complexity Theory: Fall 2005 Last updated: September, 2005 Jonathan Katz Lecture 3 1 Terminology For any complexity class C, we define the class coc as follows: coc def = { L L C }. One class

More information

17.1 Correctness of First-Order Tableaux

17.1 Correctness of First-Order Tableaux Applied Logic Lecture 17: Correctness and Completeness of First-Order Tableaux CS 4860 Spring 2009 Tuesday, March 24, 2009 Now that we have introduced a proof calculus for first-order logic we have to

More information

Principles of Program Analysis: A Sampler of Approaches

Principles of Program Analysis: A Sampler of Approaches Principles of Program Analysis: A Sampler of Approaches Transparencies based on Chapter 1 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis Springer Verlag

More information

Counterexamples to witness conjectures. Notations Let E be the set of admissible constant expressions built up from Z; + ;?;;/; exp and log. Here a co

Counterexamples to witness conjectures. Notations Let E be the set of admissible constant expressions built up from Z; + ;?;;/; exp and log. Here a co Counterexamples to witness conjectures Joris van der Hoeven D pt. de Math matiques (b t. 45) Universit Paris-Sud 91405 Orsay CEDEX France August 15, 003 Consider the class of exp-log constants, which is

More information

N.G.Bean, D.A.Green and P.G.Taylor. University of Adelaide. Adelaide. Abstract. process of an MMPP/M/1 queue is not a MAP unless the queue is a

N.G.Bean, D.A.Green and P.G.Taylor. University of Adelaide. Adelaide. Abstract. process of an MMPP/M/1 queue is not a MAP unless the queue is a WHEN IS A MAP POISSON N.G.Bean, D.A.Green and P.G.Taylor Department of Applied Mathematics University of Adelaide Adelaide 55 Abstract In a recent paper, Olivier and Walrand (994) claimed that the departure

More information

Critical Reading of Optimization Methods for Logical Inference [1]

Critical Reading of Optimization Methods for Logical Inference [1] Critical Reading of Optimization Methods for Logical Inference [1] Undergraduate Research Internship Department of Management Sciences Fall 2007 Supervisor: Dr. Miguel Anjos UNIVERSITY OF WATERLOO Rajesh

More information

1 Introduction A general problem that arises in dierent areas of computer science is the following combination problem: given two structures or theori

1 Introduction A general problem that arises in dierent areas of computer science is the following combination problem: given two structures or theori Combining Unication- and Disunication Algorithms Tractable and Intractable Instances Klaus U. Schulz CIS, University of Munich Oettingenstr. 67 80538 Munchen, Germany e-mail: schulz@cis.uni-muenchen.de

More information

COMP6463: λ-calculus

COMP6463: λ-calculus COMP6463: λ-calculus 1. Basics Michael Norrish Michael.Norrish@nicta.com.au Canberra Research Lab., NICTA Semester 2, 2015 Outline Introduction Lambda Calculus Terms Alpha Equivalence Substitution Dynamics

More information

Automatic Deduction for Theories of. Algebraic Data Types. Igor A. Chikanian

Automatic Deduction for Theories of. Algebraic Data Types. Igor A. Chikanian Automatic Deduction for Theories of Algebraic Data Types by Igor A. Chikanian A dissertation submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy Department of Computer

More information

Uniform Schemata for Proof Rules

Uniform Schemata for Proof Rules Uniform Schemata for Proof Rules Ulrich Berger and Tie Hou Department of omputer Science, Swansea University, UK {u.berger,cshou}@swansea.ac.uk Abstract. Motivated by the desire to facilitate the implementation

More information

Decidability of Existence and Construction of a Complement of a given function

Decidability of Existence and Construction of a Complement of a given function Decidability of Existence and Construction of a Complement of a given function Ka.Shrinivaasan, Chennai Mathematical Institute (CMI) (shrinivas@cmi.ac.in) April 28, 2011 Abstract This article denes a complement

More information

Operationally-Based Theories of Program Equivalence

Operationally-Based Theories of Program Equivalence Operationally-Based Theories of Program Equivalence Andrew Pitts Contents 1 Introduction : : : : : : : : : : : : : : : : : : : : : : : : : : : : 241 2 Contextual Equivalence : : : : : : : : : : : : : :

More information

Lambda-Calculus (cont): Fixpoints, Naming. Lecture 10 CS 565 2/10/08

Lambda-Calculus (cont): Fixpoints, Naming. Lecture 10 CS 565 2/10/08 Lambda-Calculus (cont): Fixpoints, Naming Lecture 10 CS 565 2/10/08 Recursion and Divergence Consider the application: Ω ((λ x. (x x)) (λ x. (x x))) Ω evaluates to itself in one step. It has no normal

More information

Lecture 1 : Data Compression and Entropy

Lecture 1 : Data Compression and Entropy CPS290: Algorithmic Foundations of Data Science January 8, 207 Lecture : Data Compression and Entropy Lecturer: Kamesh Munagala Scribe: Kamesh Munagala In this lecture, we will study a simple model for

More information

of acceptance conditions (nite, looping and repeating) for the automata. It turns out,

of acceptance conditions (nite, looping and repeating) for the automata. It turns out, Reasoning about Innite Computations Moshe Y. Vardi y IBM Almaden Research Center Pierre Wolper z Universite de Liege Abstract We investigate extensions of temporal logic by connectives dened by nite automata

More information

Tree sets. Reinhard Diestel

Tree sets. Reinhard Diestel 1 Tree sets Reinhard Diestel Abstract We study an abstract notion of tree structure which generalizes treedecompositions of graphs and matroids. Unlike tree-decompositions, which are too closely linked

More information

1 Introduction It will be convenient to use the inx operators a b and a b to stand for maximum (least upper bound) and minimum (greatest lower bound)

1 Introduction It will be convenient to use the inx operators a b and a b to stand for maximum (least upper bound) and minimum (greatest lower bound) Cycle times and xed points of min-max functions Jeremy Gunawardena, Department of Computer Science, Stanford University, Stanford, CA 94305, USA. jeremy@cs.stanford.edu October 11, 1993 to appear in the

More information

Theoretical pearl - Church numerals, twice!

Theoretical pearl - Church numerals, twice! See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/231890309 Theoretical pearl - Church numerals, twice! Article in Journal of Functional Programming

More information

An Extended Relational Algebra for Declarative Programming *

An Extended Relational Algebra for Declarative Programming * An Extended Relational Algebra for Declarative Programming * Jesús M. Almendros-Jiménez Dpto. de Lenguajes y Computación. Universidad de Almería. jalmen@ual.es Resumen Relational algebra is a well-known

More information

Denition 2: o() is the height of the well-founded relation. Notice that we must have o() (2 ) +. Much is known about the possible behaviours of. For e

Denition 2: o() is the height of the well-founded relation. Notice that we must have o() (2 ) +. Much is known about the possible behaviours of. For e Possible behaviours for the Mitchell ordering James Cummings Math and CS Department Dartmouth College Hanover NH 03755 January 23, 1998 Abstract We use a mixture of forcing and inner models techniques

More information

Using DNA to Solve NP-Complete Problems. Richard J. Lipton y. Princeton University. Princeton, NJ 08540

Using DNA to Solve NP-Complete Problems. Richard J. Lipton y. Princeton University. Princeton, NJ 08540 Using DNA to Solve NP-Complete Problems Richard J. Lipton y Princeton University Princeton, NJ 08540 rjl@princeton.edu Abstract: We show how to use DNA experiments to solve the famous \SAT" problem of

More information

Guarded resolution for Answer Set Programming

Guarded resolution for Answer Set Programming Under consideration for publication in Theory and Practice of Logic Programming 1 Guarded resolution for Answer Set Programming V.W. Marek Department of Computer Science, University of Kentucky, Lexington,

More information

This program is equivalent to: path(x; Y ) edge(x; Y ): path(x; Y ) edge(x; Z); path(z; Y ): The second is a linear program, while the rst is not. In

This program is equivalent to: path(x; Y ) edge(x; Y ): path(x; Y ) edge(x; Z); path(z; Y ): The second is a linear program, while the rst is not. In On Transformations into Linear Database Logic Programs Foto Afrati 1, Manolis Gergatsoulis 2, Maria Katzouraki 2 1 Dept. of Electrical and Computer Engineering, National Technical University of Athens,

More information

Introduction to Metalogic

Introduction to Metalogic Philosophy 135 Spring 2008 Tony Martin Introduction to Metalogic 1 The semantics of sentential logic. The language L of sentential logic. Symbols of L: Remarks: (i) sentence letters p 0, p 1, p 2,... (ii)

More information

Non-Axiomatic Logic (NAL) Specification. Pei Wang

Non-Axiomatic Logic (NAL) Specification. Pei Wang Non-Axiomatic Logic (NAL) Specification Pei Wang October 30, 2009 Contents 1 Introduction 1 1.1 NAL and NARS........................ 1 1.2 Structure of NAL........................ 2 1.3 Specifying NAL.........................

More information

ECS 120 Lesson 15 Turing Machines, Pt. 1

ECS 120 Lesson 15 Turing Machines, Pt. 1 ECS 120 Lesson 15 Turing Machines, Pt. 1 Oliver Kreylos Wednesday, May 2nd, 2001 Before we can start investigating the really interesting problems in theoretical computer science, we have to introduce

More information

2 RODNEY G. DOWNEY STEFFEN LEMPP Theorem. For any incomplete r.e. degree w, there is an incomplete r.e. degree a > w such that there is no r.e. degree

2 RODNEY G. DOWNEY STEFFEN LEMPP Theorem. For any incomplete r.e. degree w, there is an incomplete r.e. degree a > w such that there is no r.e. degree THERE IS NO PLUS-CAPPING DEGREE Rodney G. Downey Steffen Lempp Department of Mathematics, Victoria University of Wellington, Wellington, New Zealand downey@math.vuw.ac.nz Department of Mathematics, University

More information

Designing and Evaluating Generic Ontologies

Designing and Evaluating Generic Ontologies Designing and Evaluating Generic Ontologies Michael Grüninger Department of Industrial Engineering University of Toronto gruninger@ie.utoronto.ca August 28, 2007 1 Introduction One of the many uses of

More information

hal , version 1-21 Oct 2009

hal , version 1-21 Oct 2009 ON SKOLEMISING ZERMELO S SET THEORY ALEXANDRE MIQUEL Abstract. We give a Skolemised presentation of Zermelo s set theory (with notations for comprehension, powerset, etc.) and show that this presentation

More information

Fundamentals of Software Engineering

Fundamentals of Software Engineering Fundamentals of Software Engineering First-Order Logic Ina Schaefer Institute for Software Systems Engineering TU Braunschweig, Germany Slides by Wolfgang Ahrendt, Richard Bubel, Reiner Hähnle (Chalmers

More information

Operational Semantics

Operational Semantics Operational Semantics Semantics and applications to verification Xavier Rival École Normale Supérieure Xavier Rival Operational Semantics 1 / 50 Program of this first lecture Operational semantics Mathematical

More information