Disney BSSRDF, sample scattering profile, upper

Percentage Accurate: 95.8% → 96.1%
Time: 8.6s
Alternatives: 7
Speedup: 1.1×

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 7 alternatives:

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

Initial Program: 95.8% 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: 96.1% accurate, 1.1× speedup?

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

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

    \[\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 \left(3 \cdot s\right) \cdot \log \left(\frac{1}{\color{blue}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right) \]
    2. sub-negN/A

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

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

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \log \left(\frac{1}{\frac{1}{\color{blue}{\frac{-3}{4}}} \cdot \left(u - \frac{1}{4}\right) + 1}\right) \]
    11. metadata-eval95.7

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

    \[\leadsto \left(3 \cdot s\right) \cdot \log \left(\frac{1}{\color{blue}{-1.3333333333333333 \cdot \left(u - 0.25\right) + 1}}\right) \]
  5. Applied rewrites10.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\log \left(-\mathsf{fma}\left(\color{blue}{1 \cdot \left(u - \frac{1}{4}\right)}, \frac{4}{3}, -1\right)\right)\right) \]
    19. lower--.f3210.3

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\log \left(-\mathsf{fma}\left(1 \cdot \color{blue}{\left(u - 0.25\right)}, 1.3333333333333333, -1\right)\right)\right) \]
  7. Applied rewrites10.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(3 \cdot s\right) \cdot \left(-\log \left(-\color{blue}{\left(u \cdot 1.3333333333333333 - 1.3333333333333333\right)}\right)\right) \]
  10. Final simplification96.1%

    \[\leadsto \left(\left(-s\right) \cdot 3\right) \cdot \log \left(1.3333333333333333 - 1.3333333333333333 \cdot u\right) \]
  11. Add Preprocessing

Alternative 2: 25.7% accurate, 1.2× speedup?

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

\\
\left(\log 0.75 + u\right) \cdot \left(s \cdot 3\right)
\end{array}
Derivation
  1. Initial program 96.1%

    \[\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 u around 0

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

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

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

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

    \[\leadsto \left(3 \cdot s\right) \cdot \color{blue}{\left(\log 0.75 + u\right)} \]
  6. Final simplification25.8%

    \[\leadsto \left(\log 0.75 + u\right) \cdot \left(s \cdot 3\right) \]
  7. Add Preprocessing

Alternative 3: 25.7% accurate, 1.2× speedup?

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

\\
\left(\left(\log 0.75 + u\right) \cdot s\right) \cdot 3
\end{array}
Derivation
  1. Initial program 96.1%

    \[\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 u around 0

    \[\leadsto \color{blue}{3 \cdot \left(s \cdot u\right) + 3 \cdot \left(s \cdot \log \frac{3}{4}\right)} \]
  4. 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. *-commutativeN/A

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\left(\log 0.75 + u\right) \cdot s\right) \cdot 3} \]
  6. Add Preprocessing

Alternative 4: 25.7% accurate, 1.2× speedup?

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

\\
\left(\left(\log 0.75 + u\right) \cdot 3\right) \cdot s
\end{array}
Derivation
  1. Initial program 96.1%

    \[\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 u around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{s \cdot \left(\left(u + \log \frac{3}{4}\right) \cdot 3 + \left(\frac{3}{2} + u\right) \cdot {u}^{2}\right)} \]
  5. Applied rewrites14.8%

    \[\leadsto \color{blue}{s \cdot \mathsf{fma}\left(\log 0.75 + u, 3, \left(1.5 + u\right) \cdot \left(u \cdot u\right)\right)} \]
  6. Taylor expanded in u around 0

    \[\leadsto s \cdot \left(3 \cdot u + \color{blue}{3 \cdot \log \frac{3}{4}}\right) \]
  7. Step-by-step derivation
    1. Applied rewrites25.8%

      \[\leadsto s \cdot \left(\left(\log 0.75 + u\right) \cdot \color{blue}{3}\right) \]
    2. Final simplification25.8%

      \[\leadsto \left(\left(\log 0.75 + u\right) \cdot 3\right) \cdot s \]
    3. Add Preprocessing

    Alternative 5: 23.3% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ {\left(u \cdot u\right)}^{1.5} \cdot s \end{array} \]
    (FPCore (s u) :precision binary32 (* (pow (* u u) 1.5) s))
    float code(float s, float u) {
    	return powf((u * u), 1.5f) * s;
    }
    
    real(4) function code(s, u)
        real(4), intent (in) :: s
        real(4), intent (in) :: u
        code = ((u * u) ** 1.5e0) * s
    end function
    
    function code(s, u)
    	return Float32((Float32(u * u) ^ Float32(1.5)) * s)
    end
    
    function tmp = code(s, u)
    	tmp = ((u * u) ^ single(1.5)) * s;
    end
    
    \begin{array}{l}
    
    \\
    {\left(u \cdot u\right)}^{1.5} \cdot s
    \end{array}
    
    Derivation
    1. Initial program 96.1%

      \[\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 u around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{s \cdot \left(\left(u + \log \frac{3}{4}\right) \cdot 3 + \left(\frac{3}{2} + u\right) \cdot {u}^{2}\right)} \]
    5. Applied rewrites14.8%

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

      \[\leadsto s \cdot {u}^{\color{blue}{3}} \]
    7. Step-by-step derivation
      1. Applied rewrites23.3%

        \[\leadsto s \cdot {u}^{\color{blue}{3}} \]
      2. Step-by-step derivation
        1. Applied rewrites23.3%

          \[\leadsto s \cdot {\left(u \cdot u\right)}^{1.5} \]
        2. Final simplification23.3%

          \[\leadsto {\left(u \cdot u\right)}^{1.5} \cdot s \]
        3. Add Preprocessing

        Alternative 6: 23.3% accurate, 1.3× speedup?

        \[\begin{array}{l} \\ {u}^{3} \cdot s \end{array} \]
        (FPCore (s u) :precision binary32 (* (pow u 3.0) s))
        float code(float s, float u) {
        	return powf(u, 3.0f) * s;
        }
        
        real(4) function code(s, u)
            real(4), intent (in) :: s
            real(4), intent (in) :: u
            code = (u ** 3.0e0) * s
        end function
        
        function code(s, u)
        	return Float32((u ^ Float32(3.0)) * s)
        end
        
        function tmp = code(s, u)
        	tmp = (u ^ single(3.0)) * s;
        end
        
        \begin{array}{l}
        
        \\
        {u}^{3} \cdot s
        \end{array}
        
        Derivation
        1. Initial program 96.1%

          \[\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 u around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{s \cdot \left(\left(u + \log \frac{3}{4}\right) \cdot 3 + \left(\frac{3}{2} + u\right) \cdot {u}^{2}\right)} \]
        5. Applied rewrites14.7%

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

          \[\leadsto s \cdot {u}^{\color{blue}{3}} \]
        7. Step-by-step derivation
          1. Applied rewrites23.3%

            \[\leadsto s \cdot {u}^{\color{blue}{3}} \]
          2. Final simplification23.3%

            \[\leadsto {u}^{3} \cdot s \]
          3. Add Preprocessing

          Alternative 7: 23.3% accurate, 8.7× speedup?

          \[\begin{array}{l} \\ \left(\left(u \cdot u\right) \cdot u\right) \cdot s \end{array} \]
          (FPCore (s u) :precision binary32 (* (* (* u u) u) s))
          float code(float s, float u) {
          	return ((u * u) * u) * s;
          }
          
          real(4) function code(s, u)
              real(4), intent (in) :: s
              real(4), intent (in) :: u
              code = ((u * u) * u) * s
          end function
          
          function code(s, u)
          	return Float32(Float32(Float32(u * u) * u) * s)
          end
          
          function tmp = code(s, u)
          	tmp = ((u * u) * u) * s;
          end
          
          \begin{array}{l}
          
          \\
          \left(\left(u \cdot u\right) \cdot u\right) \cdot s
          \end{array}
          
          Derivation
          1. Initial program 96.1%

            \[\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 u around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \color{blue}{s \cdot \left(\left(u + \log \frac{3}{4}\right) \cdot 3 + \left(\frac{3}{2} + u\right) \cdot {u}^{2}\right)} \]
          5. Applied rewrites14.8%

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

            \[\leadsto s \cdot {u}^{\color{blue}{3}} \]
          7. Step-by-step derivation
            1. Applied rewrites23.3%

              \[\leadsto s \cdot {u}^{\color{blue}{3}} \]
            2. Step-by-step derivation
              1. Applied rewrites23.3%

                \[\leadsto s \cdot \left(\left(u \cdot u\right) \cdot u\right) \]
              2. Final simplification23.3%

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

              Reproduce

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