Disney BSSRDF, sample scattering profile, upper

Percentage Accurate: 95.9% → 98.2%
Time: 8.9s
Alternatives: 6
Speedup: 1.2×

Specification

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

\\
\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\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 6 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: 95.9% accurate, 1.0× speedup?

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

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

Alternative 1: 98.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ 3 \cdot \left(\mathsf{log1p}\left(\frac{u - 0.25}{-0.75}\right) \cdot \left(-s\right)\right) \end{array} \]
(FPCore (s u)
 :precision binary32
 (* 3.0 (* (log1p (/ (- u 0.25) -0.75)) (- s))))
float code(float s, float u) {
	return 3.0f * (log1pf(((u - 0.25f) / -0.75f)) * -s);
}
function code(s, u)
	return Float32(Float32(3.0) * Float32(log1p(Float32(Float32(u - Float32(0.25)) / Float32(-0.75))) * Float32(-s)))
end
\begin{array}{l}

\\
3 \cdot \left(\mathsf{log1p}\left(\frac{u - 0.25}{-0.75}\right) \cdot \left(-s\right)\right)
\end{array}
Derivation
  1. Initial program 95.5%

    \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f32N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\left(\mathsf{neg}\left(s\right)\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{u - \frac{1}{4}}{\mathsf{neg}\left(\frac{3}{4}\right)}}\right)\right) \cdot 3 \]
    9. metadata-eval98.3

      \[\leadsto \left(\left(-s\right) \cdot \mathsf{log1p}\left(\frac{u - 0.25}{\color{blue}{-0.75}}\right)\right) \cdot 3 \]
  6. Applied rewrites98.3%

    \[\leadsto \left(\left(-s\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{u - 0.25}{-0.75}}\right)\right) \cdot 3 \]
  7. Final simplification98.3%

    \[\leadsto 3 \cdot \left(\mathsf{log1p}\left(\frac{u - 0.25}{-0.75}\right) \cdot \left(-s\right)\right) \]
  8. Add Preprocessing

Alternative 2: 97.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \left(\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \cdot \left(-s\right)\right) \cdot 3 \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* (log1p (fma u -1.3333333333333333 0.3333333333333333)) (- s)) 3.0))
float code(float s, float u) {
	return (log1pf(fmaf(u, -1.3333333333333333f, 0.3333333333333333f)) * -s) * 3.0f;
}
function code(s, u)
	return Float32(Float32(log1p(fma(u, Float32(-1.3333333333333333), Float32(0.3333333333333333))) * Float32(-s)) * Float32(3.0))
end
\begin{array}{l}

\\
\left(\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \cdot \left(-s\right)\right) \cdot 3
\end{array}
Derivation
  1. Initial program 95.5%

    \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f32N/A

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\left(-s\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot 3} \]
  5. Applied rewrites97.8%

    \[\leadsto \color{blue}{\left(\left(-\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right)\right) \cdot s\right)} \cdot 3 \]
  6. Final simplification97.8%

    \[\leadsto \left(\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \cdot \left(-s\right)\right) \cdot 3 \]
  7. Add Preprocessing

Alternative 3: 97.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \left(-3 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right)\right) \cdot s \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* -3.0 (log1p (fma -1.3333333333333333 u 0.3333333333333333))) s))
float code(float s, float u) {
	return (-3.0f * log1pf(fmaf(-1.3333333333333333f, u, 0.3333333333333333f))) * s;
}
function code(s, u)
	return Float32(Float32(Float32(-3.0) * log1p(fma(Float32(-1.3333333333333333), u, Float32(0.3333333333333333)))) * s)
end
\begin{array}{l}

\\
\left(-3 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right)\right) \cdot s
\end{array}
Derivation
  1. Initial program 95.5%

    \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f32N/A

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\left(-s\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot 3} \]
  5. Applied rewrites97.8%

    \[\leadsto \color{blue}{\left(\left(-\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right)\right) \cdot 3\right) \cdot s} \]
  6. Step-by-step derivation
    1. lift-fma.f32N/A

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

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

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

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

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

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

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

      \[\leadsto \left(\left(\mathsf{neg}\left(\mathsf{log1p}\left(\frac{\color{blue}{u - \frac{1}{4}}}{\frac{-3}{4}}\right)\right)\right) \cdot 3\right) \cdot s \]
    9. lift-/.f3298.3

      \[\leadsto \left(\left(-\mathsf{log1p}\left(\color{blue}{\frac{u - 0.25}{-0.75}}\right)\right) \cdot 3\right) \cdot s \]
  7. Applied rewrites98.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\mathsf{log1p}\left(\mathsf{fma}\left(\frac{-4}{3}, u, \color{blue}{\frac{1}{3}}\right)\right) \cdot \left(-1 \cdot 3\right)\right) \cdot s \]
    18. metadata-eval97.8

      \[\leadsto \left(\mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot \color{blue}{-3}\right) \cdot s \]
  9. Applied rewrites97.8%

    \[\leadsto \color{blue}{\left(\mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot -3\right)} \cdot s \]
  10. Final simplification97.8%

    \[\leadsto \left(-3 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right)\right) \cdot s \]
  11. Add Preprocessing

Alternative 4: 97.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* -3.0 s) (log1p (fma u -1.3333333333333333 0.3333333333333333))))
float code(float s, float u) {
	return (-3.0f * s) * log1pf(fmaf(u, -1.3333333333333333f, 0.3333333333333333f));
}
function code(s, u)
	return Float32(Float32(Float32(-3.0) * s) * log1p(fma(u, Float32(-1.3333333333333333), Float32(0.3333333333333333))))
end
\begin{array}{l}

\\
\left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right)
\end{array}
Derivation
  1. Initial program 95.5%

    \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f32N/A

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\left(-s\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot 3} \]
  5. Applied rewrites97.8%

    \[\leadsto \color{blue}{\left(\left(-\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right)\right) \cdot 3\right) \cdot s} \]
  6. Step-by-step derivation
    1. lift-fma.f32N/A

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

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

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

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

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

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

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

      \[\leadsto \left(\left(\mathsf{neg}\left(\mathsf{log1p}\left(\frac{\color{blue}{u - \frac{1}{4}}}{\frac{-3}{4}}\right)\right)\right) \cdot 3\right) \cdot s \]
    9. lift-/.f3298.3

      \[\leadsto \left(\left(-\mathsf{log1p}\left(\color{blue}{\frac{u - 0.25}{-0.75}}\right)\right) \cdot 3\right) \cdot s \]
  7. Applied rewrites98.3%

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

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log \left(1 + \frac{-4}{3} \cdot \left(u - \frac{1}{4}\right)\right)\right)} \]
  9. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\frac{-4}{3} \cdot \color{blue}{\left(u + \left(\mathsf{neg}\left(\frac{1}{4}\right)\right)\right)}\right) \]
    7. distribute-rgt-inN/A

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(u \cdot \frac{-4}{3} + \color{blue}{\frac{1}{3}}\right) \]
    10. lower-fma.f3297.8

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)}\right) \]
  10. Applied rewrites97.8%

    \[\leadsto \color{blue}{\left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right)} \]
  11. Final simplification97.8%

    \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \]
  12. Add Preprocessing

Alternative 5: 96.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \log \left(\mathsf{fma}\left(-1.3333333333333333, u, 1.3333333333333333\right)\right) \cdot \left(-3 \cdot s\right) \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (log (fma -1.3333333333333333 u 1.3333333333333333)) (* -3.0 s)))
float code(float s, float u) {
	return logf(fmaf(-1.3333333333333333f, u, 1.3333333333333333f)) * (-3.0f * s);
}
function code(s, u)
	return Float32(log(fma(Float32(-1.3333333333333333), u, Float32(1.3333333333333333))) * Float32(Float32(-3.0) * s))
end
\begin{array}{l}

\\
\log \left(\mathsf{fma}\left(-1.3333333333333333, u, 1.3333333333333333\right)\right) \cdot \left(-3 \cdot s\right)
\end{array}
Derivation
  1. Initial program 95.5%

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

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

    \[\leadsto \color{blue}{\log \left(\mathsf{fma}\left(-1.3333333333333333, u, 1.3333333333333333\right)\right) \cdot \left(-3 \cdot s\right)} \]
  5. Add Preprocessing

Alternative 6: 29.9% accurate, 12.6× speedup?

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

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

    \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
  2. Add Preprocessing
  3. Applied rewrites94.7%

    \[\leadsto \left(3 \cdot s\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{\frac{1}{\mathsf{fma}\left(1.3333333333333333, u, 0.6666666666666666\right)} \cdot \frac{1}{\mathsf{fma}\left(1.3333333333333333, u, 0.6666666666666666\right)} - \left(\left(\left(0.25 - u\right) \cdot \left(0.25 - u\right)\right) \cdot \frac{1.7777777777777777}{\mathsf{fma}\left(1.3333333333333333, u, 0.6666666666666666\right)}\right) \cdot \left(\left(\left(0.25 - u\right) \cdot \left(0.25 - u\right)\right) \cdot \frac{1.7777777777777777}{\mathsf{fma}\left(1.3333333333333333, u, 0.6666666666666666\right)}\right)}{\frac{1}{\mathsf{fma}\left(1.3333333333333333, u, 0.6666666666666666\right)} + \left(\left(0.25 - u\right) \cdot \left(0.25 - u\right)\right) \cdot \frac{1.7777777777777777}{\mathsf{fma}\left(1.3333333333333333, u, 0.6666666666666666\right)}}}}\right) \]
  4. Taylor expanded in u around 0

    \[\leadsto \left(3 \cdot s\right) \cdot \log \color{blue}{\frac{3}{4}} \]
  5. Step-by-step derivation
    1. Applied rewrites7.5%

      \[\leadsto \left(3 \cdot s\right) \cdot \log \color{blue}{0.75} \]
    2. Taylor expanded in u around 0

      \[\leadsto \color{blue}{3 \cdot \left(s \cdot u\right) + 3 \cdot \left(s \cdot \log \frac{3}{4}\right)} \]
    3. Step-by-step derivation
      1. distribute-lft-outN/A

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

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

        \[\leadsto \color{blue}{\left(s \cdot u + s \cdot \log \frac{3}{4}\right) \cdot 3} \]
      4. distribute-lft-outN/A

        \[\leadsto \color{blue}{\left(s \cdot \left(u + \log \frac{3}{4}\right)\right)} \cdot 3 \]
      5. lower-*.f32N/A

        \[\leadsto \color{blue}{\left(s \cdot \left(u + \log \frac{3}{4}\right)\right)} \cdot 3 \]
      6. +-commutativeN/A

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

        \[\leadsto \left(s \cdot \color{blue}{\left(\log \frac{3}{4} + u\right)}\right) \cdot 3 \]
      8. lower-log.f3225.4

        \[\leadsto \left(s \cdot \left(\color{blue}{\log 0.75} + u\right)\right) \cdot 3 \]
    4. Applied rewrites25.4%

      \[\leadsto \color{blue}{\left(s \cdot \left(\log 0.75 + u\right)\right) \cdot 3} \]
    5. Taylor expanded in u around inf

      \[\leadsto \left(s \cdot u\right) \cdot 3 \]
    6. Step-by-step derivation
      1. Applied rewrites30.1%

        \[\leadsto \left(u \cdot s\right) \cdot 3 \]
      2. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2024235 
      (FPCore (s u)
        :name "Disney BSSRDF, sample scattering profile, upper"
        :precision binary32
        :pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 0.25 u) (<= u 1.0)))
        (* (* 3.0 s) (log (/ 1.0 (- 1.0 (/ (- u 0.25) 0.75))))))