3

How to simplify the following trigonometry expression such that the number of used characters is minimal?

(13*Cos[t] - 5*Cos[2*t] - 2*Cos[3*t] - Cos[4*t])/4

The question sounds weird because I ask for the minimal number of used characters, but it is not a typo. The number of used characters must be minimal because the plotter needs short expression. Please ignore the computation performance for this case.

kiss my armpit
  • 757
  • 4
  • 15

3 Answers3

10

I don't know about the expression with "minimal chracters", but the following is the version I like, since you only have to evaluate the cosine once as a common subexpression:

HornerForm[(13 Cos[t] - 5 Cos[2 t] - 2 Cos[3 t] - Cos[4 t])/4 /.
           Cos[n_Integer  t] :> ChebyshevT[n, Cos[t]], Cos[t]]

1 + Cos[t] (19/4 + Cos[t] (-(1/2) + (-2 - 2 Cos[t]) Cos[t]))

As Yves notes, you can now use a scoping construct (i.e. any of Block[]/Module[]/With[]) to isolate the common subexpression. For instance:

With[{ct = Cos[t]}, 1 + ct (19/2 - ct (1 + 4 ct (1 + ct)))/2]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
7

I'm not sure I understand the question - surely there must be some syntax rules for the expression sent to the plotter. Anyway, the shortest Mathematica expression I can think of is:

{-13, 5, 2, 1}.Cos[{1, 2, 3, 4} t]/-4
Simon Woods
  • 84,945
  • 8
  • 175
  • 324
3

One idea is to use something like

FullSimplify[
  (13*Cos[t] - 5*Cos[2*t] - 2*Cos[3*t] - Cos[4*t])/4
  , ComplexityFunction -> Composition[StringLength, ToString, InputForm]
]

which instructs FullSimplify to optimize the number of input characters for the expression. In this case it doesn't get any shorter though.

Thies Heidecke
  • 8,814
  • 34
  • 44