
(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 9 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 (expm1 (* 2.0 (log (sqrt (+ 1.0 (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0)))))))))
double code(double v) {
return expm1((2.0 * log(sqrt((1.0 + acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0))))))));
}
function code(v) return expm1(Float64(2.0 * log(sqrt(Float64(1.0 + acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0)))))))) end
code[v_] := N[(Exp[N[(2.0 * N[Log[N[Sqrt[N[(1.0 + N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(2 \cdot \log \left(\sqrt{1 + \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}\right)\right)
\end{array}
Initial program 99.0%
sub-neg99.0%
sqr-neg99.0%
+-commutative99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
fma-define99.0%
sqr-neg99.0%
metadata-eval99.0%
fmm-def99.0%
metadata-eval99.0%
Simplified99.0%
metadata-eval99.0%
fmm-def99.0%
fma-undefine99.0%
metadata-eval99.0%
distribute-rgt-neg-in99.0%
*-commutative99.0%
+-commutative99.0%
sub-neg99.0%
expm1-log1p-u99.0%
expm1-undefine99.0%
Applied egg-rr99.0%
expm1-define99.0%
Simplified99.0%
add-sqr-sqrt99.0%
pow299.0%
Applied egg-rr99.0%
unpow299.0%
add-sqr-sqrt99.0%
log1p-undefine99.0%
add-sqr-sqrt99.0%
log-prod99.0%
Applied egg-rr99.0%
count-299.0%
Simplified99.0%
unpow299.0%
Applied egg-rr99.0%
(FPCore (v) :precision binary64 (- (* PI 0.5) (log1p (expm1 (asin (/ (- 1.0 (* (* v v) 5.0)) (fma v v -1.0)))))))
double code(double v) {
return (((double) M_PI) * 0.5) - log1p(expm1(asin(((1.0 - ((v * v) * 5.0)) / fma(v, v, -1.0)))));
}
function code(v) return Float64(Float64(pi * 0.5) - log1p(expm1(asin(Float64(Float64(1.0 - Float64(Float64(v * v) * 5.0)) / fma(v, v, -1.0)))))) end
code[v_] := N[(N[(Pi * 0.5), $MachinePrecision] - N[Log[1 + N[(Exp[N[ArcSin[N[(N[(1.0 - N[(N[(v * v), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot 0.5 - \mathsf{log1p}\left(\mathsf{expm1}\left(\sin^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)
\end{array}
Initial program 99.0%
sub-neg99.0%
sqr-neg99.0%
+-commutative99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
fma-define99.0%
sqr-neg99.0%
metadata-eval99.0%
fmm-def99.0%
metadata-eval99.0%
Simplified99.0%
acos-asin99.0%
sub-neg99.0%
metadata-eval99.0%
fmm-def99.0%
fma-undefine99.0%
metadata-eval99.0%
distribute-rgt-neg-in99.0%
*-commutative99.0%
+-commutative99.0%
sub-neg99.0%
div-inv99.0%
metadata-eval99.0%
Applied egg-rr99.0%
sub-neg99.0%
Simplified99.0%
log1p-expm1-u99.0%
Applied egg-rr99.0%
fma-undefine99.0%
pow299.0%
metadata-eval99.0%
distribute-rgt-neg-in99.0%
*-commutative99.0%
+-commutative99.0%
sub-neg99.0%
pow299.0%
Applied egg-rr99.0%
unpow299.0%
Applied egg-rr99.0%
Final simplification99.0%
(FPCore (v) :precision binary64 (- (* PI 0.5) (asin (/ (fma (pow v 2.0) -5.0 1.0) (fma v v -1.0)))))
double code(double v) {
return (((double) M_PI) * 0.5) - asin((fma(pow(v, 2.0), -5.0, 1.0) / fma(v, v, -1.0)));
}
function code(v) return Float64(Float64(pi * 0.5) - asin(Float64(fma((v ^ 2.0), -5.0, 1.0) / fma(v, v, -1.0)))) end
code[v_] := N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(N[(N[Power[v, 2.0], $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot 0.5 - \sin^{-1} \left(\frac{\mathsf{fma}\left({v}^{2}, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Initial program 99.0%
sub-neg99.0%
sqr-neg99.0%
+-commutative99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
fma-define99.0%
sqr-neg99.0%
metadata-eval99.0%
fmm-def99.0%
metadata-eval99.0%
Simplified99.0%
acos-asin99.0%
sub-neg99.0%
metadata-eval99.0%
fmm-def99.0%
fma-undefine99.0%
metadata-eval99.0%
distribute-rgt-neg-in99.0%
*-commutative99.0%
+-commutative99.0%
sub-neg99.0%
div-inv99.0%
metadata-eval99.0%
Applied egg-rr99.0%
sub-neg99.0%
Simplified99.0%
(FPCore (v) :precision binary64 (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))
double code(double v) {
return acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0)));
}
function code(v) return acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0))) end
code[v_] := N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Initial program 99.0%
sub-neg99.0%
sqr-neg99.0%
+-commutative99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
fma-define99.0%
sqr-neg99.0%
metadata-eval99.0%
fmm-def99.0%
metadata-eval99.0%
Simplified99.0%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* (* v v) 5.0)) (+ (* v v) -1.0))))
double code(double v) {
return acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - ((v * v) * 5.0d0)) / ((v * v) + (-1.0d0))))
end function
public static double code(double v) {
return Math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
def code(v): return math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(Float64(v * v) * 5.0)) / Float64(Float64(v * v) + -1.0))) end
function tmp = code(v) tmp = acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(N[(v * v), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right)
\end{array}
Initial program 99.0%
Final simplification99.0%
(FPCore (v) :precision binary64 (- (* PI 0.5) (asin (+ -1.0 (* (* v v) 4.0)))))
double code(double v) {
return (((double) M_PI) * 0.5) - asin((-1.0 + ((v * v) * 4.0)));
}
public static double code(double v) {
return (Math.PI * 0.5) - Math.asin((-1.0 + ((v * v) * 4.0)));
}
def code(v): return (math.pi * 0.5) - math.asin((-1.0 + ((v * v) * 4.0)))
function code(v) return Float64(Float64(pi * 0.5) - asin(Float64(-1.0 + Float64(Float64(v * v) * 4.0)))) end
function tmp = code(v) tmp = (pi * 0.5) - asin((-1.0 + ((v * v) * 4.0))); end
code[v_] := N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(-1.0 + N[(N[(v * v), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot 0.5 - \sin^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right)
\end{array}
Initial program 99.0%
sub-neg99.0%
sqr-neg99.0%
+-commutative99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
fma-define99.0%
sqr-neg99.0%
metadata-eval99.0%
fmm-def99.0%
metadata-eval99.0%
Simplified99.0%
acos-asin99.0%
sub-neg99.0%
metadata-eval99.0%
fmm-def99.0%
fma-undefine99.0%
metadata-eval99.0%
distribute-rgt-neg-in99.0%
*-commutative99.0%
+-commutative99.0%
sub-neg99.0%
div-inv99.0%
metadata-eval99.0%
Applied egg-rr99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in v around 0 97.9%
unpow299.0%
Applied egg-rr97.9%
Final simplification97.9%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* (* v v) 5.0)) -1.0)))
double code(double v) {
return acos(((1.0 - ((v * v) * 5.0)) / -1.0));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - ((v * v) * 5.0d0)) / (-1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - ((v * v) * 5.0)) / -1.0));
}
def code(v): return math.acos(((1.0 - ((v * v) * 5.0)) / -1.0))
function code(v) return acos(Float64(Float64(1.0 - Float64(Float64(v * v) * 5.0)) / -1.0)) end
function tmp = code(v) tmp = acos(((1.0 - ((v * v) * 5.0)) / -1.0)); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(N[(v * v), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{-1}\right)
\end{array}
Initial program 99.0%
Taylor expanded in v around 0 97.3%
Final simplification97.3%
(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 99.0%
Taylor expanded in v around 0 97.3%
Taylor expanded in v around 0 97.1%
(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 99.0%
sub-neg99.0%
sqr-neg99.0%
+-commutative99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
fma-define99.0%
sqr-neg99.0%
metadata-eval99.0%
fmm-def99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in v around inf 0.0%
herbie shell --seed 2024176
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))