
(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 7 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 (* b (* b b))))
(/
(fma
(* a a)
(* (/ (* c (* c c)) (* b t_0)) -0.5625)
(fma
c
-0.5
(fma
-0.16666666666666666
(/
(* (* a a) (* (* a a) (* (* c c) (* (* c c) 6.328125))))
(* a (* t_0 t_0)))
(/ (* (* a (* c c)) -0.375) (* b b)))))
b)))
double code(double a, double b, double c) {
double t_0 = b * (b * b);
return fma((a * a), (((c * (c * c)) / (b * t_0)) * -0.5625), fma(c, -0.5, fma(-0.16666666666666666, (((a * a) * ((a * a) * ((c * c) * ((c * c) * 6.328125)))) / (a * (t_0 * t_0))), (((a * (c * c)) * -0.375) / (b * b))))) / b;
}
function code(a, b, c) t_0 = Float64(b * Float64(b * b)) return Float64(fma(Float64(a * a), Float64(Float64(Float64(c * Float64(c * c)) / Float64(b * t_0)) * -0.5625), fma(c, -0.5, fma(-0.16666666666666666, Float64(Float64(Float64(a * a) * Float64(Float64(a * a) * Float64(Float64(c * c) * Float64(Float64(c * c) * 6.328125)))) / Float64(a * Float64(t_0 * t_0))), Float64(Float64(Float64(a * Float64(c * c)) * -0.375) / Float64(b * b))))) / b) end
code[a_, b_, c_] := Block[{t$95$0 = N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(a * a), $MachinePrecision] * N[(N[(N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(b * t$95$0), $MachinePrecision]), $MachinePrecision] * -0.5625), $MachinePrecision] + N[(c * -0.5 + N[(-0.16666666666666666 * N[(N[(N[(a * a), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] * N[(N[(c * c), $MachinePrecision] * 6.328125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision] * -0.375), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot b\right)\\
\frac{\mathsf{fma}\left(a \cdot a, \frac{c \cdot \left(c \cdot c\right)}{b \cdot t\_0} \cdot -0.5625, \mathsf{fma}\left(c, -0.5, \mathsf{fma}\left(-0.16666666666666666, \frac{\left(a \cdot a\right) \cdot \left(\left(a \cdot a\right) \cdot \left(\left(c \cdot c\right) \cdot \left(\left(c \cdot c\right) \cdot 6.328125\right)\right)\right)}{a \cdot \left(t\_0 \cdot t\_0\right)}, \frac{\left(a \cdot \left(c \cdot c\right)\right) \cdot -0.375}{b \cdot b}\right)\right)\right)}{b}
\end{array}
\end{array}
Initial program 30.0%
Taylor expanded in b around inf
Simplified94.8%
lift-pow.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f6494.8
Applied egg-rr94.8%
metadata-evalN/A
pow-plusN/A
cube-unmultN/A
lift-*.f64N/A
lift-*.f64N/A
lower-*.f6494.8
Applied egg-rr94.8%
Final simplification94.8%
(FPCore (a b c) :precision binary64 (fma a (fma (/ (* c (* c c)) (pow b 5.0)) (* a -0.5625) (/ (* (* c c) -0.375) (* b (* b b)))) (* -0.5 (/ c b))))
double code(double a, double b, double c) {
return fma(a, fma(((c * (c * c)) / pow(b, 5.0)), (a * -0.5625), (((c * c) * -0.375) / (b * (b * b)))), (-0.5 * (c / b)));
}
function code(a, b, c) return fma(a, fma(Float64(Float64(c * Float64(c * c)) / (b ^ 5.0)), Float64(a * -0.5625), Float64(Float64(Float64(c * c) * -0.375) / Float64(b * Float64(b * b)))), Float64(-0.5 * Float64(c / b))) end
code[a_, b_, c_] := N[(a * N[(N[(N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] * N[(a * -0.5625), $MachinePrecision] + N[(N[(N[(c * c), $MachinePrecision] * -0.375), $MachinePrecision] / N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, \mathsf{fma}\left(\frac{c \cdot \left(c \cdot c\right)}{{b}^{5}}, a \cdot -0.5625, \frac{\left(c \cdot c\right) \cdot -0.375}{b \cdot \left(b \cdot b\right)}\right), -0.5 \cdot \frac{c}{b}\right)
\end{array}
Initial program 30.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
Simplified93.3%
Final simplification93.3%
(FPCore (a b c) :precision binary64 (/ (fma (* a a) (* (/ (* c (* c c)) (* b (* b (* b b)))) -0.5625) (fma c -0.5 (/ (* -0.375 (* c (* a c))) (* b b)))) b))
double code(double a, double b, double c) {
return fma((a * a), (((c * (c * c)) / (b * (b * (b * b)))) * -0.5625), fma(c, -0.5, ((-0.375 * (c * (a * c))) / (b * b)))) / b;
}
function code(a, b, c) return Float64(fma(Float64(a * a), Float64(Float64(Float64(c * Float64(c * c)) / Float64(b * Float64(b * Float64(b * b)))) * -0.5625), fma(c, -0.5, Float64(Float64(-0.375 * Float64(c * Float64(a * c))) / Float64(b * b)))) / b) end
code[a_, b_, c_] := N[(N[(N[(a * a), $MachinePrecision] * N[(N[(N[(c * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(b * N[(b * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5625), $MachinePrecision] + N[(c * -0.5 + N[(N[(-0.375 * N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(a \cdot a, \frac{c \cdot \left(c \cdot c\right)}{b \cdot \left(b \cdot \left(b \cdot b\right)\right)} \cdot -0.5625, \mathsf{fma}\left(c, -0.5, \frac{-0.375 \cdot \left(c \cdot \left(a \cdot c\right)\right)}{b \cdot b}\right)\right)}{b}
\end{array}
Initial program 30.0%
Taylor expanded in b around inf
Simplified94.8%
lift-pow.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f6494.8
Applied egg-rr94.8%
metadata-evalN/A
pow-plusN/A
cube-unmultN/A
lift-*.f64N/A
lift-*.f64N/A
lower-*.f6494.8
Applied egg-rr94.8%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6493.2
Simplified93.2%
Final simplification93.2%
(FPCore (a b c) :precision binary64 (/ (fma a (/ (* (* c c) -0.375) (* b b)) (* c -0.5)) b))
double code(double a, double b, double c) {
return fma(a, (((c * c) * -0.375) / (b * b)), (c * -0.5)) / b;
}
function code(a, b, c) return Float64(fma(a, Float64(Float64(Float64(c * c) * -0.375) / Float64(b * b)), Float64(c * -0.5)) / b) end
code[a_, b_, c_] := N[(N[(a * N[(N[(N[(c * c), $MachinePrecision] * -0.375), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(c * -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(a, \frac{\left(c \cdot c\right) \cdot -0.375}{b \cdot b}, c \cdot -0.5\right)}{b}
\end{array}
Initial program 30.0%
Taylor expanded in b around inf
lower-/.f64N/A
Simplified90.6%
(FPCore (a b c) :precision binary64 (/ (* c (fma -0.375 (* a (/ c (* b b))) -0.5)) b))
double code(double a, double b, double c) {
return (c * fma(-0.375, (a * (c / (b * b))), -0.5)) / b;
}
function code(a, b, c) return Float64(Float64(c * fma(-0.375, Float64(a * Float64(c / Float64(b * b))), -0.5)) / b) end
code[a_, b_, c_] := N[(N[(c * N[(-0.375 * N[(a * N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot \mathsf{fma}\left(-0.375, a \cdot \frac{c}{b \cdot b}, -0.5\right)}{b}
\end{array}
Initial program 30.0%
Taylor expanded in b around inf
Simplified94.8%
Taylor expanded in c around 0
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6490.5
Simplified90.5%
(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 30.0%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6482.2
Simplified82.2%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.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.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 30.0%
Applied egg-rr29.9%
Applied egg-rr29.9%
Applied egg-rr29.5%
Taylor expanded in c around 0
distribute-rgt-outN/A
metadata-evalN/A
mul0-rgt3.2
Simplified3.2%
herbie shell --seed 2024212
(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)))