Average Error: 34.2 → 6.5
Time: 17.8s
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.844003813175822562359270713493973222617 \cdot 10^{119}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.193871707188482833811342019428468815697 \cdot 10^{-287}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.521192511657275894218075856706322414394 \cdot 10^{99}:\\ \;\;\;\;1 \cdot \frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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.844003813175822562359270713493973222617 \cdot 10^{119}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r66710 = b;
        double r66711 = -r66710;
        double r66712 = r66710 * r66710;
        double r66713 = 4.0;
        double r66714 = a;
        double r66715 = r66713 * r66714;
        double r66716 = c;
        double r66717 = r66715 * r66716;
        double r66718 = r66712 - r66717;
        double r66719 = sqrt(r66718);
        double r66720 = r66711 + r66719;
        double r66721 = 2.0;
        double r66722 = r66721 * r66714;
        double r66723 = r66720 / r66722;
        return r66723;
}

double f(double a, double b, double c) {
        double r66724 = b;
        double r66725 = -1.8440038131758226e+119;
        bool r66726 = r66724 <= r66725;
        double r66727 = 1.0;
        double r66728 = c;
        double r66729 = r66728 / r66724;
        double r66730 = a;
        double r66731 = r66724 / r66730;
        double r66732 = r66729 - r66731;
        double r66733 = r66727 * r66732;
        double r66734 = -4.193871707188483e-287;
        bool r66735 = r66724 <= r66734;
        double r66736 = -r66724;
        double r66737 = r66724 * r66724;
        double r66738 = 4.0;
        double r66739 = r66738 * r66730;
        double r66740 = r66739 * r66728;
        double r66741 = r66737 - r66740;
        double r66742 = sqrt(r66741);
        double r66743 = r66736 + r66742;
        double r66744 = 1.0;
        double r66745 = 2.0;
        double r66746 = r66745 * r66730;
        double r66747 = r66744 / r66746;
        double r66748 = r66743 * r66747;
        double r66749 = 2.521192511657276e+99;
        bool r66750 = r66724 <= r66749;
        double r66751 = r66745 * r66728;
        double r66752 = r66736 - r66742;
        double r66753 = r66751 / r66752;
        double r66754 = r66744 * r66753;
        double r66755 = -1.0;
        double r66756 = r66755 * r66729;
        double r66757 = r66750 ? r66754 : r66756;
        double r66758 = r66735 ? r66748 : r66757;
        double r66759 = r66726 ? r66733 : r66758;
        return r66759;
}

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.1
Herbie6.5
\[\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 4 regimes
  2. if b < -1.8440038131758226e+119

    1. Initial program 51.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf 3.0

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

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

    if -1.8440038131758226e+119 < b < -4.193871707188483e-287

    1. Initial program 8.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv8.4

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

    if -4.193871707188483e-287 < b < 2.521192511657276e+99

    1. Initial program 31.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+31.7

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

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied div-inv16.8

      \[\leadsto \color{blue}{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \frac{1}{2 \cdot a}}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity16.8

      \[\leadsto \frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}} \cdot \frac{1}{2 \cdot a}\]
    9. Applied *-un-lft-identity16.8

      \[\leadsto \frac{\color{blue}{1 \cdot \left(0 + 4 \cdot \left(a \cdot c\right)\right)}}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} \cdot \frac{1}{2 \cdot a}\]
    10. Applied times-frac16.8

      \[\leadsto \color{blue}{\left(\frac{1}{1} \cdot \frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)} \cdot \frac{1}{2 \cdot a}\]
    11. Applied associate-*l*16.8

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

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

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

    if 2.521192511657276e+99 < b

    1. Initial program 59.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 2.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.844003813175822562359270713493973222617 \cdot 10^{119}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -4.193871707188482833811342019428468815697 \cdot 10^{-287}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.521192511657275894218075856706322414394 \cdot 10^{99}:\\ \;\;\;\;1 \cdot \frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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