2-ancestry mixing, positive discriminant

Percentage Accurate: 43.7% → 46.1%
Time: 7.5s
Alternatives: 7
Speedup: 1.3×

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 7 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: 43.7% 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: 46.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{g \cdot g - h \cdot h}\\ t_1 := \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\ \mathbf{if}\;h \cdot h \leq 0:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right) - g} + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (let* ((t_0 (sqrt (- (* g g) (* h h)))) (t_1 (cbrt (* (+ g t_0) (/ -0.5 a)))))
   (if (<= (* h h) 0.0)
     (+ (* (cbrt (/ 0.5 a)) (cbrt (- (hypot g (sqrt (* h (- h)))) g))) t_1)
     (+ t_1 (cbrt (* (/ 0.5 a) (- t_0 g)))))))
double code(double g, double h, double a) {
	double t_0 = sqrt(((g * g) - (h * h)));
	double t_1 = cbrt(((g + t_0) * (-0.5 / a)));
	double tmp;
	if ((h * h) <= 0.0) {
		tmp = (cbrt((0.5 / a)) * cbrt((hypot(g, sqrt((h * -h))) - g))) + t_1;
	} else {
		tmp = t_1 + cbrt(((0.5 / a) * (t_0 - g)));
	}
	return tmp;
}
public static double code(double g, double h, double a) {
	double t_0 = Math.sqrt(((g * g) - (h * h)));
	double t_1 = Math.cbrt(((g + t_0) * (-0.5 / a)));
	double tmp;
	if ((h * h) <= 0.0) {
		tmp = (Math.cbrt((0.5 / a)) * Math.cbrt((Math.hypot(g, Math.sqrt((h * -h))) - g))) + t_1;
	} else {
		tmp = t_1 + Math.cbrt(((0.5 / a) * (t_0 - g)));
	}
	return tmp;
}
function code(g, h, a)
	t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h)))
	t_1 = cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a)))
	tmp = 0.0
	if (Float64(h * h) <= 0.0)
		tmp = Float64(Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(hypot(g, sqrt(Float64(h * Float64(-h)))) - g))) + t_1);
	else
		tmp = Float64(t_1 + cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))));
	end
	return tmp
end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(h * h), $MachinePrecision], 0.0], N[(N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], N[(t$95$1 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\mathbf{if}\;h \cdot h \leq 0:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right) - g} + t_1\\

\mathbf{else}:\\
\;\;\;\;t_1 + \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\


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

    1. Initial program 50.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. Simplified50.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}}} \]
    3. Step-by-step derivation
      1. cbrt-prod56.8%

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

        \[\leadsto \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\sqrt{\color{blue}{g \cdot g + \left(-h \cdot h\right)}} - g} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
      3. add-sqr-sqrt56.8%

        \[\leadsto \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\sqrt{g \cdot g + \color{blue}{\sqrt{-h \cdot h} \cdot \sqrt{-h \cdot h}}} - g} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
      4. hypot-def58.0%

        \[\leadsto \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\color{blue}{\mathsf{hypot}\left(g, \sqrt{-h \cdot h}\right)} - g} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
      5. distribute-rgt-neg-in58.0%

        \[\leadsto \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\mathsf{hypot}\left(g, \sqrt{\color{blue}{h \cdot \left(-h\right)}}\right) - g} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
    4. Applied egg-rr58.0%

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

    if 0.0 < (*.f64 h h)

    1. Initial program 40.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. Simplified40.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. Recombined 2 regimes into one program.
  4. Final simplification47.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \cdot h \leq 0:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right) - g} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)}\\ \end{array} \]

Alternative 2: 46.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{g \cdot g - h \cdot h}\\ t_1 := \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\ \mathbf{if}\;h \cdot h \leq 0:\\ \;\;\;\;t_1 + \frac{\sqrt[3]{-0.5 \cdot \left(g + \mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right)\right)}}{\sqrt[3]{a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + t_1\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (let* ((t_0 (sqrt (- (* g g) (* h h)))) (t_1 (cbrt (* (/ 0.5 a) (- t_0 g)))))
   (if (<= (* h h) 0.0)
     (+ t_1 (/ (cbrt (* -0.5 (+ g (hypot g (sqrt (* h (- h))))))) (cbrt a)))
     (+ (cbrt (* (+ g t_0) (/ -0.5 a))) t_1))))
double code(double g, double h, double a) {
	double t_0 = sqrt(((g * g) - (h * h)));
	double t_1 = cbrt(((0.5 / a) * (t_0 - g)));
	double tmp;
	if ((h * h) <= 0.0) {
		tmp = t_1 + (cbrt((-0.5 * (g + hypot(g, sqrt((h * -h)))))) / cbrt(a));
	} else {
		tmp = cbrt(((g + t_0) * (-0.5 / a))) + t_1;
	}
	return tmp;
}
public static double code(double g, double h, double a) {
	double t_0 = Math.sqrt(((g * g) - (h * h)));
	double t_1 = Math.cbrt(((0.5 / a) * (t_0 - g)));
	double tmp;
	if ((h * h) <= 0.0) {
		tmp = t_1 + (Math.cbrt((-0.5 * (g + Math.hypot(g, Math.sqrt((h * -h)))))) / Math.cbrt(a));
	} else {
		tmp = Math.cbrt(((g + t_0) * (-0.5 / a))) + t_1;
	}
	return tmp;
}
function code(g, h, a)
	t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h)))
	t_1 = cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g)))
	tmp = 0.0
	if (Float64(h * h) <= 0.0)
		tmp = Float64(t_1 + Float64(cbrt(Float64(-0.5 * Float64(g + hypot(g, sqrt(Float64(h * Float64(-h))))))) / cbrt(a)));
	else
		tmp = Float64(cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) + t_1);
	end
	return tmp
end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(h * h), $MachinePrecision], 0.0], N[(t$95$1 + N[(N[Power[N[(-0.5 * N[(g + N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + t$95$1), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\
\mathbf{if}\;h \cdot h \leq 0:\\
\;\;\;\;t_1 + \frac{\sqrt[3]{-0.5 \cdot \left(g + \mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right)\right)}}{\sqrt[3]{a}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + t_1\\


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

    1. Initial program 50.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. Simplified50.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}}} \]
    3. Step-by-step derivation
      1. associate-*r/50.9%

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

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

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \frac{\sqrt[3]{\left(g + \sqrt{\color{blue}{g \cdot g + \left(-h \cdot h\right)}}\right) \cdot -0.5}}{\sqrt[3]{a}} \]
      4. add-sqr-sqrt54.2%

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

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \frac{\sqrt[3]{\left(g + \color{blue}{\mathsf{hypot}\left(g, \sqrt{-h \cdot h}\right)}\right) \cdot -0.5}}{\sqrt[3]{a}} \]
      6. distribute-rgt-neg-in56.1%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \frac{\sqrt[3]{\left(g + \mathsf{hypot}\left(g, \sqrt{\color{blue}{h \cdot \left(-h\right)}}\right)\right) \cdot -0.5}}{\sqrt[3]{a}} \]
    4. Applied egg-rr56.1%

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

    if 0.0 < (*.f64 h h)

    1. Initial program 40.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. Simplified40.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. Recombined 2 regimes into one program.
  4. Final simplification46.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \cdot h \leq 0:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \frac{\sqrt[3]{-0.5 \cdot \left(g + \mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right)\right)}}{\sqrt[3]{a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)}\\ \end{array} \]

Alternative 3: 45.4% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \frac{h \cdot \left(h \cdot 0.5\right)}{g}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if g < -5.4999999999999998e-156

    1. Initial program 40.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. Simplified40.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. Taylor expanded in g around -inf 42.7%

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

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

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{0.5 \cdot \color{blue}{\left(h \cdot h\right)}}{g} \cdot \frac{-0.5}{a}} \]
      3. associate-*r*42.7%

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

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

    if -5.4999999999999998e-156 < g

    1. Initial program 47.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. Simplified47.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. Taylor expanded in g around inf 48.8%

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

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

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

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

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\mathsf{fma}\left(-0.5, \color{blue}{\frac{h}{\frac{g}{h}}}, g\right) - g\right)} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
    5. Simplified48.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \frac{h \cdot \left(h \cdot 0.5\right)}{g}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(\mathsf{fma}\left(-0.5, \frac{h}{\frac{g}{h}}, g\right) - g\right)}\\ \end{array} \]

Alternative 4: 45.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{g \cdot g - h \cdot h}\\ \mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \frac{h \cdot \left(h \cdot 0.5\right)}{g}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (let* ((t_0 (sqrt (- (* g g) (* h h)))))
   (if (<= g -5.5e-156)
     (+
      (cbrt (* (/ 0.5 a) (- t_0 g)))
      (cbrt (* (/ -0.5 a) (/ (* h (* h 0.5)) g))))
     (+ (cbrt (* (+ g t_0) (/ -0.5 a))) (cbrt (* (/ 0.5 a) (- g g)))))))
double code(double g, double h, double a) {
	double t_0 = sqrt(((g * g) - (h * h)));
	double tmp;
	if (g <= -5.5e-156) {
		tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((-0.5 / a) * ((h * (h * 0.5)) / g)));
	} else {
		tmp = cbrt(((g + t_0) * (-0.5 / a))) + cbrt(((0.5 / a) * (g - g)));
	}
	return tmp;
}
public static double code(double g, double h, double a) {
	double t_0 = Math.sqrt(((g * g) - (h * h)));
	double tmp;
	if (g <= -5.5e-156) {
		tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((-0.5 / a) * ((h * (h * 0.5)) / g)));
	} else {
		tmp = Math.cbrt(((g + t_0) * (-0.5 / a))) + Math.cbrt(((0.5 / a) * (g - g)));
	}
	return tmp;
}
function code(g, h, a)
	t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h)))
	tmp = 0.0
	if (g <= -5.5e-156)
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(Float64(h * Float64(h * 0.5)) / g))));
	else
		tmp = Float64(cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) + cbrt(Float64(Float64(0.5 / a) * Float64(g - g))));
	end
	return tmp
end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[g, -5.5e-156], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(N[(h * N[(h * 0.5), $MachinePrecision]), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \frac{h \cdot \left(h \cdot 0.5\right)}{g}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if g < -5.4999999999999998e-156

    1. Initial program 40.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. Simplified40.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. Taylor expanded in g around -inf 42.7%

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

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

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{0.5 \cdot \color{blue}{\left(h \cdot h\right)}}{g} \cdot \frac{-0.5}{a}} \]
      3. associate-*r*42.7%

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

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

    if -5.4999999999999998e-156 < g

    1. Initial program 47.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. Simplified47.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. Taylor expanded in g around inf 48.8%

      \[\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}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification46.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \frac{h \cdot \left(h \cdot 0.5\right)}{g}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\ \end{array} \]

Alternative 5: 44.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{g \cdot g - h \cdot h}\\ \mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (let* ((t_0 (sqrt (- (* g g) (* h h)))))
   (if (<= g -5.5e-156)
     (+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (/ -0.5 a) (- g g))))
     (+ (cbrt (* (+ g t_0) (/ -0.5 a))) (cbrt (* (/ 0.5 a) (- g g)))))))
double code(double g, double h, double a) {
	double t_0 = sqrt(((g * g) - (h * h)));
	double tmp;
	if (g <= -5.5e-156) {
		tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((-0.5 / a) * (g - g)));
	} else {
		tmp = cbrt(((g + t_0) * (-0.5 / a))) + cbrt(((0.5 / a) * (g - g)));
	}
	return tmp;
}
public static double code(double g, double h, double a) {
	double t_0 = Math.sqrt(((g * g) - (h * h)));
	double tmp;
	if (g <= -5.5e-156) {
		tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((-0.5 / a) * (g - g)));
	} else {
		tmp = Math.cbrt(((g + t_0) * (-0.5 / a))) + Math.cbrt(((0.5 / a) * (g - g)));
	}
	return tmp;
}
function code(g, h, a)
	t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h)))
	tmp = 0.0
	if (g <= -5.5e-156)
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g - g))));
	else
		tmp = Float64(cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) + cbrt(Float64(Float64(0.5 / a) * Float64(g - g))));
	end
	return tmp
end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[g, -5.5e-156], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if g < -5.4999999999999998e-156

    1. Initial program 40.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. Simplified40.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. Taylor expanded in g around -inf 41.9%

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\left(g + \color{blue}{-1 \cdot g}\right) \cdot \frac{-0.5}{a}} \]
    4. Step-by-step derivation
      1. mul-1-neg41.9%

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\left(g + \color{blue}{\left(-g\right)}\right) \cdot \frac{-0.5}{a}} \]
    5. Simplified41.9%

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

    if -5.4999999999999998e-156 < g

    1. Initial program 47.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. Simplified47.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. Taylor expanded in g around inf 48.8%

      \[\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}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification45.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;g \leq -5.5 \cdot 10^{-156}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\ \end{array} \]

Alternative 6: 23.9% accurate, 1.3× speedup?

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

\\
\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}
\end{array}
Derivation
  1. Initial program 44.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. Simplified44.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. Taylor expanded in g around inf 28.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. Final simplification28.0%

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

Alternative 7: 27.3% accurate, 1.3× speedup?

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

\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}
\end{array}
Derivation
  1. Initial program 44.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. Simplified44.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. Taylor expanded in g around inf 30.8%

    \[\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}} \]
  4. Final simplification30.8%

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

Reproduce

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