
(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 7 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 -4.2e-77)
(/ c (- b))
(if (<= b 1e+72)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.2e-77) {
tmp = c / -b;
} else if (b <= 1e+72) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * 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 <= (-4.2d-77)) then
tmp = c / -b
else if (b <= 1d+72) then
tmp = (-b - sqrt(((b * b) - ((c * 4.0d0) * 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 <= -4.2e-77) {
tmp = c / -b;
} else if (b <= 1e+72) {
tmp = (-b - Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.2e-77: tmp = c / -b elif b <= 1e+72: tmp = (-b - math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.2e-77) tmp = Float64(c / Float64(-b)); elseif (b <= 1e+72) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.2e-77) tmp = c / -b; elseif (b <= 1e+72) tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.2e-77], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1e+72], 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[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.2 \cdot 10^{-77}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 10^{+72}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -4.20000000000000031e-77Initial program 18.1%
div-sub15.6%
sub-neg15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*14.4%
distribute-neg-frac14.4%
neg-mul-114.4%
*-commutative14.4%
associate-/l*15.6%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 83.2%
mul-1-neg83.2%
distribute-neg-frac283.2%
Simplified83.2%
if -4.20000000000000031e-77 < b < 9.99999999999999944e71Initial program 78.4%
*-commutative78.4%
*-commutative78.4%
sqr-neg78.4%
*-commutative78.4%
sqr-neg78.4%
*-commutative78.4%
associate-*r*78.4%
Simplified78.4%
if 9.99999999999999944e71 < b Initial program 52.4%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-neg-frac52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.3%
distribute-rgt-out52.3%
associate-/r*52.3%
metadata-eval52.3%
sub-neg52.3%
+-commutative52.3%
Simplified52.4%
Taylor expanded in a around 0 95.0%
associate-*r/95.0%
mul-1-neg95.0%
Simplified95.0%
Final simplification83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-83)
(/ c (- b))
(if (<= b 3e+72)
(/ (- (- 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 <= -1.25e-83) {
tmp = c / -b;
} else if (b <= 3e+72) {
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 <= (-1.25d-83)) then
tmp = c / -b
else if (b <= 3d+72) 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 <= -1.25e-83) {
tmp = c / -b;
} else if (b <= 3e+72) {
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 <= -1.25e-83: tmp = c / -b elif b <= 3e+72: 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 <= -1.25e-83) tmp = Float64(c / Float64(-b)); elseif (b <= 3e+72) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.25e-83) tmp = c / -b; elseif (b <= 3e+72) 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, -1.25e-83], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3e+72], 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 -1.25 \cdot 10^{-83}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{+72}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.25e-83Initial program 18.1%
div-sub15.6%
sub-neg15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*14.4%
distribute-neg-frac14.4%
neg-mul-114.4%
*-commutative14.4%
associate-/l*15.6%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 83.2%
mul-1-neg83.2%
distribute-neg-frac283.2%
Simplified83.2%
if -1.25e-83 < b < 3.00000000000000003e72Initial program 78.4%
if 3.00000000000000003e72 < b Initial program 52.4%
div-sub52.4%
sub-neg52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.4%
distribute-neg-frac52.4%
neg-mul-152.4%
*-commutative52.4%
associate-/l*52.3%
distribute-rgt-out52.3%
associate-/r*52.3%
metadata-eval52.3%
sub-neg52.3%
+-commutative52.3%
Simplified52.4%
Taylor expanded in a around 0 95.0%
associate-*r/95.0%
mul-1-neg95.0%
Simplified95.0%
Final simplification83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -3.4e-77)
(/ c (- b))
(if (<= b 3.35e-102)
(* (/ -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 <= -3.4e-77) {
tmp = c / -b;
} else if (b <= 3.35e-102) {
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 <= (-3.4d-77)) then
tmp = c / -b
else if (b <= 3.35d-102) 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 <= -3.4e-77) {
tmp = c / -b;
} else if (b <= 3.35e-102) {
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 <= -3.4e-77: tmp = c / -b elif b <= 3.35e-102: 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 <= -3.4e-77) tmp = Float64(c / Float64(-b)); elseif (b <= 3.35e-102) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * 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 <= -3.4e-77) tmp = c / -b; elseif (b <= 3.35e-102) 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, -3.4e-77], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.35e-102], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $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^{-77}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.35 \cdot 10^{-102}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.39999999999999983e-77Initial program 18.1%
div-sub15.6%
sub-neg15.6%
neg-mul-115.6%
*-commutative15.6%
associate-/l*14.4%
distribute-neg-frac14.4%
neg-mul-114.4%
*-commutative14.4%
associate-/l*15.6%
distribute-rgt-out18.1%
associate-/r*18.1%
metadata-eval18.1%
sub-neg18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in b around -inf 83.2%
mul-1-neg83.2%
distribute-neg-frac283.2%
Simplified83.2%
if -3.39999999999999983e-77 < b < 3.35e-102Initial program 73.7%
div-sub73.7%
sub-neg73.7%
neg-mul-173.7%
*-commutative73.7%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.6%
distribute-rgt-out73.6%
associate-/r*73.6%
metadata-eval73.6%
sub-neg73.6%
+-commutative73.6%
Simplified73.8%
Taylor expanded in a around inf 69.3%
*-commutative69.3%
Simplified69.3%
if 3.35e-102 < b Initial program 66.2%
div-sub66.1%
sub-neg66.1%
neg-mul-166.1%
*-commutative66.1%
associate-/l*66.1%
distribute-neg-frac66.1%
neg-mul-166.1%
*-commutative66.1%
associate-/l*66.0%
distribute-rgt-out66.0%
associate-/r*66.0%
metadata-eval66.0%
sub-neg66.0%
+-commutative66.0%
Simplified66.0%
Taylor expanded in c around 0 84.4%
+-commutative84.4%
mul-1-neg84.4%
unsub-neg84.4%
Simplified84.4%
Final simplification80.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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-309)) 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-309) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) 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-309) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], 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^{-309}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 30.9%
div-sub29.0%
sub-neg29.0%
neg-mul-129.0%
*-commutative29.0%
associate-/l*28.2%
distribute-neg-frac28.2%
neg-mul-128.2%
*-commutative28.2%
associate-/l*29.0%
distribute-rgt-out30.9%
associate-/r*30.9%
metadata-eval30.9%
sub-neg30.9%
+-commutative30.9%
Simplified30.9%
Taylor expanded in b around -inf 65.9%
mul-1-neg65.9%
distribute-neg-frac265.9%
Simplified65.9%
if -1.000000000000002e-309 < b Initial program 68.9%
div-sub68.9%
sub-neg68.9%
neg-mul-168.9%
*-commutative68.9%
associate-/l*68.8%
distribute-neg-frac68.8%
neg-mul-168.8%
*-commutative68.8%
associate-/l*68.7%
distribute-rgt-out68.7%
associate-/r*68.7%
metadata-eval68.7%
sub-neg68.7%
+-commutative68.7%
Simplified68.8%
Taylor expanded in c around 0 69.1%
+-commutative69.1%
mul-1-neg69.1%
unsub-neg69.1%
Simplified69.1%
(FPCore (a b c) :precision binary64 (if (<= b -3.1e-251) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.1e-251) {
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.1d-251)) 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.1e-251) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.1e-251: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.1e-251) 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 <= -3.1e-251) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.1e-251], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.1 \cdot 10^{-251}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.10000000000000003e-251Initial program 26.7%
div-sub24.6%
sub-neg24.6%
neg-mul-124.6%
*-commutative24.6%
associate-/l*23.7%
distribute-neg-frac23.7%
neg-mul-123.7%
*-commutative23.7%
associate-/l*24.6%
distribute-rgt-out26.7%
associate-/r*26.7%
metadata-eval26.7%
sub-neg26.7%
+-commutative26.7%
Simplified26.8%
Taylor expanded in b around -inf 72.6%
mul-1-neg72.6%
distribute-neg-frac272.6%
Simplified72.6%
if -3.10000000000000003e-251 < b Initial program 68.9%
div-sub68.9%
sub-neg68.9%
neg-mul-168.9%
*-commutative68.9%
associate-/l*68.9%
distribute-neg-frac68.9%
neg-mul-168.9%
*-commutative68.9%
associate-/l*68.8%
distribute-rgt-out68.8%
associate-/r*68.8%
metadata-eval68.8%
sub-neg68.8%
+-commutative68.8%
Simplified68.8%
Taylor expanded in a around 0 62.7%
associate-*r/62.7%
mul-1-neg62.7%
Simplified62.7%
Final simplification67.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 / 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 49.2%
div-sub48.2%
sub-neg48.2%
neg-mul-148.2%
*-commutative48.2%
associate-/l*47.7%
distribute-neg-frac47.7%
neg-mul-147.7%
*-commutative47.7%
associate-/l*48.1%
distribute-rgt-out49.1%
associate-/r*49.1%
metadata-eval49.1%
sub-neg49.1%
+-commutative49.1%
Simplified49.1%
Taylor expanded in b around -inf 35.4%
mul-1-neg35.4%
distribute-neg-frac235.4%
Simplified35.4%
(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 49.2%
div-sub48.2%
sub-neg48.2%
neg-mul-148.2%
*-commutative48.2%
associate-/l*47.7%
distribute-neg-frac47.7%
neg-mul-147.7%
*-commutative47.7%
associate-/l*48.1%
distribute-rgt-out49.1%
associate-/r*49.1%
metadata-eval49.1%
sub-neg49.1%
+-commutative49.1%
Simplified49.1%
Taylor expanded in a around 0 32.5%
Taylor expanded in a around inf 11.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 2024088
(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)))