x[t_] := {Subscript[x, 1][t], Subscript[x, 2][t]}

following replace works fine

x[t] /. x[t] -> 0

but following one is a problem

x[t] - 1 /. x[t] -> 0
{-1 + Subscript[x, 1][t], -1 + Subscript[x, 2][t]}

because I expect there '-1'.


1 Answer 1


First and foremost, x is a vector, so perhaps you meant x[t]-{1,1}. But your problem is another one, and it is linked to the 'overarching evaluation' of Mathematica. (Maybe one day, if I find the time, I'll add an entry to the Pitfalls in Mathematica post, since this is one of the most common pitfalls new users fall in).

When you ask MMA to evaluate

x[t] - 1 /. x[t] -> 0

A statement equivalent to

ReplaceAll[x[t] - 1, x[t] -> 0]

Mathematica evaluates the arguments of ReplaceAll before calling ReplaceAll itself. So, what ReplaceAll sees is (I won't use subscripts for brevity, hence for me x[t_]:={x1[t],x2[t]}) EDIT: corrected my blunder

 ReplaceAll[{x1[t],x2[t]} - 1, {x1[t],x2[t]} -> 0]

and there is no valid rule to apply there. You might want to specify the vector's components as in

 ReplaceAll[x[t] - 1, {x1[t] -> 0,x2[t]->0}]

Or, in short (using the improper mixture of vectors and scalars you are using)

 ReplaceAll[x[t] - 1, Thread[x[t] -> 0]]

But I would use vectors instead of 1 and 0, either by specifying their components {1,1} and {0,0} or by defining a zeroVec and a unityVec with those components.

If you want to specify vectors as symbols only, either you use some sort of Holdind and Releaseing to avoid the overarching evaluator, or you revise the way you define your vectors (for example by leaving vectors undefined and using replacement rules to specify their components at the end of your 'vector symbolic' calculations).

  • $\begingroup$ Thank you for help. Of course it is better to use {0, 0} and {1, 1} in this example. $\endgroup$
    – V_V
    Nov 20, 2013 at 23:01

Your Answer

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

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