Disney BSSRDF, PDF of scattering profile

Percentage Accurate: 99.6% → 99.5%
Time: 14.6s
Alternatives: 12
Speedup: 1.0×

Specification

?
\[\left(0 \leq s \land s \leq 256\right) \land \left(10^{-6} < r \land r < 1000000\right)\]
\[\begin{array}{l} \\ \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \end{array} \]
(FPCore (s r)
 :precision binary32
 (+
  (/ (* 0.25 (exp (/ (- r) s))) (* (* (* 2.0 PI) s) r))
  (/ (* 0.75 (exp (/ (- r) (* 3.0 s)))) (* (* (* 6.0 PI) s) r))))
float code(float s, float r) {
	return ((0.25f * expf((-r / s))) / (((2.0f * ((float) M_PI)) * s) * r)) + ((0.75f * expf((-r / (3.0f * s)))) / (((6.0f * ((float) M_PI)) * s) * r));
}
function code(s, r)
	return Float32(Float32(Float32(Float32(0.25) * exp(Float32(Float32(-r) / s))) / Float32(Float32(Float32(Float32(2.0) * Float32(pi)) * s) * r)) + Float32(Float32(Float32(0.75) * exp(Float32(Float32(-r) / Float32(Float32(3.0) * s)))) / Float32(Float32(Float32(Float32(6.0) * Float32(pi)) * s) * r)))
end
function tmp = code(s, r)
	tmp = ((single(0.25) * exp((-r / s))) / (((single(2.0) * single(pi)) * s) * r)) + ((single(0.75) * exp((-r / (single(3.0) * s)))) / (((single(6.0) * single(pi)) * s) * r));
end
\begin{array}{l}

\\
\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r}
\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 12 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: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \end{array} \]
(FPCore (s r)
 :precision binary32
 (+
  (/ (* 0.25 (exp (/ (- r) s))) (* (* (* 2.0 PI) s) r))
  (/ (* 0.75 (exp (/ (- r) (* 3.0 s)))) (* (* (* 6.0 PI) s) r))))
float code(float s, float r) {
	return ((0.25f * expf((-r / s))) / (((2.0f * ((float) M_PI)) * s) * r)) + ((0.75f * expf((-r / (3.0f * s)))) / (((6.0f * ((float) M_PI)) * s) * r));
}
function code(s, r)
	return Float32(Float32(Float32(Float32(0.25) * exp(Float32(Float32(-r) / s))) / Float32(Float32(Float32(Float32(2.0) * Float32(pi)) * s) * r)) + Float32(Float32(Float32(0.75) * exp(Float32(Float32(-r) / Float32(Float32(3.0) * s)))) / Float32(Float32(Float32(Float32(6.0) * Float32(pi)) * s) * r)))
end
function tmp = code(s, r)
	tmp = ((single(0.25) * exp((-r / s))) / (((single(2.0) * single(pi)) * s) * r)) + ((single(0.75) * exp((-r / (single(3.0) * s)))) / (((single(6.0) * single(pi)) * s) * r));
end
\begin{array}{l}

\\
\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r}
\end{array}

Alternative 1: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{\frac{1}{e^{\frac{r}{s \cdot 3}}}}{s \cdot \left(r \cdot \left(\pi \cdot 6\right)\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(r \cdot \pi\right)}\right) \end{array} \]
(FPCore (s r)
 :precision binary32
 (fma
  (/ (/ 1.0 (exp (/ r (* s 3.0)))) (* s (* r (* PI 6.0))))
  0.75
  (/ (* 0.125 (exp (/ r (- s)))) (* s (* r PI)))))
float code(float s, float r) {
	return fmaf(((1.0f / expf((r / (s * 3.0f)))) / (s * (r * (((float) M_PI) * 6.0f)))), 0.75f, ((0.125f * expf((r / -s))) / (s * (r * ((float) M_PI)))));
}
function code(s, r)
	return fma(Float32(Float32(Float32(1.0) / exp(Float32(r / Float32(s * Float32(3.0))))) / Float32(s * Float32(r * Float32(Float32(pi) * Float32(6.0))))), Float32(0.75), Float32(Float32(Float32(0.125) * exp(Float32(r / Float32(-s)))) / Float32(s * Float32(r * Float32(pi)))))
end
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{\frac{1}{e^{\frac{r}{s \cdot 3}}}}{s \cdot \left(r \cdot \left(\pi \cdot 6\right)\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(r \cdot \pi\right)}\right)
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{s \cdot -3}}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right)} \]
  4. Step-by-step derivation
    1. lift-exp.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{e^{\frac{r}{s \cdot -3}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    2. lift-/.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\color{blue}{\frac{r}{s \cdot -3}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    3. lift-*.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{s \cdot -3}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    4. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{-3 \cdot s}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    5. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{\left(\mathsf{neg}\left(3\right)\right)} \cdot s}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    6. distribute-lft-neg-inN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{\mathsf{neg}\left(3 \cdot s\right)}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    7. distribute-frac-neg2N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\color{blue}{\mathsf{neg}\left(\frac{r}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    8. neg-mul-1N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\color{blue}{-1 \cdot \frac{r}{3 \cdot s}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    9. exp-prodN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{{\left(e^{-1}\right)}^{\left(\frac{r}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    10. lower-pow.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{{\left(e^{-1}\right)}^{\left(\frac{r}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    11. lower-exp.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\color{blue}{\left(e^{-1}\right)}}^{\left(\frac{r}{3 \cdot s}\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    12. div-invN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\color{blue}{\left(r \cdot \frac{1}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    13. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\color{blue}{\left(r \cdot \frac{1}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    14. associate-/r*N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\left(r \cdot \color{blue}{\frac{\frac{1}{3}}{s}}\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    15. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\left(r \cdot \frac{\color{blue}{\frac{1}{3}}}{s}\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    16. lower-/.f3299.6

      \[\leadsto \frac{0.125}{s \cdot \pi} \cdot \left(\frac{{\left(e^{-1}\right)}^{\left(r \cdot \color{blue}{\frac{0.3333333333333333}{s}}\right)}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right) \]
  5. Applied rewrites99.6%

    \[\leadsto \frac{0.125}{s \cdot \pi} \cdot \left(\frac{\color{blue}{{\left(e^{-1}\right)}^{\left(r \cdot \frac{0.3333333333333333}{s}\right)}}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right) \]
  6. Applied rewrites99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{e^{\frac{r}{s \cdot -3}}}{s \cdot \left(\left(\pi \cdot 6\right) \cdot r\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(\pi \cdot r\right)}\right)} \]
  7. Step-by-step derivation
    1. lift-exp.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{e^{\frac{r}{s \cdot -3}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    2. lift-/.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\color{blue}{\frac{r}{s \cdot -3}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    3. div-invN/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\color{blue}{r \cdot \frac{1}{s \cdot -3}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    4. div-invN/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\color{blue}{\frac{r}{s \cdot -3}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    5. lift-*.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\frac{r}{\color{blue}{s \cdot -3}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\frac{r}{\color{blue}{-3 \cdot s}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\frac{r}{\color{blue}{\left(\mathsf{neg}\left(3\right)\right)} \cdot s}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    8. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\frac{r}{\color{blue}{\mathsf{neg}\left(3 \cdot s\right)}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    9. distribute-frac-neg2N/A

      \[\leadsto \mathsf{fma}\left(\frac{e^{\color{blue}{\mathsf{neg}\left(\frac{r}{3 \cdot s}\right)}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    10. exp-negN/A

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{1}{e^{\frac{r}{3 \cdot s}}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    11. lower-/.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{1}{e^{\frac{r}{3 \cdot s}}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    12. lower-exp.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{1}{\color{blue}{e^{\frac{r}{3 \cdot s}}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    13. lower-/.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{1}{e^{\color{blue}{\frac{r}{3 \cdot s}}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    14. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{1}{e^{\frac{r}{\color{blue}{s \cdot 3}}}}}{s \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 6\right) \cdot r\right)}, \frac{3}{4}, \frac{\frac{1}{8} \cdot e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{s \cdot \left(\mathsf{PI}\left(\right) \cdot r\right)}\right) \]
    15. lower-*.f3299.6

      \[\leadsto \mathsf{fma}\left(\frac{\frac{1}{e^{\frac{r}{\color{blue}{s \cdot 3}}}}}{s \cdot \left(\left(\pi \cdot 6\right) \cdot r\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(\pi \cdot r\right)}\right) \]
  8. Applied rewrites99.6%

    \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\frac{1}{e^{\frac{r}{s \cdot 3}}}}}{s \cdot \left(\left(\pi \cdot 6\right) \cdot r\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(\pi \cdot r\right)}\right) \]
  9. Final simplification99.6%

    \[\leadsto \mathsf{fma}\left(\frac{\frac{1}{e^{\frac{r}{s \cdot 3}}}}{s \cdot \left(r \cdot \left(\pi \cdot 6\right)\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(r \cdot \pi\right)}\right) \]
  10. Add Preprocessing

Alternative 2: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{e^{\frac{r}{s \cdot -3}}}{s \cdot \left(r \cdot \left(\pi \cdot 6\right)\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(r \cdot \pi\right)}\right) \end{array} \]
(FPCore (s r)
 :precision binary32
 (fma
  (/ (exp (/ r (* s -3.0))) (* s (* r (* PI 6.0))))
  0.75
  (/ (* 0.125 (exp (/ r (- s)))) (* s (* r PI)))))
float code(float s, float r) {
	return fmaf((expf((r / (s * -3.0f))) / (s * (r * (((float) M_PI) * 6.0f)))), 0.75f, ((0.125f * expf((r / -s))) / (s * (r * ((float) M_PI)))));
}
function code(s, r)
	return fma(Float32(exp(Float32(r / Float32(s * Float32(-3.0)))) / Float32(s * Float32(r * Float32(Float32(pi) * Float32(6.0))))), Float32(0.75), Float32(Float32(Float32(0.125) * exp(Float32(r / Float32(-s)))) / Float32(s * Float32(r * Float32(pi)))))
end
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{e^{\frac{r}{s \cdot -3}}}{s \cdot \left(r \cdot \left(\pi \cdot 6\right)\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(r \cdot \pi\right)}\right)
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{s \cdot -3}}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right)} \]
  4. Step-by-step derivation
    1. lift-exp.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{e^{\frac{r}{s \cdot -3}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    2. lift-/.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\color{blue}{\frac{r}{s \cdot -3}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    3. lift-*.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{s \cdot -3}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    4. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{-3 \cdot s}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    5. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{\left(\mathsf{neg}\left(3\right)\right)} \cdot s}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    6. distribute-lft-neg-inN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\frac{r}{\color{blue}{\mathsf{neg}\left(3 \cdot s\right)}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    7. distribute-frac-neg2N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\color{blue}{\mathsf{neg}\left(\frac{r}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    8. neg-mul-1N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{e^{\color{blue}{-1 \cdot \frac{r}{3 \cdot s}}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    9. exp-prodN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{{\left(e^{-1}\right)}^{\left(\frac{r}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    10. lower-pow.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{{\left(e^{-1}\right)}^{\left(\frac{r}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    11. lower-exp.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\color{blue}{\left(e^{-1}\right)}}^{\left(\frac{r}{3 \cdot s}\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    12. div-invN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\color{blue}{\left(r \cdot \frac{1}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    13. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\color{blue}{\left(r \cdot \frac{1}{3 \cdot s}\right)}}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    14. associate-/r*N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\left(r \cdot \color{blue}{\frac{\frac{1}{3}}{s}}\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    15. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{{\left(e^{-1}\right)}^{\left(r \cdot \frac{\color{blue}{\frac{1}{3}}}{s}\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    16. lower-/.f3299.6

      \[\leadsto \frac{0.125}{s \cdot \pi} \cdot \left(\frac{{\left(e^{-1}\right)}^{\left(r \cdot \color{blue}{\frac{0.3333333333333333}{s}}\right)}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right) \]
  5. Applied rewrites99.6%

    \[\leadsto \frac{0.125}{s \cdot \pi} \cdot \left(\frac{\color{blue}{{\left(e^{-1}\right)}^{\left(r \cdot \frac{0.3333333333333333}{s}\right)}}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right) \]
  6. Applied rewrites99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{e^{\frac{r}{s \cdot -3}}}{s \cdot \left(\left(\pi \cdot 6\right) \cdot r\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(\pi \cdot r\right)}\right)} \]
  7. Final simplification99.6%

    \[\leadsto \mathsf{fma}\left(\frac{e^{\frac{r}{s \cdot -3}}}{s \cdot \left(r \cdot \left(\pi \cdot 6\right)\right)}, 0.75, \frac{0.125 \cdot e^{\frac{r}{-s}}}{s \cdot \left(r \cdot \pi\right)}\right) \]
  8. Add Preprocessing

Alternative 3: 99.5% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \frac{0.125 \cdot \left(\frac{e^{\frac{r}{-s}}}{r} + \frac{e^{\frac{r \cdot -0.3333333333333333}{s}}}{r}\right)}{s \cdot \pi} \end{array} \]
(FPCore (s r)
 :precision binary32
 (/
  (*
   0.125
   (+ (/ (exp (/ r (- s))) r) (/ (exp (/ (* r -0.3333333333333333) s)) r)))
  (* s PI)))
float code(float s, float r) {
	return (0.125f * ((expf((r / -s)) / r) + (expf(((r * -0.3333333333333333f) / s)) / r))) / (s * ((float) M_PI));
}
function code(s, r)
	return Float32(Float32(Float32(0.125) * Float32(Float32(exp(Float32(r / Float32(-s))) / r) + Float32(exp(Float32(Float32(r * Float32(-0.3333333333333333)) / s)) / r))) / Float32(s * Float32(pi)))
end
function tmp = code(s, r)
	tmp = (single(0.125) * ((exp((r / -s)) / r) + (exp(((r * single(-0.3333333333333333)) / s)) / r))) / (s * single(pi));
end
\begin{array}{l}

\\
\frac{0.125 \cdot \left(\frac{e^{\frac{r}{-s}}}{r} + \frac{e^{\frac{r \cdot -0.3333333333333333}{s}}}{r}\right)}{s \cdot \pi}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{s \cdot -3}}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right)} \]
  4. Taylor expanded in s around 0

    \[\leadsto \color{blue}{\frac{1}{8} \cdot \frac{\frac{e^{-1 \cdot \frac{r}{s}}}{r} + \frac{e^{\frac{-1}{3} \cdot \frac{r}{s}}}{r}}{s \cdot \mathsf{PI}\left(\right)}} \]
  5. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{8} \cdot \left(\frac{e^{-1 \cdot \frac{r}{s}}}{r} + \frac{e^{\frac{-1}{3} \cdot \frac{r}{s}}}{r}\right)}{s \cdot \mathsf{PI}\left(\right)}} \]
    2. lower-/.f32N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{8} \cdot \left(\frac{e^{-1 \cdot \frac{r}{s}}}{r} + \frac{e^{\frac{-1}{3} \cdot \frac{r}{s}}}{r}\right)}{s \cdot \mathsf{PI}\left(\right)}} \]
  6. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{0.125 \cdot \left(\frac{e^{\frac{r}{-s}}}{r} + \frac{e^{\frac{r \cdot -0.3333333333333333}{s}}}{r}\right)}{s \cdot \pi}} \]
  7. Add Preprocessing

Alternative 4: 99.5% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \frac{0.125 \cdot \left(e^{\frac{r}{-s}} + e^{\frac{r \cdot -0.3333333333333333}{s}}\right)}{r \cdot \left(s \cdot \pi\right)} \end{array} \]
(FPCore (s r)
 :precision binary32
 (/
  (* 0.125 (+ (exp (/ r (- s))) (exp (/ (* r -0.3333333333333333) s))))
  (* r (* s PI))))
float code(float s, float r) {
	return (0.125f * (expf((r / -s)) + expf(((r * -0.3333333333333333f) / s)))) / (r * (s * ((float) M_PI)));
}
function code(s, r)
	return Float32(Float32(Float32(0.125) * Float32(exp(Float32(r / Float32(-s))) + exp(Float32(Float32(r * Float32(-0.3333333333333333)) / s)))) / Float32(r * Float32(s * Float32(pi))))
end
function tmp = code(s, r)
	tmp = (single(0.125) * (exp((r / -s)) + exp(((r * single(-0.3333333333333333)) / s)))) / (r * (s * single(pi)));
end
\begin{array}{l}

\\
\frac{0.125 \cdot \left(e^{\frac{r}{-s}} + e^{\frac{r \cdot -0.3333333333333333}{s}}\right)}{r \cdot \left(s \cdot \pi\right)}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{s \cdot -3}}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right)} \]
  4. Taylor expanded in r around inf

    \[\leadsto \color{blue}{\frac{1}{8} \cdot \frac{e^{-1 \cdot \frac{r}{s}} + e^{\frac{-1}{3} \cdot \frac{r}{s}}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
  5. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{8} \cdot \left(e^{-1 \cdot \frac{r}{s}} + e^{\frac{-1}{3} \cdot \frac{r}{s}}\right)}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
    2. metadata-evalN/A

      \[\leadsto \frac{\color{blue}{\left(\frac{-1}{8} \cdot -1\right)} \cdot \left(e^{-1 \cdot \frac{r}{s}} + e^{\frac{-1}{3} \cdot \frac{r}{s}}\right)}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)} \]
    3. associate-*r*N/A

      \[\leadsto \frac{\color{blue}{\frac{-1}{8} \cdot \left(-1 \cdot \left(e^{-1 \cdot \frac{r}{s}} + e^{\frac{-1}{3} \cdot \frac{r}{s}}\right)\right)}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)} \]
    4. distribute-lft-outN/A

      \[\leadsto \frac{\frac{-1}{8} \cdot \color{blue}{\left(-1 \cdot e^{-1 \cdot \frac{r}{s}} + -1 \cdot e^{\frac{-1}{3} \cdot \frac{r}{s}}\right)}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)} \]
    5. lower-/.f32N/A

      \[\leadsto \color{blue}{\frac{\frac{-1}{8} \cdot \left(-1 \cdot e^{-1 \cdot \frac{r}{s}} + -1 \cdot e^{\frac{-1}{3} \cdot \frac{r}{s}}\right)}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
  6. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{0.125 \cdot \left(e^{\frac{r}{-s}} + e^{\frac{r \cdot -0.3333333333333333}{s}}\right)}{r \cdot \left(s \cdot \pi\right)}} \]
  7. Add Preprocessing

Alternative 5: 11.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{0.125 \cdot e^{\frac{r}{-s}}}{\pi \cdot \left(r \cdot s\right)} + \frac{\frac{0.125}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.006944444444444444}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.041666666666666664}{s \cdot \pi}\right)}{s} \end{array} \]
(FPCore (s r)
 :precision binary32
 (+
  (/ (* 0.125 (exp (/ r (- s)))) (* PI (* r s)))
  (/
   (+
    (/ 0.125 (* r PI))
    (fma
     r
     (/ 0.006944444444444444 (* s (* s PI)))
     (/ -0.041666666666666664 (* s PI))))
   s)))
float code(float s, float r) {
	return ((0.125f * expf((r / -s))) / (((float) M_PI) * (r * s))) + (((0.125f / (r * ((float) M_PI))) + fmaf(r, (0.006944444444444444f / (s * (s * ((float) M_PI)))), (-0.041666666666666664f / (s * ((float) M_PI))))) / s);
}
function code(s, r)
	return Float32(Float32(Float32(Float32(0.125) * exp(Float32(r / Float32(-s)))) / Float32(Float32(pi) * Float32(r * s))) + Float32(Float32(Float32(Float32(0.125) / Float32(r * Float32(pi))) + fma(r, Float32(Float32(0.006944444444444444) / Float32(s * Float32(s * Float32(pi)))), Float32(Float32(-0.041666666666666664) / Float32(s * Float32(pi))))) / s))
end
\begin{array}{l}

\\
\frac{0.125 \cdot e^{\frac{r}{-s}}}{\pi \cdot \left(r \cdot s\right)} + \frac{\frac{0.125}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.006944444444444444}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.041666666666666664}{s \cdot \pi}\right)}{s}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Taylor expanded in s around inf

    \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot s\right) \cdot r} + \color{blue}{\frac{\left(\frac{1}{144} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \frac{1}{8} \cdot \frac{1}{r \cdot \mathsf{PI}\left(\right)}\right) - \frac{\frac{1}{24}}{s \cdot \mathsf{PI}\left(\right)}}{s}} \]
  4. Applied rewrites8.2%

    \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \color{blue}{\frac{\frac{0.125}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.006944444444444444}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.041666666666666664}{s \cdot \pi}\right)}{s}} \]
  5. Step-by-step derivation
    1. lift-/.f32N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{4} \cdot e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot s\right) \cdot r}} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    2. lift-*.f32N/A

      \[\leadsto \frac{\color{blue}{\frac{1}{4} \cdot e^{\frac{\mathsf{neg}\left(r\right)}{s}}}}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot s\right) \cdot r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    3. lift-*.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{\color{blue}{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot s\right) \cdot r}} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    4. times-fracN/A

      \[\leadsto \color{blue}{\frac{\frac{1}{4}}{\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot s} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r}} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    5. lift-*.f32N/A

      \[\leadsto \frac{\frac{1}{4}}{\color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot s}} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    6. lift-*.f32N/A

      \[\leadsto \frac{\frac{1}{4}}{\color{blue}{\left(2 \cdot \mathsf{PI}\left(\right)\right)} \cdot s} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    7. associate-*l*N/A

      \[\leadsto \frac{\frac{1}{4}}{\color{blue}{2 \cdot \left(\mathsf{PI}\left(\right) \cdot s\right)}} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    8. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{4}}{2 \cdot \color{blue}{\left(s \cdot \mathsf{PI}\left(\right)\right)}} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    9. lift-*.f32N/A

      \[\leadsto \frac{\frac{1}{4}}{2 \cdot \color{blue}{\left(s \cdot \mathsf{PI}\left(\right)\right)}} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    10. associate-/r*N/A

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{4}}{2}}{s \cdot \mathsf{PI}\left(\right)}} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    11. metadata-evalN/A

      \[\leadsto \frac{\color{blue}{\frac{1}{8}}}{s \cdot \mathsf{PI}\left(\right)} \cdot \frac{e^{\frac{\mathsf{neg}\left(r\right)}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    12. lift-neg.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \frac{e^{\frac{\color{blue}{\mathsf{neg}\left(r\right)}}{s}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    13. lift-/.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \frac{e^{\color{blue}{\frac{\mathsf{neg}\left(r\right)}{s}}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    14. distribute-frac-negN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \frac{e^{\color{blue}{\mathsf{neg}\left(\frac{r}{s}\right)}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    15. distribute-frac-neg2N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \frac{e^{\color{blue}{\frac{r}{\mathsf{neg}\left(s\right)}}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    16. lift-neg.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \frac{e^{\frac{r}{\color{blue}{\mathsf{neg}\left(s\right)}}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
    17. lift-/.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \frac{e^{\color{blue}{\frac{r}{\mathsf{neg}\left(s\right)}}}}{r} + \frac{\frac{\frac{1}{8}}{r \cdot \mathsf{PI}\left(\right)} + \mathsf{fma}\left(r, \frac{\frac{1}{144}}{s \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}, \frac{\frac{-1}{24}}{s \cdot \mathsf{PI}\left(\right)}\right)}{s} \]
  6. Applied rewrites8.2%

    \[\leadsto \color{blue}{\frac{0.125 \cdot e^{\frac{r}{-s}}}{\pi \cdot \left(s \cdot r\right)}} + \frac{\frac{0.125}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.006944444444444444}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.041666666666666664}{s \cdot \pi}\right)}{s} \]
  7. Final simplification8.2%

    \[\leadsto \frac{0.125 \cdot e^{\frac{r}{-s}}}{\pi \cdot \left(r \cdot s\right)} + \frac{\frac{0.125}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.006944444444444444}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.041666666666666664}{s \cdot \pi}\right)}{s} \]
  8. Add Preprocessing

Alternative 6: 11.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{-s}}}{r} + \frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{0.05555555555555555}{s \cdot s}, \frac{-0.3333333333333333}{s}\right), 1\right)}{r}\right) \end{array} \]
(FPCore (s r)
 :precision binary32
 (*
  (/ 0.125 (* s PI))
  (+
   (/ (exp (/ r (- s))) r)
   (/
    (fma
     r
     (fma r (/ 0.05555555555555555 (* s s)) (/ -0.3333333333333333 s))
     1.0)
    r))))
float code(float s, float r) {
	return (0.125f / (s * ((float) M_PI))) * ((expf((r / -s)) / r) + (fmaf(r, fmaf(r, (0.05555555555555555f / (s * s)), (-0.3333333333333333f / s)), 1.0f) / r));
}
function code(s, r)
	return Float32(Float32(Float32(0.125) / Float32(s * Float32(pi))) * Float32(Float32(exp(Float32(r / Float32(-s))) / r) + Float32(fma(r, fma(r, Float32(Float32(0.05555555555555555) / Float32(s * s)), Float32(Float32(-0.3333333333333333) / s)), Float32(1.0)) / r)))
end
\begin{array}{l}

\\
\frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{-s}}}{r} + \frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{0.05555555555555555}{s \cdot s}, \frac{-0.3333333333333333}{s}\right), 1\right)}{r}\right)
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{s \cdot -3}}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right)} \]
  4. Taylor expanded in r around 0

    \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{1 + r \cdot \left(\frac{1}{18} \cdot \frac{r}{{s}^{2}} - \frac{1}{3} \cdot \frac{1}{s}\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
  5. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{r \cdot \left(\frac{1}{18} \cdot \frac{r}{{s}^{2}} - \frac{1}{3} \cdot \frac{1}{s}\right) + 1}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    2. lower-fma.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\color{blue}{\mathsf{fma}\left(r, \frac{1}{18} \cdot \frac{r}{{s}^{2}} - \frac{1}{3} \cdot \frac{1}{s}, 1\right)}}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    3. sub-negN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \color{blue}{\frac{1}{18} \cdot \frac{r}{{s}^{2}} + \left(\mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right)}, 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    4. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \color{blue}{\frac{r}{{s}^{2}} \cdot \frac{1}{18}} + \left(\mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    5. associate-*l/N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \color{blue}{\frac{r \cdot \frac{1}{18}}{{s}^{2}}} + \left(\mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    6. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \color{blue}{r \cdot \frac{\frac{1}{18}}{{s}^{2}}} + \left(\mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    7. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, r \cdot \frac{\color{blue}{\frac{1}{18} \cdot 1}}{{s}^{2}} + \left(\mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    8. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, r \cdot \color{blue}{\left(\frac{1}{18} \cdot \frac{1}{{s}^{2}}\right)} + \left(\mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    9. lower-fma.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \color{blue}{\mathsf{fma}\left(r, \frac{1}{18} \cdot \frac{1}{{s}^{2}}, \mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right)}, 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    10. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \color{blue}{\frac{\frac{1}{18} \cdot 1}{{s}^{2}}}, \mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    11. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{\color{blue}{\frac{1}{18}}}{{s}^{2}}, \mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    12. lower-/.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \color{blue}{\frac{\frac{1}{18}}{{s}^{2}}}, \mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    13. unpow2N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{\frac{1}{18}}{\color{blue}{s \cdot s}}, \mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    14. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{\frac{1}{18}}{\color{blue}{s \cdot s}}, \mathsf{neg}\left(\frac{1}{3} \cdot \frac{1}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    15. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{\frac{1}{18}}{s \cdot s}, \mathsf{neg}\left(\color{blue}{\frac{\frac{1}{3} \cdot 1}{s}}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    16. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{\frac{1}{18}}{s \cdot s}, \mathsf{neg}\left(\frac{\color{blue}{\frac{1}{3}}}{s}\right)\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    17. distribute-neg-fracN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{\frac{1}{18}}{s \cdot s}, \color{blue}{\frac{\mathsf{neg}\left(\frac{1}{3}\right)}{s}}\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    18. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{8}}{s \cdot \mathsf{PI}\left(\right)} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{\frac{1}{18}}{s \cdot s}, \frac{\color{blue}{\frac{-1}{3}}}{s}\right), 1\right)}{r} + \frac{e^{\frac{r}{\mathsf{neg}\left(s\right)}}}{r}\right) \]
    19. lower-/.f328.2

      \[\leadsto \frac{0.125}{s \cdot \pi} \cdot \left(\frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{0.05555555555555555}{s \cdot s}, \color{blue}{\frac{-0.3333333333333333}{s}}\right), 1\right)}{r} + \frac{e^{\frac{r}{-s}}}{r}\right) \]
  6. Applied rewrites8.2%

    \[\leadsto \frac{0.125}{s \cdot \pi} \cdot \left(\frac{\color{blue}{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{0.05555555555555555}{s \cdot s}, \frac{-0.3333333333333333}{s}\right), 1\right)}}{r} + \frac{e^{\frac{r}{-s}}}{r}\right) \]
  7. Final simplification8.2%

    \[\leadsto \frac{0.125}{s \cdot \pi} \cdot \left(\frac{e^{\frac{r}{-s}}}{r} + \frac{\mathsf{fma}\left(r, \mathsf{fma}\left(r, \frac{0.05555555555555555}{s \cdot s}, \frac{-0.3333333333333333}{s}\right), 1\right)}{r}\right) \]
  8. Add Preprocessing

Alternative 7: 10.5% accurate, 3.6× speedup?

\[\begin{array}{l} \\ \frac{\mathsf{fma}\left(r, \frac{\mathsf{fma}\left(0.06944444444444445, \frac{r}{s \cdot \pi}, \frac{-0.16666666666666666}{\pi}\right)}{s \cdot s}, \frac{0.25}{s \cdot \pi}\right)}{r} \end{array} \]
(FPCore (s r)
 :precision binary32
 (/
  (fma
   r
   (/
    (fma 0.06944444444444445 (/ r (* s PI)) (/ -0.16666666666666666 PI))
    (* s s))
   (/ 0.25 (* s PI)))
  r))
float code(float s, float r) {
	return fmaf(r, (fmaf(0.06944444444444445f, (r / (s * ((float) M_PI))), (-0.16666666666666666f / ((float) M_PI))) / (s * s)), (0.25f / (s * ((float) M_PI)))) / r;
}
function code(s, r)
	return Float32(fma(r, Float32(fma(Float32(0.06944444444444445), Float32(r / Float32(s * Float32(pi))), Float32(Float32(-0.16666666666666666) / Float32(pi))) / Float32(s * s)), Float32(Float32(0.25) / Float32(s * Float32(pi)))) / r)
end
\begin{array}{l}

\\
\frac{\mathsf{fma}\left(r, \frac{\mathsf{fma}\left(0.06944444444444445, \frac{r}{s \cdot \pi}, \frac{-0.16666666666666666}{\pi}\right)}{s \cdot s}, \frac{0.25}{s \cdot \pi}\right)}{r}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Taylor expanded in r around 0

    \[\leadsto \color{blue}{\frac{r \cdot \left(\frac{5}{72} \cdot \frac{r}{{s}^{3} \cdot \mathsf{PI}\left(\right)} - \frac{1}{6} \cdot \frac{1}{{s}^{2} \cdot \mathsf{PI}\left(\right)}\right) + \frac{1}{4} \cdot \frac{1}{s \cdot \mathsf{PI}\left(\right)}}{r}} \]
  4. Applied rewrites7.6%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(r, \frac{\mathsf{fma}\left(0.06944444444444445, \frac{r}{s \cdot \pi}, \frac{-0.16666666666666666}{\pi}\right)}{s \cdot s}, \frac{0.25}{s \cdot \pi}\right)}{r}} \]
  5. Add Preprocessing

Alternative 8: 10.5% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \frac{\frac{0.25}{r \cdot \pi} + \mathsf{fma}\left(\frac{r}{\pi \cdot \left(s \cdot s\right)}, 0.06944444444444445, \frac{-0.16666666666666666}{s \cdot \pi}\right)}{s} \end{array} \]
(FPCore (s r)
 :precision binary32
 (/
  (+
   (/ 0.25 (* r PI))
   (fma
    (/ r (* PI (* s s)))
    0.06944444444444445
    (/ -0.16666666666666666 (* s PI))))
  s))
float code(float s, float r) {
	return ((0.25f / (r * ((float) M_PI))) + fmaf((r / (((float) M_PI) * (s * s))), 0.06944444444444445f, (-0.16666666666666666f / (s * ((float) M_PI))))) / s;
}
function code(s, r)
	return Float32(Float32(Float32(Float32(0.25) / Float32(r * Float32(pi))) + fma(Float32(r / Float32(Float32(pi) * Float32(s * s))), Float32(0.06944444444444445), Float32(Float32(-0.16666666666666666) / Float32(s * Float32(pi))))) / s)
end
\begin{array}{l}

\\
\frac{\frac{0.25}{r \cdot \pi} + \mathsf{fma}\left(\frac{r}{\pi \cdot \left(s \cdot s\right)}, 0.06944444444444445, \frac{-0.16666666666666666}{s \cdot \pi}\right)}{s}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  2. Add Preprocessing
  3. Taylor expanded in r around 0

    \[\leadsto \color{blue}{\frac{\frac{1}{4}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
  4. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{4}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
    2. lower-*.f32N/A

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

      \[\leadsto \frac{\frac{1}{4}}{r \cdot \color{blue}{\left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
    4. lower-PI.f327.2

      \[\leadsto \frac{0.25}{r \cdot \left(s \cdot \color{blue}{\pi}\right)} \]
  5. Applied rewrites7.2%

    \[\leadsto \color{blue}{\frac{0.25}{r \cdot \left(s \cdot \pi\right)}} \]
  6. Step-by-step derivation
    1. Applied rewrites7.2%

      \[\leadsto \frac{0.25}{\left(\pi \cdot r\right) \cdot \color{blue}{s}} \]
    2. Taylor expanded in s around inf

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{144} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \left(\frac{1}{16} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \frac{1}{4} \cdot \frac{1}{r \cdot \mathsf{PI}\left(\right)}\right)\right) - \frac{\frac{1}{6}}{s \cdot \mathsf{PI}\left(\right)}}{s}} \]
    3. Applied rewrites7.6%

      \[\leadsto \color{blue}{\frac{\frac{0.25}{r \cdot \pi} + \mathsf{fma}\left(\frac{r}{\pi \cdot \left(s \cdot s\right)}, 0.06944444444444445, \frac{-0.16666666666666666}{s \cdot \pi}\right)}{s}} \]
    4. Add Preprocessing

    Alternative 9: 10.5% accurate, 4.0× speedup?

    \[\begin{array}{l} \\ \frac{\frac{0.25}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.06944444444444445}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.16666666666666666}{s \cdot \pi}\right)}{s} \end{array} \]
    (FPCore (s r)
     :precision binary32
     (/
      (+
       (/ 0.25 (* r PI))
       (fma
        r
        (/ 0.06944444444444445 (* s (* s PI)))
        (/ -0.16666666666666666 (* s PI))))
      s))
    float code(float s, float r) {
    	return ((0.25f / (r * ((float) M_PI))) + fmaf(r, (0.06944444444444445f / (s * (s * ((float) M_PI)))), (-0.16666666666666666f / (s * ((float) M_PI))))) / s;
    }
    
    function code(s, r)
    	return Float32(Float32(Float32(Float32(0.25) / Float32(r * Float32(pi))) + fma(r, Float32(Float32(0.06944444444444445) / Float32(s * Float32(s * Float32(pi)))), Float32(Float32(-0.16666666666666666) / Float32(s * Float32(pi))))) / s)
    end
    
    \begin{array}{l}
    
    \\
    \frac{\frac{0.25}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.06944444444444445}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.16666666666666666}{s \cdot \pi}\right)}{s}
    \end{array}
    
    Derivation
    1. Initial program 99.6%

      \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    2. Add Preprocessing
    3. Taylor expanded in s around inf

      \[\leadsto \color{blue}{\frac{\left(\frac{-1}{48} \cdot \frac{{r}^{2}}{{s}^{3} \cdot \mathsf{PI}\left(\right)} + \left(\frac{-1}{1296} \cdot \frac{{r}^{2}}{{s}^{3} \cdot \mathsf{PI}\left(\right)} + \left(\frac{1}{144} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \left(\frac{1}{16} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \frac{1}{4} \cdot \frac{1}{r \cdot \mathsf{PI}\left(\right)}\right)\right)\right)\right) - \frac{\frac{1}{6}}{s \cdot \mathsf{PI}\left(\right)}}{s}} \]
    4. Applied rewrites5.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{r}{s \cdot \left(s \cdot \pi\right)}, 0.06944444444444445, \frac{0.25}{r \cdot \pi}\right) + \mathsf{fma}\left(-0.021604938271604937, \frac{r \cdot r}{s \cdot \left(s \cdot \left(s \cdot \pi\right)\right)}, \frac{-0.16666666666666666}{s \cdot \pi}\right)}{s}} \]
    5. Taylor expanded in s around inf

      \[\leadsto \frac{\left(\frac{5}{72} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \frac{1}{4} \cdot \frac{1}{r \cdot \mathsf{PI}\left(\right)}\right) - \frac{\frac{1}{6}}{s \cdot \mathsf{PI}\left(\right)}}{s} \]
    6. Applied rewrites7.6%

      \[\leadsto \frac{\frac{0.25}{r \cdot \pi} + \mathsf{fma}\left(r, \frac{0.06944444444444445}{s \cdot \left(s \cdot \pi\right)}, \frac{-0.16666666666666666}{s \cdot \pi}\right)}{s} \]
    7. Add Preprocessing

    Alternative 10: 10.5% accurate, 4.0× speedup?

    \[\begin{array}{l} \\ \frac{\mathsf{fma}\left(0.06944444444444445, \frac{r}{s \cdot \pi}, \frac{-0.16666666666666666}{\pi}\right)}{s \cdot s} + \frac{0.25}{r \cdot \left(s \cdot \pi\right)} \end{array} \]
    (FPCore (s r)
     :precision binary32
     (+
      (/
       (fma 0.06944444444444445 (/ r (* s PI)) (/ -0.16666666666666666 PI))
       (* s s))
      (/ 0.25 (* r (* s PI)))))
    float code(float s, float r) {
    	return (fmaf(0.06944444444444445f, (r / (s * ((float) M_PI))), (-0.16666666666666666f / ((float) M_PI))) / (s * s)) + (0.25f / (r * (s * ((float) M_PI))));
    }
    
    function code(s, r)
    	return Float32(Float32(fma(Float32(0.06944444444444445), Float32(r / Float32(s * Float32(pi))), Float32(Float32(-0.16666666666666666) / Float32(pi))) / Float32(s * s)) + Float32(Float32(0.25) / Float32(r * Float32(s * Float32(pi)))))
    end
    
    \begin{array}{l}
    
    \\
    \frac{\mathsf{fma}\left(0.06944444444444445, \frac{r}{s \cdot \pi}, \frac{-0.16666666666666666}{\pi}\right)}{s \cdot s} + \frac{0.25}{r \cdot \left(s \cdot \pi\right)}
    \end{array}
    
    Derivation
    1. Initial program 99.6%

      \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    2. Add Preprocessing
    3. Taylor expanded in s around inf

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{144} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \left(\frac{1}{16} \cdot \frac{r}{{s}^{2} \cdot \mathsf{PI}\left(\right)} + \frac{1}{4} \cdot \frac{1}{r \cdot \mathsf{PI}\left(\right)}\right)\right) - \frac{\frac{1}{6}}{s \cdot \mathsf{PI}\left(\right)}}{s}} \]
    4. Applied rewrites7.6%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(0.06944444444444445, \frac{r}{s \cdot \pi}, \frac{-0.16666666666666666}{\pi}\right)}{s \cdot s} + \frac{0.25}{r \cdot \left(s \cdot \pi\right)}} \]
    5. Add Preprocessing

    Alternative 11: 9.3% accurate, 6.3× speedup?

    \[\begin{array}{l} \\ \frac{0.25}{r \cdot \left(\sqrt{\pi} \cdot \left(s \cdot \sqrt{\pi}\right)\right)} \end{array} \]
    (FPCore (s r) :precision binary32 (/ 0.25 (* r (* (sqrt PI) (* s (sqrt PI))))))
    float code(float s, float r) {
    	return 0.25f / (r * (sqrtf(((float) M_PI)) * (s * sqrtf(((float) M_PI)))));
    }
    
    function code(s, r)
    	return Float32(Float32(0.25) / Float32(r * Float32(sqrt(Float32(pi)) * Float32(s * sqrt(Float32(pi))))))
    end
    
    function tmp = code(s, r)
    	tmp = single(0.25) / (r * (sqrt(single(pi)) * (s * sqrt(single(pi)))));
    end
    
    \begin{array}{l}
    
    \\
    \frac{0.25}{r \cdot \left(\sqrt{\pi} \cdot \left(s \cdot \sqrt{\pi}\right)\right)}
    \end{array}
    
    Derivation
    1. Initial program 99.6%

      \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    2. Add Preprocessing
    3. Taylor expanded in r around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{4}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
    4. Step-by-step derivation
      1. lower-/.f32N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{4}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
      2. lower-*.f32N/A

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

        \[\leadsto \frac{\frac{1}{4}}{r \cdot \color{blue}{\left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
      4. lower-PI.f327.2

        \[\leadsto \frac{0.25}{r \cdot \left(s \cdot \color{blue}{\pi}\right)} \]
    5. Applied rewrites7.2%

      \[\leadsto \color{blue}{\frac{0.25}{r \cdot \left(s \cdot \pi\right)}} \]
    6. Step-by-step derivation
      1. Applied rewrites7.2%

        \[\leadsto \frac{0.25}{r \cdot \left(\left(s \cdot \sqrt{\pi}\right) \cdot \color{blue}{\sqrt{\pi}}\right)} \]
      2. Final simplification7.2%

        \[\leadsto \frac{0.25}{r \cdot \left(\sqrt{\pi} \cdot \left(s \cdot \sqrt{\pi}\right)\right)} \]
      3. Add Preprocessing

      Alternative 12: 9.3% accurate, 13.5× speedup?

      \[\begin{array}{l} \\ \frac{0.25}{r \cdot \left(s \cdot \pi\right)} \end{array} \]
      (FPCore (s r) :precision binary32 (/ 0.25 (* r (* s PI))))
      float code(float s, float r) {
      	return 0.25f / (r * (s * ((float) M_PI)));
      }
      
      function code(s, r)
      	return Float32(Float32(0.25) / Float32(r * Float32(s * Float32(pi))))
      end
      
      function tmp = code(s, r)
      	tmp = single(0.25) / (r * (s * single(pi)));
      end
      
      \begin{array}{l}
      
      \\
      \frac{0.25}{r \cdot \left(s \cdot \pi\right)}
      \end{array}
      
      Derivation
      1. Initial program 99.6%

        \[\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
      2. Add Preprocessing
      3. Taylor expanded in r around 0

        \[\leadsto \color{blue}{\frac{\frac{1}{4}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
      4. Step-by-step derivation
        1. lower-/.f32N/A

          \[\leadsto \color{blue}{\frac{\frac{1}{4}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
        2. lower-*.f32N/A

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

          \[\leadsto \frac{\frac{1}{4}}{r \cdot \color{blue}{\left(s \cdot \mathsf{PI}\left(\right)\right)}} \]
        4. lower-PI.f327.2

          \[\leadsto \frac{0.25}{r \cdot \left(s \cdot \color{blue}{\pi}\right)} \]
      5. Applied rewrites7.2%

        \[\leadsto \color{blue}{\frac{0.25}{r \cdot \left(s \cdot \pi\right)}} \]
      6. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2024237 
      (FPCore (s r)
        :name "Disney BSSRDF, PDF of scattering profile"
        :precision binary32
        :pre (and (and (<= 0.0 s) (<= s 256.0)) (and (< 1e-6 r) (< r 1000000.0)))
        (+ (/ (* 0.25 (exp (/ (- r) s))) (* (* (* 2.0 PI) s) r)) (/ (* 0.75 (exp (/ (- r) (* 3.0 s)))) (* (* (* 6.0 PI) s) r))))