abs(1 / tan(ang / 180 * PI) - 1)

Percentage Accurate: 99.3% → 99.5%
Time: 3.4s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[0 \leq ang \land ang \leq 90\]
\[\begin{array}{l} \\ \left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \end{array} \]
(FPCore (ang)
 :precision binary64
 (fabs (- (/ 1.0 (tan (* (/ ang 180.0) (PI)))) 1.0)))
\begin{array}{l}

\\
\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right|
\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 9 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: 99.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \end{array} \]
(FPCore (ang)
 :precision binary64
 (fabs (- (/ 1.0 (tan (* (/ ang 180.0) (PI)))) 1.0)))
\begin{array}{l}

\\
\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right|
\end{array}

Alternative 1: 99.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\\ \left|-1 + \frac{\cos t\_0}{\sin t\_0}\right| \end{array} \end{array} \]
(FPCore (ang)
 :precision binary64
 (let* ((t_0 (* (* (PI) 0.005555555555555556) ang)))
   (fabs (+ -1.0 (/ (cos t_0) (sin t_0))))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\\
\left|-1 + \frac{\cos t\_0}{\sin t\_0}\right|
\end{array}
\end{array}
Derivation
  1. Initial program 99.3%

    \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
  2. Add Preprocessing
  3. Taylor expanded in ang around inf

    \[\leadsto \left|\color{blue}{\frac{\cos \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}} - 1\right| \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{\cos \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}} - 1\right| \]
    2. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(\left(ang \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{1}{180}\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    3. associate-*r*N/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(ang \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    4. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(ang \cdot \color{blue}{\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)}\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    5. lower-cos.f64N/A

      \[\leadsto \left|\frac{\color{blue}{\cos \left(ang \cdot \left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    6. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    7. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    8. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    9. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    10. lower-PI.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    11. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(\left(ang \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{1}{180}\right)}} - 1\right| \]
    12. associate-*r*N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(ang \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)\right)}} - 1\right| \]
    13. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(ang \cdot \color{blue}{\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)}\right)} - 1\right| \]
    14. lower-sin.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\color{blue}{\sin \left(ang \cdot \left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}} - 1\right| \]
    15. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}} - 1\right| \]
    16. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}} - 1\right| \]
    17. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)} - 1\right| \]
    18. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)} - 1\right| \]
    19. lower-PI.f6499.5

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}{\sin \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 0.005555555555555556\right) \cdot ang\right)} - 1\right| \]
  5. Applied rewrites99.5%

    \[\leadsto \left|\color{blue}{\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}{\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}} - 1\right| \]
  6. Final simplification99.5%

    \[\leadsto \left|-1 + \frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}{\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}\right| \]
  7. Add Preprocessing

Alternative 2: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left|-1 - \frac{-1}{\tan \left(\left(0.005555555555555556 \cdot ang\right) \cdot \mathsf{PI}\left(\right)\right)}\right| \end{array} \]
(FPCore (ang)
 :precision binary64
 (fabs (- -1.0 (/ -1.0 (tan (* (* 0.005555555555555556 ang) (PI)))))))
\begin{array}{l}

\\
\left|-1 - \frac{-1}{\tan \left(\left(0.005555555555555556 \cdot ang\right) \cdot \mathsf{PI}\left(\right)\right)}\right|
\end{array}
Derivation
  1. Initial program 99.3%

    \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \left|\frac{1}{\tan \left(\color{blue}{\frac{ang}{180}} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
    2. clear-numN/A

      \[\leadsto \left|\frac{1}{\tan \left(\color{blue}{\frac{1}{\frac{180}{ang}}} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
    3. associate-/r/N/A

      \[\leadsto \left|\frac{1}{\tan \left(\color{blue}{\left(\frac{1}{180} \cdot ang\right)} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
    4. lower-*.f64N/A

      \[\leadsto \left|\frac{1}{\tan \left(\color{blue}{\left(\frac{1}{180} \cdot ang\right)} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
    5. metadata-eval99.4

      \[\leadsto \left|\frac{1}{\tan \left(\left(\color{blue}{0.005555555555555556} \cdot ang\right) \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
  4. Applied rewrites99.4%

    \[\leadsto \left|\frac{1}{\tan \color{blue}{\left(\left(0.005555555555555556 \cdot ang\right) \cdot \mathsf{PI}\left(\right)\right)}} - 1\right| \]
  5. Final simplification99.4%

    \[\leadsto \left|-1 - \frac{-1}{\tan \left(\left(0.005555555555555556 \cdot ang\right) \cdot \mathsf{PI}\left(\right)\right)}\right| \]
  6. Add Preprocessing

Alternative 3: 99.2% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \left|\frac{\mathsf{fma}\left(\mathsf{fma}\left(-32400 \cdot ang, \mathsf{PI}\left(\right) \cdot 5.7155921353452215 \cdot 10^{-8}, -1\right), ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{ang}\right| \end{array} \]
(FPCore (ang)
 :precision binary64
 (fabs
  (/
   (fma
    (fma (* -32400.0 ang) (* (PI) 5.7155921353452215e-8) -1.0)
    ang
    (/ 180.0 (PI)))
   ang)))
\begin{array}{l}

\\
\left|\frac{\mathsf{fma}\left(\mathsf{fma}\left(-32400 \cdot ang, \mathsf{PI}\left(\right) \cdot 5.7155921353452215 \cdot 10^{-8}, -1\right), ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{ang}\right|
\end{array}
Derivation
  1. Initial program 99.3%

    \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
  2. Add Preprocessing
  3. Taylor expanded in ang around 0

    \[\leadsto \left|\color{blue}{\frac{ang \cdot \left(-32400 \cdot \frac{ang \cdot \left(\frac{-1}{34992000} \cdot {\mathsf{PI}\left(\right)}^{3} - \frac{-1}{11664000} \cdot {\mathsf{PI}\left(\right)}^{3}\right)}{{\mathsf{PI}\left(\right)}^{2}} - 1\right) + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{ang \cdot \left(-32400 \cdot \frac{ang \cdot \left(\frac{-1}{34992000} \cdot {\mathsf{PI}\left(\right)}^{3} - \frac{-1}{11664000} \cdot {\mathsf{PI}\left(\right)}^{3}\right)}{{\mathsf{PI}\left(\right)}^{2}} - 1\right) + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
  5. Applied rewrites99.2%

    \[\leadsto \left|\color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(-32400 \cdot ang, \left(\mathsf{PI}\left(\right) \cdot 1\right) \cdot 5.7155921353452215 \cdot 10^{-8}, -1\right), ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{ang}}\right| \]
  6. Final simplification99.2%

    \[\leadsto \left|\frac{\mathsf{fma}\left(\mathsf{fma}\left(-32400 \cdot ang, \mathsf{PI}\left(\right) \cdot 5.7155921353452215 \cdot 10^{-8}, -1\right), ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{ang}\right| \]
  7. Add Preprocessing

Alternative 4: 99.2% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \left|-1 + \frac{\mathsf{fma}\left(\left(-0.001851851851851852 \cdot \mathsf{PI}\left(\right)\right) \cdot ang, ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{ang}\right| \end{array} \]
(FPCore (ang)
 :precision binary64
 (fabs
  (+
   -1.0
   (/ (fma (* (* -0.001851851851851852 (PI)) ang) ang (/ 180.0 (PI))) ang))))
\begin{array}{l}

\\
\left|-1 + \frac{\mathsf{fma}\left(\left(-0.001851851851851852 \cdot \mathsf{PI}\left(\right)\right) \cdot ang, ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{ang}\right|
\end{array}
Derivation
  1. Initial program 99.3%

    \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
  2. Add Preprocessing
  3. Taylor expanded in ang around inf

    \[\leadsto \left|\color{blue}{\frac{\cos \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}} - 1\right| \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{\cos \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)}} - 1\right| \]
    2. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(\left(ang \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{1}{180}\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    3. associate-*r*N/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(ang \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    4. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(ang \cdot \color{blue}{\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)}\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    5. lower-cos.f64N/A

      \[\leadsto \left|\frac{\color{blue}{\cos \left(ang \cdot \left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    6. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    7. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    8. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    9. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    10. lower-PI.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)\right)} - 1\right| \]
    11. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(\left(ang \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{1}{180}\right)}} - 1\right| \]
    12. associate-*r*N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(ang \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)\right)}} - 1\right| \]
    13. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(ang \cdot \color{blue}{\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)}\right)} - 1\right| \]
    14. lower-sin.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\color{blue}{\sin \left(ang \cdot \left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}} - 1\right| \]
    15. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}} - 1\right| \]
    16. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \color{blue}{\left(\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang\right)}} - 1\right| \]
    17. *-commutativeN/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)} - 1\right| \]
    18. lower-*.f64N/A

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right) \cdot ang\right)}{\sin \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang\right)} - 1\right| \]
    19. lower-PI.f6499.5

      \[\leadsto \left|\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}{\sin \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 0.005555555555555556\right) \cdot ang\right)} - 1\right| \]
  5. Applied rewrites99.5%

    \[\leadsto \left|\color{blue}{\frac{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}{\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang\right)}} - 1\right| \]
  6. Taylor expanded in ang around 0

    \[\leadsto \left|\frac{{ang}^{2} \cdot \left(\frac{-1}{360} \cdot \mathsf{PI}\left(\right) - \frac{-1}{1080} \cdot \mathsf{PI}\left(\right)\right) + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{\color{blue}{ang}} - 1\right| \]
  7. Step-by-step derivation
    1. Applied rewrites99.2%

      \[\leadsto \left|\frac{\mathsf{fma}\left(\left(-0.001851851851851852 \cdot \mathsf{PI}\left(\right)\right) \cdot ang, ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{\color{blue}{ang}} - 1\right| \]
    2. Final simplification99.2%

      \[\leadsto \left|-1 + \frac{\mathsf{fma}\left(\left(-0.001851851851851852 \cdot \mathsf{PI}\left(\right)\right) \cdot ang, ang, \frac{180}{\mathsf{PI}\left(\right)}\right)}{ang}\right| \]
    3. Add Preprocessing

    Alternative 5: 98.6% accurate, 4.8× speedup?

    \[\begin{array}{l} \\ \left|\frac{\frac{180}{\mathsf{PI}\left(\right)} - ang}{ang}\right| \end{array} \]
    (FPCore (ang) :precision binary64 (fabs (/ (- (/ 180.0 (PI)) ang) ang)))
    \begin{array}{l}
    
    \\
    \left|\frac{\frac{180}{\mathsf{PI}\left(\right)} - ang}{ang}\right|
    \end{array}
    
    Derivation
    1. Initial program 99.3%

      \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
    2. Add Preprocessing
    3. Taylor expanded in ang around 0

      \[\leadsto \left|\color{blue}{\frac{-1 \cdot ang + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot ang + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
      2. +-commutativeN/A

        \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} + -1 \cdot ang}}{ang}\right| \]
      3. mul-1-negN/A

        \[\leadsto \left|\frac{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} + \color{blue}{\left(\mathsf{neg}\left(ang\right)\right)}}{ang}\right| \]
      4. unsub-negN/A

        \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} - ang}}{ang}\right| \]
      5. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} - ang}}{ang}\right| \]
      6. associate-*r/N/A

        \[\leadsto \left|\frac{\color{blue}{\frac{180 \cdot 1}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
      7. metadata-evalN/A

        \[\leadsto \left|\frac{\frac{\color{blue}{180}}{\mathsf{PI}\left(\right)} - ang}{ang}\right| \]
      8. lower-/.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\frac{180}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
      9. lower-PI.f6498.6

        \[\leadsto \left|\frac{\frac{180}{\color{blue}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
    5. Applied rewrites98.6%

      \[\leadsto \left|\color{blue}{\frac{\frac{180}{\mathsf{PI}\left(\right)} - ang}{ang}}\right| \]
    6. Add Preprocessing

    Alternative 6: 98.5% accurate, 4.9× speedup?

    \[\begin{array}{l} \\ \left|-1 - \frac{-1}{\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang}\right| \end{array} \]
    (FPCore (ang)
     :precision binary64
     (fabs (- -1.0 (/ -1.0 (* (* (PI) 0.005555555555555556) ang)))))
    \begin{array}{l}
    
    \\
    \left|-1 - \frac{-1}{\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang}\right|
    \end{array}
    
    Derivation
    1. Initial program 99.3%

      \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
    2. Add Preprocessing
    3. Taylor expanded in ang around 0

      \[\leadsto \left|\frac{1}{\color{blue}{\frac{1}{180} \cdot \left(ang \cdot \mathsf{PI}\left(\right)\right)}} - 1\right| \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left|\frac{1}{\frac{1}{180} \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot ang\right)}} - 1\right| \]
      2. associate-*r*N/A

        \[\leadsto \left|\frac{1}{\color{blue}{\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang}} - 1\right| \]
      3. lower-*.f64N/A

        \[\leadsto \left|\frac{1}{\color{blue}{\left(\frac{1}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot ang}} - 1\right| \]
      4. *-commutativeN/A

        \[\leadsto \left|\frac{1}{\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang} - 1\right| \]
      5. lower-*.f64N/A

        \[\leadsto \left|\frac{1}{\color{blue}{\left(\mathsf{PI}\left(\right) \cdot \frac{1}{180}\right)} \cdot ang} - 1\right| \]
      6. lower-PI.f6498.5

        \[\leadsto \left|\frac{1}{\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 0.005555555555555556\right) \cdot ang} - 1\right| \]
    5. Applied rewrites98.5%

      \[\leadsto \left|\frac{1}{\color{blue}{\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang}} - 1\right| \]
    6. Final simplification98.5%

      \[\leadsto \left|-1 - \frac{-1}{\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot ang}\right| \]
    7. Add Preprocessing

    Alternative 7: 98.5% accurate, 6.0× speedup?

    \[\begin{array}{l} \\ \left|\frac{180}{\mathsf{PI}\left(\right) \cdot ang} - 1\right| \end{array} \]
    (FPCore (ang) :precision binary64 (fabs (- (/ 180.0 (* (PI) ang)) 1.0)))
    \begin{array}{l}
    
    \\
    \left|\frac{180}{\mathsf{PI}\left(\right) \cdot ang} - 1\right|
    \end{array}
    
    Derivation
    1. Initial program 99.3%

      \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
    2. Add Preprocessing
    3. Taylor expanded in ang around 0

      \[\leadsto \left|\color{blue}{\frac{-1 \cdot ang + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot ang + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
      2. +-commutativeN/A

        \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} + -1 \cdot ang}}{ang}\right| \]
      3. mul-1-negN/A

        \[\leadsto \left|\frac{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} + \color{blue}{\left(\mathsf{neg}\left(ang\right)\right)}}{ang}\right| \]
      4. unsub-negN/A

        \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} - ang}}{ang}\right| \]
      5. lower--.f64N/A

        \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} - ang}}{ang}\right| \]
      6. associate-*r/N/A

        \[\leadsto \left|\frac{\color{blue}{\frac{180 \cdot 1}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
      7. metadata-evalN/A

        \[\leadsto \left|\frac{\frac{\color{blue}{180}}{\mathsf{PI}\left(\right)} - ang}{ang}\right| \]
      8. lower-/.f64N/A

        \[\leadsto \left|\frac{\color{blue}{\frac{180}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
      9. lower-PI.f6498.6

        \[\leadsto \left|\frac{\frac{180}{\color{blue}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
    5. Applied rewrites98.6%

      \[\leadsto \left|\color{blue}{\frac{\frac{180}{\mathsf{PI}\left(\right)} - ang}{ang}}\right| \]
    6. Step-by-step derivation
      1. Applied rewrites98.4%

        \[\leadsto \left|\frac{180}{\mathsf{PI}\left(\right) \cdot ang} - \color{blue}{1}\right| \]
      2. Add Preprocessing

      Alternative 8: 97.4% accurate, 7.0× speedup?

      \[\begin{array}{l} \\ \left|\frac{180}{\mathsf{PI}\left(\right) \cdot ang}\right| \end{array} \]
      (FPCore (ang) :precision binary64 (fabs (/ 180.0 (* (PI) ang))))
      \begin{array}{l}
      
      \\
      \left|\frac{180}{\mathsf{PI}\left(\right) \cdot ang}\right|
      \end{array}
      
      Derivation
      1. Initial program 99.3%

        \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
      2. Add Preprocessing
      3. Taylor expanded in ang around 0

        \[\leadsto \left|\color{blue}{\frac{180}{ang \cdot \mathsf{PI}\left(\right)}}\right| \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{180}{ang \cdot \mathsf{PI}\left(\right)}}\right| \]
        2. *-commutativeN/A

          \[\leadsto \left|\frac{180}{\color{blue}{\mathsf{PI}\left(\right) \cdot ang}}\right| \]
        3. lower-*.f64N/A

          \[\leadsto \left|\frac{180}{\color{blue}{\mathsf{PI}\left(\right) \cdot ang}}\right| \]
        4. lower-PI.f6497.8

          \[\leadsto \left|\frac{180}{\color{blue}{\mathsf{PI}\left(\right)} \cdot ang}\right| \]
      5. Applied rewrites97.8%

        \[\leadsto \left|\color{blue}{\frac{180}{\mathsf{PI}\left(\right) \cdot ang}}\right| \]
      6. Add Preprocessing

      Alternative 9: 5.3% accurate, 44.3× speedup?

      \[\begin{array}{l} \\ \left|-1\right| \end{array} \]
      (FPCore (ang) :precision binary64 (fabs -1.0))
      double code(double ang) {
      	return fabs(-1.0);
      }
      
      real(8) function code(ang)
          real(8), intent (in) :: ang
          code = abs((-1.0d0))
      end function
      
      public static double code(double ang) {
      	return Math.abs(-1.0);
      }
      
      def code(ang):
      	return math.fabs(-1.0)
      
      function code(ang)
      	return abs(-1.0)
      end
      
      function tmp = code(ang)
      	tmp = abs(-1.0);
      end
      
      code[ang_] := N[Abs[-1.0], $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \left|-1\right|
      \end{array}
      
      Derivation
      1. Initial program 99.3%

        \[\left|\frac{1}{\tan \left(\frac{ang}{180} \cdot \mathsf{PI}\left(\right)\right)} - 1\right| \]
      2. Add Preprocessing
      3. Taylor expanded in ang around 0

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot ang + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \left|\color{blue}{\frac{-1 \cdot ang + 180 \cdot \frac{1}{\mathsf{PI}\left(\right)}}{ang}}\right| \]
        2. +-commutativeN/A

          \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} + -1 \cdot ang}}{ang}\right| \]
        3. mul-1-negN/A

          \[\leadsto \left|\frac{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} + \color{blue}{\left(\mathsf{neg}\left(ang\right)\right)}}{ang}\right| \]
        4. unsub-negN/A

          \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} - ang}}{ang}\right| \]
        5. lower--.f64N/A

          \[\leadsto \left|\frac{\color{blue}{180 \cdot \frac{1}{\mathsf{PI}\left(\right)} - ang}}{ang}\right| \]
        6. associate-*r/N/A

          \[\leadsto \left|\frac{\color{blue}{\frac{180 \cdot 1}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
        7. metadata-evalN/A

          \[\leadsto \left|\frac{\frac{\color{blue}{180}}{\mathsf{PI}\left(\right)} - ang}{ang}\right| \]
        8. lower-/.f64N/A

          \[\leadsto \left|\frac{\color{blue}{\frac{180}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
        9. lower-PI.f6498.6

          \[\leadsto \left|\frac{\frac{180}{\color{blue}{\mathsf{PI}\left(\right)}} - ang}{ang}\right| \]
      5. Applied rewrites98.6%

        \[\leadsto \left|\color{blue}{\frac{\frac{180}{\mathsf{PI}\left(\right)} - ang}{ang}}\right| \]
      6. Taylor expanded in ang around inf

        \[\leadsto \left|-1\right| \]
      7. Step-by-step derivation
        1. Applied rewrites5.1%

          \[\leadsto \left|-1\right| \]
        2. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 1 
        (FPCore (ang)
          :name "abs(1 / tan(ang / 180 * PI) - 1)"
          :precision binary64
          :pre (and (<= 0.0 ang) (<= ang 90.0))
          (fabs (- (/ 1.0 (tan (* (/ ang 180.0) (PI)))) 1.0)))