
(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 (pow (pow (acos (/ (fma v (* v -5.0) 1.0) (fma v v -1.0))) 3.0) 0.3333333333333333))
double code(double v) {
return pow(pow(acos((fma(v, (v * -5.0), 1.0) / fma(v, v, -1.0))), 3.0), 0.3333333333333333);
}
function code(v) return (acos(Float64(fma(v, Float64(v * -5.0), 1.0) / fma(v, v, -1.0))) ^ 3.0) ^ 0.3333333333333333 end
code[v_] := N[Power[N[Power[N[ArcCos[N[(N[(v * N[(v * -5.0), $MachinePrecision] + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision]
\begin{array}{l}
\\
{\left({\cos^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}^{3}\right)}^{0.3333333333333333}
\end{array}
Initial program 98.8%
sub-neg98.8%
+-commutative98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
metadata-eval98.8%
associate-*r*98.8%
fma-udef98.8%
fma-neg98.8%
metadata-eval98.8%
add-cbrt-cube97.3%
pow1/398.8%
pow398.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (v) :precision binary64 (- (* PI 0.5) (asin (/ (fma v (* v -5.0) 1.0) (fma v v -1.0)))))
double code(double v) {
return (((double) M_PI) * 0.5) - asin((fma(v, (v * -5.0), 1.0) / fma(v, v, -1.0)));
}
function code(v) return Float64(Float64(pi * 0.5) - asin(Float64(fma(v, Float64(v * -5.0), 1.0) / fma(v, v, -1.0)))) end
code[v_] := N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(N[(v * N[(v * -5.0), $MachinePrecision] + 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, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Initial program 98.8%
acos-asin98.8%
sub-neg98.8%
div-inv98.8%
metadata-eval98.8%
sub-neg98.8%
+-commutative98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
metadata-eval98.8%
associate-*r*98.8%
fma-udef98.8%
fma-neg98.8%
metadata-eval98.8%
Applied egg-rr98.8%
sub-neg98.8%
Simplified98.8%
Final simplification98.8%
(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(v, Float64(v * -5.0), 1.0) / fma(v, v, -1.0))) end
code[v_] := N[ArcCos[N[(N[(v * N[(v * -5.0), $MachinePrecision] + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{\mathsf{fma}\left(v, v \cdot -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Initial program 98.8%
sub-neg98.8%
sqr-neg98.8%
+-commutative98.8%
associate-*r*98.8%
distribute-rgt-neg-in98.8%
remove-double-neg98.8%
*-commutative98.8%
fma-def98.8%
distribute-rgt-neg-out98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
metadata-eval98.8%
fma-neg98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (+ -1.0 (* v v)))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v))));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((-1.0d0) + (v * v))))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v))));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v))))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(-1.0 + Float64(v * v)))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v)))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{-1 + v \cdot v}\right)
\end{array}
Initial program 98.8%
Final simplification98.8%
(FPCore (v) :precision binary64 (acos (* (+ 1.0 (* v 2.0)) (+ -1.0 (* v 2.0)))))
double code(double v) {
return acos(((1.0 + (v * 2.0)) * (-1.0 + (v * 2.0))));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 + (v * 2.0d0)) * ((-1.0d0) + (v * 2.0d0))))
end function
public static double code(double v) {
return Math.acos(((1.0 + (v * 2.0)) * (-1.0 + (v * 2.0))));
}
def code(v): return math.acos(((1.0 + (v * 2.0)) * (-1.0 + (v * 2.0))))
function code(v) return acos(Float64(Float64(1.0 + Float64(v * 2.0)) * Float64(-1.0 + Float64(v * 2.0)))) end
function tmp = code(v) tmp = acos(((1.0 + (v * 2.0)) * (-1.0 + (v * 2.0)))); end
code[v_] := N[ArcCos[N[(N[(1.0 + N[(v * 2.0), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(v * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\left(1 + v \cdot 2\right) \cdot \left(-1 + v \cdot 2\right)\right)
\end{array}
Initial program 98.8%
Taylor expanded in v around 0 98.3%
add-sqr-sqrt98.3%
difference-of-sqr-198.2%
*-commutative98.2%
sqrt-prod98.2%
unpow298.2%
sqrt-prod44.7%
add-sqr-sqrt97.5%
metadata-eval97.5%
*-commutative97.5%
sqrt-prod97.5%
unpow297.5%
sqrt-prod44.7%
add-sqr-sqrt98.2%
metadata-eval98.2%
Applied egg-rr98.2%
Final simplification98.2%
(FPCore (v) :precision binary64 (acos (* (/ 1.0 (+ v 1.0)) (- -1.0 v))))
double code(double v) {
return acos(((1.0 / (v + 1.0)) * (-1.0 - v)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 / (v + 1.0d0)) * ((-1.0d0) - v)))
end function
public static double code(double v) {
return Math.acos(((1.0 / (v + 1.0)) * (-1.0 - v)));
}
def code(v): return math.acos(((1.0 / (v + 1.0)) * (-1.0 - v)))
function code(v) return acos(Float64(Float64(1.0 / Float64(v + 1.0)) * Float64(-1.0 - v))) end
function tmp = code(v) tmp = acos(((1.0 / (v + 1.0)) * (-1.0 - v))); end
code[v_] := N[ArcCos[N[(N[(1.0 / N[(v + 1.0), $MachinePrecision]), $MachinePrecision] * N[(-1.0 - v), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1}{v + 1} \cdot \left(-1 - v\right)\right)
\end{array}
Initial program 98.8%
*-un-lft-identity98.8%
difference-of-sqr-197.0%
times-frac97.0%
+-commutative97.0%
sub-neg97.0%
+-commutative97.0%
*-commutative97.0%
distribute-rgt-neg-in97.0%
metadata-eval97.0%
associate-*r*97.0%
fma-udef97.0%
sub-neg97.0%
metadata-eval97.0%
Applied egg-rr97.0%
Taylor expanded in v around 0 97.8%
sub-neg97.8%
metadata-eval97.8%
+-commutative97.8%
neg-mul-197.8%
unsub-neg97.8%
Simplified97.8%
Final simplification97.8%
(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.8%
Taylor expanded in v around 0 97.8%
Final simplification97.8%
herbie shell --seed 2023306
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))