
(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
(if (<= maxCos 4.9499998766577846e-8)
(* (cos (* (* (PI) uy) 2.0)) (sqrt (+ (* (- 1.0 ux) ux) ux)))
(*
(sqrt
(*
(-
(*
(+
(/ (- 2.0 (/ 2.0 ux)) maxCos)
(/ (- (/ 2.0 ux) 1.0) (* maxCos maxCos)))
(* ux ux))
(* ux ux))
(* maxCos maxCos)))
(cos (* (PI) (* 2.0 uy))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 4.9499998766577846 \cdot 10^{-8}:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{2 - \frac{2}{ux}}{maxCos} + \frac{\frac{2}{ux} - 1}{maxCos \cdot maxCos}\right) \cdot \left(ux \cdot ux\right) - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if maxCos < 4.94999988e-8Initial program 59.1%
Taylor expanded in uy around 0
Applied rewrites51.0%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites50.3%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3299.0
Applied rewrites99.0%
if 4.94999988e-8 < maxCos Initial program 57.4%
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-*.f3248.3
Applied rewrites48.3%
Applied rewrites98.8%
Taylor expanded in maxCos around inf
Applied rewrites98.9%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= t_0 0.9999998211860657)
(* (sqrt (* (- (/ 2.0 ux) 1.0) (* ux ux))) t_0)
(*
1.0
(sqrt
(*
(* ux ux)
(- (/ (+ (* -2.0 maxCos) 2.0) ux) (pow (- maxCos 1.0) 2.0))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;t\_0 \leq 0.9999998211860657:\\
\;\;\;\;\sqrt{\left(\frac{2}{ux} - 1\right) \cdot \left(ux \cdot ux\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{-2 \cdot maxCos + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) < 0.999999821Initial program 60.4%
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-*.f3237.7
Applied rewrites39.1%
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites92.4%
if 0.999999821 < (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) Initial program 57.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-*.f3292.2
Applied rewrites92.2%
Applied rewrites99.3%
Taylor expanded in uy around 0
Applied rewrites99.2%
Final simplification96.2%
(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 58.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-*.f3267.5
Applied rewrites67.9%
Applied rewrites98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 9.99999993922529e-9)
(* (cos (* (* (PI) uy) 2.0)) (sqrt (+ (* (- 1.0 ux) ux) ux)))
(*
(sqrt
(*
(*
(-
(/
(*
(- (/ -1.0 maxCos) (- (/ (- 2.0 (/ 2.0 maxCos)) ux) 2.0))
(* ux ux))
maxCos)
(* ux ux))
maxCos)
maxCos))
(cos (* (PI) (* 2.0 uy))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 9.99999993922529 \cdot 10^{-9}:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{\left(\frac{-1}{maxCos} - \left(\frac{2 - \frac{2}{maxCos}}{ux} - 2\right)\right) \cdot \left(ux \cdot ux\right)}{maxCos} - ux \cdot ux\right) \cdot maxCos\right) \cdot maxCos} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if maxCos < 9.99999994e-9Initial program 58.9%
Taylor expanded in uy around 0
Applied rewrites51.0%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites50.3%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3299.0
Applied rewrites99.0%
if 9.99999994e-9 < maxCos Initial program 58.3%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites57.1%
Taylor expanded in ux around inf
Applied rewrites98.4%
Applied rewrites98.4%
Taylor expanded in ux around -inf
Applied rewrites98.6%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (- 1.0 ux) ux)))
(if (<= maxCos 9.99999993922529e-9)
(* (cos (* (* (PI) uy) 2.0)) (sqrt (+ t_0 ux)))
(*
(sqrt
(*
(- (/ (- (/ (* (- 2.0 ux) ux) maxCos) (* t_0 2.0)) maxCos) (* ux ux))
(* maxCos maxCos)))
(cos (* (PI) (* 2.0 uy)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) \cdot ux\\
\mathbf{if}\;maxCos \leq 9.99999993922529 \cdot 10^{-9}:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{t\_0 + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{\frac{\left(2 - ux\right) \cdot ux}{maxCos} - t\_0 \cdot 2}{maxCos} - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if maxCos < 9.99999994e-9Initial program 58.9%
Taylor expanded in uy around 0
Applied rewrites51.0%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites50.3%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3299.0
Applied rewrites99.0%
if 9.99999994e-9 < maxCos Initial program 58.3%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites57.1%
Taylor expanded in ux around 0
Applied rewrites98.5%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (- 1.0 ux) ux)))
(if (<= (* 2.0 uy) 0.0017999999690800905)
(* (sqrt (- t_0 (- (* (fma (- 1.0 ux) ux t_0) maxCos) ux))) 1.0)
(* (sqrt (* 2.0 ux)) (cos (* (PI) (* 2.0 uy)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) \cdot ux\\
\mathbf{if}\;2 \cdot uy \leq 0.0017999999690800905:\\
\;\;\;\;\sqrt{t\_0 - \left(\mathsf{fma}\left(1 - ux, ux, t\_0\right) \cdot maxCos - ux\right)} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \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.00179999997Initial program 59.4%
Taylor expanded in uy around 0
Applied rewrites58.8%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites55.9%
lift--.f32N/A
lift-fma.f32N/A
*-commutativeN/A
+-commutativeN/A
associate-+l-N/A
lower--.f32N/A
*-commutativeN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f3256.6
Applied rewrites56.6%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
Applied rewrites91.3%
if 0.00179999997 < (*.f32 uy #s(literal 2 binary32)) Initial program 57.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-*.f3214.1
Applied rewrites14.1%
Taylor expanded in maxCos around 0
Applied rewrites91.3%
Taylor expanded in ux around 0
Applied rewrites73.7%
Final simplification81.7%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* (PI) uy) 2.0)) (sqrt (+ (* (- 1.0 ux) ux) ux))))
\begin{array}{l}
\\
\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}
\end{array}
Initial program 58.8%
Taylor expanded in uy around 0
Applied rewrites50.4%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites48.3%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3292.4
Applied rewrites92.4%
Final simplification92.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- 2.0 ux) ux)) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(2 - ux\right) \cdot ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 58.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-*.f3267.5
Applied rewrites67.9%
Taylor expanded in maxCos around 0
Applied rewrites92.3%
Taylor expanded in ux around 0
Applied rewrites92.3%
Final simplification92.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 5.000000058430487e-8)
(* (sqrt (+ (* (- 1.0 ux) ux) ux)) 1.0)
(*
(sqrt
(*
(-
(/
(* (- (+ (/ (- (/ 2.0 ux) 1.0) maxCos) 2.0) (/ 2.0 ux)) (* ux ux))
maxCos)
(* ux ux))
(* maxCos maxCos)))
1.0)))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 5.000000058430487e-8f) {
tmp = sqrtf((((1.0f - ux) * ux) + ux)) * 1.0f;
} else {
tmp = sqrtf((((((((((2.0f / ux) - 1.0f) / maxCos) + 2.0f) - (2.0f / ux)) * (ux * ux)) / maxCos) - (ux * ux)) * (maxCos * maxCos))) * 1.0f;
}
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) :: tmp
if (maxcos <= 5.000000058430487e-8) then
tmp = sqrt((((1.0e0 - ux) * ux) + ux)) * 1.0e0
else
tmp = sqrt((((((((((2.0e0 / ux) - 1.0e0) / maxcos) + 2.0e0) - (2.0e0 / ux)) * (ux * ux)) / maxcos) - (ux * ux)) * (maxcos * maxcos))) * 1.0e0
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(5.000000058430487e-8)) tmp = Float32(sqrt(Float32(Float32(Float32(Float32(1.0) - ux) * ux) + ux)) * Float32(1.0)); else tmp = Float32(sqrt(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(2.0) / ux) - Float32(1.0)) / maxCos) + Float32(2.0)) - Float32(Float32(2.0) / ux)) * Float32(ux * ux)) / maxCos) - Float32(ux * ux)) * Float32(maxCos * maxCos))) * Float32(1.0)); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(5.000000058430487e-8)) tmp = sqrt((((single(1.0) - ux) * ux) + ux)) * single(1.0); else tmp = sqrt((((((((((single(2.0) / ux) - single(1.0)) / maxCos) + single(2.0)) - (single(2.0) / ux)) * (ux * ux)) / maxCos) - (ux * ux)) * (maxCos * maxCos))) * single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 5.000000058430487 \cdot 10^{-8}:\\
\;\;\;\;\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{\left(\left(\frac{\frac{2}{ux} - 1}{maxCos} + 2\right) - \frac{2}{ux}\right) \cdot \left(ux \cdot ux\right)}{maxCos} - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot 1\\
\end{array}
\end{array}
if maxCos < 5.00000006e-8Initial program 59.2%
Taylor expanded in uy around 0
Applied rewrites51.1%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites50.4%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3280.3
Applied rewrites80.3%
if 5.00000006e-8 < maxCos Initial program 57.1%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites56.0%
Taylor expanded in ux around inf
Applied rewrites98.5%
Taylor expanded in uy around 0
Applied rewrites75.8%
Final simplification79.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 5.000000058430487e-8)
(* (sqrt (+ (* (- 1.0 ux) ux) ux)) 1.0)
(*
(sqrt
(*
(*
(-
(/
(* (- (+ (/ (- (/ 2.0 ux) 1.0) maxCos) 2.0) (/ 2.0 ux)) (* ux ux))
maxCos)
(* ux ux))
maxCos)
maxCos))
1.0)))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 5.000000058430487e-8f) {
tmp = sqrtf((((1.0f - ux) * ux) + ux)) * 1.0f;
} else {
tmp = sqrtf(((((((((((2.0f / ux) - 1.0f) / maxCos) + 2.0f) - (2.0f / ux)) * (ux * ux)) / maxCos) - (ux * ux)) * maxCos) * maxCos)) * 1.0f;
}
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) :: tmp
if (maxcos <= 5.000000058430487e-8) then
tmp = sqrt((((1.0e0 - ux) * ux) + ux)) * 1.0e0
else
tmp = sqrt(((((((((((2.0e0 / ux) - 1.0e0) / maxcos) + 2.0e0) - (2.0e0 / ux)) * (ux * ux)) / maxcos) - (ux * ux)) * maxcos) * maxcos)) * 1.0e0
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(5.000000058430487e-8)) tmp = Float32(sqrt(Float32(Float32(Float32(Float32(1.0) - ux) * ux) + ux)) * Float32(1.0)); else tmp = Float32(sqrt(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(2.0) / ux) - Float32(1.0)) / maxCos) + Float32(2.0)) - Float32(Float32(2.0) / ux)) * Float32(ux * ux)) / maxCos) - Float32(ux * ux)) * maxCos) * maxCos)) * Float32(1.0)); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(5.000000058430487e-8)) tmp = sqrt((((single(1.0) - ux) * ux) + ux)) * single(1.0); else tmp = sqrt(((((((((((single(2.0) / ux) - single(1.0)) / maxCos) + single(2.0)) - (single(2.0) / ux)) * (ux * ux)) / maxCos) - (ux * ux)) * maxCos) * maxCos)) * single(1.0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 5.000000058430487 \cdot 10^{-8}:\\
\;\;\;\;\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{\left(\left(\frac{\frac{2}{ux} - 1}{maxCos} + 2\right) - \frac{2}{ux}\right) \cdot \left(ux \cdot ux\right)}{maxCos} - ux \cdot ux\right) \cdot maxCos\right) \cdot maxCos} \cdot 1\\
\end{array}
\end{array}
if maxCos < 5.00000006e-8Initial program 59.2%
Taylor expanded in uy around 0
Applied rewrites51.1%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites50.4%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3280.3
Applied rewrites80.3%
if 5.00000006e-8 < maxCos Initial program 57.1%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites56.0%
Taylor expanded in ux around inf
Applied rewrites98.5%
Applied rewrites98.5%
Taylor expanded in uy around 0
Applied rewrites75.8%
Final simplification79.4%
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (* (- 1.0 ux) ux))) (* (sqrt (- t_0 (- (* (fma (- 1.0 ux) ux t_0) maxCos) ux))) 1.0)))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) * ux;
return sqrtf((t_0 - ((fmaf((1.0f - ux), ux, t_0) * maxCos) - ux))) * 1.0f;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) * ux) return Float32(sqrt(Float32(t_0 - Float32(Float32(fma(Float32(Float32(1.0) - ux), ux, t_0) * maxCos) - ux))) * Float32(1.0)) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) \cdot ux\\
\sqrt{t\_0 - \left(\mathsf{fma}\left(1 - ux, ux, t\_0\right) \cdot maxCos - ux\right)} \cdot 1
\end{array}
\end{array}
Initial program 58.8%
Taylor expanded in uy around 0
Applied rewrites50.4%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites48.7%
lift--.f32N/A
lift-fma.f32N/A
*-commutativeN/A
+-commutativeN/A
associate-+l-N/A
lower--.f32N/A
*-commutativeN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f3248.8
Applied rewrites48.5%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
Applied rewrites75.0%
Final simplification75.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (+ (* (- 1.0 ux) ux) ux)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((((1.0f - ux) * 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((((1.0e0 - ux) * ux) + ux)) * 1.0e0
end function
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(Float32(Float32(1.0) - ux) * ux) + ux)) * Float32(1.0)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(1.0) - ux) * ux) + ux)) * single(1.0); end
\begin{array}{l}
\\
\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot 1
\end{array}
Initial program 58.8%
Taylor expanded in uy around 0
Applied rewrites50.4%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites48.3%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3275.0
Applied rewrites75.0%
Final simplification75.0%
(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 58.8%
Taylor expanded in uy around 0
Applied rewrites50.4%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3261.3
Applied rewrites61.0%
Final simplification61.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma (- 1.0 ux) ux ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf((1.0f - ux), ux, ux));
}
function code(ux, uy, maxCos) return sqrt(fma(Float32(Float32(1.0) - ux), ux, ux)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(1 - ux, ux, ux\right)}
\end{array}
Initial program 58.8%
Taylor expanded in uy around 0
Applied rewrites50.4%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites48.3%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3292.4
Applied rewrites92.4%
Taylor expanded in uy around 0
Applied rewrites30.3%
(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 58.8%
Taylor expanded in uy around 0
Applied rewrites50.4%
Taylor expanded in ux around 0
Applied rewrites6.6%
Final simplification6.6%
herbie shell --seed 2024270
(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)))))))