
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (sqrt (* (* u2 u2) 39.47841760436263)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf(sqrtf(((u2 * u2) * 39.47841760436263f)));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * cos(sqrt(((u2 * u2) * 39.47841760436263e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(sqrt(Float32(Float32(u2 * u2) * Float32(39.47841760436263))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos(sqrt(((u2 * u2) * single(39.47841760436263)))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right)
\end{array}
Initial program 99.2%
add-sqr-sqrt99.1%
pow1/299.1%
pow1/299.1%
pow-prod-down99.2%
swap-sqr99.2%
metadata-eval99.2%
Applied egg-rr99.2%
unpow1/299.2%
unpow299.2%
*-commutative99.2%
unpow299.2%
Simplified99.2%
Final simplification99.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* u2 6.28318530718))))
(if (<= t_0 0.9800999760627747)
(/ t_0 (/ 1.0 (sqrt u1)))
(* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((u2 * 6.28318530718f));
float tmp;
if (t_0 <= 0.9800999760627747f) {
tmp = t_0 / (1.0f / sqrtf(u1));
} else {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
}
return tmp;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
real(4) :: t_0
real(4) :: tmp
t_0 = cos((u2 * 6.28318530718e0))
if (t_0 <= 0.9800999760627747e0) then
tmp = t_0 / (1.0e0 / sqrt(u1))
else
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = cos(Float32(u2 * Float32(6.28318530718))) tmp = Float32(0.0) if (t_0 <= Float32(0.9800999760627747)) tmp = Float32(t_0 / Float32(Float32(1.0) / sqrt(u1))); else tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = cos((u2 * single(6.28318530718))); tmp = single(0.0); if (t_0 <= single(0.9800999760627747)) tmp = t_0 / (single(1.0) / sqrt(u1)); else tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\
\mathbf{if}\;t_0 \leq 0.9800999760627747:\\
\;\;\;\;\frac{t_0}{\frac{1}{\sqrt{u1}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\end{array}
\end{array}
if (cos.f32 (*.f32 314159265359/50000000000 u2)) < 0.980099976Initial program 97.3%
*-commutative97.3%
sqrt-div97.3%
associate-*r/97.5%
Applied egg-rr97.5%
associate-/l*97.8%
Simplified97.8%
Taylor expanded in u1 around 0 75.2%
if 0.980099976 < (cos.f32 (*.f32 314159265359/50000000000 u2)) Initial program 99.5%
Taylor expanded in u2 around 0 98.0%
+-commutative98.0%
*-lft-identity98.0%
associate-*r*98.0%
distribute-rgt-out98.0%
unpow298.0%
Simplified98.0%
Final simplification94.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* u2 6.28318530718))))
(if (<= t_0 0.9800999760627747)
(/ t_0 (pow u1 -0.5))
(* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((u2 * 6.28318530718f));
float tmp;
if (t_0 <= 0.9800999760627747f) {
tmp = t_0 / powf(u1, -0.5f);
} else {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
}
return tmp;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
real(4) :: t_0
real(4) :: tmp
t_0 = cos((u2 * 6.28318530718e0))
if (t_0 <= 0.9800999760627747e0) then
tmp = t_0 / (u1 ** (-0.5e0))
else
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = cos(Float32(u2 * Float32(6.28318530718))) tmp = Float32(0.0) if (t_0 <= Float32(0.9800999760627747)) tmp = Float32(t_0 / (u1 ^ Float32(-0.5))); else tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = cos((u2 * single(6.28318530718))); tmp = single(0.0); if (t_0 <= single(0.9800999760627747)) tmp = t_0 / (u1 ^ single(-0.5)); else tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\
\mathbf{if}\;t_0 \leq 0.9800999760627747:\\
\;\;\;\;\frac{t_0}{{u1}^{-0.5}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\end{array}
\end{array}
if (cos.f32 (*.f32 314159265359/50000000000 u2)) < 0.980099976Initial program 97.3%
*-commutative97.3%
sqrt-div97.3%
associate-*r/97.5%
Applied egg-rr97.5%
associate-/l*97.8%
Simplified97.8%
clear-num97.4%
sqrt-div97.6%
pow1/297.6%
pow-flip97.6%
metadata-eval97.6%
Applied egg-rr97.6%
Taylor expanded in u1 around 0 75.1%
if 0.980099976 < (cos.f32 (*.f32 314159265359/50000000000 u2)) Initial program 99.5%
Taylor expanded in u2 around 0 98.0%
+-commutative98.0%
*-lft-identity98.0%
associate-*r*98.0%
distribute-rgt-out98.0%
unpow298.0%
Simplified98.0%
Final simplification94.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* u2 6.28318530718))))
(if (<= t_0 0.9800999760627747)
(* t_0 (sqrt u1))
(* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((u2 * 6.28318530718f));
float tmp;
if (t_0 <= 0.9800999760627747f) {
tmp = t_0 * sqrtf(u1);
} else {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
}
return tmp;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
real(4) :: t_0
real(4) :: tmp
t_0 = cos((u2 * 6.28318530718e0))
if (t_0 <= 0.9800999760627747e0) then
tmp = t_0 * sqrt(u1)
else
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = cos(Float32(u2 * Float32(6.28318530718))) tmp = Float32(0.0) if (t_0 <= Float32(0.9800999760627747)) tmp = Float32(t_0 * sqrt(u1)); else tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = cos((u2 * single(6.28318530718))); tmp = single(0.0); if (t_0 <= single(0.9800999760627747)) tmp = t_0 * sqrt(u1); else tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\
\mathbf{if}\;t_0 \leq 0.9800999760627747:\\
\;\;\;\;t_0 \cdot \sqrt{u1}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\end{array}
\end{array}
if (cos.f32 (*.f32 314159265359/50000000000 u2)) < 0.980099976Initial program 97.3%
Taylor expanded in u1 around 0 75.1%
if 0.980099976 < (cos.f32 (*.f32 314159265359/50000000000 u2)) Initial program 99.5%
Taylor expanded in u2 around 0 98.0%
+-commutative98.0%
*-lft-identity98.0%
associate-*r*98.0%
distribute-rgt-out98.0%
unpow298.0%
Simplified98.0%
Final simplification94.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((u2 * 6.28318530718f));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * cos((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(u2 * Float32(6.28318530718)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((u2 * single(6.28318530718))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot 6.28318530718\right)
\end{array}
Initial program 99.2%
Final simplification99.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0 89.8%
+-commutative89.8%
*-lft-identity89.8%
associate-*r*89.8%
distribute-rgt-out89.8%
unpow289.8%
Simplified89.8%
Final simplification89.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (/ u1 (- 1.0 u1))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1)));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1)))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}}
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0 81.6%
Final simplification81.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt u1))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(u1);
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt(u1)
end function
function code(cosTheta_i, u1, u2) return sqrt(u1) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(u1); end
\begin{array}{l}
\\
\sqrt{u1}
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0 81.6%
Taylor expanded in u1 around 0 64.3%
Final simplification64.3%
herbie shell --seed 2023229
(FPCore (cosTheta_i u1 u2)
:name "Trowbridge-Reitz Sample, near normal, slope_x"
: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))) (cos (* 6.28318530718 u2))))