Re: Preventing unwanted threading by Inner
- To: mathgroup at smc.vnet.net
- Subject: [mg123487] Re: Preventing unwanted threading by Inner
- From: Ray Koopman <koopman at sfu.ca>
- Date: Thu, 8 Dec 2011 05:28:51 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jbni23$47f$1@smc.vnet.net>
On Dec 7, 3:18 am, Chris Young <c... at comcast.net> wrote: > I'm trying to prevent Inner from expanding my points into coordinates: > > In[283]:= Inner[Times, {a, b, c}, {{A, =CE=B1}, {B, =CE=B2}, {C, =CF=87}}, Plus] > Out[283]= {a A + b B + c C, a =CE=B1 + b =CE=B2 + c =CF=87} > > As I understand it, this has to do with Times being Listable: > > In[304]:= Attributes[Times] > Out[304]= {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected} > > But clearing the listable attribute doesn't do anything: > > Unprotect[Times]; > ClearAttributes[Times, Listable]; > myInnnerProd = Inner[Times, {a, b, c}, {{A, =CE=B1}, {B, =CE=B2}, {C, =CF=87}}, Plus]; > SetAttributes[Times, Listable]; > Protect[Times]; > > In[315]:= myInnnerProd > > Out[315]= {a A + b B + c C, a =CE=B1 + b =CE=B2 + c =CF=87} > > In addition, I have to resort to using Hold on the points. Not sure > why; I would have thought that making Times non-listable would have > been enough. > > In[343]:= > Unprotect[Times]; > ClearAttributes[Times, Listable]; > myInnerProd = > Inner[Times, {a, b, c}, Hold /@ {{A, =CE=B1}, {B, =CE=B2}, {C, =CF=87}}, Plus]; > myInnnerProd = ReleaseHold[myInnerProd] > SetAttributes[Times, Listable]; > Protect[Times]; > > Out[346]= a {A, =CE=B1} + b {B, =CE=B2} + c {C, =CF=87} Inner[Times, {a1,a2,a3}, {b1,b2,b3}, Plus] /. Thread[{b1,b2,b3} -> HoldForm /@ {{b11,b12},{b21,b22},{b31,b32}}] a1 {b11,b12} + a2 {b21,b22} + a3 {b31,b32}