jacobi ( a m -- n )


Vocabulary
math.extras

Definition
USING: kernel math math.extras.private sequences ;

IN: math.extras

: jacobi ( a m -- n )
check-jacobi [ mod' ] keep 1
[ pick zero? ] [
[ pick even? ] [
[ 2 / ] 2dip over 8 mod' { 3 5 } member?
[ neg ] when
] while swapd 2over [ 4 mod' 3 = ] both? [ neg ] when
[ [ mod' ] keep ] dip
] until [ nip 1 = ] dip 0 ? ;