Average Error: 34.1 → 6.5
Time: 2.4min
Precision: binary64
Cost: 8387
Math TeX FPCore C \[\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;
}
Try it out Enter valid numbers for all inputs
Target Original 34.1 Target 20.7 Herbie 6.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 Error 6.5 Cost 8387
\[\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 Error 6.5 Cost 8387
\[\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 Error 10.1 Cost 8002
\[\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 Error 13.7 Cost 7874
\[\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 Error 13.4 Cost 8260
\[\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 Error 13.9 Cost 7618
\[\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 Error 13.8 Cost 7618
\[\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 Error 22.9 Cost 7169
\[\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 Error 22.6 Cost 577
\[\begin{array}{l}
\mathbf{if}\;b \leq 8.529742819354031 \cdot 10^{-226}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\]
Alternative 10 Error 39.7 Cost 256
\[\frac{-c}{b}\]
Alternative 11 Error 56.2 Cost 64
\[0\]
Alternative 12 Error 61.6 Cost 64
\[-1\]
Error Derivation Split input into 4 regimes if b < -4.89437030841433042e152 Initial program 63.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Simplified63.4
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}}\]
Taylor expanded around -inf 2.2
\[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
Simplified2.2
\[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
if -4.89437030841433042e152 < b < -6.61304443462778203e-283 Initial program 8.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Using strategy rm Applied add-exp-log_binary64_457 37.6
\[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot \color{blue}{e^{\log c}}\right)}}{2 \cdot a}\]
Applied add-exp-log_binary64_457 56.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}\]
Applied prod-exp_binary64_468 56.6
\[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \color{blue}{e^{\log a + \log c}}}}{2 \cdot a}\]
Applied add-exp-log_binary64_457 56.6
\[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{e^{\log 4}} \cdot e^{\log a + \log c}}}{2 \cdot a}\]
Applied prod-exp_binary64_468 56.6
\[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{e^{\log 4 + \left(\log a + \log c\right)}}}}{2 \cdot a}\]
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}\]
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}\]
Simplified8.5
\[\leadsto \frac{\color{blue}{\sqrt{b \cdot b - \frac{a \cdot -4}{\frac{-1}{c}}} - b}}{2 \cdot a}\]
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 Initial program 29.6
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Using strategy rm Applied flip-+_binary64_393 29.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}\]
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}\]
Using strategy rm Applied *-un-lft-identity_binary64_419 16.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}\]
Applied times-frac_binary64_425 16.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}\]
Applied times-frac_binary64_425 16.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}}\]
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}\]
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)}\]
Using strategy rm Applied associate-*r/_binary64_361 8.8
\[\leadsto 2 \cdot \color{blue}{\frac{1 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\]
Applied associate-*r/_binary64_361 8.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)}}}\]
Simplified8.8
\[\leadsto \frac{\color{blue}{c \cdot 2}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\]
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 Initial program 58.7
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Using strategy rm Applied flip-+_binary64_393 58.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}\]
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}\]
Using strategy rm Applied *-un-lft-identity_binary64_419 29.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}\]
Applied times-frac_binary64_425 29.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}\]
Applied times-frac_binary64_425 29.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}}\]
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}\]
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)}\]
Taylor expanded around 0 3.2
\[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
Simplified3.2
\[\leadsto \color{blue}{\frac{-c}{b}}\]
Simplified3.2
\[\leadsto \color{blue}{\frac{-c}{b}}\]
Recombined 4 regimes into one program. 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)))