
(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 5 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
(*
(* sinTheta_O sinTheta_O)
(/ -0.125 (/ eta (/ (/ (* sinTheta_O sinTheta_O) eta) eta)))))
(* sinTheta_O (* sinTheta_O (/ -0.5 eta)))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / ((eta + ((sinTheta_O * sinTheta_O) * (-0.125f / (eta / (((sinTheta_O * sinTheta_O) / eta) / eta))))) + (sinTheta_O * (sinTheta_O * (-0.5f / 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 * sintheta_o) * ((-0.125e0) / (eta / (((sintheta_o * sintheta_o) / eta) / eta))))) + (sintheta_o * (sintheta_o * ((-0.5e0) / eta))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(Float32(eta + Float32(Float32(sinTheta_O * sinTheta_O) * Float32(Float32(-0.125) / Float32(eta / Float32(Float32(Float32(sinTheta_O * sinTheta_O) / eta) / eta))))) + Float32(sinTheta_O * Float32(sinTheta_O * Float32(Float32(-0.5) / eta)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / ((eta + ((sinTheta_O * sinTheta_O) * (single(-0.125) / (eta / (((sinTheta_O * sinTheta_O) / eta) / eta))))) + (sinTheta_O * (sinTheta_O * (single(-0.5) / eta)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\left(eta + \left(sinTheta\_O \cdot sinTheta\_O\right) \cdot \frac{-0.125}{\frac{eta}{\frac{\frac{sinTheta\_O \cdot sinTheta\_O}{eta}}{eta}}}\right) + sinTheta\_O \cdot \left(sinTheta\_O \cdot \frac{-0.5}{eta}\right)}\right)
\end{array}
Initial program 91.0%
Taylor expanded in sinTheta_O around 0
Simplified59.9%
Taylor expanded in eta around inf
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3272.2%
Simplified72.2%
Taylor expanded in eta around 0
*-lowering-*.f32N/A
unpow3N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f32N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
unpow2N/A
*-lowering-*.f3298.7%
Simplified98.7%
distribute-lft-inN/A
associate-+r+N/A
*-commutativeN/A
+-lowering-+.f32N/A
Applied egg-rr98.8%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
sinTheta_O
(*
sinTheta_O
(+
(/ -0.125 (/ eta (/ (/ (* sinTheta_O sinTheta_O) eta) eta)))
(/ -0.5 eta))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (sinTheta_O * (sinTheta_O * ((-0.125f / (eta / (((sinTheta_O * sinTheta_O) / eta) / eta))) + (-0.5f / 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 * (sintheta_o * (((-0.125e0) / (eta / (((sintheta_o * sintheta_o) / eta) / eta))) + ((-0.5e0) / eta)))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(sinTheta_O * Float32(sinTheta_O * Float32(Float32(Float32(-0.125) / Float32(eta / Float32(Float32(Float32(sinTheta_O * sinTheta_O) / eta) / eta))) + Float32(Float32(-0.5) / eta))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (sinTheta_O * (sinTheta_O * ((single(-0.125) / (eta / (((sinTheta_O * sinTheta_O) / eta) / eta))) + (single(-0.5) / eta))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + sinTheta\_O \cdot \left(sinTheta\_O \cdot \left(\frac{-0.125}{\frac{eta}{\frac{\frac{sinTheta\_O \cdot sinTheta\_O}{eta}}{eta}}} + \frac{-0.5}{eta}\right)\right)}\right)
\end{array}
Initial program 91.0%
Taylor expanded in sinTheta_O around 0
Simplified59.9%
Taylor expanded in eta around inf
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3272.2%
Simplified72.2%
Taylor expanded in eta around 0
*-lowering-*.f32N/A
unpow3N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f32N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
unpow2N/A
*-lowering-*.f3298.7%
Simplified98.7%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
*-lowering-*.f32N/A
/-lowering-/.f3298.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(+
eta
(*
(* sinTheta_O sinTheta_O)
(+
(/ -0.5 eta)
(* -0.125 (/ (/ (/ (* sinTheta_O sinTheta_O) eta) eta) eta))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + ((sinTheta_O * sinTheta_O) * ((-0.5f / eta) + (-0.125f * ((((sinTheta_O * sinTheta_O) / eta) / eta) / 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 * sintheta_o) * (((-0.5e0) / eta) + ((-0.125e0) * ((((sintheta_o * sintheta_o) / eta) / eta) / eta)))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(Float32(sinTheta_O * sinTheta_O) * Float32(Float32(Float32(-0.5) / eta) + Float32(Float32(-0.125) * Float32(Float32(Float32(Float32(sinTheta_O * sinTheta_O) / eta) / eta) / eta))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + ((sinTheta_O * sinTheta_O) * ((single(-0.5) / eta) + (single(-0.125) * ((((sinTheta_O * sinTheta_O) / eta) / eta) / eta))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + \left(sinTheta\_O \cdot sinTheta\_O\right) \cdot \left(\frac{-0.5}{eta} + -0.125 \cdot \frac{\frac{\frac{sinTheta\_O \cdot sinTheta\_O}{eta}}{eta}}{eta}\right)}\right)
\end{array}
Initial program 91.0%
Taylor expanded in sinTheta_O around 0
Simplified59.9%
Taylor expanded in eta around inf
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3272.2%
Simplified72.2%
Taylor expanded in eta around 0
*-lowering-*.f32N/A
unpow3N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f32N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f32N/A
/-lowering-/.f32N/A
unpow2N/A
*-lowering-*.f3298.7%
Simplified98.7%
Final simplification98.7%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ h (+ eta (* sinTheta_O (* sinTheta_O (/ -0.5 eta)))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / (eta + (sinTheta_O * (sinTheta_O * (-0.5f / 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 * (sintheta_o * ((-0.5e0) / eta))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / Float32(eta + Float32(sinTheta_O * Float32(sinTheta_O * Float32(Float32(-0.5) / eta)))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / (eta + (sinTheta_O * (sinTheta_O * (single(-0.5) / eta)))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{eta + sinTheta\_O \cdot \left(sinTheta\_O \cdot \frac{-0.5}{eta}\right)}\right)
\end{array}
Initial program 91.0%
Taylor expanded in sinTheta_O around 0
+-lowering-+.f32N/A
associate-*r/N/A
/-lowering-/.f32N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f32N/A
*-lowering-*.f3298.4%
Simplified98.4%
associate-*r*N/A
associate-*r/N/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
/-lowering-/.f3298.6%
Applied egg-rr98.6%
Final simplification98.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 91.0%
Taylor expanded in eta around inf
/-lowering-/.f3296.7%
Simplified96.7%
herbie shell --seed 2024163
(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)))))))))