The simplest way to get the output you want is to enter the objects representing the vectors as String
like this:
"{1,0,1}" + "{2,0,1}" + 3 "{1,0,1}" - "{4,4,7}" - 3 "{2,0,1}"
4 {1,0,1} - 2 {2,0,1} - {4,4,7}
This is just a particularly simple version of what @Szabolcs mentioned in the comment: you don't want the lists representing the vectors to be understood as List
objects, because otherwise Times
will always look into them. By giving the "vectors" a Head
different from List
for which no special multiplication rules exist, they become like indivisible objects that behave the way you want under multiplication.
The good thing about String
as the Head
is that it not only hides the content from Times
, but also still displays the way you want. The latter can in principle also be achieved by coming up with a completely new name like vec
to wrap your list of components, and then defining how that new object displays by using Format
:
Format[vec[x_, y_, z_]] = {x, y, z}
vec[1, 0, 1] + vec[2, 0, 1] + 3 vec[1, 0, 1] - vec[4, 4, 7] - 3 vec[2, 0, 1]
4 {1,0,1} -2 {2,0,1} - {4,4,7}
With the latter approach, you can also add more tricks:
vec[x_, y_, z_] /; GCD[x, y, z] != 1 :=
Module[{g = GCD[x, y, z]}, g Apply[vec, {x, y, z}/g]]
vec[2, 2, 4]
(* ==> 2 {1, 1, 2} *)
This way, the integers in the vec
components are reduced to the point where they are mutually prime, further reducing the number of vectors in a general expression, which is a simplification that can be done without doing all the other multiplications.
{1,0,1}
you can use a symbola
and later substitutea -> {1,0,1}
. Or you can use a special head4 vec[1,0,1] - 2 vec[2,0,1] ...
and later substitutevec -> List
as needed. Or something similar to this. $\endgroup$