Re: Replace expressions
- To: mathgroup at smc.vnet.net
- Subject: [mg7688] Re: Replace expressions
- From: Stephen P Luttrell <luttrell at signal.dra.hmg.gb>
- Date: Sun, 29 Jun 1997 22:17:23 -0400 (EDT)
- Organization: Defence Research Agency
- Sender: owner-wri-mathgroup at wolfram.com
Hans Steffani wrote: > > hans.steffani at e-technik.tu-chemnitz.de (Hans Steffani) writes: > > >I want to replace all expressions > >Dot[a, xx] > >Dot[xx, a] > >for certain as by > >Times[a,xx]. > > To say it in other words > I have a list certainas, which contains a number of symbols. > > This symbols are scalars and therefore I am allowed to substitute > Dot[a,b] by Times[a,b] if a or b is in the list certainas. > > How can this be done. > Here is an example of how to solve this problem: (1) Define a pair of assignments for simplifying expressions of the form Dot[a_,xx] and Dot[xx,a_], provided that a is a member of the list certainas (^:= is used rather than := in order to associate the assignment with xx rather than Dot; this is a matter of taste): Dot[a_,xx]^:=a xx/;MemberQ[certainas,a]; Dot[xx,a_]^:=a xx/;MemberQ[certainas,a]; (2) Define an example list to work with: certainas={a1,a2,a3}; (3) See whether the substitutions are made correctly in some specific cases. The following input: Dot[a1,xx] Dot[xx,a2] Dot[b,xx] Dot[xx,b] produces the following output: a1 xx a2 xx b.xx xx.b which is what was expected, given the chosen elements of certainas. ===================================================================== Dr Stephen P Luttrell luttrell at signal.dra.hmg.gb Adaptive Systems Theory 01684-894046 (phone) Room EX21, Defence Research Agency 01684-894384 (fax) Malvern, Worcs, WR14 3PS, U.K. http://www.dra.hmg.gb/cis5pip/Welcome.html