Average Error: 34.0 → 9.5
Time: 16.5s
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{a \cdot \left(4 \cdot c\right)}{2 \cdot a} \cdot \frac{1}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \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{a \cdot \left(4 \cdot c\right)}{2 \cdot a} \cdot \frac{1}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\

\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 r62015 = b;
        double r62016 = -r62015;
        double r62017 = r62015 * r62015;
        double r62018 = 4.0;
        double r62019 = a;
        double r62020 = c;
        double r62021 = r62019 * r62020;
        double r62022 = r62018 * r62021;
        double r62023 = r62017 - r62022;
        double r62024 = sqrt(r62023);
        double r62025 = r62016 - r62024;
        double r62026 = 2.0;
        double r62027 = r62026 * r62019;
        double r62028 = r62025 / r62027;
        return r62028;
}

double f(double a, double b, double c) {
        double r62029 = b;
        double r62030 = -7.305451620439275e+42;
        bool r62031 = r62029 <= r62030;
        double r62032 = -1.0;
        double r62033 = c;
        double r62034 = r62033 / r62029;
        double r62035 = r62032 * r62034;
        double r62036 = -8.46693322491602e-96;
        bool r62037 = r62029 <= r62036;
        double r62038 = a;
        double r62039 = 4.0;
        double r62040 = r62039 * r62033;
        double r62041 = r62038 * r62040;
        double r62042 = 2.0;
        double r62043 = r62042 * r62038;
        double r62044 = r62041 / r62043;
        double r62045 = 1.0;
        double r62046 = r62029 * r62029;
        double r62047 = r62039 * r62038;
        double r62048 = r62047 * r62033;
        double r62049 = r62046 - r62048;
        double r62050 = sqrt(r62049);
        double r62051 = r62050 - r62029;
        double r62052 = r62045 / r62051;
        double r62053 = r62044 * r62052;
        double r62054 = -5.358830408552925e-132;
        bool r62055 = r62029 <= r62054;
        double r62056 = 6.326287366549383e+74;
        bool r62057 = r62029 <= r62056;
        double r62058 = -r62029;
        double r62059 = r62058 - r62050;
        double r62060 = r62059 / r62043;
        double r62061 = 1.0;
        double r62062 = r62029 / r62038;
        double r62063 = r62034 - r62062;
        double r62064 = r62061 * r62063;
        double r62065 = r62057 ? r62060 : r62064;
        double r62066 = r62055 ? r62035 : r62065;
        double r62067 = r62037 ? r62053 : r62066;
        double r62068 = r62031 ? r62035 : r62067;
        return r62068;
}

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.2

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

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

    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{a \cdot \left(4 \cdot c\right)}{2 \cdot a} \cdot \frac{1}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}\\ \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 "quadm (p42, negative)"
  :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)))