1 INTRODUCTION 2 Represent a multiset as an association list, where the rst argument of a pair is an item and the second argument is the multiplicity

Size: px
Start display at page:

Download "1 INTRODUCTION 2 Represent a multiset as an association list, where the rst argument of a pair is an item and the second argument is the multiplicity"

Transcription

1 Programming with Multisets J.W. Lloyd Department of Computer Science University of Bristol Bristol BS8 1UB, UK Abstract This paper proposes a novel way of introducing multisets into declarative programming languages. Starting from a standard denition of a multiset, suitable operations on multisets are dened and implemented in a declarative programming language, and a variety of programming examples are given to illustrate the utility of the ideas. This approach to multisets is compared with their treatment in the Z specication language and other approaches in programming languages. Multisets are recognised as being important in specication but are not normally provided as a fully-edged data type in programming languages. The approach presented here helps to reduce this mismatch. 1 Introduction Intuitively, a multiset (also called a bag) is similar to a set, except that there can be multiple occurrences of items. There are various ways of formalising this intuition. The most natural and direct of these is as follows. Denition A multiset m on some set X is a function m : X!, where is the non-negative integers. The basic idea of this denition is that, for each element a of X, m(a) is the multiplicity of a, that is, the number of times that a appears in m. A multiset m is nite if fx j m(x) 6= 0g is nite; otherwise, it is innite. In the following, I informally distinguish two kinds of multisets { intensional and extensional. An intensional multiset is one dened implicitly by some property (or properties). An extensional multiset is one dened by explicitly enumerating the items and their multiplicities. Extensional multisets are necessarily nite; intensional multisets can be nite or innite. An early (informal) denition of multiset is given in [7, p.420], where multiset union, intersection, and addition are also dened. The above denition of a multiset is essentially the same as the one used in the Z specication language [10, Section 4.6]: bag X == X 1 : This denition states that a multiset is a partial function from some set X to the positive integers. It is easy to establish a bijection between (total) functions into and partial functions into 1. Multisets are an extremely useful data type as can be seen by examining specications in standard specication languages. For example, in the Z language, one can nd such specications in [3, Chapter 21] and [4, Chapter 8]. On the other hand, programming languages rarely specically support the multiset as a data type and there is little theoretical work on this topic. (Two recent theoretical papers on multisets in declarative programming languages are [2] and [5].) Given the rich variety of applications of multisets in programming, it is surprising that they are not more prominent in programming language design. One can implement extensional multisets with standard programming language data types. Here are two possible ways of doing this: 1

2 1 INTRODUCTION 2 Represent a multiset as an association list, where the rst argument of a pair is an item and the second argument is the multiplicity of the item. The association list can be implemented using, for example, a list, array, or hash table. Set up an ADT with a suitable collection of multiset operations. This hides the implementation details of multisets and also allows a more complex, but more ecient, implementation. A rather dierent approach is taken in [5] in which extensional multisets are represented by a constant for the empty multiset and a two-place function (analogous to the cons function for lists) which joins an item and a multiset. A suitable rst-order equality theory is then imposed and a unication algorithm constructed to correspond to this theory. Something similar is proposed in [1], where the implementation of multiset constraints in a novel functional logic language is studied. Finally, in a higher-order functional programming language, such as Haskell, one can use the functional denition above to dene intensional multisets and provide a (limited) range of operations. All these approaches have their strengths and weaknesses. As can be seen from [5], and a number of papers which provide a similar treatment of sets 1, the main weakness is that the mathematical development and the unication algorithm are rather complex. The approach of functional languages provides an easy denition of multisets and some operations on them. However, as I show below, this approach does not provide the full functionality of the multiset data type. Furthermore, all of the abovementioned approaches are relatively inexible { one cannot easily, if at all, mix extensional and intensional multisets. For example, the association list approach and those of [1] and [5] only provide extensional multisets. In Haskell, one can have (a weak form of) intensional multisets and also extensional multisets, but they cannot easily be mixed. By way of comparison, this paper oers an alternative approach based on the denition of multiset given at the beginning of this section. This approach is set in the context of the Escher programming language [9]. Escher 2 is a general-purpose, higher-order, declarative programming language which integrates the best features of both functional and logic programming languages. Since a multiset is a function, the higher-order facilities of Escher are crucial to this enterprise. The main advantage of the approach given here is its exible handling of multisets which goes well beyond what Haskell provides. On the other hand, the price one pays for this exibility is a more complex implementation { the Escher abstract machine and associated run-time system [6] is more complicated than that needed by Haskell. The dierences at the language level between Escher and Haskell are as follows. 1. Escher allows -expressions and (dened) functions in arguments in the heads of statements. Thus Escher drops the constructor-based assumption of Haskell. 2. Escher allows (free and bound) variables in redexes. Thus Escher drops the ground redex assumption of Haskell. 3. Escher has facilities for concurrency. 4. Escher does not assume any order on statements in a denition. Thus Escher drops the textual order of statements assumed in Haskell. The rst three dierences mean that Escher strictly extends Haskell in those respects. The fourth dierence means Haskell code which relies of the textual order of statements may not run on an Escher implementation. The complication of the Escher implementation compared with Haskell is mainly caused by the rst two points above; in Escher, one can match on (dened) functions and -expressions in the head of a statement, and redexes may contain variables. Thus this paper is a further study beyond [9] of the new programming idioms that become possible by exploiting 1 A website on this approach and related ones to sets (and multisets) can be found at 2 M.C.Escher r is a registered trademark of Cordon Art B.V., Baarn, Nederland. Used by permission. All rights reserved.

3 2 MULTISETS AND THEIR OPERATIONS 3 these extensions of Escher. In another companion to [9], interaction and concurrency in Escher are studied in [8]. In [9], set processing is developed in a way analogous to the way multisets are developed here and it would be instructive to understand the way sets are treated before moving on to multisets. The essential idea for handling sets in [9] is that a set can be identied with a predicate, that is, a mapping into the booleans. Thus the dierence between multisets and sets is the dierence between the non-negative integers and the booleans. In fact, sets are simpler than multisets because the booleans are simpler than the non-negative integers. (This can be seen by comparing the set-processing functions in the Booleans module in [9] with the Multisets module in this paper.) Before proceeding with the development, I need to make one change to the denition of multiset. Escher does not support subtypes, so the type of the non-negative integers is not available. The closest type is Int, the type of the integers. Consequently, the type of a multiset m in Escher is given by a declaration of the form m :: T -> Int; where T is some type. This use of Int can lead to some imprecision in multiset computations. (A multiset could take a meaningless negative value.) However, if care is taken, one can avoid such problems. If the approach to multisets advocated here were to be applied in a programming language for which the type of the non-negative integers was available, then this type would replace Int in everything that follows. In the next section, multisets, their operations, and the implementation of these operations in the Escher language is presented. The third section contains a variety of programming examples to illustrate the utility of the ideas. The last section contains some conclusions. An appendix contains the module Multisets which gives the denitions of the Escher functions for multisets. 2 Multisets and their Operations In this section, the basic operations on multisets are introduced and their implementation in Escher is given. The simplest operation on a multiset is to compute the multiplicity of an item. Since a multiset is a function, this is very simple to implement: just apply the multiset to the item. Multiset application corresponds to the standard Z multiset operation ] in [10, Section 4.6]. Next come the operations of multiset addition (madd), subtraction (mmonus), union (munion), and intersection (minters). As a typical example of these, here is the denition of madd from the module Multisets. madd :: (a -> Int) -> (a -> Int) -> (a -> Int); Multiset addition. m `madd` n = \x -> (m x) + (n x); (In Escher, as in Haskell, the \ denotes a, so `\x -> (m x) + (n x)' is just the Escher notation for x :(m(x)+n(x)).) The module Multisets also contains the Escher denitions of the functions mmonus, munion, and minters, which are similar to the denition of madd above. (Note that the monus function in mmonus is similar to subtraction, except a negative result is rounded up to 0.) To connect these functions with the standard Z multiset operations [10, Section 4.6], note that madd corresponds to ], and mmonus to!. Also munion corresponds to t and minters to u, in [4, p.296]. Next we have the function melem which determines whether an item is in a multiset or not. melem :: a -> (a -> Int) -> Bool;

4 2 MULTISETS AND THEIR OPERATIONS 4 Multiset membership. x `melem` m = (m x) > 0; The function melem corresponds to in [10, Section 4.6]. The function listtomultiset converts a list to a multiset. The multiplicity of an item is the number of times it appears in the list. All the functions up to this point can be given the same denitions in Haskell and work ne in that language. I now move on to more sophisticated operations which cannot be handled so easily in Haskell. Typical of these is the function mcard which computes the sum of the multiplicities of all items in a multiset (the cardinality of the multiset). To compute the cardinality, it is convenient to convert the representation of a multiset to a standard form, which I now discuss. First, what should be the standard representation of an empty multiset? This is easy { the obvious answer is the function which always returns 0: \x -> 0. Now what about non-empty multisets? For this I have chosen to use if-then-else expressions. Thus \x -> if x == A then 3 else if x == B then 7 else 0 is the multiset containing 3 occurrences of A, 7 occurrences of B, and nothing else. Actually the use of the qualier `non-empty' is somewhat inaccurate here. It could happen that both s and t are 0 in the multiset `\x -> if x == u then s else t' in which case the multiset would be empty. More precisely, the standard representation of a multiset is dened as follows. multiset ::= \var -> body body ::= 0 j if var == item then multiplicity else body where var is a variable, item is a term, multiplicity is a term of type Int, and the items in the body of a multiset are distinct. Note that the standard representation of a multiset is not unique as the order of the items is not xed. Variations on this denition are possible. For example, one could also insist that the items which occur with multiplicity 0 are not explicitly listed, but are covered by the default value. Note that the standard form of a multiset does not contain `duplicate' occurrences of items. Consider the multiset \x -> if x == Mary then 9 else if x == Fred then 7 else if x == Mary then 6 else 0 in which there are 9 (not 6) occurrences of Mary, 7 occurrences of Fred and nothing else. A tidier form for this multiset is \x -> if x == Mary then 9 else if x == Fred then 7 else 0 which is a standard form. In essence, the standard representation of a multiset gives the multiset in extensional form: each item in the multiset is explicitly (and uniquely) listed, as is its multiplicity. The standard representation thus corresponds closely to the association list form of a multiset. However, the standard form has the advantage over an association list of being a function which can be applied directly. It would be useful to have some notational sugar for (extensional) multisets. For example, the multiset \x -> if x == A then 3 else if x == B then 7 else if x == C then 9 then 0 could be written as

5 2 MULTISETS AND THEIR OPERATIONS 5 <<A, 3>, <B, 7>, <C, 9>> and the empty multiset could be denoted by <>. I make no use of this notation in the following. Now, assuming one had the standard representation of a multiset, how would one compute its cardinality? The function mcard1 below does this. mcard1 :: (a -> Int) -> Int; Sum of multiplicities of all items in a (standard) multiset. mcard1 (\x -> 0) = 0; mcard1 (\x -> if x == u then s else t) = s + mcard1 (\x -> t); The denition is recursive and is broken into two statements. The rst deals with the case when the rst argument is an empty multiset and the second when it is non-empty. This is analogous to list-processing functions which often get broken up into a case for the empty list and a case for non-empty lists. The set-processing functions in [9] have a similar format (except in that context there are 3 cases to consider). The rst statement simply states that the cardinality of the empty multiset is 0. The second statement adds the multiplicity of the rst item in the multiset to the cardinality of the remainder of the multiset. By the way, the denition of mcard1 is illegal in Haskell which bars -expressions from appearing in an argument in the head of a statement. It is important for the correctness of mcard1 that its argument not contain any `duplicates'. To illustrate this point, consider the call mcard1 (\x -> if x == A then 9 else if x == B then 7 else if x == A then 6 else 0) which would return 22 instead of the correct answer 16. I still have to explain how to compute the standard form of a multiset. This is achieved by the function standardise in Multisets. First, standardise calls the function standardise1. Essentially, standardise1 takes a multiset expression whose body is made up of an expression involving the functions +, monus, max, min, and if-then-else. It recurses down to sub-bodies in standard form (modulo `duplicates') and recombines them using the functions madd1, mmonus1, munion1, and minters1, which work on multisets in standard form (modulo `duplicates'). The third statement in the denition of standardise1 simplies conditions which have a (disjunction) at the top level. The nal step in the reduction of a multiset to standard form involves deleting `duplicate' items. This is achieved with the function mdeletedup dened as follows. mdeletedup :: (a -> Int) -> (a -> Int); Remove `duplicates' from a multiset. mdeletedup (\x -> 0) = \x -> 0; mdeletedup (\x -> if x == u then s else t) = \x -> if x == u then s else mdeletedup (mremove u (\x -> t)) x; The function mremove removes an item from a multiset and has the following denition. mremove :: a -> (a -> Int) -> (a -> Int); Remove an item from a (standard) multiset.

6 2 MULTISETS AND THEIR OPERATIONS 6 mremove y (\x -> 0) = \x -> 0; mremove y (\x -> if x == u then s else t) = if y == u then mremove y (\x -> t) else \x -> if x == u then s else mremove y (\x -> t) x; Of course, not every multiset can be reduced to standard form. For example, the intensional multiset \x -> if (x `mod` 2 == 0 && x > 0) then 1 else 0, which is the characteristic function of the even positive integers, cannot be reduced to standard form. With standardise dened, one can now dene mcard as follows. mcard :: (a -> Int) -> Int; Sum of multiplicities of all items in a multiset. mcard m = mcard1 (standardise m); The next function in Multisets is msubset which determines whether one multiset is a subset of another. The formal denition of the subset relation [10, Section 4.6] is that m is a subset of n if, for all x, m(x) n(x). In this form, the denition isn't computationally useful. However, if m is in standard form, one can enumerate the items in m and check for each such item that its multiplicity in m is less than or equal to its multiplicity in n. For this computation to terminate, it is of course necessary for m to be nite. These considerations lead to the following denition for msubset. msubset :: (a -> Int) -> (a -> Int) -> Bool; Multiset subset. m `msubset` n = (standardise m) `msubset1` n; msubset1 :: (a -> Int) -> (a -> Int) -> Bool; (Standard) multiset subset. (\x -> 0) `msubset1` m = True; (\x -> if x == u then s else t) `msubset1` m = if s <= (m u) then ((\x -> t) `msubset1` m) else False; The function msubset corresponds to v in [10, Section 4.6]. Finally, there is the function == for multiset equality. Two multisets are equal if each is a subset of the other. Obviously, one can only check for equality between nite multisets. It should be clear by now what extra expressive power Escher provides over Haskell for dealing with multisets. For the rst 6 functions up to listtomultiset only facilities already present in Haskell are being exploited. All the remaining functions use -expressions in the heads of statements in their denitions and therefore cannot be coded this way in Haskell. The practical eect of the constructor-based assumption of Haskell is that it is inconvenient, and sometimes

7 3 PROGRAMMING EXAMPLES 7 impossible, to compare (intensional) multisets and to convert an (intensional) multiset into its extensional form. For example, the only hope of Haskell checking two intensional multisets for the subset relation is for there to be at most a nite number of items in the domain of the multisets which the program can somehow enumerate. The Escher functions for multiset operations are certainly expressive, but it is not so clear that they can be eciently implemented. With the suggested representation, even the simplest functions have time complexity that is linear in the size of the multiset(s). In this respect, one should regard multisets in a similar way to lists, which have a simple representation that allows easy denitions of the basic operations and implementations of these operations that have acceptable eciency for small lists. However, if one is doing heavyweight computations on large lists, a more sophisticated and ecient implementation is necessary. It is the same with multisets. The representation discussed so far is exible, convenient, and acceptably ecient for small multisets. However, if heavyweight computations on large multisets are needed, then Escher provides a convenient interface to an ecient extensional implementation via the function standardise. A multiset m can be easily converted to whatever representation is being employed by the ecient extensional multiset representation by rst converting it into standard form with the call `standardise m'. Thus the approach advocated here oers the exibility of intensional multiset processing plus the eciency provided by an optimised implementation for processing large extensional multisets. 3 Programming Examples In this section, I provide some programming examples to illustrate the ideas just introduced. First, it is worth remarking that computations in Escher are lazy. This means that the reduction of a subexpression is only carried out if it is embedded in a bigger computation which requires the value for the subexpression. In the examples in this section, I make the assumption that the complete reduction of the various terms is required and give the values that would thus be obtained. Suppose the multisets m1, m2 and m3 are dened by m1 = \x -> if x == A then 3 else if x == B then 8 else 0, m2 = \x -> if x == B then 5 else if x == C then 5 else 0 and m3 = \x -> if x == A then 3 else if x == B then 13 else if x == C then 5 else 0. Then the term standardise (m1 `mmonus` m2) \x -> if x == A then 3 else if x == B then 3 else 0, the term (m1 `mmonus` m2) A 3, the term mcard (m1 `madd` m2)

8 3 PROGRAMMING EXAMPLES 8 21, the term standardise (m1 `munion` m2) \x -> if x == A then 3 else if x == B then 8 else if x == C then 5 else 0, the term (m1 `munion` m2) B 8, the term m1 `msubset` m2 False, and the term (m1 `madd` m2) == m3 True. As examples of the use of mdeletedup and mremove, the term mdeletedup (\x -> if x == A then 3 else if x == B then 8 else if x == A then 5 else 0) \x -> if x == A then 3 else if x == B then 8 else 0 and the term mremove A (\x -> if x == A then 3 else if x == B then 8 else if x == A then 5 else 0) \x -> if x == B then 8 else 0. In specications, sequences and multisets often appear together in that one requires the multiset obtained from a sequence. In programming languages, lists correspond to sequences (and are in some ways more convenient). Hence Escher provides the function listtomultiset which converts a list to a multiset. For example, listtomultiset [A, B, A, A, C, C, B] \x -> if x == B then 2 else if x == C then 2 else if x == A then 3 else 0.

9 3 PROGRAMMING EXAMPLES 9 Next I give an example to illustrate intensional multiset processing. Consider the SportsDB module in Figure 1 which is taken from [9]. Suppose we want to give a multiplicity of 2 to those who like cricket, a multiplicity of 1 to those who like football but not cricket, and a multiplicity of 0 to the remainder. This can be modelled by the multiset m4 dened by m4 = \x -> if likes(x, Cricket) then 2 else if likes(x, Football) then 1 else 0. Then the term standardise m4 \x -> if x == Mary then 2 else if x == Bill then 2 else if x == Joe then 1 else 0. Note that m4 is an intensional multiset because of the conditions likes(x, Cricket) and likes(x, Football). To compute the standard form of m4, these conditions rst need to be reduced to disjunctions of atoms of the form x == Mary and so on, which are then split up with the third statement from the denition of standardise1 to obtain the standard form. module SportsDB(Person(..), Sport(..), likes) where { data Person = Mary Bill Joe Fred; data Sport = Cricket Football Tennis; likes :: (Person, Sport) -> Bool; likes = {(Mary, Cricket), (Mary, Tennis), (Bill, Cricket), (Bill, Tennis), (Joe, Tennis), (Joe, Football)}; } Figure 1: Sports database A certain amount of computation with innite multisets is possible. Consider again the characteristic function of the even positive integers dened by m5 = \x -> if (x `mod` 2 == 0 && x > 0) then 1 else 0. Then m In fact, there are no diculties with this kind of argument for any of the rst 5 functions in Multisets, up to and including melem. However, the call standardise m5 will ounder and hence most of the remaining functions in Multisets cannot handle innite multisets such as m5 as an argument. Thus, primarily, the Multisets module is meant for processing (extensional or intensional) nite multisets, although in some cases it will handle innite multisets.

10 4 CONCLUSION 10 Finally, I consider the problem of converting a multiset into an association list. At rst sight, this may seem straightforward. However, there is a serious semantic problem due to the fact that there are many possible association lists, all permutations of one another, that could be the image of the multiset. However, one can exploit Haskell's (and therefore Escher's) monadic IO to nd a (more) declarative solution to this problem. Instead of mapping the multiset to an association list, one maps it to a suitable IO action as follows. The (system) function multisettoassoclist with signature multisettoassoclist :: (a -> Int) -> IO [(a, Int)]; takes a multiset as its argument and gives an IO action as a result. This action returns an association list containing pairs of distinct elements in the multiset (in some order) and their multiplicities. If the multiset is nite, the association list contains all elements in the multiset. If the multiset is innite, then so is the association list. The idea is that the world argument, which is hidden, encodes the information for choosing a particular association list. More details are given in [8]. 4 Conclusion This paper has introduced a novel way of handling multisets in declarative programming languages. The ideas have been implemented in the Escher programming language (on the prototype Escher implementation) and various illustrative applications have been presented. It would be interesting to investigate this approach for large-scale applications and to study how to eciently incorporate multisets into the Escher system [6] being developed at Bristol. Acknowledgement I thank Rodney Topor for some remarks which greatly improved certain aspects of this paper. References [1] P. Arenas-Sanchez, F.J. Lopez-Fraguas, and M. Rodrguez-Artalejo. Embedding multiset constraints into a lazy functional logic language. In Proc. of PLILP'98, Lecture Notes in Computer Science 1490, pages 429{444. Springer-Verlag, [2] P. Arenas-Sanchez and M. Rodrguez-Artalejo. A semantic framework for functional logic programming with algebraic polymorphic types. In Proc. of TAPSOFT/CAAP'97, Lecture Notes in Computer Science 1214, pages 453{464. Springer-Verlag, [3] R. Barden, S. Stepney, and D. Cooper. Z in Practice. Prentice-Hall, [4] A. Diller. Z: An Introduction to Formal Methods. Wiley, second edition, [5] A. Dovier, A. Policriti, and G. Rossi. Integrating lists, multisets, and sets in a logic programming framework. In F. Baader and K. Schulz, editors, Proc. of FROCOS'96, pages 213{229. Kluwer, [6] K.I. Eder. EMA: Implementing the Functional Logic Language Escher on an Abstract Machine. PhD thesis, University of Bristol, Submitted for examination. [7] D.E. Knuth. The Art of Programming: Seminumerical Algorithms, volume 2. Addison Wesley, rst edition, [8] J.W. Lloyd. Interaction and concurrency in a declarative programming language. Submitted for publication, 1998.

11 REFERENCES 11 [9] J.W. Lloyd. Programming in an integrated functional and logic language. Journal of Functional and Logic Programming, To appear. [10] J.M. Spivey. The Z Notation: A Reference Manual. Prentice-Hall, second edition, 1992.

12 A MULTISETS MODULE 12 A Multisets Module module Multisets(madd, mmonus, munion, minters, melem, listtomultiset, mcard, msubset, (==), standardise) where { import Booleans; import Integers; import Lists; madd :: (a -> Int) -> (a -> Int) -> (a -> Int); Multiset addition. m `madd` n = \x -> (m x) + (n x); mmonus :: (a -> Int) -> (a -> Int) -> (a -> Int); Multiset subtraction. m `mmonus` n = \x -> (m x) `monus` (n x); munion :: (a -> Int) -> (a -> Int) -> (a -> Int); Multiset union. m `munion` n = \x -> max (m x) (n x); minters :: (a -> Int) -> (a -> Int) -> (a -> Int); Multiset intersection. m `minters` n = \x -> min (m x) (n x); melem :: a -> (a -> Int) -> Bool; Multiset membership. x `melem` m = (m x) > 0; listtomultiset :: [a] -> (a -> Int); Convert a list to a multiset. listtomultiset x = assoclisttomultiset (listtoassoclist x);

13 A MULTISETS MODULE 13 mcard :: (a -> Int) -> Int; Sum of multiplicities of all items in a multiset. mcard m = mcard1 (standardise m); msubset :: (a -> Int) -> (a -> Int) -> Bool; Multiset subset. m `msubset` n = (standardise m) `msubset1` n; (==) :: (a -> Int) -> (a -> Int) -> Bool; Multiset equality. m == n = (m `msubset` n) && (n `msubset` m); standardise :: (a -> Int) -> (a -> Int); Compute a standard representation of a multiset. standardise m = mdeletedup (standardise1 m); Various auxiliary functions follow. msubset1 :: (a -> Int) -> (a -> Int) -> Bool; (Standard) multiset subset. (\x -> 0) `msubset1` m = True; (\x -> if x == u then s else t) `msubset1` m = if s <= (m u) then ((\x -> t) `msubset1` m) else False; mcard1 :: (a -> Int) -> Int; Sum of multiplicities of all items in a (standard) multiset. mcard1 (\x -> 0) = 0; mcard1 (\x -> if x == u then s else t) = s + mcard1 (\x -> t);

14 A MULTISETS MODULE 14 listtoassoclist :: [a] -> [(a, Int)]; Convert a list to an association list. listtoassoclist [] = []; listtoassoclist (u:y) = include u (listtoassoclist y); include :: a -> [(a, Int)] -> [(a, Int)]; Add an element to an association list. include u [] = [(u,1)]; include u ((v,n):z) = if u == v then (v,n+1):z else (v,n):(include u z); assoclisttomultiset :: [(a, Int)] -> (a -> Int); Convert an association list to a multiset. assoclisttomultiset [] = \x -> 0; assoclisttomultiset ((u,s):y) = \x -> if x == u then s else assoclisttomultiset y x; madd1 :: (a -> Int) -> (a -> Int) -> (a -> Int); (Standard) multiset addition. (\x -> 0) `madd1` m = m; (\x -> if x == u then s else t) `madd1` m = \x -> if x == u then s + (m u) else ((\x -> t) `madd1` m) x; mmonus1 :: (a -> Int) -> (a -> Int) -> (a -> Int); (Standard) multiset subtraction. (\x -> 0) `mmonus1` m = \x -> 0; (\x -> if x == u then s else t) `mmonus1` m = \x -> if x == u then s `monus` (m u) else ((\x -> t) `mmonus1` m) x;

15 A MULTISETS MODULE 15 munion1 :: (a -> Int) -> (a -> Int) -> (a -> Int); (Standard) multiset union. (\x -> 0) `munion1` m = m; (\x -> if x == u then s else t) `munion1` m = \x -> if x == u then max s (m u) else ((\x -> t) `munion1` m) x; minters1 :: (a -> Int) -> (a -> Int) -> (a -> Int); (Standard) multiset intersection. (\x -> 0) `minters1` m = \x -> 0; (\x -> if x == u then s else t) `minters1` m = \x -> if x == u then min s (m u) else ((\x -> t) `minters1` m) x; standardise1 :: (a -> Int) -> (a -> Int); Compute standard representation of a multiset (modulo `duplicates'). standardise1 (\x -> 0) = \x -> 0; standardise1 (\x -> if x == u then s else t) = \x -> if x == u then s else standardise1 (\x -> t) x; standardise1 (\x -> if (u v) then s else t) = standardise1 \x -> if u then s else if v then s else t; standardise1 (\x -> t + r) = (standardise1 (\x -> t)) `madd1` (standardise1 (\x -> r)); standardise1 (\x -> t `monus` r) = (standardise1 (\x -> t)) `mmonus1` (standardise1 (\x -> r)); standardise1 \x -> max t r = (standardise1 (\x -> t)) `munion1` (standardise1 (\x -> r)); standardise1 \x -> min t r = (standardise1 (\x -> t)) `minters1` (standardise1 (\x -> r)); mdeletedup :: (a -> Int) -> (a -> Int); Remove `duplicates' from a multiset.

16 A MULTISETS MODULE 16 mdeletedup (\x -> 0) = \x -> 0; mdeletedup (\x -> if x == u then s else t) = \x -> if x == u then s else mdeletedup (mremove u (\x -> t)) x; mremove :: a -> (a -> Int) -> (a -> Int); Remove an item from a multiset. mremove y (\x -> 0) = \x -> 0; mremove y (\x -> if x == u then s else t) = if y == u then mremove y (\x -> t) else \x -> if x == u then s else mremove y (\x -> t) x; }

.Math 0450 Honors intro to analysis Spring, 2009 Notes #4 corrected (as of Monday evening, 1/12) some changes on page 6, as in .

.Math 0450 Honors intro to analysis Spring, 2009 Notes #4 corrected (as of Monday evening, 1/12) some changes on page 6, as in  . 0.1 More on innity.math 0450 Honors intro to analysis Spring, 2009 Notes #4 corrected (as of Monday evening, 1/12) some changes on page 6, as in email. 0.1.1 If you haven't read 1.3, do so now! In notes#1

More information

Introduction to Functional Programming: Lecture 7 2 Functions as innite data structures Ordinary ML data structures are always nite. We can, however,

Introduction to Functional Programming: Lecture 7 2 Functions as innite data structures Ordinary ML data structures are always nite. We can, however, Introduction to Functional Programming: Lecture 7 1 Introduction to Functional Programming John Harrison University of Cambridge Lecture 7 Innite data structures Topics covered: Functions as innite data

More information

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations Outline Computer Science 331 Data Structures, Abstract Data Types, and Their Implementations Mike Jacobson 1 Overview 2 ADTs as Interfaces Department of Computer Science University of Calgary Lecture #8

More information

Algebraic Properties of CSP Model Operators? Y.C. Law and J.H.M. Lee. The Chinese University of Hong Kong.

Algebraic Properties of CSP Model Operators? Y.C. Law and J.H.M. Lee. The Chinese University of Hong Kong. Algebraic Properties of CSP Model Operators? Y.C. Law and J.H.M. Lee Department of Computer Science and Engineering The Chinese University of Hong Kong Shatin, N.T., Hong Kong SAR, China fyclaw,jleeg@cse.cuhk.edu.hk

More information

such internal data dependencies can be formally specied. A possible approach to specify

such internal data dependencies can be formally specied. A possible approach to specify Chapter 6 Specication and generation of valid data unit instantiations In this chapter, we discuss the problem of generating valid data unit instantiations. As valid data unit instantiations must adhere

More information

LECTURE 8: SETS. Software Engineering Mike Wooldridge

LECTURE 8: SETS. Software Engineering Mike Wooldridge LECTURE 8: SETS Mike Wooldridge 1 What is a Set? The concept of a set is used throughout mathematics; its formal definition matches closely our intuitive understanding of the word. Definition: A set is

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

SOFTWARE ENGINEERING DESIGN I

SOFTWARE ENGINEERING DESIGN I 2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique

More information

time using O( n log n ) processors on the EREW PRAM. Thus, our algorithm improves on the previous results, either in time complexity or in the model o

time using O( n log n ) processors on the EREW PRAM. Thus, our algorithm improves on the previous results, either in time complexity or in the model o Reconstructing a Binary Tree from its Traversals in Doubly-Logarithmic CREW Time Stephan Olariu Michael Overstreet Department of Computer Science, Old Dominion University, Norfolk, VA 23529 Zhaofang Wen

More information

Data types for mcrl2

Data types for mcrl2 Data types for mcrl2 Aad Mathijssen April 5, 2018 We provide a syntax for the standard data types of the mcrl2 language. This syntax is intended to be a practical mix between standard mathematical notation

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. Michael P. Fourman. February 2, 2010 Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

More information

SAMOS: an Active Object{Oriented Database System. Stella Gatziu, Klaus R. Dittrich. Database Technology Research Group

SAMOS: an Active Object{Oriented Database System. Stella Gatziu, Klaus R. Dittrich. Database Technology Research Group SAMOS: an Active Object{Oriented Database System Stella Gatziu, Klaus R. Dittrich Database Technology Research Group Institut fur Informatik, Universitat Zurich fgatziu, dittrichg@ifi.unizh.ch to appear

More information

JOURNAL OF OBJECT TECHNOLOGY

JOURNAL OF OBJECT TECHNOLOGY JOURNAL OF OBJECT TECHNOLOGY Online at www.jot.fm. Published by ETH Zurich, Chair of Software Engineering JOT, 2002 Vol. 1, No. 2, July-August 2002 The Theory of Classification Part 2: The Scratch-Built

More information

1 A Tale of Two Lovers

1 A Tale of Two Lovers CS 120/ E-177: Introduction to Cryptography Salil Vadhan and Alon Rosen Dec. 12, 2006 Lecture Notes 19 (expanded): Secure Two-Party Computation Recommended Reading. Goldreich Volume II 7.2.2, 7.3.2, 7.3.3.

More information

Fundamental Concepts. Chapter 1

Fundamental Concepts. Chapter 1 Chapter 1 Fundamental Concepts This book is about the mathematical foundations of programming, with a special attention on computing with infinite objects. How can mathematics help in programming? There

More information

Let v be a vertex primed by v i (s). Then the number f(v) of neighbours of v which have

Let v be a vertex primed by v i (s). Then the number f(v) of neighbours of v which have Let v be a vertex primed by v i (s). Then the number f(v) of neighbours of v which have been red in the sequence up to and including v i (s) is deg(v)? s(v), and by the induction hypothesis this sequence

More information

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

n   n Try tutorial on front page to get started! n   spring13/ n Stack Overflow! Announcements n Rainbow grades: HW1-6, Quiz1-5, Exam1 n Still grading: HW7, Quiz6, Exam2 Intro to Haskell n HW8 due today n HW9, Haskell, out tonight, due Nov. 16 th n Individual assignment n Start early!

More information

A Boolean Expression. Reachability Analysis or Bisimulation. Equation Solver. Boolean. equations.

A Boolean Expression. Reachability Analysis or Bisimulation. Equation Solver. Boolean. equations. A Framework for Embedded Real-time System Design? Jin-Young Choi 1, Hee-Hwan Kwak 2, and Insup Lee 2 1 Department of Computer Science and Engineering, Korea Univerity choi@formal.korea.ac.kr 2 Department

More information

Worst-case running time for RANDOMIZED-SELECT

Worst-case running time for RANDOMIZED-SELECT Worst-case running time for RANDOMIZED-SELECT is ), even to nd the minimum The algorithm has a linear expected running time, though, and because it is randomized, no particular input elicits the worst-case

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

reasonable to store in a software implementation, it is likely to be a signicant burden in a low-cost hardware implementation. We describe in this pap

reasonable to store in a software implementation, it is likely to be a signicant burden in a low-cost hardware implementation. We describe in this pap Storage-Ecient Finite Field Basis Conversion Burton S. Kaliski Jr. 1 and Yiqun Lisa Yin 2 RSA Laboratories 1 20 Crosby Drive, Bedford, MA 01730. burt@rsa.com 2 2955 Campus Drive, San Mateo, CA 94402. yiqun@rsa.com

More information

Equality for Abstract Data Types

Equality for Abstract Data Types Object-Oriented Design Lecture 4 CSU 370 Fall 2008 (Pucella) Tuesday, Sep 23, 2008 Equality for Abstract Data Types Every language has mechanisms for comparing values for equality, but it is often not

More information

The Java Type System (continued)

The Java Type System (continued) Object-Oriented Design Lecture 5 CSU 370 Fall 2007 (Pucella) Friday, Sep 21, 2007 The Java Type System (continued) The Object Class All classes subclass the Object class. (By default, this is the superclass

More information

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS 1 THE FORMALIZATION OF MATHEMATICS by Harvey M. Friedman Ohio State University Department of Mathematics friedman@math.ohio-state.edu www.math.ohio-state.edu/~friedman/ May 21, 1997 Can mathematics be

More information

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Chapter 2 The Language PCF

Chapter 2 The Language PCF Chapter 2 The Language PCF We will illustrate the various styles of semantics of programming languages with an example: the language PCF Programming language for computable functions, also called Mini-ML.

More information

Optimum Alphabetic Binary Trees T. C. Hu and J. D. Morgenthaler Department of Computer Science and Engineering, School of Engineering, University of C

Optimum Alphabetic Binary Trees T. C. Hu and J. D. Morgenthaler Department of Computer Science and Engineering, School of Engineering, University of C Optimum Alphabetic Binary Trees T. C. Hu and J. D. Morgenthaler Department of Computer Science and Engineering, School of Engineering, University of California, San Diego CA 92093{0114, USA Abstract. We

More information

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions. CS 6110 S18 Lecture 18 Denotational Semantics 1 What is Denotational Semantics? So far we have looked at operational semantics involving rules for state transitions, definitional semantics involving translations

More information

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 98 in short! CPSC 449 Principles of Programming Languages Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has

More information

Parallel Rewriting of Graphs through the. Pullback Approach. Michel Bauderon 1. Laboratoire Bordelais de Recherche en Informatique

Parallel Rewriting of Graphs through the. Pullback Approach. Michel Bauderon 1. Laboratoire Bordelais de Recherche en Informatique URL: http://www.elsevier.nl/locate/entcs/volume.html 8 pages Parallel Rewriting of Graphs through the Pullback Approach Michel Bauderon Laboratoire Bordelais de Recherche en Informatique Universite Bordeaux

More information

7. Introduction to Denotational Semantics. Oscar Nierstrasz

7. Introduction to Denotational Semantics. Oscar Nierstrasz 7. Introduction to Denotational Semantics Oscar Nierstrasz Roadmap > Syntax and Semantics > Semantics of Expressions > Semantics of Assignment > Other Issues References > D. A. Schmidt, Denotational Semantics,

More information

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

Virtual views. Incremental View Maintenance. View maintenance. Materialized views. Review of bag algebra. Bag algebra operators (slide 1)

Virtual views. Incremental View Maintenance. View maintenance. Materialized views. Review of bag algebra. Bag algebra operators (slide 1) Virtual views Incremental View Maintenance CPS 296.1 Topics in Database Systems A view is defined by a query over base tables Example: CREATE VIEW V AS SELECT FROM R, S WHERE ; A view can be queried just

More information

Algebra of Logic Programming Silvija Seres Michael Spivey Tony Hoare Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3

Algebra of Logic Programming Silvija Seres Michael Spivey Tony Hoare Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3 Algebra of Logic Programming Silvija Seres Michael Spivey Tony Hoare Oxford University Computing Laboratory Wolfson Building, Parks Road, Oxford OX1 3QD, U.K. Abstract A declarative programming language

More information

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = ( Floating Point Numbers in Java by Michael L. Overton Virtually all modern computers follow the IEEE 2 floating point standard in their representation of floating point numbers. The Java programming language

More information

,, 1{48 () c Kluwer Academic Publishers, Boston. Manufactured in The Netherlands. Optimal Representations of Polymorphic Types with Subtyping * ALEXAN

,, 1{48 () c Kluwer Academic Publishers, Boston. Manufactured in The Netherlands. Optimal Representations of Polymorphic Types with Subtyping * ALEXAN ,, 1{48 () c Kluwer Academic Publishers, Boston. Manufactured in The Netherlands. Optimal Representations of Polymorphic Types with Subtyping * ALEXANDER AIKEN aiken@cs.berkeley.edu EECS Department, University

More information

A technique for adding range restrictions to. August 30, Abstract. In a generalized searching problem, a set S of n colored geometric objects

A technique for adding range restrictions to. August 30, Abstract. In a generalized searching problem, a set S of n colored geometric objects A technique for adding range restrictions to generalized searching problems Prosenjit Gupta Ravi Janardan y Michiel Smid z August 30, 1996 Abstract In a generalized searching problem, a set S of n colored

More information

III Data Structures. Dynamic sets

III Data Structures. Dynamic sets III Data Structures Elementary Data Structures Hash Tables Binary Search Trees Red-Black Trees Dynamic sets Sets are fundamental to computer science Algorithms may require several different types of operations

More information

Typed Scheme: Scheme with Static Types

Typed Scheme: Scheme with Static Types Typed Scheme: Scheme with Static Types Version 4.1.1 Sam Tobin-Hochstadt October 5, 2008 Typed Scheme is a Scheme-like language, with a type system that supports common Scheme programming idioms. Explicit

More information

16 Greedy Algorithms

16 Greedy Algorithms 16 Greedy Algorithms Optimization algorithms typically go through a sequence of steps, with a set of choices at each For many optimization problems, using dynamic programming to determine the best choices

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations

More information

Abstract Data Types. Lecture notes accompanying COL106 (Data Structures), Semester I, , IIT Delhi

Abstract Data Types. Lecture notes accompanying COL106 (Data Structures), Semester I, , IIT Delhi Abstract Data Types Lecture notes accompanying COL106 (Data Structures), Semester I, 2018-19, IIT Delhi Amitabha Bagchi Department of CS&E, IIT Delhi August 13, 2018 1 What is an abstract data type Abstract

More information

Chalmers University of Technology. Without adding any primitives to the language, we dene a concurrency monad transformer

Chalmers University of Technology. Without adding any primitives to the language, we dene a concurrency monad transformer J. Functional Programming 1 (1): 1{000, January 1993 c 1993 Cambridge University Press 1 F U N C T I O N A L P E A R L S A Poor Man's Concurrency Monad Koen Claessen Chalmers University of Technology email:

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

Network. Department of Statistics. University of California, Berkeley. January, Abstract

Network. Department of Statistics. University of California, Berkeley. January, Abstract Parallelizing CART Using a Workstation Network Phil Spector Leo Breiman Department of Statistics University of California, Berkeley January, 1995 Abstract The CART (Classication and Regression Trees) program,

More information

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Topic IV. Block-structured procedural languages Algol and Pascal. References: References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapters 10( 2) and 11( 1) of Programming

More information

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen Formal semantics of loosely typed languages Joep Verkoelen Vincent Driessen June, 2004 ii Contents 1 Introduction 3 2 Syntax 5 2.1 Formalities.............................. 5 2.2 Example language LooselyWhile.................

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

More information

FUNCTIONAL PEARLS The countdown problem

FUNCTIONAL PEARLS The countdown problem To appear in the Journal of Functional Programming 1 FUNCTIONAL PEARLS The countdown problem GRAHAM HUTTON School of Computer Science and IT University of Nottingham, Nottingham, UK www.cs.nott.ac.uk/

More information

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) January 11, 2018 Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1 In this lecture

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Week 02 Module 06 Lecture - 14 Merge Sort: Analysis So, we have seen how to use a divide and conquer strategy, we

More information

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell) Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 13 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 16 October, 2012 1 / 21 1 Types 2 3 4 2 / 21 Thus far

More information

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics 400 lecture note #4 [Ch 6] Set Theory 1. Basic Concepts and Definitions 1) Basics Element: ; A is a set consisting of elements x which is in a/another set S such that P(x) is true. Empty set: notated {

More information

APPLICATION OF THE FUZZY MIN-MAX NEURAL NETWORK CLASSIFIER TO PROBLEMS WITH CONTINUOUS AND DISCRETE ATTRIBUTES

APPLICATION OF THE FUZZY MIN-MAX NEURAL NETWORK CLASSIFIER TO PROBLEMS WITH CONTINUOUS AND DISCRETE ATTRIBUTES APPLICATION OF THE FUZZY MIN-MAX NEURAL NETWORK CLASSIFIER TO PROBLEMS WITH CONTINUOUS AND DISCRETE ATTRIBUTES A. Likas, K. Blekas and A. Stafylopatis National Technical University of Athens Department

More information

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell) Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 14 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 17 October 2017 1 / 21 1 Types 2 3 4 2 / 21 So far in

More information

perform. If more storage is required, more can be added without having to modify the processor (provided that the extra memory is still addressable).

perform. If more storage is required, more can be added without having to modify the processor (provided that the extra memory is still addressable). How to Make Zuse's Z3 a Universal Computer Raul Rojas January 14, 1998 Abstract The computing machine Z3, built by Konrad Zuse between 1938 and 1941, could only execute xed sequences of oating-point arithmetical

More information

Category Theory & Functional Data Abstraction

Category Theory & Functional Data Abstraction Category Theory & Functional Data Abstraction Brandon Shapiro Math 100b 1. Introduction Throughout mathematics, particularly algebra, there are numerous commonalities between the studies of various objects

More information

detected inference channel is eliminated by redesigning the database schema [Lunt, 1989] or upgrading the paths that lead to the inference [Stickel, 1

detected inference channel is eliminated by redesigning the database schema [Lunt, 1989] or upgrading the paths that lead to the inference [Stickel, 1 THE DESIGN AND IMPLEMENTATION OF A DATA LEVEL DATABASE INFERENCE DETECTION SYSTEM Raymond W. Yip and Karl N. Levitt Abstract: Inference is a way tosubvert access control mechanisms of database systems.

More information

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996. References: Topic IV Block-structured procedural languages Algol and Pascal Chapters 5 and 7, of Concepts in programming languages by J. C. Mitchell. CUP, 2003. Chapter 5 of Programming languages: Concepts

More information

Heap-on-Top Priority Queues. March Abstract. We introduce the heap-on-top (hot) priority queue data structure that combines the

Heap-on-Top Priority Queues. March Abstract. We introduce the heap-on-top (hot) priority queue data structure that combines the Heap-on-Top Priority Queues Boris V. Cherkassky Central Economics and Mathematics Institute Krasikova St. 32 117418, Moscow, Russia cher@cemi.msk.su Andrew V. Goldberg NEC Research Institute 4 Independence

More information

LP-Modelling. dr.ir. C.A.J. Hurkens Technische Universiteit Eindhoven. January 30, 2008

LP-Modelling. dr.ir. C.A.J. Hurkens Technische Universiteit Eindhoven. January 30, 2008 LP-Modelling dr.ir. C.A.J. Hurkens Technische Universiteit Eindhoven January 30, 2008 1 Linear and Integer Programming After a brief check with the backgrounds of the participants it seems that the following

More information

1 The smallest free number

1 The smallest free number 1 The smallest free number Introduction Consider the problem of computing the smallest natural number not in a given finite set X of natural numbers. The problem is a simplification of a common programming

More information

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2).

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

Denotational Semantics. Domain Theory

Denotational Semantics. Domain Theory Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning

More information

Working with recursion

Working with recursion Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

Expressions that talk about themselves. Maarten Fokkinga, University of Twente, dept. INF, Version of May 6, 1994

Expressions that talk about themselves. Maarten Fokkinga, University of Twente, dept. INF, Version of May 6, 1994 Expressions that talk about themselves Maarten Fokkinga, University of Twente, dept. INF, fokkinga@cs.utwente.nl Version of May 6, 1994 Introduction Self-reference occurs frequently in theoretical investigations

More information

Algorithmic "imperative" language

Algorithmic imperative language Algorithmic "imperative" language Undergraduate years Epita November 2014 The aim of this document is to introduce breiy the "imperative algorithmic" language used in the courses and tutorials during the

More information

Functional Logic Programming Language Curry

Functional Logic Programming Language Curry Functional Logic Programming Language Curry Xiang Yin Department of Computer Science McMaster University November 9, 2010 Outline Functional Logic Programming Language 1 Functional Logic Programming Language

More information

Designing Views to Answer Queries under Set, Bag,and BagSet Semantics

Designing Views to Answer Queries under Set, Bag,and BagSet Semantics Designing Views to Answer Queries under Set, Bag,and BagSet Semantics Rada Chirkova Department of Computer Science, North Carolina State University Raleigh, NC 27695-7535 chirkova@csc.ncsu.edu Foto Afrati

More information

perspective, logic programs do have a notion of control ow, and the in terms of the central control ow the program embodies.

perspective, logic programs do have a notion of control ow, and the in terms of the central control ow the program embodies. Projections of Logic Programs Using Symbol Mappings Ashish Jain Department of Computer Engineering and Science Case Western Reserve University Cleveland, OH 44106 USA email: jain@ces.cwru.edu Abstract

More information

Finding a winning strategy in variations of Kayles

Finding a winning strategy in variations of Kayles Finding a winning strategy in variations of Kayles Simon Prins ICA-3582809 Utrecht University, The Netherlands July 15, 2015 Abstract Kayles is a two player game played on a graph. The game can be dened

More information

Sets. Sets. Subset, universe. Specifying sets, membership. Examples: Specifying a set using a predicate. Examples

Sets. Sets. Subset, universe. Specifying sets, membership. Examples: Specifying a set using a predicate. Examples Sets 2/36 We will not give a precise definition of what is a set, but we will say precisely what you can do with it. Sets Lectures 7 and 8 (hapter 16) (Think of a set as a collection of things of which

More information

Let us dene the basic notation and list some results. We will consider that stack eects (type signatures) form a polycyclic monoid (introduced in [NiP

Let us dene the basic notation and list some results. We will consider that stack eects (type signatures) form a polycyclic monoid (introduced in [NiP Validation of Stack Eects in Java Bytecode Jaanus Poial Institute of Computer Science University of Tartu, Estonia e-mail: jaanus@cs.ut.ee February 21, 1997 Abstract The Java language is widely used in

More information

7. Decision or classification trees

7. Decision or classification trees 7. Decision or classification trees Next we are going to consider a rather different approach from those presented so far to machine learning that use one of the most common and important data structure,

More information

OpenMath and SMT-LIB

OpenMath and SMT-LIB James, Matthew England, Roberto Sebastiani & Patrick Trentin 1 Universities of Bath/Coventry/Trento/Trento J.H.@bath.ac.uk 17 July 2017 1 Thanks to EU H2020-FETOPEN-2016-2017-CSA project SC 2 (712689)

More information

SORT INFERENCE \coregular" signatures, they derive an algorithm for computing a most general typing for expressions e which is only slightly more comp

SORT INFERENCE \coregular signatures, they derive an algorithm for computing a most general typing for expressions e which is only slightly more comp Haskell Overloading is DEXPTIME{complete Helmut Seidl Fachbereich Informatik Universitat des Saarlandes Postfach 151150 D{66041 Saarbrucken Germany seidl@cs.uni-sb.de Febr., 1994 Keywords: Haskell type

More information

Exercise 1 ( = 22 points)

Exercise 1 ( = 22 points) 1 Exercise 1 (4 + 3 + 4 + 5 + 6 = 22 points) The following data structure represents polymorphic lists that can contain values of two types in arbitrary order: data DuoList a b = C a (DuoList a b) D b

More information

Algorithms for Learning and Teaching. Sets of Vertices in Graphs. Patricia A. Evans and Michael R. Fellows. University of Victoria

Algorithms for Learning and Teaching. Sets of Vertices in Graphs. Patricia A. Evans and Michael R. Fellows. University of Victoria Algorithms for Learning and Teaching Sets of Vertices in Graphs Patricia A. Evans and Michael R. Fellows Department of Computer Science University of Victoria Victoria, B.C. V8W 3P6, Canada Lane H. Clark

More information

14.1 Encoding for different models of computation

14.1 Encoding for different models of computation Lecture 14 Decidable languages In the previous lecture we discussed some examples of encoding schemes, through which various objects can be represented by strings over a given alphabet. We will begin this

More information

Program Calculus Calculational Programming

Program Calculus Calculational Programming Program Calculus Calculational Programming National Institute of Informatics June 21 / June 28 / July 5, 2010 Program Calculus Calculational Programming What we will learn? Discussing the mathematical

More information

Intro to Haskell Notes: Part 5

Intro to Haskell Notes: Part 5 Intro to Haskell Notes: Part 5 Adrian Brasoveanu October 5, 2013 Contents 1 Curried functions and related issues 1 1.1 Curried functions......................................... 1 1.2 Partially applied

More information

Overloading, Type Classes, and Algebraic Datatypes

Overloading, Type Classes, and Algebraic Datatypes Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

More information

Advanced Algorithms and Computational Models (module A)

Advanced Algorithms and Computational Models (module A) Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value

More information

Types, Expressions, and States

Types, Expressions, and States 8/27: solved Types, Expressions, and States CS 536: Science of Programming, Fall 2018 A. Why? Expressions represent values in programming languages, relative to a state. Types describe common properties

More information

How Efficient Can Fully Verified Functional Programs Be - A Case Study of Graph Traversal Algorithms

How Efficient Can Fully Verified Functional Programs Be - A Case Study of Graph Traversal Algorithms How Efficient Can Fully Verified Functional Programs Be - A Case Study of Graph Traversal Algorithms Mirko Stojadinović Faculty of Mathematics, University of Belgrade Abstract. One approach in achieving

More information

The Intersection of Two Sets

The Intersection of Two Sets Venn Diagrams There are times when it proves useful or desirable for us to represent sets and the relationships among them in a visual manner. This can be beneficial for a variety of reasons, among which

More information

Maciej Sobieraj. Lecture 1

Maciej Sobieraj. Lecture 1 Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Dierential-Linear Cryptanalysis of Serpent? Haifa 32000, Israel. Haifa 32000, Israel

Dierential-Linear Cryptanalysis of Serpent? Haifa 32000, Israel. Haifa 32000, Israel Dierential-Linear Cryptanalysis of Serpent Eli Biham, 1 Orr Dunkelman, 1 Nathan Keller 2 1 Computer Science Department, Technion. Haifa 32000, Israel fbiham,orrdg@cs.technion.ac.il 2 Mathematics Department,

More information

Talen en Compilers. Jurriaan Hage , period 2. November 13, Department of Information and Computing Sciences Utrecht University

Talen en Compilers. Jurriaan Hage , period 2. November 13, Department of Information and Computing Sciences Utrecht University Talen en Compilers 2017-2018, period 2 Jurriaan Hage Department of Information and Computing Sciences Utrecht University November 13, 2017 1. Introduction 1-1 This lecture Introduction Course overview

More information

Recursively Enumerable Languages, Turing Machines, and Decidability

Recursively Enumerable Languages, Turing Machines, and Decidability Recursively Enumerable Languages, Turing Machines, and Decidability 1 Problem Reduction: Basic Concepts and Analogies The concept of problem reduction is simple at a high level. You simply take an algorithm

More information

University of Utrecht. 1992; Fokker, 1995), the use of monads to structure functional programs (Wadler,

University of Utrecht. 1992; Fokker, 1995), the use of monads to structure functional programs (Wadler, J. Functional Programming 1 (1): 1{000, January 1993 c 1993 Cambridge University Press 1 F U N C T I O N A L P E A R L S Monadic Parsing in Haskell Graham Hutton University of Nottingham Erik Meijer University

More information

Relational Databases

Relational Databases Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 49 Plan of the course 1 Relational databases 2 Relational database design 3 Conceptual database design 4

More information

A stack eect (type signature) is a pair of input parameter types and output parameter types. We also consider the type clash as a stack eect. The set

A stack eect (type signature) is a pair of input parameter types and output parameter types. We also consider the type clash as a stack eect. The set Alternative Syntactic Methods for Dening Stack Based Languages Jaanus Poial Institute of Computer Science University of Tartu, Estonia e-mail: jaanus@cs.ut.ee Abstract. Traditional formal methods of syntax

More information

Dieter Gollmann, Yongfei Han, and Chris J. Mitchell. August 25, Abstract

Dieter Gollmann, Yongfei Han, and Chris J. Mitchell. August 25, Abstract Redundant integer representations and fast exponentiation Dieter Gollmann, Yongfei Han, and Chris J. Mitchell August 25, 1995 Abstract In this paper two modications to the standard square and multiply

More information

RAQUEL s Relational Operators

RAQUEL s Relational Operators Contents RAQUEL s Relational Operators Introduction 2 General Principles 2 Operator Parameters 3 Ordinary & High-Level Operators 3 Operator Valency 4 Default Tuples 5 The Relational Algebra Operators in

More information