Average Error: 35.9 → 2.8
Time: 9.9s
Precision: binary64
Cost: 20160
\[\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)} \]
\[\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{g \cdot 2} \cdot \sqrt[3]{\frac{-0.5}{a}} \]
(FPCore (g h a)
 :precision binary64
 (+
  (cbrt (* (/ 1.0 (* 2.0 a)) (+ (- g) (sqrt (- (* g g) (* h h))))))
  (cbrt (* (/ 1.0 (* 2.0 a)) (- (- g) (sqrt (- (* g g) (* h h))))))))
(FPCore (g h a)
 :precision binary64
 (+ (cbrt (* (/ 0.5 a) (- g g))) (* (cbrt (* g 2.0)) (cbrt (/ -0.5 a)))))
double code(double g, double h, double a) {
	return cbrt(((1.0 / (2.0 * a)) * (-g + sqrt(((g * g) - (h * h)))))) + cbrt(((1.0 / (2.0 * a)) * (-g - sqrt(((g * g) - (h * h))))));
}
double code(double g, double h, double a) {
	return cbrt(((0.5 / a) * (g - g))) + (cbrt((g * 2.0)) * cbrt((-0.5 / a)));
}
public static double code(double g, double h, double a) {
	return Math.cbrt(((1.0 / (2.0 * a)) * (-g + Math.sqrt(((g * g) - (h * h)))))) + Math.cbrt(((1.0 / (2.0 * a)) * (-g - Math.sqrt(((g * g) - (h * h))))));
}
public static double code(double g, double h, double a) {
	return Math.cbrt(((0.5 / a) * (g - g))) + (Math.cbrt((g * 2.0)) * Math.cbrt((-0.5 / a)));
}
function code(g, h, a)
	return Float64(cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * Float64(Float64(-g) + sqrt(Float64(Float64(g * g) - Float64(h * h)))))) + cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * Float64(Float64(-g) - sqrt(Float64(Float64(g * g) - Float64(h * h)))))))
end
function code(g, h, a)
	return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + Float64(cbrt(Float64(g * 2.0)) * cbrt(Float64(-0.5 / a))))
end
code[g_, h_, a_] := N[(N[Power[N[(N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[((-g) + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[((-g) - N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(g * 2.0), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)}
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{g \cdot 2} \cdot \sqrt[3]{\frac{-0.5}{a}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 35.9

    \[\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)} \]
  2. Simplified35.9

    \[\leadsto \color{blue}{\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}}} \]
    Proof
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1/2 a) (-.f64 (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))) g))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (/.f64 -1/2 a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 (Rewrite<= metadata-eval (/.f64 1 2)) a) (-.f64 (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))) g))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (/.f64 -1/2 a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 2 a))) (-.f64 (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))) g))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (/.f64 -1/2 a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (Rewrite<= unsub-neg_binary64 (+.f64 (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))) (neg.f64 g))))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (/.f64 -1/2 a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (/.f64 -1/2 a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (/.f64 (Rewrite<= metadata-eval (*.f64 1/2 -1)) a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (/.f64 (*.f64 (Rewrite<= metadata-eval (/.f64 1 2)) -1) a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 (/.f64 1 2) a) -1))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))) (*.f64 (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 2 a))) -1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 (/.f64 1 (*.f64 2 a)) -1) (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (Rewrite<= associate-*r*_binary64 (*.f64 (/.f64 1 (*.f64 2 a)) (*.f64 -1 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (Rewrite<= neg-mul-1_binary64 (neg.f64 (+.f64 g (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (Rewrite<= distribute-neg-out_binary64 (+.f64 (neg.f64 g) (neg.f64 (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (Rewrite<= sub-neg_binary64 (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))))): 0 points increase in error, 0 points decrease in error
  3. Taylor expanded in g around inf 49.0

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\color{blue}{g} - g\right)} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
  4. Taylor expanded in g around inf 18.2

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\color{blue}{\left(2 \cdot g\right)} \cdot \frac{-0.5}{a}} \]
  5. Simplified18.2

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\color{blue}{\left(g + g\right)} \cdot \frac{-0.5}{a}} \]
    Proof
    (+.f64 g g): 0 points increase in error, 0 points decrease in error
    (Rewrite=> count-2_binary64 (*.f64 2 g)): 0 points increase in error, 0 points decrease in error
  6. Applied egg-rr47.8

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\color{blue}{\frac{\left(2 \cdot {g}^{3}\right) \cdot -0.5}{\mathsf{fma}\left(g, g, 0\right) \cdot a}}} \]
  7. Applied egg-rr2.8

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \color{blue}{\sqrt[3]{2 \cdot g} \cdot \sqrt[3]{\frac{-0.5}{a}}} \]
  8. Simplified2.8

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \color{blue}{\sqrt[3]{g \cdot 2} \cdot \sqrt[3]{\frac{-0.5}{a}}} \]
    Proof
    (*.f64 (cbrt.f64 (*.f64 g 2)) (cbrt.f64 (/.f64 -1/2 a))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cbrt.f64 (Rewrite<= *-commutative_binary64 (*.f64 2 g))) (cbrt.f64 (/.f64 -1/2 a))): 0 points increase in error, 0 points decrease in error
  9. Final simplification2.8

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{g \cdot 2} \cdot \sqrt[3]{\frac{-0.5}{a}} \]

Alternatives

Alternative 1
Error2.8
Cost19968
\[\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \frac{\sqrt[3]{-g}}{\sqrt[3]{a}} \]
Alternative 2
Error12.7
Cost14404
\[\begin{array}{l} t_0 := \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\ \mathbf{if}\;a \leq -1.05 \cdot 10^{-121}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + \left(0.5 \cdot \frac{h}{\frac{g}{h}} - g\right)\right)}\\ \mathbf{elif}\;a \leq 8.4 \cdot 10^{-168}:\\ \;\;\;\;t_0 + \frac{g}{\sqrt[3]{g \cdot \left(g \cdot \left(-a\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \sqrt[3]{-\frac{g}{a}}\\ \end{array} \]
Alternative 3
Error12.8
Cost14088
\[\begin{array}{l} t_0 := \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\ \mathbf{if}\;a \leq -2.5 \cdot 10^{-118}:\\ \;\;\;\;t_0 + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\ \mathbf{elif}\;a \leq 1.95 \cdot 10^{-167}:\\ \;\;\;\;t_0 + \frac{g}{\sqrt[3]{g \cdot \left(g \cdot \left(-a\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \sqrt[3]{-\frac{g}{a}}\\ \end{array} \]
Alternative 4
Error18.2
Cost13568
\[\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{-\frac{g}{a}} \]
Alternative 5
Error62.1
Cost13376
\[\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{0} \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (g h a)
  :name "2-ancestry mixing, positive discriminant"
  :precision binary64
  (+ (cbrt (* (/ 1.0 (* 2.0 a)) (+ (- g) (sqrt (- (* g g) (* h h)))))) (cbrt (* (/ 1.0 (* 2.0 a)) (- (- g) (sqrt (- (* g g) (* h h))))))))