How to expand dot product by applying properties
Some time ago I developed a function for these sort of symbolic vector computations, called dotExand
. For example, it will expand (2 x + 3 y, x-y)
to 2(x,x)+(x,y)-3(y,y)
. Here I use the, at least in my country more common, notation (x,y)
for the inner product of the vectors x
and y
. The advantage is that complicated expressions become more readable in this notation than in the infix notation with the dot. To achieve this output, I define
MakeBoxes[Dot[a_, b_], StandardForm] := RowBox[{"(", ToBoxes[a], ",", ToBoxes[b], ")"}];
The function dotExpand
will work both in real and complex vector spaces. To this end, there is a second argument dom
, which may take the values Reals
or Complexes
. The default value is Reals
.
dotExpand[exp_, dom : (Reals | Complexes) : Reals] :=
Module[{res},
res = ExpandAll[exp] /. Dot[x_, y_] :> Distribute[Dot[x, y]];
res = res //. {
Dot[ (a_ /; Simplify[a \[Element] dom]) b_, c_] :> a Dot[b, c],
Dot[ a_, (b_ /; Simplify[b \[Element] dom]) c_] :> Simplify[Conjugate[b]] Dot[a, c],
If[dom === Reals, Dot[x_, y_] :> Sort[Dot[x, y]], Unevaluated[Sequence[]]]};
Collect[res, Dot[_, _]] ]
dotExpand[Dot[ 2 x + 3 y, x - y ]]
(* 2 (x, x) + (x, y) - 3 (y, y) *)
dotExpand[Dot[ 2 x + I y, x - I y ], Complexes]
(* 2 (x, x) + 2 I (x, y) + I (y, x) - (y, y) *)
Your question:
Assuming[ {c1, c2, c3} \[Element] Reals, dotExpand[ Dot[ c1 v1, c2 v2 + c3 v3]]]
(* c1 c2 (v1, v2) + c1 c3 (v1, v3) *)
The complex case:
Assuming[ {c1, c2, c3} \[Element] Complexes, dotExpand[ Dot[ c1 v1, c2 v2 + c3 v3], Complexes]]
(* c1 Conjugate[c2] (v1, v2) + c1 Conjugate[c3] (v1, v3) *)
Finally, consider in a real vector space a triangle with vertices a
, b
and c
such that all three have the same lenght (i.e. the origin is in the centre of the circumscribed circle). Then the orthocentre of this triangle is given by h=a+b+c
. The proof of this formula is a matter of substitution:
With[{h = a + b + c}, dotExpand[{(a - h).(c - b) == 0, (b - h).(a - c) == 0}] /. Dot[z_, z_] -> R^2]
(* {True, True} *)
Here is the best I've got so far. If you can be persuaded to write your vectors in a more distinguishable way, e.g. $v_1$ as v[1]
, then the following might work for you. I'm not so sure how robust it will be, but play around with it and let me know:
Clear[specialDot]
specialDot[expr_] := ReplaceAll[
Distribute[expr, Plus, Dot, Plus, Times],
v[a_] v[b_] -> v[a].v[b]
]
Here is the example you had:
specialDot[(c1 v[1]).(c2 v[2] + c3 v[3])]
(* Out: c1 c2 v[1].v[2] + c1 c3 v[1].v[3]*)
and here is another:
specialDot[(a v[1] + b v[2] - c v[3]).(d v[4] - e v[5])]
(* Out: a d v[1].v[4] - a e v[1].v[5] + b d v[2].v[4] - b e v[2].v[5] -
c d v[3].v[4] + c e v[3].v[5] *)