
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(exp
(+
(+
(-
(- (/ (* cosTheta_i cosTheta_O) v) (/ (* sinTheta_i sinTheta_O) v))
(/ 1.0 v))
0.6931)
(log (/ 1.0 (* 2.0 v))))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return expf(((((((cosTheta_i * cosTheta_O) / v) - ((sinTheta_i * sinTheta_O) / v)) - (1.0f / v)) + 0.6931f) + logf((1.0f / (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(((((((costheta_i * costheta_o) / v) - ((sintheta_i * sintheta_o) / v)) - (1.0e0 / v)) + 0.6931e0) + log((1.0e0 / (2.0e0 * v)))))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return exp(Float32(Float32(Float32(Float32(Float32(Float32(cosTheta_i * cosTheta_O) / v) - Float32(Float32(sinTheta_i * sinTheta_O) / v)) - Float32(Float32(1.0) / v)) + Float32(0.6931)) + log(Float32(Float32(1.0) / Float32(Float32(2.0) * v))))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = exp(((((((cosTheta_i * cosTheta_O) / v) - ((sinTheta_i * sinTheta_O) / v)) - (single(1.0) / v)) + single(0.6931)) + log((single(1.0) / (single(2.0) * v))))); end
\begin{array}{l}
\\
e^{\left(\left(\left(\frac{cosTheta\_i \cdot cosTheta\_O}{v} - \frac{sinTheta\_i \cdot sinTheta\_O}{v}\right) - \frac{1}{v}\right) + 0.6931\right) + \log \left(\frac{1}{2 \cdot v}\right)}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(exp
(+
(+
(-
(- (/ (* cosTheta_i cosTheta_O) v) (/ (* sinTheta_i sinTheta_O) v))
(/ 1.0 v))
0.6931)
(log (/ 1.0 (* 2.0 v))))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return expf(((((((cosTheta_i * cosTheta_O) / v) - ((sinTheta_i * sinTheta_O) / v)) - (1.0f / v)) + 0.6931f) + logf((1.0f / (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(((((((costheta_i * costheta_o) / v) - ((sintheta_i * sintheta_o) / v)) - (1.0e0 / v)) + 0.6931e0) + log((1.0e0 / (2.0e0 * v)))))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return exp(Float32(Float32(Float32(Float32(Float32(Float32(cosTheta_i * cosTheta_O) / v) - Float32(Float32(sinTheta_i * sinTheta_O) / v)) - Float32(Float32(1.0) / v)) + Float32(0.6931)) + log(Float32(Float32(1.0) / Float32(Float32(2.0) * v))))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = exp(((((((cosTheta_i * cosTheta_O) / v) - ((sinTheta_i * sinTheta_O) / v)) - (single(1.0) / v)) + single(0.6931)) + log((single(1.0) / (single(2.0) * v))))); end
\begin{array}{l}
\\
e^{\left(\left(\left(\frac{cosTheta\_i \cdot cosTheta\_O}{v} - \frac{sinTheta\_i \cdot sinTheta\_O}{v}\right) - \frac{1}{v}\right) + 0.6931\right) + \log \left(\frac{1}{2 \cdot v}\right)}
\end{array}
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(let* ((t_0 (log (* 2.0 v)))
(t_1
(+
(/ (- (* cosTheta_i cosTheta_O) (fma sinTheta_i sinTheta_O 1.0)) v)
0.6931))
(t_2 (+ t_0 t_1)))
(pow
(/ (pow E (* 0.5 (/ (* t_1 t_1) t_2))) (pow (* 2.0 v) (* (/ t_0 t_2) 0.5)))
2.0)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
float t_0 = logf((2.0f * v));
float t_1 = (((cosTheta_i * cosTheta_O) - fmaf(sinTheta_i, sinTheta_O, 1.0f)) / v) + 0.6931f;
float t_2 = t_0 + t_1;
return powf((powf(((float) M_E), (0.5f * ((t_1 * t_1) / t_2))) / powf((2.0f * v), ((t_0 / t_2) * 0.5f))), 2.0f);
}
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) t_0 = log(Float32(Float32(2.0) * v)) t_1 = Float32(Float32(Float32(Float32(cosTheta_i * cosTheta_O) - fma(sinTheta_i, sinTheta_O, Float32(1.0))) / v) + Float32(0.6931)) t_2 = Float32(t_0 + t_1) return Float32((Float32(exp(1)) ^ Float32(Float32(0.5) * Float32(Float32(t_1 * t_1) / t_2))) / (Float32(Float32(2.0) * v) ^ Float32(Float32(t_0 / t_2) * Float32(0.5)))) ^ Float32(2.0) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(2 \cdot v\right)\\
t_1 := \frac{cosTheta\_i \cdot cosTheta\_O - \mathsf{fma}\left(sinTheta\_i, sinTheta\_O, 1\right)}{v} + 0.6931\\
t_2 := t\_0 + t\_1\\
{\left(\frac{{e}^{\left(0.5 \cdot \frac{t\_1 \cdot t\_1}{t\_2}\right)}}{{\left(2 \cdot v\right)}^{\left(\frac{t\_0}{t\_2} \cdot 0.5\right)}}\right)}^{2}
\end{array}
\end{array}
Initial program 99.7%
Applied rewrites99.7%
Applied rewrites99.7%
lift-exp.f32N/A
lift-/.f32N/A
clear-numN/A
div-invN/A
clear-numN/A
lift-/.f32N/A
Applied rewrites99.7%
Applied rewrites99.7%
Final simplification99.7%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(let* ((t_0 (log (* 2.0 v)))
(t_1
(+
(/ (- (* cosTheta_i cosTheta_O) (fma sinTheta_i sinTheta_O 1.0)) v)
0.6931)))
(/
(pow (* E E) (* 0.5 (/ (* t_1 t_1) (+ t_0 t_1))))
(pow
(* 2.0 v)
(/
t_0
(+
(+
(/ (- (* cosTheta_i cosTheta_O) (fma sinTheta_O sinTheta_i 1.0)) v)
0.6931)
t_0))))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
float t_0 = logf((2.0f * v));
float t_1 = (((cosTheta_i * cosTheta_O) - fmaf(sinTheta_i, sinTheta_O, 1.0f)) / v) + 0.6931f;
return powf((((float) M_E) * ((float) M_E)), (0.5f * ((t_1 * t_1) / (t_0 + t_1)))) / powf((2.0f * v), (t_0 / (((((cosTheta_i * cosTheta_O) - fmaf(sinTheta_O, sinTheta_i, 1.0f)) / v) + 0.6931f) + t_0)));
}
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) t_0 = log(Float32(Float32(2.0) * v)) t_1 = Float32(Float32(Float32(Float32(cosTheta_i * cosTheta_O) - fma(sinTheta_i, sinTheta_O, Float32(1.0))) / v) + Float32(0.6931)) return Float32((Float32(Float32(exp(1)) * Float32(exp(1))) ^ Float32(Float32(0.5) * Float32(Float32(t_1 * t_1) / Float32(t_0 + t_1)))) / (Float32(Float32(2.0) * v) ^ Float32(t_0 / Float32(Float32(Float32(Float32(Float32(cosTheta_i * cosTheta_O) - fma(sinTheta_O, sinTheta_i, Float32(1.0))) / v) + Float32(0.6931)) + t_0)))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(2 \cdot v\right)\\
t_1 := \frac{cosTheta\_i \cdot cosTheta\_O - \mathsf{fma}\left(sinTheta\_i, sinTheta\_O, 1\right)}{v} + 0.6931\\
\frac{{\left(e \cdot e\right)}^{\left(0.5 \cdot \frac{t\_1 \cdot t\_1}{t\_0 + t\_1}\right)}}{{\left(2 \cdot v\right)}^{\left(\frac{t\_0}{\left(\frac{cosTheta\_i \cdot cosTheta\_O - \mathsf{fma}\left(sinTheta\_O, sinTheta\_i, 1\right)}{v} + 0.6931\right) + t\_0}\right)}}
\end{array}
\end{array}
Initial program 99.7%
Applied rewrites99.7%
Applied rewrites99.7%
lift-exp.f32N/A
lift-/.f32N/A
clear-numN/A
div-invN/A
clear-numN/A
lift-/.f32N/A
Applied rewrites99.7%
lift-pow.f32N/A
sqr-powN/A
pow-prod-downN/A
lower-pow.f32N/A
Applied rewrites99.7%
Final simplification99.7%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(exp
(+
(log (/ 1.0 (* 2.0 v)))
(+
(-
(- (/ (* cosTheta_i cosTheta_O) v) (/ (* sinTheta_O sinTheta_i) v))
(/ 1.0 v))
0.6931))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return expf((logf((1.0f / (2.0f * v))) + (((((cosTheta_i * cosTheta_O) / v) - ((sinTheta_O * sinTheta_i) / v)) - (1.0f / v)) + 0.6931f)));
}
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((log((1.0e0 / (2.0e0 * v))) + (((((costheta_i * costheta_o) / v) - ((sintheta_o * sintheta_i) / v)) - (1.0e0 / v)) + 0.6931e0)))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return exp(Float32(log(Float32(Float32(1.0) / Float32(Float32(2.0) * v))) + Float32(Float32(Float32(Float32(Float32(cosTheta_i * cosTheta_O) / v) - Float32(Float32(sinTheta_O * sinTheta_i) / v)) - Float32(Float32(1.0) / v)) + Float32(0.6931)))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = exp((log((single(1.0) / (single(2.0) * v))) + (((((cosTheta_i * cosTheta_O) / v) - ((sinTheta_O * sinTheta_i) / v)) - (single(1.0) / v)) + single(0.6931)))); end
\begin{array}{l}
\\
e^{\log \left(\frac{1}{2 \cdot v}\right) + \left(\left(\left(\frac{cosTheta\_i \cdot cosTheta\_O}{v} - \frac{sinTheta\_O \cdot sinTheta\_i}{v}\right) - \frac{1}{v}\right) + 0.6931\right)}
\end{array}
Initial program 99.7%
Final simplification99.7%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* (exp (- 0.6931 (* (/ 1.0 v) (fma sinTheta_i sinTheta_O 1.0)))) (/ 0.5 v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return expf((0.6931f - ((1.0f / v) * fmaf(sinTheta_i, sinTheta_O, 1.0f)))) * (0.5f / v);
}
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(exp(Float32(Float32(0.6931) - Float32(Float32(Float32(1.0) / v) * fma(sinTheta_i, sinTheta_O, Float32(1.0))))) * Float32(Float32(0.5) / v)) end
\begin{array}{l}
\\
e^{0.6931 - \frac{1}{v} \cdot \mathsf{fma}\left(sinTheta\_i, sinTheta\_O, 1\right)} \cdot \frac{0.5}{v}
\end{array}
Initial program 99.7%
Taylor expanded in cosTheta_O around 0
+-commutativeN/A
associate--l+N/A
exp-sumN/A
lower-*.f32N/A
rem-exp-logN/A
lower-/.f32N/A
lower-exp.f32N/A
sub-negN/A
lower-+.f32N/A
distribute-neg-inN/A
mul-1-negN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
distribute-neg-fracN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f32N/A
Applied rewrites99.7%
Final simplification99.7%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (/ (* (exp (- 0.6931 (/ (fma sinTheta_O sinTheta_i 1.0) v))) 0.5) v))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return (expf((0.6931f - (fmaf(sinTheta_O, sinTheta_i, 1.0f) / v))) * 0.5f) / v;
}
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(Float32(exp(Float32(Float32(0.6931) - Float32(fma(sinTheta_O, sinTheta_i, Float32(1.0)) / v))) * Float32(0.5)) / v) end
\begin{array}{l}
\\
\frac{e^{0.6931 - \frac{\mathsf{fma}\left(sinTheta\_O, sinTheta\_i, 1\right)}{v}} \cdot 0.5}{v}
\end{array}
Initial program 99.7%
Taylor expanded in cosTheta_O around 0
+-commutativeN/A
associate--l+N/A
exp-sumN/A
lower-*.f32N/A
rem-exp-logN/A
lower-/.f32N/A
lower-exp.f32N/A
sub-negN/A
lower-+.f32N/A
distribute-neg-inN/A
mul-1-negN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
distribute-neg-fracN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f32N/A
Applied rewrites99.7%
Applied rewrites99.5%
Applied rewrites99.7%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* (exp (+ (/ -1.0 v) 0.6931)) (/ 0.5 v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return expf(((-1.0f / v) + 0.6931f)) * (0.5f / 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((((-1.0e0) / v) + 0.6931e0)) * (0.5e0 / v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(exp(Float32(Float32(Float32(-1.0) / v) + Float32(0.6931))) * Float32(Float32(0.5) / v)) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = exp(((single(-1.0) / v) + single(0.6931))) * (single(0.5) / v); end
\begin{array}{l}
\\
e^{\frac{-1}{v} + 0.6931} \cdot \frac{0.5}{v}
\end{array}
Initial program 99.7%
Taylor expanded in cosTheta_O around 0
+-commutativeN/A
associate--l+N/A
exp-sumN/A
lower-*.f32N/A
rem-exp-logN/A
lower-/.f32N/A
lower-exp.f32N/A
sub-negN/A
lower-+.f32N/A
distribute-neg-inN/A
mul-1-negN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
distribute-neg-fracN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f32N/A
Applied rewrites99.7%
Taylor expanded in sinTheta_i around 0
Applied rewrites99.7%
Final simplification99.7%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (exp (+ (/ -1.0 v) 0.6931)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return expf(((-1.0f / v) + 0.6931f));
}
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((((-1.0e0) / v) + 0.6931e0))
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return exp(Float32(Float32(Float32(-1.0) / v) + Float32(0.6931))) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = exp(((single(-1.0) / v) + single(0.6931))); end
\begin{array}{l}
\\
e^{\frac{-1}{v} + 0.6931}
\end{array}
Initial program 99.7%
Taylor expanded in sinTheta_i around 0
lower-exp.f32N/A
associate--l+N/A
+-commutativeN/A
lower-+.f32N/A
associate--l+N/A
lower-+.f32N/A
rem-exp-logN/A
lower-log.f32N/A
rem-exp-logN/A
lower-/.f32N/A
div-subN/A
lower-/.f32N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f3299.7
Applied rewrites99.7%
Taylor expanded in v around 0
Applied rewrites97.4%
Taylor expanded in cosTheta_O around 0
Applied rewrites97.4%
herbie shell --seed 2024240
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:name "HairBSDF, Mp, lower"
:precision binary32
:pre (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))) (and (<= -1.5707964 v) (<= v 0.1)))
(exp (+ (+ (- (- (/ (* cosTheta_i cosTheta_O) v) (/ (* sinTheta_i sinTheta_O) v)) (/ 1.0 v)) 0.6931) (log (/ 1.0 (* 2.0 v))))))