normal distribution

Percentage Accurate: 99.4% → 99.5%
Time: 9.0s
Alternatives: 6
Speedup: 1.4×

Specification

?
\[\left(0 \leq u1 \land u1 \leq 1\right) \land \left(0 \leq u2 \land u2 \leq 1\right)\]
\[\begin{array}{l} \\ \left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \end{array} \]
(FPCore (u1 u2)
 :precision binary64
 (+
  (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 (PI)) u2)))
  0.5))
\begin{array}{l}

\\
\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5
\end{array}

Sampling outcomes in binary64 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: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \end{array} \]
(FPCore (u1 u2)
 :precision binary64
 (+
  (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 (PI)) u2)))
  0.5))
\begin{array}{l}

\\
\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5
\end{array}

Alternative 1: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left({6}^{-1} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \end{array} \]
(FPCore (u1 u2)
 :precision binary64
 (+
  (*
   (* (pow 6.0 -1.0) (* (sqrt 2.0) (sqrt (- (log u1)))))
   (cos (* (* 2.0 (PI)) u2)))
  0.5))
\begin{array}{l}

\\
\left({6}^{-1} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5
\end{array}
Derivation
  1. Initial program 99.3%

    \[\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \]
  2. Add Preprocessing
  3. Taylor expanded in u1 around inf

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

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

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

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

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

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

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

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

    \[\leadsto \left(\frac{1}{6} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{-\log u1}\right)}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \]
  6. Final simplification99.4%

    \[\leadsto \left({6}^{-1} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \]
  7. Add Preprocessing

Alternative 2: 98.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \left({6}^{-1} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2, u2 \cdot u2, 1\right) + 0.5 \end{array} \]
(FPCore (u1 u2)
 :precision binary64
 (+
  (*
   (* (pow 6.0 -1.0) (* (sqrt 2.0) (sqrt (- (log u1)))))
   (fma (* (* (PI) (PI)) -2.0) (* u2 u2) 1.0))
  0.5))
\begin{array}{l}

\\
\left({6}^{-1} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2, u2 \cdot u2, 1\right) + 0.5
\end{array}
Derivation
  1. Initial program 99.3%

    \[\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \]
  2. Add Preprocessing
  3. Taylor expanded in u1 around inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \color{blue}{\mathsf{fma}\left(-2 \cdot {\mathsf{PI}\left(\right)}^{2}, {u2}^{2}, 1\right)} + \frac{1}{2} \]
  8. Applied rewrites98.9%

    \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \color{blue}{\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2, u2 \cdot u2, 1\right)} + 0.5 \]
  9. Final simplification98.9%

    \[\leadsto \left({6}^{-1} \cdot \left(\sqrt{2} \cdot \sqrt{-\log u1}\right)\right) \cdot \mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2, u2 \cdot u2, 1\right) + 0.5 \]
  10. Add Preprocessing

Alternative 3: 99.4% accurate, 1.4× speedup?

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

\\
\mathsf{fma}\left(\cos \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \sqrt{\log u1 \cdot -2}, 0.16666666666666666, 0.5\right)
\end{array}
Derivation
  1. Initial program 99.3%

    \[\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + 0.5 \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(-2 \cdot \log u1\right)}^{\frac{1}{2}} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right), \frac{1}{6}, \frac{1}{2}\right)} \]
  4. Applied rewrites99.3%

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

Alternative 4: 98.2% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\sqrt{-\log u1} \cdot 0.16666666666666666, \sqrt{2}, 0.5\right) \end{array} \]
(FPCore (u1 u2)
 :precision binary64
 (fma (* (sqrt (- (log u1))) 0.16666666666666666) (sqrt 2.0) 0.5))
double code(double u1, double u2) {
	return fma((sqrt(-log(u1)) * 0.16666666666666666), sqrt(2.0), 0.5);
}
function code(u1, u2)
	return fma(Float64(sqrt(Float64(-log(u1))) * 0.16666666666666666), sqrt(2.0), 0.5)
end
code[u1_, u2_] := N[(N[(N[Sqrt[(-N[Log[u1], $MachinePrecision])], $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\sqrt{-\log u1} \cdot 0.16666666666666666, \sqrt{2}, 0.5\right)
\end{array}
Derivation
  1. Initial program 99.3%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{6} \cdot \sqrt{-2}, \sqrt{\log u1}, \frac{1}{2}\right)} \]
    5. lower-*.f64N/A

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{6} \cdot \sqrt{-2}, \color{blue}{\sqrt{\log u1}}, \frac{1}{2}\right) \]
    8. lower-log.f640.0

      \[\leadsto \mathsf{fma}\left(0.16666666666666666 \cdot \sqrt{-2}, \sqrt{\color{blue}{\log u1}}, 0.5\right) \]
  5. Applied rewrites0.0%

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

      \[\leadsto \mathsf{fma}\left({\left(\log u1 \cdot -2\right)}^{0.25}, \color{blue}{{\left(\log u1 \cdot -2\right)}^{0.25} \cdot 0.16666666666666666}, 0.5\right) \]
    2. Taylor expanded in u1 around inf

      \[\leadsto \frac{1}{2} + \color{blue}{\frac{1}{6} \cdot \left(\sqrt{\log \left(\frac{1}{u1}\right)} \cdot \sqrt{2}\right)} \]
    3. Step-by-step derivation
      1. Applied rewrites98.5%

        \[\leadsto \mathsf{fma}\left(\sqrt{2} \cdot 0.16666666666666666, \color{blue}{\sqrt{-\log u1}}, 0.5\right) \]
      2. Step-by-step derivation
        1. Applied rewrites98.5%

          \[\leadsto \mathsf{fma}\left(\sqrt{-\log u1} \cdot 0.16666666666666666, \sqrt{2}, 0.5\right) \]
        2. Add Preprocessing

        Alternative 5: 98.4% accurate, 2.5× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(\sqrt{2} \cdot 0.16666666666666666, \sqrt{-\log u1}, 0.5\right) \end{array} \]
        (FPCore (u1 u2)
         :precision binary64
         (fma (* (sqrt 2.0) 0.16666666666666666) (sqrt (- (log u1))) 0.5))
        double code(double u1, double u2) {
        	return fma((sqrt(2.0) * 0.16666666666666666), sqrt(-log(u1)), 0.5);
        }
        
        function code(u1, u2)
        	return fma(Float64(sqrt(2.0) * 0.16666666666666666), sqrt(Float64(-log(u1))), 0.5)
        end
        
        code[u1_, u2_] := N[(N[(N[Sqrt[2.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * N[Sqrt[(-N[Log[u1], $MachinePrecision])], $MachinePrecision] + 0.5), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \mathsf{fma}\left(\sqrt{2} \cdot 0.16666666666666666, \sqrt{-\log u1}, 0.5\right)
        \end{array}
        
        Derivation
        1. Initial program 99.3%

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{6} \cdot \sqrt{-2}, \sqrt{\log u1}, \frac{1}{2}\right)} \]
          5. lower-*.f64N/A

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

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

            \[\leadsto \mathsf{fma}\left(\frac{1}{6} \cdot \sqrt{-2}, \color{blue}{\sqrt{\log u1}}, \frac{1}{2}\right) \]
          8. lower-log.f640.0

            \[\leadsto \mathsf{fma}\left(0.16666666666666666 \cdot \sqrt{-2}, \sqrt{\color{blue}{\log u1}}, 0.5\right) \]
        5. Applied rewrites0.0%

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

            \[\leadsto \mathsf{fma}\left({\left(\log u1 \cdot -2\right)}^{0.25}, \color{blue}{{\left(\log u1 \cdot -2\right)}^{0.25} \cdot 0.16666666666666666}, 0.5\right) \]
          2. Taylor expanded in u1 around inf

            \[\leadsto \frac{1}{2} + \color{blue}{\frac{1}{6} \cdot \left(\sqrt{\log \left(\frac{1}{u1}\right)} \cdot \sqrt{2}\right)} \]
          3. Step-by-step derivation
            1. Applied rewrites98.5%

              \[\leadsto \mathsf{fma}\left(\sqrt{2} \cdot 0.16666666666666666, \color{blue}{\sqrt{-\log u1}}, 0.5\right) \]
            2. Add Preprocessing

            Alternative 6: 98.2% accurate, 2.8× speedup?

            \[\begin{array}{l} \\ \mathsf{fma}\left(\sqrt{\log u1 \cdot -2}, 0.16666666666666666, 0.5\right) \end{array} \]
            (FPCore (u1 u2)
             :precision binary64
             (fma (sqrt (* (log u1) -2.0)) 0.16666666666666666 0.5))
            double code(double u1, double u2) {
            	return fma(sqrt((log(u1) * -2.0)), 0.16666666666666666, 0.5);
            }
            
            function code(u1, u2)
            	return fma(sqrt(Float64(log(u1) * -2.0)), 0.16666666666666666, 0.5)
            end
            
            code[u1_, u2_] := N[(N[Sqrt[N[(N[Log[u1], $MachinePrecision] * -2.0), $MachinePrecision]], $MachinePrecision] * 0.16666666666666666 + 0.5), $MachinePrecision]
            
            \begin{array}{l}
            
            \\
            \mathsf{fma}\left(\sqrt{\log u1 \cdot -2}, 0.16666666666666666, 0.5\right)
            \end{array}
            
            Derivation
            1. Initial program 99.3%

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

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

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

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

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{6} \cdot \sqrt{-2}, \sqrt{\log u1}, \frac{1}{2}\right)} \]
              5. lower-*.f64N/A

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

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

                \[\leadsto \mathsf{fma}\left(\frac{1}{6} \cdot \sqrt{-2}, \color{blue}{\sqrt{\log u1}}, \frac{1}{2}\right) \]
              8. lower-log.f640.0

                \[\leadsto \mathsf{fma}\left(0.16666666666666666 \cdot \sqrt{-2}, \sqrt{\color{blue}{\log u1}}, 0.5\right) \]
            5. Applied rewrites0.0%

              \[\leadsto \color{blue}{\mathsf{fma}\left(0.16666666666666666 \cdot \sqrt{-2}, \sqrt{\log u1}, 0.5\right)} \]
            6. Step-by-step derivation
              1. Applied rewrites98.3%

                \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\log u1 \cdot -2}, 0.16666666666666666, 0.5\right)} \]
              2. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 2024314 
              (FPCore (u1 u2)
                :name "normal distribution"
                :precision binary64
                :pre (and (and (<= 0.0 u1) (<= u1 1.0)) (and (<= 0.0 u2) (<= u2 1.0)))
                (+ (* (* (/ 1.0 6.0) (pow (* -2.0 (log u1)) 0.5)) (cos (* (* 2.0 (PI)) u2))) 0.5))