UPDATE
Seems the problem is associated with the division. I've tried taking the Normal[Series[]]
of each numerator and denominator separately, and then again taking the Normal[Series[]]
of that, and it is fairly fast for order 5 and 5, but still a long time (I didn't wait) for orders 10. Also a lot of extra overhead I would think...
Is there some alternative division algorithm I can implement?
UPDATE 2
By looking here, Multivariate series expansions to different powers, I used a dummy variable and now it all seems to work adequately, though still not as fast.
For just the i=1
and j=1
case, I get,
a1 =
Assuming[Im[z1] >= 0 && Im[z2] >= 0 && Re[z1] > 0 && Re[z2] > 0,
Refine[
((D[tmpTofZ[1, z1, TSvz], z1]*
D[tmpTofZ[1, z2, TSvz], z2])/(tmpTofZ[1, z1, TSvz] -
tmpTofZ[1, z2, TSvz])^2 - If[1 == 1, 1/(z1 - z2)^2, 0]) /.
z1 -> t*z1 /. z2 -> t*z2,
z1 ∈ Reals && z2 ∈ Reals]
]
During evaluation of In[93]:= DynamicSolve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[93]:= DynamicSeries::serlim: Series order specification TSvz is not a machine-sized integer.
During evaluation of In[93]:= DynamicSolve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[93]:= DynamicSeries::serlim: Series order specification TSvz is not a machine-sized integer.
During evaluation of In[93]:= DynamicSolve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[93]:= DynamicGeneral::stop: Further output of Solve::ifun will be suppressed during this calculation.
During evaluation of In[93]:= DynamicSeries::serlim: Series order specification TSvz is not a machine-sized integer.
During evaluation of In[93]:= DynamicGeneral::stop: Further output of Series::serlim will be suppressed during this calculation.
Out[93]= -(
1/(t z1 -
t z2)^2) + ((-E^(-t^2 z1^2) (-I + E^(t^2 z1^2) -
Sqrt[-1 + E^(2 t^2 z1^2)]) t z1 +
1/2 E^(-t^2 z1^2) (2 E^(t^2 z1^2) t z1 - (
2 E^(2 t^2 z1^2) t z1)/
Sqrt[-1 + E^(2 t^2 z1^2)])) (-E^(-t^2 z2^2) (-I + E^(
t^2 z2^2) - Sqrt[-1 + E^(2 t^2 z2^2)]) t z2 +
1/2 E^(-t^2 z2^2) (2 E^(t^2 z2^2) t z2 - (
2 E^(2 t^2 z2^2) t z2)/Sqrt[-1 + E^(2 t^2 z2^2)])))/(1/
2 E^(-t^2 z1^2) (-I + E^(t^2 z1^2) -
Sqrt[-1 + E^(2 t^2 z1^2)]) -
1/2 E^(-t^2 z2^2) (-I + E^(t^2 z2^2) -
Sqrt[-1 + E^(2 t^2 z2^2)]))^2
a2 =
Assuming[Im[z1] >= 0 && Im[z2] >= 0 && Re[z1] > 0 && Re[z2] > 0,
Refine[Normal[Series[a1, {t, 0, 10}]],
z1 ∈ Reals && z2 ∈ Reals]]
a3 = a2 /. t -> 1
a4 = Simplify[a3]
Out[96]= (1/967680)(-869 z1^10 - 320 z1^9 z2 + 639 z1^8 z2^2 +
1280 z1^7 z2^3 + 256 z1^3 z2^3 (-63 + 5 z2^4) -
384 z1^5 z2 (-21 + 5 z2^4) - 210 z1^4 z2^2 (12 + 5 z2^4) -
42 z1^6 (-252 + 25 z2^4) + z2^2 (-120960 + 10584 z2^4 - 869 z2^8) -
64 z1 z2 (2520 - 126 z2^4 + 5 z2^8) +
9 z1^2 (-13440 - 280 z2^4 + 71 z2^8))
a5 = FullSimplify[a4] // Expand
Out[97]= -(z1^2/8) + (7 z1^6)/640 - (869 z1^10)/967680 - (z1 z2)/6 + (
z1^5 z2)/120 - (z1^9 z2)/3024 - z2^2/8 - (z1^4 z2^2)/384 + (
71 z1^8 z2^2)/107520 - (z1^3 z2^3)/60 + (z1^7 z2^3)/756 - (
z1^2 z2^4)/384 - (5 z1^6 z2^4)/4608 + (z1 z2^5)/120 - (
z1^5 z2^5)/504 + (7 z2^6)/640 - (5 z1^4 z2^6)/4608 + (
z1^3 z2^7)/756 + (71 z1^2 z2^8)/107520 - (z1 z2^9)/3024 - (
869 z2^10)/967680
I realize of course that square root is multi-valued, so making some concessions, I utilized some Refine[]
and Assuming[]
to finally get some answers. Of course the assumptions are not physically required - they are locations on a Riemann surface and so z1
and z2
can have negative values. I think this could be done...just wanted to correct the Thread
problem I had that, now corrected, doesn't have the exponentials hanging around. I suppose I could get results (different probably?) using assumptions on both z1
and z2
from all four quadrants of the complex plane... Still curious about that...
I guess another big lingering question is why, up to order 4 and 4, I did not need Assuming[]
, and yet afterwards did... or maybe just days worth of computational time?
I have some Maxima code I am converting to Mathematica and I notice that around the cutoff of "4" to "5" for a Series, the time it takes increases a huge amount. Here is the problem,
curve = 1 - Q*b - a*(b^f)*(1 - b) /. Q -> 2 /. f -> 1
sol2 = Solve[{curve == 0, b == t}, {a, b}]
sol = {u -> Log[a], v -> Log[b]} /. sol2
curveUV = curve /. a -> Exp[u] /. b -> Exp[v]
aiT1 = u /. sol[[1]][[1]]
aiT2 = D[aiT1, t] // FullSimplify
ai = Solve[aiT2 == 0, t]
N = Length[ai]
uai[i_] := (u /. sol[[1]][[1]]) /. ai[[i]][[1]]
uofz[i_, z_] := z^2 + uai[i]
duofz[i_, z_] := D[uofz[i, z], z]
tmpEq[i_, Z_] := curveUV /. u -> uofz[i, Z]
tmpSol[i_, z_] := Solve[tmpEq[i, z] == 0, v]
vofz[i_, z_, TSvz_] := FullSimplify[Normal[Series[v /. tmpSol[i, z][[1]], {z, 0, TSvz}]]]
tmpTofZ[i_, z_, TSvz_] := Exp[vofz[i, z, TSvz]] // FullSimplify
What I next want to do is build expressions (4, as i
and j
each range from 1 to 2) where I can extract the regular terms of this series.
RegTerms[i_, j_, z1_, z2_, TSvz_, TS1_, TS2_] :=
(*Simplify[*)
Normal[
Series[
(*Simplify[*)
(*Expand[*)
(D[tmpTofZ[i, z1, TSvz], z1]*
D[tmpTofZ[j, z2, TSvz], z2])/(tmpTofZ[i, z1, TSvz] -
tmpTofZ[j, z2, TSvz])^2 - If[i == j, 1/(z1 - z2)^2, 0]
(*]*)
(*]*)
, {z1, 0, TS1}, {z2, 0, TS2}
]
]
So I want to extract the coefficients for later use (lots of use), so I think of a table,
** edit: The time issue is the same, but the 'RT' wasn't there - copy/paste error, can just ignore the 'RT'. **
Timing[
Table[
RT[i, j] =
FullSimplify[
RegTerms[i, j, z1, z2, 15, 4, 4]
]
, {i, 1, 2}
, {j, 1, 2}
]
]
and these are the timing results;
For series expansion orders of 2 and 2 -- about 2 seconds:
In[130]:= Timing[
Table[
RT[i, j] =
FullSimplify[
RegTerms[i, j, z1, z2, 15, 2, 2]
]
, {i, 1, 2}
, {j, 1, 2}
]
]
During evaluation of In[130]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[130]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[130]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[130]:= General::stop: Further output of Solve::ifun will be suppressed during this calculation.
Out[130]= {1.8701, {{1/24 (-3 z1^2 - 4 z1 z2 - 3 z2^2),
1/8 (-4 - z1 z2 (4 + 3 z1 z2))}, {1/8 (-4 - z1 z2 (4 + 3 z1 z2)),
1/24 (-3 z1^2 - 4 z1 z2 - 3 z2^2)}}}
For series expansion orders of 3 and 3 -- about 3 seconds:
In[131]:= Timing[
Table[
RT[i, j] =
FullSimplify[
RegTerms[i, j, z1, z2, 15, 3, 3]
]
, {i, 1, 2}
, {j, 1, 2}
]
]
During evaluation of In[131]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[131]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[131]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[131]:= General::stop: Further output of Solve::ifun will be suppressed during this calculation.
Out[131]= {2.92662, {{1/
120 (-15 z1^2 - 20 z1 z2 - 15 z2^2 - 2 z1^3 z2^3),
1/8 (-4 - z1 z2 (4 + z1 z2 (3 + 2 z1 z2)))}, {1/
8 (-4 - z1 z2 (4 + z1 z2 (3 + 2 z1 z2))),
1/120 (-15 z1^2 - 20 z1 z2 - 15 z2^2 - 2 z1^3 z2^3)}}}
For series expansion orders of 4 and 4 -- about 38 seconds:
In[132]:= Timing[
Table[
RT[i, j] =
FullSimplify[
RegTerms[i, j, z1, z2, 15, 4, 4]
]
, {i, 1, 2}
, {j, 1, 2}
]
]
During evaluation of In[132]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[132]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[132]:= Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
During evaluation of In[132]:= General::stop: Further output of Solve::ifun will be suppressed during this calculation.
Out[132]= {38.4277, {{(-320 z1 z2 - 240 z2^2 - 5 z1^4 z2^2 -
32 z1^3 z2^3 - 5 z1^2 (48 + z2^4))/
1920, -(1/2) - (z1 z2)/2 - (3 z1^2 z2^2)/8 - (z1^3 z2^3)/4 + (
5 z2^4)/48 + (5 z1^4 (24 - 41 z2^4))/1152}, {-(1/2) - (z1 z2)/
2 - (3 z1^2 z2^2)/8 - (z1^3 z2^3)/4 + (5 z2^4)/48 + (
5 z1^4 (24 - 41 z2^4))/1152, (-320 z1 z2 - 240 z2^2 -
5 z1^4 z2^2 - 32 z1^3 z2^3 - 5 z1^2 (48 + z2^4))/1920}}}
To order 5 and 5, it takes so long I just kill it as I know for what I want, orders 10 and 10 or more, it would be a lifetime.
I don't claim to know much about Mathematica, actually fairly new to it, and I know each CAS has its advantages and disadvantages, but to order 10 (10,10), Maxima does this exactly in about 5 seconds or less.
Is there something obvious that I am doing wrong?
PS Any suggestions on better methods (e.g. pure functions, this or that, etc.) is greatly appreciated too!