Average Error: 34.3 → 9.2
Time: 11.4s
Precision: binary64
Cost: 13832
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -2.6 \cdot 10^{-33}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq -1 \cdot 10^{-95}:\\ \;\;\;\;\frac{c \cdot -2}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{+135}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -2.6e-33)
   (/ (- c) b)
   (if (<= b -1e-95)
     (/ (* c -2.0) (- b (hypot b (sqrt (* a (* c -4.0))))))
     (if (<= b 3e+135)
       (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
       (/ (- b) a)))))
double code(double a, double b, double c) {
	return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -2.6e-33) {
		tmp = -c / b;
	} else if (b <= -1e-95) {
		tmp = (c * -2.0) / (b - hypot(b, sqrt((a * (c * -4.0)))));
	} else if (b <= 3e+135) {
		tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
	} else {
		tmp = -b / a;
	}
	return tmp;
}
public static double code(double a, double b, double c) {
	return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -2.6e-33) {
		tmp = -c / b;
	} else if (b <= -1e-95) {
		tmp = (c * -2.0) / (b - Math.hypot(b, Math.sqrt((a * (c * -4.0)))));
	} else if (b <= 3e+135) {
		tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
	} else {
		tmp = -b / a;
	}
	return tmp;
}
def code(a, b, c):
	return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
def code(a, b, c):
	tmp = 0
	if b <= -2.6e-33:
		tmp = -c / b
	elif b <= -1e-95:
		tmp = (c * -2.0) / (b - math.hypot(b, math.sqrt((a * (c * -4.0)))))
	elif b <= 3e+135:
		tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0)
	else:
		tmp = -b / a
	return tmp
function code(a, b, c)
	return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a))
end
function code(a, b, c)
	tmp = 0.0
	if (b <= -2.6e-33)
		tmp = Float64(Float64(-c) / b);
	elseif (b <= -1e-95)
		tmp = Float64(Float64(c * -2.0) / Float64(b - hypot(b, sqrt(Float64(a * Float64(c * -4.0))))));
	elseif (b <= 3e+135)
		tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0));
	else
		tmp = Float64(Float64(-b) / a);
	end
	return tmp
end
function tmp = code(a, b, c)
	tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -2.6e-33)
		tmp = -c / b;
	elseif (b <= -1e-95)
		tmp = (c * -2.0) / (b - hypot(b, sqrt((a * (c * -4.0)))));
	elseif (b <= 3e+135)
		tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
	else
		tmp = -b / a;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -2.6e-33], N[((-c) / b), $MachinePrecision], If[LessEqual[b, -1e-95], N[(N[(c * -2.0), $MachinePrecision] / N[(b - N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3e+135], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{-33}:\\
\;\;\;\;\frac{-c}{b}\\

\mathbf{elif}\;b \leq -1 \cdot 10^{-95}:\\
\;\;\;\;\frac{c \cdot -2}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\

\mathbf{elif}\;b \leq 3 \cdot 10^{+135}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 4 regimes
  2. if b < -2.59999999999999994e-33

    1. Initial program 54.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Simplified54.6

      \[\leadsto \color{blue}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right) \cdot \frac{-0.5}{a}} \]
    3. Applied egg-rr48.5

      \[\leadsto \color{blue}{\frac{b + \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a \cdot -2}} \]
    4. Taylor expanded in b around -inf 64.0

      \[\leadsto \color{blue}{0.25 \cdot \frac{c \cdot {\left(\sqrt{-4}\right)}^{2}}{b}} \]
    5. Simplified6.7

      \[\leadsto \color{blue}{\frac{-c}{b}} \]

    if -2.59999999999999994e-33 < b < -9.99999999999999989e-96

    1. Initial program 33.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Simplified33.5

      \[\leadsto \color{blue}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right) \cdot \frac{-0.5}{a}} \]
    3. Applied egg-rr34.4

      \[\leadsto \color{blue}{\frac{\frac{-0.5}{a} \cdot \left(b \cdot b - \mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)\right)}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}} \]
    4. Taylor expanded in a around 0 15.3

      \[\leadsto \frac{\color{blue}{-2 \cdot c}}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)} \]
    5. Simplified15.3

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

    if -9.99999999999999989e-96 < b < 3e135

    1. Initial program 12.1

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

    if 3e135 < b

    1. Initial program 57.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Taylor expanded in b around inf 2.6

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    3. Simplified2.6

      \[\leadsto \color{blue}{\frac{-b}{a}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.6 \cdot 10^{-33}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq -1 \cdot 10^{-95}:\\ \;\;\;\;\frac{c \cdot -2}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{+135}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]

Alternatives

Alternative 1
Error10.0
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -1.3 \cdot 10^{-50}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{+135}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 2
Error10.0
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.3 \cdot 10^{-50}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{+135}:\\ \;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}\right) \cdot \frac{-0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 3
Error14.1
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.3 \cdot 10^{-50}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 24.5:\\ \;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 4
Error22.2
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -4.3 \cdot 10^{-191}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 5
Error45.3
Cost256
\[\frac{-b}{a} \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))