4 Pages

hw3

Course: CSE 452, Fall 2008
School: Michigan State University
Rating:
 
 
 
 
 

Word Count: 1072

Document Preview

452 CSE Due: Homework #3 Thursday September 25 Your answers to these questions are to be submitted as a single ML program using handin. Use ML comments to clearly delineate where the answer to each problem starts and ends. Embed your answers to non-coding questions as comments in this same le. 1. (a) Write the function zip to compute the product of two lists of arbitrary length that is, given two lists l1 and...

Register Now

Unformatted Document Excerpt

Coursehero >> Michigan >> Michigan State University >> CSE 452

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
452 CSE Due: Homework #3 Thursday September 25 Your answers to these questions are to be submitted as a single ML program using handin. Use ML comments to clearly delineate where the answer to each problem starts and ends. Embed your answers to non-coding questions as comments in this same le. 1. (a) Write the function zip to compute the product of two lists of arbitrary length that is, given two lists l1 and l2, the application zip l1 l2 should return the list of pairs obtained by pairing up corresponding elements of l1 and l2; if the lists do not have the same lengths, then it should pair up elements until the shorter of the two lists is exhausted. You should use pattern matching to dene this function. Here are some examples to illustrate the behavior of zip: - zip [1,3,5,7] ["a","b","c","de", "f"]; val it = [(1,"a"),(3,"b"),(5,"c"),(7,"de")]: - zip [] [1, 5, 6]; val it = nil (int * string) list Now write the inverse function, unzip, which behaves as follows: - unzip [(1,"a"),(3,"b"),(5,"c"),(7,"de")]; val it = ([1,3,5,7], ["a","b","c","de"]): int list * string list Write zip3, to zip three lists. - zip3 [1,3,5,7] ["a","b","c","de", "f"] [1,2,3,4,5,6]; val it = [(1,"a",1),(3,"b",2),(5,"c",3),(7,"de",4)]: (int * string * int) list (b) In principal, you could dene a function zip1000 that zips together 1000 lists in the same fashion that you dened zip and zip3, although actually writing out the denition of this function would be onerous. (You could write a program that would generate the function denition.) However, you cannot write a function zipAny that can zip together any arbitrary number of liststhat is, a function that takes a list of lists ll and returns the list obtained by zipping together all the lists in ll. Explain why it is impossible to dene such a list in ML. 2. Certain programming languages (and HP calculators) evaluate expressions using a stack. You are going to implement a simple evaluator for such a language. Computation is expressed as a sequence of operations, which are drawn from the following data type: datatype OpCode = | | | | PUSH of real ADD MULT SUB DIV 1 | SWAP ; The operations have the following eect on the operand stack. (The top of the stack is shown on the left.) OpCode PUSH r ADD SUB DIV SWAP Initial Stack ... a b... a b... a b... a b... Resulting Stack r... (a+b)... (a-b)... (a/b)... b a... The stack may be represented using a list for this example, although you could also dene a stack data type for it. type Stack = real list; Write a recursive evaluation function with the signature eval: OpCode list * Stack -> real This function should take a list of operations and a stack. It should perform each operation in order and return what is left on the top of the stack when no operations are left to be performed. For example, eval([PUSH 2.0, PUSH 1.0, SUB],[]) returns 1.0. The eval function will have the following basic form: fun eval (nil,a::st) = (* ... *) | eval (PUSH(n)::ops,st) = (* ... | (* ... *) | eval ( , ) = 0.0 ; *) You need to ll in the blanks and add cases for the other opcodes. last The rule handles illegal cases by matching any operation list and stack not handled by the cases you write. These illegal cases include ending with an empty stack, performing addition when fewer than two elements are on the stack, and so on. You may ignore divide-byzero errors for now (or look at exception handling in ML; we will cover that topic in a few weeks). 3. This problem is based on problem 5.4 of Mitchell. 2 (a) Answer part (a) of problem 5.4 in Mitchell. In addition, show how to use the tree datatype by declaring identiers tree1 and tree2 that represent the trees shown in the diagram below. tree1 tree2 "waste" 3 2 ~6 1 0 "not" "want" "not" "!" Next, show how to use your maptree function in declaring identiers tree3 and tree4 representing new trees as described below. Do this without declaring any additional new identiers. (Recall that functions can be anonymous.) tree3: the tree produced from tree1 by negating the values at the leaves of tree1. tree4: the tree produced from tree2 by concatenating a single blank space to the front of each string value in the leaves of tree2. (b) Read part (b) of problem 5.4 in Mitchell. I am not sure why he refers to the type expression given in the problem as the expected type I would not have expected it to have that type. So, rather than answer the question asked in this part of the problem, show an ML expression that applies maptree to a function whose domain and range are of dierent types and to one of the trees created in part (a) of this problem. Use this example to explain what is meant by the statement that The ML type inference algorithm computes the most general type possible for an ML expression. 4. This problem is based on problem 5.5 in Mitchell. (a) Write a function reduce, as described in part (a) of problem 5.5 in Mitchell. (You do not need to explain your denition, as requested in Mitchell.) (b) Write an ML expression that uses the function reduce to compute the product of the values at the leaves of tree1. (c) Write an ML expression that uses the function reduce to compute the string " waste not want not !" from tree2. Do not declare any additional identiers in doing so. (Again, you will need to use an anonymous function.) 3 5. This problem is based on problem 5.6 in Mitchell. (a) Write functions Curry and UnCurry as requested in part (a) of problem 5.5 in Mitchell. As some additional explanation, your version of Curry should transforms a function f that takes a pair of arguments into a function fcurry of a single argument x such that the result of applying fcurry (x) to an argument y is f (x, y). For example, Curry op+ 2 3 should compute 5, because op+(2,3) computes 5. UnCurry is the inverse of Curry. It converts a function g that returns another function into a function gUnCurry on a pair of arguments. For example, UnCurry map (op~,[1, ~1]) should compute [~1, 1], because map op~ [1, ~1] computes [~1, 1]. (b) Use your Curry function to declare a function insertFront: a -> a list -> a list so that the function insertFront x has the eect of inserting x at the front of each list in a list of lists. For example, - insertFront 5 [[2, 1], [0], []]; val it = [[5,2,1],[5,0],[5]] : int list list (c) Answer part (b) of problem 5.6 in Mitchell. 4
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Michigan State University - CSE - 452
PatternsGeneral form of a declaration:val <pattern> = <exp>;Canbeusedtobindmultipleidentifierstovalues:- val (height, width) = (20, 10);val height = 20 : int val width = 10 : int- val {name = n, age = a} = {age = 10, name = Big Bird
Michigan State University - CSE - 452
-6Exception handlingChair of Software EngineeringHow to use exceptions?Two opposite styles: Exceptions as a control structure: Use an exception to handle all cases other than the most favorable ones (e.g. a key not found in a hash table triggers
Michigan State University - CSE - 452
Play with EiffelStudio (from http:/se.ethz.ch/teaching/2008-H/eprog0001/exercises/assignment_1.pdf) 1. Download Traffic from http:/traffic.origo.ethz.ch/download and unzip it to a folder of your choice (it's recommended to use a path without any spac
Michigan State University - CSE - 452
Object Oriented ProgrammingPrimary object-oriented language concepts dynamic lookup encapsulation inheritance subtypingProgram organization Organize concepts into objects and relationships between them Build program to be extensible Both
Michigan State University - CSE - 471
CSE 471Media Processing and MultimediaPhasors PhasorsAand phasor mathmuch more efficient way to analyze manipulations of digital audio1CSE 471Media Processing and MultimediaNow, some simple questions? Whatdo I get if I add two sinu
Michigan State University - CSE - 471
Digital FiltersEffect such as echo and chorus are commonly referred to as temporal effects. They are easily understood as operations based of (relatively) large time delays. However, it's common that digital signals, such as digital audio, will be a
Michigan State University - CSE - 471
CSE 471Media Processing and MultimediaVideo What Howis videowould you define it?1CSE 471Media Processing and MultimediaThree Worlds of Video ComputerVideo Very unconstrained BroadcastVideo (existing, but soon to go away) Ad
Michigan State University - CSE - 471
CSE 471Media Processing and MultimediaSound, Sinusoids, and Spectrum Striking Strings Tubes Analoga Tinevs. Digital1CSE 471Media Processing and MultimediaWhat is sound? Soundis a wave of vibrating pressure variations created in a
Michigan State University - CSE - 471
CSE 471Media Processing and MultimediaSampling and Quantization Capturingsounds electronically Sampling sounds Aliasing Quantization1CSE 471Media Processing and MultimediaElectronic capture of soundsN S2CSE 471Media Processing a
Michigan State University - CSE - 472
CSE472Computer GraphicsShading Models Whereto compute colors Simulating Curved Surfaces Smooth Shading Gourard Shading Phong Shading Problemswith Smooth Shading1CSE472Computer GraphicsComputing Colors Weare drawing primitives!
Michigan State University - CSE - 472
CSE472Computer GraphicsCurves III Don'twe have all we need? Spline Curves NURBS1CSE472Computer GraphicsInterpolating Curves Aninterpolating curve will hit certain points on the curve. Bezier curves hit the end points What if we ha
Michigan State University - CSE - 472
CSE472Computer GraphicsCSE 472 Computer Graphics CharlesB. Owen (Instructor) 1138 E. B., 353-6488 ZubinAbraham (TA and grading) Classroom: 1225 Engineering Building1CSE472Computer GraphicsIntroduction Introduction Introductiont
Michigan State University - CSE - 802
Michigan State University - CSE - 802
Michigan State University - CSE - 802
Michigan State University - CSE - 802
Pattern RecognitionCSE 802 Michigan State University Spring 2008Pattern RecognitionThe real power of human thinking isbased on recognizing patterns. The better computers get at pattern recognition, the more humanlike they will become. Ray Kurzw
Michigan State University - CSE - 802
Recognizing FacesDirk ColbryOutline Introduction and Motivation Defining a feature vector Principal Component Analysis Linear Discriminate Analysis1!" # $ "" "%http:/www.infotech.oulu.fi/Annual/2004+& ' ( ) *)' +) *2!& & "
Michigan State University - CSE - 872
Ray Tracing Variants Distributed ray tracing Generalized rays Cone Tracing Beam Tracing Pencil Tracing Constructive solid geometry Acceleration methods1CSE 872 Dr. Charles B. Owen Advanced Computer GraphicsDistributed Ray Tracing Genera
Michigan State University - CSE - 872
CSE 872: Advanced Computer GraphicsFall Term 20081 Course InformationThis course is a second computer graphics class at the graduate level. My approach in this class is to introduce and experiment with many advanced techniques. Everyone will be e
Michigan State University - ECE - 305
ECE 305 Homework Set #2 Spring 2002 All Problems are in Cheng Chapter 2Kempel Due: OPTIONALAll homework must be completed NEATLY! (If I cant read it, I cant grade it!) Only some of the problems will be marked in detail (I wont tell you which ones
Michigan State University - ECE - 305
Michigan State University - ECE - 305
Michigan State University - ECE - 407
ECE 407ELECTROMAGNETIC COMPATIBILITYMWF 12:40-1:30 118 FAESpring 2006Instructor: Office: Phone: E-mail: Office Hours: Web site: Text:Ed Rothwell C133 Engineering Research 355-5231 rothwell@egr.msu.edu MWF 11:30-12:20, 2234 EB (EM lab) http:/
Michigan State University - ECE - 412
Michigan State University - ECE - 412
ECE 412: Mixed-signal circuitsDue Friday (09/28/2007)Homework 3In this assignment you will use Cadence tools to simulate the response of the following circuits. If you choose you could use other Pspice tools as long as you are using similar tran
Michigan State University - ECE - 412
Michigan State University - ECE - 412
ECE 412: Mixed-signal circuit designDue Tuesday (11/19/2007)Homework 6In this assignment you are required to use cadence simulations to design an operational amplifier (using the circuit in Figure 1) with the following specifications. You would
Michigan State University - ECE - 412
ECE 412: Mixed-signal circuit designDue Friday (11/12/2007)Homework6For the following circuits use the following values of parameters. No simulations are required for this homework.g m = 10 6 1 , g d = 10 8 1 , C gs = 0.5 pF , C gd = 0.02 pF
Michigan State University - ECE - 418
Cadence Transient Analysis GuideCreated for the MSU VLSI program by Professor A. Mason and the AMSaC lab group. Overview Often in circuit design there are parameters to test that require transient analysis. This guide provides information on running
Michigan State University - ECE - 418
ECE 418, Fall 2004 Homework 2 SolutionProblem 1 List 3 reasons why CMOS technology is preferred over bipolar transistor technologies. 1.- CMOS device operation is easier to understand than BJTs - CMOS fabrication is less complicated than BJT tech
Michigan State University - ECE - 418
Cadence Setup Guide: ECE 418Document Contents Introduction How to Setup Cadence for the First Time What to Do Each Time You Run Cadence Additional ResourcesIntroductionThis document provides step-by-step instructions for setting up your ECE 418 c
Michigan State University - ECE - 418
Switched Capacitor CircuitECE 418ECE 418, Fall 2004Switched-Capacitor Circuits, p.1Introduction to Switched-Capacitor (SC) provides compatible design solutions for digital VLSI First introduced for creating integrated filterActive RC filter
Michigan State University - ECE - 418
ECE 418, Fall 2004 Homework 6 Due Wednesday November 10th Learning Objectives: practice small signal analysis of CMOS circuits practice designing CMOS current mirrors explore the design of current and voltage references Assignment: Problem 1 a) Dr
Michigan State University - ECE - 418
Lecture 17 Outline Chapter 4 Analog CMOS Subcircuits Comments on last 3 lectures Current and Voltage References Bandgap References Current Source/Mirror ReviewECE 418, Prof. A. MasonCh 4: Analog Subcircuits p.41Comments on Last 3 Lectures
Michigan State University - ECE - 418
Homework GuidelinesProfessor A. MasonThe following guidelines should be followed for all homework papers submitted to Dr. Mason. Basic Info: Homework papers should have your name and the name of the assignment (e.g., Homework 3) on the top of t
Michigan State University - ECE - 418
Cadence Analog Tutorial 1: Schematic Entry and Transistor CharacterizationCreated for the MSU VLSI program by Professor A. Mason and the AMSaC lab group. Revision Notes:July2004 Generate tutorial for single transistor analysis. Based on existing sc
Michigan State University - ECE - 418
Cadence Tutorial A: Schematic Entry and Functional SimulationCreated for the MSU VLSI program by Professor A. Mason and the AMSaC lab group. Revision Notes:July 2004 Created tutorial for analog simulation A. Gore, N. Trombly, A. MasonDocument Con
Michigan State University - ECE - 418
ECE 418, Fall 2004 Project 4: Design of a Two-Stage CMOS Operational Amplifier Learning Objectives: Experience designing multi-stage CMOS integrated circuits. Design CMOS operational amplifiers to achieve specific performance parameters. Practice
Michigan State University - ECE - 418
Lecture 24 Outline Chapter 6: Operational Amplifiers Note: skipping 6.2 topics 6.3 Two-Stage Op Amps Not covered in detail Controlling the Right Half-Plane Zero Feedforward Compensation covered only briefly in lecture youll need to read and s