
(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 -7.2e-34)
(/ c (- b))
(if (<= b 6e+118)
(/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) (* a (- 2.0)))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-34) {
tmp = c / -b;
} else if (b <= 6e+118) {
tmp = (b + sqrt(((b * b) - (4.0 * (c * a))))) / (a * -2.0);
} 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 <= (-7.2d-34)) then
tmp = c / -b
else if (b <= 6d+118) then
tmp = (b + sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * -2.0d0)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-34) {
tmp = c / -b;
} else if (b <= 6e+118) {
tmp = (b + Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * -2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e-34: tmp = c / -b elif b <= 6e+118: tmp = (b + math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * -2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-34) tmp = Float64(c / Float64(-b)); elseif (b <= 6e+118) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * Float64(-2.0))); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.2e-34) tmp = c / -b; elseif (b <= 6e+118) tmp = (b + sqrt(((b * b) - (4.0 * (c * a))))) / (a * -2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-34], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6e+118], 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[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-34}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{+118}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -7.20000000000000016e-34Initial program 9.2%
div-sub8.6%
sub-neg8.6%
neg-mul-18.6%
*-commutative8.6%
associate-/l*7.5%
distribute-neg-frac7.5%
neg-mul-17.5%
*-commutative7.5%
associate-/l*8.6%
distribute-rgt-out9.2%
associate-/r*9.2%
metadata-eval9.2%
sub-neg9.2%
+-commutative9.2%
Simplified8.5%
Taylor expanded in b around -inf 89.4%
associate-*r/89.4%
neg-mul-189.4%
Simplified89.4%
if -7.20000000000000016e-34 < b < 6e118Initial program 84.8%
if 6e118 < b Initial program 54.1%
div-sub54.1%
sub-neg54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*54.1%
distribute-neg-frac54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*54.1%
distribute-rgt-out54.1%
associate-/r*54.1%
metadata-eval54.1%
sub-neg54.1%
+-commutative54.1%
Simplified54.1%
Taylor expanded in a around 0 96.5%
associate-*r/96.5%
mul-1-neg96.5%
Simplified96.5%
Final simplification88.9%
(FPCore (a b c)
:precision binary64
(if (<= b -7.4e-34)
(/ c (- b))
(if (<= b 2.6e-25)
(/ 1.0 (/ a (* -0.5 (+ b (sqrt (* c (* a -4.0)))))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.4e-34) {
tmp = c / -b;
} else if (b <= 2.6e-25) {
tmp = 1.0 / (a / (-0.5 * (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 <= (-7.4d-34)) then
tmp = c / -b
else if (b <= 2.6d-25) then
tmp = 1.0d0 / (a / ((-0.5d0) * (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 <= -7.4e-34) {
tmp = c / -b;
} else if (b <= 2.6e-25) {
tmp = 1.0 / (a / (-0.5 * (b + Math.sqrt((c * (a * -4.0))))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.4e-34: tmp = c / -b elif b <= 2.6e-25: tmp = 1.0 / (a / (-0.5 * (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 <= -7.4e-34) tmp = Float64(c / Float64(-b)); elseif (b <= 2.6e-25) tmp = Float64(1.0 / Float64(a / Float64(-0.5 * 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 <= -7.4e-34) tmp = c / -b; elseif (b <= 2.6e-25) tmp = 1.0 / (a / (-0.5 * (b + sqrt((c * (a * -4.0)))))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.4e-34], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.6e-25], N[(1.0 / N[(a / N[(-0.5 * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $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 -7.4 \cdot 10^{-34}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{\frac{a}{-0.5 \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 < -7.39999999999999976e-34Initial program 9.2%
div-sub8.6%
sub-neg8.6%
neg-mul-18.6%
*-commutative8.6%
associate-/l*7.5%
distribute-neg-frac7.5%
neg-mul-17.5%
*-commutative7.5%
associate-/l*8.6%
distribute-rgt-out9.2%
associate-/r*9.2%
metadata-eval9.2%
sub-neg9.2%
+-commutative9.2%
Simplified8.5%
Taylor expanded in b around -inf 89.4%
associate-*r/89.4%
neg-mul-189.4%
Simplified89.4%
if -7.39999999999999976e-34 < b < 2.6e-25Initial program 81.3%
div-sub81.3%
sub-neg81.3%
neg-mul-181.3%
*-commutative81.3%
associate-/l*81.3%
distribute-neg-frac81.3%
neg-mul-181.3%
*-commutative81.3%
associate-/l*81.1%
distribute-rgt-out81.1%
associate-/r*81.1%
metadata-eval81.1%
sub-neg81.1%
+-commutative81.1%
Simplified81.1%
Taylor expanded in a around inf 73.9%
*-commutative73.9%
associate-*r*73.9%
Simplified73.9%
associate-*l/74.1%
clear-num74.0%
associate-*r*74.0%
*-commutative74.0%
associate-*l*74.0%
Applied egg-rr74.0%
if 2.6e-25 < b Initial program 68.1%
div-sub68.1%
sub-neg68.1%
neg-mul-168.1%
*-commutative68.1%
associate-/l*68.0%
distribute-neg-frac68.0%
neg-mul-168.0%
*-commutative68.0%
associate-/l*68.0%
distribute-rgt-out68.0%
associate-/r*68.0%
metadata-eval68.0%
sub-neg68.0%
+-commutative68.0%
Simplified68.0%
Taylor expanded in c around 0 91.7%
+-commutative91.7%
mul-1-neg91.7%
unsub-neg91.7%
Simplified91.7%
Final simplification85.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e-34)
(/ c (- b))
(if (<= b 2.5e-27)
(* (/ -0.5 a) (+ b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e-34) {
tmp = c / -b;
} else if (b <= 2.5e-27) {
tmp = (-0.5 / a) * (b + sqrt((a * (c * -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.8d-34)) then
tmp = c / -b
else if (b <= 2.5d-27) then
tmp = ((-0.5d0) / a) * (b + sqrt((a * (c * (-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.8e-34) {
tmp = c / -b;
} else if (b <= 2.5e-27) {
tmp = (-0.5 / a) * (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e-34: tmp = c / -b elif b <= 2.5e-27: tmp = (-0.5 / a) * (b + math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e-34) tmp = Float64(c / Float64(-b)); elseif (b <= 2.5e-27) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(a * Float64(c * -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.8e-34) tmp = c / -b; elseif (b <= 2.5e-27) tmp = (-0.5 / a) * (b + sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e-34], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.5e-27], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -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.8 \cdot 10^{-34}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-27}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.79999999999999997e-34Initial program 9.2%
div-sub8.6%
sub-neg8.6%
neg-mul-18.6%
*-commutative8.6%
associate-/l*7.5%
distribute-neg-frac7.5%
neg-mul-17.5%
*-commutative7.5%
associate-/l*8.6%
distribute-rgt-out9.2%
associate-/r*9.2%
metadata-eval9.2%
sub-neg9.2%
+-commutative9.2%
Simplified8.5%
Taylor expanded in b around -inf 89.4%
associate-*r/89.4%
neg-mul-189.4%
Simplified89.4%
if -2.79999999999999997e-34 < b < 2.5000000000000001e-27Initial program 81.3%
div-sub81.3%
sub-neg81.3%
neg-mul-181.3%
*-commutative81.3%
associate-/l*81.3%
distribute-neg-frac81.3%
neg-mul-181.3%
*-commutative81.3%
associate-/l*81.1%
distribute-rgt-out81.1%
associate-/r*81.1%
metadata-eval81.1%
sub-neg81.1%
+-commutative81.1%
Simplified81.1%
Taylor expanded in a around inf 73.9%
*-commutative73.9%
associate-*r*73.9%
Simplified73.9%
if 2.5000000000000001e-27 < b Initial program 68.1%
div-sub68.1%
sub-neg68.1%
neg-mul-168.1%
*-commutative68.1%
associate-/l*68.0%
distribute-neg-frac68.0%
neg-mul-168.0%
*-commutative68.0%
associate-/l*68.0%
distribute-rgt-out68.0%
associate-/r*68.0%
metadata-eval68.0%
sub-neg68.0%
+-commutative68.0%
Simplified68.0%
Taylor expanded in c around 0 91.7%
+-commutative91.7%
mul-1-neg91.7%
unsub-neg91.7%
Simplified91.7%
Final simplification85.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-36)
(/ c (- b))
(if (<= b 1.02e-131)
(/ (sqrt (* a (* c -4.0))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-36) {
tmp = c / -b;
} else if (b <= 1.02e-131) {
tmp = sqrt((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 <= (-2.9d-36)) then
tmp = c / -b
else if (b <= 1.02d-131) then
tmp = sqrt((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 <= -2.9e-36) {
tmp = c / -b;
} else if (b <= 1.02e-131) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-36: tmp = c / -b elif b <= 1.02e-131: tmp = math.sqrt((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 <= -2.9e-36) tmp = Float64(c / Float64(-b)); elseif (b <= 1.02e-131) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * Float64(-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 <= -2.9e-36) tmp = c / -b; elseif (b <= 1.02e-131) tmp = sqrt((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, -2.9e-36], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.02e-131], N[(N[Sqrt[N[(a * N[(c * -4.0), $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.9 \cdot 10^{-36}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-131}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.90000000000000013e-36Initial program 9.2%
div-sub8.6%
sub-neg8.6%
neg-mul-18.6%
*-commutative8.6%
associate-/l*7.5%
distribute-neg-frac7.5%
neg-mul-17.5%
*-commutative7.5%
associate-/l*8.6%
distribute-rgt-out9.2%
associate-/r*9.2%
metadata-eval9.2%
sub-neg9.2%
+-commutative9.2%
Simplified8.5%
Taylor expanded in b around -inf 89.4%
associate-*r/89.4%
neg-mul-189.4%
Simplified89.4%
if -2.90000000000000013e-36 < b < 1.02000000000000001e-131Initial program 79.7%
add-cube-cbrt78.9%
pow379.0%
*-commutative79.0%
*-commutative79.0%
associate-*l*79.0%
Applied egg-rr79.0%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt79.2%
mul-1-neg79.2%
rem-cube-cbrt79.8%
Simplified79.8%
if 1.02000000000000001e-131 < b Initial program 71.4%
div-sub71.4%
sub-neg71.4%
neg-mul-171.4%
*-commutative71.4%
associate-/l*71.4%
distribute-neg-frac71.4%
neg-mul-171.4%
*-commutative71.4%
associate-/l*71.3%
distribute-rgt-out71.3%
associate-/r*71.3%
metadata-eval71.3%
sub-neg71.3%
+-commutative71.3%
Simplified71.3%
Taylor expanded in c around 0 84.0%
+-commutative84.0%
mul-1-neg84.0%
unsub-neg84.0%
Simplified84.0%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.4e-135)
(/ c (- b))
(if (<= b 2.9e-181)
(* (sqrt (* c (/ -4.0 a))) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-135) {
tmp = c / -b;
} else if (b <= 2.9e-181) {
tmp = sqrt((c * (-4.0 / a))) * -0.5;
} 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.4d-135)) then
tmp = c / -b
else if (b <= 2.9d-181) then
tmp = sqrt((c * ((-4.0d0) / a))) * -0.5d0
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.4e-135) {
tmp = c / -b;
} else if (b <= 2.9e-181) {
tmp = Math.sqrt((c * (-4.0 / a))) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e-135: tmp = c / -b elif b <= 2.9e-181: tmp = math.sqrt((c * (-4.0 / a))) * -0.5 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e-135) tmp = Float64(c / Float64(-b)); elseif (b <= 2.9e-181) tmp = Float64(sqrt(Float64(c * Float64(-4.0 / a))) * Float64(-0.5)); 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.4e-135) tmp = c / -b; elseif (b <= 2.9e-181) tmp = sqrt((c * (-4.0 / a))) * -0.5; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e-135], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.9e-181], N[(N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-0.5)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{-135}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{-181}:\\
\;\;\;\;\sqrt{c \cdot \frac{-4}{a}} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.40000000000000012e-135Initial program 14.1%
div-sub13.6%
sub-neg13.6%
neg-mul-113.6%
*-commutative13.6%
associate-/l*12.6%
distribute-neg-frac12.6%
neg-mul-112.6%
*-commutative12.6%
associate-/l*13.6%
distribute-rgt-out14.1%
associate-/r*14.1%
metadata-eval14.1%
sub-neg14.1%
+-commutative14.1%
Simplified13.5%
Taylor expanded in b around -inf 84.2%
associate-*r/84.2%
neg-mul-184.2%
Simplified84.2%
if -1.40000000000000012e-135 < b < 2.8999999999999998e-181Initial program 82.2%
add-cube-cbrt81.3%
pow381.5%
*-commutative81.5%
*-commutative81.5%
associate-*l*81.5%
Applied egg-rr81.5%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt31.7%
neg-mul-131.7%
rem-cube-cbrt32.0%
associate-/l*32.0%
Simplified32.0%
if 2.8999999999999998e-181 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.5%
distribute-rgt-out72.5%
associate-/r*72.5%
metadata-eval72.5%
sub-neg72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in c around 0 79.5%
+-commutative79.5%
mul-1-neg79.5%
unsub-neg79.5%
Simplified79.5%
Final simplification72.1%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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 <= -1e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 27.9%
div-sub27.5%
sub-neg27.5%
neg-mul-127.5%
*-commutative27.5%
associate-/l*26.8%
distribute-neg-frac26.8%
neg-mul-126.8%
*-commutative26.8%
associate-/l*27.4%
distribute-rgt-out27.9%
associate-/r*27.9%
metadata-eval27.9%
sub-neg27.9%
+-commutative27.9%
Simplified27.4%
Taylor expanded in b around -inf 66.7%
associate-*r/66.7%
neg-mul-166.7%
Simplified66.7%
if -9.999999999999969e-311 < b Initial program 76.1%
div-sub76.1%
sub-neg76.1%
neg-mul-176.1%
*-commutative76.1%
associate-/l*76.0%
distribute-neg-frac76.0%
neg-mul-176.0%
*-commutative76.0%
associate-/l*76.0%
distribute-rgt-out76.0%
associate-/r*76.0%
metadata-eval76.0%
sub-neg76.0%
+-commutative76.0%
Simplified76.0%
Taylor expanded in c around 0 67.6%
+-commutative67.6%
mul-1-neg67.6%
unsub-neg67.6%
Simplified67.6%
Final simplification67.1%
(FPCore (a b c) :precision binary64 (if (<= b -8e-280) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-280) {
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 <= (-8d-280)) 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 <= -8e-280) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-280: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e-280) 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 <= -8e-280) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-280], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-280}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -7.9999999999999997e-280Initial program 26.3%
div-sub25.9%
sub-neg25.9%
neg-mul-125.9%
*-commutative25.9%
associate-/l*25.2%
distribute-neg-frac25.2%
neg-mul-125.2%
*-commutative25.2%
associate-/l*25.8%
distribute-rgt-out26.2%
associate-/r*26.2%
metadata-eval26.2%
sub-neg26.2%
+-commutative26.2%
Simplified25.8%
Taylor expanded in b around -inf 68.1%
associate-*r/68.1%
neg-mul-168.1%
Simplified68.1%
if -7.9999999999999997e-280 < b Initial program 76.6%
div-sub76.6%
sub-neg76.6%
neg-mul-176.6%
*-commutative76.6%
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%
sub-neg76.5%
+-commutative76.5%
Simplified76.5%
Taylor expanded in a around 0 65.7%
associate-*r/65.7%
mul-1-neg65.7%
Simplified65.7%
Final simplification67.0%
(FPCore (a b c) :precision binary64 (if (<= b -1.85e-32) (/ c b) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e-32) {
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 <= (-1.85d-32)) 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 <= -1.85e-32) {
tmp = c / b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.85e-32: tmp = c / b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.85e-32) tmp = Float64(c / b); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.85e-32) tmp = c / b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.85e-32], N[(c / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.85 \cdot 10^{-32}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.85e-32Initial program 9.2%
div-sub8.6%
sub-neg8.6%
neg-mul-18.6%
*-commutative8.6%
associate-/l*7.5%
distribute-neg-frac7.5%
neg-mul-17.5%
*-commutative7.5%
associate-/l*8.6%
distribute-rgt-out9.2%
associate-/r*9.2%
metadata-eval9.2%
sub-neg9.2%
+-commutative9.2%
Simplified8.5%
Taylor expanded in a around 0 2.1%
+-commutative2.1%
mul-1-neg2.1%
sub-neg2.1%
associate-/l*2.3%
Simplified2.3%
Taylor expanded in a around inf 25.0%
if -1.85e-32 < b Initial program 74.9%
div-sub74.9%
sub-neg74.9%
neg-mul-174.9%
*-commutative74.9%
associate-/l*74.8%
distribute-neg-frac74.8%
neg-mul-174.8%
*-commutative74.8%
associate-/l*74.7%
distribute-rgt-out74.7%
associate-/r*74.7%
metadata-eval74.7%
sub-neg74.7%
+-commutative74.7%
Simplified74.7%
Taylor expanded in a around 0 50.8%
associate-*r/50.8%
mul-1-neg50.8%
Simplified50.8%
Final simplification41.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 50.5%
div-sub50.3%
sub-neg50.3%
neg-mul-150.3%
*-commutative50.3%
associate-/l*49.9%
distribute-neg-frac49.9%
neg-mul-149.9%
*-commutative49.9%
associate-/l*50.2%
distribute-rgt-out50.4%
associate-/r*50.4%
metadata-eval50.4%
sub-neg50.4%
+-commutative50.4%
Simplified50.1%
Taylor expanded in a around 0 32.2%
+-commutative32.2%
mul-1-neg32.2%
sub-neg32.2%
associate-/l*32.7%
Simplified32.7%
Taylor expanded in a around inf 11.1%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / 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 / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 50.5%
div-sub50.3%
sub-neg50.3%
neg-mul-150.3%
*-commutative50.3%
associate-/l*49.9%
distribute-neg-frac49.9%
neg-mul-149.9%
*-commutative49.9%
associate-/l*50.2%
distribute-rgt-out50.4%
associate-/r*50.4%
metadata-eval50.4%
sub-neg50.4%
+-commutative50.4%
Simplified50.1%
Taylor expanded in a around 0 32.9%
associate-*r/32.9%
mul-1-neg32.9%
Simplified32.9%
add-sqr-sqrt1.3%
sqrt-unprod1.9%
sqr-neg1.9%
sqrt-prod0.7%
add-sqr-sqrt2.7%
div-inv2.7%
Applied egg-rr2.7%
associate-*r/2.7%
*-rgt-identity2.7%
Simplified2.7%
(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 2024160
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))