
(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 9 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
(fma
-5.0
(* a (/ (pow c 4.0) (pow b 6.0)))
(* -2.0 (/ (pow c 3.0) (pow b 4.0)))))
(* (/ c b) (/ c b))))
c)
b))
double code(double a, double b, double c) {
return ((a * ((a * fma(-5.0, (a * (pow(c, 4.0) / pow(b, 6.0))), (-2.0 * (pow(c, 3.0) / pow(b, 4.0))))) - ((c / b) * (c / b)))) - c) / b;
}
function code(a, b, c) return Float64(Float64(Float64(a * Float64(Float64(a * fma(-5.0, Float64(a * Float64((c ^ 4.0) / (b ^ 6.0))), Float64(-2.0 * Float64((c ^ 3.0) / (b ^ 4.0))))) - Float64(Float64(c / b) * Float64(c / b)))) - c) / b) end
code[a_, b_, c_] := N[(N[(N[(a * N[(N[(a * N[(-5.0 * N[(a * N[(N[Power[c, 4.0], $MachinePrecision] / N[Power[b, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] / N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c / b), $MachinePrecision] * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - c), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot \left(a \cdot \mathsf{fma}\left(-5, a \cdot \frac{{c}^{4}}{{b}^{6}}, -2 \cdot \frac{{c}^{3}}{{b}^{4}}\right) - \frac{c}{b} \cdot \frac{c}{b}\right) - c}{b}
\end{array}
Initial program 31.6%
+-commutative31.6%
sqr-neg31.6%
unsub-neg31.6%
sqr-neg31.6%
sub-neg31.6%
+-commutative31.6%
*-commutative31.6%
associate-*r*31.6%
distribute-rgt-neg-in31.6%
fma-define31.6%
*-commutative31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in a around 0 95.7%
+-commutative95.7%
mul-1-neg95.7%
unsub-neg95.7%
Simplified95.7%
Taylor expanded in b around inf 95.7%
Taylor expanded in a around 0 95.7%
+-commutative95.7%
mul-1-neg95.7%
unsub-neg95.7%
fma-define95.7%
associate-/l*95.7%
unpow295.7%
unpow295.7%
times-frac95.7%
unpow295.7%
Simplified95.7%
unpow295.7%
Applied egg-rr95.7%
(FPCore (a b c)
:precision binary64
(-
(*
a
(*
(pow c 2.0)
(+
(*
c
(* a (+ (* -5.0 (/ (* a c) (pow b 7.0))) (* 2.0 (/ -1.0 (pow b 5.0))))))
(/ -1.0 (pow b 3.0)))))
(/ c b)))
double code(double a, double b, double c) {
return (a * (pow(c, 2.0) * ((c * (a * ((-5.0 * ((a * c) / pow(b, 7.0))) + (2.0 * (-1.0 / pow(b, 5.0)))))) + (-1.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 ** 2.0d0) * ((c * (a * (((-5.0d0) * ((a * c) / (b ** 7.0d0))) + (2.0d0 * ((-1.0d0) / (b ** 5.0d0)))))) + ((-1.0d0) / (b ** 3.0d0))))) - (c / b)
end function
public static double code(double a, double b, double c) {
return (a * (Math.pow(c, 2.0) * ((c * (a * ((-5.0 * ((a * c) / Math.pow(b, 7.0))) + (2.0 * (-1.0 / Math.pow(b, 5.0)))))) + (-1.0 / Math.pow(b, 3.0))))) - (c / b);
}
def code(a, b, c): return (a * (math.pow(c, 2.0) * ((c * (a * ((-5.0 * ((a * c) / math.pow(b, 7.0))) + (2.0 * (-1.0 / math.pow(b, 5.0)))))) + (-1.0 / math.pow(b, 3.0))))) - (c / b)
function code(a, b, c) return Float64(Float64(a * Float64((c ^ 2.0) * Float64(Float64(c * Float64(a * Float64(Float64(-5.0 * Float64(Float64(a * c) / (b ^ 7.0))) + Float64(2.0 * Float64(-1.0 / (b ^ 5.0)))))) + Float64(-1.0 / (b ^ 3.0))))) - Float64(c / b)) end
function tmp = code(a, b, c) tmp = (a * ((c ^ 2.0) * ((c * (a * ((-5.0 * ((a * c) / (b ^ 7.0))) + (2.0 * (-1.0 / (b ^ 5.0)))))) + (-1.0 / (b ^ 3.0))))) - (c / b); end
code[a_, b_, c_] := N[(N[(a * N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(c * N[(a * N[(N[(-5.0 * N[(N[(a * c), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(-1.0 / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot \left({c}^{2} \cdot \left(c \cdot \left(a \cdot \left(-5 \cdot \frac{a \cdot c}{{b}^{7}} + 2 \cdot \frac{-1}{{b}^{5}}\right)\right) + \frac{-1}{{b}^{3}}\right)\right) - \frac{c}{b}
\end{array}
Initial program 31.6%
+-commutative31.6%
sqr-neg31.6%
unsub-neg31.6%
sqr-neg31.6%
sub-neg31.6%
+-commutative31.6%
*-commutative31.6%
associate-*r*31.6%
distribute-rgt-neg-in31.6%
fma-define31.6%
*-commutative31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in a around 0 95.7%
+-commutative95.7%
mul-1-neg95.7%
unsub-neg95.7%
Simplified95.7%
Taylor expanded in c around 0 95.7%
Taylor expanded in a around 0 95.7%
Final simplification95.7%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -5.0) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (/ (+ c (* a (pow (/ c 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)) <= -5.0) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (c + (a * pow((c / 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)) <= -5.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(c + Float64(a * (Float64(c / b) ^ 2.0))) / Float64(-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.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[(a * N[Power[N[(c / b), $MachinePrecision], 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 -5:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c + a \cdot {\left(\frac{c}{b}\right)}^{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)) < -5Initial program 77.3%
*-commutative77.3%
+-commutative77.3%
sqr-neg77.3%
unsub-neg77.3%
sqr-neg77.3%
fma-neg77.4%
distribute-lft-neg-in77.4%
*-commutative77.4%
*-commutative77.4%
distribute-rgt-neg-in77.4%
metadata-eval77.4%
Simplified77.4%
if -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 25.3%
+-commutative25.3%
sqr-neg25.3%
unsub-neg25.3%
sqr-neg25.3%
sub-neg25.3%
+-commutative25.3%
*-commutative25.3%
associate-*r*25.3%
distribute-rgt-neg-in25.3%
fma-define25.3%
*-commutative25.3%
distribute-rgt-neg-in25.3%
metadata-eval25.3%
Simplified25.3%
Taylor expanded in a around 0 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Taylor expanded in b around inf 94.6%
sub-neg94.6%
+-commutative94.6%
neg-mul-194.6%
distribute-lft-out94.6%
associate-*r/94.6%
associate-*r/94.6%
+-commutative94.6%
remove-double-neg94.6%
sub-neg94.6%
associate-*r/94.6%
neg-mul-194.6%
associate-*r/94.6%
Simplified94.6%
fma-undefine94.6%
Applied egg-rr94.6%
Final simplification92.6%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -5.0) (/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0)) (/ (+ c (* a (pow (/ c 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)) <= -5.0) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = (c + (a * pow((c / 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)) <= -5.0) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(c + Float64(a * (Float64(c / b) ^ 2.0))) / Float64(-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.0], 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 + N[(a * N[Power[N[(c / b), $MachinePrecision], 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 -5:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c + a \cdot {\left(\frac{c}{b}\right)}^{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)) < -5Initial program 77.3%
+-commutative77.3%
sqr-neg77.3%
unsub-neg77.3%
sqr-neg77.3%
sub-neg77.3%
+-commutative77.3%
*-commutative77.3%
associate-*r*77.3%
distribute-rgt-neg-in77.3%
fma-define77.3%
*-commutative77.3%
distribute-rgt-neg-in77.3%
metadata-eval77.3%
Simplified77.3%
if -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 25.3%
+-commutative25.3%
sqr-neg25.3%
unsub-neg25.3%
sqr-neg25.3%
sub-neg25.3%
+-commutative25.3%
*-commutative25.3%
associate-*r*25.3%
distribute-rgt-neg-in25.3%
fma-define25.3%
*-commutative25.3%
distribute-rgt-neg-in25.3%
metadata-eval25.3%
Simplified25.3%
Taylor expanded in a around 0 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Taylor expanded in b around inf 94.6%
sub-neg94.6%
+-commutative94.6%
neg-mul-194.6%
distribute-lft-out94.6%
associate-*r/94.6%
associate-*r/94.6%
+-commutative94.6%
remove-double-neg94.6%
sub-neg94.6%
associate-*r/94.6%
neg-mul-194.6%
associate-*r/94.6%
Simplified94.6%
fma-undefine94.6%
Applied egg-rr94.6%
Final simplification92.5%
(FPCore (a b c) :precision binary64 (/ (- (* a (- (/ (* (pow c 3.0) (* a -2.0)) (pow b 4.0)) (pow (/ c b) 2.0))) c) b))
double code(double a, double b, double c) {
return ((a * (((pow(c, 3.0) * (a * -2.0)) / pow(b, 4.0)) - pow((c / b), 2.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 ** 3.0d0) * (a * (-2.0d0))) / (b ** 4.0d0)) - ((c / b) ** 2.0d0))) - c) / b
end function
public static double code(double a, double b, double c) {
return ((a * (((Math.pow(c, 3.0) * (a * -2.0)) / Math.pow(b, 4.0)) - Math.pow((c / b), 2.0))) - c) / b;
}
def code(a, b, c): return ((a * (((math.pow(c, 3.0) * (a * -2.0)) / math.pow(b, 4.0)) - math.pow((c / b), 2.0))) - c) / b
function code(a, b, c) return Float64(Float64(Float64(a * Float64(Float64(Float64((c ^ 3.0) * Float64(a * -2.0)) / (b ^ 4.0)) - (Float64(c / b) ^ 2.0))) - c) / b) end
function tmp = code(a, b, c) tmp = ((a * ((((c ^ 3.0) * (a * -2.0)) / (b ^ 4.0)) - ((c / b) ^ 2.0))) - c) / b; end
code[a_, b_, c_] := N[(N[(N[(a * N[(N[(N[(N[Power[c, 3.0], $MachinePrecision] * N[(a * -2.0), $MachinePrecision]), $MachinePrecision] / N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] - N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - c), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot \left(\frac{{c}^{3} \cdot \left(a \cdot -2\right)}{{b}^{4}} - {\left(\frac{c}{b}\right)}^{2}\right) - c}{b}
\end{array}
Initial program 31.6%
+-commutative31.6%
sqr-neg31.6%
unsub-neg31.6%
sqr-neg31.6%
sub-neg31.6%
+-commutative31.6%
*-commutative31.6%
associate-*r*31.6%
distribute-rgt-neg-in31.6%
fma-define31.6%
*-commutative31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in b around inf 94.2%
Taylor expanded in a around 0 94.3%
neg-mul-194.3%
+-commutative94.3%
unsub-neg94.3%
mul-1-neg94.3%
unsub-neg94.3%
associate-*r/94.3%
associate-*r*94.3%
*-commutative94.3%
unpow294.3%
unpow294.3%
times-frac94.3%
unpow294.3%
Simplified94.3%
Final simplification94.3%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))) (if (<= t_0 -5.0) t_0 (/ (+ c (* a (pow (/ c 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 <= -5.0) {
tmp = t_0;
} else {
tmp = (c + (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) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (t_0 <= (-5.0d0)) then
tmp = t_0
else
tmp = (c + (a * ((c / 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 <= -5.0) {
tmp = t_0;
} else {
tmp = (c + (a * Math.pow((c / 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 <= -5.0: tmp = t_0 else: tmp = (c + (a * math.pow((c / 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 <= -5.0) tmp = t_0; else tmp = Float64(Float64(c + Float64(a * (Float64(c / b) ^ 2.0))) / Float64(-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 <= -5.0) tmp = t_0; else tmp = (c + (a * ((c / 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, -5.0], t$95$0, N[(N[(c + N[(a * N[Power[N[(c / b), $MachinePrecision], 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 -5:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c + a \cdot {\left(\frac{c}{b}\right)}^{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)) < -5Initial program 77.3%
if -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 25.3%
+-commutative25.3%
sqr-neg25.3%
unsub-neg25.3%
sqr-neg25.3%
sub-neg25.3%
+-commutative25.3%
*-commutative25.3%
associate-*r*25.3%
distribute-rgt-neg-in25.3%
fma-define25.3%
*-commutative25.3%
distribute-rgt-neg-in25.3%
metadata-eval25.3%
Simplified25.3%
Taylor expanded in a around 0 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Taylor expanded in b around inf 94.6%
sub-neg94.6%
+-commutative94.6%
neg-mul-194.6%
distribute-lft-out94.6%
associate-*r/94.6%
associate-*r/94.6%
+-commutative94.6%
remove-double-neg94.6%
sub-neg94.6%
associate-*r/94.6%
neg-mul-194.6%
associate-*r/94.6%
Simplified94.6%
fma-undefine94.6%
Applied egg-rr94.6%
Final simplification92.5%
(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(c + Float64(a * (Float64(c / b) ^ 2.0))) / Float64(-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{c + a \cdot {\left(\frac{c}{b}\right)}^{2}}{-b}
\end{array}
Initial program 31.6%
+-commutative31.6%
sqr-neg31.6%
unsub-neg31.6%
sqr-neg31.6%
sub-neg31.6%
+-commutative31.6%
*-commutative31.6%
associate-*r*31.6%
distribute-rgt-neg-in31.6%
fma-define31.6%
*-commutative31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in a around 0 95.7%
+-commutative95.7%
mul-1-neg95.7%
unsub-neg95.7%
Simplified95.7%
Taylor expanded in b around inf 90.9%
sub-neg90.9%
+-commutative90.9%
neg-mul-190.9%
distribute-lft-out90.9%
associate-*r/90.9%
associate-*r/90.9%
+-commutative90.9%
remove-double-neg90.9%
sub-neg90.9%
associate-*r/90.9%
neg-mul-190.9%
associate-*r/90.9%
Simplified90.9%
fma-undefine90.9%
Applied egg-rr90.9%
Final simplification90.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(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 31.6%
+-commutative31.6%
sqr-neg31.6%
unsub-neg31.6%
sqr-neg31.6%
sub-neg31.6%
+-commutative31.6%
*-commutative31.6%
associate-*r*31.6%
distribute-rgt-neg-in31.6%
fma-define31.6%
*-commutative31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in a around 0 80.9%
associate-*r/80.9%
mul-1-neg80.9%
Simplified80.9%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
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
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 31.6%
+-commutative31.6%
sqr-neg31.6%
unsub-neg31.6%
sqr-neg31.6%
sub-neg31.6%
+-commutative31.6%
*-commutative31.6%
associate-*r*31.6%
distribute-rgt-neg-in31.6%
fma-define31.6%
*-commutative31.6%
distribute-rgt-neg-in31.6%
metadata-eval31.6%
Simplified31.6%
Taylor expanded in a around 0 95.7%
+-commutative95.7%
mul-1-neg95.7%
unsub-neg95.7%
Simplified95.7%
Taylor expanded in b around inf 90.9%
sub-neg90.9%
+-commutative90.9%
neg-mul-190.9%
distribute-lft-out90.9%
associate-*r/90.9%
associate-*r/90.9%
+-commutative90.9%
remove-double-neg90.9%
sub-neg90.9%
associate-*r/90.9%
neg-mul-190.9%
associate-*r/90.9%
Simplified90.9%
expm1-log1p-u79.2%
expm1-undefine35.3%
Applied egg-rr35.3%
sub-neg35.3%
log1p-undefine35.3%
rem-exp-log47.0%
distribute-frac-neg47.0%
unsub-neg47.0%
metadata-eval47.0%
Simplified47.0%
Taylor expanded in c around 0 3.2%
Final simplification3.2%
herbie shell --seed 2024146
(FPCore (a b c)
:name "Quadratic roots, medium range"
:precision binary64
:pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))