Disney BSSRDF, sample scattering profile, lower

?

Percentage Accurate: 61.2% → 99.3%
Time: 13.5s
Precision: binary32
Cost: 9984

?

\[\left(0 \leq s \land s \leq 256\right) \land \left(2.328306437 \cdot 10^{-10} \leq u \land u \leq 0.25\right)\]
\[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
\[\mathsf{fma}\left(\mathsf{log1p}\left(u \cdot 4\right), s, s \cdot \left(-\mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right)\right) \]
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
(FPCore (s u)
 :precision binary32
 (fma (log1p (* u 4.0)) s (* s (- (log1p (* u (* u -16.0)))))))
float code(float s, float u) {
	return s * logf((1.0f / (1.0f - (4.0f * u))));
}
float code(float s, float u) {
	return fmaf(log1pf((u * 4.0f)), s, (s * -log1pf((u * (u * -16.0f)))));
}
function code(s, u)
	return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u)))))
end
function code(s, u)
	return fma(log1p(Float32(u * Float32(4.0))), s, Float32(s * Float32(-log1p(Float32(u * Float32(u * Float32(-16.0)))))))
end
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\mathsf{fma}\left(\mathsf{log1p}\left(u \cdot 4\right), s, s \cdot \left(-\mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right)\right)

Local Percentage Accuracy?

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.

Derivation?

  1. Initial program 60.6%

    \[s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]
  2. Simplified99.2%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(u \cdot -4\right) \cdot \left(-s\right)} \]
    Step-by-step derivation

    [Start]60.6

    \[ s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right) \]

    *-commutative [=>]60.6

    \[ \color{blue}{\log \left(\frac{1}{1 - 4 \cdot u}\right) \cdot s} \]

    log-rec [=>]63.6

    \[ \color{blue}{\left(-\log \left(1 - 4 \cdot u\right)\right)} \cdot s \]

    distribute-lft-neg-out [=>]63.6

    \[ \color{blue}{-\log \left(1 - 4 \cdot u\right) \cdot s} \]

    distribute-rgt-neg-in [=>]63.6

    \[ \color{blue}{\log \left(1 - 4 \cdot u\right) \cdot \left(-s\right)} \]

    sub-neg [=>]63.6

    \[ \log \color{blue}{\left(1 + \left(-4 \cdot u\right)\right)} \cdot \left(-s\right) \]

    log1p-def [=>]99.2

    \[ \color{blue}{\mathsf{log1p}\left(-4 \cdot u\right)} \cdot \left(-s\right) \]

    *-commutative [=>]99.2

    \[ \mathsf{log1p}\left(-\color{blue}{u \cdot 4}\right) \cdot \left(-s\right) \]

    distribute-rgt-neg-in [=>]99.2

    \[ \mathsf{log1p}\left(\color{blue}{u \cdot \left(-4\right)}\right) \cdot \left(-s\right) \]

    metadata-eval [=>]99.2

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

    \[\leadsto \color{blue}{\left({\left(\sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right)}^{2} \cdot \sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right)} \cdot \left(-s\right) \]
    Step-by-step derivation

    [Start]99.2

    \[ \mathsf{log1p}\left(u \cdot -4\right) \cdot \left(-s\right) \]

    add-cube-cbrt [=>]97.8

    \[ \color{blue}{\left(\left(\sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)} \cdot \sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right) \cdot \sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right)} \cdot \left(-s\right) \]

    pow2 [=>]97.7

    \[ \left(\color{blue}{{\left(\sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right)}^{2}} \cdot \sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right) \cdot \left(-s\right) \]
  4. Applied egg-rr60.4%

    \[\leadsto \color{blue}{\left(\log \left(1 - 16 \cdot \left(u \cdot u\right)\right) - \log \left(1 - u \cdot -4\right)\right)} \cdot \left(-s\right) \]
    Step-by-step derivation

    [Start]97.7

    \[ \left({\left(\sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right)}^{2} \cdot \sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right) \cdot \left(-s\right) \]

    unpow2 [=>]97.8

    \[ \left(\color{blue}{\left(\sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)} \cdot \sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right)} \cdot \sqrt[3]{\mathsf{log1p}\left(u \cdot -4\right)}\right) \cdot \left(-s\right) \]

    add-cube-cbrt [<=]99.2

    \[ \color{blue}{\mathsf{log1p}\left(u \cdot -4\right)} \cdot \left(-s\right) \]

    log1p-udef [=>]63.6

    \[ \color{blue}{\log \left(1 + u \cdot -4\right)} \cdot \left(-s\right) \]

    flip-+ [=>]60.4

    \[ \log \color{blue}{\left(\frac{1 \cdot 1 - \left(u \cdot -4\right) \cdot \left(u \cdot -4\right)}{1 - u \cdot -4}\right)} \cdot \left(-s\right) \]

    log-div [=>]60.4

    \[ \color{blue}{\left(\log \left(1 \cdot 1 - \left(u \cdot -4\right) \cdot \left(u \cdot -4\right)\right) - \log \left(1 - u \cdot -4\right)\right)} \cdot \left(-s\right) \]

    metadata-eval [=>]60.4

    \[ \left(\log \left(\color{blue}{1} - \left(u \cdot -4\right) \cdot \left(u \cdot -4\right)\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    *-commutative [=>]60.4

    \[ \left(\log \left(1 - \color{blue}{\left(-4 \cdot u\right)} \cdot \left(u \cdot -4\right)\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    *-commutative [=>]60.4

    \[ \left(\log \left(1 - \left(-4 \cdot u\right) \cdot \color{blue}{\left(-4 \cdot u\right)}\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    swap-sqr [=>]60.4

    \[ \left(\log \left(1 - \color{blue}{\left(-4 \cdot -4\right) \cdot \left(u \cdot u\right)}\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    metadata-eval [=>]60.4

    \[ \left(\log \left(1 - \color{blue}{16} \cdot \left(u \cdot u\right)\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]
  5. Simplified99.0%

    \[\leadsto \color{blue}{\left(\mathsf{log1p}\left(\left(u \cdot u\right) \cdot -16\right) - \mathsf{log1p}\left(u \cdot 4\right)\right)} \cdot \left(-s\right) \]
    Step-by-step derivation

    [Start]60.4

    \[ \left(\log \left(1 - 16 \cdot \left(u \cdot u\right)\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    sub-neg [=>]60.4

    \[ \left(\log \color{blue}{\left(1 + \left(-16 \cdot \left(u \cdot u\right)\right)\right)} - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    log1p-def [=>]60.9

    \[ \left(\color{blue}{\mathsf{log1p}\left(-16 \cdot \left(u \cdot u\right)\right)} - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    unpow2 [<=]60.9

    \[ \left(\mathsf{log1p}\left(-16 \cdot \color{blue}{{u}^{2}}\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    *-commutative [=>]60.9

    \[ \left(\mathsf{log1p}\left(-\color{blue}{{u}^{2} \cdot 16}\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    distribute-rgt-neg-in [=>]60.9

    \[ \left(\mathsf{log1p}\left(\color{blue}{{u}^{2} \cdot \left(-16\right)}\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    unpow2 [=>]60.9

    \[ \left(\mathsf{log1p}\left(\color{blue}{\left(u \cdot u\right)} \cdot \left(-16\right)\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    metadata-eval [=>]60.9

    \[ \left(\mathsf{log1p}\left(\left(u \cdot u\right) \cdot \color{blue}{-16}\right) - \log \left(1 - u \cdot -4\right)\right) \cdot \left(-s\right) \]

    sub-neg [=>]60.9

    \[ \left(\mathsf{log1p}\left(\left(u \cdot u\right) \cdot -16\right) - \log \color{blue}{\left(1 + \left(-u \cdot -4\right)\right)}\right) \cdot \left(-s\right) \]

    log1p-def [=>]99.0

    \[ \left(\mathsf{log1p}\left(\left(u \cdot u\right) \cdot -16\right) - \color{blue}{\mathsf{log1p}\left(-u \cdot -4\right)}\right) \cdot \left(-s\right) \]

    distribute-rgt-neg-in [=>]99.0

    \[ \left(\mathsf{log1p}\left(\left(u \cdot u\right) \cdot -16\right) - \mathsf{log1p}\left(\color{blue}{u \cdot \left(--4\right)}\right)\right) \cdot \left(-s\right) \]

    metadata-eval [=>]99.0

    \[ \left(\mathsf{log1p}\left(\left(u \cdot u\right) \cdot -16\right) - \mathsf{log1p}\left(u \cdot \color{blue}{4}\right)\right) \cdot \left(-s\right) \]
  6. Taylor expanded in s around 0 60.4%

    \[\leadsto \color{blue}{-1 \cdot \left(s \cdot \left(\log \left(1 + -16 \cdot {u}^{2}\right) - \log \left(1 + 4 \cdot u\right)\right)\right)} \]
  7. Simplified99.0%

    \[\leadsto \color{blue}{s \cdot \left(\mathsf{log1p}\left(u \cdot 4\right) - \mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right)} \]
    Step-by-step derivation

    [Start]60.4

    \[ -1 \cdot \left(s \cdot \left(\log \left(1 + -16 \cdot {u}^{2}\right) - \log \left(1 + 4 \cdot u\right)\right)\right) \]

    *-commutative [=>]60.4

    \[ \color{blue}{\left(s \cdot \left(\log \left(1 + -16 \cdot {u}^{2}\right) - \log \left(1 + 4 \cdot u\right)\right)\right) \cdot -1} \]

    +-commutative [=>]60.4

    \[ \left(s \cdot \left(\log \color{blue}{\left(-16 \cdot {u}^{2} + 1\right)} - \log \left(1 + 4 \cdot u\right)\right)\right) \cdot -1 \]

    *-commutative [=>]60.4

    \[ \left(s \cdot \left(\log \left(\color{blue}{{u}^{2} \cdot -16} + 1\right) - \log \left(1 + 4 \cdot u\right)\right)\right) \cdot -1 \]

    unpow2 [=>]60.4

    \[ \left(s \cdot \left(\log \left(\color{blue}{\left(u \cdot u\right)} \cdot -16 + 1\right) - \log \left(1 + 4 \cdot u\right)\right)\right) \cdot -1 \]

    associate-*r* [<=]60.4

    \[ \left(s \cdot \left(\log \left(\color{blue}{u \cdot \left(u \cdot -16\right)} + 1\right) - \log \left(1 + 4 \cdot u\right)\right)\right) \cdot -1 \]

    fma-udef [<=]60.5

    \[ \left(s \cdot \left(\log \color{blue}{\left(\mathsf{fma}\left(u, u \cdot -16, 1\right)\right)} - \log \left(1 + 4 \cdot u\right)\right)\right) \cdot -1 \]

    +-commutative [=>]60.5

    \[ \left(s \cdot \left(\log \left(\mathsf{fma}\left(u, u \cdot -16, 1\right)\right) - \log \color{blue}{\left(4 \cdot u + 1\right)}\right)\right) \cdot -1 \]

    *-commutative [=>]60.5

    \[ \left(s \cdot \left(\log \left(\mathsf{fma}\left(u, u \cdot -16, 1\right)\right) - \log \left(\color{blue}{u \cdot 4} + 1\right)\right)\right) \cdot -1 \]

    fma-udef [<=]60.5

    \[ \left(s \cdot \left(\log \left(\mathsf{fma}\left(u, u \cdot -16, 1\right)\right) - \log \color{blue}{\left(\mathsf{fma}\left(u, 4, 1\right)\right)}\right)\right) \cdot -1 \]

    log-div [<=]60.4

    \[ \left(s \cdot \color{blue}{\log \left(\frac{\mathsf{fma}\left(u, u \cdot -16, 1\right)}{\mathsf{fma}\left(u, 4, 1\right)}\right)}\right) \cdot -1 \]

    associate-*l* [=>]60.4

    \[ \color{blue}{s \cdot \left(\log \left(\frac{\mathsf{fma}\left(u, u \cdot -16, 1\right)}{\mathsf{fma}\left(u, 4, 1\right)}\right) \cdot -1\right)} \]

    metadata-eval [<=]60.4

    \[ s \cdot \left(\log \left(\frac{\mathsf{fma}\left(u, u \cdot -16, 1\right)}{\mathsf{fma}\left(u, 4, 1\right)}\right) \cdot \color{blue}{\left(-1\right)}\right) \]

    distribute-rgt-neg-in [<=]60.4

    \[ s \cdot \color{blue}{\left(-\log \left(\frac{\mathsf{fma}\left(u, u \cdot -16, 1\right)}{\mathsf{fma}\left(u, 4, 1\right)}\right) \cdot 1\right)} \]

    *-rgt-identity [=>]60.4

    \[ s \cdot \left(-\color{blue}{\log \left(\frac{\mathsf{fma}\left(u, u \cdot -16, 1\right)}{\mathsf{fma}\left(u, 4, 1\right)}\right)}\right) \]
  8. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{log1p}\left(u \cdot 4\right), s, \left(-\mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right) \cdot s\right)} \]
    Step-by-step derivation

    [Start]99.0

    \[ s \cdot \left(\mathsf{log1p}\left(u \cdot 4\right) - \mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right) \]

    sub-neg [=>]99.0

    \[ s \cdot \color{blue}{\left(\mathsf{log1p}\left(u \cdot 4\right) + \left(-\mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right)\right)} \]

    distribute-rgt-in [=>]99.0

    \[ \color{blue}{\mathsf{log1p}\left(u \cdot 4\right) \cdot s + \left(-\mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right) \cdot s} \]

    fma-def [=>]99.4

    \[ \color{blue}{\mathsf{fma}\left(\mathsf{log1p}\left(u \cdot 4\right), s, \left(-\mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right) \cdot s\right)} \]
  9. Final simplification99.4%

    \[\leadsto \mathsf{fma}\left(\mathsf{log1p}\left(u \cdot 4\right), s, s \cdot \left(-\mathsf{log1p}\left(u \cdot \left(u \cdot -16\right)\right)\right)\right) \]

Alternatives

Alternative 1
Accuracy99.4%
Cost3392
\[s \cdot \left(-\mathsf{log1p}\left(u \cdot -4\right)\right) \]
Alternative 2
Accuracy89.1%
Cost384
\[s \cdot \frac{u \cdot \left(-16\right)}{-4 + u \cdot 8} \]
Alternative 3
Accuracy88.3%
Cost352
\[-16 \cdot \frac{u \cdot s}{u \cdot 8 - 4} \]
Alternative 4
Accuracy87.1%
Cost288
\[s \cdot \left(u \cdot \left(4 + u \cdot 8\right)\right) \]
Alternative 5
Accuracy87.1%
Cost288
\[u \cdot \left(s \cdot \left(4 - u \cdot -8\right)\right) \]
Alternative 6
Accuracy74.0%
Cost160
\[4 \cdot \left(u \cdot s\right) \]
Alternative 7
Accuracy74.3%
Cost160
\[u \cdot \left(4 \cdot s\right) \]
Alternative 8
Accuracy8.2%
Cost96
\[s \cdot -2 \]

Error

Reproduce?

herbie shell --seed 2023159 
(FPCore (s u)
  :name "Disney BSSRDF, sample scattering profile, lower"
  :precision binary32
  :pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 2.328306437e-10 u) (<= u 0.25)))
  (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))