[Question]
  [
Given a list of `1`s and `-1`s, determine whether or not it is a valid [OVSF code](https://en.wikipedia.org/wiki/Chip_(CDMA)#Orthogonal_variable_spreading_factor) (by outputting a truthy or falsey value).
OVSF codes are defined as follows:
* `[1]` is an OVSF code.
* If `X` is an OVSF code, then `X ++ X` and `X ++ -X` are both OVSF codes.
Here `++` is list concatenation, and `-` negates every element in the list.
* No other lists are valid OVSF codes.
You may assume the input list contains only `-1` and `1`, but you must handle the empty list correctly, as well as lists whose length is not a power of 2.
Shortest code (in bytes) wins.
# Test cases
```
[] -> False
[1] -> True
[-1] -> False
[1, 1] -> True
[1, -1] -> True
[-1, 1] -> False
[-1, -1] -> False
[1, 1, 1, 1] -> True
[1, 1, 1, 1, 1] -> False
[1, -1, -1, 1, -1, 1, 1, -1] -> True
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1] -> False
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1] -> False
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1] -> True
```
  
[Answer]
## Mathematica, ~~52~~ ~~47~~ 45 bytes
Byte count assumes CP-1252 encoding and `$CharacterEncoding` set to `WindowsANSI` (the default on Windows installations).
```
±___=!(±1=1>0)
a__±b__/;a!==b!||{a}==-{b}:=±a
```
This defines a variadic function `PlusMinus`, which takes the input list as a flat list of arguments and returns a boolean, e.g. `PlusMinus[1, -1, -1, 1]` gives `True`. It's theoretically also usable as an operator `±`, but that operator is only syntactically valid in unary and binary contexts, so the calling convention would get weird: `±##&[1,-1,-1,1]`. It will throw a bunch of warnings that can be ignored.
This will also throw a few warnings which can be ignored.
There *might* be away to shorten the somewhat annoying `a!==b!||{a}==-{b}` part, but I'm not finding anything right now. Keywords like `SubsetQ` and `MatrixRank` are simply too long. :/
### Explanation
The solution basically defers all the tricky things to Mathematica's pattern matcher and is therefore very declarative in style. Apart from some golfitude on the first line, this really just adds three different definitions for the operator `±`:
```
±___=False;
±1=True;
a__±b__/;a!==b!||{a}==-{b}:=±a
```
The first two rows were shortened by nesting the definitions and expressing `True` as `1>0`.
We should deconstruct this further to show how this actually defines a variadci function `PlusMinus` by only using unary and binary operator notation. The catch is that all operators are simply syntactic sugar for full expressions. In our case `±` corresponds to `PlusMinus`. The following code is 100% equivalent:
```
PlusMinus[___]=False;
PlusMinus[1]=True;
PlusMinus[a__,b__]/;a!==b!||{a}==-{b}:=PlusMinus[a]
```
By using sequences (sort of like splats in other languages) as the operands to `±` we can cover an arbitrary number of arguments to `PlusMinus`, even though `±` isn't usable with more than two arguments. The fundamental reason is that syntactic sugar is resolved first, before any of these sequences are expanded.
On to the definitions:
The first definition is simply a fallback (`___` matches an arbitrary list of arguments). Anything that isn't matched by the more specific definitions below will give `False`.
The second definition is the base case for the OVSF, the list containing only `1`. We define this to be `True`.
Finally, the third definition applies *only* to lists that can be decomposed into `X ++ X` or `X ++ -X`, and recursively uses the result for `X`. The definition is limited to these lists by ensuring they can be split into subsequences `a` and `b` with `a__±b__` and then attaching the condition (`/;`) that either `{a}=={b}` or `{a}==-{b}`. Defining `PlusMinus` as a variadic function in this weird way via an operator saves a whopping **5** bytes over defining a unary operator `±` on lists.
But wait, there's more. We're using `a!==b!` instead of `{a}=={b}`. Clearly, we're doing this because it's two bytes shorter, but the interesting question is why does it work. As I've explained above, all operators are just syntactic sugar for some expression with a head. `{a}` is `List[a]`. But `a` is a *sequence* (like I said, sort of like a splat in other languages) so if `a` is `1,-1,1` then we get `List[1,-1,1]`. Now postfix `!` is `Factorial`. So here, we'd get `Factorial[1,-1,1]`. But `Factorial` doesn't know what to do when it has a different number of arguments than one, so this simply remains unevaluated. `==` doesn't really care if the thing on both sides are lists, it just compares the expressions, and if they are equal it gives `True` (in this case, it won't actually give `False` if they aren't, but patterns don't match if the condition returns anything other than `True`). So that means, the equality check still works if there are at least two elements in the lists. What if there's only one? If `a` is `1` then `a!` is still `1`. If `a` is `-1` then `a!` gives `ComplexInfinity`. Now, comparing `1` to itself still works fine of course. But `ComplexInfinity == ComplexInfinity` remains unevaluated, and *doesn't* give true even though `a == -1 == b`. Luckily, this doesn't matter, because the only situation this shows up in is `PlusMinus[-1, -1]` which isn't a valid OVSF anyway! (If the condition did return `True`, the recursive call would report `False` after all, so it doesn't matter that the check doesn't work out.) We can't use the same trick for `{a}==-{b}` because the `-` wouldn't thread over `Factorial`, it only threads over `List`.
The pattern matcher will take care of the rest and simply find the correct definition to apply. 
[Answer]
## Haskell, 57 bytes
```
q=length
f l=l==until((>=q l).q)(\s->s++map(*l!!q s)s)[1]
```
Given input list `l`, grows a OVSF code `s` by starting from `[1]` and repeatedly concatenating either `s` or `-s`, whichever makes the first element match that of `l`. Then, checks that the result is `l` at the end. This is checked once `s` has length at least that of `l`.
Some alternatives recursive structures also happened to give 57:
```
(s%i)l|length l<=i=s==l|j<-2*i=(s++map(*l!!i)s)%j$l
[1]%1
q=length
s%l|q s>=q l=s==l|r<-s++map(*l!!q s)s=r%l
([1]%)
q=length
g s l|q s<q l=g(s++map(*l!!q s)s)l|1>0=s==l
g[1]
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~18~~ ~~16~~ ~~14~~ 11 bytes
```
^2/Eam2µḊ¿Ṭ
```
Outputs `[1]` (truthy) for OVSF codes, `[]` (falsy) otherwise.
[Try it online!](https://tio.run/nexus/jelly#@x9npO@amGt0aOvDHV2H9j/cueb/4fZHTWsi//@P5lIAguhYHQhtCGPowlmGOgrIbFQJCMIUQdcDwQgKh0EIpbooanFZgls1JTpR5WK5YgE "Jelly – TIO Nexus")
### Background
Like [@LuisMendo's MATL answer](https://codegolf.stackexchange.com/a/106409/12012) and [@xnor's Python answer](https://codegolf.stackexchange.com/a/106426/12012), this submission verifies the input array "from the inside out".
Every (non-overlapping) pair of elements of a OVSF code of length two or higher is essentially a copy of the the first pair, either with the same signs or with both signs swapped. Likewise, every (non-overlapping) 4-tuple of elements of a OVSF code of length four or higher is essentially a copy of the the first 4-tuple, either with the same signs or with both signs swapped. The same is true for 8-tuples, 16-tuples, etc., up to the length of the OVFS code.
One way to verify this is to check all pairs for equality modulo the sign first, then remove the second element of each pair (which is now redundant information). If we repeat this process once more, we're essentially checking all 4-tuples. In the next iteration, we're comparing 8-tuples, etc.
Finally, if all the required 2k-tuples were equal modulo the sign and the array has been reduced to a singleton, it is sufficient to check if the remaining element is a **1**.
### How it works
```
^2/Eam2µḊ¿Ṭ  Main link. Argument: A (array of 1's and -1's)
       µḊ¿   While dequeuing A (removing its first element) yields a non-empty
             array, execute the monadic chain to the left, updating A with the
             return value after each iteration.
^2/            Compute the bitwise XOR of each non-overlapping pair of elements of
               A. Note that 1 ^ 1 = 0 = -1 ^ -1 and 1 ^ -1 = -2 = -1 ^ 1.
               For an array of even length that consists of the same pairs modulo
               the sign, this returns either an array of 0's or an array of -2's.
               If the length is odd, it will also contain the last element, which
               is either a 1 or a -1.
   E           Test the elements of the result for equality. This yields 1 if the
               array consists solely of 0's or solely of -2's, 0 otherwise.
    a          Take the logical AND of the previous result and every element of A.
               This returns A if it passed the previous test, but replaces all of
               its elements with 0's otherwise.
     m2        Modulo 2; select every second element of A, starting with the first.
             At this point, the last return value can be:
               • [  ] if the input was empty
               • [ 1] if the input was a valid OVSF code
               • [-1] if the input was the negative of a valid OVSF code.
               • [ 0] in all other cases.
           Ṭ  Untruth; yield an array with 1's at the specified indices.
              Indexing is 1-based in Jelly, so [1] returns [1], the array with a 1
              at index 1. Since the indices -1 and 0 are non-canonical, the arrays
              [-1] and [0] are mapped to []. The empty array remains empty.
```
[Answer]
# MATLAB/[Octave](https://www.gnu.org/software/octave/), 94 bytes
```
function a=f(r);n=nnz(r);m=log2(n);a=0;if fix(m)-m==0;for c=hadamard(n);a=a+all(r==c');end;end
```
This is using a new approach: The allowed OVSF codes of length `N` appear in the `log2(N)`-th [Walsh-matrix](https://en.wikipedia.org/wiki/Walsh_matrix), as they are basically defined by the same recursion:
![](https://latex.codecogs.com/gif.latex?H%282%5Ek%29%20%3D%20H%282%29%5Cotimes%20H%282%5E%7Bk-1%7D%29)
Walsh matrices are special cases of the [Hadamard-matrices](https://en.wikipedia.org/wiki/Hadamard_matrix) of size `N x N` if `N` is a power of two. (There are also Hadamard matrices of other sizes.) MATLAB and Octave have a variety of built in functions that generate test matrices to test properties of numerical algorithms, among them is `hadamard()`. Fortunately for powers of two MATLAB's `hadamard()` usex exactly the construction of the Welsh-matrices.
So this function first checks whether the inputs length is a power of two, and if it is, it checks whether it is a row of the corresponding size Welsh-matrix.
[Try it online!](https://tio.run/nexus/octave#dU1BCgIxELv7irmILbqgXsu8RDwM7dQttFOoLat@vlYPHhYMySEkIQUvpwP8OK30P7uazRaa@FxqE6ocn7AwWBLJFRz7IAy@ia0hC/gQ@Q4zF@6wgqDISxVtEsZ8OyvRhvBogh@jh0p6SjjsuAGLMzlKVNy3BEh7ilEVRLvThsV91Km/AQ "Octave – TIO Nexus")
[Answer]
## Python, 64 bytes
```
f=lambda l:[]<l[1::2]==[x*l[1]for x in l[::2]]*f(l[::2])or[1]==l
```
Splits the list into even-indexed elements and odd-indexed elements via slices. Checks if the result vectors are either equals or negatives by multiplying one by the sign forced by its first element. Then, does the same recursive check on the even-indexed elements.
For the base case, if the check fails, rejects unless the list is `[1]`. The empty list is also specifically rejected to avoid an infinite loop.
A different strategy like [my Haskell answer](https://codegolf.stackexchange.com/a/106414/20260) gives 66 bytes:
```
f=lambda l,i=1,s=[1]:l[i:]and f(l,i*2,s+[x*l[i]for x in s])or s==l
```
[Answer]
# [><> (Fish)](https://esolangs.org/wiki/Fish), ~~431~~ 385 bytes
* -46 bytes by creating a new stack with l-2 elements so I can remove the `2-` from many places.
```
l[bb01.
>rl2=?vl3=?vl2%?vl2-2,[r0501.
      0v=1:<    0 
< <  < <<       /
  1  0
   ?!^  v|.!]@{r/
 v&,2-2l<
 >&:?!v1-&l2-[l2,[{]rl2,[}]rl2,1+[{$:@$:@=?!v}]]
 l2-, ~v&,2-2lr                 .c1r8+eer]]}<
^    1<>&:?!v1-&l2-[l2,[{]rl2,[}]rl2,1+[{$:@$:@0$-=?!v}]]79.
^         1~<.a10r                       .c1ra+eer]]}<
n;
>&1+&v
     >&:?!v1-&l4-2,[}]l4-[r]l4-2,[{]l4-[r]
       .r~<
```
[Try it](https://mousetail.github.io/Fish/#eyJ0ZXh0IjoibFtiYjAxLlxuPnJsMj0/dmwzPT92bDIlP3ZsMi0yLFtyMDUwMS5cbiAgICAgIDB2PTE6PCAgICAwIFxuPCA8ICA8IDw8ICAgICAgIC9cbiAgMSAgMFxuICAgPyFeICB2fC4hXUB7ci9cbiB2JiwyLTJsPFxuID4mOj8hdjEtJmwyLVtsMixbe11ybDIsW31dcmwyLDErW3skOkAkOkA9PyF2fV1dXG4gbDItLCB+diYsMi0ybHIgICAgICAgICAgICAgICAgIC5jMXI4K2Vlcl1dfTxcbl4gICAgMTw+Jjo/IXYxLSZsMi1bbDIsW3tdcmwyLFt9XXJsMiwxK1t7JDpAJDpAMCQtPT8hdn1dXTc5LlxuXiAgICAgICAgIDF+PC5hMTByICAgICAgICAgICAgICAgICAgICAgICAuYzFyYStlZXJdXX08XG5uO1xuPiYxKyZ2XG4gICAgID4mOj8hdjEtJmw0LTIsW31dbDQtW3JdbDQtMixbe11sNC1bcl1cbiAgICAgICAucn48IiwiaW5wdXQiOiIiLCJzdGFjayI6IjEgMSAxIDEgLTEgLTEgLTEgLTEgMSAxIDEgMSAtMSAtMSAtMSAxIiwibW9kZSI6Im51bWJlcnMifQ==) 
This took me wayyyy to long. Checking if 2 lists are equal is a pain in ><>
[![enter image description here](https://i.stack.imgur.com/a5App.png)](https://i.stack.imgur.com/a5App.png)
This code loops to check if 2 lists are equal:
```
l2-[l2,[{]rl2,[}]rl2,1+[{$:@$:@=?!v}]]
```
Basically, what we do is:
* `l` gets the length of the stack
* `l-2` is the total length of both lists. So you see `l2-` all over.
* `(l-2)/2` is the length of one list, so you see `l2-2,` all over too.
* `l2-2,[{]` moves the top list to a new stack, shifts it left, then pushes it back to the old list. This means a new value is the top one.
* To shift the other list, it's a bit more complex. Since there is no command to push the bottom of the stack to a new list. We use `l2-[3]l2-2,[}]l2-[r]`. Reverse both lists, then shift the top half right, then reverse both lists together again.
* Now we need to check if the top of both lists are equal. We now take `(l-2)/2+1` elements, so the entire top list but 1 of the bottom list. Then we shift left to 1 item from the bottom list to the top. Now we use the `$:@$:@` trick to compare them. In either case we need to shift the list back.
this is copied twice. There is also this:
```
>&1+&v                                                                 
     >&:?!v1-&l4-2,[{]l4-[r]l4-2,[{]l4-[r]                             
       .r~<
```
Which resets the list after the checking process, only needed if the process was aborted halfway though (they where not equal)
[Answer]
## JavaScript (ES6), ~~85~~ 61 bytes
```
a=>(l=a.length)&&!(l&l-1)&a.every((e,i)=>e==a[j=i&-i]*a[i-j])
```
Previous version which checked elements to ensure that they were `1` or `-1`:
```
a=>(l=a.length)&&!(l&l-1)&a.every((e,i)=>i?(j=i&-i)<i?e==a[j]*a[i-j]:e==1|e==-1:e==1)
```
Explanation:
* The length cannot be zero
* The length must be a power of 2
* The first element must be 1
* Elements in positions that are a power of 2 must be either 1 or -1
* Elements in other positions are the product of all the elements in the positions corresponding to the bitmask, e.g. `a[22] == a[2] * a[4] * a[16]`. Since `a[20] == a[4] * a[16]` has already been checked, only `a[22] == a[2] * a[20]` needs to be checked.
* The above check gives degenerate results for `i` not having at least two bits set. In the case of zero bits set, it checks that `a[0] == a[0] * a[0]`, which is false for `a[0] == -1`, while in the case of one bit set, it checks that `a[i] == a[0] * a[i]`.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 34 bytes
Translation of Jonah's solution.
```
{~^*((#1_2\#x){(x,x),'x,-x}/,1)?x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6qui9PS0FA2jDeKUa7QrNao0KnQ1FGv0NGtqNXXMdS0r6jl4kqLVjSIVahTMACydAxBLEMQS9cQJmioABc1VNCFs3Wh4gYQNop6BRQ9SAIGUENACEogmwlTq4uEMHTjVEKKUiQxiOUA3aM/ng==)
[Answer]
# [Haskell](https://www.haskell.org/), ~~106 91 87~~ 86 bytes
```
g n|n<1=[[1]]|m<-g(n-1)=foldl(\a b->[b++map(0-)b,b++b]++a)[]m++m
f l=elem l$g$length l
```
The function `g` generates the `n` iteration of lists (relatively inefficiently, since `length $ g n == 3^n`, however if we'd delete the duplicates, we'd get `2^n`), `f` checks if our list is in any one of them. Thanks to @Zgrab for a few hints!
[Try it online!](https://tio.run/nexus/haskell#LYixDsIgGAZ3n@IbOkAoiezFJ3BzRAaIQE1@/jaKcem7I4PJJXe5XsAHL8Y6Z7w/6qKLYG2kzRs9SNwDor64qFQNuzhrGefR0SsVpPN17FMG2USpgqYyUeLSVlCv4cmw2D/t1l5XxoT3un2HMpyZ8cf3Hw "Haskell – TIO Nexus")
[Answer]
# JavaScript (ES6), ~~130~~ ~~93~~ ~~87~~ ~~85~~ 83 bytes
```
f=a=>(b=a.slice(0,l=a.length/2),c=a.slice(l)+"",a==1||l&&b==c|b.map(i=>-i)==c&f(b))
```
## Demo
```
f=a=>(b=a.slice(0,l=a.length/2),c=a.slice(l)+"",a==1||l&&b==c|b.map(i=>-i)==c&f(b)),[[],[1],[-1],[1,1],[1,-1],[1,1,1,1],[1,1,1,1,1],[1,-1,-1,1,-1,1,1,-1],[1,1,1,1,-1,-1,-1,-1,1,1,1,1],[1,1,1,1,-1,-1,-1,-1,1,1,1,1,1,1,1,1],[1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1]].map(a=>console.log(`[${a}] -> ${!!f(a)}`))
```
[Answer]
# APL, 46 bytes
```
{0::0⋄⍵≡,1:1⋄⍬≡⍵:0⋄(∇Z↑⍵)∧(∇Y)∨∇-Y←⍵↓⍨Z←.5×⍴⍵}
```
Fairly straightforward:
* Base cases:
	+ `0::0`: if an error occurs, return 0
	+ `⍵≡,1:1`: if the input is exactly `[1]`, return 1
	+ `⍬≡⍵:0`: if the input is the empty list, return 0
* Recursive case:
	+ `Z←.5×⍴⍵`: `Z` is half the length of the input
	+ `Y←⍵↓⍨Z`: `Y` is the last half of the input (this fails if `⍴⍵` is uneven, triggering the exception handler)
	+ `(∇Y)∨∇-Y`: either the last half of the list, or the negation of the last half of the list, must be an OVSF code
	+ `(∇Z↑⍵)∧`: and the first half of the list must be an OVSF code.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~21~~ 20 bytes
```
`2eZ}yy=&=tn1>hh]1X=
```
[Try it online!](https://tio.run/nexus/matl#@59glBpVW1lpq2Zbkmdol5ERaxhh@/9/tKGOAhzpomHccrEA) Or [verify all test cases](https://tio.run/nexus/matl#S/ifYJQaVVtZaatmW5JnaJeREWsYYfvfJeR/dCxXtCEQ64IIQx0FKAXnQhAKB0kRBCMoTJ0IVbooyrCYilshmZpQ5WIB).
### How it works
The code splits the array into two equal-length pieces: the first with the odd-indexed entries, the second with the even-indexed entries. The two pieces are forced to have equal length, with a padding zero in the second if needed. Then the code checks that
1. The corresponding entries of the two pieces are either all equal or all different;
2. No entry in the second piece is zero;
3. The length of the pieces exceeds 1.
If these three conditions are met, the process is applied again on the first piece. If the loop is exited because the length was already 1, the input is an OFSV code. Else it is not.
Condition 1 iterated is an equivalent version of the defining property of OVSF codes. For an array of say length 8, the straightforward approach would be to check that entries 1,2,3,4 are all equal or all different to entries 5,6,7,8 respectively (this is the defining property). But we can equivalently check that entries 1,3,5,7 are all equal or all different to entries 2,4,6,8 respectively; and this turns out to use fewer bytes.
Condition 2 makes sure that the input length is a power of 2: if it's not, a padding zero will be introduced at some stage.
```
`        % Do...while loop
  2e     %   Reshape as a two-row matrix, with a padding zero if needed
         %   Row 1 contains the original odd-indexed entries, row 2 the
         %   even-indexed
  Z}     %   Split matrix into two vectors, one corresponding to each row
  yy     %   Duplicate those two vectors
  =      %   Check if corresponding entries are equal or not
  &=     %   Matrix of all pairwise comparisons. This will give a matrix
         %   filled with ones if and only if the previous check gave all
         %   true or all false (condition 1)
  tn1>   %   Duplicate and push true if size exceeds 1, or false otherwise
         %   (condition 3)
  hh     %   Concatenate condition 1, condition 3, and the original copy of
         %   the second piece (condition 2). The resulting vector is truthy
         %   if and only if it doesn't contain any zero
]        % End
1X=      % True if top of the stack is a single 1, false otherwise
```
[Answer]
# Haskell, 66 bytes
Yay, infinite lists!
```
o=[1]:(o>>= \x->[x++map(0-)x,x++x])
f l=l`elem`take(2*2^length l)o
```
Alternative versions:
```
o=[1]:(o<**>map(>>=flip(++))[map(0-),id])
f=Data.List.Ordered.hasBy(comparing length)o
```
[Answer]
# [J](http://jsoftware.com/), 31 bytes
```
e.,.@1(],.~,],.-)^:[~0>.2<.@^.#
```
[Try it online!](https://tio.run/##y/pvqWhlGGumaGWprs6lpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/U/V09BwMNWJ19Op0gISuZpxVdJ2BnZ6RjZ5DnJ7yf02u1OSMfJAGK4U0BaBRYK4hhKtjZYgirWMVb4iiwFBHAUMgHlVPPEINkggWc3QUMFQihLHaA8EICtNyZAPi0TARduLWgs9hRGlHlfsPAA "J – Try It Online")
We build everything and check if the input is a member.
* `0>.2<.@^.#` Tells us how many iterations to build: Base 2 log of the length of the list. This will be the exact number of iterations for truthy cases. To handle non-power-of-2 lengths, we take the floor. To handle empty lists, we take the max with 0.
* `,.@1` Seed the iterations with a table containing just 1.
* `(],.~,],.-)` Build the next iteration per the definition: Input zipped with itself `,.~` catted with `,` the input zipped with its negative `],.-`.
* `e.` Is the input a member of that list?
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 41 bytes
```
f:{$[2>#x;x~,1;{f[x]&|/x~/:-:\y}.2 0N#x]}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6pWiTayU66wrqjTMbSuTouuiFWr0a+o07fStYqprNUzUjDwU66IreXiSotWNIhVqFMwALJ0DEEsQxBL1xAmaKgAFzVU0IWzdaHiBhA2inoFFD1IAgZQQ0AISiCbCVOri4QwdONUQopSJDGw5QB71kIP)
[Answer]
## Haskell, ~~69~~ 68 bytes
```
g x=any(elem x)$scanr(\_->concat.mapM(\y->[y++y,y++map(0-)y]))[[1]]x
```
Usage example: `g [-1,1]` -> `False`.
Even more inefficient than [@flawr's answer](https://codegolf.stackexchange.com/a/106386/34531). It takes too much time and memory for 4 element lists. To see that the list of OVSF codes (with a lot of duplicates) is actually created, try:
```
take 10 $ c $ scanr(\_->concat.mapM(\y->[y++y,y++map(0-)y]))[[1]] [1..4]
```
which returns
```
[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
 [1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1],
 [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
 [1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1],
 [1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1],
 [1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1],
 [1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1],
 [1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1],
 [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
 [1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1]]
```
i.e. the list starts with all 16 element lists (4 times concatenated, because of `[1..4]`), continues with all 8 element lists and so on until it ends with `[1]`.
Edit: @xnor saved a byte. Thanks!
[Answer]
# [Python 2](https://docs.python.org/2/), ~~78~~ 75 bytes
```
def f(x):l=len(x)/2;return[n*x[l]*f(x[:l])for n in x[l:]]==x[:l]>[]or[1]==x
```
[Try it online!](https://tio.run/nexus/python2#nZDNCsMgDMfP21PkIq1FGd3RYV9EcptCQeywHfj2Vi3DCd1lkM9/fskh8akNmD5QYaXVLhW3@8Pr7e2dckNQFoc0VcIiNYsHB7ODpApEKYs8KVy8GnMbMxEyoZBB0lLgJY4MPrkKh7XdN3d4TSfLFeMNd3b4N/nvVjtDcb28/Ow26MgKfAKydkCgD6z8l8Yd "Python 2 – TIO Nexus")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 11 bytes
```
⁽y↔≬y*≈MA=h
```
[Try it online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLigb154oaU4omseSriiYhNQT1oIiwiIiwiWzEsIC0xLCAtMSwgMSwgLTEsIDEsIDEsIC0xLCAxLCAtMSwgLTEsIDEsIC0xLCAxLCAxLCAtMV0iXQ==) or [Test suite.](https://vyxal.pythonanywhere.com/#WyJBIiwiIiwi4oG9eeKGlOKJrHkq4omITUE9aCIsIiIsIltdXG5bMV1cblstMV1cblsxLCAxXVxuWzEsIC0xXVxuWy0xLCAxXVxuWy0xLCAtMV1cblsxLCAxLCAxLCAxXVxuWzEsIDEsIDEsIDEsIDFdXG5bMSwgLTEsIC0xLCAxLCAtMSwgMSwgMSwgLTFdXG5bMSwgMSwgMSwgMSwgLTEsIC0xLCAtMSwgLTEsIDEsIDEsIDEsIDFdXG5bMSwgMSwgMSwgMSwgLTEsIC0xLCAtMSwgLTEsIDEsIDEsIDEsIDEsIDEsIDEsIDEsIDFdXG5bMSwgMSwgMSwgMSwgLTEsIC0xLCAtMSwgLTEsIDEsIDEsIDEsIDEsIC0xLCAtMSwgLTEsIC0xXSJd) Returns 1 for truthy and 0 for falsy.
## Explanation
Essentially compares the odd indices to even indices, then applying it again with even indices, until arriving with an empty list.
```
⁽y          # a lambda that returns the even indices only
  ↔         # apply to the input until empty, returning a new list containing
            #  the values each time it was applied. Includes the input
   ≬        # a lambda that:
    y       #  uninterleaves (pushes odd indices then even indices)
     *      #  multiplies (vectorises)
            #  - in the case that the length of the input is not a power of two,
            #    it pads a 0 to the shorter list
      ≈     #  then checks if all are equal
       M    # map to each element
        A   # check if all are truthy
         =  # is the number equal to the input? (vectorises)
            # - -1 is always 0
            # - 0 never appears in the input
            # - 1 is 1 if it satisfies OVSF code, otherwise 0
            # - an input of [] returns []
          h # get first element
            # - [] outputs 0
            # - [-1,...] outputs 0
            # - [1,...] outputs 1 if it is valid
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 47 bytes
```
{$[x~,1;1;(1=#?x*|x)&c=2*(d:-2!c:#x);o(d#x);0]}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6pWia6o0zG0NrTWMLRVtq/QqqnQVEu2NdLSSLHSNVJMtlKu0LTO10gBUQaxtVxcIVYaigZcCjqGQKwLJAwVwASIqQtm60I4hhAIZ8CUgVVBCBSFUClduByKZiySxClCEtPk4nK1MgCKGYBlDBRgbDCLy7UuTT2ECwD7EjCF)
[Answer]
# JavaScript (ES6), 80
```
f=(l,k=[1])=>l+l==k+k||l[k.length]&&f(l,k.concat(k))|f(l,k.concat(k.map(v=>-v)))
```
Recursively builds and check each list up to the length of the input list, starting with `[1]`.
Return value is JS truthy or falsey, specifically `1` or `true` if valid, `0` or `false` or `undefined` if not valid.
**Test**
```
f=(l,k=[1])=>l+l==k+k||l[k.length]&&f(l,k.concat(k))|f(l,k.concat(k.map(v=>-v)))
test=`[] -> False
[1] -> True
[-1] -> False
[1, 1] -> True
[1, -1] -> True
[1, 1, 1, 1] -> True
[1, 1, 1, 1, 1] -> False
[1, -1, -1, 1, -1, 1, 1, -1] -> True
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1] -> False
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1] -> False
[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1] -> True`
.split('\n')
test.forEach(r=>{
  input = r.match(/-?1/g)||[]
  check = r.slice(-4) == 'True'
  result = f(input)
  console.log(result, check, '['+input+']')
})
```
[Answer]
## Clojure, 118 bytes
```
(defn f[C](or(=(count C)1)(let[l(/(count C)2)[a b](split-at l C)](and(> l 0)(=(count b)l)(apply =(map * a b))(f a)))))
```
Splits input `c` into two halves `a` and `b` and checks if their element-wise products are all identical. If so, checks that the first half is valid sequence.
This one is 142 bytes but I found it more interesting:
```
#((set(nth(iterate(fn[I](mapcat(fn[i][(concat i i)(concat i(map - i))])I))[[1][-1]])(loop[l(count %)i 0](if(< l 2)i(recur(/ l 2)(inc i))))))%)
```
`loop` calculates `log_2` of input's length, `iterate` generates sequences of that many iterations based on the definition. This returns the input argument if it is a valid sequence and `nil` otherwise.
[Answer]
# [Rust](https://www.rust-lang.org), 150 bytes
```
|m|f(m,1);fn f(k:&[i8],u:i8)->bool{let m=k.len()/2;k!=&[]&&(k==&[u]||f(&k[..m],u)&&(&k[..m]==&k[m..]||(f(&k[m..],-u)&&(0..m).all(|i|k[i]==-k[i+m]))))}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=rZLBToNAEIYTj32KaQ9kV3dRPDU0qyefgpAGcWk2LLSBxZgAr-HFSw969-yb6NM4lE1rMa09uAFm4f-_mSX5X16LqjTr9ySHLFI5obWWBhbirTIJn34-N1mTkIx5dIaOhKS-E6hpyCpfTSm_uV8u9QbIROpqifjl9SwdCycIHYekAjdV2GAHJw1cN0OO4nf7gmoaZK6LBrJxdHvGN5YrNFA30po0qkkDhWaO5SILKa62P93X2UeyLIAYWZp5HJWSgXxaydjIh3khy0obCioHJxiBXeRRxuMgBAZJpEtJ2UDxOskU1W-Fe0coBodBFPlR1V4nWKzr4CG4vXfl1OE7lu_Bf448gf_fXvva4NdCqLdtu1T2IfC7lIKAxS4oblTOS61iSSidbZFVoXKj8zGZ1C3U_i0-WiB3NlLYoR7Eq6UTZocIcT4QGTg_gmnz2A9rR-2oj_B63ddv)
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~96~~ 75 bytes
```
+[1].
+L:-append(A,B,L),A\=[],(A=B;A-B),+A.
[]-[].
[A|B]-[C|D]:-C is-A,B-D.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/XzvaMFaPS9vHSjexoCA1L0XDUcdJx0dTxzHGNjpWR8PR1snaUddJU0fbUY8rOlY3Gqg42rHGCchyrnGJtdJ1Vsgs1gXq0XXR@/8/RltBG6SCC2IqF5ivawgV0YEzkIR0oMJgpVA@skIQghIwfShKdZEQLuOwqEG3CLdCJDGgYj0A "Prolog (SWI) – Try It Online")
*-15 bytes thanks to [Steffan](https://codegolf.stackexchange.com/users/92689/steffan)!*
[Answer]
# [Haskell](https://www.haskell.org/), ~~85~~ 82 bytes
*-3 bytes thanks to [@Laikoni](https://codegolf.stackexchange.com/users/56433/laikoni)*
```
f[x]=x<0
f x|n<-length x`div`2,y<-take n x,z<-drop n x=n<1||y/=z&&y/=map(0-)z||f y
```
[Try it online!](https://tio.run/##rVE9a8MwEN39K95Qgg0SjTtLa6du7WYMEbVcmyiysZRENvrvrtLUbaKU0qGg0@npfXBwjTBbqdQ814UruWPrpIbzmlEl9Ztt4DZVe9g8kJFRK7YSGo5MjFZD15/eXLPc@/GeT6tVuHeiT9c0m7yvMc5WGvsqjDTgKBIgLUqCR6GMzMgHzAN@GfYLpHnME0SS8ENvXGfVpZEuujjtfG4yr6jIQz/ru/0wxGUGjeq38D@Y/iHgmlsmDxFlkgyn5dRowTl0Z9HBI21Jl4FRfG0wCHei1UHb7@2zHZ407mCa7hiaUApthWF@Bw "Haskell – Try It Online")
Not too short but efficient.
]