Am I a Fibonacci Number?

Neim, 2 bytes

f

Explanation:

f       Push an infinite fibonacci list
       Is the input in that list?

Works the same as my It's Hip to be Square answer, but uses a different infinite list: f, for fibonacci.

Try it!


JavaScript (ES6), 34 bytes

f=(n,x=0,y=1)=>x<n?f(n,y,x+y):x==n

Recursively generates the Fibonacci sequence until it finds an item greater than or equal to the input, then returns item == input.


Retina, 23 bytes

^$|^(^1|(?>\2?)(\1))*1$

Try it online!

Input in unary, outputs 0 or 1.

Explanation

The Fibonacci sequence is a good candidate for a solution with forward references, i.e. a "backreference" that refers either to a surrounding group or one that appears later in the regex (in this case, we're actually using both of those). When matching numbers like this, we need to figure out a recursive expression for the difference between sequence elements. E.g. to match triangular numbers, we usually match the previous segment plus one. To match square numbers (whose differences are the odd numbers), we match the previous segment plus two.

Since we obtain the Fibonacci numbers by adding the second-to-last element to the last one, the differences between them are also just the Fibonacci numbers. So we need to match each segment as the sum of the previous two. The core of the regex is this:

(         # This is group 1 which is repeated 0 or more times. On each
          # iteration it matches one Fibonacci number.
  ^1      # On the first iteration, we simply match 1 as the base case.
|         # Afterwards, the ^ can no longer match so the second alternative
          # is used.
  (?>\2?) # If possible, match group 2. This ends up being the Fibonacci
          # number before the last. The reason we need to make this optional
          # is that this group isn't defined yet on the second iteration.
          # The reason we wrap it in an atomic group is to prevent backtracking:
          # if group 2 exists, we *have* to include it in the match, otherwise
          # we would allow smaller increments.
  (\1)    # Finally, match the previous Fibonacci number and store it in
          # group 2 so that it becomes the second-to-last Fibonacci number
          # in the next iteration.
)*

Now this ends up adding the Fibonacci numbers starting at 1, i.e. 1, 1, 2, 3, 5, .... Those add up to 1, 2, 4, 7, 12, .... I.e. they are one less than the Fibonacci numbers, so we add a 1 at the end. The only case this doesn't cover is zero, so we have the ^$ alternative at the beginning to cover that.