[Question]
  [
Given a multidimensional array, find the recursive alternating sum. An alternating sum is simply the sum of an array, where every other item (starting with the second) is negated. For example, the alternating sum of `[7, 1, 6, -4, -2]` is the sum of `[7, -1, 6, 4, -2]`, or `14`. In this challenge, you'll take the alternating sum of a multidimensional array.
**Task:**
Given an array like this:
```
[
    [
        [1, 2], [2, 4], [4, 8]
    ],
    [
        [-4, -4], [-1, 1], [2, -2]
    ]
]
```
First find the alternating sums of all of the deepest nested arrays:
```
[
    [-1, -2, -4],
    [0, -2, 4]
]
```
Then do this again:
```
[-3, 6]
```
And finally:
```
-9
```
You can choose how input is represented, but it must be able to handle multidimensional arrays of any number of dimensions possible in the language you use. You don't need to support ragged arrays.
**Test cases:**
```
[1]                                                         1
[-1]                                                        -1
[1, 2]                                                      -1
[2, 0, 4]                                                   6
[1, -2]                                                     3
[[1]]                                                       1
[[1, 2], [4, 8]]                                            3
[[-1, -1], [2, 2]]                                          0
[[[[1], [2]], [[4], [8]]]]                                  3
[[[1, 2], [2, 4], [4, 8]], [[-4, -4], [-1, 1], [2, -2]]]    -9
```
**Other:**
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer (per language) wins!
  
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 4 bytes [SBCS](https://github.com/abrudz/SBCS)
```
-/‚ç£‚â°
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=09V/1Lv4UedCAA&f=S1d41DZBIQ1ITnzUu/hR58JHvUse9U31Cvb340pXUI82jFUH07owhqGOghGCqQtjAxXCWSAVOgrRJjoKFnBBXZBiQ5CwEUgaJgzSBxKLBZHRJiASqAchDTMLqMkEYSZIrS6QqQsWAxkNMxnoHqBmAA&i=AwA&r=tryapl&l=apl-dyalog&m=dfn&n=f)
Alternating sum (aka right-reduce by subtraction) along last axis `-/` until convergence `‚ç£‚â°`.
[Answer]
# [Python](https://www.python.org), 58 bytes
```
f=lambda a,s=-1:sum(f(x)*(s:=-s)for x in a)if[]==a*0else a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XVBLCsIwFNx7irdMSh6Y0kUp5CShi4gNBvqjaaE9i5tu9E6ewiuYp1ZpNo_MzJuZJNd7v4yXrl3X2zRazB-FVbVpTmcDRniFsvBTwyybecJ8odBz2w0wg2vBcGd1qZRJjlXtKzDfhGc_uHYMHi1Lzg8_hHsoBaQxgXsmBESYPAJ0JiCPJCS7JDGlpb1ISaSUNHVGM_jjpS09BGT_FnJgOOKbo5qtJdyWIj7P3j7wBQ)
# [Whython](https://github.com/pxeger/whython), 45 bytes
```
f=lambda a,s=-1:sum(f(x)*(s:=-s)for x in a)?a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728PKOyJCM_b8GCpaUlaboWN3XTbHMSc5NSEhUSdYptdQ2tiktzNdI0KjS1NIqtbHWLNdPyixQqFDLzFBI17ROhmt4XFGXmlQCVRRvGampywXm6qFxDHQUjdAFdVBGgAWh8kB4dhWgTHQULNCldkHZDkKQRSBGqJMgkkEwsiIw2AZFA_eiKYKYDDTBB2ALSoQtk6oLFQNbAbAG6FmQExNuwMAMA)
[Answer]
# [Python 2](https://docs.python.org/2/), 50 bytes
```
f=lambda A,*a:(f(*A)if f<A else A)-(a>()and f(*a))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=fVFBCsIwEMSrr9hjUpJDQw9FVMg7QpFIGyzUWjQefIuXXsQ36WvctcTSFLwMm5mdmZDcn93NH06t6vvH1TuZv5TbNPa4Ly1okdgVcyzRvHbg1hqq5lKB5pLZLeO2LQFFy_ngfC923bluPTlMWnC-HI8yOqcC1IyREYUhMUE2ASYTkMeapISUVEVbkUphJBWEJiPEhNlWKMCIbCwii8RRfjkqCj145UkGJaA-QCHMb0bAHDMlxGSb5H_u8M7hpz4)
Expects splatted input. Test harness borrowed from @pxeger.
How?
Hybrid recursion implementing depth first traversal. Detail: `f<A` depends on Python 2's comparability of objects of different types.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 5 bytes
```
ƒã‚Ü∞·µê-|
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3w/0g3kA9k6Nb8/x8dbRirEx0PIgx1FIyAlJGOgoGOgglEIB4kAlQCJsHyCtEmOgoWYIF4kAJDkJARSAokBDYOyI8FkdEmIBKoFiIF028ENh1uDlBdPJAZDxYDGQkzEWg3XCNYHErB1SEJQ81BFwUKomsGKyTKxNhYAA "Brachylog ‚Äì Try It Online")
```
 ‚Ü∞·µê      Recur on each element
   -     then take the alternating sum
ƒã   |    if it's a list, else return it unchanged.
```
[Answer]
# [C++ 20](https://gcc.gnu.org), 87 bytes
```
int f(int a){return a;}int f(auto a){int s=0,i=1;for(auto b:a)s+=f(b)*i,i=-i;return s;}
```
This answer is in the same spirit as [@HatsuPointerKun's](https://codegolf.stackexchange.com/questions/247398/alternating-sums-of-multidimensional-arrays/247460#247460), but it (ab)uses C++ 20's `auto` parameter declaration, which allows us to ditch the whole `#include<vector>` shenanigans (it works with any container).
[Attempt This Online!](https://ato.pxeger.com/run?1=jZTNbqMwFIU33eCnuMosGgZbBZekNIQ8xUhdZKIRJTBCSmGETTZRnmQ23cyyfZ_p09TXNpMSWZ0ssMyF-51zDz-_X4pfu17g8eNnUbyuJ0zIbVYEAQ8nm-c_vaxY8vehbiRUU1xz_9CVsu8ayNOjKee9bLGOZyILaZ1FadV2pv64yH0RZNX00f9aq0usTm2_SI8G_3YlvtRNseu3JSz3ZSHbbkVOlboVsivzpxUh-7begiyF1Fa6UvQ76ZMD8ZTnxaJoewnLpa3j7vp7c52SIyF4-1NeN1Mk6I6bG_imQFDkooR1tLEMI79U969gH0EGB4jgmBJPq1bTfeT7KTlvZ-5-rvvZGMBdgIhyJ-HWOKDAR4xbF4PTkMZOSqwpnEJIIR6BYrcZ5nYzG9ywsZ2Zi6IyPYOcAxVxrok64xFx7iaqHDYU1jGF5AL43QDX8VG1w8YzpTunEsMhI9TiqPl_rcRqmUajxrXuSC1xqmFWKLXBdR3jqub7TPVTN-jn3vghnmfj1YbQDbW12NR0HsQb27x32xzyV4PFp-eAnpnaMl3DAIbg1Gt06RDGuPrkQjRuLQaKFdhHF3A6WFZaQfJxFKNuLmr9f_kzbsf7-AWHOJ399zzbX9w7)
[Answer]
# [flax](https://github.com/PyGamer0/flax), 4 3 bytes
```
-/¬¥
```
[Try It Online!](https://dso.surge.sh/#@WyJmbGF4IiwiIiwiLS/CtCIsIiIsIiIsIltbW1sxLDJdLFsyLDRdLFs0LDhdXSxbWy00LC00XSxbLTEsMV0sWzIsLTJdXV1dIl0=)
Another port of @ovs' APL answer.
*¬Ø1 byte due to update changing direction of fold/scan to match evaluation order*
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 4 bytes
```
 ∑{¬£d
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFZtJJurlLsgqWlJWm6FstOba8-tDhlSXFScjFUaMHN-dGGsVzRuiDCUEfBCEgZ6SgY6CiYQAR0QSJAJWASJK-jEG2io2ABFtAFKTAECRmBpEBCILUgfiyIjDYBkUC1ECmYfiOQ6XBzQOp0gUxdsBjISJiJQLtjYyHuBAA)
```
 ∑      Repeat the following function until it fails:
 {     Start a block
  ¬£d   Convert from base -1; fail if the input is not a list
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 11 bytes
```
({y-x}/|:)/
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs9KortStqNWvsdLU5+JKt0pziE/IsudKV1CKNoxVAtO6MIahjoIRgqkLYwMVwlkgFToK0SY6ChZwQV2QYkOQsBFIGiYM0gcSiwWR0SYgEqgHIQ0zC6jJBGEmSK0ukKkLFgMZDTMZ6B6gZgCKwjFE)
Port of @ovs' APL answer.
[Answer]
# [Haskell](https://www.haskell.org/) + [free](https://hackage.haskell.org/package/free-5.1.7/docs/Control-Monad-Free.html#v:iter), 14 bytes
```
iter$foldr(-)0
```
[Try it online!](https://tio.run/##fVA9b4MwFNz5FW9Aqi0VKSWt1ESFqYrUqR26Vahyg12sgEHGtBny3@nzB2mQIgbAd@/e3ZmK9Qde12OSwAmeuZBKqm8wleyh4ppDL9WeI@YgNOfQtOVQc5C9ujHAfpis2RfiVsH7y2tUMsNgZ3UCWASQwduAHvZ48jwRQCYBpVEkVW8YJqCCwG5Qe9NqEIgoPmiQn8mwZvlf28zNRcM6tCIu5kghcyz42Bgnx5nMWVzIHI79mHgRxZVIGq5hu/0vZItgdQZJjr3te7qEY/zCZ@iBgmziukqG2MayDp4HT3GO9Cgyy8SirUtNEroaGyZVVrZYstNSGXcRb/LhAu4Kem12nfUbt/6XpAuaNGgewne97DfrM4PphGaSoljucCFeB@X93HcT6MeioOMf "Haskell ‚Äì Try It Online")
We need the free library to represent arbitrarily nested lists. This code works on any ragged list as well. `foldr(-)0` computes the alternating sum of a flat list and `iter` applies it recursively to a free monad.
[Answer]
# [R](https://www.r-project.org), ~~51~~ 48 bytes
*Edit: -3 bytes thanks to [@Dominic van Essen](https://codegolf.stackexchange.com/users/95126/dominic-van-essen).*
```
f=\(l)"if"(is.list(l),Reduce(`-`,Map(f,l),,T),l)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGCpaUlaboWNw3SbGM0cjSVMtOUNDKL9XIyi0uAXJ2g1JTS5FSNBN0EHd_EAo00HaCYTogmkILou8XMl6YBVmyoqamsQC4w5IKaokuJMbpwYwx1FIzINghhjJGOgoGOggl5JpkhOUaXbNcYw0yBBTLZwWOIahIohHQUwGwTHQULUg1GdZcuyI-GMPOMwKFPinkGKKYh-xdmpCaMBXExjAdyN1E2GWPagBwERqBoRgkOZOt0gUK6cHmQZ5H9CopcqBt0LSHZApatAA)
Takes input as a list of lists.
---
Old version:
```
f=\(l)"if"(is.list(l),sapply(l,f)%*%-(-1)^seq(l),l)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGCpaUlaboWN43TbGM0cjSVMtOUNDKL9XIyi0uAXJ3ixIKCnEqNHJ00TVUtVV0NXUPNuOLUQpBUjiZE6y1mvjQNsHpDTU1lBXKBIRfUFF1KjNGFG2Ooo2BEtkEIY4x0FAx0FEzIM8kMyTG6ZLvGGGYKLJDJDh5DVJNAIaSjAGab6ChYkGowqrt0QX40hJlnBA59UswzQDEN2b8wIzVhLIiLYTyQu4myyRjTBuQgMAJFM0pwIFunCxTShcuDPIvsV1DkQt2gawnJFrCcBQA)
Takes input as above. Outputs a \$1\times1\$ matrix.
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 33 bytes
```
f(a)=if(#a',f(a[1])-f(a[^1]),a,a)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XVBBCgIxDPxKXA-2kIAtPexFP7Ko5FIpiJRlPfgWL3sRP-MH_I1pmwWxh2QynUzSPl6Zx3Q653l-3qZI_WcVDdtdimbNGxQ8uIOlko8CkJGtCt-c8-VuGGgPeUzXSWBXig6KhUUYpFci1egQfMkeYYsQlKLKia4l1QSEvjFUNE77fOPUVqvqJGq9-xkT_qwEUmgLISyesoAcfdPyCV8)
```
f(a)=if(#a',f(a[1])-f(a[^1]),a,a)
f(a)=                                Define a function `f` with argument `a`:
     if(#a',                         If the length of `a`'s derivative is nonzero,
                                       so `a` is a nonempty list:
            f(a[1])                    apply `f` to the first element of `a`,
                   -                   minus
                    f(a[^1]),          apply `f` to `a` with the first element removed.
                             a,      Otherwise, if `a` is truthy,
                                       so `a` is a nonzero integer:
                               a       return `a`.
                                )    (Implicitly) Otherwise, return 0.
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 25 bytes
```
Fold[#2-#&]@*Reverse//@#&
```
[Try it online!](https://tio.run/##PU29CsMgEN59DcGheISIQ5cWp879GUMGSQ0VmgRS2@Uwr25PLV3u4/u9yYaHm2zwg03jIZ2W573jCrjoze7qPm59uaYxXKTL27tgzqufQ8fhOBrei@022HlDhm2UDKHcVqoKUJCsCllGLfeVAvkUR0VyEXKQKBFETYdyP6M2ldT/PtW1hMxppq7QsxhZTF8 "Wolfram Language (Mathematica) ‚Äì Try It Online")
Right-fold subtraction on every level. Supports ragged arrays.
[Answer]
# Haskell + [hgl](https://gitlab.com/WheatWizard/haskell-golfing-library), 9 bytes
```
itr$lH(-)
```
## Explanation
Seeing how short my [haskell answer](https://codegolf.stackexchange.com/a/247445/56656) turned out I couldn't help but port it to hgl. This works *basically* the same.
It takes input as a free monad of lists, that is a ragged list. `lH(-)` is equivalent to the haskell `foldl1(-)` and calculates the alternating sum of a flat list. We use it with `itr` to recursively reduce a ragged list.
## Reflection
This is pretty tight as far as things go.
It feels clunky to use `(-)` here but the alternative is `fsb` which would lose a byte due to spacing. In order for it to save bytes `fsb` would have to be 1 byte long.
The one thing that seems like it could be worthwhile would be an alternating sum builtin. It would probably save 2 bytes here.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 15 bytes
```
{0==ùï©?ùï©;ùïä-Àù‚éâ1ùï©}
```
Anonymous function. Takes a multidimensional array, returns a [0-dimensional array](https://mlochbaum.github.io/BQN/doc/enclose.html#whats-a-unit) containing a number.
### Explanation
```
{0==ùï©?ùï©;ùïä-Àù‚éâ1ùï©}
{              }  Anonymous function:
   =               Rank (number of dimensions) of
    ùï©              the argument
 0=                equals zero?
     ?             If so:
      ùï©             Return the argument unchanged
       ;           If not:
          Àù         Right fold
         -          on subtraction
           ‚éâ1      the innermost axis of
              ùï©     the argument
        ùïä           and call this function recursively on that array
```
[Answer]
# [Java 17](https://en.wikipedia.org/wiki/Java_(programming_language)), 101 bytes
```
int f(Object[]a){int s=0,m=-1;for(var i:a)s+=(m=-m)*(i instanceof Long j?j:f((Object[])i));return s;}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=nVNBboMwEFTVW16xR7s1UUA5oCDUD7jqIccoB4fayAhMhA1VhfKSXji0T-hj2tfUQBKlqKlCTpZnxjOzK_ntPWEVaz6jlGkNj0wqqCcA2jAjo4_SCMf_4lIZEOhpk_DIrNYM1y2gwxnJQscNRF6gihUgFwzr-xBZMMN3SIJU1kZFPBdAcxVD8pAsBDr6YIlxUHBTFgp0sOvDvm9vALblJpXRvgRUuXyGzDZDS1NIFa_WwIpY464owPJVG55N89JMt5Y2qUICKf4Ch5zapTubdKHYGaV2KfHG6D1KZpTMR0Y4ozKGs1__lIANJvALnVPiX-_ptKbtigeuXrfHEa6dDOAv7Bw6wNsS5zjb5UidqC7ynf_j659yh4j-7GaftLf9T2ia_vwB)
Java 17+ is required for pattern matching; this is probably the first time it is useful in a golf :).
[Answer]
# [Arturo](https://arturo-lang.io), 52 bytes
```
f:$[a][(block? a)?->([]=a)?->0->-f a\0f drop a 1->a]
```
[Try it](http://arturo-lang.io/playground?A6TCrA)
[Answer]
## C++, ~~194~~ ~~147~~ ~~141~~ 130 bytes
-17 (6+11) bytes tanks to ceilingcat
[TIO Link](https://tio.run/##lZPLboMwFET3@QpLVSVI7AY7zpOYr8gOsUAUKqS8BC6LIr49HYcmreo4TbO4Ctf4zHiuyY5H9pZlp9NTuTseKr1u8kwfqmhQ7jUpPFNTv61y/V7tSRp2Ot8dt6nO19k2rWuyifr3av26WvVb15sIO0y7VgEtVRAWh8oLy3X6UpcfueeHfs1U4aVxmfhDrxyNnsVQMO6HXyp12F3dZBDJKx0Ndmm59/x2QPAbj8kmrzXBYk5inpybPx1APGq4ankXntd6iFd4DfeVgtLgBoe5QEK1zCYJkJgDxalwsCYwRYUFm1xgpn0DKGhApQMpVXtetqAS0JnLIHM5nBqHzLY4BW1ym4YRJEQRbgF/w6NmplpMxYLP3GOBVyISSmJJySJJHtCYGw2ETFtJF7bW/M5BGMRwD6hJHKqPqC2ghm24IRRzELbeAnqBQ89EZ8QSU2NpKs74h@5dP3C0hCOTMvx0KK1EQQ62s@WdJK6xIwj5Hb@xyfCXnXsmrktauFD/8N17bXhgvPbDElReRgbTEGHmGRJ9sriS9gl4YD6cJc7QnT4B)
This code uses templates to have any kind of vectors as input ( `vector<int>`, `vector<vector<int>>`, `vector<vector<vector<int>>>` ... )
The code :
```
#import<vector>
int f(int a){return a;}template<class T>int f(std::vector<T>a){int s=0,i=1;for(auto x:a)s-=f(x)*(i*=-1);return s;}
```
Here's the code for testing :
```
int main() {
    // Test case [1]
    std::vector<int> v1 = { 1 };
    assert(f(v1) == 1);
    // Test case [-1]
    std::vector<int> v2 = { -1 };
    assert(f(v2) == -1);
    // Test case [1,2]
    std::vector<int> v3 = { 1,2 };
    assert(f(v3) == -1);
    
    // Test case [2,0,4]
    std::vector<int> v4 = { 2,0,4 };
    assert(f(v4) == 6);
    // Test case [1,-2]
    std::vector<int> v5 = { 1,-2 };
    assert(f(v5) == 3);
    // Test case [[1]] = 1
    std::vector<std::vector<int>> v6 = { {1} };
    assert(f(v6) == 1);
    // Test case [[1, 2], [4, 8]]
    std::vector<std::vector<int>> v7 = { {1,2}, {4,8} };
    assert(f(v7) == 3);
    // Test case [[-1, -1], [2, 2]]
    std::vector<std::vector<int>> v8 = { {-1,-1},{2,2} };
    assert(f(v8) == 0);
    // Test case [[[[1], [2]], [[4], [8]]]]                                  3
    std::vector<std::vector<std::vector<std::vector<int>>>> v9 = { {{{1},{2}},{{4},{8}}} };
    assert(f(v9) == 3);
    // Test case [[[1, 2], [2, 4], [4, 8]], [[-4, -4], [-1, 1], [2, -2]]]
    std::vector<std::vector<std::vector<int>>> v10 = { {{1,2},{2,4},{4,8}},{{-4,-4},{-1,1},{2,-2}} };
    assert(f(v10) == -9);
}
```
[Answer]
# [Uiua](https://uiua.org), 9 [bytes](https://codegolf.stackexchange.com/a/265917/97916)
```
‚ç•(/-‚áå)‚ßª‚ñ≥.
```
[Try it online!](https://www.uiua.org/pad?src=ZiDihpAg4o2lKC8t4oeMKeKnu-KWsy4KZiBbMV0KZiBbwq8xXQpmIFsxIDJdCmYgWzIgMCA0XQpmIFsxIMKvMl0KZiBbWzFdXQpmIFtbMSAyXSBbNCA4XV0KZiBbW8KvMSDCrzFdIFsyIDJdXQpmIFtbW1sxXSBbMl1dIFtbNF0gWzhdXV1dCmYgW1tbMSAyXSBbMiA0XSBbNCA4XV0gW1vCrzQgwq80XSBbwq8xIDFdIFsyIMKvMl1dXQojIDEgYDEgYDEgNiAzIDEgMyAwIDMgYDkK)
Similarly to BQN and K, alternating sum in Uiua requires a reverse before reduction by subtraction. Uiua doesn't have "converge" builtin, and "do while" isn't a good fit here because getting the iteration count directly is cheap.
```
‚ç•(/-‚áå)‚ßª‚ñ≥.    input: a possibly multidimensional array
       ‚ßª‚ñ≥.    keep input and push number of dimensions
‚ç•(    )        repeat that many times:
   /-‚áå         alternating sum over the leading axis
```
[Answer]
# [Julia 1.0](http://julialang.org/), 24 bytes
```
!x::Int=x
!x=!foldr(-,x)
```
[Try it online!](https://tio.run/##pZDBasQgEIbvPsUYyqKgoaY5tAv21kMPfQLJwTQuuIgbTHYRSp89dRq6vXZTD4OMfP984/EcvFV5WWje71/jrDOhWdPDKQyJSZH5Qg6nBB58hOTsEHx0E@MEyrGiBw3uYkPN3txs69GmydVsGoOfmReQKvhoxGfF@QqMycc5RGZBPwO1a5NaoBp62O2u79VLHt377Aa46ytOXBwWozrYehQxcjsuC64ENN2/cLmRfyCmrN5t33x1F2BaAY@3BeFsie4K@QZzbuDvC43uiHZYTYu1OPwlBWdf1cvo9ncFjJLlKr97KPjjVz55zZZPXw "Julia 1.0 ‚Äì Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 35 bytes
```
‚äûœÖŒ∏Ôº¶œÖÔº¶Œ¶Œπ‚Å∫‚ü¶‚üßŒ∫‚äûœÖŒ∫Ôº¶‚ÆåœÖ‚äûŒπ‚Ü®Ôº•‚ÆåŒπŒ£‚Å∫‚ü¶‚Å∞‚üß‚äüŒπ¬±¬πÔº©Œ∏
```
[Try it online!](https://tio.run/##PYzNDoIwEITvPMUet0mbCOFgwk0Tb5pGjw2HhlRpQIH@8Pp1QXAuuzO73zStds2g@5Rk9C1GDhOrsufgACODdV5sH4xDy0H20aOqOXSMMdiBbgfuZjbOGwK3IyEnTcFVj/@jZRwe8Y2/rgOVyWGklFF@My8dDOZkqkw6@wl41j7gRD4lRco5FISogkO5zJLDsV4WJWgVayboKd@eRFGTkpj7Lw "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
‚äûœÖŒ∏Ôº¶œÖÔº¶Œ¶Œπ‚Å∫‚ü¶‚üßŒ∫‚äûœÖŒ∫
```
Get all of the sublists of the input.
```
Ôº¶‚ÆåœÖ
```
Loop over the sublists in reverse, i.e. from deepest back up to the original input.
```
‚äûŒπ‚Ü®Ôº•‚ÆåŒπŒ£‚Å∫‚ü¶‚Å∞‚üß‚äüŒπ¬±¬π
```
Remove all the elements of the sublist in reverse order, convert them from integers or sublists to integers, then interpret them as base `-1` to obtain the alternating sum, and push the result back to the sublist.
```
Ôº©Œ∏
```
Output the final result.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
"√êÀú√äi¬ÆŒ¥.V}.¬´-"¬©.V
```
As always, 05AB1E and recursive functions are not a good match..
[Try it online](https://tio.run/##yy9OTMpM/f9f6fCE03MOd2UeWndui15Yrd6h1bpKh1bqhf3/Hx0dbahjFKsTbaRjAiRNdCxigVS0romOLoiva6hjCJbUNYqNjQUA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeV/pcMTTs853JV5aN25LXphtXqHVusqHVqpF/Zf5390tGGsjkK0Lpg01DECUUY6BjomEL4uWMBcx1DHTEfXBMoFaoFQIOXRJjoWEK4uUDnQGKB2I4gA2OxoECc6GmheNFAdVAKi0whkC1Q/UDvQeBAfaAzEFKBlQAAA).
**Explanation:**
```
"..."        # Create the recursive-string explained below
     ¬©       # Store it in variable `¬Æ` (without popping)
      .V     # Evaluate and execute it as 05AB1E code
             # (after which the result is output implicitly)
             #
√ê            # Triplicate the current list
 Àú           # Flatten the top copy
  √äi         # If the top two lists are NOT equal (so there is an inner list):
     Œ¥       #  Map over each inner item:
    ¬Æ .V     #   Do a recursive call
   }         # After the if-statement, whether we've executed it or not
    .¬´       # Right-reduce the list by:
      -      #  Subtracting
```
[Answer]
# [Factor](https://factorcode.org/), 73 bytes
```
: f ( s -- n ) dup array? [ [ 0 ] [ unclip f swap f - ] if-empty ] when ;
```
[Try it online!](https://tio.run/##XZAxD4IwEIV3fsUbdaiRhsHg4GhcXIyTcWiwKBFrbUsIIfx2PAqo2Da9d/eu3yVNReKepj0edvttDGGMqCzu0iiZw8pXIVUiLR7C3aCNdK7SJlMO62C3j3F95mkbI8UMFoxBYY5LoXvMBifaS5zpLlSSZ5oabSm6wKiapUw@tKtIljepsG7rALRqhGgGxb4yBP9oTtjox2Ffy7@eZORRjLCa1IncwT2MT5yRUfd1n0c@esJf78jnQ88wp58Rdafpp41IxgdGEwQn@oozfa6GdSK5L9o3 "Factor ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
≈íJ‚Äô¬ß-*·∏ãF
```
[Try it online!](https://tio.run/##y0rNyan8///oJK9HDTMPLdfVerij2@3/4XbNyP//ow1jdaJ1QYShjhGQNNIx0DEB83RBXKA0mATLmehYgHm6QElDsFojMD8abAiEDdILVAURhxlpgqzZREfXBGynDsQMoD0w1SAxHagEnA2yC2orQkAHRTXEibh1xwIA "Jelly ‚Äì Try It Online")
```
≈íJ          Enumerate the multidimensional indices of every element, in flat order.
  ‚Äô         Decrement each dimension (indexed from 1) of each index.
   ¬ß        Sum each index,
    -*      and raise -1 to the power of each sum.
      ·∏ãF    Take the dot product of that with the flattened input.
```
# [Jelly](https://github.com/DennisMitchell/jelly), ~~10~~ 9 bytes
```
√ü‚Ç¨≈í·∏ä¬°U_@/
```
[Try it online!](https://tio.run/##y0rNyan8///w/EdNa45Oerij69DC0HgH/f@H2zUj//@PNozVidYFEYY6RkDSSMdAxwTM0wVxgdJgEixnomMB5ukCJQ3Bao3A/GiwIRA2SC9QFUQcZqQJsmYTHV0TsJ06EDOA9sBUg8R0oBJwNsguqK0IAR0U1RAn4tYdCwA "Jelly ‚Äì Try It Online")
```
√ü‚Ç¨           Recur on each element of the argument
    ¬°        as many times as
  ≈í·∏ä         its depth.
     U       Reverse the list of results (or do nothing to the scalar argument)
      _@/    and left-reduce by reversed subtraction.
```
Previous solution was `√ü‚Ç¨N√êeS¬µ)∆ë¬°`. Gaze upon it and despair.
[Answer]
# JavaScript (ES6), 46 bytes
```
f=a=>1/a?+a:a.map(n=>p-=(a=-a)*f(n),p=0,a=1)|p
```
[Try it online!](https://tio.run/##rdKxDoIwEAbg3afo2GoPKBKjJsUHIR0uCEaD0Ihx8t2RE2UAiUro0DQdvvx/rye8YRlfjvYKebFPqirVqEPl4m6BW3TOaHmuQwuaowYU85TnQlrtSdRK3G0VF3lZZImTFQee8kgZNmYJwVyXqVlHg3Fco0GPU5L5ZjrOl8yTLDCjuNWHcDAiXaMtu1o9CDPdHJqXkywKJFv/Dg9lA@qqyPPJNf9oXk@jrkQZ2qOA9jrjN3UoW1vVp9G2lYmG@gjPOyrwzl8PzZjXF9lUDw "JavaScript (Node.js) ‚Äì Try It Online")
Or **43 bytes** with optional chaining (ES11), as suggested by @MatthewJensen:
```
f=a=>a.map?.(n=>s-=(a=-a)*f(n),s=0,a=1)?s:a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ndMxDoIwFAbgwc3BM3RstQ8oEoMmhYOQDo2KC4IJehoXBj2UnkaeFQaQiGVoSBO-_H8fvd7yYrevqvvlnEL4WKRSy0g7R32KHZrLqARJtQTN5inNGS-lx7UULC432nzynMy2RV4W2d7JigNNaSIUsXkYI65LxLSjgR1nNOhxghPfAhzifE48ToJ_RcOtvoQDi3RGW3a1ehA2RzcwB3NynCQBJ-F4eCgbYFeBno_uSM9oXk_DrkgpXJMA1zrjL3UoW1vVx9G2lZGG-hXee1igyV8PTanPL7I216K5US8)
[Answer]
# [J](http://jsoftware.com/), 7 5 bytes
```
-/^:_
```
[Try it online!](https://tio.run/##VY1BCsIwEEX3nuIjhRpIYzMNYgNdCa5ceQBnIRbpxvuv4iRTSkomiz@P/2ZJR9fOmCJaWPSI8juH2/NxT935FTmZw@f9/cFjwgzrNfEaeZ89SPOlRBJZ0MWwcqadzvkak7wmSxBwVdBXQI5whlR3TuIAGdgotq3Go8IB1JSKGAUaG/OGA/L4coop/QE "J ‚Äì Try It Online")
*-2 thanks to Bubbler*
Just a J translation of the APL answer, for completeness.
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 66 bytes
```
lambda n:n*0==0and n or sum((1-i%2*2)*f(e)for i,e in enumerate(n))
```
[Try it online!](https://tio.run/##pZLPToQwEMbvfYq5mLab1lCWw4rhSbocqpTYBErDH6NPjzOL6NVFDg2dye@bb5ovfc5vQzxf0ri21XXtXP/SOIhlPGVVlbnYQIRhhGnphTA6POSnXJ5a4WWL1aA8hAg@Lr0f3exFlHINMS3zBBVwzpk1NRz9DLP6OK4RNwry@l@4PsifmcXV6@Obb94V2ELB5T4hmq3JuyE@J507@Axp8k5oTact6EQPf1Gh2T/WcXTxuwJJafzVtxoZ3P3hI2/a@olhaKwp0frjlLowC36NXLJb2GKisG3xKhmGDwZMmXVAXffd2zEALiG04GoGaQxxFv7ddSJIBbzkCtr9ToVn8B/Jv86@odYg1y8 "Python 3.8 (pre-release) ‚Äì Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 108 bytes
```
\d+(?<=((])|(?<-2>\[)|(?(2).|((,)|.)))*)
$#4$*-$&
--
O^`-?\d+
(-)|\d+|.
$*1$1
1>`-
(1+)-\1
-
r`(1*)-?$
$.1
```
[Try it online!](https://tio.run/##VY2xDsIwDER3f0UkArLbuMJRBgagIyMfkAYVCQYWhoox/17sIpBYzs6782W6vx7P67zG0zgPtxb7/QGxUNWF43HItmGkriIGqh0RNQR@lXzDfgPMAOfLyL2eAjJVnbUD34gXkOOoNkpLPAgwTCNKQ9x78J3Mc5YCmU0kuKgjBrcNLn0AG9HIouYHl1NwuwWwBcRQNMuQZe1dTHMy1ezfebTyX43FWFdemDV@C/XrUt4 "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Explanation:
```
\d+(?<=((])|(?<-2>\[)|(?(2).|((,)|.)))*)
$#4$*-$&
```
Negate each value a number of times given by the sum of its multidimensional indices.
```
--
```
Simplify any double negations.
```
O^`-?\d+
```
Sort the negative numbers to the end.
```
(-)|\d+|.
$*1$1
```
Convert the values to unary but delete everything else that isn't a `-`. This sums the positive values together.
```
1>`-
```
Sum the negative values together.
```
(1+)-\1
-
```
Take the difference between the positive and negative values.
```
r`(1*)-?$
$.1
```
Convert to decimal, ignoring any trailing `-`.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 6 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
-¬¥‚öá1‚çü‚â°
```
`-¬¥`‚ÄÉalternating sum
`‚öá1`‚ÄÉat depth 1 (simple lists)
`‚çü‚â°`‚ÄÉrepeated as many times as the depth of the argument
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RuKGkC3CtOKahzHijZ/iiaEKRiDin6jin6jin6gxLDLin6ks4p+oMiw04p+pLOKfqDQsOOKfqeKfqSzin6jin6jCrzQswq804p+pLOKfqMKvMSwx4p+pLOKfqDIswq8y4p+p4p+p4p+p)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 12 bytes
```
Œª‚àëu$e;‚Ç¨f?f√û‚Ä¢
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLOu+KIkXUkZTvigqxmP2bDnuKAoiIsIiIsIltbWzEsIDJdLCBbMiwgNF0sIFs0LCA4XV0sIFtbLTQsIC00XSwgWy0xLCAxXSwgWzIsIC0yXV1dIl0=)
This is like, really, really, really bad.
[Answer]
# [Scala](http://www.scala-lang.org/), 100 bytes
Golfed version. [Try it online!](https://tio.run/##fU89a4QwGN79Fe@YtEk5xeHQRuhYSKej03GUaNVGNLZJOCjib7dRi8hVmyV5PnliMlGLoU2rPLPwIqSCzvOuooYiOuVf57cLS56VBTYIlnRXoZEhDWboQKiP46LVSD5SgbuGAW1iCY2w2UeXCZNDFfFWlSwx96y5qx5s63riSUmX6kkrUIr7PjZxPwC854UrkQoJXZoInrQW3@eT1VKVFxzBq5JujNsI7nw61tYKFcj1IZ9jjDd4uif4nAQ7UsDJgZNwP0j3ksuSfZGACxMYQcjJ8T8zHd3jB2Z78Lt4yz5RAKvnDZjh2HVDucqFWYkb4fBv@LgOe@t7ntl7vTf8AA)
```
a=>{var(s,m)=(0,-1);for(i<-a){m= -m;i match{case j:Long=>s+=m*j.toInt;case b:Seq[_]=>s+=m*f(b)}};s;}
```
Ungolfed version. [Try it online!](https://tio.run/##hVDLToQwFN33K86yVTADYTEhYuLSpK6MK2NMRUDIUExpTIzh27FAeWVg3FDOPY/e0zoWJ9G21XuRxBqPIpf4JcBHkiKlIsS9UuLn5e2VhXiQGlHPAt9CoTboMKHSINfrYVop0By3LgSzegx8aUGOUuj4cyKBWNQJihC8khmiOxN@HRnPFYobXZmb10Kh1LzaSm6WVopZdUPmb026P1utND2NMKvHlCetcpl1LZ9lPtf8MlN9kjSlvYx6nDG2ybj7lMcdf5f0uXPgTnDJ7O67F1tdFjgwIc5QlgbcOf5ncTtPV2o0@bbFtsk@@AqcwXHQpZ4NTfg0W9A7EcFWxHEZQZbnsHZDGtK2fw)
```
object Main {
  def f(a: Array[_]): Int = {
    var s = 0
    var m = -1
    for (i <- a) {
      m = -m
      i match {
        case j: Long => s += m * j.toInt
        case arr: Array[_] => s += m * f(arr)
      }
    }
    s
  }
  def main(args: Array[String]): Unit = {
    println(f(Array(1L)))
    println(f(Array(-1L)))
    println(f(Array(1L,2L)))
    println(f(Array(2L,0L,4L)))
    println(f(Array(1L,-2L)))
    println(f(Array(Array(1L))))
    println(f(Array(Array(1L, 2L), Array(4L,8L))))
    println(f(Array(Array(-1L, -1L), Array(2L,2L))))
    println(f(Array(
      Array(
        Array(
          Array(1L),
          Array(2L)
        ),
        Array(
          Array(4L),
          Array(8L)
        )
      )
    )))
  }
}
```
]