[Question]
  [
# Challenge
So, um, it seems that, while we have plenty of challenges that work with square numbers or numbers of other shapes, we don't have one that simply asks:
Given an integer `n` (where `n>=0`) as input return a truthy value if `n` is a perfect square or a falsey value if not.
---
## Rules
* You may take input by any reasonable, convenient means as long as it's permitted by [standard I/O rules](https://codegolf.meta.stackexchange.com/q/2447/58974).
* You need not handle inputs greater than what your chosen language can natively handle nor which would lead to floating point inaccuracies.
* Output should be one of two consistent truthy/falsey values (e.g., `true` or `false`, `1` or `0`) - truthy if the input is a perfect square, falsey if it's not.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so lowest byte count wins.
---
## Test Cases
```
Input:  0
Output: true
Input:  1
Output: true
Input:  64
Output: true
Input:  88
Output: false
Input:  2147483647
Output: false
```
  
[Answer]
# [Neim](https://github.com/okx-code/Neim), 2 bytes
```
qùïö
```
Explanation:
```
q      Push an infinite list of squares
 ùïö     Is the input in that list?
```
When I say 'infinite' I mean up until we hit the maximum value of longs (2^63-1). However, Neim is (slowly) transitioning to theoretically infinitely large BigIntegers.
[Try it!](http://178.62.56.56:80/neim?code=q%F0%9D%95%9A&input=64)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
√Ü¬≤
```
[Try it online!](https://tio.run/##y0rNyan8//9w26FN////NzMBAA "Jelly ‚Äì Try It Online")
[Answer]
# dc, 9
```
0?dvd*-^p
```
Outputs 1 for truthy and 0 for falsey.
[Try it online](https://tio.run/##RYtBCsIwEADvfcVQlIIQaDW0AUF/ItTslvaSlCb05N@jCOIcZ5jnmOYyxY2sKfsxKUugpaO3OMe5s4N1l94OVyRWfFi3JeSJ@pgwN2oOv/Nb1c/xr3ghHqM0pb3LLifzWEtTSQxa3g).
```
0            # Push zero.  Stack: [ 0 ]
 ?           # Push input.  Stack: [ n, 0 ]
  dv         # duplicate and take integer square root.  Stack: [ ‚åä‚àön‚åã, n, 0 ]
    d        # duplicate.  Stack: [ ‚åä‚àön‚åã, ‚åä‚àön‚åã, n, 0 ]
     *       # multiply.  Stack: [ ‚åä‚àön‚åã¬≤, n, 0 ]
      -      # take difference. Stack: [ n-‚åä‚àön‚åã¬≤, 0 ]
       ^     # 0 to power of the result.  Stack: [ 0^(n-‚åä‚àön‚åã¬≤) ]
        p    # print.
```
Note `dc`'s `^` exponentiation command gives 00=1 and 0n=0, where n>0.
[Answer]
# TI-Basic, 4 bytes
```
not(fPart(‚àö(Ans
```
Simply checks if the square root is an integer by looking for a nonzero fractional/decimal part.
[Answer]
# C#, 27 bytes
```
n=>System.Math.Sqrt(n)%1==0
```
---
A more [correct/accurate way](https://stackoverflow.com/questions/2751593/how-to-determine-if-a-decimal-double-is-an-integer) to do this would be:
```
n=>System.Math.Sqrt(n)%1<=double.Epsilon*100
```
[Answer]
# JavaScript (ES6), 13 bytes
```
n=>!(n**.5%1)
```
Returns true if the square root of n is a whole number.
**Snippet:**
```
f=
n=>!(n**.5%1)
console.log(f(0));
console.log(f(1));
console.log(f(2));
console.log(f(4));
console.log(f(8));
console.log(f(16));
console.log(f(88));
console.log(f(2147483647));
```
[Answer]
# [Perl 5](https://www.perl.org/), 14 bytes
13 bytes of code + `-p` flag.
```
$_=sqrt!~/\./
```
[Try it online!](https://tio.run/##K0gtyjH9r6xYAKQVdAv@q8TbFhcWlSjW6cfo6f@3VlCJV9CzVVCKyVP6b8hlZsJlYQEA "Perl 5 ‚Äì Try It Online")
Computes the square root, and looks if it's an integer (more precisely, if it doesn't contain a dot (`/\./`).
[Answer]
# [Python 3](https://docs.python.org/3/), 19 bytes
```
lambda n:n**.5%1==0
```
[Try it online!](https://tio.run/##Pcs9C4MwFIXhuf6KW0FIRETpByI4dOncoZt1iHqDoTFKbqT461MpbbfDy3nm1Q2TOXhZPbwWY9sLMKWJ4/QU5VWV@UBOFhQoA4zlyd0uyBN2Pv5WUSRXoQk5L4OdkiCZqrOGw74CVefNFnezVcax8GanVuMIPTrsHPbwUm4Ah@Q6QQgRhdGHbqK1KJ7B1120/r8IZkG0WVq6DonkovWahty/AQ "Python 3 ‚Äì Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina), 18 bytes
```
.+
$*
(^1?|11\1)+$
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX0@bS0WLSyPO0L7G0DDGUFNb5f9/Ay5DLjMTLgsLAA "Retina ‚Äì Try It Online") Shamelessly adapted from @MartinEnder's answer to [Is this number triangular?](https://codegolf.stackexchange.com/questions/122087) but with the base conversion included at a cost of 6 bytes.
Note that Is this number triangular? wasn't for some inexplicable reason required to support zero as a triangular number, so part of the adaption was to add a `?` to make the leading 1 optional, allowing the group to match the empty string, and therefore a zero input. However, having now matched the empty string, the `+` operator stops repeating, to avoid the infinite loop that would happen if it kept greedily matching the empty string (after all, `^1?` would certainly keep matching). This means that it doesn't even try to match the other alternative in the group, thus avoiding the match of 2, 6, 12 etc. As @MartinEnder points out, a simpler way to avoid that while still matching the empty string is to anchor the match at the start while making the group optional for the same byte count: `^(^1|11\1)*$`.
[Answer]
# C (gcc), 30 bytes
```
f(n){n=sqrt(n)==(int)sqrt(n);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOs@2uLCoBMiytdXIzCvRhPKsa/8DeQq5iZl5Gppc1VwKQFBQBBRK01BSTYnJw8RKOgppGgaaINIQTJqZQDhm5ubmRoZmYI6FBZgyMjQxN7EwNjMx19S05qr9/y85LScxvfi/bk4uAA)
# C, 34 bytes
```
f(n){return(int)sqrt(n)==sqrt(n);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zuii1pLQoTyMzr0SzuLCoBChkawtlWNf@Bwor5CZm5mloclVzKQBBQRFQKE1DSTUlJg8TK@kopGkYaIJIQzBpZgLhmJmbmxsZmoE5FhZgysjQxNzEwtjMxFxT05qr9v@/5LScxPTi/7o5uQA)
# C, 33 bytes
```
#define f(n)(int)sqrt(n)==sqrt(n)
```
[Try it online!](https://tio.run/##S9ZNT07@/185JTUtMy9VIU0jT1MjM69Es7iwqATItrWFMv4DBRVyEzPzNDS5qrkUgKCgCCiUpqGkmhKTh4mVdIBmGWiCSEMwaWYC4ZiZm5sbGZqBORYWYMrI0MTcxMLYzMRcU9Oaq/b/v@S0nMT04v@6ObkA)
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~5~~ 4 bytes
Thanks to Luis for reducing my one byte longer code by two bytes, making it the shortest one.
```
t:Um
```
[Try it online](https://tio.run/##y00syfn/v8QqNPf/f0MTEwA)
**Explanation:**
```
         % Implicit input
t        % Duplicate it
 :       % Range from 1 to input value
  U      % Square the range, to get 1 4 9 ... 
   m     % ismember, Checks if the input is a member of the range of perfect squares
```
---
Old answer:
```
X^1\~
```
[Try it online!](https://tio.run/##y00syfn/PyLOMKbu/38zEwA "MATL ‚Äì Try It Online")
```
        % Implicit input
X^      % Square root of input
  1\    % Modulus 1. All perfect squares will have 0, the rest will have decimal value
     ~  % Negate, so the 0 becomes 1, and the decimal values become 0
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~40~~ 38 bytes
*Thanks to squid for saving 2 bytes!*
```
lambda n:n in(i*i for i in range(n+1))
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPKk8hM08jUytTIS2/SCETyFEoSsxLT9XI0zbU1PxfUJSZV6KRmJOjkaaRrQlWkw1SE22gY6hjZhKrqckFUZKXX6KQmFeJrsxIx8ICqOg/AA "Python 3 ‚Äì Try It Online")
Too slow to return an answer for `2147483647` in a reasonable amount of time. (But written using a generator to save memory, since it doesn't cost any bytes.)
Works in Python 2 also, though an `OverflowError` is a possibility due to `range` if you try it with huge inputs. (A `MemoryError` would also be likely in Python 2, also due to `range`.)
[Answer]
# Regex (ECMAScript / Python or better), 50 bytes
```
^((?=(xx+?)\2+$)((?=\2+$)(?=(x+)(\4+$))\5){2})*x?$
```
[Try it online!](https://tio.run/##TY9BT8JAFIT/CjYE3qO2FEQPrEtPHrhw0KNosoFH@3TZbnYXqCC/vbYxJt5m5ptkMh/qqPzGsQ2Jt7wlt6/MJ301Tho69Z6peKotwFkuxqPmHSCXUNdxjutp3MfO/ooujhHWs9bg@h4v0yuO6rzfjMZnTEP1EhybAjD1mjcED7fJDFF4mYlTyZoAtHSktpoNAeKNNAet8VJInXqrOcAwGaLgHYCRRarJFKHExfT7m/1KrYClVc7T0gQoXrM3xD9A/4FZTPLJvMMYSledoqU5Ks3bnlOmoHkvirXYVQ4EP0oSHMfYDkZ1lDqypAIwpnsVNiU4xIsfDGx7KUD3YiLsIfjg2oq4XpssuZtl2Q8 "JavaScript (SpiderMonkey) ‚Äì Try It Online")
This regex is explained in [Match strings whose length is a fourth power](https://codegolf.stackexchange.com/questions/19262/match-strings-whose-length-is-a-fourth-power/21951#21951). teukon and I arrived at it independently, starting on 2014-02-22, though golfing it down to this point took him 2 days and took me 4 days. It works by dividing away squared prime factors one at a time, thus keeping the number's property of being a square at every step iff it started out being a square. This regex represents a local minimum in length; it's the shortest form that this particular algorithm can be golfed into. It can be modified to match Nth powers by changing the `2` in `{2}` to N.
# Regex (ECMAScript), 28 bytes
```
^(x(x*)|)(?=(\1*)\2+$)\1*$\3
```
[Try it online!](https://tio.run/##TY@xbsIwFEV/JY0QeS9pQkIrBlzD1IGFoR2BShY8EreOY9kGUqBrP6Cf2B9JYUDqdqUz3HPexV64tZXGp87IDdm60R/02Vmu6RC8UPncGoAjnwzi7g1aaGM8I0w5LIsYl8Okh5fRWz508eCImW9evZW6BMyckmuC0X36iMgcz9mhkooAFLckNkpqAsQ7rndK4ankKnNGSQ9RGiGTWwDNy0yRLn2Fk@H5LN1czEFyI6yjmfZQLvIV4g3Qf6AnxbQYXzH6yjaHcKb3QslNYIUuaRyEiWLbxgKTT5yYTBK8HNY8bMPMkiHhQWJWC7@uwCKeXL9vLlEerh0FMzvvvAWZRMHv908QJfWiWN1U2ddXl6fFKM//AA "JavaScript (SpiderMonkey) ‚Äì Try It Online")
```
^              # tail = C = input number
(x(x*)|)       # \1 = A = conjectured square root of C; \2 = A-1, or unset if A==0,
               # allowing us to match C==0 using ECMAScript NPCG behavior; tail -= A
(?=
    (\1*)\2+$  # iff A*A==C, the first match here must result in \3==0
)
\1*$\3         # assert A divides tail, and \3==0
```
This ultimate form of this was arrived upon from 2014-03-02 to 2014-03-04 through several rounds of golfing between teukon and me, after we had already independently come up with the coprime moduli method of generalized multiplication (which took him 3 hours and took me almost 2 days). I came up with the idea to do one of the tests as `(\1*)\2+$` followed by testing if `\3`==0 although it didn't improve my regex's overall length at the time, and he came up with the idea to combine the `\3`==0 test and `\1*$` test into one, as `\1*$\3`, thus doing the `\1*$` test at the end instead of the beginning (which sacrifices speed in the name of golf, assuming the regex engine doesn't optimize it). (That is with the group numbering of the fully golfed form mapped onto the snippets.)
I've explained the generalized multiplication algorithm [in this post](https://codegolf.stackexchange.com/questions/179239/find-a-rocco-number/179420#179420), but since its application to squares is simpler, I'm including an explanation for that here.
To explain why this works, let's rearrange the order of the assertions:
```
(?=
    \1*$       # assert that A divides C-A
)
(?=
    (\1*)\2+$  # iff A*A==C, the first match here must result in \3==0
)
.*$\3          # assert that \3==0
```
We have \$A^2 \stackrel{?}{=} C\$. If this assertion were true, we would have:
\$\begin{aligned}C &= A^2 \\
C-A &= A^2-A \\
&= (A-1)A\end{aligned}\$
This shows that the assertions made by the regex will hold true if \$C=A^2\$:
\$\begin{aligned}C-A &\equiv 0 \pmod A \\
C-A &\equiv 0 \pmod {A-1}\end{aligned}\$
Note that in regex, \$0 \equiv 0 \pmod 0\$, so the algorithm works for \$C=1^2\$ and \$A=1\$ without any need for a special case. It also works for \$C=0\$, matching it using ECMAScript NPCG (unset/non-participating capture group) behavior ‚Äì every assertion becomes \$0 \equiv 0 \pmod 0\$ and passes.
Assuming \$A>1\$, these can be simplified into:
\$\begin{aligned}C &\equiv 0 \pmod A \\
C &\equiv 1 \pmod {A-1}\end{aligned}\$
We now have two coprime moduli, \$A\$ and \$A-1\$. By the [Chinese remainder theorem](https://en.wikipedia.org/wiki/Chinese_remainder_theorem), there is one and only one integer \$E\$ such that \$0 \le E < A(A-1)\$ and the above moduli are satisfied. That applies to any window of the same length, so we can change it to \$A < E \le A^2\$.
\$A^2-A=(A-1)A\$ shows there is at least one \$E\$ satisfying the moduli: \$E=A^2\$. The Chinese remainder theorem shows that there is exactly one \$E\$ satisfying the moduli within a certain range. Thus, if we restrict our search to the range \$A < E \le A^2\$, the only value matching both moduli will be \$E=A^2\$.
The first thing the regex does is `(x(x*)|)` which subtracts \$A\$ from \$C\$, so instead of directly searching for a matching \$E\$, it is searching for a matching \$E-A\$.
`(\1*)\2+$` will first attempt a match using the largest possible number of repetitions of `\1`. Since we already asserted `\1*$`, this will bring us exactly to `$`. But then there will be no room for `\2+`, which is required to have a positive repetition count due to the `+`. So then it starts trying smaller repetition counts for `\1`, giving `\2+` more space in incremental steps of `\1`, thus resulting in incrementally larger repetition counts for `\2`. Note that `\1`\$=A\$ and `\2`\$=A-1\$. So a successful match of `\2+$` represents a value of \$E-A\$ such that \$E-A \equiv 0 \pmod A\$ and \$E-A \equiv 0 \pmod {A-1}\$.
The regex essentially searches for the smallest \$A-1 \le E-A \le C-A\$ satisfying the moduli, or alternatively stated, the smallest \$2A-1 \le E \le C\$ satisfying the moduli. Thus, even if \$C > A^2\$, the first matching \$E\$ it finds will be \$E=A^2\$. Note that the range only had to be restricted to \$A < E\$ via the Chinese remainder theorem, and the regex restricts it to \$2A-1 \le E\$ which is a subset of that range.
If no match is found, then \$C < A^2\$ and we get a non-match. If a match is found, and if \$E-A=C-A\$, then the `\1` in `(\1*)` will have a repetition count of zero, and `\3` will capture a value of zero. The regex asserts that \$E=C\$ by asserting that `\3` has a value of zero; if this matches, then \$C=A^2\$ and is indeed a perfect square.
Note that in no point in this reasoning did it matter what the value of \$A\$ is. It will only match if \$A^2=C\$. Thus, it doesn't matter whether we search for a matching \$A\$ from smallest to largest or largest to smallest. The regex does the latter, starting at \$A=C\$ and going downward from there in decrements of \$1\$.
# Regex (ECMAScript / Python or better), 30 bytes
```
^(x(x*))(?=(\1*)\2+$)\1*$\3|^$
```
[Try it online!](https://tio.run/##TY@9bsIwFEZfhUYI7k2akFDUAdcwdWBhaMdSJAsuyW2NY9kGUn6ePQ1DpW6fdD7p6Hypo/Ibxzak3vKW3L423/TTOmno1Huj8rWxAGc5G8XtGhpoYkSYS1gVMa7GSR@70V89Xdf9Nh6dMQv1e3BsSsDMa94QPD@mE0ThZS5OFWsC0NKR2mo2BIgP0hy0xkspdeat5gDDdIiCdwBGlpkmU4YKZ@Prlf1SLYGlVc7TwgQoP/JPxD9A/4GZFfNiescYKlefooU5Ks3bnlOmpGkvSrTY1Q4Ev0gSnCTYCaMmyhxZUgEYs70Kmwoc4sUPBrZLCnCvKIQ9BB9cdxG3W5unRT6e/AI "JavaScript (SpiderMonkey) ‚Äì Try It Online") - ECMAScript (SpiderMonkey)  
[Try it online!](https://tio.run/##TY69bsIwFIVfBUVIvpcQK6GdkhqmDiwM7dgUYSWXcCvXSW0DkYBnT0OlSmxH@s7flz5pXznuQmLbmgav0sKpN2pe@w7eg2PbSKfPu2ELPfQzRFgpKLMZlot4iqOYlk/X7XTYSW@4IsjmSYZYOPo5siMQjnRt2JJAWY060NoGcns9Wi9su2PIO9dW5L30oWZ7Q9laEH@JuVHLS6OM9J3hACIRWPAewKpGGrJNOOBycb2y3@gNsOq08/d2aD7ST8R/QI/ALrNVlt8xhoNrz9HanrTheuK0bSifRLEp9q2Dgl8UFRzHOA5GfSQddeN5YJTfOlQHcIiXh@PtMciz40AAfiVKK3IhMGYsvMqK2w2HNMnSxfMv "JavaScript (Node.js) ‚Äì Try It Online") - ECMAScript (Node.js - fast)  
[Try it online!](https://tio.run/##RU5BasMwEPzKEpZYG9vYcttLZCUOpNeeeqsTkYYYBGriSi64qO7XXcUN5LLMzM7uTHuy5mn8@Aa0Ary5HA8GMBOBynK7ed2sBmgulqGTuShXgjzoJjDyrdXnDmb1eSYGqIx0rdEdi9IocV/vrgsnKkl5wun0eTWt72oedFqiInH95ULiwVamLMhX5o3vZJj5Ttxy9Y2iLuW0DiiOyesGGIv6CHoIJiKQv5Chzcijm8@nclO3UJyL/66oxTAMSj2/bJUa96xn/YKIrSWr@YLqIkYKAOuHnz2OY57yvHj8Aw "Perl 5 ‚Äì Try It Online") - Perl  
[Try it online!](https://tio.run/##bVJdb9swDHzvr@CMDpGSVE26PU01im3YgAHrNrSPSQootpyolWlPkhsnXX97RjneR4H4hSJ5PupOvFeP6uw@f9ibsq5cgHvKhanEUML/lSYYe7Tm9Eq31Dmpm6U1GWRWeQ/XyiA8QV/zQQUKj5XJoaQOuw3O4AqUW/nZgkNYu2rj4VOb6TqYiv48AfhsrIYiRb3pjiwRWZVrQf2Eyw9NUWin8xutcu1g2cFeFtmfP/u04Fz2c/04yM068jPm0yVpUPlXg5px/irFxlpuCuaF/tko61lyPhwOE86fXkIPDIyFowRPxBD@MhDBOTEsCfcg/SgdzHEQY5DPh9rzDxWCdggu7U@ktqzjAM8lubGsKqsVwi4tiFFLuM0UIkk3WDcBUohq@xq73fqgS2GQS@h1djCxVv6bbgNds7MYoDfE0t2J4wBCQvQS@/5sAZbaESV8bU1gyRk9AuED4IQ6XzDQGjhRK@c1JczOJgs@BpwebQqrcRXWlxdwBREJ7yhMF8SYrZWbLdpeT5fhdCHhvXNq60VhrGXteNAOOlMAispFbXSNFCcS8DLFKYXRiAReq5CtyaGS2JwoDxnrNhdpwT8S@WFjxMapmvUjsqrefi9uFK40TZqMkfOotABW0njMybv4tjvem1yRYxtngmbxUbncpcE18X3@tWvyMBQsee0TsoTL5/idxK3a37GWtUPO2VXK5tMhn1@MTjkdTudvft2d7uPe7Cdn08nF298 "Java (JDK) ‚Äì Try It Online") - Java  
[Try it online!](https://tio.run/##dVPbjtowEH3nK6YULTZJdglUfUjIrlSpP1D1oRWwUdaYxCo4luOIS7u/Xjp2ljSl4IfEnsuZOWdsplSQM3Z6LyTb1CsOs5eyrMyD5jnf3xdKPfYuXXzPuDKilA8rkeUSTYKlQq5Lvc2sucliRaYhVfMlJPCl/2m3@/Eyrb8fDt@@Fh93BTk9kz3ZjyglTwlZhCO6mHgDipvBYvrreXCilxl9H0YqSZUXxp2OBFbXPNs@9oQ0sM2EJBR@9gCXmqNrwyVRNAiXyTiGGmOmk9RAaU82IbebyqyiCGOFzNGoahO7fFbKyoCjHEVODtAcweKzrUK6rIBdkb1loAJALOwxGftw5C14zs1GSE7cgQnpN3VofO7VLpsox6hWZkpBXMA9S7EvQqkPMvRBlRW6G89ayBUZBkMatwAyRK@NeZd0OUWRtManK7jguXgPQgoRFv@L5aY3suUk3zWnuQy9cBnDlm8rbkjlw3A/tI2hIhU6rcRtfiuFSKTVepbIMAbPE13Gdhl9uLA4LdZAusqnFc80Kwjp8KJ3tmoglr4bgY/TofQK1hnvSAGpWypkuJAoHI4pjK@GN3MqawOzGYj/Y157t0/MXQryz@1pXwzcca3pDcLXG7xoxn76EXzWutT9@DoOp7C2SA7GtwC2amxvZIuHli5e3/7fur3@qonDuEG82TVfzU2tJeBleD2Ng3A8@fCbrTdZXp2CjauQupH@AQ "C++ (gcc) ‚Äì Try It Online") - Boost  
[Try it online!](https://tio.run/##NY5BboMwEEX3nGJksZghgDDpCmrlIECkqHUaV@6Axo5KpN6d4lTdfc3772uWR7zNfNzc1zJLhPAIpdjyM8zcgxhRSm1nXHEtiPBkcNQFje0hpz3k4/HnnG97ZdBdpacenGmy6yzgwXGaqkN8d9xl4I2vw@JdRFUpysBdwVtGT69tB37Qk/FDM2WQZE6yXPjDouOICVD5l/REB037XhoQWwd7kbcbSglqVQU/SUKug0WSQs@D0f3/N/M91t/iosUQBZloayrdtC@/ "Python 3 ‚Äì Try It Online") - Python  
[Try it online!](https://tio.run/##PY5RS8MwEMff9ylupbCk2pBUnxaDFFfElwnTt3YLyrIuELKSZqyC@NVrMuce7rj73/93d@74@TU6ELBSrRo6YtUJFuV7SZz62N7@ifP5y/PydVU9lW8VBy0oh9NeGwVGtMr3EwC9A1PnbC1E0tiEh4GpKSF5seag7DY4gkL6zmiPZvkMXxBilG39HuGHIjB14AN2RXYHBxa0hSgSf5AaMYoJicZrG3znXSgZksxiED/geBT0NP7ZHX1/3hf/ZqF32nqw/ydijiFltVxIOW7QgIYMY/QoUMMy3BQ3KQ5F2tx9b9JxpDmjxf0v "Ruby ‚Äì Try It Online") - Ruby  
[Try it online!](https://tio.run/##XVBda8IwFH33V4QQaK622nZuQ2LxZRsIYw/b3qyG2qW2LKYhjSA4f3t3K3vaQy7nfpxzbq6tbb9c2doS5khG6IySKbFOHaRTVhel4sFsOl5JWRfay7I92kYrl/McRP4@64KQBPgqLMqDGgaMV8Z3XMqX9euzlBCSBFAShcWoMY3slOfUlk5N90X57R0GqZtj42lI6DxdzBcPj@ninoIYVa3jrMliwXRWoXrHPz6f1m8g4EKaijO96bzTyiCCKNlmGc0NBRzuTnvsYDmMwyiBga/OVrdfitOIhjgukF@2J@MH7jJF0gYFMMZbMSLk5mz@cmaW2a2PaDIBtCb8dqFj4cuaMxei2XAuVXgenIOQGQAgl2HFBlRZt8NeguBXEkGGnDAjrmhz/XdWDqLf8TM/jwH4KuN5MoY8nTBAwPK7nx3r@zhK4nT@Cw "PHP ‚Äì Try It Online") - PCRE (fastest)  
[Try it online!](https://tio.run/##RY/RaoQwFER/ReSCiW4WtX3aEHahz/0CdUHs3TWQ3kjMoqzNt1ttKX2bMwzDzGAndGOPxqzgVOXwjnNzOhFO7JKsVzazOeWcnRWri5TXZQZ8E1C/fF1hTS6H@M1@DtrgR8wlPFUub9Zh2/UMTKQpAk3Dw/MFWgVGjIPRPhax1DcG7bGzD/LC@KjcA5mCtsqbsBUwIFVp8s2PI4GEwT8uds4yvuwd7vje@q7HkSVzkgLxX/vJl8lpj6K3ow/brEL@cyTIbveMJoyAQghrLoq8fP0G "PowerShell ‚Äì Try It Online") - .NET
This is a port of the 28 byte version, dropping the dependence on ECMAScript NPCG behavior. Matching \$0^2\$ is done as a special case, the `^$` alternative at the end.
# Regex (Perl / Java / PCRE / .NET), 12 bytes
```
^(\1xx|^x)*$
```
[Try it online!](https://tio.run/##RY5fa8IwFMW/ykWCzdWWJoI@mMZVcK972tvU4IaFQNQuqRDJsq/exU7w5XLPuX/Orz1aM@9PNyBWQDCXr4MBUookZbVZv69XEZqLpcRJJqqVwAC6SQpDa/W5g9H2PBIRaiNda3RHsyLL3fXTdelE5QXPOR6/70svT5clH5dEobj/cinxYGtTzTDU5oPvZKpsJx65@iGJruQwTt10ikE3QGnmM/CQlhBB/kJJbImBuPF4gBvYEjgX/6xEixijUq9vG6X6Pd1y73/2Hiek71kxmy8Y@wM "Perl 5 ‚Äì Try It Online") - Perl (fastest)  
[Try it online!](https://tio.run/##bVLLbtswELznK7ZCC5N@MFaPZYSiLVqgQJMWydFxAFqibDrUSiWpWHaab3eXsvoIEF7I3R3Ocoa7VQ9qti3uj6ZqahdgS7EwtRhL@D/TBmNfzDm91h1Vzpp2ZU0OuVXew6UyCI8w5HxQgbaH2hRQUYXdBGdwDcqt/WLJIWxcvfPwuct1E0xNN88AvhirocxQ7/ojS0ReF1pQPeHyY1uW2uniWqtCO1j1sOdJ9ufmEJacy6Gvnwa520R@xny2Ig2q@GZQM85fZdhay03JvNA/W2U9S87H43HC@eNz6ImBsfAiwSMxhL8MRHBODCvC3Us/yUa3OIp7kE@n3NMPFYJ2CC4bTqS2amIDzyW5saprqxXCISuJUUu4yRUiSTfYtAEyiGqHHLvZ@6ArYZBLGHT2MLFR/kp3gZ7ZWwwwGGLp7cRxAiEhBolDfbEES@WIEr6xJrBkRp9A@AA4p8pXDDQGTjTKeU0Bs4v5kk8B0xeLwmpch83FW3gPEQnvaEuXxJhvlFssu0FPH2G6lPDBObX3ojTWsm466ka9KQBl7aI2ekaGcwl4kWFK22RCAi9VyDfkUEVsTlSniPWTizTgn4j8NDFi51TDhhZ53ey/l9cK15o6zafIeVRaAquoPRbkXfzbAx9MrsmxnTNBs/ipXB6y4Nr4P//KDXkYSpa88QlZwuVTXGdxqo537Dbtul93HR@/PsYpOc5n6ZzWbw "Java (JDK) ‚Äì Try It Online") - Java  
[Try it online!](https://tio.run/##XVBda8IwFH33V4QQaKKptqIOicWXbSCMPWx7sxpql9qwmIY0QsHtt3e3sqc95HK/zjk3x9Wu32xd7RDxKEN4htEUOa/O0itnilLRaDYdb6WsCxNk2VycNsrnNGcif5u1EUcRvAqa8qyGBRuUDS2V8nn38iQl4yhlQAnEYqStlq0KFLvSq@mpKL@ChyCNvuiAOcKL@XqxXj3M10vMxKhqPCU6SwQxWQXsLX3/eNy9MsFuSFeUmH0bvFEWMhanhyzDucUMltvrCSbQ5gmPUzbgVedM86kojjGHdQH4srnaMGA3cwDtgQBichAjhO7K9q8mdpPd55BNJgykEb07dClCWVPiOYgNdqki0KiLOLGMMXQbTtRMlXUz3CUQfCUVaKgRseIHZH7@2UqZ6I80T7vu@9ixMen7JJ4vV0nyCw "PHP ‚Äì Try It Online") - PCRE (fast)  
[Try it online!](https://tio.run/##RY/BasMwEER/RZgFS3EV7B4jBIGe@wWOA8Ld1AJ1ZWQFizj6dtduKZ3bG4ZhZvQzhmlA51YIug34iak7nQhnfi7XK780KT2vSRxgLc8vxZv/Gq3Dj0IoeOha3XxA0w8cHLPEwNJ4j2IBo8HJaXQ2FrJQ9sbBHHt/pyhdZK97oNJg2rrLWwEH0q2l2P04Ckg6/ONm56oSy94Rju8m9gNOvEzlAUj82g@xzMFGlIOfYt5mNeqfmSS/nXGWkAHlnNdaNvWmbw "PowerShell ‚Äì Try It Online") - .NET
This works by exploiting the fact that \$(N+1)^2-N^2=2N+1\$, i.e. the differences between consecutive squares are consecutive odd numbers. The loop is initialized by subtracting \$1\$ from tail, which then captures `\1`=\$1\$. Every subsequent iteration sets `\1`\$=\$`\1`\$+2\$ and subtracts `\1` from tail. As a result, the cumulative subtraction from tail is at every step a perfect square, and the `$` will only match at the end if the subtraction culminates in tail equaling zero, meaning the initial value of tail before the loop started was a perfect square.
As such, this regex relies on being able to read the last captured value of group 1 from inside group 1 ‚Äì a nested backreference, which is a feature not supported by the ECMAScript, Python, or Ruby regex engines.
In [this post by primo](https://codegolf.stackexchange.com/questions/19262/match-strings-whose-length-is-a-fourth-power/22084#22084), it is explained how to extend this method to higher powers and polynomials.
An alternative 12 byte form is `(\1xx|^x?)+$`, but this breaks some nice properties of the form shown above. Most notably, it breaks letting the loop iteration count equal the square root of the number being matched. One of the beauties of keeping that property is that we can return the square root, for example using .NET's balanced groups feature (**25 bytes**):
```
^(?=(\1xx|^x)*$)(?<-1>x)*
```
[Try it online!](https://tio.run/##RY9RboMwDIavEiFLJGVBsL2VZa20552AUQl1LkRKHRSCQGW87gA74i7CwqZpb/78W5/tzo7o@haNWcGp0mGDU7XfE478GK8nflD8NZ@m99MkdiD44VHmT6Fc4@Nd9GyvnTb4FokCbiorLtZhfW45GKaJgaZu8GKGWoGRfWe0j2RU6AuHOj3bgbw0nt1vA4mCusyqJQg4kCo1@eqnUwBJg3@cb5wkYt4cVwUufan9ucWex1O8AxK/yU3Mo9MeZWt7v4TL8uKfmSQbnjOakEVA7Ovjk0GwpY2zQ9eHnalBanwromVZ1kzmD1n2DQ "PowerShell ‚Äì Try It Online") - .NET
Or using group-building with a branch reset group (**19 bytes**):
```
^(?|\1(\1x)|^(x))*$
```
[Try it online!](https://tio.run/##RU5BTsMwELz3FVZl1V6aNDYSlzpuUqlcOXEjrVVQCpZMGuwgBbnmyAN4Ih9J3YDEHlY7o5mdaWtrbobXD4StQN4cn/YG4UxEKPPN@n69CpPD0VLsJBP5SoBH@hAR@NbqpkPTqpmKgEojXWt0R0lKEvf@6LpoUUnKEw7120VU/LMs8rDECsTll4uJe1ua/Bp8aR74VsbNtiJMEBqT9R@BdS5HQbzmc/DRS0lPeqxBfmbYZuCxm83GXmOt2JmL35pYLwj6@fpGZEExL0zdPHcvmC8ZiBCCUrd3G6WGHS1OFacV7@G0oz3AFR4GlnIW5ww "Perl 5 ‚Äì Try It Online") - Perl  
[Try it online!](https://tio.run/##XVHNatwwEL7vUwxC4JlE67WXNGGrNXtpAoGQQ9tbnAjH1camtixkBTYke80D5BHzItvx0l4q0DB/3/fNSL7xh/XGNx5kgALEQkAKPtgnE6zvqtpiskhPNsY0VRdNPfS@7WwosSRdfl@MiYKE75aT5slODS5aF0c05ur65tIYUpATUzKxnrWuNaONKHwdbPpY1b9jYGO6tm@jUCDOlquz1fnFcvVFkJ5th4CyLTItu2LL7CP@@Pnt@pY0vUK7RdndjTF01rFH8/y@KETpBHHz@PzIFU6rTM1zmvB257vhl0UxF4rbNePr4dnFCbteMuiOCdhm93oGcFR2f2Pp1sWxzt7pKbE04PGF@irWDcqgWGx6LltFTHaJko6U7IngdZqyJVs3wzSaBt4m1zDFIF0q4PP9A0SKtvfxBWXPGrTJvv7b6hiT3vNA@/8@AEkfHnDzVuZY5jt6e8Ad0Yk8HLJ5nvH5Aw "PHP ‚Äì Try It Online") - PCRE
# Regex (Python[`regex`](https://bitbucket.org/mrabarnett/mrab-regex/src/hg/) / Ruby or better), 22 bytes
```
^((?=(\3xx|^x))(\2))*$
```
[Try it online!](https://tio.run/##NY5BasMwEEX3PsUgsphJbWMlO7siB3EcCK2SqKgjM1KpAr27a7l0Vp95vM@fn@kR@Li4zzlIgviMtdi7zfVHDDyAGFFKLRfEk8HzMeefSybC84Fov1tWNOq@0dMAznTVLQh4cFxa2pjeHfcVeOPbOHuXUDWKKnA38JbR0@uhBz/qyfixmyooMhdZrny36DhhAVT/JT3Ri6a1rxRsC9tor/L2QKlBZbXnDRbqepilWLQ9jB7@B4Wv1H6LSxZjEmSipWt0t94v "Python 3 ‚Äì Try It Online") - Python `import regex`  
[Try it online!](https://tio.run/##PY7RS8MwEMbf/SvOIiwZNqQV9rAYpLgivkyYvrVbUJZ1gXAracYiiP96Tabu4Q7uu@/33bnjx@foQMJKdzr0DPUJFtVbxZx@397@ivP589PyZVU/Vq@1ACO5gNPeWA1WdtoPVwBmB7bJi7WUWYuZiAvbcMbyci1A4zY6osKG3hpPJvmE/iHMauz8ntD7MjJN5CN2QXYHBwgGIYnMH5QhBaeMJeNljL5zFslCNkUK8hucSIK5Tn/2Rz@c89LfRZydQQ/4fyL1VErVy4VS44aQB0nauxC@NoFS0paUTm/GkeezGec/ "Ruby ‚Äì Try It Online") - Ruby
In regex flavors with no support for nested backreferences, that feature must be emulated via forward-declared backreferences (which aren't supported either by ECMAScript or Python's built-in `re` module). This is done here by copying back and forth between `\2` and `\3`.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
Ln¬π√•
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fJ@/QzsNL//83MwEA "05AB1E ‚Äì Try It Online")
[Answer]
## [SageMath](https://sagemath.org), 9 bytes
```
is_square
```
[Try it online](http://sagecell.sagemath.org/?z=eJzLLI4vLixNLErVMNLSMjEyNdY11AQASNYF0A==&lang=sage)
The built-in function does exactly what it says on the tin. Since Sage uses symbolic computation, it's free of computational accuracy errors that plague IEEE-754 floats.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 3 bytes
```
¬¨v1
```
[Try it online!](https://tio.run/##y0osKPn//9CaMsP//81MAA "Japt ‚Äì Try It Online")
Seems to work fine for `2**54-2` in the [Japt Interpreter](http://ethproductions.github.io/japt/?v=1.4.5&code=rHYx&input=MTgwMTQzOTg1MDk0ODE5ODI=) but fails on TIO for some reason...
[Answer]
## Haskell, ~~26~~ 24 bytes
```
f n=elem n$map(^2)[0..n]
```
[Try it online!](https://tio.run/##DclBCoAgEADAr@zBQ8Eiq1mefIkoeFCSdJHq/9Zc50zPlVubswC73HIHFj2NJerVk5QcZk@VwcG4K78g4E8o4AkVHgaVMVHjjhYVkcLNhvkB "Haskell ‚Äì Try It Online")
Checks if n is in the list of all squares from `0` to `n`.
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 27 bytes
```
+N:-between(0,N,I),N=:=I*I.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/X9vPSjcptaQ8NTVPw0DHT8dTU8fP1srWU8tTDyipYaipx8UFAA "Prolog (SWI) ‚Äì Try It Online")
## Explanation
Searches through all numbers greater or equal to `0` and less than or equal to `N` and tests whether that number squared is equal to `N`.
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), 1 byte
```
¬∞
```
[Try it online!](https://tio.run/##y00syUjPz0n7///Qhv//DbgMucxMuCwsuIwMTcxNLIzNTMy5jM24jM25zEwB "MathGolf ‚Äì Try It Online")
I don't think an explanation is needed. I saw the need for an "is perfect square" operator before I saw this challenge, as the language is designed to handle math related golf challenges. Returns 0 or 1, as MathGolf uses integers to represent booleans.
[Answer]
# APL, 5 bytes
```
‚ä¢‚àä‚ç≥√ó‚ç≥
```
Explanation:
```
‚ä¢           N
  ‚àä         in
    ‚ç≥        numbers up to N
      √ó     times
        ‚ç≥    numbers up to N
```
Test:
```
      ((‚ä¢‚àä‚ç≥√ó‚ç≥) ¬® X) ,[√∑2] X‚Üê‚ç≥25
1 0 0 1 0 0 0 0 1  0  0  0  0  0  0  1  0  0  0  0  0  0  0  0  1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
```
[Answer]
# PHP, 21 bytes
```
<?=(-1)**$argn**.5<2;
```
If the square root is not an integer number, `(-1)**$argn**.5` is `NAN`.
[Answer]
# R, 15
```
scan()^.5%%1==0
```
^.5 is less bytes than sqrt(). %%1, the modulus, will result in 0 if answer is an interger. scan() takes user input.
<http://www.tutorialspoint.com/execute_r_online.php?PID=0Bw_CjBb95KQMSm1qVktIOUdSSDg>
[Answer]
# Ruby, 25 bytes
```
Math.sqrt(gets.to_i)%1==0
```
There probably is a shorter way but that's all I found.
[Try it online!](https://tio.run/##KypNqvz/P0fBVkHXTkGjQlOhWsE3sSRDr7iwqATIVTW0tTVQqOUqKC0pVsjRS07MydFITy0p1ivJj8/UpKXw//8GXIZcZiZcFhZcRoYm5iYWxmYm5gA "Ruby ‚Äì Try It Online")
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, ~~20~~ 17 bytes
Saved 3 bytes thanks to @chunes!
```
[ ‚àö dup ‚åä = ]
```
[Try it online!](https://tio.run/##LcwxCsIwGIbh3VN8JyimhiQqzuLiIk7iUNK/GNQkpn8GEXcRT@DxepEo4vjCw9s1lkMq281qvZzh3PABMRHzNSbnGUdKnk7o6ZLJW@p/ouqyt@yC/2f2zoaWMB/dMIZADYkphILQUBLGoBZSSzNRUuOOssPweKPNEcPriQX25fuJqMoH "Factor ‚Äì Try It Online")
[Answer]
# [PHP](https://php.net/), 26 bytes
```
<?=(0^$q=sqrt($argn))==$q;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwKWSWJSeZ6tkYqlkzWVvBxS01TCIUym0LS4sKtEAS2pq2tqqFFr///81L183OTE5IxUA "PHP ‚Äì Try It Online")
[Answer]
# [CJam](https://sourceforge.net/projects/cjam/), 8 bytes
```
ri_mQ2#=
```
[Try it online!](https://tio.run/##S85KzP3/vygzPjfQSNn2/38zIwA)
### Explanation
Integer square root, square, compare with original number.
[Answer]
# Mathematica, 13 bytes
```
AtomQ@Sqrt@#&
```
[Try it online!](https://tio.run/##y00sychMLv6fZvvfsSQ/N9AhuLCoxEFZ7X9AUWZeiYJDmoOF4X8A "Mathics ‚Äì Try It Online")
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 8 bytes
```
0=1|*‚àò.5
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/hR2wQDW8MarUcdM/RMgXwFAwVDBTMTBQsLBSNDE3MTC2MzE3MA "APL (Dyalog Unicode) ‚Äì Try It Online")
`0=`‚ÄÉ[is] zero equal to
`1|`‚ÄÉthe modulus-1 (i.e. the fractional part) of
`*‚àò.5`‚ÄÉthe argument raised to the power of a half
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 27+2 bytes
```
{x=int($0^0.5);$0=x*x==$1}1
```
[Try it online!](https://tio.run/##jcwxCgJRDATQfk9hsYUKSuYnmeQjewSvIFiKYCW4IJ79m97GcoY3c33dx3ivy@3x3M5ykaPvTrMs635dlhkfjCETJtqUOTVYaHdKVSEwINUoxt7YHUJ0kAwV84S37n86/jhFKJhFNOCZBvFosfmB7s2V8EIh0qmVeh2qScumLCJd01gD1ahVWJ0zG2DOcTh/AQ "AWK ‚Äì Try It Online")
Add `+2` bytes for using the `-M` flag for arbitrary precision.
I originally used string comparison because large number compared equal, even though they weren't, but the `sqrt` was also returning imprecise values. `2^127-2` should not be a perfect square.
[Answer]
# T-SQL, 38 bytes
```
SELECT IIF(SQRT(a)LIKE'%.%',0,1)FROM t
```
Looks for a decimal point in the square root. `IIF` is specific to MS SQL, tested and works in MS SQL Server 2012.
Input is in column **a** of pre-existing table **t**, per [our input rules](https://codegolf.meta.stackexchange.com/a/5341/70172).
]