Average Error: 34.0 → 10.4
Time: 6.8s
Precision: binary64
\[\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 -3.62263644777804 \cdot 10^{-15}:\\ \;\;\;\;\frac{c}{-b}\\ \mathbf{elif}\;b \leq 2.1532958080945476 \cdot 10^{+95}:\\ \;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \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 -3.62263644777804e-15)
   (/ c (- b))
   (if (<= b 2.1532958080945476e+95)
     (/ (+ b (sqrt (+ (* a (* c -4.0)) (* b b)))) (* a -2.0))
     (- (/ c b) (/ 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 <= -3.62263644777804e-15) {
		tmp = c / -b;
	} else if (b <= 2.1532958080945476e+95) {
		tmp = (b + sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0);
	} else {
		tmp = (c / b) - (b / a);
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-3.62263644777804d-15)) then
        tmp = c / -b
    else if (b <= 2.1532958080945476d+95) then
        tmp = (b + sqrt(((a * (c * (-4.0d0))) + (b * b)))) / (a * (-2.0d0))
    else
        tmp = (c / b) - (b / a)
    end if
    code = tmp
end function
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 <= -3.62263644777804e-15) {
		tmp = c / -b;
	} else if (b <= 2.1532958080945476e+95) {
		tmp = (b + Math.sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0);
	} else {
		tmp = (c / b) - (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 <= -3.62263644777804e-15:
		tmp = c / -b
	elif b <= 2.1532958080945476e+95:
		tmp = (b + math.sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0)
	else:
		tmp = (c / b) - (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 <= -3.62263644777804e-15)
		tmp = Float64(c / Float64(-b));
	elseif (b <= 2.1532958080945476e+95)
		tmp = Float64(Float64(b + sqrt(Float64(Float64(a * Float64(c * -4.0)) + Float64(b * b)))) / Float64(a * -2.0));
	else
		tmp = Float64(Float64(c / b) - 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 <= -3.62263644777804e-15)
		tmp = c / -b;
	elseif (b <= 2.1532958080945476e+95)
		tmp = (b + sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0);
	else
		tmp = (c / b) - (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, -3.62263644777804e-15], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.1532958080945476e+95], N[(N[(b + N[Sqrt[N[(N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $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 -3.62263644777804 \cdot 10^{-15}:\\
\;\;\;\;\frac{c}{-b}\\

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

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


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.0
Target21.7
Herbie10.4
\[\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 3 regimes
  2. if b < -3.62263644777803983e-15

    1. Initial program 54.9

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    4. Simplified6.6

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

    if -3.62263644777803983e-15 < b < 2.15329580809454757e95

    1. Initial program 15.3

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

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

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

    if 2.15329580809454757e95 < b

    1. Initial program 46.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.62263644777804 \cdot 10^{-15}:\\ \;\;\;\;\frac{c}{-b}\\ \mathbf{elif}\;b \leq 2.1532958080945476 \cdot 10^{+95}:\\ \;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

Reproduce

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