0
$\begingroup$

Given a positive integer $n$, what is the code to list $2^{a_2}3^{a_3}\cdots p^{a_p}$, where $a_i\ge 0$ are integers, with respect to the lexicographic ordering on $(a_2,a_3,\ldots, a_p)$?

The only idea that comes to mind is

Product[Prime[p]^(a_p), {p,1,PrimePi[n]}]

I know that the $a_p$ in the parenthesis is incorrect, but I am not sure what to put there and how to index the exponents since the Product code only allows one index (in my case, $p$).

$\endgroup$
  • $\begingroup$ Does Times @@ (Prime /@ Range[n]^Array[a, n]) work for you? $\endgroup$ – aardvark2012 Oct 6 '17 at 10:52
  • $\begingroup$ What do you mean by "with respect to the lexicographic ordering" on the powers? The term "lexicographic ordering" makes sense only when comparing two elements of the product of sets (in the strictly set-theoretic sense). Do you perhaps really mean simply that the powers of primes should be arranged in the order of the exponents rather than in the order of the primes? $\endgroup$ – murray Nov 6 '17 at 15:36
2
$\begingroup$

It's unclear in your question how $n$ relates to what you want. If you are trying to express the prime-power factorization of a given integer $n \geq 2$, then the built-in function FactorInteger does most of the work, e.g.:

    n = 39510856;
    FactorInteger[n]
(* {{2, 3}, {7, 4}, {11, 2}, {17, 1}} *)

If that's the essence of what you want, but you want an explicit product of prime powers expression, the following will do it:

    pPower[{p_, a_}] := HoldForm[p^a]
    Times @@ pPower /@ FactorInteger[n]

The output will look like: $2^3\, 7^4\, 11^2\, 17^1$. (I don't know how to use markup to make that expression appear within the indented code block above!)

$\endgroup$
1
$\begingroup$

Use Subscript. For instance with n = 5:

Product[Prime[p]^(Subscript[a, p]), {p, 1, PrimePi[5]}]
$\endgroup$
  • $\begingroup$ Is there a way to place bounds on $a_p$ in your code? $\endgroup$ – The Substitute Oct 6 '17 at 10:58
  • $\begingroup$ Note sure what you mean by that. You want to set the min and max value of ap ? Can you give an example ? $\endgroup$ – Lotus Oct 6 '17 at 11:05
1
$\begingroup$

From the Applications section of FactorInteger

n = 39510856;

CenterDot @@ (Superscript @@@ FactorInteger[n])

enter image description here

(% /. {Superscript -> Power, CenterDot -> Times}) == n

(* True *)
$\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.