
(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 -6.5e-106)
(/ c (- b))
(if (<= b 1e+76)
(/ (- (- 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 <= -6.5e-106) {
tmp = c / -b;
} else if (b <= 1e+76) {
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 <= (-6.5d-106)) then
tmp = c / -b
else if (b <= 1d+76) 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 <= -6.5e-106) {
tmp = c / -b;
} else if (b <= 1e+76) {
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 <= -6.5e-106: tmp = c / -b elif b <= 1e+76: 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 <= -6.5e-106) tmp = Float64(c / Float64(-b)); elseif (b <= 1e+76) 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 <= -6.5e-106) tmp = c / -b; elseif (b <= 1e+76) 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, -6.5e-106], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1e+76], 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 -6.5 \cdot 10^{-106}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 10^{+76}:\\
\;\;\;\;\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 < -6.4999999999999997e-106Initial program 16.7%
div-sub16.4%
sub-neg16.4%
neg-mul-116.4%
*-commutative16.4%
associate-/l*14.6%
distribute-neg-frac14.6%
neg-mul-114.6%
*-commutative14.6%
associate-/l*16.4%
distribute-rgt-out16.7%
associate-/r*16.7%
metadata-eval16.7%
sub-neg16.7%
+-commutative16.7%
Simplified16.8%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -6.4999999999999997e-106 < b < 1e76Initial program 80.2%
if 1e76 < b Initial program 60.9%
div-sub60.9%
sub-neg60.9%
neg-mul-160.9%
*-commutative60.9%
associate-/l*60.9%
distribute-neg-frac60.9%
neg-mul-160.9%
*-commutative60.9%
associate-/l*60.8%
distribute-rgt-out60.8%
associate-/r*60.8%
metadata-eval60.8%
sub-neg60.8%
+-commutative60.8%
Simplified61.0%
Taylor expanded in a around 0 94.8%
associate-*r/94.8%
mul-1-neg94.8%
Simplified94.8%
Final simplification85.9%
(FPCore (a b c)
:precision binary64
(if (<= b -2.7e-107)
(/ c (- b))
(if (<= b 9.5e-98)
(/ (* -0.5 (+ b (sqrt (* (* c a) -4.0)))) a)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-107) {
tmp = c / -b;
} else if (b <= 9.5e-98) {
tmp = (-0.5 * (b + sqrt(((c * a) * -4.0)))) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.7d-107)) then
tmp = c / -b
else if (b <= 9.5d-98) then
tmp = ((-0.5d0) * (b + sqrt(((c * a) * (-4.0d0))))) / a
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-107) {
tmp = c / -b;
} else if (b <= 9.5e-98) {
tmp = (-0.5 * (b + Math.sqrt(((c * a) * -4.0)))) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.7e-107: tmp = c / -b elif b <= 9.5e-98: tmp = (-0.5 * (b + math.sqrt(((c * a) * -4.0)))) / a else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-107) tmp = Float64(c / Float64(-b)); elseif (b <= 9.5e-98) tmp = Float64(Float64(-0.5 * Float64(b + sqrt(Float64(Float64(c * a) * -4.0)))) / a); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.7e-107) tmp = c / -b; elseif (b <= 9.5e-98) tmp = (-0.5 * (b + sqrt(((c * a) * -4.0)))) / a; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-107], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 9.5e-98], N[(N[(-0.5 * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-107}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-98}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.7e-107Initial program 16.7%
div-sub16.4%
sub-neg16.4%
neg-mul-116.4%
*-commutative16.4%
associate-/l*14.6%
distribute-neg-frac14.6%
neg-mul-114.6%
*-commutative14.6%
associate-/l*16.4%
distribute-rgt-out16.7%
associate-/r*16.7%
metadata-eval16.7%
sub-neg16.7%
+-commutative16.7%
Simplified16.8%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -2.7e-107 < b < 9.5000000000000001e-98Initial program 75.0%
*-commutative75.0%
*-commutative75.0%
sqr-neg75.0%
*-commutative75.0%
sqr-neg75.0%
*-commutative75.0%
associate-*r*75.0%
Simplified75.0%
add-sqr-sqrt30.8%
sqrt-unprod22.2%
*-commutative22.2%
*-commutative22.2%
swap-sqr21.9%
metadata-eval21.9%
metadata-eval21.9%
swap-sqr22.2%
sqrt-unprod0.8%
add-sqr-sqrt2.5%
*-commutative2.5%
metadata-eval2.5%
distribute-lft-neg-in2.5%
add-log-exp4.4%
neg-log4.4%
add-sqr-sqrt2.7%
sqrt-unprod8.2%
*-commutative8.2%
*-commutative8.2%
swap-sqr8.2%
metadata-eval8.2%
metadata-eval8.2%
swap-sqr8.2%
sqrt-unprod5.5%
add-sqr-sqrt9.0%
exp-prod9.0%
Applied egg-rr9.0%
Taylor expanded in c around inf 9.0%
associate-*r/9.0%
*-commutative9.0%
exp-prod9.0%
rem-log-exp75.0%
*-commutative75.0%
unpow275.0%
fmm-def75.0%
associate-*r*75.0%
*-commutative75.0%
distribute-lft-neg-in75.0%
metadata-eval75.0%
Simplified75.0%
Taylor expanded in b around 0 73.7%
*-commutative73.7%
Simplified73.7%
if 9.5000000000000001e-98 < b Initial program 71.8%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.6%
distribute-neg-frac71.6%
neg-mul-171.6%
*-commutative71.6%
associate-/l*71.6%
distribute-rgt-out71.6%
associate-/r*71.6%
metadata-eval71.6%
sub-neg71.6%
+-commutative71.6%
Simplified71.7%
Taylor expanded in c around 0 83.4%
+-commutative83.4%
mul-1-neg83.4%
unsub-neg83.4%
Simplified83.4%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e-105)
(/ c (- b))
(if (<= b 4.1e-95)
(* (/ -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 <= -1.05e-105) {
tmp = c / -b;
} else if (b <= 4.1e-95) {
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 <= (-1.05d-105)) then
tmp = c / -b
else if (b <= 4.1d-95) 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 <= -1.05e-105) {
tmp = c / -b;
} else if (b <= 4.1e-95) {
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 <= -1.05e-105: tmp = c / -b elif b <= 4.1e-95: 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 <= -1.05e-105) tmp = Float64(c / Float64(-b)); elseif (b <= 4.1e-95) 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 <= -1.05e-105) tmp = c / -b; elseif (b <= 4.1e-95) 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, -1.05e-105], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.1e-95], 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 -1.05 \cdot 10^{-105}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.1 \cdot 10^{-95}:\\
\;\;\;\;\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 < -1.05e-105Initial program 16.7%
div-sub16.4%
sub-neg16.4%
neg-mul-116.4%
*-commutative16.4%
associate-/l*14.6%
distribute-neg-frac14.6%
neg-mul-114.6%
*-commutative14.6%
associate-/l*16.4%
distribute-rgt-out16.7%
associate-/r*16.7%
metadata-eval16.7%
sub-neg16.7%
+-commutative16.7%
Simplified16.8%
Taylor expanded in b around -inf 86.5%
mul-1-neg86.5%
distribute-neg-frac286.5%
Simplified86.5%
if -1.05e-105 < b < 4.0999999999999997e-95Initial program 75.0%
div-sub75.0%
sub-neg75.0%
neg-mul-175.0%
*-commutative75.0%
associate-/l*75.0%
distribute-neg-frac75.0%
neg-mul-175.0%
*-commutative75.0%
associate-/l*74.9%
distribute-rgt-out74.9%
associate-/r*74.9%
metadata-eval74.9%
sub-neg74.9%
+-commutative74.9%
Simplified74.9%
Taylor expanded in a around inf 73.6%
*-commutative73.6%
associate-*r*73.6%
Simplified73.6%
if 4.0999999999999997e-95 < b Initial program 71.8%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.6%
distribute-neg-frac71.6%
neg-mul-171.6%
*-commutative71.6%
associate-/l*71.6%
distribute-rgt-out71.6%
associate-/r*71.6%
metadata-eval71.6%
sub-neg71.6%
+-commutative71.6%
Simplified71.7%
Taylor expanded in c around 0 83.4%
+-commutative83.4%
mul-1-neg83.4%
unsub-neg83.4%
Simplified83.4%
(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.7%
div-sub27.5%
sub-neg27.5%
neg-mul-127.5%
*-commutative27.5%
associate-/l*26.0%
distribute-neg-frac26.0%
neg-mul-126.0%
*-commutative26.0%
associate-/l*27.4%
distribute-rgt-out27.7%
associate-/r*27.7%
metadata-eval27.7%
sub-neg27.7%
+-commutative27.7%
Simplified27.7%
Taylor expanded in b around -inf 72.9%
mul-1-neg72.9%
distribute-neg-frac272.9%
Simplified72.9%
if -9.999999999999969e-311 < b Initial program 74.5%
div-sub74.5%
sub-neg74.5%
neg-mul-174.5%
*-commutative74.5%
associate-/l*74.4%
distribute-neg-frac74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.4%
distribute-rgt-out74.4%
associate-/r*74.4%
metadata-eval74.4%
sub-neg74.4%
+-commutative74.4%
Simplified74.5%
Taylor expanded in c around 0 63.6%
+-commutative63.6%
mul-1-neg63.6%
unsub-neg63.6%
Simplified63.6%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = -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(-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 = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 27.7%
div-sub27.5%
sub-neg27.5%
neg-mul-127.5%
*-commutative27.5%
associate-/l*26.0%
distribute-neg-frac26.0%
neg-mul-126.0%
*-commutative26.0%
associate-/l*27.4%
distribute-rgt-out27.7%
associate-/r*27.7%
metadata-eval27.7%
sub-neg27.7%
+-commutative27.7%
Simplified27.7%
Taylor expanded in b around -inf 72.9%
mul-1-neg72.9%
distribute-neg-frac272.9%
Simplified72.9%
if -9.999999999999969e-311 < b Initial program 74.5%
div-sub74.5%
sub-neg74.5%
neg-mul-174.5%
*-commutative74.5%
associate-/l*74.4%
distribute-neg-frac74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.4%
distribute-rgt-out74.4%
associate-/r*74.4%
metadata-eval74.4%
sub-neg74.4%
+-commutative74.4%
Simplified74.5%
Taylor expanded in a around 0 62.9%
associate-*r/62.9%
mul-1-neg62.9%
Simplified62.9%
(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.1%
div-sub49.0%
sub-neg49.0%
neg-mul-149.0%
*-commutative49.0%
associate-/l*48.2%
distribute-neg-frac48.2%
neg-mul-148.2%
*-commutative48.2%
associate-/l*48.9%
distribute-rgt-out49.0%
associate-/r*49.0%
metadata-eval49.0%
sub-neg49.0%
+-commutative49.0%
Simplified49.1%
Taylor expanded in b around -inf 40.7%
mul-1-neg40.7%
distribute-neg-frac240.7%
Simplified40.7%
(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.1%
*-commutative49.1%
fmm-def49.1%
*-commutative49.1%
associate-*r*49.1%
distribute-lft-neg-in49.1%
*-commutative49.1%
distribute-rgt-neg-in49.1%
associate-*r*49.1%
metadata-eval49.1%
Simplified49.1%
div-inv49.1%
Applied egg-rr1.0%
associate-*r/1.0%
*-commutative1.0%
*-lft-identity1.0%
*-commutative1.0%
Simplified1.0%
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 2024152
(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)))