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

  When building a house a structured modular approach is

answer this question in 200 to 300 words. this is an it programing question1. when building a house a structured

  Information systems typically support different work

information systems typically support different work models. you have been asked to create a report on what work

  Compare two architectural styles

Consider their flexibility, how easy they are to understand and use, and quality of applications they might  produce. Discuss any experiences you have had using these patterns. How has your prior training and preparation influenced your evaluation..

  Left most derivation

A->a|aS|bAA, B->b|bS|aBB, For the string “aaabbabbba” determine a Left most derivation.

  Smmarize onenbsp theory of victimization that dr carla

in the scenarios and resulting simulations dr. carla odonnell discusses theories of victimization. sgt. barry evans

  Make a non-gui based java application

make a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week.

  Show what your code has produced

Submit your JSP page along with the screenshots that show what your code has produced.

  How converting between different data system

I would like to know how I can convert from signed binary numbers to decimal values, from decimal numbers to signed magnitude, 2's complement, and short floating point format. Also, it would be better to provide examples with positive and negative..

  Termination and resumption models of continuation

Describe three approaches to exception handling in languages that do not provide direct support for it - Summarize the arguments in favor of the termination and resumption models of continuation.

  Write a class that encapsulates a deck of cards

Write a class (and a client class to test it) that encapsulates a deck of cards. A deck of cards is made up of 52 cards. You should have three instance variables.

  How many cars in every team called chevy and ford

How many cars in every team called Chevy and Ford There are eight cars in every team called Chevy and Ford. One car from each team races its opponent on drag strip.

  Design reportthe design report is a single team report that

design reportthe design report is a single team report that describes the functionality of the application in its final

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