
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -2e+26)
(/ (- c) b)
(if (<= b -4.2e-181)
(/ (* c -2.0) (- b (hypot b (sqrt (* a (* c -4.0))))))
(if (<= b 4.2e+109)
(/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) (- (* a 2.0)))
(- (/ c b) (/ b a))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+26) {
tmp = -c / b;
} else if (b <= -4.2e-181) {
tmp = (c * -2.0) / (b - hypot(b, sqrt((a * (c * -4.0)))));
} else if (b <= 4.2e+109) {
tmp = (b + sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e+26) {
tmp = -c / b;
} else if (b <= -4.2e-181) {
tmp = (c * -2.0) / (b - Math.hypot(b, Math.sqrt((a * (c * -4.0)))));
} else if (b <= 4.2e+109) {
tmp = (b + Math.sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+26: tmp = -c / b elif b <= -4.2e-181: tmp = (c * -2.0) / (b - math.hypot(b, math.sqrt((a * (c * -4.0))))) elif b <= 4.2e+109: tmp = (b + math.sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+26) tmp = Float64(Float64(-c) / b); elseif (b <= -4.2e-181) tmp = Float64(Float64(c * -2.0) / Float64(b - hypot(b, sqrt(Float64(a * Float64(c * -4.0)))))); elseif (b <= 4.2e+109) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(-Float64(a * 2.0))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e+26) tmp = -c / b; elseif (b <= -4.2e-181) tmp = (c * -2.0) / (b - hypot(b, sqrt((a * (c * -4.0))))); elseif (b <= 4.2e+109) tmp = (b + sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+26], N[((-c) / b), $MachinePrecision], If[LessEqual[b, -4.2e-181], N[(N[(c * -2.0), $MachinePrecision] / N[(b - N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e+109], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / (-N[(a * 2.0), $MachinePrecision])), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+26}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq -4.2 \cdot 10^{-181}:\\
\;\;\;\;\frac{c \cdot -2}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+109}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{-a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.0000000000000001e26Initial program 7.4%
div-sub5.5%
sub-neg5.5%
neg-mul-15.5%
*-commutative5.5%
associate-/l*3.0%
distribute-neg-frac3.0%
neg-mul-13.0%
*-commutative3.0%
associate-/l*5.5%
distribute-rgt-out7.4%
associate-/r*7.4%
metadata-eval7.4%
fma-neg7.4%
*-commutative7.4%
*-commutative7.4%
Simplified7.4%
Taylor expanded in b around -inf 90.1%
associate-*r/90.1%
neg-mul-190.1%
Simplified90.1%
if -2.0000000000000001e26 < b < -4.20000000000000006e-181Initial program 59.0%
div-sub59.0%
sub-neg59.0%
neg-mul-159.0%
*-commutative59.0%
associate-/l*58.8%
distribute-neg-frac58.8%
neg-mul-158.8%
*-commutative58.8%
associate-/l*59.1%
distribute-rgt-out59.1%
associate-/r*59.1%
metadata-eval59.1%
fma-neg59.2%
*-commutative59.2%
*-commutative59.2%
Simplified59.2%
clear-num59.2%
flip-+58.8%
frac-times49.5%
Applied egg-rr49.4%
associate-/r*58.6%
*-lft-identity58.6%
*-commutative58.6%
times-frac58.6%
metadata-eval58.6%
metadata-eval58.6%
times-frac58.6%
neg-mul-158.6%
associate-/r*49.4%
times-frac58.6%
distribute-frac-neg258.6%
distribute-neg-frac58.6%
metadata-eval58.6%
Simplified58.0%
associate-*r*58.0%
associate-*l*58.0%
associate-/l/57.9%
Applied egg-rr57.9%
*-commutative57.9%
associate-*r/57.9%
metadata-eval57.9%
*-commutative57.9%
associate-*r*57.9%
*-commutative57.9%
rem-square-sqrt0.0%
unpow20.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt57.9%
Simplified57.9%
associate-*r/58.1%
*-commutative58.1%
times-frac67.1%
*-commutative67.1%
associate-*r*67.1%
*-commutative67.1%
associate-*r*67.1%
Applied egg-rr67.1%
associate-*l/67.2%
*-commutative67.2%
associate-*r*67.2%
*-commutative67.2%
rem-square-sqrt0.0%
unpow20.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt67.2%
Simplified67.2%
Taylor expanded in a around 0 85.0%
if -4.20000000000000006e-181 < b < 4.2000000000000003e109Initial program 89.3%
if 4.2000000000000003e109 < b Initial program 56.6%
div-sub56.6%
sub-neg56.6%
neg-mul-156.6%
*-commutative56.6%
associate-/l*56.5%
distribute-neg-frac56.5%
neg-mul-156.5%
*-commutative56.5%
associate-/l*56.4%
distribute-rgt-out56.4%
associate-/r*56.4%
metadata-eval56.4%
fma-neg56.4%
*-commutative56.4%
*-commutative56.4%
Simplified56.4%
Taylor expanded in c around 0 94.3%
+-commutative94.3%
mul-1-neg94.3%
unsub-neg94.3%
Simplified94.3%
Final simplification90.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (/ -0.5 a) (+ b (sqrt (* c (* a -4.0)))))))
(if (<= b -2.9e-5)
(/ (- c) b)
(if (<= b 4e-127)
t_0
(if (<= b 1.02e-58)
(/ (- (* a (/ c b)) b) a)
(if (<= b 1.6e-13)
t_0
(- (* c (+ (/ 1.0 b) (* a (/ c (pow b 3.0))))) (/ b a))))))))
double code(double a, double b, double c) {
double t_0 = (-0.5 / a) * (b + sqrt((c * (a * -4.0))));
double tmp;
if (b <= -2.9e-5) {
tmp = -c / b;
} else if (b <= 4e-127) {
tmp = t_0;
} else if (b <= 1.02e-58) {
tmp = ((a * (c / b)) - b) / a;
} else if (b <= 1.6e-13) {
tmp = t_0;
} else {
tmp = (c * ((1.0 / b) + (a * (c / pow(b, 3.0))))) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = ((-0.5d0) / a) * (b + sqrt((c * (a * (-4.0d0)))))
if (b <= (-2.9d-5)) then
tmp = -c / b
else if (b <= 4d-127) then
tmp = t_0
else if (b <= 1.02d-58) then
tmp = ((a * (c / b)) - b) / a
else if (b <= 1.6d-13) then
tmp = t_0
else
tmp = (c * ((1.0d0 / b) + (a * (c / (b ** 3.0d0))))) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (-0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
double tmp;
if (b <= -2.9e-5) {
tmp = -c / b;
} else if (b <= 4e-127) {
tmp = t_0;
} else if (b <= 1.02e-58) {
tmp = ((a * (c / b)) - b) / a;
} else if (b <= 1.6e-13) {
tmp = t_0;
} else {
tmp = (c * ((1.0 / b) + (a * (c / Math.pow(b, 3.0))))) - (b / a);
}
return tmp;
}
def code(a, b, c): t_0 = (-0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) tmp = 0 if b <= -2.9e-5: tmp = -c / b elif b <= 4e-127: tmp = t_0 elif b <= 1.02e-58: tmp = ((a * (c / b)) - b) / a elif b <= 1.6e-13: tmp = t_0 else: tmp = (c * ((1.0 / b) + (a * (c / math.pow(b, 3.0))))) - (b / a) return tmp
function code(a, b, c) t_0 = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))) tmp = 0.0 if (b <= -2.9e-5) tmp = Float64(Float64(-c) / b); elseif (b <= 4e-127) tmp = t_0; elseif (b <= 1.02e-58) tmp = Float64(Float64(Float64(a * Float64(c / b)) - b) / a); elseif (b <= 1.6e-13) tmp = t_0; else tmp = Float64(Float64(c * Float64(Float64(1.0 / b) + Float64(a * Float64(c / (b ^ 3.0))))) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (-0.5 / a) * (b + sqrt((c * (a * -4.0)))); tmp = 0.0; if (b <= -2.9e-5) tmp = -c / b; elseif (b <= 4e-127) tmp = t_0; elseif (b <= 1.02e-58) tmp = ((a * (c / b)) - b) / a; elseif (b <= 1.6e-13) tmp = t_0; else tmp = (c * ((1.0 / b) + (a * (c / (b ^ 3.0))))) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.9e-5], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4e-127], t$95$0, If[LessEqual[b, 1.02e-58], N[(N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 1.6e-13], t$95$0, N[(N[(c * N[(N[(1.0 / b), $MachinePrecision] + N[(a * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{if}\;b \leq -2.9 \cdot 10^{-5}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-58}:\\
\;\;\;\;\frac{a \cdot \frac{c}{b} - b}{a}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(\frac{1}{b} + a \cdot \frac{c}{{b}^{3}}\right) - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9e-5Initial program 9.3%
div-sub7.6%
sub-neg7.6%
neg-mul-17.6%
*-commutative7.6%
associate-/l*5.3%
distribute-neg-frac5.3%
neg-mul-15.3%
*-commutative5.3%
associate-/l*7.6%
distribute-rgt-out9.3%
associate-/r*9.3%
metadata-eval9.3%
fma-neg9.3%
*-commutative9.3%
*-commutative9.3%
Simplified9.3%
Taylor expanded in b around -inf 87.8%
associate-*r/87.8%
neg-mul-187.8%
Simplified87.8%
if -2.9e-5 < b < 4.0000000000000001e-127 or 1.0199999999999999e-58 < b < 1.6e-13Initial program 80.2%
div-sub80.2%
sub-neg80.2%
neg-mul-180.2%
*-commutative80.2%
associate-/l*80.2%
distribute-neg-frac80.2%
neg-mul-180.2%
*-commutative80.2%
associate-/l*80.2%
distribute-rgt-out80.2%
associate-/r*80.2%
metadata-eval80.2%
fma-neg80.3%
*-commutative80.3%
*-commutative80.3%
Simplified80.3%
Taylor expanded in b around 0 75.4%
associate-*r*75.4%
*-commutative75.4%
*-commutative75.4%
Simplified75.4%
if 4.0000000000000001e-127 < b < 1.0199999999999999e-58Initial program 94.3%
div-sub94.3%
sub-neg94.3%
neg-mul-194.3%
*-commutative94.3%
associate-/l*94.2%
distribute-neg-frac94.2%
neg-mul-194.2%
*-commutative94.2%
associate-/l*94.0%
distribute-rgt-out94.0%
associate-/r*94.0%
metadata-eval94.0%
fma-neg94.0%
*-commutative94.0%
*-commutative94.0%
Simplified94.0%
Taylor expanded in a around 0 66.7%
+-commutative66.7%
mul-1-neg66.7%
sub-neg66.7%
associate-/l*66.7%
Simplified66.7%
if 1.6e-13 < b Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-neg-frac70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/l*70.2%
distribute-rgt-out70.2%
associate-/r*70.2%
metadata-eval70.2%
fma-neg70.2%
*-commutative70.2%
*-commutative70.2%
Simplified70.2%
Taylor expanded in c around 0 87.1%
+-commutative87.1%
mul-1-neg87.1%
unsub-neg87.1%
associate-/l*90.0%
Simplified90.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4.4e-5)
(/ (- c) b)
(if (<= b 8.5e+109)
(/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) (- (* a 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.4e-5) {
tmp = -c / b;
} else if (b <= 8.5e+109) {
tmp = (b + sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4.4d-5)) then
tmp = -c / b
else if (b <= 8.5d+109) then
tmp = (b + sqrt(((b * b) - (4.0d0 * (c * a))))) / -(a * 2.0d0)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.4e-5) {
tmp = -c / b;
} else if (b <= 8.5e+109) {
tmp = (b + Math.sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.4e-5: tmp = -c / b elif b <= 8.5e+109: tmp = (b + math.sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.4e-5) tmp = Float64(Float64(-c) / b); elseif (b <= 8.5e+109) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(-Float64(a * 2.0))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.4e-5) tmp = -c / b; elseif (b <= 8.5e+109) tmp = (b + sqrt(((b * b) - (4.0 * (c * a))))) / -(a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.4e-5], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 8.5e+109], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / (-N[(a * 2.0), $MachinePrecision])), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.4 \cdot 10^{-5}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{+109}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{-a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.3999999999999999e-5Initial program 9.3%
div-sub7.6%
sub-neg7.6%
neg-mul-17.6%
*-commutative7.6%
associate-/l*5.3%
distribute-neg-frac5.3%
neg-mul-15.3%
*-commutative5.3%
associate-/l*7.6%
distribute-rgt-out9.3%
associate-/r*9.3%
metadata-eval9.3%
fma-neg9.3%
*-commutative9.3%
*-commutative9.3%
Simplified9.3%
Taylor expanded in b around -inf 87.8%
associate-*r/87.8%
neg-mul-187.8%
Simplified87.8%
if -4.3999999999999999e-5 < b < 8.5000000000000004e109Initial program 85.2%
if 8.5000000000000004e109 < b Initial program 56.6%
div-sub56.6%
sub-neg56.6%
neg-mul-156.6%
*-commutative56.6%
associate-/l*56.5%
distribute-neg-frac56.5%
neg-mul-156.5%
*-commutative56.5%
associate-/l*56.4%
distribute-rgt-out56.4%
associate-/r*56.4%
metadata-eval56.4%
fma-neg56.4%
*-commutative56.4%
*-commutative56.4%
Simplified56.4%
Taylor expanded in c around 0 94.3%
+-commutative94.3%
mul-1-neg94.3%
unsub-neg94.3%
Simplified94.3%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-5)
(/ (- c) b)
(if (<= b 4e-127)
(* (/ -0.5 a) (+ b (sqrt (* c (* a -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-5) {
tmp = -c / b;
} else if (b <= 4e-127) {
tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.9d-5)) then
tmp = -c / b
else if (b <= 4d-127) then
tmp = ((-0.5d0) / a) * (b + sqrt((c * (a * (-4.0d0)))))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-5) {
tmp = -c / b;
} else if (b <= 4e-127) {
tmp = (-0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-5: tmp = -c / b elif b <= 4e-127: tmp = (-0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-5) tmp = Float64(Float64(-c) / b); elseif (b <= 4e-127) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e-5) tmp = -c / b; elseif (b <= 4e-127) tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-5], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4e-127], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-5}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9e-5Initial program 9.3%
div-sub7.6%
sub-neg7.6%
neg-mul-17.6%
*-commutative7.6%
associate-/l*5.3%
distribute-neg-frac5.3%
neg-mul-15.3%
*-commutative5.3%
associate-/l*7.6%
distribute-rgt-out9.3%
associate-/r*9.3%
metadata-eval9.3%
fma-neg9.3%
*-commutative9.3%
*-commutative9.3%
Simplified9.3%
Taylor expanded in b around -inf 87.8%
associate-*r/87.8%
neg-mul-187.8%
Simplified87.8%
if -2.9e-5 < b < 4.0000000000000001e-127Initial program 77.9%
div-sub77.9%
sub-neg77.9%
neg-mul-177.9%
*-commutative77.9%
associate-/l*77.9%
distribute-neg-frac77.9%
neg-mul-177.9%
*-commutative77.9%
associate-/l*78.0%
distribute-rgt-out78.0%
associate-/r*78.0%
metadata-eval78.0%
fma-neg78.0%
*-commutative78.0%
*-commutative78.0%
Simplified78.0%
Taylor expanded in b around 0 75.2%
associate-*r*75.2%
*-commutative75.2%
*-commutative75.2%
Simplified75.2%
if 4.0000000000000001e-127 < b Initial program 76.7%
div-sub76.7%
sub-neg76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.6%
distribute-neg-frac76.6%
neg-mul-176.6%
*-commutative76.6%
associate-/l*76.5%
distribute-rgt-out76.5%
associate-/r*76.5%
metadata-eval76.5%
fma-neg76.5%
*-commutative76.5%
*-commutative76.5%
Simplified76.5%
Taylor expanded in c around 0 81.2%
+-commutative81.2%
mul-1-neg81.2%
unsub-neg81.2%
Simplified81.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-311)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-311) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.00000000000023e-311Initial program 29.4%
div-sub28.2%
sub-neg28.2%
neg-mul-128.2%
*-commutative28.2%
associate-/l*26.6%
distribute-neg-frac26.6%
neg-mul-126.6%
*-commutative26.6%
associate-/l*28.3%
distribute-rgt-out29.4%
associate-/r*29.4%
metadata-eval29.4%
fma-neg29.5%
*-commutative29.5%
*-commutative29.5%
Simplified29.5%
Taylor expanded in b around -inf 67.1%
associate-*r/67.1%
neg-mul-167.1%
Simplified67.1%
if -5.00000000000023e-311 < b Initial program 78.0%
div-sub78.0%
sub-neg78.0%
neg-mul-178.0%
*-commutative78.0%
associate-/l*77.9%
distribute-neg-frac77.9%
neg-mul-177.9%
*-commutative77.9%
associate-/l*77.8%
distribute-rgt-out77.8%
associate-/r*77.8%
metadata-eval77.8%
fma-neg77.8%
*-commutative77.8%
*-commutative77.8%
Simplified77.8%
Taylor expanded in c around 0 65.5%
+-commutative65.5%
mul-1-neg65.5%
unsub-neg65.5%
Simplified65.5%
(FPCore (a b c) :precision binary64 (if (<= b -3.7e-279) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.7e-279) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3.7d-279)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.7e-279) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.7e-279: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.7e-279) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.7e-279) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.7e-279], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.7 \cdot 10^{-279}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.70000000000000038e-279Initial program 28.4%
div-sub27.3%
sub-neg27.3%
neg-mul-127.3%
*-commutative27.3%
associate-/l*25.6%
distribute-neg-frac25.6%
neg-mul-125.6%
*-commutative25.6%
associate-/l*27.3%
distribute-rgt-out28.5%
associate-/r*28.5%
metadata-eval28.5%
fma-neg28.5%
*-commutative28.5%
*-commutative28.5%
Simplified28.5%
Taylor expanded in b around -inf 68.7%
associate-*r/68.7%
neg-mul-168.7%
Simplified68.7%
if -3.70000000000000038e-279 < b Initial program 77.7%
div-sub77.8%
sub-neg77.8%
neg-mul-177.8%
*-commutative77.8%
associate-/l*77.7%
distribute-neg-frac77.7%
neg-mul-177.7%
*-commutative77.7%
associate-/l*77.6%
distribute-rgt-out77.6%
associate-/r*77.6%
metadata-eval77.6%
fma-neg77.6%
*-commutative77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in a around 0 63.2%
mul-1-neg63.2%
distribute-neg-frac263.2%
Simplified63.2%
Final simplification65.8%
(FPCore (a b c) :precision binary64 (if (<= b -2.9e+91) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e+91) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.9d+91)) then
tmp = c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e+91) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e+91: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e+91) tmp = Float64(c / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e+91) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e+91], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{+91}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.90000000000000014e91Initial program 6.6%
div-sub4.4%
sub-neg4.4%
neg-mul-14.4%
*-commutative4.4%
associate-/l*1.4%
distribute-neg-frac1.4%
neg-mul-11.4%
*-commutative1.4%
associate-/l*4.4%
distribute-rgt-out6.6%
associate-/r*6.6%
metadata-eval6.6%
fma-neg6.6%
*-commutative6.6%
*-commutative6.6%
Simplified6.6%
Taylor expanded in a around 0 1.8%
+-commutative1.8%
mul-1-neg1.8%
sub-neg1.8%
associate-/l*2.1%
Simplified2.1%
Taylor expanded in a around inf 37.9%
if -2.90000000000000014e91 < b Initial program 71.0%
div-sub71.0%
sub-neg71.0%
neg-mul-171.0%
*-commutative71.0%
associate-/l*70.9%
distribute-neg-frac70.9%
neg-mul-170.9%
*-commutative70.9%
associate-/l*70.9%
distribute-rgt-out70.9%
associate-/r*70.9%
metadata-eval70.9%
fma-neg70.9%
*-commutative70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in a around 0 46.0%
mul-1-neg46.0%
distribute-neg-frac246.0%
Simplified46.0%
Final simplification44.0%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 54.6%
div-sub54.1%
sub-neg54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*53.3%
distribute-neg-frac53.3%
neg-mul-153.3%
*-commutative53.3%
associate-/l*54.0%
distribute-rgt-out54.6%
associate-/r*54.6%
metadata-eval54.6%
fma-neg54.6%
*-commutative54.6%
*-commutative54.6%
Simplified54.6%
Taylor expanded in a around 0 34.2%
+-commutative34.2%
mul-1-neg34.2%
sub-neg34.2%
associate-/l*35.1%
Simplified35.1%
Taylor expanded in a around inf 12.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{t\_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t\_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024095
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(if (< b 0.0) (/ c (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0))) (/ (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))