
(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 (* a (* a (* c c))))
(t_1 (* c (* c a)))
(t_2 (* b (* b (* b b)))))
(/
(-
(fma
-2.0
(/ (* t_1 (* c a)) t_2)
(- (* -5.0 (/ (* t_0 t_0) (* a (* (* b b) t_2)))) (/ t_1 (* b b))))
c)
b)))
double code(double a, double b, double c) {
double t_0 = a * (a * (c * c));
double t_1 = c * (c * a);
double t_2 = b * (b * (b * b));
return (fma(-2.0, ((t_1 * (c * a)) / t_2), ((-5.0 * ((t_0 * t_0) / (a * ((b * b) * t_2)))) - (t_1 / (b * b)))) - c) / b;
}
function code(a, b, c) t_0 = Float64(a * Float64(a * Float64(c * c))) t_1 = Float64(c * Float64(c * a)) t_2 = Float64(b * Float64(b * Float64(b * b))) return Float64(Float64(fma(-2.0, Float64(Float64(t_1 * Float64(c * a)) / t_2), Float64(Float64(-5.0 * Float64(Float64(t_0 * t_0) / Float64(a * Float64(Float64(b * b) * t_2)))) - Float64(t_1 / Float64(b * b)))) - c) / b) end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(c * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(b * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(-2.0 * N[(N[(t$95$1 * N[(c * a), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision] + N[(N[(-5.0 * N[(N[(t$95$0 * t$95$0), $MachinePrecision] / N[(a * N[(N[(b * b), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t$95$1 / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - c), $MachinePrecision] / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(a \cdot \left(c \cdot c\right)\right)\\
t_1 := c \cdot \left(c \cdot a\right)\\
t_2 := b \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
\frac{\mathsf{fma}\left(-2, \frac{t\_1 \cdot \left(c \cdot a\right)}{t\_2}, -5 \cdot \frac{t\_0 \cdot t\_0}{a \cdot \left(\left(b \cdot b\right) \cdot t\_2\right)} - \frac{t\_1}{b \cdot b}\right) - c}{b}
\end{array}
\end{array}
Initial program 31.6%
Taylor expanded in b around inf
Simplified95.0%
Applied egg-rr95.0%
associate-*l*N/A
*-commutativeN/A
times-fracN/A
*-lowering-*.f64N/A
metadata-evalN/A
/-lowering-/.f64N/A
Applied egg-rr95.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* a (* c a)))) (t_1 (* b (* b b))))
(/
(-
(fma
(* -5.0 t_0)
(/ t_0 (* t_1 (* b (* a (* b b)))))
(/ (* (* a (* c c)) (* -2.0 (* c a))) (* b t_1)))
(fma (* c c) (/ a (* b b)) c))
b)))
double code(double a, double b, double c) {
double t_0 = c * (a * (c * a));
double t_1 = b * (b * b);
return (fma((-5.0 * t_0), (t_0 / (t_1 * (b * (a * (b * b))))), (((a * (c * c)) * (-2.0 * (c * a))) / (b * t_1))) - fma((c * c), (a / (b * b)), c)) / b;
}
function code(a, b, c) t_0 = Float64(c * Float64(a * Float64(c * a))) t_1 = Float64(b * Float64(b * b)) return Float64(Float64(fma(Float64(-5.0 * t_0), Float64(t_0 / Float64(t_1 * Float64(b * Float64(a * Float64(b * b))))), Float64(Float64(Float64(a * Float64(c * c)) * Float64(-2.0 * Float64(c * a))) / Float64(b * t_1))) - fma(Float64(c * c), Float64(a / Float64(b * b)), c)) / b) end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(-5.0 * t$95$0), $MachinePrecision] * N[(t$95$0 / N[(t$95$1 * N[(b * N[(a * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision] * N[(-2.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b * t$95$1), $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 := c \cdot \left(a \cdot \left(c \cdot a\right)\right)\\
t_1 := b \cdot \left(b \cdot b\right)\\
\frac{\mathsf{fma}\left(-5 \cdot t\_0, \frac{t\_0}{t\_1 \cdot \left(b \cdot \left(a \cdot \left(b \cdot b\right)\right)\right)}, \frac{\left(a \cdot \left(c \cdot c\right)\right) \cdot \left(-2 \cdot \left(c \cdot a\right)\right)}{b \cdot t\_1}\right) - \mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{b}
\end{array}
\end{array}
Initial program 31.6%
Taylor expanded in b around inf
Simplified95.0%
Applied egg-rr95.0%
associate-*l*N/A
*-commutativeN/A
times-fracN/A
*-lowering-*.f64N/A
metadata-evalN/A
/-lowering-/.f64N/A
Applied egg-rr95.0%
Applied egg-rr95.0%
Final simplification95.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* b (* b (* b b)))) (t_1 (* a (* a (* c c)))))
(/
(-
(fma
-5.0
(/ (* t_1 t_1) (* a (* (* b b) t_0)))
(/ (* -2.0 (* c t_1)) t_0))
(* c (fma a (/ c (* b b)) 1.0)))
b)))
double code(double a, double b, double c) {
double t_0 = b * (b * (b * b));
double t_1 = a * (a * (c * c));
return (fma(-5.0, ((t_1 * t_1) / (a * ((b * b) * t_0))), ((-2.0 * (c * t_1)) / t_0)) - (c * fma(a, (c / (b * b)), 1.0))) / b;
}
function code(a, b, c) t_0 = Float64(b * Float64(b * Float64(b * b))) t_1 = Float64(a * Float64(a * Float64(c * c))) return Float64(Float64(fma(-5.0, Float64(Float64(t_1 * t_1) / Float64(a * Float64(Float64(b * b) * t_0))), Float64(Float64(-2.0 * Float64(c * t_1)) / t_0)) - Float64(c * fma(a, Float64(c / Float64(b * b)), 1.0))) / b) end
code[a_, b_, c_] := Block[{t$95$0 = N[(b * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a * N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(-5.0 * N[(N[(t$95$1 * t$95$1), $MachinePrecision] / N[(a * N[(N[(b * b), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(c * t$95$1), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] - N[(c * N[(a * N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot \left(b \cdot b\right)\right)\\
t_1 := a \cdot \left(a \cdot \left(c \cdot c\right)\right)\\
\frac{\mathsf{fma}\left(-5, \frac{t\_1 \cdot t\_1}{a \cdot \left(\left(b \cdot b\right) \cdot t\_0\right)}, \frac{-2 \cdot \left(c \cdot t\_1\right)}{t\_0}\right) - c \cdot \mathsf{fma}\left(a, \frac{c}{b \cdot b}, 1\right)}{b}
\end{array}
\end{array}
Initial program 31.6%
Taylor expanded in b around inf
Simplified95.0%
Applied egg-rr95.0%
Applied egg-rr94.9%
Final simplification94.9%
(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)) -500.0)
(/ (/ (- t_0 (* b b)) (* a 2.0)) (+ b (sqrt t_0)))
(/ (fma (* c c) (/ a (* b b)) c) (- 0.0 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)) <= -500.0) {
tmp = ((t_0 - (b * b)) / (a * 2.0)) / (b + sqrt(t_0));
} else {
tmp = fma((c * c), (a / (b * b)), c) / (0.0 - b);
}
return tmp;
}
function code(a, b, c) t_0 = fma(Float64(c * 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)) <= -500.0) tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) / Float64(a * 2.0)) / Float64(b + sqrt(t_0))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(0.0 - 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[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], -500.0], N[(N[(N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $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] / N[(0.0 - b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2} \leq -500:\\
\;\;\;\;\frac{\frac{t\_0 - b \cdot b}{a \cdot 2}}{b + \sqrt{t\_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{0 - 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)) < -500Initial program 78.5%
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval78.4
Applied egg-rr78.4%
flip--N/A
associate-/l/N/A
rem-square-sqrtN/A
div-subN/A
--lowering--.f64N/A
Applied egg-rr78.0%
sub-divN/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
sqrt-lowering-sqrt.f64N/A
Applied egg-rr79.9%
if -500 < (/.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 27.2%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6493.9
Simplified93.9%
Final simplification92.7%
(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)) -500.0)
(/ (* (- t_0 (* b b)) (/ 0.5 a)) (+ b (sqrt t_0)))
(/ (fma (* c c) (/ a (* b b)) c) (- 0.0 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)) <= -500.0) {
tmp = ((t_0 - (b * b)) * (0.5 / a)) / (b + sqrt(t_0));
} else {
tmp = fma((c * c), (a / (b * b)), c) / (0.0 - 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)) <= -500.0) tmp = Float64(Float64(Float64(t_0 - Float64(b * b)) * Float64(0.5 / a)) / Float64(b + sqrt(t_0))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(0.0 - 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], -500.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[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / N[(0.0 - 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 -500:\\
\;\;\;\;\frac{\left(t\_0 - b \cdot b\right) \cdot \frac{0.5}{a}}{b + \sqrt{t\_0}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{0 - 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)) < -500Initial program 78.5%
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval78.4
Applied egg-rr78.4%
div-invN/A
flip--N/A
associate-*l/N/A
/-lowering-/.f64N/A
Applied egg-rr79.9%
if -500 < (/.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 27.2%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6493.9
Simplified93.9%
Final simplification92.7%
(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)) -500.0)
(/ (- t_0 (* b b)) (* (* a 2.0) (+ b (sqrt t_0))))
(/ (fma (* c c) (/ a (* b b)) c) (- 0.0 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)) <= -500.0) {
tmp = (t_0 - (b * b)) / ((a * 2.0) * (b + sqrt(t_0)));
} else {
tmp = fma((c * c), (a / (b * b)), c) / (0.0 - 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)) <= -500.0) tmp = Float64(Float64(t_0 - Float64(b * b)) / Float64(Float64(a * 2.0) * Float64(b + sqrt(t_0)))); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(0.0 - 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], -500.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[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / N[(0.0 - 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 -500:\\
\;\;\;\;\frac{t\_0 - b \cdot b}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{t\_0}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{0 - 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)) < -500Initial program 78.5%
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval78.4
Applied egg-rr78.4%
flip--N/A
associate-/l/N/A
/-lowering-/.f64N/A
rem-square-sqrtN/A
--lowering--.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
Applied egg-rr79.9%
if -500 < (/.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 27.2%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6493.9
Simplified93.9%
Final simplification92.7%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -500.0) (/ (- (sqrt (fma (* c -4.0) a (* b b))) b) (* a 2.0)) (/ (fma (* c c) (/ a (* b b)) c) (- 0.0 b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0)) <= -500.0) {
tmp = (sqrt(fma((c * -4.0), a, (b * b))) - b) / (a * 2.0);
} else {
tmp = fma((c * c), (a / (b * b)), c) / (0.0 - b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) <= -500.0) tmp = Float64(Float64(sqrt(fma(Float64(c * -4.0), a, Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(0.0 - 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], -500.0], N[(N[(N[Sqrt[N[(N[(c * -4.0), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / N[(0.0 - 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 -500:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{0 - 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)) < -500Initial program 78.5%
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-eval78.4
Applied egg-rr78.4%
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6478.5
Applied egg-rr78.5%
if -500 < (/.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 27.2%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6493.9
Simplified93.9%
Final simplification92.6%
(FPCore (a b c) :precision binary64 (/ (- (/ (- (/ (* (* a a) (* -2.0 (* c (* c c)))) (* b b)) (* a (* c c))) (* b b)) c) b))
double code(double a, double b, double c) {
return ((((((a * a) * (-2.0 * (c * (c * c)))) / (b * b)) - (a * (c * c))) / (b * b)) - c) / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((((((a * a) * ((-2.0d0) * (c * (c * c)))) / (b * b)) - (a * (c * c))) / (b * b)) - c) / b
end function
public static double code(double a, double b, double c) {
return ((((((a * a) * (-2.0 * (c * (c * c)))) / (b * b)) - (a * (c * c))) / (b * b)) - c) / b;
}
def code(a, b, c): return ((((((a * a) * (-2.0 * (c * (c * c)))) / (b * b)) - (a * (c * c))) / (b * b)) - c) / b
function code(a, b, c) return Float64(Float64(Float64(Float64(Float64(Float64(Float64(a * a) * Float64(-2.0 * Float64(c * Float64(c * c)))) / Float64(b * b)) - Float64(a * Float64(c * c))) / Float64(b * b)) - c) / b) end
function tmp = code(a, b, c) tmp = ((((((a * a) * (-2.0 * (c * (c * c)))) / (b * b)) - (a * (c * c))) / (b * b)) - c) / b; end
code[a_, b_, c_] := N[(N[(N[(N[(N[(N[(N[(a * a), $MachinePrecision] * N[(-2.0 * N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] - N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] - c), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{\left(a \cdot a\right) \cdot \left(-2 \cdot \left(c \cdot \left(c \cdot c\right)\right)\right)}{b \cdot b} - a \cdot \left(c \cdot c\right)}{b \cdot b} - c}{b}
\end{array}
Initial program 31.6%
Taylor expanded in b around inf
Simplified95.0%
Applied egg-rr95.0%
Taylor expanded in b around inf
/-lowering-/.f64N/A
Simplified93.6%
(FPCore (a b c)
:precision binary64
(/
(*
c
(fma
c
(- (/ (* -2.0 (* a (* c a))) (* (* b b) (* b b))) (/ a (* b b)))
-1.0))
b))
double code(double a, double b, double c) {
return (c * fma(c, (((-2.0 * (a * (c * a))) / ((b * b) * (b * b))) - (a / (b * b))), -1.0)) / b;
}
function code(a, b, c) return Float64(Float64(c * fma(c, Float64(Float64(Float64(-2.0 * Float64(a * Float64(c * a))) / Float64(Float64(b * b) * Float64(b * b))) - Float64(a / Float64(b * b))), -1.0)) / b) end
code[a_, b_, c_] := N[(N[(c * N[(c * N[(N[(N[(-2.0 * N[(a * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot \mathsf{fma}\left(c, \frac{-2 \cdot \left(a \cdot \left(c \cdot a\right)\right)}{\left(b \cdot b\right) \cdot \left(b \cdot b\right)} - \frac{a}{b \cdot b}, -1\right)}{b}
\end{array}
Initial program 31.6%
Taylor expanded in b around inf
Simplified95.0%
Applied egg-rr95.0%
Taylor expanded in c around 0
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
Simplified93.5%
Final simplification93.5%
(FPCore (a b c) :precision binary64 (/ (fma (* c c) (/ a (* b b)) c) (- 0.0 b)))
double code(double a, double b, double c) {
return fma((c * c), (a / (b * b)), c) / (0.0 - b);
}
function code(a, b, c) return Float64(fma(Float64(c * c), Float64(a / Float64(b * b)), c) / Float64(0.0 - b)) end
code[a_, b_, c_] := N[(N[(N[(c * c), $MachinePrecision] * N[(a / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / N[(0.0 - b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(c \cdot c, \frac{a}{b \cdot b}, c\right)}{0 - b}
\end{array}
Initial program 31.6%
Taylor expanded in b around inf
distribute-lft-outN/A
associate-/l*N/A
mul-1-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6490.9
Simplified90.9%
Final simplification90.9%
(FPCore (a b c) :precision binary64 (/ c (- 0.0 b)))
double code(double a, double b, double c) {
return c / (0.0 - b);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / (0.0d0 - b)
end function
public static double code(double a, double b, double c) {
return c / (0.0 - b);
}
def code(a, b, c): return c / (0.0 - b)
function code(a, b, c) return Float64(c / Float64(0.0 - b)) end
function tmp = code(a, b, c) tmp = c / (0.0 - b); end
code[a_, b_, c_] := N[(c / N[(0.0 - b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{0 - b}
\end{array}
Initial program 31.6%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6481.6
Simplified81.6%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6481.6
Applied egg-rr81.6%
Final simplification81.6%
herbie shell --seed 2024197
(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)))