
(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
(asin
(/
h
(+
eta
(*
-0.5
(*
(/ sinTheta_O (pow (cbrt eta) 2.0))
(* sinTheta_O (pow (exp 0.3333333333333333) (- (log eta))))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * ((sinTheta_O / powf(cbrtf(eta), 2.0f)) * (sinTheta_O * powf(expf(0.3333333333333333f), -logf(eta))))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(Float32(sinTheta_O / (cbrt(eta) ^ Float32(2.0))) * Float32(sinTheta_O * (exp(Float32(0.3333333333333333)) ^ Float32(-log(eta))))))))) end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(\frac{sinTheta_O}{{\left(\sqrt[3]{eta}\right)}^{2}} \cdot \left(sinTheta_O \cdot {\left(e^{0.3333333333333333}\right)}^{\left(-\log eta\right)}\right)\right)}\right)
\end{array}
Initial program 91.5%
Taylor expanded in sinTheta_O around 0 97.3%
unpow297.3%
add-cbrt-cube77.3%
unpow277.3%
cbrt-prod91.0%
times-frac91.6%
unpow291.6%
cbrt-prod98.1%
pow298.1%
Applied egg-rr98.1%
Taylor expanded in sinTheta_O around 0 98.1%
add-exp-log98.1%
log-pow98.1%
log-rec98.1%
Applied egg-rr98.1%
exp-prod98.1%
Simplified98.1%
Final simplification98.1%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(*
(/ sinTheta_O (pow (cbrt eta) 2.0))
(* sinTheta_O (pow (/ 1.0 eta) 0.3333333333333333))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * ((sinTheta_O / powf(cbrtf(eta), 2.0f)) * (sinTheta_O * powf((1.0f / eta), 0.3333333333333333f)))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(Float32(sinTheta_O / (cbrt(eta) ^ Float32(2.0))) * Float32(sinTheta_O * (Float32(Float32(1.0) / eta) ^ Float32(0.3333333333333333)))))))) end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(\frac{sinTheta_O}{{\left(\sqrt[3]{eta}\right)}^{2}} \cdot \left(sinTheta_O \cdot {\left(\frac{1}{eta}\right)}^{0.3333333333333333}\right)\right)}\right)
\end{array}
Initial program 91.5%
Taylor expanded in sinTheta_O around 0 97.3%
unpow297.3%
add-cbrt-cube77.3%
unpow277.3%
cbrt-prod91.0%
times-frac91.6%
unpow291.6%
cbrt-prod98.1%
pow298.1%
Applied egg-rr98.1%
Taylor expanded in sinTheta_O around 0 98.1%
Final simplification98.1%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(* (/ sinTheta_O (pow (cbrt eta) 2.0)) (/ sinTheta_O (cbrt eta))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * ((sinTheta_O / powf(cbrtf(eta), 2.0f)) * (sinTheta_O / cbrtf(eta)))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(Float32(sinTheta_O / (cbrt(eta) ^ Float32(2.0))) * Float32(sinTheta_O / cbrt(eta))))))) end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(\frac{sinTheta_O}{{\left(\sqrt[3]{eta}\right)}^{2}} \cdot \frac{sinTheta_O}{\sqrt[3]{eta}}\right)}\right)
\end{array}
Initial program 91.5%
Taylor expanded in sinTheta_O around 0 97.3%
unpow297.3%
add-cbrt-cube77.3%
unpow277.3%
cbrt-prod91.0%
times-frac91.6%
unpow291.6%
cbrt-prod98.1%
pow298.1%
Applied egg-rr98.1%
Final simplification98.1%
(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 91.5%
Taylor expanded in sinTheta_O around 0 97.3%
unpow297.3%
add-cbrt-cube77.3%
unpow277.3%
cbrt-prod91.0%
times-frac91.6%
unpow291.6%
cbrt-prod98.1%
pow298.1%
Applied egg-rr98.1%
*-commutative98.1%
clear-num98.1%
clear-num98.1%
frac-times98.1%
metadata-eval98.1%
Applied egg-rr98.1%
associate-*l/98.1%
*-commutative98.1%
associate-*l/98.1%
unpow298.1%
rem-3cbrt-lft98.1%
Simplified98.1%
Final simplification98.1%
(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(sinTheta_O * Float32(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 \left(sinTheta_O \cdot \frac{sinTheta_O}{eta}\right)}\right)
\end{array}
Initial program 91.5%
Taylor expanded in sinTheta_O around 0 97.3%
unpow297.3%
*-un-lft-identity97.3%
times-frac98.1%
Applied egg-rr98.1%
Final simplification98.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.5%
Taylor expanded in eta around inf 95.6%
Final simplification95.6%
herbie shell --seed 2024019
(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)))))))))