
(FPCore (N) :precision binary64 (- (atan (+ N 1.0)) (atan N)))
double code(double N) {
return atan((N + 1.0)) - atan(N);
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan((n + 1.0d0)) - atan(n)
end function
public static double code(double N) {
return Math.atan((N + 1.0)) - Math.atan(N);
}
def code(N): return math.atan((N + 1.0)) - math.atan(N)
function code(N) return Float64(atan(Float64(N + 1.0)) - atan(N)) end
function tmp = code(N) tmp = atan((N + 1.0)) - atan(N); end
code[N_] := N[(N[ArcTan[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[ArcTan[N], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(N + 1\right) - \tan^{-1} N
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (N) :precision binary64 (- (atan (+ N 1.0)) (atan N)))
double code(double N) {
return atan((N + 1.0)) - atan(N);
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan((n + 1.0d0)) - atan(n)
end function
public static double code(double N) {
return Math.atan((N + 1.0)) - Math.atan(N);
}
def code(N): return math.atan((N + 1.0)) - math.atan(N)
function code(N) return Float64(atan(Float64(N + 1.0)) - atan(N)) end
function tmp = code(N) tmp = atan((N + 1.0)) - atan(N); end
code[N_] := N[(N[ArcTan[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[ArcTan[N], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(N + 1\right) - \tan^{-1} N
\end{array}
(FPCore (N) :precision binary64 (atan2 1.0 (fma N (+ 1.0 N) 1.0)))
double code(double N) {
return atan2(1.0, fma(N, (1.0 + N), 1.0));
}
function code(N) return atan(1.0, fma(N, Float64(1.0 + N), 1.0)) end
code[N_] := N[ArcTan[1.0 / N[(N * N[(1.0 + N), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, 1 + N, 1\right)}
\end{array}
Initial program 75.0%
diff-atan77.2%
associate--l+77.2%
+-commutative77.2%
*-commutative77.2%
fma-def77.2%
Applied egg-rr77.2%
+-commutative77.2%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (N) :precision binary64 (- (atan (+ 1.0 N)) (atan N)))
double code(double N) {
return atan((1.0 + N)) - atan(N);
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan((1.0d0 + n)) - atan(n)
end function
public static double code(double N) {
return Math.atan((1.0 + N)) - Math.atan(N);
}
def code(N): return math.atan((1.0 + N)) - math.atan(N)
function code(N) return Float64(atan(Float64(1.0 + N)) - atan(N)) end
function tmp = code(N) tmp = atan((1.0 + N)) - atan(N); end
code[N_] := N[(N[ArcTan[N[(1.0 + N), $MachinePrecision]], $MachinePrecision] - N[ArcTan[N], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(1 + N\right) - \tan^{-1} N
\end{array}
Initial program 75.0%
Final simplification75.0%
(FPCore (N) :precision binary64 (atan (/ 1.0 (+ 1.0 (* N (+ N 1.0))))))
double code(double N) {
return atan((1.0 / (1.0 + (N * (N + 1.0)))));
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan((1.0d0 / (1.0d0 + (n * (n + 1.0d0)))))
end function
public static double code(double N) {
return Math.atan((1.0 / (1.0 + (N * (N + 1.0)))));
}
def code(N): return math.atan((1.0 / (1.0 + (N * (N + 1.0)))))
function code(N) return atan(Float64(1.0 / Float64(1.0 + Float64(N * Float64(N + 1.0))))) end
function tmp = code(N) tmp = atan((1.0 / (1.0 + (N * (N + 1.0))))); end
code[N_] := N[ArcTan[N[(1.0 / N[(1.0 + N[(N * N[(N + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1} \left(\frac{1}{1 + N \cdot \left(N + 1\right)}\right)
\end{array}
herbie shell --seed 2023187
(FPCore (N)
:name "2atan (example 3.5)"
:precision binary64
:herbie-target
(atan (/ 1.0 (+ 1.0 (* N (+ N 1.0)))))
(- (atan (+ N 1.0)) (atan N)))