Average Error: 33.8 → 6.7
Time: 4.9s
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 -7.70031330541463201 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.95103770532986732 \cdot 10^{-253}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.18338381295531773 \cdot 10^{98}:\\ \;\;\;\;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 -7.70031330541463201 \cdot 10^{138}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 4.18338381295531773 \cdot 10^{98}:\\
\;\;\;\;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 r63783 = b;
        double r63784 = -r63783;
        double r63785 = r63783 * r63783;
        double r63786 = 4.0;
        double r63787 = a;
        double r63788 = r63786 * r63787;
        double r63789 = c;
        double r63790 = r63788 * r63789;
        double r63791 = r63785 - r63790;
        double r63792 = sqrt(r63791);
        double r63793 = r63784 + r63792;
        double r63794 = 2.0;
        double r63795 = r63794 * r63787;
        double r63796 = r63793 / r63795;
        return r63796;
}

double f(double a, double b, double c) {
        double r63797 = b;
        double r63798 = -7.700313305414632e+138;
        bool r63799 = r63797 <= r63798;
        double r63800 = 1.0;
        double r63801 = c;
        double r63802 = r63801 / r63797;
        double r63803 = a;
        double r63804 = r63797 / r63803;
        double r63805 = r63802 - r63804;
        double r63806 = r63800 * r63805;
        double r63807 = -3.9510377053298673e-253;
        bool r63808 = r63797 <= r63807;
        double r63809 = -r63797;
        double r63810 = r63797 * r63797;
        double r63811 = 4.0;
        double r63812 = r63811 * r63803;
        double r63813 = r63812 * r63801;
        double r63814 = r63810 - r63813;
        double r63815 = sqrt(r63814);
        double r63816 = r63809 + r63815;
        double r63817 = 2.0;
        double r63818 = r63817 * r63803;
        double r63819 = r63816 / r63818;
        double r63820 = 4.183383812955318e+98;
        bool r63821 = r63797 <= r63820;
        double r63822 = 1.0;
        double r63823 = r63817 * r63801;
        double r63824 = r63809 - r63815;
        double r63825 = r63823 / r63824;
        double r63826 = r63822 * r63825;
        double r63827 = -1.0;
        double r63828 = r63827 * r63802;
        double r63829 = r63821 ? r63826 : r63828;
        double r63830 = r63808 ? r63819 : r63829;
        double r63831 = r63799 ? r63806 : r63830;
        return r63831;
}

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.8
Target21.2
Herbie6.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 4 regimes
  2. if b < -7.700313305414632e+138

    1. Initial program 57.3

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

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

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

    if -7.700313305414632e+138 < b < -3.9510377053298673e-253

    1. Initial program 8.0

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

    if -3.9510377053298673e-253 < b < 4.183383812955318e+98

    1. Initial program 29.8

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    6. Using strategy rm
    7. Applied flip-+29.9

      \[\leadsto 1 \cdot \frac{1}{\frac{2 \cdot a}{\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}}}}}\]
    8. Applied associate-/r/30.0

      \[\leadsto 1 \cdot \frac{1}{\color{blue}{\frac{2 \cdot a}{\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}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    9. Applied associate-/r*30.0

      \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{\frac{2 \cdot a}{\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}}}\]
    10. Simplified15.8

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

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

    if 4.183383812955318e+98 < b

    1. Initial program 59.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.70031330541463201 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.95103770532986732 \cdot 10^{-253}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.18338381295531773 \cdot 10^{98}:\\ \;\;\;\;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 2020065 
(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)))