Trowbridge-Reitz Sample, near normal, slope_y

Percentage Accurate: 98.3% → 98.3%
Time: 8.9s
Alternatives: 10
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 10 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.9× speedup?

\[\begin{array}{l} \\ \sin \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{u1}{\frac{u1 \cdot u1 - 1}{-1 - u1}}} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (*
  (sin (* u2 6.28318530718))
  (sqrt (/ u1 (/ (- (* u1 u1) 1.0) (- -1.0 u1))))))
float code(float cosTheta_i, float u1, float u2) {
	return sinf((u2 * 6.28318530718f)) * sqrtf((u1 / (((u1 * u1) - 1.0f) / (-1.0f - 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 = sin((u2 * 6.28318530718e0)) * sqrt((u1 / (((u1 * u1) - 1.0e0) / ((-1.0e0) - u1))))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sin(Float32(u2 * Float32(6.28318530718))) * sqrt(Float32(u1 / Float32(Float32(Float32(u1 * u1) - Float32(1.0)) / Float32(Float32(-1.0) - u1)))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sin((u2 * single(6.28318530718))) * sqrt((u1 / (((u1 * u1) - single(1.0)) / (single(-1.0) - u1))));
end
\begin{array}{l}

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

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

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

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

      \[\leadsto \sqrt{\frac{u1}{\color{blue}{\left(\mathsf{neg}\left(u1\right)\right) + 1}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    4. flip-+N/A

      \[\leadsto \sqrt{\frac{u1}{\color{blue}{\frac{\left(\mathsf{neg}\left(u1\right)\right) \cdot \left(\mathsf{neg}\left(u1\right)\right) - 1 \cdot 1}{\left(\mathsf{neg}\left(u1\right)\right) - 1}}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    5. sqr-negN/A

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

      \[\leadsto \sqrt{\frac{u1}{\color{blue}{\frac{u1 \cdot u1 - 1 \cdot 1}{\left(\mathsf{neg}\left(u1\right)\right) - 1}}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    7. metadata-evalN/A

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

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

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

      \[\leadsto \sqrt{\frac{u1}{\frac{u1 \cdot u1 - 1}{\color{blue}{\left(\mathsf{neg}\left(u1\right)\right) - 1}}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    11. lower-neg.f3298.3

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

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

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

Alternative 2: 98.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{-1}{\frac{u1 - 1}{u1}}} \cdot \sin \left(u2 \cdot 6.28318530718\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ -1.0 (/ (- u1 1.0) u1))) (sin (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((-1.0f / ((u1 - 1.0f) / u1))) * sinf((u2 * 6.28318530718f));
}
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(((-1.0e0) / ((u1 - 1.0e0) / u1))) * sin((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(Float32(-1.0) / Float32(Float32(u1 - Float32(1.0)) / u1))) * sin(Float32(u2 * Float32(6.28318530718))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((single(-1.0) / ((u1 - single(1.0)) / u1))) * sin((u2 * single(6.28318530718)));
end
\begin{array}{l}

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

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

    \[\leadsto \sqrt{\color{blue}{\frac{-1}{\frac{u1 - 1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  4. Final simplification98.3%

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

Alternative 3: 98.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(u2 \cdot 6.28318530718\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf((u2 * 6.28318530718f));
}
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((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(u2 * Float32(6.28318530718))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin((u2 * single(6.28318530718)));
end
\begin{array}{l}

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

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

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

Alternative 4: 89.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.012000000104308128:\\
\;\;\;\;\sqrt{\frac{\left(-1 - u1\right) \cdot u1}{u1 \cdot u1 - 1}} \cdot \left(u2 \cdot 6.28318530718\right)\\

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


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

    1. Initial program 98.4%

      \[\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. Applied rewrites96.4%

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

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

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

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

        1. Initial program 98.0%

          \[\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.f3276.1

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

          \[\leadsto \color{blue}{\sqrt{u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
      3. Recombined 2 regimes into one program.
      4. Final simplification92.2%

        \[\leadsto \begin{array}{l} \mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.012000000104308128:\\ \;\;\;\;\sqrt{\frac{\left(-1 - u1\right) \cdot u1}{u1 \cdot u1 - 1}} \cdot \left(u2 \cdot 6.28318530718\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1} \cdot \sin \left(u2 \cdot 6.28318530718\right)\\ \end{array} \]
      5. Add Preprocessing

      Alternative 5: 81.2% accurate, 2.8× speedup?

      \[\begin{array}{l} \\ \sqrt{\frac{\left(-1 - u1\right) \cdot u1}{u1 \cdot u1 - 1}} \cdot \left(u2 \cdot 6.28318530718\right) \end{array} \]
      (FPCore (cosTheta_i u1 u2)
       :precision binary32
       (* (sqrt (/ (* (- -1.0 u1) u1) (- (* u1 u1) 1.0))) (* u2 6.28318530718)))
      float code(float cosTheta_i, float u1, float u2) {
      	return sqrtf((((-1.0f - u1) * u1) / ((u1 * u1) - 1.0f))) * (u2 * 6.28318530718f);
      }
      
      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(((((-1.0e0) - u1) * u1) / ((u1 * u1) - 1.0e0))) * (u2 * 6.28318530718e0)
      end function
      
      function code(cosTheta_i, u1, u2)
      	return Float32(sqrt(Float32(Float32(Float32(Float32(-1.0) - u1) * u1) / Float32(Float32(u1 * u1) - Float32(1.0)))) * Float32(u2 * Float32(6.28318530718)))
      end
      
      function tmp = code(cosTheta_i, u1, u2)
      	tmp = sqrt((((single(-1.0) - u1) * u1) / ((u1 * u1) - single(1.0)))) * (u2 * single(6.28318530718));
      end
      
      \begin{array}{l}
      
      \\
      \sqrt{\frac{\left(-1 - u1\right) \cdot u1}{u1 \cdot u1 - 1}} \cdot \left(u2 \cdot 6.28318530718\right)
      \end{array}
      
      Derivation
      1. Initial program 98.3%

        \[\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. Applied rewrites84.9%

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

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

            \[\leadsto \sqrt{\frac{u1 \cdot \left(\left(-u1\right) - 1\right)}{u1 \cdot u1 - 1}} \cdot \left(6.28318530718 \cdot u2\right) \]
          2. Final simplification85.0%

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

          Alternative 6: 81.2% accurate, 3.9× speedup?

          \[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot 6.28318530718\right) \end{array} \]
          (FPCore (cosTheta_i u1 u2)
           :precision binary32
           (* (sqrt (/ u1 (- 1.0 u1))) (* u2 6.28318530718)))
          float code(float cosTheta_i, float u1, float u2) {
          	return sqrtf((u1 / (1.0f - u1))) * (u2 * 6.28318530718f);
          }
          
          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))) * (u2 * 6.28318530718e0)
          end function
          
          function code(cosTheta_i, u1, u2)
          	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(u2 * Float32(6.28318530718)))
          end
          
          function tmp = code(cosTheta_i, u1, u2)
          	tmp = sqrt((u1 / (single(1.0) - u1))) * (u2 * single(6.28318530718));
          end
          
          \begin{array}{l}
          
          \\
          \sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot 6.28318530718\right)
          \end{array}
          
          Derivation
          1. Initial program 98.3%

            \[\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. Applied rewrites84.9%

            \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(6.28318530718 \cdot u2\right)} \]
          6. Final simplification84.9%

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

          Alternative 7: 64.4% accurate, 6.4× speedup?

          \[\begin{array}{l} \\ \left(\sqrt{u1} \cdot u2\right) \cdot 6.28318530718 \end{array} \]
          (FPCore (cosTheta_i u1 u2)
           :precision binary32
           (* (* (sqrt u1) u2) 6.28318530718))
          float code(float cosTheta_i, float u1, float u2) {
          	return (sqrtf(u1) * u2) * 6.28318530718f;
          }
          
          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) * u2) * 6.28318530718e0
          end function
          
          function code(cosTheta_i, u1, u2)
          	return Float32(Float32(sqrt(u1) * u2) * Float32(6.28318530718))
          end
          
          function tmp = code(cosTheta_i, u1, u2)
          	tmp = (sqrt(u1) * u2) * single(6.28318530718);
          end
          
          \begin{array}{l}
          
          \\
          \left(\sqrt{u1} \cdot u2\right) \cdot 6.28318530718
          \end{array}
          
          Derivation
          1. Initial program 98.3%

            \[\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. Applied rewrites84.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 rewrites67.9%

              \[\leadsto \left(\sqrt{u1} \cdot u2\right) \cdot \color{blue}{6.28318530718} \]
            2. 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.3%

              \[\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. Applied rewrites84.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 rewrites67.9%

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

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

                Alternative 9: 19.6% accurate, 22.5× speedup?

                \[\begin{array}{l} \\ u2 \cdot 6.28318530718 \end{array} \]
                (FPCore (cosTheta_i u1 u2) :precision binary32 (* u2 6.28318530718))
                float code(float cosTheta_i, float u1, float u2) {
                	return u2 * 6.28318530718f;
                }
                
                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
                end function
                
                function code(cosTheta_i, u1, u2)
                	return Float32(u2 * Float32(6.28318530718))
                end
                
                function tmp = code(cosTheta_i, u1, u2)
                	tmp = u2 * single(6.28318530718);
                end
                
                \begin{array}{l}
                
                \\
                u2 \cdot 6.28318530718
                \end{array}
                
                Derivation
                1. Initial program 98.3%

                  \[\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. Applied rewrites84.9%

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

                    \[\leadsto \sqrt{\frac{u1 \cdot \left(\left(-u1\right) - 1\right)}{\mathsf{fma}\left(u1, u1, -1\right)}} \cdot \left(6.28318530718 \cdot u2\right) \]
                  2. Applied rewrites66.2%

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

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

                      \[\leadsto 6.28318530718 \cdot \color{blue}{u2} \]
                    2. Final simplification19.1%

                      \[\leadsto u2 \cdot 6.28318530718 \]
                    3. Add Preprocessing

                    Alternative 10: 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.3%

                      \[\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. Applied rewrites84.9%

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

                        \[\leadsto \sqrt{\frac{u1 \cdot \left(\left(-u1\right) - 1\right)}{\mathsf{fma}\left(u1, u1, -1\right)}} \cdot \left(6.28318530718 \cdot u2\right) \]
                      2. Applied rewrites66.2%

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

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

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

                        Reproduce

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