Cubic critical, narrow range

Percentage Accurate: 55.3% → 99.1%
Time: 12.1s
Alternatives: 7
Speedup: 23.2×

Specification

?
\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\begin{array}{l} \\ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\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 7 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: 55.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}

Alternative 1: 99.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)}}}{a \cdot 3} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/
  (/ (* a (* c -3.0)) (+ b (sqrt (fma a (* c -3.0) (pow b 2.0)))))
  (* a 3.0)))
double code(double a, double b, double c) {
	return ((a * (c * -3.0)) / (b + sqrt(fma(a, (c * -3.0), pow(b, 2.0))))) / (a * 3.0);
}
function code(a, b, c)
	return Float64(Float64(Float64(a * Float64(c * -3.0)) / Float64(b + sqrt(fma(a, Float64(c * -3.0), (b ^ 2.0))))) / Float64(a * 3.0))
end
code[a_, b_, c_] := N[(N[(N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)}}}{a \cdot 3}
\end{array}
Derivation
  1. Initial program 52.3%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Step-by-step derivation
    1. expm1-log1p-u52.2%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(3 \cdot a\right) \cdot c\right)\right)}}}{3 \cdot a} \]
    2. expm1-udef49.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(e^{\mathsf{log1p}\left(\left(3 \cdot a\right) \cdot c\right)} - 1\right)}}}{3 \cdot a} \]
    3. associate-*l*49.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(\color{blue}{3 \cdot \left(a \cdot c\right)}\right)} - 1\right)}}{3 \cdot a} \]
  3. Applied egg-rr49.6%

    \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}}{3 \cdot a} \]
  4. Step-by-step derivation
    1. log1p-udef49.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(e^{\color{blue}{\log \left(1 + 3 \cdot \left(a \cdot c\right)\right)}} - 1\right)}}{3 \cdot a} \]
    2. rem-exp-log49.7%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\color{blue}{\left(1 + 3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}{3 \cdot a} \]
    3. associate-*r*49.7%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\left(1 + \color{blue}{\left(3 \cdot a\right) \cdot c}\right) - 1\right)}}{3 \cdot a} \]
    4. *-commutative49.7%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\left(1 + \color{blue}{\left(a \cdot 3\right)} \cdot c\right) - 1\right)}}{3 \cdot a} \]
  5. Applied egg-rr49.7%

    \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\color{blue}{\left(1 + \left(a \cdot 3\right) \cdot c\right)} - 1\right)}}{3 \cdot a} \]
  6. Step-by-step derivation
    1. +-commutative49.7%

      \[\leadsto \frac{\color{blue}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} + \left(-b\right)}}{3 \cdot a} \]
    2. flip-+49.6%

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} \cdot \sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}}{3 \cdot a} \]
    3. add-sqr-sqrt50.9%

      \[\leadsto \frac{\frac{\color{blue}{\left(b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)\right)} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    4. pow251.0%

      \[\leadsto \frac{\frac{\left(\color{blue}{{b}^{2}} - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)\right) - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    5. add-exp-log51.0%

      \[\leadsto \frac{\frac{\left({b}^{2} - \left(\color{blue}{e^{\log \left(1 + \left(a \cdot 3\right) \cdot c\right)}} - 1\right)\right) - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    6. log1p-udef51.0%

      \[\leadsto \frac{\frac{\left({b}^{2} - \left(e^{\color{blue}{\mathsf{log1p}\left(\left(a \cdot 3\right) \cdot c\right)}} - 1\right)\right) - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    7. expm1-udef52.5%

      \[\leadsto \frac{\frac{\left({b}^{2} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(a \cdot 3\right) \cdot c\right)\right)}\right) - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    8. expm1-log1p-u52.6%

      \[\leadsto \frac{\frac{\left({b}^{2} - \color{blue}{\left(a \cdot 3\right) \cdot c}\right) - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    9. associate-*l*52.6%

      \[\leadsto \frac{\frac{\left({b}^{2} - \color{blue}{a \cdot \left(3 \cdot c\right)}\right) - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    10. sqr-neg52.6%

      \[\leadsto \frac{\frac{\left({b}^{2} - a \cdot \left(3 \cdot c\right)\right) - \color{blue}{b \cdot b}}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    11. pow252.5%

      \[\leadsto \frac{\frac{\left({b}^{2} - a \cdot \left(3 \cdot c\right)\right) - \color{blue}{{b}^{2}}}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \left(-b\right)}}{3 \cdot a} \]
    12. add-sqr-sqrt0.0%

      \[\leadsto \frac{\frac{\left({b}^{2} - a \cdot \left(3 \cdot c\right)\right) - {b}^{2}}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \color{blue}{\sqrt{-b} \cdot \sqrt{-b}}}}{3 \cdot a} \]
    13. sqrt-unprod1.3%

      \[\leadsto \frac{\frac{\left({b}^{2} - a \cdot \left(3 \cdot c\right)\right) - {b}^{2}}{\sqrt{b \cdot b - \left(\left(1 + \left(a \cdot 3\right) \cdot c\right) - 1\right)} - \color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}}}}{3 \cdot a} \]
  7. Applied egg-rr53.6%

    \[\leadsto \frac{\color{blue}{\frac{\left({b}^{2} - a \cdot \left(3 \cdot c\right)\right) - {b}^{2}}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}}{3 \cdot a} \]
  8. Step-by-step derivation
    1. sub-neg53.6%

      \[\leadsto \frac{\frac{\color{blue}{\left({b}^{2} + \left(-a \cdot \left(3 \cdot c\right)\right)\right)} - {b}^{2}}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    2. +-commutative53.6%

      \[\leadsto \frac{\frac{\color{blue}{\left(\left(-a \cdot \left(3 \cdot c\right)\right) + {b}^{2}\right)} - {b}^{2}}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    3. associate--l+99.1%

      \[\leadsto \frac{\frac{\color{blue}{\left(-a \cdot \left(3 \cdot c\right)\right) + \left({b}^{2} - {b}^{2}\right)}}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    4. distribute-rgt-neg-in99.1%

      \[\leadsto \frac{\frac{\color{blue}{a \cdot \left(-3 \cdot c\right)} + \left({b}^{2} - {b}^{2}\right)}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    5. distribute-lft-neg-in99.1%

      \[\leadsto \frac{\frac{a \cdot \color{blue}{\left(\left(-3\right) \cdot c\right)} + \left({b}^{2} - {b}^{2}\right)}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    6. metadata-eval99.1%

      \[\leadsto \frac{\frac{a \cdot \left(\color{blue}{-3} \cdot c\right) + \left({b}^{2} - {b}^{2}\right)}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    7. *-commutative99.1%

      \[\leadsto \frac{\frac{a \cdot \color{blue}{\left(c \cdot -3\right)} + \left({b}^{2} - {b}^{2}\right)}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    8. +-inverses99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + \color{blue}{0}}{b + \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}}}{3 \cdot a} \]
    9. sub-neg99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\color{blue}{{b}^{2} + \left(-a \cdot \left(3 \cdot c\right)\right)}}}}{3 \cdot a} \]
    10. +-commutative99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\color{blue}{\left(-a \cdot \left(3 \cdot c\right)\right) + {b}^{2}}}}}{3 \cdot a} \]
    11. distribute-rgt-neg-in99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\color{blue}{a \cdot \left(-3 \cdot c\right)} + {b}^{2}}}}{3 \cdot a} \]
    12. fma-def99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\color{blue}{\mathsf{fma}\left(a, -3 \cdot c, {b}^{2}\right)}}}}{3 \cdot a} \]
    13. distribute-lft-neg-in99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\mathsf{fma}\left(a, \color{blue}{\left(-3\right) \cdot c}, {b}^{2}\right)}}}{3 \cdot a} \]
    14. metadata-eval99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\mathsf{fma}\left(a, \color{blue}{-3} \cdot c, {b}^{2}\right)}}}{3 \cdot a} \]
    15. *-commutative99.1%

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\mathsf{fma}\left(a, \color{blue}{c \cdot -3}, {b}^{2}\right)}}}{3 \cdot a} \]
  9. Simplified99.1%

    \[\leadsto \frac{\color{blue}{\frac{a \cdot \left(c \cdot -3\right) + 0}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)}}}}{3 \cdot a} \]
  10. Final simplification99.1%

    \[\leadsto \frac{\frac{a \cdot \left(c \cdot -3\right)}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)}}}{a \cdot 3} \]

Alternative 2: 84.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -16:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -16.0)
   (/ (- (sqrt (fma b b (* a (* c -3.0)))) b) (* a 3.0))
   (+ (* -0.5 (/ c b)) (* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0))))))
double code(double a, double b, double c) {
	double tmp;
	if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -16.0) {
		tmp = (sqrt(fma(b, b, (a * (c * -3.0)))) - b) / (a * 3.0);
	} else {
		tmp = (-0.5 * (c / b)) + (-0.375 * ((a * pow(c, 2.0)) / pow(b, 3.0)));
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -16.0)
		tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))) - b) / Float64(a * 3.0));
	else
		tmp = Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0))));
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -16.0], N[(N[(N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -16:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -16

    1. Initial program 87.8%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Step-by-step derivation
      1. +-commutative87.8%

        \[\leadsto \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}}{3 \cdot a} \]
      2. sqr-neg87.8%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(-b\right) \cdot \left(-b\right)} - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \]
      3. unsub-neg87.8%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c} - b}}{3 \cdot a} \]
      4. div-sub86.6%

        \[\leadsto \color{blue}{\frac{\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} - \frac{b}{3 \cdot a}} \]
      5. --rgt-identity86.6%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c} - 0}}{3 \cdot a} - \frac{b}{3 \cdot a} \]
      6. div-sub87.8%

        \[\leadsto \color{blue}{\frac{\left(\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c} - 0\right) - b}{3 \cdot a}} \]
    3. Simplified88.2%

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{3 \cdot a}} \]

    if -16 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a))

    1. Initial program 48.3%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Taylor expanded in b around inf 87.2%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -16:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\\ \end{array} \]

Alternative 3: 76.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -1.6 \cdot 10^{-6}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -1.6e-6)
   (* 0.3333333333333333 (/ (- (sqrt (fma b b (* c (* a -3.0)))) b) a))
   (/ (* c -0.5) b)))
double code(double a, double b, double c) {
	double tmp;
	if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1.6e-6) {
		tmp = 0.3333333333333333 * ((sqrt(fma(b, b, (c * (a * -3.0)))) - b) / a);
	} else {
		tmp = (c * -0.5) / b;
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -1.6e-6)
		tmp = Float64(0.3333333333333333 * Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -3.0)))) - b) / a));
	else
		tmp = Float64(Float64(c * -0.5) / b);
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -1.6e-6], N[(0.3333333333333333 * N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -1.6 \cdot 10^{-6}:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -1.5999999999999999e-6

    1. Initial program 70.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Step-by-step derivation
      1. expm1-log1p-u70.4%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(3 \cdot a\right) \cdot c\right)\right)}}}{3 \cdot a} \]
      2. expm1-udef65.8%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(e^{\mathsf{log1p}\left(\left(3 \cdot a\right) \cdot c\right)} - 1\right)}}}{3 \cdot a} \]
      3. associate-*l*65.8%

        \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(\color{blue}{3 \cdot \left(a \cdot c\right)}\right)} - 1\right)}}{3 \cdot a} \]
    3. Applied egg-rr65.8%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}}{3 \cdot a} \]
    4. Step-by-step derivation
      1. add-log-exp60.6%

        \[\leadsto \color{blue}{\log \left(e^{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}{3 \cdot a}}\right)} \]
      2. neg-mul-160.6%

        \[\leadsto \log \left(e^{\frac{\color{blue}{-1 \cdot b} + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}{3 \cdot a}}\right) \]
      3. metadata-eval60.6%

        \[\leadsto \log \left(e^{\frac{\color{blue}{\left(-1\right)} \cdot b + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}{3 \cdot a}}\right) \]
      4. fma-def60.6%

        \[\leadsto \log \left(e^{\frac{\color{blue}{\mathsf{fma}\left(-1, b, \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}\right)}}{3 \cdot a}}\right) \]
      5. metadata-eval60.6%

        \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(\color{blue}{-1}, b, \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}\right)}{3 \cdot a}}\right) \]
      6. pow260.6%

        \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{\color{blue}{{b}^{2}} - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}\right)}{3 \cdot a}}\right) \]
      7. expm1-def64.7%

        \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)\right)}}\right)}{3 \cdot a}}\right) \]
      8. expm1-log1p-u64.7%

        \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{3 \cdot \left(a \cdot c\right)}}\right)}{3 \cdot a}}\right) \]
      9. associate-*r*64.7%

        \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{\left(3 \cdot a\right) \cdot c}}\right)}{3 \cdot a}}\right) \]
      10. *-commutative64.7%

        \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{\left(a \cdot 3\right)} \cdot c}\right)}{3 \cdot a}}\right) \]
      11. *-commutative64.7%

        \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{\color{blue}{a \cdot 3}}}\right) \]
    5. Applied egg-rr64.7%

      \[\leadsto \color{blue}{\log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{a \cdot 3}}\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity64.7%

        \[\leadsto \log \color{blue}{\left(1 \cdot e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{a \cdot 3}}\right)} \]
      2. log-prod64.7%

        \[\leadsto \color{blue}{\log 1 + \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{a \cdot 3}}\right)} \]
      3. metadata-eval64.7%

        \[\leadsto \color{blue}{0} + \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{a \cdot 3}}\right) \]
      4. rem-log-exp70.6%

        \[\leadsto 0 + \color{blue}{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{a \cdot 3}} \]
      5. associate-*l*70.5%

        \[\leadsto 0 + \frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{a \cdot \left(3 \cdot c\right)}}\right)}{a \cdot 3} \]
    7. Applied egg-rr70.5%

      \[\leadsto \color{blue}{0 + \frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}\right)}{a \cdot 3}} \]
    8. Step-by-step derivation
      1. +-lft-identity70.5%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}\right)}{a \cdot 3}} \]
      2. *-lft-identity70.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}\right)}}{a \cdot 3} \]
      3. *-commutative70.5%

        \[\leadsto \frac{1 \cdot \mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}\right)}{\color{blue}{3 \cdot a}} \]
      4. times-frac70.5%

        \[\leadsto \color{blue}{\frac{1}{3} \cdot \frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}\right)}{a}} \]
      5. metadata-eval70.5%

        \[\leadsto \color{blue}{0.3333333333333333} \cdot \frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - a \cdot \left(3 \cdot c\right)}\right)}{a} \]
    9. Simplified70.7%

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot -3\right) \cdot c\right)} - b}{a}} \]

    if -1.5999999999999999e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a))

    1. Initial program 31.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Taylor expanded in b around inf 83.9%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
    3. Step-by-step derivation
      1. *-commutative83.9%

        \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
      2. associate-*l/83.9%

        \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
    4. Simplified83.9%

      \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -1.6 \cdot 10^{-6}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]

Alternative 4: 76.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -1.6 \cdot 10^{-6}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -1.6e-6)
   (/ (- (sqrt (fma b b (* a (* c -3.0)))) b) (* a 3.0))
   (/ (* c -0.5) b)))
double code(double a, double b, double c) {
	double tmp;
	if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1.6e-6) {
		tmp = (sqrt(fma(b, b, (a * (c * -3.0)))) - b) / (a * 3.0);
	} else {
		tmp = (c * -0.5) / b;
	}
	return tmp;
}
function code(a, b, c)
	tmp = 0.0
	if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -1.6e-6)
		tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -3.0)))) - b) / Float64(a * 3.0));
	else
		tmp = Float64(Float64(c * -0.5) / b);
	end
	return tmp
end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -1.6e-6], N[(N[(N[Sqrt[N[(b * b + N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -1.6 \cdot 10^{-6}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -1.5999999999999999e-6

    1. Initial program 70.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Step-by-step derivation
      1. +-commutative70.6%

        \[\leadsto \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}}{3 \cdot a} \]
      2. sqr-neg70.6%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(-b\right) \cdot \left(-b\right)} - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \]
      3. unsub-neg70.6%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c} - b}}{3 \cdot a} \]
      4. div-sub69.5%

        \[\leadsto \color{blue}{\frac{\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} - \frac{b}{3 \cdot a}} \]
      5. --rgt-identity69.5%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c} - 0}}{3 \cdot a} - \frac{b}{3 \cdot a} \]
      6. div-sub70.6%

        \[\leadsto \color{blue}{\frac{\left(\sqrt{\left(-b\right) \cdot \left(-b\right) - \left(3 \cdot a\right) \cdot c} - 0\right) - b}{3 \cdot a}} \]
    3. Simplified70.7%

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{3 \cdot a}} \]

    if -1.5999999999999999e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a))

    1. Initial program 31.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Taylor expanded in b around inf 83.9%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
    3. Step-by-step derivation
      1. *-commutative83.9%

        \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
      2. associate-*l/83.9%

        \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
    4. Simplified83.9%

      \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -1.6 \cdot 10^{-6}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]

Alternative 5: 76.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{if}\;t_0 \leq -1.6 \cdot 10^{-6}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0))))
   (if (<= t_0 -1.6e-6) t_0 (/ (* c -0.5) b))))
double code(double a, double b, double c) {
	double t_0 = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
	double tmp;
	if (t_0 <= -1.6e-6) {
		tmp = t_0;
	} else {
		tmp = (c * -0.5) / b;
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
    if (t_0 <= (-1.6d-6)) then
        tmp = t_0
    else
        tmp = (c * (-0.5d0)) / b
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	double t_0 = (Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
	double tmp;
	if (t_0 <= -1.6e-6) {
		tmp = t_0;
	} else {
		tmp = (c * -0.5) / b;
	}
	return tmp;
}
def code(a, b, c):
	t_0 = (math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)
	tmp = 0
	if t_0 <= -1.6e-6:
		tmp = t_0
	else:
		tmp = (c * -0.5) / b
	return tmp
function code(a, b, c)
	t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0))
	tmp = 0.0
	if (t_0 <= -1.6e-6)
		tmp = t_0;
	else
		tmp = Float64(Float64(c * -0.5) / b);
	end
	return tmp
end
function tmp_2 = code(a, b, c)
	t_0 = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
	tmp = 0.0;
	if (t_0 <= -1.6e-6)
		tmp = t_0;
	else
		tmp = (c * -0.5) / b;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1.6e-6], t$95$0, N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{if}\;t_0 \leq -1.6 \cdot 10^{-6}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -1.5999999999999999e-6

    1. Initial program 70.6%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]

    if -1.5999999999999999e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a))

    1. Initial program 31.2%

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Taylor expanded in b around inf 83.9%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
    3. Step-by-step derivation
      1. *-commutative83.9%

        \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
      2. associate-*l/83.9%

        \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
    4. Simplified83.9%

      \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -1.6 \cdot 10^{-6}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]

Alternative 6: 64.5% accurate, 23.2× speedup?

\[\begin{array}{l} \\ \frac{c \cdot -0.5}{b} \end{array} \]
(FPCore (a b c) :precision binary64 (/ (* c -0.5) b))
double code(double a, double b, double c) {
	return (c * -0.5) / b;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (c * (-0.5d0)) / b
end function
public static double code(double a, double b, double c) {
	return (c * -0.5) / b;
}
def code(a, b, c):
	return (c * -0.5) / b
function code(a, b, c)
	return Float64(Float64(c * -0.5) / b)
end
function tmp = code(a, b, c)
	tmp = (c * -0.5) / b;
end
code[a_, b_, c_] := N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}

\\
\frac{c \cdot -0.5}{b}
\end{array}
Derivation
  1. Initial program 52.3%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Taylor expanded in b around inf 67.0%

    \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
  3. Step-by-step derivation
    1. *-commutative67.0%

      \[\leadsto \color{blue}{\frac{c}{b} \cdot -0.5} \]
    2. associate-*l/67.0%

      \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
  4. Simplified67.0%

    \[\leadsto \color{blue}{\frac{c \cdot -0.5}{b}} \]
  5. Final simplification67.0%

    \[\leadsto \frac{c \cdot -0.5}{b} \]

Alternative 7: 3.2% accurate, 38.7× speedup?

\[\begin{array}{l} \\ \frac{0}{a} \end{array} \]
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
	return 0.0 / a;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
	return 0.0 / a;
}
def code(a, b, c):
	return 0.0 / a
function code(a, b, c)
	return Float64(0.0 / a)
end
function tmp = code(a, b, c)
	tmp = 0.0 / a;
end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{0}{a}
\end{array}
Derivation
  1. Initial program 52.3%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Step-by-step derivation
    1. expm1-log1p-u52.2%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(3 \cdot a\right) \cdot c\right)\right)}}}{3 \cdot a} \]
    2. expm1-udef49.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(e^{\mathsf{log1p}\left(\left(3 \cdot a\right) \cdot c\right)} - 1\right)}}}{3 \cdot a} \]
    3. associate-*l*49.6%

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(\color{blue}{3 \cdot \left(a \cdot c\right)}\right)} - 1\right)}}{3 \cdot a} \]
  3. Applied egg-rr49.6%

    \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{\left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}}{3 \cdot a} \]
  4. Step-by-step derivation
    1. add-log-exp45.9%

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}{3 \cdot a}}\right)} \]
    2. neg-mul-145.9%

      \[\leadsto \log \left(e^{\frac{\color{blue}{-1 \cdot b} + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}{3 \cdot a}}\right) \]
    3. metadata-eval45.9%

      \[\leadsto \log \left(e^{\frac{\color{blue}{\left(-1\right)} \cdot b + \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}}{3 \cdot a}}\right) \]
    4. fma-def45.9%

      \[\leadsto \log \left(e^{\frac{\color{blue}{\mathsf{fma}\left(-1, b, \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}\right)}}{3 \cdot a}}\right) \]
    5. metadata-eval45.9%

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(\color{blue}{-1}, b, \sqrt{b \cdot b - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}\right)}{3 \cdot a}}\right) \]
    6. pow245.9%

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{\color{blue}{{b}^{2}} - \left(e^{\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)} - 1\right)}\right)}{3 \cdot a}}\right) \]
    7. expm1-def48.2%

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(3 \cdot \left(a \cdot c\right)\right)\right)}}\right)}{3 \cdot a}}\right) \]
    8. expm1-log1p-u48.2%

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{3 \cdot \left(a \cdot c\right)}}\right)}{3 \cdot a}}\right) \]
    9. associate-*r*48.2%

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{\left(3 \cdot a\right) \cdot c}}\right)}{3 \cdot a}}\right) \]
    10. *-commutative48.2%

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \color{blue}{\left(a \cdot 3\right)} \cdot c}\right)}{3 \cdot a}}\right) \]
    11. *-commutative48.2%

      \[\leadsto \log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{\color{blue}{a \cdot 3}}}\right) \]
  5. Applied egg-rr48.2%

    \[\leadsto \color{blue}{\log \left(e^{\frac{\mathsf{fma}\left(-1, b, \sqrt{{b}^{2} - \left(a \cdot 3\right) \cdot c}\right)}{a \cdot 3}}\right)} \]
  6. Taylor expanded in a around 0 3.2%

    \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{b + -1 \cdot b}{a}} \]
  7. Step-by-step derivation
    1. associate-*r/3.2%

      \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot \left(b + -1 \cdot b\right)}{a}} \]
    2. distribute-rgt1-in3.2%

      \[\leadsto \frac{0.3333333333333333 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot b\right)}}{a} \]
    3. metadata-eval3.2%

      \[\leadsto \frac{0.3333333333333333 \cdot \left(\color{blue}{0} \cdot b\right)}{a} \]
    4. mul0-lft3.2%

      \[\leadsto \frac{0.3333333333333333 \cdot \color{blue}{0}}{a} \]
    5. metadata-eval3.2%

      \[\leadsto \frac{\color{blue}{0}}{a} \]
  8. Simplified3.2%

    \[\leadsto \color{blue}{\frac{0}{a}} \]
  9. Final simplification3.2%

    \[\leadsto \frac{0}{a} \]

Reproduce

?
herbie shell --seed 2023321 
(FPCore (a b c)
  :name "Cubic critical, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))