
(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 9 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 -2.5e-23)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 3.8e+55)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* a 2.0))
(/ (- (* (/ a b) c) b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e-23) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 3.8e+55) {
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0);
} else {
tmp = (((a / b) * c) - 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.5d-23)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 3.8d+55) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (a * 2.0d0)
else
tmp = (((a / b) * c) - b) / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e-23) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 3.8e+55) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0);
} else {
tmp = (((a / b) * c) - b) / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.5e-23: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 3.8e+55: tmp = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0) else: tmp = (((a / b) * c) - b) / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.5e-23) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 3.8e+55) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(Float64(a / b) * c) - b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.5e-23) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 3.8e+55) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0); else tmp = (((a / b) * c) - b) / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.5e-23], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.8e+55], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(a / b), $MachinePrecision] * c), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.5 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{+55}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a}{b} \cdot c - b}{a}\\
\end{array}
\end{array}
if b < -2.5000000000000001e-23Initial program 14.7%
div-sub12.9%
sub-neg12.9%
neg-mul-112.9%
*-commutative12.9%
associate-/l*11.6%
distribute-neg-frac11.6%
neg-mul-111.6%
*-commutative11.6%
associate-/l*12.9%
distribute-rgt-out14.7%
associate-/r*14.7%
metadata-eval14.7%
sub-neg14.7%
+-commutative14.7%
Simplified14.3%
associate-*l/14.3%
clear-num14.3%
*-commutative14.3%
pow214.3%
Applied egg-rr14.3%
Taylor expanded in b around -inf 88.7%
associate-*r*88.7%
neg-mul-188.7%
+-commutative88.7%
mul-1-neg88.7%
unsub-neg88.7%
Simplified88.7%
Taylor expanded in c around inf 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
if -2.5000000000000001e-23 < b < 3.8e55Initial program 78.6%
if 3.8e55 < b Initial program 66.2%
div-sub66.2%
sub-neg66.2%
neg-mul-166.2%
*-commutative66.2%
associate-/l*66.2%
distribute-neg-frac66.2%
neg-mul-166.2%
*-commutative66.2%
associate-/l*66.1%
distribute-rgt-out66.1%
associate-/r*66.1%
metadata-eval66.1%
sub-neg66.1%
+-commutative66.1%
Simplified66.2%
Taylor expanded in a around 0 93.7%
+-commutative93.7%
mul-1-neg93.7%
sub-neg93.7%
associate-/l*97.0%
Simplified97.0%
clear-num97.0%
un-div-inv97.0%
Applied egg-rr97.0%
associate-/r/97.0%
Simplified97.0%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.3e-23)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 6.5e-53)
(/ (+ b (sqrt (* c (* a -4.0)))) (* a -2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-23) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 6.5e-53) {
tmp = (b + sqrt((c * (a * -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 <= (-4.3d-23)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 6.5d-53) then
tmp = (b + sqrt((c * (a * (-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 <= -4.3e-23) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 6.5e-53) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.3e-23: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 6.5e-53: tmp = (b + math.sqrt((c * (a * -4.0)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.3e-23) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 6.5e-53) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / 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 <= -4.3e-23) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 6.5e-53) tmp = (b + sqrt((c * (a * -4.0)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-23], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.5e-53], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $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 -4.3 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{-53}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.30000000000000002e-23Initial program 14.7%
div-sub12.9%
sub-neg12.9%
neg-mul-112.9%
*-commutative12.9%
associate-/l*11.6%
distribute-neg-frac11.6%
neg-mul-111.6%
*-commutative11.6%
associate-/l*12.9%
distribute-rgt-out14.7%
associate-/r*14.7%
metadata-eval14.7%
sub-neg14.7%
+-commutative14.7%
Simplified14.3%
associate-*l/14.3%
clear-num14.3%
*-commutative14.3%
pow214.3%
Applied egg-rr14.3%
Taylor expanded in b around -inf 88.7%
associate-*r*88.7%
neg-mul-188.7%
+-commutative88.7%
mul-1-neg88.7%
unsub-neg88.7%
Simplified88.7%
Taylor expanded in c around inf 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
if -4.30000000000000002e-23 < b < 6.4999999999999997e-53Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.5%
distribute-neg-frac74.5%
neg-mul-174.5%
*-commutative74.5%
associate-/l*74.2%
distribute-rgt-out74.2%
associate-/r*74.2%
metadata-eval74.2%
sub-neg74.2%
+-commutative74.2%
Simplified74.2%
Taylor expanded in a around inf 71.2%
associate-*r*71.2%
*-commutative71.2%
*-commutative71.2%
Simplified71.2%
*-commutative71.2%
clear-num71.2%
un-div-inv71.5%
+-commutative71.5%
sqrt-prod38.6%
fma-define38.6%
div-inv38.6%
metadata-eval38.6%
Applied egg-rr38.6%
fma-undefine38.6%
sqrt-unprod71.5%
Applied egg-rr71.5%
if 6.4999999999999997e-53 < b Initial program 73.9%
div-sub73.9%
sub-neg73.9%
neg-mul-173.9%
*-commutative73.9%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.7%
distribute-rgt-out73.7%
associate-/r*73.7%
metadata-eval73.7%
sub-neg73.7%
+-commutative73.7%
Simplified73.8%
Taylor expanded in c around 0 93.8%
+-commutative93.8%
mul-1-neg93.8%
unsub-neg93.8%
Simplified93.8%
Final simplification84.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.6e-24)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 8e-53)
(* (/ -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 <= -1.6e-24) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 8e-53) {
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 <= (-1.6d-24)) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 8d-53) 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 <= -1.6e-24) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 8e-53) {
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 <= -1.6e-24: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 8e-53: 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 <= -1.6e-24) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 8e-53) 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 <= -1.6e-24) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 8e-53) 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, -1.6e-24], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8e-53], 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 -1.6 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-53}:\\
\;\;\;\;\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 < -1.60000000000000006e-24Initial program 14.7%
div-sub12.9%
sub-neg12.9%
neg-mul-112.9%
*-commutative12.9%
associate-/l*11.6%
distribute-neg-frac11.6%
neg-mul-111.6%
*-commutative11.6%
associate-/l*12.9%
distribute-rgt-out14.7%
associate-/r*14.7%
metadata-eval14.7%
sub-neg14.7%
+-commutative14.7%
Simplified14.3%
associate-*l/14.3%
clear-num14.3%
*-commutative14.3%
pow214.3%
Applied egg-rr14.3%
Taylor expanded in b around -inf 88.7%
associate-*r*88.7%
neg-mul-188.7%
+-commutative88.7%
mul-1-neg88.7%
unsub-neg88.7%
Simplified88.7%
Taylor expanded in c around inf 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
if -1.60000000000000006e-24 < b < 8.00000000000000025e-53Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.5%
distribute-neg-frac74.5%
neg-mul-174.5%
*-commutative74.5%
associate-/l*74.2%
distribute-rgt-out74.2%
associate-/r*74.2%
metadata-eval74.2%
sub-neg74.2%
+-commutative74.2%
Simplified74.2%
Taylor expanded in a around inf 71.2%
associate-*r*71.2%
*-commutative71.2%
*-commutative71.2%
Simplified71.2%
if 8.00000000000000025e-53 < b Initial program 73.9%
div-sub73.9%
sub-neg73.9%
neg-mul-173.9%
*-commutative73.9%
associate-/l*73.8%
distribute-neg-frac73.8%
neg-mul-173.8%
*-commutative73.8%
associate-/l*73.7%
distribute-rgt-out73.7%
associate-/r*73.7%
metadata-eval73.7%
sub-neg73.7%
+-commutative73.7%
Simplified73.8%
Taylor expanded in c around 0 93.8%
+-commutative93.8%
mul-1-neg93.8%
unsub-neg93.8%
Simplified93.8%
(FPCore (a b c) :precision binary64 (if (<= b 1.16e-262) (/ 1.0 (- (/ a b) (/ b c))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.16e-262) {
tmp = 1.0 / ((a / b) - (b / c));
} 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.16d-262) then
tmp = 1.0d0 / ((a / b) - (b / c))
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.16e-262) {
tmp = 1.0 / ((a / b) - (b / c));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.16e-262: tmp = 1.0 / ((a / b) - (b / c)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.16e-262) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); 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.16e-262) tmp = 1.0 / ((a / b) - (b / c)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.16e-262], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.16 \cdot 10^{-262}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < 1.16000000000000001e-262Initial program 37.2%
div-sub36.1%
sub-neg36.1%
neg-mul-136.1%
*-commutative36.1%
associate-/l*35.4%
distribute-neg-frac35.4%
neg-mul-135.4%
*-commutative35.4%
associate-/l*36.0%
distribute-rgt-out37.1%
associate-/r*37.1%
metadata-eval37.1%
sub-neg37.1%
+-commutative37.1%
Simplified36.9%
associate-*l/37.0%
clear-num36.9%
*-commutative36.9%
pow236.9%
Applied egg-rr36.9%
Taylor expanded in b around -inf 60.2%
associate-*r*60.2%
neg-mul-160.2%
+-commutative60.2%
mul-1-neg60.2%
unsub-neg60.2%
Simplified60.2%
Taylor expanded in c around inf 61.1%
+-commutative61.1%
mul-1-neg61.1%
unsub-neg61.1%
Simplified61.1%
if 1.16000000000000001e-262 < b Initial program 75.9%
div-sub75.9%
sub-neg75.9%
neg-mul-175.9%
*-commutative75.9%
associate-/l*75.8%
distribute-neg-frac75.8%
neg-mul-175.8%
*-commutative75.8%
associate-/l*75.7%
distribute-rgt-out75.7%
associate-/r*75.7%
metadata-eval75.7%
sub-neg75.7%
+-commutative75.7%
Simplified75.7%
Taylor expanded in c around 0 73.7%
+-commutative73.7%
mul-1-neg73.7%
unsub-neg73.7%
Simplified73.7%
(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 36.8%
div-sub35.7%
sub-neg35.7%
neg-mul-135.7%
*-commutative35.7%
associate-/l*34.9%
distribute-neg-frac34.9%
neg-mul-134.9%
*-commutative34.9%
associate-/l*35.6%
distribute-rgt-out36.7%
associate-/r*36.7%
metadata-eval36.7%
sub-neg36.7%
+-commutative36.7%
Simplified36.4%
Taylor expanded in b around -inf 62.6%
associate-*r/62.6%
neg-mul-162.6%
Simplified62.6%
if -1.999999999999994e-310 < b Initial program 75.1%
div-sub75.1%
sub-neg75.1%
neg-mul-175.1%
*-commutative75.1%
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 c around 0 71.4%
+-commutative71.4%
mul-1-neg71.4%
unsub-neg71.4%
Simplified71.4%
Final simplification66.8%
(FPCore (a b c) :precision binary64 (if (<= b -1.8e-283) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-283) {
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.8d-283)) 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.8e-283) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.8e-283: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-283) 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 <= -1.8e-283) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-283], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-283}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.8e-283Initial program 35.9%
div-sub34.7%
sub-neg34.7%
neg-mul-134.7%
*-commutative34.7%
associate-/l*33.9%
distribute-neg-frac33.9%
neg-mul-133.9%
*-commutative33.9%
associate-/l*34.6%
distribute-rgt-out35.8%
associate-/r*35.8%
metadata-eval35.8%
sub-neg35.8%
+-commutative35.8%
Simplified35.5%
Taylor expanded in b around -inf 63.5%
associate-*r/63.5%
neg-mul-163.5%
Simplified63.5%
if -1.8e-283 < b Initial program 75.5%
div-sub75.5%
sub-neg75.5%
neg-mul-175.5%
*-commutative75.5%
associate-/l*75.4%
distribute-neg-frac75.4%
neg-mul-175.4%
*-commutative75.4%
associate-/l*75.3%
distribute-rgt-out75.3%
associate-/r*75.3%
metadata-eval75.3%
sub-neg75.3%
+-commutative75.3%
Simplified75.3%
Taylor expanded in a around 0 70.1%
associate-*r/70.1%
mul-1-neg70.1%
Simplified70.1%
Final simplification66.7%
(FPCore (a b c) :precision binary64 (if (<= b -1.22e+39) (/ c b) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e+39) {
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.22d+39)) 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.22e+39) {
tmp = c / b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.22e+39: tmp = c / b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.22e+39) 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.22e+39) tmp = c / b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.22e+39], N[(c / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.22 \cdot 10^{+39}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.22e39Initial program 11.8%
div-sub9.8%
sub-neg9.8%
neg-mul-19.8%
*-commutative9.8%
associate-/l*8.4%
distribute-neg-frac8.4%
neg-mul-18.4%
*-commutative8.4%
associate-/l*9.8%
distribute-rgt-out11.8%
associate-/r*11.8%
metadata-eval11.8%
sub-neg11.8%
+-commutative11.8%
Simplified11.3%
Taylor expanded in a around 0 2.1%
+-commutative2.1%
mul-1-neg2.1%
sub-neg2.1%
associate-/l*2.4%
Simplified2.4%
Taylor expanded in a around inf 21.4%
if -1.22e39 < b Initial program 72.1%
div-sub72.0%
sub-neg72.0%
neg-mul-172.0%
*-commutative72.0%
associate-/l*72.0%
distribute-neg-frac72.0%
neg-mul-172.0%
*-commutative72.0%
associate-/l*71.8%
distribute-rgt-out71.9%
associate-/r*71.9%
metadata-eval71.9%
sub-neg71.9%
+-commutative71.9%
Simplified71.9%
Taylor expanded in a around 0 48.2%
associate-*r/48.2%
mul-1-neg48.2%
Simplified48.2%
Final simplification40.5%
(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.9%
div-sub54.3%
sub-neg54.3%
neg-mul-154.3%
*-commutative54.3%
associate-/l*53.9%
distribute-neg-frac53.9%
neg-mul-153.9%
*-commutative53.9%
associate-/l*54.2%
distribute-rgt-out54.7%
associate-/r*54.7%
metadata-eval54.7%
sub-neg54.7%
+-commutative54.7%
Simplified54.6%
Taylor expanded in a around 0 34.0%
+-commutative34.0%
mul-1-neg34.0%
sub-neg34.0%
associate-/l*34.9%
Simplified34.9%
Taylor expanded in a around inf 8.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 54.9%
div-sub54.3%
sub-neg54.3%
neg-mul-154.3%
*-commutative54.3%
associate-/l*53.9%
distribute-neg-frac53.9%
neg-mul-153.9%
*-commutative53.9%
associate-/l*54.2%
distribute-rgt-out54.7%
associate-/r*54.7%
metadata-eval54.7%
sub-neg54.7%
+-commutative54.7%
Simplified54.6%
associate-*l/54.8%
clear-num54.6%
*-commutative54.6%
pow254.6%
Applied egg-rr54.6%
Taylor expanded in b around -inf 33.9%
associate-*r*33.9%
neg-mul-133.9%
+-commutative33.9%
mul-1-neg33.9%
unsub-neg33.9%
Simplified33.9%
Taylor expanded in b around 0 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 2024085
(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)))