Average Error: 36.1 → 31.3
Time: 15.7s
Precision: binary64
\[\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)}\]
\[\begin{array}{l} \mathbf{if}\;\sqrt[3]{\frac{1}{2 \cdot 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{-1}{2 \cdot a}} \leq \infty:\\ \;\;\;\;\frac{\sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g}}{\sqrt[3]{2 \cdot a}} + \left(\sqrt[3]{g + \sqrt{\left(g + h\right) \cdot \left(g - h\right)}} \cdot \sqrt[3]{\frac{-1}{a}}\right) \cdot \sqrt[3]{0.5}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
\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)}
\begin{array}{l}
\mathbf{if}\;\sqrt[3]{\frac{1}{2 \cdot 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{-1}{2 \cdot a}} \leq \infty:\\
\;\;\;\;\frac{\sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g}}{\sqrt[3]{2 \cdot a}} + \left(\sqrt[3]{g + \sqrt{\left(g + h\right) \cdot \left(g - h\right)}} \cdot \sqrt[3]{\frac{-1}{a}}\right) \cdot \sqrt[3]{0.5}\\

\mathbf{else}:\\
\;\;\;\;-1\\

\end{array}
(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
 (if (<=
      (+
       (cbrt (* (/ 1.0 (* 2.0 a)) (- (sqrt (- (* g g) (* h h))) g)))
       (cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -1.0 (* 2.0 a)))))
      INFINITY)
   (+
    (/ (cbrt (- (sqrt (- (* g g) (* h h))) g)) (cbrt (* 2.0 a)))
    (*
     (* (cbrt (+ g (sqrt (* (+ g h) (- g h))))) (cbrt (/ -1.0 a)))
     (cbrt 0.5)))
   -1.0))
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) {
	double tmp;
	if ((cbrt((1.0 / (2.0 * a)) * (sqrt((g * g) - (h * h)) - g)) + cbrt((g + sqrt((g * g) - (h * h))) * (-1.0 / (2.0 * a)))) <= ((double) INFINITY)) {
		tmp = (cbrt(sqrt((g * g) - (h * h)) - g) / cbrt(2.0 * a)) + ((cbrt(g + sqrt((g + h) * (g - h))) * cbrt(-1.0 / a)) * cbrt(0.5));
	} else {
		tmp = -1.0;
	}
	return tmp;
}

Error

Bits error versus g

Bits error versus h

Bits error versus a

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (+.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)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) < +inf.0

    1. Initial program 14.0

      \[\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. Using strategy rm
    3. Applied associate-*l/_binary64_274914.0

      \[\leadsto \sqrt[3]{\color{blue}{\frac{1 \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)}{2 \cdot a}}} + \sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)}\]
    4. Applied cbrt-div_binary64_283810.2

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

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g}}}{\sqrt[3]{2 \cdot a}} + \sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)}\]
    6. Taylor expanded around -inf 37.4

      \[\leadsto \frac{\sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g}}{\sqrt[3]{2 \cdot a}} + \color{blue}{e^{0.3333333333333333 \cdot \left(\log \left(\frac{-1}{a}\right) + \log \left(\sqrt{{g}^{2} - {h}^{2}} + g\right)\right)} \cdot \sqrt[3]{0.5}}\]
    7. Simplified7.4

      \[\leadsto \frac{\sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g}}{\sqrt[3]{2 \cdot a}} + \color{blue}{\left(\sqrt[3]{g + \sqrt{g \cdot g - h \cdot h}} \cdot \sqrt[3]{\frac{-1}{a}}\right) \cdot \sqrt[3]{0.5}}\]
    8. Using strategy rm
    9. Applied difference-of-squares_binary64_27757.4

      \[\leadsto \frac{\sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g}}{\sqrt[3]{2 \cdot a}} + \left(\sqrt[3]{g + \sqrt{\color{blue}{\left(g + h\right) \cdot \left(g - h\right)}}} \cdot \sqrt[3]{\frac{-1}{a}}\right) \cdot \sqrt[3]{0.5}\]
    10. Simplified7.4

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

    if +inf.0 < (+.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)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))))

    1. Initial program 61.3

      \[-1\]
  3. Recombined 2 regimes into one program.
  4. Final simplification31.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt[3]{\frac{1}{2 \cdot 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{-1}{2 \cdot a}} \leq \infty:\\ \;\;\;\;\frac{\sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g}}{\sqrt[3]{2 \cdot a}} + \left(\sqrt[3]{g + \sqrt{\left(g + h\right) \cdot \left(g - h\right)}} \cdot \sqrt[3]{\frac{-1}{a}}\right) \cdot \sqrt[3]{0.5}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Alternatives

Reproduce

herbie shell --seed 2021102 
(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))))))))