# FullSimplify not finding trig substitution with other terms present

Consider the following:

FullSimplify[Cos[x - y - z] + Cos[x + y + z] + 1]


Mathematica simply returns the exact expression with no simplification. However, if I instead write

FullSimplify[Cos[x - y - z] + Cos[x + y + z]]


I get

2 Cos[x] Cos[y + z]


How can I get Mathematica to recognize that the first two terms in the first expression can be combined? It seems that the addition of an extra term prevents Mathematica from finding a proper simplification.

Addendum:

Here is a more complex case which Mathematica is still struggling to simplify

Cos[1/4 (x - 2 y - z)] + Cos[1/4 (x + 2 y - z)] + Cos[(x + z)/4]


which should reduce to

2 Cos[y/2] Cos[(x - z)/4] + Cos[(x + z)/4]


## 2 Answers

The idea is using ComplexityFunction to make MMA treat Plus as more expensive than, e.g. Times (if you know in advance that answer should not contain Plus):

FullSimplify[expr, ComplexityFunction -> (100 Count[#, _Plus] + LeafCount[#] &)]


that gives

1 + 2 Cos[x] Cos[y + z]


EDIT

Next is very clumsy, but we may apply FullSimplify on parts of expression and see what is the LeafCount of the result.

expr = Cos[1/4 (x - 2 y - z)] + Cos[1/4 (x + 2 y - z)] + Cos[(x + z)/4]
subs=Subsets[expr,{2,3}]
compl=Complement[expr,#]&/@subs
MinimalBy[Thread[expr[[0]]@@{FullSimplify[subs],compl}],LeafCount]


And we get

{2 Cos[y/2] Cos[(x - z)/4] + Cos[(x + z)/4]}.

• Thanks, I was unaware of this capability. However it is still failing to simplify some stuff, I edited my post with a more complex example – Kai Aug 2 '19 at 15:49

Try TrigExpand

TrigExpand[Cos[x - y - z] + Cos[x + y + z] + 1 ]
(*1 + 2 Cos[x] Cos[y] Cos[z] - 2 Cos[x] Sin[y] Sin[z]*)