
(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 10 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 (let* ((t_0 (+ (* 6.28318530718 u2) 2.0))) (* (sqrt (/ u1 (- 1.0 u1))) (cos (/ (* (* 6.28318530718 u2) t_0) t_0)))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = (6.28318530718f * u2) + 2.0f;
return sqrtf((u1 / (1.0f - u1))) * cosf((((6.28318530718f * u2) * t_0) / t_0));
}
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
t_0 = (6.28318530718e0 * u2) + 2.0e0
code = sqrt((u1 / (1.0e0 - u1))) * cos((((6.28318530718e0 * u2) * t_0) / t_0))
end function
function code(cosTheta_i, u1, u2) t_0 = Float32(Float32(Float32(6.28318530718) * u2) + Float32(2.0)) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(Float32(Float32(6.28318530718) * u2) * t_0) / t_0))) end
function tmp = code(cosTheta_i, u1, u2) t_0 = (single(6.28318530718) * u2) + single(2.0); tmp = sqrt((u1 / (single(1.0) - u1))) * cos((((single(6.28318530718) * u2) * t_0) / t_0)); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 6.28318530718 \cdot u2 + 2\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\frac{\left(6.28318530718 \cdot u2\right) \cdot t\_0}{t\_0}\right)
\end{array}
\end{array}
Initial program 98.8%
expm1-log1p-u98.8%
expm1-undefine98.8%
Applied egg-rr98.8%
expm1-define98.8%
Simplified98.8%
expm1-undefine98.8%
flip--98.8%
metadata-eval98.8%
fmm-def98.8%
log1p-undefine98.8%
rem-exp-log98.8%
+-commutative98.8%
fma-define98.8%
log1p-undefine98.8%
rem-exp-log98.7%
+-commutative98.7%
fma-define98.8%
metadata-eval98.8%
log1p-undefine98.7%
rem-exp-log98.8%
+-commutative98.8%
fma-define98.8%
Applied egg-rr98.8%
fma-undefine98.8%
difference-of-sqr--198.8%
fma-undefine98.8%
associate-+l+98.8%
metadata-eval98.8%
fma-undefine98.8%
associate--l+98.8%
metadata-eval98.8%
+-rgt-identity98.8%
fma-undefine98.8%
associate-+l+98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(*
(sqrt (/ u1 (- 1.0 u1)))
(cos
(/
(* u2 (+ 12.56637061436 (* u2 39.47841760436263)))
(+ (* 6.28318530718 u2) 2.0)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf(((u2 * (12.56637061436f + (u2 * 39.47841760436263f))) / ((6.28318530718f * u2) + 2.0f)));
}
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 * (12.56637061436e0 + (u2 * 39.47841760436263e0))) / ((6.28318530718e0 * u2) + 2.0e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(u2 * Float32(Float32(12.56637061436) + Float32(u2 * Float32(39.47841760436263)))) / Float32(Float32(Float32(6.28318530718) * u2) + Float32(2.0))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos(((u2 * (single(12.56637061436) + (u2 * single(39.47841760436263)))) / ((single(6.28318530718) * u2) + single(2.0)))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\frac{u2 \cdot \left(12.56637061436 + u2 \cdot 39.47841760436263\right)}{6.28318530718 \cdot u2 + 2}\right)
\end{array}
Initial program 98.8%
expm1-log1p-u98.8%
expm1-undefine98.8%
Applied egg-rr98.8%
expm1-define98.8%
Simplified98.8%
expm1-undefine98.8%
flip--98.8%
metadata-eval98.8%
fmm-def98.8%
log1p-undefine98.8%
rem-exp-log98.8%
+-commutative98.8%
fma-define98.8%
log1p-undefine98.8%
rem-exp-log98.7%
+-commutative98.7%
fma-define98.8%
metadata-eval98.8%
log1p-undefine98.7%
rem-exp-log98.8%
+-commutative98.8%
fma-define98.8%
Applied egg-rr98.8%
fma-undefine98.8%
difference-of-sqr--198.8%
fma-undefine98.8%
associate-+l+98.8%
metadata-eval98.8%
fma-undefine98.8%
associate--l+98.8%
metadata-eval98.8%
+-rgt-identity98.8%
fma-undefine98.8%
associate-+l+98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in u2 around 0 98.8%
*-commutative98.8%
Simplified98.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.0006200000061653554) (sqrt (/ u1 (- 1.0 u1))) (* (cos (* 6.28318530718 u2)) (sqrt (* u1 (+ u1 1.0))))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.0006200000061653554f) {
tmp = sqrtf((u1 / (1.0f - u1)));
} else {
tmp = cosf((6.28318530718f * u2)) * sqrtf((u1 * (u1 + 1.0f)));
}
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) :: tmp
if ((6.28318530718e0 * u2) <= 0.0006200000061653554e0) then
tmp = sqrt((u1 / (1.0e0 - u1)))
else
tmp = cos((6.28318530718e0 * u2)) * sqrt((u1 * (u1 + 1.0e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.0006200000061653554)) tmp = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))); else tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) * sqrt(Float32(u1 * Float32(u1 + Float32(1.0))))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.0006200000061653554)) tmp = sqrt((u1 / (single(1.0) - u1))); else tmp = cos((single(6.28318530718) * u2)) * sqrt((u1 * (u1 + single(1.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.0006200000061653554:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1 \cdot \left(u1 + 1\right)}\\
\end{array}
\end{array}
if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 6.20000006e-4Initial program 99.5%
Taylor expanded in u2 around 0 99.4%
if 6.20000006e-4 < (*.f32 #s(literal 314159265359/50000000000 binary32) u2) Initial program 98.0%
Taylor expanded in u1 around 0 83.7%
+-commutative83.7%
Simplified83.7%
Final simplification92.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.014999999664723873) (sqrt (/ u1 (- 1.0 u1))) (* (cos (* 6.28318530718 u2)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.014999999664723873f) {
tmp = sqrtf((u1 / (1.0f - u1)));
} else {
tmp = cosf((6.28318530718f * u2)) * sqrtf(u1);
}
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) :: tmp
if ((6.28318530718e0 * u2) <= 0.014999999664723873e0) then
tmp = sqrt((u1 / (1.0e0 - u1)))
else
tmp = cos((6.28318530718e0 * u2)) * sqrt(u1)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.014999999664723873)) tmp = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))); else tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) * sqrt(u1)); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.014999999664723873)) tmp = sqrt((u1 / (single(1.0) - u1))); else tmp = cos((single(6.28318530718) * u2)) * sqrt(u1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.014999999664723873:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 0.0149999997Initial program 99.4%
Taylor expanded in u2 around 0 96.2%
if 0.0149999997 < (*.f32 #s(literal 314159265359/50000000000 binary32) u2) Initial program 97.6%
Taylor expanded in u1 around 0 69.8%
Final simplification88.2%
(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}
Initial program 98.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 98.8%
Taylor expanded in u2 around 0 78.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* u1 (+ u1 1.0))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 * (u1 + 1.0f)));
}
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 * (u1 + 1.0e0)))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(u1 * Float32(u1 + Float32(1.0)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 * (u1 + single(1.0)))); end
\begin{array}{l}
\\
\sqrt{u1 \cdot \left(u1 + 1\right)}
\end{array}
Initial program 98.8%
Taylor expanded in u2 around 0 78.8%
Taylor expanded in u1 around 0 72.6%
+-commutative87.0%
Simplified72.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 98.8%
Taylor expanded in u2 around 0 78.8%
Taylor expanded in u1 around 0 64.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* u1 (+ 1.0 (/ 0.5 u1))))
float code(float cosTheta_i, float u1, float u2) {
return u1 * (1.0f + (0.5f / 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 = u1 * (1.0e0 + (0.5e0 / u1))
end function
function code(cosTheta_i, u1, u2) return Float32(u1 * Float32(Float32(1.0) + Float32(Float32(0.5) / u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = u1 * (single(1.0) + (single(0.5) / u1)); end
\begin{array}{l}
\\
u1 \cdot \left(1 + \frac{0.5}{u1}\right)
\end{array}
Initial program 98.8%
Taylor expanded in u2 around 0 78.8%
Taylor expanded in u1 around 0 72.6%
+-commutative87.0%
Simplified72.6%
Taylor expanded in u1 around inf 19.7%
associate-*r/19.7%
metadata-eval19.7%
Simplified19.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (+ u1 0.5))
float code(float cosTheta_i, float u1, float u2) {
return u1 + 0.5f;
}
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 = u1 + 0.5e0
end function
function code(cosTheta_i, u1, u2) return Float32(u1 + Float32(0.5)) end
function tmp = code(cosTheta_i, u1, u2) tmp = u1 + single(0.5); end
\begin{array}{l}
\\
u1 + 0.5
\end{array}
Initial program 98.8%
Taylor expanded in u2 around 0 78.8%
Taylor expanded in u1 around 0 72.6%
+-commutative87.0%
Simplified72.6%
Taylor expanded in u1 around inf 19.7%
distribute-rgt-in19.7%
*-lft-identity19.7%
associate-*l*19.7%
lft-mult-inverse19.7%
metadata-eval19.7%
Simplified19.7%
herbie shell --seed 2024151
(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))))