MathGroup Archive 2013

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

Search the Archive

Re: Extract Integers


Since Rational[] is an Atom (AtomQ[2/3] returns True), Cases[] does not descent into it. You can use this:

Cases[Cases[equ, v_?NumericQ, Infinity] /. Rational[e1_, e2_] -> Sequence[e1, e2], _Integer]

Depending on your problem, you might want to treat Complex[] the same way.

> 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
> 
>



  • Prev by Date: Re: Extract Integers
  • Next by Date: Re: Extract Integers
  • Previous by thread: Re: Extract Integers
  • Next by thread: Re: Extract Integers