2
$\begingroup$

I have a long calculation that I am doing, which involves a particular variable h, which in the end, is either +1 or -1. (I would like a general result that is true for both cases.) Since h only takes these values, h^2 = h^4 = h^6 ... = 1, and h^3 = h^5 = ... = h. It would greatly simplify things if Mathematica could make use of these; thus, I would like to tell Mathematica to assume h^2 = 1.

However, if I do, e.g.,

Simplify[h^2, h^2 = 1]

I get the errors

Set::write: Tag Power in h^2 is Protected. >>
Simplify::bass: 1 is not a well-formed assumption. >>

If I try:

Simplify[h^2, h\[Element]{-1,1}]

It returns just h^2, not 1.

If I try:

Simplify[h^2, h=1 || h=-1]

then I get the errors:

Set::write: Tag Or in 1||h is Protected. >>
Simplify::bass: -1 is not a well-formed assumption. >>

How can I tell Mathematica to use the assumption that h^2 = 1?

Thank you for your time.

$\endgroup$
3
  • 1
    $\begingroup$ Try Simplify[h^2, h^2 == 1] There is an important difference between Set (i.e., =) and Equals (i.e. ==) $\endgroup$ – bill s Feb 21 '15 at 5:28
  • $\begingroup$ @bill s: Thanks! I don't know why that didn't occur to me. $\endgroup$ – Lauren Pearce Feb 21 '15 at 5:30
  • $\begingroup$ The one that really throws people is SameQ (i.e., ===) $\endgroup$ – bill s Feb 21 '15 at 5:32
1
$\begingroup$

Since the expression isn't guaranteed to have a unique value in general when the input variables can have multiple discrete values, we have to use an approach that can give you all possible results. This can be done with Reduce instead of Simplify. Here are two examples:

expression /. 
 List@ToRules[
   Reduce[Join[{expression == a b + a b^2 + a^2 b}, 
     Map[#^2 == 1 &, {a, b}]]]]

(* ==> {-1, -1, -1, 3} *)

This is a list of all possible outcomes for the expression under the assumption that both a and b can be $\pm 1$. A more interesting special relation is this:

expression /. 
 List@ToRules[
   Reduce[Join[{expression == a b + a y + x b - x y}, 
     Map[#^2 == 1 &, {a, b, x, y}]]]]

(* ==> {-2, -2, -2, 2, -2, 2, 2, 2, -2, 2, 2, 2, -2, -2, -2, 2} *)

Here we have four variables with value $\pm 1$, and the value of the expression turns out to always be $\pm 2$. If you want to know what combinations of inputs belong to which outputs, you can leave out the expression/. part at the beginning.

If you only want to know the set of possible outputs, you can wrap the above in DeleteDuplicates[...].

$\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.