
(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 9 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 -1.9e-39)
(/ c (- b))
(if (<= b 5.6e+47)
(fma
b
(/ -0.5 a)
(* -0.5 (/ (sqrt (* a (+ (/ (pow b 2.0) a) (* c -4.0)))) a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-39) {
tmp = c / -b;
} else if (b <= 5.6e+47) {
tmp = fma(b, (-0.5 / a), (-0.5 * (sqrt((a * ((pow(b, 2.0) / a) + (c * -4.0)))) / a)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.9e-39) tmp = Float64(c / Float64(-b)); elseif (b <= 5.6e+47) tmp = fma(b, Float64(-0.5 / a), Float64(-0.5 * Float64(sqrt(Float64(a * Float64(Float64((b ^ 2.0) / a) + Float64(c * -4.0)))) / a))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.9e-39], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.6e+47], N[(b * N[(-0.5 / a), $MachinePrecision] + N[(-0.5 * N[(N[Sqrt[N[(a * N[(N[(N[Power[b, 2.0], $MachinePrecision] / a), $MachinePrecision] + N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{-39}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{-0.5}{a}, -0.5 \cdot \frac{\sqrt{a \cdot \left(\frac{{b}^{2}}{a} + c \cdot -4\right)}}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.9000000000000001e-39Initial program 11.4%
div-sub10.6%
sub-neg10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*10.5%
distribute-neg-frac10.5%
neg-mul-110.5%
*-commutative10.5%
associate-/l*10.6%
distribute-rgt-out11.4%
associate-/r*11.4%
metadata-eval11.4%
sub-neg11.4%
+-commutative11.4%
Simplified11.4%
Taylor expanded in b around -inf 89.3%
mul-1-neg89.3%
distribute-neg-frac289.3%
Simplified89.3%
if -1.9000000000000001e-39 < b < 5.59999999999999976e47Initial program 79.6%
*-commutative79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
associate-*r*79.6%
Simplified79.6%
Taylor expanded in a around inf 79.6%
div-sub79.6%
neg-mul-179.6%
*-commutative79.6%
times-frac79.6%
metadata-eval79.6%
*-un-lft-identity79.6%
*-commutative79.6%
times-frac79.6%
metadata-eval79.6%
cancel-sign-sub-inv79.6%
metadata-eval79.6%
*-commutative79.6%
Applied egg-rr79.6%
associate-*r/79.6%
*-commutative79.6%
associate-*r/79.7%
fma-neg79.7%
distribute-lft-neg-in79.7%
metadata-eval79.7%
Simplified79.7%
if 5.59999999999999976e47 < b Initial program 61.7%
div-sub61.7%
sub-neg61.7%
neg-mul-161.7%
*-commutative61.7%
associate-/l*61.6%
distribute-neg-frac61.6%
neg-mul-161.6%
*-commutative61.6%
associate-/l*61.5%
distribute-rgt-out61.5%
associate-/r*61.5%
metadata-eval61.5%
sub-neg61.5%
+-commutative61.5%
Simplified61.5%
Taylor expanded in c around 0 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.26e-45)
(/ c (- b))
(if (<= b 1.9e+41)
(-
(* -0.5 (/ b a))
(* 0.5 (/ (sqrt (* a (+ (* c -4.0) (* b (/ b a))))) a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.26e-45) {
tmp = c / -b;
} else if (b <= 1.9e+41) {
tmp = (-0.5 * (b / a)) - (0.5 * (sqrt((a * ((c * -4.0) + (b * (b / a))))) / a));
} 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 <= (-1.26d-45)) then
tmp = c / -b
else if (b <= 1.9d+41) then
tmp = ((-0.5d0) * (b / a)) - (0.5d0 * (sqrt((a * ((c * (-4.0d0)) + (b * (b / a))))) / a))
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 <= -1.26e-45) {
tmp = c / -b;
} else if (b <= 1.9e+41) {
tmp = (-0.5 * (b / a)) - (0.5 * (Math.sqrt((a * ((c * -4.0) + (b * (b / a))))) / a));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.26e-45: tmp = c / -b elif b <= 1.9e+41: tmp = (-0.5 * (b / a)) - (0.5 * (math.sqrt((a * ((c * -4.0) + (b * (b / a))))) / a)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.26e-45) tmp = Float64(c / Float64(-b)); elseif (b <= 1.9e+41) tmp = Float64(Float64(-0.5 * Float64(b / a)) - Float64(0.5 * Float64(sqrt(Float64(a * Float64(Float64(c * -4.0) + Float64(b * Float64(b / a))))) / a))); 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 <= -1.26e-45) tmp = c / -b; elseif (b <= 1.9e+41) tmp = (-0.5 * (b / a)) - (0.5 * (sqrt((a * ((c * -4.0) + (b * (b / a))))) / a)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.26e-45], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.9e+41], N[(N[(-0.5 * N[(b / a), $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[(N[Sqrt[N[(a * N[(N[(c * -4.0), $MachinePrecision] + N[(b * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.26 \cdot 10^{-45}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{+41}:\\
\;\;\;\;-0.5 \cdot \frac{b}{a} - 0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4 + b \cdot \frac{b}{a}\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.26e-45Initial program 11.4%
div-sub10.6%
sub-neg10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*10.5%
distribute-neg-frac10.5%
neg-mul-110.5%
*-commutative10.5%
associate-/l*10.6%
distribute-rgt-out11.4%
associate-/r*11.4%
metadata-eval11.4%
sub-neg11.4%
+-commutative11.4%
Simplified11.4%
Taylor expanded in b around -inf 89.3%
mul-1-neg89.3%
distribute-neg-frac289.3%
Simplified89.3%
if -1.26e-45 < b < 1.9000000000000001e41Initial program 79.6%
*-commutative79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
associate-*r*79.6%
Simplified79.6%
Taylor expanded in a around inf 79.6%
div-sub79.6%
neg-mul-179.6%
*-commutative79.6%
times-frac79.6%
metadata-eval79.6%
*-un-lft-identity79.6%
*-commutative79.6%
times-frac79.6%
metadata-eval79.6%
cancel-sign-sub-inv79.6%
metadata-eval79.6%
*-commutative79.6%
Applied egg-rr79.6%
unpow279.6%
*-un-lft-identity79.6%
times-frac79.6%
Applied egg-rr79.6%
if 1.9000000000000001e41 < b Initial program 61.7%
div-sub61.7%
sub-neg61.7%
neg-mul-161.7%
*-commutative61.7%
associate-/l*61.6%
distribute-neg-frac61.6%
neg-mul-161.6%
*-commutative61.6%
associate-/l*61.5%
distribute-rgt-out61.5%
associate-/r*61.5%
metadata-eval61.5%
sub-neg61.5%
+-commutative61.5%
Simplified61.5%
Taylor expanded in c around 0 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -3.4e-47)
(/ c (- b))
(if (<= b 4.2e+48)
(/ (- (- 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 <= -3.4e-47) {
tmp = c / -b;
} else if (b <= 4.2e+48) {
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 <= (-3.4d-47)) then
tmp = c / -b
else if (b <= 4.2d+48) 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 <= -3.4e-47) {
tmp = c / -b;
} else if (b <= 4.2e+48) {
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 <= -3.4e-47: tmp = c / -b elif b <= 4.2e+48: 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 <= -3.4e-47) tmp = Float64(c / Float64(-b)); elseif (b <= 4.2e+48) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / 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 <= -3.4e-47) tmp = c / -b; elseif (b <= 4.2e+48) 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, -3.4e-47], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.2e+48], 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 -3.4 \cdot 10^{-47}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+48}:\\
\;\;\;\;\frac{\left(-b\right) - \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 < -3.4000000000000002e-47Initial program 11.4%
div-sub10.6%
sub-neg10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*10.5%
distribute-neg-frac10.5%
neg-mul-110.5%
*-commutative10.5%
associate-/l*10.6%
distribute-rgt-out11.4%
associate-/r*11.4%
metadata-eval11.4%
sub-neg11.4%
+-commutative11.4%
Simplified11.4%
Taylor expanded in b around -inf 89.3%
mul-1-neg89.3%
distribute-neg-frac289.3%
Simplified89.3%
if -3.4000000000000002e-47 < b < 4.1999999999999997e48Initial program 79.6%
if 4.1999999999999997e48 < b Initial program 61.7%
div-sub61.7%
sub-neg61.7%
neg-mul-161.7%
*-commutative61.7%
associate-/l*61.6%
distribute-neg-frac61.6%
neg-mul-161.6%
*-commutative61.6%
associate-/l*61.5%
distribute-rgt-out61.5%
associate-/r*61.5%
metadata-eval61.5%
sub-neg61.5%
+-commutative61.5%
Simplified61.5%
Taylor expanded in c around 0 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(if (<= b -4.3e-47)
(/ c (- b))
(if (<= b 4.2e+48)
(/ (- (- b) (sqrt (- (* b b) (* a (* c 4.0))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-47) {
tmp = c / -b;
} else if (b <= 4.2e+48) {
tmp = (-b - sqrt(((b * b) - (a * (c * 4.0))))) / (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.3d-47)) then
tmp = c / -b
else if (b <= 4.2d+48) then
tmp = (-b - sqrt(((b * b) - (a * (c * 4.0d0))))) / (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.3e-47) {
tmp = c / -b;
} else if (b <= 4.2e+48) {
tmp = (-b - Math.sqrt(((b * b) - (a * (c * 4.0))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.3e-47: tmp = c / -b elif b <= 4.2e+48: tmp = (-b - math.sqrt(((b * b) - (a * (c * 4.0))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.3e-47) tmp = Float64(c / Float64(-b)); elseif (b <= 4.2e+48) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / 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.3e-47) tmp = c / -b; elseif (b <= 4.2e+48) tmp = (-b - sqrt(((b * b) - (a * (c * 4.0))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-47], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.2e+48], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $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.3 \cdot 10^{-47}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+48}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.2999999999999998e-47Initial program 11.4%
div-sub10.6%
sub-neg10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*10.5%
distribute-neg-frac10.5%
neg-mul-110.5%
*-commutative10.5%
associate-/l*10.6%
distribute-rgt-out11.4%
associate-/r*11.4%
metadata-eval11.4%
sub-neg11.4%
+-commutative11.4%
Simplified11.4%
Taylor expanded in b around -inf 89.3%
mul-1-neg89.3%
distribute-neg-frac289.3%
Simplified89.3%
if -4.2999999999999998e-47 < b < 4.1999999999999997e48Initial program 79.6%
*-commutative79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
associate-*r*79.6%
Simplified79.6%
if 4.1999999999999997e48 < b Initial program 61.7%
div-sub61.7%
sub-neg61.7%
neg-mul-161.7%
*-commutative61.7%
associate-/l*61.6%
distribute-neg-frac61.6%
neg-mul-161.6%
*-commutative61.6%
associate-/l*61.5%
distribute-rgt-out61.5%
associate-/r*61.5%
metadata-eval61.5%
sub-neg61.5%
+-commutative61.5%
Simplified61.5%
Taylor expanded in c around 0 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.85e-34)
(/ c (- b))
(if (<= b 1.36e-112)
(/ (+ b (sqrt (* c (* a -4.0)))) (* 2.0 (- a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e-34) {
tmp = c / -b;
} else if (b <= 1.36e-112) {
tmp = (b + sqrt((c * (a * -4.0)))) / (2.0 * -a);
} 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 <= (-1.85d-34)) then
tmp = c / -b
else if (b <= 1.36d-112) then
tmp = (b + sqrt((c * (a * (-4.0d0))))) / (2.0d0 * -a)
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 <= -1.85e-34) {
tmp = c / -b;
} else if (b <= 1.36e-112) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) / (2.0 * -a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.85e-34: tmp = c / -b elif b <= 1.36e-112: tmp = (b + math.sqrt((c * (a * -4.0)))) / (2.0 * -a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.85e-34) tmp = Float64(c / Float64(-b)); elseif (b <= 1.36e-112) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / Float64(2.0 * Float64(-a))); 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 <= -1.85e-34) tmp = c / -b; elseif (b <= 1.36e-112) tmp = (b + sqrt((c * (a * -4.0)))) / (2.0 * -a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.85e-34], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.36e-112], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * (-a)), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.85 \cdot 10^{-34}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.36 \cdot 10^{-112}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{2 \cdot \left(-a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.84999999999999994e-34Initial program 11.4%
div-sub10.6%
sub-neg10.6%
neg-mul-110.6%
*-commutative10.6%
associate-/l*10.5%
distribute-neg-frac10.5%
neg-mul-110.5%
*-commutative10.5%
associate-/l*10.6%
distribute-rgt-out11.4%
associate-/r*11.4%
metadata-eval11.4%
sub-neg11.4%
+-commutative11.4%
Simplified11.4%
Taylor expanded in b around -inf 89.3%
mul-1-neg89.3%
distribute-neg-frac289.3%
Simplified89.3%
if -1.84999999999999994e-34 < b < 1.3600000000000001e-112Initial program 71.8%
*-commutative71.8%
*-commutative71.8%
sqr-neg71.8%
*-commutative71.8%
sqr-neg71.8%
*-commutative71.8%
associate-*r*71.9%
Simplified71.9%
Taylor expanded in b around 0 69.6%
associate-*r*69.7%
*-commutative69.7%
Simplified69.7%
if 1.3600000000000001e-112 < b Initial program 72.8%
div-sub72.8%
sub-neg72.8%
neg-mul-172.8%
*-commutative72.8%
associate-/l*72.7%
distribute-neg-frac72.7%
neg-mul-172.7%
*-commutative72.7%
associate-/l*72.6%
distribute-rgt-out72.6%
associate-/r*72.6%
metadata-eval72.6%
sub-neg72.6%
+-commutative72.6%
Simplified72.6%
Taylor expanded in c around 0 87.0%
+-commutative87.0%
mul-1-neg87.0%
unsub-neg87.0%
Simplified87.0%
Final simplification83.3%
(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(c / Float64(-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 31.7%
div-sub31.2%
sub-neg31.2%
neg-mul-131.2%
*-commutative31.2%
associate-/l*31.2%
distribute-neg-frac31.2%
neg-mul-131.2%
*-commutative31.2%
associate-/l*31.3%
distribute-rgt-out31.8%
associate-/r*31.8%
metadata-eval31.8%
sub-neg31.8%
+-commutative31.8%
Simplified31.8%
Taylor expanded in b around -inf 68.1%
mul-1-neg68.1%
distribute-neg-frac268.1%
Simplified68.1%
if -5.00000000000023e-311 < b Initial program 72.3%
div-sub72.2%
sub-neg72.2%
neg-mul-172.2%
*-commutative72.2%
associate-/l*72.2%
distribute-neg-frac72.2%
neg-mul-172.2%
*-commutative72.2%
associate-/l*72.1%
distribute-rgt-out72.1%
associate-/r*72.1%
metadata-eval72.1%
sub-neg72.1%
+-commutative72.1%
Simplified72.1%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
Simplified74.2%
Final simplification71.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
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 <= (-5d-311)) 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 <= -5e-311) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-311) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -5.00000000000023e-311Initial program 31.7%
div-sub31.2%
sub-neg31.2%
neg-mul-131.2%
*-commutative31.2%
associate-/l*31.2%
distribute-neg-frac31.2%
neg-mul-131.2%
*-commutative31.2%
associate-/l*31.3%
distribute-rgt-out31.8%
associate-/r*31.8%
metadata-eval31.8%
sub-neg31.8%
+-commutative31.8%
Simplified31.8%
Taylor expanded in b around -inf 68.1%
mul-1-neg68.1%
distribute-neg-frac268.1%
Simplified68.1%
if -5.00000000000023e-311 < b Initial program 72.3%
div-sub72.2%
sub-neg72.2%
neg-mul-172.2%
*-commutative72.2%
associate-/l*72.2%
distribute-neg-frac72.2%
neg-mul-172.2%
*-commutative72.2%
associate-/l*72.1%
distribute-rgt-out72.1%
associate-/r*72.1%
metadata-eval72.1%
sub-neg72.1%
+-commutative72.1%
Simplified72.1%
Taylor expanded in a around 0 74.0%
associate-*r/74.0%
mul-1-neg74.0%
Simplified74.0%
Final simplification71.2%
(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 / Float64(-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 52.6%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.3%
distribute-neg-frac52.3%
neg-mul-152.3%
*-commutative52.3%
associate-/l*52.3%
distribute-rgt-out52.5%
associate-/r*52.5%
metadata-eval52.5%
sub-neg52.5%
+-commutative52.5%
Simplified52.6%
Taylor expanded in b around -inf 34.3%
mul-1-neg34.3%
distribute-neg-frac234.3%
Simplified34.3%
Final simplification34.3%
(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 52.6%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.3%
distribute-neg-frac52.3%
neg-mul-152.3%
*-commutative52.3%
associate-/l*52.3%
distribute-rgt-out52.5%
associate-/r*52.5%
metadata-eval52.5%
sub-neg52.5%
+-commutative52.5%
Simplified52.6%
Taylor expanded in a around 0 38.5%
Taylor expanded in b around 0 9.2%
Final simplification9.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 a))))
(/ (- (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * 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 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t\_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2024050
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))