I find that the rational fractions capability in J comes in handy for
various applications. However, It occasionally comes in handy to be able to
convert a rational fraction into an integer and a remainder fraction. I put
together a function 'qr' (quotient/remainder) to input pure rational
fractions and output integer - fraction representations.
Here's the function:
qr=. 3 : '(<.%/a),(1{a)%~|~/a=.2&x:y'
Trying it out:
qr 13r5
2 3r5
qr 136r44
3 1r11
qr 38r13
2 12r13
My qr function is pretty kludgy. Is there a shorter, more tacit version I
could use? Also can it be made to operate on a vector of rational
fractions, to give a 2xn matrix of integer/fraction results?
qr 13r5 136r44 38r13
2 3r5
3 1r11
2 12r13
Skip
Skip Cave
Cave Consulting LLC
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm