13
S. Ryley proved following theorem in 1825:
Every rational number can be expressed as a sum of three rational cubes.
Challenge
Given some rational number \$r \in \mathbb Q \$ find three rational numbers \$a,b,c \in \mathbb Q\$ such that $$r= a^3+b^3+c^3.$$
Details
Your submission should be able to compute a solution for every input given enough time and memory, that means having for instance two 32-bit int
representing a fraction is not sufficient.
Examples
$$ \begin{align} 30 &= 3982933876681^3 - 636600549515^3 - 3977505554546^3 \\ 52 &= 60702901317^3 + 23961292454^3 - 61922712865^3 \\ \frac{307}{1728} &= \left(\frac12\right)^3 + \left(\frac13\right)^3 + \left(\frac14\right)^3 \\ 0 &= 0^3 + 0^3 + 0^3 \\ 1 &= \left(\frac12\right)^3 + \left(\frac23\right)^3 + \left(\frac56\right)^3\\ 42 &= \left(\frac{1810423}{509232}\right)^3 + \left(\frac{-14952}{10609}\right)^3 + \left(\frac{-2545}{4944}\right)^3 \end{align}$$
1I had something that kind-of worked in Japt, but it often ran into a "too much recursion" error. Probably because the strategy was "get random numbers, try again until they're a correct answer". – Kamil Drakari – 2018-11-04T02:54:40.863
1Requiring bignum support unnecessarily excludes a lot of languages, and/or requires a lot of wasted boilerplate to implement them – Sparr – 2018-11-04T05:54:53.760
2@Sparr This was a deliberate choice, as the output could be quite "large" even for simple inputs, or depending on what method you use, the intermediate values in the calculation could also be very large. So working with arbitrary precision numbers was an important point for this challenge (and probably quite often in other [tag:number-theory]-challenges too). – flawr – 2018-11-04T09:12:12.403
1Would it be acceptable to output
[p1,p2,p3,q]
, interpreted as $\left(\frac{p_1}{q}\right)^3+\left(\frac{p_2}{q}\right)^3+\left(\frac{p_3}{q}\right)^3$? – Arnauld – 2018-11-04T13:58:15.950Along a similar vein, do the three rational numbers outputted have to be in simplest form? – Quintec – 2018-11-04T14:36:23.273
@Quintec No, they don't have to be reduced. – flawr – 2018-11-04T22:07:46.607
@Arnauld I think if there is not a fractional type, one should at least use pairs (or lists of length 2) or something along those lines to represent a fraction, but you're making a good point, I did not specify that. (Or do you have another suggestion?) – flawr – 2018-11-04T22:09:58.600
Using pairs sounds like a reasonable option to me. (This is what I'm currently doing in my answer.) – Arnauld – 2018-11-04T22:22:45.617