MathGroup Archive 1999

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

Search the Archive

Evaluation of args in pure functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16924] Evaluation of args in pure functions
  • From: Andrea Sosso <sosso at dns.ien.it>
  • Date: Thu, 8 Apr 1999 02:32:34 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Hello Group:

	Mathematica seems to evaluate arguments in a different way, when
applying pure functions rather than using the usual function form:

	Here is and example:
	
	>>> a)  Usual form 

		In[1]:=Unevaluated[ Simplify[1 + 2 x + x^2] ]
		                                        2
		Out[5]=Unevaluated[ Simplify[1 + 2 x + x ]]
	
	>>> b)  Pure function @
 
		In[2]:=Unevaluated[#]& @ Simplify[1 + 2 x + x^2] 
					  2
		Out[2]=Unevaluated[(1 + x) ]


The trace confirms evaluation order is different in these two cases:

	>>> A)  Usual form 

		In[3]:=Trace[ Unevaluated[ Simplify[1 + 2 x + x^2] ]	
			                    2          2
		Out[3]={Simplify[1 + 2 x + x ], (1 + x) }
	
	>>> B)  Pure function @
 
		In[4]:=Unevaluated[#]& @ Simplify[1 + 2 x + x^2] 

		Out[4]={{#1 & , Unevaluated[#1] & }, 
                        		      2          2
 			 {Simplify[1 + 2 x + x ], (1 + x) }, 
 		        	                      2                      
			  (Unevaluated[#1] & )[(1 + x) ], 
							   2
					Unevaluated[(1 + x) ]}


Why ?
 And how to control evaluation in pure functions ?

Thanks to anyone giving help.


-- 

 Andrea Sosso
 

 Istituto Elettrotecnico Nazionale "Galileo Ferraris"
 Settore Metrologia Elettrica
 Strada delle Cacce, 91
 10135 TORINO  
 
 Phone: +39 11 3919436  
 Fax: +39 11 3919436 / 346384 
 ----------------------------
 E-mail:sosso at me.ien.it 
	sand at cstv.to.cnr.it


  • Prev by Date: Re: Re: binomial distribution
  • Next by Date: overwrite separate notebook
  • Previous by thread: Mie Scattering w/Mathematica
  • Next by thread: Re: Evaluation of args in pure functions