Re: Symbol and Pi and expressions evaluating to Pi
- To: mathgroup at smc.vnet.net
- Subject: [mg70131] Re: Symbol and Pi and expressions evaluating to Pi
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Thu, 5 Oct 2006 03:32:22 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <eg0286$818$1@smc.vnet.net>
David Bakin wrote: > [I apologize if this question has been asked - as it surely must have > been already - my searches didn't get me to the answer in the > archives. You can send me some better search terms and I'll be happy > with that as an answer, thanks!] > > The Mathematica 5.1 help browser entry for Symbol under "Further Examples" > defines a function SymbolQ1 to determine if something is a Symbol as > follows: > > Attributes[SymbolQ1] = {HoldAllComplete}; > SymbolQ1[expr_] := AtomQ@Unevaluated[expr] && Head@Unevaluated[expr]===Symbol ---------------------------^^^^^^^^^^^---------------^^^^^^^^^^^ Hi David, In the above definition, you will notice the call to the Unevaluated function before the call to AtomQ or Head. This prevent both function to evaluate their arguments before testing for atomicity or extracting their heads. > Then it shows the following: > > In:= SymbolQ[Pi] > Out= True > In:= {a definite integral evaluating to Pi} == Pi > Out= True > In:= SymbolQ[that definite integral] > Out= False > > Yet FullForm[Pi] is the same as FullForm[that definite integral], and is Pi. Correct, but this is only because FullForm does not prevent the evaluation of its argument. Compare, FullForm[Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2] --> Pi vs FullForm[Unevaluated[Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2]] --> Unevaluated[Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2] > So I have two questions: > 1) Why isn't SymbolQ[that definite integral] == True? What is it if > it isn't a Symbol? Head[Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2] --> Symbol Head[Unevaluated[Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2]] --> Power > 2) Why are FullForm[Pi] and FullForm[that definite integral] different? Now you have the answer: without the call to the function Unevaluated, they are equal Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2 == Pi --> True FullForm[Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2] == FullForm[Pi] --> True FullForm[Integrate[E^(-x^2), {x, -Infinity, Infinity}]^2] --> Pi FullForm[Pi] --> Pi HTH, Jean-Marc