Re: Symbolic vector handling

*To*: mathgroup at smc.vnet.net*Subject*: [mg83468] Re: Symbolic vector handling*From*: David Bailey <dave at Remove_Thisdbailey.co.uk>*Date*: Wed, 21 Nov 2007 02:50:19 -0500 (EST)*References*: <200711180946.EAA01450@smc.vnet.net> <fhrshf$66f$1@smc.vnet.net>

danl at wolfram.com wrote: >> Hello group, >> >> this is most probably a very simple question but still ... >> >> Consider a set of vectors vA, vB, vC, ... and scalars a, b, c, ... >> >> What I want to do is a symbolic handling of expressions like vA.(b vB + >> vC) >> which should be expanded to >> >> (1) expr = vA.(b vB + vC) -> b vA.vB + vA.vC >> >> i.e. I want Mathematica to apply the distributive law and the >> extraction of scalars. >> I don't want to use any coordinate representation. >> >> The first thing that comes into mind would be to define a type "vector" >> and another type "scalar" and then define the usual rules. >> >> I'd like to execute a comand like >> >> FunctionExpand[ expr , Assumptions->{{vA, vB, vC} "elem" vectors, >> {a,b,c} "elem" scalars}] >> >> Here's an example of a simple problem in which my question arises: >> >> Let the vectors vR1 and vR2 be defined in terms of four other vectors >> vA1, vA2, vN1, vN2 and two scalars a and b as follows: >> >> vR1 = vA1 + a vN1 >> vR2 = vA2 + b vN2 >> >> and consider the function >> >> U = (vR1 - vR2).(vR1 - vR2) >> >> The task is to find the minimum of U in terms of a combination of >> scalar product of the vectors vA1, vA2, vN1, vN2 and of the optimizing >> parameters a and b. >> >> Any help is greatly appreciated. >> >> Regards, >> Wolfgang > > There are probably a few reasonable ways to go about this. One is to use a > special vector "head" and define rules for handling distribution involving > Plus, Times, and whatever else might be of relevance. I encapsulate your > vectors with vec[]. > > I find it convenient to move to a new function, myDot, for purposes of > intermediate computation. This avoids placing new behavior on Dot itself. > > myDot[a_] /; Head[a] =!= vec := a > myDot[x___, y_Plus, z___] := Map[myDot[x, #, z] &, y] > myDot[x___, y_Dot, z___] := myDot[x, Apply[Sequence, y], z] > myDot[x___, y_Times, z___] := myDot[x, Apply[Sequence, y], z] > myDot[x___, y_myDot, z___] := myDot[x, Apply[Sequence, y], z] > myDot[] = 1; > myDot[x___, y_, z___] /; Head[y] =!= vec := y*myDot[x, z] > > DotExpand[expr_] := (expr /. Dot -> myDot) /. myDot -> Dot > > In[54]:= DotExpand[vec[vA].(b*vec[vB] + vec[vC])] > > Out[54]= b vec[vA].vec[vB] + vec[vA].vec[vC] > > The above myDot is an alteration of some code I cribbed from the section > "Some noncommutative algebraic manipulation" in the 1998 conference > notebook at: > > http://library.wolfram.com/infocenter/Conferences/325/ > > > Daniel Lichtblau > Wolfram Research > > > > Or why not use one of the undefined operators - such as CircleTimes - instead of Dot? Done that way, you can avoid the need for the DotExpand function because you can define the properties of CircleTimes directly. David Bailey http://www.dbaileyconsultancy.co.uk

**References**:**Symbolic vector handling***From:*"Dr. Wolfgang Hintze" <weh@snafu.de>