
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* b (* b b))))
(fma
(/ (* (* c (* c (* c c))) (* a 20.0)) (* b (* (* b b) (* b t_0))))
(* -0.25 (* a a))
(fma
(* a a)
(/ (* c (* (* c c) -2.0)) (* (* b b) t_0))
(/ (fma (* c c) (/ a (* b b)) c) (- b))))))
double code(double a, double b, double c) {
double t_0 = b * (b * b);
return fma((((c * (c * (c * c))) * (a * 20.0)) / (b * ((b * b) * (b * t_0)))), (-0.25 * (a * a)), fma((a * a), ((c * ((c * c) * -2.0)) / ((b * b) * t_0)), (fma((c * c), (a / (b * b)), c) / -b)));
}
function code(a, b, c) t_0 = Float64(b * Float64(b * b)) return fma(Float64(Float64(Float64(c * Float64(c * Float64(c * c))) * Float64(a * 20.0)) / Float64(b * Float64(Float64(b * b) * Float64(b * t_0)))), Float64(-0.25 * Float64(a * a)), fma(Float64(a * a), Float64(Float64(c * Float64(Float64(c * c) * -2.0)) / Float64(Float64(b * b) * t_0)), Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)))) end
code[a_, b_, c_] := Block[{t$95$0 = N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(c * N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * 20.0), $MachinePrecision]), $MachinePrecision] / N[(b * N[(N[(b * b), $MachinePrecision] * N[(b * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-0.25 * N[(a * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * a), $MachinePrecision] * N[(N[(c * N[(N[(c * c), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot b\right)\\
\mathsf{fma}\left(\frac{\left(c \cdot \left(c \cdot \left(c \cdot c\right)\right)\right) \cdot \left(a \cdot 20\right)}{b \cdot \left(\left(b \cdot b\right) \cdot \left(b \cdot t\_0\right)\right)}, -0.25 \cdot \left(a \cdot a\right), \mathsf{fma}\left(a \cdot a, \frac{c \cdot \left(\left(c \cdot c\right) \cdot -2\right)}{\left(b \cdot b\right) \cdot t\_0}, \frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\right)\right)
\end{array}
\end{array}
Initial program 54.5%
Taylor expanded in a around 0
Applied rewrites91.3%
Applied rewrites91.3%
Final simplification91.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* b (* b b))))
(fma
(fma
c
(* (* c c) (/ -2.0 (* (* b b) t_0)))
(*
(/ (* (* c (* c (* c c))) (* a 20.0)) (* b (* (* b b) (* b t_0))))
-0.25))
(* a a)
(/ (fma (* c c) (/ a (* b b)) c) (- b)))))
double code(double a, double b, double c) {
double t_0 = b * (b * b);
return fma(fma(c, ((c * c) * (-2.0 / ((b * b) * t_0))), ((((c * (c * (c * c))) * (a * 20.0)) / (b * ((b * b) * (b * t_0)))) * -0.25)), (a * a), (fma((c * c), (a / (b * b)), c) / -b));
}
function code(a, b, c) t_0 = Float64(b * Float64(b * b)) return fma(fma(c, Float64(Float64(c * c) * Float64(-2.0 / Float64(Float64(b * b) * t_0))), Float64(Float64(Float64(Float64(c * Float64(c * Float64(c * c))) * Float64(a * 20.0)) / Float64(b * Float64(Float64(b * b) * Float64(b * t_0)))) * -0.25)), Float64(a * a), Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b))) end
code[a_, b_, c_] := Block[{t$95$0 = N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]}, N[(N[(c * N[(N[(c * c), $MachinePrecision] * N[(-2.0 / N[(N[(b * b), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(c * N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * 20.0), $MachinePrecision]), $MachinePrecision] / N[(b * N[(N[(b * b), $MachinePrecision] * N[(b * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision] + N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot b\right)\\
\mathsf{fma}\left(\mathsf{fma}\left(c, \left(c \cdot c\right) \cdot \frac{-2}{\left(b \cdot b\right) \cdot t\_0}, \frac{\left(c \cdot \left(c \cdot \left(c \cdot c\right)\right)\right) \cdot \left(a \cdot 20\right)}{b \cdot \left(\left(b \cdot b\right) \cdot \left(b \cdot t\_0\right)\right)} \cdot -0.25\right), a \cdot a, \frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\right)
\end{array}
\end{array}
Initial program 54.5%
Taylor expanded in a around 0
Applied rewrites91.3%
Applied rewrites91.3%
Final simplification91.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -0.0001)
(* (- (* b b) t_0) (/ (/ -1.0 (+ b (sqrt t_0))) (* a 2.0)))
(/ (fma (* c c) (/ a (* b b)) c) (- b)))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -4.0), (b * b));
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -0.0001) {
tmp = ((b * b) - t_0) * ((-1.0 / (b + sqrt(t_0))) / (a * 2.0));
} else {
tmp = fma((c * c), (a / (b * b)), c) / -b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -4.0), Float64(b * b)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -0.0001) tmp = Float64(Float64(Float64(b * b) - t_0) * Float64(Float64(-1.0 / Float64(b + sqrt(t_0))) / Float64(a * 2.0))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, 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.0001], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] * N[(N[(-1.0 / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.0001:\\
\;\;\;\;\left(b \cdot b - t\_0\right) \cdot \frac{\frac{-1}{b + \sqrt{t\_0}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.00000000000000005e-4Initial program 74.0%
Applied rewrites74.1%
lift-/.f64N/A
Applied rewrites75.9%
if -1.00000000000000005e-4 < (/.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 38.3%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6494.1
Applied rewrites94.1%
Final simplification85.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -0.0001)
(/ (* (/ 0.5 a) (- t_0 (* b b))) (+ b (sqrt t_0)))
(/ (fma (* c c) (/ a (* b b)) c) (- b)))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -4.0), (b * b));
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -0.0001) {
tmp = ((0.5 / a) * (t_0 - (b * b))) / (b + sqrt(t_0));
} else {
tmp = fma((c * c), (a / (b * b)), c) / -b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -4.0), Float64(b * b)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -0.0001) tmp = Float64(Float64(Float64(0.5 / a) * Float64(t_0 - Float64(b * b))) / Float64(b + sqrt(t_0))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, 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.0001], N[(N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.0001:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot \left(t\_0 - b \cdot b\right)}{b + \sqrt{t\_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.00000000000000005e-4Initial program 74.0%
Applied rewrites74.1%
Applied rewrites75.8%
if -1.00000000000000005e-4 < (/.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 38.3%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6494.1
Applied rewrites94.1%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -0.0001)
(/ (- t_0 (* b b)) (* (+ b (sqrt t_0)) (* a 2.0)))
(/ (fma (* c c) (/ a (* b b)) c) (- b)))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -4.0), (b * b));
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -0.0001) {
tmp = (t_0 - (b * b)) / ((b + sqrt(t_0)) * (a * 2.0));
} else {
tmp = fma((c * c), (a / (b * b)), c) / -b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -4.0), Float64(b * b)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -0.0001) tmp = Float64(Float64(t_0 - Float64(b * b)) / Float64(Float64(b + sqrt(t_0)) * Float64(a * 2.0))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, 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.0001], N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.0001:\\
\;\;\;\;\frac{t\_0 - b \cdot b}{\left(b + \sqrt{t\_0}\right) \cdot \left(a \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.00000000000000005e-4Initial program 74.0%
Applied rewrites74.1%
Applied rewrites75.8%
if -1.00000000000000005e-4 < (/.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 38.3%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6494.1
Applied rewrites94.1%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma b b (* c (* a -4.0)))))
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -0.0021)
(/ (- t_0 (* b b)) (* (* a 2.0) (+ b (sqrt t_0))))
(- (fma a (/ (* c c) (* b (* b b))) (/ c b))))))
double code(double a, double b, double c) {
double t_0 = fma(b, b, (c * (a * -4.0)));
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -0.0021) {
tmp = (t_0 - (b * b)) / ((a * 2.0) * (b + sqrt(t_0)));
} else {
tmp = -fma(a, ((c * c) / (b * (b * b))), (c / b));
}
return tmp;
}
function code(a, b, c) t_0 = fma(b, b, Float64(c * Float64(a * -4.0))) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -0.0021) tmp = Float64(Float64(t_0 - Float64(b * b)) / Float64(Float64(a * 2.0) * Float64(b + sqrt(t_0)))); else tmp = Float64(-fma(a, Float64(Float64(c * c) / Float64(b * Float64(b * b))), Float64(c / b))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, 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.0021], N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(N[(a * 2.0), $MachinePrecision] * N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(a * N[(N[(c * c), $MachinePrecision] / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.0021:\\
\;\;\;\;\frac{t\_0 - b \cdot b}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{t\_0}\right)}\\
\mathbf{else}:\\
\;\;\;\;-\mathsf{fma}\left(a, \frac{c \cdot c}{b \cdot \left(b \cdot b\right)}, \frac{c}{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.00209999999999999987Initial program 74.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval75.0
Applied rewrites75.0%
lift-/.f64N/A
lift-+.f64N/A
flip-+N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites76.4%
if -0.00209999999999999987 < (/.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 42.7%
Applied rewrites41.7%
Taylor expanded in a around 0
+-commutativeN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-outN/A
lower-neg.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6491.1
Applied rewrites91.1%
Final simplification85.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= b 0.0148)
(* (- (* b b) t_0) (/ (/ -1.0 (+ b (sqrt t_0))) (* a 2.0)))
(/
(-
(* (* (* a a) -2.0) (/ (* c (* c c)) (* (* b b) (* b b))))
(fma (* c c) (/ a (* b b)) c))
b))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -4.0), (b * b));
double tmp;
if (b <= 0.0148) {
tmp = ((b * b) - t_0) * ((-1.0 / (b + sqrt(t_0))) / (a * 2.0));
} else {
tmp = ((((a * a) * -2.0) * ((c * (c * c)) / ((b * b) * (b * b)))) - fma((c * c), (a / (b * b)), c)) / b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -4.0), Float64(b * b)) tmp = 0.0 if (b <= 0.0148) tmp = Float64(Float64(Float64(b * b) - t_0) * Float64(Float64(-1.0 / Float64(b + sqrt(t_0))) / Float64(a * 2.0))); else tmp = Float64(Float64(Float64(Float64(Float64(a * a) * -2.0) * Float64(Float64(c * Float64(c * c)) / Float64(Float64(b * b) * Float64(b * b)))) - fma(Float64(c * c), Float64(a / Float64(b * b)), c)) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.0148], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] * N[(N[(-1.0 / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(a * a), $MachinePrecision] * -2.0), $MachinePrecision] * N[(N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;b \leq 0.0148:\\
\;\;\;\;\left(b \cdot b - t\_0\right) \cdot \frac{\frac{-1}{b + \sqrt{t\_0}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(a \cdot a\right) \cdot -2\right) \cdot \frac{c \cdot \left(c \cdot c\right)}{\left(b \cdot b\right) \cdot \left(b \cdot b\right)} - \mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{b}\\
\end{array}
\end{array}
if b < 0.014800000000000001Initial program 90.1%
Applied rewrites90.2%
lift-/.f64N/A
Applied rewrites91.1%
if 0.014800000000000001 < b Initial program 52.4%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites90.0%
Final simplification90.1%
(FPCore (a b c) :precision binary64 (if (<= b 1.31) (/ 1.0 (/ (* a 2.0) (- (sqrt (fma b b (* c (* a -4.0)))) b))) (/ (fma (* c c) (/ a (* b b)) c) (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.31) {
tmp = 1.0 / ((a * 2.0) / (sqrt(fma(b, b, (c * (a * -4.0)))) - b));
} else {
tmp = fma((c * c), (a / (b * b)), c) / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1.31) tmp = Float64(1.0 / Float64(Float64(a * 2.0) / Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1.31], N[(1.0 / N[(N[(a * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.31:\\
\;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\\
\end{array}
\end{array}
if b < 1.3100000000000001Initial program 79.3%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.6
Applied rewrites79.6%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6479.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6479.7
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6479.7
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6479.7
Applied rewrites79.7%
if 1.3100000000000001 < b Initial program 50.1%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6486.5
Applied rewrites86.5%
Final simplification85.4%
(FPCore (a b c) :precision binary64 (if (<= b 1.31) (* (/ 0.5 a) (- (sqrt (fma b b (* c (* a -4.0)))) b)) (/ (fma (* c c) (/ a (* b b)) c) (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.31) {
tmp = (0.5 / a) * (sqrt(fma(b, b, (c * (a * -4.0)))) - b);
} else {
tmp = fma((c * c), (a / (b * b)), c) / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1.31) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b)); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1.31], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.31:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\\
\end{array}
\end{array}
if b < 1.3100000000000001Initial program 79.3%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.6
Applied rewrites79.6%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6479.6
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6479.6
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6479.6
Applied rewrites79.6%
if 1.3100000000000001 < b Initial program 50.1%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6486.5
Applied rewrites86.5%
Final simplification85.4%
(FPCore (a b c) :precision binary64 (if (<= b 1.31) (* (/ -0.5 a) (- b (sqrt (fma a (* c -4.0) (* b b))))) (/ (fma (* c c) (/ a (* b b)) c) (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.31) {
tmp = (-0.5 / a) * (b - sqrt(fma(a, (c * -4.0), (b * b))));
} else {
tmp = fma((c * c), (a / (b * b)), c) / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 1.31) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(fma(a, Float64(c * -4.0), Float64(b * b))))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 1.31], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.31:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}\\
\end{array}
\end{array}
if b < 1.3100000000000001Initial program 79.3%
Applied rewrites79.3%
if 1.3100000000000001 < b Initial program 50.1%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6486.5
Applied rewrites86.5%
Final simplification85.4%
(FPCore (a b c) :precision binary64 (/ (fma (* c c) (/ a (* b b)) c) (- b)))
double code(double a, double b, double c) {
return fma((c * c), (a / (b * b)), c) / -b;
}
function code(a, b, c) return Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(-b)) end
code[a_, b_, c_] := N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{-b}
\end{array}
Initial program 54.5%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6482.5
Applied rewrites82.5%
Final simplification82.5%
(FPCore (a b c) :precision binary64 (/ c (- b)))
double code(double a, double b, double c) {
return c / -b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / -b
end function
public static double code(double a, double b, double c) {
return c / -b;
}
def code(a, b, c): return c / -b
function code(a, b, c) return Float64(c / Float64(-b)) end
function tmp = code(a, b, c) tmp = c / -b; end
code[a_, b_, c_] := N[(c / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{-b}
\end{array}
Initial program 54.5%
Taylor expanded in b around inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-neg.f6465.7
Applied rewrites65.7%
herbie shell --seed 2024225
(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)))