
(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 (let* ((t_0 (* c (* a 3.0)))) (/ (/ t_0 (- (- b) (sqrt (- (pow b 2.0) t_0)))) (* a 3.0))))
double code(double a, double b, double c) {
double t_0 = c * (a * 3.0);
return (t_0 / (-b - sqrt((pow(b, 2.0) - t_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
real(8) :: t_0
t_0 = c * (a * 3.0d0)
code = (t_0 / (-b - sqrt(((b ** 2.0d0) - t_0)))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a * 3.0);
return (t_0 / (-b - Math.sqrt((Math.pow(b, 2.0) - t_0)))) / (a * 3.0);
}
def code(a, b, c): t_0 = c * (a * 3.0) return (t_0 / (-b - math.sqrt((math.pow(b, 2.0) - t_0)))) / (a * 3.0)
function code(a, b, c) t_0 = Float64(c * Float64(a * 3.0)) return Float64(Float64(t_0 / Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) - t_0)))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) t_0 = c * (a * 3.0); tmp = (t_0 / (-b - sqrt(((b ^ 2.0) - t_0)))) / (a * 3.0); end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 / N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 3\right)\\
\frac{\frac{t\_0}{\left(-b\right) - \sqrt{{b}^{2} - t\_0}}}{a \cdot 3}
\end{array}
\end{array}
Initial program 17.4%
add-cbrt-cube17.4%
pow1/318.8%
pow318.8%
pow218.8%
pow-pow18.8%
metadata-eval18.8%
Applied egg-rr18.8%
unpow1/317.3%
Simplified17.3%
flip-+17.4%
pow217.4%
add-sqr-sqrt17.9%
pow1/318.9%
pow-pow18.0%
metadata-eval18.0%
*-commutative18.0%
pow1/317.9%
pow-pow18.0%
metadata-eval18.0%
*-commutative18.0%
Applied egg-rr18.0%
associate--r-99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in b around 0 99.5%
Final simplification99.5%
(FPCore (a b c) :precision binary64 (/ (/ (* 3.0 (* c a)) (- (- b) (sqrt (- (pow b 2.0) (* c (* a 3.0)))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((3.0 * (c * a)) / (-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 = ((3.0d0 * (c * a)) / (-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 ((3.0 * (c * a)) / (-b - Math.sqrt((Math.pow(b, 2.0) - (c * (a * 3.0)))))) / (a * 3.0);
}
def code(a, b, c): return ((3.0 * (c * a)) / (-b - math.sqrt((math.pow(b, 2.0) - (c * (a * 3.0)))))) / (a * 3.0)
function code(a, b, c) return Float64(Float64(Float64(3.0 * Float64(c * a)) / Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) - Float64(c * Float64(a * 3.0)))))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) tmp = ((3.0 * (c * a)) / (-b - sqrt(((b ^ 2.0) - (c * (a * 3.0)))))) / (a * 3.0); end
code[a_, b_, c_] := N[(N[(N[(3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{3 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{{b}^{2} - c \cdot \left(a \cdot 3\right)}}}{a \cdot 3}
\end{array}
Initial program 17.4%
add-cbrt-cube17.4%
pow1/318.8%
pow318.8%
pow218.8%
pow-pow18.8%
metadata-eval18.8%
Applied egg-rr18.8%
unpow1/317.3%
Simplified17.3%
flip-+17.4%
pow217.4%
add-sqr-sqrt17.9%
pow1/318.9%
pow-pow18.0%
metadata-eval18.0%
*-commutative18.0%
pow1/317.9%
pow-pow18.0%
metadata-eval18.0%
*-commutative18.0%
Applied egg-rr18.0%
associate--r-99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in b around 0 99.2%
Final simplification99.2%
(FPCore (a b c) :precision binary64 (/ (+ (* c -0.5) (* (* a -0.375) (* (/ c b) (/ c b)))) b))
double code(double a, double b, double c) {
return ((c * -0.5) + ((a * -0.375) * ((c / b) * (c / b)))) / 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)) + ((a * (-0.375d0)) * ((c / b) * (c / b)))) / b
end function
public static double code(double a, double b, double c) {
return ((c * -0.5) + ((a * -0.375) * ((c / b) * (c / b)))) / b;
}
def code(a, b, c): return ((c * -0.5) + ((a * -0.375) * ((c / b) * (c / b)))) / b
function code(a, b, c) return Float64(Float64(Float64(c * -0.5) + Float64(Float64(a * -0.375) * Float64(Float64(c / b) * Float64(c / b)))) / b) end
function tmp = code(a, b, c) tmp = ((c * -0.5) + ((a * -0.375) * ((c / b) * (c / b)))) / b; end
code[a_, b_, c_] := N[(N[(N[(c * -0.5), $MachinePrecision] + N[(N[(a * -0.375), $MachinePrecision] * N[(N[(c / b), $MachinePrecision] * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot -0.5 + \left(a \cdot -0.375\right) \cdot \left(\frac{c}{b} \cdot \frac{c}{b}\right)}{b}
\end{array}
Initial program 17.4%
Simplified17.5%
Taylor expanded in b around 0 17.4%
*-commutative17.4%
associate-*r*17.4%
fma-define17.4%
Simplified17.4%
Taylor expanded in b around inf 95.3%
fma-define95.3%
associate-/l*95.3%
unpow295.3%
unpow295.3%
times-frac95.3%
unpow195.3%
pow-plus95.3%
metadata-eval95.3%
Simplified95.3%
fma-undefine95.3%
associate-*r*95.3%
Applied egg-rr95.3%
unpow295.3%
Applied egg-rr95.3%
Final simplification95.3%
(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 17.4%
Simplified17.5%
Taylor expanded in b around inf 90.6%
herbie shell --seed 2024177
(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)))