Disney BSSRDF, sample scattering profile, lower

Percentage Accurate: 61.4% → 88.9%
Time: 7.1s
Alternatives: 4
Speedup: 11.4×

Specification

?
\[\left(0 \leq s \land s \leq 256\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 0.25\right)\]
\[\begin{array}{l} \\ s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \end{array} \]
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
float code(float s, float u) {
	return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
    real(4), intent (in) :: s
    real(4), intent (in) :: u
    code = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end function
function code(s, u)
	return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u)))))
end
function tmp = code(s, u)
	tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u))));
end
\begin{array}{l}

\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\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 4 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: 61.4% accurate, 1.0× speedup?

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

\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}

Alternative 1: 88.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - 4 \cdot u \leq 0.9998599886894226:\\ \;\;\;\;s \cdot \log \left(\frac{1}{1 - e^{\log \left(u \cdot 4\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;s \cdot \left(4 \cdot u\right)\\ \end{array} \end{array} \]
(FPCore (s u)
 :precision binary32
 (if (<= (- 1.0 (* 4.0 u)) 0.9998599886894226)
   (* s (log (/ 1.0 (- 1.0 (exp (log (* u 4.0)))))))
   (* s (* 4.0 u))))
float code(float s, float u) {
	float tmp;
	if ((1.0f - (4.0f * u)) <= 0.9998599886894226f) {
		tmp = s * logf((1.0f / (1.0f - expf(logf((u * 4.0f))))));
	} else {
		tmp = s * (4.0f * u);
	}
	return tmp;
}
real(4) function code(s, u)
    real(4), intent (in) :: s
    real(4), intent (in) :: u
    real(4) :: tmp
    if ((1.0e0 - (4.0e0 * u)) <= 0.9998599886894226e0) then
        tmp = s * log((1.0e0 / (1.0e0 - exp(log((u * 4.0e0))))))
    else
        tmp = s * (4.0e0 * u)
    end if
    code = tmp
end function
function code(s, u)
	tmp = Float32(0.0)
	if (Float32(Float32(1.0) - Float32(Float32(4.0) * u)) <= Float32(0.9998599886894226))
		tmp = Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - exp(log(Float32(u * Float32(4.0))))))));
	else
		tmp = Float32(s * Float32(Float32(4.0) * u));
	end
	return tmp
end
function tmp_2 = code(s, u)
	tmp = single(0.0);
	if ((single(1.0) - (single(4.0) * u)) <= single(0.9998599886894226))
		tmp = s * log((single(1.0) / (single(1.0) - exp(log((u * single(4.0)))))));
	else
		tmp = s * (single(4.0) * u);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;1 - 4 \cdot u \leq 0.9998599886894226:\\
\;\;\;\;s \cdot \log \left(\frac{1}{1 - e^{\log \left(u \cdot 4\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;s \cdot \left(4 \cdot u\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.999859989

    1. Initial program 84.3%

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. rem-exp-logN/A

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

        \[\leadsto s \cdot \log \left(\frac{1}{1 - \color{blue}{e^{\log \left(4 \cdot u\right)}}}\right) \]
      3. lower-log.f3284.3

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

        \[\leadsto s \cdot \log \left(\frac{1}{1 - e^{\log \color{blue}{\left(4 \cdot u\right)}}}\right) \]
      5. *-commutativeN/A

        \[\leadsto s \cdot \log \left(\frac{1}{1 - e^{\log \color{blue}{\left(u \cdot 4\right)}}}\right) \]
      6. lower-*.f3284.3

        \[\leadsto s \cdot \log \left(\frac{1}{1 - e^{\log \color{blue}{\left(u \cdot 4\right)}}}\right) \]
    4. Applied rewrites84.3%

      \[\leadsto s \cdot \log \left(\frac{1}{1 - \color{blue}{e^{\log \left(u \cdot 4\right)}}}\right) \]

    if 0.999859989 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u))

    1. Initial program 45.0%

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u around 0

      \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
    4. Step-by-step derivation
      1. lower-*.f3290.8

        \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
    5. Applied rewrites90.8%

      \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 82.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \leq 2.0000000390829628 \cdot 10^{-24}:\\ \;\;\;\;s \cdot \left(4 \cdot u\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(s \cdot s\right) \cdot \frac{-1}{s}}{0.5 - \frac{0.25}{u}}\\ \end{array} \end{array} \]
(FPCore (s u)
 :precision binary32
 (if (<= (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))) 2.0000000390829628e-24)
   (* s (* 4.0 u))
   (/ (* (* s s) (/ -1.0 s)) (- 0.5 (/ 0.25 u)))))
float code(float s, float u) {
	float tmp;
	if ((s * logf((1.0f / (1.0f - (4.0f * u))))) <= 2.0000000390829628e-24f) {
		tmp = s * (4.0f * u);
	} else {
		tmp = ((s * s) * (-1.0f / s)) / (0.5f - (0.25f / u));
	}
	return tmp;
}
real(4) function code(s, u)
    real(4), intent (in) :: s
    real(4), intent (in) :: u
    real(4) :: tmp
    if ((s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))) <= 2.0000000390829628e-24) then
        tmp = s * (4.0e0 * u)
    else
        tmp = ((s * s) * ((-1.0e0) / s)) / (0.5e0 - (0.25e0 / u))
    end if
    code = tmp
end function
function code(s, u)
	tmp = Float32(0.0)
	if (Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))) <= Float32(2.0000000390829628e-24))
		tmp = Float32(s * Float32(Float32(4.0) * u));
	else
		tmp = Float32(Float32(Float32(s * s) * Float32(Float32(-1.0) / s)) / Float32(Float32(0.5) - Float32(Float32(0.25) / u)));
	end
	return tmp
end
function tmp_2 = code(s, u)
	tmp = single(0.0);
	if ((s * log((single(1.0) / (single(1.0) - (single(4.0) * u))))) <= single(2.0000000390829628e-24))
		tmp = s * (single(4.0) * u);
	else
		tmp = ((s * s) * (single(-1.0) / s)) / (single(0.5) - (single(0.25) / u));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \leq 2.0000000390829628 \cdot 10^{-24}:\\
\;\;\;\;s \cdot \left(4 \cdot u\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(s \cdot s\right) \cdot \frac{-1}{s}}{0.5 - \frac{0.25}{u}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 s (log.f32 (/.f32 #s(literal 1 binary32) (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u))))) < 2.00000004e-24

    1. Initial program 58.5%

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u around 0

      \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
    4. Step-by-step derivation
      1. lower-*.f3279.4

        \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
    5. Applied rewrites79.4%

      \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]

    if 2.00000004e-24 < (*.f32 s (log.f32 (/.f32 #s(literal 1 binary32) (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)))))

    1. Initial program 66.3%

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Add Preprocessing
    3. Applied rewrites44.8%

      \[\leadsto s \cdot \color{blue}{\frac{1}{\frac{-{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}}} \]
    4. Step-by-step derivation
      1. lift-*.f32N/A

        \[\leadsto \color{blue}{s \cdot \frac{1}{\frac{-{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}}} \]
      2. lift-/.f32N/A

        \[\leadsto s \cdot \color{blue}{\frac{1}{\frac{-{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}}} \]
      3. un-div-invN/A

        \[\leadsto \color{blue}{\frac{s}{\frac{-{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}}} \]
      4. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(s\right)}{\mathsf{neg}\left(\frac{-{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}\right)}} \]
      5. lift-/.f32N/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\mathsf{neg}\left(\color{blue}{\frac{-{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}}\right)} \]
      6. distribute-neg-fracN/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\color{blue}{\frac{\mathsf{neg}\left(\left(-{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}\right)\right)}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}}} \]
      7. lift-neg.f32N/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left({\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}\right)\right)}\right)}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}} \]
      8. remove-double-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\frac{\color{blue}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}} \]
      9. lift-pow.f32N/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\frac{\color{blue}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}} \]
      10. lift-pow.f32N/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\frac{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{2}}{\color{blue}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{3}}}} \]
      11. pow-divN/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\color{blue}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{\left(2 - 3\right)}}} \]
      12. metadata-evalN/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{\color{blue}{-1}}} \]
      13. metadata-evalN/A

        \[\leadsto \frac{\mathsf{neg}\left(s\right)}{{\left(\mathsf{log1p}\left(-4 \cdot u\right)\right)}^{\color{blue}{\left(\frac{-2}{2}\right)}}} \]
    5. Applied rewrites66.7%

      \[\leadsto \color{blue}{\frac{-s}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}}} \]
    6. Step-by-step derivation
      1. lift-neg.f32N/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(s\right)}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      2. neg-sub0N/A

        \[\leadsto \frac{\color{blue}{0 - s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      3. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\log 1} - s}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      4. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{\log 1 \cdot \log 1 - s \cdot s}{\log 1 + s}}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      5. div-invN/A

        \[\leadsto \frac{\color{blue}{\left(\log 1 \cdot \log 1 - s \cdot s\right) \cdot \frac{1}{\log 1 + s}}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\left(\log 1 \cdot \log 1 - s \cdot s\right) \cdot \frac{1}{\color{blue}{0} + s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      7. +-lft-identityN/A

        \[\leadsto \frac{\left(\log 1 \cdot \log 1 - s \cdot s\right) \cdot \frac{1}{\color{blue}{s}}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      8. lower-*.f32N/A

        \[\leadsto \frac{\color{blue}{\left(\log 1 \cdot \log 1 - s \cdot s\right) \cdot \frac{1}{s}}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      9. metadata-evalN/A

        \[\leadsto \frac{\left(\color{blue}{0} \cdot \log 1 - s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\left(0 \cdot \color{blue}{0} - s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      11. metadata-evalN/A

        \[\leadsto \frac{\left(\color{blue}{0} - s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      12. sub0-negN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(s \cdot s\right)\right)} \cdot \frac{1}{s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      13. lower-neg.f32N/A

        \[\leadsto \frac{\color{blue}{\left(-s \cdot s\right)} \cdot \frac{1}{s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      14. lower-*.f32N/A

        \[\leadsto \frac{\left(-\color{blue}{s \cdot s}\right) \cdot \frac{1}{s}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
      15. lower-/.f3266.6

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \color{blue}{\frac{1}{s}}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
    7. Applied rewrites66.6%

      \[\leadsto \frac{\color{blue}{\left(-s \cdot s\right) \cdot \frac{1}{s}}}{\frac{1}{\mathsf{log1p}\left(-4 \cdot u\right)}} \]
    8. Taylor expanded in u around 0

      \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\color{blue}{\frac{\frac{1}{2} \cdot u - \frac{1}{4}}{u}}} \]
    9. Step-by-step derivation
      1. div-subN/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\color{blue}{\frac{\frac{1}{2} \cdot u}{u} - \frac{\frac{1}{4}}{u}}} \]
      2. associate-/l*N/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\color{blue}{\frac{1}{2} \cdot \frac{u}{u}} - \frac{\frac{1}{4}}{u}} \]
      3. *-inversesN/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{2} \cdot \color{blue}{1} - \frac{\frac{1}{4}}{u}} \]
      4. metadata-evalN/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\color{blue}{\frac{1}{2}} - \frac{\frac{1}{4}}{u}} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{2} - \frac{\color{blue}{\frac{1}{4} \cdot 1}}{u}} \]
      6. associate-*r/N/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{2} - \color{blue}{\frac{1}{4} \cdot \frac{1}{u}}} \]
      7. lower--.f32N/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\color{blue}{\frac{1}{2} - \frac{1}{4} \cdot \frac{1}{u}}} \]
      8. associate-*r/N/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{2} - \color{blue}{\frac{\frac{1}{4} \cdot 1}{u}}} \]
      9. metadata-evalN/A

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\frac{1}{2} - \frac{\color{blue}{\frac{1}{4}}}{u}} \]
      10. lower-/.f3286.8

        \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{0.5 - \color{blue}{\frac{0.25}{u}}} \]
    10. Applied rewrites86.8%

      \[\leadsto \frac{\left(-s \cdot s\right) \cdot \frac{1}{s}}{\color{blue}{0.5 - \frac{0.25}{u}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification82.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \leq 2.0000000390829628 \cdot 10^{-24}:\\ \;\;\;\;s \cdot \left(4 \cdot u\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(s \cdot s\right) \cdot \frac{-1}{s}}{0.5 - \frac{0.25}{u}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 89.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - 4 \cdot u\\ \mathbf{if}\;t\_0 \leq 0.9998599886894226:\\ \;\;\;\;s \cdot \log \left(\frac{1}{t\_0}\right)\\ \mathbf{else}:\\ \;\;\;\;s \cdot \left(4 \cdot u\right)\\ \end{array} \end{array} \]
(FPCore (s u)
 :precision binary32
 (let* ((t_0 (- 1.0 (* 4.0 u))))
   (if (<= t_0 0.9998599886894226) (* s (log (/ 1.0 t_0))) (* s (* 4.0 u)))))
float code(float s, float u) {
	float t_0 = 1.0f - (4.0f * u);
	float tmp;
	if (t_0 <= 0.9998599886894226f) {
		tmp = s * logf((1.0f / t_0));
	} else {
		tmp = s * (4.0f * u);
	}
	return tmp;
}
real(4) function code(s, u)
    real(4), intent (in) :: s
    real(4), intent (in) :: u
    real(4) :: t_0
    real(4) :: tmp
    t_0 = 1.0e0 - (4.0e0 * u)
    if (t_0 <= 0.9998599886894226e0) then
        tmp = s * log((1.0e0 / t_0))
    else
        tmp = s * (4.0e0 * u)
    end if
    code = tmp
end function
function code(s, u)
	t_0 = Float32(Float32(1.0) - Float32(Float32(4.0) * u))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.9998599886894226))
		tmp = Float32(s * log(Float32(Float32(1.0) / t_0)));
	else
		tmp = Float32(s * Float32(Float32(4.0) * u));
	end
	return tmp
end
function tmp_2 = code(s, u)
	t_0 = single(1.0) - (single(4.0) * u);
	tmp = single(0.0);
	if (t_0 <= single(0.9998599886894226))
		tmp = s * log((single(1.0) / t_0));
	else
		tmp = s * (single(4.0) * u);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - 4 \cdot u\\
\mathbf{if}\;t\_0 \leq 0.9998599886894226:\\
\;\;\;\;s \cdot \log \left(\frac{1}{t\_0}\right)\\

\mathbf{else}:\\
\;\;\;\;s \cdot \left(4 \cdot u\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.999859989

    1. Initial program 84.3%

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Add Preprocessing

    if 0.999859989 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u))

    1. Initial program 45.0%

      \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u around 0

      \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
    4. Step-by-step derivation
      1. lower-*.f3290.8

        \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
    5. Applied rewrites90.8%

      \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 74.0% accurate, 11.4× speedup?

\[\begin{array}{l} \\ s \cdot \left(4 \cdot u\right) \end{array} \]
(FPCore (s u) :precision binary32 (* s (* 4.0 u)))
float code(float s, float u) {
	return s * (4.0f * u);
}
real(4) function code(s, u)
    real(4), intent (in) :: s
    real(4), intent (in) :: u
    code = s * (4.0e0 * u)
end function
function code(s, u)
	return Float32(s * Float32(Float32(4.0) * u))
end
function tmp = code(s, u)
	tmp = s * (single(4.0) * u);
end
\begin{array}{l}

\\
s \cdot \left(4 \cdot u\right)
\end{array}
Derivation
  1. Initial program 62.2%

    \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
  2. Add Preprocessing
  3. Taylor expanded in u around 0

    \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
  4. Step-by-step derivation
    1. lower-*.f3273.6

      \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
  5. Applied rewrites73.6%

    \[\leadsto s \cdot \color{blue}{\left(4 \cdot u\right)} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2024307 
(FPCore (s u)
  :name "Disney BSSRDF, sample scattering profile, lower"
  :precision binary32
  :pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 2.328306437e-10 u) (<= u 0.25)))
  (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))