​How to find square numbers?

17 views
Skip to first unread message

Skip Cave

unread,
Aug 11, 2025, 7:15:43 PMAug 11
to forum
Question: is 21 ^ 21 a square number?

Test: Take the square root of 21^21 and test to see if the result is a integer (=>.) (is the floor of the result the same as the result)

21x^21

5842587018385982521381124421


Take the square root of 21^21, store in n, and list it:

]n=.%:21x^21

7.64368e13


Is n an integer?

(=>.) n

1

Integer test says so.


Square n to get back to 21x^21:

x: n^2

5842587018385982340114415616


However,

21x^21 is

5842587018385982521381124421


Compare the two numbers:

5842587018385982340114415616

5842587018385982521381124421


Not the same.


21x^21 is not a square, even though the integer test (=>.) says so.


What went wrong? How can one test for large square numbers?


Skip


Skip Cave
Cave Consulting LLC

Elijah Stone

unread,
Aug 11, 2025, 7:54:23 PMAug 11
to 'Skip Cave' via forum
first problem:

(=>.)n
1
(=!.0>.)n
0

second problem: all floating-point numbers above 2^52 are whole numbers, so
for any number above (2^52)^2, the test (even amended for comparison
tolerance) will always claim it to be square. (for numbers below that, i
_believe_ the test is correct, assuming %: is correctly rounded on exact
numbers, which i'm not sure of.)

the correct way to do it is to avoid introducing inexact results in the first
place; <.@%: will do this (<.%:y will not!). hence i would do something like:

(= *:@(<.@%:)) 21x^21
0

also, x:n^2 is not right in general (not necessarily wrong, but if you find
yourself writing that it is _probably_ wrong); (x:n)^2 is much likelier to do
what you want most of the time
> To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
>
>

Henry Rich

unread,
Aug 11, 2025, 8:14:37 PMAug 11
to forum
x: and *: do not commute. 

Henry Rich
Reply all
Reply to author
Forward
0 new messages