Question: answer the question with haskell code Exercise 2. Suppose we have the following in a script. Perform equational reasoning by hand execution for the function
answer the question with haskell code
Exercise 2. Suppose we have the following in a script. Perform equational reasoning by hand execution for the function roots. Use a = 1, b = 2, c = 1, and then check with the computer:
f::Double -> Double -> Double -> Bool
f a b c = if (b^2-4*a*c) < 0 then False else True
g::Double -> Double -> Double -> Double
g a b c = (b^2-4*a*c)
roots::Double -> Double -> Double -> Maybe (Double, Double)
roots a b c
| f a b c == False = Nothing
| otherwise =
let r = sqrt(g a b c)
x1 = (-b + r)/2*a
x2 = (-b - r)/2*a
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
