Average Error: 19.8 → 6.5
Time: 18.7s
Precision: binary64
Cost: 38052
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array} \]
\[\begin{array}{l} t_0 := \frac{\left(-b\right) - b}{a \cdot 2}\\ t_1 := \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\\ t_2 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - t_1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{t_1 - b}\\ \end{array}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+291}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{\frac{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{c}}\\ \end{array}\\ \mathbf{elif}\;t_2 \leq -2 \cdot 10^{-292}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(-2 \cdot \frac{a \cdot c}{b} + b \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(b, -2, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\ \end{array}\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+240}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))
   (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (/ (- (- b) b) (* a 2.0)))
        (t_1 (sqrt (+ (* b b) (* c (* a -4.0)))))
        (t_2
         (if (>= b 0.0) (/ (- (- b) t_1) (* a 2.0)) (/ (* c 2.0) (- t_1 b)))))
   (if (<= t_2 -1e+291)
     (if (>= b 0.0) t_0 (/ -2.0 (/ (- b (hypot b (sqrt (* a (* c -4.0))))) c)))
     (if (<= t_2 -2e-292)
       t_2
       (if (<= t_2 0.0)
         (if (>= b 0.0)
           (* (/ -0.5 a) (+ (* -2.0 (/ (* a c) b)) (* b 2.0)))
           (/ (* c 2.0) (fma b -2.0 (* 2.0 (* c (/ a b))))))
         (if (<= t_2 4e+240) t_2 (if (>= b 0.0) t_0 (/ (- c) b))))))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (-b - sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	} else {
		tmp = (2.0 * c) / (-b + sqrt(((b * b) - ((4.0 * a) * c))));
	}
	return tmp;
}
double code(double a, double b, double c) {
	double t_0 = (-b - b) / (a * 2.0);
	double t_1 = sqrt(((b * b) + (c * (a * -4.0))));
	double tmp;
	if (b >= 0.0) {
		tmp = (-b - t_1) / (a * 2.0);
	} else {
		tmp = (c * 2.0) / (t_1 - b);
	}
	double t_2 = tmp;
	double tmp_2;
	if (t_2 <= -1e+291) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = t_0;
		} else {
			tmp_3 = -2.0 / ((b - hypot(b, sqrt((a * (c * -4.0))))) / c);
		}
		tmp_2 = tmp_3;
	} else if (t_2 <= -2e-292) {
		tmp_2 = t_2;
	} else if (t_2 <= 0.0) {
		double tmp_4;
		if (b >= 0.0) {
			tmp_4 = (-0.5 / a) * ((-2.0 * ((a * c) / b)) + (b * 2.0));
		} else {
			tmp_4 = (c * 2.0) / fma(b, -2.0, (2.0 * (c * (a / b))));
		}
		tmp_2 = tmp_4;
	} else if (t_2 <= 4e+240) {
		tmp_2 = t_2;
	} else if (b >= 0.0) {
		tmp_2 = t_0;
	} else {
		tmp_2 = -c / b;
	}
	return tmp_2;
}
function code(a, b, c)
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a));
	else
		tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))));
	end
	return tmp
end
function code(a, b, c)
	t_0 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0))
	t_1 = sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0))))
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(Float64(-b) - t_1) / Float64(a * 2.0));
	else
		tmp = Float64(Float64(c * 2.0) / Float64(t_1 - b));
	end
	t_2 = tmp
	tmp_2 = 0.0
	if (t_2 <= -1e+291)
		tmp_3 = 0.0
		if (b >= 0.0)
			tmp_3 = t_0;
		else
			tmp_3 = Float64(-2.0 / Float64(Float64(b - hypot(b, sqrt(Float64(a * Float64(c * -4.0))))) / c));
		end
		tmp_2 = tmp_3;
	elseif (t_2 <= -2e-292)
		tmp_2 = t_2;
	elseif (t_2 <= 0.0)
		tmp_4 = 0.0
		if (b >= 0.0)
			tmp_4 = Float64(Float64(-0.5 / a) * Float64(Float64(-2.0 * Float64(Float64(a * c) / b)) + Float64(b * 2.0)));
		else
			tmp_4 = Float64(Float64(c * 2.0) / fma(b, -2.0, Float64(2.0 * Float64(c * Float64(a / b)))));
		end
		tmp_2 = tmp_4;
	elseif (t_2 <= 4e+240)
		tmp_2 = t_2;
	elseif (b >= 0.0)
		tmp_2 = t_0;
	else
		tmp_2 = Float64(Float64(-c) / b);
	end
	return tmp_2
end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], 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], 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]]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$1), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[t$95$2, -1e+291], If[GreaterEqual[b, 0.0], t$95$0, N[(-2.0 / N[(N[(b - N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$2, -2e-292], t$95$2, If[LessEqual[t$95$2, 0.0], If[GreaterEqual[b, 0.0], N[(N[(-0.5 / a), $MachinePrecision] * N[(N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(b * -2.0 + N[(2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$2, 4e+240], t$95$2, If[GreaterEqual[b, 0.0], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

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


\end{array}
\begin{array}{l}
t_0 := \frac{\left(-b\right) - b}{a \cdot 2}\\
t_1 := \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\\
t_2 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_1}{a \cdot 2}\\

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


\end{array}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{+291}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\

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


\end{array}\\

\mathbf{elif}\;t_2 \leq -2 \cdot 10^{-292}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(-2 \cdot \frac{a \cdot c}{b} + b \cdot 2\right)\\

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


\end{array}\\

\mathbf{elif}\;t_2 \leq 4 \cdot 10^{+240}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Derivation

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

    1. Initial program 61.5

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{\frac{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{c}}\\ \end{array} \]
      Proof
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 a (*.f64 c -4))))) c)): 0 points increase in error, 0 points decrease in error
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 a (*.f64 c (Rewrite<= rem-square-sqrt_binary64 (*.f64 (sqrt.f64 -4) (sqrt.f64 -4)))))))) c)): 155 points increase in error, 0 points decrease in error
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 a (*.f64 c (Rewrite<= unpow2_binary64 (pow.f64 (sqrt.f64 -4) 2))))))) c)): 0 points increase in error, 0 points decrease in error
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a c) (pow.f64 (sqrt.f64 -4) 2)))))) c)): 0 points increase in error, 0 points decrease in error
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 c a)) (pow.f64 (sqrt.f64 -4) 2))))) c)): 0 points increase in error, 0 points decrease in error
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 (*.f64 c a) (Rewrite=> unpow2_binary64 (*.f64 (sqrt.f64 -4) (sqrt.f64 -4))))))) c)): 0 points increase in error, 0 points decrease in error
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 (*.f64 c a) (Rewrite=> rem-square-sqrt_binary64 -4))))) c)): 0 points increase in error, 155 points decrease in error
      (/.f64 -2 (/.f64 (-.f64 b (hypot.f64 b (sqrt.f64 (Rewrite<= associate-*r*_binary64 (*.f64 c (*.f64 a -4)))))) c)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 -2 c) (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 c (*.f64 a -4))))))): 11 points increase in error, 30 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 c -2)) (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 c (*.f64 a -4)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-lft-identity_binary64 (+.f64 0 (/.f64 (*.f64 c -2) (-.f64 b (hypot.f64 b (sqrt.f64 (*.f64 c (*.f64 a -4)))))))): 0 points increase in error, 0 points decrease in error

    if -9.9999999999999996e290 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -2.0000000000000001e-292 or -0.0 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < 4.00000000000000006e240

    1. Initial program 2.9

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

    if -2.0000000000000001e-292 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -0.0

    1. Initial program 37.3

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

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{2}{\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b}\\ } \end{array}} \]
      Proof
      (if (>=.f64 b 0) (*.f64 (/.f64 -1/2 a) (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 (Rewrite<= metadata-eval (/.f64 -1 2)) a) (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (Rewrite<= associate-/r*_binary64 (/.f64 -1 (*.f64 2 a))) (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c (Rewrite<= metadata-eval (neg.f64 4)))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (sqrt.f64 (fma.f64 b b (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a c) (neg.f64 4))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (sqrt.f64 (fma.f64 b b (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 4) (*.f64 a c))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (sqrt.f64 (fma.f64 b b (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 4 (*.f64 a c)))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (sqrt.f64 (fma.f64 b b (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 4 a) c))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (sqrt.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (Rewrite<= sub-neg_binary64 (-.f64 b (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (Rewrite=> sub-neg_binary64 (+.f64 b (neg.f64 (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (*.f64 (/.f64 -1 (*.f64 2 a)) (+.f64 b (Rewrite=> remove-double-neg_binary64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 -1 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (*.f64 2 a))) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 2 points increase in error, 14 points decrease in error
      (if (>=.f64 b 0) (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (Rewrite<= distribute-neg-out_binary64 (+.f64 (neg.f64 b) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (Rewrite<= sub-neg_binary64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c (Rewrite<= metadata-eval (neg.f64 4)))))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a c) (neg.f64 4))))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 4) (*.f64 a c))))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 4 (*.f64 a c)))))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (fma.f64 b b (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 4 a) c))))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (-.f64 (sqrt.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) b)))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (Rewrite<= unsub-neg_binary64 (+.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))) (neg.f64 b)))))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (*.f64 c (/.f64 2 (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 2 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))) c))): 0 points increase in error, 0 points decrease in error
      (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c))))))): 3 points increase in error, 24 points decrease in error
    3. Taylor expanded in b around -inf 11.8

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot \color{blue}{\frac{2}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}}\\ \end{array} \]
      Proof
      (fma.f64 2 (/.f64 c (/.f64 b a)) (*.f64 b -2)): 0 points increase in error, 0 points decrease in error
      (fma.f64 2 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 c a) b)) (*.f64 b -2)): 15 points increase in error, 28 points decrease in error
      (fma.f64 2 (/.f64 (*.f64 c a) b) (Rewrite<= *-commutative_binary64 (*.f64 -2 b))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 2 (/.f64 (*.f64 c a) b)) (*.f64 -2 b))): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in b around inf 9.9

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

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

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

    1. Initial program 53.1

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
      Proof
      (/.f64 (neg.f64 c) b): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 c)) b): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 c b))): 0 points increase in error, 0 points decrease in error
  3. Recombined 4 regimes into one program.
  4. Final simplification6.5

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

Alternatives

Alternative 1
Error6.5
Cost38052
\[\begin{array}{l} t_0 := \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\\ t_1 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{t_0 - b}\\ \end{array}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(0.5 \cdot \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{-292}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(-2 \cdot \frac{a \cdot c}{b} + b \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(b, -2, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\ \end{array}\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+240}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 2
Error14.3
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -3.5 \cdot 10^{+108}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(-2 \cdot \frac{a \cdot c}{b} + b \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(b, -2, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \]
Alternative 3
Error17.5
Cost7496
\[\begin{array}{l} \mathbf{if}\;b \leq -2.3 \cdot 10^{-76}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(b + b\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{2}{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \]
Alternative 4
Error17.5
Cost7496
\[\begin{array}{l} \mathbf{if}\;b \leq -2.2 \cdot 10^{-76}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(-2 \cdot \frac{a \cdot c}{b} + b \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(b, -2, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \]
Alternative 5
Error17.6
Cost7368
\[\begin{array}{l} t_0 := \frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{if}\;b \leq -3 \cdot 10^{-76}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{c \cdot \left(a \cdot -4\right)} - b}\\ \end{array} \]
Alternative 6
Error44.8
Cost580
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(0.5 \cdot \frac{b}{a}\right)\\ \end{array} \]
Alternative 7
Error22.2
Cost580
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(0.5 \cdot \frac{c}{b}\right)\\ \end{array} \]

Error

Reproduce

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