Skip to main content

simplifying expressions - Separating exponential terms


Suppose I have a lot of expressions multiplied by factors such as:


$$e^{-i\theta[1]-i\theta[2] - i\theta[3]-i\theta[4]-i\theta[5]}$$


I would like to separate this into a product of exponentials of the form


$$e^{-i\theta[1]}e^{-i\theta[2]}...$$


before employing the function ExpToTrig and making substitutions to the result trigonometric functions.



However, since I plan to apply the tangent half angle substitution (cf. my previous question Simplifying Expressions for FindMinimum), I would like the arguments to involve only one variable at a time. In particular, I tried using ComplexExpand on the function to express the trigonometric functions as functions of a single variable, but it expands the entire function out.


In short, I would like to keep the simplified form, but want to expand the exponential as per the above without having to expand the entire expression.


For reference, here is my function


(E^(-I θ[1] - I θ[2] - I θ[3] - I θ[4] - I (θ[5] - θ[6]))
Abs[Sin[ϕ[6]]]^2 (1 - E^(I (θ[1] - θ[6]))
Cot[ϕ[6]/2] Tan[ϕ[1]/2]) (Cos[θ[1]] + I Sin[θ[1]] + E^(I θ[2])
Tan[ϕ[1]/2] Tan[ϕ[2]/2]) (Cos[θ[2]] + I Sin[θ[2]] + E^(I θ[3])
Tan[ϕ[2]/2] Tan[ϕ[3]/2]) (Cos[θ[3]] + I Sin[θ[3]] + E^(I θ[4])
Tan[ϕ[3]/2] Tan[ϕ[4]/2]) (Cos[θ[5] - θ[6]] + I Sin[θ[5] - θ[6]] - Cot[ϕ[6]/2]
Tan[ϕ[5]/2]) (Cos[θ[4]] + I Sin[θ[4]] + E^(I θ[5])

Tan[Ï•[4]/2] Tan[Ï•[5]/2]))/
(2 Sqrt[(1 + Abs[Tan[Ï•[1]/2]]^2) (1 + Abs[Tan[Ï•[2]/2]]^2)]
Sqrt[(1 + Abs[Tan[Ï•[2]/2]]^2) (1 + Abs[Tan[Ï•[3]/2]]^2)]
Sqrt[(1 + Abs[Tan[Ï•[3]/2]]^2) (1 + Abs[Tan[Ï•[4]/2]]^2)]
Sqrt[(1 + Abs[Tan[Ï•[4]/2]]^2) (1 + Abs[Tan[Ï•[5]/2]]^2)]
Sqrt[(1 + Abs[Tan[Ï•[1]/2]]^2) (1 + Cos[Ï•[6]])]
Sqrt[(1 + Abs[Tan[Ï•[5]/2]]^2) (1 + Cos[Ï•[6]])])

Answer



Update


In the interest of simplifying the code somewhat, I've modified one of the replacements. For instance, we can do



expr2 = Thread[expr1, Plus] /. Plus -> Times

or


epxr2 = expr1 /. expT[Plus[a__]] :> Times @@ expT /@ a

rather than


expr2 = expr1 //. {expT[a_ + b_] :> expT[a] expT[b]}

So:


f[expr_] := Thread[expr /. Power[E, a_] :> expT@Expand@a, Plus] /. Plus -> Times /. expT[a_] :> ExpToTrig@Exp@a


or


f[expr_] := expr /. Power[E, a_] :> expT@Expand@a /. expT[Plus[a__]] :> Times @@ expT /@ a /. expT[a_] :> ExpToTrig@Exp@a

Original Post


As Bill commented, Mathematica likes to keep Exp[]'s together. Here's a workaround that I've used in the past. We replace Exp with a dummy head expT, do the re-write using replacement rules, and in the process apply ExpToTrig.


For instance, if


expr = Exp[-I (4 + a) + c];

we first do



expr1 = expr /. Power[E, a_] :> expT@Expand@a
(* expT[-4 I - I a + c] *)

Then, we separate the terms inside expT using ReplaceRepeated:


expr2 = expr1 //. {expT[a_ + b_] :> expT[a] expT[b]}
(* expT[-4 I] expT[-I a] expT[c] *)

Finally, we convert back to Exp and apply ExpToTrig:


expr2 /. expT[a_] :> ExpToTrig@Exp@a
(* (Cos[4] - I Sin[4]) (Cos[a] - I Sin[a]) (Cosh[c] + Sinh[c]) *)


We can do all at once, of course. Define


f[expr_] := expr /. Power[E, a_] :> expT@a //. {expT[a_ + b_] :> expT[a] expT[b]} /. expT[a_] :> ExpToTrig@Exp@a

in which case


f[expr]
(* (Cos[4] - I Sin[4]) (Cos[a] - I Sin[a]) (Cosh[c] + Sinh[c]) *)

Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...