Disney BSSRDF, PDF of scattering profile

Percentage Accurate: 99.6% → 99.6%
Time: 4.5s
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}

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.6% accurate, 1.0× speedup?

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

\\
\mathsf{fma}\left(0.75, \frac{e^{\frac{\frac{-r}{3}}{s}}}{\left(\left(\pi \cdot 6\right) \cdot s\right) \cdot r}, 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot 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. Applied rewrites99.6%

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

Alternative 2: 99.6% accurate, 1.0× speedup?

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

\\
\frac{e^{\frac{-r}{s}}}{\left(\pi \cdot s\right) \cdot r} \cdot 0.125 + \frac{0.75 \cdot e^{-0.3333333333333333 \cdot \frac{r}{s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot 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. Taylor expanded in s around 0

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-r}{s}}}{r \cdot \left(s \cdot \mathsf{PI}\left(\right)\right)} \cdot \frac{1}{8} + \frac{\frac{3}{4} \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    8. lift-exp.f32N/A

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

      \[\leadsto \frac{e^{\frac{-r}{s}}}{\left(s \cdot \mathsf{PI}\left(\right)\right) \cdot r} \cdot \frac{1}{8} + \frac{\frac{3}{4} \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    10. lower-*.f32N/A

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

      \[\leadsto \frac{e^{\frac{-r}{s}}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \cdot \frac{1}{8} + \frac{\frac{3}{4} \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    12. lower-*.f32N/A

      \[\leadsto \frac{e^{\frac{-r}{s}}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \cdot \frac{1}{8} + \frac{\frac{3}{4} \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    13. lift-PI.f3299.6

      \[\leadsto \frac{e^{\frac{-r}{s}}}{\left(\pi \cdot s\right) \cdot r} \cdot 0.125 + \frac{0.75 \cdot e^{\frac{-r}{3 \cdot s}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  4. Applied rewrites99.6%

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

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

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

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

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

Alternative 3: 10.6% accurate, 1.4× 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 \mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.05555555555555555 - \frac{0.3333333333333333}{s}, r, 1\right)}{\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
    (fma
     (- (* (/ r (* s s)) 0.05555555555555555) (/ 0.3333333333333333 s))
     r
     1.0))
   (* (* (* 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 * fmaf((((r / (s * s)) * 0.05555555555555555f) - (0.3333333333333333f / s)), r, 1.0f)) / (((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) * fma(Float32(Float32(Float32(r / Float32(s * s)) * Float32(0.05555555555555555)) - Float32(Float32(0.3333333333333333) / s)), r, Float32(1.0))) / Float32(Float32(Float32(Float32(6.0) * Float32(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 \mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.05555555555555555 - \frac{0.3333333333333333}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot 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. Taylor expanded in r around 0

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

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \left(r \cdot \left(\frac{1}{18} \cdot \frac{r}{{s}^{2}} - \frac{1}{3} \cdot \frac{1}{s}\right) + \color{blue}{1}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \left(\left(\frac{1}{18} \cdot \frac{r}{{s}^{2}} - \frac{1}{3} \cdot \frac{1}{s}\right) \cdot r + 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    3. lower-fma.f32N/A

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

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \mathsf{fma}\left(\frac{1}{18} \cdot \frac{r}{{s}^{2}} - \frac{1}{3} \cdot \frac{1}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{18} - \frac{1}{3} \cdot \frac{1}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    6. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{18} - \frac{1}{3} \cdot \frac{1}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    7. lower-/.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{18} - \frac{1}{3} \cdot \frac{1}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    8. unpow2N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{18} - \frac{1}{3} \cdot \frac{1}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    9. lower-*.f32N/A

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

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{18} - \frac{\frac{1}{3} \cdot 1}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    11. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{3}{4} \cdot \mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{18} - \frac{\frac{1}{3}}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    12. lower-/.f3210.6

      \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot \mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.05555555555555555 - \frac{0.3333333333333333}{s}, r, 1\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  4. Applied rewrites10.6%

    \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.75 \cdot \color{blue}{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.05555555555555555 - \frac{0.3333333333333333}{s}, r, 1\right)}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  5. Add Preprocessing

Alternative 4: 10.6% accurate, 1.4× speedup?

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

\\
\mathsf{fma}\left(\frac{0.75}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{r}{s \cdot s}, 0.05555555555555555, \frac{1}{r}\right) - \frac{0.3333333333333333}{s}, 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot 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. Applied rewrites99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{0.75}{\left(\pi \cdot 6\right) \cdot s}, \frac{e^{\frac{\frac{-r}{3}}{s}}}{r}, 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right)} \]
  3. Taylor expanded in s around inf

    \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \color{blue}{\left(\frac{1}{18} \cdot \frac{r}{{s}^{2}} + \frac{1}{r}\right) - \frac{1}{3} \cdot \frac{1}{s}}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
  4. Step-by-step derivation
    1. lower--.f32N/A

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

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \left(\frac{r}{{s}^{2}} \cdot \frac{1}{18} + \frac{1}{r}\right) - \frac{1}{3} \cdot \frac{1}{s}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    3. lower-fma.f32N/A

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

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{r}{{s}^{2}}, \frac{1}{18}, \frac{1}{r}\right) - \frac{1}{3} \cdot \frac{1}{s}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    5. pow2N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{r}{s \cdot s}, \frac{1}{18}, \frac{1}{r}\right) - \frac{1}{3} \cdot \frac{1}{s}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    6. lift-*.f32N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{r}{s \cdot s}, \frac{1}{18}, \frac{1}{r}\right) - \frac{1}{3} \cdot \frac{1}{s}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    7. lower-/.f32N/A

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

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{r}{s \cdot s}, \frac{1}{18}, \frac{1}{r}\right) - \frac{\frac{1}{3} \cdot 1}{\color{blue}{s}}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{r}{s \cdot s}, \frac{1}{18}, \frac{1}{r}\right) - \frac{\frac{1}{3}}{s}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    10. lower-/.f3210.6

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

    \[\leadsto \mathsf{fma}\left(\frac{0.75}{\left(\pi \cdot 6\right) \cdot s}, \color{blue}{\mathsf{fma}\left(\frac{r}{s \cdot s}, 0.05555555555555555, \frac{1}{r}\right) - \frac{0.3333333333333333}{s}}, 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
  6. Add Preprocessing

Alternative 5: 10.6% accurate, 1.4× speedup?

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

\\
\mathsf{fma}\left(\frac{0.75}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.05555555555555555, \frac{r}{s}, 0.3333333333333333\right)}{s}, -1, \frac{1}{r}\right), 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot 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. Applied rewrites99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{0.75}{\left(\pi \cdot 6\right) \cdot s}, \frac{e^{\frac{\frac{-r}{3}}{s}}}{r}, 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right)} \]
  3. Taylor expanded in s around -inf

    \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \color{blue}{-1 \cdot \frac{\frac{1}{3} + \frac{-1}{18} \cdot \frac{r}{s}}{s} + \frac{1}{r}}, \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
  4. Step-by-step derivation
    1. *-commutativeN/A

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

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

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{\frac{1}{3} + \frac{-1}{18} \cdot \frac{r}{s}}{s}, -1, \frac{1}{r}\right), \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    4. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{\frac{-1}{18} \cdot \frac{r}{s} + \frac{1}{3}}{s}, -1, \frac{1}{r}\right), \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    5. lower-fma.f32N/A

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

      \[\leadsto \mathsf{fma}\left(\frac{\frac{3}{4}}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{-1}{18}, \frac{r}{s}, \frac{1}{3}\right)}{s}, -1, \frac{1}{r}\right), \frac{1}{4} \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
    7. lower-/.f3210.6

      \[\leadsto \mathsf{fma}\left(\frac{0.75}{\left(\pi \cdot 6\right) \cdot s}, \mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.05555555555555555, \frac{r}{s}, 0.3333333333333333\right)}{s}, -1, \frac{1}{r}\right), 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
  5. Applied rewrites10.6%

    \[\leadsto \mathsf{fma}\left(\frac{0.75}{\left(\pi \cdot 6\right) \cdot s}, \color{blue}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.05555555555555555, \frac{r}{s}, 0.3333333333333333\right)}{s}, -1, \frac{1}{r}\right)}, 0.25 \cdot \frac{e^{\frac{-r}{s}}}{\left(\left(\pi \cdot 2\right) \cdot s\right) \cdot r}\right) \]
  6. Add Preprocessing

Alternative 6: 10.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.041666666666666664 - \frac{0.25}{s}, r, 0.75\right)}{\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))
  (/
   (fma (- (* (/ r (* s s)) 0.041666666666666664) (/ 0.25 s)) r 0.75)
   (* (* (* 6.0 PI) s) r))))
float code(float s, float r) {
	return ((0.25f * expf((-r / s))) / (((2.0f * ((float) M_PI)) * s) * r)) + (fmaf((((r / (s * s)) * 0.041666666666666664f) - (0.25f / s)), r, 0.75f) / (((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(fma(Float32(Float32(Float32(r / Float32(s * s)) * Float32(0.041666666666666664)) - Float32(Float32(0.25) / s)), r, Float32(0.75)) / Float32(Float32(Float32(Float32(6.0) * Float32(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{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.041666666666666664 - \frac{0.25}{s}, r, 0.75\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot 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. Taylor expanded in r around 0

    \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\color{blue}{\frac{3}{4} + r \cdot \left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}\right)}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  3. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{r \cdot \left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}\right) + \color{blue}{\frac{3}{4}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}\right) \cdot r + \frac{3}{4}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}, \color{blue}{r}, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    4. lower--.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    6. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    7. lower-/.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    8. unpow2N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    9. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    10. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{\frac{1}{4} \cdot 1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    11. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{\frac{1}{4}}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    12. lower-/.f3210.6

      \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.041666666666666664 - \frac{0.25}{s}, r, 0.75\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  4. Applied rewrites10.6%

    \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\color{blue}{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.041666666666666664 - \frac{0.25}{s}, r, 0.75\right)}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  5. Add Preprocessing

Alternative 7: 10.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.25, s, 0.041666666666666664 \cdot r\right)}{s \cdot s}, r, 0.75\right)}{\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))
  (/
   (fma (/ (fma -0.25 s (* 0.041666666666666664 r)) (* s s)) r 0.75)
   (* (* (* 6.0 PI) s) r))))
float code(float s, float r) {
	return ((0.25f * expf((-r / s))) / (((2.0f * ((float) M_PI)) * s) * r)) + (fmaf((fmaf(-0.25f, s, (0.041666666666666664f * r)) / (s * s)), r, 0.75f) / (((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(fma(Float32(fma(Float32(-0.25), s, Float32(Float32(0.041666666666666664) * r)) / Float32(s * s)), r, Float32(0.75)) / Float32(Float32(Float32(Float32(6.0) * Float32(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{\mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.25, s, 0.041666666666666664 \cdot r\right)}{s \cdot s}, r, 0.75\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot 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. Taylor expanded in r around 0

    \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\color{blue}{\frac{3}{4} + r \cdot \left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}\right)}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  3. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{r \cdot \left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}\right) + \color{blue}{\frac{3}{4}}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}\right) \cdot r + \frac{3}{4}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    3. lower-fma.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}, \color{blue}{r}, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    4. lower--.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{1}{24} \cdot \frac{r}{{s}^{2}} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    6. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    7. lower-/.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{{s}^{2}} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    8. unpow2N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    9. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{1}{4} \cdot \frac{1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    10. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{\frac{1}{4} \cdot 1}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    11. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot \frac{1}{24} - \frac{\frac{1}{4}}{s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    12. lower-/.f3210.6

      \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.041666666666666664 - \frac{0.25}{s}, r, 0.75\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  4. Applied rewrites10.6%

    \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\color{blue}{\mathsf{fma}\left(\frac{r}{s \cdot s} \cdot 0.041666666666666664 - \frac{0.25}{s}, r, 0.75\right)}}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  5. Taylor expanded in s around 0

    \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{\frac{-1}{4} \cdot s + \frac{1}{24} \cdot r}{{s}^{2}}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  6. Step-by-step derivation
    1. lower-/.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{\frac{-1}{4} \cdot s + \frac{1}{24} \cdot r}{{s}^{2}}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    2. lower-fma.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{-1}{4}, s, \frac{1}{24} \cdot r\right)}{{s}^{2}}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    3. lower-*.f32N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{-1}{4}, s, \frac{1}{24} \cdot r\right)}{{s}^{2}}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    4. pow2N/A

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{-1}{4}, s, \frac{1}{24} \cdot r\right)}{s \cdot s}, r, \frac{3}{4}\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
    5. lift-*.f3210.6

      \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(-0.25, s, 0.041666666666666664 \cdot r\right)}{s \cdot s}, r, 0.75\right)}{\left(\left(6 \cdot \pi\right) \cdot s\right) \cdot r} \]
  7. Applied rewrites10.6%

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

Alternative 8: 9.4% accurate, 1.8× speedup?

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

\\
\frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(\pi + \pi\right) \cdot s\right) \cdot r} + \frac{0.125}{\left(\pi \cdot s\right) \cdot 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. Taylor expanded in s around inf

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{\frac{1}{8}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \]
    6. lift-PI.f329.4

      \[\leadsto \frac{0.25 \cdot e^{\frac{-r}{s}}}{\left(\left(2 \cdot \pi\right) \cdot s\right) \cdot r} + \frac{0.125}{\left(\pi \cdot s\right) \cdot r} \]
  4. Applied rewrites9.4%

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{4} \cdot e^{\frac{-r}{s}}}{\left(\left(\color{blue}{\pi} + \mathsf{PI}\left(\right)\right) \cdot s\right) \cdot r} + \frac{\frac{1}{8}}{\left(\pi \cdot s\right) \cdot r} \]
    6. lift-PI.f329.4

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

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

Alternative 9: 10.0% accurate, 4.0× speedup?

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

\\
\frac{\mathsf{fma}\left(0.06944444444444445, \frac{r}{\left(s \cdot s\right) \cdot \pi}, \frac{0.25}{r \cdot \pi}\right) - \frac{0.16666666666666666}{s \cdot \pi}}{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. Taylor expanded in s around -inf

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

    \[\leadsto \color{blue}{-\frac{\left(-\frac{\left(-\frac{\mathsf{fma}\left(\frac{r}{\pi}, -0.06944444444444445, -\frac{\frac{r \cdot r}{\pi} \cdot -0.021604938271604937}{s}\right)}{s}\right) - \frac{0.16666666666666666}{\pi}}{s}\right) - \frac{0.25}{\pi \cdot r}}{s}} \]
  4. 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)}}{\color{blue}{s}} \]
  5. Step-by-step derivation
    1. lower-/.f32N/A

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

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

Alternative 10: 8.9% accurate, 10.6× speedup?

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

\\
\frac{\frac{0.25}{r}}{\pi \cdot 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. Taylor expanded in s around inf

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{4}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \]
    6. lift-PI.f328.9

      \[\leadsto \frac{0.25}{\left(\pi \cdot s\right) \cdot r} \]
  4. Applied rewrites8.9%

    \[\leadsto \color{blue}{\frac{0.25}{\left(\pi \cdot s\right) \cdot r}} \]
  5. Step-by-step derivation
    1. lift-*.f32N/A

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

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

      \[\leadsto \frac{\frac{1}{4}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \]
    4. associate-*l*N/A

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

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

      \[\leadsto \frac{\frac{1}{4}}{\pi \cdot \left(\color{blue}{s} \cdot r\right)} \]
    7. lower-*.f328.9

      \[\leadsto \frac{0.25}{\pi \cdot \left(s \cdot \color{blue}{r}\right)} \]
  6. Applied rewrites8.9%

    \[\leadsto \frac{0.25}{\pi \cdot \color{blue}{\left(s \cdot r\right)}} \]
  7. Step-by-step derivation
    1. lift-/.f32N/A

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{4}}{\left(r \cdot s\right) \cdot \mathsf{PI}\left(\right)} \]
    7. associate-*r*N/A

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

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

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

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

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

      \[\leadsto \frac{\frac{\frac{1}{4}}{r}}{\mathsf{PI}\left(\right) \cdot \color{blue}{s}} \]
    13. lift-PI.f328.9

      \[\leadsto \frac{\frac{0.25}{r}}{\pi \cdot s} \]
  8. Applied rewrites8.9%

    \[\leadsto \frac{\frac{0.25}{r}}{\color{blue}{\pi \cdot s}} \]
  9. Add Preprocessing

Alternative 11: 8.9% accurate, 13.5× speedup?

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

\\
\frac{0.25}{\left(\pi \cdot s\right) \cdot 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. Taylor expanded in s around inf

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{4}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \]
    6. lift-PI.f328.9

      \[\leadsto \frac{0.25}{\left(\pi \cdot s\right) \cdot r} \]
  4. Applied rewrites8.9%

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

Alternative 12: 8.9% accurate, 13.5× speedup?

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

\\
\frac{0.25}{\pi \cdot \left(s \cdot 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. Taylor expanded in s around inf

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{4}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \]
    6. lift-PI.f328.9

      \[\leadsto \frac{0.25}{\left(\pi \cdot s\right) \cdot r} \]
  4. Applied rewrites8.9%

    \[\leadsto \color{blue}{\frac{0.25}{\left(\pi \cdot s\right) \cdot r}} \]
  5. Step-by-step derivation
    1. lift-*.f32N/A

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

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

      \[\leadsto \frac{\frac{1}{4}}{\left(\mathsf{PI}\left(\right) \cdot s\right) \cdot r} \]
    4. associate-*l*N/A

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

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

      \[\leadsto \frac{\frac{1}{4}}{\pi \cdot \left(\color{blue}{s} \cdot r\right)} \]
    7. lower-*.f328.9

      \[\leadsto \frac{0.25}{\pi \cdot \left(s \cdot \color{blue}{r}\right)} \]
  6. Applied rewrites8.9%

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

Reproduce

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