Average Error: 0.2 → 0.2
Time: 19.4s
Precision: binary32
\[10^{-5} \leq u \land u \leq 1 \land 0 \leq v \land v \leq 109.746574\]
\[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
\[1 + \mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)\right)\right) \]
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)
1 + \mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)\right)\right)
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
(FPCore (u v)
 :precision binary32
 (+ 1.0 (log1p (expm1 (* v (log (fma (- 1.0 u) (exp (/ -2.0 v)) u)))))))
float code(float u, float v) {
	return 1.0f + (v * logf(u + ((1.0f - u) * expf(-2.0f / v))));
}
float code(float u, float v) {
	return 1.0f + log1pf(expm1f(v * logf(fmaf((1.0f - u), expf(-2.0f / v), u))));
}

Error

Bits error versus u

Bits error versus v

Derivation

  1. Initial program 0.2

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right), 1\right)} \]
  3. Applied fma-udef_binary320.2

    \[\leadsto \color{blue}{v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) + 1} \]
  4. Applied log1p-expm1-u_binary320.2

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)\right)\right)} + 1 \]
  5. Final simplification0.2

    \[\leadsto 1 + \mathsf{log1p}\left(\mathsf{expm1}\left(v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right)\right)\right) \]

Reproduce

herbie shell --seed 2021225 
(FPCore (u v)
  :name "HairBSDF, sample_f, cosTheta"
  :precision binary32
  :pre (and (<= 1e-5 u 1.0) (<= 0.0 v 109.746574))
  (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))