-> a -- ^ The \"right\" endpoint, @b@
-> b
trapezoid_1 f a b =
- (((f a) + (f b)) / 2) * (fromRational $ toRational (b - a))
+ (((f a) + (f b)) / 2) * (realToFrac (b - a))
-- | Use the composite trapezoid rule to numerically integrate @f@
norm_infty = fromInteger
instance Normed Rational where
- norm_p _ = fromRational
- norm_infty = fromRational
+ norm_p _ = realToFrac
+ norm_infty = realToFrac
instance Epsilon e => Normed (BigFloat e) where
- norm_p _ = fromRational . toRational
- norm_infty = fromRational . toRational
+ norm_p _ = realToFrac
+ norm_infty = realToFrac
instance Normed Float where
- norm_p _ = fromRational . toRational
- norm_infty = fromRational . toRational
+ norm_p _ = realToFrac
+ norm_infty = realToFrac
instance Normed Double where
- norm_p _ = fromRational . toRational
- norm_infty = fromRational . toRational
+ norm_p _ = realToFrac
+ norm_infty = realToFrac
-- >>> norm_infty v1
-- 5
--
- norm_infty (Vn v1) = fromRational $ toRational $ V.foldl max 0 v1
+ norm_infty (Vn v1) = realToFrac $ V.foldl max 0 v1
-- | Generic p-norms. The usual norm in R^n is (norm_p 2).
--
-- 5.0
--
norm_p p (Vn v1) =
- fromRational $ toRational $ root $ V.sum $ V.map (exponentiate . abs) v1
+ realToFrac $ root $ V.sum $ V.map (exponentiate . abs) v1
where
exponentiate = (** (fromIntegral p))
root = (** (recip (fromIntegral p)))