Re: Preventing unwanted threading by Inner
- To: mathgroup at smc.vnet.net
- Subject: [mg123498] Re: Preventing unwanted threading by Inner
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Fri, 9 Dec 2011 05:55:29 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jbni23$47f$1@smc.vnet.net> <201112081027.FAA19076@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
Oleksandr, I like the simple elegance of your solution, partly because it's easy to get rid of "coordinate" at any time, as in coordinate /: Format[coordinate[pts_List]] := pts {a, b, c}.coordinate /@ {{A, \[Alpha]}, {B, \[Beta]}, {C, \[Chi]}} % /. coordinate -> Identity a {A, \[Alpha]} + b {B, \[Beta]} + c {C, \[Chi]} {a A + b B + c C, a \[Alpha] + b \[Beta] + c \[Chi]} Bobby On Thu, 08 Dec 2011 04:27:28 -0600, Oleksandr Rasputinov <oleksandr_rasputinov at hmamail.com> wrote: > On Wed, 07 Dec 2011 11:18:27 -0000, Chris Young <cy56 at comcast.net> wrote: > >> I'm trying to prevent Inner from expanding my points into coordinates: >> >> In[283]:= Inner[Times, {a, b, c}, {{A, \[Alpha]}, {B, \[Beta]}, {C, >> \[Chi]}}, Plus] >> Out[283]= {a A + b B + c C, a \[Alpha] + b \[Beta] + c \[Chi]} >> >> 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, \[Alpha]}, {B, \[Beta]}, {C, >> \[Chi]}}, Plus]; >> SetAttributes[Times, Listable]; >> Protect[Times]; >> >> In[315]:= myInnnerProd >> >> Out[315]= {a A + b B + c C, a \[Alpha] + b \[Beta] + c \[Chi]} >> >> 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, \[Alpha]}, {B, \[Beta]}, {C, >> \[Chi]}}, Plus]; >> myInnnerProd = ReleaseHold[myInnerProd] >> SetAttributes[Times, Listable]; >> Protect[Times]; >> >> Out[346]= a {A, \[Alpha]} + b {B, \[Beta]} + c {C, \[Chi]} >> > > Redefining built-in functions in such a drastic way is seldom a good idea > because Mathematica makes assumptions about the way these functions > operate and does not handle alterations gracefully. In this case it seems > that Inner does not check to see if the Attributes set on Times have been > changed and instead uses a direct internal (kernel) function call as if > it > had the default Attributes. > > I assume you want this form for display purposes or because you want to > keep the coordinates as isolated entities. In that case, rather than > redefining Times, you could use: > > coordinate /: Format[coordinate[pts_List]] := pts > > {a, b, c} . coordinate /@ {{A, \[Alpha]}, {B, \[Beta]}, {C, \[Chi]}} > -- DrMajorBob at yahoo.com
- References:
- Re: Preventing unwanted threading by Inner
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
- Re: Preventing unwanted threading by Inner