2-ancestry mixing, positive discriminant

Percentage Accurate: 44.9% → 96.4%
Time: 16.6s
Alternatives: 5
Speedup: 4.2×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{2 \cdot a}\\ t_1 := \sqrt{g \cdot g - h \cdot h}\\ \sqrt[3]{t\_0 \cdot \left(\left(-g\right) + t\_1\right)} + \sqrt[3]{t\_0 \cdot \left(\left(-g\right) - t\_1\right)} \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (let* ((t_0 (/ 1.0 (* 2.0 a))) (t_1 (sqrt (- (* g g) (* h h)))))
   (+ (cbrt (* t_0 (+ (- g) t_1))) (cbrt (* t_0 (- (- g) t_1))))))
double code(double g, double h, double a) {
	double t_0 = 1.0 / (2.0 * a);
	double t_1 = sqrt(((g * g) - (h * h)));
	return cbrt((t_0 * (-g + t_1))) + cbrt((t_0 * (-g - t_1)));
}
public static double code(double g, double h, double a) {
	double t_0 = 1.0 / (2.0 * a);
	double t_1 = Math.sqrt(((g * g) - (h * h)));
	return Math.cbrt((t_0 * (-g + t_1))) + Math.cbrt((t_0 * (-g - t_1)));
}
function code(g, h, a)
	t_0 = Float64(1.0 / Float64(2.0 * a))
	t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h)))
	return Float64(cbrt(Float64(t_0 * Float64(Float64(-g) + t_1))) + cbrt(Float64(t_0 * Float64(Float64(-g) - t_1))))
end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(t$95$0 * N[((-g) + t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[((-g) - t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{t\_0 \cdot \left(\left(-g\right) + t\_1\right)} + \sqrt[3]{t\_0 \cdot \left(\left(-g\right) - t\_1\right)}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 44.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{2 \cdot a}\\ t_1 := \sqrt{g \cdot g - h \cdot h}\\ \sqrt[3]{t\_0 \cdot \left(\left(-g\right) + t\_1\right)} + \sqrt[3]{t\_0 \cdot \left(\left(-g\right) - t\_1\right)} \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (let* ((t_0 (/ 1.0 (* 2.0 a))) (t_1 (sqrt (- (* g g) (* h h)))))
   (+ (cbrt (* t_0 (+ (- g) t_1))) (cbrt (* t_0 (- (- g) t_1))))))
double code(double g, double h, double a) {
	double t_0 = 1.0 / (2.0 * a);
	double t_1 = sqrt(((g * g) - (h * h)));
	return cbrt((t_0 * (-g + t_1))) + cbrt((t_0 * (-g - t_1)));
}
public static double code(double g, double h, double a) {
	double t_0 = 1.0 / (2.0 * a);
	double t_1 = Math.sqrt(((g * g) - (h * h)));
	return Math.cbrt((t_0 * (-g + t_1))) + Math.cbrt((t_0 * (-g - t_1)));
}
function code(g, h, a)
	t_0 = Float64(1.0 / Float64(2.0 * a))
	t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h)))
	return Float64(cbrt(Float64(t_0 * Float64(Float64(-g) + t_1))) + cbrt(Float64(t_0 * Float64(Float64(-g) - t_1))))
end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(t$95$0 * N[((-g) + t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[((-g) - t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{t\_0 \cdot \left(\left(-g\right) + t\_1\right)} + \sqrt[3]{t\_0 \cdot \left(\left(-g\right) - t\_1\right)}
\end{array}
\end{array}

Alternative 1: 96.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;h \cdot h \leq 4 \cdot 10^{+247}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (if (<= (* h h) 4e+247)
   (+
    (cbrt (* (/ 0.5 a) (/ (* -0.5 (pow h 2.0)) g)))
    (* (cbrt (/ -0.5 a)) (cbrt (* 2.0 g))))
   (fma
    (/ (cbrt g) (cbrt a))
    (* (cbrt -0.5) (sqrt (cbrt 4.0)))
    (* (cbrt (/ (pow h -2.0) (* a g))) (* (cbrt -0.5) (cbrt 0.5))))))
double code(double g, double h, double a) {
	double tmp;
	if ((h * h) <= 4e+247) {
		tmp = cbrt(((0.5 / a) * ((-0.5 * pow(h, 2.0)) / g))) + (cbrt((-0.5 / a)) * cbrt((2.0 * g)));
	} else {
		tmp = fma((cbrt(g) / cbrt(a)), (cbrt(-0.5) * sqrt(cbrt(4.0))), (cbrt((pow(h, -2.0) / (a * g))) * (cbrt(-0.5) * cbrt(0.5))));
	}
	return tmp;
}
function code(g, h, a)
	tmp = 0.0
	if (Float64(h * h) <= 4e+247)
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-0.5 * (h ^ 2.0)) / g))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(2.0 * g))));
	else
		tmp = fma(Float64(cbrt(g) / cbrt(a)), Float64(cbrt(-0.5) * sqrt(cbrt(4.0))), Float64(cbrt(Float64((h ^ -2.0) / Float64(a * g))) * Float64(cbrt(-0.5) * cbrt(0.5))));
	end
	return tmp
end
code[g_, h_, a_] := If[LessEqual[N[(h * h), $MachinePrecision], 4e+247], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[(-0.5 * N[Power[h, 2.0], $MachinePrecision]), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(2.0 * g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Sqrt[N[Power[4.0, 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(N[Power[h, -2.0], $MachinePrecision] / N[(a * g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;h \cdot h \leq 4 \cdot 10^{+247}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 h h) < 3.99999999999999981e247

    1. Initial program 48.5%

      \[\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. Simplified48.5%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in g around inf 29.5%

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

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\left(-0.5 \cdot \frac{{h}^{2}}{g}\right)}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/77.3%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    7. Simplified77.3%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    8. Step-by-step derivation
      1. *-commutative77.3%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\color{blue}{\frac{-0.5}{a} \cdot \left(g + g\right)}} \]
      2. cbrt-prod97.2%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + g}} \]
      3. count-297.2%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{\color{blue}{2 \cdot g}} \]
    9. Applied egg-rr97.2%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}} \]

    if 3.99999999999999981e247 < (*.f64 h h)

    1. Initial program 0.2%

      \[\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. Simplified0.2%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in h around 0 12.6%

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) + \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)} \]
    5. Step-by-step derivation
      1. fma-define12.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)} \]
      2. *-commutative12.6%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{\color{blue}{g \cdot a}}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right) \]
      3. *-commutative12.6%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \color{blue}{\left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)}\right) \]
    6. Simplified12.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)} \]
    7. Applied egg-rr19.5%

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

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \color{blue}{\sqrt{\sqrt[3]{4}}}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    9. Applied egg-rr88.5%

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \color{blue}{{\left(\sqrt[3]{\sqrt[3]{\frac{\frac{{h}^{-2}}{g}}{a}}}\right)}^{3}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    10. Step-by-step derivation
      1. rem-cube-cbrt88.5%

        \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \color{blue}{\sqrt[3]{\frac{\frac{{h}^{-2}}{g}}{a}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
      2. associate-/l/88.5%

        \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \sqrt[3]{\color{blue}{\frac{{h}^{-2}}{a \cdot g}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    11. Simplified88.5%

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \color{blue}{\sqrt[3]{\frac{{h}^{-2}}{a \cdot g}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \cdot h \leq 4 \cdot 10^{+247}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;h \cdot h \leq 4 \cdot 10^{+247}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (if (<= (* h h) 4e+247)
   (+
    (cbrt (* (/ 0.5 a) (/ (* -0.5 (pow h 2.0)) g)))
    (* (cbrt (/ -0.5 a)) (cbrt (* 2.0 g))))
   (fma
    (/ (cbrt g) (cbrt a))
    (* (cbrt -0.5) (cbrt 2.0))
    (* (cbrt (/ (pow h -2.0) (* a g))) (* (cbrt -0.5) (cbrt 0.5))))))
double code(double g, double h, double a) {
	double tmp;
	if ((h * h) <= 4e+247) {
		tmp = cbrt(((0.5 / a) * ((-0.5 * pow(h, 2.0)) / g))) + (cbrt((-0.5 / a)) * cbrt((2.0 * g)));
	} else {
		tmp = fma((cbrt(g) / cbrt(a)), (cbrt(-0.5) * cbrt(2.0)), (cbrt((pow(h, -2.0) / (a * g))) * (cbrt(-0.5) * cbrt(0.5))));
	}
	return tmp;
}
function code(g, h, a)
	tmp = 0.0
	if (Float64(h * h) <= 4e+247)
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-0.5 * (h ^ 2.0)) / g))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(2.0 * g))));
	else
		tmp = fma(Float64(cbrt(g) / cbrt(a)), Float64(cbrt(-0.5) * cbrt(2.0)), Float64(cbrt(Float64((h ^ -2.0) / Float64(a * g))) * Float64(cbrt(-0.5) * cbrt(0.5))));
	end
	return tmp
end
code[g_, h_, a_] := If[LessEqual[N[(h * h), $MachinePrecision], 4e+247], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[(-0.5 * N[Power[h, 2.0], $MachinePrecision]), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(2.0 * g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(N[Power[h, -2.0], $MachinePrecision] / N[(a * g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;h \cdot h \leq 4 \cdot 10^{+247}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 h h) < 3.99999999999999981e247

    1. Initial program 48.5%

      \[\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. Simplified48.5%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in g around inf 29.5%

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

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\left(-0.5 \cdot \frac{{h}^{2}}{g}\right)}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/77.3%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    7. Simplified77.3%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    8. Step-by-step derivation
      1. *-commutative77.3%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\color{blue}{\frac{-0.5}{a} \cdot \left(g + g\right)}} \]
      2. cbrt-prod97.2%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + g}} \]
      3. count-297.2%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{\color{blue}{2 \cdot g}} \]
    9. Applied egg-rr97.2%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}} \]

    if 3.99999999999999981e247 < (*.f64 h h)

    1. Initial program 0.2%

      \[\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. Simplified0.2%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in h around 0 12.6%

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) + \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)} \]
    5. Step-by-step derivation
      1. fma-define12.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)} \]
      2. *-commutative12.6%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{\color{blue}{g \cdot a}}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right) \]
      3. *-commutative12.6%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \color{blue}{\left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)}\right) \]
    6. Simplified12.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)} \]
    7. Applied egg-rr19.5%

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

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \color{blue}{{\left(\sqrt[3]{\sqrt[3]{\frac{\frac{{h}^{-2}}{g}}{a}}}\right)}^{3}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    9. Step-by-step derivation
      1. rem-cube-cbrt88.5%

        \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \color{blue}{\sqrt[3]{\frac{\frac{{h}^{-2}}{g}}{a}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
      2. associate-/l/88.5%

        \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \sqrt[3]{\color{blue}{\frac{{h}^{-2}}{a \cdot g}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    10. Simplified87.7%

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \color{blue}{\sqrt[3]{\frac{{h}^{-2}}{a \cdot g}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \cdot h \leq 4 \cdot 10^{+247}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 92.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;h \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt[3]{\frac{a}{g}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (if (<= h 1.35e+154)
   (+
    (cbrt (* (/ 0.5 a) (/ (* -0.5 (pow h 2.0)) g)))
    (* (cbrt (/ -0.5 a)) (cbrt (* 2.0 g))))
   (fma
    (/ 1.0 (cbrt (/ a g)))
    (* (cbrt -0.5) (cbrt 2.0))
    (* (cbrt (/ (pow h -2.0) (* a g))) (* (cbrt -0.5) (cbrt 0.5))))))
double code(double g, double h, double a) {
	double tmp;
	if (h <= 1.35e+154) {
		tmp = cbrt(((0.5 / a) * ((-0.5 * pow(h, 2.0)) / g))) + (cbrt((-0.5 / a)) * cbrt((2.0 * g)));
	} else {
		tmp = fma((1.0 / cbrt((a / g))), (cbrt(-0.5) * cbrt(2.0)), (cbrt((pow(h, -2.0) / (a * g))) * (cbrt(-0.5) * cbrt(0.5))));
	}
	return tmp;
}
function code(g, h, a)
	tmp = 0.0
	if (h <= 1.35e+154)
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-0.5 * (h ^ 2.0)) / g))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(2.0 * g))));
	else
		tmp = fma(Float64(1.0 / cbrt(Float64(a / g))), Float64(cbrt(-0.5) * cbrt(2.0)), Float64(cbrt(Float64((h ^ -2.0) / Float64(a * g))) * Float64(cbrt(-0.5) * cbrt(0.5))));
	end
	return tmp
end
code[g_, h_, a_] := If[LessEqual[h, 1.35e+154], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[(-0.5 * N[Power[h, 2.0], $MachinePrecision]), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(2.0 * g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Power[N[(a / g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] * N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(N[Power[h, -2.0], $MachinePrecision] / N[(a * g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;h \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt[3]{\frac{a}{g}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 1.35000000000000003e154

    1. Initial program 45.3%

      \[\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. Simplified45.3%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in g around inf 27.7%

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

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\left(-0.5 \cdot \frac{{h}^{2}}{g}\right)}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/73.7%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    7. Simplified73.7%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    8. Step-by-step derivation
      1. *-commutative73.7%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\color{blue}{\frac{-0.5}{a} \cdot \left(g + g\right)}} \]
      2. cbrt-prod93.0%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + g}} \]
      3. count-293.0%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{\color{blue}{2 \cdot g}} \]
    9. Applied egg-rr93.0%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}} \]

    if 1.35000000000000003e154 < h

    1. Initial program 0.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. Simplified0.0%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in h around 0 1.4%

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) + \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)} \]
    5. Step-by-step derivation
      1. fma-define1.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)} \]
      2. *-commutative1.4%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{\color{blue}{g \cdot a}}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right) \]
      3. *-commutative1.4%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \color{blue}{\left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)}\right) \]
    6. Simplified1.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)} \]
    7. Applied egg-rr1.4%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sqrt[3]{g}}{\sqrt[3]{a}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    8. Step-by-step derivation
      1. clear-num1.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\frac{\sqrt[3]{a}}{\sqrt[3]{g}}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
      2. inv-pow1.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\frac{\sqrt[3]{a}}{\sqrt[3]{g}}\right)}^{-1}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
      3. cbrt-undiv1.4%

        \[\leadsto \mathsf{fma}\left({\color{blue}{\left(\sqrt[3]{\frac{a}{g}}\right)}}^{-1}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    9. Applied egg-rr1.4%

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{\frac{a}{g}}\right)}^{-1}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    10. Simplified1.4%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\sqrt[3]{\frac{a}{g}}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    11. Applied egg-rr83.0%

      \[\leadsto \mathsf{fma}\left(\frac{1}{\sqrt[3]{\frac{a}{g}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \color{blue}{{\left(\sqrt[3]{\sqrt[3]{\frac{\frac{{h}^{-2}}{g}}{a}}}\right)}^{3}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    12. Step-by-step derivation
      1. rem-cube-cbrt83.4%

        \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \color{blue}{\sqrt[3]{\frac{\frac{{h}^{-2}}{g}}{a}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
      2. associate-/l/83.4%

        \[\leadsto \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt{\sqrt[3]{4}}, \sqrt[3]{\color{blue}{\frac{{h}^{-2}}{a \cdot g}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    13. Simplified83.0%

      \[\leadsto \mathsf{fma}\left(\frac{1}{\sqrt[3]{\frac{a}{g}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \color{blue}{\sqrt[3]{\frac{{h}^{-2}}{a \cdot g}}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt[3]{\frac{a}{g}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{-2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 92.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;h \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\ \mathbf{else}:\\ \;\;\;\;-\sqrt[3]{\frac{g}{a}}\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (if (<= h 1.35e+154)
   (+
    (cbrt (* (/ 0.5 a) (/ (* -0.5 (pow h 2.0)) g)))
    (* (cbrt (/ -0.5 a)) (cbrt (* 2.0 g))))
   (- (cbrt (/ g a)))))
double code(double g, double h, double a) {
	double tmp;
	if (h <= 1.35e+154) {
		tmp = cbrt(((0.5 / a) * ((-0.5 * pow(h, 2.0)) / g))) + (cbrt((-0.5 / a)) * cbrt((2.0 * g)));
	} else {
		tmp = -cbrt((g / a));
	}
	return tmp;
}
public static double code(double g, double h, double a) {
	double tmp;
	if (h <= 1.35e+154) {
		tmp = Math.cbrt(((0.5 / a) * ((-0.5 * Math.pow(h, 2.0)) / g))) + (Math.cbrt((-0.5 / a)) * Math.cbrt((2.0 * g)));
	} else {
		tmp = -Math.cbrt((g / a));
	}
	return tmp;
}
function code(g, h, a)
	tmp = 0.0
	if (h <= 1.35e+154)
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-0.5 * (h ^ 2.0)) / g))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(2.0 * g))));
	else
		tmp = Float64(-cbrt(Float64(g / a)));
	end
	return tmp
end
code[g_, h_, a_] := If[LessEqual[h, 1.35e+154], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[(-0.5 * N[Power[h, 2.0], $MachinePrecision]), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(2.0 * g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;h \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}\\

\mathbf{else}:\\
\;\;\;\;-\sqrt[3]{\frac{g}{a}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 1.35000000000000003e154

    1. Initial program 45.3%

      \[\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. Simplified45.3%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in g around inf 27.7%

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

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\left(-0.5 \cdot \frac{{h}^{2}}{g}\right)}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    6. Step-by-step derivation
      1. associate-*r/73.7%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    7. Simplified73.7%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \color{blue}{\frac{-0.5 \cdot {h}^{2}}{g}}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    8. Step-by-step derivation
      1. *-commutative73.7%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\color{blue}{\frac{-0.5}{a} \cdot \left(g + g\right)}} \]
      2. cbrt-prod93.0%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + g}} \]
      3. count-293.0%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{\color{blue}{2 \cdot g}} \]
    9. Applied egg-rr93.0%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \frac{-0.5 \cdot {h}^{2}}{g}} + \color{blue}{\sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{2 \cdot g}} \]

    if 1.35000000000000003e154 < h

    1. Initial program 0.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. Simplified0.0%

      \[\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}}} \]
    3. Add Preprocessing
    4. Taylor expanded in h around 0 1.4%

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) + \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)} \]
    5. Step-by-step derivation
      1. fma-define1.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)} \]
      2. *-commutative1.4%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{\color{blue}{g \cdot a}}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right) \]
      3. *-commutative1.4%

        \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \color{blue}{\left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)}\right) \]
    6. Simplified1.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)} \]
    7. Applied egg-rr1.4%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sqrt[3]{g}}{\sqrt[3]{a}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
    8. Step-by-step derivation
      1. add-cbrt-cube1.4%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \cdot \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)\right) \cdot \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)}} \]
      2. pow31.4%

        \[\leadsto \sqrt[3]{\color{blue}{{\left(\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)\right)}^{3}}} \]
    9. Applied egg-rr1.4%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\sqrt[3]{\frac{g}{a} \cdot -1} + \sqrt[3]{-0.25 \cdot \frac{{h}^{2}}{g \cdot a}}\right)}^{3}}} \]
    10. Taylor expanded in g around -inf 81.0%

      \[\leadsto \color{blue}{-1 \cdot \sqrt[3]{\frac{g}{a}}} \]
    11. Step-by-step derivation
      1. mul-1-neg81.0%

        \[\leadsto \color{blue}{-\sqrt[3]{\frac{g}{a}}} \]
    12. Simplified81.0%

      \[\leadsto \color{blue}{-\sqrt[3]{\frac{g}{a}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 74.1% accurate, 4.2× speedup?

\[\begin{array}{l} \\ -\sqrt[3]{\frac{g}{a}} \end{array} \]
(FPCore (g h a) :precision binary64 (- (cbrt (/ g a))))
double code(double g, double h, double a) {
	return -cbrt((g / a));
}
public static double code(double g, double h, double a) {
	return -Math.cbrt((g / a));
}
function code(g, h, a)
	return Float64(-cbrt(Float64(g / a)))
end
code[g_, h_, a_] := (-N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision])
\begin{array}{l}

\\
-\sqrt[3]{\frac{g}{a}}
\end{array}
Derivation
  1. Initial program 43.4%

    \[\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. Simplified43.4%

    \[\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}}} \]
  3. Add Preprocessing
  4. Taylor expanded in h around 0 67.1%

    \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) + \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)} \]
  5. Step-by-step derivation
    1. fma-define67.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{a \cdot g}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right)} \]
    2. *-commutative67.1%

      \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{\color{blue}{g \cdot a}}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right)\right) \]
    3. *-commutative67.1%

      \[\leadsto \mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \color{blue}{\left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)}\right) \]
  6. Simplified67.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)} \]
  7. Applied egg-rr85.5%

    \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sqrt[3]{g}}{\sqrt[3]{a}}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \]
  8. Step-by-step derivation
    1. add-cbrt-cube67.0%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right) \cdot \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)\right) \cdot \mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)}} \]
    2. pow367.0%

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}, \sqrt[3]{-0.5} \cdot \sqrt[3]{2}, \sqrt[3]{\frac{{h}^{2}}{g \cdot a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)\right)}^{3}}} \]
  9. Applied egg-rr67.6%

    \[\leadsto \color{blue}{\sqrt[3]{{\left(\sqrt[3]{\frac{g}{a} \cdot -1} + \sqrt[3]{-0.25 \cdot \frac{{h}^{2}}{g \cdot a}}\right)}^{3}}} \]
  10. Taylor expanded in g around -inf 75.9%

    \[\leadsto \color{blue}{-1 \cdot \sqrt[3]{\frac{g}{a}}} \]
  11. Step-by-step derivation
    1. mul-1-neg75.9%

      \[\leadsto \color{blue}{-\sqrt[3]{\frac{g}{a}}} \]
  12. Simplified75.9%

    \[\leadsto \color{blue}{-\sqrt[3]{\frac{g}{a}}} \]
  13. Add Preprocessing

Reproduce

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