Beckmann Distribution sample, tan2theta, alphax == alphay

Percentage Accurate: 55.6% → 89.6%
Time: 6.7s
Alternatives: 5
Speedup: 10.5×

Specification

?
\[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
\[\begin{array}{l} \\ \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (* (* (- alpha) alpha) (log (- 1.0 u0))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf((1.0f - u0));
}
real(4) function code(alpha, u0)
    real(4), intent (in) :: alpha
    real(4), intent (in) :: u0
    code = (-alpha * alpha) * log((1.0e0 - u0))
end function
function code(alpha, u0)
	return Float32(Float32(Float32(-alpha) * alpha) * log(Float32(Float32(1.0) - u0)))
end
function tmp = code(alpha, u0)
	tmp = (-alpha * alpha) * log((single(1.0) - u0));
end
\begin{array}{l}

\\
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\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 5 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: 55.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (* (* (- alpha) alpha) (log (- 1.0 u0))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf((1.0f - u0));
}
real(4) function code(alpha, u0)
    real(4), intent (in) :: alpha
    real(4), intent (in) :: u0
    code = (-alpha * alpha) * log((1.0e0 - u0))
end function
function code(alpha, u0)
	return Float32(Float32(Float32(-alpha) * alpha) * log(Float32(Float32(1.0) - u0)))
end
function tmp = code(alpha, u0)
	tmp = (-alpha * alpha) * log((single(1.0) - u0));
end
\begin{array}{l}

\\
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)
\end{array}

Alternative 1: 89.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;u0 \leq 0.00011800000356743112:\\ \;\;\;\;\frac{u0}{{\alpha}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 - u0\right) \cdot \frac{1}{\frac{-1}{\alpha \cdot \alpha}}\\ \end{array} \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (if (<= u0 0.00011800000356743112)
   (/ u0 (pow alpha -2.0))
   (* (log (- 1.0 u0)) (/ 1.0 (/ -1.0 (* alpha alpha))))))
float code(float alpha, float u0) {
	float tmp;
	if (u0 <= 0.00011800000356743112f) {
		tmp = u0 / powf(alpha, -2.0f);
	} else {
		tmp = logf((1.0f - u0)) * (1.0f / (-1.0f / (alpha * alpha)));
	}
	return tmp;
}
real(4) function code(alpha, u0)
    real(4), intent (in) :: alpha
    real(4), intent (in) :: u0
    real(4) :: tmp
    if (u0 <= 0.00011800000356743112e0) then
        tmp = u0 / (alpha ** (-2.0e0))
    else
        tmp = log((1.0e0 - u0)) * (1.0e0 / ((-1.0e0) / (alpha * alpha)))
    end if
    code = tmp
end function
function code(alpha, u0)
	tmp = Float32(0.0)
	if (u0 <= Float32(0.00011800000356743112))
		tmp = Float32(u0 / (alpha ^ Float32(-2.0)));
	else
		tmp = Float32(log(Float32(Float32(1.0) - u0)) * Float32(Float32(1.0) / Float32(Float32(-1.0) / Float32(alpha * alpha))));
	end
	return tmp
end
function tmp_2 = code(alpha, u0)
	tmp = single(0.0);
	if (u0 <= single(0.00011800000356743112))
		tmp = u0 / (alpha ^ single(-2.0));
	else
		tmp = log((single(1.0) - u0)) * (single(1.0) / (single(-1.0) / (alpha * alpha)));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;u0 \leq 0.00011800000356743112:\\
\;\;\;\;\frac{u0}{{\alpha}^{-2}}\\

\mathbf{else}:\\
\;\;\;\;\log \left(1 - u0\right) \cdot \frac{1}{\frac{-1}{\alpha \cdot \alpha}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u0 < 1.18000004e-4

    1. Initial program 35.7%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u0 around 0

      \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
    4. Step-by-step derivation
      1. lower-*.f32N/A

        \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
      2. unpow2N/A

        \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
      3. lower-*.f3291.8

        \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
    5. Applied rewrites91.8%

      \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right) \cdot u0} \]
    6. Step-by-step derivation
      1. Applied rewrites91.7%

        \[\leadsto \left(u0 \cdot \alpha\right) \cdot \color{blue}{\alpha} \]
      2. Step-by-step derivation
        1. Applied rewrites91.6%

          \[\leadsto \frac{u0}{\color{blue}{\frac{\frac{1}{\alpha}}{\alpha}}} \]
        2. Step-by-step derivation
          1. Applied rewrites91.8%

            \[\leadsto \frac{u0}{\color{blue}{{\alpha}^{-2}}} \]

          if 1.18000004e-4 < u0

          1. Initial program 85.6%

            \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-neg.f32N/A

              \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            2. neg-sub0N/A

              \[\leadsto \left(\color{blue}{\left(0 - \alpha\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            3. flip--N/A

              \[\leadsto \left(\color{blue}{\frac{0 \cdot 0 - \alpha \cdot \alpha}{0 + \alpha}} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            4. metadata-evalN/A

              \[\leadsto \left(\frac{\color{blue}{0} - \alpha \cdot \alpha}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            5. neg-sub0N/A

              \[\leadsto \left(\frac{\color{blue}{\mathsf{neg}\left(\alpha \cdot \alpha\right)}}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            6. distribute-lft-neg-outN/A

              \[\leadsto \left(\frac{\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right) \cdot \alpha}}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            7. lift-neg.f32N/A

              \[\leadsto \left(\frac{\color{blue}{\left(-\alpha\right)} \cdot \alpha}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            8. lift-*.f32N/A

              \[\leadsto \left(\frac{\color{blue}{\left(-\alpha\right) \cdot \alpha}}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            9. div-invN/A

              \[\leadsto \left(\color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{0 + \alpha}\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            10. lower-*.f32N/A

              \[\leadsto \left(\color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{0 + \alpha}\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            11. +-lft-identityN/A

              \[\leadsto \left(\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\color{blue}{\alpha}}\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            12. lower-/.f3285.5

              \[\leadsto \left(\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\frac{1}{\alpha}}\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
          4. Applied rewrites85.5%

            \[\leadsto \left(\color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
          5. Step-by-step derivation
            1. lift-*.f32N/A

              \[\leadsto \color{blue}{\left(\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right) \cdot \alpha\right)} \cdot \log \left(1 - u0\right) \]
            2. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\alpha \cdot \left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right)\right)} \cdot \log \left(1 - u0\right) \]
            3. lift-*.f32N/A

              \[\leadsto \left(\alpha \cdot \color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right)}\right) \cdot \log \left(1 - u0\right) \]
            4. *-commutativeN/A

              \[\leadsto \left(\alpha \cdot \color{blue}{\left(\frac{1}{\alpha} \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right)}\right) \cdot \log \left(1 - u0\right) \]
            5. associate-*r*N/A

              \[\leadsto \color{blue}{\left(\left(\alpha \cdot \frac{1}{\alpha}\right) \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right)} \cdot \log \left(1 - u0\right) \]
            6. lift-/.f32N/A

              \[\leadsto \left(\left(\alpha \cdot \color{blue}{\frac{1}{\alpha}}\right) \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right) \cdot \log \left(1 - u0\right) \]
            7. rgt-mult-inverseN/A

              \[\leadsto \left(\color{blue}{1} \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right) \cdot \log \left(1 - u0\right) \]
            8. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot 1\right)} \cdot \log \left(1 - u0\right) \]
            9. *-rgt-identity85.6

              \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right)} \cdot \log \left(1 - u0\right) \]
            10. lift-*.f32N/A

              \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right)} \cdot \log \left(1 - u0\right) \]
            11. lift-neg.f32N/A

              \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
            12. distribute-lft-neg-outN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\alpha \cdot \alpha\right)\right)} \cdot \log \left(1 - u0\right) \]
            13. pow2N/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{\alpha}^{2}}\right)\right) \cdot \log \left(1 - u0\right) \]
            14. metadata-evalN/A

              \[\leadsto \left(\mathsf{neg}\left({\alpha}^{\color{blue}{\left(6 - 4\right)}}\right)\right) \cdot \log \left(1 - u0\right) \]
            15. pow-divN/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{{\alpha}^{6}}{{\alpha}^{4}}}\right)\right) \cdot \log \left(1 - u0\right) \]
            16. lift-pow.f32N/A

              \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{{\alpha}^{6}}}{{\alpha}^{4}}\right)\right) \cdot \log \left(1 - u0\right) \]
            17. lift-pow.f32N/A

              \[\leadsto \left(\mathsf{neg}\left(\frac{{\alpha}^{6}}{\color{blue}{{\alpha}^{4}}}\right)\right) \cdot \log \left(1 - u0\right) \]
            18. distribute-frac-negN/A

              \[\leadsto \color{blue}{\frac{\mathsf{neg}\left({\alpha}^{6}\right)}{{\alpha}^{4}}} \cdot \log \left(1 - u0\right) \]
            19. lift-neg.f32N/A

              \[\leadsto \frac{\color{blue}{-{\alpha}^{6}}}{{\alpha}^{4}} \cdot \log \left(1 - u0\right) \]
            20. clear-numN/A

              \[\leadsto \color{blue}{\frac{1}{\frac{{\alpha}^{4}}{-{\alpha}^{6}}}} \cdot \log \left(1 - u0\right) \]
            21. lower-/.f32N/A

              \[\leadsto \color{blue}{\frac{1}{\frac{{\alpha}^{4}}{-{\alpha}^{6}}}} \cdot \log \left(1 - u0\right) \]
            22. clear-numN/A

              \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{-{\alpha}^{6}}{{\alpha}^{4}}}}} \cdot \log \left(1 - u0\right) \]
            23. lift-neg.f32N/A

              \[\leadsto \frac{1}{\frac{1}{\frac{\color{blue}{\mathsf{neg}\left({\alpha}^{6}\right)}}{{\alpha}^{4}}}} \cdot \log \left(1 - u0\right) \]
            24. distribute-frac-negN/A

              \[\leadsto \frac{1}{\frac{1}{\color{blue}{\mathsf{neg}\left(\frac{{\alpha}^{6}}{{\alpha}^{4}}\right)}}} \cdot \log \left(1 - u0\right) \]
            25. lift-pow.f32N/A

              \[\leadsto \frac{1}{\frac{1}{\mathsf{neg}\left(\frac{\color{blue}{{\alpha}^{6}}}{{\alpha}^{4}}\right)}} \cdot \log \left(1 - u0\right) \]
            26. lift-pow.f32N/A

              \[\leadsto \frac{1}{\frac{1}{\mathsf{neg}\left(\frac{{\alpha}^{6}}{\color{blue}{{\alpha}^{4}}}\right)}} \cdot \log \left(1 - u0\right) \]
            27. pow-divN/A

              \[\leadsto \frac{1}{\frac{1}{\mathsf{neg}\left(\color{blue}{{\alpha}^{\left(6 - 4\right)}}\right)}} \cdot \log \left(1 - u0\right) \]
          6. Applied rewrites85.7%

            \[\leadsto \color{blue}{\frac{1}{\frac{1}{\left(-\alpha\right) \cdot \alpha}}} \cdot \log \left(1 - u0\right) \]
        3. Recombined 2 regimes into one program.
        4. Final simplification89.4%

          \[\leadsto \begin{array}{l} \mathbf{if}\;u0 \leq 0.00011800000356743112:\\ \;\;\;\;\frac{u0}{{\alpha}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 - u0\right) \cdot \frac{1}{\frac{-1}{\alpha \cdot \alpha}}\\ \end{array} \]
        5. Add Preprocessing

        Alternative 2: 63.7% accurate, 0.5× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;u0 \leq 4.999999873689376 \cdot 10^{-5}:\\ \;\;\;\;\left(\left(\mathsf{log1p}\left(u0 \cdot u0 + u0\right) - \left(-{u0}^{3}\right)\right) \cdot \alpha\right) \cdot \alpha\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 - u0\right) \cdot \frac{1}{\frac{-1}{\alpha \cdot \alpha}}\\ \end{array} \end{array} \]
        (FPCore (alpha u0)
         :precision binary32
         (if (<= u0 4.999999873689376e-5)
           (* (* (- (log1p (+ (* u0 u0) u0)) (- (pow u0 3.0))) alpha) alpha)
           (* (log (- 1.0 u0)) (/ 1.0 (/ -1.0 (* alpha alpha))))))
        float code(float alpha, float u0) {
        	float tmp;
        	if (u0 <= 4.999999873689376e-5f) {
        		tmp = ((log1pf(((u0 * u0) + u0)) - -powf(u0, 3.0f)) * alpha) * alpha;
        	} else {
        		tmp = logf((1.0f - u0)) * (1.0f / (-1.0f / (alpha * alpha)));
        	}
        	return tmp;
        }
        
        function code(alpha, u0)
        	tmp = Float32(0.0)
        	if (u0 <= Float32(4.999999873689376e-5))
        		tmp = Float32(Float32(Float32(log1p(Float32(Float32(u0 * u0) + u0)) - Float32(-(u0 ^ Float32(3.0)))) * alpha) * alpha);
        	else
        		tmp = Float32(log(Float32(Float32(1.0) - u0)) * Float32(Float32(1.0) / Float32(Float32(-1.0) / Float32(alpha * alpha))));
        	end
        	return tmp
        end
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;u0 \leq 4.999999873689376 \cdot 10^{-5}:\\
        \;\;\;\;\left(\left(\mathsf{log1p}\left(u0 \cdot u0 + u0\right) - \left(-{u0}^{3}\right)\right) \cdot \alpha\right) \cdot \alpha\\
        
        \mathbf{else}:\\
        \;\;\;\;\log \left(1 - u0\right) \cdot \frac{1}{\frac{-1}{\alpha \cdot \alpha}}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if u0 < 4.99999987e-5

          1. Initial program 34.4%

            \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
          2. Add Preprocessing
          3. Taylor expanded in alpha around 0

            \[\leadsto \color{blue}{-1 \cdot \left({\alpha}^{2} \cdot \log \left(1 - u0\right)\right)} \]
          4. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \color{blue}{\mathsf{neg}\left({\alpha}^{2} \cdot \log \left(1 - u0\right)\right)} \]
            2. unpow2N/A

              \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\alpha \cdot \alpha\right)} \cdot \log \left(1 - u0\right)\right) \]
            3. associate-*l*N/A

              \[\leadsto \mathsf{neg}\left(\color{blue}{\alpha \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)}\right) \]
            4. distribute-rgt-neg-inN/A

              \[\leadsto \color{blue}{\alpha \cdot \left(\mathsf{neg}\left(\alpha \cdot \log \left(1 - u0\right)\right)\right)} \]
            5. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\alpha \cdot \log \left(1 - u0\right)\right)\right) \cdot \alpha} \]
            6. lower-*.f32N/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\alpha \cdot \log \left(1 - u0\right)\right)\right) \cdot \alpha} \]
            7. distribute-lft-neg-inN/A

              \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\alpha\right)\right) \cdot \log \left(1 - u0\right)\right)} \cdot \alpha \]
            8. mul-1-negN/A

              \[\leadsto \left(\color{blue}{\left(-1 \cdot \alpha\right)} \cdot \log \left(1 - u0\right)\right) \cdot \alpha \]
            9. lower-*.f32N/A

              \[\leadsto \color{blue}{\left(\left(-1 \cdot \alpha\right) \cdot \log \left(1 - u0\right)\right)} \cdot \alpha \]
            10. mul-1-negN/A

              \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right)} \cdot \log \left(1 - u0\right)\right) \cdot \alpha \]
            11. lower-neg.f32N/A

              \[\leadsto \left(\color{blue}{\left(-\alpha\right)} \cdot \log \left(1 - u0\right)\right) \cdot \alpha \]
            12. sub-negN/A

              \[\leadsto \left(\left(-\alpha\right) \cdot \log \color{blue}{\left(1 + \left(\mathsf{neg}\left(u0\right)\right)\right)}\right) \cdot \alpha \]
            13. lower-log1p.f32N/A

              \[\leadsto \left(\left(-\alpha\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{neg}\left(u0\right)\right)}\right) \cdot \alpha \]
            14. lower-neg.f3292.5

              \[\leadsto \left(\left(-\alpha\right) \cdot \mathsf{log1p}\left(\color{blue}{-u0}\right)\right) \cdot \alpha \]
          5. Applied rewrites92.5%

            \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \mathsf{log1p}\left(-u0\right)\right) \cdot \alpha} \]
          6. Step-by-step derivation
            1. Applied rewrites92.3%

              \[\leadsto \left(\left(-\alpha\right) \cdot \left(\mathsf{log1p}\left({\left(-u0\right)}^{3}\right) - \mathsf{log1p}\left(u0 \cdot u0 - \left(-u0\right)\right)\right)\right) \cdot \alpha \]
            2. Taylor expanded in u0 around 0

              \[\leadsto \left(\left(-\alpha\right) \cdot \left(-1 \cdot {u0}^{3} - \mathsf{log1p}\left(u0 \cdot u0 - \left(-u0\right)\right)\right)\right) \cdot \alpha \]
            3. Step-by-step derivation
              1. Applied rewrites93.0%

                \[\leadsto \left(\left(-\alpha\right) \cdot \left(\left(-{u0}^{3}\right) - \mathsf{log1p}\left(u0 \cdot u0 - \left(-u0\right)\right)\right)\right) \cdot \alpha \]

              if 4.99999987e-5 < u0

              1. Initial program 84.7%

                \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-neg.f32N/A

                  \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                2. neg-sub0N/A

                  \[\leadsto \left(\color{blue}{\left(0 - \alpha\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                3. flip--N/A

                  \[\leadsto \left(\color{blue}{\frac{0 \cdot 0 - \alpha \cdot \alpha}{0 + \alpha}} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                4. metadata-evalN/A

                  \[\leadsto \left(\frac{\color{blue}{0} - \alpha \cdot \alpha}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                5. neg-sub0N/A

                  \[\leadsto \left(\frac{\color{blue}{\mathsf{neg}\left(\alpha \cdot \alpha\right)}}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                6. distribute-lft-neg-outN/A

                  \[\leadsto \left(\frac{\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right) \cdot \alpha}}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                7. lift-neg.f32N/A

                  \[\leadsto \left(\frac{\color{blue}{\left(-\alpha\right)} \cdot \alpha}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                8. lift-*.f32N/A

                  \[\leadsto \left(\frac{\color{blue}{\left(-\alpha\right) \cdot \alpha}}{0 + \alpha} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                9. div-invN/A

                  \[\leadsto \left(\color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{0 + \alpha}\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                10. lower-*.f32N/A

                  \[\leadsto \left(\color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{0 + \alpha}\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                11. +-lft-identityN/A

                  \[\leadsto \left(\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\color{blue}{\alpha}}\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                12. lower-/.f3284.6

                  \[\leadsto \left(\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\frac{1}{\alpha}}\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
              4. Applied rewrites84.6%

                \[\leadsto \left(\color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
              5. Step-by-step derivation
                1. lift-*.f32N/A

                  \[\leadsto \color{blue}{\left(\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right) \cdot \alpha\right)} \cdot \log \left(1 - u0\right) \]
                2. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(\alpha \cdot \left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right)\right)} \cdot \log \left(1 - u0\right) \]
                3. lift-*.f32N/A

                  \[\leadsto \left(\alpha \cdot \color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \frac{1}{\alpha}\right)}\right) \cdot \log \left(1 - u0\right) \]
                4. *-commutativeN/A

                  \[\leadsto \left(\alpha \cdot \color{blue}{\left(\frac{1}{\alpha} \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right)}\right) \cdot \log \left(1 - u0\right) \]
                5. associate-*r*N/A

                  \[\leadsto \color{blue}{\left(\left(\alpha \cdot \frac{1}{\alpha}\right) \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right)} \cdot \log \left(1 - u0\right) \]
                6. lift-/.f32N/A

                  \[\leadsto \left(\left(\alpha \cdot \color{blue}{\frac{1}{\alpha}}\right) \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right) \cdot \log \left(1 - u0\right) \]
                7. rgt-mult-inverseN/A

                  \[\leadsto \left(\color{blue}{1} \cdot \left(\left(-\alpha\right) \cdot \alpha\right)\right) \cdot \log \left(1 - u0\right) \]
                8. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(\left(\left(-\alpha\right) \cdot \alpha\right) \cdot 1\right)} \cdot \log \left(1 - u0\right) \]
                9. *-rgt-identity84.7

                  \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right)} \cdot \log \left(1 - u0\right) \]
                10. lift-*.f32N/A

                  \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right)} \cdot \log \left(1 - u0\right) \]
                11. lift-neg.f32N/A

                  \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                12. distribute-lft-neg-outN/A

                  \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\alpha \cdot \alpha\right)\right)} \cdot \log \left(1 - u0\right) \]
                13. pow2N/A

                  \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{\alpha}^{2}}\right)\right) \cdot \log \left(1 - u0\right) \]
                14. metadata-evalN/A

                  \[\leadsto \left(\mathsf{neg}\left({\alpha}^{\color{blue}{\left(6 - 4\right)}}\right)\right) \cdot \log \left(1 - u0\right) \]
                15. pow-divN/A

                  \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\frac{{\alpha}^{6}}{{\alpha}^{4}}}\right)\right) \cdot \log \left(1 - u0\right) \]
                16. lift-pow.f32N/A

                  \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{{\alpha}^{6}}}{{\alpha}^{4}}\right)\right) \cdot \log \left(1 - u0\right) \]
                17. lift-pow.f32N/A

                  \[\leadsto \left(\mathsf{neg}\left(\frac{{\alpha}^{6}}{\color{blue}{{\alpha}^{4}}}\right)\right) \cdot \log \left(1 - u0\right) \]
                18. distribute-frac-negN/A

                  \[\leadsto \color{blue}{\frac{\mathsf{neg}\left({\alpha}^{6}\right)}{{\alpha}^{4}}} \cdot \log \left(1 - u0\right) \]
                19. lift-neg.f32N/A

                  \[\leadsto \frac{\color{blue}{-{\alpha}^{6}}}{{\alpha}^{4}} \cdot \log \left(1 - u0\right) \]
                20. clear-numN/A

                  \[\leadsto \color{blue}{\frac{1}{\frac{{\alpha}^{4}}{-{\alpha}^{6}}}} \cdot \log \left(1 - u0\right) \]
                21. lower-/.f32N/A

                  \[\leadsto \color{blue}{\frac{1}{\frac{{\alpha}^{4}}{-{\alpha}^{6}}}} \cdot \log \left(1 - u0\right) \]
                22. clear-numN/A

                  \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{-{\alpha}^{6}}{{\alpha}^{4}}}}} \cdot \log \left(1 - u0\right) \]
                23. lift-neg.f32N/A

                  \[\leadsto \frac{1}{\frac{1}{\frac{\color{blue}{\mathsf{neg}\left({\alpha}^{6}\right)}}{{\alpha}^{4}}}} \cdot \log \left(1 - u0\right) \]
                24. distribute-frac-negN/A

                  \[\leadsto \frac{1}{\frac{1}{\color{blue}{\mathsf{neg}\left(\frac{{\alpha}^{6}}{{\alpha}^{4}}\right)}}} \cdot \log \left(1 - u0\right) \]
                25. lift-pow.f32N/A

                  \[\leadsto \frac{1}{\frac{1}{\mathsf{neg}\left(\frac{\color{blue}{{\alpha}^{6}}}{{\alpha}^{4}}\right)}} \cdot \log \left(1 - u0\right) \]
                26. lift-pow.f32N/A

                  \[\leadsto \frac{1}{\frac{1}{\mathsf{neg}\left(\frac{{\alpha}^{6}}{\color{blue}{{\alpha}^{4}}}\right)}} \cdot \log \left(1 - u0\right) \]
                27. pow-divN/A

                  \[\leadsto \frac{1}{\frac{1}{\mathsf{neg}\left(\color{blue}{{\alpha}^{\left(6 - 4\right)}}\right)}} \cdot \log \left(1 - u0\right) \]
              6. Applied rewrites84.8%

                \[\leadsto \color{blue}{\frac{1}{\frac{1}{\left(-\alpha\right) \cdot \alpha}}} \cdot \log \left(1 - u0\right) \]
            4. Recombined 2 regimes into one program.
            5. Final simplification55.5%

              \[\leadsto \begin{array}{l} \mathbf{if}\;u0 \leq 4.999999873689376 \cdot 10^{-5}:\\ \;\;\;\;\left(\left(\mathsf{log1p}\left(u0 \cdot u0 + u0\right) - \left(-{u0}^{3}\right)\right) \cdot \alpha\right) \cdot \alpha\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 - u0\right) \cdot \frac{1}{\frac{-1}{\alpha \cdot \alpha}}\\ \end{array} \]
            6. Add Preprocessing

            Alternative 3: 89.6% accurate, 1.0× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;u0 \leq 0.00011800000356743112:\\ \;\;\;\;\frac{u0}{{\alpha}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha\\ \end{array} \end{array} \]
            (FPCore (alpha u0)
             :precision binary32
             (if (<= u0 0.00011800000356743112)
               (/ u0 (pow alpha -2.0))
               (* (* (log (- 1.0 u0)) (- alpha)) alpha)))
            float code(float alpha, float u0) {
            	float tmp;
            	if (u0 <= 0.00011800000356743112f) {
            		tmp = u0 / powf(alpha, -2.0f);
            	} else {
            		tmp = (logf((1.0f - u0)) * -alpha) * alpha;
            	}
            	return tmp;
            }
            
            real(4) function code(alpha, u0)
                real(4), intent (in) :: alpha
                real(4), intent (in) :: u0
                real(4) :: tmp
                if (u0 <= 0.00011800000356743112e0) then
                    tmp = u0 / (alpha ** (-2.0e0))
                else
                    tmp = (log((1.0e0 - u0)) * -alpha) * alpha
                end if
                code = tmp
            end function
            
            function code(alpha, u0)
            	tmp = Float32(0.0)
            	if (u0 <= Float32(0.00011800000356743112))
            		tmp = Float32(u0 / (alpha ^ Float32(-2.0)));
            	else
            		tmp = Float32(Float32(log(Float32(Float32(1.0) - u0)) * Float32(-alpha)) * alpha);
            	end
            	return tmp
            end
            
            function tmp_2 = code(alpha, u0)
            	tmp = single(0.0);
            	if (u0 <= single(0.00011800000356743112))
            		tmp = u0 / (alpha ^ single(-2.0));
            	else
            		tmp = (log((single(1.0) - u0)) * -alpha) * alpha;
            	end
            	tmp_2 = tmp;
            end
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;u0 \leq 0.00011800000356743112:\\
            \;\;\;\;\frac{u0}{{\alpha}^{-2}}\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if u0 < 1.18000004e-4

              1. Initial program 35.7%

                \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
              2. Add Preprocessing
              3. Taylor expanded in u0 around 0

                \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
              4. Step-by-step derivation
                1. lower-*.f32N/A

                  \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
                2. unpow2N/A

                  \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
                3. lower-*.f3291.8

                  \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
              5. Applied rewrites91.8%

                \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right) \cdot u0} \]
              6. Step-by-step derivation
                1. Applied rewrites91.7%

                  \[\leadsto \left(u0 \cdot \alpha\right) \cdot \color{blue}{\alpha} \]
                2. Step-by-step derivation
                  1. Applied rewrites91.6%

                    \[\leadsto \frac{u0}{\color{blue}{\frac{\frac{1}{\alpha}}{\alpha}}} \]
                  2. Step-by-step derivation
                    1. Applied rewrites91.8%

                      \[\leadsto \frac{u0}{\color{blue}{{\alpha}^{-2}}} \]

                    if 1.18000004e-4 < u0

                    1. Initial program 85.6%

                      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                    2. Add Preprocessing
                    3. Taylor expanded in alpha around 0

                      \[\leadsto \color{blue}{-1 \cdot \left({\alpha}^{2} \cdot \log \left(1 - u0\right)\right)} \]
                    4. Step-by-step derivation
                      1. mul-1-negN/A

                        \[\leadsto \color{blue}{\mathsf{neg}\left({\alpha}^{2} \cdot \log \left(1 - u0\right)\right)} \]
                      2. unpow2N/A

                        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\alpha \cdot \alpha\right)} \cdot \log \left(1 - u0\right)\right) \]
                      3. associate-*l*N/A

                        \[\leadsto \mathsf{neg}\left(\color{blue}{\alpha \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)}\right) \]
                      4. distribute-rgt-neg-inN/A

                        \[\leadsto \color{blue}{\alpha \cdot \left(\mathsf{neg}\left(\alpha \cdot \log \left(1 - u0\right)\right)\right)} \]
                      5. *-commutativeN/A

                        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\alpha \cdot \log \left(1 - u0\right)\right)\right) \cdot \alpha} \]
                      6. lower-*.f32N/A

                        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\alpha \cdot \log \left(1 - u0\right)\right)\right) \cdot \alpha} \]
                      7. distribute-lft-neg-inN/A

                        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\alpha\right)\right) \cdot \log \left(1 - u0\right)\right)} \cdot \alpha \]
                      8. mul-1-negN/A

                        \[\leadsto \left(\color{blue}{\left(-1 \cdot \alpha\right)} \cdot \log \left(1 - u0\right)\right) \cdot \alpha \]
                      9. lower-*.f32N/A

                        \[\leadsto \color{blue}{\left(\left(-1 \cdot \alpha\right) \cdot \log \left(1 - u0\right)\right)} \cdot \alpha \]
                      10. mul-1-negN/A

                        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right)} \cdot \log \left(1 - u0\right)\right) \cdot \alpha \]
                      11. lower-neg.f32N/A

                        \[\leadsto \left(\color{blue}{\left(-\alpha\right)} \cdot \log \left(1 - u0\right)\right) \cdot \alpha \]
                      12. sub-negN/A

                        \[\leadsto \left(\left(-\alpha\right) \cdot \log \color{blue}{\left(1 + \left(\mathsf{neg}\left(u0\right)\right)\right)}\right) \cdot \alpha \]
                      13. lower-log1p.f32N/A

                        \[\leadsto \left(\left(-\alpha\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{neg}\left(u0\right)\right)}\right) \cdot \alpha \]
                      14. lower-neg.f3250.4

                        \[\leadsto \left(\left(-\alpha\right) \cdot \mathsf{log1p}\left(\color{blue}{-u0}\right)\right) \cdot \alpha \]
                    5. Applied rewrites50.4%

                      \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \mathsf{log1p}\left(-u0\right)\right) \cdot \alpha} \]
                    6. Step-by-step derivation
                      1. Applied rewrites85.7%

                        \[\leadsto \left(\left(-\alpha\right) \cdot \log \left(1 - u0\right)\right) \cdot \alpha \]
                    7. Recombined 2 regimes into one program.
                    8. Final simplification89.4%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;u0 \leq 0.00011800000356743112:\\ \;\;\;\;\frac{u0}{{\alpha}^{-2}}\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha\\ \end{array} \]
                    9. Add Preprocessing

                    Alternative 4: 74.8% accurate, 1.0× speedup?

                    \[\begin{array}{l} \\ \frac{u0}{{\alpha}^{-2}} \end{array} \]
                    (FPCore (alpha u0) :precision binary32 (/ u0 (pow alpha -2.0)))
                    float code(float alpha, float u0) {
                    	return u0 / powf(alpha, -2.0f);
                    }
                    
                    real(4) function code(alpha, u0)
                        real(4), intent (in) :: alpha
                        real(4), intent (in) :: u0
                        code = u0 / (alpha ** (-2.0e0))
                    end function
                    
                    function code(alpha, u0)
                    	return Float32(u0 / (alpha ^ Float32(-2.0)))
                    end
                    
                    function tmp = code(alpha, u0)
                    	tmp = u0 / (alpha ^ single(-2.0));
                    end
                    
                    \begin{array}{l}
                    
                    \\
                    \frac{u0}{{\alpha}^{-2}}
                    \end{array}
                    
                    Derivation
                    1. Initial program 55.2%

                      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                    2. Add Preprocessing
                    3. Taylor expanded in u0 around 0

                      \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
                    4. Step-by-step derivation
                      1. lower-*.f32N/A

                        \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
                      2. unpow2N/A

                        \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
                      3. lower-*.f3275.6

                        \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
                    5. Applied rewrites75.6%

                      \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right) \cdot u0} \]
                    6. Step-by-step derivation
                      1. Applied rewrites75.6%

                        \[\leadsto \left(u0 \cdot \alpha\right) \cdot \color{blue}{\alpha} \]
                      2. Step-by-step derivation
                        1. Applied rewrites75.5%

                          \[\leadsto \frac{u0}{\color{blue}{\frac{\frac{1}{\alpha}}{\alpha}}} \]
                        2. Step-by-step derivation
                          1. Applied rewrites75.6%

                            \[\leadsto \frac{u0}{\color{blue}{{\alpha}^{-2}}} \]
                          2. Add Preprocessing

                          Alternative 5: 74.8% accurate, 10.5× speedup?

                          \[\begin{array}{l} \\ \left(\alpha \cdot \alpha\right) \cdot u0 \end{array} \]
                          (FPCore (alpha u0) :precision binary32 (* (* alpha alpha) u0))
                          float code(float alpha, float u0) {
                          	return (alpha * alpha) * u0;
                          }
                          
                          real(4) function code(alpha, u0)
                              real(4), intent (in) :: alpha
                              real(4), intent (in) :: u0
                              code = (alpha * alpha) * u0
                          end function
                          
                          function code(alpha, u0)
                          	return Float32(Float32(alpha * alpha) * u0)
                          end
                          
                          function tmp = code(alpha, u0)
                          	tmp = (alpha * alpha) * u0;
                          end
                          
                          \begin{array}{l}
                          
                          \\
                          \left(\alpha \cdot \alpha\right) \cdot u0
                          \end{array}
                          
                          Derivation
                          1. Initial program 55.2%

                            \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                          2. Add Preprocessing
                          3. Taylor expanded in u0 around 0

                            \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
                          4. Step-by-step derivation
                            1. lower-*.f32N/A

                              \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
                            2. unpow2N/A

                              \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
                            3. lower-*.f3275.6

                              \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right)} \cdot u0 \]
                          5. Applied rewrites75.6%

                            \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right) \cdot u0} \]
                          6. Add Preprocessing

                          Reproduce

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