Trowbridge-Reitz Sample, near normal, slope_x

Percentage Accurate: 99.0% → 99.2%
Time: 4.4s
Alternatives: 16
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 \cos \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))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf((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))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2));
end
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \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 16 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: 99.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)\]
\[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \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))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf((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))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2));
end
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)

Alternative 1: 99.2% 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(\mathsf{fma}\left(-6.28318530718, u2, 1.5707963705062866\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)))
  (*
 (sqrt (/ u1 (- 1.0 u1)))
 (sin (fma -6.28318530718 u2 1.5707963705062866))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf(fmaf(-6.28318530718f, u2, 1.5707963705062866f));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(fma(Float32(-6.28318530718), u2, Float32(1.5707963705062866))))
end
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 1.5707963705062866\right)\right)
Derivation
  1. Initial program 99.0%

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

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 0.5 \cdot \pi\right)\right) \]
    2. Evaluated real constant99.2%

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

    Alternative 2: 96.4% 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} t_0 := \sqrt{\frac{u1}{1 - u1}}\\ \mathbf{if}\;u2 \leq 0.017999999225139618:\\ \;\;\;\;t\_0 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(u1, u1, u1\right)} \cdot \cos \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)))
      (let* ((t_0 (sqrt (/ u1 (- 1.0 u1)))))
      (if (<= u2 0.017999999225139618)
        (+ t_0 (* -19.739208802181317 (* (pow u2 2.0) t_0)))
        (* (sqrt (fma u1 u1 u1)) (cos (* 6.28318530718 u2))))))
    float code(float cosTheta_i, float u1, float u2) {
    	float t_0 = sqrtf((u1 / (1.0f - u1)));
    	float tmp;
    	if (u2 <= 0.017999999225139618f) {
    		tmp = t_0 + (-19.739208802181317f * (powf(u2, 2.0f) * t_0));
    	} else {
    		tmp = sqrtf(fmaf(u1, u1, u1)) * cosf((6.28318530718f * u2));
    	}
    	return tmp;
    }
    
    function code(cosTheta_i, u1, u2)
    	t_0 = sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))
    	tmp = Float32(0.0)
    	if (u2 <= Float32(0.017999999225139618))
    		tmp = Float32(t_0 + Float32(Float32(-19.739208802181317) * Float32((u2 ^ Float32(2.0)) * t_0)));
    	else
    		tmp = Float32(sqrt(fma(u1, u1, u1)) * cos(Float32(Float32(6.28318530718) * u2)));
    	end
    	return tmp
    end
    
    \begin{array}{l}
    t_0 := \sqrt{\frac{u1}{1 - u1}}\\
    \mathbf{if}\;u2 \leq 0.017999999225139618:\\
    \;\;\;\;t\_0 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_0\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{\mathsf{fma}\left(u1, u1, u1\right)} \cdot \cos \left(6.28318530718 \cdot u2\right)\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if u2 < 0.0179999992

      1. Initial program 99.0%

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

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites88.4%

          \[\leadsto \sqrt{\frac{u1}{1 - u1}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]

        if 0.0179999992 < u2

        1. Initial program 99.0%

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

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

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

              \[\leadsto \sqrt{\mathsf{fma}\left(u1, u1, u1\right)} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
          3. Recombined 2 regimes into one program.
          4. Add Preprocessing

          Alternative 3: 94.2% accurate, 0.6× 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} t_0 := \sqrt{\frac{u1}{1 - u1}}\\ \mathbf{if}\;\cos \left(6.28318530718 \cdot u2\right) \leq 0.9934999942779541:\\ \;\;\;\;\sin \left(1.5707963705062866 + -6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_0\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)))
            (let* ((t_0 (sqrt (/ u1 (- 1.0 u1)))))
            (if (<= (cos (* 6.28318530718 u2)) 0.9934999942779541)
              (* (sin (+ 1.5707963705062866 (* -6.28318530718 u2))) (sqrt u1))
              (+ t_0 (* -19.739208802181317 (* (pow u2 2.0) t_0))))))
          float code(float cosTheta_i, float u1, float u2) {
          	float t_0 = sqrtf((u1 / (1.0f - u1)));
          	float tmp;
          	if (cosf((6.28318530718f * u2)) <= 0.9934999942779541f) {
          		tmp = sinf((1.5707963705062866f + (-6.28318530718f * u2))) * sqrtf(u1);
          	} else {
          		tmp = t_0 + (-19.739208802181317f * (powf(u2, 2.0f) * t_0));
          	}
          	return tmp;
          }
          
          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
              real(4) :: t_0
              real(4) :: tmp
              t_0 = sqrt((u1 / (1.0e0 - u1)))
              if (cos((6.28318530718e0 * u2)) <= 0.9934999942779541e0) then
                  tmp = sin((1.5707963705062866e0 + ((-6.28318530718e0) * u2))) * sqrt(u1)
              else
                  tmp = t_0 + ((-19.739208802181317e0) * ((u2 ** 2.0e0) * t_0))
              end if
              code = tmp
          end function
          
          function code(cosTheta_i, u1, u2)
          	t_0 = sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))
          	tmp = Float32(0.0)
          	if (cos(Float32(Float32(6.28318530718) * u2)) <= Float32(0.9934999942779541))
          		tmp = Float32(sin(Float32(Float32(1.5707963705062866) + Float32(Float32(-6.28318530718) * u2))) * sqrt(u1));
          	else
          		tmp = Float32(t_0 + Float32(Float32(-19.739208802181317) * Float32((u2 ^ Float32(2.0)) * t_0)));
          	end
          	return tmp
          end
          
          function tmp_2 = code(cosTheta_i, u1, u2)
          	t_0 = sqrt((u1 / (single(1.0) - u1)));
          	tmp = single(0.0);
          	if (cos((single(6.28318530718) * u2)) <= single(0.9934999942779541))
          		tmp = sin((single(1.5707963705062866) + (single(-6.28318530718) * u2))) * sqrt(u1);
          	else
          		tmp = t_0 + (single(-19.739208802181317) * ((u2 ^ single(2.0)) * t_0));
          	end
          	tmp_2 = tmp;
          end
          
          \begin{array}{l}
          t_0 := \sqrt{\frac{u1}{1 - u1}}\\
          \mathbf{if}\;\cos \left(6.28318530718 \cdot u2\right) \leq 0.9934999942779541:\\
          \;\;\;\;\sin \left(1.5707963705062866 + -6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_0\right)\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.993499994

            1. Initial program 99.0%

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

                \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 0.5 \cdot \pi\right)\right) \]
              2. Evaluated real constant99.2%

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

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

                  \[\leadsto \sin \left(1.5707963705062866 + -6.28318530718 \cdot u2\right) \cdot \sqrt{u1} \]

                if 0.993499994 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2))

                1. Initial program 99.0%

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

                  \[\leadsto \sqrt{\frac{u1}{1 - u1}} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                3. Step-by-step derivation
                  1. Applied rewrites88.4%

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

                Alternative 4: 94.2% accurate, 0.6× 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} t_0 := \sqrt{\frac{u1}{1 - u1}}\\ \mathbf{if}\;\cos \left(6.28318530718 \cdot u2\right) \leq 0.9934999942779541:\\ \;\;\;\;\sqrt{u1} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 1.5707963705062866\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_0\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)))
                  (let* ((t_0 (sqrt (/ u1 (- 1.0 u1)))))
                  (if (<= (cos (* 6.28318530718 u2)) 0.9934999942779541)
                    (* (sqrt u1) (sin (fma -6.28318530718 u2 1.5707963705062866)))
                    (+ t_0 (* -19.739208802181317 (* (pow u2 2.0) t_0))))))
                float code(float cosTheta_i, float u1, float u2) {
                	float t_0 = sqrtf((u1 / (1.0f - u1)));
                	float tmp;
                	if (cosf((6.28318530718f * u2)) <= 0.9934999942779541f) {
                		tmp = sqrtf(u1) * sinf(fmaf(-6.28318530718f, u2, 1.5707963705062866f));
                	} else {
                		tmp = t_0 + (-19.739208802181317f * (powf(u2, 2.0f) * t_0));
                	}
                	return tmp;
                }
                
                function code(cosTheta_i, u1, u2)
                	t_0 = sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))
                	tmp = Float32(0.0)
                	if (cos(Float32(Float32(6.28318530718) * u2)) <= Float32(0.9934999942779541))
                		tmp = Float32(sqrt(u1) * sin(fma(Float32(-6.28318530718), u2, Float32(1.5707963705062866))));
                	else
                		tmp = Float32(t_0 + Float32(Float32(-19.739208802181317) * Float32((u2 ^ Float32(2.0)) * t_0)));
                	end
                	return tmp
                end
                
                \begin{array}{l}
                t_0 := \sqrt{\frac{u1}{1 - u1}}\\
                \mathbf{if}\;\cos \left(6.28318530718 \cdot u2\right) \leq 0.9934999942779541:\\
                \;\;\;\;\sqrt{u1} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 1.5707963705062866\right)\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;t\_0 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_0\right)\\
                
                
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.993499994

                  1. Initial program 99.0%

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

                      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 0.5 \cdot \pi\right)\right) \]
                    2. Evaluated real constant99.2%

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

                      \[\leadsto \sqrt{u1} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 1.5707963705062866\right)\right) \]
                    4. Step-by-step derivation
                      1. Applied rewrites74.5%

                        \[\leadsto \sqrt{u1} \cdot \sin \left(\mathsf{fma}\left(-6.28318530718, u2, 1.5707963705062866\right)\right) \]

                      if 0.993499994 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2))

                      1. Initial program 99.0%

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

                        \[\leadsto \sqrt{\frac{u1}{1 - u1}} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                      3. Step-by-step derivation
                        1. Applied rewrites88.4%

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

                      Alternative 5: 94.1% accurate, 0.6× 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} t_0 := \cos \left(6.28318530718 \cdot u2\right)\\ t_1 := \sqrt{\frac{u1}{1 - u1}}\\ \mathbf{if}\;t\_0 \leq 0.9934999942779541:\\ \;\;\;\;\sqrt{u1} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_1\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)))
                        (let* ((t_0 (cos (* 6.28318530718 u2)))
                             (t_1 (sqrt (/ u1 (- 1.0 u1)))))
                        (if (<= t_0 0.9934999942779541)
                          (* (sqrt u1) t_0)
                          (+ t_1 (* -19.739208802181317 (* (pow u2 2.0) t_1))))))
                      float code(float cosTheta_i, float u1, float u2) {
                      	float t_0 = cosf((6.28318530718f * u2));
                      	float t_1 = sqrtf((u1 / (1.0f - u1)));
                      	float tmp;
                      	if (t_0 <= 0.9934999942779541f) {
                      		tmp = sqrtf(u1) * t_0;
                      	} else {
                      		tmp = t_1 + (-19.739208802181317f * (powf(u2, 2.0f) * t_1));
                      	}
                      	return tmp;
                      }
                      
                      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
                          real(4) :: t_0
                          real(4) :: t_1
                          real(4) :: tmp
                          t_0 = cos((6.28318530718e0 * u2))
                          t_1 = sqrt((u1 / (1.0e0 - u1)))
                          if (t_0 <= 0.9934999942779541e0) then
                              tmp = sqrt(u1) * t_0
                          else
                              tmp = t_1 + ((-19.739208802181317e0) * ((u2 ** 2.0e0) * t_1))
                          end if
                          code = tmp
                      end function
                      
                      function code(cosTheta_i, u1, u2)
                      	t_0 = cos(Float32(Float32(6.28318530718) * u2))
                      	t_1 = sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))
                      	tmp = Float32(0.0)
                      	if (t_0 <= Float32(0.9934999942779541))
                      		tmp = Float32(sqrt(u1) * t_0);
                      	else
                      		tmp = Float32(t_1 + Float32(Float32(-19.739208802181317) * Float32((u2 ^ Float32(2.0)) * t_1)));
                      	end
                      	return tmp
                      end
                      
                      function tmp_2 = code(cosTheta_i, u1, u2)
                      	t_0 = cos((single(6.28318530718) * u2));
                      	t_1 = sqrt((u1 / (single(1.0) - u1)));
                      	tmp = single(0.0);
                      	if (t_0 <= single(0.9934999942779541))
                      		tmp = sqrt(u1) * t_0;
                      	else
                      		tmp = t_1 + (single(-19.739208802181317) * ((u2 ^ single(2.0)) * t_1));
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      \begin{array}{l}
                      t_0 := \cos \left(6.28318530718 \cdot u2\right)\\
                      t_1 := \sqrt{\frac{u1}{1 - u1}}\\
                      \mathbf{if}\;t\_0 \leq 0.9934999942779541:\\
                      \;\;\;\;\sqrt{u1} \cdot t\_0\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;t\_1 + -19.739208802181317 \cdot \left({u2}^{2} \cdot t\_1\right)\\
                      
                      
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.993499994

                        1. Initial program 99.0%

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

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

                            \[\leadsto \sqrt{u1} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

                          if 0.993499994 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2))

                          1. Initial program 99.0%

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

                            \[\leadsto \sqrt{\frac{u1}{1 - u1}} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
                          3. Step-by-step derivation
                            1. Applied rewrites88.4%

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

                          Alternative 6: 94.1% accurate, 0.6× 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} t_0 := \cos \left(6.28318530718 \cdot u2\right)\\ \mathbf{if}\;t\_0 \leq 0.9934999942779541:\\ \;\;\;\;\sqrt{u1} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot {u2}^{2}\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)))
                            (let* ((t_0 (cos (* 6.28318530718 u2))))
                            (if (<= t_0 0.9934999942779541)
                              (* (sqrt u1) t_0)
                              (*
                               (sqrt (/ u1 (- 1.0 u1)))
                               (+ 1.0 (* -19.739208802181317 (pow u2 2.0)))))))
                          float code(float cosTheta_i, float u1, float u2) {
                          	float t_0 = cosf((6.28318530718f * u2));
                          	float tmp;
                          	if (t_0 <= 0.9934999942779541f) {
                          		tmp = sqrtf(u1) * t_0;
                          	} else {
                          		tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + (-19.739208802181317f * powf(u2, 2.0f)));
                          	}
                          	return tmp;
                          }
                          
                          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
                              real(4) :: t_0
                              real(4) :: tmp
                              t_0 = cos((6.28318530718e0 * u2))
                              if (t_0 <= 0.9934999942779541e0) then
                                  tmp = sqrt(u1) * t_0
                              else
                                  tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((-19.739208802181317e0) * (u2 ** 2.0e0)))
                              end if
                              code = tmp
                          end function
                          
                          function code(cosTheta_i, u1, u2)
                          	t_0 = cos(Float32(Float32(6.28318530718) * u2))
                          	tmp = Float32(0.0)
                          	if (t_0 <= Float32(0.9934999942779541))
                          		tmp = Float32(sqrt(u1) * t_0);
                          	else
                          		tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * (u2 ^ Float32(2.0)))));
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(cosTheta_i, u1, u2)
                          	t_0 = cos((single(6.28318530718) * u2));
                          	tmp = single(0.0);
                          	if (t_0 <= single(0.9934999942779541))
                          		tmp = sqrt(u1) * t_0;
                          	else
                          		tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (single(-19.739208802181317) * (u2 ^ single(2.0))));
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          \begin{array}{l}
                          t_0 := \cos \left(6.28318530718 \cdot u2\right)\\
                          \mathbf{if}\;t\_0 \leq 0.9934999942779541:\\
                          \;\;\;\;\sqrt{u1} \cdot t\_0\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot {u2}^{2}\right)\\
                          
                          
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.993499994

                            1. Initial program 99.0%

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

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

                                \[\leadsto \sqrt{u1} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

                              if 0.993499994 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2))

                              1. Initial program 99.0%

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

                                \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \frac{-98696044010906577398881}{5000000000000000000000} \cdot {u2}^{2}\right) \]
                              3. Step-by-step derivation
                                1. Applied rewrites88.4%

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

                              Alternative 7: 88.4% accurate, 1.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)\]
                              \[\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot {u2}^{2}\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)))
                               (+ 1.0 (* -19.739208802181317 (pow u2 2.0)))))
                              float code(float cosTheta_i, float u1, float u2) {
                              	return sqrtf((u1 / (1.0f - u1))) * (1.0f + (-19.739208802181317f * powf(u2, 2.0f)));
                              }
                              
                              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))) * (1.0e0 + ((-19.739208802181317e0) * (u2 ** 2.0e0)))
                              end function
                              
                              function code(cosTheta_i, u1, u2)
                              	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * (u2 ^ Float32(2.0)))))
                              end
                              
                              function tmp = code(cosTheta_i, u1, u2)
                              	tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (single(-19.739208802181317) * (u2 ^ single(2.0))));
                              end
                              
                              \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot {u2}^{2}\right)
                              
                              Derivation
                              1. Initial program 99.0%

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

                                \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \frac{-98696044010906577398881}{5000000000000000000000} \cdot {u2}^{2}\right) \]
                              3. Step-by-step derivation
                                1. Applied rewrites88.4%

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

                                Alternative 8: 88.1% accurate, 1.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{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\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)))
                                  (/
                                 (fma (* (* u2 u2) -19.739208802181317) (sqrt u1) (sqrt u1))
                                 (sqrt (fabs (- u1 1.0)))))
                                float code(float cosTheta_i, float u1, float u2) {
                                	return fmaf(((u2 * u2) * -19.739208802181317f), sqrtf(u1), sqrtf(u1)) / sqrtf(fabsf((u1 - 1.0f)));
                                }
                                
                                function code(cosTheta_i, u1, u2)
                                	return Float32(fma(Float32(Float32(u2 * u2) * Float32(-19.739208802181317)), sqrt(u1), sqrt(u1)) / sqrt(abs(Float32(u1 - Float32(1.0)))))
                                end
                                
                                \frac{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\right|}}
                                
                                Derivation
                                1. Initial program 99.0%

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

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

                                    \[\leadsto \frac{\sqrt{\left|u1\right|} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\left|u1\right|}\right)}{\sqrt{\left|u1 - 1\right|}} \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites88.1%

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

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

                                      Alternative 9: 88.1% accurate, 1.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{\mathsf{fma}\left(\left(-19.739208802181317 \cdot u2\right) \cdot u2, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\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)))
                                        (/
                                       (fma (* (* -19.739208802181317 u2) u2) (sqrt u1) (sqrt u1))
                                       (sqrt (fabs (- u1 1.0)))))
                                      float code(float cosTheta_i, float u1, float u2) {
                                      	return fmaf(((-19.739208802181317f * u2) * u2), sqrtf(u1), sqrtf(u1)) / sqrtf(fabsf((u1 - 1.0f)));
                                      }
                                      
                                      function code(cosTheta_i, u1, u2)
                                      	return Float32(fma(Float32(Float32(Float32(-19.739208802181317) * u2) * u2), sqrt(u1), sqrt(u1)) / sqrt(abs(Float32(u1 - Float32(1.0)))))
                                      end
                                      
                                      \frac{\mathsf{fma}\left(\left(-19.739208802181317 \cdot u2\right) \cdot u2, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\right|}}
                                      
                                      Derivation
                                      1. Initial program 99.0%

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

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

                                          \[\leadsto \frac{\sqrt{\left|u1\right|} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\left|u1\right|}\right)}{\sqrt{\left|u1 - 1\right|}} \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites88.1%

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

                                              \[\leadsto \frac{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\right|}} \]
                                            2. Step-by-step derivation
                                              1. Applied rewrites88.1%

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

                                              Alternative 10: 88.1% accurate, 1.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{\mathsf{fma}\left(\sqrt{u1} \cdot u2, -19.739208802181317 \cdot u2, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\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)))
                                                (/
                                               (fma (* (sqrt u1) u2) (* -19.739208802181317 u2) (sqrt u1))
                                               (sqrt (fabs (- u1 1.0)))))
                                              float code(float cosTheta_i, float u1, float u2) {
                                              	return fmaf((sqrtf(u1) * u2), (-19.739208802181317f * u2), sqrtf(u1)) / sqrtf(fabsf((u1 - 1.0f)));
                                              }
                                              
                                              function code(cosTheta_i, u1, u2)
                                              	return Float32(fma(Float32(sqrt(u1) * u2), Float32(Float32(-19.739208802181317) * u2), sqrt(u1)) / sqrt(abs(Float32(u1 - Float32(1.0)))))
                                              end
                                              
                                              \frac{\mathsf{fma}\left(\sqrt{u1} \cdot u2, -19.739208802181317 \cdot u2, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\right|}}
                                              
                                              Derivation
                                              1. Initial program 99.0%

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

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

                                                  \[\leadsto \frac{\sqrt{\left|u1\right|} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\left|u1\right|}\right)}{\sqrt{\left|u1 - 1\right|}} \]
                                                3. Step-by-step derivation
                                                  1. Applied rewrites88.1%

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

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

                                                    Alternative 11: 88.1% 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)\]
                                                    \[\frac{\mathsf{fma}\left(u2 \cdot u2, -19.739208802181317, 1\right) \cdot \sqrt{u1}}{\sqrt{\left|u1 - 1\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)))
                                                      (/
                                                     (* (fma (* u2 u2) -19.739208802181317 1.0) (sqrt u1))
                                                     (sqrt (fabs (- u1 1.0)))))
                                                    float code(float cosTheta_i, float u1, float u2) {
                                                    	return (fmaf((u2 * u2), -19.739208802181317f, 1.0f) * sqrtf(u1)) / sqrtf(fabsf((u1 - 1.0f)));
                                                    }
                                                    
                                                    function code(cosTheta_i, u1, u2)
                                                    	return Float32(Float32(fma(Float32(u2 * u2), Float32(-19.739208802181317), Float32(1.0)) * sqrt(u1)) / sqrt(abs(Float32(u1 - Float32(1.0)))))
                                                    end
                                                    
                                                    \frac{\mathsf{fma}\left(u2 \cdot u2, -19.739208802181317, 1\right) \cdot \sqrt{u1}}{\sqrt{\left|u1 - 1\right|}}
                                                    
                                                    Derivation
                                                    1. Initial program 99.0%

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

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

                                                        \[\leadsto \frac{\sqrt{\left|u1\right|} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\left|u1\right|}\right)}{\sqrt{\left|u1 - 1\right|}} \]
                                                      3. Step-by-step derivation
                                                        1. Applied rewrites88.1%

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

                                                            \[\leadsto \frac{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|u1 - 1\right|}} \]
                                                          2. Step-by-step derivation
                                                            1. Applied rewrites88.1%

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

                                                            Alternative 12: 83.3% accurate, 0.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)\]
                                                            \[\begin{array}{l} t_0 := \sqrt{\frac{u1}{1 - u1}}\\ \mathbf{if}\;t\_0 \cdot \cos \left(6.28318530718 \cdot u2\right) \leq 0.0005920000257901847:\\ \;\;\;\;\frac{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|-1\right|}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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)))
                                                              (let* ((t_0 (sqrt (/ u1 (- 1.0 u1)))))
                                                              (if (<= (* t_0 (cos (* 6.28318530718 u2))) 0.0005920000257901847)
                                                                (/
                                                                 (fma (* (* u2 u2) -19.739208802181317) (sqrt u1) (sqrt u1))
                                                                 (sqrt (fabs -1.0)))
                                                                t_0)))
                                                            float code(float cosTheta_i, float u1, float u2) {
                                                            	float t_0 = sqrtf((u1 / (1.0f - u1)));
                                                            	float tmp;
                                                            	if ((t_0 * cosf((6.28318530718f * u2))) <= 0.0005920000257901847f) {
                                                            		tmp = fmaf(((u2 * u2) * -19.739208802181317f), sqrtf(u1), sqrtf(u1)) / sqrtf(fabsf(-1.0f));
                                                            	} else {
                                                            		tmp = t_0;
                                                            	}
                                                            	return tmp;
                                                            }
                                                            
                                                            function code(cosTheta_i, u1, u2)
                                                            	t_0 = sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))
                                                            	tmp = Float32(0.0)
                                                            	if (Float32(t_0 * cos(Float32(Float32(6.28318530718) * u2))) <= Float32(0.0005920000257901847))
                                                            		tmp = Float32(fma(Float32(Float32(u2 * u2) * Float32(-19.739208802181317)), sqrt(u1), sqrt(u1)) / sqrt(abs(Float32(-1.0))));
                                                            	else
                                                            		tmp = t_0;
                                                            	end
                                                            	return tmp
                                                            end
                                                            
                                                            \begin{array}{l}
                                                            t_0 := \sqrt{\frac{u1}{1 - u1}}\\
                                                            \mathbf{if}\;t\_0 \cdot \cos \left(6.28318530718 \cdot u2\right) \leq 0.0005920000257901847:\\
                                                            \;\;\;\;\frac{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|-1\right|}}\\
                                                            
                                                            \mathbf{else}:\\
                                                            \;\;\;\;t\_0\\
                                                            
                                                            
                                                            \end{array}
                                                            
                                                            Derivation
                                                            1. Split input into 2 regimes
                                                            2. if (*.f32 (sqrt.f32 (/.f32 u1 (-.f32 #s(literal 1 binary32) u1))) (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2))) < 5.92000026e-4

                                                              1. Initial program 99.0%

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

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

                                                                  \[\leadsto \frac{\sqrt{\left|u1\right|} + \frac{-98696044010906577398881}{5000000000000000000000} \cdot \left({u2}^{2} \cdot \sqrt{\left|u1\right|}\right)}{\sqrt{\left|u1 - 1\right|}} \]
                                                                3. Step-by-step derivation
                                                                  1. Applied rewrites88.1%

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

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

                                                                      \[\leadsto \frac{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|-1\right|}} \]
                                                                    3. Step-by-step derivation
                                                                      1. Applied rewrites67.8%

                                                                        \[\leadsto \frac{\mathsf{fma}\left(\left(u2 \cdot u2\right) \cdot -19.739208802181317, \sqrt{u1}, \sqrt{u1}\right)}{\sqrt{\left|-1\right|}} \]

                                                                      if 5.92000026e-4 < (*.f32 (sqrt.f32 (/.f32 u1 (-.f32 #s(literal 1 binary32) u1))) (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)))

                                                                      1. Initial program 99.0%

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

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

                                                                          \[\leadsto \sqrt{\frac{u1}{1 - u1}} \]
                                                                      4. Recombined 2 regimes into one program.
                                                                      5. Add Preprocessing

                                                                      Alternative 13: 80.1% accurate, 5.3× 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}} \]
                                                                      (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))))
                                                                      float code(float cosTheta_i, float u1, float u2) {
                                                                      	return 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 = sqrt((u1 / (1.0e0 - u1)))
                                                                      end function
                                                                      
                                                                      function code(cosTheta_i, u1, u2)
                                                                      	return sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))
                                                                      end
                                                                      
                                                                      function tmp = code(cosTheta_i, u1, u2)
                                                                      	tmp = sqrt((u1 / (single(1.0) - u1)));
                                                                      end
                                                                      
                                                                      \sqrt{\frac{u1}{1 - u1}}
                                                                      
                                                                      Derivation
                                                                      1. Initial program 99.0%

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

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

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

                                                                        Alternative 14: 71.7% accurate, 5.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{u1 \cdot \left(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)))
                                                                          (sqrt (* u1 (+ 1.0 u1))))
                                                                        float code(float cosTheta_i, float u1, float u2) {
                                                                        	return 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 = sqrt((u1 * (1.0e0 + u1)))
                                                                        end function
                                                                        
                                                                        function code(cosTheta_i, u1, u2)
                                                                        	return sqrt(Float32(u1 * Float32(Float32(1.0) + u1)))
                                                                        end
                                                                        
                                                                        function tmp = code(cosTheta_i, u1, u2)
                                                                        	tmp = sqrt((u1 * (single(1.0) + u1)));
                                                                        end
                                                                        
                                                                        \sqrt{u1 \cdot \left(1 + u1\right)}
                                                                        
                                                                        Derivation
                                                                        1. Initial program 99.0%

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

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

                                                                            \[\leadsto \sqrt{\frac{u1}{1 - u1}} \]
                                                                          2. Taylor expanded in u1 around 0

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

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

                                                                            Alternative 15: 63.3% accurate, 16.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)\]
                                                                            \[\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)))
                                                                              (sqrt u1))
                                                                            float code(float cosTheta_i, float u1, float u2) {
                                                                            	return 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 = sqrt(u1)
                                                                            end function
                                                                            
                                                                            function code(cosTheta_i, u1, u2)
                                                                            	return sqrt(u1)
                                                                            end
                                                                            
                                                                            function tmp = code(cosTheta_i, u1, u2)
                                                                            	tmp = sqrt(u1);
                                                                            end
                                                                            
                                                                            \sqrt{u1}
                                                                            
                                                                            Derivation
                                                                            1. Initial program 99.0%

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

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

                                                                                \[\leadsto \sqrt{\frac{u1}{1 - u1}} \]
                                                                              2. Taylor expanded in u1 around 0

                                                                                \[\leadsto \sqrt{u1} \]
                                                                              3. Step-by-step derivation
                                                                                1. Applied rewrites63.3%

                                                                                  \[\leadsto \sqrt{u1} \]
                                                                                2. Add Preprocessing

                                                                                Reproduce

                                                                                ?
                                                                                herbie shell --seed 2025359 
                                                                                (FPCore (cosTheta_i u1 u2)
                                                                                  :name "Trowbridge-Reitz Sample, near normal, slope_x"
                                                                                  :precision binary32
                                                                                  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
                                                                                  (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))