
(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 -18000000000000.0)
(/ c (- b))
(if (<= b 4e+92)
(/ (- (- 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 <= -18000000000000.0) {
tmp = c / -b;
} else if (b <= 4e+92) {
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 <= (-18000000000000.0d0)) then
tmp = c / -b
else if (b <= 4d+92) 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 <= -18000000000000.0) {
tmp = c / -b;
} else if (b <= 4e+92) {
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 <= -18000000000000.0: tmp = c / -b elif b <= 4e+92: 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 <= -18000000000000.0) tmp = Float64(c / Float64(-b)); elseif (b <= 4e+92) 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 <= -18000000000000.0) tmp = c / -b; elseif (b <= 4e+92) 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, -18000000000000.0], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4e+92], 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 -18000000000000:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+92}:\\
\;\;\;\;\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 < -1.8e13Initial program 9.1%
div-sub5.8%
sub-neg5.8%
neg-mul-15.8%
*-commutative5.8%
associate-/l*3.3%
distribute-neg-frac3.3%
neg-mul-13.3%
*-commutative3.3%
associate-/l*5.8%
distribute-rgt-out9.1%
associate-/r*9.1%
metadata-eval9.1%
sub-neg9.1%
+-commutative9.1%
Simplified9.1%
Taylor expanded in b around -inf 89.5%
mul-1-neg89.5%
distribute-neg-frac289.5%
Simplified89.5%
if -1.8e13 < b < 4.0000000000000002e92Initial program 78.4%
*-commutative78.4%
*-commutative78.4%
sqr-neg78.4%
*-commutative78.4%
sqr-neg78.4%
*-commutative78.4%
associate-*r*78.5%
Simplified78.5%
if 4.0000000000000002e92 < b Initial program 44.1%
div-sub44.1%
sub-neg44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-neg-frac44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-rgt-out44.1%
associate-/r*44.1%
metadata-eval44.1%
sub-neg44.1%
+-commutative44.1%
Simplified44.3%
Taylor expanded in c around 0 92.3%
+-commutative92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
Final simplification85.1%
(FPCore (a b c)
:precision binary64
(if (<= b -70000000000000.0)
(/ c (- b))
(if (<= b 5e+92)
(/ (- (- 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 <= -70000000000000.0) {
tmp = c / -b;
} else if (b <= 5e+92) {
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 <= (-70000000000000.0d0)) then
tmp = c / -b
else if (b <= 5d+92) 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 <= -70000000000000.0) {
tmp = c / -b;
} else if (b <= 5e+92) {
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 <= -70000000000000.0: tmp = c / -b elif b <= 5e+92: 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 <= -70000000000000.0) tmp = Float64(c / Float64(-b)); elseif (b <= 5e+92) 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 <= -70000000000000.0) tmp = c / -b; elseif (b <= 5e+92) 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, -70000000000000.0], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5e+92], 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 -70000000000000:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+92}:\\
\;\;\;\;\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 < -7e13Initial program 9.1%
div-sub5.8%
sub-neg5.8%
neg-mul-15.8%
*-commutative5.8%
associate-/l*3.3%
distribute-neg-frac3.3%
neg-mul-13.3%
*-commutative3.3%
associate-/l*5.8%
distribute-rgt-out9.1%
associate-/r*9.1%
metadata-eval9.1%
sub-neg9.1%
+-commutative9.1%
Simplified9.1%
Taylor expanded in b around -inf 89.5%
mul-1-neg89.5%
distribute-neg-frac289.5%
Simplified89.5%
if -7e13 < b < 5.00000000000000022e92Initial program 78.4%
if 5.00000000000000022e92 < b Initial program 44.1%
div-sub44.1%
sub-neg44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-neg-frac44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-rgt-out44.1%
associate-/r*44.1%
metadata-eval44.1%
sub-neg44.1%
+-commutative44.1%
Simplified44.3%
Taylor expanded in c around 0 92.3%
+-commutative92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
Final simplification85.1%
(FPCore (a b c)
:precision binary64
(if (<= b -3.3e-103)
(/ c (- b))
(if (<= b 1.72e-46)
(* (/ -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.3e-103) {
tmp = c / -b;
} else if (b <= 1.72e-46) {
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.3d-103)) then
tmp = c / -b
else if (b <= 1.72d-46) 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.3e-103) {
tmp = c / -b;
} else if (b <= 1.72e-46) {
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.3e-103: tmp = c / -b elif b <= 1.72e-46: 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.3e-103) tmp = Float64(c / Float64(-b)); elseif (b <= 1.72e-46) 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.3e-103) tmp = c / -b; elseif (b <= 1.72e-46) 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.3e-103], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.72e-46], 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.3 \cdot 10^{-103}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.72 \cdot 10^{-46}:\\
\;\;\;\;\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.2999999999999999e-103Initial program 16.2%
div-sub13.7%
sub-neg13.7%
neg-mul-113.7%
*-commutative13.7%
associate-/l*11.7%
distribute-neg-frac11.7%
neg-mul-111.7%
*-commutative11.7%
associate-/l*13.7%
distribute-rgt-out16.2%
associate-/r*16.3%
metadata-eval16.3%
sub-neg16.3%
+-commutative16.3%
Simplified16.3%
Taylor expanded in b around -inf 77.5%
mul-1-neg77.5%
distribute-neg-frac277.5%
Simplified77.5%
if -3.2999999999999999e-103 < b < 1.7199999999999999e-46Initial program 83.7%
div-sub83.7%
sub-neg83.7%
neg-mul-183.7%
*-commutative83.7%
associate-/l*83.7%
distribute-neg-frac83.7%
neg-mul-183.7%
*-commutative83.7%
associate-/l*83.4%
distribute-rgt-out83.4%
associate-/r*83.4%
metadata-eval83.4%
sub-neg83.4%
+-commutative83.4%
Simplified83.6%
Taylor expanded in a around inf 77.3%
*-commutative77.3%
Simplified77.3%
if 1.7199999999999999e-46 < b Initial program 61.4%
div-sub61.4%
sub-neg61.4%
neg-mul-161.4%
*-commutative61.4%
associate-/l*61.3%
distribute-neg-frac61.3%
neg-mul-161.3%
*-commutative61.3%
associate-/l*61.3%
distribute-rgt-out61.3%
associate-/r*61.3%
metadata-eval61.3%
sub-neg61.3%
+-commutative61.3%
Simplified61.4%
Taylor expanded in c around 0 87.3%
+-commutative87.3%
mul-1-neg87.3%
unsub-neg87.3%
Simplified87.3%
Final simplification80.8%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 30.9%
div-sub29.0%
sub-neg29.0%
neg-mul-129.0%
*-commutative29.0%
associate-/l*27.4%
distribute-neg-frac27.4%
neg-mul-127.4%
*-commutative27.4%
associate-/l*28.9%
distribute-rgt-out30.8%
associate-/r*30.8%
metadata-eval30.8%
sub-neg30.8%
+-commutative30.8%
Simplified30.9%
Taylor expanded in b around -inf 65.0%
mul-1-neg65.0%
distribute-neg-frac265.0%
Simplified65.0%
if -3.999999999999988e-310 < b Initial program 67.9%
div-sub67.9%
sub-neg67.9%
neg-mul-167.9%
*-commutative67.9%
associate-/l*67.9%
distribute-neg-frac67.9%
neg-mul-167.9%
*-commutative67.9%
associate-/l*67.8%
distribute-rgt-out67.8%
associate-/r*67.8%
metadata-eval67.8%
sub-neg67.8%
+-commutative67.8%
Simplified67.9%
Taylor expanded in c around 0 66.7%
+-commutative66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
(FPCore (a b c) :precision binary64 (if (<= b -2e-256) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-256) {
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 <= (-2d-256)) 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 <= -2e-256) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-256: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-256) 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 <= -2e-256) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-256], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-256}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.99999999999999995e-256Initial program 28.8%
div-sub26.7%
sub-neg26.7%
neg-mul-126.7%
*-commutative26.7%
associate-/l*25.1%
distribute-neg-frac25.1%
neg-mul-125.1%
*-commutative25.1%
associate-/l*26.7%
distribute-rgt-out28.7%
associate-/r*28.7%
metadata-eval28.7%
sub-neg28.7%
+-commutative28.7%
Simplified28.8%
Taylor expanded in b around -inf 66.9%
mul-1-neg66.9%
distribute-neg-frac266.9%
Simplified66.9%
if -1.99999999999999995e-256 < 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.7%
distribute-rgt-out68.7%
associate-/r*68.7%
metadata-eval68.7%
sub-neg68.7%
+-commutative68.7%
Simplified68.8%
Taylor expanded in a around 0 64.4%
associate-*r/64.4%
mul-1-neg64.4%
Simplified64.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 / 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.0%
div-sub48.0%
sub-neg48.0%
neg-mul-148.0%
*-commutative48.0%
associate-/l*47.2%
distribute-neg-frac47.2%
neg-mul-147.2%
*-commutative47.2%
associate-/l*47.9%
distribute-rgt-out48.9%
associate-/r*48.9%
metadata-eval48.9%
sub-neg48.9%
+-commutative48.9%
Simplified49.0%
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 49.0%
div-sub48.0%
sub-neg48.0%
neg-mul-148.0%
*-commutative48.0%
associate-/l*47.2%
distribute-neg-frac47.2%
neg-mul-147.2%
*-commutative47.2%
associate-/l*47.9%
distribute-rgt-out48.9%
associate-/r*48.9%
metadata-eval48.9%
sub-neg48.9%
+-commutative48.9%
Simplified49.0%
Taylor expanded in a around 0 31.8%
associate-/l*33.6%
Simplified33.6%
Taylor expanded in a around inf 10.5%
(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 49.0%
div-sub48.0%
sub-neg48.0%
neg-mul-148.0%
*-commutative48.0%
associate-/l*47.2%
distribute-neg-frac47.2%
neg-mul-147.2%
*-commutative47.2%
associate-/l*47.9%
distribute-rgt-out48.9%
associate-/r*48.9%
metadata-eval48.9%
sub-neg48.9%
+-commutative48.9%
Simplified49.0%
Taylor expanded in a around 0 33.8%
associate-*r/33.8%
mul-1-neg33.8%
Simplified33.8%
div-inv33.7%
add-sqr-sqrt1.4%
sqrt-unprod2.0%
sqr-neg2.0%
sqrt-unprod0.6%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
associate-*r/2.6%
*-rgt-identity2.6%
Simplified2.6%
(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 2024135
(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)))