Trowbridge-Reitz Sample, sample surface normal, cosTheta

Percentage Accurate: 99.4% → 99.4%
Time: 21.9s
Alternatives: 7
Speedup: 1.5×

Specification

?
\[\left(\left(\left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 0.5\right)\right) \land \left(0.0001 \leq alphax \land alphax \leq 1\right)\right) \land \left(0.0001 \leq alphay \land alphay \leq 1\right)\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\ t_1 := \sin t\_0\\ t_2 := \cos t\_0\\ \frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \end{array} \end{array} \]
(FPCore (u0 u1 alphax alphay)
 :precision binary32
 (let* ((t_0
         (atan
          (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))
        (t_1 (sin t_0))
        (t_2 (cos t_0)))
   (/
    1.0
    (sqrt
     (+
      1.0
      (/
       (*
        (/
         1.0
         (+
          (/ (* t_2 t_2) (* alphax alphax))
          (/ (* t_1 t_1) (* alphay alphay))))
        u0)
       (- 1.0 u0)))))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}

Sampling outcomes in binary32 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 7 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.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\ t_1 := \sin t\_0\\ t_2 := \cos t\_0\\ \frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \end{array} \end{array} \]
(FPCore (u0 u1 alphax alphay)
 :precision binary32
 (let* ((t_0
         (atan
          (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))
        (t_1 (sin t_0))
        (t_2 (cos t_0)))
   (/
    1.0
    (sqrt
     (+
      1.0
      (/
       (*
        (/
         1.0
         (+
          (/ (* t_2 t_2) (* alphax alphax))
          (/ (* t_1 t_1) (* alphay alphay))))
        u0)
       (- 1.0 u0)))))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}

Alternative 1: 99.4% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\\ \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos t\_0}^{2}}{alphax \cdot alphax} + \frac{{\sin t\_0}^{2}}{alphay \cdot alphay}\right)}}} \end{array} \end{array} \]
(FPCore (u0 u1 alphax alphay)
 :precision binary32
 (let* ((t_0 (atan (* (tan (* (PI) (+ 0.5 (* 2.0 u1)))) (/ alphay alphax)))))
   (/
    1.0
    (sqrt
     (+
      1.0
      (/
       u0
       (*
        (- 1.0 u0)
        (+
         (/ (pow (cos t_0) 2.0) (* alphax alphax))
         (/ (pow (sin t_0) 2.0) (* alphay alphay))))))))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\\
\frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos t\_0}^{2}}{alphax \cdot alphax} + \frac{{\sin t\_0}^{2}}{alphay \cdot alphay}\right)}}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{\cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot alphax} + \frac{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \]
  2. Add Preprocessing
  3. Taylor expanded in u1 around 0

    \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{u0}{\left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right) \cdot \left(1 - u0\right)}}}} \]
  4. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{u0}{\left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right) \cdot \left(1 - u0\right)}}}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\color{blue}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right)}}}} \]
    3. lower-*.f32N/A

      \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\color{blue}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right)}}}} \]
    4. lower--.f32N/A

      \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\color{blue}{\left(1 - u0\right)} \cdot \left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right)}}} \]
  5. Applied rewrites94.4%

    \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}}} \]
  6. Step-by-step derivation
    1. Applied rewrites85.7%

      \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}} \]
    2. Step-by-step derivation
      1. Applied rewrites99.4%

        \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}} \]
      2. Final simplification99.4%

        \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}} \]
      3. Add Preprocessing

      Alternative 2: 98.3% accurate, 1.5× speedup?

      \[\begin{array}{l} \\ \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)}^{2}}{alphay \cdot alphay}\right)}}} \end{array} \]
      (FPCore (u0 u1 alphax alphay)
       :precision binary32
       (/
        1.0
        (sqrt
         (+
          1.0
          (/
           u0
           (*
            (- 1.0 u0)
            (+
             (/
              (pow
               (cos (atan (* (tan (* (PI) (+ 0.5 (* 2.0 u1)))) (/ alphay alphax))))
               2.0)
              (* alphax alphax))
             (/
              (pow (sin (atan (* (/ alphay alphax) (tan (* (PI) 0.5))))) 2.0)
              (* alphay alphay)))))))))
      \begin{array}{l}
      
      \\
      \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)}^{2}}{alphay \cdot alphay}\right)}}}
      \end{array}
      
      Derivation
      1. Initial program 99.4%

        \[\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{\cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot alphax} + \frac{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \]
      2. Add Preprocessing
      3. Taylor expanded in u1 around 0

        \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{u0}{\left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right) \cdot \left(1 - u0\right)}}}} \]
      4. Step-by-step derivation
        1. lower-/.f32N/A

          \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{u0}{\left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right) \cdot \left(1 - u0\right)}}}} \]
        2. *-commutativeN/A

          \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\color{blue}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right)}}}} \]
        3. lower-*.f32N/A

          \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\color{blue}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right)}}}} \]
        4. lower--.f32N/A

          \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\color{blue}{\left(1 - u0\right)} \cdot \left(\frac{{\cos \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphax}^{2}} + \frac{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2}}{{alphay}^{2}}\right)}}} \]
      5. Applied rewrites94.4%

        \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}}} \]
      6. Step-by-step derivation
        1. Applied rewrites85.7%

          \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}} \]
        2. Taylor expanded in u1 around 0

          \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + \frac{1}{2}\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}} \]
        3. Step-by-step derivation
          1. Applied rewrites98.4%

            \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay \cdot alphay}\right)}}} \]
          2. Final simplification98.4%

            \[\leadsto \frac{1}{\sqrt{1 + \frac{u0}{\left(1 - u0\right) \cdot \left(\frac{{\cos \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)}^{2}}{alphay \cdot alphay}\right)}}} \]
          3. Add Preprocessing

          Alternative 3: 98.2% accurate, 3.0× speedup?

          \[\begin{array}{l} \\ {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\right)\right)}\right)}^{-0.5} \end{array} \]
          (FPCore (u0 u1 alphax alphay)
           :precision binary32
           (pow
            (+
             1.0
             (/
              (* alphay (* alphay u0))
              (*
               (- 1.0 u0)
               (+
                0.5
                (*
                 -0.5
                 (cos
                  (*
                   2.0
                   (atan (* (tan (* (PI) (+ 0.5 (* 2.0 u1)))) (/ alphay alphax))))))))))
            -0.5))
          \begin{array}{l}
          
          \\
          {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\right)\right)}\right)}^{-0.5}
          \end{array}
          
          Derivation
          1. Initial program 99.4%

            \[\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{\cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot alphax} + \frac{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \]
          2. Add Preprocessing
          3. Taylor expanded in alphay around 0

            \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
          4. Step-by-step derivation
            1. lower-/.f32N/A

              \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
            2. lower-*.f32N/A

              \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{{alphay}^{2} \cdot u0}}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
            3. unpow2N/A

              \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
            4. lower-*.f32N/A

              \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
            5. lower-*.f32N/A

              \[\leadsto \frac{1}{\sqrt{1 + \frac{\left(alphay \cdot alphay\right) \cdot u0}{\color{blue}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
          5. Applied rewrites95.2%

            \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{\left(alphay \cdot alphay\right) \cdot u0}{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
          6. Applied rewrites80.3%

            \[\leadsto \color{blue}{{\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right)\right)\right)\right)}\right)}^{-0.5}} \]
          7. Step-by-step derivation
            1. Applied rewrites98.2%

              \[\leadsto {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + 0.5\right)\right)\right)\right)\right)}\right)}^{-0.5} \]
            2. Final simplification98.2%

              \[\leadsto {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\right)\right)}\right)}^{-0.5} \]
            3. Add Preprocessing

            Alternative 4: 98.1% accurate, 3.1× speedup?

            \[\begin{array}{l} \\ {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)}\right)}^{-0.5} \end{array} \]
            (FPCore (u0 u1 alphax alphay)
             :precision binary32
             (pow
              (+
               1.0
               (/
                (* alphay (* alphay u0))
                (*
                 (- 1.0 u0)
                 (+
                  0.5
                  (*
                   -0.5
                   (cos (* 2.0 (atan (* (/ alphay alphax) (tan (* (PI) 0.5)))))))))))
              -0.5))
            \begin{array}{l}
            
            \\
            {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)}\right)}^{-0.5}
            \end{array}
            
            Derivation
            1. Initial program 99.4%

              \[\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{\cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot alphax} + \frac{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \]
            2. Add Preprocessing
            3. Taylor expanded in alphay around 0

              \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
            4. Step-by-step derivation
              1. lower-/.f32N/A

                \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
              2. lower-*.f32N/A

                \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{{alphay}^{2} \cdot u0}}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
              3. unpow2N/A

                \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
              4. lower-*.f32N/A

                \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
              5. lower-*.f32N/A

                \[\leadsto \frac{1}{\sqrt{1 + \frac{\left(alphay \cdot alphay\right) \cdot u0}{\color{blue}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
            5. Applied rewrites95.2%

              \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{\left(alphay \cdot alphay\right) \cdot u0}{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
            6. Applied rewrites80.3%

              \[\leadsto \color{blue}{{\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right)\right)\right)\right)}\right)}^{-0.5}} \]
            7. Taylor expanded in u1 around 0

              \[\leadsto {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right)\right)\right)\right)}\right)}^{\frac{-1}{2}} \]
            8. Step-by-step derivation
              1. Applied rewrites98.0%

                \[\leadsto {\left(1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)}\right)}^{-0.5} \]
              2. Add Preprocessing

              Alternative 5: 97.8% accurate, 3.6× speedup?

              \[\begin{array}{l} \\ \frac{1}{\sqrt{1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\right)\right)}}} \end{array} \]
              (FPCore (u0 u1 alphax alphay)
               :precision binary32
               (/
                1.0
                (sqrt
                 (+
                  1.0
                  (/
                   (* alphay (* alphay u0))
                   (*
                    (- 1.0 u0)
                    (+
                     0.5
                     (*
                      -0.5
                      (cos
                       (*
                        2.0
                        (atan
                         (* (tan (* (PI) (+ 0.5 (* 2.0 u1)))) (/ alphay alphax)))))))))))))
              \begin{array}{l}
              
              \\
              \frac{1}{\sqrt{1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\right)\right)}}}
              \end{array}
              
              Derivation
              1. Initial program 99.4%

                \[\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{\cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot alphax} + \frac{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \]
              2. Add Preprocessing
              3. Taylor expanded in alphay around 0

                \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
              4. Step-by-step derivation
                1. lower-/.f32N/A

                  \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                2. lower-*.f32N/A

                  \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{{alphay}^{2} \cdot u0}}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                3. unpow2N/A

                  \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                4. lower-*.f32N/A

                  \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                5. lower-*.f32N/A

                  \[\leadsto \frac{1}{\sqrt{1 + \frac{\left(alphay \cdot alphay\right) \cdot u0}{\color{blue}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
              5. Applied rewrites95.2%

                \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{\left(alphay \cdot alphay\right) \cdot u0}{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
              6. Applied rewrites97.7%

                \[\leadsto \frac{1}{\sqrt{\color{blue}{\frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right)\right)\right)\right)} + 1}}} \]
              7. Step-by-step derivation
                1. Applied rewrites97.9%

                  \[\leadsto \frac{1}{\sqrt{\frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot u1 + 0.5\right)\right)\right)\right)\right)} + 1}} \]
                2. Final simplification97.9%

                  \[\leadsto \frac{1}{\sqrt{1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \left(0.5 + 2 \cdot u1\right)\right) \cdot \frac{alphay}{alphax}\right)\right)\right)}}} \]
                3. Add Preprocessing

                Alternative 6: 97.8% accurate, 3.7× speedup?

                \[\begin{array}{l} \\ \frac{1}{\sqrt{1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)}}} \end{array} \]
                (FPCore (u0 u1 alphax alphay)
                 :precision binary32
                 (/
                  1.0
                  (sqrt
                   (+
                    1.0
                    (/
                     (* alphay (* alphay u0))
                     (*
                      (- 1.0 u0)
                      (+
                       0.5
                       (*
                        -0.5
                        (cos (* 2.0 (atan (* (/ alphay alphax) (tan (* (PI) 0.5))))))))))))))
                \begin{array}{l}
                
                \\
                \frac{1}{\sqrt{1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)}}}
                \end{array}
                
                Derivation
                1. Initial program 99.4%

                  \[\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{\cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot alphax} + \frac{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \]
                2. Add Preprocessing
                3. Taylor expanded in alphay around 0

                  \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                4. Step-by-step derivation
                  1. lower-/.f32N/A

                    \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                  2. lower-*.f32N/A

                    \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{{alphay}^{2} \cdot u0}}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                  3. unpow2N/A

                    \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                  4. lower-*.f32N/A

                    \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                  5. lower-*.f32N/A

                    \[\leadsto \frac{1}{\sqrt{1 + \frac{\left(alphay \cdot alphay\right) \cdot u0}{\color{blue}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                5. Applied rewrites95.2%

                  \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{\left(alphay \cdot alphay\right) \cdot u0}{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                6. Applied rewrites97.7%

                  \[\leadsto \frac{1}{\sqrt{\color{blue}{\frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right)\right)\right)\right)} + 1}}} \]
                7. Taylor expanded in u1 around 0

                  \[\leadsto \frac{1}{\sqrt{\frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(\frac{1}{2} + \frac{-1}{2} \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \frac{1}{2}\right)\right)\right)\right)} + 1}} \]
                8. Step-by-step derivation
                  1. Applied rewrites97.7%

                    \[\leadsto \frac{1}{\sqrt{\frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)} + 1}} \]
                  2. Final simplification97.7%

                    \[\leadsto \frac{1}{\sqrt{1 + \frac{alphay \cdot \left(alphay \cdot u0\right)}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)}}} \]
                  3. Add Preprocessing

                  Alternative 7: 91.8% accurate, 1436.0× speedup?

                  \[\begin{array}{l} \\ 1 \end{array} \]
                  (FPCore (u0 u1 alphax alphay) :precision binary32 1.0)
                  float code(float u0, float u1, float alphax, float alphay) {
                  	return 1.0f;
                  }
                  
                  real(4) function code(u0, u1, alphax, alphay)
                      real(4), intent (in) :: u0
                      real(4), intent (in) :: u1
                      real(4), intent (in) :: alphax
                      real(4), intent (in) :: alphay
                      code = 1.0e0
                  end function
                  
                  function code(u0, u1, alphax, alphay)
                  	return Float32(1.0)
                  end
                  
                  function tmp = code(u0, u1, alphax, alphay)
                  	tmp = single(1.0);
                  end
                  
                  \begin{array}{l}
                  
                  \\
                  1
                  \end{array}
                  
                  Derivation
                  1. Initial program 99.4%

                    \[\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{\cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot alphax} + \frac{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}} \cdot u0}{1 - u0}}} \]
                  2. Add Preprocessing
                  3. Taylor expanded in alphay around 0

                    \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                  4. Step-by-step derivation
                    1. lower-/.f32N/A

                      \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                    2. lower-*.f32N/A

                      \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{{alphay}^{2} \cdot u0}}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                    3. unpow2N/A

                      \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                    4. lower-*.f32N/A

                      \[\leadsto \frac{1}{\sqrt{1 + \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
                    5. lower-*.f32N/A

                      \[\leadsto \frac{1}{\sqrt{1 + \frac{\left(alphay \cdot alphay\right) \cdot u0}{\color{blue}{{\sin \tan^{-1} \left(\frac{alphay \cdot \tan \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                  5. Applied rewrites95.2%

                    \[\leadsto \frac{1}{\sqrt{1 + \color{blue}{\frac{\left(alphay \cdot alphay\right) \cdot u0}{{\sin \tan^{-1} \left(\tan \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2} \cdot \left(1 - u0\right)}}}} \]
                  6. Taylor expanded in alphay around 0

                    \[\leadsto \color{blue}{1} \]
                  7. Step-by-step derivation
                    1. Applied rewrites91.6%

                      \[\leadsto \color{blue}{1} \]
                    2. Add Preprocessing

                    Reproduce

                    ?
                    herbie shell --seed 2024221 
                    (FPCore (u0 u1 alphax alphay)
                      :name "Trowbridge-Reitz Sample, sample surface normal, cosTheta"
                      :precision binary32
                      :pre (and (and (and (and (<= 2.328306437e-10 u0) (<= u0 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 0.5))) (and (<= 0.0001 alphax) (<= alphax 1.0))) (and (<= 0.0001 alphay) (<= alphay 1.0)))
                      (/ 1.0 (sqrt (+ 1.0 (/ (* (/ 1.0 (+ (/ (* (cos (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI))))))) (cos (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))) (* alphax alphax)) (/ (* (sin (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI))))))) (sin (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))) (* alphay alphay)))) u0) (- 1.0 u0))))))