Practice Problem 5.6 (solution page 575)
Let us continue exploring ways to evaluate polynomials, as described in Practice Problem 5 5. We can reduce the number of multiplications in evaluating a polynomial by applying Horner’s method, named after British mathematician William G. Horner (1786-1837). The idea is to repeatedly factor out the powers of x to get the following evaluation:
a0+x(a1+x(a2+···x(an-1+xan)···)) (5.3)
Using Horner's method, we can implement polynomial evaluation using the following code:
- A. For degree n, how many additions and how many multiplications does this code perform?
- B. On our reference machine, with the arithmetic operations having the latencies shown in Figure 5.12, we measure the CPE for this function to be 8.00. Explain how this CPE arises based on the data dependencies formed between iterations due to the operations implementing line 7 of the function.
- C. Explain how the function shown in Practice Problem 5.5 can run faster, even though it requires more operations.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Additional Engineering Textbook Solutions
C Programming Language
Starting Out With Visual Basic (7th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Java How To Program (Early Objects)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
C++ How to Program (10th Edition)
- I'm stuck on this problemarrow_forward4.1.1 Complete solution and answer only no need explanation Given three data points (1,6), (3,28), and (10, 231), What is the value of y at x = 2 if the function y = 2x2 + 3x + 1 passes through the three data points.arrow_forward(Oceanography) The pressure, P, exerted on an underwater object can be determined by this formula: P=gh is the density of water, which is 1.94slug/ft3 . g is the acceleration caused by Earth’s gravity, which is 32.2ft/sec2. h is the object’s depth in the water in feet. a. Determine the units of P by calculating the units resulting from the right side of the formula. Check that your answer corresponds to the units for pressure listed in Table 1.1. b. Determine the pressure on a submarine operating at a depth of 2500 feet.arrow_forward
- 4. Look up the Pythagorean theorem if you are not already familiar with it. Use the following formula to solve for c in the formula: c = √a2 + b2. Use the proper functions from the cmath header file. Be sure to output the result..arrow_forwardState whether each of the following is true or false. If false, explain why g) Definitions can appear anywhere in the body of a function.arrow_forward4.6.1: Recursive function: Writing the base case. Add an if branch to complete double_pennies()'s base case.Sample output with inputs: 1 10Number of pennies after 10 days: 1024 Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message # Returns number of pennies if pennies are doubled num_days timesdef double_pennies(num_pennies, num_days):total_pennies = 0 ''' Your solution goes here ''' else:total_pennies = double_pennies((num_pennies * 2), (num_days - 1)) return total_pennies # Program computes pennies if you have 1 penny today,# 2 pennies after one day, 4 after two days, and so onstarting_pennies = int(input())user_days = int(input()) print('Number of pennies after', user_days, 'days: ', end="")print(double_pennies(starting_pennies, user_days))arrow_forward
- Solve the problems Solve the quadratic equation 2x^2 + 6x + 4 = 0. Implement a function that takes incoefficients A,B,and C forthequadratic equation Ax2 + Bx + C = 0 and computes the two solutions. Have the function return the number of valid (not NaN) solutions and fill in the return arguments so the smaller of the two solutions is first.arrow_forwardH.W1/ Write an numerical programme to calculate the first derive for the following function y(x)=sin(4x)+cos(4x) in term of an analytic, central, forward and backward differences respectively. using 101 points from x=0 to x=4. and plot the estimates and the actual function derivatives.arrow_forwardPython 3.7.4 Given that add, a function that expects two int parameters and returns their sum, and given that two variables, euro_sales and asia_sales, have already been defined: Write a statement that calls add to compute the sum of euro_sales and asia_sales and that associates this value with a variable named eurasia_sales.arrow_forward
- Redo problem 2 where you have to define and use the following functions: (a) isTriangle - takes 3 sides of a triangle and returns true if they form a triangle, false otherwise. (b) isIsosceles - takes 3 sides of a triangle and returns true if they form an isosceles triangle, false otherwise. (c) isEquilateral - takes 3 sides of a triangle and returns true if they form anequilateral triangle, false otherwise. (d) isRight - takes 3 sides of a triangle and returns true if they form a right triangle, false otherwise. (e) your program should run continuous until the user wants to quit this is my problem 2: #include <iostream> #include <cmath> using namespace std; // Constant Declarations const double E = .0001; int main() { double side1, side2, side3; bool isTriangle, isRight, isEquilateral, isIsosceles; cout << "Enter the lengths of the 3 sides of a triangle -- "; cin >> side1 >> side2 >> side3; isTriangle = side1 + side2 > side3 &&side1 +…arrow_forwardSuppose we have the following function. f(x) = { x2 , |x| <= 1 2|x| - 1 , |x| >= 1 Solve the R programming question attached given this information above. Show all work and the R code.arrow_forwardComputer Science f(x)= Sin(x) – x 3 + C Where C = Max [0.15, (69/100)] x20, (x is in radian). Apply the false position method three iterations to find the root of the function (Decide the starting values of Xl and Xu yourself)arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning