Top Banner
EE473 Midterm Exam Purdue University Spring 2013 There are 4 questions in this midterm exam. You are to answer 3 out of the 4 questions. Indicate below which 3 questions you wish to have graded. If you do not indicate exactly 3 questions, we will not grade your exam. The 3 questions that you choose to have graded are equally weighted. All of your solutions must be written on the exam handout and no other handins will be accepted or graded. We have a supply of extra exams, thus if you want more space to write your solution, raise your hand and ask for another copy of the exam. We will only grade one solution per problem per student. If in the process of writing your solution you explore alternate approaches, you must clearly cross out the portion of your solution that you do not wish to be graded. All of the copies of this exam that you received should be returned to the proctor at the end of this exam. No copies of this exam may be removed from the exam room by students. All exams handed in must have the student’s name, PUID, and ECN userid indicated below or they will not be graded. Good luck and have fun!. Circle the three questions you wish to have graded: 1 2 3 4. Name: PUID: ECN userid: 1
21

EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

Mar 15, 2018

Download

Documents

duongkhanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

EE473 Midterm Exam

Purdue University

Spring 2013

There are 4 questions in this midterm exam. You are to answer 3 out of the 4 questions. Indicate belowwhich 3 questions you wish to have graded. If you do not indicate exactly 3 questions, we will not grade yourexam. The 3 questions that you choose to have graded are equally weighted. All of your solutions must bewritten on the exam handout and no other handins will be accepted or graded. We have a supply of extraexams, thus if you want more space to write your solution, raise your hand and ask for another copy of theexam. We will only grade one solution per problem per student. If in the process of writing your solutionyou explore alternate approaches, you must clearly cross out the portion of your solution that you do notwish to be graded. All of the copies of this exam that you received should be returned to the proctor atthe end of this exam. No copies of this exam may be removed from the exam room by students. All examshanded in must have the student’s name, PUID, and ECN userid indicated below or they will not be graded.Good luck and have fun!.

Circle the three questions you wish to have graded: 1 2 3 4.

Name:PUID:ECN userid:

1

Page 2: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

Problem 1: Write an inductive definition of a function sort that takes a list of numbers as input andreturns list of numbers as output, sorted in increasing order. You are to formulate the definition in thestyle that we have been using throughout the semester, that is as a functional definition without assignmentstatements or any form of variable or data structure mutation. Write your answer in a combination of Englishand mathematical notation. Do not write your answer in Scheme.

2

Page 3: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

3

Page 4: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

4

Page 5: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

5

Page 6: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

6

Page 7: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

Problem 2: An expression is:• a number,• x, where x is a variable,• (e1 + e2), where e1 and e2 are expressions,• (e1 − e2), where e1 and e2 are expressions,• (e1 × e2), where e1 and e2 are expressions,• (e1 ÷ e2), where e1 and e2 are expressions,•√e, where e is an expression, or

• let x be e1 in e2 end, where x is a variable and e1 and e2 are expressions.

An environment ρ is a partial function that maps variables to values. We will use the notation ρ(x) to denotethe value of the variable x and the notation ρ[x 7→ v] to denote the function that maps the variable x to thevalue v and maps all other variables to the same values as ρ.

Write an inductive definition of an evaluation function E that takes an expression and an environment asinput and returns the value of that expression as output. Write your answer in mathematical notation. Donot write your answer in Scheme.

7

Page 8: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

8

Page 9: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

9

Page 10: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

10

Page 11: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

11

Page 12: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

Problem 3: A formula is:• #t,• #f,• (and Φ1 . . .Φn), where Φ1, . . . ,Φn are formulas,• (or Φ1 . . .Φn), where Φ1, . . . ,Φn are formulas, or• (not Φ), where Φ is a formula.

Write a set of rewrite rules that rewrites a formula to its value.

12

Page 13: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

13

Page 14: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

14

Page 15: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

15

Page 16: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

16

Page 17: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

Problem 4: Let us represent nonnegative integers in binary as lists of ones and zeros with the high-orderbit to the left. For example, the number six will be represented as (1 1 0). Write a set of rewrite rulesthat increment binary numbers. For example, your rewrite system should rewrite (increment (1 1 0)) to(1 1 1). You need to handle binary numbers of any length.

Hint: you will need to proceed from right to left and propagate the carry as you do so.

17

Page 18: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

18

Page 19: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

19

Page 20: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

20

Page 21: EE473 Midterm Exam Purdue University Spring 2013 · PDF fileEE473 Midterm Exam Purdue University Spring 2013 ... We will only grade one solution per problem per student. ... and ECN

21