Beckmann Sample, near normal, slope_x

Percentage Accurate: 58.2% → 99.1%
Time: 11.3s
Alternatives: 15
Speedup: 3.1×

Specification

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

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \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 15 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: 58.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.1% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \sin \left(u2 \cdot \pi\right)\\
t_1 := \sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\mathsf{fma}\left(t\_1, \cos \left(2 \cdot \left(u2 \cdot \pi\right)\right), t\_1 \cdot \mathsf{fma}\left(-t\_0, t\_0, {t\_0}^{2}\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. log1p-expm1-u98.9%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)\right)} \]
    2. *-commutative98.9%

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

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \color{blue}{\left(\pi \cdot \left(2 \cdot u2\right)\right)}\right)\right) \]
  6. Applied egg-rr98.9%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\pi \cdot \left(2 \cdot u2\right)\right)\right)\right)} \]
  7. Step-by-step derivation
    1. log1p-expm1-u99.0%

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

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

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

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

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(\cos \left(\pi \cdot u2\right) \cdot \cos \left(\pi \cdot u2\right) - \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)} \]
    6. prod-diff98.9%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(\cos \left(\pi \cdot u2\right), \cos \left(\pi \cdot u2\right), -\sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)\right)} \]
  8. Applied egg-rr98.9%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(\cos \left(\pi \cdot u2\right), \cos \left(\pi \cdot u2\right), -\sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)\right)} \]
  9. Step-by-step derivation
    1. fmm-def98.9%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\color{blue}{\left(\cos \left(\pi \cdot u2\right) \cdot \cos \left(\pi \cdot u2\right) - \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)} + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)\right) \]
    2. *-commutative98.9%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\left(\cos \color{blue}{\left(u2 \cdot \pi\right)} \cdot \cos \left(\pi \cdot u2\right) - \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)\right) \]
    3. *-commutative98.9%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\left(\cos \left(u2 \cdot \pi\right) \cdot \cos \color{blue}{\left(u2 \cdot \pi\right)} - \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)\right) \]
    4. *-commutative98.9%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\left(\cos \left(u2 \cdot \pi\right) \cdot \cos \left(u2 \cdot \pi\right) - \sin \color{blue}{\left(u2 \cdot \pi\right)} \cdot \sin \left(\pi \cdot u2\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)\right) \]
    5. *-commutative98.9%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\left(\cos \left(u2 \cdot \pi\right) \cdot \cos \left(u2 \cdot \pi\right) - \sin \left(u2 \cdot \pi\right) \cdot \sin \color{blue}{\left(u2 \cdot \pi\right)}\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right) \cdot \sin \left(\pi \cdot u2\right)\right)\right) \]
  10. Simplified98.9%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(\left(\cos \left(u2 \cdot \pi\right) \cdot \cos \left(u2 \cdot \pi\right) - \sin \left(u2 \cdot \pi\right) \cdot \sin \left(u2 \cdot \pi\right)\right) + \mathsf{fma}\left(-\sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right) \cdot \sin \left(u2 \cdot \pi\right)\right)\right)} \]
  11. Applied egg-rr98.9%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\left(\cos \left(u2 \cdot \pi\right) \cdot \cos \left(u2 \cdot \pi\right) - \sin \left(u2 \cdot \pi\right) \cdot \sin \left(u2 \cdot \pi\right)\right) + \mathsf{fma}\left(-\sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right) \cdot \sin \color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(u2 \cdot \pi\right)\right)\right)}\right)\right) \]
  12. Step-by-step derivation
    1. distribute-rgt-in98.9%

      \[\leadsto \color{blue}{\left(\cos \left(u2 \cdot \pi\right) \cdot \cos \left(u2 \cdot \pi\right) - \sin \left(u2 \cdot \pi\right) \cdot \sin \left(u2 \cdot \pi\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)} + \mathsf{fma}\left(-\sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right) \cdot \sin \left(\mathsf{expm1}\left(\mathsf{log1p}\left(u2 \cdot \pi\right)\right)\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}} \]
  13. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{-\mathsf{log1p}\left(-u1\right)}, \cos \left(2 \cdot \left(u2 \cdot \pi\right)\right), \mathsf{fma}\left(-\sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right), {\sin \left(u2 \cdot \pi\right)}^{2}\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right)} \]
  14. Final simplification99.0%

    \[\leadsto \mathsf{fma}\left(\sqrt{-\mathsf{log1p}\left(-u1\right)}, \cos \left(2 \cdot \left(u2 \cdot \pi\right)\right), \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \mathsf{fma}\left(-\sin \left(u2 \cdot \pi\right), \sin \left(u2 \cdot \pi\right), {\sin \left(u2 \cdot \pi\right)}^{2}\right)\right) \]
  15. Add Preprocessing

Alternative 2: 99.1% accurate, 1.0× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Final simplification99.0%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \]
  6. Add Preprocessing

Alternative 3: 96.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t\_0 \leq 0.0006600000197067857:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos t\_0 \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (* u2 (* 2.0 PI))))
   (if (<= t_0 0.0006600000197067857)
     (sqrt (- (log1p (- u1))))
     (*
      (cos t_0)
      (sqrt (* u1 (+ 1.0 (* u1 (+ 0.5 (* u1 0.3333333333333333))))))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = u2 * (2.0f * ((float) M_PI));
	float tmp;
	if (t_0 <= 0.0006600000197067857f) {
		tmp = sqrtf(-log1pf(-u1));
	} else {
		tmp = cosf(t_0) * sqrtf((u1 * (1.0f + (u1 * (0.5f + (u1 * 0.3333333333333333f))))));
	}
	return tmp;
}
function code(cosTheta_i, u1, u2)
	t_0 = Float32(u2 * Float32(Float32(2.0) * Float32(pi)))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.0006600000197067857))
		tmp = sqrt(Float32(-log1p(Float32(-u1))));
	else
		tmp = Float32(cos(t_0) * sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(Float32(0.5) + Float32(u1 * Float32(0.3333333333333333))))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := u2 \cdot \left(2 \cdot \pi\right)\\
\mathbf{if}\;t\_0 \leq 0.0006600000197067857:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos t\_0 \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2) < 6.6000002e-4

    1. Initial program 60.5%

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

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

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

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

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]

    if 6.6000002e-4 < (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)

    1. Initial program 54.1%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u1 around 0 91.7%

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

        \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + \color{blue}{u1 \cdot 0.3333333333333333}\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    5. Simplified91.7%

      \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;u2 \cdot \left(2 \cdot \pi\right) \leq 0.0006600000197067857:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 94.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t\_0 \leq 0.0006600000197067857:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos t\_0 \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot 0.5\right)}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (* u2 (* 2.0 PI))))
   (if (<= t_0 0.0006600000197067857)
     (sqrt (- (log1p (- u1))))
     (* (cos t_0) (sqrt (* u1 (+ 1.0 (* u1 0.5))))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = u2 * (2.0f * ((float) M_PI));
	float tmp;
	if (t_0 <= 0.0006600000197067857f) {
		tmp = sqrtf(-log1pf(-u1));
	} else {
		tmp = cosf(t_0) * sqrtf((u1 * (1.0f + (u1 * 0.5f))));
	}
	return tmp;
}
function code(cosTheta_i, u1, u2)
	t_0 = Float32(u2 * Float32(Float32(2.0) * Float32(pi)))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.0006600000197067857))
		tmp = sqrt(Float32(-log1p(Float32(-u1))));
	else
		tmp = Float32(cos(t_0) * sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(0.5))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := u2 \cdot \left(2 \cdot \pi\right)\\
\mathbf{if}\;t\_0 \leq 0.0006600000197067857:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos t\_0 \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot 0.5\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2) < 6.6000002e-4

    1. Initial program 60.5%

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

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

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

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

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]

    if 6.6000002e-4 < (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)

    1. Initial program 54.1%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u1 around 0 88.7%

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

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

      \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1 \cdot 0.5\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;u2 \cdot \left(2 \cdot \pi\right) \leq 0.0006600000197067857:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot 0.5\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 93.5% accurate, 1.4× speedup?

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

\\
\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + u1 \cdot 0.25\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 58.0%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Add Preprocessing
  3. Taylor expanded in u1 around 0 94.3%

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

      \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + \color{blue}{u1 \cdot 0.25}\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  5. Simplified94.3%

    \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + u1 \cdot 0.25\right)\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  6. Final simplification94.3%

    \[\leadsto \cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + u1 \cdot 0.25\right)\right)\right)} \]
  7. Add Preprocessing

Alternative 6: 90.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t\_0 \leq 0.0026000000070780516:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos t\_0 \cdot \sqrt{u1}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (* u2 (* 2.0 PI))))
   (if (<= t_0 0.0026000000070780516)
     (sqrt (- (log1p (- u1))))
     (* (cos t_0) (sqrt u1)))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = u2 * (2.0f * ((float) M_PI));
	float tmp;
	if (t_0 <= 0.0026000000070780516f) {
		tmp = sqrtf(-log1pf(-u1));
	} else {
		tmp = cosf(t_0) * sqrtf(u1);
	}
	return tmp;
}
function code(cosTheta_i, u1, u2)
	t_0 = Float32(u2 * Float32(Float32(2.0) * Float32(pi)))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.0026000000070780516))
		tmp = sqrt(Float32(-log1p(Float32(-u1))));
	else
		tmp = Float32(cos(t_0) * sqrt(u1));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := u2 \cdot \left(2 \cdot \pi\right)\\
\mathbf{if}\;t\_0 \leq 0.0026000000070780516:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos t\_0 \cdot \sqrt{u1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2) < 0.00260000001

    1. Initial program 60.7%

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

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

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

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

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]

    if 0.00260000001 < (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)

    1. Initial program 52.7%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u1 around 0 79.1%

      \[\leadsto \sqrt{\color{blue}{u1}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.0%

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

Alternative 7: 80.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (- (log1p (- u1)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-log1pf(-u1));
}
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(-log1p(Float32(-u1))))
end
\begin{array}{l}

\\
\sqrt{-\mathsf{log1p}\left(-u1\right)}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Final simplification81.1%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \]
  7. Add Preprocessing

Alternative 8: 76.5% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + u1 \cdot 0.25\right)\right)\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (sqrt
  (* u1 (+ 1.0 (* u1 (+ 0.5 (* u1 (+ 0.3333333333333333 (* u1 0.25)))))))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 * (1.0f + (u1 * (0.5f + (u1 * (0.3333333333333333f + (u1 * 0.25f))))))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 * (1.0e0 + (u1 * (0.5e0 + (u1 * (0.3333333333333333e0 + (u1 * 0.25e0))))))))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(Float32(0.5) + Float32(u1 * Float32(Float32(0.3333333333333333) + Float32(u1 * Float32(0.25)))))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 * (single(1.0) + (u1 * (single(0.5) + (u1 * (single(0.3333333333333333) + (u1 * single(0.25)))))))));
end
\begin{array}{l}

\\
\sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + u1 \cdot 0.25\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 78.2%

    \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + 0.25 \cdot u1\right)\right)\right)}} \cdot 1 \]
  7. Step-by-step derivation
    1. *-commutative78.2%

      \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + \color{blue}{u1 \cdot 0.25}\right)\right)\right)} \cdot 1 \]
  8. Simplified78.2%

    \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + u1 \cdot 0.25\right)\right)\right)}} \cdot 1 \]
  9. Final simplification78.2%

    \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 + u1 \cdot 0.25\right)\right)\right)} \]
  10. Add Preprocessing

Alternative 9: 75.2% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (sqrt (* u1 (+ 1.0 (* u1 (+ 0.5 (* u1 0.3333333333333333)))))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 * (1.0f + (u1 * (0.5f + (u1 * 0.3333333333333333f))))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 * (1.0e0 + (u1 * (0.5e0 + (u1 * 0.3333333333333333e0))))))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(Float32(0.5) + Float32(u1 * Float32(0.3333333333333333)))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 * (single(1.0) + (u1 * (single(0.5) + (u1 * single(0.3333333333333333)))))));
end
\begin{array}{l}

\\
\sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 77.0%

    \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1 \cdot \left(0.5 + 0.3333333333333333 \cdot u1\right)\right)}} \cdot 1 \]
  7. Step-by-step derivation
    1. *-commutative77.0%

      \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + \color{blue}{u1 \cdot 0.3333333333333333}\right)\right)} \cdot 1 \]
  8. Simplified77.0%

    \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)}} \cdot 1 \]
  9. Final simplification77.0%

    \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)} \]
  10. Add Preprocessing

Alternative 10: 72.6% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \sqrt{u1 \cdot \left(1 + u1 \cdot 0.5\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (sqrt (* u1 (+ 1.0 (* u1 0.5)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 * (1.0f + (u1 * 0.5f))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 * (1.0e0 + (u1 * 0.5e0))))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(0.5)))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 * (single(1.0) + (u1 * single(0.5)))));
end
\begin{array}{l}

\\
\sqrt{u1 \cdot \left(1 + u1 \cdot 0.5\right)}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \color{blue}{\sqrt{u1 \cdot \left(1 + 0.5 \cdot u1\right)}} \]
  7. Step-by-step derivation
    1. *-commutative74.1%

      \[\leadsto \sqrt{u1 \cdot \left(1 + \color{blue}{u1 \cdot 0.5}\right)} \]
  8. Simplified74.1%

    \[\leadsto \color{blue}{\sqrt{u1 \cdot \left(1 + u1 \cdot 0.5\right)}} \]
  9. Add Preprocessing

Alternative 11: 64.6% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt{u1} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt u1))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(u1);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt(u1)
end function
function code(cosTheta_i, u1, u2)
	return sqrt(u1)
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(u1);
end
\begin{array}{l}

\\
\sqrt{u1}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 65.4%

    \[\leadsto \sqrt{\color{blue}{u1}} \cdot 1 \]
  7. Taylor expanded in u1 around 0 65.4%

    \[\leadsto \color{blue}{\sqrt{u1}} \]
  8. Add Preprocessing

Alternative 12: 24.0% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt[3]{u1} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (cbrt u1))
float code(float cosTheta_i, float u1, float u2) {
	return cbrtf(u1);
}
function code(cosTheta_i, u1, u2)
	return cbrt(u1)
end
\begin{array}{l}

\\
\sqrt[3]{u1}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 65.4%

    \[\leadsto \sqrt{\color{blue}{u1}} \cdot 1 \]
  7. Applied egg-rr23.9%

    \[\leadsto \color{blue}{\sqrt[3]{u1}} \]
  8. Add Preprocessing

Alternative 13: 19.4% accurate, 103.3× speedup?

\[\begin{array}{l} \\ \frac{u1}{u1} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (/ u1 u1))
float code(float cosTheta_i, float u1, float u2) {
	return u1 / u1;
}
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 = u1 / u1
end function
function code(cosTheta_i, u1, u2)
	return Float32(u1 / u1)
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = u1 / u1;
end
\begin{array}{l}

\\
\frac{u1}{u1}
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 65.4%

    \[\leadsto \sqrt{\color{blue}{u1}} \cdot 1 \]
  7. Applied egg-rr19.2%

    \[\leadsto \color{blue}{\frac{u1}{u1}} \]
  8. Add Preprocessing

Alternative 14: 4.4% accurate, 155.0× speedup?

\[\begin{array}{l} \\ -u1 \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (- u1))
float code(float cosTheta_i, float u1, float u2) {
	return -u1;
}
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 = -u1
end function
function code(cosTheta_i, u1, u2)
	return Float32(-u1)
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = -u1;
end
\begin{array}{l}

\\
-u1
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 65.4%

    \[\leadsto \sqrt{\color{blue}{u1}} \cdot 1 \]
  7. Applied egg-rr4.4%

    \[\leadsto \color{blue}{0 - u1} \]
  8. Step-by-step derivation
    1. neg-sub04.4%

      \[\leadsto \color{blue}{-u1} \]
  9. Simplified4.4%

    \[\leadsto \color{blue}{-u1} \]
  10. Add Preprocessing

Alternative 15: 19.3% accurate, 310.0× speedup?

\[\begin{array}{l} \\ u1 \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 u1)
float code(float cosTheta_i, float u1, float u2) {
	return u1;
}
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 = u1
end function
function code(cosTheta_i, u1, u2)
	return u1
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = u1;
end
\begin{array}{l}

\\
u1
\end{array}
Derivation
  1. Initial program 58.0%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 65.4%

    \[\leadsto \sqrt{\color{blue}{u1}} \cdot 1 \]
  7. Applied egg-rr19.2%

    \[\leadsto \color{blue}{0 + u1} \]
  8. Final simplification19.2%

    \[\leadsto u1 \]
  9. Add Preprocessing

Reproduce

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