My equations contain different cases which differ only by some signs. So in order to work with all cases simultaneously, I introduce a placeholder for a sign:


where x labels which sign that is. Now when I perform manipulations of my terms, I encounter higher powers of the same sign, like s[1]^2. Of course the square of a sign should be just s[1]^2=1, so I try to define a rule:


SetDelayed::write: Tag Power in s[x_]^2 is Protected.

As you can see, there is an error message and the rule does not get set. How should I be going about defining a rule that sets the square of any s[x] to 1?


1 Answer 1


You can use TagSetDelayed i.e.:

s /: s[x_]^2 := 1

This will create a substitution rule (UpValue) for symbol s, which is only applied, when s is inside Power[s[_], 2].

  • 1
    $\begingroup$ Thank you! I went with s /: s[x_]^n_Integer /; n > 1 := s[x]^Mod[n, 2]. $\endgroup$
    – Kagaratsch
    May 19, 2017 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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