
(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 (expm1 (expm1 (log1p (log1p (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))))))
double code(double v) {
return expm1(expm1(log1p(log1p(acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0)))))));
}
function code(v) return expm1(expm1(log1p(log1p(acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0))))))) end
code[v_] := N[(Exp[N[(Exp[N[Log[1 + N[Log[1 + N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)\right)\right)
\end{array}
Initial program 98.7%
expm1-log1p-u98.7%
sub-neg98.7%
+-commutative98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
fma-def98.7%
metadata-eval98.7%
fma-neg98.7%
metadata-eval98.7%
Applied egg-rr98.7%
expm1-log1p-u98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (v) :precision binary64 (expm1 (log (+ 1.0 (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0)))))))
double code(double v) {
return expm1(log((1.0 + acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0))))));
}
function code(v) return expm1(log(Float64(1.0 + acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0)))))) end
code[v_] := N[(Exp[N[Log[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]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\log \left(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 98.7%
expm1-log1p-u98.7%
sub-neg98.7%
+-commutative98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
fma-def98.7%
metadata-eval98.7%
fma-neg98.7%
metadata-eval98.7%
Applied egg-rr98.7%
log1p-udef98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (v) :precision binary64 (expm1 (log1p (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))))
double code(double v) {
return expm1(log1p(acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0)))));
}
function code(v) return expm1(log1p(acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0))))) end
code[v_] := N[(Exp[N[Log[1 + N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\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 98.7%
expm1-log1p-u98.7%
sub-neg98.7%
+-commutative98.7%
*-commutative98.7%
distribute-rgt-neg-in98.7%
fma-def98.7%
metadata-eval98.7%
fma-neg98.7%
metadata-eval98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (v) :precision binary64 (acos (+ -1.0 (* 4.0 (* (* v v) (+ (* v v) 1.0))))))
double code(double v) {
return acos((-1.0 + (4.0 * ((v * v) * ((v * v) + 1.0)))));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((-1.0d0) + (4.0d0 * ((v * v) * ((v * v) + 1.0d0)))))
end function
public static double code(double v) {
return Math.acos((-1.0 + (4.0 * ((v * v) * ((v * v) + 1.0)))));
}
def code(v): return math.acos((-1.0 + (4.0 * ((v * v) * ((v * v) + 1.0)))))
function code(v) return acos(Float64(-1.0 + Float64(4.0 * Float64(Float64(v * v) * Float64(Float64(v * v) + 1.0))))) end
function tmp = code(v) tmp = acos((-1.0 + (4.0 * ((v * v) * ((v * v) + 1.0))))); end
code[v_] := N[ArcCos[N[(-1.0 + N[(4.0 * N[(N[(v * v), $MachinePrecision] * N[(N[(v * v), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(-1 + 4 \cdot \left(\left(v \cdot v\right) \cdot \left(v \cdot v + 1\right)\right)\right)
\end{array}
Initial program 98.7%
Taylor expanded in v around 0 98.6%
sub-neg98.6%
unpow298.6%
distribute-lft-out98.6%
metadata-eval98.6%
Simplified98.6%
sqr-pow98.6%
metadata-eval98.6%
pow298.6%
metadata-eval98.6%
pow298.6%
distribute-rgt1-in98.6%
Applied egg-rr98.6%
Final simplification98.6%
(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 98.7%
Final simplification98.7%
(FPCore (v) :precision binary64 (acos (+ -1.0 (* v (* v 4.0)))))
double code(double v) {
return acos((-1.0 + (v * (v * 4.0))));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((-1.0d0) + (v * (v * 4.0d0))))
end function
public static double code(double v) {
return Math.acos((-1.0 + (v * (v * 4.0))));
}
def code(v): return math.acos((-1.0 + (v * (v * 4.0))))
function code(v) return acos(Float64(-1.0 + Float64(v * Float64(v * 4.0)))) end
function tmp = code(v) tmp = acos((-1.0 + (v * (v * 4.0)))); end
code[v_] := N[ArcCos[N[(-1.0 + N[(v * N[(v * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(-1 + v \cdot \left(v \cdot 4\right)\right)
\end{array}
Initial program 98.7%
Taylor expanded in v around 0 98.6%
sub-neg98.6%
unpow298.6%
distribute-lft-out98.6%
metadata-eval98.6%
Simplified98.6%
Taylor expanded in v around 0 98.3%
unpow298.3%
*-commutative98.3%
associate-*r*98.3%
Simplified98.3%
Final simplification98.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 98.7%
Taylor expanded in v around 0 97.6%
Final simplification97.6%
herbie shell --seed 2023264
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))