Beckmann Sample, near normal, slope_x

Percentage Accurate: 57.5% → 91.4%
Time: 8.6s
Alternatives: 6
Speedup: 14.4×

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 6 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.5% 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: 91.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\ t_1 := -\log \left(1 - u1\right)\\ \mathbf{if}\;t\_1 \leq 0.0001500000071246177:\\ \;\;\;\;\sqrt{\frac{\left(\left(\left(-u1\right) - 1\right) \cdot u1\right) \cdot u1}{-u1}} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{t\_1} \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (cos (* (* 2.0 (PI)) u2))) (t_1 (- (log (- 1.0 u1)))))
   (if (<= t_1 0.0001500000071246177)
     (* (sqrt (/ (* (* (- (- u1) 1.0) u1) u1) (- u1))) t_0)
     (* (sqrt t_1) t_0))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
t_1 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_1 \leq 0.0001500000071246177:\\
\;\;\;\;\sqrt{\frac{\left(\left(\left(-u1\right) - 1\right) \cdot u1\right) \cdot u1}{-u1}} \cdot t\_0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot t\_0\\


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

    1. Initial program 33.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.f3294.0

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

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

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

        \[\leadsto \sqrt{\color{blue}{0 - \left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      3. flip--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\frac{\left(\left(\color{blue}{\left(-u1\right)} - 1\right) \cdot u1\right) \cdot u1}{0 + \left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    10. Applied rewrites94.0%

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

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

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

        \[\leadsto \sqrt{\frac{\left(\left(\left(-u1\right) - 1\right) \cdot u1\right) \cdot u1}{\color{blue}{-u1}}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    13. Applied rewrites94.0%

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

    if 1.50000007e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))

    1. Initial program 90.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. Recombined 2 regimes into one program.
  4. Final simplification92.7%

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

Alternative 2: 85.5% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0 \leq 0.017999999225139618:\\
\;\;\;\;\sqrt{\frac{\left(\left(\left(-u1\right) - 1\right) \cdot u1\right) \cdot u1}{-u1}} \cdot t\_0\\

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


\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.0179999992

    1. Initial program 36.6%

      \[\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.f3292.0

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

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

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

        \[\leadsto \sqrt{\color{blue}{0 - \left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      3. flip--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0179999992 < (*.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 91.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. Step-by-step derivation
      1. lift-neg.f32N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\log \left({\left(1 - u1\right)}^{\frac{-1}{2}}\right) + \log \color{blue}{\left({\left(1 - u1\right)}^{\left(\frac{-1}{2}\right)}\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      13. metadata-eval86.7

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

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

      \[\leadsto \color{blue}{\sqrt{\log \left(\sqrt{\frac{1}{1 - u1}}\right)} \cdot \sqrt{2}} \]
    6. Step-by-step derivation
      1. lower-*.f32N/A

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

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

        \[\leadsto \sqrt{\color{blue}{\log \left(\sqrt{\frac{1}{1 - u1}}\right)}} \cdot \sqrt{2} \]
      4. lower-sqrt.f32N/A

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

        \[\leadsto \sqrt{\log \left(\sqrt{\color{blue}{\frac{1}{1 - u1}}}\right)} \cdot \sqrt{2} \]
      6. lower--.f32N/A

        \[\leadsto \sqrt{\log \left(\sqrt{\frac{1}{\color{blue}{1 - u1}}}\right)} \cdot \sqrt{2} \]
      7. lower-sqrt.f3275.8

        \[\leadsto \sqrt{\log \left(\sqrt{\frac{1}{1 - u1}}\right)} \cdot \color{blue}{\sqrt{2}} \]
    7. Applied rewrites75.8%

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

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

Alternative 3: 85.5% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0 \leq 0.017999999225139618:\\
\;\;\;\;\sqrt{\frac{\left(-u1\right) \cdot u1}{-u1}} \cdot t\_0\\

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


\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.0179999992

    1. Initial program 36.6%

      \[\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.f3292.0

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

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

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

        \[\leadsto \sqrt{\color{blue}{0 - \left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      3. flip--N/A

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{\color{blue}{-1 \cdot {u1}^{2}}}{0 + \left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    9. Step-by-step derivation
      1. unpow2N/A

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

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

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

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

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

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

    if 0.0179999992 < (*.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 91.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. Step-by-step derivation
      1. lift-neg.f32N/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\log \left({\left(1 - u1\right)}^{\frac{-1}{2}}\right) + \log \color{blue}{\left({\left(1 - u1\right)}^{\left(\frac{-1}{2}\right)}\right)}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
      13. metadata-eval86.7

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

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

      \[\leadsto \color{blue}{\sqrt{\log \left(\sqrt{\frac{1}{1 - u1}}\right)} \cdot \sqrt{2}} \]
    6. Step-by-step derivation
      1. lower-*.f32N/A

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

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

        \[\leadsto \sqrt{\color{blue}{\log \left(\sqrt{\frac{1}{1 - u1}}\right)}} \cdot \sqrt{2} \]
      4. lower-sqrt.f32N/A

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

        \[\leadsto \sqrt{\log \left(\sqrt{\color{blue}{\frac{1}{1 - u1}}}\right)} \cdot \sqrt{2} \]
      6. lower--.f32N/A

        \[\leadsto \sqrt{\log \left(\sqrt{\frac{1}{\color{blue}{1 - u1}}}\right)} \cdot \sqrt{2} \]
      7. lower-sqrt.f3275.8

        \[\leadsto \sqrt{\log \left(\sqrt{\frac{1}{1 - u1}}\right)} \cdot \color{blue}{\sqrt{2}} \]
    7. Applied rewrites75.8%

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

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

Alternative 4: 65.7% accurate, 1.6× speedup?

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

\\
\sqrt{\mathsf{fma}\left(-0.5, u1, 1\right) \cdot u1 - \left(-u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Derivation
  1. Initial program 54.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. Applied rewrites49.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(1 + \frac{-1}{2} \cdot u1\right) \cdot u1} - \left(-u1\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(1 + \frac{-1}{2} \cdot u1\right) \cdot u1} - \left(-u1\right) \cdot u1} \cdot \cos \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 - \left(-u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
    4. lower-fma.f3261.0

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

    \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(-0.5, u1, 1\right) \cdot u1} - \left(-u1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \]
  10. Add Preprocessing

Alternative 5: 76.4% accurate, 1.8× speedup?

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

\\
\cos \left(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot 2\right) \cdot \sqrt{u1}
\end{array}
Derivation
  1. Initial program 54.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. Applied rewrites48.6%

    \[\leadsto \sqrt{\color{blue}{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)}} \cdot \cos \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 \cos \left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right)} \]
  5. Step-by-step derivation
    1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

Alternative 6: 64.7% accurate, 14.4× 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(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 54.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. Applied rewrites46.6%

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

    \[\leadsto e^{\log \left(\mathsf{log1p}\left(u1\right)\right) \cdot \frac{1}{2}} \cdot \color{blue}{1} \]
  5. Step-by-step derivation
    1. Applied rewrites8.3%

      \[\leadsto e^{\log \left(\mathsf{log1p}\left(u1\right)\right) \cdot 0.5} \cdot \color{blue}{1} \]
    2. Taylor expanded in u1 around 0

      \[\leadsto \color{blue}{\sqrt{u1}} \cdot 1 \]
    3. Step-by-step derivation
      1. lower-sqrt.f3266.5

        \[\leadsto \color{blue}{\sqrt{u1}} \cdot 1 \]
    4. Applied rewrites66.5%

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

    Reproduce

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