Chebyshev coefficients for $e^{-x}$ for $n=1$ from Cody, Meinardus, and Varga (table III)

              n = 1
---------------------------------
i   p_i             q_i
---------------------------------
0   1.0669  ( 00)   1.0000  ( 00)
1  -1.1535  (-01)   1.7275  ( 00)

In [4]:
from sympy import init_session
init_session()
t = symbols('t', real=True)
%matplotlib inline


IPython console for SymPy 1.0 (Python 3.5.2-64-bit) (ground types: gmpy)

These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
>>> init_printing()

Documentation can be found at http://docs.sympy.org/1.0/

(From Maria_Pusa2.pdf)

Remez algorithm

  1. Assume $\left\{t_i \right\}_{i=1}^{2k+2} \subset [−1, 1]$ and find real polynomials $p_k$ and $q_k$ and a parameter $\epsilon > 0$ such that $$ \begin{align} e^{\phi(t_i)} − \frac{p(\phi(t_i))}{q(\phi(t_i))} +(−1)^i\epsilon=0,&& i=1,...,2k+2,\\ \end{align} $$ where $q_{k+1} = 1$.

  2. Assume $r_{k,k} \in \pi_{k,k}$ and $\epsilon > 0$ and find the $2k + 2$ local extreme points of the function $$ E(t) = e^{\phi(t)} - r_{k,k}(\phi(t)) $$ in the interval $[−1, 1]$.


In [2]:
[chebyshevt_root(5, i) for i in range(5)]


Out[2]:
$$\left [ \sqrt{\frac{\sqrt{5}}{8} + \frac{5}{8}}, \quad \sqrt{- \frac{\sqrt{5}}{8} + \frac{5}{8}}, \quad 0, \quad - \sqrt{- \frac{\sqrt{5}}{8} + \frac{5}{8}}, \quad - \sqrt{\frac{\sqrt{5}}{8} + \frac{5}{8}}\right ]$$

In [3]:
[chebyshevt_root(5, i).evalf() for i in range(5)]


Out[3]:
$$\left [ 0.951056516295154, \quad 0.587785252292473, \quad 0, \quad -0.587785252292473, \quad -0.951056516295154\right ]$$

In [4]:
chebyshevt(5, x)


Out[4]:
$$16 x^{5} - 20 x^{3} + 5 x$$

In [5]:
epsilon = symbols("epsilon")
p0, p1, q0, q1 = symbols("p0, p1, q0, q1")
i = symbols("i")

In [6]:
expr = exp(-t) - (p0 + p1*t)/(q0 + q1*t) + (-1)**i*epsilon
expr = expr*(q0 + q1*t)
expr = simplify(expr)
expr


Out[6]:
$$\left(\left(-1\right)^{i} \epsilon \left(q_{0} + q_{1} t\right) e^{t} + q_{0} + q_{1} t - \left(p_{0} + p_{1} t\right) e^{t}\right) e^{- t}$$

In [7]:
system = Tuple(*[expr.subs({i: j, t: chebyshevt_root(5, 4-j).evalf()}) for j in range(1,5)])

In [8]:
system = system.subs(q0, 1)
system


Out[8]:
$$\left ( - 1.0 \epsilon \left(- 0.587785252292473 q_{1} + 1\right) - 1.0 p_{0} + 0.587785252292473 p_{1} - 1.0580119595675 q_{1} + 1.79999745730443, \quad \epsilon - p_{0} + 1, \quad - 1.0 \epsilon \left(0.587785252292473 q_{1} + 1\right) - 1.0 p_{0} - 0.587785252292473 p_{1} + 0.326547823668987 q_{1} + 0.555556340339247, \quad 1.0 \epsilon \left(0.951056516295154 q_{1} + 1\right) - 1.0 p_{0} - 0.951056516295153 p_{1} + 0.367424175709618 q_{1} + 0.386332641030547\right )$$

In [9]:
sols = solve(system, [p0, p1, q1, epsilon], dict=True)
sols


Out[9]:
$$\left [ \left \{ \epsilon : -0.00534235770912832, \quad p_{0} : 0.994657642290872, \quad p_{1} : -0.448923878605042, \quad q_{1} : 0.515299670867919\right \}, \quad \left \{ \epsilon : 0.489952936015695, \quad p_{0} : 1.4899529360157, \quad p_{1} : -2.56713051633, \quad q_{1} : -2.1932147697829\right \}\right ]$$

In [10]:
E = exp(-t) - (p0 + p1*t)/(1 + q1*t)

In [11]:
plot(E.subs(sols[0]), (t, -1, 1))


Out[11]:
<sympy.plotting.plot.Plot at 0x11110fa58>

In [12]:
extreme_x2 = [-1, nsolve(diff(E.subs(sols[0]), t), -1), nsolve(diff(E.subs(sols[0]), t), 0), 1]
extreme_x2


Out[12]:
[-1, mpf('0.48756333454382529'), mpf('-0.31523643012397814'), 1]

In [13]:
system2 = Tuple(*[expr.subs({i: j, t: extreme_x2[j]}) for j in range(4)]).subs(q0, 1)
system2


Out[13]:
$$\left ( e \left(\frac{\epsilon}{e} \left(- q_{1} + 1\right) - q_{1} - \frac{1}{e} \left(p_{0} - p_{1}\right) + 1\right), \quad - 1.0 \epsilon \left(0.487563334543825 q_{1} + 1\right) - 1.0 p_{0} - 0.487563334543825 p_{1} + 0.299422872783065 q_{1} + 0.614120979919894, \quad 1.0 \epsilon \left(- 0.315236430123978 q_{1} + 1\right) - 1.0 p_{0} + 0.315236430123978 p_{1} - 0.432057792932883 q_{1} + 1.37058331983699, \quad \frac{1}{e} \left(- e \epsilon \left(q_{1} + 1\right) + q_{1} - e \left(p_{0} + p_{1}\right) + 1\right)\right )$$

In [14]:
sols2 = solve(system2, [p0, p1, q1, epsilon], dict=True)
sols2


Out[14]:
$$\left [ \left \{ \epsilon : -1.5104814764981, \quad p_{0} : 4.25148973598511, \quad p_{1} : 12.8003545770943, \quad q_{1} : 8.07804466792008\right \}, \quad \left \{ \epsilon : -0.0429508871042537, \quad p_{0} : 1.00309640680931, \quad p_{1} : -0.396335994545923, \quad q_{1} : 0.476912414937887\right \}\right ]$$

In [15]:
plot(E.subs(sols2[1]), (t, -1, 1))


Out[15]:
<sympy.plotting.plot.Plot at 0x106ac0b00>

In [16]:
extreme_x3 = [-1, nsolve(diff(E.subs(sols2[1]), t), -1), nsolve(diff(E.subs(sols2[1]), t), 1), 1]
extreme_x3


Out[16]:
[-1, mpf('-0.74688544376119458'), mpf('0.73445765239847861'), 1]

In [17]:
system3 = Tuple(*[expr.subs({i: j, t: extreme_x3[j]}) for j in range(4)]).subs(q0, 1)
system3


Out[17]:
$$\left ( e \left(\frac{\epsilon}{e} \left(- q_{1} + 1\right) - q_{1} - \frac{1}{e} \left(p_{0} - p_{1}\right) + 1\right), \quad - 1.0 \epsilon \left(- 0.746885443761195 q_{1} + 1\right) - 1.0 p_{0} + 0.746885443761195 p_{1} - 1.57623955703592 q_{1} + 2.11041675828924, \quad 1.0 \epsilon \left(0.734457652398479 q_{1} + 1\right) - 1.0 p_{0} - 0.734457652398479 p_{1} + 0.352367507570056 q_{1} + 0.479765588144325, \quad \frac{1}{e} \left(- e \epsilon \left(q_{1} + 1\right) + q_{1} - e \left(p_{0} + p_{1}\right) + 1\right)\right )$$

In [18]:
sols3 = solve(system3, [p0, p1, q1, epsilon], dict=True)
sols3


Out[18]:
$$\left [ \left \{ \epsilon : -0.372310137236292, \quad p_{0} : 4.24349463313831, \quad p_{1} : -5.99283122766953, \quad q_{1} : -3.36336290804623\right \}, \quad \left \{ \epsilon : 0.0124345286649479, \quad p_{0} : 1.03292645730692, \quad p_{1} : -0.524798610477132, \quad q_{1} : 0.429554423065506\right \}\right ]$$

In [19]:
plot(E.subs(sols3[1]), (t, -1, 1))


Out[19]:
<sympy.plotting.plot.Plot at 0x10f4c8be0>

In [20]:
[E.subs(sols3[1]).subs(t, i).evalf() for i in extreme_x3]


Out[20]:
$$\left [ -0.012434528664948, \quad 0.0124345286649508, \quad -0.0124345286649481, \quad 0.012434528664948\right ]$$

In [21]:
extreme_x4 = [-1, nsolve(diff(E.subs(sols3[1]), t), -1), nsolve(diff(E.subs(sols3[1]), t), 1), 1]
extreme_x4


Out[21]:
[-1, mpf('-0.76572373080496461'), mpf('0.184735503796684'), 1]

In [22]:
system4 = Tuple(*[expr.subs({i: j, t: extreme_x4[j]}) for j in range(4)]).subs(q0, 1)
system4


Out[22]:
$$\left ( e \left(\frac{\epsilon}{e} \left(- q_{1} + 1\right) - q_{1} - \frac{1}{e} \left(p_{0} - p_{1}\right) + 1\right), \quad - 1.0 \epsilon \left(- 0.765723730804965 q_{1} + 1\right) - 1.0 p_{0} + 0.765723730804965 p_{1} - 1.64672734618512 q_{1} + 2.15055023102653, \quad 1.0 \epsilon \left(0.184735503796684 q_{1} + 1\right) - 1.0 p_{0} - 0.184735503796684 p_{1} + 0.153575083239998 q_{1} + 0.831324136853625, \quad \frac{1}{e} \left(- e \epsilon \left(q_{1} + 1\right) + q_{1} - e \left(p_{0} + p_{1}\right) + 1\right)\right )$$

In [23]:
sols4 = solve(system4, [p0, p1, q1, epsilon], dict=True)
sols4


Out[23]:
$$\left [ \left \{ \epsilon : -0.536112467700294, \quad p_{0} : -0.224202772122158, \quad p_{1} : 3.62801956555289, \quad q_{1} : 2.76531776449084\right \}, \quad \left \{ \epsilon : 0.0205243211429465, \quad p_{0} : 1.01650703470198, \quad p_{1} : -0.51618366752204, \quad q_{1} : 0.440379998253346\right \}\right ]$$

In [24]:
plot(E.subs(sols4[1]), (t, -1, 1))


Out[24]:
<sympy.plotting.plot.Plot at 0x1138d9b00>

In [25]:
[E.subs(sols3[1]).subs(t, i).evalf() for i in extreme_x3]


Out[25]:
$$\left [ -0.012434528664948, \quad 0.0124345286649508, \quad -0.0124345286649481, \quad 0.012434528664948\right ]$$

In [ ]:


In [ ]:

Another useful resource: http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/math_toolkit/backgrounders/remez.html

The method usually adopted to solve these equations is an iterative one: we guess the value of E, solve the equations to obtain a new value for E (as well as the polynomial coefficients), then use the new value of E as the next guess. The method is repeated until E converges on a stable value.

These complications extend the running time required for the development of rational approximations quite considerably. It is often desirable to obtain a rational rather than polynomial approximation none the less: rational approximations will often match more difficult to approximate functions, to greater accuracy, and with greater efficiency, than their polynomial alternatives. For example, if we takes our previous example of an approximation to ex, we obtained 5x10-4 accuracy with an order 4 polynomial. If we move two of the unknowns into the denominator to give a pair of order 2 polynomials, and re-minimise, then the peak relative error drops to 8.7x10-5. That's a 5 fold increase in accuracy, for the same number of terms overall.


In [26]:
expr = exp(-(-t - 1)/(2*t - 2)) - (p0 + p1*t)/(q0 + q1*t) + (-1)**i*epsilon
expr = expr*(q0 + q1*t)
expr = simplify(expr)
expr


Out[26]:
$$- p_{0} - p_{1} t + \left(q_{0} + q_{1} t\right) \left(\left(-1\right)^{i} \epsilon + e^{\frac{t + 1}{2 t - 2}}\right)$$

In [27]:
system = Tuple(*[expr.subs({i: j, t: chebyshevt_root(5, 4-j).evalf()}) for j in range(1,5)])

In [28]:
system = system.subs(q0, 1)
system


Out[28]:
$$\left ( - p_{0} + 0.587785252292473 p_{1} + \left(- \epsilon + 0.878263960768525\right) \left(- 0.587785252292473 q_{1} + 1\right), \quad \epsilon - p_{0} + e^{- \frac{1}{2}}, \quad - p_{0} - 0.587785252292473 p_{1} + \left(- \epsilon + 0.145741613143836\right) \left(0.587785252292473 q_{1} + 1\right), \quad - p_{0} - 0.951056516295154 p_{1} + \left(\epsilon + 2.20678508208151 \cdot 10^{-9}\right) \left(0.951056516295154 q_{1} + 1\right)\right )$$

In [29]:
sols = solve(system, [p0, p1, q1, epsilon], dict=True)
sols


Out[29]:
$$\left [ \left \{ \epsilon : -0.0446461226196893, \quad p_{0} : 0.561884537092944, \quad p_{1} : -0.636658291554981, \quad q_{1} : -0.0243197537608033\right \}, \quad \left \{ \epsilon : 0.253383578616161, \quad p_{0} : 0.859914238328794, \quad p_{1} : -1.34545600202545, \quad q_{1} : -2.79304572741898\right \}\right ]$$

In [30]:
E = exp(-(-t - 1)/(2*t - 2)) - (p0 + p1*t)/(1 + q1*t)

In [31]:
plot(E.subs(sols[0]), (t, -1, 1))


Out[31]:
<sympy.plotting.plot.Plot at 0x113ae2320>

In [ ]:


In [ ]:


In [32]:
plot(E.subs(sols[0]).diff(t), (t, -1, 1))


Out[32]:
<sympy.plotting.plot.Plot at 0x1141afba8>

In [33]:
print(E.subs(sols[0]).diff(t))


-0.0243197537608033*(-0.636658291554981*t + 0.561884537092944)/(-0.0243197537608033*t + 1)**2 + (-2*(t + 1)/(2*t - 2)**2 + 1/(2*t - 2))*exp((t + 1)/(2*t - 2)) + 0.636658291554981/(-0.0243197537608033*t + 1)

In [34]:
nsolve(diff(E.subs(sols[0]), t), (.5, 0.9), solver='bisect')


Out[34]:
mpf('0.70295119676297064')

In [35]:
nsolve(diff(E.subs(sols[0]), t), 0.9)


Out[35]:
mpf('0.99996577349047597')

In [36]:
E.subs(sols[0]).diff(t).subs(t, 1)


Out[36]:
$$\mathrm{NaN}$$

In [37]:
E.subs(sols[0]).diff(t).subs(t, 0.99996577349047597)


Out[37]:
$$0.654436749282803$$

This is the wrong answer. See https://github.com/sympy/sympy/issues/11768


In [38]:
E.subs(sols[0]).diff(t).subs(t, 0.7)


Out[38]:
$$-0.00875727699446154$$

In [ ]:


In [ ]:

We have to use the weird wrong solution here, because expr(1) = infinity ???


In [39]:
extreme_x2 = [-1, nsolve(diff(E.subs(sols[0]), t), 0), nsolve(diff(E.subs(sols[0]), t), (0.5, .9), solver='bisect'), nsolve(diff(E.subs(sols[0]), t), 0.9)]
extreme_x2


Out[39]:
[-1,
 mpf('0.028158494689863673'),
 mpf('0.70295119676297064'),
 mpf('0.99996577349047597')]

In [40]:
system2 = Tuple(*[expr.subs({i: j, t: extreme_x2[j]}) for j in range(4)]).subs(q0, 1)
system2


Out[40]:
$$\left ( - p_{0} + p_{1} + \left(\epsilon + 1\right) \left(- q_{1} + 1\right), \quad - p_{0} - 0.0281584946898637 p_{1} + \left(- \epsilon + 0.589208970685024\right) \left(0.0281584946898637 q_{1} + 1\right), \quad - p_{0} - 0.702951196762971 p_{1} + \left(\epsilon + 0.0569005546738582\right) \left(0.702951196762971 q_{1} + 1\right), \quad - p_{0} - 0.999965773490476 p_{1} + \left(- \epsilon + 2.41885716115751 \cdot 10^{-12689}\right) \left(0.999965773490476 q_{1} + 1\right)\right )$$

In [41]:
sols2 = solve(system2, [p0, p1, q1, epsilon], dict=True)
sols2


Out[41]:
$$\left [ \left \{ \epsilon : -0.29984844230539, \quad p_{0} : 0.87421073916577, \quad p_{1} : -1.13500439575967, \quad q_{1} : -1.86968601704062\right \}, \quad \left \{ \epsilon : 0.0660026503109725, \quad p_{0} : 0.539099242220426, \quad p_{1} : -0.600561958849427, \quad q_{1} : -0.0690979058423477\right \}\right ]$$

In [42]:
plot(E.subs(sols2[1]), (t, -1, 1))


Out[42]:
<sympy.plotting.plot.Plot at 0x114483320>

In [43]:
extreme_x3 = [-1, nsolve(diff(E.subs(sols2[1]), t), -1), nsolve(diff(E.subs(sols2[1]), t), (0.5, 0.9), solver='bisect'), nsolve(diff(E.subs(sols2[1]), t), .9)]
extreme_x3


Out[43]:
[-1,
 mpf('-0.085952974958929031'),
 mpf('0.71015320710868727'),
 mpf('0.99996569817644129')]

In [44]:
plot(exp(-(-t - 1)/(2*t - 2)), (t, -1, 1))


Out[44]:
<sympy.plotting.plot.Plot at 0x1144cb470>

In [ ]:


In [45]:
system3 = Tuple(*[expr.subs({i: j, t: extreme_x3[j]}) for j in range(4)]).subs(q0, 1)
system3


Out[45]:
$$\left ( - p_{0} + p_{1} + \left(\epsilon + 1\right) \left(- q_{1} + 1\right), \quad - p_{0} + 0.085952974958929 p_{1} + \left(- \epsilon + 0.656488444584562\right) \left(- 0.085952974958929 q_{1} + 1\right), \quad - p_{0} - 0.710153207108687 p_{1} + \left(\epsilon + 0.0523345481022624\right) \left(0.710153207108687 q_{1} + 1\right), \quad - p_{0} - 0.999965698176441 p_{1} + \left(- \epsilon + 1.75212416783888 \cdot 10^{-12661}\right) \left(0.999965698176441 q_{1} + 1\right)\right )$$

In [46]:
sols3 = solve(system3, [p0, p1, q1, epsilon], dict=True)
sols3


Out[46]:
$$\left [ \left \{ \epsilon : -0.264746995446649, \quad p_{0} : 0.973960039417298, \quad p_{1} : -1.24263211890661, \quad q_{1} : -2.01473390057133\right \}, \quad \left \{ \epsilon : 0.0668239436877988, \quad p_{0} : 0.541507912004107, \quad p_{1} : -0.603458047213429, \quad q_{1} : -0.0732473394434844\right \}\right ]$$

In [47]:
plot(E.subs(sols3[1]), (t, -1, 1))


Out[47]:
<sympy.plotting.plot.Plot at 0x1146be0b8>

In [48]:
[E.subs(sols3[1]).subs(t, i).evalf() for i in extreme_x3]


Out[48]:
$$\left [ -0.0668239436877986, \quad 0.0668239436877986, \quad -0.0668239436877985, \quad 0.066823943687799\right ]$$

In [49]:
r = (p0 + p1*t)/(1 + q1*t)

In [50]:
r.subs(sols3[1])


Out[50]:
$$\frac{- 0.603458047213429 t + 0.541507912004107}{- 0.0732473394434844 t + 1}$$

In [51]:
n, d = simplify(r.subs(sols3[1]).subs(t, (2*t - 1)/(2*t + 1))).as_numer_denom()
rat_func = (n/Poly(d).TC())/(d/Poly(d).TC())
correct_rat_func = (1.0669 + -1.1535e-1*t)/(1 + 1.7275*t)
rat_func, correct_rat_func


Out[51]:
$$\left ( \frac{- 0.115444283777952 t + 1.0668239436878}{1.72700667683382 t + 1.0}, \quad \frac{- 0.11535 t + 1.0669}{1.7275 t + 1}\right )$$

In [52]:
plot((rat_func, (t, 0, 100)), (exp(-t), (t, 0, 100)), ylim=(-1, 10))


Out[52]:
<sympy.plotting.plot.Plot at 0x1146f0f60>

In [53]:
plot((correct_rat_func - exp(-t), (t, 0, 100)))


Out[53]:
<sympy.plotting.plot.Plot at 0x1141e6c50>

In [54]:
plot((rat_func - exp(-t), (t, 0, 100)))


Out[54]:
<sympy.plotting.plot.Plot at 0x1148f4278>

That's it!!!

For reference, these are the Möbius transforms for $[-1, 1] \leftrightarrow [0, \infty]$


In [55]:
simplify(1/(1 - x) - S(1)/2)


Out[55]:
$$- \frac{x + 1}{2 x - 2}$$

In [56]:
solve(1/(1 - x) - S(1)/2 - y, x)


Out[56]:
$$\left [ \frac{2 y - 1}{2 y + 1}\right ]$$

Now let's try $n = 2$

Chebyshev coefficients for $e^{-x}$ for $n=1$ from Cody, Meinardus, and Varga (table III)

              n = 2
---------------------------------
i   p_i             q_i
---------------------------------
0   9.92641  (-01)   1.00000  ( 00)
1  -1.88332  (-01)   6.69295  (-01)
2   4.21096  (-03)   5.72258  (-01)

In [57]:
[chebyshevt_root(6, i) for i in range(6)]


Out[57]:
$$\left [ \frac{\sqrt{2}}{4} + \frac{\sqrt{6}}{4}, \quad \frac{\sqrt{2}}{2}, \quad - \frac{\sqrt{2}}{4} + \frac{\sqrt{6}}{4}, \quad - \frac{\sqrt{6}}{4} + \frac{\sqrt{2}}{4}, \quad - \frac{\sqrt{2}}{2}, \quad - \frac{\sqrt{6}}{4} - \frac{\sqrt{2}}{4}\right ]$$

In [58]:
epsilon = symbols("epsilon")
p0, p1, p2, q1, q2 = symbols("p0, p1, p2, q1, q2")
i = symbols("i")

In [59]:
expr = exp(-(-t - 1)/(2*t - 2)) - (p0 + p1*t + p2*t**2)/(1 + q1*t + q2*t**2) + (-1)**i*epsilon
expr = expr*(1 + q1*t + q2*t**2)
expr = simplify(expr)
expr


Out[59]:
$$- p_{0} - p_{1} t - p_{2} t^{2} + \left(\left(-1\right)^{i} \epsilon + e^{\frac{t + 1}{2 t - 2}}\right) \left(q_{1} t + q_{2} t^{2} + 1\right)$$

In [60]:
system = Tuple(*[expr.subs({i: j, t: chebyshevt_root(7, 6-j)}) for j in range(1,7)])

In [61]:
system = system.subs(q0, 1)
system


Out[61]:
$$\left ( - p_{0} + p_{1} \cos{\left (\frac{3 \pi}{14} \right )} - p_{2} \cos^{2}{\left (\frac{3 \pi}{14} \right )} + \left(- \epsilon + e^{\frac{- \cos{\left (\frac{3 \pi}{14} \right )} + 1}{-2 - 2 \cos{\left (\frac{3 \pi}{14} \right )}}}\right) \left(- q_{1} \cos{\left (\frac{3 \pi}{14} \right )} + q_{2} \cos^{2}{\left (\frac{3 \pi}{14} \right )} + 1\right), \quad - p_{0} + p_{1} \cos{\left (\frac{5 \pi}{14} \right )} - p_{2} \cos^{2}{\left (\frac{5 \pi}{14} \right )} + \left(\epsilon + e^{\frac{- \cos{\left (\frac{5 \pi}{14} \right )} + 1}{-2 - 2 \cos{\left (\frac{5 \pi}{14} \right )}}}\right) \left(- q_{1} \cos{\left (\frac{5 \pi}{14} \right )} + q_{2} \cos^{2}{\left (\frac{5 \pi}{14} \right )} + 1\right), \quad - \epsilon - p_{0} + e^{- \frac{1}{2}}, \quad - p_{0} - p_{1} \cos{\left (\frac{5 \pi}{14} \right )} - p_{2} \cos^{2}{\left (\frac{5 \pi}{14} \right )} + \left(\epsilon + e^{\frac{\cos{\left (\frac{5 \pi}{14} \right )} + 1}{-2 + 2 \cos{\left (\frac{5 \pi}{14} \right )}}}\right) \left(q_{1} \cos{\left (\frac{5 \pi}{14} \right )} + q_{2} \cos^{2}{\left (\frac{5 \pi}{14} \right )} + 1\right), \quad - p_{0} - p_{1} \cos{\left (\frac{3 \pi}{14} \right )} - p_{2} \cos^{2}{\left (\frac{3 \pi}{14} \right )} + \left(- \epsilon + e^{\frac{\cos{\left (\frac{3 \pi}{14} \right )} + 1}{-2 + 2 \cos{\left (\frac{3 \pi}{14} \right )}}}\right) \left(q_{1} \cos{\left (\frac{3 \pi}{14} \right )} + q_{2} \cos^{2}{\left (\frac{3 \pi}{14} \right )} + 1\right), \quad - p_{0} - p_{1} \cos{\left (\frac{\pi}{14} \right )} - p_{2} \cos^{2}{\left (\frac{\pi}{14} \right )} + \left(\epsilon + e^{\frac{\cos{\left (\frac{\pi}{14} \right )} + 1}{-2 + 2 \cos{\left (\frac{\pi}{14} \right )}}}\right) \left(q_{1} \cos{\left (\frac{\pi}{14} \right )} + q_{2} \cos^{2}{\left (\frac{\pi}{14} \right )} + 1\right)\right )$$

In [62]:
sols = [dict(zip([p0, p1, p2, q1, q2, epsilon], nsolve(system, [p0, p1, p2, q1, q2, epsilon], [1, 1, 1, 1, 1, 0])))]
sols


Out[62]:
[{epsilon: mpf('0.00087520741332527754'),
  p1: mpf('-1.3617815355355396'),
  q1: mpf('-1.2351673140964272'),
  q2: mpf('0.50060529714594074'),
  p0: mpf('0.60565545229930815'),
  p2: mpf('0.75984526802652071')}]

In [63]:
E = exp(-(-t - 1)/(2*t - 2)) - (p0 + p1*t + p2*t**2)/(1 + q1*t + q2*t**2)

In [64]:
plot(E.subs(sols[0]), (t, -1, 1))


Out[64]:
<sympy.plotting.plot.Plot at 0x1138010b8>

In [65]:
E.subs(sols[0]).subs(t, 1)


Out[65]:
$$e^{\tilde{\infty}} - 0.0140115018489858$$

In [66]:
extreme_x2 = [-1, nsolve(diff(E.subs(sols[0]), t), (-1, 0), solver='bisect'), nsolve(diff(E.subs(sols[0]), t), (0, 0.5), solver='bisect'), nsolve(diff(E.subs(sols[0]), t), (0.5, .7), solver='bisect'), nsolve(diff(E.subs(sols[0]), t), 0.9), 0.999]
extreme_x2


Out[66]:
[-1,
 mpf('-0.39506511254484362'),
 mpf('0.20691058995491739'),
 mpf('0.65489012733235114'),
 mpf('0.89772666518036314'),
 0.999]

In [67]:
system2 = Tuple(*[expr.subs({i: j, t: extreme_x2[j]}) for j in range(6)]).subs(q0, 1)
system2


Out[67]:
$$\left ( - p_{0} + p_{1} - p_{2} + \left(\epsilon + 1\right) \left(- q_{1} + q_{2} + 1\right), \quad - p_{0} + 0.395065112544844 p_{1} - 0.15607644315007 p_{2} + \left(- \epsilon + 0.805080971873454\right) \left(- 0.395065112544844 q_{1} + 0.15607644315007 q_{2} + 1\right), \quad - p_{0} - 0.206910589954917 p_{1} - 0.042811992235492 p_{2} + \left(\epsilon + 0.467249508998163\right) \left(0.206910589954917 q_{1} + 0.042811992235492 q_{2} + 1\right), \quad - p_{0} - 0.654890127332351 p_{1} - 0.428881078877383 p_{2} + \left(- \epsilon + 0.0909333996194215\right) \left(0.654890127332351 q_{1} + 0.428881078877383 q_{2} + 1\right), \quad - p_{0} - 0.897726665180363 p_{1} - 0.805913165375856 p_{2} + \left(\epsilon + 9.34840528810586 \cdot 10^{-5}\right) \left(0.897726665180363 q_{1} + 0.805913165375856 q_{2} + 1\right), \quad - p_{0} - 0.999 p_{1} - 0.998001 p_{2} + \left(- \epsilon + 8.36884140359697 \cdot 10^{-435}\right) \left(0.999 q_{1} + 0.998001 q_{2} + 1\right)\right )$$

In [68]:
sols2 = [dict(zip([p0, p1, p2, q1, q2, epsilon], nsolve(system2, [p0, p1, p2, q1, q2, epsilon], [1, 1, 1, 1, 1, 0])))]
sols2


Out[68]:
[{epsilon: mpf('-0.0061928183252491161'),
  p1: mpf('-1.3318832988753191'),
  q1: mpf('-1.1458321602168974'),
  q2: mpf('0.53709548411891743'),
  p0: mpf('0.60677726907688919'),
  p2: mpf('0.7276521929024462')}]

In [69]:
plot(E.subs(sols2[0]), (t, -1, 1))


Out[69]:
<sympy.plotting.plot.Plot at 0x1141cd128>

In [70]:
extreme_x3 = [-1, nsolve(diff(E.subs(sols2[0]), t), (-1, 0), solver='bisect'), nsolve(diff(E.subs(sols2[0]), t), (0, 0.5), solver='bisect'), nsolve(diff(E.subs(sols2[0]), t), (0.5, .8), solver='bisect'), nsolve(diff(E.subs(sols2[0]), t), (0.8, 0.99), solver='bisect'), 0.999]
extreme_x3


Out[70]:
[-1,
 mpf('-0.37414267499841564'),
 mpf('0.34718736920006959'),
 mpf('0.72818971396861003'),
 mpf('0.9154771862936641'),
 0.999]

In [71]:
system3 = Tuple(*[expr.subs({i: j, t: extreme_x3[j]}) for j in range(6)]).subs(q0, 1)
system3


Out[71]:
$$\left ( - p_{0} + p_{1} - p_{2} + \left(\epsilon + 1\right) \left(- q_{1} + q_{2} + 1\right), \quad - p_{0} + 0.374142674998416 p_{1} - 0.13998274125497 p_{2} + \left(- \epsilon + 0.796342052419039\right) \left(- 0.374142674998416 q_{1} + 0.13998274125497 q_{2} + 1\right), \quad - p_{0} - 0.34718736920007 p_{1} - 0.120539069332065 p_{2} + \left(\epsilon + 0.356353128353967\right) \left(0.34718736920007 q_{1} + 0.120539069332065 q_{2} + 1\right), \quad - p_{0} - 0.72818971396861 p_{1} - 0.530260259529686 p_{2} + \left(- \epsilon + 0.041625736601407\right) \left(0.72818971396861 q_{1} + 0.530260259529686 q_{2} + 1\right), \quad - p_{0} - 0.915477186293664 p_{1} - 0.838098478624164 p_{2} + \left(\epsilon + 1.19937448818486 \cdot 10^{-5}\right) \left(0.915477186293664 q_{1} + 0.838098478624164 q_{2} + 1\right), \quad - p_{0} - 0.999 p_{1} - 0.998001 p_{2} + \left(- \epsilon + 8.36884140359697 \cdot 10^{-435}\right) \left(0.999 q_{1} + 0.998001 q_{2} + 1\right)\right )$$

In [72]:
sols3 = [dict(zip([p0, p1, p2, q1, q2, epsilon], nsolve(system3, [p0, p1, p2, q1, q2, epsilon], [1, 1, 1, 1, 1, 0])))]
sols3


Out[72]:
[{epsilon: mpf('-0.007280358179673235'),
  p1: mpf('-1.3426730316783956'),
  q1: mpf('-1.1609647500136246'),
  q2: mpf('0.54703815977150041'),
  p0: mpf('0.60872386951896721'),
  p2: mpf('0.73689077745292912')}]

In [73]:
plot(E.subs(sols3[0]), (t, -1, 1))


Out[73]:
<sympy.plotting.plot.Plot at 0x1149197f0>

In [74]:
[E.subs(sols3[0]).subs(t, i).evalf() for i in extreme_x3]


Out[74]:
$$\left [ 0.0072803581796731, \quad -0.00728035817967287, \quad 0.00728035817967265, \quad -0.00728035817967302, \quad 0.00728035817967356, \quad -0.00728035817967281\right ]$$

In [75]:
r = (p0 + p1*t + p2*t**2)/(1 + q1*t + q2*t**2)

In [76]:
r.subs(sols3[0])


Out[76]:
$$\frac{0.736890777452929 t^{2} - 1.3426730316784 t + 0.608723869518967}{0.5470381597715 t^{2} - 1.16096475001362 t + 1}$$

In [77]:
n, d = together(r.subs(sols3[0]).subs(t, (2*t - 1)/(2*t + 1))).as_numer_denom() # simplify/cancel here will add degree to the numerator and denominator
rat_func = (Poly(n)/Poly(d).TC())/(Poly(d)/Poly(d).TC())
correct_rat_func = (9.92641e-1 + -1.88332e-1*t + 4.21096e-3*t**2)/(1 + 6.69295e-1*t + 5.72258e-1*t**2)
rat_func, correct_rat_func


Out[77]:
$$\left ( \frac{0.00434506961993492 t^{2} - 0.189315761029417 t + 0.992719641820327}{0.5702703026837 t^{2} + 0.669071423212675 t + 1.0}, \quad \frac{0.00421096 t^{2} - 0.188332 t + 0.992641}{0.572258 t^{2} + 0.669295 t + 1}\right )$$

In [78]:
plot((rat_func, (t, 0, 100)), (exp(-t), (t, 0, 100)), ylim=(-1, 10))


Out[78]:
<sympy.plotting.plot.Plot at 0x1148e4cc0>

In [79]:
plot((correct_rat_func - exp(-t), (t, 0, 100)))


Out[79]:
<sympy.plotting.plot.Plot at 0x114e1f710>

In [80]:
plot((rat_func - exp(-t), (t, 0, 100)))


Out[80]:
<sympy.plotting.plot.Plot at 0x1151e8588>

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [81]:
N = symbols("N")
x = symbols("x", real=True)
phi = N*(0.1309 - 0.1149*x**2 + I*0.2500*x)

In [82]:
phi.subs(N, 4).as_real_imag()


Out[82]:
$$\left ( - 0.4596 x^{2} + 0.5236, \quad x\right )$$

In [83]:
from sympy.plotting import *
plot_parametric((*phi.subs(N, 4).as_real_imag(), (x, -10, 10)))


Out[83]:
<sympy.plotting.plot.Plot at 0x1153c0dd8>

In [84]:
correct_rat_func = (1.0669 + -1.1535e-1*t)/(1 + 1.7275*t)
correct_rat_func2 = (9.92641e-1 + -1.88332e-1*t + 4.21096e-3*t**2)/(1 + 6.69295e-1*t + 5.72258e-1*t**2)

In [85]:
apart(correct_rat_func)


Out[85]:
$$-0.0667727930535456 + \frac{1.13367279305355}{1.7275 t + 1.0}$$

In [86]:
apart(correct_rat_func2, full=True).doit()


Out[86]:
$$0.00735849913850047 - \frac{0.168854788120832 - 0.809437993293635 i}{t + 0.584784310573203 + 1.18553400067436 i} - \frac{0.168854788120832 + 0.809437993293635 i}{t + 0.584784310573203 - 1.18553400067436 i}$$

$n=14$

$p_i$

 0   9.9999999999998168e-01
 1  -2.7495604296300043e-01
 2   3.4346984175671475e-02
 3  -2.5674439819028618e-03
 4   1.2734070715233181e-04
 5  -4.3932808492511236e-06
 6   1.0753202054485227e-07
 7  -1.8710255961089453e-09
 8   2.2849515765300155e-11
 9  -1.9038640942835345e-13
10   1.0310151365350495e-15
11  -3.3490280333667533e-18
12   5.6743825539523501e-21
13  -3.7794523874503295e-24
14   4.1609826642376613e-28

$q_i$

 1   1.0000000000000000e+00
 2   7.2504395703488666e-01
 3   2.5939094125018012e-01
 4   6.0968185127283595e-02
 5   1.0574049161691156e-02
 6   1.4405527154587316e-03
 7   1.6019211440612190e-04
 8   1.4908234724800242e-05
 9   1.1820291576355772e-06
10   8.0163997982357503e-08
11   4.8361800878648281e-09
12   2.2472030400428529e-10
13   1.2922802705792779e-11
14   1.8921838854022449e-13
15   2.2710680218891295e-14

In [87]:
n14pis = """
 0   9.9999999999998168e-01
 1  -2.7495604296300043e-01
 2   3.4346984175671475e-02
 3  -2.5674439819028618e-03
 4   1.2734070715233181e-04
 5  -4.3932808492511236e-06
 6   1.0753202054485227e-07
 7  -1.8710255961089453e-09
 8   2.2849515765300155e-11
 9  -1.9038640942835345e-13
10   1.0310151365350495e-15
11  -3.3490280333667533e-18
12   5.6743825539523501e-21
13  -3.7794523874503295e-24
14   4.1609826642376613e-28
"""
n14qis = """
 1   1.0000000000000000e+00
 2   7.2504395703488666e-01
 3   2.5939094125018012e-01
 4   6.0968185127283595e-02
 5   1.0574049161691156e-02
 6   1.4405527154587316e-03
 7   1.6019211440612190e-04
 8   1.4908234724800242e-05
 9   1.1820291576355772e-06
10   8.0163997982357503e-08
11   4.8361800878648281e-09
12   2.2472030400428529e-10
13   1.2922802705792779e-11
14   1.8921838854022449e-13
15   2.2710680218891295e-14
"""
n14pi = [Float(i.split()[-1]) for i in n14pis.strip().split('\n')]
n14qi = [Float(i.split()[-1]) for i in n14qis.strip().split('\n')]
n14qi[0] = 1 # Exactly
n14pi, n14qi


Out[87]:
$$\left ( \left [ 0.99999999999998168, \quad -0.27495604296300043, \quad 0.034346984175671475, \quad -0.0025674439819028618, \quad 0.00012734070715233181, \quad -4.3932808492511236 \cdot 10^{-6}, \quad 1.0753202054485227 \cdot 10^{-7}, \quad -1.8710255961089453 \cdot 10^{-9}, \quad 2.2849515765300155 \cdot 10^{-11}, \quad -1.9038640942835345 \cdot 10^{-13}, \quad 1.0310151365350495 \cdot 10^{-15}, \quad -3.3490280333667533 \cdot 10^{-18}, \quad 5.6743825539523501 \cdot 10^{-21}, \quad -3.7794523874503295 \cdot 10^{-24}, \quad 4.1609826642376613 \cdot 10^{-28}\right ], \quad \left [ 1, \quad 0.72504395703488666, \quad 0.25939094125018012, \quad 0.060968185127283595, \quad 0.010574049161691156, \quad 0.0014405527154587316, \quad 0.0001601921144061219, \quad 1.4908234724800242 \cdot 10^{-5}, \quad 1.1820291576355772 \cdot 10^{-6}, \quad 8.0163997982357503 \cdot 10^{-8}, \quad 4.8361800878648281 \cdot 10^{-9}, \quad 2.2472030400428529 \cdot 10^{-10}, \quad 1.2922802705792779 \cdot 10^{-11}, \quad 1.8921838854022449 \cdot 10^{-13}, \quad 2.2710680218891295 \cdot 10^{-14}\right ]\right )$$

In [88]:
correct_rat_func14 = Poly(reversed(n14pi), t)/Poly(reversed(n14qi), t)
correct_rat_func14


Out[88]:
$$\frac{4.1609826642376611 \cdot 10^{-28} t^{14} - 3.7794523874503298 \cdot 10^{-24} t^{13} + 5.6743825539523504 \cdot 10^{-21} t^{12} - 3.3490280333667535 \cdot 10^{-18} t^{11} + 1.0310151365350496 \cdot 10^{-15} t^{10} - 1.9038640942835346 \cdot 10^{-13} t^{9} + 2.2849515765300154 \cdot 10^{-11} t^{8} - 1.8710255961089454 \cdot 10^{-9} t^{7} + 1.0753202054485227 \cdot 10^{-7} t^{6} - 4.3932808492511235 \cdot 10^{-6} t^{5} + 0.00012734070715233182 t^{4} - 0.002567443981902862 t^{3} + 0.034346984175671474 t^{2} - 0.27495604296300041 t + 0.99999999999998168}{2.2710680218891296 \cdot 10^{-14} t^{14} + 1.8921838854022448 \cdot 10^{-13} t^{13} + 1.292280270579278 \cdot 10^{-11} t^{12} + 2.2472030400428528 \cdot 10^{-10} t^{11} + 4.8361800878648284 \cdot 10^{-9} t^{10} + 8.0163997982357503 \cdot 10^{-8} t^{9} + 1.1820291576355772 \cdot 10^{-6} t^{8} + 1.4908234724800242 \cdot 10^{-5} t^{7} + 0.00016019211440612189 t^{6} + 0.0014405527154587316 t^{5} + 0.010574049161691156 t^{4} + 0.060968185127283595 t^{3} + 0.25939094125018014 t^{2} + 0.72504395703488667 t + 1.0}$$

In [89]:
plot(exp(-t) - correct_rat_func14, (t, 0, 10))


Out[89]:
<sympy.plotting.plot.Plot at 0x1155f1518>

In [90]:
plot(exp(-t) - correct_rat_func14, (t, 1e-4, 1e2), xscale='log', adaptive=False, nb_of_points=10000)


Out[90]:
<sympy.plotting.plot.Plot at 0x1157ce9e8>

In [91]:
# Use x, which has no assumptions, to work around a bug
#apart_correct_rat_func14 = apart(correct_rat_func14.subs(t, x), x, domain=QQ, full=True).doit().evalf().expand().subs(x, t)
#apart_correct_rat_func14

In [92]:
#plot(exp(-t) - re(apart_correct_rat_func14), (t, 1e-4, 1e2), xscale='log', adaptive=False, nb_of_points=10000)

In [93]:
#re(apart_correct_rat_func14)

In [94]:
#cancel(apart_correct_rat_func14)

In [95]:
correct_rat_func14


Out[95]:
$$\frac{4.1609826642376611 \cdot 10^{-28} t^{14} - 3.7794523874503298 \cdot 10^{-24} t^{13} + 5.6743825539523504 \cdot 10^{-21} t^{12} - 3.3490280333667535 \cdot 10^{-18} t^{11} + 1.0310151365350496 \cdot 10^{-15} t^{10} - 1.9038640942835346 \cdot 10^{-13} t^{9} + 2.2849515765300154 \cdot 10^{-11} t^{8} - 1.8710255961089454 \cdot 10^{-9} t^{7} + 1.0753202054485227 \cdot 10^{-7} t^{6} - 4.3932808492511235 \cdot 10^{-6} t^{5} + 0.00012734070715233182 t^{4} - 0.002567443981902862 t^{3} + 0.034346984175671474 t^{2} - 0.27495604296300041 t + 0.99999999999998168}{2.2710680218891296 \cdot 10^{-14} t^{14} + 1.8921838854022448 \cdot 10^{-13} t^{13} + 1.292280270579278 \cdot 10^{-11} t^{12} + 2.2472030400428528 \cdot 10^{-10} t^{11} + 4.8361800878648284 \cdot 10^{-9} t^{10} + 8.0163997982357503 \cdot 10^{-8} t^{9} + 1.1820291576355772 \cdot 10^{-6} t^{8} + 1.4908234724800242 \cdot 10^{-5} t^{7} + 0.00016019211440612189 t^{6} + 0.0014405527154587316 t^{5} + 0.010574049161691156 t^{4} + 0.060968185127283595 t^{3} + 0.25939094125018014 t^{2} + 0.72504395703488667 t + 1.0}$$

In [96]:
srepr(correct_rat_func14)


Out[96]:
"Mul(Add(Mul(Float('4.1609826642376610641e-28', prec=17), Pow(Symbol('t', real=True), Integer(14))), Mul(Integer(-1), Float('3.7794523874503297816e-24', prec=17), Pow(Symbol('t', real=True), Integer(13))), Mul(Float('5.6743825539523504126e-21', prec=17), Pow(Symbol('t', real=True), Integer(12))), Mul(Integer(-1), Float('3.3490280333667534845e-18', prec=17), Pow(Symbol('t', real=True), Integer(11))), Mul(Float('1.0310151365350495889e-15', prec=17), Pow(Symbol('t', real=True), Integer(10))), Mul(Integer(-1), Float('1.9038640942835345932e-13', prec=17), Pow(Symbol('t', real=True), Integer(9))), Mul(Float('2.2849515765300153532e-11', prec=17), Pow(Symbol('t', real=True), Integer(8))), Mul(Integer(-1), Float('1.8710255961089454423e-9', prec=17), Pow(Symbol('t', real=True), Integer(7))), Mul(Float('1.0753202054485226852e-7', prec=17), Pow(Symbol('t', real=True), Integer(6))), Mul(Integer(-1), Float('4.393280849251123483e-6', prec=17), Pow(Symbol('t', real=True), Integer(5))), Mul(Float('0.00012734070715233181928', prec=17), Pow(Symbol('t', real=True), Integer(4))), Mul(Integer(-1), Float('0.0025674439819028619519', prec=17), Pow(Symbol('t', real=True), Integer(3))), Mul(Float('0.034346984175671474437', prec=17), Pow(Symbol('t', real=True), Integer(2))), Mul(Integer(-1), Float('0.27495604296300041325', prec=17), Symbol('t', real=True)), Float('0.99999999999998168132', prec=17)), Pow(Add(Mul(Float('2.2710680218891296266e-14', prec=17), Pow(Symbol('t', real=True), Integer(14))), Mul(Float('1.8921838854022448175e-13', prec=17), Pow(Symbol('t', real=True), Integer(13))), Mul(Float('1.2922802705792779525e-11', prec=17), Pow(Symbol('t', real=True), Integer(12))), Mul(Float('2.2472030400428528176e-10', prec=17), Pow(Symbol('t', real=True), Integer(11))), Mul(Float('4.836180087864828391e-9', prec=17), Pow(Symbol('t', real=True), Integer(10))), Mul(Float('8.0163997982357503177e-8', prec=17), Pow(Symbol('t', real=True), Integer(9))), Mul(Float('1.1820291576355771705e-6', prec=17), Pow(Symbol('t', real=True), Integer(8))), Mul(Float('0.000014908234724800242013', prec=17), Pow(Symbol('t', real=True), Integer(7))), Mul(Float('0.00016019211440612189201', prec=17), Pow(Symbol('t', real=True), Integer(6))), Mul(Float('0.0014405527154587316474', prec=17), Pow(Symbol('t', real=True), Integer(5))), Mul(Float('0.010574049161691155552', prec=17), Pow(Symbol('t', real=True), Integer(4))), Mul(Float('0.060968185127283594515', prec=17), Pow(Symbol('t', real=True), Integer(3))), Mul(Float('0.25939094125018014036', prec=17), Pow(Symbol('t', real=True), Integer(2))), Mul(Float('0.7250439570348866658', prec=17), Symbol('t', real=True)), Float('1.0', prec=17)), Integer(-1)))"

In [1]:
real_part14 = """       
"-8.897 773 186468 8888199 X 100 
“3.703 275 049423 448 0603 X 100
-0.208 758 638 250 130 125 l X 100
+3.993 3697105785685194 X 100 
+5.089 345 060580 6245066 X 100 
+5.623 142 572745 977 1248 X 100 
+2.269 783 8292311127097 X 100
“7.154288 0635890672853 X 10""5
+9.439 025 310736168 877 9 X 10“3 
“3.763 600 387 822 696 871 7 X 10“1 
-2.349 823 2091082701191 X 1001 
+4.693 327 448 8831293047 X 101 
~2.787516194014564646 8 X 101 
+4.807 112098 832508 8907 X 100
+1.832 174 378 254041 275 1 X 10“14
""".strip().replace(' ', '').replace('"', '-').replace('“', '-').replace('X10', 'e').replace('--', '-').replace('l', '1').replace('~', '-')
print(real_part14)


-8.8977731864688888199e0
-3.7032750494234480603e0
-0.2087586382501301251e0
+3.9933697105785685194e0
+5.0893450605806245066e0
+5.6231425727459771248e0
+2.2697838292311127097e0
-7.1542880635890672853e-5
+9.4390253107361688779e-3
-3.7636003878226968717e-1
-2.3498232091082701191e01
+4.6933274488831293047e1
-2.7875161940145646468e1
+4.8071120988325088907e0
+1.8321743782540412751e-14

In [5]:
theta1r, theta2r, theta3r, theta4r, theta5r, theta6r, theta7r, alpha1r, alpha2r, alpha3r, alpha4r, alpha5r, alpha6r, alpha7r, alpha0r = map(Float, real_part14.strip().split())
theta1r, theta2r, theta3r, theta4r, theta5r, theta6r, theta7r, alpha1r, alpha2r, alpha3r, alpha4r, alpha5r, alpha6r, alpha7r, alpha0r


Out[5]:
$$\left ( -8.8977731864688888199, \quad -3.7032750494234480603, \quad -0.2087586382501301251, \quad 3.9933697105785685194, \quad 5.0893450605806245066, \quad 5.6231425727459771248, \quad 2.2697838292311127097, \quad -0.000071542880635890672853, \quad 0.0094390253107361688779, \quad -0.37636003878226968717, \quad -23.498232091082701191, \quad 46.933274488831293047, \quad -27.875161940145646468, \quad 4.8071120988325088907, \quad 1.8321743782540412751 \cdot 10^{-14}\right )$$

In [6]:
imaginary_part14 = """
+ 1.663 098 261 990208 5304 X 101 
+ 1.365 637 187 148 3268171 X 101 
+1.0991260561901260913 X 101 
+6.004 831 642235 0373178 X 100 
+3.588 8240290270065102 X 100 
+1.194069046 343 966 9766 X 100 
+8.461 737 973 0402214019 X 100
+1.436104334954130011 1 X 10““4 
--1.718479195 848 301 751 1 X 10-2
+3.3518347029450104214 X 10""1 
-5.808 359 129714207 4004 X 100 
+4.564 364976 882 776 0791 X 101 
- 1.021 473 399 905 645 143 4 X 102 
- 1.320 979 383742 872 3881 X 100
+ 0.000 000 000 000 000 000 0 X 100
""".strip().replace(' ', '').replace('"', '-').replace('“', '-').replace('X10', 'e').replace('--', '-').replace('l', '1').replace('~', '-')
print(imaginary_part14)


+1.6630982619902085304e1
+1.3656371871483268171e1
+1.0991260561901260913e1
+6.0048316422350373178e0
+3.5888240290270065102e0
+1.1940690463439669766e0
+8.4617379730402214019e0
+1.4361043349541300111e-4
-1.7184791958483017511e-2
+3.3518347029450104214e-1
-5.8083591297142074004e0
+4.5643649768827760791e1
-1.0214733999056451434e2
-1.3209793837428723881e0
+0.0000000000000000000e0

In [7]:
theta1j, theta2j, theta3j, theta4j, theta5j, theta6j, theta7j, alpha1j, alpha2j, alpha3j, alpha4j, alpha5j, alpha6j, alpha7j, alpha0j = [Float(i)*I for i in imaginary_part14.strip().split()]
theta1j, theta2j, theta3j, theta4j, theta5j, theta6j, theta7j, alpha1j, alpha2j, alpha3j, alpha4j, alpha5j, alpha6j, alpha7j, alpha0j


Out[7]:
$$\left ( 16.630982619902085304 i, \quad 13.656371871483268171 i, \quad 10.991260561901260913 i, \quad 6.0048316422350373178 i, \quad 3.5888240290270065102 i, \quad 1.1940690463439669766 i, \quad 8.4617379730402214019 i, \quad 0.00014361043349541300111 i, \quad - 0.017184791958483017511 i, \quad 0.33518347029450104214 i, \quad - 5.8083591297142074004 i, \quad 45.643649768827760791 i, \quad - 102.14733999056451434 i, \quad - 1.3209793837428723881 i, \quad 0\right )$$

In [8]:
theta1, theta2, theta3, theta4, theta5, theta6, theta7, alpha1, alpha2, alpha3, alpha4, alpha5, alpha6, alpha7, alpha0 =\
(r + j for r, j in zip(
        (theta1r, theta2r, theta3r, theta4r, theta5r, theta6r, theta7r, alpha1r, alpha2r, alpha3r, alpha4r, alpha5r, alpha6r, alpha7r, alpha0r),
        (theta1j, theta2j, theta3j, theta4j, theta5j, theta6j, theta7j, alpha1j, alpha2j, alpha3j, alpha4j, alpha5j, alpha6j, alpha7j, alpha0j)))

In [9]:
thetas = theta1, theta2, theta3, theta4, theta5, theta6, theta7
alphas = alpha1, alpha2, alpha3, alpha4, alpha5, alpha6, alpha7

In [10]:
correct_partial_frac14 = alpha0 + Add(*(alpha/(t - theta) + alpha/(t - conjugate(theta)) for alpha, theta in zip(alphas, thetas)))

In [12]:
correct_re_partial_frac14 = alpha0 + 2*re(Add(*(alpha/(t - theta) for alpha, theta in zip(alphas, thetas))))
print(correct_re_partial_frac14)


-55.750323880291292936*(t - 5.6231425727459771248)/((t - 5.6231425727459771248)**2 + 1.4258008874367907553) + 93.866548977662586094*(t - 5.0893450605806245066)/((t - 5.0893450605806245066)**2 + 12.879657911321636066) - 46.996464182165402382*(t - 3.9933697105785685194)/((t - 3.9933697105785685194)**2 + 36.05800305158713521) + 9.6142241976650177814*(t - 2.2697838292311127097)/((t - 2.2697838292311127097)**2 + 71.601009524390834657) - 0.75272007756453937434*(t + 0.2087586382501301251)/((t + 0.2087586382501301251)**2 + 120.80780873960602178) + 0.018878050621472337756*(t + 3.7032750494234480603)/((t + 3.7032750494234480603)**2 + 186.49649269223942035) - 0.00014308576127178134571*(t + 8.8977731864688888199)/((t + 8.8977731864688888199)**2 + 276.58958290348522919) + 1.8321743782540412751e-14 - 0.0047767652469976357985/((t + 8.8977731864688888199)**2 + 276.58958290348522919) + 0.46936381903823868629/((t + 3.7032750494234480603)**2 + 186.49649269223942035) - 7.3681777160983042402/((t + 0.2087586382501301251)**2 + 120.80780873960602178) + 22.355562826040667594/((t - 2.2697838292311127097)**2 + 71.601009524390834657) + 69.756437383145272331/((t - 3.9933697105785685194)**2 + 36.05800305158713521) - 327.61405412572407756/((t - 5.0893450605806245066)**2 + 12.879657911321636066) + 243.94195369821266069/((t - 5.6231425727459771248)**2 + 1.4258008874367907553)

In [300]:
correct_partial_frac14


Out[300]:
$$1.8321743782540412751 \cdot 10^{-14} + \frac{-0.000071542880635890672853 + 0.00014361043349541300111 i}{t + 8.8977731864688888199 + 16.630982619902085304 i} + \frac{-0.000071542880635890672853 + 0.00014361043349541300111 i}{t + 8.8977731864688888199 - 16.630982619902085304 i} + \frac{0.0094390253107361688779 - 0.017184791958483017511 i}{t + 3.7032750494234480603 + 13.656371871483268171 i} + \frac{0.0094390253107361688779 - 0.017184791958483017511 i}{t + 3.7032750494234480603 - 13.656371871483268171 i} + \frac{-0.37636003878226968717 + 0.33518347029450104214 i}{t + 0.2087586382501301251 + 10.991260561901260913 i} + \frac{-0.37636003878226968717 + 0.33518347029450104214 i}{t + 0.2087586382501301251 - 10.991260561901260913 i} + \frac{4.8071120988325088907 - 1.3209793837428723881 i}{t - 2.2697838292311127097 + 8.4617379730402214019 i} + \frac{4.8071120988325088907 - 1.3209793837428723881 i}{t - 2.2697838292311127097 - 8.4617379730402214019 i} + \frac{-23.498232091082701191 - 5.8083591297142074004 i}{t - 3.9933697105785685194 + 6.0048316422350373178 i} + \frac{-23.498232091082701191 - 5.8083591297142074004 i}{t - 3.9933697105785685194 - 6.0048316422350373178 i} + \frac{46.933274488831293047 + 45.643649768827760791 i}{t - 5.0893450605806245066 + 3.5888240290270065102 i} + \frac{46.933274488831293047 + 45.643649768827760791 i}{t - 5.0893450605806245066 - 3.5888240290270065102 i} + \frac{-27.875161940145646468 - 102.14733999056451434 i}{t - 5.6231425727459771248 + 1.1940690463439669766 i} + \frac{-27.875161940145646468 - 102.14733999056451434 i}{t - 5.6231425727459771248 - 1.1940690463439669766 i}$$

In [105]:
a, d = map(lambda i: Poly(i, t), cancel(correct_partial_frac14).as_numer_denom())
collect((a*expand_complex(1/d.TC())), t)/collect((d*expand_complex(1/d.TC())), t)


Out[105]:
$$\frac{t^{14} \left(4.1610013267680032081 \cdot 10^{-28} - 1.4081503120546971001 \cdot 10^{-49} i\right) + t^{13} \left(3.779453173892364441 \cdot 10^{-24} - 2.8758542814990479636 \cdot 10^{-12} i\right) + t^{12} \left(-3.4890692284773452702 \cdot 10^{-14} + 7.2322314480985543123 \cdot 10^{-12} i\right) + t^{11} \left(-1.2321643128679549557 \cdot 10^{-12} - 1.6025439961748732047 \cdot 10^{-9} i\right) + t^{10} \left(-5.1286267280928761482 \cdot 10^{-11} + 1.9094141389392997682 \cdot 10^{-8} i\right) + t^{9} \left(-1.1380644939022783493 \cdot 10^{-9} - 5.061728106696061879 \cdot 10^{-7} i\right) + t^{8} \left(-2.6527904706759976828 \cdot 10^{-8} + 7.2279443118221422325 \cdot 10^{-6} i\right) + t^{7} \left(-4.1082433888869133305 \cdot 10^{-7} - 0.00010885611539993569018 i\right) + t^{6} \left(-6.0633575239283197484 \cdot 10^{-6} + 0.0012678056252250066369 i\right) + t^{5} \left(-0.000059585676942834930371 - 0.013108081429793572853 i\right) + t^{4} \left(-0.00046952254224930496879 + 0.10853264065332626775 i\right) + t^{3} \left(-0.0014671342809875658267 - 0.72788923849380660069 i\right) + t^{2} \left(0.0073290229829175712606 + 3.658133105536471863 i\right) + t \left(0.12502022376449822838 - 12.475356708358264157 i\right) + 0.49181395414703010793 + 23.754303565936798037 i}{t^{14} \left(2.2710727625899900356 \cdot 10^{-14} - 7.6856784417899402515 \cdot 10^{-36} i\right) + t^{13} \left(-1.8921825619816040685 \cdot 10^{-13} - 5.1385881603842166496 \cdot 10^{-35} i\right) + t^{12} \left(1.2922822504467752627 \cdot 10^{-11} - 5.6044436671357284533 \cdot 10^{-33} i\right) + t^{11} \left(-2.2472046467801858052 \cdot 10^{-10} - 2.2443032241826525671 \cdot 10^{-32} i\right) + t^{10} \left(4.8361843519832766538 \cdot 10^{-9} + 8.8475407697290700334 \cdot 10^{-31} i\right) + t^{9} \left(-8.0164052804759259082 \cdot 10^{-8} - 2.3299130248932399591 \cdot 10^{-29} i\right) + t^{8} \left(1.1820298688854367873 \cdot 10^{-6} + 4.2700023299595191379 \cdot 10^{-28} i\right) + t^{7} \left(-0.000014908242237501135663 - 4.6369746398141080608 \cdot 10^{-27} i\right) + t^{6} \left(0.00016019218139205361321 + 2.8409514388416528924 \cdot 10^{-26} i\right) + t^{5} \left(-0.0014405532019175131073 - 8.220315298217294957 \cdot 10^{-27} i\right) + t^{4} \left(0.010574051936471403138 - 1.5955231152223676905 \cdot 10^{-24} i\right) + t^{3} \left(-0.060968196803506756465 + 1.0057119624872968603 \cdot 10^{-23} i\right) + t^{2} \left(0.25939097352682521924 - 9.8357617656798832547 \cdot 10^{-23} i\right) + t \left(-0.72504400105794986064 + 1.3961157860943764366 \cdot 10^{-22} i\right) + \left(2.2710727625899901428 \cdot 10^{-14} - 7.685678441789939598 \cdot 10^{-36} i\right) \left(44032054651546.0 + 1.490116119384765625 \cdot 10^{-8} i\right)}$$

In [106]:
correct_rat_func14


Out[106]:
$$\frac{4.1609826642376611 \cdot 10^{-28} t^{14} - 3.7794523874503298 \cdot 10^{-24} t^{13} + 5.6743825539523504 \cdot 10^{-21} t^{12} - 3.3490280333667535 \cdot 10^{-18} t^{11} + 1.0310151365350496 \cdot 10^{-15} t^{10} - 1.9038640942835346 \cdot 10^{-13} t^{9} + 2.2849515765300154 \cdot 10^{-11} t^{8} - 1.8710255961089454 \cdot 10^{-9} t^{7} + 1.0753202054485227 \cdot 10^{-7} t^{6} - 4.3932808492511235 \cdot 10^{-6} t^{5} + 0.00012734070715233182 t^{4} - 0.002567443981902862 t^{3} + 0.034346984175671474 t^{2} - 0.27495604296300041 t + 0.99999999999998168}{2.2710680218891296 \cdot 10^{-14} t^{14} + 1.8921838854022448 \cdot 10^{-13} t^{13} + 1.292280270579278 \cdot 10^{-11} t^{12} + 2.2472030400428528 \cdot 10^{-10} t^{11} + 4.8361800878648284 \cdot 10^{-9} t^{10} + 8.0163997982357503 \cdot 10^{-8} t^{9} + 1.1820291576355772 \cdot 10^{-6} t^{8} + 1.4908234724800242 \cdot 10^{-5} t^{7} + 0.00016019211440612189 t^{6} + 0.0014405527154587316 t^{5} + 0.010574049161691156 t^{4} + 0.060968185127283595 t^{3} + 0.25939094125018014 t^{2} + 0.72504395703488667 t + 1.0}$$

There are a lot of errors here. I think there must be a lot of loss of precision. Also, I think one expression is representing $e^t$ and one $e^{-t}$, which would explain the wrong signs on the odd-powered $t$ terms. See https://github.com/sympy/sympy/issues/11795.


In [107]:
together(correct_partial_frac14)


Out[107]:
$$\frac{1}{\left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right)} \left(1.8321743782540412751 \cdot 10^{-14} \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(-0.000071542880635890672853 + 0.00014361043349541300111 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) + \left(-0.000071542880635890672853 + 0.00014361043349541300111 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(0.0094390253107361688779 - 0.017184791958483017511 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(0.0094390253107361688779 - 0.017184791958483017511 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(-0.37636003878226968717 + 0.33518347029450104214 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(-0.37636003878226968717 + 0.33518347029450104214 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(4.8071120988325088907 - 1.3209793837428723881 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(4.8071120988325088907 - 1.3209793837428723881 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(-23.498232091082701191 - 5.8083591297142074004 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(-23.498232091082701191 - 5.8083591297142074004 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(46.933274488831293047 + 45.643649768827760791 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(46.933274488831293047 + 45.643649768827760791 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(-27.875161940145646468 - 102.14733999056451434 i\right) \left(t - 5.6231425727459771248 - 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right) + \left(-27.875161940145646468 - 102.14733999056451434 i\right) \left(t - 5.6231425727459771248 + 1.1940690463439669766 i\right) \left(t - 5.0893450605806245066 - 3.5888240290270065102 i\right) \left(t - 5.0893450605806245066 + 3.5888240290270065102 i\right) \left(t - 3.9933697105785685194 - 6.0048316422350373178 i\right) \left(t - 3.9933697105785685194 + 6.0048316422350373178 i\right) \left(t - 2.2697838292311127097 - 8.4617379730402214019 i\right) \left(t - 2.2697838292311127097 + 8.4617379730402214019 i\right) \left(t + 0.2087586382501301251 - 10.991260561901260913 i\right) \left(t + 0.2087586382501301251 + 10.991260561901260913 i\right) \left(t + 3.7032750494234480603 - 13.656371871483268171 i\right) \left(t + 3.7032750494234480603 + 13.656371871483268171 i\right) \left(t + 8.8977731864688888199 - 16.630982619902085304 i\right) \left(t + 8.8977731864688888199 + 16.630982619902085304 i\right)\right)$$

In [108]:
# var('_w _a')
# issue_answer = S("-1.0*RootSum(2.2710680218891296e-14*_w**14 + 1.8921838854022448e-13*_w**13 + 1.292280270579278e-11*_w**12 + 2.2472030400428528e-10*_w**11 + 4.8361800878648284e-9*_w**10 + 8.0163997982357503e-8*_w**9 + 1.1820291576355772e-6*_w**8 + 1.4908234724800242e-5*_w**7 + 0.00016019211440612189*_w**6 + 0.0014405527154587316*_w**5 + 0.010574049161691156*_w**4 + 0.060968185127283595*_w**3 + 0.25939094125018014*_w**2 + 0.72504395703488667*_w + 1.0, Lambda(_a, (3.7997502361189504e-11*_a**13 - 9.6301335874438056e-11*_a**12 + 2.2157750448607173e-8*_a**11 + 1.4101105165363766e-7*_a**10 + 6.2233711263991178e-6*_a**9 + 6.7342488958142767e-5*_a**8 + 0.0011644621826545941*_a**7 + 0.012030053971086767*_a**6 + 0.12615589337787736*_a**5 + 0.97182363139568362*_a**4 + 6.2658937818543281*_a**3 + 28.994072695533735*_a**2 + 90.256649069691846*_a + 138.65741216748256)/(-_a + x))) + 1.8321699852813983e-14")
# issue_answer

In [109]:
correct_rat_func14


Out[109]:
$$\frac{4.1609826642376611 \cdot 10^{-28} t^{14} - 3.7794523874503298 \cdot 10^{-24} t^{13} + 5.6743825539523504 \cdot 10^{-21} t^{12} - 3.3490280333667535 \cdot 10^{-18} t^{11} + 1.0310151365350496 \cdot 10^{-15} t^{10} - 1.9038640942835346 \cdot 10^{-13} t^{9} + 2.2849515765300154 \cdot 10^{-11} t^{8} - 1.8710255961089454 \cdot 10^{-9} t^{7} + 1.0753202054485227 \cdot 10^{-7} t^{6} - 4.3932808492511235 \cdot 10^{-6} t^{5} + 0.00012734070715233182 t^{4} - 0.002567443981902862 t^{3} + 0.034346984175671474 t^{2} - 0.27495604296300041 t + 0.99999999999998168}{2.2710680218891296 \cdot 10^{-14} t^{14} + 1.8921838854022448 \cdot 10^{-13} t^{13} + 1.292280270579278 \cdot 10^{-11} t^{12} + 2.2472030400428528 \cdot 10^{-10} t^{11} + 4.8361800878648284 \cdot 10^{-9} t^{10} + 8.0163997982357503 \cdot 10^{-8} t^{9} + 1.1820291576355772 \cdot 10^{-6} t^{8} + 1.4908234724800242 \cdot 10^{-5} t^{7} + 0.00016019211440612189 t^{6} + 0.0014405527154587316 t^{5} + 0.010574049161691156 t^{4} + 0.060968185127283595 t^{3} + 0.25939094125018014 t^{2} + 0.72504395703488667 t + 1.0}$$

In [110]:
num = correct_rat_func14.as_numer_denom()[0]

In [111]:
Poly(num, domain=QQ)


Out[111]:
$$\operatorname{Poly}{\left( \frac{4639650708533359 t^{14}}{11150372599265311570767859136324180752990208} - \frac{643040502033295 t^{13}}{170141183460469231731687303715884105728} + \frac{7542548149506975 t^{12}}{1329227995784915872903807060280344576} - \frac{8694573868397633 t^{11}}{2596148429267413814265248164610048} + \frac{2613933913346091 t^{10}}{2535301200456458802993406410752} - \frac{3 t^{9}}{15757427271241} + \frac{601 t^{8}}{26302526765696} - \frac{33563 t^{7}}{17938290138734} + \frac{1716787 t^{6}}{15965356098595} - \frac{134754206 t^{5}}{30672795713247} + \frac{2733076359 t^{4}}{21462707567114} - \frac{25569550907 t^{3}}{9959146562586} + \frac{133063128409 t^{2}}{3874084773453} - \frac{7460243800684 t}{27132496235727} + \frac{45035996273703}{45035996273704}, t, domain=\mathbb{Q} \right)}$$

In [112]:
Poly(num, domain=QQ).as_expr().evalf(17)


Out[112]:
$$4.1609826642376611 \cdot 10^{-28} t^{14} - 3.7794523874503298 \cdot 10^{-24} t^{13} + 5.6743825539523504 \cdot 10^{-21} t^{12} - 3.3490280333667535 \cdot 10^{-18} t^{11} + 1.0310151365350496 \cdot 10^{-15} t^{10} - 1.90386409428354 \cdot 10^{-13} t^{9} + 2.2849515765300153 \cdot 10^{-11} t^{8} - 1.8710255961089454 \cdot 10^{-9} t^{7} + 1.0753202054485227 \cdot 10^{-7} t^{6} - 4.3932808492511235 \cdot 10^{-6} t^{5} + 0.00012734070715233182 t^{4} - 0.002567443981902862 t^{3} + 0.034346984175671474 t^{2} - 0.27495604296300041 t + 0.9999999999999778$$

In [113]:
num.replace(lambda i: i.is_Float, Rational)


Out[113]:
$$4.1609826642376611 \cdot 10^{-28} t^{14} - 3.7794523874503298 \cdot 10^{-24} t^{13} + 5.6743825539523504 \cdot 10^{-21} t^{12} - 3.3490280333667535 \cdot 10^{-18} t^{11} + 1.0310151365350496 \cdot 10^{-15} t^{10} - 1.9038640942835346 \cdot 10^{-13} t^{9} + 2.2849515765300154 \cdot 10^{-11} t^{8} - 1.8710255961089454 \cdot 10^{-9} t^{7} + 1.0753202054485227 \cdot 10^{-7} t^{6} - 4.3932808492511235 \cdot 10^{-6} t^{5} + 0.00012734070715233182 t^{4} - 0.002567443981902862 t^{3} + 0.034346984175671474 t^{2} - 0.27495604296300041 t + 0.99999999999998168$$

In [114]:
Float("1.01").replace(lambda i: i.is_Float, lambda i: Rational(i))


Out[114]:
$$1.01$$

In [115]:
correct_rat_func14_rational = Poly(reversed(list(map(Rational, n14pi))), t)/Poly(reversed(list(map(Rational, n14qi))), t)
correct_rat_func14_rational


Out[115]:
$$\frac{\frac{4639650708533359 t^{14}}{11150372599265311570767859136324180752990208} - \frac{643040502033295 t^{13}}{170141183460469231731687303715884105728} + \frac{7542548149506975 t^{12}}{1329227995784915872903807060280344576} - \frac{8694573868397633 t^{11}}{2596148429267413814265248164610048} + \frac{2613933913346091 t^{10}}{2535301200456458802993406410752} - \frac{1885495673337107 t^{9}}{9903520314283042199192993792} + \frac{7071582611036897 t^{8}}{309485009821345068724781056} - \frac{2261931152295957 t^{7}}{1208925819614629174706176} + \frac{8124889754500167 t^{6}}{75557863725914323419136} - \frac{5186670558084149 t^{5}}{1180591620717411303424} + \frac{4698042870008521 t^{4}}{36893488147419103232} - \frac{1480030689304621 t^{3}}{576460752303423488} + \frac{1237480521078835 t^{2}}{36028797018963968} - \frac{4953167730525739 t}{18014398509481984} + \frac{9007199254740827}{9007199254740992}}{\frac{7028615090593 t^{14}}{309485009821345068724781056} + \frac{7495712618976059 t^{13}}{39614081257132168796771975168} + \frac{3999413722321583 t^{12}}{309485009821345068724781056} + \frac{8693445686477735 t^{11}}{38685626227668133590597632} + \frac{5846582976525937 t^{10}}{1208925819614629174706176} + \frac{6057020435275439 t^{9}}{75557863725914323419136} + \frac{2790987437896445 t^{8}}{2361183241434822606848} + \frac{4400134248946877 t^{7}}{295147905179352825856} + \frac{5910045874152263 t^{6}}{36893488147419103232} + \frac{12975345345095 t^{5}}{9007199254740992} + \frac{1523881083660467 t^{4}}{144115188075855872} + \frac{4393220733131037 t^{3}}{72057594037927936} + \frac{2336385892715187 t^{2}}{9007199254740992} + \frac{6530615389459091 t}{9007199254740992} + 1}$$

In [116]:
#apart_correct_rat_func14_rational = apart(correct_rat_func14_rational.subs(t, x), x, full=True).doit().evalf(17).expand().subs(x, t)
#apart_correct_rat_func14_rational

In [117]:
#apart_correct_rat_func14_rational*2

In [118]:
#correct_partial_frac14

In [119]:
#apart(correct_rat_func14_rational.subs(t, x), x, full=True).doit()

In [120]:
correct_partial_frac14_rational = Rational(re(alpha0)) + Rational(im(alpha0))*I + Add(*((Rational(re(alpha)) + Rational(im(alpha))*I)/(t - Rational(re(theta)) - Rational(im(theta))*I) + (Rational(re(alpha)) + Rational(im(alpha))*I)/(t - Rational(re(theta)) + Rational(im(theta))*I) for alpha, theta in zip(alphas, thetas)))
correct_partial_frac14_rational


Out[120]:
$$\frac{90724880871739}{4951760157141521099596496896} + \frac{- \frac{659866604693113}{9223372036854775808} + \frac{5298289826008739 i}{36893488147419103232}}{t + \frac{1252250250219015}{140737488355328} + \frac{585150680701533 i}{35184372088832}} + \frac{- \frac{659866604693113}{9223372036854775808} + \frac{5298289826008739 i}{36893488147419103232}}{t + \frac{1252250250219015}{140737488355328} - \frac{585150680701533 i}{35184372088832}} + \frac{\frac{1360306907909507}{144115188075855872} - \frac{4953179050282471 i}{288230376151711744}}{t + \frac{2084758516579237}{562949953421312} + \frac{7687853908955621 i}{562949953421312}} + \frac{\frac{1360306907909507}{144115188075855872} - \frac{4953179050282471 i}{288230376151711744}}{t + \frac{2084758516579237}{562949953421312} - \frac{7687853908955621 i}{562949953421312}} + \frac{- \frac{6779899721667901}{18014398509481984} + \frac{3019064303838129 i}{9007199254740992}}{t + \frac{3760661301734633}{18014398509481984} + \frac{3093764810681909 i}{281474976710656}} + \frac{- \frac{6779899721667901}{18014398509481984} + \frac{3019064303838129 i}{9007199254740992}}{t + \frac{3760661301734633}{18014398509481984} - \frac{3093764810681909 i}{281474976710656}} + \frac{\frac{1353081766064393}{281474976710656} - \frac{1487290565097127 i}{1125899906842624}}{t - \frac{638887350471051}{281474976710656} + \frac{1190883749446585 i}{140737488355328}} + \frac{\frac{1353081766064393}{281474976710656} - \frac{1487290565097127 i}{1125899906842624}}{t - \frac{638887350471051}{281474976710656} - \frac{1190883749446585 i}{140737488355328}} + \frac{- \frac{6614164330579093}{281474976710656} - \frac{6539631003053731 i}{1125899906842624}}{t - \frac{8992269170257133}{2251799813685248} + \frac{6760839386598069 i}{1125899906842624}} + \frac{- \frac{6614164330579093}{281474976710656} - \frac{6539631003053731 i}{1125899906842624}}{t - \frac{8992269170257133}{2251799813685248} - \frac{6760839386598069 i}{1125899906842624}} + \frac{\frac{6605271171849307}{140737488355328} + \frac{6423772627835067 i}{140737488355328}}{t - \frac{2865046564798847}{562949953421312} + \frac{4040656639956077 i}{1125899906842624}} + \frac{\frac{6605271171849307}{140737488355328} + \frac{6423772627835067 i}{140737488355328}}{t - \frac{2865046564798847}{562949953421312} - \frac{4040656639956077 i}{1125899906842624}} + \frac{- \frac{1961540139477065}{70368744177664} - \frac{3593990018112451 i}{35184372088832}}{t - \frac{6331095698817489}{1125899906842624} + \frac{5377608912169333 i}{4503599627370496}} + \frac{- \frac{1961540139477065}{70368744177664} - \frac{3593990018112451 i}{35184372088832}}{t - \frac{6331095698817489}{1125899906842624} - \frac{5377608912169333 i}{4503599627370496}}$$

In [121]:
a, d = map(lambda i: Poly(i, t), cancel(correct_partial_frac14_rational).as_numer_denom())
expr = collect((a*expand_complex(1/d.TC())), t)/collect((d*expand_complex(1/d.TC())), t)
expr


Out[121]:
$$\frac{1}{\frac{10520271803096747014481979765760257331100679605646347718996561806137464308594161644227333072555176902453965937712356435426038864500367607726255629541303761699910447342256889196383327515768645434542586503471562752 t^{14}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{87651418224155884959811114040529369578980232035191004278685708706617506768459301066755083254523088164919749667689453756482070352849712138239701285035791420586699468889075623256385919265052377197978447240247640064 t^{13}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} + \frac{665136501175542510153970710111188608826344758499247335813609691976990082412059001357216489216195369225005315166341731182477815061914237626479201313973715379267163675840001857716193047362748953554327062239619579904 t^{12}}{51469909220341591924425740208981296734951999147232069746231349908301931495631056197885577158658651824168160394532741961752262913576478692156138613289668813786926834819410754803845485536467861015100633181998532908120571878125} - \frac{11566341916930594903124684440955673523015819086081552459772650548494066071264779895944171118830458926119693490937446324194153128531567095906813424745026810932577982323163148051799253968446579984290620717509820547072 t^{11}}{51469909220341591924425740208981296734951999147232069746231349908301931495631056197885577158658651824168160394532741961752262913576478692156138613289668813786926834819410754803845485536467861015100633181998532908120571878125} + \frac{2240261726124741868202776521371087939971572721595788126042375164420850213638850522558762082519939697302130795933825958869106960365918104948182437285110409454390750011714663523309320611436701873300447942509036058968064 t^{10}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{7426865737072131625873275116658026099783179792034867475323526482477330361965796802645615402969608045355492674729974393022498403096460196862057793979587352437021150516049950384415362511603003719125805155529752058003456 t^{9}}{92645836596614865463966332376166334122913598465017725543216429834943476692135901156194038885585573283502688710158935531154073244437661645881049503921403864816468302674939358646921873965642149827181139727597359234617029380625} + \frac{547550730425391258363023533212500146012045624367253048129332103041561751537891580044666139020984792755953779783918015069902082528833099620840346057254959106074083672416968944257818771871377027086633263517295742786994176 t^{8}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{6905932871391410536085439009308249222509479102283609412573715130764594958558531706823233771093728852799039375415194469689145778317030663257425040821346852772581116217956085901485138999461731371379606422948152911847227392 t^{7}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} + \frac{74205693306517432050629263212037187492081660763701179951794748764461040469375157166789210048784454835726594480310569605163083410056462387576835827760332051057813913908169411903538143510896689491630089576590405358105657344 t^{6}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{667306282767901239072698711414901524497491911900758341622151504509263345711359069218864919931440093593592748302130532044059038268170481804193108337923075155641333768199223281646368270793171865363911005442673826039506927616 t^{5}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} + \frac{544245493261360271814150623149686109732469995360259879697029355357506956764635086695289422225050771799413711489775519102231830102479476731295638455394684533137812914204457528813062277347563363240193422183749035492032643072 t^{4}}{51469909220341591924425740208981296734951999147232069746231349908301931495631056197885577158658651824168160394532741961752262913576478692156138613289668813786926834819410754803845485536467861015100633181998532908120571878125} - \frac{5648449598647942932797915791869414908026921128353182457431739820157779889472044593160942579838257755748338803123998584774068127529449481555538883424685687706103284856401699251736804342719846866610029523078911837708729974784 t^{3}}{92645836596614865463966332376166334122913598465017725543216429834943476692135901156194038885585573283502688710158935531154073244437661645881049503921403864816468302674939358646921873965642149827181139727597359234617029380625} + \frac{4806298749600620357998674608796950635441547848721344654190919523601967609934007838174094368467383431514282399130914305944068817766338824505553897655417139453429712945923423878606294963512175653118859971229064880525171228672 t^{2}}{18529167319322973092793266475233266824582719693003545108643285966988695338427180231238807777117114656700537742031787106230814648887532329176209900784280772963293660534987871729384374793128429965436227945519471846923405876125} - \frac{895630773964942315516185201307410360175285709548684637219724394521227239901402732821982285179560497995959134047808347586083118726744331939040793772770722278274782789883145788440332136479722586294504192471228326706992381952 t}{1235277821288198206186217765015551121638847979533569673909552397799246355895145348749253851807807643780035849468785807082054309925835488611747326718952051530886244035665858115292291652875228664362415196367964789794893725075} + 1} \left(\frac{192749724499023038946627124533803454040338019097132075370735468811581050042520941159123450206829742707937665642528362608192940469744932284786373308427266889138511801531808311024968399883697146298368 t^{14}}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} + t^{13} \left(\frac{1750782562955620783315470971945232101868679186925137316459081176512610084520421731911519688364233998128596699644405354254102610818115065569782532801092662878677654313571266408040179229040316313380061184}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{1332179629197180356316829511983847226820483449424111477728523980086484287023395780040169461551194216109379225337279222386995457042456093126127686503786577936370924671736627763837270374590151006272109069752927780864 i}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125}\right) + t^{12} \left(- \frac{47676657465455348293095916408478155566575539033928833387271092453348603547984637345628855477634325752813202239624401605899163135766095271209544372278290947659070047484272685892427153372728562664086142827102208}{1366457766911723679409532925902158320396955729572532825121186280751378712273390872510236561734300490907119302509718813143865387086101204216534653450168198596113101809364887295677313775304456487126565482707925652427979784375} + \frac{1116726888282396382845115825832780425968114187136865742035152115572851629441026523544911464066020289731484974390365392315103166614521060116885215385826091990025973495141901056558891022504659302125277332484787273728 i}{154409727661024775773277220626943890204855997441696209238694049724905794486893168593656731475975955472504481183598225885256788740729436076468415839869006441360780504458232264411536456609403583045301899545995598724361715634375}\right) + t^{11} \left(- \frac{190258155983569696437974082698737054779341340148257062795138605311356644899261152921513759212810339226091963592404346173737054472714425155155278024316351907186259362809686510145485174661425529798443569509327437824}{154409727661024775773277220626943890204855997441696209238694049724905794486893168593656731475975955472504481183598225885256788740729436076468415839869006441360780504458232264411536456609403583045301899545995598724361715634375} - \frac{82482794004724167159399738367826025516908078955917622605922478676511385983517567802624083349453073766831748311034935372225867039093997420557524139449145781969222958416333155971392363104246499309149879232762851885056 i}{51469909220341591924425740208981296734951999147232069746231349908301931495631056197885577158658651824168160394532741961752262913576478692156138613289668813786926834819410754803845485536467861015100633181998532908120571878125}\right) + t^{10} \left(- \frac{23757295690796321966946152928545207627658350995949674520330305972693561612806576953740947024573565112967397687361024122910188620207812156882484613246004315427868044913422971516034512143815725844529990210894138703872}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} + \frac{982773723952424587956888070136299282773810314756218731663887041982626431270601642805311518625911847442951625149429398690513280650450379995970464024016021958352676834940728433280352048948178321199775294882056442478592 i}{51469909220341591924425740208981296734951999147232069746231349908301931495631056197885577158658651824168160394532741961752262913576478692156138613289668813786926834819410754803845485536467861015100633181998532908120571878125}\right) + t^{9} \left(- \frac{527184685692394896513373718510506928611285731583031978975695803227343925089221890513934953875260112130587066456340623761627249974391084694423919819916822102363454884451595757174199689798580272547497304431023511044096}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{78158005844909343699062636847854384287823783217534547788804672411219799785429572388493365394291952026540310701547146074507852286727230395160694167311568892346227591993596977913628580034938248695452642338687058396053504 i}{154409727661024775773277220626943890204855997441696209238694049724905794486893168593656731475975955472504481183598225885256788740729436076468415839869006441360780504458232264411536456609403583045301899545995598724361715634375}\right) + t^{8} \left(- \frac{12288499623565323281646947286544689324364022516809304003056099873116231217444224474104955072030714122846163151996150379054780518831105429766260732867218487202529725233592515757708446953765896643295082110448477923180544}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} + \frac{1116064912737510094818262885116260095732238539649345073663534672571663349824999823135916166679739335595200712179960857959449054267600029005366558340012906835049753481913001330986765368307381720073361109529525126921453568 i}{154409727661024775773277220626943890204855997441696209238694049724905794486893168593656731475975955472504481183598225885256788740729436076468415839869006441360780504458232264411536456609403583045301899545995598724361715634375}\right) + t^{7} \left(- \frac{190305822852969541716738332774966855382781016967067656134109757641180917143816729798308870333135679019459781642785353976275015464354220289766323155812460995900917232038842003641725901108088877187641416893186983069745152}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{16808443133141153589342493924997000729166050548920147833072201266897364474784063606767483602197798473238678567870396514212744254594932931299411421107339590772395113505053858026732676459706683213920606855313191156571963392 i}{154409727661024775773277220626943890204855997441696209238694049724905794486893168593656731475975955472504481183598225885256788740729436076468415839869006441360780504458232264411536456609403583045301899545995598724361715634375}\right) + t^{6} \left(- \frac{561744830388719745411424781801965203817099446102664242641977033068206113565731242748840051102268157274754251098372394118514744453033429954702899440515099887594166803184651108338602463008731080860769014210734962639896576}{92645836596614865463966332376166334122913598465017725543216429834943476692135901156194038885585573283502688710158935531154073244437661645881049503921403864816468302674939358646921873965642149827181139727597359234617029380625} + \frac{117456912790865098347204818904039375183614218492052472704074187148145065491780896317583879450744969715492487683377639370711597722121340028286938201645494186611415624798237587563151326852567671648626316767279297788999892992 i}{92645836596614865463966332376166334122913598465017725543216429834943476692135901156194038885585573283502688710158935531154073244437661645881049503921403864816468302674939358646921873965642149827181139727597359234617029380625}\right) + t^{5} \left(- \frac{27601824447722771257562841413691994344915272352301745790761600662605529527748331968536160766692528579501269000825070290208896132188888986794780847646747558902230797986941694551922008043638006971256578419645950393617219584}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} - \frac{6072045851198884274031054108373125166418374980072871394022210623443397125165573980928381970340098176399927465697950262502226843999695512294128589309229650350796704901972123881394435731268292002036481114427706759142390628352 i}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125}\right) + t^{4} \left(- \frac{217496543638281978044883089493209899904776746890211216030613354835425326388318401459852392336742770935781397338022101035640591887897514006458041762943145677427194513866855984177117269379374687155518185994189163623348174848}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125} + \frac{10055097291367182815519490351432730476476127189572573686781336471430754805042885868082962561900654425266931377176496542344567740321752959160281316946496890617631621360880624655602640745479514666692294014477171627126819913728 i}{92645836596614865463966332376166334122913598465017725543216429834943476692135901156194038885585573283502688710158935531154073244437661645881049503921403864816468302674939358646921873965642149827181139727597359234617029380625}\right) + t^{3} \left(- \frac{226539804769442347527484103585227834115780745951812258850951493506632555855918420263371343879514472191342904763542004608121157882387328676155654530674254511068850201093687725893921541511123663415714505981357204744200781824}{154409727661024775773277220626943890204855997441696209238694049724905794486893168593656731475975955472504481183598225885256788740729436076468415839869006441360780504458232264411536456609403583045301899545995598724361715634375} - \frac{337179537249658137072303064575780807087735730932068983108081245127249375626988117703974856782246789347144601026094238087101589689744214655068868806332894649517237273540245598667415660619109903940289129097285057121605856002048 i}{463229182983074327319831661880831670614567992325088627716082149174717383460679505780970194427927866417513443550794677655770366222188308229405247519607019324082341513374696793234609369828210749135905698637986796173085146903125}\right) + t^{2} \left(\frac{1250466787639435510024366661212322638369068299219734597047568625544738439365531561654114153428896970625031457827907303438269321177601963122512134540466730052828972035174859099856544856386963693079154425537034257123868292}{170618483603342293672129525554634132823045301040548297501319391961221872361207921097963239199973431461330918434915166724040650542242470802727531314772382808133459120948322944101145255921992909442322540934801766546256039375} + \frac{338910801944199229329595706566624930675245315278656356764122700610380674548363120915105518789036154898548563489747785935581603042177195384529639381978547632412713322826674755209061333102704146837068083741633056678972424716288 i}{92645836596614865463966332376166334122913598465017725543216429834943476692135901156194038885585573283502688710158935531154073244437661645881049503921403864816468302674939358646921873965642149827181139727597359234617029380625}\right) + t \left(\frac{40752662152570974773542274587831576929752325716805412729845249320200665379936407901384482098109464251304513616866024784927781317269454525314053424239421435804967847487159680515275108551609583234041809829851562880551567678713621525944189}{325968558729642632376463576269373747129649356505847342095088353927955177800713794235057753983993711052435770849854301035298106345102025260869747282329152187428648060690017373529492897586763252651520038500791915781032945479233954643968000} - \frac{46231594363481703857886171450316541849103285176754440115705494856895520155898633071611311462366152136375025247110092288210996379294046658138256223893120763748013082689173499977932412414922605931299290708393165495378424889344 i}{3705833463864594618558653295046653364916543938600709021728657193397739067685436046247761555423422931340107548406357421246162929777506465835241980156856154592658732106997574345876874958625685993087245589103894369384681175225}\right) + \frac{601665469611991358698300258000776197633183332990932701645027430917535333615104484451314673296922160972163606786480163160268379441414140558621161217196216458490686461453416347491162642816521539520677038523865637348853439663484919890786836175325493037}{1223359899691096833457530968658989923541815882014225567638643105115703981994087504671011757562236498905124374175787122086418237238318017875193742922777526143036429220059499998286960469911732654469164870357974732750387323803499130457152888216422973440} + \frac{3846067238358074514893082242884250714807452736759104386377285312057770979195502422420016799661681408701168268488120741711077732842228524761105263394062007797172448606030689420233536577570165360619379760914491030465541394956877807 i}{161910334591886715281239934896118316615447082373424044298672851884342818359888491151262200864152963485536858861572693305859022510599109163318945607706483298256321778242795354887591251525661971495310484618341880927996310333030400}\right)$$

In [122]:
expr.evalf()


Out[122]:
$$\frac{4.161001326768 \cdot 10^{-28} t^{14} + t^{13} \left(3.77951698051716 \cdot 10^{-24} - 2.87585428149905 \cdot 10^{-12} i\right) + t^{12} \left(-3.48906922847732 \cdot 10^{-14} + 7.23223144809855 \cdot 10^{-12} i\right) + t^{11} \left(-1.23216431286792 \cdot 10^{-12} - 1.60254399617487 \cdot 10^{-9} i\right) + t^{10} \left(-5.1286267280929 \cdot 10^{-11} + 1.9094141389393 \cdot 10^{-8} i\right) + t^{9} \left(-1.13806449390227 \cdot 10^{-9} - 5.06172810669606 \cdot 10^{-7} i\right) + t^{8} \left(-2.65279047067601 \cdot 10^{-8} + 7.22794431182214 \cdot 10^{-6} i\right) + t^{7} \left(-4.1082433888869 \cdot 10^{-7} - 0.000108856115399936 i\right) + t^{6} \left(-6.06335752392833 \cdot 10^{-6} + 0.00126780562522501 i\right) + t^{5} \left(-5.95856769428348 \cdot 10^{-5} - 0.0131080814297936 i\right) + t^{4} \left(-0.000469522542249306 + 0.108532640653326 i\right) + t^{3} \left(-0.00146713428098756 - 0.727889238493806 i\right) + t^{2} \left(0.00732902298291754 + 3.65813310553647 i\right) + t \left(0.125020223764498 - 12.4753567083583 i\right) + 0.491813954147029 + 23.7543035659368 i}{2.27107276258999 \cdot 10^{-14} t^{14} - 1.8921825619816 \cdot 10^{-13} t^{13} + 1.29228225044678 \cdot 10^{-11} t^{12} - 2.24720464678019 \cdot 10^{-10} t^{11} + 4.83618435198328 \cdot 10^{-9} t^{10} - 8.01640528047593 \cdot 10^{-8} t^{9} + 1.18202986888544 \cdot 10^{-6} t^{8} - 1.49082422375011 \cdot 10^{-5} t^{7} + 0.000160192181392054 t^{6} - 0.00144055320191751 t^{5} + 0.0105740519364714 t^{4} - 0.0609681968035067 t^{3} + 0.259390973526825 t^{2} - 0.72504400105795 t + 1.0}$$

In [123]:
def canonicalize(expr):
    n, d = expr.as_numer_denom()
    return (n/Poly(d).TC())/(d/Poly(d).TC())

In [124]:
expr1 = canonicalize(cancel(Rational(1, 3) + Rational(5, 2)/(x - 2 + I) + Rational(5, 2)/(x - 2 - I)))
expr1.evalf()


Out[124]:
$$\frac{0.0666666666666667 x^{2} + 0.733333333333333 x - 1.66666666666667}{0.2 x^{2} - 0.8 x + 1.0}$$

In [125]:
expr2 = canonicalize(cancel(Rational(1/3) + Rational(5, 2)/(x - 2 + I) + Rational(5, 2)/(x - 2 - I)))
expr2.evalf()


Out[125]:
$$\frac{0.0666666666666667 x^{2} + 0.733333333333333 x - 1.66666666666667}{0.2 x^{2} - 0.8 x + 1.0}$$

In [126]:
expr2 = canonicalize(cancel(Rational(1/3) + Rational(5/2)/(x - Rational(2  + 0.000001) + I) + Rational(5, 2)/(x - 2 - I)))
expr2.evalf()


Out[126]:
$$\frac{0.0666666400000107 x^{2} + 0.733332973333477 x - 1.66666636666679 + 6.66666400093292 \cdot 10^{-8} i}{0.199999920000032 x^{2} - 0.799999880000048 x + 1.0 + 1.99999920027988 \cdot 10^{-7} i}$$

In [127]:
expr1 = canonicalize(cancel(Rational(1, 300000000000000) + Rational(5, 2)/(x - 2 + I) + Rational(5, 2)/(x - 2 - I)))
expr1.evalf()


Out[127]:
$$\frac{6.66666666666667 \cdot 10^{-16} x^{2} + 0.999999999999997 x - 2.0}{0.2 x^{2} - 0.8 x + 1.0}$$

In [128]:
expr2 = canonicalize(cancel(Rational(1/300000000000000) + Rational(5, 2)/(x - 2 + I) + Rational(5, 2)/(x - 2 - I)))
expr2.evalf()


Out[128]:
$$\frac{6.66666666666667 \cdot 10^{-16} x^{2} + 0.999999999999997 x - 2.0}{0.2 x^{2} - 0.8 x + 1.0}$$

In [129]:
correct_rat_func14.as_numer_denom()[1]


Out[129]:
$$2.2710680218891296 \cdot 10^{-14} t^{14} + 1.8921838854022448 \cdot 10^{-13} t^{13} + 1.292280270579278 \cdot 10^{-11} t^{12} + 2.2472030400428528 \cdot 10^{-10} t^{11} + 4.8361800878648284 \cdot 10^{-9} t^{10} + 8.0163997982357503 \cdot 10^{-8} t^{9} + 1.1820291576355772 \cdot 10^{-6} t^{8} + 1.4908234724800242 \cdot 10^{-5} t^{7} + 0.00016019211440612189 t^{6} + 0.0014405527154587316 t^{5} + 0.010574049161691156 t^{4} + 0.060968185127283595 t^{3} + 0.25939094125018014 t^{2} + 0.72504395703488667 t + 1.0$$

In [130]:
roots = intervals(correct_rat_func14_rational.subs(t, -t).as_numer_denom()[1], all=True)
roots


Out[130]:
$$\left ( \left [ \right ], \quad \left [ \left ( \left ( - \frac{70368744177664}{7028615090593} - \frac{140737488355328 i}{7028615090593}, \quad - \frac{105553116266496 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{70368744177664}{7028615090593} + \frac{105553116266496 i}{7028615090593}, \quad \frac{140737488355328 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{35184372088832}{7028615090593} - \frac{87960930222080 i}{7028615090593}, \quad - \frac{70368744177664 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{35184372088832}{7028615090593} + \frac{70368744177664 i}{7028615090593}, \quad \frac{87960930222080 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{35184372088832}{7028615090593} - \frac{105553116266496 i}{7028615090593}, \quad - \frac{87960930222080 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{35184372088832}{7028615090593} + \frac{87960930222080 i}{7028615090593}, \quad \frac{105553116266496 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{52776558133248 i}{7028615090593}, \quad \frac{35184372088832}{7028615090593} - \frac{35184372088832 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( \frac{35184372088832 i}{7028615090593}, \quad \frac{35184372088832}{7028615090593} + \frac{52776558133248 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{70368744177664 i}{7028615090593}, \quad \frac{35184372088832}{7028615090593} - \frac{52776558133248 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( \frac{52776558133248 i}{7028615090593}, \quad \frac{35184372088832}{7028615090593} + \frac{70368744177664 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( \frac{35184372088832}{7028615090593} - \frac{17592186044416 i}{7028615090593}, \quad \frac{70368744177664}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( \frac{35184372088832}{7028615090593}, \quad \frac{70368744177664}{7028615090593} + \frac{17592186044416 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( \frac{35184372088832}{7028615090593} - \frac{35184372088832 i}{7028615090593}, \quad \frac{70368744177664}{7028615090593} - \frac{17592186044416 i}{7028615090593}\right ), \quad 1\right ), \quad \left ( \left ( \frac{35184372088832}{7028615090593} + \frac{17592186044416 i}{7028615090593}, \quad \frac{70368744177664}{7028615090593} + \frac{35184372088832 i}{7028615090593}\right ), \quad 1\right )\right ]\right )$$

In [255]:
list(map(lambda i: i.evalf(), roots[1][0][0]))


Out[255]:
$$\left [ -10.0117510022486 - 20.0235020044972 i, \quad - 15.0176265033729 i\right ]$$

In [256]:
list(map(lambda i: i.evalf(), roots[1][1][0]))


Out[256]:
$$\left [ -10.0117510022486 + 15.0176265033729 i, \quad 20.0235020044972 i\right ]$$

In [133]:
intervals(x**3 + 3, all=True, eps=1e-100)


Out[133]:
$$\left ( \left [ \left ( \left ( - \frac{315087833657189309495942032839299110639721756254161}{218469701876929588445406517998851632582257515513048}, \quad - \frac{74244338007781133298435885792949430248314884833429}{51478148814394390040615746700439589316357939377513}\right ), \quad 1\right )\right ], \quad \left [ \left ( \left ( \frac{25236491343782931986147923856114138905746868597712233490620148855186563982030339798613077798172905703}{34996011596528190789960035633881941845650710894291398982812329702559247987190014771576210832368861184} - \frac{43710885212204208673213686095962914780401966475680176506958264383653531091231210329053298054088894849 i}{34996011596528190789960035633881941845650710894291398982812329702559247987190014771576210832368861184}, \quad \frac{12618245671891465993073961928057069452873434298856116745310074427593281991015169899306538899086452853}{17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430592} - \frac{21855442606102104336606843047981457390200983237840088253479132191826765545615605164526649027044447423 i}{17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430592}\right ), \quad 1\right ), \quad \left ( \left ( \frac{25236491343782931986147923856114138905746868597712233490620148855186563982030339798613077798172905703}{34996011596528190789960035633881941845650710894291398982812329702559247987190014771576210832368861184} + \frac{21855442606102104336606843047981457390200983237840088253479132191826765545615605164526649027044447423 i}{17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430592}, \quad \frac{12618245671891465993073961928057069452873434298856116745310074427593281991015169899306538899086452853}{17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430592} + \frac{43710885212204208673213686095962914780401966475680176506958264383653531091231210329053298054088894849 i}{34996011596528190789960035633881941845650710894291398982812329702559247987190014771576210832368861184}\right ), \quad 1\right )\right ]\right )$$

In [134]:
solve(x**3 + 3.)


Out[134]:
$$\left [ -1.44224957030741\right ]$$

In [135]:
minpoly(sqrt(2) + sqrt(3))


Out[135]:
$$x^{4} - 10 x^{2} + 1$$

In [136]:
solve(x**4 - 10*x**2 + 1)


Out[136]:
$$\left [ - \sqrt{- 2 \sqrt{6} + 5}, \quad \sqrt{- 2 \sqrt{6} + 5}, \quad - \sqrt{2 \sqrt{6} + 5}, \quad \sqrt{2 \sqrt{6} + 5}\right ]$$

In [137]:
minpoly(sqrt(-2*sqrt(6) + 5))


Out[137]:
$$x^{4} - 10 x^{2} + 1$$

In [138]:
roots10 = intervals(correct_rat_func14_rational.subs(t, -t).as_numer_denom()[1], all=True, eps=1e-14)
roots10


Out[138]:
$$\left ( \left [ \right ], \quad \left [ \left ( \left ( - \frac{125078022371081}{14057230181186} - \frac{1870284593834793 i}{112457841449488}, \quad - \frac{1000624178968647}{112457841449488} - \frac{233785574229349 i}{14057230181186}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{125078022371081}{14057230181186} + \frac{233785574229349 i}{14057230181186}, \quad - \frac{1000624178968647}{112457841449488} + \frac{1870284593834793 i}{112457841449488}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{416462131827785}{112457841449488} - \frac{383941562643445 i}{28114460362372}, \quad - \frac{52057766478473}{14057230181186} - \frac{1535766250573779 i}{112457841449488}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{416462131827785}{112457841449488} + \frac{1535766250573779 i}{112457841449488}, \quad - \frac{52057766478473}{14057230181186} + \frac{383941562643445 i}{28114460362372}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{5869089857063}{28114460362372} - \frac{618026776618467 i}{56228920724744}, \quad - \frac{23476359428251}{112457841449488} - \frac{1236053553236933 i}{112457841449488}\right ), \quad 1\right ), \quad \left ( \left ( - \frac{5869089857063}{28114460362372} + \frac{1236053553236933 i}{112457841449488}, \quad - \frac{23476359428251}{112457841449488} + \frac{618026776618467 i}{56228920724744}\right ), \quad 1\right ), \quad \left ( \left ( \frac{255255176542051}{112457841449488} - \frac{237897218674245 i}{28114460362372}, \quad \frac{63813794135513}{28114460362372} - \frac{951588874696979 i}{112457841449488}\right ), \quad 1\right ), \quad \left ( \left ( \frac{255255176542051}{112457841449488} + \frac{951588874696979 i}{112457841449488}, \quad \frac{63813794135513}{28114460362372} + \frac{237897218674245 i}{28114460362372}\right ), \quad 1\right ), \quad \left ( \left ( \frac{449085924285613}{112457841449488} - \frac{337645233060803 i}{56228920724744}, \quad \frac{224542962142807}{56228920724744} - \frac{675290466121605 i}{112457841449488}\right ), \quad 1\right ), \quad \left ( \left ( \frac{449085924285613}{112457841449488} + \frac{675290466121605 i}{112457841449488}, \quad \frac{224542962142807}{56228920724744} + \frac{337645233060803 i}{56228920724744}\right ), \quad 1\right ), \quad \left ( \left ( \frac{71542118271671}{14057230181186} - \frac{201795720103675 i}{56228920724744}, \quad \frac{572336946173369}{112457841449488} - \frac{403591440207349 i}{112457841449488}\right ), \quad 1\right ), \quad \left ( \left ( \frac{71542118271671}{14057230181186} + \frac{403591440207349 i}{112457841449488}, \quad \frac{572336946173369}{112457841449488} + \frac{201795720103675 i}{56228920724744}\right ), \quad 1\right ), \quad \left ( \left ( \frac{632366661909653}{112457841449488} - \frac{33570609913917 i}{28114460362372}, \quad \frac{316183330954827}{56228920724744} - \frac{134282439655667 i}{112457841449488}\right ), \quad 1\right ), \quad \left ( \left ( \frac{632366661909653}{112457841449488} + \frac{134282439655667 i}{112457841449488}, \quad \frac{316183330954827}{56228920724744} + \frac{33570609913917 i}{28114460362372}\right ), \quad 1\right )\right ]\right )$$

In [258]:
list(map(lambda i: i.evalf(17), roots10[1][0][0]))


Out[258]:
$$\left [ -8.8977715210556681 - 16.63098428467398 i, \quad -8.8977715210556592 - 16.630984284673971 i\right ]$$

In [140]:
plot(re(correct_partial_frac14.subs(t, -t)), (t, 1e-4, 1e-2), xscale='log', adaptive=False, nb_of_points=10000)


Out[140]:
<sympy.plotting.plot.Plot at 0x116b3ff60>

In [141]:
plot(exp(-t), (t, 1e-4, 1e-2), xscale='log', adaptive=False, nb_of_points=10000)


Out[141]:
<sympy.plotting.plot.Plot at 0x116d82d68>

In [142]:
plot(exp(-t) - 2*re(correct_partial_frac14.subs(t, -t)), (t, 1e-4, 1e-2), xscale='log', adaptive=False, nb_of_points=10000)


Out[142]:
<sympy.plotting.plot.Plot at 0x117079a20>

In [143]:
alpha1


Out[143]:
$$-0.000071542880635890672853 + 0.00014361043349541300111 i$$

In [144]:
alpha1*2


Out[144]:
$$-0.00014308576127178134571 + 0.00028722086699082600222 i$$

In [145]:
srepr(correct_rat_func14)


Out[145]:
"Mul(Add(Mul(Float('4.1609826642376610641e-28', prec=17), Pow(Symbol('t', real=True), Integer(14))), Mul(Integer(-1), Float('3.7794523874503297816e-24', prec=17), Pow(Symbol('t', real=True), Integer(13))), Mul(Float('5.6743825539523504126e-21', prec=17), Pow(Symbol('t', real=True), Integer(12))), Mul(Integer(-1), Float('3.3490280333667534845e-18', prec=17), Pow(Symbol('t', real=True), Integer(11))), Mul(Float('1.0310151365350495889e-15', prec=17), Pow(Symbol('t', real=True), Integer(10))), Mul(Integer(-1), Float('1.9038640942835345932e-13', prec=17), Pow(Symbol('t', real=True), Integer(9))), Mul(Float('2.2849515765300153532e-11', prec=17), Pow(Symbol('t', real=True), Integer(8))), Mul(Integer(-1), Float('1.8710255961089454423e-9', prec=17), Pow(Symbol('t', real=True), Integer(7))), Mul(Float('1.0753202054485226852e-7', prec=17), Pow(Symbol('t', real=True), Integer(6))), Mul(Integer(-1), Float('4.393280849251123483e-6', prec=17), Pow(Symbol('t', real=True), Integer(5))), Mul(Float('0.00012734070715233181928', prec=17), Pow(Symbol('t', real=True), Integer(4))), Mul(Integer(-1), Float('0.0025674439819028619519', prec=17), Pow(Symbol('t', real=True), Integer(3))), Mul(Float('0.034346984175671474437', prec=17), Pow(Symbol('t', real=True), Integer(2))), Mul(Integer(-1), Float('0.27495604296300041325', prec=17), Symbol('t', real=True)), Float('0.99999999999998168132', prec=17)), Pow(Add(Mul(Float('2.2710680218891296266e-14', prec=17), Pow(Symbol('t', real=True), Integer(14))), Mul(Float('1.8921838854022448175e-13', prec=17), Pow(Symbol('t', real=True), Integer(13))), Mul(Float('1.2922802705792779525e-11', prec=17), Pow(Symbol('t', real=True), Integer(12))), Mul(Float('2.2472030400428528176e-10', prec=17), Pow(Symbol('t', real=True), Integer(11))), Mul(Float('4.836180087864828391e-9', prec=17), Pow(Symbol('t', real=True), Integer(10))), Mul(Float('8.0163997982357503177e-8', prec=17), Pow(Symbol('t', real=True), Integer(9))), Mul(Float('1.1820291576355771705e-6', prec=17), Pow(Symbol('t', real=True), Integer(8))), Mul(Float('0.000014908234724800242013', prec=17), Pow(Symbol('t', real=True), Integer(7))), Mul(Float('0.00016019211440612189201', prec=17), Pow(Symbol('t', real=True), Integer(6))), Mul(Float('0.0014405527154587316474', prec=17), Pow(Symbol('t', real=True), Integer(5))), Mul(Float('0.010574049161691155552', prec=17), Pow(Symbol('t', real=True), Integer(4))), Mul(Float('0.060968185127283594515', prec=17), Pow(Symbol('t', real=True), Integer(3))), Mul(Float('0.25939094125018014036', prec=17), Pow(Symbol('t', real=True), Integer(2))), Mul(Float('0.7250439570348866658', prec=17), Symbol('t', real=True)), Float('1.0', prec=17)), Integer(-1)))"

In [146]:
incorrect_rat_func14 = Mul(Add(Mul(Float('4.1609826642376610641e-28', prec=17), Pow(Symbol('t', real=True), Integer(14))), Mul(Integer(-1), Float('3.7794523874503297816e-24', prec=17), Pow(Symbol('t', real=True), Integer(13))), Mul(Float('5.6743825539523504126e-21', prec=17), Pow(Symbol('t', real=True), Integer(12))), Mul(Integer(-1), Float('3.3490280333667534845e-18', prec=17), Pow(Symbol('t', real=True), Integer(11))), Mul(Float('1.0310151365350495889e-15', prec=17), Pow(Symbol('t', real=True), Integer(10))), Mul(Integer(-1), Float('1.9038640942835345932e-13', prec=17), Pow(Symbol('t', real=True), Integer(9))), Mul(Float('2.2849515765300153532e-11', prec=17), Pow(Symbol('t', real=True), Integer(8))), Mul(Integer(-1), Float('1.8710255961089454423e-9', prec=17), Pow(Symbol('t', real=True), Integer(7))), Mul(Float('1.0753202054485226852e-7', prec=17), Pow(Symbol('t', real=True), Integer(6))), Mul(Integer(-1), Float('4.393280849251123483e-6', prec=17), Pow(Symbol('t', real=True), Integer(5))), Mul(Float('0.00012734070715233181928', prec=17), Pow(Symbol('t', real=True), Integer(4))), Mul(Integer(-1), Float('0.0025674439819028619519', prec=17), Pow(Symbol('t', real=True), Integer(3))), Mul(Float('0.034346984175671474437', prec=17), Pow(Symbol('t', real=True), Integer(2))), Mul(Integer(-1), Float('0.27495604296300041325', prec=17), Symbol('t', real=True)), Float('0.99999999999998168132', prec=17)), Pow(Add(Mul(Float('2.2710680218891296266e-14', prec=17), Pow(Symbol('t', real=True), Integer(14))), Mul(Float('1.8921838854022448175e-13', prec=17), Pow(Symbol('t', real=True), Integer(13))), Mul(Float('1.2922802705792779525e-11', prec=17), Pow(Symbol('t', real=True), Integer(12))), Mul(Float('2.2472030400428528176e-10', prec=17), Pow(Symbol('t', real=True), Integer(11))), Mul(Float('4.836180087864828391e-9', prec=17), Pow(Symbol('t', real=True), Integer(10))), Mul(Float('8.0163997982357503177e-8', prec=17), Pow(Symbol('t', real=True), Integer(9))), Mul(Float('1.1820291576355771705e-6', prec=17), Pow(Symbol('t', real=True), Integer(8))), Mul(Float('0.000014908234724800242013', prec=17), Pow(Symbol('t', real=True), Integer(7))), Mul(Float('0.00016019211440612189201', prec=17), Pow(Symbol('t', real=True), Integer(6))), Mul(Float('0.0014405527154587316474', prec=17), Pow(Symbol('t', real=True), Integer(5))), Mul(Float('0.010574049161691155552', prec=17), Pow(Symbol('t', real=True), Integer(4))), Mul(Float('0.060968185127283594515', prec=17), Pow(Symbol('t', real=True), Integer(3))), Mul(Float('0.25939094125018014036', prec=17), Pow(Symbol('t', real=True), Integer(2))), Mul(Float('0.725043', prec=17), Symbol('t', real=True)), Float('1.0', prec=17)), Integer(-1)))

In [147]:
plot(exp(-t) - correct_rat_func14, (t, 1e-4, 1e2), xscale='log', adaptive=False, nb_of_points=10000)


Out[147]:
<sympy.plotting.plot.Plot at 0x1170ad240>

From "Efficient Solution of Parabolic Equations by Krylov Approximation Methods" by E. Gallopoulos and Y. Saad Appendix B Table 5


In [148]:
real_part_alternate14 = """
-0.562314417475317895E+01 
-0.508934679728216110E+01 
-0.399337136365302569E+01 
-0.226978543095856366E+01 
0.208756929753827868E+00 
0.370327340957595652E+01 
0.889777151877331107E+01

0.557503973136501826E+02 
-0.938666838877006739E+02 
0.469965415550370835E+02 
-0.961424200626061065E+01 
0.752722063978321642E+00 
-0.188781253158648576E-01 
0.143086431411801849E-03 
0.183216998528140087E-11 

"""

In [149]:
theta1ra, theta2ra, theta3ra, theta4ra, theta5ra, theta6ra, theta7ra, alpha1ra, alpha2ra, alpha3ra, alpha4ra, alpha5ra, alpha6ra, alpha7ra, alpha0ra = map(Float, real_part_alternate14.strip().split())
theta1ra, theta2ra, theta3ra, theta4ra, theta5ra, theta6ra, theta7ra, alpha1ra, alpha2ra, alpha3ra, alpha4ra, alpha5ra, alpha6ra, alpha7ra, alpha0ra


Out[149]:
$$\left ( -5.62314417475317895, \quad -5.0893467972821611, \quad -3.99337136365302569, \quad -2.26978543095856366, \quad 0.208756929753827868, \quad 3.70327340957595652, \quad 8.89777151877331107, \quad 55.7503973136501826, \quad -93.8666838877006739, \quad 46.9965415550370835, \quad -9.61424200626061065, \quad 0.752722063978321642, \quad -0.0188781253158648576, \quad 0.000143086431411801849, \quad 1.83216998528140087 \cdot 10^{-12}\right )$$

In [150]:
imaginary_part_alternate14 = """
0.119406921611247440E+01 
0.358882439228376881E+01 
0.600483209099604664E+01 
0.846173881758693369E+01 
0.109912615662209418E+02 
0.136563731924991884E+02 
0.166309842834712071E+02
-0.204295038779771857E+03 
0.912874896775456363E+02 
-0.116167609985818103E+02 
-0.264195613880262669E+01 
0.670367365566377770E+00 
-0.343696176445802414E-01 
0.287221133228814096E-03 
0
"""

In [151]:
theta1ja, theta2ja, theta3ja, theta4ja, theta5ja, theta6ja, theta7ja, alpha1ja, alpha2ja, alpha3ja, alpha4ja, alpha5ja, alpha6ja, alpha7ja, alpha0ja = [Float(i)*I for i in imaginary_part_alternate14.strip().split()]
theta1ja, theta2ja, theta3ja, theta4ja, theta5ja, theta6ja, theta7ja, alpha1ja, alpha2ja, alpha3ja, alpha4ja, alpha5ja, alpha6ja, alpha7ja, alpha0ja


Out[151]:
$$\left ( 1.1940692161124744 i, \quad 3.58882439228376881 i, \quad 6.00483209099604664 i, \quad 8.46173881758693369 i, \quad 10.9912615662209418 i, \quad 13.6563731924991884 i, \quad 16.6309842834712071 i, \quad - 204.295038779771857 i, \quad 91.2874896775456363 i, \quad - 11.6167609985818103 i, \quad - 2.64195613880262669 i, \quad 0.67036736556637777 i, \quad - 0.0343696176445802414 i, \quad 0.000287221133228814096 i, \quad 0\right )$$

In [152]:
alpha1ja


Out[152]:
$$- 204.295038779771857 i$$

In [153]:
theta1a, theta2a, theta3a, theta4a, theta5a, theta6a, theta7a, alpha1a, alpha2a, alpha3a, alpha4a, alpha5a, alpha6a, alpha7a, alpha0a =\
(r + j for r, j in zip(
        (theta1ra, theta2ra, theta3ra, theta4ra, theta5ra, theta6ra, theta7ra, alpha1ra, alpha2ra, alpha3ra, alpha4ra, alpha5ra, alpha6ra, alpha7ra, alpha0ra),
        (theta1ja, theta2ja, theta3ja, theta4ja, theta5ja, theta6ja, theta7ja, alpha1ja, alpha2ja, alpha3ja, alpha4ja, alpha5ja, alpha6ja, alpha7ja, alpha0ja)))

In [154]:
thetasa = theta1a, theta2a, theta3a, theta4a, theta5a, theta6a, theta7a
alphasa = alpha1a, alpha2a, alpha3a, alpha4a, alpha5a, alpha6a, alpha7a

In [155]:
correct_partial_frac_alternate14 = alpha0a + Add(*(alpha/(t - theta) + alpha/(t - conjugate(theta)) for alpha, theta in zip(alphasa, thetasa)))
correct_partial_frac_alternate14


Out[155]:
$$1.83216998528140087 \cdot 10^{-12} + \frac{55.7503973136501826 - 204.295038779771857 i}{t + 5.62314417475317895 + 1.1940692161124744 i} + \frac{55.7503973136501826 - 204.295038779771857 i}{t + 5.62314417475317895 - 1.1940692161124744 i} + \frac{-93.8666838877006739 + 91.2874896775456363 i}{t + 5.0893467972821611 + 3.58882439228376881 i} + \frac{-93.8666838877006739 + 91.2874896775456363 i}{t + 5.0893467972821611 - 3.58882439228376881 i} + \frac{46.9965415550370835 - 11.6167609985818103 i}{t + 3.99337136365302569 + 6.00483209099604664 i} + \frac{46.9965415550370835 - 11.6167609985818103 i}{t + 3.99337136365302569 - 6.00483209099604664 i} + \frac{-9.61424200626061065 - 2.64195613880262669 i}{t + 2.26978543095856366 + 8.46173881758693369 i} + \frac{-9.61424200626061065 - 2.64195613880262669 i}{t + 2.26978543095856366 - 8.46173881758693369 i} + \frac{0.752722063978321642 + 0.67036736556637777 i}{t - 0.208756929753827868 + 10.9912615662209418 i} + \frac{0.752722063978321642 + 0.67036736556637777 i}{t - 0.208756929753827868 - 10.9912615662209418 i} + \frac{-0.0188781253158648576 - 0.0343696176445802414 i}{t - 3.70327340957595652 + 13.6563731924991884 i} + \frac{-0.0188781253158648576 - 0.0343696176445802414 i}{t - 3.70327340957595652 - 13.6563731924991884 i} + \frac{0.000143086431411801849 + 0.000287221133228814096 i}{t - 8.89777151877331107 + 16.6309842834712071 i} + \frac{0.000143086431411801849 + 0.000287221133228814096 i}{t - 8.89777151877331107 - 16.6309842834712071 i}$$

In [156]:
plot((2*re(correct_partial_frac_alternate14) - alpha0a, (t, 1e2, 1e4)), (exp(-t), (t, 1e-2, 1e4)), xscale='log', adaptive=False, nb_of_points=10000)


Out[156]:
<sympy.plotting.plot.Plot at 0x11795ec88>

In [157]:
plot((exp(-t) - re(correct_partial_frac_alternate14) + 0*alpha0a, (t, 1e-2, 1e4)), xscale='log', adaptive=False, nb_of_points=10000)


Out[157]:
<sympy.plotting.plot.Plot at 0x117067710>

In [158]:
N = symbols('N')
plot_parametric((*phi.subs(N, 4).as_real_imag(), (x, pi/14, pi*13/14)))


Out[158]:
<sympy.plotting.plot.Plot at 0x118f2c6d8>

In [159]:
phi


Out[159]:
$$N \left(- 0.1149 x^{2} + 0.25 i x + 0.1309\right)$$

In [160]:
!say done

In [161]:
correct_rat_func


Out[161]:
$$\frac{- 0.11535 t + 1.0669}{1.7275 t + 1}$$

In [162]:
apart(correct_rat_func)


Out[162]:
$$-0.0667727930535456 + \frac{1.13367279305355}{1.7275 t + 1.0}$$

In [163]:
together(apart(correct_rat_func))


Out[163]:
$$\frac{- 0.11535 t + 1.0669}{1.7275 t + 1.0}$$

In [164]:
correct_rat_func2


Out[164]:
$$\frac{0.00421096 t^{2} - 0.188332 t + 0.992641}{0.572258 t^{2} + 0.669295 t + 1}$$

In [165]:
apart(correct_rat_func2, full=True).doit()


Out[165]:
$$0.00735849913850047 - \frac{0.168854788120832 - 0.809437993293635 i}{t + 0.584784310573203 + 1.18553400067436 i} - \frac{0.168854788120832 + 0.809437993293635 i}{t + 0.584784310573203 - 1.18553400067436 i}$$

In [166]:
canonicalize(cancel(apart(correct_rat_func2, full=True).doit()))


Out[166]:
$$\frac{0.00421096 t^{2} - 0.188332 t + 0.992641}{0.572258 t^{2} + 0.669295 t + 1.0}$$

In [167]:
def quad_coeffs(k):
    import numpy
    xvals = numpy.linspace(1, 2, k - 1, dtype=complex)
    xquad = pi*x/k
    lxquad = lambdify(x, xquad, 'numpy')
    theta = phi.subs(N, k)
    ltheta = lambdify(x, theta, 'numpy')
    w_j = phi.subs(N, k).diff(x)
    alpha = I/k*exp(theta)*w_j
    lalpha = lambdify(x, alpha, 'numpy')
    return (ltheta(lxquad(xvals)), lalpha(lxquad(xvals)))

In [168]:
quad_coeffs(2)


Out[168]:
(array([-0.30520877+0.78539816j]), array([ 0.05782773-0.3183858j]))

In [169]:
quad_coeffs(14)


Out[169]:
(array([ 1.75159875+0.78539816j,  1.73753603+0.85084801j,
         1.72234829+0.91629786j,  1.70603554+0.9817477j ,
         1.68859777+1.04719755j,  1.67003498+1.1126474j ,
         1.65034718+1.17809725j,  1.62953436+1.24354709j,
         1.60759652+1.30899694j,  1.58453366+1.37444679j,
         1.56034579+1.43989663j,  1.53503290+1.50534648j,
         1.50859499+1.57079633j]),
 array([-0.80873934-1.22907529j, -0.69811370-1.27757575j,
        -0.58473712-1.31523879j, -0.46973824-1.3419598j ,
        -0.35423806-1.35775768j, -0.23933590-1.36277177j,
        -0.12609598-1.35725718j, -0.01553484-1.34157856j,
         0.09139022-1.31620242j,  0.19379161-1.28168828j,
         0.29086050-1.23867875j,  0.38187460-1.18788871j,
         0.46620436-1.13009379j]))

In [170]:
thetas


Out[170]:
$$\left ( -8.8977731864688888199 + 16.630982619902085304 i, \quad -3.7032750494234480603 + 13.656371871483268171 i, \quad -0.2087586382501301251 + 10.991260561901260913 i, \quad 3.9933697105785685194 + 6.0048316422350373178 i, \quad 5.0893450605806245066 + 3.5888240290270065102 i, \quad 5.6231425727459771248 + 1.1940690463439669766 i, \quad 2.2697838292311127097 + 8.4617379730402214019 i\right )$$

In [171]:
import numpy as np
import matplotlib.pyplot as plt

In [175]:
plt.plot(*zip(*[i.as_real_imag() for i in thetas]))


Out[175]:
[<matplotlib.lines.Line2D at 0x11889e4a8>]

In [180]:
plt.plot(*zip(*[i.as_real_imag() for i in thetasa]))


Out[180]:
[<matplotlib.lines.Line2D at 0x11a781f98>]

In [179]:
plot_parametric((*phi.subs(N, 14).as_real_imag(), (x, -pi, pi)))


Out[179]:
<sympy.plotting.plot.Plot at 0x11a59f588>

In [181]:
thetas


Out[181]:
$$\left ( -8.8977731864688888199 + 16.630982619902085304 i, \quad -3.7032750494234480603 + 13.656371871483268171 i, \quad -0.2087586382501301251 + 10.991260561901260913 i, \quad 3.9933697105785685194 + 6.0048316422350373178 i, \quad 5.0893450605806245066 + 3.5888240290270065102 i, \quad 5.6231425727459771248 + 1.1940690463439669766 i, \quad 2.2697838292311127097 + 8.4617379730402214019 i\right )$$

In [182]:
thetasa


Out[182]:
$$\left ( -5.62314417475317895 + 1.1940692161124744 i, \quad -5.0893467972821611 + 3.58882439228376881 i, \quad -3.99337136365302569 + 6.00483209099604664 i, \quad -2.26978543095856366 + 8.46173881758693369 i, \quad 0.208756929753827868 + 10.9912615662209418 i, \quad 3.70327340957595652 + 13.6563731924991884 i, \quad 8.89777151877331107 + 16.6309842834712071 i\right )$$

In [184]:
quad_thetas, quad_alphas = quad_coeffs(14)
quad_thetas, quad_alphas


Out[184]:
(array([ 1.75159875+0.78539816j,  1.73753603+0.85084801j,
         1.72234829+0.91629786j,  1.70603554+0.9817477j ,
         1.68859777+1.04719755j,  1.67003498+1.1126474j ,
         1.65034718+1.17809725j,  1.62953436+1.24354709j,
         1.60759652+1.30899694j,  1.58453366+1.37444679j,
         1.56034579+1.43989663j,  1.53503290+1.50534648j,
         1.50859499+1.57079633j]),
 array([-0.80873934-1.22907529j, -0.69811370-1.27757575j,
        -0.58473712-1.31523879j, -0.46973824-1.3419598j ,
        -0.35423806-1.35775768j, -0.23933590-1.36277177j,
        -0.12609598-1.35725718j, -0.01553484-1.34157856j,
         0.09139022-1.31620242j,  0.19379161-1.28168828j,
         0.29086050-1.23867875j,  0.38187460-1.18788871j,
         0.46620436-1.13009379j]))

In [192]:
quad_rational_func14 = 2*re(Add(*(alpha/(t - theta) for alpha, theta in zip(quad_alphas, quad_thetas))))
quad_rational_func14


Out[192]:
$$- \frac{1.617478689998 t - 2.83317364627394}{\left(t - 1.75159874673677\right)^{2} + 0.616850275068085} - \frac{1.3962274056788 t - 2.42599542226241}{\left(t - 1.73753602915635\right)^{2} + 0.723942336711849} - \frac{1.16947424751737 t - 2.0142419752867}{\left(t - 1.7223482941695\right)^{2} + 0.839601763287115} - \frac{0.93947648721202 t - 1.60278027784677}{\left(t - 1.70603554177621\right)^{2} + 0.963828554793883} - \frac{0.708476125481374 t - 1.19633120698638}{\left(t - 1.68859777197649\right)^{2} + 1.09662271123215} - \frac{0.478671800033118 t - 0.799398652278295}{\left(t - 1.67003498477033\right)^{2} + 1.23798423260192} - \frac{0.252191957847485 t - 0.416204286492056}{\left(t - 1.65034718015774\right)^{2} + 1.38791311890319} - \frac{0.031069685289444 t - 0.0506291196757061}{\left(t - 1.62953435813872\right)^{2} + 1.54640937013596} + \frac{0.182780448372868 t - 0.293837212493071}{\left(t - 1.60759651871326\right)^{2} + 1.71347298630024} + \frac{0.387583222147281 t - 0.614138662272811}{\left(t - 1.58453366188137\right)^{2} + 1.88910396739601} + \frac{0.581721005702549 t - 0.907685920831449}{\left(t - 1.56034578764305\right)^{2} + 2.07330231342329} + \frac{0.763749201496068 t - 1.17238014858889}{\left(t - 1.53503289599829\right)^{2} + 2.26606802438206} + \frac{0.932408729686383 t - 1.40662713539059}{\left(t - 1.5085949869471\right)^{2} + 2.46740110027234} + \frac{3.55029433627322}{\left(t - 1.5085949869471\right)^{2} + 2.46740110027234} + \frac{3.57636817051086}{\left(t - 1.53503289599829\right)^{2} + 2.26606802438206} + \frac{3.56713872312914}{\left(t - 1.56034578764305\right)^{2} + 2.07330231342329} + \frac{3.5232246630576}{\left(t - 1.58453366188137\right)^{2} + 1.88910396739601} + \frac{3.44580986748273}{\left(t - 1.60759651871326\right)^{2} + 1.71347298630024} + \frac{3.33663224051094}{\left(t - 1.62953435813872\right)^{2} + 1.54640937013596} + \frac{3.19796190025085}{\left(t - 1.65034718015774\right)^{2} + 1.38791311890319} + \frac{3.03256891880447}{\left(t - 1.67003498477033\right)^{2} + 1.23798423260192} + \frac{2.84368102627958}{\left(t - 1.68859777197649\right)^{2} + 1.09662271123215} + \frac{2.63493191291616}{\left(t - 1.70603554177621\right)^{2} + 0.963828554793883} + \frac{2.41030097735102}{\left(t - 1.7223482941695\right)^{2} + 0.839601763287115} + \frac{2.17404556861633}{\left(t - 1.73753602915635\right)^{2} + 0.723942336711849} + \frac{1.93062694960738}{\left(t - 1.75159874673677\right)^{2} + 0.616850275068085}$$

In [198]:
plot(quad_rational_func14)


Out[198]:
<sympy.plotting.plot.Plot at 0x11bb87a90>

In [199]:
plot(exp(t) - quad_rational_func14, (t, -100, 0))


Out[199]:
<sympy.plotting.plot.Plot at 0x11bb9b160>

In [200]:
plot((exp(t) - quad_rational_func14), (t, -1000, 0))


Out[200]:
<sympy.plotting.plot.Plot at 0x11bda84e0>

In [241]:
re_correct_partial_frac14 = alpha0 + 2*re(Add(*(alpha/(t - theta) for alpha, theta in zip(alphas, thetas))))
plot(re_correct_partial_frac14)


Out[241]:
<sympy.plotting.plot.Plot at 0x11e99a0f0>

In [242]:
plot(exp(t) - re_correct_partial_frac14, (t, -100, 0))


Out[242]:
<sympy.plotting.plot.Plot at 0x11e99a9e8>

In [243]:
plot(exp(t) - re_correct_partial_frac14, (t, -1000, 0))


Out[243]:
<sympy.plotting.plot.Plot at 0x11ef94ac8>

In [244]:
print(np.pi*np.linspace(1, 2, 14 - 1, dtype=complex)/14)
plot_parametric((*phi.subs(N, 4).as_real_imag(), (x, pi/14, pi*13/14)))


[ 0.22439948+0.j  0.24309943+0.j  0.26179939+0.j  0.28049934+0.j
  0.29919930+0.j  0.31789926+0.j  0.33659921+0.j  0.35529917+0.j
  0.37399913+0.j  0.39269908+0.j  0.41139904+0.j  0.43009899+0.j
  0.44879895+0.j]
Out[244]:
<sympy.plotting.plot.Plot at 0x11ef94d68>

In [323]:
def quad_coeffs2(k):
    import numpy
    xvals = numpy.linspace(1, k - 1, k//2, dtype=complex)
    xquad = pi*x/k
    lxquad = lambdify(x, xquad, 'numpy')
    theta = phi.subs(N, k)
    ltheta = lambdify(x, theta, 'numpy')
    w_j = phi.subs(N, k).diff(x)
    alpha = I/k*exp(theta)*w_j
    lalpha = lambdify(x, alpha, 'numpy')
    return (ltheta(lxquad(xvals)), lalpha(lxquad(xvals)))

quad2_thetas, quad2_alphas = quad_coeffs2(32)
print(quad2_thetas)
print(quad2_alphas)
quad2_rational_func14 = 2*re(Add(*(alpha/(t - theta) for alpha, theta in zip(quad2_alphas, quad2_thetas))))
plot(quad2_rational_func14)
plot(exp(t) - quad2_rational_func14, (t, -100, -10))


[  4.15336195 +0.78539816j   3.86985757 +2.35619449j
   3.30284879 +3.92699082j   2.45233563 +5.49778714j
   1.31831809 +7.06858347j  -0.09920384 +8.6393798j
  -1.80023016+10.21017612j  -3.78476087+11.78097245j
  -6.05279596+13.35176878j  -8.60433544+14.9225651j
 -11.43937930+16.49336143j -14.55792755+18.06415776j
 -17.95998019+19.63495408j -21.64553721+21.20575041j
 -25.61459862+22.77654674j -29.86716442+24.34734307j]
[ -1.02360630e+01 -1.22667692e+01j   1.07679981e+01 -6.17978097e+00j
   2.63778394e+00 +6.97532827e+00j  -3.35042596e+00 +7.56253823e-01j
  -1.24080793e-01 -1.19719439e+00j   3.18988895e-01 -1.17424012e-03j
  -5.05842792e-03 +6.34869607e-02j  -9.45068158e-03 -1.41996597e-03j
   2.22006929e-04 -1.05330950e-03j   8.79662122e-05 +2.31565727e-05j
  -1.70306437e-06 +5.50842394e-06j  -2.58775566e-07 -9.04975422e-08j
   3.51976606e-09 -9.12423821e-09j   2.41551165e-10 +1.00973075e-10j
  -2.14715287e-12 +4.80283548e-12j  -7.17429462e-14 -3.39587394e-14j]
Out[323]:
<sympy.plotting.plot.Plot at 0x121ed62b0>

In [216]:
plot((re(exp(pi/14*phi.subs(N, 14))), (x, -5, 5)), (im(exp(pi/14*phi.subs(N, 14))), (x, -5, 5)))


Out[216]:
<sympy.plotting.plot.Plot at 0x11dd63400>

In [226]:
plot(exp(t) - re_correct_partial_frac14, (t, -100, 0))


Out[226]:
<sympy.plotting.plot.Plot at 0x11dd86588>

In [228]:
plot(exp(t) - correct_rat_func14.subs(t, -t), (t, -100, 0))


Out[228]:
<sympy.plotting.plot.Plot at 0x11f144a58>

In [245]:
re_correct_partial_frac_alternate14 = alpha0a + 2*re(Add(*(alpha/(t - theta) for alpha, theta in zip(alphasa, thetasa))))
re_correct_partial_frac_alternate14 = re_correct_partial_frac_alternate14.subs(t, -t)
plot(re_correct_partial_frac_alternate14)


Out[245]:
<sympy.plotting.plot.Plot at 0x120466ef0>

In [246]:
plot(re_correct_partial_frac_alternate14, re_correct_partial_frac14)


Out[246]:
<sympy.plotting.plot.Plot at 0x11fefce48>

In [247]:
plot((exp(t) - re_correct_partial_frac14, (t, -100, 0)), (exp(t) - re_correct_partial_frac_alternate14, (t, -100, 0)))


Out[247]:
<sympy.plotting.plot.Plot at 0x12074f4a8>

In [248]:
alpha0a


Out[248]:
$$1.83216998528140087 \cdot 10^{-12}$$

In [249]:
alphasa


Out[249]:
$$\left ( 55.7503973136501826 - 204.295038779771857 i, \quad -93.8666838877006739 + 91.2874896775456363 i, \quad 46.9965415550370835 - 11.6167609985818103 i, \quad -9.61424200626061065 - 2.64195613880262669 i, \quad 0.752722063978321642 + 0.67036736556637777 i, \quad -0.0188781253158648576 - 0.0343696176445802414 i, \quad 0.000143086431411801849 + 0.000287221133228814096 i\right )$$

In [250]:
thetasa


Out[250]:
$$\left ( -5.62314417475317895 + 1.1940692161124744 i, \quad -5.0893467972821611 + 3.58882439228376881 i, \quad -3.99337136365302569 + 6.00483209099604664 i, \quad -2.26978543095856366 + 8.46173881758693369 i, \quad 0.208756929753827868 + 10.9912615662209418 i, \quad 3.70327340957595652 + 13.6563731924991884 i, \quad 8.89777151877331107 + 16.6309842834712071 i\right )$$

In [251]:
real_part_alternate14.strip().split()


Out[251]:
['-0.562314417475317895E+01',
 '-0.508934679728216110E+01',
 '-0.399337136365302569E+01',
 '-0.226978543095856366E+01',
 '0.208756929753827868E+00',
 '0.370327340957595652E+01',
 '0.889777151877331107E+01',
 '0.557503973136501826E+02',
 '-0.938666838877006739E+02',
 '0.469965415550370835E+02',
 '-0.961424200626061065E+01',
 '0.752722063978321642E+00',
 '-0.188781253158648576E-01',
 '0.143086431411801849E-03',
 '0.183216998528140087E-11']

In [253]:
print(real_part_alternate14)


-0.562314417475317895E+01 
-0.508934679728216110E+01 
-0.399337136365302569E+01 
-0.226978543095856366E+01 
0.208756929753827868E+00 
0.370327340957595652E+01 
0.889777151877331107E+01

0.557503973136501826E+02 
-0.938666838877006739E+02 
0.469965415550370835E+02 
-0.961424200626061065E+01 
0.752722063978321642E+00 
-0.188781253158648576E-01 
0.143086431411801849E-03 
0.183216998528140087E-11 



In [296]:
def my_theta_alphas14():
    num, den = correct_rat_func14_rational.subs(t, -t).as_numer_denom()
    # Note, eps is NOT the precision. It's the length of the interval. 
    # If a root is small (say, on the order of 10**-N), then eps will need to be 10**(-N - d)
    # to get d digits of precision. For the order 14 approximation, the roots (thetas) are all
    # within order 10**-1...10**1, so eps is *roughly* the precision.
    roots = intervals(den, all=True, eps=1e-14)[1]
    # eps ought to be small enough that either side of the interval is the precision we want,
    # but for the sake of with smaller eps, take the average (center of the rectangle)
    # XXX: Make sure to change the evalf precision if eps is lowered.
    thetas = [((i + j)/2).evalf(17) for ((i, j), _) in roots]
    error = [(j - i).evalf(17) for ((i, j), _) in roots]
    alphas = []
    for theta in thetas:
        q, r = div(den, t - theta)
        alpha = (num/q).evalf(17, subs={t: theta})
        alphas.append(alpha)
    alpha0 = LC(num)/LC(den)
    return thetas, alphas, alpha0

In [ ]:
my_thetas, my_alphas, my_alpha0 = my_theta_alphas14()
my_thetas, my_alphas, my_alpha0

In [269]:
my_thetas[0]


Out[269]:
$$-8.8977715210556636 - 16.630984284673975 i$$

In [272]:
num, den = correct_rat_func14.subs(t, -t).as_numer_denom()
(num.subs(t, my_thetas[0])/cancel(den/(t - my_thetas[0])).subs(t, my_thetas[0])).evalf(17)


Out[272]:
$$-1.8286618155645881 \cdot 10^{-5} - 1.3229140057839119 \cdot 10^{-5} i$$

In [278]:
(den/(t - my_thetas[0])).evalf(17, subs={t: my_thetas[0]})


Out[278]:
$$1.0726501805847709 \cdot 10^{129} - 3.4503343122918592 \cdot 10^{128} i$$

In [279]:
num.subs(t, my_thetas[0]).evalf(17)


Out[279]:
$$0.17264903070813255 + 0.18545508541786367 i$$

In [280]:
(num/(den/(t - my_thetas[0]))).evalf(17, subs={t: my_thetas[0]})


Out[280]:
$$2.0 \cdot 10^{-123} + 3.0 \cdot 10^{-123} i$$

In [284]:
q, r = div(den, t - my_thetas[0])
q.evalf(subs={t: my_thetas[0]}), r.evalf(subs={t: my_thetas[0]})


Out[284]:
$$\left ( -1514.43289213788 + 447.749835562374 i, \quad -8.18545231595635 \cdot 10^{-12} - 6.00266503170133 \cdot 10^{-11} i\right )$$

In [285]:
(num/q).evalf(17, subs={t: my_thetas[0]})


Out[285]:
$$-7.1543233405734158 \cdot 10^{-5} - 0.00014361056045465258 i$$

In [291]:
[2*i for i in my_alphas]


Out[291]:
$$\left [ -0.00014308646681146832 - 0.00028722112090930516 i, \quad -0.00014308646681146832 + 0.00028722112090930516 i, \quad 0.018878125973460966 + 0.034369618248951164 i, \quad 0.018878125973460966 - 0.034369618248951164 i, \quad -0.75272201454699444 - 0.67036734660381327 i, \quad -0.75272201454699444 + 0.67036734660381327 i, \quad 9.6142426210965836 + 2.6419562869558405 i, \quad 9.6142426210965836 - 2.6419562869558405 i, \quad -46.996539508673395 + 11.616762085324089 i, \quad -46.996539508673395 - 11.616762085324089 i, \quad 93.866684989098188 - 91.287486001166921 i, \quad 93.866684989098188 + 91.287486001166921 i, \quad -55.750401126313793 + 204.29504161432777 i, \quad -55.750401126313793 - 204.29504161432777 i\right ]$$

In [293]:
n14pi[-1]/n14qi[-1]


Out[293]:
$$1.8321699852813985 \cdot 10^{-14}$$

In [295]:
cancel(correct_rat_func14.subs(t, 1/t))


Out[295]:
$$\frac{0.99999999999998168 t^{14} - 0.27495604296300041 t^{13} + 0.034346984175671474 t^{12} - 0.002567443981902862 t^{11} + 0.00012734070715233182 t^{10} - 4.3932808492511235 \cdot 10^{-6} t^{9} + 1.0753202054485227 \cdot 10^{-7} t^{8} - 1.8710255961089454 \cdot 10^{-9} t^{7} + 2.2849515765300154 \cdot 10^{-11} t^{6} - 1.9038640942835346 \cdot 10^{-13} t^{5} + 1.0310151365350496 \cdot 10^{-15} t^{4} - 3.3490280333667535 \cdot 10^{-18} t^{3} + 5.6743825539523504 \cdot 10^{-21} t^{2} - 3.7794523874503298 \cdot 10^{-24} t + 4.1609826642376611 \cdot 10^{-28}}{1.0 t^{14} + 0.72504395703488667 t^{13} + 0.25939094125018014 t^{12} + 0.060968185127283595 t^{11} + 0.010574049161691156 t^{10} + 0.0014405527154587316 t^{9} + 0.00016019211440612189 t^{8} + 1.4908234724800242 \cdot 10^{-5} t^{7} + 1.1820291576355772 \cdot 10^{-6} t^{6} + 8.0163997982357503 \cdot 10^{-8} t^{5} + 4.8361800878648284 \cdot 10^{-9} t^{4} + 2.2472030400428528 \cdot 10^{-10} t^{3} + 1.292280270579278 \cdot 10^{-11} t^{2} + 1.8921838854022448 \cdot 10^{-13} t + 2.2710680218891296 \cdot 10^{-14}}$$

In [303]:
canonicalize(cancel(correct_partial_frac14))


Out[303]:
$$\frac{4.1610013267680030137 \cdot 10^{-28} t^{14} + 3.7794531748656004981 \cdot 10^{-24} t^{13} - 2.8758542814990479738 \cdot 10^{-12} i t^{13} - 3.4890692284773452892 \cdot 10^{-14} t^{12} + 7.2322314480985546285 \cdot 10^{-12} i t^{12} - 1.2321643128679550143 \cdot 10^{-12} t^{11} - 1.6025439961748732301 \cdot 10^{-9} i t^{11} - 5.1286267280928762584 \cdot 10^{-11} t^{10} + 1.9094141389392997611 \cdot 10^{-8} i t^{10} - 1.1380644939022783375 \cdot 10^{-9} t^{9} - 5.0617281066960617975 \cdot 10^{-7} i t^{9} - 2.6527904706759977231 \cdot 10^{-8} t^{8} + 7.227944311822142068 \cdot 10^{-6} i t^{8} - 4.1082433888869135376 \cdot 10^{-7} t^{7} - 0.00010885611539993568667 i t^{7} - 6.0633575239283196196 \cdot 10^{-6} t^{6} + 0.0012678056252250066455 i t^{6} - 0.000059585676942834929352 t^{5} - 0.013108081429793572477 i t^{5} - 0.00046952254224930496943 t^{4} + 0.10853264065332626425 i t^{4} - 0.0014671342809875658002 t^{3} - 0.72788923849380658926 i t^{3} + 0.0073290229829175712577 t^{2} + 3.658133105536471967 i t^{2} + 0.12502022376449821748 t - 12.475356708358263291 i t + 0.49181395414703011995 + 23.754303565936798084 i}{2.2710727625899901428 \cdot 10^{-14} t^{14} - 1.8921825619816040226 \cdot 10^{-13} t^{13} - 1.1542040733153391661 \cdot 10^{-34} i t^{13} + 1.2922822504467752306 \cdot 10^{-11} t^{12} - 1.2311510115363617772 \cdot 10^{-33} i t^{12} - 2.2472046467801856917 \cdot 10^{-10} t^{11} - 9.8492080922908942177 \cdot 10^{-32} i t^{11} + 4.8361843519832767585 \cdot 10^{-9} t^{10} + 2.5213972716264689197 \cdot 10^{-30} i t^{10} - 8.0164052804759261947 \cdot 10^{-8} t^{9} - 5.0427945432529378395 \cdot 10^{-29} i t^{9} + 1.1820298688854367758 \cdot 10^{-6} t^{8} + 8.2701830509348180567 \cdot 10^{-28} i t^{8} - 0.000014908242237501135348 t^{7} - 9.6821655230456406518 \cdot 10^{-27} i t^{7} + 0.00016019218139205361499 t^{6} + 8.2621145796656133562 \cdot 10^{-26} i t^{6} - 0.0014405532019175131523 t^{5} - 4.9572687477993680137 \cdot 10^{-25} i t^{5} + 0.01057405193647140299 t^{4} + 1.9829074991197472055 \cdot 10^{-24} i t^{4} - 0.060968196803506757263 t^{3} - 1.0575506661971985096 \cdot 10^{-23} i t^{3} + 0.25939097352682523935 t^{2} - 1.0575506661971985096 \cdot 10^{-23} i t^{2} - 0.72504400105794982771 t - 1.0575506661971985096 \cdot 10^{-22} i t + 1.0 + 3.3841621318310352307 \cdot 10^{-22} i}$$

In [307]:
canonicalize(cancel(correct_re_partial_frac14))


Out[307]:
$$\frac{4.1610013267680030137 \cdot 10^{-28} t^{14} + 3.7794531721339841913 \cdot 10^{-24} t^{13} + 5.6743670694445729709 \cdot 10^{-21} t^{12} + 3.3490171641883519156 \cdot 10^{-18} t^{11} + 1.0310120249641655541 \cdot 10^{-15} t^{10} + 1.9038591551024417178 \cdot 10^{-13} t^{9} + 2.284946663562568713 \cdot 10^{-11} t^{8} + 1.8710223403465298688 \cdot 10^{-9} t^{7} + 1.0753187241762206547 \cdot 10^{-7} t^{6} + 4.3932761847806352722 \cdot 10^{-6} t^{5} + 0.00012734060684477834232 t^{4} + 0.0025674425707902795073 t^{3} + 0.034346972429252959932 t^{2} + 0.27495599893993723184 t + 0.99999999999998172496}{2.2710727625899901428 \cdot 10^{-14} t^{14} - 1.8921825619816040226 \cdot 10^{-13} t^{13} + 1.2922822504467752306 \cdot 10^{-11} t^{12} - 2.2472046467801856917 \cdot 10^{-10} t^{11} + 4.8361843519832767585 \cdot 10^{-9} t^{10} - 8.0164052804759261947 \cdot 10^{-8} t^{9} + 1.1820298688854367758 \cdot 10^{-6} t^{8} - 0.000014908242237501135348 t^{7} + 0.00016019218139205361499 t^{6} - 0.0014405532019175131523 t^{5} + 0.01057405193647140299 t^{4} - 0.060968196803506757263 t^{3} + 0.25939097352682523935 t^{2} - 0.72504400105794982771 t + 1.0}$$

In [ ]: