?

Average Error: 31.13% → 12.23%
Time: 21.0s
Precision: binary64
Cost: 43164

?

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

\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot 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 -2 \cdot 10^{-255}:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, c \cdot \frac{a}{b}, b \cdot -2\right) \cdot \frac{0.5}{a}\right)} + -1\\


\end{array}\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+178}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Derivation?

  1. Split input into 3 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 or 2.0000000000000001e178 < (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 75.43

      \[\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 77.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \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 27.25

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

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

      [Start]27.25

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

      *-commutative [=>]27.25

      \[ \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot 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))) < -2e-255 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))) < 2.0000000000000001e178

    1. Initial program 4.86

      \[\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 -2e-255 < (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 55.72

      \[\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 56.12

      \[\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{2 \cdot \frac{c \cdot a}{b} + -2 \cdot b}{2 \cdot a}\\ \end{array} \]
    3. Simplified56.13

      \[\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{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{2 \cdot a}\\ \end{array} \]
      Proof

      [Start]56.12

      \[ \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{2 \cdot \frac{c \cdot a}{b} + -2 \cdot b}{2 \cdot a}\\ \end{array} \]

      fma-def [=>]56.12

      \[ \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{fma}\left(2, \frac{c \cdot a}{b}, -2 \cdot b\right)}{2 \cdot a}\\ \end{array} \]

      associate-/l* [=>]56.13

      \[ \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{fma}\left(2, \frac{c}{\frac{b}{a}}, -2 \cdot b\right)}{2 \cdot a}\\ \end{array} \]

      *-commutative [=>]56.13

      \[ \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{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{2 \cdot a}\\ \end{array} \]
    4. Taylor expanded in b around inf 51.01

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(-2 \cdot \frac{{c}^{2} \cdot {a}^{2}}{{b}^{3}} + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{2 \cdot a}\\ \end{array} \]
    5. Simplified35.06

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

      [Start]51.01

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

      +-commutative [=>]51.01

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

      associate-+l+ [=>]51.01

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

      +-commutative [<=]51.01

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

      distribute-lft-out [=>]51.01

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

      +-commutative [=>]51.01

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

      associate-/l* [=>]50.98

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

      associate-/r/ [=>]50.98

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

      associate-/l* [=>]48.88

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

      associate-/r/ [=>]48.73

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

      unpow2 [=>]48.73

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

      associate-/l* [=>]35.06

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

      unpow2 [=>]35.06

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

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

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

      [Start]20.62

      \[ \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{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{2 \cdot a}\\ \end{array} \]

      *-commutative [=>]20.62

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

      associate-*r/ [<=]16.93

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b + -2 \cdot \left(a \cdot \frac{c}{b}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, c \cdot \frac{a}{b}, b \cdot -2\right) \cdot \frac{0.5}{a}\right)} - 1\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.23

    \[\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:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2}{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 -2 \cdot 10^{-255}:\\ \;\;\;\;\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}{\left(2 \cdot \left(a \cdot \frac{c}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, c \cdot \frac{a}{b}, b \cdot -2\right) \cdot \frac{0.5}{a}\right)} + -1\\ \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 2 \cdot 10^{+178}:\\ \;\;\;\;\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{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\ \end{array} \]

Alternatives

Alternative 1
Error12.22%
Cost38052
\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot 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 -2 \cdot 10^{-255}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(a \cdot \frac{c}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2 + \left(c \cdot a\right) \cdot \frac{2}{b}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+178}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error12.22%
Cost38052
\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2}{2 \cdot 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 -5 \cdot 10^{-241}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(\frac{2 \cdot c}{\frac{b}{a}} - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;t_3 \leq 2 \cdot 10^{+178}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error20.12%
Cost7760
\[\begin{array}{l} t_0 := \frac{2 \cdot c}{\left(-b\right) - b}\\ t_1 := \sqrt{c \cdot \left(a \cdot -4\right)}\\ \mathbf{if}\;b \leq -3 \cdot 10^{-72}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq -6 \cdot 10^{-307}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-70}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(2 \cdot \left(a \cdot \frac{c}{b}\right) - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot -2 + \left(c \cdot a\right) \cdot \frac{2}{b}}{2 \cdot a}\\ \end{array} \]
Alternative 4
Error20.14%
Cost7760
\[\begin{array}{l} t_0 := \frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{2 \cdot a}\\ t_1 := \frac{2 \cdot c}{\left(-b\right) - b}\\ t_2 := \sqrt{c \cdot \left(a \cdot -4\right)}\\ \mathbf{if}\;b \leq -4.9 \cdot 10^{-73}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq -6 \cdot 10^{-307}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{t_2 - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-70}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_2}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(\frac{2 \cdot c}{\frac{b}{a}} - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error15.14%
Cost7760
\[\begin{array}{l} t_0 := \frac{2 \cdot c}{\left(-b\right) - b}\\ t_1 := \frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{2 \cdot a}\\ \mathbf{if}\;b \leq -1 \cdot 10^{+137}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \leq -6 \cdot 10^{-307}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{-70}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(\frac{2 \cdot c}{\frac{b}{a}} - b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error27.78%
Cost7368
\[\begin{array}{l} t_0 := \frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{if}\;b \leq -8.4 \cdot 10^{-73}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{2 \cdot a}\\ \end{array} \]
Alternative 7
Error34.44%
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} \]

Error

Reproduce?

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