hw6 - CS20a Homework #6 November 14, 2002 Due November 21,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS20a Homework #6 November 14, 2002 Due November 21, 2002 Exercise 1. Partial recursive functions Show that every while program over N is equivalent to a while program with at most 1 while loop. Exercise 2. Primitive recursive functions Show that a function is primitive recursive iff it is computed by a Turing Machine with a prim- itive recursive time bound. For this problem, assume a Turing Machine computes a function Σ * → { , 1 } , where the argu- ment is the input string, and the result is 1 iff the Turing machine accepts. A Turing Machine is time-bounded by a primitive recursive function f : N → N iff for any input string x , the Turing Machine accepts or rejects within f ( | x | ) moves. Exercise 3. Laboratory For this lab, we will build an evaluator for the λ-calculus with numbers and conditionals. Here is the syntax of the language: e :: = i (numbers) | x (variables) | e 1 e 2 (application) | λx.e (functions) | e 1 binop e 2 (binary arithmetic) | if e 1 then e 2 else e 3 (conditional) | let v = e 1 in e 2 (let definition) | letrec f v = e 1 in e 2 (recursive function definition) binop :: = + | - | * | / |=|≤| < |≥|≥| ≠ Evaluation is defined using evaluation rules . If e ↓ v we say the program e evaluates to the value v , where a value is a number or a function. The exact specification of evaluation is defined through evaluation rules. If we were using substitution (like we did in class), the evaluation semantics would look something like this. i ↓ i number e 1 ↓ i 1 e 2 ↓ i 2 e 1 binop e 2 ↓ (i 1 binop i 2 ) binop e 1 ↓ λx.e 3 e 2 ↓ v 2 e 3 [e 2 /x] ↓ v 3 e 1 e 2 ↓ v 3 app λx.e ↓ λx.e fun e 1 6↓ e 2 ↓ v 2 if e 1 then e 2 else e 3 ↓ v 2 if-true e 1 ↓ e 3 ↓ e 3 ↓ v 3 if e 1 then e 2 else e 3 ↓ v 4 if-false The problem with this semantics is that it is really inefficient because the usual definition of substitution e 1 [e 2 /v] requires copying the entire expression e 1 . An alternative definition that is much more widely used is to define a variable environment that keeps track of values for variables. When a variable is evaluated, the value is retrieved from the environment. We’ll use the notation σ for an environment. The environment supports two operations: we get the value of a variable...
View Full Document

This note was uploaded on 04/06/2010 for the course CS 20A taught by Professor Cs during the Spring '10 term at Abant İzzet Baysal University.

Page1 / 5

hw6 - CS20a Homework #6 November 14, 2002 Due November 21,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online