normal distribution

Percentage Accurate: 99.4% → 99.6%
Time: 13.7s
Alternatives: 8
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 \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 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: 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.6% accurate, 1.4× speedup?

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

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

    \[\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. Add Preprocessing
  3. Step-by-step derivation
    1. pow-to-expN/A

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

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

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

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

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

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

      \[\leadsto \left(\frac{1}{6} \cdot {\left(e^{\frac{1}{2}}\right)}^{\log \color{blue}{\left(-2 \cdot \log u1\right)}}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + \frac{1}{2} \]
    8. log-lowering-log.f6498.9

      \[\leadsto \left(\frac{1}{6} \cdot {\left(e^{0.5}\right)}^{\log \left(-2 \cdot \color{blue}{\log u1}\right)}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  4. Applied egg-rr98.9%

    \[\leadsto \left(\frac{1}{6} \cdot \color{blue}{{\left(e^{0.5}\right)}^{\log \left(-2 \cdot \log u1\right)}}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  5. Taylor expanded in u1 around inf

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\log \left(\frac{1}{u1}\right)}, \frac{1}{6} \cdot \left(\cos \left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{2}\right), \frac{1}{2}\right)} \]
  7. Simplified99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{0 - \log u1}, \left(0.16666666666666666 \cdot \sqrt{2}\right) \cdot \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right), 0.5\right)} \]
  8. Step-by-step derivation
    1. sub0-negN/A

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{\mathsf{neg}\left(\log u1\right)}}, \left(\frac{1}{6} \cdot \sqrt{2}\right) \cdot \cos \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \frac{1}{2}\right) \]
    3. log-lowering-log.f6499.6

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

    \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{-\log u1}}, \left(0.16666666666666666 \cdot \sqrt{2}\right) \cdot \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right), 0.5\right) \]
  10. Final simplification99.6%

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

Alternative 2: 99.4% accurate, 1.4× speedup?

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

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

    \[\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. Add Preprocessing
  3. Step-by-step derivation
    1. 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} \]
    2. *-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} \]
    3. accelerator-lowering-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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\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) \]
    5. unpow1/2N/A

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{-2 \cdot \log u1} \cdot \cos \left(2 \cdot \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot u2\right)\right), \frac{1}{6}, \frac{1}{2}\right) \]
    14. metadata-eval99.5

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

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

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

Alternative 3: 99.4% accurate, 1.4× speedup?

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

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

    \[\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. Add Preprocessing
  3. Step-by-step derivation
    1. accelerator-lowering-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{-2 \cdot \log u1} \cdot \frac{1}{6}, \cos \left(2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot u2\right)}\right), \frac{1}{2}\right) \]
    13. PI-lowering-PI.f6499.5

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

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

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

Alternative 4: 99.0% accurate, 2.1× speedup?

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

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

    \[\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. 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. *-lowering-*.f64N/A

      \[\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} \]
    2. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \left(\frac{1}{6} \cdot \left(\color{blue}{\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} \]
    3. log-recN/A

      \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{\color{blue}{\mathsf{neg}\left(\log 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. neg-sub0N/A

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

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

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

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

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

    \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{0 - \log u1} \cdot \sqrt{2}\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{0 - \log u1} \cdot \sqrt{2}\right)\right) \cdot \color{blue}{\left(-2 \cdot \left({u2}^{2} \cdot {\mathsf{PI}\left(\right)}^{2}\right) + 1\right)} + \frac{1}{2} \]
    2. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{0 - \log u1} \cdot \sqrt{2}\right)\right) \cdot \color{blue}{\mathsf{fma}\left(u2, u2 \cdot \left(\left(\pi \cdot \pi\right) \cdot -2\right), 1\right)} + 0.5 \]
  9. Step-by-step derivation
    1. flip--N/A

      \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{\color{blue}{\frac{0 \cdot 0 - \log u1 \cdot \log u1}{0 + \log u1}}} \cdot \sqrt{2}\right)\right) \cdot \mathsf{fma}\left(u2, u2 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right), 1\right) + \frac{1}{2} \]
    2. clear-numN/A

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

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

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

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

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

      \[\leadsto \left(\frac{1}{6} \cdot \left(\frac{1}{\sqrt{\frac{\color{blue}{\log u1}}{0 \cdot 0 - \log u1 \cdot \log u1}}} \cdot \sqrt{2}\right)\right) \cdot \mathsf{fma}\left(u2, u2 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right), 1\right) + \frac{1}{2} \]
    8. clear-numN/A

      \[\leadsto \left(\frac{1}{6} \cdot \left(\frac{1}{\sqrt{\color{blue}{\frac{1}{\frac{0 \cdot 0 - \log u1 \cdot \log u1}{\log u1}}}}} \cdot \sqrt{2}\right)\right) \cdot \mathsf{fma}\left(u2, u2 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right), 1\right) + \frac{1}{2} \]
    9. +-lft-identityN/A

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

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

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

      \[\leadsto \left(\frac{1}{6} \cdot \left(\frac{1}{\sqrt{\frac{1}{\color{blue}{0 - \log u1}}}} \cdot \sqrt{2}\right)\right) \cdot \mathsf{fma}\left(u2, u2 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right), 1\right) + \frac{1}{2} \]
    13. log-lowering-log.f6498.3

      \[\leadsto \left(\frac{1}{6} \cdot \left(\frac{1}{\sqrt{\frac{1}{0 - \color{blue}{\log u1}}}} \cdot \sqrt{2}\right)\right) \cdot \mathsf{fma}\left(u2, u2 \cdot \left(\left(\pi \cdot \pi\right) \cdot -2\right), 1\right) + 0.5 \]
  10. Applied egg-rr98.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{0 - \log u1} \cdot \color{blue}{\left(\left(\sqrt{2} \cdot \left(1 + -2 \cdot \left({u2}^{2} \cdot {\mathsf{PI}\left(\right)}^{2}\right)\right)\right) \cdot \frac{1}{6}\right)} + \frac{1}{2} \]
  13. Simplified98.5%

    \[\leadsto \color{blue}{\sqrt{0 - \log u1} \cdot \left(\left(\sqrt{2} \cdot \mathsf{fma}\left(\pi \cdot \pi, \left(u2 \cdot u2\right) \cdot -2, 1\right)\right) \cdot 0.16666666666666666\right)} + 0.5 \]
  14. Final simplification98.5%

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

Alternative 5: 99.0% accurate, 2.2× speedup?

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

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

    \[\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. Add Preprocessing
  3. Step-by-step derivation
    1. pow-to-expN/A

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

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

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

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

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

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

      \[\leadsto \left(\frac{1}{6} \cdot {\left(e^{\frac{1}{2}}\right)}^{\log \color{blue}{\left(-2 \cdot \log u1\right)}}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + \frac{1}{2} \]
    8. log-lowering-log.f6498.9

      \[\leadsto \left(\frac{1}{6} \cdot {\left(e^{0.5}\right)}^{\log \left(-2 \cdot \color{blue}{\log u1}\right)}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  4. Applied egg-rr98.9%

    \[\leadsto \left(\frac{1}{6} \cdot \color{blue}{{\left(e^{0.5}\right)}^{\log \left(-2 \cdot \log u1\right)}}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  5. Taylor expanded in u1 around inf

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\log \left(\frac{1}{u1}\right)}, \frac{1}{6} \cdot \left(\cos \left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{2}\right), \frac{1}{2}\right)} \]
  7. Simplified99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{0 - \log u1}, \left(0.16666666666666666 \cdot \sqrt{2}\right) \cdot \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right), 0.5\right)} \]
  8. Step-by-step derivation
    1. sub0-negN/A

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{\mathsf{neg}\left(\log u1\right)}}, \left(\frac{1}{6} \cdot \sqrt{2}\right) \cdot \cos \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \frac{1}{2}\right) \]
    3. log-lowering-log.f6499.6

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

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

    \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \color{blue}{\frac{-1}{3} \cdot \left({u2}^{2} \cdot \left({\mathsf{PI}\left(\right)}^{2} \cdot \sqrt{2}\right)\right) + \frac{1}{6} \cdot \sqrt{2}}, \frac{1}{2}\right) \]
  11. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \sqrt{2} \cdot \color{blue}{\left(\frac{1}{6} + \frac{-1}{3} \cdot \left({u2}^{2} \cdot {\mathsf{PI}\left(\right)}^{2}\right)\right)}, \frac{1}{2}\right) \]
    5. *-lowering-*.f64N/A

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \sqrt{2} \cdot \color{blue}{\left(\frac{-1}{3} \cdot \left({u2}^{2} \cdot {\mathsf{PI}\left(\right)}^{2}\right) + \frac{1}{6}\right)}, \frac{1}{2}\right) \]
    8. accelerator-lowering-fma.f64N/A

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \sqrt{2} \cdot \mathsf{fma}\left(\frac{-1}{3}, \color{blue}{\left(u2 \cdot u2\right)} \cdot {\mathsf{PI}\left(\right)}^{2}, \frac{1}{6}\right), \frac{1}{2}\right) \]
    10. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \sqrt{2} \cdot \mathsf{fma}\left(\frac{-1}{3}, \color{blue}{u2 \cdot \left(u2 \cdot {\mathsf{PI}\left(\right)}^{2}\right)}, \frac{1}{6}\right), \frac{1}{2}\right) \]
    11. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \sqrt{2} \cdot \mathsf{fma}\left(\frac{-1}{3}, \color{blue}{u2 \cdot \left(u2 \cdot {\mathsf{PI}\left(\right)}^{2}\right)}, \frac{1}{6}\right), \frac{1}{2}\right) \]
    12. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \sqrt{2} \cdot \mathsf{fma}\left(\frac{-1}{3}, u2 \cdot \left(u2 \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}\right), \frac{1}{6}\right), \frac{1}{2}\right) \]
    14. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \sqrt{2} \cdot \mathsf{fma}\left(\frac{-1}{3}, u2 \cdot \left(u2 \cdot \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot \mathsf{PI}\left(\right)\right)\right), \frac{1}{6}\right), \frac{1}{2}\right) \]
    16. PI-lowering-PI.f6498.5

      \[\leadsto \mathsf{fma}\left(\sqrt{-\log u1}, \sqrt{2} \cdot \mathsf{fma}\left(-0.3333333333333333, u2 \cdot \left(u2 \cdot \left(\pi \cdot \color{blue}{\pi}\right)\right), 0.16666666666666666\right), 0.5\right) \]
  12. Simplified98.5%

    \[\leadsto \mathsf{fma}\left(\sqrt{-\log u1}, \color{blue}{\sqrt{2} \cdot \mathsf{fma}\left(-0.3333333333333333, u2 \cdot \left(u2 \cdot \left(\pi \cdot \pi\right)\right), 0.16666666666666666\right)}, 0.5\right) \]
  13. Final simplification98.5%

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

Alternative 6: 98.8% accurate, 2.3× speedup?

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

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

    \[\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. 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. *-lowering-*.f64N/A

      \[\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} \]
    2. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \left(\frac{1}{6} \cdot \left(\color{blue}{\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} \]
    3. log-recN/A

      \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{\color{blue}{\mathsf{neg}\left(\log 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. neg-sub0N/A

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

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

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

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

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

    \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{0 - \log u1} \cdot \sqrt{2}\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{0 - \log u1} \cdot \sqrt{2}\right)\right) \cdot \color{blue}{\left(-2 \cdot \left({u2}^{2} \cdot {\mathsf{PI}\left(\right)}^{2}\right) + 1\right)} + \frac{1}{2} \]
    2. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(\frac{1}{6} \cdot \left(\sqrt{0 - \log u1} \cdot \sqrt{2}\right)\right) \cdot \color{blue}{\mathsf{fma}\left(u2, u2 \cdot \left(\left(\pi \cdot \pi\right) \cdot -2\right), 1\right)} + 0.5 \]
  9. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(u2 \cdot \left(u2 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right)\right) + 1, \frac{1}{6} \cdot \left(\sqrt{0 - \log u1} \cdot \sqrt{2}\right), \frac{1}{2}\right)} \]
  10. Applied egg-rr98.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(u2 \cdot \left(\pi \cdot \pi\right), -2 \cdot u2, 1\right), 0.16666666666666666 \cdot \sqrt{\log u1 \cdot -2}, 0.5\right)} \]
  11. Final simplification98.4%

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

Alternative 7: 98.4% accurate, 2.5× speedup?

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

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

    \[\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. Add Preprocessing
  3. Step-by-step derivation
    1. pow-to-expN/A

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

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

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

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

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

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

      \[\leadsto \left(\frac{1}{6} \cdot {\left(e^{\frac{1}{2}}\right)}^{\log \color{blue}{\left(-2 \cdot \log u1\right)}}\right) \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) + \frac{1}{2} \]
    8. log-lowering-log.f6498.9

      \[\leadsto \left(\frac{1}{6} \cdot {\left(e^{0.5}\right)}^{\log \left(-2 \cdot \color{blue}{\log u1}\right)}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  4. Applied egg-rr98.9%

    \[\leadsto \left(\frac{1}{6} \cdot \color{blue}{{\left(e^{0.5}\right)}^{\log \left(-2 \cdot \log u1\right)}}\right) \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) + 0.5 \]
  5. Taylor expanded in u1 around inf

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\log \left(\frac{1}{u1}\right)}, \frac{1}{6} \cdot \left(\cos \left(2 \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{2}\right), \frac{1}{2}\right)} \]
  7. Simplified99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{0 - \log u1}, \left(0.16666666666666666 \cdot \sqrt{2}\right) \cdot \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right), 0.5\right)} \]
  8. Step-by-step derivation
    1. sub0-negN/A

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{\mathsf{neg}\left(\log u1\right)}}, \left(\frac{1}{6} \cdot \sqrt{2}\right) \cdot \cos \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \frac{1}{2}\right) \]
    3. log-lowering-log.f6499.6

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

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

    \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \color{blue}{\frac{1}{6} \cdot \sqrt{2}}, \frac{1}{2}\right) \]
  11. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\sqrt{\mathsf{neg}\left(\log u1\right)}, \color{blue}{\frac{1}{6} \cdot \sqrt{2}}, \frac{1}{2}\right) \]
    2. sqrt-lowering-sqrt.f6498.2

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

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

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

Alternative 8: 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.5%

    \[\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. 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 \color{blue}{\left(\sqrt{\log u1} \cdot \sqrt{-2}\right) \cdot \frac{1}{6}} + \frac{1}{2} \]
    3. associate-*l*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{-2 \cdot \log u1} \cdot \frac{1}{6}} + \frac{1}{2} \]
    7. accelerator-lowering-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{\log u1} \cdot -2}, \frac{1}{6}, \frac{1}{2}\right) \]
    18. metadata-eval98.1

      \[\leadsto \mathsf{fma}\left(\sqrt{\log u1 \cdot -2}, \color{blue}{0.16666666666666666}, 0.5\right) \]
  7. Applied egg-rr98.1%

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

Reproduce

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