
(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 6 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
(let* ((t_0 (/ (PI) 2.0)))
(/
(fma
(* (PI) (PI))
(/ (PI) 8.0)
(pow (asin (/ (- (fma (* -5.0 v) v 1.0)) (fma v v -1.0))) 3.0))
(fma
(asin (/ (/ (fma (* v v) -5.0 1.0) (+ 1.0 v)) (- v 1.0)))
(+ (asin (/ (fma -5.0 (* v v) 1.0) (fma v v -1.0))) t_0)
(pow t_0 2.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{2}\\
\frac{\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), \frac{\mathsf{PI}\left(\right)}{8}, {\sin^{-1} \left(\frac{-\mathsf{fma}\left(-5 \cdot v, v, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}^{3}\right)}{\mathsf{fma}\left(\sin^{-1} \left(\frac{\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{1 + v}}{v - 1}\right), \sin^{-1} \left(\frac{\mathsf{fma}\left(-5, v \cdot v, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) + t\_0, {t\_0}^{2}\right)}
\end{array}
\end{array}
Initial program 99.2%
lift-acos.f64N/A
acos-asinN/A
flip3--N/A
lower-/.f64N/A
Applied rewrites99.2%
lift-/.f64N/A
lift-fma.f64N/A
difference-of-sqr--1N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6499.2
Applied rewrites99.2%
Applied rewrites99.2%
Final simplification99.2%
(FPCore (v)
:precision binary64
(let* ((t_0 (* (PI) (PI)))
(t_1 (asin (/ (fma (* v v) -5.0 1.0) (fma v v -1.0)))))
(/
(fma
t_0
(* (PI) 0.125)
(pow (asin (/ (- (fma (* -5.0 v) v 1.0)) (fma v v -1.0))) 3.0))
(fma (fma 0.5 (PI) t_1) t_1 (* t_0 0.25)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\\
\frac{\mathsf{fma}\left(t\_0, \mathsf{PI}\left(\right) \cdot 0.125, {\sin^{-1} \left(\frac{-\mathsf{fma}\left(-5 \cdot v, v, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}^{3}\right)}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), t\_1\right), t\_1, t\_0 \cdot 0.25\right)}
\end{array}
\end{array}
Initial program 99.2%
lift-acos.f64N/A
acos-asinN/A
flip3--N/A
lower-/.f64N/A
Applied rewrites99.2%
Taylor expanded in v around 0
lower-/.f64N/A
Applied rewrites99.2%
Applied rewrites99.2%
Final simplification99.2%
(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 99.2%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
metadata-eval99.2
lift--.f64N/A
lift-*.f64N/A
difference-of-sqr-1N/A
difference-of-sqr--1-revN/A
lower-fma.f6499.2
Applied rewrites99.2%
(FPCore (v) :precision binary64 (acos (- (* 4.0 (* v v)) 1.0)))
double code(double v) {
return acos(((4.0 * (v * v)) - 1.0));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((4.0d0 * (v * v)) - 1.0d0))
end function
public static double code(double v) {
return Math.acos(((4.0 * (v * v)) - 1.0));
}
def code(v): return math.acos(((4.0 * (v * v)) - 1.0))
function code(v) return acos(Float64(Float64(4.0 * Float64(v * v)) - 1.0)) end
function tmp = code(v) tmp = acos(((4.0 * (v * v)) - 1.0)); end
code[v_] := N[ArcCos[N[(N[(4.0 * N[(v * v), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(4 \cdot \left(v \cdot v\right) - 1\right)
\end{array}
Initial program 99.2%
Taylor expanded in v around 0
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.1
Applied rewrites99.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 99.2%
Taylor expanded in v around inf
Applied rewrites0.0%
Taylor expanded in v around 0
Applied rewrites98.5%
(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.2%
Taylor expanded in v around inf
Applied rewrites0.0%
herbie shell --seed 2024326
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))