0
$\begingroup$

Please help me use Cases,Except on list data. I just want to remove all primes, or equivocally to see only the values in the list produced that aren't prime. the prime factorization of those values are what I want to know, but I can't seem to figure that out either. Maybe I'm going about this wrong. I have an expression I'm putting in like so:

PrimeFactorization desired of...Cases[(expression here),Except[any primes???]]

I know, I'm retarded at this.

$\endgroup$
  • 3
    $\begingroup$ It would be helpful if you give a sample small input, and indicate the desired output. From the description, I'tt guess you want something like Map[FactorInteger,DeleteCases[list,_?PrimeQ]] where list is your input data. $\endgroup$ – Daniel Lichtblau Jan 30 '15 at 2:42
  • $\begingroup$ If our list (set?) for instance was {5,7,11,13,15,21} only 15 and 21 aren't prime. Also! I would want it separately consider every other prime beginning from and including the 1st and 2nd elements separately (or in other words the even and odd ordered terms in the set, such as 1st, 3rd, 5th etc. separately from 2nd, 4th, 6th etc.) That means it would be running calculations in this case on 5,11,15 for odd output and 7,13,21 for even output. However it will only print nonprimes, and their respective prime factorization. so output would look like: Odd=15(1,3,5),others.. Even=21(1,3,7),others.. $\endgroup$ – Travis Arlen McCracken Jan 30 '15 at 12:08
1
$\begingroup$

I am uncertain as to what the aim is here but post this for motivation. Divisors may not be the intended aim but this could be modified to whatever is intended and partition would need to be modified in list is not even in length.

f[x_?PrimeQ] := Sequence[];
f[x_] := Most@Divisors[x]
fun[lt_] := 
 MapIndexed[(#2[[1]] /. {1 -> "odd", 2 -> "even"}) -> (f /@ #1) &, 
  Transpose[Partition[lt, 2]]]

then

lst = {5, 7, 11, 13, 15, 21};
fun[lt]

yields:

(*{"odd" -> {{1, 3, 5}}, "even" -> {{1, 3, 7}}}*)
$\endgroup$
1
$\begingroup$

If you would just like the primes then I would suggest Select rather than Cases as you're only specifying a condition:

nList = RandomInteger[10000, 1000];
notPrime = Select[nList, ! PrimeQ[#] &]

Then you can take advantage of FactorInteger being listable

Attributes[FactorInteger]
(*{Listable, Protected}*)

As follows:

FactorInteger[notPrime]
(*{{{2, 1}, {1867, 1}}, {{2, 1}, {3, 4}, {13, 1}}, {{2, 3}, {7, 
 1}, {103, 1}}, {{2, 1}, {5, 1}, {443, 1}}, {{2, 3}, {11, 1}, {31, 
 1}}, {{7, 1}, {311, 1}}, {{37, 2}}, {{2, 2}, {11, 1}, {227, 
 1}}, {{2, 3}, {3, 1}, {7, 1}, {17, 1}}, {{2, 1}, {13, 1}, {61, 
 1}}, {{7, 1}, {499, 1}}, {{17, 1}, {167, 1}}, {{5, 1}, {7, 
 1}, {191, 1}}, {{3, 1}, {11, 1}, {83, 1}}, {{2, 2}, {11, 1}, {103, 
 1}}, {{2, 2}, {3, 4}, {19, 1}}}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.