
(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 (fma a (* c -4.0) (pow b 2.0))))
(if (<= (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) -55.0)
(/ (/ (/ (- (pow b 2.0) t_0) a) -2.0) (+ b (sqrt t_0)))
(+
(* -2.0 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(-
(-
(* -0.25 (* (/ (pow (* a c) 4.0) a) (/ 20.0 (pow b 7.0))))
(/ (* a (pow c 2.0)) (pow b 3.0)))
(/ c b))))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c * -4.0), pow(b, 2.0));
double tmp;
if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -55.0) {
tmp = (((pow(b, 2.0) - t_0) / a) / -2.0) / (b + sqrt(t_0));
} else {
tmp = (-2.0 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + (((-0.25 * ((pow((a * c), 4.0) / a) * (20.0 / pow(b, 7.0)))) - ((a * pow(c, 2.0)) / pow(b, 3.0))) - (c / b));
}
return tmp;
}
function code(a, b, c) t_0 = fma(a, Float64(c * -4.0), (b ^ 2.0)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) <= -55.0) tmp = Float64(Float64(Float64(Float64((b ^ 2.0) - t_0) / a) / -2.0) / Float64(b + sqrt(t_0))); else tmp = Float64(Float64(-2.0 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(Float64(-0.25 * Float64(Float64((Float64(a * c) ^ 4.0) / a) * Float64(20.0 / (b ^ 7.0)))) - Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0))) - Float64(c / b))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -55.0], N[(N[(N[(N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision] / a), $MachinePrecision] / -2.0), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-0.25 * N[(N[(N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision] / a), $MachinePrecision] * N[(20.0 / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -55:\\
\;\;\;\;\frac{\frac{\frac{{b}^{2} - t_0}{a}}{-2}}{b + \sqrt{t_0}}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(\left(-0.25 \cdot \left(\frac{{\left(a \cdot c\right)}^{4}}{a} \cdot \frac{20}{{b}^{7}}\right) - \frac{a \cdot {c}^{2}}{{b}^{3}}\right) - \frac{c}{b}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -55Initial program 87.8%
Simplified87.9%
frac-2neg87.9%
div-inv88.0%
sub-neg88.0%
distribute-neg-in88.0%
pow288.0%
add-sqr-sqrt0.0%
sqrt-unprod1.5%
sqr-neg1.5%
sqrt-prod1.5%
add-sqr-sqrt1.5%
add-sqr-sqrt0.0%
sqrt-unprod88.0%
sqr-neg88.0%
sqrt-prod86.9%
add-sqr-sqrt88.0%
distribute-rgt-neg-in88.0%
metadata-eval88.0%
Applied egg-rr88.0%
*-commutative88.0%
+-commutative88.0%
Simplified88.0%
add-log-exp73.1%
unsub-neg73.1%
Applied egg-rr73.1%
associate-/r*73.1%
rem-log-exp88.0%
flip--89.0%
frac-times89.0%
unpow289.0%
add-sqr-sqrt89.8%
Applied egg-rr89.8%
associate-/r*89.8%
associate-*l/89.9%
*-lft-identity89.9%
Simplified89.9%
if -55 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 51.5%
*-commutative51.5%
Simplified51.5%
Taylor expanded in b around inf 93.5%
Taylor expanded in c around 0 93.5%
distribute-rgt-out93.5%
associate-*r*93.5%
*-commutative93.5%
times-frac93.5%
Simplified93.5%
Final simplification93.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma a (* c -4.0) (pow b 2.0))))
(if (<= b 1.05)
(/ (/ (/ (- (pow b 2.0) t_0) a) -2.0) (+ b (sqrt t_0)))
(-
(- (/ (* -2.0 (pow a 2.0)) (/ (pow b 5.0) (pow c 3.0))) (/ c b))
(/ a (/ (pow b 3.0) (pow c 2.0)))))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c * -4.0), pow(b, 2.0));
double tmp;
if (b <= 1.05) {
tmp = (((pow(b, 2.0) - t_0) / a) / -2.0) / (b + sqrt(t_0));
} else {
tmp = (((-2.0 * pow(a, 2.0)) / (pow(b, 5.0) / pow(c, 3.0))) - (c / b)) - (a / (pow(b, 3.0) / pow(c, 2.0)));
}
return tmp;
}
function code(a, b, c) t_0 = fma(a, Float64(c * -4.0), (b ^ 2.0)) tmp = 0.0 if (b <= 1.05) tmp = Float64(Float64(Float64(Float64((b ^ 2.0) - t_0) / a) / -2.0) / Float64(b + sqrt(t_0))); else tmp = Float64(Float64(Float64(Float64(-2.0 * (a ^ 2.0)) / Float64((b ^ 5.0) / (c ^ 3.0))) - Float64(c / b)) - Float64(a / Float64((b ^ 3.0) / (c ^ 2.0)))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.05], N[(N[(N[(N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision] / a), $MachinePrecision] / -2.0), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-2.0 * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)\\
\mathbf{if}\;b \leq 1.05:\\
\;\;\;\;\frac{\frac{\frac{{b}^{2} - t_0}{a}}{-2}}{b + \sqrt{t_0}}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{-2 \cdot {a}^{2}}{\frac{{b}^{5}}{{c}^{3}}} - \frac{c}{b}\right) - \frac{a}{\frac{{b}^{3}}{{c}^{2}}}\\
\end{array}
\end{array}
if b < 1.05000000000000004Initial program 83.6%
Simplified83.6%
frac-2neg83.6%
div-inv83.6%
sub-neg83.6%
distribute-neg-in83.6%
pow283.7%
add-sqr-sqrt0.0%
sqrt-unprod1.6%
sqr-neg1.6%
sqrt-prod1.6%
add-sqr-sqrt1.6%
add-sqr-sqrt0.0%
sqrt-unprod83.7%
sqr-neg83.7%
sqrt-prod82.4%
add-sqr-sqrt83.7%
distribute-rgt-neg-in83.7%
metadata-eval83.7%
Applied egg-rr83.7%
*-commutative83.7%
+-commutative83.7%
Simplified83.7%
add-log-exp73.2%
unsub-neg73.2%
Applied egg-rr73.2%
associate-/r*73.2%
rem-log-exp83.7%
flip--84.4%
frac-times84.4%
unpow284.6%
add-sqr-sqrt85.4%
Applied egg-rr85.4%
associate-/r*85.4%
associate-*l/85.4%
*-lft-identity85.4%
Simplified85.4%
if 1.05000000000000004 < b Initial program 49.0%
Simplified49.0%
frac-2neg49.0%
div-inv49.0%
sub-neg49.0%
distribute-neg-in49.0%
pow249.0%
add-sqr-sqrt0.0%
sqrt-unprod1.6%
sqr-neg1.6%
sqrt-prod1.6%
add-sqr-sqrt1.6%
add-sqr-sqrt0.0%
sqrt-unprod49.0%
sqr-neg49.0%
sqrt-prod47.9%
add-sqr-sqrt49.0%
distribute-rgt-neg-in49.0%
metadata-eval49.0%
Applied egg-rr49.0%
*-commutative49.0%
+-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 91.9%
neg-mul-191.9%
associate-+r+91.9%
mul-1-neg91.9%
unsub-neg91.9%
unsub-neg91.9%
associate-/l*91.9%
associate-*r/91.9%
associate-/l*91.9%
Simplified91.9%
Final simplification90.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma a (* c -4.0) (pow b 2.0))))
(if (<= b 1.05)
(/ (- (pow b 2.0) t_0) (* (+ b (sqrt t_0)) (* a -2.0)))
(-
(- (/ (* -2.0 (pow a 2.0)) (/ (pow b 5.0) (pow c 3.0))) (/ c b))
(/ a (/ (pow b 3.0) (pow c 2.0)))))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c * -4.0), pow(b, 2.0));
double tmp;
if (b <= 1.05) {
tmp = (pow(b, 2.0) - t_0) / ((b + sqrt(t_0)) * (a * -2.0));
} else {
tmp = (((-2.0 * pow(a, 2.0)) / (pow(b, 5.0) / pow(c, 3.0))) - (c / b)) - (a / (pow(b, 3.0) / pow(c, 2.0)));
}
return tmp;
}
function code(a, b, c) t_0 = fma(a, Float64(c * -4.0), (b ^ 2.0)) tmp = 0.0 if (b <= 1.05) tmp = Float64(Float64((b ^ 2.0) - t_0) / Float64(Float64(b + sqrt(t_0)) * Float64(a * -2.0))); else tmp = Float64(Float64(Float64(Float64(-2.0 * (a ^ 2.0)) / Float64((b ^ 5.0) / (c ^ 3.0))) - Float64(c / b)) - Float64(a / Float64((b ^ 3.0) / (c ^ 2.0)))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.05], N[(N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * N[(a * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-2.0 * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)\\
\mathbf{if}\;b \leq 1.05:\\
\;\;\;\;\frac{{b}^{2} - t_0}{\left(b + \sqrt{t_0}\right) \cdot \left(a \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{-2 \cdot {a}^{2}}{\frac{{b}^{5}}{{c}^{3}}} - \frac{c}{b}\right) - \frac{a}{\frac{{b}^{3}}{{c}^{2}}}\\
\end{array}
\end{array}
if b < 1.05000000000000004Initial program 83.6%
Simplified83.6%
frac-2neg83.6%
div-inv83.6%
sub-neg83.6%
distribute-neg-in83.6%
pow283.7%
add-sqr-sqrt0.0%
sqrt-unprod1.6%
sqr-neg1.6%
sqrt-prod1.6%
add-sqr-sqrt1.6%
add-sqr-sqrt0.0%
sqrt-unprod83.7%
sqr-neg83.7%
sqrt-prod82.4%
add-sqr-sqrt83.7%
distribute-rgt-neg-in83.7%
metadata-eval83.7%
Applied egg-rr83.7%
*-commutative83.7%
+-commutative83.7%
Simplified83.7%
add-log-exp73.2%
unsub-neg73.2%
Applied egg-rr73.2%
*-commutative73.2%
rem-log-exp83.7%
flip--84.4%
frac-times84.4%
unpow284.6%
add-sqr-sqrt85.4%
Applied egg-rr85.4%
if 1.05000000000000004 < b Initial program 49.0%
Simplified49.0%
frac-2neg49.0%
div-inv49.0%
sub-neg49.0%
distribute-neg-in49.0%
pow249.0%
add-sqr-sqrt0.0%
sqrt-unprod1.6%
sqr-neg1.6%
sqrt-prod1.6%
add-sqr-sqrt1.6%
add-sqr-sqrt0.0%
sqrt-unprod49.0%
sqr-neg49.0%
sqrt-prod47.9%
add-sqr-sqrt49.0%
distribute-rgt-neg-in49.0%
metadata-eval49.0%
Applied egg-rr49.0%
*-commutative49.0%
+-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 91.9%
neg-mul-191.9%
associate-+r+91.9%
mul-1-neg91.9%
unsub-neg91.9%
unsub-neg91.9%
associate-/l*91.9%
associate-*r/91.9%
associate-/l*91.9%
Simplified91.9%
Final simplification90.9%
(FPCore (a b c)
:precision binary64
(if (<= b 1.05)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(-
(- (/ (* -2.0 (pow a 2.0)) (/ (pow b 5.0) (pow c 3.0))) (/ c b))
(/ a (/ (pow b 3.0) (pow c 2.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.05) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (((-2.0 * pow(a, 2.0)) / (pow(b, 5.0) / pow(c, 3.0))) - (c / b)) - (a / (pow(b, 3.0) / pow(c, 2.0)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1.05) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(Float64(-2.0 * (a ^ 2.0)) / Float64((b ^ 5.0) / (c ^ 3.0))) - Float64(c / b)) - Float64(a / Float64((b ^ 3.0) / (c ^ 2.0)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1.05], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-2.0 * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.05:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{-2 \cdot {a}^{2}}{\frac{{b}^{5}}{{c}^{3}}} - \frac{c}{b}\right) - \frac{a}{\frac{{b}^{3}}{{c}^{2}}}\\
\end{array}
\end{array}
if b < 1.05000000000000004Initial program 83.6%
sqr-neg83.6%
+-commutative83.6%
unsub-neg83.6%
sqr-neg83.6%
fma-neg83.7%
distribute-lft-neg-in83.7%
*-commutative83.7%
*-commutative83.7%
distribute-rgt-neg-in83.7%
metadata-eval83.7%
*-commutative83.7%
Simplified83.7%
if 1.05000000000000004 < b Initial program 49.0%
Simplified49.0%
frac-2neg49.0%
div-inv49.0%
sub-neg49.0%
distribute-neg-in49.0%
pow249.0%
add-sqr-sqrt0.0%
sqrt-unprod1.6%
sqr-neg1.6%
sqrt-prod1.6%
add-sqr-sqrt1.6%
add-sqr-sqrt0.0%
sqrt-unprod49.0%
sqr-neg49.0%
sqrt-prod47.9%
add-sqr-sqrt49.0%
distribute-rgt-neg-in49.0%
metadata-eval49.0%
Applied egg-rr49.0%
*-commutative49.0%
+-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 91.9%
neg-mul-191.9%
associate-+r+91.9%
mul-1-neg91.9%
unsub-neg91.9%
unsub-neg91.9%
associate-/l*91.9%
associate-*r/91.9%
associate-/l*91.9%
Simplified91.9%
Final simplification90.6%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)))) (if (<= t_0 -8e-6) t_0 (/ (- c) b))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -8e-6) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - ((4.0d0 * a) * c))) - b) / (a * 2.0d0)
if (t_0 <= (-8d-6)) then
tmp = t_0
else
tmp = -c / b
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))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -8e-6) {
tmp = t_0;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0) tmp = 0 if t_0 <= -8e-6: tmp = t_0 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -8e-6) tmp = t_0; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -8e-6) tmp = t_0; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -8e-6], t$95$0, N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{if}\;t_0 \leq -8 \cdot 10^{-6}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -7.99999999999999964e-6Initial program 71.7%
if -7.99999999999999964e-6 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 33.4%
*-commutative33.4%
Simplified33.4%
Taylor expanded in b around inf 82.2%
mul-1-neg82.2%
distribute-neg-frac82.2%
Simplified82.2%
Final simplification76.4%
(FPCore (a b c) :precision binary64 (if (<= b 1.1) (/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0)) (- (/ (- c) b) (/ a (/ (pow b 3.0) (pow c 2.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.1) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - (a / (pow(b, 3.0) / pow(c, 2.0)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1.1) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(a / Float64((b ^ 3.0) / (c ^ 2.0)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1.1], 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[(N[((-c) / b), $MachinePrecision] - N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{a}{\frac{{b}^{3}}{{c}^{2}}}\\
\end{array}
\end{array}
if b < 1.1000000000000001Initial program 83.6%
Simplified83.6%
if 1.1000000000000001 < b Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in b around inf 87.0%
mul-1-neg87.0%
unsub-neg87.0%
mul-1-neg87.0%
distribute-neg-frac87.0%
associate-/l*87.0%
Simplified87.0%
Final simplification86.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.05) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (- (/ (- c) b) (/ a (/ (pow b 3.0) (pow c 2.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.05) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - (a / (pow(b, 3.0) / pow(c, 2.0)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1.05) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(a / Float64((b ^ 3.0) / (c ^ 2.0)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1.05], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.05:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{a}{\frac{{b}^{3}}{{c}^{2}}}\\
\end{array}
\end{array}
if b < 1.05000000000000004Initial program 83.6%
sqr-neg83.6%
+-commutative83.6%
unsub-neg83.6%
sqr-neg83.6%
fma-neg83.7%
distribute-lft-neg-in83.7%
*-commutative83.7%
*-commutative83.7%
distribute-rgt-neg-in83.7%
metadata-eval83.7%
*-commutative83.7%
Simplified83.7%
if 1.05000000000000004 < b Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in b around inf 87.0%
mul-1-neg87.0%
unsub-neg87.0%
mul-1-neg87.0%
distribute-neg-frac87.0%
associate-/l*87.0%
Simplified87.0%
Final simplification86.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.1) (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) (- (/ (- c) b) (/ a (/ (pow b 3.0) (pow c 2.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.1) {
tmp = (sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - (a / (pow(b, 3.0) / pow(c, 2.0)));
}
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.1d0) then
tmp = (sqrt(((b * b) - ((4.0d0 * a) * c))) - b) / (a * 2.0d0)
else
tmp = (-c / b) - (a / ((b ** 3.0d0) / (c ** 2.0d0)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.1) {
tmp = (Math.sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - (a / (Math.pow(b, 3.0) / Math.pow(c, 2.0)));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.1: tmp = (math.sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0) else: tmp = (-c / b) - (a / (math.pow(b, 3.0) / math.pow(c, 2.0))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.1) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(a / Float64((b ^ 3.0) / (c ^ 2.0)))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.1) tmp = (sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0); else tmp = (-c / b) - (a / ((b ^ 3.0) / (c ^ 2.0))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.1], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{a}{\frac{{b}^{3}}{{c}^{2}}}\\
\end{array}
\end{array}
if b < 1.1000000000000001Initial program 83.6%
if 1.1000000000000001 < b Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in b around inf 87.0%
mul-1-neg87.0%
unsub-neg87.0%
mul-1-neg87.0%
distribute-neg-frac87.0%
associate-/l*87.0%
Simplified87.0%
Final simplification86.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(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.5%
*-commutative54.5%
Simplified54.5%
Taylor expanded in b around inf 64.9%
mul-1-neg64.9%
distribute-neg-frac64.9%
Simplified64.9%
Final simplification64.9%
(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.5%
*-commutative54.5%
Simplified54.5%
Taylor expanded in b around -inf 11.5%
+-commutative11.5%
mul-1-neg11.5%
unsub-neg11.5%
Simplified11.5%
Taylor expanded in c around inf 1.6%
Final simplification1.6%
herbie shell --seed 2023331
(FPCore (a b c)
:name "Quadratic roots, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))