
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
(FPCore (v) :precision binary64 (fma (PI) 0.5 (asin (/ (fma (* v v) 5.0 -1.0) (fma v v -1.0)))))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, 5, -1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)
\end{array}
Initial program 98.5%
lift-acos.f64N/A
acos-asinN/A
sub-negN/A
div-invN/A
lower-fma.f64N/A
lower-PI.f64N/A
metadata-evalN/A
asin-negN/A
lift-/.f64N/A
distribute-frac-neg2N/A
lower-asin.f64N/A
distribute-frac-neg2N/A
distribute-frac-negN/A
lower-/.f64N/A
Applied rewrites98.5%
(FPCore (v) :precision binary64 (acos (/ (fma -5.0 (* v v) 1.0) (fma v v -1.0))))
double code(double v) {
return acos((fma(-5.0, (v * v), 1.0) / fma(v, v, -1.0)));
}
function code(v) return acos(Float64(fma(-5.0, Float64(v * v), 1.0) / fma(v, v, -1.0))) end
code[v_] := N[ArcCos[N[(N[(-5.0 * N[(v * v), $MachinePrecision] + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Initial program 98.5%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
metadata-eval98.5
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval98.5
Applied rewrites98.5%
(FPCore (v) :precision binary64 (fma (PI) 0.5 (fma (PI) 0.5 (- (acos (fma -4.0 (* v v) 1.0))))))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, \mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, -\cos^{-1} \left(\mathsf{fma}\left(-4, v \cdot v, 1\right)\right)\right)\right)
\end{array}
Initial program 98.5%
lift-acos.f64N/A
acos-asinN/A
sub-negN/A
div-invN/A
lower-fma.f64N/A
lower-PI.f64N/A
metadata-evalN/A
asin-negN/A
lift-/.f64N/A
distribute-frac-neg2N/A
lower-asin.f64N/A
distribute-frac-neg2N/A
distribute-frac-negN/A
lower-/.f64N/A
Applied rewrites98.5%
Taylor expanded in v around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.1
Applied rewrites98.1%
lift-asin.f64N/A
asin-acosN/A
lift-PI.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-acos.f6498.1
Applied rewrites98.1%
(FPCore (v) :precision binary64 (fma (PI) 0.5 (asin (fma -4.0 (* v v) 1.0))))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, \sin^{-1} \left(\mathsf{fma}\left(-4, v \cdot v, 1\right)\right)\right)
\end{array}
Initial program 98.5%
lift-acos.f64N/A
acos-asinN/A
sub-negN/A
div-invN/A
lower-fma.f64N/A
lower-PI.f64N/A
metadata-evalN/A
asin-negN/A
lift-/.f64N/A
distribute-frac-neg2N/A
lower-asin.f64N/A
distribute-frac-neg2N/A
distribute-frac-negN/A
lower-/.f64N/A
Applied rewrites98.5%
Taylor expanded in v around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.1
Applied rewrites98.1%
(FPCore (v) :precision binary64 (acos (fma 4.0 (* v v) -1.0)))
double code(double v) {
return acos(fma(4.0, (v * v), -1.0));
}
function code(v) return acos(fma(4.0, Float64(v * v), -1.0)) end
code[v_] := N[ArcCos[N[(4.0 * N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\mathsf{fma}\left(4, v \cdot v, -1\right)\right)
\end{array}
Initial program 98.5%
Taylor expanded in v around 0
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.1
Applied rewrites98.1%
(FPCore (v) :precision binary64 (acos -1.0))
double code(double v) {
return acos(-1.0);
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos((-1.0d0))
end function
public static double code(double v) {
return Math.acos(-1.0);
}
def code(v): return math.acos(-1.0)
function code(v) return acos(-1.0) end
function tmp = code(v) tmp = acos(-1.0); end
code[v_] := N[ArcCos[-1.0], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} -1
\end{array}
Initial program 98.5%
Taylor expanded in v around inf
Applied rewrites0.0%
Taylor expanded in v around 0
Applied rewrites97.6%
(FPCore (v) :precision binary64 (acos -5.0))
double code(double v) {
return acos(-5.0);
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos((-5.0d0))
end function
public static double code(double v) {
return Math.acos(-5.0);
}
def code(v): return math.acos(-5.0)
function code(v) return acos(-5.0) end
function tmp = code(v) tmp = acos(-5.0); end
code[v_] := N[ArcCos[-5.0], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} -5
\end{array}
Initial program 98.5%
Taylor expanded in v around inf
Applied rewrites0.0%
herbie shell --seed 2024309
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))