2-ancestry mixing, positive discriminant

Percentage Accurate: 43.7% → 95.8%
Time: 22.5s
Alternatives: 6
Speedup: 2.1×

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 6 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: 95.8% accurate, 1.4× speedup?

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

\\
\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}
\end{array}
Derivation
  1. Initial program 40.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. Simplified40.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. Step-by-step derivation
    1. associate-*l/40.3%

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

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

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

      \[\leadsto \frac{\sqrt[3]{0.5 \cdot \left(\sqrt{{g}^{2} - \color{blue}{{h}^{2}}} - g\right)}}{\sqrt[3]{a}} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
  4. Applied egg-rr44.6%

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

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

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

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

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

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

    \[\leadsto \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}} + \sqrt[3]{\left(g + \color{blue}{\left(-g\right)}\right) \cdot \frac{-0.5}{a}} \]
  11. Taylor expanded in g around 0 95.9%

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

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

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

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

Alternative 2: 91.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -2.7 \cdot 10^{-54} \lor \neg \left(a \leq 9.4 \cdot 10^{-38}\right):\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{-g} + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (if (or (<= a -2.7e-54) (not (<= a 9.4e-38)))
   (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt (/ (- g) a)))
   (+ (cbrt (- g)) (/ (cbrt (* 0.5 (- (- g) g))) (cbrt a)))))
double code(double g, double h, double a) {
	double tmp;
	if ((a <= -2.7e-54) || !(a <= 9.4e-38)) {
		tmp = cbrt(((0.5 / a) * (g - g))) + cbrt((-g / a));
	} else {
		tmp = cbrt(-g) + (cbrt((0.5 * (-g - g))) / cbrt(a));
	}
	return tmp;
}
public static double code(double g, double h, double a) {
	double tmp;
	if ((a <= -2.7e-54) || !(a <= 9.4e-38)) {
		tmp = Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt((-g / a));
	} else {
		tmp = Math.cbrt(-g) + (Math.cbrt((0.5 * (-g - g))) / Math.cbrt(a));
	}
	return tmp;
}
function code(g, h, a)
	tmp = 0.0
	if ((a <= -2.7e-54) || !(a <= 9.4e-38))
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(Float64(Float64(-g) / a)));
	else
		tmp = Float64(cbrt(Float64(-g)) + Float64(cbrt(Float64(0.5 * Float64(Float64(-g) - g))) / cbrt(a)));
	end
	return tmp
end
code[g_, h_, a_] := If[Or[LessEqual[a, -2.7e-54], N[Not[LessEqual[a, 9.4e-38]], $MachinePrecision]], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[(-g), 1/3], $MachinePrecision] + N[(N[Power[N[(0.5 * N[((-g) - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.7 \cdot 10^{-54} \lor \neg \left(a \leq 9.4 \cdot 10^{-38}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -2.70000000000000026e-54 or 9.39999999999999996e-38 < a

    1. Initial program 43.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. Simplified43.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. Taylor expanded in g around inf 17.4%

      \[\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 85.5%

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

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

    if -2.70000000000000026e-54 < a < 9.39999999999999996e-38

    1. Initial program 35.7%

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

      \[\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-*l/35.7%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}} + \sqrt[3]{\left(g + \color{blue}{g}\right) \cdot \frac{-0.5}{a}} \]
    9. Taylor expanded in g around 0 11.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -2.7 \cdot 10^{-54} \lor \neg \left(a \leq 9.4 \cdot 10^{-38}\right):\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{-g} + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}\\ \end{array} \]

Alternative 3: 89.3% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -6 \cdot 10^{-86} \lor \neg \left(a \leq 2.65 \cdot 10^{-42}\right):\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}\\ \end{array} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (if (or (<= a -6e-86) (not (<= a 2.65e-42)))
   (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt (/ (- g) a)))
   (+ -1.0 (/ (cbrt (* 0.5 (- (- g) g))) (cbrt a)))))
double code(double g, double h, double a) {
	double tmp;
	if ((a <= -6e-86) || !(a <= 2.65e-42)) {
		tmp = cbrt(((0.5 / a) * (g - g))) + cbrt((-g / a));
	} else {
		tmp = -1.0 + (cbrt((0.5 * (-g - g))) / cbrt(a));
	}
	return tmp;
}
public static double code(double g, double h, double a) {
	double tmp;
	if ((a <= -6e-86) || !(a <= 2.65e-42)) {
		tmp = Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt((-g / a));
	} else {
		tmp = -1.0 + (Math.cbrt((0.5 * (-g - g))) / Math.cbrt(a));
	}
	return tmp;
}
function code(g, h, a)
	tmp = 0.0
	if ((a <= -6e-86) || !(a <= 2.65e-42))
		tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(Float64(Float64(-g) / a)));
	else
		tmp = Float64(-1.0 + Float64(cbrt(Float64(0.5 * Float64(Float64(-g) - g))) / cbrt(a)));
	end
	return tmp
end
code[g_, h_, a_] := If[Or[LessEqual[a, -6e-86], N[Not[LessEqual[a, 2.65e-42]], $MachinePrecision]], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[Power[N[(0.5 * N[((-g) - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -6 \cdot 10^{-86} \lor \neg \left(a \leq 2.65 \cdot 10^{-42}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -6.0000000000000002e-86 or 2.65e-42 < a

    1. Initial program 43.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. Simplified43.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 18.6%

      \[\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 85.6%

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

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

    if -6.0000000000000002e-86 < a < 2.65e-42

    1. Initial program 35.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. Simplified35.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. Step-by-step derivation
      1. associate-*l/35.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \color{blue}{\sqrt[3]{g + g} \cdot \sqrt[3]{\frac{-0.5}{a}}} \]
    10. Applied egg-rr0.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -6 \cdot 10^{-86} \lor \neg \left(a \leq 2.65 \cdot 10^{-42}\right):\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}\\ \end{array} \]

Alternative 4: 4.7% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \sqrt[3]{-g} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} \end{array} \]
(FPCore (g h a)
 :precision binary64
 (+ (cbrt (- g)) (cbrt (* (/ 0.5 a) (- g g)))))
double code(double g, double h, double a) {
	return cbrt(-g) + cbrt(((0.5 / a) * (g - g)));
}
public static double code(double g, double h, double a) {
	return Math.cbrt(-g) + Math.cbrt(((0.5 / a) * (g - g)));
}
function code(g, h, a)
	return Float64(cbrt(Float64(-g)) + cbrt(Float64(Float64(0.5 / a) * Float64(g - g))))
end
code[g_, h_, a_] := N[(N[Power[(-g), 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]{-g} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}
\end{array}
Derivation
  1. Initial program 40.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. Simplified40.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 17.4%

    \[\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 70.2%

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

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

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

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

Alternative 5: 62.9% accurate, 2.1× speedup?

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

\\
-1 + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}
\end{array}
Derivation
  1. Initial program 40.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. Simplified40.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. Step-by-step derivation
    1. associate-*l/40.3%

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

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

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

      \[\leadsto \frac{\sqrt[3]{0.5 \cdot \left(\sqrt{{g}^{2} - \color{blue}{{h}^{2}}} - g\right)}}{\sqrt[3]{a}} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} \]
  4. Applied egg-rr44.6%

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

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

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

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

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

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \color{blue}{\sqrt[3]{g + g} \cdot \sqrt[3]{\frac{-0.5}{a}}} \]
  10. Applied egg-rr0.0%

    \[\leadsto \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}} + \color{blue}{\frac{0}{0} \cdot \sqrt[3]{\frac{-0.5}{a}}} \]
  11. Simplified62.6%

    \[\leadsto \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}} + \color{blue}{-1} \]
  12. Final simplification62.6%

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

Alternative 6: 4.4% accurate, 4.0× speedup?

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

\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + -1
\end{array}
Derivation
  1. Initial program 40.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. Simplified40.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 17.4%

    \[\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 70.2%

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

      \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \color{blue}{\sqrt[3]{g + g} \cdot \sqrt[3]{\frac{-0.5}{a}}} \]
  6. Applied egg-rr0.0%

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

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \color{blue}{-1} \]
  8. Final simplification4.3%

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

Reproduce

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