Re: Extract Integers
- To: mathgroup at smc.vnet.net
 - Subject: [mg131434] Re: Extract Integers
 - From: Fred Simons <f.h.simons at tue.nl>
 - Date: Sun, 21 Jul 2013 21:43:57 -0400 (EDT)
 - Delivered-to: l-mathgroup@mail-archive0.wolfram.com
 - Delivered-to: l-mathgroup@wolfram.com
 - Delivered-to: mathgroup-outx@smc.vnet.net
 - Delivered-to: mathgroup-newsendx@smc.vnet.net
 - References: <20130721082357.762536A19@smc.vnet.net>
 
Hi Dana,
Despite the fact that rational numbers are atoms in Mathematica, pattern 
matching can be used:
In[9]:= Cases[equ, _Integer|_Rational, Infinity] /. 
Rational[a_,b_]->Sequence[a,b]
Out[9]= {1,1,2,2,1,6,3,1,24,4,1,120,5}
Regards,
Fred Simons
Eindhoven University of Technology
Op 21-07-13 10:23, Dana DeLouis schreef:
> Hi.  I've run out of ideas.  Does anyone know the proper way to extract all the integers from the following simplified version of a larger problem I'm working on?
>
> equ=Series[Exp[x],{x,0,5}] //Normal
>
> 1+x+x^2/2+x^3/6+x^4/24+x^5/120
>
> When trying to extract all the integers, I understand numbers like 120 are part of Rational[1,120]
>
> equ //FullForm
>
> << Not shown here >>
>
> I thought looking at all LevelSpec was the solution, but apparently not.
>
> Cases[equ, _Integer, Infinity]
> {1,2,3,4,5}
>
> (* Or *)
>
> Position[equ, _Integer, Infinity]
> {{1},{3,2,2},{4,2,2},{5,2,2},{6,2,2}}
>
> Extract[equ, %]
> {1,2,3,4,5}
>
> Both ways extract from the numerator, but I just can't seem to extract the {2,6,24,120} inside the denominator.
> Does anyone know the proper way?
> Thanks in advance.  :>~
>
> Dana
> Mac & Math 9
>
>
>
>
> -----
> Geen virus gevonden in dit bericht.
> Gecontroleerd door AVG - www.avg.com
> Versie: 2013.0.3349 / Virusdatabase: 3204/6507 - datum van uitgifte: 07/20/13
>
>
- References:
- Extract Integers
- From: Dana DeLouis <dana01@icloud.com>
 
 
 - Extract Integers