USING: combinatorskernellocalsmathmath.functions;:: (simplest)( ndn'd'--val)! assumes0<n/d<n'/d'
n d /mod :> ( qr)
n' d' /mod :> ( q'r'){{[ r zero? ][ q ]}{[ q q' = not ][ q 1 + ]}[
d' r' d r (simplest) >fraction :> ( n''d'')
q n'' * d'' + n'' /
]} cond ;:: simplest( xy--val){{[ x y > ][ y x simplest ]}{[ x y = ][ x ]}{[ x 0 > ][ x y [ >fraction ] bi@ (simplest) ]}{[ y 0 < ][ y x [ neg >fraction ] bi@ (simplest) neg ]}[0]} cond ;: approximate( xepsilon--y)[ - ][ + ] 2bi simplest ;