
(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 6 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 (/ (/ (* a (* 3.0 c)) (- (- b) (sqrt (fma b b (* (* a c) -3.0))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((a * (3.0 * c)) / (-b - sqrt(fma(b, b, ((a * c) * -3.0))))) / (a * 3.0);
}
function code(a, b, c) return Float64(Float64(Float64(a * Float64(3.0 * c)) / Float64(Float64(-b) - sqrt(fma(b, b, Float64(Float64(a * c) * -3.0))))) / Float64(a * 3.0)) end
code[a_, b_, c_] := N[(N[(N[(a * N[(3.0 * c), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(b * b + N[(N[(a * c), $MachinePrecision] * -3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{a \cdot \left(3 \cdot c\right)}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -3\right)}}}{a \cdot 3}
\end{array}
Initial program 19.3%
neg-sub019.3%
flip--19.4%
metadata-eval19.4%
pow219.4%
add-sqr-sqrt19.6%
sqrt-prod19.4%
sqr-neg19.4%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod19.4%
sqr-neg19.4%
sqrt-prod19.6%
add-sqr-sqrt19.4%
Applied egg-rr19.4%
neg-sub019.4%
Simplified19.4%
flip-+19.3%
pow219.3%
pow219.3%
distribute-frac-neg19.3%
pow219.3%
pow119.3%
pow-div19.3%
metadata-eval19.3%
pow119.3%
add-sqr-sqrt19.7%
pow219.7%
associate-*l*19.7%
Applied egg-rr19.7%
unpow219.7%
sqr-neg19.7%
unpow219.7%
sub-neg19.7%
associate--r+99.2%
+-inverses99.2%
neg-sub099.2%
remove-double-neg99.2%
associate-*r*99.4%
*-commutative99.4%
associate-*l*99.2%
unpow299.2%
fma-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (a b c) :precision binary64 (/ (+ (* c -0.5) (* -0.375 (/ (* a (pow c 2.0)) (pow b 2.0)))) b))
double code(double a, double b, double c) {
return ((c * -0.5) + (-0.375 * ((a * pow(c, 2.0)) / pow(b, 2.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.5d0)) + ((-0.375d0) * ((a * (c ** 2.0d0)) / (b ** 2.0d0)))) / b
end function
public static double code(double a, double b, double c) {
return ((c * -0.5) + (-0.375 * ((a * Math.pow(c, 2.0)) / Math.pow(b, 2.0)))) / b;
}
def code(a, b, c): return ((c * -0.5) + (-0.375 * ((a * math.pow(c, 2.0)) / math.pow(b, 2.0)))) / b
function code(a, b, c) return Float64(Float64(Float64(c * -0.5) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 2.0)))) / b) end
function tmp = code(a, b, c) tmp = ((c * -0.5) + (-0.375 * ((a * (c ^ 2.0)) / (b ^ 2.0)))) / b; end
code[a_, b_, c_] := N[(N[(N[(c * -0.5), $MachinePrecision] + N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot -0.5 + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{2}}}{b}
\end{array}
Initial program 19.3%
Taylor expanded in b around inf 94.2%
Final simplification94.2%
(FPCore (a b c) :precision binary64 (+ (* -0.5 (/ c b)) (* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0)))))
double code(double a, double b, double c) {
return (-0.5 * (c / b)) + (-0.375 * ((a * pow(c, 2.0)) / pow(b, 3.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.5d0) * (c / b)) + ((-0.375d0) * ((a * (c ** 2.0d0)) / (b ** 3.0d0)))
end function
public static double code(double a, double b, double c) {
return (-0.5 * (c / b)) + (-0.375 * ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0)));
}
def code(a, b, c): return (-0.5 * (c / b)) + (-0.375 * ((a * math.pow(c, 2.0)) / math.pow(b, 3.0)))
function code(a, b, c) return Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))) end
function tmp = code(a, b, c) tmp = (-0.5 * (c / b)) + (-0.375 * ((a * (c ^ 2.0)) / (b ^ 3.0))); end
code[a_, b_, c_] := N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}
\end{array}
Initial program 19.3%
Taylor expanded in a around 0 94.2%
(FPCore (a b c) :precision binary64 (/ (* c (- (* -0.375 (/ (* a c) (pow b 2.0))) 0.5)) b))
double code(double a, double b, double c) {
return (c * ((-0.375 * ((a * c) / pow(b, 2.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) * ((a * c) / (b ** 2.0d0))) - 0.5d0)) / b
end function
public static double code(double a, double b, double c) {
return (c * ((-0.375 * ((a * c) / Math.pow(b, 2.0))) - 0.5)) / b;
}
def code(a, b, c): return (c * ((-0.375 * ((a * c) / math.pow(b, 2.0))) - 0.5)) / b
function code(a, b, c) return Float64(Float64(c * Float64(Float64(-0.375 * Float64(Float64(a * c) / (b ^ 2.0))) - 0.5)) / b) end
function tmp = code(a, b, c) tmp = (c * ((-0.375 * ((a * c) / (b ^ 2.0))) - 0.5)) / b; end
code[a_, b_, c_] := N[(N[(c * N[(N[(-0.375 * N[(N[(a * c), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot \left(-0.375 \cdot \frac{a \cdot c}{{b}^{2}} - 0.5\right)}{b}
\end{array}
Initial program 19.3%
Taylor expanded in b around inf 94.2%
Taylor expanded in c around 0 94.1%
(FPCore (a b c) :precision binary64 (* c (- (* -0.375 (/ (* a c) (pow b 3.0))) (/ 0.5 b))))
double code(double a, double b, double c) {
return c * ((-0.375 * ((a * c) / 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) * ((a * c) / (b ** 3.0d0))) - (0.5d0 / b))
end function
public static double code(double a, double b, double c) {
return c * ((-0.375 * ((a * c) / Math.pow(b, 3.0))) - (0.5 / b));
}
def code(a, b, c): return c * ((-0.375 * ((a * c) / math.pow(b, 3.0))) - (0.5 / b))
function code(a, b, c) return Float64(c * Float64(Float64(-0.375 * Float64(Float64(a * c) / (b ^ 3.0))) - Float64(0.5 / b))) end
function tmp = code(a, b, c) tmp = c * ((-0.375 * ((a * c) / (b ^ 3.0))) - (0.5 / b)); end
code[a_, b_, c_] := N[(c * N[(N[(-0.375 * N[(N[(a * c), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \left(-0.375 \cdot \frac{a \cdot c}{{b}^{3}} - \frac{0.5}{b}\right)
\end{array}
Initial program 19.3%
Taylor expanded in b around inf 94.2%
Taylor expanded in c around 0 93.8%
associate-*r/93.8%
metadata-eval93.8%
Simplified93.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(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 19.3%
Taylor expanded in b around inf 89.2%
associate-*r/89.2%
*-commutative89.2%
Simplified89.2%
herbie shell --seed 2024111
(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)))