Trowbridge-Reitz Sample, near normal, slope_y

Percentage Accurate: 98.3% → 98.3%
Time: 9.6s
Alternatives: 11
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)\]
\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (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)
    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
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 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?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (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)
    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
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}

Alternative 1: 98.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ {\left({\left(\frac{u1}{1 - u1}\right)}^{2}\right)}^{0.25} \cdot \sin \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (pow (pow (/ u1 (- 1.0 u1)) 2.0) 0.25) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return powf(powf((u1 / (1.0f - u1)), 2.0f), 0.25f) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = (((u1 / (1.0e0 - u1)) ** 2.0e0) ** 0.25e0) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(((Float32(u1 / Float32(Float32(1.0) - u1)) ^ Float32(2.0)) ^ Float32(0.25)) * sin(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = (((u1 / (single(1.0) - u1)) ^ single(2.0)) ^ single(0.25)) * sin((single(6.28318530718) * u2));
end
\begin{array}{l}

\\
{\left({\left(\frac{u1}{1 - u1}\right)}^{2}\right)}^{0.25} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-sqrt.f32N/A

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    2. pow1/2N/A

      \[\leadsto \color{blue}{{\left(\frac{u1}{1 - u1}\right)}^{\frac{1}{2}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    3. sqr-powN/A

      \[\leadsto \color{blue}{\left({\left(\frac{u1}{1 - u1}\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(\frac{u1}{1 - u1}\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    4. pow-prod-downN/A

      \[\leadsto \color{blue}{{\left(\frac{u1}{1 - u1} \cdot \frac{u1}{1 - u1}\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    5. lower-pow.f32N/A

      \[\leadsto \color{blue}{{\left(\frac{u1}{1 - u1} \cdot \frac{u1}{1 - u1}\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    6. pow2N/A

      \[\leadsto {\color{blue}{\left({\left(\frac{u1}{1 - u1}\right)}^{2}\right)}}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    7. lower-pow.f32N/A

      \[\leadsto {\color{blue}{\left({\left(\frac{u1}{1 - u1}\right)}^{2}\right)}}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    8. metadata-eval98.3

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

    \[\leadsto \color{blue}{{\left({\left(\frac{u1}{1 - u1}\right)}^{2}\right)}^{0.25}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  5. Add Preprocessing

Alternative 2: 97.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1 \cdot \mathsf{fma}\left(u1, u1, 1\right)}{\mathsf{fma}\left(u1, u1, 1\right) \cdot \left(1 - u1\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (*
  (sqrt (/ (* u1 (fma u1 u1 1.0)) (* (fma u1 u1 1.0) (- 1.0 u1))))
  (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(((u1 * fmaf(u1, u1, 1.0f)) / (fmaf(u1, u1, 1.0f) * (1.0f - u1)))) * sinf((6.28318530718f * u2));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(Float32(u1 * fma(u1, u1, Float32(1.0))) / Float32(fma(u1, u1, Float32(1.0)) * Float32(Float32(1.0) - u1)))) * sin(Float32(Float32(6.28318530718) * u2)))
end
\begin{array}{l}

\\
\sqrt{\frac{u1 \cdot \mathsf{fma}\left(u1, u1, 1\right)}{\mathsf{fma}\left(u1, u1, 1\right) \cdot \left(1 - u1\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Add Preprocessing
  3. Applied rewrites97.7%

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

Alternative 3: 98.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (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)
    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
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
Derivation
  1. Initial program 98.2%

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

Alternative 4: 89.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{u1}{1 - u1 \cdot u1}\\ \mathbf{if}\;6.28318530718 \cdot u2 \leq 0.004999999888241291:\\ \;\;\;\;\sqrt{t\_0 + u1 \cdot t\_0} \cdot \left(6.28318530718 \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1} \cdot \sin \left(6.28318530718 \cdot u2\right)\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (/ u1 (- 1.0 (* u1 u1)))))
   (if (<= (* 6.28318530718 u2) 0.004999999888241291)
     (* (sqrt (+ t_0 (* u1 t_0))) (* 6.28318530718 u2))
     (* (sqrt u1) (sin (* 6.28318530718 u2))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = u1 / (1.0f - (u1 * u1));
	float tmp;
	if ((6.28318530718f * u2) <= 0.004999999888241291f) {
		tmp = sqrtf((t_0 + (u1 * t_0))) * (6.28318530718f * u2);
	} else {
		tmp = sqrtf(u1) * sinf((6.28318530718f * u2));
	}
	return tmp;
}
real(4) function code(costheta_i, u1, u2)
    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 = u1 / (1.0e0 - (u1 * u1))
    if ((6.28318530718e0 * u2) <= 0.004999999888241291e0) then
        tmp = sqrt((t_0 + (u1 * t_0))) * (6.28318530718e0 * u2)
    else
        tmp = sqrt(u1) * sin((6.28318530718e0 * u2))
    end if
    code = tmp
end function
function code(cosTheta_i, u1, u2)
	t_0 = Float32(u1 / Float32(Float32(1.0) - Float32(u1 * u1)))
	tmp = Float32(0.0)
	if (Float32(Float32(6.28318530718) * u2) <= Float32(0.004999999888241291))
		tmp = Float32(sqrt(Float32(t_0 + Float32(u1 * t_0))) * Float32(Float32(6.28318530718) * u2));
	else
		tmp = Float32(sqrt(u1) * sin(Float32(Float32(6.28318530718) * u2)));
	end
	return tmp
end
function tmp_2 = code(cosTheta_i, u1, u2)
	t_0 = u1 / (single(1.0) - (u1 * u1));
	tmp = single(0.0);
	if ((single(6.28318530718) * u2) <= single(0.004999999888241291))
		tmp = sqrt((t_0 + (u1 * t_0))) * (single(6.28318530718) * u2);
	else
		tmp = sqrt(u1) * sin((single(6.28318530718) * u2));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{u1}{1 - u1 \cdot u1}\\
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.004999999888241291:\\
\;\;\;\;\sqrt{t\_0 + u1 \cdot t\_0} \cdot \left(6.28318530718 \cdot u2\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin \left(6.28318530718 \cdot u2\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 0.00499999989

    1. Initial program 98.5%

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

      \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
      2. associate-*l*N/A

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
      3. *-commutativeN/A

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
      4. lower-*.f32N/A

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
      5. lower-sqrt.f32N/A

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      6. lower-/.f32N/A

        \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      7. lower--.f32N/A

        \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      8. lower-*.f3297.3

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
    5. Applied rewrites97.3%

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

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

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

      1. Initial program 97.6%

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

        \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      4. Step-by-step derivation
        1. lower-sqrt.f3277.5

          \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
      5. Applied rewrites77.5%

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

    Alternative 5: 81.4% accurate, 2.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{u1}{1 - u1 \cdot u1}\\ \sqrt{t\_0 + u1 \cdot t\_0} \cdot \left(6.28318530718 \cdot u2\right) \end{array} \end{array} \]
    (FPCore (cosTheta_i u1 u2)
     :precision binary32
     (let* ((t_0 (/ u1 (- 1.0 (* u1 u1)))))
       (* (sqrt (+ t_0 (* u1 t_0))) (* 6.28318530718 u2))))
    float code(float cosTheta_i, float u1, float u2) {
    	float t_0 = u1 / (1.0f - (u1 * u1));
    	return sqrtf((t_0 + (u1 * t_0))) * (6.28318530718f * u2);
    }
    
    real(4) function code(costheta_i, u1, u2)
        real(4), intent (in) :: costheta_i
        real(4), intent (in) :: u1
        real(4), intent (in) :: u2
        real(4) :: t_0
        t_0 = u1 / (1.0e0 - (u1 * u1))
        code = sqrt((t_0 + (u1 * t_0))) * (6.28318530718e0 * u2)
    end function
    
    function code(cosTheta_i, u1, u2)
    	t_0 = Float32(u1 / Float32(Float32(1.0) - Float32(u1 * u1)))
    	return Float32(sqrt(Float32(t_0 + Float32(u1 * t_0))) * Float32(Float32(6.28318530718) * u2))
    end
    
    function tmp = code(cosTheta_i, u1, u2)
    	t_0 = u1 / (single(1.0) - (u1 * u1));
    	tmp = sqrt((t_0 + (u1 * t_0))) * (single(6.28318530718) * u2);
    end
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{u1}{1 - u1 \cdot u1}\\
    \sqrt{t\_0 + u1 \cdot t\_0} \cdot \left(6.28318530718 \cdot u2\right)
    \end{array}
    \end{array}
    
    Derivation
    1. Initial program 98.2%

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

      \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
      2. associate-*l*N/A

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
      3. *-commutativeN/A

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
      4. lower-*.f32N/A

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
      5. lower-sqrt.f32N/A

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      6. lower-/.f32N/A

        \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      7. lower--.f32N/A

        \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      8. lower-*.f3280.9

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
    5. Applied rewrites80.9%

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

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

      Alternative 6: 81.1% accurate, 2.4× speedup?

      \[\begin{array}{l} \\ \sqrt{\frac{\mathsf{fma}\left(u1, u1, 1\right) \cdot u1}{\left(1 - u1\right) \cdot \mathsf{fma}\left(u1, u1, 1\right)}} \cdot \left(6.28318530718 \cdot u2\right) \end{array} \]
      (FPCore (cosTheta_i u1 u2)
       :precision binary32
       (*
        (sqrt (/ (* (fma u1 u1 1.0) u1) (* (- 1.0 u1) (fma u1 u1 1.0))))
        (* 6.28318530718 u2)))
      float code(float cosTheta_i, float u1, float u2) {
      	return sqrtf(((fmaf(u1, u1, 1.0f) * u1) / ((1.0f - u1) * fmaf(u1, u1, 1.0f)))) * (6.28318530718f * u2);
      }
      
      function code(cosTheta_i, u1, u2)
      	return Float32(sqrt(Float32(Float32(fma(u1, u1, Float32(1.0)) * u1) / Float32(Float32(Float32(1.0) - u1) * fma(u1, u1, Float32(1.0))))) * Float32(Float32(6.28318530718) * u2))
      end
      
      \begin{array}{l}
      
      \\
      \sqrt{\frac{\mathsf{fma}\left(u1, u1, 1\right) \cdot u1}{\left(1 - u1\right) \cdot \mathsf{fma}\left(u1, u1, 1\right)}} \cdot \left(6.28318530718 \cdot u2\right)
      \end{array}
      
      Derivation
      1. Initial program 98.2%

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

        \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
        2. associate-*l*N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
        3. *-commutativeN/A

          \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
        4. lower-*.f32N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
        5. lower-sqrt.f32N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        6. lower-/.f32N/A

          \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        7. lower--.f32N/A

          \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        8. lower-*.f3280.9

          \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
      5. Applied rewrites80.9%

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(6.28318530718 \cdot u2\right)} \]
      6. Applied rewrites63.5%

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

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

      Alternative 7: 81.4% accurate, 3.9× speedup?

      \[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \left(6.28318530718 \cdot u2\right) \end{array} \]
      (FPCore (cosTheta_i u1 u2)
       :precision binary32
       (* (sqrt (/ u1 (- 1.0 u1))) (* 6.28318530718 u2)))
      float code(float cosTheta_i, float u1, float u2) {
      	return sqrtf((u1 / (1.0f - u1))) * (6.28318530718f * u2);
      }
      
      real(4) function code(costheta_i, u1, u2)
          real(4), intent (in) :: costheta_i
          real(4), intent (in) :: u1
          real(4), intent (in) :: u2
          code = sqrt((u1 / (1.0e0 - u1))) * (6.28318530718e0 * u2)
      end function
      
      function code(cosTheta_i, u1, u2)
      	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(6.28318530718) * u2))
      end
      
      function tmp = code(cosTheta_i, u1, u2)
      	tmp = sqrt((u1 / (single(1.0) - u1))) * (single(6.28318530718) * u2);
      end
      
      \begin{array}{l}
      
      \\
      \sqrt{\frac{u1}{1 - u1}} \cdot \left(6.28318530718 \cdot u2\right)
      \end{array}
      
      Derivation
      1. Initial program 98.2%

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

        \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
        2. associate-*l*N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
        3. *-commutativeN/A

          \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
        4. lower-*.f32N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
        5. lower-sqrt.f32N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        6. lower-/.f32N/A

          \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        7. lower--.f32N/A

          \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        8. lower-*.f3280.9

          \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
      5. Applied rewrites80.9%

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

      Alternative 8: 64.5% accurate, 6.4× speedup?

      \[\begin{array}{l} \\ \left(\sqrt{u1} \cdot 6.28318530718\right) \cdot u2 \end{array} \]
      (FPCore (cosTheta_i u1 u2)
       :precision binary32
       (* (* (sqrt u1) 6.28318530718) u2))
      float code(float cosTheta_i, float u1, float u2) {
      	return (sqrtf(u1) * 6.28318530718f) * u2;
      }
      
      real(4) function code(costheta_i, u1, u2)
          real(4), intent (in) :: costheta_i
          real(4), intent (in) :: u1
          real(4), intent (in) :: u2
          code = (sqrt(u1) * 6.28318530718e0) * u2
      end function
      
      function code(cosTheta_i, u1, u2)
      	return Float32(Float32(sqrt(u1) * Float32(6.28318530718)) * u2)
      end
      
      function tmp = code(cosTheta_i, u1, u2)
      	tmp = (sqrt(u1) * single(6.28318530718)) * u2;
      end
      
      \begin{array}{l}
      
      \\
      \left(\sqrt{u1} \cdot 6.28318530718\right) \cdot u2
      \end{array}
      
      Derivation
      1. Initial program 98.2%

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

        \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
        2. associate-*l*N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
        3. *-commutativeN/A

          \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
        4. lower-*.f32N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
        5. lower-sqrt.f32N/A

          \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        6. lower-/.f32N/A

          \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        7. lower--.f32N/A

          \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
        8. lower-*.f3280.9

          \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
      5. Applied rewrites80.9%

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

        \[\leadsto \frac{314159265359}{50000000000} \cdot \color{blue}{\left(\sqrt{u1} \cdot u2\right)} \]
      7. Step-by-step derivation
        1. Applied rewrites65.2%

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

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

          Alternative 9: 64.5% accurate, 6.4× speedup?

          \[\begin{array}{l} \\ \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1} \end{array} \]
          (FPCore (cosTheta_i u1 u2)
           :precision binary32
           (* (* 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)
              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
          
          \begin{array}{l}
          
          \\
          \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}
          \end{array}
          
          Derivation
          1. Initial program 98.2%

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

            \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
            2. associate-*l*N/A

              \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
            3. *-commutativeN/A

              \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
            4. lower-*.f32N/A

              \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
            5. lower-sqrt.f32N/A

              \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
            6. lower-/.f32N/A

              \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
            7. lower--.f32N/A

              \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
            8. lower-*.f3280.9

              \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
          5. Applied rewrites80.9%

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

            \[\leadsto \frac{314159265359}{50000000000} \cdot \color{blue}{\left(\sqrt{u1} \cdot u2\right)} \]
          7. Step-by-step derivation
            1. Applied rewrites65.2%

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

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

              Alternative 10: 19.6% accurate, 22.5× speedup?

              \[\begin{array}{l} \\ 6.28318530718 \cdot u2 \end{array} \]
              (FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 u2))
              float code(float cosTheta_i, float u1, float u2) {
              	return 6.28318530718f * u2;
              }
              
              real(4) function code(costheta_i, u1, u2)
                  real(4), intent (in) :: costheta_i
                  real(4), intent (in) :: u1
                  real(4), intent (in) :: u2
                  code = 6.28318530718e0 * u2
              end function
              
              function code(cosTheta_i, u1, u2)
              	return Float32(Float32(6.28318530718) * u2)
              end
              
              function tmp = code(cosTheta_i, u1, u2)
              	tmp = single(6.28318530718) * u2;
              end
              
              \begin{array}{l}
              
              \\
              6.28318530718 \cdot u2
              \end{array}
              
              Derivation
              1. Initial program 98.2%

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

                \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
                2. associate-*l*N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
                3. *-commutativeN/A

                  \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
                4. lower-*.f32N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
                5. lower-sqrt.f32N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
                6. lower-/.f32N/A

                  \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
                7. lower--.f32N/A

                  \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
                8. lower-*.f3280.9

                  \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
              5. Applied rewrites80.9%

                \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(6.28318530718 \cdot u2\right)} \]
              6. Applied rewrites63.5%

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

                \[\leadsto \frac{314159265359}{50000000000} \cdot \color{blue}{u2} \]
              8. Step-by-step derivation
                1. Applied rewrites19.2%

                  \[\leadsto 6.28318530718 \cdot \color{blue}{u2} \]
                2. Add Preprocessing

                Alternative 11: 4.3% accurate, 22.5× speedup?

                \[\begin{array}{l} \\ -6.28318530718 \cdot u2 \end{array} \]
                (FPCore (cosTheta_i u1 u2) :precision binary32 (* -6.28318530718 u2))
                float code(float cosTheta_i, float u1, float u2) {
                	return -6.28318530718f * u2;
                }
                
                real(4) function code(costheta_i, u1, u2)
                    real(4), intent (in) :: costheta_i
                    real(4), intent (in) :: u1
                    real(4), intent (in) :: u2
                    code = (-6.28318530718e0) * u2
                end function
                
                function code(cosTheta_i, u1, u2)
                	return Float32(Float32(-6.28318530718) * u2)
                end
                
                function tmp = code(cosTheta_i, u1, u2)
                	tmp = single(-6.28318530718) * u2;
                end
                
                \begin{array}{l}
                
                \\
                -6.28318530718 \cdot u2
                \end{array}
                
                Derivation
                1. Initial program 98.2%

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

                  \[\leadsto \color{blue}{\frac{314159265359}{50000000000} \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
                4. Step-by-step derivation
                  1. *-commutativeN/A

                    \[\leadsto \color{blue}{\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \frac{314159265359}{50000000000}} \]
                  2. associate-*l*N/A

                    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot \frac{314159265359}{50000000000}\right)} \]
                  3. *-commutativeN/A

                    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
                  4. lower-*.f32N/A

                    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right)} \]
                  5. lower-sqrt.f32N/A

                    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
                  6. lower-/.f32N/A

                    \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
                  7. lower--.f32N/A

                    \[\leadsto \sqrt{\frac{u1}{\color{blue}{1 - u1}}} \cdot \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
                  8. lower-*.f3280.9

                    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
                5. Applied rewrites80.9%

                  \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(6.28318530718 \cdot u2\right)} \]
                6. Applied rewrites63.5%

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

                  \[\leadsto \frac{314159265359}{50000000000} \cdot \color{blue}{\left(u2 \cdot {\left(\sqrt{-1}\right)}^{2}\right)} \]
                8. Step-by-step derivation
                  1. Applied rewrites4.5%

                    \[\leadsto -6.28318530718 \cdot \color{blue}{u2} \]
                  2. Add Preprocessing

                  Reproduce

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