Average Error: 34.0 → 28.7
Time: 6.1s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.3398860289927658 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{-b}}\\ \mathbf{elif}\;b \leq 3.302437054159807 \cdot 10^{+102}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b} \cdot \frac{1}{a}}{\frac{2}{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \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 \leq -1.3398860289927658 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\frac{a \cdot 2}{-b}}\\

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

\mathbf{else}:\\
\;\;\;\;0\\

\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.3398860289927658e+154)
   (/ 1.0 (/ (* a 2.0) (- b)))
   (if (<= b 3.302437054159807e+102)
     (/
      (* (sqrt (- (sqrt (- (* b b) (* (* a 4.0) c))) b)) (/ 1.0 a))
      (/ 2.0 (sqrt (- (sqrt (- (* b b) (* (* a 4.0) c))) b))))
     0.0)))
double code(double a, double b, double c) {
	return (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.3398860289927658e+154) {
		tmp = 1.0 / ((a * 2.0) / -b);
	} else if (b <= 3.302437054159807e+102) {
		tmp = (sqrt(sqrt((b * b) - ((a * 4.0) * c)) - b) * (1.0 / a)) / (2.0 / sqrt(sqrt((b * b) - ((a * 4.0) * c)) - b));
	} else {
		tmp = 0.0;
	}
	return tmp;
}

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
Herbie28.7
\[\begin{array}{l} \mathbf{if}\;b < 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 3 regimes
  2. if b < -1.33988602899276581e154

    1. Initial program 64.0

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{a \cdot 2}{\color{blue}{0} - b}}\]

    if -1.33988602899276581e154 < b < 3.3024370541598071e102

    1. Initial program 19.8

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

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

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

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

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

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

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

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

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

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

    if 3.3024370541598071e102 < b

    1. Initial program 60.1

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

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

      \[\leadsto \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification28.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3398860289927658 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{-b}}\\ \mathbf{elif}\;b \leq 3.302437054159807 \cdot 10^{+102}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b} \cdot \frac{1}{a}}{\frac{2}{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

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

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