Disney BSSRDF, sample scattering profile, upper

Percentage Accurate: 95.8% → 98.3%
Time: 15.3s
Alternatives: 7
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 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: 98.3% accurate, 0.3× speedup?

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

\\
s \cdot \left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) \cdot -3 - -3 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\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. Step-by-step derivation
    1. associate-*l*95.5%

      \[\leadsto \color{blue}{3 \cdot \left(s \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)\right)} \]
    2. *-commutative95.5%

      \[\leadsto \color{blue}{\left(s \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)\right) \cdot 3} \]
    3. associate-*l*95.5%

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

      \[\leadsto s \cdot \left(\color{blue}{\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right)\right)} \cdot 3\right) \]
    5. distribute-lft-neg-out96.4%

      \[\leadsto s \cdot \color{blue}{\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right) \cdot 3\right)} \]
    6. distribute-rgt-neg-in96.4%

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

    \[\leadsto \color{blue}{s \cdot \left(\log \left(\mathsf{fma}\left(u, -1.3333333333333333, 1.3333333333333333\right)\right) \cdot -3\right)} \]
  4. Step-by-step derivation
    1. fma-udef95.8%

      \[\leadsto s \cdot \left(\log \color{blue}{\left(u \cdot -1.3333333333333333 + 1.3333333333333333\right)} \cdot -3\right) \]
    2. *-commutative95.8%

      \[\leadsto s \cdot \left(\log \left(\color{blue}{-1.3333333333333333 \cdot u} + 1.3333333333333333\right) \cdot -3\right) \]
    3. +-commutative95.8%

      \[\leadsto s \cdot \left(\log \color{blue}{\left(1.3333333333333333 + -1.3333333333333333 \cdot u\right)} \cdot -3\right) \]
    4. metadata-eval95.8%

      \[\leadsto s \cdot \left(\log \left(\color{blue}{\left(1 + 0.3333333333333333\right)} + -1.3333333333333333 \cdot u\right) \cdot -3\right) \]
    5. associate-+r+95.3%

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

      \[\leadsto s \cdot \left(\log \left(1 + \color{blue}{\left(-1.3333333333333333 \cdot u + 0.3333333333333333\right)}\right) \cdot -3\right) \]
    7. log1p-udef96.9%

      \[\leadsto s \cdot \left(\color{blue}{\mathsf{log1p}\left(-1.3333333333333333 \cdot u + 0.3333333333333333\right)} \cdot -3\right) \]
    8. *-commutative96.9%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333} + 0.3333333333333333\right) \cdot -3\right) \]
    9. fma-def98.1%

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

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

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333 + 0.3333333333333333}\right) \cdot -3\right) \]
    2. metadata-eval96.9%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(u \cdot -1.3333333333333333 + \color{blue}{-0.25 \cdot -1.3333333333333333}\right) \cdot -3\right) \]
    3. metadata-eval96.9%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(u \cdot -1.3333333333333333 + \color{blue}{\left(-0.25\right)} \cdot -1.3333333333333333\right) \cdot -3\right) \]
    4. distribute-rgt-in98.1%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{-1.3333333333333333 \cdot \left(u + \left(-0.25\right)\right)}\right) \cdot -3\right) \]
    5. metadata-eval98.1%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{\left(-1.3333333333333333\right)} \cdot \left(u + \left(-0.25\right)\right)\right) \cdot -3\right) \]
    6. sub-neg98.1%

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

      \[\leadsto s \cdot \left(\color{blue}{\log \left(1 + \left(-1.3333333333333333\right) \cdot \left(u - 0.25\right)\right)} \cdot -3\right) \]
    8. cancel-sign-sub-inv96.3%

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

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

      \[\leadsto s \cdot \left(\color{blue}{\left(\log \left(1 \cdot 1 - \left(1.3333333333333333 \cdot \left(u - 0.25\right)\right) \cdot \left(1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) - \log \left(1 + 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right)} \cdot -3\right) \]
    11. metadata-eval95.6%

      \[\leadsto s \cdot \left(\left(\log \left(\color{blue}{1} - \left(1.3333333333333333 \cdot \left(u - 0.25\right)\right) \cdot \left(1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) - \log \left(1 + 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot -3\right) \]
    12. swap-sqr95.4%

      \[\leadsto s \cdot \left(\left(\log \left(1 - \color{blue}{\left(1.3333333333333333 \cdot 1.3333333333333333\right) \cdot \left(\left(u - 0.25\right) \cdot \left(u - 0.25\right)\right)}\right) - \log \left(1 + 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot -3\right) \]
    13. metadata-eval95.8%

      \[\leadsto s \cdot \left(\left(\log \left(1 - \color{blue}{1.7777777777777777} \cdot \left(\left(u - 0.25\right) \cdot \left(u - 0.25\right)\right)\right) - \log \left(1 + 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot -3\right) \]
    14. pow295.8%

      \[\leadsto s \cdot \left(\left(\log \left(1 - 1.7777777777777777 \cdot \color{blue}{{\left(u - 0.25\right)}^{2}}\right) - \log \left(1 + 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot -3\right) \]
    15. sub-neg95.8%

      \[\leadsto s \cdot \left(\left(\log \left(1 - 1.7777777777777777 \cdot {\color{blue}{\left(u + \left(-0.25\right)\right)}}^{2}\right) - \log \left(1 + 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot -3\right) \]
    16. metadata-eval95.8%

      \[\leadsto s \cdot \left(\left(\log \left(1 - 1.7777777777777777 \cdot {\left(u + \color{blue}{-0.25}\right)}^{2}\right) - \log \left(1 + 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right) \cdot -3\right) \]
    17. log1p-udef96.9%

      \[\leadsto s \cdot \left(\left(\log \left(1 - 1.7777777777777777 \cdot {\left(u + -0.25\right)}^{2}\right) - \color{blue}{\mathsf{log1p}\left(1.3333333333333333 \cdot \left(u - 0.25\right)\right)}\right) \cdot -3\right) \]
    18. sub-neg96.9%

      \[\leadsto s \cdot \left(\left(\log \left(1 - 1.7777777777777777 \cdot {\left(u + -0.25\right)}^{2}\right) - \mathsf{log1p}\left(1.3333333333333333 \cdot \color{blue}{\left(u + \left(-0.25\right)\right)}\right)\right) \cdot -3\right) \]
  7. Applied egg-rr96.7%

    \[\leadsto s \cdot \left(\color{blue}{\left(\log \left(1 - 1.7777777777777777 \cdot {\left(u + -0.25\right)}^{2}\right) - \mathsf{log1p}\left(1.3333333333333333 \cdot u + -0.3333333333333333\right)\right)} \cdot -3\right) \]
  8. Step-by-step derivation
    1. sub-neg96.7%

      \[\leadsto s \cdot \left(\left(\log \color{blue}{\left(1 + \left(-1.7777777777777777 \cdot {\left(u + -0.25\right)}^{2}\right)\right)} - \mathsf{log1p}\left(1.3333333333333333 \cdot u + -0.3333333333333333\right)\right) \cdot -3\right) \]
    2. log1p-def97.7%

      \[\leadsto s \cdot \left(\left(\color{blue}{\mathsf{log1p}\left(-1.7777777777777777 \cdot {\left(u + -0.25\right)}^{2}\right)} - \mathsf{log1p}\left(1.3333333333333333 \cdot u + -0.3333333333333333\right)\right) \cdot -3\right) \]
    3. *-commutative97.7%

      \[\leadsto s \cdot \left(\left(\mathsf{log1p}\left(-\color{blue}{{\left(u + -0.25\right)}^{2} \cdot 1.7777777777777777}\right) - \mathsf{log1p}\left(1.3333333333333333 \cdot u + -0.3333333333333333\right)\right) \cdot -3\right) \]
    4. distribute-rgt-neg-in97.7%

      \[\leadsto s \cdot \left(\left(\mathsf{log1p}\left(\color{blue}{{\left(u + -0.25\right)}^{2} \cdot \left(-1.7777777777777777\right)}\right) - \mathsf{log1p}\left(1.3333333333333333 \cdot u + -0.3333333333333333\right)\right) \cdot -3\right) \]
    5. metadata-eval97.7%

      \[\leadsto s \cdot \left(\left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot \color{blue}{-1.7777777777777777}\right) - \mathsf{log1p}\left(1.3333333333333333 \cdot u + -0.3333333333333333\right)\right) \cdot -3\right) \]
    6. fma-def98.4%

      \[\leadsto s \cdot \left(\left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) - \mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)}\right)\right) \cdot -3\right) \]
  9. Simplified98.4%

    \[\leadsto s \cdot \left(\color{blue}{\left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) - \mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)\right)\right)} \cdot -3\right) \]
  10. Step-by-step derivation
    1. *-commutative98.4%

      \[\leadsto s \cdot \color{blue}{\left(-3 \cdot \left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) - \mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)\right)\right)\right)} \]
    2. sub-neg98.4%

      \[\leadsto s \cdot \left(-3 \cdot \color{blue}{\left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) + \left(-\mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)\right)\right)\right)}\right) \]
    3. distribute-rgt-in98.4%

      \[\leadsto s \cdot \color{blue}{\left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) \cdot -3 + \left(-\mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)\right)\right) \cdot -3\right)} \]
  11. Applied egg-rr98.4%

    \[\leadsto s \cdot \color{blue}{\left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) \cdot -3 + \left(-\mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)\right)\right) \cdot -3\right)} \]
  12. Final simplification98.4%

    \[\leadsto s \cdot \left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) \cdot -3 - -3 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)\right)\right) \]

Alternative 2: 98.3% accurate, 1.0× speedup?

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

\\
\left(s \cdot 3\right) \cdot \left(-\mathsf{log1p}\left(\frac{\left(--0.25\right) - u}{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. Step-by-step derivation
    1. log-rec96.5%

      \[\leadsto \left(3 \cdot s\right) \cdot \color{blue}{\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right)\right)} \]
    2. sub-neg96.5%

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\log \color{blue}{\left(1 + \left(-\frac{u - 0.25}{0.75}\right)\right)}\right) \]
    3. log1p-def98.4%

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\color{blue}{\mathsf{log1p}\left(-\frac{u - 0.25}{0.75}\right)}\right) \]
    4. distribute-neg-frac98.4%

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(\color{blue}{\frac{-\left(u - 0.25\right)}{0.75}}\right)\right) \]
    5. sub-neg98.4%

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

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

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

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

Alternative 3: 96.1% accurate, 1.0× speedup?

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

\\
-3 \cdot \left(s \cdot \log \left(1.3333333333333333 - u \cdot 1.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. Step-by-step derivation
    1. associate-*l*95.5%

      \[\leadsto \color{blue}{3 \cdot \left(s \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)\right)} \]
    2. log-rec96.5%

      \[\leadsto 3 \cdot \left(s \cdot \color{blue}{\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right)\right)}\right) \]
    3. div-sub95.5%

      \[\leadsto 3 \cdot \left(s \cdot \left(-\log \left(1 - \color{blue}{\left(\frac{u}{0.75} - \frac{0.25}{0.75}\right)}\right)\right)\right) \]
    4. metadata-eval95.5%

      \[\leadsto 3 \cdot \left(s \cdot \left(-\log \left(1 - \left(\frac{u}{0.75} - \color{blue}{0.3333333333333333}\right)\right)\right)\right) \]
  3. Simplified95.5%

    \[\leadsto \color{blue}{3 \cdot \left(s \cdot \left(-\log \left(1 - \left(\frac{u}{0.75} - 0.3333333333333333\right)\right)\right)\right)} \]
  4. Taylor expanded in s around 0 95.9%

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log \left(1.3333333333333333 - 1.3333333333333333 \cdot u\right)\right)} \]
  5. Final simplification95.9%

    \[\leadsto -3 \cdot \left(s \cdot \log \left(1.3333333333333333 - u \cdot 1.3333333333333333\right)\right) \]

Alternative 4: 97.9% accurate, 1.0× speedup?

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

\\
-3 \cdot \left(s \cdot \mathsf{log1p}\left(1.3333333333333333 \cdot \left(0.25 - u\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. Step-by-step derivation
    1. log-rec96.5%

      \[\leadsto \left(3 \cdot s\right) \cdot \color{blue}{\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right)\right)} \]
    2. sub-neg96.5%

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\log \color{blue}{\left(1 + \left(-\frac{u - 0.25}{0.75}\right)\right)}\right) \]
    3. log1p-def98.4%

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\color{blue}{\mathsf{log1p}\left(-\frac{u - 0.25}{0.75}\right)}\right) \]
    4. distribute-neg-frac98.4%

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(\color{blue}{\frac{-\left(u - 0.25\right)}{0.75}}\right)\right) \]
    5. sub-neg98.4%

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

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

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

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log \left(1 + 1.3333333333333333 \cdot \left(0.25 - u\right)\right)\right)} \]
  5. Step-by-step derivation
    1. log1p-def98.0%

      \[\leadsto -3 \cdot \left(s \cdot \color{blue}{\mathsf{log1p}\left(1.3333333333333333 \cdot \left(0.25 - u\right)\right)}\right) \]
  6. Simplified98.0%

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

    \[\leadsto -3 \cdot \left(s \cdot \mathsf{log1p}\left(1.3333333333333333 \cdot \left(0.25 - u\right)\right)\right) \]

Alternative 5: 97.9% accurate, 1.0× speedup?

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

\\
s \cdot \left(-3 \cdot \mathsf{log1p}\left(\left(u + -0.25\right) \cdot -1.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. Step-by-step derivation
    1. associate-*l*95.5%

      \[\leadsto \color{blue}{3 \cdot \left(s \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)\right)} \]
    2. *-commutative95.5%

      \[\leadsto \color{blue}{\left(s \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)\right) \cdot 3} \]
    3. associate-*l*95.5%

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

      \[\leadsto s \cdot \left(\color{blue}{\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right)\right)} \cdot 3\right) \]
    5. distribute-lft-neg-out96.4%

      \[\leadsto s \cdot \color{blue}{\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right) \cdot 3\right)} \]
    6. distribute-rgt-neg-in96.4%

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

    \[\leadsto \color{blue}{s \cdot \left(\log \left(\mathsf{fma}\left(u, -1.3333333333333333, 1.3333333333333333\right)\right) \cdot -3\right)} \]
  4. Step-by-step derivation
    1. fma-udef95.8%

      \[\leadsto s \cdot \left(\log \color{blue}{\left(u \cdot -1.3333333333333333 + 1.3333333333333333\right)} \cdot -3\right) \]
    2. *-commutative95.8%

      \[\leadsto s \cdot \left(\log \left(\color{blue}{-1.3333333333333333 \cdot u} + 1.3333333333333333\right) \cdot -3\right) \]
    3. +-commutative95.8%

      \[\leadsto s \cdot \left(\log \color{blue}{\left(1.3333333333333333 + -1.3333333333333333 \cdot u\right)} \cdot -3\right) \]
    4. metadata-eval95.8%

      \[\leadsto s \cdot \left(\log \left(\color{blue}{\left(1 + 0.3333333333333333\right)} + -1.3333333333333333 \cdot u\right) \cdot -3\right) \]
    5. associate-+r+95.3%

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

      \[\leadsto s \cdot \left(\log \left(1 + \color{blue}{\left(-1.3333333333333333 \cdot u + 0.3333333333333333\right)}\right) \cdot -3\right) \]
    7. log1p-udef96.9%

      \[\leadsto s \cdot \left(\color{blue}{\mathsf{log1p}\left(-1.3333333333333333 \cdot u + 0.3333333333333333\right)} \cdot -3\right) \]
    8. *-commutative96.9%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333} + 0.3333333333333333\right) \cdot -3\right) \]
    9. fma-def98.1%

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

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

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333 + 0.3333333333333333}\right) \cdot -3\right) \]
    2. metadata-eval96.9%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(u \cdot -1.3333333333333333 + \color{blue}{-0.25 \cdot -1.3333333333333333}\right) \cdot -3\right) \]
    3. metadata-eval96.9%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(u \cdot -1.3333333333333333 + \color{blue}{\left(-0.25\right)} \cdot -1.3333333333333333\right) \cdot -3\right) \]
    4. distribute-rgt-in98.1%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{-1.3333333333333333 \cdot \left(u + \left(-0.25\right)\right)}\right) \cdot -3\right) \]
    5. sub-neg98.1%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(-1.3333333333333333 \cdot \color{blue}{\left(u - 0.25\right)}\right) \cdot -3\right) \]
    6. *-commutative98.1%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{\left(u - 0.25\right) \cdot -1.3333333333333333}\right) \cdot -3\right) \]
    7. sub-neg98.1%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{\left(u + \left(-0.25\right)\right)} \cdot -1.3333333333333333\right) \cdot -3\right) \]
    8. metadata-eval98.1%

      \[\leadsto s \cdot \left(\mathsf{log1p}\left(\left(u + \color{blue}{-0.25}\right) \cdot -1.3333333333333333\right) \cdot -3\right) \]
  7. Applied egg-rr98.1%

    \[\leadsto s \cdot \left(\mathsf{log1p}\left(\color{blue}{\left(u + -0.25\right) \cdot -1.3333333333333333}\right) \cdot -3\right) \]
  8. Final simplification98.1%

    \[\leadsto s \cdot \left(-3 \cdot \mathsf{log1p}\left(\left(u + -0.25\right) \cdot -1.3333333333333333\right)\right) \]

Alternative 6: 29.9% accurate, 22.6× speedup?

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

\\
3 \cdot \left(s \cdot u\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. Taylor expanded in u around 0 25.3%

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

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

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

Alternative 7: 29.9% accurate, 22.6× speedup?

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

\\
s \cdot \left(u \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. Taylor expanded in u around 0 25.3%

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

    \[\leadsto \color{blue}{3 \cdot \left(s \cdot u\right)} \]
  4. Step-by-step derivation
    1. expm1-log1p-u29.7%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(3 \cdot \left(s \cdot u\right)\right)\right)} \]
    2. expm1-udef15.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(3 \cdot \left(s \cdot u\right)\right)} - 1} \]
    3. associate-*r*15.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(3 \cdot s\right) \cdot u}\right)} - 1 \]
    4. *-commutative15.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{u \cdot \left(3 \cdot s\right)}\right)} - 1 \]
  5. Applied egg-rr15.8%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(u \cdot \left(3 \cdot s\right)\right)} - 1} \]
  6. Step-by-step derivation
    1. expm1-def29.7%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(u \cdot \left(3 \cdot s\right)\right)\right)} \]
    2. expm1-log1p29.7%

      \[\leadsto \color{blue}{u \cdot \left(3 \cdot s\right)} \]
    3. associate-*r*29.7%

      \[\leadsto \color{blue}{\left(u \cdot 3\right) \cdot s} \]
  7. Simplified29.7%

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

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

Reproduce

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