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


Groups > comp.soft-sys.math.mathematica > #6982 > unrolled thread

Preventing unwanted threading by Inner

Started byChris Young <cy56@comcast.net>
First post2011-12-07 11:18 +0000
Last post2011-12-10 12:30 +0000
Articles 10 — 5 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  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

#6982 — Preventing unwanted threading by Inner

FromChris Young <cy56@comcast.net>
Date2011-12-07 11:18 +0000
SubjectPreventing unwanted threading by Inner
Message-ID<jbni23$47f$1@smc.vnet.net>
I'm trying to prevent Inner from expanding my points into coordinates:

In[283]:= Inner[Times, {a, b, c}, {{A, α}, {B, β}, {C, χ}}, Plus]
Out[283]= {a A + b B + c C, a α + b β + c χ}

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, α}, {B, β}, {C, χ}}, Plus];
SetAttributes[Times, Listable];
Protect[Times];

In[315]:= myInnnerProd

Out[315]= {a A + b B + c C, a α + b β + c χ}

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, α}, {B, β}, {C, χ}}, Plus];
myInnnerProd = ReleaseHold[myInnerProd]
SetAttributes[Times, Listable];
Protect[Times];


Out[346]= a {A, α} + b {B, β} + c {C, χ}

[toc] | [next] | [standalone]


#7034

From"Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Date2011-12-08 10:38 +0000
Message-ID<jbq43r$irr$1@smc.vnet.net>
In reply to#6982
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]}}

[toc] | [prev] | [next] | [standalone]


#7101

FromChris Young <cy56@comcast.net>
Date2011-12-10 12:44 +0000
Message-ID<jbvk6h$j6v$1@smc.vnet.net>
In reply to#7034
On 2011-12-08 10:38:51 +0000, Oleksandr Rasputinov said:

> 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]}}

Thanks, I'm filing this away also.


[toc] | [prev] | [next] | [standalone]


#7040

FromRay Koopman <koopman@sfu.ca>
Date2011-12-08 10:42 +0000
Message-ID<jbq49t$itm$1@smc.vnet.net>
In reply to#6982
On Dec 7, 3:18 am, Chris Young <c...@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}

This is a little better than my first suggestion.

Inner[Times, {a1,a2,a3}, HoldForm /@
{{b11,b12},{b21,b22},{b31,b32}}, Plus]

a1 {b11,b12} + a2 {b21,b22} + a3 {b31,b32}

[toc] | [prev] | [next] | [standalone]


#7100

FromChris Young <cy56@comcast.net>
Date2011-12-10 12:43 +0000
Message-ID<jbvk5i$j6o$1@smc.vnet.net>
In reply to#7040
On 2011-12-08 10:42:05 +0000, Ray Koopman said:

> This is a little better than my first suggestion.
> 
> Inner[Times, {a1,a2,a3}, HoldForm /@
> {{b11,b12},{b21,b22},{b31,b32}}, Plus]
> 
> a1 {b11,b12} + a2 {b21,b22} + a3 {b31,b32}

I see in the Help that HoldForm can help with preventing unwanted 
expansion of a lot of formulas:

Display a sum of squares in unevaluated form:

\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(10\)]\(\((HoldForm[
\*SuperscriptBox[\(#1\), \(2\)]] &)\)[i]\)\)

\!\(\*
TagBox[
SuperscriptBox["1", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["2", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["3", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["4", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["5", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["6", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["7", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["8", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["9", "2"],
HoldForm]\) + \!\(\*
TagBox[
SuperscriptBox["10", "2"],
HoldForm]\)

[toc] | [prev] | [next] | [standalone]


#7110

FromDrMajorBob <btreat1@austin.rr.com>
Date2011-12-11 08:52 +0000
Message-ID<jc1r04$t1k$1@smc.vnet.net>
In reply to#7040
I think Chris meant:

Sum[(HoldForm[#1^2] & )[i], {i, 1, 10}]

1^2+2^2+3^2+4^2+5^2+6^2+7^2+8^2+9^2+10^2

or

(I converted the first cell to InputForm in Mathematica, copied the output  
as Plain Text, and pasted both into e-mail.)

Bobby

On Sat, 10 Dec 2011 06:31:49 -0600, Chris Young <cy56@comcast.net> wrote:

> On 2011-12-08 10:42:05 +0000, Ray Koopman said:
>
>> This is a little better than my first suggestion.
>>
>> Inner[Times, {a1,a2,a3}, HoldForm /@
>> {{b11,b12},{b21,b22},{b31,b32}}, Plus]
>>
>> a1 {b11,b12} + a2 {b21,b22} + a3 {b31,b32}
>
> I see in the Help that HoldForm can help with preventing unwanted
> expansion of a lot of formulas:
>
> Display a sum of squares in unevaluated form:
>
> \!\(
> \*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(10\)]\(\((HoldForm[
> \*SuperscriptBox[\(#1\), \(2\)]] &)\)[i]\)\)
>
> \!\(\*
> TagBox[
> SuperscriptBox["1", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["2", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["3", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["4", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["5", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["6", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["7", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["8", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["9", "2"],
> HoldForm]\) + \!\(\*
> TagBox[
> SuperscriptBox["10", "2"],
> HoldForm]\)
>
>


-- 
DrMajorBob@yahoo.com

[toc] | [prev] | [next] | [standalone]


#7041

FromRay Koopman <koopman@sfu.ca>
Date2011-12-08 10:42 +0000
Message-ID<jbq4as$iu1$1@smc.vnet.net>
In reply to#6982
On Dec 7, 3:18 am, Chris Young <c...@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}

[toc] | [prev] | [next] | [standalone]


#7070

FromChris Young <cy56@comcast.net>
Date2011-12-10 12:29 +0000
Message-ID<jbvjap$irj$1@smc.vnet.net>
In reply to#7041
On 2011-12-08 10:42:36 +0000, Ray Koopman said:

> 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}

Thanks

[toc] | [prev] | [next] | [standalone]


#7048

FromDrMajorBob <btreat1@austin.rr.com>
Date2011-12-09 10:58 +0000
Message-ID<jbspl3$3r3$1@smc.vnet.net>
In reply to#6982
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

[toc] | [prev] | [next] | [standalone]


#7071

FromVince Virgilio <blueschi@gmail.com>
Date2011-12-10 12:30 +0000
Message-ID<jbvjdl$ito$1@smc.vnet.net>
In reply to#6982
On Wednesday, December 7, 2011 6:18:27 AM UTC-5, Chris Young wrote:
> I'm trying to prevent Inner from expanding my points into coordinates:


This MathGroup thread might interest you:

https://groups.google.com/d/topic/comp.soft-sys.math.mathematica/V-eUZ6Q8Z60/discussion

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web