
(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 4 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 (acos (/ (- 1.0 (log (+ 1.0 (expm1 (* 5.0 (pow v 2.0)))))) (+ (* v v) -1.0))))
double code(double v) {
return acos(((1.0 - log((1.0 + expm1((5.0 * pow(v, 2.0)))))) / ((v * v) + -1.0)));
}
public static double code(double v) {
return Math.acos(((1.0 - Math.log((1.0 + Math.expm1((5.0 * Math.pow(v, 2.0)))))) / ((v * v) + -1.0)));
}
def code(v): return math.acos(((1.0 - math.log((1.0 + math.expm1((5.0 * math.pow(v, 2.0)))))) / ((v * v) + -1.0)))
function code(v) return acos(Float64(Float64(1.0 - log(Float64(1.0 + expm1(Float64(5.0 * (v ^ 2.0)))))) / Float64(Float64(v * v) + -1.0))) end
code[v_] := N[ArcCos[N[(N[(1.0 - N[Log[N[(1.0 + N[(Exp[N[(5.0 * N[Power[v, 2.0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - \log \left(1 + \mathsf{expm1}\left(5 \cdot {v}^{2}\right)\right)}{v \cdot v + -1}\right)
\end{array}
Initial program 99.4%
log1p-expm1-u99.4%
log1p-udef99.4%
pow299.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (v) :precision binary64 (acos (/ (/ (+ 1.0 (* (pow v 2.0) -5.0)) (+ v -1.0)) (+ 1.0 v))))
double code(double v) {
return acos((((1.0 + (pow(v, 2.0) * -5.0)) / (v + -1.0)) / (1.0 + v)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos((((1.0d0 + ((v ** 2.0d0) * (-5.0d0))) / (v + (-1.0d0))) / (1.0d0 + v)))
end function
public static double code(double v) {
return Math.acos((((1.0 + (Math.pow(v, 2.0) * -5.0)) / (v + -1.0)) / (1.0 + v)));
}
def code(v): return math.acos((((1.0 + (math.pow(v, 2.0) * -5.0)) / (v + -1.0)) / (1.0 + v)))
function code(v) return acos(Float64(Float64(Float64(1.0 + Float64((v ^ 2.0) * -5.0)) / Float64(v + -1.0)) / Float64(1.0 + v))) end
function tmp = code(v) tmp = acos((((1.0 + ((v ^ 2.0) * -5.0)) / (v + -1.0)) / (1.0 + v))); end
code[v_] := N[ArcCos[N[(N[(N[(1.0 + N[(N[Power[v, 2.0], $MachinePrecision] * -5.0), $MachinePrecision]), $MachinePrecision] / N[(v + -1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 + v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{\frac{1 + {v}^{2} \cdot -5}{v + -1}}{1 + v}\right)
\end{array}
Initial program 99.4%
*-un-lft-identity99.4%
difference-of-sqr-199.4%
times-frac99.4%
+-commutative99.4%
pow299.4%
sub-neg99.4%
metadata-eval99.4%
Applied egg-rr99.4%
associate-*l/99.3%
*-lft-identity99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
*-commutative99.3%
Simplified99.3%
Final simplification99.3%
(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}
Initial program 99.4%
Final simplification99.4%
(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.4%
Taylor expanded in v around 0 98.7%
Final simplification98.7%
herbie shell --seed 2024029
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))