
(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 (/ c (- (- b) (sqrt (fma b b (* (* c a) -3.0))))))
double code(double a, double b, double c) {
return c / (-b - sqrt(fma(b, b, ((c * a) * -3.0))));
}
function code(a, b, c) return Float64(c / Float64(Float64(-b) - sqrt(fma(b, b, Float64(Float64(c * a) * -3.0))))) end
code[a_, b_, c_] := N[(c / N[((-b) - N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -3\right)}}
\end{array}
Initial program 28.5%
neg-sub028.5%
flip--28.7%
metadata-eval28.7%
pow228.7%
add-sqr-sqrt29.0%
sqrt-prod28.7%
sqr-neg28.7%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod28.7%
sqr-neg28.7%
sqrt-prod29.0%
add-sqr-sqrt28.7%
Applied egg-rr28.7%
neg-sub028.7%
Simplified28.7%
flip-+28.8%
Applied egg-rr29.6%
associate--r-99.3%
associate-*r*99.1%
*-commutative99.1%
associate-*r*99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
Simplified99.2%
Taylor expanded in b around 0 99.1%
associate-*r*99.3%
Simplified99.3%
*-un-lft-identity99.3%
associate-/l/99.3%
*-commutative99.3%
*-commutative99.3%
*-commutative99.3%
Applied egg-rr99.3%
*-lft-identity99.3%
*-commutative99.3%
times-frac99.7%
*-inverses99.7%
sub-neg99.7%
unpow299.7%
fma-define99.8%
associate-*r*99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (a b c) :precision binary64 (/ (/ (* c (* a 3.0)) (- (- b) (sqrt (- (* b b) (* a (* c 3.0)))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((c * (a * 3.0)) / (-b - sqrt(((b * b) - (a * (c * 3.0)))))) / (a * 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 = ((c * (a * 3.0d0)) / (-b - sqrt(((b * b) - (a * (c * 3.0d0)))))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
return ((c * (a * 3.0)) / (-b - Math.sqrt(((b * b) - (a * (c * 3.0)))))) / (a * 3.0);
}
def code(a, b, c): return ((c * (a * 3.0)) / (-b - math.sqrt(((b * b) - (a * (c * 3.0)))))) / (a * 3.0)
function code(a, b, c) return Float64(Float64(Float64(c * Float64(a * 3.0)) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 3.0)))))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) tmp = ((c * (a * 3.0)) / (-b - sqrt(((b * b) - (a * (c * 3.0)))))) / (a * 3.0); end
code[a_, b_, c_] := N[(N[(N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{c \cdot \left(a \cdot 3\right)}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 3\right)}}}{a \cdot 3}
\end{array}
Initial program 28.5%
neg-sub028.5%
flip--28.7%
metadata-eval28.7%
pow228.7%
add-sqr-sqrt29.0%
sqrt-prod28.7%
sqr-neg28.7%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod28.7%
sqr-neg28.7%
sqrt-prod29.0%
add-sqr-sqrt28.7%
Applied egg-rr28.7%
neg-sub028.7%
Simplified28.7%
flip-+28.8%
Applied egg-rr29.6%
associate--r-99.3%
associate-*r*99.1%
*-commutative99.1%
associate-*r*99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
Simplified99.2%
Taylor expanded in b around 0 99.1%
associate-*r*99.3%
Simplified99.3%
pow299.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (/ 1.0 (* b (- (* 1.5 (/ a (pow b 2.0))) (/ 2.0 c)))))
double code(double a, double b, double c) {
return 1.0 / (b * ((1.5 * (a / pow(b, 2.0))) - (2.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 / 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 / c)));
}
def code(a, b, c): return 1.0 / (b * ((1.5 * (a / math.pow(b, 2.0))) - (2.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 / c)))) end
function tmp = code(a, b, c) tmp = 1.0 / (b * ((1.5 * (a / (b ^ 2.0))) - (2.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 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{b \cdot \left(1.5 \cdot \frac{a}{{b}^{2}} - \frac{2}{c}\right)}
\end{array}
Initial program 28.5%
add-cube-cbrt28.5%
pow328.5%
Applied egg-rr28.5%
pow128.5%
metadata-eval28.5%
pow-div28.7%
pow228.7%
pow128.7%
distribute-frac-neg28.7%
pow228.7%
rem-cube-cbrt28.7%
clear-num28.7%
inv-pow28.7%
Applied egg-rr28.5%
unpow-128.5%
associate-/l*28.5%
associate-*r*28.5%
*-commutative28.5%
associate-*r*28.5%
Simplified28.5%
Taylor expanded in b around inf 91.8%
associate-*r/91.8%
metadata-eval91.8%
Simplified91.8%
(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(-0.375 * Float64(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[(-0.375 * N[(N[(c * a), $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{c \cdot a}{{b}^{3}} - \frac{0.5}{b}\right)
\end{array}
Initial program 28.5%
/-rgt-identity28.5%
metadata-eval28.5%
Simplified28.6%
Taylor expanded in c around 0 91.7%
associate-*r/91.7%
metadata-eval91.7%
Simplified91.7%
Final simplification91.7%
(FPCore (a b c) :precision binary64 (* -0.5 (/ c b)))
double code(double a, double b, double c) {
return -0.5 * (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 = (-0.5d0) * (c / b)
end function
public static double code(double a, double b, double c) {
return -0.5 * (c / b);
}
def code(a, b, c): return -0.5 * (c / b)
function code(a, b, c) return Float64(-0.5 * Float64(c / b)) end
function tmp = code(a, b, c) tmp = -0.5 * (c / b); end
code[a_, b_, c_] := N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \frac{c}{b}
\end{array}
Initial program 28.5%
/-rgt-identity28.5%
metadata-eval28.5%
Simplified28.6%
Taylor expanded in b around inf 83.1%
(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 28.5%
neg-sub028.5%
flip--28.7%
metadata-eval28.7%
pow228.7%
add-sqr-sqrt29.0%
sqrt-prod28.7%
sqr-neg28.7%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod28.7%
sqr-neg28.7%
sqrt-prod29.0%
add-sqr-sqrt28.7%
Applied egg-rr28.7%
neg-sub028.7%
Simplified28.7%
Taylor expanded in a 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 2024139
(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)))