Re: Re: Is it a bug?
- To: mathgroup at smc.vnet.net
- Subject: [mg17696] Re: [mg17640] Re: Is it a bug?
- From: BobHanlon at aol.com
- Date: Fri, 21 May 1999 23:59:08 -0400
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 5/21/99 3:12:07 PM, mitterma at linz.vai.co.at writes: >Thanks to all who have told me that it is not a strange result. > >But now look at the online-help under "Cases - Further Examples". You can >find the following lines: > >This finds all elements in the list that are integers. >Cases[{.....}, _Integer] > >And now we test it: > > x = Sqrt[I]-1/Sqrt[2](1+I); > Cases[{x, x//FullSimplify},_Integer] >Out[]= {0} > >It cannot be that a number becomes an integer by doing a "FullSimplify". >Shouldn't the text in the online-help be changed to the following: > >This finds s o m e elements in the list that are integers and when you >are >in doubt look at the FullForm!! > >The statement "Cases[{...},_Integer]" is quite useless because often I >want >to know if elements are integers but seldom I want to know if the FullForm >of an element is integer. > >Why doesn't Mathematica do any calculation on the expression x = >Sqrt[I]-1/Sqrt[2](1+I); ?? >If you have Cases[ { I I }, _Integer ] the expression is calculated to >-1. >Is the expression to complicated ?? > Franz, I agree that the wording in the on-line help is wrong; however, I believe that the text in the on-line help should read: "This finds all elements in the list whose head is Integer." If you look in the on-line help under Blank, it states "_h or Blank[h] can stand for any expression with head h. " Blank makes no claims as to what the expression is, but rather what its head is. Using FullSimplify does not change whether your expression is an integer, but it changes the form of the expression and the resulting form has a different head. To always do what you want without any intervention on your part would require very liberal automatic use of FullSimplify within Mathematica. As you are undoubtedly aware, sitting through a FullSimplify can be very painful--and you don't know how painful until it has completed. I prefer to judge when use of FullSimplify is reasonable, rather than have Mathematica constantly looking for the simplest possible form. As processors continue to become more powerful, the amount of simplification that Mathematica does automatically without explicit calls to Simplify or FullSimplify should probably increase. However, there will always be some limit on what is tolerable considering the impact on overall performance. If you want to use FullSimplify with Cases you could use either Cases[x, _?(Head[FullSimplify[#]] == Integer&)] or Cases[x, _?(Head[y=FullSimplify[#]] == Integer&)->y] depending on whether you want to retain the original forms or just return the integer values. Bob Hanlon