[Question]
  [
Given a non-negative integer \$n ,\$ output the \$n^{\text{th}}\$ [Euler number](https://en.wikipedia.org/wiki/Euler_number) ([OEIS A122045](https://oeis.org/A122045)).
All odd-indexed Euler numbers are \$0 .\$ The even-indexed Euler numbers can be computed with the following formula (\$i \equiv \sqrt{-1}\$ refers to the imaginary unit):
$$
E\_{2n}
= i
\sum\_{k=1}^{2n+1}{
 \sum\_{j=0}^{k}{
 \left(\begin{array}{c}k \\ j \end{array}\right)
 \frac{{\left(-1\right)}^{j} {\left(k-2j\right)}^{2n+1}}{2^k i^k k}
 }
}
\,.
$$
## Rules
* \$n\$ will be a non-negative integer such that the \$n^{\text{th}}\$ Euler number is within the representable range of integers for your language.
## Test Cases
```
0 -> 1
1 -> 0
2 -> -1
3 -> 0
6 -> -61
10 -> -50521
20 -> 370371188237525
```
  
[Answer]
# Mathematica, 6 bytes
```
EulerE
```
-cough-
[Answer]
# [J](http://jsoftware.com/), 10 bytes
```
(1%6&o.)t:
```
[Try it online!](https://tio.run/nexus/j#@5@mYGuloGGoaqaWr6dZYsWVmpyRr6Cho5emZKCpUGGlYKBgqGCkYKxgpmBooGBk8P8/AA "J – TIO Nexus")
Uses the definition for the exponential generating function sech(x).
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 9 bytes
```
eulerfrac
```
This built-in was added in version 2.13.0, after this challenge was asked.
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMHiNAXbpaUlaboWK1NLc1KL0ooSkyH8mypp-UUaeQq2CgY6CkZAXFCUmVcCFFBS0LUDEmkaeZqamhC1CxZAaAA)
---
# [PARI/GP](https://pari.math.u-bordeaux.fr), 24 bytes
```
n->2*imag(polylog(-n,I))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMHiNAXbpaUlaboWO_J07Yy0MnMT0zUK8nMqc_LTNXTzdDw1NSHSN1XS8os08hRsFQx1FIwMdBQKijLzSoACSgq6dkAiTSNPE6Z2wQIIDQA)
---
# [PARI/GP](https://pari.math.u-bordeaux.fr), 32 bytes
```
n->n!*Vec(1/cosh(x+O(x^n++)))[n]
```
This is the original answer.
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMHiNAXbpaUlaboWNxXydO3yFLXCUpM1DPWT84szNCq0_TUq4vK0tTU1NaPzYqHqVNLyizTyFGwVDHQUjIC4oCgzrwQooKSgawck0jTygMohahcsgNAA)
[Answer]
# Maple, 5 bytes
```
euler
```
Hurray for builtins?
[Answer]
# [Maxima](http://maxima.sourceforge.net/), 5 bytes / 42 bytes
Maxima has a built in:
```
euler
```
[Try it online!](https://tio.run/nexus/maxima#@5@mkadpZZucn5qWplGSWJmTX6RRnJqcoVGhqVOhY6CTp6mVpwhk5Wla/y8oyswr0UjTsNAEcgA "Maxima – TIO Nexus")
The following solution does not require the built in from above, and uses the formula that originally defined the euler numbers.
![](https://wikimedia.org/api/rest_v1/media/math/render/svg/bef01280cc39c7321fbfc295a5babae89a6ed906)
We are basically looking for the n-th coefficient of the series expansion of `1/cosh(t) = sech(t)` (up to the `n!`)
```
f(n):=coeff(taylor(sech(x),x,0,n)*n!,x,n);
```
[Try it online!](https://tio.run/nexus/maxima#@5@mkadpZZucn5qWplGSWJmTX6RRnJqcoVGhqVOhY6CTp6mVpwhk5Wla/y8oyswr0UjTsNAEcgA "Maxima – TIO Nexus")
[Answer]
# Mathematica, without built-in, 18 bytes
Using [@rahnema1](https://codegolf.stackexchange.com/a/107591/9288)'s formula:
```
2Im@PolyLog[-#,I]&
```
---
**21 bytes:**
```
Sech@x~D~{x,#}/.x->0&
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~70~~ ~~46~~ 44 bytes
```
F=(a,b=a)=>a?F(--a,b)*~b+F(a,b-=2)*(a-b):+!b
```
[Try it online!](https://tio.run/##HY2xDsIwDER3vsJsdlMj1JFi2PIfTgkoKKpRCh359ZAy3b2Tnu6pqy5TSa83z3aLNX5yLCBQvaD2QZTkolePzI2o@wbnt51loA6VA53cPtS7FcBVC6SmHscWZ4FhK87RDiabF8vxkO2BqYf/Byaisf4A "JavaScript (Node.js) – Try It Online")
Surprised to find no JavaScript answer yet, so I'll have a try.
The code consists of only basic mathematics, but the mathematics behind the code requires calculus. The recursion formula is derived from the expansion of the derivatives of \$\mathrm{sech}(x)\$ of different orders.
### Explanation
Here I'll use some convenient notation. Let \$T^n:=\mathrm{tanh}^n(t)\$ and \$S^n:=\mathrm{sech}^n(t)\$. Then we have
$$\frac{d^nS}{dt^n}=\sum\_{i=0}^nF(n,i)T^{n-i}S^{i+1}$$
Since \$\frac{dT}{dt}=S^2\$ and \$\frac{dS}{dt}=-TS\$, we can deduce that
$$
\begin{equation}
\begin{aligned}
\frac{d}{dt}(T^aS^b)&=aT^{a-1}(S^2)(S^b)+bS^{b-1}(-TS)(T^a) \\
&=aT^{a-1}S^{b+2}-bT^{a+1}S^b
\end{aligned}
\end{equation}
$$
Let \$b=i+1\$ and \$a=n-i\$, we can rewrite the relation above as
$$
\begin{equation}
\begin{aligned}
\frac{d}{dt}(T^{n-i}S^{i+1})&=(n-i)T^{n-i-1}S^{i+3}-(i+1)T^{n-i+1}S^{i+1}\\
&=(n-i)T^{(n+1)-(i+2)}S^{(i+2)+1}-(i+1)T^{(n+1)-i}S^{i+1}
\end{aligned}
\end{equation}
$$
That is, \$F(n,i)\$ contributes to both \$F(n+1,i+2)\$ and \$F(n+1,i)\$. As a result, we can write \$F(n,i)\$ in terms of \$F(n-1,i-2)\$ and \$F(n-1,i)\$:
$$F(n,i)=(n-i+1)F(n-1,i-2)-(i+1)F(n-1,i)$$
with initial condition \$F(0,0)=1\$ and \$F(0,i)=0\$ where \$i\neq 0\$.
The related part of the code `a?F(--a,b)*~b+F(a,b-=2)*(a-b):+!b` is exactly calculating using the above recurrence formula. Here's the breakdown:
```
F(--a,b)                 // F(n-1, i)                   [ a = n-1, b = i   ]
*~b                      // *-(i+1)                     [ a = n-1, b = i   ]
+F(a,b-=2)               // +F(n-1, i-2)                [ a = n-1, b = i-2 ]
*(a-b)                   // *((n-1)-(i-2))              [ a = n-1, b = i-2 ]
                         // which is equivalent to *(n-i+1)
```
Since \$T(0)=0\$ and \$S(0)=1\$, \$E\_n\$ equals the coefficient of \$S^{n+1}\$ in the expansion of \$\frac{d^nS}{dt^n}\$, which is \$F(n,n)\$.
For branches that \$F(0,0)\$ can never be reached, the recurrences always end at 0, so \$F(n,i)=0\$ where \$i<0\$ or \$i\$ is odd. The latter one, particularly, implies that \$E\_n=0\$ for all odd \$n\$s. For even \$i\$s strictly larger than \$n\$, the recurrence may eventually allow \$0\leq i\leq n\$ to happen at some point, but before that step it must reach a point where \$i=n+1\$, and the recurrence formula shows that the value must be 0 at that point (since the first term is multiplied by \$n-i+1=n-(n+1)+1=0\$, and the second term is farther from the "triangle" of \$0\leq i\leq n\$). As a result, \$F(n,i)=0\$ where \$i > n\$. This completes the proof of the validity of the algorithm.
[![enter image description here](https://i.stack.imgur.com/NQbeY.png)](https://i.stack.imgur.com/NQbeY.png)
### Extensions
The code can be modified to calculate three more related sequences:
**Tangent Numbers (46 bytes)**
```
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):+!~b
```
**Secant Numbers (45 bytes)**
```
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):+!b
```
**Euler Zigzag Numbers (48 bytes)**
```
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):!b+!~b
```
[Answer]
# Python 2.7, 46 bytes
Using scipy.
```
from scipy.special import*
lambda n:euler(n)[n]
```
[Answer]
# [Perl 6](http://perl6.org/), 78 bytes
```
{(->*@E {1-sum @E».&{$_*2**(@E-1-$++)*[*](@E-$++^..@E)/[*] 1..$++}}...*)[$_]}
```
Uses the iterative formula [from here](http://www.robertobigoni.eu/Matematica/Transcendental/f08/f08.htm):
$$E\_n = 1 - \sum\_{k=0}^{n-1} \left[ E\_k \cdot 2^{(n-1-k)} \cdot \binom{n}{k} \right]$$
### How it works
The general structure is a lambda in which an infinite sequence is generated, by an expression that is called repeatedly and gets all previous values of the sequence in the variable `@E`, and then that sequence is indexed with the lambda argument:
```
{ ( -> *@E {    } ... * )[$_] }
```
The expression called for each step of the sequence, is:
```
1 - sum @E».&{              # 1 - ∑
    $_                      # Eₙ
    * 2**(@E - 1 - $++)     # 2ⁿ⁻ˡ⁻ᵏ
    * [*](@E - $++ ^.. @E)  # (n-k-1)·...·(n-1)·n
    / [*] 1..$++            # 1·2·...·k
}
```
[Answer]
# Maxima, 29 bytes
```
z(n):=2*imagpart(li[-n](%i));
```
[Try It Online!](https://tio.run/#PtaV9)
Two times imaginary part of polylogarithm function of order `-n` with argument `i` [[1]](https://oeis.org/A028296)
[Answer]
# Befunge, 115 bytes
This just supports a hardcoded set of the first 16 Euler numbers (i.e. E0 to E15). Anything beyond that wouldn't fit in a 32-bit Befunge value anyway.
```
&:2%v
[[email protected]](/cdn-cgi/l/email-protection)_2/:
_1.@v:-1
v:-1_1-.@
_5.@v:-1
v:-1_"="-.@
_"}$#"*+.@v:-1
8**-.@v:-1_"'PO"
"0h;"3_"A+y^"9*+**[[email protected]](/cdn-cgi/l/email-protection)*8+*:*
```
[Try it online!](http://befunge.tryitonline.net/#code=JjoyJXYKdkAuMF8yLzoKXzEuQHY6LTEKdjotMV8xLS5ACl81LkB2Oi0xCnY6LTFfIj0iLS5ACl8ifSQjIiorLkB2Oi0xCjgqKi0uQHY6LTFfIidQTyIKIjBoOyIzXyJBK3leIjkqKyoqLkAuLSo4Kyo6Kg&input=MTQ)
I've also done a full implementation of the formula provided in the challenge, but it's nearly twice the size, and it's still limited to the first 16 values on TIO, even though that's a 64-bit interpreter.
```
<v0p00+1&
v>1:>10p\00:>20p\>010g20g2*-00g1>-:30pv>\:
_$12 0g2%2*-*10g20g110g20g-240pv^1g03:_^*
>-#1:_!>\#<:#*_$40g:1-40p!#v_*\>0\0
@.$_^#`g00:<|!`g01::+1\+*/\<
+4%1-*/+\2+^>$$10g::2>\#<1#*-#2:#\_$*\1
```
[Try it online!](http://befunge.tryitonline.net/#code=PHYwcDAwKzEmCnY+MTo+MTBwXDAwOj4yMHBcPjAxMGcyMGcyKi0wMGcxPi06MzBwdj5cOgpfJDEyIDBnMiUyKi0qMTBnMjBnMTEwZzIwZy0yNDBwdl4xZzAzOl9eKgo+LSMxOl8hPlwjPDojKl8kNDBnOjEtNDBwISN2XypcPjBcMApALiRfXiNgZzAwOjx8IWBnMDE6OisxXCsqL1w8Cis0JTEtKi8rXDIrXj4kJDEwZzo6Mj5cIzwxIyotIzI6I1xfJCpcMQ&input=MTQ)
The problem with this algorithm is that the intermediate values in the series overflow much sooner than the total does. On a 32-bit interpreter it can only handle the first 10 values (i.e. E0 to E9). Interpreters that use bignums should do much better though - [PyFunge](http://mearie.org/projects/pyfunge/) and [Befungee](https://github.com/programble/befungee) could both handle at least up to E30.
[Answer]
# Python2, (sympy rational), 153 bytes
```
from sympy import *
t=n+2 
print n,re(Add(*map(lambda (k,j):I**(k-2*j-1)*(k-2*j)**(n+1)*binomial(k,j)/(k*2**k),[(c/t+1,c%t) for c in range(0,t**2-t)])))
```
This is very suboptimal but it's trying to use basic sympy functions and avoid floating point. Thanks @Mego for setting me straight on the original formula listed above. I tried to use something like @xnor's "combine two loops" from [Tips for golfing in Python](https://codegolf.stackexchange.com/questions/54/tips-for-golfing-in-python)
[Answer]
# Axiom, 5 bytes
```
euler
```
for OEIS A122045; this is 57 bytes
```
g(n:NNI):INT==factorial(n)*coefficient(taylor(sech(x)),n)
```
test code and results
```
(102) -> [[i,g(i)] for i in [0,1,2,3,6,10,20]]
   (102)
   [[0,1],[1,0],[2,- 1],[3,0],[6,- 61],[10,- 50521],[20,370371188237525]]
(103) -> [[i,euler(i)] for i in [0,1,2,3,6,10,20]]
   (103)
   [[0,1],[1,0],[2,- 1],[3,0],[6,- 61],[10,- 50521],[20,370371188237525]]
```
[Answer]
## CJam (34 bytes)
```
{1a{_W%_,,.*0+(+W%\_,,:~.*.+}@*W=}
```
[Online demo](http://cjam.aditsu.net/#code=20%0A%0A%7B1a%7B_W%25_%2C%2C.*0%2B(%2BW%25%5C_%2C%2C%3A~.*.%2B%7D%40*W%3D%7D%0A%0A%25p) which prints E(0) to E(19). This is an anonymous block (function).
The implementation borrows [Shieru Akasoto's recurrence](https://codegolf.stackexchange.com/a/186062/194) and rewrites it in a more CJam friendly style, manipulating entire rows at a time.
## Dissection
```
{           e# Define a block
  1a        e#   Start with row 0: [1]
  {         e#   Loop...
    _W%     e#     Take a copy and reverse it
    _,,.*   e#     Multiply each element by its position
    0+(+    e#     Pop the 0 from the start and add two 0s to the end
    W%      e#     Reverse again, giving [0 0 (i-1)a_0 (i-2)a_1 ... a_{i-2}]
    \       e#     Go back to the other copy
    _,,:~.* e#     Multiply each element by -1 ... -i
    .+      e#     Add the two arrays
  }         e#
  @*        e#   Bring the input to the top to control the loop count
  W=        e#   Take the last element
}
```
[Answer]
# APL(NARS), 42 chars, 84 bytes
```
E←{0≥w←⍵:1⋄1-+/{(⍵!w)×(2*w-1+⍵)×E⍵}¨¯1+⍳⍵}
```
Follow the formula showed from "smls", test:
```
  E 0
1
  E 1
0
  E 3
0
  E 6
¯61
  E 10
¯50521
```
the last case return one big rational as result because i enter 20x (the big rational 20/1)
and not 20 as i think 20.0 float 64 bit...
```
  E 20x
370371188237525 
```
It would be more fast if one return 0 soon but would be a little more long (50 chars):
```
  E←{0≥w←⍵:1⋄0≠2∣w:0⋄1-+/{(⍵!w)×(2*w-1+⍵)×E⍵}¨¯1+⍳⍵}
  E 30x
¯441543893249023104553682821 
```
it would be more fast if it is used the definition on question (and would be a little more long 75 chars):
```
  f←{0≥⍵:1⋄0≠2∣⍵:0⋄0J1×+/{+/⍵{⍺÷⍨(0J2*-⍺)×(⍵!⍺)×(¯1*⍵)×(⍺-2×⍵)*n}¨0..⍵}¨⍳n←1+⍵}
  f 0
1
  f 1
0
  f 3
0
  f 6
¯61J0 
  f 10
¯50521J¯8.890242766E¯9 
  f 10x
¯50521J0 
  f 20x
370371188237525J0 
  f 30x
¯441543893249023104553682821J0 
  f 40x
14851150718114980017877156781405826684425J0 
  f 400x
290652112822334583927483864434329346014178100708615375725038705263971249271772421890927613982905400870578615922728
  107805634246727371465484012302031163270328101126797841939707163099497536820702479746686714267778811263343861
  344990648676537202541289333151841575657340742634189439612727396128265918519683720901279100496205972446809988
  880945212776281115581267184426274778988681851866851641727953206090552901049158520028722201942987653512716826
  524150450130141785716436856286094614730637618087804268356432570627536028770886829651448516666994497921751407
  121752827492669601130599340120509192817404674513170334607613808215971646794552204048850269569900253391449524
  735072587185797183507854751762384660697046224773187826603393443429017928197076520780169871299768968112010396
  81980247383801787585348828625J0 
```
The result above it is one complex number that has only the real part.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~47~~ 46 bytes
Without using any special functions:
```
e@0=1;e@n_:=-n!Sum[e[n-k]/k!/(n-k)!,{k,2,n,2}]
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78/z/VwcDW0DrVIS/eylY3TzG4NDc6NTpPNztWP1tRXwPI0FTUqc7WMdLJ0zGqjf0fUJSZVxIdkpiUkwpSF6ujUJ2no2Cgo2BkUBsb@x8A "Wolfram Language (Mathematica) – Try It Online")
]