Average Error: 33.8 → 9.7
Time: 15.3s
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.6257289292067596 \cdot 10^{+144}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 1.739098950628615 \cdot 10^{-79}:\\ \;\;\;\;\frac{\frac{1}{\frac{a}{\sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4} - b}}}{2}\\ \mathbf{elif}\;b \le 1.8656332031849816 \cdot 10^{-25}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 5.297236684235463 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{1}{\frac{a}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b \cdot b}} \cdot \frac{1}{b + \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \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.6257289292067596 \cdot 10^{+144}:\\
\;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\

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

\mathbf{elif}\;b \le 1.8656332031849816 \cdot 10^{-25}:\\
\;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r1456658 = b;
        double r1456659 = -r1456658;
        double r1456660 = r1456658 * r1456658;
        double r1456661 = 4.0;
        double r1456662 = a;
        double r1456663 = r1456661 * r1456662;
        double r1456664 = c;
        double r1456665 = r1456663 * r1456664;
        double r1456666 = r1456660 - r1456665;
        double r1456667 = sqrt(r1456666);
        double r1456668 = r1456659 + r1456667;
        double r1456669 = 2.0;
        double r1456670 = r1456669 * r1456662;
        double r1456671 = r1456668 / r1456670;
        return r1456671;
}

double f(double a, double b, double c) {
        double r1456672 = b;
        double r1456673 = -1.6257289292067596e+144;
        bool r1456674 = r1456672 <= r1456673;
        double r1456675 = c;
        double r1456676 = r1456675 / r1456672;
        double r1456677 = a;
        double r1456678 = r1456672 / r1456677;
        double r1456679 = r1456676 - r1456678;
        double r1456680 = 2.0;
        double r1456681 = r1456679 * r1456680;
        double r1456682 = r1456681 / r1456680;
        double r1456683 = 1.739098950628615e-79;
        bool r1456684 = r1456672 <= r1456683;
        double r1456685 = 1.0;
        double r1456686 = r1456672 * r1456672;
        double r1456687 = r1456677 * r1456675;
        double r1456688 = -4.0;
        double r1456689 = r1456687 * r1456688;
        double r1456690 = r1456686 + r1456689;
        double r1456691 = sqrt(r1456690);
        double r1456692 = r1456691 - r1456672;
        double r1456693 = r1456677 / r1456692;
        double r1456694 = r1456685 / r1456693;
        double r1456695 = r1456694 / r1456680;
        double r1456696 = 1.8656332031849816e-25;
        bool r1456697 = r1456672 <= r1456696;
        double r1456698 = -2.0;
        double r1456699 = r1456698 * r1456676;
        double r1456700 = r1456699 / r1456680;
        double r1456701 = 5.297236684235463e-16;
        bool r1456702 = r1456672 <= r1456701;
        double r1456703 = 4.0;
        double r1456704 = r1456687 * r1456703;
        double r1456705 = r1456686 - r1456704;
        double r1456706 = sqrt(r1456705);
        double r1456707 = r1456706 * r1456706;
        double r1456708 = r1456707 - r1456686;
        double r1456709 = r1456677 / r1456708;
        double r1456710 = r1456685 / r1456709;
        double r1456711 = r1456672 + r1456706;
        double r1456712 = r1456685 / r1456711;
        double r1456713 = r1456710 * r1456712;
        double r1456714 = r1456713 / r1456680;
        double r1456715 = r1456702 ? r1456714 : r1456700;
        double r1456716 = r1456697 ? r1456700 : r1456715;
        double r1456717 = r1456684 ? r1456695 : r1456716;
        double r1456718 = r1456674 ? r1456682 : r1456717;
        return r1456718;
}

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
Target20.3
Herbie9.7
\[\begin{array}{l} \mathbf{if}\;b \lt 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.6257289292067596e+144

    1. Initial program 58.0

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}{2}\]
    4. Simplified2.5

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

    if -1.6257289292067596e+144 < b < 1.739098950628615e-79

    1. Initial program 11.7

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

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

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

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

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

    if 1.739098950628615e-79 < b < 1.8656332031849816e-25 or 5.297236684235463e-16 < b

    1. Initial program 53.2

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

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

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

    if 1.8656332031849816e-25 < b < 5.297236684235463e-16

    1. Initial program 42.7

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6257289292067596 \cdot 10^{+144}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 1.739098950628615 \cdot 10^{-79}:\\ \;\;\;\;\frac{\frac{1}{\frac{a}{\sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4} - b}}}{2}\\ \mathbf{elif}\;b \le 1.8656332031849816 \cdot 10^{-25}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 5.297236684235463 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{1}{\frac{a}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b \cdot b}} \cdot \frac{1}{b + \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :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)))