normal distribution

Percentage Accurate: 99.4% → 99.7%
Time: 9.3s
Alternatives: 3
Speedup: 1.0×

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 \pi\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))
double code(double u1, double u2) {
	return (((1.0 / 6.0) * pow((-2.0 * log(u1)), 0.5)) * cos(((2.0 * ((double) M_PI)) * u2))) + 0.5;
}
public static double code(double u1, double u2) {
	return (((1.0 / 6.0) * Math.pow((-2.0 * Math.log(u1)), 0.5)) * Math.cos(((2.0 * Math.PI) * u2))) + 0.5;
}
def code(u1, u2):
	return (((1.0 / 6.0) * math.pow((-2.0 * math.log(u1)), 0.5)) * math.cos(((2.0 * math.pi) * u2))) + 0.5
function code(u1, u2)
	return Float64(Float64(Float64(Float64(1.0 / 6.0) * (Float64(-2.0 * log(u1)) ^ 0.5)) * cos(Float64(Float64(2.0 * pi) * u2))) + 0.5)
end
function tmp = code(u1, u2)
	tmp = (((1.0 / 6.0) * ((-2.0 * log(u1)) ^ 0.5)) * cos(((2.0 * pi) * u2))) + 0.5;
end
code[u1_, u2_] := N[(N[(N[(N[(1.0 / 6.0), $MachinePrecision] * N[Power[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(2.0 * Pi), $MachinePrecision] * u2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \cos \left(\left(2 \cdot \pi\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 3 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 \pi\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))
double code(double u1, double u2) {
	return (((1.0 / 6.0) * pow((-2.0 * log(u1)), 0.5)) * cos(((2.0 * ((double) M_PI)) * u2))) + 0.5;
}
public static double code(double u1, double u2) {
	return (((1.0 / 6.0) * Math.pow((-2.0 * Math.log(u1)), 0.5)) * Math.cos(((2.0 * Math.PI) * u2))) + 0.5;
}
def code(u1, u2):
	return (((1.0 / 6.0) * math.pow((-2.0 * math.log(u1)), 0.5)) * math.cos(((2.0 * math.pi) * u2))) + 0.5
function code(u1, u2)
	return Float64(Float64(Float64(Float64(1.0 / 6.0) * (Float64(-2.0 * log(u1)) ^ 0.5)) * cos(Float64(Float64(2.0 * pi) * u2))) + 0.5)
end
function tmp = code(u1, u2)
	tmp = (((1.0 / 6.0) * ((-2.0 * log(u1)) ^ 0.5)) * cos(((2.0 * pi) * u2))) + 0.5;
end
code[u1_, u2_] := N[(N[(N[(N[(1.0 / 6.0), $MachinePrecision] * N[Power[N[(-2.0 * N[Log[u1], $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(2.0 * Pi), $MachinePrecision] * u2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \sqrt{\log \left({u1}^{-0.05555555555555555}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \end{array} \]
(FPCore (u1 u2)
 :precision binary64
 (+
  (* (sqrt (log (pow u1 -0.05555555555555555))) (cos (* (* 2.0 PI) u2)))
  0.5))
double code(double u1, double u2) {
	return (sqrt(log(pow(u1, -0.05555555555555555))) * cos(((2.0 * ((double) M_PI)) * u2))) + 0.5;
}
public static double code(double u1, double u2) {
	return (Math.sqrt(Math.log(Math.pow(u1, -0.05555555555555555))) * Math.cos(((2.0 * Math.PI) * u2))) + 0.5;
}
def code(u1, u2):
	return (math.sqrt(math.log(math.pow(u1, -0.05555555555555555))) * math.cos(((2.0 * math.pi) * u2))) + 0.5
function code(u1, u2)
	return Float64(Float64(sqrt(log((u1 ^ -0.05555555555555555))) * cos(Float64(Float64(2.0 * pi) * u2))) + 0.5)
end
function tmp = code(u1, u2)
	tmp = (sqrt(log((u1 ^ -0.05555555555555555))) * cos(((2.0 * pi) * u2))) + 0.5;
end
code[u1_, u2_] := N[(N[(N[Sqrt[N[Log[N[Power[u1, -0.05555555555555555], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(2.0 * Pi), $MachinePrecision] * u2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\log \left({u1}^{-0.05555555555555555}\right)} \cdot \cos \left(\left(2 \cdot \pi\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 \pi\right) \cdot u2\right) + 0.5 \]
  2. Step-by-step derivation
    1. expm1-log1p-u99.1%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    2. expm1-udef99.1%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right)} - 1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    3. metadata-eval99.1%

      \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{0.16666666666666666} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right)} - 1\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    4. unpow1/299.1%

      \[\leadsto \left(e^{\mathsf{log1p}\left(0.16666666666666666 \cdot \color{blue}{\sqrt{-2 \cdot \log u1}}\right)} - 1\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  3. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(0.16666666666666666 \cdot \sqrt{-2 \cdot \log u1}\right)} - 1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  4. Step-by-step derivation
    1. expm1-def99.1%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.16666666666666666 \cdot \sqrt{-2 \cdot \log u1}\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    2. expm1-log1p99.3%

      \[\leadsto \color{blue}{\left(0.16666666666666666 \cdot \sqrt{-2 \cdot \log u1}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    3. *-commutative99.3%

      \[\leadsto \left(0.16666666666666666 \cdot \sqrt{\color{blue}{\log u1 \cdot -2}}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  5. Simplified99.3%

    \[\leadsto \color{blue}{\left(0.16666666666666666 \cdot \sqrt{\log u1 \cdot -2}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  6. Step-by-step derivation
    1. *-commutative99.3%

      \[\leadsto \left(0.16666666666666666 \cdot \sqrt{\color{blue}{-2 \cdot \log u1}}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    2. rem-cbrt-cube99.1%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(0.16666666666666666 \cdot \sqrt{-2 \cdot \log u1}\right)}^{3}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    3. unpow1/398.8%

      \[\leadsto \color{blue}{{\left({\left(0.16666666666666666 \cdot \sqrt{-2 \cdot \log u1}\right)}^{3}\right)}^{0.3333333333333333}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  7. Applied egg-rr44.1%

    \[\leadsto \color{blue}{{\left({\left(\log \left({u1}^{-2}\right) \cdot 0.027777777777777776\right)}^{1.5}\right)}^{0.3333333333333333}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  8. Step-by-step derivation
    1. unpow1/344.1%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\log \left({u1}^{-2}\right) \cdot 0.027777777777777776\right)}^{1.5}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    2. *-commutative44.1%

      \[\leadsto \sqrt[3]{{\color{blue}{\left(0.027777777777777776 \cdot \log \left({u1}^{-2}\right)\right)}}^{1.5}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    3. log-pow99.2%

      \[\leadsto \sqrt[3]{{\left(0.027777777777777776 \cdot \color{blue}{\left(-2 \cdot \log u1\right)}\right)}^{1.5}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    4. associate-*r*99.2%

      \[\leadsto \sqrt[3]{{\color{blue}{\left(\left(0.027777777777777776 \cdot -2\right) \cdot \log u1\right)}}^{1.5}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    5. metadata-eval99.2%

      \[\leadsto \sqrt[3]{{\left(\color{blue}{-0.05555555555555555} \cdot \log u1\right)}^{1.5}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  9. Simplified99.2%

    \[\leadsto \color{blue}{\sqrt[3]{{\left(-0.05555555555555555 \cdot \log u1\right)}^{1.5}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  10. Step-by-step derivation
    1. add-sqr-sqrt98.9%

      \[\leadsto \color{blue}{\left(\sqrt{\sqrt[3]{{\left(-0.05555555555555555 \cdot \log u1\right)}^{1.5}}} \cdot \sqrt{\sqrt[3]{{\left(-0.05555555555555555 \cdot \log u1\right)}^{1.5}}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    2. sqrt-prod99.2%

      \[\leadsto \color{blue}{\sqrt{\sqrt[3]{{\left(-0.05555555555555555 \cdot \log u1\right)}^{1.5}} \cdot \sqrt[3]{{\left(-0.05555555555555555 \cdot \log u1\right)}^{1.5}}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    3. cbrt-unprod99.5%

      \[\leadsto \sqrt{\color{blue}{\sqrt[3]{{\left(-0.05555555555555555 \cdot \log u1\right)}^{1.5} \cdot {\left(-0.05555555555555555 \cdot \log u1\right)}^{1.5}}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    4. pow-prod-up99.5%

      \[\leadsto \sqrt{\sqrt[3]{\color{blue}{{\left(-0.05555555555555555 \cdot \log u1\right)}^{\left(1.5 + 1.5\right)}}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    5. metadata-eval99.5%

      \[\leadsto \sqrt{\sqrt[3]{{\left(-0.05555555555555555 \cdot \log u1\right)}^{\color{blue}{3}}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    6. pow399.5%

      \[\leadsto \sqrt{\sqrt[3]{\color{blue}{\left(\left(-0.05555555555555555 \cdot \log u1\right) \cdot \left(-0.05555555555555555 \cdot \log u1\right)\right) \cdot \left(-0.05555555555555555 \cdot \log u1\right)}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    7. add-cbrt-cube99.6%

      \[\leadsto \sqrt{\color{blue}{-0.05555555555555555 \cdot \log u1}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    8. add-log-exp99.6%

      \[\leadsto \sqrt{\color{blue}{\log \left(e^{-0.05555555555555555 \cdot \log u1}\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    9. *-commutative99.6%

      \[\leadsto \sqrt{\log \left(e^{\color{blue}{\log u1 \cdot -0.05555555555555555}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    10. exp-to-pow99.6%

      \[\leadsto \sqrt{\log \color{blue}{\left({u1}^{-0.05555555555555555}\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  11. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\sqrt{\log \left({u1}^{-0.05555555555555555}\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  12. Final simplification99.6%

    \[\leadsto \sqrt{\log \left({u1}^{-0.05555555555555555}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]

Alternative 2: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 0.5 + \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \sqrt{-0.05555555555555555 \cdot \log u1} \end{array} \]
(FPCore (u1 u2)
 :precision binary64
 (+ 0.5 (* (cos (* (* 2.0 PI) u2)) (sqrt (* -0.05555555555555555 (log u1))))))
double code(double u1, double u2) {
	return 0.5 + (cos(((2.0 * ((double) M_PI)) * u2)) * sqrt((-0.05555555555555555 * log(u1))));
}
public static double code(double u1, double u2) {
	return 0.5 + (Math.cos(((2.0 * Math.PI) * u2)) * Math.sqrt((-0.05555555555555555 * Math.log(u1))));
}
def code(u1, u2):
	return 0.5 + (math.cos(((2.0 * math.pi) * u2)) * math.sqrt((-0.05555555555555555 * math.log(u1))))
function code(u1, u2)
	return Float64(0.5 + Float64(cos(Float64(Float64(2.0 * pi) * u2)) * sqrt(Float64(-0.05555555555555555 * log(u1)))))
end
function tmp = code(u1, u2)
	tmp = 0.5 + (cos(((2.0 * pi) * u2)) * sqrt((-0.05555555555555555 * log(u1))));
end
code[u1_, u2_] := N[(0.5 + N[(N[Cos[N[(N[(2.0 * Pi), $MachinePrecision] * u2), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-0.05555555555555555 * N[Log[u1], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 + \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \sqrt{-0.05555555555555555 \cdot \log u1}
\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 \pi\right) \cdot u2\right) + 0.5 \]
  2. Step-by-step derivation
    1. add-sqr-sqrt99.0%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}} \cdot \sqrt{\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    2. sqrt-unprod99.3%

      \[\leadsto \color{blue}{\sqrt{\left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    3. *-commutative99.3%

      \[\leadsto \sqrt{\color{blue}{\left({\left(-2 \cdot \log u1\right)}^{0.5} \cdot \frac{1}{6}\right)} \cdot \left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    4. *-commutative99.3%

      \[\leadsto \sqrt{\left({\left(-2 \cdot \log u1\right)}^{0.5} \cdot \frac{1}{6}\right) \cdot \color{blue}{\left({\left(-2 \cdot \log u1\right)}^{0.5} \cdot \frac{1}{6}\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    5. swap-sqr99.4%

      \[\leadsto \sqrt{\color{blue}{\left({\left(-2 \cdot \log u1\right)}^{0.5} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \left(\frac{1}{6} \cdot \frac{1}{6}\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    6. unpow1/299.4%

      \[\leadsto \sqrt{\left(\color{blue}{\sqrt{-2 \cdot \log u1}} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right) \cdot \left(\frac{1}{6} \cdot \frac{1}{6}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    7. unpow1/299.4%

      \[\leadsto \sqrt{\left(\sqrt{-2 \cdot \log u1} \cdot \color{blue}{\sqrt{-2 \cdot \log u1}}\right) \cdot \left(\frac{1}{6} \cdot \frac{1}{6}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    8. add-sqr-sqrt99.6%

      \[\leadsto \sqrt{\color{blue}{\left(-2 \cdot \log u1\right)} \cdot \left(\frac{1}{6} \cdot \frac{1}{6}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    9. metadata-eval99.6%

      \[\leadsto \sqrt{\left(-2 \cdot \log u1\right) \cdot \left(\color{blue}{0.16666666666666666} \cdot \frac{1}{6}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    10. metadata-eval99.6%

      \[\leadsto \sqrt{\left(-2 \cdot \log u1\right) \cdot \left(0.16666666666666666 \cdot \color{blue}{0.16666666666666666}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    11. metadata-eval99.6%

      \[\leadsto \sqrt{\left(-2 \cdot \log u1\right) \cdot \color{blue}{0.027777777777777776}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  3. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\sqrt{\left(-2 \cdot \log u1\right) \cdot 0.027777777777777776}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  4. Step-by-step derivation
    1. *-commutative99.6%

      \[\leadsto \sqrt{\color{blue}{\left(\log u1 \cdot -2\right)} \cdot 0.027777777777777776} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    2. associate-*l*99.6%

      \[\leadsto \sqrt{\color{blue}{\log u1 \cdot \left(-2 \cdot 0.027777777777777776\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
    3. metadata-eval99.6%

      \[\leadsto \sqrt{\log u1 \cdot \color{blue}{-0.05555555555555555}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  5. Simplified99.6%

    \[\leadsto \color{blue}{\sqrt{\log u1 \cdot -0.05555555555555555}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  6. Final simplification99.6%

    \[\leadsto 0.5 + \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \sqrt{-0.05555555555555555 \cdot \log u1} \]

Alternative 3: 98.0% accurate, 1.4× speedup?

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

\\
\mathsf{fma}\left(0.16666666666666666, \sqrt{\log u1 \cdot -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 \pi\right) \cdot u2\right) + 0.5 \]
  2. Step-by-step derivation
    1. *-commutative99.3%

      \[\leadsto \color{blue}{\cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \left(\frac{1}{6} \cdot {\left(-2 \cdot \log u1\right)}^{0.5}\right)} + 0.5 \]
    2. associate-*r*99.3%

      \[\leadsto \color{blue}{\left(\cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \frac{1}{6}\right) \cdot {\left(-2 \cdot \log u1\right)}^{0.5}} + 0.5 \]
    3. fma-def99.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \frac{1}{6}, {\left(-2 \cdot \log u1\right)}^{0.5}, 0.5\right)} \]
    4. associate-*l*99.3%

      \[\leadsto \mathsf{fma}\left(\cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \cdot \frac{1}{6}, {\left(-2 \cdot \log u1\right)}^{0.5}, 0.5\right) \]
    5. metadata-eval99.3%

      \[\leadsto \mathsf{fma}\left(\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \color{blue}{0.16666666666666666}, {\left(-2 \cdot \log u1\right)}^{0.5}, 0.5\right) \]
    6. unpow1/299.3%

      \[\leadsto \mathsf{fma}\left(\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot 0.16666666666666666, \color{blue}{\sqrt{-2 \cdot \log u1}}, 0.5\right) \]
  3. Applied egg-rr99.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot 0.16666666666666666, \sqrt{-2 \cdot \log u1}, 0.5\right)} \]
  4. Taylor expanded in u2 around 0 97.9%

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

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

Reproduce

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