
(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 (/ 1.0 (+ sinTheta_O eta))) (sqrt (- eta sinTheta_O))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h * (sqrtf((1.0f / (sinTheta_O + eta))) / 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((1.0e0 / (sintheta_o + eta))) / sqrt((eta - sintheta_o)))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h * Float32(sqrt(Float32(Float32(1.0) / Float32(sinTheta_O + eta))) / sqrt(Float32(eta - sinTheta_O))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h * (sqrt((single(1.0) / (sinTheta_O + eta))) / sqrt((eta - sinTheta_O))))); end
\begin{array}{l}
\\
\sin^{-1} \left(h \cdot \frac{\sqrt{\frac{1}{sinTheta\_O + eta}}}{\sqrt{eta - sinTheta\_O}}\right)
\end{array}
Initial program 93.5%
Taylor expanded in h around 0 89.8%
Taylor expanded in sinTheta_O around 0 89.8%
neg-mul-189.8%
+-commutative89.8%
unsub-neg89.8%
Simplified89.8%
unpow289.8%
unpow289.8%
difference-of-squares89.8%
Applied egg-rr89.8%
associate-/r*89.9%
sqrt-div98.8%
+-commutative98.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (* -0.5 (* sinTheta_O (* sinTheta_O (/ 1.0 eta))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (-0.5f * (sinTheta_O * (sinTheta_O * (1.0f / 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 * (1.0e0 / 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 * Float32(Float32(1.0) / eta))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (single(-0.5) * (sinTheta_O * (sinTheta_O * (single(1.0) / eta))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + -0.5 \cdot \left(sinTheta\_O \cdot \left(sinTheta\_O \cdot \frac{1}{eta}\right)\right)}\right)
\end{array}
Initial program 93.5%
Taylor expanded in sinTheta_O around 0 97.0%
add-sqr-sqrt97.0%
div-inv97.0%
sqrt-prod97.0%
sqrt-pow196.3%
metadata-eval96.3%
pow196.3%
inv-pow96.3%
sqrt-pow196.3%
metadata-eval96.3%
div-inv96.3%
sqrt-prod96.3%
sqrt-pow197.8%
metadata-eval97.8%
pow197.8%
inv-pow97.8%
sqrt-pow197.8%
metadata-eval97.8%
Applied egg-rr97.8%
unpow297.8%
Simplified97.8%
unpow-prod-down97.0%
pow-pow97.0%
metadata-eval97.0%
inv-pow97.0%
unpow297.0%
associate-*l*97.8%
Applied egg-rr97.8%
Final simplification97.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(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 93.5%
Taylor expanded in sinTheta_O around 0 97.0%
add-sqr-sqrt97.0%
div-inv97.0%
sqrt-prod97.0%
sqrt-pow196.3%
metadata-eval96.3%
pow196.3%
inv-pow96.3%
sqrt-pow196.3%
metadata-eval96.3%
div-inv96.3%
sqrt-prod96.3%
sqrt-pow197.8%
metadata-eval97.8%
pow197.8%
inv-pow97.8%
sqrt-pow197.8%
metadata-eval97.8%
Applied egg-rr97.8%
unpow297.8%
Simplified97.8%
unpow-prod-down97.0%
pow-pow97.0%
metadata-eval97.0%
inv-pow97.0%
div-inv97.0%
unpow297.0%
associate-/l*97.8%
Applied egg-rr97.8%
Final simplification97.8%
(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 95.1%
Final simplification95.1%
herbie shell --seed 2024115
(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)))))))))