
(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 6 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
(let* ((t_0 (pow (- 1.0 (pow sinTheta_O 2.0)) -0.25)))
(asin
(/
h
(* (sqrt (fma sinTheta_O t_0 eta)) (sqrt (- eta (* sinTheta_O t_0))))))))
float code(float sinTheta_O, float h, float eta) {
float t_0 = powf((1.0f - powf(sinTheta_O, 2.0f)), -0.25f);
return asinf((h / (sqrtf(fmaf(sinTheta_O, t_0, eta)) * sqrtf((eta - (sinTheta_O * t_0))))));
}
function code(sinTheta_O, h, eta) t_0 = Float32(Float32(1.0) - (sinTheta_O ^ Float32(2.0))) ^ Float32(-0.25) return asin(Float32(h / Float32(sqrt(fma(sinTheta_O, t_0, eta)) * sqrt(Float32(eta - Float32(sinTheta_O * t_0)))))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(1 - {sinTheta\_O}^{2}\right)}^{-0.25}\\
\sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(sinTheta\_O, t\_0, eta\right)} \cdot \sqrt{eta - sinTheta\_O \cdot t\_0}}\right)
\end{array}
\end{array}
Initial program 91.7%
add-sqr-sqrt91.7%
difference-of-squares91.7%
sqrt-div91.7%
sqrt-prod41.6%
add-sqr-sqrt88.4%
pow1/288.4%
sqrt-pow188.4%
pow288.4%
metadata-eval88.4%
sqrt-div88.4%
sqrt-prod41.7%
add-sqr-sqrt91.7%
pow1/291.7%
sqrt-pow191.7%
Applied egg-rr91.7%
sqrt-prod98.8%
+-commutative98.8%
div-inv98.8%
fma-define98.8%
pow-flip98.8%
metadata-eval98.8%
div-inv98.8%
pow-flip98.8%
metadata-eval98.8%
Applied egg-rr98.8%
(FPCore (sinTheta_O h eta)
:precision binary32
(let* ((t_0 (- 1.0 (pow sinTheta_O 2.0))))
(asin
(/
h
(*
(sqrt (- eta (* sinTheta_O (pow t_0 -0.25))))
(sqrt (* eta (+ 1.0 (* (pow (/ 1.0 t_0) 0.25) (/ sinTheta_O eta))))))))))
float code(float sinTheta_O, float h, float eta) {
float t_0 = 1.0f - powf(sinTheta_O, 2.0f);
return asinf((h / (sqrtf((eta - (sinTheta_O * powf(t_0, -0.25f)))) * sqrtf((eta * (1.0f + (powf((1.0f / t_0), 0.25f) * (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
real(4) :: t_0
t_0 = 1.0e0 - (sintheta_o ** 2.0e0)
code = asin((h / (sqrt((eta - (sintheta_o * (t_0 ** (-0.25e0))))) * sqrt((eta * (1.0e0 + (((1.0e0 / t_0) ** 0.25e0) * (sintheta_o / eta))))))))
end function
function code(sinTheta_O, h, eta) t_0 = Float32(Float32(1.0) - (sinTheta_O ^ Float32(2.0))) return asin(Float32(h / Float32(sqrt(Float32(eta - Float32(sinTheta_O * (t_0 ^ Float32(-0.25))))) * sqrt(Float32(eta * Float32(Float32(1.0) + Float32((Float32(Float32(1.0) / t_0) ^ Float32(0.25)) * Float32(sinTheta_O / eta)))))))) end
function tmp = code(sinTheta_O, h, eta) t_0 = single(1.0) - (sinTheta_O ^ single(2.0)); tmp = asin((h / (sqrt((eta - (sinTheta_O * (t_0 ^ single(-0.25))))) * sqrt((eta * (single(1.0) + (((single(1.0) / t_0) ^ single(0.25)) * (sinTheta_O / eta)))))))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - {sinTheta\_O}^{2}\\
\sin^{-1} \left(\frac{h}{\sqrt{eta - sinTheta\_O \cdot {t\_0}^{-0.25}} \cdot \sqrt{eta \cdot \left(1 + {\left(\frac{1}{t\_0}\right)}^{0.25} \cdot \frac{sinTheta\_O}{eta}\right)}}\right)
\end{array}
\end{array}
Initial program 91.7%
add-sqr-sqrt91.7%
difference-of-squares91.7%
sqrt-div91.7%
sqrt-prod41.6%
add-sqr-sqrt88.4%
pow1/288.4%
sqrt-pow188.4%
pow288.4%
metadata-eval88.4%
sqrt-div88.4%
sqrt-prod41.7%
add-sqr-sqrt91.7%
pow1/291.7%
sqrt-pow191.7%
Applied egg-rr91.7%
sqrt-prod98.8%
+-commutative98.8%
div-inv98.8%
fma-define98.8%
pow-flip98.8%
metadata-eval98.8%
div-inv98.8%
pow-flip98.8%
metadata-eval98.8%
Applied egg-rr98.8%
Taylor expanded in eta around inf 98.7%
Final simplification98.7%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(*
(sqrt (- eta (* sinTheta_O (pow (- 1.0 (pow sinTheta_O 2.0)) -0.25))))
(sqrt (+ sinTheta_O eta))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (sqrtf((eta - (sinTheta_O * powf((1.0f - powf(sinTheta_O, 2.0f)), -0.25f)))) * sqrtf((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 / (sqrt((eta - (sintheta_o * ((1.0e0 - (sintheta_o ** 2.0e0)) ** (-0.25e0))))) * sqrt((sintheta_o + eta)))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(sqrt(Float32(eta - Float32(sinTheta_O * (Float32(Float32(1.0) - (sinTheta_O ^ Float32(2.0))) ^ Float32(-0.25))))) * sqrt(Float32(sinTheta_O + eta))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (sqrt((eta - (sinTheta_O * ((single(1.0) - (sinTheta_O ^ single(2.0))) ^ single(-0.25))))) * sqrt((sinTheta_O + eta))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\sqrt{eta - sinTheta\_O \cdot {\left(1 - {sinTheta\_O}^{2}\right)}^{-0.25}} \cdot \sqrt{sinTheta\_O + eta}}\right)
\end{array}
Initial program 91.7%
add-sqr-sqrt91.7%
difference-of-squares91.7%
sqrt-div91.7%
sqrt-prod41.6%
add-sqr-sqrt88.4%
pow1/288.4%
sqrt-pow188.4%
pow288.4%
metadata-eval88.4%
sqrt-div88.4%
sqrt-prod41.7%
add-sqr-sqrt91.7%
pow1/291.7%
sqrt-pow191.7%
Applied egg-rr91.7%
sqrt-prod98.8%
+-commutative98.8%
div-inv98.8%
fma-define98.8%
pow-flip98.8%
metadata-eval98.8%
div-inv98.8%
pow-flip98.8%
metadata-eval98.8%
Applied egg-rr98.8%
Taylor expanded in sinTheta_O around 0 98.5%
Final simplification98.5%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (* sinTheta_O (* (/ sinTheta_O eta) -0.5))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (sinTheta_O * ((sinTheta_O / eta) * -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 * ((sintheta_o / eta) * (-0.5e0))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(sinTheta_O * Float32(Float32(sinTheta_O / eta) * Float32(-0.5)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (sinTheta_O * ((sinTheta_O / eta) * single(-0.5)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + sinTheta\_O \cdot \left(\frac{sinTheta\_O}{eta} \cdot -0.5\right)}\right)
\end{array}
Initial program 91.7%
add-sqr-sqrt91.7%
difference-of-squares91.7%
sqrt-div91.7%
sqrt-prod41.6%
add-sqr-sqrt88.4%
pow1/288.4%
sqrt-pow188.4%
pow288.4%
metadata-eval88.4%
sqrt-div88.4%
sqrt-prod41.7%
add-sqr-sqrt91.7%
pow1/291.7%
sqrt-pow191.7%
Applied egg-rr91.7%
Taylor expanded in sinTheta_O around 0 91.7%
fma-define91.7%
Simplified91.7%
Taylor expanded in sinTheta_O around 0 98.4%
Final simplification98.4%
(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(-0.5) * Float32(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 + -0.5 \cdot \frac{sinTheta\_O \cdot sinTheta\_O}{eta}}\right)
\end{array}
Initial program 91.7%
Taylor expanded in sinTheta_O around 0 98.1%
unpow298.1%
Applied egg-rr98.1%
(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 91.7%
Taylor expanded in eta around inf 96.5%
herbie shell --seed 2024114
(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)))))))))