
(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 8 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 (/ (/ (* c (* a (- 3.0))) (+ b (sqrt (fma -3.0 (* c a) (pow b 2.0))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((c * (a * -3.0)) / (b + sqrt(fma(-3.0, (c * a), pow(b, 2.0))))) / (a * 3.0);
}
function code(a, b, c) return Float64(Float64(Float64(c * Float64(a * Float64(-3.0))) / Float64(b + sqrt(fma(-3.0, Float64(c * a), (b ^ 2.0))))) / Float64(a * 3.0)) end
code[a_, b_, c_] := N[(N[(N[(c * N[(a * (-3.0)), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(-3.0 * N[(c * a), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{c \cdot \left(a \cdot \left(-3\right)\right)}{b + \sqrt{\mathsf{fma}\left(-3, c \cdot a, {b}^{2}\right)}}}{a \cdot 3}
\end{array}
Initial program 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
pow131.3%
associate-*r*31.3%
*-commutative31.3%
Applied egg-rr31.3%
unpow131.3%
associate-*r*31.3%
Simplified31.3%
neg-sub031.3%
flip--31.5%
metadata-eval31.5%
pow231.5%
add-sqr-sqrt31.6%
sqrt-prod31.5%
sqr-neg31.5%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod31.5%
sqr-neg31.5%
sqrt-prod31.6%
add-sqr-sqrt31.5%
Applied egg-rr31.5%
neg-sub031.5%
Simplified31.5%
flip-+31.5%
Applied egg-rr32.3%
associate--r-99.2%
Simplified99.2%
div-inv99.1%
+-commutative99.1%
fma-define99.1%
neg-mul-199.1%
unpow-prod-down99.1%
metadata-eval99.1%
*-un-lft-identity99.1%
Applied egg-rr99.1%
associate-*r/99.2%
*-commutative99.2%
*-lft-identity99.2%
fma-undefine99.2%
+-inverses99.2%
+-rgt-identity99.2%
remove-double-div99.1%
distribute-frac-neg299.1%
*-commutative99.1%
associate-*l*99.3%
*-commutative99.3%
distribute-frac-neg299.3%
remove-double-div99.4%
associate-*r*99.4%
*-commutative99.4%
sub-neg99.4%
+-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (a b c) :precision binary64 (/ (fma -0.5 c (* -0.375 (* a (pow (/ c b) 2.0)))) b))
double code(double a, double b, double c) {
return fma(-0.5, c, (-0.375 * (a * pow((c / b), 2.0)))) / b;
}
function code(a, b, c) return Float64(fma(-0.5, c, Float64(-0.375 * Float64(a * (Float64(c / b) ^ 2.0)))) / b) end
code[a_, b_, c_] := N[(N[(-0.5 * c + N[(-0.375 * N[(a * N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(-0.5, c, -0.375 \cdot \left(a \cdot {\left(\frac{c}{b}\right)}^{2}\right)\right)}{b}
\end{array}
Initial program 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
pow131.3%
associate-*r*31.3%
*-commutative31.3%
Applied egg-rr31.3%
unpow131.3%
associate-*r*31.3%
Simplified31.3%
neg-sub031.3%
flip--31.5%
metadata-eval31.5%
pow231.5%
add-sqr-sqrt31.6%
sqrt-prod31.5%
sqr-neg31.5%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod31.5%
sqr-neg31.5%
sqrt-prod31.6%
add-sqr-sqrt31.5%
Applied egg-rr31.5%
neg-sub031.5%
Simplified31.5%
Taylor expanded in b around inf 90.5%
fma-define90.5%
associate-/l*90.5%
unpow290.5%
unpow290.5%
times-frac90.5%
unpow190.5%
pow-plus90.5%
metadata-eval90.5%
Simplified90.5%
(FPCore (a b c) :precision binary64 (/ 1.0 (* b (+ (* 1.5 (/ a (pow b 2.0))) (* 2.0 (/ -1.0 c))))))
double code(double a, double b, double c) {
return 1.0 / (b * ((1.5 * (a / pow(b, 2.0))) + (2.0 * (-1.0 / c))));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 1.0d0 / (b * ((1.5d0 * (a / (b ** 2.0d0))) + (2.0d0 * ((-1.0d0) / c))))
end function
public static double code(double a, double b, double c) {
return 1.0 / (b * ((1.5 * (a / Math.pow(b, 2.0))) + (2.0 * (-1.0 / c))));
}
def code(a, b, c): return 1.0 / (b * ((1.5 * (a / math.pow(b, 2.0))) + (2.0 * (-1.0 / c))))
function code(a, b, c) return Float64(1.0 / Float64(b * Float64(Float64(1.5 * Float64(a / (b ^ 2.0))) + Float64(2.0 * Float64(-1.0 / c))))) end
function tmp = code(a, b, c) tmp = 1.0 / (b * ((1.5 * (a / (b ^ 2.0))) + (2.0 * (-1.0 / c)))); end
code[a_, b_, c_] := N[(1.0 / N[(b * N[(N[(1.5 * N[(a / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{b \cdot \left(1.5 \cdot \frac{a}{{b}^{2}} + 2 \cdot \frac{-1}{c}\right)}
\end{array}
Initial program 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
pow131.3%
associate-*r*31.3%
*-commutative31.3%
Applied egg-rr31.3%
unpow131.3%
associate-*r*31.3%
Simplified31.3%
clear-num31.3%
inv-pow31.3%
*-commutative31.3%
neg-mul-131.3%
fma-define31.3%
pow231.3%
*-commutative31.3%
Applied egg-rr31.3%
Simplified31.3%
Taylor expanded in b around inf 90.5%
Final simplification90.5%
(FPCore (a b c) :precision binary64 (/ 1.0 (* 3.0 (* b (- (* (/ a (pow b 2.0)) 0.5) (/ 0.6666666666666666 c))))))
double code(double a, double b, double c) {
return 1.0 / (3.0 * (b * (((a / pow(b, 2.0)) * 0.5) - (0.6666666666666666 / c))));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 1.0d0 / (3.0d0 * (b * (((a / (b ** 2.0d0)) * 0.5d0) - (0.6666666666666666d0 / c))))
end function
public static double code(double a, double b, double c) {
return 1.0 / (3.0 * (b * (((a / Math.pow(b, 2.0)) * 0.5) - (0.6666666666666666 / c))));
}
def code(a, b, c): return 1.0 / (3.0 * (b * (((a / math.pow(b, 2.0)) * 0.5) - (0.6666666666666666 / c))))
function code(a, b, c) return Float64(1.0 / Float64(3.0 * Float64(b * Float64(Float64(Float64(a / (b ^ 2.0)) * 0.5) - Float64(0.6666666666666666 / c))))) end
function tmp = code(a, b, c) tmp = 1.0 / (3.0 * (b * (((a / (b ^ 2.0)) * 0.5) - (0.6666666666666666 / c)))); end
code[a_, b_, c_] := N[(1.0 / N[(3.0 * N[(b * N[(N[(N[(a / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] - N[(0.6666666666666666 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{3 \cdot \left(b \cdot \left(\frac{a}{{b}^{2}} \cdot 0.5 - \frac{0.6666666666666666}{c}\right)\right)}
\end{array}
Initial program 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
pow131.3%
associate-*r*31.3%
*-commutative31.3%
Applied egg-rr31.3%
unpow131.3%
associate-*r*31.3%
Simplified31.3%
clear-num31.3%
inv-pow31.3%
*-commutative31.3%
neg-mul-131.3%
fma-define31.3%
pow231.3%
*-commutative31.3%
Applied egg-rr31.3%
Simplified31.3%
Taylor expanded in b around inf 90.2%
associate-*r/90.3%
metadata-eval90.3%
Simplified90.3%
Final simplification90.3%
(FPCore (a b c) :precision binary64 (* c (- (/ (* -0.375 (* c a)) (pow b 3.0)) (/ 0.5 b))))
double code(double a, double b, double c) {
return c * (((-0.375 * (c * a)) / pow(b, 3.0)) - (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.375d0) * (c * a)) / (b ** 3.0d0)) - (0.5d0 / b))
end function
public static double code(double a, double b, double c) {
return c * (((-0.375 * (c * a)) / Math.pow(b, 3.0)) - (0.5 / b));
}
def code(a, b, c): return c * (((-0.375 * (c * a)) / math.pow(b, 3.0)) - (0.5 / b))
function code(a, b, c) return Float64(c * Float64(Float64(Float64(-0.375 * Float64(c * a)) / (b ^ 3.0)) - Float64(0.5 / b))) end
function tmp = code(a, b, c) tmp = c * (((-0.375 * (c * a)) / (b ^ 3.0)) - (0.5 / b)); end
code[a_, b_, c_] := N[(c * N[(N[(N[(-0.375 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] - N[(0.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \left(\frac{-0.375 \cdot \left(c \cdot a\right)}{{b}^{3}} - \frac{0.5}{b}\right)
\end{array}
Initial program 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
Taylor expanded in c around 0 90.3%
associate-*r/90.3%
associate-*r/90.3%
metadata-eval90.3%
Simplified90.3%
Final simplification90.3%
(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 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
Taylor expanded in b around inf 81.1%
associate-*r/81.1%
*-commutative81.1%
Simplified81.1%
(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 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
Taylor expanded in b around inf 81.1%
associate-*r/81.1%
*-commutative81.1%
Simplified81.1%
Taylor expanded in c around 0 81.1%
associate-*r/81.1%
*-commutative81.1%
associate-*r/80.9%
Simplified80.9%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 31.3%
sqr-neg31.3%
sqr-neg31.3%
associate-*l*31.3%
Simplified31.3%
pow131.3%
associate-*r*31.3%
*-commutative31.3%
Applied egg-rr31.3%
unpow131.3%
associate-*r*31.3%
Simplified31.3%
neg-sub031.3%
flip--31.5%
metadata-eval31.5%
pow231.5%
add-sqr-sqrt31.6%
sqrt-prod31.5%
sqr-neg31.5%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod31.5%
sqr-neg31.5%
sqrt-prod31.6%
add-sqr-sqrt31.5%
Applied egg-rr31.5%
neg-sub031.5%
Simplified31.5%
clear-num31.6%
inv-pow31.6%
Applied egg-rr31.6%
unpow-131.6%
Simplified31.6%
Taylor expanded in c around 0 3.2%
associate-*r/3.2%
distribute-rgt1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
herbie shell --seed 2024137
(FPCore (a b c)
:name "Cubic critical, 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) (* (* 3.0 a) c)))) (* 3.0 a)))