
(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 4 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 (* (sqrt (- eta sinTheta_O)) (sqrt (+ eta sinTheta_O))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (sqrtf((eta - sinTheta_O)) * sqrtf((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 / (sqrt((eta - sintheta_o)) * sqrt((eta + sintheta_o)))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(sqrt(Float32(eta - sinTheta_O)) * sqrt(Float32(eta + sinTheta_O))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (sqrt((eta - sinTheta_O)) * sqrt((eta + sinTheta_O))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\sqrt{eta - sinTheta_O} \cdot \sqrt{eta + sinTheta_O}}\right)
\end{array}
Initial program 90.3%
Taylor expanded in sinTheta_O around 0 89.4%
unpow289.4%
unpow289.4%
mul-1-neg89.4%
unsub-neg89.4%
Simplified89.4%
pow1/289.4%
difference-of-squares89.3%
+-commutative89.3%
unpow-prod-down97.6%
pow1/297.6%
pow1/297.6%
Applied egg-rr97.6%
*-commutative97.6%
+-commutative97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
(* -0.5 (* sinTheta_O (/ sinTheta_O eta)))
(pow (- 1.0 (* sinTheta_O sinTheta_O)) -0.5))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + ((-0.5f * (sinTheta_O * (sinTheta_O / eta))) * powf((1.0f - (sinTheta_O * sinTheta_O)), -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 + (((-0.5e0) * (sintheta_o * (sintheta_o / eta))) * ((1.0e0 - (sintheta_o * sintheta_o)) ** (-0.5e0))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(Float32(-0.5) * Float32(sinTheta_O * Float32(sinTheta_O / eta))) * (Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)) ^ Float32(-0.5)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + ((single(-0.5) * (sinTheta_O * (sinTheta_O / eta))) * ((single(1.0) - (sinTheta_O * sinTheta_O)) ^ single(-0.5)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + \left(-0.5 \cdot \left(sinTheta_O \cdot \frac{sinTheta_O}{eta}\right)\right) \cdot {\left(1 - sinTheta_O \cdot sinTheta_O\right)}^{-0.5}}\right)
\end{array}
Initial program 90.3%
Taylor expanded in eta around inf 95.6%
unpow295.6%
unpow295.6%
Simplified95.6%
expm1-log1p-u95.6%
expm1-udef93.7%
associate-/l*93.7%
pow1/293.7%
inv-pow93.7%
pow-pow93.7%
metadata-eval93.7%
Applied egg-rr93.7%
expm1-def96.8%
expm1-log1p96.8%
associate-*r*96.8%
associate-/r/96.8%
Simplified96.8%
Final simplification96.8%
(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 90.3%
Taylor expanded in sinTheta_O around 0 95.6%
unpow295.6%
Simplified95.6%
Final simplification95.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 90.3%
Taylor expanded in eta around inf 92.9%
Final simplification92.9%
herbie shell --seed 2023278
(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)))))))))