
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \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) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -3.0) (* b b))) (t_1 (* (/ c (* b (* b b))) 0.375)))
(if (<= b 0.33)
(/ (/ (- (* b b) t_0) (* a (+ b (sqrt t_0)))) -3.0)
(/
1.0
(fma
a
(fma
a
(*
3.0
(fma
a
(fma
-0.75
(/ (* c t_1) (* b b))
(fma
0.2222222222222222
(/ (* b (* (/ (pow c 4.0) (pow b 6.0)) 6.328125)) (* c c))
(/ (* (* c c) -0.5625) (pow b 5.0))))
t_1))
(/ 1.5 b))
(/ (* b -2.0) c))))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -3.0), (b * b));
double t_1 = (c / (b * (b * b))) * 0.375;
double tmp;
if (b <= 0.33) {
tmp = (((b * b) - t_0) / (a * (b + sqrt(t_0)))) / -3.0;
} else {
tmp = 1.0 / fma(a, fma(a, (3.0 * fma(a, fma(-0.75, ((c * t_1) / (b * b)), fma(0.2222222222222222, ((b * ((pow(c, 4.0) / pow(b, 6.0)) * 6.328125)) / (c * c)), (((c * c) * -0.5625) / pow(b, 5.0)))), t_1)), (1.5 / b)), ((b * -2.0) / c));
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -3.0), Float64(b * b)) t_1 = Float64(Float64(c / Float64(b * Float64(b * b))) * 0.375) tmp = 0.0 if (b <= 0.33) tmp = Float64(Float64(Float64(Float64(b * b) - t_0) / Float64(a * Float64(b + sqrt(t_0)))) / -3.0); else tmp = Float64(1.0 / fma(a, fma(a, Float64(3.0 * fma(a, fma(-0.75, Float64(Float64(c * t_1) / Float64(b * b)), fma(0.2222222222222222, Float64(Float64(b * Float64(Float64((c ^ 4.0) / (b ^ 6.0)) * 6.328125)) / Float64(c * c)), Float64(Float64(Float64(c * c) * -0.5625) / (b ^ 5.0)))), t_1)), Float64(1.5 / b)), Float64(Float64(b * -2.0) / c))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.375), $MachinePrecision]}, If[LessEqual[b, 0.33], N[(N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(a * N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -3.0), $MachinePrecision], N[(1.0 / N[(a * N[(a * N[(3.0 * N[(a * N[(-0.75 * N[(N[(c * t$95$1), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(0.2222222222222222 * N[(N[(b * N[(N[(N[Power[c, 4.0], $MachinePrecision] / N[Power[b, 6.0], $MachinePrecision]), $MachinePrecision] * 6.328125), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(c * c), $MachinePrecision] * -0.5625), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision] + N[(1.5 / b), $MachinePrecision]), $MachinePrecision] + N[(N[(b * -2.0), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)\\
t_1 := \frac{c}{b \cdot \left(b \cdot b\right)} \cdot 0.375\\
\mathbf{if}\;b \leq 0.33:\\
\;\;\;\;\frac{\frac{b \cdot b - t\_0}{a \cdot \left(b + \sqrt{t\_0}\right)}}{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, 3 \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(-0.75, \frac{c \cdot t\_1}{b \cdot b}, \mathsf{fma}\left(0.2222222222222222, \frac{b \cdot \left(\frac{{c}^{4}}{{b}^{6}} \cdot 6.328125\right)}{c \cdot c}, \frac{\left(c \cdot c\right) \cdot -0.5625}{{b}^{5}}\right)\right), t\_1\right), \frac{1.5}{b}\right), \frac{b \cdot -2}{c}\right)}\\
\end{array}
\end{array}
if b < 0.330000000000000016Initial program 87.2%
Applied egg-rr87.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied egg-rr88.9%
if 0.330000000000000016 < b Initial program 50.6%
Applied egg-rr50.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6450.6
Applied egg-rr50.6%
Taylor expanded in a around 0
Simplified94.7%
Final simplification94.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* b (* b b))) (t_1 (fma c (* a -3.0) (* b b))) (t_2 (* b t_0)))
(if (<= b 0.38)
(/ (/ (- (* b b) t_1) (* a (+ b (sqrt t_1)))) -3.0)
(fma
a
(fma
a
(fma
(/ (/ (* (* c (* c (* c c))) (* a 6.328125)) (* (* b b) t_2)) b)
-0.16666666666666666
(/ (* c (* (* c c) -0.5625)) (* b t_2)))
(/ (* (* c c) -0.375) t_0))
(/ (* c -0.5) b)))))
double code(double a, double b, double c) {
double t_0 = b * (b * b);
double t_1 = fma(c, (a * -3.0), (b * b));
double t_2 = b * t_0;
double tmp;
if (b <= 0.38) {
tmp = (((b * b) - t_1) / (a * (b + sqrt(t_1)))) / -3.0;
} else {
tmp = fma(a, fma(a, fma(((((c * (c * (c * c))) * (a * 6.328125)) / ((b * b) * t_2)) / b), -0.16666666666666666, ((c * ((c * c) * -0.5625)) / (b * t_2))), (((c * c) * -0.375) / t_0)), ((c * -0.5) / b));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(b * Float64(b * b)) t_1 = fma(c, Float64(a * -3.0), Float64(b * b)) t_2 = Float64(b * t_0) tmp = 0.0 if (b <= 0.38) tmp = Float64(Float64(Float64(Float64(b * b) - t_1) / Float64(a * Float64(b + sqrt(t_1)))) / -3.0); else tmp = fma(a, fma(a, fma(Float64(Float64(Float64(Float64(c * Float64(c * Float64(c * c))) * Float64(a * 6.328125)) / Float64(Float64(b * b) * t_2)) / b), -0.16666666666666666, Float64(Float64(c * Float64(Float64(c * c) * -0.5625)) / Float64(b * t_2))), Float64(Float64(Float64(c * c) * -0.375) / t_0)), Float64(Float64(c * -0.5) / b)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(b * t$95$0), $MachinePrecision]}, If[LessEqual[b, 0.38], N[(N[(N[(N[(b * b), $MachinePrecision] - t$95$1), $MachinePrecision] / N[(a * N[(b + N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -3.0), $MachinePrecision], N[(a * N[(a * N[(N[(N[(N[(N[(c * N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * 6.328125), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision] * -0.16666666666666666 + N[(N[(c * N[(N[(c * c), $MachinePrecision] * -0.5625), $MachinePrecision]), $MachinePrecision] / N[(b * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(c * c), $MachinePrecision] * -0.375), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot b\right)\\
t_1 := \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)\\
t_2 := b \cdot t\_0\\
\mathbf{if}\;b \leq 0.38:\\
\;\;\;\;\frac{\frac{b \cdot b - t\_1}{a \cdot \left(b + \sqrt{t\_1}\right)}}{-3}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(\frac{\frac{\left(c \cdot \left(c \cdot \left(c \cdot c\right)\right)\right) \cdot \left(a \cdot 6.328125\right)}{\left(b \cdot b\right) \cdot t\_2}}{b}, -0.16666666666666666, \frac{c \cdot \left(\left(c \cdot c\right) \cdot -0.5625\right)}{b \cdot t\_2}\right), \frac{\left(c \cdot c\right) \cdot -0.375}{t\_0}\right), \frac{c \cdot -0.5}{b}\right)\\
\end{array}
\end{array}
if b < 0.38Initial program 87.2%
Applied egg-rr87.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied egg-rr88.9%
if 0.38 < b Initial program 50.6%
Taylor expanded in a around 0
Simplified94.6%
lift-pow.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f6494.6
lift-pow.f64N/A
metadata-evalN/A
pow-sqrN/A
pow2N/A
pow2N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f6494.6
lift-pow.f64N/A
metadata-evalN/A
pow-powN/A
pow2N/A
lift-*.f64N/A
cube-multN/A
lower-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f6494.6
Applied egg-rr94.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
pow-prod-upN/A
pow2N/A
cube-unmultN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6494.6
Applied egg-rr94.6%
Final simplification94.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -3.0) (* b b))))
(if (<= b 0.38)
(/ (/ (- (* b b) t_0) (* a (+ b (sqrt t_0)))) -3.0)
(/
1.0
(fma
a
(fma (* a 3.0) (* (/ c (* b (* b b))) 0.375) (/ 1.5 b))
(/ (* b -2.0) c))))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -3.0), (b * b));
double tmp;
if (b <= 0.38) {
tmp = (((b * b) - t_0) / (a * (b + sqrt(t_0)))) / -3.0;
} else {
tmp = 1.0 / fma(a, fma((a * 3.0), ((c / (b * (b * b))) * 0.375), (1.5 / b)), ((b * -2.0) / c));
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -3.0), Float64(b * b)) tmp = 0.0 if (b <= 0.38) tmp = Float64(Float64(Float64(Float64(b * b) - t_0) / Float64(a * Float64(b + sqrt(t_0)))) / -3.0); else tmp = Float64(1.0 / fma(a, fma(Float64(a * 3.0), Float64(Float64(c / Float64(b * Float64(b * b))) * 0.375), Float64(1.5 / b)), Float64(Float64(b * -2.0) / c))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.38], N[(N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(a * N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -3.0), $MachinePrecision], N[(1.0 / N[(a * N[(N[(a * 3.0), $MachinePrecision] * N[(N[(c / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.375), $MachinePrecision] + N[(1.5 / b), $MachinePrecision]), $MachinePrecision] + N[(N[(b * -2.0), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)\\
\mathbf{if}\;b \leq 0.38:\\
\;\;\;\;\frac{\frac{b \cdot b - t\_0}{a \cdot \left(b + \sqrt{t\_0}\right)}}{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a \cdot 3, \frac{c}{b \cdot \left(b \cdot b\right)} \cdot 0.375, \frac{1.5}{b}\right), \frac{b \cdot -2}{c}\right)}\\
\end{array}
\end{array}
if b < 0.38Initial program 87.2%
Applied egg-rr87.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied egg-rr88.9%
if 0.38 < b Initial program 50.6%
Applied egg-rr50.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6450.6
Applied egg-rr50.6%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
Simplified92.6%
Final simplification92.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -3.0) (* b b))))
(if (<= b 0.38)
(/ (/ (- (* b b) t_0) (* a (+ b (sqrt t_0)))) -3.0)
(/ 1.0 (fma -2.0 (/ b c) (* 1.5 (/ a b)))))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -3.0), (b * b));
double tmp;
if (b <= 0.38) {
tmp = (((b * b) - t_0) / (a * (b + sqrt(t_0)))) / -3.0;
} else {
tmp = 1.0 / fma(-2.0, (b / c), (1.5 * (a / b)));
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -3.0), Float64(b * b)) tmp = 0.0 if (b <= 0.38) tmp = Float64(Float64(Float64(Float64(b * b) - t_0) / Float64(a * Float64(b + sqrt(t_0)))) / -3.0); else tmp = Float64(1.0 / fma(-2.0, Float64(b / c), Float64(1.5 * Float64(a / b)))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.38], N[(N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(a * N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -3.0), $MachinePrecision], N[(1.0 / N[(-2.0 * N[(b / c), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)\\
\mathbf{if}\;b \leq 0.38:\\
\;\;\;\;\frac{\frac{b \cdot b - t\_0}{a \cdot \left(b + \sqrt{t\_0}\right)}}{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, 1.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < 0.38Initial program 87.2%
Applied egg-rr87.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied egg-rr88.9%
if 0.38 < b Initial program 50.6%
Applied egg-rr50.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6450.6
Applied egg-rr50.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6487.3
Simplified87.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma c (* a -3.0) (* b b))))
(if (<= b 0.38)
(/ (- (* b b) t_0) (* (* a -3.0) (+ b (sqrt t_0))))
(/ 1.0 (fma -2.0 (/ b c) (* 1.5 (/ a b)))))))
double code(double a, double b, double c) {
double t_0 = fma(c, (a * -3.0), (b * b));
double tmp;
if (b <= 0.38) {
tmp = ((b * b) - t_0) / ((a * -3.0) * (b + sqrt(t_0)));
} else {
tmp = 1.0 / fma(-2.0, (b / c), (1.5 * (a / b)));
}
return tmp;
}
function code(a, b, c) t_0 = fma(c, Float64(a * -3.0), Float64(b * b)) tmp = 0.0 if (b <= 0.38) tmp = Float64(Float64(Float64(b * b) - t_0) / Float64(Float64(a * -3.0) * Float64(b + sqrt(t_0)))); else tmp = Float64(1.0 / fma(-2.0, Float64(b / c), Float64(1.5 * Float64(a / b)))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.38], N[(N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(a * -3.0), $MachinePrecision] * N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(-2.0 * N[(b / c), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)\\
\mathbf{if}\;b \leq 0.38:\\
\;\;\;\;\frac{b \cdot b - t\_0}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{t\_0}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, 1.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < 0.38Initial program 87.2%
Applied egg-rr87.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
lift--.f64N/A
flip--N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
Applied egg-rr88.8%
if 0.38 < b Initial program 50.6%
Applied egg-rr50.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6450.6
Applied egg-rr50.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6487.3
Simplified87.3%
(FPCore (a b c) :precision binary64 (if (<= b 0.38) (/ (/ (- b (sqrt (fma b b (* c (* a -3.0))))) a) -3.0) (/ 1.0 (fma -2.0 (/ b c) (* 1.5 (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.38) {
tmp = ((b - sqrt(fma(b, b, (c * (a * -3.0))))) / a) / -3.0;
} else {
tmp = 1.0 / fma(-2.0, (b / c), (1.5 * (a / b)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.38) tmp = Float64(Float64(Float64(b - sqrt(fma(b, b, Float64(c * Float64(a * -3.0))))) / a) / -3.0); else tmp = Float64(1.0 / fma(-2.0, Float64(b / c), Float64(1.5 * Float64(a / b)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.38], N[(N[(N[(b - N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / -3.0), $MachinePrecision], N[(1.0 / N[(-2.0 * N[(b / c), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.38:\\
\;\;\;\;\frac{\frac{b - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)}}{a}}{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, 1.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < 0.38Initial program 87.2%
Applied egg-rr87.6%
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6487.6
Applied egg-rr87.6%
if 0.38 < b Initial program 50.6%
Applied egg-rr50.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6450.6
Applied egg-rr50.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6487.3
Simplified87.3%
(FPCore (a b c) :precision binary64 (if (<= b 0.38) (/ (/ (- b (sqrt (fma a (* c -3.0) (* b b)))) a) -3.0) (/ 1.0 (fma -2.0 (/ b c) (* 1.5 (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.38) {
tmp = ((b - sqrt(fma(a, (c * -3.0), (b * b)))) / a) / -3.0;
} else {
tmp = 1.0 / fma(-2.0, (b / c), (1.5 * (a / b)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.38) tmp = Float64(Float64(Float64(b - sqrt(fma(a, Float64(c * -3.0), Float64(b * b)))) / a) / -3.0); else tmp = Float64(1.0 / fma(-2.0, Float64(b / c), Float64(1.5 * Float64(a / b)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.38], N[(N[(N[(b - N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / -3.0), $MachinePrecision], N[(1.0 / N[(-2.0 * N[(b / c), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.38:\\
\;\;\;\;\frac{\frac{b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{a}}{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, 1.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < 0.38Initial program 87.2%
Applied egg-rr87.6%
if 0.38 < b Initial program 50.6%
Applied egg-rr50.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6450.6
Applied egg-rr50.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6487.3
Simplified87.3%
Final simplification87.4%
(FPCore (a b c) :precision binary64 (if (<= b 0.38) (* (- b (sqrt (fma a (* c -3.0) (* b b)))) (/ -0.3333333333333333 a)) (/ 1.0 (fma -2.0 (/ b c) (* 1.5 (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.38) {
tmp = (b - sqrt(fma(a, (c * -3.0), (b * b)))) * (-0.3333333333333333 / a);
} else {
tmp = 1.0 / fma(-2.0, (b / c), (1.5 * (a / b)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 0.38) tmp = Float64(Float64(b - sqrt(fma(a, Float64(c * -3.0), Float64(b * b)))) * Float64(-0.3333333333333333 / a)); else tmp = Float64(1.0 / fma(-2.0, Float64(b / c), Float64(1.5 * Float64(a / b)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 0.38], N[(N[(b - N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.3333333333333333 / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(-2.0 * N[(b / c), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.38:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \frac{-0.3333333333333333}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, 1.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < 0.38Initial program 87.2%
Applied egg-rr87.5%
if 0.38 < b Initial program 50.6%
Applied egg-rr50.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6450.6
Applied egg-rr50.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6487.3
Simplified87.3%
Final simplification87.4%
(FPCore (a b c) :precision binary64 (/ 1.0 (fma -2.0 (/ b c) (* 1.5 (/ a b)))))
double code(double a, double b, double c) {
return 1.0 / fma(-2.0, (b / c), (1.5 * (a / b)));
}
function code(a, b, c) return Float64(1.0 / fma(-2.0, Float64(b / c), Float64(1.5 * Float64(a / b)))) end
code[a_, b_, c_] := N[(1.0 / N[(-2.0 * N[(b / c), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, 1.5 \cdot \frac{a}{b}\right)}
\end{array}
Initial program 54.0%
Applied egg-rr54.1%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
associate-/l/N/A
clear-numN/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lift-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f6454.0
Applied egg-rr54.0%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6483.6
Simplified83.6%
(FPCore (a b c) :precision binary64 (/ (* c -0.5) b))
double code(double a, double b, double c) {
return (c * -0.5) / 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.5d0)) / b
end function
public static double code(double a, double b, double c) {
return (c * -0.5) / b;
}
def code(a, b, c): return (c * -0.5) / b
function code(a, b, c) return Float64(Float64(c * -0.5) / b) end
function tmp = code(a, b, c) tmp = (c * -0.5) / b; end
code[a_, b_, c_] := N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot -0.5}{b}
\end{array}
Initial program 54.0%
Taylor expanded in b around inf
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6465.8
Simplified65.8%
(FPCore (a b c) :precision binary64 (* c (/ -0.5 b)))
double code(double a, double b, double c) {
return c * (-0.5 / 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.5d0) / b)
end function
public static double code(double a, double b, double c) {
return c * (-0.5 / b);
}
def code(a, b, c): return c * (-0.5 / b)
function code(a, b, c) return Float64(c * Float64(-0.5 / b)) end
function tmp = code(a, b, c) tmp = c * (-0.5 / b); end
code[a_, b_, c_] := N[(c * N[(-0.5 / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \frac{-0.5}{b}
\end{array}
Initial program 54.0%
Taylor expanded in b around inf
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6465.8
Simplified65.8%
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6465.7
Applied egg-rr65.7%
Final simplification65.7%
herbie shell --seed 2024219
(FPCore (a b c)
:name "Cubic critical, 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) (* (* 3.0 a) c)))) (* 3.0 a)))