
(* Copyright 1988,1990 Wolfram Research Inc. *)

(*:Version: Mathematica 2.0 *)

(*:Name: LinearAlgebra`VectorAlgebra` *)

(*:Title: Symbolic Properties of Vector Dot and Cross Products *)

(*:Author:
	Wolfram Research Inc. 
*)

(*:Keywords:
	vector, cross product, dot product, triple scalar product
*)

(*:Requirements: none. *)

(*:Warnings: none. *)

(*:Sources:
	Introduction to Vector Analysis, by Harry Davis and Arthur D. 
	Snider, Allyn and Bacon, 1979
*)

(*:Summary:
Vector identities for dot product, cross product, and triple scalar product.
*)


BeginPackage["LinearAlgebra`CrossProduct`"]
		
		(**  Vector Cross Products  **)
		
Cross::usage = 
	"Cross[vec1, vec2] gives the vector product of the 3-vectors
	vec1 and vec2."

Begin["LinearAlgebra`CrossProduct`private`"]

Cross[v1_?VectorQ, v2_?VectorQ] :=
	Module[{m=Minors[{v1,v2},2][[1]]},
		{m[[3]], -m[[2]], m[[1]]}
	]	/; Length[v1]==Length[v2]==3

(* Properties of cross products. *)

Cross/: Cross[a_,b_]^2 := a.a b.b - (a.b)^2

Cross[a_,a_] = 0

Cross[a_ + b_, c_] := Cross[a,c] + Cross[b,c]
Cross[a_, b_ + c_] := Cross[a,b] + Cross[a,c]

Cross[a_,0] = 0
Cross[0,a_] = 0

Cross[(n_?NumberQ) a_, b_] := n Cross[a, b]

Cross[a_, (n_?NumberQ) b_] := n Cross[a, b]

Cross[a_,Cross[b_,c_]] := (a.c) b - (a.b) c
Cross[Cross[a_,b_],c_] := (a.c) b - (b.c) a

Unprotect[Dot]

(* Properties of dot products. *)

a_ . ((n_?NumberQ) b_) := n (a.b)
((n_?NumberQ) a_) . b_ := n (a.b)

a_ . (b_ + c_) := a.b + a.c
(a_ + b_) . c_ := a.c + b.c

a_ . 0 = 0
0 . a_ = 0

a_ . Cross[a_,b_] = 0
a_ . Cross[b_,a_] = 0

Cross[a_,b_] . a_ = 0
Cross[b_,a_] . b_ = 0

Cross[a_,b_] . c_ := a . Cross[b,c]

a_ . Cross[b_,c_] := b . Cross[c,a] /; !OrderedQ[{a,b}]
a_ . Cross[b_,c_] := c . Cross[a,b] /; !OrderedQ[{a,c}]

(* This rule must be given after other rules involving Cross
are defined. *)

Cross[a_,b_] := -Cross[b,a] /; !OrderedQ[{a,b}] 

End[]  (* LinearAlgebra`CrossProduct`Private` *)

Protect[Cross,Dot]

EndPackage[ ]  (* LinearAlgebra`CrossProduct` *)

(*:Limitations: none known. *)


(*:Examples:
Cross[ { a, b, c }, { d, e, f } ]

Cross[ { a, b, c }, Cross[ { d, e, f }, { g, h, i } ] ]

*)
