
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(sqrt
(-
(* eta eta)
(/
(* sinTheta_O sinTheta_O)
(sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / sqrtf(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrtf((1.0f - (sinTheta_O * sinTheta_O))))))));
}
real(4) function code(sintheta_o, h, eta)
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / sqrt(((eta * eta) - ((sintheta_o * sintheta_o) / sqrt((1.0e0 - (sintheta_o * sintheta_o))))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(Float32(sinTheta_O * sinTheta_O) / sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / sqrt(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrt((single(1.0) - (sinTheta_O * sinTheta_O)))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta_O \cdot sinTheta_O}{\sqrt{1 - sinTheta_O \cdot sinTheta_O}}}}\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(sqrt
(-
(* eta eta)
(/
(* sinTheta_O sinTheta_O)
(sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / sqrtf(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrtf((1.0f - (sinTheta_O * sinTheta_O))))))));
}
real(4) function code(sintheta_o, h, eta)
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / sqrt(((eta * eta) - ((sintheta_o * sintheta_o) / sqrt((1.0e0 - (sintheta_o * sintheta_o))))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(Float32(sinTheta_O * sinTheta_O) / sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / sqrt(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrt((single(1.0) - (sinTheta_O * sinTheta_O)))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta_O \cdot sinTheta_O}{\sqrt{1 - sinTheta_O \cdot sinTheta_O}}}}\right)
\end{array}
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(*
(sqrt (fma sinTheta_O (pow (hypot 1.0 sinTheta_O) -0.5) eta))
(sqrt (- eta (/ sinTheta_O (sqrt (hypot 1.0 sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (sqrtf(fmaf(sinTheta_O, powf(hypotf(1.0f, sinTheta_O), -0.5f), eta)) * sqrtf((eta - (sinTheta_O / sqrtf(hypotf(1.0f, sinTheta_O))))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(sqrt(fma(sinTheta_O, (hypot(Float32(1.0), sinTheta_O) ^ Float32(-0.5)), eta)) * sqrt(Float32(eta - Float32(sinTheta_O / sqrt(hypot(Float32(1.0), sinTheta_O)))))))) end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(sinTheta_O, {\left(\mathsf{hypot}\left(1, sinTheta_O\right)\right)}^{-0.5}, eta\right)} \cdot \sqrt{eta - \frac{sinTheta_O}{\sqrt{\mathsf{hypot}\left(1, sinTheta_O\right)}}}}\right)
\end{array}
Initial program 90.9%
add-sqr-sqrt90.9%
difference-of-squares90.9%
Applied egg-rr90.7%
sqrt-prod98.5%
+-commutative98.5%
div-inv98.5%
fma-def98.5%
pow1/298.5%
pow-flip98.5%
metadata-eval98.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
(*
h
(sqrt
(/
1.0
(-
eta
(* sinTheta_O (pow (/ 1.0 (+ 1.0 (* sinTheta_O sinTheta_O))) 0.25))))))
(sqrt (fma sinTheta_O (pow (hypot 1.0 sinTheta_O) -0.5) eta)))))
float code(float sinTheta_O, float h, float eta) {
return asinf(((h * sqrtf((1.0f / (eta - (sinTheta_O * powf((1.0f / (1.0f + (sinTheta_O * sinTheta_O))), 0.25f)))))) / sqrtf(fmaf(sinTheta_O, powf(hypotf(1.0f, sinTheta_O), -0.5f), eta))));
}
function code(sinTheta_O, h, eta) return asin(Float32(Float32(h * sqrt(Float32(Float32(1.0) / Float32(eta - Float32(sinTheta_O * (Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(sinTheta_O * sinTheta_O))) ^ Float32(0.25))))))) / sqrt(fma(sinTheta_O, (hypot(Float32(1.0), sinTheta_O) ^ Float32(-0.5)), eta)))) end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h \cdot \sqrt{\frac{1}{eta - sinTheta_O \cdot {\left(\frac{1}{1 + sinTheta_O \cdot sinTheta_O}\right)}^{0.25}}}}{\sqrt{\mathsf{fma}\left(sinTheta_O, {\left(\mathsf{hypot}\left(1, sinTheta_O\right)\right)}^{-0.5}, eta\right)}}\right)
\end{array}
Initial program 90.9%
add-sqr-sqrt90.9%
difference-of-squares90.9%
Applied egg-rr90.7%
*-un-lft-identity90.7%
sqrt-prod98.5%
times-frac98.1%
+-commutative98.1%
div-inv98.1%
fma-def98.1%
pow1/298.1%
pow-flip98.1%
metadata-eval98.1%
Applied egg-rr98.1%
associate-*l/98.2%
*-lft-identity98.2%
Simplified98.2%
Taylor expanded in h around 0 98.5%
*-commutative98.5%
*-commutative98.5%
+-commutative98.5%
unpow298.5%
Simplified98.5%
Final simplification98.5%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (/ (* -0.5 (* sinTheta_O sinTheta_O)) eta)))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + ((-0.5f * (sinTheta_O * sinTheta_O)) / eta))));
}
real(4) function code(sintheta_o, h, eta)
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / (eta + (((-0.5e0) * (sintheta_o * sintheta_o)) / eta))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(Float32(-0.5) * Float32(sinTheta_O * sinTheta_O)) / eta)))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + ((single(-0.5) * (sinTheta_O * sinTheta_O)) / eta)))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + \frac{-0.5 \cdot \left(sinTheta_O \cdot sinTheta_O\right)}{eta}}\right)
\end{array}
Initial program 90.9%
Taylor expanded in sinTheta_O around 0 97.2%
unpow297.2%
associate-*r/97.2%
Simplified97.2%
Final simplification97.2%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (- eta (* (/ sinTheta_O (/ eta sinTheta_O)) 0.5)))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta - ((sinTheta_O / (eta / sinTheta_O)) * 0.5f))));
}
real(4) function code(sintheta_o, h, eta)
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / (eta - ((sintheta_o / (eta / sintheta_o)) * 0.5e0))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta - Float32(Float32(sinTheta_O / Float32(eta / sinTheta_O)) * Float32(0.5))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta - ((sinTheta_O / (eta / sinTheta_O)) * single(0.5))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta - \frac{sinTheta_O}{\frac{eta}{sinTheta_O}} \cdot 0.5}\right)
\end{array}
Initial program 90.9%
Taylor expanded in sinTheta_O around 0 97.2%
unpow297.2%
associate-*r/97.2%
Simplified97.2%
Taylor expanded in h around 0 97.2%
metadata-eval97.2%
cancel-sign-sub-inv97.2%
*-commutative97.2%
unpow297.2%
associate-/l*97.8%
Simplified97.8%
Final simplification97.8%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h eta)))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / eta));
}
real(4) function code(sintheta_o, h, eta)
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / eta))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / eta)) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / eta)); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta}\right)
\end{array}
Initial program 90.9%
Taylor expanded in eta around inf 95.7%
Final simplification95.7%
herbie shell --seed 2023194
(FPCore (sinTheta_O h eta)
:name "HairBSDF, gamma for a refracted ray"
:precision binary32
:pre (and (and (and (<= -1.0 sinTheta_O) (<= sinTheta_O 1.0)) (and (<= -1.0 h) (<= h 1.0))) (and (<= 0.0 eta) (<= eta 10.0)))
(asin (/ h (sqrt (- (* eta eta) (/ (* sinTheta_O sinTheta_O) (sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))