2-ancestry mixing, zero discriminant

Percentage Accurate: 77.0% → 98.7%
Time: 2.4s
Alternatives: 5
Speedup: 0.6×

Specification

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

\\
\sqrt[3]{\frac{g}{2 \cdot a}}
\end{array}

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 5 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: 77.0% accurate, 1.0× speedup?

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

\\
\sqrt[3]{\frac{g}{2 \cdot a}}
\end{array}

Alternative 1: 98.7% accurate, 0.6× speedup?

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

\\
\frac{\sqrt[3]{0.5 \cdot g}}{\sqrt[3]{a}}
\end{array}
Derivation
  1. Initial program 77.0%

    \[\sqrt[3]{\frac{g}{2 \cdot a}} \]
  2. Step-by-step derivation
    1. lift-cbrt.f64N/A

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{2 \cdot a}}} \]
    2. lift-*.f64N/A

      \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{2 \cdot a}}} \]
    3. lift-/.f64N/A

      \[\leadsto \sqrt[3]{\color{blue}{\frac{g}{2 \cdot a}}} \]
    4. mult-flipN/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sqrt[3]{\color{blue}{\frac{g}{2}}}}{\sqrt[3]{a}} \]
    14. lower-cbrt.f64N/A

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\frac{g}{2}}}}{\sqrt[3]{a}} \]
    15. mult-flipN/A

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

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

      \[\leadsto \frac{\sqrt[3]{\color{blue}{\frac{1}{2} \cdot g}}}{\sqrt[3]{a}} \]
    18. lower-*.f64N/A

      \[\leadsto \frac{\sqrt[3]{\color{blue}{\frac{1}{2} \cdot g}}}{\sqrt[3]{a}} \]
    19. lower-cbrt.f6498.7

      \[\leadsto \frac{\sqrt[3]{0.5 \cdot g}}{\color{blue}{\sqrt[3]{a}}} \]
  3. Applied rewrites98.7%

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

Alternative 2: 98.7% accurate, 0.6× speedup?

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

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

    \[\sqrt[3]{\frac{g}{2 \cdot a}} \]
  2. Step-by-step derivation
    1. lift-cbrt.f64N/A

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{2 \cdot a}}} \]
    2. lift-*.f64N/A

      \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{2 \cdot a}}} \]
    3. lift-/.f64N/A

      \[\leadsto \sqrt[3]{\color{blue}{\frac{g}{2 \cdot a}}} \]
    4. cbrt-divN/A

      \[\leadsto \color{blue}{\frac{\sqrt[3]{g}}{\sqrt[3]{2 \cdot a}}} \]
    5. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\sqrt[3]{g}}{\sqrt[3]{2 \cdot a}}} \]
    6. lower-cbrt.f64N/A

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

      \[\leadsto \frac{\sqrt[3]{g}}{\color{blue}{\sqrt[3]{2 \cdot a}}} \]
    8. count-2-revN/A

      \[\leadsto \frac{\sqrt[3]{g}}{\sqrt[3]{\color{blue}{a + a}}} \]
    9. lower-+.f6498.7

      \[\leadsto \frac{\sqrt[3]{g}}{\sqrt[3]{\color{blue}{a + a}}} \]
  3. Applied rewrites98.7%

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

Alternative 3: 77.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt[3]{\frac{g}{2 \cdot a}}\\ t_1 := e^{\left(\log g - \log \left(a + a\right)\right) \cdot 0.3333333333333333}\\ \mathbf{if}\;t\_0 \leq 2 \cdot 10^{-104}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+102}:\\ \;\;\;\;\sqrt[3]{\frac{g}{a + a}}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (g a)
 :precision binary64
 (let* ((t_0 (cbrt (/ g (* 2.0 a))))
        (t_1 (exp (* (- (log g) (log (+ a a))) 0.3333333333333333))))
   (if (<= t_0 2e-104) t_1 (if (<= t_0 4e+102) (cbrt (/ g (+ a a))) t_1))))
double code(double g, double a) {
	double t_0 = cbrt((g / (2.0 * a)));
	double t_1 = exp(((log(g) - log((a + a))) * 0.3333333333333333));
	double tmp;
	if (t_0 <= 2e-104) {
		tmp = t_1;
	} else if (t_0 <= 4e+102) {
		tmp = cbrt((g / (a + a)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double g, double a) {
	double t_0 = Math.cbrt((g / (2.0 * a)));
	double t_1 = Math.exp(((Math.log(g) - Math.log((a + a))) * 0.3333333333333333));
	double tmp;
	if (t_0 <= 2e-104) {
		tmp = t_1;
	} else if (t_0 <= 4e+102) {
		tmp = Math.cbrt((g / (a + a)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(g, a)
	t_0 = cbrt(Float64(g / Float64(2.0 * a)))
	t_1 = exp(Float64(Float64(log(g) - log(Float64(a + a))) * 0.3333333333333333))
	tmp = 0.0
	if (t_0 <= 2e-104)
		tmp = t_1;
	elseif (t_0 <= 4e+102)
		tmp = cbrt(Float64(g / Float64(a + a)));
	else
		tmp = t_1;
	end
	return tmp
end
code[g_, a_] := Block[{t$95$0 = N[Power[N[(g / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(N[(N[Log[g], $MachinePrecision] - N[Log[N[(a + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 2e-104], t$95$1, If[LessEqual[t$95$0, 4e+102], N[Power[N[(g / N[(a + a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{g}{2 \cdot a}}\\
t_1 := e^{\left(\log g - \log \left(a + a\right)\right) \cdot 0.3333333333333333}\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{-104}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+102}:\\
\;\;\;\;\sqrt[3]{\frac{g}{a + a}}\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cbrt.f64 (/.f64 g (*.f64 #s(literal 2 binary64) a))) < 1.99999999999999985e-104 or 3.99999999999999991e102 < (cbrt.f64 (/.f64 g (*.f64 #s(literal 2 binary64) a)))

    1. Initial program 77.0%

      \[\sqrt[3]{\frac{g}{2 \cdot a}} \]
    2. Step-by-step derivation
      1. lift-cbrt.f64N/A

        \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{2 \cdot a}}} \]
      2. lift-*.f64N/A

        \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{2 \cdot a}}} \]
      3. lift-/.f64N/A

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

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

        \[\leadsto \color{blue}{e^{\log \left(\frac{g}{2 \cdot a}\right) \cdot \frac{1}{3}}} \]
      6. lower-exp.f64N/A

        \[\leadsto \color{blue}{e^{\log \left(\frac{g}{2 \cdot a}\right) \cdot \frac{1}{3}}} \]
      7. lower-*.f64N/A

        \[\leadsto e^{\color{blue}{\log \left(\frac{g}{2 \cdot a}\right) \cdot \frac{1}{3}}} \]
      8. lower-log.f64N/A

        \[\leadsto e^{\color{blue}{\log \left(\frac{g}{2 \cdot a}\right)} \cdot \frac{1}{3}} \]
      9. lift-/.f64N/A

        \[\leadsto e^{\log \color{blue}{\left(\frac{g}{2 \cdot a}\right)} \cdot \frac{1}{3}} \]
      10. count-2-revN/A

        \[\leadsto e^{\log \left(\frac{g}{\color{blue}{a + a}}\right) \cdot \frac{1}{3}} \]
      11. lower-+.f6437.1

        \[\leadsto e^{\log \left(\frac{g}{\color{blue}{a + a}}\right) \cdot 0.3333333333333333} \]
    3. Applied rewrites37.1%

      \[\leadsto \color{blue}{e^{\log \left(\frac{g}{a + a}\right) \cdot 0.3333333333333333}} \]
    4. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto e^{\color{blue}{\log \left(\frac{g}{a + a}\right)} \cdot \frac{1}{3}} \]
      2. lift-+.f64N/A

        \[\leadsto e^{\log \left(\frac{g}{\color{blue}{a + a}}\right) \cdot \frac{1}{3}} \]
      3. lift-/.f64N/A

        \[\leadsto e^{\log \color{blue}{\left(\frac{g}{a + a}\right)} \cdot \frac{1}{3}} \]
      4. log-divN/A

        \[\leadsto e^{\color{blue}{\left(\log g - \log \left(a + a\right)\right)} \cdot \frac{1}{3}} \]
      5. lower--.f64N/A

        \[\leadsto e^{\color{blue}{\left(\log g - \log \left(a + a\right)\right)} \cdot \frac{1}{3}} \]
      6. lower-log.f64N/A

        \[\leadsto e^{\left(\color{blue}{\log g} - \log \left(a + a\right)\right) \cdot \frac{1}{3}} \]
      7. lower-log.f64N/A

        \[\leadsto e^{\left(\log g - \color{blue}{\log \left(a + a\right)}\right) \cdot \frac{1}{3}} \]
      8. lift-+.f6423.7

        \[\leadsto e^{\left(\log g - \log \color{blue}{\left(a + a\right)}\right) \cdot 0.3333333333333333} \]
    5. Applied rewrites23.7%

      \[\leadsto e^{\color{blue}{\left(\log g - \log \left(a + a\right)\right)} \cdot 0.3333333333333333} \]

    if 1.99999999999999985e-104 < (cbrt.f64 (/.f64 g (*.f64 #s(literal 2 binary64) a))) < 3.99999999999999991e102

    1. Initial program 77.0%

      \[\sqrt[3]{\frac{g}{2 \cdot a}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{2 \cdot a}}} \]
      2. count-2-revN/A

        \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{a + a}}} \]
      3. lower-+.f6477.0

        \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{a + a}}} \]
    3. Applied rewrites77.0%

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{a + a}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 76.9% accurate, 0.9× speedup?

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

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

    \[\sqrt[3]{\frac{g}{2 \cdot a}} \]
  2. Step-by-step derivation
    1. lift-cbrt.f64N/A

      \[\leadsto \color{blue}{\sqrt[3]{\frac{g}{2 \cdot a}}} \]
    2. lift-*.f64N/A

      \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{2 \cdot a}}} \]
    3. lift-/.f64N/A

      \[\leadsto \sqrt[3]{\color{blue}{\frac{g}{2 \cdot a}}} \]
    4. div-flipN/A

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt[3]{\frac{2 \cdot a}{g}}}} \]
    8. lower-cbrt.f64N/A

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

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

      \[\leadsto \frac{1}{\sqrt[3]{\frac{\color{blue}{a + a}}{g}}} \]
    11. lower-+.f6476.9

      \[\leadsto \frac{1}{\sqrt[3]{\frac{\color{blue}{a + a}}{g}}} \]
  3. Applied rewrites76.9%

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

Alternative 5: 44.1% accurate, 1.0× speedup?

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

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

    \[\sqrt[3]{\frac{g}{2 \cdot a}} \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{2 \cdot a}}} \]
    2. count-2-revN/A

      \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{a + a}}} \]
    3. lower-+.f6477.0

      \[\leadsto \sqrt[3]{\frac{g}{\color{blue}{a + a}}} \]
  3. Applied rewrites77.0%

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

Reproduce

?
herbie shell --seed 2025139 
(FPCore (g a)
  :name "2-ancestry mixing, zero discriminant"
  :precision binary64
  (cbrt (/ g (* 2.0 a))))