
(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 7 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 (+ 1.0 (fma N N N))))
double code(double N) {
return atan2(1.0, (1.0 + fma(N, N, N)));
}
function code(N) return atan(1.0, Float64(1.0 + fma(N, N, N))) end
code[N_] := N[ArcTan[1.0 / N[(1.0 + N[(N * N + N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{1 + \mathsf{fma}\left(N, N, N\right)}
\end{array}
Initial program 71.2%
diff-atan72.9%
+-commutative72.9%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
distribute-lft1-in99.7%
+-commutative99.7%
pow299.7%
Applied egg-rr99.7%
+-commutative99.7%
unpow299.7%
fma-def99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (N) :precision binary64 (let* ((t_0 (- (atan (+ 1.0 N)) (atan N)))) (if (<= t_0 1e-8) (atan2 1.0 (* N (+ 1.0 N))) t_0)))
double code(double N) {
double t_0 = atan((1.0 + N)) - atan(N);
double tmp;
if (t_0 <= 1e-8) {
tmp = atan2(1.0, (N * (1.0 + N)));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = atan((1.0d0 + n)) - atan(n)
if (t_0 <= 1d-8) then
tmp = atan2(1.0d0, (n * (1.0d0 + n)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double N) {
double t_0 = Math.atan((1.0 + N)) - Math.atan(N);
double tmp;
if (t_0 <= 1e-8) {
tmp = Math.atan2(1.0, (N * (1.0 + N)));
} else {
tmp = t_0;
}
return tmp;
}
def code(N): t_0 = math.atan((1.0 + N)) - math.atan(N) tmp = 0 if t_0 <= 1e-8: tmp = math.atan2(1.0, (N * (1.0 + N))) else: tmp = t_0 return tmp
function code(N) t_0 = Float64(atan(Float64(1.0 + N)) - atan(N)) tmp = 0.0 if (t_0 <= 1e-8) tmp = atan(1.0, Float64(N * Float64(1.0 + N))); else tmp = t_0; end return tmp end
function tmp_2 = code(N) t_0 = atan((1.0 + N)) - atan(N); tmp = 0.0; if (t_0 <= 1e-8) tmp = atan2(1.0, (N * (1.0 + N))); else tmp = t_0; end tmp_2 = tmp; end
code[N_] := Block[{t$95$0 = N[(N[ArcTan[N[(1.0 + N), $MachinePrecision]], $MachinePrecision] - N[ArcTan[N], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-8], N[ArcTan[1.0 / N[(N * N[(1.0 + N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(1 + N\right) - \tan^{-1} N\\
\mathbf{if}\;t_0 \leq 10^{-8}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{N \cdot \left(1 + N\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (atan.f64 (+.f64 N 1)) (atan.f64 N)) < 1e-8Initial program 48.9%
diff-atan51.9%
+-commutative51.9%
associate--l+99.4%
+-inverses99.4%
metadata-eval99.4%
distribute-lft1-in99.4%
+-commutative99.4%
pow299.4%
Applied egg-rr99.4%
associate-+r+99.4%
Simplified99.4%
Taylor expanded in N around inf 98.9%
unpow298.9%
distribute-rgt1-in98.9%
+-commutative98.9%
Applied egg-rr98.9%
if 1e-8 < (-.f64 (atan.f64 (+.f64 N 1)) (atan.f64 N)) Initial program 99.8%
Final simplification99.3%
(FPCore (N) :precision binary64 (let* ((t_0 (- (atan (+ 1.0 N)) (atan N)))) (if (<= t_0 1e-8) (atan2 1.0 (+ N (pow N 2.0))) t_0)))
double code(double N) {
double t_0 = atan((1.0 + N)) - atan(N);
double tmp;
if (t_0 <= 1e-8) {
tmp = atan2(1.0, (N + pow(N, 2.0)));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = atan((1.0d0 + n)) - atan(n)
if (t_0 <= 1d-8) then
tmp = atan2(1.0d0, (n + (n ** 2.0d0)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double N) {
double t_0 = Math.atan((1.0 + N)) - Math.atan(N);
double tmp;
if (t_0 <= 1e-8) {
tmp = Math.atan2(1.0, (N + Math.pow(N, 2.0)));
} else {
tmp = t_0;
}
return tmp;
}
def code(N): t_0 = math.atan((1.0 + N)) - math.atan(N) tmp = 0 if t_0 <= 1e-8: tmp = math.atan2(1.0, (N + math.pow(N, 2.0))) else: tmp = t_0 return tmp
function code(N) t_0 = Float64(atan(Float64(1.0 + N)) - atan(N)) tmp = 0.0 if (t_0 <= 1e-8) tmp = atan(1.0, Float64(N + (N ^ 2.0))); else tmp = t_0; end return tmp end
function tmp_2 = code(N) t_0 = atan((1.0 + N)) - atan(N); tmp = 0.0; if (t_0 <= 1e-8) tmp = atan2(1.0, (N + (N ^ 2.0))); else tmp = t_0; end tmp_2 = tmp; end
code[N_] := Block[{t$95$0 = N[(N[ArcTan[N[(1.0 + N), $MachinePrecision]], $MachinePrecision] - N[ArcTan[N], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-8], N[ArcTan[1.0 / N[(N + N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(1 + N\right) - \tan^{-1} N\\
\mathbf{if}\;t_0 \leq 10^{-8}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{N + {N}^{2}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (atan.f64 (+.f64 N 1)) (atan.f64 N)) < 1e-8Initial program 48.9%
diff-atan51.9%
+-commutative51.9%
associate--l+99.4%
+-inverses99.4%
metadata-eval99.4%
distribute-lft1-in99.4%
+-commutative99.4%
pow299.4%
Applied egg-rr99.4%
associate-+r+99.4%
Simplified99.4%
Taylor expanded in N around inf 98.9%
if 1e-8 < (-.f64 (atan.f64 (+.f64 N 1)) (atan.f64 N)) Initial program 99.8%
Final simplification99.3%
(FPCore (N) :precision binary64 (if (or (<= N -0.56) (not (<= N 1.05))) (atan2 1.0 (* N (+ 1.0 N))) (atan2 1.0 (* (/ 1.0 (- 1.0 (* N (+ N -1.0)))) (+ 1.0 (* N (+ N 2.0)))))))
double code(double N) {
double tmp;
if ((N <= -0.56) || !(N <= 1.05)) {
tmp = atan2(1.0, (N * (1.0 + N)));
} else {
tmp = atan2(1.0, ((1.0 / (1.0 - (N * (N + -1.0)))) * (1.0 + (N * (N + 2.0)))));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-0.56d0)) .or. (.not. (n <= 1.05d0))) then
tmp = atan2(1.0d0, (n * (1.0d0 + n)))
else
tmp = atan2(1.0d0, ((1.0d0 / (1.0d0 - (n * (n + (-1.0d0))))) * (1.0d0 + (n * (n + 2.0d0)))))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((N <= -0.56) || !(N <= 1.05)) {
tmp = Math.atan2(1.0, (N * (1.0 + N)));
} else {
tmp = Math.atan2(1.0, ((1.0 / (1.0 - (N * (N + -1.0)))) * (1.0 + (N * (N + 2.0)))));
}
return tmp;
}
def code(N): tmp = 0 if (N <= -0.56) or not (N <= 1.05): tmp = math.atan2(1.0, (N * (1.0 + N))) else: tmp = math.atan2(1.0, ((1.0 / (1.0 - (N * (N + -1.0)))) * (1.0 + (N * (N + 2.0))))) return tmp
function code(N) tmp = 0.0 if ((N <= -0.56) || !(N <= 1.05)) tmp = atan(1.0, Float64(N * Float64(1.0 + N))); else tmp = atan(1.0, Float64(Float64(1.0 / Float64(1.0 - Float64(N * Float64(N + -1.0)))) * Float64(1.0 + Float64(N * Float64(N + 2.0))))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((N <= -0.56) || ~((N <= 1.05))) tmp = atan2(1.0, (N * (1.0 + N))); else tmp = atan2(1.0, ((1.0 / (1.0 - (N * (N + -1.0)))) * (1.0 + (N * (N + 2.0))))); end tmp_2 = tmp; end
code[N_] := If[Or[LessEqual[N, -0.56], N[Not[LessEqual[N, 1.05]], $MachinePrecision]], N[ArcTan[1.0 / N[(N * N[(1.0 + N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0 / N[(N[(1.0 / N[(1.0 - N[(N * N[(N + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N * N[(N + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq -0.56 \lor \neg \left(N \leq 1.05\right):\\
\;\;\;\;\tan^{-1}_* \frac{1}{N \cdot \left(1 + N\right)}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{\frac{1}{1 - N \cdot \left(N + -1\right)} \cdot \left(1 + N \cdot \left(N + 2\right)\right)}\\
\end{array}
\end{array}
if N < -0.56000000000000005 or 1.05000000000000004 < N Initial program 49.2%
diff-atan52.2%
+-commutative52.2%
associate--l+99.4%
+-inverses99.4%
metadata-eval99.4%
distribute-lft1-in99.4%
+-commutative99.4%
pow299.4%
Applied egg-rr99.4%
associate-+r+99.4%
Simplified99.4%
Taylor expanded in N around inf 98.5%
unpow298.5%
distribute-rgt1-in98.5%
+-commutative98.5%
Applied egg-rr98.5%
if -0.56000000000000005 < N < 1.05000000000000004Initial program 100.0%
diff-atan100.0%
+-commutative100.0%
associate--l+100.0%
+-inverses100.0%
metadata-eval100.0%
distribute-lft1-in100.0%
+-commutative100.0%
pow2100.0%
Applied egg-rr100.0%
associate-+r+100.0%
Simplified100.0%
flip-+100.0%
div-inv99.9%
*-commutative99.9%
+-commutative99.9%
associate--l+99.9%
metadata-eval99.9%
unpow299.9%
+-commutative99.9%
metadata-eval99.9%
unpow299.9%
associate--r-99.9%
unpow299.9%
*-un-lft-identity99.9%
distribute-rgt-out--99.9%
pow299.9%
pow-sqr99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in N around 0 100.0%
unpow2100.0%
distribute-rgt-out100.0%
Simplified100.0%
Final simplification99.1%
(FPCore (N) :precision binary64 (if (or (<= N -1.0) (not (<= N 1.0))) (atan2 1.0 (* N (+ 1.0 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 * (1.0 + 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 * (1.0d0 + 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 * (1.0 + 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 * (1.0 + 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(1.0 + 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 * (1.0 + 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[(1.0 + 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 \cdot \left(1 + N\right)}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{1 + N}\\
\end{array}
\end{array}
if N < -1 or 1 < N Initial program 49.2%
diff-atan52.2%
+-commutative52.2%
associate--l+99.4%
+-inverses99.4%
metadata-eval99.4%
distribute-lft1-in99.4%
+-commutative99.4%
pow299.4%
Applied egg-rr99.4%
associate-+r+99.4%
Simplified99.4%
Taylor expanded in N around inf 98.5%
unpow298.5%
distribute-rgt1-in98.5%
+-commutative98.5%
Applied egg-rr98.5%
if -1 < N < 1Initial program 100.0%
diff-atan100.0%
+-commutative100.0%
associate--l+100.0%
+-inverses100.0%
metadata-eval100.0%
distribute-lft1-in100.0%
+-commutative100.0%
pow2100.0%
Applied egg-rr100.0%
associate-+r+100.0%
Simplified100.0%
Taylor expanded in N around 0 99.2%
Final simplification98.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 71.2%
diff-atan72.9%
+-commutative72.9%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
distribute-lft1-in99.7%
+-commutative99.7%
pow299.7%
Applied egg-rr99.7%
associate-+r+99.7%
Simplified99.7%
Taylor expanded in N around 0 46.2%
Final simplification46.2%
(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 71.2%
diff-atan72.9%
+-commutative72.9%
associate--l+99.7%
+-inverses99.7%
metadata-eval99.7%
distribute-lft1-in99.7%
+-commutative99.7%
pow299.7%
Applied egg-rr99.7%
associate-+r+99.7%
Simplified99.7%
Taylor expanded in N around 0 44.8%
Final simplification44.8%
(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 2023336
(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)))