
(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 (* (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.1%
add-sqr-sqrt98.9%
pow1/298.9%
pow1/298.9%
pow-prod-down99.1%
swap-sqr98.9%
metadata-eval99.1%
Applied egg-rr99.1%
unpow1/299.1%
unpow299.1%
*-commutative99.1%
unpow299.1%
Simplified99.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* u2 6.28318530718))))
(if (<= t_0 0.9700000286102295)
(* 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.9700000286102295f) {
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.9700000286102295e0) 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.9700000286102295)) 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.9700000286102295)) 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.9700000286102295:\\
\;\;\;\;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.970000029Initial program 97.2%
Taylor expanded in u1 around 0 72.9%
if 0.970000029 < (cos.f32 (*.f32 314159265359/50000000000 u2)) Initial program 99.3%
Taylor expanded in u2 around 0 96.8%
+-commutative96.8%
*-lft-identity96.8%
associate-*r*96.8%
distribute-rgt-out96.8%
unpow296.8%
Simplified96.8%
Final simplification93.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (cos (* u2 6.28318530718)) 0.9999669790267944) (* (sqrt u1) (+ 1.0 (* u2 (* u2 -19.739208802181317)))) (pow (+ (/ 1.0 u1) -1.0) -0.5)))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if (cosf((u2 * 6.28318530718f)) <= 0.9999669790267944f) {
tmp = sqrtf(u1) * (1.0f + (u2 * (u2 * -19.739208802181317f)));
} else {
tmp = powf(((1.0f / u1) + -1.0f), -0.5f);
}
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 (cos((u2 * 6.28318530718e0)) <= 0.9999669790267944e0) then
tmp = sqrt(u1) * (1.0e0 + (u2 * (u2 * (-19.739208802181317e0))))
else
tmp = ((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (cos(Float32(u2 * Float32(6.28318530718))) <= Float32(0.9999669790267944)) tmp = Float32(sqrt(u1) * Float32(Float32(1.0) + Float32(u2 * Float32(u2 * Float32(-19.739208802181317))))); else tmp = Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if (cos((u2 * single(6.28318530718))) <= single(0.9999669790267944)) tmp = sqrt(u1) * (single(1.0) + (u2 * (u2 * single(-19.739208802181317)))); else tmp = ((single(1.0) / u1) + single(-1.0)) ^ single(-0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(u2 \cdot 6.28318530718\right) \leq 0.9999669790267944:\\
\;\;\;\;\sqrt{u1} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{1}{u1} + -1\right)}^{-0.5}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 314159265359/50000000000 u2)) < 0.999966979Initial program 98.3%
Taylor expanded in u1 around 0 70.5%
Taylor expanded in u2 around 0 54.2%
unpow254.2%
associate-*r*54.2%
*-commutative54.2%
distribute-rgt1-in54.2%
associate-*l*54.2%
*-commutative54.2%
fma-def54.2%
*-commutative54.2%
Simplified54.2%
fma-udef54.2%
Applied egg-rr54.2%
if 0.999966979 < (cos.f32 (*.f32 314159265359/50000000000 u2)) Initial program 99.4%
Taylor expanded in u2 around 0 97.4%
pow1/297.4%
clear-num97.3%
inv-pow97.3%
pow-pow97.5%
div-sub97.5%
inv-pow97.5%
pow197.5%
pow197.5%
pow-div97.5%
metadata-eval97.5%
metadata-eval97.5%
metadata-eval97.5%
Applied egg-rr97.5%
unpow-197.5%
sub-neg97.5%
metadata-eval97.5%
Simplified97.5%
Final simplification82.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.11999999731779099) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))) (* (cos (* u2 6.28318530718)) (sqrt (* u1 (+ u1 1.0))))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.11999999731779099f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
} else {
tmp = cosf((u2 * 6.28318530718f)) * 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 ((u2 * 6.28318530718e0) <= 0.11999999731779099e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
else
tmp = cos((u2 * 6.28318530718e0)) * sqrt((u1 * (u1 + 1.0e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(u2 * Float32(6.28318530718)) <= Float32(0.11999999731779099)) tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))); else tmp = Float32(cos(Float32(u2 * Float32(6.28318530718))) * 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 ((u2 * single(6.28318530718)) <= single(0.11999999731779099)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); else tmp = cos((u2 * single(6.28318530718))) * sqrt((u1 * (u1 + single(1.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.11999999731779099:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1 \cdot \left(u1 + 1\right)}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.119999997Initial program 99.3%
Taylor expanded in u2 around 0 98.6%
+-commutative98.6%
*-lft-identity98.6%
associate-*r*98.6%
distribute-rgt-out98.5%
unpow298.5%
Simplified98.5%
if 0.119999997 < (*.f32 314159265359/50000000000 u2) Initial program 97.8%
clear-num97.6%
associate-/r/97.3%
Applied egg-rr97.3%
Taylor expanded in u1 around 0 84.4%
+-commutative84.4%
Simplified84.4%
Final simplification95.9%
(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.1%
Final simplification99.1%
(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.1%
Taylor expanded in u2 around 0 88.7%
+-commutative88.7%
*-lft-identity88.7%
associate-*r*88.7%
distribute-rgt-out88.6%
unpow288.6%
Simplified88.6%
Final simplification88.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (pow (+ (/ 1.0 u1) -1.0) -0.5))
float code(float cosTheta_i, float u1, float u2) {
return powf(((1.0f / u1) + -1.0f), -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 = ((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5) end
function tmp = code(cosTheta_i, u1, u2) tmp = ((single(1.0) / u1) + single(-1.0)) ^ single(-0.5); end
\begin{array}{l}
\\
{\left(\frac{1}{u1} + -1\right)}^{-0.5}
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 79.0%
pow1/279.0%
clear-num79.0%
inv-pow79.0%
pow-pow79.1%
div-sub79.0%
inv-pow79.0%
pow179.0%
pow179.0%
pow-div79.0%
metadata-eval79.0%
metadata-eval79.0%
metadata-eval79.0%
Applied egg-rr79.0%
unpow-179.0%
sub-neg79.0%
metadata-eval79.0%
Simplified79.0%
Final simplification79.0%
(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.1%
Taylor expanded in u2 around 0 79.0%
Final simplification79.0%
(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.1%
Taylor expanded in u2 around 0 79.0%
Taylor expanded in u1 around 0 61.5%
Final simplification61.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 u1)
float code(float cosTheta_i, float u1, float u2) {
return 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
end function
function code(cosTheta_i, u1, u2) return u1 end
function tmp = code(cosTheta_i, u1, u2) tmp = u1; end
\begin{array}{l}
\\
u1
\end{array}
Initial program 99.1%
Taylor expanded in u1 around 0 84.9%
unpow284.9%
fma-udef84.9%
Simplified84.9%
Taylor expanded in u1 around inf 20.2%
*-commutative20.2%
Simplified20.2%
Taylor expanded in u2 around 0 19.3%
Final simplification19.3%
herbie shell --seed 2023228
(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))))