CJam(59字节)
{[WZ~C24X8TT]f*[4XGYC6 4Y].+_0=!>2%Z65135Zb+:(3/.f#:.*)W*+}
这是一个匿名块(函数),它在堆栈上取一个整数或双精度数,并产生一个具有三个双精度数的数组。内部有两种情况可以处理所有非负输入,因为只有一种情况会在0.25
或时中断4
。输入仍然中断-12
和-1.3333333333333333
,但规范允许...
该在线演示执行它,然后添加了值,打印所有4个,将它们相乘,以表明它得到原始值(模舍入误差)。
数学背景
根据Noam Elkies,我们定义辅助。则x + y + z + w = 0且− x y z w = a或x y z w + a = 0。这具有很多对称性。任何解决方案都有四个公式,我们可以选择三个最复杂的公式。w=−x−y−zx+y+z+w=0−xyzw=axyzw+a=0
Elkies提供了四套解决方案。欧拉的:
xyzw====6ast3(at4−2s4)2(4at4+s4)(2a2t8+10as4t4−s8)3s5(4at4+s4)22t(at4−2s4)(2a2t8+10as4t4−s8)2(2a2t8+10as4t4−s8)3s3t(4at4+s4)−(2a2t8+10as4t4−s8)6s3t(at4−2s4)
One related to Euler's:
xyzw====(8s8+a2)(8s8−88as4−a2)12s3(s4−a)(8s8+20as4−a2)(8s8+a2)(8s8−88as4−a2)12s3(8s4+a)(8s8+20as4−a2)192as5(s4−a)2(8s4+a)2(8s8+a2)(8s8−88as4−a2)(8s8+20as4−a2)−3s(8s8+20as4−a2)34(s4−a)(8s4+a)(8s8+a2)(8s8−88as4−a2)
A simpler one:
xyzw====(s4−4a)22s3(s4+12a)2a(3s4+4a)2s3(s4−4a)(s4+12a)s5+12as2(3s4+4a)−2s5(s4+12a)(s4−4a)(3s4+4a)
And one related to that one:
xyzw====s5(s4−3a)32(s4+a)(s12+12as8−3a2s4+2a3)s12+12as8−3a2s4+2a32s3(s4−3a)(3s4−a)2a(s4+a)2(3s4−a)2s3(s4−3a)(s12+12as8−3a2s4+2a3)−2s(s12+12as8−3a2s4+2a3)(s4−3a)(s4+a)(3s4−a)
Observe that every family has at least two denominators of the form ps4−qa for positive p and q: since all the terms involved are rational, that means that there's some positive a for which we get division by zero. Therefore we must use at least two sets of solutions which have their singularities at different values of a. Intuitively it's going to be golfiest to choose two sets from the same family. I've chosen the simplest family (the third one) with parameters s=1 and s=2.