
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v); end
\begin{array}{l}
\\
\frac{e^{-\frac{sinTheta_i \cdot sinTheta_O}{v}} \cdot \frac{cosTheta_i \cdot cosTheta_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v); end
\begin{array}{l}
\\
\frac{e^{-\frac{sinTheta_i \cdot sinTheta_O}{v}} \cdot \frac{cosTheta_i \cdot cosTheta_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}
\end{array}
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* (/ (/ 1.0 v) (* v (* (sinh (/ 1.0 v)) 2.0))) (/ (* cosTheta_i cosTheta_O) (exp (* (/ sinTheta_O v) sinTheta_i)))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return ((1.0f / v) / (v * (sinhf((1.0f / v)) * 2.0f))) * ((cosTheta_i * cosTheta_O) / expf(((sinTheta_O / v) * sinTheta_i)));
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = ((1.0e0 / v) / (v * (sinh((1.0e0 / v)) * 2.0e0))) * ((costheta_i * costheta_o) / exp(((sintheta_o / v) * sintheta_i)))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(Float32(Float32(1.0) / v) / Float32(v * Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)))) * Float32(Float32(cosTheta_i * cosTheta_O) / exp(Float32(Float32(sinTheta_O / v) * sinTheta_i)))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = ((single(1.0) / v) / (v * (sinh((single(1.0) / v)) * single(2.0)))) * ((cosTheta_i * cosTheta_O) / exp(((sinTheta_O / v) * sinTheta_i))); end
\begin{array}{l}
\\
\frac{\frac{1}{v}}{v \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)} \cdot \frac{cosTheta_i \cdot cosTheta_O}{e^{\frac{sinTheta_O}{v} \cdot sinTheta_i}}
\end{array}
Initial program 98.6%
Simplified98.6%
associate-*r/98.6%
associate-/l*98.6%
Applied egg-rr98.6%
*-un-lft-identity98.6%
div-inv98.6%
times-frac98.8%
Applied egg-rr98.8%
associate-/l/98.8%
times-frac98.8%
div-inv98.8%
inv-pow98.8%
pow-flip98.9%
metadata-eval98.9%
pow198.9%
pow-exp98.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* (* (/ cosTheta_O v) (/ cosTheta_i (sinh (/ 1.0 v)))) (/ (/ (exp (* sinTheta_O (/ sinTheta_i v))) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return ((cosTheta_O / v) * (cosTheta_i / sinhf((1.0f / v)))) * ((expf((sinTheta_O * (sinTheta_i / v))) / 2.0f) / v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = ((costheta_o / v) * (costheta_i / sinh((1.0e0 / v)))) * ((exp((sintheta_o * (sintheta_i / v))) / 2.0e0) / v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(Float32(cosTheta_O / v) * Float32(cosTheta_i / sinh(Float32(Float32(1.0) / v)))) * Float32(Float32(exp(Float32(sinTheta_O * Float32(sinTheta_i / v))) / Float32(2.0)) / v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = ((cosTheta_O / v) * (cosTheta_i / sinh((single(1.0) / v)))) * ((exp((sinTheta_O * (sinTheta_i / v))) / single(2.0)) / v); end
\begin{array}{l}
\\
\left(\frac{cosTheta_O}{v} \cdot \frac{cosTheta_i}{\sinh \left(\frac{1}{v}\right)}\right) \cdot \frac{\frac{e^{sinTheta_O \cdot \frac{sinTheta_i}{v}}}{2}}{v}
\end{array}
Initial program 98.6%
div-inv98.9%
*-commutative98.9%
Applied egg-rr98.9%
associate-*l*98.9%
div-inv98.7%
*-commutative98.7%
associate-/r/98.6%
Applied egg-rr98.6%
add-cube-cbrt98.4%
pow398.4%
Applied egg-rr98.1%
rem-cube-cbrt98.4%
associate-/r*98.4%
associate-/l*98.4%
frac-times98.4%
associate-/r/98.4%
exp-prod98.4%
Applied egg-rr98.4%
times-frac98.4%
associate-/r/98.4%
exp-prod98.4%
*-commutative98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* (/ cosTheta_i (* v (* (sinh (/ 1.0 v)) 2.0))) (/ (/ cosTheta_O v) (exp (* (/ sinTheta_O v) sinTheta_i)))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return (cosTheta_i / (v * (sinhf((1.0f / v)) * 2.0f))) * ((cosTheta_O / v) / expf(((sinTheta_O / v) * sinTheta_i)));
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = (costheta_i / (v * (sinh((1.0e0 / v)) * 2.0e0))) * ((costheta_o / v) / exp(((sintheta_o / v) * sintheta_i)))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(cosTheta_i / Float32(v * Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)))) * Float32(Float32(cosTheta_O / v) / exp(Float32(Float32(sinTheta_O / v) * sinTheta_i)))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = (cosTheta_i / (v * (sinh((single(1.0) / v)) * single(2.0)))) * ((cosTheta_O / v) / exp(((sinTheta_O / v) * sinTheta_i))); end
\begin{array}{l}
\\
\frac{cosTheta_i}{v \cdot \left(\sinh \left(\frac{1}{v}\right) \cdot 2\right)} \cdot \frac{\frac{cosTheta_O}{v}}{e^{\frac{sinTheta_O}{v} \cdot sinTheta_i}}
\end{array}
Initial program 98.6%
Simplified98.6%
associate-*r/98.6%
associate-/l*98.6%
Applied egg-rr98.6%
*-un-lft-identity98.6%
div-inv98.6%
times-frac98.8%
Applied egg-rr98.8%
associate-/l/98.8%
frac-times98.6%
*-un-lft-identity98.6%
div-inv98.6%
div-inv98.6%
clear-num98.6%
times-frac98.7%
pow-exp98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* (/ 1.0 (- (exp (/ 1.0 v)) (exp (/ -1.0 v)))) (/ cosTheta_i (* v (/ v cosTheta_O)))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return (1.0f / (expf((1.0f / v)) - expf((-1.0f / v)))) * (cosTheta_i / (v * (v / cosTheta_O)));
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = (1.0e0 / (exp((1.0e0 / v)) - exp(((-1.0e0) / v)))) * (costheta_i / (v * (v / costheta_o)))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(Float32(1.0) / Float32(exp(Float32(Float32(1.0) / v)) - exp(Float32(Float32(-1.0) / v)))) * Float32(cosTheta_i / Float32(v * Float32(v / cosTheta_O)))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = (single(1.0) / (exp((single(1.0) / v)) - exp((single(-1.0) / v)))) * (cosTheta_i / (v * (v / cosTheta_O))); end
\begin{array}{l}
\\
\frac{1}{e^{\frac{1}{v}} - e^{\frac{-1}{v}}} \cdot \frac{cosTheta_i}{v \cdot \frac{v}{cosTheta_O}}
\end{array}
Initial program 98.6%
times-frac98.6%
exp-neg98.6%
*-commutative98.6%
exp-neg98.6%
*-commutative98.6%
associate-/l*98.6%
distribute-frac-neg98.6%
associate-/r/98.6%
associate-/l*98.5%
associate-/l/98.7%
Simplified98.7%
Taylor expanded in sinTheta_i around 0 98.4%
rec-exp98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* 0.5 (/ (/ 1.0 (/ (/ 1.0 cosTheta_O) cosTheta_i)) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return 0.5f * ((1.0f / ((1.0f / cosTheta_O) / cosTheta_i)) / v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = 0.5e0 * ((1.0e0 / ((1.0e0 / costheta_o) / costheta_i)) / v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(0.5) * Float32(Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / cosTheta_O) / cosTheta_i)) / v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = single(0.5) * ((single(1.0) / ((single(1.0) / cosTheta_O) / cosTheta_i)) / v); end
\begin{array}{l}
\\
0.5 \cdot \frac{\frac{1}{\frac{\frac{1}{cosTheta_O}}{cosTheta_i}}}{v}
\end{array}
Initial program 98.6%
times-frac98.6%
exp-neg98.6%
*-commutative98.6%
exp-neg98.6%
*-commutative98.6%
associate-/l*98.6%
distribute-frac-neg98.6%
associate-/r/98.6%
associate-/l*98.5%
associate-/l/98.7%
Simplified98.7%
Taylor expanded in v around inf 58.9%
*-commutative58.9%
pow158.9%
metadata-eval58.9%
pow-flip58.9%
inv-pow58.9%
div-inv58.9%
clear-num59.6%
Applied egg-rr59.6%
Final simplification59.6%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* 0.5 (/ 1.0 (/ (/ v cosTheta_O) cosTheta_i))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return 0.5f * (1.0f / ((v / cosTheta_O) / cosTheta_i));
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = 0.5e0 * (1.0e0 / ((v / costheta_o) / costheta_i))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(0.5) * Float32(Float32(1.0) / Float32(Float32(v / cosTheta_O) / cosTheta_i))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = single(0.5) * (single(1.0) / ((v / cosTheta_O) / cosTheta_i)); end
\begin{array}{l}
\\
0.5 \cdot \frac{1}{\frac{\frac{v}{cosTheta_O}}{cosTheta_i}}
\end{array}
Initial program 98.6%
times-frac98.6%
exp-neg98.6%
*-commutative98.6%
exp-neg98.6%
*-commutative98.6%
associate-/l*98.6%
distribute-frac-neg98.6%
associate-/r/98.6%
associate-/l*98.5%
associate-/l/98.7%
Simplified98.7%
Taylor expanded in v around inf 58.9%
*-commutative58.9%
associate-*l/58.9%
*-commutative58.9%
Simplified58.9%
add-sqr-sqrt49.4%
pow249.4%
*-commutative49.4%
associate-*r/49.4%
associate-*l/49.4%
*-commutative49.4%
Applied egg-rr49.4%
unpow249.4%
add-sqr-sqrt58.9%
Applied egg-rr58.9%
associate-*r/58.9%
associate-/l*58.9%
clear-num59.4%
Applied egg-rr59.4%
Final simplification59.4%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* 0.5 (* cosTheta_O (/ cosTheta_i v))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return 0.5f * (cosTheta_O * (cosTheta_i / v));
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = 0.5e0 * (costheta_o * (costheta_i / v))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(0.5) * Float32(cosTheta_O * Float32(cosTheta_i / v))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = single(0.5) * (cosTheta_O * (cosTheta_i / v)); end
\begin{array}{l}
\\
0.5 \cdot \left(cosTheta_O \cdot \frac{cosTheta_i}{v}\right)
\end{array}
Initial program 98.6%
times-frac98.6%
exp-neg98.6%
*-commutative98.6%
exp-neg98.6%
*-commutative98.6%
associate-/l*98.6%
distribute-frac-neg98.6%
associate-/r/98.6%
associate-/l*98.5%
associate-/l/98.7%
Simplified98.7%
Taylor expanded in v around inf 58.9%
*-commutative58.9%
associate-*l/58.9%
*-commutative58.9%
Simplified58.9%
Final simplification58.9%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* 0.5 (/ (* cosTheta_i cosTheta_O) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return 0.5f * ((cosTheta_i * cosTheta_O) / v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = 0.5e0 * ((costheta_i * costheta_o) / v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(0.5) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = single(0.5) * ((cosTheta_i * cosTheta_O) / v); end
\begin{array}{l}
\\
0.5 \cdot \frac{cosTheta_i \cdot cosTheta_O}{v}
\end{array}
Initial program 98.6%
times-frac98.6%
exp-neg98.6%
*-commutative98.6%
exp-neg98.6%
*-commutative98.6%
associate-/l*98.6%
distribute-frac-neg98.6%
associate-/r/98.6%
associate-/l*98.5%
associate-/l/98.7%
Simplified98.7%
Taylor expanded in v around inf 58.9%
Final simplification58.9%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (/ 0.5 (/ v (* cosTheta_i cosTheta_O))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return 0.5f / (v / (cosTheta_i * cosTheta_O));
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: costheta_o
real(4), intent (in) :: sintheta_i
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: v
code = 0.5e0 / (v / (costheta_i * costheta_o))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(0.5) / Float32(v / Float32(cosTheta_i * cosTheta_O))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = single(0.5) / (v / (cosTheta_i * cosTheta_O)); end
\begin{array}{l}
\\
\frac{0.5}{\frac{v}{cosTheta_i \cdot cosTheta_O}}
\end{array}
Initial program 98.6%
Simplified98.6%
associate-*r/98.6%
associate-/l*98.6%
Applied egg-rr98.6%
*-un-lft-identity98.6%
div-inv98.6%
times-frac98.8%
Applied egg-rr98.8%
associate-/l/98.8%
times-frac98.8%
div-inv98.8%
inv-pow98.8%
pow-flip98.9%
metadata-eval98.9%
pow198.9%
pow-exp98.9%
Applied egg-rr98.9%
Taylor expanded in v around inf 58.9%
associate-*r/58.9%
*-commutative58.9%
associate-/l*59.4%
*-commutative59.4%
Simplified59.4%
Final simplification59.4%
herbie shell --seed 2024010
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:name "HairBSDF, Mp, upper"
:precision binary32
:pre (and (and (and (and (and (and (<= -1.0 cosTheta_i) (<= cosTheta_i 1.0)) (and (<= -1.0 cosTheta_O) (<= cosTheta_O 1.0))) (and (<= -1.0 sinTheta_i) (<= sinTheta_i 1.0))) (and (<= -1.0 sinTheta_O) (<= sinTheta_O 1.0))) (< 0.1 v)) (<= v 1.5707964))
(/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))