
(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 4 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
(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}
Initial program 99.6%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (let* ((t_0 (/ (* sinTheta_i sinTheta_O) v))) (- t_0 t_0)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
float t_0 = (sinTheta_i * sinTheta_O) / v;
return t_0 - t_0;
}
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
real(4) :: t_0
t_0 = (sintheta_i * sintheta_o) / v
code = t_0 - t_0
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) t_0 = Float32(Float32(sinTheta_i * sinTheta_O) / v) return Float32(t_0 - t_0) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) t_0 = (sinTheta_i * sinTheta_O) / v; tmp = t_0 - t_0; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{sinTheta\_i \cdot sinTheta\_O}{v}\\
t\_0 - t\_0
\end{array}
\end{array}
Initial program 99.6%
Taylor expanded in cosTheta_i around 0
Applied rewrites4.5%
Taylor expanded in cosTheta_i around 0
Applied rewrites17.5%
Taylor expanded in cosTheta_i around 0
Applied rewrites21.1%
Taylor expanded in cosTheta_i around 0
Applied rewrites96.5%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
:precision binary32
(if (<= (* sinTheta_i sinTheta_O) -9.99994610111476e-41)
(* cosTheta_i cosTheta_O)
(if (<= (* sinTheta_i sinTheta_O) 2.0038568039844884e-43)
(* sinTheta_i sinTheta_O)
(* cosTheta_i cosTheta_O))))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
float tmp;
if ((sinTheta_i * sinTheta_O) <= -9.99994610111476e-41f) {
tmp = cosTheta_i * cosTheta_O;
} else if ((sinTheta_i * sinTheta_O) <= 2.0038568039844884e-43f) {
tmp = sinTheta_i * sinTheta_O;
} else {
tmp = cosTheta_i * cosTheta_O;
}
return tmp;
}
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
real(4) :: tmp
if ((sintheta_i * sintheta_o) <= (-9.99994610111476e-41)) then
tmp = costheta_i * costheta_o
else if ((sintheta_i * sintheta_o) <= 2.0038568039844884e-43) then
tmp = sintheta_i * sintheta_o
else
tmp = costheta_i * costheta_o
end if
code = tmp
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = Float32(0.0) if (Float32(sinTheta_i * sinTheta_O) <= Float32(-9.99994610111476e-41)) tmp = Float32(cosTheta_i * cosTheta_O); elseif (Float32(sinTheta_i * sinTheta_O) <= Float32(2.0038568039844884e-43)) tmp = Float32(sinTheta_i * sinTheta_O); else tmp = Float32(cosTheta_i * cosTheta_O); end return tmp end
function tmp_2 = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = single(0.0); if ((sinTheta_i * sinTheta_O) <= single(-9.99994610111476e-41)) tmp = cosTheta_i * cosTheta_O; elseif ((sinTheta_i * sinTheta_O) <= single(2.0038568039844884e-43)) tmp = sinTheta_i * sinTheta_O; else tmp = cosTheta_i * cosTheta_O; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;sinTheta\_i \cdot sinTheta\_O \leq -9.99994610111476 \cdot 10^{-41}:\\
\;\;\;\;cosTheta\_i \cdot cosTheta\_O\\
\mathbf{elif}\;sinTheta\_i \cdot sinTheta\_O \leq 2.0038568039844884 \cdot 10^{-43}:\\
\;\;\;\;sinTheta\_i \cdot sinTheta\_O\\
\mathbf{else}:\\
\;\;\;\;cosTheta\_i \cdot cosTheta\_O\\
\end{array}
\end{array}
if (*.f32 sinTheta_i sinTheta_O) < -9.99995e-41 or 2.00386e-43 < (*.f32 sinTheta_i sinTheta_O) Initial program 99.5%
Taylor expanded in cosTheta_i around 0
Applied rewrites4.5%
Taylor expanded in cosTheta_i around 0
Applied rewrites39.0%
Taylor expanded in cosTheta_i around 0
Applied rewrites50.9%
if -9.99995e-41 < (*.f32 sinTheta_i sinTheta_O) < 2.00386e-43Initial program 99.7%
Taylor expanded in cosTheta_i around 0
Applied rewrites4.6%
Taylor expanded in cosTheta_i around 0
Applied rewrites30.2%
Taylor expanded in cosTheta_i around 0
Applied rewrites93.4%
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v) :precision binary32 (* cosTheta_i cosTheta_O))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
return 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 = costheta_i * costheta_o
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) return Float32(cosTheta_i * cosTheta_O) end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v) tmp = cosTheta_i * cosTheta_O; end
\begin{array}{l}
\\
cosTheta\_i \cdot cosTheta\_O
\end{array}
Initial program 99.6%
Taylor expanded in cosTheta_i around 0
Applied rewrites4.5%
Taylor expanded in cosTheta_i around 0
Applied rewrites36.9%
Taylor expanded in cosTheta_i around 0
Applied rewrites48.3%
herbie shell --seed 2024321
(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))))))