Average Error: 34.0 → 9.5
Time: 6.8s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -7305451620439275194790110408477452101747000:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -8.466933224916020404836136928197301032481 \cdot 10^{-96}:\\ \;\;\;\;\frac{\frac{1}{2} \cdot \left(\left({b}^{2} - {b}^{2}\right) + \left(4 \cdot a\right) \cdot c\right)}{a} \cdot \frac{1}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{elif}\;b \le -5.358830408552924876342396298354647853638 \cdot 10^{-132}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 6.326287366549382745037046972324082366467 \cdot 10^{74}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -7305451620439275194790110408477452101747000:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{elif}\;b \le -5.358830408552924876342396298354647853638 \cdot 10^{-132}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r76827 = b;
        double r76828 = -r76827;
        double r76829 = r76827 * r76827;
        double r76830 = 4.0;
        double r76831 = a;
        double r76832 = c;
        double r76833 = r76831 * r76832;
        double r76834 = r76830 * r76833;
        double r76835 = r76829 - r76834;
        double r76836 = sqrt(r76835);
        double r76837 = r76828 - r76836;
        double r76838 = 2.0;
        double r76839 = r76838 * r76831;
        double r76840 = r76837 / r76839;
        return r76840;
}

double f(double a, double b, double c) {
        double r76841 = b;
        double r76842 = -7.305451620439275e+42;
        bool r76843 = r76841 <= r76842;
        double r76844 = -1.0;
        double r76845 = c;
        double r76846 = r76845 / r76841;
        double r76847 = r76844 * r76846;
        double r76848 = -8.46693322491602e-96;
        bool r76849 = r76841 <= r76848;
        double r76850 = 1.0;
        double r76851 = 2.0;
        double r76852 = r76850 / r76851;
        double r76853 = 2.0;
        double r76854 = pow(r76841, r76853);
        double r76855 = r76854 - r76854;
        double r76856 = 4.0;
        double r76857 = a;
        double r76858 = r76856 * r76857;
        double r76859 = r76858 * r76845;
        double r76860 = r76855 + r76859;
        double r76861 = r76852 * r76860;
        double r76862 = r76861 / r76857;
        double r76863 = -r76841;
        double r76864 = r76841 * r76841;
        double r76865 = r76864 - r76859;
        double r76866 = sqrt(r76865);
        double r76867 = r76863 + r76866;
        double r76868 = r76850 / r76867;
        double r76869 = r76862 * r76868;
        double r76870 = -5.358830408552925e-132;
        bool r76871 = r76841 <= r76870;
        double r76872 = 6.326287366549383e+74;
        bool r76873 = r76841 <= r76872;
        double r76874 = r76863 - r76866;
        double r76875 = r76851 * r76857;
        double r76876 = r76874 / r76875;
        double r76877 = 1.0;
        double r76878 = r76841 / r76857;
        double r76879 = r76846 - r76878;
        double r76880 = r76877 * r76879;
        double r76881 = r76873 ? r76876 : r76880;
        double r76882 = r76871 ? r76847 : r76881;
        double r76883 = r76849 ? r76869 : r76882;
        double r76884 = r76843 ? r76847 : r76883;
        return r76884;
}

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.0
Target20.9
Herbie9.5
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -7.305451620439275e+42 or -8.46693322491602e-96 < b < -5.358830408552925e-132

    1. Initial program 54.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if -7.305451620439275e+42 < b < -8.46693322491602e-96

    1. Initial program 41.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*r*41.7

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

      \[\leadsto \color{blue}{\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--41.8

      \[\leadsto \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/41.8

      \[\leadsto \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 add-cube-cbrt41.8

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{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}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    10. Applied times-frac41.8

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{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}}} \cdot \frac{\sqrt[3]{1}}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    11. Simplified16.3

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

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

    if -5.358830408552925e-132 < b < 6.326287366549383e+74

    1. Initial program 11.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*r*11.6

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

    if 6.326287366549383e+74 < b

    1. Initial program 41.8

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

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

      \[\leadsto \color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7305451620439275194790110408477452101747000:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -8.466933224916020404836136928197301032481 \cdot 10^{-96}:\\ \;\;\;\;\frac{\frac{1}{2} \cdot \left(\left({b}^{2} - {b}^{2}\right) + \left(4 \cdot a\right) \cdot c\right)}{a} \cdot \frac{1}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{elif}\;b \le -5.358830408552924876342396298354647853638 \cdot 10^{-132}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 6.326287366549382745037046972324082366467 \cdot 10^{74}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

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

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

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