Average Error: 34.1 → 6.5
Time: 5.5s
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.7431685240570133 \cdot 10^{102}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.0417939395900796 \cdot 10^{-259}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\ \;\;\;\;\left(\frac{\frac{1}{\sqrt[3]{1} \cdot \sqrt[3]{1}}}{2} \cdot \left(c \cdot 4\right)\right) \cdot \frac{\frac{1}{\sqrt[3]{1}}}{\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 -1.7431685240570133 \cdot 10^{102}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\
\;\;\;\;\left(\frac{\frac{1}{\sqrt[3]{1} \cdot \sqrt[3]{1}}}{2} \cdot \left(c \cdot 4\right)\right) \cdot \frac{\frac{1}{\sqrt[3]{1}}}{\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 r103658 = b;
        double r103659 = -r103658;
        double r103660 = r103658 * r103658;
        double r103661 = 4.0;
        double r103662 = a;
        double r103663 = r103661 * r103662;
        double r103664 = c;
        double r103665 = r103663 * r103664;
        double r103666 = r103660 - r103665;
        double r103667 = sqrt(r103666);
        double r103668 = r103659 + r103667;
        double r103669 = 2.0;
        double r103670 = r103669 * r103662;
        double r103671 = r103668 / r103670;
        return r103671;
}

double f(double a, double b, double c) {
        double r103672 = b;
        double r103673 = -1.7431685240570133e+102;
        bool r103674 = r103672 <= r103673;
        double r103675 = 1.0;
        double r103676 = c;
        double r103677 = r103676 / r103672;
        double r103678 = a;
        double r103679 = r103672 / r103678;
        double r103680 = r103677 - r103679;
        double r103681 = r103675 * r103680;
        double r103682 = 1.0417939395900796e-259;
        bool r103683 = r103672 <= r103682;
        double r103684 = -r103672;
        double r103685 = r103672 * r103672;
        double r103686 = 4.0;
        double r103687 = r103686 * r103678;
        double r103688 = r103687 * r103676;
        double r103689 = r103685 - r103688;
        double r103690 = sqrt(r103689);
        double r103691 = r103684 + r103690;
        double r103692 = 2.0;
        double r103693 = r103692 * r103678;
        double r103694 = r103691 / r103693;
        double r103695 = 9.373511171447418e+103;
        bool r103696 = r103672 <= r103695;
        double r103697 = 1.0;
        double r103698 = cbrt(r103697);
        double r103699 = r103698 * r103698;
        double r103700 = r103697 / r103699;
        double r103701 = r103700 / r103692;
        double r103702 = r103676 * r103686;
        double r103703 = r103701 * r103702;
        double r103704 = r103697 / r103698;
        double r103705 = r103684 - r103690;
        double r103706 = r103704 / r103705;
        double r103707 = r103703 * r103706;
        double r103708 = -1.0;
        double r103709 = r103708 * r103677;
        double r103710 = r103696 ? r103707 : r103709;
        double r103711 = r103683 ? r103694 : r103710;
        double r103712 = r103674 ? r103681 : r103711;
        return r103712;
}

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.1
Target20.5
Herbie6.5
\[\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 < -1.7431685240570133e+102

    1. Initial program 47.5

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

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

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

    if -1.7431685240570133e+102 < b < 1.0417939395900796e-259

    1. Initial program 9.7

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

    if 1.0417939395900796e-259 < b < 9.373511171447418e+103

    1. Initial program 34.9

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

      \[\leadsto \frac{\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}}}}{2 \cdot a}\]
    4. Simplified17.0

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    11. Using strategy rm
    12. Applied associate-/l*16.1

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

      \[\leadsto \frac{\frac{1}{1}}{\frac{2}{\color{blue}{\frac{c \cdot 4}{1}}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    14. Using strategy rm
    15. Applied add-cube-cbrt8.3

      \[\leadsto \frac{\frac{1}{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}}{\frac{2}{\frac{c \cdot 4}{1}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    16. Applied add-sqr-sqrt8.3

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

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

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

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

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

    if 9.373511171447418e+103 < b

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7431685240570133 \cdot 10^{102}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.0417939395900796 \cdot 10^{-259}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\ \;\;\;\;\left(\frac{\frac{1}{\sqrt[3]{1} \cdot \sqrt[3]{1}}}{2} \cdot \left(c \cdot 4\right)\right) \cdot \frac{\frac{1}{\sqrt[3]{1}}}{\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 2020024 +o rules:numerics
(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)))