
(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 3 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 93.5%
add-sqr-sqrt93.5%
difference-of-squares93.5%
sqrt-div93.5%
sqrt-prod52.4%
add-sqr-sqrt89.4%
pow1/289.4%
sqrt-pow189.4%
pow289.4%
metadata-eval89.4%
sqrt-div89.4%
sqrt-prod52.7%
add-sqr-sqrt93.5%
pow1/293.5%
sqrt-pow193.5%
Applied egg-rr93.5%
sqrt-prod98.6%
+-commutative98.6%
div-inv98.6%
fma-define98.6%
pow-flip98.6%
metadata-eval98.6%
div-inv98.6%
pow-flip98.6%
metadata-eval98.6%
Applied egg-rr98.6%
Final simplification98.6%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (* sinTheta_O (* sinTheta_O (/ -0.5 eta)))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (sinTheta_O * (sinTheta_O * (-0.5f / 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 + (sintheta_o * (sintheta_o * ((-0.5e0) / eta))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(sinTheta_O * Float32(sinTheta_O * Float32(Float32(-0.5) / eta)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (sinTheta_O * (sinTheta_O * (single(-0.5) / eta)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + sinTheta\_O \cdot \left(sinTheta\_O \cdot \frac{-0.5}{eta}\right)}\right)
\end{array}
Initial program 93.5%
add-sqr-sqrt93.5%
difference-of-squares93.5%
sqrt-div93.5%
sqrt-prod52.4%
add-sqr-sqrt89.4%
pow1/289.4%
sqrt-pow189.4%
pow289.4%
metadata-eval89.4%
sqrt-div89.4%
sqrt-prod52.7%
add-sqr-sqrt93.5%
pow1/293.5%
sqrt-pow193.5%
Applied egg-rr93.5%
sqrt-prod98.6%
+-commutative98.6%
div-inv98.6%
fma-define98.6%
pow-flip98.6%
metadata-eval98.6%
div-inv98.6%
pow-flip98.6%
metadata-eval98.6%
Applied egg-rr98.6%
Taylor expanded in sinTheta_O around 0 93.1%
Simplified97.6%
Final simplification97.6%
(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 93.5%
Taylor expanded in eta around inf 94.2%
Final simplification94.2%
herbie shell --seed 2024080
(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)))))))))