Answered step by step
Verified Expert Solution
Question
1 Approved Answer
function NeumaierSum ( input ) var sum = 0 . 0 varc = 0 . 0 , ? ? A running compensation for lost low
function NeumaierSum input
var sum
varcA running compensation for lost loworder bits.
for to input.length do
vart sum inputi
if sum inputi then
c sum t inputi If sum bigger, tracks loworder digits of inputi
else
c inputi t sum Else tracks loworder digits of sum.
endif
sum
return sum c Correction only applied once in the very end.
It maintains a running sum and also a compensator that keeps track of things lost to rounding error.
This pseudocode uses modifiable state the vars
Question Modify the NeumaierSum pseudocode so that it does not use any modifiable state. In the HW
object, create the function whose input is a SeqDouble to do this summation. Use the case class
Neumaier defined at the top in scalahw.scala to keep track of the state sum and compensator c Use
foldLeft no indexing to implement the summation algorithm without any loops if you are stuck, examine
how we used foldLeft in class The state that foldLeft uses should be a case class Neumaier so you should
know how to create this thing and how to pull information out of it Remember Do not use vars!!!. Do not
use the return keyword. You must update the function definition to specify its return type.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started