Created
May 8, 2015 03:13
-
-
Save ekmett/f42ba680952a9e93955a to your computer and use it in GitHub Desktop.
basic operations on continued fractions
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
bihom a b _ _ e f _ _ xs [] = hom a b e f xs | |
bihom a _ c _ e _ g _ [] ys = hom a c e g ys | |
bihom a b c d e f g h xs@(x:xs') ys@(y:ys') | |
| e /= 0, f /= 0, g /= 0, h /= 0 | |
, q <- quot a e, q == quot b f | |
, q == quot c g, q == quot d h | |
= q : go e f g h (a-q*e) (b-q*f) (c-q*g) (d-q*h) xs ys | |
| e /= 0 || f /= 0 | |
, (e == 0 && g == 0) || abs (g*e*b - g*a*f) > abs (f*e*c - g*a*f) | |
= go (a*x+b) a (c*x+d) c (e*x+f) e (g*x+h) g xs' ys | |
| otherwise | |
= go (a*y+c) (b*y+d) a b (e*y+g) (f*y+h) e f xs ys' | |
(+) = bihom 0 1 1 0 0 0 0 1 | |
(-) = bihom 0 1 (-1) 0 0 0 0 1 | |
(*) = bihom 1 0 0 0 0 0 0 1 | |
(/) = bihom 0 1 0 0 0 0 1 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment