?

Average Error: 0.51% → 0.5%
Time: 18.1s
Precision: binary32
Cost: 13088

?

\[\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, e^{\frac{-2}{v}}, 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) (exp (/ -2.0 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), expf((-2.0f / v)), u)), 1.0f);
}
function code(u, v)
	return Float32(Float32(1.0) + Float32(v * log(Float32(u + Float32(Float32(Float32(1.0) - u) * exp(Float32(Float32(-2.0) / v)))))))
end
function code(u, v)
	return fma(v, log(fma(Float32(Float32(1.0) - u), exp(Float32(Float32(-2.0) / v)), u)), Float32(1.0))
end
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, e^{\frac{-2}{v}}, u\right)\right), 1\right)

Error?

Derivation?

  1. Initial program 0.51

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

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

    [Start]0.51

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

    +-commutative [=>]0.51

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

    fma-def [=>]0.5

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

    +-commutative [=>]0.5

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

    fma-def [=>]0.5

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

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

Alternatives

Alternative 1
Error0.52%
Cost9952
\[1 + v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \]
Alternative 2
Error0.51%
Cost6816
\[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
Alternative 3
Error4.2%
Cost6688
\[1 + v \cdot \log \left(u + e^{\frac{-2}{v}}\right) \]
Alternative 4
Error2.71%
Cost6564
\[\begin{array}{l} \mathbf{if}\;v \leq 0.5:\\ \;\;\;\;\mathsf{fma}\left(v, \log u, 1\right)\\ \mathbf{else}:\\ \;\;\;\;-1 - v \cdot \left(u \cdot \left(1 + \frac{-1}{e^{\frac{-2}{v}}}\right)\right)\\ \end{array} \]
Alternative 5
Error2.71%
Cost3684
\[\begin{array}{l} \mathbf{if}\;v \leq 0.5:\\ \;\;\;\;1 + v \cdot \log u\\ \mathbf{else}:\\ \;\;\;\;-1 - v \cdot \left(u \cdot \left(1 + \frac{-1}{e^{\frac{-2}{v}}}\right)\right)\\ \end{array} \]
Alternative 6
Error2.71%
Cost3556
\[\begin{array}{l} \mathbf{if}\;v \leq 0.5:\\ \;\;\;\;1 + v \cdot \log u\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\frac{2}{v}\right) \cdot \left(v \cdot u\right) + -1\\ \end{array} \]
Alternative 7
Error3.04%
Cost3428
\[\begin{array}{l} t_0 := 1 - u \cdot u\\ \mathbf{if}\;v \leq 0.5:\\ \;\;\;\;1 + v \cdot \log u\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \left(u + -1\right) + 0.5 \cdot \frac{\left(1 - u\right) \cdot 4 + -4 \cdot \frac{\frac{t_0 \cdot t_0}{1 + u}}{1 + u}}{v}\right)\\ \end{array} \]
Alternative 8
Error9.41%
Cost1316
\[\begin{array}{l} \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \left(u + -1\right) + 0.5 \cdot \frac{\left(1 - u\right) \cdot 4 + -4 \cdot \left(\frac{1}{1 + u} + \left(u \cdot \left(u + -1\right) - \frac{u}{\frac{1 + u}{u}}\right)\right)}{v}\right)\\ \end{array} \]
Alternative 9
Error9.41%
Cost1316
\[\begin{array}{l} t_0 := 1 - u \cdot u\\ \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \left(u + -1\right) + 0.5 \cdot \frac{\left(1 - u\right) \cdot 4 + -4 \cdot \frac{\frac{t_0 \cdot t_0}{1 + u}}{1 + u}}{v}\right)\\ \end{array} \]
Alternative 10
Error9.41%
Cost1124
\[\begin{array}{l} \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \left(u + -1\right) + 0.5 \cdot \frac{\left(1 - u\right) \cdot 4 + 4 \cdot \frac{u + -1}{\frac{1 + u}{1 - u \cdot u}}}{v}\right)\\ \end{array} \]
Alternative 11
Error9.41%
Cost932
\[\begin{array}{l} \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \left(u + -1\right) + 0.5 \cdot \frac{\left(1 - u\right) \cdot 4 + -4 \cdot \left(1 + u \cdot \left(u + -2\right)\right)}{v}\right)\\ \end{array} \]
Alternative 12
Error9.56%
Cost868
\[\begin{array}{l} \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \left(u + -1\right) + 0.5 \cdot \frac{\left(1 - u\right) \cdot 4 + -4 \cdot \left(1 + u \cdot -2\right)}{v}\right)\\ \end{array} \]
Alternative 13
Error9.56%
Cost548
\[\begin{array}{l} \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(2 \cdot \left(u + -1\right) - 0.5 \cdot \frac{u \cdot -4}{v}\right)\\ \end{array} \]
Alternative 14
Error9.56%
Cost484
\[\begin{array}{l} \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{\frac{1}{u + \frac{u}{v}}} + -1\\ \end{array} \]
Alternative 15
Error9.56%
Cost356
\[\begin{array}{l} \mathbf{if}\;v \leq 0.15000000596046448:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(u + \frac{u}{v}\right) + -1\\ \end{array} \]
Alternative 16
Error10.19%
Cost228
\[\begin{array}{l} \mathbf{if}\;v \leq 0.20000000298023224:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 - u \cdot -2\\ \end{array} \]
Alternative 17
Error10.86%
Cost100
\[\begin{array}{l} \mathbf{if}\;v \leq 0.20000000298023224:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 18
Error94%
Cost32
\[-1 \]

Error

Reproduce?

herbie shell --seed 2023088 
(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))))))))