Average Error: 33.5 → 10.5
Time: 12.5s
Precision: binary64
Cost: 7688
\[\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 -8 \cdot 10^{-143}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 2 \cdot 10^{+106}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4}}{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 -8e-143)
   (/ (- c) b)
   (if (<= b 2e+106)
     (/ (- (- b) (sqrt (+ (* b b) (* (* c a) -4.0)))) (* 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 <= -8e-143) {
		tmp = -c / b;
	} else if (b <= 2e+106) {
		tmp = (-b - sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0);
	} else {
		tmp = -(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 <= (-8d-143)) then
        tmp = -c / b
    else if (b <= 2d+106) then
        tmp = (-b - sqrt(((b * b) + ((c * a) * (-4.0d0))))) / (a * 2.0d0)
    else
        tmp = -(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 <= -8e-143) {
		tmp = -c / b;
	} else if (b <= 2e+106) {
		tmp = (-b - Math.sqrt(((b * b) + ((c * a) * -4.0)))) / (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 <= -8e-143:
		tmp = -c / b
	elif b <= 2e+106:
		tmp = (-b - math.sqrt(((b * b) + ((c * a) * -4.0)))) / (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 <= -8e-143)
		tmp = Float64(Float64(-c) / b);
	elseif (b <= 2e+106)
		tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) + Float64(Float64(c * a) * -4.0)))) / 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 <= -8e-143)
		tmp = -c / b;
	elseif (b <= 2e+106)
		tmp = (-b - sqrt(((b * b) + ((c * a) * -4.0)))) / (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, -8e-143], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+106], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(c * a), $MachinePrecision] * -4.0), $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 -8 \cdot 10^{-143}:\\
\;\;\;\;\frac{-c}{b}\\

\mathbf{elif}\;b \leq 2 \cdot 10^{+106}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4}}{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

Original33.5
Target20.4
Herbie10.5
\[\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 < -7.9999999999999996e-143

    1. Initial program 49.9

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

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

      [Start]49.9

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

      *-lft-identity [<=]49.9

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

      metadata-eval [<=]49.9

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

      associate-*r/ [=>]49.9

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

      associate-*l/ [<=]49.9

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

      distribute-neg-frac [<=]49.9

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

      distribute-lft-neg-in [<=]49.9

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

      distribute-rgt-neg-out [<=]49.9

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

      associate-/r* [=>]49.9

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

      metadata-eval [=>]49.9

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

      sub-neg [=>]49.9

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

      distribute-neg-out [=>]49.9

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

      remove-double-neg [=>]49.9

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

      sub-neg [=>]49.9

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

      +-commutative [=>]49.9

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

      associate-*r* [=>]49.9

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

      distribute-lft-neg-in [=>]49.9

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

      *-commutative [=>]49.9

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

      fma-def [=>]49.9

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

      *-commutative [=>]49.9

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

      distribute-rgt-neg-in [=>]49.9

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

      metadata-eval [=>]49.9

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

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

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

      [Start]12.1

      \[ -1 \cdot \frac{c}{b} \]

      mul-1-neg [=>]12.1

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

      distribute-neg-frac [=>]12.1

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

    if -7.9999999999999996e-143 < b < 2.00000000000000018e106

    1. Initial program 10.8

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

    if 2.00000000000000018e106 < b

    1. Initial program 48.4

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

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

      [Start]48.4

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

      *-lft-identity [<=]48.4

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

      metadata-eval [<=]48.4

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

      associate-*r/ [=>]48.4

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

      associate-*l/ [<=]48.5

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

      distribute-neg-frac [<=]48.5

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

      distribute-lft-neg-in [<=]48.5

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

      distribute-rgt-neg-out [<=]48.5

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

      associate-/r* [=>]48.5

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

      metadata-eval [=>]48.5

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

      sub-neg [=>]48.5

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

      distribute-neg-out [=>]48.5

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

      remove-double-neg [=>]48.5

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

      sub-neg [=>]48.5

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

      +-commutative [=>]48.5

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

      associate-*r* [=>]48.6

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

      distribute-lft-neg-in [=>]48.6

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

      *-commutative [=>]48.6

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

      fma-def [=>]48.6

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

      *-commutative [=>]48.6

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

      distribute-rgt-neg-in [=>]48.6

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

      metadata-eval [=>]48.6

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    4. Simplified4.5

      \[\leadsto \color{blue}{\frac{-b}{a}} \]
      Proof

      [Start]4.5

      \[ -1 \cdot \frac{b}{a} \]

      associate-*r/ [=>]4.5

      \[ \color{blue}{\frac{-1 \cdot b}{a}} \]

      mul-1-neg [=>]4.5

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

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

Alternatives

Alternative 1
Error14.1
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -8 \cdot 10^{-143}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{-26}:\\ \;\;\;\;\left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array} \]
Alternative 2
Error39.5
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -4.1 \cdot 10^{+14}:\\ \;\;\;\;\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array} \]
Alternative 3
Error22.9
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -1.2 \cdot 10^{-302}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array} \]
Alternative 4
Error56.3
Cost192
\[\frac{c}{b} \]

Error

Reproduce

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