jeff quadratic root 2

?

Percentage Accurate: 72.1% → 90.2%
Time: 17.3s
Precision: binary64
Cost: 14092

?

\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
\[\begin{array}{l} t_0 := \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}\\ \mathbf{if}\;b \leq -4.8 \cdot 10^{+56}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{+49}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))
   (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (sqrt (fma b b (* (* c a) -4.0)))))
   (if (<= b -4.8e+56)
     (if (>= b 0.0) (/ (* c 2.0) (* b -2.0)) (- (/ c b) (/ b a)))
     (if (<= b 9e+49)
       (if (>= b 0.0) (* 2.0 (/ c (- (- b) t_0))) (/ (- t_0 b) (* 2.0 a)))
       (if (>= b 0.0)
         (/ (* c 2.0) (- (- b) (fma -2.0 (* c (/ a b)) b)))
         (/ (- (hypot b (* 2.0 (sqrt (* c a)))) b) (* 2.0 a)))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c))));
	} else {
		tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	}
	return tmp;
}
double code(double a, double b, double c) {
	double t_0 = sqrt(fma(b, b, ((c * a) * -4.0)));
	double tmp_1;
	if (b <= -4.8e+56) {
		double tmp_2;
		if (b >= 0.0) {
			tmp_2 = (c * 2.0) / (b * -2.0);
		} else {
			tmp_2 = (c / b) - (b / a);
		}
		tmp_1 = tmp_2;
	} else if (b <= 9e+49) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = 2.0 * (c / (-b - t_0));
		} else {
			tmp_3 = (t_0 - b) / (2.0 * a);
		}
		tmp_1 = tmp_3;
	} else if (b >= 0.0) {
		tmp_1 = (c * 2.0) / (-b - fma(-2.0, (c * (a / b)), b));
	} else {
		tmp_1 = (hypot(b, (2.0 * sqrt((c * a)))) - b) / (2.0 * a);
	}
	return tmp_1;
}
function code(a, b, c)
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))));
	else
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a));
	end
	return tmp
end
function code(a, b, c)
	t_0 = sqrt(fma(b, b, Float64(Float64(c * a) * -4.0)))
	tmp_1 = 0.0
	if (b <= -4.8e+56)
		tmp_2 = 0.0
		if (b >= 0.0)
			tmp_2 = Float64(Float64(c * 2.0) / Float64(b * -2.0));
		else
			tmp_2 = Float64(Float64(c / b) - Float64(b / a));
		end
		tmp_1 = tmp_2;
	elseif (b <= 9e+49)
		tmp_3 = 0.0
		if (b >= 0.0)
			tmp_3 = Float64(2.0 * Float64(c / Float64(Float64(-b) - t_0)));
		else
			tmp_3 = Float64(Float64(t_0 - b) / Float64(2.0 * a));
		end
		tmp_1 = tmp_3;
	elseif (b >= 0.0)
		tmp_1 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - fma(-2.0, Float64(c * Float64(a / b)), b)));
	else
		tmp_1 = Float64(Float64(hypot(b, Float64(2.0 * sqrt(Float64(c * a)))) - b) / Float64(2.0 * a));
	end
	return tmp_1
end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -4.8e+56], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 9e+49], If[GreaterEqual[b, 0.0], N[(2.0 * N[(c / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[b ^ 2 + N[(2.0 * N[Sqrt[N[(c * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\


\end{array}
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}\\
\mathbf{if}\;b \leq -4.8 \cdot 10^{+56}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\


\end{array}\\

\mathbf{elif}\;b \leq 9 \cdot 10^{+49}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;2 \cdot \frac{c}{\left(-b\right) - t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0 - b}{2 \cdot a}\\


\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{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.

Herbie found 5 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Derivation?

  1. Split input into 3 regimes
  2. if b < -4.80000000000000027e56

    1. Initial program 61.2%

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
    2. Simplified61.2%

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2 \cdot a}\\ } \end{array}} \]
      Step-by-step derivation

      [Start]61.2%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
    3. Taylor expanded in b around -inf 90.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{c \cdot a}{b} + -1 \cdot b\right) - b}{2 \cdot a}\\ \end{array} \]
    4. Simplified92.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right) - b}{2 \cdot a}\\ \end{array} \]
      Step-by-step derivation

      [Start]90.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{c \cdot a}{b} + -1 \cdot b\right) - b}{2 \cdot a}\\ \end{array} \]

      fma-def [=>]90.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c \cdot a}{b}, -1 \cdot b\right) - b}{2 \cdot a}\\ \end{array} \]

      associate-/l* [=>]92.8%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -1 \cdot b\right) - b}{2 \cdot a}\\ \end{array} \]

      mul-1-neg [=>]92.8%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right) - b}{2 \cdot a}\\ \end{array} \]
    5. Taylor expanded in b around inf 92.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \color{blue}{b}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right) - b}{2 \cdot a}\\ \end{array} \]
    6. Taylor expanded in c around 0 92.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - b} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} + -1 \cdot \frac{b}{a}\\ \end{array} \]
    7. Simplified92.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - b} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
      Step-by-step derivation

      [Start]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - b} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} + -1 \cdot \frac{b}{a}\\ \end{array} \]

      mul-1-neg [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - b} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{c}{b} + \left(-\frac{b}{a}\right)}\\ \end{array} \]

      unsub-neg [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - b} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
    8. Applied egg-rr92.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{\frac{c \cdot 2}{\left(-b\right) - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
      Step-by-step derivation

      [Start]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - b} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

      associate-*l/ [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{\frac{c \cdot 2}{\left(-b\right) - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
    9. Simplified92.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\color{blue}{\frac{c \cdot 2}{b \cdot -2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
      Step-by-step derivation

      [Start]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

      sub-neg [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\color{blue}{\left(-b\right) + \left(-b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

      neg-mul-1 [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\color{blue}{-1 \cdot b} + \left(-b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

      neg-mul-1 [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{-1 \cdot b + \color{blue}{-1 \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

      distribute-rgt-out [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\color{blue}{b \cdot \left(-1 + -1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

      metadata-eval [=>]92.9%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot \color{blue}{-2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

    if -4.80000000000000027e56 < b < 8.99999999999999965e49

    1. Initial program 87.6%

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
    2. Simplified88.4%

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2 \cdot a}\\ } \end{array}} \]
      Step-by-step derivation

      [Start]87.6%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]

    if 8.99999999999999965e49 < b

    1. Initial program 59.5%

      \[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
    2. Applied egg-rr59.5%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]
      Step-by-step derivation

      [Start]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]

      +-commutative [=>]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      add-sqr-sqrt [=>]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      add-sqr-sqrt [<=]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      associate-*l* [=>]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      *-commutative [<=]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      cancel-sign-sub-inv [=>]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + \left(-4\right) \cdot \left(c \cdot a\right)} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      metadata-eval [=>]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + -4 \cdot \left(c \cdot a\right)} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      *-commutative [<=]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      associate-*r* [<=]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      fma-udef [<=]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} + \left(-b\right)}{2 \cdot a}\\ \end{array} \]

      sub-neg [<=]59.5%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{2 \cdot a}\\ \end{array} \]
    3. Taylor expanded in b around inf 94.4%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(b + -2 \cdot \frac{c \cdot a}{b}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]
    4. Simplified96.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]
      Step-by-step derivation

      [Start]94.4%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b + -2 \cdot \frac{c \cdot a}{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      +-commutative [=>]94.4%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(-2 \cdot \frac{c \cdot a}{b} + b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      associate-/l* [=>]96.0%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(-2 \cdot \color{blue}{\frac{c}{\frac{b}{a}}} + b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      fma-def [=>]96.0%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\mathsf{fma}\left(-2, \frac{c}{\frac{b}{a}}, b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      *-rgt-identity [<=]96.0%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(-2, \frac{\color{blue}{c \cdot 1}}{\frac{b}{a}}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      associate-*r/ [<=]96.0%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(-2, \color{blue}{c \cdot \frac{1}{\frac{b}{a}}}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      associate-/r/ [=>]96.0%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \color{blue}{\left(\frac{1}{b} \cdot a\right)}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      associate-*l/ [=>]96.0%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \color{blue}{\frac{1 \cdot a}{b}}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

      *-lft-identity [=>]96.0%

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \frac{\color{blue}{a}}{b}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification91.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.8 \cdot 10^{+56}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{+49}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy90.2%
Cost14092
\[\begin{array}{l} t_0 := \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}\\ \mathbf{if}\;b \leq -4.8 \cdot 10^{+56}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{+49}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]
Alternative 2
Accuracy90.2%
Cost13964
\[\begin{array}{l} t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\ \mathbf{if}\;b \leq -1.6 \cdot 10^{+58}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq 9.2 \cdot 10^{+49}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, 2 \cdot \sqrt{c \cdot a}\right) - b}{2 \cdot a}\\ \end{array} \]
Alternative 3
Accuracy90.6%
Cost7821
\[\begin{array}{l} t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\ \mathbf{if}\;b \leq -1.6 \cdot 10^{+58} \lor \neg \left(b \leq 3.8 \cdot 10^{+123}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 - b}{2 \cdot a}\\ \end{array} \]
Alternative 4
Accuracy68.4%
Cost7428
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \mathsf{fma}\left(-2, \frac{c}{b} \cdot a, b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 5
Accuracy68.3%
Cost580
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

Reproduce?

herbie shell --seed 2023165 
(FPCore (a b c)
  :name "jeff quadratic root 2"
  :precision binary64
  (if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))