
(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 4 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 (fma -0.5625 (/ (* (pow c 3.0) (* a a)) (pow b 5.0)) (fma -0.16666666666666666 (/ (pow (* c a) 4.0) (/ (* a (pow b 7.0)) 6.328125)) (fma -0.5 (/ c b) (/ (* -0.375 (* a (* c c))) (pow b 3.0))))))
double code(double a, double b, double c) {
return fma(-0.5625, ((pow(c, 3.0) * (a * a)) / pow(b, 5.0)), fma(-0.16666666666666666, (pow((c * a), 4.0) / ((a * pow(b, 7.0)) / 6.328125)), fma(-0.5, (c / b), ((-0.375 * (a * (c * c))) / pow(b, 3.0)))));
}
function code(a, b, c) return fma(-0.5625, Float64(Float64((c ^ 3.0) * Float64(a * a)) / (b ^ 5.0)), fma(-0.16666666666666666, Float64((Float64(c * a) ^ 4.0) / Float64(Float64(a * (b ^ 7.0)) / 6.328125)), fma(-0.5, Float64(c / b), Float64(Float64(-0.375 * Float64(a * Float64(c * c))) / (b ^ 3.0))))) end
code[a_, b_, c_] := N[(-0.5625 * N[(N[(N[Power[c, 3.0], $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[(N[Power[N[(c * a), $MachinePrecision], 4.0], $MachinePrecision] / N[(N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision] / 6.328125), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(c / b), $MachinePrecision] + N[(N[(-0.375 * N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-0.5625, \frac{{c}^{3} \cdot \left(a \cdot a\right)}{{b}^{5}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(c \cdot a\right)}^{4}}{\frac{a \cdot {b}^{7}}{6.328125}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375 \cdot \left(a \cdot \left(c \cdot c\right)\right)}{{b}^{3}}\right)\right)\right)
\end{array}
Initial program 15.8%
/-rgt-identity15.8%
metadata-eval15.8%
associate-/l*15.8%
associate-*r/15.8%
*-commutative15.8%
associate-*l/15.8%
associate-*r/15.8%
metadata-eval15.8%
metadata-eval15.8%
times-frac15.8%
neg-mul-115.8%
distribute-rgt-neg-in15.8%
times-frac15.8%
metadata-eval15.8%
neg-mul-115.8%
Simplified15.7%
Taylor expanded in b around inf 97.8%
fma-def97.8%
unpow297.8%
fma-def97.8%
Simplified97.8%
expm1-log1p-u97.8%
expm1-udef97.5%
pow-prod-down97.5%
Applied egg-rr97.5%
expm1-def97.8%
expm1-log1p97.8%
Simplified97.8%
unpow-prod-down97.8%
unpow-prod-down97.8%
pow-prod-down97.8%
pow-prod-up97.8%
metadata-eval97.8%
pow-prod-down97.8%
pow-prod-up97.8%
metadata-eval97.8%
pow-prod-down97.8%
metadata-eval97.8%
Applied egg-rr97.8%
Taylor expanded in c around 0 97.8%
+-commutative97.8%
distribute-rgt-out97.8%
associate-*r*97.8%
associate-/l*97.8%
metadata-eval97.8%
pow-sqr97.8%
unpow297.8%
unpow297.8%
metadata-eval97.8%
pow-plus97.8%
unpow397.8%
associate-*r*97.8%
unswap-sqr97.8%
unswap-sqr97.8%
unpow297.8%
unswap-sqr97.8%
unpow297.8%
pow-sqr97.8%
metadata-eval97.8%
metadata-eval97.8%
Simplified97.8%
Final simplification97.8%
(FPCore (a b c) :precision binary64 (fma -0.5625 (/ (pow c 3.0) (/ (pow b 5.0) (* a a))) (fma -0.375 (/ (* c c) (/ (pow b 3.0) a)) (/ (* c -0.5) b))))
double code(double a, double b, double c) {
return fma(-0.5625, (pow(c, 3.0) / (pow(b, 5.0) / (a * a))), fma(-0.375, ((c * c) / (pow(b, 3.0) / a)), ((c * -0.5) / b)));
}
function code(a, b, c) return fma(-0.5625, Float64((c ^ 3.0) / Float64((b ^ 5.0) / Float64(a * a))), fma(-0.375, Float64(Float64(c * c) / Float64((b ^ 3.0) / a)), Float64(Float64(c * -0.5) / b))) end
code[a_, b_, c_] := N[(-0.5625 * N[(N[Power[c, 3.0], $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(c * c), $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.375, \frac{c \cdot c}{\frac{{b}^{3}}{a}}, \frac{c \cdot -0.5}{b}\right)\right)
\end{array}
Initial program 15.8%
/-rgt-identity15.8%
metadata-eval15.8%
associate-/l*15.8%
associate-*r/15.8%
*-commutative15.8%
associate-*l/15.8%
associate-*r/15.8%
metadata-eval15.8%
metadata-eval15.8%
times-frac15.8%
neg-mul-115.8%
distribute-rgt-neg-in15.8%
times-frac15.8%
metadata-eval15.8%
neg-mul-115.8%
Simplified15.7%
Taylor expanded in b around inf 97.1%
fma-def97.1%
associate-/l*97.1%
unpow297.1%
+-commutative97.1%
fma-def97.1%
associate-/l*97.1%
unpow297.1%
associate-*r/97.1%
Simplified97.1%
Final simplification97.1%
(FPCore (a b c) :precision binary64 (+ (* -0.375 (/ (* c c) (/ (pow b 3.0) a))) (/ c (/ b -0.5))))
double code(double a, double b, double c) {
return (-0.375 * ((c * c) / (pow(b, 3.0) / a))) + (c / (b / -0.5));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((-0.375d0) * ((c * c) / ((b ** 3.0d0) / a))) + (c / (b / (-0.5d0)))
end function
public static double code(double a, double b, double c) {
return (-0.375 * ((c * c) / (Math.pow(b, 3.0) / a))) + (c / (b / -0.5));
}
def code(a, b, c): return (-0.375 * ((c * c) / (math.pow(b, 3.0) / a))) + (c / (b / -0.5))
function code(a, b, c) return Float64(Float64(-0.375 * Float64(Float64(c * c) / Float64((b ^ 3.0) / a))) + Float64(c / Float64(b / -0.5))) end
function tmp = code(a, b, c) tmp = (-0.375 * ((c * c) / ((b ^ 3.0) / a))) + (c / (b / -0.5)); end
code[a_, b_, c_] := N[(N[(-0.375 * N[(N[(c * c), $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(c / N[(b / -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.375 \cdot \frac{c \cdot c}{\frac{{b}^{3}}{a}} + \frac{c}{\frac{b}{-0.5}}
\end{array}
Initial program 15.8%
neg-sub015.8%
associate-+l-15.8%
sub0-neg15.8%
neg-mul-115.8%
associate-*r/15.8%
*-commutative15.8%
metadata-eval15.8%
metadata-eval15.8%
times-frac15.8%
*-commutative15.8%
times-frac15.8%
Simplified15.7%
add-exp-log15.7%
Applied egg-rr15.7%
Taylor expanded in b around inf 95.5%
+-commutative95.5%
fma-def95.5%
associate-/l*95.5%
unpow295.5%
*-commutative95.5%
associate-*l/95.5%
Simplified95.5%
fma-udef95.5%
associate-/l*95.5%
Applied egg-rr95.5%
Final simplification95.5%
(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 15.8%
/-rgt-identity15.8%
metadata-eval15.8%
associate-/l*15.8%
associate-*r/15.8%
*-commutative15.8%
associate-*l/15.8%
associate-*r/15.8%
metadata-eval15.8%
metadata-eval15.8%
times-frac15.8%
neg-mul-115.8%
distribute-rgt-neg-in15.8%
times-frac15.8%
metadata-eval15.8%
neg-mul-115.8%
Simplified15.7%
Taylor expanded in b around inf 91.9%
associate-*r/91.9%
Simplified91.9%
Final simplification91.9%
herbie shell --seed 2023187
(FPCore (a b c)
:name "Cubic critical, wide range"
:precision binary64
:pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))