Beckmann Sample, near normal, slope_x

Percentage Accurate: 57.0% → 97.5%
Time: 6.9s
Alternatives: 8
Speedup: 11.6×

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 \cos \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)))) (cos (* (* 2.0 (PI)) u2))))
\begin{array}{l}

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \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 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: 57.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{-\log \left(1 - u1\right)} \cdot \cos \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)))) (cos (* (* 2.0 (PI)) u2))))
\begin{array}{l}

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

Alternative 1: 97.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9965000152587891:\\ \;\;\;\;\cos \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\left(\left(-0.5 \cdot u1\right) \cdot u1 - u1\right)}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (if (<= (- 1.0 u1) 0.9965000152587891)
   (* (cos (* u2 (* (PI) 2.0))) (sqrt (- (log (- 1.0 u1)))))
   (* (cos (* (+ u2 u2) (PI))) (sqrt (- (- (* (* -0.5 u1) u1) u1))))))
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9965000152587891:\\
\;\;\;\;\cos \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\left(\left(-0.5 \cdot u1\right) \cdot u1 - u1\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f32 #s(literal 1 binary32) u1) < 0.99650002

    1. Initial program 94.7%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    2. Add Preprocessing

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

    1. Initial program 43.7%

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

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

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

        \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 - 1\right) \cdot u1}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      3. sub-negN/A

        \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 + \left(\mathsf{neg}\left(1\right)\right)\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      4. metadata-evalN/A

        \[\leadsto \sqrt{-\left(\frac{-1}{2} \cdot u1 + \color{blue}{-1}\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      5. lower-fma.f3266.3

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

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

        \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      2. Step-by-step derivation
        1. lift-*.f32N/A

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

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

          \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)}\right) \]
        4. count-2-revN/A

          \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right)}\right) \]
        5. distribute-lft-inN/A

          \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right) + u2 \cdot \mathsf{PI}\left(\right)\right)} \]
        6. distribute-rgt-outN/A

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

          \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)} \]
        8. lower-+.f3297.7

          \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\left(u2 + u2\right)}\right) \]
      3. Applied rewrites97.7%

        \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)} \]
      4. Step-by-step derivation
        1. Applied rewrites97.9%

          \[\leadsto \sqrt{-\left(\left(-0.5 \cdot u1\right) \cdot u1 + \color{blue}{\left(-u1\right)}\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right) \]
      5. Recombined 2 regimes into one program.
      6. Final simplification97.2%

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

      Alternative 2: 93.9% accurate, 0.6× speedup?

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

        1. Initial program 48.1%

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

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

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

            \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 - 1\right) \cdot u1}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          3. sub-negN/A

            \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 + \left(\mathsf{neg}\left(1\right)\right)\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          4. metadata-evalN/A

            \[\leadsto \sqrt{-\left(\frac{-1}{2} \cdot u1 + \color{blue}{-1}\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          5. lower-fma.f3264.3

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

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

            \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
          2. Step-by-step derivation
            1. lift-*.f32N/A

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

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

              \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)}\right) \]
            4. count-2-revN/A

              \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right)}\right) \]
            5. distribute-lft-inN/A

              \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right) + u2 \cdot \mathsf{PI}\left(\right)\right)} \]
            6. distribute-rgt-outN/A

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

              \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)} \]
            8. lower-+.f3295.7

              \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\left(u2 + u2\right)}\right) \]
          3. Applied rewrites95.7%

            \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)} \]
          4. Step-by-step derivation
            1. Applied rewrites95.9%

              \[\leadsto \sqrt{-\left(\left(-0.5 \cdot u1\right) \cdot u1 + \color{blue}{\left(-u1\right)}\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right) \]

            if 0.122000001 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)))

            1. Initial program 96.7%

              \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \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}{1} \]
            4. Step-by-step derivation
              1. Applied rewrites77.8%

                \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{1} \]
            5. Recombined 2 regimes into one program.
            6. Final simplification93.0%

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

            Alternative 3: 93.8% accurate, 0.6× speedup?

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

              1. Initial program 48.1%

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

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

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

                  \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 - 1\right) \cdot u1}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                3. sub-negN/A

                  \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 + \left(\mathsf{neg}\left(1\right)\right)\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                4. metadata-evalN/A

                  \[\leadsto \sqrt{-\left(\frac{-1}{2} \cdot u1 + \color{blue}{-1}\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                5. lower-fma.f3264.3

                  \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(-0.5, u1, -1\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
              5. Applied rewrites64.1%

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

                  \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                2. Step-by-step derivation
                  1. lift-*.f32N/A

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

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

                    \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)}\right) \]
                  4. count-2-revN/A

                    \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right)}\right) \]
                  5. distribute-lft-inN/A

                    \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right) + u2 \cdot \mathsf{PI}\left(\right)\right)} \]
                  6. distribute-rgt-outN/A

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

                    \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)} \]
                  8. lower-+.f3295.7

                    \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\left(u2 + u2\right)}\right) \]
                3. Applied rewrites95.7%

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

                if 0.122000001 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)))

                1. Initial program 96.7%

                  \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \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}{1} \]
                4. Step-by-step derivation
                  1. Applied rewrites77.8%

                    \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{1} \]
                5. Recombined 2 regimes into one program.
                6. Final simplification92.9%

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

                Alternative 4: 86.6% accurate, 0.6× speedup?

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

                  1. Initial program 37.0%

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

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

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

                      \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 - 1\right) \cdot u1}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                    3. sub-negN/A

                      \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 + \left(\mathsf{neg}\left(1\right)\right)\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                    4. metadata-evalN/A

                      \[\leadsto \sqrt{-\left(\frac{-1}{2} \cdot u1 + \color{blue}{-1}\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                    5. lower-fma.f3266.4

                      \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(-0.5, u1, -1\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                  5. Applied rewrites66.3%

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

                      \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                    2. Step-by-step derivation
                      1. lift-*.f32N/A

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

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

                        \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)}\right) \]
                      4. count-2-revN/A

                        \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \left(u2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right)}\right) \]
                      5. distribute-lft-inN/A

                        \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(u2 \cdot \mathsf{PI}\left(\right) + u2 \cdot \mathsf{PI}\left(\right)\right)} \]
                      6. distribute-rgt-outN/A

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

                        \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)} \]
                      8. lower-+.f3297.6

                        \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\left(u2 + u2\right)}\right) \]
                    3. Applied rewrites97.6%

                      \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)} \]
                    4. Taylor expanded in u1 around 0

                      \[\leadsto \sqrt{-\color{blue}{-1 \cdot u1}} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right) \]
                    5. Step-by-step derivation
                      1. mul-1-negN/A

                        \[\leadsto \sqrt{-\color{blue}{\left(\mathsf{neg}\left(u1\right)\right)}} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right) \]
                      2. lower-neg.f3292.2

                        \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right) \]
                    6. Applied rewrites92.2%

                      \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right) \]

                    if 0.0120000001 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)))

                    1. Initial program 88.3%

                      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \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}{1} \]
                    4. Step-by-step derivation
                      1. Applied rewrites75.3%

                        \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{1} \]
                    5. Recombined 2 regimes into one program.
                    6. Final simplification86.0%

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

                    Alternative 5: 79.4% accurate, 0.6× speedup?

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

                      1. Initial program 44.3%

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

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

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

                          \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 - 1\right) \cdot u1}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                        3. sub-negN/A

                          \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 + \left(\mathsf{neg}\left(1\right)\right)\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                        4. metadata-evalN/A

                          \[\leadsto \sqrt{-\left(\frac{-1}{2} \cdot u1 + \color{blue}{-1}\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                        5. lower-fma.f3266.4

                          \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(-0.5, u1, -1\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                      5. Applied rewrites65.0%

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

                          \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                        2. Taylor expanded in u2 around 0

                          \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \color{blue}{1} \]
                        3. Step-by-step derivation
                          1. Applied rewrites77.4%

                            \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \color{blue}{1} \]

                          if 0.0555000007 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)))

                          1. Initial program 94.4%

                            \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \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}{1} \]
                          4. Step-by-step derivation
                            1. Applied rewrites76.5%

                              \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{1} \]
                          5. Recombined 2 regimes into one program.
                          6. Final simplification77.2%

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

                          Alternative 6: 73.0% accurate, 7.5× speedup?

                          \[\begin{array}{l} \\ \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot 1 \end{array} \]
                          (FPCore (cosTheta_i u1 u2)
                           :precision binary32
                           (* (sqrt (- (* (- -1.0 (* 0.5 u1)) u1))) 1.0))
                          float code(float cosTheta_i, float u1, float u2) {
                          	return sqrtf(-((-1.0f - (0.5f * u1)) * u1)) * 1.0f;
                          }
                          
                          real(4) function code(costheta_i, u1, u2)
                              real(4), intent (in) :: costheta_i
                              real(4), intent (in) :: u1
                              real(4), intent (in) :: u2
                              code = sqrt(-(((-1.0e0) - (0.5e0 * u1)) * u1)) * 1.0e0
                          end function
                          
                          function code(cosTheta_i, u1, u2)
                          	return Float32(sqrt(Float32(-Float32(Float32(Float32(-1.0) - Float32(Float32(0.5) * u1)) * u1))) * Float32(1.0))
                          end
                          
                          function tmp = code(cosTheta_i, u1, u2)
                          	tmp = sqrt(-((single(-1.0) - (single(0.5) * u1)) * u1)) * single(1.0);
                          end
                          
                          \begin{array}{l}
                          
                          \\
                          \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot 1
                          \end{array}
                          
                          Derivation
                          1. Initial program 55.8%

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

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

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

                              \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 - 1\right) \cdot u1}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                            3. sub-negN/A

                              \[\leadsto \sqrt{-\color{blue}{\left(\frac{-1}{2} \cdot u1 + \left(\mathsf{neg}\left(1\right)\right)\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                            4. metadata-evalN/A

                              \[\leadsto \sqrt{-\left(\frac{-1}{2} \cdot u1 + \color{blue}{-1}\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                            5. lower-fma.f3259.8

                              \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(-0.5, u1, -1\right)} \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                          5. Applied rewrites60.2%

                            \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(-0.5, u1, -1\right) \cdot u1}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                          6. Step-by-step derivation
                            1. Applied rewrites88.5%

                              \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                            2. Taylor expanded in u2 around 0

                              \[\leadsto \sqrt{-\left(-1 - \frac{1}{2} \cdot u1\right) \cdot u1} \cdot \color{blue}{1} \]
                            3. Step-by-step derivation
                              1. Applied rewrites72.0%

                                \[\leadsto \sqrt{-\left(-1 - 0.5 \cdot u1\right) \cdot u1} \cdot \color{blue}{1} \]
                              2. Add Preprocessing

                              Alternative 7: 65.3% accurate, 11.6× speedup?

                              \[\begin{array}{l} \\ \sqrt{-\left(-u1\right)} \cdot 1 \end{array} \]
                              (FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (- u1))) 1.0))
                              float code(float cosTheta_i, float u1, float u2) {
                              	return sqrtf(-(-u1)) * 1.0f;
                              }
                              
                              real(4) function code(costheta_i, u1, u2)
                                  real(4), intent (in) :: costheta_i
                                  real(4), intent (in) :: u1
                                  real(4), intent (in) :: u2
                                  code = sqrt(-(-u1)) * 1.0e0
                              end function
                              
                              function code(cosTheta_i, u1, u2)
                              	return Float32(sqrt(Float32(-Float32(-u1))) * Float32(1.0))
                              end
                              
                              function tmp = code(cosTheta_i, u1, u2)
                              	tmp = sqrt(-(-u1)) * single(1.0);
                              end
                              
                              \begin{array}{l}
                              
                              \\
                              \sqrt{-\left(-u1\right)} \cdot 1
                              \end{array}
                              
                              Derivation
                              1. Initial program 55.8%

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

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

                                  \[\leadsto \sqrt{-\color{blue}{\left(\mathsf{neg}\left(u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                                2. lower-neg.f3277.7

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

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

                                \[\leadsto \sqrt{-\left(-u1\right)} \cdot \color{blue}{1} \]
                              7. Step-by-step derivation
                                1. Applied rewrites64.6%

                                  \[\leadsto \sqrt{-\left(-u1\right)} \cdot \color{blue}{1} \]
                                2. Add Preprocessing

                                Alternative 8: -0.0% accurate, 12.8× speedup?

                                \[\begin{array}{l} \\ \sqrt{-u1} \cdot 1 \end{array} \]
                                (FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- u1)) 1.0))
                                float code(float cosTheta_i, float u1, float u2) {
                                	return sqrtf(-u1) * 1.0f;
                                }
                                
                                real(4) function code(costheta_i, u1, u2)
                                    real(4), intent (in) :: costheta_i
                                    real(4), intent (in) :: u1
                                    real(4), intent (in) :: u2
                                    code = sqrt(-u1) * 1.0e0
                                end function
                                
                                function code(cosTheta_i, u1, u2)
                                	return Float32(sqrt(Float32(-u1)) * Float32(1.0))
                                end
                                
                                function tmp = code(cosTheta_i, u1, u2)
                                	tmp = sqrt(-u1) * single(1.0);
                                end
                                
                                \begin{array}{l}
                                
                                \\
                                \sqrt{-u1} \cdot 1
                                \end{array}
                                
                                Derivation
                                1. Initial program 55.8%

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

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

                                    \[\leadsto \sqrt{-\color{blue}{\left(\mathsf{neg}\left(u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
                                  2. lower-neg.f3277.7

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

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

                                  \[\leadsto \sqrt{-\left(-u1\right)} \cdot \color{blue}{1} \]
                                7. Step-by-step derivation
                                  1. Applied rewrites64.6%

                                    \[\leadsto \sqrt{-\left(-u1\right)} \cdot \color{blue}{1} \]
                                  2. Step-by-step derivation
                                    1. Applied rewrites-0.0%

                                      \[\leadsto \sqrt{-\color{blue}{u1}} \cdot 1 \]
                                    2. Add Preprocessing

                                    Reproduce

                                    ?
                                    herbie shell --seed 2024312 
                                    (FPCore (cosTheta_i u1 u2)
                                      :name "Beckmann Sample, near normal, slope_x"
                                      :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)))) (cos (* (* 2.0 (PI)) u2))))