Beckmann Distribution sample, tan2theta, alphax == alphay

Percentage Accurate: 56.2% → 99.0%
Time: 3.7s
Alternatives: 13
Speedup: 1.8×

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)\]
\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
(FPCore (alpha u0)
  :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))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf((1.0f - u0));
}
real(4) function code(alpha, u0)
use fmin_fmax_functions
    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
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)

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 13 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: 56.2% accurate, 1.0× speedup?

\[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
(FPCore (alpha u0)
  :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))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf((1.0f - u0));
}
real(4) function code(alpha, u0)
use fmin_fmax_functions
    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
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)

Alternative 1: 99.0% accurate, 0.9× speedup?

\[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \mathsf{log1p}\left(-u0\right) \]
(FPCore (alpha u0)
  :precision binary32
  :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
     (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
  (* (* (- alpha) alpha) (log1p (- u0))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * log1pf(-u0);
}
function code(alpha, u0)
	return Float32(Float32(Float32(-alpha) * alpha) * log1p(Float32(-u0)))
end
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \mathsf{log1p}\left(-u0\right)
Derivation
  1. Initial program 56.2%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. Step-by-step derivation
    1. Applied rewrites99.0%

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \mathsf{log1p}\left(-u0\right) \]
    2. Add Preprocessing

    Alternative 2: 99.0% accurate, 0.9× speedup?

    \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
    \[-\left(\mathsf{log1p}\left(-u0\right) \cdot \alpha\right) \cdot \alpha \]
    (FPCore (alpha u0)
      :precision binary32
      :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
         (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
      (- (* (* (log1p (- u0)) alpha) alpha)))
    float code(float alpha, float u0) {
    	return -((log1pf(-u0) * alpha) * alpha);
    }
    
    function code(alpha, u0)
    	return Float32(-Float32(Float32(log1p(Float32(-u0)) * alpha) * alpha))
    end
    
    -\left(\mathsf{log1p}\left(-u0\right) \cdot \alpha\right) \cdot \alpha
    
    Derivation
    1. Initial program 56.2%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Step-by-step derivation
      1. Applied rewrites56.2%

        \[\leadsto -\left(\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha \]
      2. Step-by-step derivation
        1. Applied rewrites99.0%

          \[\leadsto -\left(\mathsf{log1p}\left(-u0\right) \cdot \alpha\right) \cdot \alpha \]
        2. Add Preprocessing

        Alternative 3: 96.8% accurate, 0.7× speedup?

        \[\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} \mathbf{if}\;1 - u0 \leq 0.996999979019165:\\ \;\;\;\;\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\alpha, u0, \left(0.5 \cdot u0\right) \cdot \left(u0 \cdot \alpha\right)\right) \cdot \alpha\\ \end{array} \]
        (FPCore (alpha u0)
          :precision binary32
          :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
             (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
          (if (<= (- 1.0 u0) 0.996999979019165)
          (* (* (- alpha) alpha) (log (- 1.0 u0)))
          (* (fma alpha u0 (* (* 0.5 u0) (* u0 alpha))) alpha)))
        float code(float alpha, float u0) {
        	float tmp;
        	if ((1.0f - u0) <= 0.996999979019165f) {
        		tmp = (-alpha * alpha) * logf((1.0f - u0));
        	} else {
        		tmp = fmaf(alpha, u0, ((0.5f * u0) * (u0 * alpha))) * alpha;
        	}
        	return tmp;
        }
        
        function code(alpha, u0)
        	tmp = Float32(0.0)
        	if (Float32(Float32(1.0) - u0) <= Float32(0.996999979019165))
        		tmp = Float32(Float32(Float32(-alpha) * alpha) * log(Float32(Float32(1.0) - u0)));
        	else
        		tmp = Float32(fma(alpha, u0, Float32(Float32(Float32(0.5) * u0) * Float32(u0 * alpha))) * alpha);
        	end
        	return tmp
        end
        
        \begin{array}{l}
        \mathbf{if}\;1 - u0 \leq 0.996999979019165:\\
        \;\;\;\;\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(\alpha, u0, \left(0.5 \cdot u0\right) \cdot \left(u0 \cdot \alpha\right)\right) \cdot \alpha\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (-.f32 #s(literal 1 binary32) u0) < 0.996999979

          1. Initial program 56.2%

            \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]

          if 0.996999979 < (-.f32 #s(literal 1 binary32) u0)

          1. Initial program 56.2%

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

            \[\leadsto u0 \cdot \left(\frac{1}{2} \cdot \left({\alpha}^{2} \cdot u0\right) + {\alpha}^{2}\right) \]
          3. Step-by-step derivation
            1. Applied rewrites87.1%

              \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, {\alpha}^{2} \cdot u0, {\alpha}^{2}\right) \]
            2. Step-by-step derivation
              1. Applied rewrites87.3%

                \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \]
              2. Step-by-step derivation
                1. Applied rewrites87.0%

                  \[\leadsto \left(\left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot u0\right) \cdot \alpha\right) \cdot \alpha \]
                2. Step-by-step derivation
                  1. Applied rewrites87.3%

                    \[\leadsto \mathsf{fma}\left(\alpha, u0, \left(0.5 \cdot u0\right) \cdot \left(u0 \cdot \alpha\right)\right) \cdot \alpha \]
                3. Recombined 2 regimes into one program.
                4. Add Preprocessing

                Alternative 4: 96.7% accurate, 0.7× speedup?

                \[\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} t_0 := \left(-\alpha\right) \cdot \alpha\\ \mathbf{if}\;1 - u0 \leq 0.996999979019165:\\ \;\;\;\;t\_0 \cdot \log \left(1 - u0\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(u0 \cdot \left(-0.5 \cdot u0\right) - u0\right)\\ \end{array} \]
                (FPCore (alpha u0)
                  :precision binary32
                  :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                     (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                  (let* ((t_0 (* (- alpha) alpha)))
                  (if (<= (- 1.0 u0) 0.996999979019165)
                    (* t_0 (log (- 1.0 u0)))
                    (* t_0 (- (* u0 (* -0.5 u0)) u0)))))
                float code(float alpha, float u0) {
                	float t_0 = -alpha * alpha;
                	float tmp;
                	if ((1.0f - u0) <= 0.996999979019165f) {
                		tmp = t_0 * logf((1.0f - u0));
                	} else {
                		tmp = t_0 * ((u0 * (-0.5f * u0)) - u0);
                	}
                	return tmp;
                }
                
                real(4) function code(alpha, u0)
                use fmin_fmax_functions
                    real(4), intent (in) :: alpha
                    real(4), intent (in) :: u0
                    real(4) :: t_0
                    real(4) :: tmp
                    t_0 = -alpha * alpha
                    if ((1.0e0 - u0) <= 0.996999979019165e0) then
                        tmp = t_0 * log((1.0e0 - u0))
                    else
                        tmp = t_0 * ((u0 * ((-0.5e0) * u0)) - u0)
                    end if
                    code = tmp
                end function
                
                function code(alpha, u0)
                	t_0 = Float32(Float32(-alpha) * alpha)
                	tmp = Float32(0.0)
                	if (Float32(Float32(1.0) - u0) <= Float32(0.996999979019165))
                		tmp = Float32(t_0 * log(Float32(Float32(1.0) - u0)));
                	else
                		tmp = Float32(t_0 * Float32(Float32(u0 * Float32(Float32(-0.5) * u0)) - u0));
                	end
                	return tmp
                end
                
                function tmp_2 = code(alpha, u0)
                	t_0 = -alpha * alpha;
                	tmp = single(0.0);
                	if ((single(1.0) - u0) <= single(0.996999979019165))
                		tmp = t_0 * log((single(1.0) - u0));
                	else
                		tmp = t_0 * ((u0 * (single(-0.5) * u0)) - u0);
                	end
                	tmp_2 = tmp;
                end
                
                \begin{array}{l}
                t_0 := \left(-\alpha\right) \cdot \alpha\\
                \mathbf{if}\;1 - u0 \leq 0.996999979019165:\\
                \;\;\;\;t\_0 \cdot \log \left(1 - u0\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;t\_0 \cdot \left(u0 \cdot \left(-0.5 \cdot u0\right) - u0\right)\\
                
                
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if (-.f32 #s(literal 1 binary32) u0) < 0.996999979

                  1. Initial program 56.2%

                    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]

                  if 0.996999979 < (-.f32 #s(literal 1 binary32) u0)

                  1. Initial program 56.2%

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

                    \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 - 1\right)\right) \]
                  3. Step-by-step derivation
                    1. Applied rewrites87.0%

                      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0 - 1\right)\right) \]
                    2. Step-by-step derivation
                      1. Applied rewrites87.1%

                        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0\right) - u0\right) \]
                    3. Recombined 2 regimes into one program.
                    4. Add Preprocessing

                    Alternative 5: 96.7% accurate, 0.8× speedup?

                    \[\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} \mathbf{if}\;u0 \leq 0.002285516122356057:\\ \;\;\;\;\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0\right) - u0\right)\\ \mathbf{else}:\\ \;\;\;\;-\left(\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha\\ \end{array} \]
                    (FPCore (alpha u0)
                      :precision binary32
                      :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                         (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                      (if (<= u0 0.002285516122356057)
                      (* (* (- alpha) alpha) (- (* u0 (* -0.5 u0)) u0))
                      (- (* (* (log (- 1.0 u0)) alpha) alpha))))
                    float code(float alpha, float u0) {
                    	float tmp;
                    	if (u0 <= 0.002285516122356057f) {
                    		tmp = (-alpha * alpha) * ((u0 * (-0.5f * u0)) - u0);
                    	} else {
                    		tmp = -((logf((1.0f - u0)) * alpha) * alpha);
                    	}
                    	return tmp;
                    }
                    
                    real(4) function code(alpha, u0)
                    use fmin_fmax_functions
                        real(4), intent (in) :: alpha
                        real(4), intent (in) :: u0
                        real(4) :: tmp
                        if (u0 <= 0.002285516122356057e0) then
                            tmp = (-alpha * alpha) * ((u0 * ((-0.5e0) * u0)) - u0)
                        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.002285516122356057))
                    		tmp = Float32(Float32(Float32(-alpha) * alpha) * Float32(Float32(u0 * Float32(Float32(-0.5) * u0)) - u0));
                    	else
                    		tmp = Float32(-Float32(Float32(log(Float32(Float32(1.0) - u0)) * alpha) * alpha));
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(alpha, u0)
                    	tmp = single(0.0);
                    	if (u0 <= single(0.002285516122356057))
                    		tmp = (-alpha * alpha) * ((u0 * (single(-0.5) * u0)) - u0);
                    	else
                    		tmp = -((log((single(1.0) - u0)) * alpha) * alpha);
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    \begin{array}{l}
                    \mathbf{if}\;u0 \leq 0.002285516122356057:\\
                    \;\;\;\;\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0\right) - u0\right)\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;-\left(\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha\\
                    
                    
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if u0 < 0.00228551612

                      1. Initial program 56.2%

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

                        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 - 1\right)\right) \]
                      3. Step-by-step derivation
                        1. Applied rewrites87.0%

                          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0 - 1\right)\right) \]
                        2. Step-by-step derivation
                          1. Applied rewrites87.1%

                            \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0\right) - u0\right) \]

                          if 0.00228551612 < u0

                          1. Initial program 56.2%

                            \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                          2. Step-by-step derivation
                            1. Applied rewrites56.2%

                              \[\leadsto -\left(\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha \]
                          3. Recombined 2 regimes into one program.
                          4. Add Preprocessing

                          Alternative 6: 96.6% accurate, 0.8× speedup?

                          \[\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} \mathbf{if}\;u0 \leq 0.002285516122356057:\\ \;\;\;\;\left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha\\ \mathbf{else}:\\ \;\;\;\;-\left(\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha\\ \end{array} \]
                          (FPCore (alpha u0)
                            :precision binary32
                            :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                               (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                            (if (<= u0 0.002285516122356057)
                            (* (* u0 (+ alpha (* 0.5 (* alpha u0)))) alpha)
                            (- (* (* (log (- 1.0 u0)) alpha) alpha))))
                          float code(float alpha, float u0) {
                          	float tmp;
                          	if (u0 <= 0.002285516122356057f) {
                          		tmp = (u0 * (alpha + (0.5f * (alpha * u0)))) * alpha;
                          	} else {
                          		tmp = -((logf((1.0f - u0)) * alpha) * alpha);
                          	}
                          	return tmp;
                          }
                          
                          real(4) function code(alpha, u0)
                          use fmin_fmax_functions
                              real(4), intent (in) :: alpha
                              real(4), intent (in) :: u0
                              real(4) :: tmp
                              if (u0 <= 0.002285516122356057e0) then
                                  tmp = (u0 * (alpha + (0.5e0 * (alpha * u0)))) * alpha
                              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.002285516122356057))
                          		tmp = Float32(Float32(u0 * Float32(alpha + Float32(Float32(0.5) * Float32(alpha * u0)))) * alpha);
                          	else
                          		tmp = Float32(-Float32(Float32(log(Float32(Float32(1.0) - u0)) * alpha) * alpha));
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(alpha, u0)
                          	tmp = single(0.0);
                          	if (u0 <= single(0.002285516122356057))
                          		tmp = (u0 * (alpha + (single(0.5) * (alpha * u0)))) * alpha;
                          	else
                          		tmp = -((log((single(1.0) - u0)) * alpha) * alpha);
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          \begin{array}{l}
                          \mathbf{if}\;u0 \leq 0.002285516122356057:\\
                          \;\;\;\;\left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;-\left(\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha\\
                          
                          
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if u0 < 0.00228551612

                            1. Initial program 56.2%

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

                              \[\leadsto u0 \cdot \left(\frac{1}{2} \cdot \left({\alpha}^{2} \cdot u0\right) + {\alpha}^{2}\right) \]
                            3. Step-by-step derivation
                              1. Applied rewrites87.1%

                                \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, {\alpha}^{2} \cdot u0, {\alpha}^{2}\right) \]
                              2. Step-by-step derivation
                                1. Applied rewrites87.3%

                                  \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \]
                                2. Step-by-step derivation
                                  1. Applied rewrites87.0%

                                    \[\leadsto \left(\left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot u0\right) \cdot \alpha\right) \cdot \alpha \]
                                  2. Taylor expanded in u0 around 0

                                    \[\leadsto \left(u0 \cdot \left(\alpha + \frac{1}{2} \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites87.2%

                                      \[\leadsto \left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha \]

                                    if 0.00228551612 < u0

                                    1. Initial program 56.2%

                                      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
                                    2. Step-by-step derivation
                                      1. Applied rewrites56.2%

                                        \[\leadsto -\left(\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha \]
                                    3. Recombined 2 regimes into one program.
                                    4. Add Preprocessing

                                    Alternative 7: 87.2% accurate, 1.1× speedup?

                                    \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
                                    \[\left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha \]
                                    (FPCore (alpha u0)
                                      :precision binary32
                                      :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                                         (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                                      (* (* u0 (+ alpha (* 0.5 (* alpha u0)))) alpha))
                                    float code(float alpha, float u0) {
                                    	return (u0 * (alpha + (0.5f * (alpha * u0)))) * alpha;
                                    }
                                    
                                    real(4) function code(alpha, u0)
                                    use fmin_fmax_functions
                                        real(4), intent (in) :: alpha
                                        real(4), intent (in) :: u0
                                        code = (u0 * (alpha + (0.5e0 * (alpha * u0)))) * alpha
                                    end function
                                    
                                    function code(alpha, u0)
                                    	return Float32(Float32(u0 * Float32(alpha + Float32(Float32(0.5) * Float32(alpha * u0)))) * alpha)
                                    end
                                    
                                    function tmp = code(alpha, u0)
                                    	tmp = (u0 * (alpha + (single(0.5) * (alpha * u0)))) * alpha;
                                    end
                                    
                                    \left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha
                                    
                                    Derivation
                                    1. Initial program 56.2%

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

                                      \[\leadsto u0 \cdot \left(\frac{1}{2} \cdot \left({\alpha}^{2} \cdot u0\right) + {\alpha}^{2}\right) \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites87.1%

                                        \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, {\alpha}^{2} \cdot u0, {\alpha}^{2}\right) \]
                                      2. Step-by-step derivation
                                        1. Applied rewrites87.3%

                                          \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \]
                                        2. Step-by-step derivation
                                          1. Applied rewrites87.0%

                                            \[\leadsto \left(\left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot u0\right) \cdot \alpha\right) \cdot \alpha \]
                                          2. Taylor expanded in u0 around 0

                                            \[\leadsto \left(u0 \cdot \left(\alpha + \frac{1}{2} \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites87.2%

                                              \[\leadsto \left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha \]
                                            2. Add Preprocessing

                                            Alternative 8: 87.2% accurate, 1.1× speedup?

                                            \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
                                            \[u0 \cdot \left(\alpha \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \]
                                            (FPCore (alpha u0)
                                              :precision binary32
                                              :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                                                 (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                                              (* u0 (* alpha (+ alpha (* 0.5 (* alpha u0))))))
                                            float code(float alpha, float u0) {
                                            	return u0 * (alpha * (alpha + (0.5f * (alpha * u0))));
                                            }
                                            
                                            real(4) function code(alpha, u0)
                                            use fmin_fmax_functions
                                                real(4), intent (in) :: alpha
                                                real(4), intent (in) :: u0
                                                code = u0 * (alpha * (alpha + (0.5e0 * (alpha * u0))))
                                            end function
                                            
                                            function code(alpha, u0)
                                            	return Float32(u0 * Float32(alpha * Float32(alpha + Float32(Float32(0.5) * Float32(alpha * u0)))))
                                            end
                                            
                                            function tmp = code(alpha, u0)
                                            	tmp = u0 * (alpha * (alpha + (single(0.5) * (alpha * u0))));
                                            end
                                            
                                            u0 \cdot \left(\alpha \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right)
                                            
                                            Derivation
                                            1. Initial program 56.2%

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

                                              \[\leadsto u0 \cdot \left(\frac{1}{2} \cdot \left({\alpha}^{2} \cdot u0\right) + {\alpha}^{2}\right) \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites87.1%

                                                \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, {\alpha}^{2} \cdot u0, {\alpha}^{2}\right) \]
                                              2. Step-by-step derivation
                                                1. Applied rewrites87.0%

                                                  \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, \frac{1}{{\alpha}^{-2}} \cdot u0, \frac{1}{{\alpha}^{-2}}\right) \]
                                                2. Step-by-step derivation
                                                  1. Applied rewrites87.0%

                                                    \[\leadsto u0 \cdot \left(\alpha \cdot \left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot \alpha\right)\right) \]
                                                  2. Taylor expanded in u0 around 0

                                                    \[\leadsto u0 \cdot \left(\alpha \cdot \left(\alpha + \frac{1}{2} \cdot \left(\alpha \cdot u0\right)\right)\right) \]
                                                  3. Step-by-step derivation
                                                    1. Applied rewrites87.2%

                                                      \[\leadsto u0 \cdot \left(\alpha \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \]
                                                    2. Add Preprocessing

                                                    Alternative 9: 87.0% accurate, 1.1× speedup?

                                                    \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
                                                    \[\left(\alpha \cdot \alpha\right) \cdot \left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot u0\right) \]
                                                    (FPCore (alpha u0)
                                                      :precision binary32
                                                      :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                                                         (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                                                      (* (* alpha alpha) (* (fma 0.5 u0 1.0) u0)))
                                                    float code(float alpha, float u0) {
                                                    	return (alpha * alpha) * (fmaf(0.5f, u0, 1.0f) * u0);
                                                    }
                                                    
                                                    function code(alpha, u0)
                                                    	return Float32(Float32(alpha * alpha) * Float32(fma(Float32(0.5), u0, Float32(1.0)) * u0))
                                                    end
                                                    
                                                    \left(\alpha \cdot \alpha\right) \cdot \left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot u0\right)
                                                    
                                                    Derivation
                                                    1. Initial program 56.2%

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

                                                      \[\leadsto u0 \cdot \left(\frac{1}{2} \cdot \left({\alpha}^{2} \cdot u0\right) + {\alpha}^{2}\right) \]
                                                    3. Step-by-step derivation
                                                      1. Applied rewrites87.1%

                                                        \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, {\alpha}^{2} \cdot u0, {\alpha}^{2}\right) \]
                                                      2. Step-by-step derivation
                                                        1. Applied rewrites87.3%

                                                          \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \]
                                                        2. Step-by-step derivation
                                                          1. Applied rewrites87.0%

                                                            \[\leadsto \left(\alpha \cdot \alpha\right) \cdot \left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot u0\right) \]
                                                          2. Add Preprocessing

                                                          Alternative 10: 87.0% accurate, 1.1× speedup?

                                                          \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
                                                          \[u0 \cdot \left(\alpha \cdot \left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot \alpha\right)\right) \]
                                                          (FPCore (alpha u0)
                                                            :precision binary32
                                                            :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                                                               (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                                                            (* u0 (* alpha (* (fma 0.5 u0 1.0) alpha))))
                                                          float code(float alpha, float u0) {
                                                          	return u0 * (alpha * (fmaf(0.5f, u0, 1.0f) * alpha));
                                                          }
                                                          
                                                          function code(alpha, u0)
                                                          	return Float32(u0 * Float32(alpha * Float32(fma(Float32(0.5), u0, Float32(1.0)) * alpha)))
                                                          end
                                                          
                                                          u0 \cdot \left(\alpha \cdot \left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot \alpha\right)\right)
                                                          
                                                          Derivation
                                                          1. Initial program 56.2%

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

                                                            \[\leadsto u0 \cdot \left(\frac{1}{2} \cdot \left({\alpha}^{2} \cdot u0\right) + {\alpha}^{2}\right) \]
                                                          3. Step-by-step derivation
                                                            1. Applied rewrites87.1%

                                                              \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, {\alpha}^{2} \cdot u0, {\alpha}^{2}\right) \]
                                                            2. Step-by-step derivation
                                                              1. Applied rewrites87.0%

                                                                \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, \frac{1}{{\alpha}^{-2}} \cdot u0, \frac{1}{{\alpha}^{-2}}\right) \]
                                                              2. Step-by-step derivation
                                                                1. Applied rewrites87.0%

                                                                  \[\leadsto u0 \cdot \left(\alpha \cdot \left(\mathsf{fma}\left(0.5, u0, 1\right) \cdot \alpha\right)\right) \]
                                                                2. Add Preprocessing

                                                                Alternative 11: 87.0% accurate, 1.1× speedup?

                                                                \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
                                                                \[\alpha \cdot \left(\left(u0 \cdot \alpha\right) \cdot \mathsf{fma}\left(0.5, u0, 1\right)\right) \]
                                                                (FPCore (alpha u0)
                                                                  :precision binary32
                                                                  :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                                                                     (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                                                                  (* alpha (* (* u0 alpha) (fma 0.5 u0 1.0))))
                                                                float code(float alpha, float u0) {
                                                                	return alpha * ((u0 * alpha) * fmaf(0.5f, u0, 1.0f));
                                                                }
                                                                
                                                                function code(alpha, u0)
                                                                	return Float32(alpha * Float32(Float32(u0 * alpha) * fma(Float32(0.5), u0, Float32(1.0))))
                                                                end
                                                                
                                                                \alpha \cdot \left(\left(u0 \cdot \alpha\right) \cdot \mathsf{fma}\left(0.5, u0, 1\right)\right)
                                                                
                                                                Derivation
                                                                1. Initial program 56.2%

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

                                                                  \[\leadsto u0 \cdot \left(\frac{1}{2} \cdot \left({\alpha}^{2} \cdot u0\right) + {\alpha}^{2}\right) \]
                                                                3. Step-by-step derivation
                                                                  1. Applied rewrites87.1%

                                                                    \[\leadsto u0 \cdot \mathsf{fma}\left(0.5, {\alpha}^{2} \cdot u0, {\alpha}^{2}\right) \]
                                                                  2. Step-by-step derivation
                                                                    1. Applied rewrites87.3%

                                                                      \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \]
                                                                    2. Step-by-step derivation
                                                                      1. Applied rewrites87.0%

                                                                        \[\leadsto \alpha \cdot \left(\left(u0 \cdot \alpha\right) \cdot \mathsf{fma}\left(0.5, u0, 1\right)\right) \]
                                                                      2. Add Preprocessing

                                                                      Alternative 12: 74.5% accurate, 1.8× speedup?

                                                                      \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
                                                                      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-u0\right) \]
                                                                      (FPCore (alpha u0)
                                                                        :precision binary32
                                                                        :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                                                                           (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                                                                        (* (* (- alpha) alpha) (- u0)))
                                                                      float code(float alpha, float u0) {
                                                                      	return (-alpha * alpha) * -u0;
                                                                      }
                                                                      
                                                                      real(4) function code(alpha, u0)
                                                                      use fmin_fmax_functions
                                                                          real(4), intent (in) :: alpha
                                                                          real(4), intent (in) :: u0
                                                                          code = (-alpha * alpha) * -u0
                                                                      end function
                                                                      
                                                                      function code(alpha, u0)
                                                                      	return Float32(Float32(Float32(-alpha) * alpha) * Float32(-u0))
                                                                      end
                                                                      
                                                                      function tmp = code(alpha, u0)
                                                                      	tmp = (-alpha * alpha) * -u0;
                                                                      end
                                                                      
                                                                      \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-u0\right)
                                                                      
                                                                      Derivation
                                                                      1. Initial program 56.2%

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

                                                                        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-1 \cdot u0\right) \]
                                                                      3. Step-by-step derivation
                                                                        1. Applied rewrites74.4%

                                                                          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-1 \cdot u0\right) \]
                                                                        2. Step-by-step derivation
                                                                          1. Applied rewrites74.4%

                                                                            \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-u0\right) \]
                                                                          2. Add Preprocessing

                                                                          Alternative 13: 74.4% accurate, 1.8× speedup?

                                                                          \[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
                                                                          \[-\alpha \cdot \left(\left(-u0\right) \cdot \alpha\right) \]
                                                                          (FPCore (alpha u0)
                                                                            :precision binary32
                                                                            :pre (and (and (<= 0.0001 alpha) (<= alpha 1.0))
                                                                               (and (<= 2.328306437e-10 u0) (<= u0 1.0)))
                                                                            (- (* alpha (* (- u0) alpha))))
                                                                          float code(float alpha, float u0) {
                                                                          	return -(alpha * (-u0 * alpha));
                                                                          }
                                                                          
                                                                          real(4) function code(alpha, u0)
                                                                          use fmin_fmax_functions
                                                                              real(4), intent (in) :: alpha
                                                                              real(4), intent (in) :: u0
                                                                              code = -(alpha * (-u0 * alpha))
                                                                          end function
                                                                          
                                                                          function code(alpha, u0)
                                                                          	return Float32(-Float32(alpha * Float32(Float32(-u0) * alpha)))
                                                                          end
                                                                          
                                                                          function tmp = code(alpha, u0)
                                                                          	tmp = -(alpha * (-u0 * alpha));
                                                                          end
                                                                          
                                                                          -\alpha \cdot \left(\left(-u0\right) \cdot \alpha\right)
                                                                          
                                                                          Derivation
                                                                          1. Initial program 56.2%

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

                                                                            \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-1 \cdot u0\right) \]
                                                                          3. Step-by-step derivation
                                                                            1. Applied rewrites74.4%

                                                                              \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-1 \cdot u0\right) \]
                                                                            2. Step-by-step derivation
                                                                              1. Applied rewrites74.5%

                                                                                \[\leadsto -\alpha \cdot \left(\left(-u0\right) \cdot \alpha\right) \]
                                                                              2. Add Preprocessing

                                                                              Reproduce

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