
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (* (* (- (/ 2.0 ux) 1.0) ux) ux)))
(if (<= maxCos 4.5000000170603016e-8)
(* (sqrt t_1) t_0)
(*
(sqrt
(*
(* maxCos maxCos)
(- (/ (- (/ t_1 maxCos) (* (* (- 1.0 ux) ux) 2.0)) maxCos) (* ux ux))))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_1 := \left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux\\
\mathbf{if}\;maxCos \leq 4.5000000170603016 \cdot 10^{-8}:\\
\;\;\;\;\sqrt{t\_1} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\frac{\frac{t\_1}{maxCos} - \left(\left(1 - ux\right) \cdot ux\right) \cdot 2}{maxCos} - ux \cdot ux\right)} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 4.50000002e-8Initial program 61.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3266.4
Applied rewrites66.4%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
if 4.50000002e-8 < maxCos Initial program 50.4%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites48.0%
Taylor expanded in ux around inf
Applied rewrites98.9%
Final simplification98.9%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* ux ux) (- (/ (+ (* -2.0 maxCos) 2.0) ux) (pow (- maxCos 1.0) 2.0)))) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{-2 \cdot maxCos + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 59.5%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3263.7
Applied rewrites63.7%
Applied rewrites98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= maxCos 4.5000000170603016e-8)
(* (sqrt (* (* (- (/ 2.0 ux) 1.0) ux) ux)) t_0)
(*
(sqrt
(*
(-
(/ (- (/ (* (- 2.0 ux) ux) maxCos) (* (* (- 1.0 ux) ux) 2.0)) maxCos)
(* ux ux))
(* maxCos maxCos)))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;maxCos \leq 4.5000000170603016 \cdot 10^{-8}:\\
\;\;\;\;\sqrt{\left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{\frac{\left(2 - ux\right) \cdot ux}{maxCos} - \left(\left(1 - ux\right) \cdot ux\right) \cdot 2}{maxCos} - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 4.50000002e-8Initial program 61.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3266.4
Applied rewrites66.4%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
if 4.50000002e-8 < maxCos Initial program 50.4%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites48.0%
Taylor expanded in ux around 0
Applied rewrites98.7%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (- (+ -1.0 ux) (* maxCos ux))))
(if (<= (- 1.0 (* t_1 t_1)) 0.0003600000054575503)
(* (sqrt (* (fma maxCos -2.0 2.0) ux)) t_0)
(* (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 (- ux (* maxCos ux)))))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_1 := \left(-1 + ux\right) - maxCos \cdot ux\\
\mathbf{if}\;1 - t\_1 \cdot t\_1 \leq 0.0003600000054575503:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(maxCos, -2, 2\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(1 - \left(ux - maxCos \cdot ux\right)\right)} \cdot t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)))) < 3.60000005e-4Initial program 37.3%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3260.0
Applied rewrites60.3%
if 3.60000005e-4 < (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)))) Initial program 89.3%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3289.5
lift-*.f32N/A
*-commutativeN/A
lower-*.f3289.5
Applied rewrites89.5%
Taylor expanded in maxCos around 0
lower--.f3285.0
Applied rewrites85.0%
Final simplification86.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (- (/ 2.0 ux) 1.0) ux) ux)))
(if (<= maxCos 1.9999999494757503e-5)
(* (sqrt t_0) (cos (* (PI) (* 2.0 uy))))
(*
1.0
(sqrt
(*
(* maxCos maxCos)
(-
(/ (- (/ t_0 maxCos) (* (* (- 1.0 ux) ux) 2.0)) maxCos)
(* ux ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux\\
\mathbf{if}\;maxCos \leq 1.9999999494757503 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{t\_0} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\frac{\frac{t\_0}{maxCos} - \left(\left(1 - ux\right) \cdot ux\right) \cdot 2}{maxCos} - ux \cdot ux\right)}\\
\end{array}
\end{array}
if maxCos < 1.99999995e-5Initial program 59.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3266.4
Applied rewrites66.4%
Taylor expanded in maxCos around 0
Applied rewrites98.1%
if 1.99999995e-5 < maxCos Initial program 56.7%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites54.7%
Taylor expanded in ux around inf
Applied rewrites98.9%
Taylor expanded in uy around 0
Applied rewrites85.5%
Final simplification96.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= ux 0.00018000000272877514)
(* (sqrt (* (fma maxCos -2.0 2.0) ux)) t_0)
(* (sqrt (- 1.0 (* (- 1.0 ux) (- (* maxCos ux) (+ -1.0 ux))))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;ux \leq 0.00018000000272877514:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(maxCos, -2, 2\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right)} \cdot t\_0\\
\end{array}
\end{array}
if ux < 1.80000003e-4Initial program 37.3%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3260.0
Applied rewrites60.0%
if 1.80000003e-4 < ux Initial program 89.3%
Taylor expanded in maxCos around 0
lower--.f3284.9
Applied rewrites84.9%
Final simplification86.1%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.00139999995008111) (* (sqrt (* (- (/ 2.0 ux) 1.0) (* ux ux))) 1.0) (* (sqrt (* (fma maxCos -2.0 2.0) ux)) (cos (* (PI) (* 2.0 uy))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.00139999995008111:\\
\;\;\;\;\sqrt{\left(\frac{2}{ux} - 1\right) \cdot \left(ux \cdot ux\right)} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(maxCos, -2, 2\right) \cdot ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 0.00139999995Initial program 61.7%
Taylor expanded in uy around 0
Applied rewrites61.3%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
remove-double-divN/A
lift-/.f32N/A
div-invN/A
lower-/.f3258.6
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f3258.2
Applied rewrites58.2%
Taylor expanded in ux around inf
Applied rewrites90.0%
Taylor expanded in maxCos around 0
Applied rewrites90.1%
if 0.00139999995 < (*.f32 uy #s(literal 2 binary32)) Initial program 56.2%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3222.5
Applied rewrites22.5%
Final simplification83.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= ux 0.00018000000272877514)
(* (sqrt (* (fma maxCos -2.0 2.0) ux)) t_0)
(* (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux)))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;ux \leq 0.00018000000272877514:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(maxCos, -2, 2\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)} \cdot t\_0\\
\end{array}
\end{array}
if ux < 1.80000003e-4Initial program 37.3%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3260.0
Applied rewrites60.0%
if 1.80000003e-4 < ux Initial program 89.3%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3289.5
lift-*.f32N/A
*-commutativeN/A
lower-*.f3289.5
Applied rewrites89.5%
Taylor expanded in maxCos around 0
lower--.f3285.0
Applied rewrites85.0%
Taylor expanded in maxCos around 0
lower--.f3284.4
Applied rewrites84.4%
Final simplification85.9%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (/ 2.0 ux) 1.0)))
(if (<= maxCos 1.999999943436137e-9)
(* (sqrt (* t_0 (* ux ux))) 1.0)
(*
1.0
(sqrt
(*
(* maxCos maxCos)
(-
(/ (- (/ (* (* t_0 ux) ux) maxCos) (* (* (- 1.0 ux) ux) 2.0)) maxCos)
(* ux ux))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (2.0f / ux) - 1.0f;
float tmp;
if (maxCos <= 1.999999943436137e-9f) {
tmp = sqrtf((t_0 * (ux * ux))) * 1.0f;
} else {
tmp = 1.0f * sqrtf(((maxCos * maxCos) * ((((((t_0 * ux) * ux) / maxCos) - (((1.0f - ux) * ux) * 2.0f)) / maxCos) - (ux * ux))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: t_0
real(4) :: tmp
t_0 = (2.0e0 / ux) - 1.0e0
if (maxcos <= 1.999999943436137e-9) then
tmp = sqrt((t_0 * (ux * ux))) * 1.0e0
else
tmp = 1.0e0 * sqrt(((maxcos * maxcos) * ((((((t_0 * ux) * ux) / maxcos) - (((1.0e0 - ux) * ux) * 2.0e0)) / maxcos) - (ux * ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(2.0) / ux) - Float32(1.0)) tmp = Float32(0.0) if (maxCos <= Float32(1.999999943436137e-9)) tmp = Float32(sqrt(Float32(t_0 * Float32(ux * ux))) * Float32(1.0)); else tmp = Float32(Float32(1.0) * sqrt(Float32(Float32(maxCos * maxCos) * Float32(Float32(Float32(Float32(Float32(Float32(t_0 * ux) * ux) / maxCos) - Float32(Float32(Float32(Float32(1.0) - ux) * ux) * Float32(2.0))) / maxCos) - Float32(ux * ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = (single(2.0) / ux) - single(1.0); tmp = single(0.0); if (maxCos <= single(1.999999943436137e-9)) tmp = sqrt((t_0 * (ux * ux))) * single(1.0); else tmp = single(1.0) * sqrt(((maxCos * maxCos) * ((((((t_0 * ux) * ux) / maxCos) - (((single(1.0) - ux) * ux) * single(2.0))) / maxCos) - (ux * ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{ux} - 1\\
\mathbf{if}\;maxCos \leq 1.999999943436137 \cdot 10^{-9}:\\
\;\;\;\;\sqrt{t\_0 \cdot \left(ux \cdot ux\right)} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\frac{\frac{\left(t\_0 \cdot ux\right) \cdot ux}{maxCos} - \left(\left(1 - ux\right) \cdot ux\right) \cdot 2}{maxCos} - ux \cdot ux\right)}\\
\end{array}
\end{array}
if maxCos < 1.99999994e-9Initial program 61.4%
Taylor expanded in uy around 0
Applied rewrites51.5%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
remove-double-divN/A
lift-/.f32N/A
div-invN/A
lower-/.f3250.9
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f3250.9
Applied rewrites50.9%
Taylor expanded in ux around inf
Applied rewrites75.9%
Taylor expanded in maxCos around 0
Applied rewrites76.2%
if 1.99999994e-9 < maxCos Initial program 53.4%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites51.4%
Taylor expanded in ux around inf
Applied rewrites98.9%
Taylor expanded in uy around 0
Applied rewrites81.2%
Final simplification77.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (- (* maxCos ux) (+ -1.0 ux)) 0.9998999834060669) (* (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 (- ux (* maxCos ux)))))) 1.0) (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) 1.0)))
float code(float ux, float uy, float maxCos) {
float tmp;
if (((maxCos * ux) - (-1.0f + ux)) <= 0.9998999834060669f) {
tmp = sqrtf((1.0f - ((1.0f - ux) * (1.0f - (ux - (maxCos * ux)))))) * 1.0f;
} else {
tmp = sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux)) * 1.0f;
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(maxCos * ux) - Float32(Float32(-1.0) + ux)) <= Float32(0.9998999834060669)) tmp = Float32(sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * Float32(Float32(1.0) - Float32(ux - Float32(maxCos * ux)))))) * Float32(1.0)); else tmp = Float32(sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) * Float32(1.0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \cdot ux - \left(-1 + ux\right) \leq 0.9998999834060669:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(1 - \left(ux - maxCos \cdot ux\right)\right)} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot 1\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999899983Initial program 88.7%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3288.9
lift-*.f32N/A
*-commutativeN/A
lower-*.f3288.9
Applied rewrites88.9%
Taylor expanded in maxCos around 0
lower--.f3284.5
Applied rewrites84.5%
Taylor expanded in uy around 0
Applied rewrites68.4%
if 0.999899983 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 36.4%
Taylor expanded in uy around 0
Applied rewrites33.2%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3270.0
Applied rewrites69.7%
Final simplification68.5%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (* maxCos ux) (+ -1.0 ux))))
(if (<= t_0 0.9998999834060669)
(* (sqrt (- 1.0 (* (- 1.0 ux) t_0))) 1.0)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) 1.0))))
float code(float ux, float uy, float maxCos) {
float t_0 = (maxCos * ux) - (-1.0f + ux);
float tmp;
if (t_0 <= 0.9998999834060669f) {
tmp = sqrtf((1.0f - ((1.0f - ux) * t_0))) * 1.0f;
} else {
tmp = sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux)) * 1.0f;
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(maxCos * ux) - Float32(Float32(-1.0) + ux)) tmp = Float32(0.0) if (t_0 <= Float32(0.9998999834060669)) tmp = Float32(sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * t_0))) * Float32(1.0)); else tmp = Float32(sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) * Float32(1.0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := maxCos \cdot ux - \left(-1 + ux\right)\\
\mathbf{if}\;t\_0 \leq 0.9998999834060669:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot t\_0} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot 1\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999899983Initial program 88.7%
Taylor expanded in uy around 0
Applied rewrites71.1%
Taylor expanded in maxCos around 0
lower--.f3268.3
Applied rewrites68.3%
if 0.999899983 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 36.4%
Taylor expanded in uy around 0
Applied rewrites33.2%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3270.0
Applied rewrites69.7%
Final simplification69.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- (/ 2.0 ux) 1.0) (* ux ux))) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((((2.0f / ux) - 1.0f) * (ux * ux))) * 1.0f;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((((2.0e0 / ux) - 1.0e0) * (ux * ux))) * 1.0e0
end function
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(Float32(Float32(2.0) / ux) - Float32(1.0)) * Float32(ux * ux))) * Float32(1.0)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(2.0) / ux) - single(1.0)) * (ux * ux))) * single(1.0); end
\begin{array}{l}
\\
\sqrt{\left(\frac{2}{ux} - 1\right) \cdot \left(ux \cdot ux\right)} \cdot 1
\end{array}
Initial program 59.5%
Taylor expanded in uy around 0
Applied rewrites50.0%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
remove-double-divN/A
lift-/.f32N/A
div-invN/A
lower-/.f3248.0
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f3247.7
Applied rewrites22.0%
Taylor expanded in ux around inf
Applied rewrites72.2%
Taylor expanded in maxCos around 0
Applied rewrites72.5%
Final simplification72.5%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux)) * 1.0f;
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) * Float32(1.0)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot 1
\end{array}
Initial program 59.5%
Taylor expanded in uy around 0
Applied rewrites50.0%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3259.0
Applied rewrites54.8%
Final simplification59.0%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (fma -1.0 1.0 1.0)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(-1.0f, 1.0f, 1.0f)) * 1.0f;
}
function code(ux, uy, maxCos) return Float32(sqrt(fma(Float32(-1.0), Float32(1.0), Float32(1.0))) * Float32(1.0)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-1, 1, 1\right)} \cdot 1
\end{array}
Initial program 59.5%
Taylor expanded in uy around 0
Applied rewrites50.0%
Taylor expanded in ux around 0
Applied rewrites6.6%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
neg-mul-1N/A
lower-fma.f3220.3
Applied rewrites20.3%
Final simplification20.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (- 1.0 1.0)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - 1.0f)) * 1.0f;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((1.0e0 - 1.0e0)) * 1.0e0
end function
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(1.0) - Float32(1.0))) * Float32(1.0)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(1.0) - single(1.0))) * single(1.0); end
\begin{array}{l}
\\
\sqrt{1 - 1} \cdot 1
\end{array}
Initial program 59.5%
Taylor expanded in uy around 0
Applied rewrites50.0%
Taylor expanded in ux around 0
Applied rewrites6.6%
Final simplification6.6%
herbie shell --seed 2024267
(FPCore (ux uy maxCos)
:name "UniformSampleCone, x"
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))