HairBSDF, sample_f, cosTheta

Percentage Accurate: 99.5% → 99.5%
Time: 4.1s
Alternatives: 15
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)\]
\[1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right) \]
(FPCore (u v)
  :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))))))))
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)
use fmin_fmax_functions
    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
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)

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 15 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?

\[\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) \]
(FPCore (u v)
  :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))))))))
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)
use fmin_fmax_functions
    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
1 + v \cdot \log \left(u + \left(1 - u\right) \cdot e^{\frac{-2}{v}}\right)

Alternative 1: 99.5% accurate, 1.0× speedup?

\[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
\[\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(e^{\frac{-2}{v}}, 1 - u, u\right)\right), 1\right) \]
(FPCore (u v)
  :precision binary32
  :pre (and (and (<= 1e-5 u) (<= u 1.0))
     (and (<= 0.0 v) (<= v 109.746574)))
  (fma v (log (fma (exp (/ -2.0 v)) (- 1.0 u) u)) 1.0))
float code(float u, float v) {
	return fmaf(v, logf(fmaf(expf((-2.0f / v)), (1.0f - u), u)), 1.0f);
}
function code(u, v)
	return fma(v, log(fma(exp(Float32(Float32(-2.0) / v)), Float32(Float32(1.0) - u), u)), Float32(1.0))
end
\mathsf{fma}\left(v, \log \left(\mathsf{fma}\left(e^{\frac{-2}{v}}, 1 - u, u\right)\right), 1\right)
Derivation
  1. Initial program 99.5%

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

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

    Alternative 2: 96.1% accurate, 1.2× speedup?

    \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
    \[\mathsf{fma}\left(v, \log \left(e^{\frac{-2}{v}} + u\right), 1\right) \]
    (FPCore (u v)
      :precision binary32
      :pre (and (and (<= 1e-5 u) (<= u 1.0))
         (and (<= 0.0 v) (<= v 109.746574)))
      (fma v (log (+ (exp (/ -2.0 v)) u)) 1.0))
    float code(float u, float v) {
    	return fmaf(v, logf((expf((-2.0f / v)) + u)), 1.0f);
    }
    
    function code(u, v)
    	return fma(v, log(Float32(exp(Float32(Float32(-2.0) / v)) + u)), Float32(1.0))
    end
    
    \mathsf{fma}\left(v, \log \left(e^{\frac{-2}{v}} + u\right), 1\right)
    
    Derivation
    1. Initial program 99.5%

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

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

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

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

        Alternative 3: 94.3% accurate, 1.3× speedup?

        \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
        \[\mathsf{fma}\left(v, \log \left(-\mathsf{expm1}\left(\frac{-2}{v}\right) \cdot u\right), 1\right) \]
        (FPCore (u v)
          :precision binary32
          :pre (and (and (<= 1e-5 u) (<= u 1.0))
             (and (<= 0.0 v) (<= v 109.746574)))
          (fma v (log (- (* (expm1 (/ -2.0 v)) u))) 1.0))
        float code(float u, float v) {
        	return fmaf(v, logf(-(expm1f((-2.0f / v)) * u)), 1.0f);
        }
        
        function code(u, v)
        	return fma(v, log(Float32(-Float32(expm1(Float32(Float32(-2.0) / v)) * u))), Float32(1.0))
        end
        
        \mathsf{fma}\left(v, \log \left(-\mathsf{expm1}\left(\frac{-2}{v}\right) \cdot u\right), 1\right)
        
        Derivation
        1. Initial program 99.5%

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

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

            \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(u \cdot \mathsf{expm1}\left(\frac{-2}{v}\right)\right)\right) \]
          2. Step-by-step derivation
            1. Applied rewrites94.3%

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

            Alternative 4: 87.5% accurate, 1.4× speedup?

            \[\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(-1 \cdot \frac{1}{\frac{v}{-2 \cdot u}}\right) \]
            (FPCore (u v)
              :precision binary32
              :pre (and (and (<= 1e-5 u) (<= u 1.0))
                 (and (<= 0.0 v) (<= v 109.746574)))
              (+ 1.0 (* v (log (* -1.0 (/ 1.0 (/ v (* -2.0 u))))))))
            float code(float u, float v) {
            	return 1.0f + (v * logf((-1.0f * (1.0f / (v / (-2.0f * u))))));
            }
            
            real(4) function code(u, v)
            use fmin_fmax_functions
                real(4), intent (in) :: u
                real(4), intent (in) :: v
                code = 1.0e0 + (v * log(((-1.0e0) * (1.0e0 / (v / ((-2.0e0) * u))))))
            end function
            
            function code(u, v)
            	return Float32(Float32(1.0) + Float32(v * log(Float32(Float32(-1.0) * Float32(Float32(1.0) / Float32(v / Float32(Float32(-2.0) * u)))))))
            end
            
            function tmp = code(u, v)
            	tmp = single(1.0) + (v * log((single(-1.0) * (single(1.0) / (v / (single(-2.0) * u))))));
            end
            
            1 + v \cdot \log \left(-1 \cdot \frac{1}{\frac{v}{-2 \cdot u}}\right)
            
            Derivation
            1. Initial program 99.5%

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

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

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

                \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
              3. Step-by-step derivation
                1. Applied rewrites87.5%

                  \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
                2. Step-by-step derivation
                  1. Applied rewrites87.5%

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

                  Alternative 5: 87.5% accurate, 1.5× speedup?

                  \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                  \[\mathsf{fma}\left(v, \log \left(-\frac{-1}{\frac{v}{u + u}}\right), 1\right) \]
                  (FPCore (u v)
                    :precision binary32
                    :pre (and (and (<= 1e-5 u) (<= u 1.0))
                       (and (<= 0.0 v) (<= v 109.746574)))
                    (fma v (log (- (/ -1.0 (/ v (+ u u))))) 1.0))
                  float code(float u, float v) {
                  	return fmaf(v, logf(-(-1.0f / (v / (u + u)))), 1.0f);
                  }
                  
                  function code(u, v)
                  	return fma(v, log(Float32(-Float32(Float32(-1.0) / Float32(v / Float32(u + u))))), Float32(1.0))
                  end
                  
                  \mathsf{fma}\left(v, \log \left(-\frac{-1}{\frac{v}{u + u}}\right), 1\right)
                  
                  Derivation
                  1. Initial program 99.5%

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

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

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

                      \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
                    3. Step-by-step derivation
                      1. Applied rewrites87.5%

                        \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
                      2. Step-by-step derivation
                        1. Applied rewrites87.5%

                          \[\leadsto \mathsf{fma}\left(v, \log \left(-\frac{u}{v} \cdot -2\right), 1\right) \]
                        2. Step-by-step derivation
                          1. Applied rewrites87.5%

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

                          Alternative 6: 87.5% accurate, 1.6× speedup?

                          \[\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(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
                          (FPCore (u v)
                            :precision binary32
                            :pre (and (and (<= 1e-5 u) (<= u 1.0))
                               (and (<= 0.0 v) (<= v 109.746574)))
                            (+ 1.0 (* v (log (* -1.0 (* -2.0 (/ u v)))))))
                          float code(float u, float v) {
                          	return 1.0f + (v * logf((-1.0f * (-2.0f * (u / v)))));
                          }
                          
                          real(4) function code(u, v)
                          use fmin_fmax_functions
                              real(4), intent (in) :: u
                              real(4), intent (in) :: v
                              code = 1.0e0 + (v * log(((-1.0e0) * ((-2.0e0) * (u / v)))))
                          end function
                          
                          function code(u, v)
                          	return Float32(Float32(1.0) + Float32(v * log(Float32(Float32(-1.0) * Float32(Float32(-2.0) * Float32(u / v))))))
                          end
                          
                          function tmp = code(u, v)
                          	tmp = single(1.0) + (v * log((single(-1.0) * (single(-2.0) * (u / v)))));
                          end
                          
                          1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right)
                          
                          Derivation
                          1. Initial program 99.5%

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

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

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

                              \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
                            3. Step-by-step derivation
                              1. Applied rewrites87.5%

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

                              Alternative 7: 87.5% accurate, 1.8× speedup?

                              \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                              \[\mathsf{fma}\left(v, \log \left(-\frac{u}{v} \cdot -2\right), 1\right) \]
                              (FPCore (u v)
                                :precision binary32
                                :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                   (and (<= 0.0 v) (<= v 109.746574)))
                                (fma v (log (- (* (/ u v) -2.0))) 1.0))
                              float code(float u, float v) {
                              	return fmaf(v, logf(-((u / v) * -2.0f)), 1.0f);
                              }
                              
                              function code(u, v)
                              	return fma(v, log(Float32(-Float32(Float32(u / v) * Float32(-2.0)))), Float32(1.0))
                              end
                              
                              \mathsf{fma}\left(v, \log \left(-\frac{u}{v} \cdot -2\right), 1\right)
                              
                              Derivation
                              1. Initial program 99.5%

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

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

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

                                  \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
                                3. Step-by-step derivation
                                  1. Applied rewrites87.5%

                                    \[\leadsto 1 + v \cdot \log \left(-1 \cdot \left(-2 \cdot \frac{u}{v}\right)\right) \]
                                  2. Step-by-step derivation
                                    1. Applied rewrites87.5%

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

                                    Alternative 8: 86.8% accurate, 2.1× speedup?

                                    \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                    \[\mathsf{fma}\left(v, \log \left(\left(1 - u\right) + u\right), 1\right) \]
                                    (FPCore (u v)
                                      :precision binary32
                                      :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                         (and (<= 0.0 v) (<= v 109.746574)))
                                      (fma v (log (+ (- 1.0 u) u)) 1.0))
                                    float code(float u, float v) {
                                    	return fmaf(v, logf(((1.0f - u) + u)), 1.0f);
                                    }
                                    
                                    function code(u, v)
                                    	return fma(v, log(Float32(Float32(Float32(1.0) - u) + u)), Float32(1.0))
                                    end
                                    
                                    \mathsf{fma}\left(v, \log \left(\left(1 - u\right) + u\right), 1\right)
                                    
                                    Derivation
                                    1. Initial program 99.5%

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

                                      \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right)\right) \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites86.8%

                                        \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right)\right) \]
                                      2. Step-by-step derivation
                                        1. Applied rewrites86.8%

                                          \[\leadsto \mathsf{fma}\left(v, \log \left(\left(1 - u\right) + u\right), 1\right) \]
                                        2. Add Preprocessing

                                        Alternative 9: 86.8% accurate, 2.4× speedup?

                                        \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                        \[\mathsf{fma}\left(v, \log \left(1 + u\right), 1\right) \]
                                        (FPCore (u v)
                                          :precision binary32
                                          :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                             (and (<= 0.0 v) (<= v 109.746574)))
                                          (fma v (log (+ 1.0 u)) 1.0))
                                        float code(float u, float v) {
                                        	return fmaf(v, logf((1.0f + u)), 1.0f);
                                        }
                                        
                                        function code(u, v)
                                        	return fma(v, log(Float32(Float32(1.0) + u)), Float32(1.0))
                                        end
                                        
                                        \mathsf{fma}\left(v, \log \left(1 + u\right), 1\right)
                                        
                                        Derivation
                                        1. Initial program 99.5%

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

                                          \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right)\right) \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites86.8%

                                            \[\leadsto 1 + v \cdot \log \left(u + \left(1 - u\right)\right) \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites86.8%

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

                                              \[\leadsto \mathsf{fma}\left(v, \log \left(1 + u\right), 1\right) \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites86.8%

                                                \[\leadsto \mathsf{fma}\left(v, \log \left(1 + u\right), 1\right) \]
                                              2. Add Preprocessing

                                              Alternative 10: 46.6% accurate, 2.7× speedup?

                                              \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                              \[1 + v \cdot \left(2 \cdot \frac{u}{v}\right) \]
                                              (FPCore (u v)
                                                :precision binary32
                                                :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                                   (and (<= 0.0 v) (<= v 109.746574)))
                                                (+ 1.0 (* v (* 2.0 (/ u v)))))
                                              float code(float u, float v) {
                                              	return 1.0f + (v * (2.0f * (u / v)));
                                              }
                                              
                                              real(4) function code(u, v)
                                              use fmin_fmax_functions
                                                  real(4), intent (in) :: u
                                                  real(4), intent (in) :: v
                                                  code = 1.0e0 + (v * (2.0e0 * (u / v)))
                                              end function
                                              
                                              function code(u, v)
                                              	return Float32(Float32(1.0) + Float32(v * Float32(Float32(2.0) * Float32(u / v))))
                                              end
                                              
                                              function tmp = code(u, v)
                                              	tmp = single(1.0) + (v * (single(2.0) * (u / v)));
                                              end
                                              
                                              1 + v \cdot \left(2 \cdot \frac{u}{v}\right)
                                              
                                              Derivation
                                              1. Initial program 99.5%

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

                                                \[\leadsto 1 + v \cdot \left(-2 \cdot \frac{1 - u}{v}\right) \]
                                              3. Step-by-step derivation
                                                1. Applied rewrites8.1%

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

                                                  \[\leadsto 1 + v \cdot \left(2 \cdot \frac{u}{v}\right) \]
                                                3. Step-by-step derivation
                                                  1. Applied rewrites46.6%

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

                                                  Alternative 11: 46.6% accurate, 2.9× speedup?

                                                  \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                                  \[\mathsf{fma}\left(v, \frac{u + u}{v}, 1\right) \]
                                                  (FPCore (u v)
                                                    :precision binary32
                                                    :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                                       (and (<= 0.0 v) (<= v 109.746574)))
                                                    (fma v (/ (+ u u) v) 1.0))
                                                  float code(float u, float v) {
                                                  	return fmaf(v, ((u + u) / v), 1.0f);
                                                  }
                                                  
                                                  function code(u, v)
                                                  	return fma(v, Float32(Float32(u + u) / v), Float32(1.0))
                                                  end
                                                  
                                                  \mathsf{fma}\left(v, \frac{u + u}{v}, 1\right)
                                                  
                                                  Derivation
                                                  1. Initial program 99.5%

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

                                                    \[\leadsto 1 + v \cdot \left(-2 \cdot \frac{1 - u}{v}\right) \]
                                                  3. Step-by-step derivation
                                                    1. Applied rewrites8.1%

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

                                                      \[\leadsto 1 + v \cdot \left(2 \cdot \frac{u}{v}\right) \]
                                                    3. Step-by-step derivation
                                                      1. Applied rewrites46.6%

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

                                                          \[\leadsto \mathsf{fma}\left(v, \frac{u + u}{v}, 1\right) \]
                                                        2. Add Preprocessing

                                                        Alternative 12: 46.6% accurate, 5.7× speedup?

                                                        \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                                        \[1 + \left(u + u\right) \]
                                                        (FPCore (u v)
                                                          :precision binary32
                                                          :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                                             (and (<= 0.0 v) (<= v 109.746574)))
                                                          (+ 1.0 (+ u u)))
                                                        float code(float u, float v) {
                                                        	return 1.0f + (u + u);
                                                        }
                                                        
                                                        real(4) function code(u, v)
                                                        use fmin_fmax_functions
                                                            real(4), intent (in) :: u
                                                            real(4), intent (in) :: v
                                                            code = 1.0e0 + (u + u)
                                                        end function
                                                        
                                                        function code(u, v)
                                                        	return Float32(Float32(1.0) + Float32(u + u))
                                                        end
                                                        
                                                        function tmp = code(u, v)
                                                        	tmp = single(1.0) + (u + u);
                                                        end
                                                        
                                                        1 + \left(u + u\right)
                                                        
                                                        Derivation
                                                        1. Initial program 99.5%

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

                                                          \[\leadsto 1 + -2 \cdot \left(1 - u\right) \]
                                                        3. Step-by-step derivation
                                                          1. Applied rewrites8.1%

                                                            \[\leadsto 1 + -2 \cdot \left(1 - u\right) \]
                                                          2. Taylor expanded in u around inf

                                                            \[\leadsto 1 + 2 \cdot u \]
                                                          3. Step-by-step derivation
                                                            1. Applied rewrites46.6%

                                                              \[\leadsto 1 + 2 \cdot u \]
                                                            2. Step-by-step derivation
                                                              1. Applied rewrites46.6%

                                                                \[\leadsto 1 + \left(u + u\right) \]
                                                              2. Add Preprocessing

                                                              Alternative 13: 19.8% accurate, 8.9× speedup?

                                                              \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                                              \[u \cdot 2 \]
                                                              (FPCore (u v)
                                                                :precision binary32
                                                                :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                                                   (and (<= 0.0 v) (<= v 109.746574)))
                                                                (* u 2.0))
                                                              float code(float u, float v) {
                                                              	return u * 2.0f;
                                                              }
                                                              
                                                              real(4) function code(u, v)
                                                              use fmin_fmax_functions
                                                                  real(4), intent (in) :: u
                                                                  real(4), intent (in) :: v
                                                                  code = u * 2.0e0
                                                              end function
                                                              
                                                              function code(u, v)
                                                              	return Float32(u * Float32(2.0))
                                                              end
                                                              
                                                              function tmp = code(u, v)
                                                              	tmp = u * single(2.0);
                                                              end
                                                              
                                                              u \cdot 2
                                                              
                                                              Derivation
                                                              1. Initial program 99.5%

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

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

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

                                                                  \[\leadsto 2 \cdot u - 1 \]
                                                                3. Step-by-step derivation
                                                                  1. Applied rewrites8.1%

                                                                    \[\leadsto 2 \cdot u - 1 \]
                                                                  2. Taylor expanded in u around inf

                                                                    \[\leadsto u \cdot \left(2 - \frac{1}{u}\right) \]
                                                                  3. Step-by-step derivation
                                                                    1. Applied rewrites8.1%

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

                                                                      \[\leadsto u \cdot 2 \]
                                                                    3. Step-by-step derivation
                                                                      1. Applied rewrites19.8%

                                                                        \[\leadsto u \cdot 2 \]
                                                                      2. Add Preprocessing

                                                                      Alternative 14: 6.2% accurate, 9.9× speedup?

                                                                      \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                                                      \[u + -1 \]
                                                                      (FPCore (u v)
                                                                        :precision binary32
                                                                        :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                                                           (and (<= 0.0 v) (<= v 109.746574)))
                                                                        (+ u -1.0))
                                                                      float code(float u, float v) {
                                                                      	return u + -1.0f;
                                                                      }
                                                                      
                                                                      real(4) function code(u, v)
                                                                      use fmin_fmax_functions
                                                                          real(4), intent (in) :: u
                                                                          real(4), intent (in) :: v
                                                                          code = u + (-1.0e0)
                                                                      end function
                                                                      
                                                                      function code(u, v)
                                                                      	return Float32(u + Float32(-1.0))
                                                                      end
                                                                      
                                                                      function tmp = code(u, v)
                                                                      	tmp = u + single(-1.0);
                                                                      end
                                                                      
                                                                      u + -1
                                                                      
                                                                      Derivation
                                                                      1. Initial program 99.5%

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

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

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

                                                                          \[\leadsto 2 \cdot u - 1 \]
                                                                        3. Step-by-step derivation
                                                                          1. Applied rewrites8.1%

                                                                            \[\leadsto 2 \cdot u - 1 \]
                                                                          2. Step-by-step derivation
                                                                            1. Applied rewrites8.1%

                                                                              \[\leadsto u + \left(u - 1\right) \]
                                                                            2. Taylor expanded in u around 0

                                                                              \[\leadsto u + -1 \]
                                                                            3. Step-by-step derivation
                                                                              1. Applied rewrites6.2%

                                                                                \[\leadsto u + -1 \]
                                                                              2. Add Preprocessing

                                                                              Alternative 15: 6.0% accurate, 35.6× speedup?

                                                                              \[\left(10^{-5} \leq u \land u \leq 1\right) \land \left(0 \leq v \land v \leq 109.746574\right)\]
                                                                              \[-1 \]
                                                                              (FPCore (u v)
                                                                                :precision binary32
                                                                                :pre (and (and (<= 1e-5 u) (<= u 1.0))
                                                                                   (and (<= 0.0 v) (<= v 109.746574)))
                                                                                -1.0)
                                                                              float code(float u, float v) {
                                                                              	return -1.0f;
                                                                              }
                                                                              
                                                                              real(4) function code(u, v)
                                                                              use fmin_fmax_functions
                                                                                  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
                                                                              
                                                                              -1
                                                                              
                                                                              Derivation
                                                                              1. Initial program 99.5%

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

                                                                                \[\leadsto -1 \]
                                                                              3. Step-by-step derivation
                                                                                1. Applied rewrites6.0%

                                                                                  \[\leadsto -1 \]
                                                                                2. Add Preprocessing

                                                                                Reproduce

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