Exercises on Concepts of Programming Languages - Christian
Exercises on Concepts of Programming Languages. Christian Rinderknecht. 9 February 2006. 1 Calculator. Assume the following system of inference rules:.
We also assume that we have an infinity of rules for multiplying, adding, subtracting and dividing (integer division) numbers. 1. Is this system deterministic? 2. Reduce the following expressions in all the possible ways and give at each rewrite step the corresponding substitution: (a) (1 + 2) × (3 + (4 × 5)) (b) ((1 + 2)/0) × (3 + 4) (c) (1 + (2 × 3))/((4 + 5) − 9)
1
Assume now the following variant and answer the previous questions again. e1 → e′1 e1 × e2 → e′1 × e2 e → e′ e + v → e′ + v
e1 − e2 → e′1 − e2 e/v → e′ /v
v × e → v × e′ e2 → e′2
⟨Add1 ⟩
e1 → e′1 e → e′
e → e′
⟨Mult1 ⟩
e1 + e2 → e1 + e′2 e → e′
⟨Sub1 ⟩
v − e → v − e′ e2 → e′2
⟨Div1 ⟩
e1 /e2 → e1 /e′2
⟨Mult2 ⟩
⟨Add2 ⟩
⟨Sub2 ⟩
⟨Div2 ⟩
Assume now that we have a different rule ⟨Div1 ⟩ and new rules for handling the division by zero: v ̸= 0
e → e′
e/v → e′ /v
e/0 → NaN ⟨DivZero⟩
⟨Div1 ⟩
NaN × e → NaN ⟨Mult-Err1 ⟩
e × NaN → NaN ⟨Mult-Err2 ⟩
NaN + e → NaN ⟨Add-Err1 ⟩
e + NaN → NaN ⟨Add-Err2 ⟩
NaN − e → NaN ⟨Sub-Err1 ⟩
e − NaN → NaN
NaN/e → NaN ⟨Div-Err1 ⟩
⟨Sub-Err2 ⟩
e/NaN → NaN ⟨Div-Err2 ⟩
Answer the same questions again. Is it better to have the following rule? e1 → e′1 e1 /e2 → e′1 /e2
2
⟨Div1 ⟩
2
Boolean expressions
Consider the system of inference rules true ∧ e → e
false ∧ e → false ⟨∧False ⟩
⟨∧True ⟩
e1 → e′1 e1 ∧ e2 → e′1 ∧ e2
¬false → true ⟨Not-False⟩
⟨∧⟩
¬true → false ⟨Not-True⟩
e → e′ ¬e → ¬e′
⟨Not⟩
e1 ∨ e2 → ¬(¬e1 ∧ ¬e2 ) ⟨Or⟩ 1. Is this system deterministic? 2. Reduce the following expressions in several ways if possible, and give at each rewrite step the corresponding substitution: (a) (true ∧ (false ∨ true)) ∧ ¬(true ∨ (true ∧ true)) (b) ¬((true ∧ true) ∨ ¬(false ∨ ¬true))
3
Arithmetic
Let us model the integers. The number 0 is noted Zero. If an integer is noted n, then Succ(n) denotes the next integer and Pred(n) the previous. For example Mathematical notation New notation Zero 0 Succ(Zero) 1 Succ(Succ(Zero)) 2 ... ... Pred(Zero) −1 Pred(Pred(Zero)) −2 ... ... Let us define now a function IsZero which returns the boolean true if the argument is Zero and false if the argument is not Zero: IsZero(Zero) → true IsZero(Succ(n)) → false IsZero(Pred(n)) → false
3
But this definition is broken, because it implies, for instance IsZero(Pred(Succ(Zero))) → false What solution do you propose to fix it? Answer: Succ(Pred(n)) → n Pred(Succ(n)) → n
former students are successful in research and private industry. .... structs, it will be useful to distinguish between algorithms of constant-, polynomial-, ... different computing environments and applications require different program char- ......
us in the future, when computing conditions may change to resemble some past ..... In words, a partial function is single valued, but need not be defined on all ...... Lisp lambda makes it possible to write anonymous functions, which are ...... has t
13.4 Java System Architecture. 404 ... In Part 3 we look at program organization using abstract data types, modules, and .... An example discussed in Chapter 3 is memory management: The Lisp ...... (a) Fill in the missing code in the following defini
(or program written in L ) therefore is nothing more than a finite set of instructions ..... instructions which, in the final analysis, are represented by a certain set of symbols ..... Programming Languages: Design and Implementation, 4th edition. .
... looked at addition: the second integer was sent to the first, which returned the sum. CHAPTER 7 â¡ LOOPING. 79. 4916_Ch07_CMP2 5/12/05 7:14 PM Page ...
Sep 16, 1973 - Hitachi America Ltd . . ..... A C program need not all be translated at the same time. The text of the program is ...... of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives. the ...
Sep 16, 1973 - Physical source file characters are mapped to the source character set (introducing new-line ..... instructions that comprise the executable representation of a function) on a per-invocation basis. ...... stl u( t-or-ro~ior~spc~ ifret.
We'll typically write such arguments in proof-tree form: ...... Page 86 ...... To define evaluation, we define the CS machine, which transforms expression-store pairs.
Sep 16, 1973 - 7.5.4 Exponential and logarithmic functions . ...... elrrirOllnze!lr in this International Standard Their characteristics define and ...... Conversions that involve pointers (other than as permitted by the constraints of 6.3.16.1) shal
pearls. LITTLE LANGUAGES. When you say âlanguage,â most programmers think of the big ones, like FORTRAN or COBOL or Pascal. In fact, a language is any ...
Answers to the Final Exam on. Prolog Programming. Christian Rinderknecht. 3 December 2008. 1 Sorting leaves in a binary tree. Question. Design a simple ...
on similar sets of basic principles, yet they all differ in their precise in- terpretation of these principles. Moreover, if the prototype-based model advocates concrete ...
Dele g ation as a s h arin g mec h anism b et w een representations of differ - ent entities I n the fi ...... Ada Reference Manual and Rationale for the D esign of the Ada ... cial Issue ofACФСSIGP ÐAN Notices ¦ 1 ( 11 ) , pages 214-223, 19 8 6.
useful set of simple concepts that map easily onto the IBM 704 architecture, and ...... is written as not, conjunction (and) is written as andalso and disjunction (or).
You also learn C, as a part of C++ or by itself (for system programming), so you are ... which is mainly an introduction to the Prolog programming language, al-.
Expert systems are more similar to a database of domain-specific infor- mations and logic rules (simpler than within proof assistants) which allow queries to be ...
In this work, we use adaptive archetypes to show that virtual machines and operating systems can agree to fulfill this ambition. 1 Introduction. The implications of ...
in Silicon Valley, and has been a statistical consultant for firms such as the ... The main programming language used is C (C++ if you prefer), but some of the ...
their payoffs, ra = (...,ra,s,...), are denominated in units of the commodity. 1. Develop the first order conditions for individual optimization in the asset market. 2.
Oct 4, 2005 - know exactly their names for the C language, we still can find meaningful names based on what ... The method to answer these questions is simply to try small words by constructing ... Let us test the membership with x = aba:.
Oct 25, 2005 - Write an integer postfix calculator in Lex. For example, expressions such as 1 2 + and 1 2 3 4 /*- should be evalu- ated respectively to 3, i.e. 1+2 ...