Re: Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]
- To: mathgroup at smc.vnet.net
- Subject: [mg58792] Re: Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]
- From: dh <dh at metrohm.ch>
- Date: Tue, 19 Jul 2005 04:10:02 -0400 (EDT)
- References: <dbd0rd$2r7$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Zhe, the manual says: Through[p[f1,f2][x]] gives p[f1[x], f2[x]] Using (Max - Min) // FullForm you can convince yourselve that in your case: p= Plus f1= Max f2= Times[-1,Min] the problem is the form of f2. This is not the Head of any defined function. Therefore, f2[x] will not match any defined pattern and not be evaluated. For my taste, you should stick to the simple and traight forward solutions you proposed yourselve. sincerely, Daniel Zhe Hu wrote: > 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 >