Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7048

Re: Preventing unwanted threading by Inner

From DrMajorBob <btreat1@austin.rr.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Preventing unwanted threading by Inner
Date 2011-12-09 10:58 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jbspl3$3r3$1@smc.vnet.net> (permalink)
References <jbni23$47f$1@smc.vnet.net> <201112081027.FAA19076@smc.vnet.net>

Show all headers | View raw


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@hmamail.com> wrote:

> On Wed, 07 Dec 2011 11:18:27 -0000, Chris Young <cy56@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@yahoo.com

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Preventing unwanted threading by Inner Chris Young <cy56@comcast.net> - 2011-12-07 11:18 +0000
  Re: Preventing unwanted threading by Inner "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-12-08 10:38 +0000
    Re: Preventing unwanted threading by Inner Chris Young <cy56@comcast.net> - 2011-12-10 12:44 +0000
  Re: Preventing unwanted threading by Inner Ray Koopman <koopman@sfu.ca> - 2011-12-08 10:42 +0000
    Re: Preventing unwanted threading by Inner Chris Young <cy56@comcast.net> - 2011-12-10 12:43 +0000
    Re: Preventing unwanted threading by Inner DrMajorBob <btreat1@austin.rr.com> - 2011-12-11 08:52 +0000
  Re: Preventing unwanted threading by Inner Ray Koopman <koopman@sfu.ca> - 2011-12-08 10:42 +0000
    Re: Preventing unwanted threading by Inner Chris Young <cy56@comcast.net> - 2011-12-10 12:29 +0000
  Re: Preventing unwanted threading by Inner DrMajorBob <btreat1@austin.rr.com> - 2011-12-09 10:58 +0000
  Re: Preventing unwanted threading by Inner Vince Virgilio <blueschi@gmail.com> - 2011-12-10 12:30 +0000

csiph-web