Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: [mg5161] Programming: Replace Heads
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
w.meeussen.vdmcc@vandemoortele.be

Posts: 69
Registered: 12/4/04
Re: [mg5161] Programming: Replace Heads
Posted: Nov 9, 1996 2:03 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

At 01:34 06.11.96 -0500, you wrote:
>I'm delited 2 have the opportunity 2 post another interesting prograMing
>problem.
>
>Problem:
>Given an abritrary expression, how to replace all heads to List?
>
>my solution:
>Map[ {(Sequence@@#)}&, expr, {0,-2}]
>
>Example:
>
>Clear[a,b,c,d,e,f,g]
>
>f := ({a,b,c,d,e,g}[[Random[Integer, {1,6}] ]])
>
>Array[ Hold@f, {3,2,3},1, Hold@f]//ReleaseHold
>
>Map[ {(Sequence@@#)}&, %, {0,-2}]
>
>Post your solutions. Please cc to me 2. I will write up a summary of
>solutions of PrograMMing Competition of last month.
>
> Xah
> xah@best.com; 74631.731@compuserve.com
> http://www.best.com/~xah/SpecialPlaneCurves_dir/specialPlaneCurves.html
> Mountain View, CA, USA
>

*****************************************************
Elementary, my dear Watson ...
(C. Doyle, "The Case of the bearded Smiley")
(;-)#

List@@Apply[List,Xah,-1]
- or -
List@@Apply[List,Xah,-2]
do it too!

- but -

Apply[List,Xah,0,Heads->True] doesn't,
while The Book pg 725 (A.3.6 Level Specifications) says it should ?!

compare :
Xah=Array[ Hold@g,{3,4,5,6},0,Hold@g]//ReleaseHold
Map[ {(Sequence@@#)}&, Xah, {0,-2}]
List@@Apply[List,Xah,-2]

or make it nice & big :
In[...]:=
Table[ {
test=Array[ Hold@g,{2,3,4,5,4,3,2},1,Hold@g]//ReleaseHold;
Timing[
t1=Map[ {(Sequence@@#)}&, test, {0,-2}];
] ,
Timing[
t2=List@@Apply[List,test,-1];
] , t1==t2
} ,{counter,20}]

Out[...]=
{{{1.072 Second, Null}, {0.14 Second, Null}, True},
{{1.092 Second, Null}, {0.14 Second, Null}, True},
{{1.092 Second, Null}, {0.15 Second, Null}, True},
{{1.092 Second, Null}, {0.15 Second, Null}, True},
{{1.082 Second, Null}, {0.15 Second, Null}, True},
{{1.092 Second, Null}, {0.14 Second, Null}, True},
{{1.112 Second, Null}, {0.14 Second, Null}, True},
{{1.082 Second, Null}, {0.15 Second, Null}, True},
{{1.102 Second, Null}, {0.15 Second, Null}, True},
{{1.092 Second, Null}, {0.15 Second, Null}, True},
{{1.092 Second, Null}, {0.15 Second, Null}, True},
{{1.082 Second, Null}, {0.14 Second, Null}, True},
{{1.092 Second, Null}, {0.14 Second, Null}, True},
{{1.092 Second, Null}, {0.14 Second, Null}, True},
{{1.092 Second, Null}, {0.14 Second, Null}, True},
{{1.082 Second, Null}, {0.15 Second, Null}, True},
{{1.082 Second, Null}, {0.15 Second, Null}, True},
{{1.082 Second, Null}, {0.15 Second, Null}, True},
{{1.092 Second, Null}, {0.14 Second, Null}, True},
{{1.092 Second, Null}, {0.14 Second, Null}, True}}

Question :
Why is 'Sequence' undocumented in Mma 2.2.3 ?
the Wolframians must have had their reasons, but ...


Wouter.
NV Vandemoortele Coordination Center
Group R&D Center
Prins Albertlaan 79
Postbus 40
B-8870 Izegem
(Belgium)
Tel: +/32/51/33 21 11
Fax:+32/51/33 21 75
vdmcc@vandemoortele.be








Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.