Average Error: 34.6 → 10.7
Time: 27.2s
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.766818940874854722177248139872145176232 \cdot 10^{100}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 7.923524897992036987166355557663274472861 \cdot 10^{-153}:\\ \;\;\;\;\frac{\frac{1}{a \cdot 2}}{\frac{1}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \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.766818940874854722177248139872145176232 \cdot 10^{100}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r3834658 = b;
        double r3834659 = -r3834658;
        double r3834660 = r3834658 * r3834658;
        double r3834661 = 4.0;
        double r3834662 = a;
        double r3834663 = r3834661 * r3834662;
        double r3834664 = c;
        double r3834665 = r3834663 * r3834664;
        double r3834666 = r3834660 - r3834665;
        double r3834667 = sqrt(r3834666);
        double r3834668 = r3834659 + r3834667;
        double r3834669 = 2.0;
        double r3834670 = r3834669 * r3834662;
        double r3834671 = r3834668 / r3834670;
        return r3834671;
}

double f(double a, double b, double c) {
        double r3834672 = b;
        double r3834673 = -2.7668189408748547e+100;
        bool r3834674 = r3834672 <= r3834673;
        double r3834675 = c;
        double r3834676 = r3834675 / r3834672;
        double r3834677 = a;
        double r3834678 = r3834672 / r3834677;
        double r3834679 = r3834676 - r3834678;
        double r3834680 = 1.0;
        double r3834681 = r3834679 * r3834680;
        double r3834682 = 7.923524897992037e-153;
        bool r3834683 = r3834672 <= r3834682;
        double r3834684 = 1.0;
        double r3834685 = 2.0;
        double r3834686 = r3834677 * r3834685;
        double r3834687 = r3834684 / r3834686;
        double r3834688 = r3834672 * r3834672;
        double r3834689 = 4.0;
        double r3834690 = r3834677 * r3834689;
        double r3834691 = r3834690 * r3834675;
        double r3834692 = r3834688 - r3834691;
        double r3834693 = sqrt(r3834692);
        double r3834694 = r3834693 - r3834672;
        double r3834695 = r3834684 / r3834694;
        double r3834696 = r3834687 / r3834695;
        double r3834697 = -1.0;
        double r3834698 = r3834676 * r3834697;
        double r3834699 = r3834683 ? r3834696 : r3834698;
        double r3834700 = r3834674 ? r3834681 : r3834699;
        return r3834700;
}

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.6
Target21.1
Herbie10.7
\[\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.7668189408748547e+100

    1. Initial program 47.2

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

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

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    6. Simplified4.0

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

    if -2.7668189408748547e+100 < b < 7.923524897992037e-153

    1. Initial program 10.8

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

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}} - b}{2 \cdot a}\]
    6. Simplified10.8

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}}}\]
    9. Using strategy rm
    10. Applied div-inv11.0

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}}}\]
    11. Applied associate-/r*11.0

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

    if 7.923524897992037e-153 < b

    1. Initial program 50.5

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

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

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

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

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(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)))