Implementation of partial fractions. Useful e.g. for fractions of integers and fractions of polynomials.
For the considered ring the prime factorization must be unique.
- data T a = Cons a (Map (ToOrd a) [a])
- fromFractionSum :: C a => a -> [(a, [a])] -> T a
- toFractionSum :: C a => T a -> (a, [(a, [a])])
- appPrec :: Int
- toFraction :: C a => T a -> T a
- toFactoredFraction :: C a => T a -> ([a], a)
- multiToFraction :: C a => a -> [a] -> T a
- hornerRev :: C a => a -> [a] -> a
- fromFactoredFraction :: (C a, C a) => [a] -> a -> T a
- fromFactoredFractionAlt :: (C a, C a) => [a] -> a -> T a
- multiFromFraction :: C a => [a] -> a -> (a, [a])
- fromValue :: a -> T a
- reduceHeads :: C a => T a -> T a
- carryRipple :: C a => a -> [a] -> (a, [a])
- normalizeModulo :: C a => T a -> T a
- removeZeros :: (C a, C a) => T a -> T a
- zipWith :: C a => (a -> a -> a) -> ([a] -> [a] -> [a]) -> T a -> T a -> T a
- mulFrac :: C a => T a -> T a -> (a, a)
- mulFrac' :: C a => T a -> T a -> (T a, T a)
- mulFracStupid :: C a => T a -> T a -> ((T a, T a), T a)
- mulFracOverlap :: C a => T a -> T a -> ((T a, T a), T a)
- scaleFrac :: (C a, C a) => T a -> T a -> T a
- scaleInt :: (C a, C a) => a -> T a -> T a
- mul :: (C a, C a) => T a -> T a -> T a
- mulFast :: (C a, C a) => T a -> T a -> T a
- indexMapMapWithKey :: (a -> b -> c) -> Map (ToOrd a) b -> Map (ToOrd a) c
- indexMapToList :: Map (ToOrd a) b -> [(a, b)]
- indexMapFromList :: C a => [(a, b)] -> Map (ToOrd a) b
- mapApplySplit :: Ord a => a -> (c -> c -> c) -> (b -> c) -> (Map a b -> Map a c) -> Map a b -> Map a c
Cons z (indexMapFromList [(x0,[y00,y01]), (x1,[y10]), (x2,[y20,y21,y22])])
represents the partial fraction
z + y00x0 + y01x0^2 + y10x1 + y20x2 + y21x2^2 + y22x2^3
x0, x1, x2, ... must be irreducible,
but we can't check this in general.
It is also not enough to have relatively prime denominators,
because when adding two partial fraction representations
there might concur denominators that have non-trivial common divisors.
fromFactoredFraction x y
computes the partial fraction representation of
y % product x,
where the elements of
x must be irreducible.
The function transforms the factors into their standard form
with respect to unit factors.
There are more direct methods for special cases like polynomials over rational numbers where the denominators are linear factors.
The list of denominators must contain equal elements. Sorry for this hack.
A normalization step which separates the integer part from the leading fraction of each sub-list.
A normalization step which reduces all elements in sub-lists
modulo their denominators.
Zeros might be the result, that must be remove with
Transforms a product of two partial fractions
into a sum of two fractions.
The denominators must be at least relatively prime.
T requires irreducible denominators,
these are also relatively prime.
mulFrac (1%6) (1%4) fails because of the common divisor
Works always but simply puts the product into the last fraction.
Also works if the operands share a non-trivial divisor. However the results are quite arbitrary.
Expects an irreducible denominator as associate in standard form.