[Question]
  [
# Background
Most of you know what a [Fibonacci number](https://en.wikipedia.org/wiki/Fibonacci_number) is. Some of you may know that all positive integers can be represented as a sum of one or more distinct Fibonacci numbers, according to [Zeckendorf's Theorem](https://en.wikipedia.org/wiki/Zeckendorf%27s_theorem). If the number of terms in the optimal Zeckendorf Representation of an integer `n` is itself a Fibonacci number, we will call `n` "secretly" Fibonacci.
For example:
```
139 = 89 + 34 + 13 + 3
This is a total of 4 integers. Since 4 is not a Fibonacci number, 139 is not secretly Fibonacci
140 = 89 + 34 + 13 + 3 + 1
This is a total of 5 integers. Since 5 is a Fibonacci number, 140 is secretly Fibonacci
```
## Notes
* The optimal Zeckendorf Representation can be found using a greedy algorithm. Simply take the largest Fibonacci number <= n and subtract it from n until you reach 0
* All Fibonacci numbers can be represented as a sum of 1 Fibonacci number (itself). Since 1 is a Fibonacci number, all Fibonacci numbers are also secretly Fibonacci.
# Challenge
Your challenge is to write a program or function that takes an integer and returns whether that integer is secretly Fibonacci. 
## Input
You may take input in any reasonable format. You may assume the input will be a single positive integer.
## Output
Output one of two distinct results for whether the input is secretly Fibonacci. Examples include `True`/`False`, `1`/`0`, etc.
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins! Standard loopholes are forbidden.
# Test Cases
```
Truthy (secretly Fibonacci)
1
2
4
50
140
300099
Falsey (NOT secretly Fibonacci)
33
53
54
139
118808
```
  
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 54 bytes
```
x=>g(g(x))<2;g=(x,i=1,j=1)=>j>x?x&&g(x-i)+1:g(x,j,i+j)
```
[Try it online!](https://tio.run/##ZclNDkAwEEDhvYPITJQoNn6mdu4hSNOJqCAyt6/u7V6@x/M738vlzic//LqFiYKQsWBBEIeqtwSiHGnFpJEMGxklTePNHWa6i6FYuYwx9Mnij9vvW7F7CxPoukX8YVNGDB8 "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 77 bytes
```
def f(n):z=[bin(x).count('1')for x in range(n*n+1)if x&2*x<1];print z[z[n]]<2
```
[Try it online!](https://tio.run/##NcmxDsIgEIDh3ae4yXKVmB7UQa1PQhiqFmXwIAQT5OWxDg7/8n/xk5@BVWv3xYETjKd6MVfPouD@Ft6cRUcdupCggGdIMz8WwT3vCL2DslV9mcieY/KcoZpq2NpJtdcchZNgSIKSMEo4DBJoHCxu/qT1en@tSvposX0B "Python 2 – Try It Online")
This makes use of the theorem that the two descriptions of [OEIS A003714](https://oeis.org/A003714) are equivalent:
> 
> Fibbinary numbers: if \$n = F(i\_1) + F(i\_2) + \dots + F(i\_k) \$ is the Zeckendorf representation of \$n\$ (i.e., write \$n\$ in Fibonacci number system) then \$a(n) = 2^{i\_1} + 2^{i\_2} + \dots + 2^{i\_k}\$. **Also** numbers whose binary representation contains no two adjacent \$1\$'s. 
> 
> 
> 
We generate enough\* such numbers, and then use `z` as a mapping from non-negative integers to “how many terms are in the Zeckendorf representation of \$n\$?” by counting 1s in binary.
Then it remains to check if `z[n]` is a Fibonacci number, i.e. `z[z[n]] == 1`.
\*At least, \$n^2+1\$ *feels* like enough, and experimentally it seems to be enough. I'll prove this some time later.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
‘ÆḞ€fRṪạµƬL’Ɗ⁺Ị
```
A monadic link accepting a non-negative integer which yields `1` if "Secretly Fibonacci" and `0` otherwise. 
**[Try it online!](https://tio.run/##ATAAz/9qZWxsef//4oCYw4bhuJ7igqxmUuG5quG6ocK1xqxM4oCZxorigbrhu4r///8yMzI "Jelly – Try It Online")** (too inefficient for the larger test cases)
### How?
```
‘ÆḞ€fRṪạµƬL’Ɗ⁺Ị - Link: integer, I
        µƬ      - perform the monadic link to the left as a function of the current I,
                - collecting up all the inputs until the results are no longer unique:
‘               -   increment I -> I+1
 ÆḞ€            -   nth Fibonacci number for €ach n in [1,I+1]
     R          -   range from 1 to I
    f           -   filter discard (discard Fibonacci numbers not in the range, i.e. > I)
      Ṫ         -   tail (get the largest)
       ạ        -   absolute difference with I
                - This gives us a list from I decreasing by Fibonacci numbers to 0
                - e.g. for 88 we get [88,33,12,4,1,0]
                -      because (88-33)+(33-12)+(12-4)+(4-1)+(1-0)=55+21+8+3+1=88 
          L     - length (the number of Fibonacci numbers required plus one)
           ’    - decrement (the number of Fibonacci numbers required)
            Ɗ   - treat the last three links (which is everything to the left) as a monad:
             ⁺  - ...and repeat it
                - i.e. get the number of Fibonacci numbers required for the number of
                -      Fibonacci numbers required to represent I.
                -      This is 1 if I is Secretly Fibonacci, and greater if not)
              Ị - insignificant? (is the absolute value of that <= 1?)
```
[Answer]
# [R](https://www.r-project.org/), 83 bytes
```
function(n){T=1:0
while(n>T)T=c(T[1]+T[2],T)
while(n){n=n-T[T<=n][1]
F=F+1}
F%in%T}
```
[Try it online!](https://tio.run/##PcrNCoJAFEDh/TyFEMIMXmGuo6DhBC2cVau6rcRFSJIgN@mHCPHZJxcVnN13br4Lyth3T24f/ZUlq4ksrrV4XfrhLHlDimwrqcYmojppgNSP1MSWY6qptNwsLpx1Ec7ChT2HNPv7aRyHt2wlQgIpZBow1WC01kWhoFPBKqD9sRL/zxjIllJAUwBinuv8@7nt7lD5Dw "R – Try It Online")
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 124 115 98 bytes
```
a=>{int n=0,b,c;for(;a>0;a-=b,n++)for(b=c=1;c<=a;b=c-b)c+=b;for(b=c=1;c<n;c+=b)b=c-b;return c==n;}
```
[Try it online!](https://tio.run/##hc/BSsUwEAXQtf2KLBvaSmKf0DJvCiK40pUL10lMJVAnkKSClH57bUXBhbxkFe49TCYmNsYHu83R0Rt7/ozJvgMzk4qR3bGliEklZ9jDTObsKNXa@2lgI24Kh2UPGKGodW1g9KEENQhQDeqaqoofiUaDEswZFezXRnNToYa/DcER8e8Wgk1zIGYQCdYNfl//8O6VPSlHJV@Kq3tP0U/2@iW4ZB8d2XIsJedQsJ/zH7jJgVMO3IqckKcsaYUQfX@oC@xyuw9ps7vmRfa/su2zRHad6A61rtsX "C# (.NET Core) – Try It Online")
*-3 bytes: changed while loop to for (thanks to [Olivier Grégoire](https://codegolf.stackexchange.com/questions/174907/is-this-number-secretly-fibonacci/174922?noredirect=1#comment421548_174922))*  
*-6 bytes: switched returns to use variable, initialized b and c outside of loops (thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/questions/174907/is-this-number-secretly-fibonacci/174922?noredirect=1#comment421559_174922))*  
*-17 bytes: changed condition in second loop to move if out of loop and combine with return, reused b and c variables in last loop (thanks to [raznagul](https://codegolf.stackexchange.com/questions/174907/is-this-number-secretly-fibonacci/174922?noredirect=1#comment421577_174922))*
Ungolfed:
```
a => {
    int n = 0, b, c;                        // initialize variables
    for(; a > 0; a -= b, n++)               // increase n until a is 0
        for(b = c = 1; c <= a; b = c - b)   // set b and c to 1 for each a; set second largest Fibonacci number until largest Fibonacci number reaches a
            c += b;                         // set largest Fibonacci number of current sequence
    for(b = c = 1; c < n; c += b)           // while e is less than or equal to n, continue incrementing largest (e) Fibonacci number in the sequence
        b = c - b;                          // increment second-largest (d) Fibonacci number
    return c == n;                          // if c equals n, a is a secret Fibonacci number
}
```
[Answer]
# [Perl 6](http://perl6.org/), 58 bytes
```
{(1,&[+]...*>$_)∋($_,{$^n-(1,&[+]...^*>$n).tail}...0)-1}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WsNQRy1aO1ZPT0/LTiVe81FHt4ZKvE61SlyeLkIqDiiXp6lXkpiZUwvkGmjqGtb@L06sVFBSiVewtVOoTlNQia9VUkjLL1Iw1FEw0lEw0VEwNdBRMDQBEsYGBgaWlkDaGCgIwkBJQ2OggKGhhYWBxX8A "Perl 6 – Try It Online")
`1, &[+] ... * > $_` is just the Fibonacci sequence, stopped at a convenient non-infinite place (the input number).
`$_, { $^n - (1, &[+] ...^ * > $n).tail } ... 0` is a sequence of numbers, starting with the input number, and each successive element obtained by subtracting the largest Fibonacci number less than or equal to the previous element from the previous element. The sequence terminates when `0` is reached. For example, if `$_` is `140`, then this sequence is `140, 51, 17, 4, 1, 0`.
Subtracting one from this sequence treats it as a number, its length, and the difference is the number of Fibonacci numbers which, added together, give the input number. Then this number is checked for membership in the first Fibonacci sequence.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 48 bytes
```
{4>($_,{$_,{$_-(1,&[+]...*>$_)[*-2]}...^0}...1)}
```
[Try it online!](https://tio.run/##JYlBCoMwFET3PcUgQdTGkG/SEinmImJDF83K0mJXEnL29EsX84Z583lu67W8dtQRE0qyvhFBpn/6hmQ9nxelVOdFaOeuH5bM664PUpvL7fR97KhEwOSRIkTIFeJ7A0kMElbioiXIMozWehy5DcsjfJJhQeScduUH "Perl 6 – Try It Online")
Transforms the input to a list of Zeckendorf Representation repeatedly until it reaches a single number and then checks if the length of the sequence was less than 4.
The Zenckendorf function in the middle is mostly from [Sean's answer](https://codegolf.stackexchange.com/a/174924/76162) with a couple of improvements.
### Explanation:
```
{4>($_,{$_,{$_-(1,&[+]...*>$_)[*-2]}...^0}...1)}
{                                              } # Anonymous code block
                                          ...     # Define a sequence:
    $_  # That starts at the input
      ,{                                 }  # Each element is defined by:
                                   ... # Another sequence that:
        $_,   # Starts at the previous element
            $_-   # The previous element minus
                1,&[+]...*     # The Fibonacci sequence
                          >$_  # Ending when it is larger than the previous element
               (             )[*-2]  # The second from last element
          {                        }...^0  # Run until 0, discarding the last element
         # This returns the length of the Zeckendorf Representation
                                         ...1  # Run this until it is length 1
 4>(                                         )  # Return true if the length of the sequence is smaller than 4
```
For example, the sequence for `2` is `2 1` since `2` is already a Fibonacci number. The sequence for `140` is `140 5 1`, and since 5 is a Fibonacci number this returns true. The sequence for `33` is `33 4 2 1`, and since `4` is not a Fibonacci number the sequence is of length 4.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ΔDÅFθ-¼}¾ÅF¾<å
```
[Try it online](https://tio.run/##yy9OTMpM/f//3BSXw61u53boHtpTe2gfkHlon83hpf//G5oYAAA). No test suite for all test cases, because the `counter_variable` cannot be reset to 0.. I verified all by hand though, and they are correct.
**Explanation:**
```
Δ      }          # Loop until the top of the stack no longer changes
 D                #  Duplicate the top of the stack
                  #  (implicitly the input in the first iteration)
  ÅF              #  Get a list of all Fibonacci numbers lower than this number
    θ             #  Get the last item (largest one)
     -            #  Subtract it from the number
      ¼           #  Increase the counter_variable by 1 every iteration
        ¾         # After the loop, push the counter_variable
         ÅF       # Get all Fibonacci numbers below this counter_variable
           ¾<     # Push the counter_variable again, and subtract 1
             å    # Check if this value is in the list of Fibonacci numbers
                  # (and output implicitly)
```
NOTE: The `counter_variable` would be `5` for input `139` and `6` for input `140`, because in order for the `Δ`-loop to check the stack remained the same, it does of course an additional iteration.
[Answer]
# [Haskell](https://www.haskell.org/), 64 bytes
```
s=(<2).r.r
f=1:scanl(+)1f
r 0=0
r z=1+r(z-last(takeWhile(<=z)f))
```
[Try it online!](https://tio.run/##ZYqxDoMgFAB3voLBAeKreU80kQb6Gx0aB9JqNFLagBM/T9l7udx0m0vH4n0pyQrTyy52ka2WrunpghetpJVFjhZrs6U2inzxLp3idMdy33a/CGOzXKUsb7cHbvnrw3jlG/dw8oYn09weBD0MMCLQgKAQUev5/1IKxuoApDQQTRNOc/kB "Haskell – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 61 bytes
```
.+
$*
M`((?>\2?)(\1|\G.))*..|.
.+
$*
^(((?>\3?)(\2|^.))*.)?.$
```
[Try it online!](https://tio.run/##Jcm7CoQwEEbh/n8OhYnCMJOJEBtTWu0bBHGLLWwsxDLvHi/bHA58x@/c9m9taV4r92g6fFaiNGWfHGUteWbnOubC@PNCL9vDviyvusRNrQqPADMMguFugNoIDQITkfFejVHiBQ "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
.+
$*
```
Convert to unary.
```
M`((?>\2?)(\1|\G.))*..|.
```
Count the number of Fibonacci numbers needed.
The first alternation deals with Fibonacci numbers that are at least 2. On the first pass, `\2` does not exist yet, but fortunately it's optional, so we don't have to match it. `\1` doesn't exist either, but fortunately we have the alternative of `\G.` which matches a single character at the start of the match. Both `\2` and `\1` therefore take on the value 1.
On subsequent passes, `\2` exists, so we try to match it. This time if it fails then `\1` also fails (since it is bigger than `\2`), but if it succeeds, the `(?>)` prevents backtracking, so if `\2` matches but `\1` does not we don't try just `\1`. (`\G1` always fails since we've advanced past the start of the patch.) Finally `\2` takes on the previous value of `\1` while `\1` takes on the sum of the two values.
We therefore match as many Fibonacci numbers as we can, adding as we go. Since the partial sums of the sequence `1, 2, 3, 5...` are `0, 1, 3, 6, 11...` i.e. 2 less than the Fibonacci numbers we finish by matching 2 at the end.
This obviously fails to match 1 itself so an alternation handles that case.
```
.+
$*
```
Convert to unary.
```
^(((?>\3?)(\2|^.))*.)?.$
```
Test whether this is a Fibonacci number. This uses the same idea as the first test but it uses `^` instead of `\G` and we also need to match exactly, so it uses an optional capture instead of an alternation as that's golfier (but it increases the capture numbers by 1).
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 35 bytes
```
.+
*
2}C`((?>\2?)(\1|\G.))*..|.
^1$
```
[Try it online!](https://tio.run/##DcaxCoAgEAbg/X@OgrPguFMDXWpo8CUkbGhoaYhGe3Zr@fju4zmvXVtPlErjEQPsuxaiZc52MZS15sTGDMyVsWnXmsLCwzlMgunXQ12EeoETkfhXQ5DwAQ "Retina – Try It Online") Link includes test cases. Explanation:
```
.+
*
```
Convert to unary.
```
C`((?>\2?)(\1|\G.))*..|.
```
Count the number of Fibonacci numbers needed. (Looping both the conversion and count saves a whole byte over getting the count in unary in the first place.)
```
2}
```
Perform the previous steps twice in total. This takes the count of Fibonacci numbers needed to sum to the count of Fibonacci numbers.
```
^1$
```
If the number was secretly Fibonacci then the result is 1.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~146~~ 137 bytes
```
lambda a:len(g(len(g(a))))<2
f=lambda n:n<3or f(n-2)+f(n-1)
def g(a,n=1):j=f(n-1);return[j]if a-j<1else[j]+g(a-j)if a-f(n)<0else g(a,n+1)
```
[Try it online!](https://tio.run/##bY3BDoIwDIbP7ikaTiyMZGOawISrT@BNPcy4CQSqmXDw6bGI8WBc0r9d@/fr/TnUN8ymujpOne3PFwvWdA7ja7yo5fTKjPnqM0aDpb4F8DGmGU/mpDi7OA9kFlgpbtpq6W6DG8aAh/bUeLBpWyrXPRx9E7KmLX93ycpLOQ8WQKL4dA8NDhDtwzjUTxMxT/dw7KFBOCgBmYC1gI0UoNYkWkpZFCfDVsseOQXUMSXO2AcVfaudpVO/UK2JNwdxlS5IVJ7L/C9zegE "Python 2 – Try It Online")
f() is a recursive function that returns the value of the nth Fibonacci number. Taken from [this answer](https://codegolf.stackexchange.com/a/131578/73368).
g() is a recursive function that returns the Zeckendorf Representation of the given number as a list of integers.
Since all Fibonacci numbers will have a return length of one item from g(), h() checks if the length of the g() of g(n) == 1.
**EDIT:** Saved 9 bytes thanks to [nedla2004](https://codegolf.stackexchange.com/users/59363/nedla2004). I keep forgetting that lambdas aren't always the best solution...
[Answer]
# [Husk](https://github.com/barbuz/Husk), 16 bytes
```
£İf←LU¡λ≠⁰→↑≤⁰İf
```
[Try it online!](https://tio.run/##yygtzv7//9DiIxvSHrVN8Ak9tPDc7kedCx41bnjUNulR28RHnUuAbKDs////DY0tAQ "Husk – Try It Online")
]