2-ancestry mixing, positive discriminant

Percentage Accurate: 44.2% → 95.7%
Time: 30.4s
Alternatives: 9
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 9 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.2% 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.7% accurate, 1.4× speedup?

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

\\
\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}}
\end{array}
Derivation
  1. Initial program 42.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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}} \]
    6. neg-mul-195.8%

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

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

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

Alternative 2: 89.2% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.6 \cdot 10^{-28} \lor \neg \left(a \leq 2.05 \cdot 10^{-52}\right):\\
\;\;\;\;\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} - \sqrt[3]{\frac{g}{a}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -1.59999999999999991e-28 or 2.04999999999999994e-52 < a

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

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

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

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

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

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

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

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

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

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

    if -1.59999999999999991e-28 < a < 2.04999999999999994e-52

    1. Initial program 36.6%

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{0}{0}}{a}\right)} - 1}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    9. Simplified46.5%

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

      \[\leadsto \sqrt[3]{-1} + \color{blue}{\frac{\sqrt[3]{-g}}{\sqrt[3]{a}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.6 \cdot 10^{-28} \lor \neg \left(a \leq 2.05 \cdot 10^{-52}\right):\\ \;\;\;\;\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} - \sqrt[3]{\frac{g}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{-1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 62.1% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.4 \cdot 10^{-41} \lor \neg \left(a \leq 2.8 \cdot 10^{-23}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \frac{-1}{\sqrt[3]{a}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -1.4000000000000001e-41 or 2.7999999999999997e-23 < a

    1. Initial program 45.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. Simplified45.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. Add Preprocessing
    4. Taylor expanded in g around -inf 26.4%

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

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

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

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

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

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

    if -1.4000000000000001e-41 < a < 2.7999999999999997e-23

    1. Initial program 38.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.4 \cdot 10^{-41} \lor \neg \left(a \leq 2.8 \cdot 10^{-23}\right):\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \frac{-1}{\sqrt[3]{a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{g} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 47.4% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;g \leq -1.75 \cdot 10^{+41} \lor \neg \left(g \leq 2.4 \cdot 10^{+21}\right):\\
\;\;\;\;\sqrt[3]{-1} + \sqrt[3]{\frac{g}{-a}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if g < -1.75e41 or 2.4e21 < g

    1. Initial program 28.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. Simplified28.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 g around -inf 18.7%

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{0}{0}}{a}\right)} - 1}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    9. Simplified50.3%

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

      \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{-1 \cdot \frac{g}{a}}} \]
    11. Step-by-step derivation
      1. associate-*r/50.7%

        \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{\frac{-1 \cdot g}{a}}} \]
      2. mul-1-neg50.7%

        \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\frac{\color{blue}{-g}}{a}} \]
    12. Simplified50.7%

      \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{\frac{-g}{a}}} \]

    if -1.75e41 < g < 2.4e21

    1. Initial program 70.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. Simplified70.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 g around -inf 39.6%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;g \leq -1.75 \cdot 10^{+41} \lor \neg \left(g \leq 2.4 \cdot 10^{+21}\right):\\ \;\;\;\;\sqrt[3]{-1} + \sqrt[3]{\frac{g}{-a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} - \sqrt[3]{g}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 47.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;g \leq -0.059 \lor \neg \left(g \leq 9\right):\\
\;\;\;\;\sqrt[3]{-1} + \sqrt[3]{\frac{g}{-a}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g} + \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 < -0.058999999999999997 or 9 < g

    1. Initial program 32.6%

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{0}{0}}{a}\right)} - 1}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
    9. Simplified49.9%

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

      \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{-1 \cdot \frac{g}{a}}} \]
    11. Step-by-step derivation
      1. associate-*r/50.3%

        \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{\frac{-1 \cdot g}{a}}} \]
      2. mul-1-neg50.3%

        \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\frac{\color{blue}{-g}}{a}} \]
    12. Simplified50.3%

      \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{\frac{-g}{a}}} \]

    if -0.058999999999999997 < g < 9

    1. Initial program 66.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. Simplified66.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. Add Preprocessing
    4. Taylor expanded in g around -inf 37.8%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;g \leq -0.059 \lor \neg \left(g \leq 9\right):\\ \;\;\;\;\sqrt[3]{-1} + \sqrt[3]{\frac{g}{-a}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{g} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 72.9% accurate, 2.0× speedup?

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

\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot 0}
\end{array}
Derivation
  1. Initial program 42.6%

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\color{blue}{\left(g + -1 \cdot g\right)} \cdot \frac{-0.5}{a}} \]
  11. Step-by-step derivation
    1. distribute-rgt1-in69.9%

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

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

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

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

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

Alternative 7: 73.0% accurate, 2.1× speedup?

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

\\
\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} - \sqrt[3]{\frac{g}{a}}
\end{array}
Derivation
  1. Initial program 42.6%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} - \sqrt[3]{\frac{g}{a}} \]
  14. Add Preprocessing

Alternative 8: 44.1% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt[3]{\color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{0}{0}}{a}\right)} - 1}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
  9. Simplified41.8%

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

    \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{-1 \cdot \frac{g}{a}}} \]
  11. Step-by-step derivation
    1. associate-*r/42.0%

      \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{\frac{-1 \cdot g}{a}}} \]
    2. mul-1-neg42.0%

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

    \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\color{blue}{\frac{-g}{a}}} \]
  13. Final simplification42.0%

    \[\leadsto \sqrt[3]{-1} + \sqrt[3]{\frac{g}{-a}} \]
  14. Add Preprocessing

Alternative 9: 5.4% accurate, 4.1× speedup?

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

\\
1 + \sqrt[3]{g \cdot \left(-a\right)}
\end{array}
Derivation
  1. Initial program 42.6%

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

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

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

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

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

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

    \[\leadsto \sqrt[3]{\color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{0}{0}}{a}\right)} - 1}} + \sqrt[3]{\left(g + g\right) \cdot \frac{-0.5}{a}} \]
  9. Simplified41.8%

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt[3]{\left(2 \cdot g\right) \cdot \left(-0.5 \cdot a\right)}\right)}} \]
  11. Step-by-step derivation
    1. log1p-undefine3.4%

      \[\leadsto e^{\color{blue}{\log \left(1 + \sqrt[3]{\left(2 \cdot g\right) \cdot \left(-0.5 \cdot a\right)}\right)}} \]
    2. metadata-eval3.4%

      \[\leadsto e^{\log \left(\color{blue}{-1 \cdot -1} + \sqrt[3]{\left(2 \cdot g\right) \cdot \left(-0.5 \cdot a\right)}\right)} \]
    3. fma-undefine3.4%

      \[\leadsto e^{\log \color{blue}{\left(\mathsf{fma}\left(-1, -1, \sqrt[3]{\left(2 \cdot g\right) \cdot \left(-0.5 \cdot a\right)}\right)\right)}} \]
    4. rem-exp-log5.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, -1, \sqrt[3]{\left(2 \cdot g\right) \cdot \left(-0.5 \cdot a\right)}\right)} \]
    5. fma-undefine5.4%

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

      \[\leadsto \color{blue}{1} + \sqrt[3]{\left(2 \cdot g\right) \cdot \left(-0.5 \cdot a\right)} \]
    7. *-commutative5.4%

      \[\leadsto 1 + \sqrt[3]{\color{blue}{\left(-0.5 \cdot a\right) \cdot \left(2 \cdot g\right)}} \]
    8. *-commutative5.4%

      \[\leadsto 1 + \sqrt[3]{\color{blue}{\left(a \cdot -0.5\right)} \cdot \left(2 \cdot g\right)} \]
    9. associate-*l*5.4%

      \[\leadsto 1 + \sqrt[3]{\color{blue}{a \cdot \left(-0.5 \cdot \left(2 \cdot g\right)\right)}} \]
    10. associate-*r*5.4%

      \[\leadsto 1 + \sqrt[3]{a \cdot \color{blue}{\left(\left(-0.5 \cdot 2\right) \cdot g\right)}} \]
    11. metadata-eval5.4%

      \[\leadsto 1 + \sqrt[3]{a \cdot \left(\color{blue}{-1} \cdot g\right)} \]
    12. mul-1-neg5.4%

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

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

    \[\leadsto 1 + \sqrt[3]{g \cdot \left(-a\right)} \]
  14. Add Preprocessing

Reproduce

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