Define a function insert to insert a new binding

Assignment Help Computer Engineering
Reference no: EM131394370

Programming Languages and Paradigms Assignment

Please answer all questions:

Question 1: This is a classic example of a higher-order function in action. Newton's method can be used to generate approximate solutions to the equation f(x) = 0 where f is a differentiable real-valued function of the real variable x. The idea can be summarized as follows:

Suppose that x0 is some point which we suspect is near a solution. We can form the linear approximation l at x0 and solve the linear equation for a new approximate solution. Let x1 be the solution to the linear approximation l(x) = f(x0) + f'(x0)(x - x0) = 0. In other words,

f(x0) + f'(x0)(x1 - x0) = 0

x1 - x0 =   - (f(x0)/f'(x0))

x1 = x0 - (f(x0)- f'(x0))

If our first guess x0 was a good one, then the approximate solution x1 should be an even better approximation to the solution of f(x) = 0. Once we have x1, we can repeat the process to obtain x2, etc. In fact, we can repeat this process indefinitely: if, after n steps, we have an approximate solution xn, then the next step is

xn+1 = xn - (f(xn)/f'(xn)).

This will produce approximate solutions to any degree of accuracy provided we have started with a good guess x0. If we have reached a xn such that |f(xn)| < t, where t is some real number representing the tolerance, we will stop.

Implement a function called Newton with the type shown below

val newton : f:(float -> float) * guess:float * tol:float * dx:float -> float

Question 2: In this question you will implement one-variable polynomials as lists. Use the following type definitions and exception declaration

type term = Term of float * int

type poly = Poly of (float * int) list

exception EmptyList

Question 3: In this exercise you will work with expression trees very similar to the ones discussed in class and you will implement a little interpreter for them. The main difference is that you will implement your own lookup and insert functions to keep track of bindings and you will return option values. This could be done easily with the Map collection type but I want you to get the idea of how one handles situations where the item you are looking for is not present. Thus we will use lists and raw pattern matching and explicit insertions of Some and None.

Define a function lookup, to lookup values in the binding list. If the name occurs more than once it must find the latest value inserted. We never remove values from the binding list. The binding list must be kept sorted by the name of the variable. You can use the < operator on strings but you need to give a type annotation to tell the system that you are using it on strings. Your lookup function should use options to deal with values that are not present.

Define a function insert to insert a new binding in the right place in the binding list.

Define a function eval which evaluates expressions and returns options.

Question 4: This question involves the Map collection library. Please read documentation on this collection from the web. We are going to model a couple of weeks of the English Premier League Football Season.

Question 5: In this question we will implement some (very) simple graph algorithms: we will be given a road map and we will look for paths between cities. We are given the map as a list of pairs. The first item in each pair is the name of a city and the second item is a set of cities; these are the cities directly connected to the first city.

We use the following type definitions and raw data

Write the code for the function make RoadMap.

Finally, write a function that takes the number of steps as a parameter and finds which cities are up to that number of steps away.

Question 6: Annoying question; it will teach you patience and attention to detail. Write a program to display a polynomial on the screen in the manner that we are used to. This means that if the coefficient is 1:0 we don't write it, if the exponent is 0 we omit it, the terms are ordered by decreasing degree and zero terms are not displayed except in the special case of the zero polynomial.

Question 7: This one is for ambitious students interested in the theory of algorithms. It is hard; I was not able to do it, but in the past 26 years that I have taught at McGill 3 people have done it. Come up with the best (i.e. fewest comparisons) algorithm that you can to find the largest and the second largest numbers in a set of n numbers. There is an algorithm that can do it with n+log2 n 2 comparisons. The real challenge: prove that this is the best possible.

Attachment:- Assignment Files.rar

Reference no: EM131394370

Questions Cloud

What might account for the gaps seen in the histogram : What might account for the gaps seen in the histogram?- Is the histogram unimodal?- What advice might you give the analyst about the appropriateness of this display?
Write an essay discussing the test and what you think of it : Write an essay discussing the test and what you think of it. Include responses to following questions. Justify your responses. What profile did you receive? Do you agree?
Determine the implications of trade barriers on your company : Determine the implications of the trade barriers on your company. Do these barriers hinder your company's business? Define trade barriers in your specific international market.
Calculate appropriate summary statistics : Graph the given data.- Calculate appropriate summary statistics.- Write a few sentences about these data. (Remember: shape, center, spread, unusual features.)
Define a function insert to insert a new binding : COMP 302 Programming Languages and Paradigms Assignment. Define a function insert to insert a new binding in the right place in the binding list. Define a function eval which evaluates expressions and returns options
How will the firm''s eps be affected : According to this information, how will the firm's EPS be affected if its amount of EBIT turns out to be 5 percent higher than expected?
What is jj’s degree of operating leverage (dol) : The CFO of Jupiter Jibs (JJ) expects this year's sales to be $2.5 million. EBIT is expected to be $1 million. The CFO knows that if sales actually turn out to be $2.3 million, JJ's EBIT will be $880,000. What is JJ's degree of operating leverage (..
How can people learn more about the event : How can people learn more about the event? Remember to include contact information and direct people to digital resources here. What sponsor information needs to be included in your communication?
Examine kristoff''s and barumas conclusions : Sample Assignments For English 1101 - Examine Kristoff's and Baruma's conclusions and discuss below the strategy each uses.What rhetorical method does each use for development? Is the topic sentence stated? What transitions do the writers use

Reviews

len1394370

2/15/2017 1:55:14 AM

Use the assigment templates! You can find them on the course web page. Test your code before you submit it!!! Now that we are past the first assignment, feel free to use library functions. Of particular note are List.fold, List.map, List.filter, and the equivalent functions on sets – Set.fold, .... Submit assignments in the formats specified. Submit only your source code (the .fs file). Don’t submit compiled code (.exe) or .zip. If you can’t figure out a particular assignment question, don’t take the function out of your code; leave it in with a failwith "Not Implemented". Make sure that your code compiles, by which we mean there shouldn’t be an error when you send your code to the terminal, or when you do fsharpi assignment.fs. We have very low tolerance for code that doesn’t compile as it can be very time-consuming to figure out the source of the issue. Make sure the types of your functions match up with the types given in the assignment. For example, the sumlist function from assignment 1 should have type float list -> float and not int list -> int.

len1394370

2/15/2017 1:22:00 AM

Topic: McGill COMP302 (the course is using f#). Detailed Question: Ok, so I would want you to do Question 2, 4, and 5. I have also attached my assignment 2 materials with the assignment. Just want to let you know our assignments have strict restrictions: We cannot change any type definitions and anything that is defined on the template that the professor gave us, and this assignment is allow to use all List.map, List.fold, Map.map, etc. Please answer all questions: there are 5 in all plus two for spiritual growth. You must use the function names that we have given. We will put a file on the web site which you should use as a template. Questions 6 and 7 are for your spiritual growth only. Please do not submit any answers.

Write a Review

Computer Engineering Questions & Answers

  Outline a plan for the development of an addressing and

write a three to four 3-4 page paper in which you1 outline a plan for the development of an addressing and naming model

  Algorithm to prepare a job applicant report

Develop an algorithm in order to prepare a job applicant report. Input consists of a series of records that contain the Social Security number or equivalent, last name, first name, middle initial, verbal test score, science test score, math test s..

  How to consider changing the hibernate framework

This Application challenges you to evaluate connectivity issues between database management systems (DBMS) and the procedural programming languages.

  Describing the main components and users of the system

Decompose the application using data flow diagrams, system architecture diagrams, and a table describing the main components and users of the system

  Developing a shopping cart for a website

Developing a Shopping Cart for a Website - Write a program that explores the seating patterns - Now that you have built a web page for your business, you will be adding a shopping cart allowing users to add and remove items from it.

  Write a report on your attempts to solve multiplexer problem

UFCFY3-15-3 Advances in Artificial Intelligence: Resit Assignment. Write a report on your attempts to solve the multiplexer problem of size k=2 as effectively as possible using any form of evolutionary intelligence covered in the course, building u..

  Prepare a paper comparing three of the design patterns

Prepare a 2- to 3-page paper comparing and contrasting three of design patterns listed. Choose any three from the list. First describe/explain in some detail, what each of your selected design pattern choices have in common with each other.

  Give a program that reads a 5 x 5 two-dimensional array

Write down a program that reads a 5 x 5 two-dimensional array of integers and then prints the row sums and the column sums.

  Determine the spectrum of a signal describe the

question 1 explain the relationship between frequency period and wavelength in a sine wave.question 2 what is the

  Compute the number of pages in the virtual address space

Compute the number of pages in the virtual address space and what is the maximum size of addressable physical memory in this system?

  Produce a book class that stores book information

Produce a Book class that stores book information

  Write down a perl program that given a dna string prints

write a perl program that given a dna string prints out the 20 characters upstream of the start codon atg. that is

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd