
(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 3 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 (* (* (pow (- eta sinTheta_O) -0.5) (pow (+ eta sinTheta_O) -0.5)) h)))
float code(float sinTheta_O, float h, float eta) {
return asinf(((powf((eta - sinTheta_O), -0.5f) * powf((eta + sinTheta_O), -0.5f)) * h));
}
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(((((eta - sintheta_o) ** (-0.5e0)) * ((eta + sintheta_o) ** (-0.5e0))) * h))
end function
function code(sinTheta_O, h, eta) return asin(Float32(Float32((Float32(eta - sinTheta_O) ^ Float32(-0.5)) * (Float32(eta + sinTheta_O) ^ Float32(-0.5))) * h)) end
function tmp = code(sinTheta_O, h, eta) tmp = asin(((((eta - sinTheta_O) ^ single(-0.5)) * ((eta + sinTheta_O) ^ single(-0.5))) * h)); end
\begin{array}{l}
\\
\sin^{-1} \left(\left({\left(eta - sinTheta_O\right)}^{-0.5} \cdot {\left(eta + sinTheta_O\right)}^{-0.5}\right) \cdot h\right)
\end{array}
Initial program 92.2%
clear-num91.5%
associate-/r/91.6%
pow1/291.6%
pow-flip91.6%
pow291.6%
pow291.6%
pow291.6%
metadata-eval91.6%
Applied egg-rr91.6%
Taylor expanded in sinTheta_O around 0 91.5%
neg-mul-191.5%
+-commutative91.5%
unsub-neg91.5%
Simplified91.5%
unpow291.5%
unpow291.5%
difference-of-squares91.5%
Applied egg-rr91.5%
*-commutative91.5%
unpow-prod-down98.3%
+-commutative98.3%
Applied egg-rr98.3%
Final simplification98.3%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (/ (* sinTheta_O -0.5) (/ eta sinTheta_O))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + ((sinTheta_O * -0.5f) / (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 + ((sintheta_o * (-0.5e0)) / (eta / sintheta_o)))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(sinTheta_O * Float32(-0.5)) / Float32(eta / sinTheta_O))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + ((sinTheta_O * single(-0.5)) / (eta / sinTheta_O))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + \frac{sinTheta_O \cdot -0.5}{\frac{eta}{sinTheta_O}}}\right)
\end{array}
Initial program 92.2%
Taylor expanded in sinTheta_O around 0 98.1%
unpow298.1%
*-un-lft-identity98.1%
times-frac98.3%
Applied egg-rr98.3%
/-rgt-identity98.3%
associate-*r*98.3%
clear-num98.3%
un-div-inv98.3%
*-commutative98.3%
Applied egg-rr98.3%
Final simplification98.3%
(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 92.2%
Taylor expanded in eta around inf 96.2%
Final simplification96.2%
herbie shell --seed 2024021
(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)))))))))