
(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 (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 74.1%
diff-atan75.6%
associate--l+75.6%
+-commutative75.6%
*-commutative75.6%
fma-def75.6%
Applied egg-rr75.6%
+-commutative75.6%
associate-+l-99.1%
+-inverses99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (N) :precision binary64 (if (or (<= N -1.0) (not (<= N 1.0))) (atan2 1.0 (+ N (* N N))) (atan2 1.0 (+ 1.0 N))))
double code(double N) {
double tmp;
if ((N <= -1.0) || !(N <= 1.0)) {
tmp = atan2(1.0, (N + (N * N)));
} else {
tmp = atan2(1.0, (1.0 + N));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-1.0d0)) .or. (.not. (n <= 1.0d0))) then
tmp = atan2(1.0d0, (n + (n * n)))
else
tmp = atan2(1.0d0, (1.0d0 + n))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((N <= -1.0) || !(N <= 1.0)) {
tmp = Math.atan2(1.0, (N + (N * N)));
} else {
tmp = Math.atan2(1.0, (1.0 + N));
}
return tmp;
}
def code(N): tmp = 0 if (N <= -1.0) or not (N <= 1.0): tmp = math.atan2(1.0, (N + (N * N))) else: tmp = math.atan2(1.0, (1.0 + N)) return tmp
function code(N) tmp = 0.0 if ((N <= -1.0) || !(N <= 1.0)) tmp = atan(1.0, Float64(N + Float64(N * N))); else tmp = atan(1.0, Float64(1.0 + N)); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((N <= -1.0) || ~((N <= 1.0))) tmp = atan2(1.0, (N + (N * N))); else tmp = atan2(1.0, (1.0 + N)); end tmp_2 = tmp; end
code[N_] := If[Or[LessEqual[N, -1.0], N[Not[LessEqual[N, 1.0]], $MachinePrecision]], N[ArcTan[1.0 / N[(N + N[(N * N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0 / N[(1.0 + N), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq -1 \lor \neg \left(N \leq 1\right):\\
\;\;\;\;\tan^{-1}_* \frac{1}{N + N \cdot N}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{1 + N}\\
\end{array}
\end{array}
if N < -1 or 1 < N Initial program 49.9%
diff-atan52.7%
associate--l+52.7%
+-commutative52.7%
*-commutative52.7%
fma-def52.7%
Applied egg-rr52.7%
+-commutative52.7%
associate-+l-98.4%
+-inverses98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in N around 0 98.4%
+-commutative98.4%
flip-+31.0%
div-inv31.0%
fma-def31.0%
metadata-eval31.0%
pow-prod-up31.0%
metadata-eval31.0%
unpow231.0%
Applied egg-rr31.0%
fma-udef31.0%
+-commutative31.0%
associate-*r/31.0%
*-rgt-identity31.0%
Simplified31.0%
Taylor expanded in N around inf 96.2%
unpow296.2%
Simplified96.2%
if -1 < N < 1Initial program 100.0%
diff-atan99.9%
associate--l+100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
+-commutative100.0%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in N around 0 97.0%
Final simplification96.6%
(FPCore (N) :precision binary64 (if (or (<= N -1.0) (not (<= N 1.0))) (atan2 1.0 (* N N)) (atan2 1.0 1.0)))
double code(double N) {
double tmp;
if ((N <= -1.0) || !(N <= 1.0)) {
tmp = atan2(1.0, (N * N));
} else {
tmp = atan2(1.0, 1.0);
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-1.0d0)) .or. (.not. (n <= 1.0d0))) then
tmp = atan2(1.0d0, (n * n))
else
tmp = atan2(1.0d0, 1.0d0)
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((N <= -1.0) || !(N <= 1.0)) {
tmp = Math.atan2(1.0, (N * N));
} else {
tmp = Math.atan2(1.0, 1.0);
}
return tmp;
}
def code(N): tmp = 0 if (N <= -1.0) or not (N <= 1.0): tmp = math.atan2(1.0, (N * N)) else: tmp = math.atan2(1.0, 1.0) return tmp
function code(N) tmp = 0.0 if ((N <= -1.0) || !(N <= 1.0)) tmp = atan(1.0, Float64(N * N)); else tmp = atan(1.0, 1.0); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((N <= -1.0) || ~((N <= 1.0))) tmp = atan2(1.0, (N * N)); else tmp = atan2(1.0, 1.0); end tmp_2 = tmp; end
code[N_] := If[Or[LessEqual[N, -1.0], N[Not[LessEqual[N, 1.0]], $MachinePrecision]], N[ArcTan[1.0 / N[(N * N), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0 / 1.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq -1 \lor \neg \left(N \leq 1\right):\\
\;\;\;\;\tan^{-1}_* \frac{1}{N \cdot N}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{1}\\
\end{array}
\end{array}
if N < -1 or 1 < N Initial program 49.9%
diff-atan52.7%
associate--l+52.7%
+-commutative52.7%
*-commutative52.7%
fma-def52.7%
Applied egg-rr52.7%
+-commutative52.7%
associate-+l-98.4%
+-inverses98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in N around inf 95.0%
unpow295.0%
Simplified95.0%
if -1 < N < 1Initial program 100.0%
diff-atan99.9%
associate--l+100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
+-commutative100.0%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in N around 0 95.4%
Final simplification95.2%
(FPCore (N) :precision binary64 (if (or (<= N -0.62) (not (<= N 1.65))) (atan2 1.0 (* N N)) (atan2 1.0 (+ 1.0 N))))
double code(double N) {
double tmp;
if ((N <= -0.62) || !(N <= 1.65)) {
tmp = atan2(1.0, (N * N));
} else {
tmp = atan2(1.0, (1.0 + N));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-0.62d0)) .or. (.not. (n <= 1.65d0))) then
tmp = atan2(1.0d0, (n * n))
else
tmp = atan2(1.0d0, (1.0d0 + n))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((N <= -0.62) || !(N <= 1.65)) {
tmp = Math.atan2(1.0, (N * N));
} else {
tmp = Math.atan2(1.0, (1.0 + N));
}
return tmp;
}
def code(N): tmp = 0 if (N <= -0.62) or not (N <= 1.65): tmp = math.atan2(1.0, (N * N)) else: tmp = math.atan2(1.0, (1.0 + N)) return tmp
function code(N) tmp = 0.0 if ((N <= -0.62) || !(N <= 1.65)) tmp = atan(1.0, Float64(N * N)); else tmp = atan(1.0, Float64(1.0 + N)); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((N <= -0.62) || ~((N <= 1.65))) tmp = atan2(1.0, (N * N)); else tmp = atan2(1.0, (1.0 + N)); end tmp_2 = tmp; end
code[N_] := If[Or[LessEqual[N, -0.62], N[Not[LessEqual[N, 1.65]], $MachinePrecision]], N[ArcTan[1.0 / N[(N * N), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0 / N[(1.0 + N), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq -0.62 \lor \neg \left(N \leq 1.65\right):\\
\;\;\;\;\tan^{-1}_* \frac{1}{N \cdot N}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{1 + N}\\
\end{array}
\end{array}
if N < -0.619999999999999996 or 1.6499999999999999 < N Initial program 49.9%
diff-atan52.7%
associate--l+52.7%
+-commutative52.7%
*-commutative52.7%
fma-def52.7%
Applied egg-rr52.7%
+-commutative52.7%
associate-+l-98.4%
+-inverses98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in N around inf 95.0%
unpow295.0%
Simplified95.0%
if -0.619999999999999996 < N < 1.6499999999999999Initial program 100.0%
diff-atan99.9%
associate--l+100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
+-commutative100.0%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in N around 0 97.0%
Final simplification95.9%
(FPCore (N) :precision binary64 (atan2 1.0 (+ N (+ 1.0 (* N N)))))
double code(double N) {
return atan2(1.0, (N + (1.0 + (N * N))));
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan2(1.0d0, (n + (1.0d0 + (n * n))))
end function
public static double code(double N) {
return Math.atan2(1.0, (N + (1.0 + (N * N))));
}
def code(N): return math.atan2(1.0, (N + (1.0 + (N * N))))
function code(N) return atan(1.0, Float64(N + Float64(1.0 + Float64(N * N)))) end
function tmp = code(N) tmp = atan2(1.0, (N + (1.0 + (N * N)))); end
code[N_] := N[ArcTan[1.0 / N[(N + N[(1.0 + N[(N * N), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{N + \left(1 + N \cdot N\right)}
\end{array}
Initial program 74.1%
diff-atan75.6%
associate--l+75.6%
+-commutative75.6%
*-commutative75.6%
fma-def75.6%
Applied egg-rr75.6%
+-commutative75.6%
associate-+l-99.1%
+-inverses99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in N around 0 99.1%
+-commutative99.1%
flip-+64.4%
div-inv64.4%
fma-def64.4%
metadata-eval64.4%
pow-prod-up64.4%
metadata-eval64.4%
unpow264.4%
Applied egg-rr64.4%
fma-udef64.4%
+-commutative64.4%
associate-*r/64.4%
*-rgt-identity64.4%
Simplified64.4%
metadata-eval64.4%
metadata-eval64.4%
pow-prod-up64.4%
pow-prod-down64.4%
pow264.4%
flip-+99.1%
+-commutative99.1%
Applied egg-rr99.1%
Final simplification99.1%
(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 74.1%
diff-atan75.6%
associate--l+75.6%
+-commutative75.6%
*-commutative75.6%
fma-def75.6%
Applied egg-rr75.6%
+-commutative75.6%
associate-+l-99.1%
+-inverses99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in N around 0 48.6%
Final simplification48.6%
(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 2023278
(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)))