
(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 9 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
(*
(pow (expm1 (log1p E)) (log (* sinTheta_O (/ sinTheta_O eta))))
(sqrt (/ 1.0 (- 1.0 (* sinTheta_O sinTheta_O))))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (powf(expm1f(log1pf(((float) M_E))), logf((sinTheta_O * (sinTheta_O / eta)))) * sqrtf((1.0f / (1.0f - (sinTheta_O * sinTheta_O)))))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32((expm1(log1p(Float32(exp(1)))) ^ log(Float32(sinTheta_O * Float32(sinTheta_O / eta)))) * sqrt(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O))))))))) end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left({\left(\mathsf{expm1}\left(\mathsf{log1p}\left(e\right)\right)\right)}^{\log \left(sinTheta_O \cdot \frac{sinTheta_O}{eta}\right)} \cdot \sqrt{\frac{1}{1 - sinTheta_O \cdot sinTheta_O}}\right)}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
add-exp-log96.7%
associate-/l*97.4%
Applied egg-rr97.4%
*-un-lft-identity97.4%
exp-prod97.4%
exp-1-e97.4%
associate-/r/97.4%
Applied egg-rr97.4%
expm1-log1p-u97.4%
Applied egg-rr97.4%
Final simplification97.4%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(*
(sqrt (/ 1.0 (- 1.0 (* sinTheta_O sinTheta_O))))
(pow (sqrt E) (* (log (* sinTheta_O (/ sinTheta_O eta))) 2.0))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (sqrtf((1.0f / (1.0f - (sinTheta_O * sinTheta_O)))) * powf(sqrtf(((float) M_E)), (logf((sinTheta_O * (sinTheta_O / eta))) * 2.0f)))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(sqrt(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))) * (sqrt(Float32(exp(1))) ^ Float32(log(Float32(sinTheta_O * Float32(sinTheta_O / eta))) * Float32(2.0)))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (sqrt((single(1.0) / (single(1.0) - (sinTheta_O * sinTheta_O)))) * (sqrt(single(2.71828182845904523536)) ^ (log((sinTheta_O * (sinTheta_O / eta))) * single(2.0)))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(\sqrt{\frac{1}{1 - sinTheta_O \cdot sinTheta_O}} \cdot {\left(\sqrt{e}\right)}^{\left(\log \left(sinTheta_O \cdot \frac{sinTheta_O}{eta}\right) \cdot 2\right)}\right)}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
add-exp-log96.7%
associate-/l*97.4%
Applied egg-rr97.4%
*-un-lft-identity97.4%
exp-prod97.4%
exp-1-e97.4%
associate-/r/97.4%
Applied egg-rr97.4%
add-sqr-sqrt97.4%
unpow-prod-down97.4%
associate-*l/96.7%
associate-*l/96.7%
Applied egg-rr96.7%
pow-sqr96.7%
associate-*r/97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(*
(sqrt (/ 1.0 (- 1.0 (* sinTheta_O sinTheta_O))))
(pow E (- (* 2.0 (log sinTheta_O)) (log eta)))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (sqrtf((1.0f / (1.0f - (sinTheta_O * sinTheta_O)))) * powf(((float) M_E), ((2.0f * logf(sinTheta_O)) - logf(eta))))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(sqrt(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))) * (Float32(exp(1)) ^ Float32(Float32(Float32(2.0) * log(sinTheta_O)) - log(eta)))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (sqrt((single(1.0) / (single(1.0) - (sinTheta_O * sinTheta_O)))) * (single(2.71828182845904523536) ^ ((single(2.0) * log(sinTheta_O)) - log(eta)))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(\sqrt{\frac{1}{1 - sinTheta_O \cdot sinTheta_O}} \cdot {e}^{\left(2 \cdot \log sinTheta_O - \log eta\right)}\right)}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
add-exp-log96.7%
associate-/l*97.4%
Applied egg-rr97.4%
*-un-lft-identity97.4%
exp-prod97.4%
exp-1-e97.4%
associate-/r/97.4%
Applied egg-rr97.4%
associate-*l/96.7%
log-div96.7%
pow296.7%
log-pow45.3%
Applied egg-rr45.3%
Final simplification45.3%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(*
(sqrt (/ 1.0 (- 1.0 (* sinTheta_O sinTheta_O))))
(exp (- (log sinTheta_O) (log (/ eta sinTheta_O))))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (sqrtf((1.0f / (1.0f - (sinTheta_O * sinTheta_O)))) * expf((logf(sinTheta_O) - logf((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) * (sqrt((1.0e0 / (1.0e0 - (sintheta_o * sintheta_o)))) * exp((log(sintheta_o) - log((eta / sintheta_o)))))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(sqrt(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))) * exp(Float32(log(sinTheta_O) - log(Float32(eta / sinTheta_O))))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (sqrt((single(1.0) / (single(1.0) - (sinTheta_O * sinTheta_O)))) * exp((log(sinTheta_O) - log((eta / sinTheta_O))))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(\sqrt{\frac{1}{1 - sinTheta_O \cdot sinTheta_O}} \cdot e^{\log sinTheta_O - \log \left(\frac{eta}{sinTheta_O}\right)}\right)}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
add-exp-log96.7%
associate-/l*97.4%
Applied egg-rr97.4%
log-div45.3%
Applied egg-rr45.3%
Final simplification45.3%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(*
(sqrt (/ 1.0 (- 1.0 (* sinTheta_O sinTheta_O))))
(pow E (log (* sinTheta_O (/ sinTheta_O eta))))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (sqrtf((1.0f / (1.0f - (sinTheta_O * sinTheta_O)))) * powf(((float) M_E), logf((sinTheta_O * (sinTheta_O / eta)))))))));
}
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(sqrt(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))) * (Float32(exp(1)) ^ log(Float32(sinTheta_O * Float32(sinTheta_O / eta))))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (sqrt((single(1.0) / (single(1.0) - (sinTheta_O * sinTheta_O)))) * (single(2.71828182845904523536) ^ log((sinTheta_O * (sinTheta_O / eta))))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(\sqrt{\frac{1}{1 - sinTheta_O \cdot sinTheta_O}} \cdot {e}^{\log \left(sinTheta_O \cdot \frac{sinTheta_O}{eta}\right)}\right)}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
add-exp-log96.7%
associate-/l*97.4%
Applied egg-rr97.4%
*-un-lft-identity97.4%
exp-prod97.4%
exp-1-e97.4%
associate-/r/97.4%
Applied egg-rr97.4%
Final simplification97.4%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(exp
(log
(/
sinTheta_O
(* (/ eta sinTheta_O) (sqrt (- 1.0 (* sinTheta_O sinTheta_O))))))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * expf(logf((sinTheta_O / ((eta / 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 / (eta + ((-0.5e0) * exp(log((sintheta_o / ((eta / sintheta_o) * sqrt((1.0e0 - (sintheta_o * sintheta_o)))))))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * exp(log(Float32(sinTheta_O / Float32(Float32(eta / sinTheta_O) * sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O))))))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * exp(log((sinTheta_O / ((eta / sinTheta_O) * sqrt((single(1.0) - (sinTheta_O * sinTheta_O))))))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot e^{\log \left(\frac{sinTheta_O}{\frac{eta}{sinTheta_O} \cdot \sqrt{1 - sinTheta_O \cdot sinTheta_O}}\right)}}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
expm1-log1p-u96.7%
expm1-udef24.3%
associate-/l*24.4%
sqrt-div24.4%
metadata-eval24.4%
Applied egg-rr24.4%
expm1-def97.4%
expm1-log1p97.4%
associate-*r/97.4%
*-rgt-identity97.4%
associate-/r/97.4%
Simplified97.4%
associate-/r/97.4%
un-div-inv97.4%
add-exp-log97.4%
associate-/r/97.4%
*-commutative97.4%
associate-/r/97.4%
frac-times97.4%
*-un-lft-identity97.4%
Applied egg-rr97.4%
Final simplification97.4%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
-0.5
(/
(* sinTheta_O (/ sinTheta_O eta))
(sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * ((sinTheta_O * (sinTheta_O / eta)) / 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 / (eta + ((-0.5e0) * ((sintheta_o * (sintheta_o / eta)) / sqrt((1.0e0 - (sintheta_o * sintheta_o))))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(-0.5) * Float32(Float32(sinTheta_O * Float32(sinTheta_O / eta)) / sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * ((sinTheta_O * (sinTheta_O / eta)) / sqrt((single(1.0) - (sinTheta_O * sinTheta_O)))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \frac{sinTheta_O \cdot \frac{sinTheta_O}{eta}}{\sqrt{1 - sinTheta_O \cdot sinTheta_O}}}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
expm1-log1p-u96.7%
expm1-udef24.3%
associate-/l*24.4%
sqrt-div24.4%
metadata-eval24.4%
Applied egg-rr24.4%
expm1-def97.4%
expm1-log1p97.4%
associate-*r/97.4%
*-rgt-identity97.4%
associate-/r/97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (* sinTheta_O (* -0.5 (/ sinTheta_O eta)))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (sinTheta_O * (-0.5f * (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 + (sintheta_o * ((-0.5e0) * (sintheta_o / eta))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(sinTheta_O * Float32(Float32(-0.5) * Float32(sinTheta_O / eta)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (sinTheta_O * (single(-0.5) * (sinTheta_O / eta)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + sinTheta_O \cdot \left(-0.5 \cdot \frac{sinTheta_O}{eta}\right)}\right)
\end{array}
Initial program 91.1%
Taylor expanded in eta around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
expm1-log1p-u96.7%
expm1-udef24.3%
associate-/l*24.4%
sqrt-div24.4%
metadata-eval24.4%
Applied egg-rr24.4%
expm1-def97.4%
expm1-log1p97.4%
associate-*r/97.4%
*-rgt-identity97.4%
associate-/r/97.4%
Simplified97.4%
Taylor expanded in sinTheta_O around 0 96.7%
*-commutative96.7%
unpow296.7%
associate-*r/97.4%
associate-*l*97.4%
Simplified97.4%
Final simplification97.4%
(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.1%
Taylor expanded in eta around inf 94.8%
Final simplification94.8%
herbie shell --seed 2023240
(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)))))))))