
(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 (fma N (+ N 1.0) 1.0)))
double code(double N) {
return atan2(1.0, fma(N, (N + 1.0), 1.0));
}
function code(N) return atan(1.0, fma(N, Float64(N + 1.0), 1.0)) end
code[N_] := N[ArcTan[1.0 / N[(N * N[(N + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N + 1, 1\right)}
\end{array}
Initial program 76.3%
diff-atan78.7%
associate--l+78.7%
+-commutative78.7%
*-commutative78.7%
fma-def78.7%
Applied egg-rr78.7%
+-commutative78.7%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (N) :precision binary64 (let* ((t_0 (- (atan (+ 1.0 N)) (atan N)))) (if (<= t_0 5e-9) (atan2 1.0 (* (- -0.5 N) (- -0.5 N))) t_0)))
double code(double N) {
double t_0 = atan((1.0 + N)) - atan(N);
double tmp;
if (t_0 <= 5e-9) {
tmp = atan2(1.0, ((-0.5 - N) * (-0.5 - 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 <= 5d-9) then
tmp = atan2(1.0d0, (((-0.5d0) - n) * ((-0.5d0) - 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 <= 5e-9) {
tmp = Math.atan2(1.0, ((-0.5 - N) * (-0.5 - 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 <= 5e-9: tmp = math.atan2(1.0, ((-0.5 - N) * (-0.5 - 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 <= 5e-9) tmp = atan(1.0, Float64(Float64(-0.5 - N) * Float64(-0.5 - 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 <= 5e-9) tmp = atan2(1.0, ((-0.5 - N) * (-0.5 - 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, 5e-9], N[ArcTan[1.0 / N[(N[(-0.5 - N), $MachinePrecision] * N[(-0.5 - 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 5 \cdot 10^{-9}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{\left(-0.5 - N\right) \cdot \left(-0.5 - N\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (atan.f64 (+.f64 N 1)) (atan.f64 N)) < 5.0000000000000001e-9Initial program 54.3%
diff-atan59.0%
associate--l+59.0%
+-commutative59.0%
*-commutative59.0%
fma-def59.0%
Applied egg-rr59.0%
+-commutative59.0%
associate-+l-99.8%
+-inverses99.8%
metadata-eval99.8%
+-commutative99.8%
Simplified99.8%
add-sqr-sqrt99.7%
pow299.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in N around -inf 99.3%
sub-neg99.3%
+-commutative99.3%
mul-1-neg99.3%
unsub-neg99.3%
metadata-eval99.3%
Simplified99.3%
unpow299.3%
Applied egg-rr99.3%
if 5.0000000000000001e-9 < (-.f64 (atan.f64 (+.f64 N 1)) (atan.f64 N)) Initial program 100.0%
Final simplification99.6%
(FPCore (N)
:precision binary64
(if (<= N -0.86)
(atan2 1.0 (* (- -0.5 N) (- -0.5 N)))
(if (<= N 0.86)
(atan2 1.0 (+ N 1.0))
(atan2 1.0 (+ (* -0.5 (- -0.5 N)) (* N (- N -0.5)))))))
double code(double N) {
double tmp;
if (N <= -0.86) {
tmp = atan2(1.0, ((-0.5 - N) * (-0.5 - N)));
} else if (N <= 0.86) {
tmp = atan2(1.0, (N + 1.0));
} else {
tmp = atan2(1.0, ((-0.5 * (-0.5 - N)) + (N * (N - -0.5))));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= (-0.86d0)) then
tmp = atan2(1.0d0, (((-0.5d0) - n) * ((-0.5d0) - n)))
else if (n <= 0.86d0) then
tmp = atan2(1.0d0, (n + 1.0d0))
else
tmp = atan2(1.0d0, (((-0.5d0) * ((-0.5d0) - n)) + (n * (n - (-0.5d0)))))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= -0.86) {
tmp = Math.atan2(1.0, ((-0.5 - N) * (-0.5 - N)));
} else if (N <= 0.86) {
tmp = Math.atan2(1.0, (N + 1.0));
} else {
tmp = Math.atan2(1.0, ((-0.5 * (-0.5 - N)) + (N * (N - -0.5))));
}
return tmp;
}
def code(N): tmp = 0 if N <= -0.86: tmp = math.atan2(1.0, ((-0.5 - N) * (-0.5 - N))) elif N <= 0.86: tmp = math.atan2(1.0, (N + 1.0)) else: tmp = math.atan2(1.0, ((-0.5 * (-0.5 - N)) + (N * (N - -0.5)))) return tmp
function code(N) tmp = 0.0 if (N <= -0.86) tmp = atan(1.0, Float64(Float64(-0.5 - N) * Float64(-0.5 - N))); elseif (N <= 0.86) tmp = atan(1.0, Float64(N + 1.0)); else tmp = atan(1.0, Float64(Float64(-0.5 * Float64(-0.5 - N)) + Float64(N * Float64(N - -0.5)))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= -0.86) tmp = atan2(1.0, ((-0.5 - N) * (-0.5 - N))); elseif (N <= 0.86) tmp = atan2(1.0, (N + 1.0)); else tmp = atan2(1.0, ((-0.5 * (-0.5 - N)) + (N * (N - -0.5)))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, -0.86], N[ArcTan[1.0 / N[(N[(-0.5 - N), $MachinePrecision] * N[(-0.5 - N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N, 0.86], N[ArcTan[1.0 / N[(N + 1.0), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0 / N[(N[(-0.5 * N[(-0.5 - N), $MachinePrecision]), $MachinePrecision] + N[(N * N[(N - -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq -0.86:\\
\;\;\;\;\tan^{-1}_* \frac{1}{\left(-0.5 - N\right) \cdot \left(-0.5 - N\right)}\\
\mathbf{elif}\;N \leq 0.86:\\
\;\;\;\;\tan^{-1}_* \frac{1}{N + 1}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{-0.5 \cdot \left(-0.5 - N\right) + N \cdot \left(N - -0.5\right)}\\
\end{array}
\end{array}
if N < -0.859999999999999987Initial program 60.3%
diff-atan63.8%
associate--l+63.8%
+-commutative63.8%
*-commutative63.8%
fma-def63.8%
Applied egg-rr63.8%
+-commutative63.8%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
add-sqr-sqrt99.8%
pow299.8%
+-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in N around -inf 99.8%
sub-neg99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
metadata-eval99.8%
Simplified99.8%
unpow299.8%
Applied egg-rr99.8%
if -0.859999999999999987 < N < 0.859999999999999987Initial program 100.0%
diff-atan100.0%
associate--l+100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
+-commutative100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in N around 0 99.2%
if 0.859999999999999987 < N Initial program 47.6%
diff-atan53.6%
associate--l+53.6%
+-commutative53.6%
*-commutative53.6%
fma-def53.6%
Applied egg-rr53.6%
+-commutative53.6%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
add-sqr-sqrt99.7%
pow299.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in N around -inf 98.7%
sub-neg98.7%
+-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
metadata-eval98.7%
Simplified98.7%
unpow298.7%
sub-neg98.7%
distribute-lft-in98.7%
Applied egg-rr98.7%
Final simplification99.2%
(FPCore (N) :precision binary64 (if (or (<= N -0.86) (not (<= N 0.86))) (atan2 1.0 (* (- -0.5 N) (- -0.5 N))) (atan2 1.0 (+ N 1.0))))
double code(double N) {
double tmp;
if ((N <= -0.86) || !(N <= 0.86)) {
tmp = atan2(1.0, ((-0.5 - N) * (-0.5 - N)));
} else {
tmp = atan2(1.0, (N + 1.0));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-0.86d0)) .or. (.not. (n <= 0.86d0))) then
tmp = atan2(1.0d0, (((-0.5d0) - n) * ((-0.5d0) - n)))
else
tmp = atan2(1.0d0, (n + 1.0d0))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((N <= -0.86) || !(N <= 0.86)) {
tmp = Math.atan2(1.0, ((-0.5 - N) * (-0.5 - N)));
} else {
tmp = Math.atan2(1.0, (N + 1.0));
}
return tmp;
}
def code(N): tmp = 0 if (N <= -0.86) or not (N <= 0.86): tmp = math.atan2(1.0, ((-0.5 - N) * (-0.5 - N))) else: tmp = math.atan2(1.0, (N + 1.0)) return tmp
function code(N) tmp = 0.0 if ((N <= -0.86) || !(N <= 0.86)) tmp = atan(1.0, Float64(Float64(-0.5 - N) * Float64(-0.5 - N))); else tmp = atan(1.0, Float64(N + 1.0)); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((N <= -0.86) || ~((N <= 0.86))) tmp = atan2(1.0, ((-0.5 - N) * (-0.5 - N))); else tmp = atan2(1.0, (N + 1.0)); end tmp_2 = tmp; end
code[N_] := If[Or[LessEqual[N, -0.86], N[Not[LessEqual[N, 0.86]], $MachinePrecision]], N[ArcTan[1.0 / N[(N[(-0.5 - N), $MachinePrecision] * N[(-0.5 - N), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0 / N[(N + 1.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq -0.86 \lor \neg \left(N \leq 0.86\right):\\
\;\;\;\;\tan^{-1}_* \frac{1}{\left(-0.5 - N\right) \cdot \left(-0.5 - N\right)}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{N + 1}\\
\end{array}
\end{array}
if N < -0.859999999999999987 or 0.859999999999999987 < N Initial program 54.3%
diff-atan59.0%
associate--l+59.0%
+-commutative59.0%
*-commutative59.0%
fma-def59.0%
Applied egg-rr59.0%
+-commutative59.0%
associate-+l-99.8%
+-inverses99.8%
metadata-eval99.8%
+-commutative99.8%
Simplified99.8%
add-sqr-sqrt99.7%
pow299.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in N around -inf 99.3%
sub-neg99.3%
+-commutative99.3%
mul-1-neg99.3%
unsub-neg99.3%
metadata-eval99.3%
Simplified99.3%
unpow299.3%
Applied egg-rr99.3%
if -0.859999999999999987 < N < 0.859999999999999987Initial program 100.0%
diff-atan100.0%
associate--l+100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
+-commutative100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in N around 0 99.2%
Final simplification99.2%
(FPCore (N) :precision binary64 (if (or (<= N -1.0) (not (<= N 1.0))) (atan2 1.0 (* N (+ N 1.0))) (atan2 1.0 (+ N 1.0))))
double code(double N) {
double tmp;
if ((N <= -1.0) || !(N <= 1.0)) {
tmp = atan2(1.0, (N * (N + 1.0)));
} else {
tmp = atan2(1.0, (N + 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 + 1.0d0)))
else
tmp = atan2(1.0d0, (n + 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 + 1.0)));
} else {
tmp = Math.atan2(1.0, (N + 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 + 1.0))) else: tmp = math.atan2(1.0, (N + 1.0)) return tmp
function code(N) tmp = 0.0 if ((N <= -1.0) || !(N <= 1.0)) tmp = atan(1.0, Float64(N * Float64(N + 1.0))); else tmp = atan(1.0, Float64(N + 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 + 1.0))); else tmp = atan2(1.0, (N + 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[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[ArcTan[1.0 / N[(N + 1.0), $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(N + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\tan^{-1}_* \frac{1}{N + 1}\\
\end{array}
\end{array}
if N < -1 or 1 < N Initial program 54.3%
diff-atan59.0%
associate--l+59.0%
+-commutative59.0%
*-commutative59.0%
fma-def59.0%
Applied egg-rr59.0%
+-commutative59.0%
associate-+l-99.8%
+-inverses99.8%
metadata-eval99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in N around inf 99.3%
unpow299.3%
distribute-rgt1-in99.3%
Applied egg-rr99.3%
if -1 < N < 1Initial program 100.0%
diff-atan100.0%
associate--l+100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
+-commutative100.0%
associate-+l-100.0%
+-inverses100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in N around 0 99.2%
Final simplification99.2%
(FPCore (N) :precision binary64 (atan2 1.0 (+ N 1.0)))
double code(double N) {
return atan2(1.0, (N + 1.0));
}
real(8) function code(n)
real(8), intent (in) :: n
code = atan2(1.0d0, (n + 1.0d0))
end function
public static double code(double N) {
return Math.atan2(1.0, (N + 1.0));
}
def code(N): return math.atan2(1.0, (N + 1.0))
function code(N) return atan(1.0, Float64(N + 1.0)) end
function tmp = code(N) tmp = atan2(1.0, (N + 1.0)); end
code[N_] := N[ArcTan[1.0 / N[(N + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\tan^{-1}_* \frac{1}{N + 1}
\end{array}
Initial program 76.3%
diff-atan78.7%
associate--l+78.7%
+-commutative78.7%
*-commutative78.7%
fma-def78.7%
Applied egg-rr78.7%
+-commutative78.7%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in N around 0 50.6%
Final simplification50.6%
(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 76.3%
diff-atan78.7%
associate--l+78.7%
+-commutative78.7%
*-commutative78.7%
fma-def78.7%
Applied egg-rr78.7%
+-commutative78.7%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in N around 0 49.4%
Final simplification49.4%
(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 2023311
(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)))