Trowbridge-Reitz Sample, near normal, slope_y

Percentage Accurate: 98.3% → 98.4%
Time: 35.4s
Alternatives: 8
Speedup: 1.0×

Specification

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

\[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
(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)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2));
end
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)

Alternative 1: 98.4% accurate, 0.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 98.3% accurate, 1.0× speedup?

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

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. +-rgt-identityN/A

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{u1}{\left(1 - u1\right) + \color{blue}{\left(3 - 3\right)}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    9. associate-+r-N/A

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

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

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

    \[\leadsto \sqrt{\frac{u1}{\color{blue}{\left(\left(1 - u1\right) + 3\right) - 3}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  4. Step-by-step derivation
    1. lift--.f32N/A

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

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

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

      \[\leadsto \sqrt{\frac{u1}{\left(1 - u1\right) + \color{blue}{0}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    5. +-rgt-identity98.3%

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{u1}{\mathsf{neg}\left(\left(\frac{u1 \cdot u1}{u1} - \color{blue}{\frac{u1}{u1}}\right)\right)}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    15. sub-divN/A

      \[\leadsto \sqrt{\frac{u1}{\mathsf{neg}\left(\color{blue}{\frac{u1 \cdot u1 - u1}{u1}}\right)}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    16. sub-to-fractionN/A

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

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

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

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

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

      \[\leadsto \sqrt{\frac{u1}{\color{blue}{\frac{1}{2} - \left(u1 - \frac{1}{2}\right)}}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
    22. lower--.f3298.4%

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

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

Alternative 3: 93.4% accurate, 0.9× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u2 < 3.9999999e-4

    1. Initial program 98.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\left|1 - u1\right|}}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
      11. neg-fabsN/A

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

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

        \[\leadsto \frac{1}{\frac{\sqrt{\left|\mathsf{neg}\left(\color{blue}{\left(1 - u1\right)}\right)\right|}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
      14. sub-negate-revN/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{\frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
      4. lower-fabs.f3281.6%

        \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
    6. Applied rewrites81.6%

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

    if 3.9999999e-4 < u2

    1. Initial program 98.3%

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

      \[\leadsto \sqrt{\color{blue}{u1 \cdot \left(1 + u1\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    3. Step-by-step derivation
      1. lower-*.f32N/A

        \[\leadsto \sqrt{u1 \cdot \color{blue}{\left(1 + u1\right)}} \cdot \sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \]
      2. lower-+.f3286.1%

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

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

Alternative 4: 89.7% accurate, 1.1× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u2 < 0.00100000005

    1. Initial program 98.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\left|1 - u1\right|}}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
      11. neg-fabsN/A

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

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

        \[\leadsto \frac{1}{\frac{\sqrt{\left|\mathsf{neg}\left(\color{blue}{\left(1 - u1\right)}\right)\right|}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
      14. sub-negate-revN/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{\frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
      4. lower-fabs.f3281.6%

        \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
    6. Applied rewrites81.6%

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

    if 0.00100000005 < u2

    1. Initial program 98.3%

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

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

        \[\leadsto \sqrt{u1} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    4. Applied rewrites74.0%

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

Alternative 5: 81.6% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\left|1 - u1\right|}}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
    11. neg-fabsN/A

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left|\mathsf{neg}\left(\color{blue}{\left(1 - u1\right)}\right)\right|}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
    14. sub-negate-revN/A

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{\frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
    4. lower-fabs.f3281.6%

      \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
  6. Applied rewrites81.6%

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

Alternative 6: 74.6% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\left|1 - u1\right|}}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
    11. neg-fabsN/A

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left|\mathsf{neg}\left(\color{blue}{\left(1 - u1\right)}\right)\right|}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
    14. sub-negate-revN/A

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{\frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
    4. lower-fabs.f3281.6%

      \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
  6. Applied rewrites81.6%

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

    \[\leadsto \frac{1}{\frac{\color{blue}{1 + \frac{-1}{2} \cdot u1}}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
  8. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto \frac{1}{\frac{1 + \color{blue}{\frac{-1}{2} \cdot u1}}{\frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
    2. lower-*.f3274.6%

      \[\leadsto \frac{1}{\frac{1 + -0.5 \cdot \color{blue}{u1}}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
  9. Applied rewrites74.6%

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

Alternative 7: 64.7% accurate, 2.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{\left|1 - u1\right|}}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
    11. neg-fabsN/A

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left|\mathsf{neg}\left(\color{blue}{\left(1 - u1\right)}\right)\right|}}{\sin \left(\frac{314159265359}{50000000000} \cdot u2\right) \cdot \sqrt{\left|u1\right|}}} \]
    14. sub-negate-revN/A

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{\frac{314159265359}{50000000000} \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
    4. lower-fabs.f3281.6%

      \[\leadsto \frac{1}{\frac{\sqrt{\left|u1 - 1\right|}}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\left|u1\right|}\right)}} \]
  6. Applied rewrites81.6%

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

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

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

    Reproduce

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