Transitive Closure A binary relation is transitive if, whenever it contains the tuples

Size: px
Start display at page:

Download "Transitive Closure A binary relation is transitive if, whenever it contains the tuples"

Transcription

1 logic 63 Some useful facts about transpose: s.~r is equal to r.s, and is the image of the set s navigating backward through the relation r; r.~r is the relation that associates two atoms in the domain of the relation r when they map to a common element; when r is a function, r.~r is the equivalence relation that equates atoms with the same image. r.~r in iden therefore says that r is injective, and ~r.r in iden says that r is functional. Example. If mother is the relation that maps a child to its mother, the expression mother.~mother is the sibling relation that maps a child to its siblings (and also to itself). Discussion Why did you write ~r in r to say that r is symmetric? You might have expected ~r = r instead. The two conditions are equivalent, but I prefer the first because (1) it matches the informal statement more closely; (2) it follows the pattern of the conditions for reflexivity and transitivity; and (3) it s a good habit from an analysis perspective to write constraints in their weakest form. Admittedly, this is a bit pedantic, and it s not unreasonable to expect a definition of symmetry to be symmetric Transitive Closure A binary relation is transitive if, whenever it contains the tuples a -> b and b -> c, it also contains a -> c, or more succinctly as a relational constraint: r.r in r The transitive closure ^r of a binary relation r, or just the closure for short, is the smallest relation that contains r and is transitive. You can compute the closure by taking the relation, adding the join of the relation with itself, then adding the join of the relation with that, and so on: ^r = r + r.r + r.r.r + Example. A relation address representing an address book with multiple levels (which maps aliases and groups to groups, aliases, and addresses), and its transitive closure:

2 64 logic G0 A0 D0 G1 A1 D1 A2 D2 ^address - address address fig. 3.9 A snapshot illustrating transitive closure of a relation: the feint arcs represent the relation address; the solid arcs are those that are added to it to form its closure ^address. address = {(G0, A0), (G0, G1), (A0, D0), (G1, D0), (G1, A1), (A1, D1), (A2, D2)} ^address = {(G0, A0), (G0, G1), (A0, D0), (G1, D0), (G1, A1), (A1, D1), (A2, D2), (G0, D0), (G0, A1), (G1, D1), (G0, D1)} I ve broken the transitive closure into lines to indicate the contribution from the relation itself (on the first line), from its square address.address (on the second), and from its cube address.address. address (on the third). Fig. 3.9 shows the closure graphically. Viewing a relation as a graph, the transitive closure represents reachability. Since the relation itself represents the paths that are one step long, its square the paths that are two steps long, and so on, the closure relates one atom to another when they are connected by a path of any length (except for zero). A binary relation r is reflexive if it contains the tuple a -> a for every atom a, or as a relational constraint,

3 logic 65 iden in r The reflexive-transitive closure *r is the smallest relation that contains r and is both transitive and reflexive, and is obtained by adding the identity relation to the transitive closure: *r = ^r + iden From the graphical viewpoint, the reflexive-transitive closure relates one atom to another when they are connected by a path of any length, including zero. Because iden relates every atom in the universe to itself (as explained in section and the discussion that follows it), the reflexive-transitive closure will do so as well. Discussion Why does the reflexive-transitive closure associate irrelevant atoms? Suppose a model has a set Book of books, a set Name of names, a set Addr of addresses, a book b, and a relation addr mapping books to their contents, with the following values: Book = {(B0), (B1)} Name = {(N0), (N1)} Addr = {(D0), (D1)} b = {(B0)} addr = {(B0, N0, N1), (B0, N1, D0), (B1, N1, D1)} Then the universe will contain all the atoms univ = {(B0), (B1), (N0), (N1), (D0), (D1)} and the identity relation will map each to itself: iden = {(B0, B0), (B1, B1), (N0, N0), (N1, N1), (D0, D0), (D1, D1)} The expression ^(b.addr), denoting the direct and indirect mapping of names in book b to the names and addresses reachable, will map names to names and addresses: ^(b.addr) = {(N0, N1), (N1, D0), (N0, D0)} The expression *(b.addr) will include the tuples of both these relations. In addition to tuples such as (N0, N0), which are expected, it will also includes tuples such as (B0, B0).

4 66 logic Although this seems odd, it follows naturally from the definition of reflexive-transitive closure and the identity relation. The alternative would be to have sets implicitly associated with each relation that represent the possible members of its domain and range, which would complicate the logic. In practice this is not a problem. Closures often appear in navigation expressions, and the irrelevant self-tuples disappear in the join. For example, the names and addresses reachable in zero or more steps from a set of names friends would be denoted friends.*(b.addr), and would not include any books, because friends and Book would be disjoint. If you need to remove the extra tuples explicitly, you can always write s <: *r to restrict the closure to map only atoms in the set s. How many iterations can it take to form the closure of a relation? For a finite universe, transitive closure needs only a finite unwinding, limited by the length of the longest path in the graph. For some relations, the transitive closure requires very few unwindings even if the universe is large. Stanley Milgram s famous experiment in which he had residents of Kansas attempt to get letters to residents of Boston via acquaintances showed that it took on average only six steps for a letter to arrive [54]. If six steps were really enough to connect any two people, it would mean that the closure of the knows relation is the universal relation, and that it can be obtained in six unwindings Domain and Range Restrictions The restriction operators are used to filter relations to a given domain or range. The expression s <: r, formed from a set s and a relation r, contains those tuples of r that start with an element in s. Similarly, r :> s contains the tuples of r that end with an element in s. Restrictions can be applied to relations of any arity of two or more, but are most often applied to binary relations. Examples. Given a relation representing a multilevel address book and sets representing the aliases, groups, and addresses address = {(G0, A0), (G0, G1), (A0, D0), (G1, D0), (G1, A1), (A1, D1), (A2, D2)} Alias = {(A0), (A1), (A2)} Group = {(G0), (G1)} Addr = {(D0), (D1), (D2)}

5 logic 67 address :> Addr = {(A0, D0), (G1, D0), (A1, D1), (A2, D2)} contains the entries that map names to addresses (and not to other names); address :> Alias = {(G0, A0), (G1, A1)} contains the entries that map names to aliases; Group <: address = {(G0, A0), (G0, G1), (G1, D0), (G1, A1)} contains the entries that map groups. Applying a restriction to a binary relation is like taking the image of a set, but without dropping the matching elements. Put more formally, if r is a binary relation, and s is a set, then range (s <: r) = s.r domain (r :> s) = r.s The identity relation maps every atom in the universe to itself. Often, what we want instead is a relation that maps every atom in some set s to itself, which can be written s <: iden Override The override p ++ q of relation p by relation q is like the union, except that the tuples of q can replace the tuples of p rather than just augmenting them. Any tuple in p that matches a tuple in q by starting with the same element is dropped. The relations p and q can have any matching arity of two or more. Example. An address book might be represented by two relations, homeaddress and workaddress, mapping an alias to addresses at home and at work: homeaddress = {(A0, D1), (A1, D2), (A2, D3)} workaddress = {(A0, D0), (A1, D2)} The preferred address for an alias, which is the work address if it exists, and otherwise the home address, is given by homeaddress ++ workaddress = {(A0, D0), (A1, D2), (A2, D3)} Override can be defined in terms of simpler operators. Taking the override of p by q is equivalent to taking the union of q and what s left of p after removing the tuples that start with an element in the domain of q: p ++ q = p - (domain (q) <: p) + q Override is useful for modeling insertions into map datatypes, and assignment-like statements in programs.

6 68 logic Example. Insertion of a key k with value v into a hashmap can be modeled by representing the value of the map before and after as two relations m and m from keys to values, satisfying m = m ++ k -> v Example. The environment e of an executing Java program can be viewed (simplistically) as a relation mapping variables to object references. The effect of a Java assignment x = y with a variable on both sides can be modeled in Alloy as e = e ++ x -> y.e where e and e are the values of the environment before and after execution. The state of the heap at any point can be represented by one relation for each field (that is, instance variable) of each class. A setter statement such as x.f = y in which x and y are variables and f is a field can thus be described by f = f ++ x.e -> y.e where f and f represent the values of the field f before and after execution. Discussion What are the operator precedences? Operators have a standard precedence ranking so that constraints aren t marred by masses of parentheses. The ranking follows the usual conventions: unary operators (closure, transpose) precede binary operators; product operators (such as dot and arrow) precede sum operators (plus, minus, intersect). The details are given in appendix B. All operators associate to the left. 3.5 Constraints We ve seen how to make a constraint from two expressions using the comparison operators in and =. Larger constraints are made from smaller constraints by combining them with the standard logical operators, and by quantifying constraints that contain free variables over bindings.

7 logic Logical Operators There are two forms of each logical operator: a shorthand and a verbose form (similar to the operators used in boolean expressions in programming languages): not! negation and && conjunction or disjunction implies => implication iff <=> bi-implication The negation symbol can be combined with comparison operators, so a!= b is equivalent to not a = b, for example. The shorthand and the verbose forms are completely interchangeable, so you can write a not = b as well. There is an else keyword that can be used with the implication operator; F implies G else H is equivalent to (F and G) or ((not F) and H) Implications are often nested. The common idiom C1 implies F1 else C2 implies F2 else C3 implies F3 says that under condition C1, F1 holds, and if not, then under condition C2, F2 holds, and if not, under condition C3, F3 holds. Conjunctions of constraints are so common that we ll often omit the and operator, and wrap the entire collection of constraints in braces. So {F G H} is equivalent to F and G and H. Sometimes, it s more natural to use a conditional expression than a conditional formula. This takes the form or C implies E1 else E2 C => E1 else E2 where C is a constraint, and E1 and E2 are expressions, and has the value of E1 when C is true, and the value of E2 otherwise.

8 70 logic Examples. Suppose an address book is modeled with three relations: homeaddress and workaddress mapping an alias to addresses at home and at work, and address mapping an alias to the preferred address. To say that the preferred address for an alias a is the work address if it exists, otherwise the home address, we can write some a.workaddress => a.address = a.workaddress else a.address = a.homeaddress or, using a conditional expression a.address = some a.workaddress => a.workaddress else a.homeaddress Quantification A quantified constraint takes the form Q x: e F where F is a constraint that contains the variable x, e is an expression bounding x, and Q is a quantifier. The forms of quantification in Alloy are all x: e F F holds for every x in e; some x: e F F holds for some x in e; no x: e F F holds for no x in e; lone x: e F F holds for at most one x in e; one x: e F F holds for exactly one x in e. To remember what lone means, it might help to think of it as being short for less than or equal to one. Several variables can be bound in the same quantifier; one x: e, y: e F for example, says that there is exactly one combination of values for x and y that makes F true. Variables with the same bounding expression can share a declaration, so this constraint can also be written one x, y: e F By using the keyword disj before the declaration, you can restrict the bindings only to include ones in which the bound variables are disjoint from one another, so

9 logic 71 all disj x, y: e F means that F is true for any distinct combination of values for x and y. (See subsection for cases in which x and y are not scalars.) Examples. Given a set Address of addresses, Name of names, and a relation address representing a multilevel address book mapping names to names and addresses, some n: Name, a: Address a in n.address says that some name maps to some address (that is, the address book is not empty); no n: Name n in n.^address says that no name can be reached by lookups from itself (that is, there are no cycles in the address book); all n: Name lone d: Address d in n.address says that every name maps to at most one address; all n: Name no disj d, d : Address d + d in n.address says the same thing, but slightly differently: that for every name, there is no pair of distinct addresses that are among the results obtained by looking up the name. Quantifiers can be applied to expressions too: some e e has some tuples; no e e has no tuples; lone e e has at most one tuple; one e e has exactly one tuple. Note that some e and no e could be written e!= none and e = none respectively, but using the quantifiers makes the constraints more readable. Examples. Using the sets and relation from the previous example, some Name says that the set of names is not empty; some address says that the address book is not empty: there is some pair mapping a name to an address; no (address.addr - Name) says that nothing is mapped to addresses except for names; all n: Name lone n.address

10 72 logic says that every name maps to at most one address (more succinctly than in the previous example); all n: Name one n.address or no n.address says the same thing Higher-Order Quantification Quantified variables don t have to be scalars; they can be sets, or even multirelations. A logic that allows this is no longer first order and becomes higher order. Alloy includes such quantifications, but they cannot always be analyzed (see subsection 5.2.2). Examples. Higher-order quantifications are often useful for stating properties about operators: all s, t: set univ s + t = t + s the union operator on sets is commutative; all p, q: univ lone -> lone univ p.q in univ lone -> lone univ the join of two functions is a function too. Discussion Does Alloy allow freestanding declarations? The declaration forms described in this section can be used for quantified variables, and for fields, and they can be used as constraints (using in rather than the colon). Top-level relation declarations are not supported, as they are unnecessary (as explained in the discussion following section 4.2.2). When can higher-order quantifications be analyzed? Generally, the Alloy Analyzer cannot handle formulas that involve higher-order quantifications, so their use is discouraged. But in some useful cases, higher-order quantifiers can be eliminated by a scheme known as Skolemization, which turns a quantified variable into a free variable whose value can then be found by constraint solving. See subsection for more details. What s the difference between quantifiers and multiplicities? Novices are sometimes confused by the difference between these quantifications: lone p: some X F some p: lone X F

11 logic 73 What makes these confusing is the use of the same keywords for the quantifier and the bounding expression s multiplicity. In the first case, the quantifier is lone (at most one), and the multiplicity is some (one or more), so p is constrained to be drawn from the nonempty subsets of X, and the constraint says that F holds for at most one such subset p. In the second case, the quantifier is some, and the multiplicity is lone, so the constraint says that F holds for some option p, and is equivalent to (some p: X F) or (let p = none F) and is thus not really a higher-order quantification at all. I ve never come across a need for the first, but the second is occasionally useful. Does anyone really confuse quantifiers and multiplicities? Lest you think the last question was of purely academic interest, consider the following common (but surprisingly subtle) modeling mistake. Suppose you want to model the flushing of a line from a cache defined as a set of lines. You might be tempted to write something like one x: Line cache = cache - x reading it as pick one line so that the cache after is the cache before with that line removed. But this is not what the Alloy constraint actually means. Rather, it says there is exactly one line for which the old and new cache are related by that constraint. Note that, in particular, if the cache is empty before and after, the constraint will be false, because there will be multiple values of x in fact, any value for which the body holds. What you meant to write instead was some x: Line cache = cache - x namely that there is some line that can be removed from the cache before to obtain the cache after. This constraint allows for the cache to be empty before and after. If this were not desired, analysis would find the error, and you could then elaborate the formula, for example to some x: Line x in cache and cache = cache - x Let Expressions and Constraints When an expression appears repeatedly, or is a subexpression of a larger, complicated expression, you can factor it out. The form let x = e A

12 74 logic is short for A with each occurrence of the variable x replaced by the expression e. The body of the let, A, and thus the form as a whole, can be a constraint or an expression. Example. Revisiting the version of the address book with three relations homeaddress and workaddress mapping an alias to addresses at home and at work, and address mapping an alias to the preferred address we can say that the preferred address for an alias a is the work address if it exists, otherwise the home address, by writing or all a: Alias let w = a.workaddress a.address = some w implies w else a.homeaddress all a: Alias a.address = let w = a.workaddress some w implies w else a.homeaddress Discussion Can let bindings be recursive? No. They only provide a convenient shorthand, and don t allow recursive definitions. A variable introduced by a let on the left-hand side of a binding cannot appear on the right-hand side of the same binding, or one that precedes it in the same let construct Comprehensions Comprehensions make relations from properties. The comprehension expression {x 1 : e 1, x 2 : e 2,, x n : e n F} makes a relation with all tuples of the form x 1 -> x 2 -> -> x n for which the constraint F holds, and where the value of x i is drawn from the value of the bounding set expression e i. Each expression e i must denote a set, and not a relation of higher arity. Examples. In a multilevel address book represented by a relation address mapping names in the set Name to names and also to addresses in the set Addr,

13 logic 75 {n: Name no n.^address & Addr} is the set of names that don t resolve to any actual addresses; {n: Name, a: Addr n -> a in ^address} is a relation mapping names to addresses that corresponds to the multilevel lookup. 3.6 Declarations and Multiplicity Constraints A declaration introduces a relation name. We ve just seen how declarations are used in quantified constraints and comprehensions. Freestanding declarations of relation names make sense too, although we ll see in chapter 4 how, in the full Alloy language, these would instead be declared within signatures. The notion of multiplicity is closely tied to the notion of declaration. It s not essential in a logic, but I ve included it in this chapter because it s so useful, and can be explained independently of the structuring mechanisms of Alloy Declarations A constraint of the form relation-name : expression is called a declaration, and says that the relation named on the left has a value that is a subset of the value of the bounding expression on the right. The bounding expression is usually formed with unary relations and the arrow operator, but any expression can be used. In fact, as we shall see in the next two sections, the bounding expression on the right can actually be a more general form of expression that uses multiplicity symbols. Declarations in this form, with the colon as the operator, are used to declare bound variables in quantified formulas (section 3.5.2), and fields of signatures (section 4.2). But the same form can also constrain a previously declared variable, or an arbitrary expression (section 3.6.4), in which case the colon is replaced by the keyword in. Examples. The address relation, representing a single address book, maps names to addresses: address: Name -> Addr The addr relation, representing a collection of address books, maps books to names to addresses:

14 76 logic addr: Book -> Name -> Addr A relation address representing a multilevel address book maps names to names and addresses: address: Name -> (Name + Addr) The same relation can be declared in different ways, depending on how much information you want to put in the declaration. Example. A declaration saying that a relation address maps aliases and groups to addresses and to aliases and groups address: (Alias + Group) -> (Addr + Alias + Group) and a stronger declaration of the same relation, saying, in addition, that aliases, unlike groups, are always mapped directly to addresses: address: (Alias -> Addr) + (Group -> (Addr + Alias + Group)) Relations, not just sets, can appear on the right-hand side of declarations too. Example. An address book might be represented with three relations, representing the home, work, and preferred addresses: workaddress, homeaddress: Alias -> Addr prefaddress: workaddress + homeaddress Set Multiplicities A declaration can include multiplicity constraints, which are sometimes implicit. Multiplicities are expressed with the multiplicity keywords: set any number one exactly one lone zero or one some one or more Note that one, lone, and some are the same keywords used for quantification. The meaning of a declaration depends on the arity of the bounding expression. If it denotes a set (that is, is unary), it can be prefixed by a multiplicity keyword like this x: m e

15 logic 77 which constrains the size of the set x according to m. For a set-valued bounding expression, omitting the keyword is the same as writing one. So if no keyword appears, the declaration makes the variable a scalar. Examples RecentlyUsed: set Name says that RecentlyUsed is a subset of the set Name; senderaddress: Addr says that senderaddress is a scalar in the set Addr; sendername: lone Name says that sendername is an option: either a scalar in the set Name, or empty; receiveraddresses: some Addr says that receiveraddresses is a nonempty subset of Addr. The declarations of variables in quantified constraints are declarations of exactly the same form, and follow the same rules. The only difference is that quantifiers introduce variables that are bound within the body of the quantified constraint; the other declarations we have seen introduce free variables. Example. The quantification we saw above, some n: Name, a: Address a in n.address has two declarations, binding the scalars n and a Relation Multiplicities When the bounding expression is a relation (that is, a relation with arity greater than one), it may not be preceded by a multiplicity keyword. But if the bounding expression is constructed with the arrow operator, multiplicities can appear inside it. Suppose the declaration looks like this: r: A m -> n B where m and n are multiplicity keywords (and where A and B are, for now, sets). Then the relation r is constrained to map each member of A to n members of B, and to map m members of A to each member of B. Such a declaration can indicate the domain and range of the relation (see subsection 3.2.5), and whether or not it is functional or injective (see subsection 3.2.4): r: A -> one B a function whose domain is A;

16 78 logic r: A one -> B an injective relation whose range is B; r: A -> lone B a function that is partial over the domain A; r: A one -> one B an injective function with domain A and range B, also called a bijection from A to B; r: A some -> some B a relation with domain A and range B. Examples. Some declarations and their meaning: workaddress: Alias -> lone Addr The relation workaddress is a function that maps each member of the set Alias to at most one member of the set Addr; each alias represents at most one work address. homeaddress: Alias -> one Addr Each alias represents exactly one home address. members: Group lone -> some Addr An address belongs to at most one group, and a group contains at least one address. Multiplicities are just a shorthand, and can be replaced by standard constraints; the multiplicity constraint in r: A m -> n B can be written as all a: A n a.r all b: B m r.b but multiplicities are preferable because they are terser and easier to read. Example. The last declaration of the previous example members: Group lone -> some Addr can be replaced by members: Group -> Addr along with the constraints all g: Group some g.members

17 logic 79 all a: Addr lone members.a The expressions A and B can be arbitrary expressions, and don t have to be relation names. They also don t have to represent unary relations. The rule is generalized simply by replacing member by tuple. Thus r: A m -> n B says that r maps m tuples in A to each tuple in B, and maps each tuple in A to n tuples in B. Example. The declaration addr: (Book -> Name) -> lone Addr says that the relation addr associates at most one address with each address book and name pair Declaration Formulas Declarations usually introduce new names, but the same form can also be used to impose constraints on relations that have already been declared, or on arbitrary expressions. In this case, the subset operator in is used in place of the colon, and the term declaration formula is used. Example. For an address book represented by a relation address mapping groups and aliases to addresses address in (Group + Alias) -> Addr a declaration formula might say that each alias maps to at most one address: Alias <: address in Alias -> lone Addr A declaration formula is like any other formula, and can be combined with logical operators, placed inside the body of quantifications, and so on. Example. Given a relation addr associating address books, names and addresses, the constraint that each address book is injective (that is, maps at most one name to an address) can be written all b: Book b.addr in Name lone -> Addr Nested Multiplicities Multiplicities can be nested. Suppose you have a declaration of the form r: A -> (B m -> n C)

18 80 logic This means that, for each tuple in A, the corresponding tuples in B -> C form a relation with the given multiplicity. In the case that A is a set, the multiplicity constraint is equivalent to Similarly, all a: A a.r in B m -> n C r: (A m -> n B) -> C will be equivalent to all c: C r.c in A m -> n B Examples. The declaration addr: Book -> (Name lone -> Addr) says that, for any book, each address is associated with at most one name, and is equivalent to all b: Book b.addr in Name lone -> Addr whereas addr: (Book -> Name) lone -> Addr says that each address is associated with at most one book/name combination. The first allows an address to have different names in different books; the second does not. 3.7 Cardinality and Integers The operator # applied to a relation gives the number of tuples it contains, as an integer value. The following operators can be used to combine integers: plus minus mul div rem addition subtraction multiplication division remainder and the following to compare them: = equals < less than > greater than =< less than or equal to >= greater than or equal to

19 logic 81 Example. For a relation address address: (Group + Alias) -> Addr mapping groups and aliases to addresses, the constraint that every group has more than one address associated with it can be written all g: Group #g.address > 1 Example. Suppose an program needs to break groups of addresses into smaller subgroups. Given a relation mapping groups to the addresses they contain, address: Group -> Addr a second relation split: Group -> Group might map a group to its subgroups under the constraint that no group is a subgroup of itself no g: Group g in g.split that a group s subgroups contain all its addresses all g: split.group g.address = g.split.address and that the subgroups are disjoint all g: Group, disj g1, g2: g.split no g1.address & g2.address The cardinality constraints on the division into subgroups might be that any group with more than 5 members is split up all g: Group #g.address > 5 implies some g.split that no subgroup contains more than 5 members all g: Group.split #g.address =< 5 and that subgroups are of roughly equal size (differing from each other by at most one) all g: Group, disj g1, g2: g.split #g1.address < #g2.address implies #g2.address = #g1.address.plus[1] The expression e.sum denotes the sum of a set of integers e, and the expression sum x: e ie

20 82 logic denotes the integer obtained by summing the values of the integer expression ie for all values of the scalar x drawn from the set e. Example. The size of a group is the sum of the sizes of its subgroups: all g: split.group #g.address = (sum g : g.split #g.address) Discussion Why not use the standard symbol + for addition? An earlier version of Alloy used the same symbol for integer addition and relational union, but this complicated the language. The current version avoids any ambiguity by using distinct integer operators. What kind of form is x.plus[1]? You can think of plus, minus, etc. as predefined ternary relations representing the arithmetic operators. So this expression is just a standard join using dot and box, and could be written equivalently as plus[x,1], for example. Can integers be atoms in relations? Yes, they can. But the arithmetic operators and comparisons cannot be applied to sets, so in a formula such as S =< T, if S and T are sets of integers, the operator will actually compare their sums, as if you d written S.sum =< T.sum and similarly S.plus[T] will be short for (S.sum).plus[(T.sum)]. The equality operator, however, retains its standard meaning, so S = T will be false when S and T are distinct sets of integers, even if their sums are equal. This has the somewhat disturbing consequence that S =< T and T =< S implies S.sum = T.sum will always be true, but S =< T and T =< S implies S = T may not be. What kind of form is S.sum? That s a good question. Unfortunately, it can t be interpreted as a standard join, since the sum takes the entire set and produces a single in-

21 logic 83 teger (that is, a scalar) result. Think of sum as a special function, which, like equality, cannot be represented as a first-order relation.

CIS 771: Software Specifications. Lecture: Alloy Logic (part D)

CIS 771: Software Specifications. Lecture: Alloy Logic (part D) CIS 771: Software Specifications Lecture: Alloy Logic (part D) Copyright 2007, John Hatcliff, and Robby. The syllabus and all lectures for this course are copyrighted materials and may not be used in other

More information

From: FM 2006 Alloy Intro and Logic. Greg Dennis and Rob Seater Software Design Group, MIT

From: FM 2006 Alloy Intro and Logic. Greg Dennis and Rob Seater Software Design Group, MIT From: FM 2006 Alloy Intro and Logic Greg Dennis and Rob Seater Software Design Group, MIT agenda Intro & Logic Language & Analysis Dynamic Modeling M.C. Escher Observations Software is built on abstractions

More information

B.6 Types and Overloading

B.6 Types and Overloading 266 appendix b: alloy language reference B.6 Types and Overloading Alloy s type system was designed with a different aim from that of a programming language. There is no notion in a modeling language of

More information

Appendix B: Alloy Language Reference B.1 Lexical Issues

Appendix B: Alloy Language Reference B.1 Lexical Issues Appendix B: Alloy Language Reference B.1 Lexical Issues The permitted characters are the printing characters of the ASCII character set, with the exception of backslash \ backquote ` and, of the ASCII

More information

Conceptual modeling of entities and relationships using Alloy

Conceptual modeling of entities and relationships using Alloy Conceptual modeling of entities and relationships using Alloy K. V. Raghavan Indian Institute of Science, Bangalore Conceptual modeling What is it? Capture requirements, other essential aspects of software

More information

Alloy: A Lightweight Object Modelling Notation

Alloy: A Lightweight Object Modelling Notation Alloy: A Lightweight Object Modelling Notation Daniel Jackson, ACM Transactions on Software Engineering, 2002 Presented By: Steven Stewart, 2012-January-23 1 Alloy: 2002 to present Software is built on

More information

2.2 Syntax Definition

2.2 Syntax Definition 42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

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

CS:5810 Formal Methods in Software Engineering

CS:5810 Formal Methods in Software Engineering CS:5810 Formal Methods in Software Engineering Introduction to Alloy Part 2 Copyright 2001-17, Matt Dwyer, John Hatcliff, Rod Howell, Laurence Pilard, and Cesare Tinelli. Created by Cesare Tinelli and

More information

A.1 Numbers, Sets and Arithmetic

A.1 Numbers, Sets and Arithmetic 522 APPENDIX A. MATHEMATICS FOUNDATIONS A.1 Numbers, Sets and Arithmetic Numbers started as a conceptual way to quantify count objects. Later, numbers were used to measure quantities that were extensive,

More information

logic & language Daniel Jackson Lipari Summer School July 18-22, 2005

logic & language Daniel Jackson Lipari Summer School July 18-22, 2005 logic & language Daniel Jackson Lipari Summer School July 18-22, 2005 handshaking solution what this lecture s about a relational logic first-order logic + relational operators Alloy language signatures

More information

AXIOMS FOR THE INTEGERS

AXIOMS FOR THE INTEGERS AXIOMS FOR THE INTEGERS BRIAN OSSERMAN We describe the set of axioms for the integers which we will use in the class. The axioms are almost the same as what is presented in Appendix A of the textbook,

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 2.1-2.7 p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np Chapter 1: Introduction Introduction Purpose of the Theory of Computation: Develop formal mathematical models of computation that reflect real-world computers. Nowadays, the Theory of Computation can be

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections p.

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections p. CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections 10.1-10.3 p. 1/106 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer

More information

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Semantics via Syntax. f (4) = if define f (x) =2 x + 55. 1 Semantics via Syntax The specification of a programming language starts with its syntax. As every programmer knows, the syntax of a language comes in the shape of a variant of a BNF (Backus-Naur Form)

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

Model Finder. Lawrence Chung 1

Model Finder. Lawrence Chung 1 Model Finder Lawrence Chung 1 Comparison with Model Checking Model Checking Model (System Requirements) STM Specification (System Property) Temporal Logic Model Checker M φ Model Finder (http://alloy.mit.edu/tutorial3/alloy-tutorial.html)

More information

Chapter 3. Set Theory. 3.1 What is a Set?

Chapter 3. Set Theory. 3.1 What is a Set? Chapter 3 Set Theory 3.1 What is a Set? A set is a well-defined collection of objects called elements or members of the set. Here, well-defined means accurately and unambiguously stated or described. Any

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

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

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

MATH 22 MORE ABOUT FUNCTIONS. Lecture M: 10/14/2003. Form follows function. Louis Henri Sullivan

MATH 22 MORE ABOUT FUNCTIONS. Lecture M: 10/14/2003. Form follows function. Louis Henri Sullivan MATH 22 Lecture M: 10/14/2003 MORE ABOUT FUNCTIONS Form follows function. Louis Henri Sullivan This frightful word, function, was born under other skies than those I have loved. Le Corbusier D ora innanzi

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

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

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F 1 Logical Operations 1.1 And The and operator is a binary operator, denoted as, &,, or sometimes by just concatenating symbols, is true only if both parameters are true. A B A B F T F F F F The expression

More information

SWEN-220 Mathematical Models of Software

SWEN-220 Mathematical Models of Software SWEN-220 Mathematical Models of Software Introduction to Alloy Signatures, Fields, Facts, Predicates, and Assertions 2017 - Thomas Reichlmayr & Michael Lutz 1 Topics What is Alloy? Atoms, Sets, Relations

More information

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017 SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop AXIOMS OF AN IMPERATIVE LANGUAGE We will use the same language, with the same abstract syntax that we used for operational semantics. However, we will only be concerned with the commands, since the language

More information

CHAPTER 8. Copyright Cengage Learning. All rights reserved.

CHAPTER 8. Copyright Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS Copyright Cengage Learning. All rights reserved. SECTION 8.3 Equivalence Relations Copyright Cengage Learning. All rights reserved. The Relation Induced by a Partition 3 The Relation

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

2 Sets. 2.1 Notation. last edited January 26, 2016

2 Sets. 2.1 Notation. last edited January 26, 2016 2 Sets Sets show up in virtually every topic in mathematics, and so understanding their basics is a necessity for understanding advanced mathematics. As far as we re concerned, the word set means what

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2 2.2 Set Operations 127 2.2 Set Operations Introduction Two, or more, sets can be combined in many different ways. For instance, starting with the set of mathematics majors at your school and the set of

More information

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

Statistics Case Study 2000 M. J. Clancy and M. C. Linn Statistics Case Study 2000 M. J. Clancy and M. C. Linn Problem Write and test functions to compute the following statistics for a nonempty list of numeric values: The mean, or average value, is computed

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

9. Elementary Algebraic and Transcendental Scalar Functions

9. Elementary Algebraic and Transcendental Scalar Functions Scalar Functions Summary. Introduction 2. Constants 2a. Numeric Constants 2b. Character Constants 2c. Symbol Constants 2d. Nested Constants 3. Scalar Functions 4. Arithmetic Scalar Functions 5. Operators

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

Arithmetic Processing

Arithmetic Processing CS/EE 5830/6830 VLSI ARCHITECTURE Chapter 1 Basic Number Representations and Arithmetic Algorithms Arithmetic Processing AP = (operands, operation, results, conditions, singularities) Operands are: Set

More information

Reasoning About Programs Panagiotis Manolios

Reasoning About Programs Panagiotis Manolios Reasoning About Programs Panagiotis Manolios Northeastern University March 22, 2012 Version: 58 Copyright c 2012 by Panagiotis Manolios All rights reserved. We hereby grant permission for this publication

More information

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Solutions to Homework 10

Solutions to Homework 10 CS/Math 240: Intro to Discrete Math 5/3/20 Instructor: Dieter van Melkebeek Solutions to Homework 0 Problem There were five different languages in Problem 4 of Homework 9. The Language D 0 Recall that

More information

Alloy 3.0 Reference Manual

Alloy 3.0 Reference Manual Alloy 3.0 Reference Manual Daniel Jackson May 10, 2004 2004 Daniel Jackson Contributors to the design of the Alloy language include: Daniel Jackson, Manu Sridharan, Ilya Shlyakhter, Emina Torlak, Jonathan

More information

Relational Database: The Relational Data Model; Operations on Database Relations

Relational Database: The Relational Data Model; Operations on Database Relations Relational Database: The Relational Data Model; Operations on Database Relations Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin Overview

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

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

RSL Reference Manual

RSL Reference Manual RSL Reference Manual Part No.: Date: April 6, 1990 Original Authors: Klaus Havelund, Anne Haxthausen Copyright c 1990 Computer Resources International A/S This document is issued on a restricted basis

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

CS103 Spring 2018 Mathematical Vocabulary

CS103 Spring 2018 Mathematical Vocabulary CS103 Spring 2018 Mathematical Vocabulary You keep using that word. I do not think it means what you think it means. - Inigo Montoya, from The Princess Bride Consider the humble while loop in most programming

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

CHAPTER 3 FUZZY RELATION and COMPOSITION

CHAPTER 3 FUZZY RELATION and COMPOSITION CHAPTER 3 FUZZY RELATION and COMPOSITION The concept of fuzzy set as a generalization of crisp set has been introduced in the previous chapter. Relations between elements of crisp sets can be extended

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

(Refer Slide Time: 01.26)

(Refer Slide Time: 01.26) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.

More information

Chapter 2, Part III Arithmetic Operators and Decision Making

Chapter 2, Part III Arithmetic Operators and Decision Making Chapter 2, Part III Arithmetic Operators and Decision Making C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson

More information

CS:5810 Formal Methods in Software Engineering

CS:5810 Formal Methods in Software Engineering CS:5810 Formal Methods in Software Engineering Introduction to Alloy Part 1 Copyright 2001-17, Matt Dwyer, John Hatcliff, Rod Howell, Laurence Pilard, and Cesare Tinelli. Created by Cesare Tinelli and

More information

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and Chapter 6 The Relational Algebra and Relational Calculus Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Outline Unary Relational Operations: SELECT and PROJECT Relational

More information

Today s Topics. What is a set?

Today s Topics. What is a set? Today s Topics Introduction to set theory What is a set? Set notation Basic set operations What is a set? Definition: A set is an unordered collection of objects Examples: Sets can contain items of mixed

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information

Lecture 2: Big-Step Semantics

Lecture 2: Big-Step Semantics Lecture 2: Big-Step Semantics 1 Representing Abstract Syntax These are examples of arithmetic expressions: 2 * 4 1 + 2 + 3 5 * 4 * 2 1 + 2 * 3 We all know how to evaluate these expressions in our heads.

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

6. Relational Algebra (Part II)

6. Relational Algebra (Part II) 6. Relational Algebra (Part II) 6.1. Introduction In the previous chapter, we introduced relational algebra as a fundamental model of relational database manipulation. In particular, we defined and discussed

More information

Informatics 1 - Computation & Logic: Tutorial 4

Informatics 1 - Computation & Logic: Tutorial 4 Informatics 1 - Computation & Logic: Tutorial 4 Satisfiability and Resolution Week 6: 23-27 October 2017 Please attempt the entire worksheet in advance of the tutorial, and bring all work with you. Tutorials

More information

Sets. Margaret M. Fleck. 15 September 2010

Sets. Margaret M. Fleck. 15 September 2010 Sets Margaret M. Fleck 15 September 2010 These notes cover set notation, operations on sets, and how to prove claims involving sets (Rosen sections 2.1 and 2.2). They also cover some logic subtleties that

More information

A set with only one member is called a SINGLETON. A set with no members is called the EMPTY SET or 2 N

A set with only one member is called a SINGLETON. A set with no members is called the EMPTY SET or 2 N Mathematical Preliminaries Read pages 529-540 1. Set Theory 1.1 What is a set? A set is a collection of entities of any kind. It can be finite or infinite. A = {a, b, c} N = {1, 2, 3, } An entity is an

More information

Combinatorics Prof. Dr. L. Sunil Chandran Department of Computer Science and Automation Indian Institute of Science, Bangalore

Combinatorics Prof. Dr. L. Sunil Chandran Department of Computer Science and Automation Indian Institute of Science, Bangalore Combinatorics Prof. Dr. L. Sunil Chandran Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 5 Elementary concepts and basic counting principles So, welcome

More information

CSC 501 Semantics of Programming Languages

CSC 501 Semantics of Programming Languages CSC 501 Semantics of Programming Languages Subtitle: An Introduction to Formal Methods. Instructor: Dr. Lutz Hamel Email: hamel@cs.uri.edu Office: Tyler, Rm 251 Books There are no required books in this

More information

Set and Set Operations

Set and Set Operations Set and Set Operations Introduction A set is a collection of objects. The objects in a set are called elements of the set. A well defined set is a set in which we know for sure if an element belongs to

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #23 Loops: Precedence of Operators

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #23 Loops: Precedence of Operators Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #23 Loops: Precedence of Operators This one more concept that we have to understand, before we really understand

More information

Introduction to Programming, Aug-Dec 2008

Introduction to Programming, Aug-Dec 2008 Introduction to Programming, Aug-Dec 2008 Lecture 1, Monday 4 Aug 2008 Administrative matters Resource material Textbooks and other resource material for the course: The Craft of Functional Programming

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 20 Priority Queues Today we are going to look at the priority

More information

Lecture 3: Recursion; Structural Induction

Lecture 3: Recursion; Structural Induction 15-150 Lecture 3: Recursion; Structural Induction Lecture by Dan Licata January 24, 2012 Today, we are going to talk about one of the most important ideas in functional programming, structural recursion

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from Discrete Mathematics and It's Applications Kenneth H.

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

CS 512, Spring 2017: Take-Home End-of-Term Examination

CS 512, Spring 2017: Take-Home End-of-Term Examination CS 512, Spring 2017: Take-Home End-of-Term Examination Out: Tuesday, 9 May 2017, 12:00 noon Due: Wednesday, 10 May 2017, by 11:59 am Turn in your solutions electronically, as a single PDF file, by placing

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008

Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008 Math 202 Test Problem Solving, Sets, and Whole Numbers 19 September, 2008 Ten questions, each worth the same amount. Complete six of your choice. I will only grade the first six I see. Make sure your name

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

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

Stating the obvious, people and computers do not speak the same language.

Stating the obvious, people and computers do not speak the same language. 3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what

More information

1. Lexical Analysis Phase

1. Lexical Analysis Phase 1. Lexical Analysis Phase The purpose of the lexical analyzer is to read the source program, one character at time, and to translate it into a sequence of primitive units called tokens. Keywords, identifiers,

More information

CPS122 Lecture: From Python to Java

CPS122 Lecture: From Python to Java Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions): CS 70 Discrete Mathematics for CS Fall 2003 Wagner Lecture 7 This lecture returns to the topic of propositional logic. Whereas in Lecture 1 we studied this topic as a way of understanding proper reasoning

More information

CS Introduction to Data Structures How to Parse Arithmetic Expressions

CS Introduction to Data Structures How to Parse Arithmetic Expressions CS3901 - Introduction to Data Structures How to Parse Arithmetic Expressions Lt Col Joel Young One of the common task required in implementing programming languages, calculators, simulation systems, and

More information

Section 1.1 Definitions and Properties

Section 1.1 Definitions and Properties Section 1.1 Definitions and Properties Objectives In this section, you will learn to: To successfully complete this section, you need to understand: Abbreviate repeated addition using Exponents and Square

More information

Z Notation. June 21, 2018

Z Notation. June 21, 2018 Z Notation June 21, 2018 1 Definitions There are many different ways to introduce an object in a Z specification: declarations, abbreviations, axiomatic definitions, and free types. Keep in mind that the

More information

Lattice Tutorial Version 1.0

Lattice Tutorial Version 1.0 Lattice Tutorial Version 1.0 Nenad Jovanovic Secure Systems Lab www.seclab.tuwien.ac.at enji@infosys.tuwien.ac.at November 3, 2005 1 Introduction This tutorial gives an introduction to a number of concepts

More information

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02) Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 04 Lecture - 01 Merge Sort (Refer

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

An Interesting Way to Combine Numbers

An Interesting Way to Combine Numbers An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis October 12, 2016 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly

More information

Relations, Equivalence Relations, and Partial Orders

Relations, Equivalence Relations, and Partial Orders Massachusetts Institute of Technology Lecture 6 6.042J/18.062J: Mathematics for Computer Science February 17, 2000 Professors David Karger and Nancy Lynch Relations, Equivalence Relations, and Partial

More information

Lecture 6: Arithmetic and Threshold Circuits

Lecture 6: Arithmetic and Threshold Circuits IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Advanced Course on Computational Complexity Lecture 6: Arithmetic and Threshold Circuits David Mix Barrington and Alexis Maciel July

More information