3
$\begingroup$

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

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

1 Answer 1

10
$\begingroup$

You can view the code for PowersRepresentations using

Needs["GeneralUtilities`"]; 
PrintDefinitions @PowersRepresentations
$\endgroup$
5
  • $\begingroup$ Can one view codes this way for any function? $\endgroup$ 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
    Dec 4, 2016 at 21:50
  • $\begingroup$ @kglr That's because closed-source software hates its users :) $\endgroup$
    – cat
    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
    Oct 19, 2017 at 11:59
  • $\begingroup$ @yode, interesting. $\endgroup$
    – kglr
    Oct 19, 2017 at 12:06

Your Answer

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

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