
(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 6 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 (+ N (fma N N 1.0))))
double code(double N) {
return atan2(1.0, (N + fma(N, N, 1.0)));
}
function code(N) return atan(1.0, Float64(N + fma(N, N, 1.0))) end
code[N_] := N[ArcTan[1.0 / N[(N + N[(N * N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{N + \mathsf{fma}\left(N, N, 1\right)}
\end{array}
Initial program 9.2%
diff-atan18.8%
associate--l+18.8%
+-commutative18.8%
*-commutative18.8%
fma-def18.8%
Applied egg-rr18.8%
+-commutative18.8%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
add-cube-cbrt97.9%
pow397.9%
Applied egg-rr97.9%
unpow397.9%
add-cube-cbrt99.5%
fma-udef99.5%
distribute-rgt-in99.5%
*-un-lft-identity99.5%
unpow299.5%
associate-+l+99.5%
unpow299.5%
fma-def99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (N) :precision binary64 (atan2 1.0 (+ 1.0 (* N (+ 1.0 N)))))
double code(double N) {
return atan2(1.0, (1.0 + (N * (1.0 + N))));
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan2(1.0d0, (1.0d0 + (n * (1.0d0 + n))))
end function
public static double code(double N) {
return Math.atan2(1.0, (1.0 + (N * (1.0 + N))));
}
def code(N): return math.atan2(1.0, (1.0 + (N * (1.0 + N))))
function code(N) return atan(1.0, Float64(1.0 + Float64(N * Float64(1.0 + N)))) end
function tmp = code(N) tmp = atan2(1.0, (1.0 + (N * (1.0 + N)))); end
code[N_] := N[ArcTan[1.0 / N[(1.0 + N[(N * N[(1.0 + N), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{1 + N \cdot \left(1 + N\right)}
\end{array}
Initial program 9.2%
diff-atan18.8%
associate--l+18.8%
+-commutative18.8%
*-commutative18.8%
fma-def18.8%
Applied egg-rr18.8%
+-commutative18.8%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in N around 0 99.5%
unpow295.8%
distribute-rgt1-in95.8%
+-commutative95.8%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (N) :precision binary64 (atan2 1.0 (* N (+ 1.0 N))))
double code(double N) {
return atan2(1.0, (N * (1.0 + N)));
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan2(1.0d0, (n * (1.0d0 + n)))
end function
public static double code(double N) {
return Math.atan2(1.0, (N * (1.0 + N)));
}
def code(N): return math.atan2(1.0, (N * (1.0 + N)))
function code(N) return atan(1.0, Float64(N * Float64(1.0 + N))) end
function tmp = code(N) tmp = atan2(1.0, (N * (1.0 + N))); end
code[N_] := N[ArcTan[1.0 / N[(N * N[(1.0 + N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{N \cdot \left(1 + N\right)}
\end{array}
Initial program 9.2%
diff-atan18.8%
associate--l+18.8%
+-commutative18.8%
*-commutative18.8%
fma-def18.8%
Applied egg-rr18.8%
+-commutative18.8%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in N around inf 95.8%
unpow295.8%
distribute-rgt1-in95.8%
+-commutative95.8%
Applied egg-rr95.8%
Final simplification95.8%
(FPCore (N) :precision binary64 (atan2 1.0 (+ 1.0 N)))
double code(double N) {
return atan2(1.0, (1.0 + N));
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan2(1.0d0, (1.0d0 + n))
end function
public static double code(double N) {
return Math.atan2(1.0, (1.0 + N));
}
def code(N): return math.atan2(1.0, (1.0 + N))
function code(N) return atan(1.0, Float64(1.0 + N)) end
function tmp = code(N) tmp = atan2(1.0, (1.0 + N)); end
code[N_] := N[ArcTan[1.0 / N[(1.0 + N), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{1 + N}
\end{array}
Initial program 9.2%
diff-atan18.8%
associate--l+18.8%
+-commutative18.8%
*-commutative18.8%
fma-def18.8%
Applied egg-rr18.8%
+-commutative18.8%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in N around 0 8.0%
Final simplification8.0%
(FPCore (N) :precision binary64 (atan2 1.0 1.0))
double code(double N) {
return atan2(1.0, 1.0);
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan2(1.0d0, 1.0d0)
end function
public static double code(double N) {
return Math.atan2(1.0, 1.0);
}
def code(N): return math.atan2(1.0, 1.0)
function code(N) return atan(1.0, 1.0) end
function tmp = code(N) tmp = atan2(1.0, 1.0); end
code[N_] := N[ArcTan[1.0 / 1.0], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{1}
\end{array}
Initial program 9.2%
diff-atan18.8%
associate--l+18.8%
+-commutative18.8%
*-commutative18.8%
fma-def18.8%
Applied egg-rr18.8%
+-commutative18.8%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in N around 0 6.5%
Final simplification6.5%
(FPCore (N) :precision binary64 (atan2 1.0 N))
double code(double N) {
return atan2(1.0, N);
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan2(1.0d0, n)
end function
public static double code(double N) {
return Math.atan2(1.0, N);
}
def code(N): return math.atan2(1.0, N)
function code(N) return atan(1.0, N) end
function tmp = code(N) tmp = atan2(1.0, N); end
code[N_] := N[ArcTan[1.0 / N], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{N}
\end{array}
Initial program 9.2%
diff-atan18.8%
associate--l+18.8%
+-commutative18.8%
*-commutative18.8%
fma-def18.8%
Applied egg-rr18.8%
+-commutative18.8%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in N around inf 95.8%
Taylor expanded in N around 0 8.0%
Final simplification8.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 2024041
(FPCore (N)
:name "2atan (example 3.5)"
:precision binary64
:pre (and (> N 1.0) (< N 1e+100))
:herbie-target
(atan (/ 1.0 (+ 1.0 (* N (+ N 1.0)))))
(- (atan (+ N 1.0)) (atan N)))