2-ancestry mixing, positive discriminant

Percentage Accurate: 44.0% → 95.8%
Time: 12.5s
Alternatives: 4
Speedup: 4.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 4 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.0% 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, 2.1× speedup?

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

\\
\frac{0 - \sqrt[3]{g}}{\sqrt[3]{a}}
\end{array}
Derivation
  1. Initial program 44.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. Add Preprocessing
  3. Taylor expanded in g around -inf

    \[\leadsto \color{blue}{-1 \cdot \left(\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{2}\right)\right)} \]
  4. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{2}\right)\right) \]
    2. distribute-rgt-neg-inN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \color{blue}{\left(\mathsf{neg}\left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{2}\right)\right)} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\sqrt[3]{\frac{g}{a}}\right), \color{blue}{\left(\mathsf{neg}\left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{2}\right)\right)}\right) \]
    4. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\left(\frac{g}{a}\right)\right), \left(\mathsf{neg}\left(\color{blue}{\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{2}}\right)\right)\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \left(\mathsf{neg}\left(\color{blue}{\sqrt[3]{\frac{1}{2}}} \cdot \sqrt[3]{2}\right)\right)\right) \]
    6. neg-lowering-neg.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{neg.f64}\left(\left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{2}\right)\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(\sqrt[3]{\frac{1}{2}}\right), \left(\sqrt[3]{2}\right)\right)\right)\right) \]
    8. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\frac{1}{2}\right), \left(\sqrt[3]{2}\right)\right)\right)\right) \]
    9. cbrt-lowering-cbrt.f6478.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\frac{1}{2}\right), \mathsf{cbrt.f64}\left(2\right)\right)\right)\right) \]
  5. Simplified78.2%

    \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(-\sqrt[3]{0.5} \cdot \sqrt[3]{2}\right)} \]
  6. Step-by-step derivation
    1. cbrt-divN/A

      \[\leadsto \frac{\sqrt[3]{g}}{\sqrt[3]{a}} \cdot \left(\mathsf{neg}\left(\color{blue}{\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{2}}\right)\right) \]
    2. cbrt-unprodN/A

      \[\leadsto \frac{\sqrt[3]{g}}{\sqrt[3]{a}} \cdot \left(\mathsf{neg}\left(\sqrt[3]{\frac{1}{2} \cdot 2}\right)\right) \]
    3. metadata-evalN/A

      \[\leadsto \frac{\sqrt[3]{g}}{\sqrt[3]{a}} \cdot \left(\mathsf{neg}\left(\sqrt[3]{1}\right)\right) \]
    4. metadata-evalN/A

      \[\leadsto \frac{\sqrt[3]{g}}{\sqrt[3]{a}} \cdot \left(\mathsf{neg}\left(1\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \frac{\sqrt[3]{g}}{\sqrt[3]{a}} \cdot -1 \]
    6. associate-*l/N/A

      \[\leadsto \frac{\sqrt[3]{g} \cdot -1}{\color{blue}{\sqrt[3]{a}}} \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\sqrt[3]{g} \cdot -1\right), \color{blue}{\left(\sqrt[3]{a}\right)}\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(\sqrt[3]{g}\right), -1\right), \left(\sqrt[3]{\color{blue}{a}}\right)\right) \]
    9. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(g\right), -1\right), \left(\sqrt[3]{a}\right)\right) \]
    10. cbrt-lowering-cbrt.f6495.4%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(g\right), -1\right), \mathsf{cbrt.f64}\left(a\right)\right) \]
  7. Applied egg-rr95.4%

    \[\leadsto \color{blue}{\frac{\sqrt[3]{g} \cdot -1}{\sqrt[3]{a}}} \]
  8. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\left(-1 \cdot \sqrt[3]{g}\right), \mathsf{cbrt.f64}\left(\color{blue}{a}\right)\right) \]
    2. mul-1-negN/A

      \[\leadsto \mathsf{/.f64}\left(\left(\mathsf{neg}\left(\sqrt[3]{g}\right)\right), \mathsf{cbrt.f64}\left(\color{blue}{a}\right)\right) \]
    3. neg-lowering-neg.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{neg.f64}\left(\left(\sqrt[3]{g}\right)\right), \mathsf{cbrt.f64}\left(\color{blue}{a}\right)\right) \]
    4. cbrt-lowering-cbrt.f6495.4%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{neg.f64}\left(\mathsf{cbrt.f64}\left(g\right)\right), \mathsf{cbrt.f64}\left(a\right)\right) \]
  9. Applied egg-rr95.4%

    \[\leadsto \frac{\color{blue}{-\sqrt[3]{g}}}{\sqrt[3]{a}} \]
  10. Final simplification95.4%

    \[\leadsto \frac{0 - \sqrt[3]{g}}{\sqrt[3]{a}} \]
  11. Add Preprocessing

Alternative 2: 74.1% accurate, 4.0× speedup?

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

\\
\frac{1}{\sqrt[3]{\frac{a}{0 - g}}}
\end{array}
Derivation
  1. Initial program 44.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. Add Preprocessing
  3. Taylor expanded in g around inf

    \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{2}\right)} \]
  4. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \left(\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{-1}{2}}\right) \cdot \color{blue}{\sqrt[3]{2}} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{-1}{2}}\right), \color{blue}{\left(\sqrt[3]{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\sqrt[3]{\frac{g}{a}}\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{\color{blue}{2}}\right)\right) \]
    4. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\left(\frac{g}{a}\right)\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    6. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{cbrt.f64}\left(\frac{-1}{2}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    7. cbrt-lowering-cbrt.f6478.0%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{cbrt.f64}\left(\frac{-1}{2}\right)\right), \mathsf{cbrt.f64}\left(2\right)\right) \]
  5. Simplified78.0%

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

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \color{blue}{\left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{2}\right)} \]
    2. pow1/3N/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{-1}{2}}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    3. sqr-powN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\left({\frac{-1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot {\frac{-1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)}\right) \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    4. pow-prod-downN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\left(\frac{-1}{2} \cdot \frac{-1}{2}\right)}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    5. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{1}{4}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{2}\right) \]
    6. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\left(\frac{1}{2} \cdot \frac{1}{2}\right)}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{2}\right) \]
    7. pow-prod-downN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\left({\frac{1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot {\frac{1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)}\right) \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    8. sqr-powN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{1}{2}}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    9. pow1/3N/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    10. cbrt-unprodN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{1}{2} \cdot 2} \]
    11. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{1} \]
    12. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot 1 \]
    13. *-rgt-identityN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \]
    14. clear-numN/A

      \[\leadsto \sqrt[3]{\frac{1}{\frac{a}{g}}} \]
    15. frac-2negN/A

      \[\leadsto \sqrt[3]{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\frac{a}{g}\right)}} \]
    16. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{-1}{\mathsf{neg}\left(\frac{a}{g}\right)}} \]
    17. cbrt-divN/A

      \[\leadsto \frac{\sqrt[3]{-1}}{\color{blue}{\sqrt[3]{\mathsf{neg}\left(\frac{a}{g}\right)}}} \]
  7. Applied egg-rr79.9%

    \[\leadsto \color{blue}{\frac{1}{\sqrt[3]{-\frac{a}{g}}}} \]
  8. Final simplification79.9%

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

Alternative 3: 73.3% accurate, 4.1× speedup?

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

\\
\sqrt[3]{0 - \frac{g}{a}}
\end{array}
Derivation
  1. Initial program 44.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. Add Preprocessing
  3. Taylor expanded in g around inf

    \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{2}\right)} \]
  4. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \left(\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{-1}{2}}\right) \cdot \color{blue}{\sqrt[3]{2}} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{-1}{2}}\right), \color{blue}{\left(\sqrt[3]{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\sqrt[3]{\frac{g}{a}}\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{\color{blue}{2}}\right)\right) \]
    4. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\left(\frac{g}{a}\right)\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    6. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{cbrt.f64}\left(\frac{-1}{2}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    7. cbrt-lowering-cbrt.f6478.0%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{cbrt.f64}\left(\frac{-1}{2}\right)\right), \mathsf{cbrt.f64}\left(2\right)\right) \]
  5. Simplified78.0%

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

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \color{blue}{\left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{2}\right)} \]
    2. pow1/3N/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{-1}{2}}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    3. sqr-powN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\left({\frac{-1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot {\frac{-1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)}\right) \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    4. pow-prod-downN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\left(\frac{-1}{2} \cdot \frac{-1}{2}\right)}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    5. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{1}{4}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{2}\right) \]
    6. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\left(\frac{1}{2} \cdot \frac{1}{2}\right)}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{2}\right) \]
    7. pow-prod-downN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\left({\frac{1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot {\frac{1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)}\right) \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    8. sqr-powN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{1}{2}}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    9. pow1/3N/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    10. cbrt-unprodN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{1}{2} \cdot 2} \]
    11. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{1} \]
    12. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot 1 \]
    13. *-rgt-identityN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \]
    14. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left(\frac{g}{a}\right)\right) \]
    15. /-lowering-/.f641.4%

      \[\leadsto \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right) \]
  7. Applied egg-rr1.4%

    \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}}} \]
  8. Step-by-step derivation
    1. frac-2negN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left(\frac{\mathsf{neg}\left(g\right)}{\mathsf{neg}\left(a\right)}\right)\right) \]
    2. neg-mul-1N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left(\frac{-1 \cdot g}{\mathsf{neg}\left(a\right)}\right)\right) \]
    3. associate-/l*N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left(-1 \cdot \frac{g}{\mathsf{neg}\left(a\right)}\right)\right) \]
    4. distribute-neg-frac2N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left(-1 \cdot \left(\mathsf{neg}\left(\frac{g}{a}\right)\right)\right)\right) \]
    5. sub0-negN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left(-1 \cdot \left(0 - \frac{g}{a}\right)\right)\right) \]
    6. metadata-evalN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \left(0 - \frac{g}{a}\right)\right)\right) \]
    7. flip3--N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{{0}^{3} - {\left(\frac{g}{a}\right)}^{3}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{0 - {\left(\frac{g}{a}\right)}^{3}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    9. sub0-negN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\mathsf{neg}\left({\left(\frac{g}{a}\right)}^{3}\right)}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    10. cube-negN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{{\left(\mathsf{neg}\left(\frac{g}{a}\right)\right)}^{3}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    11. distribute-neg-fracN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{{\left(\frac{\mathsf{neg}\left(g\right)}{a}\right)}^{3}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    12. cube-divN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{\left(\mathsf{neg}\left(g\right)\right)}^{3}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    13. metadata-evalN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{\left(\mathsf{neg}\left(g\right)\right)}^{\left(2 \cdot \frac{3}{2}\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    14. metadata-evalN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{\left(\mathsf{neg}\left(g\right)\right)}^{\left(2 \cdot \left(\frac{1}{2} \cdot 3\right)\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    15. pow-powN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{\left({\left(\mathsf{neg}\left(g\right)\right)}^{2}\right)}^{\left(\frac{1}{2} \cdot 3\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    16. pow2N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{\left(\left(\mathsf{neg}\left(g\right)\right) \cdot \left(\mathsf{neg}\left(g\right)\right)\right)}^{\left(\frac{1}{2} \cdot 3\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    17. sqr-negN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{\left(g \cdot g\right)}^{\left(\frac{1}{2} \cdot 3\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    18. pow2N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{\left({g}^{2}\right)}^{\left(\frac{1}{2} \cdot 3\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    19. pow-powN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{g}^{\left(2 \cdot \left(\frac{1}{2} \cdot 3\right)\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    20. metadata-evalN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{g}^{\left(2 \cdot \frac{3}{2}\right)}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    21. metadata-evalN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{\frac{{g}^{3}}{{a}^{3}}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    22. cube-divN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{{\left(\frac{g}{a}\right)}^{3}}{0 \cdot 0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
    23. metadata-evalN/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left({-1}^{1} \cdot \frac{{\left(\frac{g}{a}\right)}^{3}}{0 + \left(\frac{g}{a} \cdot \frac{g}{a} + 0 \cdot \frac{g}{a}\right)}\right)\right) \]
  9. Applied egg-rr78.9%

    \[\leadsto \sqrt[3]{\color{blue}{-\frac{g}{a}}} \]
  10. Final simplification78.9%

    \[\leadsto \sqrt[3]{0 - \frac{g}{a}} \]
  11. Add Preprocessing

Alternative 4: 1.4% accurate, 4.2× speedup?

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

\\
\sqrt[3]{\frac{g}{a}}
\end{array}
Derivation
  1. Initial program 44.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. Add Preprocessing
  3. Taylor expanded in g around inf

    \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{2}\right)} \]
  4. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \left(\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{-1}{2}}\right) \cdot \color{blue}{\sqrt[3]{2}} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{-1}{2}}\right), \color{blue}{\left(\sqrt[3]{2}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\sqrt[3]{\frac{g}{a}}\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{\color{blue}{2}}\right)\right) \]
    4. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\left(\frac{g}{a}\right)\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \left(\sqrt[3]{\frac{-1}{2}}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    6. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{cbrt.f64}\left(\frac{-1}{2}\right)\right), \left(\sqrt[3]{2}\right)\right) \]
    7. cbrt-lowering-cbrt.f6478.0%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{cbrt.f64}\left(\frac{-1}{2}\right)\right), \mathsf{cbrt.f64}\left(2\right)\right) \]
  5. Simplified78.0%

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

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \color{blue}{\left(\sqrt[3]{\frac{-1}{2}} \cdot \sqrt[3]{2}\right)} \]
    2. pow1/3N/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{-1}{2}}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    3. sqr-powN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\left({\frac{-1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot {\frac{-1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)}\right) \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    4. pow-prod-downN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\left(\frac{-1}{2} \cdot \frac{-1}{2}\right)}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    5. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{1}{4}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{2}\right) \]
    6. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\left(\frac{1}{2} \cdot \frac{1}{2}\right)}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot \sqrt[3]{2}\right) \]
    7. pow-prod-downN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\left({\frac{1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)} \cdot {\frac{1}{2}}^{\left(\frac{\frac{1}{3}}{2}\right)}\right) \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    8. sqr-powN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left({\frac{1}{2}}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    9. pow1/3N/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \left(\sqrt[3]{\frac{1}{2}} \cdot \sqrt[3]{\color{blue}{2}}\right) \]
    10. cbrt-unprodN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{\frac{1}{2} \cdot 2} \]
    11. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{1} \]
    12. metadata-evalN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \cdot 1 \]
    13. *-rgt-identityN/A

      \[\leadsto \sqrt[3]{\frac{g}{a}} \]
    14. cbrt-lowering-cbrt.f64N/A

      \[\leadsto \mathsf{cbrt.f64}\left(\left(\frac{g}{a}\right)\right) \]
    15. /-lowering-/.f641.4%

      \[\leadsto \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right) \]
  7. Applied egg-rr1.4%

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

Reproduce

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