# How to get rid of complex terms in the given expression and rewrite it as a real function?

I have an expression exp in terms of the parameter $$n\in\mathbb{N}^+$$ which takes the values $$n=\{ 1,2,3,4,5,6,7,8,9,10 \}$$. As can be seen (a picture is also attached), the expression contains complex exponential and imaginary unit $$i$$ but when I simplify the function for each value of $$n$$, the answer is always real.

How can I get rid of those complex exponential and imaginary unit $$i$$ in the expression and rewrite it as a real function in terms of $$n$$? I tried exp // ExpToTrig // ExpandAll // ComplexExpand // FullSimplify but did not help.

exp :=  E^((10 I π n)/11) (112960 Cos[(2 π n)/11] + 112896 Cos[(4 π n)/11] + 112714 Cos[(6 π n)/11] + 111828 Cos[(8 π n)/11] + 117404 Cos[(10 π n)/11] + I (-56491 I + 22 Sin[(2 π n)/11] + 42 Sin[(4 π n)/11] + 140 Sin[(6 π n)/11] + 746 Sin[(8 π n)/11] - 6322 Sin[(10 π n)/11]));

exp /. n -> {1, 2} // ComplexExpand // FullSimplify

(* { 61863 - 112982 Cos[π/11] + 111082 Cos[(2 π)/11] -112854 Sin[π/22] + 112574 Sin[(3 π)/22] -112938 Sin[(5 π)/22],
61863 - 112854 Cos[π/11] + 112982 Cos[(2 π)/11] -112938 Sin[π/22] + 111082 Sin[(3 π)/22] -112574 Sin[(5 π)/22]} *)

This seems to be a rather recalcitrant beast. But we may tame it by adding the conjugate complex as we already know that the imaginary part is zero:

Simplify[(exp + Conjugate[exp])/2 // ExpToTrig // Expand ,
n \[Element] Integers  ]

$Version (* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *) Clear["Global`*"] exp := E^((10 I π n)/11) (112960 Cos[(2 π n)/11] + 112896 Cos[(4 π n)/11] + 112714 Cos[(6 π n)/11] + 111828 Cos[(8 π n)/11] + 117404 Cos[(10 π n)/11] + I (-56491 I + 22 Sin[(2 π n)/11] + 42 Sin[(4 π n)/11] + 140 Sin[(6 π n)/11] + 746 Sin[(8 π n)/11] - 6322 Sin[(10 π n)/11])); First verify that exp is real for integer n Assuming[n ∈ Integers, exp == Re[exp] // FullSimplify] (* True *) Then exp = Re[exp] // ComplexExpand // Simplify (* 61863 + 55541 Cos[(2 n π)/11] + 56287 Cos[(4 n π)/11] + 56427 Cos[(6 n π)/11] + 56469 Cos[(8 n π)/11] + 56491 Cos[(10 n π)/11] + 56491 Cos[(12 n π)/11] + 56469 Cos[(14 n π)/11] + 56427 Cos[(16 n π)/11] + 56287 Cos[(18 n π)/11] + 55541 Cos[(20 n π)/11] *) expression = E^((10 I π n)/11) (112960 Cos[(2 π n)/11] + 112896 Cos[(4 π n)/11] + 112714 Cos[(6 π n)/11] + 111828 Cos[(8 π n)/11] + 117404 Cos[(10 π n)/11] + I (-56491 I + 22 Sin[(2 π n)/11] + 42 Sin[(4 π n)/11] + 140 Sin[(6 π n)/11] + 746 Sin[(8 π n)/11] - 6322 Sin[(10 π n)/11])); The purpose of the following answer is to verify that the expression is real and to re-write it in such a way that it is explicitly real for integer n. Outline: • Verifying that the expression is real for integer n • Re-writing the expression to explicitly see that it is real for integer n Verifying that the expression is real for integer n It is easier to check that the expression is real when each term is in its exponential form: Note: in the variable names below …= \[Ellipsis] expression$only…exponentials = TrigToExp[expression]

$$55541 e^{\frac{2 i \pi n}{11}}+56287 e^{\frac{4 i \pi n}{11}}+56427 e^{\frac{6 i \pi n}{11}}+56469 e^{\frac{8 i \pi n}{11}}+56491 e^{\frac{10 i \pi n}{11}}+56491 e^{\frac{12 i \pi n}{11}}+56469 e^{\frac{14 i \pi n}{11}}+56427 e^{\frac{16 i \pi n}{11}}+56287 e^{\frac{18 i \pi n}{11}}+55541 e^{\frac{20 i \pi n}{11}}+61863$$

Then, the operation of conjugation changes an angle $$\theta$$ by $$2\pi k-\theta$$. A convenient choice for $$k$$ here is n:

expression$$only…exponentials$$conjugated =
expression$only…exponentials /. Exp[iθ_] :> Exp[2*Pi*n*I - iθ] $$55541 e^{\frac{2 i \pi n}{11}}+56287 e^{\frac{4 i \pi n}{11}}+56427 e^{\frac{6 i \pi n}{11}}+56469 e^{\frac{8 i \pi n}{11}}+56491 e^{\frac{10 i \pi n}{11}}+56491 e^{\frac{12 i \pi n}{11}}+56469 e^{\frac{14 i \pi n}{11}}+56427 e^{\frac{16 i \pi n}{11}}+56287 e^{\frac{18 i \pi n}{11}}+55541 e^{\frac{20 i \pi n}{11}}+61863$$ Check: expression$$only…exponentials$$conjugated == expression$only…exponentials

(* True *)

Re-writing the expression to explicitly see that it is real for integer n

The expression is real as every integer coefficient is multiplied by a complex number and its conjugate. A natural re-writing of the expression can be obtained by collecting/grouping the complex conjugate pairs and factoring the common numerical coefficient. Collect is a natural candidate but it only collects variables. We will wrap the coefficients around an arbitrary function c to replace the integer coefficients with variables:

Note: c is a global variable that might conflict with other variables in your notebook.

to…variables =
f_?NumericQ*Exp[iθ_] :> c[f]*Exp[iθ];

expression$$only…exponentials$$mod =
expression\$only…exponentials /. to…variables

The expression can be simplified using that modification and we may then remove the wrapper c:

expression$$only…exponentials$$mod //
Collect[#, Cases[#, c[_], All], FullSimplify] & //
ReplaceAll[c -> Identity]

$$112982 e^{i \pi n} \cos \left(\frac{\pi n}{11}\right)+112938 e^{i \pi n} \cos \left(\frac{3 \pi n}{11}\right)+112854 e^{i \pi n} \cos \left(\frac{5 \pi n}{11}\right)+112574 e^{i \pi n} \cos \left(\frac{7 \pi n}{11}\right)+111082 e^{i \pi n} \cos \left(\frac{9 \pi n}{11}\right)+61863$$

Note the $$e^{i \pi n}$$ which is real for integer n. Adding // FullSimplify[#, n ∈ Integers] & at the end of that last code makes the expression even more clearly real for integer n:

$$2 (-1)^n \left(56491 \cos \left(\frac{\pi n}{11}\right)+56469 \cos \left(\frac{3 \pi n}{11}\right)+56427 \cos \left(\frac{5 \pi n}{11}\right)+56287 \cos \left(\frac{7 \pi n}{11}\right)+55541 \cos \left(\frac{9 \pi n}{11}\right)\right)+61863$$