莱利定理


13

S. Ryley于1825年证明了该定理:

每个有理数可以表示为三个有理立方体的总和。

挑战

鉴于一些有理数rQ发现三个有理数a,b,cQ,使得

r=a3+b3+c3.

细节

给定足够的时间和内存,您的提交应该能够为每个输入计算一个解决方案,这意味着仅用两个32位int表示一个分数是不够的。

例子

30=3982933876681363660054951533977505554546352=607029013173+2396129245436192271286533071728=(12)3+(13)3+(14)30=03+03+031=(12)3+(23)3+(56)342=(1810423509232)3+(1495210609)3+(25454944)3


1
我在Japt中有过类似的工作,但是它经常遇到“太多递归”错误。可能是因为该策略是“获取随机数,然后重试直到获得正确答案”。
卡米尔·德拉卡里

1
需要bignum支持不必要地排除了许多语言,并且/或者需要大量浪费的样板实现它们
Sparr,

2
@Sparr这是一个刻意的选择,因为即使对于简单的输入,输出也可能“很大”,或者取决于您使用的方法,计算中的中间值也可能非常大。因此,使用任意精度的数字是应对这一挑战的重点(也许在其他数字理论中也常常面临挑战)。
瑕疵

1
将输出[p1,p2,p3,q]解释为(p1q)3+(p2q)3+(p3q)3
Arnauld

同样,输出的三个有理数是否必须采用最简单的形式?
Quintec,

Answers:


10

Pari / GP,40字节

r->[x=27*r^3+1,9*r-x,z=9*r-27*r^2]/(3-z)

在线尝试!


相同的长度,相同的公式:

r->d=9*r^2-3*r+1;[x=r+1/3,3*r/d-x,1/d-1]

在线尝试!


该公式在: Richmond,H.(1930)中给出。上的Rational解决方案x3+y3+z3=R爱丁堡数学学会会议论文集,2(2),92-100。

r=(27r3+127r29r+3)3+(27r3+9r127r29r+3)3+(27r2+9r27r29r+3)3

在线检查!


1
-5个字节,因为您可以更改加总的顺序
Black Owl Kai

1
@BlackOwlKai The numerator of the second summand is 27r3+9r1, not 27r2+9r1.
alephalpha

8

Haskell, 95 89 76 69 68 bytes

f x=[w|n<-[1..],w<-mapM(\_->[-n,1/n-n..n])"IOU",x==sum((^3)<$>w)]!!0

Try it online!

Simple bruteforce solution. It tests all triples of rational numbers of the form

(a1n,a2n,a3n)with nainn.

  • We can always assume that the three rational numbers have the same denominator, since
    (a1n1,a2n2,a3n3)=(a1n2n3n1n2n3,a2n1n3n1n2n3,a3n1n2n1n2n3).
  • We can always assume that nainn, since
    ain=aiNnN
    for any arbitrarily large integer N.

What does the "IOU" do?
Solomon Ucko

@SolomonUcko Nothing special, it's as good as any other list of length 3
Delfad0r

@H.PWiz I couldn't find any consensus on Meta on whether assuming typed input is accepted, but I still found a way to shorten the code without that assumption. Thanks!
Delfad0r

4
@Delfad0r There is a "consensus" that you do not have to count a possible import, that is only needed to construct the type needed, if you do not explicitly need anything from that import for defining your function. (And you can assume that the correct type is passed to your function, when it is called.)
flawr

1
Save one byte by using [-n,1/n-n..n]
Christian Sievers

6

Husk, 14 bytes

ḟo=⁰ṁ^3π3×/NİZ

Simple brute force solution. Try it online!

Explanation

Division in Husk uses rational numbers by default and Cartesian products work correctly for infinite lists, making this a very straightforward program.

ḟo=⁰ṁ^3π3×/NİZ
            İZ  Integers: [0,1,-1,2,-2,3,-3...
           N    Natural numbers: [1,2,3,4,5...
         ×/     Mix by division: [0,1,0,-1,1/2,0,2,-1/2,1/3...
                This list contains n/m for every integer n and natural m.
       π3       All triples: [[0,0,0],[0,0,1],[1,0,0]...
ḟ               Find the first one
    ṁ^3         whose sum of cubes
 o=⁰            equals the input.


2

Haskell, 70 bytes

In An introduction to the Theory of Numbers (by Hardy and Wright) there is an construction that even includes a rational parameter. For golfing purposes I just set this parameter to 1, and tried reducing as much as possible. This results in the formula

r[r3648r2+77760r+37324872(r+72)2,12(r72)r(r+72)2,r2720r+518472(r+72)]

f r|t<-r/72,c<-t+1,v<-24*t/c^3,a<-(v*t-1)*c=((a+v*c+c)/2-)<$>[a,v*c,c]

Try it online!


1

perl -Mbigrat -nE, 85 bytes

$_=eval;($a,$b)=($_*9,$_**2*27);$c=$b*$_;say for map$_/($b-$a+3),$c+1,-$c+$a-1,-$b+$a

You can save 8 bytes (the leading $_=eval;) if you know the input is an integer; this part is needed to have the program grok an input of the form 308/1728. Input is read from STDIN. I'm using the formula given by @alephalpha.

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.