Average Error: 14.1 → 0.5
Time: 8.6s
Precision: binary32
\[0.0001 \leq \alpha \land \alpha \leq 1 \land 2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\]
\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\]
\[\begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9607079029083252:\\ \;\;\;\;\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot {\alpha}^{2} + \left(0.5 \cdot \left({\alpha}^{2} \cdot {u0}^{2}\right) + \left(0.25 \cdot \left({\alpha}^{2} \cdot {u0}^{4}\right) + 0.3333333333333333 \cdot \left({\alpha}^{2} \cdot {u0}^{3}\right)\right)\right)\\ \end{array}\]
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)
\begin{array}{l}
\mathbf{if}\;1 - u0 \leq 0.9607079029083252:\\
\;\;\;\;\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)\\

\mathbf{else}:\\
\;\;\;\;u0 \cdot {\alpha}^{2} + \left(0.5 \cdot \left({\alpha}^{2} \cdot {u0}^{2}\right) + \left(0.25 \cdot \left({\alpha}^{2} \cdot {u0}^{4}\right) + 0.3333333333333333 \cdot \left({\alpha}^{2} \cdot {u0}^{3}\right)\right)\right)\\

\end{array}
(FPCore (alpha u0)
 :precision binary32
 (* (* (- alpha) alpha) (log (- 1.0 u0))))
(FPCore (alpha u0)
 :precision binary32
 (if (<= (- 1.0 u0) 0.9607079029083252)
   (* (- alpha) (* alpha (log (- 1.0 u0))))
   (+
    (* u0 (pow alpha 2.0))
    (+
     (* 0.5 (* (pow alpha 2.0) (pow u0 2.0)))
     (+
      (* 0.25 (* (pow alpha 2.0) (pow u0 4.0)))
      (* 0.3333333333333333 (* (pow alpha 2.0) (pow u0 3.0))))))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf(1.0f - u0);
}
float code(float alpha, float u0) {
	float tmp;
	if ((1.0f - u0) <= 0.9607079029083252f) {
		tmp = -alpha * (alpha * logf(1.0f - u0));
	} else {
		tmp = (u0 * powf(alpha, 2.0f)) + ((0.5f * (powf(alpha, 2.0f) * powf(u0, 2.0f))) + ((0.25f * (powf(alpha, 2.0f) * powf(u0, 4.0f))) + (0.3333333333333333f * (powf(alpha, 2.0f) * powf(u0, 3.0f)))));
	}
	return tmp;
}

Error

Bits error versus alpha

Bits error versus u0

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (-.f32 1 u0) < 0.960707903

    1. Initial program 1.0

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\]
    2. Using strategy rm
    3. Applied associate-*l*_binary321.0

      \[\leadsto \color{blue}{\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)}\]

    if 0.960707903 < (-.f32 1 u0)

    1. Initial program 16.4

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\]
    2. Taylor expanded around 0 0.4

      \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0 + \left(0.5 \cdot \left({\alpha}^{2} \cdot {u0}^{2}\right) + \left(0.25 \cdot \left({\alpha}^{2} \cdot {u0}^{4}\right) + 0.3333333333333333 \cdot \left({\alpha}^{2} \cdot {u0}^{3}\right)\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9607079029083252:\\ \;\;\;\;\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot {\alpha}^{2} + \left(0.5 \cdot \left({\alpha}^{2} \cdot {u0}^{2}\right) + \left(0.25 \cdot \left({\alpha}^{2} \cdot {u0}^{4}\right) + 0.3333333333333333 \cdot \left({\alpha}^{2} \cdot {u0}^{3}\right)\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2021173 
(FPCore (alpha u0)
  :name "Beckmann Distribution sample, tan2theta, alphax == alphay"
  :precision binary32
  :pre (and (<= 0.0001 alpha 1.0) (<= 2.328306437e-10 u0 1.0))
  (* (* (- alpha) alpha) (log (- 1.0 u0))))