I am working on an algorithm. But I am not very clear on the haskell code provide by the author, so I need you guys' help. The codes can split into two parts, I think.
> type LFT = (Integer, Integer, Integer, Integer)
>
> extr :: LFT -> Integer -> Rational
> extr (q,r,s,t) x = ((fromInteger q) * x + (fromInteger r)) / ((fromInteger s) * x + (fromInteger t))
>
> unit :: LFT
> unit = (1,0,0,1)
>
> comp :: LFT -> LFT -> LFT
> comp (q,r,s,t) (u,v,w,x) = (q*u+r*w,q*v+r*x,s*u+t*w,s*v+t*x)
Here, very clearly, a type called LFT (may be a tuple in Python) and three function called extr unit comp
be defined.However, the next part puzzled me a lot:
> pi = stream next safe prod cons init lfts where
> init = unit
> lfts = [(k, 4*k+2, 0, 2*k+1) | k<-[1..]]
> next z = floor (extr z 3)
> safe z n = (n == floor (extr z 4))
> prod z n = comp (10, -10*n, 0, 1) z
> cons z zā = comp z zā
I believe lfts
is a generator but I am failed to understand how the loop performed in this code and I do not know much about the Haskell. Can you help me convert this one to Python or a pseudocode?