Average Error: 34.0 → 9.0
Time: 15.8s
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 -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 3.243927964746086489471681708926883768814 \cdot 10^{-167}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.092314858884959904180796965245633627496 \cdot 10^{-13}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \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 -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r6480796 = b;
        double r6480797 = -r6480796;
        double r6480798 = r6480796 * r6480796;
        double r6480799 = 4.0;
        double r6480800 = a;
        double r6480801 = r6480799 * r6480800;
        double r6480802 = c;
        double r6480803 = r6480801 * r6480802;
        double r6480804 = r6480798 - r6480803;
        double r6480805 = sqrt(r6480804);
        double r6480806 = r6480797 + r6480805;
        double r6480807 = 2.0;
        double r6480808 = r6480807 * r6480800;
        double r6480809 = r6480806 / r6480808;
        return r6480809;
}

double f(double a, double b, double c) {
        double r6480810 = b;
        double r6480811 = -8.035809894237901e+152;
        bool r6480812 = r6480810 <= r6480811;
        double r6480813 = c;
        double r6480814 = r6480813 / r6480810;
        double r6480815 = a;
        double r6480816 = r6480810 / r6480815;
        double r6480817 = r6480814 - r6480816;
        double r6480818 = 1.0;
        double r6480819 = r6480817 * r6480818;
        double r6480820 = 3.2439279647460865e-167;
        bool r6480821 = r6480810 <= r6480820;
        double r6480822 = r6480810 * r6480810;
        double r6480823 = 4.0;
        double r6480824 = r6480813 * r6480823;
        double r6480825 = r6480824 * r6480815;
        double r6480826 = r6480822 - r6480825;
        double r6480827 = sqrt(r6480826);
        double r6480828 = r6480827 - r6480810;
        double r6480829 = 2.0;
        double r6480830 = r6480815 * r6480829;
        double r6480831 = r6480828 / r6480830;
        double r6480832 = 1.0923148588849599e-13;
        bool r6480833 = r6480810 <= r6480832;
        double r6480834 = r6480822 - r6480822;
        double r6480835 = r6480823 * r6480815;
        double r6480836 = r6480813 * r6480835;
        double r6480837 = r6480834 + r6480836;
        double r6480838 = -r6480810;
        double r6480839 = r6480822 - r6480836;
        double r6480840 = sqrt(r6480839);
        double r6480841 = r6480838 - r6480840;
        double r6480842 = r6480837 / r6480841;
        double r6480843 = r6480842 / r6480830;
        double r6480844 = -1.0;
        double r6480845 = r6480844 * r6480814;
        double r6480846 = r6480833 ? r6480843 : r6480845;
        double r6480847 = r6480821 ? r6480831 : r6480846;
        double r6480848 = r6480812 ? r6480819 : r6480847;
        return r6480848;
}

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
Target21.1
Herbie9.0
\[\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 < -8.035809894237901e+152

    1. Initial program 63.6

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

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied associate-*r/63.6

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    8. Simplified2.0

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

    if -8.035809894237901e+152 < b < 3.2439279647460865e-167

    1. Initial program 10.5

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

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied associate-*r/10.5

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

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

    if 3.2439279647460865e-167 < b < 1.0923148588849599e-13

    1. Initial program 30.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-+31.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. Simplified18.4

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

    if 1.0923148588849599e-13 < b

    1. Initial program 55.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 3.243927964746086489471681708926883768814 \cdot 10^{-167}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.092314858884959904180796965245633627496 \cdot 10^{-13}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))