Lets write some simple rules for Cross
that will work in conjunction with the object vec
:
first of all we have to Unprotect
the command Cross
:
Unprotect[Cross]
to be safe because we are screwing around with a system command we save the current set of downvalues to a temporary varaiable:
temp = DownValues[Cross]
we begin with a rule for the skew-symmetric property:
Cross[vl_vec,vr_vec]/;!OrderedQ[{vl,vr}] := -Cross[vr,vl]
we continue for the multiplication by a scalar rule
Cross[Times[al__, vl_vec], vr_vec] := Times[al, Cross[vl, vr]]
Cross[vl_vec,Times[al__, vr_vec]] := Times[al, Cross[vl, vr]]
Cross[Times[al__ ,vl_vec],Times[bl__, vr_vec]] := Times[al, bl, Cross[vl, vr]]
I split them in two in order to cover the case Cross[vec[x],2*vec[y]] for instance where one of the is not multiplied by a scalar.
Now the command
Cross[vec[x], 2*vec[y]] + Cross[2*vec[y], vec[x]]
will give
0
to return everything the way thy were:
DownValues[Cross] = temp
or just Quit
the Kernel.
vec/: Cross[Times[al___,vl_vec,ar___],Times[bl___,vr_vec,br___]] := Times[al,ar,bl,br,Cross[vl,vr]]
. $\endgroup$Unprotect
Cross
and assign the rule toCross
instead:Cross[Times[al___,vl_vec,ar___],Times[bl___,vr_vec,br___]] := Times[al,ar,bl,br,Cross[vl,vr]]
$\endgroup$