Beckmann Sample, near normal, slope_y

Percentage Accurate: 57.2% → 98.4%
Time: 11.8s
Alternatives: 7
Speedup: 2.0×

Specification

?
\[\left(\left(cosTheta_i > 0.9999 \land cosTheta_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\begin{array}{l} \\ \sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 PI) u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-logf((1.0f - u1))) * sinf(((2.0f * ((float) M_PI)) * u2));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(-log(Float32(Float32(1.0) - u1)))) * sin(Float32(Float32(Float32(2.0) * Float32(pi)) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(-log((single(1.0) - u1))) * sin(((single(2.0) * single(pi)) * u2));
end
\begin{array}{l}

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\end{array}

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 57.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 PI) u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-logf((1.0f - u1))) * sinf(((2.0f * ((float) M_PI)) * u2));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(-log(Float32(Float32(1.0) - u1)))) * sin(Float32(Float32(Float32(2.0) * Float32(pi)) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(-log((single(1.0) - u1))) * sin(((single(2.0) * single(pi)) * u2));
end
\begin{array}{l}

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\end{array}

Alternative 1: 98.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{2 \cdot \pi}\\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(t_0 \cdot \left(u2 \cdot t_0\right)\right) \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (sqrt (* 2.0 PI))))
   (* (sqrt (- (log1p (- u1)))) (sin (* t_0 (* u2 t_0))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = sqrtf((2.0f * ((float) M_PI)));
	return sqrtf(-log1pf(-u1)) * sinf((t_0 * (u2 * t_0)));
}
function code(cosTheta_i, u1, u2)
	t_0 = sqrt(Float32(Float32(2.0) * Float32(pi)))
	return Float32(sqrt(Float32(-log1p(Float32(-u1)))) * sin(Float32(t_0 * Float32(u2 * t_0))))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{2 \cdot \pi}\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(t_0 \cdot \left(u2 \cdot t_0\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 56.2%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg56.2%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-def98.3%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified98.3%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Step-by-step derivation
    1. add-sqr-sqrt97.5%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(\sqrt{\left(2 \cdot \pi\right) \cdot u2} \cdot \sqrt{\left(2 \cdot \pi\right) \cdot u2}\right)} \]
    2. pow297.5%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left({\left(\sqrt{\left(2 \cdot \pi\right) \cdot u2}\right)}^{2}\right)} \]
    3. *-commutative97.5%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left({\left(\sqrt{\color{blue}{u2 \cdot \left(2 \cdot \pi\right)}}\right)}^{2}\right) \]
    4. associate-*r*97.5%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left({\left(\sqrt{\color{blue}{\left(u2 \cdot 2\right) \cdot \pi}}\right)}^{2}\right) \]
  5. Applied egg-rr97.5%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left({\left(\sqrt{\left(u2 \cdot 2\right) \cdot \pi}\right)}^{2}\right)} \]
  6. Step-by-step derivation
    1. unpow297.5%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(\sqrt{\left(u2 \cdot 2\right) \cdot \pi} \cdot \sqrt{\left(u2 \cdot 2\right) \cdot \pi}\right)} \]
    2. add-sqr-sqrt98.3%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(\left(u2 \cdot 2\right) \cdot \pi\right)} \]
    3. associate-*l*98.3%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(u2 \cdot \left(2 \cdot \pi\right)\right)} \]
    4. add-sqr-sqrt98.3%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(u2 \cdot \color{blue}{\left(\sqrt{2 \cdot \pi} \cdot \sqrt{2 \cdot \pi}\right)}\right) \]
    5. associate-*r*98.4%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(\left(u2 \cdot \sqrt{2 \cdot \pi}\right) \cdot \sqrt{2 \cdot \pi}\right)} \]
  7. Applied egg-rr98.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(\left(u2 \cdot \sqrt{2 \cdot \pi}\right) \cdot \sqrt{2 \cdot \pi}\right)} \]
  8. Final simplification98.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(\sqrt{2 \cdot \pi} \cdot \left(u2 \cdot \sqrt{2 \cdot \pi}\right)\right) \]

Alternative 2: 98.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(u2 \cdot \left(2 \cdot \pi\right)\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log1p (- u1)))) (sin (* u2 (* 2.0 PI)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-log1pf(-u1)) * sinf((u2 * (2.0f * ((float) M_PI))));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(-log1p(Float32(-u1)))) * sin(Float32(u2 * Float32(Float32(2.0) * Float32(pi)))))
end
\begin{array}{l}

\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(u2 \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Derivation
  1. Initial program 56.2%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg56.2%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-def98.3%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified98.3%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Final simplification98.3%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(u2 \cdot \left(2 \cdot \pi\right)\right) \]

Alternative 3: 88.1% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \sin \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 \cdot \left(\left(--1\right) - u1 \cdot -0.5\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sin (* u2 (* 2.0 PI))) (sqrt (* u1 (- (- -1.0) (* u1 -0.5))))))
float code(float cosTheta_i, float u1, float u2) {
	return sinf((u2 * (2.0f * ((float) M_PI)))) * sqrtf((u1 * (-(-1.0f) - (u1 * -0.5f))));
}
function code(cosTheta_i, u1, u2)
	return Float32(sin(Float32(u2 * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(u1 * Float32(Float32(-Float32(-1.0)) - Float32(u1 * Float32(-0.5))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sin((u2 * (single(2.0) * single(pi)))) * sqrt((u1 * (-single(-1.0) - (u1 * single(-0.5)))));
end
\begin{array}{l}

\\
\sin \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 \cdot \left(\left(--1\right) - u1 \cdot -0.5\right)}
\end{array}
Derivation
  1. Initial program 56.2%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Taylor expanded in u1 around 0 88.4%

    \[\leadsto \sqrt{-\color{blue}{\left(-1 \cdot u1 + -0.5 \cdot {u1}^{2}\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Step-by-step derivation
    1. *-commutative88.4%

      \[\leadsto \sqrt{-\left(\color{blue}{u1 \cdot -1} + -0.5 \cdot {u1}^{2}\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. *-commutative88.4%

      \[\leadsto \sqrt{-\left(u1 \cdot -1 + \color{blue}{{u1}^{2} \cdot -0.5}\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. unpow288.4%

      \[\leadsto \sqrt{-\left(u1 \cdot -1 + \color{blue}{\left(u1 \cdot u1\right)} \cdot -0.5\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    4. associate-*l*88.4%

      \[\leadsto \sqrt{-\left(u1 \cdot -1 + \color{blue}{u1 \cdot \left(u1 \cdot -0.5\right)}\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    5. distribute-lft-out88.4%

      \[\leadsto \sqrt{-\color{blue}{u1 \cdot \left(-1 + u1 \cdot -0.5\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  4. Simplified88.4%

    \[\leadsto \sqrt{-\color{blue}{u1 \cdot \left(-1 + u1 \cdot -0.5\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  5. Final simplification88.4%

    \[\leadsto \sin \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 \cdot \left(\left(--1\right) - u1 \cdot -0.5\right)} \]

Alternative 4: 76.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \sqrt{u1} \cdot \sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt u1) (sin (* 2.0 (* u2 PI)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(u1) * sinf((2.0f * (u2 * ((float) M_PI))));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(u1) * sin(Float32(Float32(2.0) * Float32(u2 * Float32(pi)))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(u1) * sin((single(2.0) * (u2 * single(pi))));
end
\begin{array}{l}

\\
\sqrt{u1} \cdot \sin \left(2 \cdot \left(u2 \cdot \pi\right)\right)
\end{array}
Derivation
  1. Initial program 56.2%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Taylor expanded in u1 around 0 77.4%

    \[\leadsto \sqrt{-\color{blue}{-1 \cdot u1}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Step-by-step derivation
    1. mul-1-neg77.4%

      \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  4. Simplified77.4%

    \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  5. Taylor expanded in u2 around inf 77.4%

    \[\leadsto \color{blue}{\sqrt{u1} \cdot \sin \left(2 \cdot \left(u2 \cdot \pi\right)\right)} \]
  6. Final simplification77.4%

    \[\leadsto \sqrt{u1} \cdot \sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \]

Alternative 5: 66.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ 2 \cdot \left(u2 \cdot \left(\pi \cdot \sqrt{u1}\right)\right) \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 2.0 (* u2 (* PI (sqrt u1)))))
float code(float cosTheta_i, float u1, float u2) {
	return 2.0f * (u2 * (((float) M_PI) * sqrtf(u1)));
}
function code(cosTheta_i, u1, u2)
	return Float32(Float32(2.0) * Float32(u2 * Float32(Float32(pi) * sqrt(u1))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = single(2.0) * (u2 * (single(pi) * sqrt(u1)));
end
\begin{array}{l}

\\
2 \cdot \left(u2 \cdot \left(\pi \cdot \sqrt{u1}\right)\right)
\end{array}
Derivation
  1. Initial program 56.2%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Taylor expanded in u1 around 0 77.4%

    \[\leadsto \sqrt{-\color{blue}{-1 \cdot u1}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Step-by-step derivation
    1. mul-1-neg77.4%

      \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  4. Simplified77.4%

    \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  5. Taylor expanded in u2 around 0 67.7%

    \[\leadsto \color{blue}{2 \cdot \left(\sqrt{u1} \cdot \left(u2 \cdot \pi\right)\right)} \]
  6. Step-by-step derivation
    1. *-commutative67.7%

      \[\leadsto 2 \cdot \color{blue}{\left(\left(u2 \cdot \pi\right) \cdot \sqrt{u1}\right)} \]
  7. Simplified67.7%

    \[\leadsto \color{blue}{2 \cdot \left(\left(u2 \cdot \pi\right) \cdot \sqrt{u1}\right)} \]
  8. Taylor expanded in u2 around 0 67.7%

    \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{u1} \cdot \left(u2 \cdot \pi\right)\right)} \]
  9. Step-by-step derivation
    1. associate-*r*67.9%

      \[\leadsto 2 \cdot \color{blue}{\left(\left(\sqrt{u1} \cdot u2\right) \cdot \pi\right)} \]
    2. *-commutative67.9%

      \[\leadsto 2 \cdot \left(\color{blue}{\left(u2 \cdot \sqrt{u1}\right)} \cdot \pi\right) \]
    3. *-commutative67.9%

      \[\leadsto 2 \cdot \color{blue}{\left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right)} \]
  10. Simplified67.9%

    \[\leadsto 2 \cdot \color{blue}{\left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right)} \]
  11. Taylor expanded in u2 around 0 67.7%

    \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{u1} \cdot \left(u2 \cdot \pi\right)\right)} \]
  12. Step-by-step derivation
    1. associate-*r*67.9%

      \[\leadsto 2 \cdot \color{blue}{\left(\left(\sqrt{u1} \cdot u2\right) \cdot \pi\right)} \]
    2. *-commutative67.9%

      \[\leadsto 2 \cdot \left(\color{blue}{\left(u2 \cdot \sqrt{u1}\right)} \cdot \pi\right) \]
    3. associate-*l*67.9%

      \[\leadsto 2 \cdot \color{blue}{\left(u2 \cdot \left(\sqrt{u1} \cdot \pi\right)\right)} \]
  13. Simplified67.9%

    \[\leadsto 2 \cdot \color{blue}{\left(u2 \cdot \left(\sqrt{u1} \cdot \pi\right)\right)} \]
  14. Final simplification67.9%

    \[\leadsto 2 \cdot \left(u2 \cdot \left(\pi \cdot \sqrt{u1}\right)\right) \]

Alternative 6: 66.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ 2 \cdot \left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right) \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 2.0 (* PI (* u2 (sqrt u1)))))
float code(float cosTheta_i, float u1, float u2) {
	return 2.0f * (((float) M_PI) * (u2 * sqrtf(u1)));
}
function code(cosTheta_i, u1, u2)
	return Float32(Float32(2.0) * Float32(Float32(pi) * Float32(u2 * sqrt(u1))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = single(2.0) * (single(pi) * (u2 * sqrt(u1)));
end
\begin{array}{l}

\\
2 \cdot \left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right)
\end{array}
Derivation
  1. Initial program 56.2%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Taylor expanded in u1 around 0 77.4%

    \[\leadsto \sqrt{-\color{blue}{-1 \cdot u1}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Step-by-step derivation
    1. mul-1-neg77.4%

      \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  4. Simplified77.4%

    \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  5. Taylor expanded in u2 around 0 67.7%

    \[\leadsto \color{blue}{2 \cdot \left(\sqrt{u1} \cdot \left(u2 \cdot \pi\right)\right)} \]
  6. Step-by-step derivation
    1. *-commutative67.7%

      \[\leadsto 2 \cdot \color{blue}{\left(\left(u2 \cdot \pi\right) \cdot \sqrt{u1}\right)} \]
  7. Simplified67.7%

    \[\leadsto \color{blue}{2 \cdot \left(\left(u2 \cdot \pi\right) \cdot \sqrt{u1}\right)} \]
  8. Taylor expanded in u2 around 0 67.7%

    \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{u1} \cdot \left(u2 \cdot \pi\right)\right)} \]
  9. Step-by-step derivation
    1. associate-*r*67.9%

      \[\leadsto 2 \cdot \color{blue}{\left(\left(\sqrt{u1} \cdot u2\right) \cdot \pi\right)} \]
    2. *-commutative67.9%

      \[\leadsto 2 \cdot \left(\color{blue}{\left(u2 \cdot \sqrt{u1}\right)} \cdot \pi\right) \]
    3. *-commutative67.9%

      \[\leadsto 2 \cdot \color{blue}{\left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right)} \]
  10. Simplified67.9%

    \[\leadsto 2 \cdot \color{blue}{\left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right)} \]
  11. Final simplification67.9%

    \[\leadsto 2 \cdot \left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right) \]

Alternative 7: 7.1% accurate, 409.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 0.0)
float code(float cosTheta_i, float u1, float u2) {
	return 0.0f;
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = 0.0e0
end function
function code(cosTheta_i, u1, u2)
	return Float32(0.0)
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = single(0.0);
end
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 56.2%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg56.2%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-def98.3%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified98.3%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Step-by-step derivation
    1. add-cube-cbrt97.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(\left(\sqrt[3]{\left(2 \cdot \pi\right) \cdot u2} \cdot \sqrt[3]{\left(2 \cdot \pi\right) \cdot u2}\right) \cdot \sqrt[3]{\left(2 \cdot \pi\right) \cdot u2}\right)} \]
    2. pow397.3%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left({\left(\sqrt[3]{\left(2 \cdot \pi\right) \cdot u2}\right)}^{3}\right)} \]
    3. *-commutative97.3%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left({\left(\sqrt[3]{\color{blue}{u2 \cdot \left(2 \cdot \pi\right)}}\right)}^{3}\right) \]
    4. associate-*r*97.3%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left({\left(\sqrt[3]{\color{blue}{\left(u2 \cdot 2\right) \cdot \pi}}\right)}^{3}\right) \]
  5. Applied egg-rr97.3%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left({\left(\sqrt[3]{\left(u2 \cdot 2\right) \cdot \pi}\right)}^{3}\right)} \]
  6. Taylor expanded in u2 around 0 7.2%

    \[\leadsto \color{blue}{0} \]
  7. Final simplification7.2%

    \[\leadsto 0 \]

Reproduce

?
herbie shell --seed 2023321 
(FPCore (cosTheta_i u1 u2)
  :name "Beckmann Sample, near normal, slope_y"
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 PI) u2))))