Trowbridge-Reitz Sample, near normal, slope_y

Percentage Accurate: 98.3% → 98.3%
Time: 5.0s
Alternatives: 15
Speedup: 1.0×

Specification

?
\[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
(FPCore (cosTheta_i u1 u2)
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
          (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
     (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2));
end
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\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 15 alternatives:

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

Initial Program: 98.3% accurate, 1.0× speedup?

\[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
(FPCore (cosTheta_i u1 u2)
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
          (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
     (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2));
end
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)

Alternative 1: 98.3% accurate, 1.0× speedup?

\[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
(FPCore (cosTheta_i u1 u2)
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
          (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
     (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (/ u1 (- 0.5 (- u1 0.5)))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (0.5f - (u1 - 0.5f)))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (0.5e0 - (u1 - 0.5e0)))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(0.5) - Float32(u1 - Float32(0.5))))) * sin(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(0.5) - (u1 - single(0.5))))) * sin((single(6.28318530718) * u2));
end
\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right)
Derivation
  1. Initial program 98.3%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. Applied rewrites98.3%

      \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    2. Add Preprocessing

    Alternative 2: 96.0% accurate, 0.9× speedup?

    \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
    \[\begin{array}{l} \mathbf{if}\;u2 \leq 0.019999999552965164:\\ \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1 \cdot \left(1 + u1\right)} \cdot \sin \left(6.28318530718 \cdot u2\right)\\ \end{array} \]
    (FPCore (cosTheta_i u1 u2)
      :precision binary32
      :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
              (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
         (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
      (if (<= u2 0.019999999552965164)
      (*
       (sqrt (/ u1 (- 0.5 (- u1 0.5))))
       (fma u2 6.28318530718 (* (* (* u2 u2) -41.341702240407926) u2)))
      (* (sqrt (* u1 (+ 1.0 u1))) (sin (* 6.28318530718 u2)))))
    float code(float cosTheta_i, float u1, float u2) {
    	float tmp;
    	if (u2 <= 0.019999999552965164f) {
    		tmp = sqrtf((u1 / (0.5f - (u1 - 0.5f)))) * fmaf(u2, 6.28318530718f, (((u2 * u2) * -41.341702240407926f) * u2));
    	} else {
    		tmp = sqrtf((u1 * (1.0f + u1))) * sinf((6.28318530718f * u2));
    	}
    	return tmp;
    }
    
    function code(cosTheta_i, u1, u2)
    	tmp = Float32(0.0)
    	if (u2 <= Float32(0.019999999552965164))
    		tmp = Float32(sqrt(Float32(u1 / Float32(Float32(0.5) - Float32(u1 - Float32(0.5))))) * fma(u2, Float32(6.28318530718), Float32(Float32(Float32(u2 * u2) * Float32(-41.341702240407926)) * u2)));
    	else
    		tmp = Float32(sqrt(Float32(u1 * Float32(Float32(1.0) + u1))) * sin(Float32(Float32(6.28318530718) * u2)));
    	end
    	return tmp
    end
    
    \begin{array}{l}
    \mathbf{if}\;u2 \leq 0.019999999552965164:\\
    \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{u1 \cdot \left(1 + u1\right)} \cdot \sin \left(6.28318530718 \cdot u2\right)\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if u2 < 0.0199999996

      1. Initial program 98.3%

        \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
      2. Step-by-step derivation
        1. Applied rewrites98.3%

          \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
        2. Taylor expanded in u2 around 0

          \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(\frac{314159265359}{50000000000} + \frac{-31006276680305942139213528068663279}{750000000000000000000000000000000} \cdot {u2}^{2}\right)\right) \]
        3. Step-by-step derivation
          1. Applied rewrites88.7%

            \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(6.28318530718 + -41.341702240407926 \cdot {u2}^{2}\right)\right) \]
          2. Step-by-step derivation
            1. Applied rewrites88.8%

              \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right) \]

            if 0.0199999996 < u2

            1. Initial program 98.3%

              \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
            2. Taylor expanded in u1 around 0

              \[\leadsto \sqrt{u1 \cdot \left(1 + u1\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
            3. Step-by-step derivation
              1. Applied rewrites86.5%

                \[\leadsto \sqrt{u1 \cdot \left(1 + u1\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
            4. Recombined 2 regimes into one program.
            5. Add Preprocessing

            Alternative 3: 94.0% accurate, 1.0× speedup?

            \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
            \[\begin{array}{l} \mathbf{if}\;u2 \leq 0.03999999910593033:\\ \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin \left(u2 \cdot 6.28318530718\right)}{\frac{\sqrt{u1}}{u1}}\\ \end{array} \]
            (FPCore (cosTheta_i u1 u2)
              :precision binary32
              :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                      (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                 (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
              (if (<= u2 0.03999999910593033)
              (*
               (sqrt (/ u1 (- 0.5 (- u1 0.5))))
               (fma u2 6.28318530718 (* (* (* u2 u2) -41.341702240407926) u2)))
              (/ (sin (* u2 6.28318530718)) (/ (sqrt u1) u1))))
            float code(float cosTheta_i, float u1, float u2) {
            	float tmp;
            	if (u2 <= 0.03999999910593033f) {
            		tmp = sqrtf((u1 / (0.5f - (u1 - 0.5f)))) * fmaf(u2, 6.28318530718f, (((u2 * u2) * -41.341702240407926f) * u2));
            	} else {
            		tmp = sinf((u2 * 6.28318530718f)) / (sqrtf(u1) / u1);
            	}
            	return tmp;
            }
            
            function code(cosTheta_i, u1, u2)
            	tmp = Float32(0.0)
            	if (u2 <= Float32(0.03999999910593033))
            		tmp = Float32(sqrt(Float32(u1 / Float32(Float32(0.5) - Float32(u1 - Float32(0.5))))) * fma(u2, Float32(6.28318530718), Float32(Float32(Float32(u2 * u2) * Float32(-41.341702240407926)) * u2)));
            	else
            		tmp = Float32(sin(Float32(u2 * Float32(6.28318530718))) / Float32(sqrt(u1) / u1));
            	end
            	return tmp
            end
            
            \begin{array}{l}
            \mathbf{if}\;u2 \leq 0.03999999910593033:\\
            \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;\frac{\sin \left(u2 \cdot 6.28318530718\right)}{\frac{\sqrt{u1}}{u1}}\\
            
            
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if u2 < 0.0399999991

              1. Initial program 98.3%

                \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
              2. Step-by-step derivation
                1. Applied rewrites98.3%

                  \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                2. Taylor expanded in u2 around 0

                  \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(\frac{314159265359}{50000000000} + \frac{-31006276680305942139213528068663279}{750000000000000000000000000000000} \cdot {u2}^{2}\right)\right) \]
                3. Step-by-step derivation
                  1. Applied rewrites88.7%

                    \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(6.28318530718 + -41.341702240407926 \cdot {u2}^{2}\right)\right) \]
                  2. Step-by-step derivation
                    1. Applied rewrites88.8%

                      \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right) \]

                    if 0.0399999991 < u2

                    1. Initial program 98.3%

                      \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                    2. Step-by-step derivation
                      1. Applied rewrites98.2%

                        \[\leadsto \sqrt{\frac{u1}{\frac{1}{\frac{-1}{u1 - 1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                      2. Applied rewrites98.3%

                        \[\leadsto \frac{\sin \left(u2 \cdot 6.28318530718\right)}{\sqrt{\frac{1 - u1}{u1}}} \]
                      3. Taylor expanded in u1 around 0

                        \[\leadsto \frac{\sin \left(u2 \cdot 6.28318530718\right)}{\frac{\sqrt{u1}}{u1}} \]
                      4. Step-by-step derivation
                        1. Applied rewrites74.9%

                          \[\leadsto \frac{\sin \left(u2 \cdot 6.28318530718\right)}{\frac{\sqrt{u1}}{u1}} \]
                      5. Recombined 2 regimes into one program.
                      6. Add Preprocessing

                      Alternative 4: 94.0% accurate, 1.0× speedup?

                      \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                      \[\begin{array}{l} \mathbf{if}\;u2 \leq 0.03999999910593033:\\ \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{u1 \cdot \sin \left(6.28318530718 \cdot u2\right)}{\sqrt{u1}}\\ \end{array} \]
                      (FPCore (cosTheta_i u1 u2)
                        :precision binary32
                        :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                           (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                        (if (<= u2 0.03999999910593033)
                        (*
                         (sqrt (/ u1 (- 0.5 (- u1 0.5))))
                         (fma u2 6.28318530718 (* (* (* u2 u2) -41.341702240407926) u2)))
                        (/ (* u1 (sin (* 6.28318530718 u2))) (sqrt u1))))
                      float code(float cosTheta_i, float u1, float u2) {
                      	float tmp;
                      	if (u2 <= 0.03999999910593033f) {
                      		tmp = sqrtf((u1 / (0.5f - (u1 - 0.5f)))) * fmaf(u2, 6.28318530718f, (((u2 * u2) * -41.341702240407926f) * u2));
                      	} else {
                      		tmp = (u1 * sinf((6.28318530718f * u2))) / sqrtf(u1);
                      	}
                      	return tmp;
                      }
                      
                      function code(cosTheta_i, u1, u2)
                      	tmp = Float32(0.0)
                      	if (u2 <= Float32(0.03999999910593033))
                      		tmp = Float32(sqrt(Float32(u1 / Float32(Float32(0.5) - Float32(u1 - Float32(0.5))))) * fma(u2, Float32(6.28318530718), Float32(Float32(Float32(u2 * u2) * Float32(-41.341702240407926)) * u2)));
                      	else
                      		tmp = Float32(Float32(u1 * sin(Float32(Float32(6.28318530718) * u2))) / sqrt(u1));
                      	end
                      	return tmp
                      end
                      
                      \begin{array}{l}
                      \mathbf{if}\;u2 \leq 0.03999999910593033:\\
                      \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\frac{u1 \cdot \sin \left(6.28318530718 \cdot u2\right)}{\sqrt{u1}}\\
                      
                      
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if u2 < 0.0399999991

                        1. Initial program 98.3%

                          \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                        2. Step-by-step derivation
                          1. Applied rewrites98.3%

                            \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                          2. Taylor expanded in u2 around 0

                            \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(\frac{314159265359}{50000000000} + \frac{-31006276680305942139213528068663279}{750000000000000000000000000000000} \cdot {u2}^{2}\right)\right) \]
                          3. Step-by-step derivation
                            1. Applied rewrites88.7%

                              \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(6.28318530718 + -41.341702240407926 \cdot {u2}^{2}\right)\right) \]
                            2. Step-by-step derivation
                              1. Applied rewrites88.8%

                                \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right) \]

                              if 0.0399999991 < u2

                              1. Initial program 98.3%

                                \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                              2. Step-by-step derivation
                                1. Applied rewrites98.2%

                                  \[\leadsto \sqrt{\frac{u1}{\frac{1}{\frac{-1}{u1 - 1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                2. Applied rewrites98.3%

                                  \[\leadsto \frac{\sin \left(u2 \cdot 6.28318530718\right)}{\sqrt{\frac{1 - u1}{u1}}} \]
                                3. Taylor expanded in u1 around 0

                                  \[\leadsto \frac{u1 \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right)}{\sqrt{u1}} \]
                                4. Step-by-step derivation
                                  1. Applied rewrites74.9%

                                    \[\leadsto \frac{u1 \cdot \sin \left(6.28318530718 \cdot u2\right)}{\sqrt{u1}} \]
                                5. Recombined 2 regimes into one program.
                                6. Add Preprocessing

                                Alternative 5: 94.0% accurate, 1.1× speedup?

                                \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                \[\begin{array}{l} \mathbf{if}\;u2 \leq 0.03999999910593033:\\ \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1} \cdot \sin \left(6.28318530718 \cdot u2\right)\\ \end{array} \]
                                (FPCore (cosTheta_i u1 u2)
                                  :precision binary32
                                  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                          (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                     (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                  (if (<= u2 0.03999999910593033)
                                  (*
                                   (sqrt (/ u1 (- 0.5 (- u1 0.5))))
                                   (fma u2 6.28318530718 (* (* (* u2 u2) -41.341702240407926) u2)))
                                  (* (sqrt u1) (sin (* 6.28318530718 u2)))))
                                float code(float cosTheta_i, float u1, float u2) {
                                	float tmp;
                                	if (u2 <= 0.03999999910593033f) {
                                		tmp = sqrtf((u1 / (0.5f - (u1 - 0.5f)))) * fmaf(u2, 6.28318530718f, (((u2 * u2) * -41.341702240407926f) * u2));
                                	} else {
                                		tmp = sqrtf(u1) * sinf((6.28318530718f * u2));
                                	}
                                	return tmp;
                                }
                                
                                function code(cosTheta_i, u1, u2)
                                	tmp = Float32(0.0)
                                	if (u2 <= Float32(0.03999999910593033))
                                		tmp = Float32(sqrt(Float32(u1 / Float32(Float32(0.5) - Float32(u1 - Float32(0.5))))) * fma(u2, Float32(6.28318530718), Float32(Float32(Float32(u2 * u2) * Float32(-41.341702240407926)) * u2)));
                                	else
                                		tmp = Float32(sqrt(u1) * sin(Float32(Float32(6.28318530718) * u2)));
                                	end
                                	return tmp
                                end
                                
                                \begin{array}{l}
                                \mathbf{if}\;u2 \leq 0.03999999910593033:\\
                                \;\;\;\;\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\sqrt{u1} \cdot \sin \left(6.28318530718 \cdot u2\right)\\
                                
                                
                                \end{array}
                                
                                Derivation
                                1. Split input into 2 regimes
                                2. if u2 < 0.0399999991

                                  1. Initial program 98.3%

                                    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                  2. Step-by-step derivation
                                    1. Applied rewrites98.3%

                                      \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                    2. Taylor expanded in u2 around 0

                                      \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(\frac{314159265359}{50000000000} + \frac{-31006276680305942139213528068663279}{750000000000000000000000000000000} \cdot {u2}^{2}\right)\right) \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites88.7%

                                        \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(6.28318530718 + -41.341702240407926 \cdot {u2}^{2}\right)\right) \]
                                      2. Step-by-step derivation
                                        1. Applied rewrites88.8%

                                          \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right) \]

                                        if 0.0399999991 < u2

                                        1. Initial program 98.3%

                                          \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                        2. Taylor expanded in u1 around 0

                                          \[\leadsto \sqrt{u1} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites75.0%

                                            \[\leadsto \sqrt{u1} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                        4. Recombined 2 regimes into one program.
                                        5. Add Preprocessing

                                        Alternative 6: 88.8% accurate, 1.7× speedup?

                                        \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                        \[\sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right) \]
                                        (FPCore (cosTheta_i u1 u2)
                                          :precision binary32
                                          :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                  (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                             (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                          (*
                                         (sqrt (/ u1 (- 0.5 (- u1 0.5))))
                                         (fma u2 6.28318530718 (* (* (* u2 u2) -41.341702240407926) u2))))
                                        float code(float cosTheta_i, float u1, float u2) {
                                        	return sqrtf((u1 / (0.5f - (u1 - 0.5f)))) * fmaf(u2, 6.28318530718f, (((u2 * u2) * -41.341702240407926f) * u2));
                                        }
                                        
                                        function code(cosTheta_i, u1, u2)
                                        	return Float32(sqrt(Float32(u1 / Float32(Float32(0.5) - Float32(u1 - Float32(0.5))))) * fma(u2, Float32(6.28318530718), Float32(Float32(Float32(u2 * u2) * Float32(-41.341702240407926)) * u2)))
                                        end
                                        
                                        \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right)
                                        
                                        Derivation
                                        1. Initial program 98.3%

                                          \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                        2. Step-by-step derivation
                                          1. Applied rewrites98.3%

                                            \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                          2. Taylor expanded in u2 around 0

                                            \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(\frac{314159265359}{50000000000} + \frac{-31006276680305942139213528068663279}{750000000000000000000000000000000} \cdot {u2}^{2}\right)\right) \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites88.7%

                                              \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(6.28318530718 + -41.341702240407926 \cdot {u2}^{2}\right)\right) \]
                                            2. Step-by-step derivation
                                              1. Applied rewrites88.8%

                                                \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \mathsf{fma}\left(u2, 6.28318530718, \left(\left(u2 \cdot u2\right) \cdot -41.341702240407926\right) \cdot u2\right) \]
                                              2. Add Preprocessing

                                              Alternative 7: 88.7% accurate, 2.1× speedup?

                                              \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                              \[\sqrt{\frac{u1}{1 - u1}} \cdot \left(\mathsf{fma}\left(u2 \cdot u2, -41.341702240407926, 6.28318530718\right) \cdot u2\right) \]
                                              (FPCore (cosTheta_i u1 u2)
                                                :precision binary32
                                                :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                        (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                   (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                (*
                                               (sqrt (/ u1 (- 1.0 u1)))
                                               (* (fma (* u2 u2) -41.341702240407926 6.28318530718) u2)))
                                              float code(float cosTheta_i, float u1, float u2) {
                                              	return sqrtf((u1 / (1.0f - u1))) * (fmaf((u2 * u2), -41.341702240407926f, 6.28318530718f) * u2);
                                              }
                                              
                                              function code(cosTheta_i, u1, u2)
                                              	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(fma(Float32(u2 * u2), Float32(-41.341702240407926), Float32(6.28318530718)) * u2))
                                              end
                                              
                                              \sqrt{\frac{u1}{1 - u1}} \cdot \left(\mathsf{fma}\left(u2 \cdot u2, -41.341702240407926, 6.28318530718\right) \cdot u2\right)
                                              
                                              Derivation
                                              1. Initial program 98.3%

                                                \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                              2. Step-by-step derivation
                                                1. Applied rewrites98.3%

                                                  \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                2. Taylor expanded in u2 around 0

                                                  \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(\frac{314159265359}{50000000000} + \frac{-31006276680305942139213528068663279}{750000000000000000000000000000000} \cdot {u2}^{2}\right)\right) \]
                                                3. Step-by-step derivation
                                                  1. Applied rewrites88.7%

                                                    \[\leadsto \sqrt{\frac{u1}{0.5 - \left(u1 - 0.5\right)}} \cdot \left(u2 \cdot \left(6.28318530718 + -41.341702240407926 \cdot {u2}^{2}\right)\right) \]
                                                  2. Step-by-step derivation
                                                    1. Applied rewrites88.7%

                                                      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(\mathsf{fma}\left(u2 \cdot u2, -41.341702240407926, 6.28318530718\right) \cdot u2\right) \]
                                                    2. Add Preprocessing

                                                    Alternative 8: 80.9% accurate, 2.9× speedup?

                                                    \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                                    \[\frac{6.28318530718}{\frac{\sqrt{\frac{1 - u1}{u1}}}{u2}} \]
                                                    (FPCore (cosTheta_i u1 u2)
                                                      :precision binary32
                                                      :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                              (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                         (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                      (/ 6.28318530718 (/ (sqrt (/ (- 1.0 u1) u1)) u2)))
                                                    float code(float cosTheta_i, float u1, float u2) {
                                                    	return 6.28318530718f / (sqrtf(((1.0f - u1) / u1)) / u2);
                                                    }
                                                    
                                                    real(4) function code(costheta_i, u1, u2)
                                                    use fmin_fmax_functions
                                                        real(4), intent (in) :: costheta_i
                                                        real(4), intent (in) :: u1
                                                        real(4), intent (in) :: u2
                                                        code = 6.28318530718e0 / (sqrt(((1.0e0 - u1) / u1)) / u2)
                                                    end function
                                                    
                                                    function code(cosTheta_i, u1, u2)
                                                    	return Float32(Float32(6.28318530718) / Float32(sqrt(Float32(Float32(Float32(1.0) - u1) / u1)) / u2))
                                                    end
                                                    
                                                    function tmp = code(cosTheta_i, u1, u2)
                                                    	tmp = single(6.28318530718) / (sqrt(((single(1.0) - u1) / u1)) / u2);
                                                    end
                                                    
                                                    \frac{6.28318530718}{\frac{\sqrt{\frac{1 - u1}{u1}}}{u2}}
                                                    
                                                    Derivation
                                                    1. Initial program 98.3%

                                                      \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                    2. Taylor expanded in u2 around 0

                                                      \[\leadsto \frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                    3. Step-by-step derivation
                                                      1. Applied rewrites80.9%

                                                        \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                      2. Applied rewrites80.8%

                                                        \[\leadsto \frac{1}{\frac{\sqrt{\frac{1 - u1}{u1}}}{u2 \cdot 6.28318530718}} \]
                                                      3. Step-by-step derivation
                                                        1. Applied rewrites80.9%

                                                          \[\leadsto \frac{6.28318530718}{\frac{\sqrt{\frac{1 - u1}{u1}}}{u2}} \]
                                                        2. Add Preprocessing

                                                        Alternative 9: 80.9% accurate, 3.2× speedup?

                                                        \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                                        \[\left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{u1}{1 - u1}} \]
                                                        (FPCore (cosTheta_i u1 u2)
                                                          :precision binary32
                                                          :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                                  (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                             (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                          (* (* u2 6.28318530718) (sqrt (/ u1 (- 1.0 u1)))))
                                                        float code(float cosTheta_i, float u1, float u2) {
                                                        	return (u2 * 6.28318530718f) * sqrtf((u1 / (1.0f - u1)));
                                                        }
                                                        
                                                        real(4) function code(costheta_i, u1, u2)
                                                        use fmin_fmax_functions
                                                            real(4), intent (in) :: costheta_i
                                                            real(4), intent (in) :: u1
                                                            real(4), intent (in) :: u2
                                                            code = (u2 * 6.28318530718e0) * sqrt((u1 / (1.0e0 - u1)))
                                                        end function
                                                        
                                                        function code(cosTheta_i, u1, u2)
                                                        	return Float32(Float32(u2 * Float32(6.28318530718)) * sqrt(Float32(u1 / Float32(Float32(1.0) - u1))))
                                                        end
                                                        
                                                        function tmp = code(cosTheta_i, u1, u2)
                                                        	tmp = (u2 * single(6.28318530718)) * sqrt((u1 / (single(1.0) - u1)));
                                                        end
                                                        
                                                        \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{u1}{1 - u1}}
                                                        
                                                        Derivation
                                                        1. Initial program 98.3%

                                                          \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                        2. Taylor expanded in u2 around 0

                                                          \[\leadsto \frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                        3. Step-by-step derivation
                                                          1. Applied rewrites80.9%

                                                            \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                          2. Step-by-step derivation
                                                            1. Applied rewrites80.9%

                                                              \[\leadsto \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{u1}{1 - u1}} \]
                                                            2. Add Preprocessing

                                                            Alternative 10: 80.9% accurate, 3.2× speedup?

                                                            \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                                            \[\left(6.28318530718 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \cdot u2 \]
                                                            (FPCore (cosTheta_i u1 u2)
                                                              :precision binary32
                                                              :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                                      (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                                 (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                              (* (* 6.28318530718 (sqrt (/ u1 (- 1.0 u1)))) u2))
                                                            float code(float cosTheta_i, float u1, float u2) {
                                                            	return (6.28318530718f * sqrtf((u1 / (1.0f - u1)))) * u2;
                                                            }
                                                            
                                                            real(4) function code(costheta_i, u1, u2)
                                                            use fmin_fmax_functions
                                                                real(4), intent (in) :: costheta_i
                                                                real(4), intent (in) :: u1
                                                                real(4), intent (in) :: u2
                                                                code = (6.28318530718e0 * sqrt((u1 / (1.0e0 - u1)))) * u2
                                                            end function
                                                            
                                                            function code(cosTheta_i, u1, u2)
                                                            	return Float32(Float32(Float32(6.28318530718) * sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))) * u2)
                                                            end
                                                            
                                                            function tmp = code(cosTheta_i, u1, u2)
                                                            	tmp = (single(6.28318530718) * sqrt((u1 / (single(1.0) - u1)))) * u2;
                                                            end
                                                            
                                                            \left(6.28318530718 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \cdot u2
                                                            
                                                            Derivation
                                                            1. Initial program 98.3%

                                                              \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                            2. Taylor expanded in u2 around 0

                                                              \[\leadsto \frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                            3. Step-by-step derivation
                                                              1. Applied rewrites80.9%

                                                                \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                              2. Step-by-step derivation
                                                                1. Applied rewrites80.9%

                                                                  \[\leadsto \left(6.28318530718 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \cdot u2 \]
                                                                2. Add Preprocessing

                                                                Alternative 11: 80.9% accurate, 3.2× speedup?

                                                                \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                                                \[6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                (FPCore (cosTheta_i u1 u2)
                                                                  :precision binary32
                                                                  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                                          (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                                     (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                                  (* 6.28318530718 (* u2 (sqrt (/ u1 (- 1.0 u1))))))
                                                                float code(float cosTheta_i, float u1, float u2) {
                                                                	return 6.28318530718f * (u2 * sqrtf((u1 / (1.0f - u1))));
                                                                }
                                                                
                                                                real(4) function code(costheta_i, u1, u2)
                                                                use fmin_fmax_functions
                                                                    real(4), intent (in) :: costheta_i
                                                                    real(4), intent (in) :: u1
                                                                    real(4), intent (in) :: u2
                                                                    code = 6.28318530718e0 * (u2 * sqrt((u1 / (1.0e0 - u1))))
                                                                end function
                                                                
                                                                function code(cosTheta_i, u1, u2)
                                                                	return Float32(Float32(6.28318530718) * Float32(u2 * sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))))
                                                                end
                                                                
                                                                function tmp = code(cosTheta_i, u1, u2)
                                                                	tmp = single(6.28318530718) * (u2 * sqrt((u1 / (single(1.0) - u1))));
                                                                end
                                                                
                                                                6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right)
                                                                
                                                                Derivation
                                                                1. Initial program 98.3%

                                                                  \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                                2. Taylor expanded in u2 around 0

                                                                  \[\leadsto \frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                3. Step-by-step derivation
                                                                  1. Applied rewrites80.9%

                                                                    \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                  2. Add Preprocessing

                                                                  Alternative 12: 72.7% accurate, 3.4× speedup?

                                                                  \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                                                  \[6.28318530718 \cdot \left(u2 \cdot \sqrt{u1 \cdot \left(1 + u1\right)}\right) \]
                                                                  (FPCore (cosTheta_i u1 u2)
                                                                    :precision binary32
                                                                    :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                                            (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                                       (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                                    (* 6.28318530718 (* u2 (sqrt (* u1 (+ 1.0 u1))))))
                                                                  float code(float cosTheta_i, float u1, float u2) {
                                                                  	return 6.28318530718f * (u2 * sqrtf((u1 * (1.0f + u1))));
                                                                  }
                                                                  
                                                                  real(4) function code(costheta_i, u1, u2)
                                                                  use fmin_fmax_functions
                                                                      real(4), intent (in) :: costheta_i
                                                                      real(4), intent (in) :: u1
                                                                      real(4), intent (in) :: u2
                                                                      code = 6.28318530718e0 * (u2 * sqrt((u1 * (1.0e0 + u1))))
                                                                  end function
                                                                  
                                                                  function code(cosTheta_i, u1, u2)
                                                                  	return Float32(Float32(6.28318530718) * Float32(u2 * sqrt(Float32(u1 * Float32(Float32(1.0) + u1)))))
                                                                  end
                                                                  
                                                                  function tmp = code(cosTheta_i, u1, u2)
                                                                  	tmp = single(6.28318530718) * (u2 * sqrt((u1 * (single(1.0) + u1))));
                                                                  end
                                                                  
                                                                  6.28318530718 \cdot \left(u2 \cdot \sqrt{u1 \cdot \left(1 + u1\right)}\right)
                                                                  
                                                                  Derivation
                                                                  1. Initial program 98.3%

                                                                    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                                  2. Taylor expanded in u2 around 0

                                                                    \[\leadsto \frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                  3. Step-by-step derivation
                                                                    1. Applied rewrites80.9%

                                                                      \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                    2. Taylor expanded in u1 around 0

                                                                      \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1 \cdot \left(1 + u1\right)}\right) \]
                                                                    3. Step-by-step derivation
                                                                      1. Applied rewrites72.7%

                                                                        \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1 \cdot \left(1 + u1\right)}\right) \]
                                                                      2. Add Preprocessing

                                                                      Alternative 13: 64.6% accurate, 5.5× speedup?

                                                                      \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                                                      \[\left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1} \]
                                                                      (FPCore (cosTheta_i u1 u2)
                                                                        :precision binary32
                                                                        :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                                                (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                                           (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                                        (* (* u2 6.28318530718) (sqrt u1)))
                                                                      float code(float cosTheta_i, float u1, float u2) {
                                                                      	return (u2 * 6.28318530718f) * sqrtf(u1);
                                                                      }
                                                                      
                                                                      real(4) function code(costheta_i, u1, u2)
                                                                      use fmin_fmax_functions
                                                                          real(4), intent (in) :: costheta_i
                                                                          real(4), intent (in) :: u1
                                                                          real(4), intent (in) :: u2
                                                                          code = (u2 * 6.28318530718e0) * sqrt(u1)
                                                                      end function
                                                                      
                                                                      function code(cosTheta_i, u1, u2)
                                                                      	return Float32(Float32(u2 * Float32(6.28318530718)) * sqrt(u1))
                                                                      end
                                                                      
                                                                      function tmp = code(cosTheta_i, u1, u2)
                                                                      	tmp = (u2 * single(6.28318530718)) * sqrt(u1);
                                                                      end
                                                                      
                                                                      \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}
                                                                      
                                                                      Derivation
                                                                      1. Initial program 98.3%

                                                                        \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                                      2. Taylor expanded in u2 around 0

                                                                        \[\leadsto \frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                      3. Step-by-step derivation
                                                                        1. Applied rewrites80.9%

                                                                          \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                        2. Taylor expanded in u1 around 0

                                                                          \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right) \]
                                                                        3. Step-by-step derivation
                                                                          1. Applied rewrites64.6%

                                                                            \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right) \]
                                                                          2. Step-by-step derivation
                                                                            1. Applied rewrites64.6%

                                                                              \[\leadsto \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1} \]
                                                                            2. Add Preprocessing

                                                                            Alternative 14: 64.6% accurate, 5.5× speedup?

                                                                            \[\left(\left(cosTheta\_i > 0.9999 \land cosTheta\_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
                                                                            \[6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right) \]
                                                                            (FPCore (cosTheta_i u1 u2)
                                                                              :precision binary32
                                                                              :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0))
                                                                                      (and (<= 2.328306437e-10 u1) (<= u1 1.0)))
                                                                                 (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                                              (* 6.28318530718 (* u2 (sqrt u1))))
                                                                            float code(float cosTheta_i, float u1, float u2) {
                                                                            	return 6.28318530718f * (u2 * sqrtf(u1));
                                                                            }
                                                                            
                                                                            real(4) function code(costheta_i, u1, u2)
                                                                            use fmin_fmax_functions
                                                                                real(4), intent (in) :: costheta_i
                                                                                real(4), intent (in) :: u1
                                                                                real(4), intent (in) :: u2
                                                                                code = 6.28318530718e0 * (u2 * sqrt(u1))
                                                                            end function
                                                                            
                                                                            function code(cosTheta_i, u1, u2)
                                                                            	return Float32(Float32(6.28318530718) * Float32(u2 * sqrt(u1)))
                                                                            end
                                                                            
                                                                            function tmp = code(cosTheta_i, u1, u2)
                                                                            	tmp = single(6.28318530718) * (u2 * sqrt(u1));
                                                                            end
                                                                            
                                                                            6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)
                                                                            
                                                                            Derivation
                                                                            1. Initial program 98.3%

                                                                              \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
                                                                            2. Taylor expanded in u2 around 0

                                                                              \[\leadsto \frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                            3. Step-by-step derivation
                                                                              1. Applied rewrites80.9%

                                                                                \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                                                                              2. Taylor expanded in u1 around 0

                                                                                \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right) \]
                                                                              3. Step-by-step derivation
                                                                                1. Applied rewrites64.6%

                                                                                  \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right) \]
                                                                                2. Add Preprocessing

                                                                                Reproduce

                                                                                ?
                                                                                herbie shell --seed 2026035 +o sampling:rival3
                                                                                (FPCore (cosTheta_i u1 u2)
                                                                                  :name "Trowbridge-Reitz Sample, near normal, slope_y"
                                                                                  :precision binary32
                                                                                  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                                                  (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))