def mkspiro(degree):
    if tex:
        us = ['u = 1']
        vs = ['v =']
    else:
        us = ['u = 1']
        vs = ['v = 0']
    if tex:
        tp = [None, 't_{11}', 't_{12}', 't_{13}', 't_{14}']
    else:
        tp = [None, 't1_1', 't1_2', 't1_3', 't1_4']
    if tex:
        prd(tp[1] + ' = k_0')
        prd(tp[2] + ' = \\frac{k_1}{2}')
        prd(tp[3] + ' = \\frac{k_2}{6}')
        prd(tp[4] + ' = \\frac{k_3}{24}')
    else:
        prd(tp[1] + ' = km0')
        prd(tp[2] + ' = .5 * km1')
        prd(tp[3] + ' = (1./6) * km2')
        prd(tp[4] + ' = (1./24) * km3')
    tlast = tp
    coef = 1.
    for i in range(1, degree - 1):
        tmp = []
        tcoef = coef
        #print tlast
        for j in range(len(tlast)):
            c = tcoef / (j + 1)
            if (j % 2) == 0 and tlast[j] != None:
                if tex:
                    tmp.append('\\frac{%s}{%.0f}' % (tlast[j], 1./c))
                else:
                    if c < 1e-9:
                        cstr = '%.16e' % c
                    else:
                        cstr = '(1./%d)' % int(.5 + (1./c))
                    tmp.append(cstr + ' * ' + tlast[j])
            tcoef *= .5
        if tmp != []:
            sign = ('+', '-')[(i / 2) % 2]
            var = ('u', 'v')[i % 2]
            if tex:
                if i == 1: pref = ''
                else: pref = sign + ' '
                str = pref + (' ' + sign + ' ').join(tmp)
            else:
                str = var + ' ' + sign + '= ' + ' + '.join(tmp)
            if var == 'u': us.append(str)
            else: vs.append(str)
        if i < degree - 1:
            if tex:
                basename = 't_{%d%%d}' % (i + 1)
            else:
                basename = 't%d_%%d' % (i + 1)
            if i == 1:
                tnext = polysquare(tp, degree - 1, basename)
                t2 = tnext
            elif i == 3:
                tnext = polysquare(t2l, degree - 1, basename)
            elif (i % 2) == 0:
                tnext = polymul(tlast, tp, degree - 1, basename, True)
            else:
                tnext = polymul(t2l, t2, degree - 1, basename)
            t2l = tlast
            tlast = tnext
        coef /= (i + 1)
    if tex:
        pr(' '.join(us))
        pr(' '.join(vs))
    else:
        for u in us:
            pr(u)
        for v in vs:
            pr(v)
dataset/ETHPy150Open google/roboto/third_party/spiro/curves/numintsynth.py/mkspiro/original