The quadratic formula (r2)

?

Percentage Accurate: 51.6% → 85.5%
Time: 18.5s
Precision: binary64
Cost: 14216

?

\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{-c}{b}\\ \mathbf{if}\;b \leq -1.32 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq -1.05 \cdot 10^{-97}:\\ \;\;\;\;-0.5 \cdot \frac{\frac{4 \cdot \left(c \cdot a\right)}{b - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}}{a}\\ \mathbf{elif}\;b \leq -7.5 \cdot 10^{-143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 8 \cdot 10^{+142}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\ \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
 (let* ((t_0 (/ (- c) b)))
   (if (<= b -1.32e-23)
     t_0
     (if (<= b -1.05e-97)
       (*
        -0.5
        (/ (/ (* 4.0 (* c a)) (- b (hypot b (sqrt (* c (* a -4.0)))))) a))
       (if (<= b -7.5e-143)
         t_0
         (if (<= b 8e+142)
           (* -0.5 (/ (+ b (sqrt (fma a (* c -4.0) (* b b)))) a))
           (/ (- 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 t_0 = -c / b;
	double tmp;
	if (b <= -1.32e-23) {
		tmp = t_0;
	} else if (b <= -1.05e-97) {
		tmp = -0.5 * (((4.0 * (c * a)) / (b - hypot(b, sqrt((c * (a * -4.0)))))) / a);
	} else if (b <= -7.5e-143) {
		tmp = t_0;
	} else if (b <= 8e+142) {
		tmp = -0.5 * ((b + sqrt(fma(a, (c * -4.0), (b * b)))) / a);
	} 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)
	t_0 = Float64(Float64(-c) / b)
	tmp = 0.0
	if (b <= -1.32e-23)
		tmp = t_0;
	elseif (b <= -1.05e-97)
		tmp = Float64(-0.5 * Float64(Float64(Float64(4.0 * Float64(c * a)) / Float64(b - hypot(b, sqrt(Float64(c * Float64(a * -4.0)))))) / a));
	elseif (b <= -7.5e-143)
		tmp = t_0;
	elseif (b <= 8e+142)
		tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))) / a));
	else
		tmp = Float64(Float64(-b) / a);
	end
	return 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_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -1.32e-23], t$95$0, If[LessEqual[b, -1.05e-97], N[(-0.5 * N[(N[(N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b - N[Sqrt[b ^ 2 + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -7.5e-143], t$95$0, If[LessEqual[b, 8e+142], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $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}
t_0 := \frac{-c}{b}\\
\mathbf{if}\;b \leq -1.32 \cdot 10^{-23}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;b \leq -7.5 \cdot 10^{-143}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b \leq 8 \cdot 10^{+142}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\

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


\end{array}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Target

Original51.6%
Target70.2%
Herbie85.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 4 regimes
  2. if b < -1.31999999999999994e-23 or -1.0500000000000001e-97 < b < -7.5000000000000003e-143

    1. Initial program 11.4%

      \[\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 90.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    3. Simplified90.6%

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
      Step-by-step derivation

      [Start]90.6

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

      associate-*r/ [=>]90.6

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

      neg-mul-1 [<=]90.6

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

    if -1.31999999999999994e-23 < b < -1.0500000000000001e-97

    1. Initial program 73.4%

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

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

      [Start]73.4

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

      /-rgt-identity [<=]73.4

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

      metadata-eval [<=]73.4

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

      associate-/l* [=>]73.2

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

      associate-/r/ [=>]73.1

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

      *-commutative [<=]73.1

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

      metadata-eval [=>]73.1

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

      metadata-eval [<=]73.1

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

      associate-*l/ [<=]73.1

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

      associate-/r/ [<=]73.1

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

      times-frac [<=]73.4

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

      *-commutative [<=]73.4

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

      times-frac [=>]73.4

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

      metadata-eval [=>]73.4

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

      associate-/r/ [=>]73.4

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

      *-commutative [<=]73.4

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

      div-sub [=>]73.4

      \[ -0.5 \cdot \left(-1 \cdot \color{blue}{\left(\frac{-b}{a} - \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}\right)}\right) \]
    3. Applied egg-rr72.8%

      \[\leadsto -0.5 \cdot \frac{\color{blue}{\frac{b \cdot b}{b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)} - \frac{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}{b - \mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)}}}{a} \]
      Step-by-step derivation

      [Start]73.4

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

      flip-+ [=>]73.4

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

      add-sqr-sqrt [<=]73.1

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

      div-sub [=>]73.1

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

      fma-udef [=>]73.1

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

      +-commutative [=>]73.1

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

      add-sqr-sqrt [=>]72.8

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

      hypot-def [=>]72.8

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

      associate-*r* [=>]72.8

      \[ -0.5 \cdot \frac{\frac{b \cdot b}{b - \mathsf{hypot}\left(b, \sqrt{\color{blue}{\left(a \cdot c\right) \cdot -4}}\right)} - \frac{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}{a} \]
    4. Simplified89.9%

      \[\leadsto -0.5 \cdot \frac{\color{blue}{\frac{\left(c \cdot a\right) \cdot 4}{b - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}}}{a} \]
      Step-by-step derivation

      [Start]72.8

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

      div-sub [<=]72.8

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

      fma-udef [=>]72.8

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

      associate--r+ [=>]89.9

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

      +-inverses [=>]89.9

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

      neg-sub0 [<=]89.9

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

      *-commutative [=>]89.9

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

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

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

      metadata-eval [=>]89.9

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

      *-commutative [=>]89.9

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

      associate-*l* [=>]89.9

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

    if -7.5000000000000003e-143 < b < 8.00000000000000041e142

    1. Initial program 88.1%

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

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

      [Start]88.1

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

      /-rgt-identity [<=]88.1

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

      metadata-eval [<=]88.1

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

      associate-/l* [=>]88.0

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

      associate-/r/ [=>]88.0

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

      *-commutative [<=]88.0

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

      metadata-eval [=>]88.0

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

      metadata-eval [<=]88.0

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

      associate-*l/ [<=]88.0

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

      associate-/r/ [<=]88.0

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

      times-frac [<=]88.1

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

      *-commutative [<=]88.1

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

      times-frac [=>]88.1

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

      metadata-eval [=>]88.1

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

      associate-/r/ [=>]88.1

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

      *-commutative [<=]88.1

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

      div-sub [=>]88.1

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

    if 8.00000000000000041e142 < b

    1. Initial program 41.8%

      \[\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 93.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    3. Simplified93.4%

      \[\leadsto \color{blue}{\frac{-b}{a}} \]
      Step-by-step derivation

      [Start]93.4

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

      associate-*r/ [=>]93.4

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

      mul-1-neg [=>]93.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.32 \cdot 10^{-23}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq -1.05 \cdot 10^{-97}:\\ \;\;\;\;-0.5 \cdot \frac{\frac{4 \cdot \left(c \cdot a\right)}{b - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}}{a}\\ \mathbf{elif}\;b \leq -7.5 \cdot 10^{-143}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 8 \cdot 10^{+142}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy85.6%
Cost13896
\[\begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-27}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 6 \cdot 10^{+142}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 2
Accuracy85.6%
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -5.2 \cdot 10^{-28}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 4 \cdot 10^{+143}:\\ \;\;\;\;\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 3
Accuracy79.8%
Cost7432
\[\begin{array}{l} \mathbf{if}\;b \leq -8.5 \cdot 10^{-24}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-8}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 4
Accuracy43.0%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -2.5 \cdot 10^{+85}:\\ \;\;\;\;\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 5
Accuracy68.5%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -3.7 \cdot 10^{-287}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array} \]
Alternative 6
Accuracy2.5%
Cost192
\[\frac{b}{a} \]
Alternative 7
Accuracy11.0%
Cost192
\[\frac{c}{b} \]

Reproduce?

herbie shell --seed 2023161 
(FPCore (a b c)
  :name "The quadratic formula (r2)"
  :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)))