I believe that what you're looking for is some data structure Vector
which has some list defining direction and some scalar which in part defines magnitude.
Here you go:
Vector[a_List] := Vector[1, a]
Vector[b_, _]["scalar"] := b
Vector[_, a_List]["vector"] := a
Vector /: (b_ Vector[c_, a_List]) := Vector[c b, a]
a = 3 Vector[{1, 1, 0}];
b = 2 Vector[.3, {3, 2, 0}];
If you want to "extract" the scalars, then use magicfunction
:
Vector /: magicfunction[a__Vector, z_] :=
Times @@ (#["scalar"] &) /@ List[a] z @@ (#["vector"] &) /@ List[a]
For instance:
magicfunction[a, b, Cross]
(* {0., 0., -1.8} *)
magicfunction[a, b, Hold]
(* 1.8 Hold[{1, 1, 0}, {3, 2, 0}] *)
In order to get the regular vector back, just use Normal
. Make sure you have a copy of your Vector
, however, as this transformation will lose the information about the scalar.
Vector /: Normal[Vector[b_, a_List]] := b a
Normal[a]
(* {3, 3, 0} *)