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


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

new functional operator

Started byroby <roby.nowak@gmail.com>
First post2012-03-03 11:52 +0000
Last post2012-03-08 09:38 +0000
Articles 11 — 5 participants

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


Contents

  new functional operator roby <roby.nowak@gmail.com> - 2012-03-03 11:52 +0000
    Re: new functional operator noqsiaerospace@gmail.com - 2012-03-04 09:37 +0000
      Re: new functional operator roby <roby.nowak@gmail.com> - 2012-03-08 09:37 +0000
      Re: new functional operator roby <roby.nowak@gmail.com> - 2012-03-08 09:40 +0000
      Re: new functional operator roby <roby.nowak@gmail.com> - 2012-03-08 09:40 +0000
        Re: new functional operator roby <roby.nowak@gmail.com> - 2012-03-09 11:11 +0000
        Re: new functional operator Murray Eisenberg <murray@math.umass.edu> - 2012-03-10 11:21 +0000
      Re: new functional operator Barrie Stokes <Barrie.Stokes@newcastle.edu.au> - 2012-03-10 11:14 +0000
      Re: new functional operator Barrie Stokes <Barrie.Stokes@newcastle.edu.au> - 2012-03-10 11:15 +0000
      Re: new functional operator roby <roby.nowak@gmail.com> - 2012-03-13 08:01 +0000
    Re: new functional operator "branton.campbell" <branton.campbell@gmail.com> - 2012-03-08 09:38 +0000

#8845 — new functional operator

Fromroby <roby.nowak@gmail.com>
Date2012-03-03 11:52 +0000
Subjectnew functional operator
Message-ID<jit0me$e32$1@smc.vnet.net>
Dear Group and Mathematica staff.

In the functional programming spirit I am missing a postfix notation
for Map[ ].

Du to its clarity I often prefer the sequentiall postfix style
processing of expressions and data:
e.g.

data//F1//F2//F3


but what if our data is a List and the functions we want to perform on
don't have the Listable Attribute ?.
the clumsy solution now is:

data//F1/@#&//F2/@#&//F3/@#&



therefor I suggest a new functional operator, which e.g. could look
like this: ///
such that my favorit expression would appear in this nice and clear
form:

data///F1///F2///F3


In other words the new /// operator should temporarily activate the
Listable Atrribute for the affected function


any comments welcome

Robert

[toc] | [next] | [standalone]


#8855

Fromnoqsiaerospace@gmail.com
Date2012-03-04 09:37 +0000
Message-ID<jivd47$n7j$1@smc.vnet.net>
In reply to#8845
On Saturday, March 3, 2012 8:52:46 PM UTC+9, roby wrote:
> Dear Group and Mathematica staff.
> 
> In the functional programming spirit I am missing a postfix notation
> for Map[ ].

How about:


RightVector[a_,f_]:=Map[f, a]
RightVector[a_,more__]:=RightVector[Map[{more}[[1]],a],Sequence@@Drop[{more},1]]

Then:

{1,2,3}\[RightVector](#^2&)\[RightVector]g

yields:

{g[1],g[4],g[9]}

(it looks nicer in a notebook)

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


#8915

Fromroby <roby.nowak@gmail.com>
Date2012-03-08 09:37 +0000
Message-ID<jj9uke$dqg$1@smc.vnet.net>
In reply to#8855
On 4 Mrz., 10:37, noqsiaerosp...@gmail.com wrote:
> On Saturday, March 3, 2012 8:52:46 PM UTC+9, roby wrote:
> > Dear Group and Mathematica staff.
>
> > In the functional programming spirit I am missing a postfix notation
> > forMap[ ].
>
> How about:
>
> RightVector[a_,f_]:=Map[f, a]
> RightVector[a_,more__]:=RightVector[Map[{more}[[1]],a],Sequence@@Drop[{more },1]]
>
> Then:
>
> {1,2,3}\[RightVector](#^2&)\[RightVector]g
>
> yields:
>
> {g[1],g[4],g[9]}
>
> (it looks nicer in a notebook)

Yes,

THIS IS IT

surprisingly easy, surprisingly not yet standard in Mathematica

can even be prettyfied a little bit:

RightVector[a_,f_]:=f/@a
RightVector[a_,more__]:=RightVector[First@{more}/
@a,Sequence@@Rest@{more}]

or we can use LeftTee[ ] which in contrast to RightArrow[ ] already
implements the neccesary left-assocciativitiy such that:

LeftTee[a_, f_] := f /@ a

is all we need.


{1,2,3}\[LeftTee]Sin\[LeftTee]Sqrt
(looks nicer in a notebook)


Robert

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


#8921

Fromroby <roby.nowak@gmail.com>
Date2012-03-08 09:40 +0000
Message-ID<jj9uq9$dt0$1@smc.vnet.net>
In reply to#8855
On 4 Mrz., 10:37, noqsiaerosp...@gmail.com wrote:
> On Saturday, March 3, 2012 8:52:46 PM UTC+9, roby wrote:
> > Dear Group and Mathematica staff.
>
> > In the functional programming spirit I am missing a postfix notation
> > for Map[ ].
>
> How about:
>
> RightVector[a_,f_]:=Map[f, a]
> RightVector[a_,more__]:=RightVector[Map[{more}[[1]],a],Sequence@@Drop[{more },1]]
>
> Then:
>
> {1,2,3}\[RightVector](#^2&)\[RightVector]g
>
> yields:
>
> {g[1],g[4],g[9]}
>
> (it looks nicer in a notebook)

even more tricky:

RightVector[a_,first_,rest___]:=
If[rest===Null,first/@a,RightVector@@{first/@a,rest}]

Robert

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


#8922

Fromroby <roby.nowak@gmail.com>
Date2012-03-08 09:40 +0000
Message-ID<jj9ur8$dtl$1@smc.vnet.net>
In reply to#8855
On 4 Mrz., 10:37, noqsiaerosp...@gmail.com wrote:
> On Saturday, March 3, 2012 8:52:46 PM UTC+9, roby wrote:
> > Dear Group and Mathematica staff.
>
> > In the functional programming spirit I am missing a postfix notation
> > for Map[ ].
>
> How about:
>
> RightVector[a_,f_]:=Map[f, a]
> RightVector[a_,more__]:=RightVector[Map[{more}[[1]],a],Sequence@@Drop[{more },1]]
>
> Then:
>
> {1,2,3}\[RightVector](#^2&)\[RightVector]g
>
> yields:
>
> {g[1],g[4],g[9]}
>
> (it looks nicer in a notebook)

...  sorry for flooding the group, but got it even nicer:

RightVector[a_, first_, rest___] := If[rest === Null, first /@ a,
RightVector[first /@ a, rest]]

Robert

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


#8936

Fromroby <roby.nowak@gmail.com>
Date2012-03-09 11:11 +0000
Message-ID<jjcogp$q9a$1@smc.vnet.net>
In reply to#8922
Ok, next version.

One can look for an prefix operator with no buit in meaning to modify
the function in question such that it acts mapping,
this way we can use the standard // postfix operator and just modify
the behavoir of the function:


\[Del] fn_ := fn /@ # &

{1,2,3,4}//\[Del]f//\[Del]g

Out[5]= {g[f[1]], g[f[2]], g[f[3]], g[f[4]]}

(looks all nice in a Notebook)



Robert

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


#8954

FromMurray Eisenberg <murray@math.umass.edu>
Date2012-03-10 11:21 +0000
Message-ID<jjfdg3$823$1@smc.vnet.net>
In reply to#8922
An unfortunate choice of notation, \[Del], for that operator. After all 
\[Del] is a universal notation for grad, the gradient operator.

On 3/9/12 6:09 AM, roby wrote:
> Ok, next version.
>
> One can look for an prefix operator with no buit in meaning to modify
> the function in question such that it acts mapping,
> this way we can use the standard // postfix operator and just modify
> the behavoir of the function:
>
>
> \[Del] fn_ := fn /@ #&
>
> {1,2,3,4}//\[Del]f//\[Del]g
>
> Out[5]= {g[f[1]], g[f[2]], g[f[3]], g[f[4]]}
>
> (looks all nice in a Notebook)
>
>
>
> Robert
>

-- 
Murray Eisenberg                     murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

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


#8941

FromBarrie Stokes <Barrie.Stokes@newcastle.edu.au>
Date2012-03-10 11:14 +0000
Message-ID<jjfd3h$7so$1@smc.vnet.net>
In reply to#8855
Hi Roby

Very nice also; even prettier is, e.g.,

In[288]:= {1, 2,  3} \[LeftTee] (s \[Function] Sin[     s^(2 Log[    s]) ])

Out[288]= {Sin[1], Sin[2^(2 Log[2])], Sin[3^(2 Log[3])]}

and

In[289]:= {1, 2, 3} \[LeftTee] Sin \[LeftTee] Sqrt \[LeftTee] (s \[Function] Sin[ s^(2 Log[ s ]) ])

Out[289]= {Sin[Sin[1]^(1/2 Log[Sin[1]])], 
 Sin[Sin[2]^(1/2 Log[Sin[2]])], Sin[Sin[3]^(1/2 Log[Sin[3]])]}

for someone who thinks "#" and "@" are ugly.

I think I like LeftTee more than RightVector, since the former sort of "points" in the direction of application of the pure function.

Maybe LeftVector is another possibility?

Now I just need to devise a mnemonic keyboard shortcut ...

Cheers

Barrie

>>> On 08/03/2012 at 8:36 pm, in message <201203080936.EAA14139@smc.vnet.net>, roby
<roby.nowak@gmail.com> wrote:
> On 4 Mrz., 10:37, noqsiaerosp...@gmail.com wrote:
>> On Saturday, March 3, 2012 8:52:46 PM UTC+9, roby wrote:
>> > Dear Group and Mathematica staff.
>>
>> > In the functional programming spirit I am missing a postfix notation
>> > forMap[ ].
>>
>> How about:
>>
>> RightVector[a_,f_]:=Map[f, a]
>> RightVector[a_,more__]:=RightVector[Map[{more}[[1]],a],Sequence@@Drop[{more 
> },1]]
>>
>> Then:
>>
>> {1,2,3}\[RightVector](#^2&)\[RightVector]g
>>
>> yields:
>>
>> {g[1],g[4],g[9]}
>>
>> (it looks nicer in a notebook)
> 
> Yes,
> 
> THIS IS IT
> 
> surprisingly easy, surprisingly not yet standard in Mathematica
> 
> can even be prettyfied a little bit:
> 
> RightVector[a_,f_]:=f/@a
> RightVector[a_,more__]:=RightVector[First@{more}/
> @a,Sequence@@Rest@{more}]
> 
> or we can use LeftTee[ ] which in contrast to RightArrow[ ] already
> implements the neccesary left-assocciativitiy such that:
> 
> LeftTee[a_, f_] := f /@ a
> 
> is all we need.
> 
> 
> {1,2,3}\[LeftTee]Sin\[LeftTee]Sqrt
> (looks nicer in a notebook)
> 
> 
> Robert

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


#8942

FromBarrie Stokes <Barrie.Stokes@newcastle.edu.au>
Date2012-03-10 11:15 +0000
Message-ID<jjfd4g$7t9$1@smc.vnet.net>
In reply to#8855
Hi Robert

Nice!

But for even greater elegance, IMHO, how about

In[277]:= {a, b, c} \[RightVector] (s \[Function] s^2)

Out[277]= {a^2, b^2, c^2}

Cheers

Barrie

>>> On 08/03/2012 at 8:39 pm, in message <201203080939.EAA14205@smc.vnet.net>, roby
<roby.nowak@gmail.com> wrote:
> On 4 Mrz., 10:37, noqsiaerosp...@gmail.com wrote:
>> On Saturday, March 3, 2012 8:52:46 PM UTC+9, roby wrote:
>> > Dear Group and Mathematica staff.
>>
>> > In the functional programming spirit I am missing a postfix notation
>> > for Map[ ].
>>
>> How about:
>>
>> RightVector[a_,f_]:=Map[f, a]
>> RightVector[a_,more__]:=RightVector[Map[{more}[[1]],a],Sequence@@Drop[{more 
> },1]]
>>
>> Then:
>>
>> {1,2,3}\[RightVector](#^2&)\[RightVector]g
>>
>> yields:
>>
>> {g[1],g[4],g[9]}
>>
>> (it looks nicer in a notebook)
> 
> ...  sorry for flooding the group, but got it even nicer:
> 
> RightVector[a_, first_, rest___] := If[rest === Null, first /@ a,
> RightVector[first /@ a, rest]]
> 
> Robert

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


#8984

Fromroby <roby.nowak@gmail.com>
Date2012-03-13 08:01 +0000
Message-ID<jjmus6$cd9$1@smc.vnet.net>
In reply to#8855
> An unfortunate choice of notation, \[Del], for that operator. After all
> \[Del] is a universal notation for grad, the gradient operator.

Yes, you are right of course, but  \[Del] beside \[PlusMinus] and \
[MinusPlus] are the only prefix operators without predefined meaning/
function in Mathematica.
Every other prefix operator would need Unprotect[ ].

Robert

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


#8918

From"branton.campbell" <branton.campbell@gmail.com>
Date2012-03-08 09:38 +0000
Message-ID<jj9unb$drr$1@smc.vnet.net>
In reply to#8845
> In the functional programming spirit I am missing a postfix notation
> for Map[ ].

I have wanted just such an operation for years.  Excellent suggestion.

[toc] | [prev] | [standalone]


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


csiph-web