9
$\begingroup$

We know that: $$ \cos\left[(i+j+k)\pi\right] = (-1)^{i+j+k} $$ for $i, j, k$ being positive integers. In Mathematica I've tried:

FullSimplify[Cos[(i + j + k)*Pi], Assumptions -> Element[{i, j, k}, {Positive, Integers}]]

But it still returns the Cos function. Does anyone know how to perform this simplification?

$\endgroup$
12
$\begingroup$

Here's another way:

 Assuming[Element[{i, j, k}, Integers], Refine[Cos[(i + j + k) Pi]]]

enter image description here

|improve this answer|||||
$\endgroup$
  • 2
    $\begingroup$ It can be shorter: Refine[Cos[(i + j + k) Pi], Element[{i, j, k}, Integers]] $\endgroup$ – Kuba Nov 21 '13 at 9:41
  • $\begingroup$ @Kuba. Indeed. Thanks $\endgroup$ – RunnyKine Nov 21 '13 at 9:42
  • $\begingroup$ @RunnyKine So... Refine can simplify better than FullSimplify in this case? $\endgroup$ – Saullo G. P. Castro Nov 21 '13 at 9:42
  • 1
    $\begingroup$ @SaulloCastro. It would seem so since FullSimplify is more general than Refine and it seems Refine is best suited for this situation. $\endgroup$ – RunnyKine Nov 21 '13 at 9:45
9
$\begingroup$
FullSimplify[Cos[(i + j + k)*Pi], 
 Assumptions -> Element[i + j + k, Integers], ComplexityFunction -> LeafCount]

(-1)^(i + j + k)

Simplify[Cos[t*Pi], Element[t, Integers]] /. t :> i + j + k

(-1)^(i + j + k)

|improve this answer|||||
$\endgroup$
4
$\begingroup$

Element is not Listable, also, Positive is not valid domain so it is reasonable to me that it is not working.

If you put the assumptions more carefully then everything is alright:

 Simplify[Cos[(i + j + k)*Pi], 
         Element[{i, j, k}, Integers] && And @@ (# > 0 & /@ {i, j, k}), 
         ComplexityFunction -> LeafCount]

$(-1)^{i+j+k}$

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you... you mean that when I do Element[{i, j, k}, Integers] it is not applying the assumptions for all the variables? $\endgroup$ – Saullo G. P. Castro Nov 21 '13 at 9:31
  • 1
    $\begingroup$ @SaulloCastro This should work but using multiple domains shouldn't. $\endgroup$ – Kuba Nov 21 '13 at 9:33
  • 1
    $\begingroup$ The ComplexityFunction option is very useful in this situation to determine the rule for ranking the most simplified $\endgroup$ – yshk Nov 21 '13 at 10:30
2
$\begingroup$

Another way is basically use the Mathematica's build in Head for all expressions. The following may seem less elegant but works for arbitrary number of summands:

Cos[(intp[a]+intp[b]+intp[c]+intp[d])*Pi]/.Cos[(Plus[x__])*Pi]:>Hold[-1^x]
/;SameQ@@((Head/@List@@x)~Join~{intp})

(* Hold[-1^(int[a]+int[b]+int[c]+int[d])] *)

where intp is positive integer.

|improve this answer|||||
$\endgroup$
  • 2
    $\begingroup$ man... this is hard core stuff... $\endgroup$ – Saullo G. P. Castro Nov 21 '13 at 13:18
  • $\begingroup$ This technique is usually good for create data type. Too brutal for this case. $\endgroup$ – yshk Nov 22 '13 at 1:07

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.