There is an interesting (and documented) number-theoretic function in MMA called PowersRepresentations[$n$, $k$, $p$].

It gives the distinct representations of the integer $n$ as a sum of $k$ non-negative $p$-th integer powers.

I recently heard about related undocumented function SumOfSquaresReps.

How can I find out more on that undocumented function (number of arguments etc.)? What does it do exactly? How does it relate to PowersRepresentations, esp. performance-wise? Is there SumOfCubesReps, etc.?

The only place on the Internet known to me where this function is mentioned and used is @kglr answer to a question on this site.


How does Mathematica compute how to write integers as the sum of k non-negative pth integer powers so quickly?

  • 5
    $\begingroup$ "number of arguments etc." - as you can surmise from kglr's answer, it takes two arguments: Reduce`SumOfSquaresReps[k, n] returns all possible lists of k positive integers whose squares sum to n. $\endgroup$ – J. M.'s technical difficulties Aug 30 '15 at 15:51
  • 4
    $\begingroup$ The function is implemented in top-level code, so if you are interested you can look at its implementation using Spelunk[Reduce`SumOfSquaresReps] (you need "spelunking tools" for this, see this post to get them). $\endgroup$ – MarcoB Aug 30 '15 at 18:19
  • $\begingroup$ Vivid, could you explain what you would like to see in an answer? As I mentioned the first time you asked the question, you can access the actual implementation code for SumOfSquaresReps: ClearAttributes[Reduce`SumOfSquaresReps, ReadProtected];??Reduce`SumOfSquaresReps. What would be more credible and official than the code itself? $\endgroup$ – MarcoB Oct 16 '17 at 4:33
  • $\begingroup$ @MarkoB I would like to see everything that I mentioned in the question: implementation details (if possible), perf comparison SumOfSquaresReps vs PowersRepresentations, details on other related undocumented and documented functions, etc... An overview of general methods for exploring internals of built-in functions would definitely not hurt. Thanks for interest and info so far! $\endgroup$ – VividD Oct 16 '17 at 11:36

Your Answer

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

Browse other questions tagged or ask your own question.