
(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 11 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
(-
(*
a
(+
(* -5.0 (/ (* a (pow c 4.0)) (pow b 7.0)))
(* -2.0 (/ (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) {
return (a * ((a * ((-5.0 * ((a * pow(c, 4.0)) / pow(b, 7.0))) + (-2.0 * (pow(c, 3.0) / 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 * ((a * (((-5.0d0) * ((a * (c ** 4.0d0)) / (b ** 7.0d0))) + ((-2.0d0) * ((c ** 3.0d0) / (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 * ((a * ((-5.0 * ((a * Math.pow(c, 4.0)) / Math.pow(b, 7.0))) + (-2.0 * (Math.pow(c, 3.0) / Math.pow(b, 5.0))))) - (Math.pow(c, 2.0) / Math.pow(b, 3.0)))) - (c / b);
}
def code(a, b, c): return (a * ((a * ((-5.0 * ((a * math.pow(c, 4.0)) / math.pow(b, 7.0))) + (-2.0 * (math.pow(c, 3.0) / 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(a * Float64(Float64(-5.0 * Float64(Float64(a * (c ^ 4.0)) / (b ^ 7.0))) + Float64(-2.0 * Float64((c ^ 3.0) / (b ^ 5.0))))) - Float64((c ^ 2.0) / (b ^ 3.0)))) - Float64(c / b)) end
function tmp = code(a, b, c) tmp = (a * ((a * ((-5.0 * ((a * (c ^ 4.0)) / (b ^ 7.0))) + (-2.0 * ((c ^ 3.0) / (b ^ 5.0))))) - ((c ^ 2.0) / (b ^ 3.0)))) - (c / b); end
code[a_, b_, c_] := N[(N[(a * N[(N[(a * N[(N[(-5.0 * N[(N[(a * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] / N[Power[b, 5.0], $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(a \cdot \left(-5 \cdot \frac{a \cdot {c}^{4}}{{b}^{7}} + -2 \cdot \frac{{c}^{3}}{{b}^{5}}\right) - \frac{{c}^{2}}{{b}^{3}}\right) - \frac{c}{b}
\end{array}
Initial program 53.9%
*-commutative53.9%
Simplified53.9%
Taylor expanded in c around 0 92.5%
fma-neg92.5%
Simplified92.5%
Taylor expanded in a around 0 92.7%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -30.0)
(* (- b (sqrt (fma a (* c -4.0) (pow b 2.0)))) (/ 1.0 (* 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)) <= -30.0) {
tmp = (b - sqrt(fma(a, (c * -4.0), pow(b, 2.0)))) * (1.0 / (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)) <= -30.0) tmp = Float64(Float64(b - sqrt(fma(a, Float64(c * -4.0), (b ^ 2.0)))) * Float64(1.0 / 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], -30.0], N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a * -2.0), $MachinePrecision]), $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 -30:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right) \cdot \frac{1}{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)) < -30Initial program 87.9%
+-commutative87.9%
sqr-neg87.9%
unsub-neg87.9%
sqr-neg87.9%
sub-neg87.9%
+-commutative87.9%
*-commutative87.9%
associate-*r*87.9%
distribute-rgt-neg-in87.9%
fma-define88.0%
*-commutative88.0%
distribute-rgt-neg-in88.0%
metadata-eval88.0%
Simplified88.0%
frac-2neg88.0%
div-inv88.1%
sub-neg88.1%
distribute-neg-in88.1%
pow288.3%
add-sqr-sqrt0.0%
sqrt-unprod1.5%
sqr-neg1.5%
sqrt-prod1.5%
add-sqr-sqrt1.5%
add-sqr-sqrt0.0%
sqrt-unprod88.3%
sqr-neg88.3%
sqrt-prod85.6%
add-sqr-sqrt88.3%
distribute-rgt-neg-in88.3%
metadata-eval88.3%
Applied egg-rr88.3%
if -30 < (/.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 51.3%
*-commutative51.3%
Simplified51.3%
Taylor expanded in a around 0 92.0%
+-commutative92.0%
mul-1-neg92.0%
unsub-neg92.0%
mul-1-neg92.0%
unsub-neg92.0%
associate-/l*92.0%
Simplified92.0%
Final simplification91.7%
(FPCore (a b c)
:precision binary64
(*
c
(+
(*
c
(-
(*
c
(+
(* -5.0 (/ (* c (pow a 3.0)) (pow b 7.0)))
(* -2.0 (/ (pow a 2.0) (pow b 5.0)))))
(/ a (pow b 3.0))))
(/ -1.0 b))))
double code(double a, double b, double c) {
return c * ((c * ((c * ((-5.0 * ((c * pow(a, 3.0)) / pow(b, 7.0))) + (-2.0 * (pow(a, 2.0) / pow(b, 5.0))))) - (a / pow(b, 3.0)))) + (-1.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 * ((c * ((c * (((-5.0d0) * ((c * (a ** 3.0d0)) / (b ** 7.0d0))) + ((-2.0d0) * ((a ** 2.0d0) / (b ** 5.0d0))))) - (a / (b ** 3.0d0)))) + ((-1.0d0) / b))
end function
public static double code(double a, double b, double c) {
return c * ((c * ((c * ((-5.0 * ((c * Math.pow(a, 3.0)) / Math.pow(b, 7.0))) + (-2.0 * (Math.pow(a, 2.0) / Math.pow(b, 5.0))))) - (a / Math.pow(b, 3.0)))) + (-1.0 / b));
}
def code(a, b, c): return c * ((c * ((c * ((-5.0 * ((c * math.pow(a, 3.0)) / math.pow(b, 7.0))) + (-2.0 * (math.pow(a, 2.0) / math.pow(b, 5.0))))) - (a / math.pow(b, 3.0)))) + (-1.0 / b))
function code(a, b, c) return Float64(c * Float64(Float64(c * Float64(Float64(c * Float64(Float64(-5.0 * Float64(Float64(c * (a ^ 3.0)) / (b ^ 7.0))) + Float64(-2.0 * Float64((a ^ 2.0) / (b ^ 5.0))))) - Float64(a / (b ^ 3.0)))) + Float64(-1.0 / b))) end
function tmp = code(a, b, c) tmp = c * ((c * ((c * ((-5.0 * ((c * (a ^ 3.0)) / (b ^ 7.0))) + (-2.0 * ((a ^ 2.0) / (b ^ 5.0))))) - (a / (b ^ 3.0)))) + (-1.0 / b)); end
code[a_, b_, c_] := 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[(-2.0 * N[(N[Power[a, 2.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \left(c \cdot \left(c \cdot \left(-5 \cdot \frac{c \cdot {a}^{3}}{{b}^{7}} + -2 \cdot \frac{{a}^{2}}{{b}^{5}}\right) - \frac{a}{{b}^{3}}\right) + \frac{-1}{b}\right)
\end{array}
Initial program 53.9%
*-commutative53.9%
Simplified53.9%
Taylor expanded in c around 0 92.5%
fma-neg92.5%
Simplified92.5%
Taylor expanded in c around 0 92.5%
Final simplification92.5%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -30.0)
(* (- b (sqrt (fma a (* c -4.0) (pow b 2.0)))) (/ 1.0 (* a -2.0)))
(*
c
(+
(* c (- (* -2.0 (/ (* c (pow a 2.0)) (pow b 5.0))) (/ a (pow b 3.0))))
(/ -1.0 b)))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0)) <= -30.0) {
tmp = (b - sqrt(fma(a, (c * -4.0), pow(b, 2.0)))) * (1.0 / (a * -2.0));
} else {
tmp = c * ((c * ((-2.0 * ((c * pow(a, 2.0)) / pow(b, 5.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(a * 4.0)))) - b) / Float64(a * 2.0)) <= -30.0) tmp = Float64(Float64(b - sqrt(fma(a, Float64(c * -4.0), (b ^ 2.0)))) * Float64(1.0 / Float64(a * -2.0))); else tmp = Float64(c * Float64(Float64(c * Float64(Float64(-2.0 * Float64(Float64(c * (a ^ 2.0)) / (b ^ 5.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[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -30.0], N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c * N[(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] + N[(-1.0 / b), $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 -30:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)}\right) \cdot \frac{1}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(c \cdot \left(-2 \cdot \frac{c \cdot {a}^{2}}{{b}^{5}} - \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)) < -30Initial program 87.9%
+-commutative87.9%
sqr-neg87.9%
unsub-neg87.9%
sqr-neg87.9%
sub-neg87.9%
+-commutative87.9%
*-commutative87.9%
associate-*r*87.9%
distribute-rgt-neg-in87.9%
fma-define88.0%
*-commutative88.0%
distribute-rgt-neg-in88.0%
metadata-eval88.0%
Simplified88.0%
frac-2neg88.0%
div-inv88.1%
sub-neg88.1%
distribute-neg-in88.1%
pow288.3%
add-sqr-sqrt0.0%
sqrt-unprod1.5%
sqr-neg1.5%
sqrt-prod1.5%
add-sqr-sqrt1.5%
add-sqr-sqrt0.0%
sqrt-unprod88.3%
sqr-neg88.3%
sqrt-prod85.6%
add-sqr-sqrt88.3%
distribute-rgt-neg-in88.3%
metadata-eval88.3%
Applied egg-rr88.3%
if -30 < (/.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 51.3%
*-commutative51.3%
Simplified51.3%
Taylor expanded in c around 0 91.7%
Final simplification91.5%
(FPCore (a b c) :precision binary64 (if (<= b 3.8) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (- (/ (- c) b) (/ (* a (pow (/ c b) 2.0)) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.8) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - ((a * pow((c / b), 2.0)) / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 3.8) 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(Float64(a * (Float64(c / b) ^ 2.0)) / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 3.8], 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[(N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.8:\\
\;\;\;\;\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 \cdot {\left(\frac{c}{b}\right)}^{2}}{b}\\
\end{array}
\end{array}
if b < 3.7999999999999998Initial program 80.5%
*-commutative80.5%
+-commutative80.5%
sqr-neg80.5%
unsub-neg80.5%
sqr-neg80.5%
fma-neg80.7%
distribute-lft-neg-in80.7%
*-commutative80.7%
*-commutative80.7%
distribute-rgt-neg-in80.7%
metadata-eval80.7%
Simplified80.7%
if 3.7999999999999998 < b Initial program 47.5%
*-commutative47.5%
Simplified47.5%
Taylor expanded in b around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
mul-1-neg88.8%
Simplified88.8%
div-sub88.8%
associate-/l*88.8%
add-sqr-sqrt88.8%
pow288.8%
sqrt-div88.8%
sqrt-pow188.8%
metadata-eval88.8%
pow188.8%
sqrt-pow188.8%
metadata-eval88.8%
pow188.8%
Applied egg-rr88.8%
(FPCore (a b c) :precision binary64 (if (<= b 4.8) (/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0)) (- (/ (- c) b) (/ (* a (pow (/ c b) 2.0)) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.8) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - ((a * pow((c / b), 2.0)) / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 4.8) 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(Float64(a * (Float64(c / b) ^ 2.0)) / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 4.8], 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[(N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.8:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{a \cdot {\left(\frac{c}{b}\right)}^{2}}{b}\\
\end{array}
\end{array}
if b < 4.79999999999999982Initial program 80.5%
+-commutative80.5%
sqr-neg80.5%
unsub-neg80.5%
sqr-neg80.5%
sub-neg80.5%
+-commutative80.5%
*-commutative80.5%
associate-*r*80.5%
distribute-rgt-neg-in80.5%
fma-define80.5%
*-commutative80.5%
distribute-rgt-neg-in80.5%
metadata-eval80.5%
Simplified80.5%
if 4.79999999999999982 < b Initial program 47.5%
*-commutative47.5%
Simplified47.5%
Taylor expanded in b around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
mul-1-neg88.8%
Simplified88.8%
div-sub88.8%
associate-/l*88.8%
add-sqr-sqrt88.8%
pow288.8%
sqrt-div88.8%
sqrt-pow188.8%
metadata-eval88.8%
pow188.8%
sqrt-pow188.8%
metadata-eval88.8%
pow188.8%
Applied egg-rr88.8%
(FPCore (a b c) :precision binary64 (if (<= b 3.9) (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) (- (/ (- c) b) (/ (* a (pow (/ c b) 2.0)) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.9) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - ((a * pow((c / 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) :: tmp
if (b <= 3.9d0) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = (-c / b) - ((a * ((c / b) ** 2.0d0)) / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 3.9) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - ((a * Math.pow((c / b), 2.0)) / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.9: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = (-c / b) - ((a * math.pow((c / b), 2.0)) / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.9) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(Float64(a * (Float64(c / b) ^ 2.0)) / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3.9) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = (-c / b) - ((a * ((c / b) ^ 2.0)) / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.9], 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[(N[((-c) / b), $MachinePrecision] - N[(N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.9:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{a \cdot {\left(\frac{c}{b}\right)}^{2}}{b}\\
\end{array}
\end{array}
if b < 3.89999999999999991Initial program 80.5%
if 3.89999999999999991 < b Initial program 47.5%
*-commutative47.5%
Simplified47.5%
Taylor expanded in b around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
mul-1-neg88.8%
Simplified88.8%
div-sub88.8%
associate-/l*88.8%
add-sqr-sqrt88.8%
pow288.8%
sqrt-div88.8%
sqrt-pow188.8%
metadata-eval88.8%
pow188.8%
sqrt-pow188.8%
metadata-eval88.8%
pow188.8%
Applied egg-rr88.8%
Final simplification87.2%
(FPCore (a b c) :precision binary64 (- (/ (- c) b) (/ (* a (pow (/ c b) 2.0)) b)))
double code(double a, double b, double c) {
return (-c / b) - ((a * pow((c / 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 / b) - ((a * ((c / b) ** 2.0d0)) / b)
end function
public static double code(double a, double b, double c) {
return (-c / b) - ((a * Math.pow((c / b), 2.0)) / b);
}
def code(a, b, c): return (-c / b) - ((a * math.pow((c / b), 2.0)) / b)
function code(a, b, c) return Float64(Float64(Float64(-c) / b) - Float64(Float64(a * (Float64(c / b) ^ 2.0)) / b)) end
function tmp = code(a, b, c) tmp = (-c / b) - ((a * ((c / b) ^ 2.0)) / b); end
code[a_, b_, c_] := N[(N[((-c) / b), $MachinePrecision] - N[(N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-c}{b} - \frac{a \cdot {\left(\frac{c}{b}\right)}^{2}}{b}
\end{array}
Initial program 53.9%
*-commutative53.9%
Simplified53.9%
Taylor expanded in b around inf 83.5%
mul-1-neg83.5%
unsub-neg83.5%
mul-1-neg83.5%
Simplified83.5%
div-sub83.6%
associate-/l*83.6%
add-sqr-sqrt83.6%
pow283.6%
sqrt-div83.6%
sqrt-pow183.6%
metadata-eval83.6%
pow183.6%
sqrt-pow183.6%
metadata-eval83.6%
pow183.6%
Applied egg-rr83.6%
(FPCore (a b c) :precision binary64 (/ (- (- c) (* a (pow (/ c b) 2.0))) b))
double code(double a, double b, double c) {
return (-c - (a * pow((c / 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 - (a * ((c / b) ** 2.0d0))) / b
end function
public static double code(double a, double b, double c) {
return (-c - (a * Math.pow((c / b), 2.0))) / b;
}
def code(a, b, c): return (-c - (a * math.pow((c / b), 2.0))) / b
function code(a, b, c) return Float64(Float64(Float64(-c) - Float64(a * (Float64(c / b) ^ 2.0))) / b) end
function tmp = code(a, b, c) tmp = (-c - (a * ((c / b) ^ 2.0))) / b; end
code[a_, b_, c_] := N[(N[((-c) - N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-c\right) - a \cdot {\left(\frac{c}{b}\right)}^{2}}{b}
\end{array}
Initial program 53.9%
*-commutative53.9%
Simplified53.9%
Taylor expanded in b around inf 83.5%
mul-1-neg83.5%
unsub-neg83.5%
mul-1-neg83.5%
Simplified83.5%
associate-/l*83.5%
add-sqr-sqrt83.5%
pow283.5%
sqrt-div83.5%
sqrt-pow183.5%
metadata-eval83.5%
pow183.5%
sqrt-pow183.5%
metadata-eval83.5%
pow183.5%
Applied egg-rr83.5%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* c (/ a b)))) (/ (/ (* -2.0 (+ (* c a) (* t_0 t_0))) b) (* a 2.0))))
double code(double a, double b, double c) {
double t_0 = c * (a / b);
return ((-2.0 * ((c * a) + (t_0 * t_0))) / b) / (a * 2.0);
}
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
t_0 = c * (a / b)
code = (((-2.0d0) * ((c * a) + (t_0 * t_0))) / b) / (a * 2.0d0)
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a / b);
return ((-2.0 * ((c * a) + (t_0 * t_0))) / b) / (a * 2.0);
}
def code(a, b, c): t_0 = c * (a / b) return ((-2.0 * ((c * a) + (t_0 * t_0))) / b) / (a * 2.0)
function code(a, b, c) t_0 = Float64(c * Float64(a / b)) return Float64(Float64(Float64(-2.0 * Float64(Float64(c * a) + Float64(t_0 * t_0))) / b) / Float64(a * 2.0)) end
function tmp = code(a, b, c) t_0 = c * (a / b); tmp = ((-2.0 * ((c * a) + (t_0 * t_0))) / b) / (a * 2.0); end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(-2.0 * N[(N[(c * a), $MachinePrecision] + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \frac{a}{b}\\
\frac{\frac{-2 \cdot \left(c \cdot a + t\_0 \cdot t\_0\right)}{b}}{a \cdot 2}
\end{array}
\end{array}
Initial program 53.9%
*-commutative53.9%
Simplified53.9%
Taylor expanded in b around inf 83.3%
distribute-lft-out83.3%
associate-/l*83.3%
Simplified83.3%
Taylor expanded in a around 0 83.3%
associate-/l*83.3%
unpow283.3%
unpow283.3%
unpow283.3%
times-frac83.3%
swap-sqr83.3%
unpow283.3%
associate-*r/83.3%
*-commutative83.3%
associate-/l*83.3%
Simplified83.3%
unpow283.3%
Applied egg-rr83.3%
Final simplification83.3%
(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 53.9%
*-commutative53.9%
Simplified53.9%
Taylor expanded in b around inf 65.8%
associate-*r/65.8%
mul-1-neg65.8%
Simplified65.8%
herbie shell --seed 2024089
(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)))