4
$\begingroup$

I want to know how to get the HornerForm of the following expression in terms of E^(I x):

 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)

HornerForm[ expr, E^(I x)] doesn't work as well as something like Collect[ expr, E^(I x]].
How can I get the desired form?

$\endgroup$
8
$\begingroup$

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)

enter image description here

% // TraditionalForm

enter image description here

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.

$\endgroup$
  • $\begingroup$ Oops apparently we took almost the same approach! :P $\endgroup$ – Leo Fang Oct 10 '13 at 1:10
  • $\begingroup$ @Artes Great! Rule Replace, I got that $\endgroup$ – matheorem Oct 10 '13 at 1:16
  • $\begingroup$ @Artes Great! But it seems that ` Times[a_, Power[E, Times[Complex[0, b_], x]]] :> a z^b ` is rebundant, right? $\endgroup$ – matheorem Oct 10 '13 at 1:22
  • $\begingroup$ @matheorem yes, that was redundant, just improved. $\endgroup$ – Artes Oct 10 '13 at 1:26
  • 1
    $\begingroup$ @LeoFang You had to map Power[E, Times[Complex[0, #], x]] -> y^# & because you had used Rule (->) instead of RuleDelayed (:>) $\endgroup$ – Artes Oct 10 '13 at 1:34
2
$\begingroup$

This only works for the special case given in your post:

input =  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);
HornerForm[input/. (Power[E, Times[Complex[0, #], x]] -> y^# & /@ 
 Range[1, 10])] /. y -> Exp[I x]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.