Beckmann Sample, near normal, slope_y

Percentage Accurate: 57.7% → 91.4%
Time: 11.3s
Alternatives: 9
Speedup: 8.9×

Specification

?
\[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\begin{array}{l} \\ \sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\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 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: 57.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}

Alternative 1: 91.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \mathbf{if}\;u1 \leq 0.00015999999595806003:\\ \;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (sin (* u2 (* (PI) 2.0)))))
   (if (<= u1 0.00015999999595806003)
     (* t_0 (pow (* u1 u1) 0.25))
     (* (sqrt (- (log (- 1.0 u1)))) t_0))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
\mathbf{if}\;u1 \leq 0.00015999999595806003:\\
\;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u1 < 1.59999996e-4

    1. Initial program 43.2%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    2. Add Preprocessing
    3. Applied rewrites32.5%

      \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    4. Taylor expanded in u1 around 0

      \[\leadsto {\color{blue}{\left({u1}^{2}\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    5. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      2. lower-*.f3290.6

        \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    6. Applied rewrites90.6%

      \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]

    if 1.59999996e-4 < u1

    1. Initial program 89.9%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification90.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;u1 \leq 0.00015999999595806003:\\ \;\;\;\;\sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 73.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := u2 \cdot \mathsf{PI}\left(\right)\\ t_1 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\ \;\;\;\;t\_1 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\ \;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\sin t\_0 \cdot \cos t\_0\right) \cdot 2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (* u2 (PI))) (t_1 (sin (* u2 (* (PI) 2.0)))))
   (if (<= u1 4.4999998749517545e-7)
     (* t_1 (pow (* u1 u1) 0.25))
     (if (<= u1 0.0038399999029934406)
       (*
        (sqrt
         (-
          (* (/ (- 1.0 (* 0.25 (* u1 u1))) (- 1.0 (* -0.5 u1))) u1)
          (log1p (* (- u1) u1))))
        t_1)
       (* (* (* (sin t_0) (cos t_0)) 2.0) (sqrt (- (log (- 1.0 u1)))))))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
\mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\
\;\;\;\;t\_1 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\

\mathbf{elif}\;u1 \leq 0.0038399999029934406:\\
\;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_1\\

\mathbf{else}:\\
\;\;\;\;\left(\left(\sin t\_0 \cdot \cos t\_0\right) \cdot 2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if u1 < 4.49999987e-7

    1. Initial program 21.5%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    2. Add Preprocessing
    3. Applied rewrites37.7%

      \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    4. Taylor expanded in u1 around 0

      \[\leadsto {\color{blue}{\left({u1}^{2}\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    5. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      2. lower-*.f3298.5

        \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    6. Applied rewrites98.5%

      \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]

    if 4.49999987e-7 < u1 < 0.0038399999

    1. Initial program 66.2%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    2. Add Preprocessing
    3. Applied rewrites33.9%

      \[\leadsto \sqrt{\color{blue}{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    4. Taylor expanded in u1 around 0

      \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + \frac{-1}{2} \cdot u1\right)} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    5. Step-by-step derivation
      1. *-commutativeN/A

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

        \[\leadsto \sqrt{\color{blue}{\left(1 + \frac{-1}{2} \cdot u1\right) \cdot u1} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      3. +-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{\left(\frac{-1}{2} \cdot u1 + 1\right)} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      4. lower-fma.f3216.3

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(-0.5, u1, 1\right)} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    6. Applied rewrites16.6%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(-0.5, u1, 1\right) \cdot u1} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    7. Step-by-step derivation
      1. Applied rewrites58.2%

        \[\leadsto \sqrt{\frac{1 - \left(u1 \cdot u1\right) \cdot 0.25}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]

      if 0.0038399999 < u1

      1. Initial program 94.7%

        \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-sin.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
        2. lift-*.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \sin \color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
        3. lift-*.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)} \cdot u2\right) \]
        4. associate-*l*N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \sin \color{blue}{\left(2 \cdot \left(\mathsf{PI}\left(\right) \cdot u2\right)\right)} \]
        5. sin-2N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(2 \cdot \left(\sin \left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot \cos \left(\mathsf{PI}\left(\right) \cdot u2\right)\right)\right)} \]
        6. *-commutativeN/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(\sin \left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot \cos \left(\mathsf{PI}\left(\right) \cdot u2\right)\right) \cdot 2\right)} \]
        7. lower-*.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(\sin \left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot \cos \left(\mathsf{PI}\left(\right) \cdot u2\right)\right) \cdot 2\right)} \]
        8. *-commutativeN/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\color{blue}{\left(\cos \left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot \sin \left(\mathsf{PI}\left(\right) \cdot u2\right)\right)} \cdot 2\right) \]
        9. lower-*.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\color{blue}{\left(\cos \left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot \sin \left(\mathsf{PI}\left(\right) \cdot u2\right)\right)} \cdot 2\right) \]
        10. lower-cos.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\color{blue}{\cos \left(\mathsf{PI}\left(\right) \cdot u2\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot u2\right)\right) \cdot 2\right) \]
        11. *-commutativeN/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\cos \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right)\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot u2\right)\right) \cdot 2\right) \]
        12. lower-*.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\cos \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right)\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot u2\right)\right) \cdot 2\right) \]
        13. lower-sin.f32N/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\cos \left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot \color{blue}{\sin \left(\mathsf{PI}\left(\right) \cdot u2\right)}\right) \cdot 2\right) \]
        14. *-commutativeN/A

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\cos \left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot \sin \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot 2\right) \]
        15. lower-*.f3294.7

          \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\cos \left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot \sin \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right)\right)}\right) \cdot 2\right) \]
      4. Applied rewrites94.7%

        \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(\cos \left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot \sin \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 2\right)} \]
    8. Recombined 3 regimes into one program.
    9. Final simplification68.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\ \;\;\;\;\sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\ \;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\sin \left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot \cos \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\ \end{array} \]
    10. Add Preprocessing

    Alternative 3: 73.1% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\ \;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\ \;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\ \end{array} \end{array} \]
    (FPCore (cosTheta_i u1 u2)
     :precision binary32
     (let* ((t_0 (sin (* u2 (* (PI) 2.0)))))
       (if (<= u1 4.4999998749517545e-7)
         (* t_0 (pow (* u1 u1) 0.25))
         (if (<= u1 0.0038399999029934406)
           (*
            (sqrt
             (-
              (* (/ (- 1.0 (* 0.25 (* u1 u1))) (- 1.0 (* -0.5 u1))) u1)
              (log1p (* (- u1) u1))))
            t_0)
           (* (sqrt (- (log (- 1.0 u1)))) t_0)))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
    \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\
    \;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
    
    \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\
    \;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if u1 < 4.49999987e-7

      1. Initial program 21.5%

        \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      2. Add Preprocessing
      3. Applied rewrites35.1%

        \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      4. Taylor expanded in u1 around 0

        \[\leadsto {\color{blue}{\left({u1}^{2}\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      5. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        2. lower-*.f3298.5

          \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      6. Applied rewrites98.5%

        \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]

      if 4.49999987e-7 < u1 < 0.0038399999

      1. Initial program 66.2%

        \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      2. Add Preprocessing
      3. Applied rewrites35.3%

        \[\leadsto \sqrt{\color{blue}{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      4. Taylor expanded in u1 around 0

        \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + \frac{-1}{2} \cdot u1\right)} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      5. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \sqrt{\color{blue}{\left(1 + \frac{-1}{2} \cdot u1\right) \cdot u1} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        3. +-commutativeN/A

          \[\leadsto \sqrt{\color{blue}{\left(\frac{-1}{2} \cdot u1 + 1\right)} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        4. lower-fma.f3216.6

          \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(-0.5, u1, 1\right)} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      6. Applied rewrites16.1%

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(-0.5, u1, 1\right) \cdot u1} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      7. Step-by-step derivation
        1. Applied rewrites59.4%

          \[\leadsto \sqrt{\frac{1 - \left(u1 \cdot u1\right) \cdot 0.25}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]

        if 0.0038399999 < u1

        1. Initial program 94.7%

          \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        2. Add Preprocessing
      8. Recombined 3 regimes into one program.
      9. Final simplification68.4%

        \[\leadsto \begin{array}{l} \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\ \;\;\;\;\sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\ \;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \end{array} \]
      10. Add Preprocessing

      Alternative 4: 73.1% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\ \;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\ \;\;\;\;\sqrt{\left(-0.5 \cdot u1 + 1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\ \end{array} \end{array} \]
      (FPCore (cosTheta_i u1 u2)
       :precision binary32
       (let* ((t_0 (sin (* u2 (* (PI) 2.0)))))
         (if (<= u1 4.4999998749517545e-7)
           (* t_0 (pow (* u1 u1) 0.25))
           (if (<= u1 0.0038399999029934406)
             (* (sqrt (- (* (+ (* -0.5 u1) 1.0) u1) (log1p (* (- u1) u1)))) t_0)
             (* (sqrt (- (log (- 1.0 u1)))) t_0)))))
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
      \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\
      \;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
      
      \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\
      \;\;\;\;\sqrt{\left(-0.5 \cdot u1 + 1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
      
      \mathbf{else}:\\
      \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if u1 < 4.49999987e-7

        1. Initial program 21.5%

          \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        2. Add Preprocessing
        3. Applied rewrites36.4%

          \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        4. Taylor expanded in u1 around 0

          \[\leadsto {\color{blue}{\left({u1}^{2}\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        5. Step-by-step derivation
          1. unpow2N/A

            \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. lower-*.f3298.5

            \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        6. Applied rewrites98.5%

          \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]

        if 4.49999987e-7 < u1 < 0.0038399999

        1. Initial program 66.2%

          \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        2. Add Preprocessing
        3. Applied rewrites35.2%

          \[\leadsto \sqrt{\color{blue}{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        4. Taylor expanded in u1 around 0

          \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + \frac{-1}{2} \cdot u1\right)} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        5. Step-by-step derivation
          1. *-commutativeN/A

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

            \[\leadsto \sqrt{\color{blue}{\left(1 + \frac{-1}{2} \cdot u1\right) \cdot u1} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          3. +-commutativeN/A

            \[\leadsto \sqrt{\color{blue}{\left(\frac{-1}{2} \cdot u1 + 1\right)} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          4. lower-fma.f3217.9

            \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(-0.5, u1, 1\right)} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        6. Applied rewrites13.7%

          \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(-0.5, u1, 1\right) \cdot u1} - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        7. Step-by-step derivation
          1. Applied rewrites51.2%

            \[\leadsto \sqrt{\left(-0.5 \cdot u1 + 1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]

          if 0.0038399999 < u1

          1. Initial program 94.7%

            \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. Add Preprocessing
        8. Recombined 3 regimes into one program.
        9. Final simplification68.6%

          \[\leadsto \begin{array}{l} \mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\ \;\;\;\;\sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \mathbf{elif}\;u1 \leq 0.0038399999029934406:\\ \;\;\;\;\sqrt{\left(-0.5 \cdot u1 + 1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \end{array} \]
        10. Add Preprocessing

        Alternative 5: 86.1% accurate, 1.0× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\ \mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\ \;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \end{array} \end{array} \]
        (FPCore (cosTheta_i u1 u2)
         :precision binary32
         (let* ((t_0 (* u2 (* (PI) 2.0))))
           (if (<= (- 1.0 u1) 0.9993000030517578)
             (* t_0 (sqrt (- (log (- 1.0 u1)))))
             (* (sin t_0) (pow (* u1 u1) 0.25)))))
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\
        \mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\
        \;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
        
        \mathbf{else}:\\
        \;\;\;\;\sin t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (-.f32 #s(literal 1 binary32) u1) < 0.9993

          1. Initial program 92.1%

            \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. Add Preprocessing
          3. Taylor expanded in u2 around 0

            \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot u2\right)}\right) \]
            2. associate-*r*N/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
            3. lower-*.f32N/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
            4. *-commutativeN/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)} \cdot u2\right) \]
            5. lower-*.f32N/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)} \cdot u2\right) \]
            6. lower-PI.f3280.1

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 2\right) \cdot u2\right) \]
          5. Applied rewrites80.1%

            \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)} \]

          if 0.9993 < (-.f32 #s(literal 1 binary32) u1)

          1. Initial program 45.7%

            \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. Add Preprocessing
          3. Applied rewrites31.1%

            \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          4. Taylor expanded in u1 around 0

            \[\leadsto {\color{blue}{\left({u1}^{2}\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          5. Step-by-step derivation
            1. unpow2N/A

              \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
            2. lower-*.f3289.0

              \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          6. Applied rewrites89.0%

            \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        3. Recombined 2 regimes into one program.
        4. Final simplification85.7%

          \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\ \;\;\;\;\left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}\\ \end{array} \]
        5. Add Preprocessing

        Alternative 6: 86.1% accurate, 1.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\ \mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\ \;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1} \cdot \sin t\_0\\ \end{array} \end{array} \]
        (FPCore (cosTheta_i u1 u2)
         :precision binary32
         (let* ((t_0 (* u2 (* (PI) 2.0))))
           (if (<= (- 1.0 u1) 0.9993000030517578)
             (* t_0 (sqrt (- (log (- 1.0 u1)))))
             (* (sqrt u1) (sin t_0)))))
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\
        \mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\
        \;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
        
        \mathbf{else}:\\
        \;\;\;\;\sqrt{u1} \cdot \sin t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (-.f32 #s(literal 1 binary32) u1) < 0.9993

          1. Initial program 92.1%

            \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. Add Preprocessing
          3. Taylor expanded in u2 around 0

            \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot u2\right)}\right) \]
            2. associate-*r*N/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
            3. lower-*.f32N/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
            4. *-commutativeN/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)} \cdot u2\right) \]
            5. lower-*.f32N/A

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)} \cdot u2\right) \]
            6. lower-PI.f3280.1

              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 2\right) \cdot u2\right) \]
          5. Applied rewrites80.1%

            \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)} \]

          if 0.9993 < (-.f32 #s(literal 1 binary32) u1)

          1. Initial program 45.7%

            \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. Add Preprocessing
          3. Applied rewrites32.3%

            \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          4. Taylor expanded in u1 around 0

            \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          5. Step-by-step derivation
            1. lower-sqrt.f3288.9

              \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          6. Applied rewrites88.9%

            \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        3. Recombined 2 regimes into one program.
        4. Final simplification85.7%

          \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\ \;\;\;\;\left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\ \end{array} \]
        5. Add Preprocessing

        Alternative 7: 76.5% accurate, 1.8× speedup?

        \[\begin{array}{l} \\ \sqrt{u1} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \end{array} \]
        (FPCore (cosTheta_i u1 u2)
         :precision binary32
         (* (sqrt u1) (sin (* u2 (* (PI) 2.0)))))
        \begin{array}{l}
        
        \\
        \sqrt{u1} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 62.5%

          \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        2. Add Preprocessing
        3. Applied rewrites26.2%

          \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        4. Taylor expanded in u1 around 0

          \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        5. Step-by-step derivation
          1. lower-sqrt.f3274.3

            \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        6. Applied rewrites74.3%

          \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        7. Final simplification74.3%

          \[\leadsto \sqrt{u1} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \]
        8. Add Preprocessing

        Alternative 8: 66.5% accurate, 1.9× speedup?

        \[\begin{array}{l} \\ \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot {\left(u1 \cdot u1\right)}^{0.25} \end{array} \]
        (FPCore (cosTheta_i u1 u2)
         :precision binary32
         (* (* (* u2 (PI)) 2.0) (pow (* u1 u1) 0.25)))
        \begin{array}{l}
        
        \\
        \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}
        \end{array}
        
        Derivation
        1. Initial program 62.5%

          \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        2. Add Preprocessing
        3. Applied rewrites26.7%

          \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        4. Taylor expanded in u1 around 0

          \[\leadsto {\color{blue}{\left({u1}^{2}\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        5. Step-by-step derivation
          1. unpow2N/A

            \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{\frac{1}{4}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. lower-*.f3274.3

            \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        6. Applied rewrites74.3%

          \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        7. Taylor expanded in u2 around 0

          \[\leadsto {\left(u1 \cdot u1\right)}^{\frac{1}{4}} \cdot \color{blue}{\left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right)} \]
        8. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto {\left(u1 \cdot u1\right)}^{\frac{1}{4}} \cdot \color{blue}{\left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)} \]
          2. lower-*.f32N/A

            \[\leadsto {\left(u1 \cdot u1\right)}^{\frac{1}{4}} \cdot \color{blue}{\left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)} \]
          3. *-commutativeN/A

            \[\leadsto {\left(u1 \cdot u1\right)}^{\frac{1}{4}} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot u2\right)} \cdot 2\right) \]
          4. lower-*.f32N/A

            \[\leadsto {\left(u1 \cdot u1\right)}^{\frac{1}{4}} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot u2\right)} \cdot 2\right) \]
          5. lower-PI.f3265.6

            \[\leadsto {\left(u1 \cdot u1\right)}^{0.25} \cdot \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot u2\right) \cdot 2\right) \]
        9. Applied rewrites65.6%

          \[\leadsto {\left(u1 \cdot u1\right)}^{0.25} \cdot \color{blue}{\left(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot 2\right)} \]
        10. Final simplification65.6%

          \[\leadsto \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot {\left(u1 \cdot u1\right)}^{0.25} \]
        11. Add Preprocessing

        Alternative 9: 66.5% accurate, 8.9× speedup?

        \[\begin{array}{l} \\ \sqrt{u1} \cdot \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \end{array} \]
        (FPCore (cosTheta_i u1 u2)
         :precision binary32
         (* (sqrt u1) (* u2 (* (PI) 2.0))))
        \begin{array}{l}
        
        \\
        \sqrt{u1} \cdot \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 62.5%

          \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        2. Add Preprocessing
        3. Applied rewrites27.1%

          \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        4. Taylor expanded in u1 around 0

          \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        5. Step-by-step derivation
          1. lower-sqrt.f3274.3

            \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        6. Applied rewrites74.3%

          \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
        7. Taylor expanded in u2 around 0

          \[\leadsto \sqrt{u1} \cdot \color{blue}{\left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right)} \]
        8. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \sqrt{u1} \cdot \left(2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot u2\right)}\right) \]
          2. associate-*r*N/A

            \[\leadsto \sqrt{u1} \cdot \color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
          3. lower-*.f32N/A

            \[\leadsto \sqrt{u1} \cdot \color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)} \]
          4. *-commutativeN/A

            \[\leadsto \sqrt{u1} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)} \cdot u2\right) \]
          5. lower-*.f32N/A

            \[\leadsto \sqrt{u1} \cdot \left(\color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)} \cdot u2\right) \]
          6. lower-PI.f3265.6

            \[\leadsto \sqrt{u1} \cdot \left(\left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 2\right) \cdot u2\right) \]
        9. Applied rewrites65.6%

          \[\leadsto \sqrt{u1} \cdot \color{blue}{\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)} \]
        10. Final simplification65.6%

          \[\leadsto \sqrt{u1} \cdot \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \]
        11. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 2024268 
        (FPCore (cosTheta_i u1 u2)
          :name "Beckmann Sample, near normal, slope_y"
          :precision binary32
          :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
          (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))