Disney BSSRDF, sample scattering profile, upper

Percentage Accurate: 95.9% → 98.3%
Time: 15.1s
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.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} \\ \left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(\frac{0.25 - u}{0.75}\right)\right) \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* 3.0 s) (- (log1p (/ (- 0.25 u) 0.75)))))
float code(float s, float u) {
	return (3.0f * s) * -log1pf(((0.25f - u) / 0.75f));
}
function code(s, u)
	return Float32(Float32(Float32(3.0) * s) * Float32(-log1p(Float32(Float32(Float32(0.25) - u) / Float32(0.75)))))
end
\begin{array}{l}

\\
\left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(\frac{0.25 - u}{0.75}\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. log-rec96.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(-\color{blue}{1.3333333333333333 \cdot \left(u + -0.25\right)}\right)\right) \]
    4. distribute-lft-neg-in97.9%

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

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

    \[\leadsto \left(3 \cdot s\right) \cdot \left(-\color{blue}{\mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u + -0.25\right)\right)}\right) \]
  8. Step-by-step derivation
    1. *-commutative97.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(\color{blue}{\frac{0.25 + \left(-u\right)}{0.75}}\right)\right) \]
  10. Step-by-step derivation
    1. unsub-neg98.3%

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

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

    \[\leadsto \left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(\frac{0.25 - u}{0.75}\right)\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. log-rec96.6%

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

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

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

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

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

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

Alternative 3: 96.8% accurate, 1.0× speedup?

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

\\
s \cdot \left(-3 \cdot \mathsf{log1p}\left(u \cdot -1.3333333333333333 + 0.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. *-commutative95.9%

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \left(-3 \cdot \mathsf{log1p}\left(\color{blue}{-1 \cdot \frac{u - 0.25}{0.75}}\right)\right) \]
    10. associate-*r/98.2%

      \[\leadsto s \cdot \left(-3 \cdot \mathsf{log1p}\left(\color{blue}{\frac{-1 \cdot \left(u - 0.25\right)}{0.75}}\right)\right) \]
    11. associate-/l*97.9%

      \[\leadsto s \cdot \left(-3 \cdot \mathsf{log1p}\left(\color{blue}{\frac{-1}{\frac{0.75}{u - 0.25}}}\right)\right) \]
    12. associate-/r/97.9%

      \[\leadsto s \cdot \left(-3 \cdot \mathsf{log1p}\left(\color{blue}{\frac{-1}{0.75} \cdot \left(u - 0.25\right)}\right)\right) \]
    13. sub-neg97.9%

      \[\leadsto s \cdot \left(-3 \cdot \mathsf{log1p}\left(\frac{-1}{0.75} \cdot \color{blue}{\left(u + \left(-0.25\right)\right)}\right)\right) \]
    14. distribute-lft-in96.8%

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

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

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

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

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

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

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

Alternative 4: 97.9% accurate, 1.0× speedup?

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

\\
\left(s \cdot -3\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u + -0.25\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. log-rec96.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(3 \cdot s\right) \cdot \left(-\mathsf{log1p}\left(-\color{blue}{1.3333333333333333 \cdot \left(u + -0.25\right)}\right)\right) \]
    4. distribute-lft-neg-in97.9%

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

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

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

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log \left(1 + -1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right)} \]
  9. Step-by-step derivation
    1. associate-*r*96.3%

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

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

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

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

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

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

Alternative 5: 28.1% 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. add-log-exp9.9%

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

      \[\leadsto \log \left(e^{\color{blue}{\log 0.75 \cdot \left(3 \cdot s\right)}}\right) \]
    3. exp-to-pow9.9%

      \[\leadsto \log \color{blue}{\left({0.75}^{\left(3 \cdot s\right)}\right)} \]
    4. add-sqr-sqrt9.9%

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(\sqrt{3 \cdot s} \cdot \sqrt{3 \cdot s}\right)}}\right) \]
    5. sqrt-unprod9.9%

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(\sqrt{\left(3 \cdot s\right) \cdot \left(3 \cdot s\right)}\right)}}\right) \]
    6. swap-sqr9.9%

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

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

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

      \[\leadsto \log \left({0.75}^{\left(\sqrt{\color{blue}{\left(-3 \cdot s\right) \cdot \left(-3 \cdot s\right)}}\right)}\right) \]
    10. *-commutative9.9%

      \[\leadsto \log \left({0.75}^{\left(\sqrt{\color{blue}{\left(s \cdot -3\right)} \cdot \left(-3 \cdot s\right)}\right)}\right) \]
    11. *-commutative9.9%

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

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(\sqrt{s \cdot -3} \cdot \sqrt{s \cdot -3}\right)}}\right) \]
    13. add-sqr-sqrt15.7%

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(s \cdot -3\right)}}\right) \]
    14. *-commutative15.7%

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

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

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

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

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

Alternative 6: 28.1% accurate, 1.1× speedup?

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

\\
s \cdot \mathsf{log1p}\left(1.3703703703703705\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. add-log-exp9.9%

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

      \[\leadsto \log \left(e^{\color{blue}{\log 0.75 \cdot \left(3 \cdot s\right)}}\right) \]
    3. exp-to-pow9.9%

      \[\leadsto \log \color{blue}{\left({0.75}^{\left(3 \cdot s\right)}\right)} \]
    4. add-sqr-sqrt9.9%

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(\sqrt{3 \cdot s} \cdot \sqrt{3 \cdot s}\right)}}\right) \]
    5. sqrt-unprod9.9%

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(\sqrt{\left(3 \cdot s\right) \cdot \left(3 \cdot s\right)}\right)}}\right) \]
    6. swap-sqr9.9%

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

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

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

      \[\leadsto \log \left({0.75}^{\left(\sqrt{\color{blue}{\left(-3 \cdot s\right) \cdot \left(-3 \cdot s\right)}}\right)}\right) \]
    10. *-commutative9.9%

      \[\leadsto \log \left({0.75}^{\left(\sqrt{\color{blue}{\left(s \cdot -3\right)} \cdot \left(-3 \cdot s\right)}\right)}\right) \]
    11. *-commutative9.9%

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

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(\sqrt{s \cdot -3} \cdot \sqrt{s \cdot -3}\right)}}\right) \]
    13. add-sqr-sqrt15.7%

      \[\leadsto \log \left({0.75}^{\color{blue}{\left(s \cdot -3\right)}}\right) \]
    14. *-commutative15.7%

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

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

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

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

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

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

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

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

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

      \[\leadsto s \cdot \mathsf{log1p}\left(\color{blue}{{0.75}^{-3}} - 1\right) \]
    5. metadata-eval28.1%

      \[\leadsto s \cdot \mathsf{log1p}\left(\color{blue}{2.3703703703703702} - 1\right) \]
    6. metadata-eval28.1%

      \[\leadsto s \cdot \mathsf{log1p}\left(\color{blue}{1.3703703703703705}\right) \]
  8. Applied egg-rr28.1%

    \[\leadsto s \cdot \color{blue}{\mathsf{log1p}\left(1.3703703703703705\right)} \]
  9. Final simplification28.1%

    \[\leadsto s \cdot \mathsf{log1p}\left(1.3703703703703705\right) \]

Alternative 7: 10.5% accurate, 113.0× speedup?

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

\\
0
\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. log-rec96.6%

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

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

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

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

    \[\leadsto \color{blue}{-3 \cdot \left(s \cdot \log \left(1 - 1.3333333333333333 \cdot \left(u - 0.25\right)\right)\right)} \]
  5. Step-by-step derivation
    1. associate-*r*96.3%

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

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

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

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

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

      \[\leadsto \mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u + \color{blue}{-0.25}\right)\right) \cdot \left(-3 \cdot s\right) \]
    7. distribute-lft-neg-in97.9%

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \cdot \left(-3 \cdot s\right)} \]
  7. Step-by-step derivation
    1. associate-*r*97.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\log \left(e^{s \cdot \left(\mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot -3\right)}\right)} \]
    7. *-commutative25.3%

      \[\leadsto \log \left(e^{\color{blue}{\left(\mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot -3\right) \cdot s}}\right) \]
    8. fma-udef25.2%

      \[\leadsto \log \left(e^{\left(\mathsf{log1p}\left(\color{blue}{-1.3333333333333333 \cdot u + 0.3333333333333333}\right) \cdot -3\right) \cdot s}\right) \]
    9. *-commutative25.2%

      \[\leadsto \log \left(e^{\left(\mathsf{log1p}\left(\color{blue}{u \cdot -1.3333333333333333} + 0.3333333333333333\right) \cdot -3\right) \cdot s}\right) \]
    10. fma-udef25.3%

      \[\leadsto \log \left(e^{\left(\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)}\right) \cdot -3\right) \cdot s}\right) \]
    11. associate-*r*25.3%

      \[\leadsto \log \left(e^{\color{blue}{\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \cdot \left(-3 \cdot s\right)}}\right) \]
    12. log1p-udef25.2%

      \[\leadsto \log \left(e^{\color{blue}{\log \left(1 + \mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right)} \cdot \left(-3 \cdot s\right)}\right) \]
    13. fma-udef25.1%

      \[\leadsto \log \left(e^{\log \left(1 + \color{blue}{\left(u \cdot -1.3333333333333333 + 0.3333333333333333\right)}\right) \cdot \left(-3 \cdot s\right)}\right) \]
    14. *-commutative25.1%

      \[\leadsto \log \left(e^{\log \left(1 + \left(\color{blue}{-1.3333333333333333 \cdot u} + 0.3333333333333333\right)\right) \cdot \left(-3 \cdot s\right)}\right) \]
    15. fma-udef25.2%

      \[\leadsto \log \left(e^{\log \left(1 + \color{blue}{\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)}\right) \cdot \left(-3 \cdot s\right)}\right) \]
    16. *-commutative25.2%

      \[\leadsto \log \left(e^{\log \left(1 + \mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot \color{blue}{\left(s \cdot -3\right)}}\right) \]
    17. exp-to-pow25.2%

      \[\leadsto \log \color{blue}{\left({\left(1 + \mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right)}^{\left(s \cdot -3\right)}\right)} \]
  8. Applied egg-rr25.2%

    \[\leadsto \color{blue}{\log \left({\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right) + 1\right)}^{\left(-3 \cdot s\right)}\right)} \]
  9. Taylor expanded in s around 0 10.7%

    \[\leadsto \log \color{blue}{1} \]
  10. Final simplification10.7%

    \[\leadsto 0 \]

Reproduce

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