"PowersRepresentations[n,k,p] gives the distinct representations of the integer n as a sum of k non-negative p-th integer powers"

Documentation: PowersRepresentations

How does Mathematica do this computation so quickly? Is there a fast algorithm? What is it?

I am particularly interested in the case where $n$ is the sum of $k$ squares of positive integers.

  • $\begingroup$ There is a little man inside the computer who is good at sums $\endgroup$
    – wolfies
    Commented Dec 5, 2016 at 4:43

1 Answer 1


You can view the code for PowersRepresentations using

PrintDefinitions @PowersRepresentations
  • $\begingroup$ Can one view codes this way for any function? $\endgroup$ Commented Dec 4, 2016 at 20:46
  • 3
    $\begingroup$ @Mirko, unfortunately, 'PrintDefinitions' does not give the code for Kernel functions; it just returns '<Kernel Function>'. $\endgroup$
    – kglr
    Commented Dec 4, 2016 at 21:50
  • $\begingroup$ @kglr That's because closed-source software hates its users :) $\endgroup$
    – cat
    Commented Dec 4, 2016 at 22:04
  • $\begingroup$ @kglr You will find any function is kernel function when you arive v11.2. Even this :) $\endgroup$
    – yode
    Commented Oct 19, 2017 at 11:59
  • $\begingroup$ @yode, interesting. $\endgroup$
    – kglr
    Commented Oct 19, 2017 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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