Description of background ideas, and the module itself.

Size: px
Start display at page:

Download "Description of background ideas, and the module itself."

Transcription

1 CO3008 Semantic of Programming Language 1 Chapter 1 Decription of background idea, and the module itelf. Review ome mathematic.

2 CO3008 Semantic of Programming Language 2 Overview: Background Introduction to MC308 What i a Language? What i a Programming Language? What i Syntax? What i Semantic?

3 CO3008 Semantic of Programming Language 3 Two kind of language Natural language: Some Anwer Recognized method of communicating thought and feeling: peech, hand ignal, ending gift... Formal language: A rigourouly defined ytem to convey meaning or information. We do not have a precie definition of language. Try looking up language in, ay, the Cambridge Encyclopaedia of Language.

4 CO3008 Semantic of Programming Language 4 Programming Language are formal language ued to communicate with a computer. Programming language may be low level. They give direct intruction to the computer (machine code). Programming language may be high level. The intruction given to the computer are indirect, but much cloer to general concept undertood by the uer (Java, C++,... ).

5 CO3008 Semantic of Programming Language 5 Syntax refer to particular arrangement of word and letter eg David hit the ball or if t 2 then H = Off. A grammar i a et of rule which can be ued to pecify how yntax i created. Example can be een in automata theory, or programming manual. Theorie of yntax and grammar can be developed idea are ued in compiler contruction.

6 CO3008 Semantic of Programming Language 6 Semantic i the tudy of meaning. In particular, yntax can be given meaning. The word run can mean execution of a computer program, pread of ink on paper,... Programming language yntax can be given a emantic. We need thi to write program.

7 CO3008 Semantic of Programming Language 7 Semantic decription are often informal. Conider while (expreion) command ; adapted from Kernighan and Ritchie 1978/1988, p 224: The command i executed repeatedly o long a the value of the expreion remain unequal to 0; the expreion mut have arithmetic or pointer type. The tet, including all ide effect from the expreion, occur before each execution of the command. We want to be more precie, more uccinct.

8 P CO3008 Semantic of Programming Language 8 High Level view of MC308 For variou language we hall define yntax for program P and type σ ; define type aignment P :: σ ; define operational emantic looking like P P or P V define algorithm to check that P :: σ; and compile P to a lit of machine intruction P.

9 CO3008 Semantic of Programming Language 9 Overview: Dicrete Mathematic We briefly review Logic Set Relation Function

10 CO3008 Semantic of Programming Language 10 Logic If P and Q are propoition, we can form new propoition a follow: P implie Q (ometime written P... ee the note. for all x, P (ometime written x P); Q or P Q); We hall often prove propoition of the form x X P x P where x i a propoition depending on x, and X i a given et. Eg n 2n 1i odd

11 B, interection A A and b CO3008 Semantic of Programming Language 11 Set We aume a et i undertood. A or B or... often ued to denote et. Write a Afor element of. If a i not an element of A, we write a A. Union A known. B, hould already be The carteian product of A and B i a et given by A B def a b a B

12 b CO3008 Semantic of Programming Language 12 Relation A relation R between et A and B i a ubet R A B. A binary relation R on A i a relation between A and A. If R A intead of B i a relation, it i convenient to write a R b a b R. R i reflexive iff for all a A we have a R a; R i tranitive iff for all a implie a R c; c A, a R b and b R c For example.

13 CO3008 Semantic of Programming Language 13 Function You hould know what a (total) function f :A You hould know what a partial function f :A B i. B i. Recall undefinedne and application notation, compoition, and domain of definition.

14 CO3008 Semantic of Programming Language 14 Chapter 2 Define abtract yntax tree a bit like pare tree. Explain inductive definition. Explain Rule Induction.

15 CO3008 Semantic of Programming Language 15 Overview: Abtract Syntax Outline the idea of concrete yntax (eg program a acii file) and abtract yntax (the pare tree of program).

16 CO3008 Semantic of Programming Language 16 Abtract and Concrete Syntax The text tring if true then 2 ele 3 i concrete yntax. A compiler will recognize a conditional expreion (an if-then-ele ) and three data, namely the Boolean and the two number. The three data, together with the knowledge that the tring denote a conditional, make up the emantic content of the expreion.

17 2 T 2 CO3008 Semantic of Programming Language 17 We can capture thi emantic content a a tree T 2 3 which can be denoted by the formal notation T 3 and informally by the ugared notation 3 Lexer and parer tranform text program into pare tree, ometime referred to a abtract yntax.

18 B 0 CO3008 Semantic of Programming Language 18 Here i another example of ugared tree notation l 0 l l It ha the form E1 E2 where, for example, B i l. The abtract yntax tree i l l l Think of the conditional a a contructor which act on three argument (ubprogram) to contruct a new program.

19 T CO3008 Semantic of Programming Language 19 In CO3008 we need to give precie definition of abtract yntax tree. An example: Let C l 1 l 2 l 3 c1 c 2 are label for tree node. We can pecify a et of finite be a et of contructor, which tree built from thi et by a grammar of the form T :: l1 l 2 l 3 c 1 T T c 2 T T

20 CO3008 Semantic of Programming Language 20 You need to undertand the definition of node leaf root contructor (a label for any node) children (of non-leaf node) ubtree We alo talk about ubprogram, ubexpreion outermot contructor ( = root label).

21 CO3008 Semantic of Programming Language 21 Overview: Inductively Defined et Specify inductively defined et; program, type etc will be defined thi way. BNF grammar are a form of inductive definition; abtract yntax tree were defined inductively. Define Rule Induction; propertie of program will be proved uing thi. It i important.

22 A CO3008 Semantic of Programming Language 22 Example Inductive Definition Let Var be a et of propoitional variable. Then the et Prpn of propoition of propoitional logic i inductively defined by the rule P P Var φ φ ψ ψ φ ψ φ ψ φ φ ψ φ ψ φ Each propoition i created by a deduction...

23 CO3008 Semantic of Programming Language 23 Two More Example A et R of rule for defining the et E number i R 6 R1 R2 0 R1 where E iff there i a deduction of 6. e e 2 R2 of even Suppoe that Σ i any et, which we think of a an alphabet. Each element l of Σ i letter. We inductively define the et Σ of word over the alphabet Σ by l l Σ 1 w ww w 2

24 R CO3008 Semantic of Programming Language 24 Some Notation for Rule A rule R i a pair H c where H i any finite et. Note that H might be i a bae rule., in which cae we ay that R c R If H i non-empty (ay H h 1 hk where 1 k) we ay R i an inductive rule. h 1 h 2 hk c

25 c CO3008 Semantic of Programming Language 25 that Inductively Defined Set Given a et of rule, a deduction i a finite tree uch each leaf node label c occur a a bae rule R for any non-leaf node label c, if H i the et of children of c then R i an inductive rule. H c The et I inductively defined by R conit of thoe element e which have a deduction with root node e.

26 R2 u3 u3 CO3008 Semantic of Programming Language 26 An Abtract Example Let R be the et of rule R1 R 3 R4 where R 1 u1 R2 u3 R3 u 1 u3 u4 R 4 u 1 u 4 u5 R5 u 2 u3 u6 Then a deduction for u 5 i given by u 1 u 3 u 1 u 3 u 1 u 3 u 4 u 5 u 1 u 3 u 4 u 5 The inductively defined et i I u 1 u 4 u5

27 CO3008 Semantic of Programming Language 27 Rule Induction Let I be inductively defined by a et of rule R. Suppoe we wih to how the truth of i I φ i To do thi, it i enough to how for every bae rule b R that φ b hold; and for every inductive rule h 1 whenever h i I, φ c hk R prove that h 1 and φ h 2 and and φ h k implie φ c We call φ out the h j inductive hypothee. We refer to carrying tak a verifying property cloure.

28 T L T2 N T2 CO3008 Semantic of Programming Language 28 Example Conider the et of tree T defined inductively by n n T1 T 1 T 2 T2 Let L number of T be the number of leave in T, and N -node of T. We prove T T L T N T 1 be the where the function L N:T are defined recurively by L n 1 and L T1 T2 T 1 L N n 0 and N T1 T2 T 1 N 1

29 CO3008 Semantic of Programming Language 29 Chapter 3 Decribe the program (yntax) of a imple imperative language called IMP. Review and motivate type. Give a type ytem to IMP. Decribe compile time type checking and type inference.

30 CO3008 Semantic of Programming Language 30 Overview: Syntax for IMP Program Decribe the baic building block for program. Specify the program expreion. Comment on ome grammatical convention.

31 Syntax for 1 1 CO3008 Semantic of Programming Language 31 Program Expreion for IMP built out of element of the et def def 0 T F Loc ICt BCt IOpr BOpr def def def def def l 1 n b l 2 n b (** NB **)

32 BOpr aign cond CO3008 Semantic of Programming Language 32 The et of expreion contructor i pecified by Loc ICt kip equence while The program expreion are given by P :: ccontant l iop P P P l memory location integer operator P aignment P P P while loop P equencing

33 CO3008 Semantic of Programming Language 33 We adopt ome abbreviation (known a yntactic ugar): We write P iop P for iop P P ; l : P for P l ; P ; P for P P ;... Bracketing convention: Arithmetic operator group to the left. Thu P 1 op P 2 op P 3 abbreviate Sequencing aociate to the right. P1 op P2 op P 3

34 CO3008 Semantic of Programming Language 34 Overview: Type for IMP Program Explain what a type i. Motivate the ue for type. Explain ome terminology. Define IMP type checking (compilation check). Define IMP type inference.

35 CO3008 Semantic of Programming Language 35 Defining and Motivating Type Type in a programming language are collection of object ( et ), with collection of operation acting on thee object. The type int conit of the collection of integer, together with operation uch a might be pecified a,, and o on. The action of int int bool

36 CO3008 Semantic of Programming Language 36 Statically typed language carry out type checking at compile-time. Need ome explicit type information. Ue of type Expreion organized to reduce program error. Polymorphim mean function can have many type. Thi allow code re-ue. Type tructure data, uing ADT and module.

37 CO3008 Semantic of Programming Language 37 Run time error trapped error execution halt immediately. An untrapped error execution doe not necearily halt. An example i acceing data pat the end of an array, which one can do in C! A language i afe if all yntactically legal program do not yield certain run-time error. JAVA wa claimed to be afe, but in 1997 thi wa hown not to be the cae. Proof ue MC 308 method!

38 CO3008 Semantic of Programming Language 38 Technical Definition If P can be aigned a type σ we write P :: σ and call the tatement a type aignment. Type afety i the property that if P :: σ then certain kind of error can not occur at P run-time. Given P and σ, type checking validate P :: σ. Given P, type inference i the proce of trying to find σ for which P :: σ the proce can fail.

39 CO3008 Semantic of Programming Language 39 Type for IMP The type of the language grammar σ :: are given by the A location environment L i a finite et of (location, type) pair, with type being jut or: L l1 :: l n :: l n 1 : : l m :: Given L, then any P whoe location all appear in L can (ometime) be aigned a type; we write P :: σ to indicate thi.

40 CO3008 Semantic of Programming Language 40 n :: [any n ] :: INT T :: :: TRUE F :: l :: l :: L P1 :: P2 :: P1 bop P2 :: [ bop BOpr] :: BOP :: l :: σ P :: σ l : P :: P1 :: P2 :: P3 :: P1 :: P2 :: P1 P3 :: P2 P1 P2 ::

41 CO3008 Semantic of Programming Language 41 Example: Deduction of a Type Aignment l :: l l 5 :: 5 :: 5 D2 l : 1 l : l l : l 1 ; l D3 1 ; l D4 : l l :: : l l ::

42 CO3008 Semantic of Programming Language 42 Type Inference Given L and P, there i an algorithm which will infer if P can be aigned a type. If uch a type exit we ay P i typable. The algorithm will ucceed and will output the type. If not, the algorithm fail. In a real language, uch type inference i often performed by the compiler. Given L and P, we define a function Φ which given P a input will either return a type for P, or will FAIL.

43 T P1 bop P2 P2 CO3008 Semantic of Programming Language 43 Φ Φ l τ FAIL if l :: τ L otherwie and τ or Φ if Φ FAIL otherwie P1 and Φ

44 P or CO3008 Semantic of Programming Language 44 Φ l : P if Φ l and τ Φ FAIL otherwie τ Φ P1 P2 if Φ FAIL otherwie P1 and Φ P2

45 CO3008 Semantic of Programming Language 45 Chapter 4 Explain how IMP programme execute an operational emantic. Show that the type of a program doe not change on execution. Show that a program alway give the ame anwer when run IMP i determinitic. Typed program don t yield certain error.

46 CO3008 Semantic of Programming Language 46 Overview: Tranition Semantic Motivate and define tranition emantic a method for tating preciely how a program execute. Give ome example.

47 CO3008 Semantic of Programming Language 47 State A tate i a partial function Loc. For example l1 4 l 2 T l 3 21 There i a tate denoted by l c : Loc which i the partial function l c l def c l if l l otherwie We ay that tate i updated at l by c.

48 CO3008 Semantic of Programming Language 48 Tranition Semantic Conider the following tranition, which model one tep in a program execution l :2 5 l 8 l :7 l 8 l 8 l 7 The element of Exp configuration. State will be known a Wehall inductively define a binary relation. We call it tranition relation, and any intance of a relationhip in i called a tranition tep.

49 P1 P2 P1 P2 P1 op P P2 op P P1 P2 CO3008 Semantic of Programming Language 49 l l provided that l i defined OP1 n op P1 n op P2 OP2 n1 op n2 n1 op n2 OP3 l : P1 l :P2 ASS1 l : c l c ASS2 LOC

50 P T P P1 ; P P1 CO3008 Semantic of Programming Language P2 ; P P2 2 2 P SEQ1 ; P SEQ2 P1 P2 P P P1 P2 COND1 P1 P2 P1 COND2 P1 P2 P1 P2 ; P1 P2 LOOP

51 2 ; l : 2 ; l : CO3008 Semantic of Programming Language 51 Example of Tranition A deduction (for any P): l l : : l : 2 l l 1 1 ; P l 2 ; l : l ASS2 1 ; l : l l 2 1 ; P SEQ1 l 2 SEQ1

52 CO3008 Semantic of Programming Language 52 Q i l 0 Q where Q i l : l 2 ; l : l 1. Q l 1 l 0 l 0 Q ; Q l 1 l Q ; Q l 1 l 0 T Q ; Q l 1 l 0 l : 2 ; l : l 1 ; Q l 1 l 0 ; l : l 1 ; Q l 1 l 2 l : l1 ; Q l 1 l 2

53 CO3008 Semantic of Programming Language 53 Overview: Propertie of the Semantic Program type do not change on execution. IMP i determinitic the final reult of a program run i unique; and in fact the tage of the run are unique.

54 or CO3008 Semantic of Programming Language 54 Type Preervation Given L, i enible for L if for all l :: σ in L (l) i defined (all location initialized), and l:: σ (the type of data tored in a location matche the type of the location). Take L and enible 1. Then atifie Let P 1 :: σ. Then for any P1 1 P2 2 we have P 2 :: σ. Further, if σ i either, then 1 2.

55 P1 :: σ implie P2 : : σ CO3008 Semantic of Programming Language 55 Proving Type Preervation P1 1 P2 2 σ We have to check property cloure for each of the rule defining. We look at a couple of example. (Property Cloure for LOC) We have to how that l :: σ implie l :: σ for any σ. Thi i immediate a i enible.

56 P1 :: σ implie P2 : : σ CO3008 Semantic of Programming Language 56 (Property Cloure for OP2) The induction hypothei i σ IH P1 n op P 1 P2 n op P 2 OP2 We have to prove σ n op P 1 :: σ implie n op P 2 :: σ C

57 The operational emantic of CO3008 Semantic of Programming Language 57 IMP i Determinitic i determinitic: If P P and P P then P P and

58 CO3008 Semantic of Programming Language 58 Proof of Determinim We can prove thi reult by Rule Induction. We how P P X x P X x implie X P and x

59 z y P2 and y CO3008 Semantic of Programming Language 59 We conider property cloure for P1 l : P1 P2 l : P2 ASS1 The inductive hypothei IH i Y P1 Y y implie Y We need to prove the concluion C Z l: P1 Z z implie Z l: P2 and z

60 CO3008 Semantic of Programming Language 60 Overview: IMP i Type Safe We decribe ome pecial program; we decribe ome pecial kind of tranition, and ue the idea to how IMP i type afe.

61 CO3008 Semantic of Programming Language 61 Different Kind of Tranition We define V :: c. V configuration are called terminal. They indicate proper termination of program run. Any configuration and there i no P P for which i tuck if P i non-terminal P P. WARNING: Note that any terminal configuration ha no tranition.

62 CO3008 Semantic of Programming Language 62 Given any configuration P there i a unique equence of tranition P P1 1 P2 2 An infinite tranition equence take the form P P1 1 P2 2 Pi i where no configuration Pi i i terminal or tuck.

63 CO3008 Semantic of Programming Language 63 A P finite tranition equence for a configuration take the form P P1 1 P2 2 Pm m m 1 If Pm m i either tuck or terminal we call the tranition equence complete. Make up lot of example of thee idea!!

64 CO3008 Semantic of Programming Language 64 Some Reult about IMP Type Safety Let be enible for L. Then if P :: σ i any type aignment, P i not tuck. If alo P P, then i alo enible. If P P, then might be terminal). Thu P cannot be tuck (but i type afe. Thi follow from the two reult above why?

65 or CO3008 Semantic of Programming Language 65 We prove P :: σ P i not tuck by Rule Induction on type aignment. (Property Cloure for :: IOP) The inductive hypothee are that neither are tuck, where P1 : : P1 P 2 and P2 ::. We have to prove that P1 iop P2 i not tuck, where P 1 iop P 2 ::. Let work thi on the board...

66 CO3008 Semantic of Programming Language 66 We prove, for a given L, P P σ (P::σ and enible) implie enible by rule induction for. We check property cloure for l : c l c ASS2 Suppoe i enible, and l : c :: σ. We need to verify that l c i enible, that i All location in L are in the domain of definition of l c. l :: τ in L we have l c l :: τ.

67 CO3008 Semantic of Programming Language 67 Overview: Evaluation Relation We decribe a emantic which tell u immediately the final reult of a program run. We how how thi connect with tranition.

68 T ; l : and CO3008 Semantic of Programming Language 68 An Evaluation Relation Conider the following evaluation relationhip l : 4 1 l T l 5 The idea i Starting program final reult We decribe an operational emantic which ha aertion which look like P n P 1 2

69 P1 ; P2 P1 P P1 P1 bop P2 provided l CO3008 Semantic of Programming Language 69 l l domain of n1 P2 n1 bop n2 n2 OP2 l :P l n n ASS1 l :P l P b b ASS P SEQ LOC

70 P F P1 P1 P CO3008 Semantic of Programming Language 70 1 F 1 P2 P1 1 P COND2 1 T 1 P2 1 2 P1 P2 2 3 P1 P2 1 3 P1 P2 LOOP2

71 CO3008 Semantic of Programming Language 71 We derive deduction for Example Evaluation and l 1 l : l 1 l 1 l 0

72 CO3008 Semantic of Programming Language 72 A Mutual Correctne Proof For any configuration V, P P V and terminal configuration iff P V where denote reflexive, tranitive cloure of.

73 CO3008 Semantic of Programming Language 73 We break the proof into three part: Prove Induction. P V implie P V by Rule Prove by Rule Induction for that P P V implie P V Ue previou reult to deduce P V implie P V

74 H1 H2 H3 P2 1 2 P1 P V P V CO3008 Semantic of Programming Language 74 We hall prove by Rule Induction that We need to prove that P1 1 P2 2 T 1 3 P1 P2 1 3 C

75 LOOP T H1 H2 H3 Q P2 ; Q Q CO3008 Semantic of Programming Language 75 Let u write Q for P1 P2. Then 1 P1 P2 ; Q 1 P2 ; Q 1 & COND1 1 COND2 ; Q 2 & SEQ1 2 SEQ2 3 which prove (C).

76 LOOP COND1 CO3008 Semantic of Programming Language 76 We hall prove by Rule Induction for that P P V P V implie P V Let u jut conider property cloure for the rule any V and uppoe that. Pick P1 P2 ; Q V 1 We need to how that Q V 2 But (1) can hold only if it ha been deduced either from or COND2. In either cae V mut be.

77 CO3008 Semantic of Programming Language 77 Chapter 5 Decribe the CSS machine, which execute compiled IMP program. Show how to compile IMP program to CSS intruction equence. Give ome example execution.

78 CO3008 Semantic of Programming Language 78 Motivating the CSS Machine An operational emantic give a ueful model of we eek a more direct, computational method for evaluating configuration. If P e V, how do we effectively compute V from P? The tranition relation i not quite right. It i eay for human to ee that but etablihing thi involve a deduction tree...

79 CO3008 Semantic of Programming Language 79 We eek a way of taking a program P, and mechanically producing the value V : P P 0 P1 P2 Pn V Mechanically produce can be made precie uing a relation P Pdefined by a et of rule in which there are no hypothee. Such rule are called re-write: n m m n Etablihing P deduction tree: P will not require the contruction of a

80 CO3008 Semantic of Programming Language 80 P 0 P1 P2 P3 P4 V Rewrite Rule (Abtract Machine) deduction tree deduction tree deduction tree P 0 P1 P 2 V Tranition Semantic

81 CO3008 Semantic of Programming Language 81 An Example Let l 6. Execute 10 l on the CSS machine. Firt, compile the program. 10 l FETCH l : PUSH 10 : OP Then FETCH l : PUSH 10 : OP PUSH 10 : OP 6 OP 10 : 6 4

82 FETCH OP BR CO3008 Semantic of Programming Language 82 Defining the CSS Machine A CSS code C i a lit : in ::PUSH c l op SKIP STO l C C LOOP C C C :: in in : C The object in are CSS intruction. A tack σ i produced by the grammar σ :: c c : σ

83 σ σ1 σ2 CO3008 Semantic of Programming Language 83 A CSS configuration i a triple C. A CSS tranition take the form C1 1 C2 2 Defined inductively by a et of rule, each rule having the form C1 σ1 1 C2 σ2 2 We call a binary relation (uch a) which i inductively defined by rule with no hypothee a re-write relation. R

84 C2 : LOOP l CO3008 Semantic of Programming Language 84 PUSH c : C σ C c : σ FETCH l : C σ C l : σ OP op : C n 1 : n 2 : σ C n1 op n2 : σ SKIP : C σ C σ STO l : C c : σ C σ c BR C1 C2 : C F : σ C2 : C σ LOOP C1 C2 : C σ C 1 : BR C 1 C2 SKIP : C σ

85 P CO3008 Semantic of Programming Language 85 c def PUSH c l def FETCH l l : P P1 op P2 P2 def def def SKIP : P1 P : STO l : OP op P1 P2 P1 ; P2 def def P1 : P2 P P1 P2 P1 P2 def LOOP P1 P2 : BR

86 CO3008 Semantic of Programming Language 86 An Example Execution Execute l : 2 ; l the program. : 5l on the CSS machine. Firt, compile l : 2 ; l : 5l PUSH 2 : STO l : FETCH l : PUSH 5 : OP : STO l Then PUSH 2 : STO l : FETCH l : PUSH 5 : OP : STO l l 2 l 10

87 CO3008 Semantic of Programming Language 87 Chapter 6 Motivate a language in which we can write higher order function. Decribe it type. Decribe it expreion yntax. Outline a type aignment ytem. Explain how to write imple program.

88 CO3008 Semantic of Programming Language 88 Overview: Motivating and Defining FUN Give a broad outline of FUN. Define it yntax and type ytem. Explain ome technical convention and definition.

89 CO3008 Semantic of Programming Language 89 ct :: Int ct = 76 Example of FUN Declaration f :: Int -> Int f x = x g :: Int -> Int -> Int g x y = x+y h :: Int -> Int -> Int -> Int h x y z = x+y+z

90 CO3008 Semantic of Programming Language 90 empty_lit :: [Int] empty_lit = nil l1 :: [Int] l1 = 5:(6:(8:(4:(nil)))) l2 :: [Int] l2 = 5:6:8:4:nil h :: Int h = hd (5:6:8:4:nil)

91 CO3008 Semantic of Programming Language 91 p :: (Int,Int) ft :: (Int,Int) -> Int length :: [Bool] -> Int map :: (Int -> Bool) -> [Int] -> [Bool] p = (3,4) ft (x,y) = x length l = if elit(l) then 0 ele (1 + length t) map f l = if elit(l) then nil ele (f h) : (map f t)

92 σ σ2 σn σ2 CO3008 Semantic of Programming Language 92 FUN Type The type of e are σ :: σ σ σ σ We hall write Type for the et of type. We hall write σ 1 σ 3 σ for σ 1 σ2 σ3 σn σ Thu for example σ 1 σ 3 mean σ 1 σ2 σ3.

93 CO3008 Semantic of Programming Language 93 FUN Expreion E :: xvariable contant identifier function identifier E 1 E 2 E 1 : E 2 Bracketing convention apply... E E E firt projection function application tail of lit con for lit Boolean tet for empty lit

94 x x y z CO3008 Semantic of Programming Language 94 Subtitution (for next chapter) E The variable x occur in the expreion x op 3 op x. If E and E 1 E1 En x 1 En are expreion, then xn denote the expreion E with Ei imultaneouly replacing x i for each 1 Eg i n. u y 6 2 z u x 2 x 6

95 CO3008 Semantic of Programming Language 95 Overview: FUN Type Sytem Show how to declare the type of variable and identifier; an identifier i (the name of) a contant or function. Define a type aignment ytem. Give ome example. Verify that FUN i monomorphic each program ha a unique type.

96 CO3008 Semantic of Programming Language 96 Context When we write a FUN program, we hall declare the type of variable, for example x :: y : : z : : A context take the form Γ x1 :: σ1 xn : : σn Thu a context pecifie type declaration for variable. The variable mut be ditinct.

97 CO3008 Semantic of Programming Language 97 Environment When we write a FUN program, we want to declare the type of contant and function. A imple example of an identifier environment i :: :: and another i :: and another i :: :: ::

98 CO3008 Semantic of Programming Language 98 σ 1 An identifier type look like σ2 σ 3 number and σ i NOT a function type. σk σ where k i a natural If k If k 0 then the identifier i called a contant. 0 then the identifier i called a function. An identifier environment look like I 1 :: ι 1 m : : ιm

99 y : : z : : CO3008 Semantic of Programming Language 99 Example Type Aignment With the previou identifier environment x :: x : y : z : :: We have T 2 : 2 : 6 : ::

100 CO3008 Semantic of Programming Language 100 E1 : : E1 iop E2 : : E2 : : n : : Inductively Defining Type Aignment Start with an identifier environment and a context. Then Γ x :: σ where x :: σ Γ :: VAR Γ :: INT Γ Γ Γ :: OP1

101 σ σ CO3008 Semantic of Programming Language 101 Γ E 1 :: σ 2 σ1 Γ E 2 :: σ 2 :: AP Γ E1 E2 :: σ1 Γ Γ E :: E :: σ 1 σ1 σ2 :: FST Γ :: ι where :: ι I :: IDR Γ σ : : :: NIL Γ E1 :: σ Γ E 2 :: Γ E1 : E2 :: σ :: CONS

102 CO3008 Semantic of Programming Language 102 FUN i Monomorphic Given I, Γ and E, if there i a type σ for which Γ then uch a type i unique. E :: σ, We verify Γ E :: σ 1 σ2 Γ E :: σ 2 implie σ 1 σ2 uing Rule Induction. We check property cloure for the rule HD:

103 σ σ E E CO3008 Semantic of Programming Language 103 The inductive hypothei i σ2 Γ E :: σ2 implie σ2 where Γ E ::. Γ Γ E :: E σ :: σ :: HD We wih to prove that σ2 Γ :: σ 2 implie σ σ2 where Γ :: σ.

104 CO3008 Semantic of Programming Language 104 Overview: Function Declaration and Program Show how to code up function. Define what make up a FUN program. Give ome example.

105 CO3008 Semantic of Programming Language 105 Introducing Function Declaration To declare can write x x x. To declare x x 1 1 x x 1 And to declare that denote T we write T. In e, can pecify E x E xy E

106 v CO3008 Semantic of Programming Language 106 An Example Declaration Let I 1 :: 2 : : 3 : : an example of an identifier declaration dec I i. Then 1 l y l 2 y 2x x x 3 T 4 u v w u w

107 σ2 σk CO3008 Semantic of Programming Language 107 Defining Declaration Let I 1 :: ι 1 m : : ιm where for example ι j σ1 σ 3 σ j j 1 m Then an identifier declaration dec I conit of. j x 1 xk E j. for each j 1 m

108 y : : :: :: CO3008 Semantic of Programming Language 108 An Example Program Let I ::. Then an identifier declaration dec I i x y x 7 y 10 An example of a program i dec I in 81. Note that 8 :: and that x :: y : : x 7 and

109 CO3008 Semantic of Programming Language 109 Program A program expreion P i any expreion containing no variable. A program in e i a judgement of the form dec I in P where P :: σ and the declaration in dec I atify. x 1 :: σ 1 xk : : σk E j :: σ j.

110 CO3008 Semantic of Programming Language 110 Example Program x x 1 1 x x 1 in 4 1 xyz 2 x x 1 x1 2 x 1 y x z 1 in 2 4 l code to ort lin 3 : 6 : 2 : 8 :

111 CO3008 Semantic of Programming Language 111 Chapter 7 Explain call-by-value (eager) and call-by-need (lazy) function calling method. Give FUN an eager and lazy evaluation tyle operational emantic. Prove propertie uch a determinim. Extend the language to give local declaration.

112 CO3008 Semantic of Programming Language 112 Overview: Program and Value Look at the notion of evaluation order. Define value, which are the reult of eager program execution. Define an eager evaluation emantic: P e V. Give ome example.

113 4 CO3008 Semantic of Programming Language 113 Evaluation Order The operational emantic of e ay when a program P evaluate to a value V. It i like the IMP evaluation emantic. Write thi in general a P e V, and example are 3 10 e 17 and 2 : e 2

114 Let CO3008 Semantic of Programming Language 114 xy x y. We would expect e 26. We could evaluate 2 3 to get value 6 yielding 6 4 5, then evaluate 4 5 to get value 20 yielding 620. We then call the function to get 6 20, which evaluate to 26. Thi i call-by-value or eager evaluation. Or the function could be called firt yielding and then we continue to get and 6 i called call-by-name or lazy evaluation. The order of evaluation i different. 20 and 26. Thi

115 σ2 σk CO3008 Semantic of Programming Language 115 Defining and Explaining (Eager) Value Let dec I be a identifier declaration, with typical typing :: σ1 σ 3 σ A value expreion i any expreion V produced by V :: c σ V V V V : V where V abbreviate V 1 V 2 Vl 1Vl and 0 lk, and k i the. CARE!!! maximum number of input taken by Note that contant are not value. Note alo that l i trictly le than k, and that if k 1then denote V.

116 :: CO3008 Semantic of Programming Language 116 A value i any value expreion for which dec I i a valid e program. in V Suppoe that and P e 2 5 and P 3 and that P1 e 7 with P i not value. Then e 2 P V P V P 1 2 P P P 1 P 2 P 3 14 Of coure P1 P2 P3 e 14.

117 P V 2 P 2 V 2 P V 2 CO3008 Semantic of Programming Language 117 V e V e VAL P 1 e m P 2 e n P 1 op P e 2 m op n e OP P 1 P1 e T P 2 P2 e V P3 e V e COND1 P 1 P1 e F P 3 P2 e V P3 e V e COND2 P 1 e V 1 P 2 e V 2 e PAIR P 1 e V 1 P e V 1 e FST P e V 1 e SND e V 1 e V 2

118 Vk j CO3008 Semantic of Programming Language 118 P 1 e V P 2 e V 2 V V 2 e V where either P 1 or P 2 i not a value P 1 P 2 e V e AP E V1 V1 x 1 V k xk e V e V x E declared in deci e FID E e V e V E declared in deci e CID

119 P P P P P CO3008 Semantic of Programming Language 119 P e e σ σ e NIL P e V : V e V e HD P e V : V e V e TL P 1 P 1 : P 2 e V P 2 e V e V : V e CONS P e σ e T e ELIST1 P e V : V e F e ELIST2

120 CO3008 Semantic of Programming Language 120 Suppoe that dec I i Example of Evaluation x x 2 3 e VAL 3 e 3 VAL e 3 CID 3 e 6 e VAL 3 x 2 3 x e 6 2 e VAL 2 e 6 OP FID AP

121 CO3008 Semantic of Programming Language 121 e VAL SND e D 4 VAL VAL e 4 e 2 2 OP 4 e e 8 FID e 8 AP

122 :: y CO3008 Semantic of Programming Language 122 Let where xyz x z 2 and 23 are (program and) value i a program, but not a value Note that i ugar for 23 i ugar for and that V In the Definition of value, k and l , and in 23 we have

123 y CO3008 Semantic of Programming Language 123 We can prove that e 10 where xyz x z a follow: 23 e 23 e VAL e e 10 e 5 e 1 T e AP

124 y CO3008 Semantic of Programming Language 124 where T i the tree 2 e 2 3 x e 3 e y z e 10 x e 10 z e 10 e 5 e FID

125 CO3008 Semantic of Programming Language 125 Overview: FUN Propertie of Eager Evaluation Explain and define determinim. Explain and define ubject reduction, that i, preervation of type during program execution.

126 CO3008 Semantic of Programming Language 126 Propertie of FUN The evaluation relation for More preciely, for all P, V 1 and V 2, if e i determinitic. P e V 1 and P e V 2 then V 1 V2. (Thu e i a partial function.) Evaluating a program dec I type. More preciely, in P doe not alter it P :: σ and P e V implie V :: σ for any P, V, σ and I. The conervation of type during program evaluation i called ubject reduction.

127 CO3008 Semantic of Programming Language 127 Proving Determinim To prove determinim, we prove by Rule Induction that P e V 1 V2 P e V 2 implie V 1 V2 See the board...

128 CO3008 Semantic of Programming Language 128 Proving Subject Reduction We prove by Rule Induction that given dec I in P P e V σ P :: σ implie V :: σ The tricky rule i E V1 V 1 Vk j x 1 Vk xk e V e V x E declared in deci e FID Suppoe that we need to prove V1 we jut need to prove Vk :: σ where σ i any type. Then V :: σ. By the induction hypothei, E V1 Vk j x 1 xk :: σ.

129 CO3008 Semantic of Programming Language 129 Overview: Program and (Lazy) Value Define value, which are the reult of program execution. Define a lazy evaluation emantic: P l V. Give ome example.

130 P CO3008 Semantic of Programming Language 130 Defining and Explaining Value Let dec I be a identifier declaration, with typical typing :: σ 1 σ2 σ 3 A value expreion i any expreion V produced by the grammar σk σ V :: c σ P P P : P where P abbreviate P 1 P 2 Pl 1 Pl and 0 i the maximum number of input taken by l k, and k. A value i any value expreion for which dec I l i a valid program. in V

131 P1 P CO3008 Semantic of Programming Language 131 P l P 1 P 2 P 1 l V l V lfst P 1 l P PP 2 l V where either P 1 or P 2 i not a value P 1 P 2 l V l AP E P1 P k x 1 P k xk l V l V x E declared in deci l FID P 1 l P 2 : P 3 P 2 P 1 l V l V lhd

132 :: CO3008 Semantic of Programming Language 132 Example of Evaluation Let I be there i a program dec I 1 l 3., and dec I be in 1 xx : x 2. Then. We prove that 1 : l 1 : l 1 : l VAL l FID T1 1 l 1 2 : T2 1 l 3

133 CO3008 Semantic of Programming Language 133 T2 1 l l 3 l 2 T1 1 2 : l 1 l : : l VAL

134 CO3008 Semantic of Programming Language 134 Let x 1 x in thi programme to a value V 3 0. We try to evaluate 3 0 l P1 P2 3 0 R l V P 1 l V R l FST for which we mut have P 1 and R are both intance of l VAL. 3, P2 0, V 3 and R

135 CO3008 Semantic of Programming Language 135 Overview: Locality Explain unnamed function and local definition. Decribe free and bound variable. Extend the yntax of FUN, and it operational emantic. Give ome example.

136 x x CO3008 Semantic of Programming Language 136 Motivating Function and Locality We can define unnamed function. The expreion x 2 i a program whoe intended meaning i the function which add 2. But it i not (necearily) named by an identifer. x 2 4 will evaluate to 4 2 (and thu to 6).

137 y CO3008 Semantic of Programming Language 137 If xx 2then x x 2would be interchangeable. i the name of the function. and The yntax example x 5 x E1 x y E2 give local declaration. For x. We explain local with the next example: x 7 x x 5 x x

138 We call CO3008 Semantic of Programming Language 138 Syntax and Type Aignment E :: x E x E E We call body of x E. x E a function abtraction. We call E the x E1 E2 a local declaration. Γ E 1 :: σ Γ Γ x E1 E 2 E1 x E2 :: σ :: σ LET Γ Γ x : : σ E :: τ x E : : σ τ ABS

139 E y x x y y y x CO3008 Semantic of Programming Language 139 Convention and Example x E mean x x E1 E2 mean x E1 E2 Thu yy2 = y 2 y x y x 2 = x y 2 x 4 y T x x 4 y T x

140 E2 E2 CO3008 Semantic of Programming Language 140 Motivating Free and Bound Variable Write F def emantic xe 1. Given any expreion E 2, in a tranition F E 2 E1 x Thu if E 1 i x y, then F E 2 x y x def E2 y and the intended meaning of F xx y i the function with add y. E x y ought to be the function which add x. But in fact E x y clearly the expreion xi x x, which i the function which double an integer input!

141 x CO3008 Semantic of Programming Language 141 We ay that the ubtituted x fall in the cope of the coping x. The expreion x x yand x x ycan be regarded a the ame. We ay that x and x are bound, and y i free. Note that x y x y x x x We re-name the bound variable x in x x ya a new variable x o that when x i ubtituted for y it doe not become bound.

142 v E CO3008 Semantic of Programming Language 142 Definition of Free and Bound Variable The yntax tree for look like thi coping variable v E cope In v E1 uch a v a coping variable. E2, the cope of v i E2. We alo call

143 x E CO3008 Semantic of Programming Language 143 Suppoe x doe occur in E. Each occurrence of x (in E) i either free or bound (but not both!!). We ay that an occurrence of x i bound if and only if the occurrence of x i in a ubexpreion of the form or x E1 E2 where the occurrence i in E2. Thu an occurrence of x in E i bound jut in cae the occurrence i a coping variable; the occurrence occur within the cope of a coping occurrence of x.

144 CO3008 Semantic of Programming Language 144 If there i an occurrence of x in uch E or E 2 then we ometime ay that thi bound occurrence of x ha been captured by the coping x. An occurrence of x in E i free iff the occurrence of x i not bound.

145 CO3008 Semantic of Programming Language 145 Subtitution Example x x y 2 y x x 2 x x y x y x x x x y 4 x z 7 u v z x y 4 x u v 7 x y 4 x z 7 u y z x y 4 x u y 7 x z 4 x x z 7 x y z x x y 4 x x x y 7 u u u 7 7 u u 7 u 7

146 E2 CO3008 Semantic of Programming Language 146 Extending the Eager Semantic P 1 e x E P2 P 1 P 2 e V e V E V x e V e AA E 1 e V 1 E 2 x E1 V1 x e V e V e LET

147 CO3008 Semantic of Programming Language 147 An Example e VAL e 3 3?? x 2 x x 2 3 : x x 2 VAL 3 x x x 23 e 5 : 3 : e e 5 e 5 VAL e 5 OP AA CONS HD

148 CO3008 Semantic of Programming Language 148 Chapter 8 Give overview of polymorphim. Introduce type variable into e. Give example of type aignment. Explain local polymorphim. Explain the polymorphic type inference algorithm.

149 CO3008 Semantic of Programming Language 149 Overview: Simple Type Deduction with Variable Explain different kind of polymorphim. Give example of type aignment deduction.

150 CO3008 Semantic of Programming Language 150 Varietie of Type Sytem A language i trongly typed if every legal expreion ha at leat one type. A trongly typed language i monomorphic if every legal expreion ha a unique type (for example Pacal). A trongly typed language i polymorphic if a legal expreion can have everal type (for example Standard ML and Hakell and Java).

151 CO3008 Semantic of Programming Language 151 Overloading: The ame ymbol i ued to denote (finitely many) function, implemented by different algorithm. Parametric: One expreion belong to a family of tructurally related type. The expreion encode one algorithm which work at each type in the family. An example i lit orting. Implicit: Thi i a particular form of parametric polymorphim, and we meet it later on.

152 The et Type of type of σ σ CO3008 Semantic of Programming Language 152 PFUN Type Sytem pecified by the grammar i inductively σ :: X σ σ σ σ Each type i a finite tree. Two type are equal if the tree are identical. Example on the board. We hall write TV appearing in σ. for the et of type variable The rule for deriving type aignment are a before. expreion are from the extended language.

153 T : CO3008 Semantic of Programming Language 153 Example of Type Aignment Deduction Prove that ::. T :: TRUE T : :: :: NIL CONS

154 x CO3008 Semantic of Programming Language 154 Show that Γ 0 : x :: for any context Γ. We produce a deduction tree: note that the expreion i a function, o the final rule ued in the deduction mut be ABS, where E : x, and σ 0 τ. Γ x : : 0 :: Γ x : : INT x Γ 0 : x Γ x : : 0 : x :: :: x :: VAR CONS ABS

155 Show that Γ i not typable in σ σ CO3008 Semantic of Programming Language 155 y : 3 in any context Γ. Working backward we have: Γ y :: σ VAR Γ y : 3 :: Γ y : 3 3 :: :: σ INT CONS HD Looking at the rule INT (which mut be ued to type 3) we mut have cannot be typable. σ, a contradiction. So the expreion

156 f X X X X X f X X f X T T T CO3008 Semantic of Programming Language 156 Show that f :: Y Y. f :: Y f :: Y VAR f :: f :: f f :: Y Y :: Y f Y Y :: NIL AP :: Y D PAIR :: Y ABS

157 f CO3008 Semantic of Programming Language 157 Show that f f y y i not typable for any context of the form y :: τ. (Note that y i the only free variable). We uppoe, for a contradiction, that the expreion i typeable. Let u call thi type σ 1, ay. We have: y :: τ f :: σ 2 f :: σ 3 σ 1 VAR y :: τ VAR f :: σ 2 y :: σ 3 AP y :: τ y :: τ y :: τ f y :: σ 2 f f y f :: σ 2 f y :: σ 1 ABS σ1d y :: σ 1 AP where D i y :: τ y :: σ 2 VAR

158 x X; any type σ CO3008 Semantic of Programming Language 158 Motivating Type Subtitution 6 T ha no type. 1 :: σ hold only for σ. However, x :: σ σ hold for any type σ. In, of all the type that can be aigned to an expreion, there i a mot general one: all other type are intance of it. We call thi the principal type. The principal type of x x i X obtained by ubtituting σ for X. σ i

159 X CO3008 Semantic of Programming Language 159 Type Subtitution Define S def U Y. Let σ def X Y Z. Then S σ U Z S a type ubtitution if it i a (poibly empty) finite et of (type-variable,type) pair in which all the type-variable are ditinct. We will write a typical S in the form X 1 σ1 Xn σn We write the empty type ubtitution a.

160 CO3008 Semantic of Programming Language 160 If τ i any type, we hall write S τ to denote the type τ in which any occurrence of X i i changed to σ i. Thu X 1 σ1 Xn σn τ def τ σ1 σn X1 Xn We will define equality of type ubtitution in a imilar way to function equality, namely S S iff τ S τ S τ

161 V CO3008 Semantic of Programming Language 161 Given ubtitution S 1 and S 2 we define the effect of the ubtitution S 1 S 2 by etting S 1 S 2 Warning!! A type ubtitution i a et of (type-variable,type) pair. What et i S 1 S 2? τ def S1 S 2 τ. to be If S def X1 σ σ1 X1 Xn σ1 σn Xn σn and alo then we define S V V to be.

162 CO3008 Semantic of Programming Language 162 σ generalie σ for which if there exit a type ubtitution S σs σ and ay that σ i an intance of σ. In, if P :: σ, the type σ aigned to the expreion P i principal if σ generalie any other type which can be aigned to P. The principal type of x x i X X. Note that the principal type i unique up to a conitent renaming of variable. Another principal type for x x i V V.

163 σ Γ y : : Y y : : X Z Y X Y X Y Y y : : S Y U X CO3008 Semantic of Programming Language 163 Type Subtitution Example Define S def Γ def x :: X U Z. Then X Y and Y. Let σ def Z S Z and S x :: S X Z x :: U Z Note that Z generalie for S Z where S def

164 X X X X Z Y X CO3008 Semantic of Programming Language 164 It follow from the definition that X. The definition of compoition of type ubtitution doe not decribe S 1 S 2 a an explicit et of pair. Conider X. The compoition i Y Y X Z Now conider compoition i Y X. The Y

165 Y X Z X Y X Y CO3008 Semantic of Programming Language 165 X Z Y X Y X Z X U Y X Z Y U A an exercie, try to write down a formula for Y1 τ1 Ym τm X1 σ1 Xn σn

166 CO3008 Semantic of Programming Language 166 Local Polymorphim in The LET rule permit different occurrence of x in E 2 to have different implicit type in a local declaration x E1 E2. Thu, E 1 can be ued polymorphically in the body E 2. Thi idea i bet explained by example...

167 x x X X x X X X x X x x T T : : CO3008 Semantic of Programming Language 167 and D1 x :: x :: x :: VAR x ABS T :: TRUE AP and D2 x :: x :: x X x :: VAR x ABS D1 D2 x :: :: :: PAIR NIL AP

168 x x x x x X CO3008 Semantic of Programming Language 168 x :: Y x : : Y x :: Y VAR Y f ABS x f T f T T x f f X X D1 D2 :: x x f :: :: LET

169 X ha implicit type X X CO3008 Semantic of Programming Language 169 In the above deduction of f xx f T f :: occurrence of f labelled (2) ha implicit type occurrence of f labelled 3 X. The principal type of xx i Y Y The implicit type of f are ubtitution intance of thi principal type, (2) with S Y (3) and S Y

170 CO3008 Semantic of Programming Language 170 Can Function Abtraction Yield Implicit Poly m? It i only poible for bound variable to poe polymorphic intance. ha one other variable binding operation, that found in function abtraction x E. Can uch bound variable have polymorphic intance within the cope of x abtraction? The anwer i in fact no. An example illutrate thi.

171 f f σ8 CO3008 Semantic of Programming Language 171 f T f i not typable (in the empty context). VAR NIL D f :: σ 2 f :: σ 7 σ 5 f :: σ 2 f f :: σ 2 :: σ5 :: σ7 AP f :: σ 2 f T f T f f :: σ 3 :: σ 1 σ2 σ4 σ5 σ3 ABS where D i f :: σ 2 f :: σ 6 f :: σ 2 σ 4 VAR f T :: σ4 f :: σ 2 T :: σ 6 TRUE AP

172 X E E CO3008 Semantic of Programming Language 172 A Type Inference Algorithm The type and expreion are now jut given by σ :: σ σ E :: n E iop E x E x E E S σ and τ are unifiable if we can find S for which Sτ. We call S a unifier. σ S i a mot general unifer if, given another unifer S there exit T for which S TS.,

173 CO3008 Semantic of Programming Language 173 X X X MGU σ σ here σ i any type MGU X Y Y here X and Y are ditinct here σ i either or a function type MGU X σ FAIL σ if X TV otherwie σ here σ i either or a function type MGU σ X σ if X TV FAIL otherwie σ

174 CO3008 Semantic of Programming Language 174 MGU σ1 σ2 τ1 τ2 S2 S1 where σ i τi any type S 1 def MGU S 2 def MGU S 1 FAIL otherwie σ1 τ1 S1 σ2 τ 2 MGU σ τ FAIL here σ τ any type MGU σ τ FAIL here σ τ any type

175 σ1 σn CO3008 Semantic of Programming Language 175 A typing for the judgement x 1 :: σ 1 xn : : σn E i a pair S τ for which x 1 :: S xn : : S E :: τ Such a typing i aid to be principal if given any other S there i ome T for which STSand τ Tτ. τ There i a type inference function Φ which given any input of the form will either return a principal typing, or FAIL if there i none. To define Φ we need more notation.

176 σ1 σn Γ σ1 σn CO3008 Semantic of Programming Language 176 Given a context Γ abuing notation) TV x1 :: σ1 Γ for the et xn : : σn let u write (by TV TV We hall alo write S to mean x 1 :: S xn : : S and we define S def.

177 Γ Γ CO3008 Semantic of Programming Language 177 Φ x1 :: σ1 xn :: σn xi Φ x1 :: σ1 i xn :: σn y FAIL xi y Φ n Φ E1 iop E2 S4 S3 S2 S1 where S1 S2 S3 S4 τ2 τ1 Γ Φ MGU Φ MGU τ1 τ2 S4 τ2 E1 S2 S1 Γ E2 σi

178 Γ Γ S τ Γ Γ CO3008 Semantic of Programming Language 178 Φ x E S V where V S TV V Φ Γ x:v τ E Φ E1 E2 S3 V S2 S1 where S1 S2 S3 V τ2 τ1 Γ Φ Φ MGU TV S2 S2 τ1 S1 τ1 τ2 E1 E2 V or TV τ2 V S3

179 CO3008 Semantic of Programming Language 179 Φ Γ x E1 E2 S 2 S 1 τ2 where S 1 τ1 Φ Γ E1 S 2 τ2 Φ S 1 Γ E 2 E1 x

180 x x V V CO3008 Semantic of Programming Language 180 Example We claimed that the principal type of have x i X X. We Φ x S V S τ where S τ Φ x :: V x V Thu Φ x x V V V. So, up to a renaming of type variable, the principal type i V V. V

181 f V X V U CO3008 Semantic of Programming Language 181 We calculate Φ x :: X f x. Thi i S V S τ where S τ Φ x :: X f :: V f x A3 U A 2 A 1 A3 where A1 τ1 Φ x :: X f :: V f and A2 τ2 Φ x :: X f :: V x

182 τ f X X U and o CO3008 Semantic of Programming Language 182 and A3 MGU V X X U V U U Therefore S V U Φ x :: X f x U U V X V X

Operational Semantics Class notes for a lecture given by Mooly Sagiv Tel Aviv University 24/5/2007 By Roy Ganor and Uri Juhasz

Operational Semantics Class notes for a lecture given by Mooly Sagiv Tel Aviv University 24/5/2007 By Roy Ganor and Uri Juhasz Operational emantic Page Operational emantic Cla note for a lecture given by Mooly agiv Tel Aviv Univerity 4/5/7 By Roy Ganor and Uri Juhaz Reference emantic with Application, H. Nielon and F. Nielon,

More information

A SIMPLE IMPERATIVE LANGUAGE THE STORE FUNCTION NON-TERMINATING COMMANDS

A SIMPLE IMPERATIVE LANGUAGE THE STORE FUNCTION NON-TERMINATING COMMANDS A SIMPLE IMPERATIVE LANGUAGE Eventually we will preent the emantic of a full-blown language, with declaration, type and looping. However, there are many complication, o we will build up lowly. Our firt

More information

Temporal Abstract Interpretation. To have a continuum of program analysis techniques ranging from model-checking to static analysis.

Temporal Abstract Interpretation. To have a continuum of program analysis techniques ranging from model-checking to static analysis. Temporal Abtract Interpretation Patrick COUSOT DI, École normale upérieure 45 rue d Ulm 75230 Pari cedex 05, France mailto:patrick.couot@en.fr http://www.di.en.fr/ couot and Radhia COUSOT LIX École polytechnique

More information

Topics. Lecture 37: Global Optimization. Issues. A Simple Example: Copy Propagation X := 3 B > 0 Y := 0 X := 4 Y := Z + W A := 2 * 3X

Topics. Lecture 37: Global Optimization. Issues. A Simple Example: Copy Propagation X := 3 B > 0 Y := 0 X := 4 Y := Z + W A := 2 * 3X Lecture 37: Global Optimization [Adapted from note by R. Bodik and G. Necula] Topic Global optimization refer to program optimization that encompa multiple baic block in a function. (I have ued the term

More information

Lecture 14: Minimum Spanning Tree I

Lecture 14: Minimum Spanning Tree I COMPSCI 0: Deign and Analyi of Algorithm October 4, 07 Lecture 4: Minimum Spanning Tree I Lecturer: Rong Ge Scribe: Fred Zhang Overview Thi lecture we finih our dicuion of the hortet path problem and introduce

More information

Minimum congestion spanning trees in bipartite and random graphs

Minimum congestion spanning trees in bipartite and random graphs Minimum congetion panning tree in bipartite and random graph M.I. Otrovkii Department of Mathematic and Computer Science St. John Univerity 8000 Utopia Parkway Queen, NY 11439, USA e-mail: otrovm@tjohn.edu

More information

Karen L. Collins. Wesleyan University. Middletown, CT and. Mark Hovey MIT. Cambridge, MA Abstract

Karen L. Collins. Wesleyan University. Middletown, CT and. Mark Hovey MIT. Cambridge, MA Abstract Mot Graph are Edge-Cordial Karen L. Collin Dept. of Mathematic Weleyan Univerity Middletown, CT 6457 and Mark Hovey Dept. of Mathematic MIT Cambridge, MA 239 Abtract We extend the definition of edge-cordial

More information

1 The secretary problem

1 The secretary problem Thi i new material: if you ee error, pleae email jtyu at tanford dot edu 1 The ecretary problem We will tart by analyzing the expected runtime of an algorithm, a you will be expected to do on your homework.

More information

Lecture Outline. Global flow analysis. Global Optimization. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization

Lecture Outline. Global flow analysis. Global Optimization. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization Lecture Outline Global flow analyi Global Optimization Global contant propagation Livene analyi Adapted from Lecture by Prof. Alex Aiken and George Necula (UCB) CS781(Praad) L27OP 1 CS781(Praad) L27OP

More information

A note on degenerate and spectrally degenerate graphs

A note on degenerate and spectrally degenerate graphs A note on degenerate and pectrally degenerate graph Noga Alon Abtract A graph G i called pectrally d-degenerate if the larget eigenvalue of each ubgraph of it with maximum degree D i at mot dd. We prove

More information

Select Operation (σ) It selects tuples that satisfy the given predicate from a relation (choose rows). Review : RELATIONAL ALGEBRA

Select Operation (σ) It selects tuples that satisfy the given predicate from a relation (choose rows). Review : RELATIONAL ALGEBRA Review : RELATIONAL ALGEBRA Relational databae ytem are expected to be equipped with a query language that can ait it uer to query the databae intance. There are two kind of query language relational algebra

More information

Bottom Up parsing. Bottom-up parsing. Steps in a shift-reduce parse. 1. s. 2. np. john. john. john. walks. walks.

Bottom Up parsing. Bottom-up parsing. Steps in a shift-reduce parse. 1. s. 2. np. john. john. john. walks. walks. Paring Technologie Outline Paring Technologie Outline Bottom Up paring Paring Technologie Paring Technologie Bottom-up paring Step in a hift-reduce pare top-down: try to grow a tree down from a category

More information

Delaunay Triangulation: Incremental Construction

Delaunay Triangulation: Incremental Construction Chapter 6 Delaunay Triangulation: Incremental Contruction In the lat lecture, we have learned about the Lawon ip algorithm that compute a Delaunay triangulation of a given n-point et P R 2 with O(n 2 )

More information

CORRECTNESS ISSUES AND LOOP INVARIANTS

CORRECTNESS ISSUES AND LOOP INVARIANTS The next everal lecture 2 Study algorithm for earching and orting array. Invetigate their complexity how much time and pace they take Formalize the notion of average-cae and wort-cae complexity CORRECTNESS

More information

Algorithmic Discrete Mathematics 4. Exercise Sheet

Algorithmic Discrete Mathematics 4. Exercise Sheet Algorithmic Dicrete Mathematic. Exercie Sheet Department of Mathematic SS 0 PD Dr. Ulf Lorenz 0. and. May 0 Dipl.-Math. David Meffert Verion of May, 0 Groupwork Exercie G (Shortet path I) (a) Calculate

More information

Shortest Paths Problem. CS 362, Lecture 20. Today s Outline. Negative Weights

Shortest Paths Problem. CS 362, Lecture 20. Today s Outline. Negative Weights Shortet Path Problem CS 6, Lecture Jared Saia Univerity of New Mexico Another intereting problem for graph i that of finding hortet path Aume we are given a weighted directed graph G = (V, E) with two

More information

Today s Outline. CS 561, Lecture 23. Negative Weights. Shortest Paths Problem. The presence of a negative cycle might mean that there is

Today s Outline. CS 561, Lecture 23. Negative Weights. Shortest Paths Problem. The presence of a negative cycle might mean that there is Today Outline CS 56, Lecture Jared Saia Univerity of New Mexico The path that can be trodden i not the enduring and unchanging Path. The name that can be named i not the enduring and unchanging Name. -

More information

Generic Traverse. CS 362, Lecture 19. DFS and BFS. Today s Outline

Generic Traverse. CS 362, Lecture 19. DFS and BFS. Today s Outline Generic Travere CS 62, Lecture 9 Jared Saia Univerity of New Mexico Travere(){ put (nil,) in bag; while (the bag i not empty){ take ome edge (p,v) from the bag if (v i unmarked) mark v; parent(v) = p;

More information

CS201: Data Structures and Algorithms. Assignment 2. Version 1d

CS201: Data Structures and Algorithms. Assignment 2. Version 1d CS201: Data Structure and Algorithm Aignment 2 Introduction Verion 1d You will compare the performance of green binary earch tree veru red-black tree by reading in a corpu of text, toring the word and

More information

Drawing Lines in 2 Dimensions

Drawing Lines in 2 Dimensions Drawing Line in 2 Dimenion Drawing a traight line (or an arc) between two end point when one i limited to dicrete pixel require a bit of thought. Conider the following line uperimpoed on a 2 dimenional

More information

Edits in Xylia Validity Preserving Editing of XML Documents

Edits in Xylia Validity Preserving Editing of XML Documents dit in Xylia Validity Preerving diting of XML Document Pouria Shaker, Theodore S. Norvell, and Denni K. Peter Faculty of ngineering and Applied Science, Memorial Univerity of Newfoundland, St. John, NFLD,

More information

Compiler Construction

Compiler Construction Compiler Contruction Lecture 6 - An Introduction to Bottom- Up Paring 3 Robert M. Siegfried All right reerved Bottom-up Paring Bottom-up parer pare a program from the leave of a pare tree, collecting the

More information

Laboratory Exercise 2

Laboratory Exercise 2 Laoratory Exercie Numer and Diplay Thi i an exercie in deigning cominational circuit that can perform inary-to-decimal numer converion and inary-coded-decimal (BCD) addition. Part I We wih to diplay on

More information

Control Flow Analysis

Control Flow Analysis Control Flow Analyi Efficiency Control Flow Analyi Type an Effect ytem Data Flow Analyi Abtract Interpretation Correctne Control Flow Analyi p.1/35 Control Flow Analyi Flow information i eential for the

More information

Chapter S:II (continued)

Chapter S:II (continued) Chapter S:II (continued) II. Baic Search Algorithm Sytematic Search Graph Theory Baic State Space Search Depth-Firt Search Backtracking Breadth-Firt Search Uniform-Cot Search AND-OR Graph Baic Depth-Firt

More information

Region analysis and the polymorphic lambda calculus

Region analysis and the polymorphic lambda calculus Region analyi and the polymorphic lambda calculu Anindya Banerjee Steven Intitute of Technology ab@c.teven-tech.edu Nevin Heintze Bell Laboratorie nch@bell-lab.com Jon G. Riecke Bell Laboratorie riecke@bell-lab.com

More information

Laboratory Exercise 6

Laboratory Exercise 6 Laboratory Exercie 6 Adder, Subtractor, and Multiplier The purpoe of thi exercie i to examine arithmetic circuit that add, ubtract, and multiply number. Each circuit will be decribed in Verilog and implemented

More information

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference Lecture #13: Type Inference and Unification Typing In the Language ML Examples from the language ML: fun map f [] = [] map f (a :: y) = (f a) :: (map f y) fun reduce f init [] = init reduce f init (a ::

More information

Microsemantics as a Bootstrap in Teaching Formal Methods

Microsemantics as a Bootstrap in Teaching Formal Methods Microemantic a a Boottrap in Teaching Formal Method Raymond Boute INTEC Univeriteit Gent, Belgium Raymond.Boute@intec.UGent.be Abtract Introducing an elementary form of program emantic early in the curriculum

More information

Contents. shortest paths. Notation. Shortest path problem. Applications. Algorithms and Networks 2010/2011. In the entire course:

Contents. shortest paths. Notation. Shortest path problem. Applications. Algorithms and Networks 2010/2011. In the entire course: Content Shortet path Algorithm and Network 21/211 The hortet path problem: Statement Verion Application Algorithm (for ingle ource p problem) Reminder: relaxation, Dijktra, Variant of Dijktra, Bellman-Ford,

More information

np vp cost = 0 cost = c np vp cost = c I replacing term cost = c+c n cost = c * Error detection Error correction pron det pron det n gi

np vp cost = 0 cost = c np vp cost = c I replacing term cost = c+c n cost = c * Error detection Error correction pron det pron det n gi Spoken Language Paring with Robutne and ncrementality Yohihide Kato, Shigeki Matubara, Katuhiko Toyama and Yauyohi nagaki y Graduate School of Engineering, Nagoya Univerity y Faculty of Language and Culture,

More information

xy-monotone path existence queries in a rectilinear environment

xy-monotone path existence queries in a rectilinear environment CCCG 2012, Charlottetown, P.E.I., Augut 8 10, 2012 xy-monotone path exitence querie in a rectilinear environment Gregory Bint Anil Mahehwari Michiel Smid Abtract Given a planar environment coniting of

More information

Laboratory Exercise 2

Laboratory Exercise 2 Laoratory Exercie Numer and Diplay Thi i an exercie in deigning cominational circuit that can perform inary-to-decimal numer converion and inary-coded-decimal (BCD) addition. Part I We wih to diplay on

More information

How to. write a paper. The basics writing a solid paper Different communities/different standards Common errors

How to. write a paper. The basics writing a solid paper Different communities/different standards Common errors How to write a paper The baic writing a olid paper Different communitie/different tandard Common error Reource Raibert eay My grammar point Article on a v. the Bug in writing Clarity Goal Conciene Calling

More information

SIMIT 7. Component Type Editor (CTE) User manual. Siemens Industrial

SIMIT 7. Component Type Editor (CTE) User manual. Siemens Industrial SIMIT 7 Component Type Editor (CTE) Uer manual Siemen Indutrial Edition January 2013 Siemen offer imulation oftware to plan, imulate and optimize plant and machine. The imulation- and optimizationreult

More information

Laboratory Exercise 6

Laboratory Exercise 6 Laboratory Exercie 6 Adder, Subtractor, and Multiplier a a The purpoe of thi exercie i to examine arithmetic circuit that add, ubtract, and multiply number. Each b c circuit will be decribed in Verilog

More information

Lecture #23: Conversion and Type Inference

Lecture #23: Conversion and Type Inference Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:

More information

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = Hello; Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";

More information

An Intro to LP and the Simplex Algorithm. Primal Simplex

An Intro to LP and the Simplex Algorithm. Primal Simplex An Intro to LP and the Simplex Algorithm Primal Simplex Linear programming i contrained minimization of a linear objective over a olution pace defined by linear contraint: min cx Ax b l x u A i an m n

More information

MAT 155: Describing, Exploring, and Comparing Data Page 1 of NotesCh2-3.doc

MAT 155: Describing, Exploring, and Comparing Data Page 1 of NotesCh2-3.doc MAT 155: Decribing, Exploring, and Comparing Data Page 1 of 8 001-oteCh-3.doc ote for Chapter Summarizing and Graphing Data Chapter 3 Decribing, Exploring, and Comparing Data Frequency Ditribution, Graphic

More information

On successive packing approach to multidimensional (M-D) interleaving

On successive packing approach to multidimensional (M-D) interleaving On ucceive packing approach to multidimenional (M-D) interleaving Xi Min Zhang Yun Q. hi ankar Bau Abtract We propoe an interleaving cheme for multidimenional (M-D) interleaving. To achieved by uing a

More information

Objects, Classes, and Inheritance

Objects, Classes, and Inheritance Object, Clae, and Inheritance CS111 Computer Programming Department of Computer Science Welleley College The Big Picture Some paradigm of programming: o Imperative Programming Program pecified by conditional,

More information

Routing Definition 4.1

Routing Definition 4.1 4 Routing So far, we have only looked at network without dealing with the iue of how to end information in them from one node to another The problem of ending information in a network i known a routing

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

Laboratory Exercise 6

Laboratory Exercise 6 Laboratory Exercie 6 Adder, Subtractor, and Multiplier The purpoe of thi exercie i to examine arithmetic circuit that add, ubtract, and multiply number. Each type of circuit will be implemented in two

More information

Shortest Path Routing in Arbitrary Networks

Shortest Path Routing in Arbitrary Networks Journal of Algorithm, Vol 31(1), 1999 Shortet Path Routing in Arbitrary Network Friedhelm Meyer auf der Heide and Berthold Vöcking Department of Mathematic and Computer Science and Heinz Nixdorf Intitute,

More information

An Approach to a Test Oracle for XML Query Testing

An Approach to a Test Oracle for XML Query Testing An Approach to a Tet Oracle for XML Query Teting Dae S. Kim-Park, Claudio de la Riva, Javier Tuya Univerity of Oviedo Computing Department Campu of Vieque, /n, 33204 (SPAIN) kim_park@li.uniovi.e, claudio@uniovi.e,

More information

Type Checking and Type Inference

Type Checking and Type Inference Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

More information

arxiv: v1 [cs.ds] 27 Feb 2018

arxiv: v1 [cs.ds] 27 Feb 2018 Incremental Strong Connectivity and 2-Connectivity in Directed Graph Louka Georgiadi 1, Giueppe F. Italiano 2, and Niko Parotidi 2 arxiv:1802.10189v1 [c.ds] 27 Feb 2018 1 Univerity of Ioannina, Greece.

More information

Objects and Classes. The Big Picture. Classes. Objects. Some paradigms of programming:

Objects and Classes. The Big Picture. Classes. Objects. Some paradigms of programming: Object and Clae The Big Picture Some paradigm of programming: Imperative Programming ue explicit loop, conditional, variable Three paradigm of programming we cover in CS111. Functional Programming Ue function

More information

Midterm 2 March 10, 2014 Name: NetID: # Total Score

Midterm 2 March 10, 2014 Name: NetID: # Total Score CS 3 : Algorithm and Model of Computation, Spring 0 Midterm March 0, 0 Name: NetID: # 3 Total Score Max 0 0 0 0 Grader Don t panic! Pleae print your name and your NetID in the boxe above. Thi i a cloed-book,

More information

else end while End References

else end while End References 621-630. [RM89] [SK76] Roenfeld, A. and Melter, R. A., Digital geometry, The Mathematical Intelligencer, vol. 11, No. 3, 1989, pp. 69-72. Sklanky, J. and Kibler, D. F., A theory of nonuniformly digitized

More information

Course Project: Adders, Subtractors, and Multipliers a

Course Project: Adders, Subtractors, and Multipliers a In the name Allah Department of Computer Engineering 215 Spring emeter Computer Architecture Coure Intructor: Dr. Mahdi Abbai Coure Project: Adder, Subtractor, and Multiplier a a The purpoe of thi p roject

More information

Laboratory Exercise 6

Laboratory Exercise 6 Laboratory Exercie 6 Adder, Subtractor, and Multiplier The purpoe of thi exercie i to examine arithmetic circuit that add, ubtract, and multiply number. Each circuit will be decribed in VHL and implemented

More information

3D SMAP Algorithm. April 11, 2012

3D SMAP Algorithm. April 11, 2012 3D SMAP Algorithm April 11, 2012 Baed on the original SMAP paper [1]. Thi report extend the tructure of MSRF into 3D. The prior ditribution i modified to atify the MRF property. In addition, an iterative

More information

Predicate Abstraction and CEGAR for Higher-Order Model Checking

Predicate Abstraction and CEGAR for Higher-Order Model Checking Predicate Abtraction and CEGAR for Higher-Order Model Checking Naoki Kobayahi Tohoku Univerity koba@ecei.tohoku.ac.jp Ryouke Sato Tohoku Univerity ryouke@kb.ecei.tohoku.ac.jp Hirohi Unno Tohoku Univerity

More information

Mid-term review ECE 161C Electrical and Computer Engineering University of California San Diego

Mid-term review ECE 161C Electrical and Computer Engineering University of California San Diego Mid-term review ECE 161C Electrical and Computer Engineering Univerity of California San Diego Nuno Vaconcelo Spring 2014 1. We have een in cla that one popular technique for edge detection i the Canny

More information

The Set Constraint/CFL Reachability Connection in Practice

The Set Constraint/CFL Reachability Connection in Practice The Set Contraint/CFL Reachability Connection in Practice John Kodumal EECS Department Univerity of California, Berkeley jkodumal@c.berkeley.edu Alex Aiken Computer Science Department Stanford Univerity

More information

CERIAS Tech Report EFFICIENT PARALLEL ALGORITHMS FOR PLANAR st-graphs. by Mikhail J. Atallah, Danny Z. Chen, and Ovidiu Daescu

CERIAS Tech Report EFFICIENT PARALLEL ALGORITHMS FOR PLANAR st-graphs. by Mikhail J. Atallah, Danny Z. Chen, and Ovidiu Daescu CERIAS Tech Report 2003-15 EFFICIENT PARALLEL ALGORITHMS FOR PLANAR t-graphs by Mikhail J. Atallah, Danny Z. Chen, and Ovidiu Daecu Center for Education and Reearch in Information Aurance and Security,

More information

Fall 2010 EE457 Instructor: Gandhi Puvvada Date: 10/1/2010, Friday in SGM123 Name:

Fall 2010 EE457 Instructor: Gandhi Puvvada Date: 10/1/2010, Friday in SGM123 Name: Fall 2010 EE457 Intructor: Gandhi Puvvada Quiz (~ 10%) Date: 10/1/2010, Friday in SGM123 Name: Calculator and Cadence Verilog guide are allowed; Cloed-book, Cloed-note, Time: 12:00-2:15PM Total point:

More information

arxiv: v1 [math.co] 18 Jan 2019

arxiv: v1 [math.co] 18 Jan 2019 Anti-Ramey number of path in hypergraph Ran Gu 1, Jiaao Li 2 and Yongtang Shi 3 1 College of Science, Hohai Univerity, Nanjing, Jiangu Province 210098, P.R. China 2 School of Mathematical Science and LPMC

More information

Modeling of underwater vehicle s dynamics

Modeling of underwater vehicle s dynamics Proceeding of the 11th WEA International Conference on YTEM, Agio Nikolao, Crete Iland, Greece, July 23-25, 2007 44 Modeling of underwater vehicle dynamic ANDRZEJ ZAK Department of Radiolocation and Hydrolocation

More information

Operational Semantics. One-Slide Summary. Lecture Outline

Operational Semantics. One-Slide Summary. Lecture Outline Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:

More information

The Data Locality of Work Stealing

The Data Locality of Work Stealing The Data Locality of Work Stealing Umut A. Acar School of Computer Science Carnegie Mellon Univerity umut@c.cmu.edu Guy E. Blelloch School of Computer Science Carnegie Mellon Univerity guyb@c.cmu.edu Robert

More information

Shortest Paths with Single-Point Visibility Constraint

Shortest Paths with Single-Point Visibility Constraint Shortet Path with Single-Point Viibility Contraint Ramtin Khoravi Mohammad Ghodi Department of Computer Engineering Sharif Univerity of Technology Abtract Thi paper tudie the problem of finding a hortet

More information

Fall 2010 EE457 Instructor: Gandhi Puvvada Date: 10/1/2010, Friday in SGM123 Name:

Fall 2010 EE457 Instructor: Gandhi Puvvada Date: 10/1/2010, Friday in SGM123 Name: Fall 2010 EE457 Intructor: Gandhi Puvvada Quiz (~ 10%) Date: 10/1/2010, Friday in SGM123 Name: Calculator and Cadence Verilog guide are allowed; Cloed-book, Cloed-note, Time: 12:00-2:15PM Total point:

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative

More information

Aspects of Formal and Graphical Design of a Bus System

Aspects of Formal and Graphical Design of a Bus System Apect of Formal and Graphical Deign of a Bu Sytem Tiberiu Seceleanu Univerity of Turku, Dpt. of Information Technology Turku, Finland tiberiu.eceleanu@utu.fi Tomi Weterlund Turku Centre for Computer Science

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

Programming Languages Lecture 14: Sum, Product, Recursive Types

Programming Languages Lecture 14: Sum, Product, Recursive Types CSE 230: Winter 200 Principles of Programming Languages Lecture 4: Sum, Product, Recursive Types The end is nigh HW 3 No HW 4 (= Final) Project (Meeting + Talk) Ranjit Jhala UC San Diego Recap Goal: Relate

More information

New Structural Decomposition Techniques for Constraint Satisfaction Problems

New Structural Decomposition Techniques for Constraint Satisfaction Problems New Structural Decompoition Technique for Contraint Satifaction Problem Yaling Zheng and Berthe Y. Choueiry Contraint Sytem Laboratory Univerity of Nebraka-Lincoln Email: yzheng choueiry@ce.unl.edu Abtract.

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

Universität Augsburg. Institut für Informatik. Approximating Optimal Visual Sensor Placement. E. Hörster, R. Lienhart.

Universität Augsburg. Institut für Informatik. Approximating Optimal Visual Sensor Placement. E. Hörster, R. Lienhart. Univerität Augburg à ÊÇÅÍÆ ËÀǼ Approximating Optimal Viual Senor Placement E. Hörter, R. Lienhart Report 2006-01 Januar 2006 Intitut für Informatik D-86135 Augburg Copyright c E. Hörter, R. Lienhart Intitut

More information

The Split Domination and Irredundant Number of a Graph

The Split Domination and Irredundant Number of a Graph The Split Domination and Irredundant Number of a Graph S. Delbin Prema 1, C. Jayaekaran 2 1 Department of Mathematic, RVS Technical Campu-Coimbatore, Coimbatore - 641402, Tamil Nadu, India 2 Department

More information

Types-2. Polymorphism

Types-2. Polymorphism Types-2 Polymorphism Type reconstruction (type inference) for a simple PL Typing functions Coercion, conversion, reconstruction Rich area of programming language research as people try to provide safety

More information

Application: Programming Language Semantics

Application: Programming Language Semantics Chapter 8 Application: Programming Language Semantics Prof. Dr. K. Madlener: Specification and Verification in Higher Order Logic 527 Introduction to Programming Language Semantics Programming Language

More information

The Association of System Performance Professionals

The Association of System Performance Professionals The Aociation of Sytem Performance Profeional The Computer Meaurement Group, commonly called CMG, i a not for profit, worldwide organization of data proceing profeional committed to the meaurement and

More information

KS3 Maths Assessment Objectives

KS3 Maths Assessment Objectives KS3 Math Aement Objective Tranition Stage 9 Ratio & Proportion Probabilit y & Statitic Appreciate the infinite nature of the et of integer, real and rational number Can interpret fraction and percentage

More information

DAROS: Distributed User-Server Assignment And Replication For Online Social Networking Applications

DAROS: Distributed User-Server Assignment And Replication For Online Social Networking Applications DAROS: Ditributed Uer-Server Aignment And Replication For Online Social Networking Application Thuan Duong-Ba School of EECS Oregon State Univerity Corvalli, OR 97330, USA Email: duongba@eec.oregontate.edu

More information

(12) Patent Application Publication (10) Pub. No.: US 2011/ A1

(12) Patent Application Publication (10) Pub. No.: US 2011/ A1 (19) United State US 2011 0316690A1 (12) Patent Application Publication (10) Pub. No.: US 2011/0316690 A1 Siegman (43) Pub. Date: Dec. 29, 2011 (54) SYSTEMAND METHOD FOR IDENTIFYING ELECTRICAL EQUIPMENT

More information

arxiv: v3 [cs.cg] 1 Oct 2018

arxiv: v3 [cs.cg] 1 Oct 2018 Improved Time-Space Trade-off for Computing Voronoi Diagram Bahareh Banyaady Matia Korman Wolfgang Mulzer André van Renen Marcel Roeloffzen Paul Seiferth Yannik Stein arxiv:1708.00814v3 [c.cg] 1 Oct 2018

More information

Homework 4 Due Thursday Oct 7. CLRS 12-4 (number of binary trees) CLRS (rb insert implementation)

Homework 4 Due Thursday Oct 7. CLRS 12-4 (number of binary trees) CLRS (rb insert implementation) Homework 4 Due Thurday Oct 7 CLRS 12-4 (number of binary tree) CLRS 13.3-6 (rb inert imlementation) 1 Chater 13: Red-Black Tree A red-black tree i a node-colored BST. Each node i colored either black or

More information

SIMIT 7. Profinet IO Gateway. User Manual

SIMIT 7. Profinet IO Gateway. User Manual SIMIT 7 Profinet IO Gateway Uer Manual Edition January 2013 Siemen offer imulation oftware to plan, imulate and optimize plant and machine. The imulation- and optimizationreult are only non-binding uggetion

More information

AN ALGORITHM FOR RESTRICTED NORMAL FORM TO SOLVE DUAL TYPE NON-CANONICAL LINEAR FRACTIONAL PROGRAMMING PROBLEM

AN ALGORITHM FOR RESTRICTED NORMAL FORM TO SOLVE DUAL TYPE NON-CANONICAL LINEAR FRACTIONAL PROGRAMMING PROBLEM RAC Univerity Journal, Vol IV, No, 7, pp 87-9 AN ALGORITHM FOR RESTRICTED NORMAL FORM TO SOLVE DUAL TYPE NON-CANONICAL LINEAR FRACTIONAL PROGRAMMING PROLEM Mozzem Hoain Department of Mathematic Ghior Govt

More information

Towards a verified Lustre compiler with modular reset

Towards a verified Lustre compiler with modular reset Toward a verified Lutre compiler with modular reet Timothy Bourke, Lélio Brun, Marc Pouzet To cite thi verion: Timothy Bourke, Lélio Brun, Marc Pouzet. Toward a verified Lutre compiler with modular reet.

More information

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1 Introduction to Automata Theory BİL405 - Automata Theory and Formal Languages 1 Automata, Computability and Complexity Automata, Computability and Complexity are linked by the question: What are the fundamental

More information

Refining SIRAP with a Dedicated Resource Ceiling for Self-Blocking

Refining SIRAP with a Dedicated Resource Ceiling for Self-Blocking Refining SIRAP with a Dedicated Reource Ceiling for Self-Blocking Mori Behnam, Thoma Nolte Mälardalen Real-Time Reearch Centre P.O. Box 883, SE-721 23 Väterå, Sweden {mori.behnam,thoma.nolte}@mdh.e ABSTRACT

More information

Harvard School of Engineering and Applied Sciences Computer Science 152

Harvard School of Engineering and Applied Sciences Computer Science 152 Harvard School of Engineering and Applied Sciences Computer Science 152 Lecture 17 Tuesday, March 30, 2010 1 Polymorph means many forms. Polymorphism is the ability of code to be used on values of different

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

Web Science and additionality

Web Science and additionality Admin tuff... Lecture 1: EITN01 Web Intelligence and Information Retrieval Meage, lide, handout, lab manual and link: http://www.eit.lth.e/coure/eitn01 Contact: Ander Ardö, Ander.Ardo@eit.lth.e, room:

More information

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 Natural Semantics Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 1 Natural deduction is an instance of first-order logic; that is, it is the formal

More information

Testing Structural Properties in Textual Data: Beyond Document Grammars

Testing Structural Properties in Textual Data: Beyond Document Grammars Teting Structural Propertie in Textual Data: Beyond Document Grammar Felix Saaki and Jen Pönninghau Univerity of Bielefeld, Germany Abtract Schema language concentrate on grammatical contraint on document

More information

Gray-level histogram. Intensity (grey-level) transformation, or mapping. Use of intensity transformations:

Gray-level histogram. Intensity (grey-level) transformation, or mapping. Use of intensity transformations: Faculty of Informatic Eötvö Loránd Univerity Budapet, Hungary Lecture : Intenity Tranformation Image enhancement by point proceing Spatial domain and frequency domain method Baic Algorithm for Digital

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

New Structural Decomposition Techniques for Constraint Satisfaction Problems

New Structural Decomposition Techniques for Constraint Satisfaction Problems 113 New Structural Decompoition Technique for Contraint Satifaction Problem Yaling Zheng and Berthe Y. Choueiry Contraint Sytem Laboratory, Univerity of Nebraka-Lincoln {yzheng,choueiry}@ce.unl.edu Abtract.

More information

Lambda Calculus and Type Inference

Lambda Calculus and Type Inference Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ October 13, 2004 Lambda Calculus and Type

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And

More information

SML A F unctional Functional Language Language Lecture 19

SML A F unctional Functional Language Language Lecture 19 SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list

More information

Fall Lecture 3 September 4. Stephen Brookes

Fall Lecture 3 September 4. Stephen Brookes 15-150 Fall 2018 Lecture 3 September 4 Stephen Brookes Today A brief remark about equality types Using patterns Specifying what a function does equality in ML e1 = e2 Only for expressions whose type is

More information

ES205 Analysis and Design of Engineering Systems: Lab 1: An Introductory Tutorial: Getting Started with SIMULINK

ES205 Analysis and Design of Engineering Systems: Lab 1: An Introductory Tutorial: Getting Started with SIMULINK ES05 Analyi and Deign of Engineering Sytem: Lab : An Introductory Tutorial: Getting Started with SIMULINK What i SIMULINK? SIMULINK i a oftware package for modeling, imulating, and analyzing dynamic ytem.

More information