Average Error: 0.2 → 0.2
Time: 5.4s
Precision: binary32
\[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
\[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
\[\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, {\left(e^{{v}^{-0.5}}\right)}^{\left(\frac{-2}{\sqrt{v}}\right)}, u\right)\right), 1\right) \]
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)
\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, {\left(e^{{v}^{-0.5}}\right)}^{\left(\frac{-2}{\sqrt{v}}\right)}, u\right)\right), 1\right)
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
(FPCore (u v)
 :precision binary32
 (fma
  v
  (log (fma (- 1.0 u) (pow (exp (pow v -0.5)) (/ -2.0 (sqrt v))) u))
  1.0))
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 fmaf(v, logf(fmaf((1.0f - u), powf(expf(powf(v, -0.5f)), (-2.0f / sqrtf(v))), u)), 1.0f);
}

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 add-sqr-sqrt_binary320.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{\color{blue}{\sqrt{v} \cdot \sqrt{v}}}}, u\right)\right), 1\right) \]
  4. Applied *-un-lft-identity_binary320.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{\color{blue}{1 \cdot -2}}{\sqrt{v} \cdot \sqrt{v}}}, u\right)\right), 1\right) \]
  5. Applied times-frac_binary320.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\color{blue}{\frac{1}{\sqrt{v}} \cdot \frac{-2}{\sqrt{v}}}}, u\right)\right), 1\right) \]
  6. Applied exp-prod_binary320.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, \color{blue}{{\left(e^{\frac{1}{\sqrt{v}}}\right)}^{\left(\frac{-2}{\sqrt{v}}\right)}}, u\right)\right), 1\right) \]
  7. Applied pow1/2_binary320.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, {\left(e^{\frac{1}{\color{blue}{{v}^{0.5}}}}\right)}^{\left(\frac{-2}{\sqrt{v}}\right)}, u\right)\right), 1\right) \]
  8. Applied pow-flip_binary320.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, {\left(e^{\color{blue}{{v}^{\left(-0.5\right)}}}\right)}^{\left(\frac{-2}{\sqrt{v}}\right)}, u\right)\right), 1\right) \]
  9. Simplified0.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, {\left(e^{{v}^{\color{blue}{-0.5}}}\right)}^{\left(\frac{-2}{\sqrt{v}}\right)}, u\right)\right), 1\right) \]
  10. Final simplification0.2

    \[\leadsto \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, {\left(e^{{v}^{-0.5}}\right)}^{\left(\frac{-2}{\sqrt{v}}\right)}, u\right)\right), 1\right) \]

Reproduce

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