
(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 14 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 (/ 0.5 (fma a (fma a (/ (fma 0.5 (* (* b b) c) (* a (* c c))) (pow b 5.0)) (/ 0.5 b)) (* -0.5 (/ b c)))))
double code(double a, double b, double c) {
return 0.5 / fma(a, fma(a, (fma(0.5, ((b * b) * c), (a * (c * c))) / pow(b, 5.0)), (0.5 / b)), (-0.5 * (b / c)));
}
function code(a, b, c) return Float64(0.5 / fma(a, fma(a, Float64(fma(0.5, Float64(Float64(b * b) * c), Float64(a * Float64(c * c))) / (b ^ 5.0)), Float64(0.5 / b)), Float64(-0.5 * Float64(b / c)))) end
code[a_, b_, c_] := N[(0.5 / N[(a * N[(a * N[(N[(0.5 * N[(N[(b * b), $MachinePrecision] * c), $MachinePrecision] + N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] + N[(0.5 / b), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{\mathsf{fma}\left(0.5, \left(b \cdot b\right) \cdot c, a \cdot \left(c \cdot c\right)\right)}{{b}^{5}}, \frac{0.5}{b}\right), -0.5 \cdot \frac{b}{c}\right)}
\end{array}
Initial program 33.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6433.9
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6433.9
Applied rewrites33.9%
lift--.f64N/A
flip--N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-*.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites34.6%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-pow.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6495.2
Applied rewrites95.2%
Taylor expanded in b around 0
Applied rewrites95.2%
(FPCore (a b c) :precision binary64 (/ 0.5 (fma a (* 0.5 (fma a (/ c (pow b 3.0)) (pow b -1.0))) (* -0.5 (/ b c)))))
double code(double a, double b, double c) {
return 0.5 / fma(a, (0.5 * fma(a, (c / pow(b, 3.0)), pow(b, -1.0))), (-0.5 * (b / c)));
}
function code(a, b, c) return Float64(0.5 / fma(a, Float64(0.5 * fma(a, Float64(c / (b ^ 3.0)), (b ^ -1.0))), Float64(-0.5 * Float64(b / c)))) end
code[a_, b_, c_] := N[(0.5 / N[(a * N[(0.5 * N[(a * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] + N[Power[b, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{\mathsf{fma}\left(a, 0.5 \cdot \mathsf{fma}\left(a, \frac{c}{{b}^{3}}, {b}^{-1}\right), -0.5 \cdot \frac{b}{c}\right)}
\end{array}
Initial program 33.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6433.9
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6433.9
Applied rewrites33.9%
lift--.f64N/A
flip--N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-*.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites34.6%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
distribute-lft-outN/A
lower-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6493.7
Applied rewrites93.7%
Final simplification93.7%
(FPCore (a b c) :precision binary64 (* (fma (/ (fma (* -2.0 (* a a)) c (* (- a) (* b b))) (pow b 5.0)) c (/ -1.0 b)) c))
double code(double a, double b, double c) {
return fma((fma((-2.0 * (a * a)), c, (-a * (b * b))) / pow(b, 5.0)), c, (-1.0 / b)) * c;
}
function code(a, b, c) return Float64(fma(Float64(fma(Float64(-2.0 * Float64(a * a)), c, Float64(Float64(-a) * Float64(b * b))) / (b ^ 5.0)), c, Float64(-1.0 / b)) * c) end
code[a_, b_, c_] := N[(N[(N[(N[(N[(-2.0 * N[(a * a), $MachinePrecision]), $MachinePrecision] * c + N[((-a) * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] * c + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\mathsf{fma}\left(-2 \cdot \left(a \cdot a\right), c, \left(-a\right) \cdot \left(b \cdot b\right)\right)}{{b}^{5}}, c, \frac{-1}{b}\right) \cdot c
\end{array}
Initial program 33.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.4%
Taylor expanded in b around 0
Applied rewrites93.4%
(FPCore (a b c) :precision binary64 (* (/ (fma (* -2.0 (* a a)) (* c c) (* (- (fma a c (* b b))) (* b b))) (pow b 5.0)) c))
double code(double a, double b, double c) {
return (fma((-2.0 * (a * a)), (c * c), (-fma(a, c, (b * b)) * (b * b))) / pow(b, 5.0)) * c;
}
function code(a, b, c) return Float64(Float64(fma(Float64(-2.0 * Float64(a * a)), Float64(c * c), Float64(Float64(-fma(a, c, Float64(b * b))) * Float64(b * b))) / (b ^ 5.0)) * c) end
code[a_, b_, c_] := N[(N[(N[(N[(-2.0 * N[(a * a), $MachinePrecision]), $MachinePrecision] * N[(c * c), $MachinePrecision] + N[((-N[(a * c + N[(b * b), $MachinePrecision]), $MachinePrecision]) * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(-2 \cdot \left(a \cdot a\right), c \cdot c, \left(-\mathsf{fma}\left(a, c, b \cdot b\right)\right) \cdot \left(b \cdot b\right)\right)}{{b}^{5}} \cdot c
\end{array}
Initial program 33.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.4%
Taylor expanded in b around 0
Applied rewrites93.0%
(FPCore (a b c)
:precision binary64
(if (<= b 0.00075)
(/
0.5
(/
a
(/
(fma b b (fma (* -4.0 c) a (* (- b) b)))
(+ (sqrt (fma (* -4.0 c) a (* b b))) b))))
(/ 0.5 (fma (/ a b) 0.5 (* (/ b c) -0.5)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.00075) {
tmp = 0.5 / (a / (fma(b, b, fma((-4.0 * c), a, (-b * b))) / (sqrt(fma((-4.0 * c), a, (b * b))) + b)));
} else {
tmp = 0.5 / fma((a / b), 0.5, ((b / c) * -0.5));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.00075) tmp = Float64(0.5 / Float64(a / Float64(fma(b, b, fma(Float64(-4.0 * c), a, Float64(Float64(-b) * b))) / Float64(sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) + b)))); else tmp = Float64(0.5 / fma(Float64(a / b), 0.5, Float64(Float64(b / c) * -0.5))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.00075], N[(0.5 / N[(a / N[(N[(b * b + N[(N[(-4.0 * c), $MachinePrecision] * a + N[((-b) * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(N[(a / b), $MachinePrecision] * 0.5 + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.00075:\\
\;\;\;\;\frac{0.5}{\frac{a}{\frac{\mathsf{fma}\left(b, b, \mathsf{fma}\left(-4 \cdot c, a, \left(-b\right) \cdot b\right)\right)}{\sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)} + b}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.5\right)}\\
\end{array}
\end{array}
if b < 7.5000000000000002e-4Initial program 78.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6479.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6479.0
Applied rewrites79.1%
lift--.f64N/A
flip--N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-*.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites80.0%
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
sub-divN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lower-/.f64N/A
Applied rewrites81.1%
if 7.5000000000000002e-4 < b Initial program 29.0%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6429.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6429.0
Applied rewrites29.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6493.4
Applied rewrites93.4%
(FPCore (a b c)
:precision binary64
(if (<= b 0.00075)
(/
(* 0.5 (fma b b (fma (* -4.0 c) a (* (- b) b))))
(* a (+ (sqrt (fma (* -4.0 c) a (* b b))) b)))
(/ 0.5 (fma (/ a b) 0.5 (* (/ b c) -0.5)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.00075) {
tmp = (0.5 * fma(b, b, fma((-4.0 * c), a, (-b * b)))) / (a * (sqrt(fma((-4.0 * c), a, (b * b))) + b));
} else {
tmp = 0.5 / fma((a / b), 0.5, ((b / c) * -0.5));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.00075) tmp = Float64(Float64(0.5 * fma(b, b, fma(Float64(-4.0 * c), a, Float64(Float64(-b) * b)))) / Float64(a * Float64(sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) + b))); else tmp = Float64(0.5 / fma(Float64(a / b), 0.5, Float64(Float64(b / c) * -0.5))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.00075], N[(N[(0.5 * N[(b * b + N[(N[(-4.0 * c), $MachinePrecision] * a + N[((-b) * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * N[(N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(N[(a / b), $MachinePrecision] * 0.5 + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.00075:\\
\;\;\;\;\frac{0.5 \cdot \mathsf{fma}\left(b, b, \mathsf{fma}\left(-4 \cdot c, a, \left(-b\right) \cdot b\right)\right)}{a \cdot \left(\sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)} + b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.5\right)}\\
\end{array}
\end{array}
if b < 7.5000000000000002e-4Initial program 78.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6479.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6479.0
Applied rewrites79.1%
lift--.f64N/A
flip--N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-*.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites80.0%
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
sub-divN/A
Applied rewrites81.1%
if 7.5000000000000002e-4 < b Initial program 29.0%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6429.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6429.0
Applied rewrites29.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6493.4
Applied rewrites93.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (* -4.0 c) a (* b b))))
(if (<= b 0.00075)
(/ (* 0.5 (- t_0 (* b b))) (* a (+ (sqrt t_0) b)))
(/ 0.5 (fma (/ a b) 0.5 (* (/ b c) -0.5))))))
double code(double a, double b, double c) {
double t_0 = fma((-4.0 * c), a, (b * b));
double tmp;
if (b <= 0.00075) {
tmp = (0.5 * (t_0 - (b * b))) / (a * (sqrt(t_0) + b));
} else {
tmp = 0.5 / fma((a / b), 0.5, ((b / c) * -0.5));
}
return tmp;
}
function code(a, b, c) t_0 = fma(Float64(-4.0 * c), a, Float64(b * b)) tmp = 0.0 if (b <= 0.00075) tmp = Float64(Float64(0.5 * Float64(t_0 - Float64(b * b))) / Float64(a * Float64(sqrt(t_0) + b))); else tmp = Float64(0.5 / fma(Float64(a / b), 0.5, Float64(Float64(b / c) * -0.5))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.00075], N[(N[(0.5 * N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * N[(N[Sqrt[t$95$0], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(N[(a / b), $MachinePrecision] * 0.5 + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)\\
\mathbf{if}\;b \leq 0.00075:\\
\;\;\;\;\frac{0.5 \cdot \left(t\_0 - b \cdot b\right)}{a \cdot \left(\sqrt{t\_0} + b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.5\right)}\\
\end{array}
\end{array}
if b < 7.5000000000000002e-4Initial program 78.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6479.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6479.0
Applied rewrites79.1%
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
lift--.f64N/A
flip--N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites80.8%
if 7.5000000000000002e-4 < b Initial program 29.0%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6429.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6429.0
Applied rewrites29.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6493.4
Applied rewrites93.4%
(FPCore (a b c) :precision binary64 (if (<= b 0.00075) (/ 0.5 (/ a (- (sqrt (fma b b (* (* -4.0 c) a))) b))) (/ 0.5 (fma (/ a b) 0.5 (* (/ b c) -0.5)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.00075) {
tmp = 0.5 / (a / (sqrt(fma(b, b, ((-4.0 * c) * a))) - b));
} else {
tmp = 0.5 / fma((a / b), 0.5, ((b / c) * -0.5));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.00075) tmp = Float64(0.5 / Float64(a / Float64(sqrt(fma(b, b, Float64(Float64(-4.0 * c) * a))) - b))); else tmp = Float64(0.5 / fma(Float64(a / b), 0.5, Float64(Float64(b / c) * -0.5))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.00075], N[(0.5 / N[(a / N[(N[Sqrt[N[(b * b + N[(N[(-4.0 * c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(N[(a / b), $MachinePrecision] * 0.5 + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.00075:\\
\;\;\;\;\frac{0.5}{\frac{a}{\sqrt{\mathsf{fma}\left(b, b, \left(-4 \cdot c\right) \cdot a\right)} - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.5\right)}\\
\end{array}
\end{array}
if b < 7.5000000000000002e-4Initial program 78.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6479.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6479.0
Applied rewrites79.1%
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f6479.4
Applied rewrites79.4%
if 7.5000000000000002e-4 < b Initial program 29.0%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6429.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6429.0
Applied rewrites29.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6493.4
Applied rewrites93.4%
(FPCore (a b c) :precision binary64 (if (<= b 0.00075) (/ (+ (- b) (sqrt (fma b b (* (* -4.0 c) a)))) (* 2.0 a)) (/ 0.5 (fma (/ a b) 0.5 (* (/ b c) -0.5)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.00075) {
tmp = (-b + sqrt(fma(b, b, ((-4.0 * c) * a)))) / (2.0 * a);
} else {
tmp = 0.5 / fma((a / b), 0.5, ((b / c) * -0.5));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.00075) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(Float64(-4.0 * c) * a)))) / Float64(2.0 * a)); else tmp = Float64(0.5 / fma(Float64(a / b), 0.5, Float64(Float64(b / c) * -0.5))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.00075], N[(N[((-b) + N[Sqrt[N[(b * b + N[(N[(-4.0 * c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(N[(a / b), $MachinePrecision] * 0.5 + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.00075:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, \left(-4 \cdot c\right) \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.5\right)}\\
\end{array}
\end{array}
if b < 7.5000000000000002e-4Initial program 78.9%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.3
Applied rewrites79.3%
if 7.5000000000000002e-4 < b Initial program 29.0%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6429.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6429.0
Applied rewrites29.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6493.4
Applied rewrites93.4%
(FPCore (a b c) :precision binary64 (if (<= b 0.00075) (* (/ 0.5 a) (- (sqrt (fma (* -4.0 c) a (* b b))) b)) (/ 0.5 (fma (/ a b) 0.5 (* (/ b c) -0.5)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.00075) {
tmp = (0.5 / a) * (sqrt(fma((-4.0 * c), a, (b * b))) - b);
} else {
tmp = 0.5 / fma((a / b), 0.5, ((b / c) * -0.5));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.00075) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) - b)); else tmp = Float64(0.5 / fma(Float64(a / b), 0.5, Float64(Float64(b / c) * -0.5))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.00075], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(N[(a / b), $MachinePrecision] * 0.5 + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.00075:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.5\right)}\\
\end{array}
\end{array}
if b < 7.5000000000000002e-4Initial program 78.9%
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.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6479.0
Applied rewrites79.2%
if 7.5000000000000002e-4 < b Initial program 29.0%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6429.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6429.0
Applied rewrites29.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6493.4
Applied rewrites93.4%
(FPCore (a b c) :precision binary64 (/ 0.5 (fma (/ a b) 0.5 (* (/ b c) -0.5))))
double code(double a, double b, double c) {
return 0.5 / fma((a / b), 0.5, ((b / c) * -0.5));
}
function code(a, b, c) return Float64(0.5 / fma(Float64(a / b), 0.5, Float64(Float64(b / c) * -0.5))) end
code[a_, b_, c_] := N[(0.5 / N[(N[(a / b), $MachinePrecision] * 0.5 + N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{\mathsf{fma}\left(\frac{a}{b}, 0.5, \frac{b}{c} \cdot -0.5\right)}
\end{array}
Initial program 33.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6433.9
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6433.9
Applied rewrites33.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6490.3
Applied rewrites90.3%
(FPCore (a b c) :precision binary64 (/ (fma a (/ (* c c) (* b b)) c) (- b)))
double code(double a, double b, double c) {
return fma(a, ((c * c) / (b * b)), c) / -b;
}
function code(a, b, c) return Float64(fma(a, Float64(Float64(c * c) / Float64(b * b)), c) / Float64(-b)) end
code[a_, b_, c_] := N[(N[(a * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(a, \frac{c \cdot c}{b \cdot b}, c\right)}{-b}
\end{array}
Initial program 33.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.4%
Taylor expanded in a around 0
Applied rewrites79.2%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-*r/N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6490.1
Applied rewrites90.1%
Final simplification90.1%
(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 33.9%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6479.4
Applied rewrites79.4%
(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 33.9%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-/.f6433.9
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6433.9
Applied rewrites33.9%
lift--.f64N/A
flip--N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-*.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites34.6%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f6434.5
Applied rewrites34.5%
Taylor expanded in a around 0
associate-*r/N/A
distribute-rgt-outN/A
metadata-evalN/A
mul0-rgtN/A
metadata-evalN/A
lower-/.f643.2
Applied rewrites3.2%
Final simplification3.2%
herbie shell --seed 2024307
(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)))