J, 86 62 54 49 47 42 41 4037 bytes
_2&(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#]\)~1<#
Try it online!Try it online!
f =: _2&(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#]\)~1<#
f 1 1 1 1
4 0 0 0
f 1 2 3 4
10 _2j2 _2 _2j_2
f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661
_2&(0((+,-)]%_1^i.@#%#)&$:/@|:_2]\])^:(1<#]\)~1<# Input: x
array A
1<# Is the input length is# greater than oneLength
^: 1< Greater Ifthan true,one?
_2&( ] )~ Execute this if true, else Getreturn xA
_2 _2]\ ]\ Split xGet intonon-overlapping sublists of lengthsize 2
0 0 |: |: Move Transposeaxis it0 to getthe [even-indexend, odd-index]
equivalent to transpose
/@ by movingReduce axis[even-indexed, 0odd-indexed]
to the end
&$:/@ Call recursively on each list
# # Get the length of the odd list
i.@ i.@ Range from 0 to that length exclusive
%# %# Divide each value by thatthe odd length
_1^ _1^ Compute (-1)^x for each x in it
% ] Divide each value inGet the odd list
] % Divide byeach ain valuethat inby the previous elementwise
+ + Add elementwise between the even values
and modified odd values
- - Subtract elementwise between the even
values and modified odd values
, , Join the two lists and return
Else
Return x (act as identity function)