
(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
(let* ((t_0 (pow (fma b b (* (* c a) -4.0)) 1.5)) (t_1 (cbrt t_0)))
(if (<= b 0.102)
(/ (/ (- t_0 (pow b 3.0)) (fma b (+ b t_1) (pow t_1 2.0))) (* a 2.0))
(-
(-
(fma
-0.25
(/ (pow a 3.0) (/ (pow b 7.0) (* (pow c 4.0) 20.0)))
(* -2.0 (/ (pow c 3.0) (/ (pow b 5.0) (* a a)))))
(/ c b))
(/ (* c c) (/ (pow b 3.0) a))))))
double code(double a, double b, double c) {
double t_0 = pow(fma(b, b, ((c * a) * -4.0)), 1.5);
double t_1 = cbrt(t_0);
double tmp;
if (b <= 0.102) {
tmp = ((t_0 - pow(b, 3.0)) / fma(b, (b + t_1), pow(t_1, 2.0))) / (a * 2.0);
} else {
tmp = (fma(-0.25, (pow(a, 3.0) / (pow(b, 7.0) / (pow(c, 4.0) * 20.0))), (-2.0 * (pow(c, 3.0) / (pow(b, 5.0) / (a * a))))) - (c / b)) - ((c * c) / (pow(b, 3.0) / a));
}
return tmp;
}
function code(a, b, c) t_0 = fma(b, b, Float64(Float64(c * a) * -4.0)) ^ 1.5 t_1 = cbrt(t_0) tmp = 0.0 if (b <= 0.102) tmp = Float64(Float64(Float64(t_0 - (b ^ 3.0)) / fma(b, Float64(b + t_1), (t_1 ^ 2.0))) / Float64(a * 2.0)); else tmp = Float64(Float64(fma(-0.25, Float64((a ^ 3.0) / Float64((b ^ 7.0) / Float64((c ^ 4.0) * 20.0))), Float64(-2.0 * Float64((c ^ 3.0) / Float64((b ^ 5.0) / Float64(a * a))))) - Float64(c / b)) - Float64(Float64(c * c) / Float64((b ^ 3.0) / a))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[Power[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 1/3], $MachinePrecision]}, If[LessEqual[b, 0.102], N[(N[(N[(t$95$0 - N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] / N[(b * N[(b + t$95$1), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-0.25 * N[(N[Power[a, 3.0], $MachinePrecision] / N[(N[Power[b, 7.0], $MachinePrecision] / N[(N[Power[c, 4.0], $MachinePrecision] * 20.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(N[(c * c), $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)\right)}^{1.5}\\
t_1 := \sqrt[3]{t_0}\\
\mathbf{if}\;b \leq 0.102:\\
\;\;\;\;\frac{\frac{t_0 - {b}^{3}}{\mathsf{fma}\left(b, b + t_1, {t_1}^{2}\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-0.25, \frac{{a}^{3}}{\frac{{b}^{7}}{{c}^{4} \cdot 20}}, -2 \cdot \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}\right) - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}}\\
\end{array}
\end{array}
if b < 0.101999999999999993Initial program 89.0%
*-commutative89.0%
+-commutative89.0%
unsub-neg89.0%
fma-neg89.1%
associate-*l*89.1%
*-commutative89.1%
distribute-rgt-neg-in89.1%
metadata-eval89.1%
Simplified89.1%
add-cbrt-cube87.2%
pow386.9%
sqrt-pow286.8%
associate-*l*86.8%
metadata-eval86.8%
Applied egg-rr86.8%
flip3--86.7%
Applied egg-rr86.7%
rem-cube-cbrt89.1%
associate-*r*89.1%
*-commutative89.1%
+-commutative89.1%
Simplified89.3%
if 0.101999999999999993 < b Initial program 54.9%
/-rgt-identity54.9%
metadata-eval54.9%
associate-/l*54.9%
associate-*r/54.9%
+-commutative54.9%
unsub-neg54.9%
fma-neg55.2%
associate-*l*55.2%
*-commutative55.2%
distribute-rgt-neg-in55.2%
metadata-eval55.2%
associate-/r*55.2%
metadata-eval55.2%
metadata-eval55.2%
Simplified55.2%
Taylor expanded in a around 0 92.3%
Simplified92.3%
Taylor expanded in b around 0 92.3%
associate-/l*92.3%
distribute-rgt-out92.3%
metadata-eval92.3%
Simplified92.3%
Final simplification92.0%
(FPCore (a b c)
:precision binary64
(if (<= b 0.059)
(/ (- (sqrt (fma b b (* (* c a) -4.0))) b) (* a 2.0))
(-
(-
(fma
-0.25
(/ (pow a 3.0) (/ (pow b 7.0) (* (pow c 4.0) 20.0)))
(* -2.0 (/ (pow c 3.0) (/ (pow b 5.0) (* a a)))))
(/ c b))
(/ (* c c) (/ (pow b 3.0) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.059) {
tmp = (sqrt(fma(b, b, ((c * a) * -4.0))) - b) / (a * 2.0);
} else {
tmp = (fma(-0.25, (pow(a, 3.0) / (pow(b, 7.0) / (pow(c, 4.0) * 20.0))), (-2.0 * (pow(c, 3.0) / (pow(b, 5.0) / (a * a))))) - (c / b)) - ((c * c) / (pow(b, 3.0) / a));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.059) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(fma(-0.25, Float64((a ^ 3.0) / Float64((b ^ 7.0) / Float64((c ^ 4.0) * 20.0))), Float64(-2.0 * Float64((c ^ 3.0) / Float64((b ^ 5.0) / Float64(a * a))))) - Float64(c / b)) - Float64(Float64(c * c) / Float64((b ^ 3.0) / a))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.059], N[(N[(N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-0.25 * N[(N[Power[a, 3.0], $MachinePrecision] / N[(N[Power[b, 7.0], $MachinePrecision] / N[(N[Power[c, 4.0], $MachinePrecision] * 20.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(N[(c * c), $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.059:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-0.25, \frac{{a}^{3}}{\frac{{b}^{7}}{{c}^{4} \cdot 20}}, -2 \cdot \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}\right) - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}}\\
\end{array}
\end{array}
if b < 0.058999999999999997Initial program 89.0%
*-commutative89.0%
+-commutative89.0%
unsub-neg89.0%
fma-neg89.1%
associate-*l*89.1%
*-commutative89.1%
distribute-rgt-neg-in89.1%
metadata-eval89.1%
Simplified89.1%
if 0.058999999999999997 < b Initial program 54.9%
/-rgt-identity54.9%
metadata-eval54.9%
associate-/l*54.9%
associate-*r/54.9%
+-commutative54.9%
unsub-neg54.9%
fma-neg55.2%
associate-*l*55.2%
*-commutative55.2%
distribute-rgt-neg-in55.2%
metadata-eval55.2%
associate-/r*55.2%
metadata-eval55.2%
metadata-eval55.2%
Simplified55.2%
Taylor expanded in a around 0 92.3%
Simplified92.3%
Taylor expanded in b around 0 92.3%
associate-/l*92.3%
distribute-rgt-out92.3%
metadata-eval92.3%
Simplified92.3%
Final simplification92.0%
(FPCore (a b c)
:precision binary64
(if (<= b 0.058)
(/ (- (sqrt (fma b b (* (* c a) -4.0))) b) (* a 2.0))
(-
(fma
-0.25
(* (/ (pow (* c a) 4.0) a) (/ 20.0 (pow b 7.0)))
(- (/ (* -2.0 (* c (pow (* c a) 2.0))) (pow b 5.0)) (/ c b)))
(* (* c a) (/ c (pow b 3.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.058) {
tmp = (sqrt(fma(b, b, ((c * a) * -4.0))) - b) / (a * 2.0);
} else {
tmp = fma(-0.25, ((pow((c * a), 4.0) / a) * (20.0 / pow(b, 7.0))), (((-2.0 * (c * pow((c * a), 2.0))) / pow(b, 5.0)) - (c / b))) - ((c * a) * (c / pow(b, 3.0)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.058) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(fma(-0.25, Float64(Float64((Float64(c * a) ^ 4.0) / a) * Float64(20.0 / (b ^ 7.0))), Float64(Float64(Float64(-2.0 * Float64(c * (Float64(c * a) ^ 2.0))) / (b ^ 5.0)) - Float64(c / b))) - Float64(Float64(c * a) * Float64(c / (b ^ 3.0)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.058], N[(N[(N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.25 * N[(N[(N[Power[N[(c * a), $MachinePrecision], 4.0], $MachinePrecision] / a), $MachinePrecision] * N[(20.0 / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-2.0 * N[(c * N[Power[N[(c * a), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c * a), $MachinePrecision] * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.058:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.25, \frac{{\left(c \cdot a\right)}^{4}}{a} \cdot \frac{20}{{b}^{7}}, \frac{-2 \cdot \left(c \cdot {\left(c \cdot a\right)}^{2}\right)}{{b}^{5}} - \frac{c}{b}\right) - \left(c \cdot a\right) \cdot \frac{c}{{b}^{3}}\\
\end{array}
\end{array}
if b < 0.0580000000000000029Initial program 89.0%
*-commutative89.0%
+-commutative89.0%
unsub-neg89.0%
fma-neg89.1%
associate-*l*89.1%
*-commutative89.1%
distribute-rgt-neg-in89.1%
metadata-eval89.1%
Simplified89.1%
if 0.0580000000000000029 < b Initial program 54.9%
*-commutative54.9%
+-commutative54.9%
unsub-neg54.9%
fma-neg55.2%
associate-*l*55.2%
*-commutative55.2%
distribute-rgt-neg-in55.2%
metadata-eval55.2%
Simplified55.2%
add-cbrt-cube53.9%
pow354.1%
sqrt-pow253.9%
associate-*l*53.9%
metadata-eval53.9%
Applied egg-rr53.9%
Taylor expanded in b around inf 92.3%
Simplified92.3%
Final simplification92.0%
(FPCore (a b c)
:precision binary64
(if (<= b 1.7)
(/ (- (sqrt (fma b b (* (* c a) -4.0))) b) (* a 2.0))
(-
(fma -2.0 (/ (pow c 3.0) (/ (pow b 5.0) (* a a))) (/ (- c) b))
(/ (* c c) (/ (pow b 3.0) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.7) {
tmp = (sqrt(fma(b, b, ((c * a) * -4.0))) - b) / (a * 2.0);
} else {
tmp = fma(-2.0, (pow(c, 3.0) / (pow(b, 5.0) / (a * a))), (-c / b)) - ((c * c) / (pow(b, 3.0) / a));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1.7) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(fma(-2.0, Float64((c ^ 3.0) / Float64((b ^ 5.0) / Float64(a * a))), Float64(Float64(-c) / b)) - Float64(Float64(c * c) / Float64((b ^ 3.0) / a))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1.7], N[(N[(N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[((-c) / b), $MachinePrecision]), $MachinePrecision] - N[(N[(c * c), $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.7:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \frac{-c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}}\\
\end{array}
\end{array}
if b < 1.69999999999999996Initial program 85.5%
*-commutative85.5%
+-commutative85.5%
unsub-neg85.5%
fma-neg85.6%
associate-*l*85.6%
*-commutative85.6%
distribute-rgt-neg-in85.6%
metadata-eval85.6%
Simplified85.6%
if 1.69999999999999996 < b Initial program 52.8%
/-rgt-identity52.8%
metadata-eval52.8%
associate-/l*52.8%
associate-*r/52.8%
+-commutative52.8%
unsub-neg52.8%
fma-neg53.0%
associate-*l*53.0%
*-commutative53.0%
distribute-rgt-neg-in53.0%
metadata-eval53.0%
associate-/r*53.0%
metadata-eval53.0%
metadata-eval53.0%
Simplified53.0%
Taylor expanded in b around inf 90.5%
+-commutative90.5%
mul-1-neg90.5%
unsub-neg90.5%
+-commutative90.5%
fma-def90.5%
associate-/l*90.5%
unpow290.5%
mul-1-neg90.5%
distribute-neg-frac90.5%
associate-/l*90.5%
unpow290.5%
Simplified90.5%
Final simplification89.6%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -0.035) (* (- (sqrt (fma b b (* (* c a) -4.0))) b) (/ 0.5 a)) (- (/ (* c (- c)) (/ (* b (* b b)) a)) (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0)) <= -0.035) {
tmp = (sqrt(fma(b, b, ((c * a) * -4.0))) - b) * (0.5 / a);
} else {
tmp = ((c * -c) / ((b * (b * b)) / a)) - (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)) <= -0.035) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(Float64(c * Float64(-c)) / Float64(Float64(b * Float64(b * b)) / a)) - 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], -0.035], N[(N[(N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * (-c)), $MachinePrecision] / N[(N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $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 -0.035:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \left(-c\right)}{\frac{b \cdot \left(b \cdot b\right)}{a}} - \frac{c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -0.035000000000000003Initial program 83.2%
/-rgt-identity83.2%
metadata-eval83.2%
associate-/l*83.2%
associate-*r/83.1%
+-commutative83.1%
unsub-neg83.1%
fma-neg83.3%
associate-*l*83.3%
*-commutative83.3%
distribute-rgt-neg-in83.3%
metadata-eval83.3%
associate-/r*83.3%
metadata-eval83.3%
metadata-eval83.3%
Simplified83.3%
if -0.035000000000000003 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 50.1%
/-rgt-identity50.1%
metadata-eval50.1%
associate-/l*50.1%
associate-*r/50.1%
+-commutative50.1%
unsub-neg50.1%
fma-neg50.4%
associate-*l*50.4%
*-commutative50.4%
distribute-rgt-neg-in50.4%
metadata-eval50.4%
associate-/r*50.4%
metadata-eval50.4%
metadata-eval50.4%
Simplified50.4%
Taylor expanded in b around inf 86.3%
+-commutative86.3%
mul-1-neg86.3%
unsub-neg86.3%
mul-1-neg86.3%
distribute-neg-frac86.3%
associate-/l*86.3%
unpow286.3%
Simplified86.3%
unpow386.3%
Applied egg-rr86.3%
Final simplification85.6%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -0.035) (/ (- (sqrt (fma b b (* (* c a) -4.0))) b) (* a 2.0)) (- (/ (* c (- c)) (/ (* b (* b b)) a)) (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0)) <= -0.035) {
tmp = (sqrt(fma(b, b, ((c * a) * -4.0))) - b) / (a * 2.0);
} else {
tmp = ((c * -c) / ((b * (b * b)) / a)) - (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)) <= -0.035) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(c * Float64(-c)) / Float64(Float64(b * Float64(b * b)) / a)) - 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], -0.035], N[(N[(N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * (-c)), $MachinePrecision] / N[(N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $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 -0.035:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \left(-c\right)}{\frac{b \cdot \left(b \cdot b\right)}{a}} - \frac{c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -0.035000000000000003Initial program 83.2%
*-commutative83.2%
+-commutative83.2%
unsub-neg83.2%
fma-neg83.3%
associate-*l*83.3%
*-commutative83.3%
distribute-rgt-neg-in83.3%
metadata-eval83.3%
Simplified83.3%
if -0.035000000000000003 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 50.1%
/-rgt-identity50.1%
metadata-eval50.1%
associate-/l*50.1%
associate-*r/50.1%
+-commutative50.1%
unsub-neg50.1%
fma-neg50.4%
associate-*l*50.4%
*-commutative50.4%
distribute-rgt-neg-in50.4%
metadata-eval50.4%
associate-/r*50.4%
metadata-eval50.4%
metadata-eval50.4%
Simplified50.4%
Taylor expanded in b around inf 86.3%
+-commutative86.3%
mul-1-neg86.3%
unsub-neg86.3%
mul-1-neg86.3%
distribute-neg-frac86.3%
associate-/l*86.3%
unpow286.3%
Simplified86.3%
unpow386.3%
Applied egg-rr86.3%
Final simplification85.6%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))) (if (<= t_0 -0.035) t_0 (- (/ (* c (- c)) (/ (* b (* b b)) a)) (/ c 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 <= -0.035) {
tmp = t_0;
} else {
tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.035d0)) then
tmp = t_0
else
tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.035) {
tmp = t_0;
} else {
tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / 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 <= -0.035: tmp = t_0 else: tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / 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 <= -0.035) tmp = t_0; else tmp = Float64(Float64(Float64(c * Float64(-c)) / Float64(Float64(b * Float64(b * b)) / a)) - Float64(c / 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 <= -0.035) tmp = t_0; else tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.035], t$95$0, N[(N[(N[(c * (-c)), $MachinePrecision] / N[(N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] - N[(c / b), $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 -0.035:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \left(-c\right)}{\frac{b \cdot \left(b \cdot b\right)}{a}} - \frac{c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -0.035000000000000003Initial program 83.2%
*-commutative83.2%
+-commutative83.2%
unsub-neg83.2%
fma-neg83.3%
associate-*l*83.3%
*-commutative83.3%
distribute-rgt-neg-in83.3%
metadata-eval83.3%
Simplified83.3%
fma-udef83.1%
*-commutative83.1%
metadata-eval83.1%
cancel-sign-sub-inv83.1%
associate-*l*83.1%
*-un-lft-identity83.1%
prod-diff83.3%
Applied egg-rr83.0%
*-rgt-identity83.0%
fma-neg82.7%
fma-udef82.7%
*-rgt-identity82.7%
*-rgt-identity82.7%
associate--r-83.1%
associate--r+83.1%
+-inverses83.1%
neg-sub083.1%
associate-*r*83.1%
distribute-rgt-neg-in83.1%
metadata-eval83.1%
*-commutative83.1%
associate-*r*83.1%
Simplified83.2%
if -0.035000000000000003 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 50.1%
/-rgt-identity50.1%
metadata-eval50.1%
associate-/l*50.1%
associate-*r/50.1%
+-commutative50.1%
unsub-neg50.1%
fma-neg50.4%
associate-*l*50.4%
*-commutative50.4%
distribute-rgt-neg-in50.4%
metadata-eval50.4%
associate-/r*50.4%
metadata-eval50.4%
metadata-eval50.4%
Simplified50.4%
Taylor expanded in b around inf 86.3%
+-commutative86.3%
mul-1-neg86.3%
unsub-neg86.3%
mul-1-neg86.3%
distribute-neg-frac86.3%
associate-/l*86.3%
unpow286.3%
Simplified86.3%
unpow386.3%
Applied egg-rr86.3%
Final simplification85.5%
(FPCore (a b c) :precision binary64 (if (<= b 8.2) (* (/ 0.5 a) (- (sqrt (- (* b b) (* c (* a 4.0)))) b)) (- (/ (* c (- c)) (/ (* b (* b b)) a)) (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 8.2) {
tmp = (0.5 / a) * (sqrt(((b * b) - (c * (a * 4.0)))) - b);
} else {
tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 8.2d0) then
tmp = (0.5d0 / a) * (sqrt(((b * b) - (c * (a * 4.0d0)))) - b)
else
tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 8.2) {
tmp = (0.5 / a) * (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b);
} else {
tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 8.2: tmp = (0.5 / a) * (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) else: tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 8.2) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b)); else tmp = Float64(Float64(Float64(c * Float64(-c)) / Float64(Float64(b * Float64(b * b)) / a)) - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 8.2) tmp = (0.5 / a) * (sqrt(((b * b) - (c * (a * 4.0)))) - b); else tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 8.2], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * (-c)), $MachinePrecision] / N[(N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.2:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \left(-c\right)}{\frac{b \cdot \left(b \cdot b\right)}{a}} - \frac{c}{b}\\
\end{array}
\end{array}
if b < 8.1999999999999993Initial program 83.0%
/-rgt-identity83.0%
metadata-eval83.0%
associate-/l*83.0%
associate-*r/83.0%
+-commutative83.0%
unsub-neg83.0%
fma-neg83.1%
associate-*l*83.1%
*-commutative83.1%
distribute-rgt-neg-in83.1%
metadata-eval83.1%
associate-/r*83.1%
metadata-eval83.1%
metadata-eval83.1%
Simplified83.1%
fma-udef83.0%
*-commutative83.0%
metadata-eval83.0%
cancel-sign-sub-inv83.0%
associate-*l*83.0%
*-un-lft-identity83.0%
prod-diff83.1%
Applied egg-rr82.8%
*-rgt-identity82.8%
fma-neg82.6%
fma-udef82.6%
*-rgt-identity82.6%
*-rgt-identity82.6%
associate--r-83.0%
associate--r+83.0%
+-inverses83.0%
neg-sub083.0%
associate-*r*83.0%
distribute-rgt-neg-in83.0%
metadata-eval83.0%
*-commutative83.0%
associate-*r*83.0%
Simplified83.0%
if 8.1999999999999993 < b Initial program 51.0%
/-rgt-identity51.0%
metadata-eval51.0%
associate-/l*51.0%
associate-*r/51.0%
+-commutative51.0%
unsub-neg51.0%
fma-neg51.3%
associate-*l*51.3%
*-commutative51.3%
distribute-rgt-neg-in51.3%
metadata-eval51.3%
associate-/r*51.3%
metadata-eval51.3%
metadata-eval51.3%
Simplified51.3%
Taylor expanded in b around inf 86.0%
+-commutative86.0%
mul-1-neg86.0%
unsub-neg86.0%
mul-1-neg86.0%
distribute-neg-frac86.0%
associate-/l*86.0%
unpow286.0%
Simplified86.0%
unpow386.0%
Applied egg-rr86.0%
Final simplification85.3%
(FPCore (a b c) :precision binary64 (- (/ (* c (- c)) (/ (* b (* b b)) a)) (/ c b)))
double code(double a, double b, double c) {
return ((c * -c) / ((b * (b * b)) / a)) - (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 * -c) / ((b * (b * b)) / a)) - (c / b)
end function
public static double code(double a, double b, double c) {
return ((c * -c) / ((b * (b * b)) / a)) - (c / b);
}
def code(a, b, c): return ((c * -c) / ((b * (b * b)) / a)) - (c / b)
function code(a, b, c) return Float64(Float64(Float64(c * Float64(-c)) / Float64(Float64(b * Float64(b * b)) / a)) - Float64(c / b)) end
function tmp = code(a, b, c) tmp = ((c * -c) / ((b * (b * b)) / a)) - (c / b); end
code[a_, b_, c_] := N[(N[(N[(c * (-c)), $MachinePrecision] / N[(N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot \left(-c\right)}{\frac{b \cdot \left(b \cdot b\right)}{a}} - \frac{c}{b}
\end{array}
Initial program 58.4%
/-rgt-identity58.4%
metadata-eval58.4%
associate-/l*58.4%
associate-*r/58.4%
+-commutative58.4%
unsub-neg58.4%
fma-neg58.6%
associate-*l*58.6%
*-commutative58.6%
distribute-rgt-neg-in58.6%
metadata-eval58.6%
associate-/r*58.6%
metadata-eval58.6%
metadata-eval58.6%
Simplified58.6%
Taylor expanded in b around inf 79.6%
+-commutative79.6%
mul-1-neg79.6%
unsub-neg79.6%
mul-1-neg79.6%
distribute-neg-frac79.6%
associate-/l*79.6%
unpow279.6%
Simplified79.6%
unpow379.6%
Applied egg-rr79.6%
Final simplification79.6%
(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.4%
/-rgt-identity58.4%
metadata-eval58.4%
associate-/l*58.4%
associate-*r/58.4%
+-commutative58.4%
unsub-neg58.4%
fma-neg58.6%
associate-*l*58.6%
*-commutative58.6%
distribute-rgt-neg-in58.6%
metadata-eval58.6%
associate-/r*58.6%
metadata-eval58.6%
metadata-eval58.6%
Simplified58.6%
Taylor expanded in b around inf 62.0%
mul-1-neg62.0%
distribute-neg-frac62.0%
Simplified62.0%
Final simplification62.0%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 58.4%
/-rgt-identity58.4%
metadata-eval58.4%
associate-/l*58.4%
associate-*r/58.4%
+-commutative58.4%
unsub-neg58.4%
fma-neg58.6%
associate-*l*58.6%
*-commutative58.6%
distribute-rgt-neg-in58.6%
metadata-eval58.6%
associate-/r*58.6%
metadata-eval58.6%
metadata-eval58.6%
Simplified58.6%
Taylor expanded in b around -inf 11.7%
mul-1-neg11.7%
unsub-neg11.7%
Simplified11.7%
Taylor expanded in c around inf 1.6%
Final simplification1.6%
herbie shell --seed 2023230
(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)))