Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1.  
  2. --the quickcheck
  3. prop_polyListValue :: [Integer] -> Integer -> Bool
  4. prop_polyListValue [] _ = True
  5. prop_polyListValue pl n
  6. | plv == pv = True
  7. | otherwise = False
  8. where
  9. plv = polyListValue pl n
  10. pv = polyValue p n
  11. p = polyListToPoly pl
  12.  
  13. --functions used in quickcheck
  14.  
  15. --polyValue from assignment 3
  16. polyValue :: Poly -> Integer -> Integer
  17. polyValue X n = n
  18. polyValue (Coef x) _ = x
  19. polyValue (Sum x y) n = (polyValue x n) + (polyValue y n)
  20. polyValue (Prod x y) n = (polyValue x n) * (polyValue y n)
  21.  
  22. polyListValue :: [Integer] -> Integer -> Integer
  23. polyListValue [] _ = 0
  24. polyListValue pl n = hormeth pl n
  25. where
  26. hormeth (x:[]) n = x
  27. hormeth (x:xs) n = (hormeth xs n) * n + x
  28.  
  29. polyListToPoly :: [Integer] -> Poly
  30. polyListToPoly [] = (Coef 0)
  31. polyListToPoly (x:xs) = Sum (Prod (Coef x) (indexDegree (length xs))) (polyListToPoly xs)
  32. where indexDegree a =
  33. if a == 0 then Coef 1
  34. else Prod X (indexDegree (a - 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement