The most straightforward way appears to be using carefully simple replacement rules involving RuleDelayed
rather than Rule
:
HornerForm[ E^(I x) + 2 E^(2 I x) + 3 E^(3 I x) + 4 E^(4 I x) + 5 E^(5 I x)
+ 6 E^(6 I x) + 7 E^(7 I x) + 8 E^(8 I x) + 9 E^(9 I x) + 10 E^(10 I x) /.
E^(Complex[0, b_] x) :> z^b, z] /. z :> E^(I x)
% // TraditionalForm
We should remember one subtlety using patterns in replacement rules involving complex (imaginary) factors, which we can illustrate with e.g.:
FullForm @ Unevaluated[ 5 I x]
FullForm[ 5 I x]
Unevaluated[ Times[5, I, x]]
Times[ Complex[0, 5], x]
namely: built-in rewriting rules of the system automatically evaluate Times[ 5, I]
to Complex[0, 5]
being an atom:
AtomQ[ Complex[0, 5]]
True
therefore we couldn't make our rule simpler and had used E^(Complex[0, b_] x) :> z^b
instead of something like apparently simpler E^(I b_ x) :> z^b
.