Average Error: 34.2 → 10.4
Time: 15.3s
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 -2.063494556122608953103184521416208568921 \cdot 10^{74}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 3.561827827173035262135227954892736389 \cdot 10^{-90}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b} \cdot 2}\\ \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 -2.063494556122608953103184521416208568921 \cdot 10^{74}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r58707 = b;
        double r58708 = -r58707;
        double r58709 = r58707 * r58707;
        double r58710 = 4.0;
        double r58711 = a;
        double r58712 = r58710 * r58711;
        double r58713 = c;
        double r58714 = r58712 * r58713;
        double r58715 = r58709 - r58714;
        double r58716 = sqrt(r58715);
        double r58717 = r58708 + r58716;
        double r58718 = 2.0;
        double r58719 = r58718 * r58711;
        double r58720 = r58717 / r58719;
        return r58720;
}

double f(double a, double b, double c) {
        double r58721 = b;
        double r58722 = -2.063494556122609e+74;
        bool r58723 = r58721 <= r58722;
        double r58724 = c;
        double r58725 = r58724 / r58721;
        double r58726 = a;
        double r58727 = r58721 / r58726;
        double r58728 = r58725 - r58727;
        double r58729 = 1.0;
        double r58730 = r58728 * r58729;
        double r58731 = 3.5618278271730353e-90;
        bool r58732 = r58721 <= r58731;
        double r58733 = 1.0;
        double r58734 = r58721 * r58721;
        double r58735 = r58726 * r58724;
        double r58736 = 4.0;
        double r58737 = r58735 * r58736;
        double r58738 = r58734 - r58737;
        double r58739 = sqrt(r58738);
        double r58740 = r58739 - r58721;
        double r58741 = r58726 / r58740;
        double r58742 = 2.0;
        double r58743 = r58741 * r58742;
        double r58744 = r58733 / r58743;
        double r58745 = -1.0;
        double r58746 = r58745 * r58725;
        double r58747 = r58732 ? r58744 : r58746;
        double r58748 = r58723 ? r58730 : r58747;
        return r58748;
}

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.2
Target21.0
Herbie10.4
\[\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 < -2.063494556122609e+74

    1. Initial program 41.4

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

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

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

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

    if -2.063494556122609e+74 < b < 3.5618278271730353e-90

    1. Initial program 13.1

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

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

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

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

    if 3.5618278271730353e-90 < b

    1. Initial program 52.9

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

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

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

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

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

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

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

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

Reproduce

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

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

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