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)
- Problem 1 (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words. Here is how your program should work to simulate the ransom problem: your program should prompt the user to enter a long String to represent the magazine and another short String to represent the required ransom note. your program needs to check if the magazine string contains all required characters in equal or greater number present in the ransom note. your program should print true if it is possible to create the given ransom note from the given magazine, and print false otherwise. Break up your code into a set of well-defined functions. Each function should include a comment block that briefly describes…arrow_forward*PLEASE SOLVE USING PYTHON* You are a nasa engineer who needs to monitor the situation every time a probe uses its thrusters. For a given day you are given the planned times when the thruster will be used. You need to be monitoring the situation at those boost times and for 5 minutes after. You want to figure out if you can take a break for a certain number of minutes. To achieve this you are given the planned boost times in in hours and minutes with an am/pm. And you are given a desired break time in minutes. Output if you can take the break or not given the monitoring you have to do. For example: If you know the thruster is fired at 5:00am and 12:50pm. You need to be monitoring the situation from 5:00am to 5:05am and again from 12:50pm to 12:55pm. Apart from those times you are free to take a break. So a 5 minute break is possible. But a 12 hour break is not possible.arrow_forwardplease do 2) and 3)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_forward(8) Discrete Structure: Please solve it on urgent basis: Question # 8 : Prove that n2−1 is divisible by 8 whenever n is an odd positive integer.arrow_forwardUse c# for the following casearrow_forward
- use c++.arrow_forwarduse python codearrow_forward2. (13-09-2022) Let n number of identical small boxes are there where each of the first i boxes contains a diamond and remaining ni are empty. Harry Potter got two magic sticks that can test whether a box is empty or not in a single touch, except that a magic stick vanishes if he tests it on an empty box. How Harry Potter knows the value of i using two magic sticks to determine all the boxes containing pearls using at most o(n) touches?arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr