4

I am looking for a way to simply the general expression in cross product and dot product with general vectors. I got a help in How do I simplify a vector expression? but soon I find that it doesn't work in the case

FullSimplify[Cross[vec[x], 2*vec[y]] + Cross[vec[y], 2*vec[x]] ]

it doesn't give zero. It seems that Mathematica doesn't know how to expand the following expression

Cross[vec[x], 2*vec[y]] -> 2*Cross[vec[x], vec[y]]
user1285419
  • 577
  • 1
  • 4
  • 12
  • You have to create some rules for instance vec/: Cross[Times[al___,vl_vec,ar___],Times[bl___,vr_vec,br___]] := Times[al,ar,bl,br,Cross[vl,vr]]. – Spawn1701D Apr 16 '13 at 23:17
  • Hi there, thanks for your reply. I try that code, but when I apply that, it reports "TagSetDelayed::tagnf: Tag OverVector not found in (al___\ ar___\ vl_vec)[Cross](bl___ br___ vr_vec)" – user1285419 Apr 17 '13 at 01:52
  • Yes my mistake sorry, its too deep. You got to Unprotect Cross and assign the rule to Cross instead: Cross[Times[al___,vl_vec,ar___],Times[bl___,vr_vec,br___]] := Times[al,ar,bl,br,Cross[vl,vr]] – Spawn1701D Apr 17 '13 at 02:05
  • I am sorry to bother again. I try the following but it doesn't work, am I doing anything wrong? Unprotect[Cross]; Cross[Times[al___, vl_vec, ar___], Times[bl___, vr_vec, br___]] := Times[al, ar, bl, br, Cross[vl, vr]] FullSimplify[Cross[x, 2*y] + Cross[y, 2*x]] – user1285419 Apr 17 '13 at 02:42

3 Answers3

6

You can use TensorReduce and Vectors:

$Assumptions = Element[vec[x] | vec[y], Vectors[{n}]];

TensorReduce[Cross[vec[x],2*vec[y]]+Cross[vec[y],2*vec[x]]]

0

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
5

Since it seems you want your vec[] objects to be nicely formatted, here's one way to go about it:

Remove[vec]; (* clear everything!! *)

vec /: MakeBoxes[vec[x_], StandardForm] := TagBox[FormBox[
              TemplateBox[{MakeBoxes[x, StandardForm]}, "vec",
                          DisplayFunction :> (OverscriptBox[#1, "⇀"] &)],
              StandardForm], StandardForm, Editable -> True]

Now, vec[x] will display as $\overset{\tiny\rightharpoonup}{x}$ in StandardForm. Having done this, we can again do Spawn's initial suggestion to use TagSetDelayed[]:

vec /: Cross[v1_vec, v2_vec] /; ! OrderedQ[{v1, v2}] := -Cross[v2, v1];
vec /: Cross[p_ v1_vec, v2_vec] := p Cross[v1, v2];
vec /: Cross[v1_vec, q_ v2_vec] := q Cross[v1, v2];

Test:

samples of vec's behavior

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
4

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.

Spawn1701D
  • 1,871
  • 13
  • 14
  • Rather than unprotecting Cross[], it is usually better to use TagSet[]/TagSetDelayed[] associated with vec[]. For instance, here's the flipping rule: vec /: Cross[v1_vec, v2_vec] /; ! OrderedQ[{v1, v2}] := -Cross[v2, v1]. Now, try Cross[vec[y], vec[x]]. – J. M.'s missing motivation Apr 17 '13 at 03:44
  • @J.M. Its too deep, not for this rule but the following ones. – Spawn1701D Apr 17 '13 at 03:50
  • How so? If you add vec /: Cross[Times[al__, vl_vec], vr_vec] := Times[al, Cross[vl, vr]] and then do Cross[3 vec[y], vec[x]], it still works. – J. M.'s missing motivation Apr 17 '13 at 04:32
  • @J.M. look the comments with the OP and you will understand why I thought so. – Spawn1701D Apr 17 '13 at 04:40
  • Apparently, there's something wrong with his implementation of vec[], since TagSet[] is seeing it as an OverVector[] object. I think an answer is in order... – J. M.'s missing motivation Apr 17 '13 at 04:43
  • @J.M. probably he wrote the vector using the mathematical notation for it, nevertheless the suggestion I gave him, in that form, has problem - OverVector or not OverVector present. – Spawn1701D Apr 17 '13 at 04:46
  • thanks all. it works up to now. I am just wonder how to apply these to complicate expression like Dot[vec[x], Cross[vec[y], vec[z]]] + Dot[vec[x], Cross[vec[y], vec[x]]] ? – user1285419 Apr 17 '13 at 05:07
  • @user1285419 in the same fashion you can add the properties of Dot and Cross you want. For instance vec/:Dot[a:_vec, Cross[_, a:_vec]|Cross[a:_vec, _]] = 0. Depends on what you want to implement. – Spawn1701D Apr 17 '13 at 05:32
  • @Spawn1701D thanks. I am just wondering if there is any way to include all possible combinations of operations instead of define each of them individually – user1285419 Apr 17 '13 at 05:36
  • Like a student Mathematica must be taught ;) – Spawn1701D Apr 17 '13 at 06:14
  • So Cross[a vec[x], vec[y]] works, Cross[vec[x], b vec[y]] works but Cross[a vec[x], b vec[y]] doesn't work :( – user1285419 Apr 26 '13 at 01:49
  • @user1285419 indeed thats why first I attached the rule to Outer. – Spawn1701D Apr 26 '13 at 05:20
  • @user1285419 I revert back to my initial answer. – Spawn1701D Apr 26 '13 at 05:27