
(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 (if (<= (* sinTheta_O sinTheta_O) 0.0) (asin (/ h eta)) (asin (/ h (sqrt (fma eta eta (* sinTheta_O (- sinTheta_O))))))))
float code(float sinTheta_O, float h, float eta) {
float tmp;
if ((sinTheta_O * sinTheta_O) <= 0.0f) {
tmp = asinf((h / eta));
} else {
tmp = asinf((h / sqrtf(fmaf(eta, eta, (sinTheta_O * -sinTheta_O)))));
}
return tmp;
}
function code(sinTheta_O, h, eta) tmp = Float32(0.0) if (Float32(sinTheta_O * sinTheta_O) <= Float32(0.0)) tmp = asin(Float32(h / eta)); else tmp = asin(Float32(h / sqrt(fma(eta, eta, Float32(sinTheta_O * Float32(-sinTheta_O)))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;sinTheta\_O \cdot sinTheta\_O \leq 0:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(eta, eta, sinTheta\_O \cdot \left(-sinTheta\_O\right)\right)}}\right)\\
\end{array}
\end{array}
if (*.f32 sinTheta_O sinTheta_O) < 0.0Initial program 90.8%
Taylor expanded in eta around inf
lower-/.f3298.7
Applied rewrites98.7%
if 0.0 < (*.f32 sinTheta_O sinTheta_O) Initial program 99.5%
Taylor expanded in sinTheta_O around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
unpow2N/A
difference-of-squaresN/A
lower-*.f32N/A
lower-+.f32N/A
lower--.f3299.5
Applied rewrites99.5%
difference-of-squaresN/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-*.f32N/A
lower-fma.f32N/A
lower-*.f32N/A
lower-neg.f3299.5
Applied rewrites99.5%
Final simplification99.1%
(FPCore (sinTheta_O h eta) :precision binary32 (asin (/ (* h (sqrt (/ 1.0 (+ eta sinTheta_O)))) (sqrt (- eta sinTheta_O)))))
float code(float sinTheta_O, float h, float eta) {
return asinf(((h * sqrtf((1.0f / (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((1.0e0 / (eta + sintheta_o)))) / sqrt((eta - sintheta_o))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(Float32(h * sqrt(Float32(Float32(1.0) / Float32(eta + sinTheta_O)))) / sqrt(Float32(eta - sinTheta_O)))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin(((h * sqrt((single(1.0) / (eta + sinTheta_O)))) / sqrt((eta - sinTheta_O)))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h \cdot \sqrt{\frac{1}{eta + sinTheta\_O}}}{\sqrt{eta - sinTheta\_O}}\right)
\end{array}
Initial program 94.9%
Taylor expanded in sinTheta_O around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
unpow2N/A
difference-of-squaresN/A
lower-*.f32N/A
lower-+.f32N/A
lower--.f3294.8
Applied rewrites94.8%
lift-+.f32N/A
lift--.f32N/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
associate-/r*N/A
lower-/.f32N/A
lower-/.f32N/A
pow1/2N/A
lower-sqrt.f32N/A
lift-+.f32N/A
+-commutativeN/A
lower-+.f32N/A
pow1/2N/A
lower-sqrt.f3298.4
Applied rewrites98.4%
Taylor expanded in h around 0
lower-*.f32N/A
lower-sqrt.f32N/A
lower-/.f32N/A
lower-+.f3298.5
Applied rewrites98.5%
(FPCore (sinTheta_O h eta) :precision binary32 (if (<= (* sinTheta_O sinTheta_O) 0.0) (asin (/ h eta)) (asin (/ h (sqrt (* (+ eta sinTheta_O) (- eta sinTheta_O)))))))
float code(float sinTheta_O, float h, float eta) {
float tmp;
if ((sinTheta_O * sinTheta_O) <= 0.0f) {
tmp = asinf((h / eta));
} else {
tmp = asinf((h / sqrtf(((eta + sinTheta_O) * (eta - sinTheta_O)))));
}
return tmp;
}
real(4) function code(sintheta_o, h, eta)
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
real(4) :: tmp
if ((sintheta_o * sintheta_o) <= 0.0e0) then
tmp = asin((h / eta))
else
tmp = asin((h / sqrt(((eta + sintheta_o) * (eta - sintheta_o)))))
end if
code = tmp
end function
function code(sinTheta_O, h, eta) tmp = Float32(0.0) if (Float32(sinTheta_O * sinTheta_O) <= Float32(0.0)) tmp = asin(Float32(h / eta)); else tmp = asin(Float32(h / sqrt(Float32(Float32(eta + sinTheta_O) * Float32(eta - sinTheta_O))))); end return tmp end
function tmp_2 = code(sinTheta_O, h, eta) tmp = single(0.0); if ((sinTheta_O * sinTheta_O) <= single(0.0)) tmp = asin((h / eta)); else tmp = asin((h / sqrt(((eta + sinTheta_O) * (eta - sinTheta_O))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;sinTheta\_O \cdot sinTheta\_O \leq 0:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{\left(eta + sinTheta\_O\right) \cdot \left(eta - sinTheta\_O\right)}}\right)\\
\end{array}
\end{array}
if (*.f32 sinTheta_O sinTheta_O) < 0.0Initial program 90.8%
Taylor expanded in eta around inf
lower-/.f3298.7
Applied rewrites98.7%
if 0.0 < (*.f32 sinTheta_O sinTheta_O) Initial program 99.5%
Taylor expanded in sinTheta_O around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
unpow2N/A
difference-of-squaresN/A
lower-*.f32N/A
lower-+.f32N/A
lower--.f3299.5
Applied rewrites99.5%
(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 94.9%
Taylor expanded in sinTheta_O around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
unpow2N/A
unpow2N/A
difference-of-squaresN/A
lower-*.f32N/A
lower-+.f32N/A
lower--.f3294.8
Applied rewrites94.8%
lift-+.f32N/A
lift--.f32N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
lower-*.f32N/A
pow1/2N/A
lower-sqrt.f32N/A
pow1/2N/A
lower-sqrt.f3298.5
lift-+.f32N/A
+-commutativeN/A
lower-+.f3298.5
Applied rewrites98.5%
Final simplification98.5%
(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 94.9%
Taylor expanded in eta around inf
lower-/.f3294.5
Applied rewrites94.5%
herbie shell --seed 2024214
(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)))))))))