Search All of the Math Forum:

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

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

 w.meeussen.vdmcc@vandemoortele.be Posts: 69 Registered: 12/4/04
[mg5217] Re: [mg5161] Programming: Replace Heads
Posted: Nov 18, 1996 2:03 AM

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 -

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[
Timing[

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
Tel: +/32/51/33 21 11
Fax:+32/51/33 21 75
vdmcc@vandemoortele.be