Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: What is happening here?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22166] Re: What is happening here?
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 17 Feb 2000 01:23:55 -0500 (EST)
  • References: <888ad7$c7d@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Jordan,

With

vLarge = {1, 2};
authornames = {"PA", "HW"};

We get the contrast

    Through[Hold[f["PA"], f["HW"]][vLarge]](*1*)

        Hold[f["PA"][{1, 2}], f["HW"][{1, 2}]]

    Through[FullForm[Hold @@ (f /@ authornames)][vLarge]](*2*)

        Hold[f["PA"], f["HW"]][List[1, 2]]

The difference arrises from the behaviour of the "wrapper" FullForm.
The evaluation of (*2*) proceeds as follows


    Through[FullForm[Hold @@ (f /@ authornames)][vLarge]]

    Through[FullForm[Hold @@ (f /@ {"PA", "HW"})][vLarge]];

    Through[FullForm[Hold @@ ({f["PA"], f["HW"]})][vLarge]]

    Through[FullForm[Hold[f["PA"], f["HW"]]][vLarge]]         (*3*)

    FullForm[Hold[f["PA"], f["HW"]]][vLarge]

    FullForm[Hold[f["PA"], f["HW"]][{1, 2}]]

    Hold[f["PA"], f["HW"]][List[1, 2]]

We can see the how the last expression displays

    FullForm[Hold[f["PA"], f["HW"]][{1, 2}]]

           Hold[f["PA"], f["HW"]][List[1, 2]]

The crucial point is the presence of the FullForm in (*3*) when Through is
evaluated.


Some notes about wrappers:

FullForm  is a "wrapper" ($OutputForms gives the list of them) and whenever
Wrapper[expr] is sent for display and for storing as a value of Out[n] for
some n, then Wrapper[expr] is displayed but *expr* is stored as the value of
Out[n], thus:

    %

        Hold[f["PA"], f["HW"]][{1, 2}]

This stripping off of the wrappers only occrurs at this final stage and is
only done then for wrappers that are not inside non-wrappers

    A[FullForm[a^2]]

        A[Power[a, 2]]

    %

        A[Power[a, 2]]

These difficulties often crop up with MatrixForm -compare

    {{a}, {b}} + FullForm[{{c}, {d}}]

    {{a}, {b}} + MatrixForm[{{c}, {d}}]


"Jordan Rosenthal" <jr at ece.gatech.edu> wrote in message
news:888ad7$c7d at smc.vnet.net...
> Hi all,
>
> I finally had a chance to try and compare all the different methods people
> sent me for computing the matrix
>
>   ( 1 0 0 )
>   ( 2 1 0 )
>   ( 3 2 1 )
>   ( 0 3 2 )
>   ( 0 0 3 )
>
> from the vector {1,2,3} (using much larger vectors).  I am running into a
> strange problem that I can't explain.
>
> I started by creating a function for each contributer.  Here is an example
> for two of the defintions (picked arbitrarily for this example because
they
> were first and last in the alphabet):
>
> -------------------------------------------------------
> f["Paul Abbot"][v_?VectorQ] := Module[
> {n = Length[v]},
> NestList[RotateRight,
> Reverse[PadRight[PadLeft[v, 2n - 1], 3n - 2]], 2n - 2][[All,
>         Range[2n - 1, 3n - 2]]]
> ]
>
> f["Hartmut Wolf"][v_?VectorQ] := With[{r = Length[v] - 1},
> Transpose[NestList[RotateRight, Join[v, Table[0, {r}]], r]]]
> -------------------------------------------------------
>
> Running the following code (based on a suggestion from Hartmut Wolf) works
> great:
>
> -------------------------------------------------------
> vLarge = Range[400];
>
> List @@ (Part[#, 1, 1] &) /@
>     Timing /@ Through[ Hold[f["Paul Abbot"], f["Hartmut Wolf"]][vLarge]]
>
>    {0.49 Null, 0.27 Null}
> -------------------------------------------------------
>
> This works great; it gives me a list of timings for the two methods.  But
> because I have a large list I wanted to instead run code like this (where
> authornames would be a larger vector):
>
> -------------------------------------------------------
> authornames = {"Paul Abbot", "Hartmut Wolf"};
>
> List @@ (Part[#, 1, 1] &) /@
>     Timing /@ Through[ FullForm[Hold @@ (f /@ authornames)][vLarge]]
>
>    {0. Null}
> -------------------------------------------------------
>
> but this doesn't work the same way.  So I tried to compare the difference
> between the two versions by checking the difference between the code I
> replaced and my code.  Shown below, the two expressions have the same
> FullForms and Attributes:
>
> -------------------------------------------------------
> expr1 = Hold[ f["Paul Abbot"], f["Hartmut Wolf"] ];
> expr2 = Hold @@ (f /@ authornames);
>
> FullForm[expr1]==FullForm[expr2]
>     True
>
> Attributes[expr1]==Attributes[expr2]
>    True
>
> expr1 == expr2
>     True
> -------------------------------------------------------
>
> If the two expression have the same FullForm and Attributes, why do I not
> get the same results if I substitute one for the other?
>
>
> Humbly perplexed,
>
> Jordan
>
>
>
>
>



  • Prev by Date: Re: solving third order equation: bad result
  • Next by Date: Re: sum of recursive fn: solving for n
  • Previous by thread: Re: What is happening here?
  • Next by thread: Re: ASCII ... plus new stuff