MathGroup Archive 1999

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

Search the Archive

Re: Re: Is it a bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17699] Re: [mg17640] Re: Is it a bug?
  • From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
  • Date: Fri, 21 May 1999 23:59:09 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

The explanation given in the online help is indeed misleading. Cases only 
finds certain patterns, it does not do any mathematics! Thus as you already
know Cases[...,_Integer] looks for expressions having the Head Integer, and
does not perform any but the most rivial simplifications. This can be very
useful for programming purposes. Cases is really a programming function not
a mathematical one. If you really want a function which works like Cases but
performs more than the most trivial mathematical simplifications you can
easily write it yourself (in my opinion that is really the main point of
using Mathematica):

In[10]:=
mycases[expr_,x_]:=Cases[Simplify[expr],x]

Now you've got the behaviour you wanted:

In[11]:=
mycases[{Sqrt[I]-1/Sqrt[2](1+I)},_Integer]
Out[11]=
{0}


--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp


----------
>From: "F. Mittermayr" <mitterma at linz.vai.co.at>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg17699] [mg17640] Re: Is it a bug?
>Date: Fri, May 21, 1999, 4:37 PM
>

> 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 ??
>
> Regards
> Franz Mittermayr
>
>
> F. Mittermayr wrote in message <37393190.0 at webpc1.vai.co.at>...
>>A = {1 + Sqrt[2] I , 1 + 2 * 3 I};
>>Cases[A, _Complex]
>>
>>Out[1] = {1+6 I}
>>
>>Isn't it a strange result?
>>
>>
>>
>>
>
> 


  • Prev by Date: special characters in EPS graphics
  • Next by Date: Re: Version 4 out and NO reaction?
  • Previous by thread: Re: Re: Is it a bug?
  • Next by thread: Re: Is it a bug?