
(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
(-
(*
a
(-
(*
(pow c 4.0)
(+ (* -5.0 (/ (pow a 2.0) (pow b 7.0))) (* -2.0 (/ a (* c (pow b 5.0))))))
(/ (pow c 2.0) (pow b 3.0))))
(/ c b)))
double code(double a, double b, double c) {
return (a * ((pow(c, 4.0) * ((-5.0 * (pow(a, 2.0) / pow(b, 7.0))) + (-2.0 * (a / (c * pow(b, 5.0)))))) - (pow(c, 2.0) / pow(b, 3.0)))) - (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 = (a * (((c ** 4.0d0) * (((-5.0d0) * ((a ** 2.0d0) / (b ** 7.0d0))) + ((-2.0d0) * (a / (c * (b ** 5.0d0)))))) - ((c ** 2.0d0) / (b ** 3.0d0)))) - (c / b)
end function
public static double code(double a, double b, double c) {
return (a * ((Math.pow(c, 4.0) * ((-5.0 * (Math.pow(a, 2.0) / Math.pow(b, 7.0))) + (-2.0 * (a / (c * Math.pow(b, 5.0)))))) - (Math.pow(c, 2.0) / Math.pow(b, 3.0)))) - (c / b);
}
def code(a, b, c): return (a * ((math.pow(c, 4.0) * ((-5.0 * (math.pow(a, 2.0) / math.pow(b, 7.0))) + (-2.0 * (a / (c * math.pow(b, 5.0)))))) - (math.pow(c, 2.0) / math.pow(b, 3.0)))) - (c / b)
function code(a, b, c) return Float64(Float64(a * Float64(Float64((c ^ 4.0) * Float64(Float64(-5.0 * Float64((a ^ 2.0) / (b ^ 7.0))) + Float64(-2.0 * Float64(a / Float64(c * (b ^ 5.0)))))) - Float64((c ^ 2.0) / (b ^ 3.0)))) - Float64(c / b)) end
function tmp = code(a, b, c) tmp = (a * (((c ^ 4.0) * ((-5.0 * ((a ^ 2.0) / (b ^ 7.0))) + (-2.0 * (a / (c * (b ^ 5.0)))))) - ((c ^ 2.0) / (b ^ 3.0)))) - (c / b); end
code[a_, b_, c_] := N[(N[(a * N[(N[(N[Power[c, 4.0], $MachinePrecision] * N[(N[(-5.0 * N[(N[Power[a, 2.0], $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(a / N[(c * N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot \left({c}^{4} \cdot \left(-5 \cdot \frac{{a}^{2}}{{b}^{7}} + -2 \cdot \frac{a}{c \cdot {b}^{5}}\right) - \frac{{c}^{2}}{{b}^{3}}\right) - \frac{c}{b}
\end{array}
Initial program 51.1%
*-commutative51.1%
Simplified51.1%
Taylor expanded in a around 0 92.6%
Taylor expanded in c around inf 92.6%
Final simplification92.6%
(FPCore (a b c)
:precision binary64
(*
c
(fma
c
(-
(*
(pow a 3.0)
(+ (* -5.0 (/ (pow c 2.0) (pow b 7.0))) (* -2.0 (/ c (* a (pow b 5.0))))))
(/ a (pow b 3.0)))
(/ -1.0 b))))
double code(double a, double b, double c) {
return c * fma(c, ((pow(a, 3.0) * ((-5.0 * (pow(c, 2.0) / pow(b, 7.0))) + (-2.0 * (c / (a * pow(b, 5.0)))))) - (a / pow(b, 3.0))), (-1.0 / b));
}
function code(a, b, c) return Float64(c * fma(c, Float64(Float64((a ^ 3.0) * Float64(Float64(-5.0 * Float64((c ^ 2.0) / (b ^ 7.0))) + Float64(-2.0 * Float64(c / Float64(a * (b ^ 5.0)))))) - Float64(a / (b ^ 3.0))), Float64(-1.0 / b))) end
code[a_, b_, c_] := N[(c * N[(c * N[(N[(N[Power[a, 3.0], $MachinePrecision] * N[(N[(-5.0 * N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(c / N[(a * N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \mathsf{fma}\left(c, {a}^{3} \cdot \left(-5 \cdot \frac{{c}^{2}}{{b}^{7}} + -2 \cdot \frac{c}{a \cdot {b}^{5}}\right) - \frac{a}{{b}^{3}}, \frac{-1}{b}\right)
\end{array}
Initial program 51.1%
*-commutative51.1%
+-commutative51.1%
sqr-neg51.1%
unsub-neg51.1%
sqr-neg51.1%
fma-neg51.1%
distribute-lft-neg-in51.1%
*-commutative51.1%
*-commutative51.1%
distribute-rgt-neg-in51.1%
metadata-eval51.1%
Simplified51.1%
Taylor expanded in c around inf 50.8%
Taylor expanded in c around 0 92.4%
fma-neg92.4%
Simplified92.4%
Taylor expanded in a around inf 92.4%
Final simplification92.4%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -5.5)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(-
(*
a
(-
(* -2.0 (* a (/ (pow c 3.0) (pow b 5.0))))
(/ (pow c 2.0) (pow b 3.0))))
(/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0)) <= -5.5) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (a * ((-2.0 * (a * (pow(c, 3.0) / pow(b, 5.0)))) - (pow(c, 2.0) / pow(b, 3.0)))) - (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) <= -5.5) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(a * Float64(Float64(-2.0 * Float64(a * Float64((c ^ 3.0) / (b ^ 5.0)))) - Float64((c ^ 2.0) / (b ^ 3.0)))) - Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[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], -5.5], 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[(a * N[(N[(-2.0 * N[(a * N[(N[Power[c, 3.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2} \leq -5.5:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(-2 \cdot \left(a \cdot \frac{{c}^{3}}{{b}^{5}}\right) - \frac{{c}^{2}}{{b}^{3}}\right) - \frac{c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -5.5Initial program 85.0%
*-commutative85.0%
+-commutative85.0%
sqr-neg85.0%
unsub-neg85.0%
sqr-neg85.0%
fma-neg85.1%
distribute-lft-neg-in85.1%
*-commutative85.1%
*-commutative85.1%
distribute-rgt-neg-in85.1%
metadata-eval85.1%
Simplified85.1%
if -5.5 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.8%
*-commutative46.8%
+-commutative46.8%
sqr-neg46.8%
unsub-neg46.8%
sqr-neg46.8%
fma-neg46.8%
distribute-lft-neg-in46.8%
*-commutative46.8%
*-commutative46.8%
distribute-rgt-neg-in46.8%
metadata-eval46.8%
Simplified46.8%
Taylor expanded in c around inf 46.5%
add-cbrt-cube46.5%
pow346.5%
*-commutative46.5%
fma-define46.5%
Applied egg-rr46.5%
Taylor expanded in a around 0 93.2%
+-commutative93.2%
mul-1-neg93.2%
unsub-neg93.2%
mul-1-neg93.2%
unsub-neg93.2%
associate-/l*93.2%
Simplified93.2%
Final simplification92.3%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -5.5)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(*
c
(+
(/ -1.0 b)
(* c (- (* -2.0 (/ (* c (pow a 2.0)) (pow b 5.0))) (/ a (pow b 3.0))))))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0)) <= -5.5) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = c * ((-1.0 / b) + (c * ((-2.0 * ((c * pow(a, 2.0)) / pow(b, 5.0))) - (a / pow(b, 3.0)))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) <= -5.5) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(c * Float64(Float64(-1.0 / b) + Float64(c * Float64(Float64(-2.0 * Float64(Float64(c * (a ^ 2.0)) / (b ^ 5.0))) - Float64(a / (b ^ 3.0)))))); end return tmp end
code[a_, b_, c_] := If[LessEqual[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], -5.5], 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[(c * N[(N[(-1.0 / b), $MachinePrecision] + N[(c * N[(N[(-2.0 * N[(N[(c * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2} \leq -5.5:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(\frac{-1}{b} + c \cdot \left(-2 \cdot \frac{c \cdot {a}^{2}}{{b}^{5}} - \frac{a}{{b}^{3}}\right)\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -5.5Initial program 85.0%
*-commutative85.0%
+-commutative85.0%
sqr-neg85.0%
unsub-neg85.0%
sqr-neg85.0%
fma-neg85.1%
distribute-lft-neg-in85.1%
*-commutative85.1%
*-commutative85.1%
distribute-rgt-neg-in85.1%
metadata-eval85.1%
Simplified85.1%
if -5.5 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.8%
*-commutative46.8%
Simplified46.8%
Taylor expanded in c around 0 93.0%
Final simplification92.1%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -2.0) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (/ (- (- c) (/ (* a (pow c 2.0)) (pow b 2.0))) b)))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0)) <= -2.0) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (-c - ((a * pow(c, 2.0)) / pow(b, 2.0))) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) <= -2.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) - Float64(Float64(a * (c ^ 2.0)) / (b ^ 2.0))) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[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], -2.0], 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) - N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2} \leq -2:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-c\right) - \frac{a \cdot {c}^{2}}{{b}^{2}}}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -2Initial program 82.9%
*-commutative82.9%
+-commutative82.9%
sqr-neg82.9%
unsub-neg82.9%
sqr-neg82.9%
fma-neg83.0%
distribute-lft-neg-in83.0%
*-commutative83.0%
*-commutative83.0%
distribute-rgt-neg-in83.0%
metadata-eval83.0%
Simplified83.0%
if -2 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 45.6%
*-commutative45.6%
Simplified45.6%
Taylor expanded in b around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
mul-1-neg89.0%
Simplified89.0%
Final simplification88.1%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))) (if (<= t_0 -2.0) t_0 (- (/ c (- b)) (* a (/ (pow c 2.0) (pow b 3.0)))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.0) {
tmp = t_0;
} else {
tmp = (c / -b) - (a * (pow(c, 2.0) / pow(b, 3.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) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (t_0 <= (-2.0d0)) then
tmp = t_0
else
tmp = (c / -b) - (a * ((c ** 2.0d0) / (b ** 3.0d0)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.0) {
tmp = t_0;
} else {
tmp = (c / -b) - (a * (Math.pow(c, 2.0) / Math.pow(b, 3.0)));
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -2.0: tmp = t_0 else: tmp = (c / -b) - (a * (math.pow(c, 2.0) / math.pow(b, 3.0))) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -2.0) tmp = t_0; else tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64((c ^ 2.0) / (b ^ 3.0)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -2.0) tmp = t_0; else tmp = (c / -b) - (a * ((c ^ 2.0) / (b ^ 3.0))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = 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[t$95$0, -2.0], t$95$0, N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \frac{{c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -2Initial program 82.9%
if -2 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 45.6%
*-commutative45.6%
Simplified45.6%
Taylor expanded in a around 0 89.0%
mul-1-neg89.0%
unsub-neg89.0%
mul-1-neg89.0%
distribute-neg-frac289.0%
associate-/l*89.0%
Simplified89.0%
Final simplification88.1%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))) (if (<= t_0 -2.0) t_0 (/ (- (- c) (/ (* a (pow c 2.0)) (pow b 2.0))) b))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.0) {
tmp = t_0;
} else {
tmp = (-c - ((a * pow(c, 2.0)) / pow(b, 2.0))) / 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) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (t_0 <= (-2.0d0)) then
tmp = t_0
else
tmp = (-c - ((a * (c ** 2.0d0)) / (b ** 2.0d0))) / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.0) {
tmp = t_0;
} else {
tmp = (-c - ((a * Math.pow(c, 2.0)) / Math.pow(b, 2.0))) / b;
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -2.0: tmp = t_0 else: tmp = (-c - ((a * math.pow(c, 2.0)) / math.pow(b, 2.0))) / b return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -2.0) tmp = t_0; else tmp = Float64(Float64(Float64(-c) - Float64(Float64(a * (c ^ 2.0)) / (b ^ 2.0))) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -2.0) tmp = t_0; else tmp = (-c - ((a * (c ^ 2.0)) / (b ^ 2.0))) / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = 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[t$95$0, -2.0], t$95$0, N[(N[((-c) - N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-c\right) - \frac{a \cdot {c}^{2}}{{b}^{2}}}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -2Initial program 82.9%
if -2 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 45.6%
*-commutative45.6%
Simplified45.6%
Taylor expanded in b around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
mul-1-neg89.0%
Simplified89.0%
Final simplification88.1%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))) (if (<= t_0 -2.0) t_0 (/ (* c (- -1.0 (/ (* c a) (pow b 2.0)))) b))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.0) {
tmp = t_0;
} else {
tmp = (c * (-1.0 - ((c * a) / pow(b, 2.0)))) / 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) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (t_0 <= (-2.0d0)) then
tmp = t_0
else
tmp = (c * ((-1.0d0) - ((c * a) / (b ** 2.0d0)))) / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.0) {
tmp = t_0;
} else {
tmp = (c * (-1.0 - ((c * a) / Math.pow(b, 2.0)))) / b;
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -2.0: tmp = t_0 else: tmp = (c * (-1.0 - ((c * a) / math.pow(b, 2.0)))) / b return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -2.0) tmp = t_0; else tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / (b ^ 2.0)))) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -2.0) tmp = t_0; else tmp = (c * (-1.0 - ((c * a) / (b ^ 2.0)))) / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = 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[t$95$0, -2.0], t$95$0, N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{{b}^{2}}\right)}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -2Initial program 82.9%
if -2 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 45.6%
*-commutative45.6%
Simplified45.6%
Taylor expanded in b around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
mul-1-neg89.0%
Simplified89.0%
Taylor expanded in c around 0 88.8%
Final simplification87.9%
(FPCore (a b c) :precision binary64 (* c (- (/ -1.0 b) (/ (* c a) (pow b 3.0)))))
double code(double a, double b, double c) {
return c * ((-1.0 / b) - ((c * a) / pow(b, 3.0)));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c * (((-1.0d0) / b) - ((c * a) / (b ** 3.0d0)))
end function
public static double code(double a, double b, double c) {
return c * ((-1.0 / b) - ((c * a) / Math.pow(b, 3.0)));
}
def code(a, b, c): return c * ((-1.0 / b) - ((c * a) / math.pow(b, 3.0)))
function code(a, b, c) return Float64(c * Float64(Float64(-1.0 / b) - Float64(Float64(c * a) / (b ^ 3.0)))) end
function tmp = code(a, b, c) tmp = c * ((-1.0 / b) - ((c * a) / (b ^ 3.0))); end
code[a_, b_, c_] := N[(c * N[(N[(-1.0 / b), $MachinePrecision] - N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \left(\frac{-1}{b} - \frac{c \cdot a}{{b}^{3}}\right)
\end{array}
Initial program 51.1%
*-commutative51.1%
Simplified51.1%
Taylor expanded in c around 0 84.4%
associate-*r/84.4%
neg-mul-184.4%
distribute-rgt-neg-in84.4%
Simplified84.4%
Final simplification84.4%
(FPCore (a b c) :precision binary64 (/ (* c (- -1.0 (/ (* c a) (pow b 2.0)))) b))
double code(double a, double b, double c) {
return (c * (-1.0 - ((c * a) / pow(b, 2.0)))) / 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 * ((-1.0d0) - ((c * a) / (b ** 2.0d0)))) / b
end function
public static double code(double a, double b, double c) {
return (c * (-1.0 - ((c * a) / Math.pow(b, 2.0)))) / b;
}
def code(a, b, c): return (c * (-1.0 - ((c * a) / math.pow(b, 2.0)))) / b
function code(a, b, c) return Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / (b ^ 2.0)))) / b) end
function tmp = code(a, b, c) tmp = (c * (-1.0 - ((c * a) / (b ^ 2.0)))) / b; end
code[a_, b_, c_] := N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot \left(-1 - \frac{c \cdot a}{{b}^{2}}\right)}{b}
\end{array}
Initial program 51.1%
*-commutative51.1%
Simplified51.1%
Taylor expanded in b around inf 84.6%
mul-1-neg84.6%
unsub-neg84.6%
mul-1-neg84.6%
Simplified84.6%
Taylor expanded in c around 0 84.5%
Final simplification84.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 / Float64(-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 51.1%
*-commutative51.1%
Simplified51.1%
Taylor expanded in b around inf 68.0%
associate-*r/68.0%
mul-1-neg68.0%
Simplified68.0%
Final simplification68.0%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 51.1%
*-commutative51.1%
Simplified51.1%
add-sqr-sqrt51.1%
difference-of-squares51.1%
associate-*l*51.1%
sqrt-prod51.1%
metadata-eval51.1%
associate-*l*51.1%
sqrt-prod51.1%
metadata-eval51.1%
Applied egg-rr51.1%
*-commutative51.1%
cancel-sign-sub-inv51.1%
metadata-eval51.1%
Simplified51.1%
Taylor expanded in b around inf 3.2%
associate-*r/3.2%
distribute-rgt-out3.2%
metadata-eval3.2%
mul0-rgt3.2%
metadata-eval3.2%
Simplified3.2%
Final simplification3.2%
herbie shell --seed 2024081
(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)))