Trowbridge-Reitz Sample, sample surface normal, cosTheta

Percentage Accurate: 99.4% → 100.0%
Time: 16.6s
Alternatives: 8
Speedup: 1.7×

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 8 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: 100.0% accurate, 1.3× speedup?

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

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

    \[\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. Applied rewrites100.0%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{u0}{{\left(\frac{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{2} + {\left(\frac{\cos \tan^{-1} \left(\tan \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphax}\right)}^{2}}}{1 - u0}\right) \cdot -0.5}} \]
  4. Add Preprocessing

Alternative 2: 99.8% accurate, 1.6× speedup?

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

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

    \[\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. Applied rewrites100.0%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{u0}{{\left(\frac{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{2} + {\left(\frac{\cos \tan^{-1} \left(\tan \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphax}\right)}^{2}}}{1 - u0}\right) \cdot -0.5}} \]
  4. Applied rewrites99.9%

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

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

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

Alternative 3: 99.7% accurate, 1.7× speedup?

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

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

    \[\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. Applied rewrites100.0%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{u0}{{\left(\frac{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{2} + {\left(\frac{\cos \tan^{-1} \left(\tan \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphax}\right)}^{2}}}{1 - u0}\right) \cdot -0.5}} \]
  4. Applied rewrites99.9%

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

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

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

Alternative 4: 98.7% accurate, 2.4× speedup?

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

\\
\sqrt{\frac{1}{\mathsf{fma}\left(\frac{alphay \cdot alphay}{{\sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \frac{\sin \left(\mathsf{PI}\left(\right) \cdot 0.5\right)}{\cos \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, u1, 0.5\right)\right)}\right)}^{2}}, \frac{u0}{1 - u0}, 1\right)}}
\end{array}
Derivation
  1. Initial program 99.5%

    \[\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 alphax around inf

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

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

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

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

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

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

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

    Alternative 5: 98.2% accurate, 3.0× speedup?

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

      \[\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 alphax around inf

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

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

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

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

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

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

    Alternative 6: 96.5% accurate, 3.7× speedup?

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

      \[\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}{\color{blue}{1 + \frac{1}{2} \cdot \frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \sin \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot \cos \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}\right)}^{2} \cdot \left(1 - u0\right)}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

      Alternative 7: 96.5% accurate, 3.9× speedup?

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

        \[\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 \color{blue}{1 + \frac{-1}{2} \cdot \frac{{alphay}^{2} \cdot u0}{{\sin \tan^{-1} \left(\frac{alphay \cdot \sin \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}{alphax \cdot \cos \left(\frac{1}{2} \cdot \mathsf{PI}\left(\right) + 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\right)}\right)}^{2} \cdot \left(1 - u0\right)}} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

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

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

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

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

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

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

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

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

          Alternative 8: 91.5% 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;
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(4) function code(u0, u1, alphax, alphay)
          use fmin_fmax_functions
              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.5%

            \[\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 u0 around 0

            \[\leadsto \color{blue}{1} \]
          4. Step-by-step derivation
            1. Applied rewrites92.3%

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

            Reproduce

            ?
            herbie shell --seed 2024351 
            (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))))))