
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -0.91)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(*
c
(+
(*
c
(-
(*
c
(+
(* -5.0 (/ (* c (pow a 3.0)) (pow b 7.0)))
(* (/ (pow a 2.0) (pow b 5.0)) -2.0)))
(/ a (pow b 3.0))))
(/ -1.0 b)))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -0.91) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = c * ((c * ((c * ((-5.0 * ((c * pow(a, 3.0)) / pow(b, 7.0))) + ((pow(a, 2.0) / pow(b, 5.0)) * -2.0))) - (a / pow(b, 3.0)))) + (-1.0 / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -0.91) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(c * Float64(Float64(c * Float64(Float64(c * Float64(Float64(-5.0 * Float64(Float64(c * (a ^ 3.0)) / (b ^ 7.0))) + Float64(Float64((a ^ 2.0) / (b ^ 5.0)) * -2.0))) - Float64(a / (b ^ 3.0)))) + Float64(-1.0 / b))); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -0.91], 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[(c * N[(N[(c * N[(N[(-5.0 * N[(N[(c * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[a, 2.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.91:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(c \cdot \left(c \cdot \left(-5 \cdot \frac{c \cdot {a}^{3}}{{b}^{7}} + \frac{{a}^{2}}{{b}^{5}} \cdot -2\right) - \frac{a}{{b}^{3}}\right) + \frac{-1}{b}\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)) < -0.910000000000000031Initial program 85.5%
*-commutative85.5%
+-commutative85.5%
sqr-neg85.5%
unsub-neg85.5%
sqr-neg85.5%
fma-neg85.8%
distribute-lft-neg-in85.8%
*-commutative85.8%
*-commutative85.8%
distribute-rgt-neg-in85.8%
metadata-eval85.8%
Simplified85.8%
if -0.910000000000000031 < (/.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 52.0%
*-commutative52.0%
+-commutative52.0%
sqr-neg52.0%
unsub-neg52.0%
sqr-neg52.0%
fma-neg52.1%
distribute-lft-neg-in52.1%
*-commutative52.1%
*-commutative52.1%
distribute-rgt-neg-in52.1%
metadata-eval52.1%
Simplified52.1%
Taylor expanded in a around 0 93.2%
Taylor expanded in c around -inf 93.2%
expm1-log1p-u93.2%
expm1-undefine67.0%
Applied egg-rr67.0%
expm1-define93.2%
Simplified93.2%
Taylor expanded in c around 0 93.0%
Final simplification91.7%
(FPCore (a b c)
:precision binary64
(-
(*
(pow c 4.0)
(-
(* -5.0 (/ (pow a 3.0) (pow b 7.0)))
(/ (+ (* 2.0 (/ (pow a 2.0) (pow b 5.0))) (/ a (* c (pow b 3.0)))) c)))
(/ c b)))
double code(double a, double b, double c) {
return (pow(c, 4.0) * ((-5.0 * (pow(a, 3.0) / pow(b, 7.0))) - (((2.0 * (pow(a, 2.0) / pow(b, 5.0))) + (a / (c * pow(b, 3.0)))) / c))) - (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 ** 4.0d0) * (((-5.0d0) * ((a ** 3.0d0) / (b ** 7.0d0))) - (((2.0d0 * ((a ** 2.0d0) / (b ** 5.0d0))) + (a / (c * (b ** 3.0d0)))) / c))) - (c / b)
end function
public static double code(double a, double b, double c) {
return (Math.pow(c, 4.0) * ((-5.0 * (Math.pow(a, 3.0) / Math.pow(b, 7.0))) - (((2.0 * (Math.pow(a, 2.0) / Math.pow(b, 5.0))) + (a / (c * Math.pow(b, 3.0)))) / c))) - (c / b);
}
def code(a, b, c): return (math.pow(c, 4.0) * ((-5.0 * (math.pow(a, 3.0) / math.pow(b, 7.0))) - (((2.0 * (math.pow(a, 2.0) / math.pow(b, 5.0))) + (a / (c * math.pow(b, 3.0)))) / c))) - (c / b)
function code(a, b, c) return Float64(Float64((c ^ 4.0) * Float64(Float64(-5.0 * Float64((a ^ 3.0) / (b ^ 7.0))) - Float64(Float64(Float64(2.0 * Float64((a ^ 2.0) / (b ^ 5.0))) + Float64(a / Float64(c * (b ^ 3.0)))) / c))) - Float64(c / b)) end
function tmp = code(a, b, c) tmp = ((c ^ 4.0) * ((-5.0 * ((a ^ 3.0) / (b ^ 7.0))) - (((2.0 * ((a ^ 2.0) / (b ^ 5.0))) + (a / (c * (b ^ 3.0)))) / c))) - (c / b); end
code[a_, b_, c_] := N[(N[(N[Power[c, 4.0], $MachinePrecision] * N[(N[(-5.0 * N[(N[Power[a, 3.0], $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(2.0 * N[(N[Power[a, 2.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a / N[(c * N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{c}^{4} \cdot \left(-5 \cdot \frac{{a}^{3}}{{b}^{7}} - \frac{2 \cdot \frac{{a}^{2}}{{b}^{5}} + \frac{a}{c \cdot {b}^{3}}}{c}\right) - \frac{c}{b}
\end{array}
Initial program 58.1%
*-commutative58.1%
+-commutative58.1%
sqr-neg58.1%
unsub-neg58.1%
sqr-neg58.1%
fma-neg58.2%
distribute-lft-neg-in58.2%
*-commutative58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
Taylor expanded in a around 0 90.3%
Taylor expanded in c around -inf 90.3%
associate-*r/90.3%
neg-mul-190.3%
Applied egg-rr90.3%
Final simplification90.3%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -0.91)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(/
(/ 1.0 a)
(/ (fma a (+ (/ 1.0 b) (/ (* c a) (pow b 3.0))) (/ b (- c))) a))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -0.91) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (1.0 / a) / (fma(a, ((1.0 / b) + ((c * a) / pow(b, 3.0))), (b / -c)) / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -0.91) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(1.0 / a) / Float64(fma(a, Float64(Float64(1.0 / b) + Float64(Float64(c * a) / (b ^ 3.0))), Float64(b / Float64(-c))) / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -0.91], 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[(1.0 / a), $MachinePrecision] / N[(N[(a * N[(N[(1.0 / b), $MachinePrecision] + N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b / (-c)), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.91:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{a}}{\frac{\mathsf{fma}\left(a, \frac{1}{b} + \frac{c \cdot a}{{b}^{3}}, \frac{b}{-c}\right)}{a}}\\
\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)) < -0.910000000000000031Initial program 85.5%
*-commutative85.5%
+-commutative85.5%
sqr-neg85.5%
unsub-neg85.5%
sqr-neg85.5%
fma-neg85.8%
distribute-lft-neg-in85.8%
*-commutative85.8%
*-commutative85.8%
distribute-rgt-neg-in85.8%
metadata-eval85.8%
Simplified85.8%
if -0.910000000000000031 < (/.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 52.0%
*-commutative52.0%
+-commutative52.0%
sqr-neg52.0%
unsub-neg52.0%
sqr-neg52.0%
fma-neg52.1%
distribute-lft-neg-in52.1%
*-commutative52.1%
*-commutative52.1%
distribute-rgt-neg-in52.1%
metadata-eval52.1%
Simplified52.1%
Taylor expanded in c around 0 90.8%
clear-num90.6%
inv-pow90.6%
Applied egg-rr90.6%
unpow-190.6%
associate-/l*90.6%
associate-/r*90.6%
associate-/r*90.6%
associate-*r*90.6%
*-commutative90.6%
associate-*l/90.6%
Simplified90.6%
Taylor expanded in a around 0 91.1%
Simplified91.1%
Final simplification90.2%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -0.91)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(/
(/ 1.0 a)
(* b (+ (+ (/ (/ 1.0 b) b) (* a (/ c (pow b 4.0)))) (/ -1.0 (* c a)))))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -0.91) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (1.0 / a) / (b * ((((1.0 / b) / b) + (a * (c / pow(b, 4.0)))) + (-1.0 / (c * a))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -0.91) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(1.0 / a) / Float64(b * Float64(Float64(Float64(Float64(1.0 / b) / b) + Float64(a * Float64(c / (b ^ 4.0)))) + Float64(-1.0 / Float64(c * a))))); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -0.91], 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[(1.0 / a), $MachinePrecision] / N[(b * N[(N[(N[(N[(1.0 / b), $MachinePrecision] / b), $MachinePrecision] + N[(a * N[(c / N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.91:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{a}}{b \cdot \left(\left(\frac{\frac{1}{b}}{b} + a \cdot \frac{c}{{b}^{4}}\right) + \frac{-1}{c \cdot a}\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)) < -0.910000000000000031Initial program 85.5%
*-commutative85.5%
+-commutative85.5%
sqr-neg85.5%
unsub-neg85.5%
sqr-neg85.5%
fma-neg85.8%
distribute-lft-neg-in85.8%
*-commutative85.8%
*-commutative85.8%
distribute-rgt-neg-in85.8%
metadata-eval85.8%
Simplified85.8%
if -0.910000000000000031 < (/.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 52.0%
*-commutative52.0%
+-commutative52.0%
sqr-neg52.0%
unsub-neg52.0%
sqr-neg52.0%
fma-neg52.1%
distribute-lft-neg-in52.1%
*-commutative52.1%
*-commutative52.1%
distribute-rgt-neg-in52.1%
metadata-eval52.1%
Simplified52.1%
Taylor expanded in c around 0 90.8%
clear-num90.6%
inv-pow90.6%
Applied egg-rr90.6%
unpow-190.6%
associate-/l*90.6%
associate-/r*90.6%
associate-/r*90.6%
associate-*r*90.6%
*-commutative90.6%
associate-*l/90.6%
Simplified90.6%
Taylor expanded in b around inf 91.1%
sub-neg91.1%
+-commutative91.1%
mul-1-neg91.1%
distribute-lft1-in91.1%
metadata-eval91.1%
associate-*r/91.1%
mul-1-neg91.1%
remove-double-neg91.1%
associate-/l*91.1%
distribute-neg-frac91.1%
metadata-eval91.1%
*-commutative91.1%
Simplified91.1%
inv-pow91.1%
unpow291.1%
unpow-prod-down91.1%
inv-pow91.1%
inv-pow91.1%
Applied egg-rr91.1%
associate-*l/91.1%
*-lft-identity91.1%
Simplified91.1%
Final simplification90.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0))))
(if (<= t_0 -0.91)
t_0
(/
(/ 1.0 a)
(*
b
(+ (+ (/ (/ 1.0 b) b) (* a (/ c (pow b 4.0)))) (/ -1.0 (* c a))))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.91) {
tmp = t_0;
} else {
tmp = (1.0 / a) / (b * ((((1.0 / b) / b) + (a * (c / pow(b, 4.0)))) + (-1.0 / (c * 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) - (c * (4.0d0 * a)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.91d0)) then
tmp = t_0
else
tmp = (1.0d0 / a) / (b * ((((1.0d0 / b) / b) + (a * (c / (b ** 4.0d0)))) + ((-1.0d0) / (c * a))))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.91) {
tmp = t_0;
} else {
tmp = (1.0 / a) / (b * ((((1.0 / b) / b) + (a * (c / Math.pow(b, 4.0)))) + (-1.0 / (c * a))));
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -0.91: tmp = t_0 else: tmp = (1.0 / a) / (b * ((((1.0 / b) / b) + (a * (c / math.pow(b, 4.0)))) + (-1.0 / (c * a)))) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.91) tmp = t_0; else tmp = Float64(Float64(1.0 / a) / Float64(b * Float64(Float64(Float64(Float64(1.0 / b) / b) + Float64(a * Float64(c / (b ^ 4.0)))) + Float64(-1.0 / Float64(c * a))))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -0.91) tmp = t_0; else tmp = (1.0 / a) / (b * ((((1.0 / b) / b) + (a * (c / (b ^ 4.0)))) + (-1.0 / (c * a)))); 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[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.91], t$95$0, N[(N[(1.0 / a), $MachinePrecision] / N[(b * N[(N[(N[(N[(1.0 / b), $MachinePrecision] / b), $MachinePrecision] + N[(a * N[(c / N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.91:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{a}}{b \cdot \left(\left(\frac{\frac{1}{b}}{b} + a \cdot \frac{c}{{b}^{4}}\right) + \frac{-1}{c \cdot a}\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)) < -0.910000000000000031Initial program 85.5%
if -0.910000000000000031 < (/.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 52.0%
*-commutative52.0%
+-commutative52.0%
sqr-neg52.0%
unsub-neg52.0%
sqr-neg52.0%
fma-neg52.1%
distribute-lft-neg-in52.1%
*-commutative52.1%
*-commutative52.1%
distribute-rgt-neg-in52.1%
metadata-eval52.1%
Simplified52.1%
Taylor expanded in c around 0 90.8%
clear-num90.6%
inv-pow90.6%
Applied egg-rr90.6%
unpow-190.6%
associate-/l*90.6%
associate-/r*90.6%
associate-/r*90.6%
associate-*r*90.6%
*-commutative90.6%
associate-*l/90.6%
Simplified90.6%
Taylor expanded in b around inf 91.1%
sub-neg91.1%
+-commutative91.1%
mul-1-neg91.1%
distribute-lft1-in91.1%
metadata-eval91.1%
associate-*r/91.1%
mul-1-neg91.1%
remove-double-neg91.1%
associate-/l*91.1%
distribute-neg-frac91.1%
metadata-eval91.1%
*-commutative91.1%
Simplified91.1%
inv-pow91.1%
unpow291.1%
unpow-prod-down91.1%
inv-pow91.1%
inv-pow91.1%
Applied egg-rr91.1%
associate-*l/91.1%
*-lft-identity91.1%
Simplified91.1%
Final simplification90.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0))))
(if (<= t_0 -0.0035)
t_0
(/ (/ 1.0 a) (* b (+ (/ 1.0 (pow b 2.0)) (/ -1.0 (* c a))))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0035) {
tmp = t_0;
} else {
tmp = (1.0 / a) / (b * ((1.0 / pow(b, 2.0)) + (-1.0 / (c * 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) - (c * (4.0d0 * a)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.0035d0)) then
tmp = t_0
else
tmp = (1.0d0 / a) / (b * ((1.0d0 / (b ** 2.0d0)) + ((-1.0d0) / (c * a))))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0035) {
tmp = t_0;
} else {
tmp = (1.0 / a) / (b * ((1.0 / Math.pow(b, 2.0)) + (-1.0 / (c * a))));
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -0.0035: tmp = t_0 else: tmp = (1.0 / a) / (b * ((1.0 / math.pow(b, 2.0)) + (-1.0 / (c * a)))) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.0035) tmp = t_0; else tmp = Float64(Float64(1.0 / a) / Float64(b * Float64(Float64(1.0 / (b ^ 2.0)) + Float64(-1.0 / Float64(c * a))))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -0.0035) tmp = t_0; else tmp = (1.0 / a) / (b * ((1.0 / (b ^ 2.0)) + (-1.0 / (c * a)))); 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[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.0035], t$95$0, N[(N[(1.0 / a), $MachinePrecision] / N[(b * N[(N[(1.0 / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.0035:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{a}}{b \cdot \left(\frac{1}{{b}^{2}} + \frac{-1}{c \cdot a}\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)) < -0.00350000000000000007Initial program 79.5%
if -0.00350000000000000007 < (/.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 44.8%
*-commutative44.8%
+-commutative44.8%
sqr-neg44.8%
unsub-neg44.8%
sqr-neg44.8%
fma-neg44.8%
distribute-lft-neg-in44.8%
*-commutative44.8%
*-commutative44.8%
distribute-rgt-neg-in44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in c around 0 94.8%
clear-num94.7%
inv-pow94.7%
Applied egg-rr94.7%
unpow-194.7%
associate-/l*94.6%
associate-/r*94.7%
associate-/r*94.6%
associate-*r*94.6%
*-commutative94.6%
associate-*l/94.6%
Simplified94.6%
Taylor expanded in b around inf 91.4%
*-commutative91.4%
Simplified91.4%
Final simplification86.8%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)))) (if (<= t_0 -0.0035) t_0 (/ (/ 1.0 a) (/ (- (/ a b) (/ b c)) a)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0035) {
tmp = t_0;
} else {
tmp = (1.0 / a) / (((a / b) - (b / c)) / 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) - (c * (4.0d0 * a)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.0035d0)) then
tmp = t_0
else
tmp = (1.0d0 / a) / (((a / b) - (b / c)) / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0035) {
tmp = t_0;
} else {
tmp = (1.0 / a) / (((a / b) - (b / c)) / a);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -0.0035: tmp = t_0 else: tmp = (1.0 / a) / (((a / b) - (b / c)) / a) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.0035) tmp = t_0; else tmp = Float64(Float64(1.0 / a) / Float64(Float64(Float64(a / b) - Float64(b / c)) / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -0.0035) tmp = t_0; else tmp = (1.0 / a) / (((a / b) - (b / c)) / a); 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[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.0035], t$95$0, N[(N[(1.0 / a), $MachinePrecision] / N[(N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.0035:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{a}}{\frac{\frac{a}{b} - \frac{b}{c}}{a}}\\
\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)) < -0.00350000000000000007Initial program 79.5%
if -0.00350000000000000007 < (/.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 44.8%
*-commutative44.8%
+-commutative44.8%
sqr-neg44.8%
unsub-neg44.8%
sqr-neg44.8%
fma-neg44.8%
distribute-lft-neg-in44.8%
*-commutative44.8%
*-commutative44.8%
distribute-rgt-neg-in44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in c around 0 94.8%
clear-num94.7%
inv-pow94.7%
Applied egg-rr94.7%
unpow-194.7%
associate-/l*94.6%
associate-/r*94.7%
associate-/r*94.6%
associate-*r*94.6%
*-commutative94.6%
associate-*l/94.6%
Simplified94.6%
Taylor expanded in a around 0 91.4%
+-commutative91.4%
mul-1-neg91.4%
unsub-neg91.4%
Simplified91.4%
Final simplification86.8%
(FPCore (a b c) :precision binary64 (/ (/ 1.0 a) (/ (- (/ c b) (/ b a)) c)))
double code(double a, double b, double c) {
return (1.0 / a) / (((c / b) - (b / a)) / c);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (1.0d0 / a) / (((c / b) - (b / a)) / c)
end function
public static double code(double a, double b, double c) {
return (1.0 / a) / (((c / b) - (b / a)) / c);
}
def code(a, b, c): return (1.0 / a) / (((c / b) - (b / a)) / c)
function code(a, b, c) return Float64(Float64(1.0 / a) / Float64(Float64(Float64(c / b) - Float64(b / a)) / c)) end
function tmp = code(a, b, c) tmp = (1.0 / a) / (((c / b) - (b / a)) / c); end
code[a_, b_, c_] := N[(N[(1.0 / a), $MachinePrecision] / N[(N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{a}}{\frac{\frac{c}{b} - \frac{b}{a}}{c}}
\end{array}
Initial program 58.1%
*-commutative58.1%
+-commutative58.1%
sqr-neg58.1%
unsub-neg58.1%
sqr-neg58.1%
fma-neg58.2%
distribute-lft-neg-in58.2%
*-commutative58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
Taylor expanded in c around 0 86.6%
clear-num86.5%
inv-pow86.5%
Applied egg-rr86.5%
unpow-186.5%
associate-/l*86.4%
associate-/r*86.5%
associate-/r*86.5%
associate-*r*86.5%
*-commutative86.5%
associate-*l/86.5%
Simplified86.5%
Taylor expanded in c around 0 80.6%
+-commutative80.6%
mul-1-neg80.6%
unsub-neg80.6%
Simplified80.6%
(FPCore (a b c) :precision binary64 (/ (/ 1.0 a) (/ (- (/ a b) (/ b c)) a)))
double code(double a, double b, double c) {
return (1.0 / a) / (((a / b) - (b / c)) / a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (1.0d0 / a) / (((a / b) - (b / c)) / a)
end function
public static double code(double a, double b, double c) {
return (1.0 / a) / (((a / b) - (b / c)) / a);
}
def code(a, b, c): return (1.0 / a) / (((a / b) - (b / c)) / a)
function code(a, b, c) return Float64(Float64(1.0 / a) / Float64(Float64(Float64(a / b) - Float64(b / c)) / a)) end
function tmp = code(a, b, c) tmp = (1.0 / a) / (((a / b) - (b / c)) / a); end
code[a_, b_, c_] := N[(N[(1.0 / a), $MachinePrecision] / N[(N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{a}}{\frac{\frac{a}{b} - \frac{b}{c}}{a}}
\end{array}
Initial program 58.1%
*-commutative58.1%
+-commutative58.1%
sqr-neg58.1%
unsub-neg58.1%
sqr-neg58.1%
fma-neg58.2%
distribute-lft-neg-in58.2%
*-commutative58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
Taylor expanded in c around 0 86.6%
clear-num86.5%
inv-pow86.5%
Applied egg-rr86.5%
unpow-186.5%
associate-/l*86.4%
associate-/r*86.5%
associate-/r*86.5%
associate-*r*86.5%
*-commutative86.5%
associate-*l/86.5%
Simplified86.5%
Taylor expanded in a around 0 80.5%
+-commutative80.5%
mul-1-neg80.5%
unsub-neg80.5%
Simplified80.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 58.1%
*-commutative58.1%
+-commutative58.1%
sqr-neg58.1%
unsub-neg58.1%
sqr-neg58.1%
fma-neg58.2%
distribute-lft-neg-in58.2%
*-commutative58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
Taylor expanded in b around inf 62.4%
associate-*r/62.4%
mul-1-neg62.4%
Simplified62.4%
Final simplification62.4%
herbie shell --seed 2024129
(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)))