Average Error: 34.1 → 6.5
Time: 2.4min
Precision: binary64
Cost: 8387
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -4.89437030841433 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -6.613044434627782 \cdot 10^{-283}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \frac{a \cdot -4}{\frac{-1}{c}}} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 4.816931246986667 \cdot 10^{+76}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -4.89437030841433 \cdot 10^{+152}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -6.613044434627782 \cdot 10^{-283}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \frac{a \cdot -4}{\frac{-1}{c}}} - b}{a \cdot 2}\\

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

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

\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 -4.89437030841433e+152)
   (- (/ c b) (/ b a))
   (if (<= b -6.613044434627782e-283)
     (/ (- (sqrt (- (* b b) (/ (* a -4.0) (/ -1.0 c)))) b) (* a 2.0))
     (if (<= b 4.816931246986667e+76)
       (/ (* c 2.0) (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))))
       (/ (- c) b)))))
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 <= -4.89437030841433e+152) {
		tmp = (c / b) - (b / a);
	} else if (b <= -6.613044434627782e-283) {
		tmp = (sqrt((b * b) - ((a * -4.0) / (-1.0 / c))) - b) / (a * 2.0);
	} else if (b <= 4.816931246986667e+76) {
		tmp = (c * 2.0) / (-b - sqrt((b * b) - (4.0 * (c * a))));
	} else {
		tmp = -c / b;
	}
	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.1
Target20.7
Herbie6.5
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array}\]

Alternatives

Alternative 1
Error6.5
Cost8387
\[\begin{array}{l} \mathbf{if}\;b \leq -4.0737268480388477 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -2.8094746472583994 \cdot 10^{-281}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 4.816931246986667 \cdot 10^{+76}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 2
Error6.5
Cost8387
\[\begin{array}{l} \mathbf{if}\;b \leq -4.191727865581558 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -9.078145301820259 \cdot 10^{-283}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 9.7059850177998 \cdot 10^{+76}:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 3
Error10.1
Cost8002
\[\begin{array}{l} \mathbf{if}\;b \leq -6.065441046468951 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.0684527239595751 \cdot 10^{-19}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 4
Error13.7
Cost7874
\[\begin{array}{l} \mathbf{if}\;b \leq -6.666572808649524 \cdot 10^{-25}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.595244068316303 \cdot 10^{-20}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 5
Error13.4
Cost8260
\[\begin{array}{l} \mathbf{if}\;b \leq -1.0036134703492082 \cdot 10^{-42}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.624296268777243 \cdot 10^{-68}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 2.1306939922765858 \cdot 10^{-52}:\\ \;\;\;\;2 \cdot \frac{c}{2 \cdot \left(\frac{c \cdot a}{b} - b\right)}\\ \mathbf{elif}\;b \leq 6.322625190231006 \cdot 10^{-20}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 6
Error13.9
Cost7618
\[\begin{array}{l} \mathbf{if}\;b \leq -5.614797585418129 \cdot 10^{-41}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.322625190231006 \cdot 10^{-20}:\\ \;\;\;\;-2 \cdot \frac{c}{\sqrt{-4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 7
Error13.8
Cost7618
\[\begin{array}{l} \mathbf{if}\;b \leq -1.036257904214663 \cdot 10^{-42}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 6.322625190231006 \cdot 10^{-20}:\\ \;\;\;\;0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 8
Error22.9
Cost7169
\[\begin{array}{l} \mathbf{if}\;b \leq 4.2341774179204834 \cdot 10^{-169}:\\ \;\;\;\;\frac{\left|b\right| - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 9
Error22.6
Cost577
\[\begin{array}{l} \mathbf{if}\;b \leq 8.529742819354031 \cdot 10^{-226}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]
Alternative 10
Error39.7
Cost256
\[\frac{-c}{b}\]
Alternative 11
Error56.2
Cost64
\[0\]
Alternative 12
Error61.6
Cost64
\[-1\]

Error

Derivation

  1. Split input into 4 regimes
  2. if b < -4.89437030841433042e152

    1. Initial program 63.4

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

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

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

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

    if -4.89437030841433042e152 < b < -6.61304443462778203e-283

    1. Initial program 8.5

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot \color{blue}{e^{\log c}}\right)}}{2 \cdot a}\]
    4. Applied add-exp-log_binary64_45756.6

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(\color{blue}{e^{\log a}} \cdot e^{\log c}\right)}}{2 \cdot a}\]
    5. Applied prod-exp_binary64_46856.6

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \color{blue}{e^{\log a + \log c}}}}{2 \cdot a}\]
    6. Applied add-exp-log_binary64_45756.6

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{e^{\log 4}} \cdot e^{\log a + \log c}}}{2 \cdot a}\]
    7. Applied prod-exp_binary64_46856.6

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{e^{\log 4 + \left(\log a + \log c\right)}}}}{2 \cdot a}\]
    8. Simplified44.9

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - e^{\color{blue}{\log \left(4 \cdot \left(a \cdot c\right)\right)}}}}{2 \cdot a}\]
    9. Taylor expanded around -inf 56.1

      \[\leadsto \frac{\color{blue}{\sqrt{{b}^{2} - e^{\log \left(-4 \cdot a\right) - \log \left(\frac{-1}{c}\right)}} - b}}{2 \cdot a}\]
    10. Simplified8.5

      \[\leadsto \frac{\color{blue}{\sqrt{b \cdot b - \frac{a \cdot -4}{\frac{-1}{c}}} - b}}{2 \cdot a}\]
    11. Simplified8.5

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

    if -6.61304443462778203e-283 < b < 4.81693124698666678e76

    1. Initial program 29.6

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.81693124698666678e76 < b

    1. Initial program 58.7

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-c}{b}}\]
    13. Simplified3.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.89437030841433 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -6.613044434627782 \cdot 10^{-283}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \frac{a \cdot -4}{\frac{-1}{c}}} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 4.816931246986667 \cdot 10^{+76}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2021014 
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :precision binary64
  :herbie-expected #f

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