Comments on: POW 1UP
http://ask.metafilter.com/149596/POW-1UP/
Comments on Ask MetaFilter post POW 1UPSat, 27 Mar 2010 05:25:18 -0800Sat, 27 Mar 2010 05:25:18 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: POW 1UP
http://ask.metafilter.com/149596/POW-1UP
Is there a closed-form method for finding the unique subsets from the power set of prime factors of an integer? <br /><br /> Let's say I start with the integer 28, with prime factors {2, 2, 7}.<br>
<br>
If I construct a power set from this set of factors, I get:<br>
<br>
{{nil}, {2}, {2}, {7}, {2,2}, {2,7}, {2, 7}, {2, 2, 7}}<br>
<br>
I can reduce this to a set of divisors by multiplying the elements inside the non-empty subsets, to get {2, 7, 4, 14, 28} (adding {1} as a default divisor).<br>
<br>
However, two of the subsets are duplicates: {2} and {2,7}, so I am doing unnecessary calculations by simply iterating through all subsets. <br>
<br>
I could loop through the subsets and keep a hash table of multiplied elements-as-keys or some similar brute force approach. But as a power set grows quickly, there could be a very large number of subsets. <br>
<br>
Is there a smarter, more general way to do this, if I know what the labels (prime factors) are, something like a unique permutation of the factors, where some factors might be repeated?<br>
<br>
(Note: This isn't homework.)post:ask.metafilter.com,2010:site.149596Sat, 27 Mar 2010 05:19:21 -0800Blazecock PileonmathsetpowersetprimefactorfactorizationnumbernumbertheoryresolvedBy: madcaptenor
http://ask.metafilter.com/149596/POW-1UP#2142924
Let's say your number has the factorization p_1^(e_1) p_2^(e_2) ... p_m^(e_m), where the p_i are distinct primes. For example, 28 = 2^2 7^1.<br>
<br>
Then you want p_1^(f_1) ... p_m^(f_m) for each m-tuple (f_1, ..., f_m) where f_k is between 0 and e_k (inclusive).comment:ask.metafilter.com,2010:site.149596-2142924Sat, 27 Mar 2010 05:25:18 -0800madcaptenorBy: advil
http://ask.metafilter.com/149596/POW-1UP#2142931
<i>two of the subsets are duplicates: {2} and {2,7}, so I am doing unnecessary calculations by simply iterating through all subsets.</i><br>
<br>
If you are actually representing these using some kind of set data structure, duplicates should be removed for you automatically. By definition sets don't contain duplicates (e.g. {{0}, {0}} is the same set as {{0}}). However, if you are using a multiset, it won't do this for you. If you are rolling your own data structure, maybe the thing to do would be to see how a standard implementation of a set would do this. (Or just use one.)comment:ask.metafilter.com,2010:site.149596-2142931Sat, 27 Mar 2010 06:20:42 -0800advilBy: bsdfish
http://ask.metafilter.com/149596/POW-1UP#2143003
Exactly what madcaptenor said: write out all the unique prime factors and how often each one occurs. Then, every element of the factor power set can be written in terms of taking f_1 of the first factor, f_2 of the 2nd factor, etc...<br>
<br>
On that note, if there are factors p_1, p_2, ... p_m with counts e_1, e_2, ... , e_m, the number has (1+e_1) * (1+e_2) ... * (1+e_m) factors including 1 and itself.comment:ask.metafilter.com,2010:site.149596-2143003Sat, 27 Mar 2010 08:07:00 -0800bsdfishBy: DU
http://ask.metafilter.com/149596/POW-1UP#2143023
<i>(Note: This isn't homework.) </i><br>
<br>
I'm pretty sure it's <a href="http://projecteuler.net/">Euly</a>, though.<br>
<br>
Anyway, I agree with the above: Keep track of unique primes and the powers thereof.comment:ask.metafilter.com,2010:site.149596-2143023Sat, 27 Mar 2010 08:43:43 -0800DUBy: Blazecock Pileon
http://ask.metafilter.com/149596/POW-1UP#2143380
<em>If you are actually representing these using some kind of set data structure, duplicates should be removed for you automatically.</em><br>
<br>
That would be language or implementation dependent, and a kind of a cheat. My hope was to find a method for generating a power set that automatically removes duplicates, without relying on the vagaries of a particular language. But instead of using a power set, it seems better to just use an ordered tuple approach, once I have the factorization.comment:ask.metafilter.com,2010:site.149596-2143380Sat, 27 Mar 2010 16:48:59 -0800Blazecock PileonBy: albrecht
http://ask.metafilter.com/149596/POW-1UP#2143485
<em>Then you want p_1^(f_1) ... p_m^(f_m) for each m-tuple (f_1, ..., f_m) where f_k is between 0 and e_k (inclusive).</em><br>
<br>
Isn't that also just the list of factors?comment:ask.metafilter.com,2010:site.149596-2143485Sat, 27 Mar 2010 19:38:52 -0800albrechtBy: madcaptenor
http://ask.metafilter.com/149596/POW-1UP#2143786
albrecht, I thought the list of factors is what Blazecock was asking for.comment:ask.metafilter.com,2010:site.149596-2143786Sun, 28 Mar 2010 06:53:09 -0800madcaptenorBy: albrecht
http://ask.metafilter.com/149596/POW-1UP#2143805
Oh, sorry; I misunderstood the question. In that case, your answer is definitely the way to go.comment:ask.metafilter.com,2010:site.149596-2143805Sun, 28 Mar 2010 07:35:54 -0800albrechtBy: Blazecock Pileon
http://ask.metafilter.com/149596/POW-1UP#2145878
No, I have the factors. I was trying to build a count of divisors. Using a power set will introduce duplicates. So I just need to generate permutations of factors a different way.comment:ask.metafilter.com,2010:site.149596-2145878Tue, 30 Mar 2010 03:25:09 -0800Blazecock Pileon