?

Average Error: 19.8 → 7.5
Time: 24.7s
Precision: binary64
Cost: 43932

?

\[\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 := \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\\ t_1 := \sqrt{t_0}\\ t_2 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\ t_3 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_2 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;c \cdot \frac{-2}{b + t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{\mathsf{hypot}\left(b, \sqrt{a \cdot -4} \cdot \sqrt{c}\right) - b}} \cdot \frac{0.5}{a}\\ \end{array}\\ \mathbf{elif}\;t_3 \leq -1 \cdot 10^{-246}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\frac{b - t_1}{b \cdot b - t_0}}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;t_3 \leq 4 \cdot 10^{+270}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{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 (fma b b (* c (* a -4.0))))
        (t_1 (sqrt t_0))
        (t_2 (sqrt (- (* b b) (* c (* 4.0 a)))))
        (t_3
         (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_2)) (/ (- t_2 b) (* 2.0 a)))))
   (if (<= t_3 (- INFINITY))
     (if (>= b 0.0)
       (* c (/ -2.0 (+ b t_1)))
       (*
        (/ 1.0 (/ 1.0 (- (hypot b (* (sqrt (* a -4.0)) (sqrt c))) b)))
        (/ 0.5 a)))
     (if (<= t_3 -1e-246)
       t_3
       (if (<= t_3 0.0)
         (if (>= b 0.0)
           (/ (* 2.0 c) (fma 2.0 (/ c (/ b a)) (* b -2.0)))
           (/ (/ 1.0 (/ (- b t_1) (- (* b b) t_0))) (* 2.0 a)))
         (if (<= t_3 4e+270) t_3 (if (>= b 0.0) (/ b a) (/ (- b) 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 = fma(b, b, (c * (a * -4.0)));
	double t_1 = sqrt(t_0);
	double t_2 = sqrt(((b * b) - (c * (4.0 * a))));
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - t_2);
	} else {
		tmp = (t_2 - b) / (2.0 * a);
	}
	double t_3 = tmp;
	double tmp_2;
	if (t_3 <= -((double) INFINITY)) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = c * (-2.0 / (b + t_1));
		} else {
			tmp_3 = (1.0 / (1.0 / (hypot(b, (sqrt((a * -4.0)) * sqrt(c))) - b))) * (0.5 / a);
		}
		tmp_2 = tmp_3;
	} else if (t_3 <= -1e-246) {
		tmp_2 = t_3;
	} else if (t_3 <= 0.0) {
		double tmp_4;
		if (b >= 0.0) {
			tmp_4 = (2.0 * c) / fma(2.0, (c / (b / a)), (b * -2.0));
		} else {
			tmp_4 = (1.0 / ((b - t_1) / ((b * b) - t_0))) / (2.0 * a);
		}
		tmp_2 = tmp_4;
	} else if (t_3 <= 4e+270) {
		tmp_2 = t_3;
	} else if (b >= 0.0) {
		tmp_2 = b / a;
	} else {
		tmp_2 = -b / a;
	}
	return tmp_2;
}
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 = fma(b, b, Float64(c * Float64(a * -4.0)))
	t_1 = sqrt(t_0)
	t_2 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a))))
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_2));
	else
		tmp = Float64(Float64(t_2 - b) / Float64(2.0 * a));
	end
	t_3 = tmp
	tmp_2 = 0.0
	if (t_3 <= Float64(-Inf))
		tmp_3 = 0.0
		if (b >= 0.0)
			tmp_3 = Float64(c * Float64(-2.0 / Float64(b + t_1)));
		else
			tmp_3 = Float64(Float64(1.0 / Float64(1.0 / Float64(hypot(b, Float64(sqrt(Float64(a * -4.0)) * sqrt(c))) - b))) * Float64(0.5 / a));
		end
		tmp_2 = tmp_3;
	elseif (t_3 <= -1e-246)
		tmp_2 = t_3;
	elseif (t_3 <= 0.0)
		tmp_4 = 0.0
		if (b >= 0.0)
			tmp_4 = Float64(Float64(2.0 * c) / fma(2.0, Float64(c / Float64(b / a)), Float64(b * -2.0)));
		else
			tmp_4 = Float64(Float64(1.0 / Float64(Float64(b - t_1) / Float64(Float64(b * b) - t_0))) / Float64(2.0 * a));
		end
		tmp_2 = tmp_4;
	elseif (t_3 <= 4e+270)
		tmp_2 = t_3;
	elseif (b >= 0.0)
		tmp_2 = Float64(b / a);
	else
		tmp_2 = Float64(Float64(-b) / a);
	end
	return tmp_2
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[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$2 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[t$95$3, (-Infinity)], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.0 / N[(N[Sqrt[b ^ 2 + N[(N[Sqrt[N[(a * -4.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[c], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$3, -1e-246], t$95$3, If[LessEqual[t$95$3, 0.0], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(b - t$95$1), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$3, 4e+270], t$95$3, If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[((-b) / a), $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 := \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\\
t_1 := \sqrt{t_0}\\
t_2 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_3 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_2}\\

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


\end{array}\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + t_1}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{\mathsf{hypot}\left(b, \sqrt{a \cdot -4} \cdot \sqrt{c}\right) - b}} \cdot \frac{0.5}{a}\\


\end{array}\\

\mathbf{elif}\;t_3 \leq -1 \cdot 10^{-246}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}\\

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


\end{array}\\

\mathbf{elif}\;t_3 \leq 4 \cdot 10^{+270}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\

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


\end{array}

Error?

Derivation?

  1. Split input into 4 regimes
  2. if (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -inf.0

    1. Initial program 64.0

      \[\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. Simplified64.0

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

      [Start]64.0

      \[ \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. Applied egg-rr45.3

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

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

    if -inf.0 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -9.99999999999999956e-247 or -0.0 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < 4.0000000000000002e270

    1. Initial program 2.7

      \[\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 -9.99999999999999956e-247 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))) < -0.0

    1. Initial program 35.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. Taylor expanded in b around inf 12.5

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

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

      [Start]12.5

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

      fma-def [=>]12.5

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

      associate-/l* [=>]10.7

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

      *-commutative [=>]10.7

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

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

    if 4.0000000000000002e270 < (if (>=.f64 b 0) (/.f64 (*.f64 2 c) (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)))

    1. Initial program 59.0

      \[\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. Taylor expanded in b around inf 59.2

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

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

      [Start]59.2

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

      fma-def [=>]59.2

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

      associate-/l* [=>]54.3

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

      *-commutative [=>]54.3

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array} \]
    6. Simplified19.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
      Proof

      [Start]19.5

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

      mul-1-neg [=>]19.5

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

      distribute-neg-frac [=>]19.5

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.5

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

Alternatives

Alternative 1
Error7.4
Cost38052
\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\\ t_1 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\ t_2 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_2 \leq -1 \cdot 10^{-246}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{c \cdot a}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+270}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error7.2
Cost38052
\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\\ t_1 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\ t_2 := \frac{t_1 - b}{2 \cdot a}\\ t_3 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_3 \leq -1 \cdot 10^{-230}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, a \cdot \frac{c}{b}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;t_3 \leq 4 \cdot 10^{+270}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error7.5
Cost38052
\[\begin{array}{l} t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\ t_1 := \frac{t_0 - b}{2 \cdot a}\\ t_2 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;c \cdot \frac{-2}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{\mathsf{hypot}\left(b, \sqrt{a \cdot -4} \cdot \sqrt{c}\right) - b}} \cdot \frac{0.5}{a}\\ \end{array}\\ \mathbf{elif}\;t_2 \leq -1 \cdot 10^{-230}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, a \cdot \frac{c}{b}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+270}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 4
Error14.5
Cost7756
\[\begin{array}{l} \mathbf{if}\;b \leq -1.02 \cdot 10^{+124}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{-219}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{c \cdot a}{b} - b\right) - b}{2 \cdot a}\\ \end{array} \]
Alternative 5
Error14.7
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{+115}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \]
Alternative 6
Error17.9
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.5 \cdot 10^{-33}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{2 \cdot a}\\ \end{array} \]
Alternative 7
Error22.7
Cost644
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 8
Error22.8
Cost644
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{a}{b}}\\ \end{array} \]
Alternative 9
Error22.7
Cost644
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 10
Error45.1
Cost388
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]

Error

Reproduce?

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