HairBSDF, sample_f, cosTheta

Percentage Accurate: 99.5% → 99.5%
Time: 12.9s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
\[\begin{array}{l} \\ 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
float code(float u, float v) {
	return 1.0f + (v * logf((u + ((1.0f - u) * expf((-2.0f / v))))));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log((u + ((1.0e0 - u) * exp(((-2.0e0) / v))))))
end function
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 tmp = code(u, v)
	tmp = single(1.0) + (v * log((u + ((single(1.0) - u) * exp((single(-2.0) / v))))));
end
\begin{array}{l}

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
float code(float u, float v) {
	return 1.0f + (v * logf((u + ((1.0f - u) * expf((-2.0f / v))))));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log((u + ((1.0e0 - u) * exp(((-2.0e0) / v))))))
end function
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 tmp = code(u, v)
	tmp = single(1.0) + (v * log((u + ((single(1.0) - u) * exp((single(-2.0) / v))))));
end
\begin{array}{l}

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

Alternative 1: 99.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right), 1\right) \end{array} \]
(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 fmaf(v, logf(fmaf((1.0f - u), expf((-2.0f / v)), u)), 1.0f);
}
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
\begin{array}{l}

\\
\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right), 1\right)
\end{array}
Derivation
  1. Initial program 99.7%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Step-by-step derivation
    1. +-commutative99.7%

      \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
    2. fma-define99.7%

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

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

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

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

Alternative 2: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 + v \cdot \log \left(u \cdot \left(1 + e^{\frac{-2}{v}} \cdot \left(-1 + \frac{1}{u}\right)\right)\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (* u (+ 1.0 (* (exp (/ -2.0 v)) (+ -1.0 (/ 1.0 u)))))))))
float code(float u, float v) {
	return 1.0f + (v * logf((u * (1.0f + (expf((-2.0f / v)) * (-1.0f + (1.0f / u)))))));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log((u * (1.0e0 + (exp(((-2.0e0) / v)) * ((-1.0e0) + (1.0e0 / u)))))))
end function
function code(u, v)
	return Float32(Float32(1.0) + Float32(v * log(Float32(u * Float32(Float32(1.0) + Float32(exp(Float32(Float32(-2.0) / v)) * Float32(Float32(-1.0) + Float32(Float32(1.0) / u))))))))
end
function tmp = code(u, v)
	tmp = single(1.0) + (v * log((u * (single(1.0) + (exp((single(-2.0) / v)) * (single(-1.0) + (single(1.0) / u)))))));
end
\begin{array}{l}

\\
1 + v \cdot \log \left(u \cdot \left(1 + e^{\frac{-2}{v}} \cdot \left(-1 + \frac{1}{u}\right)\right)\right)
\end{array}
Derivation
  1. Initial program 99.7%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Step-by-step derivation
    1. +-commutative99.7%

      \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
    2. fma-define99.7%

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right), 1\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. fma-undefine99.8%

      \[\leadsto \color{blue}{v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) + 1} \]
  6. Applied egg-rr99.8%

    \[\leadsto \color{blue}{v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) + 1} \]
  7. Taylor expanded in u around inf 99.8%

    \[\leadsto v \cdot \log \color{blue}{\left(u \cdot \left(1 + \left(-1 \cdot e^{\frac{-2}{v}} + \frac{e^{\frac{-2}{v}}}{u}\right)\right)\right)} + 1 \]
  8. Step-by-step derivation
    1. *-commutative99.8%

      \[\leadsto v \cdot \log \left(u \cdot \left(1 + \left(\color{blue}{e^{\frac{-2}{v}} \cdot -1} + \frac{e^{\frac{-2}{v}}}{u}\right)\right)\right) + 1 \]
    2. *-rgt-identity99.8%

      \[\leadsto v \cdot \log \left(u \cdot \left(1 + \left(e^{\frac{-2}{v}} \cdot -1 + \frac{\color{blue}{e^{\frac{-2}{v}} \cdot 1}}{u}\right)\right)\right) + 1 \]
    3. associate-/l*99.8%

      \[\leadsto v \cdot \log \left(u \cdot \left(1 + \left(e^{\frac{-2}{v}} \cdot -1 + \color{blue}{e^{\frac{-2}{v}} \cdot \frac{1}{u}}\right)\right)\right) + 1 \]
    4. distribute-lft-out99.8%

      \[\leadsto v \cdot \log \left(u \cdot \left(1 + \color{blue}{e^{\frac{-2}{v}} \cdot \left(-1 + \frac{1}{u}\right)}\right)\right) + 1 \]
  9. Simplified99.8%

    \[\leadsto v \cdot \log \color{blue}{\left(u \cdot \left(1 + e^{\frac{-2}{v}} \cdot \left(-1 + \frac{1}{u}\right)\right)\right)} + 1 \]
  10. Final simplification99.8%

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

Alternative 3: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (+ u (* (- 1.0 u) (exp (/ -2.0 v))))))))
float code(float u, float v) {
	return 1.0f + (v * logf((u + ((1.0f - u) * expf((-2.0f / v))))));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log((u + ((1.0e0 - u) * exp(((-2.0e0) / v))))))
end function
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 tmp = code(u, v)
	tmp = single(1.0) + (v * log((u + ((single(1.0) - u) * exp((single(-2.0) / v))))));
end
\begin{array}{l}

\\
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)
\end{array}
Derivation
  1. Initial program 99.7%

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

Alternative 4: 94.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 + v \cdot \log \left(\mathsf{expm1}\left(\frac{-2}{v}\right) \cdot \left(-u\right)\right) \end{array} \]
(FPCore (u v)
 :precision binary32
 (+ 1.0 (* v (log (* (expm1 (/ -2.0 v)) (- u))))))
float code(float u, float v) {
	return 1.0f + (v * logf((expm1f((-2.0f / v)) * -u)));
}
function code(u, v)
	return Float32(Float32(1.0) + Float32(v * log(Float32(expm1(Float32(Float32(-2.0) / v)) * Float32(-u)))))
end
\begin{array}{l}

\\
1 + v \cdot \log \left(\mathsf{expm1}\left(\frac{-2}{v}\right) \cdot \left(-u\right)\right)
\end{array}
Derivation
  1. Initial program 99.7%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Step-by-step derivation
    1. +-commutative99.7%

      \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
    2. fma-define99.7%

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right), 1\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. fma-undefine99.8%

      \[\leadsto \color{blue}{v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) + 1} \]
  6. Applied egg-rr99.8%

    \[\leadsto \color{blue}{v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) + 1} \]
  7. Taylor expanded in u around inf 97.2%

    \[\leadsto v \cdot \log \color{blue}{\left(u \cdot \left(1 + -1 \cdot e^{\frac{-2}{v}}\right)\right)} + 1 \]
  8. Step-by-step derivation
    1. *-commutative97.2%

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

      \[\leadsto v \cdot \log \left(\color{blue}{\left(-1 \cdot e^{\frac{-2}{v}} + 1\right)} \cdot u\right) + 1 \]
    3. mul-1-neg97.2%

      \[\leadsto v \cdot \log \left(\left(\color{blue}{\left(-e^{\frac{-2}{v}}\right)} + 1\right) \cdot u\right) + 1 \]
    4. metadata-eval97.2%

      \[\leadsto v \cdot \log \left(\left(\left(-e^{\frac{-2}{v}}\right) + \color{blue}{\left(--1\right)}\right) \cdot u\right) + 1 \]
    5. distribute-neg-in97.2%

      \[\leadsto v \cdot \log \left(\color{blue}{\left(-\left(e^{\frac{-2}{v}} + -1\right)\right)} \cdot u\right) + 1 \]
    6. metadata-eval97.2%

      \[\leadsto v \cdot \log \left(\left(-\left(e^{\frac{-2}{v}} + \color{blue}{\left(-1\right)}\right)\right) \cdot u\right) + 1 \]
    7. sub-neg97.2%

      \[\leadsto v \cdot \log \left(\left(-\color{blue}{\left(e^{\frac{-2}{v}} - 1\right)}\right) \cdot u\right) + 1 \]
    8. distribute-lft-neg-in97.2%

      \[\leadsto v \cdot \log \color{blue}{\left(-\left(e^{\frac{-2}{v}} - 1\right) \cdot u\right)} + 1 \]
    9. distribute-rgt-neg-in97.2%

      \[\leadsto v \cdot \log \color{blue}{\left(\left(e^{\frac{-2}{v}} - 1\right) \cdot \left(-u\right)\right)} + 1 \]
    10. expm1-define97.2%

      \[\leadsto v \cdot \log \left(\color{blue}{\mathsf{expm1}\left(\frac{-2}{v}\right)} \cdot \left(-u\right)\right) + 1 \]
  9. Simplified97.2%

    \[\leadsto v \cdot \log \color{blue}{\left(\mathsf{expm1}\left(\frac{-2}{v}\right) \cdot \left(-u\right)\right)} + 1 \]
  10. Final simplification97.2%

    \[\leadsto 1 + v \cdot \log \left(\mathsf{expm1}\left(\frac{-2}{v}\right) \cdot \left(-u\right)\right) \]
  11. Add Preprocessing

Alternative 5: 87.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ 1 + v \cdot \log \left(\frac{u \cdot 2}{v}\right) \end{array} \]
(FPCore (u v) :precision binary32 (+ 1.0 (* v (log (/ (* u 2.0) v)))))
float code(float u, float v) {
	return 1.0f + (v * logf(((u * 2.0f) / v)));
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0 + (v * log(((u * 2.0e0) / v)))
end function
function code(u, v)
	return Float32(Float32(1.0) + Float32(v * log(Float32(Float32(u * Float32(2.0)) / v))))
end
function tmp = code(u, v)
	tmp = single(1.0) + (v * log(((u * single(2.0)) / v)));
end
\begin{array}{l}

\\
1 + v \cdot \log \left(\frac{u \cdot 2}{v}\right)
\end{array}
Derivation
  1. Initial program 99.7%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Step-by-step derivation
    1. +-commutative99.7%

      \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
    2. fma-define99.7%

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right), 1\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in u around inf 97.2%

    \[\leadsto \mathsf{fma}\left(v, \log \color{blue}{\left(u \cdot \left(1 + -1 \cdot e^{\frac{-2}{v}}\right)\right)}, 1\right) \]
  6. Step-by-step derivation
    1. *-commutative97.2%

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

      \[\leadsto v \cdot \log \left(\color{blue}{\left(-1 \cdot e^{\frac{-2}{v}} + 1\right)} \cdot u\right) + 1 \]
    3. mul-1-neg97.2%

      \[\leadsto v \cdot \log \left(\left(\color{blue}{\left(-e^{\frac{-2}{v}}\right)} + 1\right) \cdot u\right) + 1 \]
    4. metadata-eval97.2%

      \[\leadsto v \cdot \log \left(\left(\left(-e^{\frac{-2}{v}}\right) + \color{blue}{\left(--1\right)}\right) \cdot u\right) + 1 \]
    5. distribute-neg-in97.2%

      \[\leadsto v \cdot \log \left(\color{blue}{\left(-\left(e^{\frac{-2}{v}} + -1\right)\right)} \cdot u\right) + 1 \]
    6. metadata-eval97.2%

      \[\leadsto v \cdot \log \left(\left(-\left(e^{\frac{-2}{v}} + \color{blue}{\left(-1\right)}\right)\right) \cdot u\right) + 1 \]
    7. sub-neg97.2%

      \[\leadsto v \cdot \log \left(\left(-\color{blue}{\left(e^{\frac{-2}{v}} - 1\right)}\right) \cdot u\right) + 1 \]
    8. distribute-lft-neg-in97.2%

      \[\leadsto v \cdot \log \color{blue}{\left(-\left(e^{\frac{-2}{v}} - 1\right) \cdot u\right)} + 1 \]
    9. distribute-rgt-neg-in97.2%

      \[\leadsto v \cdot \log \color{blue}{\left(\left(e^{\frac{-2}{v}} - 1\right) \cdot \left(-u\right)\right)} + 1 \]
    10. expm1-define97.2%

      \[\leadsto v \cdot \log \left(\color{blue}{\mathsf{expm1}\left(\frac{-2}{v}\right)} \cdot \left(-u\right)\right) + 1 \]
  7. Simplified97.2%

    \[\leadsto \mathsf{fma}\left(v, \log \color{blue}{\left(\mathsf{expm1}\left(\frac{-2}{v}\right) \cdot \left(-u\right)\right)}, 1\right) \]
  8. Taylor expanded in v around inf 90.1%

    \[\leadsto \mathsf{fma}\left(v, \log \color{blue}{\left(2 \cdot \frac{u}{v}\right)}, 1\right) \]
  9. Step-by-step derivation
    1. fma-undefine90.1%

      \[\leadsto \color{blue}{v \cdot \log \left(2 \cdot \frac{u}{v}\right) + 1} \]
    2. associate-*r/90.1%

      \[\leadsto v \cdot \log \color{blue}{\left(\frac{2 \cdot u}{v}\right)} + 1 \]
  10. Applied egg-rr90.1%

    \[\leadsto \color{blue}{v \cdot \log \left(\frac{2 \cdot u}{v}\right) + 1} \]
  11. Final simplification90.1%

    \[\leadsto 1 + v \cdot \log \left(\frac{u \cdot 2}{v}\right) \]
  12. Add Preprocessing

Alternative 6: 87.0% accurate, 213.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (u v) :precision binary32 1.0)
float code(float u, float v) {
	return 1.0f;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = 1.0e0
end function
function code(u, v)
	return Float32(1.0)
end
function tmp = code(u, v)
	tmp = single(1.0);
end
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 99.7%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Step-by-step derivation
    1. +-commutative99.7%

      \[\leadsto \color{blue}{v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) + 1} \]
    2. fma-define99.7%

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right), 1\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. fma-undefine99.8%

      \[\leadsto \color{blue}{v \cdot \log \left(\mathsf{fma}\left(1 - u, e^{\frac{-2}{v}}, u\right)\right) + 1} \]
  6. Applied egg-rr99.8%

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

    \[\leadsto \color{blue}{1} \]
  8. Add Preprocessing

Alternative 7: 6.0% accurate, 213.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (u v) :precision binary32 -1.0)
float code(float u, float v) {
	return -1.0f;
}
real(4) function code(u, v)
    real(4), intent (in) :: u
    real(4), intent (in) :: v
    code = -1.0e0
end function
function code(u, v)
	return Float32(-1.0)
end
function tmp = code(u, v)
	tmp = single(-1.0);
end
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 99.7%

    \[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
  2. Add Preprocessing
  3. Taylor expanded in u around 0 4.7%

    \[\leadsto \color{blue}{-1} \]
  4. Add Preprocessing

Reproduce

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