HairBSDF, sample_f, cosTheta

Percentage Accurate: 99.5% → 99.5%
Time: 9.3s
Alternatives: 5
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 5 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, 1.0× speedup?

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

\\
\log \left(e^{\frac{-2}{v}} \cdot \left(1 - u\right) + u\right) \cdot v + 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. Final simplification99.7%

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

Alternative 2: 47.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{2}{v \cdot v}\\ \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;\log \left(\mathsf{fma}\left(e^{\frac{-2}{v}}, 1 - u, u\right)\right) \cdot v + 1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left(\frac{\left(\frac{2}{v} + \frac{4}{v \cdot v}\right) - t\_0}{u} - t\_0\right) - \frac{\frac{2}{u \cdot u}}{v}\right) \cdot \left(u \cdot u\right)\right) \cdot v + 1\\ \end{array} \end{array} \]
(FPCore (u v)
 :precision binary32
 (let* ((t_0 (/ 2.0 (* v v))))
   (if (<= v 0.10000000149011612)
     (+ (* (log (fma (exp (/ -2.0 v)) (- 1.0 u) u)) v) 1.0)
     (+
      (*
       (*
        (-
         (- (/ (- (+ (/ 2.0 v) (/ 4.0 (* v v))) t_0) u) t_0)
         (/ (/ 2.0 (* u u)) v))
        (* u u))
       v)
      1.0))))
float code(float u, float v) {
	float t_0 = 2.0f / (v * v);
	float tmp;
	if (v <= 0.10000000149011612f) {
		tmp = (logf(fmaf(expf((-2.0f / v)), (1.0f - u), u)) * v) + 1.0f;
	} else {
		tmp = ((((((((2.0f / v) + (4.0f / (v * v))) - t_0) / u) - t_0) - ((2.0f / (u * u)) / v)) * (u * u)) * v) + 1.0f;
	}
	return tmp;
}
function code(u, v)
	t_0 = Float32(Float32(2.0) / Float32(v * v))
	tmp = Float32(0.0)
	if (v <= Float32(0.10000000149011612))
		tmp = Float32(Float32(log(fma(exp(Float32(Float32(-2.0) / v)), Float32(Float32(1.0) - u), u)) * v) + Float32(1.0));
	else
		tmp = Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(2.0) / v) + Float32(Float32(4.0) / Float32(v * v))) - t_0) / u) - t_0) - Float32(Float32(Float32(2.0) / Float32(u * u)) / v)) * Float32(u * u)) * v) + Float32(1.0));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{2}{v \cdot v}\\
\mathbf{if}\;v \leq 0.10000000149011612:\\
\;\;\;\;\log \left(\mathsf{fma}\left(e^{\frac{-2}{v}}, 1 - u, u\right)\right) \cdot v + 1\\

\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\frac{\left(\frac{2}{v} + \frac{4}{v \cdot v}\right) - t\_0}{u} - t\_0\right) - \frac{\frac{2}{u \cdot u}}{v}\right) \cdot \left(u \cdot u\right)\right) \cdot v + 1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if v < 0.100000001

    1. Initial program 100.0%

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

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

    if 0.100000001 < v

    1. Initial program 95.5%

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

      \[\leadsto 1 + v \cdot \color{blue}{\left(-1 \cdot \frac{\frac{-1}{2} \cdot \frac{-4 \cdot {\left(1 - u\right)}^{2} + 4 \cdot \left(1 - u\right)}{v} + 2 \cdot \left(1 - u\right)}{v}\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto 1 + v \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{\frac{-1}{2} \cdot \frac{-4 \cdot {\left(1 - u\right)}^{2} + 4 \cdot \left(1 - u\right)}{v} + 2 \cdot \left(1 - u\right)}{v}\right)\right)} \]
      2. distribute-neg-frac2N/A

        \[\leadsto 1 + v \cdot \color{blue}{\frac{\frac{-1}{2} \cdot \frac{-4 \cdot {\left(1 - u\right)}^{2} + 4 \cdot \left(1 - u\right)}{v} + 2 \cdot \left(1 - u\right)}{\mathsf{neg}\left(v\right)}} \]
      3. lower-/.f32N/A

        \[\leadsto 1 + v \cdot \color{blue}{\frac{\frac{-1}{2} \cdot \frac{-4 \cdot {\left(1 - u\right)}^{2} + 4 \cdot \left(1 - u\right)}{v} + 2 \cdot \left(1 - u\right)}{\mathsf{neg}\left(v\right)}} \]
    5. Applied rewrites9.0%

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

        \[\leadsto 1 + v \cdot \frac{\mathsf{fma}\left(2, 1 - u, \frac{\mathsf{fma}\left(\left(1 - u\right) \cdot 2, 1 - u, -2 \cdot \left(1 - u\right)\right)}{v}\right)}{-v} \]
      2. Taylor expanded in u around inf

        \[\leadsto 1 + v \cdot \left({u}^{2} \cdot \color{blue}{\left(-1 \cdot \frac{2 \cdot \frac{1}{{v}^{2}} - \left(2 \cdot \frac{1}{v} + 4 \cdot \frac{1}{{v}^{2}}\right)}{u} - \left(2 \cdot \frac{1}{{v}^{2}} + \frac{2}{{u}^{2} \cdot v}\right)\right)}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites50.5%

          \[\leadsto 1 + v \cdot \left(\left(\left(\frac{\frac{2}{v \cdot v} - \left(\frac{4}{v \cdot v} + \frac{2}{v}\right)}{-u} - \frac{2}{v \cdot v}\right) - \frac{\frac{2}{u \cdot u}}{v}\right) \cdot \color{blue}{\left(u \cdot u\right)}\right) \]
      4. Recombined 2 regimes into one program.
      5. Final simplification96.0%

        \[\leadsto \begin{array}{l} \mathbf{if}\;v \leq 0.10000000149011612:\\ \;\;\;\;\log \left(\mathsf{fma}\left(e^{\frac{-2}{v}}, 1 - u, u\right)\right) \cdot v + 1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left(\frac{\left(\frac{2}{v} + \frac{4}{v \cdot v}\right) - \frac{2}{v \cdot v}}{u} - \frac{2}{v \cdot v}\right) - \frac{\frac{2}{u \cdot u}}{v}\right) \cdot \left(u \cdot u\right)\right) \cdot v + 1\\ \end{array} \]
      6. Add Preprocessing

      Alternative 3: 94.4% accurate, 1.0× speedup?

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

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{e^{\frac{-2}{v}}}\right) \]
        2. *-lft-identityN/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\color{blue}{1 \cdot \frac{-2}{v}}}\right) \]
        3. exp-prodN/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{{\left(e^{1}\right)}^{\left(\frac{-2}{v}\right)}}\right) \]
        4. lift-/.f32N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left(e^{1}\right)}^{\color{blue}{\left(\frac{-2}{v}\right)}}\right) \]
        5. clear-numN/A

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

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left(e^{1}\right)}^{\left(\frac{1}{\color{blue}{\frac{\mathsf{neg}\left(v\right)}{\mathsf{neg}\left(-2\right)}}}\right)}\right) \]
        7. associate-/r/N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left(e^{1}\right)}^{\color{blue}{\left(\frac{1}{\mathsf{neg}\left(v\right)} \cdot \left(\mathsf{neg}\left(-2\right)\right)\right)}}\right) \]
        8. pow-unpowN/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{{\left({\left(e^{1}\right)}^{\left(\frac{1}{\mathsf{neg}\left(v\right)}\right)}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}}\right) \]
        9. lower-pow.f32N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{{\left({\left(e^{1}\right)}^{\left(\frac{1}{\mathsf{neg}\left(v\right)}\right)}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}}\right) \]
        10. lower-pow.f32N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\color{blue}{\left({\left(e^{1}\right)}^{\left(\frac{1}{\mathsf{neg}\left(v\right)}\right)}\right)}}^{\left(\mathsf{neg}\left(-2\right)\right)}\right) \]
        11. exp-1-eN/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left({\color{blue}{\mathsf{E}\left(\right)}}^{\left(\frac{1}{\mathsf{neg}\left(v\right)}\right)}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}\right) \]
        12. lower-E.f32N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left({\color{blue}{\mathsf{E}\left(\right)}}^{\left(\frac{1}{\mathsf{neg}\left(v\right)}\right)}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}\right) \]
        13. neg-mul-1N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left({\mathsf{E}\left(\right)}^{\left(\frac{1}{\color{blue}{-1 \cdot v}}\right)}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}\right) \]
        14. associate-/r*N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left({\mathsf{E}\left(\right)}^{\color{blue}{\left(\frac{\frac{1}{-1}}{v}\right)}}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}\right) \]
        15. metadata-evalN/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left({\mathsf{E}\left(\right)}^{\left(\frac{\color{blue}{-1}}{v}\right)}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}\right) \]
        16. lower-/.f32N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left({\mathsf{E}\left(\right)}^{\color{blue}{\left(\frac{-1}{v}\right)}}\right)}^{\left(\mathsf{neg}\left(-2\right)\right)}\right) \]
        17. metadata-eval99.6

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot {\left({\mathsf{E}\left(\right)}^{\left(\frac{-1}{v}\right)}\right)}^{\color{blue}{2}}\right) \]
      4. Applied rewrites99.6%

        \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{{\left({\mathsf{E}\left(\right)}^{\left(\frac{-1}{v}\right)}\right)}^{2}}\right) \]
      5. Taylor expanded in v around -inf

        \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{\left(1 + -1 \cdot \frac{-1 \cdot \frac{-1 \cdot \frac{\frac{1}{3} \cdot {\log \mathsf{E}\left(\right)}^{3} + {\log \mathsf{E}\left(\right)}^{3}}{v} + 2 \cdot {\log \mathsf{E}\left(\right)}^{2}}{v} + 2 \cdot \log \mathsf{E}\left(\right)}{v}\right)}\right) \]
      6. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \left(1 + \color{blue}{\left(\mathsf{neg}\left(\frac{-1 \cdot \frac{-1 \cdot \frac{\frac{1}{3} \cdot {\log \mathsf{E}\left(\right)}^{3} + {\log \mathsf{E}\left(\right)}^{3}}{v} + 2 \cdot {\log \mathsf{E}\left(\right)}^{2}}{v} + 2 \cdot \log \mathsf{E}\left(\right)}{v}\right)\right)}\right)\right) \]
        2. unsub-negN/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{\left(1 - \frac{-1 \cdot \frac{-1 \cdot \frac{\frac{1}{3} \cdot {\log \mathsf{E}\left(\right)}^{3} + {\log \mathsf{E}\left(\right)}^{3}}{v} + 2 \cdot {\log \mathsf{E}\left(\right)}^{2}}{v} + 2 \cdot \log \mathsf{E}\left(\right)}{v}\right)}\right) \]
        3. lower--.f32N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{\left(1 - \frac{-1 \cdot \frac{-1 \cdot \frac{\frac{1}{3} \cdot {\log \mathsf{E}\left(\right)}^{3} + {\log \mathsf{E}\left(\right)}^{3}}{v} + 2 \cdot {\log \mathsf{E}\left(\right)}^{2}}{v} + 2 \cdot \log \mathsf{E}\left(\right)}{v}\right)}\right) \]
        4. lower-/.f32N/A

          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \left(1 - \color{blue}{\frac{-1 \cdot \frac{-1 \cdot \frac{\frac{1}{3} \cdot {\log \mathsf{E}\left(\right)}^{3} + {\log \mathsf{E}\left(\right)}^{3}}{v} + 2 \cdot {\log \mathsf{E}\left(\right)}^{2}}{v} + 2 \cdot \log \mathsf{E}\left(\right)}{v}}\right)\right) \]
      7. Applied rewrites2.3%

        \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right) \cdot \color{blue}{\left(1 - \frac{2 - \frac{2 - \frac{1.3333333333333333}{v}}{v}}{v}\right)}\right) \]
      8. Taylor expanded in u around -inf

        \[\leadsto 1 + v \cdot \log \color{blue}{\left(-1 \cdot \left(u \cdot \left(\left(-1 \cdot \frac{{\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}}{u} + {\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}\right) - 1\right)\right)\right)} \]
      9. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto 1 + v \cdot \log \color{blue}{\left(\mathsf{neg}\left(u \cdot \left(\left(-1 \cdot \frac{{\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}}{u} + {\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}\right) - 1\right)\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto 1 + v \cdot \log \left(\mathsf{neg}\left(\color{blue}{\left(\left(-1 \cdot \frac{{\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}}{u} + {\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}\right) - 1\right) \cdot u}\right)\right) \]
        3. distribute-rgt-neg-inN/A

          \[\leadsto 1 + v \cdot \log \color{blue}{\left(\left(\left(-1 \cdot \frac{{\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}}{u} + {\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}\right) - 1\right) \cdot \left(\mathsf{neg}\left(u\right)\right)\right)} \]
        4. mul-1-negN/A

          \[\leadsto 1 + v \cdot \log \left(\left(\left(-1 \cdot \frac{{\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}}{u} + {\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}\right) - 1\right) \cdot \color{blue}{\left(-1 \cdot u\right)}\right) \]
        5. lower-*.f32N/A

          \[\leadsto 1 + v \cdot \log \color{blue}{\left(\left(\left(-1 \cdot \frac{{\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}}{u} + {\left(e^{-1 \cdot \frac{\log \mathsf{E}\left(\right)}{v}}\right)}^{2}\right) - 1\right) \cdot \left(-1 \cdot u\right)\right)} \]
      10. Applied rewrites99.6%

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

        \[\leadsto 1 + v \cdot \log \left(\left(e^{\frac{-2}{v}} - 1\right) \cdot \left(-u\right)\right) \]
      12. Step-by-step derivation
        1. Applied rewrites94.6%

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

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

        Alternative 4: 86.7% accurate, 231.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 v around 0

          \[\leadsto \color{blue}{1} \]
        4. Step-by-step derivation
          1. Applied rewrites88.8%

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

          Alternative 5: 5.8% accurate, 231.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

            \[\leadsto \color{blue}{-1} \]
          4. Step-by-step derivation
            1. Applied rewrites5.2%

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

            Reproduce

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