Average Error: 33.7 → 10.9
Time: 9.4s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.98276540088900058 \cdot 10^{134}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.1860189201379418 \cdot 10^{-161}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{\frac{1}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -1.98276540088900058 \cdot 10^{134}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 1.1860189201379418 \cdot 10^{-161}:\\
\;\;\;\;\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{\frac{1}{2}}{a}\\

\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\end{array}
double f(double a, double b, double c) {
        double r166590 = b;
        double r166591 = -r166590;
        double r166592 = r166590 * r166590;
        double r166593 = 4.0;
        double r166594 = a;
        double r166595 = r166593 * r166594;
        double r166596 = c;
        double r166597 = r166595 * r166596;
        double r166598 = r166592 - r166597;
        double r166599 = sqrt(r166598);
        double r166600 = r166591 + r166599;
        double r166601 = 2.0;
        double r166602 = r166601 * r166594;
        double r166603 = r166600 / r166602;
        return r166603;
}

double f(double a, double b, double c) {
        double r166604 = b;
        double r166605 = -1.9827654008890006e+134;
        bool r166606 = r166604 <= r166605;
        double r166607 = 1.0;
        double r166608 = c;
        double r166609 = r166608 / r166604;
        double r166610 = a;
        double r166611 = r166604 / r166610;
        double r166612 = r166609 - r166611;
        double r166613 = r166607 * r166612;
        double r166614 = 1.1860189201379418e-161;
        bool r166615 = r166604 <= r166614;
        double r166616 = r166604 * r166604;
        double r166617 = 4.0;
        double r166618 = r166617 * r166610;
        double r166619 = r166618 * r166608;
        double r166620 = r166616 - r166619;
        double r166621 = sqrt(r166620);
        double r166622 = r166621 - r166604;
        double r166623 = 1.0;
        double r166624 = 2.0;
        double r166625 = r166623 / r166624;
        double r166626 = r166625 / r166610;
        double r166627 = r166622 * r166626;
        double r166628 = -1.0;
        double r166629 = r166628 * r166609;
        double r166630 = r166615 ? r166627 : r166629;
        double r166631 = r166606 ? r166613 : r166630;
        return r166631;
}

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

Original33.7
Target21.0
Herbie10.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if b < -1.9827654008890006e+134

    1. Initial program 56.8

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Taylor expanded around -inf 3.1

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

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

    if -1.9827654008890006e+134 < b < 1.1860189201379418e-161

    1. Initial program 10.3

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity10.3

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{\color{blue}{1 \cdot a}}\]
    5. Applied div-inv10.3

      \[\leadsto \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2}}}{1 \cdot a}\]
    6. Applied times-frac10.5

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

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

    if 1.1860189201379418e-161 < b

    1. Initial program 49.7

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Taylor expanded around inf 13.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.98276540088900058 \cdot 10^{134}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.1860189201379418 \cdot 10^{-161}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{\frac{1}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

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

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))