g | x | w | all
Bytes Lang Time Link
069Python 2170808T070000Ztsh
130Forth gforth201111T052059ZBubbler
035CasioBasic170808T074901Znumberma
030Octave170809T081107ZCinaski
040Julia 0.6.0170808T184740ZGoysa
02605AB1E170808T132807ZEmigna
080JavaScript ES6170808T104950ZNeil
036Pari/GP170808T080330Zalephalp
052Haskell170808T120707Zბიმო
014APL Dyalog170808T070021ZAdá
028Mathematica170808T073255Zalephalp
011M170808T080438Zmiles

Python 2, 69 bytes

from fractions import*
f=lambda k:k and Fraction(k+f(k-1),1-k*f(k-1))

Try it online!

Use the identity:

tan(A + B) = (tan(A) + tan(B)) / (1 - tan(A) * tan(B))

We have:

f(k) = 0                                    if k = 0
     = (k + f(k - 1)) / (1 - k * f(k - 1))  if k > 0

Thanks to Luis Mendo, save 4 bytes. Thanks to Lucenaposition, save 3 bytes.

Forth (gforth), 130 bytes

: g dup if tuck mod recurse then ;
: f 0 1 rot for 2dup i * + -rot swap i * - next
2dup g + abs over 0< 2* 1+ * >r i / swap r> / ;

Try it online!

Uses my own implementation of gcd, and the OEIS formula. Takes k from the stack and returns two integers denom num on the stack. It took a lot of effort (and bytes) to normalize the fraction.

: g ( x y -- gcd 0 )
  dup if tuck mod recurse then
;

: f ( k -- denom num )
  0 1               \ push initial fraction with num=0, denom=1
  rot for           \ ( num denom ) loop from k to 0 inclusive
    2dup i * + -rot \ ( denom*k+num num denom )
    swap i * -      \ ( denom*k+num denom-num*k )
  next
  2dup g + abs      \ ( num denom gcd ) evaluate positive gcd and remove 0
  over 0< 2* 1+ *   \ ( num denom gcd' ) negate gcd if denom < 0
  >r i / swap r> /  \ ( denom/gcd' num/gcd' )
;

Casio-Basic, 35 bytes

tExpand(tan(sum(seq(tan⁻¹(n),n,0,k

tan-1 should be entered as the one on the Trig keyboard; or the -1 can be entered separately from the abc>Math keyboard. According to the fx-CP400's manual, it's a single two-byte character (764).

Function, 34 bytes for the code, +1 byte to add k as an argument.

Explanation

seq(tan-1(n),n,0,k) generates all the values for tan-1(n) from 0 to k.

sum adds them all together, then tan does the tangent function on them.

tExpand will then turn them into a single fraction.

Octave, 30 bytes

format rat
tan(sum(atan(0:k)))

Try it online!

Julia 0.6.0 40 bytes

k->rationalize(tan(sum(x->atan(x),1:k)))

It's a straightforward implementation of the question. The precision of rationalize can sometimes be weird but works fine 99% of the time.

05AB1E, 33 26 bytes

0X)Iƒ©`N*+®`sN*-‚D¿D_i\¤}/

Try it online!

Explanation

0X)                          # initialize stack with [0,1]
   Iƒ                        # for N in range [0 ... input] do:
     ©                       # store a copy of the current pair in the register
      `                      # push the pair separately to the stack
       N*                    # multiply the denominator with N
         +                   # add the numerator
          ®`s                # push the denominator then the numerator to the stack
             N*              # multiply the numerator by N
               -             # subtract it from the denominator
                D¿D          # get 2 copies of the greatest common divisor
                   0Qi  }    # if the gcd equals 0
                      \¤     # replace it with the denominator
                         /   # divide the pair with this number

JavaScript (ES6), 80 bytes

f=n=>n?([a,b]=f(n-1),g=(a,b)=>a?g(b%a,a):b,c=g(d=b*n+a,e=b-n*a),[d/c,e/c]):[0,1]

Returns a [numerator, denominator] pair. Explanation: Let f(n-1) = a/b then f(n) = atan(tan(n)+tan(a/b)) = (n+a/b)/(1-n*a/b) = (b*n+a)/(b-n*a). It then remains to reduce the fraction to its lowest terms.

Online ES6 Environment

Pari/GP, 36 bytes

n->imag(x=prod(i=0,n,1+i*I))/real(x)

Try it online!

Or the same length:

n->fold((x,y)->(x+y)/(1-x*y),[0..n])

Try it online!

Haskell, 52 bytes

This uses the OEIS series expansion:

import Data.Ratio
f 0=0%1
f n|p<-f$n-1=(p+n)/(1-n*p)

Try it online!

Or a pointfree version:

(scanl1(\f n->(f+n)/(1-n*f))[0%1..]!!)

APL (Dyalog), 14 bytes

Requires ⎕FR←1287 (128 bit Floating-point Representation) for small input. Takes k as right argument.

1(∧÷,)3○¯3+.○⍳

Try it online!

 integers one through k (zero is not needed as 0 = arctan 0)

¯3+.○ sum of arcus tangents

3○ tangent

1() apply the following tacit function with 1 as left argument and the above as right argument:

 the lowest common multiple (of 1 and the right argument); gives the numerator

÷ divided by

, the concatenation (of 1 and the right argument); gives the numerator and the denominator

Mathematica, 28 bytes

Fold[+##/(1-##)&,0,Range@#]&

Try it online!

A longer, but more interesting approach (32 bytes):

Im@#/Re@#&@Product[1+n I,{n,#}]&

Try it online!

M, 11 bytes

×C÷@+
R0;ç/

Try it online!

Uses the OEIS formula x(n) = (x(n-1)+n)/(1-n*x(n-1)) with x(0) = 0.