2atan (example 3.5)

Percentage Accurate: 8.6% → 99.6%
Time: 5.7s
Alternatives: 6
Speedup: 1.9×

Specification

?
\[N > 1 \land N < 10^{+100}\]
\[\begin{array}{l} \\ \tan^{-1} \left(N + 1\right) - \tan^{-1} N \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 8.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \tan^{-1} \left(N + 1\right) - \tan^{-1} N \end{array} \]
(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}

Alternative 1: 99.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{1}{{\left({\left(\mathsf{fma}\left(N - -1, N, 1\right)\right)}^{-1}\right)}^{-1}} \end{array} \]
(FPCore (N)
 :precision binary64
 (atan2 1.0 (pow (pow (fma (- N -1.0) N 1.0) -1.0) -1.0)))
double code(double N) {
	return atan2(1.0, pow(pow(fma((N - -1.0), N, 1.0), -1.0), -1.0));
}
function code(N)
	return atan(1.0, ((fma(Float64(N - -1.0), N, 1.0) ^ -1.0) ^ -1.0))
end
code[N_] := N[ArcTan[1.0 / N[Power[N[Power[N[(N[(N - -1.0), $MachinePrecision] * N + 1.0), $MachinePrecision], -1.0], $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan^{-1}_* \frac{1}{{\left({\left(\mathsf{fma}\left(N - -1, N, 1\right)\right)}^{-1}\right)}^{-1}}
\end{array}
Derivation
  1. Initial program 9.4%

    \[\tan^{-1} \left(N + 1\right) - \tan^{-1} N \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right) - \tan^{-1} N} \]
    2. lift-atan.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right)} - \tan^{-1} N \]
    3. lift-atan.f64N/A

      \[\leadsto \tan^{-1} \left(N + 1\right) - \color{blue}{\tan^{-1} N} \]
    4. diff-atanN/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(N + 1\right) - N}{1 + \left(N + 1\right) \cdot N}} \]
    5. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(N + 1\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    6. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(1 + N\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    7. associate--l+N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1 + \left(N - N\right)}}{1 + \left(N + 1\right) \cdot N} \]
    8. +-inversesN/A

      \[\leadsto \tan^{-1}_* \frac{1 + \color{blue}{0}}{1 + \left(N + 1\right) \cdot N} \]
    9. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1}}{1 + \left(N + 1\right) \cdot N} \]
    10. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N + 1}} \]
    11. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    12. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right)} + 1} \]
    13. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N + \left(N + 1\right)}} \]
    14. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(1 + N\right)}} \]
    15. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1 \cdot 1} + N\right)} \]
    16. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + \color{blue}{N \cdot 1}\right)} \]
    17. lower-atan2.f64N/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + N \cdot 1\right)}} \]
    18. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1} + N \cdot 1\right)} \]
    19. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 + \color{blue}{N}\right)} \]
    20. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(N + 1\right)}} \]
    21. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right) + 1}} \]
    22. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N} + 1} \]
    23. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    24. lower-fma.f6499.7

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N + 1, N, 1\right)}} \]
  4. Applied rewrites99.7%

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)}} \]
  5. Step-by-step derivation
    1. lift-fma.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(1 + N\right) \cdot N + 1}} \]
    2. flip-+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\frac{\left(\left(1 + N\right) \cdot N\right) \cdot \left(\left(1 + N\right) \cdot N\right) - 1 \cdot 1}{\left(1 + N\right) \cdot N - 1}}} \]
    3. clear-numN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\frac{1}{\frac{\left(1 + N\right) \cdot N - 1}{\left(\left(1 + N\right) \cdot N\right) \cdot \left(\left(1 + N\right) \cdot N\right) - 1 \cdot 1}}}} \]
    4. lower-/.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\frac{1}{\frac{\left(1 + N\right) \cdot N - 1}{\left(\left(1 + N\right) \cdot N\right) \cdot \left(\left(1 + N\right) \cdot N\right) - 1 \cdot 1}}}} \]
    5. clear-numN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\color{blue}{\frac{1}{\frac{\left(\left(1 + N\right) \cdot N\right) \cdot \left(\left(1 + N\right) \cdot N\right) - 1 \cdot 1}{\left(1 + N\right) \cdot N - 1}}}}} \]
    6. flip-+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\frac{1}{\color{blue}{\left(1 + N\right) \cdot N + 1}}}} \]
    7. lift-fma.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\frac{1}{\color{blue}{\mathsf{fma}\left(1 + N, N, 1\right)}}}} \]
    8. inv-powN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\color{blue}{{\left(\mathsf{fma}\left(1 + N, N, 1\right)\right)}^{-1}}}} \]
    9. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{{\left(\mathsf{fma}\left(1 + N, N, 1\right)\right)}^{\color{blue}{\left(\mathsf{neg}\left(1\right)\right)}}}} \]
    10. lower-pow.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\color{blue}{{\left(\mathsf{fma}\left(1 + N, N, 1\right)\right)}^{\left(\mathsf{neg}\left(1\right)\right)}}}} \]
    11. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{{\left(\mathsf{fma}\left(\color{blue}{1 + N}, N, 1\right)\right)}^{\left(\mathsf{neg}\left(1\right)\right)}}} \]
    12. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{{\left(\mathsf{fma}\left(\color{blue}{N + 1}, N, 1\right)\right)}^{\left(\mathsf{neg}\left(1\right)\right)}}} \]
    13. lower-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{{\left(\mathsf{fma}\left(\color{blue}{N + 1}, N, 1\right)\right)}^{\left(\mathsf{neg}\left(1\right)\right)}}} \]
    14. metadata-eval99.7

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{{\left(\mathsf{fma}\left(N + 1, N, 1\right)\right)}^{\color{blue}{-1}}}} \]
  6. Applied rewrites99.7%

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\frac{1}{{\left(\mathsf{fma}\left(N + 1, N, 1\right)\right)}^{-1}}}} \]
  7. Step-by-step derivation
    1. lift-pow.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\color{blue}{{\left(\mathsf{fma}\left(N + 1, N, 1\right)\right)}^{-1}}}} \]
    2. unpow-1N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\color{blue}{\frac{1}{\mathsf{fma}\left(N + 1, N, 1\right)}}}} \]
    3. lower-/.f6499.7

      \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\color{blue}{\frac{1}{\mathsf{fma}\left(N + 1, N, 1\right)}}}} \]
  8. Applied rewrites99.7%

    \[\leadsto \tan^{-1}_* \frac{1}{\frac{1}{\color{blue}{\frac{1}{\mathsf{fma}\left(N + 1, N, 1\right)}}}} \]
  9. Final simplification99.7%

    \[\leadsto \tan^{-1}_* \frac{1}{{\left({\left(\mathsf{fma}\left(N - -1, N, 1\right)\right)}^{-1}\right)}^{-1}} \]
  10. Add Preprocessing

Alternative 2: 99.6% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)} \end{array} \]
(FPCore (N) :precision binary64 (atan2 1.0 (fma (+ 1.0 N) N 1.0)))
double code(double N) {
	return atan2(1.0, fma((1.0 + N), N, 1.0));
}
function code(N)
	return atan(1.0, fma(Float64(1.0 + N), N, 1.0))
end
code[N_] := N[ArcTan[1.0 / N[(N[(1.0 + N), $MachinePrecision] * N + 1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)}
\end{array}
Derivation
  1. Initial program 9.4%

    \[\tan^{-1} \left(N + 1\right) - \tan^{-1} N \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right) - \tan^{-1} N} \]
    2. lift-atan.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right)} - \tan^{-1} N \]
    3. lift-atan.f64N/A

      \[\leadsto \tan^{-1} \left(N + 1\right) - \color{blue}{\tan^{-1} N} \]
    4. diff-atanN/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(N + 1\right) - N}{1 + \left(N + 1\right) \cdot N}} \]
    5. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(N + 1\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    6. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(1 + N\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    7. associate--l+N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1 + \left(N - N\right)}}{1 + \left(N + 1\right) \cdot N} \]
    8. +-inversesN/A

      \[\leadsto \tan^{-1}_* \frac{1 + \color{blue}{0}}{1 + \left(N + 1\right) \cdot N} \]
    9. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1}}{1 + \left(N + 1\right) \cdot N} \]
    10. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N + 1}} \]
    11. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    12. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right)} + 1} \]
    13. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N + \left(N + 1\right)}} \]
    14. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(1 + N\right)}} \]
    15. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1 \cdot 1} + N\right)} \]
    16. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + \color{blue}{N \cdot 1}\right)} \]
    17. lower-atan2.f64N/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + N \cdot 1\right)}} \]
    18. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1} + N \cdot 1\right)} \]
    19. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 + \color{blue}{N}\right)} \]
    20. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(N + 1\right)}} \]
    21. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right) + 1}} \]
    22. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N} + 1} \]
    23. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    24. lower-fma.f6499.7

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N + 1, N, 1\right)}} \]
  4. Applied rewrites99.7%

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)}} \]
  5. Add Preprocessing

Alternative 3: 96.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N, N\right)} \end{array} \]
(FPCore (N) :precision binary64 (atan2 1.0 (fma N N N)))
double code(double N) {
	return atan2(1.0, fma(N, N, N));
}
function code(N)
	return atan(1.0, fma(N, N, N))
end
code[N_] := N[ArcTan[1.0 / N[(N * N + N), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N, N\right)}
\end{array}
Derivation
  1. Initial program 9.4%

    \[\tan^{-1} \left(N + 1\right) - \tan^{-1} N \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right) - \tan^{-1} N} \]
    2. lift-atan.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right)} - \tan^{-1} N \]
    3. lift-atan.f64N/A

      \[\leadsto \tan^{-1} \left(N + 1\right) - \color{blue}{\tan^{-1} N} \]
    4. diff-atanN/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(N + 1\right) - N}{1 + \left(N + 1\right) \cdot N}} \]
    5. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(N + 1\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    6. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(1 + N\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    7. associate--l+N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1 + \left(N - N\right)}}{1 + \left(N + 1\right) \cdot N} \]
    8. +-inversesN/A

      \[\leadsto \tan^{-1}_* \frac{1 + \color{blue}{0}}{1 + \left(N + 1\right) \cdot N} \]
    9. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1}}{1 + \left(N + 1\right) \cdot N} \]
    10. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N + 1}} \]
    11. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    12. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right)} + 1} \]
    13. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N + \left(N + 1\right)}} \]
    14. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(1 + N\right)}} \]
    15. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1 \cdot 1} + N\right)} \]
    16. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + \color{blue}{N \cdot 1}\right)} \]
    17. lower-atan2.f64N/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + N \cdot 1\right)}} \]
    18. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1} + N \cdot 1\right)} \]
    19. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 + \color{blue}{N}\right)} \]
    20. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(N + 1\right)}} \]
    21. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right) + 1}} \]
    22. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N} + 1} \]
    23. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    24. lower-fma.f6499.7

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N + 1, N, 1\right)}} \]
  4. Applied rewrites99.7%

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)}} \]
  5. Taylor expanded in N around inf

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{{N}^{2} \cdot \left(1 + \frac{1}{N}\right)}} \]
  6. Step-by-step derivation
    1. distribute-lft-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{{N}^{2} \cdot 1 + {N}^{2} \cdot \frac{1}{N}}} \]
    2. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{{N}^{2}} + {N}^{2} \cdot \frac{1}{N}} \]
    3. unpow2N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N} + {N}^{2} \cdot \frac{1}{N}} \]
    4. unpow2N/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(N \cdot N\right)} \cdot \frac{1}{N}} \]
    5. associate-*l*N/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{N \cdot \left(N \cdot \frac{1}{N}\right)}} \]
    6. rgt-mult-inverseN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + N \cdot \color{blue}{1}} \]
    7. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{N}} \]
    8. lower-fma.f6495.8

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N, N, N\right)}} \]
  7. Applied rewrites95.8%

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N, N, N\right)}} \]
  8. Add Preprocessing

Alternative 4: 93.3% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{1}{N \cdot N} \end{array} \]
(FPCore (N) :precision binary64 (atan2 1.0 (* N N)))
double code(double N) {
	return atan2(1.0, (N * N));
}
real(8) function code(n)
    real(8), intent (in) :: n
    code = atan2(1.0d0, (n * n))
end function
public static double code(double N) {
	return Math.atan2(1.0, (N * N));
}
def code(N):
	return math.atan2(1.0, (N * N))
function code(N)
	return atan(1.0, Float64(N * N))
end
function tmp = code(N)
	tmp = atan2(1.0, (N * N));
end
code[N_] := N[ArcTan[1.0 / N[(N * N), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\tan^{-1}_* \frac{1}{N \cdot N}
\end{array}
Derivation
  1. Initial program 9.4%

    \[\tan^{-1} \left(N + 1\right) - \tan^{-1} N \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right) - \tan^{-1} N} \]
    2. lift-atan.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right)} - \tan^{-1} N \]
    3. lift-atan.f64N/A

      \[\leadsto \tan^{-1} \left(N + 1\right) - \color{blue}{\tan^{-1} N} \]
    4. diff-atanN/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(N + 1\right) - N}{1 + \left(N + 1\right) \cdot N}} \]
    5. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(N + 1\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    6. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(1 + N\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    7. associate--l+N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1 + \left(N - N\right)}}{1 + \left(N + 1\right) \cdot N} \]
    8. +-inversesN/A

      \[\leadsto \tan^{-1}_* \frac{1 + \color{blue}{0}}{1 + \left(N + 1\right) \cdot N} \]
    9. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1}}{1 + \left(N + 1\right) \cdot N} \]
    10. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N + 1}} \]
    11. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    12. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right)} + 1} \]
    13. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N + \left(N + 1\right)}} \]
    14. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(1 + N\right)}} \]
    15. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1 \cdot 1} + N\right)} \]
    16. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + \color{blue}{N \cdot 1}\right)} \]
    17. lower-atan2.f64N/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + N \cdot 1\right)}} \]
    18. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1} + N \cdot 1\right)} \]
    19. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 + \color{blue}{N}\right)} \]
    20. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(N + 1\right)}} \]
    21. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right) + 1}} \]
    22. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N} + 1} \]
    23. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    24. lower-fma.f6499.7

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N + 1, N, 1\right)}} \]
  4. Applied rewrites99.7%

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)}} \]
  5. Taylor expanded in N around inf

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{{N}^{2}}} \]
  6. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N}} \]
    2. lower-*.f6493.2

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N}} \]
  7. Applied rewrites93.2%

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N}} \]
  8. Add Preprocessing

Alternative 5: 7.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{1}{N - -1} \end{array} \]
(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}
Derivation
  1. Initial program 9.4%

    \[\tan^{-1} \left(N + 1\right) - \tan^{-1} N \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right) - \tan^{-1} N} \]
    2. lift-atan.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right)} - \tan^{-1} N \]
    3. lift-atan.f64N/A

      \[\leadsto \tan^{-1} \left(N + 1\right) - \color{blue}{\tan^{-1} N} \]
    4. diff-atanN/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(N + 1\right) - N}{1 + \left(N + 1\right) \cdot N}} \]
    5. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(N + 1\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    6. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(1 + N\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    7. associate--l+N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1 + \left(N - N\right)}}{1 + \left(N + 1\right) \cdot N} \]
    8. +-inversesN/A

      \[\leadsto \tan^{-1}_* \frac{1 + \color{blue}{0}}{1 + \left(N + 1\right) \cdot N} \]
    9. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1}}{1 + \left(N + 1\right) \cdot N} \]
    10. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N + 1}} \]
    11. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    12. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right)} + 1} \]
    13. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N + \left(N + 1\right)}} \]
    14. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(1 + N\right)}} \]
    15. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1 \cdot 1} + N\right)} \]
    16. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + \color{blue}{N \cdot 1}\right)} \]
    17. lower-atan2.f64N/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + N \cdot 1\right)}} \]
    18. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1} + N \cdot 1\right)} \]
    19. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 + \color{blue}{N}\right)} \]
    20. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(N + 1\right)}} \]
    21. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right) + 1}} \]
    22. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N} + 1} \]
    23. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    24. lower-fma.f6499.7

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N + 1, N, 1\right)}} \]
  4. Applied rewrites99.7%

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)}} \]
  5. Taylor expanded in N around 0

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{1 + N}} \]
  6. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N + 1}} \]
    2. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)}} \]
    3. sub-negN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N - -1}} \]
    4. lower--.f647.9

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N - -1}} \]
  7. Applied rewrites7.9%

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N - -1}} \]
  8. Add Preprocessing

Alternative 6: 6.3% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \tan^{-1}_* \frac{1}{1} \end{array} \]
(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}
Derivation
  1. Initial program 9.4%

    \[\tan^{-1} \left(N + 1\right) - \tan^{-1} N \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right) - \tan^{-1} N} \]
    2. lift-atan.f64N/A

      \[\leadsto \color{blue}{\tan^{-1} \left(N + 1\right)} - \tan^{-1} N \]
    3. lift-atan.f64N/A

      \[\leadsto \tan^{-1} \left(N + 1\right) - \color{blue}{\tan^{-1} N} \]
    4. diff-atanN/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(N + 1\right) - N}{1 + \left(N + 1\right) \cdot N}} \]
    5. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(N + 1\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    6. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{\left(1 + N\right)} - N}{1 + \left(N + 1\right) \cdot N} \]
    7. associate--l+N/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1 + \left(N - N\right)}}{1 + \left(N + 1\right) \cdot N} \]
    8. +-inversesN/A

      \[\leadsto \tan^{-1}_* \frac{1 + \color{blue}{0}}{1 + \left(N + 1\right) \cdot N} \]
    9. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{\color{blue}{1}}{1 + \left(N + 1\right) \cdot N} \]
    10. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N + 1}} \]
    11. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    12. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right)} + 1} \]
    13. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{N \cdot N + \left(N + 1\right)}} \]
    14. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(1 + N\right)}} \]
    15. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1 \cdot 1} + N\right)} \]
    16. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + \color{blue}{N \cdot 1}\right)} \]
    17. lower-atan2.f64N/A

      \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{N \cdot N + \left(1 \cdot 1 + N \cdot 1\right)}} \]
    18. metadata-evalN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(\color{blue}{1} + N \cdot 1\right)} \]
    19. *-rgt-identityN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \left(1 + \color{blue}{N}\right)} \]
    20. +-commutativeN/A

      \[\leadsto \tan^{-1}_* \frac{1}{N \cdot N + \color{blue}{\left(N + 1\right)}} \]
    21. associate-+r+N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N \cdot N + N\right) + 1}} \]
    22. distribute-lft1-inN/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right) \cdot N} + 1} \]
    23. lift-+.f64N/A

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\left(N + 1\right)} \cdot N + 1} \]
    24. lower-fma.f6499.7

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N + 1, N, 1\right)}} \]
  4. Applied rewrites99.7%

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{1}{\mathsf{fma}\left(1 + N, N, 1\right)}} \]
  5. Taylor expanded in N around 0

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{1}} \]
  6. Step-by-step derivation
    1. Applied rewrites6.3%

      \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{1}} \]
    2. Add Preprocessing

    Developer Target 1: 99.6% accurate, 1.9× speedup?

    \[\begin{array}{l} \\ \tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, 1 + N, 1\right)} \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}
    

    Reproduce

    ?
    herbie shell --seed 2024313 
    (FPCore (N)
      :name "2atan (example 3.5)"
      :precision binary64
      :pre (and (> N 1.0) (< N 1e+100))
    
      :alt
      (! :herbie-platform default (atan2 1 (fma N (+ 1 N) 1)))
    
      (- (atan (+ N 1.0)) (atan N)))