Average Error: 0.2 → 0.2
Time: 18.2s
Precision: binary32
Cost: 13216
\[\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, 2 \cdot \log \left(\sqrt{u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}}\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 (* 2.0 (log (sqrt (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))) 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, (2.0f * logf(sqrtf((u + ((1.0f - u) * expf((-2.0f / v))))))), 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, Float32(Float32(2.0) * log(sqrt(Float32(u + Float32(Float32(Float32(1.0) - u) * exp(Float32(Float32(-2.0) / v))))))), Float32(1.0))
end
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)
\mathsf{fma}\left(v, 2 \cdot \log \left(\sqrt{u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}}\right), 1\right)

Error

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)} \]
    Proof
    (fma.f32 v (log.f32 (fma.f32 (-.f32 1 u) (exp.f32 (/.f32 -2 v)) u)) 1): 0 points increase in error, 0 points decrease in error
    (fma.f32 v (log.f32 (Rewrite<= fma-def_binary32 (+.f32 (*.f32 (-.f32 1 u) (exp.f32 (/.f32 -2 v))) u))) 1): 2 points increase in error, 3 points decrease in error
    (fma.f32 v (log.f32 (Rewrite<= +-commutative_binary32 (+.f32 u (*.f32 (-.f32 1 u) (exp.f32 (/.f32 -2 v)))))) 1): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary32 (+.f32 (*.f32 v (log.f32 (+.f32 u (*.f32 (-.f32 1 u) (exp.f32 (/.f32 -2 v)))))) 1)): 13 points increase in error, 3 points decrease in error
    (Rewrite<= +-commutative_binary32 (+.f32 1 (*.f32 v (log.f32 (+.f32 u (*.f32 (-.f32 1 u) (exp.f32 (/.f32 -2 v)))))))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.2

    \[\leadsto \mathsf{fma}\left(v, \color{blue}{2 \cdot \log \left(\sqrt{\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)}\right)}, 1\right) \]
  4. Taylor expanded in v around 0 0.2

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

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

Alternatives

Alternative 1
Error0.2
Cost9952
\[1 + v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) \]
Alternative 2
Error0.2
Cost9952
\[\mathsf{fma}\left(v, \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right), 1\right) \]
Alternative 3
Error0.2
Cost6816
\[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
Alternative 4
Error2.8
Cost4612
\[\begin{array}{l} t_0 := 2 + u \cdot -2\\ \mathbf{if}\;v \leq 0.23000000417232513:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{2 \cdot t_0 - {t_0}^{2}}{v} + \left(1 + \left(\left(-2 + 2 \cdot u\right) + \frac{u}{v \cdot v} \cdot \left(1.3333333333333333 + u \cdot \left(-4 + u \cdot 2.6666666666666665\right)\right)\right)\right)\\ \end{array} \]
Alternative 5
Error2.9
Cost3556
\[\begin{array}{l} \mathbf{if}\;v \leq 0.30000001192092896:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + v \cdot \left(u \cdot \mathsf{expm1}\left(\frac{2}{v}\right)\right)\\ \end{array} \]
Alternative 6
Error3.0
Cost740
\[\begin{array}{l} \mathbf{if}\;v \leq 0.23000000417232513:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + v \cdot \left(u \cdot \left(\frac{2}{v} + \frac{1}{v \cdot v} \cdot \left(2 + \frac{1.3333333333333333}{v}\right)\right)\right)\\ \end{array} \]
Alternative 7
Error3.1
Cost356
\[\begin{array}{l} \mathbf{if}\;v \leq 0.30000001192092896:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + u \cdot \left(2 + \frac{2}{v}\right)\\ \end{array} \]
Alternative 8
Error3.3
Cost228
\[\begin{array}{l} \mathbf{if}\;v \leq 0.30000001192092896:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1 + 2 \cdot u\\ \end{array} \]
Alternative 9
Error3.5
Cost100
\[\begin{array}{l} \mathbf{if}\;v \leq 0.30000001192092896:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 10
Error30.1
Cost32
\[-1 \]

Error

Reproduce

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