{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RebindableSyntax #-}
module Integration.Trapezoid (
-- >>> trapezoid_1 f (-1) 1
-- 2.0
--
-trapezoid_1 :: (Field.C a, ToRational.C a, Field.C b)
+trapezoid_1 :: forall a b. (Field.C a, ToRational.C a, Field.C b)
=> (a -> b) -- ^ The function @f@
-> a -- ^ The \"left\" endpoint, @a@
-> a -- ^ The \"right\" endpoint, @b@
-> b
-trapezoid_1 f a b =
- (((f a) + (f b)) / 2) * coerced_interval_length
+trapezoid_1 f x y =
+ (((f x) + (f y)) / 2) * coerced_interval_length
where
- coerced_interval_length = fromRational' $ toRational (b - a)
+ coerced_interval_length = fromRational' $ toRational (y - x) :: b
-- | Use the composite trapezoid rule to numerically integrate @f@
-- over @n@ subintervals of [@a@, @b@].