
(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 12 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 -5.5e+119)
(- (/ c b) (/ b a))
(if (<= b -3.5e-286)
(/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0))
(if (<= b 2.6e+117)
(/ (* c -2.0) (+ b (sqrt (fma a (* c -4.0) (pow b 2.0)))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.5e+119) {
tmp = (c / b) - (b / a);
} else if (b <= -3.5e-286) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else if (b <= 2.6e+117) {
tmp = (c * -2.0) / (b + sqrt(fma(a, (c * -4.0), pow(b, 2.0))));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5.5e+119) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -3.5e-286) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); elseif (b <= 2.6e+117) tmp = Float64(Float64(c * -2.0) / Float64(b + sqrt(fma(a, Float64(c * -4.0), (b ^ 2.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5.5e+119], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -3.5e-286], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.6e+117], N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.5 \cdot 10^{+119}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -3.5 \cdot 10^{-286}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+117}:\\
\;\;\;\;\frac{c \cdot -2}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.5000000000000003e119Initial program 43.9%
*-commutative43.9%
Simplified43.9%
Taylor expanded in b around -inf 98.1%
+-commutative98.1%
mul-1-neg98.1%
unsub-neg98.1%
Simplified98.1%
if -5.5000000000000003e119 < b < -3.49999999999999988e-286Initial program 89.1%
Simplified89.1%
if -3.49999999999999988e-286 < b < 2.5999999999999999e117Initial program 45.9%
*-commutative45.9%
Simplified45.9%
+-commutative45.9%
unsub-neg45.9%
*-un-lft-identity45.9%
*-un-lft-identity45.9%
cancel-sign-sub-inv45.9%
+-commutative45.9%
*-commutative45.9%
distribute-rgt-neg-in45.9%
metadata-eval45.9%
associate-*r*45.9%
*-commutative45.9%
fma-udef45.9%
div-sub45.7%
sub-neg45.7%
Applied egg-rr45.6%
sub-neg45.6%
distribute-rgt-out--45.8%
Simplified45.8%
flip--45.5%
+-commutative45.5%
associate-*r/45.5%
add-sqr-sqrt45.7%
fma-udef45.7%
unpow245.7%
associate--l+72.7%
+-inverses72.7%
Applied egg-rr72.7%
Taylor expanded in a around 0 87.0%
if 2.5999999999999999e117 < b Initial program 4.0%
*-commutative4.0%
Simplified4.0%
Taylor expanded in b around inf 98.0%
mul-1-neg98.0%
distribute-neg-frac98.0%
Simplified98.0%
Final simplification91.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4e+119)
(- (/ c b) (/ b a))
(if (<= b -6.8e-286)
(/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0))
(if (<= b 2.4e-62)
(/ (* (/ a a) (/ c -0.5)) (+ b (hypot (sqrt (* c (* a -4.0))) b)))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+119) {
tmp = (c / b) - (b / a);
} else if (b <= -6.8e-286) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else if (b <= 2.4e-62) {
tmp = ((a / a) * (c / -0.5)) / (b + hypot(sqrt((c * (a * -4.0))), b));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e+119) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -6.8e-286) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); elseif (b <= 2.4e-62) tmp = Float64(Float64(Float64(a / a) * Float64(c / -0.5)) / Float64(b + hypot(sqrt(Float64(c * Float64(a * -4.0))), b))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e+119], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -6.8e-286], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.4e-62], N[(N[(N[(a / a), $MachinePrecision] * N[(c / -0.5), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+119}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -6.8 \cdot 10^{-286}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-62}:\\
\;\;\;\;\frac{\frac{a}{a} \cdot \frac{c}{-0.5}}{b + \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -4\right)}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.99999999999999978e119Initial program 43.9%
*-commutative43.9%
Simplified43.9%
Taylor expanded in b around -inf 98.1%
+-commutative98.1%
mul-1-neg98.1%
unsub-neg98.1%
Simplified98.1%
if -3.99999999999999978e119 < b < -6.8000000000000002e-286Initial program 89.1%
Simplified89.1%
if -6.8000000000000002e-286 < b < 2.39999999999999984e-62Initial program 62.5%
*-commutative62.5%
Simplified62.5%
+-commutative62.5%
unsub-neg62.5%
*-un-lft-identity62.5%
*-un-lft-identity62.5%
cancel-sign-sub-inv62.5%
+-commutative62.5%
*-commutative62.5%
distribute-rgt-neg-in62.5%
metadata-eval62.5%
associate-*r*62.5%
*-commutative62.5%
fma-udef62.5%
div-sub62.4%
sub-neg62.4%
Applied egg-rr62.3%
sub-neg62.3%
distribute-rgt-out--62.4%
Simplified62.4%
flip--62.0%
+-commutative62.0%
associate-*r/62.0%
add-sqr-sqrt62.3%
fma-udef62.3%
unpow262.3%
associate--l+66.7%
+-inverses66.7%
Applied egg-rr66.7%
expm1-log1p-u52.5%
expm1-udef22.5%
Applied egg-rr20.4%
expm1-def46.4%
expm1-log1p60.1%
*-commutative60.1%
associate-/r*60.1%
associate-/l*60.3%
associate-*l/60.3%
/-rgt-identity60.3%
*-commutative60.3%
associate-/l*60.3%
metadata-eval60.3%
associate-/r*60.3%
*-commutative60.3%
times-frac77.5%
associate-/l*77.5%
metadata-eval77.5%
Simplified77.5%
if 2.39999999999999984e-62 < b Initial program 11.5%
*-commutative11.5%
Simplified11.5%
Taylor expanded in b around inf 91.1%
mul-1-neg91.1%
distribute-neg-frac91.1%
Simplified91.1%
Final simplification89.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.65e+119)
(- (/ c b) (/ b a))
(if (<= b 4e-66)
(/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.65e+119) {
tmp = (c / b) - (b / a);
} else if (b <= 4e-66) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.65e+119) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4e-66) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.65e+119], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4e-66], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $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.65 \cdot 10^{+119}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-66}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.6500000000000001e119Initial program 43.9%
*-commutative43.9%
Simplified43.9%
Taylor expanded in b around -inf 98.1%
+-commutative98.1%
mul-1-neg98.1%
unsub-neg98.1%
Simplified98.1%
if -1.6500000000000001e119 < b < 3.9999999999999999e-66Initial program 80.1%
Simplified80.1%
if 3.9999999999999999e-66 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in b around inf 90.3%
mul-1-neg90.3%
distribute-neg-frac90.3%
Simplified90.3%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e+119)
(- (/ c b) (/ b a))
(if (<= b 1.75e-66)
(/ (- (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 <= -5.8e+119) {
tmp = (c / b) - (b / a);
} else if (b <= 1.75e-66) {
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 <= (-5.8d+119)) then
tmp = (c / b) - (b / a)
else if (b <= 1.75d-66) 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 <= -5.8e+119) {
tmp = (c / b) - (b / a);
} else if (b <= 1.75e-66) {
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 <= -5.8e+119: tmp = (c / b) - (b / a) elif b <= 1.75e-66: 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 <= -5.8e+119) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.75e-66) 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 <= -5.8e+119) tmp = (c / b) - (b / a); elseif (b <= 1.75e-66) 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, -5.8e+119], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.75e-66], 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 -5.8 \cdot 10^{+119}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-66}:\\
\;\;\;\;\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 < -5.80000000000000014e119Initial program 43.9%
*-commutative43.9%
Simplified43.9%
Taylor expanded in b around -inf 98.1%
+-commutative98.1%
mul-1-neg98.1%
unsub-neg98.1%
Simplified98.1%
if -5.80000000000000014e119 < b < 1.75e-66Initial program 80.1%
if 1.75e-66 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in b around inf 90.3%
mul-1-neg90.3%
distribute-neg-frac90.3%
Simplified90.3%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -7e-55)
(- (/ c b) (/ b a))
(if (<= b 5.2e-118)
(* (- b (sqrt (* c (* a -4.0)))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-55) {
tmp = (c / b) - (b / a);
} else if (b <= 5.2e-118) {
tmp = (b - 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 <= (-7d-55)) then
tmp = (c / b) - (b / a)
else if (b <= 5.2d-118) then
tmp = (b - 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 <= -7e-55) {
tmp = (c / b) - (b / a);
} else if (b <= 5.2e-118) {
tmp = (b - Math.sqrt((c * (a * -4.0)))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-55: tmp = (c / b) - (b / a) elif b <= 5.2e-118: tmp = (b - 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 <= -7e-55) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.2e-118) tmp = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7e-55) tmp = (c / b) - (b / a); elseif (b <= 5.2e-118) tmp = (b - sqrt((c * (a * -4.0)))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-55], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.2e-118], N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{-55}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-118}:\\
\;\;\;\;\left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.00000000000000051e-55Initial program 66.7%
*-commutative66.7%
Simplified66.7%
Taylor expanded in b around -inf 91.6%
+-commutative91.6%
mul-1-neg91.6%
unsub-neg91.6%
Simplified91.6%
if -7.00000000000000051e-55 < b < 5.2e-118Initial program 75.4%
*-commutative75.4%
Simplified75.4%
Taylor expanded in b around 0 69.9%
*-commutative69.9%
associate-*r*69.9%
Simplified69.9%
frac-2neg69.9%
div-inv69.7%
distribute-neg-in69.7%
add-sqr-sqrt42.4%
sqrt-unprod68.9%
sqr-neg68.9%
unpow268.9%
unpow268.9%
sqrt-prod27.3%
add-sqr-sqrt67.9%
sub-neg67.9%
add-sqr-sqrt40.6%
sqrt-unprod68.0%
sqr-neg68.0%
unpow268.0%
unpow268.0%
sqrt-prod27.3%
add-sqr-sqrt69.7%
distribute-rgt-neg-in69.7%
metadata-eval69.7%
Applied egg-rr69.7%
*-commutative69.7%
associate-*l*69.7%
*-commutative69.7%
associate-/r*69.7%
metadata-eval69.7%
Simplified69.7%
if 5.2e-118 < b Initial program 16.4%
*-commutative16.4%
Simplified16.4%
Taylor expanded in b around inf 85.8%
mul-1-neg85.8%
distribute-neg-frac85.8%
Simplified85.8%
Final simplification83.2%
(FPCore (a b c)
:precision binary64
(if (<= b -5.1e-61)
(- (/ c b) (/ b a))
(if (<= b 3.6e-118)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.1e-61) {
tmp = (c / b) - (b / a);
} else if (b <= 3.6e-118) {
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 <= (-5.1d-61)) then
tmp = (c / b) - (b / a)
else if (b <= 3.6d-118) 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 <= -5.1e-61) {
tmp = (c / b) - (b / a);
} else if (b <= 3.6e-118) {
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 <= -5.1e-61: tmp = (c / b) - (b / a) elif b <= 3.6e-118: 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 <= -5.1e-61) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.6e-118) tmp = Float64(Float64(sqrt(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 <= -5.1e-61) tmp = (c / b) - (b / a); elseif (b <= 3.6e-118) 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, -5.1e-61], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.6e-118], 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 -5.1 \cdot 10^{-61}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-118}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.09999999999999968e-61Initial program 66.7%
*-commutative66.7%
Simplified66.7%
Taylor expanded in b around -inf 91.6%
+-commutative91.6%
mul-1-neg91.6%
unsub-neg91.6%
Simplified91.6%
if -5.09999999999999968e-61 < b < 3.6000000000000002e-118Initial program 75.4%
*-commutative75.4%
Simplified75.4%
Taylor expanded in b around 0 69.9%
*-commutative69.9%
associate-*r*69.9%
Simplified69.9%
neg-sub069.9%
associate-+l-69.9%
Applied egg-rr69.9%
associate--r-69.9%
+-commutative69.9%
associate--l+69.9%
+-rgt-identity69.9%
*-commutative69.9%
associate-*l*69.9%
Simplified69.9%
if 3.6000000000000002e-118 < b Initial program 16.4%
*-commutative16.4%
Simplified16.4%
Taylor expanded in b around inf 85.8%
mul-1-neg85.8%
distribute-neg-frac85.8%
Simplified85.8%
Final simplification83.2%
(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 71.3%
*-commutative71.3%
Simplified71.3%
Taylor expanded in b around -inf 67.8%
+-commutative67.8%
mul-1-neg67.8%
unsub-neg67.8%
Simplified67.8%
if -4.999999999999985e-310 < b Initial program 28.9%
*-commutative28.9%
Simplified28.9%
Taylor expanded in b around inf 69.3%
mul-1-neg69.3%
distribute-neg-frac69.3%
Simplified69.3%
Final simplification68.5%
(FPCore (a b c) :precision binary64 (if (<= b 9e+44) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 9e+44) {
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 <= 9d+44) 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 <= 9e+44) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 9e+44: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 9e+44) 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 <= 9e+44) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 9e+44], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9 \cdot 10^{+44}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 9e44Initial program 63.9%
*-commutative63.9%
Simplified63.9%
Taylor expanded in b around -inf 47.9%
associate-*r/47.9%
mul-1-neg47.9%
Simplified47.9%
if 9e44 < b Initial program 11.9%
*-commutative11.9%
Simplified11.9%
Taylor expanded in b around -inf 2.5%
Taylor expanded in b around 0 29.4%
Final simplification43.3%
(FPCore (a b c) :precision binary64 (if (<= b 9e-309) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 9e-309) {
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 <= 9d-309) 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 <= 9e-309) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 9e-309: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 9e-309) 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 <= 9e-309) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 9e-309], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 9.0000000000000021e-309Initial program 71.3%
*-commutative71.3%
Simplified71.3%
Taylor expanded in b around -inf 67.5%
associate-*r/67.5%
mul-1-neg67.5%
Simplified67.5%
if 9.0000000000000021e-309 < b Initial program 28.9%
*-commutative28.9%
Simplified28.9%
Taylor expanded in b around inf 69.3%
mul-1-neg69.3%
distribute-neg-frac69.3%
Simplified69.3%
Final simplification68.4%
(FPCore (a b c) :precision binary64 (/ -3.0 a))
double code(double a, double b, double c) {
return -3.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 = (-3.0d0) / a
end function
public static double code(double a, double b, double c) {
return -3.0 / a;
}
def code(a, b, c): return -3.0 / a
function code(a, b, c) return Float64(-3.0 / a) end
function tmp = code(a, b, c) tmp = -3.0 / a; end
code[a_, b_, c_] := N[(-3.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-3}{a}
\end{array}
Initial program 50.9%
Simplified51.0%
*-un-lft-identity51.0%
*-un-lft-identity51.0%
prod-diff51.0%
*-commutative51.0%
*-un-lft-identity51.0%
fma-neg51.0%
*-un-lft-identity51.0%
prod-diff51.0%
*-commutative51.0%
*-un-lft-identity51.0%
fma-neg51.0%
*-un-lft-identity51.0%
associate-+l+51.0%
Applied egg-rr32.6%
+-commutative32.6%
associate-+l+32.6%
count-232.6%
fma-udef32.6%
*-rgt-identity32.6%
Simplified32.6%
Taylor expanded in a around 0 2.5%
*-un-lft-identity2.5%
metadata-eval2.5%
*-commutative2.5%
times-frac2.5%
metadata-eval2.5%
metadata-eval2.5%
associate-+r+2.5%
flip-+0.0%
associate-*r/0.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
flip-+2.5%
count-22.5%
flip-+0.0%
associate-*r/0.0%
+-inverses0.0%
metadata-eval0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified2.4%
Final simplification2.4%
(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 50.9%
*-commutative50.9%
Simplified50.9%
+-commutative50.9%
unsub-neg50.9%
*-un-lft-identity50.9%
*-un-lft-identity50.9%
cancel-sign-sub-inv50.9%
+-commutative50.9%
*-commutative50.9%
distribute-rgt-neg-in50.9%
metadata-eval50.9%
associate-*r*50.9%
*-commutative50.9%
fma-udef51.0%
add-cbrt-cube28.5%
Applied egg-rr18.9%
Taylor expanded in b 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 50.9%
*-commutative50.9%
Simplified50.9%
Taylor expanded in b around -inf 34.6%
Taylor expanded in b around 0 9.7%
Final simplification9.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023326
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))