
(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 10 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 -3.5e-38)
(/ c (- b))
(if (<= b 3.8e+48)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e-38) {
tmp = c / -b;
} else if (b <= 3.8e+48) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * 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.5d-38)) then
tmp = c / -b
else if (b <= 3.8d+48) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * 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.5e-38) {
tmp = c / -b;
} else if (b <= 3.8e+48) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e-38: tmp = c / -b elif b <= 3.8e+48: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e-38) tmp = Float64(c / Float64(-b)); elseif (b <= 3.8e+48) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * 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.5e-38) tmp = c / -b; elseif (b <= 3.8e+48) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e-38], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.8e+48], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $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.5 \cdot 10^{-38}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{+48}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.5000000000000001e-38Initial 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.5000000000000001e-38 < b < 3.8e48Initial program 79.6%
*-commutative79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
sqr-neg79.6%
*-commutative79.6%
associate-*r*79.6%
Simplified79.6%
if 3.8e48 < 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 a 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 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 <= -1.26e-45) {
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 <= (-1.26d-45)) 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 <= -1.26e-45) {
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 <= -1.26e-45: 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 <= -1.26e-45) 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 <= -1.26e-45) 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, -1.26e-45], 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 -1.26 \cdot 10^{-45}:\\
\;\;\;\;\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 < -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 < 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 a 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 1.5e-114)
(* -0.5 (/ (+ b (sqrt (* a (* c -4.0)))) a))
(- (/ 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 <= 1.5e-114) {
tmp = -0.5 * ((b + sqrt((a * (c * -4.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 <= (-4.3d-47)) then
tmp = c / -b
else if (b <= 1.5d-114) then
tmp = (-0.5d0) * ((b + sqrt((a * (c * (-4.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 <= -4.3e-47) {
tmp = c / -b;
} else if (b <= 1.5e-114) {
tmp = -0.5 * ((b + Math.sqrt((a * (c * -4.0)))) / a);
} 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 <= 1.5e-114: tmp = -0.5 * ((b + math.sqrt((a * (c * -4.0)))) / a) 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 <= 1.5e-114) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / 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 <= -4.3e-47) tmp = c / -b; elseif (b <= 1.5e-114) tmp = -0.5 * ((b + sqrt((a * (c * -4.0)))) / a); 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, 1.5e-114], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $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 1.5 \cdot 10^{-114}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\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 < 1.50000000000000008e-114Initial program 71.8%
div-sub71.8%
sub-neg71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*72.0%
distribute-neg-frac72.0%
neg-mul-172.0%
*-commutative72.0%
associate-/l*71.8%
distribute-rgt-out71.8%
associate-/r*71.8%
metadata-eval71.8%
sub-neg71.8%
+-commutative71.8%
Simplified71.8%
add-sqr-sqrt71.4%
pow271.4%
pow1/271.4%
sqrt-pow171.5%
pow271.5%
metadata-eval71.5%
Applied egg-rr71.5%
Taylor expanded in a around -inf 39.5%
Taylor expanded in c around 0 39.5%
Simplified69.7%
if 1.50000000000000008e-114 < 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 a 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 -1.85e-44)
(/ c (- b))
(if (<= b 9.5e-120)
(* -0.5 (/ (sqrt (* a (* c -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e-44) {
tmp = c / -b;
} else if (b <= 9.5e-120) {
tmp = -0.5 * (sqrt((a * (c * -4.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-44)) then
tmp = c / -b
else if (b <= 9.5d-120) then
tmp = (-0.5d0) * (sqrt((a * (c * (-4.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-44) {
tmp = c / -b;
} else if (b <= 9.5e-120) {
tmp = -0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.85e-44: tmp = c / -b elif b <= 9.5e-120: tmp = -0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.85e-44) tmp = Float64(c / Float64(-b)); elseif (b <= 9.5e-120) tmp = Float64(-0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / 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-44) tmp = c / -b; elseif (b <= 9.5e-120) tmp = -0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.85e-44], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 9.5e-120], N[(-0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 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^{-44}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-120}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.85e-44Initial 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.85e-44 < b < 9.49999999999999937e-120Initial program 71.8%
div-sub71.8%
sub-neg71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*72.0%
distribute-neg-frac72.0%
neg-mul-172.0%
*-commutative72.0%
associate-/l*71.8%
distribute-rgt-out71.8%
associate-/r*71.8%
metadata-eval71.8%
sub-neg71.8%
+-commutative71.8%
Simplified71.8%
add-sqr-sqrt71.4%
pow271.4%
pow1/271.4%
sqrt-pow171.5%
pow271.5%
metadata-eval71.5%
Applied egg-rr71.5%
Taylor expanded in a around -inf 39.5%
Taylor expanded in b around 0 39.4%
Simplified68.5%
if 9.49999999999999937e-120 < 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 a around 0 87.0%
+-commutative87.0%
mul-1-neg87.0%
unsub-neg87.0%
Simplified87.0%
Final simplification83.0%
(FPCore (a b c) :precision binary64 (if (<= b -1.6e-218) (/ 1.0 (- (/ a b) (/ b c))) (if (<= b 2.4e-122) (* -0.5 (sqrt (/ (* c -4.0) a))) (- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-218) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 2.4e-122) {
tmp = -0.5 * sqrt(((c * -4.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.6d-218)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 2.4d-122) then
tmp = (-0.5d0) * sqrt(((c * (-4.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.6e-218) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 2.4e-122) {
tmp = -0.5 * Math.sqrt(((c * -4.0) / a));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.6e-218: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 2.4e-122: tmp = -0.5 * math.sqrt(((c * -4.0) / a)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.6e-218) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 2.4e-122) tmp = Float64(-0.5 * sqrt(Float64(Float64(c * -4.0) / 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.6e-218) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 2.4e-122) tmp = -0.5 * sqrt(((c * -4.0) / a)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.6e-218], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.4e-122], N[(-0.5 * N[Sqrt[N[(N[(c * -4.0), $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.6 \cdot 10^{-218}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-122}:\\
\;\;\;\;-0.5 \cdot \sqrt{\frac{c \cdot -4}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.6000000000000001e-218Initial program 27.2%
div-sub26.6%
sub-neg26.6%
neg-mul-126.6%
*-commutative26.6%
associate-/l*26.6%
distribute-neg-frac26.6%
neg-mul-126.6%
*-commutative26.6%
associate-/l*26.7%
distribute-rgt-out27.2%
associate-/r*27.2%
metadata-eval27.2%
sub-neg27.2%
+-commutative27.2%
Simplified27.2%
associate-*l/27.2%
clear-num27.2%
*-commutative27.2%
pow227.2%
Applied egg-rr27.2%
Taylor expanded in b around -inf 74.0%
+-commutative74.0%
mul-1-neg74.0%
unsub-neg74.0%
Simplified74.0%
if -1.6000000000000001e-218 < b < 2.39999999999999987e-122Initial program 71.2%
div-sub71.2%
sub-neg71.2%
neg-mul-171.2%
*-commutative71.2%
associate-/l*71.2%
distribute-neg-frac71.2%
neg-mul-171.2%
*-commutative71.2%
associate-/l*71.1%
distribute-rgt-out71.1%
associate-/r*71.1%
metadata-eval71.1%
sub-neg71.1%
+-commutative71.1%
Simplified71.2%
add-sqr-sqrt70.9%
pow270.9%
pow1/270.9%
sqrt-pow171.0%
pow271.0%
metadata-eval71.0%
Applied egg-rr71.0%
Taylor expanded in a around -inf 33.4%
Taylor expanded in b around 0 32.9%
Simplified69.4%
add-sqr-sqrt42.0%
sqrt-unprod28.2%
pow1/228.2%
*-commutative28.2%
associate-*l*28.2%
metadata-eval28.2%
pow-pow28.2%
pow1/228.2%
*-commutative28.2%
associate-*l*28.2%
metadata-eval28.2%
pow-pow28.0%
frac-times23.0%
Applied egg-rr23.1%
unpow223.1%
times-frac35.7%
*-inverses35.7%
Simplified35.7%
if 2.39999999999999987e-122 < 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 a around 0 87.0%
+-commutative87.0%
mul-1-neg87.0%
unsub-neg87.0%
Simplified87.0%
Final simplification74.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (/ 1.0 (- (/ a b) (/ b c))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
tmp = 1.0 / ((a / b) - (b / c));
} 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 = 1.0d0 / ((a / b) - (b / c))
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 = 1.0 / ((a / b) - (b / c));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = 1.0 / ((a / b) - (b / c)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); 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 = 1.0 / ((a / b) - (b / c)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $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{1}{\frac{a}{b} - \frac{b}{c}}\\
\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%
associate-*l/31.8%
clear-num31.8%
*-commutative31.8%
pow231.8%
Applied egg-rr31.8%
Taylor expanded in b around -inf 68.4%
+-commutative68.4%
mul-1-neg68.4%
unsub-neg68.4%
Simplified68.4%
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.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
Simplified74.2%
Final simplification71.4%
(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 a 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 b around -inf 24.3%
*-commutative24.3%
associate-/l*26.5%
Simplified26.5%
associate-*l/26.5%
*-commutative26.5%
associate-*r*26.5%
metadata-eval26.5%
clear-num26.5%
un-div-inv26.5%
Applied egg-rr26.5%
mul-1-neg26.5%
distribute-frac-neg26.5%
distribute-frac-neg226.5%
associate-/r/24.1%
Simplified24.1%
Taylor expanded in a around 0 24.3%
div-inv24.3%
associate-/l*26.5%
associate-*l*30.5%
add-sqr-sqrt16.6%
sqrt-unprod16.6%
sqr-neg16.6%
sqrt-unprod4.1%
add-sqr-sqrt9.2%
Applied egg-rr9.2%
associate-*r*9.3%
*-commutative9.3%
associate-*r*9.2%
lft-mult-inverse9.2%
*-lft-identity9.2%
Simplified9.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)))