Disney BSSRDF, sample scattering profile, upper

Percentage Accurate: 95.9% → 98.3%
Time: 9.8s
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: 98.3% accurate, 1.0× speedup?

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

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

    \[\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*96.0%

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

      \[\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.9%

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

      \[\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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 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.9%

    \[\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*96.0%

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

      \[\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.9%

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

      \[\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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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. Taylor expanded in u around 0 97.1%

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

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

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

Alternative 3: 97.9% accurate, 1.0× speedup?

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

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

    \[\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*96.0%

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

      \[\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.9%

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

      \[\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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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(\left(0.25 - u\right) \cdot 1.3333333333333333\right)\right) \]

Alternative 4: 28.0% accurate, 1.1× speedup?

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

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

    \[\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 7.6%

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(3 \cdot s\right) \cdot \log 0.75\right)} - 1} \]
    3. add-sqr-sqrt9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{3 \cdot s} \cdot \sqrt{3 \cdot s}\right)} \cdot \log 0.75\right)} - 1 \]
    4. sqrt-unprod9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\left(3 \cdot s\right) \cdot \left(3 \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    5. swap-sqr9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(3 \cdot 3\right) \cdot \left(s \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    6. metadata-eval9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{9} \cdot \left(s \cdot s\right)} \cdot \log 0.75\right)} - 1 \]
    7. metadata-eval9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(-3 \cdot -3\right)} \cdot \left(s \cdot s\right)} \cdot \log 0.75\right)} - 1 \]
    8. swap-sqr9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(-3 \cdot s\right) \cdot \left(-3 \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    9. sqrt-unprod-0.0%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{-3 \cdot s} \cdot \sqrt{-3 \cdot s}\right)} \cdot \log 0.75\right)} - 1 \]
    10. add-sqr-sqrt15.1%

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-3 \cdot s\right) \cdot \log 0.75\right)} - 1} \]
  5. Step-by-step derivation
    1. expm1-def28.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(-3 \cdot s\right) \cdot \log 0.75\right)\right)} \]
    2. expm1-log1p28.3%

      \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \log 0.75} \]
    3. associate-*l*28.3%

      \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
  6. Simplified28.3%

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
  7. Final simplification28.3%

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

Alternative 5: 28.0% accurate, 1.1× speedup?

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

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

    \[\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 7.6%

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(3 \cdot s\right) \cdot \log 0.75\right)} - 1} \]
    3. add-sqr-sqrt9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{3 \cdot s} \cdot \sqrt{3 \cdot s}\right)} \cdot \log 0.75\right)} - 1 \]
    4. sqrt-unprod9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\left(3 \cdot s\right) \cdot \left(3 \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    5. swap-sqr9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(3 \cdot 3\right) \cdot \left(s \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    6. metadata-eval9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{9} \cdot \left(s \cdot s\right)} \cdot \log 0.75\right)} - 1 \]
    7. metadata-eval9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(-3 \cdot -3\right)} \cdot \left(s \cdot s\right)} \cdot \log 0.75\right)} - 1 \]
    8. swap-sqr9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(-3 \cdot s\right) \cdot \left(-3 \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    9. sqrt-unprod-0.0%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{-3 \cdot s} \cdot \sqrt{-3 \cdot s}\right)} \cdot \log 0.75\right)} - 1 \]
    10. add-sqr-sqrt15.1%

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-3 \cdot s\right) \cdot \log 0.75\right)} - 1} \]
  5. Step-by-step derivation
    1. expm1-def28.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(-3 \cdot s\right) \cdot \log 0.75\right)\right)} \]
    2. expm1-log1p28.3%

      \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \log 0.75} \]
    3. associate-*l*28.3%

      \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
  6. Simplified28.3%

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
  7. Step-by-step derivation
    1. pow128.3%

      \[\leadsto \color{blue}{{\left(-3 \cdot \left(s \cdot \log 0.75\right)\right)}^{1}} \]
  8. Applied egg-rr28.3%

    \[\leadsto \color{blue}{{\left(-3 \cdot \left(s \cdot \log 0.75\right)\right)}^{1}} \]
  9. Step-by-step derivation
    1. unpow128.3%

      \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
    2. *-commutative28.3%

      \[\leadsto \color{blue}{\left(s \cdot \log 0.75\right) \cdot -3} \]
    3. associate-*l*28.3%

      \[\leadsto \color{blue}{s \cdot \left(\log 0.75 \cdot -3\right)} \]
  10. Simplified28.3%

    \[\leadsto \color{blue}{s \cdot \left(\log 0.75 \cdot -3\right)} \]
  11. Final simplification28.3%

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

Alternative 6: 28.0% accurate, 1.1× speedup?

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

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

    \[\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 7.6%

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(3 \cdot s\right) \cdot \log 0.75\right)} - 1} \]
    3. add-sqr-sqrt9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{3 \cdot s} \cdot \sqrt{3 \cdot s}\right)} \cdot \log 0.75\right)} - 1 \]
    4. sqrt-unprod9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\left(3 \cdot s\right) \cdot \left(3 \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    5. swap-sqr9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(3 \cdot 3\right) \cdot \left(s \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    6. metadata-eval9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{9} \cdot \left(s \cdot s\right)} \cdot \log 0.75\right)} - 1 \]
    7. metadata-eval9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(-3 \cdot -3\right)} \cdot \left(s \cdot s\right)} \cdot \log 0.75\right)} - 1 \]
    8. swap-sqr9.8%

      \[\leadsto e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(-3 \cdot s\right) \cdot \left(-3 \cdot s\right)}} \cdot \log 0.75\right)} - 1 \]
    9. sqrt-unprod-0.0%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{-3 \cdot s} \cdot \sqrt{-3 \cdot s}\right)} \cdot \log 0.75\right)} - 1 \]
    10. add-sqr-sqrt15.1%

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-3 \cdot s\right) \cdot \log 0.75\right)} - 1} \]
  5. Step-by-step derivation
    1. expm1-def28.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(-3 \cdot s\right) \cdot \log 0.75\right)\right)} \]
    2. expm1-log1p28.3%

      \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \log 0.75} \]
    3. associate-*l*28.3%

      \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
  6. Simplified28.3%

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
  7. Step-by-step derivation
    1. pow128.3%

      \[\leadsto \color{blue}{{\left(-3 \cdot \left(s \cdot \log 0.75\right)\right)}^{1}} \]
  8. Applied egg-rr28.3%

    \[\leadsto \color{blue}{{\left(-3 \cdot \left(s \cdot \log 0.75\right)\right)}^{1}} \]
  9. Step-by-step derivation
    1. unpow128.3%

      \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log 0.75\right)} \]
    2. associate-*r*28.3%

      \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \log 0.75} \]
  10. Simplified28.3%

    \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \log 0.75} \]
  11. Final simplification28.3%

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

Reproduce

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