2-ancestry mixing, positive discriminant

Percentage Accurate: 43.9% → 95.8%
Time: 18.8s
Alternatives: 6
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 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 95.8% accurate, 2.1× speedup?

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

\\
\sqrt[3]{g} \cdot \sqrt[3]{\frac{-1}{a}}
\end{array}
Derivation
  1. Initial program 39.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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\sqrt[3]{g}}{\sqrt[3]{0 - a}}} \]
  7. Step-by-step derivation
    1. cbrt-undivN/A

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

      \[\leadsto \sqrt[3]{\frac{g}{\mathsf{neg}\left(a\right)}} \]
    3. div-invN/A

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(g\right), \mathsf{cbrt.f64}\left(\left(\frac{1}{\mathsf{neg}\left(a\right)}\right)\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(g\right), \mathsf{cbrt.f64}\left(\left(\frac{\mathsf{neg}\left(-1\right)}{\mathsf{neg}\left(a\right)}\right)\right)\right) \]
    9. frac-2negN/A

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

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

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

Alternative 2: 95.8% accurate, 2.1× speedup?

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

\\
\frac{\sqrt[3]{g}}{\sqrt[3]{0 - a}}
\end{array}
Derivation
  1. Initial program 39.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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cbrt.f64}\left(g\right), \mathsf{cbrt.f64}\left(\left(\mathsf{neg}\left(a\right)\right)\right)\right) \]
    2. neg-lowering-neg.f6496.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cbrt.f64}\left(g\right), \mathsf{cbrt.f64}\left(\mathsf{neg.f64}\left(a\right)\right)\right) \]
  8. Applied egg-rr96.5%

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

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

Alternative 3: 73.5% accurate, 4.0× speedup?

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

\\
0 - \sqrt[3]{g \cdot \frac{1}{a}}
\end{array}
Derivation
  1. Initial program 39.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. Step-by-step derivation
    1. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(\mathsf{neg}\left(g\right)\right) + \sqrt{g \cdot g - h \cdot h}\right)}\right), \color{blue}{\left(\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(\mathsf{neg}\left(g\right)\right) - \sqrt{g \cdot g - h \cdot h}\right)}\right)}\right) \]
  3. Simplified39.7%

    \[\leadsto \color{blue}{\sqrt[3]{\frac{\sqrt{g \cdot g - h \cdot h} - g}{2 \cdot a}} + \sqrt[3]{\frac{\frac{g + \sqrt{g \cdot g - h \cdot h}}{-2}}{a}}} \]
  4. Add Preprocessing
  5. Taylor expanded in g around -inf

    \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{g}{a}\right)}\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right), a\right)\right)\right) \]
  6. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\left(\mathsf{neg}\left(\frac{g}{a}\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right)}, a\right)\right)\right) \]
    2. neg-sub0N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{\_.f64}\left(0, \left(\frac{g}{a}\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right)}, a\right)\right)\right) \]
    4. /-lowering-/.f6423.6%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(g, a\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), \color{blue}{-2}\right), a\right)\right)\right) \]
  7. Simplified23.6%

    \[\leadsto \sqrt[3]{\color{blue}{0 - \frac{g}{a}}} + \sqrt[3]{\frac{\frac{g + \sqrt{g \cdot g - h \cdot h}}{-2}}{a}} \]
  8. Taylor expanded in g around -inf

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right)\right) \]
  10. Simplified75.8%

    \[\leadsto \color{blue}{-\sqrt[3]{\frac{g}{a}}} \]
  11. Step-by-step derivation
    1. div-invN/A

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{a}\right), g\right)\right)\right) \]
    4. metadata-evalN/A

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(-1\right)\right), a\right), g\right)\right)\right) \]
    6. metadata-eval75.8%

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, a\right), g\right)\right)\right) \]
  12. Applied egg-rr75.8%

    \[\leadsto -\sqrt[3]{\color{blue}{\frac{1}{a} \cdot g}} \]
  13. Final simplification75.8%

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

Alternative 4: 74.1% accurate, 4.1× speedup?

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

\\
\frac{-1}{\sqrt[3]{\frac{a}{g}}}
\end{array}
Derivation
  1. Initial program 39.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. Step-by-step derivation
    1. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(\mathsf{neg}\left(g\right)\right) + \sqrt{g \cdot g - h \cdot h}\right)}\right), \color{blue}{\left(\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(\mathsf{neg}\left(g\right)\right) - \sqrt{g \cdot g - h \cdot h}\right)}\right)}\right) \]
  3. Simplified39.7%

    \[\leadsto \color{blue}{\sqrt[3]{\frac{\sqrt{g \cdot g - h \cdot h} - g}{2 \cdot a}} + \sqrt[3]{\frac{\frac{g + \sqrt{g \cdot g - h \cdot h}}{-2}}{a}}} \]
  4. Add Preprocessing
  5. Taylor expanded in g around -inf

    \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{g}{a}\right)}\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right), a\right)\right)\right) \]
  6. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\left(\mathsf{neg}\left(\frac{g}{a}\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right)}, a\right)\right)\right) \]
    2. neg-sub0N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{\_.f64}\left(0, \left(\frac{g}{a}\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right)}, a\right)\right)\right) \]
    4. /-lowering-/.f6423.6%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(g, a\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), \color{blue}{-2}\right), a\right)\right)\right) \]
  7. Simplified23.6%

    \[\leadsto \sqrt[3]{\color{blue}{0 - \frac{g}{a}}} + \sqrt[3]{\frac{\frac{g + \sqrt{g \cdot g - h \cdot h}}{-2}}{a}} \]
  8. Taylor expanded in g around -inf

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right)\right) \]
  10. Simplified75.8%

    \[\leadsto \color{blue}{-\sqrt[3]{\frac{g}{a}}} \]
  11. Step-by-step derivation
    1. cbrt-divN/A

      \[\leadsto \mathsf{neg.f64}\left(\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}}\right)\right) \]
    2. clear-numN/A

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

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{/.f64}\left(1, \mathsf{cbrt.f64}\left(\left(\frac{a}{g}\right)\right)\right)\right) \]
    8. /-lowering-/.f6477.1%

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{/.f64}\left(1, \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(a, g\right)\right)\right)\right) \]
  12. Applied egg-rr77.1%

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

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

Alternative 5: 73.6% accurate, 4.1× speedup?

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

\\
0 - \sqrt[3]{\frac{g}{a}}
\end{array}
Derivation
  1. Initial program 39.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. Step-by-step derivation
    1. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(\mathsf{neg}\left(g\right)\right) + \sqrt{g \cdot g - h \cdot h}\right)}\right), \color{blue}{\left(\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(\mathsf{neg}\left(g\right)\right) - \sqrt{g \cdot g - h \cdot h}\right)}\right)}\right) \]
  3. Simplified39.7%

    \[\leadsto \color{blue}{\sqrt[3]{\frac{\sqrt{g \cdot g - h \cdot h} - g}{2 \cdot a}} + \sqrt[3]{\frac{\frac{g + \sqrt{g \cdot g - h \cdot h}}{-2}}{a}}} \]
  4. Add Preprocessing
  5. Taylor expanded in g around -inf

    \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{g}{a}\right)}\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right), a\right)\right)\right) \]
  6. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\left(\mathsf{neg}\left(\frac{g}{a}\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right)}, a\right)\right)\right) \]
    2. neg-sub0N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{\_.f64}\left(0, \left(\frac{g}{a}\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), -2\right)}, a\right)\right)\right) \]
    4. /-lowering-/.f6423.6%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(g, a\right)\right)\right), \mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(g, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(g, g\right), \mathsf{*.f64}\left(h, h\right)\right)\right)\right), \color{blue}{-2}\right), a\right)\right)\right) \]
  7. Simplified23.6%

    \[\leadsto \sqrt[3]{\color{blue}{0 - \frac{g}{a}}} + \sqrt[3]{\frac{\frac{g + \sqrt{g \cdot g - h \cdot h}}{-2}}{a}} \]
  8. Taylor expanded in g around -inf

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right)\right) \]
  10. Simplified75.8%

    \[\leadsto \color{blue}{-\sqrt[3]{\frac{g}{a}}} \]
  11. Final simplification75.8%

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

Alternative 6: 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 39.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. *-lowering-*.f64N/A

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\mathsf{/.f64}\left(g, a\right)\right), \mathsf{*.f64}\left(\mathsf{cbrt.f64}\left(\frac{-1}{2}\right), \mathsf{cbrt.f64}\left(2\right)\right)\right) \]
  5. Simplified75.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. *-commutativeN/A

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

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

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

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

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

      \[\leadsto {\left(-1 \cdot \frac{g}{a}\right)}^{\frac{1}{3}} \]
    7. neg-mul-1N/A

      \[\leadsto {\left(\mathsf{neg}\left(\frac{g}{a}\right)\right)}^{\frac{1}{3}} \]
    8. div-invN/A

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

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

      \[\leadsto {\left(\left(0 - g\right) \cdot \frac{1}{a}\right)}^{\frac{1}{3}} \]
    11. unpow-prod-downN/A

      \[\leadsto {\left(0 - g\right)}^{\frac{1}{3}} \cdot \color{blue}{{\left(\frac{1}{a}\right)}^{\frac{1}{3}}} \]
  7. Applied egg-rr1.4%

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

Reproduce

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