We can find perfect squares in a list by taking the square root (%:) of a
number, and checking to see if it is an integer:

* n#~(=>.)%:n=.>:i.30*

*1 4 9 16 25*


Now we can try larger integers by taking the square root of the factorial
of some small integers:

* n#~(=>.)%:!n=.>:i.30*

*1 26 27 28 29 30*


Hmm. This says that !26 and up, are perfect squares.

* !26x*

*403291461126605635584000000*

* %:!26x*

*20082117944246*


Well it looks like %:!26x is an integer, making !26x a perfect square.
Let's check:

* 20082117944246x^2*

*403291461126607189164508516*

* !26x*

*403291461126605635584000000*


 *  (!26x)-:20082117944246x^2 *
*0*
Clearly, !26x is not a perfect square.

Looks like J has precision issues with the square root of large extended
integers. How can I fix this, to find accurate square roots of large
integers?

Skip Cave
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to