
(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 (fma (* c a) -4.0 (* b b))) (t_1 (* b (* b (* b b)))))
(if (<= b 5.0)
(/ (/ (- t_0 (* b b)) (+ b (sqrt t_0))) (* a 2.0))
(/
(-
(fma
(/ (* c (* c (* a (* c a)))) t_1)
-2.0
(/
(* -5.0 (* (* c (* c (* c c))) (* a (* a (* a a)))))
(* a (* (* b b) t_1))))
(fma (* c a) (/ c (* b b)) c))
b))))
double code(double a, double b, double c) {
double t_0 = fma((c * a), -4.0, (b * b));
double t_1 = b * (b * (b * b));
double tmp;
if (b <= 5.0) {
tmp = ((t_0 - (b * b)) / (b + sqrt(t_0))) / (a * 2.0);
} else {
tmp = (fma(((c * (c * (a * (c * a)))) / t_1), -2.0, ((-5.0 * ((c * (c * (c * c))) * (a * (a * (a * a))))) / (a * ((b * b) * t_1)))) - fma((c * a), (c / (b * b)), c)) / b;
}
return tmp;
}
function code(a, b, c) t_0 = fma(Float64(c * a), -4.0, Float64(b * b)) t_1 = Float64(b * Float64(b * Float64(b * b))) tmp = 0.0 if (b <= 5.0) tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) / Float64(b + sqrt(t_0))) / Float64(a * 2.0)); else tmp = Float64(Float64(fma(Float64(Float64(c * Float64(c * Float64(a * Float64(c * a)))) / t_1), -2.0, Float64(Float64(-5.0 * Float64(Float64(c * Float64(c * Float64(c * c))) * Float64(a * Float64(a * Float64(a * a))))) / Float64(a * Float64(Float64(b * b) * t_1)))) - fma(Float64(c * a), Float64(c / Float64(b * b)), c)) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c * a), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 5.0], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(c * N[(c * N[(a * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision] * -2.0 + N[(N[(-5.0 * N[(N[(c * N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * N[(N[(b * b), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c * a), $MachinePrecision] * N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)\\
t_1 := b \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
\mathbf{if}\;b \leq 5:\\
\;\;\;\;\frac{\frac{t\_0 - b \cdot b}{b + \sqrt{t\_0}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c \cdot \left(c \cdot \left(a \cdot \left(c \cdot a\right)\right)\right)}{t\_1}, -2, \frac{-5 \cdot \left(\left(c \cdot \left(c \cdot \left(c \cdot c\right)\right)\right) \cdot \left(a \cdot \left(a \cdot \left(a \cdot a\right)\right)\right)\right)}{a \cdot \left(\left(b \cdot b\right) \cdot t\_1\right)}\right) - \mathsf{fma}\left(c \cdot a, \frac{c}{b \cdot b}, c\right)}{b}\\
\end{array}
\end{array}
if b < 5Initial program 82.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6482.8
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval82.6
Applied rewrites82.6%
Applied rewrites81.6%
Applied rewrites83.9%
if 5 < b Initial program 49.0%
Taylor expanded in b around inf
Applied rewrites94.2%
Applied rewrites94.2%
Applied rewrites94.2%
Final simplification92.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -0.00195)
(/ (/ (- t_0 (* b b)) (+ b (sqrt t_0))) (* a 2.0))
(- (fma a (/ (* c c) (* b (* 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 * (a * 4.0)))) - b) / (a * 2.0)) <= -0.00195) {
tmp = ((t_0 - (b * b)) / (b + sqrt(t_0))) / (a * 2.0);
} else {
tmp = -fma(a, ((c * c) / (b * (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(a * 4.0)))) - b) / Float64(a * 2.0)) <= -0.00195) tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) / Float64(b + sqrt(t_0))) / Float64(a * 2.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[(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[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -0.00195], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $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(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2} \leq -0.00195:\\
\;\;\;\;\frac{\frac{t\_0 - b \cdot b}{b + \sqrt{t\_0}}}{a \cdot 2}\\
\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.0019499999999999999Initial program 78.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6478.0
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval78.0
Applied rewrites78.0%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites79.5%
if -0.0019499999999999999 < (/.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 44.2%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6444.2
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval44.2
Applied rewrites44.2%
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-/.f6489.7
Applied rewrites89.7%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma (* c a) -4.0 (* b b))))
(if (<= b 5.0)
(/ (/ (- t_0 (* b b)) (+ b (sqrt t_0))) (* a 2.0))
(/
(-
(* (* -2.0 (* a a)) (/ (* 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 <= 5.0) {
tmp = ((t_0 - (b * b)) / (b + sqrt(t_0))) / (a * 2.0);
} else {
tmp = (((-2.0 * (a * a)) * ((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(Float64(c * a), -4.0, Float64(b * b)) tmp = 0.0 if (b <= 5.0) tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) / Float64(b + sqrt(t_0))) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(Float64(-2.0 * Float64(a * a)) * 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[(N[(c * a), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 5.0], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-2.0 * N[(a * a), $MachinePrecision]), $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 \cdot a, -4, b \cdot b\right)\\
\mathbf{if}\;b \leq 5:\\
\;\;\;\;\frac{\frac{t\_0 - b \cdot b}{b + \sqrt{t\_0}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-2 \cdot \left(a \cdot a\right)\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 < 5Initial program 82.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6482.8
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval82.6
Applied rewrites82.6%
Applied rewrites81.6%
Applied rewrites83.9%
if 5 < b Initial program 49.0%
Taylor expanded in b around inf
lower-/.f64N/A
Applied rewrites92.0%
Final simplification90.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= b 14.0)
(/ (* (- t_0 (* b b)) (/ 0.5 a)) (+ 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(c, (a * -4.0), (b * b));
double tmp;
if (b <= 14.0) {
tmp = ((t_0 - (b * b)) * (0.5 / a)) / (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(c, Float64(a * -4.0), Float64(b * b)) tmp = 0.0 if (b <= 14.0) tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) * Float64(0.5 / a)) / 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[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 14.0], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$0], $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(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;b \leq 14:\\
\;\;\;\;\frac{\left(t\_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{b + \sqrt{t\_0}}\\
\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 b < 14Initial program 81.4%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6481.4
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval81.2
Applied rewrites81.2%
Applied rewrites82.4%
if 14 < b Initial program 48.3%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6448.3
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval48.3
Applied rewrites48.3%
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-/.f6487.2
Applied rewrites87.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -4.0) (* b b))))
(if (<= b 14.0)
(/ (- 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(c, (a * -4.0), (b * b));
double tmp;
if (b <= 14.0) {
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(c, Float64(a * -4.0), Float64(b * b)) tmp = 0.0 if (b <= 14.0) 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[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 14.0], 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(c, a \cdot -4, b \cdot b\right)\\
\mathbf{if}\;b \leq 14:\\
\;\;\;\;\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 b < 14Initial program 81.4%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6481.4
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval81.2
Applied rewrites81.2%
Applied rewrites82.4%
if 14 < b Initial program 48.3%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6448.3
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval48.3
Applied rewrites48.3%
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-/.f6487.2
Applied rewrites87.2%
(FPCore (a b c) :precision binary64 (if (<= b 5.0) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (- (fma a (/ (* c c) (* b (* b b))) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.0) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = -fma(a, ((c * c) / (b * (b * b))), (c / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 5.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.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_] := If[LessEqual[b, 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[(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}
\mathbf{if}\;b \leq 5:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\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 b < 5Initial program 82.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6482.8
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval82.6
Applied rewrites82.6%
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6482.9
Applied rewrites82.9%
if 5 < b Initial program 49.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6449.0
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval49.0
Applied rewrites49.0%
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-/.f6486.6
Applied rewrites86.6%
Final simplification85.9%
(FPCore (a b c) :precision binary64 (if (<= b 5.0) (* (/ 0.5 a) (- (sqrt (fma (* c a) -4.0 (* b b))) b)) (- (fma a (/ (* c c) (* b (* b b))) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.0) {
tmp = (0.5 / a) * (sqrt(fma((c * a), -4.0, (b * b))) - b);
} else {
tmp = -fma(a, ((c * c) / (b * (b * b))), (c / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 5.0) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(fma(Float64(c * a), -4.0, Float64(b * b))) - b)); 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_] := If[LessEqual[b, 5.0], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $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}
\mathbf{if}\;b \leq 5:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - b\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 b < 5Initial program 82.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6482.8
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval82.6
Applied rewrites82.6%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
div-invN/A
lower-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-neg.f64N/A
lower-/.f6481.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6481.2
Applied rewrites81.2%
Applied rewrites82.8%
if 5 < b Initial program 49.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6449.0
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval49.0
Applied rewrites49.0%
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-/.f6486.6
Applied rewrites86.6%
(FPCore (a b c) :precision binary64 (if (<= b 5.0) (* (/ -0.5 a) (- b (sqrt (fma a (* c -4.0) (* b b))))) (- (fma a (/ (* c c) (* b (* b b))) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.0) {
tmp = (-0.5 / a) * (b - sqrt(fma(a, (c * -4.0), (b * b))));
} else {
tmp = -fma(a, ((c * c) / (b * (b * b))), (c / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 5.0) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(fma(a, Float64(c * -4.0), Float64(b * b))))); 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_] := If[LessEqual[b, 5.0], 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[(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}
\mathbf{if}\;b \leq 5:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\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 b < 5Initial program 82.8%
Applied rewrites82.6%
if 5 < b Initial program 49.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6449.0
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval49.0
Applied rewrites49.0%
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-/.f6486.6
Applied rewrites86.6%
Final simplification85.8%
(FPCore (a b c) :precision binary64 (- (fma a (/ (* c c) (* b (* b b))) (/ c b))))
double code(double a, double b, double c) {
return -fma(a, ((c * c) / (b * (b * b))), (c / b));
}
function code(a, b, c) return Float64(-fma(a, Float64(Float64(c * c) / Float64(b * Float64(b * b))), Float64(c / b))) end
code[a_, b_, c_] := (-N[(a * N[(N[(c * c), $MachinePrecision] / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision])
\begin{array}{l}
\\
-\mathsf{fma}\left(a, \frac{c \cdot c}{b \cdot \left(b \cdot b\right)}, \frac{c}{b}\right)
\end{array}
Initial program 56.1%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6456.1
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval56.0
Applied rewrites56.0%
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-/.f6480.5
Applied rewrites80.5%
(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 56.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-*.f6480.5
Applied rewrites80.5%
Final simplification80.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(-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 56.1%
Taylor expanded in b around inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-neg.f6463.7
Applied rewrites63.7%
Final simplification63.7%
(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 56.1%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6456.1
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval56.0
Applied rewrites56.0%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
sub-negN/A
div-invN/A
lower-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-neg.f64N/A
lower-/.f6455.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.9
Applied rewrites55.9%
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
div-invN/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lift-/.f6455.8
Applied rewrites55.8%
Taylor expanded in c around 0
distribute-rgt-outN/A
metadata-evalN/A
mul0-rgt3.2
Applied rewrites3.2%
herbie shell --seed 2024221
(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)))