tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,22 @@
|
|||
import Data.List
|
||||
|
||||
shift n l = l ++ replicate n 0
|
||||
|
||||
pad n l = replicate n 0 ++ l
|
||||
|
||||
norm :: Fractional a => [a] -> [a]
|
||||
norm = dropWhile (== 0)
|
||||
|
||||
deg l = length (norm l) - 1
|
||||
|
||||
zipWith' op p q = zipWith op (pad (-d) p) (pad d q)
|
||||
where d = (length p) - (length q)
|
||||
|
||||
polydiv f g = aux (norm f) (norm g) []
|
||||
where aux f s q | ddif < 0 = (q, f)
|
||||
| otherwise = aux f' s q'
|
||||
where ddif = (deg f) - (deg s)
|
||||
k = (head f) / (head s)
|
||||
ks = map (* k) $ shift ddif s
|
||||
q' = zipWith' (+) q $ shift ddif [k]
|
||||
f' = norm $ tail $ zipWith' (-) f ks
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
str_poly l = intercalate " + " $ terms l
|
||||
where term v 0 = show v
|
||||
term 1 1 = "x"
|
||||
term v 1 = (show v) ++ "x"
|
||||
term 1 p = "x^" ++ (show p)
|
||||
term v p = (show v) ++ "x^" ++ (show p)
|
||||
|
||||
terms :: Fractional a => [a] -> [String]
|
||||
terms [] = []
|
||||
terms (0:t) = terms t
|
||||
terms (h:t) = (term h (length t)) : (terms t)
|
||||
Loading…
Add table
Add a link
Reference in a new issue