Average Error: 33.5 → 11.9
Time: 27.0s
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.3725796156555912 \cdot 10^{+127}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 3.207624111695675 \cdot 10^{-187}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} - \frac{b}{a}}{2}\\ \mathbf{elif}\;b \le 4.664677641347216 \cdot 10^{-111}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 1.922674299151799 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{\frac{b \cdot b - \left(\left(4 \cdot a\right) \cdot c + b \cdot b\right)}{a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} + b}}{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.3725796156555912 \cdot 10^{+127}:\\
\;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\

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

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r5709775 = b;
        double r5709776 = -r5709775;
        double r5709777 = r5709775 * r5709775;
        double r5709778 = 4.0;
        double r5709779 = a;
        double r5709780 = r5709778 * r5709779;
        double r5709781 = c;
        double r5709782 = r5709780 * r5709781;
        double r5709783 = r5709777 - r5709782;
        double r5709784 = sqrt(r5709783);
        double r5709785 = r5709776 + r5709784;
        double r5709786 = 2.0;
        double r5709787 = r5709786 * r5709779;
        double r5709788 = r5709785 / r5709787;
        return r5709788;
}

double f(double a, double b, double c) {
        double r5709789 = b;
        double r5709790 = -1.3725796156555912e+127;
        bool r5709791 = r5709789 <= r5709790;
        double r5709792 = c;
        double r5709793 = r5709792 / r5709789;
        double r5709794 = a;
        double r5709795 = r5709789 / r5709794;
        double r5709796 = r5709793 - r5709795;
        double r5709797 = 2.0;
        double r5709798 = r5709796 * r5709797;
        double r5709799 = r5709798 / r5709797;
        double r5709800 = 3.207624111695675e-187;
        bool r5709801 = r5709789 <= r5709800;
        double r5709802 = r5709789 * r5709789;
        double r5709803 = 4.0;
        double r5709804 = r5709794 * r5709792;
        double r5709805 = r5709803 * r5709804;
        double r5709806 = r5709802 - r5709805;
        double r5709807 = sqrt(r5709806);
        double r5709808 = r5709807 / r5709794;
        double r5709809 = r5709808 - r5709795;
        double r5709810 = r5709809 / r5709797;
        double r5709811 = 4.664677641347216e-111;
        bool r5709812 = r5709789 <= r5709811;
        double r5709813 = -2.0;
        double r5709814 = r5709813 * r5709793;
        double r5709815 = r5709814 / r5709797;
        double r5709816 = 1.922674299151799e-16;
        bool r5709817 = r5709789 <= r5709816;
        double r5709818 = r5709803 * r5709794;
        double r5709819 = r5709818 * r5709792;
        double r5709820 = r5709819 + r5709802;
        double r5709821 = r5709802 - r5709820;
        double r5709822 = r5709821 / r5709794;
        double r5709823 = r5709807 + r5709789;
        double r5709824 = r5709822 / r5709823;
        double r5709825 = r5709824 / r5709797;
        double r5709826 = r5709817 ? r5709825 : r5709815;
        double r5709827 = r5709812 ? r5709815 : r5709826;
        double r5709828 = r5709801 ? r5709810 : r5709827;
        double r5709829 = r5709791 ? r5709799 : r5709828;
        return r5709829;
}

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.5
Target21.2
Herbie11.9
\[\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.3725796156555912e+127

    1. Initial program 51.4

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

      \[\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.3

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

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

    if -1.3725796156555912e+127 < b < 3.207624111695675e-187

    1. Initial program 10.4

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

      \[\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 div-sub10.4

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

    if 3.207624111695675e-187 < b < 4.664677641347216e-111 or 1.922674299151799e-16 < b

    1. Initial program 50.1

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

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

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

    if 4.664677641347216e-111 < b < 1.922674299151799e-16

    1. Initial program 36.3

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

      \[\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 *-un-lft-identity36.3

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\frac{1}{a}}{\frac{1}{\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}\]
    13. Applied associate-/r/36.5

      \[\leadsto \frac{\frac{\frac{1}{a}}{\color{blue}{\frac{1}{\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}\]
    14. Applied associate-/r*36.5

      \[\leadsto \frac{\color{blue}{\frac{\frac{\frac{1}{a}}{\frac{1}{\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}\]
    15. Simplified36.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3725796156555912 \cdot 10^{+127}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 3.207624111695675 \cdot 10^{-187}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} - \frac{b}{a}}{2}\\ \mathbf{elif}\;b \le 4.664677641347216 \cdot 10^{-111}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \mathbf{elif}\;b \le 1.922674299151799 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{\frac{b \cdot b - \left(\left(4 \cdot a\right) \cdot c + b \cdot b\right)}{a}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} + b}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019139 
(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)))