
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -4e+113)
(- (/ c b) (/ b a))
(if (<= b 9e-12)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+113) {
tmp = (c / b) - (b / a);
} else if (b <= 9e-12) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
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+113)) then
tmp = (c / b) - (b / a)
else if (b <= 9d-12) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e+113) {
tmp = (c / b) - (b / a);
} else if (b <= 9e-12) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e+113: tmp = (c / b) - (b / a) elif b <= 9e-12: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e+113) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 9e-12) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e+113) tmp = (c / b) - (b / a); elseif (b <= 9e-12) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e+113], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9e-12], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+113}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 9 \cdot 10^{-12}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4e113Initial program 52.6%
*-commutative52.6%
Simplified52.6%
Taylor expanded in b around -inf 90.7%
+-commutative90.7%
mul-1-neg90.7%
unsub-neg90.7%
Simplified90.7%
if -4e113 < b < 8.99999999999999962e-12Initial program 86.9%
if 8.99999999999999962e-12 < b Initial program 14.6%
*-commutative14.6%
Simplified14.6%
Taylor expanded in b around inf 90.9%
mul-1-neg90.9%
distribute-neg-frac90.9%
Simplified90.9%
Final simplification88.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b) (/ b a)))
(t_1 (* (/ 0.5 a) (+ b (sqrt (* c (* a -4.0)))))))
(if (<= b -1.4e-17)
t_0
(if (<= b -5e-66)
t_1
(if (<= b -4.5e-133) t_0 (if (<= b 1.55e-11) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (0.5 / a) * (b + sqrt((c * (a * -4.0))));
double tmp;
if (b <= -1.4e-17) {
tmp = t_0;
} else if (b <= -5e-66) {
tmp = t_1;
} else if (b <= -4.5e-133) {
tmp = t_0;
} else if (b <= 1.55e-11) {
tmp = t_1;
} else {
tmp = -c / b;
}
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) :: t_1
real(8) :: tmp
t_0 = (c / b) - (b / a)
t_1 = (0.5d0 / a) * (b + sqrt((c * (a * (-4.0d0)))))
if (b <= (-1.4d-17)) then
tmp = t_0
else if (b <= (-5d-66)) then
tmp = t_1
else if (b <= (-4.5d-133)) then
tmp = t_0
else if (b <= 1.55d-11) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
double tmp;
if (b <= -1.4e-17) {
tmp = t_0;
} else if (b <= -5e-66) {
tmp = t_1;
} else if (b <= -4.5e-133) {
tmp = t_0;
} else if (b <= 1.55e-11) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = (c / b) - (b / a) t_1 = (0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) tmp = 0 if b <= -1.4e-17: tmp = t_0 elif b <= -5e-66: tmp = t_1 elif b <= -4.5e-133: tmp = t_0 elif b <= 1.55e-11: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(c / b) - Float64(b / a)) t_1 = Float64(Float64(0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))) tmp = 0.0 if (b <= -1.4e-17) tmp = t_0; elseif (b <= -5e-66) tmp = t_1; elseif (b <= -4.5e-133) tmp = t_0; elseif (b <= 1.55e-11) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c / b) - (b / a); t_1 = (0.5 / a) * (b + sqrt((c * (a * -4.0)))); tmp = 0.0; if (b <= -1.4e-17) tmp = t_0; elseif (b <= -5e-66) tmp = t_1; elseif (b <= -4.5e-133) tmp = t_0; elseif (b <= 1.55e-11) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.4e-17], t$95$0, If[LessEqual[b, -5e-66], t$95$1, If[LessEqual[b, -4.5e-133], t$95$0, If[LessEqual[b, 1.55e-11], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := \frac{0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{if}\;b \leq -1.4 \cdot 10^{-17}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -5 \cdot 10^{-66}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -4.5 \cdot 10^{-133}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-11}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.3999999999999999e-17 or -4.99999999999999962e-66 < b < -4.50000000000000009e-133Initial program 73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in b around -inf 86.1%
+-commutative86.1%
mul-1-neg86.1%
unsub-neg86.1%
Simplified86.1%
if -1.3999999999999999e-17 < b < -4.99999999999999962e-66 or -4.50000000000000009e-133 < b < 1.55000000000000014e-11Initial program 81.6%
*-commutative81.6%
Simplified81.6%
add-sqr-sqrt34.3%
pow234.3%
Applied egg-rr33.0%
Taylor expanded in b around 0 32.9%
unpow232.9%
add-sqr-sqrt77.7%
*-commutative77.7%
*-commutative77.7%
*-commutative77.7%
associate-*r*77.7%
Applied egg-rr77.7%
if 1.55000000000000014e-11 < b Initial program 14.6%
*-commutative14.6%
Simplified14.6%
Taylor expanded in b around inf 90.9%
mul-1-neg90.9%
distribute-neg-frac90.9%
Simplified90.9%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b) (/ b a)))
(t_1 (/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))))
(if (<= b -6.6e-15)
t_0
(if (<= b -2.5e-66)
t_1
(if (<= b -4.5e-133) t_0 (if (<= b 3e-12) t_1 (/ (- c) b)))))))
double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -6.6e-15) {
tmp = t_0;
} else if (b <= -2.5e-66) {
tmp = t_1;
} else if (b <= -4.5e-133) {
tmp = t_0;
} else if (b <= 3e-12) {
tmp = t_1;
} else {
tmp = -c / b;
}
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) :: t_1
real(8) :: tmp
t_0 = (c / b) - (b / a)
t_1 = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
if (b <= (-6.6d-15)) then
tmp = t_0
else if (b <= (-2.5d-66)) then
tmp = t_1
else if (b <= (-4.5d-133)) then
tmp = t_0
else if (b <= 3d-12) then
tmp = t_1
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -6.6e-15) {
tmp = t_0;
} else if (b <= -2.5e-66) {
tmp = t_1;
} else if (b <= -4.5e-133) {
tmp = t_0;
} else if (b <= 3e-12) {
tmp = t_1;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = (c / b) - (b / a) t_1 = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) tmp = 0 if b <= -6.6e-15: tmp = t_0 elif b <= -2.5e-66: tmp = t_1 elif b <= -4.5e-133: tmp = t_0 elif b <= 3e-12: tmp = t_1 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(c / b) - Float64(b / a)) t_1 = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -6.6e-15) tmp = t_0; elseif (b <= -2.5e-66) tmp = t_1; elseif (b <= -4.5e-133) tmp = t_0; elseif (b <= 3e-12) tmp = t_1; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c / b) - (b / a); t_1 = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); tmp = 0.0; if (b <= -6.6e-15) tmp = t_0; elseif (b <= -2.5e-66) tmp = t_1; elseif (b <= -4.5e-133) tmp = t_0; elseif (b <= 3e-12) tmp = t_1; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -6.6e-15], t$95$0, If[LessEqual[b, -2.5e-66], t$95$1, If[LessEqual[b, -4.5e-133], t$95$0, If[LessEqual[b, 3e-12], t$95$1, N[((-c) / b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := \frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -6.6 \cdot 10^{-15}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -2.5 \cdot 10^{-66}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -4.5 \cdot 10^{-133}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 3 \cdot 10^{-12}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -6.6e-15 or -2.49999999999999981e-66 < b < -4.50000000000000009e-133Initial program 73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in b around -inf 86.1%
+-commutative86.1%
mul-1-neg86.1%
unsub-neg86.1%
Simplified86.1%
if -6.6e-15 < b < -2.49999999999999981e-66 or -4.50000000000000009e-133 < b < 3.0000000000000001e-12Initial program 81.6%
*-commutative81.6%
Simplified81.6%
Taylor expanded in b around 0 78.8%
*-commutative78.8%
*-commutative78.8%
associate-*r*78.8%
Simplified78.8%
if 3.0000000000000001e-12 < b Initial program 14.6%
*-commutative14.6%
Simplified14.6%
Taylor expanded in b around inf 90.9%
mul-1-neg90.9%
distribute-neg-frac90.9%
Simplified90.9%
Final simplification85.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
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 <= (-5d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 77.4%
*-commutative77.4%
Simplified77.4%
Taylor expanded in b around -inf 69.3%
+-commutative69.3%
mul-1-neg69.3%
unsub-neg69.3%
Simplified69.3%
if -4.999999999999985e-310 < b Initial program 39.8%
*-commutative39.8%
Simplified39.8%
Taylor expanded in b around inf 60.9%
mul-1-neg60.9%
distribute-neg-frac60.9%
Simplified60.9%
Final simplification65.6%
(FPCore (a b c) :precision binary64 (if (<= b 1.38e-11) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.38e-11) {
tmp = -b / a;
} else {
tmp = c / b;
}
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.38d-11) then
tmp = -b / a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.38e-11) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.38e-11: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.38e-11) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.38e-11) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.38e-11], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.38 \cdot 10^{-11}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.38e-11Initial program 76.8%
*-commutative76.8%
Simplified76.8%
Taylor expanded in b around -inf 52.8%
associate-*r/52.8%
mul-1-neg52.8%
Simplified52.8%
if 1.38e-11 < b Initial program 14.6%
*-commutative14.6%
Simplified14.6%
Taylor expanded in b around inf 68.6%
associate-*r/68.6%
associate-*r*68.6%
*-commutative68.6%
Simplified68.6%
div-inv68.5%
*-commutative68.5%
times-frac69.2%
associate-*l*69.2%
Applied egg-rr69.2%
associate-/l*69.3%
*-commutative69.3%
associate-/l/68.5%
Simplified68.5%
frac-2neg68.5%
frac-2neg68.5%
metadata-eval68.5%
frac-times71.6%
frac-2neg71.6%
metadata-eval71.6%
distribute-neg-frac71.6%
metadata-eval71.6%
distribute-rgt-neg-in71.6%
metadata-eval71.6%
distribute-rgt-neg-in71.6%
add-sqr-sqrt0.0%
sqrt-unprod26.2%
sqr-neg26.2%
sqrt-unprod26.0%
add-sqr-sqrt26.0%
*-commutative26.0%
Applied egg-rr26.0%
*-commutative26.0%
mul-1-neg26.0%
*-commutative26.0%
associate-*l*25.8%
Simplified25.8%
Taylor expanded in a around 0 25.6%
Final simplification45.8%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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 <= (-5d-310)) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 77.4%
*-commutative77.4%
Simplified77.4%
Taylor expanded in b around -inf 69.2%
associate-*r/69.2%
mul-1-neg69.2%
Simplified69.2%
if -4.999999999999985e-310 < b Initial program 39.8%
*-commutative39.8%
Simplified39.8%
Taylor expanded in b around inf 60.9%
mul-1-neg60.9%
distribute-neg-frac60.9%
Simplified60.9%
Final simplification65.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 60.8%
*-commutative60.8%
Simplified60.8%
Taylor expanded in b around inf 21.3%
associate-*r/21.3%
associate-*r*21.3%
*-commutative21.3%
Simplified21.3%
div-inv21.2%
*-commutative21.2%
times-frac21.3%
associate-*l*21.3%
Applied egg-rr21.3%
associate-/l*21.3%
*-commutative21.3%
associate-/l/21.1%
Simplified21.1%
frac-2neg21.1%
frac-2neg21.1%
metadata-eval21.1%
frac-times23.5%
frac-2neg23.5%
metadata-eval23.5%
distribute-neg-frac23.5%
metadata-eval23.5%
distribute-rgt-neg-in23.5%
metadata-eval23.5%
distribute-rgt-neg-in23.5%
add-sqr-sqrt1.7%
sqrt-unprod8.6%
sqr-neg8.6%
sqrt-unprod7.0%
add-sqr-sqrt9.5%
*-commutative9.5%
Applied egg-rr9.5%
*-commutative9.5%
mul-1-neg9.5%
*-commutative9.5%
associate-*l*10.8%
Simplified10.8%
Taylor expanded in a around 0 8.8%
Final simplification8.8%
herbie shell --seed 2023305
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))