
(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 10 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 -4.6e+59)
(/ b (- a))
(if (<= b 8.4e-35)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e+59) {
tmp = b / -a;
} else if (b <= 8.4e-35) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - 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 <= (-4.6d+59)) then
tmp = b / -a
else if (b <= 8.4d-35) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - 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 <= -4.6e+59) {
tmp = b / -a;
} else if (b <= 8.4e-35) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e+59: tmp = b / -a elif b <= 8.4e-35: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e+59) tmp = Float64(b / Float64(-a)); elseif (b <= 8.4e-35) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e+59) tmp = b / -a; elseif (b <= 8.4e-35) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e+59], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 8.4e-35], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $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.6 \cdot 10^{+59}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{-35}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.60000000000000016e59Initial program 66.0%
*-commutative66.0%
Simplified66.0%
Taylor expanded in b around -inf 93.6%
associate-*r/93.6%
mul-1-neg93.6%
Simplified93.6%
if -4.60000000000000016e59 < b < 8.3999999999999999e-35Initial program 82.9%
if 8.3999999999999999e-35 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 87.2%
associate-*r/87.2%
mul-1-neg87.2%
Simplified87.2%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-78)
(/ b (- a))
(if (<= b 7e-40)
(- (/ (sqrt (* a (* c -4.0))) (* a 2.0)) (/ (/ b a) 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-78) {
tmp = b / -a;
} else if (b <= 7e-40) {
tmp = (sqrt((a * (c * -4.0))) / (a * 2.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 <= (-2.9d-78)) then
tmp = b / -a
else if (b <= 7d-40) then
tmp = (sqrt((a * (c * (-4.0d0)))) / (a * 2.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 <= -2.9e-78) {
tmp = b / -a;
} else if (b <= 7e-40) {
tmp = (Math.sqrt((a * (c * -4.0))) / (a * 2.0)) - ((b / a) / 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-78: tmp = b / -a elif b <= 7e-40: tmp = (math.sqrt((a * (c * -4.0))) / (a * 2.0)) - ((b / a) / 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-78) tmp = Float64(b / Float64(-a)); elseif (b <= 7e-40) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * 2.0)) - Float64(Float64(b / a) / 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e-78) tmp = b / -a; elseif (b <= 7e-40) tmp = (sqrt((a * (c * -4.0))) / (a * 2.0)) - ((b / a) / 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-78], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 7e-40], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision] - N[(N[(b / a), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-40}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2} - \frac{\frac{b}{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.9000000000000001e-78Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
if -2.9000000000000001e-78 < b < 7.0000000000000003e-40Initial program 79.8%
*-commutative79.8%
Simplified79.8%
Taylor expanded in a around inf 78.7%
associate-*r*78.7%
*-commutative78.7%
Simplified78.7%
div-sub78.7%
associate-*l*78.7%
Applied egg-rr78.7%
*-commutative78.7%
associate-/r*78.7%
Simplified78.7%
if 7.0000000000000003e-40 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 87.2%
associate-*r/87.2%
mul-1-neg87.2%
Simplified87.2%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.45e-78)
(/ b (- a))
(if (<= b 1.32e-37)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-78) {
tmp = b / -a;
} else if (b <= 1.32e-37) {
tmp = (sqrt((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 <= (-1.45d-78)) then
tmp = b / -a
else if (b <= 1.32d-37) then
tmp = (sqrt((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 <= -1.45e-78) {
tmp = b / -a;
} else if (b <= 1.32e-37) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-78: tmp = b / -a elif b <= 1.32e-37: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-78) tmp = Float64(b / Float64(-a)); elseif (b <= 1.32e-37) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.45e-78) tmp = b / -a; elseif (b <= 1.32e-37) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-78], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.32e-37], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $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 -1.45 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-37}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.45e-78Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
if -1.45e-78 < b < 1.3200000000000001e-37Initial program 79.8%
*-commutative79.8%
Simplified79.8%
Taylor expanded in a around inf 78.7%
associate-*r*78.7%
*-commutative78.7%
Simplified78.7%
if 1.3200000000000001e-37 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 87.2%
associate-*r/87.2%
mul-1-neg87.2%
Simplified87.2%
Final simplification84.9%
(FPCore (a b c) :precision binary64 (if (<= b -4.3e-78) (/ b (- a)) (if (<= b 5e-37) (/ (sqrt (* a (* c -4.0))) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-78) {
tmp = b / -a;
} else if (b <= 5e-37) {
tmp = sqrt((a * (c * -4.0))) / (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 <= (-4.3d-78)) then
tmp = b / -a
else if (b <= 5d-37) then
tmp = sqrt((a * (c * (-4.0d0)))) / (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 <= -4.3e-78) {
tmp = b / -a;
} else if (b <= 5e-37) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.3e-78: tmp = b / -a elif b <= 5e-37: tmp = math.sqrt((a * (c * -4.0))) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.3e-78) tmp = Float64(b / Float64(-a)); elseif (b <= 5e-37) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.3e-78) tmp = b / -a; elseif (b <= 5e-37) tmp = sqrt((a * (c * -4.0))) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-78], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 5e-37], N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.3 \cdot 10^{-78}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-37}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.29999999999999994e-78Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
if -4.29999999999999994e-78 < b < 4.9999999999999997e-37Initial program 79.8%
*-commutative79.8%
Simplified79.8%
add-cube-cbrt79.1%
pow379.1%
Applied egg-rr79.1%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt77.1%
rem-cube-cbrt77.7%
*-commutative77.7%
distribute-lft-neg-in77.7%
metadata-eval77.7%
*-lft-identity77.7%
*-commutative77.7%
Simplified77.7%
if 4.9999999999999997e-37 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 87.2%
associate-*r/87.2%
mul-1-neg87.2%
Simplified87.2%
Final simplification84.6%
(FPCore (a b c) :precision binary64 (if (<= b -1.45e-80) (/ b (- a)) (if (<= b 9.2e-40) (* (sqrt (* c (* a -4.0))) (/ 0.5 a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-80) {
tmp = b / -a;
} else if (b <= 9.2e-40) {
tmp = sqrt((c * (a * -4.0))) * (0.5 / 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.45d-80)) then
tmp = b / -a
else if (b <= 9.2d-40) then
tmp = sqrt((c * (a * (-4.0d0)))) * (0.5d0 / 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.45e-80) {
tmp = b / -a;
} else if (b <= 9.2e-40) {
tmp = Math.sqrt((c * (a * -4.0))) * (0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-80: tmp = b / -a elif b <= 9.2e-40: tmp = math.sqrt((c * (a * -4.0))) * (0.5 / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-80) tmp = Float64(b / Float64(-a)); elseif (b <= 9.2e-40) tmp = Float64(sqrt(Float64(c * Float64(a * -4.0))) * Float64(0.5 / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.45e-80) tmp = b / -a; elseif (b <= 9.2e-40) tmp = sqrt((c * (a * -4.0))) * (0.5 / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-80], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 9.2e-40], N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-80}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-40}:\\
\;\;\;\;\sqrt{c \cdot \left(a \cdot -4\right)} \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.44999999999999999e-80Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
if -1.44999999999999999e-80 < b < 9.2e-40Initial program 79.8%
*-commutative79.8%
Simplified79.8%
add-cube-cbrt79.1%
pow379.1%
Applied egg-rr79.1%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt77.1%
rem-cube-cbrt77.7%
*-commutative77.7%
distribute-lft-neg-in77.7%
metadata-eval77.7%
*-lft-identity77.7%
*-commutative77.7%
Simplified77.7%
clear-num77.5%
associate-/r/77.5%
*-commutative77.5%
associate-/r*77.5%
metadata-eval77.5%
*-commutative77.5%
associate-*l*77.5%
Applied egg-rr77.5%
if 9.2e-40 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 87.2%
associate-*r/87.2%
mul-1-neg87.2%
Simplified87.2%
Final simplification84.5%
(FPCore (a b c) :precision binary64 (if (<= b -2.6e-118) (/ b (- a)) (if (<= b 6.2e-40) (sqrt (/ (/ (* c -4.0) a) 4.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-118) {
tmp = b / -a;
} else if (b <= 6.2e-40) {
tmp = sqrt((((c * -4.0) / a) / 4.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 <= (-2.6d-118)) then
tmp = b / -a
else if (b <= 6.2d-40) then
tmp = sqrt((((c * (-4.0d0)) / a) / 4.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 <= -2.6e-118) {
tmp = b / -a;
} else if (b <= 6.2e-40) {
tmp = Math.sqrt((((c * -4.0) / a) / 4.0));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.6e-118: tmp = b / -a elif b <= 6.2e-40: tmp = math.sqrt((((c * -4.0) / a) / 4.0)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.6e-118) tmp = Float64(b / Float64(-a)); elseif (b <= 6.2e-40) tmp = sqrt(Float64(Float64(Float64(c * -4.0) / a) / 4.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.6e-118) tmp = b / -a; elseif (b <= 6.2e-40) tmp = sqrt((((c * -4.0) / a) / 4.0)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.6e-118], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 6.2e-40], N[Sqrt[N[(N[(N[(c * -4.0), $MachinePrecision] / a), $MachinePrecision] / 4.0), $MachinePrecision]], $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{-118}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-40}:\\
\;\;\;\;\sqrt{\frac{\frac{c \cdot -4}{a}}{4}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.6e-118Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 83.5%
associate-*r/83.5%
mul-1-neg83.5%
Simplified83.5%
if -2.6e-118 < b < 6.20000000000000021e-40Initial program 80.0%
*-commutative80.0%
Simplified80.0%
add-cube-cbrt79.3%
pow379.3%
Applied egg-rr79.3%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt77.2%
rem-cube-cbrt77.8%
*-commutative77.8%
distribute-lft-neg-in77.8%
metadata-eval77.8%
*-lft-identity77.8%
*-commutative77.8%
Simplified77.8%
add-sqr-sqrt35.6%
sqrt-unprod27.8%
frac-times24.4%
add-sqr-sqrt24.4%
*-commutative24.4%
associate-*l*24.4%
swap-sqr24.4%
pow224.4%
metadata-eval24.4%
Applied egg-rr24.4%
associate-/r*24.4%
associate-*r*24.4%
unpow224.4%
times-frac32.5%
*-inverses32.5%
Simplified32.5%
if 6.20000000000000021e-40 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 87.2%
associate-*r/87.2%
mul-1-neg87.2%
Simplified87.2%
Final simplification72.5%
(FPCore (a b c) :precision binary64 (if (<= b 6.5e-301) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.5e-301) {
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 <= 6.5d-301) 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 <= 6.5e-301) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6.5e-301: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6.5e-301) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 6.5e-301) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6.5e-301], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.5 \cdot 10^{-301}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 6.49999999999999991e-301Initial program 77.2%
*-commutative77.2%
Simplified77.2%
Taylor expanded in b around -inf 67.9%
associate-*r/67.9%
mul-1-neg67.9%
Simplified67.9%
if 6.49999999999999991e-301 < b Initial program 32.7%
*-commutative32.7%
Simplified32.7%
Taylor expanded in a around 0 67.4%
associate-*r/67.4%
mul-1-neg67.4%
Simplified67.4%
Final simplification67.6%
(FPCore (a b c) :precision binary64 (if (<= b 1000.0) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1000.0) {
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 <= 1000.0d0) 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 <= 1000.0) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1000.0: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1000.0) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1000.0) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1000.0], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1000:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1e3Initial program 73.0%
*-commutative73.0%
Simplified73.0%
Taylor expanded in b around -inf 49.5%
associate-*r/49.5%
mul-1-neg49.5%
Simplified49.5%
if 1e3 < b Initial program 14.9%
*-commutative14.9%
Simplified14.9%
add-cbrt-cube9.9%
pow39.9%
Applied egg-rr9.9%
rem-cbrt-cube14.9%
div-inv14.9%
add-sqr-sqrt0.0%
sqrt-unprod8.8%
sqr-neg8.8%
sqrt-prod8.8%
add-sqr-sqrt8.8%
pow28.8%
*-commutative8.8%
*-commutative8.8%
Applied egg-rr8.8%
*-commutative8.8%
Simplified8.8%
Taylor expanded in b around -inf 24.9%
Final simplification41.7%
(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.4%
*-commutative54.4%
Simplified54.4%
add-cbrt-cube29.1%
pow329.1%
Applied egg-rr29.1%
rem-cbrt-cube54.4%
div-inv54.3%
add-sqr-sqrt37.1%
sqrt-unprod51.8%
sqr-neg51.8%
sqrt-prod14.7%
add-sqr-sqrt32.2%
pow232.2%
*-commutative32.2%
*-commutative32.2%
Applied egg-rr32.2%
*-commutative32.2%
Simplified32.2%
Taylor expanded in b around -inf 10.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.4%
*-commutative54.4%
Simplified54.4%
Taylor expanded in b around -inf 34.5%
associate-*r/34.5%
mul-1-neg34.5%
Simplified34.5%
div-inv34.4%
add-sqr-sqrt32.8%
sqrt-unprod27.7%
sqr-neg27.7%
sqrt-prod1.9%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
associate-*r/2.6%
*-rgt-identity2.6%
Simplified2.6%
herbie shell --seed 2024136
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))