
(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
(let* ((t_0 (* a (* c 4.0))))
(if (<= b -2.2e+46)
(- (/ c b) (/ b a))
(if (<= b 1.25e-152)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(if (<= b 2.6e+41)
(* (/ t_0 (+ b (sqrt (- (* b b) t_0)))) (/ -0.5 a))
(/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = a * (c * 4.0);
double tmp;
if (b <= -2.2e+46) {
tmp = (c / b) - (b / a);
} else if (b <= 1.25e-152) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else if (b <= 2.6e+41) {
tmp = (t_0 / (b + sqrt(((b * b) - t_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) :: t_0
real(8) :: tmp
t_0 = a * (c * 4.0d0)
if (b <= (-2.2d+46)) then
tmp = (c / b) - (b / a)
else if (b <= 1.25d-152) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else if (b <= 2.6d+41) then
tmp = (t_0 / (b + sqrt(((b * b) - t_0)))) * ((-0.5d0) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = a * (c * 4.0);
double tmp;
if (b <= -2.2e+46) {
tmp = (c / b) - (b / a);
} else if (b <= 1.25e-152) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else if (b <= 2.6e+41) {
tmp = (t_0 / (b + Math.sqrt(((b * b) - t_0)))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = a * (c * 4.0) tmp = 0 if b <= -2.2e+46: tmp = (c / b) - (b / a) elif b <= 1.25e-152: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) elif b <= 2.6e+41: tmp = (t_0 / (b + math.sqrt(((b * b) - t_0)))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(a * Float64(c * 4.0)) tmp = 0.0 if (b <= -2.2e+46) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.25e-152) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); elseif (b <= 2.6e+41) tmp = Float64(Float64(t_0 / Float64(b + sqrt(Float64(Float64(b * b) - t_0)))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = a * (c * 4.0); tmp = 0.0; if (b <= -2.2e+46) tmp = (c / b) - (b / a); elseif (b <= 1.25e-152) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); elseif (b <= 2.6e+41) tmp = (t_0 / (b + sqrt(((b * b) - t_0)))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.2e+46], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.25e-152], 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], If[LessEqual[b, 2.6e+41], N[(N[(t$95$0 / N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot 4\right)\\
\mathbf{if}\;b \leq -2.2 \cdot 10^{+46}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-152}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+41}:\\
\;\;\;\;\frac{t_0}{b + \sqrt{b \cdot b - t_0}} \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.2e46Initial program 54.1%
neg-sub054.1%
associate-+l-54.1%
sub0-neg54.1%
neg-mul-154.1%
associate-*l/54.0%
*-commutative54.0%
associate-/r*54.0%
/-rgt-identity54.0%
metadata-eval54.0%
Simplified54.2%
Taylor expanded in b around -inf 98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
if -2.2e46 < b < 1.2499999999999999e-152Initial program 78.4%
if 1.2499999999999999e-152 < b < 2.6000000000000001e41Initial program 61.8%
neg-sub061.8%
associate-+l-61.8%
sub0-neg61.8%
neg-mul-161.8%
associate-*l/61.8%
*-commutative61.8%
associate-/r*61.8%
/-rgt-identity61.8%
metadata-eval61.8%
Simplified61.8%
fma-udef61.8%
*-commutative61.8%
associate-*r*61.8%
metadata-eval61.8%
distribute-rgt-neg-in61.8%
*-commutative61.8%
distribute-lft-neg-in61.8%
+-commutative61.8%
sub-neg61.8%
*-commutative61.8%
associate-*l*61.8%
Applied egg-rr61.8%
*-commutative61.8%
Simplified61.8%
flip--61.7%
add-sqr-sqrt61.9%
Applied egg-rr61.9%
associate--r-90.1%
Simplified90.1%
Taylor expanded in b around 0 90.1%
if 2.6000000000000001e41 < b Initial program 10.4%
neg-sub010.4%
associate-+l-10.4%
sub0-neg10.4%
neg-mul-110.4%
associate-*l/10.4%
*-commutative10.4%
associate-/r*10.4%
/-rgt-identity10.4%
metadata-eval10.4%
Simplified10.4%
Taylor expanded in b around inf 95.6%
mul-1-neg95.6%
distribute-neg-frac95.6%
Simplified95.6%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4.4e+35)
(- (/ c b) (/ b a))
(if (<= b 1e-47)
(* (/ -0.5 a) (- b (sqrt (- (* b b) (* a (* c 4.0))))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.4e+35) {
tmp = (c / b) - (b / a);
} else if (b <= 1e-47) {
tmp = (-0.5 / a) * (b - sqrt(((b * b) - (a * (c * 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 <= (-4.4d+35)) then
tmp = (c / b) - (b / a)
else if (b <= 1d-47) then
tmp = ((-0.5d0) / a) * (b - sqrt(((b * b) - (a * (c * 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 <= -4.4e+35) {
tmp = (c / b) - (b / a);
} else if (b <= 1e-47) {
tmp = (-0.5 / a) * (b - Math.sqrt(((b * b) - (a * (c * 4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.4e+35: tmp = (c / b) - (b / a) elif b <= 1e-47: tmp = (-0.5 / a) * (b - math.sqrt(((b * b) - (a * (c * 4.0))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.4e+35) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1e-47) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.4e+35) tmp = (c / b) - (b / a); elseif (b <= 1e-47) tmp = (-0.5 / a) * (b - sqrt(((b * b) - (a * (c * 4.0))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.4e+35], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e-47], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.4 \cdot 10^{+35}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 10^{-47}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.3999999999999997e35Initial program 56.6%
neg-sub056.6%
associate-+l-56.6%
sub0-neg56.6%
neg-mul-156.6%
associate-*l/56.5%
*-commutative56.5%
associate-/r*56.5%
/-rgt-identity56.5%
metadata-eval56.5%
Simplified56.6%
Taylor expanded in b around -inf 98.7%
mul-1-neg98.7%
unsub-neg98.7%
Simplified98.7%
if -4.3999999999999997e35 < b < 9.9999999999999997e-48Initial program 77.6%
neg-sub077.6%
associate-+l-77.6%
sub0-neg77.6%
neg-mul-177.6%
associate-*l/77.4%
*-commutative77.4%
associate-/r*77.4%
/-rgt-identity77.4%
metadata-eval77.4%
Simplified77.4%
fma-udef77.4%
*-commutative77.4%
associate-*r*77.4%
metadata-eval77.4%
distribute-rgt-neg-in77.4%
*-commutative77.4%
distribute-lft-neg-in77.4%
+-commutative77.4%
sub-neg77.4%
*-commutative77.4%
associate-*l*77.4%
Applied egg-rr77.4%
*-commutative77.4%
Simplified77.4%
if 9.9999999999999997e-48 < b Initial program 15.7%
neg-sub015.7%
associate-+l-15.7%
sub0-neg15.7%
neg-mul-115.7%
associate-*l/15.7%
*-commutative15.7%
associate-/r*15.7%
/-rgt-identity15.7%
metadata-eval15.7%
Simplified15.7%
Taylor expanded in b around inf 90.4%
mul-1-neg90.4%
distribute-neg-frac90.4%
Simplified90.4%
Final simplification88.6%
(FPCore (a b c)
:precision binary64
(if (<= b -7e+45)
(- (/ c b) (/ b a))
(if (<= b 9.5e-48)
(/ (- (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 <= -7e+45) {
tmp = (c / b) - (b / a);
} else if (b <= 9.5e-48) {
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 <= (-7d+45)) then
tmp = (c / b) - (b / a)
else if (b <= 9.5d-48) 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 <= -7e+45) {
tmp = (c / b) - (b / a);
} else if (b <= 9.5e-48) {
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 <= -7e+45: tmp = (c / b) - (b / a) elif b <= 9.5e-48: 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 <= -7e+45) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 9.5e-48) 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 <= -7e+45) tmp = (c / b) - (b / a); elseif (b <= 9.5e-48) 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, -7e+45], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9.5e-48], 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 -7 \cdot 10^{+45}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-48}:\\
\;\;\;\;\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 < -7.00000000000000046e45Initial program 54.1%
neg-sub054.1%
associate-+l-54.1%
sub0-neg54.1%
neg-mul-154.1%
associate-*l/54.0%
*-commutative54.0%
associate-/r*54.0%
/-rgt-identity54.0%
metadata-eval54.0%
Simplified54.2%
Taylor expanded in b around -inf 98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
if -7.00000000000000046e45 < b < 9.50000000000000036e-48Initial program 78.6%
if 9.50000000000000036e-48 < b Initial program 15.7%
neg-sub015.7%
associate-+l-15.7%
sub0-neg15.7%
neg-mul-115.7%
associate-*l/15.7%
*-commutative15.7%
associate-/r*15.7%
/-rgt-identity15.7%
metadata-eval15.7%
Simplified15.7%
Taylor expanded in b around inf 90.4%
mul-1-neg90.4%
distribute-neg-frac90.4%
Simplified90.4%
Final simplification88.7%
(FPCore (a b c)
:precision binary64
(if (<= b -5.5e-137)
(- (/ c b) (/ b a))
(if (<= b 1.25e-47)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.5e-137) {
tmp = (c / b) - (b / a);
} else if (b <= 1.25e-47) {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -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 <= (-5.5d-137)) then
tmp = (c / b) - (b / a)
else if (b <= 1.25d-47) then
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-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 <= -5.5e-137) {
tmp = (c / b) - (b / a);
} else if (b <= 1.25e-47) {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.5e-137: tmp = (c / b) - (b / a) elif b <= 1.25e-47: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.5e-137) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.25e-47) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.5e-137) tmp = (c / b) - (b / a); elseif (b <= 1.25e-47) tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.5e-137], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.25e-47], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.5 \cdot 10^{-137}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-47}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.5000000000000003e-137Initial program 65.9%
neg-sub065.9%
associate-+l-65.9%
sub0-neg65.9%
neg-mul-165.9%
associate-*l/65.8%
*-commutative65.8%
associate-/r*65.8%
/-rgt-identity65.8%
metadata-eval65.8%
Simplified65.9%
Taylor expanded in b around -inf 89.5%
mul-1-neg89.5%
unsub-neg89.5%
Simplified89.5%
if -5.5000000000000003e-137 < b < 1.25000000000000003e-47Initial program 71.1%
neg-sub071.1%
associate-+l-71.1%
sub0-neg71.1%
neg-mul-171.1%
associate-*l/71.0%
*-commutative71.0%
associate-/r*71.0%
/-rgt-identity71.0%
metadata-eval71.0%
Simplified71.0%
Taylor expanded in a around inf 67.0%
*-commutative67.0%
*-commutative67.0%
associate-*r*67.0%
Simplified67.0%
if 1.25000000000000003e-47 < b Initial program 15.7%
neg-sub015.7%
associate-+l-15.7%
sub0-neg15.7%
neg-mul-115.7%
associate-*l/15.7%
*-commutative15.7%
associate-/r*15.7%
/-rgt-identity15.7%
metadata-eval15.7%
Simplified15.7%
Taylor expanded in b around inf 90.4%
mul-1-neg90.4%
distribute-neg-frac90.4%
Simplified90.4%
Final simplification85.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-137)
(- (/ c b) (/ b a))
(if (<= b 9.2e-48)
(/ (* -0.5 (- b (sqrt (* a (* c -4.0))))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-137) {
tmp = (c / b) - (b / a);
} else if (b <= 9.2e-48) {
tmp = (-0.5 * (b - sqrt((a * (c * -4.0))))) / 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 <= (-4.6d-137)) then
tmp = (c / b) - (b / a)
else if (b <= 9.2d-48) then
tmp = ((-0.5d0) * (b - sqrt((a * (c * (-4.0d0)))))) / 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 <= -4.6e-137) {
tmp = (c / b) - (b / a);
} else if (b <= 9.2e-48) {
tmp = (-0.5 * (b - Math.sqrt((a * (c * -4.0))))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-137: tmp = (c / b) - (b / a) elif b <= 9.2e-48: tmp = (-0.5 * (b - math.sqrt((a * (c * -4.0))))) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-137) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 9.2e-48) tmp = Float64(Float64(-0.5 * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e-137) tmp = (c / b) - (b / a); elseif (b <= 9.2e-48) tmp = (-0.5 * (b - sqrt((a * (c * -4.0))))) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-137], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9.2e-48], N[(N[(-0.5 * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{-137}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-48}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.60000000000000016e-137Initial program 65.9%
neg-sub065.9%
associate-+l-65.9%
sub0-neg65.9%
neg-mul-165.9%
associate-*l/65.8%
*-commutative65.8%
associate-/r*65.8%
/-rgt-identity65.8%
metadata-eval65.8%
Simplified65.9%
Taylor expanded in b around -inf 89.5%
mul-1-neg89.5%
unsub-neg89.5%
Simplified89.5%
if -4.60000000000000016e-137 < b < 9.2000000000000003e-48Initial program 71.1%
neg-sub071.1%
associate-+l-71.1%
sub0-neg71.1%
neg-mul-171.1%
associate-*l/71.0%
*-commutative71.0%
associate-/r*71.0%
/-rgt-identity71.0%
metadata-eval71.0%
Simplified71.0%
Taylor expanded in a around inf 67.0%
*-commutative67.0%
*-commutative67.0%
associate-*r*67.0%
Simplified67.0%
associate-*r/67.2%
Applied egg-rr67.2%
if 9.2000000000000003e-48 < b Initial program 15.7%
neg-sub015.7%
associate-+l-15.7%
sub0-neg15.7%
neg-mul-115.7%
associate-*l/15.7%
*-commutative15.7%
associate-/r*15.7%
/-rgt-identity15.7%
metadata-eval15.7%
Simplified15.7%
Taylor expanded in b around inf 90.4%
mul-1-neg90.4%
distribute-neg-frac90.4%
Simplified90.4%
Final simplification85.4%
(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 66.5%
neg-sub066.5%
associate-+l-66.5%
sub0-neg66.5%
neg-mul-166.5%
associate-*l/66.3%
*-commutative66.3%
associate-/r*66.3%
/-rgt-identity66.3%
metadata-eval66.3%
Simplified66.4%
Taylor expanded in b around -inf 80.2%
mul-1-neg80.2%
unsub-neg80.2%
Simplified80.2%
if -4.999999999999985e-310 < b Initial program 30.1%
neg-sub030.1%
associate-+l-30.1%
sub0-neg30.1%
neg-mul-130.1%
associate-*l/30.1%
*-commutative30.1%
associate-/r*30.1%
/-rgt-identity30.1%
metadata-eval30.1%
Simplified30.1%
Taylor expanded in b around inf 72.7%
mul-1-neg72.7%
distribute-neg-frac72.7%
Simplified72.7%
Final simplification76.4%
(FPCore (a b c) :precision binary64 (if (<= b 0.0023) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.0023) {
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 <= 0.0023d0) 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 <= 0.0023) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 0.0023: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 0.0023) 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 <= 0.0023) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 0.0023], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.0023:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 0.0023Initial program 65.8%
neg-sub065.8%
associate-+l-65.8%
sub0-neg65.8%
neg-mul-165.8%
associate-*l/65.6%
*-commutative65.6%
associate-/r*65.6%
/-rgt-identity65.6%
metadata-eval65.6%
Simplified65.7%
Taylor expanded in b around -inf 60.5%
associate-*r/60.5%
mul-1-neg60.5%
Simplified60.5%
if 0.0023 < b Initial program 15.1%
neg-sub015.1%
associate-+l-15.1%
sub0-neg15.1%
neg-mul-115.1%
associate-*l/15.1%
*-commutative15.1%
associate-/r*15.1%
/-rgt-identity15.1%
metadata-eval15.1%
Simplified15.1%
Taylor expanded in b around -inf 2.3%
mul-1-neg2.3%
unsub-neg2.3%
Simplified2.3%
Taylor expanded in c around inf 29.8%
Final simplification49.6%
(FPCore (a b c) :precision binary64 (if (<= b 5.8e-303) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.8e-303) {
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 <= 5.8d-303) 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 <= 5.8e-303) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.8e-303: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.8e-303) 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 <= 5.8e-303) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.8e-303], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.8 \cdot 10^{-303}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 5.80000000000000028e-303Initial program 66.7%
neg-sub066.7%
associate-+l-66.7%
sub0-neg66.7%
neg-mul-166.7%
associate-*l/66.6%
*-commutative66.6%
associate-/r*66.6%
/-rgt-identity66.6%
metadata-eval66.6%
Simplified66.7%
Taylor expanded in b around -inf 78.8%
associate-*r/78.8%
mul-1-neg78.8%
Simplified78.8%
if 5.80000000000000028e-303 < b Initial program 29.6%
neg-sub029.6%
associate-+l-29.6%
sub0-neg29.6%
neg-mul-129.6%
associate-*l/29.6%
*-commutative29.6%
associate-/r*29.6%
/-rgt-identity29.6%
metadata-eval29.6%
Simplified29.6%
Taylor expanded in b around inf 73.3%
mul-1-neg73.3%
distribute-neg-frac73.3%
Simplified73.3%
Final simplification76.0%
(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 47.7%
neg-sub047.7%
associate-+l-47.7%
sub0-neg47.7%
neg-mul-147.7%
associate-*l/47.7%
*-commutative47.7%
associate-/r*47.7%
/-rgt-identity47.7%
metadata-eval47.7%
Simplified47.7%
associate-*r/47.8%
clear-num47.7%
Applied egg-rr47.7%
Taylor expanded in a around 0 38.4%
mul-1-neg38.4%
unsub-neg38.4%
Simplified38.4%
Taylor expanded in a around inf 2.5%
Final simplification2.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 47.7%
neg-sub047.7%
associate-+l-47.7%
sub0-neg47.7%
neg-mul-147.7%
associate-*l/47.7%
*-commutative47.7%
associate-/r*47.7%
/-rgt-identity47.7%
metadata-eval47.7%
Simplified47.7%
Taylor expanded in b around -inf 40.1%
mul-1-neg40.1%
unsub-neg40.1%
Simplified40.1%
Taylor expanded in c around inf 12.5%
Final simplification12.5%
herbie shell --seed 2023238
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))