
(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
(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 89.5%
add-sqr-sqrt89.5%
difference-of-squares89.5%
sqrt-div89.5%
sqrt-prod41.5%
add-sqr-sqrt85.7%
pow1/285.7%
sqrt-pow185.7%
pow285.7%
metadata-eval85.7%
sqrt-div85.7%
sqrt-prod41.6%
add-sqr-sqrt89.5%
pow1/289.5%
sqrt-pow189.5%
Applied egg-rr89.5%
sqrt-prod98.6%
+-commutative98.6%
div-inv98.6%
fma-def98.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 (* -0.5 (pow (exp (log (/ sinTheta_O (sqrt eta)))) 2.0))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * powf(expf(logf((sinTheta_O / sqrtf(eta)))), 2.0f)))));
}
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) * (exp(log((sintheta_o / sqrt(eta)))) ** 2.0e0)))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * (exp(log(Float32(sinTheta_O / sqrt(eta)))) ^ Float32(2.0)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (exp(log((sinTheta_O / sqrt(eta)))) ^ single(2.0)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot {\left(e^{\log \left(\frac{sinTheta_O}{\sqrt{eta}}\right)}\right)}^{2}}\right)
\end{array}
Initial program 89.5%
Taylor expanded in sinTheta_O around 0 97.5%
add-sqr-sqrt97.5%
sqrt-div97.5%
unpow297.5%
sqrt-prod47.0%
add-sqr-sqrt96.6%
sqrt-div96.6%
unpow296.6%
sqrt-prod47.3%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
unpow298.2%
Simplified98.2%
add-exp-log47.3%
Applied egg-rr47.3%
Final simplification47.3%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (* -0.5 (/ 1.0 (/ (/ eta sinTheta_O) sinTheta_O)))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (1.0f / ((eta / 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 / (eta + ((-0.5e0) * (1.0e0 / ((eta / sintheta_o) / sintheta_o))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(Float32(1.0) / Float32(Float32(eta / sinTheta_O) / sinTheta_O)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (single(1.0) / ((eta / sinTheta_O) / sinTheta_O)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \frac{1}{\frac{\frac{eta}{sinTheta_O}}{sinTheta_O}}}\right)
\end{array}
Initial program 89.5%
Taylor expanded in sinTheta_O around 0 97.5%
add-sqr-sqrt97.5%
sqrt-div97.5%
unpow297.5%
sqrt-prod47.0%
add-sqr-sqrt96.6%
sqrt-div96.6%
unpow296.6%
sqrt-prod47.3%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
unpow298.2%
Simplified98.2%
unpow298.2%
clear-num98.2%
clear-num98.2%
frac-times98.2%
metadata-eval98.2%
Applied egg-rr98.2%
associate-*r/98.2%
associate-*l/98.2%
rem-square-sqrt98.2%
Simplified98.2%
Final simplification98.2%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (* -0.5 (/ sinTheta_O (/ eta sinTheta_O)))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (sinTheta_O / (eta / 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 / (eta + ((-0.5e0) * (sintheta_o / (eta / sintheta_o))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(sinTheta_O / Float32(eta / sinTheta_O)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (sinTheta_O / (eta / sinTheta_O)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \frac{sinTheta_O}{\frac{eta}{sinTheta_O}}}\right)
\end{array}
Initial program 89.5%
Taylor expanded in sinTheta_O around 0 97.5%
add-sqr-sqrt97.5%
sqrt-div97.5%
unpow297.5%
sqrt-prod47.0%
add-sqr-sqrt96.6%
sqrt-div96.6%
unpow296.6%
sqrt-prod47.3%
add-sqr-sqrt98.2%
Applied egg-rr98.2%
unpow298.2%
Simplified98.2%
unpow298.2%
clear-num98.2%
frac-times98.2%
*-un-lft-identity98.2%
Applied egg-rr98.2%
associate-*l/98.2%
rem-square-sqrt98.2%
Simplified98.2%
Final simplification98.2%
(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 89.5%
Taylor expanded in eta around inf 96.1%
Final simplification96.1%
herbie shell --seed 2023311
(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)))))))))