1
$\begingroup$

If we have a three dimensional vector variable:

$Assumptions = a ∈ Vectors[3];

and a three dimensional vector value for example:

b = {1, 2, 3};

Then a + b evaluates to {1 + a, 2 + a, 3 + a}. We would expect the sum to generate a + {1, 2, 3}, because the elements of vector $\mathbf{a}$ are, as yet, unspecified. It looks Mathematica recognizes a as a scalars, which is not intended.

How can we get Mathematica to generate a + {1, 2, 3} as expected?

$\endgroup$
2
$\begingroup$

The behavior you're seeing is a consequence of the Listable attribute of Plus. This means that mixing explicit and symbolic vectors in arithmetic will not work correctly, and should be avoided.

Phrased another way: Since Plus is Listable, a + {1, 2, 3} will always evaluate to {1+a, 2+a, 3+a}. The only exceptions are when a evaluates to a List object, in which case it will thread, or issue a message if dimensions are incompatible. In other words, your desired endpoint will always evaluate further.

$\endgroup$
  • $\begingroup$ Thank you for your answer, but why the replication is applied to a? It is assumed as a list, and the manual tells replication is applied only for that are not list. $\endgroup$ – hsmtta Mar 26 at 18:29
  • $\begingroup$ Specific assumptions apply to specific transformations. Plus doesn't apply any assumptions at all, it simply sees a as a symbol, and transforms the expression accordingly. It's only a list if it has the head List. $\endgroup$ – John Doty Mar 26 at 18:32
  • $\begingroup$ @JohnDoty I see. Thanks! $\endgroup$ – hsmtta Mar 26 at 18:54
  • $\begingroup$ @CarlWoll Thank you so much for editing your answer. I completely understood how Mathematica recognizes and deals with a. Assuming object as a vectors is not equal to making list object! I hope Mathematica supports vector calculus which contains both explicit and symbolic vectors. $\endgroup$ – hsmtta Mar 27 at 13:34
0
$\begingroup$

There is a simple way to have things behave as you wish. Define your vector using Array (instead of trying to use an assumption:

aVec = Array[a, 3];
aVec + {1, 2, 3}
{1 + a[1], 2 + a[2], 3 + a[3]}
$\endgroup$
  • $\begingroup$ Thanks! But can I archive the intended result by not defining the vector elements? As another post says, I don't want to define new variables... $\endgroup$ – hsmtta Mar 27 at 13:51

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.