Re: Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]

• To: mathgroup at smc.vnet.net
• Subject: [mg58766] Re: [mg58751] Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]
• From: "David Park" <djmp at earthlink.net>
• Date: Sun, 17 Jul 2005 13:03:12 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Hu Zhe,

That is a problem with the Through command. It pushes the arguments onto
everything at the top level and only the top level. It is not a very useful
command as it stands.

At my web site there is a package called Algebra`PushThrough` that allows
better control of how arguments are pushed onto a head expression.

Needs["Algebra`PushThrough`"]

mylist = Table[Random[Integer, {1, 100}], {5}]
{9, 72, 68, 51, 61}

The routine PushThrough does not push onto numbers or Mathematica constants
and there are other elements of control that can be specified.

(Max - Min)[mylist]
% // PushThrough[]
(Max - Min)[{9, 72, 68, 51, 61}]
63

As an alternative, the package routine PushOnto allows the user to specify
the forms that the arguments will be pushed onto.

(Max - Min)[mylist]
% // PushOnto[{Max, Min}]
(Max - Min)[{9, 72, 68, 51, 61}]
63

The package also has the routines: LinearPushOut, PushOut, PushDerivative.

PushOnto is also built into the Tensorial tensor calculus package.

David Park

From: Zhe Hu [mailto:iamhuzhe at gmail.com]
To: mathgroup at smc.vnet.net

I tried to get the difference between the largest and the smallest
elements in a list.

Max[mylist] - Min[mylist]  OR (Max[#]-Min[#])&[mylist]  would get the job
done.

However just to be fancy, I tried

Through[Max - Min, mylist] .

It didn't work as expected. Try

Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]

I guess the problem is "Max - Min" was turned into "Max + (-Min)" and
"(-Min)" won't be applied correctly.

One way to go around this problem is to try

Subtract@@Through[{Max, Min}[{1, 2, 3, 4, 5}]]

But that's kind of ugly. Is there better solutions? Thanks.

Sincerely,
Hu Zhe

P.S.
In a language called "J". This is termed "fork". Their expression would be:
(>./ - <./) 1 2 3 4 5

```

• Prev by Date: Re: Sudoku puzzle
• Next by Date: Re: Notebook Style problems?
• Previous by thread: Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]
• Next by thread: Re: Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]