NB. Definitions for Software Engineering Chapter NB. Rational Arithmetic Operations plus_rat =: dyad def '(((num x.) * den y.) + (num y.) * den x.) make_rat (den x.) * den y.' minus_rat =: dyad def '(((num x.) * den y.) - (num y.) * den x.) make_rat (den x.) * den y.' times_rat =: dyad def '((num x.) * num y.) make_rat (den x.) * den y.' divide_rat =: dyad def '((num x.) * den y.) make_rat (den x.) * num y.' equal_rat =: dyad def '((num x.) * den y.) = (num y.) * den x.' print_rat =: monad define if. 1 = denum =. den y. do. format num y. else. (format num y.) , '%' , format denum end. ) NB. Constructor (Do not remove common factors) make_rat =: append NB. Accessors num =: 0 bond from den =: 1 bond from NB. Constructor (Remove common factors at construction time) make_rat =: dyad def '(x. % g) append y. % g =. x. gcd y.' NB. Accessors num =: 0 bond from den =: 1 bond from NB. Constructor (Remove common factors at access time) make_rat =: append NB. Accessors num =: monad def 'num % (num =. 0 from y.) gcd 1 from y.' den =: monad def 'den % (0 from y.) gcd den =. 1 from y.'