
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -5.4e-65)
(/ c (- b))
(if (<= b 2.9e+84)
(/ (- (- 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 <= -5.4e-65) {
tmp = c / -b;
} else if (b <= 2.9e+84) {
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 <= (-5.4d-65)) then
tmp = c / -b
else if (b <= 2.9d+84) 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 <= -5.4e-65) {
tmp = c / -b;
} else if (b <= 2.9e+84) {
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 <= -5.4e-65: tmp = c / -b elif b <= 2.9e+84: 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 <= -5.4e-65) tmp = Float64(c / Float64(-b)); elseif (b <= 2.9e+84) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.4e-65) tmp = c / -b; elseif (b <= 2.9e+84) 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, -5.4e-65], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.9e+84], 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 -5.4 \cdot 10^{-65}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{+84}:\\
\;\;\;\;\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 < -5.3999999999999997e-65Initial program 18.2%
div-sub17.6%
sub-neg17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*17.7%
distribute-rgt-out18.2%
associate-/r*18.2%
metadata-eval18.2%
sub-neg18.2%
+-commutative18.2%
Simplified18.2%
Taylor expanded in b around -inf 85.9%
mul-1-neg85.9%
distribute-neg-frac285.9%
Simplified85.9%
if -5.3999999999999997e-65 < b < 2.89999999999999989e84Initial program 80.2%
*-commutative80.2%
*-commutative80.2%
sqr-neg80.2%
*-commutative80.2%
sqr-neg80.2%
*-commutative80.2%
associate-*r*80.3%
Simplified80.3%
if 2.89999999999999989e84 < b Initial program 65.5%
div-sub65.5%
sub-neg65.5%
neg-mul-165.5%
*-commutative65.5%
associate-/l*65.4%
distribute-neg-frac65.4%
neg-mul-165.4%
*-commutative65.4%
associate-/l*65.4%
distribute-rgt-out65.4%
associate-/r*65.4%
metadata-eval65.4%
sub-neg65.4%
+-commutative65.4%
Simplified65.5%
Taylor expanded in a around 0 96.7%
associate-*r/96.7%
mul-1-neg96.7%
Simplified96.7%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e-64)
(/ c (- b))
(if (<= b 5e+81)
(/ (- (- 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.5e-64) {
tmp = c / -b;
} else if (b <= 5e+81) {
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.5d-64)) then
tmp = c / -b
else if (b <= 5d+81) 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.5e-64) {
tmp = c / -b;
} else if (b <= 5e+81) {
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.5e-64: tmp = c / -b elif b <= 5e+81: 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.5e-64) tmp = Float64(c / Float64(-b)); elseif (b <= 5e+81) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.5e-64) tmp = c / -b; elseif (b <= 5e+81) 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.5e-64], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5e+81], 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.5 \cdot 10^{-64}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+81}:\\
\;\;\;\;\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.5e-64Initial program 18.2%
div-sub17.6%
sub-neg17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*17.7%
distribute-rgt-out18.2%
associate-/r*18.2%
metadata-eval18.2%
sub-neg18.2%
+-commutative18.2%
Simplified18.2%
Taylor expanded in b around -inf 85.9%
mul-1-neg85.9%
distribute-neg-frac285.9%
Simplified85.9%
if -1.5e-64 < b < 4.9999999999999998e81Initial program 80.2%
if 4.9999999999999998e81 < b Initial program 65.5%
div-sub65.5%
sub-neg65.5%
neg-mul-165.5%
*-commutative65.5%
associate-/l*65.4%
distribute-neg-frac65.4%
neg-mul-165.4%
*-commutative65.4%
associate-/l*65.4%
distribute-rgt-out65.4%
associate-/r*65.4%
metadata-eval65.4%
sub-neg65.4%
+-commutative65.4%
Simplified65.5%
Taylor expanded in a around 0 96.7%
associate-*r/96.7%
mul-1-neg96.7%
Simplified96.7%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-68)
(/ c (- b))
(if (<= b 3.3e-90)
(* (/ -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 <= -9e-68) {
tmp = c / -b;
} else if (b <= 3.3e-90) {
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 <= (-9d-68)) then
tmp = c / -b
else if (b <= 3.3d-90) 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 <= -9e-68) {
tmp = c / -b;
} else if (b <= 3.3e-90) {
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 <= -9e-68: tmp = c / -b elif b <= 3.3e-90: 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 <= -9e-68) tmp = Float64(c / Float64(-b)); elseif (b <= 3.3e-90) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-68) tmp = c / -b; elseif (b <= 3.3e-90) 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, -9e-68], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.3e-90], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-68}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-90}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.99999999999999998e-68Initial program 18.2%
div-sub17.6%
sub-neg17.6%
neg-mul-117.6%
*-commutative17.6%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*17.7%
distribute-rgt-out18.2%
associate-/r*18.2%
metadata-eval18.2%
sub-neg18.2%
+-commutative18.2%
Simplified18.2%
Taylor expanded in b around -inf 85.9%
mul-1-neg85.9%
distribute-neg-frac285.9%
Simplified85.9%
if -8.99999999999999998e-68 < b < 3.3e-90Initial program 71.0%
div-sub71.0%
sub-neg71.0%
neg-mul-171.0%
*-commutative71.0%
associate-/l*71.0%
distribute-neg-frac71.0%
neg-mul-171.0%
*-commutative71.0%
associate-/l*70.8%
distribute-rgt-out70.9%
associate-/r*70.9%
metadata-eval70.9%
sub-neg70.9%
+-commutative70.9%
Simplified71.0%
Taylor expanded in b around inf 20.9%
associate-/l*16.7%
Simplified16.7%
Taylor expanded in b around 0 68.6%
associate-*r*68.7%
*-commutative68.7%
Simplified68.7%
if 3.3e-90 < b Initial program 78.2%
div-sub78.2%
sub-neg78.2%
neg-mul-178.2%
*-commutative78.2%
associate-/l*78.1%
distribute-neg-frac78.1%
neg-mul-178.1%
*-commutative78.1%
associate-/l*78.0%
distribute-rgt-out78.0%
associate-/r*78.0%
metadata-eval78.0%
sub-neg78.0%
+-commutative78.0%
Simplified78.0%
Taylor expanded in c around 0 87.5%
+-commutative87.5%
mul-1-neg87.5%
unsub-neg87.5%
Simplified87.5%
Final simplification82.0%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 34.9%
div-sub34.5%
sub-neg34.5%
neg-mul-134.5%
*-commutative34.5%
associate-/l*34.1%
distribute-neg-frac34.1%
neg-mul-134.1%
*-commutative34.1%
associate-/l*34.5%
distribute-rgt-out34.9%
associate-/r*34.9%
metadata-eval34.9%
sub-neg34.9%
+-commutative34.9%
Simplified34.9%
Taylor expanded in b around -inf 63.7%
mul-1-neg63.7%
distribute-neg-frac263.7%
Simplified63.7%
if -1.999999999999994e-310 < 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*75.9%
distribute-rgt-out75.9%
associate-/r*75.9%
metadata-eval75.9%
sub-neg75.9%
+-commutative75.9%
Simplified76.0%
Taylor expanded in c around 0 72.2%
+-commutative72.2%
mul-1-neg72.2%
unsub-neg72.2%
Simplified72.2%
(FPCore (a b c) :precision binary64 (if (<= b -3.3e-307) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.3e-307) {
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.3d-307)) 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.3e-307) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.3e-307: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.3e-307) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.3e-307) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.3e-307], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.3 \cdot 10^{-307}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.3e-307Initial program 34.4%
div-sub34.0%
sub-neg34.0%
neg-mul-134.0%
*-commutative34.0%
associate-/l*33.6%
distribute-neg-frac33.6%
neg-mul-133.6%
*-commutative33.6%
associate-/l*34.0%
distribute-rgt-out34.4%
associate-/r*34.4%
metadata-eval34.4%
sub-neg34.4%
+-commutative34.4%
Simplified34.4%
Taylor expanded in b around -inf 64.2%
mul-1-neg64.2%
distribute-neg-frac264.2%
Simplified64.2%
if -3.3e-307 < b Initial program 76.3%
div-sub76.3%
sub-neg76.3%
neg-mul-176.3%
*-commutative76.3%
associate-/l*76.2%
distribute-neg-frac76.2%
neg-mul-176.2%
*-commutative76.2%
associate-/l*76.1%
distribute-rgt-out76.1%
associate-/r*76.1%
metadata-eval76.1%
sub-neg76.1%
+-commutative76.1%
Simplified76.2%
Taylor expanded in a around 0 71.3%
associate-*r/71.3%
mul-1-neg71.3%
Simplified71.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 54.5%
div-sub54.3%
sub-neg54.3%
neg-mul-154.3%
*-commutative54.3%
associate-/l*54.1%
distribute-neg-frac54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*54.2%
distribute-rgt-out54.4%
associate-/r*54.4%
metadata-eval54.4%
sub-neg54.4%
+-commutative54.4%
Simplified54.5%
Taylor expanded in b around -inf 34.3%
mul-1-neg34.3%
distribute-neg-frac234.3%
Simplified34.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 54.5%
div-sub54.3%
sub-neg54.3%
neg-mul-154.3%
*-commutative54.3%
associate-/l*54.1%
distribute-neg-frac54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*54.2%
distribute-rgt-out54.4%
associate-/r*54.4%
metadata-eval54.4%
sub-neg54.4%
+-commutative54.4%
Simplified54.5%
Taylor expanded in a around 0 34.9%
Taylor expanded in b around 0 10.4%
(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 54.5%
div-sub54.3%
sub-neg54.3%
neg-mul-154.3%
*-commutative54.3%
associate-/l*54.1%
distribute-neg-frac54.1%
neg-mul-154.1%
*-commutative54.1%
associate-/l*54.2%
distribute-rgt-out54.4%
associate-/r*54.4%
metadata-eval54.4%
sub-neg54.4%
+-commutative54.4%
Simplified54.5%
Applied egg-rr33.5%
Taylor expanded in b around -inf 2.5%
(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 2024108
(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)))