Disney BSSRDF, sample scattering profile, upper

Percentage Accurate: 95.9% → 95.9%
Time: 10.3s
Alternatives: 6
Speedup: 1.0×

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: 95.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 + \frac{0.25 - u}{0.75}}\right) \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* 3.0 s) (log (/ 1.0 (+ 1.0 (/ (- 0.25 u) 0.75))))))
float code(float s, float u) {
	return (3.0f * s) * logf((1.0f / (1.0f + ((0.25f - u) / 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 + ((0.25e0 - u) / 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(Float32(0.25) - u) / Float32(0.75))))))
end
function tmp = code(s, u)
	tmp = (single(3.0) * s) * log((single(1.0) / (single(1.0) + ((single(0.25) - u) / single(0.75)))));
end
\begin{array}{l}

\\
\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 + \frac{0.25 - u}{0.75}}\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. Final simplification95.5%

    \[\leadsto \left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 + \frac{0.25 - u}{0.75}}\right) \]
  4. Add Preprocessing

Alternative 2: 95.5% accurate, 1.1× speedup?

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

\\
\left(3 \cdot s\right) \cdot \log \left(\frac{1}{u \cdot -1.3333333333333333 + 1.3333333333333333}\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. div-subN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(3 \cdot s\right) \cdot \log \left(\frac{1}{\color{blue}{u \cdot -1.3333333333333333 + 1.3333333333333333}}\right) \]
  7. Add Preprocessing

Alternative 3: 32.1% accurate, 1.1× speedup?

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

\\
\left(3 \cdot s\right) \cdot \left(u + \left(\log 0.75 + u \cdot \left(u \cdot 0.5\right)\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. Taylor expanded in u around 0

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \mathsf{fma}\left(u, \mathsf{fma}\left(u, 0.5, 1\right), \color{blue}{\log 0.75}\right) \]
  5. Applied rewrites10.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \left(\left(\log 0.75 + u \cdot \color{blue}{\left(u \cdot 0.5\right)}\right) + u\right) \]
  7. Applied rewrites32.0%

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

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

Alternative 4: 32.1% accurate, 1.1× speedup?

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

\\
\left(3 \cdot s\right) \cdot \left(u \cdot \left(u \cdot 0.5\right) + \left(u + \log 0.75\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. Taylor expanded in u around 0

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \mathsf{fma}\left(u, \mathsf{fma}\left(u, 0.5, 1\right), \color{blue}{\log 0.75}\right) \]
  5. Applied rewrites10.9%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \left(u \cdot \color{blue}{\left(u \cdot \frac{1}{2}\right)} + \left(u + \log \frac{3}{4}\right)\right) \]
    11. lower-+.f3232.0

      \[\leadsto \left(3 \cdot s\right) \cdot \left(u \cdot \left(u \cdot 0.5\right) + \color{blue}{\left(u + \log 0.75\right)}\right) \]
  7. Applied rewrites32.0%

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

Alternative 5: 29.6% accurate, 8.7× speedup?

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

\\
\left(u \cdot -1.3333333333333333\right) \cdot \left(s \cdot -3\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. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{-4}{3}} \cdot \left(u - \frac{1}{4}\right)\right) \]
    14. 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) \]
    15. distribute-lft-inN/A

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

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

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

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

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot \frac{-4}{3}} + \frac{1}{3}\right) \]
    3. lower-*.f329.5

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333} + 0.3333333333333333\right) \]
  7. Applied rewrites9.5%

    \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333 + 0.3333333333333333}\right) \]
  8. Taylor expanded in u around inf

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333}\right) \]
  10. Applied rewrites29.7%

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \color{blue}{\left(u \cdot \frac{-4}{3}\right)} \]
    2. lower-*.f3229.7

      \[\leadsto \left(s \cdot -3\right) \cdot \color{blue}{\left(u \cdot -1.3333333333333333\right)} \]
  13. Applied rewrites29.7%

    \[\leadsto \left(s \cdot -3\right) \cdot \color{blue}{\left(u \cdot -1.3333333333333333\right)} \]
  14. Final simplification29.7%

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

Alternative 6: 29.6% accurate, 12.6× speedup?

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

\\
s \cdot \left(u \cdot 4\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. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{-4}{3}} \cdot \left(u - \frac{1}{4}\right)\right) \]
    14. 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) \]
    15. distribute-lft-inN/A

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

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

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

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

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot \frac{-4}{3}} + \frac{1}{3}\right) \]
    3. lower-*.f329.5

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333} + 0.3333333333333333\right) \]
  7. Applied rewrites9.5%

    \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333 + 0.3333333333333333}\right) \]
  8. Taylor expanded in u around inf

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

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

      \[\leadsto \left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333}\right) \]
  10. Applied rewrites29.7%

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

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

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

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

      \[\leadsto \color{blue}{s \cdot \left(u \cdot 4\right)} \]
    4. lower-*.f3229.7

      \[\leadsto s \cdot \color{blue}{\left(u \cdot 4\right)} \]
  13. Applied rewrites29.7%

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

Reproduce

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