import math

def thieleInterpolator(x, y):
     = [[yi]*(len(y)-i) for i, yi in enumerate(y)]
    for i in range(len()-1):
        [i][1] = (x[i] - x[i+1]) / ([i][0] - [i+1][0])
    for i in range(2, len()):
        for j in range(len()-i):
            [j][i] = (x[j]-x[j+i]) / ([j][i-1]-[j+1][i-1]) + [j+1][i-2]
    0 = [0]
    def t(xin):
        a = 0
        for i in range(len(0)-1, 1, -1):
            a = (xin - x[i-1]) / (0[i] - 0[i-2] + a)
        return y[0] + (xin-x[0]) / (0[1]+a)
    return t


xVal = [i*.05 for i in range(32)]
tSin = [math.sin(x) for x in xVal]
tCos = [math.cos(x) for x in xVal]
tTan = [math.tan(x) for x in xVal]

iSin = thieleInterpolator(tSin, xVal)
iCos = thieleInterpolator(tCos, xVal)
iTan = thieleInterpolator(tTan, xVal)

print('{:16.14f}'.format(6*iSin(.5)))
print('{:16.14f}'.format(3*iCos(.5)))
print('{:16.14f}'.format(4*iTan(1)))