Re: Precedence question
- To: mathgroup at smc.vnet.net
- Subject: [mg119286] Re: Precedence question
- From: Arturas Acus <Arturas.Acus at tfai.vu.lt>
- Date: Sun, 29 May 2011 07:36:03 -0400 (EDT)
Well, I just learned from Mark (author of DesignerUnits package http://designerunits.com/) a much better precedence adjusting solution. Study that package for details (not an easy task). Sincerely, Arturas On Sat, 28 May 2011, Arturas.Acus at tfai.vu.lt wrote: > Following David's suggestion I wrote the following > function > > myPreFunction[{x},ReplaceAll[ToExpression[StringReplace[ToString[x],{"\[Wedge]"->"\[CircleDot]","\[CenterDot]"->"\[SmallCircle]"}],StandardForm],{CircleDot->Wedge,SmallCircle->CenterDot}],{HoldAll}] > > which seems do the job. > > However I notice that if the following function > > > $PreFunction[{x},ReplaceAll[ToExpression[StringReplace[ToString[x], > {"\[CenterDot]"->"\[SmallCircle]","\[Wedge]"->"\[CircleDot]"}]],{SmallCircle->>CenterDot,CircleDot->Wedge}],{HoldAll}] > > > is evaluated inside package private context (package context impors Global`) > I encounter the problems (for example FullForm do not work properly). > > I think this function should be evaluated in the very beginning, however > I have no idea how to include it into package structure. (init.m ?) > > > > > David Bailey <dave at removedbailey.co.uk> ra=C5=A1=C4=97: > >> On 25/05/2011 10:57, Arturas.Acus at tfai.vu.lt wrote: >>> >>> Dear Group >>> In order to implement some geometric algebra code I need >>> to reverse the order of the following operators which have no built in >>> meaning: >>> >>> Precedence/@{NonCommutativeMultiply,Wedge,CenterDot} >>> >>> Acording to geometric algebra rules the highest precedence has inner >>> product operator =C2 (I plan to use CenterDot symbol to denote this), >>> then goes Wedge (outer multiplication) and last is geometric product >>> (will definetely use NonCommutativeMultiply for that) >>> >>> Because of Mathematica predefined precedences the following input >>> >>> MV[a]\[Wedge]MV[b]\[CenterDot]MV[c]**MV[d]//FullForm >>> >>> is interpreted as >>> >>> CenterDot[Wedge[MV[a],MV[b]],NonCommutativeMultiply[MV[c],MV[d]]] >>> >>> whereas I need >>> >>> NonCommutativeMultiply[Wedge[MV[a],CenterDot[MV[b],MV[c]]],MV[d]]] >>> >>> >>> Few hours of Mathematica documentation reading did not yield any simple solution. >>> >>> Sure, instead of operators with no build in meaning I can use symbols >>> with user precedence level =C2 ( for example =C2 \[RawWedge] instead of >>> \[Wedge]). >>> =C2 The problem then is to define proper Infix INPUT notation+ alias. >>> This can be done with Notation package, hovewer this is what I would >>> like to avoid, because the task becomes complicated from the very >>> begining. >>> >>> >>> Could anybody suggest more simple alternative? >>> >>> >>> Sincerely, Arturas Acus >>> >> >> One possible approach would be to supply your expressions as strings, >> and then use StringReplace to replace the operator characters with >> another set with the correct order of precedences (and no built-in >> meaning). Then you could use ToExpression on the result, and work from >> there. >> >> David Bailey >> http://www.dbaileyconsultancy.co.uk >> >> > >