Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following problem must be solved and written in Scheme programming language: 1. Re-write the following arithmetic expressions as Scheme expressions and show the result

The following problem must be solved and written in Scheme programming language:
image text in transcribed
1. Re-write the following arithmetic expressions as Scheme expressions and show the result of the Scheme interpreter when invoked on your expressions. (a) (22+42) (54 x 99). (b) ((22+42) x 54) x 99. (c) 64 x 102 + 16 x (44/22). 2. Reflect on the expressions above. (a) Of course, the first two expressions evaluate to the same number. In what sense are they different? How is this reflected in the Scheme expression? (b) In an unparenthesized infix arithmetic expression, like 3+4.5, we rely on a convention to determine which operation we apply first (rules of precedence). Are rules of precedence necessary for arithmetic operations Scheme? 3. Write Scheme definitions for the functions below. Use the interpreter to try them out on a couple of test cases to check that they work, and include this output with your solutions NOTE: Scheme provides built-in support for exponentiation (via the expt function, defined so that (expt x y) yields r"). For the exercises below, however, please construct the functions ** using only and function application. (a) cube, the function cube(x) = ? (b) p, the polynomial function p(I) = (x + 11x + 24r - 2+21) (Hint: Of course it is possible to expand (5 + 112 + 242-+21) as a polynomial of degree 15 and write a Scheme function to compute this by brute force. You can avoid much of this computation by defining p in stages first define the polynomial a(z) = +11 +243-+21 as a Scheme function; now use this function to define p.) (c) Using your function cube, write the function tenth(I) = 210 (d) Using the function tenth, write the function hundredth(z) = 2100 Recall that 100 = 10 x 10 (e) How might you check to see whether your hundredth function gives you the right answer? (1) Reflect on your definition of hundredth above. What would have been the difficulty of defining this merely in terms of *? 4. Write and test the following functions that deal with points and lines in the Cartesian plane. (a) (y-value x bm), a function of three parameters (an I value, a y-intercept b, and a slope m) that returns the y value of the line at that, that is mr + b. (b) (points-slope x1 y1 x2 y2), a function of four parameters (the x and y values of two points) that calculates the slope of a line through those points (71.1) and (12, 12). You may assume that the two points are distinct. (Note: this function is not required to work if the slope of the line is undefined.) (c) (points-intercept x1 y1 x2 y2), a function of four parameters (the x and y values of two points) that calculates the y-intercept of a line through points (1.1) and (32,12). You may assume that the two points are distinct. (Note: this function is not required to

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions