Created
September 15, 2010 10:50
-
-
Save metaxy/580553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{--polylist a@([q,p]:xs) = pl' a p [] | |
where | |
p' ([q,p]:xs) e l | |
pl' [] _ l = l | |
| p == e = pl' xs (e-1) (l++[q]) | |
| otherwise = pl' ([q,e]:xs) (e-1) (l++[0])--} | |
type Polynom = [(Int,Int)] | |
polyplus :: Polynom -> Polynom -> Polynom | |
--polyplus [] p = p | |
---polypuls p [] = p | |
polyplus p@((g1,e1):p1) q@((g2,e2):p2) | |
| g1>g2 = (g1,e1):(polyplus p1 q) | |
| g2>g1 = (g2,e2):(polyplus p p2) | |
| g1==g2 && e1+e2/=0 = (g1, e1+e2):(polyplus p1 p2) | |
| otherwise = polyplus p1 p2 | |
polymul [] p = [] | |
polymul p [] = [] | |
polymul ((g,e):p) q = polyplus (m (g,e) q) (polymul p q) | |
where | |
m (g,e) [] = [] | |
m (g,e) ((gq,eq):q) = (g+gq, e*eq):(m (g,e) q) | |
polydiv [(e,q):p] [(u,m):a] = pd' [(e,q):p] [(u,m):a] ([],[]) | |
where | |
pd' [(e,q):p] [(u,m):a] (s,t) | |
| u<=e = pd' ( polyplus [(e,q):p] (polymul[(e-4,-1*(q/m))] )) ((u-m):a) ((u,m):a) ((e-u, q/m):s,t) | |
| otherwise = (s, (e,q):p ++ t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment