diff --git a/lab5.5/diophantine.fs b/lab5.5/diophantine.fs index fc0b380..adf4bdb 100644 --- a/lab5.5/diophantine.fs +++ b/lab5.5/diophantine.fs @@ -34,29 +34,29 @@ \ otherwise 0 0 0 : diophantine ( c b a -- y x result ) {: | _d _c _b _a :} - over over ( c b a -- c b a b a ) - check-2-top-0 if ( c b a b a -- c b a ) - drop drop drop ( c b a -- ) - 0 0 0 - else ( c b a b a -- c b a ) - rot to _c ( c b a -- b a ) - over over to _a to _b ( b a -- b a ) - extended-gcd ( b a -- y x d ) \ b a extended-gcd - dup to _d ( y x d -- y x d ) - _c swap mod ( y x d -- y x c%d ) - 0 = invert if ( y x c%d -- y x ) - drop drop ( y x -- ) - 0 0 0 - else ( y x c%d -- y x ) - _c _d / ( y x -- y x [c/d] = e ) - dup rot ( y x e -- y e e x ) - * ( y e e x -- y e [e*x] = f ) - rot rot ( y e f -- f y e ) - * ( f y e -- f [y*e] = g ) + over over ( c b a -- c b a b a ) + check-2-top-0 if ( c b a b a -- c b a ) + drop drop drop ( c b a -- ) + 0 0 0 ( -- 0 0 0 ) + else ( c b a b a -- c b a ) + rot to _c ( c b a -- b a ) + over over to _a to _b ( b a -- b a ) + extended-gcd ( b a -- y x d ) \ b a extended-gcd + dup to _d ( y x d -- y x d ) + _c swap mod ( y x d -- y x c%d ) + 0 = invert if ( y x c%d -- y x ) + drop drop ( y x -- ) + 0 0 0 ( -- 0 0 0 ) + else ( y x c%d -- y x ) + _c _d / ( y x -- y x [c/d] = e ) + dup rot ( y x e -- y e e x ) + * ( y e e x -- y e [e*x] = f ) + rot rot ( y e f -- f y e ) + * ( f y e -- f [y*e] = g ) _b 0 < if -1 * then ( x0 y0 -- x0 -y0 ) - swap ( x0 y0 -- y0 x0 ) + swap ( x0 y0 -- y0 x0 ) _a 0 < if -1 * then ( y0 x0 -- y0 -x0 ) - -1 ( y0 x0 -- y0 x0 -1 ) \ x = x0; y = y0; result = -1 - true + -1 ( y0 x0 -- y0 x0 -1 ) \ x = x0; y = y0; result = -1 - true then then ;