
(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 13 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 (* (sqrt (* (- (- 2.0 (* ux (pow (- maxCos 1.0) 2.0))) (* maxCos 2.0)) ux)) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos \cdot 2\right) \cdot ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 55.3%
Taylor expanded in maxCos around inf
*-commutativeN/A
lower-*.f32N/A
associate--l+N/A
div-subN/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f32N/A
lower--.f3255.3
Applied rewrites55.3%
Applied rewrites31.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.6
Applied rewrites98.6%
Final simplification98.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* ux maxCos) (- 1.0 ux))) (t_1 (cos (* (PI) (* 2.0 uy)))))
(if (<= (* (sqrt (- 1.0 (* t_0 t_0))) t_1) 0.0215000007301569)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_1)
(* (sqrt (- 1.0 (* (- 1.0 (- ux (* ux maxCos))) t_0))) 1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos + \left(1 - ux\right)\\
t_1 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot t\_1 \leq 0.0215000007301569:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot t\_0} \cdot 1\\
\end{array}
\end{array}
if (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.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)))))) < 0.0215000007Initial program 37.9%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3238.0
lift-*.f32N/A
*-commutativeN/A
lower-*.f3238.0
Applied rewrites38.0%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3263.2
Applied rewrites63.1%
if 0.0215000007 < (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.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 90.9%
Taylor expanded in uy around 0
Applied rewrites76.8%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3276.8
Applied rewrites76.8%
Final simplification67.7%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* ux maxCos) (- 1.0 ux))))
(if (<=
(* (sqrt (- 1.0 (* t_0 t_0))) (cos (* (PI) (* 2.0 uy))))
0.017480000853538513)
(* (sqrt 0.3333333333333333) (sqrt (* (- 6.0 (* 6.0 maxCos)) ux)))
(* 1.0 (sqrt (- 1.0 (* (- 1.0 ux) t_0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos + \left(1 - ux\right)\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.017480000853538513:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot \sqrt{\left(6 - 6 \cdot maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \sqrt{1 - \left(1 - ux\right) \cdot t\_0}\\
\end{array}
\end{array}
if (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.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)))))) < 0.0174800009Initial program 36.8%
Taylor expanded in uy around 0
Applied rewrites29.6%
Applied rewrites29.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
distribute-rgt-outN/A
metadata-evalN/A
lower-*.f3291.5
Applied rewrites91.5%
Taylor expanded in uy around 0
Applied rewrites74.2%
if 0.0174800009 < (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.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.9%
Taylor expanded in uy around 0
Applied rewrites76.4%
Taylor expanded in maxCos around 0
lower--.f3271.5
Applied rewrites71.5%
Final simplification73.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* ux maxCos) (- 1.0 ux))))
(if (<=
(* (sqrt (- 1.0 (* t_0 t_0))) (cos (* (PI) (* 2.0 uy))))
0.017480000853538513)
(* (sqrt (* (* (- 6.0 (* 6.0 maxCos)) ux) 0.3333333333333333)) 1.0)
(* 1.0 (sqrt (- 1.0 (* (- 1.0 ux) t_0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos + \left(1 - ux\right)\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.017480000853538513:\\
\;\;\;\;\sqrt{\left(\left(6 - 6 \cdot maxCos\right) \cdot ux\right) \cdot 0.3333333333333333} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \sqrt{1 - \left(1 - ux\right) \cdot t\_0}\\
\end{array}
\end{array}
if (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.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)))))) < 0.0174800009Initial program 36.8%
Taylor expanded in uy around 0
Applied rewrites29.6%
Applied rewrites29.3%
Taylor expanded in ux around 0
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
distribute-rgt-outN/A
metadata-evalN/A
lower-*.f3274.2
Applied rewrites74.2%
if 0.0174800009 < (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.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.9%
Taylor expanded in uy around 0
Applied rewrites76.4%
Taylor expanded in maxCos around 0
lower--.f3271.5
Applied rewrites71.5%
Final simplification73.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (+ (* ux maxCos) (- 1.0 ux))))
(if (<= t_1 0.9998499751091003)
(* (sqrt (- 1.0 (* (- 1.0 ux) t_1))) t_0)
(* (sqrt (* (fma -2.0 maxCos 2.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)\\
t_1 := ux \cdot maxCos + \left(1 - ux\right)\\
\mathbf{if}\;t\_1 \leq 0.9998499751091003:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot t\_1} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_0\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999849975Initial program 89.7%
Taylor expanded in maxCos around 0
lower--.f3283.0
Applied rewrites83.0%
if 0.999849975 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 34.3%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3234.5
lift-*.f32N/A
*-commutativeN/A
lower-*.f3234.5
Applied rewrites34.5%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3266.5
Applied rewrites66.3%
Final simplification73.1%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 2.9000000722589903e-5)
(* (sqrt (* (* ux ux) (- (/ 2.0 ux) 1.0))) (cos (* (PI) (* 2.0 uy))))
(*
(sqrt (* (- 6.0 (* 6.0 maxCos)) ux))
(* (cos (* (* (PI) uy) 2.0)) (sqrt 0.3333333333333333)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 2.9000000722589903 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{2}{ux} - 1\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(6 - 6 \cdot maxCos\right) \cdot ux} \cdot \left(\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{0.3333333333333333}\right)\\
\end{array}
\end{array}
if maxCos < 2.90000007e-5Initial program 55.3%
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-*.f3270.4
Applied rewrites70.4%
Taylor expanded in maxCos around 0
Applied rewrites97.6%
if 2.90000007e-5 < maxCos Initial program 55.2%
Taylor expanded in uy around 0
Applied rewrites46.2%
Applied rewrites32.9%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
distribute-rgt-outN/A
metadata-evalN/A
lower-*.f3276.2
Applied rewrites76.2%
Final simplification94.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* ux ux) (- (/ 2.0 ux) 1.0))) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{2}{ux} - 1\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 55.3%
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-*.f3265.7
Applied rewrites65.7%
Taylor expanded in maxCos around 0
Applied rewrites90.2%
Final simplification90.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* ux maxCos) (- 1.0 ux))))
(if (<= t_0 0.9998499751091003)
(* (sqrt (- 1.0 (* (- 1.0 (- ux (* ux maxCos))) t_0))) 1.0)
(* (sqrt 0.3333333333333333) (sqrt (* (- 6.0 (* 6.0 maxCos)) ux))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (ux * maxCos) + (1.0f - ux);
float tmp;
if (t_0 <= 0.9998499751091003f) {
tmp = sqrtf((1.0f - ((1.0f - (ux - (ux * maxCos))) * t_0))) * 1.0f;
} else {
tmp = sqrtf(0.3333333333333333f) * sqrtf(((6.0f - (6.0f * maxCos)) * 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 = (ux * maxcos) + (1.0e0 - ux)
if (t_0 <= 0.9998499751091003e0) then
tmp = sqrt((1.0e0 - ((1.0e0 - (ux - (ux * maxcos))) * t_0))) * 1.0e0
else
tmp = sqrt(0.3333333333333333e0) * sqrt(((6.0e0 - (6.0e0 * maxcos)) * ux))
end if
code = tmp
end function
function code(ux, uy, maxCos) t_0 = Float32(Float32(ux * maxCos) + Float32(Float32(1.0) - ux)) tmp = Float32(0.0) if (t_0 <= Float32(0.9998499751091003)) tmp = Float32(sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - Float32(ux - Float32(ux * maxCos))) * t_0))) * Float32(1.0)); else tmp = Float32(sqrt(Float32(0.3333333333333333)) * sqrt(Float32(Float32(Float32(6.0) - Float32(Float32(6.0) * maxCos)) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = (ux * maxCos) + (single(1.0) - ux); tmp = single(0.0); if (t_0 <= single(0.9998499751091003)) tmp = sqrt((single(1.0) - ((single(1.0) - (ux - (ux * maxCos))) * t_0))) * single(1.0); else tmp = sqrt(single(0.3333333333333333)) * sqrt(((single(6.0) - (single(6.0) * maxCos)) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos + \left(1 - ux\right)\\
\mathbf{if}\;t\_0 \leq 0.9998499751091003:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot t\_0} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot \sqrt{\left(6 - 6 \cdot maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999849975Initial program 89.7%
Taylor expanded in uy around 0
Applied rewrites71.0%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3271.1
Applied rewrites71.1%
if 0.999849975 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 34.3%
Taylor expanded in uy around 0
Applied rewrites30.5%
Applied rewrites30.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
distribute-rgt-outN/A
metadata-evalN/A
lower-*.f3293.5
Applied rewrites93.5%
Taylor expanded in uy around 0
Applied rewrites77.4%
Final simplification75.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* ux maxCos) (- 1.0 ux))))
(if (<= t_0 0.9998499751091003)
(* 1.0 (sqrt (- 1.0 (* t_0 t_0))))
(* (sqrt 0.3333333333333333) (sqrt (* (- 6.0 (* 6.0 maxCos)) ux))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (ux * maxCos) + (1.0f - ux);
float tmp;
if (t_0 <= 0.9998499751091003f) {
tmp = 1.0f * sqrtf((1.0f - (t_0 * t_0)));
} else {
tmp = sqrtf(0.3333333333333333f) * sqrtf(((6.0f - (6.0f * maxCos)) * 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 = (ux * maxcos) + (1.0e0 - ux)
if (t_0 <= 0.9998499751091003e0) then
tmp = 1.0e0 * sqrt((1.0e0 - (t_0 * t_0)))
else
tmp = sqrt(0.3333333333333333e0) * sqrt(((6.0e0 - (6.0e0 * maxcos)) * ux))
end if
code = tmp
end function
function code(ux, uy, maxCos) t_0 = Float32(Float32(ux * maxCos) + Float32(Float32(1.0) - ux)) tmp = Float32(0.0) if (t_0 <= Float32(0.9998499751091003)) tmp = Float32(Float32(1.0) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))); else tmp = Float32(sqrt(Float32(0.3333333333333333)) * sqrt(Float32(Float32(Float32(6.0) - Float32(Float32(6.0) * maxCos)) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = (ux * maxCos) + (single(1.0) - ux); tmp = single(0.0); if (t_0 <= single(0.9998499751091003)) tmp = single(1.0) * sqrt((single(1.0) - (t_0 * t_0))); else tmp = sqrt(single(0.3333333333333333)) * sqrt(((single(6.0) - (single(6.0) * maxCos)) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos + \left(1 - ux\right)\\
\mathbf{if}\;t\_0 \leq 0.9998499751091003:\\
\;\;\;\;1 \cdot \sqrt{1 - t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot \sqrt{\left(6 - 6 \cdot maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999849975Initial program 89.7%
Taylor expanded in uy around 0
Applied rewrites71.0%
if 0.999849975 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 34.3%
Taylor expanded in uy around 0
Applied rewrites30.5%
Applied rewrites30.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
distribute-rgt-outN/A
metadata-evalN/A
lower-*.f3293.5
Applied rewrites93.5%
Taylor expanded in uy around 0
Applied rewrites77.4%
Final simplification75.0%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* (- 6.0 (* 6.0 maxCos)) ux) 0.3333333333333333)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((((6.0f - (6.0f * maxCos)) * ux) * 0.3333333333333333f)) * 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((((6.0e0 - (6.0e0 * maxcos)) * ux) * 0.3333333333333333e0)) * 1.0e0
end function
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(Float32(Float32(6.0) - Float32(Float32(6.0) * maxCos)) * ux) * Float32(0.3333333333333333))) * Float32(1.0)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(6.0) - (single(6.0) * maxCos)) * ux) * single(0.3333333333333333))) * single(1.0); end
\begin{array}{l}
\\
\sqrt{\left(\left(6 - 6 \cdot maxCos\right) \cdot ux\right) \cdot 0.3333333333333333} \cdot 1
\end{array}
Initial program 55.3%
Taylor expanded in uy around 0
Applied rewrites45.9%
Applied rewrites43.7%
Taylor expanded in ux around 0
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
distribute-rgt-outN/A
metadata-evalN/A
lower-*.f3265.6
Applied rewrites65.6%
Final simplification65.6%
(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 55.3%
Taylor expanded in uy around 0
Applied rewrites45.9%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3262.0
Applied rewrites61.8%
Final simplification60.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 55.3%
Taylor expanded in uy around 0
Applied rewrites45.9%
Taylor expanded in ux around 0
Applied rewrites6.6%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
neg-mul-1N/A
lower-fma.f3219.3
Applied rewrites19.8%
Final simplification19.4%
(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 55.3%
Taylor expanded in uy around 0
Applied rewrites45.9%
Taylor expanded in ux around 0
Applied rewrites6.6%
Final simplification6.6%
herbie shell --seed 2024271
(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)))))))