Average Error: 33.0 → 6.6
Time: 51.3s
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 -8.28610472349374 \cdot 10^{+140}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.931313556234952 \cdot 10^{-296}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 6.523631550102089 \cdot 10^{+89}:\\ \;\;\;\;\frac{-2 \cdot c}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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 -8.28610472349374 \cdot 10^{+140}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r5049514 = b;
        double r5049515 = -r5049514;
        double r5049516 = r5049514 * r5049514;
        double r5049517 = 4.0;
        double r5049518 = a;
        double r5049519 = c;
        double r5049520 = r5049518 * r5049519;
        double r5049521 = r5049517 * r5049520;
        double r5049522 = r5049516 - r5049521;
        double r5049523 = sqrt(r5049522);
        double r5049524 = r5049515 + r5049523;
        double r5049525 = 2.0;
        double r5049526 = r5049525 * r5049518;
        double r5049527 = r5049524 / r5049526;
        return r5049527;
}

double f(double a, double b, double c) {
        double r5049528 = b;
        double r5049529 = -8.28610472349374e+140;
        bool r5049530 = r5049528 <= r5049529;
        double r5049531 = c;
        double r5049532 = r5049531 / r5049528;
        double r5049533 = a;
        double r5049534 = r5049528 / r5049533;
        double r5049535 = r5049532 - r5049534;
        double r5049536 = 9.931313556234952e-296;
        bool r5049537 = r5049528 <= r5049536;
        double r5049538 = 1.0;
        double r5049539 = 2.0;
        double r5049540 = r5049533 * r5049539;
        double r5049541 = r5049528 * r5049528;
        double r5049542 = 4.0;
        double r5049543 = r5049542 * r5049533;
        double r5049544 = r5049543 * r5049531;
        double r5049545 = r5049541 - r5049544;
        double r5049546 = sqrt(r5049545);
        double r5049547 = r5049546 - r5049528;
        double r5049548 = r5049540 / r5049547;
        double r5049549 = r5049538 / r5049548;
        double r5049550 = 6.523631550102089e+89;
        bool r5049551 = r5049528 <= r5049550;
        double r5049552 = -2.0;
        double r5049553 = r5049552 * r5049531;
        double r5049554 = r5049531 * r5049533;
        double r5049555 = r5049554 * r5049542;
        double r5049556 = r5049541 - r5049555;
        double r5049557 = sqrt(r5049556);
        double r5049558 = r5049557 + r5049528;
        double r5049559 = r5049553 / r5049558;
        double r5049560 = -r5049532;
        double r5049561 = r5049551 ? r5049559 : r5049560;
        double r5049562 = r5049537 ? r5049549 : r5049561;
        double r5049563 = r5049530 ? r5049535 : r5049562;
        return r5049563;
}

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.0
Target20.1
Herbie6.6
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 < -8.28610472349374e+140

    1. Initial program 55.8

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

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

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

    if -8.28610472349374e+140 < b < 9.931313556234952e-296

    1. Initial program 8.7

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

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{1 \cdot b}}{2 \cdot a}\]
    5. Applied *-un-lft-identity8.7

      \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} - 1 \cdot b}{2 \cdot a}\]
    6. Applied distribute-lft-out--8.7

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

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

    if 9.931313556234952e-296 < b < 6.523631550102089e+89

    1. Initial program 32.6

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity32.6

      \[\leadsto \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{1 \cdot b}}{2 \cdot a}\]
    5. Applied *-un-lft-identity32.6

      \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} - 1 \cdot b}{2 \cdot a}\]
    6. Applied distribute-lft-out--32.6

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b \cdot b} \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}}\]
    11. Applied add-cube-cbrt32.8

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

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

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

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

      \[\leadsto \color{blue}{\left(-2 \cdot c\right)} \cdot \frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b}\]
    16. Using strategy rm
    17. Applied un-div-inv9.2

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

    if 6.523631550102089e+89 < b

    1. Initial program 58.7

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified2.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.28610472349374 \cdot 10^{+140}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.931313556234952 \cdot 10^{-296}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 6.523631550102089 \cdot 10^{+89}:\\ \;\;\;\;\frac{-2 \cdot c}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019112 
(FPCore (a b c)
  :name "quadp (p42, positive)"

  :herbie-target
  (if (< b 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)))