
(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 a) a) (- (- b) (sqrt (fma (* c a) -3.0 (pow b 2.0))))))
double code(double a, double b, double c) {
return ((c * a) / a) / (-b - sqrt(fma((c * a), -3.0, pow(b, 2.0))));
}
function code(a, b, c) return Float64(Float64(Float64(c * a) / a) / Float64(Float64(-b) - sqrt(fma(Float64(c * a), -3.0, (b ^ 2.0))))) end
code[a_, b_, c_] := N[(N[(N[(c * a), $MachinePrecision] / a), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -3.0 + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{c \cdot a}{a}}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -3, {b}^{2}\right)}}
\end{array}
Initial program 31.1%
sqr-neg31.1%
sqr-neg31.1%
associate-*l*31.1%
Simplified31.1%
expm1-log1p-u31.1%
expm1-undefine25.1%
*-commutative25.1%
*-commutative25.1%
associate-*l*25.1%
*-commutative25.1%
Applied egg-rr25.1%
flip-+25.1%
pow225.1%
add-sqr-sqrt26.0%
pow226.0%
expm1-define30.5%
expm1-log1p-u30.5%
*-commutative30.5%
pow230.5%
expm1-define32.4%
expm1-log1p-u32.3%
*-commutative32.3%
Applied egg-rr32.3%
associate--r-99.3%
associate-*r*99.1%
*-commutative99.1%
associate-*r*99.1%
*-commutative99.1%
Simplified99.1%
div-inv99.1%
+-commutative99.1%
associate-*l*99.1%
fma-define99.1%
neg-mul-199.1%
metadata-eval99.1%
unpow-prod-down99.1%
metadata-eval99.1%
metadata-eval99.1%
*-un-lft-identity99.1%
associate-*l*99.1%
Applied egg-rr99.1%
associate-*r/99.1%
fma-undefine99.1%
+-inverses99.1%
+-rgt-identity99.1%
*-rgt-identity99.1%
*-commutative99.1%
associate-*l*99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
+-commutative99.3%
fma-define99.3%
*-commutative99.3%
Simplified99.3%
div-inv99.3%
associate-/l*99.2%
*-commutative99.2%
Applied egg-rr99.2%
*-commutative99.2%
associate-*r/99.3%
times-frac99.3%
*-lft-identity99.3%
associate-/r*99.6%
associate-*r*99.2%
*-commutative99.2%
*-commutative99.2%
*-commutative99.2%
times-frac99.6%
metadata-eval99.6%
*-commutative99.6%
fma-define99.6%
*-commutative99.6%
*-commutative99.6%
fma-define99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b c) :precision binary64 (/ (/ (* c (* a 3.0)) (- (- b) (sqrt (* c (+ (* a -3.0) (/ (pow b 2.0) c)))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((c * (a * 3.0)) / (-b - sqrt((c * ((a * -3.0) + (pow(b, 2.0) / c)))))) / (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((c * ((a * (-3.0d0)) + ((b ** 2.0d0) / c)))))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
return ((c * (a * 3.0)) / (-b - Math.sqrt((c * ((a * -3.0) + (Math.pow(b, 2.0) / c)))))) / (a * 3.0);
}
def code(a, b, c): return ((c * (a * 3.0)) / (-b - math.sqrt((c * ((a * -3.0) + (math.pow(b, 2.0) / c)))))) / (a * 3.0)
function code(a, b, c) return Float64(Float64(Float64(c * Float64(a * 3.0)) / Float64(Float64(-b) - sqrt(Float64(c * Float64(Float64(a * -3.0) + Float64((b ^ 2.0) / c)))))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) tmp = ((c * (a * 3.0)) / (-b - sqrt((c * ((a * -3.0) + ((b ^ 2.0) / c)))))) / (a * 3.0); end
code[a_, b_, c_] := N[(N[(N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(c * N[(N[(a * -3.0), $MachinePrecision] + N[(N[Power[b, 2.0], $MachinePrecision] / c), $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{c \cdot \left(a \cdot -3 + \frac{{b}^{2}}{c}\right)}}}{a \cdot 3}
\end{array}
Initial program 31.1%
sqr-neg31.1%
sqr-neg31.1%
associate-*l*31.1%
Simplified31.1%
expm1-log1p-u31.1%
expm1-undefine25.1%
*-commutative25.1%
*-commutative25.1%
associate-*l*25.1%
*-commutative25.1%
Applied egg-rr25.1%
flip-+25.1%
pow225.1%
add-sqr-sqrt26.0%
pow226.0%
expm1-define30.5%
expm1-log1p-u30.5%
*-commutative30.5%
pow230.5%
expm1-define32.4%
expm1-log1p-u32.3%
*-commutative32.3%
Applied egg-rr32.3%
associate--r-99.3%
associate-*r*99.1%
*-commutative99.1%
associate-*r*99.1%
*-commutative99.1%
Simplified99.1%
div-inv99.1%
+-commutative99.1%
associate-*l*99.1%
fma-define99.1%
neg-mul-199.1%
metadata-eval99.1%
unpow-prod-down99.1%
metadata-eval99.1%
metadata-eval99.1%
*-un-lft-identity99.1%
associate-*l*99.1%
Applied egg-rr99.1%
associate-*r/99.1%
fma-undefine99.1%
+-inverses99.1%
+-rgt-identity99.1%
*-rgt-identity99.1%
*-commutative99.1%
associate-*l*99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
+-commutative99.3%
fma-define99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in c around inf 99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (/ (/ (* c (* a 3.0)) (- (- b) (sqrt (+ (pow b 2.0) (* (* c a) -3.0))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((c * (a * 3.0)) / (-b - sqrt((pow(b, 2.0) + ((c * a) * -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 ** 2.0d0) + ((c * a) * (-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((Math.pow(b, 2.0) + ((c * a) * -3.0))))) / (a * 3.0);
}
def code(a, b, c): return ((c * (a * 3.0)) / (-b - math.sqrt((math.pow(b, 2.0) + ((c * a) * -3.0))))) / (a * 3.0)
function code(a, b, c) return Float64(Float64(Float64(c * Float64(a * 3.0)) / Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) + Float64(Float64(c * a) * -3.0))))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) tmp = ((c * (a * 3.0)) / (-b - sqrt(((b ^ 2.0) + ((c * a) * -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[Power[b, 2.0], $MachinePrecision] + N[(N[(c * a), $MachinePrecision] * -3.0), $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}^{2} + \left(c \cdot a\right) \cdot -3}}}{a \cdot 3}
\end{array}
Initial program 31.1%
sqr-neg31.1%
sqr-neg31.1%
associate-*l*31.1%
Simplified31.1%
expm1-log1p-u31.1%
expm1-undefine25.1%
*-commutative25.1%
*-commutative25.1%
associate-*l*25.1%
*-commutative25.1%
Applied egg-rr25.1%
flip-+25.1%
pow225.1%
add-sqr-sqrt26.0%
pow226.0%
expm1-define30.5%
expm1-log1p-u30.5%
*-commutative30.5%
pow230.5%
expm1-define32.4%
expm1-log1p-u32.3%
*-commutative32.3%
Applied egg-rr32.3%
associate--r-99.3%
associate-*r*99.1%
*-commutative99.1%
associate-*r*99.1%
*-commutative99.1%
Simplified99.1%
div-inv99.1%
+-commutative99.1%
associate-*l*99.1%
fma-define99.1%
neg-mul-199.1%
metadata-eval99.1%
unpow-prod-down99.1%
metadata-eval99.1%
metadata-eval99.1%
*-un-lft-identity99.1%
associate-*l*99.1%
Applied egg-rr99.1%
associate-*r/99.1%
fma-undefine99.1%
+-inverses99.1%
+-rgt-identity99.1%
*-rgt-identity99.1%
*-commutative99.1%
associate-*l*99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
+-commutative99.3%
fma-define99.3%
*-commutative99.3%
Simplified99.3%
fma-undefine99.3%
Applied egg-rr99.3%
Final simplification99.3%
(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 31.1%
sqr-neg31.1%
sqr-neg31.1%
associate-*l*31.1%
Simplified31.1%
Taylor expanded in a around 0 91.9%
Final simplification91.9%
(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 31.1%
sqr-neg31.1%
sqr-neg31.1%
associate-*l*31.1%
Simplified31.1%
Taylor expanded in a around 0 91.9%
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 (/ (* 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.1%
sqr-neg31.1%
sqr-neg31.1%
associate-*l*31.1%
Simplified31.1%
Taylor expanded in b around inf 81.8%
associate-*r/81.8%
*-commutative81.8%
Simplified81.8%
Final simplification81.8%
herbie shell --seed 2024080
(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)))